Decompiled source of BetterStaminaRevived v2.1.2

BetterStaminaRevived.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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("BetterStamina")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("2.1.1.0")]
[assembly: AssemblyInformationalVersion("2.1.1")]
[assembly: AssemblyProduct("BetterStamina")]
[assembly: AssemblyTitle("BetterStamina")]
[assembly: AssemblyVersion("2.1.1.0")]
[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 BetterStamina
{
	[BepInPlugin("com.bouns.betterstamina", "Better Stamina", "2.1.1")]
	public class Plugin : BaseUnityPlugin
	{
		public enum CurveMode
		{
			Linear,
			EaseOut,
			EaseInExpo
		}

		public const string GUID = "com.bouns.betterstamina";

		public const string NAME = "Better Stamina";

		public const string VERSION = "2.1.1";

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<float> RegenRate;

		internal static ConfigEntry<float> RegenRateWeapons;

		internal static ConfigEntry<float> RegenDelay;

		internal static ConfigEntry<bool> RemoveEncumberedDrain;

		internal static ConfigEntry<bool> RemoveHammer;

		internal static ConfigEntry<bool> RemoveHoe;

		internal static ConfigEntry<bool> RemoveCultivator;

		internal static ConfigEntry<CurveMode> SkillCurve;

		internal static ConfigEntry<float> RunCost;

		internal static ConfigEntry<float> RunCostWeapons;

		internal static ConfigEntry<float> DodgeCost;

		internal static ConfigEntry<float> JumpCost;

		internal static ConfigEntry<float> BlockCost;

		internal static ConfigEntry<float> SneakCost;

		internal static ConfigEntry<float> AttackCost;

		internal static ConfigEntry<float> BowCost;

		internal static ConfigEntry<float> SwimCost;

		internal static ConfigEntry<float> ColdRegen;

		internal static ConfigEntry<float> WetRegen;

		internal static ConfigEntry<float> RestedRegen;

		internal static ConfigEntry<float> RestedDurationPerComfort;

		private void Awake()
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Expected O, but got Unknown
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Expected O, but got Unknown
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Expected O, but got Unknown
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Expected O, but got Unknown
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Expected O, but got Unknown
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Expected O, but got Unknown
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Expected O, but got Unknown
			//IL_0326: Unknown result type (might be due to invalid IL or missing references)
			//IL_0330: Expected O, but got Unknown
			//IL_0363: Unknown result type (might be due to invalid IL or missing references)
			//IL_036d: Expected O, but got Unknown
			//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03aa: Expected O, but got Unknown
			//IL_03dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e7: Expected O, but got Unknown
			//IL_041a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0424: Expected O, but got Unknown
			//IL_0457: Unknown result type (might be due to invalid IL or missing references)
			//IL_0461: Expected O, but got Unknown
			//IL_0494: Unknown result type (might be due to invalid IL or missing references)
			//IL_049e: Expected O, but got Unknown
			//IL_04aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b4: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Master switch. false = vanilla stamina.");
			RegenRate = ((BaseUnityPlugin)this).Config.Bind<float>("General", "StaminaRegenRateMod", 1.5f, new ConfigDescription("Stamina regen speed. 1 = default, 1.5 = 50% faster, 0.5 = 50% slower.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 10f), Array.Empty<object>()));
			RegenRateWeapons = ((BaseUnityPlugin)this).Config.Bind<float>("General", "StaminaRegenRateModWithWeapons", 1.4f, new ConfigDescription("Used instead of StaminaRegenRateMod when a weapon is equipped.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 10f), Array.Empty<object>()));
			RegenDelay = ((BaseUnityPlugin)this).Config.Bind<float>("General", "StaminaRegenDelay", 1f, new ConfigDescription("Seconds before stamina starts regenerating. Vanilla is around 1.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 5f), Array.Empty<object>()));
			RemoveEncumberedDrain = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "RemoveEncumberedStaminaDrain", true, "Prevents stamina drain while encumbered.");
			RemoveHammer = ((BaseUnityPlugin)this).Config.Bind<bool>("Tools", "RemoveHammerStaminaCost", true, "Building and repairing with the hammer costs no stamina.");
			RemoveHoe = ((BaseUnityPlugin)this).Config.Bind<bool>("Tools", "RemoveHoeStaminaCost", true, "Using the hoe costs no stamina.");
			RemoveCultivator = ((BaseUnityPlugin)this).Config.Bind<bool>("Tools", "RemoveCultivatorStaminaCost", true, "Using the cultivator costs no stamina.");
			SkillCurve = ((BaseUnityPlugin)this).Config.Bind<CurveMode>("Skills", "SkillCurve", CurveMode.EaseOut, "How the cost drops as the skill grows. EaseOut drops fast early then tapers. Linear is proportional. EaseInExpo drops almost only near max skill (the old mod behaviour). Costs never go above the base game at the same skill level.");
			RunCost = ((BaseUnityPlugin)this).Config.Bind<float>("Skills", "RunCostAtMaxSkill", 0.4f, new ConfigDescription("Run stamina cost at max Run skill, as a fraction of the cost at skill 0. Base game is 0.5.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 1f), Array.Empty<object>()));
			RunCostWeapons = ((BaseUnityPlugin)this).Config.Bind<float>("Skills", "RunWithWeaponsCostAtMaxSkill", 0.5f, new ConfigDescription("Used instead of RunCostAtMaxSkill when a weapon is equipped.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 1f), Array.Empty<object>()));
			DodgeCost = ((BaseUnityPlugin)this).Config.Bind<float>("Skills", "DodgeCostAtMaxSkill", 0.4f, new ConfigDescription("Dodge stamina cost at max Dodge skill, as a fraction of the cost at skill 0. Base game is 0.5.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 1f), Array.Empty<object>()));
			JumpCost = ((BaseUnityPlugin)this).Config.Bind<float>("Skills", "JumpCostAtMaxSkill", 0.67f, new ConfigDescription("Jump stamina cost at max Jump skill, as a fraction of the cost at skill 0. Base game is 1.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 1f), Array.Empty<object>()));
			BlockCost = ((BaseUnityPlugin)this).Config.Bind<float>("Skills", "BlockCostAtMaxSkill", 0.67f, new ConfigDescription("Block and parry stamina cost at max Blocking skill, as a fraction of the cost at skill 0. Base game is 1.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 1f), Array.Empty<object>()));
			SneakCost = ((BaseUnityPlugin)this).Config.Bind<float>("Skills", "SneakCostAtMaxSkill", 0.2f, new ConfigDescription("Sneak stamina cost at max Sneak skill, as a fraction of the cost at skill 0. Base game is 0.25.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 1f), Array.Empty<object>()));
			AttackCost = ((BaseUnityPlugin)this).Config.Bind<float>("Skills", "WeaponAttackCostAtMaxSkill", 0.67f, new ConfigDescription("Weapon and tool attack stamina cost at max skill, as a fraction of the cost at skill 0. Base game is 0.67.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 1f), Array.Empty<object>()));
			BowCost = ((BaseUnityPlugin)this).Config.Bind<float>("Skills", "HoldBowCostAtMaxSkill", 0.67f, new ConfigDescription("Bow draw stamina drain at max skill, as a fraction of the drain at skill 0. Base game is 0.67.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 1f), Array.Empty<object>()));
			SwimCost = ((BaseUnityPlugin)this).Config.Bind<float>("Skills", "SwimCostAtMaxSkill", 0.3f, new ConfigDescription("Swim stamina cost at max Swim skill, as a fraction of the cost at skill 0. Base game is 0.5.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 1f), Array.Empty<object>()));
			ColdRegen = ((BaseUnityPlugin)this).Config.Bind<float>("Status Effects", "ColdStaminaRegenModifier", 0.75f, new ConfigDescription("Regen multiplier while cold. Vanilla is 0.75.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), Array.Empty<object>()));
			WetRegen = ((BaseUnityPlugin)this).Config.Bind<float>("Status Effects", "WetStaminaRegenModifier", 0.85f, new ConfigDescription("Regen multiplier while wet. Vanilla is 0.85.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), Array.Empty<object>()));
			RestedRegen = ((BaseUnityPlugin)this).Config.Bind<float>("Status Effects", "RestedStaminaRegenModifier", 1.5f, new ConfigDescription("Regen multiplier while rested. Vanilla is 2.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 5f), Array.Empty<object>()));
			RestedDurationPerComfort = ((BaseUnityPlugin)this).Config.Bind<float>("Status Effects", "RestedDurationIncreasePerComfortLevel", 60f, new ConfigDescription("Seconds of rested duration added per comfort level. Vanilla is 60.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 600f), Array.Empty<object>()));
			Harmony harmony = new Harmony("com.bouns.betterstamina");
			int ok = 0;
			int ko = 0;
			Patch(typeof(Patch_Regen));
			Patch(typeof(Patch_Run));
			Patch(typeof(Patch_Sneak));
			Patch(typeof(Patch_Jump.Gate));
			Patch(typeof(Patch_Jump.Use));
			Patch(typeof(Patch_Dodge));
			Patch(typeof(Patch_Block));
			Patch(typeof(Patch_Attack));
			Patch(typeof(Patch_Bow));
			Patch(typeof(Patch_Swim));
			Patch(typeof(Patch_Tools));
			Patch(typeof(Patch_StatusEffects));
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Better Stamina v2.1.1 loaded (" + ok + " patch groups active, " + ko + " skipped)."));
			void Patch(Type t)
			{
				try
				{
					harmony.CreateClassProcessor(t).Patch();
					ok++;
				}
				catch (Exception ex)
				{
					ko++;
					((BaseUnityPlugin)this).Logger.LogError((object)("[BetterStamina] patch failed on " + t.Name + ": " + ex.Message));
				}
			}
		}

		internal static float Curve(float t)
		{
			t = Mathf.Clamp01(t);
			switch (SkillCurve.Value)
			{
			case CurveMode.Linear:
				return t;
			case CurveMode.EaseInExpo:
				if (!(t <= 0f))
				{
					return Mathf.Pow(2f, 10f * (t - 1f));
				}
				return 0f;
			default:
				return 1f - (1f - t) * (1f - t);
			}
		}

		internal static float SkillMult(float configMax, float skillFactor)
		{
			return Mathf.Lerp(1f, configMax, Curve(skillFactor));
		}

		internal static float CostMult(float configMax, float skillFactor, float vanillaMult)
		{
			return Mathf.Min(vanillaMult, SkillMult(configMax, skillFactor));
		}

		internal static float Rescale(float configMax, float skillFactor, float vanillaMult)
		{
			return CostMult(configMax, skillFactor, vanillaMult) / Mathf.Max(0.05f, vanillaMult);
		}

		internal static bool IsLocal(Character c)
		{
			if ((Object)(object)c != (Object)null)
			{
				return (Object)(object)c == (Object)(object)Player.m_localPlayer;
			}
			return false;
		}

		internal static bool HasWeapon(Humanoid h)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Invalid comparison between Unknown and I4
			ItemData val = (((Object)(object)h != (Object)null) ? h.GetCurrentWeapon() : null);
			if (val != null && val.m_shared != null)
			{
				return (int)val.m_shared.m_skillType != 11;
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(Player), "UpdateStats", new Type[] { typeof(float) })]
	internal static class Patch_Regen
	{
		internal struct State
		{
			public bool on;

			public float regen;

			public bool encOn;

			public float enc;
		}

		private static float _vanillaDelay = -1f;

		private static void Prefix(Player __instance, ref float ___m_staminaRegen, ref float ___m_encumberedStaminaDrain, ref float ___m_staminaRegenDelay, out State __state)
		{
			__state = default(State);
			if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer)
			{
				return;
			}
			if (_vanillaDelay < 0f)
			{
				_vanillaDelay = ___m_staminaRegenDelay;
			}
			if (!Plugin.Enabled.Value)
			{
				___m_staminaRegenDelay = _vanillaDelay;
				return;
			}
			___m_staminaRegenDelay = Plugin.RegenDelay.Value;
			__state.on = true;
			__state.regen = ___m_staminaRegen;
			___m_staminaRegen *= (Plugin.HasWeapon((Humanoid)(object)__instance) ? Plugin.RegenRateWeapons.Value : Plugin.RegenRate.Value);
			if (Plugin.RemoveEncumberedDrain.Value)
			{
				__state.encOn = true;
				__state.enc = ___m_encumberedStaminaDrain;
				___m_encumberedStaminaDrain = 0f;
			}
		}

		private static void Postfix(ref float ___m_staminaRegen, ref float ___m_encumberedStaminaDrain, State __state)
		{
			if (__state.on)
			{
				___m_staminaRegen = __state.regen;
				if (__state.encOn)
				{
					___m_encumberedStaminaDrain = __state.enc;
				}
			}
		}
	}
	[HarmonyPatch(typeof(Player), "CheckRun")]
	internal static class Patch_Run
	{
		private static void Prefix(Player __instance, ref float ___m_runStaminaDrain, out float __state)
		{
			__state = -1f;
			if (Plugin.Enabled.Value && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
			{
				float skillFactor = ((Character)__instance).GetSkillFactor((SkillType)102);
				float configMax = (Plugin.HasWeapon((Humanoid)(object)__instance) ? Plugin.RunCostWeapons.Value : Plugin.RunCost.Value);
				__state = ___m_runStaminaDrain;
				___m_runStaminaDrain *= Plugin.Rescale(configMax, skillFactor, Mathf.Lerp(1f, 0.5f, skillFactor));
			}
		}

		private static void Postfix(ref float ___m_runStaminaDrain, float __state)
		{
			if (__state >= 0f)
			{
				___m_runStaminaDrain = __state;
			}
		}
	}
	[HarmonyPatch(typeof(Player), "OnSneaking")]
	internal static class Patch_Sneak
	{
		private static void Prefix(Player __instance, ref float ___m_sneakStaminaDrain, out float __state)
		{
			__state = -1f;
			if (Plugin.Enabled.Value && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
			{
				float skillFactor = ((Character)__instance).GetSkillFactor((SkillType)101);
				__state = ___m_sneakStaminaDrain;
				___m_sneakStaminaDrain *= Plugin.Rescale(Plugin.SneakCost.Value, skillFactor, Mathf.Lerp(1f, 0.25f, Mathf.Pow(skillFactor, 0.5f)));
			}
		}

		private static void Postfix(ref float ___m_sneakStaminaDrain, float __state)
		{
			if (__state >= 0f)
			{
				___m_sneakStaminaDrain = __state;
			}
		}
	}
	internal static class Patch_Jump
	{
		[HarmonyPatch(typeof(Character), "Jump")]
		internal static class Gate
		{
			private static void Prefix(Character __instance, ref float ___m_jumpStaminaUsage, out float __state)
			{
				if (Begin(__instance, ref ___m_jumpStaminaUsage, out __state))
				{
					_inJump = true;
				}
			}

			private static void Finalizer(ref float ___m_jumpStaminaUsage, float __state)
			{
				if (!(__state < 0f))
				{
					___m_jumpStaminaUsage = __state;
					_inJump = false;
				}
			}
		}

		[HarmonyPatch(typeof(Player), "OnJump")]
		internal static class Use
		{
			private static void Prefix(Player __instance, ref float ___m_jumpStaminaUsage, out float __state)
			{
				Begin((Character)(object)__instance, ref ___m_jumpStaminaUsage, out __state);
			}

			private static void Finalizer(ref float ___m_jumpStaminaUsage, float __state)
			{
				if (__state >= 0f)
				{
					___m_jumpStaminaUsage = __state;
				}
			}
		}

		private static bool _inJump;

		private static bool Begin(Character c, ref float usage, out float state)
		{
			state = -1f;
			if (_inJump || !Plugin.Enabled.Value || (Object)(object)c != (Object)(object)Player.m_localPlayer)
			{
				return false;
			}
			state = usage;
			usage *= Plugin.CostMult(Plugin.JumpCost.Value, c.GetSkillFactor((SkillType)100), 1f);
			return true;
		}
	}
	[HarmonyPatch(typeof(Player), "GetDodgeStaminaUse")]
	internal static class Patch_Dodge
	{
		private static void Postfix(Player __instance, ref float __result)
		{
			if (Plugin.Enabled.Value && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && !(__result <= 0f))
			{
				float skillFactor = ((Character)__instance).GetSkillFactor((SkillType)108);
				__result *= Plugin.Rescale(Plugin.DodgeCost.Value, skillFactor, Mathf.Lerp(1f, 0.5f, skillFactor));
			}
		}
	}
	[HarmonyPatch(typeof(Humanoid), "BlockAttack")]
	internal static class Patch_Block
	{
		private static void Prefix(Humanoid __instance, ref float ___m_blockStaminaDrain, ref float ___m_perfectBlockStaminaDrain, out float[] __state)
		{
			__state = null;
			if (Plugin.Enabled.Value && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
			{
				float num = Plugin.CostMult(Plugin.BlockCost.Value, ((Character)__instance).GetSkillFactor((SkillType)6), 1f);
				__state = new float[2] { ___m_blockStaminaDrain, ___m_perfectBlockStaminaDrain };
				___m_blockStaminaDrain *= num;
				if (___m_perfectBlockStaminaDrain > 0f)
				{
					___m_perfectBlockStaminaDrain *= num;
				}
			}
		}

		private static void Finalizer(ref float ___m_blockStaminaDrain, ref float ___m_perfectBlockStaminaDrain, float[] __state)
		{
			if (__state != null)
			{
				___m_blockStaminaDrain = __state[0];
				___m_perfectBlockStaminaDrain = __state[1];
			}
		}
	}
	[HarmonyPatch(typeof(Attack), "GetAttackStamina")]
	internal static class Patch_Attack
	{
		private static void Prefix(Attack __instance, Humanoid ___m_character, ItemData ___m_weapon, out float __state)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			__state = -1f;
			if (Plugin.Enabled.Value && !(__instance.m_attackStamina <= 0f) && !((Object)(object)___m_character != (Object)(object)Player.m_localPlayer) && ___m_weapon != null && ___m_weapon.m_shared != null)
			{
				float skillFactor = ((Character)___m_character).GetSkillFactor(___m_weapon.m_shared.m_skillType);
				__state = __instance.m_attackStamina;
				__instance.m_attackStamina *= Plugin.Rescale(Plugin.AttackCost.Value, skillFactor, 1f - 0.33f * skillFactor);
			}
		}

		private static void Finalizer(Attack __instance, float __state)
		{
			if (__state >= 0f)
			{
				__instance.m_attackStamina = __state;
			}
		}
	}
	[HarmonyPatch(typeof(ItemData), "GetDrawStaminaDrain")]
	internal static class Patch_Bow
	{
		private static void Postfix(ItemData __instance, ref float __result)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if (Plugin.Enabled.Value && !((Object)(object)localPlayer == (Object)null) && !(__result <= 0f) && __instance.m_shared != null)
			{
				float skillFactor = ((Character)localPlayer).GetSkillFactor(__instance.m_shared.m_skillType);
				__result *= Plugin.Rescale(Plugin.BowCost.Value, skillFactor, 1f - 0.33f * skillFactor);
			}
		}
	}
	[HarmonyPatch(typeof(Player), "OnSwimming")]
	internal static class Patch_Swim
	{
		private static void Prefix(Player __instance, ref float ___m_swimStaminaDrainMinSkill, ref float ___m_swimStaminaDrainMaxSkill, out float[] __state)
		{
			__state = null;
			if (Plugin.Enabled.Value && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && !(___m_swimStaminaDrainMinSkill <= 0f))
			{
				float num = ___m_swimStaminaDrainMinSkill;
				float num2 = ___m_swimStaminaDrainMaxSkill;
				float skillFactor = ((Character)__instance).GetSkillFactor((SkillType)103);
				float num3 = num * Plugin.CostMult(Plugin.SwimCost.Value, skillFactor, Mathf.Lerp(1f, num2 / num, skillFactor));
				__state = new float[2] { num, num2 };
				___m_swimStaminaDrainMinSkill = num3;
				___m_swimStaminaDrainMaxSkill = num3;
			}
		}

		private static void Postfix(ref float ___m_swimStaminaDrainMinSkill, ref float ___m_swimStaminaDrainMaxSkill, float[] __state)
		{
			if (__state != null)
			{
				___m_swimStaminaDrainMinSkill = __state[0];
				___m_swimStaminaDrainMaxSkill = __state[1];
			}
		}
	}
	[HarmonyPatch(typeof(Player), "UpdatePlacement")]
	internal static class Patch_Tools
	{
		internal struct State
		{
			public Attack attack;

			public float stamina;
		}

		private static void Prefix(Player __instance, ItemData ___m_rightItem, out State __state)
		{
			__state = default(State);
			if (!Plugin.Enabled.Value || (Object)(object)__instance != (Object)(object)Player.m_localPlayer)
			{
				return;
			}
			Attack val = ___m_rightItem?.m_shared?.m_attack;
			if (val != null)
			{
				string name = ___m_rightItem.m_shared.m_name;
				if ((name == "$item_hammer" && Plugin.RemoveHammer.Value) || (name == "$item_hoe" && Plugin.RemoveHoe.Value) || (name == "$item_cultivator" && Plugin.RemoveCultivator.Value))
				{
					__state = new State
					{
						attack = val,
						stamina = val.m_attackStamina
					};
					val.m_attackStamina = 0f;
				}
			}
		}

		private static void Finalizer(State __state)
		{
			if (__state.attack != null)
			{
				__state.attack.m_attackStamina = __state.stamina;
			}
		}
	}
	[HarmonyPatch(typeof(ObjectDB), "Awake")]
	internal static class Patch_StatusEffects
	{
		private static void Postfix(ObjectDB __instance)
		{
			if (!Plugin.Enabled.Value || (Object)(object)__instance == (Object)null || __instance.m_StatusEffects == null)
			{
				return;
			}
			foreach (StatusEffect statusEffect in __instance.m_StatusEffects)
			{
				SE_Stats val = (SE_Stats)(object)((statusEffect is SE_Stats) ? statusEffect : null);
				if (val != null)
				{
					switch (statusEffect.m_name)
					{
					case "$se_cold_name":
						val.m_staminaRegenMultiplier = Plugin.ColdRegen.Value;
						break;
					case "$se_wet_name":
						val.m_staminaRegenMultiplier = Plugin.WetRegen.Value;
						break;
					case "$se_rested_name":
						val.m_staminaRegenMultiplier = Plugin.RestedRegen.Value;
						break;
					}
				}
				SE_Rested val2 = (SE_Rested)(object)((statusEffect is SE_Rested) ? statusEffect : null);
				if (val2 != null)
				{
					val2.m_TTLPerComfortLevel = Plugin.RestedDurationPerComfort.Value;
				}
			}
		}
	}
}