Decompiled source of RealisticExhaustion v1.1.0

Mods/RealisticExhaustion.dll

Decompiled 6 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using MelonLoader;
using MelonLoader.Preferences;
using ModThatIsNotMod;
using ModThatIsNotMod.BoneMenu;
using RealisticExhaustion;
using StressLevelZero.Interaction;
using StressLevelZero.Rig;
using StressLevelZero.VRMK;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Main), "Realistic Exhaustion", "1.1.0", "ffba", null)]
[assembly: MelonGame("Stress Level Zero", "BONEWORKS")]
[assembly: AssemblyTitle("bwmodtest")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("HP")]
[assembly: AssemblyProduct("bwmodtest")]
[assembly: AssemblyCopyright("Copyright © HP 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ccd630c4-aea7-4b16-8b51-00e3cc2e217e")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace RealisticExhaustion;

public class Main : MelonMod
{
	public static Main Instance;

	private MelonPreferences_Category prefCategory;

	public MelonPreferences_Entry<float> prefMaxStamina;

	public MelonPreferences_Entry<float> prefWeightThreshold;

	public MelonPreferences_Entry<float> prefRegenRate;

	public MelonPreferences_Entry<float> prefMinWeakness;

	public MelonPreferences_Entry<bool> prefExhaustionNotifs;

	public MelonPreferences_Entry<bool> prefGrabNotifs;

	public MelonPreferences_Entry<float> prefJumpTax;

	public MelonPreferences_Entry<bool> prefErrorDrainEnabled;

	public MelonPreferences_Entry<float> prefErrorMultiplier;

	public MelonPreferences_Entry<float> prefLeftArmStrength;

	public MelonPreferences_Entry<float> prefRightArmStrength;

	public MelonPreferences_Entry<bool> prefGripSlippingEnabled;

	public MelonPreferences_Entry<bool> prefHandShakeEnabled;

	public MelonPreferences_Entry<float> prefHandShakeIntensity;

	public MelonPreferences_Entry<bool> prefLegsEnabled;

	public MelonPreferences_Entry<bool> prefLegNotifs;

	public MelonPreferences_Entry<float> prefLegMaxStamina;

	public MelonPreferences_Entry<float> prefLegRegenRate;

	public MelonPreferences_Entry<float> prefLegMinWeakness;

	public MelonPreferences_Entry<float> prefSprintThreshold;

	public MelonPreferences_Entry<float> prefWalkDrainMultiplier;

	public MelonPreferences_Entry<float> prefDefaultSpeed;

	public MelonPreferences_Entry<bool> prefDefaultSprintToggle;

	public MelonPreferences_Entry<float> prefDefaultJumpPower;

	private float lStamina = 50f;

	private bool lExhausted;

	private float lExhaustionTimer;

	private float lFloor = 1f;

	private float lMult = 1f;

	private GameObject lastLeftObj;

	private float rStamina = 50f;

	private bool rExhausted;

	private float rExhaustionTimer;

	private float rFloor = 1f;

	private float rMult = 1f;

	private GameObject lastRightObj;

	private float legStamina;

	private float regenDelayTimer;

	private bool wasSprintLocked;

	private const float _BaseAcceleration = 7f;

	private const float _BaseMaxVel = 2f;

	private float defaultBreakForce = float.MaxValue;

	private float defaultBreakTorque = float.MaxValue;

	private bool gripDefaultsStored;

	private FloatElement lStatsDisplay;

	private FloatElement rStatsDisplay;

	private FloatElement legStatsDisplay;

	public override void OnApplicationStart()
	{
		//IL_0313: Unknown result type (might be due to invalid IL or missing references)
		//IL_0323: Unknown result type (might be due to invalid IL or missing references)
		//IL_0333: Unknown result type (might be due to invalid IL or missing references)
		//IL_036a: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_040f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0446: Unknown result type (might be due to invalid IL or missing references)
		//IL_046d: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_04db: Unknown result type (might be due to invalid IL or missing references)
		//IL_0502: Unknown result type (might be due to invalid IL or missing references)
		//IL_0529: Unknown result type (might be due to invalid IL or missing references)
		//IL_0550: Unknown result type (might be due to invalid IL or missing references)
		//IL_0576: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_05bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_060b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0642: Unknown result type (might be due to invalid IL or missing references)
		//IL_0679: Unknown result type (might be due to invalid IL or missing references)
		//IL_06b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_06e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_071e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0755: Unknown result type (might be due to invalid IL or missing references)
		//IL_078c: Unknown result type (might be due to invalid IL or missing references)
		//IL_07b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_07e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_07f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0831: Unknown result type (might be due to invalid IL or missing references)
		//IL_083b: Expected O, but got Unknown
		//IL_0841: Unknown result type (might be due to invalid IL or missing references)
		//IL_087a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0884: Expected O, but got Unknown
		//IL_088a: Unknown result type (might be due to invalid IL or missing references)
		//IL_08c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_08cd: Expected O, but got Unknown
		Instance = this;
		prefCategory = MelonPreferences.CreateCategory("RealisticExhaustion");
		prefMaxStamina = prefCategory.CreateEntry<float>("MaxStamina", 50f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		prefWeightThreshold = prefCategory.CreateEntry<float>("WeightThreshold", 2f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		prefRegenRate = prefCategory.CreateEntry<float>("RegenRate", 1f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		prefMinWeakness = prefCategory.CreateEntry<float>("MinWeakness", 0.1f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		prefExhaustionNotifs = prefCategory.CreateEntry<bool>("ExhaustionNotifs", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		prefGrabNotifs = prefCategory.CreateEntry<bool>("GrabNotifs", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		prefJumpTax = prefCategory.CreateEntry<float>("JumpTax", 5f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		prefErrorDrainEnabled = prefCategory.CreateEntry<bool>("ErrorDrainEnabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		prefErrorMultiplier = prefCategory.CreateEntry<float>("ErrorMultiplier", 0.5f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		prefLeftArmStrength = prefCategory.CreateEntry<float>("LeftArmDefaultStrength", 1f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		prefRightArmStrength = prefCategory.CreateEntry<float>("RightArmDefaultStrength", 1f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		prefGripSlippingEnabled = prefCategory.CreateEntry<bool>("GripSlippingEnabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		prefHandShakeEnabled = prefCategory.CreateEntry<bool>("HandShakeEnabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		prefHandShakeIntensity = prefCategory.CreateEntry<float>("HandShakeIntensity", 0.5f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		prefLegsEnabled = prefCategory.CreateEntry<bool>("LegsEnabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		prefLegNotifs = prefCategory.CreateEntry<bool>("LegNotifs", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		prefLegMaxStamina = prefCategory.CreateEntry<float>("LegMaxStamina", 70f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		prefLegRegenRate = prefCategory.CreateEntry<float>("LegRegenRate", 1f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		prefLegMinWeakness = prefCategory.CreateEntry<float>("LegMinWeakness", 0.3f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		prefSprintThreshold = prefCategory.CreateEntry<float>("SprintLockThreshold", 10f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		prefWalkDrainMultiplier = prefCategory.CreateEntry<float>("WalkDrainMultiplier", 1f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		prefDefaultSpeed = prefCategory.CreateEntry<float>("DefaultSpeed", 1f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		prefDefaultSprintToggle = prefCategory.CreateEntry<bool>("DefaultSprintToggle", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		prefDefaultJumpPower = prefCategory.CreateEntry<float>("DefaultJumpPower", 1f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		MenuCategory obj = MenuManager.CreateCategory("Realistic Exhaustion", Color.yellow);
		MenuCategory obj2 = obj.CreateSubCategory("Arm Settings", Color.white);
		obj2.CreateFloatElement("Max Stamina", Color.cyan, prefMaxStamina.Value, (Action<float>)delegate(float v)
		{
			prefMaxStamina.Value = v;
			prefCategory.SaveToFile(true);
		}, 10f, 10f, 500f, true);
		obj2.CreateFloatElement("Weight Threshold", Color.green, prefWeightThreshold.Value, (Action<float>)delegate(float v)
		{
			prefWeightThreshold.Value = v;
			prefCategory.SaveToFile(true);
		}, 0.5f, 0f, 10f, true);
		obj2.CreateFloatElement("Regen Rate", Color.yellow, prefRegenRate.Value, (Action<float>)delegate(float v)
		{
			prefRegenRate.Value = v;
			prefCategory.SaveToFile(true);
		}, 0.5f, 0.1f, 50f, true);
		obj2.CreateFloatElement("Left Arm Strength", Color.blue, prefLeftArmStrength.Value, (Action<float>)delegate(float v)
		{
			prefLeftArmStrength.Value = v;
			prefCategory.SaveToFile(true);
		}, 0.1f, 0.1f, 3f, true);
		obj2.CreateFloatElement("Right Arm Strength", Color.blue, prefRightArmStrength.Value, (Action<float>)delegate(float v)
		{
			prefRightArmStrength.Value = v;
			prefCategory.SaveToFile(true);
		}, 0.1f, 0.1f, 3f, true);
		obj2.CreateBoolElement("Struggle Drain", Color.white, prefErrorDrainEnabled.Value, (Action<bool>)delegate(bool v)
		{
			prefErrorDrainEnabled.Value = v;
			prefCategory.SaveToFile(true);
		});
		obj2.CreateFloatElement("Struggle Intensity", Color.magenta, prefErrorMultiplier.Value, (Action<float>)delegate(float v)
		{
			prefErrorMultiplier.Value = v;
			prefCategory.SaveToFile(true);
		}, 0.1f, 0.1f, 10f, true);
		obj2.CreateFloatElement("Min Weakness", Color.red, prefMinWeakness.Value, (Action<float>)delegate(float v)
		{
			prefMinWeakness.Value = v;
			prefCategory.SaveToFile(true);
		}, 0.1f, 0.1f, 1f, true);
		obj2.CreateBoolElement("Exhaustion Notifs", Color.white, prefExhaustionNotifs.Value, (Action<bool>)delegate(bool v)
		{
			prefExhaustionNotifs.Value = v;
			prefCategory.SaveToFile(true);
		});
		obj2.CreateBoolElement("Grab Notifs", Color.white, prefGrabNotifs.Value, (Action<bool>)delegate(bool v)
		{
			prefGrabNotifs.Value = v;
			prefCategory.SaveToFile(true);
		});
		obj2.CreateBoolElement("Grip Slipping", Color.white, prefGripSlippingEnabled.Value, (Action<bool>)delegate(bool v)
		{
			prefGripSlippingEnabled.Value = v;
			prefCategory.SaveToFile(true);
			RestoreGripIfDisabled();
		});
		obj2.CreateBoolElement("Hand Shake at 0%", Color.white, prefHandShakeEnabled.Value, (Action<bool>)delegate(bool v)
		{
			prefHandShakeEnabled.Value = v;
			prefCategory.SaveToFile(true);
		});
		obj2.CreateFloatElement("Hand Shake Intensity", Color.magenta, prefHandShakeIntensity.Value, (Action<float>)delegate(float v)
		{
			prefHandShakeIntensity.Value = v;
			prefCategory.SaveToFile(true);
		}, 0.1f, 0.1f, 2f, true);
		MenuCategory obj3 = obj.CreateSubCategory("Leg Settings", Color.green);
		obj3.CreateBoolElement("Enable Leg System", Color.white, prefLegsEnabled.Value, (Action<bool>)delegate(bool v)
		{
			prefLegsEnabled.Value = v;
			prefCategory.SaveToFile(true);
		});
		obj3.CreateBoolElement("Leg Notifications", Color.white, prefLegNotifs.Value, (Action<bool>)delegate(bool v)
		{
			prefLegNotifs.Value = v;
			prefCategory.SaveToFile(true);
		});
		obj3.CreateFloatElement("Max Leg Stamina", Color.cyan, prefLegMaxStamina.Value, (Action<float>)delegate(float v)
		{
			prefLegMaxStamina.Value = v;
			prefCategory.SaveToFile(true);
		}, 10f, 10f, 500f, true);
		obj3.CreateFloatElement("Regen Rate", Color.yellow, prefLegRegenRate.Value, (Action<float>)delegate(float v)
		{
			prefLegRegenRate.Value = v;
			prefCategory.SaveToFile(true);
		}, 0.5f, 0.1f, 50f, true);
		obj3.CreateFloatElement("Walk Drain Multiplier", Color.blue, prefWalkDrainMultiplier.Value, (Action<float>)delegate(float v)
		{
			prefWalkDrainMultiplier.Value = v;
			prefCategory.SaveToFile(true);
		}, 0.1f, 0f, 5f, true);
		obj3.CreateFloatElement("Jump Tax", Color.magenta, prefJumpTax.Value, (Action<float>)delegate(float v)
		{
			prefJumpTax.Value = v;
			prefCategory.SaveToFile(true);
		}, 1f, 0f, 50f, true);
		obj3.CreateFloatElement("Min Weakness", Color.red, prefLegMinWeakness.Value, (Action<float>)delegate(float v)
		{
			prefLegMinWeakness.Value = v;
			prefCategory.SaveToFile(true);
		}, 0.1f, 0.1f, 1f, true);
		obj3.CreateFloatElement("Sprint Lock at:", Color.white, prefSprintThreshold.Value, (Action<float>)delegate(float v)
		{
			prefSprintThreshold.Value = v;
			prefCategory.SaveToFile(true);
		}, 1f, 0f, 50f, true);
		obj3.CreateFloatElement("Default Speed", Color.cyan, prefDefaultSpeed.Value, (Action<float>)delegate(float v)
		{
			prefDefaultSpeed.Value = v;
			prefCategory.SaveToFile(true);
		}, 0.1f, 0.1f, 3f, true);
		obj3.CreateBoolElement("Default Sprint Toggle", Color.white, prefDefaultSprintToggle.Value, (Action<bool>)delegate(bool v)
		{
			prefDefaultSprintToggle.Value = v;
			prefCategory.SaveToFile(true);
		});
		obj3.CreateFloatElement("Default Jump Power", Color.magenta, prefDefaultJumpPower.Value, (Action<float>)delegate(float v)
		{
			prefDefaultJumpPower.Value = v;
			prefCategory.SaveToFile(true);
		}, 0.1f, 0.1f, 3f, true);
		MenuCategory obj4 = obj.CreateSubCategory("Real-Time Stats", Color.gray);
		lStatsDisplay = new FloatElement("L-Stamina %", Color.white, 100f, (Action<float>)delegate
		{
		}, 0f, 0f, 100f, false);
		rStatsDisplay = new FloatElement("R-Stamina %", Color.white, 100f, (Action<float>)delegate
		{
		}, 0f, 0f, 100f, false);
		legStatsDisplay = new FloatElement("Leg Stamina %", Color.green, 100f, (Action<float>)delegate
		{
		}, 0f, 0f, 100f, false);
		obj4.AddElement((MenuElement)(object)lStatsDisplay);
		obj4.AddElement((MenuElement)(object)rStatsDisplay);
		obj4.AddElement((MenuElement)(object)legStatsDisplay);
	}

	public override void OnUpdate()
	{
		if (!((Object)(object)Player.GetRigManager() == (Object)null))
		{
			if (!gripDefaultsStored)
			{
				StoreDefaultGripValues();
			}
			GameObject objectInHand = Player.GetObjectInHand(Player.leftHand);
			GameObject objectInHand2 = Player.GetObjectInHand(Player.rightHand);
			bool twoHandedGrip = AreBothHandsOnSameObject(objectInHand, objectInHand2);
			CheckGrabNotif(objectInHand, ref lastLeftObj, "Left Hand");
			HandleHandLogic(objectInHand, ref lStamina, ref lExhausted, ref lExhaustionTimer, ref lFloor, ref lMult, "Left Hand", twoHandedGrip);
			CheckGrabNotif(objectInHand2, ref lastRightObj, "Right Hand");
			HandleHandLogic(objectInHand2, ref rStamina, ref rExhausted, ref rExhaustionTimer, ref rFloor, ref rMult, "Right Hand", twoHandedGrip);
			if (Time.frameCount % 30 == 0 && lStatsDisplay != null && rStatsDisplay != null && legStatsDisplay != null)
			{
				((GenericElement<float>)(object)lStatsDisplay).SetValue(Mathf.Round(lStamina / prefMaxStamina.Value * 100f));
				((GenericElement<float>)(object)rStatsDisplay).SetValue(Mathf.Round(rStamina / prefMaxStamina.Value * 100f));
				((GenericElement<float>)(object)legStatsDisplay).SetValue(Mathf.Round(legStamina / prefLegMaxStamina.Value * 100f));
			}
			ApplyPhysicalState();
			if (prefGripSlippingEnabled.Value)
			{
				ApplyGripSlipping(Player.leftHand, lStamina);
				ApplyGripSlipping(Player.rightHand, rStamina);
			}
			if (prefHandShakeEnabled.Value)
			{
				ApplyHandShake(Player.leftHand, lStamina);
				ApplyHandShake(Player.rightHand, rStamina);
			}
			if (prefLegsEnabled.Value)
			{
				HandleLegLogic();
			}
		}
	}

	private void ApplyGripSlipping(Hand hand, float stamina)
	{
		if (!((Object)(object)hand == (Object)null) && !((Object)(object)hand.joint == (Object)null))
		{
			float num = stamina / prefMaxStamina.Value * 100f;
			if (num <= 10f)
			{
				float num2 = Mathf.Lerp(200f, 250f, num / 10f);
				((Joint)hand.joint).breakForce = num2;
				((Joint)hand.joint).breakTorque = num2;
			}
			else
			{
				((Joint)hand.joint).breakForce = defaultBreakForce;
				((Joint)hand.joint).breakTorque = defaultBreakTorque;
			}
		}
	}

	private void StoreDefaultGripValues()
	{
		if ((Object)(object)Player.leftHand != (Object)null && (Object)(object)Player.leftHand.joint != (Object)null)
		{
			defaultBreakForce = ((Joint)Player.leftHand.joint).breakForce;
			defaultBreakTorque = ((Joint)Player.leftHand.joint).breakTorque;
			gripDefaultsStored = true;
		}
	}

	private void RestoreGripIfDisabled()
	{
		if (!prefGripSlippingEnabled.Value)
		{
			if ((Object)(object)Player.leftHand != (Object)null && (Object)(object)Player.leftHand.joint != (Object)null)
			{
				((Joint)Player.leftHand.joint).breakForce = defaultBreakForce;
				((Joint)Player.leftHand.joint).breakTorque = defaultBreakTorque;
			}
			if ((Object)(object)Player.rightHand != (Object)null && (Object)(object)Player.rightHand.joint != (Object)null)
			{
				((Joint)Player.rightHand.joint).breakForce = defaultBreakForce;
				((Joint)Player.rightHand.joint).breakTorque = defaultBreakTorque;
			}
		}
	}

	private void ApplyHandShake(Hand hand, float stamina)
	{
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)hand == (Object)null) && !((Object)(object)hand.rb == (Object)null) && stamina <= 0f)
		{
			float num = prefHandShakeIntensity.Value * 37.5f;
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(Random.value - 0.5f, Random.value - 0.5f, Random.value - 0.5f);
			hand.rb.AddRelativeTorque(num * val);
		}
	}

	private void HandleHandLogic(GameObject obj, ref float stamina, ref bool exhausted, ref float timer, ref float floor, ref float mult, string handName, bool twoHandedGrip)
	{
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		float num = GetWeight(obj);
		if (IsObjectSupported(obj))
		{
			num = 0f;
		}
		bool flag = num > prefWeightThreshold.Value;
		if (twoHandedGrip && num > 0f)
		{
			num *= 0.25f;
		}
		if (exhausted)
		{
			timer += Time.deltaTime;
			mult = Mathf.Lerp(floor, 1f, timer / 10f);
			if (timer >= 10f)
			{
				exhausted = false;
				timer = 0f;
				stamina = 5f;
				mult = 1f;
				if (prefExhaustionNotifs.Value)
				{
					Notifications.SendNotification(handName + " Restored", 1f);
				}
			}
		}
		else if (num > prefWeightThreshold.Value)
		{
			float num2 = Mathf.Clamp01(Mathf.InverseLerp(1f, 20f, num));
			float num3 = Mathf.Lerp(prefMaxStamina.Value / 60f, prefMaxStamina.Value / 10f, num2);
			float num4 = 0f;
			if (prefErrorDrainEnabled.Value)
			{
				Hand val = ((handName == "Left Hand") ? Player.leftHand : Player.rightHand);
				BaseController val2 = ((handName == "Left Hand") ? Player.leftBaseController : Player.rightBaseController);
				if ((Object)(object)val != (Object)null && (Object)(object)val2 != (Object)null)
				{
					float num5 = Vector3.Distance(((Component)val).transform.position, ((Component)val2).transform.position);
					if (num5 > 0.07f)
					{
						num4 = num5 * num * prefErrorMultiplier.Value;
					}
				}
			}
			stamina -= (num3 + num4) * Time.deltaTime;
			floor = Mathf.Lerp(prefMinWeakness.Value, 0.1f, num2);
			mult = Mathf.Lerp(floor, 1f, stamina / prefMaxStamina.Value);
			if (stamina <= 0f)
			{
				stamina = 0f;
				exhausted = true;
				if (prefExhaustionNotifs.Value)
				{
					Notifications.SendNotification(handName.ToUpper() + " NO STAMINA", 2f);
				}
			}
		}
		else if (!(twoHandedGrip && flag) && stamina < prefMaxStamina.Value)
		{
			stamina += prefRegenRate.Value * Time.deltaTime;
			if (stamina > prefMaxStamina.Value)
			{
				stamina = prefMaxStamina.Value;
			}
			mult = Mathf.Clamp(stamina / prefMaxStamina.Value, prefMinWeakness.Value, 1f);
		}
	}

	private void HandleLegLogic()
	{
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_030d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0317: Unknown result type (might be due to invalid IL or missing references)
		GameObject rigManager = Player.GetRigManager();
		if ((Object)(object)rigManager == (Object)null)
		{
			return;
		}
		RigManager component = rigManager.GetComponent<RigManager>();
		if ((Object)(object)component == (Object)null)
		{
			return;
		}
		ControllerRig controllerRig = component.ControllerRig;
		PhysBody physBody = component.physicsRig.physBody;
		Rigidbody rbPelvis = physBody.rbPelvis;
		bool flag = false;
		bool num = Player.rightController.GetAButtonDown() || Player.leftController.GetAButtonDown();
		bool flag2 = rbPelvis.velocity.y > 1f;
		if (num && flag2)
		{
			legStamina -= prefJumpTax.Value;
			flag = true;
			if (prefLegNotifs.Value)
			{
				Notifications.SendNotification($"Jump: -{prefJumpTax.Value} Stamina", 1f);
			}
		}
		Vector3 val = default(Vector3);
		((Vector3)(ref val))..ctor(rbPelvis.velocity.x, 0f, rbPelvis.velocity.z);
		float magnitude = ((Vector3)(ref val)).magnitude;
		if (physBody.physG.isGrounded && magnitude > 2f)
		{
			legStamina -= magnitude * 0.1f * prefWalkDrainMultiplier.Value * Time.deltaTime;
			flag = true;
		}
		if (legStamina < prefSprintThreshold.Value)
		{
			controllerRig._jogToggle = false;
			if (!wasSprintLocked && prefLegNotifs.Value)
			{
				Notifications.SendNotification("Legs Fatigued: No Sprint", 2f);
				wasSprintLocked = true;
			}
		}
		else if (wasSprintLocked && legStamina >= prefSprintThreshold.Value)
		{
			if (prefLegNotifs.Value)
			{
				Notifications.SendNotification("Legs Recovered", 1f);
			}
			wasSprintLocked = false;
		}
		if (flag)
		{
			regenDelayTimer = 5f;
		}
		if (regenDelayTimer > 0f)
		{
			regenDelayTimer -= Time.deltaTime;
		}
		else if (legStamina < prefLegMaxStamina.Value)
		{
			legStamina += prefLegRegenRate.Value * Time.deltaTime;
		}
		legStamina = Mathf.Clamp(legStamina, 0f, prefLegMaxStamina.Value);
		float num2 = legStamina / prefLegMaxStamina.Value;
		float num3 = Mathf.Lerp(prefLegMinWeakness.Value, 1f, num2);
		controllerRig.maxAcceleration = 7f * num3 * prefDefaultSpeed.Value;
		controllerRig.maxVelocity = 2f * num3 * prefDefaultSpeed.Value;
		if (prefDefaultSprintToggle.Value != controllerRig._jogToggle && legStamina >= prefSprintThreshold.Value)
		{
			controllerRig._jogToggle = prefDefaultSprintToggle.Value;
		}
		if (!physBody.physG.isGrounded && rbPelvis.velocity.y > 0.1f)
		{
			rbPelvis.velocity = new Vector3(rbPelvis.velocity.x, rbPelvis.velocity.y * num3 * prefDefaultJumpPower.Value, rbPelvis.velocity.z);
		}
	}

	private bool IsObjectSupported(GameObject obj)
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)obj == (Object)null)
		{
			return false;
		}
		Rigidbody componentInParent = obj.GetComponentInParent<Rigidbody>();
		if ((Object)(object)componentInParent == (Object)null)
		{
			return false;
		}
		if (Mathf.Abs(componentInParent.velocity.y) > 0.1f)
		{
			return false;
		}
		foreach (Collider componentsInChild in obj.GetComponentsInChildren<Collider>())
		{
			Bounds bounds = componentsInChild.bounds;
			Vector3 center = ((Bounds)(ref bounds)).center;
			Vector3 down = Vector3.down;
			bounds = componentsInChild.bounds;
			if (Physics.Raycast(center, down, ((Bounds)(ref bounds)).extents.y + 0.05f))
			{
				return true;
			}
		}
		return false;
	}

	private float GetWeight(GameObject obj)
	{
		if ((Object)(object)obj == (Object)null)
		{
			return 0f;
		}
		Rigidbody componentInParent = obj.GetComponentInParent<Rigidbody>();
		if (!((Object)(object)componentInParent != (Object)null))
		{
			return 0f;
		}
		return componentInParent.mass;
	}

	private bool AreBothHandsOnSameObject(GameObject leftObj, GameObject rightObj)
	{
		if ((Object)(object)leftObj == (Object)null || (Object)(object)rightObj == (Object)null)
		{
			return false;
		}
		Rigidbody componentInParent = leftObj.GetComponentInParent<Rigidbody>();
		Rigidbody componentInParent2 = rightObj.GetComponentInParent<Rigidbody>();
		if ((Object)(object)componentInParent == (Object)null || (Object)(object)componentInParent2 == (Object)null)
		{
			return false;
		}
		return (Object)(object)componentInParent == (Object)(object)componentInParent2;
	}

	private void CheckGrabNotif(GameObject currentObj, ref GameObject lastObj, string handName)
	{
		if (prefGrabNotifs.Value && (Object)(object)currentObj != (Object)(object)lastObj && (Object)(object)currentObj != (Object)null)
		{
			float weight = GetWeight(currentObj);
			Notifications.SendNotification($"{handName}: {((Object)currentObj).name}\nWeight: {weight:F1}kg", 2f);
		}
		lastObj = currentObj;
	}

	private void ApplyPhysicalState()
	{
		ApplyForceToHand(Player.leftHand.physHand, lMult);
		ApplyForceToHand(Player.rightHand.physHand, rMult);
	}

	private void ApplyForceToHand(PhysHand hand, float mult)
	{
		if (!((Object)(object)hand == (Object)null))
		{
			float num = (((Object)(object)hand == (Object)(object)Player.leftHand.physHand) ? prefLeftArmStrength.Value : prefRightArmStrength.Value);
			float num2 = mult * num;
			hand.xPosForce = 90f * num2;
			hand.yPosForce = 90f * num2;
			hand.zPosForce = 340f * num2;
			hand.xNegForce = 90f * num2;
			hand.yNegForce = 200f * num2;
			hand.zNegForce = 360f * num2;
			hand.newtonDamp = 80f * num2;
			hand.angDampening = num2;
			hand.dampening = 0.2f * num2;
			hand.maxTorque = 30f * num2;
		}
	}

	public override void OnSceneWasLoaded(int buildIndex, string sceneName)
	{
		gripDefaultsStored = false;
		if (prefLegMaxStamina != null)
		{
			legStamina = prefLegMaxStamina.Value;
		}
		regenDelayTimer = 0f;
		wasSprintLocked = false;
		GameObject rigManager = Player.GetRigManager();
		if ((Object)(object)rigManager != (Object)null)
		{
			RigManager component = rigManager.GetComponent<RigManager>();
			if ((Object)(object)component != (Object)null)
			{
				component.ControllerRig.maxAcceleration = 7f * prefDefaultSpeed.Value;
				component.ControllerRig.maxVelocity = 2f * prefDefaultSpeed.Value;
				component.ControllerRig._jogToggle = prefDefaultSprintToggle.Value;
			}
		}
	}
}