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 HarmonyLib;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using YAPYAP;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("InfiniteStamina")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("HP")]
[assembly: AssemblyProduct("InfiniteStamina")]
[assembly: AssemblyCopyright("Copyright © HP 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("10162207-c3b2-4536-9678-c52d48cfe13d")]
[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 YapYapInfiniteStamina;
[BepInPlugin("controllerv.infinitestamina", "Infinite Stamina Toggle", "1.0.0")]
public class InfiniteStaminaPlugin : BaseUnityPlugin
{
public static ConfigEntry<KeyCode> ToggleKey;
private static ControllerStaminaComponent localStaminaComp;
private bool isInfiniteActive = false;
private void Awake()
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
ToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "ToggleKey", (KeyCode)105, "The key used to toggle infinite stamina. (e.g. I, F1, LeftControl)");
((BaseUnityPlugin)this).Logger.LogInfo((object)$"Infinite Stamina Mod Loaded! Current toggle key: {ToggleKey.Value}");
Harmony.CreateAndPatchAll(typeof(InfiniteStaminaPlugin), (string)null);
}
private void Update()
{
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
if ((Input.GetKeyDown((KeyCode)13) || Input.GetKeyDown((KeyCode)271)) && (Object)(object)EventSystem.current != (Object)null)
{
EventSystem.current.SetSelectedGameObject((GameObject)null);
}
if (!IsPlayerTyping() && Input.GetKeyDown(ToggleKey.Value))
{
if (localStaminaComp != null)
{
isInfiniteActive = !isInfiniteActive;
localStaminaComp.SetInfiniteStamina(isInfiniteActive);
((BaseUnityPlugin)this).Logger.LogInfo((object)$"Infinite Stamina toggled: {isInfiniteActive}");
}
else
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"Stamina component not found. Make sure you are in a match.");
}
}
}
private bool IsPlayerTyping()
{
EventSystem current = EventSystem.current;
if ((Object)(object)current == (Object)null)
{
return false;
}
GameObject currentSelectedGameObject = current.currentSelectedGameObject;
if ((Object)(object)currentSelectedGameObject == (Object)null)
{
return false;
}
if (!currentSelectedGameObject.activeInHierarchy)
{
return false;
}
InputField component = currentSelectedGameObject.GetComponent<InputField>();
if ((Object)(object)component != (Object)null && component.isFocused)
{
return true;
}
MonoBehaviour[] components = currentSelectedGameObject.GetComponents<MonoBehaviour>();
MonoBehaviour[] array = components;
foreach (MonoBehaviour val in array)
{
if (!((Object)(object)val != (Object)null))
{
continue;
}
Type type = ((object)val).GetType();
if (type.Name.Contains("InputField"))
{
PropertyInfo property = type.GetProperty("isFocused");
if (!(property != null))
{
return true;
}
if ((bool)property.GetValue(val))
{
return true;
}
}
}
return false;
}
[HarmonyPatch(typeof(ControllerStaminaComponent), "OnEnterState")]
[HarmonyPostfix]
private static void PostfixOnEnter(ControllerStaminaComponent __instance)
{
Traverse val = Traverse.Create((object)__instance).Property("Controller", (object[])null);
if (!val.PropertyExists())
{
return;
}
object value = val.GetValue();
if (value != null)
{
Traverse val2 = Traverse.Create(value).Property("isLocalPlayer", (object[])null);
if (val2.PropertyExists() && val2.GetValue<bool>())
{
localStaminaComp = __instance;
Debug.Log((object)"[Mod] Successfully captured local player's stamina component.");
}
}
}
}