Decompiled source of YoumuMercenary v1.0.0

YoumuMerc.dll

Decompiled 8 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HG;
using MonoMod.RuntimeDetour;
using MonoMod.RuntimeDetour.HookGen;
using On.RoR2;
using RoR2;
using RoR2.ContentManagement;
using RuneFoxMods.DynamicSkins;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace YoumuMerc
{
	[BepInPlugin("com.Miyowi.YoumuMerc", "YoumuMerc", "1.0.0")]
	public class YoumuMercPlugin : BaseUnityPlugin
	{
		public class DynamicSkinExtension
		{
			private Modification DefYoumuMerchair_back01LModification;

			private Modification DefYoumuMerchair_back01RModification;

			private Modification DefYoumuMerchair_back02LModification;

			private Modification DefYoumuMerchair_back02RModification;

			private Modification DefYoumuMerchair_back03Modification;

			private Modification DefYoumuMerchair_back_Inner01LModification;

			private Modification DefYoumuMerchair_back_Inner01RModification;

			private Modification DefYoumuMerchair_back_Inner02LModification;

			private Modification DefYoumuMerchair_back_Inner02RModification;

			private Modification DefYoumuMerchair_back_Inner03Modification;

			private Modification DefYoumuMerchair_front01Modification;

			private Modification DefYoumuMerchair_front02Modification;

			private Modification DefYoumuMerchair_front03Modification;

			private Modification DefYoumuMerchair_ribbon1Modification;

			private Modification DefYoumuMerchair_ribbon2Modification;

			private Modification DefYoumuMerchair_side01LModification;

			private Modification DefYoumuMerchair_side01RModification;

			private Modification DefYoumuMercskirt_back1_1Modification;

			private Modification DefYoumuMercskirt_back2_1LModification;

			private Modification DefYoumuMercskirt_back2_1RModification;

			private Modification DefYoumuMercskirt_back3_1LModification;

			private Modification DefYoumuMercskirt_back3_1RModification;

			private Modification DefYoumuMercskirt_back4_1LModification;

			private Modification DefYoumuMercskirt_back4_1RModification;

			private Modification DefYoumuMercskirt_front1_1Modification;

			private Modification DefYoumuMercskirt_front2_1LModification;

			private Modification DefYoumuMercskirt_front2_1RModification;

			private Modification DefYoumuMercskirt_front3_1LModification;

			private Modification DefYoumuMercskirt_front3_1RModification;

			private Modification DefYoumuMercskirt_front4_1LModification;

			private Modification DefYoumuMercskirt_front4_1RModification;

			private Modification DefYoumuMercskirt_side1LModification;

			private Modification DefYoumuMercskirt_side1RModification;

			private Modification DefYoumuMercsword_flowersModification;

			private Modification DefYoumuMercsword_fluffyModification;

			private Modification DefYoumuMerctag_stringModification;

			internal void BeforeStart()
			{
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				_DynamicSkinManager.InstanceLogger = ((BaseUnityPlugin)Instance).Logger;
				new Hook((MethodBase)typeof(SkinDef).GetMethod("ApplyAsync"), (Delegate)new Func<Func<SkinDef, GameObject, List<AssetReferenceT<Material>>, List<AssetReferenceT<Mesh>>, int, IEnumerator>, SkinDef, GameObject, List<AssetReferenceT<Material>>, List<AssetReferenceT<Mesh>>, int, IEnumerator>(_DynamicSkinManager.SkinDefApply)).Apply();
			}

			internal void AfterStart()
			{
				InitializeModifications();
				InitializeDynamicBones();
				AddModificationsToList();
			}

			internal void BeforeBodyCatalogInit()
			{
				MercBodyDefYoumuMercSkinAddedEvent += onSkinAdded;
			}

			internal void AfterBodyCatalogInit()
			{
			}

			private void InitializeModifications()
			{
				DefYoumuMerchair_back01LModification = new Modification("hair_back01L.prefab", "head", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 36, AffectsBaseModel: true, assetBundle);
				DefYoumuMerchair_back01RModification = new Modification("hair_back01R.prefab", "head", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 37, AffectsBaseModel: true, assetBundle);
				DefYoumuMerchair_back02LModification = new Modification("hair_back02L.prefab", "head", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 38, AffectsBaseModel: true, assetBundle);
				DefYoumuMerchair_back02RModification = new Modification("hair_back02R.prefab", "head", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 39, AffectsBaseModel: true, assetBundle);
				DefYoumuMerchair_back03Modification = new Modification("hair_back03.prefab", "head", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 40, AffectsBaseModel: true, assetBundle);
				DefYoumuMerchair_back_Inner01LModification = new Modification("hair_back_Inner01L.prefab", "head", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 44, AffectsBaseModel: true, assetBundle);
				DefYoumuMerchair_back_Inner01RModification = new Modification("hair_back_Inner01R.prefab", "head", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 45, AffectsBaseModel: true, assetBundle);
				DefYoumuMerchair_back_Inner02LModification = new Modification("hair_back_Inner02L.prefab", "head", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 46, AffectsBaseModel: true, assetBundle);
				DefYoumuMerchair_back_Inner02RModification = new Modification("hair_back_Inner02R.prefab", "head", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 47, AffectsBaseModel: true, assetBundle);
				DefYoumuMerchair_back_Inner03Modification = new Modification("hair_back_Inner03.prefab", "head", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 43, AffectsBaseModel: true, assetBundle);
				DefYoumuMerchair_front01Modification = new Modification("hair_front01.prefab", "head", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 32, AffectsBaseModel: true, assetBundle);
				DefYoumuMerchair_front02Modification = new Modification("hair_front02.prefab", "head", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 31, AffectsBaseModel: true, assetBundle);
				DefYoumuMerchair_front03Modification = new Modification("hair_front03.prefab", "head", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 33, AffectsBaseModel: true, assetBundle);
				DefYoumuMerchair_ribbon1Modification = new Modification("hair_ribbon1.prefab", "head", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 41, AffectsBaseModel: true, assetBundle);
				DefYoumuMerchair_ribbon2Modification = new Modification("hair_ribbon2.prefab", "head", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 42, AffectsBaseModel: true, assetBundle);
				DefYoumuMerchair_side01LModification = new Modification("hair_side01L.prefab", "head", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 34, AffectsBaseModel: true, assetBundle);
				DefYoumuMerchair_side01RModification = new Modification("hair_side01R.prefab", "head", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 35, AffectsBaseModel: true, assetBundle);
				DefYoumuMercskirt_back1_1Modification = new Modification("skirt_back1_1.prefab", "pelvis", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 155, AffectsBaseModel: true, assetBundle);
				DefYoumuMercskirt_back2_1LModification = new Modification("skirt_back2_1L.prefab", "pelvis", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 140, AffectsBaseModel: true, assetBundle);
				DefYoumuMercskirt_back2_1RModification = new Modification("skirt_back2_1R.prefab", "pelvis", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 145, AffectsBaseModel: true, assetBundle);
				DefYoumuMercskirt_back3_1LModification = new Modification("skirt_back3_1L.prefab", "pelvis", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 130, AffectsBaseModel: true, assetBundle);
				DefYoumuMercskirt_back3_1RModification = new Modification("skirt_back3_1R.prefab", "pelvis", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 135, AffectsBaseModel: true, assetBundle);
				DefYoumuMercskirt_back4_1LModification = new Modification("skirt_back4_1L.prefab", "pelvis", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 170, AffectsBaseModel: true, assetBundle);
				DefYoumuMercskirt_back4_1RModification = new Modification("skirt_back4_1R.prefab", "pelvis", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 175, AffectsBaseModel: true, assetBundle);
				DefYoumuMercskirt_front1_1Modification = new Modification("skirt_front1_1.prefab", "pelvis", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 150, AffectsBaseModel: true, assetBundle);
				DefYoumuMercskirt_front2_1LModification = new Modification("skirt_front2_1L.prefab", "pelvis", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 100, AffectsBaseModel: true, assetBundle);
				DefYoumuMercskirt_front2_1RModification = new Modification("skirt_front2_1R.prefab", "pelvis", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 105, AffectsBaseModel: true, assetBundle);
				DefYoumuMercskirt_front3_1LModification = new Modification("skirt_front3_1L.prefab", "pelvis", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 110, AffectsBaseModel: true, assetBundle);
				DefYoumuMercskirt_front3_1RModification = new Modification("skirt_front3_1R.prefab", "pelvis", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 115, AffectsBaseModel: true, assetBundle);
				DefYoumuMercskirt_front4_1LModification = new Modification("skirt_front4_1L.prefab", "pelvis", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 160, AffectsBaseModel: true, assetBundle);
				DefYoumuMercskirt_front4_1RModification = new Modification("skirt_front4_1R.prefab", "pelvis", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 165, AffectsBaseModel: true, assetBundle);
				DefYoumuMercskirt_side1LModification = new Modification("skirt_side1L.prefab", "pelvis", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 120, AffectsBaseModel: true, assetBundle);
				DefYoumuMercskirt_side1RModification = new Modification("skirt_side1R.prefab", "pelvis", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 125, AffectsBaseModel: true, assetBundle);
				DefYoumuMercsword_flowersModification = new Modification("sword_flowers.prefab", "chest", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 85, AffectsBaseModel: true, assetBundle);
				DefYoumuMercsword_fluffyModification = new Modification("sword_fluffy.prefab", "SwordBase", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 81, AffectsBaseModel: true, assetBundle);
				DefYoumuMerctag_stringModification = new Modification("tag_string.prefab", "chest", "MercBody", "MIYOWI_SKIN_DEFYOUMUMERC_NAME", 86, AffectsBaseModel: true, assetBundle);
			}

			private void InitializeDynamicBones()
			{
				//IL_003d: 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_0065: 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_00d0: 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_013b: 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_0163: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e2: 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_024d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0261: Unknown result type (might be due to invalid IL or missing references)
				//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
				//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
				//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
				//IL_0337: Unknown result type (might be due to invalid IL or missing references)
				//IL_034b: Unknown result type (might be due to invalid IL or missing references)
				//IL_035f: Unknown result type (might be due to invalid IL or missing references)
				//IL_03b6: Unknown result type (might be due to invalid IL or missing references)
				//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
				//IL_03de: Unknown result type (might be due to invalid IL or missing references)
				//IL_0435: Unknown result type (might be due to invalid IL or missing references)
				//IL_0449: Unknown result type (might be due to invalid IL or missing references)
				//IL_045d: Unknown result type (might be due to invalid IL or missing references)
				//IL_04b4: Unknown result type (might be due to invalid IL or missing references)
				//IL_04c8: Unknown result type (might be due to invalid IL or missing references)
				//IL_04dc: Unknown result type (might be due to invalid IL or missing references)
				//IL_0533: Unknown result type (might be due to invalid IL or missing references)
				//IL_0547: Unknown result type (might be due to invalid IL or missing references)
				//IL_055b: Unknown result type (might be due to invalid IL or missing references)
				//IL_05b2: Unknown result type (might be due to invalid IL or missing references)
				//IL_05c6: Unknown result type (might be due to invalid IL or missing references)
				//IL_05da: Unknown result type (might be due to invalid IL or missing references)
				//IL_0631: Unknown result type (might be due to invalid IL or missing references)
				//IL_0645: Unknown result type (might be due to invalid IL or missing references)
				//IL_0659: Unknown result type (might be due to invalid IL or missing references)
				//IL_06b0: Unknown result type (might be due to invalid IL or missing references)
				//IL_06c4: Unknown result type (might be due to invalid IL or missing references)
				//IL_06d8: Unknown result type (might be due to invalid IL or missing references)
				//IL_072f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0743: Unknown result type (might be due to invalid IL or missing references)
				//IL_0757: Unknown result type (might be due to invalid IL or missing references)
				//IL_07ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_07c2: Unknown result type (might be due to invalid IL or missing references)
				//IL_07d6: Unknown result type (might be due to invalid IL or missing references)
				//IL_082d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0841: Unknown result type (might be due to invalid IL or missing references)
				//IL_0855: Unknown result type (might be due to invalid IL or missing references)
				//IL_08ac: Unknown result type (might be due to invalid IL or missing references)
				//IL_08c0: Unknown result type (might be due to invalid IL or missing references)
				//IL_08d4: Unknown result type (might be due to invalid IL or missing references)
				//IL_08f4: Unknown result type (might be due to invalid IL or missing references)
				//IL_095b: Unknown result type (might be due to invalid IL or missing references)
				//IL_096f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0983: Unknown result type (might be due to invalid IL or missing references)
				//IL_09a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_0a0a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0a1e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0a32: Unknown result type (might be due to invalid IL or missing references)
				//IL_0a52: Unknown result type (might be due to invalid IL or missing references)
				//IL_0ab9: Unknown result type (might be due to invalid IL or missing references)
				//IL_0acd: Unknown result type (might be due to invalid IL or missing references)
				//IL_0ae1: Unknown result type (might be due to invalid IL or missing references)
				//IL_0b01: Unknown result type (might be due to invalid IL or missing references)
				//IL_0b68: Unknown result type (might be due to invalid IL or missing references)
				//IL_0b7c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0b90: Unknown result type (might be due to invalid IL or missing references)
				//IL_0bb0: Unknown result type (might be due to invalid IL or missing references)
				//IL_0c17: Unknown result type (might be due to invalid IL or missing references)
				//IL_0c2b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0c3f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0c5f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0cc6: Unknown result type (might be due to invalid IL or missing references)
				//IL_0cda: Unknown result type (might be due to invalid IL or missing references)
				//IL_0cee: Unknown result type (might be due to invalid IL or missing references)
				//IL_0d0e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0d75: Unknown result type (might be due to invalid IL or missing references)
				//IL_0d89: Unknown result type (might be due to invalid IL or missing references)
				//IL_0d9d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0dbd: Unknown result type (might be due to invalid IL or missing references)
				//IL_0e24: Unknown result type (might be due to invalid IL or missing references)
				//IL_0e38: Unknown result type (might be due to invalid IL or missing references)
				//IL_0e4c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0e6c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0ed3: Unknown result type (might be due to invalid IL or missing references)
				//IL_0ee7: Unknown result type (might be due to invalid IL or missing references)
				//IL_0efb: Unknown result type (might be due to invalid IL or missing references)
				//IL_0f1b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0f82: Unknown result type (might be due to invalid IL or missing references)
				//IL_0f96: Unknown result type (might be due to invalid IL or missing references)
				//IL_0faa: Unknown result type (might be due to invalid IL or missing references)
				//IL_0fca: Unknown result type (might be due to invalid IL or missing references)
				//IL_1031: Unknown result type (might be due to invalid IL or missing references)
				//IL_1045: Unknown result type (might be due to invalid IL or missing references)
				//IL_1059: Unknown result type (might be due to invalid IL or missing references)
				//IL_1079: Unknown result type (might be due to invalid IL or missing references)
				//IL_10e0: Unknown result type (might be due to invalid IL or missing references)
				//IL_10f4: Unknown result type (might be due to invalid IL or missing references)
				//IL_1108: Unknown result type (might be due to invalid IL or missing references)
				//IL_1128: Unknown result type (might be due to invalid IL or missing references)
				//IL_118f: Unknown result type (might be due to invalid IL or missing references)
				//IL_11a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_11b7: Unknown result type (might be due to invalid IL or missing references)
				//IL_11d7: Unknown result type (might be due to invalid IL or missing references)
				//IL_123e: Unknown result type (might be due to invalid IL or missing references)
				//IL_1252: Unknown result type (might be due to invalid IL or missing references)
				//IL_1266: Unknown result type (might be due to invalid IL or missing references)
				//IL_1286: Unknown result type (might be due to invalid IL or missing references)
				//IL_12ed: Unknown result type (might be due to invalid IL or missing references)
				//IL_1301: Unknown result type (might be due to invalid IL or missing references)
				//IL_1315: Unknown result type (might be due to invalid IL or missing references)
				//IL_1335: Unknown result type (might be due to invalid IL or missing references)
				//IL_139c: Unknown result type (might be due to invalid IL or missing references)
				//IL_13b0: Unknown result type (might be due to invalid IL or missing references)
				//IL_13c4: Unknown result type (might be due to invalid IL or missing references)
				//IL_141b: Unknown result type (might be due to invalid IL or missing references)
				//IL_142f: Unknown result type (might be due to invalid IL or missing references)
				//IL_1443: Unknown result type (might be due to invalid IL or missing references)
				//IL_149a: Unknown result type (might be due to invalid IL or missing references)
				//IL_14ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_14c2: Unknown result type (might be due to invalid IL or missing references)
				DefYoumuMerchair_back01LModification.dynamicBoneData = new DynamicBoneData("hair_back01L", 0.8f, null, 0.2f, null, 0.9f, null, 0f, null, 0f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>(), new List<string>(), (FreezeAxis)0);
				DefYoumuMerchair_back01RModification.dynamicBoneData = new DynamicBoneData("hair_back01R", 0.8f, null, 0.2f, null, 0.9f, null, 0f, null, 0f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>(), new List<string>(), (FreezeAxis)0);
				DefYoumuMerchair_back02LModification.dynamicBoneData = new DynamicBoneData("hair_back02L", 0.8f, null, 0.2f, null, 0.9f, null, 0f, null, 0f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>(), new List<string>(), (FreezeAxis)0);
				DefYoumuMerchair_back02RModification.dynamicBoneData = new DynamicBoneData("hair_back02R", 0.8f, null, 0.2f, null, 0.9f, null, 0f, null, 0f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>(), new List<string>(), (FreezeAxis)0);
				DefYoumuMerchair_back03Modification.dynamicBoneData = new DynamicBoneData("hair_back03", 0.8f, null, 0.2f, null, 0.9f, null, 0f, null, 0f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>(), new List<string>(), (FreezeAxis)0);
				DefYoumuMerchair_back_Inner01LModification.dynamicBoneData = new DynamicBoneData("hair_back_Inner01L", 0.8f, null, 0.2f, null, 0.9f, null, 0f, null, 0f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>(), new List<string>(), (FreezeAxis)0);
				DefYoumuMerchair_back_Inner01RModification.dynamicBoneData = new DynamicBoneData("hair_back_Inner01R", 0.8f, null, 0.2f, null, 0.9f, null, 0f, null, 0f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>(), new List<string>(), (FreezeAxis)0);
				DefYoumuMerchair_back_Inner02LModification.dynamicBoneData = new DynamicBoneData("hair_back_Inner02L", 0.8f, null, 0.2f, null, 0.9f, null, 0f, null, 0f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>(), new List<string>(), (FreezeAxis)0);
				DefYoumuMerchair_back_Inner02RModification.dynamicBoneData = new DynamicBoneData("hair_back_Inner02R", 0.8f, null, 0.2f, null, 0.9f, null, 0f, null, 0f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>(), new List<string>(), (FreezeAxis)0);
				DefYoumuMerchair_back_Inner03Modification.dynamicBoneData = new DynamicBoneData("hair_back_Inner03", 0.8f, null, 0.2f, null, 0.9f, null, 0f, null, 0f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>(), new List<string>(), (FreezeAxis)0);
				DefYoumuMerchair_front01Modification.dynamicBoneData = new DynamicBoneData("hair_front01", 0.8f, null, 0.2f, null, 0.9f, null, 0f, null, 0f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>(), new List<string>(), (FreezeAxis)0);
				DefYoumuMerchair_front02Modification.dynamicBoneData = new DynamicBoneData("hair_front02", 0.8f, null, 0.2f, null, 0.9f, null, 0f, null, 0f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>(), new List<string>(), (FreezeAxis)0);
				DefYoumuMerchair_front03Modification.dynamicBoneData = new DynamicBoneData("hair_front03", 0.8f, null, 0.2f, null, 0.9f, null, 0f, null, 0f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>(), new List<string>(), (FreezeAxis)0);
				DefYoumuMerchair_ribbon1Modification.dynamicBoneData = new DynamicBoneData("hair_ribbon1", 0.4f, null, 0.2f, null, 0.9f, null, 0f, null, 0f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>(), new List<string>(), (FreezeAxis)0);
				DefYoumuMerchair_ribbon2Modification.dynamicBoneData = new DynamicBoneData("hair_ribbon2", 0.4f, null, 0.2f, null, 0.9f, null, 0f, null, 0f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>(), new List<string>(), (FreezeAxis)0);
				DefYoumuMerchair_side01LModification.dynamicBoneData = new DynamicBoneData("hair_side01L", 0.8f, null, 0.2f, null, 0.9f, null, 0f, null, 0f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>(), new List<string>(), (FreezeAxis)0);
				DefYoumuMerchair_side01RModification.dynamicBoneData = new DynamicBoneData("hair_side01R", 0.8f, null, 0.2f, null, 0.9f, null, 0f, null, 0f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>(), new List<string>(), (FreezeAxis)0);
				DefYoumuMercskirt_back1_1Modification.dynamicBoneData = new DynamicBoneData("skirt_back1_1", 0.407f, null, 0.296f, null, 0.725f, null, 0f, null, 0.03f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>
				{
					new DynamicBoneColliderData("pelvis", (Direction)0, new Vector3(0f, 0.09f, 0f), (Bound)0, 0.11f, 0.41f)
				}, new List<string>(), (FreezeAxis)0);
				DefYoumuMercskirt_back2_1LModification.dynamicBoneData = new DynamicBoneData("skirt_back2_1L", 0.407f, null, 0.296f, null, 0.725f, null, 0f, null, 0.03f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>
				{
					new DynamicBoneColliderData("pelvis", (Direction)0, new Vector3(0f, 0.09f, 0f), (Bound)0, 0.11f, 0.41f)
				}, new List<string>(), (FreezeAxis)0);
				DefYoumuMercskirt_back2_1RModification.dynamicBoneData = new DynamicBoneData("skirt_back2_1R", 0.407f, null, 0.296f, null, 0.725f, null, 0f, null, 0.03f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>
				{
					new DynamicBoneColliderData("pelvis", (Direction)0, new Vector3(0f, 0.09f, 0f), (Bound)0, 0.11f, 0.41f)
				}, new List<string>(), (FreezeAxis)0);
				DefYoumuMercskirt_back3_1LModification.dynamicBoneData = new DynamicBoneData("skirt_back3_1L", 0.407f, null, 0.296f, null, 0.725f, null, 0f, null, 0.03f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>
				{
					new DynamicBoneColliderData("pelvis", (Direction)0, new Vector3(0f, 0.09f, 0f), (Bound)0, 0.11f, 0.41f)
				}, new List<string>(), (FreezeAxis)0);
				DefYoumuMercskirt_back3_1RModification.dynamicBoneData = new DynamicBoneData("skirt_back3_1R", 0.407f, null, 0.296f, null, 0.725f, null, 0f, null, 0.03f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>
				{
					new DynamicBoneColliderData("pelvis", (Direction)0, new Vector3(0f, 0.09f, 0f), (Bound)0, 0.11f, 0.41f)
				}, new List<string>(), (FreezeAxis)0);
				DefYoumuMercskirt_back4_1LModification.dynamicBoneData = new DynamicBoneData("skirt_back4_1L", 0.407f, null, 0.296f, null, 0.725f, null, 0f, null, 0.03f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>
				{
					new DynamicBoneColliderData("pelvis", (Direction)0, new Vector3(0f, 0.09f, 0f), (Bound)0, 0.11f, 0.41f)
				}, new List<string>(), (FreezeAxis)0);
				DefYoumuMercskirt_back4_1RModification.dynamicBoneData = new DynamicBoneData("skirt_back4_1R", 0.407f, null, 0.296f, null, 0.725f, null, 0f, null, 0.03f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>
				{
					new DynamicBoneColliderData("pelvis", (Direction)0, new Vector3(0f, 0.09f, 0f), (Bound)0, 0.11f, 0.41f)
				}, new List<string>(), (FreezeAxis)0);
				DefYoumuMercskirt_front1_1Modification.dynamicBoneData = new DynamicBoneData("skirt_front1_1", 0.7f, null, 0.1f, null, 1f, null, 0f, null, 0.05f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>
				{
					new DynamicBoneColliderData("pelvis", (Direction)0, new Vector3(0f, 0.09f, 0f), (Bound)0, 0.11f, 0.41f)
				}, new List<string>(), (FreezeAxis)0);
				DefYoumuMercskirt_front2_1LModification.dynamicBoneData = new DynamicBoneData("skirt_front2_1L", 0.7f, null, 0.1f, null, 1f, null, 0f, null, 0.05f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>
				{
					new DynamicBoneColliderData("pelvis", (Direction)0, new Vector3(0f, 0.09f, 0f), (Bound)0, 0.11f, 0.41f)
				}, new List<string>(), (FreezeAxis)0);
				DefYoumuMercskirt_front2_1RModification.dynamicBoneData = new DynamicBoneData("skirt_front2_1R", 0.7f, null, 0.1f, null, 1f, null, 0f, null, 0.05f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>
				{
					new DynamicBoneColliderData("pelvis", (Direction)0, new Vector3(0f, 0.09f, 0f), (Bound)0, 0.11f, 0.41f)
				}, new List<string>(), (FreezeAxis)0);
				DefYoumuMercskirt_front3_1LModification.dynamicBoneData = new DynamicBoneData("skirt_front3_1L", 0.7f, null, 0.1f, null, 1f, null, 0f, null, 0.05f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>
				{
					new DynamicBoneColliderData("pelvis", (Direction)0, new Vector3(0f, 0.09f, 0f), (Bound)0, 0.11f, 0.41f)
				}, new List<string>(), (FreezeAxis)0);
				DefYoumuMercskirt_front3_1RModification.dynamicBoneData = new DynamicBoneData("skirt_front3_1R", 0.7f, null, 0.1f, null, 1f, null, 0f, null, 0.05f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>
				{
					new DynamicBoneColliderData("pelvis", (Direction)0, new Vector3(0f, 0.09f, 0f), (Bound)0, 0.11f, 0.41f)
				}, new List<string>(), (FreezeAxis)0);
				DefYoumuMercskirt_front4_1LModification.dynamicBoneData = new DynamicBoneData("skirt_front4_1L", 0.407f, null, 0.296f, null, 1f, null, 0f, null, 0.05f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>
				{
					new DynamicBoneColliderData("pelvis", (Direction)0, new Vector3(0f, 0.09f, 0f), (Bound)0, 0.11f, 0.41f)
				}, new List<string>(), (FreezeAxis)0);
				DefYoumuMercskirt_front4_1RModification.dynamicBoneData = new DynamicBoneData("skirt_front4_1R", 0.407f, null, 0.296f, null, 1f, null, 0f, null, 0.05f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>
				{
					new DynamicBoneColliderData("pelvis", (Direction)0, new Vector3(0f, 0.09f, 0f), (Bound)0, 0.11f, 0.41f)
				}, new List<string>(), (FreezeAxis)0);
				DefYoumuMercskirt_side1LModification.dynamicBoneData = new DynamicBoneData("skirt_side1L", 0.407f, null, 0.296f, null, 0.725f, null, 0f, null, 0.03f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>
				{
					new DynamicBoneColliderData("pelvis", (Direction)0, new Vector3(0f, 0.09f, 0f), (Bound)0, 0.11f, 0.41f)
				}, new List<string>(), (FreezeAxis)0);
				DefYoumuMercskirt_side1RModification.dynamicBoneData = new DynamicBoneData("skirt_side1R", 0.407f, null, 0.296f, null, 0.725f, null, 0f, null, 0.03f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>
				{
					new DynamicBoneColliderData("pelvis", (Direction)0, new Vector3(0f, 0.09f, 0f), (Bound)0, 0.11f, 0.41f)
				}, new List<string>(), (FreezeAxis)0);
				DefYoumuMercsword_flowersModification.dynamicBoneData = new DynamicBoneData("sword_flowers", 0.315f, null, 0.2f, null, 0.865f, null, 0f, null, 0f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>(), new List<string>(), (FreezeAxis)0);
				DefYoumuMercsword_fluffyModification.dynamicBoneData = new DynamicBoneData("sword_fluffy", 0.908f, null, 0.166f, null, 0.431f, null, 0f, null, 0f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, -0.03f, 0f), new List<DynamicBoneColliderData>(), new List<string>(), (FreezeAxis)0);
				DefYoumuMerctag_stringModification.dynamicBoneData = new DynamicBoneData("tag_string", 0.4f, null, 0.2f, null, 0.339f, null, 0f, null, 0f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, -0.01f, 0f), new List<DynamicBoneColliderData>(), new List<string>(), (FreezeAxis)0);
			}

			private void AddModificationsToList()
			{
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 36, DefYoumuMerchair_back01LModification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 37, DefYoumuMerchair_back01RModification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 38, DefYoumuMerchair_back02LModification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 39, DefYoumuMerchair_back02RModification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 40, DefYoumuMerchair_back03Modification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 44, DefYoumuMerchair_back_Inner01LModification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 45, DefYoumuMerchair_back_Inner01RModification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 46, DefYoumuMerchair_back_Inner02LModification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 47, DefYoumuMerchair_back_Inner02RModification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 43, DefYoumuMerchair_back_Inner03Modification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 32, DefYoumuMerchair_front01Modification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 31, DefYoumuMerchair_front02Modification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 33, DefYoumuMerchair_front03Modification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 41, DefYoumuMerchair_ribbon1Modification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 42, DefYoumuMerchair_ribbon2Modification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 34, DefYoumuMerchair_side01LModification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 35, DefYoumuMerchair_side01RModification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 155, DefYoumuMercskirt_back1_1Modification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 140, DefYoumuMercskirt_back2_1LModification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 145, DefYoumuMercskirt_back2_1RModification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 130, DefYoumuMercskirt_back3_1LModification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 135, DefYoumuMercskirt_back3_1RModification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 170, DefYoumuMercskirt_back4_1LModification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 175, DefYoumuMercskirt_back4_1RModification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 150, DefYoumuMercskirt_front1_1Modification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 100, DefYoumuMercskirt_front2_1LModification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 105, DefYoumuMercskirt_front2_1RModification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 110, DefYoumuMercskirt_front3_1LModification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 115, DefYoumuMercskirt_front3_1RModification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 160, DefYoumuMercskirt_front4_1LModification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 165, DefYoumuMercskirt_front4_1RModification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 120, DefYoumuMercskirt_side1LModification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 125, DefYoumuMercskirt_side1RModification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 85, DefYoumuMercsword_flowersModification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 81, DefYoumuMercsword_fluffyModification);
				_DynamicSkinManager.AddModification("MIYOWI_SKIN_DEFYOUMUMERC_NAME", 86, DefYoumuMerctag_stringModification);
			}

			private static void onSkinAdded(object sender, SkinAddedArgs e)
			{
				_DynamicSkinManager.AddSkinDef(e.skinDef);
			}
		}

		public delegate void VoidDelegate();

		public class SkinAddedArgs : EventArgs
		{
			public SkinDef skinDef { get; }

			public GameObject bodyPrefab { get; }

			public SkinAddedArgs(SkinDef newSkinDef, GameObject newGameObject)
			{
				skinDef = newSkinDef;
				bodyPrefab = newGameObject;
			}
		}

		private class FieldException : Exception
		{
			public FieldException(string message, Exception innerException)
				: base(message, innerException)
			{
			}
		}

		private static DynamicSkinExtension _DynamicSkinExtension = new DynamicSkinExtension();

		private static DynamicSkinManager _DynamicSkinManager = new DynamicSkinManager();

		private static VoidDelegate BeforeStartDelegate;

		private static VoidDelegate AfterStartDelegate;

		private static VoidDelegate BeforeBodyCatalogDelegate;

		private static VoidDelegate AfterBodyCatalogDelegate;

		public static PluginInfo pluginInfo;

		private static AssetBundle assetBundle;

		private static readonly List<Material> materialsWithRoRShader = new List<Material>();

		internal static YoumuMercPlugin Instance { get; private set; }

		internal static ManualLogSource InstanceLogger
		{
			get
			{
				YoumuMercPlugin instance = Instance;
				if (instance == null)
				{
					return null;
				}
				return ((BaseUnityPlugin)instance).Logger;
			}
		}

		private static event EventHandler<SkinAddedArgs> MercBodyDefYoumuMercSkinAddedEvent;

		private void Awake()
		{
			pluginInfo = ((BaseUnityPlugin)this).Info;
			Assets.Init();
		}

		private void Start()
		{
			Instance = this;
			BeforeStart();
			using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("YoumuMerc.miyowiyoumumerc"))
			{
				assetBundle = AssetBundle.LoadFromStream(stream);
			}
			((ResourceAvailability)(ref BodyCatalog.availability)).CallWhenAvailable((Action)BodyCatalogInit);
			HookEndpointManager.Add((MethodBase)typeof(Language).GetMethod("LoadStrings"), (Delegate)new Action<Action<Language>, Language>(LanguageLoadStrings));
			ReplaceShaders();
			AfterStart();
		}

		private void BeforeStart()
		{
			BeforeStartDelegate = (VoidDelegate)Delegate.Combine(BeforeStartDelegate, new VoidDelegate(_DynamicSkinExtension.BeforeStart));
			BeforeStartDelegate?.Invoke();
		}

		private void AfterStart()
		{
			AfterStartDelegate = (VoidDelegate)Delegate.Combine(AfterStartDelegate, new VoidDelegate(_DynamicSkinExtension.AfterStart));
			AfterStartDelegate?.Invoke();
		}

		private static void BeforeBodyCatalogInit()
		{
			BeforeBodyCatalogDelegate = (VoidDelegate)Delegate.Combine(BeforeBodyCatalogDelegate, new VoidDelegate(_DynamicSkinExtension.BeforeBodyCatalogInit));
			BeforeBodyCatalogDelegate?.Invoke();
		}

		private static void AfterBodyCatalogInit()
		{
			AfterBodyCatalogDelegate = (VoidDelegate)Delegate.Combine(AfterBodyCatalogDelegate, new VoidDelegate(_DynamicSkinExtension.AfterBodyCatalogInit));
			AfterBodyCatalogDelegate?.Invoke();
		}

		private static void ReplaceShaders()
		{
			LoadMaterialsWithReplacedShader("RoR2/Base/Shaders/HGStandard.shader", "Assets/Skins/YoumuMerc/Skin/matYoumuMerc.mat");
		}

		private static void LoadMaterialsWithReplacedShader(string shaderPath, params string[] materialPaths)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			Shader shader = Addressables.LoadAssetAsync<Shader>((object)shaderPath).WaitForCompletion();
			foreach (string text in materialPaths)
			{
				Material val = assetBundle.LoadAsset<Material>(text);
				val.shader = shader;
				materialsWithRoRShader.Add(val);
			}
		}

		private static void LanguageLoadStrings(Action<Language> orig, Language self)
		{
			orig(self);
			self.SetStringByToken("MIYOWI_SKIN_DEFYOUMUMERC_NAME", "Youmu");
		}

		private static void BodyCatalogInit()
		{
			BeforeBodyCatalogInit();
			AddMercBodyDefYoumuMercSkin();
			AfterBodyCatalogInit();
		}

		private static void MercBodyDefYoumuMercSkinAdded(SkinDef skinDef, GameObject bodyPrefab)
		{
			YoumuMercPlugin.MercBodyDefYoumuMercSkinAddedEvent(Instance, new SkinAddedArgs(skinDef, bodyPrefab));
		}

		private static void AddMercBodyDefYoumuMercSkin()
		{
			string text = "MercBody";
			string text2 = "DefYoumuMerc";
			try
			{
				GameObject val = BodyCatalog.FindBodyPrefab(text);
				if (!Object.op_Implicit((Object)(object)val))
				{
					InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" skin because \"" + text + "\" doesn't exist"));
					return;
				}
				ModelLocator component = val.GetComponent<ModelLocator>();
				if (!Object.op_Implicit((Object)(object)component))
				{
					InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" skin to \"" + text + "\" because it doesn't have \"ModelLocator\" component"));
					return;
				}
				GameObject gameObject = ((Component)component.modelTransform).gameObject;
				((Component)(gameObject.transform.Find("MercArmature/ROOT/base/stomach/chest/Point Light (1)") ?? gameObject.transform.Find("MercArmature/ROOT/base/stomach/chest/Point Light"))).gameObject.SetActive(false);
				((Component)(gameObject.transform.Find("MercArmature/ROOT/base/stomach/chest/SwingCenter/SwordBase/Point Light (1)") ?? gameObject.transform.Find("MercArmature/ROOT/base/stomach/chest/SwingCenter/SwordBase/Point Light"))).gameObject.SetActive(false);
				ModelSkinController skinController = (Object.op_Implicit((Object)(object)gameObject) ? gameObject.GetComponent<ModelSkinController>() : null);
				if (!Object.op_Implicit((Object)(object)skinController))
				{
					InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" skin to \"" + text + "\" because it doesn't have \"ModelSkinController\" component"));
					return;
				}
				Renderer[] renderers = gameObject.GetComponentsInChildren<Renderer>(true);
				SkinDef skin = ScriptableObject.CreateInstance<SkinDef>();
				SkinDefParams skinParams = ScriptableObject.CreateInstance<SkinDefParams>();
				skin.skinDefParams = skinParams;
				TryCatchThrow("Icon", delegate
				{
					skin.icon = assetBundle.LoadAsset<Sprite>("Assets\\SkinMods\\YoumuMerc\\Icons\\DefYoumuMercIcon.png");
				});
				((Object)skin).name = text2;
				skin.nameToken = "MIYOWI_SKIN_DEFYOUMUMERC_NAME";
				skin.rootObject = gameObject;
				TryCatchThrow("Base Skins", delegate
				{
					skin.baseSkins = (SkinDef[])(object)new SkinDef[1] { skinController.skins[0] };
				});
				TryCatchThrow("Unlockable Name", delegate
				{
					skin.unlockableDef = null;
				});
				TryCatchThrow("Game Object Activations", delegate
				{
					skinParams.gameObjectActivations = Array.Empty<GameObjectActivation>();
				});
				TryCatchThrow("Renderer Infos", delegate
				{
					//IL_0010: Unknown result type (might be due to invalid IL or missing references)
					//IL_002f: Unknown result type (might be due to invalid IL or missing references)
					//IL_006d: 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_0077: 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_00d4: 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)
					skinParams.rendererInfos = (RendererInfo[])(object)new RendererInfo[2]
					{
						new RendererInfo
						{
							defaultMaterial = assetBundle.LoadAsset<Material>("Assets/Skins/YoumuMerc/Skin/matYoumuMerc.mat"),
							defaultShadowCastingMode = (ShadowCastingMode)0,
							ignoreOverlays = false,
							renderer = renderers.First((Renderer r) => ((Object)r).name == "MercMesh")
						},
						new RendererInfo
						{
							defaultMaterial = assetBundle.LoadAsset<Material>("Assets/Skins/YoumuMerc/Skin/matYoumuMerc.mat"),
							defaultShadowCastingMode = (ShadowCastingMode)0,
							ignoreOverlays = false,
							renderer = renderers.First((Renderer r) => ((Object)r).name == "MercSwordMesh")
						}
					};
				});
				TryCatchThrow("Mesh Replacements", delegate
				{
					//IL_0010: 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_005e: Unknown result type (might be due to invalid IL or missing references)
					//IL_0067: Unknown result type (might be due to invalid IL or missing references)
					//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
					//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
					skinParams.meshReplacements = (MeshReplacement[])(object)new MeshReplacement[2]
					{
						new MeshReplacement
						{
							mesh = assetBundle.LoadAsset<Mesh>("Assets\\SkinMods\\YoumuMerc\\Meshes\\BodyMesh.mesh"),
							renderer = renderers.First((Renderer r) => ((Object)r).name == "MercMesh")
						},
						new MeshReplacement
						{
							mesh = assetBundle.LoadAsset<Mesh>("Assets\\SkinMods\\YoumuMerc\\Meshes\\SwordMesh.mesh"),
							renderer = renderers.First((Renderer r) => ((Object)r).name == "MercSwordMesh")
						}
					};
				});
				TryCatchThrow("Light Infos", delegate
				{
					skinParams.lightReplacements = (LightInfo[])(object)new LightInfo[0];
				});
				TryCatchThrow("Minion Skin Replacements", delegate
				{
					skinParams.minionSkinReplacements = Array.Empty<MinionSkinReplacement>();
				});
				TryCatchThrow("Projectile Ghost Replacements", delegate
				{
					skinParams.projectileGhostReplacements = Array.Empty<ProjectileGhostReplacement>();
				});
				Array.Resize(ref skinController.skins, skinController.skins.Length + 1);
				skinController.skins[skinController.skins.Length - 1] = skin;
				MwSkinEvents.Init(skin);
				MercBodyDefYoumuMercSkinAdded(skin, val);
			}
			catch (FieldException ex)
			{
				InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" skin to \"" + text + "\""));
				InstanceLogger.LogWarning((object)("Field causing issue: " + ex.Message));
				InstanceLogger.LogError((object)ex.InnerException);
			}
			catch (Exception ex2)
			{
				InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" skin to \"" + text + "\""));
				InstanceLogger.LogError((object)ex2);
			}
		}

		private static void TryCatchThrow(string message, Action action)
		{
			try
			{
				action?.Invoke();
			}
			catch (Exception innerException)
			{
				throw new FieldException(message, innerException);
			}
		}

		private static void TryAddComponent<T>(GameObject obj) where T : Component
		{
			if (!Object.op_Implicit((Object)(object)obj.GetComponent<T>()))
			{
				obj.AddComponent<T>();
			}
		}
	}
	public static class Assets
	{
		public static AssetBundle mainAssetBundle = null;

		internal static string assetBundleName = "mwmwyoumubundle";

		internal static string assemblyDir => Path.GetDirectoryName(YoumuMercPlugin.pluginInfo.Location);

		public static void Init()
		{
			mainAssetBundle = AssetBundle.LoadFromFile(Path.Combine(assemblyDir, assetBundleName));
		}
	}
	public static class MwSkinEvents
	{
		private static SkinDef _eventSkin;

		public static SkinDef eventSkin => _eventSkin;

		public static event Action<GameObject> SkinAppliedLobby;

		public static event Action<GameObject> SkinAppliedRun;

		public static event Action<GameObject> DifferentSkinApplied;

		public static event Action<GameObject> Death;

		public static void Init(SkinDef skin)
		{
			_eventSkin = skin;
			MwTransformController.Init();
			SubscribeEvents();
		}

		private static void SubscribeEvents()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			ModelSkinController.ApplySkinAsync += new hook_ApplySkinAsync(OnSkinAppliedBody);
			CharacterBody.OnDeathStart += new hook_OnDeathStart(OnDeath);
		}

		public static bool HasEventSkin(GameObject obj)
		{
			return (Object)(object)eventSkin == (Object)(object)SkinCatalog.FindCurrentSkinDefForBodyInstance(obj);
		}

		private static IEnumerator OnSkinAppliedBody(orig_ApplySkinAsync orig, ModelSkinController self, int skinIndex, AsyncReferenceHandleUnloadType unloadType)
		{
			//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)
			yield return orig.Invoke(self, skinIndex, unloadType);
			object obj;
			if (self == null)
			{
				obj = null;
			}
			else
			{
				CharacterModel characterModel = self.characterModel;
				if (characterModel == null)
				{
					obj = null;
				}
				else
				{
					CharacterBody body = characterModel.body;
					obj = ((body != null) ? ((Component)body).gameObject : null);
				}
			}
			GameObject val = (GameObject)obj;
			if ((Object)(object)val != (Object)null && HasEventSkin(val))
			{
				MwSkinEvents.SkinAppliedRun?.Invoke(val);
			}
			else if ((Object)(object)val == (Object)null && (Object)(object)ArrayUtils.GetSafe<SkinDef>(self.skins, self.currentSkinIndex) == (Object)(object)eventSkin)
			{
				MwSkinEvents.SkinAppliedLobby?.Invoke(((Component)self).gameObject);
			}
			else if ((Object)(object)val != (Object)null)
			{
				MwSkinEvents.DifferentSkinApplied?.Invoke(val);
			}
			else
			{
				MwSkinEvents.DifferentSkinApplied?.Invoke(((Component)self).gameObject);
			}
		}

		private static void OnDeath(orig_OnDeathStart orig, CharacterBody self)
		{
			orig.Invoke(self);
			if (HasEventSkin(((Component)self).gameObject))
			{
				MwSkinEvents.Death?.Invoke(((Component)self).gameObject);
			}
		}
	}
	public class MwTransformController : MonoBehaviour
	{
		public Vector3 clavOffset = new Vector3(0.015f, 0.05f, -0.05f);

		public Vector3 swordOffset = new Vector3(0f, -0.06f, 0f);

		public float clavScaleFactor = 0.749f;

		public float handsScaleFactor = 0.9f;

		public bool isInRun;

		public GameObject youmuGhost;

		private Transform head;

		private Transform neck;

		private Transform leftClav;

		private Transform rightClav;

		private Transform leftHand;

		private Transform rightHand;

		private Transform swordBase;

		public static void Init()
		{
			SubscribeEvents();
		}

		private static void SubscribeEvents()
		{
			MwSkinEvents.SkinAppliedRun += AddTransformControllerRun;
			MwSkinEvents.SkinAppliedLobby += AddTransformControllerLobby;
			MwSkinEvents.Death += SetIsDead;
			MwSkinEvents.DifferentSkinApplied += RemoveTransformController;
			MwSkinEvents.SkinAppliedRun += AddGhost;
			MwSkinEvents.SkinAppliedLobby += AddGhost;
			MwSkinEvents.DifferentSkinApplied += RemoveGhost;
		}

		private static void AddGhost(GameObject body)
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(Assets.mainAssetBundle.LoadAsset<GameObject>("YoumuGhostTarget"));
			MwTransformController component = body.GetComponent<MwTransformController>();
			if (component.isInRun)
			{
				val.transform.parent = ((Component)((Component)body.GetComponent<ModelLocator>().modelTransform).GetComponent<ChildLocator>().FindChild("Base")).transform;
			}
			else
			{
				val.transform.parent = body.transform.Find("MercArmature/ROOT/base");
			}
			val.transform.localPosition = new Vector3(0.8f, 0f, -0.8f);
			val.transform.localEulerAngles = new Vector3(0f, 180f, 90f);
			component.youmuGhost = val;
		}

		private static void RemoveGhost(GameObject body)
		{
			MwTransformController component = body.GetComponent<MwTransformController>();
			if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.youmuGhost))
			{
				Object.Destroy((Object)(object)component.youmuGhost.GetComponent<ItemFollower>()?.followerInstance);
				Object.Destroy((Object)(object)component.youmuGhost);
			}
		}

		private static void AddTransformControllerRun(GameObject body)
		{
			body.AddComponent<MwTransformController>().isInRun = true;
		}

		private static void RemoveTransformController(GameObject body)
		{
			MwTransformController mwTransformController = ((body != null) ? body.GetComponent<MwTransformController>() : null);
			if ((Object)(object)mwTransformController != (Object)null)
			{
				Object.Destroy((Object)(object)mwTransformController);
			}
		}

		private static void AddTransformControllerLobby(GameObject body)
		{
			MwTransformController mwTransformController = body.GetComponent<MwTransformController>();
			if ((Object)(object)mwTransformController == (Object)null)
			{
				mwTransformController = body.AddComponent<MwTransformController>();
			}
			mwTransformController.isInRun = false;
			((Component)(body.transform.Find("MercArmature/ROOT/base/stomach/chest/Point Light (1)") ?? body.transform.Find("MercArmature/ROOT/base/stomach/chest/Point Light"))).gameObject.SetActive(false);
			((Component)(body.transform.Find("MercArmature/ROOT/base/stomach/chest/SwingCenter/SwordBase/Point Light (1)") ?? body.transform.Find("MercArmature/ROOT/base/stomach/chest/SwingCenter/SwordBase/Point Light"))).gameObject.SetActive(false);
		}

		private void Start()
		{
			if (isInRun)
			{
				AssignLimbsRun();
			}
			else
			{
				AssignLimbsLobby();
			}
		}

		private void AssignLimbsRun()
		{
			head = ((Component)((Component)((Component)this).GetComponent<ModelLocator>().modelTransform).GetComponent<ChildLocator>().FindChild("Head")).transform;
			neck = ((Component)((Component)((Component)this).GetComponent<ModelLocator>().modelTransform).GetComponent<ChildLocator>().FindChild("Neck")).transform;
			leftClav = ((Component)((Component)((Component)this).GetComponent<ModelLocator>().modelTransform).GetComponent<ChildLocator>().FindChild("UpperArmL")).transform;
			rightClav = ((Component)((Component)((Component)this).GetComponent<ModelLocator>().modelTransform).GetComponent<ChildLocator>().FindChild("UpperArmR")).transform;
			leftHand = ((Component)((Component)((Component)this).GetComponent<ModelLocator>().modelTransform).GetComponent<ChildLocator>().FindChild("HandL")).transform;
			rightHand = ((Component)((Component)((Component)this).GetComponent<ModelLocator>().modelTransform).GetComponent<ChildLocator>().FindChild("HandR")).transform;
			swordBase = ((Component)((Component)((Component)this).GetComponent<ModelLocator>().modelTransform).GetComponent<ChildLocator>().FindChild("SwordBase")).transform;
		}

		private void AssignLimbsLobby()
		{
			head = ((Component)this).transform.Find("MercArmature/ROOT/base/stomach/chest/neck/head");
			neck = ((Component)this).transform.Find("MercArmature/ROOT/base/stomach/chest/neck");
			leftClav = ((Component)this).transform.Find("MercArmature/ROOT/base/stomach/chest/clavicle.l");
			rightClav = ((Component)this).transform.Find("MercArmature/ROOT/base/stomach/chest/clavicle.r");
			leftHand = ((Component)this).transform.Find("MercArmature/ROOT/base/stomach/chest/clavicle.l/upper_arm.l/lower_arm.l/hand.l");
			rightHand = ((Component)this).transform.Find("MercArmature/ROOT/base/stomach/chest/clavicle.r/upper_arm.r/lower_arm.r/hand.r");
			swordBase = ((Component)this).transform.Find("MercArmature/ROOT/base/stomach/chest/SwingCenter/SwordBase");
		}

		private void LateUpdate()
		{
			ApplyScale();
			ApplyPosition();
		}

		private void ApplyScale()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: 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)
			leftClav.localScale = Vector3.one * clavScaleFactor;
			rightClav.localScale = Vector3.one * clavScaleFactor;
			leftHand.localScale = Vector3.one * handsScaleFactor;
			rightHand.localScale = Vector3.one * handsScaleFactor;
		}

		private void ApplyPosition()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: 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_009e: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: 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_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: 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)
			head.localPosition = new Vector3(1.06229E-09f, 0.1344895f, 1.109584E-08f);
			neck.localPosition = new Vector3(-0.0003988522f, 0.242322f, -2.050125E-06f);
			if (isInRun)
			{
				Transform obj = leftClav;
				obj.localPosition += Vector3.right * clavOffset.x + Vector3.forward * clavOffset.z + Vector3.down * clavOffset.y;
				Transform obj2 = rightClav;
				obj2.localPosition += Vector3.left * clavOffset.x + Vector3.forward * clavOffset.z + Vector3.down * clavOffset.y;
			}
			if (isInRun)
			{
				swordBase.position = leftHand.position + swordOffset;
			}
			else
			{
				swordBase.position = leftHand.position + swordOffset + Vector3.back * 0.05f;
			}
		}

		private static void SetIsDead(GameObject body)
		{
			MwTransformController mwTransformController = ((body != null) ? body.GetComponent<MwTransformController>() : null);
			if ((Object)(object)mwTransformController != (Object)null)
			{
				((Behaviour)mwTransformController).enabled = false;
			}
		}
	}
}
namespace RuneFoxMods
{
	internal class Utils
	{
		public static void PrintBodyCatalog()
		{
			Debug.Log((object)"\nBodyCatalog");
			foreach (GameObject allBodyPrefab in BodyCatalog.allBodyPrefabs)
			{
				Debug.Log((object)((Object)allBodyPrefab).name);
			}
			Debug.Log((object)"\n");
		}

		public static void ReadChildren(GameObject parent, int tabs, bool includecomponents = true)
		{
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			string text = "";
			for (int i = 0; i < tabs; i++)
			{
				text += "  ";
			}
			for (int j = 0; j < parent.transform.childCount; j++)
			{
				Transform child = parent.transform.GetChild(j);
				if ((Object)(object)child == (Object)null)
				{
					break;
				}
				string text2 = ((Component)child).gameObject.activeInHierarchy.ToString();
				string[] obj = new string[6]
				{
					text,
					((Object)child).name,
					" ",
					text2,
					" ",
					null
				};
				Vector3 position = ((Component)child).transform.position;
				obj[5] = ((object)(Vector3)(ref position)).ToString();
				Debug.Log((object)string.Concat(obj));
				if (includecomponents)
				{
					ReadComponents(((Component)child).gameObject, tabs + 1);
					Debug.Log((object)"");
				}
				ReadChildren(((Component)child).gameObject, tabs + 1, includecomponents);
			}
		}

		public static void readheiarchy(GameObject parent, bool includeComponents = true)
		{
			Debug.Log((object)((Object)parent).name);
			if (includeComponents)
			{
				ReadComponents(parent, 1);
				Debug.Log((object)"");
			}
			ReadChildren(parent, 1, includeComponents);
		}

		public static void ReadComponents(GameObject obj, int tabs)
		{
			string text = "";
			for (int i = 0; i < tabs; i++)
			{
				text += "  ";
			}
			Component[] components = obj.GetComponents(typeof(Component));
			foreach (Component val in components)
			{
				string text2 = "";
				Debug.Log((object)(text + "Comp: " + ((object)val).GetType().ToString() + "  " + text2));
			}
		}

		public static void PrintAllPaths(GameObject parent)
		{
			Debug.Log((object)((Object)parent).name);
			PrintAllPathsInner(parent, ((Object)parent).name);
		}

		private static void PrintAllPathsInner(GameObject parent, string parent_string)
		{
			int childCount = parent.transform.childCount;
			for (int i = 0; i < childCount; i++)
			{
				Transform child = parent.transform.GetChild(i);
				if (!((Object)child).name.EndsWith("_end"))
				{
					string text = parent_string + "/" + ((Object)child).name;
					Debug.Log((object)("  " + ((Object)child).name + "\t\t" + text));
					PrintAllPathsInner(((Component)child).gameObject, text);
					continue;
				}
				break;
			}
		}

		public static void PrintDynamicBone(DynamicBone DB)
		{
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			Debug.Log((object)("Root: " + (object)DB.m_Root));
			Debug.Log((object)("Damping: " + DB.m_Damping));
			Debug.Log((object)("Damping Dist: " + (object)DB.m_DampingDistrib));
			Debug.Log((object)("Elasticity: " + DB.m_Elasticity));
			Debug.Log((object)("Elasticity Dist: " + (object)DB.m_ElasticityDistrib));
			Debug.Log((object)("Stiffness: " + DB.m_Stiffness));
			Debug.Log((object)("Stiffness Dist: " + (object)DB.m_StiffnessDistrib));
			Debug.Log((object)("Inert: " + DB.m_Inert));
			Debug.Log((object)("Inert Dist: " + (object)DB.m_InertDistrib));
			Debug.Log((object)("Radius: " + DB.m_Radius));
			Debug.Log((object)("Radius Dist: " + (object)DB.m_RadiusDistrib));
			Debug.Log((object)("End Length: " + DB.m_EndLength));
			Vector3 val = DB.m_EndOffset;
			Debug.Log((object)("End Offset: " + ((object)(Vector3)(ref val)).ToString()));
			val = DB.m_Gravity;
			Debug.Log((object)("Gravity: " + ((object)(Vector3)(ref val)).ToString()));
			val = DB.m_Force;
			Debug.Log((object)("Force: " + ((object)(Vector3)(ref val)).ToString()));
			Debug.Log((object)("FreezeAxis: " + ((object)(FreezeAxis)(ref DB.m_FreezeAxis)).ToString()));
			Debug.Log((object)("Colliders: " + DB.m_Colliders.Count));
			foreach (DynamicBoneCollider collider in DB.m_Colliders)
			{
				Debug.Log((object)("\t Parent: " + ((Object)((Component)collider).transform).name));
				Debug.Log((object)("\t Direction: " + ((object)(Direction)(ref collider.m_Direction)).ToString()));
				val = collider.m_Center;
				Debug.Log((object)("\t Center " + ((object)(Vector3)(ref val)).ToString()));
				Debug.Log((object)("\t Bound " + ((object)(Bound)(ref collider.m_Bound)).ToString()));
				Debug.Log((object)("\t Radius " + collider.m_Radius));
				Debug.Log((object)("\t Height " + collider.m_Height));
			}
			Debug.Log((object)("Exclusions: " + DB.m_Exclusions.Count));
			foreach (Transform exclusion in DB.m_Exclusions)
			{
				Debug.Log((object)("\t Transform: " + ((Object)exclusion).name));
			}
		}

		public static ChildLocator GetChildLocator(GameObject body)
		{
			ChildLocator val = null;
			Transform child = body.transform.GetChild(0);
			if (Object.op_Implicit((Object)(object)child))
			{
				Transform child2 = child.GetChild(0);
				if (Object.op_Implicit((Object)(object)child2))
				{
					val = ((Component)child2).GetComponent<ChildLocator>();
					if (Object.op_Implicit((Object)(object)val))
					{
						Debug.Log((object)"Locator Found");
					}
				}
			}
			return val;
		}

		public static Transform FindChildInTree(Transform Root, string name)
		{
			Queue<Transform> queue = new Queue<Transform>();
			queue.Enqueue(Root);
			while (queue.Count != 0)
			{
				Transform val = queue.Dequeue();
				if (((Object)val).name == name)
				{
					return val;
				}
				for (int i = 0; i < val.childCount; i++)
				{
					Transform child = val.GetChild(i);
					queue.Enqueue(child);
				}
			}
			return null;
		}

		public static string RemoveCloneNaming(string str)
		{
			return str.Remove(str.Length - 7);
		}
	}
}
namespace RuneFoxMods.DynamicSkins
{
	public static class DynamicSkinHelpers
	{
		public static SkinnedMeshRenderer[] GetBaseSkinRenderers(GameObject modelObject)
		{
			SkinnedMeshRenderer[] componentsInChildren = modelObject.GetComponentsInChildren<SkinnedMeshRenderer>(true);
			List<SkinnedMeshRenderer> list = new List<SkinnedMeshRenderer>();
			SkinnedMeshRenderer[] array = componentsInChildren;
			foreach (SkinnedMeshRenderer val in array)
			{
				if ((Object)(object)((Component)val).transform.parent == (Object)(object)modelObject.transform)
				{
					list.Add(val);
				}
			}
			return list.ToArray();
		}

		public static Transform[] BoneArrayBuilder(Transform NewBoneRoot)
		{
			List<Transform> list = new List<Transform>();
			BoneArrayBuilderHelper(NewBoneRoot, list);
			return list.ToArray();
		}

		public static void BoneArrayBuilderHelper(Transform parent, List<Transform> list)
		{
			if (!((Object)parent).name.EndsWith("_end"))
			{
				list.Add(parent);
			}
			for (int i = 0; i < parent.childCount; i++)
			{
				BoneArrayBuilderHelper(parent.GetChild(i), list);
			}
		}

		public static Transform GetArmature(GameObject obj)
		{
			return GetArmatureHelper(obj);
		}

		public static Transform GetArmatureHelper(GameObject obj)
		{
			if (((Object)obj).name.ToLower().Contains("armature"))
			{
				return obj.transform;
			}
			for (int i = 0; i < obj.transform.childCount; i++)
			{
				Transform armatureHelper = GetArmatureHelper(((Component)obj.transform.GetChild(i)).gameObject);
				if (Object.op_Implicit((Object)(object)armatureHelper))
				{
					return armatureHelper;
				}
			}
			return null;
		}

		public static Transform GetTopParent(Transform obj)
		{
			Transform val = obj;
			while ((Object)(object)val.parent != (Object)null)
			{
				val = val.parent;
			}
			return val;
		}

		public static string GetPrevBoneInList(Transform targetBone, SkinnedMeshRenderer meshRenderer)
		{
			Transform[] bones = meshRenderer.bones;
			for (int i = 0; i <= bones.Length - 1; i++)
			{
				if (((Object)bones[i + 1]).name == ((Object)targetBone).name)
				{
					return ((Object)bones[i]).name;
				}
			}
			return null;
		}

		public static int GetBoneIndexInList(Transform targetBone, SkinnedMeshRenderer meshRenderer)
		{
			Transform[] bones = meshRenderer.bones;
			for (int i = 0; i <= bones.Length; i++)
			{
				if (((Object)bones[i]).name == ((Object)targetBone).name)
				{
					return i;
				}
			}
			return -1;
		}

		public static int GetPrevBoneIndexInList(Transform targetBone, SkinnedMeshRenderer meshRenderer)
		{
			Transform[] bones = meshRenderer.bones;
			for (int i = 0; i <= bones.Length - 1; i++)
			{
				if (((Object)bones[i + 1]).name == ((Object)targetBone).name)
				{
					return i;
				}
			}
			return -1;
		}
	}
	internal class DynamicSkinManager
	{
		internal Dictionary<string, SkinDef> SkinDefs = new Dictionary<string, SkinDef>();

		private GameObject LastModelObject;

		internal Dictionary<string, SortedList<int, Modification>> ModificationList = new Dictionary<string, SortedList<int, Modification>>();

		private Dictionary<GameObject, AppliedModifications> ModifiedObjects = new Dictionary<GameObject, AppliedModifications>();

		internal ManualLogSource InstanceLogger;

		internal void AddModification(string skinNameToken, int boneIndex, Modification modification)
		{
			if (!ModificationList.TryGetValue(skinNameToken, out var value))
			{
				value = new SortedList<int, Modification>();
				ModificationList.Add(skinNameToken, value);
			}
			value.Add(boneIndex, modification);
		}

		internal void AddSkinDef(SkinDef skinDef)
		{
			SkinDefs.Add(skinDef.nameToken, skinDef);
		}

		internal IEnumerator SkinDefApply(Func<SkinDef, GameObject, List<AssetReferenceT<Material>>, List<AssetReferenceT<Mesh>>, int, IEnumerator> orig, SkinDef self, GameObject modelObject, List<AssetReferenceT<Material>> loadedMaterials, List<AssetReferenceT<Mesh>> loadedMeshes, int unloadType)
		{
			IEnumerator result = orig(self, modelObject, loadedMaterials, loadedMeshes, unloadType);
			RemoveInvalidModelObjects();
			ModifiedObjects.TryGetValue(modelObject, out var value);
			try
			{
				if (!SkinDefs.TryGetValue(self.nameToken, out var _))
				{
					if (value != null)
					{
						ClearSkinModifications(LastModelObject, value);
					}
					return result;
				}
				if (value == null)
				{
					AppliedModifications appliedModifications = new AppliedModifications();
					ModifiedObjects.Add(modelObject, appliedModifications);
					ApplySkinModifications(self, modelObject, appliedModifications);
				}
			}
			catch (Exception ex)
			{
				InstanceLogger.LogWarning((object)"An error occured while adding accessories to a skin");
				InstanceLogger.LogError((object)ex);
			}
			return result;
		}

		private void RemoveInvalidModelObjects()
		{
			foreach (GameObject item in ModifiedObjects.Keys.Where((GameObject el) => !Object.op_Implicit((Object)(object)el)).ToList())
			{
				ModifiedObjects.Remove(item);
			}
		}

		private void ClearSkinModifications(GameObject modelObject, AppliedModifications modifications)
		{
			while (modifications.BaseModelModifications.Count != 0)
			{
				Modification modification = modifications.BaseModelModifications.Pop();
				clearModification(modification, modelObject, modifications);
			}
			while (modifications.OtherModifications.Count != 0)
			{
				clearModification(modifications.OtherModifications[0], modelObject, modifications);
			}
			ModifiedObjects.Remove(modelObject);
		}

		private void ApplySkinModifications(SkinDef skindef, GameObject modelObject, AppliedModifications modifications)
		{
			CharacterModel component = modelObject.GetComponent<CharacterModel>();
			LastModelObject = modelObject;
			if (!ModificationList.TryGetValue(skindef.nameToken, out var value))
			{
				return;
			}
			foreach (KeyValuePair<int, Modification> item in value)
			{
				ApplyModification(modelObject, component, item.Value, modifications);
			}
		}

		private static void ApplyModification(GameObject modelObject, CharacterModel characterModel, Modification modification, AppliedModifications modifications)
		{
			_ = modification.bodyname;
			string parentname = modification.parentname;
			Transform val = Utils.FindChildInTree(modelObject.transform, parentname);
			GameObject val2;
			if (modification.affectsbasemodel)
			{
				val2 = Object.Instantiate<GameObject>(modification.prefab, val, false);
				((Object)val2).name = Utils.RemoveCloneNaming(((Object)val2).name);
				modification.instance = val2;
				modification.inst_armature = val2;
				ModificationApplyBones(modelObject, modification, modifications);
			}
			else
			{
				val2 = Object.Instantiate<GameObject>(modification.prefab, modelObject.transform, false);
				((Object)val2).name = Utils.RemoveCloneNaming(((Object)val2).name);
				modification.instance = val2;
				Transform armature = DynamicSkinHelpers.GetArmature(val2);
				((Component)armature).transform.SetParent(val, false);
				modification.inst_armature = ((Component)armature).gameObject;
			}
			modification.instance = val2;
			if (modification.dynamicBoneData != null)
			{
				ModificationApplyDynamicBones(modelObject, modification);
			}
			ModificationAddRenderers(val2, characterModel);
			modifications.OtherModifications.Add(modification);
		}

		private static void ModificationApplyBones(GameObject modelObject, Modification modification, AppliedModifications modifications)
		{
			SkinnedMeshRenderer[] baseSkinRenderers = DynamicSkinHelpers.GetBaseSkinRenderers(modelObject);
			List<Transform> list = baseSkinRenderers[0].bones.ToList();
			Transform[] array = DynamicSkinHelpers.BoneArrayBuilder(modification.instance.transform);
			list.InsertRange(modification.boneIndex, array);
			modification.boneCount = array.Length;
			SkinnedMeshRenderer[] array2 = baseSkinRenderers;
			for (int i = 0; i < array2.Length; i++)
			{
				array2[i].bones = list.ToArray();
			}
			modifications.BaseModelModifications.Push(modification);
		}

		private static void ModificationApplyDynamicBones(GameObject modelObject, Modification modification)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			DynamicBone val = (modification.inst_dynamicBone = modification.instance.AddComponent<DynamicBone>());
			List<DynamicBoneCollider> list = new List<DynamicBoneCollider>();
			foreach (DynamicBoneColliderData collider in modification.dynamicBoneData.m_Colliders)
			{
				DynamicBoneCollider val2 = ((Component)Utils.FindChildInTree(modelObject.transform, collider.m_parent_name)).gameObject.AddComponent<DynamicBoneCollider>();
				val2.m_Direction = collider.m_Direction;
				val2.m_Center = collider.m_Center;
				val2.m_Bound = collider.m_Bound;
				val2.m_Radius = collider.m_Radius;
				val2.m_Height = collider.m_Height;
				list.Add(val2);
			}
			modification.inst_DB_colliders = list;
			Transform root = (val.m_Root = Utils.FindChildInTree(modification.inst_armature.transform, modification.dynamicBoneData.m_Root));
			val.m_Damping = modification.dynamicBoneData.m_Damping;
			val.m_DampingDistrib = modification.dynamicBoneData.m_DampingDistrib;
			val.m_Elasticity = modification.dynamicBoneData.m_Elasticity;
			val.m_ElasticityDistrib = modification.dynamicBoneData.m_ElasticityDistrib;
			val.m_Stiffness = modification.dynamicBoneData.m_Stiffness;
			val.m_StiffnessDistrib = modification.dynamicBoneData.m_StiffnessDistrib;
			val.m_Inert = modification.dynamicBoneData.m_Inert;
			val.m_InertDistrib = modification.dynamicBoneData.m_InertDistrib;
			val.m_Radius = modification.dynamicBoneData.m_Radius;
			val.m_RadiusDistrib = modification.dynamicBoneData.m_RadiusDistrib;
			val.m_EndLength = modification.dynamicBoneData.m_EndLength;
			val.m_EndOffset = modification.dynamicBoneData.m_EndOffset;
			val.m_Gravity = modification.dynamicBoneData.m_Gravity;
			val.m_Force = modification.dynamicBoneData.m_Force;
			val.m_Colliders = list;
			val.m_Exclusions = new List<Transform>();
			foreach (string exclusion in modification.dynamicBoneData.m_Exclusions)
			{
				Transform val3 = Utils.FindChildInTree(root, exclusion);
				if ((Object)(object)val3 != (Object)null)
				{
					val.m_Exclusions.Add(val3);
				}
				else
				{
					Debug.LogWarning((object)"Tried to exclude a transform that could not be found");
				}
			}
			val.m_FreezeAxis = modification.dynamicBoneData.m_FreezeAxis;
		}

		private static void ModificationAddRenderers(GameObject newPart, CharacterModel characterModel)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: 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)
			SkinnedMeshRenderer[] componentsInChildren = newPart.GetComponentsInChildren<SkinnedMeshRenderer>(true);
			Array.Resize(ref characterModel.baseRendererInfos, characterModel.baseRendererInfos.Length + componentsInChildren.Length);
			if (componentsInChildren.Length != 0)
			{
				int num = componentsInChildren.Length;
				SkinnedMeshRenderer[] array = componentsInChildren;
				foreach (SkinnedMeshRenderer val in array)
				{
					characterModel.baseRendererInfos[characterModel.baseRendererInfos.Length - num] = new RendererInfo
					{
						renderer = (Renderer)(object)componentsInChildren[^num],
						ignoreOverlays = false,
						defaultShadowCastingMode = (ShadowCastingMode)1,
						defaultMaterial = ((Renderer)val).sharedMaterial
					};
					num--;
				}
			}
		}

		private void clearModification(Modification modification, GameObject modelObject, AppliedModifications modifications)
		{
			if (modification.inst_DB_colliders != null)
			{
				foreach (DynamicBoneCollider inst_DB_collider in modification.inst_DB_colliders)
				{
					Object.Destroy((Object)(object)inst_DB_collider);
				}
			}
			if (modification.affectsbasemodel)
			{
				SkinnedMeshRenderer[] baseSkinRenderers = DynamicSkinHelpers.GetBaseSkinRenderers(modelObject);
				List<Transform> list = baseSkinRenderers[0].bones.ToList();
				list.RemoveRange(modification.boneIndex, modification.boneCount);
				SkinnedMeshRenderer[] array = baseSkinRenderers;
				for (int i = 0; i < array.Length; i++)
				{
					array[i].bones = list.ToArray();
				}
			}
			Object.Destroy((Object)(object)modifications.OtherModifications[0].inst_dynamicBone);
			Object.Destroy((Object)(object)modifications.OtherModifications[0].inst_armature);
			Object.Destroy((Object)(object)modifications.OtherModifications[0].instance);
			if (!modifications.OtherModifications.Remove(modification))
			{
				InstanceLogger.LogError((object)"Skin Modification was not removed");
			}
		}
	}
	internal class Modification
	{
		public string prefabpath;

		public string bodyname;

		public string parentname;

		public GameObject prefab;

		public bool affectsbasemodel;

		public DynamicBoneData dynamicBoneData;

		public string parentSkinToken;

		public int boneIndex;

		public int boneCount;

		public GameObject instance;

		public GameObject inst_armature;

		public DynamicBone inst_dynamicBone;

		public List<DynamicBoneCollider> inst_DB_colliders = new List<DynamicBoneCollider>();

		public Modification(string PrefabPath, string ParentName, string BodyName, string ParentSkinToken, int BoneIndex, bool AffectsBaseModel, AssetBundle assetBundle)
		{
			bodyname = BodyName;
			prefabpath = PrefabPath;
			parentname = ParentName;
			parentSkinToken = ParentSkinToken;
			affectsbasemodel = AffectsBaseModel;
			boneIndex = BoneIndex;
			prefab = assetBundle.LoadAsset<GameObject>(prefabpath);
			if ((Object)(object)prefab == (Object)null)
			{
				Debug.LogWarning((object)("Asset at " + PrefabPath + " was not loaded"));
			}
		}
	}
	internal class AppliedModifications
	{
		public Stack<Modification> BaseModelModifications = new Stack<Modification>();

		public List<Modification> OtherModifications = new List<Modification>();
	}
	internal class DynamicBoneData
	{
		public string m_Root;

		public float m_Damping;

		public AnimationCurve m_DampingDistrib;

		public float m_Elasticity;

		public AnimationCurve m_ElasticityDistrib;

		public float m_Stiffness;

		public AnimationCurve m_StiffnessDistrib;

		public float m_Inert;

		public AnimationCurve m_InertDistrib;

		public float m_Radius;

		public AnimationCurve m_RadiusDistrib;

		public float m_EndLength;

		public Vector3 m_EndOffset;

		public Vector3 m_Gravity;

		public Vector3 m_Force;

		public List<DynamicBoneColliderData> m_Colliders;

		public List<string> m_Exclusions;

		public FreezeAxis m_FreezeAxis;

		public DynamicBoneData(string root, float damping, AnimationCurve damping_dist, float elasticity, AnimationCurve elasticity_dist, float stiffness, AnimationCurve stiffness_dist, float inert, AnimationCurve inert_dist, float radius, AnimationCurve radius_dist, float end_length, Vector3 end_offset, Vector3 gravity, Vector3 force, List<DynamicBoneColliderData> colliders, List<string> exclusions, FreezeAxis freeze_axis)
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: 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)
			m_Root = root;
			m_Damping = damping;
			m_DampingDistrib = damping_dist;
			m_Elasticity = elasticity;
			m_ElasticityDistrib = elasticity_dist;
			m_Stiffness = stiffness;
			m_StiffnessDistrib = stiffness_dist;
			m_Inert = inert;
			m_InertDistrib = inert_dist;
			m_Radius = radius;
			m_RadiusDistrib = radius_dist;
			m_EndLength = end_length;
			m_EndOffset = end_offset;
			m_Gravity = gravity;
			m_Force = force;
			m_Colliders = colliders;
			m_Exclusions = exclusions;
			m_FreezeAxis = freeze_axis;
		}
	}
	internal class DynamicBoneColliderData
	{
		public string m_parent_name;

		public Direction m_Direction;

		public Vector3 m_Center;

		public Bound m_Bound;

		public float m_Radius;

		public float m_Height;

		public DynamicBoneColliderData(string parent_name, Direction direction, Vector3 Center, Bound bound, float radius, float heaight)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: 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)
			m_parent_name = parent_name;
			m_Direction = direction;
			m_Center = Center;
			m_Bound = bound;
			m_Radius = radius;
			m_Height = heaight;
		}
	}
}