using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using HarmonyLib;
using MelonLoader;
using MelonLoader.Preferences;
using NoAutoEjectMod;
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), "No Auto Eject Mag", "1.2.0", "MVR", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: AssemblyTitle("NoAutoEjectMag")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NoAutoEjectMag")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("edc9d2e4-8356-4c49-8cca-34b72072dddf")]
[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 NoAutoEjectMod;
public class Main : MelonMod
{
private static MelonPreferences_Category _prefsCategory;
private static MelonPreferences_Entry<bool> _prefsEnabled;
private static MelonPreferences_Entry<float> _prefsForceThreshold;
public static bool ModEnabled => _prefsEnabled?.Value ?? true;
public static float ForceThreshold => _prefsForceThreshold?.Value ?? 3f;
public override void OnInitializeMelon()
{
_prefsCategory = MelonPreferences.CreateCategory("NoAutoEjectMod", "No Auto Eject");
_prefsEnabled = _prefsCategory.CreateEntry<bool>("Enabled", true, "Enable Mod", (string)null, false, false, (ValueValidator)null, (string)null);
_prefsForceThreshold = _prefsCategory.CreateEntry<float>("ForceThreshold", 3f, "Force threshold", (string)null, false, false, (ValueValidator)null, (string)null);
SetupBoneMenuUltimate();
MelonLogger.Msg("NoAutoEjectMod loaded!");
}
private void SetupBoneMenuUltimate()
{
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_0136: Unknown result type (might be due to invalid IL or missing references)
//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
try
{
Type type = Type.GetType("BoneLib.BoneMenu.Page, BoneLib");
if (type == null)
{
return;
}
object obj = type.GetProperty("Root", BindingFlags.Static | BindingFlags.Public)?.GetValue(null);
if (obj == null)
{
return;
}
MethodInfo method = obj.GetType().GetMethod("CreatePage", new Type[4]
{
typeof(string),
typeof(Color),
typeof(int),
typeof(bool)
});
if (method == null)
{
return;
}
object obj2 = method.Invoke(obj, new object[4]
{
"No Auto Eject",
Color.cyan,
0,
true
});
if (obj2 == null)
{
return;
}
MethodInfo method2 = obj2.GetType().GetMethod("CreateBool");
MethodInfo method3 = obj2.GetType().GetMethod("CreateFloat");
if (method2 != null)
{
method2.Invoke(obj2, new object[4]
{
"Mod Enabled",
Color.white,
_prefsEnabled.Value,
(Action<bool>)delegate(bool val)
{
_prefsEnabled.Value = val;
_prefsCategory.SaveToFile(true);
}
});
}
if (method3 != null)
{
method3.Invoke(obj2, new object[7]
{
"Force Threshold",
Color.yellow,
_prefsForceThreshold.Value,
0.1f,
1f,
15f,
(Action<float>)delegate(float val)
{
_prefsForceThreshold.Value = val;
_prefsCategory.SaveToFile(true);
}
});
}
}
catch (Exception ex)
{
MelonLogger.Warning("BoneMenu error: " + ex.Message);
}
}
}
[HarmonyPatch("Il2CppSLZ.Marrow.AmmoSocket", "OnPlugEnter")]
public class Patch_AmmoSocket
{
private static FieldInfo _isMagazineInsertedField;
private static PropertyInfo _isMagazineInsertedProperty;
private static bool _isInitialized;
private static void Init(Type type)
{
if (!_isInitialized)
{
_isMagazineInsertedField = type.GetField("_isMagazineInserted", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (_isMagazineInsertedField == null)
{
_isMagazineInsertedProperty = type.GetProperty("_isMagazineInserted", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
}
_isInitialized = true;
}
}
[HarmonyPrefix]
public static bool Prefix(Component __instance, object plug)
{
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
if (!Main.ModEnabled || (Object)(object)__instance == (Object)null)
{
return true;
}
try
{
Type type = ((object)__instance).GetType();
Init(type);
bool flag = false;
if (_isMagazineInsertedField != null)
{
flag = (bool)_isMagazineInsertedField.GetValue(__instance);
}
else if (_isMagazineInsertedProperty != null)
{
flag = (bool)_isMagazineInsertedProperty.GetValue(__instance);
}
if (flag && plug != null)
{
Component val = (Component)((plug is Component) ? plug : null);
if ((Object)(object)val != (Object)null)
{
Rigidbody val2 = val.GetComponentInParent<Rigidbody>() ?? val.GetComponent<Rigidbody>();
if ((Object)(object)val2 != (Object)null)
{
Vector3 velocity = val2.velocity;
float magnitude = ((Vector3)(ref velocity)).magnitude;
if (magnitude > Main.ForceThreshold)
{
return true;
}
return false;
}
}
return false;
}
}
catch
{
}
return true;
}
}