Decompiled source of BetterSprint v0.0.2

BetterSprint.dll

Decompiled 2 months ago
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 BetterSprint.Patches;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("BetterSprint")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BetterSprint")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("3a3cbecb-7649-45fb-a632-fe41ccf069d0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BetterSprint
{
	public class Config
	{
		public static ConfigEntry<float> sprintSpeed;

		public static ConfigEntry<float> maxStamina;

		public static ConfigEntry<float> staminaRegen;

		public Config(ConfigFile cfg)
		{
			sprintSpeed = cfg.Bind<float>("General", "SprintSpeed", 2f, "Sets the speed bonus sprinting gives you.");
			maxStamina = cfg.Bind<float>("General", "maxStamina", 10f, "Sets the maximum amount of stamina you have.");
			staminaRegen = cfg.Bind<float>("General", "staminaRegen", 1f, "Sets the stamina regeneration speed. Number is a multiplier. Number can only be an positive number.");
		}
	}
	[BepInPlugin("Astro.BetterSprint", "Configurable sprint options", "0.0.2")]
	public class BetterSprintBase : BaseUnityPlugin
	{
		private const string modGUID = "Astro.BetterSprint";

		private const string modName = "Configurable sprint options";

		private const string modVersion = "0.0.2";

		private readonly Harmony harmony = new Harmony("Astro.BetterSprint");

		private static BetterSprintBase Instance;

		internal static ManualLogSource mls;

		public static Config BsConfig { get; internal set; }

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("Astro.BetterSprint");
			BsConfig = new Config(((BaseUnityPlugin)this).Config);
			mls.LogInfo((object)"The mod has awakened.");
			harmony.PatchAll(typeof(BetterSprintBase));
			harmony.PatchAll(typeof(PlayerControllerPatch));
		}
	}
}
namespace BetterSprint.Patches
{
	[HarmonyPatch(typeof(PlayerController))]
	internal class PlayerControllerPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void StartPatch(ref float ___maxStamina, ref float ___staminaRegRate, ref float ___sprintMultiplier)
		{
			BetterSprintBase.mls.LogInfo((object)"StartPatch running.");
			___maxStamina = Config.maxStamina.Value;
			___sprintMultiplier = Config.sprintSpeed.Value;
			Player.localPlayer.data.currentStamina = Config.maxStamina.Value;
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void UpdatePatch()
		{
			PlayerData data = Player.localPlayer.data;
			if (data.sinceSprint > 1f)
			{
				if (Config.staminaRegen.Value > 1f)
				{
					data.currentStamina = Mathf.MoveTowards(data.currentStamina, Config.maxStamina.Value, (Config.staminaRegen.Value - 1f) * Time.deltaTime);
				}
				else if (Config.staminaRegen.Value > 0f)
				{
					data.currentStamina = Mathf.MoveTowards(data.currentStamina, 0f, (1f - Config.staminaRegen.Value) * Time.deltaTime);
				}
			}
		}
	}
}