using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BoneLib;
using BoneLib.BoneMenu;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Marrow;
using Il2CppSystem;
using Il2CppSystem.Reflection;
using MelonLoader;
using OneShotGuns;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Main), "OneShotGuns", "1.2.0", "Moris", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: AssemblyTitle("OneShotGuns")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OneShotGuns")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("75b47613-7e99-482c-8612-1c796311ed3e")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace OneShotGuns;
public class Main : MelonMod
{
private struct SavedDamageState
{
public object DataObj;
public float OriginalDamage;
public bool Modified;
}
public static bool IsEnabled = true;
public static bool OverkillMode = false;
public static bool OnlyPlayers = false;
private const float StandardOneShotDamage = 90000f;
private const float OverkillOneShotDamage = 2E+09f;
private static BoolElement _enabledToggle;
private static BoolElement _overkillToggle;
private static RigManager _cachedLocalRig;
private static Component _cachedLocalProxy;
private static Type _aiBrainIl2CppType;
private static Type _puppetMasterIl2CppType;
private static Type _projEmitterType;
private static Type _projDataType;
private static PropertyInfo _projDataDamageProp;
private static FieldInfo _projDataDamageField;
private static Type _attackType;
private static PropertyInfo _attackDamageProp;
private static FieldInfo _attackDamageField;
private static PropertyInfo _attackProxyProp;
private static FieldInfo _attackProxyField;
private static PropertyInfo _gunProxyProp;
private static FieldInfo _gunProxyField;
public static Main Instance { get; private set; }
public static float CurrentDamage => OverkillMode ? 2E+09f : 90000f;
public override void OnInitializeMelon()
{
Instance = this;
CacheMarrowReflection();
ApplyHarmonyPatches();
SetupBoneMenu();
((MelonBase)this).LoggerInstance.Msg("OneShotGuns v1.2.0 initialized!");
}
private void CacheMarrowReflection()
{
BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
Type typeFromHandle = typeof(Gun);
_gunProxyProp = typeFromHandle.GetProperty("triggerRefProxy", bindingAttr) ?? typeFromHandle.GetProperty("TriggerRefProxy", bindingAttr) ?? typeFromHandle.GetProperty("proxy", bindingAttr);
_gunProxyField = typeFromHandle.GetField("triggerRefProxy", bindingAttr) ?? typeFromHandle.GetField("_proxy", bindingAttr) ?? typeFromHandle.GetField("proxy", bindingAttr);
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
for (int i = 0; i < assemblies.Length; i++)
{
string text = assemblies[i].GetName().Name ?? string.Empty;
if (text.IndexOf("Marrow", StringComparison.OrdinalIgnoreCase) < 0)
{
continue;
}
Type[] types;
try
{
types = assemblies[i].GetTypes();
}
catch
{
continue;
}
foreach (Type type in types)
{
if (type.Name == "ProjectileEmitter")
{
_projEmitterType = type;
}
else if (type.Name == "ProjectileData")
{
_projDataType = type;
_projDataDamageProp = type.GetProperty("damage", bindingAttr);
_projDataDamageField = type.GetField("damage", bindingAttr);
}
else if (type.Name == "Attack")
{
_attackType = type;
_attackDamageProp = type.GetProperty("damage", bindingAttr);
_attackDamageField = type.GetField("damage", bindingAttr);
_attackProxyProp = type.GetProperty("proxy", bindingAttr);
_attackProxyField = type.GetField("proxy", bindingAttr);
}
else if (type.Name == "AIBrain")
{
_aiBrainIl2CppType = Il2CppType.From(type);
}
else if (type.Name == "PuppetMaster")
{
_puppetMasterIl2CppType = Il2CppType.From(type);
}
}
}
}
private void ApplyHarmonyPatches()
{
//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Expected O, but got Unknown
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Expected O, but got Unknown
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Expected O, but got Unknown
BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
int num = 0;
int num2 = 0;
if (_projEmitterType != null)
{
HarmonyMethod val = new HarmonyMethod(typeof(Main), "OnProjectileEmitPrefix", (Type[])null);
HarmonyMethod val2 = new HarmonyMethod(typeof(Main), "OnProjectileEmitPostfix", (Type[])null);
MethodInfo[] methods = _projEmitterType.GetMethods(bindingAttr);
for (int i = 0; i < methods.Length; i++)
{
if (!(methods[i].Name != "Emit"))
{
try
{
((MelonBase)this).HarmonyInstance.Patch((MethodBase)methods[i], val, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
num++;
}
catch
{
}
}
}
}
HarmonyMethod val3 = new HarmonyMethod(typeof(Main), "OnFusionSendDamagePrefix", (Type[])null);
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
for (int j = 0; j < assemblies.Length; j++)
{
string text = assemblies[j].GetName().Name ?? string.Empty;
if (text.IndexOf("LabFusion", StringComparison.OrdinalIgnoreCase) < 0)
{
continue;
}
Type[] types;
try
{
types = assemblies[j].GetTypes();
}
catch
{
continue;
}
for (int k = 0; k < types.Length; k++)
{
if (types[k].Name != "PlayerSender")
{
continue;
}
MethodInfo[] methods2 = types[k].GetMethods(bindingAttr);
for (int l = 0; l < methods2.Length; l++)
{
if (!(methods2[l].Name != "SendPlayerDamage"))
{
try
{
((MelonBase)this).HarmonyInstance.Patch((MethodBase)methods2[l], val3, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
num2++;
}
catch
{
}
}
}
}
}
((MelonBase)this).LoggerInstance.Msg($"OneShotGuns v1.2.0 patched: Emitter={num}, Fusion={num2}");
}
private void SetupBoneMenu()
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
Page val = Page.Root.CreatePage("One-Shot Guns", new Color(1f, 0.25f, 0.25f), 0, true);
_enabledToggle = val.CreateBool("Enabled (90K DMG)", Color.white, IsEnabled, (Action<bool>)delegate(bool flag)
{
IsEnabled = flag;
if (!flag && OverkillMode)
{
OverkillMode = false;
if (_overkillToggle != null)
{
_overkillToggle.Value = false;
}
}
});
_overkillToggle = val.CreateBool("Overkill Mode (2B DMG)", Color.yellow, OverkillMode, (Action<bool>)delegate(bool flag)
{
OverkillMode = flag;
if (flag && !IsEnabled)
{
IsEnabled = true;
if (_enabledToggle != null)
{
_enabledToggle.Value = true;
}
}
});
val.CreateBool("Only Players", Color.cyan, OnlyPlayers, (Action<bool>)delegate(bool onlyPlayers)
{
OnlyPlayers = onlyPlayers;
});
}
public override void OnSceneWasLoaded(int buildIndex, string sceneName)
{
_cachedLocalRig = null;
_cachedLocalProxy = null;
}
private static void RefreshLocalRigCache()
{
RigManager rigManager = Player.RigManager;
if ((Object)(object)rigManager == (Object)(object)_cachedLocalRig)
{
return;
}
_cachedLocalRig = rigManager;
_cachedLocalProxy = null;
if ((Object)(object)rigManager == (Object)null)
{
return;
}
Component[] array = Il2CppArrayBase<Component>.op_Implicit(((Component)rigManager).GetComponentsInChildren<Component>(true));
for (int i = 0; i < array.Length; i++)
{
if ((Object)(object)array[i] != (Object)null && ((MemberInfo)((Object)array[i]).GetIl2CppType()).Name == "TriggerRefProxy")
{
_cachedLocalProxy = array[i];
break;
}
}
}
private static bool IsLocalPlayerOrFreeProp(Component emitter)
{
if ((Object)(object)emitter == (Object)null)
{
return false;
}
RefreshLocalRigCache();
if ((Object)(object)_cachedLocalRig == (Object)null)
{
return false;
}
if (emitter.transform.IsChildOf(((Component)_cachedLocalRig).transform))
{
return true;
}
RigManager componentInParent = emitter.GetComponentInParent<RigManager>();
if ((Object)(object)componentInParent != (Object)null && (Object)(object)componentInParent != (Object)(object)_cachedLocalRig)
{
return false;
}
if (_puppetMasterIl2CppType != (Type)null && (Object)(object)emitter.GetComponentInParent(_puppetMasterIl2CppType) != (Object)null)
{
return false;
}
if (_aiBrainIl2CppType != (Type)null && (Object)(object)emitter.GetComponentInParent(_aiBrainIl2CppType) != (Object)null)
{
return false;
}
return true;
}
private static float GetFloatMember(object target, PropertyInfo prop, FieldInfo field)
{
if (target == null)
{
return 0f;
}
if (prop != null)
{
return (float)prop.GetValue(target);
}
if (field != null)
{
return (float)field.GetValue(target);
}
return 0f;
}
private static void SetFloatMember(object target, PropertyInfo prop, FieldInfo field, float value)
{
if (target != null)
{
if (prop != null && prop.CanWrite)
{
prop.SetValue(target, value);
}
else if (field != null)
{
field.SetValue(target, value);
}
}
}
private static void OnProjectileEmitPrefix(Component __instance, object[] __args, out SavedDamageState __state)
{
__state = default(SavedDamageState);
if (!IsEnabled || OnlyPlayers || (Object)(object)__instance == (Object)null || __args == null || !IsLocalPlayerOrFreeProp(__instance))
{
return;
}
if ((Object)(object)_cachedLocalProxy != (Object)null)
{
try
{
Gun componentInParent = __instance.GetComponentInParent<Gun>();
if ((Object)(object)componentInParent != (Object)null)
{
if (_gunProxyProp != null && _gunProxyProp.CanWrite)
{
_gunProxyProp.SetValue(componentInParent, _cachedLocalProxy);
}
else if (_gunProxyField != null)
{
_gunProxyField.SetValue(componentInParent, _cachedLocalProxy);
}
}
}
catch
{
}
}
if (_projDataType == null)
{
return;
}
foreach (object obj2 in __args)
{
if (obj2 != null && _projDataType.IsInstanceOfType(obj2))
{
try
{
float floatMember = GetFloatMember(obj2, _projDataDamageProp, _projDataDamageField);
__state = new SavedDamageState
{
DataObj = obj2,
OriginalDamage = floatMember,
Modified = true
};
SetFloatMember(obj2, _projDataDamageProp, _projDataDamageField, CurrentDamage);
break;
}
catch
{
break;
}
}
}
}
private static void OnProjectileEmitPostfix(SavedDamageState __state)
{
if (!__state.Modified || __state.DataObj == null)
{
return;
}
try
{
SetFloatMember(__state.DataObj, _projDataDamageProp, _projDataDamageField, __state.OriginalDamage);
}
catch
{
}
}
private static void OnFusionSendDamagePrefix(object[] __args)
{
if (!IsEnabled || __args == null)
{
return;
}
float currentDamage = CurrentDamage;
for (int i = 1; i < __args.Length; i++)
{
if (__args[i] == null)
{
continue;
}
if (__args[i] is float)
{
__args[i] = currentDamage;
}
else
{
if (!(_attackType != null) || !_attackType.IsInstanceOfType(__args[i]))
{
continue;
}
try
{
object obj = __args[i];
SetFloatMember(obj, _attackDamageProp, _attackDamageField, currentDamage);
if ((Object)(object)_cachedLocalProxy != (Object)null)
{
if (_attackProxyProp != null && _attackProxyProp.CanWrite)
{
_attackProxyProp.SetValue(obj, _cachedLocalProxy);
}
else if (_attackProxyField != null)
{
_attackProxyField.SetValue(obj, _cachedLocalProxy);
}
}
__args[i] = obj;
}
catch
{
}
}
}
}
}