Decompiled source of HumanoidEnemies v1.0.1

plugins/HumanoidSoldier/HumanoidSoldier.dll

Decompiled 12 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using FistVR;
using HarmonyLib;
using HumanoidSoldier.Dev;
using HumanoidSoldier.Soldier;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
using Valve.Newtonsoft.Json;
using Valve.Newtonsoft.Json.Linq;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("HumanoidSoldier")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+80f48a607441334d7755d065b0bb65f2b5bdedd5")]
[assembly: AssemblyProduct("HumanoidSoldier")]
[assembly: AssemblyTitle("HumanoidSoldier")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 HumanoidSoldier
{
	[BepInPlugin("sorcerio.humanoidsoldier", "Humanoid Soldier", "1.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "sorcerio.humanoidsoldier";

		public const string Name = "Humanoid Soldier";

		public const string Version = "1.0.1";

		internal static Plugin Instance;

		internal static ManualLogSource Log;

		private Harmony _harmony;

		private FileSystemWatcher _configWatcher;

		private volatile bool _configChanged;

		private void Awake()
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			DevSettings.Bind(((BaseUnityPlugin)this).Config);
			SoldierSettings.Bind(((BaseUnityPlugin)this).Config);
			SoldierAssets.Load();
			SoldierRagdoll.Layers(on: true);
			_configWatcher = new FileSystemWatcher(Path.GetDirectoryName(((BaseUnityPlugin)this).Config.ConfigFilePath), Path.GetFileName(((BaseUnityPlugin)this).Config.ConfigFilePath));
			_configWatcher.Changed += delegate
			{
				_configChanged = true;
			};
			_configWatcher.EnableRaisingEvents = true;
			_harmony = new Harmony("sorcerio.humanoidsoldier");
			_harmony.PatchAll(typeof(Plugin).Assembly);
			if (DevSettings.EnableDumps.Value)
			{
				((MonoBehaviour)this).StartCoroutine(ArmorCensus.Run());
			}
			if (DevSettings.AutopilotScene.Value != "")
			{
				((Component)this).gameObject.AddComponent<Autopilot>();
			}
			Log.LogInfo((object)"Humanoid Soldier 1.0.1 loaded");
		}

		private void Start()
		{
			Patches patchInfo = Harmony.GetPatchInfo((MethodBase)AccessTools.Method(typeof(Sosig), "Start", (Type[])null, (Type[])null));
			Log.LogInfo((object)$"Sosig.Start postfixes: {patchInfo?.Postfixes.Count ?? 0}");
		}

		private void Update()
		{
			if (_configChanged)
			{
				_configChanged = false;
				((BaseUnityPlugin)this).Config.Reload();
			}
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			_configWatcher?.Dispose();
			SoldierBody.DestroyAll();
			SoldierRagdoll.Layers(on: false);
			SoldierGore.Unload();
			SoldierAssets.Unload();
		}
	}
}
namespace HumanoidSoldier.Soldier
{
	internal static class ArmorLayers
	{
		public enum Tier
		{
			None,
			Mask,
			Light,
			Medium,
			Heavy
		}

		public struct Piece
		{
			public Vector3 Min;

			public Vector3 Max;

			public Tier Tier;

			public Piece(Vector3 min, Vector3 max, Tier tier)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				Min = min;
				Max = max;
				Tier = tier;
			}
		}

		public struct Coverage
		{
			public bool Covered;

			public Tier Tier;
		}

		private const float WrapShare = 0.8f;

		private const float ZoneShare = 0.5f;

		private const float Slack = 0.02f;

		private const float BackEdge = -0.05f;

		public static readonly Vector3[] Around = Ring(0.15f, 8, -0.2f, 0f, 0.2f);

		public static readonly Vector3[] Crown = Join((Vector3[])(object)new Vector3[1]
		{
			new Vector3(0f, 0.29f, 0f)
		}, Ring(0.13f, 8, 0.22f));

		public static readonly Vector3[] Brim = Ring(0.2f, 8, 0.17f);

		public static readonly Vector3[] Face = Front(0.15f, 35f, -0.12f, -0.04f);

		public static readonly Vector3[] Eyes = Front(0.15f, 35f, 0.07f);

		public static readonly Vector3[] LeftShoulder = (Vector3[])(object)new Vector3[1]
		{
			new Vector3(-0.15f, 0.15f, 0f)
		};

		public static readonly Vector3[] RightShoulder = (Vector3[])(object)new Vector3[1]
		{
			new Vector3(0.15f, 0.15f, 0f)
		};

		public static readonly Vector3[] Back = (Vector3[])(object)new Vector3[1]
		{
			new Vector3(0f, 0.05f, -0.25f)
		};

		public static bool Wraps(Piece piece)
		{
			return Reach(new Piece[1] { piece }, Around, 0.8f).Covered;
		}

		public static Tier Shell(IList<Piece> pieces)
		{
			return Reach(pieces, Around, 0.8f).Tier;
		}

		public static List<Piece> Partial(IList<Piece> pieces)
		{
			List<Piece> list = new List<Piece>();
			foreach (Piece piece in pieces)
			{
				if (!Wraps(piece))
				{
					list.Add(piece);
				}
			}
			return list;
		}

		public static void SplitBack(IList<Piece> pieces, out List<Piece> front, out List<Piece> back)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			front = new List<Piece>();
			back = new List<Piece>();
			foreach (Piece piece in pieces)
			{
				((piece.Max.z < -0.05f) ? back : front).Add(piece);
			}
		}

		public static List<Piece> AtLeast(IList<Piece> pieces, Tier tier)
		{
			List<Piece> list = new List<Piece>();
			foreach (Piece piece in pieces)
			{
				if (piece.Tier >= tier)
				{
					list.Add(piece);
				}
			}
			return list;
		}

		public static Tier Strongest(IList<Piece> pieces)
		{
			Tier tier = Tier.None;
			foreach (Piece piece in pieces)
			{
				if (piece.Tier > tier)
				{
					tier = piece.Tier;
				}
			}
			return tier;
		}

		public static Coverage Zone(IList<Piece> pieces, Vector3[] spots)
		{
			return Reach(pieces, spots, 0.5f);
		}

		private static Coverage Reach(IList<Piece> pieces, Vector3[] spots, float share)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			int[] array = new int[spots.Length];
			for (int i = 0; i < spots.Length; i++)
			{
				array[i] = -1;
				foreach (Piece piece in pieces)
				{
					if ((int)piece.Tier > array[i] && Contains(piece, spots[i]))
					{
						array[i] = (int)piece.Tier;
					}
				}
			}
			float num = share * (float)spots.Length;
			Coverage result = new Coverage
			{
				Covered = ((float)Count(array, 0) >= num)
			};
			for (Tier tier = Tier.Mask; tier <= Tier.Heavy; tier++)
			{
				if ((float)Count(array, (int)tier) >= num)
				{
					result.Tier = tier;
				}
			}
			return result;
		}

		private static int Count(int[] best, int atLeast)
		{
			int num = 0;
			foreach (int num2 in best)
			{
				num += ((num2 >= atLeast) ? 1 : 0);
			}
			return num;
		}

		private static bool Contains(Piece piece, Vector3 spot)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			if (spot.x >= piece.Min.x - 0.02f && spot.x <= piece.Max.x + 0.02f && spot.y >= piece.Min.y - 0.02f && spot.y <= piece.Max.y + 0.02f && spot.z >= piece.Min.z - 0.02f)
			{
				return spot.z <= piece.Max.z + 0.02f;
			}
			return false;
		}

		private static Vector3[] Ring(float radius, int count, params float[] heights)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			foreach (float num in heights)
			{
				for (int j = 0; j < count; j++)
				{
					float num2 = (float)j * (float)Math.PI * 2f / (float)count;
					list.Add(new Vector3(Mathf.Sin(num2) * radius, num, Mathf.Cos(num2) * radius));
				}
			}
			return list.ToArray();
		}

		private static Vector3[] Front(float radius, float spread, params float[] heights)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			foreach (float num in heights)
			{
				float[] array = new float[3]
				{
					0f - spread,
					0f,
					spread
				};
				for (int j = 0; j < array.Length; j++)
				{
					float num2 = array[j] * ((float)Math.PI / 180f);
					list.Add(new Vector3(Mathf.Sin(num2) * radius, num, Mathf.Cos(num2) * radius));
				}
			}
			return list.ToArray();
		}

		private static Vector3[] Join(Vector3[] first, Vector3[] second)
		{
			List<Vector3> list = new List<Vector3>(first);
			list.AddRange(second);
			return list.ToArray();
		}
	}
	internal static class BodyHitboxes
	{
		private struct Core
		{
			public string Bone;

			public Vector3 Start;

			public Vector3 End;

			public float Radius;

			public SosigBodyPart Part;
		}

		private struct Fit
		{
			public SosigBodyPart Part;

			public Vector3 Center;

			public Vector3 Scale;

			public string[] Bones;
		}

		private static readonly Core Head = new Core
		{
			Bone = "head",
			Start = new Vector3(0f, 1.64f, 0.055f),
			End = new Vector3(0f, 1.72f, 0.055f),
			Radius = 0.095f,
			Part = (SosigBodyPart)0
		};

		private static readonly Core Neck = new Core
		{
			Bone = "neck_01",
			Start = new Vector3(0f, 1.5f, 0f),
			End = new Vector3(0f, 1.585f, 0f),
			Radius = 0.055f,
			Part = (SosigBodyPart)1
		};

		private static readonly Core[] Trunk = new Core[3]
		{
			new Core
			{
				Bone = "spine_03",
				Start = new Vector3(-0.08f, 1.36f, 0f),
				End = new Vector3(0.08f, 1.36f, 0f),
				Radius = 0.13f,
				Part = (SosigBodyPart)1
			},
			new Core
			{
				Bone = "spine_01",
				Start = new Vector3(-0.06f, 1.13f, 0f),
				End = new Vector3(0.06f, 1.13f, 0f),
				Radius = 0.13f,
				Part = (SosigBodyPart)1
			},
			new Core
			{
				Bone = "pelvis",
				Start = new Vector3(-0.06f, 0.95f, 0f),
				End = new Vector3(0.06f, 0.95f, 0f),
				Radius = 0.125f,
				Part = (SosigBodyPart)2
			}
		};

		private static readonly Core[] TrunkShells = new Core[5]
		{
			new Core
			{
				Bone = "spine_02",
				Start = new Vector3(-0.07f, 1.15f, 0f),
				End = new Vector3(-0.07f, 1.335f, 0f),
				Radius = 0.155f,
				Part = (SosigBodyPart)1
			},
			new Core
			{
				Bone = "spine_02",
				Start = new Vector3(0f, 1.15f, 0f),
				End = new Vector3(0f, 1.335f, 0f),
				Radius = 0.155f,
				Part = (SosigBodyPart)1
			},
			new Core
			{
				Bone = "spine_02",
				Start = new Vector3(0.07f, 1.15f, 0f),
				End = new Vector3(0.07f, 1.335f, 0f),
				Radius = 0.155f,
				Part = (SosigBodyPart)1
			},
			new Core
			{
				Bone = "pelvis",
				Start = new Vector3(-0.06f, 0.9f, 0f),
				End = new Vector3(-0.06f, 0.95f, 0f),
				Radius = 0.14f,
				Part = (SosigBodyPart)2
			},
			new Core
			{
				Bone = "pelvis",
				Start = new Vector3(0.06f, 0.9f, 0f),
				End = new Vector3(0.06f, 0.95f, 0f),
				Radius = 0.14f,
				Part = (SosigBodyPart)2
			}
		};

		private static readonly Fit[] Fits = new Fit[4]
		{
			new Fit
			{
				Part = (SosigBodyPart)0,
				Center = new Vector3(0f, 1.685f, 0.04f),
				Scale = new Vector3(0.85f, 0.55f, 0.85f),
				Bones = new string[1] { "head" }
			},
			new Fit
			{
				Part = (SosigBodyPart)1,
				Center = new Vector3(0f, 1.245f, 0f),
				Scale = new Vector3(1.4f, 0.83f, 1f),
				Bones = new string[2] { "spine_03", "spine_01" }
			},
			new Fit
			{
				Part = (SosigBodyPart)2,
				Center = new Vector3(0f, 0.8f, 0f),
				Scale = new Vector3(1.27f, 0.88f, 0.9f),
				Bones = new string[3] { "pelvis", "thigh_l", "thigh_r" }
			},
			new Fit
			{
				Part = (SosigBodyPart)3,
				Center = new Vector3(0f, 0.33f, 0f),
				Scale = new Vector3(1.4f, 0.65f, 0.6f),
				Bones = new string[2] { "calf_l", "calf_r" }
			}
		};

		public static SoldierHitbox Add(Transform soldier, Dictionary<string, Transform> bones, Sosig sosig, Dictionary<string, GearRules.Region> covered, SoldierArmor armor)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00d0: 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_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			SoldierHitbox result = Wrap(soldier, bones, Head, sosig, armor.Shell(Head.Part));
			Wrap(soldier, bones, Neck, sosig, covered.TryGetValue(Neck.Bone, out var value) ? armor.Covering(value) : default(SoldierArmor.Worn));
			Core[] trunk = Trunk;
			foreach (Core core in trunk)
			{
				Wrap(soldier, bones, core, sosig, default(SoldierArmor.Worn));
			}
			trunk = TrunkShells;
			for (int i = 0; i < trunk.Length; i++)
			{
				Core core2 = trunk[i];
				SoldierHitbox.Shell(bones[core2.Bone], soldier.TransformPoint(core2.Start), soldier.TransformPoint(core2.End), core2.Radius, sosig, core2.Part, armor.Shell(core2.Part), limb: false);
			}
			Fit[] fits = Fits;
			for (int i = 0; i < fits.Length; i++)
			{
				Fit fit = fits[i];
				foreach (SoldierArmor.Plate item in armor.Plates(fit.Part))
				{
					SoldierHitbox.Plate(FitFrame(soldier, bones, fit, item), item, sosig, fit.Part);
				}
			}
			return result;
		}

		public static Vector3 Map(Transform link, SosigBodyPart part, Vector3 local)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			Fit fit = Array.Find(Fits, (Fit candidate) => candidate.Part == part);
			return link.TransformPoint(fit.Center - Vector3.up * SoldierRig.LinkHeights[part] + Vector3.Scale(local, fit.Scale));
		}

		private static SoldierHitbox Wrap(Transform soldier, Dictionary<string, Transform> bones, Core core, Sosig sosig, SoldierArmor.Worn armor)
		{
			//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_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			return SoldierHitbox.Wrap(bones[core.Bone], soldier.TransformPoint(core.Start), soldier.TransformPoint(core.End), core.Radius, sosig, core.Part, armor, limb: false);
		}

		private static Transform FitFrame(Transform soldier, Dictionary<string, Transform> bones, Fit fit, SoldierArmor.Plate plate)
		{
			//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_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_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_002c: 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_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00f1: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = soldier.TransformPoint(fit.Center);
			Transform link = plate.Link;
			Bounds bounds = plate.Collider.bounds;
			Vector3 val2 = link.InverseTransformPoint(((Bounds)(ref bounds)).center);
			Vector3 val3 = val + soldier.rotation * Vector3.Scale(val2, fit.Scale);
			Transform val4 = bones[fit.Bones[0]];
			string[] bones2 = fit.Bones;
			foreach (string key in bones2)
			{
				if (Vector3.Distance(bones[key].position, val3) < Vector3.Distance(val4.position, val3))
				{
					val4 = bones[key];
				}
			}
			GameObject val5 = new GameObject("ArmorFit");
			val5.transform.SetParent(val4, false);
			val5.transform.position = val;
			val5.transform.rotation = soldier.rotation;
			val5.transform.localScale = fit.Scale / val4.lossyScale.x;
			return val5.transform;
		}
	}
	internal static class Capsules
	{
		public static bool Inside(CapsuleCollider capsule, Vector3 point, float margin, out Vector3 clear)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			Core(capsule, out var start, out var end);
			Vector3 val = Nearest(start, end, point);
			Vector3 val2 = point - val;
			float num = capsule.radius * ((Component)capsule).transform.lossyScale.x + margin;
			if (((Vector3)(ref val2)).sqrMagnitude >= num * num)
			{
				clear = point;
				return false;
			}
			clear = val + ((((Vector3)(ref val2)).sqrMagnitude > 1E-06f) ? ((Vector3)(ref val2)).normalized : ((Component)capsule).transform.forward) * num;
			return true;
		}

		public static bool Crosses(CapsuleCollider capsule, Vector3 from, Vector3 to, float margin)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//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_0028: 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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_004c: 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_004e: 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_0064: 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_0067: 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_0072: Unknown result type (might be due to invalid IL or missing references)
			Core(capsule, out var start, out var end);
			float num = capsule.radius * ((Component)capsule).transform.lossyScale.x + margin;
			Vector3 val = Nearest(from, to, Nearest(start, end, (from + to) * 0.5f));
			for (int i = 0; i < 4; i++)
			{
				val = Nearest(from, to, Nearest(start, end, val));
			}
			Vector3 val2 = val - Nearest(start, end, val);
			return ((Vector3)(ref val2)).sqrMagnitude < num * num;
		}

		private static void Core(CapsuleCollider capsule, out Vector3 start, out Vector3 end)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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_0011: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((capsule.direction == 0) ? Vector3.right : ((capsule.direction == 1) ? Vector3.up : Vector3.forward)) * Mathf.Max(0f, capsule.height * 0.5f - capsule.radius);
			start = ((Component)capsule).transform.TransformPoint(capsule.center - val);
			end = ((Component)capsule).transform.TransformPoint(capsule.center + val);
		}

		private static Vector3 Nearest(Vector3 start, Vector3 end, Vector3 point)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = end - start;
			float num = Mathf.Clamp01(Vector3.Dot(point - start, val) / Mathf.Max(((Vector3)(ref val)).sqrMagnitude, 1E-06f));
			return start + val * num;
		}
	}
	internal static class Eligibility
	{
		private static readonly string[] AllowedPrefabs = new string[2] { "SosigBody", "SosigBody_Operator" };

		public static string PrefabName(Sosig sosig)
		{
			return ((Object)((Component)sosig).transform.root).name.Replace("(Clone)", "").Trim();
		}

		public static bool IsEligible(Sosig sosig)
		{
			return Array.IndexOf(AllowedPrefabs, PrefabName(sosig)) >= 0;
		}
	}
	internal static class Floor
	{
		private static readonly int Mask = LayerMask.GetMask(new string[2] { "Default", "Environment" });

		public static bool Cast(Vector3 origin, Vector3 direction, float distance, out RaycastHit hit)
		{
			//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)
			return Physics.Raycast(origin, direction, ref hit, distance, Mask, (QueryTriggerInteraction)1);
		}
	}
	internal static class GearRules
	{
		public enum Region
		{
			Head,
			Torso,
			Legs
		}

		public struct Reading
		{
			public ArmorLayers.Coverage Crown;

			public ArmorLayers.Coverage Brim;

			public ArmorLayers.Coverage Face;

			public ArmorLayers.Coverage Eyes;

			public ArmorLayers.Tier TorsoShell;

			public ArmorLayers.Tier TorsoPlates;

			public bool LeftShoulder;

			public bool RightShoulder;

			public bool Backpack;

			public bool Pouches;

			public ArmorLayers.Tier UpperShell;

			public ArmorLayers.Tier LowerShell;

			public ArmorLayers.Tier LegPlates;

			public override string ToString()
			{
				return string.Format("head crown {0}{1} face {2} eyes {3}, torso shell {4} plates {5}, legs shells {6}/{7} plates {8}", Crown.Tier, (Crown.Covered || Brim.Covered) ? " hat" : "", Face.Tier, Eyes.Tier, TorsoShell, TorsoPlates, UpperShell, LowerShell, LegPlates);
			}
		}

		public const int Head = 0;

		public const int Torso = 1;

		public const int Upper = 2;

		public const int Lower = 3;

		public static Reading Read(IList<ArmorLayers.Piece>[] links)
		{
			ArmorLayers.SplitBack(ArmorLayers.Partial(links[1]), out var front, out var back);
			List<ArmorLayers.Piece> pieces = ArmorLayers.AtLeast(front, ArmorLayers.Tier.Medium);
			List<ArmorLayers.Piece> list = ArmorLayers.Partial(links[2]);
			list.AddRange(ArmorLayers.Partial(links[3]));
			List<ArmorLayers.Piece> list2 = new List<ArmorLayers.Piece>(front);
			list2.AddRange(list);
			return new Reading
			{
				Crown = ArmorLayers.Zone(links[0], ArmorLayers.Crown),
				Brim = ArmorLayers.Zone(links[0], ArmorLayers.Brim),
				Face = ArmorLayers.Zone(links[0], ArmorLayers.Face),
				Eyes = ArmorLayers.Zone(links[0], ArmorLayers.Eyes),
				TorsoShell = ArmorLayers.Shell(links[1]),
				TorsoPlates = ArmorLayers.Strongest(front),
				LeftShoulder = ArmorLayers.Zone(pieces, ArmorLayers.LeftShoulder).Covered,
				RightShoulder = ArmorLayers.Zone(pieces, ArmorLayers.RightShoulder).Covered,
				Backpack = ArmorLayers.Zone(back, ArmorLayers.Back).Covered,
				Pouches = list2.Exists((ArmorLayers.Piece piece) => piece.Tier == ArmorLayers.Tier.Light),
				UpperShell = ArmorLayers.Shell(links[2]),
				LowerShell = ArmorLayers.Shell(links[3]),
				LegPlates = ArmorLayers.Strongest(list)
			};
		}

		public static List<string> Keys(Region region, Reading reading)
		{
			return region switch
			{
				Region.Head => HeadKeys(reading), 
				Region.Torso => TorsoKeys(reading), 
				_ => LegKeys(reading), 
			};
		}

		private static List<string> HeadKeys(Reading reading)
		{
			List<string> list = new List<string>();
			ArmorLayers.Tier tier = ((reading.Crown.Covered && reading.Crown.Tier >= ArmorLayers.Tier.Light) ? reading.Crown.Tier : ArmorLayers.Tier.None);
			bool flag = reading.Crown.Covered || reading.Brim.Covered;
			bool flag2 = reading.Face.Covered && reading.Face.Tier >= ArmorLayers.Tier.Light;
			bool flag3 = reading.Face.Covered && reading.Face.Tier == ArmorLayers.Tier.Mask;
			bool flag4 = reading.Eyes.Covered && reading.Eyes.Tier >= ArmorLayers.Tier.Mask && !flag2 && !flag3;
			switch (tier)
			{
			case ArmorLayers.Tier.Heavy:
				list.Add("Heavy");
				if (flag2 || flag4)
				{
					list.Add("Visor");
				}
				if (flag3)
				{
					list.Add("Mask");
				}
				return list;
			default:
				list.Add(tier.ToString() + (flag4 ? "Goggles" : ""));
				break;
			case ArmorLayers.Tier.None:
				list.Add(flag ? "Hat" : "Bare");
				if (flag4)
				{
					list.Add("Goggles");
				}
				break;
			}
			if (flag2)
			{
				list.Add("FaceArmor");
			}
			else if (flag3)
			{
				list.Add("Mask");
			}
			return list;
		}

		private static List<string> TorsoKeys(Reading reading)
		{
			List<string> list = new List<string>();
			bool num = reading.TorsoShell >= ArmorLayers.Tier.Medium || reading.TorsoPlates >= ArmorLayers.Tier.Medium;
			bool flag = reading.TorsoShell == ArmorLayers.Tier.Heavy;
			if (num)
			{
				list.Add("Hard");
				if (reading.UpperShell >= ArmorLayers.Tier.Light)
				{
					list.Add("Bottom");
				}
				if (flag)
				{
					list.Add("Collar");
				}
				if (flag || reading.LeftShoulder)
				{
					list.Add("ShoulderLeft");
				}
				if (flag || reading.RightShoulder)
				{
					list.Add("ShoulderRight");
				}
			}
			else if (reading.TorsoShell >= ArmorLayers.Tier.Light)
			{
				list.Add("Soft");
			}
			else if (reading.Pouches)
			{
				list.Add("Pouches");
			}
			if (reading.Backpack)
			{
				list.Add("Backpack");
			}
			return list;
		}

		private static List<string> LegKeys(Reading reading)
		{
			List<string> list = new List<string>();
			if (reading.UpperShell >= ArmorLayers.Tier.Medium || reading.LowerShell >= ArmorLayers.Tier.Medium || reading.LegPlates >= ArmorLayers.Tier.Medium)
			{
				list.Add("Armored");
			}
			return list;
		}
	}
	internal static class HitReactions
	{
		public enum Reaction
		{
			None,
			Flinch,
			Stagger
		}

		private const float MaxStrength = 3f;

		private const float Least = 0.02f;

		public static float Strength(float kinetic, float energyScale)
		{
			if (energyScale <= 0f || kinetic <= 0f)
			{
				return 0f;
			}
			float num = kinetic / energyScale;
			if (!(num > 3f))
			{
				return num;
			}
			return 3f;
		}

		public static float Flinch(float strength, bool armored, float armorFlinch)
		{
			if (!armored)
			{
				return strength;
			}
			return strength * armorFlinch;
		}

		public static Reaction Classify(float strength, float staggerAt)
		{
			if (strength < 0.02f)
			{
				return Reaction.None;
			}
			if (!(strength >= staggerAt))
			{
				return Reaction.Flinch;
			}
			return Reaction.Stagger;
		}
	}
	internal class Pendulum
	{
		private const float Gravity = 9.81f;

		private const float Damping = 3f;

		private bool _swinging;

		private Vector3 _direction;

		private Vector3 _velocity;

		private Quaternion _rotation;

		public void Reset()
		{
			_swinging = false;
		}

		public Quaternion Swing(Transform bone, Vector3 tip, float deltaTime, float stiffness)
		{
			//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_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: 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_0061: 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_006d: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00c6: 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_00d3: 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_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00f3: 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_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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = bone.position;
			Vector3 val = tip - position;
			float magnitude = ((Vector3)(ref val)).magnitude;
			if (magnitude < 0.001f)
			{
				return bone.rotation;
			}
			Vector3 val2 = val / magnitude;
			if (!_swinging)
			{
				_swinging = true;
				_direction = val2;
				_velocity = Vector3.zero;
				_rotation = bone.rotation;
			}
			Vector3 direction = _direction;
			Vector3 val3 = Vector3.ProjectOnPlane(Vector3.down * 9.81f / magnitude + (val2 - _direction) * stiffness, _direction) - _velocity * 3f;
			_velocity += val3 * deltaTime;
			Vector3 val4 = _direction + _velocity * deltaTime;
			_direction = ((Vector3)(ref val4)).normalized;
			_velocity = Vector3.ProjectOnPlane(_velocity, _direction);
			if (stiffness > 0f)
			{
				_rotation = Quaternion.FromToRotation(val2, _direction) * bone.rotation;
			}
			else
			{
				_rotation = Quaternion.FromToRotation(direction, _direction) * _rotation;
			}
			return _rotation;
		}
	}
	internal class SoldierArm : SoldierLimb
	{
		public enum Grip
		{
			Gun,
			Fist,
			Fore,
			Cup,
			Backhand
		}

		private struct Shape
		{
			public readonly Vector3 Tilt;

			public readonly Vector3 Drop;

			public readonly Vector3 Shift;

			public readonly Vector3 Thumb;

			public readonly Vector3 Index;

			public readonly Vector3 Fingers;

			public Shape(Vector3 tilt, Vector3 drop, Vector3 shift, Vector3 thumb, Vector3 index, Vector3 fingers)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: 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_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				Tilt = tilt;
				Drop = drop;
				Shift = shift;
				Thumb = thumb;
				Index = index;
				Fingers = fingers;
			}
		}

		private static readonly Vector3 GunIndex = new Vector3(25f, 30f, 15f);

		private static readonly Vector3 Wrap = new Vector3(75f, 85f, 55f);

		private static readonly Vector3 LightWrap = new Vector3(55f, 65f, 40f);

		private static readonly Vector3 ThumbWrap = new Vector3(20f, 30f, 20f);

		private static readonly Shape[] Shapes = new Shape[5]
		{
			new Shape(new Vector3(62.7f, 10.4f, 7.7f), new Vector3(0f, -0.7f, -1.2f), new Vector3(0.03f, 0.065f, -0.06f), ThumbWrap, GunIndex, Wrap),
			new Shape(new Vector3(90f, 0f, 0f), new Vector3(0f, 0f, -0.5f), Vector3.zero, ThumbWrap, Wrap, Wrap),
			new Shape(new Vector3(-5.6f, -68.6f, -79.2f), new Vector3(0f, -0.7f, -1.2f), new Vector3(0.01f, 0.005f, 0.09f), ThumbWrap, LightWrap, LightWrap),
			new Shape(new Vector3(62.7f, 10.4f, -32.3f), new Vector3(0f, -0.7f, -1.2f), new Vector3(0.03f, 0.045f, -0.06f), ThumbWrap, LightWrap, LightWrap),
			new Shape(new Vector3(90f, 0f, 180f), new Vector3(0f, 0f, -0.5f), Vector3.zero, ThumbWrap, Wrap, Wrap)
		};

		private static readonly string[] FingerNames = new string[5] { "thumb", "index", "middle", "ring", "pinky" };

		private const int FingerJoints = 3;

		private static readonly Vector3 ElbowHint = new Vector3(0.6f, -1f, -0.4f);

		private static readonly Vector3 SupportHint = new Vector3(0.3f, -1f, 0.2f);

		private const float TrunkClearance = 0.05f;

		private const float SwingStep = 20f;

		private const int SwingTries = 8;

		private const float ShrugShare = 0.25f;

		private readonly Transform _clavicle;

		private readonly Quaternion _clavicleRest;

		private const float FistSpans = 1.5f;

		private readonly Vector3 _gripPosition;

		private readonly Quaternion _gripRotation;

		private readonly float _fistHeight;

		private readonly Vector3[] _curlAxes;

		public CapsuleCollider[] Trunk { get; set; }

		protected override float SwayStiffness => SoldierSettings.ArmSway.Value;

		protected override float UpperRadius => 0.055f;

		protected override float LowerRadius => 0.045f;

		protected override SosigBodyPart UpperPart => (SosigBodyPart)1;

		protected override SosigBodyPart LowerPart => (SosigBodyPart)1;

		protected override bool WearsLinkArmor => false;

		public SoldierArm(Transform soldier, bool isRight)
			: base(isRight, SoldierRig.Find(soldier, "upperarm" + Side(isRight)), SoldierRig.Find(soldier, "lowerarm" + Side(isRight)), SoldierRig.Find(soldier, "hand" + Side(isRight)), FingerBones(soldier, Side(isRight)))
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: 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_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0173: 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_0191: 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_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_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			string text = Side(isRight);
			_clavicle = SoldierRig.Find(soldier, "clavicle" + text);
			_clavicleRest = _clavicle.localRotation;
			Vector3 position = SoldierRig.Find(soldier, "index_01" + text).position;
			Vector3 position2 = SoldierRig.Find(soldier, "middle_01" + text).position;
			Vector3 position3 = SoldierRig.Find(soldier, "pinky_01" + text).position;
			Quaternion val = Quaternion.Inverse(End.rotation);
			_gripPosition = val * ((position2 - End.position) * 0.5f);
			_gripRotation = val * Quaternion.LookRotation(position2 - End.position, position - position3);
			_fistHeight = Vector3.Distance(position, position3) * 1.5f;
			Vector3 val2 = position - position3;
			Vector3 val3 = ((Vector3)(ref val2)).normalized;
			if (Vector3.Dot(Bend(soldier, "middle", text), val3) < 0f)
			{
				val3 = -val3;
			}
			Vector3 val4 = Bend(soldier, "thumb", text);
			Vector3 val5 = ((((Vector3)(ref val4)).sqrMagnitude > 1E-08f) ? ((Vector3)(ref val4)).normalized : val3);
			_curlAxes = (Vector3[])(object)new Vector3[Extra.Length];
			for (int i = 0; i < Extra.Length; i++)
			{
				_curlAxes[i] = Quaternion.Inverse(Extra[i].rotation) * ((i < 3) ? val5 : val3);
			}
		}

		private static string Side(bool isRight)
		{
			if (!isRight)
			{
				return "_l";
			}
			return "_r";
		}

		private static Transform[] FingerBones(Transform soldier, string side)
		{
			Transform[] array = (Transform[])(object)new Transform[FingerNames.Length * 3];
			for (int i = 0; i < FingerNames.Length; i++)
			{
				for (int j = 0; j < 3; j++)
				{
					array[i * 3 + j] = SoldierRig.Find(soldier, FingerNames[i] + "_0" + (j + 1) + side);
				}
			}
			return array;
		}

		private static Vector3 Bend(Transform soldier, string finger, string side)
		{
			//IL_0012: 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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: 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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = SoldierRig.Find(soldier, finger + "_01" + side).position;
			Vector3 position2 = SoldierRig.Find(soldier, finger + "_02" + side).position;
			Vector3 position3 = SoldierRig.Find(soldier, finger + "_03" + side).position;
			return Vector3.Cross(position2 - position, position3 - position2);
		}

		public void Reach(Object holding, Vector3 position, Quaternion rotation, Quaternion item, Grip grip, Transform torso)
		{
			//IL_000e: 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_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_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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: 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_0072: 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_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_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: 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_0180: 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_0196: 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_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: 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_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_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: 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_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			Shape shape = Shapes[(int)grip];
			Vector3 val = shape.Shift + SoldierSettings.GripPosition[(int)grip].Value;
			Vector3 val2 = shape.Tilt;
			Vector3 val3 = SoldierSettings.GripRotation[(int)grip].Value;
			bool flag = grip == Grip.Fore || grip == Grip.Cup;
			Vector3 val4 = (flag ? SupportHint : ElbowHint);
			if (!IsRight)
			{
				val.x = 0f - val.x;
				val2 = Mirror(val2);
				val3 = Mirror(val3);
				val4.x = 0f - val4.x;
			}
			position += rotation * (shape.Drop * _fistHeight) + item * val;
			rotation = rotation * Quaternion.Euler(val2) * Quaternion.Euler(val3);
			Quaternion val5 = rotation * Quaternion.Inverse(_gripRotation);
			Vector3 val6 = position - val5 * _gripPosition;
			if (!flag || !(Vector3.Distance(Upper.position, val6) > Length * SoldierSettings.SupportReach.Value))
			{
				Transform val7 = ((Trunk != null && Trunk.Length != 0) ? ((Component)Trunk[0]).transform : torso);
				if (!flag || !(Vector3.Dot(val6 - val7.position, torso.forward) < 0f))
				{
					val6 = Clear(val6);
					_clavicle.rotation = Quaternion.Slerp(Quaternion.identity, Quaternion.FromToRotation(Upper.position - _clavicle.position, val6 - _clavicle.position), 0.25f) * _clavicle.rotation;
					Solve(val6, ClearElbow(val6, torso.rotation * val4));
					End.rotation = val5;
					Curl(shape);
					Place(holding, (int)grip);
				}
			}
		}

		public override void Rest()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			base.Rest();
			_clavicle.localRotation = _clavicleRest;
		}

		private Vector3 Clear(Vector3 point)
		{
			//IL_0008: 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_0023: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			if (Trunk == null)
			{
				return point;
			}
			CapsuleCollider[] trunk = Trunk;
			foreach (CapsuleCollider val in trunk)
			{
				if ((Object)(object)val != (Object)null && Capsules.Inside(val, point, 0.05f, out var clear))
				{
					point = clear;
				}
			}
			return point;
		}

		private bool Crosses(Vector3 from, Vector3 to)
		{
			//IL_0023: 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)
			if (Trunk == null)
			{
				return false;
			}
			CapsuleCollider[] trunk = Trunk;
			foreach (CapsuleCollider val in trunk)
			{
				if ((Object)(object)val != (Object)null && Capsules.Crosses(val, from, to, 0.05f))
				{
					return true;
				}
			}
			return false;
		}

		private Vector3 ClearElbow(Vector3 wrist, Vector3 hint)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_004c: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_007a: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = wrist - Upper.position;
			for (int i = 0; i <= 8; i++)
			{
				float[] array = new float[2] { 1f, -1f };
				for (int j = 0; j < array.Length; j++)
				{
					Vector3 val2 = Quaternion.AngleAxis(array[j] * (float)i * 20f, val) * hint;
					Vector3 direction;
					float reach;
					Vector3 val3 = Middle(wrist, val2, out direction, out reach);
					if (!Crosses(Upper.position, val3) && !Crosses(val3, wrist))
					{
						return val2;
					}
					if (i == 0)
					{
						break;
					}
				}
			}
			return hint;
		}

		private void Curl(Shape shape)
		{
			//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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: 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_001b: Unknown result type (might be due to invalid IL or missing references)
			float value = SoldierSettings.FingerCurl.Value;
			for (int i = 0; i < Extra.Length; i++)
			{
				Vector3 val = (Vector3)((i / 3) switch
				{
					1 => shape.Index, 
					0 => shape.Thumb, 
					_ => shape.Fingers, 
				});
				Transform obj = Extra[i];
				obj.localRotation *= Quaternion.AngleAxis(((Vector3)(ref val))[i % 3] * value, _curlAxes[i]);
			}
		}

		private static Vector3 Mirror(Vector3 euler)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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)
			return new Vector3(euler.x, 0f - euler.y, 0f - euler.z);
		}
	}
	internal class SoldierArmor
	{
		public struct Worn
		{
			public SosigWearable Wearable;

			public PMat Material;

			public ArmorLayers.Tier Tier;
		}

		public struct Plate
		{
			public Collider Collider;

			public Transform Link;

			public Worn Armor;
		}

		private readonly List<ArmorLayers.Piece>[] _pieces = new List<ArmorLayers.Piece>[4];

		private readonly List<SosigWearable>[] _wearables = new List<SosigWearable>[4];

		private readonly List<PMat>[] _materials = new List<PMat>[4];

		private readonly List<Collider>[] _colliders = new List<Collider>[4];

		private readonly Transform[] _links = (Transform[])(object)new Transform[4];

		public GearRules.Reading Reading { get; private set; }

		public SoldierArmor(Sosig sosig)
		{
			for (int i = 0; i < _pieces.Length; i++)
			{
				_pieces[i] = new List<ArmorLayers.Piece>();
				_wearables[i] = new List<SosigWearable>();
				_materials[i] = new List<PMat>();
				_colliders[i] = new List<Collider>();
				if ((Object)(object)sosig.Links[i] != (Object)null)
				{
					_links[i] = ((Component)sosig.Links[i]).transform;
					Collect(sosig.Links[i], i);
				}
			}
			IList<ArmorLayers.Piece>[] pieces = _pieces;
			Reading = GearRules.Read(pieces);
		}

		public Worn Shell(SosigBodyPart part)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Expected I4, but got Unknown
			int num = (int)part;
			ArmorLayers.Tier tier = ArmorLayers.Shell(_pieces[num]);
			return Strongest(num, tier, tier);
		}

		public Worn Covering(GearRules.Region region)
		{
			int num = region switch
			{
				GearRules.Region.Torso => 1, 
				GearRules.Region.Head => 0, 
				_ => StrongerLeg(), 
			};
			Worn result = Shell((SosigBodyPart)num);
			if (!((Object)(object)result.Wearable != (Object)null))
			{
				return Strongest(num, ArmorLayers.Tier.Light, ArmorLayers.Tier.Heavy);
			}
			return result;
		}

		public List<Plate> Plates(SosigBodyPart part)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Expected I4, but got Unknown
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			int num = (int)part;
			Worn worn = Shell(part);
			List<Plate> list = new List<Plate>();
			for (int i = 0; i < _pieces[num].Count; i++)
			{
				if (!((Object)(object)_colliders[num][i] == (Object)null) && !((Object)(object)_links[num] == (Object)null) && ((Object)(object)worn.Wearable == (Object)null || _pieces[num][i].Tier > worn.Tier))
				{
					list.Add(new Plate
					{
						Collider = _colliders[num][i],
						Link = _links[num],
						Armor = Layer(num, i)
					});
				}
			}
			return list;
		}

		public static PMat Material(Collider collider)
		{
			PMat component = ((Component)collider).GetComponent<PMat>();
			if ((Object)(object)component == (Object)null && (Object)(object)collider.attachedRigidbody != (Object)null)
			{
				component = ((Component)collider.attachedRigidbody).GetComponent<PMat>();
			}
			return component;
		}

		private void Collect(SosigLink link, int index)
		{
			//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_0064: Unknown result type (might be due to invalid IL or missing references)
			foreach (KeyValuePair<SosigWearable, Collider> item in SosigColliders.Wearables(link))
			{
				if (Box(item.Value, ((Component)link).transform, out var min, out var max))
				{
					PMat val = Material(item.Value);
					ArmorLayers.Tier tier = (((Object)(object)val != (Object)null && (Object)(object)val.MatDef != (Object)null) ? MaterialTier(val.MatDef.BallisticType, item.Key, index == 0) : ArmorLayers.Tier.None);
					_pieces[index].Add(new ArmorLayers.Piece(min, max, tier));
					_wearables[index].Add(item.Key);
					_materials[index].Add(val);
					_colliders[index].Add(item.Value);
				}
			}
		}

		private Worn Strongest(int link, ArmorLayers.Tier lowest, ArmorLayers.Tier highest)
		{
			if (lowest < ArmorLayers.Tier.Light)
			{
				return default(Worn);
			}
			int num = -1;
			for (int i = 0; i < _pieces[link].Count; i++)
			{
				ArmorLayers.Piece piece = _pieces[link][i];
				if (piece.Tier >= lowest && piece.Tier <= highest && (num < 0 || piece.Tier > _pieces[link][num].Tier || (piece.Tier == _pieces[link][num].Tier && ArmorLayers.Wraps(piece) && !ArmorLayers.Wraps(_pieces[link][num]))))
				{
					num = i;
				}
			}
			if (num < 0)
			{
				return default(Worn);
			}
			return Layer(link, num);
		}

		private Worn Layer(int link, int piece)
		{
			return new Worn
			{
				Wearable = _wearables[link][piece],
				Material = _materials[link][piece],
				Tier = _pieces[link][piece].Tier
			};
		}

		private int StrongerLeg()
		{
			if (ArmorLayers.Shell(_pieces[2]) < ArmorLayers.Shell(_pieces[3]))
			{
				return 3;
			}
			return 2;
		}

		private static bool Box(Collider collider, Transform link, out Vector3 min, out Vector3 max)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			//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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: 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_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: 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_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: 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_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: 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_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)
			min = Vector3.one * float.MaxValue;
			max = Vector3.one * float.MinValue;
			Vector3 center;
			Vector3 val2;
			if (collider is CapsuleCollider)
			{
				CapsuleCollider val = (CapsuleCollider)collider;
				center = val.center;
				val2 = Vector3.one * val.radius;
				((Vector3)(ref val2))[val.direction] = Mathf.Max(val.height * 0.5f, val.radius);
			}
			else if (collider is SphereCollider)
			{
				SphereCollider val3 = (SphereCollider)collider;
				center = val3.center;
				val2 = Vector3.one * val3.radius;
			}
			else if (collider is BoxCollider)
			{
				BoxCollider val4 = (BoxCollider)collider;
				center = val4.center;
				val2 = val4.size * 0.5f;
			}
			else
			{
				if (!(collider is MeshCollider) || !((Object)(object)((MeshCollider)collider).sharedMesh != (Object)null))
				{
					return false;
				}
				Bounds bounds = ((MeshCollider)collider).sharedMesh.bounds;
				center = ((Bounds)(ref bounds)).center;
				val2 = ((Bounds)(ref bounds)).extents;
			}
			Vector3 val5 = default(Vector3);
			for (int i = 0; i < 8; i++)
			{
				((Vector3)(ref val5))..ctor(((i & 1) == 0) ? (-1f) : 1f, ((i & 2) == 0) ? (-1f) : 1f, ((i & 4) == 0) ? (-1f) : 1f);
				Vector3 val6 = link.InverseTransformPoint(((Component)collider).transform.TransformPoint(center + Vector3.Scale(val2, val5)));
				min = Vector3.Min(min, val6);
				max = Vector3.Max(max, val6);
			}
			return true;
		}

		private static ArmorLayers.Tier MaterialTier(MatBallisticType type, SosigWearable wearable, bool head)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Invalid comparison between Unknown and I4
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Invalid comparison between Unknown and I4
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			if ((int)type <= 61)
			{
				if ((int)type == 10)
				{
					if (!head || !(wearable.BluntDamageTransmission < 1f))
					{
						return ArmorLayers.Tier.None;
					}
					return ArmorLayers.Tier.Mask;
				}
				if ((int)type == 61)
				{
					return ArmorLayers.Tier.Medium;
				}
			}
			else
			{
				if ((int)type == 70)
				{
					return ArmorLayers.Tier.Heavy;
				}
				if ((int)type == 110)
				{
					return ArmorLayers.Tier.Light;
				}
			}
			return ArmorLayers.Tier.None;
		}
	}
	internal static class SoldierAssets
	{
		private const string BundleName = "humanoidsoldier";

		private const string PrefabPath = "Assets/Art/Soldier.prefab";

		private const string DataPath = "Assets/Soldier/soldier.json";

		private const string MaterialFolder = "Assets/Art/Materials/";

		private static AssetBundle Bundle;

		private static readonly Dictionary<PrimitiveType, Mesh> Primitives = new Dictionary<PrimitiveType, Mesh>();

		public static GameObject Prefab { get; private set; }

		public static JObject Data { get; private set; }

		public static bool Loaded => (Object)(object)Prefab != (Object)null;

		public static void Load()
		{
			string location = ((BaseUnityPlugin)Plugin.Instance).Info.Location;
			string text = Path.Combine((!string.IsNullOrEmpty(location)) ? Path.GetDirectoryName(location) : Path.Combine(Paths.BepInExRootPath, "scripts"), "humanoidsoldier");
			if (!File.Exists(text))
			{
				Plugin.Log.LogError((object)("Soldier bundle not found at " + text + "; Sosigs stay vanilla"));
				return;
			}
			Bundle = AssetBundle.LoadFromFile(text);
			Prefab = Bundle.LoadAsset<GameObject>("Assets/Art/Soldier.prefab");
			Data = JObject.Parse(Bundle.LoadAsset<TextAsset>("Assets/Soldier/soldier.json").text);
		}

		public static Material Material(string name)
		{
			return Bundle.LoadAsset<Material>("Assets/Art/Materials/" + name + ".mat");
		}

		public static Mesh Primitive(PrimitiveType type)
		{
			//IL_0005: 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_002b: Unknown result type (might be due to invalid IL or missing references)
			if (!Primitives.TryGetValue(type, out var value))
			{
				GameObject obj = GameObject.CreatePrimitive(type);
				value = obj.GetComponent<MeshFilter>().sharedMesh;
				Object.DestroyImmediate((Object)(object)obj);
				Primitives[type] = value;
			}
			return value;
		}

		public static void Unload()
		{
			if ((Object)(object)Bundle != (Object)null)
			{
				Bundle.Unload(true);
			}
			Bundle = null;
			Prefab = null;
			Data = null;
		}
	}
	internal class SoldierBody : MonoBehaviour
	{
		private static readonly Color GhostColor = new Color(1f, 0.45f, 0.2f, 0.25f);

		private static readonly int[] JoinedTo = new int[4] { 1, -1, 1, 2 };

		private const float ProjectionDistance = 0.03f;

		private static readonly Dictionary<Sosig, SoldierBody> Bodies = new Dictionary<Sosig, SoldierBody>();

		private Sosig _sosig;

		private SoldierArmor _armor;

		private int _seed;

		private readonly Dictionary<int, SoldierPiece> _pieces = new Dictionary<int, SoldierPiece>();

		private readonly Dictionary<int, bool[]> _groups = new Dictionary<int, bool[]>();

		private const float LowCrouchHeight = 0.7f;

		private const float LowCrouchLean = 15f;

		private Vector3 _pronePosition;

		private Vector3 _proneEulers;

		private static readonly Vector3 RestCarry = new Vector3(0.21f, -0.05f, 0.24f);

		private static readonly Vector3 HipCarry = new Vector3(0.24f, 0f, 0.12f);

		private readonly Dictionary<Transform, Vector3> _carryPoints = new Dictionary<Transform, Vector3>();

		private const float FreshHit = 0.3f;

		private Vector3 _hitPoint;

		private Vector3 _hitDirection;

		private float _hitStrength;

		private Transform _hitBone;

		private float _hitTime = float.MinValue;

		private float _staggerLeft;

		private readonly List<Renderer> _hiddenRenderers = new List<Renderer>();

		private readonly List<Collider> _hidden = new List<Collider>();

		private readonly Dictionary<Renderer, Material[]> _ghostedRenderers = new Dictionary<Renderer, Material[]>();

		private Material _ghost;

		private bool? _ghosting;

		private bool _hitboxesShown;

		private List<GameObject> _hitboxShapes;

		public static void Attach(Sosig sosig)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			if (SoldierAssets.Loaded)
			{
				new GameObject("HumanoidSoldier").AddComponent<SoldierBody>().Init(sosig);
			}
		}

		public static bool HasSoldier(Sosig sosig)
		{
			if ((Object)(object)sosig != (Object)null)
			{
				return Bodies.ContainsKey(sosig);
			}
			return false;
		}

		public static string Folds(Sosig sosig)
		{
			SoldierBody value;
			SoldierPiece soldierPiece = (((Object)(object)sosig != (Object)null && Bodies.TryGetValue(sosig, out value)) ? value.Carrier((SosigBodyPart)1) : null);
			if (!((Object)(object)soldierPiece != (Object)null))
			{
				return null;
			}
			return soldierPiece.Folds();
		}

		public static bool HidesWearables(Sosig sosig)
		{
			if (HasSoldier(sosig))
			{
				return !DevSettings.ShowSosig.Value;
			}
			return false;
		}

		public static void HoldDecals(Sosig sosig)
		{
			if ((Object)(object)sosig != (Object)null && Bodies.TryGetValue(sosig, out var value))
			{
				value.Hold(sosig.m_spawnedHitDecals);
			}
		}

		public static void DestroyAll()
		{
			foreach (SoldierBody item in new List<SoldierBody>(Bodies.Values))
			{
				Object.Destroy((Object)(object)((Component)item).gameObject);
			}
		}

		public static Material[] Fill(Material material, int count)
		{
			Material[] array = (Material[])(object)new Material[count];
			for (int i = 0; i < count; i++)
			{
				array[i] = material;
			}
			return array;
		}

		private void Init(Sosig sosig)
		{
			_sosig = sosig;
			Bodies[sosig] = this;
			_armor = new SoldierArmor(sosig);
			_seed = ((Object)sosig).GetInstanceID();
			SoldierGore.Apply(sosig);
			Crouch(low: true);
			Carry(outward: true);
			_hidden.AddRange(SosigColliders.Links(sosig));
			_hidden.AddRange(SosigColliders.Wearables(sosig));
			foreach (Collider item in _hidden)
			{
				SoldierRays.Hide(item);
			}
			LateUpdate();
		}

		private void LateUpdate()
		{
			//IL_006a: 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_007b: 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)
			if ((Object)(object)_sosig == (Object)null)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			ShowDev();
			Split();
			Brace();
			foreach (SoldierPiece value in _pieces.Values)
			{
				value.Pose(Time.deltaTime);
				if (value.WentLimp && Fresh())
				{
					value.Push(_hitBone, _hitPoint, _hitDirection * _hitStrength * SoldierSettings.KnockPush.Value);
				}
			}
			Unstagger(Time.deltaTime);
		}

		public static void React(SosigLink link, Damage d, Transform bone, bool armored)
		{
			if ((Object)(object)link != (Object)null && (Object)(object)link.S != (Object)null && Bodies.TryGetValue(link.S, out var value))
			{
				value.Take(link, d, bone, armored);
			}
		}

		public static Vector3 ShudderDirection(Sosig sosig)
		{
			//IL_0027: 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)
			if ((Object)(object)sosig != (Object)null && Bodies.TryGetValue(sosig, out var value) && value.Fresh())
			{
				return value._hitDirection;
			}
			return Random.onUnitSphere;
		}

		private bool Fresh()
		{
			return Time.time - _hitTime < 0.3f;
		}

		private void Take(SosigLink link, Damage d, Transform bone, bool armored)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_00a9: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Invalid comparison between Unknown and I4
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: 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_016b: Unknown result type (might be due to invalid IL or missing references)
			SoldierPiece soldierPiece = Carrier(link.BodyPart);
			Vector3 normalized;
			if (!(((Vector3)(ref d.strikeDir)).sqrMagnitude > 0.0001f))
			{
				Vector3 val = d.point - d.Source_Point;
				normalized = ((Vector3)(ref val)).normalized;
			}
			else
			{
				normalized = ((Vector3)(ref d.strikeDir)).normalized;
			}
			Vector3 val2 = normalized;
			float num = HitReactions.Strength(d.Dam_TotalKinetic, SoldierSettings.ReactionEnergy.Value);
			if ((Object)(object)soldierPiece == (Object)null || ((Vector3)(ref val2)).sqrMagnitude < 0.5f || num <= 0f)
			{
				return;
			}
			_hitPoint = d.point;
			_hitDirection = val2;
			_hitStrength = num;
			_hitBone = (((Object)(object)bone != (Object)null) ? bone : soldierPiece.NearestBone(d.point, link.BodyPart));
			_hitTime = Time.time;
			if (soldierPiece.IsLimp)
			{
				soldierPiece.Push(_hitBone, d.point, val2 * num * SoldierSettings.KnockPush.Value);
				return;
			}
			HitReactions.Reaction reaction = HitReactions.Classify(num, SoldierSettings.StaggerAt.Value);
			if (reaction != HitReactions.Reaction.None)
			{
				soldierPiece.Flinch(d.point, val2, HitReactions.Flinch(num, armored, SoldierSettings.ArmorFlinch.Value), (int)link.BodyPart == 0);
				if (reaction == HitReactions.Reaction.Stagger && (int)_sosig.BodyState == 0 && !_sosig.m_recoveringFromBallisticState)
				{
					Stagger(link, d.point, val2 * num * SoldierSettings.StaggerPush.Value);
				}
			}
		}

		private void Stagger(SosigLink link, Vector3 point, Vector3 impulse)
		{
			//IL_0006: 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_0056: 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_0073: 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_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: 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)
			link.R.AddForceAtPosition(impulse, point, (ForceMode)1);
			float value = SoldierSettings.StaggerLoosen.Value;
			foreach (SosigLink link2 in _sosig.Links)
			{
				if (!((Object)(object)link2 == (Object)null) && !((Object)(object)link2.J == (Object)null))
				{
					CharacterJoint j = link2.J;
					SoftJointLimit val = default(SoftJointLimit);
					((SoftJointLimit)(ref val)).limit = 0f - value;
					j.lowTwistLimit = val;
					CharacterJoint j2 = link2.J;
					val = default(SoftJointLimit);
					((SoftJointLimit)(ref val)).limit = value;
					j2.highTwistLimit = val;
					CharacterJoint j3 = link2.J;
					val = default(SoftJointLimit);
					((SoftJointLimit)(ref val)).limit = value;
					j3.swing1Limit = val;
					CharacterJoint j4 = link2.J;
					val = default(SoftJointLimit);
					((SoftJointLimit)(ref val)).limit = value;
					j4.swing2Limit = val;
				}
			}
			_staggerLeft = SoldierSettings.StaggerTime.Value;
		}

		private void Unstagger(float deltaTime)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			if (!(_staggerLeft <= 0f))
			{
				_staggerLeft -= deltaTime;
				if (_staggerLeft <= 0f && (int)_sosig.BodyState == 0 && !_sosig.m_recoveringFromBallisticState)
				{
					_sosig.UpdateJoints(1f);
				}
			}
		}

		private void Split()
		{
			_groups.Clear();
			for (int i = 0; i < JoinedTo.Length; i++)
			{
				if (Alive(i))
				{
					int num = i;
					while (Joined(num))
					{
						num = JoinedTo[num];
					}
					if (!_groups.TryGetValue(num, out var value))
					{
						value = new bool[JoinedTo.Length];
						_groups[num] = value;
					}
					value[i] = true;
				}
			}
			bool flag = false;
			List<SoldierPiece> list = new List<SoldierPiece>();
			foreach (int item in new List<int>(_pieces.Keys))
			{
				if (!_groups.TryGetValue(item, out var value2))
				{
					list.Add(_pieces[item]);
					_pieces.Remove(item);
					flag = true;
				}
				else if (!Same(value2, item))
				{
					_pieces[item].Carry(value2);
					flag = true;
				}
			}
			foreach (KeyValuePair<int, bool[]> group in _groups)
			{
				if (!_pieces.ContainsKey(group.Key))
				{
					_pieces[group.Key] = SoldierPiece.Create(_sosig, (SosigBodyPart)group.Key, group.Value, _armor, _seed);
					flag = true;
				}
			}
			if (flag)
			{
				Rehome(_sosig.m_spawnedHitDecals, list);
			}
			foreach (SoldierPiece item2 in list)
			{
				Object.Destroy((Object)(object)((Component)item2).gameObject);
			}
		}

		private void Brace()
		{
			for (int i = 0; i < JoinedTo.Length; i++)
			{
				if (Joined(i))
				{
					SosigLink val = _sosig.Links[i];
					SosigLink val2 = _sosig.Links[JoinedTo[i]];
					bool flag = ((Object)(object)val.O != (Object)null && ((FVRInteractiveObject)val.O).IsHeld) || ((Object)(object)val2.O != (Object)null && ((FVRInteractiveObject)val2.O).IsHeld);
					val.J.projectionDistance = 0.03f;
					val.J.enableProjection = !flag && !DevSettings.LooseJoints.Value;
				}
			}
		}

		private void ShowDev()
		{
			bool value = DevSettings.ShowSosig.Value;
			if (_ghosting != value)
			{
				_ghosting = value;
				ShowSosig();
				if (value)
				{
					GhostSosig();
				}
				else
				{
					HideSosig();
				}
			}
			bool value2 = DevSettings.ShowSosigHitboxes.Value;
			if (value2 != _hitboxesShown)
			{
				_hitboxesShown = value2;
				if (_hitboxShapes == null)
				{
					_hitboxShapes = Overlays.SosigHitboxes(_sosig);
				}
				Overlays.Show(_hitboxShapes, value2);
			}
		}

		private void Carry(bool outward)
		{
			//IL_0082: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			if (!outward)
			{
				foreach (KeyValuePair<Transform, Vector3> carryPoint in _carryPoints)
				{
					if ((Object)(object)carryPoint.Key != (Object)null)
					{
						carryPoint.Key.localPosition = carryPoint.Value;
					}
				}
				_carryPoints.Clear();
				return;
			}
			foreach (SosigHand hand in _sosig.Hands)
			{
				Move(hand.Point_AtRest, RestCarry);
				Move(hand.Point_HipFire, HipCarry);
			}
		}

		private void Move(Transform point, Vector3 carry)
		{
			//IL_0020: 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_003b: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)point == (Object)null) && !_carryPoints.ContainsKey(point))
			{
				_carryPoints[point] = point.localPosition;
				point.localPosition = new Vector3(Mathf.Sign(point.localPosition.x) * carry.x, carry.y, carry.z);
			}
		}

		private void Crouch(bool low)
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0048: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
			Transform pose_Prone = _sosig.Pose_Prone;
			if (low)
			{
				_pronePosition = pose_Prone.localPosition;
				_proneEulers = _sosig.m_poseLocalEulers_Prone;
				pose_Prone.localPosition = new Vector3(_pronePosition.x, 0.7f, _pronePosition.z);
				_sosig.m_poseLocalEulers_Prone = new Vector3(15f, _proneEulers.y, _proneEulers.z);
			}
			else
			{
				pose_Prone.localPosition = _pronePosition;
				_sosig.m_poseLocalEulers_Prone = _proneEulers;
			}
			pose_Prone.localEulerAngles = _sosig.m_poseLocalEulers_Prone;
		}

		private void Unbrace()
		{
			for (int i = 0; i < JoinedTo.Length; i++)
			{
				SosigLink val = _sosig.Links[i];
				if ((Object)(object)val != (Object)null && (Object)(object)val.J != (Object)null)
				{
					val.J.enableProjection = false;
				}
			}
		}

		private bool Same(bool[] carried, int root)
		{
			for (int i = 0; i < carried.Length; i++)
			{
				if (carried[i] != _pieces[root].Carries((SosigBodyPart)i))
				{
					return false;
				}
			}
			return true;
		}

		private bool Alive(int part)
		{
			if ((Object)(object)_sosig.Links[part] != (Object)null)
			{
				return !_sosig.m_linksDestroyed[part];
			}
			return false;
		}

		private bool Joined(int part)
		{
			int num = JoinedTo[part];
			if (num >= 0 && Alive(part) && Alive(num) && !_sosig.m_jointsSevered[part])
			{
				return (Object)(object)_sosig.Links[part].J != (Object)null;
			}
			return false;
		}

		private void Hold(List<Transform> decals)
		{
			//IL_0042: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			foreach (Transform decal in decals)
			{
				if (!((Object)(object)decal == (Object)null) && !((Object)(object)decal.parent == (Object)null))
				{
					SosigLink component = ((Component)decal.parent).GetComponent<SosigLink>();
					SoldierPiece soldierPiece = (((Object)(object)component != (Object)null) ? Carrier(component.BodyPart) : null);
					if ((Object)(object)soldierPiece != (Object)null)
					{
						decal.SetParent(soldierPiece.NearestBone(decal.position, component.BodyPart), true);
					}
				}
			}
		}

		private void Rehome(List<Transform> decals, List<SoldierPiece> dropped)
		{
			//IL_0055: 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)
			foreach (Transform decal in decals)
			{
				SoldierPiece soldierPiece = (((Object)(object)decal != (Object)null) ? ((Component)decal).GetComponentInParent<SoldierPiece>() : null);
				SosigBodyPart? val = (((Object)(object)soldierPiece != (Object)null) ? soldierPiece.PartOf(decal.parent) : ((SosigBodyPart?)null));
				if (val.HasValue && (!soldierPiece.Carries(val.Value) || dropped.Contains(soldierPiece)))
				{
					SoldierPiece soldierPiece2 = Carrier(val.Value);
					Transform val2 = (((Object)(object)soldierPiece2 != (Object)null) ? soldierPiece2.Bone(((Object)decal.parent).name) : null);
					if ((Object)(object)val2 != (Object)null)
					{
						decal.SetParent(val2, false);
					}
					else
					{
						Object.Destroy((Object)(object)((Component)decal).gameObject);
					}
				}
			}
		}

		private SoldierPiece Carrier(SosigBodyPart part)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			foreach (SoldierPiece value in _pieces.Values)
			{
				if (value.Carries(part))
				{
					return value;
				}
			}
			return null;
		}

		private void OnDestroy()
		{
			Bodies.Remove(_sosig);
			foreach (SoldierPiece value in _pieces.Values)
			{
				if ((Object)(object)value != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)value).gameObject);
				}
			}
			foreach (Collider item in _hidden)
			{
				SoldierRays.Show(item);
			}
			if ((Object)(object)_sosig != (Object)null)
			{
				ShowSosig();
				SoldierGore.Restore(_sosig);
				Unbrace();
				Crouch(low: false);
				Carry(outward: false);
			}
			if ((Object)(object)_ghost != (Object)null)
			{
				Object.Destroy((Object)(object)_ghost);
			}
			if (_hitboxShapes != null)
			{
				Overlays.Clear(_hitboxShapes);
			}
		}

		private void HideSosig()
		{
			foreach (Renderer item in SosigRenderers())
			{
				item.enabled = false;
				_hiddenRenderers.Add(item);
			}
		}

		private void GhostSosig()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_ghost == (Object)null)
			{
				_ghost = Overlays.SeeThrough(GhostColor);
			}
			foreach (Renderer item in SosigRenderers())
			{
				_ghostedRenderers[item] = item.sharedMaterials;
				item.sharedMaterials = Fill(_ghost, item.sharedMaterials.Length);
			}
		}

		private void ShowSosig()
		{
			foreach (Renderer hiddenRenderer in _hiddenRenderers)
			{
				if ((Object)(object)hiddenRenderer != (Object)null)
				{
					hiddenRenderer.enabled = true;
				}
			}
			_hiddenRenderers.Clear();
			foreach (KeyValuePair<Renderer, Material[]> ghostedRenderer in _ghostedRenderers)
			{
				if ((Object)(object)ghostedRenderer.Key != (Object)null)
				{
					ghostedRenderer.Key.sharedMaterials = ghostedRenderer.Value;
				}
			}
			_ghos