Decompiled source of EasyVanity v1.2.5

plugins/EzVanity.dll

Decompiled a week ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Nessie.ATLYSS.EasySettings;
using UnityEngine.Events;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: AssemblyCompany("EzVanity")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+7f3118ba531dfb78b3f2730cab60611fe30f78b5")]
[assembly: AssemblyProduct("EzVanity")]
[assembly: AssemblyTitle("EzVanity")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace EzVanity
{
	internal class DyePatch
	{
		[HarmonyPatch(typeof(PlayerInventory), "Init_RemoveConsumableItemData")]
		public class PatchRemoveDye
		{
			private static bool Prefix(PlayerInventory __instance, ItemData _itemData)
			{
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				if (Plugin.Instance.DontConsumeDyeEnabled() && (int)TabMenu._current._itemCell._currentEquipCellTab == 0 && _itemData._itemName.EndsWith(" Dye", StringComparison.Ordinal))
				{
					return false;
				}
				return true;
			}

			private static void Postfix(PlayerInventory __instance, ItemData _itemData)
			{
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				if (Plugin.Instance.DontConsumeDyeEnabled() && (int)TabMenu._current._itemCell._currentEquipCellTab == 0 && _itemData._itemName.EndsWith(" Dye", StringComparison.Ordinal))
				{
					ProfileDataManager._current.Save_ProfileData();
				}
			}
		}
	}
	internal class ESsetup
	{
		internal static ESsetup Instance;

		public static void Initialize()
		{
			if (Instance == null)
			{
				Instance = new ESsetup();
			}
		}

		private ESsetup()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			Settings.OnInitialized.AddListener(new UnityAction(ES_AddSettings));
		}

		public void ES_AddSettings()
		{
			SettingsTab modTab = Settings.ModTab;
			modTab.AddHeader("Easy Vanity");
			modTab.AddToggle("Free Appearance Changes", Plugin.ConfigEnableFree);
			modTab.AddToggle("Free Transmog", Plugin.ConfigEnableFreeTransmog);
			modTab.AddToggle("Unlocked Transmog", Plugin.ConfigEnableUnlockedTransmog);
			if (!Plugin.HBloaded)
			{
				modTab.AddToggle("Dont Consume Dye", Plugin.ConfigEnableDontConsumeDye);
			}
		}
	}
	internal class FreeTransmogPatch
	{
		[HarmonyPatch(typeof(PlayerEquipment), "<Init_TransmogItem>g__Retrieve_IllusionStoneCount|23_0")]
		public class PatchRetrieveIllusionStoneCount
		{
			private static bool Prefix(ref int __result)
			{
				if (!Plugin.Instance.IsFreeTransmogEnabled())
				{
					return true;
				}
				__result = 1;
				return false;
			}
		}

		[HarmonyPatch(typeof(PlayerInventory), "Remove_Item")]
		public class PatchRemoveIllusionStone
		{
			private static bool Prefix(PlayerInventory __instance, ItemData _itemData, int _quantity)
			{
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_001d: Invalid comparison between Unknown and I4
				if (!Plugin.Instance.IsFreeTransmogEnabled() || (int)TabMenu._current._itemCell._currentEquipCellTab != 1)
				{
					return true;
				}
				if (_itemData._itemName == "Illusion Stone" && _quantity > 0)
				{
					return false;
				}
				return true;
			}
		}
	}
	internal class FreeVanityMirrorPatch
	{
		[HarmonyPatch(typeof(VanityMirrorManager), "<Update>g__Retrieve_IllusionStoneCount|92_0")]
		public class PatchRetrieveIllusionStoneCount
		{
			private static bool Prefix(ref int __result)
			{
				if (!Plugin.Instance.IsFreeAppearanceEnabled())
				{
					return true;
				}
				__result = 1;
				return false;
			}
		}

		[HarmonyPatch(typeof(PlayerInventory), "Remove_Item")]
		public class PatchRemoveIllusionStone
		{
			private static bool Prefix(PlayerInventory __instance, ItemData _itemData, int _quantity)
			{
				if (!Plugin.Instance.IsFreeAppearanceEnabled() || !VanityMirrorManager._current._isOpen)
				{
					return true;
				}
				if (_itemData._itemName == "Illusion Stone" && _quantity > 0)
				{
					return false;
				}
				return true;
			}
		}
	}
	[BepInPlugin("ez.vanity", "Easy Vanity", "1.2.5")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		private const string modGUID = "ez.vanity";

		private const string modName = "Easy Vanity";

		private const string modVersion = "1.2.5";

		public static ConfigEntry<bool> ConfigEnableFree;

		public static ConfigEntry<bool> ConfigEnableFreeTransmog;

		public static ConfigEntry<bool> ConfigEnableUnlockedTransmog;

		public static ConfigEntry<bool> ConfigEnableDontConsumeDye;

		public static bool HBloaded;

		public static Plugin Instance { get; private set; }

		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			Harmony val = new Harmony("ez.vanity");
			Instance = this;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin ez.vanity is loaded!");
			val.PatchAll(typeof(FreeTransmogPatch.PatchRemoveIllusionStone));
			val.PatchAll(typeof(FreeTransmogPatch.PatchRetrieveIllusionStoneCount));
			val.PatchAll(typeof(FreeVanityMirrorPatch.PatchRemoveIllusionStone));
			val.PatchAll(typeof(FreeVanityMirrorPatch.PatchRetrieveIllusionStoneCount));
			val.PatchAll(typeof(UnlockedTransmogPatch.PatchAbleToTransmogEquip));
			val.PatchAll(typeof(UnlockedTransmogPatch.PatchCanTransmogItem));
			ConfigEnableFree = ((BaseUnityPlugin)this).Config.Bind<bool>("Free Appearance Change", "EnableFreeAppearance", true, "Whether or not it is free to make changes at the mirror");
			ConfigEnableFreeTransmog = ((BaseUnityPlugin)this).Config.Bind<bool>("Free Transmog", "EnableFreeTransmog", true, "Whether or not it is free to transmog armor");
			ConfigEnableUnlockedTransmog = ((BaseUnityPlugin)this).Config.Bind<bool>("Unlocked Transmog", "EnableUnlockedTransmog", true, "Whether or not transmog is unrestricted");
			ConfigEnableDontConsumeDye = ((BaseUnityPlugin)this).Config.Bind<bool>("Dont Consume Dye", "DontConsumeDye", true, "Whether or not consume dye when used (Not HB Compatiable)");
			if (Chainloader.PluginInfos.ContainsKey("EasySettings"))
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"EasySettings found - Settings tab added");
				ESsetup.Initialize();
			}
			if (Chainloader.PluginInfos.ContainsKey("Homebrewery"))
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Homebrewery found - Skipping dye patch");
				HBloaded = true;
			}
			else
			{
				val.PatchAll(typeof(DyePatch.PatchRemoveDye));
			}
		}

		public bool IsFreeAppearanceEnabled()
		{
			return ConfigEnableFree.Value;
		}

		public bool IsFreeTransmogEnabled()
		{
			return ConfigEnableFreeTransmog.Value;
		}

		public bool IsUnlockedTransmogEnabled()
		{
			return ConfigEnableUnlockedTransmog.Value;
		}

		public bool DontConsumeDyeEnabled()
		{
			return ConfigEnableDontConsumeDye.Value;
		}
	}
	public class UnlockedTransmogPatch
	{
		[HarmonyPatch(typeof(ItemListDataEntry), "CanTransmogItem")]
		public class PatchCanTransmogItem
		{
			private static bool Prefix(ItemListDataEntry __instance, ref bool __result)
			{
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0023: Invalid comparison between Unknown and I4
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Expected O, but got Unknown
				if (!Plugin.Instance.IsUnlockedTransmogEnabled())
				{
					return true;
				}
				if ((int)__instance._scriptableItem._itemType == 0)
				{
					ScriptableEquipment scriptableEquipment = (ScriptableEquipment)__instance._scriptableItem;
					Instance.CheckEquipmentType(scriptableEquipment);
					if (Instance.IsNotWeaponOrRing())
					{
						__result = true;
						return false;
					}
				}
				__result = false;
				return false;
			}
		}

		[HarmonyPatch(typeof(ItemMenuCell), "AbleToTransmogEquip")]
		public class PatchAbleToTransmogEquip
		{
			private static void Postfix(ItemMenuCell __instance, ItemListDataEntry _listEntry, ref bool __result)
			{
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Invalid comparison between Unknown and I4
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: Expected O, but got Unknown
				if (Plugin.Instance.IsUnlockedTransmogEnabled() && (int)_listEntry._scriptableItem._itemType == 0)
				{
					ScriptableEquipment scriptableEquipment = (ScriptableEquipment)_listEntry._scriptableItem;
					Instance.CheckEquipmentType(scriptableEquipment);
					if (Instance.IsNotWeaponOrRing())
					{
						__result = true;
					}
				}
			}
		}

		private static UnlockedTransmogPatch _instance;

		private bool isNotWeaponOrRing;

		private ScriptableEquipment currentScriptableEquipment;

		public static UnlockedTransmogPatch Instance => _instance ?? (_instance = new UnlockedTransmogPatch());

		public void CheckEquipmentType(ScriptableEquipment scriptableEquipment)
		{
			currentScriptableEquipment = scriptableEquipment;
			isNotWeaponOrRing = !(((object)scriptableEquipment).GetType() == typeof(ScriptableWeapon)) && !(((object)scriptableEquipment).GetType() == typeof(ScriptableRing));
		}

		public bool IsNotWeaponOrRing()
		{
			return isNotWeaponOrRing;
		}
	}
}