using System;
using System.Collections;
using Cpp2IlInjected;
using UnityEngine;

namespace RootMotion.FinalIK
{
	// Token: 0x020004B4 RID: 1204
	[Token(Token = "0x20004B4")]
	[RequireComponent(typeof(Animator))]
	public class RagdollUtility : MonoBehaviour
	{
		// Token: 0x06002AF7 RID: 10999 RVA: 0x00060130 File Offset: 0x0005E330
		[Token(Token = "0x6002AF7")]
		[Address(RVA = "0xEC08C0", Offset = "0xEBF8C0", VA = "0x180EC08C0")]
		public void EnableRagdoll()
		{
			if (this.rigidbones[0].r.isKinematic || this.animator.enabled)
			{
				base.StopAllCoroutines();
				this.enableRagdollFlag = true;
			}
		}

		// Token: 0x06002AF8 RID: 11000 RVA: 0x00060178 File Offset: 0x0005E378
		[Token(Token = "0x6002AF8")]
		[Address(RVA = "0xEC0770", Offset = "0xEBF770", VA = "0x180EC0770")]
		public void DisableRagdoll()
		{
			if (!this.rigidbones[0].r.isKinematic && !this.animator.enabled)
			{
				RagdollUtility.Child[] array = this.children;
				int num = 0;
				int length = array.Length;
				if (num < length)
				{
					array[num].StoreLocalState();
					num++;
				}
				base.StopAllCoroutines();
				int num2;
				RagdollUtility.<DisableRagdollSmooth>d__21 <DisableRagdollSmooth>d__ = new RagdollUtility.<DisableRagdollSmooth>d__21(num2);
				num2 = 0;
				<DisableRagdollSmooth>d__.<>4__this = this;
				Coroutine coroutine = base.StartCoroutine(<DisableRagdollSmooth>d__);
			}
		}

		// Token: 0x06002AF9 RID: 11001 RVA: 0x000020D3 File Offset: 0x000002D3
		[Token(Token = "0x6002AF9")]
		[Address(RVA = "0xEC1130", Offset = "0xEC0130", VA = "0x180EC1130")]
		public void Start()
		{
			throw new AnalysisFailedException("CPP2IL failed to recover any usable IL for this method.");
		}

		// Token: 0x06002AFA RID: 11002 RVA: 0x000020D3 File Offset: 0x000002D3
		[Token(Token = "0x6002AFA")]
		[Address(RVA = "0xEC0700", Offset = "0xEBF700", VA = "0x180EC0700")]
		private IEnumerator DisableRagdollSmooth()
		{
			throw new AnalysisFailedException("CPP2IL failed to recover any usable IL for this method.");
		}

		// Token: 0x06002AFB RID: 11003 RVA: 0x000020D3 File Offset: 0x000002D3
		[Token(Token = "0x6002AFB")]
		[Address(RVA = "0xEC16A0", Offset = "0xEC06A0", VA = "0x180EC16A0")]
		private void Update()
		{
			throw new AnalysisFailedException("CPP2IL failed to recover any usable IL for this method.");
		}

		// Token: 0x06002AFC RID: 11004 RVA: 0x000601F8 File Offset: 0x0005E3F8
		[Token(Token = "0x6002AFC")]
		[Address(RVA = "0xEC09B0", Offset = "0xEBF9B0", VA = "0x180EC09B0")]
		private void FixedUpdate()
		{
			if (!this.rigidbones[0].r.isKinematic)
			{
				bool enabled = this.animator.enabled;
				if (!enabled && this.applyIkOnRagdoll != enabled)
				{
					this.FixTransforms(1f);
				}
			}
			this.fixedFrame = true;
		}

		// Token: 0x06002AFD RID: 11005 RVA: 0x00060250 File Offset: 0x0005E450
		[Token(Token = "0x6002AFD")]
		[Address(RVA = "0xEC0A40", Offset = "0xEBFA40", VA = "0x180EC0A40")]
		private void LateUpdate()
		{
			if (this.animator.updateMode != AnimatorUpdateMode.AnimatePhysics || (this.animator.updateMode == AnimatorUpdateMode.AnimatePhysics && this.fixedFrame))
			{
				if (!this.rigidbones[0].r.isKinematic && !this.animator.enabled)
				{
					RagdollUtility.Child[] array = this.children;
					int num = 0;
					int length = array.Length;
					if (num >= length)
					{
						goto IL_7E;
					}
					array[num].StoreLocalState();
					num++;
				}
				float num2 = this.ragdollWeight;
				this.FixTransforms(num2);
			}
			IL_7E:
			this.fixedFrame = false;
			if (!this.ikUsed)
			{
				this.OnFinalPose();
			}
		}

		// Token: 0x06002AFE RID: 11006 RVA: 0x000602F8 File Offset: 0x0005E4F8
		[Token(Token = "0x6002AFE")]
		[Address(RVA = "0xEC06D0", Offset = "0xEBF6D0", VA = "0x180EC06D0")]
		private void AfterLastIK()
		{
			if (this.ikUsed)
			{
				this.OnFinalPose();
				return;
			}
		}

		// Token: 0x06002AFF RID: 11007 RVA: 0x00060318 File Offset: 0x0005E518
		[Token(Token = "0x6002AFF")]
		[Address(RVA = "0xEC0600", Offset = "0xEBF600", VA = "0x180EC0600")]
		private void AfterAnimation()
		{
			if (!this.rigidbones[0].r.isKinematic && !this.animator.enabled)
			{
				RagdollUtility.Child[] array = this.children;
				int num = 0;
				int length = array.Length;
				if (num >= length)
				{
					return;
				}
				array[num].StoreLocalState();
				num++;
			}
			float num2 = this.ragdollWeight;
			this.FixTransforms(num2);
		}

		// Token: 0x06002B00 RID: 11008 RVA: 0x00060384 File Offset: 0x0005E584
		[Token(Token = "0x6002B00")]
		[Address(RVA = "0xEC0CB0", Offset = "0xEBFCB0", VA = "0x180EC0CB0")]
		private void OnFinalPose()
		{
			if (this.rigidbones[0].r.isKinematic || this.animator.enabled)
			{
				RagdollUtility.Rigidbone[] array = this.rigidbones;
				int num = 0;
				int length = array.Length;
				if (num < length)
				{
					array[num].RecordVelocity();
					num++;
				}
			}
			if (this.enableRagdollFlag)
			{
				this.RagdollEnabler();
			}
		}

		// Token: 0x06002B01 RID: 11009 RVA: 0x000020D3 File Offset: 0x000002D3
		[Token(Token = "0x6002B01")]
		[Address(RVA = "0xEC0D90", Offset = "0xEBFD90", VA = "0x180EC0D90")]
		private void RagdollEnabler()
		{
			throw new AnalysisFailedException("CPP2IL failed to recover any usable IL for this method.");
		}

		// Token: 0x170002AA RID: 682
		// (get) Token: 0x06002B02 RID: 11010 RVA: 0x000020D3 File Offset: 0x000002D3
		[Token(Token = "0x170002AA")]
		private bool isRagdoll
		{
			[Token(Token = "0x6002B02")]
			[Address(RVA = "0xEC1C80", Offset = "0xEC0C80", VA = "0x180EC1C80")]
			get
			{
				throw new AnalysisFailedException("CPP2IL failed to recover any usable IL for this method.");
			}
		}

		// Token: 0x06002B03 RID: 11011 RVA: 0x000603F4 File Offset: 0x0005E5F4
		[Token(Token = "0x6002B03")]
		[Address(RVA = "0xEC10D0", Offset = "0xEC00D0", VA = "0x180EC10D0")]
		private void RecordVelocities()
		{
			RagdollUtility.Rigidbone[] array = this.rigidbones;
			int num = 0;
			int length = array.Length;
			if (num < length)
			{
				array[num].RecordVelocity();
				num++;
			}
		}

		// Token: 0x170002AB RID: 683
		// (get) Token: 0x06002B04 RID: 11012 RVA: 0x000020D3 File Offset: 0x000002D3
		[Token(Token = "0x170002AB")]
		private bool ikUsed
		{
			[Token(Token = "0x6002B04")]
			[Address(RVA = "0xEC1B30", Offset = "0xEC0B30", VA = "0x180EC1B30")]
			get
			{
				throw new AnalysisFailedException("CPP2IL failed to recover any usable IL for this method.");
			}
		}

		// Token: 0x06002B05 RID: 11013 RVA: 0x0006042C File Offset: 0x0005E62C
		[Token(Token = "0x6002B05")]
		[Address(RVA = "0xEC1640", Offset = "0xEC0640", VA = "0x180EC1640")]
		private void StoreLocalState()
		{
			RagdollUtility.Child[] array = this.children;
			int num = 0;
			int length = array.Length;
			if (num < length)
			{
				array[num].StoreLocalState();
				num++;
			}
		}

		// Token: 0x06002B06 RID: 11014 RVA: 0x00060464 File Offset: 0x0005E664
		[Token(Token = "0x6002B06")]
		[Address(RVA = "0xEC0940", Offset = "0xEBF940", VA = "0x180EC0940")]
		private void FixTransforms(float weight)
		{
			RagdollUtility.Child[] array = this.children;
			int num = 0;
			int length = array.Length;
			if (num < length)
			{
				array[num].FixTransform(weight);
				num++;
			}
		}

		// Token: 0x06002B07 RID: 11015 RVA: 0x0006049C File Offset: 0x0005E69C
		[Token(Token = "0x6002B07")]
		[Address(RVA = "0xEC0B80", Offset = "0xEBFB80", VA = "0x180EC0B80")]
		private void OnDestroy()
		{
			IK ik = this.ik;
			int num = 0;
			if (ik != num)
			{
				IKSolver iksolver = this.ik.GetIKSolver();
				IKSolver.UpdateDelegate onPostUpdate = iksolver.OnPostUpdate;
				IKSolver.UpdateDelegate updateDelegate = new IKSolver.UpdateDelegate(this.AfterLastIK);
				Delegate @delegate = Delegate.Remove(onPostUpdate, updateDelegate);
				int num2 = 0;
				if (@delegate != 0 && @delegate == 0)
				{
					throw new InvalidCastException();
				}
				iksolver.OnPostUpdate = num2;
			}
		}

		// Token: 0x06002B08 RID: 11016 RVA: 0x00060508 File Offset: 0x0005E708
		[Token(Token = "0x6002B08")]
		[Address(RVA = "0xEC1A30", Offset = "0xEC0A30", VA = "0x180EC1A30")]
		public RagdollUtility()
		{
			int num = 0;
			this.applyVelocity = 1f;
			this.applyAngularVelocity = 1f;
			RagdollUtility.Rigidbone[] array = new RagdollUtility.Rigidbone[num];
			this.rigidbones = array;
			RagdollUtility.Child[] array2 = new RagdollUtility.Child[0];
			this.children = array2;
			IK[] array3 = new IK[0];
			this.allIKComponents = array3;
			bool[] array4 = new bool[0];
			this.fixTransforms = array4;
			bool[] array5 = new bool[0];
			this.disabledIKComponents = array5;
			base..ctor();
		}

		// Token: 0x04003474 RID: 13428
		[FieldOffset(Offset = "0x18")]
		[Token(Token = "0x4003474")]
		[Tooltip("If you have multiple IK components, then this should be the one that solves last each frame.")]
		public IK ik;

		// Token: 0x04003475 RID: 13429
		[FieldOffset(Offset = "0x20")]
		[Token(Token = "0x4003475")]
		[Tooltip("How long does it take to blend from ragdoll to animation?")]
		public float ragdollToAnimationTime = 0.2f;

		// Token: 0x04003476 RID: 13430
		[FieldOffset(Offset = "0x24")]
		[Token(Token = "0x4003476")]
		[Tooltip("If true, IK can be used on top of physical ragdoll simulation.")]
		public bool applyIkOnRagdoll;

		// Token: 0x04003477 RID: 13431
		[FieldOffset(Offset = "0x28")]
		[Token(Token = "0x4003477")]
		[Tooltip("How much velocity transfer from animation to ragdoll?")]
		public float applyVelocity;

		// Token: 0x04003478 RID: 13432
		[FieldOffset(Offset = "0x2C")]
		[Token(Token = "0x4003478")]
		[Tooltip("How much angular velocity to transfer from animation to ragdoll?")]
		public float applyAngularVelocity;

		// Token: 0x04003479 RID: 13433
		[FieldOffset(Offset = "0x30")]
		[Token(Token = "0x4003479")]
		private Animator animator;

		// Token: 0x0400347A RID: 13434
		[FieldOffset(Offset = "0x38")]
		[Token(Token = "0x400347A")]
		private RagdollUtility.Rigidbone[] rigidbones;

		// Token: 0x0400347B RID: 13435
		[FieldOffset(Offset = "0x40")]
		[Token(Token = "0x400347B")]
		private RagdollUtility.Child[] children;

		// Token: 0x0400347C RID: 13436
		[FieldOffset(Offset = "0x48")]
		[Token(Token = "0x400347C")]
		private bool enableRagdollFlag;

		// Token: 0x0400347D RID: 13437
		[FieldOffset(Offset = "0x4C")]
		[Token(Token = "0x400347D")]
		private AnimatorUpdateMode animatorUpdateMode;

		// Token: 0x0400347E RID: 13438
		[FieldOffset(Offset = "0x50")]
		[Token(Token = "0x400347E")]
		private IK[] allIKComponents;

		// Token: 0x0400347F RID: 13439
		[FieldOffset(Offset = "0x58")]
		[Token(Token = "0x400347F")]
		private bool[] fixTransforms;

		// Token: 0x04003480 RID: 13440
		[FieldOffset(Offset = "0x60")]
		[Token(Token = "0x4003480")]
		private float ragdollWeight;

		// Token: 0x04003481 RID: 13441
		[FieldOffset(Offset = "0x64")]
		[Token(Token = "0x4003481")]
		private float ragdollWeightV;

		// Token: 0x04003482 RID: 13442
		[FieldOffset(Offset = "0x68")]
		[Token(Token = "0x4003482")]
		private bool fixedFrame;

		// Token: 0x04003483 RID: 13443
		[FieldOffset(Offset = "0x70")]
		[Token(Token = "0x4003483")]
		private bool[] disabledIKComponents;

		// Token: 0x020004B5 RID: 1205
		[Token(Token = "0x20004B5")]
		public class Rigidbone
		{
			// Token: 0x06002B09 RID: 11017 RVA: 0x000020D3 File Offset: 0x000002D3
			[Token(Token = "0x6002B09")]
			[Address(RVA = "0x69CF80", Offset = "0x69BF80", VA = "0x18069CF80")]
			public Rigidbone(Rigidbody r)
			{
				throw new AnalysisFailedException("CPP2IL failed to recover any usable IL for this method.");
			}

			// Token: 0x06002B0A RID: 11018 RVA: 0x000020D3 File Offset: 0x000002D3
			[Token(Token = "0x6002B0A")]
			[Address(RVA = "0x69CBB0", Offset = "0x69BBB0", VA = "0x18069CBB0")]
			public void RecordVelocity()
			{
				throw new AnalysisFailedException("CPP2IL failed to recover any usable IL for this method.");
			}

			// Token: 0x06002B0B RID: 11019 RVA: 0x000020D3 File Offset: 0x000002D3
			[Token(Token = "0x6002B0B")]
			[Address(RVA = "0x69CCF0", Offset = "0x69BCF0", VA = "0x18069CCF0")]
			public void WakeUp(float velocityWeight, float angularVelocityWeight)
			{
				throw new AnalysisFailedException("CPP2IL failed to recover any usable IL for this method.");
			}

			// Token: 0x04003484 RID: 13444
			[FieldOffset(Offset = "0x10")]
			[Token(Token = "0x4003484")]
			public Rigidbody r;

			// Token: 0x04003485 RID: 13445
			[FieldOffset(Offset = "0x18")]
			[Token(Token = "0x4003485")]
			public Transform t;

			// Token: 0x04003486 RID: 13446
			[FieldOffset(Offset = "0x20")]
			[Token(Token = "0x4003486")]
			public Collider collider;

			// Token: 0x04003487 RID: 13447
			[FieldOffset(Offset = "0x28")]
			[Token(Token = "0x4003487")]
			public Joint joint;

			// Token: 0x04003488 RID: 13448
			[FieldOffset(Offset = "0x30")]
			[Token(Token = "0x4003488")]
			public Rigidbody c;

			// Token: 0x04003489 RID: 13449
			[FieldOffset(Offset = "0x38")]
			[Token(Token = "0x4003489")]
			public bool updateAnchor;

			// Token: 0x0400348A RID: 13450
			[FieldOffset(Offset = "0x3C")]
			[Token(Token = "0x400348A")]
			public Vector3 deltaPosition;

			// Token: 0x0400348B RID: 13451
			[FieldOffset(Offset = "0x48")]
			[Token(Token = "0x400348B")]
			public Quaternion deltaRotation;

			// Token: 0x0400348C RID: 13452
			[FieldOffset(Offset = "0x58")]
			[Token(Token = "0x400348C")]
			public float deltaTime;

			// Token: 0x0400348D RID: 13453
			[FieldOffset(Offset = "0x5C")]
			[Token(Token = "0x400348D")]
			public Vector3 lastPosition;

			// Token: 0x0400348E RID: 13454
			[FieldOffset(Offset = "0x68")]
			[Token(Token = "0x400348E")]
			public Quaternion lastRotation;
		}

		// Token: 0x020004B6 RID: 1206
		[Token(Token = "0x20004B6")]
		public class Child
		{
			// Token: 0x06002B0C RID: 11020 RVA: 0x000020D3 File Offset: 0x000002D3
			[Token(Token = "0x6002B0C")]
			[Address(RVA = "0x697720", Offset = "0x696720", VA = "0x180697720")]
			public Child(Transform transform)
			{
				throw new AnalysisFailedException("CPP2IL failed to recover any usable IL for this method.");
			}

			// Token: 0x06002B0D RID: 11021 RVA: 0x000020D3 File Offset: 0x000002D3
			[Token(Token = "0x6002B0D")]
			[Address(RVA = "0x697500", Offset = "0x696500", VA = "0x180697500")]
			public void FixTransform(float weight)
			{
				throw new AnalysisFailedException("CPP2IL failed to recover any usable IL for this method.");
			}

			// Token: 0x06002B0E RID: 11022 RVA: 0x000020D3 File Offset: 0x000002D3
			[Token(Token = "0x6002B0E")]
			[Address(RVA = "0x6976C0", Offset = "0x6966C0", VA = "0x1806976C0")]
			public void StoreLocalState()
			{
				throw new AnalysisFailedException("CPP2IL failed to recover any usable IL for this method.");
			}

			// Token: 0x0400348F RID: 13455
			[FieldOffset(Offset = "0x10")]
			[Token(Token = "0x400348F")]
			public Transform t;

			// Token: 0x04003490 RID: 13456
			[FieldOffset(Offset = "0x18")]
			[Token(Token = "0x4003490")]
			public Vector3 localPosition;

			// Token: 0x04003491 RID: 13457
			[FieldOffset(Offset = "0x24")]
			[Token(Token = "0x4003491")]
			public Quaternion localRotation;
		}
	}
}
