Decompiled source of Glamour v0.1.1

Glamour.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace Glamour;

[BepInPlugin("j1ga.glamour", "Glamour", "0.1.1")]
public class GlamourPlugin : BaseUnityPlugin
{
	private sealed class Outfit
	{
		public ItemData Left;

		public ItemData Right;

		public ItemData LeftBack;

		public ItemData RightBack;

		public ItemData Chest;

		public ItemData Legs;

		public ItemData Helmet;

		public ItemData Shoulder;

		public ItemData Utility;

		public ItemData Trinket;
	}

	[HarmonyPatch(typeof(Humanoid), "SetupVisEquipment")]
	private static class Humanoid_SetupVisEquipment_Patch
	{
		private static void Prefix(Humanoid __instance, out Outfit __state, ItemData ___m_leftItem, ItemData ___m_rightItem, ItemData ___m_hiddenLeftItem, ItemData ___m_hiddenRightItem, ItemData ___m_chestItem, ItemData ___m_legItem, ItemData ___m_helmetItem, ItemData ___m_shoulderItem, ItemData ___m_utilityItem, ItemData ___m_trinketItem)
		{
			__state = _dressing;
			Player val = (Player)(object)((__instance is Player) ? __instance : null);
			if (!_enabled.Value || (Object)(object)val == (Object)null || ((Object)(object)Player.m_localPlayer != (Object)null && !object.ReferenceEquals(val, Player.m_localPlayer)))
			{
				_dressing = null;
				return;
			}
			Outfit outfit = new Outfit();
			outfit.Left = ___m_leftItem;
			outfit.Right = ___m_rightItem;
			outfit.LeftBack = ___m_hiddenLeftItem;
			outfit.RightBack = ___m_hiddenRightItem;
			outfit.Chest = ___m_chestItem;
			outfit.Legs = ___m_legItem;
			outfit.Helmet = ___m_helmetItem;
			outfit.Shoulder = ___m_shoulderItem;
			outfit.Utility = ___m_utilityItem;
			outfit.Trinket = ___m_trinketItem;
			_dressing = outfit;
		}

		private static Exception Finalizer(Exception __exception, Outfit __state)
		{
			_dressing = __state;
			return __exception;
		}
	}

	[HarmonyPatch(typeof(VisEquipment), "SetLeftItem")]
	private static class VisEquipment_SetLeftItem_Patch
	{
		private static void Prefix(ref int __0, ref int __1)
		{
			if (_dressing != null)
			{
				Swap(_dressing.Left, ref __0, ref __1);
			}
		}
	}

	[HarmonyPatch(typeof(VisEquipment), "SetRightItem")]
	private static class VisEquipment_SetRightItem_Patch
	{
		private static void Prefix(ref int __0)
		{
			if (_dressing != null)
			{
				Swap(_dressing.Right, ref __0);
			}
		}
	}

	[HarmonyPatch(typeof(VisEquipment), "SetLeftBackItem")]
	private static class VisEquipment_SetLeftBackItem_Patch
	{
		private static void Prefix(ref int __0, ref int __1)
		{
			if (_dressing != null)
			{
				Swap(_dressing.LeftBack, ref __0, ref __1);
			}
		}
	}

	[HarmonyPatch(typeof(VisEquipment), "SetRightBackItem")]
	private static class VisEquipment_SetRightBackItem_Patch
	{
		private static void Prefix(ref int __0)
		{
			if (_dressing != null)
			{
				Swap(_dressing.RightBack, ref __0);
			}
		}
	}

	[HarmonyPatch(typeof(VisEquipment), "SetChestItem")]
	private static class VisEquipment_SetChestItem_Patch
	{
		private static void Prefix(ref int __0)
		{
			if (_dressing != null)
			{
				Swap(_dressing.Chest, ref __0);
			}
		}
	}

	[HarmonyPatch(typeof(VisEquipment), "SetLegItem")]
	private static class VisEquipment_SetLegItem_Patch
	{
		private static void Prefix(ref int __0)
		{
			if (_dressing != null)
			{
				Swap(_dressing.Legs, ref __0);
			}
		}
	}

	[HarmonyPatch(typeof(VisEquipment), "SetHelmetItem")]
	private static class VisEquipment_SetHelmetItem_Patch
	{
		private static void Prefix(ref int __0)
		{
			if (_dressing != null)
			{
				Swap(_dressing.Helmet, ref __0);
			}
		}
	}

	[HarmonyPatch(typeof(VisEquipment), "SetShoulderItem")]
	private static class VisEquipment_SetShoulderItem_Patch
	{
		private static void Prefix(ref int __0, ref int __1)
		{
			if (_dressing != null)
			{
				Swap(_dressing.Shoulder, ref __0, ref __1);
			}
		}
	}

	[HarmonyPatch(typeof(VisEquipment), "SetUtilityItem")]
	private static class VisEquipment_SetUtilityItem_Patch
	{
		private static void Prefix(ref int __0)
		{
			if (_dressing != null)
			{
				Swap(_dressing.Utility, ref __0);
			}
		}
	}

	[HarmonyPatch(typeof(VisEquipment), "SetTrinketItem")]
	private static class VisEquipment_SetTrinketItem_Patch
	{
		private static void Prefix(ref string __0)
		{
			if (_dressing != null && _dressing.Trinket != null && Resolve(_dressing.Trinket, out var prefab, out var _))
			{
				__0 = prefab;
			}
		}
	}

	[HarmonyPatch]
	private static class ItemData_GetTooltip_Patch
	{
		private static MethodBase TargetMethod()
		{
			MethodInfo[] methods = typeof(ItemData).GetMethods(BindingFlags.Static | BindingFlags.Public);
			foreach (MethodInfo methodInfo in methods)
			{
				if (!(methodInfo.Name != "GetTooltip") && !(methodInfo.ReturnType != typeof(string)))
				{
					ParameterInfo[] parameters = methodInfo.GetParameters();
					if (parameters.Length > 0 && parameters[0].ParameterType == typeof(ItemData))
					{
						return methodInfo;
					}
				}
			}
			return null;
		}

		private static void Postfix(ItemData item, ref string __result)
		{
			if (_tooltip.Value && item != null)
			{
				string text = LookName(GetLook(item));
				if (text != null)
				{
					string text2 = (_enabled.Value ? "" : " (Glamour is off)");
					string text3 = __result;
					__result = text3 + "\n\n<color=#C9A0FF>Look: " + text + text2 + "</color>";
				}
			}
		}
	}

	public enum LookSource
	{
		Found,
		All
	}

	public enum ButtonPlace
	{
		Minimap,
		Inventory
	}

	private sealed class LookEntry
	{
		public string Value;

		public string Name;

		public Sprite Icon;

		public bool Dim;
	}

	private sealed class DragHandle : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler, IEventSystemHandler
	{
		public GlamourPlugin Owner;

		private Vector2 _start;

		public void OnBeginDrag(PointerEventData e)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			_start = ((RectTransform)((Component)this).transform).anchoredPosition;
		}

		public void OnDrag(PointerEventData e)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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_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)
			Canvas componentInParent = ((Component)this).GetComponentInParent<Canvas>();
			float num = (((Object)(object)componentInParent != (Object)null && componentInParent.scaleFactor > 0f) ? componentInParent.scaleFactor : 1f);
			RectTransform val = (RectTransform)((Component)this).transform;
			val.anchoredPosition += e.delta / num;
		}

		public void OnEndDrag(PointerEventData e)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: 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_002a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Owner != (Object)null)
			{
				Owner.SavePanelOffset(((RectTransform)((Component)this).transform).anchoredPosition - _start);
			}
		}
	}

	public const string Guid = "j1ga.glamour";

	public const string Name = "Glamour";

	public const string Version = "0.1.1";

	private const string DataKey = "j1ga.glamour";

	private const string HiddenValue = "-";

	private const int GridColumns = 8;

	private const int GridRows = 4;

	private const float Pad = 14f;

	private static GlamourPlugin _instance;

	private static ConfigEntry<bool> _enabled;

	private static ConfigEntry<bool> _weapons;

	private static ConfigEntry<bool> _tooltip;

	private static Outfit _dressing;

	private static readonly FieldInfo _visEquipmentField = AccessTools.Field(typeof(Humanoid), "m_visEquipment");

	private static readonly MethodInfo _setupVisEquipment = AccessTools.Method(typeof(Humanoid), "SetupVisEquipment", (Type[])null, (Type[])null);

	private readonly HashSet<string> _loggedErrors = new HashSet<string>();

	private Harmony _harmony;

	private static ConfigEntry<LookSource> _cfgLooks;

	private static ConfigEntry<ButtonPlace> _cfgButtonPlace;

	private static ConfigEntry<Vector2> _cfgButtonOffset;

	private static ConfigEntry<Vector2> _cfgPanelOffset;

	private static ConfigEntry<bool> _cfgAllOfKind;

	private InventoryGui _uiGui;

	private RectTransform _button;

	private RectTransform _panel;

	private RectTransform _slotRow;

	private RectTransform _gridContent;

	private ScrollRect _scroll;

	private TextMeshProUGUI _infoText;

	private TextMeshProUGUI _hintText;

	private bool _panelOpen;

	private float _cell = 70f;

	private ItemData _selected;

	private readonly List<ItemData> _slotItems = new List<ItemData>();

	private readonly List<ItemData> _shownSlots = new List<ItemData>();

	private readonly List<string> _shownLooks = new List<string>();

	private static readonly ItemType[] ArmorSlots = (ItemType[])(object)new ItemType[6]
	{
		(ItemType)6,
		(ItemType)7,
		(ItemType)11,
		(ItemType)17,
		(ItemType)18,
		(ItemType)24
	};

	private void Awake()
	{
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Expected O, but got Unknown
		_instance = this;
		_enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("01 General", "Enabled", true, "Off: every item shows its own look again (the looks stay saved in the items).");
		_weapons = ((BaseUnityPlugin)this).Config.Bind<bool>("01 General", "Weapons", true, "Weapons, shields, torches and tools can take a look too (of the same kind and grip only).");
		_tooltip = ((BaseUnityPlugin)this).Config.Bind<bool>("01 General", "Tooltip", true, "The item tooltip says which look the item wears.");
		_enabled.SettingChanged += delegate
		{
			Refresh();
		};
		_weapons.SettingChanged += delegate
		{
			Refresh();
		};
		BindUiConfig();
		_harmony = new Harmony("j1ga.glamour");
		_harmony.PatchAll(typeof(GlamourPlugin).Assembly);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Glamour 0.1.1 loaded.");
	}

	private void OnDestroy()
	{
		if (_harmony != null)
		{
			_harmony.UnpatchSelf();
		}
		DestroyUi();
	}

	private void Update()
	{
		try
		{
			UpdateUi();
		}
		catch (Exception e)
		{
			Fail("Update", e);
		}
	}

	private static string WhyNot(ItemData item, SharedData look)
	{
		//IL_0008: 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_002f: 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_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Invalid comparison between Unknown and I4
		SharedData shared = item.m_shared;
		if (!HasLookSlot(shared.m_itemType) || (Object)(object)item.m_dropPrefab == (Object)null)
		{
			return "cannot take a look";
		}
		if (shared.m_itemType != look.m_itemType)
		{
			return "a different kind of item";
		}
		if (IsHand(shared.m_itemType))
		{
			if (!_weapons.Value)
			{
				return "looks for weapons are off (Weapons in the config)";
			}
			if (shared.m_animationState != look.m_animationState)
			{
				return "held differently";
			}
			if ((int)shared.m_animationState == 9)
			{
				return "fishing rods keep their own look";
			}
		}
		return null;
	}

	private static bool HasLookSlot(ItemType type)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Invalid comparison between Unknown and I4
		//IL_001e: 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_002f: Expected I4, but got Unknown
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Expected I4, but got Unknown
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Invalid comparison between Unknown and I4
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Invalid comparison between Unknown and I4
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		if ((int)type <= 11)
		{
			switch (type - 6)
			{
			case 0:
			case 1:
				goto IL_0034;
			}
			if ((int)type == 11)
			{
				goto IL_0034;
			}
		}
		else
		{
			switch (type - 17)
			{
			case 0:
			case 1:
				goto IL_0034;
			}
			if ((int)type == 24)
			{
				goto IL_0034;
			}
		}
		return IsHand(type);
		IL_0034:
		return true;
	}

	private static bool IsHand(ItemType type)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Invalid comparison between Unknown and I4
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Invalid comparison between Unknown and I4
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Expected I4, but got Unknown
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Invalid comparison between Unknown and I4
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Expected I4, but got Unknown
		if ((int)type <= 15)
		{
			switch (type - 3)
			{
			case 0:
			case 1:
			case 2:
				goto IL_0038;
			}
			switch (type - 14)
			{
			case 0:
			case 1:
				break;
			default:
				goto IL_003a;
			}
		}
		else if ((int)type != 19 && (int)type != 22)
		{
			goto IL_003a;
		}
		goto IL_0038;
		IL_0038:
		return true;
		IL_003a:
		return false;
	}

	private static bool CanHide(ItemType type)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Invalid comparison between Unknown and I4
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Invalid comparison between Unknown and I4
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Invalid comparison between Unknown and I4
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Invalid comparison between Unknown and I4
		if ((int)type != 6 && (int)type != 17 && (int)type != 18)
		{
			return (int)type == 24;
		}
		return true;
	}

	private static string GetLook(ItemData item)
	{
		if (item == null || item.m_customData == null)
		{
			return null;
		}
		if (!item.m_customData.TryGetValue("j1ga.glamour", out var value) || string.IsNullOrEmpty(value))
		{
			return null;
		}
		return value;
	}

	private static void SetLook(ItemData item, string value)
	{
		if (StoreLook(item, value))
		{
			Refresh();
		}
	}

	private static bool StoreLook(ItemData item, string value)
	{
		if (item.m_customData == null)
		{
			item.m_customData = new Dictionary<string, string>();
		}
		if (value == null)
		{
			item.m_customData.Remove("j1ga.glamour");
		}
		else
		{
			item.m_customData["j1ga.glamour"] = value;
		}
		return item.m_equipped;
	}

	private static string OwnValue(ItemData item)
	{
		if ((Object)(object)item.m_dropPrefab == (Object)null)
		{
			return null;
		}
		return LookValue(((Object)item.m_dropPrefab).name, (item.m_shared.m_variants > 1) ? item.m_variant : (-1));
	}

	private static bool SameKind(ItemData a, ItemData b)
	{
		//IL_002c: 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_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: 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_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Invalid comparison between Unknown and I4
		if (a == null || b == null || (Object)(object)a.m_dropPrefab == (Object)null || a.m_shared == null || b.m_shared == null)
		{
			return false;
		}
		ItemType itemType = a.m_shared.m_itemType;
		if (itemType != b.m_shared.m_itemType || !HasLookSlot(itemType))
		{
			return false;
		}
		if (!IsHand(itemType))
		{
			return true;
		}
		if (a.m_shared.m_animationState == b.m_shared.m_animationState)
		{
			return (int)a.m_shared.m_animationState != 9;
		}
		return false;
	}

	private static string LookValue(string prefab, int variant)
	{
		if (variant < 0)
		{
			return prefab;
		}
		return prefab + "|" + variant;
	}

	private static void ParseLook(string value, out string prefab, out int variant)
	{
		variant = -1;
		int num = value.IndexOf('|');
		if (num < 0)
		{
			prefab = value;
			return;
		}
		prefab = value.Substring(0, num);
		if (int.TryParse(value.Substring(num + 1), out var result))
		{
			variant = result;
		}
	}

	private static bool Resolve(ItemData item, out string prefab, out int variant)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		prefab = null;
		variant = -1;
		string look = GetLook(item);
		if (look == null)
		{
			return false;
		}
		ItemType itemType = item.m_shared.m_itemType;
		if (IsHand(itemType) && !_weapons.Value)
		{
			return false;
		}
		if (look == "-")
		{
			if (!CanHide(itemType))
			{
				return false;
			}
			prefab = "";
			return true;
		}
		ParseLook(look, out prefab, out variant);
		if ((Object)(object)ObjectDB.instance == (Object)null || (Object)(object)ObjectDB.instance.GetItemPrefab(prefab) == (Object)null)
		{
			return false;
		}
		return true;
	}

	private static string LookName(string value)
	{
		if (value == null)
		{
			return null;
		}
		if (value == "-")
		{
			return "hidden";
		}
		ParseLook(value, out var prefab, out var variant);
		GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab(prefab) : null);
		ItemDrop val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<ItemDrop>() : null);
		if ((Object)(object)val2 == (Object)null)
		{
			return prefab + " (missing)";
		}
		string text = Localize(val2.m_itemData.m_shared.m_name);
		if (variant >= 0 && val2.m_itemData.m_shared.m_variants > 1)
		{
			object obj = text;
			text = string.Concat(obj, " (style ", variant + 1, ")");
		}
		return text;
	}

	private static void Refresh()
	{
		try
		{
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null) && !(_visEquipmentField == null) && !(_setupVisEquipment == null))
			{
				object? value = _visEquipmentField.GetValue(localPlayer);
				VisEquipment val = (VisEquipment)((value is VisEquipment) ? value : null);
				if (!((Object)(object)val == (Object)null))
				{
					_setupVisEquipment.Invoke(localPlayer, new object[2] { val, false });
				}
			}
		}
		catch (Exception e)
		{
			if ((Object)(object)_instance != (Object)null)
			{
				_instance.Fail("Refresh", e);
			}
		}
	}

	private static string Localize(string text)
	{
		if (Localization.instance == null)
		{
			return text;
		}
		return Localization.instance.Localize(text);
	}

	private static string ItemName(ItemData item)
	{
		return Localize(item.m_shared.m_name);
	}

	private void Fail(string where, Exception e)
	{
		string text = where + ": " + e.GetType().Name + ": " + e.Message;
		if (_loggedErrors.Add(text))
		{
			((BaseUnityPlugin)this).Logger.LogError((object)(text + "\n" + e.StackTrace));
		}
	}

	private static void Swap(ItemData item, ref int itemHash)
	{
		if (item != null && Resolve(item, out var prefab, out var _))
		{
			itemHash = ((prefab.Length != 0) ? StringExtensionMethods.GetStableHashCode(prefab) : 0);
		}
	}

	private static void Swap(ItemData item, ref int itemHash, ref int itemVariant)
	{
		if (item != null && Resolve(item, out var prefab, out var variant))
		{
			itemHash = ((prefab.Length != 0) ? StringExtensionMethods.GetStableHashCode(prefab) : 0);
			itemVariant = ((variant >= 0) ? variant : 0);
		}
	}

	private void BindUiConfig()
	{
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		_cfgLooks = ((BaseUnityPlugin)this).Config.Bind<LookSource>("02 Panel", "Looks", LookSource.Found, "Found: the looks of items you have picked up at least once (or carry). All: every item of the kind in the game.");
		_cfgButtonPlace = ((BaseUnityPlugin)this).Config.Bind<ButtonPlace>("02 Panel", "ButtonPlace", ButtonPlace.Minimap, "Where the Glamour button sits while the inventory is open. Minimap: at the top of the screen, left of the minimap. Inventory: beside the inventory panel's top right corner.");
		_cfgButtonOffset = ((BaseUnityPlugin)this).Config.Bind<Vector2>("02 Panel", "ButtonOffset", new Vector2(0f, 0f), "Moves the Glamour button from that place, in pixels (x right, y up).");
		_cfgPanelOffset = ((BaseUnityPlugin)this).Config.Bind<Vector2>("02 Panel", "PanelOffset", new Vector2(0f, 0f), "Where the window opens, relative to its place beside the inventory. Dragging the window sets it.");
		_cfgAllOfKind = ((BaseUnityPlugin)this).Config.Bind<bool>("02 Panel", "ApplyToAllOfKind", false, "On: a look chosen for an item goes onto every item of the same kind you carry (the same slot; weapons, shields, torches and tools also the same grip). Own look and Hidden too.");
		_cfgLooks.SettingChanged += delegate
		{
			if ((Object)(object)_instance != (Object)null)
			{
				_instance.RebuildLooks();
			}
		};
		_cfgAllOfKind.SettingChanged += delegate
		{
			if ((Object)(object)_instance != (Object)null)
			{
				_instance.RebuildLooks();
			}
		};
		_cfgButtonOffset.SettingChanged += delegate
		{
			if ((Object)(object)_instance != (Object)null)
			{
				_instance.PlaceButton();
			}
		};
		_cfgButtonPlace.SettingChanged += delegate
		{
			if ((Object)(object)_instance != (Object)null)
			{
				_instance.PlaceButton();
			}
		};
	}

	private void DestroyUi()
	{
		if ((Object)(object)_button != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)_button).gameObject);
		}
		if ((Object)(object)_panel != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)_panel).gameObject);
		}
		_button = null;
		_panel = null;
		_uiGui = null;
	}

	private void UpdateUi()
	{
		if (!InventoryGui.IsVisible() || (Object)(object)Player.m_localPlayer == (Object)null || !EnsureUi())
		{
			return;
		}
		if (((Component)_panel).gameObject.activeSelf != _panelOpen)
		{
			((Component)_panel).gameObject.SetActive(_panelOpen);
		}
		if (_panelOpen)
		{
			CollectSlots(_slotItems);
			if (!SameItems(_slotItems, _shownSlots))
			{
				RebuildAll();
			}
		}
	}

	private void TogglePanel()
	{
		_panelOpen = !_panelOpen;
		if (!((Object)(object)_panel == (Object)null))
		{
			((Component)_panel).gameObject.SetActive(_panelOpen);
			if (_panelOpen)
			{
				PlacePanel();
				((Transform)_panel).SetAsLastSibling();
				RebuildAll();
			}
		}
	}

	private static void CollectSlots(List<ItemData> into)
	{
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		into.Clear();
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null || ((Humanoid)localPlayer).GetInventory() == null)
		{
			return;
		}
		List<ItemData> equippedItems = ((Humanoid)localPlayer).GetInventory().GetEquippedItems();
		ItemType[] armorSlots = ArmorSlots;
		foreach (ItemType val in armorSlots)
		{
			ItemData item = null;
			foreach (ItemData item2 in equippedItems)
			{
				if (item2.m_shared.m_itemType == val)
				{
					item = item2;
					break;
				}
			}
			into.Add(item);
		}
		foreach (ItemData item3 in equippedItems)
		{
			if (IsHand(item3.m_shared.m_itemType) && (Object)(object)item3.m_dropPrefab != (Object)null)
			{
				into.Add(item3);
			}
		}
	}

	private static bool SameItems(List<ItemData> a, List<ItemData> b)
	{
		if (a.Count != b.Count)
		{
			return false;
		}
		for (int i = 0; i < a.Count; i++)
		{
			if (!object.ReferenceEquals(a[i], b[i]))
			{
				return false;
			}
		}
		return true;
	}

	private void RebuildAll()
	{
		CollectSlots(_slotItems);
		if (_selected == null || !_slotItems.Contains(_selected) || !_selected.m_equipped)
		{
			_selected = null;
			foreach (ItemData slotItem in _slotItems)
			{
				if (slotItem != null)
				{
					_selected = slotItem;
					break;
				}
			}
		}
		RebuildSlots();
		RebuildLooks();
	}

	private void RebuildSlots()
	{
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Expected O, but got Unknown
		_shownSlots.Clear();
		_shownSlots.AddRange(_slotItems);
		if ((Object)(object)_slotRow == (Object)null)
		{
			return;
		}
		Clear((Transform)(object)_slotRow);
		for (int i = 0; i < _slotItems.Count; i++)
		{
			ItemData val = _slotItems[i];
			InventoryElement val2 = MakeCell(_slotRow, new Vector2((float)i * _cell, 0f));
			if ((Object)(object)val2 == (Object)null)
			{
				continue;
			}
			if (val == null)
			{
				SetIcon(val2, null, dim: false);
				((Selectable)val2.m_button).interactable = false;
				continue;
			}
			string look = GetLook(val);
			Sprite icon = val.GetIcon();
			bool dim = false;
			if (look == "-")
			{
				dim = true;
			}
			else if (look != null)
			{
				Sprite val3 = LookIcon(look);
				if ((Object)(object)val3 != (Object)null)
				{
					icon = val3;
				}
			}
			SetIcon(val2, icon, dim);
			SetShown(val2.m_selected, object.ReferenceEquals(val, _selected));
			string text = ((look != null) ? ("Looks like: " + LookName(look)) : "Own look");
			SetTooltip(val2, ItemName(val), text);
			ItemData captured = val;
			((UnityEvent)val2.m_button.onClick).AddListener((UnityAction)delegate
			{
				_selected = captured;
				RebuildSlots();
				RebuildLooks();
			});
		}
	}

	private void RebuildLooks()
	{
		//IL_010d: 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_01d2: Expected O, but got Unknown
		_shownLooks.Clear();
		if ((Object)(object)_gridContent == (Object)null)
		{
			return;
		}
		Clear((Transform)(object)_gridContent);
		ItemData selected = _selected;
		if (selected == null)
		{
			((TMP_Text)_infoText).text = "Equip an armor piece or a weapon to give it a look.";
			SetGridHeight(0);
			return;
		}
		string look = GetLook(selected);
		((TMP_Text)_infoText).text = "<b>" + ItemName(selected) + "</b>   " + ((look != null) ? ("looks like " + LookName(look)) : "own look");
		((TMP_Text)_hintText).text = ((_cfgLooks.Value == LookSource.All) ? "All items of this kind. Stats stay the item's own." : "Looks of items you have found. Stats stay the item's own.") + (_cfgAllOfKind.Value ? " A click dresses every item of this kind you carry." : "");
		List<LookEntry> list = Looks(selected);
		for (int i = 0; i < list.Count; i++)
		{
			LookEntry lookEntry = list[i];
			InventoryElement val = MakeCell(_gridContent, new Vector2((float)(i % 8) * _cell, (float)(-(i / 8)) * _cell));
			if (!((Object)(object)val == (Object)null))
			{
				SetIcon(val, lookEntry.Icon, lookEntry.Dim);
				SetShown(val.m_selected, lookEntry.Value == look);
				SetTooltip(val, lookEntry.Name, (lookEntry.Value == null) ? "The item's own look." : ((lookEntry.Value == "-") ? "Not shown on the character." : "Click to wear this look."));
				_shownLooks.Add(lookEntry.Value);
				LookEntry captured = lookEntry;
				ItemData target = selected;
				((UnityEvent)val.m_button.onClick).AddListener((UnityAction)delegate
				{
					PutOn(target, captured.Value);
					RebuildSlots();
					RebuildLooks();
				});
			}
		}
		SetGridHeight((list.Count + 8 - 1) / 8);
	}

	private static void PutOn(ItemData item, string value)
	{
		Player localPlayer = Player.m_localPlayer;
		Inventory val = (((Object)(object)localPlayer != (Object)null) ? ((Humanoid)localPlayer).GetInventory() : null);
		if (!_cfgAllOfKind.Value || val == null)
		{
			SetLook(item, value);
			return;
		}
		bool flag = false;
		foreach (ItemData allItem in val.GetAllItems())
		{
			if (object.ReferenceEquals(allItem, item) || SameKind(allItem, item))
			{
				string value2 = ((value != null && value != "-" && value == OwnValue(allItem)) ? null : value);
				if (StoreLook(allItem, value2))
				{
					flag = true;
				}
			}
		}
		if (!val.ContainsItem(item) && StoreLook(item, value))
		{
			flag = true;
		}
		if (flag)
		{
			Refresh();
		}
	}

	private static List<LookEntry> Looks(ItemData item)
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		List<LookEntry> list = new List<LookEntry>();
		LookEntry lookEntry = new LookEntry();
		lookEntry.Value = null;
		lookEntry.Name = "Own look";
		lookEntry.Icon = item.GetIcon();
		list.Add(lookEntry);
		if (CanHide(item.m_shared.m_itemType))
		{
			LookEntry lookEntry2 = new LookEntry();
			lookEntry2.Value = "-";
			lookEntry2.Name = "Hidden";
			lookEntry2.Icon = item.GetIcon();
			lookEntry2.Dim = true;
			list.Add(lookEntry2);
		}
		ObjectDB instance = ObjectDB.instance;
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)instance == (Object)null || instance.m_items == null)
		{
			return list;
		}
		HashSet<string> hashSet = new HashSet<string>();
		if ((Object)(object)localPlayer != (Object)null && ((Humanoid)localPlayer).GetInventory() != null)
		{
			foreach (ItemData allItem in ((Humanoid)localPlayer).GetInventory().GetAllItems())
			{
				if ((Object)(object)allItem.m_dropPrefab != (Object)null)
				{
					hashSet.Add(((Object)allItem.m_dropPrefab).name);
				}
			}
		}
		List<LookEntry> list2 = new List<LookEntry>();
		HashSet<string> hashSet2 = new HashSet<string>();
		string text = (((Object)(object)item.m_dropPrefab != (Object)null) ? ((Object)item.m_dropPrefab).name : "");
		foreach (GameObject item2 in instance.m_items)
		{
			if ((Object)(object)item2 == (Object)null || !hashSet2.Add(((Object)item2).name))
			{
				continue;
			}
			ItemDrop component = item2.GetComponent<ItemDrop>();
			if ((Object)(object)component == (Object)null || component.m_itemData == null)
			{
				continue;
			}
			SharedData shared = component.m_itemData.m_shared;
			if (shared == null || shared.m_icons == null || shared.m_icons.Length == 0 || WhyNot(item, shared) != null)
			{
				continue;
			}
			string text2 = Localize(shared.m_name);
			if (string.IsNullOrEmpty(text2) || text2.StartsWith("[") || (_cfgLooks.Value == LookSource.Found && !hashSet.Contains(((Object)item2).name) && ((Object)(object)localPlayer == (Object)null || !localPlayer.IsKnownMaterial(shared.m_name))))
			{
				continue;
			}
			int num = ((shared.m_variants > 1) ? Math.Min(shared.m_variants, shared.m_icons.Length) : 0);
			if (num == 0)
			{
				if (!(((Object)item2).name == text))
				{
					list2.Add(Entry(LookValue(((Object)item2).name, -1), text2, shared.m_icons[0]));
				}
				continue;
			}
			for (int i = 0; i < num; i++)
			{
				if (!(((Object)item2).name == text) || i != item.m_variant)
				{
					list2.Add(Entry(LookValue(((Object)item2).name, i), text2 + " (style " + (i + 1) + ")", shared.m_icons[i]));
				}
			}
		}
		list2.Sort((LookEntry x, LookEntry y) => string.Compare(x.Name, y.Name, StringComparison.CurrentCultureIgnoreCase));
		list.AddRange(list2);
		return list;
	}

	private static LookEntry Entry(string value, string name, Sprite icon)
	{
		LookEntry lookEntry = new LookEntry();
		lookEntry.Value = value;
		lookEntry.Name = name;
		lookEntry.Icon = icon;
		return lookEntry;
	}

	private static Sprite LookIcon(string value)
	{
		ParseLook(value, out var prefab, out var variant);
		GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab(prefab) : null);
		ItemDrop val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<ItemDrop>() : null);
		if ((Object)(object)val2 == (Object)null || val2.m_itemData.m_shared.m_icons == null || val2.m_itemData.m_shared.m_icons.Length == 0)
		{
			return null;
		}
		Sprite[] icons = val2.m_itemData.m_shared.m_icons;
		return icons[(variant >= 0 && variant < icons.Length) ? variant : 0];
	}

	private bool EnsureUi()
	{
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Expected O, but got Unknown
		//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b8: Expected O, but got Unknown
		//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ed: 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_0218: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_027c: Unknown result type (might be due to invalid IL or missing references)
		//IL_028b: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0304: Unknown result type (might be due to invalid IL or missing references)
		//IL_031a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0330: Unknown result type (might be due to invalid IL or missing references)
		//IL_0358: Unknown result type (might be due to invalid IL or missing references)
		//IL_036b: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_0405: Unknown result type (might be due to invalid IL or missing references)
		//IL_0442: Unknown result type (might be due to invalid IL or missing references)
		//IL_0454: Unknown result type (might be due to invalid IL or missing references)
		//IL_0466: Unknown result type (might be due to invalid IL or missing references)
		//IL_0505: Unknown result type (might be due to invalid IL or missing references)
		//IL_0514: Unknown result type (might be due to invalid IL or missing references)
		//IL_0548: Unknown result type (might be due to invalid IL or missing references)
		InventoryGui instance = InventoryGui.instance;
		if ((Object)(object)instance == (Object)null || (Object)(object)instance.m_player == (Object)null || (Object)(object)instance.m_inventoryRoot == (Object)null || (Object)(object)instance.m_playerGrid == (Object)null)
		{
			return false;
		}
		if ((Object)(object)instance == (Object)(object)_uiGui && (Object)(object)_button != (Object)null && (Object)(object)_panel != (Object)null)
		{
			return true;
		}
		DestroyUi();
		_uiGui = instance;
		GameObject elementPrefab = instance.m_playerGrid.m_elementPrefab;
		RectTransform val = (RectTransform)(((Object)(object)elementPrefab != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null);
		float num;
		if ((Object)(object)val != (Object)null)
		{
			Rect rect = val.rect;
			if (((Rect)(ref rect)).width > 1f)
			{
				Rect rect2 = val.rect;
				num = ((Rect)(ref rect2)).width;
				goto IL_00cd;
			}
		}
		num = 64f;
		goto IL_00cd;
		IL_00cd:
		float num2 = num;
		_cell = num2 + 6f;
		_button = MakeButton(instance, instance.m_inventoryRoot, "Glamour", TogglePanel);
		PlaceButton();
		float num3 = 28f + 8f * _cell;
		float num4 = 34f;
		float num5 = 26f;
		float num6 = 24f;
		float num7 = 14f + num4 + _cell + 8f + num5 + 4f * _cell + num6 + 14f;
		GameObject val2 = new GameObject("Glamour", new Type[2]
		{
			typeof(RectTransform),
			typeof(Image)
		});
		val2.layer = ((Component)instance.m_inventoryRoot).gameObject.layer;
		_panel = (RectTransform)val2.transform;
		((Transform)_panel).SetParent(instance.m_inventoryRoot, false);
		RectTransform panel = _panel;
		Vector2 anchorMin = (_panel.anchorMax = new Vector2(0.5f, 0.5f));
		panel.anchorMin = anchorMin;
		_panel.pivot = new Vector2(0f, 1f);
		_panel.sizeDelta = new Vector2(num3, num7);
		CopyBackground(val2.GetComponent<Image>(), instance.m_player);
		val2.AddComponent<DragHandle>().Owner = this;
		TMP_Text sample = (((Object)(object)instance.m_takeAllButton != (Object)null) ? ((Component)instance.m_takeAllButton).GetComponentInChildren<TMP_Text>(true) : null);
		TextMeshProUGUI val4 = MakeText((Transform)(object)_panel, "Title", sample, 22f, new Vector2(14f, -14f), new Vector2(num3 - 28f, num4));
		((TMP_Text)val4).text = "Glamour";
		((TMP_Text)val4).fontStyle = (FontStyles)1;
		((TMP_Text)val4).alignment = (TextAlignmentOptions)513;
		RectTransform val5 = MakeButton(instance, (Transform)(object)_panel, "X", TogglePanel);
		Vector2 anchorMin2 = (val5.anchorMax = new Vector2(1f, 1f));
		val5.anchorMin = anchorMin2;
		val5.pivot = new Vector2(1f, 1f);
		val5.sizeDelta = new Vector2(36f, 30f);
		val5.anchoredPosition = new Vector2(-10f, -10f);
		float num8 = 0f - (14f + num4);
		_slotRow = MakeRect((Transform)(object)_panel, "Slots", new Vector2(14f, num8), new Vector2(num3 - 28f, _cell));
		num8 -= _cell + 8f;
		_infoText = MakeText((Transform)(object)_panel, "Info", sample, 17f, new Vector2(14f, num8), new Vector2(num3 - 28f, num5));
		((TMP_Text)_infoText).alignment = (TextAlignmentOptions)513;
		num8 -= num5;
		RectTransform val7 = MakeRect((Transform)(object)_panel, "Looks", new Vector2(14f, num8), new Vector2(num3 - 28f, 4f * _cell));
		((Component)val7).gameObject.AddComponent<RectMask2D>();
		Image val8 = ((Component)val7).gameObject.AddComponent<Image>();
		((Graphic)val8).color = new Color(0f, 0f, 0f, 0.001f);
		_gridContent = MakeRect((Transform)(object)val7, "Content", Vector2.zero, new Vector2(num3 - 28f, 0f));
		_scroll = ((Component)val7).gameObject.AddComponent<ScrollRect>();
		_scroll.content = _gridContent;
		_scroll.viewport = val7;
		_scroll.horizontal = false;
		_scroll.movementType = (MovementType)2;
		_scroll.scrollSensitivity = _cell * 0.5f;
		num8 -= 4f * _cell;
		_hintText = MakeText((Transform)(object)_panel, "Hint", sample, 14f, new Vector2(14f, num8 - 2f), new Vector2(num3 - 28f, num6));
		((TMP_Text)_hintText).alignment = (TextAlignmentOptions)513;
		((Graphic)_hintText).color = new Color(0.8f, 0.8f, 0.76f);
		RegisterWithHudLayout(_button, _panel);
		val2.SetActive(false);
		if (_panelOpen)
		{
			val2.SetActive(true);
			PlacePanel();
			RebuildAll();
		}
		return true;
	}

	private void PlaceButton()
	{
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: 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_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: 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_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e0: 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_01e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ee: 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_01fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		//IL_019a: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_button == (Object)null || (Object)(object)_uiGui == (Object)null)
		{
			return;
		}
		if (_cfgButtonPlace.Value == ButtonPlace.Inventory)
		{
			((Transform)_button).SetParent((Transform)(object)_uiGui.m_player, false);
			RectTransform button = _button;
			Vector2 anchorMin = (_button.anchorMax = new Vector2(1f, 1f));
			button.anchorMin = anchorMin;
			_button.pivot = new Vector2(0f, 1f);
			_button.anchoredPosition = new Vector2(8f, 0f) + _cfgButtonOffset.Value;
			return;
		}
		Transform inventoryRoot = _uiGui.m_inventoryRoot;
		RectTransform val2 = (RectTransform)(object)((inventoryRoot is RectTransform) ? inventoryRoot : null);
		if (!((Object)(object)val2 == (Object)null))
		{
			((Transform)_button).SetParent((Transform)(object)val2, false);
			RectTransform button2 = _button;
			Vector2 anchorMin2 = (_button.anchorMax = new Vector2(0.5f, 0.5f));
			button2.anchorMin = anchorMin2;
			_button.pivot = new Vector2(1f, 1f);
			RectTransform val4 = (RectTransform)(((Object)(object)Minimap.instance != (Object)null && (Object)(object)Minimap.instance.m_smallRoot != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null);
			Vector2 val5 = default(Vector2);
			if ((Object)(object)val4 != (Object)null && ((Component)val4).gameObject.activeInHierarchy)
			{
				Vector3[] array = (Vector3[])(object)new Vector3[4];
				val4.GetWorldCorners(array);
				val5 = Vector2.op_Implicit(((Transform)val2).InverseTransformPoint(array[1])) + new Vector2(-12f, 0f);
			}
			else
			{
				Rect rect = val2.rect;
				float num = ((Rect)(ref rect)).xMax - 12f;
				Rect rect2 = val2.rect;
				((Vector2)(ref val5))..ctor(num, ((Rect)(ref rect2)).yMax - 12f);
			}
			RectTransform button3 = _button;
			Vector2 val6 = val5;
			Rect rect3 = val2.rect;
			button3.anchoredPosition = val6 - ((Rect)(ref rect3)).center + _cfgButtonOffset.Value;
		}
	}

	private void PlacePanel()
	{
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: 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_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_panel == (Object)null || (Object)(object)_uiGui == (Object)null)
		{
			return;
		}
		Transform parent = ((Transform)_panel).parent;
		RectTransform val = (RectTransform)(object)((parent is RectTransform) ? parent : null);
		if (!((Object)(object)val == (Object)null))
		{
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			_uiGui.m_player.GetWorldCorners(array);
			Vector2 val2 = Vector2.op_Implicit(((Transform)val).InverseTransformPoint(array[2]));
			float num = 8f;
			if (_cfgButtonPlace.Value == ButtonPlace.Inventory && (Object)(object)_button != (Object)null)
			{
				float num2 = num;
				float num3 = 8f + _cfgButtonOffset.Value.x;
				Rect rect = _button.rect;
				num = num2 + (num3 + ((Rect)(ref rect)).width);
			}
			RectTransform panel = _panel;
			Rect rect2 = val.rect;
			panel.anchoredPosition = val2 - ((Rect)(ref rect2)).center + new Vector2(num, 0f) + _cfgPanelOffset.Value;
		}
	}

	private void SetGridHeight(int rows)
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)_gridContent == (Object)null))
		{
			_gridContent.sizeDelta = new Vector2(_gridContent.sizeDelta.x, (float)rows * _cell);
			_gridContent.anchoredPosition = Vector2.zero;
		}
	}

	private InventoryElement MakeCell(RectTransform parent, Vector2 pos)
	{
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Expected O, but got Unknown
		//IL_0060: 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_0066: 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_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: 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_009a: 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_019a: Expected O, but got Unknown
		GameObject val = (((Object)(object)_uiGui != (Object)null) ? _uiGui.m_playerGrid.m_elementPrefab : null);
		if ((Object)(object)val == (Object)null)
		{
			return null;
		}
		GameObject val2 = Object.Instantiate<GameObject>(val, (Transform)(object)parent, false);
		((Object)val2).name = "Cell";
		val2.SetActive(true);
		RectTransform val3 = (RectTransform)val2.transform;
		Vector2 anchorMin = (val3.anchorMax = new Vector2(0f, 1f));
		val3.anchorMin = anchorMin;
		val3.pivot = new Vector2(0f, 1f);
		val3.anchoredPosition = pos + new Vector2(3f, -3f);
		InventoryElement component = val2.GetComponent<InventoryElement>();
		if ((Object)(object)component == (Object)null || (Object)(object)component.m_button == (Object)null || (Object)(object)component.m_icon == (Object)null)
		{
			Object.Destroy((Object)(object)val2);
			return null;
		}
		GameObject gameObject = ((Component)component.m_icon).gameObject;
		HideExtra((Component)(object)component.m_amount, val2, gameObject);
		HideExtra((Component)(object)component.m_quality, val2, gameObject);
		HideExtra((Component)(object)component.m_durability, val2, gameObject);
		HideExtra((Component)(object)component.m_queued, val2, gameObject);
		HideExtra((Component)(object)component.m_noteleport, val2, gameObject);
		HideExtra((Component)(object)component.m_food, val2, gameObject);
		HideExtra((Component)(object)component.m_equiped, val2, gameObject);
		HideExtra((Component)(object)component.m_dropFocus, val2, gameObject);
		SetShown(component.m_selected, on: false);
		Transform val5 = val2.transform.Find("binding");
		if ((Object)(object)val5 != (Object)null)
		{
			((Component)val5).gameObject.SetActive(false);
		}
		component.m_button.onClick = new ButtonClickedEvent();
		((Selectable)component.m_button).interactable = true;
		return component;
	}

	private static void SetIcon(InventoryElement cell, Sprite icon, bool dim)
	{
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		((Behaviour)cell.m_icon).enabled = (Object)(object)icon != (Object)null;
		cell.m_icon.sprite = icon;
		((Graphic)cell.m_icon).color = (Color)(dim ? new Color(1f, 1f, 1f, 0.3f) : Color.white);
	}

	private static void SetTooltip(InventoryElement cell, string topic, string text)
	{
		if (!((Object)(object)cell.m_tooltip == (Object)null))
		{
			cell.m_tooltip.m_topic = topic;
			cell.m_tooltip.m_text = text;
		}
	}

	private static RectTransform MakeButton(InventoryGui gui, Transform parent, string label, Action onClick)
	{
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Expected O, but got Unknown
		//IL_00c0: 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_00df: 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_012b: Expected O, but got Unknown
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Expected O, but got Unknown
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0171: Expected O, but got Unknown
		Button takeAllButton = gui.m_takeAllButton;
		GameObject val;
		if ((Object)(object)takeAllButton != (Object)null)
		{
			val = Object.Instantiate<GameObject>(((Component)takeAllButton).gameObject, parent, false);
			UIGamePad[] componentsInChildren = val.GetComponentsInChildren<UIGamePad>(true);
			foreach (UIGamePad val2 in componentsInChildren)
			{
				Object.Destroy((Object)(object)val2);
			}
		}
		else
		{
			val = new GameObject("Button", new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(Button)
			});
			val.transform.SetParent(parent, false);
			((Graphic)val.GetComponent<Image>()).color = new Color(0.3f, 0.25f, 0.2f, 0.9f);
			((RectTransform)val.transform).sizeDelta = new Vector2(110f, 32f);
		}
		((Object)val).name = "Glamour" + ((label == "X") ? "Close" : "Button");
		val.SetActive(true);
		Button component = val.GetComponent<Button>();
		component.onClick = new ButtonClickedEvent();
		((UnityEvent)component.onClick).AddListener((UnityAction)delegate
		{
			onClick();
		});
		((Selectable)component).interactable = true;
		TMP_Text componentInChildren = val.GetComponentInChildren<TMP_Text>(true);
		if ((Object)(object)componentInChildren != (Object)null)
		{
			componentInChildren.text = label;
		}
		return (RectTransform)val.transform;
	}

	private static RectTransform MakeRect(Transform parent, string name, Vector2 pos, Vector2 size)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Expected O, but got Unknown
		//IL_004d: 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_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: 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_007c: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
		val.layer = ((Component)parent).gameObject.layer;
		RectTransform val2 = (RectTransform)val.transform;
		((Transform)val2).SetParent(parent, false);
		Vector2 anchorMin = (val2.anchorMax = new Vector2(0f, 1f));
		val2.anchorMin = anchorMin;
		val2.pivot = new Vector2(0f, 1f);
		val2.anchoredPosition = pos;
		val2.sizeDelta = size;
		return val2;
	}

	private static TextMeshProUGUI MakeText(Transform parent, string name, TMP_Text sample, float fontSize, Vector2 pos, Vector2 size)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0004: 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)
		RectTransform val = MakeRect(parent, name, pos, size);
		TextMeshProUGUI val2 = ((Component)val).gameObject.AddComponent<TextMeshProUGUI>();
		if ((Object)(object)sample != (Object)null)
		{
			((TMP_Text)val2).font = sample.font;
			((TMP_Text)val2).fontSharedMaterial = sample.fontSharedMaterial;
		}
		((TMP_Text)val2).fontSize = fontSize;
		((Graphic)val2).color = new Color(1f, 0.93f, 0.8f);
		((TMP_Text)val2).alignment = (TextAlignmentOptions)514;
		((TMP_Text)val2).textWrappingMode = (TextWrappingModes)0;
		((TMP_Text)val2).overflowMode = (TextOverflowModes)1;
		((Graphic)val2).raycastTarget = false;
		return val2;
	}

	private static void CopyBackground(Image target, RectTransform from)
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: 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_00a1: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		Image val = null;
		float num = 0f;
		Image[] componentsInChildren = ((Component)from).GetComponentsInChildren<Image>(true);
		foreach (Image val2 in componentsInChildren)
		{
			if (!((Object)(object)val2.sprite == (Object)null))
			{
				Rect rect = ((Graphic)val2).rectTransform.rect;
				float width = ((Rect)(ref rect)).width;
				Rect rect2 = ((Graphic)val2).rectTransform.rect;
				float num2 = width * ((Rect)(ref rect2)).height;
				if (num2 > num)
				{
					num = num2;
					val = val2;
				}
			}
		}
		if ((Object)(object)val == (Object)null)
		{
			((Graphic)target).color = new Color(0.12f, 0.11f, 0.1f, 0.94f);
			return;
		}
		target.sprite = val.sprite;
		target.type = val.type;
		((Graphic)target).material = ((Graphic)val).material;
		target.pixelsPerUnitMultiplier = val.pixelsPerUnitMultiplier;
		Color color = ((Graphic)val).color;
		color.a = Mathf.Max(color.a, 0.92f);
		((Graphic)target).color = color;
	}

	private static void Clear(Transform parent)
	{
		for (int num = parent.childCount - 1; num >= 0; num--)
		{
			Object.Destroy((Object)(object)((Component)parent.GetChild(num)).gameObject);
		}
	}

	private static void HideExtra(Component c, GameObject root, GameObject keep)
	{
		if ((Object)(object)c == (Object)null)
		{
			return;
		}
		if ((Object)(object)c.gameObject != (Object)(object)root && (Object)(object)c.gameObject != (Object)(object)keep)
		{
			c.gameObject.SetActive(false);
			return;
		}
		Behaviour val = (Behaviour)(object)((c is Behaviour) ? c : null);
		if ((Object)(object)val != (Object)null)
		{
			val.enabled = false;
		}
	}

	private static void SetShown(object o, bool on)
	{
		if (o == null)
		{
			return;
		}
		GameObject val = (GameObject)((o is GameObject) ? o : null);
		if ((Object)(object)val != (Object)null)
		{
			val.SetActive(on);
			return;
		}
		Behaviour val2 = (Behaviour)((o is Behaviour) ? o : null);
		if ((Object)(object)val2 != (Object)null)
		{
			val2.enabled = on;
			return;
		}
		Component val3 = (Component)((o is Component) ? o : null);
		if ((Object)(object)val3 != (Object)null)
		{
			val3.gameObject.SetActive(on);
		}
	}

	private static void RegisterWithHudLayout(RectTransform button, RectTransform window)
	{
		try
		{
			Type type = Type.GetType("HudLayout.HudLayoutApi, HudLayout");
			if (type == null)
			{
				return;
			}
			MethodInfo methodInfo = null;
			MethodInfo[] methods = type.GetMethods(BindingFlags.Static | BindingFlags.Public);
			foreach (MethodInfo methodInfo2 in methods)
			{
				if (!(methodInfo2.Name != "Register"))
				{
					ParameterInfo[] parameters = methodInfo2.GetParameters();
					if (parameters.Length == 3 && parameters[0].ParameterType == typeof(string) && parameters[1].ParameterType == typeof(RectTransform) && parameters[2].ParameterType == typeof(string))
					{
						methodInfo = methodInfo2;
						break;
					}
				}
			}
			if (!(methodInfo == null))
			{
				if ((Object)(object)button != (Object)null)
				{
					methodInfo.Invoke(null, new object[3] { "Glamour.Button", button, "Glamour button" });
				}
				if ((Object)(object)window != (Object)null)
				{
					methodInfo.Invoke(null, new object[3] { "Glamour.Window", window, "Glamour window" });
				}
			}
		}
		catch (Exception e)
		{
			if ((Object)(object)_instance != (Object)null)
			{
				_instance.Fail("HudLayout", e);
			}
		}
	}

	private void SavePanelOffset(Vector2 delta)
	{
		//IL_000a: 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_0010: Unknown result type (might be due to invalid IL or missing references)
		_cfgPanelOffset.Value += delta;
	}
}