Please disclose if your mod was created primarily using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of RunForYourLife v1.1.5
BepInEx/plugins/RunForYourLife.dll
Decompiled 2 years agousing 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 GameNetcodeStuff; using HarmonyLib; using Unity.Netcode; using UnityEngine; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyDescription("When you use more stamina than you have, you lose life instead.")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("")] [assembly: AssemblyCopyright("Copyright © 2024")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("e279d7a9-7f26-4825-af0f-1b827a9f7ab5")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("1.0.0.0")] namespace RunForYourLife; internal class RFYLConfig { public static ConfigEntry<float> baseStamina; public static ConfigEntry<int> damageMagnitude; public static ConfigEntry<float> damageInterval; public static ConfigEntry<bool> isFatal; public static void Setup() { baseStamina = Plugin.Instance.Config.Bind<float>("Stamina", "BaseStamina", 0.8f, "How much stamina the player has before taking damage."); damageMagnitude = Plugin.Instance.Config.Bind<int>("Damage", "DamageMagnitude", 14, "The amount of damage taken per tick of damage."); damageInterval = Plugin.Instance.Config.Bind<float>("Damage", "DamageInterval", 0.1f, "How much stamina taken to cause one tick of damage."); isFatal = Plugin.Instance.Config.Bind<bool>("Damage", "IsFatal", true, "Whether you can die from oversprinting. Otherwise it'll stop when hitting critical health."); } } [HarmonyPatch(typeof(PlayerControllerB))] internal class PlayerControllerBPatch { [HarmonyPatch("Update")] [HarmonyPostfix] private static void OverStamina(ref float ___sprintMeter, ref bool ___isSprinting, ref bool ___isExhausted, ref bool ___isJumping) { //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) ManualLogSource val = Logger.CreateLogSource("RunForYourLife"); PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController; if (!(___sprintMeter <= RFYLConfig.damageInterval.Value * 2f) || !(___isSprinting | ___isJumping)) { return; } if (!localPlayerController.isPlayerDead && localPlayerController.isPlayerControlled) { if (localPlayerController.health <= RFYLConfig.damageMagnitude.Value && RFYLConfig.isFatal.Value) { localPlayerController.KillPlayer(default(Vector3), true, (CauseOfDeath)0, 0, default(Vector3)); } else { localPlayerController.DamagePlayer(RFYLConfig.damageMagnitude.Value, false, true, (CauseOfDeath)0, 0, false, default(Vector3)); if (RFYLConfig.isFatal.Value) { localPlayerController.MakeCriticallyInjured(false); } if (RFYLConfig.damageMagnitude.Value >= 10) { ___sprintMeter = Mathf.Clamp(___sprintMeter - (float)RFYLConfig.damageMagnitude.Value / 125f, 0f, RFYLConfig.baseStamina.Value); } } } ___sprintMeter += RFYLConfig.damageInterval.Value; ___isExhausted = true; } [HarmonyPatch("LateUpdate")] [HarmonyPostfix] private static void MaxStaminaAndRegen(ref float ___sprintMeter, ref bool ___isSprinting, ref bool ___isWalking, ref float ___drunkness, ref float ___sprintTime, ref float ___carryWeight, ref bool ___isExhausted, ref int ___isMovementHindered, ref Image ___sprintMeterUI, ref NetworkBehaviour ___base) { float num = 1f; PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController; if (!___base.IsOwner || (___base.IsServer && !localPlayerController.isHostPlayerObject) || !localPlayerController.isPlayerControlled || localPlayerController.isPlayerDead) { return; } if (___drunkness > 0.02f) { num *= Mathf.Abs(StartOfRound.Instance.drunknessSpeedEffect.Evaluate(___drunkness) - 1.25f); } if (___isSprinting) { ___sprintMeter = Mathf.Clamp(___sprintMeter + Time.deltaTime / ___sprintTime * ___carryWeight * num, 0f, 1f); ___sprintMeter = Mathf.Clamp(___sprintMeter - Time.deltaTime / ___sprintTime * ___carryWeight * num, 0f, RFYLConfig.baseStamina.Value); } else if (___isMovementHindered > 0) { if (___isWalking) { ___sprintMeter = Mathf.Clamp(___sprintMeter + Time.deltaTime / ___sprintTime * num * 0.5f, 0f, 1f); ___sprintMeter = Mathf.Clamp(___sprintMeter - Time.deltaTime / ___sprintTime * num * 0.5f, 0f, RFYLConfig.baseStamina.Value); } } else { if (!___isWalking) { ___sprintMeter = Mathf.Clamp(___sprintMeter - Time.deltaTime / (___sprintTime + 4f) * num, 0f, 1f); ___sprintMeter = Mathf.Clamp(___sprintMeter + Time.deltaTime / (___sprintTime + 4f) * num, 0f, RFYLConfig.baseStamina.Value); } else { ___sprintMeter = Mathf.Clamp(___sprintMeter - Time.deltaTime / (___sprintTime + 9f) * num, 0f, 1f); ___sprintMeter = Mathf.Clamp(___sprintMeter + Time.deltaTime / (___sprintTime + 9f) * num, 0f, RFYLConfig.baseStamina.Value); } if (___isExhausted && ___sprintMeter > 0.2f * RFYLConfig.baseStamina.Value) { ___isExhausted = false; } } ___sprintMeterUI.fillAmount = ___sprintMeter / RFYLConfig.baseStamina.Value; } [HarmonyPatch("Awake")] [HarmonyPostfix] private static void SetMaxStamina(ref float ___sprintMeter) { ___sprintMeter = RFYLConfig.baseStamina.Value; } } [BepInPlugin("RunForYourLife", "Run For Your Life", "0.1")] public class Plugin : BaseUnityPlugin { private const string PLUGIN_GUID = "RunForYourLife"; private const string PLUGIN_NAME = "Run For Your Life"; private const string PLUGIN_VERSION = "0.1"; private readonly Harmony harmony = new Harmony("RunForYourLife"); internal static ManualLogSource mls; public static BaseUnityPlugin Instance { get; private set; } private void Awake() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown if ((Object)Instance == (Object)null) { Instance = (BaseUnityPlugin)this; } mls = Logger.CreateLogSource("RunForYourLife"); mls.LogInfo((object)"Loaded Run For Your Life"); RFYLConfig.Setup(); harmony.PatchAll(typeof(PlayerControllerBPatch)); } }