Decompiled source of BeastTribes Reimagined v1.2.1

BeastTribesFixesMod.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: AssemblyCompany("BeastTribesFixesMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+c66b62a0cdb84daf723c02019d0d17930f208874")]
[assembly: AssemblyProduct("BeastTribesFixesMod")]
[assembly: AssemblyTitle("BeastTribesFixesMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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;
		}
	}
}
[AddComponentMenu("Dynamic Bone/Dynamic Bone")]
public class DynamicBone : MonoBehaviour
{
	public enum UpdateMode
	{
		Normal,
		AnimatePhysics,
		UnscaledTime,
		Default
	}

	public enum FreezeAxis
	{
		None,
		X,
		Y,
		Z
	}

	private class Particle
	{
		public Transform m_Transform;

		public int m_ParentIndex;

		public int m_ChildCount;

		public float m_Damping;

		public float m_Elasticity;

		public float m_Stiffness;

		public float m_Inert;

		public float m_Friction;

		public float m_Radius;

		public float m_BoneLength;

		public bool m_isCollide;

		public bool m_TransformNotNull;

		public Vector3 m_Position;

		public Vector3 m_PrevPosition;

		public Vector3 m_EndOffset;

		public Vector3 m_InitLocalPosition;

		public Quaternion m_InitLocalRotation;

		public Vector3 m_TransformPosition;

		public Vector3 m_TransformLocalPosition;

		public Matrix4x4 m_TransformLocalToWorldMatrix;
	}

	private class ParticleTree
	{
		public Transform m_Root;

		public Vector3 m_LocalGravity;

		public Matrix4x4 m_RootWorldToLocalMatrix;

		public float m_BoneTotalLength;

		public List<Particle> m_Particles = new List<Particle>();

		public Vector3 m_RestGravity;
	}

	[Tooltip("The roots of the transform hierarchy to apply physics.")]
	public Transform m_Root;

	public List<Transform> m_Roots;

	[Tooltip("Internal physics simulation rate.")]
	public float m_UpdateRate = 60f;

	public UpdateMode m_UpdateMode = UpdateMode.Default;

	[Tooltip("How much the bones slowed down.")]
	[Range(0f, 1f)]
	public float m_Damping = 0.1f;

	public AnimationCurve m_DampingDistrib;

	[Tooltip("How much the force applied to return each bone to original orientation.")]
	[Range(0f, 1f)]
	public float m_Elasticity = 0.1f;

	public AnimationCurve m_ElasticityDistrib;

	[Tooltip("How much bone's original orientation are preserved.")]
	[Range(0f, 1f)]
	public float m_Stiffness = 0.1f;

	public AnimationCurve m_StiffnessDistrib;

	[Tooltip("How much character's position change is ignored in physics simulation.")]
	[Range(0f, 1f)]
	public float m_Inert;

	public AnimationCurve m_InertDistrib;

	[Tooltip("How much the bones slowed down when collide.")]
	public float m_Friction;

	public AnimationCurve m_FrictionDistrib;

	[Tooltip("Each bone can be a sphere to collide with colliders. Radius describe sphere's size.")]
	public float m_Radius;

	public AnimationCurve m_RadiusDistrib;

	[Tooltip("If End Length is not zero, an extra bone is generated at the end of transform hierarchy.")]
	public float m_EndLength;

	[Tooltip("If End Offset is not zero, an extra bone is generated at the end of transform hierarchy.")]
	public Vector3 m_EndOffset = Vector3.zero;

	[Tooltip("The force apply to bones. Partial force apply to character's initial pose is cancelled out.")]
	public Vector3 m_Gravity = Vector3.zero;

	[Tooltip("The force apply to bones.")]
	public Vector3 m_Force = Vector3.zero;

	[Tooltip("Control how physics blends with existing animation.")]
	[Range(0f, 1f)]
	public float m_BlendWeight = 1f;

	[Tooltip("Collider objects interact with the bones.")]
	public List<DynamicBoneColliderBase> m_Colliders;

	[Tooltip("Bones exclude from physics simulation.")]
	public List<Transform> m_Exclusions;

	[Tooltip("Constrain bones to move on specified plane.")]
	public FreezeAxis m_FreezeAxis;

	[Tooltip("Disable physics simulation automatically if character is far from camera or player.")]
	public bool m_DistantDisable;

	public Transform m_ReferenceObject;

	public float m_DistanceToObject = 20f;

	[HideInInspector]
	public bool m_Multithread = true;

	private Vector3 m_ObjectMove;

	private Vector3 m_ObjectPrevPosition;

	private float m_ObjectScale;

	private float m_Time;

	private float m_Weight = 1f;

	private bool m_DistantDisabled;

	private int m_PreUpdateCount;

	private List<ParticleTree> m_ParticleTrees = new List<ParticleTree>();

	private float m_DeltaTime;

	private List<DynamicBoneColliderBase> m_EffectiveColliders;

	private bool m_WorkAdded;

	private static List<DynamicBone> s_PendingWorks = new List<DynamicBone>();

	private static List<DynamicBone> s_EffectiveWorks = new List<DynamicBone>();

	private static AutoResetEvent s_AllWorksDoneEvent;

	private static int s_RemainWorkCount;

	private static Semaphore s_WorkQueueSemaphore;

	private static int s_WorkQueueIndex;

	private static int s_UpdateCount;

	private static int s_PrepareFrame;

	private void Start()
	{
		SetupParticles();
	}

	private void FixedUpdate()
	{
		if (m_UpdateMode == UpdateMode.AnimatePhysics)
		{
			PreUpdate();
		}
	}

	private void Update()
	{
		if (m_UpdateMode != UpdateMode.AnimatePhysics)
		{
			PreUpdate();
		}
		if (m_PreUpdateCount > 0 && m_Multithread)
		{
			AddPendingWork(this);
			m_WorkAdded = true;
		}
		s_UpdateCount++;
	}

	private void LateUpdate()
	{
		if (m_PreUpdateCount == 0)
		{
			return;
		}
		if (s_UpdateCount > 0)
		{
			s_UpdateCount = 0;
			s_PrepareFrame++;
		}
		SetWeight(m_BlendWeight);
		if (m_WorkAdded)
		{
			m_WorkAdded = false;
			ExecuteWorks();
		}
		else
		{
			CheckDistance();
			if (IsNeedUpdate())
			{
				Prepare();
				UpdateParticles();
				ApplyParticlesToTransforms();
			}
		}
		m_PreUpdateCount = 0;
	}

	private void Prepare()
	{
		//IL_0044: 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_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: 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_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)
		m_DeltaTime = Time.deltaTime;
		if (m_UpdateMode == UpdateMode.UnscaledTime)
		{
			m_DeltaTime = Time.unscaledDeltaTime;
		}
		else if (m_UpdateMode == UpdateMode.AnimatePhysics)
		{
			m_DeltaTime = Time.fixedDeltaTime * (float)m_PreUpdateCount;
		}
		m_ObjectScale = Mathf.Abs(((Component)this).transform.lossyScale.x);
		m_ObjectMove = ((Component)this).transform.position - m_ObjectPrevPosition;
		m_ObjectPrevPosition = ((Component)this).transform.position;
		for (int i = 0; i < m_ParticleTrees.Count; i++)
		{
			ParticleTree particleTree = m_ParticleTrees[i];
			particleTree.m_RestGravity = particleTree.m_Root.TransformDirection(particleTree.m_LocalGravity);
			for (int j = 0; j < particleTree.m_Particles.Count; j++)
			{
				Particle particle = particleTree.m_Particles[j];
				if (particle.m_TransformNotNull)
				{
					particle.m_TransformPosition = particle.m_Transform.position;
					particle.m_TransformLocalPosition = particle.m_Transform.localPosition;
					particle.m_TransformLocalToWorldMatrix = particle.m_Transform.localToWorldMatrix;
				}
			}
		}
		if (m_EffectiveColliders != null)
		{
			m_EffectiveColliders.Clear();
		}
		if (m_Colliders == null)
		{
			return;
		}
		for (int k = 0; k < m_Colliders.Count; k++)
		{
			DynamicBoneColliderBase dynamicBoneColliderBase = m_Colliders[k];
			if ((Object)(object)dynamicBoneColliderBase != (Object)null && ((Behaviour)dynamicBoneColliderBase).enabled)
			{
				if (m_EffectiveColliders == null)
				{
					m_EffectiveColliders = new List<DynamicBoneColliderBase>();
				}
				m_EffectiveColliders.Add(dynamicBoneColliderBase);
				if (dynamicBoneColliderBase.PrepareFrame != s_PrepareFrame)
				{
					dynamicBoneColliderBase.Prepare();
					dynamicBoneColliderBase.PrepareFrame = s_PrepareFrame;
				}
			}
		}
	}

	private bool IsNeedUpdate()
	{
		if (m_Weight > 0f)
		{
			if (m_DistantDisable)
			{
				return !m_DistantDisabled;
			}
			return true;
		}
		return false;
	}

	private void PreUpdate()
	{
		if (IsNeedUpdate())
		{
			InitTransforms();
		}
		m_PreUpdateCount++;
	}

	private void CheckDistance()
	{
		//IL_003b: 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)
		if (!m_DistantDisable)
		{
			return;
		}
		Transform val = m_ReferenceObject;
		if ((Object)(object)val == (Object)null && (Object)(object)Camera.main != (Object)null)
		{
			val = ((Component)Camera.main).transform;
		}
		if (!((Object)(object)val != (Object)null))
		{
			return;
		}
		Vector3 val2 = val.position - ((Component)this).transform.position;
		bool flag = ((Vector3)(ref val2)).sqrMagnitude > m_DistanceToObject * m_DistanceToObject;
		if (flag != m_DistantDisabled)
		{
			if (!flag)
			{
				ResetParticlesPosition();
			}
			m_DistantDisabled = flag;
		}
	}

	private void OnEnable()
	{
		ResetParticlesPosition();
	}

	private void OnDisable()
	{
		InitTransforms();
	}

	private void OnValidate()
	{
		m_UpdateRate = Mathf.Max(m_UpdateRate, 0f);
		m_Damping = Mathf.Clamp01(m_Damping);
		m_Elasticity = Mathf.Clamp01(m_Elasticity);
		m_Stiffness = Mathf.Clamp01(m_Stiffness);
		m_Inert = Mathf.Clamp01(m_Inert);
		m_Friction = Mathf.Clamp01(m_Friction);
		m_Radius = Mathf.Max(m_Radius, 0f);
		if (Application.isEditor && Application.isPlaying)
		{
			if (IsRootChanged())
			{
				InitTransforms();
				SetupParticles();
			}
			else
			{
				UpdateParameters();
			}
		}
	}

	private bool IsRootChanged()
	{
		List<Transform> list = new List<Transform>();
		if ((Object)(object)m_Root != (Object)null)
		{
			list.Add(m_Root);
		}
		if (m_Roots != null)
		{
			foreach (Transform root in m_Roots)
			{
				if ((Object)(object)root != (Object)null && !list.Contains(root))
				{
					list.Add(root);
				}
			}
		}
		if (list.Count != m_ParticleTrees.Count)
		{
			return true;
		}
		for (int i = 0; i < list.Count; i++)
		{
			if ((Object)(object)list[i] != (Object)(object)m_ParticleTrees[i].m_Root)
			{
				return true;
			}
		}
		return false;
	}

	private void OnDidApplyAnimationProperties()
	{
		UpdateParameters();
	}

	private void OnDrawGizmosSelected()
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		if (((Behaviour)this).enabled)
		{
			if (Application.isEditor && !Application.isPlaying && ((Component)this).transform.hasChanged)
			{
				SetupParticles();
			}
			Gizmos.color = Color.white;
			for (int i = 0; i < m_ParticleTrees.Count; i++)
			{
				DrawGizmos(m_ParticleTrees[i]);
			}
		}
	}

	private void DrawGizmos(ParticleTree pt)
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < pt.m_Particles.Count; i++)
		{
			Particle particle = pt.m_Particles[i];
			if (particle.m_ParentIndex >= 0)
			{
				Particle particle2 = pt.m_Particles[particle.m_ParentIndex];
				Gizmos.DrawLine(particle.m_Position, particle2.m_Position);
			}
			if (particle.m_Radius > 0f)
			{
				Gizmos.DrawWireSphere(particle.m_Position, particle.m_Radius * m_ObjectScale);
			}
		}
	}

	public void SetWeight(float w)
	{
		if (m_Weight != w)
		{
			if (w == 0f)
			{
				InitTransforms();
			}
			else if (m_Weight == 0f)
			{
				ResetParticlesPosition();
			}
			m_Weight = (m_BlendWeight = w);
		}
	}

	public float GetWeight()
	{
		return m_Weight;
	}

	private void UpdateParticles()
	{
		if (m_ParticleTrees.Count <= 0)
		{
			return;
		}
		int num = 1;
		float timeVar = 1f;
		float deltaTime = m_DeltaTime;
		if (m_UpdateMode == UpdateMode.Default)
		{
			if (m_UpdateRate > 0f)
			{
				timeVar = deltaTime * m_UpdateRate;
			}
		}
		else if (m_UpdateRate > 0f)
		{
			float num2 = 1f / m_UpdateRate;
			m_Time += deltaTime;
			num = 0;
			while (m_Time >= num2)
			{
				m_Time -= num2;
				if (++num >= 3)
				{
					m_Time = 0f;
					break;
				}
			}
		}
		if (num > 0)
		{
			for (int i = 0; i < num; i++)
			{
				UpdateParticles1(timeVar, i);
				UpdateParticles2(timeVar);
			}
		}
		else
		{
			SkipUpdateParticles();
		}
	}

	public void SetupParticles()
	{
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: 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)
		m_ParticleTrees.Clear();
		if ((Object)(object)m_Root != (Object)null)
		{
			AppendParticleTree(m_Root);
		}
		if (m_Roots != null)
		{
			for (int i = 0; i < m_Roots.Count; i++)
			{
				Transform root = m_Roots[i];
				if (!((Object)(object)root == (Object)null) && !m_ParticleTrees.Exists((ParticleTree x) => (Object)(object)x.m_Root == (Object)(object)root))
				{
					AppendParticleTree(root);
				}
			}
		}
		m_ObjectScale = Mathf.Abs(((Component)this).transform.lossyScale.x);
		m_ObjectPrevPosition = ((Component)this).transform.position;
		m_ObjectMove = Vector3.zero;
		for (int num = 0; num < m_ParticleTrees.Count; num++)
		{
			ParticleTree particleTree = m_ParticleTrees[num];
			AppendParticles(particleTree, particleTree.m_Root, -1, 0f);
		}
		UpdateParameters();
	}

	private void AppendParticleTree(Transform root)
	{
		//IL_0019: 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)
		if (!((Object)(object)root == (Object)null))
		{
			ParticleTree particleTree = new ParticleTree();
			particleTree.m_Root = root;
			particleTree.m_RootWorldToLocalMatrix = root.worldToLocalMatrix;
			m_ParticleTrees.Add(particleTree);
		}
	}

	private void AppendParticles(ParticleTree pt, Transform b, int parentIndex, float boneLength)
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: 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_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_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)
		//IL_011d: 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_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: 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_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: 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_00ab: 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_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: 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_024d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0252: Unknown result type (might be due to invalid IL or missing references)
		//IL_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0210: Unknown result type (might be due to invalid IL or missing references)
		Particle particle = new Particle();
		particle.m_Transform = b;
		particle.m_TransformNotNull = (Object)(object)b != (Object)null;
		particle.m_ParentIndex = parentIndex;
		Vector3 val;
		if ((Object)(object)b != (Object)null)
		{
			val = (particle.m_Position = (particle.m_PrevPosition = b.position));
			particle.m_InitLocalPosition = b.localPosition;
			particle.m_InitLocalRotation = b.localRotation;
		}
		else
		{
			Transform transform = pt.m_Particles[parentIndex].m_Transform;
			if (m_EndLength > 0f)
			{
				Transform parent = transform.parent;
				if ((Object)(object)parent != (Object)null)
				{
					particle.m_EndOffset = transform.InverseTransformPoint(transform.position * 2f - parent.position) * m_EndLength;
				}
				else
				{
					particle.m_EndOffset = new Vector3(m_EndLength, 0f, 0f);
				}
			}
			else
			{
				particle.m_EndOffset = transform.InverseTransformPoint(((Component)this).transform.TransformDirection(m_EndOffset) + transform.position);
			}
			val = (particle.m_Position = (particle.m_PrevPosition = transform.TransformPoint(particle.m_EndOffset)));
			particle.m_InitLocalPosition = Vector3.zero;
			particle.m_InitLocalRotation = Quaternion.identity;
		}
		if (parentIndex >= 0)
		{
			float num = boneLength;
			val = pt.m_Particles[parentIndex].m_Transform.position - particle.m_Position;
			boneLength = num + ((Vector3)(ref val)).magnitude;
			particle.m_BoneLength = boneLength;
			pt.m_BoneTotalLength = Mathf.Max(pt.m_BoneTotalLength, boneLength);
			pt.m_Particles[parentIndex].m_ChildCount++;
		}
		int count = pt.m_Particles.Count;
		pt.m_Particles.Add(particle);
		if (!((Object)(object)b != (Object)null))
		{
			return;
		}
		for (int i = 0; i < b.childCount; i++)
		{
			Transform child = b.GetChild(i);
			bool flag = false;
			if (m_Exclusions != null)
			{
				flag = m_Exclusions.Contains(child);
			}
			if (!flag)
			{
				AppendParticles(pt, child, count, boneLength);
			}
			else if (m_EndLength > 0f || m_EndOffset != Vector3.zero)
			{
				AppendParticles(pt, null, count, boneLength);
			}
		}
		if (b.childCount == 0 && (m_EndLength > 0f || m_EndOffset != Vector3.zero))
		{
			AppendParticles(pt, null, count, boneLength);
		}
	}

	public void UpdateParameters()
	{
		SetWeight(m_BlendWeight);
		for (int i = 0; i < m_ParticleTrees.Count; i++)
		{
			UpdateParameters(m_ParticleTrees[i]);
		}
	}

	private void UpdateParameters(ParticleTree pt)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		Vector3 val = ((Matrix4x4)(ref pt.m_RootWorldToLocalMatrix)).MultiplyVector(m_Gravity);
		pt.m_LocalGravity = ((Vector3)(ref val)).normalized * ((Vector3)(ref m_Gravity)).magnitude;
		for (int i = 0; i < pt.m_Particles.Count; i++)
		{
			Particle particle = pt.m_Particles[i];
			particle.m_Damping = m_Damping;
			particle.m_Elasticity = m_Elasticity;
			particle.m_Stiffness = m_Stiffness;
			particle.m_Inert = m_Inert;
			particle.m_Friction = m_Friction;
			particle.m_Radius = m_Radius;
			if (pt.m_BoneTotalLength > 0f)
			{
				float num = particle.m_BoneLength / pt.m_BoneTotalLength;
				if (m_DampingDistrib != null && m_DampingDistrib.keys.Length != 0)
				{
					particle.m_Damping *= m_DampingDistrib.Evaluate(num);
				}
				if (m_ElasticityDistrib != null && m_ElasticityDistrib.keys.Length != 0)
				{
					particle.m_Elasticity *= m_ElasticityDistrib.Evaluate(num);
				}
				if (m_StiffnessDistrib != null && m_StiffnessDistrib.keys.Length != 0)
				{
					particle.m_Stiffness *= m_StiffnessDistrib.Evaluate(num);
				}
				if (m_InertDistrib != null && m_InertDistrib.keys.Length != 0)
				{
					particle.m_Inert *= m_InertDistrib.Evaluate(num);
				}
				if (m_FrictionDistrib != null && m_FrictionDistrib.keys.Length != 0)
				{
					particle.m_Friction *= m_FrictionDistrib.Evaluate(num);
				}
				if (m_RadiusDistrib != null && m_RadiusDistrib.keys.Length != 0)
				{
					particle.m_Radius *= m_RadiusDistrib.Evaluate(num);
				}
			}
			particle.m_Damping = Mathf.Clamp01(particle.m_Damping);
			particle.m_Elasticity = Mathf.Clamp01(particle.m_Elasticity);
			particle.m_Stiffness = Mathf.Clamp01(particle.m_Stiffness);
			particle.m_Inert = Mathf.Clamp01(particle.m_Inert);
			particle.m_Friction = Mathf.Clamp01(particle.m_Friction);
			particle.m_Radius = Mathf.Max(particle.m_Radius, 0f);
		}
	}

	private void InitTransforms()
	{
		for (int i = 0; i < m_ParticleTrees.Count; i++)
		{
			InitTransforms(m_ParticleTrees[i]);
		}
	}

	private void InitTransforms(ParticleTree pt)
	{
		//IL_0020: 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)
		for (int i = 0; i < pt.m_Particles.Count; i++)
		{
			Particle particle = pt.m_Particles[i];
			if (particle.m_TransformNotNull)
			{
				particle.m_Transform.localPosition = particle.m_InitLocalPosition;
				particle.m_Transform.localRotation = particle.m_InitLocalRotation;
			}
		}
	}

	private void ResetParticlesPosition()
	{
		//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)
		for (int i = 0; i < m_ParticleTrees.Count; i++)
		{
			ResetParticlesPosition(m_ParticleTrees[i]);
		}
		m_ObjectPrevPosition = ((Component)this).transform.position;
	}

	private void ResetParticlesPosition(ParticleTree pt)
	{
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: 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_005b: 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_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: 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_002e: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < pt.m_Particles.Count; i++)
		{
			Particle particle = pt.m_Particles[i];
			if (particle.m_TransformNotNull)
			{
				particle.m_Position = (particle.m_PrevPosition = particle.m_Transform.position);
			}
			else
			{
				Transform transform = pt.m_Particles[particle.m_ParentIndex].m_Transform;
				particle.m_Position = (particle.m_PrevPosition = transform.TransformPoint(particle.m_EndOffset));
			}
			particle.m_isCollide = false;
		}
	}

	private void UpdateParticles1(float timeVar, int loopIndex)
	{
		for (int i = 0; i < m_ParticleTrees.Count; i++)
		{
			UpdateParticles1(m_ParticleTrees[i], timeVar, loopIndex);
		}
	}

	private void UpdateParticles1(ParticleTree pt, float timeVar, int loopIndex)
	{
		//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_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_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: 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_0030: 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_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_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_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_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: 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_012a: 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_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_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: 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_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		Vector3 gravity = m_Gravity;
		Vector3 normalized = ((Vector3)(ref m_Gravity)).normalized;
		Vector3 val = normalized * Mathf.Max(Vector3.Dot(pt.m_RestGravity, normalized), 0f);
		gravity -= val;
		gravity = (gravity + m_Force) * (m_ObjectScale * timeVar);
		Vector3 val2 = ((loopIndex == 0) ? m_ObjectMove : Vector3.zero);
		for (int i = 0; i < pt.m_Particles.Count; i++)
		{
			Particle particle = pt.m_Particles[i];
			if (particle.m_ParentIndex >= 0)
			{
				Vector3 val3 = particle.m_Position - particle.m_PrevPosition;
				Vector3 val4 = val2 * particle.m_Inert;
				particle.m_PrevPosition = particle.m_Position + val4;
				float num = particle.m_Damping;
				if (particle.m_isCollide)
				{
					num += particle.m_Friction;
					if (num > 1f)
					{
						num = 1f;
					}
					particle.m_isCollide = false;
				}
				particle.m_Position += val3 * (1f - num) + gravity + val4;
			}
			else
			{
				particle.m_PrevPosition = particle.m_Position;
				particle.m_Position = particle.m_TransformPosition;
			}
		}
	}

	private void UpdateParticles2(float timeVar)
	{
		for (int i = 0; i < m_ParticleTrees.Count; i++)
		{
			UpdateParticles2(m_ParticleTrees[i], timeVar);
		}
	}

	private void UpdateParticles2(ParticleTree pt, float timeVar)
	{
		//IL_0002: 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_0037: 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_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00d8: 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_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: 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_00e4: 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_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_00f5: 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_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: 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_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_022e: 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_023e: Unknown result type (might be due to invalid IL or missing references)
		//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_01e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ed: 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_01f6: 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_0205: Unknown result type (might be due to invalid IL or missing references)
		//IL_020c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0214: Unknown result type (might be due to invalid IL or missing references)
		//IL_021e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0223: Unknown result type (might be due to invalid IL or missing references)
		//IL_0228: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_0254: Unknown result type (might be due to invalid IL or missing references)
		//IL_0259: Unknown result type (might be due to invalid IL or missing references)
		//IL_0263: Unknown result type (might be due to invalid IL or missing references)
		//IL_0268: Unknown result type (might be due to invalid IL or missing references)
		//IL_026d: Unknown result type (might be due to invalid IL or missing references)
		Plane val = default(Plane);
		for (int i = 1; i < pt.m_Particles.Count; i++)
		{
			Particle particle = pt.m_Particles[i];
			Particle particle2 = pt.m_Particles[particle.m_ParentIndex];
			Vector3 val2;
			float magnitude;
			if (particle.m_TransformNotNull)
			{
				val2 = particle2.m_TransformPosition - particle.m_TransformPosition;
				magnitude = ((Vector3)(ref val2)).magnitude;
			}
			else
			{
				val2 = ((Matrix4x4)(ref particle2.m_TransformLocalToWorldMatrix)).MultiplyVector(particle.m_EndOffset);
				magnitude = ((Vector3)(ref val2)).magnitude;
			}
			float num = Mathf.Lerp(1f, particle.m_Stiffness, m_Weight);
			if (num > 0f || particle.m_Elasticity > 0f)
			{
				Matrix4x4 transformLocalToWorldMatrix = particle2.m_TransformLocalToWorldMatrix;
				((Matrix4x4)(ref transformLocalToWorldMatrix)).SetColumn(3, Vector4.op_Implicit(particle2.m_Position));
				Vector3 val3 = ((!particle.m_TransformNotNull) ? ((Matrix4x4)(ref transformLocalToWorldMatrix)).MultiplyPoint3x4(particle.m_EndOffset) : ((Matrix4x4)(ref transformLocalToWorldMatrix)).MultiplyPoint3x4(particle.m_TransformLocalPosition));
				Vector3 val4 = val3 - particle.m_Position;
				particle.m_Position += val4 * (particle.m_Elasticity * timeVar);
				if (num > 0f)
				{
					val4 = val3 - particle.m_Position;
					float magnitude2 = ((Vector3)(ref val4)).magnitude;
					float num2 = magnitude * (1f - num) * 2f;
					if (magnitude2 > num2)
					{
						particle.m_Position += val4 * ((magnitude2 - num2) / magnitude2);
					}
				}
			}
			if (m_EffectiveColliders != null)
			{
				float particleRadius = particle.m_Radius * m_ObjectScale;
				for (int j = 0; j < m_EffectiveColliders.Count; j++)
				{
					DynamicBoneColliderBase dynamicBoneColliderBase = m_EffectiveColliders[j];
					particle.m_isCollide |= dynamicBoneColliderBase.Collide(ref particle.m_Position, particleRadius);
				}
			}
			if (m_FreezeAxis != FreezeAxis.None)
			{
				Vector4 column = ((Matrix4x4)(ref particle2.m_TransformLocalToWorldMatrix)).GetColumn((int)(m_FreezeAxis - 1));
				Vector3 val5 = Vector4.op_Implicit(((Vector4)(ref column)).normalized);
				((Plane)(ref val)).SetNormalAndPosition(val5, particle2.m_Position);
				particle.m_Position -= ((Plane)(ref val)).normal * ((Plane)(ref val)).GetDistanceToPoint(particle.m_Position);
			}
			Vector3 val6 = particle2.m_Position - particle.m_Position;
			float magnitude3 = ((Vector3)(ref val6)).magnitude;
			if (magnitude3 > 0f)
			{
				particle.m_Position += val6 * ((magnitude3 - magnitude) / magnitude3);
			}
		}
	}

	private void SkipUpdateParticles()
	{
		for (int i = 0; i < m_ParticleTrees.Count; i++)
		{
			SkipUpdateParticles(m_ParticleTrees[i]);
		}
	}

	private void SkipUpdateParticles(ParticleTree pt)
	{
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_008c: 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_0096: 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_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_0079: 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_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_017e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: Unknown result type (might be due to invalid IL or missing references)
		//IL_018c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: 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_00ef: 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_0107: 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_0114: 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_013e: 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)
		for (int i = 0; i < pt.m_Particles.Count; i++)
		{
			Particle particle = pt.m_Particles[i];
			if (particle.m_ParentIndex >= 0)
			{
				particle.m_PrevPosition += m_ObjectMove;
				particle.m_Position += m_ObjectMove;
				Particle particle2 = pt.m_Particles[particle.m_ParentIndex];
				Vector3 val;
				float magnitude;
				if (particle.m_TransformNotNull)
				{
					val = particle2.m_TransformPosition - particle.m_TransformPosition;
					magnitude = ((Vector3)(ref val)).magnitude;
				}
				else
				{
					val = ((Matrix4x4)(ref particle2.m_TransformLocalToWorldMatrix)).MultiplyVector(particle.m_EndOffset);
					magnitude = ((Vector3)(ref val)).magnitude;
				}
				float num = Mathf.Lerp(1f, particle.m_Stiffness, m_Weight);
				if (num > 0f)
				{
					Matrix4x4 transformLocalToWorldMatrix = particle2.m_TransformLocalToWorldMatrix;
					((Matrix4x4)(ref transformLocalToWorldMatrix)).SetColumn(3, Vector4.op_Implicit(particle2.m_Position));
					Vector3 val2 = ((!particle.m_TransformNotNull) ? ((Matrix4x4)(ref transformLocalToWorldMatrix)).MultiplyPoint3x4(particle.m_EndOffset) : ((Matrix4x4)(ref transformLocalToWorldMatrix)).MultiplyPoint3x4(particle.m_TransformLocalPosition));
					Vector3 val3 = val2 - particle.m_Position;
					float magnitude2 = ((Vector3)(ref val3)).magnitude;
					float num2 = magnitude * (1f - num) * 2f;
					if (magnitude2 > num2)
					{
						particle.m_Position += val3 * ((magnitude2 - num2) / magnitude2);
					}
				}
				Vector3 val4 = particle2.m_Position - particle.m_Position;
				float magnitude3 = ((Vector3)(ref val4)).magnitude;
				if (magnitude3 > 0f)
				{
					particle.m_Position += val4 * ((magnitude3 - magnitude) / magnitude3);
				}
			}
			else
			{
				particle.m_PrevPosition = particle.m_Position;
				particle.m_Position = particle.m_TransformPosition;
			}
		}
	}

	private static Vector3 MirrorVector(Vector3 v, Vector3 axis)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		return v - axis * (Vector3.Dot(v, axis) * 2f);
	}

	private void ApplyParticlesToTransforms()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		Vector3 right = Vector3.right;
		Vector3 up = Vector3.up;
		Vector3 forward = Vector3.forward;
		bool nx = false;
		bool ny = false;
		bool nz = false;
		for (int i = 0; i < m_ParticleTrees.Count; i++)
		{
			ApplyParticlesToTransforms(m_ParticleTrees[i], right, up, forward, nx, ny, nz);
		}
	}

	private void ApplyParticlesToTransforms(ParticleTree pt, Vector3 ax, Vector3 ay, Vector3 az, bool nx, bool ny, bool nz)
	{
		//IL_00a0: 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_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_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: 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_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_007a: 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)
		for (int i = 1; i < pt.m_Particles.Count; i++)
		{
			Particle particle = pt.m_Particles[i];
			Particle particle2 = pt.m_Particles[particle.m_ParentIndex];
			if (particle2.m_ChildCount <= 1)
			{
				Vector3 val = ((!particle.m_TransformNotNull) ? particle.m_EndOffset : particle.m_Transform.localPosition);
				Vector3 val2 = particle2.m_Transform.TransformDirection(val);
				Vector3 val3 = particle.m_Position - particle2.m_Position;
				Quaternion val4 = Quaternion.FromToRotation(val2, val3);
				particle2.m_Transform.rotation = val4 * particle2.m_Transform.rotation;
			}
			if (particle.m_TransformNotNull)
			{
				particle.m_Transform.position = particle.m_Position;
			}
		}
	}

	private static void AddPendingWork(DynamicBone db)
	{
		s_PendingWorks.Add(db);
	}

	private static void AddWorkToQueue(DynamicBone db)
	{
		s_WorkQueueSemaphore.Release();
	}

	private static DynamicBone GetWorkFromQueue()
	{
		int index = Interlocked.Increment(ref s_WorkQueueIndex);
		return s_EffectiveWorks[index];
	}

	private static void ThreadProc()
	{
		while (true)
		{
			s_WorkQueueSemaphore.WaitOne();
			GetWorkFromQueue().UpdateParticles();
			if (Interlocked.Decrement(ref s_RemainWorkCount) <= 0)
			{
				s_AllWorksDoneEvent.Set();
			}
		}
	}

	private static void InitThreadPool()
	{
		s_AllWorksDoneEvent = new AutoResetEvent(initialState: false);
		s_WorkQueueSemaphore = new Semaphore(0, int.MaxValue);
		int processorCount = Environment.ProcessorCount;
		for (int i = 0; i < processorCount; i++)
		{
			Thread thread = new Thread(ThreadProc);
			thread.IsBackground = true;
			thread.Start();
		}
	}

	private static void ExecuteWorks()
	{
		if (s_PendingWorks.Count <= 0)
		{
			return;
		}
		s_EffectiveWorks.Clear();
		for (int i = 0; i < s_PendingWorks.Count; i++)
		{
			DynamicBone dynamicBone = s_PendingWorks[i];
			if ((Object)(object)dynamicBone != (Object)null && ((Behaviour)dynamicBone).enabled)
			{
				dynamicBone.CheckDistance();
				if (dynamicBone.IsNeedUpdate())
				{
					s_EffectiveWorks.Add(dynamicBone);
				}
			}
		}
		s_PendingWorks.Clear();
		if (s_EffectiveWorks.Count > 0)
		{
			if (s_AllWorksDoneEvent == null)
			{
				InitThreadPool();
			}
			int num = (s_RemainWorkCount = s_EffectiveWorks.Count);
			s_WorkQueueIndex = -1;
			for (int j = 0; j < num; j++)
			{
				DynamicBone dynamicBone2 = s_EffectiveWorks[j];
				dynamicBone2.Prepare();
				AddWorkToQueue(dynamicBone2);
			}
			s_AllWorksDoneEvent.WaitOne();
			for (int k = 0; k < num; k++)
			{
				s_EffectiveWorks[k].ApplyParticlesToTransforms();
			}
		}
	}
}
public class DynamicBoneColliderBase : MonoBehaviour
{
	public enum Direction
	{
		X,
		Y,
		Z
	}

	public enum Bound
	{
		Outside,
		Inside
	}

	[Tooltip("The axis of the capsule's height.")]
	public Direction m_Direction = Direction.Y;

	[Tooltip("The center of the sphere or capsule, in the object's local space.")]
	public Vector3 m_Center = Vector3.zero;

	[Tooltip("Constrain bones to outside bound or inside bound.")]
	public Bound m_Bound;

	public int PrepareFrame { get; set; }

	public virtual void Start()
	{
	}

	public virtual void Prepare()
	{
	}

	public virtual bool Collide(ref Vector3 particlePosition, float particleRadius)
	{
		return false;
	}
}
[AddComponentMenu("Dynamic Bone/Dynamic Bone Collider")]
public class DynamicBoneCollider : DynamicBoneColliderBase
{
	[Tooltip("The radius of the sphere or capsule.")]
	public float m_Radius = 0.5f;

	[Tooltip("The height of the capsule.")]
	public float m_Height;

	[Tooltip("The other radius of the capsule.")]
	public float m_Radius2;

	private float m_ScaledRadius;

	private float m_ScaledRadius2;

	private Vector3 m_C0;

	private Vector3 m_C1;

	private float m_C01Distance;

	private int m_CollideType;

	private void OnValidate()
	{
		m_Radius = Mathf.Max(m_Radius, 0f);
		m_Height = Mathf.Max(m_Height, 0f);
		m_Radius2 = Mathf.Max(m_Radius2, 0f);
	}

	public override void Prepare()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: 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_01fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0204: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Unknown result type (might be due to invalid IL or missing references)
		//IL_027c: Unknown result type (might be due to invalid IL or missing references)
		//IL_027e: 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_028f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0291: Unknown result type (might be due to invalid IL or missing references)
		//IL_0296: Unknown result type (might be due to invalid IL or missing references)
		//IL_029d: 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_02a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
		float num = Mathf.Abs(((Component)this).transform.lossyScale.x);
		float num2 = m_Height * 0.5f;
		Vector3 val;
		if (m_Radius2 <= 0f || Mathf.Abs(m_Radius - m_Radius2) < 0.01f)
		{
			m_ScaledRadius = m_Radius * num;
			float num3 = num2 - m_Radius;
			if (num3 <= 0f)
			{
				m_C0 = ((Component)this).transform.TransformPoint(m_Center);
				if (m_Bound == Bound.Outside)
				{
					m_CollideType = 0;
				}
				else
				{
					m_CollideType = 1;
				}
				return;
			}
			Vector3 center = m_Center;
			Vector3 center2 = m_Center;
			switch (m_Direction)
			{
			case Direction.X:
				center.x += num3;
				center2.x -= num3;
				break;
			case Direction.Y:
				center.y += num3;
				center2.y -= num3;
				break;
			case Direction.Z:
				center.z += num3;
				center2.z -= num3;
				break;
			}
			m_C0 = ((Component)this).transform.TransformPoint(center);
			m_C1 = ((Component)this).transform.TransformPoint(center2);
			val = m_C1 - m_C0;
			m_C01Distance = ((Vector3)(ref val)).magnitude;
			if (m_Bound == Bound.Outside)
			{
				m_CollideType = 2;
			}
			else
			{
				m_CollideType = 3;
			}
			return;
		}
		float num4 = Mathf.Max(m_Radius, m_Radius2);
		if (num2 - num4 <= 0f)
		{
			m_ScaledRadius = num4 * num;
			m_C0 = ((Component)this).transform.TransformPoint(m_Center);
			if (m_Bound == Bound.Outside)
			{
				m_CollideType = 0;
			}
			else
			{
				m_CollideType = 1;
			}
			return;
		}
		m_ScaledRadius = m_Radius * num;
		m_ScaledRadius2 = m_Radius2 * num;
		float num5 = num2 - m_Radius;
		float num6 = num2 - m_Radius2;
		Vector3 center3 = m_Center;
		Vector3 center4 = m_Center;
		switch (m_Direction)
		{
		case Direction.X:
			center3.x += num5;
			center4.x -= num6;
			break;
		case Direction.Y:
			center3.y += num5;
			center4.y -= num6;
			break;
		case Direction.Z:
			center3.z += num5;
			center4.z -= num6;
			break;
		}
		m_C0 = ((Component)this).transform.TransformPoint(center3);
		m_C1 = ((Component)this).transform.TransformPoint(center4);
		val = m_C1 - m_C0;
		m_C01Distance = ((Vector3)(ref val)).magnitude;
		if (m_Bound == Bound.Outside)
		{
			m_CollideType = 4;
		}
		else
		{
			m_CollideType = 5;
		}
	}

	public override bool Collide(ref Vector3 particlePosition, float particleRadius)
	{
		//IL_002d: 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_0055: 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_0075: 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_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: 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)
		return m_CollideType switch
		{
			0 => OutsideSphere(ref particlePosition, particleRadius, m_C0, m_ScaledRadius), 
			1 => InsideSphere(ref particlePosition, particleRadius, m_C0, m_ScaledRadius), 
			2 => OutsideCapsule(ref particlePosition, particleRadius, m_C0, m_C1, m_ScaledRadius, m_C01Distance), 
			3 => InsideCapsule(ref particlePosition, particleRadius, m_C0, m_C1, m_ScaledRadius, m_C01Distance), 
			4 => OutsideCapsule2(ref particlePosition, particleRadius, m_C0, m_C1, m_ScaledRadius, m_ScaledRadius2, m_C01Distance), 
			5 => InsideCapsule2(ref particlePosition, particleRadius, m_C0, m_C1, m_ScaledRadius, m_ScaledRadius2, m_C01Distance), 
			_ => false, 
		};
	}

	private static bool OutsideSphere(ref Vector3 particlePosition, float particleRadius, Vector3 sphereCenter, float sphereRadius)
	{
		//IL_0009: 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_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: 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_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)
		float num = sphereRadius + particleRadius;
		float num2 = num * num;
		Vector3 val = particlePosition - sphereCenter;
		float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
		if (sqrMagnitude > 0f && sqrMagnitude < num2)
		{
			float num3 = Mathf.Sqrt(sqrMagnitude);
			particlePosition = sphereCenter + val * (num / num3);
			return true;
		}
		return false;
	}

	private static bool InsideSphere(ref Vector3 particlePosition, float particleRadius, Vector3 sphereCenter, float sphereRadius)
	{
		//IL_0009: 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_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		float num = sphereRadius - particleRadius;
		float num2 = num * num;
		Vector3 val = particlePosition - sphereCenter;
		float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
		if (sqrMagnitude > num2)
		{
			float num3 = Mathf.Sqrt(sqrMagnitude);
			particlePosition = sphereCenter + val * (num / num3);
			return true;
		}
		return false;
	}

	private static bool OutsideCapsule(ref Vector3 particlePosition, float particleRadius, Vector3 capsuleP0, Vector3 capsuleP1, float capsuleRadius, float dirlen)
	{
		//IL_0009: 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_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_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: 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_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: 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_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: 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_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		float num = capsuleRadius + particleRadius;
		float num2 = num * num;
		Vector3 val = capsuleP1 - capsuleP0;
		Vector3 val2 = particlePosition - capsuleP0;
		float num3 = Vector3.Dot(val2, val);
		if (num3 <= 0f)
		{
			float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
			if (sqrMagnitude > 0f && sqrMagnitude < num2)
			{
				float num4 = Mathf.Sqrt(sqrMagnitude);
				particlePosition = capsuleP0 + val2 * (num / num4);
				return true;
			}
		}
		else
		{
			float num5 = dirlen * dirlen;
			if (num3 >= num5)
			{
				val2 = particlePosition - capsuleP1;
				float sqrMagnitude2 = ((Vector3)(ref val2)).sqrMagnitude;
				if (sqrMagnitude2 > 0f && sqrMagnitude2 < num2)
				{
					float num6 = Mathf.Sqrt(sqrMagnitude2);
					particlePosition = capsuleP1 + val2 * (num / num6);
					return true;
				}
			}
			else
			{
				Vector3 val3 = val2 - val * (num3 / num5);
				float sqrMagnitude3 = ((Vector3)(ref val3)).sqrMagnitude;
				if (sqrMagnitude3 > 0f && sqrMagnitude3 < num2)
				{
					float num7 = Mathf.Sqrt(sqrMagnitude3);
					particlePosition += val3 * ((num - num7) / num7);
					return true;
				}
			}
		}
		return false;
	}

	private static bool InsideCapsule(ref Vector3 particlePosition, float particleRadius, Vector3 capsuleP0, Vector3 capsuleP1, float capsuleRadius, float dirlen)
	{
		//IL_0009: 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_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_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00bc: 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_004b: 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_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: 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_00e5: 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_00ef: 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_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: 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)
		float num = capsuleRadius - particleRadius;
		float num2 = num * num;
		Vector3 val = capsuleP1 - capsuleP0;
		Vector3 val2 = particlePosition - capsuleP0;
		float num3 = Vector3.Dot(val2, val);
		if (num3 <= 0f)
		{
			float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
			if (sqrMagnitude > num2)
			{
				float num4 = Mathf.Sqrt(sqrMagnitude);
				particlePosition = capsuleP0 + val2 * (num / num4);
				return true;
			}
		}
		else
		{
			float num5 = dirlen * dirlen;
			if (num3 >= num5)
			{
				val2 = particlePosition - capsuleP1;
				float sqrMagnitude2 = ((Vector3)(ref val2)).sqrMagnitude;
				if (sqrMagnitude2 > num2)
				{
					float num6 = Mathf.Sqrt(sqrMagnitude2);
					particlePosition = capsuleP1 + val2 * (num / num6);
					return true;
				}
			}
			else
			{
				Vector3 val3 = val2 - val * (num3 / num5);
				float sqrMagnitude3 = ((Vector3)(ref val3)).sqrMagnitude;
				if (sqrMagnitude3 > num2)
				{
					float num7 = Mathf.Sqrt(sqrMagnitude3);
					particlePosition += val3 * ((num - num7) / num7);
					return true;
				}
			}
		}
		return false;
	}

	private static bool OutsideCapsule2(ref Vector3 particlePosition, float particleRadius, Vector3 capsuleP0, Vector3 capsuleP1, float capsuleRadius0, float capsuleRadius1, float dirlen)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0009: 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_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00d4: 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_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: 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)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = capsuleP1 - capsuleP0;
		Vector3 val2 = particlePosition - capsuleP0;
		float num = Vector3.Dot(val2, val);
		if (num <= 0f)
		{
			float num2 = capsuleRadius0 + particleRadius;
			float num3 = num2 * num2;
			float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
			if (sqrMagnitude > 0f && sqrMagnitude < num3)
			{
				float num4 = Mathf.Sqrt(sqrMagnitude);
				particlePosition = capsuleP0 + val2 * (num2 / num4);
				return true;
			}
		}
		else
		{
			float num5 = dirlen * dirlen;
			if (num >= num5)
			{
				float num6 = capsuleRadius1 + particleRadius;
				float num7 = num6 * num6;
				val2 = particlePosition - capsuleP1;
				float sqrMagnitude2 = ((Vector3)(ref val2)).sqrMagnitude;
				if (sqrMagnitude2 > 0f && sqrMagnitude2 < num7)
				{
					float num8 = Mathf.Sqrt(sqrMagnitude2);
					particlePosition = capsuleP1 + val2 * (num6 / num8);
					return true;
				}
			}
			else
			{
				Vector3 val3 = val2 - val * (num / num5);
				float sqrMagnitude3 = ((Vector3)(ref val3)).sqrMagnitude;
				float num9 = Vector3.Dot(val2, val / dirlen);
				float num10 = Mathf.Lerp(capsuleRadius0, capsuleRadius1, num9 / dirlen) + particleRadius;
				float num11 = num10 * num10;
				if (sqrMagnitude3 > 0f && sqrMagnitude3 < num11)
				{
					float num12 = Mathf.Sqrt(sqrMagnitude3);
					particlePosition += val3 * ((num10 - num12) / num12);
					return true;
				}
			}
		}
		return false;
	}

	private static bool InsideCapsule2(ref Vector3 particlePosition, float particleRadius, Vector3 capsuleP0, Vector3 capsuleP1, float capsuleRadius0, float capsuleRadius1, float dirlen)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0009: 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_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: 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_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: 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_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_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: 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_00a5: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = capsuleP1 - capsuleP0;
		Vector3 val2 = particlePosition - capsuleP0;
		float num = Vector3.Dot(val2, val);
		if (num <= 0f)
		{
			float num2 = capsuleRadius0 - particleRadius;
			float num3 = num2 * num2;
			float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
			if (sqrMagnitude > num3)
			{
				float num4 = Mathf.Sqrt(sqrMagnitude);
				particlePosition = capsuleP0 + val2 * (num2 / num4);
				return true;
			}
		}
		else
		{
			float num5 = dirlen * dirlen;
			if (num >= num5)
			{
				float num6 = capsuleRadius1 - particleRadius;
				float num7 = num6 * num6;
				val2 = particlePosition - capsuleP1;
				float sqrMagnitude2 = ((Vector3)(ref val2)).sqrMagnitude;
				if (sqrMagnitude2 > num7)
				{
					float num8 = Mathf.Sqrt(sqrMagnitude2);
					particlePosition = capsuleP1 + val2 * (num6 / num8);
					return true;
				}
			}
			else
			{
				Vector3 val3 = val2 - val * (num / num5);
				float sqrMagnitude3 = ((Vector3)(ref val3)).sqrMagnitude;
				float num9 = Vector3.Dot(val2, val / dirlen);
				float num10 = Mathf.Lerp(capsuleRadius0, capsuleRadius1, num9 / dirlen) - particleRadius;
				float num11 = num10 * num10;
				if (sqrMagnitude3 > num11)
				{
					float num12 = Mathf.Sqrt(sqrMagnitude3);
					particlePosition += val3 * ((num10 - num12) / num12);
					return true;
				}
			}
		}
		return false;
	}

	private void OnDrawGizmosSelected()
	{
		//IL_0023: 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_0054: 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_006c: 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_008a: Unknown result type (might be due to invalid IL or missing references)
		if (((Behaviour)this).enabled)
		{
			Prepare();
			if (m_Bound == Bound.Outside)
			{
				Gizmos.color = Color.yellow;
			}
			else
			{
				Gizmos.color = Color.magenta;
			}
			switch (m_CollideType)
			{
			case 0:
			case 1:
				Gizmos.DrawWireSphere(m_C0, m_ScaledRadius);
				break;
			case 2:
			case 3:
				DrawCapsule(m_C0, m_C1, m_ScaledRadius, m_ScaledRadius);
				break;
			case 4:
			case 5:
				DrawCapsule(m_C0, m_C1, m_ScaledRadius, m_ScaledRadius2);
				break;
			}
		}
	}

	private static void DrawCapsule(Vector3 c0, Vector3 c1, float radius0, float radius1)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: 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)
		Gizmos.DrawLine(c0, c1);
		Gizmos.DrawWireSphere(c0, radius0);
		Gizmos.DrawWireSphere(c1, radius1);
	}
}
[AddComponentMenu("Dynamic Bone/Dynamic Bone Plane Collider")]
public class DynamicBonePlaneCollider : DynamicBoneColliderBase
{
	private Plane m_Plane;

	private void OnValidate()
	{
	}

	public override void Prepare()
	{
		//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_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_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_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: 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_0061: 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)
		Vector3 val = Vector3.up;
		switch (m_Direction)
		{
		case Direction.X:
			val = ((Component)this).transform.right;
			break;
		case Direction.Y:
			val = ((Component)this).transform.up;
			break;
		case Direction.Z:
			val = ((Component)this).transform.forward;
			break;
		}
		Vector3 val2 = ((Component)this).transform.TransformPoint(m_Center);
		((Plane)(ref m_Plane)).SetNormalAndPosition(val, val2);
	}

	public override bool Collide(ref Vector3 particlePosition, float particleRadius)
	{
		//IL_0007: 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_005b: 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_006b: 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_002f: 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_003f: Unknown result type (might be due to invalid IL or missing references)
		float distanceToPoint = ((Plane)(ref m_Plane)).GetDistanceToPoint(particlePosition);
		if (m_Bound == Bound.Outside)
		{
			if (distanceToPoint < 0f)
			{
				particlePosition -= ((Plane)(ref m_Plane)).normal * distanceToPoint;
				return true;
			}
		}
		else if (distanceToPoint > 0f)
		{
			particlePosition -= ((Plane)(ref m_Plane)).normal * distanceToPoint;
			return true;
		}
		return false;
	}

	private void OnDrawGizmosSelected()
	{
		//IL_0023: 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_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		if (((Behaviour)this).enabled)
		{
			Prepare();
			if (m_Bound == Bound.Outside)
			{
				Gizmos.color = Color.yellow;
			}
			else
			{
				Gizmos.color = Color.magenta;
			}
			Vector3 val = ((Component)this).transform.TransformPoint(m_Center);
			Gizmos.DrawLine(val, val + ((Plane)(ref m_Plane)).normal);
		}
	}
}
namespace BeastTribesFixesMod
{
	[HarmonyPatch]
	internal static class AzuPreviewCompat
	{
		private static Type? _cloneSyncType;

		private static MethodInfo? _mirrorFromMethod;

		private static bool _firstFireLogged;

		private static bool _firstSkipLogged;

		private static bool _firstSuccessLogged;

		public static bool Prepare()
		{
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				Type type;
				try
				{
					type = assembly.GetType("AzuEPI.Game.PlayerPreview.VECloneSync", throwOnError: false, ignoreCase: false);
				}
				catch
				{
					continue;
				}
				if (!(type == null))
				{
					_cloneSyncType = type;
					break;
				}
			}
			if (_cloneSyncType == null)
			{
				if (Chainloader.PluginInfos.ContainsKey("Azumatt.AzuExtendedPlayerInventory"))
				{
					Plugin.Log.LogWarning((object)"[AzuPreviewCompat] AzuExtendedPlayerInventory is loaded but AzuEPI.Game.PlayerPreview.VECloneSync was not found — its preview code changed.  The inventory preview will show a Viking.");
				}
				else
				{
					Plugin.Log.LogInfo((object)"[AzuPreviewCompat] AzuExtendedPlayerInventory not detected — preview compat patch skipped (harmless).");
				}
				return false;
			}
			_mirrorFromMethod = _cloneSyncType.GetMethod("MirrorFrom", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[2]
			{
				typeof(Player),
				typeof(Player)
			}, null);
			if (_mirrorFromMethod == null)
			{
				Plugin.Log.LogWarning((object)("[AzuPreviewCompat] Found " + _cloneSyncType.FullName + " but no MirrorFrom(Player, Player) method — AzuEPI API may have changed.  Preview compat patch skipped."));
				return false;
			}
			Plugin.Log.LogInfo((object)("[AzuPreviewCompat] Will postfix " + _cloneSyncType.FullName + ".MirrorFrom(Player, Player)."));
			return true;
		}

		public static MethodBase TargetMethod()
		{
			return _mirrorFromMethod;
		}

		[HarmonyPostfix]
		public static void Postfix(Humanoid __0, Humanoid __1, bool __result)
		{
			if (!_firstFireLogged)
			{
				_firstFireLogged = true;
				string text = (((Object)(object)__0 == (Object)null) ? "null" : ((Object)__0).name);
				string arg = (((Object)(object)__1 == (Object)null) ? "null" : ((Object)__1).name);
				bool flag = (Object)(object)__1 != (Object)null && (Object)(object)((Component)__1).GetComponent<SpeciesController>() != (Object)null;
				Plugin.Log.LogInfo((object)("[AzuPreviewCompat] First Postfix fire. src='" + text + "' " + $"dst='{arg}' __result={__result} previewHasSpeciesController={flag}"));
			}
			Player localPlayer = Player.m_localPlayer;
			SpeciesController speciesController = (((Object)(object)__1 != (Object)null) ? ((Component)__1).GetComponent<SpeciesController>() : null);
			bool flag2 = (Object)(object)localPlayer != (Object)null && (Object)(object)speciesController != (Object)null && RaceIdentity.Normalize(speciesController.CurrentSpecies) != CharacterRace.GetEffective(localPlayer);
			if (!__result && !flag2)
			{
				if (!_firstSkipLogged)
				{
					_firstSkipLogged = true;
					Plugin.Log.LogInfo((object)"[AzuPreviewCompat] First stamp-unchanged skip (this is normal — MirrorFrom is called more often than visuals change).");
				}
				return;
			}
			if ((Object)(object)__1 == (Object)null)
			{
				Plugin.Log.LogWarning((object)"[AzuPreviewCompat] Postfix: dst humanoid null despite __result==true — unexpected, AzuEPI contract drift?  Bailing.");
				return;
			}
			Player localPlayer2 = Player.m_localPlayer;
			if ((Object)(object)localPlayer2 == (Object)null)
			{
				return;
			}
			if ((Object)(object)BeastBodyPatch.ForeignPreviewTarget != (Object)null)
			{
				Plugin.Log.LogWarning((object)"[AzuPreviewCompat] ForeignPreviewTarget already set on entry — another caller is driving the preview path.  Bailing to avoid clobbering their state.");
				return;
			}
			try
			{
				(((Component)__1).GetComponent<HairPreviewSource>() ?? ((Component)__1).gameObject.AddComponent<HairPreviewSource>()).Source = localPlayer2;
				string text2 = ResolveLocalSpecies(localPlayer2);
				SpeciesController component = ((Component)__1).GetComponent<SpeciesController>();
				if ((Object)(object)component == (Object)null)
				{
					if (!_firstSuccessLogged)
					{
						_firstSuccessLogged = true;
						Plugin.Log.LogWarning((object)"[AzuPreviewCompat] Preview Humanoid has no SpeciesController — Humanoid.Awake postfix didn't fire for this instance.  Preview will not reflect beast form.");
					}
					return;
				}
				component.ApplyForeignSpecies(text2);
				if (!_firstSuccessLogged)
				{
					_firstSuccessLogged = true;
					Plugin.Log.LogInfo((object)("[AzuPreviewCompat] First successful apply: species='" + text2 + "' on humanoid='" + ((Object)__1).name + "' (ctrl found, proceeding to legs+hair refresh)."));
				}
				BeastBodyPatch.ForeignPreviewTarget = __1;
				try
				{
					BeastBodyPatch.Postfix(component);
					HairAndHelmetFix.RefreshPatch.Postfix(component);
				}
				finally
				{
					BeastBodyPatch.ForeignPreviewTarget = null;
				}
			}
			catch (Exception arg2)
			{
				Plugin.Log.LogError((object)$"[AzuPreviewCompat] Postfix threw: {arg2}");
				BeastBodyPatch.ForeignPreviewTarget = null;
			}
		}

		private static string ResolveLocalSpecies(Player local)
		{
			return CharacterRace.GetEffective(local);
		}
	}
	internal sealed class AppliedPerkValue
	{
		private bool _active;

		private float _original;

		private float _applied;

		internal void Apply(ref float field, float value)
		{
			if (!_active || field != _applied)
			{
				_original = field;
			}
			field = (_applied = value);
			_active = _original != value;
		}

		internal void Restore(ref float field)
		{
			if (_active && field == _applied)
			{
				field = _original;
			}
			_active = false;
		}
	}
	internal static class DragonFlightAnimation
	{
		private sealed class BodyState
		{
			internal Animator? Animator;

			internal RuntimeAnimatorController? Original;

			internal AnimatorOverrideController? Flight;

			internal AnimatorCullingMode Culling;

			internal bool Active;

			internal Transform? Visual;

			internal Quaternion VisualRotation;
		}

		private sealed class WingState
		{
			internal GameObject Driver;

			internal Animator Animator;

			internal Transform[] Sources = Array.Empty<Transform>();

			internal Quaternion[] SourceRest = Array.Empty<Quaternion>();

			internal Vector3[] SourcePosition = Array.Empty<Vector3>();

			internal Transform[][] Targets = Array.Empty<Transform[]>();

			internal Quaternion[][] TargetRest = Array.Empty<Quaternion[]>();

			internal Vector3[][] TargetPosition = Array.Empty<Vector3[]>();

			internal float[][] PositionScale = Array.Empty<float[]>();

			internal long Forward;

			internal long Elevate;

			internal long NotFlying;

			internal bool Active;
		}

		private static AssetBundle? _bundle;

		private static AnimationClip? _accelerate;

		private static AnimationClip? _elevate;

		private static GameObject? _wingPrefab;

		private static bool _loadAttempted;

		private static readonly ConditionalWeakTable<Player, BodyState> Bodies = new ConditionalWeakTable<Player, BodyState>();

		private static readonly ConditionalWeakTable<GameObject, WingState> Wings = new ConditionalWeakTable<GameObject, WingState>();

		internal static bool Begin(Player player)
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Expected O, but got Unknown
			//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)
			if (!Load() || (Object)(object)((Character)player).m_animator == (Object)null || (Object)(object)((Character)player).m_animator.runtimeAnimatorController == (Object)null)
			{
				return false;
			}
			Animator animator = ((Character)player).m_animator;
			BodyState value = Bodies.GetValue(player, (Player _) => new BodyState());
			if (value.Active && (Object)(object)value.Animator == (Object)(object)animator && (Object)(object)animator.runtimeAnimatorController == (Object)(object)value.Flight)
			{
				return true;
			}
			RestoreBody(value);
			value.Animator = animator;
			value.Original = animator.runtimeAnimatorController;
			value.Culling = animator.cullingMode;
			value.Visual = (((Object)(object)((Humanoid)player).m_visEquipment != (Object)null) ? ((Component)((Humanoid)player).m_visEquipment).transform : null);
			if ((Object)(object)value.Visual != (Object)null)
			{
				value.VisualRotation = value.Visual.localRotation;
			}
			value.Flight = new AnimatorOverrideController(value.Original)
			{
				name = "BeastFlightRAC"
			};
			List<KeyValuePair<AnimationClip, AnimationClip>> list = new List<KeyValuePair<AnimationClip, AnimationClip>>();
			value.Flight.GetOverrides(list);
			for (int num = 0; num < list.Count; num++)
			{
				list[num] = new KeyValuePair<AnimationClip, AnimationClip>(list[num].Key, (((Object)list[num].Key).name == "Flex") ? _elevate : _accelerate);
			}
			value.Flight.ApplyOverrides((IList<KeyValuePair<AnimationClip, AnimationClip>>)list);
			animator.runtimeAnimatorController = (RuntimeAnimatorController)(object)value.Flight;
			animator.cullingMode = (AnimatorCullingMode)0;
			value.Active = true;
			return true;
		}

		internal static void UpdatePlayer(Humanoid? host)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			Player val = (Player)(object)((host is Player) ? host : null);
			if (val == null)
			{
				return;
			}
			if (SpeciesPerks.IsDragonFlying((Humanoid?)(object)val) && ((Component)val).GetComponent<SpeciesController>()?.CurrentSpecies == "dragon")
			{
				Begin(val);
				if ((Object)(object)val != (Object)(object)Player.m_localPlayer && (Object)(object)((Humanoid)val).m_visEquipment != (Object)null)
				{
					((Component)((Humanoid)val).m_visEquipment).transform.rotation = ((Character)val).m_nview.GetZDO().GetQuaternion("BTR.DragonFlightRotation", ((Component)val).transform.rotation);
				}
			}
			else
			{
				End(val);
			}
		}

		internal static void End(Player player)
		{
			if (Bodies.TryGetValue(player, out BodyState value))
			{
				RestoreBody(value);
				Bodies.Remove(player);
			}
		}

		private static void RestoreBody(BodyState state)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			if (state.Active && (Object)(object)state.Animator != (Object)null)
			{
				if ((Object)(object)state.Animator.runtimeAnimatorController == (Object)(object)state.Flight)
				{
					state.Animator.runtimeAnimatorController = state.Original;
				}
				if ((int)state.Animator.cullingMode == 0)
				{
					state.Animator.cullingMode = state.Culling;
				}
				if ((Object)(object)state.Visual != (Object)null)
				{
					state.Visual.localRotation = state.VisualRotation;
				}
			}
			if ((Object)(object)state.Flight != (Object)null)
			{
				Object.Destroy((Object)(object)state.Flight);
			}
			state.Flight = null;
			state.Active = false;
		}

		internal static void Tick(GameObject? rig, Humanoid? host)
		{
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: 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_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: 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_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)rig == (Object)null)
			{
				return;
			}
			Player val = (Player)(object)((host is Player) ? host : null);
			if (val == null || (Object)(object)((Character)val).m_nview == (Object)null || !((Character)val).m_nview.IsValid())
			{
				return;
			}
			if (!SpeciesPerks.IsDragonFlying((Humanoid?)(object)val))
			{
				if (Wings.TryGetValue(rig, out WingState value) && value.Active)
				{
					RestoreWings(value);
					value.Active = false;
				}
			}
			else
			{
				if (!Load())
				{
					return;
				}
				WingState value2 = Wings.GetValue(rig, Bind);
				ZDO zDO = ((Character)val).m_nview.GetZDO();
				long value3 = zDO.GetLong("BeastAdditionalItemAnimatorFlyForward", 0L);
				long value4 = zDO.GetLong("BeastAdditionalItemAnimatorFlyElevate", 0L);
				long value5 = zDO.GetLong("BeastAdditionalItemAnimatorNotFlying", 0L);
				if (!value2.Active)
				{
					value2.Animator.Rebind();
					value2.Animator.Update(0f);
					value2.Active = true;
					value2.Forward = (value2.Elevate = (value2.NotFlying = 0L));
				}
				value2.Animator.SetBool("Flying", zDO.GetBool("BeastAdditionalItemAnimatorFlying", false));
				value2.Animator.SetBool("Decelerating", zDO.GetBool("BeastAdditionalItemAnimatorDecelerating", false));
				value2.Animator.SetFloat("Velocity", zDO.GetFloat("BeastAdditionalItemAnimatorVelocity", 0f));
				Trigger(value2.Animator, "FlyForward", value3, ref value2.Forward);
				Trigger(value2.Animator, "FlyElevate", value4, ref value2.Elevate);
				Trigger(value2.Animator, "NotFlying", value5, ref value2.NotFlying);
				value2.Animator.Update(Time.deltaTime);
				for (int i = 0; i < value2.Targets.Length; i++)
				{
					for (int j = 0; j < value2.Sources.Length; j++)
					{
						if