Please disclose if your mod was created primarily 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 WeightedBeltBag v1.1.2
WeightedBeltBag.dll
Decompiled 11 months agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using CSync.Extensions; using CSync.Lib; using GameNetcodeStuff; using HarmonyLib; using Microsoft.CodeAnalysis; using Unity.Netcode; using UnityEngine; using WeightedBeltBag.NetcodePatcher; using bluexephops.patch; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: IgnoresAccessChecksTo("Assembly-CSharp")] [assembly: AssemblyCompany("WeightedBeltBag")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.1.1.0")] [assembly: AssemblyInformationalVersion("1.1.1-alpha.0.3")] [assembly: AssemblyProduct("WeightedBeltBag")] [assembly: AssemblyTitle("WeightedBeltBag")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] [module: NetcodePatchedAssembly] internal class <Module> { static <Module>() { } } namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace bluexephops { [BepInPlugin("WeightedBeltBag", "WeightedBeltBag", "1.0.0")] [BepInDependency("com.sigurd.csync", "5.0.1")] public class Plugin : BaseUnityPlugin { private readonly Harmony _harmony = new Harmony("WeightedBeltBag"); internal static BeltBagConfig BoundConfig; public static Plugin Instance { get; set; } public static ManualLogSource Log => ((BaseUnityPlugin)Instance).Logger; public Plugin() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown Instance = this; } private void Awake() { BoundConfig = new BeltBagConfig(((BaseUnityPlugin)this).Config); Log.LogInfo((object)"Applying patches..."); ApplyPluginPatch(); Log.LogInfo((object)"Patches applied"); } private void ApplyPluginPatch() { _harmony.PatchAll(typeof(BeltBagItemPatch)); _harmony.PatchAll(typeof(GrabbableObjectPatch)); } } public static class PluginInfo { public const string PLUGIN_GUID = "WeightedBeltBag"; public const string PLUGIN_NAME = "WeightedBeltBag"; public const string PLUGIN_VERSION = "1.0.0"; } } namespace bluexephops.patch { internal class BeltBagConfig : SyncedConfig2<BeltBagConfig> { [SyncedEntryField] public SyncedEntry<float> configPercent; public BeltBagConfig(ConfigFile config) : base("bluexephops.Plugin.Guid") { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Expected O, but got Unknown //IL_0040: Expected O, but got Unknown config.SaveOnConfigSet = false; configPercent = SyncedBindingExtensions.BindSyncedEntry<float>(config, new ConfigDefinition("General", "Percentage of weight"), 1f, new ConfigDescription("Percentage of the item's weight to use for the belt bag (1 is 100%).", (AcceptableValueBase)null, Array.Empty<object>())); ClearOrphanedEntries(config); config.Save(); ConfigManager.Register<BeltBagConfig>((SyncedConfig2<BeltBagConfig>)this); } private static void ClearOrphanedEntries(ConfigFile config) { PropertyInfo propertyInfo = AccessTools.Property(typeof(ConfigFile), "OrphanedEntries"); Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)propertyInfo.GetValue(config); dictionary.Clear(); } } [HarmonyPatch(typeof(BeltBagItem))] public class BeltBagItemPatch { [HarmonyPatch("PutObjectInBagLocalClient")] [HarmonyPrefix] private static bool OnAddToBag(ref BeltBagItem __instance, object[] __args) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Expected O, but got Unknown GrabbableObject val = (GrabbableObject)__args[0]; if (Object.op_Implicit((Object)(object)val)) { ((GrabbableObject)__instance).playerHeldBy.carryWeight = Mathf.Clamp(((GrabbableObject)__instance).playerHeldBy.carryWeight + (val.itemProperties.weight - 1f) * Plugin.BoundConfig.configPercent.Value, 1f, 10f); } return true; } [HarmonyPatch("RemoveFromBagLocalClient")] [HarmonyPrefix] private static bool OnRemoveFromBag(ref BeltBagItem __instance, object[] __args) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) NetworkObjectReference val = (NetworkObjectReference)__args[0]; GrabbableObject val2 = null; NetworkObject val3 = default(NetworkObject); if (((NetworkObjectReference)(ref val)).TryGet(ref val3, (NetworkManager)null)) { for (int i = 0; i < __instance.objectsInBag.Count; i++) { if ((Object)(object)((NetworkBehaviour)__instance.objectsInBag[i]).NetworkObject == (Object)(object)val3) { val2 = __instance.objectsInBag[i]; if (((GrabbableObject)__instance).playerHeldBy.carryWeight - val2.itemProperties.weight * Plugin.BoundConfig.configPercent.Value >= 0f) { PlayerControllerB playerHeldBy = ((GrabbableObject)__instance).playerHeldBy; playerHeldBy.carryWeight -= (val2.itemProperties.weight - 1f) * Plugin.BoundConfig.configPercent.Value; } else { ((GrabbableObject)__instance).playerHeldBy.carryWeight = ((GrabbableObject)__instance).itemProperties.weight; } } } } return true; } } [HarmonyPatch(typeof(GrabbableObject))] public class GrabbableObjectPatch { [HarmonyPatch("DiscardItem")] [HarmonyPrefix] private static bool onDisardItem(ref GrabbableObject __instance) { GrabbableObject obj = __instance; BeltBagItem val = (BeltBagItem)(object)((obj is BeltBagItem) ? obj : null); if ((Object)(object)val != (Object)null && val.objectsInBag.Count > 0) { for (int i = 0; i < val.objectsInBag.Count; i++) { if (((GrabbableObject)val).playerHeldBy.carryWeight - (val.objectsInBag[i].itemProperties.weight - 1f) * Plugin.BoundConfig.configPercent.Value >= 0f) { PlayerControllerB playerHeldBy = ((GrabbableObject)val).playerHeldBy; playerHeldBy.carryWeight -= (val.objectsInBag[i].itemProperties.weight - 1f) * Plugin.BoundConfig.configPercent.Value; } else { __instance.playerHeldBy.carryWeight = 1f; } } } return true; } [HarmonyPatch("GrabItemOnClient")] [HarmonyPrefix] private static bool onAddItem(ref GrabbableObject __instance) { GrabbableObject obj = __instance; BeltBagItem val = (BeltBagItem)(object)((obj is BeltBagItem) ? obj : null); if ((Object)(object)val != (Object)null && val.objectsInBag.Count > 0) { for (int i = 0; i < val.objectsInBag.Count; i++) { ((GrabbableObject)val).playerHeldBy.carryWeight = Mathf.Clamp(((GrabbableObject)val).playerHeldBy.carryWeight + (val.objectsInBag[i].itemProperties.weight - 1f) * Plugin.BoundConfig.configPercent.Value, 1f, 10f); } } return true; } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } } namespace WeightedBeltBag.NetcodePatcher { [AttributeUsage(AttributeTargets.Module)] internal class NetcodePatchedAssemblyAttribute : Attribute { } }