Decompiled source of BackFlip v1.0.0

Mods/BackFlip.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BackFlip;
using BoneLib;
using BoneLib.BoneMenu;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Marrow;
using Il2CppSLZ.Marrow.AI;
using Il2CppSLZ.Marrow.Combat;
using Il2CppSLZ.Marrow.Data;
using Il2CppSLZ.Marrow.PuppetMasta;
using Il2CppSLZ.VRMK;
using LabFusion.Entities;
using LabFusion.Network;
using LabFusion.Network.Serialization;
using LabFusion.SDK.Modules;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Events;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(FlipMod), "BackFlip", "1.0.0", "YourName", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("BackFlip")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BackFlip")]
[assembly: AssemblyTitle("BackFlip")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BackFlip
{
	internal class BodyFlipper
	{
		private class HandDrive
		{
			public Rigidbody Rb;

			public Transform Controller;

			public Vector3 OffsetPos;

			public Quaternion OffsetRot;
		}

		private const float CatchUpRate = 6f;

		private const float MaxSpin = 15f;

		private const float HandGain = 25f;

		private const float HandTurnGain = 20f;

		private const float HeadGain = 15f;

		private const float MaxReach = 12f;

		private const float MaxExitSpeed = 6f;

		private const float MaxExitRise = 0.5f;

		private readonly List<Rigidbody> _all = new List<Rigidbody>();

		private readonly List<Rigidbody> _core = new List<Rigidbody>();

		private readonly HashSet<int> _free = new HashSet<int>();

		private readonly List<HandDrive> _hands = new List<HandDrive>();

		private Rigidbody _pelvis;

		private Rigidbody _chest;

		private Rigidbody _head;

		private Transform _space;

		private Transform _headset;

		private Quaternion _pelvisStart;

		private Vector3 _axis;

		private Vector3 _comVel;

		private Vector3 _omega;

		private Vector3 _com;

		private bool _haveComVel;

		private FlipPivot _pivotMode;

		private Vector3 _pivot;

		private Vector3 _pivotVel;

		private Vector3 _feetInPelvis;

		private Vector3 _spaceInChestPos;

		private Vector3 _headInChest;

		private Quaternion _spaceInChestRot;

		private const float MaxEyeOffset = 0.2f;

		private const float MaxHandOffset = 0.3f;

		private Vector3 _correction;

		private const float StabilizeTime = 0.6f;

		private const float StabilizeMaxRise = 0.8f;

		private const float StabilizeMaxFlat = 5f;

		private float _stabilizeLeft;

		public bool Active { get; private set; }

		public float Drift { get; private set; }

		public int Clamps { get; private set; }

		public Quaternion CurrentRotation
		{
			get
			{
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				if (!((Object)(object)_pelvis != (Object)null))
				{
					return Quaternion.identity;
				}
				return _pelvis.rotation * Quaternion.Inverse(_pelvisStart);
			}
		}

		public Vector3 PelvisPosition
		{
			get
			{
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				if (!((Object)(object)_pelvis != (Object)null))
				{
					return Vector3.zero;
				}
				return _pelvis.position;
			}
		}

		public float VerticalSpeed
		{
			get
			{
				if (!_haveComVel)
				{
					return 0f;
				}
				return _pivotVel.y;
			}
		}

		public string Begin(Vector3 axisWorld, FlipPivot pivot)
		{
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: 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_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: 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_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			PhysicsRig physicsRig = Player.PhysicsRig;
			if ((Object)(object)physicsRig == (Object)null || (Object)(object)physicsRig.torso == (Object)null)
			{
				return "no physics rig";
			}
			_headset = (((Object)(object)Player.ControllerRig != (Object)null) ? Player.ControllerRig.headset : null);
			_space = (((Object)(object)_headset != (Object)null) ? _headset.parent : null);
			if ((Object)(object)_space == (Object)null)
			{
				return "no tracking space";
			}
			_pelvis = physicsRig.torso.rbPelvis;
			_chest = physicsRig.torso.rbChest;
			_head = physicsRig.torso.rbHead;
			if ((Object)(object)_pelvis == (Object)null || (Object)(object)_chest == (Object)null || (Object)(object)_head == (Object)null)
			{
				return "missing torso rigidbodies";
			}
			Vector3 val = Vector3.ClampMagnitude(_headset.position - _head.position, 0.2f);
			Vector3 val2 = _head.position + val;
			_correction = val2 - _headset.position;
			Drift = ((Vector3)(ref _correction)).magnitude;
			_pivotMode = pivot;
			_feetInPelvis = Quaternion.Inverse(_pelvis.rotation) * (physicsRig.feet.transform.position - _pelvis.position);
			CancelStabilize();
			physicsRig.RagdollRig();
			physicsRig.DisableBallLoco();
			physicsRig.PhysicalLegs();
			physicsRig.legLf.ShutdownLimb();
			physicsRig.legRt.ShutdownLimb();
			_free.Clear();
			AddFree(_head);
			AddFree(physicsRig.torso.rbNeck);
			_hands.Clear();
			AddHand(physicsRig.leftHand, Player.LeftController);
			AddHand(physicsRig.rightHand, Player.RightController);
			_all.Clear();
			_core.Clear();
			Il2CppArrayBase<Rigidbody> componentsInChildren = ((Component)physicsRig).GetComponentsInChildren<Rigidbody>();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Rigidbody val3 = componentsInChildren[i];
				if (!((Object)(object)val3 == (Object)null) && !val3.isKinematic)
				{
					_all.Add(val3);
					if (!_free.Contains(((Object)val3).GetInstanceID()))
					{
						_core.Add(val3);
					}
				}
			}
			Quaternion val4 = Quaternion.Inverse(_chest.rotation);
			_spaceInChestRot = val4 * _space.rotation;
			_spaceInChestPos = val4 * (_space.position + _correction - _chest.position);
			_headInChest = val4 * -val;
			_pelvisStart = _pelvis.rotation;
			_axis = ((Vector3)(ref axisWorld)).normalized;
			_haveComVel = false;
			Clamps = 0;
			Active = true;
			return null;
		}

		private void AddFree(Rigidbody rb)
		{
			if ((Object)(object)rb != (Object)null)
			{
				_free.Add(((Object)rb).GetInstanceID());
			}
		}

		private void AddHand(Hand hand, BaseController controller)
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: 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)
			//IL_00a5: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)hand == (Object)null) && !((Object)(object)controller == (Object)null) && !((Object)(object)hand.physHand == (Object)null))
			{
				PhysHand physHand = hand.physHand;
				AddFree(physHand.rbHand);
				AddFree(physHand.rbUpper);
				AddFree(physHand.rbLower);
				if (!((Object)(object)physHand.rbHand == (Object)null))
				{
					Transform transform = ((Component)controller).transform;
					Quaternion val = Quaternion.Inverse(transform.rotation);
					_hands.Add(new HandDrive
					{
						Rb = physHand.rbHand,
						Controller = transform,
						OffsetPos = Vector3.ClampMagnitude(val * (physHand.rbHand.position - (transform.position + _correction)), 0.3f),
						OffsetRot = val * physHand.rbHand.rotation
					});
				}
			}
		}

		public void PinnedSpace(out Vector3 pos, out Quaternion rot)
		{
			//IL_0007: 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_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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)
			//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_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)
			rot = _chest.rotation * _spaceInChestRot;
			pos = _chest.position + _chest.rotation * _spaceInChestPos;
		}

		private void ToPinned(Vector3 worldPos, Quaternion worldRot, out Vector3 pos, out Quaternion rot)
		{
			//IL_0010: 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_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_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: 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)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: 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)
			PinnedSpace(out var pos2, out var rot2);
			Vector3 val = Vector3.Scale(_space.lossyScale, _space.InverseTransformPoint(worldPos));
			pos = pos2 + rot2 * val;
			rot = rot2 * (Quaternion.Inverse(_space.rotation) * worldRot);
		}

		public void Tick(float angleDeg, float degPerSec, float dt)
		{
			//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_0032: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: 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_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: 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_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			if (!Active || (Object)(object)_pelvis == (Object)null || (Object)(object)_chest == (Object)null)
			{
				return;
			}
			Quaternion val = Quaternion.AngleAxis(angleDeg, _axis) * _pelvisStart * Quaternion.Inverse(_pelvis.rotation);
			float num = default(float);
			Vector3 axis = default(Vector3);
			((Quaternion)(ref val)).ToAngleAxis(ref num, ref axis);
			if (num > 180f)
			{
				num -= 360f;
			}
			if (float.IsNaN(axis.x) || ((Vector3)(ref axis)).sqrMagnitude < 1E-06f)
			{
				axis = _axis;
				num = 0f;
			}
			_omega = _axis * degPerSec * ((float)Math.PI / 180f) + ((Vector3)(ref axis)).normalized * num * ((float)Math.PI / 180f) * 6f;
			if (((Vector3)(ref _omega)).magnitude > 15f)
			{
				_omega = ((Vector3)(ref _omega)).normalized * 15f;
			}
			float num2 = 0f;
			Vector3 val2 = Vector3.zero;
			Vector3 val3 = Vector3.zero;
			for (int i = 0; i < _all.Count; i++)
			{
				Rigidbody val4 = _all[i];
				if (!((Object)(object)val4 == (Object)null))
				{
					num2 += val4.mass;
					val2 += val4.worldCenterOfMass * val4.mass;
					val3 += val4.velocity * val4.mass;
				}
			}
			if (num2 <= 0f)
			{
				return;
			}
			_com = val2 / num2;
			Vector3 val5 = val3 / num2;
			if (_haveComVel)
			{
				Vector3 val6 = _comVel + Physics.gravity * dt;
				Vector3 val7 = val5 - val6;
				if (((Vector3)(ref val7)).sqrMagnitude > 0.25f)
				{
					val5 = val6;
					Clamps++;
				}
			}
			switch (_pivotMode)
			{
			case FlipPivot.Head:
				_pivot = _head.position;
				break;
			case FlipPivot.Feet:
				_pivot = _pelvis.position + _pelvis.rotation * _feetInPelvis;
				break;
			default:
				_pivot = _com;
				break;
			}
			if (_pivotMode == FlipPivot.Hips)
			{
				_pivotVel = val5;
			}
			else
			{
				_pivotVel = (_haveComVel ? (_pivotVel + Physics.gravity * dt) : val5);
			}
			_comVel = val5;
			_haveComVel = true;
			for (int j = 0; j < _core.Count; j++)
			{
				Rigidbody val8 = _core[j];
				if (!((Object)(object)val8 == (Object)null))
				{
					val8.velocity = BodyVelocityAt(val8.worldCenterOfMass);
					val8.angularVelocity = _omega;
				}
			}
			for (int k = 0; k < _hands.Count; k++)
			{
				DriveHand(_hands[k]);
			}
			DriveHead();
		}

		private Vector3 BodyVelocityAt(Vector3 point)
		{
			//IL_0001: 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_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_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)
			return _pivotVel + Vector3.Cross(_omega, point - _pivot);
		}

		private void DriveHand(HandDrive h)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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_003e: 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)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: 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_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: 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_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: 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_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)h.Rb == (Object)null) && !((Object)(object)h.Controller == (Object)null))
			{
				ToPinned(h.Controller.position, h.Controller.rotation, out var pos, out var rot);
				Vector3 val = pos + rot * h.OffsetPos;
				Quaternion val2 = rot * h.OffsetRot;
				Vector3 val3 = Vector3.ClampMagnitude((val - h.Rb.position) * 25f, 12f);
				h.Rb.velocity = BodyVelocityAt(h.Rb.position) + val3;
				Quaternion val4 = val2 * Quaternion.Inverse(h.Rb.rotation);
				float num = default(float);
				Vector3 val5 = default(Vector3);
				((Quaternion)(ref val4)).ToAngleAxis(ref num, ref val5);
				if (num > 180f)
				{
					num -= 360f;
				}
				if (!float.IsNaN(val5.x) && ((Vector3)(ref val5)).sqrMagnitude > 1E-06f)
				{
					h.Rb.angularVelocity = _omega + Vector3.ClampMagnitude(((Vector3)(ref val5)).normalized * num * ((float)Math.PI / 180f) * 20f, 30f);
				}
			}
		}

		private void DriveHead()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_0096: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_head == (Object)null) && !((Object)(object)_headset == (Object)null))
			{
				ToPinned(_headset.position, _headset.rotation, out var pos, out var _);
				Vector3 val = Vector3.ClampMagnitude((pos + _chest.rotation * _headInChest - _head.position) * 15f, 12f);
				_head.velocity = BodyVelocityAt(_head.position) + val;
			}
		}

		public void End()
		{
			//IL_0020: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: 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_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: 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_0130: 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_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: 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_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			if (!Active)
			{
				return;
			}
			Active = false;
			Vector3 val = (_haveComVel ? _pivotVel : Vector3.zero);
			if (val.y > 0.5f)
			{
				val.y = 0.5f;
			}
			if (((Vector3)(ref val)).magnitude > 6f)
			{
				val = ((Vector3)(ref val)).normalized * 6f;
			}
			for (int i = 0; i < _all.Count; i++)
			{
				Rigidbody val2 = _all[i];
				if (!((Object)(object)val2 == (Object)null))
				{
					val2.velocity = val;
					val2.angularVelocity = Vector3.zero;
				}
			}
			_core.Clear();
			_hands.Clear();
			PhysicsRig physicsRig = Player.PhysicsRig;
			if ((Object)(object)physicsRig == (Object)null)
			{
				_all.Clear();
				return;
			}
			Transform pelvis = ((Rig)physicsRig).m_pelvis;
			physicsRig.TurnOnRig();
			physicsRig.UnRagdollRig();
			if ((Object)(object)pelvis != (Object)null)
			{
				Vector3 position = pelvis.position;
				Vector3 val3 = Vector3.ProjectOnPlane(pelvis.forward, Vector3.up);
				Quaternion val4 = Quaternion.LookRotation((((Vector3)(ref val3)).sqrMagnitude > 0.0001f) ? val3 : Vector3.forward, Vector3.up);
				Vector3 val5 = position + Vector3.down * 0.9f;
				if (GroundBelow(position, 0.95f, ((Component)Player.RigManager).transform, out var point))
				{
					val5 = point + Vector3.up * Mathf.Max(0.05f, physicsRig.footballRadius);
				}
				physicsRig.feet.transform.SetPositionAndRotation(val5, val4);
				physicsRig.knee.transform.SetPositionAndRotation(Vector3.Lerp(val5, position, 0.5f), val4);
			}
			_stabilizeLeft = 0.6f;
		}

		public void Stabilize(float dt)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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_00a1: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
			if (_stabilizeLeft <= 0f)
			{
				return;
			}
			_stabilizeLeft -= dt;
			Vector2 val2 = default(Vector2);
			for (int i = 0; i < _all.Count; i++)
			{
				Rigidbody val = _all[i];
				if (!((Object)(object)val == (Object)null) && !val.isKinematic)
				{
					Vector3 velocity = val.velocity;
					bool flag = false;
					if (velocity.y > 0.8f)
					{
						velocity.y = 0.8f;
						flag = true;
					}
					((Vector2)(ref val2))..ctor(velocity.x, velocity.z);
					if (((Vector2)(ref val2)).magnitude > 5f)
					{
						val2 = ((Vector2)(ref val2)).normalized * 5f;
						velocity.x = val2.x;
						velocity.z = val2.y;
						flag = true;
					}
					if (flag)
					{
						val.velocity = velocity;
					}
				}
			}
			if (_stabilizeLeft <= 0f)
			{
				_all.Clear();
			}
		}

		public void CancelStabilize()
		{
			_stabilizeLeft = 0f;
			if (!Active)
			{
				_all.Clear();
			}
		}

		private static bool GroundBelow(Vector3 from, float maxDist, Transform self, out Vector3 point)
		{
			//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_0016: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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)
			Il2CppStructArray<RaycastHit> val = Physics.RaycastAll(from, Vector3.down, maxDist, -1, (QueryTriggerInteraction)1);
			float num = float.MaxValue;
			point = Vector3.zero;
			for (int i = 0; i < ((Il2CppArrayBase<RaycastHit>)(object)val).Length; i++)
			{
				RaycastHit val2 = ((Il2CppArrayBase<RaycastHit>)(object)val)[i];
				if (!((Component)((RaycastHit)(ref val2)).collider).transform.IsChildOf(self))
				{
					val2 = ((Il2CppArrayBase<RaycastHit>)(object)val)[i];
					if (!(((RaycastHit)(ref val2)).distance >= num))
					{
						val2 = ((Il2CppArrayBase<RaycastHit>)(object)val)[i];
						num = ((RaycastHit)(ref val2)).distance;
						val2 = ((Il2CppArrayBase<RaycastHit>)(object)val)[i];
						point = ((RaycastHit)(ref val2)).point;
					}
				}
			}
			return num < float.MaxValue;
		}

		public bool NearGround(Transform self, float maxHeight)
		{
			//IL_0016: 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_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_pelvis == (Object)null)
			{
				return false;
			}
			Il2CppStructArray<RaycastHit> val = Physics.RaycastAll(_pelvis.position, Vector3.down, maxHeight, -1, (QueryTriggerInteraction)1);
			for (int i = 0; i < ((Il2CppArrayBase<RaycastHit>)(object)val).Length; i++)
			{
				RaycastHit val2 = ((Il2CppArrayBase<RaycastHit>)(object)val)[i];
				if (!((Component)((RaycastHit)(ref val2)).collider).transform.IsChildOf(self))
				{
					return true;
				}
			}
			return false;
		}
	}
	internal class FlipAudio
	{
		private const int Rate = 44100;

		private AudioClip _wind;

		private AudioClip _thud;

		private AudioSource _windSrc;

		private AudioSource _fxSrc;

		private float _windLevel;

		private void Ensure()
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			if ((Object)(object)_wind == (Object)null)
			{
				_wind = MakeWind();
			}
			if ((Object)(object)_thud == (Object)null)
			{
				_thud = MakeThud();
			}
			if (!((Object)(object)_windSrc != (Object)null) || !((Object)(object)_fxSrc != (Object)null))
			{
				Transform val = (((Object)(object)Player.ControllerRig != (Object)null) ? Player.ControllerRig.headset : null);
				if (!((Object)(object)val == (Object)null))
				{
					GameObject val2 = new GameObject("BackFlipAudio");
					val2.transform.SetParent(val, false);
					_windSrc = val2.AddComponent<AudioSource>();
					_windSrc.clip = _wind;
					_windSrc.loop = true;
					_windSrc.spatialBlend = 0f;
					_windSrc.volume = 0f;
					_windSrc.playOnAwake = false;
					_fxSrc = val2.AddComponent<AudioSource>();
					_fxSrc.spatialBlend = 0f;
					_fxSrc.playOnAwake = false;
				}
			}
		}

		public void Reset()
		{
			_windSrc = null;
			_fxSrc = null;
			_windLevel = 0f;
		}

		public void UpdateWind(float spin01, float dt, float master)
		{
			Ensure();
			if ((Object)(object)_windSrc == (Object)null)
			{
				return;
			}
			float num = Mathf.Clamp01(spin01) * master;
			_windLevel = Mathf.MoveTowards(_windLevel, num, dt * ((num > _windLevel) ? 6f : 2.5f));
			_windSrc.volume = _windLevel * 0.55f;
			_windSrc.pitch = 0.75f + 0.6f * Mathf.Clamp01(spin01);
			if (_windLevel > 0.001f)
			{
				if (!_windSrc.isPlaying)
				{
					_windSrc.Play();
				}
			}
			else if (_windSrc.isPlaying)
			{
				_windSrc.Stop();
			}
		}

		public void Thud(float strength01, float master)
		{
			Ensure();
			if (!((Object)(object)_fxSrc == (Object)null) && !(master <= 0f))
			{
				_fxSrc.pitch = 0.9f + Random.value * 0.2f;
				_fxSrc.PlayOneShot(_thud, Mathf.Lerp(0.25f, 0.9f, Mathf.Clamp01(strength01)) * master);
			}
		}

		private static AudioClip MakeWind()
		{
			int num = 88200;
			int num2 = 4410;
			float[] array = new float[num + num2];
			Random random = new Random(1234);
			float num3 = 0f;
			float num4 = 0f;
			for (int i = 0; i < array.Length; i++)
			{
				num3 = Mathf.Clamp(num3 + ((float)random.NextDouble() * 2f - 1f) * 0.06f, -1f, 1f) * 0.998f;
				num4 = (array[i] = num4 + (num3 - num4) * 0.2f);
			}
			float num5 = 0.0001f;
			for (int j = 0; j < array.Length; j++)
			{
				num5 = Mathf.Max(num5, Mathf.Abs(array[j]));
			}
			float[] array2 = new float[num];
			for (int k = 0; k < num; k++)
			{
				float num6 = array[k];
				if (k < num2)
				{
					num6 = Mathf.Lerp(array[num + k], num6, (float)k / (float)num2);
				}
				array2[k] = num6 / num5 * 0.8f;
			}
			return ToClip("BackFlipWind", array2);
		}

		private static AudioClip MakeThud()
		{
			int num = 11025;
			float[] array = new float[num];
			Random random = new Random(99);
			float num2 = 0f;
			float num3 = 0f;
			for (int i = 0; i < num; i++)
			{
				float num4 = (float)i / 44100f;
				float num5 = Mathf.Min(1f, num4 / 0.004f) * Mathf.Exp((0f - num4) * 22f);
				float num6 = (float)random.NextDouble() * 2f - 1f;
				num2 += (num6 - num2) * 0.08f;
				num3 += (num2 - num3) * 0.08f;
				float num7 = Mathf.Sin((float)Math.PI * 140f * num4) * 0.5f;
				array[i] = (num3 * 6f + num7) * num5;
			}
			float num8 = 0.0001f;
			for (int j = 0; j < num; j++)
			{
				num8 = Mathf.Max(num8, Mathf.Abs(array[j]));
			}
			for (int k = 0; k < num; k++)
			{
				array[k] = array[k] / num8 * 0.9f;
			}
			return ToClip("BackFlipThud", array);
		}

		private static AudioClip ToClip(string name, float[] samples)
		{
			AudioClip obj = AudioClip.Create(name, samples.Length, 1, 44100, false);
			obj.SetData(new Il2CppStructArray<float>(samples), 0);
			((Object)obj).hideFlags = (HideFlags)32;
			return obj;
		}
	}
	internal class FlipKick
	{
		private const float FootRadius = 0.2f;

		private const float LegLength = 0.95f;

		private readonly Action<string> _log;

		private readonly HashSet<int> _hitThisFlip = new HashSet<int>();

		private Vector3 _prevL;

		private Vector3 _prevR;

		private bool _havePrev;

		public FlipKick(Action<string> log)
		{
			_log = log;
		}

		public void Begin()
		{
			_hitThisFlip.Clear();
			_havePrev = false;
		}

		public void Tick(float dt, Quaternion rot, Vector3 pivot, float minFootSpeed, float force, float damage)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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_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_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_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: 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_0022: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: 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_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			GetFeet(out var l, out var r);
			l = pivot + rot * (l - pivot);
			r = pivot + rot * (r - pivot);
			if (_havePrev && dt > 0f)
			{
				CheckFoot(l, (l - _prevL) / dt, minFootSpeed, force, damage);
				CheckFoot(r, (r - _prevR) / dt, minFootSpeed, force, damage);
			}
			_prevL = l;
			_prevR = r;
			_havePrev = true;
		}

		private void GetFeet(out Vector3 l, out Vector3 r)
		{
			//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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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_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)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)Player.ControllerRig).transform;
			Vector3 position = ((Rig)Player.PhysicsRig).m_pelvis.position;
			Vector3 val = Vector3.down * 0.95f;
			l = position + val - transform.right * 0.12f;
			r = position + val + transform.right * 0.12f;
		}

		private void CheckFoot(Vector3 pos, Vector3 vel, float minFootSpeed, float force, float damage)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			float magnitude = ((Vector3)(ref vel)).magnitude;
			if (magnitude < minFootSpeed)
			{
				return;
			}
			Transform transform = ((Component)Player.RigManager).transform;
			Il2CppReferenceArray<Collider> val = Physics.OverlapSphere(pos, 0.2f, -1, (QueryTriggerInteraction)1);
			for (int i = 0; i < ((Il2CppArrayBase<Collider>)(object)val).Length; i++)
			{
				Collider val2 = ((Il2CppArrayBase<Collider>)(object)val)[i];
				if ((Object)(object)val2 == (Object)null || ((Component)val2).transform.IsChildOf(transform))
				{
					continue;
				}
				Rigidbody attachedRigidbody = val2.attachedRigidbody;
				if ((Object)(object)attachedRigidbody == (Object)null || attachedRigidbody.isKinematic)
				{
					continue;
				}
				AIBrain componentInParent = ((Component)attachedRigidbody).GetComponentInParent<AIBrain>();
				int item = (((Object)(object)componentInParent != (Object)null) ? ((Object)componentInParent).GetInstanceID() : ((Object)attachedRigidbody).GetInstanceID());
				if (_hitThisFlip.Add(item))
				{
					Vector3 val3 = vel / magnitude;
					attachedRigidbody.AddForce(val3 * force * magnitude, (ForceMode)1);
					if ((Object)(object)componentInParent != (Object)null && !componentInParent.isDead)
					{
						Damage(componentInParent, val2, pos, val3, damage);
						continue;
					}
					_log("Kick hit " + ((Object)attachedRigidbody).name + " at " + magnitude.ToString("F1") + " m/s");
				}
			}
		}

		private void Damage(AIBrain brain, Collider c, Vector3 pos, Vector3 dir, float damage)
		{
			//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_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: 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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			Attack val = new Attack
			{
				damage = damage,
				origin = pos,
				direction = dir,
				normal = -dir,
				collider = c,
				attackType = (AttackType)2
			};
			SubBehaviourHealth val2 = (((Object)(object)brain.behaviour != (Object)null) ? brain.behaviour.health : null);
			float num = ((val2 != null) ? val2.cur_hp : (-1f));
			ImpactProperties componentInParent = ((Component)c).GetComponentInParent<ImpactProperties>();
			if ((Object)(object)componentInParent != (Object)null)
			{
				componentInParent.ReceiveAttack(val);
			}
			if (val2 != null && Mathf.Approximately(val2.cur_hp, num))
			{
				val2.TakeDamage(1, val);
			}
			_log("KICK " + ((Object)brain).name + ": hp " + num.ToString("F2") + " -> " + ((val2 != null) ? val2.cur_hp.ToString("F2") : "?"));
		}
	}
	public class FlipMod : MelonMod
	{
		private MelonPreferences_Category _cat;

		private MelonPreferences_Entry<bool> _enabled;

		private MelonPreferences_Entry<bool> _invert;

		private MelonPreferences_Entry<bool> _debug;

		private MelonPreferences_Entry<bool> _kicks;

		private MelonPreferences_Entry<bool> _flipFromClimb;

		private MelonPreferences_Entry<bool> _bodyFollow;

		private MelonPreferences_Entry<bool> _sounds;

		private MelonPreferences_Entry<bool> _haptics;

		private MelonPreferences_Entry<float> _minHandSpeed;

		private MelonPreferences_Entry<float> _handMult;

		private MelonPreferences_Entry<float> _jumpPower;

		private MelonPreferences_Entry<float> _spinSpeed;

		private MelonPreferences_Entry<float> _drift;

		private MelonPreferences_Entry<float> _kickFootSpeed;

		private MelonPreferences_Entry<float> _kickForce;

		private MelonPreferences_Entry<float> _kickDamage;

		private MelonPreferences_Entry<float> _recoverTime;

		private MelonPreferences_Entry<float> _volume;

		private MelonPreferences_Entry<FlipPivot> _pivot;

		private MelonPreferences_Entry<int> _configVersion;

		private bool _flipping;

		private float _flipTimer;

		private float _flipClock;

		private float _flipDuration;

		private float _spinNow;

		private bool _wasAirborne;

		private Vector3 _launchVel;

		private float _landingThudUntil = -1f;

		private readonly List<Rigidbody> _bodies = new List<Rigidbody>();

		private readonly ViewRotator _view = new ViewRotator();

		private readonly BodyFlipper _body = new BodyFlipper();

		private readonly FlipAudio _audio = new FlipAudio();

		private readonly RemoteFlips _remote = new RemoteFlips();

		private bool _fusion;

		private float _resyncCheckAt = -1f;

		private const float ResyncDistance = 0.35f;

		private FlipKick _kick;

		private bool _renderHook;

		private const float LaunchTime = 0.1f;

		private const float MaxFlipTime = 3f;

		private const float CompleteBlendTime = 0.15f;

		private const float MinFlipDuration = 0.4f;

		private const float MaxFlipDuration = 1.4f;

		private static bool _gameJumped;

		private bool _jumpHookActive;

		private bool _aWasHeld;

		private bool _jumpPressed;

		private float _lastGroundedTime = -10f;

		private float _lastJumpTime = -10f;

		private const float CoyoteTime = 0.3f;

		private const float SwingWindow = 0.35f;

		private const float MaxRealHandSpeed = 15f;

		private const float EffortRange = 4f;

		private readonly Queue<KeyValuePair<float, Vector3>> _swingSamples = new Queue<KeyValuePair<float, Vector3>>();

		private Vector3 _prevL;

		private Vector3 _prevR;

		private Vector3 _prevHead;

		private Vector3 _smoothed;

		private bool _havePrev;

		private readonly HashSet<string> _loggedErrors = new HashSet<string>();

		public override void OnInitializeMelon()
		{
			_cat = MelonPreferences.CreateCategory("BackFlip");
			_enabled = _cat.CreateEntry<bool>("Enabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_minHandSpeed = _cat.CreateEntry<float>("MinHandSpeed", 3f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_handMult = _cat.CreateEntry<float>("HandSpeedMultiplier", 1f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_jumpPower = _cat.CreateEntry<float>("FlipJumpPower", 4.2f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_spinSpeed = _cat.CreateEntry<float>("FlipSpinSpeed", 1f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_drift = _cat.CreateEntry<float>("FlipTravel", 1f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_invert = _cat.CreateEntry<bool>("InvertDirection", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_bodyFollow = _cat.CreateEntry<bool>("BodyFollowsFlip", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_pivot = _cat.CreateEntry<FlipPivot>("RotateAround", FlipPivot.Hips, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_recoverTime = _cat.CreateEntry<float>("LandingRecoverTime", 0.45f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_kicks = _cat.CreateEntry<bool>("FlipKicks", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_kickFootSpeed = _cat.CreateEntry<float>("KickMinFootSpeed", 3f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_kickForce = _cat.CreateEntry<float>("KickForce", 6f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_kickDamage = _cat.CreateEntry<float>("KickDamage", 0.6f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_flipFromClimb = _cat.CreateEntry<bool>("FlipFromClimb", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_sounds = _cat.CreateEntry<bool>("Sounds", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_volume = _cat.CreateEntry<float>("Volume", 0.8f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_haptics = _cat.CreateEntry<bool>("Haptics", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_debug = _cat.CreateEntry<bool>("DebugLogging", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_configVersion = _cat.CreateEntry<int>("ConfigVersion", 0, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			if (_configVersion.Value < 9)
			{
				_invert.Value = false;
				if (_recoverTime.Value > 0.8f)
				{
					_recoverTime.Value = 0.45f;
				}
				_configVersion.Value = 9;
				_cat.SaveToFile(false);
			}
			if (_minHandSpeed.Value < 1.5f)
			{
				_minHandSpeed.Value = 1.5f;
			}
			_kick = new FlipKick(Dbg);
			try
			{
				SetupBoneMenu();
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Error("BoneMenu setup failed: " + ex);
			}
			try
			{
				Application.onBeforeRender += UnityAction.op_Implicit((Action)OnBeforeRender);
				_renderHook = true;
			}
			catch (Exception ex2)
			{
				((MelonBase)this).LoggerInstance.Warning("onBeforeRender hook failed, using LateUpdate: " + ex2.Message);
			}
			MelonCoroutines.Start(EndOfFrameLoop());
			InitFusion();
			HookGameJump();
			Hooking.OnLevelLoaded += delegate
			{
				ResetState();
			};
			((MelonBase)this).LoggerInstance.Msg("BackFlip 1.0 loaded. Jump hook: " + (_jumpHookActive ? "ON" : "OFF (using A button)") + (_fusion ? ", Fusion sync: ON" : ""));
		}

		private void InitFusion()
		{
			bool flag = false;
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			for (int i = 0; i < assemblies.Length; i++)
			{
				if (assemblies[i].GetName().Name == "LabFusion")
				{
					flag = true;
					break;
				}
			}
			if (!flag)
			{
				return;
			}
			try
			{
				InitFusionInner();
				_fusion = true;
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Warning("Fusion found but sync couldn't start: " + ex.Message);
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void InitFusionInner()
		{
			FusionBridge.Init(_remote, Dbg);
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void SendFlipStart(Vector3 axis, float duration, FlipPivot pivot)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			FusionBridge.SendStart(axis, duration, pivot);
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void SendFlipEnd(float recover)
		{
			FusionBridge.SendEnd(recover);
		}

		private void HookGameJump()
		{
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Expected O, but got Unknown
			try
			{
				Type type = null;
				Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
				for (int i = 0; i < assemblies.Length; i++)
				{
					foreach (Type item in SafeGetTypes(assemblies[i]))
					{
						if (item.Name == "RemapRig")
						{
							type = item;
							break;
						}
					}
					if (type != null)
					{
						break;
					}
				}
				if (type == null)
				{
					((MelonBase)this).LoggerInstance.Warning("RemapRig not found; jump hook disabled.");
					return;
				}
				MethodInfo method = type.GetMethod("Jump", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (method == null)
				{
					((MelonBase)this).LoggerInstance.Warning("RemapRig.Jump not found; jump hook disabled.");
					return;
				}
				MethodInfo method2 = typeof(FlipMod).GetMethod("OnGameJump", BindingFlags.Static | BindingFlags.NonPublic);
				((MelonBase)this).HarmonyInstance.Patch((MethodBase)method, (HarmonyMethod)null, new HarmonyMethod(method2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				_jumpHookActive = true;
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Warning("Jump hook failed, falling back to A button: " + ex.Message);
			}
		}

		private static IEnumerable<Type> SafeGetTypes(Assembly asm)
		{
			try
			{
				return asm.GetTypes();
			}
			catch (ReflectionTypeLoadException ex)
			{
				return Array.FindAll(ex.Types, (Type t) => t != null);
			}
			catch
			{
				return Array.Empty<Type>();
			}
		}

		private static void OnGameJump()
		{
			_gameJumped = true;
		}

		private void SetupBoneMenu()
		{
			//IL_000a: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: 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_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: 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_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0319: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			//IL_0387: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dd: Unknown result type (might be due to invalid IL or missing references)
			Page obj = Page.Root.CreatePage("BackFlip", Color.cyan, 0, true);
			obj.CreateBool("Enabled", Color.white, _enabled.Value, (Action<bool>)delegate(bool v)
			{
				Save(_enabled, v);
			});
			obj.CreateFloat("Minimum Hand Speed", Color.yellow, _minHandSpeed.Value, 0.25f, 1.5f, 10f, (Action<float>)delegate(float v)
			{
				Save(_minHandSpeed, v);
			});
			obj.CreateFloat("Flip Hand Speed Multiplier", Color.yellow, _handMult.Value, 0.1f, 0.2f, 3f, (Action<float>)delegate(float v)
			{
				Save(_handMult, v);
			});
			obj.CreateFloat("Jump Power", Color.yellow, _jumpPower.Value, 0.2f, 2.5f, 8f, (Action<float>)delegate(float v)
			{
				Save(_jumpPower, v);
			});
			obj.CreateFloat("Spin Speed", Color.yellow, _spinSpeed.Value, 0.05f, 0.6f, 2f, (Action<float>)delegate(float v)
			{
				Save(_spinSpeed, v);
			});
			obj.CreateFloat("Flip Travel", Color.yellow, _drift.Value, 0.25f, 0f, 4f, (Action<float>)delegate(float v)
			{
				Save(_drift, v);
			});
			obj.CreateFloat("Landing Recover Time (s)", Color.yellow, _recoverTime.Value, 0.05f, 0f, 2f, (Action<float>)delegate(float v)
			{
				Save(_recoverTime, v);
			});
			obj.CreateBool("Invert Direction", Color.white, _invert.Value, (Action<bool>)delegate(bool v)
			{
				Save(_invert, v);
			});
			obj.CreateEnum("Rotate Around", Color.white, (Enum)_pivot.Value, (Action<Enum>)delegate(Enum v)
			{
				Save(_pivot, (FlipPivot)(object)v);
			});
			obj.CreateBool("Body Follows Flip", Color.white, _bodyFollow.Value, (Action<bool>)delegate(bool v)
			{
				Save(_bodyFollow, v);
			});
			obj.CreateBool("Flip From Climb", Color.white, _flipFromClimb.Value, (Action<bool>)delegate(bool v)
			{
				Save(_flipFromClimb, v);
			});
			obj.CreateBool("Sounds", Color.white, _sounds.Value, (Action<bool>)delegate(bool v)
			{
				Save(_sounds, v);
			});
			obj.CreateFloat("Volume", Color.white, _volume.Value, 0.1f, 0f, 1f, (Action<float>)delegate(float v)
			{
				Save(_volume, v);
			});
			obj.CreateBool("Haptics", Color.white, _haptics.Value, (Action<bool>)delegate(bool v)
			{
				Save(_haptics, v);
			});
			obj.CreateBool("Flip Kicks", Color.red, _kicks.Value, (Action<bool>)delegate(bool v)
			{
				Save(_kicks, v);
			});
			obj.CreateFloat("Kick Damage", Color.red, _kickDamage.Value, 0.1f, 0f, 5f, (Action<float>)delegate(float v)
			{
				Save(_kickDamage, v);
			});
			obj.CreateFloat("Kick Force", Color.red, _kickForce.Value, 1f, 0f, 30f, (Action<float>)delegate(float v)
			{
				Save(_kickForce, v);
			});
			obj.CreateFloat("Kick Min Foot Speed", Color.red, _kickFootSpeed.Value, 0.5f, 0.5f, 10f, (Action<float>)delegate(float v)
			{
				Save(_kickFootSpeed, v);
			});
			obj.CreateFunction("Test Backflip", Color.green, (Action)delegate
			{
				TestFlip(front: false);
			});
			obj.CreateFunction("Test Frontflip", Color.green, (Action)delegate
			{
				TestFlip(front: true);
			});
			obj.CreateFunction("Resync Body", Color.green, (Action)delegate
			{
				Resync("button");
			});
			obj.CreateBool("Debug Logging", Color.white, _debug.Value, (Action<bool>)delegate(bool v)
			{
				Save(_debug, v);
			});
		}

		private void Save<T>(MelonPreferences_Entry<T> entry, T value)
		{
			entry.Value = value;
			_cat.SaveToFile(false);
		}

		private void ResetState()
		{
			_view.End();
			_body.End();
			_body.CancelStabilize();
			_audio.Reset();
			_remote.Clear();
			_resyncCheckAt = -1f;
			_flipping = false;
			_landingThudUntil = -1f;
			_swingSamples.Clear();
			_bodies.Clear();
			_havePrev = false;
			_gameJumped = false;
		}

		private void LogErrorOnce(string where, Exception e)
		{
			if (_loggedErrors.Add(where + e.GetType().Name))
			{
				((MelonBase)this).LoggerInstance.Error("Error in " + where + ": " + e);
			}
		}

		private void Dbg(string msg)
		{
			if (_debug.Value)
			{
				((MelonBase)this).LoggerInstance.Msg(msg);
			}
		}

		private bool RigReady()
		{
			if ((Object)(object)Player.RigManager != (Object)null && (Object)(object)Player.ControllerRig != (Object)null)
			{
				return (Object)(object)Player.PhysicsRig != (Object)null;
			}
			return false;
		}

		public override void OnUpdate()
		{
			try
			{
				_view.Restore();
				_remote.Restore();
				_remote.Update(Time.deltaTime);
				if (!RigReady())
				{
					if (_flipping)
					{
						ResetState();
					}
					return;
				}
				if (!_jumpHookActive && (Object)(object)Player.RightController != (Object)null)
				{
					bool aButton = Player.RightController.GetAButton();
					if (aButton && !_aWasHeld)
					{
						_jumpPressed = true;
						Dbg("A button pressed");
					}
					_aWasHeld = aButton;
				}
				float deltaTime = Time.deltaTime;
				if (_flipping)
				{
					AdvanceFlip(deltaTime);
				}
				else
				{
					SampleHands(deltaTime);
				}
				float spin = (_flipping ? Mathf.Clamp01(_spinNow / 720f) : 0f);
				try
				{
					_audio.UpdateWind(spin, deltaTime, _sounds.Value ? _volume.Value : 0f);
				}
				catch (Exception e)
				{
					LogErrorOnce("Audio", e);
				}
			}
			catch (Exception e2)
			{
				LogErrorOnce("OnUpdate", e2);
				ResetState();
			}
		}

		public override void OnLateUpdate()
		{
			if (_renderHook)
			{
				return;
			}
			try
			{
				_view.ApplyForRender();
				_remote.Apply();
			}
			catch (Exception e)
			{
				LogErrorOnce("OnLateUpdate", e);
				ResetState();
			}
		}

		private void OnBeforeRender()
		{
			try
			{
				_view.ApplyForRender();
				_remote.Apply();
			}
			catch (Exception e)
			{
				LogErrorOnce("OnBeforeRender", e);
				ResetState();
			}
		}

		private IEnumerator EndOfFrameLoop()
		{
			WaitForEndOfFrame wait = new WaitForEndOfFrame();
			while (true)
			{
				yield return wait;
				try
				{
					_view.Restore();
					_remote.Restore();
				}
				catch (Exception e)
				{
					LogErrorOnce("EndOfFrame", e);
				}
			}
		}

		public override void OnFixedUpdate()
		{
			try
			{
				FixedTick();
			}
			catch (Exception e)
			{
				LogErrorOnce("OnFixedUpdate", e);
				ResetState();
			}
			_jumpPressed = false;
			_gameJumped = false;
		}

		private void FixedTick()
		{
			if (!RigReady())
			{
				return;
			}
			float fixedDeltaTime = Time.fixedDeltaTime;
			_body.Stabilize(fixedDeltaTime);
			if (!_enabled.Value)
			{
				return;
			}
			bool flag = IsGrounded();
			if (flag)
			{
				_lastGroundedTime = Time.time;
			}
			if (_resyncCheckAt > 0f && Time.time >= _resyncCheckAt)
			{
				_resyncCheckAt = -1f;
				CheckResync();
			}
			if (_landingThudUntil > 0f)
			{
				if (flag)
				{
					_landingThudUntil = -1f;
					LandingFeedback(0.5f);
				}
				else if (Time.time > _landingThudUntil)
				{
					_landingThudUntil = -1f;
				}
			}
			if (_flipping)
			{
				FixedFlip(fixedDeltaTime, flag);
				return;
			}
			bool flag2 = _gameJumped;
			if (!flag2 && _jumpPressed)
			{
				float num = Time.time - _lastGroundedTime;
				flag2 = num <= 0.3f;
				if (!flag2)
				{
					Dbg("Jump ignored: not grounded (" + num.ToString("F2") + "s since ground)");
				}
			}
			if (flag2 && Time.time - _lastJumpTime > 0.4f)
			{
				_lastJumpTime = Time.time;
				TryStartFlip();
			}
		}

		private void SampleHands(float dt)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//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_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: 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_0093: 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_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: 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_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: 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_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: 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)
			Transform val = ViewRotator.TrackingSpace();
			if ((Object)(object)val == (Object)null || (Object)(object)Player.LeftController == (Object)null || (Object)(object)Player.RightController == (Object)null || dt <= 0f)
			{
				_havePrev = false;
				return;
			}
			Vector3 val2 = val.InverseTransformPoint(((Component)Player.LeftController).transform.position);
			Vector3 val3 = val.InverseTransformPoint(((Component)Player.RightController).transform.position);
			Vector3 val4 = val.InverseTransformPoint(Player.ControllerRig.headset.position);
			if (_havePrev)
			{
				Vector3 val5 = (val4 - _prevHead) / dt;
				Vector3 val6 = (val2 - _prevL) / dt - val5;
				Vector3 val7 = (val3 - _prevR) / dt - val5;
				Vector3 val8 = Vector3.zero;
				float num = Mathf.Min(((Vector3)(ref val6)).magnitude, ((Vector3)(ref val7)).magnitude);
				if (num > 0.01f && Vector3.Dot(((Vector3)(ref val6)).normalized, ((Vector3)(ref val7)).normalized) > 0.5f && Mathf.Max(((Vector3)(ref val6)).magnitude, ((Vector3)(ref val7)).magnitude) <= 15f)
				{
					Vector3 val9 = val6 + val7;
					val8 = ((Vector3)(ref val9)).normalized * num;
				}
				_smoothed = Vector3.Lerp(_smoothed, val8, 0.5f);
				_swingSamples.Enqueue(new KeyValuePair<float, Vector3>(Time.time, _smoothed));
			}
			while (_swingSamples.Count > 0 && Time.time - _swingSamples.Peek().Key > 0.35f)
			{
				_swingSamples.Dequeue();
			}
			_prevL = val2;
			_prevR = val3;
			_prevHead = val4;
			_havePrev = true;
		}

		private void TryStartFlip()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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_0032: 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_003a: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: 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_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: 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_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			float num = 0f;
			Vector3 val = Vector3.zero;
			Vector3 val2 = Vector3.zero;
			foreach (KeyValuePair<float, Vector3> swingSample in _swingSamples)
			{
				val2 += swingSample.Value;
				Vector3 value = swingSample.Value;
				if (((Vector3)(ref value)).magnitude > num)
				{
					value = swingSample.Value;
					num = ((Vector3)(ref value)).magnitude;
					val = swingSample.Value;
				}
			}
			Dbg("Jump! peak hand speed = " + num.ToString("F2") + " m/s (need " + _minHandSpeed.Value.ToString("F2") + ")");
			if (num < _minHandSpeed.Value)
			{
				return;
			}
			if (!_flipFromClimb.Value && IsClimbing())
			{
				Dbg("Jump ignored: climbing (Flip From Climb is off)");
				return;
			}
			Vector3 val3 = ViewRotator.TrackingSpace().TransformDirection((((Vector3)(ref val2)).sqrMagnitude > 0.01f) ? val2 : val);
			Vector3 val4 = Vector3.ProjectOnPlane(val3, Vector3.up);
			if (((Vector3)(ref val4)).sqrMagnitude < 0.04f * ((Vector3)(ref val3)).sqrMagnitude)
			{
				val4 = -Vector3.ProjectOnPlane(HeadForward(), Vector3.up);
			}
			((Vector3)(ref val4)).Normalize();
			if (_invert.Value)
			{
				val4 = -val4;
			}
			float effort = Mathf.Clamp01((num - _minHandSpeed.Value) / 4f * _handMult.Value);
			StartFlip(val4, effort);
			_swingSamples.Clear();
		}

		private void TestFlip(bool front)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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)
			if (RigReady())
			{
				Vector3 val = Vector3.ProjectOnPlane(HeadForward(), Vector3.up);
				Vector3 normalized = ((Vector3)(ref val)).normalized;
				StartFlip(front ? normalized : (-normalized), 0.5f);
			}
		}

		private Vector3 PivotPoint()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: 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)
			return (Vector3)(_pivot.Value switch
			{
				FlipPivot.Head => Player.ControllerRig.headset.position, 
				FlipPivot.Feet => BelowHeadset(Player.PhysicsRig.feet.transform.position.y), 
				_ => BelowHeadset(((Rig)Player.PhysicsRig).m_pelvis.position.y), 
			});
		}

		private static Vector3 BelowHeadset(float y)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: 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)
			//IL_0017: 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)
			Vector3 position = Player.ControllerRig.headset.position;
			return new Vector3(position.x, y, position.z);
		}

		private void CheckResync()
		{
			float num = HeadsetDrift();
			Dbg("After landing: headset is " + num.ToString("F2") + " m from the body");
			if (num > 0.35f)
			{
				Resync("drift " + num.ToString("F2") + " m");
			}
		}

		private float HeadsetDrift()
		{
			//IL_003e: 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_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			Rigidbody val = (((Object)(object)Player.PhysicsRig.torso != (Object)null) ? Player.PhysicsRig.torso.rbHead : null);
			if ((Object)(object)val == (Object)null)
			{
				return 0f;
			}
			Vector3 val2 = Player.ControllerRig.headset.position - val.position;
			val2.y = 0f;
			return ((Vector3)(ref val2)).magnitude;
		}

		private void Resync(string why)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			if (!RigReady() || _flipping)
			{
				return;
			}
			try
			{
				Vector3 position = Player.PhysicsRig.feet.transform.position;
				position.y -= Player.PhysicsRig.footballRadius;
				Player.RigManager.Teleport(position, true);
				((MelonBase)this).LoggerInstance.Msg("Re-synced the rig to the body (" + why + ")");
			}
			catch (Exception e)
			{
				LogErrorOnce("Resync", e);
			}
		}

		private Vector3 HeadForward()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			Transform headset = Player.ControllerRig.headset;
			if (!((Object)(object)headset != (Object)null))
			{
				return Player.Head.forward;
			}
			return headset.forward;
		}

		private void StartFlip(Vector3 flatDir, float effort)
		{
			//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_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: 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_008f: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Vector3.Cross(Vector3.up, flatDir);
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			string text = _view.Begin(normalized, PivotPoint());
			if (text != null)
			{
				((MelonBase)this).LoggerInstance.Warning("Can't flip: " + text);
				return;
			}
			CacheBodies();
			Vector3 val2 = AverageVelocity();
			float num = _jumpPower.Value + effort * 1.6f;
			Vector3 val3 = flatDir * _drift.Value * (0.6f + 0.4f * effort);
			_launchVel = new Vector3(val2.x + val3.x, Mathf.Max(val2.y, num), val2.z + val3.z);
			float num2 = 0f - Physics.gravity.y;
			float num3 = DropBelowFeet();
			float num4 = (_launchVel.y + Mathf.Sqrt(_launchVel.y * _launchVel.y + 2f * num2 * num3)) / num2;
			float num5 = Mathf.Lerp(0.88f, 0.78f, effort);
			_flipDuration = Mathf.Clamp(num4 * num5 / Mathf.Max(0.1f, _spinSpeed.Value), 0.4f, 1.4f);
			_flipTimer = 0f;
			_flipClock = 0f;
			_spinNow = 0f;
			_wasAirborne = false;
			_landingThudUntil = -1f;
			_flipping = true;
			_kick.Begin();
			_view.Follow = null;
			if (_bodyFollow.Value && !IsClimbing())
			{
				string text2 = _body.Begin(normalized, _pivot.Value);
				if (text2 != null)
				{
					((MelonBase)this).LoggerInstance.Warning("Body can't follow this flip: " + text2);
				}
				else
				{
					_view.Follow = _body;
				}
			}
			if (_fusion)
			{
				try
				{
					SendFlipStart(normalized, _flipDuration, _pivot.Value);
				}
				catch (Exception e)
				{
					LogErrorOnce("Fusion send", e);
				}
			}
			Haptic(takeoff: true, effort);
			Dbg("FLIP: effort " + effort.ToString("F2") + ", launch " + _launchVel.y.ToString("F1") + " m/s up, airtime " + num4.ToString("F2") + "s, turn in " + _flipDuration.ToString("F2") + "s" + (_body.Active ? ", body following" : ""));
		}

		private void CacheBodies()
		{
			_bodies.Clear();
			Il2CppArrayBase<Rigidbody> componentsInChildren = ((Component)Player.PhysicsRig).GetComponentsInChildren<Rigidbody>();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				if ((Object)(object)componentsInChildren[i] != (Object)null)
				{
					_bodies.Add(componentsInChildren[i]);
				}
			}
		}

		private Vector3 AverageVelocity()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: 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_0069: 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_0039: 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_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			float num = 0f;
			Vector3 val = Vector3.zero;
			for (int i = 0; i < _bodies.Count; i++)
			{
				Rigidbody val2 = _bodies[i];
				if (!((Object)(object)val2 == (Object)null) && !val2.isKinematic)
				{
					num += val2.mass;
					val += val2.velocity * val2.mass;
				}
			}
			if (!(num > 0f))
			{
				return Vector3.zero;
			}
			return val / num;
		}

		private void ApplyLaunch(float dt)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < _bodies.Count; i++)
			{
				Rigidbody val = _bodies[i];
				if (!((Object)(object)val == (Object)null) && !val.isKinematic)
				{
					val.velocity = _launchVel;
				}
			}
			_launchVel += Physics.gravity * dt;
		}

		private float DropBelowFeet()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			Il2CppStructArray<RaycastHit> val = Physics.RaycastAll(Player.PhysicsRig.feet.transform.position + Vector3.up * 0.1f, Vector3.down, 10f, -1, (QueryTriggerInteraction)1);
			Transform transform = ((Component)Player.RigManager).transform;
			float num = 10f;
			for (int i = 0; i < ((Il2CppArrayBase<RaycastHit>)(object)val).Length; i++)
			{
				RaycastHit val2 = ((Il2CppArrayBase<RaycastHit>)(object)val)[i];
				if (!((Component)((RaycastHit)(ref val2)).collider).transform.IsChildOf(transform))
				{
					float num2 = num;
					val2 = ((Il2CppArrayBase<RaycastHit>)(object)val)[i];
					num = Mathf.Min(num2, ((RaycastHit)(ref val2)).distance);
				}
			}
			return Mathf.Max(0f, num - 0.1f);
		}

		private void FixedFlip(float dt, bool grounded)
		{
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			_flipTimer += dt;
			if (_flipTimer <= 0.1f)
			{
				ApplyLaunch(dt);
			}
			if (!grounded && !_wasAirborne)
			{
				_wasAirborne = true;
				Dbg("Left the ground at " + _flipTimer.ToString("F2") + "s");
			}
			if (_body.Active)
			{
				_body.Tick(_view.Angle, _spinNow, dt);
			}
			if (_kicks.Value)
			{
				_kick.Tick(dt, _view.Rotation, _body.Active ? _body.PelvisPosition : _view.Pivot, _kickFootSpeed.Value, _kickForce.Value, _kickDamage.Value);
			}
			bool num;
			if (!_body.Active)
			{
				if (_wasAirborne && grounded)
				{
					num = _flipTimer > 0.15f;
					goto IL_0152;
				}
			}
			else if (_flipTimer > 0.3f && _body.VerticalSpeed <= 0f)
			{
				num = _body.NearGround(((Component)Player.RigManager).transform, 0.75f);
				goto IL_0152;
			}
			goto IL_0161;
			IL_0161:
			if (_flipTimer > 3f)
			{
				FinishFlip("Timed out", hitGround: false);
			}
			return;
			IL_0152:
			if (num)
			{
				FinishFlip("Landed", hitGround: true);
				return;
			}
			goto IL_0161;
		}

		private void AdvanceFlip(float dt)
		{
			_flipClock += dt;
			float num = Mathf.Clamp01(_flipClock / _flipDuration);
			_view.Angle = 360f * FlipMath.Curve(num);
			_spinNow = 360f * FlipMath.CurveRate(num) / _flipDuration;
			if (num >= 1f)
			{
				FinishFlip("Flip complete", hitGround: false);
			}
		}

		private void FinishFlip(string why, bool hitGround)
		{
			if (!_flipping)
			{
				return;
			}
			float num = (_body.Active ? (0f - _body.VerticalSpeed) : 4f);
			Dbg(why + " at " + _view.Angle.ToString("F0") + " deg after " + _flipTimer.ToString("F2") + "s (view tipped up to " + _view.MaxTilt.ToString("F0") + " deg, restore misses " + _view.RestoreMisses + ", around " + _pivot.Value.ToString() + (_body.Active ? (", start drift " + _body.Drift.ToString("F2") + " m") : "") + ")");
			bool flag = _view.Angle >= 359f;
			_view.BeginRecover(flag ? 0.15f : _recoverTime.Value);
			if (_fusion)
			{
				try
				{
					SendFlipEnd(flag ? 0f : _recoverTime.Value);
				}
				catch (Exception e)
				{
					LogErrorOnce("Fusion send", e);
				}
			}
			if (_body.Active)
			{
				_resyncCheckAt = Time.time + 0.8f;
			}
			_body.End();
			_flipping = false;
			_spinNow = 0f;
			_havePrev = false;
			_swingSamples.Clear();
			if (hitGround)
			{
				LandingFeedback(Mathf.Clamp01(Mathf.Max(num, 2f) / 7f));
			}
			else
			{
				_landingThudUntil = Time.time + 1.5f;
			}
		}

		private void LandingFeedback(float strength)
		{
			try
			{
				if (_sounds.Value)
				{
					_audio.Thud(strength, _volume.Value);
				}
			}
			catch (Exception e)
			{
				LogErrorOnce("Audio", e);
			}
			Haptic(takeoff: false, strength);
		}

		private void Haptic(bool takeoff, float strength)
		{
			if (!_haptics.Value)
			{
				return;
			}
			try
			{
				BaseController[] array = (BaseController[])(object)new BaseController[2]
				{
					Player.LeftController,
					Player.RightController
				};
				foreach (BaseController val in array)
				{
					Haptor val2 = (((Object)(object)val != (Object)null) ? val.haptor : null);
					if (!((Object)(object)val2 == (Object)null))
					{
						if (takeoff)
						{
							val2.Haptic_Tap();
						}
						else
						{
							val2.Haptic_Hit(Mathf.Lerp(0.3f, 1f, strength));
						}
					}
				}
			}
			catch (Exception e)
			{
				LogErrorOnce("Haptic", e);
			}
		}

		private bool IsClimbing()
		{
			if (!HoldingStatic(Player.LeftHand))
			{
				return HoldingStatic(Player.RightHand);
			}
			return true;
		}

		private static bool HoldingStatic(Hand hand)
		{
			if ((Object)(object)hand == (Object)null || !hand.HasAttachedObject())
			{
				return false;
			}
			GameObject currentAttachedGO = hand.m_CurrentAttachedGO;
			if ((Object)(object)currentAttachedGO == (Object)null)
			{
				return false;
			}
			Rigidbody componentInParent = currentAttachedGO.GetComponentInParent<Rigidbody>();
			if (!((Object)(object)componentInParent == (Object)null))
			{
				return componentInParent.isKinematic;
			}
			return true;
		}

		private bool IsGrounded()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			Il2CppStructArray<RaycastHit> val = Physics.RaycastAll(Player.PhysicsRig.feet.transform.position + Vector3.up * 0.1f, Vector3.down, 0.2f, -1, (QueryTriggerInteraction)1);
			Transform transform = ((Component)Player.RigManager).transform;
			for (int i = 0; i < ((Il2CppArrayBase<RaycastHit>)(object)val).Length; i++)
			{
				RaycastHit val2 = ((Il2CppArrayBase<RaycastHit>)(object)val)[i];
				if (!((Component)((RaycastHit)(ref val2)).collider).transform.IsChildOf(transform))
				{
					return true;
				}
			}
			return false;
		}
	}
	public enum FlipPivot
	{
		Head,
		Hips,
		Feet
	}
	internal static class FusionBridge
	{
		public static RemoteFlips Remote;

		private static Action<string> _log;

		public static bool InServer => NetworkInfo.HasServer;

		public static void Init(RemoteFlips remote, Action<string> log)
		{
			Remote = remote;
			_log = log;
			ModuleMessageManager.RegisterHandler<FlipNetMessage>();
		}

		public static void SendStart(Vector3 axis, float duration, FlipPivot pivot)
		{
			//IL_0015: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			if (NetworkInfo.HasServer)
			{
				MessageRelay.RelayModule<FlipNetMessage, FlipNetData>(new FlipNetData
				{
					Kind = 1,
					AxisX = axis.x,
					AxisY = axis.y,
					AxisZ = axis.z,
					Seconds = duration,
					Pivot = (byte)pivot
				}, CommonMessageRoutes.ReliableToOtherClients);
			}
		}

		public static void SendEnd(float recoverSeconds)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			if (NetworkInfo.HasServer)
			{
				MessageRelay.RelayModule<FlipNetMessage, FlipNetData>(new FlipNetData
				{
					Kind = 2,
					Seconds = recoverSeconds
				}, CommonMessageRoutes.ReliableToOtherClients);
			}
		}

		internal static void OnReceived(byte sender, FlipNetData data)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			NetworkPlayer val = default(NetworkPlayer);
			if (Remote != null && NetworkPlayerManager.TryGetPlayer(sender, ref val) && val.HasRig)
			{
				RigManager rigManager = val.RigRefs.RigManager;
				if (data.Kind == 1)
				{
					Remote.Start(rigManager, new Vector3(data.AxisX, data.AxisY, data.AxisZ), data.Seconds, (FlipPivot)Math.Min((int)data.Pivot, 2));
					_log?.Invoke("Player " + sender + " flipped");
				}
				else if (data.Kind == 2)
				{
					Remote.End(rigManager, data.Seconds);
				}
			}
		}
	}
	public class FlipNet