Decompiled source of NoclipMod v1.4.0

Mods/Noclip_V1.4.dll

Decompiled 3 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BoneLib;
using BoneLib.BoneMenu;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Marrow;
using MelonLoader;
using MelonLoader.Preferences;
using NoClipMod;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("NoClipMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.4.0.0")]
[assembly: AssemblyInformationalVersion("1.4.0")]
[assembly: AssemblyProduct("NoClipMod")]
[assembly: AssemblyTitle("NoClipMod")]
[assembly: MelonInfo(typeof(global::NoClipMod.NoClipMod), "NoClipMod", "1.4.0", "Sansw", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.4.0.0")]
[module: UnverifiableCode]
namespace NoClipMod;

public class NoClipMod : MelonMod
{
	private bool yWasPressed;

	private float lastYPressTime = -10f;

	private bool noclipEnabled;

	private bool groundDetectorEnabled;

	private int calculatedGroundMask;

	private Vector3 smoothedGroundPoint;

	private Vector3 smoothedGroundNormal = Vector3.up;

	private bool hasSmoothedGround;

	private int currentSceneHandle = -1;

	private bool groundMaskReady;

	private float probeRadius = 0.035f;

	private float footSupportDistance = 0.08f;

	private float correctionSpeed = 2f;

	private float jumpProtectionUntil = -10f;

	private bool customGrounded;

	private float recoveryRange = 0.5f;

	private float nextMaskRefreshTime;

	private float maskRefreshUntil;

	private float headToFeetDistance = 1.7f;

	private float groundClearance = 0.005f;

	private float rayDistance = 2.5f;

	private float groundPointSmooth = 5.5f;

	private float groundNormalSmooth = 5f;

	private bool jumpRequested;

	private bool jumpButtonWasDown;

	private FieldInfo aButtonDownField;

	private PropertyInfo aButtonDownProperty;

	private Vector2 thumbstickInput;

	private const float StickDeadzone = 0.12f;

	private bool jumpActive;

	private bool jumpBindingSearched;

	private bool airWalkEnabled;

	private bool wallTransferEnabled;

	private bool menuCreated;

	private bool rightBWasPressed;

	private bool wallTransferRequested;

	private bool wallTransferActive;

	private Vector3 currentMoveVelocity;

	private Vector3 lastMoveDirection = Vector3.forward;

	private float movementSpeed = 3.9f;

	private float movementAcceleration = 18f;

	private float movementDeceleration = 42f;

	private float airControl = 0.9f;

	private float airWalkAssistSpeed = 4.5f;

	private float airWalkSearchStep = 0.4f;

	private float airWalkHoldFeetY;

	private bool hasAirWalkHoldHeight;

	private float wallDetectionDistance = 1.8f;

	private float wallScanDistance = 8f;

	private float wallScanStep = 0.15f;

	private float wallClearance = 0.12f;

	private float wallProbeRadius = 0.16f;

	private float wallTransferCooldownUntil;

	private readonly Collider[] transferOverlapBuffer = (Collider[])(object)new Collider[64];

	private Collider[] temporaryTransferColliders;

	private Page mainPage;

	private float jumpVelocity = 5.5f;

	private float wallOpenSpaceDepth = 1.5f;

	private const float JumpProtectionDuration = 0.4f;

	private const float YButtonDoubleTapWindow = 0.35f;

	private int lastRigInstanceId;

	private readonly List<Collider> noclipDisabledColliders = new List<Collider>();

	private float groundMissUntil;

	private readonly RaycastHit[] airWalkHitBuffer = (RaycastHit[])(object)new RaycastHit[64];

	private bool temporaryTransferRestorePending;

	private float temporaryTransferRestoreTime;

	private float footSupportRadius = 0.12f;

	private float playerCapsuleRadius = 0.18f;

	private float groundRecoveryGain = 0.72f;

	private const float minimumGroundNormalY = 0.45f;

	private readonly Vector3[] groundProbeOffsets = (Vector3[])(object)new Vector3[17];

	private readonly Vector3[] groundProbePoints = (Vector3[])(object)new Vector3[17];

	private readonly Vector3[] groundProbeNormals = (Vector3[])(object)new Vector3[17];

	private readonly float[] groundProbeWeights = new float[17];

	private float directionChangeDeceleration = 48f;

	private float movementStopThreshold = 0.015f;

	private float airWalkSmoothedTargetY;

	private float airWalkTargetVelocity;

	private float airWalkTargetSmoothTime = 0.22f;

	private const float minimumAirWalkNormalY = 0.32f;

	private Type thumbstickControllerType;

	private FieldInfo thumbstickAxisField;

	private PropertyInfo thumbstickAxisProperty;

	private float lastStableGroundFeetY;

	private float lastStableGroundTime = -10f;

	private bool hasStableGroundFeetY;

	private bool airWalkWasAscending;

	private Vector3 lastStableGroundPosition;

	private bool squareGroundMapEnabled;

	private bool squareGroundMapAlwaysOn;

	private float squareGroundMapSize = 3.5f;

	private float squareGroundMapSmoothing = 10f;

	private float squareGroundMapStaleTime = 0.25f;

	private const int SquareMapSideCount = 5;

	private readonly Vector3[] squareMapPoints = (Vector3[])(object)new Vector3[25];

	private readonly Vector3[] squareMapNormals = (Vector3[])(object)new Vector3[25];

	private readonly bool[] squareMapHasSample = new bool[25];

	private readonly float[] squareMapSampleTimes = new float[25];

	private bool squareMapReady;

	private Vector3 airWalkGuideReturnPoint;

	private bool airWalkGuideReturnActive;

	private float airWalkNoTargetSince = -1f;

	private const float minimumGroundDetectorNormalY = 0.34f;

	private float airWalkGuidePathWidth = 0.9f;

	private Vector3 airWalkGuideTargetPoint;

	private readonly Collider[] groundProbeColliders = (Collider[])(object)new Collider[17];

	private bool groundHasPendingSupport;

	private float groundPendingSupportY;

	private int groundPendingSupportFrames;

	private bool groundHasSelectedSupport;

	private Collider groundSelectedSupportCollider;

	private float groundSelectedSupportY;

	private float groundNoHitSince = -1f;

	private Collider airWalkGuideCollider;

	private float airWalkGuideTargetFeetY;

	private float airWalkGuideInitialDistance;

	private int airWalkGroundContactFrames;

	private Collider airWalkBlockedTargetCollider;

	private Vector3 airWalkBlockedTargetPoint;

	private float airWalkBlockedTargetUntil = -1f;

	private readonly Vector3[] airWalkContactOffsets = (Vector3[])(object)new Vector3[5];

	private string airWalkNoticeText = "";

	private float airWalkNoticeUntil = -1f;

	private bool airWalkHudErrorLogged;

	private const float AirWalkActualContactTolerance = 0.018f;

	private bool airWalkAssistActive;

	private bool airWalkWaitingForTakeoff;

	private bool airWalkStateInitialized;

	private int airWalkTakeoffClearFrames;

	private const float AirWalkContactRayStartHeight = 0.045f;

	private const float AirWalkContactRayLength = 0.085f;

	private readonly Vector3[] airWalkGroundContactOffsets = (Vector3[])(object)new Vector3[9];

	private readonly RaycastHit[] airWalkContactRayBuffer = (RaycastHit[])(object)new RaycastHit[32];

	private float airWalkBlockedTargetRadius = 0.9f;

	private Vector3 airWalkDepartureSurfacePoint;

	private Vector3 airWalkDepartureSurfaceNormal = Vector3.up;

	private Collider airWalkDepartureSurfaceCollider;

	private bool airWalkHasDepartureSurface;

	private Vector3 airWalkBlockedAtPosition;

	private float airWalkBlockedTargetFeetY;

	private float airWalkHorizontalGuideRange = 8f;

	private float airWalkVerticalGuideRange = 4f;

	private float airWalkGuideProgress;

	private Vector3 airWalkGuideLastPosition;

	private bool airWalkGuideProgressInitialized;

	private bool airWalkGroundRearmLatched;

	private float airWalkFreeDescentSpeed;

	private bool airWalkLookDownDescentEnabled = true;

	private float airWalkDescentAngle = 15f;

	private float airWalkGuideBlockedProgress;

	private MelonPreferences_Category settingsCategory;

	private MelonPreferences_Entry<bool> prefNoClipEnabled;

	private MelonPreferences_Entry<bool> prefGroundDetectorEnabled;

	private MelonPreferences_Entry<bool> prefAirWalkEnabled;

	private MelonPreferences_Entry<bool> prefWallTransferEnabled;

	private MelonPreferences_Entry<bool> prefSquareGroundMapEnabled;

	private MelonPreferences_Entry<bool> prefSquareGroundMapAlwaysOn;

	private MelonPreferences_Entry<bool> prefAirWalkLookDownDescentEnabled;

	private MelonPreferences_Entry<float> prefMovementSpeed;

	private MelonPreferences_Entry<float> prefMovementAcceleration;

	private MelonPreferences_Entry<float> prefMovementDeceleration;

	private MelonPreferences_Entry<float> prefDirectionChangeDeceleration;

	private MelonPreferences_Entry<float> prefAirControl;

	private MelonPreferences_Entry<float> prefJumpVelocity;

	private MelonPreferences_Entry<float> prefSquareGroundMapSize;

	private MelonPreferences_Entry<float> prefAirWalkAssistSpeed;

	private MelonPreferences_Entry<float> prefAirWalkHorizontalGuideRange;

	private MelonPreferences_Entry<float> prefAirWalkVerticalGuideRange;

	private MelonPreferences_Entry<float> prefAirWalkGuidePathWidth;

	private MelonPreferences_Entry<float> prefAirWalkDescentAngle;

	private MelonPreferences_Entry<float> prefWallDetectionDistance;

	private MelonPreferences_Entry<float> prefWallClearance;

	private MelonPreferences_Entry<float> prefWallScanDistance;

	private MelonPreferences_Entry<float> prefWallScanStep;

	private MelonPreferences_Entry<float> prefWallOpenSpaceDepth;

	private bool controllerRigStateCaptured;

	private bool controllerRigWasEnabled;

	private float controllerRigRecoveryUntil = -1f;

	private float controllerRigDisabledSince = -1f;

	private int controllerRigRecoverySceneHandle = -1;

	private int controllerRigRecoveryPhysicsRigId;

	private int controllerRigRecoveryAttempts;

	private const float PostNoClipRecoveryWindow = 120f;

	private const float ControllerRigDisabledGrace = 20f;

	private const int MaximumControllerRigRecoveryAttempts = 2;

	private float airWalkLastOpenSurfaceScanTime = -1f;

	private readonly RaycastHit[] airWalkClearanceHitBuffer = (RaycastHit[])(object)new RaycastHit[32];

	public override void OnInitializeMelon()
	{
		//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)
		InitializePersistentSettings();
		MelonLogger.Msg("NoClip V4 - Stable Ground / Targeted Air Walk Guidance / Air Momentum");
		Hooking.OnLevelLoaded += OnLevelLoaded;
		Hooking.OnLevelUnloaded += OnLevelUnloaded;
		Scene activeScene = SceneManager.GetActiveScene();
		currentSceneHandle = ((Scene)(ref activeScene)).handle;
		BeginLevelSetup();
		TryCreateBoneMenu();
	}

	public override void OnUpdate()
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_022f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0234: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (!menuCreated)
			{
				TryCreateBoneMenu();
			}
			Scene activeScene = SceneManager.GetActiveScene();
			int handle = ((Scene)(ref activeScene)).handle;
			if (handle != currentSceneHandle)
			{
				currentSceneHandle = handle;
				BeginLevelSetup();
				BuildGroundMask();
				UpdatePlayerMeasurements();
				if (noclipEnabled)
				{
					EnableNoClip();
				}
				MelonLogger.Msg("Scene changed - NoClip state refreshed.");
			}
			UpdateControllerRigRecovery();
			if ((Object)(object)Player.PhysicsRig != (Object)null)
			{
				int instanceID = ((Object)Player.PhysicsRig).GetInstanceID();
				if (noclipEnabled && instanceID != lastRigInstanceId)
				{
					MelonLogger.Warning("Physics rig changed; applying NoClip to the new rig.");
					UpdatePlayerMeasurements();
					EnableNoClip();
					ResetAirWalkHold();
				}
				bool flag = groundDetectorEnabled || airWalkEnabled;
				if (Time.time >= nextMaskRefreshTime && (Time.time <= maskRefreshUntil || flag))
				{
					BuildGroundMask();
					nextMaskRefreshTime = Time.time + ((Time.time <= maskRefreshUntil) ? 0.5f : 2f);
				}
			}
			if (!Player.HandsExist)
			{
				thumbstickInput = Vector2.zero;
				yWasPressed = false;
				rightBWasPressed = false;
				jumpButtonWasDown = false;
				return;
			}
			bool flag2 = false;
			bool flag3 = false;
			try
			{
				Hand leftHand = Player.LeftHand;
				if ((Object)(object)leftHand != (Object)null && (Object)(object)leftHand.Controller != (Object)null)
				{
					flag2 = leftHand.Controller._bButtonDown;
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("Left controller input error: " + ex.Message);
			}
			try
			{
				Hand rightHand = Player.RightHand;
				if ((Object)(object)rightHand != (Object)null && (Object)(object)rightHand.Controller != (Object)null)
				{
					flag3 = rightHand.Controller._bButtonDown;
				}
			}
			catch (Exception ex2)
			{
				MelonLogger.Warning("Right controller input error: " + ex2.Message);
			}
			if (flag2 && !yWasPressed)
			{
				HandleNoClipToggleInput();
			}
			if (flag3 && !rightBWasPressed && wallTransferEnabled)
			{
				wallTransferRequested = true;
			}
			yWasPressed = flag2;
			rightBWasPressed = flag3;
			if ((noclipEnabled || airWalkEnabled || wallTransferEnabled) && !wallTransferActive)
			{
				ReadThumbstick();
			}
			else
			{
				thumbstickInput = Vector2.zero;
			}
			bool flag4 = ReadJumpButton();
			if (flag4 && !jumpButtonWasDown)
			{
				jumpRequested = true;
			}
			jumpButtonWasDown = flag4;
		}
		catch (Exception ex3)
		{
			MelonLogger.Error("NoClip update error: " + ex3.Message);
		}
	}

	public override void OnFixedUpdate()
	{
		if ((Object)(object)Player.PhysicsRig == (Object)null)
		{
			return;
		}
		try
		{
			if (temporaryTransferRestorePending && Time.time >= temporaryTransferRestoreTime)
			{
				RestoreTemporaryTransferColliders();
			}
			UpdatePlayerMeasurements();
			if (wallTransferRequested && !wallTransferActive && Time.time >= wallTransferCooldownUntil)
			{
				wallTransferRequested = false;
				TrackStableGroundForWallTransfer();
				ExecuteWallTransfer();
			}
			if (wallTransferActive)
			{
				return;
			}
			if (noclipEnabled)
			{
				ApplyNoclipMovement();
				NeutralizeNoclipPlanarPhysics();
			}
			if (jumpRequested)
			{
				jumpRequested = false;
				if (noclipEnabled && !jumpActive)
				{
					PerformFixedJump();
				}
			}
			if (jumpActive && Time.time >= jumpProtectionUntil && GetFeetVerticalVelocity() < -0.05f)
			{
				jumpActive = false;
			}
			if (groundDetectorEnabled)
			{
				RunGroundDetector(!airWalkAssistActive);
			}
			else
			{
				customGrounded = false;
			}
			if (airWalkEnabled)
			{
				ApplyAirWalkAssist();
			}
			if (wallTransferEnabled)
			{
				TrackStableGroundForWallTransfer();
			}
		}
		catch (Exception ex)
		{
			MelonLogger.Error("NoClip fixed update error: " + ex.Message);
		}
	}

	private void EnableNoClip()
	{
		if ((Object)(object)Player.PhysicsRig == (Object)null)
		{
			return;
		}
		try
		{
			MeasureFootGeometry();
			Collider[] array = Il2CppArrayBase<Collider>.op_Implicit(((Component)Player.PhysicsRig).GetComponentsInChildren<Collider>(true));
			int count = noclipDisabledColliders.Count;
			Collider[] array2 = array;
			foreach (Collider collider in array2)
			{
				DisableNoClipCollider(collider);
			}
			DisableHandColliders(Player.LeftHand);
			DisableHandColliders(Player.RightHand);
			lastRigInstanceId = ((Object)Player.PhysicsRig).GetInstanceID();
			BuildGroundMask();
			nextMaskRefreshTime = Time.time;
			maskRefreshUntil = Time.time + 5f;
			MelonLogger.Msg("NOCLIP ON - disabled " + (noclipDisabledColliders.Count - count) + " player collider(s), including hands.");
		}
		catch (Exception ex)
		{
			MelonLogger.Error("Enable NoClip error: " + ex.Message);
		}
	}

	private void DisableNoClip()
	{
		int num = 0;
		bool flag = noclipDisabledColliders.Count > 0;
		try
		{
			for (int num2 = noclipDisabledColliders.Count - 1; num2 >= 0; num2--)
			{
				Collider val = noclipDisabledColliders[num2];
				if ((Object)(object)val != (Object)null && !val.enabled)
				{
					val.enabled = true;
					num++;
				}
			}
		}
		catch (Exception ex)
		{
			MelonLogger.Error("Restore player collider error: " + ex.Message);
		}
		finally
		{
			noclipDisabledColliders.Clear();
			lastRigInstanceId = 0;
			if (flag)
			{
				TransferNoClipMomentum();
			}
		}
		MelonLogger.Msg("NOCLIP OFF - restored " + num + " collider(s).");
	}

	public override void OnDeinitializeMelon()
	{
		SavePersistentSettings();
		Hooking.OnLevelLoaded -= OnLevelLoaded;
		Hooking.OnLevelUnloaded -= OnLevelUnloaded;
		temporaryTransferRestorePending = false;
		RestoreTemporaryTransferColliders();
		DisableNoClip();
		RestoreControllerRigEnabledState();
		noclipEnabled = false;
		groundDetectorEnabled = false;
		airWalkEnabled = false;
		wallTransferEnabled = false;
		customGrounded = false;
		wallTransferActive = false;
		menuCreated = false;
		MelonLogger.Msg("NoClip unloaded - player colliders restored.");
	}

	private void OnLevelLoaded(LevelInfo info)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		MelonLogger.Msg("=== NOCLIP LEVEL LOADED ===");
		Scene activeScene = SceneManager.GetActiveScene();
		currentSceneHandle = ((Scene)(ref activeScene)).handle;
		BeginLevelSetup();
		BuildGroundMask();
		UpdatePlayerMeasurements();
		SearchJumpBinding();
		RebindControllerRigRecoveryAfterSceneChange();
		if (noclipEnabled)
		{
			EnableNoClip();
		}
	}

	private void OnLevelUnloaded()
	{
		//IL_005a: 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_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		groundMaskReady = false;
		calculatedGroundMask = 0;
		hasSmoothedGround = false;
		ResetGroundSupportStability();
		squareMapReady = false;
		Array.Clear(squareMapHasSample, 0, squareMapHasSample.Length);
		customGrounded = false;
		jumpRequested = false;
		jumpActive = false;
		jumpButtonWasDown = false;
		rightBWasPressed = false;
		thumbstickInput = Vector2.zero;
		aButtonDownField = null;
		aButtonDownProperty = null;
		jumpBindingSearched = false;
		wallTransferRequested = false;
		wallTransferActive = false;
		currentMoveVelocity = Vector3.zero;
		temporaryTransferRestorePending = false;
		RestoreTemporaryTransferColliders();
		PrepareControllerRigRecoveryForSceneChange();
		try
		{
			for (int num = noclipDisabledColliders.Count - 1; num >= 0; num--)
			{
				Collider val = noclipDisabledColliders[num];
				if ((Object)(object)val != (Object)null && !val.enabled)
				{
					val.enabled = true;
				}
			}
			noclipDisabledColliders.Clear();
		}
		catch (Exception ex)
		{
			MelonLogger.Warning("Level unload collider restore error: " + ex.Message);
		}
		lastRigInstanceId = 0;
		groundMissUntil = 0f;
		hasStableGroundFeetY = false;
		lastStableGroundFeetY = 0f;
		lastStableGroundTime = -10f;
		lastStableGroundPosition = Vector3.zero;
		ResetAirWalkHold();
		MelonLogger.Msg("NoClip: level unloaded; runtime state reset.");
	}

	private void BeginLevelSetup()
	{
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		groundMaskReady = false;
		calculatedGroundMask = 0;
		hasSmoothedGround = false;
		ResetGroundSupportStability();
		squareMapReady = false;
		Array.Clear(squareMapHasSample, 0, squareMapHasSample.Length);
		customGrounded = false;
		jumpRequested = false;
		jumpActive = false;
		jumpProtectionUntil = -10f;
		nextMaskRefreshTime = Time.time;
		maskRefreshUntil = Time.time + 5f;
		currentMoveVelocity = Vector3.zero;
		hasStableGroundFeetY = false;
		lastStableGroundFeetY = 0f;
		lastStableGroundTime = -10f;
		lastStableGroundPosition = Vector3.zero;
		ResetAirWalkHold();
	}

	private void UpdatePlayerMeasurements()
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			Transform feetTransform = GetFeetTransform();
			if ((Object)(object)feetTransform == (Object)null)
			{
				return;
			}
			if ((Object)(object)Player.Head != (Object)null)
			{
				float num = Mathf.Abs(Player.Head.position.y - feetTransform.position.y);
				if (num > 0.15f)
				{
					headToFeetDistance = num;
				}
			}
			if (!noclipEnabled)
			{
				MeasureFootGeometry();
			}
			float num2 = Mathf.Max(headToFeetDistance, 0.15f);
			probeRadius = Mathf.Clamp(footSupportRadius * 0.24f, 0.012f, num2 * 0.045f);
			groundClearance = Mathf.Max(num2 * 0.003f, 0.0015f);
			recoveryRange = Mathf.Max(num2 * 0.4f, 0.12f);
			correctionSpeed = Mathf.Clamp(num2 * 0.78f, 0.95f, 1.55f);
			float num3 = Mathf.Max(0f, 0f - GetFeetVerticalVelocity());
			float num4 = num3 * num3 / 36f + num3 * Time.fixedDeltaTime * 2.5f;
			rayDistance = Mathf.Max(num2 * 1.25f, 0.65f) + num4;
			float num5 = Mathf.Max(num2 * 0.105f, footSupportRadius * 1.65f);
			float num6 = Mathf.Max(num2 * 0.22f, 0.08f);
			playerCapsuleRadius = Mathf.Clamp(num5, 0.06f, num6);
		}
		catch (Exception ex)
		{
			MelonLogger.Warning("Player measurement error: " + ex.Message);
		}
	}

	private Transform GetFeetTransform()
	{
		try
		{
			if ((Object)(object)Player.PhysicsRig == (Object)null || (Object)(object)Player.PhysicsRig.feet == (Object)null)
			{
				return null;
			}
			return Player.PhysicsRig.feet.transform;
		}
		catch
		{
			return null;
		}
	}

	private void BuildGroundMask()
	{
		int num = 0;
		int num2 = LayerMask.NameToLayer("Ground");
		int num3 = LayerMask.NameToLayer("Platform");
		int num4 = LayerMask.NameToLayer("Static");
		int num5 = LayerMask.NameToLayer("Default");
		int num6 = LayerMask.NameToLayer("Environment");
		int num7 = LayerMask.NameToLayer("Terrain");
		int num8 = LayerMask.NameToLayer("World");
		int num9 = LayerMask.NameToLayer("Map");
		if (num2 != -1)
		{
			num |= 1 << num2;
		}
		if (num3 != -1)
		{
			num |= 1 << num3;
		}
		if (num4 != -1)
		{
			num |= 1 << num4;
		}
		if (num5 != -1)
		{
			num |= 1 << num5;
		}
		if (num6 != -1)
		{
			num |= 1 << num6;
		}
		if (num7 != -1)
		{
			num |= 1 << num7;
		}
		if (num8 != -1)
		{
			num |= 1 << num8;
		}
		if (num9 != -1)
		{
			num |= 1 << num9;
		}
		if (num == 0)
		{
			num = -1;
			MelonLogger.Warning("Named ground layers not found; using broad fallback mask.");
		}
		int num10 = LayerMask.NameToLayer("Player");
		int num11 = LayerMask.NameToLayer("Water");
		if (num10 != -1)
		{
			num &= ~(1 << num10);
		}
		if (num11 != -1)
		{
			num &= ~(1 << num11);
		}
		MelonLogger.Msg("Ground mask refreshed with world, default and platform layers.");
		calculatedGroundMask = num;
		groundMaskReady = num != 0;
	}

	private void ApplyNoclipMovement()
	{
		//IL_001f: 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_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: 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)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0213: Unknown result type (might be due to invalid IL or missing references)
		//IL_0218: Unknown result type (might be due to invalid IL or missing references)
		//IL_021f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0229: Unknown result type (might be due to invalid IL or missing references)
		//IL_0201: Unknown result type (might be due to invalid IL or missing references)
		//IL_0206: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_018d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0192: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: Unknown result type (might be due to invalid IL or missing references)
		if (!noclipEnabled || (Object)(object)Player.PhysicsRig == (Object)null || wallTransferActive)
		{
			return;
		}
		Vector3 planarMovementDirection = GetPlanarMovementDirection();
		float num = Mathf.Clamp01(((Vector2)(ref thumbstickInput)).magnitude);
		float num2 = num * num * (3f - 2f * num);
		bool flag = num > 0.12f;
		Vector3 val = planarMovementDirection * movementSpeed * num2;
		if (jumpActive || jumpRequested || GetFeetVerticalVelocity() > 0.18f)
		{
			val *= Mathf.Max(airControl, 0.35f);
		}
		bool flag2 = jumpRequested || !IsNoClipGroundContactForMomentum();
		float num3;
		if (flag)
		{
			num3 = ((((Vector3)(ref val)).sqrMagnitude > ((Vector3)(ref currentMoveVelocity)).sqrMagnitude) ? movementAcceleration : movementDeceleration);
			if (((Vector3)(ref val)).sqrMagnitude > 0.0001f && ((Vector3)(ref currentMoveVelocity)).sqrMagnitude > 0.0001f && Vector3.Dot(((Vector3)(ref currentMoveVelocity)).normalized, ((Vector3)(ref val)).normalized) < 0.35f)
			{
				num3 = Mathf.Max(num3, directionChangeDeceleration);
			}
		}
		else if (flag2)
		{
			num3 = 0f;
			val = currentMoveVelocity;
			float feetVerticalVelocity = GetFeetVerticalVelocity();
			bool flag3 = jumpActive || jumpRequested || feetVerticalVelocity > 0.18f;
			if (airWalkEnabled && !flag3)
			{
				float num4 = Mathf.Exp(-0.65f * Time.fixedDeltaTime);
				currentMoveVelocity *= num4;
				val = currentMoveVelocity;
			}
		}
		else
		{
			num3 = Mathf.Clamp(movementDeceleration * 0.28f, 4.5f, 15f);
			val = Vector3.zero;
		}
		if (num3 > 0f)
		{
			currentMoveVelocity = Vector3.MoveTowards(currentMoveVelocity, val, num3 * Time.fixedDeltaTime);
		}
		if (((Vector3)(ref currentMoveVelocity)).sqrMagnitude < movementStopThreshold * movementStopThreshold)
		{
			currentMoveVelocity = Vector3.zero;
			return;
		}
		lastMoveDirection = ((Vector3)(ref currentMoveVelocity)).normalized;
		ApplyRigDelta(currentMoveVelocity * Time.fixedDeltaTime);
	}

	private bool ReadJumpButton()
	{
		bool result = false;
		try
		{
			if (Input.GetButtonDown("Jump"))
			{
				result = true;
			}
		}
		catch
		{
		}
		try
		{
			if (Input.GetKeyDown((KeyCode)32))
			{
				result = true;
			}
		}
		catch
		{
		}
		try
		{
			if (!jumpBindingSearched)
			{
				SearchJumpBinding();
			}
			Hand rightHand = Player.RightHand;
			if ((Object)(object)rightHand == (Object)null || (Object)(object)rightHand.Controller == (Object)null)
			{
				return result;
			}
			object controller = rightHand.Controller;
			if (aButtonDownField != null)
			{
				object value = aButtonDownField.GetValue(controller);
				if (value is bool && (bool)value)
				{
					result = true;
				}
			}
			if (aButtonDownProperty != null)
			{
				object value2 = aButtonDownProperty.GetValue(controller);
				if (value2 is bool && (bool)value2)
				{
					result = true;
				}
			}
		}
		catch
		{
		}
		return result;
	}

	private void SearchJumpBinding()
	{
		jumpBindingSearched = true;
		try
		{
			Hand rightHand = Player.RightHand;
			if (!((Object)(object)rightHand == (Object)null) && !((Object)(object)rightHand.Controller == (Object)null))
			{
				Type type = ((object)rightHand.Controller).GetType();
				aButtonDownField = type.GetField("_aButtonDown", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (aButtonDownField == null)
				{
					aButtonDownField = type.GetField("aButtonDown", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				}
				aButtonDownProperty = type.GetProperty("_aButtonDown", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (aButtonDownProperty == null)
				{
					aButtonDownProperty = type.GetProperty("AButtonDown", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				}
			}
		}
		catch
		{
		}
	}

	private void TryCreateBoneMenu()
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: 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_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0216: Unknown result type (might be due to invalid IL or missing references)
		//IL_0239: Unknown result type (might be due to invalid IL or missing references)
		//IL_025b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0292: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0308: Unknown result type (might be due to invalid IL or missing references)
		//IL_033a: Unknown result type (might be due to invalid IL or missing references)
		//IL_036c: Unknown result type (might be due to invalid IL or missing references)
		//IL_038e: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0409: Unknown result type (might be due to invalid IL or missing references)
		//IL_043b: 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_049f: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0504: Unknown result type (might be due to invalid IL or missing references)
		//IL_0521: Unknown result type (might be due to invalid IL or missing references)
		//IL_053e: Unknown result type (might be due to invalid IL or missing references)
		//IL_055a: Unknown result type (might be due to invalid IL or missing references)
		if (menuCreated)
		{
			return;
		}
		try
		{
			if (Page.Root != null)
			{
				mainPage = Page.Root.CreatePage("NoClip V4", Color.cyan, 0, true);
				mainPage.CreateFunction("NoClip", Color.cyan, (Action)delegate
				{
					SetNoClipState(!noclipEnabled);
					MelonLogger.Msg("MENU: NoClip toggled " + (noclipEnabled ? "ON" : "OFF"));
				});
				mainPage.CreateBool("Ground Detector", Color.green, groundDetectorEnabled, (Action<bool>)delegate(bool value)
				{
					SetGroundDetectorState(value);
				});
				mainPage.CreateBool("Air Walk", Color.yellow, airWalkEnabled, (Action<bool>)delegate(bool value)
				{
					SetAirWalkState(value);
				});
				mainPage.CreateBool("Wall Transfer", Color.magenta, wallTransferEnabled, (Action<bool>)delegate(bool value)
				{
					wallTransferEnabled = value;
					SavePersistentSettings();
				});
				Page obj = mainPage.CreatePage("Movement", Color.white, 0, true);
				obj.CreateFloat("Move Speed", Color.white, movementSpeed, 0.25f, 1f, float.MaxValue, (Action<float>)delegate(float value)
				{
					movementSpeed = Mathf.Max(value, 1f);
					SavePersistentSettings();
				});
				obj.CreateFloat("Acceleration", Color.white, movementAcceleration, 0.5f, 2f, float.MaxValue, (Action<float>)delegate(float value)
				{
					movementAcceleration = Mathf.Max(value, 2f);
					SavePersistentSettings();
				});
				obj.CreateFloat("Deceleration", Color.white, movementDeceleration, 1f, 5f, float.MaxValue, (Action<float>)delegate(float value)
				{
					movementDeceleration = Mathf.Max(value, 5f);
					SavePersistentSettings();
				});
				obj.CreateFloat("Air Control", Color.white, airControl, 0.05f, 0f, float.MaxValue, (Action<float>)delegate(float value)
				{
					airControl = Mathf.Max(value, 0f);
					SavePersistentSettings();
				});
				obj.CreateFloat("Jump Height", Color.white, jumpVelocity, 0.25f, 3.5f, float.MaxValue, (Action<float>)delegate(float value)
				{
					jumpVelocity = Mathf.Max(value, 3.5f);
					SavePersistentSettings();
				});
				Page obj2 = mainPage.CreatePage("Ground Detector", Color.green, 0, true);
				obj2.CreateFunction("Refresh Layer Mask", Color.white, (Action)RefreshGroundMaskNow);
				obj2.CreateBool("Square Ground Map", Color.green, squareGroundMapEnabled, (Action<bool>)delegate(bool value)
				{
					squareGroundMapEnabled = value;
					squareMapReady = false;
					SavePersistentSettings();
				});
				obj2.CreateBool("Map Always On", Color.green, squareGroundMapAlwaysOn, (Action<bool>)delegate(bool value)
				{
					squareGroundMapAlwaysOn = value;
					SavePersistentSettings();
				});
				obj2.CreateFloat("Map Size", Color.white, squareGroundMapSize, 0.25f, 1.5f, 10f, (Action<float>)delegate(float value)
				{
					squareGroundMapSize = Mathf.Clamp(value, 1.5f, 10f);
					squareMapReady = false;
					SavePersistentSettings();
				});
				Page obj3 = mainPage.CreatePage("Air Walk", Color.yellow, 0, true);
				obj3.CreateFloat("Guide Speed (m/s)", Color.white, airWalkAssistSpeed, 0.25f, 0.5f, float.MaxValue, (Action<float>)delegate(float value)
				{
					airWalkAssistSpeed = Mathf.Max(value, 0.5f);
					SavePersistentSettings();
				});
				obj3.CreateFloat("Horizontal Guide Range (m)", Color.white, airWalkHorizontalGuideRange, 0.5f, 0.5f, float.MaxValue, (Action<float>)delegate(float value)
				{
					airWalkHorizontalGuideRange = Mathf.Max(value, 0.5f);
					SavePersistentSettings();
				});
				obj3.CreateFloat("Vertical Guide Range (+/- m)", Color.white, airWalkVerticalGuideRange, 0.25f, 0.25f, float.MaxValue, (Action<float>)delegate(float value)
				{
					airWalkVerticalGuideRange = Mathf.Max(value, 0.25f);
					SavePersistentSettings();
				});
				obj3.CreateFloat("Guide Path Width (m)", Color.white, airWalkGuidePathWidth, 0.1f, 0.25f, float.MaxValue, (Action<float>)delegate(float value)
				{
					airWalkGuidePathWidth = Mathf.Max(value, 0.25f);
					SavePersistentSettings();
				});
				obj3.CreateBool("Look-Down Descent", Color.yellow, airWalkLookDownDescentEnabled, (Action<bool>)delegate(bool value)
				{
					airWalkLookDownDescentEnabled = value;
					SavePersistentSettings();
				});
				obj3.CreateFloat("Descent Angle (degrees)", Color.white, airWalkDescentAngle, 5f, 5f, 90f, (Action<float>)delegate(float value)
				{
					airWalkDescentAngle = Mathf.Clamp(Mathf.Round(value / 5f) * 5f, 5f, 90f);
					SavePersistentSettings();
				});
				Page obj4 = mainPage.CreatePage("Wall Transfer", Color.magenta, 0, true);
				obj4.CreateFloat("Wall Detection", Color.white, wallDetectionDistance, 0.1f, 0.5f, float.MaxValue, (Action<float>)delegate(float value)
				{
					wallDetectionDistance = Mathf.Max(value, 0.5f);
					SavePersistentSettings();
				});
				obj4.CreateFloat("Wall Clearance", Color.white, wallClearance, 0.02f, 0.03f, float.MaxValue, (Action<float>)delegate(float value)
				{
					wallClearance = Mathf.Max(value, 0.03f);
					SavePersistentSettings();
				});
				obj4.CreateFloat("Search Distance", Color.white, wallScanDistance, 0.25f, 1f, float.MaxValue, (Action<float>)delegate(float value)
				{
					wallScanDistance = Mathf.Max(value, 1f);
					SavePersistentSettings();
				});
				obj4.CreateFloat("Search Step", Color.white, wallScanStep, 0.05f, 0.05f, float.MaxValue, (Action<float>)delegate(float value)
				{
					wallScanStep = Mathf.Clamp(value, 0.08f, 0.2f);
					SavePersistentSettings();
				});
				obj4.CreateFloat("Open Space Depth", Color.white, wallOpenSpaceDepth, 0.05f, 0.3f, float.MaxValue, (Action<float>)delegate(float value)
				{
					wallOpenSpaceDepth = Mathf.Max(value, 0.3f);
					SavePersistentSettings();
				});
				obj4.CreateFunction("Transfer Now", Color.magenta, (Action)delegate
				{
					wallTransferRequested = true;
				});
				Page obj5 = mainPage.CreatePage("Presets", Color.cyan, 0, true);
				obj5.CreateFunction("Default", Color.white, (Action)delegate
				{
					ApplyPreset(0);
				});
				obj5.CreateFunction("Fast", Color.white, (Action)delegate
				{
					ApplyPreset(1);
				});
				obj5.CreateFunction("Precision", Color.white, (Action)delegate
				{
					ApplyPreset(2);
				});
				obj5.CreateFunction("Stable Ground", Color.white, (Action)delegate
				{
					ApplyPreset(3);
				});
				menuCreated = true;
				MelonLogger.Msg("BoneLib NoClip V4 menu created.");
			}
		}
		catch (Exception ex)
		{
			MelonLogger.Error("BoneLib menu creation error: " + ex.Message);
		}
	}

	private void SetGroundDetectorState(bool enabled)
	{
		if (groundDetectorEnabled != enabled)
		{
			groundDetectorEnabled = enabled;
			SavePersistentSettings();
			ResetGroundSupportStability();
			hasSmoothedGround = false;
			squareMapReady = false;
			Array.Clear(squareMapHasSample, 0, squareMapHasSample.Length);
			customGrounded = false;
			if (enabled)
			{
				BuildGroundMask();
				nextMaskRefreshTime = Time.time;
				maskRefreshUntil = Time.time + 5f;
				MelonLogger.Msg("GROUND DETECTOR: ON");
			}
			else
			{
				MelonLogger.Msg("GROUND DETECTOR: OFF");
			}
		}
	}

	private void RefreshGroundMaskNow()
	{
		BuildGroundMask();
		nextMaskRefreshTime = Time.time;
		maskRefreshUntil = Time.time + 5f;
		hasSmoothedGround = false;
		ResetGroundSupportStability();
	}

	private void SetNoClipState(bool enabled)
	{
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		if (noclipEnabled == enabled)
		{
			return;
		}
		noclipEnabled = enabled;
		SavePersistentSettings();
		customGrounded = false;
		hasSmoothedGround = false;
		jumpActive = false;
		jumpRequested = false;
		wallTransferRequested = false;
		currentMoveVelocity = Vector3.zero;
		if (enabled)
		{
			CaptureControllerRigEnabledState();
			UpdatePlayerMeasurements();
			EnableNoClip();
			MelonLogger.Msg("NOCLIP STATE: ON");
			return;
		}
		if (temporaryTransferColliders != null)
		{
			RestoreTemporaryTransferColliders();
		}
		DisableNoClip();
		RestoreControllerRigEnabledState(keepRecoveryWindow: true);
		MelonLogger.Msg("NOCLIP STATE: OFF");
	}

	private Vector3 GetPlanarLookDirection()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: 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_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		Vector3 forward = Vector3.forward;
		try
		{
			if ((Object)(object)Player.Head != (Object)null)
			{
				forward = Player.Head.forward;
			}
			else if ((Object)(object)Player.PhysicsRig != (Object)null)
			{
				forward = ((Component)Player.PhysicsRig).transform.forward;
			}
		}
		catch
		{
		}
		forward.y = 0f;
		if (((Vector3)(ref forward)).sqrMagnitude < 0.0001f)
		{
			return Vector3.forward;
		}
		return ((Vector3)(ref forward)).normalized;
	}

	private Vector3 GetPlanarMovementDirection()
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: 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_0015: 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_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: 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_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: 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_0083: 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)
		Vector3 planarLookDirection = GetPlanarLookDirection();
		Vector3 val = Vector3.Cross(Vector3.up, planarLookDirection);
		Vector3 normalized = ((Vector3)(ref val)).normalized;
		Vector3 val2 = planarLookDirection * thumbstickInput.y + normalized * thumbstickInput.x;
		val2.y = 0f;
		if (((Vector3)(ref val2)).sqrMagnitude >= 1E-06f)
		{
			return ((Vector3)(ref val2)).normalized;
		}
		if (((Vector3)(ref lastMoveDirection)).sqrMagnitude > 0.0001f)
		{
			return ((Vector3)(ref lastMoveDirection)).normalized;
		}
		return planarLookDirection;
	}

	private void ApplyRigDelta(Vector3 delta)
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)Player.PhysicsRig == (Object)null || ((Vector3)(ref delta)).sqrMagnitude <= 1E-08f)
		{
			return;
		}
		try
		{
			Transform transform = ((Component)Player.PhysicsRig).transform;
			transform.position += delta;
		}
		catch (Exception ex)
		{
			MelonLogger.Error("Rig movement error: " + ex.Message);
		}
	}

	private bool FindGroundAtPosition(Vector3 feetPosition, Vector3 forwardDirection, out Vector3 groundPoint, out Vector3 groundNormal)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		Collider supportCollider;
		return FindGroundAtPosition(feetPosition, forwardDirection, out groundPoint, out groundNormal, out supportCollider);
	}

	private void ApplyAirWalkAssist()
	{
		//IL_003e: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_0224: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_041e: Unknown result type (might be due to invalid IL or missing references)
		//IL_042b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0498: Unknown result type (might be due to invalid IL or missing references)
		//IL_045c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0468: Unknown result type (might be due to invalid IL or missing references)
		//IL_0538: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_053d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0530: Unknown result type (might be due to invalid IL or missing references)
		//IL_0523: Unknown result type (might be due to invalid IL or missing references)
		//IL_0500: Unknown result type (might be due to invalid IL or missing references)
		//IL_0397: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_055a: Unknown result type (might be due to invalid IL or missing references)
		//IL_055f: 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_0572: Unknown result type (might be due to invalid IL or missing references)
		//IL_057b: Unknown result type (might be due to invalid IL or missing references)
		//IL_057e: Unknown result type (might be due to invalid IL or missing references)
		//IL_057f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0581: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0705: Unknown result type (might be due to invalid IL or missing references)
		//IL_070a: Unknown result type (might be due to invalid IL or missing references)
		//IL_070f: Unknown result type (might be due to invalid IL or missing references)
		//IL_074d: Unknown result type (might be due to invalid IL or missing references)
		//IL_074f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0754: Unknown result type (might be due to invalid IL or missing references)
		//IL_0759: Unknown result type (might be due to invalid IL or missing references)
		//IL_0767: Unknown result type (might be due to invalid IL or missing references)
		//IL_0769: Unknown result type (might be due to invalid IL or missing references)
		//IL_076e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0773: Unknown result type (might be due to invalid IL or missing references)
		//IL_07e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_07eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_06e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_05f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0619: Unknown result type (might be due to invalid IL or missing references)
		//IL_0620: Unknown result type (might be due to invalid IL or missing references)
		//IL_062c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0633: Unknown result type (might be due to invalid IL or missing references)
		//IL_063a: Unknown result type (might be due to invalid IL or missing references)
		//IL_063f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0664: Unknown result type (might be due to invalid IL or missing references)
		//IL_0665: Unknown result type (might be due to invalid IL or missing references)
		//IL_0672: Unknown result type (might be due to invalid IL or missing references)
		//IL_0689: Unknown result type (might be due to invalid IL or missing references)
		//IL_080f: Unknown result type (might be due to invalid IL or missing references)
		//IL_087c: Unknown result type (might be due to invalid IL or missing references)
		//IL_08a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_08a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_08ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_08c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0951: Unknown result type (might be due to invalid IL or missing references)
		//IL_0954: Unknown result type (might be due to invalid IL or missing references)
		//IL_0959: Unknown result type (might be due to invalid IL or missing references)
		//IL_095e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0973: Unknown result type (might be due to invalid IL or missing references)
		//IL_0975: Unknown result type (might be due to invalid IL or missing references)
		//IL_0976: Unknown result type (might be due to invalid IL or missing references)
		//IL_097b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0992: Unknown result type (might be due to invalid IL or missing references)
		//IL_099e: Unknown result type (might be due to invalid IL or missing references)
		//IL_09a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_09c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0be6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0bec: Unknown result type (might be due to invalid IL or missing references)
		//IL_0bf1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0bf6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b1b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b28: Unknown result type (might be due to invalid IL or missing references)
		//IL_08ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_08f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_08f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_08fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c13: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c18: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c19: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c1e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c44: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c3b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c80: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c82: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c87: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c8c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c9a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c9c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c73: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c74: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c49: Unknown result type (might be due to invalid IL or missing references)
		//IL_0cc2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0cc7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0bad: Unknown result type (might be due to invalid IL or missing references)
		//IL_0bba: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a50: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a53: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a58: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a5d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0ddd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0de2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0df0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0df2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0aa1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0aa3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0ae2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0ae3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0af0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0e82: Unknown result type (might be due to invalid IL or missing references)
		//IL_0fce: Unknown result type (might be due to invalid IL or missing references)
		//IL_0fd0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0fd5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0fda: Unknown result type (might be due to invalid IL or missing references)
		//IL_0e2a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0e2f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0e3d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0e3f: Unknown result type (might be due to invalid IL or missing references)
		//IL_1018: Unknown result type (might be due to invalid IL or missing references)
		//IL_101a: Unknown result type (might be due to invalid IL or missing references)
		//IL_101f: Unknown result type (might be due to invalid IL or missing references)
		//IL_1024: Unknown result type (might be due to invalid IL or missing references)
		//IL_1085: Unknown result type (might be due to invalid IL or missing references)
		//IL_1086: Unknown result type (might be due to invalid IL or missing references)
		//IL_10e3: Unknown result type (might be due to invalid IL or missing references)
		if (!airWalkEnabled || (Object)(object)Player.PhysicsRig == (Object)null)
		{
			return;
		}
		if (!groundMaskReady || calculatedGroundMask == 0)
		{
			BuildGroundMask();
		}
		Transform feetTransform = GetFeetTransform();
		if ((Object)(object)feetTransform == (Object)null)
		{
			return;
		}
		Vector3 position = feetTransform.position;
		float num = Mathf.Max(headToFeetDistance, 0.15f);
		float feetVerticalVelocity = GetFeetVerticalVelocity();
		bool flag = ((Vector2)(ref thumbstickInput)).sqrMagnitude > 0.0144f;
		bool flag2 = jumpActive && Time.time < jumpProtectionUntil;
		bool flag3 = feetVerticalVelocity > Mathf.Max(0.65f, num * 0.32f);
		float supportFeetY;
		bool flag4 = TryGetAirWalkGroundContact(position, out supportFeetY);
		if (flag4)
		{
			RememberAirWalkDepartureSurface(position);
		}
		bool flag5 = (jumpActive && feetVerticalVelocity > -0.1f) || feetVerticalVelocity > 0.55f;
		if (!airWalkStateInitialized)
		{
			InitializeAirWalkRuntimeState(position, feetVerticalVelocity, flag4);
		}
		bool flag6 = false;
		float supportFeetY2 = position.y;
		if (!airWalkAssistActive && airWalkGroundRearmLatched)
		{
			flag6 = TryGetAirWalkStableLandingSupport(position, out supportFeetY2);
		}
		bool flag7 = flag4 || flag6;
		bool flag8 = flag7 && feetVerticalVelocity < 0.65f && !flag2 && !flag3 && !flag5;
		if (!airWalkAssistActive)
		{
			if (flag8)
			{
				airWalkWaitingForTakeoff = true;
				airWalkGroundRearmLatched = true;
				airWalkTakeoffClearFrames = 0;
				airWalkGroundContactFrames = 0;
				if (flag4 || flag6)
				{
					RememberAirWalkDepartureSurface(position);
				}
				if (noclipEnabled)
				{
					NeutralizeAirWalkVerticalPhysics();
				}
				return;
			}
			if (flag5)
			{
				airWalkTakeoffClearFrames = 2;
				airWalkGroundRearmLatched = false;
			}
			else if (!flag7)
			{
				airWalkTakeoffClearFrames++;
				if (airWalkTakeoffClearFrames >= 2)
				{
					airWalkGroundRearmLatched = false;
				}
			}
			else
			{
				airWalkTakeoffClearFrames = 0;
			}
			if (airWalkTakeoffClearFrames < 2)
			{
				if (noclipEnabled)
				{
					NeutralizeAirWalkVerticalPhysics();
				}
				return;
			}
			airWalkGroundRearmLatched = false;
			ActivateAirWalkAssistAtCurrentPosition(position, feetVerticalVelocity);
			feetVerticalVelocity = GetFeetVerticalVelocity();
			flag2 = jumpActive && Time.time < jumpProtectionUntil;
			flag3 = feetVerticalVelocity > Mathf.Max(0.65f, num * 0.32f);
		}
		float num2 = Mathf.Max(0f, 0f - feetVerticalVelocity);
		float supportFeetY3;
		float gap;
		bool num3 = TryGetAirWalkLandingSupport(position, num2, out supportFeetY3, out gap);
		bool flag9 = flag2 || flag3 || airWalkWasAscending;
		if (num3 && !flag9)
		{
			if (num2 > 0.1f)
			{
				float num4 = Mathf.Max(gap - 0.055f, 0f);
				float num5 = Mathf.Sqrt(36f * num4);
				num5 = Mathf.Max(num5, 0.12f);
				LimitAirWalkDownwardVelocity(num5);
				feetVerticalVelocity = GetFeetVerticalVelocity();
			}
			if (gap < -0.018f)
			{
				float num6 = Mathf.Clamp(0f - gap + 0.008f, 0.008f, 0.085f);
				ApplyRigDelta(Vector3.up * num6);
				NeutralizeAirWalkVerticalPhysics();
				return;
			}
		}
		float supportFeetY4;
		bool flag10 = TryGetAirWalkStableLandingSupport(position, out supportFeetY4);
		if ((flag10 || flag4) && feetVerticalVelocity < 0.65f && !flag2 && !flag3 && !flag5)
		{
			airWalkGroundContactFrames++;
			if (noclipEnabled)
			{
				NeutralizeAirWalkVerticalPhysics();
			}
			else
			{
				StopDownwardVelocity();
			}
			int num7 = (flag10 ? 2 : 4);
			if (airWalkGroundContactFrames >= num7)
			{
				airWalkAssistActive = false;
				airWalkWaitingForTakeoff = true;
				airWalkTakeoffClearFrames = 0;
				airWalkWasAscending = false;
				airWalkGroundRearmLatched = true;
				airWalkSmoothedTargetY = (airWalkHoldFeetY = (flag10 ? supportFeetY4 : supportFeetY));
				airWalkTargetVelocity = 0f;
				airWalkFreeDescentSpeed = 0f;
				RememberAirWalkDepartureSurface(position);
				airWalkBlockedTargetCollider = null;
				airWalkBlockedTargetPoint = Vector3.zero;
				airWalkBlockedAtPosition = Vector3.zero;
				airWalkBlockedTargetFeetY = 0f;
				airWalkBlockedTargetRadius = 0.9f;
				airWalkBlockedTargetUntil = -1f;
				ClearAirWalkGuide();
				SetAirWalkNotice("AIR WALK: ON - GROUNDED / ARMED");
				MelonLogger.Msg("AIR WALK: physical landing confirmed; ability remains ON and is re-armed for takeoff.");
			}
			return;
		}
		airWalkGroundContactFrames = 0;
		if (airWalkGuideReturnActive)
		{
			float searchDistance = Mathf.Max(airWalkHorizontalGuideRange, 0.5f);
			if (!IsAirWalkGuideWithinBounds(position, searchDistance, out var reason))
			{
				CancelAirWalkGuideAtCurrentHeight(position, reason, blockPreviousTarget: true);
			}
		}
		if (flag2 || flag3)
		{
			airWalkWasAscending = true;
			return;
		}
		if (airWalkWasAscending)
		{
			if (feetVerticalVelocity > -0.08f)
			{
				return;
			}
			airWalkWasAscending = false;
			airWalkHoldFeetY = position.y;
			airWalkSmoothedTargetY = position.y;
			airWalkTargetVelocity = 0f;
			hasAirWalkHoldHeight = true;
			MelonLogger.Msg("AIR WALK: hover height anchored at end of ascent.");
		}
		if (!hasAirWalkHoldHeight)
		{
			airWalkHoldFeetY = position.y;
			hasAirWalkHoldHeight = true;
		}
		float num8 = Mathf.Max(airWalkHorizontalGuideRange, 0.5f);
		float num9 = Mathf.Max(num * 0.03f, 0.055f);
		float airWalkDescentIntentStrength = GetAirWalkDescentIntentStrength();
		bool flag11 = airWalkDescentIntentStrength > 0.001f;
		if (flag11 && airWalkGuideReturnActive && airWalkGuideTargetFeetY > position.y + num9)
		{
			CancelAirWalkGuideAtCurrentHeight(position, "look-down + forward descent request", blockPreviousTarget: false);
		}
		Vector3 searchDirection = (flag ? GetPlanarMovementDirection() : ((((Vector3)(ref currentMoveVelocity)).sqrMagnitude > 0.05f) ? ((Vector3)(ref currentMoveVelocity)).normalized : GetPlanarLookDirection()));
		searchDirection.y = 0f;
		if (((Vector3)(ref searchDirection)).sqrMagnitude < 0.0001f)
		{
			searchDirection = GetPlanarLookDirection();
		}
		else
		{
			((Vector3)(ref searchDirection)).Normalize();
		}
		Vector3 savedRangeAnchor = (airWalkGuideReturnActive ? airWalkGuideReturnPoint : position);
		Vector3 groundPoint;
		Vector3 groundNormal;
		float targetFeetY;
		Collider targetCollider;
		bool flag12 = FindAirWalkGround(position, searchDirection, savedRangeAnchor, num8, flag11, out groundPoint, out groundNormal, out targetFeetY, out targetCollider);
		if (flag12 && ((Object)(object)targetCollider == (Object)null || groundNormal.y < 0.32f))
		{
			flag12 = false;
		}
		if (!airWalkGuideReturnActive)
		{
			if (!flag12 || !(Mathf.Abs(targetFeetY - position.y) >= num9))
			{
				ApplyAirWalkFreeDescent(position, airWalkDescentIntentStrength, feetVerticalVelocity, num);
				return;
			}
			airWalkFreeDescentSpeed = 0f;
			airWalkGuideReturnPoint = position;
			airWalkGuideTargetPoint = groundPoint;
			airWalkGuideTargetFeetY = targetFeetY;
			airWalkGuideCollider = targetCollider;
			airWalkGuideReturnActive = true;
			airWalkNoTargetSince = -1f;
			Vector3 val = new Vector3(groundPoint.x - position.x, 0f, groundPoint.z - position.z);
			airWalkGuideInitialDistance = ((Vector3)(ref val)).magnitude;
			airWalkGuideProgress = 0f;
			airWalkGuideBlockedProgress = 0f;
			airWalkGuideLastPosition = position;
			airWalkGuideProgressInitialized = true;
			airWalkSmoothedTargetY = position.y;
			airWalkTargetVelocity = 0f;
			airWalkHoldFeetY = position.y;
			MelonLogger.Msg("AIR WALK: guide acquired; target height=" + targetFeetY.ToString("F2") + "m; horizontal distance=" + airWalkGuideInitialDistance.ToString("F2") + "m.");
		}
		float num10 = Mathf.Max(airWalkGuidePathWidth, 0.25f);
		Vector3 val2 = airWalkGuideTargetPoint - airWalkGuideReturnPoint;
		val2.y = 0f;
		float magnitude = ((Vector3)(ref val2)).magnitude;
		float num11 = Mathf.Min(num8, Mathf.Max(magnitude, num10));
		bool num12 = magnitude <= num11 * 2f - 0.001f;
		Vector3 val3 = position - airWalkGuideReturnPoint;
		val3.y = 0f;
		Vector3 val4 = position - airWalkGuideTargetPoint;
		val4.y = 0f;
		bool flag13 = ((Vector3)(ref val3)).sqrMagnitude <= num11 * num11;
		bool flag14 = ((Vector3)(ref val4)).sqrMagnitude <= num11 * num11;
		float num13 = num10;
		float num14 = Mathf.Min(airWalkGuideReturnPoint.y, airWalkGuideTargetFeetY) - num13;
		float num15 = Mathf.Max(airWalkGuideReturnPoint.y, airWalkGuideTargetFeetY) + num13;
		bool flag15 = position.y >= num14 && position.y <= num15;
		if (!num12 || !flag13 || !flag14 || !flag15)
		{
			CancelAirWalkGuideAtCurrentHeight(position, "player left the guide bounds (start=" + ((Vector3)(ref val3)).magnitude.ToString("F2") + "m, target=" + ((Vector3)(ref val4)).magnitude.ToString("F2") + "m, vertical band=" + flag15 + ")", blockPreviousTarget: true);
			ApplyAirWalkHeightCorrection(position.y, airWalkHoldFeetY, feetVerticalVelocity, num);
			return;
		}
		bool flag16 = IsAirWalkGuideTargetStillPresent();
		bool flag17 = false;
		if (flag16 && !HasAirWalkTargetClearance(position, airWalkGuideTargetPoint, airWalkGuideTargetFeetY))
		{
			CancelAirWalkGuideAtCurrentHeight(position, "ceiling obstructs the selected guide route", blockPreviousTarget: true);
			ApplyAirWalkFreeDescent(position, 0f, feetVerticalVelocity, num);
			return;
		}
		if (flag12)
		{
			if (!flag16 && (Object)(object)airWalkGuideCollider != (Object)null)
			{
				Vector3 val5 = groundPoint - airWalkGuideTargetPoint;
				val5.y = 0f;
				if ((Object)(object)targetCollider == (Object)(object)airWalkGuideCollider && ((Vector3)(ref val5)).magnitude <= 0.8f && Mathf.Abs(targetFeetY - airWalkGuideTargetFeetY) <= 0.3f)
				{
					flag16 = true;
					airWalkNoTargetSince = -1f;
				}
			}
			Vector3 val6 = groundPoint - airWalkGuideReturnPoint;
			val6.y = 0f;
			float magnitude2 = ((Vector3)(ref val6)).magnitude;
			Vector3 val7 = groundPoint - position;
			val7.y = 0f;
			float magnitude3 = ((Vector3)(ref val7)).magnitude;
			float num16 = Vector3.Distance(new Vector3(groundPoint.x, 0f, groundPoint.z), new Vector3(airWalkGuideTargetPoint.x, 0f, airWalkGuideTargetPoint.z));
			float num17 = Mathf.Abs(targetFeetY - airWalkGuideTargetFeetY);
			bool num18 = magnitude2 <= num8 && magnitude3 <= num8;
			bool flag18 = num16 >= 0.8f || num17 >= 0.16f || ((Object)(object)targetCollider != (Object)null && (Object)(object)airWalkGuideCollider != (Object)null && (Object)(object)targetCollider != (Object)(object)airWalkGuideCollider && num16 >= 0.35f);
			bool flag19 = !flag16;
			if (num18 && flag18 && flag19)
			{
				Vector3 val8 = groundPoint - airWalkGuideReturnPoint;
				val8.y = 0f;
				bool flag20 = ((Vector3)(ref val7)).sqrMagnitude <= num11 * num11;
				if (((Vector3)(ref val8)).magnitude <= num11 * 2f - 0.001f && flag13 && flag20)
				{
					airWalkGuideTargetPoint = groundPoint;
					airWalkGuideTargetFeetY = targetFeetY;
					airWalkGuideCollider = targetCollider;
					airWalkNoTargetSince = -1f;
					airWalkGuideInitialDistance = magnitude3;
					airWalkGuideProgress = 0f;
					airWalkGuideBlockedProgress = 0f;
					airWalkGuideLastPosition = position;
					airWalkGuideProgressInitialized = true;
					airWalkSmoothedTargetY = position.y;
					airWalkTargetVelocity = 0f;
					flag17 = true;
					flag16 = true;
				}
			}
		}
		if (!(flag16 || flag17))
		{
			if (flag11)
			{
				CancelAirWalkGuideAtCurrentHeight(position, "lower target unavailable; continuing free-air descent", blockPreviousTarget: false);
				ApplyAirWalkFreeDescent(position, airWalkDescentIntentStrength, feetVerticalVelocity, num);
				return;
			}
			if (airWalkNoTargetSince < 0f)
			{
				airWalkNoTargetSince = Time.time;
			}
			bool num19 = (Object)(object)airWalkGuideCollider != (Object)null && airWalkGuideCollider.enabled && (Object)(object)((Component)airWalkGuideCollider).gameObject != (Object)null && ((Component)airWalkGuideCollider).gameObject.activeInHierarchy;
			bool flag21 = Time.time - airWalkNoTargetSince >= 0.7f;
			if (!num19 || flag21)
			{
				CancelAirWalkGuideAtCurrentHeight(position, "selected surface disappeared or became unsafe", blockPreviousTarget: true);
				ApplyAirWalkFreeDescent(position, 0f, feetVerticalVelocity, num);
				return;
			}
		}
		else
		{
			airWalkNoTargetSince = -1f;
		}
		float num20 = Mathf.Max(airWalkGuideInitialDistance, 0.05f);
		Vector3 val9 = airWalkGuideTargetPoint - airWalkGuideReturnPoint;
		val9.y = 0f;
		if (((Vector3)(ref val9)).sqrMagnitude < 0.0001f)
		{
			Vector3 val10 = airWalkGuideTargetPoint - position;
			val10.y = 0f;
			val9 = ((((Vector3)(ref val10)).sqrMagnitude > 0.0001f) ? ((Vector3)(ref val10)).normalized : GetPlanarLookDirection());
		}
		else
		{
			((Vector3)(ref val9)).Normalize();
		}
		if (!airWalkGuideProgressInitialized)
		{
			airWalkGuideProgress = 0f;
			airWalkGuideBlockedProgress = 0f;
			airWalkGuideLastPosition = position;
			airWalkGuideProgressInitialized = true;
		}
		Vector3 val11 = position - airWalkGuideLastPosition;
		val11.y = 0f;
		float num21 = Vector3.Dot(val11, val9);
		float num22 = 0f;
		float num23 = 0f;
		float num24 = 0f;
		if (flag)
		{
			num22 = Vector3.Dot(GetPlanarMovementDirection(), val9) * movementSpeed * Mathf.Clamp01(((Vector2)(ref thumbstickInput)).magnitude);
			float num25 = num22 * Time.fixedDeltaTime;
			if (Mathf.Abs(num25) > 0.0005f)
			{
				if (airWalkGuideBlockedProgress * num22 < -0.0001f)
				{
					airWalkGuideBlockedProgress = 0f;
				}
				airWalkGuideBlockedProgress += (num25 - num21) / num20;
				airWalkGuideBlockedProgress = Mathf.Clamp(airWalkGuideBlockedProgress, -1f, 1f);
			}
			num23 = Mathf.Abs(num22);
			num24 = Mathf.Max(0f, num22);
		}
		else if (Mathf.Abs(num21) > 0.0005f && Mathf.Abs(airWalkGuideBlockedProgress) > 0.0005f)
		{
			if (Mathf.Sign(num21) != Mathf.Sign(airWalkGuideBlockedProgress))
			{
				airWalkGuideBlockedProgress = 0f;
			}
			else
			{
				float num26 = num21 / num20;
				if (Mathf.Abs(num26) >= Mathf.Abs(airWalkGuideBlockedProgress))
				{
					airWalkGuideBlockedProgress = 0f;
				}
				else
				{
					airWalkGuideBlockedProgress -= num26;
				}
			}
		}
		Vector3 val12 = currentMoveVelocity;
		val12.y = 0f;
		float num27 = Vector3.Dot(val12, val9);
		num23 = Mathf.Max(num23, Mathf.Abs(num27));
		num24 = Mathf.Max(num24, num27);
		Rigidbody feetRigidbody = GetFeetRigidbody();
		if ((Object)(object)feetRigidbody != (Object)null)
		{
			Vector3 velocity = feetRigidbody.velocity;
			velocity.y = 0f;
			float num28 = Vector3.Dot(velocity, val9);
			num23 = Mathf.Max(num23, Mathf.Abs(num28));
			num24 = Mathf.Max(num24, num28);
		}
		float num29 = Mathf.Abs(airWalkGuideTargetFeetY - airWalkGuideReturnPoint.y);
		float num30 = Mathf.Abs(airWalkGuideTargetFeetY - position.y);
		float magnitude4 = ((Vector3)(ref val4)).magnitude;
		float num31 = Mathf.Max(num24, 0.35f);
		float num32 = Mathf.Max(footSupportRadius * 0.55f, 0.1f);
		float num33 = Mathf.Max(Mathf.Max(magnitude4 - num32, 0.12f) / num31, Time.fixedDeltaTime * 2f);
		float num34 = num30 / num33;
		float num35 = num29 / Mathf.Max(num20, 0.35f) * num23;
		float num36 = Mathf.Max(Mathf.Max(airWalkAssistSpeed * 0.6f, 0.25f), Mathf.Max(num34, num35 * 1.1f));
		float num37 = Mathf.Max(airWalkAssistSpeed * 2.5f, num * 4f);
		num36 = Mathf.Min(num36, num37);
		float num38 = Mathf.Max(footSupportDistance * 1.2f, 0.12f);
		float num39 = Mathf.Max(num32 * 2f, 0.3f);
		float num40 = 1f - Mathf.Clamp01(num30 / num38);
		float num41 = 1f - Mathf.Clamp01(magnitude4 / num39);
		float num42 = num40 * num41;
		float num43 = Mathf.Max(0.3f, airWalkAssistSpeed * 0.25f);
		num36 = Mathf.Lerp(num36, Mathf.Min(num36, num43), num42);
		float num44 = Vector3.Dot(position - airWalkGuideReturnPoint, val9) / num20;
		bool num45 = num21 < -0.002f || (flag && num22 < -0.05f);
		float num46 = Mathf.Max(footSupportRadius * 1.5f, 0.18f);
		Vector3 val13 = position - airWalkGuideReturnPoint;
		val13.y = 0f;
		if (num45 && ((Vector3)(ref val13)).magnitude <= num46)
		{
			airWalkGuideBlockedProgress = 0f;
		}
		float num47 = Mathf.Clamp01(num44 + airWalkGuideBlockedProgress);
		float num48 = num36 * Time.fixedDeltaTime / Mathf.Max(num29, 0.1f);
		airWalkGuideProgress = Mathf.MoveTowards(airWalkGuideProgress, num47, num48);
		airWalkGuideLastPosition = position;
		float num49 = Mathf.Lerp(airWalkGuideReturnPoint.y, airWalkGuideTargetFeetY, airWalkGuideProgress);
		float num50 = Mathf.Clamp(airWalkTargetSmoothTime, 0.1f, 0.4f);
		airWalkSmoothedTargetY = Mathf.SmoothDamp(airWalkSmoothedTargetY, num49, ref airWalkTargetVelocity, num50, num36, Time.fixedDeltaTime);
		ApplyAirWalkHeightCorrection(position.y, airWalkSmoothedTargetY, feetVerticalVelocity, num, num36);
	}

	private void ResetAirWalkHold()
	{
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: 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_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		airWalkLastOpenSurfaceScanTime = -1f;
		hasAirWalkHoldHeight = false;
		airWalkHoldFeetY = 0f;
		airWalkSmoothedTargetY = 0f;
		airWalkTargetVelocity = 0f;
		airWalkGuideReturnPoint = Vector3.zero;
		airWalkGuideTargetPoint = Vector3.zero;
		airWalkGuideCollider = null;
		airWalkGuideReturnActive = false;
		airWalkGuideTargetFeetY = 0f;
		airWalkGuideInitialDistance = 0f;
		airWalkGuideProgress = 0f;
		airWalkGuideBlockedProgress = 0f;
		airWalkGuideLastPosition = Vector3.zero;
		airWalkGuideProgressInitialized = false;
		airWalkWasAscending = false;
		airWalkGroundContactFrames = 0;
		airWalkGroundRearmLatched = false;
		airWalkFreeDescentSpeed = 0f;
		airWalkNoTargetSince = -1f;
		airWalkBlockedTargetCollider = null;
		airWalkBlockedTargetPoint = Vector3.zero;
		airWalkBlockedAtPosition = Vector3.zero;
		airWalkBlockedTargetFeetY = 0f;
		airWalkBlockedTargetRadius = 0.9f;
		airWalkBlockedTargetUntil = -1f;
		airWalkDepartureSurfacePoint = Vector3.zero;
		airWalkDepartureSurfaceNormal = Vector3.up;
		airWalkDepartureSurfaceCollider = null;
		airWalkHasDepartureSurface = false;
		airWalkAssistActive = false;
		airWalkWaitingForTakeoff = false;
		airWalkStateInitialized = false;
		airWalkTakeoffClearFrames = 0;
	}

	private void ExecuteWallTransfer()
	{
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_0223: Unknown result type (might be due to invalid IL or missing references)
		//IL_0244: Unknown result type (might be due to invalid IL or missing references)
		//IL_024a: Unknown result type (might be due to invalid IL or missing references)
		//IL_024f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0254: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0199: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cf: 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_033f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0392: Unknown result type (might be due to invalid IL or missing references)
		//IL_0398: Unknown result type (might be due to invalid IL or missing references)
		//IL_039d: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03db: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0400: Unknown result type (might be due to invalid IL or missing references)
		//IL_0410: Unknown result type (might be due to invalid IL or missing references)
		//IL_0416: Unknown result type (might be due to invalid IL or missing references)
		//IL_041b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0420: Unknown result type (might be due to invalid IL or missing references)
		//IL_0586: Unknown result type (might be due to invalid IL or missing references)
		//IL_058b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0363: Unknown result type (might be due to invalid IL or missing references)
		//IL_0599: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_05b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_05cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_05d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_05d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_05d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_076b: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_05eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_05f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_05fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0602: Unknown result type (might be due to invalid IL or missing references)
		//IL_0775: Unknown result type (might be due to invalid IL or missing references)
		//IL_0777: Unknown result type (might be due to invalid IL or missing references)
		//IL_06bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_078f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0792: Unknown result type (might be due to invalid IL or missing references)
		//IL_0797: Unknown result type (might be due to invalid IL or missing references)
		//IL_07c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_07d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_07f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_06fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0703: Unknown result type (might be due to invalid IL or missing references)
		//IL_0710: Unknown result type (might be due to invalid IL or missing references)
		//IL_071a: Unknown result type (might be due to invalid IL or missing references)
		//IL_071c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0725: Unknown result type (might be due to invalid IL or missing references)
		//IL_0727: Unknown result type (might be due to invalid IL or missing references)
		//IL_072d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0732: Unknown result type (might be due to invalid IL or missing references)
		//IL_066f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0671: Unknown result type (might be due to invalid IL or missing references)
		//IL_073e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0740: 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_0680: Unknown result type (might be due to invalid IL or missing references)
		//IL_0699: Unknown result type (might be due to invalid IL or missing references)
		//IL_069b: Unknown result type (might be due to invalid IL or missing references)
		//IL_069d: Unknown result type (might be due to invalid IL or missing references)
		//IL_069f: Unknown result type (might be due to invalid IL or missing references)
		if (!wallTransferEnabled || (Object)(object)Player.PhysicsRig == (Object)null || Time.time < wallTransferCooldownUntil)
		{
			return;
		}
		bool flag = noclipEnabled;
		if (!flag)
		{
			CaptureControllerRigEnabledState(5f);
		}
		wallTransferActive = true;
		if (!flag)
		{
			TemporarilyDisablePlayerColliders();
		}
		try
		{
			Transform feetTransform = GetFeetTransform();
			if ((Object)(object)feetTransform == (Object)null)
			{
				return;
			}
			Vector3 val = ((((Vector2)(ref thumbstickInput)).sqrMagnitude > 0.0001f) ? GetPlanarMovementDirection() : GetPlanarLookDirection());
			val.y = 0f;
			if (((Vector3)(ref val)).sqrMagnitude < 0.0001f)
			{
				val = Vector3.forward;
			}
			else
			{
				((Vector3)(ref val)).Normalize();
			}
			RaycastHit val2 = default(RaycastHit);
			bool flag2 = false;
			float num = float.MaxValue;
			float[] array = new float[3]
			{
				Mathf.Max(headToFeetDistance * 0.22f, 0.22f),
				Mathf.Max(headToFeetDistance * 0.43f, 0.35f),
				Mathf.Max(headToFeetDistance * 0.66f, 0.5f)
			};
			float[] array2 = new float[5] { 0f, -8f, 8f, -16f, 16f };
			RaycastHit val5 = default(RaycastHit);
			for (int i = 0; i < array.Length; i++)
			{
				Vector3 val3 = feetTransform.position + Vector3.up * array[i];
				for (int j = 0; j < array2.Length; j++)
				{
					Vector3 val4 = Quaternion.AngleAxis(array2[j], Vector3.up) * val;
					if (Physics.SphereCast(val3, wallProbeRadius, val4, ref val5, Mathf.Max(wallDetectionDistance, 0.5f), -1, (QueryTriggerInteraction)1) && !((Object)(object)((RaycastHit)(ref val5)).collider == (Object)null) && !(((RaycastHit)(ref val5)).normal.y > 0.65f) && IsUsableWallHit(((RaycastHit)(ref val5)).collider) && ((RaycastHit)(ref val5)).distance < num)
					{
						num = ((RaycastHit)(ref val5)).distance;
						val2 = val5;
						flag2 = true;
					}
				}
			}
			if (!flag2)
			{
				MelonLogger.Msg("Wall Transfer: no usable wall detected within " + wallDetectionDistance.ToString("0.0") + "m.");
				return;
			}
			float num2 = feetTransform.position.y;
			float feetVerticalVelocity = GetFeetVerticalVelocity();
			float num3 = Time.time - lastStableGroundTime;
			Vector3 val6 = feetTransform.position - lastStableGroundPosition;
			val6.y = 0f;
			bool flag3 = hasStableGroundFeetY && num3 <= 5f && ((Vector3)(ref val6)).magnitude <= Mathf.Max(headToFeetDistance * 2f, 3.5f);
			float num4 = Mathf.Max(headToFeetDistance * 0.16f, 0.22f);
			bool num5 = Mathf.Abs(feetVerticalVelocity) > 0.45f || (flag3 && Mathf.Abs(feetTransform.position.y - lastStableGroundFeetY) > num4);
			bool flag4 = false;
			Vector3 groundPoint;
			Vector3 groundNormal;
			if (num5 && flag3)
			{
				num2 = lastStableGroundFeetY;
				flag4 = true;
			}
			else if (FindWallTransferGround(feetTransform.position, out groundPoint, out groundNormal))
			{
				float num6 = groundPoint.y + footSupportDistance + groundClearance;
				float num7 = Mathf.Max(headToFeetDistance * 3.5f, 3f);
				if (num6 <= feetTransform.position.y + Mathf.Max(headToFeetDistance * 0.04f, 0.08f) && feetTransform.position.y - num6 <= num7)
				{
					num2 = num6;
					flag4 = true;
				}
			}
			if (!flag4 && flag3)
			{
				num2 = lastStableGroundFeetY;
				flag4 = true;
			}
			float num8 = Mathf.Max(Vector3.Dot(((RaycastHit)(ref val2)).point - feetTransform.position, val), 0.05f) + wallProbeRadius + wallClearance + playerCapsuleRadius * 0.35f;
			Bounds bounds = ((RaycastHit)(ref val2)).collider.bounds;
			float num9 = Mathf.Abs(val.x) * ((Bounds)(ref bounds)).extents.x + Mathf.Abs(val.z) * ((Bounds)(ref bounds)).extents.z;
			float num10 = Vector3.Dot(((Bounds)(ref bounds)).center - feetTransform.position, val) + num9;
			float num11 = Mathf.Max(num8, num10 + playerCapsuleRadius + wallClearance + 0.1f);
			float num12 = Mathf.Clamp(Mathf.Max(new float[3]
			{
				wallScanDistance,
				45f,
				headToFeetDistance * 25f
			}), 35f, 80f);
			float num13 = Mathf.Clamp(wallScanStep, 0.08f, 0.2f);
			float num14 = num11 + num12;
			float num15 = Mathf.Max(headToFeetDistance * 0.22f, 0.2f);
			float[] array3 = new float[18]
			{
				0f,
				num15,
				num15 * 2f,
				num15 * 3f,
				num15 * 4f,
				num15 * 6f,
				num15 * 8f,
				num15 * 12f,
				num15 * 16f,
				num15 * 24f,
				0f - num15,
				(0f - num15) * 2f,
				(0f - num15) * 4f,
				(0f - num15) * 6f,
				(0f - num15) * 9f,
				(0f - num15) * 12f,
				(0f - num15) * 18f,
				(0f - num15) * 24f
			};
			bool flag5 = false;
			Vector3 val7 = Vector3.zero;
			Vector3 val8 = default(Vector3);
			Vector3 val12 = default(Vector3);
			for (float num16 = num11; num16 <= num14; num16 += num13)
			{
				((Vector3)(ref val8))..ctor(feetTransform.position.x + val.x * num16, num2, feetTransform.position.z + val.z * num16);
				bool flag6 = false;
				Vector3 val9 = Vector3.zero;
				Vector3 val10 = Vector3.up;
				float num17 = float.MaxValue;
				for (int k = 0; k < array3.Length; k++)
				{
					Vector3 val11 = val8 + Vector3.up * array3[k];
					if (FindWallTransferGround(val11, out var groundPoint2, out var groundNormal2, out var groundCollider) && !((Object)(object)groundCollider == (Object)null) && !((Object)(object)groundCollider == (Object)(object)((RaycastHit)(ref val2)).collider) && !((Component)groundCollider).transform.IsChildOf(((Component)((RaycastHit)(ref val2)).collider).transform) && !((Component)((RaycastHit)(ref val2)).collider).transform.IsChildOf(((Component)groundCollider).transform) && !IsWallTopLanding(((RaycastHit)(ref val2)).collider, groundCollider, groundPoint2, val))
					{
						float num18 = Mathf.Abs(val11.y - groundPoint2.y);
						if (num18 < num17)
						{
							num17 = num18;
							val9 = groundPoint2;
							val10 = groundNormal2;
							flag6 = true;
						}
					}
				}
				if (flag6 && !(val10.y < 0.45f))
				{
					float num19 = val9.y + footSupportDistance + groundClearance + Mathf.Max(headToFeetDistance * 0.015f, 0.02f);
					((Vector3)(ref val12))..ctor(val8.x, num19, val8.z);
					if (CanPlayerFitAtPosition(val12) && IsWallTransferDestinationEmpty(val12, val) && CanPlayerFitAtPosition(val12 + val * 0.12f))
					{
						val7 = val12;
						flag5 = true;
						break;
					}
				}
			}
			if (!flag5)
			{
				MelonLogger.Msg("Wall Transfer: no full-capsule-clear landing beyond the obstacle.");
				return;
			}
			if (!CanPlayerFitAtPosition(val7) || !IsWallTransferDestinationEmpty(val7, val))
			{
				MelonLogger.Msg("Wall Transfer: final landing validation failed.");
				return;
			}
			ApplyRigDelta(val7 - feetTransform.position);
			StopRigMomentumForTransfer();
			hasSmoothedGround = false;
			customGrounded = false;
			hasAirWalkHoldHeight = true;
			jumpActive = false;
			airWalkHoldFeetY = val7.y;
			airWalkSmoothedTargetY = val7.y;
			airWalkTargetVelocity = 0f;
			airWalkWasAscending = false;
			RecordStableGround(val7.y);
			wallTransferCooldownUntil = Time.time + 0.35f;
			MelonLogger.Msg("Wall Transfer complete.");
		}
		catch (Exception ex)
		{
			MelonLogger.Error("Wall Transfer error: " + ex.Message);
		}
		finally
		{
			if (!flag && temporaryTransferColliders != null)
			{
				temporaryTransferRestorePending = true;
				temporaryTransferRestoreTime = Time.time + Mathf.Max(Time.fixedDeltaTime * 1.5f, 0.025f);
			}
			wallTransferActive = false;
			wallTransferRequested = false;
		}
	}

	private bool IsUsableWallHit(Collider collider)
	{
		if ((Object)(object)collider == (Object)null)
		{
			return false;
		}
		try
		{
			if ((Object)(object)Player.PhysicsRig != (Object)null && ((Component)collider).transform.IsChildOf(((Component)Player.PhysicsRig).transform))
			{
				return false;
			}
			if ((Object)(object)((Component)collider).GetComponentInParent<PhysicsRig>() != (Object)null)
			{
				return false;
			}
		}
		catch
		{
		}
		return true;
	}

	private void TemporarilyDisablePlayerColliders()
	{
		if ((Object)(object)Player.PhysicsRig == (Object)null)
		{
			return;
		}
		try
		{
			if (temporaryTransferColliders != null)
			{
				RestoreTemporaryTransferColliders();
			}
			List<Collider> list = new List<Collider>();
			Collider[] array = Il2CppArrayBase<Collider>.op_Implicit(((Component)Player.PhysicsRig).GetComponentsInChildren<Collider>(true));
			foreach (Collider val in array)
			{
				if ((Object)(object)val != (Object)null && val.enabled && !val.isTrigger)
				{
					val.enabled = false;
					list.Add(val);
				}
			}
			AddTemporaryHandColliders(Player.LeftHand, list);
			AddTemporaryHandColliders(Player.RightHand, list);
			temporaryTransferColliders = list.ToArray();
		}
		catch (Exception ex)
		{
			MelonLogger.Warning("Temporary collider disable error: " + ex.Message);
		}
	}

	private void RestoreTemporaryTransferColliders()
	{
		if (temporaryTransferColliders == null)
		{
			temporaryTransferRestorePending = false;
			return;
		}
		try
		{
			Collider[] array = temporaryTransferColliders;
			foreach (Collider val in array)
			{
				if ((Object)(object)val == (Object)null || val.enabled)
				{
					continue;
				}
				if (noclipEnabled)
				{
					if (!noclipDisabledColliders.Contains(val))
					{
						noclipDisabledColliders.Add(val);
					}
				}
				else
				{
					val.enabled = true;
				}
			}
		}
		catch (Exception ex)
		{
			MelonLogger.Warning("Temporary collider restore error: " + ex.Message);
		}
		temporaryTransferColliders = null;
		temporaryTransferRestorePending = false;
	}

	private void PerformFixedJump()
	{
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)Player.PhysicsRig == (Object)null || !IsGroundedForNoClipJump())
		{
			return;
		}
		try
		{
			float y = Mathf.Max(jumpVelocity, 3.5f);
			int num = 0;
			Rigidbody[] array = Il2CppArrayBase<Rigidbody>.op_Implicit(((Component)Player.PhysicsRig).GetComponentsInChildren<Rigidbody>(true));
			foreach (Rigidbody val in array)
			{
				if (!((Object)(object)val == (Object)null) && !val.isKinematic)
				{
					Vector3 velocity = val.velocity;
					if (velocity.y < 0f)
					{
						velocity.y = 0f;
					}
					velocity.y = y;
					val.velocity = velocity;
					num++;
				}
			}
			if (num == 0)
			{
				MelonLogger.Warning("Jump cancelled: no dynamic rig rigidbodies found.");
				return;
			}
			customGrounded = false;
			hasSmoothedGround = false;
			jumpActive = true;
			jumpProtectionUntil = Time.time + 0.4f;
			MelonLogger.Msg("JUMP - fixed velocity=" + y.ToString("F2") + "m/s");
		}
		catch (Exception ex)
		{
			MelonLogger.Error("Jump error: " + ex.Message);
		}
	}

	private void ApplyPreset(int preset)
	{
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		switch (preset)
		{
		case 0:
			movementSpeed = 3.9f;
			movementAcceleration = 18f;
			movementDeceleration = 42f;
			directionChangeDeceleration = 48f;
			airControl = 0.9f;
			jumpVelocity = 5.5f;
			airWalkAssistSpeed = 3.6f;
			break;
		case 1:
			movementSpeed = 5.25f;
			movementAcceleration = 24f;
			movementDeceleration = 48f;
			directionChangeDeceleration = 55f;
			airControl = 0.95f;
			jumpVelocity = 5.5f;
			airWalkAssistSpeed = 4f;
			break;
		case 2:
			movementSpeed = 2.75f;
			movementAcceleration = 14f;
			movementDeceleration = 38f;
			directionChangeDeceleration = 44f;
			airControl = 0.75f;
			jumpVelocity = 5.5f;
			airWalkAssistSpeed = 3f;
			break;
		case 3:
			movementSpeed = 3.75f;
			movementAcceleration = 18f;
			movementDeceleration = 45f;
			directionChangeDeceleration = 50f;
			airControl = 0.88f;
			jumpVelocity = 5.5f;
			airWalkAssistSpeed = 3.4f;
			break;
		}
		currentMoveVelocity = Vector3.zero;
		SavePersistentSettings();
		MelonLogger.Msg("NoClip preset applied: " + preset);
	}

	private bool IsWallTransferDestinationEmpty(Vector3 feetPosition, Vector3 forwardDirection)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = forwardDirection;
		val.y = 0f;
		if (((Vector3)(ref val)).sqrMagnitude < 0.0001f)
		{
			val = Vector3.forward;
		}
		else
		{
			((Vector3)(ref val)).Normalize();
		}
		float num = Mathf.Max(playerCapsuleRadius, 0.06f);
		float num2 = Mathf.Max(new float[3]
		{
			wallOpenSpaceDepth,
			num * 5f,
			1.25f
		});
		float num3 = Mathf.Clamp(wallScanStep, 0.05f, 0.12f);
		int num4 = Mathf.Max(Mathf.CeilToInt(num2 / num3), 4);
		for (int i = 0; i <= num4; i++)
		{
			float num5 = (float)i / (float)num4;
			Vector3 feetPosition2 = feetPosition + val * (num2 * num5);
			if (!CanPlayerFitAtPosition(feetPosition2))
			{
				return false;
			}
		}
		return true;
	}

	private void StopDownwardVelocity()
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		Rigidbody feetRigidbody = GetFeetRigidbody();
		if (!((Object)(object)feetRigidbody == (Object)null))
		{
			Vector3 velocity = feetRigidbody.velocity;
			if (velocity.y < 0f)
			{
				velocity.y = 0f;
				feetRigidbody.velocity = velocity;
			}
		}
	}

	private float GetFeetVerticalVelocity()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		Rigidbody feetRigidbody = GetFeetRigidbody();
		if (!((Object)(object)feetRigidbody == (Object)null))
		{
			return feetRigidbody.velocity.y;
		}
		return 0f;
	}

	private void HandleNoClipToggleInput()
	{
		if (Time.time - lastYPressTime <= 0.35f)
		{
			if (!noclipEnabled || !groundDetectorEnabled)
			{
				SetNoClipState(enabled: true);
				SetGroundDetectorState(enabled: true);
				MelonLogger.Msg("INPUT: NoClip + Ground Detector enabled.");
			}
			else
			{
				SetGroundDetectorState(enabled: false);
				SetNoClipState(enabled: false);
				MelonLogger.Msg("INPUT: NoClip + Ground Detector disabled.");
			}
			lastYPressTime = -10f;
			return;
		}
		if (noclipEnabled && groundDetectorEnabled)
		{
			SetGroundDetectorState(enabled: false);
			SetNoClipState(enabled: false);
		}
		else if (noclipEnabled)
		{
			SetNoClipState(enabled: false);
		}
		else if (groundDetectorEnabled)
		{
			SetGroundDetectorState(enabled: false);
		}
		else
		{
			SetNoClipState(enabled: true);
		}
		lastYPressTime = Time.time;
	}

	private bool CanPlayerFitAtPosition(Vector3 feetPosition)
	{
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: 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_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: 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)
		if ((Object)(object)Player.PhysicsRig == (Object)null)
		{
			return false;
		}
		float num = Mathf.Max(playerCapsuleRadius, 0.06f);
		float num2 = Mathf.Max(headToFeetDistance, num * 2.2f);
		float num3 = Mathf.Max(headToFeetDistance * 0.025f, 0.025f);
		Vector3 val = feetPosition + Vector3.up * (num + num3);
		Vector3 val2 = feetPosition + Vector3.up * Mathf.Max(num + 0.02f, num2 - num);
		int num4 = Physics.OverlapCapsuleNonAlloc(val, val2, num, Il2CppReferenceArray<Collider>.op_Implicit(transferOverlapBuffer), -1, (QueryTriggerInteraction)1);
		if (num4 >= transferOverlapBuffer.Length)
		{
			return false;
		}
		for (int i = 0; i < num4; i++)
		{
			Collider val3 = transferOverlapBuffer[i];
			if (!((Object)(object)val3 == (Object)null) && !((Component)val3).transform.IsChildOf(((Component)Player.PhysicsRig).transform))
			{
				bool flag = false;
				try
				{
					flag = (Object)(object)((Component)val3).GetComponentInParent<PhysicsRig>() != (Object)null;
				}
				catch
				{
				}
				if (!flag)
				{
					return false;
				}
			}
		}
		return true;
	}

	private void TransferNoClipMomentum()
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		currentMoveVelocity = Vector3.zero;
		NeutralizeNoclipPlanarPhysics();
	}

	private Rigidbody GetFeetRigidbody()
	{
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to inval