using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BoneLib; using BoneLib.BoneMenu; using HarmonyLib; using Il2CppSLZ.Marrow; using MelonLoader; using Microsoft.CodeAnalysis; using RealJammingSystem; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: MelonInfo(typeof(JammingMod), "Mechanical Weapon Jamming", "1.2.0", "Picklerick", null)] [assembly: MelonGame("Stress Level Zero", "BONELAB")] [assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")] [assembly: AssemblyVersion("0.0.0.0")] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } } namespace RealJammingSystem { public class JammingMod : MelonMod { private static Page? customMenuPage = null; public static float globalJamChancePercent = 0.2f; public static bool isModEnabled = true; public static bool allowMisfires = true; public static HashSet JammedGunIDs = new HashSet(); public override void OnInitializeMelon() { Hooking.OnLevelLoaded += delegate { BuildModConfigurationMenu(); }; MelonLogger.Msg("Mechanical Weapon Jamming initialized successfully for Patch 6!"); } private void BuildModConfigurationMenu() { //IL_0012: 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) if (customMenuPage != null) { return; } customMenuPage = Page.Root.CreatePage("Weapon Jam Settings", Color.yellow, 0, true); customMenuPage.CreateBool("Mod Enabled", Color.white, isModEnabled, (Action)delegate(bool value) { isModEnabled = value; MelonLogger.Msg("Weapon Jamming Mod Toggled: " + (value ? "ENABLED" : "DISABLED")); if (!value) { JammedGunIDs.Clear(); } }); customMenuPage.CreateBool("Include Misfires", Color.white, allowMisfires, (Action)delegate(bool value) { allowMisfires = value; MelonLogger.Msg("Failure to Fire Misfires: " + (value ? "ALLOWED" : "DISABLED (Slide Lock Only)")); }); customMenuPage.CreateFloat("Jam Probability Rate", Color.white, globalJamChancePercent, 0.05f, 0f, 5f, (Action)delegate(float value) { globalJamChancePercent = value; MelonLogger.Msg($"Global firearm jam rate updated to: {value:F2}%"); }); } } [HarmonyPatch(typeof(Gun), "Fire")] public static class GunFirePrePatch { private static readonly Random randomEngine = new Random(); [HarmonyPrefix] public static bool Prefix(Gun __instance) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Invalid comparison between Unknown and I4 if ((Object)(object)__instance == (Object)null) { return true; } if (!JammingMod.isModEnabled || JammingMod.globalJamChancePercent <= 0f) { return true; } int instanceID = ((Object)__instance).GetInstanceID(); if (JammingMod.JammedGunIDs.Contains(instanceID)) { return false; } if ((int)__instance.slideState == 4) { return true; } double num = JammingMod.globalJamChancePercent; if (randomEngine.NextDouble() * 100.0 < num) { JammingMod.JammedGunIDs.Add(instanceID); if (JammingMod.allowMisfires && randomEngine.NextDouble() < 0.5) { MelonLogger.Msg("[Gun Misfire] " + ((Object)__instance).name + " suffered a failure to fire! Round stuck in chamber."); } else { MelonLogger.Msg("[Failure to Eject] " + ((Object)__instance).name + " suffered an ejection failure jam!"); __instance.EjectCartridge(); __instance.SlideLocked(); } return false; } return true; } } [HarmonyPatch(typeof(Gun), "SlideRelease")] public static class GunSlideReleasePatch { [HarmonyPrefix] public static bool Prefix(Gun __instance) { if ((Object)(object)__instance == (Object)null) { return true; } int instanceID = ((Object)__instance).GetInstanceID(); if (JammingMod.JammedGunIDs.Contains(instanceID)) { JammingMod.JammedGunIDs.Remove(instanceID); MelonLogger.Msg("[Jam Cleared] Weapon mechanism manually cycled and cleared: " + ((Object)__instance).name); } return true; } } }