using 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 AsyncLoggers.DBAPI;
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.3.1.0")]
[assembly: AssemblyInformationalVersion("1.3.1+5edf0cb5c28828b14c5db68ef155ce3bcd5c5cc8")]
[assembly: AssemblyProduct("Too Many Items")]
[assembly: AssemblyTitle("TooManyItems")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.3.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.3.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.3.1";
internal static ManualLogSource Log;
private void Awake()
{
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
try
{
if (LobbyCompatibilityChecker.Enabled)
{
LobbyCompatibilityChecker.Init();
}
if (AsyncLoggerProxy.Enabled)
{
AsyncLoggerProxy.WriteEvent("TooManyItems", "Awake", "Initializing");
}
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.3.1 Loaded!");
if (AsyncLoggerProxy.Enabled)
{
AsyncLoggerProxy.WriteEvent("TooManyItems", "Awake", "Finished Initializing");
}
}
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
{
[HarmonyPatch(typeof(GrabbableObject), "Start")]
[HarmonyPriority(0)]
internal class ObjectCreationPatch
{
private static void Prefix(GrabbableObject __instance, out bool __state)
{
__state = __instance.itemProperties.itemSpawnsOnGround;
if (!(__instance is ClipboardItem) && (!(__instance is PhysicsProp) || !(__instance.itemProperties.itemName == "Sticky note")) && (!Object.op_Implicit((Object)(object)StartOfRound.Instance.localPlayerController) || IsInitializingGame))
{
__instance.itemProperties.itemSpawnsOnGround = ((NetworkBehaviour)__instance).IsServer;
}
}
private static void Postfix(GrabbableObject __instance, bool __state)
{
__instance.itemProperties.itemSpawnsOnGround = __state;
}
}
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;
}
[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();
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
private static Collider GetVehicleCollider()
{
return (Collider)(object)Object.FindObjectOfType<VehicleController>()?.boundsCollider;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(RoundManager), "DespawnPropsAtEndOfRound")]
private static void ShipLeave(RoundManager __instance, bool despawnAllItems)
{
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: 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_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
GrabbableObject[] array = Object.FindObjectsOfType<GrabbableObject>();
Collider shipInnerRoomBounds = StartOfRound.Instance.shipInnerRoomBounds;
Collider val = null;
try
{
val = GetVehicleCollider();
}
catch (TypeLoadException)
{
}
Bounds bounds;
float num;
if (!((Object)(object)val == (Object)null))
{
bounds = shipInnerRoomBounds.bounds;
float y = ((Bounds)(ref bounds)).min.y;
bounds = val.bounds;
num = Math.Min(y, ((Bounds)(ref bounds)).min.y);
}
else
{
bounds = shipInnerRoomBounds.bounds;
num = ((Bounds)(ref bounds)).min.y;
}
float num2 = num;
GrabbableObject[] array2 = array;
foreach (GrabbableObject val2 in array2)
{
if (val2.isInShipRoom)
{
Transform transform = ((Component)val2).transform;
if (!(transform.position.y >= num2))
{
bounds = shipInnerRoomBounds.bounds;
transform.position = ((Bounds)(ref bounds)).center;
val2.targetFloorPosition = transform.localPosition;
val2.FallToGround(false);
}
}
}
}
[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.LogInfo((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_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: 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_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
Vector3 val = position + Vector3.down * grabbable.itemProperties.verticalOffset;
val += Vector3.up * 0.1f;
TooManyItems.Log.LogDebug((object)$"{grabbable.itemProperties.itemName}({((NetworkBehaviour)grabbable).NetworkObjectId}) fixing saved position pos:{position} newpos:{val}");
return val;
}
}
[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 || ((Object)(object)StartOfRound.Instance.localPlayerController != (Object)null && !OutOfBoundsItemsFix.IsInitializingGame))
{
return;
}
val.isInElevator = true;
val.isInShipRoom = true;
val.scrapPersistedThroughRounds = 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 AsyncLoggerProxy
{
private static bool? _enabled;
public static bool Enabled
{
get
{
if (_enabled.HasValue)
{
return _enabled.Value;
}
try
{
_enabled = isDbEnabled();
}
catch (Exception)
{
_enabled = false;
return false;
}
return _enabled.Value;
}
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void WriteEvent(string source, string tag, string data, DateTime? timestamp = null)
{
SqliteLogger.WriteEvent(source, tag, data, timestamp);
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void WriteData(string source, string tag, string data, DateTime? timestamp = null)
{
SqliteLogger.WriteData(source, tag, data, timestamp);
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static bool isDbEnabled()
{
return SqliteLogger.Enabled;
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static int getExecutionID()
{
return SqliteLogger.ExecutionId;
}
}
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.3.1"), (CompatibilityLevel)1, (VersionStrictness)0);
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}