Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of Lethal Weight Fix v1.1.1
BepInEx/Plugins/Lethal_Weight_Fix.dll
Decompiled 2 years agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Logging; using GameNetcodeStuff; using HarmonyLib; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("Lethal_Weight_Fix")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Lethal_Weight_Fix")] [assembly: AssemblyCopyright("Copyright © 2024")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("e244d445-54a0-46e3-9f21-7710a2086463")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("1.0.0.0")] namespace Lethal_Weight_Fix { [BepInPlugin("Hackattack242.Lethal_Weight_Fix", "Lethal_Weight_Fix", "1.1.1")] public class Lethal_weight_fix_base : BaseUnityPlugin { private const string mod_GUID = "Hackattack242.Lethal_Weight_Fix"; private const string mod_name = "Lethal_Weight_Fix"; private const string mod_version = "1.1.1"; private readonly Harmony harmony = new Harmony("Hackattack242.Lethal_Weight_Fix"); private static Lethal_weight_fix_base Instance; private ManualLogSource logger; private void Awake() { if ((Object)(object)Instance == (Object)null) { Instance = this; } logger = Logger.CreateLogSource("Lethal_Weight_Fix"); logger.LogInfo((object)"Lethal Weight Fix has awoken"); harmony.PatchAll(); logger.LogInfo((object)"Lethal Weight Fix Patches Applied"); } internal static void LogDebug(string message) { Instance.Log(message, (LogLevel)32); } internal static void LogInfo(string message) { Instance.Log(message, (LogLevel)16); } internal static void LogWarning(string message) { Instance.Log(message, (LogLevel)4); } internal static void LogError(string message) { Instance.Log(message, (LogLevel)2); } internal static void LogError(Exception ex) { Instance.Log(ex.Message + "\n" + ex.StackTrace, (LogLevel)2); } private void Log(string message, LogLevel logLevel) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) logger.Log(logLevel, (object)message); } } } namespace Lethal_Weight_Fix.Patches { [HarmonyPatch(typeof(PlayerControllerB))] internal class Lethal_weight_fix { private static IEnumerable<CodeInstruction> deliver_patch(IEnumerable<CodeInstruction> instructions, string func_name) { List<CodeInstruction> list = new List<CodeInstruction>(instructions); for (int i = 0; i < list.Count; i++) { if (CodeInstructionExtensions.Calls(list[i], typeof(Mathf).GetMethod("Clamp", new Type[3] { typeof(float), typeof(float), typeof(float) }))) { if (i < 3) { Lethal_weight_fix_base.LogWarning("index was too small on match in " + ((object)list[i])?.ToString() + "in function " + func_name + ", index: " + i); } else { list.Insert(i + 1, list[i - 3]); list[i - 2].operand = 0f; list.RemoveAt(i - 3); Lethal_weight_fix_base.LogInfo("Patched function " + func_name); } } } return list; } [HarmonyPatch("BeginGrabObject")] [HarmonyTranspiler] private static IEnumerable<CodeInstruction> patch_BeginGrabObject(IEnumerable<CodeInstruction> instructions) { return deliver_patch(instructions, "BeginGrabObject"); } [HarmonyPatch("GrabObject")] [HarmonyTranspiler] private static IEnumerable<CodeInstruction> patch_GrabObject(IEnumerable<CodeInstruction> instructions) { return deliver_patch(instructions, "GrabObject"); } [HarmonyPatch("GrabObjectClientRpc")] [HarmonyTranspiler] private static IEnumerable<CodeInstruction> patch_GrabObjectClientRpc(IEnumerable<CodeInstruction> instructions) { return deliver_patch(instructions, "GrabObjectClientRpc"); } [HarmonyPatch("DespawnHeldObjectOnClient")] [HarmonyTranspiler] private static IEnumerable<CodeInstruction> patch_DespawnHeldObjectOnClient(IEnumerable<CodeInstruction> instructions) { return deliver_patch(instructions, "DespawnHeldObjectOnClient"); } [HarmonyPatch("SetObjectAsNoLongerHeld")] [HarmonyTranspiler] private static IEnumerable<CodeInstruction> patch_SetObjectAsNoLongerHeld(IEnumerable<CodeInstruction> instructions) { return deliver_patch(instructions, "SetObjectAsNoLongerHeld"); } [HarmonyPatch("PlaceGrabbableObject")] [HarmonyTranspiler] private static IEnumerable<CodeInstruction> patch_PlaceGrabbableObject(IEnumerable<CodeInstruction> instructions) { return deliver_patch(instructions, "PlaceGrabbableObject"); } [HarmonyPatch("DestroyItemInSlot")] [HarmonyTranspiler] private static IEnumerable<CodeInstruction> patch_DestroyItemInSlot(IEnumerable<CodeInstruction> instructions) { return deliver_patch(instructions, "DestroyItemInSlot"); } private static void enforce_miunimum_weight(ref float ___carryWeight, string func) { if (___carryWeight < 1f) { Lethal_weight_fix_base.LogWarning("Carry Weight went below 1 {" + ___carryWeight + "}. This should not happen. Resetting weight to 1. function: " + func); ___carryWeight = 1f; } } [HarmonyPatch("DespawnHeldObjectOnClient")] [HarmonyPostfix] private static void patch_DespawnHeldObjectOnClient_postfix(ref float ___carryWeight) { enforce_miunimum_weight(ref ___carryWeight, "DespawnHeldObjectOnClient"); } [HarmonyPatch("SetObjectAsNoLongerHeld")] [HarmonyPostfix] private static void patch_SetObjectAsNoLongerHeld_postfix(ref float ___carryWeight) { enforce_miunimum_weight(ref ___carryWeight, "SetObjectAsNoLongerHeld"); } [HarmonyPatch("PlaceGrabbableObject")] [HarmonyPostfix] private static void patch_PlaceGrabbableObject_postfix(ref float ___carryWeight) { enforce_miunimum_weight(ref ___carryWeight, "PlaceGrabbableObject"); } [HarmonyPatch("DestroyItemInSlot")] [HarmonyPostfix] private static void patch_DestroyItemInSlot_postfix(ref float ___carryWeight) { enforce_miunimum_weight(ref ___carryWeight, "DestroyItemInSlot"); } } }