Decompiled source of HandsOverSkins v1.1.0

HandsOverSkins/HandsOverSkins.dll

Decompiled 3 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 System.Security;
using System.Security.Permissions;
using System.Text.Json;
using System.Text.Json.Serialization;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HandsOverSkins.API;
using HandsOverSkins.Core;
using HandsOverSkins.Patches;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Jaws.Characters;
using Jaws.Chat;
using Jaws.Gameplay.Character;
using Jaws.Gameplay.Character.Visual;
using Jaws.Gameplay.UI;
using Jaws.MainMenu.UI.Wardrobe;
using Jaws.Providers;
using Jaws.Utilities.Materials;
using Jaws.Wardrobe;
using Microsoft.CodeAnalysis;
using Project.Tools.DictionaryHelp;
using TMPro;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Localization;
using UnityEngine.Localization.Settings;
using UnityEngine.Localization.Tables;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("HandsOverSkins")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("HandsOverSkins")]
[assembly: AssemblyTitle("HandsOverSkins")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace HandsOverSkins
{
	[BepInPlugin("com.handsover.customskins", "HandsOverSkins", "1.1.0")]
	public class Plugin : BasePlugin
	{
		public const string Guid = "com.handsover.customskins";

		public const string Name = "HandsOverSkins";

		public const string Version = "1.1.0";

		internal static ManualLogSource Logger;

		internal static PluginConfig Cfg;

		internal static Harmony HarmonyInstance;

		public override void Load()
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Expected O, but got Unknown
			Logger = ((BasePlugin)this).Log;
			Cfg = new PluginConfig(((BasePlugin)this).Config);
			if (!ClassInjector.IsTypeRegisteredInIl2Cpp<SkinsRuntime>())
			{
				ClassInjector.RegisterTypeInIl2Cpp<SkinsRuntime>();
			}
			((BasePlugin)this).AddComponent<SkinsRuntime>();
			if (!ClassInjector.IsTypeRegisteredInIl2Cpp<FollowRigDriver>())
			{
				ClassInjector.RegisterTypeInIl2Cpp<FollowRigDriver>();
			}
			HarmonyInstance = new Harmony("com.handsover.customskins");
			HarmonyInstance.PatchAll(typeof(Plugin).Assembly);
			SkinBundleLoader.DiscoverBundles(Paths.PluginPath);
			if (!string.IsNullOrEmpty(Cfg.ExtraSkinFolder.Value) && Directory.Exists(Cfg.ExtraSkinFolder.Value))
			{
				SkinBundleLoader.DiscoverBundles(Cfg.ExtraSkinFolder.Value);
			}
			ManualLogSource logger = Logger;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(33, 3, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("HandsOverSkins");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.1.0");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded. ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(SkinBundleLoader.PendingCount);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" skin bundle(s) queued.");
			}
			logger.LogInfo(val);
		}
	}
	internal sealed class PluginConfig
	{
		public readonly ConfigEntry<bool> UnlockCustomSkins;

		public readonly ConfigEntry<bool> RandomSkin;

		public readonly ConfigEntry<string> RandomPool;

		public readonly ConfigEntry<bool> RandomRerollEachMatch;

		public readonly ConfigEntry<bool> AutoGhostMaterials;

		public readonly ConfigEntry<bool> AutoDeadMaterials;

		public readonly ConfigEntry<bool> GhostOnlyWhenDead;

		public readonly ConfigEntry<string> DescriptionFormat;

		public readonly ConfigEntry<bool> DumpGameData;

		public readonly ConfigEntry<string> ExtraSkinFolder;

		public readonly ConfigEntry<bool> VerboseLogging;

		public readonly ConfigEntry<string> LocalizationTable;

		public readonly ConfigEntry<bool> HangingHandAnchor;

		public readonly ConfigEntry<float> HangingBlendStart;

		public readonly ConfigEntry<float> HangingBlendEnd;

		public readonly ConfigEntry<bool> ArmIK;

		public readonly ConfigEntry<bool> ArmIKAlways;

		public readonly ConfigEntry<bool> Jiggle;

		public readonly ConfigEntry<float> ArmIKForwardStart;

		public readonly ConfigEntry<float> ArmIKForwardEnd;

		public readonly ConfigEntry<bool> LiveChange;

		public readonly ConfigEntry<bool> LiveSync;

		public readonly ConfigEntry<string> LiveNextKey;

		public readonly ConfigEntry<string> LivePrevKey;

		public readonly ConfigEntry<string> LiveRandomKey;

		public readonly ConfigEntry<string> LiveFavoriteKey;

		public readonly ConfigEntry<bool> FavoritesEnabled;

		public readonly ConfigEntry<bool> FavoritesFirst;

		public readonly ConfigEntry<bool> RandomCardFirst;

		public readonly ConfigEntry<float> FavoriteStarSize;

		public PluginConfig(ConfigFile cfg)
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			UnlockCustomSkins = cfg.Bind<bool>("Skins", "UnlockCustomSkins", false, "Ignore the RequiredLevel of custom skins and treat them as always unlocked.");
			RandomSkin = cfg.Bind<bool>("Random Skin", "Enabled", true, "Add a 'Random' card to every character's wardrobe. With it selected you get one of that character's skins at random.");
			RandomPool = cfg.Bind<string>("Random Skin", "Pool", "Unlocked", new ConfigDescription("Which skins Random picks from. Favorites = only the skins you starred in the wardrobe (falls back to Unlocked while none are starred).", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[4] { "Unlocked", "CustomOnly", "Favorites", "All" }), Array.Empty<object>()));
			RandomRerollEachMatch = cfg.Bind<bool>("Random Skin", "RerollEachMatch", true, "Pick a new random skin after every match (otherwise it changes only when you select Random again or restart).");
			AutoGhostMaterials = cfg.Bind<bool>("Materials", "AutoGhostMaterials", true, "Generate a ghost material (game shader 'MS/Ghost Unlit') for custom skin materials that don't ship one.");
			AutoDeadMaterials = cfg.Bind<bool>("Materials", "AutoDeadMaterials", true, "Generate a dead-body material (game shader 'Dissolve/SH_Dissolve_Lit5') for custom skin materials that don't ship one.");
			GhostOnlyWhenDead = cfg.Bind<bool>("Materials", "GhostOnlyWhenDead", true, "Custom skins wear ghost materials only while the character is dead. The game also asks for ghost hands on living players in some rounds (BuzzWire); set false to copy that.");
			DescriptionFormat = cfg.Bind<string>("UI", "DescriptionFormat", "<size=120%><b>{name}</b></size>\n{description}\n<size=75%><alpha=#99>by {author}</size>", "How custom skin descriptions are rendered in the wardrobe. Tokens: {name} {description} {author} {version} {character}.");
			LocalizationTable = cfg.Bind<string>("UI", "LocalizationTable", "General", "String table collection the game uses for wardrobe descriptions. Only change this if a game update renames it.");
			DumpGameData = cfg.Bind<bool>("Developer", "DumpGameData", false, "Write the game's skins, shaders (with properties) and rig bone names to BepInEx/HandsOverSkins_Dump on load. Use it to refresh the SDK after game updates.");
			ExtraSkinFolder = cfg.Bind<string>("Developer", "ExtraSkinFolder", "", "Optional extra folder scanned for *.hoskin bundles (handy while authoring: point it at the SDK's build output).");
			VerboseLogging = cfg.Bind<bool>("Developer", "VerboseLogging", false, "Log every patch decision.");
			HangingHandAnchor = cfg.Bind<bool>("Follow Rig", "HangingHandAnchor", true, "When both of the character's hands are above its head (hanging from the lobby rope), move follow-rig skins so their hands meet the tied hands. Keeps smaller or differently proportioned models attached to the rope.");
			HangingBlendStart = cfg.Bind<float>("Follow Rig", "HangingBlendStart", 0.02f, "Hands this far (m) above the head start blending toward the hand anchor.");
			HangingBlendEnd = cfg.Bind<float>("Follow Rig", "HangingBlendEnd", 0.15f, "Hands this far (m) above the head are fully hand-anchored.");
			ArmIK = cfg.Bind<bool>("Follow Rig", "ArmIK", true, "Bend follow-rig arms (two-bone IK) so their hands reach the character's real hand positions when the hands are interacting: in front of the chest (table, cards, crank) or above the head (rope). Relaxed arms are left alone.");
			ArmIKAlways = cfg.Bind<bool>("Follow Rig", "ArmIKAlways", true, "Always put the hands on the character's real hand positions (so held props like cash/cards/crank line up). Set false to only use IK when the hands are in front of the chest or raised (better for very small models standing with relaxed arms).");
			Jiggle = cfg.Bind<bool>("Follow Rig", "Jiggle", true, "Run the spring ('jiggle') bones that Follow Rig skins define (hair, tails, ears, …).");
			ArmIKForwardStart = cfg.Bind<float>("Follow Rig", "ArmIKForwardStart", 0.1f, "Hand this far (m) in front of the chest starts blending in the arm IK.");
			ArmIKForwardEnd = cfg.Bind<float>("Follow Rig", "ArmIKForwardEnd", 0.25f, "Hand this far (m) in front of the chest gets full arm IK.");
			LiveChange = cfg.Bind<bool>("Live Change", "Enabled", true, "Change your skin in the middle of a match with the hotkeys below (not while typing in chat).");
			LiveSync = cfg.Bind<bool>("Live Change", "SyncToOthers", true, "Tell the other players about the change through the game chat. Players with HandsOverSkins apply it and hide the line; players without the mod see a short 'HOSKIN …' line in chat.");
			LiveNextKey = cfg.Bind<string>("Live Change", "NextSkinKey", "F7", "Next skin (Unity Input System key name, e.g. F7, PageDown, Numpad6). Empty = off.");
			LivePrevKey = cfg.Bind<string>("Live Change", "PreviousSkinKey", "F6", "Previous skin.");
			LiveRandomKey = cfg.Bind<string>("Live Change", "RandomSkinKey", "F10", "Random unlocked skin.");
			LiveFavoriteKey = cfg.Bind<string>("Live Change", "RandomFavoriteKey", "F11", "Random skin from your favourites.");
			FavoritesEnabled = cfg.Bind<bool>("Favorites", "Enabled", true, "Show a star on every wardrobe skin card to mark favourites.");
			FavoritesFirst = cfg.Bind<bool>("Favorites", "PinToTop", true, "List favourite skins first on each character's skin page.");
			RandomCardFirst = cfg.Bind<bool>("Favorites", "RandomCardFirst", true, "Put the Random card at the very front (before the favourites).");
			FavoriteStarSize = cfg.Bind<float>("Favorites", "StarSize", 44f, "Size of the star button in UI units.");
		}
	}
}
namespace HandsOverSkins.Patches
{
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal static class CharactersProvider_Ctor
	{
		private static void Postfix(CharactersProvider __instance)
		{
			SkinInjector.EnsureInjected(__instance);
		}
	}
	[HarmonyPatch(typeof(CharactersProvider), "GetSkins")]
	internal static class CharactersProvider_GetSkins
	{
		private static void Prefix(CharactersProvider __instance)
		{
			SkinInjector.EnsureInjected(__instance);
		}
	}
	[HarmonyPatch(typeof(CharactersProvider), "TryGetSkin")]
	internal static class CharactersProvider_TryGetSkin
	{
		private static void Prefix(CharactersProvider __instance)
		{
			SkinInjector.EnsureInjected(__instance);
		}
	}
	[HarmonyPatch(typeof(CharacterSkinLogic), "TrySetSkin")]
	internal static class CharacterSkinLogic_TrySetSkin
	{
		private static void Prefix(CharacterSkinLogic __instance, ref ESkinType targetSkin, out ESkinType __state)
		{
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Expected O, but got Unknown
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected I4, but got Unknown
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected I4, but got Unknown
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected I4, but got Unknown
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Expected O, but got Unknown
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			__state = targetSkin;
			bool flag = default(bool);
			try
			{
				HiddenParts.Restore(__instance);
				CharactersProvider provider = __instance._provider;
				if (provider == null)
				{
					return;
				}
				SkinInjector.EnsureInjected(provider);
				if (LiveSkins.TryOverride(__instance, out var skin))
				{
					targetSkin = (ESkinType)(int)skin;
					__state = (ESkinType)(int)skin;
				}
				if (RandomSkins.IsRandom(targetSkin))
				{
					targetSkin = (ESkinType)(int)RandomSkins.Resolve(targetSkin);
					__state = targetSkin;
				}
				if ((int)targetSkin < 1000)
				{
					return;
				}
				CharacterSkinConfig val = default(CharacterSkinConfig);
				if (!provider.TryGetSkin(__instance._characterType, targetSkin, ref val) || (Object)(object)val == (Object)null)
				{
					if (Plugin.Cfg.VerboseLogging.Value)
					{
						ManualLogSource logger = Plugin.Logger;
						BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(49, 2, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Skin #");
							((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>((int)targetSkin);
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" for ");
							((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<ECharacterType>(__instance._characterType);
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" is not installed here, using Default.");
						}
						logger.LogInfo(val2);
					}
					targetSkin = (ESkinType)0;
				}
				__state = targetSkin;
			}
			catch (Exception ex)
			{
				ManualLogSource logger2 = Plugin.Logger;
				BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(19, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("TrySetSkin prefix: ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<Exception>(ex);
				}
				logger2.LogError(val3);
			}
		}

		private static void Postfix(CharacterSkinLogic __instance, ESkinType __state)
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			//IL_0009: 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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				ShaderResolver.RetryUnresolved();
				HiddenParts.Apply(__instance, __state);
				MaterialStates.Reapply(__instance);
				LiveSkins.Note(__instance, __state);
				Stumps.Track(__instance, __state);
				HeldItems.Apply(__instance, __state);
				if (SkinAPI.TryGetSkin(__state, out var skin))
				{
					SkinRendering.Match(__instance);
					FollowRigs.Attach(__instance, skin);
				}
				else
				{
					FollowRigs.Detach(__instance);
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logger = Plugin.Logger;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(20, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("TrySetSkin postfix: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				logger.LogError(val);
			}
		}
	}
	[HarmonyPatch(typeof(CharacterSkinLogic), "ShowHead")]
	internal static class CharacterSkinLogic_ShowHead
	{
		private static void Postfix(CharacterSkinLogic __instance, bool state)
		{
			LiveSkins.NoteShowHead(__instance, state);
			HiddenParts.Reapply(__instance);
			Stumps.Update(__instance);
			FollowRigs.Refresh(__instance);
		}
	}
	[HarmonyPatch(typeof(CharacterSkinLogic), "ShowFullBody")]
	internal static class CharacterSkinLogic_ShowFullBody
	{
		private static void Postfix(CharacterSkinLogic __instance, bool state)
		{
			LiveSkins.NoteShowFullBody(__instance, state);
			HiddenParts.Reapply(__instance);
			Stumps.Update(__instance);
			FollowRigs.Refresh(__instance);
		}
	}
	[HarmonyPatch(typeof(CharacterSkinLogic), "RestoreHands")]
	internal static class CharacterSkinLogic_RestoreHands
	{
		private static void Postfix(CharacterSkinLogic __instance)
		{
			HiddenParts.Reapply(__instance);
			Stumps.Update(__instance);
			FollowRigs.Refresh(__instance);
		}
	}
	[HarmonyPatch(typeof(CharacterSkinLogic), "CutHand")]
	internal static class CharacterSkinLogic_CutHand
	{
		private static void Postfix(CharacterSkinLogic __instance)
		{
			HiddenParts.Reapply(__instance);
			Stumps.Update(__instance);
			FollowRigs.Refresh(__instance);
		}
	}
	[HarmonyPatch(typeof(CharacterSkinLogic), "Dispose")]
	internal static class CharacterSkinLogic_Dispose
	{
		private static void Prefix(CharacterSkinLogic __instance)
		{
			HiddenParts.Forget(__instance);
			MaterialStates.Forget(__instance);
			LiveSkins.Forget(__instance);
			FollowRigs.Detach(__instance);
			Stumps.Untrack(__instance);
			HeldItems.Forget(__instance);
		}
	}
	[HarmonyPatch(typeof(CharacterVisualController), "ReplaceMaterials")]
	internal static class CharacterVisual_ReplaceMaterials
	{
		private static void Postfix(CharacterVisualController __instance, EMaterialContentType contentType)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				MaterialStates.OnReplaceMaterials(__instance, contentType);
			}
			catch (Exception ex)
			{
				ManualLogSource logger = Plugin.Logger;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(17, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Ghost materials: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				logger.LogError(val);
			}
		}
	}
	[HarmonyPatch(typeof(CharacterVisualController), "Initialize")]
	internal static class CharacterVisual_Initialize
	{
		private static void Postfix(CharacterVisualController __instance)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			try
			{
				MaterialStates.SetDead(__instance, dead: false);
				MaterialStates.OnDeadBody(__instance);
				LiveSkins.Register(__instance);
			}
			catch (Exception ex)
			{
				ManualLogSource logger = Plugin.Logger;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(23, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Dead materials (init): ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				logger.LogError(val);
			}
		}
	}
	[HarmonyPatch(typeof(CharacterVisualController), "ActivateDeadBody")]
	internal static class CharacterVisual_ActivateDeadBody
	{
		private static void Prefix(CharacterVisualController __instance)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			try
			{
				MaterialStates.OnDeadBody(__instance);
			}
			catch (Exception ex)
			{
				ManualLogSource logger = Plugin.Logger;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(16, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Dead materials: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				logger.LogError(val);
			}
		}

		private static void Postfix(CharacterVisualController __instance)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			try
			{
				MaterialStates.OnDeadBody(__instance);
			}
			catch (Exception ex)
			{
				ManualLogSource logger = Plugin.Logger;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(16, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Dead materials: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				logger.LogError(val);
			}
		}
	}
	[HarmonyPatch(typeof(CharacterManager), "ClientHandleIsDeadChanged")]
	internal static class CharacterManager_IsDeadChanged
	{
		private static void Postfix(CharacterManager __instance, bool newValue)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			try
			{
				MaterialStates.SetDead(__instance.characterVisualController, newValue);
			}
			catch (Exception ex)
			{
				ManualLogSource logger = Plugin.Logger;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(30, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Ghost materials (dead state): ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				logger.LogError(val);
			}
		}
	}
	[HarmonyPatch(typeof(ChatContainerView), "AddPlayerMessage")]
	internal static class Chat_AddPlayerMessage
	{
		private static bool Prefix(string messageText)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			try
			{
				return !LiveSkins.TryHandleChat(messageText);
			}
			catch (Exception ex)
			{
				ManualLogSource logger = Plugin.Logger;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(16, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Live skin chat: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				logger.LogError(val);
				return true;
			}
		}
	}
	[HarmonyPatch(typeof(WardrobeCharactersView), "BuildSkinCards")]
	internal static class WardrobeCharacters_BuildSkinCards
	{
		private static void Postfix(WardrobeCharactersView __instance)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			try
			{
				Favorites.Decorate(__instance);
			}
			catch (Exception ex)
			{
				ManualLogSource logger = Plugin.Logger;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(11, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Favorites: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				logger.LogError(val);
			}
		}
	}
	[HarmonyPatch(typeof(WardrobeCharactersView), "ClearSkinCards")]
	internal static class WardrobeCharacters_ClearSkinCards
	{
		private static void Prefix()
		{
			Favorites.ForgetCards();
		}
	}
	[HarmonyPatch(typeof(WardrobeService), "IsUnlocked", new Type[] { typeof(CharacterSkinConfig) })]
	internal static class WardrobeService_IsUnlockedSkin
	{
		private static void Postfix(WardrobeService __instance, CharacterSkinConfig skin, ref bool __result)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			RandomSkins.Wardrobe = __instance;
			if ((Object)(object)skin != (Object)null && RandomSkins.IsRandom(skin.skinType))
			{
				__result = true;
			}
			else if (!__result && !((Object)(object)skin == (Object)null) && Plugin.Cfg.UnlockCustomSkins.Value && SkinAPI.IsCustom(skin.skinType))
			{
				__result = true;
			}
		}
	}
	[HarmonyPatch(typeof(WardrobeView), "HandleDescriptionRequested")]
	internal static class WardrobeView_HandleDescriptionRequested
	{
		private static void Prefix(LocalizedString description, out CustomSkin __state)
		{
			__state = null;
			if (LocalizationBridge.TryGetSkin(description, out var skin))
			{
				__state = skin;
				LocalizationBridge.EnsureEntries();
			}
			else
			{
				DescriptionGuard.Clear();
			}
		}

		private static void Postfix(WardrobeView __instance, CustomSkin __state)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			if (__state == null)
			{
				return;
			}
			try
			{
				TMP_Text descriptionText = __instance.descriptionText;
				if ((Object)(object)descriptionText != (Object)null)
				{
					DescriptionGuard.Set(descriptionText, __state.FormatDescription(LocalizationBridge.CurrentLocaleCode()));
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logger = Plugin.Logger;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(21, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Description postfix: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				logger.LogError(val);
			}
		}
	}
	[HarmonyPatch(typeof(WardrobeView), "Open")]
	internal static class WardrobeView_Open
	{
		private static void Prefix()
		{
			LocalizationBridge.EnsureEntries();
		}
	}
	[HarmonyPatch(typeof(WardrobeView), "Close")]
	internal static class WardrobeView_Close
	{
		private static void Prefix()
		{
			DescriptionGuard.Clear();
		}
	}
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal static class PlayerDataService_GetSkinType
	{
		private static void Postfix(ref ESkinType __result)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected I4, but got Unknown
			try
			{
				if (RandomSkins.IsRandom(__result))
				{
					__result = (ESkinType)(int)RandomSkins.Resolve(__result);
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logger = Plugin.Logger;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(13, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Random skin: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				logger.LogError(val);
			}
		}
	}
	[HarmonyPatch(typeof(WardrobeService), "TrySelectSkin")]
	internal static class WardrobeService_TrySelectSkin
	{
		private static void Prefix(WardrobeService __instance, CharacterSkinConfig skin)
		{
			//IL_0011: 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)
			RandomSkins.Wardrobe = __instance;
			if ((Object)(object)skin != (Object)null && RandomSkins.IsRandom(skin.skinType))
			{
				RandomSkins.Reroll(skin.characterType);
			}
		}
	}
	[HarmonyPatch(typeof(GameplayUiPresenter), "HandleToLobbyClicked")]
	internal static class GameplayUi_ToLobby
	{
		private static void Postfix()
		{
			if (Plugin.Cfg.RandomRerollEachMatch.Value)
			{
				RandomSkins.Reroll();
			}
		}
	}
	internal static class HiddenParts
	{
		private static readonly Dictionary<IntPtr, (ESkinType skin, List<SkinnedMeshRenderer> hidden)> _state = new Dictionary<IntPtr, (ESkinType, List<SkinnedMeshRenderer>)>();

		private static readonly Dictionary<IntPtr, Material[]> _savedMaterials = new Dictionary<IntPtr, Material[]>();

		private static readonly Il2CppReferenceArray<Material> NoMaterials = new Il2CppReferenceArray<Material>(0L);

		private static readonly HashSet<ESkinBodyPart> Replaceable = new HashSet<ESkinBodyPart>
		{
			(ESkinBodyPart)1,
			(ESkinBodyPart)7,
			(ESkinBodyPart)2,
			(ESkinBodyPart)3,
			(ESkinBodyPart)4
		};

		private static void Hide(SkinnedMeshRenderer r)
		{
			if (!_savedMaterials.ContainsKey(((Il2CppObjectBase)r).Pointer))
			{
				_savedMaterials[((Il2CppObjectBase)r).Pointer] = ((IEnumerable<Material>)((Renderer)r).sharedMaterials).ToArray();
			}
			((Renderer)r).sharedMaterials = NoMaterials;
		}

		private static void Show(SkinnedMeshRenderer r)
		{
			if (_savedMaterials.Remove(((Il2CppObjectBase)r).Pointer, out var value))
			{
				((Renderer)r).sharedMaterials = Il2CppReferenceArray<Material>.op_Implicit(value);
			}
		}

		internal static void HideRenderer(SkinnedMeshRenderer r)
		{
			if ((Object)(object)r != (Object)null && ((Il2CppArrayBase<Material>)(object)((Renderer)r).sharedMaterials).Length > 0)
			{
				Hide(r);
			}
		}

		internal static void ShowRenderer(SkinnedMeshRenderer r)
		{
			if ((Object)(object)r != (Object)null)
			{
				Show(r);
			}
		}

		internal static Material[] Original(SkinnedMeshRenderer r)
		{
			Material[] value;
			return ((Object)(object)r == (Object)null) ? Array.Empty<Material>() : (_savedMaterials.TryGetValue(((Il2CppObjectBase)r).Pointer, out value) ? value : ((IEnumerable<Material>)((Renderer)r).sharedMaterials).ToArray());
		}

		internal static bool IsHidden(SkinnedMeshRenderer r)
		{
			return (Object)(object)r != (Object)null && _savedMaterials.ContainsKey(((Il2CppObjectBase)r).Pointer);
		}

		public static void Apply(CharacterSkinLogic logic, ESkinType skinType)
		{
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Expected O, but got Unknown
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: 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_024e: Unknown result type (might be due to invalid IL or missing references)
			if (logic == null)
			{
				return;
			}
			if (!SkinAPI.TryGetSkin(skinType, out var skin))
			{
				_state.Remove(((Il2CppObjectBase)logic).Pointer);
				return;
			}
			HashSet<ESkinBodyPart> hashSet = new HashSet<ESkinBodyPart>(skin.HiddenParts);
			foreach (KeyValuePair<ESkinBodyPart, List<SkinnedMeshRenderer>> bodyPart in skin.BodyParts)
			{
				if (bodyPart.Value != null && bodyPart.Value.Count > 0 && Replaceable.Contains(bodyPart.Key))
				{
					hashSet.Add(bodyPart.Key);
				}
			}
			if (hashSet.Contains((ESkinBodyPart)7))
			{
				hashSet.Add((ESkinBodyPart)1);
			}
			if (hashSet.Count == 0)
			{
				_state.Remove(((Il2CppObjectBase)logic).Pointer);
				return;
			}
			List<SkinnedMeshRenderer> list = new List<SkinnedMeshRenderer>();
			Dictionary<ESkinBodyPart, List<SkinnedMeshRenderer>> defaultSkin = logic._defaultSkin;
			if (defaultSkin != null)
			{
				List<SkinnedMeshRenderer> val = default(List<SkinnedMeshRenderer>);
				foreach (ESkinBodyPart item in hashSet)
				{
					if (!defaultSkin.TryGetValue(item, ref val) || val == null)
					{
						continue;
					}
					for (int i = 0; i < val.Count; i++)
					{
						SkinnedMeshRenderer val2 = val[i];
						if (!((Object)(object)val2 == (Object)null))
						{
							Hide(val2);
							list.Add(val2);
						}
					}
				}
			}
			try
			{
				Transform val3 = Stumps.MeshRoot(logic._root);
				if ((Object)(object)val3 != (Object)null)
				{
					HashSet<IntPtr> hashSet2 = CustomMeshes();
					foreach (SkinnedMeshRenderer componentsInChild in ((Component)val3).GetComponentsInChildren<SkinnedMeshRenderer>(true))
					{
						if ((Object)(object)componentsInChild == (Object)null || list.Contains(componentsInChild))
						{
							continue;
						}
						Mesh sharedMesh = componentsInChild.sharedMesh;
						if (!((Object)(object)sharedMesh != (Object)null) || !hashSet2.Contains(((Il2CppObjectBase)sharedMesh).Pointer))
						{
							ESkinBodyPart? val4 = PartByName(((Object)componentsInChild).name);
							if (val4.HasValue && hashSet.Contains(val4.Value))
							{
								Hide(componentsInChild);
								list.Add(componentsInChild);
							}
						}
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logger = Plugin.Logger;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val5 = new BepInExWarningLogInterpolatedStringHandler(24, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("Hidden parts (by name): ");
					((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(ex.Message);
				}
				logger.LogWarning(val5);
			}
			_state[((Il2CppObjectBase)logic).Pointer] = (skinType, list);
		}

		private static HashSet<IntPtr> CustomMeshes()
		{
			HashSet<IntPtr> hashSet = new HashSet<IntPtr>();
			foreach (CustomSkin skin in SkinAPI.Skins)
			{
				foreach (List<SkinnedMeshRenderer> value in skin.BodyParts.Values)
				{
					foreach (SkinnedMeshRenderer item in value)
					{
						if ((Object)(object)item != (Object)null && (Object)(object)item.sharedMesh != (Object)null)
						{
							hashSet.Add(((Il2CppObjectBase)item.sharedMesh).Pointer);
						}
					}
				}
			}
			return hashSet;
		}

		private static ESkinBodyPart? PartByName(string name)
		{
			if (string.IsNullOrEmpty(name))
			{
				return null;
			}
			string text = name.ToLowerInvariant();
			if (text.EndsWith("_cutted") || text.StartsWith("rope_"))
			{
				return null;
			}
			if (text.EndsWith("_outfit"))
			{
				return (ESkinBodyPart)2;
			}
			if (text.EndsWith("_hair"))
			{
				return (ESkinBodyPart)1;
			}
			if (text.EndsWith("_head"))
			{
				return (ESkinBodyPart)7;
			}
			if (text.EndsWith("_hand_l") || text.EndsWith("_arm_l"))
			{
				return (ESkinBodyPart)3;
			}
			if (text.EndsWith("_hand_r") || text.EndsWith("_arm_r"))
			{
				return (ESkinBodyPart)4;
			}
			return null;
		}

		public static void Reapply(CharacterSkinLogic logic)
		{
			if (logic == null || !_state.TryGetValue(((Il2CppObjectBase)logic).Pointer, out (ESkinType, List<SkinnedMeshRenderer>) value))
			{
				return;
			}
			foreach (SkinnedMeshRenderer item in value.Item2)
			{
				if (!((Object)(object)item == (Object)null) && !((Il2CppObjectBase)item).WasCollected && ((Il2CppArrayBase<Material>)(object)((Renderer)item).sharedMaterials).Length > 0)
				{
					Hide(item);
				}
			}
		}

		public static void ReapplyAll()
		{
			foreach (KeyValuePair<IntPtr, (ESkinType, List<SkinnedMeshRenderer>)> item in _state)
			{
				foreach (SkinnedMeshRenderer item2 in item.Value.Item2)
				{
					if (!((Object)(object)item2 == (Object)null) && !((Il2CppObjectBase)item2).WasCollected && ((Il2CppArrayBase<Material>)(object)((Renderer)item2).sharedMaterials).Length > 0)
					{
						Hide(item2);
					}
				}
			}
		}

		public static void Restore(CharacterSkinLogic logic)
		{
			if (logic == null || !_state.TryGetValue(((Il2CppObjectBase)logic).Pointer, out (ESkinType, List<SkinnedMeshRenderer>) value))
			{
				return;
			}
			foreach (SkinnedMeshRenderer item in value.Item2)
			{
				if ((Object)(object)item != (Object)null)
				{
					Show(item);
				}
			}
			_state.Remove(((Il2CppObjectBase)logic).Pointer);
		}

		public static void Forget(CharacterSkinLogic logic)
		{
			if (logic == null || !_state.TryGetValue(((Il2CppObjectBase)logic).Pointer, out (ESkinType, List<SkinnedMeshRenderer>) value))
			{
				return;
			}
			foreach (SkinnedMeshRenderer item in value.Item2)
			{
				if ((Object)(object)item != (Object)null)
				{
					_savedMaterials.Remove(((Il2CppObjectBase)item).Pointer);
				}
			}
			_state.Remove(((Il2CppObjectBase)logic).Pointer);
		}
	}
}
namespace HandsOverSkins.Core
{
	internal static class Favorites
	{
		private static HashSet<string> _set;

		private static Sprite _starOn;

		private static Sprite _starOff;

		private static WardrobeCharactersView _view;

		private static readonly Dictionary<IntPtr, int> _orig = new Dictionary<IntPtr, int>();

		private static string FilePath => Path.Combine(Paths.ConfigPath, "HandsOverSkins.favorites.txt");

		private static HashSet<string> Set
		{
			get
			{
				//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ab: Expected O, but got Unknown
				if (_set != null)
				{
					return _set;
				}
				_set = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
				try
				{
					if (File.Exists(FilePath))
					{
						string[] array = File.ReadAllLines(FilePath);
						foreach (string text in array)
						{
							if (!string.IsNullOrWhiteSpace(text) && !text.TrimStart().StartsWith("#"))
							{
								_set.Add(text.Trim());
							}
						}
					}
				}
				catch (Exception ex)
				{
					ManualLogSource logger = Plugin.Logger;
					bool flag = default(bool);
					BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(11, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Favorites: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
					}
					logger.LogWarning(val);
				}
				return _set;
			}
		}

		private static void Save()
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			try
			{
				File.WriteAllLines(FilePath, new string[1] { "# HandsOverSkins favourite skins (one per line)" }.Concat(Set.OrderBy((string s) => s)));
			}
			catch (Exception ex)
			{
				ManualLogSource logger = Plugin.Logger;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(18, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Favorites (save): ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				logger.LogWarning(val);
			}
		}

		public static string Key(ECharacterType character, ESkinType skin)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected I4, but got Unknown
			CustomSkin skin2;
			return SkinAPI.TryGetSkin(skin, out skin2) ? skin2.Id : $"{character}:{(int)skin}";
		}

		public static bool Is(ECharacterType character, ESkinType skin)
		{
			//IL_0005: 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)
			return Set.Contains(Key(character, skin));
		}

		public static bool Toggle(ECharacterType character, ESkinType skin)
		{
			//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)
			string item = Key(character, skin);
			bool flag = !Set.Remove(item);
			if (flag)
			{
				Set.Add(item);
			}
			Save();
			return flag;
		}

		public static bool Any(ECharacterType character)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			CharactersProvider latestProvider = SkinInjector.LatestProvider;
			if (latestProvider == null)
			{
				return false;
			}
			List<CharacterSkinConfig> val = default(List<CharacterSkinConfig>);
			if (!latestProvider._skins.TryGetValue(character, ref val) || val == null)
			{
				return false;
			}
			for (int i = 0; i < val.Count; i++)
			{
				if ((Object)(object)val[i] != (Object)null && !RandomSkins.IsRandom(val[i].skinType) && Is(character, val[i].skinType))
				{
					return true;
				}
			}
			return false;
		}

		public static void Decorate(WardrobeCharactersView view)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.Cfg.FavoritesEnabled.Value || (Object)(object)view == (Object)null)
			{
				return;
			}
			_view = view;
			Dictionary<WardrobeCardView, CharacterSkinConfig> skinCards = view._skinCards;
			if (skinCards == null)
			{
				return;
			}
			Enumerator<WardrobeCardView, CharacterSkinConfig> enumerator = skinCards.GetEnumerator();
			while (enumerator.MoveNext())
			{
				KeyValuePair<WardrobeCardView, CharacterSkinConfig> current = enumerator.Current;
				WardrobeCardView key = current.Key;
				CharacterSkinConfig value = current.Value;
				if (!((Object)(object)key == (Object)null) && !((Object)(object)value == (Object)null) && !RandomSkins.IsRandom(value.skinType))
				{
					AddStar(key, value);
				}
			}
			Sort(view);
		}

		private static void AddStar(WardrobeCardView card, CharacterSkinConfig cfg)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: 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_0115: 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_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			Transform val = ((Component)card).transform.Find("HOS_Favorite");
			GameObject val2;
			if ((Object)(object)val != (Object)null)
			{
				val2 = ((Component)val).gameObject;
			}
			else
			{
				val2 = new GameObject("HOS_Favorite");
				RectTransform val3 = val2.AddComponent<RectTransform>();
				((Transform)val3).SetParent(((Component)card).transform, false);
				Vector2 val4 = default(Vector2);
				((Vector2)(ref val4))..ctor(1f, 1f);
				val3.anchorMax = val4;
				val3.anchorMin = val4;
				val3.pivot = new Vector2(1f, 1f);
				float num = Mathf.Clamp(Plugin.Cfg.FavoriteStarSize.Value, 16f, 160f);
				val3.sizeDelta = new Vector2(num, num);
				val3.anchoredPosition = new Vector2((0f - num) * 0.15f, (0f - num) * 0.15f);
				val2.AddComponent<Image>();
				val2.AddComponent<Button>();
			}
			val2.transform.SetAsLastSibling();
			Image img = val2.GetComponent<Image>();
			Button component = val2.GetComponent<Button>();
			ECharacterType character = cfg.characterType;
			ESkinType skin = cfg.skinType;
			Paint(img, Is(character, skin));
			((UnityEventBase)component.onClick).RemoveAllListeners();
			((UnityEvent)component.onClick).AddListener(DelegateSupport.ConvertDelegate<UnityAction>((Delegate)(Action)delegate
			{
				//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)
				bool flag = Toggle(character, skin);
				Paint(img, flag);
				if ((Object)(object)_view != (Object)null && !((Il2CppObjectBase)_view).WasCollected)
				{
					Sort(_view);
				}
			}));
		}

		private static void Paint(Image img, bool on)
		{
			//IL_0043: 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)
			if (!((Object)(object)img == (Object)null))
			{
				img.sprite = (on ? StarOn() : StarOff());
				((Graphic)img).color = (Color)(on ? Color.white : new Color(1f, 1f, 1f, 0.55f));
				img.preserveAspect = true;
			}
		}

		private static void Sort(WardrobeCharactersView view)
		{
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.Cfg.FavoritesFirst.Value)
			{
				return;
			}
			Dictionary<WardrobeCardView, CharacterSkinConfig> skinCards = view._skinCards;
			if (skinCards == null || skinCards.Count == 0)
			{
				return;
			}
			List<(Transform, int, int)> list = new List<(Transform, int, int)>();
			Transform val = null;
			Enumerator<WardrobeCardView, CharacterSkinConfig> enumerator = skinCards.GetEnumerator();
			while (enumerator.MoveNext())
			{
				KeyValuePair<WardrobeCardView, CharacterSkinConfig> current = enumerator.Current;
				WardrobeCardView key = current.Key;
				if (!((Object)(object)key == (Object)null) && !((Object)(object)current.Value == (Object)null))
				{
					Transform transform = ((Component)key).transform;
					if (val == null)
					{
						val = transform.parent;
					}
					if (!((Object)(object)transform.parent != (Object)(object)val))
					{
						int item = ((!RandomSkins.IsRandom(current.Value.skinType)) ? (Is(current.Value.characterType, current.Value.skinType) ? 1 : 2) : ((!Plugin.Cfg.RandomCardFirst.Value) ? 3 : 0));
						list.Add((transform, OriginalIndex(transform), item));
					}
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			int num = ((list.Count != 0) ? list.Min<(Transform, int, int)>(((Transform t, int idx, int group) a) => a.t.GetSiblingIndex()) : 0);
			int num2 = num;
			foreach (var item2 in from a in list
				orderby a.@group, a.idx
				select a)
			{
				item2.Item1.SetSiblingIndex(num2++);
			}
		}

		private static int OriginalIndex(Transform t)
		{
			if (!_orig.TryGetValue(((Il2CppObjectBase)t).Pointer, out var value))
			{
				value = (_orig[((Il2CppObjectBase)t).Pointer] = t.GetSiblingIndex());
			}
			return value;
		}

		public static void ForgetCards()
		{
			_orig.Clear();
		}

		private static Sprite StarOn()
		{
			//IL_002a: 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)
			return ((Object)(object)_starOn != (Object)null && !((Il2CppObjectBase)_starOn).WasCollected) ? _starOn : (_starOn = MakeStar(new Color32(byte.MaxValue, (byte)205, (byte)64, byte.MaxValue), new Color32((byte)90, (byte)50, (byte)0, byte.MaxValue), filled: true));
		}

		private static Sprite StarOff()
		{
			//IL_002d: 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)
			return ((Object)(object)_starOff != (Object)null && !((Il2CppObjectBase)_starOff).WasCollected) ? _starOff : (_starOff = MakeStar(new Color32((byte)235, (byte)228, (byte)210, byte.MaxValue), new Color32((byte)20, (byte)18, (byte)16, (byte)200), filled: false));
		}

		private static Sprite MakeStar(Color32 fill, Color32 rim, bool filled)
		{
			//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_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: 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_0176: 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_0143: 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_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: 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_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(96, 96, (TextureFormat)4, false)
			{
				name = "HOS_Star",
				wrapMode = (TextureWrapMode)1
			};
			Color32[] array = (Color32[])(object)new Color32[9216];
			Vector2[] poly = Star(48f, 48f, 45.12f, 19.2f);
			Vector2[] poly2 = Star(48f, 48f, 34.56f, 14.400001f);
			Vector2 p = default(Vector2);
			for (int i = 0; i < 96; i++)
			{
				for (int j = 0; j < 96; j++)
				{
					float num = 0f;
					float num2 = 0f;
					for (int k = 0; k < 3; k++)
					{
						for (int l = 0; l < 3; l++)
						{
							((Vector2)(ref p))..ctor((float)j + ((float)l + 0.5f) / 3f, (float)i + ((float)k + 0.5f) / 3f);
							if (Inside(poly, p))
							{
								num += 1f;
							}
							if (Inside(poly2, p))
							{
								num2 += 1f;
							}
						}
					}
					num /= 9f;
					num2 /= 9f;
					Color val2 = Color.clear;
					if (num > 0f)
					{
						Color val3 = Color32.op_Implicit(rim);
						Color val4 = (Color)(filled ? Color32.op_Implicit(fill) : new Color((float)(int)fill.r / 255f, (float)(int)fill.g / 255f, (float)(int)fill.b / 255f, 0.15f));
						val2 = Color.Lerp(val3, val4, num2);
						val2.a *= num;
					}
					array[i * 96 + j] = Color32.op_Implicit(val2);
				}
			}
			val.SetPixels32(Il2CppStructArray<Color32>.op_Implicit(array));
			val.Apply();
			((Object)val).hideFlags = (HideFlags)32;
			Sprite val5 = Sprite.Create(val, new Rect(0f, 0f, 96f, 96f), new Vector2(0.5f, 0.5f), 100f);
			((Object)val5).hideFlags = (HideFlags)32;
			return val5;
		}

		private static Vector2[] Star(float cx, float cy, float ro, float ri)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			Vector2[] array = (Vector2[])(object)new Vector2[10];
			for (int i = 0; i < 10; i++)
			{
				float num = (float)Math.PI / 2f + (float)i * (float)Math.PI / 5f;
				float num2 = (((i & 1) == 0) ? ro : ri);
				array[i] = new Vector2(cx + num2 * Mathf.Cos(num), cy + num2 * Mathf.Sin(num));
			}
			return array;
		}

		private static bool Inside(Vector2[] poly, Vector2 p)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			bool flag = false;
			int num = 0;
			int num2 = poly.Length - 1;
			while (num < poly.Length)
			{
				if (poly[num].y > p.y != poly[num2].y > p.y && p.x < (poly[num2].x - poly[num].x) * (p.y - poly[num].y) / (poly[num2].y - poly[num].y) + poly[num].x)
				{
					flag = !flag;
				}
				num2 = num++;
			}
			return flag;
		}
	}
	internal static class FollowRigs
	{
		private sealed class State
		{
			public CustomSkin Skin;

			public Transform GameRoot;

			public GameObject Root;

			public Transform[] Proxies;

			public Transform[] Game;

			public Quaternion[] Offsets;

			public int Hips = -1;

			public int[] TopLevel = Array.Empty<int>();

			public Vector3[] AnchorPos;

			public Quaternion[] AnchorRot;

			public int HandL = -1;

			public int HandR = -1;

			public int UpperL = -1;

			public int UpperR = -1;

			public int LowerL = -1;

			public int LowerR = -1;

			public Transform GameHead;

			public Transform GameChest;

			public Transform GameThighL;

			public Transform GameThighR;

			public JiggleSim Jiggle;

			public bool Dead => (Object)(object)Root == (Object)null || ((Il2CppObjectBase)Root).WasCollected || (Object)(object)GameRoot == (Object)null || ((Il2CppObjectBase)GameRoot).WasCollected;
		}

		private sealed class CharRig
		{
			public Transform CharRoot;

			public Transform GameRoot;

			public Dictionary<string, Transform> Bones;

			public uint Mask;

			public int Layer = -1;

			public bool Dead => (Object)(object)GameRoot == (Object)null || ((Il2CppObjectBase)GameRoot).WasCollected;
		}

		private static readonly Dictionary<(IntPtr, string), State> _states = new Dictionary<(IntPtr, string), State>();

		private static readonly Dictionary<IntPtr, State> _byDriver = new Dictionary<IntPtr, State>();

		private static readonly Dictionary<IntPtr, CharRig> _chars = new Dictionary<IntPtr, CharRig>();

		private static readonly Dictionary<IntPtr, CustomSkin> _followMeshes = new Dictionary<IntPtr, CustomSkin>();

		private static readonly Dictionary<string, (CustomSkin skin, int[] slots)> _followByName = new Dictionary<string, (CustomSkin, int[])>();

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

		private static readonly HashSet<IntPtr> _reported = new HashSet<IntPtr>();

		private static readonly HashSet<IntPtr> _warned = new HashSet<IntPtr>();

		private static readonly Dictionary<IntPtr, int> _rebinds = new Dictionary<IntPtr, int>();

		private static readonly HashSet<IntPtr> _customMeshes = new HashSet<IntPtr>();

		private static readonly HashSet<IntPtr> _assetRenderers = new HashSet<IntPtr>();

		private static readonly HashSet<IntPtr> _styled = new HashSet<IntPtr>();

		private static int _indexedSkins = -1;

		private static float _nextScan;

		public static void Attach(CharacterSkinLogic logic, CustomSkin skin)
		{
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Expected O, but got Unknown
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Expected O, but got Unknown
			if (logic == null || skin == null)
			{
				return;
			}
			Dictionary<string, Transform> rig = logic._rigBones;
			if (rig == null)
			{
				return;
			}
			Transform gameRoot = default(Transform);
			if (!rig.TryGetValue("root", ref gameRoot) || (Object)(object)gameRoot == (Object)null)
			{
				Transform val = default(Transform);
				gameRoot = ((rig.TryGetValue("root.x", ref val) && (Object)(object)val != (Object)null) ? val.parent : logic._root);
			}
			if ((Object)(object)gameRoot == (Object)null)
			{
				return;
			}
			BuildIndex();
			DropOtherSkins(gameRoot, skin);
			if (skin.FollowRig == null || skin.FollowRig.Bones.Count == 0)
			{
				return;
			}
			Dictionary<string, Transform> all = null;
			State state = GetState(gameRoot, skin, delegate(string name)
			{
				Transform value2 = default(Transform);
				if (rig.TryGetValue(name, ref value2) && (Object)(object)value2 != (Object)null)
				{
					return value2;
				}
				if (all == null)
				{
					all = new Dictionary<string, Transform>();
					foreach (Transform componentsInChild in ((Component)gameRoot).GetComponentsInChildren<Transform>(true))
					{
						if ((Object)(object)componentsInChild != (Object)null && !((Object)componentsInChild).name.StartsWith("HOS_") && !all.ContainsKey(((Object)componentsInChild).name))
						{
							all[((Object)componentsInChild).name] = componentsInChild;
						}
					}
				}
				return all.TryGetValue(name, out value2) ? value2 : null;
			});
			if (state == null)
			{
				return;
			}
			Dictionary<ESkinBodyPart, List<SkinnedMeshRenderer>> currentSkin = logic.CurrentSkin;
			if (currentSkin == null)
			{
				return;
			}
			Enumerator<ESkinBodyPart, List<SkinnedMeshRenderer>> enumerator = currentSkin.GetEnumerator();
			bool flag = default(bool);
			while (enumerator.MoveNext())
			{
				KeyValuePair<ESkinBodyPart, List<SkinnedMeshRenderer>> current = enumerator.Current;
				List<SkinnedMeshRenderer> value = current.Value;
				if (value == null)
				{
					continue;
				}
				for (int num = 0; num < value.Count; num++)
				{
					SkinnedMeshRenderer val2 = value[num];
					if ((Object)(object)val2 == (Object)null)
					{
						continue;
					}
					if (TryBind(val2, state))
					{
						ManualLogSource logger = Plugin.Logger;
						BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(36, 1, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Follow rig: bound '");
							((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(((Object)val2).name);
							((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("' via TrySetSkin.");
						}
						logger.LogInfo(val3);
					}
					else if (((Object)(object)val2.sharedMesh == (Object)null || Lookup(val2.sharedMesh).skin == null) && _warned.Add(((Il2CppObjectBase)val2).Pointer))
					{
						ManualLogSource logger2 = Plugin.Logger;
						BepInExWarningLogInterpolatedStringHandler val4 = new BepInExWarningLogInterpolatedStringHandler(74, 2, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("Follow rig: CurrentSkin renderer '");
							((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(((Object)val2).name);
							((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("' mesh '");
							Mesh sharedMesh = val2.sharedMesh;
							((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>((sharedMesh != null) ? ((Object)sharedMesh).name : null);
							((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("' isn't a known follow-rig mesh.");
						}
						logger2.LogWarning(val4);
					}
				}
			}
			Drive(state);
		}

		public static void Refresh(CharacterSkinLogic logic)
		{
			_nextScan = 0f;
		}

		public static void Detach(CharacterSkinLogic logic)
		{
			if (logic != null)
			{
				Dictionary<string, Transform> rigBones = logic._rigBones;
				Transform val = null;
				rigBones?.TryGetValue("root", ref val);
				if ((Object)(object)val != (Object)null)
				{
					DropOtherSkins(val, null);
				}
			}
		}

		public static void Scan()
		{
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Expected O, but got Unknown
			//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: Expected O, but got Unknown
			if (Time.realtimeSinceStartup < _nextScan)
			{
				return;
			}
			_nextScan = Time.realtimeSinceStartup + 0.25f;
			if (!SkinInjector.HasInjected)
			{
				return;
			}
			BuildIndex();
			if (_customMeshes.Count == 0)
			{
				return;
			}
			Cleanup();
			bool flag = default(bool);
			foreach (Object item in (Il2CppArrayBase<Object>)(object)Resources.FindObjectsOfTypeAll(Il2CppType.Of<SkinnedMeshRenderer>()))
			{
				SkinnedMeshRenderer val = ((Il2CppObjectBase)item).TryCast<SkinnedMeshRenderer>();
				if ((Object)(object)val == (Object)null || _assetRenderers.Contains(((Il2CppObjectBase)val).Pointer))
				{
					continue;
				}
				Mesh sharedMesh = val.sharedMesh;
				if ((Object)(object)sharedMesh == (Object)null || (!_customMeshes.Contains(((Il2CppObjectBase)sharedMesh).Pointer) && !_customMeshNames.Contains(Clean(((Object)sharedMesh).name))))
				{
					continue;
				}
				GameObject gameObject = ((Component)val).gameObject;
				if ((Object)(object)gameObject == (Object)null || !gameObject.activeInHierarchy)
				{
					continue;
				}
				CharRig cr = FindCharRig(((Component)val).transform);
				if (cr == null)
				{
					continue;
				}
				if (_styled.Add(((Il2CppObjectBase)val).Pointer))
				{
					Style(val, cr);
				}
				(CustomSkin, int[]) tuple = Lookup(sharedMesh);
				Report(val, sharedMesh, cr, tuple.Item1 != null);
				if (tuple.Item1 == null)
				{
					continue;
				}
				Transform value2;
				State state = GetState(cr.GameRoot, tuple.Item1, (string name) => cr.Bones.TryGetValue(name, out value2) ? value2 : null);
				if (state == null || !TryBind(val, state))
				{
					continue;
				}
				int value;
				int num = ((!_rebinds.TryGetValue(((Il2CppObjectBase)val).Pointer, out value)) ? 1 : (value + 1));
				_rebinds[((Il2CppObjectBase)val).Pointer] = num;
				switch (num)
				{
				case 1:
				{
					ManualLogSource logger = Plugin.Logger;
					BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(42, 3, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Follow rig: bound '");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((Object)val).name);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("' to ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(tuple.Item1.Id);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" proxies under '");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((Object)cr.CharRoot).name);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("'.");
					}
					logger.LogInfo(val2);
					continue;
				}
				default:
					if (num % 50 != 0)
					{
						continue;
					}
					break;
				case 3:
					break;
				}
				ManualLogSource logger2 = Plugin.Logger;
				BepInExWarningLogInterpolatedStringHandler val3 = new BepInExWarningLogInterpolatedStringHandler(76, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Follow rig: '");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(((Object)val).name);
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("' had its bones reset ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(num - 1);
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("× by something else (re-bound each time).");
				}
				logger2.LogWarning(val3);
			}
		}

		private static void BuildIndex()
		{
			if (_indexedSkins == SkinAPI.Skins.Count)
			{
				return;
			}
			_indexedSkins = SkinAPI.Skins.Count;
			_followMeshes.Clear();
			_customMeshes.Clear();
			_assetRenderers.Clear();
			_followByName.Clear();
			_customMeshNames.Clear();
			foreach (CustomSkin skin in SkinAPI.Skins)
			{
				foreach (List<SkinnedMeshRenderer> value2 in skin.BodyParts.Values)
				{
					foreach (SkinnedMeshRenderer item in value2)
					{
						if ((Object)(object)item == (Object)null)
						{
							continue;
						}
						_assetRenderers.Add(((Il2CppObjectBase)item).Pointer);
						Mesh sharedMesh = item.sharedMesh;
						if (!((Object)(object)sharedMesh == (Object)null))
						{
							_customMeshes.Add(((Il2CppObjectBase)sharedMesh).Pointer);
							_customMeshNames.Add(Clean(((Object)sharedMesh).name));
							if (skin.FollowSlots.TryGetValue(((Il2CppObjectBase)sharedMesh).Pointer, out var value))
							{
								_followMeshes[((Il2CppObjectBase)sharedMesh).Pointer] = skin;
								_followByName[Clean(((Object)sharedMesh).name) + "|" + sharedMesh.vertexCount] = (skin, value);
							}
						}
					}
				}
			}
		}

		private static CharRig FindCharRig(Transform t)
		{
			Transform parent = t.parent;
			while ((Object)(object)parent != (Object)null)
			{
				if (_chars.TryGetValue(((Il2CppObjectBase)parent).Pointer, out var value))
				{
					if (!value.Dead)
					{
						return value;
					}
					_chars.Remove(((Il2CppObjectBase)parent).Pointer);
				}
				Transform val = parent.Find("root");
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val.Find("root.x") == (Object)null))
				{
					CharRig charRig = new CharRig
					{
						CharRoot = parent,
						GameRoot = val,
						Bones = new Dictionary<string, Transform>()
					};
					foreach (Transform componentsInChild in ((Component)val).GetComponentsInChildren<Transform>(true))
					{
						if ((Object)(object)componentsInChild != (Object)null && !charRig.Bones.ContainsKey(((Object)componentsInChild).name) && !((Object)componentsInChild).name.StartsWith("HOS_"))
						{
							charRig.Bones[((Object)componentsInChild).name] = componentsInChild;
						}
					}
					charRig.Bones["root"] = val;
					foreach (SkinnedMeshRenderer componentsInChild2 in ((Component)parent).GetComponentsInChildren<SkinnedMeshRenderer>(true))
					{
						Mesh sharedMesh = componentsInChild2.sharedMesh;
						if ((Object)(object)sharedMesh == (Object)null || _customMeshes.Contains(((Il2CppObjectBase)sharedMesh).Pointer))
						{
							continue;
						}
						charRig.Layer = ((Component)componentsInChild2).gameObject.layer;
						charRig.Mask = ((Renderer)componentsInChild2).renderingLayerMask;
						break;
					}
					_chars[((Il2CppObjectBase)parent).Pointer] = charRig;
					return charRig;
				}
				parent = parent.parent;
			}
			return null;
		}

		private static void Style(SkinnedMeshRenderer r, CharRig cr)
		{
			if (cr.Layer >= 0)
			{
				((Component)r).gameObject.layer = cr.Layer;
				((Renderer)r).renderingLayerMask = cr.Mask;
			}
			r.updateWhenOffscreen = true;
		}

		private static State GetState(Transform gameRoot, CustomSkin skin, Func<string, Transform> findBone)
		{
			(IntPtr, string) key = (((Il2CppObjectBase)gameRoot).Pointer, skin.Id);
			if (_states.TryGetValue(key, out var value))
			{
				if (!value.Dead)
				{
					return value;
				}
				Destroy(value);
				_states.Remove(key);
			}
			value = Build(gameRoot, skin, findBone);
			if (value != null)
			{
				_states[key] = value;
			}
			return value;
		}

		private static bool TryBind(SkinnedMeshRenderer smr, State st)
		{
			Mesh val = (((Object)(object)smr != (Object)null) ? smr.sharedMesh : null);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			(CustomSkin, int[]) tuple = Lookup(val);
			int[] array = ((tuple.Item1 == st.Skin) ? tuple.Item2 : null);
			if (array == null || array.Length == 0)
			{
				return false;
			}
			Il2CppReferenceArray<Transform> bones = smr.bones;
			if (bones != null && ((Il2CppArrayBase<Transform>)(object)bones).Length == array.Length && (Object)(object)((Il2CppArrayBase<Transform>)(object)bones)[0] != (Object)null && ((Il2CppObjectBase)((Il2CppArrayBase<Transform>)(object)bones)[0]).Pointer == ((Il2CppObjectBase)st.Proxies[array[0]]).Pointer)
			{
				return false;
			}
			Il2CppReferenceArray<Transform> val2 = new Il2CppReferenceArray<Transform>((long)array.Length);
			for (int i = 0; i < array.Length; i++)
			{
				((Il2CppArrayBase<Transform>)(object)val2)[i] = st.Proxies[array[i]];
			}
			smr.bones = val2;
			smr.rootBone = st.Proxies[(st.Hips >= 0) ? st.Hips : 0];
			smr.updateWhenOffscreen = true;
			return true;
		}

		private static State Build(Transform gameRoot, CustomSkin skin, Func<string, Transform> findBone)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0334: Unknown result type (might be due to invalid IL or missing references)
			//IL_033b: Expected O, but got Unknown
			//IL_0115: 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_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			List<FollowBone> bones = skin.FollowRig.Bones;
			State state = new State();
			state.Skin = skin;
			state.GameRoot = gameRoot;
			state.Root = new GameObject("HOS_FollowRig_" + skin.Id);
			state.Proxies = (Transform[])(object)new Transform[bones.Count];
			state.Game = (Transform[])(object)new Transform[bones.Count];
			state.Offsets = (Quaternion[])(object)new Quaternion[bones.Count];
			State state2 = state;
			state2.Root.transform.SetParent(gameRoot, false);
			int num = 0;
			for (int i = 0; i < bones.Count; i++)
			{
				FollowBone followBone = bones[i];
				Transform transform = new GameObject("HOS_" + (followBone.Name ?? ("bone" + i))).transform;
				transform.SetParent((followBone.Parent >= 0 && followBone.Parent < i) ? state2.Proxies[followBone.Parent] : state2.Root.transform, false);
				transform.localPosition = V3(followBone.P);
				transform.localRotation = Q(followBone.R);
				state2.Proxies[i] = transform;
				if (string.IsNullOrEmpty(followBone.GameBone))
				{
					continue;
				}
				Transform val = findBone(followBone.GameBone);
				if (!((Object)(object)val == (Object)null))
				{
					state2.Game[i] = val;
					state2.Offsets[i] = Q(followBone.Offset);
					num++;
					if (followBone.GameBone == "root.x")
					{
						state2.Hips = i;
					}
					else if (followBone.GameBone == "hand.l")
					{
						state2.HandL = i;
					}
					else if (followBone.GameBone == "hand.r")
					{
						state2.HandR = i;
					}
					else if (followBone.GameBone == "arm_stretch.l")
					{
						state2.UpperL = i;
					}
					else if (followBone.GameBone == "arm_stretch.r")
					{
						state2.UpperR = i;
					}
					else if (followBone.GameBone == "forearm_stretch.l")
					{
						state2.LowerL = i;
					}
					else if (followBone.GameBone == "forearm_stretch.r")
					{
						state2.LowerR = i;
					}
				}
			}
			state2.GameHead = findBone("head.x");
			state2.GameChest = findBone("spine_03.x") ?? findBone("spine_02.x");
			state2.GameThighL = findBone("thigh_stretch.l");
			state2.GameThighR = findBone("thigh_stretch.r");
			ComputeAnchors(state2, bones);
			BuildJiggle(state2);
			FollowRigDriver followRigDriver = state2.Root.AddComponent<FollowRigDriver>();
			_byDriver[((Il2CppObjectBase)followRigDriver).Pointer] = state2;
			ManualLogSource logger = Plugin.Logger;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(60, 5, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<CustomSkin>(skin);
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(": follow rig built under '");
				Transform parent = gameRoot.parent;
				((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>((parent != null) ? ((Object)parent).name : null);
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("' (");
				((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(bones.Count);
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" bones, ");
				((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(num);
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" following game bones");
				((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>((state2.Hips < 0) ? ", NO HIPS" : "");
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(").");
			}
			logger.LogInfo(val2);
			Drive(state2);
			return state2;
		}

		private static void BuildJiggle(State st)
		{
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Expected O, but got Unknown
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			List<FollowJiggle> jiggle = st.Skin.FollowRig.Jiggle;
			if (jiggle == null || jiggle.Count == 0)
			{
				return;
			}
			List<(int, Vector3, FollowJiggle)> list = new List<(int, Vector3, FollowJiggle)>();
			foreach (FollowJiggle item in jiggle)
			{
				if (item?.Bones == null)
				{
					continue;
				}
				for (int i = 0; i < item.Bones.Count; i++)
				{
					int num = item.Bones[i];
					if (num >= 0 && num < st.Proxies.Length && !((Object)(object)st.Game[num] != (Object)null) && item.Tips != null && item.Tips.Count >= i * 3 + 3)
					{
						list.Add((num, new Vector3(item.Tips[i * 3], item.Tips[i * 3 + 1], item.Tips[i * 3 + 2]), item));
					}
				}
			}
			if (list.Count == 0)
			{
				return;
			}
			list.Sort(((int idx, Vector3 tip, FollowJiggle g) a, (int idx, Vector3 tip, FollowJiggle g) b) => a.idx.CompareTo(b.idx));
			JiggleSim jiggleSim = new JiggleSim();
			List<FollowBone> bones = st.Skin.FollowRig.Bones;
			foreach (var item2 in list)
			{
				jiggleSim.Add(st.Proxies[item2.Item1], Q(bones[item2.Item1].R), item2.Item2, item2.Item3.Stiffness, item2.Item3.Damping, item2.Item3.Gravity);
			}
			st.Jiggle = jiggleSim;
			ManualLogSource logger = Plugin.Logger;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(18, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<CustomSkin>(st.Skin);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(jiggleSim.Count);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" jiggle bone(s).");
			}
			logger.LogInfo(val);
		}

		private static void ComputeAnchors(State st, List<FollowBone> data)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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_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_0114: 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_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: 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_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00c3: Unknown result type (might be due to invalid IL or missing references)
			if (st.Hips < 0)
			{
				return;
			}
			int count = data.Count;
			Vector3[] array = (Vector3[])(object)new Vector3[count];
			Quaternion[] array2 = (Quaternion[])(object)new Quaternion[count];
			List<int> list = new List<int>();
			for (int i = 0; i < count; i++)
			{
				FollowBone followBone = data[i];
				Vector3 val = V3(followBone.P);
				Quaternion val2 = Q(followBone.R);
				if (followBone.Parent >= 0 && followBone.Parent < i)
				{
					array[i] = array[followBone.Parent] + array2[followBone.Parent] * val;
					array2[i] = array2[followBone.Parent] * val2;
				}
				else
				{
					array[i] = val;
					array2[i] = val2;
					list.Add(i);
				}
			}
			Vector3 val3 = array[st.Hips];
			Quaternion val4 = Quaternion.Inverse(array2[st.Hips] * Quaternion.Inverse(st.Offsets[st.Hips]));
			st.TopLevel = list.ToArray();
			st.AnchorPos = (Vector3[])(object)new Vector3[list.Count];
			st.AnchorRot = (Quaternion[])(object)new Quaternion[list.Count];
			for (int j = 0; j < list.Count; j++)
			{
				int num = list[j];
				st.AnchorPos[j] = val4 * (array[num] - val3);
				st.AnchorRot[j] = val4 * array2[num];
			}
		}

		private static void DropOtherSkins(Transform gameRoot, CustomSkin keep)
		{
			List<(IntPtr, string)> list = new List<(IntPtr, string)>();
			foreach (KeyValuePair<(IntPtr, string), State> state in _states)
			{
				if (state.Key.Item1 == ((Il2CppObjectBase)gameRoot).Pointer && (keep == null || state.Value.Skin != keep))
				{
					list.Add(state.Key);
				}
			}
			foreach (var item in list)
			{
				Destroy(_states[item]);
				_states.Remove(item);
			}
		}

		private static void Cleanup()
		{
			List<(IntPtr, string)> list = new List<(IntPtr, string)>();
			foreach (KeyValuePair<(IntPtr, string), State> state in _states)
			{
				if (state.Value.Dead)
				{
					list.Add(state.Key);
				}
			}
			foreach (var item in list)
			{
				Destroy(_states[item]);
				_states.Remove(item);
			}
			List<IntPtr> list2 = new List<IntPtr>();
			foreach (KeyValuePair<IntPtr, CharRig> @char in _chars)
			{
				if (@char.Value.Dead)
				{
					list2.Add(@char.Key);
				}
			}
			foreach (IntPtr item2 in list2)
			{
				_chars.Remove(item2);
			}
			if (_styled.Count > 4096)
			{
				_styled.Clear();
			}
		}

		private static void Destroy(State st)
		{
			foreach (IntPtr item in new List<IntPtr>(_byDriver.Keys))
			{
				if (_byDriver[item] == st)
				{
					_byDriver.Remove(item);
				}
			}
			if ((Object)(object)st.Root != (Object)null && !((Il2CppObjectBase)st.Root).WasCollected)
			{
				Object.Destroy((Object)(object)st.Root);
			}
		}

		public static void Drive(IntPtr driver)
		{
			if (_byDriver.TryGetValue(driver, out var value))
			{
				Drive(value);
			}
		}

		private static void Drive(State st)
		{
			//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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			Transform[] proxies = st.Proxies;
			if (st.Hips >= 0 && (Object)(object)st.Game[st.Hips] != (Object)null)
			{
				Transform val = st.Game[st.Hips];
				Vector3 position = val.position;
				Quaternion rotation = val.rotation;
				for (int i = 0; i < st.TopLevel.Length; i++)
				{
					Transform val2 = proxies[st.TopLevel[i]];
					val2.SetPositionAndRotation(position + rotation * st.AnchorPos[i], rotation * st.AnchorRot[i]);
				}
			}
			for (int j = 0; j < proxies.Length; j++)
			{
				Transform val3 = st.Game[j];
				if (!((Object)(object)val3 == (Object)null))
				{
					proxies[j].rotation = val3.rotation * st.Offsets[j];
					if (j == st.Hips)
					{
						proxies[j].position = val3.position;
					}
				}
			}
			float hang = (Plugin.Cfg.HangingHandAnchor.Value ? HangFromHands(st) : 0f);
			if (Plugin.Cfg.ArmIK.Value)
			{
				ArmIK(st, st.UpperL, st.LowerL, st.HandL, hang);
				ArmIK(st, st.UpperR, st.LowerR, st.HandR, hang);
			}
			if (st.Jiggle != null && Plugin.Cfg.Jiggle.Value)
			{
				st.Jiggle.Update(Time.deltaTime);
			}
			HeldItems.Follow(st.Skin.Id, st.Game, proxies, st.Offsets);
		}

		private static void ArmIK(State st, int upper, int lower, int hand, float hang)
		{
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: 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_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			if (upper < 0 || lower < 0 || hand < 0)
			{
				return;
			}
			Transform val = st.Game[hand];
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			float num = (Plugin.Cfg.ArmIKAlways.Value ? 1f : hang);
			if (num < 1f && (Object)(object)st.GameChest != (Object)null && (Object)(object)st.GameThighL != (Object)null && (Object)(object)st.GameThighR != (Object)null)
			{
				Vector3 up = st.GameRoot.up;
				Vector3 val2 = st.GameThighR.position - st.GameThighL.position;
				Vector3 val3 = Vector3.Cross(val2, up);
				if (((Vector3)(ref val3)).sqrMagnitude > 1E-08f)
				{
					float num2 = Vector3.Dot(val.position - st.GameChest.position, ((Vector3)(ref val3)).normalized);
					float num3 = Mathf.InverseLerp(Plugin.Cfg.ArmIKForwardStart.Value, Plugin.Cfg.ArmIKForwardEnd.Value, num2);
					num = Mathf.Max(num, num3 * num3 * (3f - 2f * num3));
				}
			}
			if (!(num <= 0.001f))
			{
				Transform[] proxies = st.Proxies;
				SolveTwoBone(proxies[upper], proxies[lower], proxies[hand], val.position, num);
			}
		}

		internal static void SolveTwoBone(Transform upper, Transform lower, Transform hand, Vector3 target, float weight)
		{
			//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_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: 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_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: 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)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			Quaternion rotation = hand.rotation;
			Vector3 position = upper.position;
			Vector3 position2 = lower.position;
			Vector3 position3 = hand.position;
			float num = Vector3.Distance(position, position2);
			float num2 = Vector3.Distance(position2, position3);
			if (!(num < 1E-05f) && !(num2 < 1E-05f))
			{
				Vector3 val = target - position;
				float num3 = Mathf.Clamp(((Vector3)(ref val)).magnitude, Mathf.Abs(num - num2) + 0.0001f, num + num2 - 0.0001f);
				Vector3 normalized;
				if (!(((Vector3)(ref val)).sqrMagnitude > 1E-10f))
				{
					Vector3 val2 = position3 - position;
					normalized = ((Vector3)(ref val2)).normalized;
				}
				else
				{
					normalized = ((Vector3)(ref val)).normalized;
				}
				Vector3 val3 = normalized;
				Vector3 val4 = position2 - position - Vector3.Dot(position2 - position, val3) * val3;
				if (((Vector3)(ref val4)).sqrMagnitude < 1E-10f)
				{
					val4 = Vector3.Cross(val3, upper.right);
				}
				if (((Vector3)(ref val4)).sqrMagnitude < 1E-10f)
				{
					val4 = Vector3.Cross(val3, Vector3.up);
				}
				((Vector3)(ref val4)).Normalize();
				float num4 = Mathf.Clamp((num * num + num3 * num3 - num2 * num2) / (2f * num * num3), -1f, 1f);
				Vector3 val5 = position + val3 * (num * num4) + val4 * (num * Mathf.Sqrt(1f - num4 * num4));
				Vector3 val6 = position + val3 * num3;
				Quaternion val7 = Quaternion.FromToRotation(position2 - position, val5 - position);
				upper.rotation = Quaternion.Slerp(Quaternion.identity, val7, weight) * upper.rotation;
				position2 = lower.position;
				position3 = hand.position;
				Vector3 val8 = Vector3.Lerp(position3, val6, weight);
				Quaternion val9 = Quaternion.FromToRotation(position3 - position2, val8 - position2);
				lower.rotation = val9 * lower.rotation;
				hand.rotation = rotation;
			}
		}

		private static float HangFromHands(State st)
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: 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_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: 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)
			if (st.HandL < 0 || st.HandR < 0 || (Object)(object)st.GameHead == (Object)null)
			{
				return 0f;
			}
			Transform val = st.Game[st.HandL];
			Transform val2 = st.Game[st.HandR];
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				return 0f;
			}
			Vector3 up = st.GameRoot.up;
			Vector3 position = st.GameHead.position;
			float num = Mathf.Min(Vector3.Dot(val.position - position, up), Vector3.Dot(val2.position - position, up));
			float num2 = Mathf.InverseLerp(Plugin.Cfg.HangingBlendStart.Value, Plugin.Cfg.HangingBlendEnd.Value, num);
			if (num2 <= 0f)
			{
				return 0f;
			}
			num2 = num2 * num2 * (3f - 2f * num2);
			Transform[] proxies = st.Proxies;
			Vector3 val3 = (val.position + val2.position) * 0.5f;
			Vector3 val4 = (proxies[st.HandL].position + proxies[st.HandR].position) * 0.5f;
			Vector3 val5 = (val3 - val4) * num2;
			for (int i = 0; i < st.TopLevel.Length; i++)
			{
				Transform obj = proxies[st.TopLevel[i]];
				obj.position += val5;
			}
			return num2;
		}

		private static string Clean(string n)
		{
			if (string.IsNullOrEmpty(n))
			{
				return "";
			}
			return n.Replace(" (Instance)", "").Replace("(Clone)", "").Trim();
		}

		private static (CustomSkin skin, int[] slots) Lookup(Mesh mesh)
		{
			if ((Object)(object)mesh == (Object)null)
			{
				return (skin: null, slots: null);
			}
			if (_followMeshes.TryGetValue(((Il2CppObjectBase)mesh).Pointer, out var value) && value.FollowSlots.TryGetValue(((Il2CppObjectBase)mesh).Pointer, out var value2))
			{
				return (skin: value, slots: value2);
			}
			(CustomSkin, int[]) value3;
			return _followByName.TryGetValue(Clean(((Object)mesh).name) + "|" + mesh.vertexCount, out value3) ? value3 : (skin: null, slots: null);
		}

		private static void Report(SkinnedMeshRenderer r, Mesh mesh, CharRig cr, bool follow)
		{
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Expected O, but got Unknown
			if (_reported.Add(((Il2CppObjectBase)r).Pointer))
			{
				Il2CppReferenceArray<Transform> bones = r.bones;
				string text = ((bones != null && ((Il2CppArrayBase<Transform>)(object)bones).Length > 0 && (Object)(object)((Il2CppArrayBase<Transform>)(object)bones)[0] != (Object)null) ? ((Object)((Il2CppArrayBase<Transform>)(object)bones)[0]).name : "<none>");
				string text2 = (((Object)(object)((Component)r).transform.parent != (Object)null) ? ((Object)((Component)r).transform.parent).name : "<none>");
				string text3 = (((Object)(object)((Component)r).transform.parent != (Object)null && (Object)(object)((Component)r).transform.parent.parent != (Object)null) ? ((Object)((Component)r).transform.parent.parent).name : "<none>");
				ManualLogSource logger = Plugin.Logger;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new