Decompiled source of Quicksilver v1.7.0

Mods/Quicksilver.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BoneLib;
using BoneLib.BoneMenu;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSLZ.Marrow;
using Il2CppSLZ.Marrow.Audio;
using Il2CppSLZ.Marrow.Warehouse;
using Il2CppSLZ.VRMK;
using Il2CppSystem;
using MelonLoader;
using MelonLoader.Preferences;
using Quicksilver;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Quicksilver")]
[assembly: MelonInfo(typeof(QuicksilverMod), "Quicksilver", "1.7.0", "Lakatrazz", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.7.0.0")]
[module: UnverifiableCode]
namespace Quicksilver
{
	public class QuicksilverMod : MelonMod
	{
		public struct RigidbodyState
		{
			public float drag;

			public float angularDrag;

			public RigidbodyState(Rigidbody rb)
			{
				drag = rb.drag;
				angularDrag = rb.angularDrag;
			}
		}

		public const string Version = "1.7.0";

		private static bool _previousIsEnabled;

		public RigManager rigManager;

		public float lastTimeScale;

		public float lastCheckedTimeScale;

		public float timeOfLastAvatarUpdate;

		public bool checkForUpdate;

		public Dictionary<Rigidbody, RigidbodyState> rigidbodies = new Dictionary<Rigidbody, RigidbodyState>();

		private static bool _registeredPrefs = false;

		public static QuicksilverMod Instance { get; private set; }

		public static bool IsEnabled { get; private set; }

		public static float TargetTimeScale { get; private set; } = 1f;


		public static MelonPreferences_Category MelonPrefCategory { get; private set; }

		public static MelonPreferences_Entry<bool> MelonPrefEnabled { get; private set; }

		public static Page BoneMenuPage { get; private set; }

		public static BoolElement BoneMenuEnabledElement { get; private set; }

		public override void OnInitializeMelon()
		{
			Instance = this;
			Hooking.OnLevelLoaded += OnLevelLoaded;
			SetupMelonPrefs();
			SetupBoneMenu();
		}

		public static void SetupMelonPrefs()
		{
			MelonPrefCategory = MelonPreferences.CreateCategory("Quicksilver");
			MelonPrefEnabled = MelonPrefCategory.CreateEntry<bool>("IsEnabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			IsEnabled = MelonPrefEnabled.Value;
			_previousIsEnabled = IsEnabled;
			_registeredPrefs = true;
		}

		public static void SetupBoneMenu()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			BoneMenuPage = Page.Root.CreatePage("Quicksilver", new Color(0.75f, 0.75f, 0.75f), 0, true);
			BoneMenuEnabledElement = BoneMenuPage.CreateBool("Mod Toggle", Color.yellow, IsEnabled, (Action<bool>)OnSetEnabled);
		}

		public static void OnSetEnabled(bool value)
		{
			IsEnabled = value;
			MelonPrefEnabled.Value = value;
			MelonPrefCategory.SaveToFile(false);
		}

		public override void OnPreferencesLoaded()
		{
			if (_registeredPrefs)
			{
				IsEnabled = MelonPrefEnabled.Value;
				BoneMenuEnabledElement.Value = IsEnabled;
			}
		}

		public void OnLevelLoaded(LevelInfo info)
		{
			rigManager = Player.RigManager;
			TargetTimeScale = Time.timeScale;
			lastTimeScale = Time.timeScale;
			lastCheckedTimeScale = lastTimeScale;
			rigidbodies.Clear();
			foreach (Rigidbody componentsInChild in ((Component)rigManager).GetComponentsInChildren<Rigidbody>(true))
			{
				rigidbodies.Add(componentsInChild, new RigidbodyState(componentsInChild));
			}
		}

		public void ResetPlayer()
		{
			PhysicsRig physicsRig = rigManager.physicsRig;
			physicsRig._pelvisForceInternalMult = 1f;
			physicsRig.leftHand.physHand.armInternalMult = 1f;
			physicsRig.rightHand.physHand.armInternalMult = 1f;
			rigManager.SwapAvatarCrate(((ScannableReference)rigManager.AvatarCrate).Barcode, false, (Action<bool>)null);
			OnUpdateRigidbodies(1f);
		}

		public bool HasRigManager()
		{
			if (rigManager != null && !((Object)(object)rigManager == (Object)null))
			{
				return !((Il2CppObjectBase)rigManager).WasCollected;
			}
			return false;
		}

		public override void OnFixedUpdate()
		{
			float timeScale = Time.timeScale;
			if (timeScale <= 0f || !HasRigManager() || !rigManager.physicsRig.ballLocoEnabled)
			{
				return;
			}
			if (IsEnabled)
			{
				if (Mathf.Round(timeScale * 1000f) != Mathf.Round(lastCheckedTimeScale * 1000f))
				{
					OnUpdateVelocities(timeScale, lastCheckedTimeScale);
					timeOfLastAvatarUpdate = Time.realtimeSinceStartup;
					checkForUpdate = true;
					lastCheckedTimeScale = timeScale;
				}
				if (!_previousIsEnabled || (checkForUpdate && Time.realtimeSinceStartup - timeOfLastAvatarUpdate > 0.015f))
				{
					checkForUpdate = false;
					rigManager.SwapAvatarCrate(((ScannableReference)rigManager.AvatarCrate).Barcode, false, (Action<bool>)null);
					OnUpdateRigidbodies(timeScale);
					lastTimeScale = timeScale;
					TargetTimeScale = timeScale;
				}
				ApplyGravity(timeScale);
				PhysicsRig physicsRig = rigManager.physicsRig;
				physicsRig._pelvisForceInternalMult = 1f / Mathf.Pow(timeScale, 3f);
				physicsRig.leftHand.physHand.armInternalMult = 1f / timeScale;
				physicsRig.rightHand.physHand.armInternalMult = 1f / timeScale;
			}
			else if (_previousIsEnabled)
			{
				ResetPlayer();
			}
			_previousIsEnabled = IsEnabled;
		}

		private void ApplyGravity(float timeScale)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: 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)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			float num = 1f / timeScale;
			num *= num;
			Vector3 gravity = Physics.gravity;
			Vector3 val = gravity * num - gravity;
			Rigidbody feetRb = rigManager.physicsRig._feetRb;
			Rigidbody kneeRb = rigManager.physicsRig._kneeRb;
			Vector3 val2 = val;
			float num2 = 0f;
			if (feetRb.useGravity)
			{
				feetRb.AddForce(val, (ForceMode)5);
				num2 += feetRb.mass;
			}
			if (kneeRb.useGravity)
			{
				kneeRb.AddForce(val, (ForceMode)5);
				num2 += kneeRb.mass;
			}
			Collider groundedCollider = rigManager.physicsRig.physG._groundedCollider;
			if (Object.op_Implicit((Object)(object)groundedCollider) && Object.op_Implicit((Object)(object)groundedCollider.attachedRigidbody))
			{
				groundedCollider.attachedRigidbody.AddForceAtPosition(-val2 * Mathf.Min(groundedCollider.attachedRigidbody.mass, num2), feetRb.worldCenterOfMass, (ForceMode)0);
			}
		}

		public void OnUpdateVelocities(float timeScale, float lastTimeScale)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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)
			if (timeScale <= 0f || lastTimeScale <= 0f)
			{
				return;
			}
			float num = lastTimeScale / timeScale;
			for (int i = 0; i < rigidbodies.Keys.Count; i++)
			{
				Rigidbody val = rigidbodies.Keys.ElementAt(i);
				if (val != null && !((Object)(object)val == (Object)null) && !((Il2CppObjectBase)val).WasCollected)
				{
					val.velocity *= num;
					val.angularVelocity *= num;
				}
			}
		}

		public void OnUpdateRigidbodies(float timeScale)
		{
			if (timeScale <= 0f)
			{
				return;
			}
			for (int i = 0; i < rigidbodies.Keys.Count; i++)
			{
				Rigidbody val = rigidbodies.Keys.ElementAt(i);
				if (val != null && !((Object)(object)val == (Object)null) && !((Il2CppObjectBase)val).WasCollected)
				{
					RigidbodyState rigidbodyState = rigidbodies[val];
					val.drag = rigidbodyState.drag * timeScale;
					val.angularDrag = rigidbodyState.angularDrag * timeScale;
				}
			}
		}

		public static bool IsMainRig(Avatar avatar)
		{
			bool result = false;
			try
			{
				if ((Object)(object)Instance.rigManager.avatar == (Object)(object)avatar)
				{
					result = true;
				}
			}
			catch
			{
			}
			return result;
		}

		public static bool IsMainRig(Rig rig)
		{
			bool result = false;
			try
			{
				if ((Object)(object)rig.manager == (Object)(object)Instance.rigManager)
				{
					result = true;
				}
			}
			catch
			{
			}
			return result;
		}
	}
}
namespace Quicksilver.Patching
{
	[HarmonyPatch(typeof(AnimationRig))]
	public static class AnimationRigPatches
	{
		[HarmonyPrefix]
		[HarmonyPatch("OnEarlyUpdate")]
		public static void OnEarlyUpdatePrefix(AnimationRig __instance)
		{
			if (QuicksilverMod.IsEnabled && QuicksilverMod.IsMainRig((Rig)(object)__instance))
			{
				TimePatches.ReturnScaled = true;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("OnEarlyUpdate")]
		public static void OnEarlyUpdatePostfix(AnimationRig __instance)
		{
			TimePatches.ReturnScaled = false;
		}

		[HarmonyPrefix]
		[HarmonyPatch("BodyVelocity")]
		public static void BodyVelocity(AnimationRig __instance, Rig inRig, ref Vector2 vel, ref Vector2 accel, float deltaTime)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			if (QuicksilverMod.IsEnabled && QuicksilverMod.IsMainRig((Rig)(object)__instance))
			{
				vel *= QuicksilverMod.TargetTimeScale;
				accel *= QuicksilverMod.TargetTimeScale;
			}
		}
	}
	[HarmonyPatch(typeof(ArtRig))]
	public static class ArtRigPatches
	{
		[HarmonyPrefix]
		[HarmonyPatch("ArtOutputUpdate")]
		public static void ArtOutputUpdatePrefix(ArtRig __instance, PhysicsRig inRig)
		{
			if (QuicksilverMod.IsEnabled && QuicksilverMod.TargetTimeScale > 0f && QuicksilverMod.IsMainRig((Rig)(object)inRig))
			{
				TimePatches.ReturnScaled = true;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("ArtOutputUpdate")]
		public static void ArtOutputUpdatePostfix()
		{
			TimePatches.ReturnScaled = false;
		}
	}
	[HarmonyPatch(typeof(Avatar))]
	public static class AvatarPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch("ComputeMass")]
		public static void ComputeMass(Avatar __instance, float normalizeTo82)
		{
			if (!(QuicksilverMod.TargetTimeScale <= 0f) && QuicksilverMod.IsMainRig(__instance) && QuicksilverMod.IsEnabled)
			{
				float num = 1f / QuicksilverMod.TargetTimeScale;
				float num2 = 1f / Mathf.Lerp(1f, QuicksilverMod.TargetTimeScale, 0.9f);
				__instance._massChest *= num;
				__instance._massHead *= num;
				__instance._massPelvis *= num;
				__instance._massArm *= num;
				__instance._massLeg *= num;
				__instance._massTotal *= num2;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("ComputeBaseStats")]
		public static void ComputeBaseStats(Avatar __instance)
		{
			if (!(QuicksilverMod.TargetTimeScale <= 0f) && QuicksilverMod.IsMainRig(__instance) && QuicksilverMod.IsEnabled)
			{
				float num = 1f / QuicksilverMod.TargetTimeScale;
				float num2 = num * num;
				__instance._strengthUpper *= num2;
				__instance._strengthLower *= num2 * num2;
				__instance._speed *= num;
				__instance._agility *= num2 * num2;
			}
		}
	}
	[HarmonyPatch(typeof(Footstep))]
	public static class FootstepPatches
	{
		[HarmonyPrefix]
		[HarmonyPatch("UpdateStepping")]
		public static void UpdateStepping(Vector3 rootPosition, Quaternion rootRotation, Quaternion footRotation, Vector3 rootUp, ref Vector3 velocitySanGrav, ref Vector3 accel, float angularVel, float velocitySanGravNorm, float stepLZ, float velDot, float sacrumHeightWeight, float deltaTime)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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)
			if (QuicksilverMod.IsEnabled && QuicksilverMod.TargetTimeScale > 0f)
			{
				float num = Mathf.Lerp(1f, QuicksilverMod.TargetTimeScale, 0.95f);
				velocitySanGrav *= num;
				accel *= num;
			}
		}
	}
	[HarmonyPatch(typeof(FootstepSFX))]
	public static class FootstepSFXPatches
	{
		[HarmonyPrefix]
		[HarmonyPatch("PlayStep")]
		public static void PlayStepPrefix(float velocitySqr)
		{
			TimePatches.ForceDefaultTimescale = true;
		}

		[HarmonyPostfix]
		[HarmonyPatch("PlayStep")]
		public static void PlayStepPostfix(float velocitySqr)
		{
			TimePatches.ForceDefaultTimescale = false;
		}
	}
	[HarmonyPatch(typeof(ForcePullGrip), "OnFarHandHoverUpdate")]
	public static class ForcePullPatches
	{
		public static void Prefix(ForcePullGrip __instance, Hand hand)
		{
			if (QuicksilverMod.IsEnabled && QuicksilverMod.TargetTimeScale > 0f)
			{
				__instance.maxForce = 250f / QuicksilverMod.TargetTimeScale;
			}
		}
	}
	[HarmonyPatch(typeof(AlignPlug))]
	public static class AlignPlugPatches
	{
		[HarmonyPrefix]
		[HarmonyPatch("Update")]
		public static void UpdatePrefix()
		{
			if (QuicksilverMod.IsEnabled && QuicksilverMod.TargetTimeScale > 0f)
			{
				TimePatches.ReturnScaled = true;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("Update")]
		public static void UpdatePostfix()
		{
			TimePatches.ReturnScaled = false;
		}
	}
	[HarmonyPatch(typeof(Gun))]
	public static class GunPatches
	{
		[HarmonyPrefix]
		[HarmonyPatch("Update")]
		public static void UpdatePrefix(Gun __instance)
		{
			if (QuicksilverMod.TargetTimeScale > 0f && Object.op_Implicit((Object)(object)__instance.triggerGrip) && Object.op_Implicit((Object)(object)__instance.triggerGrip.GetHand()) && (Object)(object)__instance.triggerGrip.GetHand().manager == (Object)(object)QuicksilverMod.Instance.rigManager)
			{
				if (QuicksilverMod.IsEnabled)
				{
					__instance.fireDuration = 60f / __instance.roundsPerMinute * QuicksilverMod.TargetTimeScale;
				}
				else
				{
					__instance.fireDuration = 60f / __instance.roundsPerMinute;
				}
			}
			TimePatches.ReturnScaled = true;
		}

		[HarmonyPostfix]
		[HarmonyPatch("Update")]
		public static void UpdatePostfix()
		{
			TimePatches.ReturnScaled = false;
		}
	}
	[HarmonyPatch(typeof(HandJointConfiguration))]
	public static class HandJointConfigurationPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch("LockConfiguration")]
		public static void LockConfiguration(ConfigurableJoint joint)
		{
			float targetTimeScale = QuicksilverMod.TargetTimeScale;
			if (QuicksilverMod.IsEnabled && targetTimeScale > 0f)
			{
				float num = targetTimeScale * targetTimeScale;
				((Joint)joint).breakForce = ((Joint)joint).breakForce / num;
				((Joint)joint).breakTorque = ((Joint)joint).breakTorque / num;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("ApplyConfiguration", new Type[] { typeof(ConfigurableJoint) })]
		public static void ApplyConfiguration(ConfigurableJoint joint)
		{
			if (QuicksilverMod.IsEnabled && QuicksilverMod.TargetTimeScale > 0f)
			{
				((Joint)joint).breakForce = ((Joint)joint).breakForce / (QuicksilverMod.TargetTimeScale * QuicksilverMod.TargetTimeScale);
				((Joint)joint).breakTorque = ((Joint)joint).breakTorque / (QuicksilverMod.TargetTimeScale * QuicksilverMod.TargetTimeScale);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("ApplyConfiguration", new Type[]
		{
			typeof(Quaternion),
			typeof(ConfigurableJoint)
		})]
		public static void ApplyConfiguration(Quaternion localRotation, ConfigurableJoint joint)
		{
			if (QuicksilverMod.IsEnabled && QuicksilverMod.TargetTimeScale > 0f)
			{
				((Joint)joint).breakForce = ((Joint)joint).breakForce / (QuicksilverMod.TargetTimeScale * QuicksilverMod.TargetTimeScale);
				((Joint)joint).breakTorque = ((Joint)joint).breakTorque / (QuicksilverMod.TargetTimeScale * QuicksilverMod.TargetTimeScale);
			}
		}
	}
	[HarmonyPatch(typeof(HandSFX))]
	public static class HandSFXPatches
	{
		[HarmonyPrefix]
		[HarmonyPatch("Grab")]
		public static void GrabPrefix()
		{
			TimePatches.ForceDefaultTimescale = true;
		}

		[HarmonyPostfix]
		[HarmonyPatch("Grab")]
		public static void GrabPostfix()
		{
			TimePatches.ForceDefaultTimescale = false;
		}

		[HarmonyPrefix]
		[HarmonyPatch("BodySlot")]
		public static void BodySlotPrefix()
		{
			TimePatches.ForceDefaultTimescale = true;
		}

		[HarmonyPostfix]
		[HarmonyPatch("BodySlot")]
		public static void BodySlotPostfix()
		{
			TimePatches.ForceDefaultTimescale = false;
		}

		[HarmonyPrefix]
		[HarmonyPatch("Drop")]
		public static void DropPrefix()
		{
			TimePatches.ForceDefaultTimescale = true;
		}

		[HarmonyPostfix]
		[HarmonyPatch("Drop")]
		public static void DropPostfix()
		{
			TimePatches.ForceDefaultTimescale = false;
		}

		[HarmonyPrefix]
		[HarmonyPatch("ForcePull")]
		public static void ForcePullPrefix(float massDistance)
		{
			TimePatches.ForceDefaultTimescale = true;
		}

		[HarmonyPostfix]
		[HarmonyPatch("ForcePull")]
		public static void ForcePullPostfix(float massDistance)
		{
			TimePatches.ForceDefaultTimescale = false;
		}

		[HarmonyPrefix]
		[HarmonyPatch("OnSignificantCollisionEnter")]
		public static void OnSignificantCollisionEnterPrefix()
		{
			TimePatches.ForceDefaultTimescale = true;
		}

		[HarmonyPostfix]
		[HarmonyPatch("OnSignificantCollisionEnter")]
		public static void OnSignificantCollisionEnterPostfix()
		{
			TimePatches.ForceDefaultTimescale = false;
		}
	}
	[HarmonyPatch(typeof(HeadSFX))]
	public static class HeadSFXPatches
	{
		[HarmonyPrefix]
		[HarmonyPatch("SmallDamageVocal")]
		public static void SmallDamageVocalPrefix(float damage)
		{
			TimePatches.ForceDefaultTimescale = true;
		}

		[HarmonyPostfix]
		[HarmonyPatch("SmallDamageVocal")]
		public static void SmallDamageVocalPostfix(float damage)
		{
			TimePatches.ForceDefaultTimescale = false;
		}

		[HarmonyPrefix]
		[HarmonyPatch("BigDamageVocal")]
		public static void BigDamageVocalPrefix()
		{
			TimePatches.ForceDefaultTimescale = true;
		}

		[HarmonyPostfix]
		[HarmonyPatch("BigDamageVocal")]
		public static void BigDamageVocalPostfix()
		{
			TimePatches.ForceDefaultTimescale = false;
		}

		[HarmonyPrefix]
		[HarmonyPatch("DyingVocal")]
		public static void DyingVocalPrefix()
		{
			TimePatches.ForceDefaultTimescale = true;
		}

		[HarmonyPostfix]
		[HarmonyPatch("DyingVocal")]
		public static void DyingVocalPostfix()
		{
			TimePatches.ForceDefaultTimescale = false;
		}

		[HarmonyPrefix]
		[HarmonyPatch("DeathVocal")]
		public static void DeathVocalPrefix()
		{
			TimePatches.ForceDefaultTimescale = true;
		}

		[HarmonyPostfix]
		[HarmonyPatch("DeathVocal")]
		public static void DeathVocalPostfix()
		{
			TimePatches.ForceDefaultTimescale = false;
		}

		[HarmonyPrefix]
		[HarmonyPatch("RecoveryVocal")]
		public static void RecoveryVocalPrefix()
		{
			TimePatches.ForceDefaultTimescale = true;
		}

		[HarmonyPostfix]
		[HarmonyPatch("RecoveryVocal")]
		public static void RecoveryVocalPostfix()
		{
			TimePatches.ForceDefaultTimescale = false;
		}

		[HarmonyPrefix]
		[HarmonyPatch("JumpEffort")]
		public static void JumpEffortPrefix()
		{
			TimePatches.ForceDefaultTimescale = true;
		}

		[HarmonyPostfix]
		[HarmonyPatch("JumpEffort")]
		public static void JumpEffortPostfix()
		{
			TimePatches.ForceDefaultTimescale = false;
		}

		[HarmonyPrefix]
		[HarmonyPatch("DoubleJump")]
		public static void DoubleJumpPrefix()
		{
			TimePatches.ForceDefaultTimescale = true;
		}

		[HarmonyPostfix]
		[HarmonyPatch("DoubleJump")]
		public static void DoubleJumpPostfix()
		{
			TimePatches.ForceDefaultTimescale = false;
		}

		[HarmonyPrefix]
		[HarmonyPatch("OnSignificantCollisionEnter")]
		public static void OnSignificantCollisionEnterPrefix()
		{
			TimePatches.ForceDefaultTimescale = true;
		}

		[HarmonyPostfix]
		[HarmonyPatch("OnSignificantCollisionEnter")]
		public static void OnSignificantCollisionEnterPostfix()
		{
			TimePatches.ForceDefaultTimescale = false;
		}
	}
	[HarmonyPatch(typeof(OpenControllerRig))]
	public static class OpenControllerRigPatches
	{
		[HarmonyPrefix]
		[HarmonyPatch("UpdateHeptaBody")]
		public static void UpdateHeptaBody(OpenControllerRig __instance, ref float deltaTime)
		{
			if (QuicksilverMod.IsEnabled && QuicksilverMod.TargetTimeScale > 0f && QuicksilverMod.IsMainRig((Rig)(object)__instance))
			{
				deltaTime /= QuicksilverMod.TargetTimeScale;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("OnEarlyUpdate")]
		public static void OnEarlyUpdatePrefix(OpenControllerRig __instance)
		{
			if (QuicksilverMod.IsEnabled && QuicksilverMod.IsMainRig((Rig)(object)__instance))
			{
				TimePatches.ReturnScaled = true;
				TimePatches.ForceDefaultTimescale = true;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("OnEarlyUpdate")]
		public static void OnEarlyUpdatePostfix(OpenControllerRig __instance)
		{
			TimePatches.ReturnScaled = false;
			TimePatches.ForceDefaultTimescale = false;
		}
	}
	[HarmonyPatch(typeof(RemapRig))]
	public static class RemapRigPatches
	{
		[HarmonyPrefix]
		[HarmonyPatch("OnEarlyUpdate")]
		public static void OnEarlyUpdatePrefix(RemapRig __instance)
		{
			if (QuicksilverMod.IsEnabled && QuicksilverMod.IsMainRig((Rig)(object)__instance))
			{
				TimePatches.ReturnScaled = true;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("OnEarlyUpdate")]
		public static void OnEarlyUpdatePostfix(RemapRig __instance)
		{
			TimePatches.ReturnScaled = false;
		}
	}
	[HarmonyPatch(typeof(Time))]
	public static class TimePatches
	{
		public static bool ReturnScaled;

		public static bool ForceDefaultTimescale;

		public static bool ReturnInversed;

		[HarmonyPostfix]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		public static void GetDeltaTime(ref float __result)
		{
			if (QuicksilverMod.IsEnabled)
			{
				float realTimeScale = GetRealTimeScale();
				if (ReturnScaled)
				{
					__result /= realTimeScale;
				}
				else if (ReturnInversed)
				{
					__result *= realTimeScale;
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		public static void GetFixedDeltaTime(ref float __result)
		{
			if (QuicksilverMod.IsEnabled)
			{
				float realTimeScale = GetRealTimeScale();
				if (ReturnScaled)
				{
					__result /= realTimeScale;
				}
				else if (ReturnInversed)
				{
					__result *= realTimeScale;
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		public static void GetTimeScale(ref float __result)
		{
			if (QuicksilverMod.IsEnabled && ForceDefaultTimescale)
			{
				__result = 1f;
			}
		}

		private static float GetRealTimeScale()
		{
			bool forceDefaultTimescale = ForceDefaultTimescale;
			ForceDefaultTimescale = false;
			float timeScale = Time.timeScale;
			ForceDefaultTimescale = forceDefaultTimescale;
			return timeScale;
		}
	}
	[HarmonyPatch(typeof(HandgunVirtualController))]
	public static class HandgunVirtualControllerPatches
	{
		[HarmonyPrefix]
		[HarmonyPatch("OnVirtualControllerSolve")]
		public static void OnVirtualControllerSolvePrefix(VirtualControlerPayload p)
		{
			TimePatches.ReturnScaled = true;
		}

		[HarmonyPostfix]
		[HarmonyPatch("OnVirtualControllerSolve")]
		public static void OnVirtualControllerSolvePostfix(VirtualControlerPayload p)
		{
			TimePatches.ReturnScaled = false;
		}
	}
	[HarmonyPatch(typeof(RifleVirtualController))]
	public static class RifleVirtualControllerPatches
	{
		[HarmonyPrefix]
		[HarmonyPatch("OnVirtualControllerSolve")]
		public static void OnVirtualControllerSolvePrefix(VirtualControlerPayload payload)
		{
			TimePatches.ReturnScaled = true;
		}

		[HarmonyPostfix]
		[HarmonyPatch("OnVirtualControllerSolve")]
		public static void OnVirtualControllerSolvePostfix(VirtualControlerPayload payload)
		{
			TimePatches.ReturnScaled = false;
		}
	}
	[HarmonyPatch(typeof(WindBuffetSFX))]
	public static class WindBuffetPatches
	{
		[HarmonyPrefix]
		[HarmonyPatch("UpdateBuffet")]
		public static void UpdateBuffetPrefix(WindBuffetSFX __instance)
		{
			if (QuicksilverMod.IsEnabled)
			{
				if (QuicksilverMod.TargetTimeScale > 0f)
				{
					__instance.minSpeed = 5f / QuicksilverMod.TargetTimeScale;
					__instance.maxSpeed = 40f / QuicksilverMod.TargetTimeScale;
				}
				TimePatches.ForceDefaultTimescale = true;
			}
			else
			{
				__instance.minSpeed = 5f;
				__instance.maxSpeed = 40f;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("UpdateBuffet")]
		public static void UpdateBuffetPostfix(WindBuffetSFX __instance)
		{
			TimePatches.ForceDefaultTimescale = false;
		}
	}
}