Decompiled source of HexInfiniteStamina v1.0.0

plugins/InfiniteStaminaMod.dll

Decompiled 2 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
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.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("InfiniteStaminaMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("InfiniteStaminaMod")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a6c4c790-44bf-4084-8891-1faaea953dfd")]
[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 InfiniteStaminaMod
{
	[BepInPlugin("com.hex.infinitestamina", "InfiniteStamina", "1.0.0")]
	public class InfiniteStaminaPlugin : BaseUnityPlugin
	{
		private const string PluginGuid = "com.hex.infinitestamina";

		private const string PluginName = "InfiniteStamina";

		private const string PluginVersion = "1.0.0";

		private Harmony _harmony;

		private ConfigEntry<KeyboardShortcut> _toggleKey;

		private ConfigEntry<bool> _modEnabled;

		private float _lastMessageTime;

		private static readonly KeyboardShortcut DefaultHotKey = new KeyboardShortcut((KeyCode)287, Array.Empty<KeyCode>());

		private const float MessageCooldown = 0.2f;

		internal static InfiniteStaminaPlugin Instance { get; private set; }

		internal static ManualLogSource Log { get; private set; }

		internal bool IsInfiniteStaminaEnabled
		{
			get
			{
				if (_modEnabled != null)
				{
					return _modEnabled.Value;
				}
				return false;
			}
		}

		private void Awake()
		{
			//IL_0022: 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_007e: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			_toggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("General", "ToggleKey", DefaultHotKey, "Hotkey to toggle infinite stamina.");
			_modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", false, "Whether infinite stamina is enabled.");
			_toggleKey.SettingChanged += OnToggleKeyChanged;
			_harmony = new Harmony("com.hex.infinitestamina");
			_harmony.PatchAll();
			Log.LogInfo((object)"v1.0.0 loaded.");
		}

		private void Update()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			if (!IsGameActive() || !IsShortcutPressedAllowingExtraKeys(_toggleKey.Value))
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			_modEnabled.Value = !_modEnabled.Value;
			bool value = _modEnabled.Value;
			if (value)
			{
				float num = ((Character)localPlayer).GetMaxStamina() - localPlayer.GetStamina();
				if (num > 0f)
				{
					((Character)localPlayer).AddStamina(num);
				}
			}
			ShowStatus(value);
		}

		private void OnDestroy()
		{
			if (_toggleKey != null)
			{
				_toggleKey.SettingChanged -= OnToggleKeyChanged;
			}
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Instance = null;
		}

		private bool IsGameActive()
		{
			if (Time.timeScale != 0f)
			{
				return (Object)(object)Player.m_localPlayer != (Object)null;
			}
			return false;
		}

		private void ShowStatus(bool isEnabled)
		{
			if (!(Time.time - _lastMessageTime < 0.2f))
			{
				_lastMessageTime = Time.time;
				string text = (isEnabled ? "Infinite Stamina: ENABLED" : "Infinite Stamina: DISABLED");
				Log.LogInfo((object)text);
				if ((Object)(object)MessageHud.instance != (Object)null)
				{
					MessageHud.instance.ShowMessage((MessageType)2, text, 0, (Sprite)null, false);
				}
			}
		}

		private void OnToggleKeyChanged(object sender, EventArgs e)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			string text = $"Hotkey updated -> {_toggleKey.Value}";
			Log.LogInfo((object)text);
			if ((Object)(object)MessageHud.instance != (Object)null)
			{
				MessageHud.instance.ShowMessage((MessageType)2, text, 0, (Sprite)null, false);
			}
		}

		private static bool IsShortcutPressedAllowingExtraKeys(KeyboardShortcut shortcut)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			if ((int)((KeyboardShortcut)(ref shortcut)).MainKey == 0)
			{
				return false;
			}
			if (!Input.GetKeyDown(((KeyboardShortcut)(ref shortcut)).MainKey))
			{
				return false;
			}
			foreach (KeyCode modifier in ((KeyboardShortcut)(ref shortcut)).Modifiers)
			{
				if (!Input.GetKey(modifier))
				{
					return false;
				}
			}
			return true;
		}
	}
}
namespace InfiniteStaminaMod.Patches
{
	[HarmonyPatch(typeof(Player), "UseStamina")]
	internal static class PlayerUseStaminaPatch
	{
		[HarmonyPrefix]
		internal static bool PreventStaminaUse(Player __instance)
		{
			if ((Object)(object)InfiniteStaminaPlugin.Instance == (Object)null || !InfiniteStaminaPlugin.Instance.IsInfiniteStaminaEnabled || (Object)(object)__instance != (Object)(object)Player.m_localPlayer)
			{
				return true;
			}
			return false;
		}
	}
}