Decompiled source of Mercenary2B v1.3.1

plugins\Mercenary2B\Mercenary2B.dll

Decompiled 6 months 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.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using MonoMod.RuntimeDetour;
using MonoMod.RuntimeDetour.HookGen;
using RoR2;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace Mercenary2B;

[BepInPlugin("com.KingEnderBrine.Mercenary2B", "Mercenary2B", "1.3.1")]
public class Mercenary2BPlugin : BaseUnityPlugin
{
	private class FieldException : Exception
	{
		public FieldException(string message, Exception innerException)
			: base(message, innerException)
		{
		}
	}

	private static GameObject swordAccessoryPrefab;

	private static GameObject skirtPrefab;

	private static GameObject breastBonesPrefab;

	private static GameObject buttBonesPrefab;

	private const int breastBoneIndex = 64;

	private const int buttBoneIndex = 76;

	private static readonly ConditionalWeakTable<GameObject, ModificationObjects> appliedModificatons = new ConditionalWeakTable<GameObject, ModificationObjects>();

	private static ConfigEntry<bool> DisableSkirt;

	private static AssetBundle assetBundle;

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

	public static GameObject SwordAccessoryPrefab => Object.op_Implicit((Object)(object)swordAccessoryPrefab) ? swordAccessoryPrefab : (swordAccessoryPrefab = assetBundle.LoadAsset<GameObject>("Assets/Mercenary2B/Resources/Prefabs/SwordAccessoryPrefab.prefab"));

	public static GameObject SkirtPrefab => Object.op_Implicit((Object)(object)skirtPrefab) ? skirtPrefab : (skirtPrefab = assetBundle.LoadAsset<GameObject>("Assets/Mercenary2B/Resources/Prefabs/SkirtPrefab.prefab"));

	public static GameObject BreastBonesPrefab => Object.op_Implicit((Object)(object)breastBonesPrefab) ? breastBonesPrefab : (breastBonesPrefab = assetBundle.LoadAsset<GameObject>("Assets/Mercenary2B/Resources/Prefabs/breast_base.prefab"));

	public static GameObject ButtBonesPrefab => Object.op_Implicit((Object)(object)buttBonesPrefab) ? buttBonesPrefab : (buttBonesPrefab = assetBundle.LoadAsset<GameObject>("Assets/Mercenary2B/Resources/Prefabs/butt_base.prefab"));

	public static SkinDef SkinDef { get; private set; }

	internal static Mercenary2BPlugin Instance { get; private set; }

	internal static ManualLogSource InstanceLogger
	{
		get
		{
			Mercenary2BPlugin instance = Instance;
			return (instance != null) ? ((BaseUnityPlugin)instance).Logger : null;
		}
	}

	private static void SkinDefApply(Action<SkinDef, GameObject> orig, SkinDef self, GameObject modelObject)
	{
		orig(self, modelObject);
		try
		{
			appliedModificatons.TryGetValue(modelObject, out var value);
			if ((Object)(object)self != (Object)(object)SkinDef)
			{
				if (value != null)
				{
					appliedModificatons.Remove(modelObject);
					ClearSkinModifications(value);
				}
			}
			else if (value == null)
			{
				appliedModificatons.Add(modelObject, ApplySkinModifications(modelObject));
			}
		}
		catch (Exception ex)
		{
			InstanceLogger.LogWarning((object)"An error occured while adding accessories to a Mercenary2B skin");
			InstanceLogger.LogError((object)ex);
		}
	}

	private static void ClearSkinModifications(ModificationObjects modifications)
	{
		Object.Destroy((Object)(object)modifications.swordAccessoryInstance);
		Object.Destroy((Object)(object)modifications.swordAccessoryArmature);
		Object.Destroy((Object)(object)modifications.swordAccessoryDynamicBone);
		if (!DisableSkirt.Value)
		{
			Object.Destroy((Object)(object)modifications.skirtInstance);
			Object.Destroy((Object)(object)modifications.skirtArmature);
			Object.Destroy((Object)(object)modifications.skirtDynamicBone);
		}
		Object.Destroy((Object)(object)modifications.pelvisDynamicBoneCollider);
		Object.Destroy((Object)(object)modifications.thighL1DynamicBoneCollider);
		Object.Destroy((Object)(object)modifications.thighL2DynamicBoneCollider);
		Object.Destroy((Object)(object)modifications.thighR1DynamicBoneCollider);
		Object.Destroy((Object)(object)modifications.thighR2DynamicBoneCollider);
		Object.Destroy((Object)(object)modifications.stomachDynamicBoneCollider);
		List<Transform> list = modifications.mercMeshRenderer.bones.ToList();
		list.RemoveRange(76, 3);
		list.RemoveRange(64, 3);
		modifications.mercMeshRenderer.bones = list.ToArray();
		modifications.swordMeshRenderer.bones = list.ToArray();
		Object.Destroy((Object)(object)modifications.mercBreastDynamicBone);
		Object.Destroy((Object)(object)modifications.breastBonesInstance);
		Object.Destroy((Object)(object)modifications.mercButtDynamicBone);
		Object.Destroy((Object)(object)modifications.buttBonesInstance);
		if (Object.op_Implicit((Object)(object)modifications.chestPointLight))
		{
			modifications.chestPointLight.SetActive(true);
		}
		if (Object.op_Implicit((Object)(object)modifications.swordPointLight))
		{
			modifications.swordPointLight.SetActive(true);
		}
	}

	private static ModificationObjects ApplySkinModifications(GameObject modelObject)
	{
		CharacterModel component = modelObject.GetComponent<CharacterModel>();
		ModificationObjects modificationObjects = new ModificationObjects
		{
			mercMeshRenderer = ((Component)modelObject.transform.Find("MercMesh")).GetComponent<SkinnedMeshRenderer>(),
			swordMeshRenderer = ((Component)modelObject.transform.Find("MercSwordMesh")).GetComponent<SkinnedMeshRenderer>()
		};
		ApplyBreastModifications(modelObject, modificationObjects);
		ApplyButtModifications(modelObject, modificationObjects);
		ApplySwordAccessoriesModifications(modelObject, modificationObjects, component);
		if (!DisableSkirt.Value)
		{
			ApplySkirtModifications(modelObject, modificationObjects, component);
		}
		return modificationObjects;
	}

	private static void ApplyBreastModifications(GameObject modelObject, ModificationObjects modifications)
	{
		Transform val = modelObject.transform.Find("MercArmature/ROOT/base/stomach/chest");
		Transform obj = val.Find("Point Light (1)") ?? val.Find("Point Light");
		modifications.chestPointLight = ((obj != null) ? ((Component)obj).gameObject : null);
		if (Object.op_Implicit((Object)(object)modifications.chestPointLight))
		{
			modifications.chestPointLight.SetActive(false);
		}
		modifications.breastBonesInstance = Object.Instantiate<GameObject>(BreastBonesPrefab, val, false);
		List<Transform> list = modifications.mercMeshRenderer.bones.ToList();
		list.InsertRange(64, (IEnumerable<Transform>)(object)new Transform[3]
		{
			modifications.breastBonesInstance.transform,
			modifications.breastBonesInstance.transform.GetChild(0),
			modifications.breastBonesInstance.transform.GetChild(1)
		});
		modifications.mercMeshRenderer.bones = list.ToArray();
		modifications.swordMeshRenderer.bones = list.ToArray();
		modifications.mercBreastDynamicBone = modelObject.AddComponent<DynamicBone>();
		modifications.mercBreastDynamicBone.m_Root = modifications.breastBonesInstance.transform;
		modifications.mercBreastDynamicBone.m_Damping = 0.2f;
		modifications.mercBreastDynamicBone.m_Elasticity = 0.05f;
		modifications.mercBreastDynamicBone.m_Stiffness = 0.8f;
		modifications.mercBreastDynamicBone.m_Inert = 0.5f;
	}

	private static void ApplyButtModifications(GameObject modelObject, ModificationObjects modifications)
	{
		Transform val = modelObject.transform.Find("MercArmature/ROOT/base/pelvis");
		modifications.buttBonesInstance = Object.Instantiate<GameObject>(ButtBonesPrefab, val, false);
		List<Transform> list = modifications.mercMeshRenderer.bones.ToList();
		list.InsertRange(76, (IEnumerable<Transform>)(object)new Transform[3]
		{
			modifications.buttBonesInstance.transform,
			modifications.buttBonesInstance.transform.GetChild(0),
			modifications.buttBonesInstance.transform.GetChild(1)
		});
		modifications.mercMeshRenderer.bones = list.ToArray();
		modifications.swordMeshRenderer.bones = list.ToArray();
		modifications.mercButtDynamicBone = modelObject.AddComponent<DynamicBone>();
		modifications.mercButtDynamicBone.m_Root = modifications.buttBonesInstance.transform;
		modifications.mercButtDynamicBone.m_Damping = 0.2f;
		modifications.mercButtDynamicBone.m_Elasticity = 0.05f;
		modifications.mercButtDynamicBone.m_Stiffness = 0.925f;
		modifications.mercButtDynamicBone.m_Inert = 0.5f;
	}

	private static void ApplySkirtModifications(GameObject modelObject, ModificationObjects modifications, CharacterModel characterModel)
	{
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: Unknown result type (might be due to invalid IL or missing references)
		//IL_0190: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0204: Unknown result type (might be due to invalid IL or missing references)
		//IL_023b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0240: Unknown result type (might be due to invalid IL or missing references)
		//IL_026c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0278: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_03db: Expected O, but got Unknown
		//IL_047d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0497: Unknown result type (might be due to invalid IL or missing references)
		//IL_04aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ac: Unknown result type (might be due to invalid IL or missing references)
		Transform val = modelObject.transform.Find("MercArmature/ROOT/base/stomach");
		modifications.skirtInstance = Object.Instantiate<GameObject>(SkirtPrefab, modelObject.transform, false);
		modifications.skirtArmature = ((Component)modifications.skirtInstance.transform.Find("SkirtArmature")).gameObject;
		modifications.skirtArmature.transform.SetParent(val, false);
		modifications.stomachDynamicBoneCollider = ((Component)val).gameObject.AddComponent<DynamicBoneCollider>();
		modifications.stomachDynamicBoneCollider.m_Center = new Vector3(0f, 0.7f, 0f);
		modifications.stomachDynamicBoneCollider.m_Height = 0.6f;
		modifications.stomachDynamicBoneCollider.m_Direction = (Direction)0;
		modifications.stomachDynamicBoneCollider.m_Bound = (Bound)0;
		Transform val2 = modelObject.transform.Find("MercArmature/ROOT/base/pelvis");
		modifications.pelvisDynamicBoneCollider = ((Component)val2).gameObject.AddComponent<DynamicBoneCollider>();
		modifications.pelvisDynamicBoneCollider.m_Center = new Vector3(0f, 0.2f, -0.05f);
		modifications.pelvisDynamicBoneCollider.m_Height = 0.54f;
		modifications.pelvisDynamicBoneCollider.m_Radius = 0.25f;
		modifications.pelvisDynamicBoneCollider.m_Direction = (Direction)0;
		modifications.pelvisDynamicBoneCollider.m_Bound = (Bound)0;
		Transform val3 = val2.Find("thigh.l");
		modifications.thighL1DynamicBoneCollider = ((Component)val3).gameObject.AddComponent<DynamicBoneCollider>();
		modifications.thighL1DynamicBoneCollider.m_Center = new Vector3(-0.1f, 0.24f, 0.04f);
		modifications.thighL1DynamicBoneCollider.m_Height = 0.6f;
		modifications.thighL1DynamicBoneCollider.m_Radius = 0.1f;
		modifications.thighL1DynamicBoneCollider.m_Direction = (Direction)1;
		modifications.thighL1DynamicBoneCollider.m_Bound = (Bound)0;
		modifications.thighL2DynamicBoneCollider = ((Component)val3).gameObject.AddComponent<DynamicBoneCollider>();
		modifications.thighL2DynamicBoneCollider.m_Center = new Vector3(0.1f, 0.24f, 0.04f);
		modifications.thighL2DynamicBoneCollider.m_Height = 0.6f;
		modifications.thighL2DynamicBoneCollider.m_Radius = 0.1f;
		modifications.thighL2DynamicBoneCollider.m_Direction = (Direction)1;
		modifications.thighL2DynamicBoneCollider.m_Bound = (Bound)0;
		Transform val4 = val2.Find("thigh.r");
		modifications.thighR1DynamicBoneCollider = ((Component)val4).gameObject.AddComponent<DynamicBoneCollider>();
		modifications.thighR1DynamicBoneCollider.m_Center = new Vector3(-0.1f, 0.24f, 0.04f);
		modifications.thighR1DynamicBoneCollider.m_Height = 0.6f;
		modifications.thighR1DynamicBoneCollider.m_Radius = 0.1f;
		modifications.thighR1DynamicBoneCollider.m_Direction = (Direction)1;
		modifications.thighR1DynamicBoneCollider.m_Bound = (Bound)0;
		modifications.thighR2DynamicBoneCollider = ((Component)val4).gameObject.AddComponent<DynamicBoneCollider>();
		modifications.thighR2DynamicBoneCollider.m_Center = new Vector3(0.1f, 0.24f, 0.04f);
		modifications.thighR2DynamicBoneCollider.m_Height = 0.6f;
		modifications.thighR2DynamicBoneCollider.m_Radius = 0.1f;
		modifications.thighR2DynamicBoneCollider.m_Direction = (Direction)1;
		modifications.thighR2DynamicBoneCollider.m_Bound = (Bound)0;
		modifications.skirtDynamicBone = modelObject.AddComponent<DynamicBone>();
		modifications.skirtDynamicBone.m_Root = modifications.skirtArmature.transform.GetChild(0);
		modifications.skirtDynamicBone.m_Exclusions = new List<Transform> { modifications.skirtDynamicBone.m_Root.Find("skirt.base") };
		modifications.skirtDynamicBone.m_Damping = 0.5f;
		modifications.skirtDynamicBone.m_Elasticity = 0.25f;
		modifications.skirtDynamicBone.m_Stiffness = 0f;
		modifications.skirtDynamicBone.m_Inert = 0.75f;
		modifications.skirtDynamicBone.m_Radius = 0.15f;
		modifications.skirtDynamicBone.m_RadiusDistrib = new AnimationCurve((Keyframe[])(object)new Keyframe[2]
		{
			new Keyframe(0f, 0.6f),
			new Keyframe(1f, 1f)
		})
		{
			postWrapMode = (WrapMode)2,
			preWrapMode = (WrapMode)2
		};
		modifications.skirtDynamicBone.m_Colliders = new List<DynamicBoneCollider> { modifications.pelvisDynamicBoneCollider, modifications.thighL1DynamicBoneCollider, modifications.thighL2DynamicBoneCollider, modifications.thighR1DynamicBoneCollider, modifications.thighR2DynamicBoneCollider, modifications.stomachDynamicBoneCollider };
		Array.Resize(ref characterModel.baseRendererInfos, characterModel.baseRendererInfos.Length + 1);
		SkinnedMeshRenderer component = ((Component)modifications.skirtInstance.transform.Find("Skirt")).GetComponent<SkinnedMeshRenderer>();
		characterModel.baseRendererInfos[characterModel.baseRendererInfos.Length - 1] = new RendererInfo
		{
			renderer = (Renderer)(object)component,
			ignoreOverlays = false,
			defaultShadowCastingMode = (ShadowCastingMode)1,
			defaultMaterial = ((Renderer)component).sharedMaterial
		};
	}

	private static void ApplySwordAccessoriesModifications(GameObject modelObject, ModificationObjects modifications, CharacterModel characterModel)
	{
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		Transform val = modelObject.transform.Find("MercArmature/ROOT/base/stomach/chest/SwingCenter/SwordBase");
		Transform obj = val.Find("Point Light");
		modifications.swordPointLight = ((obj != null) ? ((Component)obj).gameObject : null);
		if (Object.op_Implicit((Object)(object)modifications.swordPointLight))
		{
			modifications.swordPointLight.SetActive(false);
		}
		modifications.swordAccessoryInstance = Object.Instantiate<GameObject>(SwordAccessoryPrefab, modelObject.transform, false);
		modifications.swordAccessoryArmature = ((Component)modifications.swordAccessoryInstance.transform.Find("SwordAccessoryArmature")).gameObject;
		modifications.swordAccessoryArmature.transform.SetParent(val, false);
		modifications.swordAccessoryDynamicBone = modelObject.AddComponent<DynamicBone>();
		modifications.swordAccessoryDynamicBone.m_Root = modifications.swordAccessoryArmature.transform.GetChild(0);
		modifications.swordAccessoryDynamicBone.m_Force = new Vector3(0f, -0.05f, 0f);
		modifications.swordAccessoryDynamicBone.m_Damping = 0f;
		modifications.swordAccessoryDynamicBone.m_Elasticity = 0.05f;
		modifications.swordAccessoryDynamicBone.m_Stiffness = 0f;
		modifications.swordAccessoryDynamicBone.m_Inert = 0f;
		Array.Resize(ref characterModel.baseRendererInfos, characterModel.baseRendererInfos.Length + 1);
		SkinnedMeshRenderer component = ((Component)modifications.swordAccessoryInstance.transform.Find("SwordAccessory")).GetComponent<SkinnedMeshRenderer>();
		characterModel.baseRendererInfos[characterModel.baseRendererInfos.Length - 1] = new RendererInfo
		{
			renderer = (Renderer)(object)component,
			ignoreOverlays = false,
			defaultShadowCastingMode = (ShadowCastingMode)1,
			defaultMaterial = ((Renderer)component).sharedMaterial
		};
	}

	private void Start()
	{
		Instance = this;
		BeforeStart();
		using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Mercenary2B.kingenderbrinemercenary2b"))
		{
			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();
	}

	private void BeforeStart()
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		new Hook((MethodBase)typeof(SkinDef).GetMethod("Apply"), (Delegate)new Action<Action<SkinDef, GameObject>, SkinDef, GameObject>(SkinDefApply)).Apply();
		DisableSkirt = ((BaseUnityPlugin)this).Config.Bind<bool>("Main", "DisableSkirt", false, "Disable skirt on the skin");
	}

	private static void ReplaceShaders()
	{
		LoadMaterialsWithReplacedShader("RoR2/Base/Shaders/HGStandard.shader", "Assets/Mercenary2B/Resources/Materials/mat2B.mat", "Assets/Mercenary2B/Resources/Materials/matSword.mat");
	}

	private static void LoadMaterialsWithReplacedShader(string shaderPath, params string[] materialPaths)
	{
		//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)
		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("KINGENDERBRINE_SKIN_MERCENARY2B_NAME", "2B");
	}

	private static void Nothing(Action<SkinDef> orig, SkinDef self)
	{
	}

	private static void BodyCatalogInit()
	{
		MethodInfo method = typeof(SkinDef).GetMethod("Awake", BindingFlags.Instance | BindingFlags.NonPublic);
		HookEndpointManager.Add((MethodBase)method, (Delegate)new Action<Action<SkinDef>, SkinDef>(Nothing));
		AddMercBodyMercenary2BSkin();
		HookEndpointManager.Remove((MethodBase)method, (Delegate)new Action<Action<SkinDef>, SkinDef>(Nothing));
	}

	private static void MercBodyMercenary2BSkinAdded(SkinDef skinDef, GameObject bodyPrefab)
	{
		SkinDef = skinDef;
	}

	private static void AddMercBodyMercenary2BSkin()
	{
		//IL_025b: Unknown result type (might be due to invalid IL or missing references)
		string text = "MercBody";
		string text2 = "Mercenary2B";
		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;
			ModelSkinController val2 = (Object.op_Implicit((Object)(object)gameObject) ? gameObject.GetComponent<ModelSkinController>() : null);
			if (!Object.op_Implicit((Object)(object)val2))
			{
				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>();
			TryCatchThrow("Icon", delegate
			{
				skin.icon = assetBundle.LoadAsset<Sprite>("Assets\\SkinMods\\Mercenary2B\\Icons\\Mercenary2BIcon.png");
			});
			((Object)skin).name = text2;
			skin.nameToken = "KINGENDERBRINE_SKIN_MERCENARY2B_NAME";
			skin.rootObject = gameObject;
			TryCatchThrow("Base Skins", delegate
			{
				skin.baseSkins = Array.Empty<SkinDef>();
			});
			TryCatchThrow("Unlockable Name", delegate
			{
				skin.unlockableDef = null;
			});
			TryCatchThrow("Game Object Activations", delegate
			{
				skin.gameObjectActivations = Array.Empty<GameObjectActivation>();
			});
			TryCatchThrow("Renderer Infos", delegate
			{
				//IL_0011: 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_004c: Unknown result type (might be due to invalid IL or missing references)
				//IL_004d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0056: Unknown result type (might be due to invalid IL or missing references)
				//IL_0075: Unknown result type (might be due to invalid IL or missing references)
				//IL_0091: 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)
				skin.rendererInfos = (RendererInfo[])(object)new RendererInfo[2]
				{
					new RendererInfo
					{
						defaultMaterial = assetBundle.LoadAsset<Material>("Assets/Mercenary2B/Resources/Materials/mat2B.mat"),
						defaultShadowCastingMode = (ShadowCastingMode)1,
						ignoreOverlays = false,
						renderer = renderers[7]
					},
					new RendererInfo
					{
						defaultMaterial = assetBundle.LoadAsset<Material>("Assets/Mercenary2B/Resources/Materials/matSword.mat"),
						defaultShadowCastingMode = (ShadowCastingMode)1,
						ignoreOverlays = false,
						renderer = renderers[8]
					}
				};
			});
			TryCatchThrow("Mesh Replacements", delegate
			{
				//IL_0011: 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_003d: 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_0071: Unknown result type (might be due to invalid IL or missing references)
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				skin.meshReplacements = (MeshReplacement[])(object)new MeshReplacement[2]
				{
					new MeshReplacement
					{
						mesh = assetBundle.LoadAsset<Mesh>("Assets\\SkinMods\\Mercenary2B\\Meshes\\Nier2b.mesh"),
						renderer = renderers[7]
					},
					new MeshReplacement
					{
						mesh = assetBundle.LoadAsset<Mesh>("Assets\\SkinMods\\Mercenary2B\\Meshes\\Sword.mesh"),
						renderer = renderers[8]
					}
				};
			});
			TryCatchThrow("Minion Skin Replacements", delegate
			{
				skin.minionSkinReplacements = Array.Empty<MinionSkinReplacement>();
			});
			TryCatchThrow("Projectile Ghost Replacements", delegate
			{
				skin.projectileGhostReplacements = Array.Empty<ProjectileGhostReplacement>();
			});
			Array.Resize(ref val2.skins, val2.skins.Length + 1);
			val2.skins[val2.skins.Length - 1] = skin;
			BodyCatalog.skins[BodyCatalog.FindBodyIndex(val)] = val2.skins;
			MercBodyMercenary2BSkinAdded(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);
		}
	}
}
public class ModificationObjects
{
	public GameObject swordAccessoryInstance;

	public GameObject swordAccessoryArmature;

	public DynamicBone swordAccessoryDynamicBone;

	public GameObject skirtInstance;

	public GameObject skirtArmature;

	public DynamicBone skirtDynamicBone;

	public DynamicBoneCollider pelvisDynamicBoneCollider;

	public DynamicBoneCollider thighL1DynamicBoneCollider;

	public DynamicBoneCollider thighL2DynamicBoneCollider;

	public DynamicBoneCollider thighR1DynamicBoneCollider;

	public DynamicBoneCollider thighR2DynamicBoneCollider;

	public DynamicBoneCollider stomachDynamicBoneCollider;

	public SkinnedMeshRenderer swordMeshRenderer;

	public SkinnedMeshRenderer mercMeshRenderer;

	public GameObject breastBonesInstance;

	public DynamicBone mercBreastDynamicBone;

	public GameObject buttBonesInstance;

	public DynamicBone mercButtDynamicBone;

	public GameObject swordPointLight;

	public GameObject chestPointLight;
}