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 TooManyItems v1.4.1
TooManyItems/TooManyItems.dll
Decompiled a year agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Logging; using HarmonyLib; using LobbyCompatibility.Enums; using LobbyCompatibility.Features; using Microsoft.CodeAnalysis; using TooManyItems.Dependency; using TooManyItems.Patches; using Unity.Collections; using Unity.Netcode; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: IgnoresAccessChecksTo("Assembly-CSharp")] [assembly: IgnoresAccessChecksTo("Unity.Netcode.Components")] [assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")] [assembly: AssemblyCompany("TooManyItems")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.4.1.0")] [assembly: AssemblyInformationalVersion("1.4.1+4a764036dce782dcccc577a698a4a188cdf4c9ea")] [assembly: AssemblyProduct("Too Many Items")] [assembly: AssemblyTitle("TooManyItems")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.4.1.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] 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 TooManyItems { [BepInPlugin("mattymatty.TooManyItems", "TooManyItems", "1.4.1")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] internal class TooManyItems : BaseUnityPlugin { public const string GUID = "mattymatty.TooManyItems"; public const string NAME = "TooManyItems"; public const string VERSION = "1.4.1"; internal static ManualLogSource Log; private void Awake() { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; try { if (LobbyCompatibilityChecker.Enabled) { LobbyCompatibilityChecker.Init(); } Log.LogInfo((object)"Patching Methods"); Harmony val = new Harmony("mattymatty.TooManyItems"); if (!Chainloader.PluginInfos.ContainsKey("mattymatty.LobbyControl")) { val.PatchAll(typeof(LimitPatcher)); } if (!Chainloader.PluginInfos.ContainsKey("mattymatty.MattyFixes")) { val.PatchAll(typeof(RadarPatch)); val.PatchAll(typeof(OutOfBoundsItemsFix)); val.PatchAll(typeof(RehostItemFixes)); } Log.LogInfo((object)"TooManyItems v1.4.1 Loaded!"); } catch (Exception ex) { Log.LogError((object)("Exception while initializing: \n" + ex)); } } } } namespace TooManyItems.Patches { [HarmonyPatch] internal class LimitPatcher { [HarmonyTranspiler] [HarmonyPatch(typeof(StartOfRound), "SyncShipUnlockablesClientRpc")] private static IEnumerable<CodeInstruction> PacketSizePatch(IEnumerable<CodeInstruction> instructions) { //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Expected O, but got Unknown //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Expected O, but got Unknown //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Expected O, but got Unknown //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Expected O, but got Unknown //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Expected O, but got Unknown //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Expected O, but got Unknown //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Expected O, but got Unknown MethodInfo method = typeof(NetworkBehaviour).GetMethod("__beginSendClientRpc", BindingFlags.Instance | BindingFlags.NonPublic); ConstructorInfo constructor = typeof(FastBufferWriter).GetConstructor(new Type[3] { typeof(int), typeof(Allocator), typeof(int) }); List<CodeInstruction> list = instructions.ToList(); CodeMatcher val = new CodeMatcher((IEnumerable<CodeInstruction>)list, (ILGenerator)null); val.MatchForward(true, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((OpCode?)OpCodes.Call, (object)method, (string)null) }); if (val.IsInvalid) { TooManyItems.Log.LogWarning((object)"PacketSize patch failed 1!!"); TooManyItems.Log.LogDebug((object)string.Join("\n", val.Instructions())); return list; } val.Advance(1); val.Insert((CodeInstruction[])(object)new CodeInstruction[5] { new CodeInstruction(OpCodes.Pop, (object)null), new CodeInstruction(OpCodes.Ldc_I4, (object)1024), new CodeInstruction(OpCodes.Ldc_I4_2, (object)null), new CodeInstruction(OpCodes.Ldc_I4, (object)int.MaxValue), new CodeInstruction(OpCodes.Newobj, (object)constructor) }); TooManyItems.Log.LogDebug((object)"Patched PacketSize!"); return val.Instructions(); } [HarmonyTranspiler] [HarmonyPriority(800)] [HarmonyPatch(typeof(StartOfRound), "SyncShipUnlockablesServerRpc")] private static IEnumerable<CodeInstruction> SyncUnlockablesPatch(IEnumerable<CodeInstruction> instructions) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Expected O, but got Unknown //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Expected O, but got Unknown //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Expected O, but got Unknown //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Expected O, but got Unknown MethodInfo method = typeof(GrabbableObject).GetMethod("GetItemDataToSave"); List<CodeInstruction> list = instructions.ToList(); CodeMatcher val = new CodeMatcher((IEnumerable<CodeInstruction>)list, (ILGenerator)null); val.End(); val.MatchBack(false, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((OpCode?)OpCodes.Callvirt, (object)method, (string)null) }); if (val.IsInvalid) { TooManyItems.Log.LogWarning((object)"SyncShipUnlockablesServerRpc patch failed 1!!"); TooManyItems.Log.LogDebug((object)string.Join("\n", val.Instructions())); return list; } val.MatchBack(false, (CodeMatch[])(object)new CodeMatch[3] { new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldc_I4, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ble, (object)null, (string)null) }); if (val.IsInvalid) { TooManyItems.Log.LogWarning((object)"SyncShipUnlockablesServerRpc patch failed 2!!"); TooManyItems.Log.LogDebug((object)string.Join("\n", val.Instructions())); return list; } List<Label> labels = val.Labels; val.RemoveInstructions(6); val.AddLabels((IEnumerable<Label>)labels); TooManyItems.Log.LogDebug((object)"Patched SyncShipUnlockablesServerRpc!!"); return val.Instructions(); } [HarmonyTranspiler] [HarmonyPriority(800)] [HarmonyPatch(typeof(GameNetworkManager), "SaveItemsInShip")] private static IEnumerable<CodeInstruction> SaveItemsInShipPatch(IEnumerable<CodeInstruction> instructions) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Expected O, but got Unknown //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Expected O, but got Unknown //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Expected O, but got Unknown //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Expected O, but got Unknown //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Expected O, but got Unknown FieldInfo field = typeof(StartOfRound).GetField("maxShipItemCapacity"); MethodInfo getMethod = typeof(StartOfRound).GetProperty("Instance").GetMethod; List<CodeInstruction> list = instructions.ToList(); CodeMatcher val = new CodeMatcher((IEnumerable<CodeInstruction>)list, (ILGenerator)null); val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[4] { new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Call, (object)getMethod, (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)field, (string)null), new CodeMatch((OpCode?)OpCodes.Bgt, (object)null, (string)null) }); if (val.IsInvalid) { TooManyItems.Log.LogWarning((object)"SaveItemsInShip patch failed 1!!"); TooManyItems.Log.LogDebug((object)string.Join("\n", val.Instructions())); return list; } List<Label> labels = val.Labels; val.RemoveInstructions(4); val.AddLabels((IEnumerable<Label>)labels); TooManyItems.Log.LogDebug((object)"Patched SaveItemsInShip!!"); return val.Instructions(); } } [HarmonyPatch] internal class OutOfBoundsItemsFix { internal static bool IsInitializingGame; [HarmonyPrefix] [HarmonyPatch(typeof(StartOfRound), "Start")] private static void MarkServerStart(StartOfRound __instance) { IsInitializingGame = true; ((MonoBehaviour)__instance).StartCoroutine(WaitCoupleOfFrames()); } private static IEnumerator WaitCoupleOfFrames() { yield return (object)new WaitForEndOfFrame(); yield return (object)new WaitForEndOfFrame(); yield return (object)new WaitForEndOfFrame(); IsInitializingGame = false; } [HarmonyTranspiler] [HarmonyPatch(typeof(GrabbableObject), "Start")] private static IEnumerable<CodeInstruction> RedirectSpawnOnGroundCheck(IEnumerable<CodeInstruction> instructions) { //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Expected O, but got Unknown //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Expected O, but got Unknown //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Expected O, but got Unknown //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Expected O, but got Unknown //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Expected O, but got Unknown //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Expected O, but got Unknown List<CodeInstruction> list = instructions.ToList(); FieldInfo fieldInfo = AccessTools.Field(typeof(GrabbableObject), "itemProperties"); FieldInfo fieldInfo2 = AccessTools.Field(typeof(Item), "itemSpawnsOnGround"); MethodInfo methodInfo = AccessTools.Method(typeof(OutOfBoundsItemsFix), "NewSpawnOnGroundCheck", (Type[])null, (Type[])null); CodeMatcher val = new CodeMatcher((IEnumerable<CodeInstruction>)list, (ILGenerator)null); val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[4] { new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)fieldInfo, (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)fieldInfo2, (string)null), new CodeMatch((OpCode?)OpCodes.Brfalse, (object)null, (string)null) }); if (val.IsInvalid) { return list; } val.Advance(1); val.RemoveInstructions(2); val.Insert((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Call, (object)methodInfo) }); TooManyItems.Log.LogDebug((object)"GrabbableObject.Start patched!"); return val.Instructions(); } private static bool NewSpawnOnGroundCheck(GrabbableObject grabbableObject) { bool itemSpawnsOnGround = grabbableObject.itemProperties.itemSpawnsOnGround; if (grabbableObject is ClipboardItem || (grabbableObject is PhysicsProp && grabbableObject.itemProperties.itemName == "Sticky note")) { return itemSpawnsOnGround; } if (Object.op_Implicit((Object)(object)StartOfRound.Instance.localPlayerController) && !IsInitializingGame) { return itemSpawnsOnGround; } return ((NetworkBehaviour)StartOfRound.Instance).IsServer; } [HarmonyPostfix] [HarmonyPatch(typeof(StartOfRound), "LoadUnlockables")] private static void CorrectlyPlaceAllUnlockables(StartOfRound __instance) { AutoParentToShip[] array = Object.FindObjectsOfType<AutoParentToShip>(); foreach (AutoParentToShip val in array) { val.MoveToOffset(); } Physics.SyncTransforms(); } [HarmonyTranspiler] [HarmonyPatch(typeof(GameNetworkManager), "SaveItemsInShip")] private static IEnumerable<CodeInstruction> SaveItemsCorrectly(IEnumerable<CodeInstruction> instructions, ILGenerator ilGenerator) { //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Expected O, but got Unknown //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Expected O, but got Unknown //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Expected O, but got Unknown //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Expected O, but got Unknown //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Expected O, but got Unknown //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Expected O, but got Unknown //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Expected O, but got Unknown //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Expected O, but got Unknown //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Expected O, but got Unknown List<CodeInstruction> list = instructions.ToList(); MethodInfo methodInfo = AccessTools.Method(typeof(OutOfBoundsItemsFix), "ApplyVerticalOffset", (Type[])null, (Type[])null); MethodInfo getMethod = AccessTools.Property(typeof(Component), "transform").GetMethod; MethodInfo getMethod2 = AccessTools.Property(typeof(Transform), "position").GetMethod; CodeMatcher val = new CodeMatcher((IEnumerable<CodeInstruction>)list, ilGenerator); val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[6] { new CodeMatch((OpCode?)OpCodes.Ldloc_2, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldloc_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldelem_Ref, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Callvirt, (object)getMethod, (string)null), new CodeMatch((OpCode?)OpCodes.Callvirt, (object)getMethod2, (string)null) }); if (val.IsInvalid) { TooManyItems.Log.LogError((object)"Cannot patch SaveItemsInShip"); TooManyItems.Log.LogDebug((object)string.Join("\n", list)); return list; } val.Advance(4); val.Insert((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Dup, (object)null) }); val.Advance(3); val.Insert((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Call, (object)methodInfo) }); TooManyItems.Log.LogDebug((object)"SaveItemsInShip Patched"); return val.Instructions(); } private static Vector3 ApplyVerticalOffset(GrabbableObject grabbable, Vector3 position) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) Vector3 val = position; if (grabbable.isHeld || grabbable.isHeldByEnemy) { return position; } if (!grabbable.hasHitGround) { val = grabbable.targetFloorPosition; } val += Vector3.down * grabbable.itemProperties.verticalOffset; return val + Vector3.up * 0.01f; } } [HarmonyPatch] internal class RadarPatch { [HarmonyPatch] internal class ItemInShipPatch { [HarmonyPostfix] [HarmonyPatch(typeof(GrabbableObject), "LateUpdate")] [HarmonyPriority(0)] private static void UpdatePatch(GrabbableObject __instance, bool __runOriginal) { if (__runOriginal && __instance.isInShipRoom && (Object)(object)__instance.radarIcon != (Object)null) { Object.Destroy((Object)(object)((Component)__instance.radarIcon).gameObject); } } } [HarmonyPatch] internal class DeletedObjectPatch { [HarmonyPrefix] [HarmonyPatch(typeof(NetworkBehaviour), "OnDestroy")] private static void DestroyPatch(NetworkBehaviour __instance) { GrabbableObject val = (GrabbableObject)(object)((__instance is GrabbableObject) ? __instance : null); if ((Object)(object)val != (Object)null && (Object)(object)val.radarIcon != (Object)null && (Object)(object)((Component)val.radarIcon).gameObject != (Object)null) { Object.Destroy((Object)(object)((Component)val.radarIcon).gameObject); } } } } [HarmonyPatch] internal class RehostItemFixes { [HarmonyPostfix] [HarmonyPatch(typeof(NetworkBehaviour), "OnNetworkSpawn")] [HarmonyPriority(20)] private static void SpawnPostfix(NetworkBehaviour __instance) { GrabbableObject val = (GrabbableObject)(object)((__instance is GrabbableObject) ? __instance : null); if (val == null || val is ClipboardItem || (val is PhysicsProp && val.itemProperties.itemName == "Sticky note") || (Object.op_Implicit((Object)(object)StartOfRound.Instance.localPlayerController) && !OutOfBoundsItemsFix.IsInitializingGame)) { return; } val.isInElevator = true; val.isInShipRoom = true; LungProp val2 = (LungProp)(object)((val is LungProp) ? val : null); if (val2 != null) { val2.isLungDocked = false; val2.isLungPowered = false; val2.isLungDockedInElevator = false; AudioSource component = ((Component)val2).GetComponent<AudioSource>(); if (component != null) { component.Stop(); } } } } } namespace TooManyItems.Dependency { public static class LobbyCompatibilityChecker { public static bool Enabled => Chainloader.PluginInfos.ContainsKey("BMX.LobbyCompatibility"); [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] public static void Init() { PluginHelper.RegisterPlugin("mattymatty.TooManyItems", Version.Parse("1.4.1"), (CompatibilityLevel)1, (VersionStrictness)0); } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } }