Decompiled source of Transmog v2.0.2

Transmog.dll

Decompiled 4 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn;
using Jotunn.Managers;
using Jotunn.Utils;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Transmog")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Transmog")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.0")]
namespace Transmog;

public static class Configs
{
	public static ConfigEntry<KeyboardShortcut> HotKeyOpenTransmogPanel;

	public static ConfigEntry<KeyboardShortcut> HotKeyToggleTransmog;

	public static ConfigEntry<string> PanelStartingAnchor;

	public static ConfigEntry<Vector2> PanelStartingPosition;

	public static void SetupConfigs(ConfigFile config)
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Expected O, but got Unknown
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		AcceptableValueList<string> val = new AcceptableValueList<string>(TransmogUI.Anchors.Keys.ToArray());
		HotKeyOpenTransmogPanel = config.Bind<KeyboardShortcut>("General", GenerateConfigKey("HotKeyOpenTransmogPanel"), new KeyboardShortcut((KeyCode)116, Array.Empty<KeyCode>()), "Hotkey to open the transmog panel. Make sure your inventory is open before using the hotkey. Examples: Q, C, LeftShift + Q, LeftShift + Alpha1, LeftAlt + F1. It is recommended that you use a configuration manager mod to easily change the hotkey in-game.");
		HotKeyToggleTransmog = config.Bind<KeyboardShortcut>("General", GenerateConfigKey("HotKeyToggleTransmog"), new KeyboardShortcut((KeyCode)61, (KeyCode[])(object)new KeyCode[1] { (KeyCode)308 }), "Hotkey to switch the transmog on and off. Examples: Q, C, LeftShift + Q, LeftShift + Alpha1, LeftAlt + F1. It is recommended that you use a configuration manager mod to easily change the hotkey in-game.");
		PanelStartingAnchor = config.Bind<string>("General", GenerateConfigKey("PanelStartingAnchor"), "Upper-right", new ConfigDescription("Defines the starting point of the transmog panel.", (AcceptableValueBase)(object)val, Array.Empty<object>()));
		PanelStartingPosition = config.Bind<Vector2>("General", GenerateConfigKey("PanelStartingPosition"), new Vector2(-632f, -31f), "Defines the starting position of the transmog panel.");
		PanelStartingAnchor.SettingChanged += PanelSettingsChanged;
		PanelStartingPosition.SettingChanged += PanelSettingsChanged;
	}

	public static string GenerateConfigKey(string key)
	{
		return GenerateConfigKey(key, null);
	}

	public static string GenerateConfigKey(string key, string unit)
	{
		key = string.Concat(key.Select((char x) => char.IsUpper(x) ? (" " + x) : x.ToString())).TrimStart(new char[1] { ' ' });
		if (!string.IsNullOrEmpty(unit))
		{
			key += $" ({unit})";
		}
		return key;
	}

	private static void PanelSettingsChanged(object sender, EventArgs e)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: 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_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: 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)
		RectTransform val = (RectTransform)TransmogUI.Panel.transform;
		Vector2 val3 = (val.pivot = TransmogUI.Anchors[PanelStartingAnchor.Value]);
		Vector2 anchorMin = (val.anchorMax = val3);
		val.anchorMin = anchorMin;
		val.anchoredPosition = PanelStartingPosition.Value;
	}
}
public class TransmogItem
{
	public ItemType ItemType;

	public SkillType ItemSkill;

	public string ItemLabel;

	public string ItemName;

	public int ItemVariant;

	public bool Hidden;

	public bool CanBeHidden;

	public TransmogItem(ItemType itemType, SkillType itemSkill, string itemLabel, bool canBeHidden = false)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		ItemType = itemType;
		ItemSkill = itemSkill;
		ItemLabel = itemLabel;
		CanBeHidden = canBeHidden;
		ItemName = string.Empty;
	}
}
public enum ItemCategory
{
	HELMET,
	CHEST,
	LEGS,
	SHOULDER,
	UTILITY,
	SHIELD,
	ONE_HANDED_AXE,
	ONE_HANDED_CLUB,
	ONE_HANDED_SWORD,
	KNIFE,
	SPEAR,
	POLEARM,
	TWO_HANDED_AXE,
	TWO_HANDED_CLUB,
	TWO_HANDED_SWORD,
	PICKAXE,
	BOW,
	CROSSBOW
}
[BepInPlugin("Transmog", "Transmog", "2.0.2")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
public class Transmog : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Player), "OnSpawned")]
	public class Player_OnSpawned_Patch
	{
		public static void Postfix(Player __instance)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && __instance.m_customData.ContainsKey("Alpus-Transmog"))
			{
				LoadData(new ZPackage(__instance.m_customData["Alpus-Transmog"]));
				((Humanoid)Player.m_localPlayer).SetupVisEquipment(((Humanoid)Player.m_localPlayer).m_visEquipment, false);
			}
		}
	}

	[HarmonyPatch(typeof(Player), "Update")]
	public class Player_Update_Patch
	{
		public static void Postfix(Player __instance)
		{
			//IL_002a: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer || (Object)(object)ZNetScene.instance == (Object)null)
			{
				return;
			}
			KeyboardShortcut value = Configs.HotKeyOpenTransmogPanel.Value;
			if (((KeyboardShortcut)(ref value)).Modifiers.Count() == 0)
			{
				value = Configs.HotKeyOpenTransmogPanel.Value;
				if (Input.GetKeyUp(((KeyboardShortcut)(ref value)).MainKey))
				{
					goto IL_006b;
				}
			}
			value = Configs.HotKeyOpenTransmogPanel.Value;
			if (((KeyboardShortcut)(ref value)).IsUp())
			{
				goto IL_006b;
			}
			goto IL_0086;
			IL_0086:
			value = Configs.HotKeyToggleTransmog.Value;
			if (((KeyboardShortcut)(ref value)).Modifiers.Count() == 0)
			{
				value = Configs.HotKeyToggleTransmog.Value;
				if (Input.GetKeyUp(((KeyboardShortcut)(ref value)).MainKey))
				{
					goto IL_00cc;
				}
			}
			value = Configs.HotKeyToggleTransmog.Value;
			if (!((KeyboardShortcut)(ref value)).IsUp())
			{
				return;
			}
			goto IL_00cc;
			IL_006b:
			if (TakeInput() && InventoryGui.IsVisible())
			{
				TransmogUI.ToggleMenu();
			}
			goto IL_0086;
			IL_00cc:
			if (TakeInput())
			{
				TransmogEnabled = !TransmogEnabled;
				((Humanoid)Player.m_localPlayer).SetupVisEquipment(((Humanoid)Player.m_localPlayer).m_visEquipment, false);
				SaveData();
				((Character)__instance).Message((MessageType)1, string.Format("Transmog = {0}.", TransmogEnabled ? "on" : "off"), 0, (Sprite)null);
			}
		}
	}

	[HarmonyPatch(typeof(InventoryGrid), "OnLeftClick")]
	public static class InventoryGrid_OnLeftClick_Patch
	{
		public static bool Prefix(InventoryGrid __instance, UIInputHandler clickHandler)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			if (TransmogUI.Panel.activeSelf)
			{
				Vector2i buttonPos = __instance.GetButtonPos(((Component)clickHandler).gameObject);
				ItemData itemDrop = __instance.m_inventory.GetItemAt(buttonPos.x, buttonPos.y);
				if (itemDrop != null)
				{
					KeyValuePair<ItemCategory, TransmogItem> keyValuePair = TransmogItems.FirstOrDefault((KeyValuePair<ItemCategory, TransmogItem> x) => x.Value.ItemType == itemDrop.m_shared.m_itemType && x.Value.ItemSkill == itemDrop.m_shared.m_skillType);
					if (!keyValuePair.Equals(default(KeyValuePair<ItemCategory, TransmogItem>)))
					{
						UpdateTransmog(keyValuePair.Key, ((Object)itemDrop.m_dropPrefab).name, itemDrop.m_variant, false, itemDrop.GetIcon());
					}
					return false;
				}
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(InventoryGui), "Hide")]
	public static class InventoryGui_Show_Patch
	{
		public static void Postfix()
		{
			if (!((Object)(object)Player.m_localPlayer == (Object)null))
			{
				TransmogUI.CloseMenu();
			}
		}
	}

	[HarmonyPatch(typeof(VisEquipment), "SetHelmetItem")]
	public static class VisEquipment_SetHelmetItem_Patch
	{
		public static void Prefix(VisEquipment __instance, ref string name)
		{
			if (TransmogEnabled && !((Object)(object)Player.m_localPlayer == (Object)null) && !((Object)(object)((Component)__instance).gameObject != (Object)(object)((Component)Player.m_localPlayer).gameObject) && (TransmogItems[ItemCategory.HELMET].ItemName != string.Empty || TransmogItems[ItemCategory.HELMET].Hidden) && ((Humanoid)Player.m_localPlayer).m_helmetItem != null)
			{
				name = ((!TransmogItems[ItemCategory.HELMET].Hidden) ? TransmogItems[ItemCategory.HELMET].ItemName : string.Empty);
			}
		}
	}

	[HarmonyPatch(typeof(VisEquipment), "SetChestItem")]
	public static class VisEquipment_SetChestItem_Patch
	{
		public static void Prefix(VisEquipment __instance, ref string name)
		{
			if (TransmogEnabled && !((Object)(object)Player.m_localPlayer == (Object)null) && !((Object)(object)((Component)__instance).gameObject != (Object)(object)((Component)Player.m_localPlayer).gameObject) && (TransmogItems[ItemCategory.CHEST].ItemName != string.Empty || TransmogItems[ItemCategory.CHEST].Hidden) && ((Humanoid)Player.m_localPlayer).m_chestItem != null)
			{
				name = ((!TransmogItems[ItemCategory.CHEST].Hidden) ? TransmogItems[ItemCategory.CHEST].ItemName : string.Empty);
			}
		}
	}

	[HarmonyPatch(typeof(VisEquipment), "SetLegItem")]
	public static class VisEquipment_SetLegItem_Patch
	{
		public static void Prefix(VisEquipment __instance, ref string name)
		{
			if (TransmogEnabled && !((Object)(object)Player.m_localPlayer == (Object)null) && !((Object)(object)((Component)__instance).gameObject != (Object)(object)((Component)Player.m_localPlayer).gameObject) && (TransmogItems[ItemCategory.LEGS].ItemName != string.Empty || TransmogItems[ItemCategory.LEGS].Hidden) && ((Humanoid)Player.m_localPlayer).m_legItem != null)
			{
				name = ((!TransmogItems[ItemCategory.LEGS].Hidden) ? TransmogItems[ItemCategory.LEGS].ItemName : string.Empty);
			}
		}
	}

	[HarmonyPatch(typeof(VisEquipment), "SetUtilityItem")]
	public static class VisEquipment_SetUtilityItem_Patch
	{
		public static void Prefix(VisEquipment __instance, ref string name)
		{
			if (TransmogEnabled && !((Object)(object)Player.m_localPlayer == (Object)null) && !((Object)(object)((Component)__instance).gameObject != (Object)(object)((Component)Player.m_localPlayer).gameObject) && (TransmogItems[ItemCategory.UTILITY].ItemName != string.Empty || TransmogItems[ItemCategory.UTILITY].Hidden) && ((Humanoid)Player.m_localPlayer).m_utilityItem != null)
			{
				name = ((!TransmogItems[ItemCategory.UTILITY].Hidden) ? TransmogItems[ItemCategory.UTILITY].ItemName : string.Empty);
			}
		}
	}

	[HarmonyPatch(typeof(VisEquipment), "SetShoulderItem")]
	public static class VisEquipment_SetShoulderItem_Patch
	{
		public static void Prefix(VisEquipment __instance, ref string name, ref int variant)
		{
			if (TransmogEnabled && !((Object)(object)Player.m_localPlayer == (Object)null) && !((Object)(object)((Component)__instance).gameObject != (Object)(object)((Component)Player.m_localPlayer).gameObject) && (TransmogItems[ItemCategory.SHOULDER].ItemName != string.Empty || TransmogItems[ItemCategory.SHOULDER].Hidden) && ((Humanoid)Player.m_localPlayer).m_shoulderItem != null)
			{
				name = ((!TransmogItems[ItemCategory.SHOULDER].Hidden) ? TransmogItems[ItemCategory.SHOULDER].ItemName : string.Empty);
				variant = TransmogItems[ItemCategory.SHOULDER].ItemVariant;
			}
		}
	}

	[HarmonyPatch(typeof(VisEquipment), "SetLeftItem")]
	public static class VisEquipment_SetLeftItem_Patch
	{
		public static void Prefix(VisEquipment __instance, ref string name, ref int variant)
		{
			if (TransmogEnabled && !((Object)(object)Player.m_localPlayer == (Object)null) && !((Object)(object)((Component)__instance).gameObject != (Object)(object)((Component)Player.m_localPlayer).gameObject) && ((Humanoid)Player.m_localPlayer).m_leftItem != null)
			{
				KeyValuePair<ItemCategory, TransmogItem> keyValuePair = TransmogItems.FirstOrDefault((KeyValuePair<ItemCategory, TransmogItem> x) => x.Value.ItemType == ((Humanoid)Player.m_localPlayer).m_leftItem.m_shared.m_itemType && x.Value.ItemSkill == ((Humanoid)Player.m_localPlayer).m_leftItem.m_shared.m_skillType);
				if (!keyValuePair.Equals(default(KeyValuePair<ItemCategory, TransmogItem>)) && keyValuePair.Value.ItemName != string.Empty)
				{
					name = keyValuePair.Value.ItemName;
					variant = keyValuePair.Value.ItemVariant;
				}
			}
		}
	}

	[HarmonyPatch(typeof(VisEquipment), "SetLeftBackItem")]
	public static class VisEquipment_SetLeftBackItem_Patch
	{
		public static void Prefix(VisEquipment __instance, ref string name, ref int variant)
		{
			if (TransmogEnabled && !((Object)(object)Player.m_localPlayer == (Object)null) && !((Object)(object)((Component)__instance).gameObject != (Object)(object)((Component)Player.m_localPlayer).gameObject) && ((Humanoid)Player.m_localPlayer).m_hiddenLeftItem != null)
			{
				KeyValuePair<ItemCategory, TransmogItem> keyValuePair = TransmogItems.FirstOrDefault((KeyValuePair<ItemCategory, TransmogItem> x) => x.Value.ItemType == ((Humanoid)Player.m_localPlayer).m_hiddenLeftItem.m_shared.m_itemType && x.Value.ItemSkill == ((Humanoid)Player.m_localPlayer).m_hiddenLeftItem.m_shared.m_skillType);
				if (!keyValuePair.Equals(default(KeyValuePair<ItemCategory, TransmogItem>)) && keyValuePair.Value.ItemName != string.Empty)
				{
					name = keyValuePair.Value.ItemName;
					variant = keyValuePair.Value.ItemVariant;
				}
			}
		}
	}

	[HarmonyPatch(typeof(VisEquipment), "SetRightItem")]
	public static class VisEquipment_SetRightItem_Patch
	{
		public static void Prefix(VisEquipment __instance, ref string name)
		{
			if (TransmogEnabled && !((Object)(object)Player.m_localPlayer == (Object)null) && !((Object)(object)((Component)__instance).gameObject != (Object)(object)((Component)Player.m_localPlayer).gameObject) && ((Humanoid)Player.m_localPlayer).m_rightItem != null)
			{
				KeyValuePair<ItemCategory, TransmogItem> keyValuePair = TransmogItems.FirstOrDefault((KeyValuePair<ItemCategory, TransmogItem> x) => x.Value.ItemType == ((Humanoid)Player.m_localPlayer).m_rightItem.m_shared.m_itemType && x.Value.ItemSkill == ((Humanoid)Player.m_localPlayer).m_rightItem.m_shared.m_skillType);
				if (!keyValuePair.Equals(default(KeyValuePair<ItemCategory, TransmogItem>)) && keyValuePair.Value.ItemName != string.Empty)
				{
					name = keyValuePair.Value.ItemName;
				}
			}
		}
	}

	[HarmonyPatch(typeof(VisEquipment), "SetRightBackItem")]
	public static class VisEquipment_SetRightBackItem_Patch
	{
		public static void Prefix(VisEquipment __instance, ref string name)
		{
			if (TransmogEnabled && !((Object)(object)Player.m_localPlayer == (Object)null) && !((Object)(object)((Component)__instance).gameObject != (Object)(object)((Component)Player.m_localPlayer).gameObject) && ((Humanoid)Player.m_localPlayer).m_hiddenRightItem != null)
			{
				KeyValuePair<ItemCategory, TransmogItem> keyValuePair = TransmogItems.FirstOrDefault((KeyValuePair<ItemCategory, TransmogItem> x) => x.Value.ItemType == ((Humanoid)Player.m_localPlayer).m_hiddenRightItem.m_shared.m_itemType && x.Value.ItemSkill == ((Humanoid)Player.m_localPlayer).m_hiddenRightItem.m_shared.m_skillType);
				if (!keyValuePair.Equals(default(KeyValuePair<ItemCategory, TransmogItem>)) && keyValuePair.Value.ItemName != string.Empty)
				{
					name = keyValuePair.Value.ItemName;
				}
			}
		}
	}

	public const string PluginGUID = "Transmog";

	public const string PluginName = "Transmog";

	public const string PluginVersion = "2.0.2";

	public const string SaveDataVersion = "3.0";

	public const string CustomDataKey = "Alpus-Transmog";

	public static Dictionary<ItemCategory, TransmogItem> TransmogItems;

	private static bool TransmogEnabled = true;

	private static Harmony harmony;

	private void Awake()
	{
		Configs.SetupConfigs(((BaseUnityPlugin)this).Config);
		SetupTransmogItems();
		GUIManager.OnCustomGUIAvailable += AddTransmogUI;
		harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "Transmog");
	}

	private void OnDestroy()
	{
		Harmony obj = harmony;
		if (obj != null)
		{
			obj.UnpatchSelf();
		}
	}

	private void AddTransmogUI()
	{
		TransmogUI.Awake();
	}

	private void SetupTransmogItems()
	{
		TransmogItems = new Dictionary<ItemCategory, TransmogItem>
		{
			{
				ItemCategory.HELMET,
				new TransmogItem((ItemType)6, (SkillType)1, "Helmet", canBeHidden: true)
			},
			{
				ItemCategory.CHEST,
				new TransmogItem((ItemType)7, (SkillType)1, "Chest", canBeHidden: true)
			},
			{
				ItemCategory.LEGS,
				new TransmogItem((ItemType)11, (SkillType)1, "Legs", canBeHidden: true)
			},
			{
				ItemCategory.SHOULDER,
				new TransmogItem((ItemType)17, (SkillType)1, "Shoulder", canBeHidden: true)
			},
			{
				ItemCategory.UTILITY,
				new TransmogItem((ItemType)18, (SkillType)1, "Utility", canBeHidden: true)
			},
			{
				ItemCategory.SHIELD,
				new TransmogItem((ItemType)5, (SkillType)6, "Shield")
			},
			{
				ItemCategory.ONE_HANDED_AXE,
				new TransmogItem((ItemType)3, (SkillType)7, "One-handed Axe")
			},
			{
				ItemCategory.ONE_HANDED_CLUB,
				new TransmogItem((ItemType)3, (SkillType)3, "One-handed Club")
			},
			{
				ItemCategory.ONE_HANDED_SWORD,
				new TransmogItem((ItemType)3, (SkillType)1, "One-handed Sword")
			},
			{
				ItemCategory.KNIFE,
				new TransmogItem((ItemType)3, (SkillType)2, "Knife")
			},
			{
				ItemCategory.SPEAR,
				new TransmogItem((ItemType)3, (SkillType)5, "Spear")
			},
			{
				ItemCategory.POLEARM,
				new TransmogItem((ItemType)14, (SkillType)4, "Polearm")
			},
			{
				ItemCategory.TWO_HANDED_AXE,
				new TransmogItem((ItemType)14, (SkillType)7, "Two-handed Axe")
			},
			{
				ItemCategory.TWO_HANDED_CLUB,
				new TransmogItem((ItemType)14, (SkillType)3, "Two-handed Club")
			},
			{
				ItemCategory.TWO_HANDED_SWORD,
				new TransmogItem((ItemType)14, (SkillType)1, "Two-handed Sword")
			},
			{
				ItemCategory.PICKAXE,
				new TransmogItem((ItemType)14, (SkillType)12, "Pickaxe")
			},
			{
				ItemCategory.BOW,
				new TransmogItem((ItemType)4, (SkillType)8, "Bow")
			},
			{
				ItemCategory.CROSSBOW,
				new TransmogItem((ItemType)4, (SkillType)14, "Crossbow")
			}
		};
	}

	private static void SaveData()
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		ZPackage val = new ZPackage();
		val.Write("3.0");
		val.Write(TransmogEnabled);
		val.Write(TransmogItems.Count);
		foreach (KeyValuePair<ItemCategory, TransmogItem> transmogItem in TransmogItems)
		{
			val.Write(transmogItem.Key.ToString());
			val.Write(transmogItem.Value.ItemName);
			val.Write(transmogItem.Value.ItemVariant);
			if (transmogItem.Value.CanBeHidden)
			{
				val.Write(transmogItem.Value.Hidden);
			}
		}
		if (Player.m_localPlayer.m_customData.ContainsKey("Alpus-Transmog"))
		{
			Player.m_localPlayer.m_customData["Alpus-Transmog"] = val.GetBase64();
		}
		else
		{
			Player.m_localPlayer.m_customData.Add("Alpus-Transmog", val.GetBase64());
		}
		Logger.LogInfo((object)"Transmog data saved successfuly!");
	}

	private static void LoadData(ZPackage package)
	{
		Logger.LogInfo((object)"Loading transmog data...");
		string text = package.ReadString();
		if (!(text == "3.0"))
		{
			return;
		}
		TransmogEnabled = package.ReadBool();
		int num = package.ReadInt();
		for (int i = 0; i < num; i++)
		{
			if (Enum.TryParse<ItemCategory>(package.ReadString(), out var result))
			{
				if (TransmogItems.ContainsKey(result))
				{
					TransmogItems[result].ItemName = package.ReadString();
					TransmogItems[result].ItemVariant = package.ReadInt();
					if (TransmogItems[result].CanBeHidden)
					{
						TransmogItems[result].Hidden = package.ReadBool();
					}
					continue;
				}
				Logger.LogError((object)$"Could not find item category '{result}'. Aborting the loading.");
				break;
			}
			Logger.LogWarning((object)$"Could not parse item category '{result}'. Aborting the loading.");
			break;
		}
		TransmogUI.UpdateItemGrid();
		Logger.LogInfo((object)"Transmog data loading completed.");
	}

	public static bool TakeInput()
	{
		bool result = (!Object.op_Implicit((Object)(object)Chat.instance) || !Chat.instance.HasFocus()) && !Console.IsVisible() && !TextInput.IsVisible() && !StoreGui.IsVisible() && !Menu.IsVisible() && (!Object.op_Implicit((Object)(object)TextViewer.instance) || !TextViewer.instance.IsVisible()) && !Minimap.IsOpen() && !GameCamera.InFreeFly() && !PlayerCustomizaton.IsBarberGuiVisible();
		if (((Character)Player.m_localPlayer).IsDead() || ((Character)Player.m_localPlayer).InCutscene() || ((Character)Player.m_localPlayer).IsTeleporting())
		{
			result = false;
		}
		return result;
	}

	public static void UpdateTransmog(ItemCategory itemCategory, string itemName, int itemVariant, bool? hidden = null, Sprite sprite = null)
	{
		TransmogItems[itemCategory].ItemName = itemName;
		TransmogItems[itemCategory].ItemVariant = itemVariant;
		if (hidden.HasValue)
		{
			TransmogItems[itemCategory].Hidden = hidden.Value;
		}
		TransmogUI.UpdateItemGrid(itemCategory, sprite ?? TransmogUI.GetItemIcon(itemName));
		((Humanoid)Player.m_localPlayer).SetupVisEquipment(((Humanoid)Player.m_localPlayer).m_visEquipment, false);
		SaveData();
	}

	public static void UpdateTransmog(ItemCategory itemCategory, bool hidden)
	{
		TransmogItems[itemCategory].Hidden = hidden;
		((Humanoid)Player.m_localPlayer).SetupVisEquipment(((Humanoid)Player.m_localPlayer).m_visEquipment, false);
		SaveData();
	}
}
public class TransmogUI
{
	public class ItemGridProperties
	{
		public Image Image;

		public Toggle Toggle;

		public ItemGridProperties(Image image, Toggle toggle)
		{
			Image = image;
			Toggle = toggle;
		}
	}

	public static readonly Dictionary<string, Vector2> Anchors = new Dictionary<string, Vector2>
	{
		{
			"Upper-left",
			new Vector2(0f, 1f)
		},
		{
			"Upper-mid",
			new Vector2(0.5f, 1f)
		},
		{
			"Upper-right",
			new Vector2(1f, 1f)
		},
		{
			"Middle-left",
			new Vector2(0f, 0.5f)
		},
		{
			"Middle-center",
			new Vector2(0.5f, 0.5f)
		},
		{
			"Middle-right",
			new Vector2(1f, 0.5f)
		},
		{
			"Lower-left",
			new Vector2(0f, 0f)
		},
		{
			"Lower-center",
			new Vector2(0.5f, 0f)
		},
		{
			"Lower-right",
			new Vector2(1f, 0f)
		}
	};

	private static Dictionary<ItemCategory, ItemGridProperties> ItemGrid;

	public static Sprite DefaultItemIcon;

	public static GameObject Panel;

	public static void Awake()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		Scene scene = GUIManager.CustomGUIBack.scene;
		if (!(((Scene)(ref scene)).name != "main"))
		{
			BuildMenu();
		}
	}

	public static void OpenMenu()
	{
		GameObject panel = Panel;
		if (panel != null)
		{
			panel.SetActive(true);
		}
	}

	public static void CloseMenu()
	{
		GameObject panel = Panel;
		if (panel != null)
		{
			panel.SetActive(false);
		}
	}

	public static void ToggleMenu()
	{
		if (!((Object)(object)Panel == (Object)null))
		{
			if (!Panel.activeSelf)
			{
				OpenMenu();
			}
			else
			{
				CloseMenu();
			}
		}
	}

	public static void UpdateItemGrid()
	{
		foreach (KeyValuePair<ItemCategory, ItemGridProperties> item in ItemGrid)
		{
			TransmogItem transmogItem = Transmog.TransmogItems[item.Key];
			item.Value.Image.sprite = GetItemIcon(transmogItem.ItemName) ?? DefaultItemIcon;
			if ((Object)(object)item.Value.Toggle != (Object)null)
			{
				item.Value.Toggle.isOn = transmogItem.Hidden;
			}
		}
	}

	public static void UpdateItemGrid(ItemCategory itemCategory, Sprite sprite, bool hidden = false)
	{
		ItemGrid[itemCategory].Image.sprite = sprite;
		if ((Object)(object)ItemGrid[itemCategory].Toggle != (Object)null)
		{
			ItemGrid[itemCategory].Toggle.isOn = hidden;
		}
	}

	public static Sprite GetItemIcon(string prefab)
	{
		Sprite val = null;
		if (!string.IsNullOrEmpty(prefab))
		{
			GameObject prefab2 = ZNetScene.instance.GetPrefab(prefab);
			if ((Object)(object)prefab2 != (Object)null)
			{
				ItemDrop component = prefab2.GetComponent<ItemDrop>();
				if ((Object)(object)component != (Object)null)
				{
					val = component.m_itemData.GetIcon();
				}
			}
		}
		return val ?? DefaultItemIcon;
	}

	private static void ResetItem(ItemCategory itemCategory)
	{
		Transmog.UpdateTransmog(itemCategory, string.Empty, 0);
	}

	private static void HideItem(ItemCategory itemCategory)
	{
		Transmog.UpdateTransmog(itemCategory, ItemGrid[itemCategory].Toggle.isOn);
	}

	private static Image CreateItemFrame(ItemCategory itemCategory, Sprite sprite, Transform parent, Vector2 anchorMin, Vector2 anchorMax, Vector2 pivot, Vector2 position, Color color, float width, float height)
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Expected O, but got Unknown
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Expected O, but got Unknown
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("Image", new Type[2]
		{
			typeof(RectTransform),
			typeof(Image)
		});
		RectTransform component = val.GetComponent<RectTransform>();
		component.anchorMin = anchorMin;
		component.anchorMax = anchorMax;
		component.pivot = pivot;
		component.SetSizeWithCurrentAnchors((Axis)0, width);
		component.SetSizeWithCurrentAnchors((Axis)1, height);
		Image component2 = val.GetComponent<Image>();
		component2.sprite = sprite;
		((Graphic)component2).color = color;
		Button val2 = val.AddComponent<Button>();
		((UnityEvent)val2.onClick).AddListener((UnityAction)delegate
		{
			ResetItem(itemCategory);
		});
		val.transform.SetParent(Panel.transform);
		component.anchoredPosition = position;
		return component2;
	}

	private static void BuildMenu()
	{
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: 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_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_015d: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_017b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_021d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0227: Expected O, but got Unknown
		//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02af: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02da: Unknown result type (might be due to invalid IL or missing references)
		//IL_030a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0319: Unknown result type (might be due to invalid IL or missing references)
		//IL_0328: Unknown result type (might be due to invalid IL or missing references)
		//IL_0332: 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_0385: Unknown result type (might be due to invalid IL or missing references)
		//IL_0394: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cd: 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_03e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0409: Unknown result type (might be due to invalid IL or missing references)
		//IL_0467: Unknown result type (might be due to invalid IL or missing references)
		//IL_047e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0495: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0500: Unknown result type (might be due to invalid IL or missing references)
		//IL_0525: Unknown result type (might be due to invalid IL or missing references)
		//IL_0536: Unknown result type (might be due to invalid IL or missing references)
		//IL_053c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0561: Unknown result type (might be due to invalid IL or missing references)
		DefaultItemIcon = GetItemIcon("Wisp");
		float num = 768f;
		float num2 = 740f;
		float num3 = 24f;
		Panel = GUIManager.Instance.CreateWoodpanel(GUIManager.CustomGUIFront.transform, Anchors[Configs.PanelStartingAnchor.Value], Anchors[Configs.PanelStartingAnchor.Value], Configs.PanelStartingPosition.Value, num, num2, true);
		((RectTransform)Panel.transform).pivot = Anchors[Configs.PanelStartingAnchor.Value];
		GameObject val = GUIManager.Instance.CreateText("Transmogrification", Panel.transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, 0f - num3), GUIManager.Instance.AveriaSerifBold, 24, GUIManager.Instance.ValheimOrange, true, Color.black, num - num3 * 2f, 100f, false);
		val.GetComponent<RectTransform>().pivot = new Vector2(0.5f, 1f);
		val.GetComponent<Text>().alignment = (TextAnchor)1;
		GameObject val2 = GUIManager.Instance.CreateText("- Click on an item in your inventory to copy its appearance to all other items of the same type.\n- Click on an item on the transmog panel to revert the apperace of all items of that type.\n- You can optionally hide an item type, such as your helmet.", Panel.transform, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(num3, num3 - 96f), GUIManager.Instance.AveriaSerif, 16, Color.white, false, Color.black, num - num3 * 2f, 64f, false);
		val2.GetComponent<RectTransform>().pivot = new Vector2(0f, 1f);
		GameObject val3 = GUIManager.Instance.CreateButton("X", Panel.transform, new Vector2(1f, 1f), new Vector2(1f, 1f), new Vector2(-25f, -25f), 40f, 40f);
		((UnityEvent)val3.GetComponent<Button>().onClick).AddListener(new UnityAction(CloseMenu));
		float num4 = 64f;
		float num5 = 64f;
		float num6 = 240f;
		float num7 = 96f;
		float num8 = num3;
		float num9 = num3 + 140f;
		ItemGrid = new Dictionary<ItemCategory, ItemGridProperties>();
		foreach (KeyValuePair<ItemCategory, TransmogItem> transmogItem in Transmog.TransmogItems)
		{
			GameObject val4 = GUIManager.Instance.CreateButton(string.Empty, Panel.transform, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(num8, 0f - num9), num4, num5);
			val4.GetComponent<RectTransform>().pivot = new Vector2(0f, 1f);
			Image image = CreateItemFrame(transmogItem.Key, DefaultItemIcon, Panel.transform, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(num8, 0f - num9), new Color(1f, 1f, 1f, 0.75f), num4, num5);
			GameObject val5 = GUIManager.Instance.CreateText(transmogItem.Value.ItemLabel, Panel.transform, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(num8 + num4 + 8f, 0f - num9 - 8f - ((!transmogItem.Value.CanBeHidden) ? 14f : 0f)), GUIManager.Instance.AveriaSerif, 16, Color.white, false, Color.black, num6, 32f, false);
			val5.GetComponent<RectTransform>().pivot = new Vector2(0f, 1f);
			Toggle val6 = null;
			if (transmogItem.Value.CanBeHidden)
			{
				GameObject val7 = GUIManager.Instance.CreateToggle(Panel.transform, 20f, 20f);
				RectTransform component = val7.GetComponent<RectTransform>();
				component.anchorMin = new Vector2(0f, 1f);
				component.anchorMax = new Vector2(0f, 1f);
				component.pivot = new Vector2(0f, 1f);
				component.anchoredPosition = new Vector2(num8 + num4 + 8f, 0f - num9 - 34f);
				val6 = val7.GetComponent<Toggle>();
				val6.isOn = false;
				GameObject val8 = GUIManager.Instance.CreateText("Hide Item", Panel.transform, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(num8 + num4 + 8f + 28f, 0f - num9 - 34f - 1f), GUIManager.Instance.AveriaSerif, 16, Color.white, false, Color.black, num6, 32f, false);
				val8.GetComponent<RectTransform>().pivot = new Vector2(0f, 1f);
			}
			num8 += num6;
			if (num8 + num6 + num3 > num)
			{
				num9 += num7;
				num8 = num3;
			}
			ItemGrid.Add(transmogItem.Key, new ItemGridProperties(image, val6));
			((UnityEvent<bool>)(object)val6?.onValueChanged).AddListener((UnityAction<bool>)delegate
			{
				HideItem(transmogItem.Key);
			});
		}
		Panel.SetActive(false);
	}
}