Decompiled source of FullHPSprint v1.4.0

FullHPSprint.dll

Decompiled 2 weeks ago
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using FullHPSprint.Patches;
using GameNetcodeStuff;
using HarmonyLib;
using Unity.Netcode;
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("FullHPSprint")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FullHPSprint")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("0881498b-da41-4e5e-9cdb-ca173ed6881f")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
[HarmonyPatch(typeof(NetworkManager))]
internal static class NetworkPrefabPatch2
{
	private static readonly string MOD_GUID = "EventhorizonHeve.FullHPSprint";

	[HarmonyPostfix]
	[HarmonyPatch("SetSingleton")]
	private static void RegisterPrefab()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject(MOD_GUID + " Prefab");
		((Object)val).hideFlags = (HideFlags)(((Object)val).hideFlags | 0x3D);
		Object.DontDestroyOnLoad((Object)(object)val);
		NetworkObject obj = val.AddComponent<NetworkObject>();
		FieldInfo field = typeof(NetworkObject).GetField("GlobalObjectIdHash", BindingFlags.Instance | BindingFlags.NonPublic);
		field.SetValue(obj, GetHash(MOD_GUID));
		NetworkManager.Singleton.PrefabHandler.AddNetworkPrefab(val);
		static uint GetHash(string value)
		{
			return value?.Aggregate(17u, (uint current, char c) => (current * 31) ^ c) ?? 0;
		}
	}
}
namespace FullHPSprint
{
	[BepInPlugin("EventhorizonHeve.FullHPSprint", "FullHPSprint", "1.4.0")]
	public class FullHPSprintModBase : BaseUnityPlugin
	{
		public const string modGUID = "EventhorizonHeve.FullHPSprint";

		private const string modName = "FullHPSprint";

		private const string modVersion = "1.4.0";

		private readonly Harmony harmony = new Harmony("EventhorizonHeve.FullHPSprint");

		private static FullHPSprintModBase Instance;

		internal ManualLogSource mls;

		public static ConfigEntry<bool> InfiniteSprint { get; set; }

		public static ConfigEntry<bool> AlwaysApplySprintMultiplier { get; set; }

		public static ConfigEntry<bool> AlwaysApplyJumpMultiplier { get; set; }

		public static ConfigEntry<float> SprintMultiplier { get; set; }

		public static ConfigEntry<float> JumpCostMultiplier { get; set; }

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("EventhorizonHeve.FullHPSprint");
			mls.LogInfo((object)"Useless awake log from: FullHPSprint");
			_bind_config();
			harmony.PatchAll(typeof(FullHPSprintModBase));
			harmony.PatchAll(typeof(PlayerControllerBPatch));
			harmony.PatchAll(typeof(NetworkPrefabPatch2));
		}

		private void _bind_config()
		{
			InfiniteSprint = ((BaseUnityPlugin)this).Config.Bind<bool>("Infinite Sprint", "Infinite Sprint", true, "Gives infinite sprint when on full HP, regardless of any other settings. Additionally removes sprint drain from jumping!");
			AlwaysApplySprintMultiplier = ((BaseUnityPlugin)this).Config.Bind<bool>("Sprint Settings", "Always apply sprint multiplier", false, "Enabling this setting will always apply the sprint multiplier, even if you don't have full HP!");
			SprintMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Sprint Settings", "Sprint Cost Multiplier", 0.5f, "How many times FASTER the sprint will drain when on full HP (0.5 means 2x slower)! Influences only sprint cost.");
			AlwaysApplyJumpMultiplier = ((BaseUnityPlugin)this).Config.Bind<bool>("Jump Settings", "Always apply jump multiplier", false, "Enabling this setting will always apply the jump multiplier, even if you don't have full HP!");
			JumpCostMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Jump Settings", "Jump Cost Multiplier", 1f, "How much a jump should drain sprint when on full HP (1 is default, 0 is nothing). Influences only jumping.");
		}
	}
}
namespace FullHPSprint.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		private static float newSprintMeter;

		private static float jumpSprintMeterBuffer;

		[HarmonyPatch("Update")]
		[HarmonyPrefix]
		private static void UpdatePrefix(ref float ___sprintMeter)
		{
			newSprintMeter = ___sprintMeter;
		}

		[HarmonyPatch("LateUpdate")]
		[HarmonyPostfix]
		private static void LateUpdatePatch(PlayerControllerB __instance, ref float ___sprintMeter, ref int ___health, ref float ___sprintTime, ref float ___carryWeight, ref bool ___isSprinting, ref float ___drunkness)
		{
			if (!((NetworkBehaviour)__instance).IsOwner)
			{
				return;
			}
			if (___isSprinting && (___health >= 100 || FullHPSprintModBase.AlwaysApplySprintMultiplier.Value) && (!FullHPSprintModBase.InfiniteSprint.Value || ___health < 100))
			{
				float num = 1f;
				if (___drunkness > 0.02f && (Object)(object)StartOfRound.Instance != (Object)null && StartOfRound.Instance.drunknessSpeedEffect != null)
				{
					num *= Mathf.Abs(StartOfRound.Instance.drunknessSpeedEffect.Evaluate(___drunkness) - 1.25f);
				}
				newSprintMeter = Mathf.Clamp(newSprintMeter - Time.deltaTime / ___sprintTime * ___carryWeight * num * FullHPSprintModBase.SprintMultiplier.Value, 0f, 1f);
				___sprintMeter = newSprintMeter;
			}
			else if (FullHPSprintModBase.InfiniteSprint.Value && ___health >= 100)
			{
				___sprintMeter = 1f;
			}
		}

		[HarmonyPatch("Jump_performed")]
		[HarmonyPrefix]
		private static void Jump_performedPre(ref float ___sprintMeter)
		{
			jumpSprintMeterBuffer = ___sprintMeter;
		}

		[HarmonyPatch("Jump_performed")]
		[HarmonyPostfix]
		private static void Jump_performedPost(ref float ___sprintMeter, ref int ___health)
		{
			if (jumpSprintMeterBuffer != ___sprintMeter && (___health >= 100 || FullHPSprintModBase.AlwaysApplyJumpMultiplier.Value) && (!FullHPSprintModBase.InfiniteSprint.Value || ___health < 100))
			{
				jumpSprintMeterBuffer = Mathf.Clamp(jumpSprintMeterBuffer - 0.08f * FullHPSprintModBase.JumpCostMultiplier.Value, 0f, 1f);
				___sprintMeter = jumpSprintMeterBuffer;
			}
		}
	}
}