Decompiled source of TrollChests v1.0.0

TrollChests.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace TrollChests
{
	internal class ChestSurface
	{
		private readonly Vector3[] pts;

		private readonly Vector2[] uv;

		private readonly float[] depth;

		private readonly Vector2[] skinUV;

		private readonly int nx;

		private readonly int ny;

		private readonly float x0;

		private readonly float y0;

		private readonly float cell;

		public string Mode { get; private set; }

		public static ChestSurface Sample(SkinnedMeshRenderer body, Transform bone, Transform rig)
		{
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Expected O, but got Unknown
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)body == (Object)null)
			{
				return null;
			}
			Mesh sharedMesh = body.sharedMesh;
			int num = Array.IndexOf(body.bones, bone);
			if (sharedMesh.isReadable && num >= 0)
			{
				Matrix4x4 val = sharedMesh.bindposes[num];
				Vector3[] vertices = sharedMesh.vertices;
				for (int i = 0; i < vertices.Length; i++)
				{
					vertices[i] = rig.InverseTransformPoint(bone.TransformPoint(((Matrix4x4)(ref val)).MultiplyPoint3x4(vertices[i])));
				}
				Vector2[] array = sharedMesh.uv;
				return new ChestSurface(vertices, (array.Length == vertices.Length) ? array : null, sharedMesh.triangles)
				{
					Mode = "bind pose"
				};
			}
			Mesh val2 = new Mesh();
			try
			{
				body.BakeMesh(val2);
				Matrix4x4 val3 = Matrix4x4.TRS(((Component)body).transform.position, ((Component)body).transform.rotation, Vector3.one);
				Vector3[] vertices2 = val2.vertices;
				for (int j = 0; j < vertices2.Length; j++)
				{
					vertices2[j] = rig.InverseTransformPoint(((Matrix4x4)(ref val3)).MultiplyPoint3x4(vertices2[j]));
				}
				Vector2[] array2 = val2.uv;
				return new ChestSurface(vertices2, (array2.Length == vertices2.Length) ? array2 : null, val2.triangles)
				{
					Mode = "current pose (" + (sharedMesh.isReadable ? "bone not skinned" : "mesh not readable") + ")"
				};
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Couldn't read body mesh of " + ((Object)body).name + ", using bone position: " + ex.Message));
				return null;
			}
			finally
			{
				Object.Destroy((Object)(object)val2);
			}
		}

		private ChestSurface(Vector3[] pts, Vector2[] uv, int[] tris)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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_005c: 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)
			this.pts = pts;
			this.uv = uv;
			float num = float.MaxValue;
			float num2 = float.MinValue;
			float num3 = float.MaxValue;
			float num4 = float.MinValue;
			foreach (Vector3 val in pts)
			{
				num = Mathf.Min(num, val.x);
				num2 = Mathf.Max(num2, val.x);
				num3 = Mathf.Min(num3, val.y);
				num4 = Mathf.Max(num4, val.y);
			}
			cell = Mathf.Max(num2 - num, num4 - num3) / 128f;
			x0 = num;
			y0 = num3;
			nx = Mathf.CeilToInt((num2 - num) / cell) + 1;
			ny = Mathf.CeilToInt((num4 - num3) / cell) + 1;
			depth = new float[nx * ny];
			skinUV = (Vector2[])(object)new Vector2[nx * ny];
			for (int j = 0; j < depth.Length; j++)
			{
				depth[j] = float.NaN;
			}
			for (int k = 0; k + 2 < tris.Length; k += 3)
			{
				Raster(tris[k], tris[k + 1], tris[k + 2]);
			}
		}

		private void Raster(int ia, int ib, int ic)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: 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_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: 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_02a0: 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_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: 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)
			Vector3 val = pts[ia];
			Vector3 val2 = pts[ib];
			Vector3 val3 = pts[ic];
			float num = (val2.x - val.x) * (val3.y - val.y) - (val2.y - val.y) * (val3.x - val.x);
			if (Mathf.Abs(num) < 1E-09f)
			{
				return;
			}
			int num2 = Mathf.Max(0, Mathf.CeilToInt((Mathf.Min(val.x, Mathf.Min(val2.x, val3.x)) - x0) / cell));
			int num3 = Mathf.Min(nx - 1, Mathf.FloorToInt((Mathf.Max(val.x, Mathf.Max(val2.x, val3.x)) - x0) / cell));
			int num4 = Mathf.Max(0, Mathf.CeilToInt((Mathf.Min(val.y, Mathf.Min(val2.y, val3.y)) - y0) / cell));
			int num5 = Mathf.Min(ny - 1, Mathf.FloorToInt((Mathf.Max(val.y, Mathf.Max(val2.y, val3.y)) - y0) / cell));
			for (int i = num4; i <= num5; i++)
			{
				float num6 = y0 + (float)i * cell;
				for (int j = num2; j <= num3; j++)
				{
					float num7 = x0 + (float)j * cell;
					float num8 = ((val2.x - num7) * (val3.y - num6) - (val2.y - num6) * (val3.x - num7)) / num;
					float num9 = ((val3.x - num7) * (val.y - num6) - (val3.y - num6) * (val.x - num7)) / num;
					float num10 = 1f - num8 - num9;
					if (num8 < -0.0001f || num9 < -0.0001f || num10 < -0.0001f)
					{
						continue;
					}
					float num11 = num8 * val.z + num9 * val2.z + num10 * val3.z;
					ref float reference = ref depth[i * nx + j];
					if (float.IsNaN(reference) || !(num11 <= reference))
					{
						reference = num11;
						if (uv != null)
						{
							skinUV[i * nx + j] = num8 * uv[ia] + num9 * uv[ib] + num10 * uv[ic];
						}
					}
				}
			}
		}

		public float Height(float x, float y)
		{
			float num = (x - x0) / cell;
			float num2 = (y - y0) / cell;
			int num3 = Mathf.FloorToInt(num);
			int num4 = Mathf.FloorToInt(num2);
			if (num3 < 0 || num4 < 0 || num3 >= nx - 1 || num4 >= ny - 1)
			{
				return float.NaN;
			}
			float num5 = num - (float)num3;
			float num6 = num2 - (float)num4;
			float num7 = depth[num4 * nx + num3];
			float num8 = depth[num4 * nx + num3 + 1];
			float num9 = depth[(num4 + 1) * nx + num3];
			float num10 = depth[(num4 + 1) * nx + num3 + 1];
			if (float.IsNaN(num7) || float.IsNaN(num8) || float.IsNaN(num9) || float.IsNaN(num10))
			{
				return Max(Max(num7, num8), Max(num9, num10));
			}
			return Mathf.Lerp(Mathf.Lerp(num7, num8, num5), Mathf.Lerp(num9, num10, num5), num6);
			static float Max(float p, float q)
			{
				if (!float.IsNaN(p))
				{
					if (!float.IsNaN(q))
					{
						return Mathf.Max(p, q);
					}
					return p;
				}
				return q;
			}
		}

		public Vector3 Normal(float x, float y)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			float num = cell * 1.5f;
			float num2 = Height(x + num, y) - Height(x - num, y);
			float num3 = Height(x, y + num) - Height(x, y - num);
			if (float.IsNaN(num2) || float.IsNaN(num3))
			{
				return Vector3.forward;
			}
			Vector3 val = new Vector3((0f - num2) / (2f * num), (0f - num3) / (2f * num), 1f);
			return ((Vector3)(ref val)).normalized;
		}

		public Vector2? UV(float x, float y)
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			if (uv == null)
			{
				return null;
			}
			int num = Mathf.RoundToInt((x - x0) / cell);
			int num2 = Mathf.RoundToInt((y - y0) / cell);
			if (num < 0 || num2 < 0 || num >= nx || num2 >= ny || float.IsNaN(depth[num2 * nx + num]))
			{
				return null;
			}
			return skinUV[num2 * nx + num];
		}

		public bool FitIslandUV(float cx, float cy, float r, out Vector3 mu, out Vector3 mv, out int cells)
		{
			//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_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0404: Unknown result type (might be due to invalid IL or missing references)
			//IL_0409: Unknown result type (might be due to invalid IL or missing references)
			//IL_0418: Unknown result type (might be due to invalid IL or missing references)
			//IL_041d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_0345: Unknown result type (might be due to invalid IL or missing references)
			//IL_034a: Unknown result type (might be due to invalid IL or missing references)
			mu = (mv = Vector3.zero);
			cells = 0;
			if (uv == null)
			{
				return false;
			}
			int num = Mathf.RoundToInt((cx - x0) / cell);
			int num2 = Mathf.RoundToInt((cy - y0) / cell);
			if (num < 0 || num2 < 0 || num >= nx || num2 >= ny || float.IsNaN(depth[num2 * nx + num]))
			{
				return false;
			}
			bool[] array = new bool[nx * ny];
			Queue<int> queue = new Queue<int>();
			queue.Enqueue(num2 * nx + num);
			array[num2 * nx + num] = true;
			double sxx = 0.0;
			double sxy = 0.0;
			double sx = 0.0;
			double syy = 0.0;
			double sy = 0.0;
			double n = 0.0;
			double num3 = 0.0;
			double num4 = 0.0;
			double num5 = 0.0;
			double num6 = 0.0;
			double num7 = 0.0;
			double num8 = 0.0;
			int num9 = Mathf.CeilToInt(r / cell);
			int[] array2 = new int[4] { 1, -1, 0, 0 };
			int[] array3 = new int[4] { 0, 0, 1, -1 };
			while (queue.Count > 0)
			{
				int num10 = queue.Dequeue();
				int num11 = num10 % nx;
				int num12 = num10 / nx;
				double num13 = x0 + (float)num11 * cell;
				double num14 = y0 + (float)num12 * cell;
				double num15 = skinUV[num10].x;
				double num16 = skinUV[num10].y;
				sxx += num13 * num13;
				sxy += num13 * num14;
				sx += num13;
				syy += num14 * num14;
				sy += num14;
				n++;
				num3 += num13 * num15;
				num4 += num14 * num15;
				num5 += num15;
				num6 += num13 * num16;
				num7 += num14 * num16;
				num8 += num16;
				for (int i = 0; i < 4; i++)
				{
					int num17 = num11 + array2[i];
					int num18 = num12 + array3[i];
					int num19 = num18 * nx + num17;
					if (num17 >= 0 && num18 >= 0 && num17 < nx && num18 < ny && !array[num19] && !float.IsNaN(depth[num19]) && (num17 - num) * (num17 - num) + (num18 - num2) * (num18 - num2) <= num9 * num9)
					{
						Vector2 val = skinUV[num19] - skinUV[num10];
						if (!(((Vector2)(ref val)).sqrMagnitude > 0.0009f))
						{
							array[num19] = true;
							queue.Enqueue(num19);
						}
					}
				}
			}
			cells = (int)n;
			if (n < 6.0)
			{
				return false;
			}
			double det = Det(sxx, sxy, sx, sxy, syy, sy, sx, sy, n);
			if (Math.Abs(det) < 1E-12)
			{
				return false;
			}
			mu = Solve(num3, num4, num5);
			mv = Solve(num6, num7, num8);
			return true;
			Vector3 Solve(double b0, double b1, double b2)
			{
				//IL_009c: Unknown result type (might be due to invalid IL or missing references)
				return new Vector3((float)(Det(b0, sxy, sx, b1, syy, sy, b2, sy, n) / det), (float)(Det(sxx, b0, sx, sxy, b1, sy, sx, b2, n) / det), (float)(Det(sxx, sxy, b0, sxy, syy, b1, sx, sy, b2) / det));
			}
		}

		private static double Det(double a, double b, double c, double d, double e, double f, double g, double h, double i)
		{
			return a * (e * i - f * h) - b * (d * i - f * g) + c * (d * h - e * g);
		}

		public Vector2 NearestUV(float x, float y, float front)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			if (uv == null)
			{
				return Vector2.zero;
			}
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(x, y, front);
			int num = 0;
			for (int i = 1; i < pts.Length; i++)
			{
				Vector3 val2 = pts[i] - val;
				float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
				val2 = pts[num] - val;
				if (sqrMagnitude < ((Vector3)(ref val2)).sqrMagnitude)
				{
					num = i;
				}
			}
			return uv[num];
		}
	}
	internal class Part
	{
		public struct Capsule
		{
			public Vector3 A;

			public Vector3 B;

			public float R;
		}

		public readonly Shape S;

		public Transform T;

		public Mesh Mesh;

		public float Side;

		public float Surface;

		public Vector3 Mass;

		public Vector3 Pivot;

		public readonly Vector3[] Rest;

		public readonly Vector3[] SkinNormal;

		public readonly float[] SkinBlend;

		private Vector3 pos;

		private Vector3 vel;

		private Vector3 prevAnchor;

		private Vector3 anchorVel;

		private Vector3 lowPos;

		private Vector3 lowVel;

		private Vector3 massAccel;

		private Vector3 D;

		private Vector3 D2;

		private Vector3 shownD;

		private Vector3 shownD2;

		private Vector3 shownDVel;

		private Vector3 shownD2Vel;

		private readonly int[] probes;

		private const int Levels = 32;

		private readonly Quaternion[] swingSteps = (Quaternion[])(object)new Quaternion[33];

		private readonly int[] level;

		private float armDepth;

		private readonly Vector3[] capMin = (Vector3[])(object)new Vector3[4];

		private readonly Vector3[] capMax = (Vector3[])(object)new Vector3[4];

		private Vector3[] fromPivot;

		private readonly Vector3[] verts;

		private readonly List<Vector3> normals;

		public Part(Shape shape, float side)
		{
			S = shape;
			Side = side;
			Rest = (Vector3[])(object)new Vector3[S.N];
			SkinNormal = (Vector3[])(object)new Vector3[S.N];
			SkinBlend = new float[S.N];
			verts = (Vector3[])(object)new Vector3[S.N];
			normals = new List<Vector3>(S.N);
			int[] array = (from i in Enumerable.Range(0, S.N)
				where S.Main[i] > 0.3f
				select i).ToArray();
			int step = Mathf.Max(1, array.Length / 64);
			probes = array.Where((int _, int k) => k % step == 0).ToArray();
			level = S.Main.Select((float w) => Mathf.RoundToInt(w * 32f)).ToArray();
		}

		public void Prepare()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			fromPivot = (Vector3[])(object)new Vector3[S.N];
			for (int i = 0; i < S.N; i++)
			{
				fromPivot[i] = Rest[i] - Pivot;
			}
		}

		public void Simulate(float dt, int steps, Vector3 accel, Vector3 gravity, float k, float c, float size, float meters, Matrix4x4 toRig, Matrix4x4 toWorld, bool reset, ChestSurface chest, Capsule[] arms, int armCount)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0416: Unknown result type (might be due to invalid IL or missing references)
			//IL_041b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0428: Unknown result type (might be due to invalid IL or missing references)
			//IL_042d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0434: Unknown result type (might be due to invalid IL or missing references)
			//IL_043a: 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_0455: Unknown result type (might be due to invalid IL or missing references)
			//IL_045c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0462: Unknown result type (might be due to invalid IL or missing references)
			//IL_0478: Unknown result type (might be due to invalid IL or missing references)
			//IL_047d: 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_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: 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_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: 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_0310: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: 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_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			//IL_035b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0360: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: 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_0370: 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_0378: Unknown result type (might be due to invalid IL or missing references)
			//IL_037d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0382: Unknown result type (might be due to invalid IL or missing references)
			//IL_0389: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0395: Unknown result type (might be due to invalid IL or missing references)
			//IL_039a: Unknown result type (might be due to invalid IL or missing references)
			//IL_039f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: 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_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ff: Unknown result type (might be due to invalid IL or missing references)
			float num = dt / (float)steps;
			float num2 = size * meters;
			Vector3 val = ((Matrix4x4)(ref toWorld)).MultiplyPoint3x4(T.localPosition + T.localRotation * (Mass * size));
			Vector3 val2;
			if (reset)
			{
				val2 = (pos = (prevAnchor = val));
				val2 = (anchorVel = Vector3.zero);
				val2 = (D2 = val2);
				val2 = (D = val2);
				val2 = (massAccel = val2);
				val2 = (lowVel = val2);
				val2 = (vel = (lowPos = val2));
				val2 = (shownD2Vel = Vector3.zero);
				val2 = (shownDVel = val2);
				val2 = (shownD = (shownD2 = val2));
			}
			anchorVel = Vector3.Lerp(anchorVel, (val - prevAnchor) / dt, 1f - Mathf.Exp((0f - dt) / 0.03f));
			prevAnchor = val;
			float num3 = k * 2.5f;
			float num4 = 1f / (0.04f * num2 * num2);
			float num5 = 0.15f * num2;
			float num6 = 1f - Mathf.Exp((0f - num) / 0.03f);
			for (int i = 0; i < steps; i++)
			{
				Vector3 val3 = vel;
				Vector3 val4 = pos - val;
				Vector3 val5 = (0f - k) * (1f + ((Vector3)(ref val4)).sqrMagnitude * num4) * val4 - c * (vel - anchorVel) + accel + ((Matrix4x4)(ref toWorld)).MultiplyVector(ArmPush(arms, armCount, size)) * (6f * k);
				vel += val5 * num;
				Vector3 val6 = vel - anchorVel;
				float num7 = 1.5f * num2;
				if (((Vector3)(ref val6)).sqrMagnitude > num7 * num7)
				{
					vel = anchorVel + val6 * (num7 / ((Vector3)(ref val6)).magnitude);
				}
				D = ((Matrix4x4)(ref toRig)).MultiplyVector(pos + vel * num - val);
				Vector3 d = D;
				Limit(size);
				Collide(chest, size);
				if (D != d)
				{
					val2 = ((Matrix4x4)(ref toWorld)).MultiplyVector(D - d);
					Vector3 normalized = ((Vector3)(ref val2)).normalized;
					float num8 = Vector3.Dot(vel - anchorVel, normalized);
					if (num8 < 0f)
					{
						vel -= normalized * num8;
					}
				}
				pos = val + ((Matrix4x4)(ref toWorld)).MultiplyVector(D);
				massAccel = Vector3.Lerp(massAccel, (vel - val3) / num, num6);
				lowVel += ((0f - num3) * (1f + ((Vector3)(ref lowPos)).sqrMagnitude / (0.25f * num5 * num5)) * lowPos - c * lowVel - massAccel + gravity) * num;
				lowPos += lowVel * num;
				if (((Vector3)(ref lowPos)).sqrMagnitude > num5 * num5)
				{
					Vector3 normalized2 = ((Vector3)(ref lowPos)).normalized;
					lowPos = normalized2 * num5;
					float num9 = Vector3.Dot(lowVel, normalized2);
					if (num9 > 0f)
					{
						lowVel -= normalized2 * num9;
					}
				}
			}
			D2 = Vector3.ClampMagnitude(((Matrix4x4)(ref toRig)).MultiplyVector(lowPos), 0.15f * size);
			shownD = Vector3.SmoothDamp(shownD, D, ref shownDVel, 0.05f, float.PositiveInfinity, dt);
			shownD2 = Vector3.SmoothDamp(shownD2, D2, ref shownD2Vel, 0.05f, float.PositiveInfinity, dt);
		}

		private void Limit(float size)
		{
			//IL_0002: 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_0013: Unknown result type (might be due to invalid IL or missing references)
			D = Vector3.ClampMagnitude(D, 0.4f * size);
			if (D.z < -0.25f * size)
			{
				D.z = -0.25f * size;
			}
		}

		private Quaternion Swing(float size)
		{
			//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)
			return Swing(size, D);
		}

		private Quaternion Swing(float size, Vector3 d)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0022: 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_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Mass - Pivot;
			return Quaternion.FromToRotation(val, val + Quaternion.Inverse(T.localRotation) * d / size);
		}

		private Vector3 Bend(int j, Quaternion swing, Vector3 slosh)
		{
			//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_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			return Pivot + Quaternion.Slerp(Quaternion.identity, swing, S.Main[j]) * (Rest[j] - Pivot) + slosh * S.Lower[j];
		}

		private static Vector3 Closest(Capsule cap, Vector3 x)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = cap.B - cap.A;
			return cap.A + val * Mathf.Clamp01(Vector3.Dot(x - cap.A, val) / Mathf.Max(((Vector3)(ref val)).sqrMagnitude, 1E-06f));
		}

		private Vector3 ArmPush(Capsule[] arms, int armCount, float size)
		{
			//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_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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: 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_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			if (armCount == 0)
			{
				return Vector3.zero;
			}
			Quaternion swing = Swing(size);
			Vector3 slosh = Quaternion.Inverse(T.localRotation) * D2 / size;
			Vector3 val = T.localPosition + T.localRotation * (Mass * size) + D;
			float num = 0f;
			Vector3 val2 = Vector3.zero;
			for (int i = 0; i < armCount; i++)
			{
				Capsule cap = arms[i];
				Vector3 val3 = val - Closest(cap, val);
				if (!(((Vector3)(ref val3)).sqrMagnitude < 1E-08f))
				{
					float num2 = 0f;
					int[] array = probes;
					foreach (int j2 in array)
					{
						Vector3 val4 = T.localPosition + T.localRotation * (Bend(j2, swing, slosh) * size);
						float num3 = num2;
						float r = cap.R;
						Vector3 val5 = val4 - Closest(cap, val4);
						num2 = Mathf.Max(num3, r - ((Vector3)(ref val5)).magnitude);
					}
					if (num2 > num)
					{
						num = num2;
						val2 = ((Vector3)(ref val3)).normalized;
					}
				}
			}
			armDepth = num;
			return val2 * Mathf.Min(num, 0.3f * size);
		}

		private void Collide(ChestSurface chest, float size)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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_0091: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			float num = 0.3f * size;
			Vector3 slosh = Quaternion.Inverse(T.localRotation) * D2 / size;
			for (int i = 0; i < 2; i++)
			{
				Quaternion swing = Swing(size);
				float num2 = 0f;
				float num3 = 0f;
				int[] array = probes;
				foreach (int num4 in array)
				{
					float num5 = Mathf.Max(S.Main[num4], 0.3f);
					Vector3 val = T.localPosition + T.localRotation * (Bend(num4, swing, slosh) * size);
					float num6 = chest?.Height(val.x, val.y) ?? Surface;
					if (!float.IsNaN(num6) && val.z < num6)
					{
						num2 = Mathf.Max(num2, (num6 - val.z) / num5);
					}
					if (val.x * Side > 0f)
					{
						num3 = Mathf.Max(num3, val.x * Side / num5);
					}
				}
				D.z += Mathf.Min(num2, num);
				D.x -= Side * Mathf.Min(num3, num);
				Limit(size);
			}
		}

		public void Render(ChestSurface chest, float size, Capsule[] arms, int armCount)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: 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_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: 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_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: 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_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			//IL_033b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0300: Unknown result type (might be due to invalid IL or missing references)
			//IL_0525: Unknown result type (might be due to invalid IL or missing references)
			//IL_0532: Unknown result type (might be due to invalid IL or missing references)
			//IL_0540: Unknown result type (might be due to invalid IL or missing references)
			//IL_0545: Unknown result type (might be due to invalid IL or missing references)
			//IL_0549: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: Unknown result type (might be due to invalid IL or missing references)
			//IL_0378: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: 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_049c: Unknown result type (might be due to invalid IL or missing references)
			//IL_049e: Unknown result type (might be due to invalid IL or missing references)
			//IL_049f: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04aa: 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_03d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_040b: Unknown result type (might be due to invalid IL or missing references)
			//IL_042e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0430: Unknown result type (might be due to invalid IL or missing references)
			//IL_0435: Unknown result type (might be due to invalid IL or missing references)
			//IL_0437: Unknown result type (might be due to invalid IL or missing references)
			//IL_0439: Unknown result type (might be due to invalid IL or missing references)
			//IL_043b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0440: Unknown result type (might be due to invalid IL or missing references)
			//IL_0471: 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_047a: Unknown result type (might be due to invalid IL or missing references)
			//IL_047f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0484: Unknown result type (might be due to invalid IL or missing references)
			Vector3 localPosition = T.localPosition;
			Quaternion val = Swing(size, shownD);
			for (int i = 0; i <= 32; i++)
			{
				swingSteps[i] = Quaternion.Slerp(Quaternion.identity, val, (float)i / 32f);
			}
			Vector3 val2 = shownD2 / size;
			float num = 0.15f * size;
			int num2 = ((armDepth > 0f) ? armCount : 0);
			for (int j = 0; j < num2; j++)
			{
				capMin[j] = Vector3.Min(arms[j].A, arms[j].B) - Vector3.one * arms[j].R;
				capMax[j] = Vector3.Max(arms[j].A, arms[j].B) + Vector3.one * arms[j].R;
			}
			float x = Pivot.x;
			float y = Pivot.y;
			float z = Pivot.z;
			float x2 = val2.x;
			float y2 = val2.y;
			float z2 = val2.z;
			float[] main = S.Main;
			float[] lower = S.Lower;
			Vector3 val5 = default(Vector3);
			for (int k = 0; k < S.N; k++)
			{
				Quaternion val3 = swingSteps[level[k]];
				Vector3 val4 = fromPivot[k];
				float num3 = 2f * (val3.y * val4.z - val3.z * val4.y);
				float num4 = 2f * (val3.z * val4.x - val3.x * val4.z);
				float num5 = 2f * (val3.x * val4.y - val3.y * val4.x);
				float num6 = lower[k];
				((Vector3)(ref val5))..ctor(x + val4.x + val3.w * num3 + (val3.y * num5 - val3.z * num4) + x2 * num6, y + val4.y + val3.w * num4 + (val3.z * num3 - val3.x * num5) + y2 * num6, z + val4.z + val3.w * num5 + (val3.x * num4 - val3.y * num3) + z2 * num6);
				if (main[k] > 0.02f)
				{
					Vector3 val6 = localPosition + val5 * size;
					bool flag = false;
					if (val5.z < Rest[k].z && chest != null)
					{
						float num7 = chest.Height(val6.x, val6.y);
						if (!float.IsNaN(num7) && val6.z < num7 && num7 - val6.z < num)
						{
							val6.z = num7;
							flag = true;
						}
					}
					if (val6.x * Side > 0f && val6.x * Side < num)
					{
						val6.x = 0f;
						flag = true;
					}
					for (int l = 0; l < num2; l++)
					{
						if (!(val6.x < capMin[l].x) && !(val6.y < capMin[l].y) && !(val6.z < capMin[l].z) && !(val6.x > capMax[l].x) && !(val6.y > capMax[l].y) && !(val6.z > capMax[l].z))
						{
							Vector3 val7 = Closest(arms[l], val6);
							Vector3 val8 = val6 - val7;
							float magnitude = ((Vector3)(ref val8)).magnitude;
							float r = arms[l].R;
							if (magnitude < r && magnitude > 1E-05f && r - magnitude < num)
							{
								val6 = val7 + val8 * (r / magnitude);
								flag = true;
							}
						}
					}
					if (flag)
					{
						val5 = (val6 - localPosition) / size;
					}
				}
				verts[k] = val5;
			}
			Mesh.vertices = verts;
			Mesh.RecalculateNormals();
			Mesh.GetNormals(normals);
			for (int m = 0; m < S.N; m++)
			{
				if (SkinBlend[m] > 0f)
				{
					List<Vector3> list = normals;
					int index = m;
					Vector3 val9 = Vector3.Lerp(normals[m], SkinNormal[m], SkinBlend[m]);
					list[index] = ((Vector3)(ref val9)).normalized;
				}
			}
			Mesh.SetNormals(normals);
		}
	}
	public enum Outfit
	{
		Bikini,
		HalterTop
	}
	[BepInPlugin("cyntrex.TrollChests", "TrollChests", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private const string Guid = "cyntrex.TrollChests";

		private const string Version = "1.0.0";

		internal static ManualLogSource Log;

		internal static ConfigEntry<string> BoneName;

		internal static ConfigEntry<Outfit> OutfitChoice;

		internal static ConfigEntry<float> Size;

		internal static ConfigEntry<float> Inflate;

		internal static ConfigEntry<float> Forward;

		internal static ConfigEntry<float> Up;

		internal static ConfigEntry<float> Spacing;

		internal static ConfigEntry<float> Stiffness;

		internal static ConfigEntry<float> Damping;

		internal static ConfigEntry<float> Exaggeration;

		internal static ConfigEntry<float> Gravity;

		private Harmony harmony;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			BoneName = ((BaseUnityPlugin)this).Config.Bind<string>("Placement", "BoneName", "", "Bone to attach to. Empty = auto (deepest bone named chest/spine). Bone lists are printed to the log.");
			Size = ((BaseUnityPlugin)this).Config.Bind<float>("Placement", "Size", 1.8f, "Width of each breast, in meters at troll scale 1.");
			Inflate = ((BaseUnityPlugin)this).Config.Bind<float>("Placement", "Inflate", 1.6f, "Makes them bigger and rounder (more bulbous), growing in height and depth but barely in width so they stay inside the troll's silhouette. 1 = the model as is.");
			Forward = ((BaseUnityPlugin)this).Config.Bind<float>("Placement", "Forward", 0f, "Push out (+) or in (-) from the troll's chest surface (auto-detected per troll).");
			Up = ((BaseUnityPlugin)this).Config.Bind<float>("Placement", "Up", -0.8f, "Height on the chest, relative to the chest bone.");
			Spacing = ((BaseUnityPlugin)this).Config.Bind<float>("Placement", "Spacing", 0f, "Extra gap between the two sides (0 = they meet at the cleavage).");
			Stiffness = ((BaseUnityPlugin)this).Config.Bind<float>("Physics", "Stiffness", 30f, "How firmly they hold their shape and position. Lower = heavier, slower, floppier.");
			Damping = ((BaseUnityPlugin)this).Config.Bind<float>("Physics", "Damping", 4f, "How fast the wobble dies down. Lower = keeps bouncing longer.");
			Gravity = ((BaseUnityPlugin)this).Config.Bind<float>("Physics", "Gravity", 1f, "How hard gravity pulls them down. Higher = heavier, saggier.");
			Exaggeration = ((BaseUnityPlugin)this).Config.Bind<float>("Physics", "Exaggeration", 1.5f, "Extra throw from the troll's own movement, on top of real inertia (capped so attacks can't slam them around). 1 = physically real.");
			OutfitChoice = ((BaseUnityPlugin)this).Config.Bind<Outfit>("Look", "Outfit", Outfit.Bikini, "Bikini: micro bikini on bare skin. HalterTop: a deep-V halter top.");
			OutfitChoice.SettingChanged += delegate
			{
				Reattach();
			};
			harmony = Harmony.CreateAndPatchAll(typeof(Plugin), "cyntrex.TrollChests");
			foreach (Character allCharacter in Character.GetAllCharacters())
			{
				Rig.TryAttach(allCharacter);
			}
		}

		private static void Reattach()
		{
			Rig.DetachAll();
			foreach (Character allCharacter in Character.GetAllCharacters())
			{
				Rig.TryAttach(allCharacter);
			}
		}

		private void OnDestroy()
		{
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			Rig.DetachAll();
		}

		[HarmonyPostfix]
		[HarmonyPriority(0)]
		[HarmonyPatch(typeof(Character), "Awake")]
		private static void CharacterAwake(Character __instance)
		{
			Rig.TryAttach(__instance);
		}
	}
	public class Rig : MonoBehaviour
	{
		private const float ArmThickness = 0.3f;

		private const float MaxSimDistance = 80f;

		private static readonly string[] armBones = new string[6] { "LeftArm", "LeftForeArm", "LeftHand", "RightArm", "RightForeArm", "RightHand" };

		private static readonly List<Rig> all = new List<Rig>();

		private static readonly Dictionary<Material, Material> materials = new Dictionary<Material, Material>();

		private static readonly Dictionary<Material, Material> braMaterials = new Dictionary<Material, Material>();

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

		private ChestSurface chest;

		private readonly Part[] parts = new Part[2]
		{
			new Part(Shape.For(Plugin.OutfitChoice.Value, left: true), 1f),
			new Part(Shape.For(Plugin.OutfitChoice.Value, left: false), -1f)
		};

		private (float, float, float, float, float) measuredFor;

		private Transform[] arms;

		private readonly Part.Capsule[] capsules = new Part.Capsule[4];

		private Vector3 prevOrigin;

		private Vector3 originVel;

		private Vector3 prevOriginVel;

		private Vector3 frameAccel;

		private bool primed;

		private static readonly Color Straw = new Color(0.78f, 0.66f, 0.38f);

		public static void TryAttach(Character c)
		{
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Expected O, but got Unknown
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Expected O, but got Unknown
			//IL_0391: Unknown result type (might be due to invalid IL or missing references)
			//IL_0393: 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)
			if ((Object)(object)c == (Object)null || c is Player || (!IsTroll(c.m_name) && !IsTroll(((Object)((Component)c).gameObject).name)) || (Object)(object)((Component)c).GetComponentInChildren<Rig>(true) != (Object)null)
			{
				return;
			}
			Transform[] bones = ((Component)((Component)c).transform).GetComponentsInChildren<Transform>(true);
			bool flag = dumped.Add(((Object)((Component)c).gameObject).name);
			if (flag)
			{
				Plugin.Log.LogDebug((object)("Bones of " + ((Object)((Component)c).gameObject).name + ": " + string.Join(", ", bones.Select((Transform b) => ((Object)b).name))));
			}
			Transform val = FindBone(bones, ((Component)c).transform);
			SkinnedMeshRenderer body = Body(c);
			GameObject val2 = new GameObject("TrollChests");
			val2.layer = ((Component)val).gameObject.layer;
			val2.transform.SetParent(val, false);
			Quaternion val3 = Quaternion.Inverse(val.rotation) * ((Component)c).transform.rotation;
			Quaternion? val4 = BindFrame(body, val, val3);
			val2.transform.localRotation = val4 ?? val3;
			val2.transform.localScale = Vector3.one * (((Component)c).transform.lossyScale.x / val.lossyScale.x);
			Rig rig = val2.AddComponent<Rig>();
			rig.chest = ChestSurface.Sample(body, val, val2.transform);
			Transform[] source = armBones.Select((string n) => ((IEnumerable<Transform>)bones).FirstOrDefault((Func<Transform, bool>)((Transform b) => ((Object)b).name == n))).ToArray();
			if (source.All((Transform b) => (Object)(object)b != (Object)null))
			{
				rig.arms = source;
			}
			Material val5 = SkinMaterial(body);
			Material val6 = BraMaterial(c, val5);
			for (int num = 0; num < 2; num++)
			{
				GameObject val7 = new GameObject((num == 0) ? "L" : "R");
				val7.layer = val2.layer;
				val7.transform.SetParent(val2.transform, false);
				val7.AddComponent<MeshFilter>().sharedMesh = (rig.parts[num].Mesh = rig.parts[num].S.CreateMesh());
				MeshRenderer val8 = val7.AddComponent<MeshRenderer>();
				if ((Object)(object)val5 != (Object)null)
				{
					((Renderer)val8).sharedMaterials = (Material[])(object)new Material[2]
					{
						val5,
						val6 ?? val5
					};
				}
				rig.parts[num].T = val7.transform;
			}
			string text = rig.Measure();
			all.Add(rig);
			Plugin.Log.LogDebug((object)string.Format("Attached to {0} ({1}) on bone '{2}', skin at L {3:0.00} R {4:0.00}, texture{5}, arm collision {6}, body from {7}, frame from {8} ({9:0}° from current facing)", ((Object)((Component)c).gameObject).name, c.m_name, ((Object)val).name, rig.parts[0].Surface, rig.parts[1].Surface, text, (rig.arms != null) ? "on" : "off", rig.chest?.Mode ?? "nothing", val4.HasValue ? "bind pose" : "current pose", Quaternion.Angle(val4 ?? val3, val3)));
			if (flag && rig.chest != null)
			{
				List<string> list = new List<string>();
				for (float num2 = 2f; num2 >= -4.01f; num2 -= 0.25f)
				{
					list.Add($"{num2:0.00}:{rig.chest.Height(Plugin.Spacing.Value, num2):0.00}");
				}
				Plugin.Log.LogDebug((object)string.Format("Front profile of {0} at x={1} (y:z): {2}", ((Object)((Component)c).gameObject).name, Plugin.Spacing.Value, string.Join(" ", list)));
			}
		}

		public static void DetachAll()
		{
			foreach (Rig item in all)
			{
				if (Object.op_Implicit((Object)(object)item))
				{
					Object.Destroy((Object)(object)((Component)item).gameObject);
				}
			}
			all.Clear();
			foreach (Material value in materials.Values)
			{
				if (Object.op_Implicit((Object)(object)value))
				{
					Object.Destroy((Object)(object)value);
				}
			}
			materials.Clear();
			foreach (Material value2 in braMaterials.Values)
			{
				if (Object.op_Implicit((Object)(object)value2))
				{
					Object.Destroy((Object)(object)value2.mainTexture);
					Object.Destroy((Object)(object)value2);
				}
			}
			braMaterials.Clear();
		}

		private static bool IsTroll(string s)
		{
			if (s != null)
			{
				return s.IndexOf("troll", StringComparison.OrdinalIgnoreCase) >= 0;
			}
			return false;
		}

		private static Transform FindBone(Transform[] bones, Transform root)
		{
			string want = Plugin.BoneName.Value.Trim();
			if (want != "")
			{
				return ((IEnumerable<Transform>)bones).FirstOrDefault((Func<Transform, bool>)((Transform b) => ((Object)b).name == want)) ?? root;
			}
			Transform val = null;
			int num = -1;
			foreach (Transform val2 in bones)
			{
				string text = ((Object)val2).name.ToLowerInvariant();
				if (text.Contains("chest"))
				{
					return val2;
				}
				if (text.Contains("spine"))
				{
					int num3 = Depth(val2, root);
					if (num3 > num)
					{
						val = val2;
						num = num3;
					}
				}
			}
			return val ?? root;
		}

		private static int Depth(Transform t, Transform root)
		{
			int num = 0;
			while ((Object)(object)t != (Object)(object)root && (Object)(object)t != (Object)null)
			{
				num++;
				t = t.parent;
			}
			return num;
		}

		private static Quaternion? BindFrame(SkinnedMeshRenderer body, Transform bone, Quaternion now)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)body == (Object)null)
			{
				return null;
			}
			int num = Array.IndexOf(body.bones, bone);
			Matrix4x4[] bindposes = body.sharedMesh.bindposes;
			if (num < 0 || num >= bindposes.Length)
			{
				return null;
			}
			Matrix4x4 val = bindposes[num];
			Vector3[] array = ((IEnumerable<Vector4>)(object)new Vector4[3]
			{
				((Matrix4x4)(ref val)).GetColumn(0),
				((Matrix4x4)(ref val)).GetColumn(1),
				((Matrix4x4)(ref val)).GetColumn(2)
			}).Select(delegate(Vector4 a)
			{
				//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_0006: 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)
				Vector3 val5 = Vector4.op_Implicit(a);
				return ((Vector3)(ref val5)).normalized;
			}).ToArray();
			Quaternion value = now;
			float num2 = float.MaxValue;
			Vector3[] array2 = array;
			foreach (Vector3 val2 in array2)
			{
				Vector3[] array3 = array;
				foreach (Vector3 val3 in array3)
				{
					if (val2 == val3)
					{
						continue;
					}
					int[] array4 = new int[2] { 1, -1 };
					foreach (int num6 in array4)
					{
						int[] array5 = new int[2] { 1, -1 };
						foreach (int num8 in array5)
						{
							Quaternion val4 = Quaternion.LookRotation(val2 * (float)num6, val3 * (float)num8);
							float num9 = Quaternion.Angle(val4, now);
							if (num9 < num2)
							{
								num2 = num9;
								value = val4;
							}
						}
					}
				}
			}
			return value;
		}

		private static SkinnedMeshRenderer Body(Character c)
		{
			return (from s in ((Component)c).GetComponentsInChildren<SkinnedMeshRenderer>(true)
				where (Object)(object)s.sharedMesh != (Object)null && (Object)(object)((Renderer)s).sharedMaterial != (Object)null
				orderby s.sharedMesh.vertexCount descending
				select s).FirstOrDefault();
		}

		private static Material SkinMaterial(SkinnedMeshRenderer body)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			//IL_0057: Expected O, but got Unknown
			if ((Object)(object)body == (Object)null)
			{
				return null;
			}
			if (!materials.TryGetValue(((Renderer)body).sharedMaterial, out var value))
			{
				Dictionary<Material, Material> dictionary = materials;
				Material sharedMaterial = ((Renderer)body).sharedMaterial;
				Material val = new Material(((Renderer)body).sharedMaterial)
				{
					name = "TrollChests_" + ((Object)((Renderer)body).sharedMaterial).name
				};
				value = val;
				dictionary[sharedMaterial] = val;
			}
			return value;
		}

		private static Material BraMaterial(Character c, Material skin)
		{
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Expected O, but got Unknown
			//IL_00ce: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Expected O, but got Unknown
			//IL_0117: 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)
			if ((Object)(object)skin == (Object)null)
			{
				return null;
			}
			Renderer val = ((IEnumerable<Renderer>)((Component)c).GetComponentsInChildren<Renderer>(true)).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name.IndexOf("hair", StringComparison.OrdinalIgnoreCase) >= 0 && (Object)(object)r.sharedMaterial != (Object)null));
			Material key = (((Object)(object)val != (Object)null) ? val.sharedMaterial : skin);
			if (braMaterials.TryGetValue(key, out var value))
			{
				return value;
			}
			Renderer obj = ((val is SkinnedMeshRenderer) ? val : null);
			object obj2 = ((obj != null) ? ((SkinnedMeshRenderer)obj).sharedMesh : null);
			if (obj2 == null)
			{
				if (val == null)
				{
					obj2 = null;
				}
				else
				{
					MeshFilter component = ((Component)val).GetComponent<MeshFilter>();
					obj2 = ((component != null) ? component.sharedMesh : null);
				}
			}
			Mesh val2 = (Mesh)obj2;
			Color val3 = (((Object)(object)val != (Object)null) ? AverageColor(val.sharedMaterial, ((Object)(object)val2 != (Object)null && val2.isReadable) ? val2.uv : null) : Straw);
			Texture2D val4 = new Texture2D(1, 1);
			val4.SetPixel(0, 0, val3);
			val4.Apply();
			value = new Material(skin)
			{
				name = "TrollChests_Top",
				mainTexture = (Texture)(object)val4
			};
			braMaterials[key] = value;
			Plugin.Log.LogDebug((object)string.Format("Top color for {0}: {1} (from {2})", ((Object)((Component)c).gameObject).name, val3, ((Object)(object)val != (Object)null) ? (((Object)val).name + "/" + ((Object)val.sharedMaterial).name + ", " + (((Object)(object)val2 != (Object)null && val2.isReadable) ? "hair UVs" : "whole texture")) : "default"));
			return value;
		}

		private static Color AverageColor(Material m, Vector2[] uvs)
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: 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_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			Texture mainTexture = m.mainTexture;
			if ((Object)(object)mainTexture == (Object)null)
			{
				if (!m.HasProperty("_Color"))
				{
					return Straw;
				}
				return m.color;
			}
			RenderTexture temporary = RenderTexture.GetTemporary(256, 256, 0, (RenderTextureFormat)0);
			RenderTexture active = RenderTexture.active;
			Graphics.Blit(mainTexture, temporary);
			RenderTexture.active = temporary;
			Texture2D val = new Texture2D(256, 256, (TextureFormat)4, false);
			val.ReadPixels(new Rect(0f, 0f, 256f, 256f), 0, 0);
			RenderTexture.active = active;
			RenderTexture.ReleaseTemporary(temporary);
			Color val2 = Color.clear;
			int num = 0;
			Color[] pixels = val.GetPixels();
			if (uvs != null && uvs.Length != 0)
			{
				foreach (Vector2 val3 in uvs)
				{
					int num2 = (int)(Mathf.Repeat(val3.x, 1f) * 255f);
					int num3 = (int)(Mathf.Repeat(val3.y, 1f) * 255f);
					Color val4 = pixels[num3 * 256 + num2];
					if (val4.a > 0.5f)
					{
						val2 += val4;
						num++;
					}
				}
			}
			else
			{
				Color[] array = pixels;
				foreach (Color val5 in array)
				{
					if (val5.a > 0.5f)
					{
						val2 += val5;
						num++;
					}
				}
			}
			Object.Destroy((Object)(object)val);
			Color val6 = ((num > 0) ? (val2 / (float)num) : Straw);
			if (m.HasProperty("_Color"))
			{
				val6 *= m.color;
			}
			val6.a = 1f;
			return val6;
		}

		private string Measure()
		{
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: 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_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_037a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0381: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: 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_0394: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: 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_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			//IL_030d: 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_031e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_039f: 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)
			float value = Plugin.Size.Value;
			measuredFor = Settings();
			float value2 = Plugin.Inflate.Value;
			string text = "";
			for (int i = 0; i < 2; i++)
			{
				Part part = parts[i];
				Shape s = part.S;
				float num = ((i == 0) ? (0f - Plugin.Spacing.Value) : Plugin.Spacing.Value);
				float value3 = Plugin.Up.Value;
				float num2 = ((chest != null) ? chest.Height(num, value3) : float.NaN);
				part.Surface = (float.IsNaN(num2) ? 0f : num2);
				part.Mass = Inflated(s, s.Mass, 1f, value2);
				part.Pivot = new Vector3(part.Mass.x, part.Mass.y + 0.25f, 0f);
				Transform t = part.T;
				t.localPosition = new Vector3(num, value3, part.Surface + Plugin.Forward.Value);
				t.localRotation = Quaternion.identity;
				t.localScale = Vector3.one * value;
				Vector3 localPosition = t.localPosition;
				for (int j = 0; j < s.N; j++)
				{
					Vector3 val = localPosition + Inflated(s, s.Verts[j], s.Main[j], value2) * value;
					float num3 = val.z - part.Surface;
					val.z = SkinAt(val.x, val.y, num, value3, part.Surface, value) + num3;
					part.Rest[j] = (val - localPosition) / value;
					part.SkinNormal[j] = ((chest != null) ? chest.Normal(val.x, val.y) : Vector3.forward);
					float num4 = Mathf.Clamp01((num3 - Plugin.Forward.Value) / (0.15f * value));
					part.SkinBlend[j] = 1f - num4 * num4 * (3f - 2f * num4);
				}
				Vector2[] array = (Vector2[])(object)new Vector2[s.N];
				Vector3 val2 = localPosition + part.Mass * value;
				if (chest != null && chest.FitIslandUV(val2.x, val2.y, 0.8f * value, out var mu, out var mv, out var cells))
				{
					for (int k = 0; k < s.N; k++)
					{
						Vector3 val3 = localPosition + part.Rest[k] * value;
						array[k] = new Vector2(mu.x * val3.x + mu.y * val3.y + mu.z, mv.x * val3.x + mv.y * val3.y + mv.z);
					}
					text += string.Format(" {0}=island({1} cells)", (i == 0) ? "L" : "R", cells);
				}
				else
				{
					Vector2 val4 = ((chest != null) ? chest.NearestUV(val2.x, val2.y, part.Surface) : Vector2.zero);
					for (int l = 0; l < s.N; l++)
					{
						array[l] = val4;
					}
					text = text + " " + ((i == 0) ? "L" : "R") + "=solid";
				}
				part.Prepare();
				part.Mesh.vertices = part.Rest;
				part.Mesh.uv = array;
				part.Mesh.RecalculateNormals();
				part.Mesh.RecalculateTangents();
			}
			return text;
		}

		private static (float, float, float, float, float) Settings()
		{
			return (Plugin.Size.Value, Plugin.Inflate.Value, Plugin.Spacing.Value, Plugin.Up.Value, Plugin.Forward.Value);
		}

		private static Vector3 Inflated(Shape s, Vector3 v, float w, float inflate)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = v - s.Mass;
			float magnitude = ((Vector3)(ref val)).magnitude;
			float num = w * Mathf.Min(0.7f, (inflate - 1f) * 1.5f);
			if (magnitude > 1E-06f)
			{
				val *= 1f - num + num * s.BallRadius / magnitude;
			}
			float num2 = (inflate - 1f) * w;
			return s.Mass + Vector3.Scale(val, new Vector3(1f + 0.35f * num2, 1f + 0.9f * num2, 1f + 0.55f * num2));
		}

		private float SkinAt(float qx, float qy, float cx, float cy, float surface, float size)
		{
			if (chest == null)
			{
				return surface;
			}
			for (float num = 1f; num >= 0f; num -= 0.2f)
			{
				float num2 = chest.Height(Mathf.Lerp(cx, qx, num), Mathf.Lerp(cy, qy, num));
				if (!float.IsNaN(num2))
				{
					return Mathf.Clamp(num2, surface - 1.5f * size, surface + 0.2f * size);
				}
			}
			return surface;
		}

		private void OnDestroy()
		{
			all.Remove(this);
			Part[] array = parts;
			foreach (Part part in array)
			{
				if (Object.op_Implicit((Object)(object)part.Mesh))
				{
					Object.Destroy((Object)(object)part.Mesh);
				}
			}
		}

		private void LateUpdate()
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: 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_01ee: 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_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: 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_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: 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_024b: 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_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: 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_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: 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_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Min(Time.deltaTime, 0.05f);
			if (num <= 0f)
			{
				return;
			}
			Camera main = Camera.main;
			if (((Renderer)((Component)parts[0].T).GetComponent<MeshRenderer>()).isVisible || ((Renderer)((Component)parts[1].T).GetComponent<MeshRenderer>()).isVisible)
			{
				Vector3 val;
				if ((Object)(object)main != (Object)null)
				{
					val = ((Component)main).transform.position - ((Component)this).transform.position;
					if (((Vector3)(ref val)).sqrMagnitude > 6400f)
					{
						goto IL_0085;
					}
				}
				(float, float, float, float, float) tuple = Settings();
				(float, float, float, float, float) tuple2 = measuredFor;
				if (tuple.Item1 != tuple2.Item1 || tuple.Item2 != tuple2.Item2 || tuple.Item3 != tuple2.Item3 || tuple.Item4 != tuple2.Item4 || tuple.Item5 != tuple2.Item5)
				{
					Measure();
				}
				float x = ((Component)this).transform.lossyScale.x;
				int steps = Mathf.Max(1, Mathf.CeilToInt(num * 120f));
				Matrix4x4 worldToLocalMatrix = ((Component)this).transform.worldToLocalMatrix;
				Matrix4x4 localToWorldMatrix = ((Component)this).transform.localToWorldMatrix;
				Vector3 position = ((Component)this).transform.position;
				int num2;
				if (primed)
				{
					val = position - prevOrigin;
					num2 = ((((Vector3)(ref val)).sqrMagnitude > 25f * x * x) ? 1 : 0);
				}
				else
				{
					num2 = 1;
				}
				bool flag = (byte)num2 != 0;
				if (fla