Decompiled source of Frieren v0.1.8

Frieren.dll

Decompiled 4 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using Dissonance;
using GameNetcodeStuff;
using Microsoft.CodeAnalysis;
using ModelReplacement;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Frieren")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Frieren")]
[assembly: AssemblyTitle("Frieren")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace FrierenMod
{
	internal sealed class CapePose
	{
		private sealed class Panel
		{
			public Transform t;

			public Transform tip;

			public Vector3 rest;

			public Vector3 tipParent;

			public Vector3 delta;

			public Quaternion rotation;

			public int side;

			public int index;
		}

		private readonly Transform chest;

		private readonly Transform hips;

		private readonly Transform body;

		private readonly Transform[] upper = (Transform[])(object)new Transform[2];

		private readonly Transform[] lower = (Transform[])(object)new Transform[2];

		private readonly Transform[] hand = (Transform[])(object)new Transform[2];

		private readonly Panel[] panels;

		public int Count => panels.Length;

		public CapePose(Animator a)
		{
			panels = new Panel[0];
			if (!Object.op_Implicit((Object)(object)a) || !a.isHuman)
			{
				return;
			}
			body = ((Component)a).transform;
			chest = a.GetBoneTransform((HumanBodyBones)54);
			hips = a.GetBoneTransform((HumanBodyBones)0);
			upper[0] = a.GetBoneTransform((HumanBodyBones)13);
			upper[1] = a.GetBoneTransform((HumanBodyBones)14);
			lower[0] = a.GetBoneTransform((HumanBodyBones)15);
			lower[1] = a.GetBoneTransform((HumanBodyBones)16);
			hand[0] = a.GetBoneTransform((HumanBodyBones)17);
			hand[1] = a.GetBoneTransform((HumanBodyBones)18);
			panels = (from t in ((Component)a).GetComponentsInChildren<Transform>(true)
				where ((Object)t).name.StartsWith("FR_MantleAnchor_")
				select t).Select(delegate(Transform t)
			{
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				//IL_003f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0050: Unknown result type (might be due to invalid IL or missing references)
				//IL_0057: Unknown result type (might be due to invalid IL or missing references)
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				Transform val = t;
				for (int i = 0; i < 3; i++)
				{
					if (val.childCount <= 0)
					{
						break;
					}
					val = val.GetChild(0);
				}
				return new Panel
				{
					t = t,
					tip = val,
					tipParent = t.parent.InverseTransformPoint(val.position),
					rest = t.localPosition,
					rotation = t.localRotation,
					side = ((!((Object)t).name.Contains("_L_")) ? 1 : 0),
					index = int.Parse(((Object)t).name.Substring(((Object)t).name.Length - 2))
				};
			}).ToArray();
		}

		private static Vector3 Nearest(Vector3 p, Vector3 a, Vector3 b)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = b - a;
			return a + val * Mathf.Clamp01(Vector3.Dot(p - a, val) / Mathf.Max(((Vector3)(ref val)).sqrMagnitude, 1E-08f));
		}

		private static Vector3 Away(Vector3 p, Vector3 a, Vector3 b, float radius, Vector3 fallback)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Nearest(p, a, b);
			Vector3 val2 = p - val;
			if (((Vector3)(ref val2)).sqrMagnitude >= radius * radius)
			{
				return p;
			}
			return val + ((((Vector3)(ref val2)).sqrMagnitude > 1E-06f) ? ((Vector3)(ref val2)).normalized : fallback) * radius;
		}

		public void Frame(Animator a, float dt)
		{
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: 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)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: 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_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dd: 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_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_030e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: 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_0326: Unknown result type (might be due to invalid IL or missing references)
			//IL_0328: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0335: Unknown result type (might be due to invalid IL or missing references)
			//IL_033a: 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_0343: Unknown result type (might be due to invalid IL or missing references)
			//IL_0351: Unknown result type (might be due to invalid IL or missing references)
			//IL_0358: 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_0370: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)chest) || !Object.op_Implicit((Object)(object)hips) || !Object.op_Implicit((Object)(object)upper[0]) || !Object.op_Implicit((Object)(object)upper[1]) || !Object.op_Implicit((Object)(object)lower[0]) || !Object.op_Implicit((Object)(object)lower[1]) || !Object.op_Implicit((Object)(object)hand[0]) || !Object.op_Implicit((Object)(object)hand[1]))
			{
				return;
			}
			Vector3 val = upper[0].position - upper[1].position;
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			val = Vector3.ProjectOnPlane(chest.position - hips.position, normalized);
			Vector3 normalized2 = ((Vector3)(ref val)).normalized;
			if (((Vector3)(ref normalized)).sqrMagnitude < 0.9f || ((Vector3)(ref normalized2)).sqrMagnitude < 0.9f)
			{
				return;
			}
			Vector3 val2 = Vector3.Cross(normalized, normalized2);
			if (Vector3.Dot(body.forward, val2) < 0f)
			{
				val2 = -val2;
			}
			float num = Mathf.Max(0.001f, Mathf.Abs(body.lossyScale.x));
			float num2 = 1f - Mathf.Exp((0f - Mathf.Max(dt, 0f)) * 32f);
			Panel[] array = panels;
			foreach (Panel panel in array)
			{
				int side = panel.side;
				Vector3 position = upper[side].position;
				Vector3 position2 = lower[side].position;
				Vector3 position3 = hand[side].position;
				val = position2 - position;
				Vector3 normalized3 = ((Vector3)(ref val)).normalized;
				Vector3 val3 = ((side == 0) ? normalized : (-normalized));
				float num3 = Vector3.Dot(normalized3, normalized2);
				float num4 = Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(-0.87f, 0.52f, num3));
				bool flag = panel.index == 4 || panel.index == 7;
				Transform parent = panel.t.parent;
				Vector3 val4 = parent.TransformPoint(panel.tipParent);
				Vector3 val5 = ((panel.index == 1) ? val2 : ((panel.index == 10) ? (-val2) : val3));
				val = Vector3.ProjectOnPlane(normalized2 * 0.7f + val5 * 0.77f, normalized3);
				Vector3 val6 = ((Vector3)(ref val)).normalized;
				if (((Vector3)(ref val6)).sqrMagnitude < 0.1f)
				{
					val6 = val3;
				}
				float num5 = 0.059f * num;
				float radius = 0.057f * num;
				Vector3 val7 = Vector3.Lerp(position, position2, (panel.index == 7) ? 0.77f : ((panel.index == 4) ? 0.57f : 0.3f)) + val6 * (num5 + 0.02f * num);
				Vector3 val8 = Vector3.ClampMagnitude(Away(Away(Vector3.Lerp(val4, val7, num4 * (flag ? 0.84f : 0.44f)), position, position2, num5, val6), position2, position3, radius, val6) - val4, 0.34f * num);
				Vector3 val9 = parent.InverseTransformVector(val8);
				panel.delta = Vector3.Lerp(panel.delta, val9, num2);
				panel.t.localPosition = panel.rest + panel.delta;
				panel.t.localRotation = panel.rotation;
			}
		}
	}
	internal sealed class ClothSurface : IDisposable
	{
		private readonly SkinnedMeshRenderer render;

		private readonly Mesh original;

		private readonly Mesh working;

		private readonly Vector3[] rest;

		private readonly Vector3[] vertices;

		private readonly BoneWeight[] weights;

		private readonly Matrix4x4[] bind;

		private readonly Matrix4x4[] skin;

		private readonly Transform[] bones;

		private readonly Transform[] joint;

		private readonly Transform avatar;

		private readonly List<Vector4> mask = new List<Vector4>();

		private readonly List<int> cloth = new List<int>();

		private readonly List<int> boots = new List<int>();

		private readonly SurfaceSolve.Segment[] arms = new SurfaceSolve.Segment[4];

		private readonly SurfaceSolve.Segment[] legs = new SurfaceSolve.Segment[4];

		private bool dirty;

		private bool disposed;

		internal ClothSurface(SkinnedMeshRenderer r, Animator a)
		{
			//IL_015e: 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_0198: Unknown result type (might be due to invalid IL or missing references)
			render = r;
			original = r.sharedMesh;
			if (!Object.op_Implicit((Object)(object)original) || !original.isReadable || !Object.op_Implicit((Object)(object)a) || !a.isHuman)
			{
				throw new InvalidOperationException("No readable humanoid cloth mesh");
			}
			original.GetUVs(4, mask);
			if (mask.Count != original.vertexCount)
			{
				throw new InvalidOperationException("No garment weights");
			}
			rest = original.vertices;
			vertices = (Vector3[])rest.Clone();
			weights = original.boneWeights;
			bind = original.bindposes;
			bones = r.bones;
			if (bind.Length != bones.Length || weights.Length != rest.Length)
			{
				throw new InvalidOperationException("Skin data mismatch");
			}
			skin = (Matrix4x4[])(object)new Matrix4x4[bind.Length];
			for (int i = 0; i < mask.Count; i++)
			{
				if (Mathf.Max(mask[i].x, mask[i].y) > 0.08f)
				{
					cloth.Add(i);
				}
				if (mask[i].z > 0.5f)
				{
					boots.Add(i);
				}
			}
			if (cloth.Count < 80)
			{
				throw new InvalidOperationException("Garment weights incomplete");
			}
			avatar = ((Component)a).transform;
			HumanBodyBones[] array = new HumanBodyBones[14];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			joint = ((IEnumerable<HumanBodyBones>)(object)array).Select((Func<HumanBodyBones, Transform>)a.GetBoneTransform).ToArray();
			if (joint.Any((Transform x) => !Object.op_Implicit((Object)(object)x)))
			{
				throw new InvalidOperationException("Garment joint missing");
			}
			working = Object.Instantiate<Mesh>(original);
			((Object)working).name = ((Object)original).name + "_Cloth";
			working.MarkDynamic();
		}

		internal int Frame()
		{
			//IL_0073: 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_00b3: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: 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_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			if (disposed || !Object.op_Implicit((Object)(object)render) || !((Renderer)render).enabled || !((Component)render).gameObject.activeInHierarchy)
			{
				return 0;
			}
			if ((Object)(object)render.sharedMesh != (Object)(object)original && (Object)(object)render.sharedMesh != (Object)(object)working)
			{
				return 0;
			}
			float num = Mathf.Max(0.2f, Mathf.Abs(avatar.lossyScale.x));
			for (int i = 0; i < 2; i++)
			{
				int num2 = i * 3;
				arms[i * 2] = new SurfaceSolve.Segment(joint[num2].position, joint[num2 + 1].position, 0.065f * num);
				arms[i * 2 + 1] = new SurfaceSolve.Segment(joint[num2 + 1].position, joint[num2 + 2].position, 0.062f * num);
				legs[i * 2] = new SurfaceSolve.Segment(joint[num2 + 6].position, joint[num2 + 7].position, 0.077f * num);
				legs[i * 2 + 1] = new SurfaceSolve.Segment(joint[num2 + 7].position, joint[num2 + 8].position, 0.063f * num);
			}
			Vector3 val = joint[13].position - joint[12].position;
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			return Deform(arms, legs, normalized, num);
		}

		internal bool TrySoles(out Vector3 left, out Vector3 right)
		{
			//IL_0011: 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_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: 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_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			left = (right = new Vector3(0f, float.PositiveInfinity, 0f));
			if (disposed || !Object.op_Implicit((Object)(object)render) || !((Renderer)render).enabled || !((Component)render).gameObject.activeInHierarchy || boots.Count < 20)
			{
				return false;
			}
			UpdatePose();
			foreach (int boot in boots)
			{
				Vector3 val = WorldVertex(boot, rest[boot]);
				if (!Finite(val))
				{
					continue;
				}
				if (mask[boot].w > 0.5f)
				{
					if (val.y < left.y)
					{
						left = val;
					}
				}
				else if (val.y < right.y)
				{
					right = val;
				}
			}
			if (Finite(left))
			{
				return Finite(right);
			}
			return false;
		}

		internal void UpdatePose()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < skin.Length; i++)
			{
				skin[i] = (Object.op_Implicit((Object)(object)bones[i]) ? (bones[i].localToWorldMatrix * bind[i]) : Matrix4x4.zero);
			}
		}

		private Matrix4x4 VertexPose(int i)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00c2: Unknown result type (might be due to invalid IL or missing references)
			BoneWeight val = weights[i];
			Matrix4x4 zero = Matrix4x4.zero;
			Matrix4x4 val2 = skin[((BoneWeight)(ref val)).boneIndex0];
			Matrix4x4 val3 = skin[((BoneWeight)(ref val)).boneIndex1];
			Matrix4x4 val4 = skin[((BoneWeight)(ref val)).boneIndex2];
			Matrix4x4 val5 = skin[((BoneWeight)(ref val)).boneIndex3];
			for (int j = 0; j < 16; j++)
			{
				((Matrix4x4)(ref zero))[j] = ((Matrix4x4)(ref val2))[j] * ((BoneWeight)(ref val)).weight0 + ((Matrix4x4)(ref val3))[j] * ((BoneWeight)(ref val)).weight1 + ((Matrix4x4)(ref val4))[j] * ((BoneWeight)(ref val)).weight2 + ((Matrix4x4)(ref val5))[j] * ((BoneWeight)(ref val)).weight3;
			}
			return zero;
		}

		internal Vector3 WorldVertex(int i, Vector3 bindVertex)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			Matrix4x4 val = VertexPose(i);
			return ((Matrix4x4)(ref val)).MultiplyPoint3x4(bindVertex);
		}

		internal int Deform(SurfaceSolve.Segment[] arm, SurfaceSolve.Segment[] leg, Vector3 up, float scale)
		{
			//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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: 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_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_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: 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_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: 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_020e: 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)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			UpdatePose();
			int num = 0;
			foreach (int item in cloth)
			{
				Vector3 val = rest[item];
				vertices[item] = val;
				Matrix4x4 val2 = VertexPose(item);
				Vector3 val3 = ((Matrix4x4)(ref val2)).MultiplyPoint3x4(val);
				if (!Finite(val3))
				{
					continue;
				}
				Vector3 val4 = val3 - joint[12].position;
				if (((Vector3)(ref val4)).sqrMagnitude > 4f * scale * scale)
				{
					continue;
				}
				Vector4 val5 = mask[item];
				bool flag = val5.y > val5.x;
				val4 = Vector3.ProjectOnPlane(avatar.right * val.x + avatar.forward * (0f - val.y - 0.035f), up);
				Vector3 val6 = ((Vector3)(ref val4)).normalized;
				if (((Vector3)(ref val6)).sqrMagnitude < 0.5f)
				{
					val4 = Vector3.ProjectOnPlane(val3 - (flag ? joint[13] : joint[12]).position, up);
					val6 = ((Vector3)(ref val4)).normalized;
				}
				if (((Vector3)(ref val6)).sqrMagnitude < 0.5f)
				{
					val6 = avatar.forward;
				}
				if (flag)
				{
					val4 = val6 + up * 0.25f;
					val6 = ((Vector3)(ref val4)).normalized;
				}
				Vector3 val7 = val3;
				for (int i = 0; i < 3; i++)
				{
					SurfaceSolve.Segment[] array = (flag ? arm : leg);
					foreach (SurfaceSolve.Segment s in array)
					{
						val7 = SurfaceSolve.Project(val7, val6, s, 0.017f * scale);
					}
				}
				val4 = val7 - val3;
				if (((Vector3)(ref val4)).sqrMagnitude < 1E-09f || Mathf.Abs(((Matrix4x4)(ref val2)).determinant) < 1E-05f)
				{
					continue;
				}
				float num2 = Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(0.08f, 0.5f, Mathf.Max(val5.x, val5.y)));
				Vector3 val8 = val3 + Vector3.ClampMagnitude(val7 - val3, 0.24f * scale) * num2;
				Matrix4x4 inverse = ((Matrix4x4)(ref val2)).inverse;
				Vector3 val9 = ((Matrix4x4)(ref inverse)).MultiplyPoint3x4(val8);
				if (Finite(val9))
				{
					val4 = val9 - val;
					if (!(((Vector3)(ref val4)).sqrMagnitude > 0.36f))
					{
						vertices[item] = val9;
						num++;
					}
				}
			}
			if (num > 0 || dirty)
			{
				working.SetVertices(vertices, 0, vertices.Length, (MeshUpdateFlags)8);
				if ((Object)(object)render.sharedMesh != (Object)(object)working)
				{
					render.sharedMesh = working;
				}
			}
			dirty = num > 0;
			return num;
		}

		private static bool Finite(Vector3 v)
		{
			if (!float.IsNaN(((Vector3)(ref v)).sqrMagnitude))
			{
				return !float.IsInfinity(((Vector3)(ref v)).sqrMagnitude);
			}
			return false;
		}

		public void Dispose()
		{
			if (!disposed)
			{
				disposed = true;
				if (Object.op_Implicit((Object)(object)render) && (Object)(object)render.sharedMesh == (Object)(object)working)
				{
					render.sharedMesh = original;
				}
				if (Application.isPlaying)
				{
					Object.Destroy((Object)(object)working);
				}
				else
				{
					Object.DestroyImmediate((Object)(object)working);
				}
			}
		}
	}
	internal sealed class DressContact
	{
		private class Panel
		{
			public Transform anchor;

			public Quaternion rest;

			public Quaternion filtered = Quaternion.identity;

			public Vector3 far;

			public Vector3 mid;

			public Vector3 outwards;
		}

		private readonly Animator avatar;

		private readonly Transform[] hips = (Transform[])(object)new Transform[2];

		private readonly Transform[] knees = (Transform[])(object)new Transform[2];

		private readonly Transform[] ankles = (Transform[])(object)new Transform[2];

		private readonly Panel[] panels;

		public int Count => panels.Length;

		public DressContact(Animator a)
		{
			DressContact dressContact = this;
			avatar = a;
			panels = new Panel[0];
			if (Object.op_Implicit((Object)(object)a) && a.isHuman)
			{
				hips[0] = a.GetBoneTransform((HumanBodyBones)1);
				hips[1] = a.GetBoneTransform((HumanBodyBones)2);
				knees[0] = a.GetBoneTransform((HumanBodyBones)3);
				knees[1] = a.GetBoneTransform((HumanBodyBones)4);
				ankles[0] = a.GetBoneTransform((HumanBodyBones)5);
				ankles[1] = a.GetBoneTransform((HumanBodyBones)6);
				Transform center = a.GetBoneTransform((HumanBodyBones)0);
				panels = (from t in ((Component)a).GetComponentsInChildren<Transform>(true)
					where ((Object)t).name.StartsWith("FR_DressAnchor_")
					select t).Select(delegate(Transform t)
				{
					//IL_0035: Unknown result type (might be due to invalid IL or missing references)
					//IL_0047: Unknown result type (might be due to invalid IL or missing references)
					//IL_004c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0051: Unknown result type (might be due to invalid IL or missing references)
					//IL_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_0068: Unknown result type (might be due to invalid IL or missing references)
					//IL_0073: Unknown result type (might be due to invalid IL or missing references)
					//IL_0078: Unknown result type (might be due to invalid IL or missing references)
					//IL_007d: Unknown result type (might be due to invalid IL or missing references)
					//IL_007e: 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_0087: 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_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_00a8: Unknown result type (might be due to invalid IL or missing references)
					//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
					//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
					//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
					//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
					//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
					//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
					//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
					//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
					//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
					//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
					//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
					//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
					//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
					//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
					Transform child = t.GetChild(0).GetChild(0).GetChild(0);
					Transform val = ((child.childCount > 0) ? child.GetChild(0) : child);
					Vector3 val2 = dressContact.hips[0].position - dressContact.hips[1].position;
					Vector3 normalized = ((Vector3)(ref val2)).normalized;
					val2 = Vector3.ProjectOnPlane(a.GetBoneTransform((HumanBodyBones)54).position - center.position, normalized);
					Vector3 normalized2 = ((Vector3)(ref val2)).normalized;
					Panel obj = new Panel
					{
						anchor = t,
						rest = t.localRotation,
						far = t.InverseTransformPoint(val.position),
						mid = t.InverseTransformPoint(child.position)
					};
					val2 = Vector3.ProjectOnPlane(val.position - center.position, normalized2);
					obj.outwards = t.InverseTransformDirection(((Vector3)(ref val2)).normalized);
					return obj;
				}).ToArray();
			}
		}

		private static Vector3 Outside(Vector3 p, Vector3 start, Vector3 end, float radius, Vector3 outward)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0089: 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_008e: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = end - start;
			Vector3 val2 = start + val * Mathf.Clamp01(Vector3.Dot(p - start, val) / Mathf.Max(((Vector3)(ref val)).sqrMagnitude, 1E-08f));
			Vector3 val3 = p - val2;
			if (((Vector3)(ref val3)).sqrMagnitude >= radius * radius)
			{
				return p;
			}
			Vector3 val4 = Vector3.ProjectOnPlane(outward, ((Vector3)(ref val)).normalized);
			Vector3 val5 = ((Vector3)(ref val4)).normalized;
			if (((Vector3)(ref val5)).sqrMagnitude < 0.5f)
			{
				val5 = ((((Vector3)(ref val3)).sqrMagnitude > 1E-06f) ? ((Vector3)(ref val3)).normalized : outward);
			}
			float num = Vector3.Dot(val3, val5);
			return p + val5 * (0f - num + Mathf.Sqrt(Mathf.Max(0f, num * num + radius * radius - ((Vector3)(ref val3)).sqrMagnitude)));
		}

		public void Frame(float dt)
		{
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: 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_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: 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_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: 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_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: 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_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_02c2: 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_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: 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_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: 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_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: 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_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_0245: 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_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)avatar) || hips.Any((Transform t) => !Object.op_Implicit((Object)(object)t)) || knees.Any((Transform t) => !Object.op_Implicit((Object)(object)t)) || ankles.Any((Transform t) => !Object.op_Implicit((Object)(object)t)))
			{
				return;
			}
			float num = Mathf.Abs(((Component)avatar).transform.lossyScale.x);
			float num2 = 1f - Mathf.Exp((0f - Mathf.Max(0f, dt)) * 29f);
			Panel[] array = panels;
			foreach (Panel panel in array)
			{
				Transform anchor = panel.anchor;
				Transform parent = anchor.parent;
				Vector3 position = anchor.position;
				Quaternion val = parent.rotation * panel.rest;
				Vector3 outward = val * panel.outwards;
				Vector3 val2 = anchor.TransformPoint(panel.far) - position;
				val2 = val * Quaternion.Inverse(anchor.rotation) * val2;
				Vector3 val3 = anchor.TransformPoint(panel.mid) - position;
				val3 = val * Quaternion.Inverse(anchor.rotation) * val3;
				Quaternion val4 = Quaternion.identity;
				for (int num4 = 0; num4 < 5; num4++)
				{
					for (int num5 = 0; num5 < 2; num5++)
					{
						Vector3 val5 = val4 * ((num5 == 0) ? val2 : val3);
						Vector3 val6 = position + val5;
						Vector3 val7 = val6;
						for (int num6 = 0; num6 < 2; num6++)
						{
							val7 = Outside(val7, hips[num6].position, knees[num6].position, 0.077f * num, outward);
							val7 = Outside(val7, knees[num6].position, ankles[num6].position, 0.064f * num, outward);
						}
						Vector3 val8 = val7 - val6;
						if (((Vector3)(ref val8)).sqrMagnitude > 1E-08f)
						{
							val4 = Quaternion.FromToRotation(val5, val7 - position) * val4;
						}
					}
				}
				val4 = Quaternion.RotateTowards(Quaternion.identity, val4, 38f);
				Quaternion val9 = Quaternion.Inverse(parent.rotation) * val4 * parent.rotation;
				panel.filtered = Quaternion.Slerp(panel.filtered, val9, num2);
				anchor.localRotation = panel.filtered * panel.rest;
			}
		}
	}
	[BepInPlugin("dtopaz.frieren", "Frieren", "0.1.8")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		internal static GameObject Prefab;

		internal static Texture2D Atlas;

		private AssetBundle bundle;

		private void Awake()
		{
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Expected O, but got Unknown
			string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "frieren");
			if (!File.Exists(text))
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Frieren asset bundle not found.");
				return;
			}
			bundle = AssetBundle.LoadFromFile(text);
			if (!Object.op_Implicit((Object)(object)bundle))
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Cannot load Frieren asset bundle.");
				return;
			}
			Prefab = bundle.LoadAsset<GameObject>("assets/frieren/frieren.prefab");
			if (!Object.op_Implicit((Object)(object)Prefab))
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Frieren prefab not found.");
				return;
			}
			using (Stream stream = typeof(Plugin).Assembly.GetManifestResourceStream("FrierenMod.Atlas.png"))
			{
				using MemoryStream memoryStream = new MemoryStream();
				stream.CopyTo(memoryStream);
				Atlas = new Texture2D(2, 2, (TextureFormat)3, true, false);
				if (!ImageConversion.LoadImage(Atlas, memoryStream.ToArray(), true))
				{
					Object.Destroy((Object)(object)Atlas);
					((BaseUnityPlugin)this).Logger.LogError((object)"Frieren atlas invalid.");
					return;
				}
				((Object)Atlas).name = "FrierenAtlasEmbedded";
				((Texture)Atlas).anisoLevel = 4;
			}
			ModelReplacementAPI.RegisterSuitModelReplacement("Frieren", typeof(FrierenBody));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Frieren: registered separate suit.");
		}
	}
	public sealed class FrierenBody : BodyReplacementBase
	{
		private readonly VoiceFace voice = new VoiceFace();

		private Material material;

		private GameObject boundModel;

		private GameObject boundCorpse;

		private Animator boundAnimator;

		private CapePose cape;

		private DressContact skirt;

		private ClothSurface surface;

		private Transform left;

		private Transform right;

		private Transform baseLeft;

		private Transform baseRight;

		private bool logged;

		private bool clothLogged;

		private bool deckLogged;

		private readonly ShipFootOffset shipFeet = new ShipFootOffset();

		private CharacterController hull;

		private readonly RaycastHit[] soleHits = (RaycastHit[])(object)new RaycastHit[16];

		private Transform[] soles;

		protected override GameObject LoadAssetsAndReturnModel()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			Plugin.Prefab.transform.localScale = Vector3.one;
			return Plugin.Prefab;
		}

		public override void LateUpdate()
		{
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0300: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_0319: Unknown result type (might be due to invalid IL or missing references)
			//IL_031e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			shipFeet.Restore();
			((BodyReplacementBase)this).LateUpdate();
			if (Object.op_Implicit((Object)(object)base.replacementModel) && Object.op_Implicit((Object)(object)((BodyReplacementBase)this).controller))
			{
				if ((Object)(object)boundModel != (Object)(object)base.replacementModel)
				{
					boundModel = base.replacementModel;
					hull = ((Component)((BodyReplacementBase)this).controller).GetComponent<CharacterController>();
					boundAnimator = boundModel.GetComponentInChildren<Animator>(true);
					cape = new CapePose(boundAnimator);
					skirt = new DressContact(boundAnimator);
					soles = (from t in boundModel.GetComponentsInChildren<Transform>(true)
						where ((Object)t).name.StartsWith("FR_Sole_", StringComparison.Ordinal)
						select t).ToArray();
					left = Toe(boundAnimator, (HumanBodyBones)19, (HumanBodyBones)5);
					right = Toe(boundAnimator, (HumanBodyBones)20, (HumanBodyBones)6);
					SkinnedMeshRenderer val = (Object.op_Implicit((Object)(object)((BodyReplacementBase)this).controller.thisPlayerModel) ? ((Component)((BodyReplacementBase)this).controller.thisPlayerModel).GetComponent<SkinnedMeshRenderer>() : null);
					Material vanilla = (Object.op_Implicit((Object)(object)val) ? ((Renderer)val).sharedMaterial : null);
					if (!Object.op_Implicit((Object)(object)material) && Object.op_Implicit((Object)(object)Plugin.Atlas))
					{
						material = CreateAtlasMaterial(vanilla);
					}
					Animator playerBodyAnimator = ((BodyReplacementBase)this).controller.playerBodyAnimator;
					baseLeft = Toe(playerBodyAnimator, (HumanBodyBones)19, (HumanBodyBones)5);
					baseRight = Toe(playerBodyAnimator, (HumanBodyBones)20, (HumanBodyBones)6);
					Apply(boundModel);
					surface?.Dispose();
					surface = null;
					try
					{
						SkinnedMeshRenderer val2 = ((IEnumerable<SkinnedMeshRenderer>)boundModel.GetComponentsInChildren<SkinnedMeshRenderer>(true)).FirstOrDefault((Func<SkinnedMeshRenderer, bool>)((SkinnedMeshRenderer r) => Object.op_Implicit((Object)(object)r.sharedMesh) && r.sharedMesh.GetBlendShapeIndex("FR_Blink") >= 0));
						if (Object.op_Implicit((Object)(object)val2))
						{
							surface = new ClothSurface(val2, boundAnimator);
						}
					}
					catch (Exception ex)
					{
						Debug.LogWarning((object)("[Frieren] Optional cloth surface unavailable: " + ex.Message));
					}
					Apply(base.replacementViewModel);
					if (Object.op_Implicit((Object)(object)base.replacementModelShadow))
					{
						Ground(base.replacementModelShadow, main: false);
					}
					if (!logged)
					{
						logged = true;
						SkinnedMeshRenderer componentInChildren = boundModel.GetComponentInChildren<SkinnedMeshRenderer>(true);
						Transform val3 = Toe(boundAnimator, (HumanBodyBones)10, (HumanBodyBones)10);
						Transform val4 = Toe(boundAnimator, (HumanBodyBones)0, (HumanBodyBones)0);
						if (Object.op_Implicit((Object)(object)componentInChildren) && Object.op_Implicit((Object)(object)val3) && Object.op_Implicit((Object)(object)val4))
						{
							string[] obj = new string[10]
							{
								"[Frieren] Runtime rig: torso=",
								Vector3.Distance(val3.position, val4.position).ToString("F2"),
								", bounds=",
								null,
								null,
								null,
								null,
								null,
								null,
								null
							};
							Bounds bounds = ((Renderer)componentInChildren).bounds;
							obj[3] = ((object)((Bounds)(ref bounds)).size/*cast due to .constrained prefix*/).ToString();
							obj[4] = ", meshOffset=";
							bounds = ((Renderer)componentInChildren).bounds;
							obj[5] = ((object)(((Bounds)(ref bounds)).center - ((Component)((BodyReplacementBase)this).controller).transform.position)/*cast due to .constrained prefix*/).ToString();
							obj[6] = ", layer=";
							obj[7] = ((Component)componentInChildren).gameObject.layer.ToString();
							obj[8] = ", enabled=";
							obj[9] = ((Renderer)componentInChildren).enabled.ToString();
							Debug.Log((object)string.Concat(obj));
						}
					}
				}
				if (((BodyReplacementBase)this).controller.isInHangarShipRoom)
				{
					ShipGround();
				}
				else
				{
					Ground(boundModel, main: true);
				}
				cape?.Frame(boundAnimator, Time.deltaTime);
				skirt?.Frame(Time.deltaTime);
				if (surface != null && !((BodyReplacementBase)this).controller.isPlayerDead)
				{
					try
					{
						int num = surface.Frame();
						if (num > 0 && !clothLogged)
						{
							clothLogged = true;
							Debug.Log((object)("[Frieren] Cloth surface active on original renderer: " + num + " corrected vertices."));
						}
					}
					catch (Exception ex2)
					{
						surface.Dispose();
						surface = null;
						Debug.LogWarning((object)("[Frieren] Reverted optional cloth surface: " + ex2.Message));
					}
				}
			}
			if (Object.op_Implicit((Object)(object)base.replacementDeadBody) && (Object)(object)boundCorpse != (Object)(object)base.replacementDeadBody)
			{
				boundCorpse = base.replacementDeadBody;
				Apply(boundCorpse);
			}
			voice.Frame(base.replacementModel, base.replacementModelShadow, base.replacementViewModel, ((BodyReplacementBase)this).controller);
		}

		private void ShipGround()
		{
			//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_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_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: 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)
			if (surface == null || ((BodyReplacementBase)this).controller.isPlayerDead || !surface.TrySoles(out var val, out var val2))
			{
				return;
			}
			Vector3 position = ((Component)((BodyReplacementBase)this).controller).transform.position;
			if (Object.op_Implicit((Object)(object)hull) && ((Collider)hull).enabled)
			{
				Bounds bounds = ((Collider)hull).bounds;
				if (Mathf.Abs(((Bounds)(ref bounds)).min.y - position.y) < 1.15f)
				{
					((Vector3)(ref position))..ctor(((Bounds)(ref bounds)).center.x, ((Bounds)(ref bounds)).min.y, ((Bounds)(ref bounds)).center.z);
				}
			}
			float floorY;
			float num = shipFeet.Apply(boundModel.transform, ((Component)((BodyReplacementBase)this).controller).transform, position, val, val2, out floorY);
			if (num > 0f && !deckLogged)
			{
				deckLogged = true;
				Debug.Log((object)$"[Frieren] Deck contact: lowest sole {Mathf.Min(val.y, val2.y) - floorY:F3}m from deck, visual lift {num:F3}m.");
			}
		}

		private static Material CreateAtlasMaterial(Material vanilla)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Expected O, but got Unknown
			//IL_007f: 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_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			Shader val = ((Object.op_Implicit((Object)(object)vanilla) && Object.op_Implicit((Object)(object)vanilla.shader) && ((Object)vanilla.shader).name == "HDRP/Lit") ? vanilla.shader : Shader.Find("HDRP/Lit"));
			if (!Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)vanilla))
			{
				val = vanilla.shader;
			}
			if (!Object.op_Implicit((Object)(object)val))
			{
				return null;
			}
			Material val2 = ((Object.op_Implicit((Object)(object)vanilla) && (Object)(object)vanilla.shader == (Object)(object)val) ? new Material(vanilla) : new Material(val));
			((Object)val2).name = "FrierenOpaque";
			string[] array = new string[2] { "_BaseColorMap", "_MainTex" };
			foreach (string text in array)
			{
				if (val2.HasProperty(text))
				{
					val2.SetTexture(text, (Texture)(object)Plugin.Atlas);
					val2.SetTextureScale(text, Vector2.one);
					val2.SetTextureOffset(text, Vector2.zero);
				}
			}
			array = new string[3] { "_BaseColor", "_Color", "_UnlitColor" };
			foreach (string text2 in array)
			{
				if (val2.HasProperty(text2))
				{
					val2.SetColor(text2, Color.white);
				}
			}
			array = new string[11]
			{
				"_MaskMap", "_NormalMap", "_NormalMapOS", "_DetailMap", "_BentNormalMap", "_BentNormalMapOS", "_EmissiveColorMap", "_AnisotropyMap", "_CoatMaskMap", "_HeightMap",
				"_DistortionVectorMap"
			};
			foreach (string text3 in array)
			{
				if (val2.HasProperty(text3))
				{
					val2.SetTexture(text3, (Texture)null);
				}
			}
			array = new string[17]
			{
				"_SURFACE_TYPE_TRANSPARENT", "_ALPHATEST_ON", "_BLENDMODE_ALPHA", "_BLENDMODE_ADD", "_BLENDMODE_PRE_MULTIPLY", "_ENABLE_FOG_ON_TRANSPARENT", "_TRANSPARENT_WRITES_MOTION_VEC", "_MASKMAP", "_NORMALMAP", "_NORMALMAP_TANGENT_SPACE",
				"_DETAIL_MAP", "_EMISSIVE_COLOR_MAP", "_BENTNORMALMAP", "_HEIGHTMAP", "_MATERIAL_FEATURE_SUBSURFACE_SCATTERING", "_MATERIAL_FEATURE_TRANSMISSION", "_ENABLE_GEOMETRIC_SPECULAR_AA"
			};
			foreach (string text4 in array)
			{
				val2.DisableKeyword(text4);
			}
			array = new string[17]
			{
				"_SurfaceType", "_AlphaCutoffEnable", "_TransparentZWrite", "_TransparentDepthPrepassEnable", "_TransparentDepthPostpassEnable", "_BlendMode", "_CullMode", "_CullModeForward", "_CullModeForDepth", "_OpaqueCullMode",
				"_Metallic", "_EnableBlendModePreserveSpecularLighting", "_EnableFogOnTransparent", "_UseEmissiveIntensity", "_EmissiveIntensity", "_EnableSpecularOcclusion", "_CoatMask"
			};
			foreach (string text5 in array)
			{
				if (val2.HasProperty(text5))
				{
					val2.SetFloat(text5, 0f);
				}
			}
			array = new string[5] { "_ZWrite", "_AlphaDstBlendIgnored", "_SrcBlend", "_AlphaSrcBlend", "_DoubleSidedEnable" };
			foreach (string text6 in array)
			{
				if (val2.HasProperty(text6))
				{
					val2.SetFloat(text6, 1f);
				}
			}
			array = new string[2] { "_DstBlend", "_AlphaDstBlend" };
			foreach (string text7 in array)
			{
				if (val2.HasProperty(text7))
				{
					val2.SetFloat(text7, 0f);
				}
			}
			array = new string[3] { "_ZTestDepthEqualForOpaque", "_ZTestGBuffer", "_ZTestTransparent" };
			foreach (string text8 in array)
			{
				if (val2.HasProperty(text8))
				{
					val2.SetFloat(text8, 4f);
				}
			}
			if (val2.HasProperty("_Smoothness"))
			{
				val2.SetFloat("_Smoothness", 0.27f);
			}
			val2.EnableKeyword("_DOUBLESIDED_ON");
			val2.SetOverrideTag("RenderType", "Opaque");
			val2.renderQueue = 2000;
			array = new string[6] { "Forward", "ForwardOnly", "GBuffer", "DepthOnly", "DepthForwardOnly", "ShadowCaster" };
			foreach (string text9 in array)
			{
				val2.SetShaderPassEnabled(text9, true);
			}
			array = new string[4] { "TransparentDepthPrepass", "TransparentDepthPostpass", "TransparentBackface", "DistortionVectors" };
			foreach (string text10 in array)
			{
				val2.SetShaderPassEnabled(text10, false);
			}
			return val2;
		}

		private void Apply(GameObject o)
		{
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)o) || !Object.op_Implicit((Object)(object)material))
			{
				return;
			}
			SkinnedMeshRenderer[] componentsInChildren = o.GetComponentsInChildren<SkinnedMeshRenderer>(true);
			foreach (SkinnedMeshRenderer val in componentsInChildren)
			{
				if (Object.op_Implicit((Object)(object)val.sharedMesh) && (((Object)val.sharedMesh).name.StartsWith("FrierenMesh", StringComparison.Ordinal) || val.sharedMesh.GetBlendShapeIndex("FR_Blink") >= 0))
				{
					Material[] sharedMaterials = ((Renderer)val).sharedMaterials;
					for (int j = 0; j < sharedMaterials.Length; j++)
					{
						sharedMaterials[j] = material;
					}
					((Renderer)val).sharedMaterials = sharedMaterials;
					if (!logged)
					{
						Debug.Log((object)("[Frieren] Opaque material applied: " + ((Object)material.shader).name + ", queue " + material.renderQueue + ", texture " + ((object)Plugin.Atlas.format/*cast due to .constrained prefix*/).ToString()));
					}
				}
			}
		}

		private static Transform Toe(Animator a, HumanBodyBones toe, HumanBodyBones foot)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)a) || !a.isHuman)
			{
				return null;
			}
			Transform boneTransform = a.GetBoneTransform(toe);
			if (!Object.op_Implicit((Object)(object)boneTransform))
			{
				return a.GetBoneTransform(foot);
			}
			return boneTransform;
		}

		private void Ground(GameObject obj, bool main)
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: 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_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: 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_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: 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_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: 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_0283: 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_022a: 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)
			if (!Object.op_Implicit((Object)(object)baseLeft) || !Object.op_Implicit((Object)(object)baseRight) || !Object.op_Implicit((Object)(object)obj) || !Object.op_Implicit((Object)(object)((BodyReplacementBase)this).controller) || ((BodyReplacementBase)this).controller.isPlayerDead)
			{
				return;
			}
			Animator a = (main ? boundAnimator : obj.GetComponentInChildren<Animator>(true));
			Transform val = (main ? left : Toe(a, (HumanBodyBones)19, (HumanBodyBones)5));
			Transform val2 = (main ? right : Toe(a, (HumanBodyBones)20, (HumanBodyBones)6));
			if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val2))
			{
				return;
			}
			float num = Mathf.Min(val.position.y, val2.position.y) - 0.035f;
			if (main && soles != null && soles.Length != 0)
			{
				num = float.PositiveInfinity;
				Transform[] array = soles;
				foreach (Transform val3 in array)
				{
					if (Object.op_Implicit((Object)(object)val3))
					{
						num = Mathf.Min(num, val3.position.y);
					}
				}
				if (float.IsInfinity(num))
				{
					return;
				}
			}
			Vector3 val4 = ((baseLeft.position.y <= baseRight.position.y) ? baseLeft.position : baseRight.position);
			float num2 = val4.y + 0.018f;
			if (main)
			{
				int num3 = Physics.RaycastNonAlloc(val4 + Vector3.up * 0.29f, Vector3.down, soleHits, 0.73f, -5, (QueryTriggerInteraction)1);
				float num4 = float.NegativeInfinity;
				for (int j = 0; j < num3; j++)
				{
					RaycastHit val5 = soleHits[j];
					Collider collider = ((RaycastHit)(ref val5)).collider;
					if (Object.op_Implicit((Object)(object)collider) && !(((RaycastHit)(ref val5)).normal.y < 0.58f) && !((Component)collider).transform.IsChildOf(((Component)((BodyReplacementBase)this).controller).transform) && !((Component)collider).transform.IsChildOf(obj.transform) && (!Object.op_Implicit((Object)(object)collider.attachedRigidbody) || collider.attachedRigidbody.isKinematic))
					{
						float num5 = val4.y - ((RaycastHit)(ref val5)).point.y;
						if (!(num5 < -0.1f) && !(num5 > 0.28f))
						{
							num4 = Mathf.Max(num4, ((RaycastHit)(ref val5)).point.y);
						}
					}
				}
				if (!float.IsInfinity(num4))
				{
					num2 = num4 + 0.012f + Mathf.Max(0f, val4.y - num4 - 0.095f);
				}
			}
			float num6 = num2 - num;
			if (Mathf.Abs(num6) < 0.62f)
			{
				Transform transform = obj.transform;
				transform.position += Vector3.up * Mathf.Clamp(num6, -0.26f, 0.37f);
			}
		}

		protected override void OnDestroy()
		{
			shipFeet.Restore();
			surface?.Dispose();
			if (Object.op_Implicit((Object)(object)material))
			{
				Object.Destroy((Object)(object)material);
			}
			((BodyReplacementBase)this).OnDestroy();
		}
	}
	internal sealed class ShipFootOffset
	{
		private readonly RaycastHit[] hits = (RaycastHit[])(object)new RaycastHit[48];

		private Transform visual;

		private Transform parent;

		private Vector3 originalLocal;

		private Vector3 appliedLocal;

		internal void Restore()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)visual) && (Object)(object)visual.parent == (Object)(object)parent)
			{
				Vector3 val = visual.localPosition - appliedLocal;
				if (((Vector3)(ref val)).sqrMagnitude < 1E-08f)
				{
					visual.localPosition = originalLocal;
				}
			}
			visual = null;
			parent = null;
		}

		internal float Apply(Transform model, Transform player, Vector3 contact, Vector3 left, Vector3 right, out float floorY)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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)
			Restore();
			floorY = float.NaN;
			if (!Object.op_Implicit((Object)(object)model) || !Object.op_Implicit((Object)(object)player) || (Object)(object)model == (Object)(object)player || player.IsChildOf(model))
			{
				return 0f;
			}
			float? num = DeckAt(contact, contact.y, player, model);
			if (!num.HasValue)
			{
				return 0f;
			}
			floorY = num.Value;
			float num2 = FootDepth(left, contact, num.Value, player, model);
			float num3 = FootDepth(right, contact, num.Value, player, model);
			float num4 = Mathf.Max(num2, num3);
			if (num4 <= 0.003f)
			{
				return 0f;
			}
			visual = model;
			parent = model.parent;
			originalLocal = model.localPosition;
			model.position += Vector3.up * num4;
			appliedLocal = model.localPosition;
			return num4;
		}

		private float FootDepth(Vector3 sole, Vector3 contact, float center, Transform player, Transform model)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = sole - contact;
			val.y = 0f;
			if (float.IsNaN(((Vector3)(ref sole)).sqrMagnitude) || float.IsInfinity(((Vector3)(ref sole)).sqrMagnitude) || ((Vector3)(ref val)).sqrMagnitude > 1.6899998f)
			{
				return 0f;
			}
			float? num = DeckAt(sole, contact.y, player, model);
			if (!num.HasValue || Mathf.Abs(num.Value - center) > 0.09f)
			{
				return 0f;
			}
			float num2 = num.Value - sole.y;
			if (num2 < 0.003f || num2 > 0.55f)
			{
				return 0f;
			}
			return Mathf.Min(0.38f, num2 + 0.005f);
		}

		private float? DeckAt(Vector3 xz, float expected, Transform player, Transform model)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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_0112: Unknown result type (might be due to invalid IL or missing references)
			int num = Physics.RaycastNonAlloc(new Vector3(xz.x, expected + 0.27f, xz.z), Vector3.down, hits, 0.56f, -5, (QueryTriggerInteraction)1);
			float value = 0f;
			float num2 = float.PositiveInfinity;
			for (int i = 0; i < num; i++)
			{
				RaycastHit val = hits[i];
				Collider collider = ((RaycastHit)(ref val)).collider;
				if (!Object.op_Implicit((Object)(object)collider) || ((RaycastHit)(ref val)).normal.y < 0.72f || collider is CharacterController || ((Component)collider).transform.IsChildOf(player) || ((Component)collider).transform.IsChildOf(model) || (Object.op_Implicit((Object)(object)collider.attachedRigidbody) && !collider.attachedRigidbody.isKinematic))
				{
					continue;
				}
				float num3 = ((RaycastHit)(ref val)).point.y - expected;
				if (!(num3 > 0.13f) && !(num3 < -0.2f))
				{
					float num4 = Mathf.Abs(num3) + ((num3 > 0.04f) ? 0.07f : 0f);
					if (num4 < num2)
					{
						num2 = num4;
						value = ((RaycastHit)(ref val)).point.y;
					}
				}
			}
			if (!float.IsPositiveInfinity(num2))
			{
				return value;
			}
			return null;
		}
	}
	internal static class SurfaceSolve
	{
		internal struct Segment
		{
			internal Vector3 A;

			internal Vector3 B;

			internal float Radius;

			internal Segment(Vector3 a, Vector3 b, float r)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				A = a;
				B = b;
				Radius = r;
			}
		}

		internal static Vector3 Nearest(Vector3 p, Segment s)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = s.B - s.A;
			return s.A + val * Mathf.Clamp01(Vector3.Dot(p - s.A, val) / Mathf.Max(1E-08f, ((Vector3)(ref val)).sqrMagnitude));
		}

		internal static Vector3 Project(Vector3 point, Vector3 preferred, Segment s, float padding = 0f)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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)
			Vector3 val = Nearest(point, s);
			Vector3 val2 = point - val;
			float num = s.Radius + padding;
			float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
			if (sqrMagnitude >= num * num)
			{
				return point;
			}
			Vector3 val3 = s.B - s.A;
			Vector3 normalized = ((Vector3)(ref val3)).normalized;
			val3 = Vector3.ProjectOnPlane(preferred, normalized);
			Vector3 val4 = ((Vector3)(ref val3)).normalized;
			if (((Vector3)(ref val4)).sqrMagnitude < 0.5f)
			{
				Vector3 normalized2;
				if (!(sqrMagnitude > 1E-08f))
				{
					val3 = Vector3.Cross(normalized, Vector3.right);
					normalized2 = ((Vector3)(ref val3)).normalized;
				}
				else
				{
					normalized2 = ((Vector3)(ref val2)).normalized;
				}
				val4 = normalized2;
			}
			if (((Vector3)(ref val4)).sqrMagnitude < 0.5f)
			{
				val4 = Vector3.up;
			}
			float num2 = Vector3.Dot(val2, val4);
			return point + val4 * (Mathf.Max(0f, 0f - num2 + Mathf.Sqrt(Mathf.Max(0f, num2 * num2 + num * num - sqrMagnitude))) + 0.0001f);
		}

		internal static float FloorLift(float? floor, float lowest, float rootFloor)
		{
			return Mathf.Clamp((floor ?? rootFloor) + 0.013f - lowest, 0f, 0.46f);
		}
	}
	internal sealed class VoiceFace
	{
		private sealed class Face
		{
			private GameObject root;

			private SkinnedMeshRenderer face;

			private int open = -1;

			private int round = -1;

			private int blink = -1;

			public void Bind(GameObject root)
			{
				if ((Object)(object)this.root == (Object)(object)root)
				{
					return;
				}
				this.root = root;
				face = null;
				open = (round = (blink = -1));
				if (!Object.op_Implicit((Object)(object)root))
				{
					return;
				}
				SkinnedMeshRenderer[] componentsInChildren = root.GetComponentsInChildren<SkinnedMeshRenderer>(true);
				foreach (SkinnedMeshRenderer val in componentsInChildren)
				{
					Mesh sharedMesh = val.sharedMesh;
					if (Object.op_Implicit((Object)(object)sharedMesh))
					{
						int num = Find(sharedMesh, "FR_MouthOpen");
						if (num >= 0)
						{
							face = val;
							open = num;
							round = Find(sharedMesh, "FR_MouthRound");
							blink = Find(sharedMesh, "FR_Blink");
							break;
						}
					}
				}
			}

			private static int Find(Mesh m, string s)
			{
				for (int i = 0; i < m.blendShapeCount; i++)
				{
					string blendShapeName = m.GetBlendShapeName(i);
					if (blendShapeName == s || blendShapeName.EndsWith("." + s, StringComparison.Ordinal))
					{
						return i;
					}
				}
				return -1;
			}

			public void Apply(float a, float o, float b)
			{
				if (Object.op_Implicit((Object)(object)face))
				{
					if (open >= 0)
					{
						face.SetBlendShapeWeight(open, a * 100f);
					}
					if (round >= 0)
					{
						face.SetBlendShapeWeight(round, o * 100f);
					}
					if (blink >= 0)
					{
						face.SetBlendShapeWeight(blink, b * 100f);
					}
				}
			}
		}

		private static readonly FieldInfo CaptureField = typeof(DissonanceComms).GetField("_capture", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly PropertyInfo CaptureAmp = CaptureField?.FieldType.GetProperty("Amplitude", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

		private readonly Face[] faces = new Face[3]
		{
			new Face(),
			new Face(),
			new Face()
		};

		private readonly VoiceEnvelope envelope = new VoiceEnvelope();

		private bool logged;

		private float nextBlink;

		private float started = -100f;

		internal void Frame(GameObject body, GameObject shadow, GameObject view, PlayerControllerB p)
		{
			faces[0].Bind(body);
			faces[1].Bind(shadow);
			faces[2].Bind(view);
			bool num = Object.op_Implicit((Object)(object)p) && !p.isPlayerDead;
			(bool, float, bool) tuple = Read(p);
			envelope.Step(tuple.Item1, tuple.Item2, Time.unscaledDeltaTime);
			float unscaledTime = Time.unscaledTime;
			if (unscaledTime >= nextBlink)
			{
				started = unscaledTime;
				nextBlink = unscaledTime + Random.Range(2.4f, 6.3f);
			}
			float num2 = unscaledTime - started;
			float b = ((!num) ? 0f : ((num2 < 0.065f) ? Mathf.SmoothStep(0f, 1f, num2 / 0.065f) : Mathf.SmoothStep(1f, 0f, (num2 - 0.078f) / 0.115f)));
			Face[] array = faces;
			for (int i = 0; i < array.Length; i++)
			{
				array[i].Apply(envelope.Open, envelope.Round, b);
			}
			if (!logged && envelope.Open > 0.003f)
			{
				logged = true;
				Debug.Log((object)("[Frieren] Voice enabled: active " + (tuple.Item3 ? "local microphone" : "remote player") + " envelope."));
			}
		}

		private static (bool active, float amplitude, bool local) Read(PlayerControllerB p)
		{
			if (!Object.op_Implicit((Object)(object)p) || p.isPlayerDead)
			{
				return (active: false, amplitude: 0f, local: false);
			}
			GameNetworkManager instance = GameNetworkManager.Instance;
			if (!Object.op_Implicit((Object)(object)instance) || (Object)(object)instance.localPlayerController != (Object)(object)p)
			{
				VoicePlayerState voicePlayerState = p.voicePlayerState;
				if (voicePlayerState != null && !voicePlayerState.IsLocallyMuted)
				{
					return (active: voicePlayerState.IsSpeaking || voicePlayerState.Amplitude > 0.001f, amplitude: voicePlayerState.Amplitude, local: false);
				}
				return (active: false, amplitude: 0f, local: false);
			}
			StartOfRound instance2 = StartOfRound.Instance;
			DissonanceComms val = (Object.op_Implicit((Object)(object)instance2) ? instance2.voiceChatModule : null);
			if (!Object.op_Implicit((Object)(object)val) || !((Behaviour)val).enabled || val.IsMuted)
			{
				return (active: false, amplitude: 0f, local: true);
			}
			IngamePlayerSettings instance3 = IngamePlayerSettings.Instance;
			if (Object.op_Implicit((Object)(object)instance3) && !instance3.settings.micEnabled)
			{
				return (active: false, amplitude: 0f, local: true);
			}
			bool num = Object.op_Implicit((Object)(object)instance3) && instance3.settings.pushToTalk;
			string localPlayerName = val.LocalPlayerName;
			VoicePlayerState val2 = (string.IsNullOrEmpty(localPlayerName) ? null : val.FindPlayer(localPlayerName));
			if (num && (val2 == null || !val2.IsSpeaking))
			{
				return (active: false, amplitude: 0f, local: true);
			}
			float num2 = ((val2 != null) ? val2.Amplitude : 0f);
			if (num2 < 0.012f)
			{
				object obj = CaptureField?.GetValue(val);
				if (obj != null && CaptureAmp?.GetValue(obj) is float num3)
				{
					num2 = Mathf.Max(num2, num3);
				}
			}
			return (active: num2 > 0.0006f, amplitude: num2, local: true);
		}
	}
	internal sealed class VoiceEnvelope
	{
		public float Open { get; private set; }

		public float Round { get; private set; }

		public void Step(bool active, float amplitude, float dt)
		{
			if (float.IsNaN(amplitude) || float.IsInfinity(amplitude))
			{
				amplitude = 0f;
			}
			float num = (active ? Mathf.Clamp01((amplitude - 0.006f) / 0.105f) : 0f);
			Open = Smooth(Open, Mathf.Pow(num, 1.35f) * 0.68f, dt, 0.025f, 0.085f);
			Round = Smooth(Round, Mathf.Sqrt(num) * (1f - num) * 0.15f, dt, 0.035f, 0.09f);
		}

		private static float Smooth(float a, float b, float dt, float attack, float release)
		{
			float num = Mathf.Lerp(a, b, 1f - Mathf.Exp((0f - Mathf.Clamp(dt, 0f, 0.1f)) / ((b > a) ? attack : release)));
			if (!(num < 0.001f))
			{
				return num;
			}
			return 0f;
		}
	}
}