Decompiled source of Overhaul v2.2.64

Overhaul/Overhaul.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using APIManager;
using Advize_PlantEasily;
using Auga;
using Auga.Compat;
using Auga.Utilities;
using AugaUnity;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Common;
using EquipmentAndQuickSlots;
using EquipmentAndQuickSlots.src.MultiUtility;
using GUIFramework;
using HarmonyLib;
using JetBrains.Annotations;
using Jotunn;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Overhaul;
using Overhaul.AI;
using Overhaul.Commands;
using Overhaul.Dungeons;
using Overhaul.Leveling;
using Overhaul.Patches;
using Overhaul.Persistence;
using Overhaul.Storage;
using Overhaul.Utility;
using SoftReferenceableAssets;
using Splatform;
using TMPro;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.Utilities;
using UnityEngine.Rendering;
using UnityEngine.UI;
using Valheim.SettingsGui;
using XPortal;
using XPortal.Extension;
using XPortal.Patches;
using XPortal.RPC;
using XPortal.RPC.Client;
using XPortal.RPC.Server;
using XPortal.UI;
using fastJSON;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Overhaul")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("LyriaStudio")]
[assembly: AssemblyProduct("Overhaul")]
[assembly: AssemblyCopyright("Copyright © LyriaStudio 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("0b5fc708-52ce-4b88-9bbc-3ec85c10c081")]
[assembly: AssemblyFileVersion("2.2.0.64")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = "")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.2.0.64")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace EquipmentAndQuickSlots
{
	public static class EquipmentAndQuickSlots
	{
		public const string PluginId = "randyknapp.mods.equipmentandquickslots";

		public const string Version = "3.1.3";

		public static Sprite PaperdollMale;

		public static Sprite PaperdollFemale;

		public static GameObject Paperdolls;

		private static ManualLogSource logger;

		private static Harmony harmony;

		private static AssetBundle assets;

		public static bool HasAuga => false;

		public static bool IsInitialized { get; private set; }

		internal static ConfigFile OpenConfig(string directory, string legacyDirectory)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			string text = Path.Combine(directory, "plopyy.valheim.Overhaul.EquipmentSlots.cfg");
			string text2 = Path.Combine(legacyDirectory, "randyknapp.mods.equipmentandquickslots.cfg");
			if (!File.Exists(text) && File.Exists(text2))
			{
				File.Copy(text2, text);
			}
			return new ConfigFile(text, true);
		}

		internal static void Initialize(ManualLogSource log)
		{
			if (!IsInitialized)
			{
				ConfigFile val = OpenConfig(Paths.ConfigPath, Paths.ConfigPath);
				Initialize(log, val);
				SynchronizationManager.Instance.RegisterCustomConfig(val);
			}
		}

		internal static void Initialize(ManualLogSource log, ConfigFile config)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Invalid comparison between Unknown and I4
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Expected O, but got Unknown
			if (IsInitialized)
			{
				return;
			}
			logger = log;
			new ValConfig(config);
			Slots.InitializeSlots();
			if (!Application.isBatchMode && (int)SystemInfo.graphicsDeviceType != 4)
			{
				assets = LoadAssetBundle("eaqs");
				PaperdollMale = assets.LoadAsset<Sprite>("PaperdollMale");
				PaperdollFemale = assets.LoadAsset<Sprite>("PaperdollFemale");
				Paperdolls = assets.LoadAsset<GameObject>("Paperdolls");
			}
			EpicLootCompat.Initialize();
			harmony = new Harmony("plopyy.valheim.Overhaul.EquipmentSlots");
			Type[] types = typeof(EquipmentAndQuickSlots).Assembly.GetTypes();
			foreach (Type type in types)
			{
				if (!(type.Namespace == "EquipmentAndQuickSlots"))
				{
					string? text = type.Namespace;
					if (text == null || !text.StartsWith("EquipmentAndQuickSlots."))
					{
						continue;
					}
				}
				harmony.CreateClassProcessor(type).Patch();
			}
			BetterArcheryCompat.Initialize(harmony);
			IsInitialized = true;
			LogInfo("Equipment & Quick Slots integrated into Overhaul.");
		}

		internal static void Update()
		{
			Player localPlayer = Player.m_localPlayer;
			if (!IsInitialized || !Object.op_Implicit((Object)(object)localPlayer))
			{
				return;
			}
			AmmoSlots.Update(localPlayer);
			Slots.Slot[] slots = Slots.slots;
			foreach (Slots.Slot slot in slots)
			{
				if (slot.IsHotkeySlot && slot.IsShortcutDownWithItem() && slot.ItemFits(slot.Item))
				{
					((Humanoid)localPlayer).UseItem((Inventory)null, slot.Item, false);
				}
			}
		}

		internal static void LateUpdate()
		{
			if (IsInitialized)
			{
				SlotValidation.Validate();
				API.DetectSlotItemChanges();
			}
		}

		internal static void Stop()
		{
			IsInitialized = false;
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			harmony = null;
			if (Object.op_Implicit((Object)(object)assets))
			{
				assets.Unload(false);
			}
			assets = null;
		}

		public static AssetBundle LoadAssetBundle(string filename)
		{
			return EmbeddedAssets.LoadBundle("Overhaul." + filename);
		}

		public static void Log(string message)
		{
			ConfigEntry<bool> loggingEnabled = ValConfig.LoggingEnabled;
			if (loggingEnabled != null && loggingEnabled.Value)
			{
				ManualLogSource obj = logger;
				if (obj != null)
				{
					obj.LogMessage((object)message);
				}
			}
		}

		public static void LogWarning(string message)
		{
			ManualLogSource obj = logger;
			if (obj != null)
			{
				obj.LogWarning((object)message);
			}
		}

		public static void LogError(string message)
		{
			ManualLogSource obj = logger;
			if (obj != null)
			{
				obj.LogError((object)message);
			}
		}

		public static void LogInfo(string message)
		{
			ManualLogSource obj = logger;
			if (obj != null)
			{
				obj.LogInfo((object)message);
			}
		}
	}
	internal static class AmmoSlots
	{
		[HarmonyPatch(typeof(Inventory), "GetAmmoItem")]
		private static class InventoryAmmo
		{
			private static bool Prefix(Inventory __instance, string ammoName, string matchPrefabName, ref ItemData __result)
			{
				Player localPlayer = Player.m_localPlayer;
				if (!Ready(localPlayer) || __instance != ((Humanoid)localPlayer).GetInventory() || !Managed(ammoName))
				{
					return true;
				}
				__result = Select(localPlayer, ammoName, matchPrefabName);
				return false;
			}
		}

		[HarmonyPatch(typeof(Humanoid), "GetAmmoItem")]
		private static class EquippedAmmo
		{
			private static bool Prefix(Humanoid __instance, ref ItemData __result)
			{
				Player val = (Player)(object)((__instance is Player) ? __instance : null);
				if (!Ready(val))
				{
					return true;
				}
				string text = ((Humanoid)val).GetCurrentWeapon()?.m_shared.m_ammoType;
				if (!Managed(text))
				{
					return true;
				}
				__result = Select(val, text);
				return false;
			}
		}

		[HarmonyPatch(typeof(InventoryGui), "OnRightClickItem")]
		private static class RightClick
		{
			private static bool Prefix(InventoryGrid grid, ItemData item)
			{
				Player localPlayer = Player.m_localPlayer;
				if (!Ready(localPlayer) || !IsAmmo(item))
				{
					return true;
				}
				if (!Insert(localPlayer, grid.GetInventory(), item))
				{
					((Character)localPlayer).Message((MessageType)2, "$overhaul_ammo_slots_full", 0, (Sprite)null, false);
				}
				return false;
			}
		}

		private const string SelectionKey = "overhaul_ammo_slot";

		internal static bool IsAmmo(ItemData item)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Invalid comparison between Unknown and I4
			return item != null && ((int)item.m_shared.m_itemType == 9 || (int)item.m_shared.m_itemType == 23);
		}

		internal static bool IsFood(ItemData item)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Invalid comparison between Unknown and I4
			return item != null && (int)item.m_shared.m_itemType == 2 && (item.m_shared.m_food > 0f || item.m_shared.m_foodStamina > 0f || item.m_shared.m_foodEitr > 0f);
		}

		internal static bool Ready(Player player)
		{
			return Object.op_Implicit((Object)(object)player) && (Object)(object)player == (Object)(object)Player.m_localPlayer && !player.m_isLoading && Slots.slots[28] != null;
		}

		internal static int Selected(Player player)
		{
			string value;
			int result;
			return (Object.op_Implicit((Object)(object)player) && player.m_customData.TryGetValue("overhaul_ammo_slot", out value) && int.TryParse(value, out result)) ? Mathf.Clamp(result, 0, 2) : 0;
		}

		internal static void SetSelected(Player player, int index)
		{
			player.m_customData["overhaul_ammo_slot"] = Mathf.Clamp(index, 0, 2).ToString();
		}

		private static ItemData Item(int index)
		{
			//IL_000b: 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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			Vector2i gridPosition = Slots.slots[28 + index].GridPosition;
			Inventory playerInventory = Slots.PlayerInventory;
			return (playerInventory != null) ? playerInventory.GetItemAt(gridPosition.x, gridPosition.y) : null;
		}

		private static bool Matches(ItemData item, string ammo, string prefab)
		{
			return IsAmmo(item) && item.m_stack > 0 && (string.IsNullOrEmpty(ammo) || item.m_shared.m_ammoType == ammo) && (prefab == null || (Object.op_Implicit((Object)(object)item.m_dropPrefab) && ((Object)item.m_dropPrefab).name == prefab));
		}

		internal static ItemData Select(Player player, string ammo, string prefab = null, bool cycle = false)
		{
			int num = Selected(player);
			for (int i = 0; i < 3; i++)
			{
				int index = (num + i + (cycle ? 1 : 0)) % 3;
				ItemData val = Item(index);
				if (Matches(val, ammo, prefab))
				{
					SetSelected(player, index);
					return val;
				}
			}
			return null;
		}

		internal static bool Shortcut(bool held = false)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			return Ready(localPlayer) && ((Character)localPlayer).TakeInput() && ValConfig.AmmoCycleKey != null && (held ? PreventSimilarHotkeys.IsShortcutPressed(ValConfig.AmmoCycleKey.Value) : PreventSimilarHotkeys.IsShortcutDown(ValConfig.AmmoCycleKey.Value));
		}

		internal static void Update(Player player)
		{
			if (Ready(player))
			{
				string ammo = ((Humanoid)player).GetCurrentWeapon()?.m_shared.m_ammoType;
				bool flag = Shortcut();
				ItemData val = Select(player, ammo, null, flag);
				if (flag)
				{
					((Character)player).Message((MessageType)2, (val != null) ? val.m_shared.m_name : "$overhaul_no_ammo", 0, (Sprite)null, false);
				}
			}
		}

		private static bool Managed(string type)
		{
			return !string.IsNullOrEmpty(type) && (type == "$ammo_arrows" || type == "$ammo_bolts" || Slots.slots.Skip(28).Take(3).Any((Slots.Slot s) => s != null && IsAmmo(s.Item) && s.Item.m_shared.m_ammoType == type) || (Object.op_Implicit((Object)(object)ObjectDB.instance) && ObjectDB.instance.m_items.Any((GameObject go) => Object.op_Implicit((Object)(object)go) && IsAmmo(go.GetComponent<ItemDrop>()?.m_itemData) && go.GetComponent<ItemDrop>().m_itemData.m_shared.m_ammoType == type)));
		}

		internal static bool Insert(Player player, Inventory source, ItemData item)
		{
			//IL_00cb: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: 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_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: 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)
			if (!Ready(player) || !IsAmmo(item) || source == null || !source.ContainsItem(item))
			{
				return false;
			}
			Inventory inventory = ((Humanoid)player).GetInventory();
			Slots.Slot slot = ((source == inventory) ? Slots.GetItemSlot(item) : null);
			if (slot != null && slot.IsAmmoSlot)
			{
				SetSelected(player, slot.Index - 28);
				return true;
			}
			int stack = item.m_stack;
			int num = -1;
			for (int i = 0; i < 3; i++)
			{
				if (item.m_stack <= 0)
				{
					break;
				}
				ItemData val = Item(i);
				if (val != null && val != item && val.IsSameType(item) && val.m_stack < val.m_shared.m_maxStackSize)
				{
					Vector2i gridPosition = Slots.slots[28 + i].GridPosition;
					int stack2 = item.m_stack;
					inventory.MoveItemToThis(source, item, Mathf.Min(stack2, val.m_shared.m_maxStackSize - val.m_stack), gridPosition.x, gridPosition.y);
					Slots.ClearCachedItems();
					if (item.m_stack < stack2 && num < 0)
					{
						num = i;
					}
				}
			}
			for (int j = 0; j < 3; j++)
			{
				if (item.m_stack <= 0)
				{
					break;
				}
				if (Item(j) != null)
				{
					continue;
				}
				Vector2i gridPosition2 = Slots.slots[28 + j].GridPosition;
				if (source == inventory)
				{
					item.m_gridPos = gridPosition2;
					Slots.ClearCachedItems();
					inventory.Changed(false, false);
					if (num < 0)
					{
						num = j;
					}
					break;
				}
				int stack3 = item.m_stack;
				inventory.MoveItemToThis(source, item, Mathf.Min(stack3, item.m_shared.m_maxStackSize), gridPosition2.x, gridPosition2.y);
				Slots.ClearCachedItems();
				if (item.m_stack < stack3 && num < 0)
				{
					num = j;
				}
			}
			if (num >= 0)
			{
				SetSelected(player, num);
				return true;
			}
			return item.m_stack < stack;
		}

		internal static void MigrateInvalidSlots()
		{
			//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_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: 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_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if (!Ready(localPlayer))
			{
				return;
			}
			Inventory inventory = ((Humanoid)localPlayer).GetInventory();
			bool flag = false;
			foreach (Slots.Slot item2 in Slots.slots.Where((Slots.Slot s) => s.IsQuickSlot || s.IsAmmoSlot))
			{
				ItemData item = item2.Item;
				if (item == null || item2.ItemFits(item))
				{
					continue;
				}
				if (item2.IsQuickSlot && IsAmmo(item))
				{
					int index = Selected(localPlayer);
					Insert(localPlayer, inventory, item);
					SetSelected(localPlayer, index);
					if (inventory.ContainsItem(item))
					{
						Slots.Slot itemSlot = Slots.GetItemSlot(item);
						if (itemSlot == null || !itemSlot.IsAmmoSlot)
						{
							goto IL_00f0;
						}
					}
					flag = true;
					Slots.ClearCachedItems();
					continue;
				}
				goto IL_00f0;
				IL_00f0:
				Vector2i emptyPosition = Slots.emptyPosition;
				for (int num = 0; num < Slots.VisibleRows; num++)
				{
					if (!(emptyPosition == Slots.emptyPosition))
					{
						break;
					}
					for (int num2 = 0; num2 < Slots.InventoryWidth; num2++)
					{
						if (inventory.GetItemAt(num2, num) == null)
						{
							((Vector2i)(ref emptyPosition))..ctor(num2, num);
							break;
						}
					}
				}
				if (emptyPosition != Slots.emptyPosition)
				{
					item.m_gridPos = emptyPosition;
					flag = true;
				}
				else if (!((Humanoid)localPlayer).DropItem(inventory, item, item.m_stack))
				{
					EquipmentAndQuickSlots.LogWarning("Could not move legacy food/ammo slot item yet; retaining it for retry.");
				}
				Slots.ClearCachedItems();
			}
			if (flag)
			{
				inventory.Changed(false, false);
			}
		}
	}
	public static class API
	{
		public const int ApiVersion = 2;

		private static readonly List<Action<string>> slotChangedListeners = new List<Action<string>>();

		private static readonly List<Action<string, ItemData, ItemData>> slotItemChangedListeners = new List<Action<string, ItemData, ItemData>>();

		private static readonly Dictionary<string, ItemData> lastKnownSlotItems = new Dictionary<string, ItemData>();

		public static int GetApiVersion()
		{
			return 2;
		}

		public static string GetPluginVersion()
		{
			return "3.1.3";
		}

		public static string GetPluginId()
		{
			return "randyknapp.mods.equipmentandquickslots";
		}

		public static bool HasEndpoint(string name)
		{
			return typeof(API).GetMethods(BindingFlags.Static | BindingFlags.Public).Any((MethodInfo m) => m.Name == name);
		}

		public static List<string> GetEndpointNames()
		{
			return (from n in (from m in typeof(API).GetMethods(BindingFlags.Static | BindingFlags.Public)
					select m.Name).Distinct()
				orderby n
				select n).ToList();
		}

		public static bool AddSlot(string slotId, string ownerPluginGuid, string nameToken, Func<ItemData, bool> isValid, Func<bool> isActive)
		{
			if (string.IsNullOrEmpty(slotId))
			{
				return false;
			}
			bool flag = Slots.TryAddCustomSlot(slotId, ownerPluginGuid, () => nameToken ?? "", (ItemData item) => GuardedPredicate(ownerPluginGuid, isValid, item), () => GuardedActive(ownerPluginGuid, isActive));
			if (flag)
			{
				NotifySlotChanged(slotId);
			}
			return flag;
		}

		public static bool RemoveSlot(string slotId)
		{
			bool flag = Slots.TryRemoveCustomSlot(slotId);
			if (flag)
			{
				lastKnownSlotItems.Remove("Custom" + slotId);
				NotifySlotChanged(slotId);
			}
			return flag;
		}

		private static bool GuardedPredicate(string owner, Func<ItemData, bool> isValid, ItemData item)
		{
			if (isValid == null)
			{
				return true;
			}
			try
			{
				return isValid(item);
			}
			catch (Exception arg)
			{
				Debug.LogWarning((object)$"[EAQS API] isValid delegate of '{owner}' threw: {arg}");
				return false;
			}
		}

		private static bool GuardedActive(string owner, Func<bool> isActive)
		{
			if (isActive == null)
			{
				return true;
			}
			try
			{
				return isActive();
			}
			catch (Exception arg)
			{
				Debug.LogWarning((object)$"[EAQS API] isActive delegate of '{owner}' threw: {arg}");
				return false;
			}
		}

		public static string GetSlotIdsJson()
		{
			StringBuilder stringBuilder = new StringBuilder("[");
			bool flag = true;
			Slots.Slot[] slots = Slots.slots;
			foreach (Slots.Slot slot in slots)
			{
				if (!slot.IsEmptySlot)
				{
					if (!flag)
					{
						stringBuilder.Append(',');
					}
					flag = false;
					stringBuilder.Append('"').Append(Escape(PublicSlotId(slot))).Append('"');
				}
			}
			return stringBuilder.Append(']').ToString();
		}

		public static string GetSlotInfoJson(string slotId)
		{
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			Slots.Slot slot = FindPublicSlot(slotId);
			if (slot == null)
			{
				return null;
			}
			return "{\"id\":\"" + Escape(PublicSlotId(slot)) + "\"," + $"\"index\":{slot.Index}," + "\"nameToken\":\"" + Escape(slot.Name) + "\",\"active\":" + (slot.IsActive ? "true" : "false") + "," + $"\"gridX\":{slot.GridPosition.x}," + $"\"gridY\":{slot.GridPosition.y}," + "\"isQuickSlot\":" + (slot.IsQuickSlot ? "true" : "false") + ",\"isEquipmentSlot\":" + (slot.IsEquipmentSlot ? "true" : "false") + ",\"isCustomSlot\":" + (slot.IsCustomSlot ? "true" : "false") + ",\"ownerPluginGuid\":\"" + Escape(slot.OwnerGuid ?? "") + "\",\"occupied\":" + ((slot.Item != null) ? "true" : "false") + "}";
		}

		public static bool TryGetSlotItem(string slotId, ref ItemData item)
		{
			Slots.Slot slot = FindPublicSlot(slotId);
			if (slot == null)
			{
				return false;
			}
			item = slot.Item;
			return item != null;
		}

		public static bool IsSlotCell(int x, int y, ref string slotId)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			Slots.Slot slotInGrid = Slots.GetSlotInGrid(new Vector2i(x, y));
			if (slotInGrid == null || slotInGrid.IsEmptySlot)
			{
				return false;
			}
			slotId = PublicSlotId(slotInGrid);
			return true;
		}

		public static List<ItemData> GetQuickSlotItems()
		{
			return (from slot in Slots.GetQuickSlots()
				where slot.IsActive
				select slot.Item into item
				where item != null
				select item).ToList();
		}

		public static List<ItemData> GetEquipmentSlotItems()
		{
			return (from slot in Slots.GetEquipmentSlots()
				select slot.Item into item
				where item != null
				select item).ToList();
		}

		public static int GetVisibleRows()
		{
			return Slots.VisibleRows;
		}

		public static int GetFullHeight()
		{
			return Slots.FullHeight;
		}

		public static void AddSlotChangedListener(Action<string> listener)
		{
			if (listener != null && !slotChangedListeners.Contains(listener))
			{
				slotChangedListeners.Add(listener);
			}
		}

		public static void RemoveSlotChangedListener(Action<string> listener)
		{
			slotChangedListeners.Remove(listener);
		}

		public static void AddSlotItemChangedListener(Action<string, ItemData, ItemData> listener)
		{
			if (listener != null && !slotItemChangedListeners.Contains(listener))
			{
				slotItemChangedListeners.Add(listener);
			}
		}

		public static void RemoveSlotItemChangedListener(Action<string, ItemData, ItemData> listener)
		{
			slotItemChangedListeners.Remove(listener);
		}

		private static string PublicSlotId(Slots.Slot slot)
		{
			return slot.IsCustomSlot ? slot.ID.Substring("Custom".Length) : slot.ID;
		}

		private static Slots.Slot FindPublicSlot(string slotId)
		{
			if (string.IsNullOrEmpty(slotId))
			{
				return null;
			}
			Slots.Slot slot = Slots.FindSlot(slotId) ?? Slots.FindSlot("Custom" + slotId);
			return (slot != null && !slot.IsEmptySlot) ? slot : null;
		}

		private static string Escape(string value)
		{
			return value?.Replace("\\", "\\\\").Replace("\"", "\\\"") ?? "";
		}

		private static void NotifySlotChanged(string slotId)
		{
			foreach (Action<string> item in slotChangedListeners.ToList())
			{
				try
				{
					item(slotId);
				}
				catch (Exception arg)
				{
					Debug.LogWarning((object)$"[EAQS API] slot-changed listener threw: {arg}");
				}
			}
		}

		internal static void DetectSlotItemChanges()
		{
			if (slotItemChangedListeners.Count == 0 || (Object)(object)Player.m_localPlayer == (Object)null)
			{
				return;
			}
			Slots.Slot[] slots = Slots.slots;
			foreach (Slots.Slot slot in slots)
			{
				if (slot.IsEmptySlot)
				{
					continue;
				}
				string iD = slot.ID;
				ItemData item = slot.Item;
				lastKnownSlotItems.TryGetValue(iD, out var value);
				if (item == value)
				{
					continue;
				}
				lastKnownSlotItems[iD] = item;
				string arg = PublicSlotId(slot);
				foreach (Action<string, ItemData, ItemData> item2 in slotItemChangedListeners.ToList())
				{
					try
					{
						item2(arg, value, item);
					}
					catch (Exception arg2)
					{
						Debug.LogWarning((object)$"[EAQS API] slot-item-changed listener threw: {arg2}");
					}
				}
			}
		}
	}
	public static class AugaPanel
	{
		private const string PanelName = "EAQS";

		private static readonly Vector2 panelBase = new Vector2(752f, -166f);

		private const float panelWidth = 255f;

		private const float panelHeight = 352f;

		private const float paperdollHeight = 157f;

		private const float tileSize = 74f;

		private static readonly Vector2 equipClusterCenter = new Vector2(110.5f, -57f);

		private static readonly Vector2[] equipPositions = (Vector2[])(object)new Vector2[8]
		{
			new Vector2(0f, 0f),
			new Vector2(-36f, -72f),
			new Vector2(0f, -144f),
			new Vector2(36f, -72f),
			new Vector2(104f, 0f),
			new Vector2(-104f, 0f),
			new Vector2(104f, -72f),
			new Vector2(104f, -144f)
		};

		private static GameObject _panel;

		private const int customSlotsPerColumn = 4;

		private static int ActiveQuickSlots => ValConfig.QuickSlotsEnabled.Value ? ValConfig.QuickSlotCount.Value : 0;

		private static Slots.Slot[] ActiveCustomSlots => (from slot in Slots.GetCustomSlots()
			where slot.IsActive
			orderby slot.Index
			select slot).ToArray();

		private static float PanelWidth => Mathf.Max(255f, (float)ActiveQuickSlots * 74f + 20f);

		internal static Vector2 GetSlotPosition(Slots.Slot slot)
		{
			//IL_000b: 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_0015: 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)
			//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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
			if (slot.IsEquipmentSlot)
			{
				return panelBase + equipClusterCenter + equipPositions[slot.Index - 8];
			}
			if (slot.IsQuickSlot)
			{
				float num = (PanelWidth - (float)ActiveQuickSlots * 74f) / 2f + 5f;
				return panelBase + new Vector2(num + (float)slot.Index * 74f, -187f);
			}
			if (slot.IsCustomSlot)
			{
				int num2 = Math.Max(0, Array.IndexOf(ActiveCustomSlots, slot));
				int num3 = num2 % 4;
				int num4 = num2 / 4;
				return panelBase + new Vector2(PanelWidth + 10f + (float)num4 * 74f, 0f - (float)num3 * 74f);
			}
			return panelBase;
		}

		internal static void UpdatePanel()
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Expected O, but got Unknown
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)InventoryGui.instance) || !Object.op_Implicit((Object)(object)InventoryGui.instance.m_player))
			{
				return;
			}
			if ((Object)(object)_panel == (Object)null)
			{
				_panel = Auga.API.Panel_Create((Transform)(object)InventoryGui.instance.m_player, new Vector2(PanelWidth, 352f), "EAQS", withCornerDecoration: false);
				if ((Object)(object)_panel == (Object)null)
				{
					return;
				}
				RectTransform val = (RectTransform)_panel.transform;
				val.anchorMin = new Vector2(0f, 1f);
				val.anchorMax = new Vector2(0f, 1f);
				val.anchoredPosition = panelBase;
				val.SetSizeWithCurrentAnchors((Axis)0, PanelWidth);
				val.SetSizeWithCurrentAnchors((Axis)1, 352f);
				GameObject val2 = Object.Instantiate<GameObject>(EquipmentAndQuickSlots.Paperdolls, _panel.transform, false);
				((Object)val2).name = "Paperdolls";
				GameObject val3 = Auga.API.Divider_CreateSmall(_panel.transform, "Divider", PanelWidth - 40f);
				((RectTransform)val3.transform).anchoredPosition = new Vector2(0f, -157f);
			}
			_panel.SetActive(ValConfig.EquipmentSlotsEnabled.Value || ActiveQuickSlots > 0);
			UpdatePaperdollGender();
		}

		private static void UpdatePaperdollGender()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || (Object)(object)_panel == (Object)null)
			{
				return;
			}
			Transform val = _panel.transform.Find("Paperdolls");
			if (!((Object)(object)val == (Object)null))
			{
				bool flag = (Object)(object)((Humanoid)localPlayer).m_visEquipment != (Object)null && ((Humanoid)localPlayer).m_visEquipment.GetModelIndex() == 1;
				Transform obj = val.Find("Male");
				if (obj != null)
				{
					((Component)obj).gameObject.SetActive(!flag);
				}
				Transform obj2 = val.Find("Female");
				if (obj2 != null)
				{
					((Component)obj2).gameObject.SetActive(flag);
				}
			}
		}

		internal static void Clear()
		{
			_panel = null;
		}
	}
	internal static class BetterArcheryCompat
	{
		public const string BetterArcheryGUID = "ishid4.mods.betterarchery";

		private const string PluginTypeName = "BetterArchery.BetterArchery";

		private const string QuiverConfigSection = "Quiver";

		private const string QuiverConfigKey = "Enable Quiver";

		private const string HoldingKeyConfigKey = "Quiver slot hotkey holding key";

		private const string KnownVersion = "1.9.8x";

		private static readonly int[] QuiverSlotIndices = new int[3] { 16, 17, 18 };

		private const string QuiverSlotIdPrefix = "BetterArcheryQuiver";

		private static PluginInfo _plugin;

		private static Assembly _assembly;

		private static ConfigEntry<bool> _quiverEnabled;

		private static ConfigEntry<KeyboardShortcut> _holdingKey;

		private static Func<bool> _isQuiverEquipped;

		private static Func<int, string> _getBindingLabel;

		private static FieldInfo _quiverRowIndex;

		private static bool _initialized;

		private static bool _quiverDisableHooked;

		private static bool _quiverStateWarned;

		internal static bool QuiverHosted { get; private set; }

		public static bool IsLoaded => Chainloader.PluginInfos.ContainsKey("ishid4.mods.betterarchery");

		internal static void Initialize(Harmony harmony)
		{
			if (_initialized)
			{
				return;
			}
			_initialized = true;
			if (!Chainloader.PluginInfos.TryGetValue("ishid4.mods.betterarchery", out _plugin))
			{
				return;
			}
			PluginInfo plugin = _plugin;
			if ((Object)(object)((plugin != null) ? plugin.Instance : null) == (Object)null)
			{
				return;
			}
			_assembly = ((object)_plugin.Instance).GetType().Assembly;
			CompatibilityHelper.RemoveHarmonyPatch(harmony, _assembly, typeof(TombStone), "OnTakeAllSuccess", "BetterArchery.Tombstone+TombStone_OnTakeAllSuccess_Patch", "Postfix", "stop it dropping equipment and quick slot items when a gravestone is emptied");
			if (!_plugin.Instance.Config.TryGetEntry<bool>("Quiver", "Enable Quiver", ref _quiverEnabled))
			{
				EquipmentAndQuickSlots.LogWarning(string.Format("Better Archery is loaded but its '{0}' setting could not be read (this logic was written for {1}, the installed version is {2}). Its quiver may conflict with the equipment and quick slots.", "Enable Quiver", "1.9.8x", _plugin.Metadata.Version));
			}
			else if (_quiverEnabled.Value)
			{
				if (!ValConfig.BetterArcheryQuiverIntegration.Value)
				{
					DisableQuiver("the Better Archery quiver integration is turned off in this mod's config");
					return;
				}
				if (!BindBetterArchery() || !ClaimQuiverSlots())
				{
					DisableQuiver("its quiver could not be hosted in the equipment panel");
					return;
				}
				QuiverHosted = true;
				SyncQuiverRow();
				CompatibilityHelper.RemoveHarmonyPatch(harmony, _assembly, typeof(Player), "Awake", "BetterArchery.Player_Awake_Patch", "Prefix", "stop it replacing the player inventory with a taller one (the empty cells under the inventory)");
				CompatibilityHelper.RemoveHarmonyPatch(harmony, _assembly, typeof(InventoryGrid), "UpdateGui", "BetterArchery.InventoryGrid_UpdateGui_Patch", "Postfix", "let the equipment panel own the quiver cells and their positions");
				CompatibilityHelper.RemoveHarmonyPatch(harmony, _assembly, typeof(Inventory), "FindEmptySlot", "BetterArchery.Inventory_FindEmptySlot_Patch", "Prefix", "stop it handing out equipment and quick slot cells as free space");
				CompatibilityHelper.RemoveHarmonyPatch(harmony, _assembly, typeof(Inventory), "HaveEmptySlot", "BetterArchery.Inventory_HaveEmptySlot_Patch", "Prefix", "stop its hardcoded capacity arithmetic overriding the slot-aware count");
				CompatibilityHelper.RemoveHarmonyPatch(harmony, _assembly, typeof(Player), "CreateTombStone", "BetterArchery.Player_CreateTombStone_Patch", "Prefix", "keep a single gravestone instead of a separate one for the quiver");
				EquipmentAndQuickSlots.LogInfo($"Better Archery {_plugin.Metadata.Version} detected: its quiver is hosted in three ammo-only slots in the equipment panel.");
			}
		}

		private static bool BindBetterArchery()
		{
			Type type = _assembly.GetType("BetterArchery.BetterArchery");
			if (type == null)
			{
				EquipmentAndQuickSlots.LogWarning("Better Archery is loaded but BetterArchery.BetterArchery could not be resolved.");
				return false;
			}
			_isQuiverEquipped = CompatibilityHelper.BindStatic<Func<bool>>(type, "IsQuiverEquipped");
			_getBindingLabel = CompatibilityHelper.BindStatic<Func<int, string>>(type, "GetBindingLabel");
			_quiverRowIndex = AccessTools.Field(type, "QuiverRowIndex");
			_plugin.Instance.Config.TryGetEntry<KeyboardShortcut>("Quiver", "Quiver slot hotkey holding key", ref _holdingKey);
			if (_isQuiverEquipped != null && _quiverRowIndex != null && _quiverRowIndex.FieldType == typeof(int))
			{
				return true;
			}
			EquipmentAndQuickSlots.LogWarning(string.Format("Better Archery's quiver members could not be bound (this logic was written for {0}, the installed version is {1}).", "1.9.8x", _plugin.Metadata.Version));
			return false;
		}

		private static bool ClaimQuiverSlots()
		{
			int num = 0;
			for (int i = 0; i < QuiverSlotIndices.Length; i++)
			{
				int ordinal = i;
				if (!Slots.TryAddCustomSlotAt(QuiverSlotIndices[i], "BetterArcheryQuiver" + (i + 1), "ishid4.mods.betterarchery", () => SlotLabel(ordinal), IsQuiverAmmo, IsQuiverEquipped))
				{
					break;
				}
				num++;
			}
			if (num == QuiverSlotIndices.Length && QuiverCellsAreWhereBetterArcheryExpects())
			{
				return true;
			}
			for (int num2 = 0; num2 < num; num2++)
			{
				Slots.TryRemoveCustomSlot("BetterArcheryQuiver" + (num2 + 1));
			}
			return false;
		}

		private static bool QuiverCellsAreWhereBetterArcheryExpects()
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_003a: Unknown result type (might be due to invalid IL or missing references)
			int y = Slots.slots[QuiverSlotIndices[0]].GridPosition.y;
			for (int i = 0; i < QuiverSlotIndices.Length; i++)
			{
				Vector2i gridPosition = Slots.slots[QuiverSlotIndices[i]].GridPosition;
				if (gridPosition.x != i || gridPosition.y != y)
				{
					return false;
				}
			}
			return true;
		}

		private static bool IsQuiverEquipped()
		{
			if (_isQuiverEquipped == null)
			{
				return false;
			}
			try
			{
				return _isQuiverEquipped();
			}
			catch (Exception ex)
			{
				if (!_quiverStateWarned)
				{
					_quiverStateWarned = true;
					EquipmentAndQuickSlots.LogWarning("Better Archery's IsQuiverEquipped threw; the quiver slots stay hidden: " + ex.Message);
				}
				return false;
			}
		}

		private static bool IsQuiverAmmo(ItemData item)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			return item != null && (int)item.m_shared.m_itemType == 9;
		}

		private static string SlotLabel(int ordinal)
		{
			//IL_002d: 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_0035: 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_003e: 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)
			string text = ((_getBindingLabel != null) ? _getBindingLabel(ordinal) : (ordinal + 1).ToString());
			int num;
			if (_holdingKey != null)
			{
				KeyboardShortcut value = _holdingKey.Value;
				num = (int)((KeyboardShortcut)(ref value)).MainKey;
			}
			else
			{
				num = 0;
			}
			KeyCode val = (KeyCode)num;
			return ((int)val == 0) ? text : $"{val} + {text}";
		}

		internal static void SyncQuiverRow()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			if (QuiverHosted)
			{
				int y = Slots.slots[QuiverSlotIndices[0]].GridPosition.y;
				if ((int)_quiverRowIndex.GetValue(null) != y)
				{
					_quiverRowIndex.SetValue(null, y);
				}
			}
		}

		private static void DisableQuiver(string reason)
		{
			if (_quiverEnabled == null || !_quiverEnabled.Value)
			{
				return;
			}
			if (!_quiverDisableHooked)
			{
				_quiverDisableHooked = true;
				_quiverEnabled.SettingChanged += delegate
				{
					DisableQuiver(reason);
				};
			}
			_quiverEnabled.Value = false;
			EquipmentAndQuickSlots.LogWarning(string.Format("Better Archery's quiver was disabled because {0}. Arrows already in it are not lost -- they move into your inventory. Use the quick slots for ammo instead. (This logic was written for Better Archery {1}; the installed version is {2}.)", reason, "1.9.8x", _plugin.Metadata.Version));
		}
	}
	internal static class BetterUICompat
	{
		public const string BetterUIGUID = "MK_BetterUI";

		private static bool _handoffNoted;

		public static bool IsLoaded => Chainloader.PluginInfos.ContainsKey("MK_BetterUI");

		internal static void NoteQuickBarHandoff(HotkeyBar quickBar)
		{
			if (!_handoffNoted && !((Object)(object)quickBar == (Object)null))
			{
				_handoffNoted = true;
				if (IsLoaded && (Object)(object)((Component)quickBar).GetComponent<ConfigPositionedElement>() == (Object)null)
				{
					EquipmentAndQuickSlots.LogInfo("BetterUI's HUD editor is positioning the quick slot bar; 'Quick Slots Anchor' and 'Quick Slots Position' only set where it starts. Move the bar with BetterUI's HUD edit key (F7 by default).");
				}
			}
		}
	}
	internal static class CompatibilityHelper
	{
		internal static bool RemoveHarmonyPatch(Harmony harmony, Assembly assembly, Type patchedType, string patchedMethod, string patcherClassName, string patcherClassMethod, string reason)
		{
			if (harmony == null || assembly == null)
			{
				return false;
			}
			Type type = assembly.GetType(patcherClassName);
			if (type == null)
			{
				EquipmentAndQuickSlots.LogInfo("Compatibility: " + patcherClassName + " not found; nothing to unpatch");
				return false;
			}
			MethodInfo methodInfo = AccessTools.Method(patchedType, patchedMethod, (Type[])null, (Type[])null);
			if ((object)methodInfo == null)
			{
				EquipmentAndQuickSlots.LogInfo("Compatibility: " + patchedType.Name + "." + patchedMethod + " not found; nothing to unpatch");
				return false;
			}
			MethodInfo methodInfo2 = AccessTools.Method(type, patcherClassMethod, (Type[])null, (Type[])null);
			if ((object)methodInfo2 == null)
			{
				EquipmentAndQuickSlots.LogInfo("Compatibility: " + patcherClassName + "." + patcherClassMethod + " not found; nothing to unpatch");
				return false;
			}
			try
			{
				harmony.Unpatch((MethodBase)methodInfo, methodInfo2);
			}
			catch (Exception ex)
			{
				EquipmentAndQuickSlots.LogWarning("Compatibility: failed to unpatch " + patcherClassName + "." + patcherClassMethod + ": " + ex.Message);
				return false;
			}
			EquipmentAndQuickSlots.LogInfo("Compatibility: unpatched " + patcherClassName + "." + patcherClassMethod + " from " + patchedType.Name + "." + patchedMethod + " to " + reason);
			return true;
		}

		internal static TDelegate BindStatic<TDelegate>(Type type, string methodName) where TDelegate : class
		{
			if (type == null)
			{
				return null;
			}
			MethodInfo methodInfo = AccessTools.Method(type, methodName, (Type[])null, (Type[])null);
			if ((object)methodInfo == null || !methodInfo.IsStatic)
			{
				return null;
			}
			try
			{
				return Delegate.CreateDelegate(typeof(TDelegate), methodInfo, throwOnBindFailure: false) as TDelegate;
			}
			catch (Exception)
			{
				return null;
			}
		}
	}
	internal static class EpicLootCompat
	{
		public const string EpicLootGUID = "randyknapp.mods.epicloot";

		private const string ApiTypeName = "EpicLoot.API, EpicLoot";

		private const string ProviderId = "randyknapp.mods.equipmentandquickslots";

		private static bool _initialized;

		private static MethodInfo _invalidatePlayerEffectCache;

		public static bool IsLoaded => Chainloader.PluginInfos.ContainsKey("randyknapp.mods.epicloot");

		internal static void Initialize()
		{
			if (_initialized || !IsLoaded)
			{
				return;
			}
			_initialized = true;
			try
			{
				Type type = Type.GetType("EpicLoot.API, EpicLoot");
				if (type == null)
				{
					EquipmentAndQuickSlots.LogWarning("Epic Loot is loaded but EpicLoot.API could not be resolved; slot items will not contribute magic effects");
					return;
				}
				MethodInfo method = type.GetMethod("RegisterEquipmentProvider", BindingFlags.Static | BindingFlags.Public, null, new Type[2]
				{
					typeof(string),
					typeof(Func<Player, List<ItemData>>)
				}, null);
				MethodInfo method2 = type.GetMethod("RegisterSacrificeFilter", BindingFlags.Static | BindingFlags.Public, null, new Type[2]
				{
					typeof(string),
					typeof(Func<ItemData, bool>)
				}, null);
				_invalidatePlayerEffectCache = type.GetMethod("InvalidatePlayerEffectCache", BindingFlags.Static | BindingFlags.Public, null, new Type[1] { typeof(Player) }, null);
				if (method == null || _invalidatePlayerEffectCache == null)
				{
					EquipmentAndQuickSlots.LogWarning("Epic Loot's equipment provider API is missing (older Epic Loot?); custom slot items will not contribute magic effects");
					return;
				}
				Func<Player, List<ItemData>> func = GetCustomSlotEquipment;
				method.Invoke(null, new object[2] { "randyknapp.mods.equipmentandquickslots", func });
				if (method2 != null)
				{
					Func<ItemData, bool> func2 = CanSacrifice;
					method2.Invoke(null, new object[2] { "randyknapp.mods.equipmentandquickslots", func2 });
				}
				API.AddSlotItemChangedListener(OnSlotItemChanged);
				API.AddSlotChangedListener(delegate
				{
					InvalidateEffectCache();
				});
				EquipmentAndQuickSlots.Log("Epic Loot equipment provider registered for custom slots");
			}
			catch (Exception arg)
			{
				EquipmentAndQuickSlots.LogWarning($"Epic Loot integration failed: {arg}");
			}
		}

		private static List<ItemData> GetCustomSlotEquipment(Player player)
		{
			if ((Object)(object)player == (Object)null || (Object)(object)player != (Object)(object)Player.m_localPlayer)
			{
				return null;
			}
			return (from slot in Slots.GetCustomSlots()
				where slot.IsActive
				select slot.Item into item
				where item != null
				select item).ToList();
		}

		private static bool CanSacrifice(ItemData item)
		{
			Slots.Slot itemSlot = Slots.GetItemSlot(item);
			return itemSlot == null || (!itemSlot.IsCustomSlot && !itemSlot.IsEquipmentSlot);
		}

		private static void OnSlotItemChanged(string slotId, ItemData oldItem, ItemData newItem)
		{
			Slots.Slot slot = Slots.FindSlot("Custom" + slotId);
			if (slot != null && slot.IsCustomSlot)
			{
				InvalidateEffectCache();
			}
		}

		internal static void InvalidateEffectCache()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || _invalidatePlayerEffectCache == null)
			{
				return;
			}
			try
			{
				_invalidatePlayerEffectCache.Invoke(null, new object[1] { localPlayer });
			}
			catch (Exception arg)
			{
				EquipmentAndQuickSlots.LogWarning($"Epic Loot InvalidatePlayerEffectCache failed: {arg}");
			}
		}
	}
	internal static class CosmeticEquipment
	{
		[HarmonyPatch(typeof(InventoryGui), "OnRightClickItem")]
		private static class RightClick
		{
			private static bool Prefix(InventoryGui __instance, InventoryGrid grid, ItemData item)
			{
				if (__instance.m_dragItem != null)
				{
					return true;
				}
				return !HandleRightClick(Player.m_localPlayer, grid.GetInventory(), item, EquipmentPanelBridge.IsCosmeticTab);
			}
		}

		[HarmonyPatch(typeof(Humanoid), "EquipItem")]
		private static class PreventEquip
		{
			[HarmonyPriority(800)]
			private static bool Prefix(Humanoid __instance, ItemData item, ref bool __result)
			{
				Player val = (Player)(object)((__instance is Player) ? __instance : null);
				if (val == null || !IsCosmetic(val, item))
				{
					return true;
				}
				if (((Humanoid)val).IsItemEquiped(item))
				{
					((Humanoid)val).UnequipItem(item, false);
				}
				item.m_equipped = false;
				__result = false;
				return false;
			}
		}

		[HarmonyPatch(typeof(FejdStartup), "SetupCharacterPreview")]
		private static class RefreshMenuPreview
		{
			[HarmonyPriority(0)]
			private static void Postfix(FejdStartup __instance)
			{
				Player previewPlayer = __instance.GetPreviewPlayer();
				if (Object.op_Implicit((Object)(object)previewPlayer) && Object.op_Implicit((Object)(object)((Humanoid)previewPlayer).m_visEquipment))
				{
					((Humanoid)previewPlayer).SetupVisEquipment(((Humanoid)previewPlayer).m_visEquipment, false);
				}
			}
		}

		[HarmonyPatch(typeof(Player), "QueueEquipAction")]
		private static class PreventEquipQueue
		{
			private static bool Prefix(Player __instance, ItemData item)
			{
				return !IsCosmetic(__instance, item);
			}
		}

		[HarmonyPatch(typeof(Humanoid), "SetupVisEquipment")]
		private static class VisualOverride
		{
			private static void Postfix(Humanoid __instance, VisEquipment visEq)
			{
				Player val = (Player)(object)((__instance is Player) ? __instance : null);
				if (val != null)
				{
					Apply(val, visEq);
				}
			}
		}

		[HarmonyPatch(typeof(Player), "OnInventoryChanged")]
		private static class RefreshVisuals
		{
			private static void Postfix(Player __instance)
			{
				if (!((Object)(object)__instance != (Object)(object)Slots.CurrentPlayer) && !__instance.m_isLoading && Object.op_Implicit((Object)(object)((Humanoid)__instance).m_visEquipment) && (!Object.op_Implicit((Object)(object)((Character)__instance).m_nview) || !((Character)__instance).m_nview.IsValid() || ((Character)__instance).m_nview.IsOwner()))
				{
					((Humanoid)__instance).SetupVisEquipment(((Humanoid)__instance).m_visEquipment, false);
				}
			}
		}

		[HarmonyPatch(typeof(Player), "OnSpawned")]
		private static class RefreshAfterSpawn
		{
			[HarmonyPriority(0)]
			private static void Postfix(Player __instance)
			{
				if ((Object)(object)__instance == (Object)(object)Slots.CurrentPlayer && Object.op_Implicit((Object)(object)((Humanoid)__instance).m_visEquipment) && (!Object.op_Implicit((Object)(object)((Character)__instance).m_nview) || !((Character)__instance).m_nview.IsValid() || ((Character)__instance).m_nview.IsOwner()))
				{
					((Humanoid)__instance).SetupVisEquipment(((Humanoid)__instance).m_visEquipment, false);
				}
			}
		}

		internal static bool IsVisualPlayer(Player player)
		{
			return Object.op_Implicit((Object)(object)player) && ((Object)(object)player == (Object)(object)Slots.CurrentPlayer || (Object.op_Implicit((Object)(object)FejdStartup.instance) && (Object)(object)FejdStartup.instance.GetPreviewPlayer() == (Object)(object)player));
		}

		internal static bool HandleRightClick(Player player, Inventory inventory, ItemData item, bool cosmeticTab)
		{
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)player == (Object)null || (Object)(object)player != (Object)(object)Slots.CurrentPlayer || inventory != ((Humanoid)player).GetInventory() || item == null || !inventory.ContainsItem(item))
			{
				return false;
			}
			bool flag = Slots.GetItemSlot(item)?.IsCosmeticSlot ?? false;
			Slots.Slot slot = null;
			if (!flag && cosmeticTab)
			{
				for (int i = 0; i < 4; i++)
				{
					if (Slots.slots[24 + i].ItemFits(item))
					{
						slot = Slots.slots[24 + i];
						break;
					}
				}
			}
			if (!flag && slot == null)
			{
				return false;
			}
			if (((Character)player).IsTeleporting())
			{
				return true;
			}
			ItemData val = ((slot == null) ? null : inventory.GetItemAt(slot.GridPosition.x, slot.GridPosition.y));
			Vector2i val2 = Slots.emptyPosition;
			if (flag || val != null)
			{
				if (!flag && item.m_gridPos.y < Slots.VisibleRows)
				{
					val2 = item.m_gridPos;
				}
				else
				{
					for (int j = 0; j < Slots.VisibleRows; j++)
					{
						if (!(val2 == Slots.emptyPosition))
						{
							break;
						}
						for (int k = 0; k < inventory.GetWidth(); k++)
						{
							if (inventory.GetItemAt(k, j) == null)
							{
								((Vector2i)(ref val2))..ctor(k, j);
								break;
							}
						}
					}
				}
				if (val2 == Slots.emptyPosition)
				{
					((Character)player).Message((MessageType)2, "$msg_inventoryfull", 0, (Sprite)null, false);
					return true;
				}
			}
			((Humanoid)player).RemoveEquipAction(item);
			if (((Humanoid)player).IsItemEquiped(item))
			{
				((Humanoid)player).UnequipItem(item, false);
			}
			item.m_equipped = false;
			item.m_customData.Remove("eaqs_parked");
			Slots.PruneLastEquippedSlotFromItem(item);
			if (val != null)
			{
				((Humanoid)player).RemoveEquipAction(val);
				val.m_gridPos = val2;
				Slots.PruneLastEquippedSlotFromItem(val);
			}
			item.m_gridPos = (flag ? val2 : slot.GridPosition);
			Slots.ClearCachedItems();
			inventory.Changed(false, false);
			return true;
		}

		internal static bool IsCosmetic(Player player, ItemData item)
		{
			if ((Object)(object)player == (Object)null || (Object)(object)player != (Object)(object)Slots.CurrentPlayer || item == null || !((Humanoid)player).GetInventory().ContainsItem(item))
			{
				return false;
			}
			return Slots.GetItemSlot(item)?.IsCosmeticSlot ?? false;
		}

		internal static ItemData Get(Player player, int index)
		{
			//IL_0039: 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)
			//IL_0045: 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)
			if (!IsVisualPlayer(player))
			{
				return null;
			}
			Slots.Slot slot = Slots.slots[24 + index];
			if (slot == null || !slot.IsActive)
			{
				return null;
			}
			Vector2i gridPosition = slot.GridPosition;
			ItemData itemAt = ((Humanoid)player).GetInventory().GetItemAt(gridPosition.x, gridPosition.y);
			return slot.ItemFits(itemAt) ? itemAt : null;
		}

		internal static void Apply(Player player, VisEquipment visual)
		{
			if (Object.op_Implicit((Object)(object)visual) && IsVisualPlayer(player) && (!Object.op_Implicit((Object)(object)((Character)player).m_nview) || !((Character)player).m_nview.IsValid() || ((Character)player).m_nview.IsOwner()))
			{
				ItemData val = Get(player, 0);
				ItemData val2 = Get(player, 1);
				ItemData val3 = Get(player, 2);
				ItemData val4 = Get(player, 3);
				if (Object.op_Implicit((Object)(object)val?.m_dropPrefab))
				{
					visual.SetHelmetItem(StringExtensionMethods.GetStableHashCode(((Object)val.m_dropPrefab).name));
				}
				if (Object.op_Implicit((Object)(object)val2?.m_dropPrefab))
				{
					visual.SetChestItem(StringExtensionMethods.GetStableHashCode(((Object)val2.m_dropPrefab).name));
				}
				if (Object.op_Implicit((Object)(object)val3?.m_dropPrefab))
				{
					visual.SetLegItem(StringExtensionMethods.GetStableHashCode(((Object)val3.m_dropPrefab).name));
				}
				if (Object.op_Implicit((Object)(object)val4?.m_dropPrefab))
				{
					visual.SetShoulderItem(StringExtensionMethods.GetStableHashCode(((Object)val4.m_dropPrefab).name), val4.m_variant, val4.m_quality);
				}
			}
		}
	}
	public static class DeathPatches
	{
		private class KeptItem
		{
			public ItemData item;

			public bool wasEquipped;
		}

		[HarmonyPatch(typeof(Character), "CheckDeath")]
		private static class Character_CheckDeath_OnDeathWrapping
		{
			[HarmonyPriority(800)]
			private static void Prefix(Character __instance)
			{
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: Expected O, but got Unknown
				if (Slots.IsValidPlayer(__instance) && !__instance.IsDead() && __instance.GetHealth() <= 0f)
				{
					OnDeathPrefix((Player)__instance);
				}
			}

			[HarmonyFinalizer]
			[HarmonyPriority(0)]
			private static Exception Finalizer(Character __instance, Exception __exception)
			{
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Expected O, but got Unknown
				if (Slots.IsValidPlayer(__instance))
				{
					OnDeathPostfix((Player)__instance);
				}
				return __exception;
			}
		}

		[HarmonyPatch(typeof(Player), "OnDeath")]
		private static class Player_OnDeath_RestoreKeptItems
		{
			[HarmonyPriority(0)]
			private static void Postfix(Player __instance)
			{
				if (Slots.IsValidPlayer((Character)(object)__instance))
				{
					OnDeathPostfix(__instance);
				}
			}

			[HarmonyFinalizer]
			[HarmonyPriority(0)]
			private static Exception Finalizer(Player __instance, Exception __exception)
			{
				if (Slots.IsValidPlayer((Character)(object)__instance))
				{
					OnDeathPostfix(__instance);
				}
				return __exception;
			}
		}

		[HarmonyPatch(typeof(Container), "Awake")]
		private static class Container_Awake_TombstoneHeightAdjustment
		{
			private static void Prefix(Container __instance)
			{
				if (!(__instance.m_name != "Grave") || Object.op_Implicit((Object)(object)((Component)__instance).GetComponentInParent<TombStone>()))
				{
					int num = TargetGraveHeight(__instance.m_width);
					if (num > __instance.m_height)
					{
						__instance.m_height = num;
					}
				}
			}

			private static void Postfix(Container __instance)
			{
				ZNetView nview = __instance.m_nview;
				if (nview != null && nview.IsValid() && __instance.m_nview.IsOwner() && (Object)(object)((Component)__instance).GetComponent<TombStone>() != (Object)null && __instance.m_height > 4)
				{
					string name = ((object)__instance).GetType().Name;
					__instance.m_nview.GetZDO().Set("HasFields", true);
					__instance.m_nview.GetZDO().Set(StringExtensionMethods.GetStableHashCode("HasFields" + name), true);
					__instance.m_nview.GetZDO().Set(name + ".m_height", __instance.m_height);
				}
			}
		}

		[HarmonyPatch(typeof(TombStone), "Setup")]
		private static class TombStone_Setup_PersistGraveDimensions
		{
			private static void Postfix(TombStone __instance)
			{
				Container val = (((Object)(object)__instance.m_container != (Object)null) ? __instance.m_container : ((Component)__instance).GetComponent<Container>());
				if (!((Object)(object)val == (Object)null) && val.m_inventory != null)
				{
					val.m_width = Mathf.Max(val.m_width, val.m_inventory.m_width);
					val.m_height = Mathf.Max(val.m_height, val.m_inventory.m_height);
					ZNetView nview = val.m_nview;
					if (nview != null && nview.IsValid() && val.m_nview.IsOwner())
					{
						string name = ((object)val).GetType().Name;
						ZDO zDO = val.m_nview.GetZDO();
						zDO.Set("HasFields", true);
						zDO.Set(StringExtensionMethods.GetStableHashCode("HasFields" + name), true);
						zDO.Set(name + ".m_width", val.m_width);
						zDO.Set(name + ".m_height", val.m_height);
					}
				}
			}
		}

		[HarmonyPatch(typeof(TombStone), "Interact")]
		private static class TombStone_Interact_AdjustHeight
		{
			[HarmonyPriority(800)]
			private static void Prefix(TombStone __instance, bool hold)
			{
				if (!hold)
				{
					int num = TargetGraveHeight(__instance.m_container.m_width);
					if (num > __instance.m_container.m_height)
					{
						__instance.m_container.m_height = num;
						__instance.m_container.m_inventory.m_height = num;
						__instance.m_container.m_lastRevision = 0u;
						__instance.m_container.Load();
					}
				}
			}
		}

		[HarmonyPatch(typeof(TombStone), "EasyFitInInventory")]
		private static class TombStone_EasyFitInInventory_SlotAwareCounting
		{
			private static float GetDynamicWeightChange(StatusEffect se)
			{
				float result = 0f;
				se.ModifyMaxCarryWeight(0f, ref result);
				return result;
			}

			private static void Prefix(TombStone __instance, Player player, ref float __state)
			{
				if (!Slots.IsValidPlayer((Character)(object)player))
				{
					return;
				}
				StatusEffect lootStatusEffect = __instance.m_lootStatusEffect;
				__state = ((SE_Stats)(((lootStatusEffect is SE_Stats) ? lootStatusEffect : null)?)).m_addMaxCarryWeight ?? 0f;
				if (ValConfig.AutoEquipCarryWeightItems.Value || ValConfig.InstantlyReequipArmorOnPickup.Value)
				{
					__state += __instance.m_container.GetInventory().GetAllItems().Where(delegate(ItemData item)
					{
						//IL_0017: Unknown result type (might be due to invalid IL or missing references)
						int result;
						if (item != null && (Object)(object)item.m_shared.m_equipStatusEffect != (Object)null)
						{
							Slots.Slot slotInGrid = Slots.GetSlotInGrid(item.m_gridPos);
							if (slotInGrid != null)
							{
								result = (slotInGrid.IsEquipmentSlot ? 1 : 0);
								goto IL_002e;
							}
						}
						result = 0;
						goto IL_002e;
						IL_002e:
						return (byte)result != 0;
					})
						.Sum((ItemData item) => GetDynamicWeightChange(item.m_shared.m_equipStatusEffect));
				}
				Player localPlayer = Player.m_localPlayer;
				localPlayer.m_maxCarryWeight += __state;
			}

			private static void Postfix(TombStone __instance, Player player, float __state, ref bool __result)
			{
				//IL_0083: Unknown result type (might be due to invalid IL or missing references)
				if (!Slots.IsValidPlayer((Character)(object)player))
				{
					return;
				}
				Player localPlayer = Player.m_localPlayer;
				localPlayer.m_maxCarryWeight -= __state;
				if (__result || __instance.m_container.GetInventory().NrOfItems() > Slots.InventorySizeActive)
				{
					return;
				}
				int num = 0;
				takenSlots.Clear();
				foreach (ItemData item in __instance.m_container.GetInventory().GetAllItemsInGridOrder())
				{
					Slots.Slot slotInGrid = Slots.GetSlotInGrid(item.m_gridPos);
					if (slotInGrid == null || takenSlots.Contains(slotInGrid))
					{
						num++;
						continue;
					}
					takenSlots.Add(slotInGrid);
					if (!slotInGrid.IsEquipmentSlot || !slotInGrid.IsFree || !Slots.WouldFitEquipmentSlot(slotInGrid, item))
					{
						num++;
					}
				}
				__result = num <= Slots.PlayerInventory.GetEmptySlots() && ((Humanoid)player).GetInventory().GetTotalWeight() + __instance.m_container.GetInventory().GetTotalWeight() < player.GetMaxCarryWeight() + __state;
			}
		}

		[HarmonyPatch(typeof(TombStone), "OnTakeAllSuccess")]
		private static class TombStone_OnTakeAllSuccess_AutoEquip
		{
			private static void Postfix()
			{
				AutoEquipAndParkReturnedItems();
			}
		}

		[HarmonyPatch(typeof(InventoryGui), "OnTakeAll")]
		private static class InventoryGui_OnTakeAll_AutoEquip
		{
			private static void Postfix(InventoryGui __instance)
			{
				if ((Object)(object)__instance.m_currentContainer != (Object)null && (Object)(object)((Component)__instance.m_currentContainer).GetComponent<TombStone>() != (Object)null)
				{
					AutoEquipAndParkReturnedItems();
				}
			}
		}

		private static readonly List<KeptItem> itemsToKeep = new List<KeptItem>();

		private static readonly HashSet<Slots.Slot> takenSlots = new HashSet<Slots.Slot>();

		public static readonly int AfterdeathGhost = StringExtensionMethods.GetStableHashCode("Afterdeath Ghost");

		private const string legacyEquipmentKey = "eaqs-e";

		private const string legacyQuickSlotKey = "eaqs-qs";

		public static void OnDeathPrefix(Player player)
		{
			if (itemsToKeep.Count != 0)
			{
				return;
			}
			Slots.SaveLastEquippedSlotsToItems();
			SaveLastEquippedWeaponShieldToItems(player);
			Slots.Slot[] slots = Slots.slots;
			foreach (Slots.Slot slot in slots)
			{
				if (IsSlotToKeep(slot))
				{
					ItemData item = slot.Item;
					itemsToKeep.Add(new KeptItem
					{
						item = item,
						wasEquipped = (item.m_equipped || ((Humanoid)player).IsItemEquiped(item))
					});
					((Humanoid)player).GetInventory().m_inventory.Remove(item);
				}
			}
			Slots.ClearCachedItems();
		}

		private static bool IsSlotToKeep(Slots.Slot slot)
		{
			if (slot.Item == null)
			{
				return false;
			}
			return ((slot.IsEquipmentSlot || slot.IsCustomSlot || slot.IsCosmeticSlot) && ValConfig.DontDropEquipmentOnDeath.Value) || (slot.IsQuickSlot && ValConfig.DontDropQuickslotsOnDeath.Value);
		}

		public static void OnDeathPostfix(Player player)
		{
			if (itemsToKeep.Count == 0)
			{
				return;
			}
			foreach (KeptItem item in itemsToKeep)
			{
				item.item.m_equipped = item.wasEquipped;
				((Humanoid)player).GetInventory().m_inventory.Add(item.item);
			}
			itemsToKeep.Clear();
			Slots.ClearCachedItems();
		}

		private static void SaveLastEquippedWeaponShieldToItems(Player player)
		{
			long playerID = Game.instance.GetPlayerProfile().GetPlayerID();
			if (((Humanoid)player).LeftItem != null)
			{
				((Humanoid)player).LeftItem.m_customData["eaqs_weaponshield"] = playerID.ToString();
			}
			if (((Humanoid)player).RightItem != null)
			{
				((Humanoid)player).RightItem.m_customData["eaqs_weaponshield"] = playerID.ToString();
			}
		}

		private static int TargetGraveHeight(int width)
		{
			return (Slots.InventorySizeFull - 1) / Mathf.Max(1, width) + 1;
		}

		private static void AutoEquipAndParkReturnedItems()
		{
			Player currentPlayer = Slots.CurrentPlayer;
			if ((Object)(object)currentPlayer == (Object)null || Slots.PlayerInventory == null || ((Character)currentPlayer).IsDead())
			{
				return;
			}
			string playerID = Game.instance.GetPlayerProfile().GetPlayerID().ToString();
			foreach (ItemData item in Slots.PlayerInventory.GetAllItems().ToList())
			{
				if (item == null)
				{
					continue;
				}
				if (item.m_equipped && !((Humanoid)currentPlayer).IsItemEquiped(item))
				{
					item.m_equipped = false;
				}
				HandleLegacyMarkers(currentPlayer, item);
				if (IsItemToEquip(currentPlayer, item, playerID))
				{
					PruneWeaponShieldKey(item);
					if (!((Humanoid)currentPlayer).IsItemEquiped(item))
					{
						((Humanoid)currentPlayer).EquipItem(item, false);
					}
				}
				else if (!((Humanoid)currentPlayer).IsItemEquiped(item))
				{
					Slots.Slot itemSlot = Slots.GetItemSlot(item);
					if (itemSlot != null && itemSlot.IsEquipmentSlot && Slots.WouldFitEquipmentSlot(itemSlot, item))
					{
						itemSlot.Park(item);
					}
				}
			}
		}

		private static bool IsItemToEquip(Player player, ItemData item, string playerID)
		{
			if (ValConfig.AutoEquipCarryWeightItems.Value)
			{
				StatusEffect equipStatusEffect = item.m_shared.m_equipStatusEffect;
				SE_Stats val = (SE_Stats)(object)((equipStatusEffect is SE_Stats) ? equipStatusEffect : null);
				if (val != null && val.m_addMaxCarryWeight > 0f)
				{
					return true;
				}
			}
			if (ValConfig.AutoEquipWeaponShield.Value && item.m_customData.TryGetValue("eaqs_weaponshield", out var value) && value == playerID)
			{
				return true;
			}
			if (ValConfig.InstantlyReequipArmorOnPickup.Value && item.m_customData.TryGetValue("eaqs_player", out var value2) && value2 == playerID && item.m_customData.TryGetValue("eaqs_slot", out var value3))
			{
				Slots.Slot slot = Slots.FindSlot(value3);
				if (slot != null && slot.IsEquipmentSlot)
				{
					return true;
				}
			}
			return false;
		}

		private static void PruneWeaponShieldKey(ItemData item)
		{
			item.m_customData.Remove("eaqs_weaponshield");
		}

		private static void HandleLegacyMarkers(Player player, ItemData item)
		{
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			if (item.m_customData.Remove("eaqs-e") && ValConfig.InstantlyReequipArmorOnPickup.Value && !((Humanoid)player).IsItemEquiped(item))
			{
				((Humanoid)player).EquipItem(item, false);
			}
			if (!item.m_customData.TryGetValue("eaqs-qs", out var value))
			{
				return;
			}
			item.m_customData.Remove("eaqs-qs");
			string[] array = value.Split(',');
			if (array.Length >= 1 && int.TryParse(array[0], out var result) && result >= 0 && result < 6)
			{
				Slots.Slot slot = Slots.slots[result];
				if (slot != null && slot.IsFreeQuickSlot())
				{
					item.m_gridPos = slot.GridPosition;
					slot.ClearItemCache();
					((Humanoid)player).GetInventory().Changed(false, false);
				}
			}
		}
	}
	public static class EquipmentPanel
	{
		private class PanelDragHandle : MonoBehaviour, IBeginDragHandler, IEventSystemHandler, IDragHandler, IEndDragHandler
		{
			private bool _dragging;

			private float _scaleFactor = 1f;

			public void OnBeginDrag(PointerEventData eventData)
			{
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Invalid comparison between Unknown and I4
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				if (CanDrag && (int)eventData.button <= 0)
				{
					_dragging = true;
					_dragPosition = PanelBase;
					Canvas componentInParent = ((Component)this).GetComponentInParent<Canvas>();
					_scaleFactor = ((componentInParent != null) ? componentInParent.scaleFactor : 1f);
					if (_scaleFactor <= 0f)
					{
						_scaleFactor = 1f;
					}
				}
			}

			public void OnDrag(PointerEventData eventData)
			{
				//IL_0024: 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)
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				if (_dragging && _dragPosition.HasValue)
				{
					_dragPosition = _dragPosition.Value + eventData.delta / _scaleFactor;
				}
			}

			public void OnEndDrag(PointerEventData eventData)
			{
				//IL_002f: Unknown result type (might be due to invalid IL or missing references)
				if (_dragging)
				{
					_dragging = false;
					if (_dragPosition.HasValue)
					{
						ValConfig.EquipmentPanelPosition.Value = _dragPosition.Value;
					}
					_dragPosition = null;
				}
			}

			private void OnDisable()
			{
				if (_dragging)
				{
					OnEndDrag(null);
				}
			}
		}

		[HarmonyPatch(typeof(InventoryGui), "OnDestroy")]
		private static class InventoryGui_OnDestroy_ClearPanel
		{
			private static void Postfix()
			{
				ClearPanel();
				AugaPanel.Clear();
			}
		}

		[HarmonyPatch(typeof(InventoryGui), "Update")]
		private static class InventoryGui_Update_UpdateEquipmentPanel
		{
			private static void Postfix()
			{
				if (Object.op_Implicit((Object)(object)Player.m_localPlayer) && InventoryGui.IsVisible())
				{
					if (EquipmentAndQuickSlots.HasAuga)
					{
						AugaPanel.UpdatePanel();
					}
					else
					{
						UpdateEquipmentBackground();
					}
				}
			}
		}

		[HarmonyPatch(typeof(InventoryGrid), "UpdateGui")]
		private static class InventoryGrid_UpdateGui_RelocateSlotElements
		{
			private static void Postfix(InventoryGrid __instance)
			{
				if (Object.op_Implicit((Object)(object)InventoryGui.instance) && !((Object)(object)__instance != (Object)(object)InventoryGui.instance.m_playerGrid) && !((Object)(object)Player.m_localPlayer == (Object)null))
				{
					UpdateInventorySlots();
				}
			}
		}

		private static Vector2? _dragPosition;

		private const float elementSpace = 70f;

		private const float slotSpacing = 80f;

		private static readonly Vector2 equipmentOrigin = new Vector2(60.5f, -27f);

		private static readonly Vector2[] equipmentOffsets = (Vector2[])(object)new Vector2[8]
		{
			new Vector2(0f, 0f),
			new Vector2(0f, -80f),
			new Vector2(0f, -160f),
			new Vector2(80f, -40f),
			new Vector2(80f, -120f),
			new Vector2(80f, -200f),
			new Vector2(160f, -120f),
			new Vector2(160f, -200f)
		};

		private static readonly Vector2 equipmentBackgroundCenter = new Vector2(132.5f, -159f);

		private static readonly Vector2 equipmentBackgroundSize = new Vector2(210f, 300f);

		private static readonly Vector2 equipmentLabelPosition = new Vector2(32f, 5f);

		private const float rowLeft = 25.5f;

		private const float rowGap = 20f;

		private const float quickRowTop = -342f;

		private const float rowBackgroundLeft = 14.5f;

		private const float rowBackgroundHeight = 90f;

		private const float rowBackgroundPitch = 74f;

		private const float customRowTop = -452f;

		private const int customSlotsPerRow = 3;

		private static readonly Vector2 paperdollOffset = new Vector2(-35f, 0f);

		private static float originalLabelFontSize;

		private static RectTransform inventoryBackground;

		private static Image inventoryBackgroundImage;

		private static RectTransform inventoryDarken;

		private static RectTransform inventorySelectedFrame;

		private static Vector2? containerOriginalPivot;

		private static RectTransform equipmentBackground;

		private static RectTransform quickBackground;

		private static RectTransform customBackground;

		private static RectTransform slotRoot;

		private static RectTransform hiddenRoot;

		private static GameObject paperdoll;

		private static RectTransform[] paperdollImages;

		private static Color normalColor = Color.clear;

		private static Color highlightedColor = Color.clear;

		private static readonly Vector3[] inventoryCorners = (Vector3[])(object)new Vector3[4];

		private static readonly Vector3[] containerCorners = (Vector3[])(object)new Vector3[4];

		private static Vector2 PanelBase => (Vector2)(((??)_dragPosition) ?? ValConfig.EquipmentPanelPosition.Value);

		private static bool CanDrag
		{
			get
			{
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: 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)
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				int result;
				if (!ValConfig.EquipmentPanelDraggable.Value)
				{
					KeyboardShortcut value = ValConfig.EquipmentPanelDragKey.Value;
					if ((int)((KeyboardShortcut)(ref value)).MainKey != 0)
					{
						value = ValConfig.EquipmentPanelDragKey.Value;
						result = (ZInput.GetKey(((KeyboardShortcut)(ref value)).MainKey, true) ? 1 : 0);
					}
					else
					{
						result = 0;
					}
				}
				else
				{
					result = 1;
				}
				return (byte)result != 0;
			}
		}

		private static float ExtraUtilityColumnWidth => (Slots.ActiveExtraUtilitySlots > 0) ? 80f : 0f;

		private static Vector2 EquipmentBackgroundSize => equipmentBackgroundSize + new Vector2(ExtraUtilityColumnWidth, 0f);

		private static Vector2 EquipmentBackgroundCenter => equipmentBackgroundCenter + new Vector2(ExtraUtilityColumnWidth / 2f, 0f);

		private static int ActiveQuickSlots => ValConfig.QuickSlotsEnabled.Value ? ValConfig.QuickSlotCount.Value : 0;

		private static bool EquipmentVisible => ValConfig.EquipmentSlotsEnabled.Value;

		private static Slots.Slot[] ActiveCustomSlots => (from slot in Slots.GetCustomSlots()
			where slot.IsActive
			orderby slot.Index
			select slot).ToArray();

		internal static Vector2 GetSlotPosition(Slots.Slot slot)
		{
			//IL_000b: 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_0015: 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)
			//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_0041: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: 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_00b8: 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)
			if (slot.IsEquipmentSlot)
			{
				return PanelBase + equipmentOrigin + equipmentOffsets[slot.Index - 8];
			}
			if (slot.IsQuickSlot)
			{
				return PanelBase + new Vector2(25.5f + (float)slot.Index * 70f, -342f);
			}
			if (slot.IsCustomSlot)
			{
				int num = Math.Max(0, Array.IndexOf(ActiveCustomSlots, slot));
				int num2 = num % 3;
				int num3 = num / 3;
				return PanelBase + new Vector2(25.5f + (float)num2 * 70f, -452f - (float)num3 * 70f);
			}
			return PanelBase;
		}

		internal static void UpdateEquipmentBackground()
		{
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: 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_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)InventoryGui.instance) || !Object.op_Implicit((Object)(object)InventoryGui.instance.m_player))
			{
				return;
			}
			if ((Object)(object)inventoryBackground == (Object)null)
			{
				Transform obj = ((Transform)InventoryGui.instance.m_player).Find("Bkg");
				inventoryBackground = ((obj != null) ? ((Component)obj).GetComponent<RectTransform>() : null);
				RectTransform obj2 = inventoryBackground;
				inventoryBackgroundImage = ((obj2 != null) ? ((Component)obj2).GetComponent<Image>() : null);
				Transform obj3 = ((Transform)InventoryGui.instance.m_player).Find("Darken");
				inventoryDarken = ((obj3 != null) ? ((Component)obj3).GetComponent<RectTransform>() : null);
				UIGroupHandler component = ((Component)InventoryGui.instance.m_player).GetComponent<UIGroupHandler>();
				object obj4;
				if (component == null)
				{
					obj4 = null;
				}
				else
				{
					GameObject enableWhenActiveAndGamepad = component.m_enableWhenActiveAndGamepad;
					obj4 = ((enableWhenActiveAndGamepad != null) ? enableWhenActiveAndGamepad.transform.GetChild(0) : null);
				}
				inventorySelectedFrame = (RectTransform)((obj4 is RectTransform) ? obj4 : null);
			}
			if (!((Object)(object)inventoryBackground == (Object)null))
			{
				UpdateInventoryPanelForExtraRows();
				if (!Object.op_Implicit((Object)(object)equipmentBackground))
				{
					equipmentBackground = CreateBackground("EaqsEquipmentBkg");
				}
				if (!Object.op_Implicit((Object)(object)quickBackground))
				{
					quickBackground = CreateBackground("EaqsQuickSlotBkg");
				}
				if (!Object.op_Implicit((Object)(object)customBackground))
				{
					customBackground = CreateBackground("EaqsCustomSlotBkg");
				}
				SyncBackground(equipmentBackground, EquipmentVisible, PanelBase + EquipmentBackgroundCenter, EquipmentBackgroundSize);
				UpdatePaperdoll();
				int activeQuickSlots = ActiveQuickSlots;
				SyncBackground(quickBackground, activeQuickSlots > 0, RowBackgroundCenter(activeQuickSlots, -342f), RowBackgroundSize(activeQuickSlots));
				int num = ActiveCustomSlots.Length;
				int rows = (num + 3 - 1) / 3;
				SyncBackground(customBackground, num > 0, CustomBackgroundCenter(num, rows), CustomBackgroundSize(num, rows));
			}
		}

		private static void UpdatePaperdoll()
		{
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: 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_00b2: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			if (!ValConfig.ShowPaperdoll.Value || !EquipmentVisible || !((Object)(object)EquipmentAndQuickSlots.Paperdolls != (Object)null) || !Object.op_Implicit((Object)(object)equipmentBackground))
			{
				if (Object.op_Implicit((Object)(object)paperdoll))
				{
					paperdoll.SetActive(false);
				}
				return;
			}
			if (!Object.op_Implicit((Object)(object)paperdoll))
			{
				paperdoll = Object.Instantiate<GameObject>(EquipmentAndQuickSlots.Paperdolls, (Transform)(object)equipmentBackground, false);
				((Object)paperdoll).name = "Paperdolls";
				RectTransform component = paperdoll.GetComponent<RectTransform>();
				component.anchorMin = Vector2.zero;
				component.anchorMax = Vector2.one;
				component.pivot = new Vector2(0.5f, 0.5f);
				component.offsetMin = Vector2.zero;
				component.offsetMax = Vector2.zero;
				((Transform)component).SetAsFirstSibling();
				Image[] componentsInChildren = paperdoll.GetComponentsInChildren<Image>(true);
				paperdollImages = (RectTransform[])(object)new RectTransform[componentsInChildren.Length];
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					((Graphic)componentsInChildren[i]).raycastTarget = false;
					componentsInChildren[i].preserveAspect = true;
					paperdollImages[i] = ((Graphic)componentsInChildren[i]).rectTransform;
				}
			}
			paperdoll.SetActive(true);
			Vector2 anchoredPosition = paperdollOffset - new Vector2(ExtraUtilityColumnWidth / 2f, 0f);
			RectTransform[] array = paperdollImages;
			foreach (RectTransform val in array)
			{
				val.anchoredPosition = anchoredPosition;
			}
			Player localPlayer = Player.m_localPlayer;
			bool flag = (Object)(object)localPlayer != (Object)null && (Object)(object)((Humanoid)localPlayer).m_visEquipment != (Object)null && ((Humanoid)localPlayer).m_visEquipment.GetModelIndex() == 1;
			Transform obj = paperdoll.transform.Find("Male");
			if (obj != null)
			{
				((Component)obj).gameObject.SetActive(!flag);
			}
			Transform obj2 = paperdoll.transform.Find("Female");
			if (obj2 != null)
			{
				((Component)obj2).gameObject.SetActive(flag);
			}
		}

		private static void UpdateInventoryPanelForExtraRows()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: 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_0103: 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)
			int extraRows = Slots.ExtraRows;
			float num = -1f * ((float)extraRows / (float)Slots.BaseRows - 0.01f * (float)Math.Max(extraRows - 1, 0));
			inventoryBackground.anchorMin = new Vector2(0f, num);
			if (Object.op_Implicit((Object)(object)inventoryDarken))
			{
				inventoryDarken.anchorMin = inventoryBackground.anchorMin;
			}
			if (Object.op_Implicit((Object)(object)inventorySelectedFrame))
			{
				inventorySelectedFrame.anchorMin = inventoryBackground.anchorMin;
			}
			RectTransform container = InventoryGui.instance.m_container;
			if (!Object.op_Implicit((Object)(object)container))
			{
				return;
			}
			if (EquipmentAndQuickSlots.HasAuga)
			{
				FollowInventoryBackground(inventoryBackground, container);
				return;
			}
			if (!containerOriginalPivot.HasValue)
			{
				containerOriginalPivot = container.pivot;
			}
			container.pivot = new Vector2(containerOriginalPivot.Value.x, containerOriginalPivot.Value.y + (float)extraRows * 0.2f);
		}

		internal static void FollowInventoryBackground(RectTransform background, RectTransform container)
		{
			//IL_0075: 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_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)background) && Object.op_Implicit((Object)(object)container) && Object.op_Implicit((Object)(object)((Transform)container).parent))
			{
				Transform obj = ((Transform)container).Find("Bkg");
				RectTransform val = (RectTransform)(object)((obj is RectTransform) ? obj : null);
				if (!Object.op_Implicit((Object)(object)val))
				{
					val = container;
				}
				background.GetWorldCorners(inventoryCorners);
				val.GetWorldCorners(containerCorners);
				Transform parent = ((Transform)container).parent;
				float y = parent.InverseTransformPoint(inventoryCorners[0]).y;
				float y2 = parent.InverseTransformPoint(containerCorners[1]).y;
				Vector2 anchoredPosition = container.anchoredPosition;
				anchoredPosition.y += y - 8f - y2;
				container.anchoredPosition = anchoredPosition;
			}
		}

		private static Vector2 RowBackgroundSize(int slotCount)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			return new Vector2(74f * (float)slotCount + 10f, 90f);
		}

		private static Vector2 CustomBackgroundSize(int slotCount, int rows)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			return new Vector2(74f * (float)Math.Min(slotCount, 3) + 10f, 90f + (float)Math.Max(0, rows - 1) * 70f);
		}

		private static Vector2 CustomBackgroundCenter(int slotCount, int rows)
		{
			//IL_0000: 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_0039: 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)
			return PanelBase + new Vector2(14.5f + CustomBackgroundSize(slotCount, rows).x / 2f, -484f - (float)Math.Max(0, rows - 1) * 70f / 2f);
		}

		private static Vector2 RowBackgroundCenter(int slotCount, float rowTop)
		{
			//IL_0000: 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)
			//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)
			return PanelBase + new Vector2(14.5f + RowBackgroundSize(slotCount).x / 2f, rowTop - 32f);
		}

		private static RectTransform CreateBackground(string name)
		{
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: 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_00c8: Unknown result type (might be due to invalid IL or missing references)
			Transform player = (Transform)(object)InventoryGui.instance.m_player;
			UIGroupHandler component = ((Component)player).GetComponent<UIGroupHandler>();
			object obj;
			if (component == null)
			{
				obj = null;
			}
			else
			{
				GameObject enableWhenActiveAndGamepad = component.m_enableWhenActiveAndGamepad;
				obj = ((enableWhenActiveAndGamepad != null) ? enableWhenActiveAndGamepad.transform : null);
			}
			Transform val = (Transform)obj;
			Transform val2 = player.Find("Darken");
			RectTransform val3 = Object.Instantiate<RectTransform>(inventoryBackground, player, false);
			((Object)val3).name = name;
			int num = (((Object)(object)val != (Object)null) ? val.GetSiblingIndex() : (((Object)(object)val2 != (Object)null) ? val2.GetSiblingIndex() : ((Transform)inventoryBackground).GetSiblingIndex()));
			((Transform)val3).SetSiblingIndex(num + 1);
			val3.anchorMin = new Vector2(0f, 1f);
			val3.anchorMax = new Vector2(0f, 1f);
			val3.pivot = new Vector2(0.5f, 0.5f);
			((Transform)val3).localScale = Vector3.one;
			Image component2 = ((Component)val3).GetComponent<Image>();
			if (Object.op_Implicit((Object)(object)component2))
			{
				((Graphic)component2).raycastTarget = true;
			}
			((Component)val3).gameObject.AddComponent<PanelDragHandle>();
			return val3;
		}

		private static void SyncBackground(RectTransform background, bool visible, Vector2 center, Vector2 size)
		{
			//IL_0028: 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_0080: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)background))
			{
				return;
			}
			((Component)background).gameObject.SetActive(visible);
			if (visible)
			{
				background.sizeDelta = size;
				background.anchoredPosition = center;
				Image component = ((Component)background).GetComponent<Image>();
				if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)inventoryBackgroundImage))
				{
					component.sprite = inventoryBackgroundImage.sprite;
					component.overrideSprite = inventoryBackgroundImage.overrideSprite;
					((Graphic)component).color = ((Graphic)inventoryBackgroundImage).color;
				}
			}
		}

		private static RectTransform EnsureSlotRoot(InventoryGrid grid)
		{
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: 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_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			RectTransform gridRoot = grid.m_gridRoot;
			if (!Object.op_Implicit((Object)(object)gridRoot) || !Object.op_Implicit((Object)(object)((Transform)gridRoot).parent) || !Object.op_Implicit((Object)(object)InventoryGui.instance.m_player))
			{
				return null;
			}
			if (!Object.op_Implicit((Object)(object)slotRoot))
			{
				slotRoot = new GameObject("EaqsSlotRoot", new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>();
				((Transform)slotRoot).SetParent((Transform)(object)InventoryGui.instance.m_player, false);
				((Transform)slotRoot).localScale = Vector3.one;
				((Transform)slotRoot).localRotation = Quaternion.identity;
				((Transform)slotRoot).SetAsLastSibling();
			}
			slotRoot.anchorMin = Vector2.zero;
			slotRoot.anchorMax = Vector2.zero;
			slotRoot.pivot = gridRoot.pivot;
			RectTransform obj = slotRoot;
			Rect rect = gridRoot.rect;
			obj.sizeDelta = ((Rect)(ref rect)).size;
			Vector3 point = ((Transform)gridRoot).localPosition - Vector2.op_Implicit(gridRoot.anchoredPosition);
			if (TryTransformToPanelSpace(((Transform)gridRoot).parent, ((Transform)slotRoot).parent, ref point))
			{
				((Transform)slotRoot).localPosition = point;
			}
			else
			{
				((Transform)slotRoot).position = ((Transform)gridRoot).parent.TransformPoint(point);
			}
			return slotRoot;
		}

		private static bool TryTransformToPanelSpace(Transform from, Transform panel, ref Vector3 point)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_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_003c: 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)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = point;
			Transform val2 = from;
			while ((Object)(object)val2 != (Object)null)
			{
				if ((Object)(object)val2 == (Object)(object)panel)
				{
					point = val;
					return true;
				}
				val = val2.localPosition + val2.localRotation * Vector3.Scale(val2.localScale, val);
				val2 = val2.parent;
			}
			return false;
		}

		private static RectTransform EnsureHiddenRoot()
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)hiddenRoot) || !Object.op_Implicit((Object)(object)InventoryGui.instance.m_player))
			{
				return hiddenRoot;
			}
			hiddenRoot = new GameObject("EaqsHiddenSlotRoot", new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>();
			((Transform)hiddenRoot).SetParent((Transform)(object)InventoryGui.instance.m_player, false);
			((Transform)hiddenRoot).localScale = Vector3.one;
			((Transform)hiddenRoot).localRotation = Quaternion.identity;
			hiddenRoot.anchorMin = Vector2.zero;
			hiddenRoot.anchorMax = Vector2.zero;
			hiddenRoot.anchoredPosition = new Vector2(-100000f, 0f);
			((Component)hiddenRoot).gameObject.SetActive(false);
			return hiddenRoot;
		}

		private static void ParkHiddenCell(GameObject go, RectTransform holder)
		{
			if (Object.op_Implicit((Object)(object)go))
			{
				go.SetActive(false);
				if (Object.op_Implicit((Object)(object)holder) && (Object)(object)go.transform.parent != (Object)(object)holder)
				{
					go.transform.SetParent((Transform)(object)holder, false);
				}
			}
		}

		internal static void UpdateInventorySlots()
		{
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			InventoryGrid playerGrid = InventoryGui.instance.m_playerGrid;
			playerGrid.m_gridRoot.SetSizeWithCurrentAnchors((Axis)1, (float)Slots.VisibleRows * playerGrid.m_elementSpace);
			int inventorySizeVisible = Slots.InventorySizeVisible;
			ItemData dragItem = InventoryGui.instance.m_dragItem;
			RectTransform val = EnsureSlotRoot(playerGrid);
			RectTransform holder = EnsureHiddenRoot();
			Transform val2 = (Transform)(object)(Object.op_Implicit((Object)(object)val) ? val : playerGrid.m_gridRoot);
			for (int i = 0; i < Math.Min(Slots.slots.Length, playerGrid.m_elements.Count - inventorySizeVisible); i++)
			{
				InventoryElement val3 = playerGrid.m_elements[inventorySizeVisible + i];
				Slots.Slot slot = Slots.slots[i];
				GameObject val4 = ((val3 != null) ? ((Component)val3).gameObject : null);
				if (!Object.op_Implicit((Object)(object)val4))
				{
					continue;
				}
				if (!slot.IsActive)
				{
					ParkHiddenCell(val4, holder);
					continue;
				}
				val4.SetActive(true);
				if (Object.op_Implicit((Object)(object)val2) && (Object)(object)val4.transform.parent != (Object)(object)val2)
				{
					val4.transform.SetParent(val2, false);
				}
				val4.GetComponent<RectTransform>().anchoredPosition = (EquipmentAndQuickSlots.HasAuga ? AugaPanel.GetSlotPosition(slot) : GetSlotPosition(slot));
				SetSlotLabel(val4.transform.Find("binding"), slot);
				SetSlotColor(val4.GetComponent<Button>(), dragItem != null && !DragItemFits(slot, dragItem));
			}
			for (int j = inventorySizeVisible + Slots.slots.Length; j < playerGrid.m_elements.Count; j++)
			{
				InventoryElement obj = playerGrid.m_elements[j];
				ParkHiddenCell((obj != null) ? ((Component)obj).gameObject : null, holder);
			}
		}

		private static bool DragItemFits(Slots.Slot slot, ItemData dragItem)
		{
			if (slot.IsEquipmentSlot)
			{
				return Slots.WouldFitEquipmentSlot(slot, dragItem);
			}
			return slot.ItemFits(dragItem);
		}

		private static void SetSlotLabel(Transform binding, Slots.Slot slot)
		{
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)binding))
			{
				return;
			}
			TMP_Text component = ((Component)binding).GetComponent<TMP_Text>();
			if (!Object.op_Implicit((Object)(object)component))
			{
				return;
			}
			if (EquipmentAndQuickSlots.HasAuga && slot.IsEquipmentSlot)
			{
				((Behaviour)component).enabled = false;
				return;
			}
			if (originalLabelFontSize <= 0f && !component.enableAutoSizing)
			{
				originalLabelFontSize = component.fontSize;
			}
			((Component)binding).gameObject.SetActive(true);
			((Behaviour)component).enabled = true;
			component.overflowMode = (TextOverflowModes)0;
			component.textWrappingMode = (TextWrappingModes)0;
			component.text = (slot.IsHotkeySlot ? slot.GetShortcutText() : slot.Name);
			if (slot.IsEquipmentSlot)
			{
				component.rectTransform.anchoredPosition = equipmentLabelPosition;
			}
			if (slot.IsCustomSlot)
			{
				component.rectTransform.anchoredPosition = equipmentLabelPosition;
				component.rectTransform.sizeDelta = new Vector2(64f, component.rectTransform.sizeDelta.y);
				component.overflowMode = (TextOverflowModes)1;
				if (originalLabelFontSize > 0f)
				{
					component.fontSizeMax = originalLabelFontSize;
					component.fontSizeMin = Mathf.Min(10f, originalLabelFontSize);
					component.enableAutoSizing = true;
				}
			}
		}

		private static void SetSlotColor(Button button, bool unfit)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_0028: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: U