Decompiled source of InfiniteItemBatteryMod v1.1.0

InfiniteItemBatteryMod.dll

Decompiled 2 weeks ago
using System;
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 Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("InfiniteItemBatteryMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("InfiniteItemBatteryMod")]
[assembly: AssemblyTitle("InfiniteItemBatteryMod")]
[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 InfiniteItemBatteryMod
{
	public class ModConfig
	{
		public ConfigEntry<bool> Enabled;

		public ConfigEntry<string> ToggleKey;

		public ModConfig(ConfigFile cfg)
		{
			Enabled = cfg.Bind<bool>("General", "Enabled", true, "เป\u0e34ด/ป\u0e34ด infinite battery (true = แบตไม\u0e48จำก\u0e31ด)");
			ToggleKey = cfg.Bind<string>("General", "ToggleKey", "F6", "ค\u0e35ย\u0e4cล\u0e31ดสำหร\u0e31บ toggle mod on/off\nใส\u0e48ช\u0e37\u0e48อป\u0e38\u0e48มได\u0e49เลย เช\u0e48น F5, F6, F7, Insert, Home, Keypad0");
		}

		public KeyCode GetToggleKeyCode()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			if (Enum.TryParse<KeyCode>(ToggleKey.Value, ignoreCase: true, out KeyCode result))
			{
				return result;
			}
			Plugin.Log.LogWarning((object)("[InfiniteItemBatteryMod] Invalid ToggleKey '" + ToggleKey.Value + "', falling back to F6."));
			return (KeyCode)287;
		}
	}
	[BepInPlugin("com.yourname.infiniteitembatterymod", "InfiniteItemBatteryMod", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		internal static ModConfig Cfg;

		private readonly Harmony _harmony = new Harmony("com.yourname.infiniteitembatterymod");

		private GUIStyle _styleOn;

		private GUIStyle _styleOff;

		private bool _stylesInit;

		private float _hudTimer;

		private const float HudDuration = 2.5f;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Cfg = new ModConfig(((BaseUnityPlugin)this).Config);
			_harmony.PatchAll();
			Log.LogInfo((object)"InfiniteItemBatteryMod loaded!");
			Log.LogInfo((object)$"Enabled={Cfg.Enabled.Value} | ToggleKey={Cfg.ToggleKey.Value}");
		}

		private void Update()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetKeyDown(Cfg.GetToggleKeyCode()))
			{
				Cfg.Enabled.Value = !Cfg.Enabled.Value;
				_hudTimer = 2.5f;
				string text = (Cfg.Enabled.Value ? "ON" : "OFF");
				Log.LogInfo((object)("[InfiniteItemBatteryMod] Toggled " + text + " via hotkey."));
			}
			if (_hudTimer > 0f)
			{
				_hudTimer -= Time.deltaTime;
			}
		}

		private void InitStyles()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			if (!_stylesInit)
			{
				_styleOn = new GUIStyle
				{
					fontSize = 22,
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)4
				};
				_styleOn.normal.textColor = new Color(0.2f, 1f, 0.2f, 1f);
				_styleOff = new GUIStyle
				{
					fontSize = 22,
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)4
				};
				_styleOff.normal.textColor = new Color(1f, 0.3f, 0.3f, 1f);
				_stylesInit = true;
			}
		}

		private void OnGUI()
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			if (!(_hudTimer <= 0f))
			{
				InitStyles();
				float num = Mathf.Clamp01(_hudTimer / 0.8f);
				string text;
				GUIStyle val;
				if (Cfg.Enabled.Value)
				{
					text = "♾ Infinite Battery: ON";
					val = _styleOn;
				}
				else
				{
					text = "⬜ Infinite Battery: OFF";
					val = _styleOff;
				}
				Color textColor = val.normal.textColor;
				textColor.a = num;
				val.normal.textColor = textColor;
				GUIStyle val2 = new GUIStyle(val);
				val2.normal.textColor = new Color(0f, 0f, 0f, num * 0.6f);
				GUI.Label(new Rect((float)Screen.width / 2f - 149f, (float)Screen.height * 0.12f + 1f, 300f, 40f), text, val2);
				GUI.Label(new Rect((float)Screen.width / 2f - 150f, (float)Screen.height * 0.12f, 300f, 40f), text, val);
			}
		}
	}
}
namespace InfiniteItemBatteryMod.Patches
{
	[HarmonyPatch(typeof(ItemBattery), "RemoveFullBar")]
	public static class RemoveFullBarPatch
	{
		public static bool Prefix(ItemBattery __instance, int _bars)
		{
			if (!Plugin.Cfg.Enabled.Value)
			{
				return true;
			}
			Plugin.Log.LogInfo((object)$"[InfiniteItemBatteryMod] RemoveFullBar blocked ({_bars} bars).");
			return false;
		}
	}
	[HarmonyPatch(typeof(ItemBattery), "Update")]
	public static class UpdatePatch
	{
		public static void Postfix(ItemBattery __instance)
		{
			if (Plugin.Cfg.Enabled.Value && SemiFunc.IsMasterClientOrSingleplayer() && __instance.batteryLife < 100f)
			{
				__instance.batteryLife = 100f;
			}
		}
	}
	[HarmonyPatch(typeof(ItemBattery), "Drain")]
	public static class DrainPatch
	{
		public static bool Prefix()
		{
			if (!Plugin.Cfg.Enabled.Value)
			{
				return true;
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(ItemDrone), "StateSearching")]
	public static class ItemDroneStateSearchingPatch
	{
		public static void Postfix(ItemDrone __instance)
		{
			if (Plugin.Cfg.Enabled.Value)
			{
				ItemBattery value = Traverse.Create((object)__instance).Field("itemBattery").GetValue<ItemBattery>();
				if ((Object)(object)value != (Object)null && value.batteryLife <= 0f)
				{
					value.batteryLife = 100f;
				}
			}
		}
	}
	[HarmonyPatch(typeof(ItemDrone), "StateBeamDeployed")]
	public static class ItemDroneStateBeamDeployedPatch
	{
		public static void Postfix(ItemDrone __instance)
		{
			if (Plugin.Cfg.Enabled.Value)
			{
				ItemBattery value = Traverse.Create((object)__instance).Field("itemBattery").GetValue<ItemBattery>();
				if ((Object)(object)value != (Object)null && value.batteryLife <= 0f)
				{
					value.batteryLife = 100f;
				}
			}
		}
	}
	[HarmonyPatch(typeof(ItemDrone), "StateAttached")]
	public static class ItemDroneStateAttachedPatch
	{
		public static void Postfix(ItemDrone __instance)
		{
			if (Plugin.Cfg.Enabled.Value)
			{
				ItemBattery value = Traverse.Create((object)__instance).Field("itemBattery").GetValue<ItemBattery>();
				if ((Object)(object)value != (Object)null && value.batteryLife <= 0f)
				{
					value.batteryLife = 100f;
				}
			}
		}
	}
}