Decompiled source of CustomStamina v0.5.46

CustomStamina.dll

Decompiled 3 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Features.Movement.Scripts;
using Features.PlayerStatesModule.Scripts;
using Features.PostProcessingModule.Scripts;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using RSG.Muffin.StatsSubmodule.EntityStatsModule.Scripts.StatsEntity;

[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("CustomStamina")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.5.46.0")]
[assembly: AssemblyInformationalVersion("0.5.46+a77f644ea306b30d7d024750ad6e6a27a23cfc6e")]
[assembly: AssemblyProduct("CustomStamina")]
[assembly: AssemblyTitle("CustomStamina")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.5.46.0")]
[module: UnverifiableCode]
[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 CustomStamina
{
	[BepInPlugin("dev.chaosholz.customstamina", "CustomStamina", "0.5.46")]
	public class Plugin : BaseUnityPlugin
	{
		private const string modGUID = "dev.chaosholz.customstamina";

		private const string modName = "CustomStamina";

		private const string modVersion = "0.5.46";

		private static readonly Harmony _harmony = new Harmony("dev.chaosholz.customstamina");

		internal static readonly ManualLogSource logger = Logger.CreateLogSource("CustomStamina");

		internal static ConfigEntry<bool> disableStaminaDrain;

		internal static ConfigEntry<bool> disableStaminaStun;

		internal static ConfigEntry<bool> disableStaminaUIEffekt;

		internal static ConfigEntry<float> sprintStaminaDrain;

		internal static ConfigEntry<float> staminaRecharge;

		internal static ConfigEntry<float> sprintSpeed;

		internal static ConfigEntry<float> walkSpeed;

		internal static ConfigEntry<float> crouchSpeed;

		private void Awake()
		{
			logger.LogInfo((object)"Plugin CustomStamina is loaded!");
			Configs();
			_harmony.PatchAll();
		}

		private void Configs()
		{
			disableStaminaDrain = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Disable Stamina Drain", false, "Disables stamina drain completely. \nfalse = normal drain, true = no stamina drain.");
			disableStaminaStun = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Disable Stamina Stun", false, "Prevents the player from being stunned when stamina is fully depleted. \nfalse = zero stamina stuns the player, true = zero stamina does not stun the player..");
			disableStaminaUIEffekt = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Disable Stamina UI Effect", false, "Disables the visual UI effect when stamina is low. \nfalse = normal UI effect, true = no stamina UI effect.");
			sprintStaminaDrain = ((BaseUnityPlugin)this).Config.Bind<float>("Stamina", "Sprint Stamina Drain", 0.5f, "Multiplier for stamina drain while sprinting. \n1.0 = normal, 0.5 = half drain, 2.0 = double drain.");
			staminaRecharge = ((BaseUnityPlugin)this).Config.Bind<float>("Stamina", "Stamina Recharge", 1f, "Multiplier for stamina recharge. \n1.0 = normal, 1.5 = 50% faster, 2.0 = double recharge speed.");
			sprintSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Speed", "Sprint Speed", 1f, "Multiplier for sprint speed. \n1.0 = normal, 1.5 = 50% faster, 2.0 = double speed.");
			walkSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Speed", "Walk Speed", 1f, "Multiplier for walk speed. \n1.0 = normal, 1.5 = 50% faster, 2.0 = double speed.");
			crouchSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Speed", "Crouch Speed", 1f, "Multiplier for crouch speed. \n1.0 = normal, 1.5 = 50% faster, 2.0 = double speed.");
		}
	}
}
namespace CustomStamina.Patches
{
	[HarmonyPatch(typeof(PlayerCharacterMovableBase), "SubtractStaminaLogic", new Type[] { typeof(float) })]
	internal static class SubtractStaminaLogicPatch
	{
		[HarmonyPrefix]
		public static void Prefix(ref float staminaDrainRate)
		{
			if (Plugin.disableStaminaDrain.Value)
			{
				staminaDrainRate = 0f;
			}
		}
	}
	[HarmonyPatch(typeof(PlayerStunHandleSystem), "TryStunPlayerByHiddenStamina", new Type[] { typeof(float) })]
	internal static class TryStunPlayerByHiddenStaminaPatch
	{
		[HarmonyPrefix]
		private static bool Prefix()
		{
			if (Plugin.disableStaminaStun.Value)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(StaminaVignetteAdjustingSystem), "AdjustVignette", new Type[] { typeof(float) })]
	internal static class AdjustVignettePatch
	{
		[HarmonyPrefix]
		public static bool Prefix()
		{
			if (Plugin.disableStaminaUIEffekt.Value)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(PlayerCharacterMovableBase), "InitizeStats")]
	internal static class InitizeStatsPatch
	{
		private static readonly FieldRef<PlayerCharacterMovableBase, IStat> sprintSpeedStat = AccessTools.FieldRefAccess<PlayerCharacterMovableBase, IStat>("_sprintSpeedStat");

		private static readonly FieldRef<PlayerCharacterMovableBase, IStat> walkSpeedStat = AccessTools.FieldRefAccess<PlayerCharacterMovableBase, IStat>("_walkSpeedStat");

		private static readonly FieldRef<PlayerCharacterMovableBase, IStat> crouchSpeedStat = AccessTools.FieldRefAccess<PlayerCharacterMovableBase, IStat>("_crouchSpeedStat");

		private static readonly FieldRef<PlayerCharacterMovableBase, IStat> staminaRechargeRateStat = AccessTools.FieldRefAccess<PlayerCharacterMovableBase, IStat>("_staminaRechargeRateStat");

		private static readonly FieldRef<PlayerCharacterMovableBase, IStat> staminaRechargeRateOnPunishStat = AccessTools.FieldRefAccess<PlayerCharacterMovableBase, IStat>("_staminaRechargeRateOnPunishStat");

		private static readonly FieldRef<PlayerCharacterMovableBase, IStat> staminaDrainRateStat = AccessTools.FieldRefAccess<PlayerCharacterMovableBase, IStat>("_staminaDrainRateStat");

		[HarmonyPostfix]
		public static void Postfix(PlayerCharacterMovableBase __instance)
		{
			IStat obj = sprintSpeedStat.Invoke(__instance);
			float num = obj.FullValue * Plugin.sprintSpeed.Value;
			obj.OverrideValue(num);
			IStat obj2 = walkSpeedStat.Invoke(__instance);
			float num2 = obj2.FullValue * Plugin.walkSpeed.Value;
			obj2.OverrideValue(num2);
			IStat obj3 = crouchSpeedStat.Invoke(__instance);
			float num3 = obj3.FullValue * Plugin.crouchSpeed.Value;
			obj3.OverrideValue(num3);
			IStat obj4 = staminaRechargeRateStat.Invoke(__instance);
			float num4 = obj4.FullValue * Plugin.staminaRecharge.Value;
			obj4.OverrideValue(num4);
			IStat obj5 = staminaRechargeRateOnPunishStat.Invoke(__instance);
			float num5 = obj5.FullValue * Plugin.staminaRecharge.Value;
			obj5.OverrideValue(num5);
			IStat obj6 = staminaDrainRateStat.Invoke(__instance);
			float num6 = obj6.FullValue * Plugin.sprintStaminaDrain.Value;
			obj6.OverrideValue(num6);
		}
	}
}