Decompiled source of UnlimitedBattery v0.0.1

BepinEx/plugins/UnlimitedBattery.dll

Decompiled 7 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.1", FrameworkDisplayName = ".NET Framework 4.7.1")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace Koi.LethalCompany.UnlimitedBattery
{
	[BepInPlugin("Koi.LethalCompany.UnlimitedBattery", "Unlimited Battery", "0.0.1")]
	public class Mod : BaseUnityPlugin
	{
		private static Mod _instance;

		internal static ManualLogSource ModLogger;

		private readonly Harmony _harmony = new Harmony("Koi.LethalCompany.UnlimitedBattery");

		private void Awake()
		{
			if ((Object)(object)_instance == (Object)null)
			{
				_instance = this;
			}
			ModLogger = Logger.CreateLogSource("Koi.LethalCompany.UnlimitedBattery");
			ModLogger.LogInfo((object)"The mod has been loaded successfully");
			ModConfig.Init(((BaseUnityPlugin)this).Config);
			_harmony.PatchAll();
		}
	}
	public abstract class ModConfig
	{
		public static ConfigEntry<bool> ConfigEnabled { get; private set; }

		public static void Init(ConfigFile configFile)
		{
			ConfigEnabled = configFile.Bind<bool>("General", "Enabled", true, "Check to enable mod functionnalities, uncheck to disable.");
		}
	}
	public abstract class ModConstants
	{
		public static class Meta
		{
			public const string ModGuid = "Koi.LethalCompany.UnlimitedBattery";

			public const string ModName = "Unlimited Battery";

			public const string ModVersion = "0.0.1";
		}

		public static class Config
		{
			public static class Sections
			{
				public const string General = "General";
			}

			public static class Fields
			{
				public static class Enabled
				{
					public const string Label = "Enabled";

					public const bool DefaultValue = true;

					public const string Description = "Check to enable mod functionnalities, uncheck to disable.";
				}
			}
		}
	}
}
namespace Koi.LethalCompany.UnlimitedBattery.Patches
{
	[HarmonyPatch(typeof(GrabbableObject))]
	internal class GrabbableObjectPatches
	{
		[HarmonyPatch("SyncBatteryServerRpc")]
		[HarmonyPostfix]
		public static void UnlimitedBatteryServer(GrabbableObject __instance, ref int charge)
		{
			Debug.Log((object)"[SERVER] Hello World !");
			if (ModConfig.ConfigEnabled.Value && __instance.itemProperties.requiresBattery)
			{
				__instance.insertedBattery.empty = false;
				__instance.insertedBattery.charge = 1f;
				charge = 100;
			}
		}

		[HarmonyPatch("SyncBatteryClientRpc")]
		[HarmonyPostfix]
		public static void UnlimitedBatteryClient(GrabbableObject __instance, ref int charge)
		{
			Debug.Log((object)"[CLIENT] Hello World !");
			if (ModConfig.ConfigEnabled.Value && __instance.itemProperties.requiresBattery)
			{
				__instance.insertedBattery.empty = false;
				__instance.insertedBattery.charge = 1f;
				charge = 100;
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		public static void UnlimitedBatteryUpdate(GrabbableObject __instance)
		{
			if (ModConfig.ConfigEnabled.Value && __instance.itemProperties.requiresBattery && __instance.isHeld)
			{
				Debug.Log((object)$"[UPDATE] {__instance.insertedBattery.empty} {__instance.insertedBattery.charge}");
				__instance.insertedBattery.empty = false;
				__instance.insertedBattery.charge = 100f;
			}
		}
	}
}