Decompiled source of BetterStamina v1.2.0

BetterStamina.dll

Decompiled 10 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using OPJosMod.BetterStamina.Patches;
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("OPJosMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OPJosMod")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("70095872-b952-4e27-bbc4-3d70d0238f39")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace OPJosMod.BetterStamina
{
	[BepInPlugin("OpJosMod.BetterStamina", "Better Stamina", "1.0.0.1")]
	public class OpJosMod : BaseUnityPlugin
	{
		private const string modGUID = "OpJosMod.BetterStamina";

		private const string modName = "Better Stamina";

		private const string modVersion = "1.0.0.1";

		private readonly Harmony harmony = new Harmony("OpJosMod.BetterStamina");

		private static OpJosMod Instance;

		internal ManualLogSource mls;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("OpJosMod.BetterStamina");
			mls.LogInfo((object)"Better stamina mod has started");
			harmony.PatchAll(typeof(OpJosMod));
			PlayerControllerBPatch.SetLogSource(mls);
			harmony.PatchAll(typeof(PlayerControllerBPatch));
		}
	}
}
namespace OPJosMod.BetterStamina.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		private static ManualLogSource mls;

		public static void SetLogSource(ManualLogSource logSource)
		{
			mls = logSource;
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void patchUpdate(PlayerControllerB __instance)
		{
			__instance.sprintTime = 19f;
			float num = 22f;
			float num2 = 13f;
			FieldInfo field = typeof(PlayerControllerB).GetField("isWalking", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field != null)
			{
				bool flag = (bool)field.GetValue(__instance);
				if (!__instance.isPlayerControlled || __instance.isPlayerDead)
				{
					return;
				}
				float num3 = 1f;
				if (!__instance.isSprinting && __instance.isMovementHindered <= 0)
				{
					if (!flag)
					{
						__instance.sprintMeter = Mathf.Clamp(__instance.sprintMeter + Time.deltaTime / num2 * num3, 0f, 1f);
					}
					else
					{
						__instance.sprintMeter = Mathf.Clamp(__instance.sprintMeter + Time.deltaTime / num * num3, 0f, 1f);
					}
					if (__instance.isExhausted && __instance.sprintMeter > 0.2f)
					{
						__instance.isExhausted = false;
					}
				}
				__instance.sprintMeterUI.fillAmount = __instance.sprintMeter;
			}
			else
			{
				mls.LogMessage((object)"BetterStamina(error): failed to find private field");
			}
		}

		private static bool NearOtherPlayers(PlayerControllerB playerScript, float checkRadius = 10f)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			((Component)playerScript).gameObject.layer = 0;
			bool result = Physics.CheckSphere(((Component)playerScript).transform.position, checkRadius, 8, (QueryTriggerInteraction)1);
			((Component)playerScript).gameObject.layer = 3;
			return result;
		}
	}
}