Decompiled source of GirlFartParty Suits v0.7.24

GirlFartParty_Suits.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ModelReplacement;
using ModelReplacement.AvatarBodyUpdater;
using ModelReplacement.Monobehaviors;
using MoreCompany;
using MoreCompany.Cosmetics;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Events;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("GirlFartParty_Suits")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+250597662a2bf7aa3383ac70fa06c514e59890b5")]
[assembly: AssemblyProduct("GirlFartParty_Suits")]
[assembly: AssemblyTitle("GirlFartParty_Suits")]
[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 GirlFartPartyMod
{
	public abstract class SuitReplacement : BodyReplacementBase
	{
		private HideVisor hideVisor;

		private EyeHeight eyeHeight;

		private GameObject prefabAsset;

		protected abstract string PrefabName { get; }

		protected override GameObject LoadAssetsAndReturnModel()
		{
			GameObject obj = Assets.MainAssetBundle.LoadAsset<GameObject>(PrefabName);
			CosmeticTuning.Apply(obj, ((BaseUnityPlugin)Plugin.Instance).Config);
			return obj;
		}

		public override void LateUpdate()
		{
			((BodyReplacementBase)this).LateUpdate();
			if ((Object)(object)prefabAsset == (Object)null)
			{
				prefabAsset = Assets.MainAssetBundle.LoadAsset<GameObject>(PrefabName);
			}
			FloorClamp.Apply(base.replacementModel, prefabAsset, ((BodyReplacementBase)this).controller);
			FloorClamp.Apply(base.replacementModelShadow, prefabAsset, ((BodyReplacementBase)this).controller);
			AfterPose();
			CosmeticTuning.PlaceOnAnchors((BodyReplacementBase)(object)this);
			(hideVisor ?? (hideVisor = new HideVisor((BodyReplacementBase)(object)this))).Update();
			if (eyeHeight == null && (Object)(object)base.replacementModel != (Object)null)
			{
				eyeHeight = new EyeHeight((BodyReplacementBase)(object)this, base.replacementModel);
				ItemAnchors.Register((BodyReplacementBase)(object)this, base.replacementModel);
			}
			eyeHeight?.Update();
		}

		protected virtual void AfterPose()
		{
		}

		protected override void OnDestroy()
		{
			hideVisor?.Restore();
			eyeHeight?.Restore();
			CosmeticTuning.OnRemoved((BodyReplacementBase)(object)this);
			((BodyReplacementBase)this).OnDestroy();
		}
	}
	public class MRMUSHROOMCHILD : SuitReplacement
	{
		protected override string PrefabName => "MushroomChild";
	}
	public class MRBABBLONG : SuitReplacement
	{
		protected override string PrefabName => "Babblong";
	}
	public class MRABRA : SuitReplacement
	{
		protected override string PrefabName => "Abra";
	}
	public abstract class QuadrupedSuit : SuitReplacement
	{
		private GameObject prefab;

		private GameObject registered;

		private protected abstract QuadrupedSpec Quad { get; }

		protected override void AfterPose()
		{
			if ((Object)(object)prefab == (Object)null)
			{
				prefab = Assets.MainAssetBundle.LoadAsset<GameObject>(PrefabName);
			}
			if ((Object)(object)registered != (Object)(object)((BodyReplacementBase)this).replacementModel && (Object)(object)((BodyReplacementBase)this).replacementModel != (Object)null)
			{
				HeldOnBack.Register(this, ((BodyReplacementBase)this).replacementModel);
				registered = ((BodyReplacementBase)this).replacementModel;
			}
			Transform feet = (((Object)(object)((BodyReplacementBase)this).controller != (Object)null) ? ((Component)((BodyReplacementBase)this).controller).transform : null);
			QuadrupedPose.Apply(((BodyReplacementBase)this).replacementModel, prefab, Quad, feet);
			QuadrupedPose.Apply(((BodyReplacementBase)this).replacementModelShadow, prefab, Quad, feet, log: false);
		}
	}
	public class MRABSOL : QuadrupedSuit
	{
		private static readonly QuadrupedSpec Spec = new QuadrupedSpec
		{
			LockToRest = new string[2] { "Spine1", "Spine2" },
			KeepWorld = new string[3] { "Head", "FakeArm1.L", "FakeArm1.R" },
			Body = "Waist",
			MirrorCopy = new(string, string)[6]
			{
				("LArm", "RThigh"),
				("LForeArm", "RLeg"),
				("LHand", "RToeA1"),
				("RArm", "LThigh"),
				("RForeArm", "LLeg"),
				("RHand", "LToeA1")
			},
			FrontLegs = new(string, string, string)[2]
			{
				("LArm", "LForeArm", "LHand"),
				("RArm", "RForeArm", "RHand")
			},
			HindPaws = new string[2] { "LToeA1", "RToeA1" }
		};

		protected override string PrefabName => "Absol";

		private protected override QuadrupedSpec Quad => Spec;
	}
	public class MRABSOLSHINY : MRABSOL
	{
		protected override string PrefabName => "AbsolShiny";
	}
	public class MRGOLDENHAMSTER : QuadrupedSuit
	{
		private static readonly QuadrupedSpec Spec = new QuadrupedSpec
		{
			LockToRest = new string[2] { "hara_bone", "mune_bone" },
			KeepWorld = new string[3] { "atama_bone", "FakeArm1.L", "FakeArm1.R" },
			Body = "koshi_bone",
			MirrorCopy = new(string, string)[6]
			{
				("L_ude_bone_1", "R_asi_bone_1"),
				("L_ude_bone_2", "R_asi_bone_2"),
				("L_hand", "R_asi_bone_3"),
				("R_ude_bone_1", "L_asi_bone_1"),
				("R_ude_bone_2", "L_asi_bone_2"),
				("R_hand", "L_asi_bone_3")
			},
			FrontLegs = new(string, string, string)[2]
			{
				("L_ude_bone_1", "L_ude_bone_2", "L_hand"),
				("R_ude_bone_1", "R_ude_bone_2", "R_hand")
			},
			HindPaws = new string[2] { "L_asi_bone_3", "R_asi_bone_3" }
		};

		protected override string PrefabName => "GoldenHamster";

		private protected override QuadrupedSpec Quad => Spec;
	}
	public class MRRENAMON : SuitReplacement
	{
		protected override string PrefabName => "Renamon";
	}
	public class MRSHINX : QuadrupedSuit
	{
		private static readonly QuadrupedSpec Spec = new QuadrupedSpec
		{
			LockToRest = new string[1] { "spine" },
			KeepWorld = new string[4] { "neck", "head", "FakeArm1.L", "FakeArm1.R" },
			Body = "hips",
			MirrorCopy = new(string, string)[6]
			{
				("Left_Arm", "Right_UpLeg"),
				("Left_ForeArm", "Right_Leg"),
				("Left_Hand", "Right_Foot"),
				("Right_Arm", "Left_UpLeg"),
				("Right_ForeArm", "Left_Leg"),
				("Right_Hand", "Left_Foot")
			},
			FrontLegs = new(string, string, string)[2]
			{
				("Left_Arm", "Left_ForeArm", "Left_Hand"),
				("Right_Arm", "Right_ForeArm", "Right_Hand")
			},
			HindPaws = new string[2] { "Left_Foot", "Right_Foot" }
		};

		protected override string PrefabName => "Shinx";

		private protected override QuadrupedSpec Quad => Spec;
	}
	public class MRSHINXSHINY : MRSHINX
	{
		protected override string PrefabName => "ShinxShiny";
	}
	public class MRSPOTTEDPUPPY : QuadrupedSuit
	{
		private static readonly QuadrupedSpec Spec = new QuadrupedSpec
		{
			LockToRest = new string[1] { "Spine" },
			KeepWorld = new string[3] { "Head", "FakeArm1.L", "FakeArm1.R" },
			Body = "Root",
			MirrorCopy = new(string, string)[6]
			{
				("L_FrontUpper", "R_BackThigh"),
				("L_FrontLower", "R_BackShin"),
				("L_FrontFoot", "R_BackFoot"),
				("R_FrontUpper", "L_BackThigh"),
				("R_FrontLower", "L_BackShin"),
				("R_FrontFoot", "L_BackFoot")
			},
			FrontLegs = new(string, string, string)[2]
			{
				("L_FrontUpper", "L_FrontLower", "L_FrontFoot"),
				("R_FrontUpper", "R_FrontLower", "R_FrontFoot")
			},
			HindPaws = new string[2] { "L_BackFoot", "R_BackFoot" }
		};

		protected override string PrefabName => "SpottedPuppy";

		private protected override QuadrupedSpec Quad => Spec;
	}
	public class MRRIKU : SuitReplacement
	{
		protected override string PrefabName => "Riku";
	}
	public class MRPIGEON : SuitReplacement
	{
		protected override string PrefabName => "Pigeon";
	}
	internal static class CosmeticTuning
	{
		private class Slot
		{
			public string Name;

			public int MoreCompanyType;

			public HumanBodyBones[] Bones;

			public ConfigEntry<bool> Show;
		}

		private static readonly Quaternion BlenderToUnity = Quaternion.Euler(270f, 0f, 0f);

		internal const int FaceKey = 100;

		private static Slot faceSlot;

		private static ConfigEntry<string> faceKeywords;

		private static ConfigEntry<string> faceIds;

		private static ConfigEntry<string> hatIds;

		private static readonly Dictionary<string, bool> faceCache = new Dictionary<string, bool>();

		private static readonly HashSet<string> BuiltinFaceIds = new HashSet<string> { "builtin.fancypants" };

		private static readonly List<Slot> slots = new List<Slot>
		{
			new Slot
			{
				Name = "Hat",
				MoreCompanyType = 0,
				Bones = (HumanBodyBones[])(object)new HumanBodyBones[1] { (HumanBodyBones)10 }
			},
			new Slot
			{
				Name = "Chest",
				MoreCompanyType = 2,
				Bones = (HumanBodyBones[])(object)new HumanBodyBones[2]
				{
					(HumanBodyBones)54,
					(HumanBodyBones)8
				}
			},
			new Slot
			{
				Name = "RightForearm",
				MoreCompanyType = 3,
				Bones = (HumanBodyBones[])(object)new HumanBodyBones[1] { (HumanBodyBones)16 }
			},
			new Slot
			{
				Name = "Hip",
				MoreCompanyType = 4,
				Bones = (HumanBodyBones[])(object)new HumanBodyBones[1]
			},
			new Slot
			{
				Name = "LeftShin",
				MoreCompanyType = 5,
				Bones = (HumanBodyBones[])(object)new HumanBodyBones[1] { (HumanBodyBones)3 }
			},
			new Slot
			{
				Name = "RightShin",
				MoreCompanyType = 6,
				Bones = (HumanBodyBones[])(object)new HumanBodyBones[1] { (HumanBodyBones)4 }
			},
			new Slot
			{
				Name = "Face",
				MoreCompanyType = 100,
				Bones = (HumanBodyBones[])(object)new HumanBodyBones[0]
			}
		};

		private static ConfigEntry<bool> useAnchors;

		internal static ConfigEntry<bool> debugLog;

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

		internal static bool FaceShown
		{
			get
			{
				if (faceSlot != null)
				{
					return faceSlot.Show.Value;
				}
				return true;
			}
		}

		public static void Bind(ConfigFile config)
		{
			debugLog = config.Bind<bool>("Debug", "Cosmetic diagnostics", false, "Log where each cosmetic is placed ([AnchorDiag]) and dump all cosmetics while emoting ([SceneDump]).");
			useAnchors = config.Bind<bool>("Cosmetics", "Use model anchors", true, "Place MoreCompany cosmetics on the anchors built into this model. Off = ModelReplacementAPI's default placement.");
			foreach (Slot slot in slots)
			{
				slot.Show = config.Bind<bool>("Cosmetics." + slot.Name, "Show", true, "Show " + slot.Name + " cosmetics on this model. (Wrist cosmetics are never shown on model replacements.)");
			}
			faceSlot = slots.First((Slot s) => s.MoreCompanyType == 100);
			faceKeywords = config.Bind<string>("Cosmetics.Face", "Face keywords", "glasses,goggle,monocle,eye,mask,face,brow,chin,nose,rudolph,mustache,moustache,beard,mouth,teeth,lips,visor", "Head cosmetics whose id contains one of these words (comma separated, case-insensitive) go on the model's face anchor instead of the hat anchor. Ids are listed in BepInEx/LogOutput.log ('Loaded cosmetic: ...').");
			faceIds = config.Bind<string>("Cosmetics.Face", "Extra face cosmetic ids", "", "Comma separated cosmetic ids that always go on the face anchor (e.g. kirby.pepe).");
			hatIds = config.Bind<string>("Cosmetics.Face", "Never face cosmetic ids", "", "Comma separated cosmetic ids that always stay on the hat anchor even if a keyword matches.");
		}

		public static void Apply(GameObject prefab, ConfigFile config)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			config.Reload();
			Animator componentInChildren = prefab.GetComponentInChildren<Animator>(true);
			if ((Object)(object)componentInChildren == (Object)null || (Object)(object)componentInChildren.avatar == (Object)null)
			{
				return;
			}
			Dictionary<string, string> dictionary = componentInChildren.avatar.humanDescription.human.ToDictionary((HumanBone h) => ((HumanBone)(ref h)).humanName, (HumanBone h) => ((HumanBone)(ref h)).boneName);
			Transform[] componentsInChildren = prefab.GetComponentsInChildren<Transform>(true);
			bool flag = componentsInChildren.Any((Transform t) => ((Object)t).name.StartsWith("Cosmetic_"));
			foreach (Slot slot in slots)
			{
				Transform val = null;
				HumanBodyBones[] bones = slot.Bones;
				foreach (HumanBodyBones val2 in bones)
				{
					if (dictionary.TryGetValue(HumanTrait.BoneName[val2], out var boneName) && (Object)(object)(val = ((IEnumerable<Transform>)componentsInChildren).FirstOrDefault((Func<Transform, bool>)((Transform t) => ((Object)t).name == boneName))) != (Object)null)
					{
						break;
					}
				}
				if (!((Object)(object)val == (Object)null))
				{
					RotationOffset val3 = ((Component)val).GetComponent<RotationOffset>();
					if ((Object)(object)val3 == (Object)null)
					{
						val3 = ((Component)val).gameObject.AddComponent<RotationOffset>();
					}
					val3.RenderMCC = slot.Show.Value;
					val3.MCCPosition = Vector3.zero;
					val3.MCCRotation = Quaternion.Inverse(val3.offset);
				}
			}
			Plugin.Log.LogInfo((object)("Cosmetics: " + ((flag && useAnchors.Value) ? "using model anchors" : "API placement (no anchors)")));
		}

		public static void PlaceOnAnchors(BodyReplacementBase br)
		{
			if (!ModelReplacementAPI.moreCompanyPresent || !useAnchors.Value || (Object)(object)br.controller == (Object)null)
			{
				return;
			}
			GameObject val = (((Object)(object)br.replacementDeadBody != (Object)null && br.replacementDeadBody.activeInHierarchy) ? br.replacementDeadBody : br.replacementModel);
			if (!((Object)(object)val == (Object)null))
			{
				Dictionary<int, Transform> dictionary = AnchorsFor(val);
				if (dictionary.Count != 0)
				{
					MoreCompanyBridge.Place(br, dictionary);
				}
			}
		}

		public static void OnRemoved(BodyReplacementBase br)
		{
			if (ModelReplacementAPI.moreCompanyPresent && (Object)(object)br.controller != (Object)null)
			{
				MoreCompanyBridge.RestoreScales(((Component)br.controller).gameObject);
			}
		}

		private static Dictionary<int, Transform> AnchorsFor(GameObject model)
		{
			int instanceID = ((Object)model).GetInstanceID();
			if (anchorCache.TryGetValue(instanceID, out var value) && value.Values.All((Transform t) => (Object)(object)t != (Object)null))
			{
				return value;
			}
			Dictionary<string, Transform> dictionary = (from t in model.GetComponentsInChildren<Transform>(true)
				where ((Object)t).name.StartsWith("Cosmetic_")
				group t by ((Object)t).name).ToDictionary((IGrouping<string, Transform> g) => g.Key, (IGrouping<string, Transform> g) => g.First());
			Dictionary<int, Transform> dictionary2 = new Dictionary<int, Transform>();
			foreach (Slot slot in slots)
			{
				if (slot.Show.Value && dictionary.TryGetValue("Cosmetic_" + slot.Name, out var value2))
				{
					dictionary2[slot.MoreCompanyType] = value2;
				}
			}
			anchorCache[instanceID] = dictionary2;
			return dictionary2;
		}

		private static HashSet<string> List(ConfigEntry<string> e)
		{
			return new HashSet<string>(from x in e.Value.Split(',')
				select x.Trim().ToLowerInvariant() into x
				where x.Length > 0
				select x);
		}

		internal static bool IsFace(string id)
		{
			if (string.IsNullOrEmpty(id))
			{
				return false;
			}
			if (faceCache.TryGetValue(id, out var value))
			{
				return value;
			}
			string lid = id.ToLowerInvariant();
			value = !List(hatIds).Contains(lid) && (BuiltinFaceIds.Contains(lid) || List(faceIds).Contains(lid) || List(faceKeywords).Any((string k) => lid.Contains(k)));
			faceCache[id] = value;
			Plugin.Log.LogInfo((object)("Cosmetic '" + id + "': head cosmetic -> " + (value ? "FACE" : "hat") + " anchor"));
			return value;
		}

		internal static void PlaceOne(Transform cosmetic, Transform anchor, Vector3 baseScale)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			cosmetic.SetPositionAndRotation(anchor.position, anchor.rotation * BlenderToUnity);
			Vector3 localScale = anchor.localScale;
			cosmetic.localScale = Vector3.Scale(baseScale, new Vector3(localScale.x, localScale.z, localScale.y));
		}
	}
	internal static class MoreCompanyBridge
	{
		private static class Diag
		{
			private class Entry
			{
				public Transform T;

				public Transform Anchor;

				public string Name;

				public string Type;

				public Vector3 ApiPos;

				public Vector3 BaseScale;

				public int Frame;
			}

			[CompilerGenerated]
			private static class <>O
			{
				public static UnityAction <0>__Report;
			}

			private static readonly Dictionary<int, Entry> tracked = new Dictionary<int, Entry>();

			private static readonly HashSet<int> done = new HashSet<int>();

			private static bool hooked;

			public static void Track(Transform t, string name, string type, Transform anchor, Vector3 apiPos, Vector3 baseScale)
			{
				//IL_005e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0060: Unknown result type (might be due to invalid IL or missing references)
				//IL_0066: Unknown result type (might be due to invalid IL or missing references)
				//IL_0068: Unknown result type (might be due to invalid IL or missing references)
				//IL_0084: Unknown result type (might be due to invalid IL or missing references)
				//IL_0089: Unknown result type (might be due to invalid IL or missing references)
				//IL_008f: Expected O, but got Unknown
				int instanceID = ((Object)t).GetInstanceID();
				if (done.Contains(instanceID))
				{
					return;
				}
				if (!tracked.TryGetValue(instanceID, out var value))
				{
					Dictionary<int, Entry> dictionary = tracked;
					Entry obj = new Entry
					{
						T = t,
						Name = name,
						Type = type,
						Frame = Time.frameCount
					};
					value = obj;
					dictionary[instanceID] = obj;
				}
				value.Anchor = anchor;
				value.ApiPos = apiPos;
				value.BaseScale = baseScale;
				if (!hooked)
				{
					object obj2 = <>O.<0>__Report;
					if (obj2 == null)
					{
						UnityAction val = Report;
						<>O.<0>__Report = val;
						obj2 = (object)val;
					}
					Application.onBeforeRender += (UnityAction)obj2;
					hooked = true;
				}
			}

			private static void Report()
			{
				//IL_009d: 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_00d9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
				//IL_0101: Unknown result type (might be due to invalid IL or missing references)
				//IL_010c: 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_012c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0144: Unknown result type (might be due to invalid IL or missing references)
				//IL_0154: Unknown result type (might be due to invalid IL or missing references)
				//IL_0171: Unknown result type (might be due to invalid IL or missing references)
				//IL_017c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0190: Unknown result type (might be due to invalid IL or missing references)
				//IL_0195: Unknown result type (might be due to invalid IL or missing references)
				foreach (KeyValuePair<int, Entry> item in tracked.ToList())
				{
					Entry value = item.Value;
					if ((Object)(object)value.T == (Object)null || (Object)(object)value.Anchor == (Object)null)
					{
						tracked.Remove(item.Key);
					}
					else if (Time.frameCount - value.Frame >= 120)
					{
						Plugin.Log.LogInfo((object)($"[AnchorDiag] {value.Type} '{value.Name}': rendered at {value.T.position:F3}, anchor {((Object)value.Anchor).name} at " + $"{value.Anchor.position:F3} (off by {Vector3.Distance(value.T.position, value.Anchor.position):F3} m), API-only spot " + $"{value.ApiPos:F3} (anchor moved it {Vector3.Distance(value.ApiPos, value.Anchor.position):F3} m); scale {value.T.lossyScale:F3} " + $"= base {value.BaseScale:F3} x anchor local {value.Anchor.localScale:F3}; rot diff to anchor " + $"{Quaternion.Angle(value.T.rotation, value.Anchor.rotation * Quaternion.Euler(270f, 0f, 0f)):F1} deg; " + $"active={((Component)value.T).gameObject.activeInHierarchy} layer={((Component)value.T).gameObject.layer}"));
						tracked.Remove(item.Key);
						done.Add(item.Key);
					}
				}
			}
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static UnityAction <0>__SceneDump;
		}

		private static readonly Dictionary<int, Vector3> baseScales = new Dictionary<int, Vector3>();

		private static int dumps;

		private static int lastDumpFrame = -100000;

		private static bool sceneHooked;

		public static void Place(BodyReplacementBase br, Dictionary<int, Transform> anchors)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Invalid comparison between Unknown and I4
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Expected I4, but got Unknown
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			if (CosmeticTuning.debugLog.Value)
			{
				HookSceneDump();
			}
			ViewStateManager viewState = br.viewState;
			bool flag = (Object)(object)viewState != (Object)null && ((ManagerBase)viewState).localPlayer && (int)viewState.GetViewState() != 1;
			int num = ((!((Object)(object)viewState == (Object)null)) ? (flag ? viewState.ModelLayer : viewState.VisibleLayer) : 0);
			bool value = MainClass.cosmeticsSyncOther.Value;
			CosmeticApplication[] componentsInChildren = ((Component)br.controller).GetComponentsInChildren<CosmeticApplication>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				foreach (CosmeticInstance spawnedCosmetic in componentsInChildren[i].spawnedCosmetics)
				{
					if ((Object)(object)spawnedCosmetic == (Object)null)
					{
						continue;
					}
					int num2 = (int)spawnedCosmetic.cosmeticType;
					if (num2 == 0 && CosmeticTuning.IsFace(spawnedCosmetic.cosmeticId))
					{
						if (!CosmeticTuning.FaceShown)
						{
							num2 = -1;
						}
						else if (anchors.ContainsKey(100))
						{
							num2 = 100;
						}
					}
					if (!anchors.TryGetValue(num2, out var value2))
					{
						if (((Component)spawnedCosmetic).gameObject.activeSelf)
						{
							((Component)spawnedCosmetic).gameObject.SetActive(false);
						}
						continue;
					}
					Transform transform = ((Component)spawnedCosmetic).transform;
					if ((Object)(object)transform.parent != (Object)null)
					{
						transform.SetParent((Transform)null, true);
					}
					int instanceID = ((Object)spawnedCosmetic).GetInstanceID();
					if (!baseScales.TryGetValue(instanceID, out var value3))
					{
						value3 = (baseScales[instanceID] = transform.localScale);
					}
					if (((Component)spawnedCosmetic).gameObject.activeSelf != value)
					{
						((Component)spawnedCosmetic).gameObject.SetActive(value);
					}
					if (((Component)spawnedCosmetic).gameObject.layer != num)
					{
						SetLayer(transform, num);
					}
					Vector3 position = transform.position;
					CosmeticTuning.PlaceOne(transform, value2, value3);
					if (CosmeticTuning.debugLog.Value)
					{
						Diag.Track(transform, spawnedCosmetic.cosmeticId, ((object)Unsafe.As<CosmeticType, CosmeticType>(ref spawnedCosmetic.cosmeticType)/*cast due to .constrained prefix*/).ToString(), value2, position, value3);
					}
				}
			}
		}

		private static void SetLayer(Transform t, int layer)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			((Component)t).gameObject.layer = layer;
			foreach (Transform item in t)
			{
				SetLayer(item, layer);
			}
		}

		public static void HookSceneDump()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			if (!sceneHooked)
			{
				sceneHooked = true;
				object obj = <>O.<0>__SceneDump;
				if (obj == null)
				{
					UnityAction val = SceneDump;
					<>O.<0>__SceneDump = val;
					obj = (object)val;
				}
				Application.onBeforeRender += (UnityAction)obj;
			}
		}

		private static string PathOf(Transform t)
		{
			List<string> list = new List<string>();
			int num = 0;
			while ((Object)(object)t != (Object)null && num < 5)
			{
				list.Add(((Object)t).name);
				num++;
				t = t.parent;
			}
			return string.Join("<", list);
		}

		private static void SceneDump()
		{
			//IL_0140: 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)
			if (dumps >= 4 || Time.frameCount - lastDumpFrame < 180)
			{
				return;
			}
			Camera[] allCameras = Camera.allCameras;
			if (!allCameras.Any((Camera c) => ((Object)c).name == "EmoteCamera"))
			{
				return;
			}
			dumps++;
			lastDumpFrame = Time.frameCount;
			ManualLogSource log = Plugin.Log;
			log.LogInfo((object)($"[SceneDump {dumps}] cameras: " + string.Join(" | ", allCameras.Select((Camera c) => $"{((Object)c).name} mask=0x{c.cullingMask:X} at {((Component)c).transform.position:F2}"))));
			CosmeticInstance[] array = Object.FindObjectsOfType<CosmeticInstance>(true);
			foreach (CosmeticInstance val in array)
			{
				Renderer[] componentsInChildren = ((Component)val).GetComponentsInChildren<Renderer>(true);
				int layer = ((Component)val).gameObject.layer;
				IEnumerable<string> values = from cam in allCameras
					where (cam.cullingMask & (1 << layer)) != 0
					select ((Object)cam).name;
				log.LogInfo((object)($"[SceneDump {dumps}] {val.cosmeticType} '{val.cosmeticId}' id={((Object)val).GetInstanceID()} active={((Component)val).gameObject.activeInHierarchy} " + $"layer={layer} renderers={componentsInChildren.Count((Renderer r) => r.enabled)}/{componentsInChildren.Length} pos={((Component)val).transform.position:F3} " + string.Format("tracked={0} path={1} seenBy=[{2}]", baseScales.ContainsKey(((Object)val).GetInstanceID()), PathOf(((Component)val).transform), string.Join(",", values))));
			}
		}

		public static void RestoreScales(GameObject player)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			CosmeticApplication[] componentsInChildren = player.GetComponentsInChildren<CosmeticApplication>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				foreach (CosmeticInstance spawnedCosmetic in componentsInChildren[i].spawnedCosmetics)
				{
					if ((Object)(object)spawnedCosmetic != (Object)null && baseScales.TryGetValue(((Object)spawnedCosmetic).GetInstanceID(), out var value) && (Object)(object)((Component)spawnedCosmetic).transform.parent == (Object)null)
					{
						((Component)spawnedCosmetic).transform.localScale = value;
					}
				}
			}
		}
	}
	internal sealed class EyeHeight
	{
		private static ConfigEntry<bool> enabled;

		private static ConfigEntry<bool> diag;

		private readonly BodyReplacementBase body;

		private readonly Transform eye;

		private Transform container;

		private Vector3 baseLocal;

		private Vector3 written;

		private float shift;

		private float rel = float.NaN;

		private Transform arms;

		private Vector3 armsWritten;

		private float armsShift;

		private Transform vm;

		private Vector3 vmWritten;

		private float vmShift;

		private Transform visor;

		private Vector3 visorBase;

		private Vector3 visorWritten;

		private bool active;

		private bool logged;

		private float logAt;

		private float eyeDiagAt;

		private static StartMatchLever lever;

		private static float leverLookAt;

		private static EyeHeight current;

		private const float MinEyeHeight = 0.25f;

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

		private static bool subscribed;

		private Transform[] armBones;

		private Transform armL;

		private Transform armR;

		private float diagAt;

		public static void Bind(ConfigFile config)
		{
			diag = config.Bind<bool>("Debug", "Eye height diagnostics", false, "Log the first-person camera height ([EyeDiag], every 0.5 s) and whether the held item was moved to the first-person hands ([EyeItem], every 2 s).");
			enabled = config.Bind<bool>("Camera", "First person at model eye height", true, "Move your first-person camera up/down to the eyes of the model you wear (smaller models see from lower down). Only your own view changes. Note: grabbing/using things is aimed from the camera, so high shelves and buttons are a bit harder to reach on short models.");
		}

		private static bool PullingShipLever(PlayerControllerB pc)
		{
			if (!pc.inSpecialInteractAnimation || (Object)(object)pc.currentTriggerInAnimationWith == (Object)null)
			{
				return false;
			}
			if ((Object)(object)lever == (Object)null && Time.time >= leverLookAt)
			{
				leverLookAt = Time.time + 2f;
				lever = Object.FindObjectOfType<StartMatchLever>();
			}
			if ((Object)(object)lever != (Object)null)
			{
				return (Object)(object)pc.currentTriggerInAnimationWith == (Object)(object)lever.triggerScript;
			}
			return false;
		}

		internal static void ApplyNowFor(PlayerControllerB pc)
		{
			EyeHeight eyeHeight = current;
			if (eyeHeight != null && eyeHeight.active && (Object)(object)eyeHeight.body != (Object)null && (Object)(object)eyeHeight.body.controller == (Object)(object)pc)
			{
				eyeHeight.ApplyNow();
			}
		}

		internal static bool IsShifting(PlayerControllerB pc)
		{
			EyeHeight eyeHeight = current;
			if (eyeHeight != null && eyeHeight.active && (Object)(object)eyeHeight.body != (Object)null && (Object)(object)eyeHeight.body.controller == (Object)(object)pc)
			{
				return Mathf.Abs(eyeHeight.shift) > 0.01f;
			}
			return false;
		}

		private void ApplyNow()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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_00b8: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: 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)
			Transform val = container;
			if (!((Object)(object)val == (Object)null))
			{
				if (val.localPosition != written)
				{
					baseLocal = val.localPosition;
					val.localPosition = baseLocal + (((Object)(object)val.parent != (Object)null) ? val.parent.InverseTransformVector(Vector3.up * shift) : (Vector3.up * shift));
					written = val.localPosition;
				}
				if ((Object)(object)visor != (Object)null && visor.localPosition != visorWritten)
				{
					visorBase = visor.localPosition;
					visor.localPosition = visorBase + (((Object)(object)visor.parent != (Object)null) ? visor.parent.InverseTransformVector(Vector3.up * shift) : (Vector3.up * shift));
					visorWritten = visor.localPosition;
				}
			}
		}

		public EyeHeight(BodyReplacementBase body, GameObject model)
		{
			this.body = body;
			all.Add(this);
			if (!subscribed)
			{
				RenderPipelineManager.beginContextRendering += PlaceHeldItems;
				subscribed = true;
			}
			Transform[] componentsInChildren = model.GetComponentsInChildren<Transform>(true);
			foreach (Transform val in componentsInChildren)
			{
				if (((Object)val).name == "Eye_View")
				{
					eye = val;
					break;
				}
			}
			if ((Object)(object)eye == (Object)null)
			{
				Plugin.Log.LogWarning((object)(((Object)model).name + ": no Eye_View anchor, first-person camera height unchanged"));
			}
		}

		public void Update()
		{
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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_036a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0395: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_037d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0388: Unknown result type (might be due to invalid IL or missing references)
			//IL_03aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0403: Unknown result type (might be due to invalid IL or missing references)
			//IL_0408: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0410: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_043d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0448: Unknown result type (might be due to invalid IL or missing references)
			//IL_044d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0424: Unknown result type (might be due to invalid IL or missing references)
			//IL_042f: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0452: Unknown result type (might be due to invalid IL or missing references)
			//IL_045f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0464: Unknown result type (might be due to invalid IL or missing references)
			//IL_054e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0553: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0511: Unknown result type (might be due to invalid IL or missing references)
			//IL_0516: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0573: Unknown result type (might be due to invalid IL or missing references)
			//IL_0564: Unknown result type (might be due to invalid IL or missing references)
			//IL_0567: Unknown result type (might be due to invalid IL or missing references)
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_0342: Unknown result type (might be due to invalid IL or missing references)
			//IL_058e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0592: Unknown result type (might be due to invalid IL or missing references)
			//IL_0594: Unknown result type (might be due to invalid IL or missing references)
			//IL_059f: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_05be: Unknown result type (might be due to invalid IL or missing references)
			//IL_0577: Unknown result type (might be due to invalid IL or missing references)
			//IL_0579: Unknown result type (might be due to invalid IL or missing references)
			//IL_0584: Unknown result type (might be due to invalid IL or missing references)
			//IL_0589: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB controller = body.controller;
			if (enabled == null || !enabled.Value || !((Object)(object)eye != (Object)null) || !((Object)(object)controller != (Object)null) || controller.isPlayerDead || !((Object)(object)GameNetworkManager.Instance != (Object)null) || !((Object)(object)controller == (Object)(object)GameNetworkManager.Instance.localPlayerController) || !((Object)(object)controller.cameraContainerTransform != (Object)null) || !((Object)(object)controller.gameplayCamera != (Object)null))
			{
				Restore();
				return;
			}
			Transform cameraContainerTransform = controller.cameraContainerTransform;
			if (!active || (Object)(object)cameraContainerTransform != (Object)(object)container || cameraContainerTransform.localPosition != written)
			{
				container = cameraContainerTransform;
				baseLocal = cameraContainerTransform.localPosition;
			}
			active = true;
			current = this;
			cameraContainerTransform.localPosition = baseLocal;
			float y = ((Component)controller.gameplayCamera).transform.position.y;
			float y2 = ((Component)controller).transform.position.y;
			float num = Mathf.Max(eye.position.y - y2, 0.25f);
			if (controller.inTerminalMenu || PullingShipLever(controller))
			{
				num = y - y2;
			}
			rel = (float.IsNaN(rel) ? num : Mathf.Lerp(rel, num, 1f - Mathf.Exp((0f - Time.deltaTime) / 0.08f)));
			shift = y2 + rel - y;
			if (diag != null && diag.Value && Time.time >= eyeDiagAt)
			{
				eyeDiagAt = Time.time + 0.5f;
				ManualLogSource log = Plugin.Log;
				object[] array = new object[6];
				GameObject replacementModel = body.replacementModel;
				array[0] = ((replacementModel != null) ? ((Object)replacementModel).name : null);
				array[1] = controller.isCrouching;
				array[2] = eye.position.y - y2;
				array[3] = rel;
				array[4] = y - y2;
				array[5] = shift;
				log.LogInfo((object)string.Format("[EyeDiag] {0}: crouch={1} eye={2:F3} camera={3:F3} vanillaCamera={4:F3} shift={5:+0.000;-0.000} (m above the player's feet)", array));
				SkinnedMeshRenderer[] array2 = (SkinnedMeshRenderer[])(((Object)(object)body.replacementModel != (Object)null) ? ((Array)body.replacementModel.GetComponentsInChildren<SkinnedMeshRenderer>()) : ((Array)new SkinnedMeshRenderer[0]));
				if (array2.Length != 0)
				{
					float num2 = array2.Min(delegate(SkinnedMeshRenderer r)
					{
						//IL_0001: Unknown result type (might be due to invalid IL or missing references)
						//IL_0006: Unknown result type (might be due to invalid IL or missing references)
						//IL_0009: Unknown result type (might be due to invalid IL or missing references)
						Bounds bounds = ((Renderer)r).bounds;
						return ((Bounds)(ref bounds)).min.y;
					}) - y2;
					float num3 = array2.Max(delegate(SkinnedMeshRenderer r)
					{
						//IL_0001: Unknown result type (might be due to invalid IL or missing references)
						//IL_0006: Unknown result type (might be due to invalid IL or missing references)
						//IL_0009: Unknown result type (might be due to invalid IL or missing references)
						Bounds bounds = ((Renderer)r).bounds;
						return ((Bounds)(ref bounds)).max.y;
					}) - y2;
					Plugin.Log.LogInfo((object)($"[SizeDiag] {((Object)body.replacementModel).name}: mesh from {num2:F3} to {num3:F3} m above the feet (height {num3 - num2:F3}), eye {eye.position.y - y2:F3}, " + $"root scale {body.replacementModel.transform.lossyScale.y:F4}, vanilla camera {y - y2:F3} (player height ~ vanilla camera / 0.882)"));
				}
			}
			cameraContainerTransform.localPosition = baseLocal + (((Object)(object)cameraContainerTransform.parent != (Object)null) ? cameraContainerTransform.parent.InverseTransformVector(Vector3.up * shift) : (Vector3.up * shift));
			written = cameraContainerTransform.localPosition;
			Transform localVisorTargetPoint = controller.localVisorTargetPoint;
			if ((Object)(object)localVisorTargetPoint != (Object)null)
			{
				if ((Object)(object)localVisorTargetPoint != (Object)(object)visor || localVisorTargetPoint.localPosition != visorWritten)
				{
					visor = localVisorTargetPoint;
					visorBase = localVisorTargetPoint.localPosition;
				}
				localVisorTargetPoint.localPosition = visorBase + (((Object)(object)localVisorTargetPoint.parent != (Object)null) ? localVisorTargetPoint.parent.InverseTransformVector(Vector3.up * shift) : (Vector3.up * shift));
				visorWritten = localVisorTargetPoint.localPosition;
			}
			Transform val = (((Object)(object)body.replacementViewModel != (Object)null) ? body.replacementViewModel.transform : null);
			if ((Object)(object)val != (Object)null)
			{
				RestoreArms();
				Vector3 position = val.position;
				Vector3 val2 = (((Object)(object)val == (Object)(object)vm && position == vmWritten) ? (position - Vector3.up * vmShift) : position);
				val.position = val2 + Vector3.up * shift;
				vm = val;
				vmWritten = val.position;
				vmShift = shift;
			}
			else
			{
				Transform localArmsTransform = controller.localArmsTransform;
				if ((Object)(object)localArmsTransform != (Object)null && !controller.localArmsMatchCamera)
				{
					Vector3 position2 = localArmsTransform.position;
					Vector3 val3 = (((Object)(object)localArmsTransform == (Object)(object)arms && position2 == armsWritten) ? (position2 - Vector3.up * armsShift) : position2);
					localArmsTransform.position = val3 + Vector3.up * shift;
					arms = localArmsTransform;
					armsWritten = localArmsTransform.position;
					armsShift = shift;
				}
				else
				{
					RestoreArms();
				}
			}
			if (!logged)
			{
				if (logAt == 0f)
				{
					logAt = Time.time + 2f;
				}
				else if (Time.time >= logAt)
				{
					logged = true;
					ManualLogSource log2 = Plugin.Log;
					object[] array3 = new object[4];
					GameObject replacementModel2 = body.replacementModel;
					array3[0] = ((replacementModel2 != null) ? ((Object)replacementModel2).name : null);
					array3[1] = shift;
					array3[2] = (((Object)(object)vm != (Object)null) ? "view model" : (((Object)(object)arms != (Object)null) ? "game arms" : "NONE"));
					array3[3] = (((Object)(object)visor != (Object)null) ? "yes" : "NONE");
					log2.LogInfo((object)string.Format("Eye height ({0}): first-person camera moved {1:+0.00;-0.00} m to the model's eyes; arms moved with it: {2}, visor: {3}", array3));
				}
			}
		}

		private static void PlaceHeldItems(ScriptableRenderContext ctx, List<Camera> cams)
		{
			for (int num = all.Count - 1; num >= 0; num--)
			{
				EyeHeight eyeHeight = all[num];
				if (eyeHeight == null || (Object)(object)eyeHeight.body == (Object)null)
				{
					all.RemoveAt(num);
				}
				else
				{
					try
					{
						eyeHeight.PlaceHeldItem();
					}
					catch (Exception arg)
					{
						Plugin.Log.LogError((object)$"EyeHeight held item: {arg}");
						all.RemoveAt(num);
					}
				}
			}
		}

		private void PlaceHeldItem()
		{
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Invalid comparison between Unknown and I4
			//IL_0367: Unknown result type (might be due to invalid IL or missing references)
			//IL_036c: Unknown result type (might be due to invalid IL or missing references)
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: 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_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			string text = null;
			PlayerControllerB controller = body.controller;
			GrabbableObject val = (((Object)(object)controller != (Object)null) ? controller.currentlyHeldObjectServer : null);
			if (!active)
			{
				text = "camera shift not active";
			}
			else if ((Object)(object)vm == (Object)null)
			{
				text = "no view model";
			}
			else if (!((Behaviour)body).isActiveAndEnabled)
			{
				text = "body disabled";
			}
			else if ((Object)(object)val == (Object)null || (Object)(object)val.itemProperties == (Object)null || (Object)(object)val.parentObject == (Object)null)
			{
				text = "no held item";
			}
			else if ((Object)(object)val.parentObject == (Object)(object)controller.serverItemHolder)
			{
				text = "item on serverItemHolder (third person / emote)";
			}
			else if ((Object)(object)body.viewState == (Object)null || (int)body.viewState.GetViewState() != 2)
			{
				text = "not first person";
			}
			Vector3 val2 = (((Object)(object)val != (Object)null) ? ((Component)val).transform.position : Vector3.zero);
			Vector3 val3 = Vector3.zero;
			if (text == null)
			{
				if (armBones == null || (Object)(object)armL == (Object)null || (Object)(object)armR == (Object)null)
				{
					armBones = (Transform[])(((Object)(object)controller.thisPlayerModelArms != (Object)null) ? ((Array)controller.thisPlayerModelArms.bones) : ((Array)new Transform[0]));
					armL = ((IEnumerable<Transform>)armBones).FirstOrDefault((Func<Transform, bool>)((Transform t) => (Object)(object)t != (Object)null && ((Object)t).name == "hand.L"));
					armR = ((IEnumerable<Transform>)armBones).FirstOrDefault((Func<Transform, bool>)((Transform t) => (Object)(object)t != (Object)null && ((Object)t).name == "hand.R"));
				}
				Animator componentInChildren = ((Component)vm).GetComponentInChildren<Animator>();
				Transform val4 = (((Object)(object)componentInChildren != (Object)null && componentInChildren.isHuman) ? componentInChildren.GetBoneTransform((HumanBodyBones)17) : null);
				Transform val5 = (((Object)(object)componentInChildren != (Object)null && componentInChildren.isHuman) ? componentInChildren.GetBoneTransform((HumanBodyBones)18) : null);
				if ((Object)(object)armL == (Object)null || (Object)(object)armR == (Object)null || (Object)(object)val4 == (Object)null || (Object)(object)val5 == (Object)null)
				{
					text = "hand bones missing";
				}
				else
				{
					val3 = (val.itemProperties.twoHandedAnimation ? ((val4.position - armL.position + (val5.position - armR.position)) / 2f) : (val5.position - armR.position));
					Transform parentObject = val.parentObject;
					((Component)val).transform.position = parentObject.position + parentObject.rotation * val.itemProperties.positionOffset + val3;
				}
			}
			if (diag != null && diag.Value && Time.time >= diagAt && (Object)(object)val != (Object)null)
			{
				diagAt = Time.time + 2f;
				ManualLogSource log = Plugin.Log;
				object[] obj = new object[5]
				{
					val.itemProperties.itemName,
					text ?? "placed",
					null,
					null,
					null
				};
				Transform parentObject2 = val.parentObject;
				obj[2] = ((parentObject2 != null) ? ((Object)parentObject2).name : null);
				Vector3 val6 = ((Component)val).transform.position - val2;
				obj[3] = ((Vector3)(ref val6)).magnitude;
				obj[4] = val3;
				log.LogInfo((object)string.Format("[EyeItem] {0}: {1}; holder {2}; moved {3:F3} m; hand offset {4}", obj));
			}
		}

		private void RestoreArms()
		{
			//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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: 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)
			if ((Object)(object)arms != (Object)null && arms.position == armsWritten)
			{
				Transform obj = arms;
				obj.position -= Vector3.up * armsShift;
			}
			arms = null;
			armsShift = 0f;
		}

		public void Restore()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			if (current == this)
			{
				current = null;
			}
			RestoreArms();
			if ((Object)(object)visor != (Object)null && visor.localPosition == visorWritten)
			{
				visor.localPosition = visorBase;
			}
			visor = null;
			if ((Object)(object)vm != (Object)null && vm.position == vmWritten)
			{
				Transform obj = vm;
				obj.position -= Vector3.up * vmShift;
			}
			vm = null;
			vmShift = 0f;
			if (active)
			{
				if ((Object)(object)container != (Object)null && container.localPosition == written)
				{
					container.localPosition = baseLocal;
				}
				active = false;
				shift = 0f;
				rel = float.NaN;
			}
		}
	}
	[HarmonyPatch]
	internal static class EyeHeightPatches
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			foreach (MethodInfo declaredMethod in AccessTools.GetDeclaredMethods(typeof(PlayerControllerB)))
			{
				if (declaredMethod.Name.EndsWith("_performed") || declaredMethod.Name == "BeginGrabObject" || declaredMethod.Name == "SetHoverTipAndCurrentInteractTrigger" || declaredMethod.Name == "Update" || declaredMethod.Name == "LateUpdate")
				{
					yield return declaredMethod;
				}
			}
		}

		private static void Prefix(PlayerControllerB __instance)
		{
			EyeHeight.ApplyNowFor(__instance);
		}
	}
	[HarmonyPatch(typeof(GrabbableObject), "GetItemFloorPosition")]
	internal static class EyeHeightDropPatch
	{
		private static void Prefix(GrabbableObject __instance, ref Vector3 startPosition)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			if (!(startPosition != Vector3.zero) && !((Object)(object)__instance == (Object)null) && !((Object)(object)__instance.parentObject == (Object)null) && !((Object)(object)__instance.itemProperties == (Object)null))
			{
				PlayerControllerB playerHeldBy = __instance.playerHeldBy;
				if (!((Object)(object)playerHeldBy == (Object)null) && EyeHeight.IsShifting(playerHeldBy))
				{
					Transform parentObject = __instance.parentObject;
					startPosition = parentObject.position + parentObject.rotation * __instance.itemProperties.positionOffset + Vector3.up * 0.15f;
				}
			}
		}
	}
	internal sealed class FloorClamp
	{
		private static ConfigEntry<bool> enabled;

		private readonly Transform hips;

		private readonly Transform[] feet;

		private readonly float restLocal;

		private float baseline = float.NaN;

		private float standingSince = -1f;

		private static readonly Dictionary<GameObject, FloorClamp> cache = new Dictionary<GameObject, FloorClamp>();

		public static void Bind(ConfigFile config)
		{
			enabled = config.Bind<bool>("Body", "Keep feet above the floor", true, "Lift the model when its feet would sink into the floor (small models while crouching).");
		}

		private FloorClamp(GameObject model, GameObject prefab)
		{
			Animator anim = model.GetComponentInChildren<Animator>();
			if ((Object)(object)anim == (Object)null || !anim.isHuman)
			{
				feet = (Transform[])(object)new Transform[0];
				return;
			}
			hips = anim.GetBoneTransform((HumanBodyBones)0);
			feet = ((IEnumerable<Transform>)(object)new Transform[2]
			{
				Pick((HumanBodyBones)19, (HumanBodyBones)5),
				Pick((HumanBodyBones)20, (HumanBodyBones)6)
			}).Where((Transform t) => (Object)(object)t != (Object)null).ToArray();
			Dictionary<string, Transform> pb = (from t in prefab.GetComponentsInChildren<Transform>(true)
				group t by ((Object)t).name).ToDictionary((IGrouping<string, Transform> g) => g.Key, (IGrouping<string, Transform> g) => g.First());
			Transform value;
			List<float> list = (from f in feet
				select (!pb.TryGetValue(((Object)f).name, out value)) ? float.NaN : prefab.transform.InverseTransformPoint(value.position).y into y
				where !float.IsNaN(y)
				select y).ToList();
			restLocal = ((list.Count > 0) ? list.Min() : 0f);
			if ((Object)(object)hips == (Object)null || feet.Length == 0)
			{
				Plugin.Log.LogWarning((object)("FloorClamp on " + ((Object)model).name + ": no humanoid hips/feet"));
			}
			Transform Pick(HumanBodyBones toes, HumanBodyBones foot)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				return anim.GetBoneTransform(toes) ?? anim.GetBoneTransform(foot);
			}
		}

		public static void Apply(GameObject model, GameObject prefab, PlayerControllerB pc)
		{
			if (enabled == null || !enabled.Value || (Object)(object)model == (Object)null || (Object)(object)prefab == (Object)null || (Object)(object)pc == (Object)null || pc.isPlayerDead)
			{
				return;
			}
			if (!cache.TryGetValue(model, out var value))
			{
				foreach (GameObject item in cache.Keys.Where((GameObject k) => (Object)(object)k == (Object)null).ToList())
				{
					cache.Remove(item);
				}
				value = (cache[model] = new FloorClamp(model, prefab));
			}
			value.Run(model, pc);
		}

		private void Run(GameObject model, PlayerControllerB pc)
		{
			//IL_0048: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)hips == (Object)null) && feet.Length != 0)
			{
				float num = feet.Min((Transform f) => f.position.y) - ((Component)pc).transform.position.y;
				if (float.IsNaN(baseline))
				{
					baseline = model.transform.TransformVector(Vector3.up * restLocal).y;
				}
				if (pc.isCrouching || pc.isFallingFromJump || pc.isFallingNoJump || pc.isClimbingLadder || pc.inSpecialInteractAnimation)
				{
					standingSince = -1f;
				}
				else if (standingSince < 0f)
				{
					standingSince = Time.time;
				}
				else if (Time.time - standingSince > 0.5f)
				{
					baseline = Mathf.Lerp(baseline, num, 1f - Mathf.Exp((0f - Time.deltaTime) / 1f));
				}
				float num2 = baseline - num;
				if (num2 > 0.005f)
				{
					Transform obj = hips;
					obj.position += Vector3.up * num2;
				}
			}
		}
	}
	internal sealed class HideVisor
	{
		private static ConfigEntry<bool> enabled;

		private readonly BodyReplacementBase body;

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

		private Transform visor;

		private Renderer[] renderers;

		public static void Bind(ConfigFile config)
		{
			enabled = config.Bind<bool>("Camera", "Hide helmet visor", true, "Hide the helmet visor (the gas-mask rim around your first-person view) while you wear one of these suits. Only your own view.");
		}

		public HideVisor(BodyReplacementBase body)
		{
			this.body = body;
		}

		public void Update()
		{
			PlayerControllerB controller = body.controller;
			if (enabled == null || !enabled.Value || !((Object)(object)controller != (Object)null) || controller.isPlayerDead || !((Object)(object)controller.localVisor != (Object)null) || !((Object)(object)GameNetworkManager.Instance != (Object)null) || !((Object)(object)controller == (Object)(object)GameNetworkManager.Instance.localPlayerController))
			{
				Restore();
				return;
			}
			if ((Object)(object)visor != (Object)(object)controller.localVisor)
			{
				Restore();
				visor = controller.localVisor;
				renderers = ((Component)visor).GetComponentsInChildren<Renderer>(true);
			}
			Renderer[] array = renderers;
			foreach (Renderer val in array)
			{
				if ((Object)(object)val != (Object)null && val.enabled)
				{
					val.enabled = false;
					hidden.Add(val);
				}
			}
		}

		public void Restore()
		{
			foreach (Renderer item in hidden)
			{
				if ((Object)(object)item != (Object)null)
				{
					item.enabled = true;
				}
			}
			hidden.Clear();
		}
	}
	internal static class ItemAnchors
	{
		private class Entry
		{
			public BodyReplacementBase body;

			public Transform jetpack;

			public Transform beltBag;

			public Transform vanillaSpine;
		}

		private static readonly Quaternion BlenderToUnity = Quaternion.Euler(270f, 0f, 0f);

		private static bool subscribed;

		private static readonly List<Entry> bodies = new List<Entry>();

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

		private static readonly HashSet<Transform> placed = new HashSet<Transform>();

		private static readonly List<Transform> drop = new List<Transform>();

		private static bool logged;

		private static readonly Dictionary<string, float> diagNext = new Dictionary<string, float>();

		private static ConfigEntry<bool> diag;

		private static float bagStateAt;

		public static void Bind(ConfigFile config)
		{
			diag = config.Bind<bool>("Debug", "Item anchor diagnostics", false, "Log every 2 s where the worn belt bag / held jetpack really is (size + centre in the anchor's bone frame, model units).");
		}

		private static void Diag(string what, Transform item, Transform anchor, float s)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: 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_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			if (diag == null || !diag.Value || (diagNext.TryGetValue(what, out var value) && !(Time.time >= value)))
			{
				return;
			}
			diagNext[what] = Time.time + 2f;
			Renderer[] componentsInChildren = ((Component)item).GetComponentsInChildren<Renderer>();
			if (componentsInChildren.Length == 0)
			{
				return;
			}
			Bounds bounds = componentsInChildren[0].bounds;
			Renderer[] array = componentsInChildren;
			foreach (Renderer val in array)
			{
				if (val.enabled)
				{
					((Bounds)(ref bounds)).Encapsulate(val.bounds);
				}
			}
			Transform parent = anchor.parent;
			float x = parent.lossyScale.x;
			Vector3 val2 = parent.InverseTransformPoint(((Bounds)(ref bounds)).center);
			Plugin.Log.LogInfo((object)($"[ItemDiag] {what}: bounds size {((Bounds)(ref bounds)).size / x} (model units), centre in {((Object)parent).name} frame {val2}; anchor localScale {anchor.localScale} (s={s:F3}); " + string.Format("item lossy {0:F3}, parent {1}; bone lossy {2:F4}; renderers {3}", item.lossyScale.x, Object.op_Implicit((Object)(object)item.parent) ? ((Object)item.parent).name : "-", x, componentsInChildren.Length)));
		}

		public static void Register(BodyReplacementBase body, GameObject model)
		{
			bodies.RemoveAll((Entry b) => (Object)(object)b.body == (Object)null || (Object)(object)b.body == (Object)(object)body);
			Entry entry = new Entry
			{
				body = body
			};
			Transform[] componentsInChildren = model.GetComponentsInChildren<Transform>(true);
			foreach (Transform val in componentsInChildren)
			{
				if (((Object)val).name == "Cosmetic_Jetpack")
				{
					entry.jetpack = val;
				}
				else if (((Object)val).name == "Cosmetic_BeltBag")
				{
					entry.beltBag = val;
				}
			}
			if (!((Object)(object)entry.jetpack == (Object)null) || !((Object)(object)entry.beltBag == (Object)null))
			{
				bodies.Add(entry);
				if (!subscribed)
				{
					RenderPipelineManager.beginContextRendering += Place;
					subscribed = true;
				}
			}
		}

		private static BeltBagItem WornBag(PlayerControllerB pc)
		{
			Transform lowerTorsoCostumeContainerBeltBagOffset = pc.lowerTorsoCostumeContainerBeltBagOffset;
			if ((Object)(object)lowerTorsoCostumeContainerBeltBagOffset == (Object)null)
			{
				return null;
			}
			GrabbableObject itemOnlySlot = pc.ItemOnlySlot;
			BeltBagItem val = (BeltBagItem)(object)((itemOnlySlot is BeltBagItem) ? itemOnlySlot : null);
			if (val != null && (Object)(object)val != (Object)null && (Object)(object)((GrabbableObject)val).parentObject == (Object)(object)lowerTorsoCostumeContainerBeltBagOffset)
			{
				return val;
			}
			if (pc.ItemSlots != null)
			{
				GrabbableObject[] itemSlots = pc.ItemSlots;
				foreach (GrabbableObject obj in itemSlots)
				{
					BeltBagItem val2 = (BeltBagItem)(object)((obj is BeltBagItem) ? obj : null);
					if (val2 != null && (Object)(object)val2 != (Object)null && (Object)(object)((GrabbableObject)val2).parentObject == (Object)(object)lowerTorsoCostumeContainerBeltBagOffset)
					{
						return val2;
					}
				}
			}
			return null;
		}

		private static void BagState(PlayerControllerB pc)
		{
			if (Time.time < bagStateAt)
			{
				return;
			}
			GrabbableObject itemOnlySlot = pc.ItemOnlySlot;
			BeltBagItem val = (BeltBagItem)(object)((itemOnlySlot is BeltBagItem) ? itemOnlySlot : null);
			string text = "utility";
			if ((Object)(object)val == (Object)null && pc.ItemSlots != null)
			{
				for (int i = 0; i < pc.ItemSlots.Length; i++)
				{
					GrabbableObject obj = pc.ItemSlots[i];
					BeltBagItem val2 = (BeltBagItem)(object)((obj is BeltBagItem) ? obj : null);
					if (val2 != null)
					{
						val = val2;
						text = "slot " + i;
						break;
					}
				}
			}
			if (!((Object)(object)val == (Object)null))
			{
				bagStateAt = Time.time + 2f;
				Plugin.Log.LogInfo((object)(string.Format("[ItemDiag] belt bag state: {0}; isPocketed {1}; isHeld {2}; parentObject {3}; ", text, ((GrabbableObject)val).isPocketed, ((GrabbableObject)val).isHeld, Object.op_Implicit((Object)(object)((GrabbableObject)val).parentObject) ? ((Object)((GrabbableObject)val).parentObject).name : "null") + string.Format("heldBy {0}; worn {1}", Object.op_Implicit((Object)(object)((GrabbableObject)val).playerHeldBy) ? ((GrabbableObject)val).playerHeldBy.playerUsername : "-", (Object)(object)((GrabbableObject)val).parentObject != (Object)null && (Object)(object)((GrabbableObject)val).parentObject == (Object)(object)pc.lowerTorsoCostumeContainerBeltBagOffset)));
			}
		}

		private static float Scale(Transform a)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			Vector3 localScale = a.localScale;
			return (localScale.x + localScale.y + localScale.z) / 3f;
		}

		private static Vector3 ScaleInR(Transform a)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			Vector3 localScale = a.localScale;
			return new Vector3(localScale.x, localScale.z, localScale.y);
		}

		private static Vector3 AxisScale(Vector3 sR, Quaternion q)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Vector3.Scale(sR, q * Vector3.right);
			float magnitude = ((Vector3)(ref val)).magnitude;
			val = Vector3.Scale(sR, q * Vector3.up);
			float magnitude2 = ((Vector3)(ref val)).magnitude;
			val = Vector3.Scale(sR, q * Vector3.forward);
			return new Vector3(magnitude, magnitude2, ((Vector3)(ref val)).magnitude);
		}

		private static void Place(ScriptableRenderContext ctx, List<Camera> cams)
		{
			//IL_047f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: 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_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: 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_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: 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_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0304: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: 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_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0322: Unknown result type (might be due to invalid IL or missing references)
			//IL_0327: Unknown result type (might be due to invalid IL or missing references)
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0331: Unknown result type (might be due to invalid IL or missing references)
			//IL_0336: 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_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_034f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0360: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Unknown result type (might be due to invalid IL or missing references)
			//IL_0364: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			//IL_036f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0374: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_037e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ae: Unknown result type (might be due to invalid IL or missing references)
			placed.Clear();
			for (int num = bodies.Count - 1; num >= 0; num--)
			{
				Entry entry = bodies[num];
				if ((Object)(object)entry.body == (Object)null)
				{
					bodies.RemoveAt(num);
				}
				else
				{
					try
					{
						PlayerControllerB controller = entry.body.controller;
						if (((Behaviour)entry.body).isActiveAndEnabled && !((Object)(object)controller == (Object)null))
						{
							if ((Object)(object)entry.jetpack != (Object)null && ((Component)entry.jetpack).gameObject.activeInHierarchy)
							{
								GrabbableObject currentlyHeldObjectServer = controller.currentlyHeldObjectServer;
								JetpackItem val = (JetpackItem)(object)((currentlyHeldObjectServer is JetpackItem) ? currentlyHeldObjectServer : null);
								if (val != null && (Object)(object)val != (Object)null && (Object)(object)val.backPart != (Object)null && (Object)(object)((GrabbableObject)val).playerHeldBy == (Object)(object)controller)
								{
									float s = Scale(entry.jetpack);
									Vector3 val2 = ScaleInR(entry.jetpack);
									Quaternion val3 = entry.jetpack.rotation * BlenderToUnity;
									Quaternion val4 = Quaternion.Euler(val.backPartRotationOffset);
									Remember(val.backPart);
									val.backPart.rotation = val3 * val4;
									val.backPart.position = entry.jetpack.position + val3 * Vector3.Scale(val2, val.backPartPositionOffset);
									val.backPart.localScale = Vector3.Scale(scaled[val.backPart], AxisScale(val2, val4));
									placed.Add(val.backPart);
									Diag("jetpack back part", val.backPart, entry.jetpack, s);
								}
							}
							BeltBagItem val5 = WornBag(controller);
							if (diag != null && diag.Value)
							{
								BagState(controller);
							}
							if ((Object)(object)entry.beltBag != (Object)null && ((Component)entry.beltBag).gameObject.activeInHierarchy && (Object)(object)val5 != (Object)null && (Object)(object)((GrabbableObject)val5).itemProperties != (Object)null)
							{
								if ((Object)(object)entry.vanillaSpine == (Object)null)
								{
									Transform[] bones = controller.thisPlayerModel.bones;
									foreach (Transform val6 in bones)
									{
										if ((Object)(object)val6 != (Object)null && ((Object)val6).name == "spine")
										{
											entry.vanillaSpine = val6;
											break;
										}
									}
								}
								if ((Object)(object)entry.vanillaSpine != (Object)null)
								{
									float s2 = Scale(entry.beltBag);
									Vector3 val7 = ScaleInR(entry.beltBag);
									Quaternion val8 = entry.beltBag.rotation * BlenderToUnity;
									Transform lowerTorsoCostumeContainerBeltBagOffset = controller.lowerTorsoCostumeContainerBeltBagOffset;
									Transform vanillaSpine = entry.vanillaSpine;
									Quaternion val9 = Quaternion.Inverse(vanillaSpine.rotation);
									Quaternion val10 = val9 * lowerTorsoCostumeContainerBeltBagOffset.rotation;
									Quaternion val11 = val10 * Quaternion.Euler(((GrabbableObject)val5).itemProperties.rotationOffset);
									Vector3 val12 = entry.beltBag.position + val8 * Vector3.Scale(val7, val9 * (lowerTorsoCostumeContainerBeltBagOffset.position - vanillaSpine.position));
									Remember(((Component)val5).transform);
									((Component)val5).transform.rotation = val8 * val11;
									((Component)val5).transform.position = val12 + val8 * Vector3.Scale(val7, val10 * ((GrabbableObject)val5).itemProperties.positionOffset);
									((Component)val5).transform.localScale = Vector3.Scale(scaled[((Component)val5).transform], AxisScale(val7, val11));
									placed.Add(((Component)val5).transform);
									Diag("belt bag", ((Component)val5).transform, entry.beltBag, s2);
								}
							}
						}
					}
					catch (Exception ex)
					{
						if (!logged)
						{
							logged = true;
							Plugin.Log.LogWarning((object)("ItemAnchors (skipped a frame): " + ex.Message));
						}
					}
				}
			}
			if (scaled.Count == placed.Count)
			{
				return;
			}
			drop.Clear();
			foreach (KeyValuePair<Transform, Vector3> item in scaled)
			{
				if (!placed.Contains(item.Key))
				{
					if ((Object)(object)item.Key != (Object)null)
					{
						item.Key.localScale = item.Value;
					}
					drop.Add(item.Key);
				}
			}
			foreach (Transform item2 in drop)
			{
				scaled.Remove(item2);
			}
		}

		private static void Remember(Transform t)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			if (!scaled.ContainsKey(t))
			{
				scaled[t] = t.localScale;
			}
		}
	}
	[BepInPlugin("Wee.GirlFartParty_Suits", "GirlFartParty_Suits", "0.7.24")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string GUID = "Wee.GirlFartParty_Suits";

		public const string NAME = "GirlFartParty_Suits";

		public const string VERSION = "0.7.24";

		internal static Plugin Instance;

		internal static ManualLogSource Log;

		private static readonly (Type type, string label, string defaultSuits)[] Suits = new(Type, string, string)[12]
		{
			(typeof(MRMUSHROOMCHILD), "Mushroom Child", "Mushroom Child"),
			(typeof(MRBABBLONG), "Babblong", "Babblong"),
			(typeof(MRABRA), "Abra", "Abra"),
			(typeof(MRABSOL), "Absol", "Absol"),
			(typeof(MRABSOLSHINY), "Absol Shiny", "Absol Shiny"),
			(typeof(MRGOLDENHAMSTER), "Golden Hamster", "Golden Hamster"),
			(typeof(MRRENAMON), "Renamon", "Renamon"),
			(typeof(MRSHINX), "Shinx", "Shinx"),
			(typeof(MRSHINXSHINY), "Shinx Shiny", "Shinx Shiny"),
			(typeof(MRSPOTTEDPUPPY), "Spotted Puppy", "Spotted Puppy"),
			(typeof(MRRIKU), "Riku", "Riku"),
			(typeof(MRPIGEON), "Pigeon", "Pigeon")
		};

		private void Awake()
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			CosmeticTuning.Bind(((BaseUnityPlugin)this).Config);
			QuadrupedPose.Bind(((BaseUnityPlugin)this).Config);
			HeldOnBack.Bind(((BaseUnityPlugin)this).Config);
			HideVisor.Bind(((BaseUnityPlugin)this).Config);
			EyeHeight.Bind(((BaseUnityPlugin)this).Config);
			new Harmony("Wee.GirlFartParty_Suits.eyeheight").PatchAll(typeof(EyeHeightPatches));
			new Harmony("Wee.GirlFartParty_Suits.eyedrop").PatchAll(typeof(EyeHeightDropPatch));
			FloorClamp.Bind(((BaseUnityPlugin)this).Config);
			ItemAnchors.Bind(((BaseUnityPlugin)this).Config);
			Assets.PopulateAssets();
			(Type, string, string)[] suits = Suits;
			for (int i = 0; i < suits.Length; i++)
			{
				(Type, string, string) tuple = suits[i];
				Type item = tuple.Item1;
				string item2 = tuple.Item2;
				string item3 = tuple.Item3;
				string[] array = ((BaseUnityPlugin)this).Config.Bind<string>("Suits to Replace Settings", "Suits to enable " + item2 + " for", item3, "Comma separated list of suit names that get the " + item2 + " model.").Value.Split(',');
				foreach (string text in array)
				{
					if (!string.IsNullOrWhiteSpace(text))
					{
						ModelReplacementAPI.RegisterSuitModelReplacement(text.Trim(), item);
					}
				}
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("{0} {1} loaded (bundle {2}, {3} suits)", "GirlFartParty_Suits", "0.7.24", ((Object)(object)Assets.MainAssetBundle != (Object)null) ? "ok" : "MISSING", Suits.Length));
		}
	}
	public static class Assets
	{
		public const string mainAssetBundleName = "girlfartpartybundle";

		public static AssetBundle MainAssetBundle;

		public static void PopulateAssets()
		{
			if ((Object)(object)MainAssetBundle != (Object)null)
			{
				return;
			}
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("girlfartpartybundle");
			if (stream == null)
			{
				Console.WriteLine("[GirlFartParty_Suits] embedded resource girlfartpartybundle not found");
			}
			else
			{
				MainAssetBundle = AssetBundle.LoadFromStream(stream);
			}
		}
	}
	internal sealed class QuadrupedSpec
	{
		public string[] LockToRest;

		public string[] KeepWorld;

		public string Body;

		public (string front, string hind)[] MirrorCopy;

		public (string upper, string lower, string paw)[] FrontLegs;

		public string[] HindPaws;
	}
	internal sealed class QuadrupedPose
	{
		private readonly (Transform t, Quaternion rest)[] locked;

		private readonly Transform[] keepWorld;

		private readonly Quaternion[] buf;

		private readonly (Transform a, Transform b, Transform c)[] front;

		private readonly Transform body;

		private readonly Quaternion bodyRest;

		private readonly (Transform f, Transform h, Quaternion fRel0, Quaternion hRel0Inv)[] copy;

		private readonly Transform[] hind;

		private readonly Transform[] hindSoles;

		private readonly Transform[] frontSoles;

		private float nextLog;

		private float floorAbove = float.NaN;

		private float lastLift;

		private static ConfigEntry<bool> diag;

		private static readonly Dictionary<GameObject, QuadrupedPose> cache = new Dictionary<GameObject, QuadrupedPose>();

		public static void Bind(ConfigFile config)
		{
			diag = config.Bind<bool>("Debug", "Quadruped diagnostics", false, "Log front/hind paw heights above the player's feet every 2 s (quadruped suits like Absol).");
		}

		private QuadrupedPose(GameObject model, GameObject prefab, QuadrupedSpec spec)
		{
			//IL_0382: Unknown result type (might be due to invalid IL or missing references)
			//IL_0387: Unknown result type (might be due to invalid IL or missing references)
			//IL_0392: Unknown result type (might be due to invalid IL or missing references)
			//IL_0397: Unknown result type (might be due to invalid IL or missing references)
			//IL_039c: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<string, Transform> bones = (from t in model.GetComponentsInChildren<Transform>(true)
				group t by ((Object)t).name).ToDictionary((IGrouping<string, Transform> g) => g.Key, (IGrouping<string, Transform> g) => g.First());
			Dictionary<string, Quaternion> rest = (from t in prefab.GetComponentsInChildren<Transform>(true)
				group t by ((Object)t).name).ToDictionary((IGrouping<string, Transform> g) => g.Key, (IGrouping<string, Transform> g) => g.First().localRotation);
			locked = (from n in spec.LockToRest
				where bones.ContainsKey(n) && rest.ContainsKey(n)
				select (bones[n], rest[n])).ToArray();
			keepWorld = (from n in spec.KeepWorld.Where(bones.ContainsKey)
				select bones[n]).ToArray();
			buf = (Quaternion[])(object)new Quaternion[keepWorld.Length];
			front = (from l in spec.FrontLegs
				where bones.ContainsKey(l.upper) && bones.ContainsKey(l.lower) && bones.ContainsKey(l.paw)
				select (bones[l.upper], bones[l.lower], bones[l.paw])).ToArray();
			hind = (from n in spec.HindPaws.Where(bones.ContainsKey)
				select bones[n]).ToArray();
			hindSoles = (from n in spec.HindPaws
				select (!bones.TryGetValue("Sole_" + n, out var value)) ? null : value into t
				where (Object)(object)t != (Object)null
				select t).ToArray();
			frontSoles = spec.FrontLegs.Select(((string upper, string lower, string paw) l) => (!bones.TryGetValue("Sole_" + l.paw, out value)) ? null : value).ToArray();
			if (hindSoles.Length != hind.Length || frontSoles.Any((Transform t) => (Object)(object)t == (Object)null))
			{
				Plugin.Log.LogWarning((object)$"QuadrupedPose on {((Object)model).name}: no Sole_ anchors for all paws (hind {hindSoles.Length}/{hind.Length}): paws are grounded by joint height only");
			}
			Dictionary<string, Transform> pb = (from t in prefab.GetComponentsInChildren<Transform>(true)
				group t by ((Object)t).name).ToDictionary((IGrouping<string, Transform> g) => g.Key, (IGrouping<string, Transform> g) => g.First());
			if (spec.Body != null && bones.TryGetValue(spec.Body, out body) && pb.TryGetValue(spec.Body, out var pBody))
			{
				bodyRest = Quaternion.Inverse(prefab.transform.rotation) * pBody.rotation;
				copy = (from m in spec.MirrorCopy ?? new(string, string)[0]
					where bones.ContainsKey(m.front) && bones.ContainsKey(m.hind) && pb.ContainsKey(m.front) && pb.ContainsKey(m.hind)
					select (bones[m.front], bones[m.hind], Quaternion.Inverse(pBody.rotation) * pb[m.front].rotation, Quaternion.Inverse(Quaternion.Inverse(pBody.rotation) * pb[m.hind].rotation))).ToArray();
				(Transform, Transform, Quaternion, Quaternion)[] array = copy;
				for (int num = 0; num < array.Length; num++)
				{
					RotationConstraint[] components = ((Component)array[num].Item1).GetComponents<RotationConstraint>();
					for (int num2 = 0; num2 < components.Length; num2++)
					{
						components[num2].constraintActive = false;
					}
				}
			}
			else
			{
				copy = new(Transform, Transform, Quaternion, Quaternion)[0];
			}
			if (locked.Length != spec.LockToRest.Length || keepWorld.Length != spec.KeepWorld.Length || front.Length != spec.FrontLegs.Length || hind.Length != spec.HindPaws.Length)
			{
				Plugin.Log.LogWarning((object)($"QuadrupedPose on {((Object)model).name}: missing bones (spine {locked.Length}/{spec.LockToRest.Length}, world {keepWorld.Length}/{spec.KeepWorld.Length}, " + $"front legs {front.Length}/{spec.FrontLegs.Length}, hind paws {hind.Length}/{spec.HindPaws.Length})"));
			}
		}

		public static void Apply(GameObject model, GameObject prefab, QuadrupedSpec spec, Transform feet, bool log = true)
		{
			if ((Object)(object)model == (Object)null || (Object)(object)prefab == (Object)null)
			{
				return;
			}
			if (!cache.TryGetValue(model, out var value))
			{
				foreach (GameObject item in cache.Keys.Where((GameObject k) => (Object)(object)k == (Object)null).ToList())
				{
					cache.Remove(item);
				}
				value = (cache[model] = new QuadrupedPose(model, prefab, spec));
			}
			value.Run(model, feet, log);
		}

		private void Run(GameObject model, Transform feet, bool log)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: 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_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0438: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: 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_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0504: Unknown result type (might be due to invalid IL or missing references)
			//IL_0527: Unknown result type (might be due to invalid IL or missing references)
			//IL_056b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0588: Unknown result type (might be due to invalid IL or missing references)
			//IL_0341: Unknown result type (might be due to invalid IL or missing references)
			//IL_039f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0626: Unknown result type (might be due to invalid IL or missing references)
			//IL_064a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0676: Unknown result type (might be due to invalid IL or missing references)
			//IL_0697: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < keepWorld.Length; i++)
			{
				buf[i] = keepWorld[i].rotation;
			}
			(Transform, Quaternion)[] array = locked;
			for (int j = 0; j < array.Length; j++)
			{
				var (val, localRotation) = array[j];
				val.localRotation = localRotation;
			}
			for (int k = 0; k < keepWorld.Length; k++)
			{
				keepWorld[k].rotation = buf[k];
			}
			if ((Object)(object)body != (Object)null)
			{
				Quaternion rotation = body.rotation;
				Quaternion val2 = Quaternion.Inverse(rotation);
				(Transform, Transform, Quaternion, Quaternion)[] array2 = copy;
				for (int j = 0; j < array2.Length; j++)
				{
					(Transform, Transform, Quaternion, Quaternion) tuple2 = array2[j];
					Transform item = tuple2.Item1;
					Transform item2 = tuple2.Item2;
					Quaternion item3 = tuple2.Item3;
					Quaternion item4 = tup