Decompiled source of ImBadAtNamingStuff v0.0.2

RandomPatches.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("RandomPatches")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RandomPatches")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("0784b401-5e07-41ec-a78a-df87279f6b03")]
[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")]
[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 RandomPatches
{
	public static class PluginInfo
	{
		public const string PLUGIN_ID = "RandomPatches";

		public const string PLUGIN_NAME = "RandomPatches";

		public const string PLUGIN_VERSION = "0.0.1";

		public const string PLUGIN_GUID = "cris16228.repo.randompatches";
	}
	[BepInPlugin("cris16228.repo.randompatches", "RandomPatches", "0.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		public ManualLogSource PluginLogger;

		public static ConfigEntry<bool> enableDebugLogs;

		public static ConfigEntry<bool> enableBoomboxPatch;

		public static ConfigEntry<bool> SkipLastBlockConfig;

		public static ConfigEntry<bool> enableHealthpacksGlitchPatch;

		public static ConfigEntry<bool> enableInfiniteAmmoPatch;

		public static ConfigEntry<bool> enableOverchargePatch;

		private static List<ConfigEntry<bool>> patches;

		private static int enabledPatches;

		private FileSystemWatcher fileSystemWatcher;

		public static Plugin Instance { get; private set; }

		public static void LogMessage(object message)
		{
			Instance.PluginLogger.LogMessage((object)("RandomPatches: " + message));
		}

		public static void LogError(object message)
		{
			Instance.PluginLogger.LogError((object)("RandomPatches: " + message));
		}

		public static void LogWarning(object message)
		{
			Instance.PluginLogger.LogWarning((object)("RandomPatches: " + message));
		}

		private void Awake()
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			PluginLogger = ((BaseUnityPlugin)this).Logger;
			patches = new List<ConfigEntry<bool>> { enableOverchargePatch, enableInfiniteAmmoPatch, enableHealthpacksGlitchPatch, enableBoomboxPatch };
			PluginLogger.LogInfo((object)"Loading plugin RandomPatches 0.0.1");
			LoadConfig();
			if (enabledPatches > 0)
			{
				new Harmony("cris16228.repo.randompatches").PatchAll();
			}
			PluginLogger.LogInfo((object)"Loading finished for RandomPatches 0.0.1");
			StartFileWatcher();
		}

		private void StartFileWatcher()
		{
			fileSystemWatcher = new FileSystemWatcher
			{
				Path = Paths.ConfigPath,
				Filter = "cris16228.repo.randompatches.cfg",
				NotifyFilter = NotifyFilters.LastWrite
			};
			fileSystemWatcher.Changed += OnConfigFileChanged;
			fileSystemWatcher.EnableRaisingEvents = true;
		}

		private void OnConfigFileChanged(object sender, FileSystemEventArgs e)
		{
			Thread.Sleep(2000);
			LoadConfig();
		}

		private void LoadConfig()
		{
			enabledPatches = 0;
			enableBoomboxPatch = ((BaseUnityPlugin)this).Config.Bind<bool>("Patches", "Enable music box", false, "Enable the boombox behavior patch.");
			enableHealthpacksGlitchPatch = ((BaseUnityPlugin)this).Config.Bind<bool>("Patches", "HealthPack glitch", false, "Enables the use of health packs heal while switching from shop to post-shop.");
			enableInfiniteAmmoPatch = ((BaseUnityPlugin)this).Config.Bind<bool>("Patches", "Infinite ammo glitch", false, "Enable the glitch for infinite ammo.");
			enableOverchargePatch = ((BaseUnityPlugin)this).Config.Bind<bool>("Patches", "Overcharge patch", false, "Enable the overcharge patch.");
			PluginLogger.LogInfo((object)$"Enabled {enabledPatches} patches ({patches.Count} total)");
			if (enableBoomboxPatch.Value)
			{
				enabledPatches++;
			}
			else
			{
				enabledPatches--;
			}
			if (enableHealthpacksGlitchPatch.Value)
			{
				enabledPatches++;
			}
			else
			{
				enabledPatches--;
			}
			if (enableInfiniteAmmoPatch.Value)
			{
				enabledPatches++;
			}
			else
			{
				enabledPatches--;
			}
			if (enableOverchargePatch.Value)
			{
				enabledPatches++;
			}
			else
			{
				enabledPatches--;
			}
		}
	}
}
namespace RandomPatches.Patches.Overcharge
{
	[HarmonyPatch(typeof(EnemyRigidbody), "PhysGrabOverCharge")]
	public class Patch
	{
		private static bool Prefix(EnemyRigidbody __instance)
		{
			if (Plugin.enableOverchargePatch.Value)
			{
				Plugin.LogMessage("No overcharge patch enabled");
				return false;
			}
			return true;
		}
	}
}
namespace RandomPatches.Patches.Health_Packs
{
	[HarmonyPatch(typeof(ItemHealthPack), "Start")]
	public class Patch
	{
		private static FieldRef<ItemHealthPack, ItemToggle> itemToggleRef = AccessTools.FieldRefAccess<ItemHealthPack, ItemToggle>("itemToggle");

		private static void Postfix(ItemHealthPack __instance)
		{
			if (Plugin.enableHealthpacksGlitchPatch.Value)
			{
				Plugin.LogMessage("Health packs glitch enabled");
				if (SemiFunc.RunIsShop())
				{
					itemToggleRef.Invoke(__instance).ToggleItem(true, -1);
				}
			}
		}
	}
}
namespace RandomPatches.Patches.BoomBox
{
	[HarmonyPatch(typeof(ValuableBoombox), "Update")]
	public class Patch
	{
		private static bool Skip;

		private static bool Prefix(ValuableBoombox __instance)
		{
			Skip = Plugin.enableBoomboxPatch.Value;
			typeof(ValuableBoombox).GetField("physgrabObject", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(__instance);
			if (Skip)
			{
				Plugin.LogMessage("No boombox movement patch enabled");
				return false;
			}
			return true;
		}
	}
}
namespace RandomPatches.Patches.Ammo
{
	[HarmonyPatch(typeof(ItemGun), "Update")]
	public class Patch
	{
		private static FieldRef<ItemGun, ItemBattery> itemBatteryRef = AccessTools.FieldRefAccess<ItemGun, ItemBattery>("itemBattery");

		private static bool Prefix(ItemGun __instance)
		{
			if (Plugin.enableInfiniteAmmoPatch.Value)
			{
				Plugin.LogMessage("Infinite ammo glitch enabled");
				ItemBattery val = itemBatteryRef.Invoke(__instance);
				FieldInfo field = typeof(ItemBattery).GetField("batteryLifeInt", BindingFlags.Instance | BindingFlags.NonPublic);
				if (field != null && (int)field.GetValue(val) <= 0)
				{
					field.SetValue(val, 1);
					val.batteryLife = 20f;
				}
				return true;
			}
			return true;
		}
	}
}