using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
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("ImprovedStamina")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0+c8f2cea1b32c76bda37659e15fffea03a128d49e")]
[assembly: AssemblyProduct("Improved Stamina")]
[assembly: AssemblyTitle("ImprovedStamina")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.0.0")]
[module: UnverifiableCode]
[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 ImprovedStamina
{
[BepInPlugin("ImprovedStamina", "Improved Stamina", "1.2.0")]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Logger;
private static Harmony _harmony;
private void Awake()
{
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Expected O, but got Unknown
Logger = ((BaseUnityPlugin)this).Logger;
Logger.LogInfo((object)"Plugin ImprovedStamina is loaded!");
ConfigManager.Initialize(((BaseUnityPlugin)this).Config);
_harmony = new Harmony("ImprovedStamina");
_harmony.PatchAll();
}
}
public static class ConfigManager
{
public static ConfigEntry<float> MaxRegenRate { get; private set; }
public static ConfigEntry<float> RegenRampUpTime { get; private set; }
public static ConfigEntry<float> DelayBeforeRegen { get; private set; }
public static ConfigEntry<float> SprintDrainMultiplier { get; private set; }
public static void Initialize(ConfigFile config)
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Expected O, but got Unknown
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Expected O, but got Unknown
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Expected O, but got Unknown
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: Expected O, but got Unknown
MaxRegenRate = config.Bind<float>("Stamina Settings", "MaxRegenRate", 8f, new ConfigDescription("Maximum stamina regeneration multiplier after not sprinting for some time.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 25f), Array.Empty<object>()));
RegenRampUpTime = config.Bind<float>("Stamina Settings", "RegenRampUpTime", 3f, new ConfigDescription("Time in seconds before stamina regeneration reaches max multiplier.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 25f), Array.Empty<object>()));
DelayBeforeRegen = config.Bind<float>("Stamina Settings", "DelayBeforeRegen", 0.5f, new ConfigDescription("Time in seconds before stamina starts regenerating after stopping sprinting.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 25f), Array.Empty<object>()));
SprintDrainMultiplier = config.Bind<float>("Stamina Settings", "SprintDrainMultiplier", 1f, new ConfigDescription("Multiplier for stamina cost when sprinting. 1.0x is default.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>()));
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "ImprovedStamina";
public const string PLUGIN_NAME = "Improved Stamina";
public const string PLUGIN_VERSION = "1.2.0";
}
}
namespace ImprovedStamina.Patches
{
[HarmonyPatch(typeof(PlayerController), "LateStart")]
public static class PlayerControllerLateStartPatch
{
public static void Postfix(PlayerController __instance)
{
if (!((Object)(object)__instance == (Object)null))
{
((MonoBehaviour)__instance).StartCoroutine(AdjustSprintDrain(__instance));
}
}
private static IEnumerator AdjustSprintDrain(PlayerController player)
{
yield return (object)new WaitForSeconds(0.1f);
float energySprintDrain = player.EnergySprintDrain;
float value = ConfigManager.SprintDrainMultiplier.Value;
player.EnergySprintDrain = energySprintDrain * value;
}
}
[HarmonyPatch(typeof(PlayerController), "Update")]
public static class PlayerControllerPatch
{
private static float timeSinceStoppedSprinting;
private static float staminaRegenRate;
public static void Postfix(PlayerController __instance)
{
if ((Object)(object)__instance == (Object)null)
{
return;
}
if (__instance.sprinting)
{
timeSinceStoppedSprinting = 0f;
staminaRegenRate = 0f;
}
else
{
timeSinceStoppedSprinting += Time.deltaTime;
if (timeSinceStoppedSprinting >= ConfigManager.DelayBeforeRegen.Value)
{
float num = timeSinceStoppedSprinting - ConfigManager.DelayBeforeRegen.Value;
staminaRegenRate = Mathf.Min(ConfigManager.MaxRegenRate.Value, num / ConfigManager.RegenRampUpTime.Value * ConfigManager.MaxRegenRate.Value);
}
}
if (staminaRegenRate > 0f && __instance.EnergyCurrent < __instance.EnergyStart)
{
__instance.EnergyCurrent += staminaRegenRate * Time.deltaTime;
if (__instance.EnergyCurrent > __instance.EnergyStart)
{
__instance.EnergyCurrent = __instance.EnergyStart;
}
}
}
}
}