Decompiled source of Unlimited Universal Boxes v1.0.1

BepInEx/plugins/KeyErrorFinn-UnlimitedBoxes/KeyErrorFinn.UnlimitedBoxes.dll

Decompiled 13 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("KeyErrorFinn.UnlimitedBoxes")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("KeyErrorFinn.UnlimitedBoxes")]
[assembly: AssemblyTitle("KeyErrorFinn.UnlimitedBoxes")]
[assembly: AssemblyVersion("1.0.1.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 KeyErrorFinn.UnlimitedBoxes
{
	[BepInPlugin("com.keyerrorfinn.roadsideresearch.unlimitedboxes", "Unlimited Universal Boxes", "1.0.1")]
	public sealed class Plugin : BasePlugin
	{
		public const string Id = "com.keyerrorfinn.roadsideresearch.unlimitedboxes";

		private static PropertyInfo identity;

		private static PropertyInfo identityId;

		public override void Load()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Expected O, but got Unknown
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Expected O, but got Unknown
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Expected O, but got Unknown
			Harmony val = new Harmony("com.keyerrorfinn.roadsideresearch.unlimitedboxes");
			try
			{
				Type? type = Type.GetType("Interaction.SpawnLimits, Assembly-CSharp", throwOnError: true);
				Type type2 = Type.GetType("Interaction.SpawnObjectOnInteract, Assembly-CSharp", throwOnError: true);
				Type type3 = Type.GetType("Interaction.SpawnLimitIdentity, Assembly-CSharp", throwOnError: true);
				identity = type2.GetProperty("_spawnLimitIdentityPrefab", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) ?? throw new MissingMemberException("_spawnLimitIdentityPrefab");
				identityId = type3.GetProperty("SpawnLimitID", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) ?? throw new MissingMemberException("SpawnLimitID");
				MethodInfo method = type.GetMethod("CanSpawn", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(string) }, null);
				MethodInfo method2 = type2.GetMethod("get_ReachedSpawnLimit", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				if (method == null || method2 == null || method.ReturnType != typeof(bool) || method2.ReturnType != typeof(bool))
				{
					throw new MissingMethodException("Spawn-limit signatures changed");
				}
				val.Patch((MethodBase)method, new HarmonyMethod(typeof(Plugin), "CanSpawn", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				val.Patch((MethodBase)method2, new HarmonyMethod(typeof(Plugin), "ReachedLimit", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				((BasePlugin)this).Log.LogInfo((object)"Unlimited Universal Boxes 1.0.1: GenericBox spawn limit bypass installed (dispenser and shared check).");
			}
			catch (Exception ex)
			{
				val.UnpatchSelf();
				ManualLogSource log = ((BasePlugin)this).Log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(36, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Unlimited Universal Boxes disabled: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
				}
				log.LogError(val2);
			}
		}

		private static bool CanSpawn(string __0, ref bool __result)
		{
			if (__0 != "GenericBox")
			{
				return true;
			}
			__result = true;
			return false;
		}

		private static bool ReachedLimit(object __instance, ref bool __result)
		{
			object value = identity.GetValue(__instance);
			if (value == null || identityId.GetValue(value) as string != "GenericBox")
			{
				return true;
			}
			__result = false;
			return false;
		}
	}
}