Decompiled source of BodyValkyrReplacer v1.4.0

LokiValkyr.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using MagicaCloth2;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: InternalsVisibleTo("LokiValkyrArmor")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("LokiValkyr")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.4.0.0")]
[assembly: AssemblyInformationalVersion("1.4.0+8885e872e98aef3eacd8846186fe821e165f09c9")]
[assembly: AssemblyProduct("LokiValkyr")]
[assembly: AssemblyTitle("LokiValkyr")]
[assembly: AssemblyVersion("1.4.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace LokiValkyr
{
	public sealed class Appearance
	{
		[HarmonyPatch(typeof(Player), "SetupVisEquipment")]
		private class MirrorEquipment
		{
			private static void Postfix(Player __instance, VisEquipment visEq)
			{
				if (Plugin.Replacing && Object.op_Implicit((Object)(object)visEq))
				{
					Mirror(__instance, visEq);
				}
			}
		}

		public const string Key = "lokivalkyr_colors_v1";

		private static readonly int ZdoKey;

		private static readonly FieldRef<VisEquipment, ZNetView> View;

		public float HairHue = 0.08f;

		public float HairSaturation = 0.25f;

		public float HairValue = 0.85f;

		public float EyeHue = 0.52f;

		public float EyeSaturation = 0.85f;

		public float EyeValue = 1f;

		public float Glow = 0.98f;

		public bool CustomHair;

		public int HairStyle = (Plugin.PublicEdition ? 1 : 0);

		public float IrisSize = 0.8f;

		public float BreastSize;

		public float ButtSize;

		public int EyelinerStyle;

		public float EyelinerHue;

		public float EyelinerSaturation;

		public float EyelinerValue = 0.02f;

		public float EyelinerStrength = 0.85f;

		private static readonly List<(string key, int hash)> extras;

		public const string MuscleKey = "lokivalkyr_muscle_v1";

		public static readonly string[] HairNames;

		public static readonly int[] Styles;

		public static readonly string[] EyelinerNames;

		public Color Hair => Color.HSVToRGB(HairHue, HairSaturation, HairValue);

		public Color Eye => Color.HSVToRGB(EyeHue, EyeSaturation, EyeValue);

		public Color Eyeliner => Color.HSVToRGB(EyelinerHue, EyelinerSaturation, EyelinerValue);

		public static void RegisterExtra(string key)
		{
			foreach (var extra in extras)
			{
				if (extra.key == key)
				{
					return;
				}
			}
			extras.Add((key, StringExtensionMethods.GetStableHashCode(key)));
		}

		public static string? Extra(VisEquipment vis, string key)
		{
			ZNetView val = View.Invoke(vis);
			ZDO val2 = (Object.op_Implicit((Object)(object)val) ? val.GetZDO() : null);
			Player component = ((Component)vis).GetComponent<Player>();
			if (Object.op_Implicit((Object)(object)component) && (val2 == null || val.IsOwner()))
			{
				if (!component.m_customData.TryGetValue(key, out var value))
				{
					return null;
				}
				return value;
			}
			string text = ((val2 != null) ? val2.GetString(StringExtensionMethods.GetStableHashCode(key), "") : null) ?? "";
			if (text.Length <= 0)
			{
				return null;
			}
			return text;
		}

		public static void SetExtra(Player p, string key, string? value)
		{
			if (value == null)
			{
				p.m_customData.Remove(key);
			}
			else
			{
				p.m_customData[key] = value;
			}
			VisEquipment component = ((Component)p).GetComponent<VisEquipment>();
			if (Object.op_Implicit((Object)(object)component))
			{
				Mirror(p, component);
			}
		}

		static Appearance()
		{
			ZdoKey = StringExtensionMethods.GetStableHashCode("lokivalkyr_colors_v1");
			View = AccessTools.FieldRefAccess<VisEquipment, ZNetView>("m_nview");
			extras = new List<(string, int)>();
			HairNames = new string[8] { "Long Fringe", "Short Bob", "Long Swept", "Long Layered", "No Hair", "Half-Up Loose", "Braided Bun", "Side Braid" };
			Styles = ((!Plugin.PublicEdition) ? new int[8] { 0, 1, 2, 3, 4, 5, 6, 7 } : new int[7] { 1, 2, 3, 4, 5, 6, 7 });
			EyelinerNames = new string[6] { "None", "Runeline", "Ashwing", "Frostring", "Nightlid", "Ravenwing" };
			RegisterExtra("lokivalkyr_muscle_v1");
		}

		private static float? ParseMuscle(string? s)
		{
			if (s == null || !float.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out var result) || float.IsNaN(result))
			{
				return null;
			}
			return Mathf.Clamp(result, 0f, 100f);
		}

		public static float? MuscleOf(VisEquipment vis)
		{
			if (!CompanionLooks.Supported(vis))
			{
				return ParseMuscle(Extra(vis, "lokivalkyr_muscle_v1"));
			}
			return CompanionLooks.Muscle(vis);
		}

		public static float? MuscleOf(Player p)
		{
			string value;
			return ParseMuscle(p.m_customData.TryGetValue("lokivalkyr_muscle_v1", out value) ? value : null);
		}

		public static void SetMuscle(Player p, float? value)
		{
			SetExtra(p, "lokivalkyr_muscle_v1", value.HasValue ? Mathf.Clamp(value.Value, 0f, 100f).ToString("F1", CultureInfo.InvariantCulture) : null);
			LokiValkyrVisual component = ((Component)p).GetComponent<LokiValkyrVisual>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.UpdateAppearance();
			}
		}

		public static int Shown(int style)
		{
			if (Array.IndexOf(Styles, style) < 0)
			{
				return 1;
			}
			return style;
		}

		public string Encode()
		{
			return string.Join("|", new float[17]
			{
				CustomHair ? 1f : 0f,
				HairHue,
				HairSaturation,
				HairValue,
				EyeHue,
				EyeSaturation,
				EyeValue,
				Glow,
				HairStyle,
				IrisSize,
				BreastSize,
				ButtSize,
				EyelinerStyle,
				EyelinerHue,
				EyelinerSaturation,
				EyelinerValue,
				EyelinerStrength
			}.Select((float v) => v.ToString("R", CultureInfo.InvariantCulture)));
		}

		public static Appearance Parse(string? value)
		{
			Appearance appearance = new Appearance();
			if (string.IsNullOrEmpty(value))
			{
				return appearance;
			}
			string[] array = value.Split(new char[1] { '|' });
			if (array.Length != 8 && array.Length != 12 && array.Length != 17)
			{
				return appearance;
			}
			float[] array2 = new float[array.Length];
			for (int i = 0; i < array2.Length; i++)
			{
				if (!float.TryParse(array[i], NumberStyles.Float, CultureInfo.InvariantCulture, out array2[i]) || float.IsNaN(array2[i]) || float.IsInfinity(array2[i]))
				{
					return appearance;
				}
			}
			appearance.CustomHair = array2[0] > 0f;
			appearance.HairHue = Mathf.Clamp01(array2[1]);
			appearance.HairSaturation = Mathf.Clamp01(array2[2]);
			appearance.HairValue = Mathf.Clamp01(array2[3]);
			appearance.EyeHue = Mathf.Clamp01(array2[4]);
			appearance.EyeSaturation = Mathf.Clamp01(array2[5]);
			appearance.EyeValue = Mathf.Clamp01(array2[6]);
			appearance.Glow = Mathf.Clamp(array2[7], 0f, 3f);
			if (array2.Length >= 12)
			{
				appearance.HairStyle = Mathf.Clamp((int)array2[8], 0, HairNames.Length - 1);
				appearance.IrisSize = Mathf.Clamp(array2[9], 0.5f, 1.2f);
				appearance.BreastSize = Mathf.Clamp(array2[10], -100f, 100f);
				appearance.ButtSize = Mathf.Clamp(array2[11], -100f, 100f);
			}
			if (array2.Length >= 17)
			{
				appearance.EyelinerStyle = Mathf.Clamp((int)array2[12], 0, EyelinerNames.Length - 1);
				appearance.EyelinerHue = Mathf.Clamp01(array2[13]);
				appearance.EyelinerSaturation = Mathf.Clamp01(array2[14]);
				appearance.EyelinerValue = Mathf.Clamp01(array2[15]);
				appearance.EyelinerStrength = Mathf.Clamp01(array2[16]);
			}
			return appearance;
		}

		public static Appearance Of(Player p)
		{
			string value;
			return Parse(p.m_customData.TryGetValue("lokivalkyr_colors_v1", out value) ? value : null);
		}

		public static Appearance For(VisEquipment vis)
		{
			if (CompanionLooks.Supported(vis))
			{
				return CompanionLooks.Read(vis);
			}
			ZNetView val = View.Invoke(vis);
			ZDO val2 = (Object.op_Implicit((Object)(object)val) ? val.GetZDO() : null);
			Player component = ((Component)vis).GetComponent<Player>();
			if (Object.op_Implicit((Object)(object)component) && (val2 == null || val.IsOwner()))
			{
				Appearance result = Of(component);
				Mirror(component, vis);
				return result;
			}
			return Parse((val2 != null) ? val2.GetString(ZdoKey, "") : null);
		}

		public static void Set(Player p, Appearance a)
		{
			p.m_customData["lokivalkyr_colors_v1"] = a.Encode();
			VisEquipment component = ((Component)p).GetComponent<VisEquipment>();
			if (Object.op_Implicit((Object)(object)component))
			{
				Mirror(p, component);
			}
			LokiValkyrVisual component2 = ((Component)p).GetComponent<LokiValkyrVisual>();
			if (Object.op_Implicit((Object)(object)component2))
			{
				component2.UpdateAppearance();
			}
		}

		public static void Mirror(Player p, VisEquipment vis)
		{
			ZNetView val = View.Invoke(vis);
			ZDO val2 = (Object.op_Implicit((Object)(object)val) ? val.GetZDO() : null);
			if (val2 == null || !val.IsOwner())
			{
				return;
			}
			string text = Of(p).Encode();
			if (val2.GetString(ZdoKey, "") != text)
			{
				val2.Set(ZdoKey, text);
			}
			foreach (var extra in extras)
			{
				string item = extra.key;
				int item2 = extra.hash;
				string value;
				string text2 = (p.m_customData.TryGetValue(item, out value) ? value : "");
				if (val2.GetString(item2, "") != text2)
				{
					val2.Set(item2, text2);
				}
			}
		}
	}
	internal static class ArmorAutoFit
	{
		private sealed class Job
		{
			internal string name = "";

			internal string note = "";

			internal string target = "";

			internal string? error;

			internal int count;

			internal Mesh? bodyMesh;

			internal bool rigid;

			internal Matrix4x4 toSocket;

			internal Mesh src;

			internal Mesh? copy;

			internal Task? task;

			internal Vector3[] v;

			internal Vector3[] nIn;

			internal Vector4[] tIn;

			internal BoneWeight[] wIn;

			internal int[] tris;

			internal Matrix4x4[] bp;

			internal string?[] bones;

			internal int bodyBones;

			internal Vector3[]?[] morphDelta;

			internal Vector3[]? outV;

			internal Vector3[]? outN;

			internal Vector4[]? outT;

			internal BoneWeight[]? outW;

			internal readonly List<(string name, Vector3[] delta)> shapes = new List<(string, Vector3[])>();
		}

		[StructLayout(LayoutKind.Explicit)]
		private struct FloatBits
		{
			[FieldOffset(0)]
			internal float Value;

			[FieldOffset(0)]
			internal uint Bits;
		}

		private sealed class Data
		{
			private readonly float clearance;

			private readonly float transferNear;

			private readonly float transferFar;

			private readonly float coverReach;

			private readonly float coverDepth;

			private readonly float maxPush;

			private readonly float morphFull;

			private readonly float morphNone;

			private readonly string[] morphs;

			private readonly float[] fitWeights;

			private readonly Dictionary<string, int> vIndex = new Dictionary<string, int>(StringComparer.Ordinal);

			private readonly byte[] vRegion;

			private readonly int[] nativeToTarget;

			private readonly Matrix4x4[] vBoneV;

			private readonly Vector3[] sv;

			private readonly Vector3[] sn;

			private readonly Vector3[] disp;

			private readonly int[] sTris;

			private readonly byte[] sTriRegion;

			private readonly Vector3[] tv;

			private readonly Vector3[] tn;

			private readonly Vector3[] surf;

			private readonly BoneWeight[] tw;

			private readonly int[] tTris;

			private readonly byte[] tTriRegion;

			private readonly int bodyCount;

			private readonly Matrix4x4[] tSkinV;

			private readonly List<(string name, Matrix4x4[] skin)> poses = new List<(string, Matrix4x4[])>();

			internal ulong Hash;

			private Grid vanillaGrid;

			private Grid surfGrid;

			private Helmet? helmet;

			private const float NearField = 0.04f;

			private const float LatticeStep = 0.03f;

			private readonly ConcurrentDictionary<(Vector3Int, byte), (Vector3 disp, float signed)> lattice = new ConcurrentDictionary<(Vector3Int, byte), (Vector3, float)>();

			private static readonly ParallelOptions Workers = new ParallelOptions
			{
				MaxDegreeOfParallelism = Math.Max(1, Math.Min(4, Environment.ProcessorCount / 2))
			};

			private const float SmallPart = 6f / 95f;

			private const float HelmetCoverDepth = 1f / 19f;

			private const float HelmetMaxPush = 9f / 190f;

			private const float NearSkin = 0.1f;

			private byte[]? vertexRegion;

			internal bool HasHelmet => helmet != null;

			internal Data(BinaryReader r)
			{
				//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_0239: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
				//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
				//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
				//IL_0377: Unknown result type (might be due to invalid IL or missing references)
				//IL_033a: Unknown result type (might be due to invalid IL or missing references)
				//IL_033f: Unknown result type (might be due to invalid IL or missing references)
				int num;
				if (Encoding.ASCII.GetString(r.ReadBytes(4)) != "VAF1" || (num = r.ReadInt32()) < 1 || num > 3)
				{
					throw new InvalidDataException("not an auto-fit file");
				}
				r.ReadString();
				clearance = r.ReadSingle();
				transferNear = r.ReadSingle();
				transferFar = r.ReadSingle();
				coverReach = r.ReadSingle();
				coverDepth = r.ReadSingle();
				maxPush = r.ReadSingle();
				morphFull = r.ReadSingle();
				morphNone = r.ReadSingle();
				int num2 = r.ReadInt32();
				morphs = new string[num2];
				fitWeights = new float[num2];
				for (int i = 0; i < num2; i++)
				{
					morphs[i] = r.ReadString();
					fitWeights[i] = r.ReadSingle();
				}
				int num3 = r.ReadInt32();
				vRegion = new byte[num3];
				nativeToTarget = new int[num3];
				vBoneV = (Matrix4x4[])(object)new Matrix4x4[num3];
				for (int j = 0; j < num3; j++)
				{
					vIndex[r.ReadString()] = j;
					vRegion[j] = r.ReadByte();
					nativeToTarget[j] = r.ReadInt32();
					vBoneV[j] = Mat(r);
				}
				int n = r.ReadInt32();
				sv = Vecs(r, n);
				sn = Vecs(r, n);
				disp = Vecs(r, n);
				sTris = Ints(r);
				sTriRegion = Bytes(r);
				int num4 = r.ReadInt32();
				bodyCount = r.ReadInt32();
				tv = Vecs(r, num4);
				tn = Vecs(r, num4);
				surf = Vecs(r, num4);
				tw = (BoneWeight[])(object)new BoneWeight[num4];
				for (int k = 0; k < num4; k++)
				{
					BoneWeight[] array = tw;
					int num5 = k;
					BoneWeight val = default(BoneWeight);
					((BoneWeight)(ref val)).boneIndex0 = r.ReadInt32();
					((BoneWeight)(ref val)).boneIndex1 = r.ReadInt32();
					((BoneWeight)(ref val)).boneIndex2 = r.ReadInt32();
					((BoneWeight)(ref val)).boneIndex3 = r.ReadInt32();
					((BoneWeight)(ref val)).weight0 = r.ReadSingle();
					((BoneWeight)(ref val)).weight1 = r.ReadSingle();
					((BoneWeight)(ref val)).weight2 = r.ReadSingle();
					((BoneWeight)(ref val)).weight3 = r.ReadSingle();
					array[num5] = val;
				}
				tTris = Ints(r);
				tTriRegion = Bytes(r);
				int num6 = r.ReadInt32();
				tSkinV = (Matrix4x4[])(object)new Matrix4x4[num6];
				for (int l = 0; l < num6; l++)
				{
					tSkinV[l] = Mat(r);
				}
				if (num >= 2)
				{
					int num7 = r.ReadInt32();
					for (int m = 0; m < num7; m++)
					{
						string item = r.ReadString();
						Matrix4x4[] array2 = (Matrix4x4[])(object)new Matrix4x4[num6];
						for (int num8 = 0; num8 < num6; num8++)
						{
							array2[num8] = Mat(r);
						}
						poses.Add((item, array2));
					}
				}
				if (num >= 3)
				{
					helmet = new Helmet(r, Mat(r));
				}
			}

			internal Vector3[]?[] MorphDeltas(Mesh bodyMesh)
			{
				//IL_0067: Unknown result type (might be due to invalid IL or missing references)
				//IL_006e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0073: Unknown result type (might be due to invalid IL or missing references)
				Vector3[][] array = new Vector3[morphs.Length][];
				for (int i = 0; i < morphs.Length; i++)
				{
					int blendShapeIndex = bodyMesh.GetBlendShapeIndex(morphs[i]);
					if (blendShapeIndex >= 0)
					{
						int num = bodyMesh.GetBlendShapeFrameCount(blendShapeIndex) - 1;
						Vector3[] array2 = (Vector3[])(object)new Vector3[bodyMesh.vertexCount];
						bodyMesh.GetBlendShapeFrameVertices(blendShapeIndex, num, array2, (Vector3[])null, (Vector3[])null);
						float num2 = 100f / bodyMesh.GetBlendShapeFrameWeight(blendShapeIndex, num);
						for (int j = 0; j < array2.Length; j++)
						{
							ref Vector3 reference = ref array2[j];
							reference *= num2;
						}
						array[i] = array2;
					}
				}
				return array;
			}

			private static Matrix4x4 Mat(BinaryReader r)
			{
				//IL_0002: 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)
				Matrix4x4 result = default(Matrix4x4);
				for (int i = 0; i < 16; i++)
				{
					((Matrix4x4)(ref result))[i] = r.ReadSingle();
				}
				return result;
			}

			private static Vector3[] Vecs(BinaryReader r, int n)
			{
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Unknown result type (might be due to invalid IL or missing references)
				Vector3[] array = (Vector3[])(object)new Vector3[n];
				for (int i = 0; i < n; i++)
				{
					array[i] = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
				}
				return array;
			}

			private static int[] Ints(BinaryReader r)
			{
				int num = r.ReadInt32();
				int[] array = new int[num];
				for (int i = 0; i < num; i++)
				{
					array[i] = r.ReadInt32();
				}
				return array;
			}

			private static byte[] Bytes(BinaryReader r)
			{
				int count = r.ReadInt32();
				return r.ReadBytes(count);
			}

			private (Vector3 disp, float signed) Field(Vector3 a, byte region)
			{
				//IL_001a: 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_005e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0063: Unknown result type (might be due to invalid IL or missing references)
				//IL_0066: Unknown result type (might be due to invalid IL or missing references)
				//IL_0071: Unknown result type (might be due to invalid IL or missing references)
				//IL_007c: 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_008d: Unknown result type (might be due to invalid IL or missing references)
				//IL_008e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0093: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_009e: 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_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_0046: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fd: 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_0109: Unknown result type (might be due to invalid IL or missing references)
				//IL_010e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0111: 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_011f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0139: Unknown result type (might be due to invalid IL or missing references)
				//IL_0161: Unknown result type (might be due to invalid IL or missing references)
				//IL_0158: Unknown result type (might be due to invalid IL or missing references)
				//IL_017d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0174: 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_0191: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a3: 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_01b3: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
				if (vanillaGrid.Closest(a, 0.04f, (int k) => Near(region, sTriRegion[k]), out var _, out var _) >= 0)
				{
					return (disp: DisplacementAt(a, region), signed: VanillaSigned(a, region));
				}
				Vector3 val = a / 0.03f;
				Vector3Int val2 = default(Vector3Int);
				((Vector3Int)(ref val2))..ctor(Mathf.FloorToInt(val.x), Mathf.FloorToInt(val.y), Mathf.FloorToInt(val.z));
				Vector3 val3 = val - Vector3Int.op_Implicit(val2);
				Vector3 val4 = Vector3.zero;
				float num = 0f;
				bool flag = false;
				Vector3Int val5 = default(Vector3Int);
				for (int num2 = 0; num2 < 8; num2++)
				{
					((Vector3Int)(ref val5))..ctor(((Vector3Int)(ref val2)).x + (num2 & 1), ((Vector3Int)(ref val2)).y + ((num2 >> 1) & 1), ((Vector3Int)(ref val2)).z + ((num2 >> 2) & 1));
					if (!lattice.TryGetValue((val5, region), out (Vector3, float) value))
					{
						Vector3 p = Vector3Int.op_Implicit(val5) * 0.03f;
						value = (DisplacementAt(p, region), VanillaSigned(p, region));
						lattice[(val5, region)] = value;
					}
					float num3 = (((num2 & 1) != 0) ? val3.x : (1f - val3.x)) * ((((num2 >> 1) & 1) != 0) ? val3.y : (1f - val3.y)) * ((((num2 >> 2) & 1) != 0) ? val3.z : (1f - val3.z));
					val4 += num3 * value.Item1;
					if (value.Item2 == float.MaxValue)
					{
						flag = true;
					}
					else
					{
						num += num3 * value.Item2;
					}
				}
				return (disp: val4, signed: flag ? float.MaxValue : num);
			}

			private Vector3 DisplacementAt(Vector3 p, byte region)
			{
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: 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_006c: Unknown result type (might be due to invalid IL or missing references)
				//IL_006e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0073: Unknown result type (might be due to invalid IL or missing references)
				//IL_0078: 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_00ac: 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_00d3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00de: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
				//IL_0066: 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_0191: 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_012c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0131: Unknown result type (might be due to invalid IL or missing references)
				//IL_0136: 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_0153: Unknown result type (might be due to invalid IL or missing references)
				//IL_0158: Unknown result type (might be due to invalid IL or missing references)
				//IL_015d: 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_017f: Unknown result type (might be due to invalid IL or missing references)
				Vector3 point;
				Vector3 bary;
				int num = vanillaGrid.Closest(p, 0.6f, (int k) => Near(region, sTriRegion[k]), out point, out bary);
				if (num < 0)
				{
					num = vanillaGrid.Closest(p, 1.5f, null, out point, out bary);
				}
				if (num < 0)
				{
					return Vector3.zero;
				}
				Vector3 val = point - p;
				float magnitude = ((Vector3)(ref val)).magnitude;
				float radius = Mathf.Max(2f * magnitude, 0.03f);
				float eps = 0.01f;
				Vector3 sum = Vector3.zero;
				float wsum = 0f;
				vanillaGrid.Visit(p - Vector3.one * radius, p + Vector3.one * radius, delegate(int k)
				{
					//IL_0050: 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_0072: 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_008a: Unknown result type (might be due to invalid IL or missing references)
					//IL_0090: Unknown result type (might be due to invalid IL or missing references)
					//IL_0095: Unknown result type (might be due to invalid IL or missing references)
					//IL_009a: Unknown result type (might be due to invalid IL or missing references)
					//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
					//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
					//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
					//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
					//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
					//IL_0102: Unknown result type (might be due to invalid IL or missing references)
					//IL_0107: Unknown result type (might be due to invalid IL or missing references)
					//IL_010c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0111: Unknown result type (might be due to invalid IL or missing references)
					//IL_0123: Unknown result type (might be due to invalid IL or missing references)
					//IL_0128: Unknown result type (might be due to invalid IL or missing references)
					//IL_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_0137: Unknown result type (might be due to invalid IL or missing references)
					//IL_013c: Unknown result type (might be due to invalid IL or missing references)
					if (Near(region, sTriRegion[k]))
					{
						int num2 = sTris[k * 3];
						int num3 = sTris[k * 3 + 1];
						int num4 = sTris[k * 3 + 2];
						Vector3 bary2;
						Vector3 val2 = Grid.ClosestPointOnTriangle(p, sv[num2], sv[num3], sv[num4], out bary2) - p;
						float magnitude2 = ((Vector3)(ref val2)).magnitude;
						if (!(magnitude2 > radius))
						{
							float num5 = 1f / (magnitude2 * magnitude2 + eps * eps);
							sum += num5 * (bary2.x * disp[num2] + bary2.y * disp[num3] + bary2.z * disp[num4]);
							wsum += num5;
						}
					}
				});
				if (wsum <= 0f)
				{
					return bary.x * disp[sTris[num * 3]] + bary.y * disp[sTris[num * 3 + 1]] + bary.z * disp[sTris[num * 3 + 2]];
				}
				return sum / wsum;
			}

			private float VanillaSigned(Vector3 p, byte region)
			{
				//IL_001a: 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_0056: Unknown result type (might be due to invalid IL or missing references)
				//IL_005b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0060: 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_0082: Unknown result type (might be due to invalid IL or missing references)
				//IL_0087: Unknown result type (might be due to invalid IL or missing references)
				//IL_009f: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
				Vector3 point;
				Vector3 bary;
				int num = vanillaGrid.Closest(p, 0.3f, (int t) => Near(region, sTriRegion[t]), out point, out bary);
				if (num < 0)
				{
					return float.MaxValue;
				}
				Vector3 val = Unit(bary.x * sn[sTris[num * 3]] + bary.y * sn[sTris[num * 3 + 1]] + bary.z * sn[sTris[num * 3 + 2]]);
				return Vector3.Dot(p - point, val);
			}

			private BoneWeight MapNative(BoneWeight w)
			{
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				Dictionary<int, float> acc = new Dictionary<int, float>();
				Add(((BoneWeight)(ref w)).boneIndex0, ((BoneWeight)(ref w)).weight0);
				Add(((BoneWeight)(ref w)).boneIndex1, ((BoneWeight)(ref w)).weight1);
				Add(((BoneWeight)(ref w)).boneIndex2, ((BoneWeight)(ref w)).weight2);
				Add(((BoneWeight)(ref w)).boneIndex3, ((BoneWeight)(ref w)).weight3);
				return Top4(acc);
				void Add(int b, float x)
				{
					if (!(x <= 0f) && b >= 0 && b < nativeToTarget.Length)
					{
						int key = nativeToTarget[b];
						acc.TryGetValue(key, out var value);
						acc[key] = value + x;
					}
				}
			}

			internal void Fit(Job j)
			{
				//IL_012b: 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_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_01c2: Unknown result type (might be due to invalid IL or missing references)
				//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
				//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
				//IL_0201: Unknown result type (might be due to invalid IL or missing references)
				//IL_0206: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
				//IL_020b: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_0263: Unknown result type (might be due to invalid IL or missing references)
				//IL_0265: Unknown result type (might be due to invalid IL or missing references)
				//IL_0568: Unknown result type (might be due to invalid IL or missing references)
				//IL_056d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0572: Unknown result type (might be due to invalid IL or missing references)
				//IL_0576: Unknown result type (might be due to invalid IL or missing references)
				//IL_057b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0587: Unknown result type (might be due to invalid IL or missing references)
				//IL_058c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0591: Unknown result type (might be due to invalid IL or missing references)
				//IL_0467: Unknown result type (might be due to invalid IL or missing references)
				//IL_046c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0598: Unknown result type (might be due to invalid IL or missing references)
				//IL_05ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_05c2: Unknown result type (might be due to invalid IL or missing references)
				//IL_05c7: Unknown result type (might be due to invalid IL or missing references)
				//IL_05cc: Unknown result type (might be due to invalid IL or missing references)
				//IL_05e7: Unknown result type (might be due to invalid IL or missing references)
				//IL_05e9: Unknown result type (might be due to invalid IL or missing references)
				//IL_05f8: Unknown result type (might be due to invalid IL or missing references)
				//IL_05fd: Unknown result type (might be due to invalid IL or missing references)
				//IL_0602: Unknown result type (might be due to invalid IL or missing references)
				//IL_0607: Unknown result type (might be due to invalid IL or missing references)
				//IL_04cf: Unknown result type (might be due to invalid IL or missing references)
				//IL_04d3: Unknown result type (might be due to invalid IL or missing references)
				//IL_04d8: Unknown result type (might be due to invalid IL or missing references)
				//IL_0619: Unknown result type (might be due to invalid IL or missing references)
				//IL_0622: Unknown result type (might be due to invalid IL or missing references)
				//IL_0627: Unknown result type (might be due to invalid IL or missing references)
				//IL_062c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0631: Unknown result type (might be due to invalid IL or missing references)
				//IL_0636: Unknown result type (might be due to invalid IL or missing references)
				//IL_0659: Unknown result type (might be due to invalid IL or missing references)
				//IL_065e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0665: Unknown result type (might be due to invalid IL or missing references)
				//IL_0667: Unknown result type (might be due to invalid IL or missing references)
				//IL_066c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0671: Unknown result type (might be due to invalid IL or missing references)
				//IL_067c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0691: Unknown result type (might be due to invalid IL or missing references)
				//IL_06a6: Unknown result type (might be due to invalid IL or missing references)
				//IL_0495: Unknown result type (might be due to invalid IL or missing references)
				//IL_04af: Unknown result type (might be due to invalid IL or missing references)
				//IL_04b4: Unknown result type (might be due to invalid IL or missing references)
				//IL_04b9: Unknown result type (might be due to invalid IL or missing references)
				//IL_04be: Unknown result type (might be due to invalid IL or missing references)
				if (j.bodyBones != tSkinV.Length)
				{
					j.note = "body has " + j.bodyBones + " bones, fit data " + tSkinV.Length;
					return;
				}
				if (vanillaGrid == null)
				{
					vanillaGrid = new Grid(sv, sTris, 0.03f);
					surfGrid = new Grid(surf, tTris, 0.03f);
				}
				string[] bones = j.bones;
				Matrix4x4[] bp = j.bp;
				if (bones.Length != bp.Length)
				{
					j.note = "bone/bindpose count mismatch";
					return;
				}
				int[] array = new int[bones.Length];
				for (int i = 0; i < bones.Length; i++)
				{
					if (bones[i] == null || !vIndex.TryGetValue(bones[i], out array[i]))
					{
						j.note = "bone " + (bones[i] ?? "null") + " is not a vanilla body bone";
						return;
					}
				}
				Matrix4x4[] array2 = (Matrix4x4[])(object)new Matrix4x4[bp.Length];
				for (int k = 0; k < bp.Length; k++)
				{
					array2[k] = vBoneV[array[k]] * bp[k];
				}
				Vector3[] v = j.v;
				Vector3[] nIn = j.nIn;
				BoneWeight[] wIn = j.wIn;
				Vector4[] tIn = j.tIn;
				int num = v.Length;
				if (wIn.Length != num)
				{
					j.note = "no skin weights";
					return;
				}
				Vector3[] a = (Vector3[])(object)new Vector3[num];
				Vector3[] array3 = (Vector3[])(object)new Vector3[num];
				BoneWeight[] vw = (BoneWeight[])(object)new BoneWeight[num];
				for (int l = 0; l < num; l++)
				{
					a[l] = Blend(array2, wIn[l], v[l]);
					array3[l] = ((nIn.Length == num) ? Unit(BlendVector(array2, wIn[l], nIn[l])) : Vector3.up);
					BoneWeight val = wIn[l];
					((BoneWeight)(ref val)).boneIndex0 = array[((BoneWeight)(ref val)).boneIndex0];
					((BoneWeight)(ref val)).boneIndex1 = array[((BoneWeight)(ref val)).boneIndex1];
					((BoneWeight)(ref val)).boneIndex2 = array[((BoneWeight)(ref val)).boneIndex2];
					((BoneWeight)(ref val)).boneIndex3 = array[((BoneWeight)(ref val)).boneIndex3];
					vw[l] = val;
				}
				Stopwatch stopwatch = Stopwatch.StartNew();
				Vector3[] p = (Vector3[])(object)new Vector3[num];
				BoneWeight[] w = (BoneWeight[])(object)new BoneWeight[num];
				BoneWeight[] own = (BoneWeight[])(object)new BoneWeight[num];
				float[] alpha = new float[num];
				byte[] region = new byte[num];
				float[] s0 = new float[num];
				int[] skinTri = new int[num];
				Vector3[] skinBary = (Vector3[])(object)new Vector3[num];
				float[] skinDist = new float[num];
				Parallel.For(0, num, Workers, delegate(int num15)
				{
					//IL_0026: 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_0052: Unknown result type (might be due to invalid IL or missing references)
					//IL_0057: Unknown result type (might be due to invalid IL or missing references)
					//IL_006c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0071: Unknown result type (might be due to invalid IL or missing references)
					//IL_0072: Unknown result type (might be due to invalid IL or missing references)
					//IL_0077: Unknown result type (might be due to invalid IL or missing references)
					//IL_0093: Unknown result type (might be due to invalid IL or missing references)
					//IL_0098: Unknown result type (might be due to invalid IL or missing references)
					//IL_0099: Unknown result type (might be due to invalid IL or missing references)
					//IL_009e: Unknown result type (might be due to invalid IL or missing references)
					//IL_00d4: 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_0114: 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_0134: Unknown result type (might be due to invalid IL or missing references)
					//IL_0139: Unknown result type (might be due to invalid IL or missing references)
					//IL_013e: Unknown result type (might be due to invalid IL or missing references)
					//IL_015c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0161: Unknown result type (might be due to invalid IL or missing references)
					//IL_0166: Unknown result type (might be due to invalid IL or missing references)
					//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
					//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
					//IL_01db: Unknown result type (might be due to invalid IL or missing references)
					//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
					region[num15] = vRegion[Dominant(vw[num15])];
					var (val7, num16) = Field(a[num15], region[num15]);
					p[num15] = a[num15] + val7;
					s0[num15] = num16;
					byte r = region[num15];
					Vector3 point = Vector3.zero;
					Vector3 bary = Vector3.zero;
					int num17 = ((Mathf.Abs(num16) < transferFar * 2f + 0.01f) ? surfGrid.Closest(p[num15], transferFar * 2f, (int t) => Near(r, tTriRegion[t]), out point, out bary) : (-1));
					skinTri[num15] = num17;
					skinBary[num15] = bary;
					float[] array9 = skinDist;
					float num18;
					if (num17 < 0)
					{
						num18 = float.MaxValue;
					}
					else
					{
						Vector3 val8 = point - p[num15];
						num18 = ((Vector3)(ref val8)).magnitude;
					}
					array9[num15] = num18;
					own[num15] = MapNative(vw[num15]);
					alpha[num15] = ((num17 < 0) ? 0f : (1f - Mathf.Clamp01((skinDist[num15] - transferNear) / (transferFar - transferNear))));
					w[num15] = Mix(own[num15], num17, bary, alpha[num15]);
				});
				int[] tris = j.tris;
				int[] weld = Weld(a, 1E-06f);
				List<int>[] adj = Adjacency(weld, tris, num);
				long elapsedMilliseconds = stopwatch.ElapsedMilliseconds;
				List<int> skinPts = SkinPoints(p, region);
				int num2 = Cover(p, s0, region, tris, weld, adj, skinPts);
				long num3 = stopwatch.ElapsedMilliseconds - elapsedMilliseconds;
				int num4;
				int num5;
				if (poses.Count > 0)
				{
					(num4, num5) = Posed(p, w, own, alpha, skinTri, skinBary, skinDist, tris, weld, adj, skinPts);
				}
				else
				{
					num4 = 0;
					num5 = 0;
				}
				long num6 = stopwatch.ElapsedMilliseconds - elapsedMilliseconds - num3;
				List<float> list = new List<float>();
				for (int num7 = 0; num7 < morphs.Length; num7++)
				{
					Vector3[] array4 = j.morphDelta[num7];
					if (array4 == null)
					{
						continue;
					}
					Vector3[] array5 = (Vector3[])(object)new Vector3[num];
					for (int num8 = 0; num8 < num; num8++)
					{
						int num9 = skinTri[num8];
						if (num9 < 0)
						{
							continue;
						}
						float num10 = 1f - Mathf.Clamp01((skinDist[num8] - morphFull) / (morphNone - morphFull));
						if (num10 <= 0f)
						{
							continue;
						}
						Vector3 val2 = Vector3.zero;
						for (int num11 = 0; num11 < 3; num11++)
						{
							int num12 = tTris[num9 * 3 + num11];
							if (num12 < bodyCount && num12 < array4.Length)
							{
								val2 += ((Vector3)(ref skinBary[num8]))[num11] * array4[num12];
							}
						}
						array5[num8] = val2 * num10;
					}
					j.shapes.Add((morphs[num7], array5));
					list.Add(fitWeights[num7]);
				}
				Vector3[] array6 = (Vector3[])(object)new Vector3[num];
				Vector3[] array7 = (Vector3[])(object)new Vector3[num];
				Vector4[] array8 = (Vector4[])(object)((tIn.Length == num) ? new Vector4[num] : null);
				for (int num13 = 0; num13 < num; num13++)
				{
					Matrix4x4 val3 = BlendMatrix(tSkinV, w[num13]);
					Matrix4x4 inverse = ((Matrix4x4)(ref val3)).inverse;
					Vector3 val4 = ((Matrix4x4)(ref inverse)).MultiplyPoint3x4(p[num13]);
					for (int num14 = 0; num14 < j.shapes.Count; num14++)
					{
						val4 -= j.shapes[num14].delta[num13] * (list[num14] / 100f);
					}
					array6[num13] = val4;
					array7[num13] = Unit(((Matrix4x4)(ref inverse)).MultiplyVector(array3[num13]));
					if (array8 != null)
					{
						Vector3 val5 = Unit(BlendVector(array2, wIn[num13], Vector4.op_Implicit(tIn[num13])));
						array8[num13] = new Vector4(0f, 0f, 0f, tIn[num13].w);
						Vector3 val6 = Unit(((Matrix4x4)(ref inverse)).MultiplyVector(val5));
						array8[num13].x = val6.x;
						array8[num13].y = val6.y;
						array8[num13].z = val6.z;
					}
				}
				j.outV = array6;
				j.outN = array7;
				j.outT = array8;
				j.outW = w;
				j.note = $"{num} v, {num2} pushed out of her skin, {num4} follow her skin in motion, {num5} pushed for motion, shapes {j.shapes.Count} (field {elapsedMilliseconds} ms, cover {num3} ms, motion {num6} ms)";
			}

			internal void FitRigid(Job j)
			{
				//IL_005a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0060: Unknown result type (might be due to invalid IL or missing references)
				//IL_0065: Unknown result type (might be due to invalid IL or missing references)
				//IL_006a: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00dd: 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_00e2: Unknown result type (might be due to invalid IL or missing references)
				//IL_016d: 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_0177: 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_0159: Unknown result type (might be due to invalid IL or missing references)
				//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
				//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
				//IL_02c6: 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_022d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0231: Unknown result type (might be due to invalid IL or missing references)
				//IL_0236: Unknown result type (might be due to invalid IL or missing references)
				//IL_030b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0356: Unknown result type (might be due to invalid IL or missing references)
				//IL_035b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0360: Unknown result type (might be due to invalid IL or missing references)
				//IL_0361: Unknown result type (might be due to invalid IL or missing references)
				//IL_0366: Unknown result type (might be due to invalid IL or missing references)
				//IL_036a: Unknown result type (might be due to invalid IL or missing references)
				//IL_036f: Unknown result type (might be due to invalid IL or missing references)
				//IL_029b: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_0278: Unknown result type (might be due to invalid IL or missing references)
				//IL_027d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0281: Unknown result type (might be due to invalid IL or missing references)
				//IL_0286: Unknown result type (might be due to invalid IL or missing references)
				//IL_028b: Unknown result type (might be due to invalid IL or missing references)
				//IL_028c: Unknown result type (might be due to invalid IL or missing references)
				//IL_03a8: Unknown result type (might be due to invalid IL or missing references)
				//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
				//IL_03b2: Unknown result type (might be due to invalid IL or missing references)
				//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
				//IL_03c6: Unknown result type (might be due to invalid IL or missing references)
				//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
				//IL_03d0: Unknown result type (might be due to invalid IL or missing references)
				//IL_03e0: Unknown result type (might be due to invalid IL or missing references)
				//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
				//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
				//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
				//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
				//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
				//IL_03ff: Unknown result type (might be due to invalid IL or missing references)
				//IL_0406: Unknown result type (might be due to invalid IL or missing references)
				//IL_040d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0421: Unknown result type (might be due to invalid IL or missing references)
				//IL_0426: Unknown result type (might be due to invalid IL or missing references)
				if (helmet == null)
				{
					j.note = "no helmet fit data";
					return;
				}
				if (vanillaGrid == null)
				{
					vanillaGrid = new Grid(sv, sTris, 0.03f);
					surfGrid = new Grid(surf, tTris, 0.03f);
				}
				Matrix4x4 val = helmet.SocketV * j.toSocket;
				Vector3[] v = j.v;
				Vector3[] nIn = j.nIn;
				Vector4[] tIn = j.tIn;
				int[] tris = j.tris;
				int num = v.Length;
				Vector3[] array = (Vector3[])(object)new Vector3[num];
				Vector3[] array2 = (Vector3[])(object)new Vector3[num];
				for (int i = 0; i < num; i++)
				{
					array[i] = ((Matrix4x4)(ref val)).MultiplyPoint3x4(v[i]);
					array2[i] = ((nIn.Length == num) ? Unit(((Matrix4x4)(ref val)).MultiplyVector(nIn[i])) : Vector3.up);
				}
				string text = helmet.AlignEyes(array, tris);
				int[] weld = Weld(array, 1E-06f);
				int[] array3 = Islands(weld, tris, num);
				Dictionary<int, Bounds> dictionary = new Dictionary<int, Bounds>();
				Dictionary<int, int> dictionary2 = new Dictionary<int, int>();
				for (int k = 0; k < num; k++)
				{
					if (dictionary.TryGetValue(array3[k], out var value))
					{
						((Bounds)(ref value)).Encapsulate(array[k]);
						dictionary[array3[k]] = value;
					}
					else
					{
						dictionary[array3[k]] = new Bounds(array[k], Vector3.zero);
					}
					dictionary2.TryGetValue(array3[k], out var value2);
					dictionary2[array3[k]] = value2 + 1;
				}
				int num2 = -1;
				foreach (KeyValuePair<int, int> item in dictionary2)
				{
					if (num2 < 0 || item.Value > dictionary2[num2])
					{
						num2 = item.Key;
					}
				}
				Dictionary<int, Vector3> dictionary3 = new Dictionary<int, Vector3>();
				Vector3[] array4 = (Vector3[])(object)new Vector3[num];
				for (int l = 0; l < num; l++)
				{
					int num3 = array3[l];
					if (num3 != num2)
					{
						Bounds val2 = dictionary[num3];
						Vector3 size = ((Bounds)(ref val2)).size;
						if (((Vector3)(ref size)).magnitude < 6f / 95f)
						{
							if (!dictionary3.TryGetValue(num3, out var value3))
							{
								Helmet? obj = helmet;
								val2 = dictionary[num3];
								Vector3 val3 = obj.Fit(((Bounds)(ref val2)).center);
								val2 = dictionary[num3];
								value3 = (dictionary3[num3] = val3 - ((Bounds)(ref val2)).center);
							}
							array4[l] = array[l] + value3;
							continue;
						}
					}
					array4[l] = helmet.Fit(array[l]);
				}
				helmet.ClearEyes();
				byte[] array5 = new byte[num];
				float[] array6 = new float[num];
				for (int m = 0; m < num; m++)
				{
					array5[m] = 1;
					array6[m] = VanillaSigned(array[m], 1);
				}
				List<int>[] adj = Adjacency(weld, tris, num);
				int num4 = Cover(array4, array6, array5, tris, weld, adj, SkinPoints(array4, array5, headSkin: true), headSkin: true);
				Matrix4x4 val5 = Matrix4x4.Translate(helmet.Delta) * val;
				Matrix4x4 inverse = ((Matrix4x4)(ref val5)).inverse;
				Vector3[] array7 = (Vector3[])(object)new Vector3[num];
				Vector3[] array8 = (Vector3[])(object)new Vector3[num];
				Vector4[] array9 = (Vector4[])(object)((tIn.Length == num) ? new Vector4[num] : null);
				for (int n = 0; n < num; n++)
				{
					array7[n] = ((Matrix4x4)(ref inverse)).MultiplyPoint3x4(array4[n]);
					array8[n] = Unit(((Matrix4x4)(ref inverse)).MultiplyVector(array2[n]));
					if (array9 != null)
					{
						Vector3 val6 = Unit(((Matrix4x4)(ref inverse)).MultiplyVector(((Matrix4x4)(ref val)).MultiplyVector(Vector4.op_Implicit(tIn[n]))));
						array9[n] = new Vector4(val6.x, val6.y, val6.z, tIn[n].w);
					}
				}
				j.outV = array7;
				j.outN = array8;
				j.outT = array9;
				j.note = $"{num} v, {text}{dictionary3.Count} small parts moved whole, {num4} pushed out of the skin";
			}

			private static int[] Islands(int[] weld, int[] tris, int n)
			{
				int[] parent = new int[n];
				for (int i = 0; i < n; i++)
				{
					parent[i] = weld[i];
				}
				for (int j = 0; j + 2 < tris.Length; j += 3)
				{
					int num = Find(tris[j]);
					parent[Find(tris[j + 1])] = num;
					parent[Find(tris[j + 2])] = num;
				}
				int[] array = new int[n];
				for (int k = 0; k < n; k++)
				{
					array[k] = Find(k);
				}
				return array;
				int Find(int x)
				{
					while (parent[x] != x)
					{
						parent[x] = parent[parent[x]];
						x = parent[x];
					}
					return x;
				}
			}

			private BoneWeight Mix(BoneWeight own, int k, Vector3 bc, float alpha)
			{
				//IL_000d: 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_003b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0059: Unknown result type (might be due to invalid IL or missing references)
				if (alpha <= 0f || k < 0)
				{
					return own;
				}
				Dictionary<int, float> acc = new Dictionary<int, float>();
				Accumulate(acc, own, 1f - alpha);
				for (int i = 0; i < 3; i++)
				{
					Accumulate(acc, tw[tTris[k * 3 + i]], alpha * ((Vector3)(ref bc))[i]);
				}
				return Top4(acc);
			}

			private (int follow, int pushed) Posed(Vector3[] p, BoneWeight[] w, BoneWeight[] own, float[] alpha, int[] skinTri, Vector3[] skinBary, float[] skinDist, int[] tris, int[] weld, List<int>[] adj, List<int> skinPts)
			{
				//IL_006e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0073: Unknown result type (might be due to invalid IL or missing references)
				//IL_0078: Unknown result type (might be due to invalid IL or missing references)
				//IL_007c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0081: Unknown result type (might be due to invalid IL or missing references)
				//IL_0091: Unknown result type (might be due to invalid IL or missing references)
				//IL_0096: Unknown result type (might be due to invalid IL or missing references)
				//IL_009b: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
				//IL_010f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0114: Unknown result type (might be due to invalid IL or missing references)
				//IL_0119: Unknown result type (might be due to invalid IL or missing references)
				//IL_0127: Unknown result type (might be due to invalid IL or missing references)
				//IL_012c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0131: Unknown result type (might be due to invalid IL or missing references)
				//IL_0143: Unknown result type (might be due to invalid IL or missing references)
				//IL_0148: Unknown result type (might be due to invalid IL or missing references)
				//IL_014d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0152: Unknown result type (might be due to invalid IL or missing references)
				//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
				//IL_0204: Unknown result type (might be due to invalid IL or missing references)
				//IL_0208: Unknown result type (might be due to invalid IL or missing references)
				//IL_020d: 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_021e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0759: Unknown result type (might be due to invalid IL or missing references)
				//IL_0762: Unknown result type (might be due to invalid IL or missing references)
				//IL_0767: Unknown result type (might be due to invalid IL or missing references)
				//IL_076c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0258: Unknown result type (might be due to invalid IL or missing references)
				//IL_025d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0262: Unknown result type (might be due to invalid IL or missing references)
				//IL_0278: Unknown result type (might be due to invalid IL or missing references)
				//IL_027d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0282: Unknown result type (might be due to invalid IL or missing references)
				//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
				//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
				//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
				//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
				//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
				//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
				//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
				//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
				//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
				//IL_0336: Unknown result type (might be due to invalid IL or missing references)
				//IL_033b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0348: Unknown result type (might be due to invalid IL or missing references)
				//IL_034f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0608: Unknown result type (might be due to invalid IL or missing references)
				//IL_060d: Unknown result type (might be due to invalid IL or missing references)
				//IL_06c3: Unknown result type (might be due to invalid IL or missing references)
				//IL_06c8: Unknown result type (might be due to invalid IL or missing references)
				//IL_06db: Unknown result type (might be due to invalid IL or missing references)
				//IL_06e0: Unknown result type (might be due to invalid IL or missing references)
				//IL_06e2: Unknown result type (might be due to invalid IL or missing references)
				//IL_06eb: Unknown result type (might be due to invalid IL or missing references)
				//IL_06f0: Unknown result type (might be due to invalid IL or missing references)
				//IL_06f5: Unknown result type (might be due to invalid IL or missing references)
				//IL_0721: Unknown result type (might be due to invalid IL or missing references)
				//IL_0726: Unknown result type (might be due to invalid IL or missing references)
				//IL_0728: Unknown result type (might be due to invalid IL or missing references)
				//IL_072d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0708: Unknown result type (might be due to invalid IL or missing references)
				//IL_0713: Unknown result type (might be due to invalid IL or missing references)
				//IL_0718: Unknown result type (might be due to invalid IL or missing references)
				//IL_0626: Unknown result type (might be due to invalid IL or missing references)
				//IL_062c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0631: Unknown result type (might be due to invalid IL or missing references)
				//IL_0636: Unknown result type (might be due to invalid IL or missing references)
				//IL_0651: Unknown result type (might be due to invalid IL or missing references)
				//IL_065e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0663: Unknown result type (might be due to invalid IL or missing references)
				//IL_0669: Unknown result type (might be due to invalid IL or missing references)
				//IL_066e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0675: Unknown result type (might be due to invalid IL or missing references)
				//IL_067a: Unknown result type (might be due to invalid IL or missing references)
				//IL_06a2: Unknown result type (might be due to invalid IL or missing references)
				//IL_069b: Unknown result type (might be due to invalid IL or missing references)
				//IL_059b: Unknown result type (might be due to invalid IL or missing references)
				//IL_05a9: Unknown result type (might be due to invalid IL or missing references)
				//IL_05b0: Unknown result type (might be due to invalid IL or missing references)
				//IL_05b5: Unknown result type (might be due to invalid IL or missing references)
				//IL_06a4: Unknown result type (might be due to invalid IL or missing references)
				//IL_0424: Unknown result type (might be due to invalid IL or missing references)
				//IL_0429: Unknown result type (might be due to invalid IL or missing references)
				//IL_042e: Unknown result type (might be due to invalid IL or missing references)
				//IL_043b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0440: Unknown result type (might be due to invalid IL or missing references)
				//IL_0446: Unknown result type (might be due to invalid IL or missing references)
				//IL_044d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0452: Unknown result type (might be due to invalid IL or missing references)
				//IL_0457: Unknown result type (might be due to invalid IL or missing references)
				//IL_045c: Unknown result type (might be due to invalid IL or missing references)
				int num = p.Length;
				int count = skinPts.Count;
				if (count == 0)
				{
					return (follow: 0, pushed: 0);
				}
				Vector3[][] array = new Vector3[poses.Count][];
				Vector3[][] array2 = new Vector3[poses.Count][];
				Vector3[] array3 = (Vector3[])(object)new Vector3[count];
				Vector3[] array4 = (Vector3[])(object)new Vector3[count];
				Matrix4x4 val;
				for (int i = 0; i < count; i++)
				{
					int num2 = skinPts[i];
					val = BlendMatrix(tSkinV, tw[num2]);
					Matrix4x4 inverse = ((Matrix4x4)(ref val)).inverse;
					array3[i] = ((Matrix4x4)(ref inverse)).MultiplyPoint3x4(tv[num2]);
					array4[i] = ((Matrix4x4)(ref inverse)).MultiplyVector(tn[num2]);
				}
				for (int j = 0; j < poses.Count; j++)
				{
					array[j] = (Vector3[])(object)new Vector3[count];
					array2[j] = (Vector3[])(object)new Vector3[count];
					Matrix4x4[] item = poses[j].skin;
					for (int k = 0; k < count; k++)
					{
						Matrix4x4 val2 = BlendMatrix(item, tw[skinPts[k]]);
						array[j][k] = ((Matrix4x4)(ref val2)).MultiplyPoint3x4(array3[k]);
						array2[j][k] = Unit(((Matrix4x4)(ref val2)).MultiplyVector(array4[k]));
					}
				}
				Vector3[] array5 = (Vector3[])p.Clone();
				bool[] array6 = new bool[num];
				int num3 = 0;
				Vector3[] array7 = (Vector3[])(object)new Vector3[num];
				Vector3[] array8 = (Vector3[])(object)new Vector3[num];
				Matrix4x4[] array9 = (Matrix4x4[])(object)new Matrix4x4[num];
				Vector3[] fn = (Vector3[])(object)new Vector3[tris.Length / 3];
				for (int l = 0; l < 4; l++)
				{
					bool flag = l >= 2;
					Vector3[] array10 = (Vector3[])(object)new Vector3[num];
					float[] array11 = new float[num];
					bool[] array12 = new bool[num];
					int num4 = 0;
					for (int m = 0; m < num; m++)
					{
						int num5 = m;
						val = BlendMatrix(tSkinV, w[m]);
						val = ((Matrix4x4)(ref val)).inverse;
						array8[num5] = ((Matrix4x4)(ref val)).MultiplyPoint3x4(p[m]);
					}
					for (int n = 0; n < poses.Count; n++)
					{
						Matrix4x4[] item2 = poses[n].skin;
						for (int num6 = 0; num6 < num; num6++)
						{
							array9[num6] = BlendMatrix(item2, w[num6]);
							array7[num6] = ((Matrix4x4)(ref array9[num6])).MultiplyPoint3x4(array8[num6]);
						}
						Grid grid = new Grid(array7, tris, 0.03f);
						for (int num7 = 0; num7 < fn.Length; num7++)
						{
							fn[num7] = Unit(Vector3.Cross(array7[tris[num7 * 3 + 1]] - array7[tris[num7 * 3]], array7[tris[num7 * 3 + 2]] - array7[tris[num7 * 3]]));
						}
						for (int num8 = 0; num8 < count; num8++)
						{
							Vector3 nq = array2[n][num8];
							float tHit;
							Vector3 bary;
							int num9 = grid.Ray(array[n][num8], nq, coverReach, (int t) => Vector3.Dot(fn[t], nq) > 0.2f, out tHit, out bary);
							if (num9 < 0 || tHit >= clearance)
							{
								continue;
							}
							bool flag2 = false;
							for (int num10 = 0; num10 < 3; num10++)
							{
								if (skinDist[tris[num9 * 3 + num10]] < 0.1f)
								{
									flag2 = true;
								}
							}
							if (!flag2)
							{
								continue;
							}
							num4++;
							float num11 = clearance - tHit;
							for (int num12 = 0; num12 < 3; num12++)
							{
								int num13 = tris[num9 * 3 + num12];
								int num14 = weld[num13];
								array12[num14] = true;
								float num15 = num11 * Mathf.Clamp01(((Vector3)(ref bary))[num12] * 1.5f);
								if (flag && !(num15 <= array11[num14]))
								{
									array11[num14] = num15;
									val = BlendMatrix(tSkinV, w[num13]);
									Matrix4x4 inverse2 = ((Matrix4x4)(ref array9[num13])).inverse;
									array10[num14] = ((Matrix4x4)(ref val)).MultiplyVector(((Matrix4x4)(ref inverse2)).MultiplyVector(nq * num15));
								}
							}
						}
					}
					if (num4 == 0)
					{
						break;
					}
					if (!flag)
					{
						float[] array13 = new float[num];
						for (int num16 = 0; num16 < num; num16++)
						{
							if (array12[num16])
							{
								array13[num16] = 1f;
							}
						}
						for (int num17 = 0; num17 < 2; num17++)
						{
							float[] array14 = (float[])array13.Clone();
							for (int num18 = 0; num18 < num; num18++)
							{
								if (weld[num18] != num18)
								{
									continue;
								}
								foreach (int item3 in adj[num18])
								{
									array14[num18] = Mathf.Max(array14[num18], array13[item3] * 0.6f);
								}
							}
							array13 = array14;
						}
						bool flag3 = false;
						for (int num19 = 0; num19 < num; num19++)
						{
							float num20 = array13[weld[num19]];
							if (!(num20 <= alpha[num19] + 0.01f) && skinTri[num19] >= 0)
							{
								if (!array6[num19])
								{
									array6[num19] = true;
									num3++;
								}
								alpha[num19] = num20;
								w[num19] = Mix(own[num19], skinTri[num19], skinBary[num19], num20);
								flag3 = true;
							}
						}
						if (!flag3)
						{
							l = 1;
						}
						continue;
					}
					Vector3[] array15 = (Vector3[])array10.Clone();
					for (int num21 = 0; num21 < num; num21++)
					{
						if (weld[num21] != num21 || adj[num21].Count == 0)
						{
							continue;
						}
						Vector3 val3 = Vector3.zero;
						foreach (int item4 in adj[num21])
						{
							val3 += array10[item4];
						}
						val3 /= (float)adj[num21].Count;
						Vector3 val4 = Vector3.Lerp(array10[num21], val3, 0.5f);
						array15[num21] = ((((Vector3)(ref val4)).sqrMagnitude > ((Vector3)(ref array10[num21])).sqrMagnitude) ? val4 : array10[num21]);
					}
					for (int num22 = 0; num22 < num; num22++)
					{
						Vector3 val5 = array15[weld[num22]];
						if (!(((Vector3)(ref val5)).sqrMagnitude <= 0f))
						{
							Vector3 val6 = p[num22] + val5 - array5[num22];
							if (((Vector3)(ref val6)).magnitude > maxPush)
							{
								val6 = ((Vector3)(ref val6)).normalized * maxPush;
							}
							p[num22] = array5[num22] + val6;
						}
					}
				}
				int num23 = 0;
				for (int num24 = 0; num24 < num; num24++)
				{
					Vector3 val7 = p[num24] - array5[num24];
					if (((Vector3)(ref val7)).sqrMagnitude > 1E-10f)
					{
						num23++;
					}
				}
				return (follow: num3, pushed: num23);
			}

			private List<int> SkinPoints(Vector3[] p, byte[] region, bool headSkin = false)
			{
				//IL_0000: 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_0010: 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_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_002b: Unknown result type (might be due to invalid IL or missing references)
				//IL_002f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: Unknown result type (might be due to invalid IL or missing references)
				//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_003e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0043: Unknown result type (might be due to invalid IL or missing references)
				//IL_0048: Unknown result type (might be due to invalid IL or missing references)
				//IL_0061: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: Unknown result type (might be due to invalid IL or missing references)
				//IL_006d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				//IL_0077: 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_0079: Unknown result type (might be due to invalid IL or missing references)
				//IL_0084: Unknown result type (might be due to invalid IL or missing references)
				//IL_0089: Unknown result type (might be due to invalid IL or missing references)
				//IL_008e: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ac: 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_00be: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d0: 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_00df: 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_00ee: 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_00fd: Unknown result type (might be due to invalid IL or missing references)
				//IL_0104: Unknown result type (might be due to invalid IL or missing references)
				Vector3 val = Vector3.one * float.MaxValue;
				Vector3 val2 = Vector3.one * float.MinValue;
				HashSet<byte> hashSet = new HashSet<byte>();
				for (int i = 0; i < p.Length; i++)
				{
					val = Vector3.Min(val, p[i]);
					val2 = Vector3.Max(val2, p[i]);
					hashSet.Add(region[i]);
				}
				val -= Vector3.one * coverReach;
				val2 += Vector3.one * coverReach;
				List<int> list = new List<int>();
				for (int j = 0; j < tv.Length; j++)
				{
					Vector3 val3 = tv[j];
					if (val3.x < val.x || val3.y < val.y || val3.z < val.z || val3.x > val2.x || val3.y > val2.y || val3.z > val2.z)
					{
						continue;
					}
					byte b = vRegionOfTarget(j);
					if (b == 1 && !headSkin)
					{
						continue;
					}
					foreach (byte item in hashSet)
					{
						if (Near(item, b))
						{
							list.Add(j);
							break;
						}
					}
				}
				return list;
			}

			private int Cover(Vector3[] p, float[] s0, byte[] region, int[] tris, int[] weld, List<int>[] adj, List<int> skinPts, bool headSkin = false)
			{
				//IL_054c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0555: Unknown result type (might be due to invalid IL or missing references)
				//IL_055a: Unknown result type (might be due to invalid IL or missing references)
				//IL_055f: 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_0208: Unknown result type (might be due to invalid IL or missing references)
				//IL_0215: Unknown result type (might be due to invalid IL or missing references)
				//IL_021a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0229: Unknown result type (might be due to invalid IL or missing references)
				//IL_0236: Unknown result type (might be due to invalid IL or missing references)
				//IL_023b: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_010b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0123: Unknown result type (might be due to invalid IL or missing references)
				//IL_0128: Unknown result type (might be due to invalid IL or missing references)
				//IL_012d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0147: Unknown result type (might be due to invalid IL or missing references)
				//IL_014c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0151: Unknown result type (might be due to invalid IL or missing references)
				//IL_0156: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_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_0184: 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_018e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0190: 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_01b1: Unknown result type (might be due to invalid IL or missing references)
				//IL_0294: Unknown result type (might be due to invalid IL or missing references)
				//IL_0299: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
				//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
				//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
				//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
				//IL_0316: Unknown result type (might be due to invalid IL or missing references)
				//IL_03aa: Unknown result type (might be due to invalid IL or missing references)
				//IL_03af: Unknown result type (might be due to invalid IL or missing references)
				//IL_0489: Unknown result type (might be due to invalid IL or missing references)
				//IL_048e: Unknown result type (might be due to invalid IL or missing references)
				//IL_04a4: Unknown result type (might be due to invalid IL or missing references)
				//IL_04a9: Unknown result type (might be due to invalid IL or missing references)
				//IL_04ab: Unknown result type (might be due to invalid IL or missing references)
				//IL_04b4: Unknown result type (might be due to invalid IL or missing references)
				//IL_04b9: Unknown result type (might be due to invalid IL or missing references)
				//IL_04be: Unknown result type (might be due to invalid IL or missing references)
				//IL_04dd: Unknown result type (might be due to invalid IL or missing references)
				//IL_04e2: Unknown result type (might be due to invalid IL or missing references)
				//IL_04e4: Unknown result type (might be due to invalid IL or missing references)
				//IL_04ec: Unknown result type (might be due to invalid IL or missing references)
				//IL_04f1: Unknown result type (might be due to invalid IL or missing references)
				//IL_04f6: Unknown result type (might be due to invalid IL or missing references)
				//IL_04cc: Unknown result type (might be due to invalid IL or missing references)
				//IL_04d2: Unknown result type (might be due to invalid IL or missing references)
				//IL_04d7: Unknown result type (might be due to invalid IL or missing references)
				//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
				//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
				//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
				//IL_03dd: Unknown result type (might be due to invalid IL or missing references)
				//IL_050d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0512: Unknown result type (might be due to invalid IL or missing references)
				//IL_0514: Unknown result type (might be due to invalid IL or missing references)
				//IL_0519: Unknown result type (might be due to invalid IL or missing references)
				//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
				//IL_0405: Unknown result type (might be due to invalid IL or missing references)
				//IL_040a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0415: Unknown result type (might be due to invalid IL or missing references)
				//IL_041a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0421: Unknown result type (might be due to invalid IL or missing references)
				//IL_0426: Unknown result type (might be due to invalid IL or missing references)
				//IL_0458: Unknown result type (might be due to invalid IL or missing references)
				//IL_0451: Unknown result type (might be due to invalid IL or missing references)
				//IL_045a: Unknown result type (might be due to invalid IL or missing references)
				float num = (headSkin ? (1f / 19f) : coverDepth);
				float num2 = (headSkin ? (9f / 190f) : maxPush);
				int num3 = p.Length;
				Vector3[] array = (Vector3[])p.Clone();
				Vector3 val6;
				for (int i = 0; i < 8; i++)
				{
					Vector3[] need = (Vector3[])(object)new Vector3[num3];
					float[] needLen = new float[num3];
					for (int j = 0; j < num3; j++)
					{
						if (s0[j] < -0.01f || weld[j] != j)
						{
							continue;
						}
						byte r = region[j];
						Vector3 point;
						Vector3 bary;
						int num4 = surfGrid.Closest(p[j], coverReach, (int t) => Near(r, tTriRegion[t]) && (headSkin || tTriRegion[t] != 1), out point, out bary);
						if (num4 >= 0)
						{
							Vector3 val = Unit(bary.x * tn[tTris[num4 * 3]] + bary.y * tn[tTris[num4 * 3 + 1]] + bary.z * tn[tTris[num4 * 3 + 2]]);
							float num5 = Vector3.Dot(p[j] - point, val);
							if (num5 < clearance)
							{
								Want(j, val, clearance - num5);
							}
						}
					}
					Grid grid = new Grid(p, tris, 0.03f);
					Vector3[] fn = (Vector3[])(object)new Vector3[tris.Length / 3];
					for (int num6 = 0; num6 < fn.Length; num6++)
					{
						fn[num6] = Unit(Vector3.Cross(p[tris[num6 * 3 + 1]] - p[tris[num6 * 3]], p[tris[num6 * 3 + 2]] - p[tris[num6 * 3]]));
					}
					int num7 = 0;
					foreach (int skinPt in skinPts)
					{
						Vector3 o = tv[skinPt];
						Vector3 nq = tn[skinPt];
						float tHit;
						Vector3 bary2;
						int num8 = grid.Ray(o, nq, coverReach, (int t) => Vector3.Dot(fn[t], nq) > 0.2f, out tHit, out bary2);
						if (num8 >= 0 && !(tHit >= clearance) && !(tHit < 0f - num))
						{
							float num9 = clearance - tHit;
							num7++;
							for (int num10 = 0; num10 < 3; num10++)
							{
								Want(tris[num8 * 3 + num10], nq, num9 * Mathf.Clamp01(((Vector3)(ref bary2))[num10] * 1.5f));
							}
						}
					}
					if (num7 == 0 && i > 0)
					{
						break;
					}
					Vector3[] array2 = (Vector3[])need.Clone();
					for (int num11 = 0; num11 < num3; num11++)
					{
						if (weld[num11] != num11 || adj[num11].Count == 0)
						{
							continue;
						}
						Vector3 val2 = Vector3.zero;
						foreach (int item in adj[num11])
						{
							val2 += need[item];
						}
						val2 /= (float)adj[num11].Count;
						Vector3 val3 = Vector3.Lerp(need[num11], val2, 0.5f);
						array2[num11] = ((((Vector3)(ref val3)).sqrMagnitude > ((Vector3)(ref need[num11])).sqrMagnitude) ? val3 : need[num11]);
					}
					bool flag = false;
					for (int num12 = 0; num12 < num3; num12++)
					{
						Vector3 val4 = array2[weld[num12]];
						if (!(((Vector3)(ref val4)).sqrMagnitude <= 0f))
						{
							Vector3 val5 = p[num12] + val4 - array[num12];
							if (((Vector3)(ref val5)).magnitude > num2)
							{
								val5 = ((Vector3)(ref val5)).normalized * num2;
							}
							val6 = array[num12] + val5 - p[num12];
							if (!(((Vector3)(ref val6)).sqrMagnitude < 1E-12f))
							{
								p[num12] = array[num12] + val5;
								flag = true;
							}
						}
					}
					if (!flag)
					{
						break;
					}
					void Want(int vtx, Vector3 dir, float amount)
					{
						//IL_0029: Unknown result type (might be due to invalid IL or missing references)
						//IL_002b: Unknown result type (might be due to invalid IL or missing references)
						//IL_0030: Unknown result type (might be due to invalid IL or missing references)
						int num15 = weld[vtx];
						if (amount > needLen[num15])
						{
							needLen[num15] = amount;
							need[num15] = dir * amount;
						}
					}
				}
				int num13 = 0;
				for (int num14 = 0; num14 < num3; num14++)
				{
					val6 = p[num14] - array[num14];
					if (((Vector3)(ref val6)).sqrMagnitude > 1E-10f)
					{
						num13++;
					}
				}
				return num13;
			}

			private byte vRegionOfTarget(int i)
			{
				if (vertexRegion == null)
				{
					vertexRegion = new byte[tv.Length];
					for (int j = 0; j < tTriRegion.Length; j++)
					{
						for (int k = 0; k < 3; k++)
						{
							vertexRegion[tTris[j * 3 + k]] = tTriRegion[j];
						}
					}
				}
				return vertexRegion[i];
			}
		}

		private sealed class Helmet
		{
			private sealed class Shape
			{
				internal Vector3 Centre;

				internal readonly float[,] R = new float[48, 23];

				internal float Radius(Vector3 d)
				{
					//IL_0008: Unknown result type (might be due to invalid IL or missing references)
					//IL_000e: Unknown result type (might be due to invalid IL or missing references)
					//IL_0030: Unknown result type (might be due to invalid IL or missing references)
					float num = Mathf.Repeat(Mathf.Atan2(d.x, d.z) * 57.29578f, 360f) / 7.5f;
					float num2 = (Mathf.Asin(Mathf.Clamp(d.y, -1f, 1f)) * 57.29578f - -75f) / 7.5f;
					if (num2 < 0f)
					{
						return -1f;
					}
					int num3 = (int)num % 48;
					int i = (num3 + 1) % 48;
					int num4 = Mathf.Min((int)num2, 22);
					int j = Mathf.Min(num4 + 1, 22);
					float num5 = num - Mathf.Floor(num);
					float num6 = Mathf.Clamp01(num2 - (float)num4);
					float sum = 0f;
					float wsum = 0f;
					Add(num3, num4, (1f - num5) * (1f - num6));
					Add(i, num4, num5 * (1f - num6));
					Add(num3, j, (1f - num5) * num6);
					Add(i, j, num5 * num6);
					if (!(wsum > 0.25f))
					{
						return -1f;
					}
					return sum / wsum;
					void Add(int num7, int num8, float w)
					{
						if (R[num7, num8] > 0f && w > 0f)
						{
							sum += R[num7, num8] * w;
							wsum += w;
						}
					}
				}
			}

			private const int Lon = 48;

			private const int Lat = 23;

			private const float LatMin = -75f;

			internal readonly Matrix4x4 SocketV;

			internal readonly Vector3 Delta;

			private readonly bool hasEyes;

			private readonly Vector3 herEyes;

			private readonly float herEyeHalfSpan;

			private readonly Shape vanilla;

			private readonly Shape target;

			private float eyeShift;

			private float eyeLat;

			private float meanRatio = -1f;

			internal Helmet(BinaryReader r, Matrix4x4 socketV)
			{
				//IL_001a: 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_0042: Unknown result type (might be due to invalid IL or missing references)
				//IL_0047: Unknown result type (might be due to invalid IL or missing references)
				//IL_007f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0084: Unknown result type (might be due to invalid IL or missing references)
				BinaryReader r2 = r;
				base..ctor();
				SocketV = socketV;
				Delta = new Vector3(r2.ReadSingle(), r2.ReadSingle(), r2.ReadSingle());
				hasEyes = r2.ReadBoolean();
				herEyes = new Vector3(r2.ReadSingle(), r2.ReadSingle(), r2.ReadSingle());
				herEyeHalfSpan = r2.ReadSingle();
				vanilla = S();
				target = S();
				Shape S()
				{
					//IL_0027: Unknown result type (might be due to invalid IL or missing references)
					//IL_002c: Unknown result type (might be due to invalid IL or missing references)
					Shape shape = new Shape
					{
						Centre = new Vector3(r2.ReadSingle(), r2.ReadSingle(), r2.ReadSingle())
					};
					for (int i = 0; i < 48; i++)
					{
						for (int j = 0; j < 23; j++)
						{
							shape.R[i, j] = r2.ReadSingle();
						}
					}
					return shape;
				}
			}

			internal Vector3 Fit(Vector3 p)
			{
				//IL_0000: 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_002e: 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_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_003d: 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_0051: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_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_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_00a7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
				Vector3 val = p - vanilla.Centre;
				float magnitude = ((Vector3)(ref val)).magnitude;
				if (magnitude < 1E-05f)
				{
					return target.Centre;
				}
				val /= magnitude;
				Vector3 val2 = Warp(val);
				float num = vanilla.Radius(val);
				float num2 = target.Radius(val2);
				if (num <= 0f || num2 <= 0f)
				{
					return target.Centre + val2 * (magnitude * MeanRatio());
				}
				return target.Centre + val2 * ((magnitude >= num) ? (num2 + (magnitude - num)) : (magnitude * num2 / num));
			}

			private Vector3 Warp(Vector3 d)
			{
				//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_000d: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
				if (eyeShift == 0f)
				{
					return d;
				}
				float num = Mathf.Asin(Mathf.Clamp(d.y, -1f, 1f));
				float num2 = Mathf.Atan2(d.x, d.z);
				float num3 = Mathf.Max(0f, Mathf.Cos(num2));
				float num4 = -1.3089969f;
				float num5 = (float)Math.PI / 2f;
				float num6 = ((num <= eyeLat) ? Mathf.Clamp01((num - num4) / (eyeLat - num4)) : Mathf.Clamp01((num5 - num) / (num5 - eyeLat)));
				float num7 = num + eyeShift * num3 * num6;
				return new Vector3(Mathf.Cos(num7) * Mathf.Sin(num2), Mathf.Sin(num7), Mathf.Cos(num7) * Mathf.Cos(num2));
			}

			internal string AlignEyes(Vector3[] a, int[] tris)
			{
				//IL_001a: 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_0026: 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_006b: Unknown result type (might be due to invalid IL or missing references)
				//IL_025b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0273: Unknown result type (might be due to invalid IL or missing references)
				//IL_0275: Unknown result type (might be due to invalid IL or missing references)
				//IL_0276: Unknown result type (might be due to invalid IL or missing references)
				//IL_027b: 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_00f7: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a4: 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_02ab: Unknown result type (might be due to invalid IL or missing references)
				//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
				//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
				//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
				//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
				//IL_02de: Unknown result type (might be due to invalid IL or missing references)
				//IL_0114: Unknown result type (might be due to invalid IL or missing references)
				//IL_0116: Unknown result type (might be due to invalid IL or missing references)
				//IL_0120: Unknown result type (might be due to invalid IL or missing references)
				//IL_012c: 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_017b: Unknown result type (might be due to invalid IL or missing references)
				ClearEyes();
				if (!hasEyes)
				{
					return "";
				}
				Vector3 centre = vanilla.Centre;
				float num = vanilla.Radius(Vector3.right);
				float num2 = target.Radius(Vector3.right);
				float num3 = herEyeHalfSpan * ((num > 0f && num2 > 0f) ? (num / num2) : 1f);
				float num4 = 0.0021052633f;
				float num5 = centre.y + 12f / 95f;
				float num6 = 0.3157895f;
				int num7 = Mathf.CeilToInt(24f / 95f / num4);
				float num8 = 0f;
				float num9 = 0f;
				int num10 = 0;
				float[] array = new float[2] { -1f, 1f };
				Vector3 val = default(Vector3);
				foreach (float num11 in array)
				{
					bool[] array2 = new bool[num7];
					float[] array3 = new float[num7];
					for (int j = 0; j < num7; j++)
					{
						((Vector3)(ref val))..ctor(centre.x + num11 * num3, num5 - (float)j * num4, centre.z - 0.02105263f);
						float num12 = float.MaxValue;
						for (int k = 0; k + 2 < tris.Length; k += 3)
						{
							if (Grid.RayTriangle(val, Vector3.forward, a[tris[k]], a[tris[k + 1]], a[tris[k + 2]], out var t, out var _, out var _) && t > 0f && t < num12)
							{
								num12 = t;
							}
						}
						array2[j] = num12 < num6;
						array3[j] = val.z + num12;
					}
					int l;
					for (l = 0; l < num7 && !array2[l]; l++)
					{
					}
					for (; l < num7 && array2[l]; l++)
					{
					}
					int m;
					for (m = l; m < num7 && !array2[m]; m++)
					{
					}
					if (l != 0 && l < num7 && m < num7)
					{
						float num13 = (float)(m - l) * num4;
						if (!(num13 < 0.008421053f) && !(num13 > 6f / 95f))
						{
							num8 += num5 - 0.5f * (float)(l + m) * num4;
							num9 += 0.5f * (array3[l - 1] + array3[m]);
							num10++;
						}
					}
				}
				if (num10 < 2)
				{
					return "";
				}
				Vector3 val2 = default(Vector3);
				((Vector3)(ref val2))..ctor(centre.x, num8 / (float)num10, num9 / (float)num10);
				eyeLat = Mathf.Asin(Mathf.Clamp(Unit(val2 - centre).y, -1f, 1f));
				for (int n = 0; n < 4; n++)
				{
					Vector3 val3 = Fit(val2);
					float num14 = eyeShift;
					float num15 = herEyes.y - val3.y;
					Vector3 val4 = val3 - target.Centre;
					eyeShift = num14 + num15 / Mathf.Max(0.01f, ((Vector3)(ref val4)).magnitude);
				}
				return $"eye openings lifted {eyeShift * 57.29578f:F1} deg, ";
			}

			internal void ClearEyes()
			{
				eyeShift = 0f;
				eyeLat = 0f;
			}

			private float MeanRatio()
			{
				if (meanRatio > 0f)
				{
					return meanRatio;
				}
				float num = 0f;
				int num2 = 0;
				for (int i = 0; i < 48; i++)
				{
					for (int j = 0; j < 23; j++)
					{
						if (vanilla.R[i, j] > 0f && target.R[i, j] > 0f)
						{
							num += target.R[i, j] / vanilla.R[i, j];
							num2++;
						}
					}
				}
				return meanRatio = ((num2 > 0) ? (num / (float)num2) : 1f);
			}
		}

		private sealed class Grid
		{
			private readonly Vector3[] v;

			private readonly int[] t;

			private readonly float cell;

			private readonly Dictionary<Vector3Int, List<int>> cells = new Dictionary<Vector3Int, List<int>>();

			private readonly Dictionary<Vector3Int, List<int>> coarse = new Dictionary<Vector3Int, List<int>>();

			private readonly ThreadLocal<int[]> stamps;

			[ThreadStatic]
			private static int query;

			private const int Coarse = 4;

			internal Grid(Vector3[] v, int[] tris, float cell)
			{
				//IL_0066: Unknown result type (might be due to invalid IL or missing references)
				//IL_006b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0074: Unknown result type (might be due to invalid IL or missing references)
				//IL_0079: Unknown result type (might be due to invalid IL or missing references)
				//IL_0082: Unknown result type (might be due to invalid IL or missing references)
				//IL_0087: Unknown result type (might be due to invalid IL or missing references)
				//IL_0089: 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_009f: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_00b0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c3: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
				//IL_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)