Decompiled source of MikuGlider v0.12.66

BepInEx/plugins/Gelofrat-MikuGlider-0.12.66.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Text;
using Animancer;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Pigeon.Math;
using Pigeon.Movement;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Rendering;
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: AssemblyCompany("Gelofrat")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Adds 3 Hatsune Miku skins for Glider and a wearable Porcelain Mask.")]
[assembly: AssemblyFileVersion("0.12.66.0")]
[assembly: AssemblyInformationalVersion("0.12.66+f85142bcb3180f12b82e64aedfeea0899b7a0017")]
[assembly: AssemblyProduct("MikuGlider")]
[assembly: AssemblyTitle("MikuGlider")]
[assembly: AssemblyVersion("0.12.66.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MikuGlider
{
	[DefaultExecutionOrder(1000)]
	internal sealed class AnimatedHairVisual : MonoBehaviour
	{
		private const float BlendDuration = 0.18f;

		private RegisteredSkin skin;

		private SkinnedMeshRenderer body;

		private Player owner;

		private Transform root;

		private Transform[] bones;

		private SkinnedMeshRenderer[] tails;

		private Quaternion[] blendFrom;

		private Material material;

		private readonly List<Material> materials = new List<Material>(4);

		private int materialIndex;

		private HairAnimationState state;

		private float animationStarted;

		private bool wantedFlight;

		private HairSpringSolver spring;

		private CharacterBodyBones bodyBones;

		private Quaternion[] authoredRotations;

		private Quaternion[] authoredWorldRotations;

		private Vector3[] authoredPositions;

		private int[] primaryChildren;

		private bool physicsApplied;

		internal static void Attach(GameObject host, SkinnedMeshRenderer body, Transform head, int materialIndex, RegisteredSkin skin, Player owner)
		{
			AnimatedHairVisual animatedHairVisual = host.GetComponent<AnimatedHairVisual>();
			if ((Object)(object)animatedHairVisual == (Object)null)
			{
				animatedHairVisual = host.AddComponent<AnimatedHairVisual>();
			}
			animatedHairVisual.Bind(body, head, materialIndex, skin, owner);
		}

		private void Bind(SkinnedMeshRenderer renderer, Transform head, int mainIndex, RegisteredSkin variant, Player player)
		{
			bool num = (Object)(object)root == (Object)null || skin != variant || (Object)(object)body != (Object)(object)renderer || (Object)(object)root.parent != (Object)(object)head;
			skin = variant;
			body = renderer;
			owner = player;
			materialIndex = mainIndex;
			if (num)
			{
				CreateRig(head);
			}
		}

		private void CreateRig(Transform head)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: 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_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			RemoveRig();
			root = new GameObject(skin.Definition.Key + " animated hair").transform;
			root.SetParent(head, false);
			HairAnimationData hair = skin.Assets.Hair;
			bones = (Transform[])(object)new Transform[hair.Parents.Length];
			blendFrom = (Quaternion[])(object)new Quaternion[bones.Length];
			authoredRotations = (Quaternion[])(object)new Quaternion[bones.Length];
			authoredWorldRotations = (Quaternion[])(object)new Quaternion[bones.Length];
			authoredPositions = (Vector3[])(object)new Vector3[bones.Length];
			primaryChildren = new int[bones.Length];
			for (int i = 0; i < primaryChildren.Length; i++)
			{
				primaryChildren[i] = -1;
			}
			for (int j = 0; j < bones.Length; j++)
			{
				Transform transform = new GameObject(hair.Names[j]).transform;
				transform.SetParent((hair.Parents[j] < 0) ? root : bones[hair.Parents[j]], false);
				transform.localPosition = hair.Positions[j];
				transform.localRotation = hair.RestRotations[j];
				transform.localScale = hair.Scales[j];
				bones[j] = transform;
				blendFrom[j] = transform.localRotation;
				authoredRotations[j] = transform.localRotation;
				int num = hair.Parents[j];
				if (num >= 0 && primaryChildren[num] < 0)
				{
					primaryChildren[num] = j;
				}
			}
			spring = new HairSpringSolver(hair);
			bodyBones = new CharacterBodyBones(body.bones);
			tails = (SkinnedMeshRenderer[])(object)new SkinnedMeshRenderer[2]
			{
				CreateTail("hair-l"),
				CreateTail("hair-r")
			};
			state = HairAnimationState.Idle;
			wantedFlight = false;
			material = null;
			physicsApplied = false;
			animationStarted = Time.time;
		}

		private SkinnedMeshRenderer CreateTail(string meshName)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: 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)
			GameObject val = new GameObject(skin.Definition.Key + " " + meshName);
			val.transform.SetParent(root, false);
			SkinnedMeshRenderer obj = val.AddComponent<SkinnedMeshRenderer>();
			obj.sharedMesh = skin.Assets.GetMesh(meshName);
			obj.bones = bones;
			obj.rootBone = root;
			((Renderer)obj).localBounds = new Bounds(Vector3.zero, new Vector3(4f, 4f, 4f));
			obj.quality = (SkinQuality)4;
			obj.updateWhenOffscreen = false;
			return obj;
		}

		private void LateUpdate()
		{
			if ((Object)(object)root == (Object)null || (Object)(object)body == (Object)null)
			{
				return;
			}
			bool flag = skin.OwnsBody(body.sharedMesh) && ((Renderer)body).enabled;
			((Component)root).gameObject.SetActive(flag);
			if (!flag)
			{
				spring.Invalidate();
				return;
			}
			SynchronizeRenderers();
			if (physicsApplied)
			{
				RestoreAuthoredPose();
			}
			Wingsuit obj = GliderEquipment.FindWingsuit(owner);
			bool flying = obj != null && obj.IsFlying;
			Animate(flying);
			physicsApplied = !((Renderer)body).forceRenderingOff && Time.deltaTime > 0f && HairSpringSolver.ShouldSimulate(state, flying);
			if (physicsApplied)
			{
				CaptureAuthoredPose();
				SimulateGroundMotion();
			}
			else
			{
				spring.Invalidate();
			}
		}

		private void RestoreAuthoredPose()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < bones.Length; i++)
			{
				bones[i].localRotation = authoredRotations[i];
			}
		}

		private void CaptureAuthoredPose()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			for (int i = 0; i < bones.Length; i++)
			{
				authoredRotations[i] = bones[i].localRotation;
				authoredWorldRotations[i] = bones[i].rotation;
				authoredPositions[i] = bones[i].position;
			}
		}

		private void SimulateGroundMotion()
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			float scale = CharacterBodyBones.GetScale(((Component)body).transform);
			spring.Step(authoredPositions, bodyBones.UpdateHairCollisions(scale), Time.deltaTime, scale);
			for (int i = 0; i < bones.Length; i++)
			{
				int num = primaryChildren[i];
				if (num >= 0 && spring.Freedom[num] != 0f)
				{
					Vector3 val = authoredPositions[num] - authoredPositions[i];
					Vector3 val2 = spring.Positions[num] - spring.Positions[i];
					if (!(((Vector3)(ref val)).sqrMagnitude < 1E-06f) && !(((Vector3)(ref val2)).sqrMagnitude < 1E-06f))
					{
						Quaternion val3 = Quaternion.FromToRotation(val, val2);
						float num2 = Mathf.Lerp(7f, 42f, spring.Freedom[num]);
						val3 = Quaternion.RotateTowards(Quaternion.identity, val3, num2);
						bones[i].rotation = val3 * authoredWorldRotations[i];
					}
				}
			}
		}

		private void SynchronizeRenderers()
		{
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			((Renderer)body).GetSharedMaterials(materials);
			Material val = materials[materialIndex];
			SkinnedMeshRenderer[] array;
			if ((Object)(object)material != (Object)(object)val)
			{
				material = val;
				array = tails;
				for (int i = 0; i < array.Length; i++)
				{
					((Renderer)array[i]).sharedMaterial = material;
				}
			}
			array = tails;
			foreach (SkinnedMeshRenderer obj in array)
			{
				((Component)obj).gameObject.layer = ((Component)body).gameObject.layer;
				((Renderer)obj).renderingLayerMask = ((Renderer)body).renderingLayerMask;
				((Renderer)obj).forceRenderingOff = ((Renderer)body).forceRenderingOff;
				((Renderer)obj).shadowCastingMode = ((Renderer)body).shadowCastingMode;
			}
		}

		private void Animate(bool flying)
		{
			//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_00e9: 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)
			if (flying != wantedFlight)
			{
				wantedFlight = flying;
				TransitionTo(flying ? HairAnimationState.Unfolding : HairAnimationState.Folding);
			}
			float num = Time.time - animationStarted;
			HairAnimationClip clip = skin.Assets.Hair.GetClip(state);
			if (num >= clip.Duration && (state == HairAnimationState.Unfolding || state == HairAnimationState.Folding))
			{
				TransitionTo((state == HairAnimationState.Unfolding) ? HairAnimationState.Gliding : HairAnimationState.Idle);
				num = 0f;
				clip = skin.Assets.Hair.GetClip(state);
			}
			float num2 = Mathf.SmoothStep(0f, 1f, num / 0.18f);
			bool loop = state == HairAnimationState.Idle || state == HairAnimationState.Gliding;
			for (int i = 0; i < bones.Length; i++)
			{
				Quaternion val = clip.Sample(num, i, loop);
				bones[i].localRotation = Quaternion.Slerp(blendFrom[i], val, num2);
			}
		}

		private void TransitionTo(HairAnimationState nextState)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < bones.Length; i++)
			{
				blendFrom[i] = bones[i].localRotation;
			}
			state = nextState;
			animationStarted = Time.time;
		}

		private void RemoveRig()
		{
			if (!((Object)(object)root == (Object)null))
			{
				((Component)root).gameObject.SetActive(false);
				Object.Destroy((Object)(object)((Component)root).gameObject);
				root = null;
			}
		}

		private void OnDestroy()
		{
			RemoveRig();
		}
	}
	[DefaultExecutionOrder(1200)]
	internal sealed class FirstPersonWristVisual : MonoBehaviour
	{
		private SkinnedMeshRenderer surface;

		private Mesh original;

		private Mesh corrected;

		private Transform[] originalBones;

		private const int Stations = 9;

		private const float ForearmBlendLength = 0.09f;

		private const float PalmBlendLength = 0.035f;

		private float twistLength;

		private readonly float[] stationDistances = new float[9];

		private readonly Transform[] joints = (Transform[])(object)new Transform[9];

		private Matrix4x4 forearmBind;

		private Matrix4x4 palmBind;

		private Vector3 axis;

		private Vector3 restElbow;

		private Vector3 restStart;

		private Vector3 restEnd;

		private Quaternion forearmRestRotation;

		private RendererBoneBinding binding;

		internal ModelPoseCorrections PoseOwner { get; set; }

		internal static void Attach(SkinnedMeshRenderer renderer, Mesh expected, SkinModelDefinition definition = null)
		{
			if ((Object)(object)renderer == (Object)null)
			{
				return;
			}
			if ((Object)(object)expected != (Object)null && !((Object)expected).name.EndsWith(".arm-left", StringComparison.Ordinal) && !((Object)expected).name.EndsWith(".arm-right", StringComparison.Ordinal))
			{
				expected = null;
			}
			float num = definition?.firstPersonWristTwistLength ?? 0f;
			FirstPersonWristVisual component = ((Component)renderer).GetComponent<FirstPersonWristVisual>();
			if ((Object)(object)component != (Object)null && (Object)(object)component.original == (Object)(object)expected && (Object)(object)expected != (Object)null && component.twistLength == num && component.binding != null && component.binding.Matches(renderer.bones))
			{
				renderer.sharedMesh = component.corrected;
				((Behaviour)component).enabled = true;
				if ((Object)(object)component.PoseOwner == (Object)null || !component.PoseOwner.UpdatesWrist)
				{
					component.UpdatePose();
				}
				return;
			}
			if ((Object)(object)component != (Object)null)
			{
				component.Release();
			}
			if (!((Object)(object)expected == (Object)null) && !((Object)(object)renderer.sharedMesh != (Object)(object)expected))
			{
				FirstPersonWristVisual obj = component ?? ((Component)renderer).gameObject.AddComponent<FirstPersonWristVisual>();
				obj.twistLength = num;
				obj.Initialize(renderer, expected);
			}
		}

		private void Initialize(SkinnedMeshRenderer renderer, Mesh source)
		{
			//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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: 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_00e5: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: 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_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Unknown result type (might be due to invalid IL or missing references)
			surface = renderer;
			original = source;
			originalBones = renderer.bones;
			Matrix4x4[] bindposes = source.bindposes;
			if (bindposes.Length < 4 || originalBones.Length != bindposes.Length)
			{
				throw new InvalidOperationException("First-person arm rig does not match its mesh.");
			}
			forearmBind = bindposes[1];
			palmBind = bindposes[3];
			Matrix4x4 inverse = ((Matrix4x4)(ref bindposes[2])).inverse;
			Vector3 val = ((Matrix4x4)(ref inverse)).MultiplyPoint3x4(Vector3.zero);
			inverse = ((Matrix4x4)(ref forearmBind)).inverse;
			restElbow = ((Matrix4x4)(ref inverse)).MultiplyPoint3x4(Vector3.zero);
			inverse = ((Matrix4x4)(ref forearmBind)).inverse;
			forearmRestRotation = ((Matrix4x4)(ref inverse)).rotation;
			Vector3 val2 = val - restElbow;
			axis = ((Vector3)(ref val2)).normalized;
			restStart = val - axis * 0.09f;
			restEnd = val + axis * 0.035f;
			Transform[] array = (Transform[])(object)new Transform[bindposes.Length + joints.Length];
			Matrix4x4[] array2 = (Matrix4x4[])(object)new Matrix4x4[array.Length];
			Array.Copy(originalBones, array, bindposes.Length);
			Array.Copy(bindposes, array2, bindposes.Length);
			for (int i = 0; i < joints.Length; i++)
			{
				stationDistances[i] = ((twistLength > 0.09f) ? ((i < 2) ? Mathf.Lerp(0f - twistLength, -0.09f, (float)i / 2f) : Mathf.Lerp(-0.09f, 0.035f, ((float)i - 2f) / 6f)) : Mathf.Lerp(-0.09f, 0.035f, (float)i / 8f));
				joints[i] = new GameObject("Miku wrist transition " + i).transform;
				joints[i].SetParent(((Component)renderer).transform, false);
				array[bindposes.Length + i] = joints[i];
				array2[bindposes.Length + i] = forearmBind;
			}
			BoneWeight[] boneWeights = source.boneWeights;
			Vector3[] vertices = source.vertices;
			float num = 0.125f;
			for (int j = 0; j < boneWeights.Length; j++)
			{
				BoneWeight source2 = boneWeights[j];
				float num2 = Mathf.Clamp01(Vector3.Dot(vertices[j] - restStart, axis) / num) * 8f;
				int k = Mathf.Min(7, Mathf.FloorToInt(num2));
				float num3 = num2 - (float)k;
				if (twistLength > 0.09f)
				{
					float num4 = Vector3.Dot(vertices[j] - val, axis);
					for (k = 0; k < 7 && num4 > stationDistances[k + 1]; k++)
					{
					}
					num3 = Mathf.InverseLerp(stationDistances[k], stationDistances[k + 1], num4);
				}
				if (RetainedInfluence(((BoneWeight)(ref source2)).boneIndex0, ((BoneWeight)(ref source2)).weight0) + RetainedInfluence(((BoneWeight)(ref source2)).boneIndex1, ((BoneWeight)(ref source2)).weight1) + RetainedInfluence(((BoneWeight)(ref source2)).boneIndex2, ((BoneWeight)(ref source2)).weight2) + RetainedInfluence(((BoneWeight)(ref source2)).boneIndex3, ((BoneWeight)(ref source2)).weight3) > 2)
				{
					num3 = Mathf.Round(num3);
				}
				boneWeights[j] = SkinWeightBlend.Replace(source2, 1, 2, 3, bindposes.Length + k, num3);
			}
			corrected = Object.Instantiate<Mesh>(source);
			((Object)corrected).name = ((Object)source).name + " wrist transition";
			corrected.bindposes = array2;
			corrected.boneWeights = boneWeights;
			binding = RendererBoneBinding.For(renderer);
			binding.SetWrist(array);
			renderer.sharedMesh = corrected;
			((Behaviour)this).enabled = true;
			UpdatePose();
		}

		private static int RetainedInfluence(int bone, float weight)
		{
			if (!(weight > 0f) || (bone >= 1 && bone <= 3))
			{
				return 0;
			}
			return 1;
		}

		private void LateUpdate()
		{
			if ((Object)(object)surface == (Object)null || (Object)(object)surface.sharedMesh != (Object)(object)corrected)
			{
				Release();
			}
			else if ((Object)(object)PoseOwner == (Object)null || !PoseOwner.UpdatesWrist)
			{
				UpdatePose();
			}
		}

		internal void UpdatePose(Transform palmOverride = null, Transform forearmOverride = null)
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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_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_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00cf: 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_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: 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_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: 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_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: 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_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: 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)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0300: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0396: Unknown result type (might be due to invalid IL or missing references)
			//IL_0398: Unknown result type (might be due to invalid IL or missing references)
			//IL_039b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_0327: Unknown result type (might be due to invalid IL or missing references)
			//IL_0334: Unknown result type (might be due to invalid IL or missing references)
			//IL_0339: Unknown result type (might be due to invalid IL or missing references)
			//IL_033e: Unknown result type (might be due to invalid IL or missing references)
			//IL_036c: Unknown result type (might be due to invalid IL or missing references)
			//IL_036e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0373: Unknown result type (might be due to invalid IL or missing references)
			//IL_0377: Unknown result type (might be due to invalid IL or missing references)
			//IL_037c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0381: Unknown result type (might be due to invalid IL or missing references)
			//IL_0386: Unknown result type (might be due to invalid IL or missing references)
			//IL_038a: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0394: Unknown result type (might be due to invalid IL or missing references)
			//IL_034b: Unknown result type (might be due to invalid IL or missing references)
			//IL_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0352: Unknown result type (might be due to invalid IL or missing references)
			if (originalBones == null || (Object)(object)originalBones[0] == (Object)null || (Object)(object)originalBones[1] == (Object)null || (Object)(object)originalBones[2] == (Object)null || (Object)(object)originalBones[3] == (Object)null)
			{
				return;
			}
			Matrix4x4 val = (((Object)(object)forearmOverride != (Object)null) ? forearmOverride : originalBones[1]).localToWorldMatrix * forearmBind;
			Matrix4x4 val2 = (((Object)(object)palmOverride != (Object)null) ? palmOverride : originalBones[3]).localToWorldMatrix * palmBind;
			Vector3 val3 = ((Matrix4x4)(ref val)).MultiplyPoint3x4(restStart);
			Vector3 val4 = ((Matrix4x4)(ref val2)).MultiplyPoint3x4(restEnd);
			float num = 0.125f;
			Vector3 val5 = ((Matrix4x4)(ref val)).MultiplyVector(axis) * num;
			Vector3 val6 = ((Matrix4x4)(ref val2)).MultiplyVector(axis) * num;
			Quaternion rotation = ((Matrix4x4)(ref val)).rotation;
			Quaternion rotation2 = ((Matrix4x4)(ref val2)).rotation;
			bool flag = twistLength > 0.09f;
			Quaternion identity = Quaternion.identity;
			Quaternion val7 = Quaternion.identity;
			if (flag)
			{
				Quaternion val8 = Quaternion.Inverse(rotation) * rotation2;
				Vector3 val9 = axis * Vector3.Dot(new Vector3(val8.x, val8.y, val8.z), axis);
				float num2 = Mathf.Sqrt(((Vector3)(ref val9)).sqrMagnitude + val8.w * val8.w);
				if (num2 > 1E-06f)
				{
					float num3 = ((val8.w < 0f) ? (-1f) : 1f);
					((Quaternion)(ref identity))..ctor(val9.x * num3 / num2, val9.y * num3 / num2, val9.z * num3 / num2, val8.w * num3 / num2);
				}
				val7 = val8 * Quaternion.Inverse(identity);
			}
			Vector3 lossyScale = originalBones[1].lossyScale;
			Vector3 lossyScale2 = ((Component)surface).transform.lossyScale;
			Vector3 localScale = default(Vector3);
			((Vector3)(ref localScale))..ctor(lossyScale.x / lossyScale2.x, lossyScale.y / lossyScale2.y, lossyScale.z / lossyScale2.z);
			for (int i = 0; i < 9; i++)
			{
				float num4 = (float)i / 8f;
				if (flag)
				{
					num4 = Mathf.Clamp01((stationDistances[i] + 0.09f) / num);
				}
				float num5 = num4 * num4;
				float num6 = num5 * num4;
				Vector3 val10 = (2f * num6 - 3f * num5 + 1f) * val3 + (num6 - 2f * num5 + num4) * val5 + (-2f * num6 + 3f * num5) * val4 + (num6 - num5) * val6;
				Quaternion val11 = (flag ? Quaternion.identity : Quaternion.Slerp(rotation, rotation2, num4));
				Vector3 val12 = Vector3.Lerp(restStart, restEnd, num4);
				if (flag)
				{
					float num7 = stationDistances[i];
					val12 = restStart + axis * (num7 + 0.09f);
					if (num7 < -0.09f)
					{
						val10 = ((Matrix4x4)(ref val)).MultiplyPoint3x4(val12);
					}
					float num8 = (num7 + twistLength) / (twistLength + 0.035f);
					val11 = rotation * Quaternion.Slerp(Quaternion.identity, val7, num4) * Quaternion.Slerp(Quaternion.identity, identity, num8);
				}
				Vector3 val13 = val10 + val11 * Vector3.Scale(restElbow - val12, lossyScale);
				joints[i].SetPositionAndRotation(val13, val11 * forearmRestRotation);
				joints[i].localScale = localScale;
			}
		}

		private void Release()
		{
			if ((Object)(object)PoseOwner != (Object)null)
			{
				PoseOwner.ResetShapes();
			}
			if ((Object)(object)surface != (Object)null && originalBones != null && (Object)(object)surface.sharedMesh == (Object)(object)corrected)
			{
				surface.sharedMesh = original;
			}
			binding?.ReleaseWrist();
			binding = null;
			PoseOwner = null;
			for (int i = 0; i < joints.Length; i++)
			{
				if ((Object)(object)joints[i] != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)joints[i]).gameObject);
				}
				joints[i] = null;
			}
			if ((Object)(object)corrected != (Object)null)
			{
				Object.Destroy((Object)(object)corrected);
			}
			original = null;
			corrected = null;
			originalBones = null;
			((Behaviour)this).enabled = false;
		}

		private void OnDestroy()
		{
			Release();
		}
	}
	[DefaultExecutionOrder(1000)]
	internal sealed class FlightHairVisual : MonoBehaviour
	{
		private const int BoneCount = 8;

		private readonly MeshRenderer[] sources = (MeshRenderer[])(object)new MeshRenderer[2];

		private readonly SkinnedMeshRenderer[] renderers = (SkinnedMeshRenderer[])(object)new SkinnedMeshRenderer[2];

		private readonly bool[] hiddenBefore = new bool[2];

		private readonly bool[] hidden = new bool[2];

		private readonly Mesh[] meshes = (Mesh[])(object)new Mesh[2];

		private Transform[] bones;

		private GameObject rig;

		private RegisteredSkin skin;

		private Player owner;

		private float phase;

		private float flightBlend;

		internal static void Attach(Transform mount, RegisteredSkin skin, Player owner, float phase)
		{
			if ((Object)(object)mount == (Object)null)
			{
				return;
			}
			FlightHairVisual flightHairVisual = ((Component)mount).GetComponent<FlightHairVisual>();
			if (skin == null)
			{
				if ((Object)(object)flightHairVisual != (Object)null)
				{
					flightHairVisual.Clear();
					Object.Destroy((Object)(object)flightHairVisual);
				}
				return;
			}
			if ((Object)(object)flightHairVisual == (Object)null)
			{
				flightHairVisual = ((Component)mount).gameObject.AddComponent<FlightHairVisual>();
			}
			flightHairVisual.owner = owner;
			flightHairVisual.phase = phase;
			if (flightHairVisual.skin != skin || (Object)(object)flightHairVisual.rig == (Object)null)
			{
				flightHairVisual.Build(skin);
			}
		}

		private void Build(RegisteredSkin variant)
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			//IL_00fb: 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_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: 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_013b: 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_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0353: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cd: Unknown result type (might be due to invalid IL or missing references)
			Clear();
			if (((Component)this).transform.childCount == 0)
			{
				return;
			}
			sources[0] = ((Component)this).GetComponent<MeshRenderer>();
			sources[1] = ((Component)((Component)this).transform.GetChild(0)).GetComponent<MeshRenderer>();
			if ((Object)(object)sources[0] == (Object)null || (Object)(object)sources[1] == (Object)null)
			{
				return;
			}
			skin = variant;
			rig = new GameObject("Miku flight hair");
			rig.transform.SetParent(((Component)this).transform, false);
			bones = (Transform[])(object)new Transform[8];
			Mesh[] array = (Mesh[])(object)new Mesh[2]
			{
				skin.Assets.GetMesh("wing-base"),
				skin.Assets.GetMesh("wing-blades")
			};
			Vector3[][] array2 = new Vector3[2][];
			float num = float.PositiveInfinity;
			float num2 = float.NegativeInfinity;
			for (int i = 0; i < 2; i++)
			{
				array2[i] = array[i].vertices;
				Matrix4x4 val = ((Component)this).transform.worldToLocalMatrix * ((Component)sources[i]).transform.localToWorldMatrix;
				for (int j = 0; j < array2[i].Length; j++)
				{
					Vector3 val2 = ((Matrix4x4)(ref val)).MultiplyPoint3x4(array2[i][j]);
					array2[i][j] = val2;
					num = Mathf.Min(num, val2.z);
					num2 = Mathf.Max(num2, val2.z);
				}
			}
			float num3 = Mathf.Max(num2 - num, 0.001f) / 7f;
			for (int k = 0; k < bones.Length; k++)
			{
				Transform transform = new GameObject("Hair " + k).transform;
				transform.SetParent((k == 0) ? rig.transform : bones[k - 1], false);
				transform.localPosition = new Vector3(0f, 0f, (k == 0) ? num : num3);
				bones[k] = transform;
			}
			for (int l = 0; l < 2; l++)
			{
				Mesh val3 = Object.Instantiate<Mesh>(array[l]);
				((Object)val3).name = ((Object)array[l]).name + " animated";
				meshes[l] = val3;
				BoneWeight[] array3 = (BoneWeight[])(object)new BoneWeight[array2[l].Length];
				for (int m = 0; m < array3.Length; m++)
				{
					float num4 = Mathf.Clamp((array2[l][m].z - num) / num3, 0f, 7f);
					int num5 = Mathf.Min((int)num4, 6);
					int num6 = m;
					BoneWeight val4 = default(BoneWeight);
					((BoneWeight)(ref val4)).boneIndex0 = num5;
					((BoneWeight)(ref val4)).boneIndex1 = num5 + 1;
					((BoneWeight)(ref val4)).weight0 = 1f - (num4 - (float)num5);
					((BoneWeight)(ref val4)).weight1 = num4 - (float)num5;
					array3[num6] = val4;
				}
				Matrix4x4[] array4 = (Matrix4x4[])(object)new Matrix4x4[8];
				for (int n = 0; n < array4.Length; n++)
				{
					array4[n] = bones[n].worldToLocalMatrix * ((Component)sources[l]).transform.localToWorldMatrix;
				}
				val3.boneWeights = array3;
				val3.bindposes = array4;
				Transform transform2 = new GameObject("Animated " + ((Object)array[l]).name).transform;
				transform2.SetParent(((Component)sources[l]).transform, false);
				SkinnedMeshRenderer val5 = ((Component)transform2).gameObject.AddComponent<SkinnedMeshRenderer>();
				val5.sharedMesh = val3;
				val5.bones = bones;
				val5.rootBone = bones[0];
				val5.quality = (SkinQuality)2;
				Bounds bounds = val3.bounds;
				Vector3 size = ((Bounds)(ref bounds)).size;
				((Bounds)(ref bounds)).Expand(((Vector3)(ref size)).magnitude);
				((Renderer)val5).localBounds = bounds;
				renderers[l] = val5;
			}
		}

		private void LateUpdate()
		{
			//IL_00b5: 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)
			if ((Object)(object)rig == (Object)null)
			{
				return;
			}
			float num = flightBlend;
			Wingsuit obj = GliderEquipment.FindWingsuit(owner);
			flightBlend = Mathf.MoveTowards(num, (obj != null && obj.IsFlying) ? 1f : 0f, Time.deltaTime * 5f);
			for (int i = 1; i < bones.Length; i++)
			{
				float num2 = (float)i / 7f;
				float num3 = Time.time * 6.4f - num2 * 5f + phase;
				bones[i].localRotation = Quaternion.Euler(Mathf.Sin(num3) * 5f * num2 * flightBlend, Mathf.Sin(num3 + 1.3f) * 2f * num2 * flightBlend, 0f);
			}
			for (int j = 0; j < renderers.Length; j++)
			{
				MeshRenderer val = sources[j];
				SkinnedMeshRenderer obj2 = renderers[j];
				if (!hidden[j])
				{
					hiddenBefore[j] = ((Renderer)val).forceRenderingOff;
					hidden[j] = true;
				}
				((Renderer)obj2).sharedMaterial = ((Renderer)val).sharedMaterial;
				((Component)obj2).gameObject.layer = ((Component)val).gameObject.layer;
				((Renderer)obj2).renderingLayerMask = ((Renderer)val).renderingLayerMask;
				((Renderer)obj2).shadowCastingMode = ((Renderer)val).shadowCastingMode;
				((Renderer)obj2).enabled = ((Renderer)val).enabled;
				((Renderer)obj2).forceRenderingOff = hiddenBefore[j];
				((Renderer)val).forceRenderingOff = true;
			}
		}

		private void OnDisable()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			flightBlend = 0f;
			if (bones != null)
			{
				Transform[] array = bones;
				foreach (Transform val in array)
				{
					if ((Object)(object)val != (Object)null)
					{
						val.localRotation = Quaternion.identity;
					}
				}
			}
			for (int j = 0; j < sources.Length; j++)
			{
				if (hidden[j] && (Object)(object)sources[j] != (Object)null)
				{
					((Renderer)sources[j]).forceRenderingOff = hiddenBefore[j];
				}
				hidden[j] = false;
				if ((Object)(object)renderers[j] != (Object)null)
				{
					((Renderer)renderers[j]).enabled = false;
				}
			}
		}

		private void Clear()
		{
			OnDisable();
			for (int i = 0; i < renderers.Length; i++)
			{
				if ((Object)(object)renderers[i] != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)renderers[i]).gameObject);
				}
				if ((Object)(object)meshes[i] != (Object)null)
				{
					Object.Destroy((Object)(object)meshes[i]);
				}
				renderers[i] = null;
				meshes[i] = null;
			}
			if ((Object)(object)rig != (Object)null)
			{
				Object.Destroy((Object)(object)rig);
			}
			rig = null;
			bones = null;
			skin = null;
		}

		private void OnDestroy()
		{
			Clear();
		}
	}
	internal enum HairAnimationState
	{
		Idle,
		Unfolding,
		Gliding,
		Folding
	}
	internal sealed class HairAnimationData
	{
		private readonly HairAnimationClip[] clips;

		internal int[] Parents { get; }

		internal string[] Names { get; }

		internal Vector3[] Positions { get; }

		internal Vector3[] Scales { get; }

		internal Quaternion[] RestRotations { get; }

		internal HairAnimationData(int[] parents, string[] names, Vector3[] positions, Vector3[] scales, Quaternion[] restRotations, HairAnimationClip[] clips)
		{
			Parents = parents;
			Names = names;
			Positions = positions;
			Scales = scales;
			RestRotations = restRotations;
			this.clips = clips;
		}

		internal HairAnimationClip GetClip(HairAnimationState state)
		{
			return clips[(int)state];
		}
	}
	internal sealed class HairAnimationClip
	{
		private readonly Quaternion[][] frames;

		private readonly float framesPerSecond;

		internal float Duration => (float)(frames.Length - 1) / framesPerSecond;

		internal HairAnimationClip(Quaternion[][] frames, float framesPerSecond)
		{
			this.frames = frames;
			this.framesPerSecond = framesPerSecond;
		}

		internal Quaternion Sample(float time, int bone, bool loop)
		{
			//IL_0058: 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_006f: Unknown result type (might be due to invalid IL or missing references)
			float num = (loop ? Mathf.Repeat(time, Duration) : Mathf.Clamp(time, 0f, Duration)) * framesPerSecond;
			int num2 = Mathf.Min((int)num, frames.Length - 1);
			int num3 = Mathf.Min(num2 + 1, frames.Length - 1);
			return Quaternion.Slerp(frames[num2][bone], frames[num3][bone], num - (float)num2);
		}
	}
	internal sealed class InventoryWaistPose
	{
		private readonly InventoryWaistPoseDefinition fit;

		private readonly Transform shoulder;

		private readonly Transform elbow;

		private readonly Transform wrist;

		private readonly Transform middleTip;

		private readonly Quaternion shoulderTurn;

		private readonly Quaternion elbowTurn;

		private readonly Quaternion wristTurn;

		private InventoryWaistPose(InventoryWaistPoseDefinition fit, Transform shoulder, Transform elbow, Transform wrist, Transform middleTip)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			this.fit = fit;
			this.shoulder = shoulder;
			this.elbow = elbow;
			this.wrist = wrist;
			this.middleTip = middleTip;
			shoulderTurn = Rotation(fit.shoulderDegrees);
			elbowTurn = Rotation(fit.elbowDegrees);
			wristTurn = Rotation(fit.wristDegrees);
		}

		internal static InventoryWaistPose Bind(InventoryWaistPoseDefinition fit, Transform[] copies)
		{
			if (fit == null)
			{
				return null;
			}
			Transform val = Find("joint_Shoulder_R");
			Transform val2 = Find("joint_Elbow_R");
			Transform val3 = Find("joint_Wrist_R");
			Transform val4 = Find("joint_Middle04_R");
			if (!((Object)(object)val != (Object)null) || !((Object)(object)val2 != (Object)null) || !((Object)(object)val3 != (Object)null) || !((Object)(object)val4 != (Object)null))
			{
				return null;
			}
			return new InventoryWaistPose(fit, val, val2, val3, val4);
			Transform Find(string name)
			{
				return Array.Find(copies, (Transform bone) => (Object)(object)bone != (Object)null && ((Object)bone).name == name);
			}
		}

		private static Quaternion Rotation(Vector3 degrees)
		{
			//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_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			if (!(degrees == Vector3.zero))
			{
				return Quaternion.AngleAxis(((Vector3)(ref degrees)).magnitude, ((Vector3)(ref degrees)).normalized);
			}
			return Quaternion.identity;
		}

		internal bool Apply(Transform reference)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: 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_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//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_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_00b1: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Max(Vector3.Distance(reference.InverseTransformPoint(wrist.position), fit.wristPosition), Vector3.Distance(reference.InverseTransformPoint(middleTip.position), fit.middleTipPosition));
			float num2 = 1f - Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(0.025f, 0.085f, num));
			if (num2 <= 0f)
			{
				return false;
			}
			Transform obj = shoulder;
			obj.localRotation *= Quaternion.SlerpUnclamped(Quaternion.identity, shoulderTurn, num2);
			Transform obj2 = elbow;
			obj2.localRotation *= Quaternion.SlerpUnclamped(Quaternion.identity, elbowTurn, num2);
			Transform obj3 = wrist;
			obj3.localRotation *= Quaternion.SlerpUnclamped(Quaternion.identity, wristTurn, num2);
			return true;
		}
	}
	internal static class ModelCorrectionMeshes
	{
		internal sealed class AppliedMesh
		{
			internal MeshCorrection Correction;

			internal BoneWeight[] OriginalWeights;

			internal int[] Shapes;
		}

		private static readonly ConditionalWeakTable<Mesh, AppliedMesh> Applied = new ConditionalWeakTable<Mesh, AppliedMesh>();

		private static readonly Action<Mesh, string, float, Vector3[], Vector3[], Vector3[]> AddShape = (Action<Mesh, string, float, Vector3[], Vector3[], Vector3[]>)Delegate.CreateDelegate(typeof(Action<Mesh, string, float, Vector3[], Vector3[], Vector3[]>), typeof(Mesh).GetMethod("AddBlendShapeFrame", new Type[5]
		{
			typeof(string),
			typeof(float),
			typeof(Vector3[]),
			typeof(Vector3[]),
			typeof(Vector3[])
		}));

		private static readonly ConditionalWeakTable<Mesh, ConditionalWeakTable<MeshCorrection, object>> Rejected = new ConditionalWeakTable<Mesh, ConditionalWeakTable<MeshCorrection, object>>();

		internal static AppliedMesh GetApplied(Mesh mesh)
		{
			if (!((Object)(object)mesh != (Object)null) || !Applied.TryGetValue(mesh, out var value))
			{
				return null;
			}
			return value;
		}

		internal static bool Validate(Mesh mesh, MeshCorrection correction)
		{
			if (GetApplied(mesh) != null)
			{
				return true;
			}
			ConditionalWeakTable<MeshCorrection, object> value = Rejected.GetValue(mesh, (Mesh _) => new ConditionalWeakTable<MeshCorrection, object>());
			if (value.TryGetValue(correction, out var _))
			{
				return false;
			}
			try
			{
				ModelCorrections.Validate(mesh, correction);
				return true;
			}
			catch (InvalidDataException ex)
			{
				value.Add(correction, new object());
				Debug.LogWarning((object)("Miku Glider skipped incompatible correction asset for " + ((Object)mesh).name + ": " + ex.Message));
				return false;
			}
		}

		internal static AppliedMesh Prepare(Mesh mesh, MeshCorrection correction)
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00f9: 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_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			if (!Applied.TryGetValue(mesh, out var value))
			{
				value = new AppliedMesh
				{
					Correction = correction,
					OriginalWeights = mesh.boneWeights,
					Shapes = new int[correction.poses.Length]
				};
				BoneWeight[] array = (BoneWeight[])value.OriginalWeights.Clone();
				VertexWeightEdit[] weights = correction.weights;
				foreach (VertexWeightEdit vertexWeightEdit in weights)
				{
					array[vertexWeightEdit.vertex] = vertexWeightEdit.value;
				}
				for (int j = 0; j < correction.poses.Length; j++)
				{
					PoseShapeEdit poseShapeEdit = correction.poses[j];
					Vector3[] array2 = (Vector3[])(object)new Vector3[mesh.vertexCount];
					for (int k = 0; k < poseShapeEdit.vertices.Length; k++)
					{
						array2[poseShapeEdit.vertices[k]] = poseShapeEdit.deltas[k];
					}
					Vector3[] vertices = mesh.vertices;
					Vector3[] array3 = (Vector3[])vertices.Clone();
					for (int l = 0; l < array3.Length; l++)
					{
						ref Vector3 reference = ref array3[l];
						reference += array2[l];
					}
					Vector3[] arg = ModelPoseCorrections.CalculateNormalDeltas(vertices, array3, mesh.normals, mesh.triangles);
					value.Shapes[j] = mesh.blendShapeCount;
					AddShape(mesh, "MikuManual:" + poseShapeEdit.name, 100f, array2, arg, null);
				}
				mesh.boneWeights = array;
				Applied.Add(mesh, value);
			}
			return value;
		}
	}
	[DefaultExecutionOrder(1400)]
	internal sealed class ModelPoseCorrections : MonoBehaviour
	{
		private sealed class RejectedBinding
		{
			private readonly Mesh mesh;

			private readonly ModelCorrections profile;

			private readonly Transform[] bones;

			private readonly string[] names;

			internal RejectedBinding(Mesh mesh, ModelCorrections profile, Transform[] bones)
			{
				this.mesh = mesh;
				this.profile = profile;
				this.bones = bones;
				names = Array.ConvertAll(bones, (Transform bone) => (!((Object)(object)bone != (Object)null)) ? null : ((Object)bone).name);
			}

			internal bool Matches(Mesh mesh, ModelCorrections profile, Transform[] current)
			{
				if ((Object)(object)this.mesh != (Object)(object)mesh || this.profile != profile || bones.Length != current.Length)
				{
					return false;
				}
				for (int i = 0; i < bones.Length; i++)
				{
					if ((Object)(object)bones[i] != (Object)(object)current[i] || names[i] != (((Object)(object)current[i] != (Object)null) ? ((Object)current[i]).name : null))
					{
						return false;
					}
				}
				return true;
			}
		}

		private static readonly ConditionalWeakTable<SkinnedMeshRenderer, RejectedBinding> Rejected = new ConditionalWeakTable<SkinnedMeshRenderer, RejectedBinding>();

		private SkinnedMeshRenderer surface;

		private ModelCorrectionMeshes.AppliedMesh state;

		private ModelCorrections profile;

		private Transform[] bones;

		private float[] activations;

		private float[] handleContacts;

		private float[] appliedWeights;

		private int[] poseGroups;

		private float[] groupTotals;

		private Transform weaponRoot;

		private string weaponNamePrefix = "";

		private Transform[] weaponChildren = Array.Empty<Transform>();

		private string[] weaponNames = Array.Empty<string>();

		private Transform[] gripBones;

		private Transform[] renderedBones;

		private Quaternion[] gripOffsets;

		private bool gripBound;

		private Transform[] anchorTargets;

		private bool anchorsDirty = true;

		private FirstPersonWristVisual wrist;

		private RendererBoneBinding binding;

		internal bool UpdatesWrist
		{
			get
			{
				if (((Behaviour)this).enabled && state != null && (Object)(object)surface != (Object)null && GetApplied(surface.sharedMesh) == state && gripBones != null && gripBones.Length > 3)
				{
					return (Object)(object)gripBones[3] != (Object)null;
				}
				return false;
			}
		}

		internal Transform[] SourceBones => bones;

		internal static ModelCorrectionMeshes.AppliedMesh GetApplied(Mesh mesh)
		{
			return ModelCorrectionMeshes.GetApplied(mesh);
		}

		internal static void PrepareMeshChange(SkinnedMeshRenderer renderer)
		{
			if (!((Object)(object)renderer == (Object)null))
			{
				RendererBoneBinding.ReleaseSeated(renderer);
				((Component)renderer).GetComponent<ModelPoseCorrections>()?.ResetShapes();
				FirstPersonWristVisual.Attach(renderer, null);
			}
		}

		internal static void Attach(SkinnedMeshRenderer renderer, ModelCorrections profile, Transform weaponRoot = null, string weaponNamePrefix = "")
		{
			if ((Object)(object)renderer == (Object)null)
			{
				return;
			}
			RendererBoneBinding.ReleaseSeated(renderer);
			if ((Object)(object)renderer.sharedMesh == (Object)null || profile == null || profile.meshes.Length == 0)
			{
				((Component)renderer).GetComponent<ModelPoseCorrections>()?.ResetShapes();
				return;
			}
			Mesh sharedMesh = renderer.sharedMesh;
			if (Rejected.TryGetValue(renderer, out var value) && value.Matches(sharedMesh, profile, renderer.bones))
			{
				return;
			}
			try
			{
				AttachValidated(renderer, profile);
				ModelPoseCorrections component = ((Component)renderer).GetComponent<ModelPoseCorrections>();
				if (value != null && (Object)(object)component != (Object)null && component.state != null)
				{
					Rejected.Remove(renderer);
				}
				if ((Object)(object)component != (Object)null && ((Object)(object)component.weaponRoot != (Object)(object)weaponRoot || component.weaponNamePrefix != weaponNamePrefix))
				{
					component.weaponRoot = weaponRoot;
					component.weaponNamePrefix = weaponNamePrefix;
					component.weaponChildren = Array.Empty<Transform>();
					component.weaponNames = Array.Empty<string>();
					component.anchorsDirty = true;
				}
			}
			catch (Exception ex) when (ex is InvalidDataException || ex is InvalidOperationException)
			{
				((Component)renderer).GetComponent<ModelPoseCorrections>()?.ResetShapes();
				Rejected.Remove(renderer);
				Rejected.Add(renderer, new RejectedBinding(sharedMesh, profile, renderer.bones));
				Debug.LogWarning((object)("Miku Glider skipped incompatible manual corrections for " + ((Object)sharedMesh).name + ": " + ex.Message));
			}
		}

		private static void AttachValidated(SkinnedMeshRenderer renderer, ModelCorrections profile)
		{
			ModelPoseCorrections component = ((Component)renderer).GetComponent<ModelPoseCorrections>();
			Mesh sharedMesh = renderer.sharedMesh;
			ModelCorrectionMeshes.AppliedMesh applied = GetApplied(sharedMesh);
			if ((Object)(object)component != (Object)null && component.state != null && (Object)(object)component.surface.sharedMesh == (Object)(object)sharedMesh && applied == component.state && component.profile == profile && component.MatchesSource(renderer.bones))
			{
				component.BindGripBones(force: true);
				((Behaviour)component).enabled = applied.Shapes.Length != 0;
				return;
			}
			MeshCorrection meshCorrection = profile.Find(sharedMesh);
			if (meshCorrection == null)
			{
				if ((Object)(object)component != (Object)null)
				{
					component.ResetShapes();
				}
				return;
			}
			if ((Object)(object)component != (Object)null)
			{
				component.ReleaseGripBones();
			}
			if (!ModelCorrectionMeshes.Validate(sharedMesh, meshCorrection))
			{
				return;
			}
			Transform[] array = renderer.bones;
			if (array.Length < sharedMesh.bindposes.Length)
			{
				throw new InvalidOperationException("Correction skeleton has fewer bones than its mesh: " + meshCorrection.key);
			}
			PoseShapeEdit[] poses = meshCorrection.poses;
			foreach (PoseShapeEdit poseShapeEdit in poses)
			{
				if (poseShapeEdit.gripAnchor != null && (array.Length <= 3 || (Object)(object)array[3] == (Object)null || ((Object)array[3]).name != poseShapeEdit.gripAnchor.name))
				{
					throw new InvalidOperationException("Grip anchor skeleton differs: " + meshCorrection.key);
				}
				PoseGripAnchor gripAnchor = poseShapeEdit.gripAnchor;
				if (gripAnchor != null && gripAnchor.followArm && (Object)(object)array[0] == (Object)null)
				{
					throw new InvalidOperationException("Grip anchor requires an arm root: " + meshCorrection.key);
				}
				PoseShapeDriver[] drivers = poseShapeEdit.drivers;
				foreach (PoseShapeDriver poseShapeDriver in drivers)
				{
					if (poseShapeDriver == null || poseShapeDriver.bone < 0 || poseShapeDriver.bone >= array.Length || (Object)(object)array[poseShapeDriver.bone] == (Object)null || ((Object)array[poseShapeDriver.bone]).name != poseShapeDriver.name)
					{
						throw new InvalidOperationException("Pose correction skeleton differs: " + meshCorrection.key);
					}
				}
				PoseBoneRotation[] boneRotations = poseShapeEdit.boneRotations;
				foreach (PoseBoneRotation poseBoneRotation in boneRotations)
				{
					if (poseBoneRotation.bone < 0 || poseBoneRotation.bone >= array.Length || (Object)(object)array[poseBoneRotation.bone] == (Object)null || ((Object)array[poseBoneRotation.bone]).name != poseBoneRotation.name)
					{
						throw new InvalidOperationException("Finger correction skeleton differs: " + meshCorrection.key);
					}
				}
			}
			ModelCorrectionMeshes.AppliedMesh appliedMesh = ModelCorrectionMeshes.Prepare(sharedMesh, meshCorrection);
			ModelPoseCorrections modelPoseCorrections = component ?? ((Component)renderer).gameObject.AddComponent<ModelPoseCorrections>();
			modelPoseCorrections.surface = renderer;
			modelPoseCorrections.state = appliedMesh;
			modelPoseCorrections.profile = profile;
			modelPoseCorrections.bones = renderer.bones;
			modelPoseCorrections.wrist = ((Component)renderer).GetComponent<FirstPersonWristVisual>();
			if ((Object)(object)modelPoseCorrections.wrist != (Object)null)
			{
				modelPoseCorrections.wrist.PoseOwner = modelPoseCorrections;
			}
			modelPoseCorrections.anchorsDirty = true;
			modelPoseCorrections.CreateGripBones();
			modelPoseCorrections.activations = new float[appliedMesh.Shapes.Length];
			modelPoseCorrections.handleContacts = new float[appliedMesh.Shapes.Length];
			modelPoseCorrections.appliedWeights = new float[appliedMesh.Shapes.Length];
			modelPoseCorrections.poseGroups = new int[appliedMesh.Shapes.Length];
			Dictionary<string, int> dictionary = new Dictionary<string, int>();
			for (int k = 0; k < appliedMesh.Shapes.Length; k++)
			{
				string key = meshCorrection.poses[k].group ?? "";
				if (!dictionary.TryGetValue(key, out var value))
				{
					dictionary.Add(key, value = dictionary.Count);
				}
				modelPoseCorrections.poseGroups[k] = value;
			}
			modelPoseCorrections.groupTotals = new float[dictionary.Count];
			for (int l = 0; l < modelPoseCorrections.appliedWeights.Length; l++)
			{
				modelPoseCorrections.appliedWeights[l] = float.NaN;
			}
			((Behaviour)modelPoseCorrections).enabled = appliedMesh.Shapes.Length != 0;
		}

		private bool MatchesSource(Transform[] current)
		{
			if (!RendererBoneBinding.SameBones(current, renderedBones))
			{
				return RendererBoneBinding.SameBones(current, bones);
			}
			return true;
		}

		private void CreateGripBones()
		{
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			bool[] array = new bool[bones.Length];
			bool flag = false;
			PoseShapeEdit[] poses = state.Correction.poses;
			foreach (PoseShapeEdit poseShapeEdit in poses)
			{
				PoseBoneRotation[] boneRotations = poseShapeEdit.boneRotations;
				foreach (PoseBoneRotation poseBoneRotation in boneRotations)
				{
					array[poseBoneRotation.bone] = true;
					flag = true;
				}
				if (poseShapeEdit.gripAnchor != null && !poseShapeEdit.gripAnchor.weightOnly)
				{
					array[(!poseShapeEdit.gripAnchor.followArm) ? poseShapeEdit.gripAnchor.bone : 0] = true;
					flag = true;
				}
			}
			if (!flag)
			{
				return;
			}
			for (int k = 0; k < bones.Length; k++)
			{
				for (int l = 0; l < bones.Length; l++)
				{
					if (!((Object)(object)bones[l] == (Object)null) && !array[l])
					{
						int num = Array.IndexOf(bones, bones[l].parent);
						if (num >= 0 && array[num])
						{
							array[l] = true;
						}
					}
				}
			}
			gripBones = (Transform[])(object)new Transform[bones.Length];
			gripOffsets = (Quaternion[])(object)new Quaternion[bones.Length];
			renderedBones = (Transform[])bones.Clone();
			for (int m = 0; m < bones.Length; m++)
			{
				if (array[m])
				{
					Transform transform = new GameObject("Miku grip " + ((Object)bones[m]).name).transform;
					((Object)((Component)transform).gameObject).hideFlags = (HideFlags)52;
					gripBones[m] = (renderedBones[m] = transform);
				}
			}
			for (int n = 0; n < bones.Length; n++)
			{
				if ((Object)(object)gripBones[n] != (Object)null)
				{
					int num2 = Array.IndexOf(bones, bones[n].parent);
					gripBones[n].SetParent((num2 >= 0 && (Object)(object)gripBones[num2] != (Object)null) ? gripBones[num2] : bones[n].parent, false);
					CopyGripBone(n, Quaternion.identity);
				}
			}
			BindGripBones();
		}

		private void BindGripBones(bool force = false)
		{
			if ((Object)(object)surface != (Object)null && renderedBones != null && (force || !gripBound))
			{
				binding = RendererBoneBinding.For(surface);
				binding.SetGrip(renderedBones);
				gripBound = true;
			}
		}

		private void CopyGripBone(int i, Quaternion offset)
		{
			//IL_0010: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			gripBones[i].localPosition = bones[i].localPosition;
			gripBones[i].localRotation = bones[i].localRotation * offset;
			gripBones[i].localScale = bones[i].localScale;
		}

		private float HandleContact(PoseGripAnchor anchor, Transform target)
		{
			//IL_002b: 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_0042: 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_0060: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)target == (Object)null || !((Component)target).gameObject.activeInHierarchy)
			{
				return 0f;
			}
			Transform val = bones[anchor.bone];
			float num = Vector3.Distance(val.position, target.TransformPoint((Vector3)(((??)anchor.contactPosition) ?? anchor.position))) / Mathf.Max(0.0001f, val.lossyScale.x);
			float num2 = Mathf.InverseLerp(anchor.innerDistance, anchor.outerDistance, num);
			return 1f - num2 * num2 * (3f - 2f * num2);
		}

		private void UpdateGripBones()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: 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_007a: 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_00be: 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_00ca: 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_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_010c: 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_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: 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_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_037b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0380: Unknown result type (might be due to invalid IL or missing references)
			//IL_0385: Unknown result type (might be due to invalid IL or missing references)
			//IL_049c: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0424: Unknown result type (might be due to invalid IL or missing references)
			//IL_0428: Unknown result type (might be due to invalid IL or missing references)
			//IL_042d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0432: Unknown result type (might be due to invalid IL or missing references)
			//IL_0437: Unknown result type (might be due to invalid IL or missing references)
			//IL_043b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0440: Unknown result type (might be due to invalid IL or missing references)
			//IL_0444: Unknown result type (might be due to invalid IL or missing references)
			//IL_0449: Unknown result type (might be due to invalid IL or missing references)
			//IL_044d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0452: Unknown result type (might be due to invalid IL or missing references)
			//IL_0457: Unknown result type (might be due to invalid IL or missing references)
			//IL_045c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0460: Unknown result type (might be due to invalid IL or missing references)
			//IL_0464: Unknown result type (might be due to invalid IL or missing references)
			//IL_0469: Unknown result type (might be due to invalid IL or missing references)
			//IL_046e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0470: Unknown result type (might be due to invalid IL or missing references)
			//IL_0475: Unknown result type (might be due to invalid IL or missing references)
			//IL_0479: Unknown result type (might be due to invalid IL or missing references)
			//IL_047e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0402: Unknown result type (might be due to invalid IL or missing references)
			//IL_0407: Unknown result type (might be due to invalid IL or missing references)
			//IL_040c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0418: Unknown result type (might be due to invalid IL or missing references)
			if (gripBones == null)
			{
				return;
			}
			for (int i = 0; i < gripOffsets.Length; i++)
			{
				gripOffsets[i] = Quaternion.identity;
			}
			for (int j = 0; j < activations.Length; j++)
			{
				if (!(activations[j] > 0f))
				{
					continue;
				}
				PoseBoneRotation[] boneRotations = state.Correction.poses[j].boneRotations;
				foreach (PoseBoneRotation poseBoneRotation in boneRotations)
				{
					Quaternion val = (poseBoneRotation.contactRotation.HasValue ? Quaternion.Slerp(poseBoneRotation.rotation, poseBoneRotation.contactRotation.Value, handleContacts[j]) : poseBoneRotation.rotation);
					Quaternion val2 = (poseBoneRotation.absolute ? (Quaternion.Inverse(bones[poseBoneRotation.bone].localRotation) * val) : val);
					if (poseBoneRotation.motionReference.HasValue)
					{
						Quaternion localRotation = bones[poseBoneRotation.bone].localRotation;
						Quaternion value = poseBoneRotation.motionReference.Value;
						float num = Mathf.InverseLerp(0.5f, 2f, Quaternion.Angle(value, localRotation));
						float num2 = poseBoneRotation.motionFraction * num * num * (3f - 2f * num);
						Quaternion val3 = Quaternion.Slerp(value, localRotation, num2);
						val2 = Quaternion.Inverse(localRotation) * val3 * val;
					}
					ref Quaternion reference = ref gripOffsets[poseBoneRotation.bone];
					reference *= Quaternion.Slerp(Quaternion.identity, val2, activations[j] / Mathf.Max(1f, groupTotals[poseGroups[j]]));
				}
			}
			for (int l = 0; l < gripBones.Length; l++)
			{
				if ((Object)(object)gripBones[l] != (Object)null)
				{
					CopyGripBone(l, gripOffsets[l]);
				}
			}
			for (int m = 0; m < activations.Length; m++)
			{
				if (!(activations[m] > 0f))
				{
					continue;
				}
				PoseBoneRotation[] boneRotations = state.Correction.poses[m].boneRotations;
				foreach (PoseBoneRotation poseBoneRotation2 in boneRotations)
				{
					if (poseBoneRotation2.position.HasValue)
					{
						Transform obj = gripBones[poseBoneRotation2.bone];
						obj.localPosition += (poseBoneRotation2.position.Value - bones[poseBoneRotation2.bone].localPosition) * (activations[m] / Mathf.Max(1f, groupTotals[poseGroups[m]]));
					}
				}
			}
			for (int n = 0; n < activations.Length; n++)
			{
				PoseGripAnchor gripAnchor = state.Correction.poses[n].gripAnchor;
				if (gripAnchor == null || gripAnchor.weightOnly || anchorTargets == null || (Object)(object)anchorTargets[n] == (Object)null || activations[n] <= 0f)
				{
					continue;
				}
				Transform val4 = bones[gripAnchor.bone];
				Transform val5 = anchorTargets[n];
				Transform val6 = gripBones[gripAnchor.bone];
				Vector3 val7 = val5.TransformPoint(gripAnchor.position);
				float num3 = activations[n] / Mathf.Max(1f, groupTotals[poseGroups[n]]);
				if (gripAnchor.followArm)
				{
					Quaternion val8 = Quaternion.Slerp(val6.rotation, val5.rotation * gripAnchor.rotation, num3);
					Transform val9 = gripBones[0];
					if (gripAnchor.rotateAtWrist)
					{
						val9.position += num3 * (val7 - val6.position);
						val6.rotation = val8;
					}
					else
					{
						Quaternion val10 = val8 * Quaternion.Inverse(val6.rotation);
						Vector3 val11 = Vector3.Lerp(val6.position, val7, num3) - val10 * val6.position;
						val9.SetPositionAndRotation(val10 * val9.position + val11, val10 * val9.rotation);
					}
				}
				else
				{
					num3 *= handleContacts[n];
					val6.SetPositionAndRotation(Vector3.Lerp(val4.position, val7, num3), Quaternion.Slerp(val4.rotation, val5.rotation * gripAnchor.rotation, num3));
				}
			}
			if ((Object)(object)wrist != (Object)null && gripBones.Length > 3 && (Object)(object)gripBones[3] != (Object)null)
			{
				wrist.UpdatePose(gripBones[3], gripBones[1]);
			}
			BindGripBones();
		}

		private void RestoreSourceBones()
		{
			gripBound = false;
			binding?.ReleaseGrip();
			binding = null;
			if ((Object)(object)wrist != (Object)null)
			{
				wrist.UpdatePose();
			}
		}

		private void ReleaseGripBones()
		{
			RestoreSourceBones();
			if ((Object)(object)wrist != (Object)null && (Object)(object)wrist.PoseOwner == (Object)(object)this)
			{
				wrist.PoseOwner = null;
			}
			if (gripBones != null)
			{
				for (int i = 0; i < gripBones.Length; i++)
				{
					if ((Object)(object)gripBones[i] != (Object)null)
					{
						if (Application.isPlaying)
						{
							Object.Destroy((Object)(object)((Component)gripBones[i]).gameObject);
						}
						else
						{
							Object.DestroyImmediate((Object)(object)((Component)gripBones[i]).gameObject);
						}
					}
				}
			}
			gripBones = null;
			renderedBones = null;
			gripOffsets = null;
			anchorTargets = null;
			anchorsDirty = true;
		}

		internal static Vector3[] CalculateNormalDeltas(Vector3[] basis, Vector3[] target, Vector3[] shading, int[] triangles)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: 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_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_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_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: 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_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: 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)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: 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_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			Vector3[] array = (Vector3[])(object)new Vector3[basis.Length];
			Vector3[] array2 = (Vector3[])(object)new Vector3[basis.Length];
			for (int i = 0; i < triangles.Length; i += 3)
			{
				int num = triangles[i];
				int num2 = triangles[i + 1];
				int num3 = triangles[i + 2];
				Vector3 val = Vector3.Cross(basis[num2] - basis[num], basis[num3] - basis[num]);
				Vector3 val2 = Vector3.Cross(target[num2] - target[num], target[num3] - target[num]);
				ref Vector3 reference = ref array[num];
				reference += val;
				ref Vector3 reference2 = ref array[num2];
				reference2 += val;
				ref Vector3 reference3 = ref array[num3];
				reference3 += val;
				ref Vector3 reference4 = ref array2[num];
				reference4 += val2;
				ref Vector3 reference5 = ref array2[num2];
				reference5 += val2;
				ref Vector3 reference6 = ref array2[num3];
				reference6 += val2;
			}
			Dictionary<Vector3Int, List<int>> dictionary = new Dictionary<Vector3Int, List<int>>();
			for (int j = 0; j < basis.Length; j++)
			{
				Vector3Int key = Vector3Int.RoundToInt(basis[j] * 1000000f);
				if (!dictionary.TryGetValue(key, out var value))
				{
					dictionary.Add(key, value = new List<int>());
				}
				value.Add(j);
			}
			Vector3[] array3 = (Vector3[])(object)new Vector3[basis.Length];
			foreach (List<int> value2 in dictionary.Values)
			{
				foreach (int item in value2)
				{
					Vector3 val3 = Vector3.zero;
					Vector3 val4 = Vector3.zero;
					foreach (int item2 in value2)
					{
						if (Vector3.Dot(shading[item], shading[item2]) > 0.999f)
						{
							Vector3 val5 = target[item] - target[item2];
							if (((Vector3)(ref val5)).sqrMagnitude < 1E-10f)
							{
								val3 += array[item2];
								val4 += array2[item2];
							}
						}
					}
					float magnitude = ((Vector3)(ref val3)).magnitude;
					float magnitude2 = ((Vector3)(ref val4)).magnitude;
					if (magnitude > 1E-12f && magnitude2 > 1E-12f)
					{
						array3[item] = ((Vector3.Dot(val3, shading[item]) < 0f) ? (-1f) : 1f) * (val4 / magnitude2 - val3 / magnitude);
					}
				}
			}
			return array3;
		}

		internal static float Activation(PoseShapeEdit pose, Transform[] bones)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			float num = 1f;
			PoseShapeDriver[] drivers = pose.drivers;
			foreach (PoseShapeDriver poseShapeDriver in drivers)
			{
				if ((Object)(object)bones[poseShapeDriver.bone] == (Object)null)
				{
					return 0f;
				}
				float num2 = Quaternion.Angle(bones[poseShapeDriver.bone].localRotation, poseShapeDriver.rotation);
				float num3 = Mathf.InverseLerp(poseShapeDriver.innerRadius, poseShapeDriver.radius, num2);
				num = Mathf.Min(num, 1f - num3 * num3 * (3f - 2f * num3));
			}
			return num;
		}

		private void LateUpdate()
		{
			if ((Object)(object)surface == (Object)null || state == null || GetApplied(surface.sharedMesh) != state)
			{
				((Behaviour)this).enabled = false;
				return;
			}
			UpdateWeaponCache();
			Array.Clear(groupTotals, 0, groupTotals.Length);
			for (int i = 0; i < activations.Length; i++)
			{
				PoseShapeEdit poseShapeEdit = state.Correction.poses[i];
				string required = (string.IsNullOrEmpty(poseShapeEdit.weapon) ? state.Correction.weapon : poseShapeEdit.weapon);
				bool flag = MatchesWeapon(required);
				activations[i] = (flag ? Activation(poseShapeEdit, bones) : 0f);
				PoseGripAnchor gripAnchor = poseShapeEdit.gripAnchor;
				if (gripAnchor != null && flag && (activations[i] > 0f || gripAnchor.sustainOnContact))
				{
					if ((Object)(object)weaponRoot != (Object)null && (Object)(object)anchorTargets[i] == (Object)null)
					{
						anchorTargets[i] = weaponRoot.Find(gripAnchor.path);
					}
					float[] array = handleContacts;
					int num = i;
					Transform[] array2 = anchorTargets;
					array[num] = HandleContact(gripAnchor, (array2 != null) ? array2[i] : null);
					if (gripAnchor.sustainOnContact)
					{
						activations[i] = Mathf.Lerp(activations[i], 1f, handleContacts[i]);
					}
					else if (gripAnchor.followArm || gripAnchor.weightOnly)
					{
						activations[i] *= (gripAnchor.releaseOnly ? (1f - handleContacts[i]) : handleContacts[i]);
					}
				}
				groupTotals[poseGroups[i]] += activations[i];
			}
			UpdateGripBones();
			for (int j = 0; j < activations.Length; j++)
			{
				float num2 = activations[j] * 100f / Mathf.Max(1f, groupTotals[poseGroups[j]]);
				if (appliedWeights[j] != num2)
				{
					surface.SetBlendShapeWeight(state.Shapes[j], num2);
					appliedWeights[j] = num2;
				}
			}
		}

		private void UpdateWeaponCache()
		{
			if ((Object)(object)weaponRoot == (Object)null)
			{
				return;
			}
			int childCount = weaponRoot.childCount;
			if (weaponChildren.Length != childCount)
			{
				weaponChildren = (Transform[])(object)new Transform[childCount];
				weaponNames = new string[childCount];
				anchorsDirty = true;
			}
			for (int i = 0; i < childCount; i++)
			{
				Transform child = weaponRoot.GetChild(i);
				if ((Object)(object)weaponChildren[i] != (Object)(object)child)
				{
					weaponChildren[i] = child;
					anchorsDirty = true;
					string name = ((Object)child).name;
					weaponNames[i] = (name.StartsWith(weaponNamePrefix, StringComparison.Ordinal) ? name.Substring(weaponNamePrefix.Length) : name);
				}
			}
			if (!anchorsDirty)
			{
				return;
			}
			anchorTargets = (Transform[])(object)new Transform[state.Correction.poses.Length];
			for (int j = 0; j < anchorTargets.Length; j++)
			{
				PoseGripAnchor gripAnchor = state.Correction.poses[j].gripAnchor;
				if (gripAnchor == null)
				{
					continue;
				}
				anchorTargets[j] = weaponRoot.Find(gripAnchor.path);
				if (!((Object)(object)anchorTargets[j] == (Object)null) || string.IsNullOrEmpty(weaponNamePrefix))
				{
					continue;
				}
				string text = gripAnchor.path.Substring(gripAnchor.path.LastIndexOf('/') + 1);
				Transform[] componentsInChildren = ((Component)weaponRoot).GetComponentsInChildren<Transform>(true);
				foreach (Transform val in componentsInChildren)
				{
					if (((Object)val).name == weaponNamePrefix + text)
					{
						anchorTargets[j] = val;
						break;
					}
				}
			}
			anchorsDirty = false;
		}

		private bool MatchesWeapon(string required)
		{
			if (string.IsNullOrEmpty(required))
			{
				return true;
			}
			if ((Object)(object)weaponRoot == (Object)null)
			{
				return false;
			}
			for (int i = 0; i < weaponChildren.Length; i++)
			{
				if (weaponNames[i] == required && ((Component)weaponChildren[i]).gameObject.activeSelf)
				{
					return true;
				}
			}
			return false;
		}

		internal void ResetShapes()
		{
			if ((Object)(object)surface != (Object)null && state != null && GetApplied(surface.sharedMesh) == state)
			{
				int[] shapes = state.Shapes;
				foreach (int num in shapes)
				{
					surface.SetBlendShapeWeight(num, 0f);
				}
			}
			ReleaseGripBones();
			state = null;
			profile = null;
			((Behaviour)this).enabled = false;
		}

		private void OnDisable()
		{
			RestoreSourceBones();
			if ((Object)(object)surface != (Object)null && state != null && GetApplied(surface.sharedMesh) == state)
			{
				int[] shapes = state.Shapes;
				foreach (int num in shapes)
				{
					surface.SetBlendShapeWeight(num, 0f);
				}
			}
			if (appliedWeights != null)
			{
				for (int j = 0; j < appliedWeights.Length; j++)
				{
					appliedWeights[j] = float.NaN;
				}
			}
		}

		private void OnDestroy()
		{
			ReleaseGripBones();
		}
	}
	internal sealed class RendererBoneBinding
	{
		private static readonly ConditionalWeakTable<SkinnedMeshRenderer, RendererBoneBinding> Owners = new ConditionalWeakTable<SkinnedMeshRenderer, RendererBoneBinding>();

		private readonly SkinnedMeshRenderer renderer;

		private readonly Transform[] native;

		private Transform[] wrist;

		private Transform[] grip;

		private Transform[] seated;

		private Transform[] lastApplied;

		private RendererBoneBinding(SkinnedMeshRenderer renderer)
		{
			this.renderer = renderer;
			native = renderer.bones;
		}

		internal static RendererBoneBinding For(SkinnedMeshRenderer renderer)
		{
			return Owners.GetValue(renderer, (SkinnedMeshRenderer value) => new RendererBoneBinding(value));
		}

		internal bool Matches(Transform[] bones)
		{
			if (!SameBones(bones, lastApplied))
			{
				return SameBones(bones, native);
			}
			return true;
		}

		internal void SetWrist(Transform[] bones)
		{
			wrist = bones;
			Apply();
		}

		internal void SetGrip(Transform[] bones)
		{
			grip = bones;
			Apply();
		}

		internal void SetSeated(Transform[] bones)
		{
			seated = bones;
			Apply();
		}

		internal void ReleaseGrip()
		{
			grip = null;
			Restore();
		}

		internal void ReleaseWrist()
		{
			wrist = null;
			Restore();
		}

		internal void ReleaseSeated()
		{
			seated = null;
			Restore();
		}

		internal static Transform[] BeforeSeated(SkinnedMeshRenderer renderer, Transform[] fallback)
		{
			if (!Owners.TryGetValue(renderer, out var value))
			{
				return fallback;
			}
			return value.grip ?? value.wrist ?? value.native;
		}

		internal static Transform[] NativeBones(SkinnedMeshRenderer renderer)
		{
			Transform[] bones = renderer.bones;
			if (!Owners.TryGetValue(renderer, out var value) || !value.Matches(bones))
			{
				return bones;
			}
			return value.native;
		}

		internal static void ReleaseSeated(SkinnedMeshRenderer renderer)
		{
			if (Owners.TryGetValue(renderer, out var value) && value.seated != null)
			{
				value.ReleaseSeated();
			}
		}

		private void Apply()
		{
			lastApplied = seated ?? grip ?? wrist ?? native;
			renderer.bones = lastApplied;
		}

		private void Restore()
		{
			if ((Object)(object)renderer != (Object)null && SameBones(renderer.bones, lastApplied))
			{
				Apply();
			}
			if (wrist == null && grip == null && seated == null)
			{
				Owners.Remove(renderer);
			}
		}

		internal static bool SameBones(Transform[] a, Transform[] b)
		{
			if (a == null || b == null || a.Length != b.Length)
			{
				return false;
			}
			for (int i = 0; i < a.Length; i++)
			{
				if ((Object)(object)a[i] != (Object)(object)b[i])
				{
					return false;
				}
			}
			return true;
		}
	}
	internal sealed class SeatedArmPlayback
	{
		private enum ClipKind
		{
			Other,
			GenericSeat,
			Enter,
			Loop,
			Idle,
			Exit
		}

		private readonly Dictionary<AnimationClip, ClipKind> clips = new Dictionary<AnimationClip, ClipKind>();

		private readonly SeatedArmProfile profile;

		private readonly Transform[] arms;

		private readonly Transform idleBone;

		private readonly Quaternion[] pose;

		private float poseWeight;

		private float idleWeight;

		private float exitAmount;

		private float genericWeight;

		private ClipKind dest