Decompiled source of OutDatedNpcFixer v1.7.2

Mods/OutdatedNPCFixer.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using BoneLib;
using BoneLib.BoneMenu;
using BoneLib.Notifications;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Marrow.Pool;
using Il2CppSLZ.Marrow.PuppetMasta;
using Il2CppSystem;
using Il2CppSystem.Reflection;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using NPCReviver;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "Outdated NPC Fixer", "1.7.0", "Calvin", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("OutdatedNPCFixer")]
[assembly: AssemblyConfiguration("release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("OutdatedNPCFixer")]
[assembly: AssemblyTitle("OutdatedNPCFixer")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace NPCReviver
{
	public class Core : MelonMod
	{
		private class ScanInfo
		{
			public bool Player;

			public bool Brain;

			public bool Puppet;

			public bool Leftover;

			public bool Body;

			public int Bodies;

			public int Joints;

			public int Missing;

			public int Bones;

			public bool Broken
			{
				get
				{
					if (!Player && Body && Bodies >= 6 && Joints >= 4 && (!Brain || !Puppet))
					{
						if (!Leftover)
						{
							return Missing >= 2;
						}
						return true;
					}
					return false;
				}
			}

			public override string ToString()
			{
				return $"bodies={Bodies} joints={Joints} bones={Bones} brain={Brain} puppet={Puppet} leftoverAI={Leftover} missingScripts={Missing} player={Player} => {(Broken ? "BROKEN" : "ok")}";
			}
		}

		private class Revived
		{
			public GameObject Npc;

			public int Id;

			public readonly List<GameObject> Added = new List<GameObject>();

			public readonly List<Renderer> HiddenRenderers = new List<Renderer>();

			public readonly List<bool> HiddenWasEnabled = new List<bool>();

			public readonly List<Rigidbody> ChangedBodies = new List<Rigidbody>();

			public readonly List<float> OriginalMasses = new List<float>();

			public readonly List<Rigidbody> AnchorBodies = new List<Rigidbody>();

			public readonly List<Transform> AnchorFollow = new List<Transform>();

			public readonly List<object> BakTargets = new List<object>();

			public readonly List<PropertyInfo> BakProps = new List<PropertyInfo>();

			public readonly List<object> BakValues = new List<object>();

			public SubBehaviourSfx SfxTarget;

			public readonly List<PropertyInfo> SfxProps = new List<PropertyInfo>();

			public readonly List<object> SfxOriginal = new List<object>();
		}

		private class Pending
		{
			public GameObject Broken;

			public float Started;

			public Vector3 SpawnPos;

			public HashSet<int> ActiveBefore = new HashSet<int>();

			public readonly List<Rigidbody> Bodies = new List<Rigidbody>();

			public readonly List<bool> WasKinematic = new List<bool>();

			public readonly List<Collider> Colliders = new List<Collider>();

			public readonly List<bool> ColliderWasEnabled = new List<bool>();
		}

		private class MapEntry
		{
			public Transform Ford;

			public Quaternion Q = Quaternion.identity;

			public bool Identity;
		}

		private class BindPose
		{
			public Vector3 Pos;

			public Quaternion Rot;
		}

		private class Skeleton
		{
			public Transform Root;

			public readonly Dictionary<int, Transform> Bones = new Dictionary<int, Transform>();

			public readonly Dictionary<int, BindPose> Binds = new Dictionary<int, BindPose>();

			public Transform LHand;

			public Transform RHand;

			public Transform LFoot;

			public Transform RFoot;

			public Transform Head;

			public Transform Hips;

			public Transform Chest;

			public Quaternion Frame = Quaternion.identity;

			private static readonly string[] HandYes = new string[2] { "hand", "wrist" };

			private static readonly string[] HandNo = new string[21]
			{
				"finger", "thumb", "index", "middle", "ring", "pinky", "little", "twist", "ik", "target",
				"grip", "pole", "end", "nub", "carpal", "handle", "prop", "weapon", "attach", "socket",
				"point"
			};

			private static readonly string[] FootYes = new string[2] { "foot", "ankle" };

			private static readonly string[] FootNo = new string[11]
			{
				"toe", "ball", "ik", "target", "end", "nub", "heel", "twist", "pole", "roll",
				"point"
			};

			private static readonly string[] HeadYes = new string[1] { "head" };

			private static readonly string[] HeadNo = new string[12]
			{
				"top", "end", "nub", "eye", "jaw", "target", "ik", "look", "hair", "tip",
				"forehead", "point"
			};

			public bool Has(Transform t)
			{
				if ((Object)(object)t != (Object)null)
				{
					return Binds.ContainsKey(((Object)t).GetInstanceID());
				}
				return false;
			}

			public BindPose B(Transform t)
			{
				return Binds[((Object)t).GetInstanceID()];
			}

			public static Skeleton Build(Transform root, List<SkinnedMeshRenderer> skins)
			{
				//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_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_00cc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_010f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0114: Unknown result type (might be due to invalid IL or missing references)
				//IL_0119: Unknown result type (might be due to invalid IL or missing references)
				//IL_011f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0121: Unknown result type (might be due to invalid IL or missing references)
				//IL_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)
				Skeleton skeleton = new Skeleton
				{
					Root = root
				};
				foreach (SkinnedMeshRenderer skin in skins)
				{
					Il2CppReferenceArray<Transform> bones = skin.bones;
					if (bones == null)
					{
						continue;
					}
					Il2CppStructArray<Matrix4x4> val = null;
					try
					{
						val = skin.sharedMesh.bindposes;
					}
					catch
					{
					}
					for (int i = 0; i < ((Il2CppArrayBase<Transform>)(object)bones).Length; i++)
					{
						Transform val2 = ((Il2CppArrayBase<Transform>)(object)bones)[i];
						if ((Object)(object)val2 == (Object)null)
						{
							continue;
						}
						int instanceID = ((Object)val2).GetInstanceID();
						if (!skeleton.Bones.ContainsKey(instanceID))
						{
							skeleton.Bones[instanceID] = val2;
						}
						if (val != null && i < ((Il2CppArrayBase<Matrix4x4>)(object)val).Length && !skeleton.Binds.ContainsKey(instanceID))
						{
							Matrix4x4 val3 = ((Il2CppArrayBase<Matrix4x4>)(object)val)[i];
							Matrix4x4 inverse = ((Matrix4x4)(ref val3)).inverse;
							Vector3 val4 = Vector4.op_Implicit(((Matrix4x4)(ref inverse)).GetColumn(2));
							Vector3 val5 = Vector4.op_Implicit(((Matrix4x4)(ref inverse)).GetColumn(1));
							if (!(((Vector3)(ref val4)).sqrMagnitude < 1E-12f) && !(((Vector3)(ref val5)).sqrMagnitude < 1E-12f))
							{
								skeleton.Binds[instanceID] = new BindPose
								{
									Pos = Vector4.op_Implicit(((Matrix4x4)(ref inverse)).GetColumn(3)),
									Rot = Quaternion.LookRotation(val4, val5)
								};
							}
						}
					}
				}
				return skeleton;
			}

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

			private static int Side(string raw)
			{
				string text = raw.ToLowerInvariant();
				if (text.Contains("left"))
				{
					return -1;
				}
				if (text.Contains("right"))
				{
					return 1;
				}
				if (raw.Length > 1 && raw[0] == 'l' && char.IsUpper(raw[1]))
				{
					return -1;
				}
				if (raw.Length > 1 && raw[0] == 'r' && char.IsUpper(raw[1]))
				{
					return 1;
				}
				if (Regex.IsMatch(text, "(^|[^a-z])l([^a-z]|$)"))
				{
					return -1;
				}
				if (Regex.IsMatch(text, "(^|[^a-z])r([^a-z]|$)"))
				{
					return 1;
				}
				return 0;
			}

			private static bool IsPart(string norm, string[] yes, string[] no)
			{
				bool flag = false;
				string[] array = yes;
				foreach (string value in array)
				{
					if (norm.Contains(value))
					{
						flag = true;
						break;
					}
				}
				if (!flag)
				{
					return false;
				}
				array = no;
				foreach (string value2 in array)
				{
					if (norm.Contains(value2))
					{
						return false;
					}
				}
				return true;
			}

			private void PickPair(string[] yes, string[] no, out Transform left, out Transform right)
			{
				left = null;
				right = null;
				int num = int.MaxValue;
				int num2 = int.MaxValue;
				List<Transform> list = new List<Transform>();
				foreach (KeyValuePair<int, BindPose> bind in Binds)
				{
					Transform val = Bones[bind.Key];
					string text = Norm(((Object)val).name);
					if (IsPart(text, yes, no))
					{
						int num3 = Side(((Object)val).name);
						int num4 = Depth(val) * 2 + ((!text.Contains(yes[0])) ? 1 : 0);
						if (num3 < 0 && num4 < num)
						{
							left = val;
							num = num4;
						}
						else if (num3 > 0 && num4 < num2)
						{
							right = val;
							num2 = num4;
						}
						else if (num3 == 0)
						{
							list.Add(val);
						}
					}
				}
				if (((Object)(object)left == (Object)null || (Object)(object)right == (Object)null) && list.Count >= 2)
				{
					list.Sort((Transform x, Transform y) => Depth(x).CompareTo(Depth(y)));
					Transform val2 = list[0];
					Transform val3 = list[1];
					if (B(val2).Pos.x > B(val3).Pos.x)
					{
						Transform obj = val2;
						val2 = val3;
						val3 = obj;
					}
					if ((Object)(object)left == (Object)null)
					{
						left = val2;
					}
					if ((Object)(object)right == (Object)null)
					{
						right = val3;
					}
				}
			}

			private Transform LCA(Transform a, Transform b)
			{
				HashSet<int> hashSet = new HashSet<int>();
				Transform val = a;
				while ((Object)(object)val != (Object)null)
				{
					hashSet.Add(((Object)val).GetInstanceID());
					if ((Object)(object)val == (Object)(object)Root)
					{
						break;
					}
					val = val.parent;
				}
				Transform val2 = b;
				while ((Object)(object)val2 != (Object)null)
				{
					if (hashSet.Contains(((Object)val2).GetInstanceID()))
					{
						return val2;
					}
					if ((Object)(object)val2 == (Object)(object)Root)
					{
						break;
					}
					val2 = val2.parent;
				}
				return Root;
			}

			public string FindAnchors()
			{
				//IL_029f: Unknown result type (might be due to invalid IL or missing references)
				//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
				//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
				//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
				//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
				//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
				//IL_02da: Unknown result type (might be due to invalid IL or missing references)
				//IL_02de: Unknown result type (might be due to invalid IL or missing references)
				//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
				//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
				//IL_0301: Unknown result type (might be due to invalid IL or missing references)
				//IL_0306: Unknown result type (might be due to invalid IL or missing references)
				//IL_030b: Unknown result type (might be due to invalid IL or missing references)
				//IL_030c: Unknown result type (might be due to invalid IL or missing references)
				//IL_030d: Unknown result type (might be due to invalid IL or missing references)
				//IL_030e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0314: Unknown result type (might be due to invalid IL or missing references)
				//IL_0315: Unknown result type (might be due to invalid IL or missing references)
				//IL_031a: Unknown result type (might be due to invalid IL or missing references)
				//IL_031f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0323: Unknown result type (might be due to invalid IL or missing references)
				//IL_0328: Unknown result type (might be due to invalid IL or missing references)
				//IL_034c: Unknown result type (might be due to invalid IL or missing references)
				//IL_034d: Unknown result type (might be due to invalid IL or missing references)
				//IL_034e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0353: Unknown result type (might be due to invalid IL or missing references)
				//IL_0354: Unknown result type (might be due to invalid IL or missing references)
				//IL_0359: Unknown result type (might be due to invalid IL or missing references)
				PickPair(HandYes, HandNo, out LHand, out RHand);
				PickPair(FootYes, FootNo, out LFoot, out RFoot);
				int num = int.MaxValue;
				foreach (KeyValuePair<int, BindPose> bind in Binds)
				{
					Transform val = Bones[bind.Key];
					if (IsPart(Norm(((Object)val).name), HeadYes, HeadNo))
					{
						int num2 = Depth(val);
						if (num2 < num)
						{
							Head = val;
							num = num2;
						}
					}
				}
				if ((Object)(object)Head == (Object)null)
				{
					int num3 = int.MaxValue;
					foreach (KeyValuePair<int, BindPose> bind2 in Binds)
					{
						Transform val2 = Bones[bind2.Key];
						string text = Norm(((Object)val2).name);
						if (!text.Contains("jaw") && !text.Contains("headtop") && !text.Contains("headend"))
						{
							continue;
						}
						Transform parent = val2.parent;
						while ((Object)(object)parent != (Object)null && (Object)(object)parent != (Object)(object)Root && !Has(parent))
						{
							parent = parent.parent;
						}
						if (!((Object)(object)parent == (Object)null) && !((Object)(object)parent == (Object)(object)Root))
						{
							int num4 = Depth(parent);
							if (num4 < num3)
							{
								Head = parent;
								num3 = num4;
							}
						}
					}
				}
				List<string> list = new List<string>();
				if ((Object)(object)LHand == (Object)null)
				{
					list.Add("left hand");
				}
				if ((Object)(object)RHand == (Object)null)
				{
					list.Add("right hand");
				}
				if ((Object)(object)LFoot == (Object)null)
				{
					list.Add("left foot");
				}
				if ((Object)(object)RFoot == (Object)null)
				{
					list.Add("right foot");
				}
				if ((Object)(object)Head == (Object)null)
				{
					list.Add("head");
				}
				if (list.Count > 0)
				{
					return "is missing: " + string.Join(", ", list);
				}
				Hips = LCA(LFoot, RFoot);
				Chest = LCA(LHand, RHand);
				Vector3 val3 = B(Head).Pos - (B(LFoot).Pos + B(RFoot).Pos) * 0.5f;
				Vector3 normalized = ((Vector3)(ref val3)).normalized;
				Vector3 val4 = B(RHand).Pos - B(LHand).Pos;
				val3 = val4 - Vector3.Dot(val4, normalized) * normalized;
				val4 = ((Vector3)(ref val3)).normalized;
				if (((Vector3)(ref normalized)).sqrMagnitude < 0.5f || ((Vector3)(ref val4)).sqrMagnitude < 0.5f)
				{
					return "has a weird rest pose";
				}
				Frame = Quaternion.LookRotation(Vector3.Cross(val4, normalized), normalized);
				return null;
			}

			public List<Transform> Chain(Transform from, Transform stop)
			{
				List<Transform> list = new List<Transform>();
				Transform val = from;
				while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)stop && (Object)(object)val != (Object)(object)Root)
				{
					if (Has(val))
					{
						list.Add(val);
					}
					val = val.parent;
				}
				return list;
			}

			public string Describe()
			{
				return "hands " + N(LHand) + "/" + N(RHand) + ", feet " + N(LFoot) + "/" + N(RFoot) + ", head " + N(Head) + ", hips " + N(Hips) + ", chest " + N(Chest) + " (" + Binds.Count + " bones)";
				static string N(Transform t)
				{
					if (!((Object)(object)t != (Object)null))
					{
						return "?";
					}
					return ((Object)t).name;
				}
			}
		}

		private class Retarget
		{
			public readonly Dictionary<int, MapEntry> Map = new Dictionary<int, MapEntry>();

			private readonly Dictionary<int, Transform> _targets = new Dictionary<int, Transform>();

			private readonly Transform _oldRoot;

			private readonly Transform _freshHips;

			private readonly Transform _freshRoot;

			private Il2CppArrayBase<Collider> _fordColliders;

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

			private readonly Revived _rev;

			private Transform _top;

			public int HelperCount;

			private readonly Dictionary<int, Joint> _jiggle = new Dictionary<int, Joint>();

			private readonly Dictionary<int, Rigidbody> _anchors = new Dictionary<int, Rigidbody>();

			public int JiggleBuilt;

			public Retarget(Transform oldRoot, Transform freshRoot, Transform freshHips, Revived rev)
			{
				_oldRoot = oldRoot;
				_freshRoot = freshRoot;
				_freshHips = freshHips;
				_rev = rev;
			}

			public int MapByStructure(Skeleton o, Skeleton f)
			{
				int num = 0 + MapChain(o, f, o.Chain(o.LHand, o.Chest), f.Chain(f.LHand, f.Chest)) + MapChain(o, f, o.Chain(o.RHand, o.Chest), f.Chain(f.RHand, f.Chest)) + MapChain(o, f, o.Chain(o.LFoot, o.Hips), f.Chain(f.LFoot, f.Hips)) + MapChain(o, f, o.Chain(o.RFoot, o.Hips), f.Chain(f.RFoot, f.Hips)) + MapChain(o, f, o.Chain(o.Head, o.Chest), f.Chain(f.Head, f.Chest));
				List<Transform> list = o.Chain(o.Chest, o.Hips);
				if (o.Has(o.Hips))
				{
					list.Add(o.Hips);
				}
				List<Transform> list2 = f.Chain(f.Chest, f.Hips);
				if (f.Has(f.Hips))
				{
					list2.Add(f.Hips);
				}
				return num + MapChain(o, f, list, list2);
			}

			private int MapChain(Skeleton o, Skeleton f, List<Transform> oc, List<Transform> fc)
			{
				//IL_0071: Unknown result type (might be due to invalid IL or missing references)
				//IL_0076: Unknown result type (might be due to invalid IL or missing references)
				//IL_0185: Unknown result type (might be due to invalid IL or missing references)
				//IL_018a: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
				//IL_0100: Unknown result type (might be due to invalid IL or missing references)
				//IL_0105: Unknown result type (might be due to invalid IL or missing references)
				//IL_0108: Unknown result type (might be due to invalid IL or missing references)
				//IL_010d: Unknown result type (might be due to invalid IL or missing references)
				//IL_011a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0127: Unknown result type (might be due to invalid IL or missing references)
				//IL_012c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0131: Unknown result type (might be due to invalid IL or missing references)
				//IL_0136: 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_00cc: 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_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_01cf: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
				//IL_01da: Unknown result type (might be due to invalid IL or missing references)
				//IL_01df: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
				//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
				//IL_020f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0214: Unknown result type (might be due to invalid IL or missing references)
				//IL_0219: Unknown result type (might be due to invalid IL or missing references)
				//IL_0231: Unknown result type (might be due to invalid IL or missing references)
				//IL_0233: Unknown result type (might be due to invalid IL or missing references)
				if (oc.Count == 0 || fc.Count == 0)
				{
					return 0;
				}
				int[] array = new int[oc.Count];
				for (int i = 0; i < oc.Count; i++)
				{
					array[i] = ((oc.Count != 1) ? Mathf.RoundToInt((float)(i * (fc.Count - 1)) / (float)(oc.Count - 1)) : 0);
				}
				Quaternion[] array2 = (Quaternion[])(object)new Quaternion[oc.Count];
				for (int j = 0; j < oc.Count; j++)
				{
					array2[j] = Quaternion.identity;
					if (j == 0)
					{
						continue;
					}
					Transform t = oc[j];
					Transform t2 = oc[j - 1];
					Transform val = fc[array[j]];
					Transform val2 = fc[array[j - 1]];
					if ((Object)(object)val == (Object)(object)val2)
					{
						array2[j] = array2[j - 1];
						continue;
					}
					Vector3 val3 = Quaternion.Inverse(o.Frame) * (o.B(t2).Pos - o.B(t).Pos);
					Vector3 val4 = Quaternion.Inverse(f.Frame) * (f.B(val2).Pos - f.B(val).Pos);
					if (((Vector3)(ref val3)).sqrMagnitude > 1E-10f && ((Vector3)(ref val4)).sqrMagnitude > 1E-10f)
					{
						array2[j] = Quaternion.FromToRotation(val3, val4);
					}
				}
				if (oc.Count > 1)
				{
					array2[0] = array2[1];
				}
				int num = 0;
				for (int k = 0; k < oc.Count; k++)
				{
					int instanceID = ((Object)oc[k]).GetInstanceID();
					if (!Map.ContainsKey(instanceID))
					{
						Transform val5 = fc[array[k]];
						Quaternion q = Quaternion.Inverse(f.B(val5).Rot) * f.Frame * array2[k] * Quaternion.Inverse(o.Frame) * o.B(oc[k]).Rot;
						Map[instanceID] = new MapEntry
						{
							Ford = val5,
							Q = q,
							Identity = false
						};
						num++;
					}
				}
				return num;
			}

			public int FindJiggle(Dictionary<int, Transform> meshBones)
			{
				foreach (Joint componentsInChild in ((Component)_oldRoot).GetComponentsInChildren<Joint>(true))
				{
					if ((Object)(object)componentsInChild == (Object)null || (Object)(object)componentsInChild.connectedBody == (Object)null)
					{
						continue;
					}
					Transform transform = ((Component)componentsInChild).transform;
					int instanceID = ((Object)transform).GetInstanceID();
					if (Map.ContainsKey(instanceID) || _jiggle.ContainsKey(instanceID) || (Object)(object)((Component)transform).GetComponent<Rigidbody>() == (Object)null || (Object)(object)transform.parent == (Object)null || !HasMappedAncestor(transform.parent))
					{
						continue;
					}
					bool flag = false;
					int num = 0;
					foreach (Transform componentsInChild2 in ((Component)transform).GetComponentsInChildren<Transform>(true))
					{
						int instanceID2 = ((Object)componentsInChild2).GetInstanceID();
						if ((Object)(object)componentsInChild2 != (Object)(object)transform && Map.ContainsKey(instanceID2))
						{
							flag = true;
							break;
						}
						if (meshBones.ContainsKey(instanceID2))
						{
							num++;
						}
					}
					if (!flag && num != 0 && !((float)num > (float)meshBones.Count * 0.3f))
					{
						_jiggle[instanceID] = componentsInChild;
					}
				}
				return _jiggle.Count;
			}

			private Rigidbody AnchorFor(Transform oldBody)
			{
				//IL_0063: Unknown result type (might be due to invalid IL or missing references)
				//IL_0069: Expected O, but got Unknown
				//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_00a3: Unknown result type (might be due to invalid IL or missing references)
				int instanceID = ((Object)oldBody).GetInstanceID();
				if (_jiggle.ContainsKey(instanceID))
				{
					Rigidbody component = ((Component)Target(oldBody)).GetComponent<Rigidbody>();
					if ((Object)(object)component != (Object)null)
					{
						return component;
					}
				}
				if (_anchors.TryGetValue(instanceID, out var value) && (Object)(object)value != (Object)null)
				{
					return value;
				}
				Transform val = Target(oldBody);
				GameObject val2 = new GameObject("NR_anchor_" + ((Object)oldBody).name);
				_rev.Added.Add(val2);
				val2.transform.position = val.position;
				val2.transform.rotation = val.rotation;
				val2.transform.localScale = val.lossyScale;
				Rigidbody val3 = val2.AddComponent<Rigidbody>();
				val3.isKinematic = true;
				val3.useGravity = false;
				val3.interpolation = (RigidbodyInterpolation)1;
				_rev.AnchorBodies.Add(val3);
				_rev.AnchorFollow.Add(val);
				_anchors[instanceID] = val3;
				return val3;
			}

			private Transform BuildJiggle(Transform old, Joint oj)
			{
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0023: Expected O, but got Unknown
				//IL_004c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0051: Unknown result type (might be due to invalid IL or missing references)
				//IL_005d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0063: Unknown result type (might be due to invalid IL or missing references)
				//IL_0068: Unknown result type (might be due to invalid IL or missing references)
				//IL_0074: Unknown result type (might be due to invalid IL or missing references)
				//IL_007a: Unknown result type (might be due to invalid IL or missing references)
				//IL_007f: Unknown result type (might be due to invalid IL or missing references)
				Transform val = Target(old.parent);
				GameObject val2 = new GameObject("NR_jiggle_" + ((Object)old).name);
				_rev.Added.Add(val2);
				HelperCount++;
				Transform transform = val2.transform;
				transform.position = val.TransformPoint(old.localPosition);
				transform.rotation = val.rotation * old.localRotation;
				transform.localScale = Vector3.Scale(val.lossyScale, old.localScale);
				_targets[((Object)old).GetInstanceID()] = transform;
				try
				{
					float num = Mathf.Clamp(_jiggleAmount.Value, 0.1f, 1f);
					float num2 = 1f - num;
					Rigidbody component = ((Component)old).GetComponent<Rigidbody>();
					Rigidbody obj = val2.AddComponent<Rigidbody>();
					obj.mass = component.mass;
					obj.drag = component.drag + num2 * 8f;
					obj.angularDrag = component.angularDrag + num2 * 15f;
					obj.useGravity = component.useGravity;
					obj.maxAngularVelocity = Mathf.Min(component.maxAngularVelocity, 7f + 20f * num);
					obj.maxDepenetrationVelocity = 2f;
					obj.solverIterations = 12;
					obj.solverVelocityIterations = 4;
					obj.interpolation = (RigidbodyInterpolation)1;
					obj.isKinematic = false;
					Rigidbody connected = AnchorFor(((Component)oj.connectedBody).transform);
					CopyJoint(oj, val2, connected, num, component.mass);
					if (_jiggleTouch.Value)
					{
						AddColliders(old, transform);
					}
					JiggleBuilt++;
				}
				catch (Exception ex)
				{
					MelonLogger.Warning("[Outdated NPC Fixer] jiggle bone " + ((Object)old).name + " failed: " + ex.Message);
					transform.SetParent(val, true);
					Rigidbody component2 = val2.GetComponent<Rigidbody>();
					if ((Object)(object)component2 != (Object)null)
					{
						Object.Destroy((Object)(object)component2);
					}
				}
				return transform;
			}

			private static SoftJointLimit Shrink(SoftJointLimit l, float a)
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				((SoftJointLimit)(ref l)).limit = ((SoftJointLimit)(ref l)).limit * a;
				return l;
			}

			private static JointDrive Calm(JointDrive d, float amount, float mass)
			{
				//IL_0054: Unknown result type (might be due to invalid IL or missing references)
				float num = 1f - amount;
				((JointDrive)(ref d)).positionSpring = ((JointDrive)(ref d)).positionSpring / amount + num * 60f * mass;
				((JointDrive)(ref d)).positionDamper = ((JointDrive)(ref d)).positionDamper + num * 6f * mass;
				if (((JointDrive)(ref d)).maximumForce <= 0f)
				{
					((JointDrive)(ref d)).maximumForce = float.MaxValue;
				}
				return d;
			}

			private static void CopyJoint(Joint src, GameObject dst, Rigidbody connected, float amount, float mass)
			{
				//IL_007b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0088: Unknown result type (might be due to invalid IL or missing references)
				//IL_0095: 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_00af: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e3: 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_00fd: Unknown result type (might be due to invalid IL or missing references)
				//IL_010a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0117: 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_0131: Unknown result type (might be due to invalid IL or missing references)
				//IL_013e: Unknown result type (might be due to invalid IL or missing references)
				//IL_014b: 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_0165: Unknown result type (might be due to invalid IL or missing references)
				//IL_0172: Unknown result type (might be due to invalid IL or missing references)
				//IL_017f: Unknown result type (might be due to invalid IL or missing references)
				//IL_018c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0199: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
				//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
				//IL_01da: Unknown result type (might be due to invalid IL or missing references)
				//IL_033e: Unknown result type (might be due to invalid IL or missing references)
				//IL_034b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0358: Unknown result type (might be due to invalid IL or missing references)
				//IL_0365: Unknown result type (might be due to invalid IL or missing references)
				//IL_0372: Unknown result type (might be due to invalid IL or missing references)
				//IL_037f: Unknown result type (might be due to invalid IL or missing references)
				//IL_038c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0399: Unknown result type (might be due to invalid IL or missing references)
				//IL_0227: Unknown result type (might be due to invalid IL or missing references)
				//IL_022d: Unknown result type (might be due to invalid IL or missing references)
				//IL_023b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0241: Unknown result type (might be due to invalid IL or missing references)
				//IL_024f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0255: Unknown result type (might be due to invalid IL or missing references)
				//IL_0263: Unknown result type (might be due to invalid IL or missing references)
				//IL_0269: Unknown result type (might be due to invalid IL or missing references)
				//IL_0277: Unknown result type (might be due to invalid IL or missing references)
				//IL_027d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0289: Unknown result type (might be due to invalid IL or missing references)
				//IL_028f: Invalid comparison between Unknown and I4
				//IL_03d6: Unknown result type (might be due to invalid IL or missing references)
				//IL_03dc: Unknown result type (might be due to invalid IL or missing references)
				//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
				//IL_03f0: Unknown result type (might be due to invalid IL or missing references)
				//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
				//IL_0404: Unknown result type (might be due to invalid IL or missing references)
				//IL_0412: Unknown result type (might be due to invalid IL or missing references)
				//IL_0418: Unknown result type (might be due to invalid IL or missing references)
				//IL_0574: Unknown result type (might be due to invalid IL or missing references)
				//IL_0580: Unknown result type (might be due to invalid IL or missing references)
				//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
				//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
				//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
				//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
				//IL_0295: Unknown result type (might be due to invalid IL or missing references)
				//IL_029d: Unknown result type (might be due to invalid IL or missing references)
				//IL_04e0: Unknown result type (might be due to invalid IL or missing references)
				//IL_04fa: Unknown result type (might be due to invalid IL or missing references)
				//IL_0513: Unknown result type (might be due to invalid IL or missing references)
				//IL_0518: Unknown result type (might be due to invalid IL or missing references)
				//IL_0539: Unknown result type (might be due to invalid IL or missing references)
				//IL_0550: Unknown result type (might be due to invalid IL or missing references)
				//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
				//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
				//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
				//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
				//IL_0305: Unknown result type (might be due to invalid IL or missing references)
				//IL_030d: Unknown result type (might be due to invalid IL or missing references)
				ConfigurableJoint val = ((Il2CppObjectBase)src).TryCast<ConfigurableJoint>();
				CharacterJoint val2 = (((Object)(object)val == (Object)null) ? ((Il2CppObjectBase)src).TryCast<CharacterJoint>() : null);
				SpringJoint val3 = (((Object)(object)val == (Object)null && (Object)(object)val2 == (Object)null) ? ((Il2CppObjectBase)src).TryCast<SpringJoint>() : null);
				HingeJoint val4 = (((Object)(object)val == (Object)null && (Object)(object)val2 == (Object)null && (Object)(object)val3 == (Object)null) ? ((Il2CppObjectBase)src).TryCast<HingeJoint>() : null);
				Joint val6;
				if ((Object)(object)val != (Object)null)
				{
					ConfigurableJoint val5 = dst.AddComponent<ConfigurableJoint>();
					((Joint)val5).connectedBody = connected;
					((Joint)val5).axis = ((Joint)val).axis;
					val5.secondaryAxis = val.secondaryAxis;
					val5.xMotion = val.xMotion;
					val5.yMotion = val.yMotion;
					val5.zMotion = val.zMotion;
					val5.angularXMotion = val.angularXMotion;
					val5.angularYMotion = val.angularYMotion;
					val5.angularZMotion = val.angularZMotion;
					val5.linearLimit = val.linearLimit;
					val5.linearLimitSpring = val.linearLimitSpring;
					val5.lowAngularXLimit = val.lowAngularXLimit;
					val5.highAngularXLimit = val.highAngularXLimit;
					val5.angularXLimitSpring = val.angularXLimitSpring;
					val5.angularYLimit = val.angularYLimit;
					val5.angularZLimit = val.angularZLimit;
					val5.angularYZLimitSpring = val.angularYZLimitSpring;
					val5.targetPosition = val.targetPosition;
					val5.targetVelocity = val.targetVelocity;
					val5.xDrive = val.xDrive;
					val5.yDrive = val.yDrive;
					val5.zDrive = val.zDrive;
					val5.targetRotation = val.targetRotation;
					val5.targetAngularVelocity = val.targetAngularVelocity;
					val5.rotationDriveMode = val.rotationDriveMode;
					val5.angularXDrive = val.angularXDrive;
					val5.angularYZDrive = val.angularYZDrive;
					val5.slerpDrive = val.slerpDrive;
					val5.projectionMode = val.projectionMode;
					val5.projectionDistance = val.projectionDistance;
					val5.projectionAngle = val.projectionAngle;
					val5.configuredInWorldSpace = val.configuredInWorldSpace;
					val5.swapBodies = val.swapBodies;
					if (amount < 0.999f)
					{
						val5.lowAngularXLimit = Shrink(val5.lowAngularXLimit, amount);
						val5.highAngularXLimit = Shrink(val5.highAngularXLimit, amount);
						val5.angularYLimit = Shrink(val5.angularYLimit, amount);
						val5.angularZLimit = Shrink(val5.angularZLimit, amount);
						val5.linearLimit = Shrink(val5.linearLimit, amount);
						if ((int)val5.rotationDriveMode == 1)
						{
							val5.slerpDrive = Calm(val5.slerpDrive, amount, mass);
						}
						else
						{
							val5.angularXDrive = Calm(val5.angularXDrive, amount, mass);
							val5.angularYZDrive = Calm(val5.angularYZDrive, amount, mass);
						}
						val5.xDrive = Calm(val5.xDrive, amount, mass);
						val5.yDrive = Calm(val5.yDrive, amount, mass);
						val5.zDrive = Calm(val5.zDrive, amount, mass);
					}
					val6 = (Joint)(object)val5;
				}
				else if ((Object)(object)val2 != (Object)null)
				{
					CharacterJoint val7 = dst.AddComponent<CharacterJoint>();
					((Joint)val7).connectedBody = connected;
					((Joint)val7).axis = ((Joint)val2).axis;
					val7.swingAxis = val2.swingAxis;
					val7.twistLimitSpring = val2.twistLimitSpring;
					val7.lowTwistLimit = val2.lowTwistLimit;
					val7.highTwistLimit = val2.highTwistLimit;
					val7.swingLimitSpring = val2.swingLimitSpring;
					val7.swing1Limit = val2.swing1Limit;
					val7.swing2Limit = val2.swing2Limit;
					val7.enableProjection = val2.enableProjection;
					val7.projectionDistance = val2.projectionDistance;
					val7.projectionAngle = val2.projectionAngle;
					if (amount < 0.999f)
					{
						val7.lowTwistLimit = Shrink(val7.lowTwistLimit, amount);
						val7.highTwistLimit = Shrink(val7.highTwistLimit, amount);
						val7.swing1Limit = Shrink(val7.swing1Limit, amount);
						val7.swing2Limit = Shrink(val7.swing2Limit, amount);
					}
					val6 = (Joint)(object)val7;
				}
				else if ((Object)(object)val3 != (Object)null)
				{
					SpringJoint obj = dst.AddComponent<SpringJoint>();
					((Joint)obj).connectedBody = connected;
					obj.spring = val3.spring;
					obj.damper = val3.damper;
					obj.minDistance = val3.minDistance;
					obj.maxDistance = val3.maxDistance * amount;
					obj.tolerance = val3.tolerance;
					obj.spring = val3.spring / amount + (1f - amount) * 60f * mass;
					obj.damper = val3.damper + (1f - amount) * 6f * mass;
					val6 = (Joint)(object)obj;
				}
				else if ((Object)(object)val4 != (Object)null)
				{
					HingeJoint obj2 = dst.AddComponent<HingeJoint>();
					((Joint)obj2).connectedBody = connected;
					((Joint)obj2).axis = ((Joint)val4).axis;
					obj2.useSpring = val4.useSpring;
					obj2.spring = val4.spring;
					obj2.useLimits = val4.useLimits;
					JointLimits limits = val4.limits;
					((JointLimits)(ref limits)).min = ((JointLimits)(ref limits)).min * amount;
					((JointLimits)(ref limits)).max = ((JointLimits)(ref limits)).max * amount;
					obj2.limits = limits;
					obj2.useMotor = val4.useMotor;
					obj2.motor = val4.motor;
					val6 = (Joint)(object)obj2;
				}
				else
				{
					FixedJoint obj3 = dst.AddComponent<FixedJoint>();
					((Joint)obj3).connectedBody = connected;
					val6 = (Joint)(object)obj3;
				}
				val6.autoConfigureConnectedAnchor = false;
				val6.anchor = src.anchor;
				val6.connectedAnchor = src.connectedAnchor;
				val6.enableCollision = false;
				val6.enablePreprocessing = src.enablePreprocessing;
				val6.breakForce = src.breakForce;
				val6.breakTorque = src.breakTorque;
				val6.massScale = src.massScale;
				val6.connectedMassScale = src.connectedMassScale;
			}

			private void AddColliders(Transform old, Transform nt)
			{
				//IL_014e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0153: Unknown result type (might be due to invalid IL or missing references)
				//IL_0155: Unknown result type (might be due to invalid IL or missing references)
				//IL_0161: Unknown result type (might be due to invalid IL or missing references)
				//IL_016d: 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)
				if (_fordColliders == null)
				{
					_fordColliders = ((Component)_freshRoot).GetComponentsInChildren<Collider>(true);
				}
				List<Collider> list = new List<Collider>();
				foreach (Collider componentsInChild in ((Component)old).GetComponentsInChildren<Collider>(true))
				{
					if ((Object)(object)componentsInChild == (Object)null || componentsInChild.isTrigger)
					{
						continue;
					}
					Transform val = ((Component)componentsInChild).transform;
					while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)old && (Object)(object)((Component)val).GetComponent<Rigidbody>() == (Object)null)
					{
						val = val.parent;
					}
					if (!((Object)(object)val != (Object)(object)old))
					{
						Transform val2 = (((Object)(object)((Component)componentsInChild).transform == (Object)(object)old) ? nt : Target(((Component)componentsInChild).transform));
						Collider val3 = CloneCollider(componentsInChild, ((Component)val2).gameObject);
						if (!((Object)(object)val3 == (Object)null))
						{
							((Component)val2).gameObject.layer = ((Component)componentsInChild).gameObject.layer;
							list.Add(val3);
						}
					}
				}
				if (list.Count == 0)
				{
					float num = 0.05f;
					if (old.childCount > 0)
					{
						Vector3 val4 = old.GetChild(0).position - old.position;
						num = ((Vector3)(ref val4)).magnitude;
					}
					float num2 = Mathf.Clamp(num * 0.4f, 0.01f, 0.08f);
					Vector3 lossyScale = nt.lossyScale;
					float num3 = Mathf.Max(Mathf.Abs(lossyScale.x), Mathf.Max(Mathf.Abs(lossyScale.y), Mathf.Abs(lossyScale.z)));
					SphereCollider val5 = ((Component)nt).gameObject.AddComponent<SphereCollider>();
					val5.radius = ((num3 > 0f) ? (num2 / num3) : num2);
					if (_fordColliders.Length > 0 && (Object)(object)_fordColliders[0] != (Object)null)
					{
						((Component)nt).gameObject.layer = ((Component)_fordColliders[0]).gameObject.layer;
					}
					list.Add((Collider)(object)val5);
				}
				foreach (Collider item in list)
				{
					foreach (Collider fordCollider in _fordColliders)
					{
						if ((Object)(object)fordCollider != (Object)null)
						{
							Physics.IgnoreCollision(item, fordCollider, true);
						}
					}
					foreach (Collider jiggleCollider in _jiggleColliders)
					{
						if ((Object)(object)jiggleCollider != (Object)null)
						{
							Physics.IgnoreCollision(item, jiggleCollider, true);
						}
					}
					_jiggleColliders.Add(item);
				}
			}

			private static Collider CloneCollider(Collider c, GameObject go)
			{
				//IL_001a: 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_0097: 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)
				Collider val = null;
				SphereCollider val2 = ((Il2CppObjectBase)c).TryCast<SphereCollider>();
				if ((Object)(object)val2 != (Object)null)
				{
					SphereCollider obj = go.AddComponent<SphereCollider>();
					obj.center = val2.center;
					obj.radius = val2.radius;
					val = (Collider)(object)obj;
				}
				else
				{
					CapsuleCollider val3 = ((Il2CppObjectBase)c).TryCast<CapsuleCollider>();
					if ((Object)(object)val3 != (Object)null)
					{
						CapsuleCollider obj2 = go.AddComponent<CapsuleCollider>();
						obj2.center = val3.center;
						obj2.radius = val3.radius;
						obj2.height = val3.height;
						obj2.direction = val3.direction;
						val = (Collider)(object)obj2;
					}
					else
					{
						BoxCollider val4 = ((Il2CppObjectBase)c).TryCast<BoxCollider>();
						if ((Object)(object)val4 != (Object)null)
						{
							BoxCollider obj3 = go.AddComponent<BoxCollider>();
							obj3.center = val4.center;
							obj3.size = val4.size;
							val = (Collider)(object)obj3;
						}
						else
						{
							MeshCollider val5 = ((Il2CppObjectBase)c).TryCast<MeshCollider>();
							if ((Object)(object)val5 != (Object)null && (Object)(object)val5.sharedMesh != (Object)null)
							{
								MeshCollider obj4 = go.AddComponent<MeshCollider>();
								obj4.sharedMesh = val5.sharedMesh;
								obj4.convex = true;
								val = (Collider)(object)obj4;
							}
						}
					}
				}
				if ((Object)(object)val != (Object)null)
				{
					val.sharedMaterial = c.sharedMaterial;
				}
				return val;
			}

			private bool HasMappedAncestor(Transform t)
			{
				Transform val = t;
				while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)_oldRoot)
				{
					if (Map.ContainsKey(((Object)val).GetInstanceID()))
					{
						return true;
					}
					val = val.parent;
				}
				return false;
			}

			private Transform NewHelper(Transform parent, string name)
			{
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Expected O, but got Unknown
				GameObject val = new GameObject("NR_" + name);
				val.transform.SetParent(parent, false);
				_rev.Added.Add(val);
				HelperCount++;
				return val.transform;
			}

			private static Vector3 Div(Vector3 a, Vector3 b)
			{
				//IL_0000: 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_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				//IL_0035: 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_0056: 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_0063: Unknown result type (might be due to invalid IL or missing references)
				return new Vector3((b.x != 0f) ? (a.x / b.x) : 1f, (b.y != 0f) ? (a.y / b.y) : 1f, (b.z != 0f) ? (a.z / b.z) : 1f);
			}

			public Transform Target(Transform old)
			{
				//IL_007d: Unknown result type (might be due to invalid IL or missing references)
				//IL_008a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0096: 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_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_0180: Unknown result type (might be due to invalid IL or missing references)
				//IL_0185: Unknown result type (might be due to invalid IL or missing references)
				//IL_018b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0190: Unknown result type (might be due to invalid IL or missing references)
				//IL_019c: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
				//IL_010b: 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)
				if ((Object)(object)old == (Object)null)
				{
					return _freshHips;
				}
				int instanceID = ((Object)old).GetInstanceID();
				if (_targets.TryGetValue(instanceID, out var value))
				{
					return value;
				}
				if (_jiggle.TryGetValue(instanceID, out var value2))
				{
					return BuildJiggle(old, value2);
				}
				Transform val;
				if (Map.TryGetValue(instanceID, out var value3))
				{
					if (value3.Identity)
					{
						val = value3.Ford;
					}
					else
					{
						val = NewHelper(value3.Ford, ((Object)old).name);
						val.localPosition = Vector3.zero;
						val.localRotation = value3.Q;
						val.localScale = Div(old.lossyScale, value3.Ford.lossyScale);
					}
				}
				else if ((Object)(object)old.parent != (Object)null && (Object)(object)old != (Object)(object)_oldRoot && HasMappedAncestor(old.parent))
				{
					Transform parent = Target(old.parent);
					val = NewHelper(parent, ((Object)old).name);
					val.localPosition = old.localPosition;
					val.localRotation = old.localRotation;
					val.localScale = old.localScale;
				}
				else
				{
					Transform val2 = TopMapped();
					if ((Object)(object)val2 == (Object)null)
					{
						_targets[instanceID] = _freshHips;
						return _freshHips;
					}
					Transform parent2 = Target(val2);
					val = NewHelper(parent2, ((Object)old).name);
					val.localPosition = val2.InverseTransformPoint(old.position);
					val.localRotation = Quaternion.Inverse(val2.rotation) * old.rotation;
					val.localScale = Div(old.lossyScale, val2.lossyScale);
				}
				_targets[instanceID] = val;
				return val;
			}

			private Transform TopMapped()
			{
				if ((Object)(object)_top != (Object)null)
				{
					return _top;
				}
				int num = int.MaxValue;
				foreach (Transform componentsInChild in ((Component)_oldRoot).GetComponentsInChildren<Transform>(true))
				{
					if (Map.ContainsKey(((Object)componentsInChild).GetInstanceID()))
					{
						int num2 = 0;
						Transform val = componentsInChild;
						while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)_oldRoot)
						{
							num2++;
							val = val.parent;
						}
						if (num2 < num)
						{
							num = num2;
							_top = componentsInChild;
						}
					}
				}
				return _top;
			}

			public bool CopyAudioSource(AudioSource src, Transform freshRoot)
			{
				//IL_0041: Unknown result type (might be due to invalid IL or missing references)
				//IL_0047: Expected O, but got Unknown
				//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
				Transform val = (((Object)(object)((Component)src).transform != (Object)(object)_oldRoot && HasMappedAncestor(((Component)src).transform)) ? Target(((Component)src).transform) : freshRoot);
				GameObject val2 = new GameObject("NR_audio_" + ((Object)src).name);
				val2.transform.SetParent(val, false);
				_rev.Added.Add(val2);
				AudioSource val3 = val2.AddComponent<AudioSource>();
				val3.clip = src.clip;
				val3.outputAudioMixerGroup = src.outputAudioMixerGroup;
				val3.volume = src.volume;
				val3.pitch = src.pitch;
				val3.loop = src.loop;
				val3.spatialBlend = src.spatialBlend;
				val3.minDistance = src.minDistance;
				val3.maxDistance = src.maxDistance;
				val3.rolloffMode = src.rolloffMode;
				val3.dopplerLevel = src.dopplerLevel;
				val3.spread = src.spread;
				val3.priority = src.priority;
				val3.playOnAwake = src.playOnAwake;
				if (src.loop || src.playOnAwake)
				{
					val3.Play();
				}
				return true;
			}

			public void AttachRigidCopy(Transform src, Mesh mesh, Il2CppReferenceArray<Material> mats, bool asSkinned, SkinnedMeshRenderer blendSource)
			{
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: Expected O, but got Unknown
				//IL_0050: Unknown result type (might be due to invalid IL or missing references)
				//IL_0061: Unknown result type (might be due to invalid IL or missing references)
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				Transform parent = src.parent;
				if ((Object)(object)parent == (Object)null || (Object)(object)parent == (Object)(object)_oldRoot || !HasMappedAncestor(parent))
				{
					return;
				}
				Transform val = Target(parent);
				GameObject val2 = new GameObject(((Object)src).name);
				val2.transform.SetParent(val, false);
				val2.transform.localPosition = src.localPosition;
				val2.transform.localRotation = src.localRotation;
				val2.transform.localScale = src.localScale;
				_rev.Added.Add(val2);
				if (asSkinned)
				{
					SkinnedMeshRenderer val3 = val2.AddComponent<SkinnedMeshRenderer>();
					val3.sharedMesh = mesh;
					((Renderer)val3).sharedMaterials = mats;
					val3.updateWhenOffscreen = true;
					if ((Object)(object)blendSource != (Object)null)
					{
						CopyBlendShapes(blendSource, val3);
					}
				}
				else
				{
					val2.AddComponent<MeshFilter>().sharedMesh = mesh;
					((Renderer)val2.AddComponent<MeshRenderer>()).sharedMaterials = mats;
				}
			}
		}

		private static MelonPreferences_Category _prefs;

		private static MelonPreferences_Entry<bool> _autoMode;

		private static MelonPreferences_Entry<bool> _keepWeight;

		private static MelonPreferences_Entry<bool> _keepJiggle;

		private static MelonPreferences_Entry<float> _jiggleAmount;

		private static MelonPreferences_Entry<bool> _jiggleTouch;

		private static MelonPreferences_Entry<bool> _copySounds;

		private static MelonPreferences_Entry<bool> _onlyOriginalSounds;

		private static MelonPreferences_Entry<bool> _copyBehaviour;

		private static MelonPreferences_Entry<bool> _notifications;

		private static MelonPreferences_Entry<string> _replacementBarcode;

		private const float ScanInterval = 0.5f;

		private const float MinAgeBeforeFix = 0.4f;

		private const float SpawnTimeout = 8f;

		private const float MinBoneMatch = 0.5f;

		private const string FordBarcode = "c1534c5a-3fd8-4d50-9eaf-0695466f7264";

		private const string OldWrongBarcode = "SLZ.BONELAB.Content.Spawnable.NPCFord";

		private static readonly HashSet<string> PlayerParts = new HashSet<string> { "RigManager", "PhysicsRig" };

		private static readonly HashSet<string> LeftoverNpcParts = new HashSet<string> { "BehaviourBaseNav", "BehaviourGrabbableBaseNav", "BehaviourPowerLegs", "BehaviourCrabby", "BehaviourOmniwheel", "BehaviourBase" };

		private readonly List<Revived> _revived = new List<Revived>();

		private readonly HashSet<int> _revivedIds = new HashSet<int>();

		private readonly Dictionary<int, Pending> _pending = new Dictionary<int, Pending>();

		private readonly Dictionary<int, float> _firstSeen = new Dictionary<int, float>();

		private readonly HashSet<int> _skip = new HashSet<int>();

		private float _nextScan;

		private bool _loggedScanError;

		private static AudioClip _silence;

		private static readonly string[] NavSettings = new string[31]
		{
			"accuracy", "activeRange", "agroedAngSpeed", "agroedSpeed", "breakAgroHomeDistance", "breakAgroTargetDistance", "burstSize", "clipSize", "desiredGunDistance", "enableThrowAttack",
			"freezeWhileResting", "gunCooldown", "gunRange", "investigateRange", "reloadTime", "restingRange", "roamAngSpeed", "roamFrequency", "roamRange", "roamSpeed",
			"roamWaitDuration", "roamWanders", "throwCooldown", "throwMaxRange", "throwMinRange", "throwVelocity", "throwAttackUsesGravity", "isSoundAggroWhenInSecondaryZone", "baseColor", "agroColor",
			"emissColor"
		};

		private static readonly string[] LegsSettings = new string[17]
		{
			"breakEngagedHomeDistance", "breakEngagedTargetDistance", "combatProficiency", "crumbleDeath", "desiredDistance", "desiredMeleeDistance", "engagedSpeed", "followPlayer", "getUpWhileResting", "jumpCooldown",
			"meleeCooldown", "meleeRange", "mirrorSkill", "restingActivateRange", "throwGap", "throwSpeed", "engagedMode"
		};

		private static readonly string[] HealthSettings = new string[15]
		{
			"aggression", "bluntMult", "irritability", "isOrganic", "maxAppendageHp", "maxHitPoints", "maxStunSeconds", "minHeadImpact", "minLimbImpact", "minSpineImpact",
			"pierceMult", "placability", "stabMult", "stunRecovery", "vengefulness"
		};

		public override void OnInitializeMelon()
		{
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_0341: Unknown result type (might be due to invalid IL or missing references)
			//IL_037b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e0: Unknown result type (might be due to invalid IL or missing references)
			_prefs = MelonPreferences.CreateCategory("NPCReviver");
			_autoMode = _prefs.CreateEntry<bool>("AutoRefreshMode", true, "Auto Refresh Mode", (string)null, false, false, (ValueValidator)null, (string)null);
			_keepWeight = _prefs.CreateEntry<bool>("KeepOriginalWeight", true, "Keep Original Weight", (string)null, false, false, (ValueValidator)null, (string)null);
			_keepJiggle = _prefs.CreateEntry<bool>("KeepJigglePhysics", true, "Keep Jiggle Physics (hair, clothes, gear...)", (string)null, false, false, (ValueValidator)null, (string)null);
			_copySounds = _prefs.CreateEntry<bool>("CopySounds", true, "Copy the old NPC's voice/sounds", (string)null, false, false, (ValueValidator)null, (string)null);
			_onlyOriginalSounds = _prefs.CreateEntry<bool>("OnlyOriginalSounds", true, "Silence Ford sounds the old NPC didn't have", (string)null, false, false, (ValueValidator)null, (string)null);
			_copyBehaviour = _prefs.CreateEntry<bool>("CopyBehaviour", true, "Copy the old NPC's health/speed/combat settings", (string)null, false, false, (ValueValidator)null, (string)null);
			_jiggleAmount = _prefs.CreateEntry<float>("JiggleAmount", 0.4f, "Jiggle amount (0.1 = barely moves, 1 = original)", (string)null, false, false, (ValueValidator)null, (string)null);
			_jiggleTouch = _prefs.CreateEntry<bool>("JiggleTouchable", true, "Jiggle parts can be touched/pushed", (string)null, false, false, (ValueValidator)null, (string)null);
			_notifications = _prefs.CreateEntry<bool>("Notifications", true, "Notifications", (string)null, false, false, (ValueValidator)null, (string)null);
			_replacementBarcode = _prefs.CreateEntry<string>("ReplacementNpcBarcode", "c1534c5a-3fd8-4d50-9eaf-0695466f7264", "Barcode of the working NPC used as the new body (default = Ford)", (string)null, false, false, (ValueValidator)null, (string)null);
			if (string.IsNullOrWhiteSpace(_replacementBarcode.Value) || _replacementBarcode.Value == "SLZ.BONELAB.Content.Spawnable.NPCFord")
			{
				_replacementBarcode.Value = "c1534c5a-3fd8-4d50-9eaf-0695466f7264";
				_prefs.SaveToFile(false);
			}
			Page obj = Page.Root.CreatePage("Outdated NPC Fixer", new Color(0.45f, 1f, 0.6f), 0, true);
			obj.CreateFunction("Refresh Broken NPCs", Color.green, (Action)delegate
			{
				int num = SafeScan(manual: true);
				if (num == 0)
				{
					Notify("No broken NPCs found. Try Scan Report and check the console.", (NotificationType)0);
				}
				else
				{
					Notify("Refreshing " + num + " NPC" + ((num == 1) ? "" : "s") + "...", (NotificationType)0);
				}
			});
			obj.CreateBool("Auto Refresh Mode", Color.yellow, _autoMode.Value, (Action<bool>)delegate(bool v)
			{
				_autoMode.Value = v;
				_prefs.SaveToFile(false);
				Notify(v ? "Auto Refresh ON: broken NPCs get fixed when they spawn." : "Auto Refresh OFF.", (NotificationType)0);
			});
			obj.CreateBool("Keep Jiggle Physics", Color.cyan, _keepJiggle.Value, (Action<bool>)delegate(bool v)
			{
				_keepJiggle.Value = v;
				_prefs.SaveToFile(false);
			});
			obj.CreateFloat("Jiggle Amount", Color.cyan, _jiggleAmount.Value, 0.1f, 0.1f, 1f, (Action<float>)delegate(float v)
			{
				_jiggleAmount.Value = Mathf.Clamp(v, 0.1f, 1f);
				_prefs.SaveToFile(false);
			});
			obj.CreateBool("Touchable Jiggle", Color.cyan, _jiggleTouch.Value, (Action<bool>)delegate(bool v)
			{
				_jiggleTouch.Value = v;
				_prefs.SaveToFile(false);
			});
			obj.CreateBool("Only Original Sounds", Color.cyan, _onlyOriginalSounds.Value, (Action<bool>)delegate(bool v)
			{
				_onlyOriginalSounds.Value = v;
				_prefs.SaveToFile(false);
			});
			obj.CreateBool("Copy Behaviour (health, speed, combat)", Color.cyan, _copyBehaviour.Value, (Action<bool>)delegate(bool v)
			{
				_copyBehaviour.Value = v;
				_prefs.SaveToFile(false);
			});
			obj.CreateBool("Copy Sounds", Color.cyan, _copySounds.Value, (Action<bool>)delegate(bool v)
			{
				_copySounds.Value = v;
				_prefs.SaveToFile(false);
			});
			obj.CreateBool("Keep Original Weight", Color.cyan, _keepWeight.Value, (Action<bool>)delegate(bool v)
			{
				_keepWeight.Value = v;
				_prefs.SaveToFile(false);
			});
			obj.CreateFunction("Scan Report (console)", new Color(1f, 0.6f, 0.2f), (Action)delegate
			{
				Notify("Logged " + ScanReport() + " ragdoll-type objects to the MelonLoader console.", (NotificationType)0);
			});
			obj.CreateBool("Notifications", Color.white, _notifications.Value, (Action<bool>)delegate(bool v)
			{
				_notifications.Value = v;
				_prefs.SaveToFile(false);
			});
			Hooking.OnLevelLoaded += delegate
			{
				ClearAll();
			};
			((MelonBase)this).LoggerInstance.Msg("Outdated NPC Fixer loaded. Auto Refresh Mode: " + (_autoMode.Value ? "ON" : "OFF"));
		}

		public override void OnFixedUpdate()
		{
			//IL_0046: 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)
			for (int i = 0; i < _revived.Count; i++)
			{
				Revived revived = _revived[i];
				for (int j = 0; j < revived.AnchorBodies.Count; j++)
				{
					Rigidbody val = revived.AnchorBodies[j];
					Transform val2 = revived.AnchorFollow[j];
					if (!((Object)(object)val == (Object)null) && !((Object)(object)val2 == (Object)null))
					{
						val.MovePosition(val2.position);
						val.MoveRotation(val2.rotation);
					}
				}
			}
		}

		public override void OnUpdate()
		{
			for (int num = _revived.Count - 1; num >= 0; num--)
			{
				Revived revived = _revived[num];
				if ((Object)(object)revived.Npc == (Object)null)
				{
					_revivedIds.Remove(revived.Id);
					_revived.RemoveAt(num);
				}
				else if (!revived.Npc.activeInHierarchy)
				{
					Restore(revived);
					_revivedIds.Remove(revived.Id);
					_revived.RemoveAt(num);
				}
			}
			if (_pending.Count > 0)
			{
				Poolee[] array = null;
				List<KeyValuePair<int, GameObject>> list = null;
				foreach (KeyValuePair<int, Pending> item in _pending)
				{
					if (Time.time - item.Value.Started < 0.1f)
					{
						continue;
					}
					if (array == null)
					{
						array = Il2CppArrayBase<Poolee>.op_Implicit(Object.FindObjectsOfType<Poolee>());
					}
					GameObject val = null;
					try
					{
						val = FindSpawnedReplacement(item.Value, array);
					}
					catch (Exception ex)
					{
						((MelonBase)this).LoggerInstance.Warning("Replacement search failed: " + ex.Message);
					}
					if ((Object)(object)val != (Object)null)
					{
						if (list == null)
						{
							list = new List<KeyValuePair<int, GameObject>>();
						}
						list.Add(new KeyValuePair<int, GameObject>(item.Key, val));
					}
				}
				if (list != null)
				{
					foreach (KeyValuePair<int, GameObject> item2 in list)
					{
						try
						{
							OnReplacementSpawned(item2.Value, item2.Key, "search");
						}
						catch (Exception ex2)
						{
							((MelonBase)this).LoggerInstance.Error("Revive failed: " + ex2);
						}
					}
				}
			}
			if (_pending.Count > 0)
			{
				List<int> list2 = null;
				foreach (KeyValuePair<int, Pending> item3 in _pending)
				{
					if (Time.time - item3.Value.Started > 8f)
					{
						if (list2 == null)
						{
							list2 = new List<int>();
						}
						list2.Add(item3.Key);
					}
				}
				if (list2 != null)
				{
					foreach (int item4 in list2)
					{
						((MelonBase)this).LoggerInstance.Warning("Timed out waiting for the replacement NPC for " + (((Object)(object)_pending[item4].Broken != (Object)null) ? ((Object)_pending[item4].Broken).name : "?"));
						Unfreeze(_pending[item4]);
						_pending.Remove(item4);
						_skip.Add(item4);
					}
					Notify("Couldn't spawn the replacement NPC. Check the barcode in MelonPreferences.", (NotificationType)2);
				}
			}
			if (_autoMode.Value && Time.time >= _nextScan)
			{
				_nextScan = Time.time + 0.5f;
				SafeScan(manual: false);
			}
		}

		private void ClearAll()
		{
			_revived.Clear();
			_revivedIds.Clear();
			_pending.Clear();
			_firstSeen.Clear();
			_skip.Clear();
		}

		private int SafeScan(bool manual)
		{
			try
			{
				return Scan(manual);
			}
			catch (Exception ex)
			{
				if (!_loggedScanError)
				{
					_loggedScanError = true;
					((MelonBase)this).LoggerInstance.Error("Scan failed: " + ex);
				}
				return 0;
			}
		}

		private int Scan(bool manual)
		{
			Il2CppArrayBase<Poolee> obj = Object.FindObjectsOfType<Poolee>();
			HashSet<int> activeNow = new HashSet<int>();
			int num = 0;
			foreach (Poolee item in obj)
			{
				if ((Object)(object)item == (Object)null)
				{
					continue;
				}
				GameObject gameObject = ((Component)item).gameObject;
				if ((Object)(object)gameObject == (Object)null || !gameObject.activeInHierarchy)
				{
					continue;
				}
				int instanceID = ((Object)gameObject).GetInstanceID();
				activeNow.Add(instanceID);
				if (_skip.Contains(instanceID) || _pending.ContainsKey(instanceID) || _revivedIds.Contains(instanceID))
				{
					continue;
				}
				if (!_firstSeen.TryGetValue(instanceID, out var value))
				{
					value = Time.time;
					_firstSeen[instanceID] = value;
				}
				if (manual || !(Time.time - value < 0.4f))
				{
					bool flag;
					try
					{
						flag = IsBrokenNpc(gameObject);
					}
					catch (Exception ex)
					{
						flag = false;
						((MelonBase)this).LoggerInstance.Warning("Couldn't inspect " + ((Object)gameObject).name + ": " + ex.Message);
					}
					if (!flag)
					{
						_skip.Add(instanceID);
					}
					else if (StartRevive(gameObject, instanceID))
					{
						num++;
					}
				}
			}
			_skip.RemoveWhere((int id) => !activeNow.Contains(id));
			List<int> list = new List<int>();
			foreach (KeyValuePair<int, float> item2 in _firstSeen)
			{
				if (!activeNow.Contains(item2.Key))
				{
					list.Add(item2.Key);
				}
			}
			foreach (int item3 in list)
			{
				_firstSeen.Remove(item3);
			}
			return num;
		}

		private static bool IsBrokenNpc(GameObject go)
		{
			return Inspect(go).Broken;
		}

		private static ScanInfo Inspect(GameObject go)
		{
			ScanInfo scanInfo = new ScanInfo
			{
				Player = IsUnderPlayerRig(go.transform)
			};
			foreach (Component componentsInChild in go.GetComponentsInChildren<Component>(true))
			{
				if ((Object)(object)componentsInChild == (Object)null)
				{
					scanInfo.Missing++;
					continue;
				}
				Type val = ((Object)componentsInChild).GetIl2CppType();
				switch (((MemberInfo)val).Name)
				{
				case "Rigidbody":
					scanInfo.Bodies++;
					continue;
				case "ConfigurableJoint":
				case "CharacterJoint":
					scanInfo.Joints++;
					continue;
				case "MonoBehaviour":
					scanInfo.Missing++;
					continue;
				}
				int num = 0;
				while (val != (Type)null && num < 12)
				{
					string name = ((MemberInfo)val).Name;
					if (name == "AIBrain")
					{
						scanInfo.Brain = true;
					}
					else if (name == "PuppetMaster")
					{
						scanInfo.Puppet = true;
					}
					else if (PlayerParts.Contains(name))
					{
						scanInfo.Player = true;
					}
					else if (LeftoverNpcParts.Contains(name))
					{
						scanInfo.Leftover = true;
					}
					val = val.BaseType;
					num++;
				}
			}
			foreach (SkinnedMeshRenderer componentsInChild2 in go.GetComponentsInChildren<SkinnedMeshRenderer>(true))
			{
				if (!((Object)(object)componentsInChild2 == (Object)null) && !((Object)(object)componentsInChild2.sharedMesh == (Object)null) && componentsInChild2.bones != null && ((Il2CppArrayBase<Transform>)(object)componentsInChild2.bones).Length > scanInfo.Bones)
				{
					scanInfo.Bones = ((Il2CppArrayBase<Transform>)(object)componentsInChild2.bones).Length;
				}
			}
			scanInfo.Body = scanInfo.Bones >= 10;
			return scanInfo;
		}

		private int ScanReport()
		{
			int num = 0;
			HashSet<int> hashSet = new HashSet<int>();
			((MelonBase)this).LoggerInstance.Msg("===== Outdated NPC Fixer scan report =====");
			try
			{
				foreach (Poolee item in Object.FindObjectsOfType<Poolee>())
				{
					if (!((Object)(object)item == (Object)null) && ((Component)item).gameObject.activeInHierarchy)
					{
						GameObject gameObject = ((Component)item).gameObject;
						hashSet.Add(((Object)gameObject).GetInstanceID());
						ScanInfo scanInfo = Inspect(gameObject);
						if (scanInfo.Bodies >= 3 || scanInfo.Body)
						{
							((MelonBase)this).LoggerInstance.Msg("[Poolee] " + ((Object)gameObject).name + " | " + scanInfo);
							num++;
						}
					}
				}
				foreach (SkinnedMeshRenderer item2 in Object.FindObjectsOfType<SkinnedMeshRenderer>())
				{
					if ((Object)(object)item2 == (Object)null || item2.bones == null || ((Il2CppArrayBase<Transform>)(object)item2.bones).Length < 10 || (Object)(object)((Component)item2).GetComponentInParent<Poolee>() != (Object)null)
					{
						continue;
					}
					GameObject gameObject2 = ((Component)((Component)item2).transform.root).gameObject;
					if (hashSet.Add(((Object)gameObject2).GetInstanceID()))
					{
						ScanInfo scanInfo2 = Inspect(gameObject2);
						if (!scanInfo2.Player)
						{
							((MelonBase)this).LoggerInstance.Msg("[NOT pooled] " + ((Object)gameObject2).name + " | " + scanInfo2);
							num++;
						}
					}
				}
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Error("Scan report failed: " + ex);
			}
			((MelonBase)this).LoggerInstance.Msg("===== end of report (" + num + " objects) =====");
			return num;
		}

		private static bool IsUnderPlayerRig(Transform t)
		{
			Transform parent = t.parent;
			while ((Object)(object)parent != (Object)null)
			{
				foreach (Component component in ((Component)parent).GetComponents<Component>())
				{
					if ((Object)(object)component != (Object)null && ((MemberInfo)((Object)component).GetIl2CppType()).Name == "RigManager")
					{
						return true;
					}
				}
				parent = parent.parent;
			}
			return false;
		}

		private unsafe bool StartRevive(GameObject broken, int id)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: 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_01d8: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = FindGround(FindHips(broken).position, broken.transform);
			Quaternion val2 = FacePlayer(val, broken.transform);
			Pending pending = new Pending
			{
				Broken = broken,
				Started = Time.time,
				SpawnPos = val
			};
			foreach (Poolee item in Object.FindObjectsOfType<Poolee>())
			{
				if ((Object)(object)item != (Object)null && ((Component)item).gameObject.activeInHierarchy)
				{
					pending.ActiveBefore.Add(((Object)((Component)item).gameObject).GetInstanceID());
				}
			}
			Instance loggerInstance = ((MelonBase)this).LoggerInstance;
			string[] obj = new string[6]
			{
				"Broken NPC found: ",
				((Object)broken).name,
				" -> spawning ",
				_replacementBarcode.Value,
				" at ",
				null
			};
			Vector3 val3 = val;
			obj[5] = ((object)(*(Vector3*)(&val3))/*cast due to .constrained prefix*/).ToString();
			loggerInstance.Msg(string.Concat(obj));
			foreach (Rigidbody componentsInChild in broken.GetComponentsInChildren<Rigidbody>(true))
			{
				pending.Bodies.Add(componentsInChild);
				pending.WasKinematic.Add(componentsInChild.isKinematic);
				componentsInChild.isKinematic = true;
			}
			foreach (Collider componentsInChild2 in broken.GetComponentsInChildren<Collider>(true))
			{
				pending.Colliders.Add(componentsInChild2);
				pending.ColliderWasEnabled.Add(componentsInChild2.enabled);
				componentsInChild2.enabled = false;
			}
			_pending[id] = pending;
			try
			{
				HelperMethods.SpawnCrate(_replacementBarcode.Value, val, val2, Vector3.one, true, (Action<GameObject>)delegate(GameObject fresh)
				{
					try
					{
						OnReplacementSpawned(fresh, id, "callback");
					}
					catch (Exception ex2)
					{
						MelonLogger.Error("[Outdated NPC Fixer] spawn callback failed: " + ex2);
					}
				}, (Action<GameObject>)null);
				return true;
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Error("Failed to spawn replacement NPC: " + ex);
				Unfreeze(pending);
				_pending.Remove(id);
				_skip.Add(id);
				return false;
			}
		}

		private GameObject FindSpawnedReplacement(Pending pending, Poolee[] poolees)
		{
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			GameObject result = null;
			float num = 6.25f;
			foreach (Poolee val in poolees)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				GameObject gameObject = ((Component)val).gameObject;
				if ((Object)(object)gameObject == (Object)null || !gameObject.activeInHierarchy || (Object)(object)gameObject == (Object)(object)pending.Broken)
				{
					continue;
				}
				int instanceID = ((Object)gameObject).GetInstanceID();
				if (pending.ActiveBefore.Contains(instanceID) || _revivedIds.Contains(instanceID))
				{
					continue;
				}
				Vector3 val2 = gameObject.transform.position - pending.SpawnPos;
				float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
				if (!(sqrMagnitude > num))
				{
					ScanInfo scanInfo = Inspect(gameObject);
					if (scanInfo.Brain && scanInfo.Puppet && !scanInfo.Player)
					{
						result = gameObject;
						num = sqrMagnitude;
					}
				}
			}
			return result;
		}

		private void OnReplacementSpawned(GameObject fresh, int brokenId, string how)
		{
			if (!_pending.TryGetValue(brokenId, out var value))
			{
				return;
			}
			_pending.Remove(brokenId);
			((MelonBase)this).LoggerInstance.Msg("Replacement NPC found via " + how + ": " + (((Object)(object)fresh != (Object)null) ? ((Object)fresh).name : "null"));
			GameObject broken = value.Broken;
			if ((Object)(object)fresh == (Object)null)
			{
				Unfreeze(value);
				_skip.Add(brokenId);
				return;
			}
			if ((Object)(object)broken == (Object)null || !broken.activeInHierarchy)
			{
				Despawn(fresh);
				return;
			}
			Revived revived = new Revived
			{
				Npc = fresh,
				Id = ((Object)fresh).GetInstanceID()
			};
			bool flag;
			try
			{
				flag = Transplant(broken, fresh, revived);
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Error("Transplant failed: " + ex);
				flag = false;
			}
			Unfreeze(value);
			if (!flag)
			{
				Restore(revived);
				Despawn(fresh);
				_skip.Add(brokenId);
				Notify("This NPC's skeleton is too different to refresh.", (NotificationType)1);
				return;
			}
			if (_copySounds.Value)
			{
				try
				{
					string report;
					int num = CopySounds(broken, fresh, revived, out report);
					((MelonBase)this).LoggerInstance.Msg((num < 0) ? "No sound data found on the old NPC (keeping Ford's voice)." : ("Copied " + num + " sound settings. " + report));
				}
				catch (Exception ex2)
				{
					((MelonBase)this).LoggerInstance.Warning("Copying sounds failed: " + ex2.Message);
				}
			}
			if (_copyBehaviour.Value)
			{
				try
				{
					int num2 = CopyBehaviour(broken, fresh, revived);
					((MelonBase)this).LoggerInstance.Msg((num2 < 0) ? "No behaviour settings found on the old NPC." : ("Copied " + num2 + " behaviour/health settings from the old NPC."));
				}
				catch (Exception ex3)
				{
					((MelonBase)this).LoggerInstance.Warning("Copying behaviour failed: " + ex3.Message);
				}
			}
			_revived.Add(revived);
			_revivedIds.Add(revived.Id);
			_firstSeen.Remove(brokenId);
			Despawn(broken);
			Notify("NPC refreshed!", (NotificationType)3);
		}

		private bool Transplant(GameObject broken, GameObject fresh, Revived rev)
		{
			//IL_0720: Unknown result type (might be due to invalid IL or missing references)
			//IL_0727: Expected O, but got Unknown
			//IL_07f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_07f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0867: Unknown result type (might be due to invalid IL or missing references)
			SkinnedMeshRenderer val = null;
			foreach (SkinnedMeshRenderer componentsInChild in fresh.GetComponentsInChildren<SkinnedMeshRenderer>(true))
			{
				if (!((Object)(object)componentsInChild == (Object)null) && componentsInChild.bones != null && ((Object)(object)val == (Object)null || ((Il2CppArrayBase<Transform>)(object)componentsInChild.bones).Length > ((Il2CppArrayBase<Transform>)(object)val.bones).Length))
				{
					val = componentsInChild;
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				MelonLogger.Warning("[Outdated NPC Fixer] Replacement NPC has no body mesh.");
				return false;
			}
			Transform val2 = (((Object)(object)val.rootBone != (Object)null) ? val.rootBone : ((Component)val).transform);
			List<SkinnedMeshRenderer> list = new List<SkinnedMeshRenderer>();
			Dictionary<int, Transform> dictionary = new Dictionary<int, Transform>();
			foreach (SkinnedMeshRenderer componentsInChild2 in broken.GetComponentsInChildren<SkinnedMeshRenderer>(false))
			{
				if ((Object)(object)componentsInChild2 == (Object)null || !((Renderer)componentsInChild2).enabled || (Object)(object)componentsInChild2.sharedMesh == (Object)null)
				{
					continue;
				}
				list.Add(componentsInChild2);
				if (componentsInChild2.bones == null)
				{
					continue;
				}
				foreach (Transform item in (Il2CppArrayBase<Transform>)(object)componentsInChild2.bones)
				{
					if ((Object)(object)item != (Object)null)
					{
						dictionary[((Object)item).GetInstanceID()] = item;
					}
				}
			}
			if (list.Count == 0 || dictionary.Count == 0)
			{
				MelonLogger.Warning("[Outdated NPC Fixer] Broken NPC has no visible skinned mesh to copy (" + list.Count + " meshes, " + dictionary.Count + " bones).");
				return false;
			}
			list.Sort((SkinnedMeshRenderer x, SkinnedMeshRenderer y) => ((y.bones != null) ? ((Il2CppArrayBase<Transform>)(object)y.bones).Length : 0).CompareTo((x.bones != null) ? ((Il2CppArrayBase<Transform>)(object)x.bones).Length : 0));
			Retarget retarget = new Retarget(broken.transform, fresh.transform, val2, rev);
			Dictionary<string, Transform> dictionary2 = new Dictionary<string, Transform>();
			foreach (Transform item2 in (Il2CppArrayBase<Transform>)(object)val.bones)
			{
				if (!((Object)(object)item2 == (Object)null))
				{
					string text = Norm(((Object)item2).name);
					if (text.Length > 0 && !dictionary2.ContainsKey(text))
					{
						dictionary2[text] = item2;
					}
				}
			}
			foreach (Transform componentsInChild3 in ((Component)val2).GetComponentsInChildren<Transform>(true))
			{
				string text2 = Norm(((Object)componentsInChild3).name);
				if (text2.Length > 0 && !dictionary2.ContainsKey(text2))
				{
					dictionary2[text2] = componentsInChild3;
				}
			}
			int num = 0;
			foreach (KeyValuePair<int, Transform> item3 in dictionary)
			{
				if (dictionary2.ContainsKey(Norm(((Object)item3.Value).name)))
				{
					num++;
				}
			}
			MelonLogger.Msg("[Outdated NPC Fixer] " + ((Object)broken).name + ": " + num + "/" + dictionary.Count + " bones match Ford by name");
			Dictionary<int, Transform> dictionary3 = new Dictionary<int, Transform>();
			foreach (Transform componentsInChild4 in broken.GetComponentsInChildren<Transform>(true))
			{
				if (!((Object)(object)componentsInChild4 == (Object)(object)broken.transform) && dictionary2.TryGetValue(Norm(((Object)componentsInChild4).name), out var value))
				{
					dictionary3[((Object)componentsInChild4).GetInstanceID()] = value;
				}
			}
			int num2 = 0;
			foreach (KeyValuePair<int, Transform> item4 in dictionary)
			{
				Transform val3 = item4.Value;
				while ((Object)(object)val3 != (Object)null && (Object)(object)val3 != (Object)(object)broken.transform)
				{
					if (dictionary3.ContainsKey(((Object)val3).GetInstanceID()))
					{
						num2++;
						break;
					}
					val3 = val3.parent;
				}
			}
			MelonLogger.Msg("[Outdated NPC Fixer] Ford-style rig bones found: " + dictionary3.Count + ", mesh bones attached to them: " + num2 + "/" + dictionary.Count);
			if ((float)num / (float)dictionary.Count >= 0.5f)
			{
				foreach (KeyValuePair<int, Transform> item5 in dictionary)
				{
					if (dictionary2.TryGetValue(Norm(((Object)item5.Value).name), out var value2))
					{
						retarget.Map[item5.Key] = new MapEntry
						{
							Ford = value2,
							Identity = true
						};
					}
				}
			}
			else if (dictionary3.Count >= 10 && (float)num2 / (float)dictionary.Count >= 0.8f)
			{
				foreach (KeyValuePair<int, Transform> item6 in dictionary3)
				{
					retarget.Map[item6.Key] = new MapEntry
					{
						Ford = item6.Value,
						Identity = true
					};
				}
				MelonLogger.Msg("[Outdated NPC Fixer] using the Ford-style rig the model is attached to");
			}
			else
			{
				Skeleton skeleton = Skeleton.Build(broken.transform, list);
				Skeleton skeleton2 = Skeleton.Build(fresh.transform, new List<SkinnedMeshRenderer> { val });
				string text3 = skeleton.FindAnchors();
				string text4 = skeleton2.FindAnchors();
				MelonLogger.Msg("[Outdated NPC Fixer] old rig: " + skeleton.Describe());
				MelonLogger.Msg("[Outdated NPC Fixer] Ford rig: " + skeleton2.Describe());
				if (text3 != null || text4 != null)
				{
					MelonLogger.Warning("[Outdated NPC Fixer] Couldn't read the skeleton: " + ((text3 != null) ? ("old NPC " + text3) : "") + ((text4 != null) ? (" Ford " + text4) : ""));
					return false;
				}
				int num3 = retarget.MapByStructure(skeleton, skeleton2);
				MelonLogger.Msg("[Outdated NPC Fixer] structure match: " + num3 + " body bones lined up");
				if (num3 < 8)
				{
					return false;
				}
			}
			if (retarget.Map.Count == 0)
			{
				return false;
			}
			if (_keepJiggle.Value)
			{
				MelonLogger.Msg("[Outdated NPC Fixer] jiggle bones found: " + retarget.FindJiggle(dictionary));
			}
			foreach (Renderer componentsInChild5 in fresh.GetComponentsInChildren<Renderer>(true))
			{
				if (!((Object)(object)componentsInChild5 == (Object)null))
				{
					rev.HiddenRenderers.Add(componentsInChild5);
					rev.HiddenWasEnabled.Add(componentsInChild5.enabled);
					componentsInChild5.enabled = false;
				}
			}
			GameObject val4 = new GameObject("NPCReviver_Model");
			val4.transform.SetParent(fresh.transform, false);
			rev.Added.Add(val4);
			foreach (SkinnedMeshRenderer item7 in list)
			{
				Il2CppReferenceArray<Transform> bones = item7.bones;
				if (bones == null || ((Il2CppArrayBase<Transform>)(object)bones).Length == 0)
				{
					retarget.AttachRigidCopy(((Component)item7).transform, item7.sharedMesh, ((Renderer)item7).sharedMaterials, asSkinned: true, item7);
					continue;
				}
				Il2CppReferenceArray<Transform> val5 = new Il2CppReferenceArray<Transform>((long)((Il2CppArrayBase<Transform>)(object)bones).Length);
				for (int num4 = 0; num4 < ((Il2CppArrayBase<Transform>)(object)bones).Length; num4++)
				{
					((Il2CppArrayBase<Transform>)(object)val5)[num4] = (((Object)(object)((Il2CppArrayBase<Transform>)(object)bones)[num4] == (Object)null) ? val2 : retarget.Target(((Il2CppArrayBase<Transform>)(object)bones)[num4]));
				}
				GameObject val6 = new GameObject(((Object)item7).name);
				val6.transform.SetParent(val4.transform, false);
				SkinnedMeshRenderer val7 = val6.AddComponent<SkinnedMeshRenderer>();
				val7.sharedMesh = item7.sharedMesh;
				((Renderer)val7).sharedMaterials = ((Renderer)item7).sharedMaterials;
				val7.bones = val5;
				val7.rootBone = (((Object)(object)item7.rootBone != (Object)null) ? retarget.Target(item7.rootBone) : val2);
				val7.updateWhenOffscreen = true;
				((Renderer)val7).shadowCastingMode = ((Renderer)item7).shadowCastingMode;
				((Renderer)val7).receiveShadows = ((Renderer)item7).receiveShadows;
				CopyBlendShapes(item7, val7);
			}
			foreach (MeshRenderer componentsInChild6 in broken.GetComponentsInChildren<MeshRenderer>(false))
			{
				if (!((Object)(object)componentsInChild6 == (Object)null) && ((Renderer)componentsInChild6).enabled)
				{
					MeshFilter component = ((Component)componentsInChild6).GetComponent<MeshFilter>();
					if (!((Object)(object)component == (Object)null) && !((Object)(object)component.sharedMesh == (Object)null))
					{
						retarget.AttachRigidCopy(((Component)componentsInChild6).transform, component.sharedMesh, ((Renderer)componentsInChild6).sharedMaterials, asSkinned: false, null);
					}
				}
			}
			if (_copySounds.Value)
			{
				int num5 = 0;
				foreach (AudioSource componentsInChild7 in broken.GetComponentsInChildren<AudioSource>(true))
				{
					if (!((Object)(object)componentsInChild7 == (Object)null) && !((Object)(object)componentsInChild7.clip == (Object)null) && retarget.CopyAudioSource(componentsInChild7, fresh.transform))
					{
						num5++;
					}
				}
				if (num5 > 0)
				{
					MelonLogger.Msg("[Outdated NPC Fixer] copied " + num5 + " extra sound players");
				}
			}
			MelonLogger.Msg("[Outdated NPC Fixer] model moved onto Ford (" + retarget.HelperCount + " helper bones, " + retarget.JiggleBuilt + " jiggle bodies)");
			if (_keepWeight.Value)
			{
				Dictionary<string, Rigidbody> dictionary4 = new Dictionary<string, Rigidbody>();
				foreach (Rigidbody componentsInChild8 in fresh.GetComponentsInChildren<Rigidbody>(true))
				{
					string text5 = Norm(((Object)componentsInChild8).name);
					if (text5.Length > 0 && !dictionary4.ContainsKey(text5))
					{
						dictionary4[text5] = componentsInChild8;
					}
				}
				foreach (Rigidbody componentsInChild9 in broken.GetComponentsInChildren<Rigidbody>(true))
				{
					if (dictionary4.TryGetValue(Norm(((Object)componentsInChild9).name), out var value3) && !(componentsInChild9.mass <= 0f))
					{
						rev.ChangedBodies.Add(value3);
						rev.OriginalMasses.Add(value3.mass);
						value3.mass = componentsInChild9.mass;
					}
				}
			}
			return true;
		}

		private static void SetWithBackup(Revived rev, object target, PropertyInfo p, object value)
		{
			object value2 = p.GetValue(target);
			p.SetValue(target, value);
			rev.BakTargets.Add(target);
			rev.BakProps.Add(p);
			rev.BakValues.Add(value2);
		}

		private static AudioClip Silence()
		{
			if ((Object)(object)_silence == (Object)null)
			{
				_silence = AudioClip.Create("NPCReviver_Silence", 256, 1, 44100, false);
				((Object)_silence).hideFlags = (HideFlags)32;
			}
			return _silence;
		}

		private static int CopySounds(GameObject broken, GameObject fresh, Revived rev, out string report)
		{
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Expected O, but got Unknown
			report = "";
			BehaviourBaseNav componentInChildren = broken.GetComponentInChildren<BehaviourBaseNav>(true);
			BehaviourBaseNav componentInChildren2 = fresh.GetComponentInChildren<BehaviourBaseNav>(true);
			if ((Object)(object)componentInChildren == (Object)null || (Object)(object)componentInChildren2 == (Object)null)
			{
				return -1;
			}
			SubBehaviourSfx sfx = componentInChildren.sfx;
			SubBehaviourSfx sfx2 = componentInChildren2.sfx;
			if (sfx == null || sfx2 == null)
			{
				return -1;
			}
			bool value = _onlyOriginalSounds.Value;
			List<string> list = new List<string>();
			List<string> list2 = new List<string>();
			int num = 0;
			PropertyInfo[] properties = typeof(SubBehaviourSfx).GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public);
			foreach (PropertyInfo propertyInfo in properties)
			{
				if (!propertyInfo.CanRead || !propertyInfo.CanWrite || propertyInfo.GetIndexParameters().Length != 0 || propertyInfo.Name.StartsWith("_"))
				{
					continue;
				}
				Type propertyType = propertyInfo.PropertyType;
				bool flag = propertyType == typeof(AudioClip);
				bool flag2 = propertyType.IsGenericType && propertyType.GetGenericArguments().Length == 1 && propertyType.GetGenericArguments()[0] == typeof(AudioClip);
				bool flag3 = propertyType == typeof(float);
				if (!flag && !flag2 && !flag3)
				{
					continue;
				}
				object obj = null;
				try
				{
					obj = propertyInfo.GetValue(sfx);
				}
				catch
				{
				}
				bool flag4 = (flag3 ? (obj != null) : ((!flag) ? (obj is Il2CppReferenceArray<AudioClip> val && ((Il2CppArrayBase<AudioClip>)(object)val).Length > 0) : (obj != null && (Object)(AudioClip)obj != (Object)null)));
				try
				{
					if (flag4)
					{
						SetWithBackup(rev, sfx2, propertyInfo, obj);
						num++;
						if (!flag3)
						{
							list.Add(propertyInfo.Name);
						}
					}
					else if (value && !flag3)
					{
						object value2 = (flag ? ((object)Silence()) : ((object)new Il2CppReferenceArray<AudioClip>((AudioClip[])(object)new AudioClip[1] { Silence() })));
						SetWithBackup(rev, sfx2, propertyInfo, value2);
						list2.Add(propertyInfo.Name);
					}
				}
				catch
				{
				}
			}
			report = "original sounds: " + ((list.Count > 0) ? string.Join(", ", list) : "none") + ((list2.Count > 0) ? (" | silenced Ford's: " + string.Join(", ", list2)) : "");
			return num;
		}

		private static int CopyNamed(object src, object dst, Type type, string[] names, Revived rev)
		{
			int num = 0;
			foreach (string name in names)
			{
				PropertyInfo property = type.GetProperty(name, BindingFlags.Instance | BindingFlags.Public);
				if (property == null || !property.CanRead || !property.CanWrite || !property.PropertyType.IsValueType)
				{
					continue;
				}
				try
				{
					object value = property.GetValue(src);
					if (!object.Equals(value, property.GetValue(dst)))
					{
						SetWithBackup(rev, dst, property, value);
						num++;
					}
				}
				catch
				{
				}
			}
			return num;
		}

		private static object AsRealType(Object obj, out Type type)
		{
			type = null;
			string fullName = obj.GetIl2CppType().FullName;
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				Type type2 = assembly.GetType("Il2Cpp" + fullName, throwOnError: false) ?? assembly.GetType(fullName, throwOnError: false);
				if (!(type2 == null) && typeof(Il2CppObjectBase).IsAssignableFrom(type2))
				{
					try
					{
						type = type2;
						return Activator.CreateInstance(type2, ((Il2CppObjectBase)obj).Pointer);
					}
					catch
					{
					}
				}
			}
			return null;
		}

		private static int CopyBehaviour(GameObject broken, GameObject fresh, Revived rev)
		{
			BehaviourBaseNav componentInChildren = broken.GetComponentInChildren<BehaviourBaseNav>(true);
			BehaviourBaseNav componentInChildren2 = fresh.GetComponentInChildren<BehaviourBaseNav>(true);
			if ((Object)(object)componentInChildren == (Object)null || (Object)(object)componentInChildren2 == (Object)null)
			{
				return -1;
			}
			int num = CopyNamed(componentInChildren, componentInChildren2, typeof(BehaviourBaseNav), NavSettings, rev);
			if (((Object)componentInChildren).GetIl2CppType().FullName == ((Object)componentInChildren2).GetIl2CppType().FullName)
			{
				Type type;
				object obj = AsRealType((Object)(object)componentInChildren, out type);
				Type type2;
				object obj2 = AsRealType((Object)(object)componentInChildren2, out type2);
				if (obj != null && obj2 != null && type == type2)
				{
					num += CopyNamed(obj, obj2, type, LegsSettings, rev);
				}
			}
			SubBehaviourHealth health = componentInChildren.health;
			SubBehaviourHealth health2 = componentInChildren2.health;
			if (health != null && health2 != null)
			{
				num += CopyNamed(health, health2, typeof(SubBehaviourHealth), HealthSettings, rev);
				try
				{
					PropertyInfo property = typeof(SubBehaviourHealth).GetProperty("cur_hp");
					PropertyInfo property2 = typeof(SubBehaviourHealth).GetProperty("maxHitPoints");
					if (property != null && property2 != null && property.PropertyType == property2.PropertyType)
					{
						SetWithBackup(rev, health2, property, property2.GetValue(health2));
					}
					PropertyInfo property3 = typeof(SubBehaviourHealth).GetProperty("maxAppendageHp");
					string[] array = new string[4] { "cur_arm_lf", "cur_arm_rt", "cur_leg_lf", "cur_leg_rt" };
					foreach (string name in array)
					{
						PropertyInfo property4 = typeof(SubBehaviourHealth).GetProperty(name);
						if (property4 != null && property3 != null && property4.PropertyType == property3.PropertyType)
						{
							SetWithBackup(rev, health2, property4, property3.GetValue(health2));
						}
					}
				}
				catch
				{
				}
			}
			return num;
		}

		private static void CopyBlendShapes(SkinnedMeshRenderer from, SkinnedMeshRenderer to)
		{
			if (!((Object)(object)from.sharedMesh == (Object)null))
			{
				int blendShapeCount = from.sharedMesh.blendShapeCount;
				for (int i = 0; i < blendShapeCount; i++)
				{
					to.SetBlendShapeWeight(i, from.GetBlendShapeWeight(i));
				}
			}
		}

		private static void Restore(Revived r)
		{
			for (int i = 0; i < r.HiddenRenderers.Count; i++)
			{
				if ((Object)(object)r.HiddenRenderers[i] != (Object)null)
				{
					r.HiddenRenderers[i].enabled = r.HiddenWasEnabled[i];
				}
			}
			for (int j = 0; j < r.ChangedBodies.Count; j++)
			{
				if ((Object)(object)r.ChangedBodies[j] != (Object)null)
				{
					r.ChangedBodies[j].mass = r.OriginalMasses[j];
				}
			}
			if (r.SfxTarget != null)
			{
				for (int k = 0; k < r.SfxProps.Count; k++)
				{
					try
					{
						r.SfxProps[k].SetValue(r.SfxTarget, r.SfxOriginal[k]);
					}
					catch
					{
					}
				}
			}
			for (int num = r.BakProps.Count - 1; num >= 0; num--)
			{
				try
				{
					r.BakProps[num].SetValue(r.BakTargets[num], r.BakValues[num]);
				}
				catch
				{
				}
			}
			r.BakTargets.Clear();
			r.BakProps.Clear();
			r.BakValues.Clear();
			r.SfxTarget = null;
			r.AnchorBodies.Clear();
			r.AnchorFollow.Clear();
			r.SfxProps.Clear();
			r.SfxOriginal.Clear();
			foreach (GameObject item in r.Added)
			{
				if ((Object)(object)item != (Object)null)
				{
					Object.Destroy((Object)(object)item);
				}
			}
			r.HiddenRenderers.Clear();
			r.HiddenWasEnabled.Clear();
			r.ChangedBodies.Clear();
			r.OriginalMasses.Clear();
			r.Added.Clear();
		}

		private static void Unfreeze(Pending p)
		{
			for (int i = 0; i < p.Colliders.Count; i++)
			{
				if ((Object)(object)p.Colliders[i] != (Object)null)
				{
					p.Colliders[i].enabled = p.ColliderWasEnabled[i];
				}
			}
			for (int j = 0; j < p.Bodies.Count; j++)
			{
				Rigidbody val = p.Bodies[j];
				if (!((Object)(object)val == (Object)null))
				{
					val.isKinematic = p.WasKinematic[j];
					if (!val.isKinematic)
					{
						val.WakeUp();
					}
				}
			}
		}

		private static void Despawn(GameObject go)
		{
			if ((Object)(object)go == (Object)null)
			{
				return;
			}
			try
			{
				Poolee component = go.GetComponent<Poolee>();
				if ((Object)(object)component != (Object)null)
				{
					component.Despawn();
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("[Outdated NPC Fixer] Despawn failed: " + ex.Message);
			}
			if ((Object)(object)go != (Object)null && go.activeSelf)
			{
				go.SetActive(false);
			}
		}

		private static Transform FindHips(GameObject go)
		{
			SkinnedMeshRenderer val = null;
			foreach (SkinnedMeshRenderer componentsInChild in go.GetComponentsInChildren<SkinnedMeshRenderer>(true))
			{
				if (!((Object)(object)componentsInChild == (Object)null) && componentsInChild.bones != null && ((Object)(object)val == (Object)null || ((Il2CppArrayBase<Transform>)(object)componentsInChild.bones).Length > ((Il2CppArrayBase<Transform>)(object)val.bones).Length))
				{
					val = componentsInChild;
				}
			}
			if ((Object)(object)val != (Object)null && (Object)(object)val.rootBone != (Object)null)
			{
				return val.rootBone;
			}
			Rigidbody val2 = null;
			foreach (Rigidbody componentsInChild2 in go.GetComponentsInChildren<Rigidbody>(true))
			{
				if ((Object)(object)val2 == (Object)null || componentsInChild2.mass > val2.mass)
				{
					val2 = componentsInChild2;
				}
			}
			if (!((Object)(object)val2 != (Object)null))
			{
				return go.transform;
			}
			return ((Component)val2).transform;
		}

		private static Vector3 FindGround(Vector3 from, Transform ignore)
		{
			//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_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or m