Decompiled source of SmoothClimbing v1.0.2

SmoothClimbing.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Playables;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[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 Valheim_Climbing_Mod
{
	[DefaultExecutionOrder(30000)]
	public class ClimbRig : MonoBehaviour
	{
		private struct Segment
		{
			public Transform A;

			public Transform B;

			public float Mass;

			public float At;

			public int Limb;

			public bool Lower;
		}

		private struct MantleStep
		{
			public int Limb;

			public float From;

			public float To;

			public bool OnTop;

			public float Along;

			public float Height;
		}

		private class Limb
		{
			public string Name;

			public bool IsArm;

			public float Side;

			public Transform Root;

			public Transform Mid;

			public Transform End;

			public float UpperLength;

			public float LowerLength;

			public bool Planted;

			public Vector3 Grip;

			public Vector3 GripNormal;

			public bool Moving;

			public Vector3 From;

			public Vector3 To;

			public Vector3 ToNormal;

			public float MoveT;

			public float MoveDuration;

			public float Weight;

			public Vector3 FreeLocal;

			public bool StandInit;

			public bool Held;

			public Vector3 Shown;

			public Transform Index;

			public Transform Middle;

			public Transform Little;

			public Transform Marker;
		}

		public static ConfigEntry<bool> JointLimits;

		private const float HandPastMiddle = 0.06f;

		private const float HandLowest = 1f;

		private const float HandLowestOnTop = 0.55f;

		private const float HandWidest = 0.8f;

		private const float FootPastMiddle = 0.04f;

		private const float FootHighest = 0.85f;

		private const float FootWidest = 0.45f;

		private const float HeadBottom = 1.45f;

		private const float HeadTop = 1.95f;

		private const float HandBesideHead = 0.13f;

		private const float HandsApart = 0.2f;

		private const float FeetApart = 0.18f;

		private const float HandAboveFoot = 0.35f;

		private const float ZoneMargin = 0.12f;

		private const float FootZoneMargin = 0.05f;

		private readonly int[,] _rejected = new int[4, 5];

		private const float LetGoOutOfZone = 0.08f;

		private HumanPoseHandler _limitHandler;

		private HumanPose _limitPose;

		private static bool[] _limitedMuscles;

		private int _clampedMuscles;

		private float _clampMax;

		private string _clampNames = "";

		private Vector3[] _clampPositions;

		public static ConfigEntry<bool> Balance;

		private const float Gravity = 9.81f;

		private const float Intensity = 0.6f;

		private const float Slower = 0.75f;

		private const float HoldBase = 40f;

		private const float HoldFeet = 110f;

		private const float ShiftStiffness = 55f;

		private const float DampingRatio = 0.85f;

		private const float MaxShift = 0.45f;

		private const float MaxSideShift = 0.16f;

		private const float PreShiftTime = 0.08f;

		private const float GripStiffness = 350f;

		private const float ArmStretch = 0.98f;

		private const float LegStretch = 1f;

		private const float SwayRoll = 18f;

		private const float SwayPitch = 10f;

		private const float MaxSway = 9f;

		private Segment[] _segments;

		private Transform _neck;

		private Vector2 _shift;

		private Vector2 _shiftVelocity;

		private Vector3 _capsuleVelocity;

		private Vector3 _capsuleAcceleration;

		private Vector3 _cog;

		private float _feetSupport;

		private float _hanging;

		private bool _balanced = true;

		private int _unbalancedFrames;

		private float _cogBaseX;

		private const float CycleDistance = 0.9f;

		private const float MinSwingTime = 0.45f;

		private static readonly float[] SwingStart = new float[4] { 0f, 0.5f, 0.62f, 0.12f };

		private static readonly float[] SwingEnd = new float[4] { 0.42f, 0.92f, 1f, 0.5f };

		private static readonly Vector2[] ReachCentre = (Vector2[])(object)new Vector2[4]
		{
			new Vector2(-0.23f, 1.78f),
			new Vector2(0.23f, 1.78f),
			new Vector2(-0.17f, 0.38f),
			new Vector2(0.17f, 0.38f)
		};

		private static readonly float[] ReachHalf = new float[4] { 0.275f, 0.275f, 0.24f, 0.24f };

		private static readonly float[] ReachHalfSideways = new float[4] { 0.16f, 0.16f, 0.14f, 0.14f };

		private const float CycleDistanceSideways = 0.55f;

		private static readonly Vector2[] FirstGrip = (Vector2[])(object)new Vector2[4]
		{
			new Vector2(-0.22f, 1.72f),
			new Vector2(0.22f, 1.78f),
			new Vector2(-0.17f, 0.45f),
			new Vector2(0.17f, 0.3f)
		};

		private float _phase;

		private Vector2 _moveDir = Vector2.up;

		private static readonly float[] Lowering = new float[5] { 0f, 0.15f, 0.3f, 0.45f, 0.6f };

		private static readonly float[] Inwards = new float[3] { 0f, 0.5f, 0.85f };

		private static readonly float[] KneelBack = new float[5] { 0.35f, 0.15f, 0f, -0.15f, -0.3f };

		private static readonly MantleStep[] MantleSteps = new MantleStep[6]
		{
			new MantleStep
			{
				Limb = 0,
				From = 0f,
				To = 0.12f,
				OnTop = true,
				Along = 0.35f
			},
			new MantleStep
			{
				Limb = 1,
				From = 0.06f,
				To = 0.18f,
				OnTop = true,
				Along = 0.35f
			},
			new MantleStep
			{
				Limb = 2,
				From = 0.15f,
				To = 0.33f,
				Height = -0.75f
			},
			new MantleStep
			{
				Limb = 3,
				From = 0.33f,
				To = 0.48f,
				Height = -0.45f
			},
			new MantleStep
			{
				Limb = 2,
				From = 0.48f,
				To = 0.66f,
				OnTop = true,
				Along = 0.04f
			},
			new MantleStep
			{
				Limb = 3,
				From = 0.7f,
				To = 0.84f,
				OnTop = true,
				Along = 0.24f
			}
		};

		private static readonly float[] HipKeyAt = new float[5] { 0f, 0.4f, 0.65f, 0.8f, 0.88f };

		private static readonly Vector2[] HipKey = (Vector2[])(object)new Vector2[5]
		{
			Vector2.zero,
			new Vector2(-0.25f, -0.1f),
			new Vector2(-0.05f, 0.25f),
			new Vector2(0.12f, 0.45f),
			new Vector2(0.2f, 0.55f)
		};

		private static readonly float[] LeanKey = new float[5] { 10f, 35f, 50f, 38f, 25f };

		private const float MantleHandsOff = 0.86f;

		private const float MantleStandFrom = 0.86f;

		private const float MantleStandTime = 0.35f;

		private bool _mantling;

		private float _mantleP;

		private Vector3 _edge;

		private Vector3 _inward;

		private Vector3 _mantleUp;

		private float _slope;

		private float _mantleStartY;

		private float _mantleTopY;

		private Vector3 _stepStart;

		private bool _stepSeen;

		private Vector3 _lastHips;

		private readonly bool[] _stepDone = new bool[6];

		private readonly int[] _limbStep = new int[4] { -1, -1, -1, -1 };

		private readonly Vector2[] _hipKey = (Vector2[])HipKey.Clone();

		public static ConfigEntry<bool> Enabled;

		public static ConfigEntry<bool> ShowTargets;

		public static ConfigEntry<bool> SkinOffscreen;

		public static ConfigEntry<bool> LogRig;

		public static ManualLogSource Log;

		private static readonly List<ClimbRig> Rigs = new List<ClimbRig>();

		private static readonly int SurfaceMask = LayerMask.GetMask(new string[5] { "Default", "static_solid", "terrain", "piece", "Default_small" });

		private const float BlendInTime = 0.15f;

		private const float BlendOutTime = 0.3f;

		private const float HipsGap = 0.3f;

		private const float HeadGap = 0.22f;

		private const float LeanBack = 8f;

		private const float MaxLean = 0.45f;

		private Player _player;

		private Animator _animator;

		private Rigidbody _body;

		private Transform _visual;

		private Vector3 _visualRest;

		private readonly Limb[] _limbs = new Limb[4];

		private bool _active;

		private bool _ok;

		private float _weight;

		private float _lean;

		private float _bend;

		private Transform[] _spine;

		private Transform _hips;

		private Transform _chest;

		private Transform _head;

		private Transform _leftThigh;

		private Transform _rightThigh;

		private Vector3 _lastPosition;

		private Vector3 _velocity;

		private readonly bool[] _found = new bool[4];

		private readonly bool[] _deferred = new bool[4];

		private static bool _clipsDumped;

		private readonly Vector3[] _desired = (Vector3[])(object)new Vector3[4];

		private readonly Vector3[] _desiredNormal = (Vector3[])(object)new Vector3[4];

		private readonly Vector3[] _target = (Vector3[])(object)new Vector3[4];

		private readonly Vector3[] _targetNormal = (Vector3[])(object)new Vector3[4];

		private readonly Vector3[] _standSpot = (Vector3[])(object)new Vector3[4];

		private Transform[] _posed;

		private Quaternion[] _animated;

		private Quaternion[] _output;

		private const float MantleTime = 1.1f;

		private const float CrawlPitch = 80f;

		private const float CrawlHipHeight = 0.45f;

		private float _mantleStart;

		private float _mantleUntil;

		private float _topCrawl;

		private float _crawlAtRelease;

		private float _startHeight;

		private const float StandingHipHeight = 0.95f;

		private const float CrawlFrom = -0.05f;

		private const float CrawlFull = 0.45f;

		private static readonly float[] TopProbes = new float[3] { 0.7f, 0.95f, 1.2f };

		private float _crawlLower;

		private const float SteadyTime = 2f;

		private const float SteadySettleTime = 0.2f;

		private float _steadyAge;

		private Vector3 _steadyHips;

		private Vector3 _animatedHips;

		private Vector3[] _animatedPositions;

		private Vector3[] _restPositions;

		private Transform[] _torso;

		private Quaternion[] _torsoHeld;

		private bool _steadyInit;

		private bool _animatorWrote;

		private const float ExitBlend = 0.35f;

		private Vector3 _exitHipsOffset;

		private float _exitOffsetLeft;

		private bool _exitCapture;

		private const float ExitGrace = 0.6f;

		private float _exitGrace;

		public static int TraceFrames;

		private Vector3 _preClampFoot;

		private Vector3 _preClampKnee;

		private HumanPoseHandler _poseHandler;

		private HumanPose _pose;

		private const float LedgeReach = 1.4f;

		private const float MaxHold = 1.5f;

		private const float MinReach = 0.45f;

		private const float MaxWristTurn = 60f;

		private LineRenderer[] _bones;

		private Transform _cogMarker;

		public static ConfigEntry<bool> Sway;

		public static float SwayScale = 1f;

		private const float SideShiftFoot = 0.022f;

		private const float SideShiftHand = 0.01f;

		private const float HipTwistFoot = 3.5f;

		private const float HipRollFoot = 3f;

		private const float ChestTwistHand = 4f;

		private const float ChestRollHand = 2.5f;

		private const float SpineAbsorb = 0.5f;

		private const float SwaySmooth = 0.1f;

		private float _swaySide;

		private float _swayTwist;

		private float _swayRoll;

		private float _swayChestTwist;

		private float _swayChestRoll;

		private float _swaySideV;

		private float _swayTwistV;

		private float _swayRollV;

		private float _swayChestTwistV;

		private float _swayChestRollV;

		private bool BalanceOn
		{
			get
			{
				if (Balance != null)
				{
					return Balance.Value;
				}
				return true;
			}
		}

		private float Cycle => Mathf.Lerp(0.9f, 0.55f, Mathf.Abs(_moveDir.x));

		private bool Mantling => _mantleUntil > 0f;

		private static void BindAnatomy(ConfigFile config)
		{
			JointLimits = config.Bind<bool>("Animation", "JointLimits", true, "Keep every joint of the climbing pose within the body's natural range.");
		}

		private bool InZone(int i, Vector3 point, Vector3 normal, Vector3 lead, float margin = 0f)
		{
			//IL_0015: 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_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_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_002d: 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_0043: 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_00d2: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			Limb obj = _limbs[i];
			Transform transform = ((Component)_player).transform;
			Vector3 val = transform.InverseTransformDirection(point - transform.position - lead);
			float num = obj.Side * val.x;
			if (obj.IsArm)
			{
				float num2 = ((Vector3.Dot(normal, transform.up) > 0.55f) ? 0.55f : 1f);
				float num3 = ((val.y > 1.45f && val.y < 1.95f) ? 0.13f : (-0.06f));
				if (num >= num3 - margin * 0.5f && num <= 0.8f + margin)
				{
					return val.y >= num2 - margin;
				}
				return false;
			}
			if (num >= -0.04f - margin * 0.5f && num <= 0.45f + margin)
			{
				return val.y <= 0.85f + margin;
			}
			return false;
		}

		private bool Acceptable(Limb limb, Vector3 point, Vector3 normal, Vector3 lead)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//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_0048: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_001e: 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_0066: 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_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)
			//IL_00bb: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: 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_0117: Unknown result type (might be due to invalid IL or missing references)
			int num = Array.IndexOf(_limbs, limb);
			if (Crawl() < 0.3f && !InZone(num, point, normal, lead))
			{
				return Reject(num, 0);
			}
			Vector3 val = limb.Root.position + lead;
			if (Vector3.Dot(normal, val - point) <= 0f)
			{
				return Reject(num, 1);
			}
			RaycastHit val2 = default(RaycastHit);
			if (Physics.Linecast(val, point + normal * 0.05f, ref val2, SurfaceMask, (QueryTriggerInteraction)1) && (Object)(object)((RaycastHit)(ref val2)).collider.attachedRigidbody != (Object)(object)_body)
			{
				return Reject(num, 2);
			}
			Limb limb2 = _limbs[num ^ 1];
			if (limb2.Planted && Vector3.Distance(point, limb2.Moving ? limb2.To : limb2.Grip) < (limb.IsArm ? 0.2f : 0.18f))
			{
				return Reject(num, 3);
			}
			Limb limb3 = _limbs[num ^ 2];
			if (limb3.Planted && Vector3.Distance(point, limb3.Moving ? limb3.To : limb3.Grip) < 0.35f)
			{
				return Reject(num, 4);
			}
			return true;
		}

		private bool Reject(int i, int rule)
		{
			_rejected[i, rule]++;
			return false;
		}

		private bool OutOfZone(int i, float further = 0f)
		{
			//IL_0029: 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)
			Limb limb = _limbs[i];
			if (limb.Planted && !limb.Moving && Crawl() < 0.3f)
			{
				return !InZone(i, limb.Grip, limb.GripNormal, Vector3.zero, (limb.IsArm ? 0.12f : 0.05f) + further);
			}
			return false;
		}

		private void ClampToAnatomy()
		{
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Expected O, but got Unknown
			//IL_01df: 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_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: 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_02a5: Unknown result type (might be due to invalid IL or missing references)
			if (JointLimits == null || !JointLimits.Value || (Object)(object)_animator == (Object)null || (Object)(object)_animator.avatar == (Object)null)
			{
				return;
			}
			if (_limitedMuscles == null)
			{
				_limitedMuscles = new bool[HumanTrait.MuscleCount];
				for (int i = 0; i < HumanTrait.MuscleCount; i++)
				{
					int num = HumanTrait.BoneFromMuscle(i);
					_limitedMuscles[i] = (num < 24 || num == 54) && num != 23 && num != 21 && num != 22;
				}
			}
			if (_limitHandler == null)
			{
				_limitHandler = new HumanPoseHandler(_animator.avatar, ((Component)_animator).transform);
			}
			_limitHandler.GetHumanPose(ref _limitPose);
			bool flag = false;
			_clampedMuscles = 0;
			_clampMax = 0f;
			_clampNames = "";
			for (int j = 0; j < _limitPose.muscles.Length; j++)
			{
				float num2 = _limitPose.muscles[j];
				if (_limitedMuscles[j])
				{
					_clampMax = Mathf.Max(_clampMax, Mathf.Abs(num2));
					if (!(num2 >= -1f) || !(num2 <= 1f))
					{
						_clampNames = _clampNames + HumanTrait.MuscleName[j].Replace(" ", "") + ":" + num2.ToString("F3") + ";";
						_limitPose.muscles[j] = Mathf.Clamp(num2, -1f, 1f);
						_clampedMuscles++;
						flag = true;
					}
				}
			}
			if (flag)
			{
				Vector3 position = _hips.position;
				Quaternion rotation = _hips.rotation;
				if (_clampPositions == null || _clampPositions.Length != _posed.Length)
				{
					_clampPositions = (Vector3[])(object)new Vector3[_posed.Length];
				}
				for (int k = 0; k < _posed.Length; k++)
				{
					_clampPositions[k] = _posed[k].localPosition;
				}
				_limitHandler.SetHumanPose(ref _limitPose);
				for (int l = 0; l < _posed.Length; l++)
				{
					_posed[l].localPosition = _clampPositions[l];
				}
				_hips.position = position;
				_hips.rotation = rotation;
			}
		}

		private static void BindBalance(ConfigFile config)
		{
			Balance = config.Bind<bool>("Animation", "PhysicsBalance", false, "Let the body hang off its grips with weight: sag, sway and shift over the supporting hands and feet.");
		}

		private void SetupBalance(Animator animator)
		{
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: 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_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: 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_028a: Unknown result type (might be due to invalid IL or missing references)
			_neck = animator.GetBoneTransform((HumanBodyBones)9) ?? _head;
			_segments = new Segment[10]
			{
				new Segment
				{
					A = _hips,
					B = _neck,
					Mass = 0.497f,
					At = 0.5f,
					Limb = -1
				},
				new Segment
				{
					A = _head,
					B = _head,
					Mass = 0.081f,
					At = 0f,
					Limb = -1
				},
				new Segment
				{
					Mass = 0.028f,
					At = 0.436f,
					Limb = 0
				},
				new Segment
				{
					Mass = 0.022f,
					At = 0.6f,
					Limb = 0,
					Lower = true
				},
				new Segment
				{
					Mass = 0.028f,
					At = 0.436f,
					Limb = 1
				},
				new Segment
				{
					Mass = 0.022f,
					At = 0.6f,
					Limb = 1,
					Lower = true
				},
				new Segment
				{
					Mass = 0.1f,
					At = 0.433f,
					Limb = 2
				},
				new Segment
				{
					Mass = 0.061f,
					At = 0.5f,
					Limb = 2,
					Lower = true
				},
				new Segment
				{
					Mass = 0.1f,
					At = 0.433f,
					Limb = 3
				},
				new Segment
				{
					Mass = 0.061f,
					At = 0.5f,
					Limb = 3,
					Lower = true
				}
			};
			_shift = (_shiftVelocity = Vector2.zero);
			_capsuleVelocity = (_capsuleAcceleration = Vector3.zero);
		}

		private Vector3 CentreOfGravity(Vector3[] targets, Vector3 offset)
		{
			//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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: 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_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0076: 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_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Vector3.zero;
			float num = 0f;
			Segment[] segments = _segments;
			for (int i = 0; i < segments.Length; i++)
			{
				Segment segment = segments[i];
				Vector3 val2;
				if (segment.Limb < 0)
				{
					if ((Object)(object)segment.A == (Object)null || (Object)(object)segment.B == (Object)null)
					{
						continue;
					}
					val2 = Vector3.Lerp(segment.A.position, segment.B.position, segment.At) + offset;
				}
				else
				{
					val2 = Vector3.Lerp(_limbs[segment.Limb].Root.position + offset, targets[segment.Limb], segment.Lower ? (0.5f + 0.5f * segment.At) : (0.5f * segment.At));
				}
				val += val2 * segment.Mass;
				num += segment.Mass;
			}
			if (!(num > 0f))
			{
				return ((Component)_player).transform.position;
			}
			return val / num;
		}

		private bool Supporting(int i)
		{
			if (_limbs[i].Planted && !_limbs[i].Moving)
			{
				return _limbs[i].Weight > 0.5f;
			}
			return false;
		}

		private static bool Steep(Transform body)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			return Vector3.Dot(-body.forward, Vector3.up) < 0.64f;
		}

		private float SideTarget(Transform body, float cogX)
		{
			//IL_004c: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			float num = 0f;
			float num2 = 0f;
			for (int i = 0; i < _limbs.Length; i++)
			{
				if (Supporting(i) && !SwingsSoon(i))
				{
					float num3 = (_limbs[i].IsArm ? 0.4f : 0.6f);
					num += Vector3.Dot(_limbs[i].Grip - body.position, body.right) * num3;
					num2 += num3;
				}
			}
			if (!(num2 > 0f))
			{
				return 0f;
			}
			return Mathf.Clamp(num / num2 - cogX, -0.16f, 0.16f);
		}

		private void SolveBalance(Transform body, Vector3 up, Vector3 right, float dt, float crawl)
		{
			//IL_0029: 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_002f: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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_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_0057: 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_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: 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_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: 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_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			//IL_0377: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: Unknown result type (might be due to invalid IL or missing references)
			//IL_0388: Unknown result type (might be due to invalid IL or missing references)
			//IL_038e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0393: Unknown result type (might be due to invalid IL or missing references)
			//IL_0398: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: 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_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b0: 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_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: 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_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0322: Unknown result type (might be due to invalid IL or missing references)
			//IL_0327: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_0338: Unknown result type (might be due to invalid IL or missing references)
			//IL_0344: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_034f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0354: Unknown result type (might be due to invalid IL or missing references)
			//IL_0414: Unknown result type (might be due to invalid IL or missing references)
			//IL_0419: Unknown result type (might be due to invalid IL or missing references)
			//IL_0420: Unknown result type (might be due to invalid IL or missing references)
			//IL_0421: Unknown result type (might be due to invalid IL or missing references)
			//IL_0426: Unknown result type (might be due to invalid IL or missing references)
			//IL_0433: Unknown result type (might be due to invalid IL or missing references)
			//IL_0438: Unknown result type (might be due to invalid IL or missing references)
			float num = (BalanceOn ? _weight : 0f);
			if (dt <= 0f || _segments == null)
			{
				return;
			}
			Vector3 velocity = _velocity;
			Vector3 val = (velocity - _capsuleVelocity) / dt;
			_capsuleVelocity = velocity;
			_capsuleAcceleration = Vector3.Lerp(_capsuleAcceleration, Vector3.ClampMagnitude(val, 20f), Mathf.Clamp01(dt * 12f));
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(Vector3.Dot(_capsuleAcceleration, right), Vector3.Dot(_capsuleAcceleration, up));
			int num2 = 0;
			for (int i = 2; i < 4; i++)
			{
				if (Supporting(i))
				{
					num2++;
				}
			}
			_feetSupport = Mathf.MoveTowards(_feetSupport, (float)num2 / 2f, dt * 6f);
			Vector3 val3 = CentreOfGravity(_target, Vector3.zero);
			_cogBaseX = Vector3.Dot(val3 - body.position, right);
			float num3 = SideTarget(body, _cogBaseX);
			float num4 = ((_active && !Mantling) ? (1f - crawl) : 0f);
			_hanging = Mathf.MoveTowards(_hanging, num4, dt * 4f);
			float num5 = (40f + 110f * _feetSupport) * 0.75f;
			float num6 = 1.7f * Mathf.Sqrt(num5);
			float num7 = 41.25f;
			float num8 = 1.7f * Mathf.Sqrt(num7);
			int num9 = Mathf.Clamp(Mathf.CeilToInt(dt / (1f / 120f)), 1, 8);
			float num10 = dt / (float)num9;
			Vector2 val4 = default(Vector2);
			for (int j = 0; j < num9; j++)
			{
				Vector2 shift = _shift;
				((Vector2)(ref val4))..ctor(num7 * (num3 * 0.6f - _shift.x) - num8 * _shiftVelocity.x, (0f - num5) * _shift.y - num6 * _shiftVelocity.y - 4.4145f * _hanging);
				val4 -= val2 * (_hanging * 0.6f);
				if (_hanging > 0f)
				{
					val4 += GripForce(body, up, right) * _hanging;
				}
				if (_hanging < 1f)
				{
					val4.x -= 55f * (1f - _hanging) * _shift.x;
				}
				_shiftVelocity += val4 * num10;
				_shift += _shiftVelocity * num10;
				_shift = Vector2.ClampMagnitude(_shift, 0.45f);
				_shiftVelocity = (_shift - shift) / num10;
			}
			if ((Object)(object)_visual != (Object)null && num > 0f)
			{
				Transform visual = _visual;
				visual.position += (right * _shift.x + up * _shift.y) * num;
			}
			_cog = CentreOfGravity(_target, (right * _shift.x + up * _shift.y) * num);
			if (num > 0f && _spine.Length != 0)
			{
				float num11 = Mathf.Clamp((0f - _shiftVelocity.x) * 18f, -9f, 9f) * (num * 0.6f);
				float num12 = Mathf.Clamp(_shiftVelocity.y * 10f, -9f, 9f) * (num * 0.6f);
				_spine[0].rotation = Quaternion.AngleAxis(num11, body.forward) * Quaternion.AngleAxis(num12, right) * _spine[0].rotation;
			}
			_balanced = BalancedNow(body);
			if (!_balanced && _hanging >= 1f && _weight >= 1f)
			{
				_unbalancedFrames++;
			}
		}

		private Vector2 GripForce(Transform body, Vector3 up, Vector3 right)
		{
			//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_0117: 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_003a: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_006e: 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_00d1: 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_00e2: 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)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: 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_00f4: 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)
			Vector2 val = Vector2.zero;
			for (int i = 0; i < _limbs.Length; i++)
			{
				if (Supporting(i))
				{
					Limb limb = _limbs[i];
					float num = limb.UpperLength + limb.LowerLength;
					Vector3 val2 = limb.Root.position + right * _shift.x + up * _shift.y;
					Vector3 val3 = limb.Grip - val2;
					float magnitude = ((Vector3)(ref val3)).magnitude;
					float num2 = num * (limb.IsArm ? 0.98f : 1f);
					float num3 = num * 0.45f;
					float num4 = ((magnitude > num2) ? (magnitude - num2) : ((magnitude < num3) ? (magnitude - num3) : 0f));
					if (num4 != 0f && !(magnitude < 0.0001f))
					{
						Vector3 val4 = val3 / magnitude * (350f * num4);
						val += new Vector2(Vector3.Dot(val4, right), Vector3.Dot(val4, up));
					}
				}
			}
			return val;
		}

		private bool BalancedNow(Transform body)
		{
			//IL_0028: 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_0033: 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_0087: 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_0092: 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)
			float num = float.MaxValue;
			float num2 = float.MinValue;
			int num3 = 0;
			int num4 = 0;
			for (int i = 0; i < _limbs.Length; i++)
			{
				if (Supporting(i))
				{
					float num5 = Vector3.Dot(_limbs[i].Grip - body.position, body.right);
					num = Mathf.Min(num, num5);
					num2 = Mathf.Max(num2, num5);
					num4++;
					if (_limbs[i].IsArm)
					{
						num3++;
					}
				}
			}
			if (num4 == 0)
			{
				return false;
			}
			float num6 = Vector3.Dot(_cog - body.position, body.right);
			if (num6 > num - 0.2f && num6 < num2 + 0.2f)
			{
				if (num3 <= 0 && Steep(body))
				{
					return Crawl() > 0.3f;
				}
				return true;
			}
			return false;
		}

		private string DescribeBalance(Transform body)
		{
			//IL_0002: 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_0040: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = body.InverseTransformPoint(_cog);
			return $" bal shift=({_shift.x:F2},{_shift.y:F2}) cog=({val.x:F2},{val.y:F2},{val.z:F2}) feet={_feetSupport:F2}" + $" phase={_phase:F2} hang={_hanging:F2} ok={((_balanced || _hanging < 1f || _weight < 1f) ? 1 : 0)}";
		}

		private static Vector2 ReachPoint(int i, Vector2 m)
		{
			//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_0019: 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)
			return ReachCentre[i] + new Vector2(m.x * ReachHalfSideways[i], m.y * ReachHalf[i]);
		}

		private static float Sweep(int i, Vector2 m)
		{
			//IL_0000: 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_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)
			Vector2 val = new Vector2(m.x * ReachHalfSideways[i], m.y * ReachHalf[i]);
			return ((Vector2)(ref val)).magnitude;
		}

		private static float Wrap(float x)
		{
			return x - Mathf.Floor(x);
		}

		private static float WindowLength(int i)
		{
			return Wrap(SwingEnd[i] - SwingStart[i] - 0.0001f) + 0.0001f;
		}

		private void ResetGait()
		{
			//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)
			_phase = 0.95f;
			_moveDir = Vector2.up;
		}

		private float AdvanceGait(Vector3 moved, Vector3 up, Vector3 right, float crawl)
		{
			//IL_0039: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_0065: 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)
			//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)
			if (crawl > 0.3f)
			{
				_moveDir = Vector2.up;
				float num = ((Vector3)(ref moved)).magnitude / 0.9f;
				_phase = Wrap(_phase + num);
				return num;
			}
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(Vector3.Dot(moved, right), Vector3.Dot(moved, up));
			float magnitude = ((Vector2)(ref val)).magnitude;
			if (magnitude > 0.001f)
			{
				Vector2 val2 = Vector2.Lerp(_moveDir, val / magnitude, 0.25f);
				_moveDir = ((Vector2)(ref val2)).normalized;
			}
			float num2 = magnitude / Cycle;
			_phase = Wrap(_phase + num2);
			return num2;
		}

		private bool SwingDue(int i, float before, float step)
		{
			if (step > 0f)
			{
				return Wrap(SwingStart[i] - before) < step;
			}
			return false;
		}

		private Vector2 StanceSpot(int i)
		{
			//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_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)
			float num = 1f - WindowLength(i);
			float num2 = Wrap(_phase - SwingEnd[i]);
			float num3 = ((num2 > num) ? 0f : (num2 / num));
			return Vector2.Lerp(ReachPoint(i, _moveDir), ReachPoint(i, -_moveDir), num3);
		}

		private void BeginSwing(int i, Transform body, Vector3 up, Vector3 right, Vector3 wallNormal, float speed, Vector2 spot, float window)
		{
			//IL_002b: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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_0047: 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_004b: 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_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00ab: 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_006e: 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)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			Limb limb = _limbs[i];
			float num = Mathf.Min(window * Cycle / Mathf.Max(speed, 0.25f), 0.45f);
			Vector3 lead = Vector3.ClampMagnitude(_velocity * num, 0.5f);
			if (GaitGrip(limb, body, up, right, wallNormal, spot, lead, out var point, out var normal))
			{
				if (!limb.Planted)
				{
					limb.Planted = true;
					limb.Grip = limb.Shown;
					limb.GripNormal = normal;
				}
				limb.Moving = true;
				limb.MoveT = 0f;
				limb.MoveDuration = window;
				limb.From = limb.Grip;
				limb.To = point;
				limb.ToNormal = normal;
			}
		}

		private bool GaitGrip(Limb limb, Transform body, Vector3 up, Vector3 right, Vector3 wallNormal, Vector2 spot, Vector3 lead, out Vector3 point, out Vector3 normal)
		{
			//IL_0131: 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_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: 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_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: 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_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: 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_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_005b: 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_006b: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: 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_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: 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_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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_00c1: 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_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: 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_0109: 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_0117: 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)
			float[] kneelBack;
			if (!limb.IsArm && Crawl() > 0.3f)
			{
				kneelBack = KneelBack;
				RaycastHit val = default(RaycastHit);
				foreach (float num in kneelBack)
				{
					if (Physics.Raycast(limb.Root.position + lead + wallNormal * num + right * (limb.Side * 0.08f) + up * 0.6f, -up, ref val, 2f, SurfaceMask, (QueryTriggerInteraction)1) && (Object)(object)((RaycastHit)(ref val)).collider.attachedRigidbody != (Object)(object)_body && Vector3.Dot(((RaycastHit)(ref val)).normal, up) > 0.5f && ((RaycastHit)(ref val)).point.y > _startHeight + 0.5f && ReachFrom(limb, ((RaycastHit)(ref val)).point, lead) <= 1.05f && ReachFrom(limb, ((RaycastHit)(ref val)).point, lead) >= 0.45f)
					{
						point = ((RaycastHit)(ref val)).point;
						normal = ((RaycastHit)(ref val)).normal;
						return true;
					}
				}
			}
			Vector3 val2 = body.position + lead;
			Vector3 val3 = val2 + right * spot.x + up * spot.y;
			if (limb.IsArm && LedgeGrip(limb, val3, wallNormal, up, lead, out point, out normal))
			{
				return true;
			}
			kneelBack = Lowering;
			foreach (float num2 in kneelBack)
			{
				float[] inwards = Inwards;
				foreach (float num3 in inwards)
				{
					Vector3 home = val2 + right * (spot.x * (1f - num3)) + up * (spot.y - num2 * (limb.IsArm ? 1f : (-0.5f)));
					if (FaceGrip(limb, home, wallNormal, lead, out point, out normal))
					{
						return true;
					}
				}
			}
			if (!limb.IsArm && LedgeGrip(limb, val3, wallNormal, up, lead, out point, out normal))
			{
				return true;
			}
			point = val3;
			normal = wallNormal;
			return false;
		}

		private static float ReachFrom(Limb limb, Vector3 point, Vector3 lead)
		{
			//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)
			return Vector3.Distance(limb.Root.position + lead, point) / (limb.UpperLength + limb.LowerLength);
		}

		private float Trailing(int i, Transform body, Vector3 up, Vector3 right)
		{
			//IL_0008: 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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = _limbs[i].Grip - body.position;
			return 0f - Vector2.Dot(new Vector2(Vector3.Dot(val, right), Vector3.Dot(val, up)) - ReachCentre[i], _moveDir);
		}

		private bool SwingsSoon(int i, float ahead = 0.1f)
		{
			if (_limbs[i].Moving)
			{
				return true;
			}
			return Wrap(SwingStart[i] - _phase) < ahead;
		}

		public static bool IsMantling(Player player)
		{
			ClimbRig climbRig = (((Object)(object)player != (Object)null) ? ((Component)player).GetComponent<ClimbRig>() : null);
			if ((Object)(object)climbRig != (Object)null)
			{
				return climbRig._mantling;
			}
			return false;
		}

		private bool BeginMantle(Transform body)
		{
			//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_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//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_0050: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: 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_0099: 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_00b7: 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_00bb: 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_00e2: 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)
			//IL_00ea: 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_00f6: 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_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: 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_011c: 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_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: 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_019c: 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_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: 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_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: 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_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			Vector3 up = Vector3.up;
			Vector3 val = Vector3.ProjectOnPlane(body.forward, up);
			if (((Vector3)(ref val)).sqrMagnitude < 0.01f)
			{
				return false;
			}
			((Vector3)(ref val)).Normalize();
			RaycastHit val2 = default(RaycastHit);
			RaycastHit val3 = default(RaycastHit);
			if (!Physics.Raycast(body.position + up * 2.4f + val * 0.65f, -up, ref val2, 2.9f, SurfaceMask, (QueryTriggerInteraction)1) || (Object)(object)((RaycastHit)(ref val2)).collider.attachedRigidbody == (Object)(object)_body || !Physics.Raycast(body.position + up * 0.5f, val, ref val3, 1.5f, SurfaceMask, (QueryTriggerInteraction)1))
			{
				return false;
			}
			Vector3 normal = ((RaycastHit)(ref val2)).normal;
			float num = Mathf.Max(Vector3.Dot(normal, up), 0.3f);
			_slope = (0f - Vector3.Dot(normal, val)) / num;
			_edge = ((RaycastHit)(ref val3)).point + up * (Vector3.Dot(((RaycastHit)(ref val2)).point - ((RaycastHit)(ref val3)).point, normal) / num);
			_inward = val;
			_mantleUp = up;
			_mantleStartY = body.position.y;
			_mantleTopY = _edge.y;
			_stepSeen = false;
			_mantleP = 0f;
			Array.Clear(_stepDone, 0, _stepDone.Length);
			for (int i = 0; i < 4; i++)
			{
				_limbStep[i] = -1;
			}
			Vector3 val4 = ((_lastHips != Vector3.zero) ? _lastHips : _hips.position);
			float num2 = Vector3.Dot(val4 - _edge, val);
			_hipKey[0] = new Vector2(num2, val4.y - TopPoint(num2).y);
			_shift = (_shiftVelocity = Vector2.zero);
			_lean = 0f;
			_topCrawl = 0f;
			_mantleUntil = 0f;
			Limb[] limbs = _limbs;
			foreach (Limb obj in limbs)
			{
				obj.Moving = false;
				obj.Planted = true;
				obj.Grip = obj.Shown;
			}
			_mantling = true;
			return true;
		}

		private Vector3 TopPoint(float along)
		{
			//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_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_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_002a: Unknown result type (might be due to invalid IL or missing references)
			return _edge + _inward * along + _mantleUp * (along * _slope);
		}

		private void AdvanceMantle(Transform body, float dt)
		{
			//IL_0024: 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_009e: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			ClimbingState.ClimbingData orCreate = ClimbingState.GetOrCreate(_player);
			float mantleP = _mantleP;
			if (orCreate.isClimbing && !orCreate.steppingOn)
			{
				float num = Mathf.Clamp01((body.position.y - _mantleStartY) / Mathf.Max(_mantleTopY + 0.03f - _mantleStartY, 0.05f));
				mantleP = Mathf.Max(mantleP, 0.65f * num);
			}
			else if (orCreate.isClimbing)
			{
				if (!_stepSeen)
				{
					_stepSeen = true;
					_stepStart = body.position;
				}
				float num2 = Vector3.Dot(body.position - _stepStart, _inward);
				mantleP = Mathf.Max(mantleP, 0.65f + 0.21f * Mathf.Clamp01(num2 / 0.55f));
			}
			else
			{
				mantleP = Mathf.Max(mantleP, 0.86f) + dt * 0.13999999f / 0.35f;
			}
			_mantleP = Mathf.Min(mantleP, 1f);
		}

		private static float Key(float[] at, float[] values, float p)
		{
			for (int i = 1; i < at.Length; i++)
			{
				if (p <= at[i])
				{
					return Mathf.Lerp(values[i - 1], values[i], Mathf.SmoothStep(0f, 1f, (p - at[i - 1]) / (at[i] - at[i - 1])));
				}
			}
			return values[^1];
		}

		private static Vector2 Key(float[] at, Vector2[] values, float p)
		{
			//IL_0050: 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_0015: 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)
			for (int i = 1; i < at.Length; i++)
			{
				if (p <= at[i])
				{
					return Vector2.Lerp(values[i - 1], values[i], Mathf.SmoothStep(0f, 1f, (p - at[i - 1]) / (at[i] - at[i - 1])));
				}
			}
			return values[^1];
		}

		private bool MantleGrip(MantleStep step, Limb limb, out Vector3 point, out Vector3 normal)
		{
			//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_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_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: 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_00f7: 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_004a: 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_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_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_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_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: 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_0131: 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_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_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Vector3.Cross(_mantleUp, _inward) * (limb.Side * (limb.IsArm ? 0.22f : 0.14f));
			RaycastHit val3 = default(RaycastHit);
			if (step.OnTop)
			{
				RaycastHit val2 = default(RaycastHit);
				if (Physics.Raycast(TopPoint(step.Along) + val + _mantleUp * 0.5f, -_mantleUp, ref val2, 1.2f, SurfaceMask, (QueryTriggerInteraction)1) && (Object)(object)((RaycastHit)(ref val2)).collider.attachedRigidbody != (Object)(object)_body)
				{
					point = ((RaycastHit)(ref val2)).point;
					normal = ((RaycastHit)(ref val2)).normal;
					return true;
				}
			}
			else if (Physics.Raycast(_edge + _mantleUp * step.Height + val - _inward * 0.5f, _inward, ref val3, 1.2f, SurfaceMask, (QueryTriggerInteraction)1) && (Object)(object)((RaycastHit)(ref val3)).collider.attachedRigidbody != (Object)(object)_body)
			{
				point = ((RaycastHit)(ref val3)).point;
				normal = ((RaycastHit)(ref val3)).normal;
				return true;
			}
			point = Vector3.zero;
			normal = Vector3.zero;
			return false;
		}

		private bool MantleFrame(Transform body, float dt)
		{
			//IL_0010: 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_0016: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: 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_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: 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_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: 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)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: 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_028b: 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_0496: Unknown result type (might be due to invalid IL or missing references)
			//IL_049b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04be: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0500: Unknown result type (might be due to invalid IL or missing references)
			//IL_0506: Unknown result type (might be due to invalid IL or missing references)
			//IL_050b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0510: Unknown result type (might be due to invalid IL or missing references)
			//IL_0395: Unknown result type (might be due to invalid IL or missing references)
			//IL_039a: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_051a: Unknown result type (might be due to invalid IL or missing references)
			//IL_051c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0521: Unknown result type (might be due to invalid IL or missing references)
			//IL_0523: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_030e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Unknown result type (might be due to invalid IL or missing references)
			//IL_032e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0335: Unknown result type (might be due to invalid IL or missing references)
			//IL_033c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0343: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Unknown result type (might be due to invalid IL or missing references)
			//IL_053b: Unknown result type (might be due to invalid IL or missing references)
			//IL_053c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0546: Unknown result type (might be due to invalid IL or missing references)
			//IL_054b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0559: Unknown result type (might be due to invalid IL or missing references)
			//IL_055e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0564: Unknown result type (might be due to invalid IL or missing references)
			//IL_056e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0573: Unknown result type (might be due to invalid IL or missing references)
			//IL_0578: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03da: Unknown result type (might be due to invalid IL or missing references)
			//IL_03df: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Unknown result type (might be due to invalid IL or missing references)
			//IL_0367: Unknown result type (might be due to invalid IL or missing references)
			//IL_0370: Unknown result type (might be due to invalid IL or missing references)
			//IL_0375: Unknown result type (might be due to invalid IL or missing references)
			//IL_0603: Unknown result type (might be due to invalid IL or missing references)
			//IL_060d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0612: Unknown result type (might be due to invalid IL or missing references)
			//IL_0620: Unknown result type (might be due to invalid IL or missing references)
			//IL_0625: Unknown result type (might be due to invalid IL or missing references)
			//IL_062a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0630: Unknown result type (might be due to invalid IL or missing references)
			//IL_0635: Unknown result type (might be due to invalid IL or missing references)
			//IL_063a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0589: Unknown result type (might be due to invalid IL or missing references)
			//IL_0596: Unknown result type (might be due to invalid IL or missing references)
			//IL_059b: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05be: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_05fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_065d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0662: Unknown result type (might be due to invalid IL or missing references)
			//IL_0437: Unknown result type (might be due to invalid IL or missing references)
			//IL_043e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0445: Unknown result type (might be due to invalid IL or missing references)
			//IL_044a: Unknown result type (might be due to invalid IL or missing references)
			//IL_044f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0453: Unknown result type (might be due to invalid IL or missing references)
			//IL_045a: Unknown result type (might be due to invalid IL or missing references)
			//IL_045f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0471: Unknown result type (might be due to invalid IL or missing references)
			//IL_0476: Unknown result type (might be due to invalid IL or missing references)
			//IL_047f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0484: Unknown result type (might be due to invalid IL or missing references)
			//IL_0679: Unknown result type (might be due to invalid IL or missing references)
			//IL_067e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0683: Unknown result type (might be due to invalid IL or missing references)
			//IL_0687: Unknown result type (might be due to invalid IL or missing references)
			//IL_0689: Unknown result type (might be due to invalid IL or missing references)
			//IL_069b: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_06bc: Unknown result type (might be due to invalid IL or missing references)
			AdvanceMantle(body, dt);
			float mantleP = _mantleP;
			Vector3 mantleUp = _mantleUp;
			Vector3 val = Vector3.Cross(mantleUp, _inward);
			for (int i = 0; i < MantleSteps.Length; i++)
			{
				MantleStep step = MantleSteps[i];
				if (!_stepDone[i] && !(mantleP < step.From))
				{
					_stepDone[i] = true;
					Limb limb = _limbs[step.Limb];
					if (MantleGrip(step, limb, out var point, out var normal))
					{
						limb.From = (limb.Planted ? limb.Grip : limb.Shown);
						limb.To = point;
						limb.ToNormal = normal;
						limb.Moving = true;
						limb.Planted = true;
						_limbStep[step.Limb] = i;
					}
				}
			}
			for (int j = 0; j < 2; j++)
			{
				if (mantleP >= 0.86f && _limbs[j].Planted)
				{
					_limbs[j].Planted = false;
					_limbs[j].Moving = false;
					_limbs[j].FreeLocal = body.InverseTransformPoint(_limbs[j].Shown);
				}
			}
			float num = Key(HipKeyAt, LeanKey, mantleP);
			float num2 = Mathf.SmoothStep(0f, 1f, (mantleP - 0.86f) / 0.13999999f);
			_hips.rotation = Quaternion.AngleAxis(num * (1f - num2), val) * _hips.rotation;
			if ((Object)(object)_visual != (Object)null)
			{
				_visual.localPosition = _visualRest;
				Vector2 val2 = Key(HipKeyAt, _hipKey, mantleP);
				Vector3 val3 = TopPoint(val2.x) + mantleUp * val2.y;
				Transform visual = _visual;
				visual.position += (val3 - _hips.position) * (1f - num2);
			}
			RaycastHit val6 = default(RaycastHit);
			for (int k = 0; k < _limbs.Length; k++)
			{
				Limb limb2 = _limbs[k];
				Vector3 val5;
				if (limb2.Moving)
				{
					MantleStep mantleStep = MantleSteps[_limbStep[k]];
					float num3 = Mathf.SmoothStep(0f, 1f, (mantleP - mantleStep.From) / (mantleStep.To - mantleStep.From));
					Vector3 val4 = limb2.From + mantleUp * (Mathf.Max(limb2.To.y - limb2.From.y, 0f) + (limb2.IsArm ? 0.15f : 0.25f));
					_target[k] = (1f - num3) * (1f - num3) * limb2.From + 2f * num3 * (1f - num3) * val4 + num3 * num3 * limb2.To;
					val5 = Vector3.Slerp(limb2.GripNormal, limb2.ToNormal, num3);
					if (num3 >= 1f)
					{
						limb2.Moving = false;
						limb2.Grip = limb2.To;
						limb2.GripNormal = limb2.ToNormal;
					}
				}
				else if (limb2.Planted)
				{
					_target[k] = limb2.Grip;
					val5 = limb2.GripNormal;
					if (!limb2.IsArm && num2 > 0f && Physics.Raycast(limb2.Root.position + val * (limb2.Side * 0.04f) + mantleUp * 0.3f, -mantleUp, ref val6, 2.5f, SurfaceMask, (QueryTriggerInteraction)1) && (Object)(object)((RaycastHit)(ref val6)).collider.attachedRigidbody != (Object)(object)_body)
					{
						_target[k] = Vector3.Lerp(limb2.Grip, ((RaycastHit)(ref val6)).point, num2);
						val5 = Vector3.Slerp(val5, ((RaycastHit)(ref val6)).normal, num2);
						if (num2 >= 0.999f)
						{
							limb2.Grip = ((RaycastHit)(ref val6)).point;
							limb2.GripNormal = ((RaycastHit)(ref val6)).normal;
						}
					}
				}
				else
				{
					Vector3 val7 = body.InverseTransformPoint(limb2.Root.position - mantleUp * 0.5f + val * (limb2.Side * 0.08f));
					limb2.FreeLocal = Vector3.Lerp(limb2.FreeLocal, val7, Mathf.Clamp01(dt * 6f));
					_target[k] = body.TransformPoint(limb2.FreeLocal);
					val5 = -_inward;
				}
				_targetNormal[k] = val5;
				bool flag = Vector3.Dot(val5, mantleUp) > 0.5f;
				Vector3 pole;
				if (limb2.IsArm)
				{
					pole = -mantleUp * 0.5f + val * (limb2.Side * 0.7f) - _inward * 0.2f;
				}
				else if (flag)
				{
					float num4 = Vector3.Dot(_hips.position - _target[k], mantleUp);
					pole = Vector3.Slerp(_inward * 0.6f + mantleUp * 0.6f, _inward, Mathf.Clamp01((num4 - 0.4f) / 0.4f)) + val * (limb2.Side * 0.2f);
				}
				else
				{
					pole = _inward * 0.7f + val * (limb2.Side * 0.4f) - mantleUp * 0.1f;
				}
				float num5 = _weight * limb2.Weight;
				if (!(num5 <= 0f))
				{
					Vector3 target = _target[k] + val5 * (limb2.IsArm ? 0.04f : 0.06f);
					SolveTwoBone(limb2, target, pole, num5);
					limb2.Shown = limb2.End.position;
					if (limb2.IsArm && limb2.Planted)
					{
						OrientHand(limb2, val5, _inward, num5);
					}
				}
			}
			if (_mantleP >= 1f)
			{
				_mantling = false;
				_active = false;
				return false;
			}
			return true;
		}

		public static void Bind(ConfigFile config)
		{
			Enabled = config.Bind<bool>("Animation", "LimbPlacement", true, "Place hands and feet on the surface being climbed.");
			ShowTargets = config.Bind<bool>("Debug", "ShowLimbTargets", false, "Draw a marker at every hand and foot grip and the limbs as lines, and log the rig's state every frame.");
			BindBalance(config);
			BindAnatomy(config);
			BindSway(config);
			LogRig = config.Bind<bool>("Debug", "LogRig", false, "Write the rig's state to the log every frame.");
			SkinOffscreen = config.Bind<bool>("Debug", "SkinOffscreen", false, "Keep skinning the climbing player's meshes when no camera sees them, for recordings made with an off-screen camera.");
		}

		public static void Attach(Player player, Animator animator)
		{
			if (Enabled == null || Enabled.Value)
			{
				ClimbRig obj = ((Component)player).GetComponent<ClimbRig>() ?? ((Component)player).gameObject.AddComponent<ClimbRig>();
				obj.Setup(player, animator);
				obj._active = true;
				obj._mantleUntil = 0f;
				obj._exitOffsetLeft = 0f;
				obj._exitCapture = false;
				obj._exitGrace = 0f;
			}
		}

		public static void Release(Player player)
		{
			ClimbRig climbRig = (((Object)(object)player != (Object)null) ? ((Component)player).GetComponent<ClimbRig>() : null);
			if (!((Object)(object)climbRig == (Object)null) && !climbRig._mantling)
			{
				if (climbRig._active && (climbRig._topCrawl > 0.2f || climbRig.HandsOnTop() || climbRig.TopAhead(out var _)))
				{
					climbRig._mantleStart = Time.time;
					climbRig._crawlAtRelease = climbRig._topCrawl;
					climbRig._topCrawl = 0f;
					climbRig._mantleUntil = Time.time + 1.1f;
				}
				else
				{
					climbRig._active = false;
				}
			}
		}

		private float Crawl()
		{
			float num = 0f;
			if (Mantling)
			{
				float num2 = Mathf.Clamp01((Time.time - _mantleStart) / 1.1f);
				num = Mathf.Lerp(_crawlAtRelease, 1f, Mathf.SmoothStep(0f, 1f, num2 / 0.15f)) * (1f - Mathf.SmoothStep(0f, 1f, (num2 - 0.4f) / 0.55f));
			}
			return Mathf.Max(_topCrawl, num);
		}

		private void UpdateTopCrawl(float dt)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			float num = 0f;
			if (_active && !Mantling && (Object)(object)_hips != (Object)null && TopAhead(out var hit))
			{
				Transform transform = ((Component)_player).transform;
				float num2 = Vector3.Dot(transform.position + transform.up * 0.95f - ((RaycastHit)(ref hit)).point, transform.up);
				num = Mathf.SmoothStep(0f, 1f, (num2 - -0.05f) / 0.5f);
			}
			_topCrawl = Mathf.MoveTowards(_topCrawl, num, dt * 4f);
		}

		private bool TopAhead(out RaycastHit hit)
		{
			//IL_001e: 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)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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_0118: 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_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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)_player).transform;
			float[] topProbes = TopProbes;
			foreach (float num in topProbes)
			{
				Vector3 val = transform.position + transform.up * 2.2f + transform.forward * num;
				if (!Physics.CheckSphere(val, 0.05f, SurfaceMask, (QueryTriggerInteraction)1) && Physics.Raycast(val, -transform.up, ref hit, 2.6f, SurfaceMask, (QueryTriggerInteraction)1) && (Object)(object)((RaycastHit)(ref hit)).collider.attachedRigidbody != (Object)(object)_body && Vector3.Dot(((RaycastHit)(ref hit)).normal, transform.up) > 0.5f && Vector3.Dot(((RaycastHit)(ref hit)).normal, Vector3.up) > 0.6f && Vector3.Dot(((RaycastHit)(ref hit)).point - transform.position, transform.up) > -0.4f && ((RaycastHit)(ref hit)).point.y > _startHeight + 0.5f)
				{
					return true;
				}
			}
			hit = default(RaycastHit);
			return false;
		}

		private bool HandsOnTop()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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)
			Vector3 up = ((Component)_player).transform.up;
			for (int i = 0; i < 2; i++)
			{
				if (!_limbs[i].Planted || Vector3.Dot(_limbs[i].Moving ? _limbs[i].ToNormal : _limbs[i].GripNormal, up) < 0.5f)
				{
					return false;
				}
			}
			return true;
		}

		public static float CrawlAmount(Player player)
		{
			foreach (ClimbRig rig in Rigs)
			{
				if (rig._player == player)
				{
					if (!rig._ok)
					{
						return 0f;
					}
					return rig._mantling ? 1f : (rig.Crawl() * rig._weight);
				}
			}
			return 0f;
		}

		public static void RemoveAll()
		{
			ClimbRig[] array = Rigs.ToArray();
			foreach (ClimbRig climbRig in array)
			{
				if ((Object)(object)climbRig != (Object)null)
				{
					Object.Destroy((Object)(object)climbRig);
				}
			}
			Rigs.Clear();
		}

		private void OnEnable()
		{
			Rigs.Add(this);
		}

		private void OnDestroy()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			Rigs.Remove(this);
			if ((Object)(object)_visual != (Object)null)
			{
				_visual.localPosition = _visualRest;
			}
			Limb[] limbs = _limbs;
			foreach (Limb limb in limbs)
			{
				if ((Object)(object)limb?.Marker != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)limb.Marker).gameObject);
				}
			}
			if (_bones != null)
			{
				LineRenderer[] bones = _bones;
				foreach (LineRenderer val in bones)
				{
					if ((Object)(object)val != (Object)null)
					{
						Object.Destroy((Object)(object)((Component)val).gameObject);
					}
				}
			}
			if ((Object)(object)_cogMarker != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)_cogMarker).gameObject);
			}
		}

		private void Setup(Player player, Animator animator)
		{
			//IL_005c: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0394: Unknown result type (might be due to invalid IL or missing references)
			//IL_0399: Unknown result type (might be due to invalid IL or missing references)
			//IL_039e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03da: Unknown result type (might be due to invalid IL or missing references)
			//IL_03df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0402: Unknown result type (might be due to invalid IL or missing references)
			_player = player;
			_animator = animator;
			_body = ((Component)player).GetComponent<Rigidbody>();
			if ((Object)(object)_visual == (Object)null)
			{
				_visual = (((Object)(object)animator != (Object)null) ? ((Component)animator).transform : null);
				_visualRest = (((Object)(object)_visual != (Object)null) ? _visual.localPosition : Vector3.zero);
			}
			_ok = (Object)(object)animator != (Object)null && animator.isHuman;
			if (!_ok)
			{
				return;
			}
			if (SkinOffscreen != null && SkinOffscreen.Value)
			{
				SkinnedMeshRenderer[] componentsInChildren = ((Component)player).GetComponentsInChildren<SkinnedMeshRenderer>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					componentsInChildren[i].updateWhenOffscreen = true;
				}
			}
			_hips = animator.GetBoneTransform((HumanBodyBones)0);
			_chest = animator.GetBoneTransform((HumanBodyBones)54) ?? animator.GetBoneTransform((HumanBodyBones)8);
			_head = animator.GetBoneTransform((HumanBodyBones)10);
			_leftThigh = animator.GetBoneTransform((HumanBodyBones)1);
			_rightThigh = animator.GetBoneTransform((HumanBodyBones)2);
			_spine = Array.FindAll((Transform[])(object)new Transform[3]
			{
				animator.GetBoneTransform((HumanBodyBones)7),
				animator.GetBoneTransform((HumanBodyBones)8),
				animator.GetBoneTransform((HumanBodyBones)54)
			}, (Transform t) => (Object)(object)t != (Object)null);
			_limbs[0] = MakeLimb("LeftHand", arm: true, -1f, (HumanBodyBones)13, (HumanBodyBones)15, (HumanBodyBones)17);
			_limbs[1] = MakeLimb("RightHand", arm: true, 1f, (HumanBodyBones)14, (HumanBodyBones)16, (HumanBodyBones)18);
			_limbs[2] = MakeLimb("LeftFoot", arm: false, -1f, (HumanBodyBones)1, (HumanBodyBones)3, (HumanBodyBones)5);
			_limbs[3] = MakeLimb("RightFoot", arm: false, 1f, (HumanBodyBones)2, (HumanBodyBones)4, (HumanBodyBones)6);
			_limbs[0].Index = animator.GetBoneTransform((HumanBodyBones)27);
			_limbs[0].Middle = animator.GetBoneTransform((HumanBodyBones)30);
			_limbs[0].Little = animator.GetBoneTransform((HumanBodyBones)36);
			_limbs[1].Index = animator.GetBoneTransform((HumanBodyBones)42);
			_limbs[1].Middle = animator.GetBoneTransform((HumanBodyBones)45);
			_limbs[1].Little = animator.GetBoneTransform((HumanBodyBones)51);
			Limb[] limbs = _limbs;
			foreach (Limb limb in limbs)
			{
				if ((Object)(object)limb.Root == (Object)null || (Object)(object)limb.Mid == (Object)null || (Object)(object)limb.End == (Object)null)
				{
					_ok = false;
				}
			}
			if (!_ok)
			{
				return;
			}
			CaptureSkeleton(fresh: true);
			List<Transform> list = new List<Transform>(_spine)
			{
				animator.GetBoneTransform((HumanBodyBones)11),
				animator.GetBoneTransform((HumanBodyBones)12)
			};
			_torso = list.FindAll((Transform t) => (Object)(object)t != (Object)null).ToArray();
			_torsoHeld = (Quaternion[])(object)new Quaternion[_torso.Length];
			_steadyInit = false;
			if (LogRig != null && LogRig.Value && !_clipsDumped)
			{
				_clipsDumped = true;
				ClimbAnimationController.DumpClips(player);
			}
			SetupBalance(animator);
			if (_weight <= 0f)
			{
				limbs = _limbs;
				foreach (Limb limb2 in limbs)
				{
					limb2.Planted = false;
					limb2.Moving = false;
					limb2.Weight = 0f;
					limb2.FreeLocal = ((Component)player).transform.InverseTransformPoint(limb2.End.position);
					limb2.Held = false;
					limb2.Shown = limb2.End.position;
				}
				_lastPosition = ((Component)player).transform.position;
				_velocity = Vector3.zero;
				_topCrawl = 0f;
				ResetGait();
				ResetSway();
				_startHeight = ((Component)player).transform.position.y;
			}
		}

		private Limb MakeLimb(string name, bool arm, float side, HumanBodyBones root, HumanBodyBones mid, HumanBodyBones end)
		{
			//IL_004f: 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_0075: 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_00bd: Unknown result type (might be du