Decompiled source of NaiLongFogSkins v1.0.9

BepInEx/plugins/Local-NaiLongFogSkins/NaiLongFogSkins.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using GameData;
using Gear;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using Player;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: InternalsVisibleTo("NaiLongProbe")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("NaiLongFogSkins")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.9.0")]
[assembly: AssemblyInformationalVersion("1.0.9")]
[assembly: AssemblyProduct("NaiLongFogSkins")]
[assembly: AssemblyTitle("NaiLongFogSkins")]
[assembly: AssemblyVersion("1.0.9.0")]
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;
		}
	}
}
namespace NaiLongFogSkins
{
	internal static class Assets
	{
		internal sealed record Part(Mesh Mesh, Material Material);

		private const uint Magic = 827147095u;

		private static Part[] parts;

		private static readonly List<Material> glow = new List<Material>();

		internal static bool Emitting { get; private set; } = true;

		internal static float Gain { get; private set; } = 0.35f;

		internal static void Configure(bool emitting, float gain)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			Emitting = emitting;
			Gain = Mathf.Clamp(gain, 0f, 1f);
			Apply();
			ManualLogSource logSource = Plugin.LogSource;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(22, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Art emission=");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(Emitting);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" eyeGain=");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(Gain, "F2");
			}
			logSource.LogInfo(val);
		}

		private static void Apply()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			Color val = Color.white * (Emitting ? Gain : 0f);
			foreach (Material item in glow)
			{
				if (!((Object)(object)item == (Object)null))
				{
					item.SetColor("_EmissionColor", val);
				}
			}
			FpGearMaterial.ApplyAll(Emitting, Gain);
		}

		internal static Part[] Parts()
		{
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Expected O, but got Unknown
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0533: Unknown result type (might be due to invalid IL or missing references)
			//IL_053a: Expected O, but got Unknown
			//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)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_037e: Unknown result type (might be due to invalid IL or missing references)
			//IL_041f: 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_043d: Expected O, but got Unknown
			if (parts != null)
			{
				return parts;
			}
			string text = Path.Combine(Plugin.Root, "nailong.wcm");
			if (!File.Exists(text))
			{
				throw new FileNotFoundException("art file missing", text);
			}
			byte[] buffer = File.ReadAllBytes(text);
			BinaryReader r = new BinaryReader(new MemoryStream(buffer, writable: false));
			List<Object> owned;
			Dictionary<string, Texture2D> textures;
			try
			{
				if (r.ReadUInt32() != 827147095)
				{
					throw new InvalidDataException("WCM1 header");
				}
				owned = new List<Object>();
				textures = new Dictionary<string, Texture2D>();
				try
				{
					Shader val = Shader.Find("Standard");
					if ((Object)(object)val == (Object)null || !val.isSupported)
					{
						throw new NotSupportedException("Standard shader unavailable");
					}
					int num = r.ReadInt32();
					if (num < 1 || num > 64)
					{
						throw new InvalidDataException("material count");
					}
					Material[] array = (Material[])(object)new Material[num];
					Color color = default(Color);
					for (int i = 0; i < num; i++)
					{
						Texture2D val2 = Texture();
						((Color)(ref color))..ctor(F(), F(), F(), F());
						float num2 = F();
						Texture2D val3 = Texture();
						int num3 = r.ReadInt32();
						Material val4 = new Material(val)
						{
							name = $"NaiLong.{i}"
						};
						owned.Add((Object)(object)val4);
						array[i] = val4;
						val4.mainTexture = (Texture)(object)val2;
						val4.color = color;
						val4.SetFloat("_Glossiness", 0.12f);
						val4.SetFloat("_Metallic", 0f);
						if (num3 == 1)
						{
							val4.SetFloat("_Mode", 1f);
							val4.SetFloat("_Cutoff", 0.45f);
							val4.EnableKeyword("_ALPHATEST_ON");
							val4.SetOverrideTag("RenderType", "TransparentCutout");
							val4.renderQueue = 2450;
						}
						if (num2 > 0f)
						{
							val4.EnableKeyword("_EMISSION");
							val4.SetTexture("_EmissionMap", (Texture)(object)(val3 ?? val2));
							val4.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)0;
							val4.SetColor("_EmissionColor", Color.white * num2);
							glow.Add(val4);
						}
					}
					int num4 = r.ReadInt32();
					if (num4 < 1 || num4 > 256)
					{
						throw new InvalidDataException("part count");
					}
					Part[] array2 = new Part[num4];
					for (int j = 0; j < num4; j++)
					{
						int num5 = r.ReadInt32();
						if (num5 < 0 || num5 >= num)
						{
							throw new InvalidDataException("material index");
						}
						int num6 = r.ReadInt32();
						if (num6 < 3 || num6 > 2000000)
						{
							throw new InvalidDataException("vertex count");
						}
						if ((long)num6 * 32L > r.BaseStream.Length - r.BaseStream.Position)
						{
							throw new EndOfStreamException();
						}
						Vector3[] array3 = (Vector3[])(object)new Vector3[num6];
						Vector3[] array4 = (Vector3[])(object)new Vector3[num6];
						Vector2[] array5 = (Vector2[])(object)new Vector2[num6];
						for (int k = 0; k < num6; k++)
						{
							array3[k] = new Vector3(F(), F(), F());
							array4[k] = new Vector3(F(), F(), F());
							array5[k] = new Vector2(F(), F());
						}
						int num7 = r.ReadInt32();
						if (num7 <= 0 || num7 % 3 != 0 || (long)num7 * 4L > r.BaseStream.Length - r.BaseStream.Position)
						{
							throw new InvalidDataException("triangle list");
						}
						int[] array6 = new int[num7];
						for (int l = 0; l < num7; l++)
						{
							int num8 = r.ReadInt32();
							if (num8 < 0 || num8 >= num6)
							{
								throw new InvalidDataException("index range");
							}
							array6[l] = num8;
						}
						Mesh val5 = new Mesh
						{
							name = "NaiLong.part." + j
						};
						owned.Add((Object)(object)val5);
						if (num6 > 65535)
						{
							val5.indexFormat = (IndexFormat)1;
						}
						val5.vertices = Il2CppStructArray<Vector3>.op_Implicit(array3);
						val5.normals = Il2CppStructArray<Vector3>.op_Implicit(array4);
						val5.uv = Il2CppStructArray<Vector2>.op_Implicit(array5);
						val5.triangles = Il2CppStructArray<int>.op_Implicit(array6);
						val5.RecalculateBounds();
						array2[j] = new Part(val5, array[num5]);
					}
					if (r.BaseStream.Position != r.BaseStream.Length)
					{
						throw new InvalidDataException("trailing data");
					}
					foreach (Object item in owned)
					{
						item.hideFlags = (HideFlags)32;
					}
					parts = array2;
					Apply();
					ManualLogSource logSource = Plugin.LogSource;
					bool flag = default(bool);
					BepInExInfoLogInterpolatedStringHandler val6 = new BepInExInfoLogInterpolatedStringHandler(50, 3, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val6).AppendLiteral("Loaded nailong.wcm: ");
						((BepInExLogInterpolatedStringHandler)val6).AppendFormatted<int>(array2.Length);
						((BepInExLogInterpolatedStringHandler)val6).AppendLiteral(" parts, ");
						((BepInExLogInterpolatedStringHandler)val6).AppendFormatted<int>(textures.Count);
						((BepInExLogInterpolatedStringHandler)val6).AppendLiteral(" textures, ");
						((BepInExLogInterpolatedStringHandler)val6).AppendFormatted<int>(glow.Count);
						((BepInExLogInterpolatedStringHandler)val6).AppendLiteral(" glow slots");
					}
					logSource.LogInfo(val6);
					return parts;
				}
				catch
				{
					foreach (Object item2 in owned)
					{
						Object.Destroy(item2);
					}
					throw;
				}
			}
			finally
			{
				if (r != null)
				{
					((IDisposable)r).Dispose();
				}
			}
			float F()
			{
				float num9 = r.ReadSingle();
				if (!float.IsFinite(num9))
				{
					throw new InvalidDataException("non-finite WCM float");
				}
				return num9;
			}
			Texture2D Texture()
			{
				//IL_007e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0085: Expected O, but got Unknown
				int num9 = r.ReadInt32();
				if (num9 < 0 || num9 > 67108864)
				{
					throw new InvalidDataException("texture length");
				}
				if (num9 == 0)
				{
					return null;
				}
				byte[] array7 = r.ReadBytes(num9);
				if (array7.Length != num9 || num9 < 24 || array7[0] != 137 || array7[1] != 80)
				{
					throw new InvalidDataException("truncated PNG");
				}
				string text2 = Convert.ToHexString(SHA256.HashData(array7));
				if (textures.TryGetValue(text2, out var value))
				{
					return value;
				}
				Texture2D val7 = new Texture2D(2, 2, (TextureFormat)4, true);
				owned.Add((Object)(object)val7);
				if (!ImageConversion.LoadImage(val7, Il2CppStructArray<byte>.op_Implicit(array7), true))
				{
					throw new InvalidDataException("Unity rejected PNG");
				}
				((Object)val7).name = "NaiLong." + text2.Substring(0, 8);
				((Texture)val7).filterMode = (FilterMode)2;
				((Texture)val7).anisoLevel = 1;
				return textures[text2] = val7;
			}
		}
	}
	public sealed class BatchVisual : MonoBehaviour
	{
		private Material[] fp;

		private bool fpSynced;

		private bool deployed;

		private Bounds artFrame;

		private Bounds stockFrame;

		private bool framesRead;

		private float liftTotal;

		private bool skipLogged;

		internal int Lifts;

		private bool savedOff;

		private bool armed;

		private bool owned;

		private bool announced;

		private int frames;

		private MeshRenderer original;

		private MeshRenderer visual;

		internal Fit.Product Product;

		private Vector3 hostPos;

		private Quaternion hostRot;

		private Vector3 hostScale;

		private readonly SlotBuffer slotBuf = new SlotBuffer();

		internal bool Armed => armed;

		internal MeshRenderer Host => original;

		public BatchVisual(IntPtr p)
			: base(p)
		{
		}

		internal static void Attach(Transform body, MeshRenderer source, Renderer shadowFrom, Fit.Product product, Material[] fp, bool deployedForm)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: 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_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			Transform val = body.Find("NaiLong.Visual");
			GameObject val2 = null;
			bool flag = (Object)(object)val == (Object)null;
			try
			{
				Transform val3 = val;
				if (flag)
				{
					val2 = new GameObject("NaiLong.Visual");
					val2.SetActive(false);
					val3 = val2.transform;
					val3.SetParent(body, false);
					val2.AddComponent<MeshFilter>();
					val2.AddComponent<MeshRenderer>();
					val2.AddComponent<BatchVisual>();
				}
				else if ((Object)(object)((Component)val3).GetComponent<BatchVisual>() == (Object)null)
				{
					throw new InvalidOperationException("foreign child shares the skin name");
				}
				BatchVisual batchVisual = ((Component)val3).GetComponent<BatchVisual>() ?? throw new InvalidOperationException("skin child has no marker");
				MeshFilter val4 = ((Component)val3).GetComponent<MeshFilter>() ?? throw new InvalidOperationException("skin child has no MeshFilter");
				MeshRenderer val5 = ((Component)val3).GetComponent<MeshRenderer>() ?? throw new InvalidOperationException("skin child has no MeshRenderer");
				Material[] array = fp ?? product.Materials;
				if ((Object)(object)val4.sharedMesh != (Object)(object)product.Mesh || !SameMaterials(Il2CppArrayBase<Material>.op_Implicit((Il2CppArrayBase<Material>)(object)((Renderer)val5).sharedMaterials), array))
				{
					((Renderer)val5).sharedMaterials = Il2CppReferenceArray<Material>.op_Implicit(array);
					val4.sharedMesh = product.Mesh;
				}
				if ((Object)(object)val4.sharedMesh != (Object)(object)product.Mesh || ((Il2CppArrayBase<Material>)(object)((Renderer)val5).sharedMaterials).Length != array.Length)
				{
					throw new InvalidOperationException("skin child incomplete");
				}
				Material[] array2 = batchVisual.fp;
				batchVisual.fp = fp;
				if (array2 != null && array2 != fp)
				{
					FpGearMaterial.Release(array2);
				}
				bool num = batchVisual.Product == null || (Object)(object)batchVisual.Product.Mesh != (Object)(object)product.Mesh || (Object)(object)batchVisual.original != (Object)(object)source;
				batchVisual.Product = product;
				batchVisual.deployed = deployedForm;
				if (num)
				{
					batchVisual.framesRead = false;
					batchVisual.liftTotal = 0f;
					((Component)val5).transform.localPosition = Vector3.zero;
				}
				if (flag)
				{
					batchVisual.original = source;
					batchVisual.deployed = deployedForm;
					batchVisual.Product = product;
					batchVisual.visual = val5;
					batchVisual.savedOff = ((Renderer)source).forceRenderingOff;
					batchVisual.MirrorStock(source, shadowFrom, val5);
					batchVisual.armed = true;
					batchVisual.Follow();
					val2.SetActive(true);
					batchVisual.hostPos = ((Component)source).transform.localPosition;
					batchVisual.hostRot = ((Component)source).transform.localRotation;
					batchVisual.hostScale = ((Component)source).transform.localScale;
				}
				else
				{
					if ((Object)(object)batchVisual.original != (Object)(object)source)
					{
						batchVisual.Release();
						batchVisual.original = source;
						batchVisual.savedOff = ((Renderer)source).forceRenderingOff;
						batchVisual.MirrorStock(source, shadowFrom, val5);
						batchVisual.hostPos = ((Component)source).transform.localPosition;
						batchVisual.hostRot = ((Component)source).transform.localRotation;
						batchVisual.hostScale = ((Component)source).transform.localScale;
					}
					batchVisual.armed = true;
					batchVisual.visual = val5;
					batchVisual.Follow();
				}
				batchVisual.Own();
			}
			catch
			{
				if ((Object)(object)val2 != (Object)null)
				{
					Object.Destroy((Object)(object)val2);
				}
				throw;
			}
		}

		private void MirrorStock(MeshRenderer source, Renderer shadowFrom, MeshRenderer self)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			((Renderer)self).shadowCastingMode = (ShadowCastingMode)((!((Object)(object)shadowFrom == (Object)null)) ? ((int)shadowFrom.shadowCastingMode) : 0);
			((Renderer)self).receiveShadows = ((Renderer)source).receiveShadows;
		}

		private static bool SameMaterials(Material[] actual, Material[] expected)
		{
			if (actual == null || expected == null || actual.Length != expected.Length)
			{
				return false;
			}
			for (int i = 0; i < expected.Length; i++)
			{
				if ((Object)(object)actual[i] != (Object)(object)expected[i])
				{
					return false;
				}
			}
			return true;
		}

		private void ReleaseFp()
		{
			if (fp != null)
			{
				Material[] made = fp;
				fp = null;
				fpSynced = false;
				FpGearMaterial.Release(made);
			}
		}

		private void LateUpdate()
		{
			//IL_00a6: 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_00b1: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Expected O, but got Unknown
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			if (!armed)
			{
				return;
			}
			Follow();
			Own();
			if (fp != null && (Object)(object)original != (Object)null && (Object)(object)visual != (Object)null)
			{
				SyncProjection();
			}
			if (deployed)
			{
				VerifyPlacement();
			}
			if (announced || ++frames < 90)
			{
				return;
			}
			announced = true;
			if ((Object)(object)original != (Object)null && (Object)(object)visual != (Object)null)
			{
				Transform transform = ((Component)original).transform;
				Vector3 val = transform.localPosition - hostPos;
				float num = ((Vector3)(ref val)).magnitude + Quaternion.Angle(transform.localRotation, hostRot) / 1000f;
				val = transform.localScale - hostScale;
				float num2 = num + ((Vector3)(ref val)).magnitude;
				ManualLogSource logSource = Plugin.LogSource;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(118, 8, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("SKIN_PLACE host=");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((Object)original).name);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" hostEnabled=");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<bool>(((Renderer)original).enabled);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" ");
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("hostWorld=");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(Describe((Renderer)(object)original));
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" artEnabled=");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<bool>(((Renderer)visual).enabled);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" artWorld=");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(Describe((Renderer)(object)visual));
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" ");
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("follow=childOfHost hostLocalDrift=");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<float>(num2, "F5");
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" artLocal=");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(Fit.V(((Component)visual).transform.localPosition));
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" ");
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("artParent=");
					Transform parent = ((Component)visual).transform.parent;
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>((parent != null) ? ((Object)parent).name : null);
				}
				logSource.LogInfo(val2);
			}
		}

		internal void VerifyPlacement()
		{
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: 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_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: 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_027f: 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_0363: Unknown result type (might be due to invalid IL or missing references)
			//IL_0374: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_039b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a2: Expected O, but got Unknown
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0433: Unknown result type (might be due to invalid IL or missing references)
			//IL_0450: Unknown result type (might be due to invalid IL or missing references)
			//IL_046a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0499: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Expected O, but got Unknown
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: 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_0110: 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_0136: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)original == (Object)null || (Object)(object)visual == (Object)null || !((Renderer)visual).enabled || !((Renderer)original).enabled)
			{
				return;
			}
			Mesh val = ((Product != null) ? Product.Mesh : null);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			if (!framesRead)
			{
				if (Product == null)
				{
					return;
				}
				Matrix4x4 bake = Product.Bake;
				if (!(Mathf.Abs(bake.m00 - 1f) <= 0.001f) || !(Mathf.Abs(bake.m11 - 1f) <= 0.001f) || !(Mathf.Abs(bake.m22 - 1f) <= 0.001f) || !(Mathf.Abs(bake.m01) <= 0.001f) || !(Mathf.Abs(bake.m02) <= 0.001f) || !(Mathf.Abs(bake.m10) <= 0.001f) || !(Mathf.Abs(bake.m12) <= 0.001f) || !(Mathf.Abs(bake.m20) <= 0.001f) || !(Mathf.Abs(bake.m21) <= 0.001f))
				{
					framesRead = true;
					skipLogged = true;
					Plugin.LogSource.LogInfo((object)("SKIN_GROUND_SKIP host=" + (((Object)(object)original != (Object)null) ? ((Object)original).name : "?") + " reason=rotated-bake (the axis-minimum comparison is only proven for an identity bake)"));
					return;
				}
				Vector3[] array = Support.Vertices(val);
				if (array == null || array.Length == 0)
				{
					return;
				}
				stockFrame = Fit.Box(bake, Product.Stock);
				artFrame = VertexBox(array);
				framesRead = true;
			}
			if (skipLogged)
			{
				return;
			}
			Transform transform = ((Component)visual).transform;
			if (Quaternion.Angle(transform.localRotation, Quaternion.identity) > 0.01f)
			{
				return;
			}
			Vector3 val2 = transform.localScale - Vector3.one;
			if (((Vector3)(ref val2)).magnitude > 0.0001f)
			{
				return;
			}
			Bounds b = default(Bounds);
			((Bounds)(ref b))..ctor(((Bounds)(ref artFrame)).center + transform.localPosition, ((Bounds)(ref artFrame)).size);
			float num = ((Bounds)(ref b)).min.y - ((Bounds)(ref stockFrame)).min.y;
			if (Mathf.Abs(num) <= 0.002f)
			{
				return;
			}
			float num2 = Mathf.Max(0.05f, ((Bounds)(ref b)).size.y);
			float num3 = Mathf.Clamp(0f - num, 0f - num2, num2);
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val3;
			if (Mathf.Abs(liftTotal + num3) > 0.25f)
			{
				if (!skipLogged)
				{
					skipLogged = true;
					ManualLogSource logSource = Plugin.LogSource;
					val3 = new BepInExInfoLogInterpolatedStringHandler(83, 3, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("SKIN_GROUND_REFUSE host=");
						((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(((Object)original).name);
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" sink=");
						((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<float>(num, "F4");
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" ");
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("applied=");
						((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<float>(liftTotal, "F4");
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" reason=correction-budget (0.25 m) exhausted");
					}
					logSource.LogInfo(val3);
				}
				return;
			}
			liftTotal += num3;
			transform.localPosition += new Vector3(0f, num3, 0f);
			Lifts++;
			ManualLogSource logSource2 = Plugin.LogSource;
			val3 = new BepInExInfoLogInterpolatedStringHandler(78, 8, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("SKIN_GROUND host=");
				((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(((Object)original).name);
				((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" sink=");
				((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<float>(num, "F4");
				((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" lift=");
				((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<float>(num3, "F4");
				((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" total=");
				((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<float>(liftTotal, "F4");
				((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" ");
				((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("artLocal=");
				((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(Fit.V(transform.localPosition));
				((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" art=");
				((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(Fit.D(b));
				((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" stock=");
				((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(Fit.D(stockFrame));
				((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" frame=host ");
				((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("support=");
				((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(Fit.D(Product.Stock));
			}
			logSource2.LogInfo(val3);
		}

		private static Bounds VertexBox(Vector3[] verts)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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)
			Bounds result = default(Bounds);
			((Bounds)(ref result))..ctor(verts[0], Vector3.zero);
			for (int i = 1; i < verts.Length; i++)
			{
				((Bounds)(ref result)).Encapsulate(verts[i]);
			}
			return result;
		}

		private void SyncProjection()
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			Material[] array = slotBuf.Read(visual);
			int num = ((array != null) ? FpGearMaterial.SyncProjection(((Renderer)original).sharedMaterial, array) : 0);
			Targets.Stats.FpSyncs++;
			Targets.Stats.FpFixes += num;
			if (num != 0 && !fpSynced)
			{
				fpSynced = true;
				ManualLogSource logSource = Plugin.LogSource;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(44, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("SKIN_FP projection corrected=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("native=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(((Renderer)original).sharedMaterial.IsKeywordEnabled("ENABLE_FPS_RENDERING"));
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" slots=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>((array != null) ? array.Length : 0);
				}
				logSource.LogInfo(val);
			}
		}

		private static string Describe(Renderer r)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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)
			Bounds bounds = r.bounds;
			return "size=" + Fit.V(((Bounds)(ref bounds)).size) + " center=" + Fit.V(((Bounds)(ref bounds)).center);
		}

		private void Own()
		{
			if (!((Object)(object)original == (Object)null))
			{
				if (!((Renderer)original).forceRenderingOff)
				{
					((Renderer)original).forceRenderingOff = true;
				}
				owned = true;
			}
		}

		private void Release()
		{
			if (owned)
			{
				owned = false;
				if ((Object)(object)original != (Object)null)
				{
					((Renderer)original).forceRenderingOff = savedOff;
				}
			}
		}

		internal void KeepNative()
		{
			armed = false;
			if ((Object)(object)visual != (Object)null)
			{
				((Renderer)visual).enabled = false;
			}
			ReleaseFp();
			Release();
		}

		private void Follow()
		{
			if ((Object)(object)visual == (Object)null)
			{
				return;
			}
			if ((Object)(object)original == (Object)null)
			{
				bool activeInHierarchy = ((Component)this).gameObject.activeInHierarchy;
				if (((Renderer)visual).enabled != activeInHierarchy)
				{
					((Renderer)visual).enabled = activeInHierarchy;
				}
				return;
			}
			bool flag = ((Renderer)original).enabled && ((Component)original).gameObject.activeInHierarchy;
			if (((Renderer)visual).enabled != flag)
			{
				((Renderer)visual).enabled = flag;
			}
			int layer = ((Component)original).gameObject.layer;
			if (((Component)this).gameObject.layer != layer)
			{
				((Component)this).gameObject.layer = layer;
			}
		}

		private void OnDestroy()
		{
			Release();
			ReleaseFp();
		}
	}
	internal sealed class SlotBuffer
	{
		private readonly List<Material> read = new List<Material>();

		private Material[] slots;

		internal Material[] Read(MeshRenderer r)
		{
			if ((Object)(object)r == (Object)null)
			{
				return null;
			}
			try
			{
				read.Clear();
				((Renderer)r).GetSharedMaterials(read);
				int count = read.Count;
				if (count <= 0)
				{
					return null;
				}
				if (slots == null || slots.Length != count)
				{
					slots = (Material[])(object)new Material[count];
				}
				for (int i = 0; i < count; i++)
				{
					slots[i] = read[i];
				}
				return slots;
			}
			catch
			{
				return null;
			}
		}
	}
	internal static class Fit
	{
		internal sealed record Product(Mesh Mesh, Material[] Materials, Bounds Stock, Bounds Fitted, Vector3 Scale, Vector3 Shift, float ContactPlane, float ContactLateral, float Contact3D, string Used, bool Measured, string CacheKey, Matrix4x4 Bake);

		internal readonly struct Stock
		{
			internal readonly Bounds Box;

			internal readonly bool Measured;

			internal readonly int Scanned;

			internal readonly int Meshes;

			internal Stock(Bounds box, bool measured, int scanned, int meshes)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				Box = box;
				Measured = measured;
				Scanned = scanned;
				Meshes = meshes;
			}

			internal Stock(Support.Cloud cloud)
			{
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				Box = (Bounds)(((??)cloud?.Box) ?? default(Bounds));
				Measured = cloud?.Measured ?? false;
				Scanned = cloud?.Scanned ?? 0;
				Meshes = cloud?.Meshes ?? 0;
			}
		}

		internal enum Sizing
		{
			Footprint,
			Height,
			Stretch,
			Proportional,
			Capped
		}

		private static readonly Dictionary<string, Product> cache = new Dictionary<string, Product>();

		private static readonly HashSet<string> collided = new HashSet<string>();

		private static Vector3 artSource;

		private const int CacheLimit = 64;

		internal static Sizing Mode = Sizing.Footprint;

		private const float MaxHeightOverflow = 2.2f;

		private const float MaxAnisotropy = 2.6f;

		private const float MaxContactPush = 0.05f;

		private const float MaxContactLateral = 0.01f;

		private const float NearestTarget = 0.006f;

		internal static int CachedCount => cache.Count;

		internal static Sizing For(string visualName)
		{
			string text = visualName ?? "";
			if (text.EndsWith("(Clone)", StringComparison.Ordinal))
			{
				string text2 = text;
				text = text2.Substring(0, text2.Length - 7).TrimEnd();
			}
			if (text.EndsWith("_Pickup", StringComparison.Ordinal))
			{
				return Sizing.Height;
			}
			if (text == "Consumable_FogRepeller")
			{
				return Sizing.Proportional;
			}
			if (text == "Consumable_FogRepeller_Activated")
			{
				return Sizing.Capped;
			}
			return Mode;
		}

		internal static void Require(bool ok, string why)
		{
			if (!ok)
			{
				throw new InvalidOperationException(why);
			}
		}

		internal static string V(Vector3 v)
		{
			//IL_000d: 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_0029: Unknown result type (might be due to invalid IL or missing references)
			return FormattableString.Invariant($"({v.x:F4},{v.y:F4},{v.z:F4})");
		}

		internal static string D(Bounds b)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			return "size=" + V(((Bounds)(ref b)).size) + " center=" + V(((Bounds)(ref b)).center);
		}

		internal static Matrix4x4 Relative(Transform ancestor, Transform child)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			Matrix4x4 val = Matrix4x4.identity;
			while ((Object)(object)child != (Object)(object)ancestor)
			{
				Require((Object)(object)child != (Object)null, "frame is not an ancestor");
				val = Matrix4x4.TRS(child.localPosition, child.localRotation, child.localScale) * val;
				child = child.parent;
			}
			return val;
		}

		internal static Bounds Box(Matrix4x4 m, Bounds b)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_007b: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			Vector3 center = ((Bounds)(ref b)).center;
			Vector3 extents = ((Bounds)(ref b)).extents;
			Bounds result = default(Bounds);
			((Bounds)(ref result))..ctor(((Matrix4x4)(ref m)).MultiplyPoint3x4(center), Vector3.zero);
			for (int i = 0; i < 8; i++)
			{
				Vector3 val = ((Matrix4x4)(ref m)).MultiplyPoint3x4(center + new Vector3(((i & 1) == 0) ? (0f - extents.x) : extents.x, ((i & 2) == 0) ? (0f - extents.y) : extents.y, ((i & 4) == 0) ? (0f - extents.z) : extents.z));
				Require(float.IsFinite(val.x) && float.IsFinite(val.y) && float.IsFinite(val.z), "non-finite bound");
				((Bounds)(ref result)).Encapsulate(val);
			}
			return result;
		}

		internal static Vector3 ScaleOf(Mesh mesh)
		{
			//IL_003c: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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_0073: 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)
			if ((Object)(object)mesh == (Object)null || artSource.x <= 0f || artSource.y <= 0f || artSource.z <= 0f)
			{
				return Vector3.zero;
			}
			Bounds val = VertexBox(mesh);
			Vector3 size = ((Bounds)(ref val)).size;
			return new Vector3(size.x / artSource.x, size.y / artSource.y, size.z / artSource.z);
		}

		internal static bool IsCached(Mesh mesh)
		{
			if ((Object)(object)mesh == (Object)null)
			{
				return false;
			}
			foreach (KeyValuePair<string, Product> item in cache)
			{
				if (item.Value != null && (Object)(object)item.Value.Mesh == (Object)(object)mesh)
				{
					return true;
				}
			}
			return false;
		}

		internal static string Key(string tag, Sizing mode, float fill, Bounds stock, bool measured, Matrix4x4 bake, bool contact, Vector3 anchor, int artVertices)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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_0091: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: 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_00f8: 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_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			Vector4 column = ((Matrix4x4)(ref bake)).GetColumn(3);
			string value = string.Format(CultureInfo.InvariantCulture, "{0:F2},{1:F2},{2:F2},{3:F2},{4:F2},{5:F2},{6:F2},{7:F2},{8:F2},{9:F2},{10:F2},{11:F2}", S(column.x), S(column.y), S(column.z), S(bake.m00), S(bake.m01), S(bake.m02), S(bake.m10), S(bake.m11), S(bake.m12), S(bake.m20), S(bake.m21), S(bake.m22));
			return $"{tag}|{mode}|{S(fill):F2}|{(measured ? "v" : "c")}|{artVertices}|{Q(stock)}|bake({value})|" + (contact ? ("c" + V(S(anchor))) : "nc");
		}

		private static float S(float v)
		{
			if (v != 0f)
			{
				return v;
			}
			return 0f;
		}

		private static Vector3 S(Vector3 v)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(S(v.x), S(v.y), S(v.z));
		}

		private static string Q(Bounds b)
		{
			//IL_000f: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: 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)
			return FormattableString.Invariant($"size=({S(((Bounds)(ref b)).size.x):F2},{S(((Bounds)(ref b)).size.y):F2},{S(((Bounds)(ref b)).size.z):F2}) center=({S(((Bounds)(ref b)).center.x):F2},{S(((Bounds)(ref b)).center.y):F2},{S(((Bounds)(ref b)).center.z):F2})");
		}

		private static float MaxDiff(Matrix4x4 a, Matrix4x4 b)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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_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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			return Mathf.Max(Mathf.Max(Mathf.Max(Mathf.Max(Mathf.Max(Mathf.Max(Mathf.Max(Mathf.Max(Mathf.Abs(a.m00 - b.m00), Mathf.Abs(a.m01 - b.m01)), Mathf.Abs(a.m02 - b.m02)), Mathf.Abs(a.m10 - b.m10)), Mathf.Abs(a.m11 - b.m11)), Mathf.Abs(a.m12 - b.m12)), Mathf.Abs(a.m20 - b.m20)), Mathf.Abs(a.m21 - b.m21)), Mathf.Abs(a.m22 - b.m22));
		}

		private static bool SameBake(Matrix4x4 a, Matrix4x4 b)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			Vector4 val = ((Matrix4x4)(ref a)).GetColumn(3) - ((Matrix4x4)(ref b)).GetColumn(3);
			if (((Vector4)(ref val)).magnitude <= 0.002f)
			{
				return MaxDiff(a, b) <= 0.002f;
			}
			return false;
		}

		private static void Collide(string tag, Matrix4x4 was, Matrix4x4 now)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			Targets.Stats.Collisions++;
			if (collided.Add(tag))
			{
				ManualLogSource logSource = Plugin.LogSource;
				object[] obj = new object[3] { tag, null, null };
				Vector4 val = ((Matrix4x4)(ref was)).GetColumn(3) - ((Matrix4x4)(ref now)).GetColumn(3);
				obj[1] = ((Vector4)(ref val)).magnitude;
				obj[2] = MaxDiff(was, now);
				logSource.LogInfo((object)FormattableString.Invariant(FormattableStringFactory.Create("FIT_COLLIDE tag={0} dt={1:F4} dm={2:F4}", obj)));
			}
		}

		internal static Bounds SupportBox(Stock stock, StockCalibration.Entry calib, out bool measured)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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_0015: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			measured = stock.Measured;
			Bounds result = (Bounds)(stock.Measured ? stock.Box : (((??)calib?.Box) ?? default(Bounds)));
			Require(((Bounds)(ref result)).size.x > 0f && ((Bounds)(ref result)).size.y > 0f && ((Bounds)(ref result)).size.z > 0f, "no readable stock vertex and no original calibration; keeping the stock art");
			return result;
		}

		internal static Bounds SupportBox(Support.Cloud stock, StockCalibration.Entry calib, out bool measured)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			Require(stock != null, "no stock geometry");
			return SupportBox(new Stock(stock), calib, out measured);
		}

		internal static Product Build(Support.Cloud stock, StockCalibration.Entry calib, Assets.Part[] parts, string tag, Sizing mode, Matrix4x4 bake, float fill = 0.95f)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			Require(stock != null, "no stock geometry");
			return Build(new Stock(stock), calib, parts, tag, mode, bake, fill);
		}

		internal static Product Build(Stock stock, StockCalibration.Entry calib, Assets.Part[] parts, string tag, Sizing mode, Matrix4x4 bake, float fill = 0.95f)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_00b9: Expected O, but got Unknown
			//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_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Expected O, but got Unknown
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: 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_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_0536: Unknown result type (might be due to invalid IL or missing references)
			//IL_0538: Unknown result type (might be due to invalid IL or missing references)
			//IL_053d: Unknown result type (might be due to invalid IL or missing references)
			//IL_053f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0544: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_055b: 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_057d: Unknown result type (might be due to invalid IL or missing references)
			//IL_057f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0588: Unknown result type (might be due to invalid IL or missing references)
			//IL_058d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0597: Unknown result type (might be due to invalid IL or missing references)
			//IL_0599: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ab: 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_05da: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e3: Expected O, but got Unknown
			//IL_0472: Unknown result type (might be due to invalid IL or missing references)
			//IL_0465: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: 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_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ee: 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_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_030e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			//IL_031a: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_031e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0320: Unknown result type (might be due to invalid IL or missing references)
			//IL_0327: Unknown result type (might be due to invalid IL or missing references)
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0331: Unknown result type (might be due to invalid IL or missing references)
			//IL_0477: Unknown result type (might be due to invalid IL or missing references)
			//IL_0343: Unknown result type (might be due to invalid IL or missing references)
			//IL_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0352: Unknown result type (might be due to invalid IL or missing references)
			//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_04ad: 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_047e: Unknown result type (might be due to invalid IL or missing references)
			//IL_048a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0496: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0402: Unknown result type (might be due to invalid IL or missing references)
			//IL_0404: 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_0408: 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_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_0426: Unknown result type (might be due to invalid IL or missing references)
			//IL_0428: Unknown result type (might be due to invalid IL or missing references)
			//IL_042b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0367: Unknown result type (might be due to invalid IL or missing references)
			//IL_0369: Unknown result type (might be due to invalid IL or missing references)
			//IL_036b: Unknown result type (might be due to invalid IL or missing references)
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0372: 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_066e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0670: 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_0679: Unknown result type (might be due to invalid IL or missing references)
			//IL_0685: 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_04b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_037a: Unknown result type (might be due to invalid IL or missing references)
			//IL_037c: Unknown result type (might be due to invalid IL or missing references)
			//IL_037e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: Unknown result type (might be due to invalid IL or missing references)
			//IL_0699: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0702: Unknown result type (might be due to invalid IL or missing references)
			//IL_0729: Unknown result type (might be due to invalid IL or missing references)
			//IL_072e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0737: Unknown result type (might be due to invalid IL or missing references)
			//IL_0738: Unknown result type (might be due to invalid IL or missing references)
			//IL_073a: Unknown result type (might be due to invalid IL or missing references)
			//IL_073c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0748: 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_04cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04db: 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_04df: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f2: 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_04fb: 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_03b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_078b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0792: Expected O, but got Unknown
			//IL_0501: Unknown result type (might be due to invalid IL or missing references)
			//IL_0503: Unknown result type (might be due to invalid IL or missing references)
			//IL_0505: Unknown result type (might be due to invalid IL or missing references)
			//IL_0507: Unknown result type (might be due to invalid IL or missing references)
			//IL_050c: 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_0525: Unknown result type (might be due to invalid IL or missing references)
			//IL_0527: Unknown result type (might be due to invalid IL or missing references)
			//IL_052a: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_07e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_080f: Unknown result type (might be due to invalid IL or missing references)
			//IL_082b: Unknown result type (might be due to invalid IL or missing references)
			//IL_084f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0939: Unknown result type (might be due to invalid IL or missing references)
			//IL_0945: Unknown result type (might be due to invalid IL or missing references)
			bool measured;
			Bounds val = SupportBox(stock, calib, out measured);
			Vector3 anchor = ((calib != null && calib.HasContact) ? calib.ContactPoint : Vector3.zero);
			string text = Key(tag, mode, fill, val, measured, bake, calib?.HasContact ?? false, anchor, Parts_Count(parts));
			bool flag = false;
			if (cache.TryGetValue(text, out var value) && value != null && (Object)(object)value.Mesh != (Object)null)
			{
				if (SameBake(value.Bake, bake))
				{
					Targets.Stats.Hits++;
					return value;
				}
				Collide(tag, value.Bake, bake);
				flag = true;
			}
			Targets.Stats.Builds++;
			GameObject val2 = new GameObject("NaiLong.staging");
			List<GameObject> list = new List<GameObject>();
			Mesh val3 = null;
			Mesh val4 = null;
			try
			{
				val2.SetActive(false);
				Support.Part[] array = new Support.Part[parts.Length];
				Matrix4x4[] array2 = (Matrix4x4[])(object)new Matrix4x4[parts.Length];
				for (int i = 0; i < parts.Length; i++)
				{
					GameObject val5 = new GameObject("part" + i);
					val5.transform.SetParent(val2.transform, false);
					val5.AddComponent<MeshFilter>().sharedMesh = parts[i].Mesh;
					((Renderer)val5.AddComponent<MeshRenderer>()).sharedMaterial = parts[i].Material;
					list.Add(val5);
					array[i] = new Support.Part(val5.transform, parts[i].Mesh);
					array2[i] = Relative(val2.transform, val5.transform);
				}
				Support.Cloud cloud = Support.Gather(val2.transform, array);
				Require(cloud.Measured, "art mesh has no readable vertex to measure");
				Bounds box = cloud.Box;
				string used;
				bool capped;
				Vector3 val6 = Size(val, box, mode, fill, out used, out capped);
				Vector3 val7 = default(Vector3);
				((Vector3)(ref val7))..ctor(((Bounds)(ref val)).center.x - ((Bounds)(ref box)).center.x * val6.x, ((Bounds)(ref val)).min.y - ((Bounds)(ref box)).min.y * val6.y, ((Bounds)(ref val)).center.z - ((Bounds)(ref box)).center.z * val6.z);
				float num = 0f;
				float num2 = 0f;
				float num3 = 0f;
				if (calib != null && calib.HasContact && cloud.Points.Count > 0)
				{
					Vector3 normalized = ((Vector3)(ref calib.ContactNormal)).normalized;
					float num4 = 0f;
					float num5 = float.MaxValue;
					for (int j = 0; j <= 50; j++)
					{
						float num6 = NearestTo(cloud, val6, val7 + normalized * ((float)j / 1000f), calib.ContactPoint);
						if (num6 < num5 - 1E-05f)
						{
							num5 = num6;
							num4 = (float)j / 1000f;
						}
						else if (num6 > num5 + 0.0005f)
						{
							break;
						}
					}
					val7 += normalized * num4;
					Vector3 val8 = calib.ContactPoint - ContactPoint(cloud, val6, val7, normalized);
					val8 -= normalized * Vector3.Dot(val8, normalized);
					if (((Vector3)(ref val8)).magnitude > 0.01f)
					{
						val8 = ((Vector3)(ref val8)).normalized * 0.01f;
					}
					if (((Vector3)(ref val8)).magnitude > 1E-05f)
					{
						if (Fits(cloud, val6, val7 + val8, val))
						{
							val7 += val8;
							num2 = ((Vector3)(ref val8)).magnitude;
						}
						else
						{
							float num7 = 0f;
							float num8 = 1f;
							for (int k = 0; k < 12; k++)
							{
								float num9 = (num7 + num8) * 0.5f;
								if (Fits(cloud, val6, val7 + val8 * num9, val))
								{
									num7 = num9;
								}
								else
								{
									num8 = num9;
								}
							}
							val7 += val8 * num7;
							num2 = ((Vector3)(ref val8)).magnitude * num7;
						}
					}
					num = Vector3.Dot(ContactPoint(cloud, val6, val7, normalized), normalized) - Vector3.Dot(calib.ContactPoint, normalized);
					num3 = NearestTo(cloud, val6, val7, calib.ContactPoint);
				}
				float num10 = 1f;
				int num11;
				Vector3 val9;
				if (capped)
				{
					if (calib != null && calib.HasContact)
					{
						num11 = ((cloud.Points.Count > 0) ? 1 : 0);
						if (num11 != 0)
						{
							val9 = ((Vector3)(ref calib.ContactNormal)).normalized;
							goto IL_0477;
						}
					}
					else
					{
						num11 = 0;
					}
					val9 = Vector3.up;
					goto IL_0477;
				}
				goto IL_0536;
				IL_0536:
				Matrix4x4 val10 = Matrix4x4.TRS(val7, Quaternion.identity, val6);
				CombineInstance[] array3 = (CombineInstance[])(object)new CombineInstance[parts.Length];
				for (int l = 0; l < parts.Length; l++)
				{
					int num12 = l;
					CombineInstance val11 = default(CombineInstance);
					((CombineInstance)(ref val11)).mesh = parts[l].Mesh;
					((CombineInstance)(ref val11)).subMeshIndex = 0;
					((CombineInstance)(ref val11)).transform = bake * val10 * array2[l];
					array3[num12] = val11;
				}
				val4 = new Mesh
				{
					name = "NaiLong.fitted." + Math.Abs(text.GetHashCode() % 100000),
					indexFormat = (IndexFormat)1
				};
				val4.CombineMeshes(Il2CppStructArray<CombineInstance>.op_Implicit(array3), false, true, false);
				val4.RecalculateBounds();
				Require(val4.vertexCount >= 3 && val4.subMeshCount == parts.Length, "incomplete art combine");
				Material[] array4 = (Material[])(object)new Material[parts.Length];
				for (int m = 0; m < parts.Length; m++)
				{
					Require(val4.GetIndexCount(m) != 0, "empty submesh " + m);
					array4[m] = parts[m].Material;
				}
				Bounds val12 = Placed(cloud, val6, val7);
				Require(((Bounds)(ref val12)).size.x <= ((Bounds)(ref val)).size.x + 0.001f && ((Bounds)(ref val12)).size.z <= ((Bounds)(ref val)).size.z + 0.001f, "art exceeds stock footprint");
				Require(((Bounds)(ref val12)).min.y >= ((Bounds)(ref val)).min.y - 0.001f, "art sinks below the stock support");
				Require(((Bounds)(ref val12)).size.y <= ((Bounds)(ref val)).size.y * 2.2f + 0.001f, "art far taller than stock");
				artSource = ((Bounds)(ref box)).size;
				Product product = new Product(val4, array4, val, val12, val6, val7, num, num2, num3, used, measured, text, bake);
				val3 = val4;
				val4 = null;
				if (!flag && cache.Count < 64)
				{
					cache[text] = product;
					((Object)val3).hideFlags = (HideFlags)32;
				}
				ManualLogSource logSource = Plugin.LogSource;
				bool flag2 = default(bool);
				BepInExInfoLogInterpolatedStringHandler val13 = new BepInExInfoLogInterpolatedStringHandler(121, 16, ref flag2);
				if (flag2)
				{
					((BepInExLogInterpolatedStringHandler)val13).AppendLiteral("FIT ");
					((BepInExLogInterpolatedStringHandler)val13).AppendFormatted<string>(tag);
					((BepInExLogInterpolatedStringHandler)val13).AppendLiteral(" mode=");
					((BepInExLogInterpolatedStringHandler)val13).AppendFormatted<string>(used);
					((BepInExLogInterpolatedStringHandler)val13).AppendLiteral(" support=");
					((BepInExLogInterpolatedStringHandler)val13).AppendFormatted<string>(D(val));
					((BepInExLogInterpolatedStringHandler)val13).AppendLiteral(" art=");
					((BepInExLogInterpolatedStringHandler)val13).AppendFormatted<string>(D(val12));
					((BepInExLogInterpolatedStringHandler)val13).AppendLiteral(" ");
					((BepInExLogInterpolatedStringHandler)val13).AppendLiteral("scale=");
					((BepInExLogInterpolatedStringHandler)val13).AppendFormatted<string>(V(val6));
					((BepInExLogInterpolatedStringHandler)val13).AppendLiteral(" supportY[stock=");
					((BepInExLogInterpolatedStringHandler)val13).AppendFormatted<float>(((Bounds)(ref val)).min.y, "F4");
					((BepInExLogInterpolatedStringHandler)val13).AppendLiteral(" art=");
					((BepInExLogInterpolatedStringHandler)val13).AppendFormatted<float>(((Bounds)(ref val12)).min.y, "F4");
					((BepInExLogInterpolatedStringHandler)val13).AppendLiteral("] ");
					((BepInExLogInterpolatedStringHandler)val13).AppendLiteral("contact[plane=");
					((BepInExLogInterpolatedStringHandler)val13).AppendFormatted<float>(num, "F4");
					((BepInExLogInterpolatedStringHandler)val13).AppendLiteral(" lateral=");
					((BepInExLogInterpolatedStringHandler)val13).AppendFormatted<float>(num2, "F4");
					((BepInExLogInterpolatedStringHandler)val13).AppendLiteral(" 3d=");
					((BepInExLogInterpolatedStringHandler)val13).AppendFormatted<float>(num3, "F4");
					((BepInExLogInterpolatedStringHandler)val13).AppendLiteral("] measured=");
					((BepInExLogInterpolatedStringHandler)val13).AppendFormatted<bool>(measured);
					((BepInExLogInterpolatedStringHandler)val13).AppendLiteral(" ");
					((BepInExLogInterpolatedStringHandler)val13).AppendLiteral("vertices=");
					((BepInExLogInterpolatedStringHandler)val13).AppendFormatted<int>(stock.Scanned);
					((BepInExLogInterpolatedStringHandler)val13).AppendLiteral("/");
					((BepInExLogInterpolatedStringHandler)val13).AppendFormatted<int>(stock.Meshes);
					((BepInExLogInterpolatedStringHandler)val13).AppendLiteral(" fill=");
					((BepInExLogInterpolatedStringHandler)val13).AppendFormatted<float>(fill, "F2");
					((BepInExLogInterpolatedStringHandler)val13).AppendLiteral(" ratio=");
					((BepInExLogInterpolatedStringHandler)val13).AppendFormatted<float>(((Bounds)(ref val12)).size.y / ((Bounds)(ref val)).size.y, "F2");
					((BepInExLogInterpolatedStringHandler)val13).AppendLiteral(" cap=");
					((BepInExLogInterpolatedStringHandler)val13).AppendFormatted<float>(num10, "F4");
				}
				logSource.LogInfo(val13);
				return product;
				IL_0477:
				Vector3 val14 = val9;
				Vector3 val15 = (Vector3)((num11 != 0) ? ContactPoint(cloud, val6, val7, val14) : new Vector3(((Bounds)(ref val)).center.x, ((Bounds)(ref val)).min.y, ((Bounds)(ref val)).center.z));
				num10 = Cap(val, box, (mode == Sizing.Capped) ? 1f : fill) / Footprint(val, box, fill);
				val7 = val15 + (val7 - val15) * num10;
				val6 *= num10;
				if (num11 != 0)
				{
					num = Vector3.Dot(ContactPoint(cloud, val6, val7, val14), val14) - Vector3.Dot(calib.ContactPoint, val14);
					num3 = NearestTo(cloud, val6, val7, calib.ContactPoint);
				}
				goto IL_0536;
			}
			finally
			{
				if ((Object)(object)val4 != (Object)null)
				{
					Object.Destroy((Object)(object)val4);
				}
				if ((Object)(object)val2 != (Object)null)
				{
					Object.Destroy((Object)(object)val2);
				}
			}
		}

		internal static Product Legacy(Bounds boxUnion, Assets.Part[] parts, string tag, Sizing mode, Matrix4x4 bake, Vector3? grip, float fill = 0.95f)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_00c0: 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_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: 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_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: 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_015b: 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_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: 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_0351: 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_0358: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0374: Unknown result type (might be due to invalid IL or missing references)
			//IL_0394: Unknown result type (might be due to invalid IL or missing references)
			//IL_0396: Unknown result type (might be due to invalid IL or missing references)
			//IL_0398: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b0: 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_03c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fb: Expected O, but got Unknown
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: 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_0237: 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_043d: Unknown result type (might be due to invalid IL or missing references)
			//IL_043f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0441: 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_044b: Unknown result type (might be due to invalid IL or missing references)
			//IL_044c: Unknown result type (might be due to invalid IL or missing references)
			//IL_044e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0450: Unknown result type (might be due to invalid IL or missing references)
			//IL_0473: Unknown result type (might be due to invalid IL or missing references)
			//IL_047c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0481: Unknown result type (might be due to invalid IL or missing references)
			//IL_0492: Unknown result type (might be due to invalid IL or missing references)
			//IL_0499: Expected O, but got Unknown
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: 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_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: 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_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_033d: 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)
			//IL_0343: 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_034d: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("NaiLong.legacy");
			List<GameObject> list = new List<GameObject>();
			Mesh val2 = null;
			try
			{
				val.SetActive(false);
				Support.Part[] array = new Support.Part[parts.Length];
				Matrix4x4[] array2 = (Matrix4x4[])(object)new Matrix4x4[parts.Length];
				for (int i = 0; i < parts.Length; i++)
				{
					GameObject val3 = new GameObject("part" + i);
					val3.transform.SetParent(val.transform, false);
					val3.AddComponent<MeshFilter>().sharedMesh = parts[i].Mesh;
					((Renderer)val3.AddComponent<MeshRenderer>()).sharedMaterial = parts[i].Material;
					list.Add(val3);
					array[i] = new Support.Part(val3.transform, parts[i].Mesh);
					array2[i] = Relative(val.transform, val3.transform);
				}
				Support.Cloud cloud = Support.Gather(val.transform, array);
				Require(cloud.Measured, "legacy: art mesh unreadable");
				Bounds box = cloud.Box;
				Sizing mode2 = ((mode != Sizing.Proportional && mode != Sizing.Capped) ? mode : Sizing.Footprint);
				string used;
				Vector3 val4 = Size(boxUnion, box, mode2, fill, out used);
				Vector3 val5 = default(Vector3);
				((Vector3)(ref val5))..ctor(((Bounds)(ref boxUnion)).center.x - ((Bounds)(ref box)).center.x * val4.x, ((Bounds)(ref boxUnion)).min.y - ((Bounds)(ref box)).min.y * val4.y, ((Bounds)(ref boxUnion)).center.z - ((Bounds)(ref box)).center.z * val4.z);
				if (grip.HasValue)
				{
					Vector3 val6 = default(Vector3);
					((Vector3)(ref val6))..ctor(grip.Value.x - ((Bounds)(ref boxUnion)).center.x, 0f, grip.Value.z - ((Bounds)(ref boxUnion)).center.z);
					if (((Vector3)(ref val6)).sqrMagnitude > 1E-08f)
					{
						Vector3 val7 = ((Mathf.Abs(val6.x) >= Mathf.Abs(val6.z)) ? new Vector3(Mathf.Sign(val6.x), 0f, 0f) : new Vector3(0f, 0f, Mathf.Sign(val6.z)));
						float num = Mathf.Max((Mathf.Abs(val7.x) > 0f) ? ((Bounds)(ref boxUnion)).size.x : 0f, (Mathf.Abs(val7.z) > 0f) ? ((Bounds)(ref boxUnion)).size.z : 0f) * 0.5f;
						float num2 = float.MinValue;
						for (int j = 0; j < cloud.Points.Count; j++)
						{
							Vector3 val8 = cloud.Points[j];
							float num3 = (val8.x * val4.x + val5.x) * val7.x + (val8.z * val4.z + val5.z) * val7.z;
							if (num3 > num2)
							{
								num2 = num3;
							}
						}
						float num4 = Mathf.Clamp(Vector3.Dot(((Bounds)(ref boxUnion)).center, val7) + num - num2, 0f, 0.04f);
						if (num4 > 1E-05f)
						{
							val5 += val7 * num4;
						}
					}
				}
				Matrix4x4 val9 = Matrix4x4.TRS(val5, Quaternion.identity, val4);
				CombineInstance[] array3 = (CombineInstance[])(object)new CombineInstance[parts.Length];
				for (int k = 0; k < parts.Length; k++)
				{
					int num5 = k;
					CombineInstance val10 = default(CombineInstance);
					((CombineInstance)(ref val10)).mesh = parts[k].Mesh;
					((CombineInstance)(ref val10)).subMeshIndex = 0;
					((CombineInstance)(ref val10)).transform = bake * val9 * array2[k];
					array3[num5] = val10;
				}
				val2 = new Mesh
				{
					name = "NaiLong.legacy." + Math.Abs(tag.GetHashCode() % 100000),
					indexFormat = (IndexFormat)1
				};
				val2.CombineMeshes(Il2CppStructArray<CombineInstance>.op_Implicit(array3), false, true, false);
				val2.RecalculateBounds();
				Material[] array4 = (Material[])(object)new Material[parts.Length];
				for (int l = 0; l < parts.Length; l++)
				{
					array4[l] = parts[l].Material;
				}
				Bounds val11 = Placed(cloud, val4, val5);
				Product result = new Product(val2, array4, boxUnion, val11, val4, val5, 0f, 0f, 0f, "legacy/" + used, Measured: false, "legacy", bake);
				artSource = ((Bounds)(ref box)).size;
				val2 = null;
				ManualLogSource logSource = Plugin.LogSource;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val12 = new BepInExInfoLogInterpolatedStringHandler(32, 4, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val12).AppendLiteral("FIT_LEGACY ");
					((BepInExLogInterpolatedStringHandler)val12).AppendFormatted<string>(tag);
					((BepInExLogInterpolatedStringHandler)val12).AppendLiteral(" support=");
					((BepInExLogInterpolatedStringHandler)val12).AppendFormatted<string>(D(boxUnion));
					((BepInExLogInterpolatedStringHandler)val12).AppendLiteral(" art=");
					((BepInExLogInterpolatedStringHandler)val12).AppendFormatted<string>(D(val11));
					((BepInExLogInterpolatedStringHandler)val12).AppendLiteral(" scale=");
					((BepInExLogInterpolatedStringHandler)val12).AppendFormatted<string>(V(val4));
				}
				logSource.LogInfo(val12);
				return result;
			}
			finally
			{
				if ((Object)(object)val2 != (Object)null)
				{
					Object.Destroy((Object)(object)val2);
				}
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
			}
		}

		private static int Parts_Count(Assets.Part[] parts)
		{
			if (parts != null)
			{
				return parts.Length;
			}
			return 0;
		}

		private static float Footprint(Bounds stockBox, Bounds art, float fill)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Bounds)(ref stockBox)).size * fill;
			float num = val.x / ((Bounds)(ref art)).size.x;
			float num2 = val.z / ((Bounds)(ref art)).size.z;
			Require(float.IsFinite(num) && float.IsFinite(num2) && num > 0f && num2 > 0f, "degenerate fit scale");
			return Mathf.Min(num, num2);
		}

		private static float Cap(Bounds stockBox, Bounds art, float fill)
		{
			//IL_0002: 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)
			return ((Bounds)(ref stockBox)).size.y * fill / ((Bounds)(ref art)).size.y;
		}

		private static Vector3 Size(Bounds stockBox, Bounds art, Sizing mode, float fill, out string used)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			bool capped;
			return Size(stockBox, art, mode, fill, out used, out capped);
		}

		private static Vector3 Size(Bounds stockBox, Bounds art, Sizing mode, float fill, out string used, out bool capped)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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_0018: 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)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: 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_00b4: 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_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: 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_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Bounds)(ref stockBox)).size * fill;
			Vector3 val2 = default(Vector3);
			((Vector3)(ref val2))..ctor(val.x / ((Bounds)(ref art)).size.x, val.y / ((Bounds)(ref art)).size.y, val.z / ((Bounds)(ref art)).size.z);
			Require(float.IsFinite(val2.x) && float.IsFinite(val2.y) && float.IsFinite(val2.z), "degenerate fit scale");
			Require(val2.x > 0f && val2.y > 0f && val2.z > 0f, "degenerate fit scale");
			float num = Mathf.Min(val2.x, Mathf.Min(val2.y, val2.z));
			float num2 = Mathf.Max(val2.x, Mathf.Max(val2.y, val2.z));
			float num3 = Mathf.Min(val2.x, val2.z);
			capped = false;
			switch (mode)
			{
			case Sizing.Capped:
				if (Cap(stockBox, art, 1f) < num3)
				{
					used = "capped-100";
					capped = true;
					return new Vector3(num3, num3, num3);
				}
				used = "capped-clear";
				return new Vector3(num3, num3, num3);
			case Sizing.Proportional:
				if (Cap(stockBox, art, fill) < num3)
				{
					used = "proportional-capped";
					capped = true;
					return new Vector3(num3, num3, num3);
				}
				used = "proportional";
				return new Vector3(num3, num3, num3);
			case Sizing.Footprint:
				if (num3 * ((Bounds)(ref art)).size.y <= ((Bounds)(ref stockBox)).size.y * 2.2f)
				{
					used = "footprint";
					return new Vector3(num3, num3, num3);
				}
				break;
			case Sizing.Stretch:
				if (num2 <= num * 2.6f)
				{
					used = "stretch";
					return val2;
				}
				break;
			}
			used = ((mode == Sizing.Stretch) ? "stretch->uniform" : "height");
			return new Vector3(num, num, num);
		}

		private static Vector3 ContactPoint(Support.Cloud art, Vector3 scale, Vector3 shift, Vector3 u)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			Vector3 result = Vector3.zero;
			float num = float.MinValue;
			Vector3 val2 = default(Vector3);
			for (int i = 0; i < art.Points.Count; i++)
			{
				Vector3 val = art.Points[i];
				((Vector3)(ref val2))..ctor(val.x * scale.x + shift.x, val.y * scale.y + shift.y, val.z * scale.z + shift.z);
				float num2 = Vector3.Dot(val2, u);
				if (num2 > num)
				{
					num = num2;
					result = val2;
				}
			}
			return result;
		}

		private static bool Fits(Support.Cloud art, Vector3 scale, Vector3 shift, Bounds stockBox)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_004b: 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)
			Bounds val = Placed(art, scale, shift);
			if (((Bounds)(ref val)).size.x <= ((Bounds)(ref stockBox)).size.x + 0.001f && ((Bounds)(ref val)).size.z <= ((Bounds)(ref stockBox)).size.z + 0.001f)
			{
				return ((Bounds)(ref val)).min.y >= ((Bounds)(ref stockBox)).min.y - 0.001f;
			}
			return false;
		}

		private static float NearestTo(Support.Cloud art, Vector3 scale, Vector3 shift, Vector3 point)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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)
			float num = float.MaxValue;
			for (int i = 0; i < art.Points.Count; i++)
			{
				Vector3 val = art.Points[i];
				Vector3 val2 = new Vector3(val.x * scale.x + shift.x, val.y * scale.y + shift.y, val.z * scale.z + shift.z) - point;
				float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
				if (sqrMagnitude < num)
				{
					num = sqrMagnitude;
				}
			}
			return Mathf.Sqrt(num);
		}

		internal static Bounds Placed(Support.Cloud art, Vector3 scale, Vector3 shift)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: