Decompiled source of BetterStamina v1.0.0

BetterStamina.dll

Decompiled an hour 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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("BetterStamina")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BetterStamina")]
[assembly: AssemblyTitle("BetterStamina")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 BetterStamina
{
	[BepInPlugin("douglas.betterstamina", "BetterStamina", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "douglas.betterstamina";

		public const string PluginName = "BetterStamina";

		public const string PluginVersion = "1.0.0";

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<float> DrainMultiplier;

		internal static ConfigEntry<float> RegenMultiplier;

		private readonly Harmony _harmony = new Harmony("douglas.betterstamina");

		private void Awake()
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Master on/off switch.");
			DrainMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "DrainMultiplier", 0.4f, new ConfigDescription("Sprint drain multiplier. 1 = vanilla, 0.5 = half drain, 0 = infinite sprint.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), Array.Empty<object>()));
			RegenMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "RegenMultiplier", 1.75f, new ConfigDescription("Stamina regen multiplier. 1 = vanilla, 2 = double regen.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 5f), Array.Empty<object>()));
			_harmony.PatchAll();
			Log.LogInfo((object)"BetterStamina 1.0.0 loaded");
		}
	}
}
namespace BetterStamina.Patches
{
	[HarmonyPatch(typeof(PlayerController), "FixedUpdate")]
	internal static class SprintDrainPatch
	{
		[HarmonyPrefix]
		private static void Prefix(PlayerController __instance, out float __state)
		{
			__state = __instance.EnergySprintDrain;
			if (Plugin.Enabled.Value)
			{
				float value = Plugin.DrainMultiplier.Value;
				if (!Mathf.Approximately(value, 1f))
				{
					float sprintSpeedUpgrades = __instance.SprintSpeedUpgrades;
					__instance.EnergySprintDrain = value * (__state + sprintSpeedUpgrades) - sprintSpeedUpgrades;
				}
			}
		}

		[HarmonyFinalizer]
		private static void Finalizer(PlayerController __instance, float __state)
		{
			__instance.EnergySprintDrain = __state;
		}
	}
	[HarmonyPatch(typeof(PlayerController), "Update")]
	internal static class RegenPatch
	{
		[HarmonyPrefix]
		private static void Prefix(PlayerController __instance, out float __state)
		{
			__state = __instance.EnergyCurrent;
		}

		[HarmonyPostfix]
		private static void Postfix(PlayerController __instance, float __state)
		{
			if (Plugin.Enabled.Value)
			{
				float num = __instance.EnergyCurrent - __state;
				if (!(num <= 0f))
				{
					float num2 = __state + num * Plugin.RegenMultiplier.Value;
					__instance.EnergyCurrent = Mathf.Min(num2, __instance.EnergyStart);
				}
			}
		}
	}
}