Decompiled source of XP Pickup All v1.2.2

XP_Pickup_all.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("instantcollect.port")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("instantcollect.port")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("18fb3036-dd51-466b-9493-0130fdc7a9b3")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace InstantCollect.Port
{
	[BepInPlugin("gobo.megabonk.instantcollect", "Instant Collect (BepInEx IL2CPP)", "1.2.1")]
	public class Plugin : BasePlugin
	{
		internal static ManualLogSource LogS;

		internal static ConfigEntry<string> PickupManagerTypeName;

		internal static ConfigEntry<float> IntervalSeconds;

		internal static ConfigEntry<bool> DebugLog;

		public override void Load()
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			LogS = ((BasePlugin)this).Log;
			PickupManagerTypeName = ((BasePlugin)this).Config.Bind<string>("Resolve", "PickupManagerTypeName", "PickupManager", "Type name in Assembly-CSharp (proxy). Use full name if namespaced.");
			IntervalSeconds = ((BasePlugin)this).Config.Bind<float>("Behavior", "IntervalSeconds", 5f, "How often (in seconds) to call PickupAllXp(). Try 5–10 for low overhead.");
			DebugLog = ((BasePlugin)this).Config.Bind<bool>("Debug", "DebugLog", false, "Verbose logging.");
			Harmony val = new Harmony("gobo.megabonk.instantcollect");
			val.PatchAll(typeof(PickupManager_AwakePatch));
			val.PatchAll(typeof(PickupManager_OnDestroyPatch));
			LogS.LogInfo((object)"Instant Collect (BepInEx IL2CPP) 1.2.1 loaded (timer mode).");
		}
	}
	internal static class PMResolver
	{
		internal static Type ResolvePMType()
		{
			Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "Assembly-CSharp");
			Type type = null;
			if (assembly != null)
			{
				try
				{
					Type[] types = assembly.GetTypes();
					foreach (Type type2 in types)
					{
						if (!(type2 == null) && (type2.Name == Plugin.PickupManagerTypeName.Value || type2.FullName == Plugin.PickupManagerTypeName.Value))
						{
							type = type2;
							break;
						}
					}
				}
				catch
				{
				}
			}
			if (type == null)
			{
				type = AccessTools.TypeByName(Plugin.PickupManagerTypeName.Value);
			}
			return type;
		}
	}
	[HarmonyPatch]
	internal static class PickupManager_AwakePatch
	{
		private static MethodBase TargetMethod()
		{
			Type type = PMResolver.ResolvePMType();
			if (type == null)
			{
				return null;
			}
			return type.GetMethod("Awake", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		}

		private static void Postfix(object __instance)
		{
			try
			{
				if (__instance == null)
				{
					return;
				}
				Type type = __instance.GetType();
				MethodInfo? method = type.GetMethod("PickupAllXp", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				MethodInfo method2 = type.GetMethod("InvokeRepeating", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (method == null || method2 == null)
				{
					if (Plugin.DebugLog.Value)
					{
						Plugin.LogS.LogWarning((object)("PickupAllXp or InvokeRepeating not found on " + type.FullName + ". Timer mode unavailable."));
					}
					return;
				}
				float num = Math.Max(0.1f, Plugin.IntervalSeconds.Value);
				method2.Invoke(__instance, new object[3] { "PickupAllXp", num, num });
				if (Plugin.DebugLog.Value)
				{
					Plugin.LogS.LogInfo((object)("Scheduled PickupAllXp every " + num + "s via InvokeRepeating."));
				}
			}
			catch (Exception ex)
			{
				Plugin.LogS.LogWarning((object)("Awake Postfix failed: " + ex.GetType().Name + ": " + ex.Message));
			}
		}
	}
	[HarmonyPatch]
	internal static class PickupManager_OnDestroyPatch
	{
		private static MethodBase TargetMethod()
		{
			Type type = PMResolver.ResolvePMType();
			if (type == null)
			{
				return null;
			}
			return type.GetMethod("OnDestroy", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		}

		private static void Prefix(object __instance)
		{
			try
			{
				if (__instance == null)
				{
					return;
				}
				MethodInfo method = __instance.GetType().GetMethod("CancelInvoke", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null);
				if (method != null)
				{
					method.Invoke(__instance, null);
					if (Plugin.DebugLog.Value)
					{
						Plugin.LogS.LogInfo((object)"CancelInvoke called on PickupManager (clean shutdown).");
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.LogS.LogWarning((object)("OnDestroy Prefix failed: " + ex.GetType().Name + ": " + ex.Message));
			}
		}
	}
}
namespace instantcollect.port
{
	public class Class1
	{
	}
}