Decompiled source of CDEV EquipmentSlots v0.1.23

plugins/CDEV.EquipmentSlots/CDEV.EquipmentSlots.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Utilities;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("assembly_guiutils")]
[assembly: IgnoresAccessChecksTo("assembly_utils")]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("CDEV.EquipmentSlots")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.23.0")]
[assembly: AssemblyInformationalVersion("0.1.23+efb24945142928ac03192750576c1d4fe797e026")]
[assembly: AssemblyProduct("CDEV.EquipmentSlots")]
[assembly: AssemblyTitle("CDEV.EquipmentSlots")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.23.0")]
[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 CDEV.EquipmentSlots
{
	[HarmonyPatch]
	internal static class AmmoRefill
	{
		private static string s_ranOutName;

		private static string s_ranOutType;

		[HarmonyPatch(typeof(Attack), "UseAmmo")]
		[HarmonyPostfix]
		private static void UseAmmo(Attack __instance, ref ItemData ammoItem, bool __result)
		{
			if (Plugin.Active && __result && ammoItem != null && ModConfig.AutoEquipAmmo.Value)
			{
				Humanoid character = __instance.m_character;
				Player val = (Player)(object)((character is Player) ? character : null);
				if (val != null && !((Object)(object)val != (Object)(object)Player.m_localPlayer) && (!((Humanoid)val).GetInventory().ContainsItem(ammoItem) || ammoItem.m_stack <= 0))
				{
					s_ranOutName = ammoItem.m_shared.m_name;
					s_ranOutType = ammoItem.m_shared.m_ammoType;
				}
			}
		}

		internal static void Tick()
		{
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Invalid comparison between Unknown and I4
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Invalid comparison between Unknown and I4
			if (s_ranOutType == null)
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead())
			{
				s_ranOutType = null;
			}
			else
			{
				if (((Character)localPlayer).InAttack())
				{
					return;
				}
				string text = s_ranOutName;
				string text2 = s_ranOutType;
				s_ranOutName = (s_ranOutType = null);
				ItemData ammoItem = ((Humanoid)localPlayer).GetAmmoItem();
				if (ammoItem != null && ((Humanoid)localPlayer).GetInventory().ContainsItem(ammoItem) && ammoItem.m_shared.m_ammoType == text2)
				{
					return;
				}
				Inventory inventory = ((Humanoid)localPlayer).GetInventory();
				ItemData val = null;
				foreach (ItemData item in inventory.m_inventory)
				{
					if (item.m_shared.m_name == text && item.m_shared.m_ammoType == text2)
					{
						val = item;
						break;
					}
				}
				val = val ?? inventory.GetAmmoItem(text2, (string)null);
				if (val != null && ((int)val.m_shared.m_itemType == 9 || (int)val.m_shared.m_itemType == 23))
				{
					((Humanoid)localPlayer).EquipItem(val, true);
				}
			}
		}
	}
	[HarmonyPatch]
	internal static class Appearance
	{
		internal struct Look
		{
			internal GameObject Prefab;

			internal int Variant;

			internal string Value
			{
				get
				{
					if (!((Object)(object)Prefab == (Object)null))
					{
						if (Variant <= 0)
						{
							return ((Object)Prefab).name;
						}
						return ((Object)Prefab).name + "#" + Variant;
					}
					return null;
				}
			}

			internal Look(GameObject prefab, int variant)
			{
				Prefab = prefab;
				Variant = variant;
			}

			internal bool Same(Look other)
			{
				if ((Object)(object)Prefab == (Object)(object)other.Prefab)
				{
					if (!((Object)(object)Prefab == (Object)null))
					{
						return Variant == other.Variant;
					}
					return true;
				}
				return false;
			}
		}

		internal const string Key = "CDEV_EquipmentSlots_look";

		internal static readonly SlotKind[] Kinds = new SlotKind[4]
		{
			SlotKind.Helmet,
			SlotKind.Chest,
			SlotKind.Legs,
			SlotKind.Cape
		};

		internal const string HiddenValue = "-";

		private const char VariantMark = '#';

		private const int GhostRank = 2;

		private static readonly Dictionary<string, GameObject> RealByName = new Dictionary<string, GameObject>();

		private static ObjectDB s_realDb;

		private static int s_realItems = -1;

		private static int s_realRecipes = -1;

		private static readonly HashSet<GameObject> Crafted = new HashSet<GameObject>();

		internal static int IndexOf(SlotKind kind)
		{
			return Array.IndexOf(Kinds, kind);
		}

		internal static GameObject Chosen(Player player, int index)
		{
			return ChosenLook(player, index).Prefab;
		}

		internal static Look ChosenLook(Player player, int index)
		{
			string text = ChosenName(player, index);
			if (text == null || text == "-" || (Object)(object)ObjectDB.instance == (Object)null)
			{
				return default(Look);
			}
			int num = 0;
			int num2 = text.LastIndexOf('#');
			if (num2 > 0 && int.TryParse(text.Substring(num2 + 1), out var result))
			{
				num = result;
				text = text.Substring(0, num2);
			}
			GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(text);
			GameObject val = Real(itemPrefab);
			itemPrefab = (((Object)(object)itemPrefab != (Object)null && Rank(itemPrefab) == 2) ? (val ?? itemPrefab) : itemPrefab);
			return new Look(itemPrefab, Mathf.Clamp(num, 0, VariantCount(itemPrefab) - 1));
		}

		internal static bool IsHidden(Player player, int index)
		{
			return ChosenName(player, index) == "-";
		}

		private static string ChosenName(Player player, int index)
		{
			if (player?.m_customData == null || index < 0 || !player.m_customData.TryGetValue("CDEV_EquipmentSlots_look", out var value))
			{
				return null;
			}
			string[] array = value.Split(new char[1] { '|' });
			if (index >= array.Length || array[index].Length <= 0)
			{
				return null;
			}
			return array[index];
		}

		private static int VariantCount(GameObject prefab)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Invalid comparison between Unknown and I4
			ItemDrop val = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<ItemDrop>() : null);
			SharedData val2 = (((Object)(object)val != (Object)null) ? val.m_itemData.m_shared : null);
			if (val2 == null || (int)val2.m_itemType != 17 || val2.m_icons == null)
			{
				return 1;
			}
			return Mathf.Max(1, Mathf.Min(val2.m_variants, val2.m_icons.Length));
		}

		internal static void Set(Player player, int index, string prefab)
		{
			if (!((Object)(object)player == (Object)null) && index >= 0 && index < Kinds.Length)
			{
				string[] array = new string[Kinds.Length];
				for (int i = 0; i < array.Length; i++)
				{
					array[i] = ChosenName(player, i) ?? "";
				}
				array[index] = prefab ?? "";
				string text = string.Join("|", array);
				if (text.Replace("|", "").Length == 0)
				{
					player.m_customData.Remove("CDEV_EquipmentSlots_look");
				}
				else
				{
					player.m_customData["CDEV_EquipmentSlots_look"] = text;
				}
				if ((Object)(object)((Humanoid)player).m_visEquipment != (Object)null)
				{
					((Humanoid)player).SetupVisEquipment(((Humanoid)player).m_visEquipment, false);
				}
			}
		}

		internal static SlotKind KindOf(ItemData item)
		{
			//IL_0023: 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)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Invalid comparison between Unknown and I4
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Invalid comparison between Unknown and I4
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Invalid comparison between Unknown and I4
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Invalid comparison between Unknown and I4
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Invalid comparison between Unknown and I4
			ItemType? val = item?.m_shared?.m_itemType;
			if (val.HasValue)
			{
				ItemType valueOrDefault = val.GetValueOrDefault();
				if ((int)valueOrDefault <= 7)
				{
					if ((int)valueOrDefault == 6)
					{
						return SlotKind.Helmet;
					}
					if ((int)valueOrDefault == 7)
					{
						return SlotKind.Chest;
					}
				}
				else
				{
					if ((int)valueOrDefault == 11)
					{
						return SlotKind.Legs;
					}
					if ((int)valueOrDefault == 17)
					{
						return SlotKind.Cape;
					}
				}
			}
			return SlotKind.None;
		}

		internal static List<Look> Known(Player player, SlotKind kind, List<Look> into)
		{
			into.Clear();
			ObjectDB instance = ObjectDB.instance;
			if ((Object)(object)player == (Object)null || (Object)(object)instance == (Object)null)
			{
				return into;
			}
			HashSet<string> hashSet = new HashSet<string>();
			foreach (GameObject item in instance.m_items)
			{
				ItemDrop val = (((Object)(object)item != (Object)null) ? item.GetComponent<ItemDrop>() : null);
				SharedData val2 = (((Object)(object)val != (Object)null) ? val.m_itemData.m_shared : null);
				if (val2 != null && KindOf(val.m_itemData) == kind && val2.m_icons != null && val2.m_icons.Length != 0 && player.m_knownMaterial.Contains(val2.m_name) && hashSet.Add(val2.m_name))
				{
					GameObject prefab = Real(item) ?? item;
					int num = VariantCount(prefab);
					for (int i = 0; i < num; i++)
					{
						into.Add(new Look(prefab, i));
					}
				}
			}
			return into;
		}

		private static GameObject Real(GameObject prefab)
		{
			ItemDrop val = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<ItemDrop>() : null);
			if ((Object)(object)val == (Object)null || (Object)(object)ObjectDB.instance == (Object)null)
			{
				return null;
			}
			ObjectDB instance = ObjectDB.instance;
			if ((Object)(object)instance != (Object)(object)s_realDb || instance.m_items.Count != s_realItems || instance.m_recipes.Count != s_realRecipes)
			{
				s_realDb = instance;
				s_realItems = instance.m_items.Count;
				s_realRecipes = instance.m_recipes.Count;
				Crafted.Clear();
				foreach (Recipe recipe in instance.m_recipes)
				{
					if ((Object)(object)recipe != (Object)null && (Object)(object)recipe.m_item != (Object)null)
					{
						Crafted.Add(((Component)recipe.m_item).gameObject);
					}
				}
				RealByName.Clear();
				foreach (GameObject item in instance.m_items)
				{
					string text = (((Object)(object)item != (Object)null) ? item.GetComponent<ItemDrop>() : null)?.m_itemData?.m_shared?.m_name;
					if (text != null && (!RealByName.TryGetValue(text, out var value) || Rank(item) < Rank(value)))
					{
						RealByName[text] = item;
					}
				}
			}
			if (!RealByName.TryGetValue(val.m_itemData.m_shared.m_name, out var value2))
			{
				return prefab;
			}
			return value2;
		}

		private static int Rank(GameObject prefab)
		{
			if (Crafted.Contains(prefab))
			{
				return 0;
			}
			string name = ((Object)prefab).name;
			if (!name.StartsWith("FW_", StringComparison.Ordinal) && !name.StartsWith("SP_", StringComparison.Ordinal))
			{
				return 1;
			}
			return 2;
		}

		internal static bool TakeLookOf(Player player, ItemData item)
		{
			int num = IndexOf(KindOf(item));
			if ((Object)(object)player == (Object)null || num < 0 || (Object)(object)item.m_dropPrefab == (Object)null)
			{
				return false;
			}
			int variant = Mathf.Clamp(item.m_variant, 0, VariantCount(item.m_dropPrefab) - 1);
			Set(player, num, new Look(item.m_dropPrefab, variant).Value);
			return true;
		}

		internal static Sprite Icon(Look look)
		{
			ItemDrop val = (((Object)(object)look.Prefab != (Object)null) ? look.Prefab.GetComponent<ItemDrop>() : null);
			Sprite[] array = (((Object)(object)val != (Object)null) ? val.m_itemData.m_shared.m_icons : null);
			if (array == null || array.Length == 0)
			{
				return null;
			}
			return array[Mathf.Clamp(look.Variant, 0, array.Length - 1)];
		}

		internal static string DisplayName(GameObject prefab)
		{
			ItemDrop val = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<ItemDrop>() : null);
			if (!((Object)(object)val != (Object)null))
			{
				return "";
			}
			return Localization.instance.Localize(val.m_itemData.m_shared.m_name);
		}

		[HarmonyPatch(typeof(Humanoid), "SetupVisEquipment")]
		[HarmonyPostfix]
		private static void Dress(Humanoid __instance, VisEquipment visEq)
		{
			if (!Plugin.Active || (Object)(object)visEq == (Object)null)
			{
				return;
			}
			Player val = (Player)(object)((__instance is Player) ? __instance : null);
			if (val == null || val.m_customData == null || !val.m_customData.ContainsKey("CDEV_EquipmentSlots_look"))
			{
				return;
			}
			try
			{
				for (int i = 0; i < Kinds.Length; i++)
				{
					Look look = ChosenLook(val, i);
					GameObject prefab = look.Prefab;
					bool flag = (Object)(object)prefab == (Object)null && IsHidden(val, i);
					if (!((Object)(object)prefab == (Object)null) || flag)
					{
						int num = ((!flag) ? StringExtensionMethods.GetStableHashCode(((Object)prefab).name) : 0);
						switch (Kinds[i])
						{
						case SlotKind.Helmet:
							visEq.SetHelmetItem(num);
							break;
						case SlotKind.Chest:
							visEq.SetChestItem(num);
							break;
						case SlotKind.Legs:
							visEq.SetLegItem(num);
							break;
						default:
							visEq.SetShoulderItem(num, (!flag) ? look.Variant : 0, 1);
							break;
						}
					}
				}
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Dressing the chosen appearance failed: {arg}");
			}
		}
	}
	internal static class BetterArcheryHost
	{
		internal const string Guid = "ishid4.mods.betterarchery";

		private static FieldInfo s_rowIndex;

		private static Func<bool> s_isQuiverEquipped;

		private static Func<ItemData, string> s_customSlotName;

		private static ConfigEntry<bool> s_enabled;

		private static ConfigEntry<bool> s_hudEnabled;

		private static readonly Dictionary<SharedData, bool> Quivers = new Dictionary<SharedData, bool>();

		internal static bool Hosted { get; private set; }

		internal static bool QuiverActive
		{
			get
			{
				if (Hosted && s_enabled != null)
				{
					return s_enabled.Value;
				}
				return false;
			}
		}

		internal static bool QuiverHudShown
		{
			get
			{
				if (QuiverActive && s_hudEnabled != null && s_hudEnabled.Value)
				{
					return IsQuiverEquipped();
				}
				return false;
			}
		}

		internal static void Setup()
		{
			if (!Chainloader.PluginInfos.TryGetValue("ishid4.mods.betterarchery", out var value) || (Object)(object)value.Instance == (Object)null)
			{
				return;
			}
			try
			{
				Type type = ((object)value.Instance).GetType();
				FieldInfo field = type.GetField("eaqsPresent", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				s_rowIndex = type.GetField("QuiverRowIndex", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				MethodInfo method = type.GetMethod("IsQuiverEquipped", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null);
				s_enabled = type.GetField("ConfigQuiverEnabled", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(null) as ConfigEntry<bool>;
				s_hudEnabled = type.GetField("QuiverHudEnabled", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(null) as ConfigEntry<bool>;
				if (field == null || field.FieldType != typeof(int) || s_rowIndex == null || s_rowIndex.FieldType != typeof(int) || method == null || s_enabled == null)
				{
					Plugin.Log.LogWarning((object)($"Better Archery {value.Metadata.Version}: its quiver members were not found; the quiver is not hosted " + "(written for 2.0.0). Keep Better Archery's 'Enable Quiver' off, or arrows in the quiver may be lost."));
					return;
				}
				MethodInfo methodInfo = type.Assembly.GetType("Common.CustomSlotCreator")?.GetMethod("GetCustomSlotName", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(ItemData) }, null);
				s_customSlotName = ((methodInfo != null && methodInfo.ReturnType == typeof(string)) ? ((Func<ItemData, string>)Delegate.CreateDelegate(typeof(Func<ItemData, string>), methodInfo)) : null);
				if (s_customSlotName == null)
				{
					Plugin.Log.LogWarning((object)"Better Archery: Common.CustomSlotCreator.GetCustomSlotName was not found; the ammo slot cannot tell its quiver from arrows.");
				}
				field.SetValue(null, 1);
				s_rowIndex.SetValue(null, 23);
				s_isQuiverEquipped = (Func<bool>)Delegate.CreateDelegate(typeof(Func<bool>), method);
				Hosted = true;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Better Archery quiver hosting failed: " + ex.Message));
			}
		}

		internal static void KeepRow()
		{
			if (Hosted && (int)s_rowIndex.GetValue(null) != 23)
			{
				s_rowIndex.SetValue(null, 23);
			}
		}

		internal static bool IsQuiver(ItemData item)
		{
			if (!Hosted || s_customSlotName == null || item?.m_shared == null || (Object)(object)item.m_dropPrefab == (Object)null)
			{
				return false;
			}
			if (Quivers.TryGetValue(item.m_shared, out var value))
			{
				return value;
			}
			bool flag;
			try
			{
				flag = s_customSlotName(item) == "quiver";
			}
			catch
			{
				flag = false;
			}
			Quivers[item.m_shared] = flag;
			return flag;
		}

		internal static bool IsQuiverEquipped()
		{
			if (!QuiverActive)
			{
				return false;
			}
			try
			{
				return s_isQuiverEquipped();
			}
			catch
			{
				return false;
			}
		}
	}
	internal static class BetterUiHost
	{
		internal const string Guid = "zenox.betterui";

		private static readonly string[] Names = new string[3] { "CDEV_QuickSlot1", "CDEV_QuickSlot2", "CDEV_QuickSlot3" };

		private static object s_plugin;

		private static FieldInfo s_offsets;

		private static ConfigEntry<bool> s_starsOn;

		private static ConfigEntry<bool> s_durabilityOn;

		private static ConfigEntry<int> s_starSize;

		private static Func<int, string> s_starText;

		private static Color s_starColor;

		private static Action<GuiBar, float> s_durabilityColor;

		private static bool s_lookFailed;

		private static readonly Dictionary<TMP_Text, (Color color, Vector2 size)> QualityDefaults = new Dictionary<TMP_Text, (Color, Vector2)>();

		internal static void Setup()
		{
			if (!Chainloader.PluginInfos.TryGetValue("zenox.betterui", out var value) || (Object)(object)value.Instance == (Object)null)
			{
				return;
			}
			BindItemLook(value);
			try
			{
				Type type = ((object)value.Instance).GetType();
				if (!(type.GetField("AutoDetectExcludedNames", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(null) is HashSet<string> hashSet))
				{
					Plugin.Log.LogWarning((object)($"BetterUI {value.Metadata.Version}: its list of HUD elements to leave alone was not " + "found, so its HUD editor may pin the quick slots onto the forsaken power."));
					return;
				}
				string[] names = Names;
				foreach (string item in names)
				{
					hashSet.Add(item);
				}
				s_plugin = value.Instance;
				s_offsets = type.GetField("barOffsets", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				if (type.GetField("barOffsets", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(value.Instance) is IDictionary dictionary)
				{
					string[] names2 = Names;
					foreach (string text in names2)
					{
						dictionary.Remove("Custom:" + text);
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not keep BetterUI's HUD editor off the quick slots: " + ex.Message));
			}
		}

		private static void BindItemLook(PluginInfo info)
		{
			//IL_009e: 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_00a4: 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)
			try
			{
				Type type = ((object)info.Instance).GetType();
				s_starsOn = type.GetField("ItemLevelStarsEnabled", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(null) as ConfigEntry<bool>;
				s_starSize = type.GetField("InventoryStarFontSize", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(null) as ConfigEntry<int>;
				MethodInfo method = type.GetMethod("StarText", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(int) }, null);
				if (type.GetField("StarColor", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(null) is Color val)
				{
					s_starColor = val;
				}
				if (s_starsOn != null && s_starSize != null && method != null)
				{
					s_starText = (Func<int, string>)Delegate.CreateDelegate(typeof(Func<int, string>), method);
				}
				s_durabilityOn = type.GetField("DurabilityColorEnabled", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(null) as ConfigEntry<bool>;
				MethodInfo method2 = type.GetMethod("ApplyDurabilityColor", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[2]
				{
					typeof(GuiBar),
					typeof(float)
				}, null);
				if (s_durabilityOn != null && method2 != null)
				{
					s_durabilityColor = (Action<GuiBar, float>)Delegate.CreateDelegate(typeof(Action<GuiBar, float>), method2);
				}
				if (s_starText == null && s_durabilityColor == null)
				{
					Plugin.Log.LogWarning((object)($"BetterUI {info.Metadata.Version}: its quality stars and durability colours were not " + "found, so the equipment panel shows vanilla's."));
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not read BetterUI's quality stars: " + ex.Message));
				s_starText = null;
				s_durabilityColor = null;
			}
		}

		internal static string QualityText(ItemData item)
		{
			if (s_starText == null || s_lookFailed || !s_starsOn.Value || item.m_shared.m_maxQuality <= 1)
			{
				return null;
			}
			return $"<size={s_starSize.Value}>{s_starText(item.m_quality)}</size>";
		}

		internal static void Cell(InventoryElement element, ItemData item)
		{
			if ((Object)(object)element != (Object)null)
			{
				Paint(element.m_quality, element.m_durability, item);
			}
		}

		internal static void Paint(TMP_Text quality, GuiBar durability, ItemData item)
		{
			//IL_0044: 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_00d0: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			if (s_lookFailed || item == null || (s_starText == null && s_durabilityColor == null))
			{
				return;
			}
			try
			{
				if (s_starText != null && (Object)(object)quality != (Object)null)
				{
					if (!QualityDefaults.ContainsKey(quality))
					{
						QualityDefaults[quality] = (((Graphic)quality).color, quality.rectTransform.sizeDelta);
					}
					if (s_starsOn.Value && ((Behaviour)quality).enabled && item.m_shared.m_maxQuality > 1)
					{
						((Graphic)quality).color = s_starColor;
						quality.textWrappingMode = (TextWrappingModes)0;
						quality.rectTransform.sizeDelta = new Vector2((float)item.m_quality * ((float)s_starSize.Value * 0.85f), 20f);
					}
					else
					{
						(Color, Vector2) tuple = QualityDefaults[quality];
						((Graphic)quality).color = tuple.Item1;
						quality.rectTransform.sizeDelta = tuple.Item2;
					}
				}
				if (s_durabilityColor != null && s_durabilityOn.Value && (Object)(object)durability != (Object)null && ((Component)durability).gameObject.activeSelf && item.m_shared.m_useDurability && item.m_durability > 0f)
				{
					s_durabilityColor(durability, item.GetDurabilityPercentage());
				}
			}
			catch (Exception ex)
			{
				s_lookFailed = true;
				Plugin.Log.LogWarning((object)("BetterUI's quality stars failed in the equipment panel, switched off for this session: " + ex.Message));
			}
		}

		internal static void Rebase(string name, Vector2 position)
		{
			//IL_00b1: 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)
			if (s_plugin == null || s_offsets == null)
			{
				return;
			}
			try
			{
				if (s_offsets.GetValue(s_plugin) is IDictionary dictionary && dictionary.Contains("Custom:" + name))
				{
					object obj = dictionary["Custom:" + name];
					FieldInfo field = obj.GetType().GetField("Captured");
					FieldInfo field2 = obj.GetType().GetField("BaseAnchoredPositions");
					if (field != null && (bool)field.GetValue(obj) && field2?.GetValue(obj) is Vector2[] array && array.Length != 0)
					{
						array[0] = position;
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not tell BetterUI the quick slots' new place: " + ex.Message));
				s_plugin = null;
			}
		}
	}
	internal static class EpicLootHost
	{
		internal const string Guid = "randyknapp.mods.epicloot";

		private const string ChildName = "CDEV_MagicItem";

		private static Func<ItemData, bool> s_isMagic;

		private static Func<ItemData, Color> s_color;

		private static Func<Sprite> s_sprite;

		private static Func<GameObject, ItemData, bool> s_icon;

		private static bool s_failed;

		internal static void Setup()
		{
			if (!Chainloader.PluginInfos.TryGetValue("randyknapp.mods.epicloot", out var value) || (Object)(object)value.Instance == (Object)null)
			{
				return;
			}
			try
			{
				Assembly assembly = ((object)value.Instance).GetType().Assembly;
				Type type = assembly.GetType("EpicLoot.ItemDataExtensions");
				MethodInfo methodInfo = type?.GetMethod("UseMagicBackground", BindingFlags.Static | BindingFlags.Public, null, new Type[1] { typeof(ItemData) }, null);
				MethodInfo methodInfo2 = type?.GetMethod("GetRarityColor", BindingFlags.Static | BindingFlags.Public, null, new Type[1] { typeof(ItemData) }, null);
				MethodInfo methodInfo3 = assembly.GetType("EpicLoot.EpicLoot")?.GetMethod("GetMagicItemBgSprite", BindingFlags.Static | BindingFlags.Public, null, Type.EmptyTypes, null);
				MethodInfo methodInfo4 = assembly.GetType("EpicLoot.API")?.GetMethod("ApplyMagicItemBackgroundToIcon", BindingFlags.Static | BindingFlags.Public, null, new Type[2]
				{
					typeof(GameObject),
					typeof(ItemData)
				}, null);
				if (methodInfo == null || methodInfo2 == null || methodInfo3 == null || methodInfo4 == null)
				{
					Plugin.Log.LogWarning((object)($"Epic Loot {value.Metadata.Version}: its item backgrounds were not found, so the equipment " + "panel shows magic items without their rarity colour."));
					return;
				}
				s_isMagic = (Func<ItemData, bool>)Delegate.CreateDelegate(typeof(Func<ItemData, bool>), methodInfo);
				s_color = (Func<ItemData, Color>)Delegate.CreateDelegate(typeof(Func<ItemData, Color>), methodInfo2);
				s_sprite = (Func<Sprite>)Delegate.CreateDelegate(typeof(Func<Sprite>), methodInfo3);
				s_icon = (Func<GameObject, ItemData, bool>)Delegate.CreateDelegate(typeof(Func<GameObject, ItemData, bool>), methodInfo4);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not bind Epic Loot's item backgrounds: " + ex.Message));
				s_isMagic = null;
			}
		}

		internal static bool IsMagic(ItemData item)
		{
			if (s_isMagic == null || s_failed || item == null)
			{
				return false;
			}
			try
			{
				return s_isMagic(item);
			}
			catch (Exception ex)
			{
				s_failed = true;
				Plugin.Log.LogWarning((object)("Epic Loot's item background failed, switched off for this session: " + ex.Message));
				return false;
			}
		}

		internal static void Cell(InventoryElement element, ItemData item)
		{
			//IL_00fa: 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_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: 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)
			if (s_isMagic == null || s_failed || (Object)(object)element == (Object)null || (Object)(object)element.m_equiped == (Object)null)
			{
				return;
			}
			try
			{
				bool flag = item != null && s_isMagic(item);
				Transform val = ((Component)element).transform.Find("CDEV_MagicItem");
				if (!flag)
				{
					if ((Object)(object)val != (Object)null && ((Component)val).gameObject.activeSelf)
					{
						((Component)val).gameObject.SetActive(false);
					}
					return;
				}
				Image val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<Image>() : Create(element.m_equiped));
				int siblingIndex = ((Component)element.m_icon).transform.GetSiblingIndex();
				if (((Component)val2).transform.GetSiblingIndex() != siblingIndex - 1)
				{
					((Component)val2).transform.SetSiblingIndex((((Component)val2).transform.GetSiblingIndex() < siblingIndex) ? (siblingIndex - 1) : siblingIndex);
				}
				Sprite val3 = s_sprite();
				if ((Object)(object)val2.sprite != (Object)(object)val3)
				{
					val2.sprite = val3;
				}
				Color val4 = s_color(item);
				if (((Graphic)val2).color != val4)
				{
					((Graphic)val2).color = val4;
				}
				if (!((Component)val2).gameObject.activeSelf)
				{
					((Component)val2).gameObject.SetActive(true);
				}
			}
			catch (Exception ex)
			{
				s_failed = true;
				Plugin.Log.LogWarning((object)("Epic Loot's item background failed, switched off for this session: " + ex.Message));
			}
		}

		internal static void Icon(Image icon, ItemData item)
		{
			if (s_icon == null || s_failed || (Object)(object)icon == (Object)null)
			{
				return;
			}
			try
			{
				s_icon(((Component)icon).gameObject, item);
			}
			catch (Exception ex)
			{
				s_failed = true;
				Plugin.Log.LogWarning((object)("Epic Loot's item background failed, switched off for this session: " + ex.Message));
			}
		}

		private static Image Create(Image equipped)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("CDEV_MagicItem", new Type[1] { typeof(RectTransform) });
			RectTransform val2 = (RectTransform)val.transform;
			((Transform)val2).SetParent(((Component)equipped).transform.parent, false);
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(0.5f, 0.5f);
			val2.pivot = val3;
			Vector2 anchorMin = (val2.anchorMax = val3);
			val2.anchorMin = anchorMin;
			val2.sizeDelta = new Vector2(64f, 64f);
			val2.anchoredPosition = Vector2.zero;
			Image val5 = val.AddComponent<Image>();
			val5.type = equipped.type;
			val5.pixelsPerUnitMultiplier = equipped.pixelsPerUnitMultiplier;
			((Graphic)val5).raycastTarget = false;
			return val5;
		}
	}
	internal static class LocalCraftFromStorageHost
	{
		internal const string Guid = "LuminairPrime.valheim.localcraftfromstorageprime";

		internal static void Setup(Harmony harmony)
		{
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Expected O, but got Unknown
			if (harmony == null || !Chainloader.PluginInfos.TryGetValue("LuminairPrime.valheim.localcraftfromstorageprime", out var value) || (Object)(object)value.Instance == (Object)null)
			{
				return;
			}
			try
			{
				MethodInfo methodInfo = ((object)value.Instance).GetType().Assembly.GetType("LocalCraftFromStoragePrime.DepositOperation")?.GetMethod("Eligible", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(ItemData) }, null);
				if (methodInfo == null || methodInfo.ReturnType != typeof(bool))
				{
					Plugin.Log.LogWarning((object)($"Local Craft From Storage Prime {value.Metadata.Version}: its deposit check was not " + "found, so \"Store Nearby\" may move items out of the slots."));
				}
				else
				{
					harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(LocalCraftFromStorageHost), "LeaveSlotsAlone", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not keep Local Craft From Storage Prime out of the slots: " + ex.Message));
			}
		}

		private static void LeaveSlotsAlone(ItemData __0, ref bool __result)
		{
			//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_0016: 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_0020: Unknown result type (might be due to invalid IL or missing references)
			if (__result && Plugin.Active && __0 != null)
			{
				Vector2i gridPos = __0.m_gridPos;
				if ((gridPos.y >= 20 && gridPos.y <= 31) || Locks.IsLocked(gridPos))
				{
					__result = false;
				}
			}
		}
	}
	internal static class MultiUtilityHost
	{
		internal const string Guid = "aedenthorn.EquipMultipleUtilityItems";

		private static ConfigEntry<bool> s_enabled;

		private static ConfigEntry<int> s_max;

		internal static int ExtraCells
		{
			get
			{
				if (s_max != null && (s_enabled == null || s_enabled.Value))
				{
					return Mathf.Clamp(s_max.Value - 1, 0, 4);
				}
				return 0;
			}
		}

		internal static bool Active => ExtraCells > 0;

		internal static void Setup()
		{
			if (!Chainloader.PluginInfos.TryGetValue("aedenthorn.EquipMultipleUtilityItems", out var value) || (Object)(object)value.Instance == (Object)null)
			{
				return;
			}
			try
			{
				Type type = ((object)value.Instance).GetType();
				s_enabled = type.GetField("modEnabled", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(null) as ConfigEntry<bool>;
				s_max = type.GetField("maxEquippedItems", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(null) as ConfigEntry<int>;
				if (s_max == null)
				{
					Plugin.Log.LogWarning((object)($"Equip Multiple Utility Items {value.Metadata.Version}: its MaxEquippedItems setting was not " + "found, so the panel has one belt cell and extra utility items stay worn in the inventory."));
					return;
				}
				s_max.SettingChanged += delegate
				{
					SlotPanel.Invalidate();
				};
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not read Equip Multiple Utility Items' settings: " + ex.Message));
				s_max = null;
			}
		}
	}
	internal static class QuickStackStoreHost
	{
		internal const string Guid = "goldenrevolver.quick_stack_store";

		private static bool s_borderErrorLogged;

		internal static bool Hooked { get; private set; }

		internal static void Setup(Harmony harmony)
		{
			if (harmony != null && Chainloader.PluginInfos.TryGetValue("goldenrevolver.quick_stack_store", out var value) && !((Object)(object)value.Instance == (Object)null))
			{
				Assembly assembly = ((object)value.Instance).GetType().Assembly;
				HookSlotChecks(harmony, assembly, value);
				HookBorders(harmony, assembly, value);
			}
		}

		private static void HookSlotChecks(Harmony harmony, Assembly assembly, PluginInfo info)
		{
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Expected O, but got Unknown
			try
			{
				Type type = assembly.GetType("QuickStackStore.CompatibilitySupport");
				Type[] types = new Type[3]
				{
					typeof(int),
					typeof(int),
					typeof(Vector2i)
				};
				MethodInfo methodInfo = type?.GetMethod("IsEquipOrQuickSlot", BindingFlags.Static | BindingFlags.Public, null, types, null);
				MethodInfo methodInfo2 = type?.GetMethod("IsEquipSlot", BindingFlags.Static | BindingFlags.Public, null, types, null);
				if (methodInfo != null)
				{
					harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(QuickStackStoreHost), "LeaveSlotsAlone", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
				if (methodInfo2 != null)
				{
					harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(typeof(QuickStackStoreHost), "LeaveSlotsAloneButRestock", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
				if (methodInfo == null || methodInfo2 == null)
				{
					Plugin.Log.LogWarning((object)($"QuickStackStore {info.Metadata.Version}: its IsEquipOrQuickSlot / IsEquipSlot check " + "was not found, so its sort, store, quick stack or restock may move items out of the slots."));
				}
				else
				{
					Hooked = true;
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not teach QuickStackStore about the slots: " + ex.Message));
			}
		}

		private static void HookBorders(Harmony harmony, Assembly assembly, PluginInfo info)
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Expected O, but got Unknown
			//IL_00b6: Expected O, but got Unknown
			try
			{
				MethodInfo methodInfo = assembly.GetType("QuickStackStore.BorderRenderer")?.GetMethod("UpdateGui", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[3]
				{
					typeof(Player),
					typeof(Inventory),
					typeof(List<InventoryElement>)
				}, null);
				if (methodInfo == null)
				{
					Plugin.Log.LogWarning((object)($"QuickStackStore {info.Metadata.Version}: its border renderer was not found; " + "if its favourite borders throw, the inventory window stops updating."));
				}
				else
				{
					harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(QuickStackStoreHost), "BordersBefore", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(QuickStackStoreHost), "BordersAfter", (Type[])null), (HarmonyMethod)null);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not guard QuickStackStore's favourite borders: " + ex.Message));
			}
		}

		private static bool IsSlotRow(Vector2i pos)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			if (pos.y >= 20)
			{
				return pos.y <= 31;
			}
			return false;
		}

		private static void LeaveSlotsAlone(Vector2i itemPos, ref bool __result)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (!__result && Plugin.Active && (IsSlotRow(itemPos) || Locks.IsLocked(itemPos)))
			{
				__result = true;
			}
		}

		private static void LeaveSlotsAloneButRestock(Vector2i itemPos, ref bool __result)
		{
			//IL_000c: 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_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			if (!__result && Plugin.Active)
			{
				bool flag = itemPos.y == 22 && itemPos.x >= 0 && itemPos.x < 6;
				if ((IsSlotRow(itemPos) && !flag) || Locks.IsLocked(itemPos))
				{
					__result = true;
				}
			}
		}

		private static bool BordersBefore(Player __0, Inventory __1, List<InventoryElement> __2, out List<KeyValuePair<int, ItemData>> __state)
		{
			__state = null;
			if (!Plugin.Active || (Object)(object)__0 == (Object)null || __1 == null || ((Humanoid)__0).m_inventory != __1)
			{
				return true;
			}
			if (SlotPanel.Grid != null && __2 == SlotPanel.Grid.m_elements)
			{
				return false;
			}
			int height = __1.GetHeight();
			List<ItemData> inventory = __1.m_inventory;
			for (int num = inventory.Count - 1; num >= 0; num--)
			{
				if (inventory[num] != null && inventory[num].m_gridPos.y >= height)
				{
					(__state ?? (__state = new List<KeyValuePair<int, ItemData>>())).Add(new KeyValuePair<int, ItemData>(num, inventory[num]));
					inventory.RemoveAt(num);
				}
			}
			return true;
		}

		private static Exception BordersAfter(Exception __exception, Inventory __1, List<KeyValuePair<int, ItemData>> __state)
		{
			if (__state != null && __1 != null)
			{
				List<ItemData> inventory = __1.m_inventory;
				for (int num = __state.Count - 1; num >= 0; num--)
				{
					inventory.Insert(Math.Min(__state[num].Key, inventory.Count), __state[num].Value);
				}
			}
			if (__exception != null && !s_borderErrorLogged)
			{
				s_borderErrorLogged = true;
				Plugin.Log.LogWarning((object)("QuickStackStore's favourite borders failed (ignored, so the inventory window keeps updating; logged once): " + __exception));
			}
			return null;
		}
	}
	internal static class EquipSync
	{
		[StructLayout(LayoutKind.Sequential, Size = 1)]
		internal readonly struct BusyScope : IDisposable
		{
			internal static BusyScope Enter()
			{
				s_busy++;
				return default(BusyScope);
			}

			public void Dispose()
			{
				s_busy--;
			}
		}

		internal struct DragState
		{
			internal bool Dropping;

			internal Inventory TargetInventory;

			internal Vector2i TargetPos;

			internal Inventory SourceInventory;

			internal Vector2i SourcePos;
		}

		private static int s_busy;

		internal static int EquipDepth;

		private static bool s_dirty = true;

		private static float s_nextPass;

		private static readonly List<ItemData> Items = new List<ItemData>();

		private static readonly Dictionary<ItemData, Vector2i> Refused = new Dictionary<ItemData, Vector2i>();

		private static Player s_refusedFor;

		private static readonly Dictionary<ItemData, Vector2i> ReturnCells = new Dictionary<ItemData, Vector2i>();

		internal static bool Busy => s_busy > 0;

		internal static void Enter()
		{
			s_busy++;
		}

		internal static void Exit()
		{
			s_busy = Math.Max(0, s_busy - 1);
		}

		internal static void MarkDirty()
		{
			s_dirty = true;
		}

		internal static bool IsLocal(Humanoid humanoid)
		{
			if ((Object)(object)humanoid != (Object)null)
			{
				return (Object)(object)humanoid == (Object)(object)Player.m_localPlayer;
			}
			return false;
		}

		private static bool CanManage(Player player)
		{
			if ((Object)(object)player != (Object)null && !player.m_isLoading && !((Character)player).IsDead())
			{
				return ((Humanoid)player).m_inventory != null;
			}
			return false;
		}

		internal static bool StaysInGrid(ItemData item, SlotKind kind)
		{
			if (!ModConfig.KeepWornInInventory.Value || item == null)
			{
				return false;
			}
			switch (kind)
			{
			case SlotKind.Helmet:
			case SlotKind.Chest:
			case SlotKind.Legs:
			case SlotKind.Cape:
			case SlotKind.Belt:
			case SlotKind.Trinket:
				return true;
			case SlotKind.Ammo:
				if (!BetterArcheryHost.IsQuiver(item))
				{
					return !BetterArcheryHost.IsQuiverEquipped();
				}
				return false;
			default:
				return false;
			}
		}

		internal static ItemData MirrorOf(Player player, SlotCell cell)
		{
			if (!ModConfig.KeepWornInInventory.Value || (Object)(object)player == (Object)null || cell == null)
			{
				return null;
			}
			ItemData val;
			switch (cell.Kind)
			{
			case SlotKind.Helmet:
				val = ((Humanoid)player).m_helmetItem;
				break;
			case SlotKind.Chest:
				val = ((Humanoid)player).m_chestItem;
				break;
			case SlotKind.Legs:
				val = ((Humanoid)player).m_legItem;
				break;
			case SlotKind.Cape:
				val = ((Humanoid)player).m_shoulderItem;
				break;
			case SlotKind.Belt:
				val = ((cell.Ordinal == 0) ? ((Humanoid)player).m_utilityItem : null);
				break;
			case SlotKind.Trinket:
				val = ((Humanoid)player).m_trinketItem;
				break;
			case SlotKind.Ammo:
				val = ((Humanoid)player).m_ammoItem;
				break;
			default:
				return null;
			}
			if (val == null || !StaysInGrid(val, cell.Kind) || SlotInventory.InOwnCell(val) || !((Humanoid)player).m_inventory.ContainsItem(val))
			{
				return null;
			}
			return val;
		}

		internal static void OnEquipped(Player player, ItemData item)
		{
			if (Busy || !CanManage(player) || item == null)
			{
				return;
			}
			SlotKind slotKind = SlotLayout.HomeKind(item);
			if (slotKind == SlotKind.None || SlotInventory.InOwnCell(item) || !((Humanoid)player).m_inventory.ContainsItem(item) || StaysInGrid(item, slotKind))
			{
				return;
			}
			using (BusyScope.Enter())
			{
				if (PlaceIntoSlot(((Humanoid)player).m_inventory, item, slotKind))
				{
					((Humanoid)player).m_inventory.Changed(false, false);
				}
			}
		}

		internal static void OnUnequipped(Player player, ItemData item)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: 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_008d: Unknown result type (might be due to invalid IL or missing references)
			if (Busy || EquipDepth > 0 || !CanManage(player) || item == null || ((Humanoid)player).IsItemEquiped(item) || !SlotInventory.InOwnCell(item) || !((Humanoid)player).m_inventory.ContainsItem(item) || (item.m_shared.m_useDurability && item.m_durability <= 0f))
			{
				return;
			}
			SlotCell slotCell = SlotLayout.At(item.m_gridPos);
			if (slotCell != null && slotCell.Kind == SlotKind.Quiver)
			{
				return;
			}
			using (BusyScope.Enter())
			{
				Vector2i val = SlotInventory.FreeGridCellPreferBag(((Humanoid)player).m_inventory);
				if (val.x >= 0)
				{
					item.m_gridPos = val;
					((Humanoid)player).m_inventory.Changed(false, false);
				}
			}
		}

		internal static bool PlaceIntoSlot(Inventory inventory, ItemData item, SlotKind kind)
		{
			//IL_009e: 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_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: 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_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			if (kind == SlotKind.Ammo && BetterArcheryHost.IsQuiverEquipped() && !BetterArcheryHost.IsQuiver(item))
			{
				foreach (SlotCell item2 in SlotLayout.Quiver)
				{
					if (SlotInventory.ItemIn(inventory, item2) == null)
					{
						item.m_gridPos = item2.Pos;
						return true;
					}
				}
				return false;
			}
			SlotCell slotCell = SlotInventory.TargetCell(inventory, kind, item);
			if (slotCell == null)
			{
				return false;
			}
			ItemData val = SlotInventory.ItemIn(inventory, slotCell);
			if (val == item)
			{
				return false;
			}
			if (val != null && BetterArcheryHost.IsQuiver(val))
			{
				return false;
			}
			if (val != null && kind == SlotKind.Belt && MultiUtilityHost.Active)
			{
				return false;
			}
			Vector2i gridPos = item.m_gridPos;
			if (val != null)
			{
				SlotCell slotCell2 = SlotLayout.At(gridPos);
				if ((slotCell2 == null) ? SlotInventory.InGrid(inventory, gridPos) : SlotLayout.Accepts(slotCell2, val))
				{
					val.m_gridPos = gridPos;
				}
				else
				{
					item.m_gridPos = new Vector2i(-1000, -1000);
					if (!SlotInventory.MoveToGridOrStash(inventory, val))
					{
						item.m_gridPos = gridPos;
						return false;
					}
				}
				if (val.m_equipped && (Object)(object)Player.m_localPlayer != (Object)null && ((Humanoid)Player.m_localPlayer).m_inventory == inventory)
				{
					((Humanoid)Player.m_localPlayer).UnequipItem(val, false);
				}
			}
			item.m_gridPos = slotCell.Pos;
			return true;
		}

		internal static void AfterDrop(DragState state)
		{
			//IL_002f: 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)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if (!state.Dropping || !CanManage(localPlayer))
			{
				return;
			}
			Inventory inventory = ((Humanoid)localPlayer).m_inventory;
			using (BusyScope.Enter())
			{
				if (state.TargetInventory == inventory)
				{
					ItemData itemAt = inventory.GetItemAt(state.TargetPos.x, state.TargetPos.y);
					ApplyLocation(localPlayer, itemAt);
					if (itemAt != null && state.SourceInventory == inventory && SlotInventory.InGrid(inventory, state.SourcePos) && SlotInventory.InOwnCell(itemAt) && StaysInGrid(itemAt, SlotLayout.HomeKind(itemAt)))
					{
						ReturnCells[itemAt] = state.SourcePos;
					}
				}
				if (state.SourceInventory == inventory)
				{
					ApplyLocation(localPlayer, inventory.GetItemAt(state.SourcePos.x, state.SourcePos.y));
				}
			}
			MarkDirty();
		}

		private static void ApplyLocation(Player player, ItemData item)
		{
			if (item == null || !((Humanoid)player).m_inventory.ContainsItem(item) || SlotLayout.HomeKind(item) == SlotKind.None)
			{
				return;
			}
			bool flag = SlotInventory.InOwnCell(item);
			bool flag2 = ((Humanoid)player).IsItemEquiped(item);
			if (flag && !flag2)
			{
				if (item.m_shared.m_equipDuration > 0f && SlotInventory.InGridOrSlot(item))
				{
					if (!player.IsEquipActionQueued(item))
					{
						player.QueueEquipAction(item);
					}
				}
				else
				{
					((Humanoid)player).EquipItem(item, false);
				}
			}
			else if (!flag && flag2 && !StaysInGrid(item, SlotLayout.HomeKind(item)))
			{
				((Humanoid)player).UnequipItem(item, false);
			}
		}

		internal static void OnSlotRightClick(Player player, SlotCell cell, ItemData item)
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			if (item == null && CanManage(player))
			{
				ItemData val = MirrorOf(player, cell);
				if (val != null)
				{
					((Humanoid)player).RemoveEquipAction(val);
					((Humanoid)player).UnequipItem(val, true);
				}
			}
			else
			{
				if (item == null || !CanManage(player))
				{
					return;
				}
				if (cell.Kind == SlotKind.Quick || cell.Kind == SlotKind.Quiver)
				{
					((Humanoid)player).UseItem(((Humanoid)player).m_inventory, item, true);
					return;
				}
				Vector2i val2 = SlotInventory.FreeGridCellPreferBag(((Humanoid)player).m_inventory);
				if (val2.x < 0)
				{
					((Character)player).Message((MessageType)2, "$cdev_es_nospace", 0, (Sprite)null, false);
					return;
				}
				using (BusyScope.Enter())
				{
					if (((Humanoid)player).IsItemEquiped(item))
					{
						((Humanoid)player).RemoveEquipAction(item);
						((Humanoid)player).UnequipItem(item, true);
					}
					item.m_gridPos = val2;
					item.m_equipped = false;
				}
				((Humanoid)player).m_inventory.Changed(false, false);
			}
		}

		internal static bool AllowToggle(Player player, ItemData item)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			if (!IsLocal((Humanoid)(object)player) || item == null || !((Humanoid)player).IsItemEquiped(item) || !SlotInventory.InOwnCell(item))
			{
				return true;
			}
			if (SlotInventory.FreeGridCellPreferBag(((Humanoid)player).m_inventory).x >= 0)
			{
				return true;
			}
			((Character)player).Message((MessageType)2, "$cdev_es_nospace", 0, (Sprite)null, false);
			return false;
		}

		internal static void Tick()
		{
			Player localPlayer = Player.m_localPlayer;
			if (Busy || !CanManage(localPlayer) || (!s_dirty && Time.time < s_nextPass))
			{
				return;
			}
			s_dirty = false;
			s_nextPass = Time.time + 1f;
			try
			{
				if (Repair(localPlayer))
				{
					((Humanoid)localPlayer).m_inventory.Changed(false, false);
				}
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Slot pass failed: {arg}");
			}
			s_dirty = false;
		}

		private static bool Repair(Player player)
		{
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0357: Unknown result type (might be due to invalid IL or missing references)
			//IL_0337: Unknown result type (might be due to invalid IL or missing references)
			//IL_0360: Unknown result type (might be due to invalid IL or missing references)
			//IL_036f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0341: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Unknown result type (might be due to invalid IL or missing references)
			//IL_037b: Unknown result type (might be due to invalid IL or missing references)
			//IL_037d: Unknown result type (might be due to invalid IL or missing references)
			//IL_035e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03de: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f5: Unknown result type (might be due to invalid IL or missing references)
			Inventory inventory = ((Humanoid)player).m_inventory;
			bool flag = false;
			if ((Object)(object)s_refusedFor != (Object)(object)player)
			{
				Refused.Clear();
				ReturnCells.Clear();
				s_refusedFor = player;
			}
			using (BusyScope.Enter())
			{
				Items.Clear();
				Items.AddRange(inventory.m_inventory);
				foreach (ItemData item in Items)
				{
					flag |= SlotMemory.Restore(player, inventory, item);
				}
				flag |= SlotMemory.RestoreCells(player, inventory, Items);
				foreach (ItemData item2 in Items)
				{
					if (item2.m_equipped && Jewelry.IsJewelry(item2) && !SlotInventory.InOwnCell(item2))
					{
						item2.m_equipped = false;
						flag = true;
					}
				}
				foreach (ItemData item3 in Items)
				{
					SlotKind slotKind = SlotLayout.HomeKind(item3);
					if (slotKind != SlotKind.None && !SlotInventory.InOwnCell(item3) && ((Humanoid)player).IsItemEquiped(item3) && !StaysInGrid(item3, slotKind))
					{
						flag |= PlaceIntoSlot(inventory, item3, slotKind);
					}
				}
				foreach (ItemData item4 in Items)
				{
					SlotCell slotCell = SlotLayout.At(item4.m_gridPos);
					if (slotCell != null && slotCell.Kind != SlotKind.Stash && !SlotLayout.Accepts(slotCell, item4))
					{
						if (((Humanoid)player).IsItemEquiped(item4))
						{
							((Humanoid)player).UnequipItem(item4, false);
						}
						if (!((Humanoid)player).IsItemEquiped(item4))
						{
							item4.m_equipped = false;
						}
						if (SlotInventory.MoveToGridOrStash(inventory, item4))
						{
							flag = true;
						}
					}
				}
				foreach (SlotCell item5 in SlotLayout.Equipment)
				{
					ItemData val = SlotInventory.ItemIn(inventory, item5);
					if (val != null && !val.m_equipped && SlotLayout.Accepts(item5, val) && !((Humanoid)player).IsItemEquiped(val) && !player.IsEquipActionQueued(val) && (!val.m_shared.m_useDurability || !(val.m_durability <= 0f)) && (!Refused.TryGetValue(val, out var value) || !(value == val.m_gridPos)) && !((Character)player).InAttack() && !((Character)player).InDodge() && (!((Character)player).IsSwimming() || ((Character)player).IsOnGround()))
					{
						if (((Humanoid)player).EquipItem(val, false))
						{
							Refused.Remove(val);
						}
						else
						{
							Refused[val] = val.m_gridPos;
						}
					}
				}
				foreach (SlotCell item6 in SlotLayout.Equipment)
				{
					ItemData val2 = SlotInventory.ItemIn(inventory, item6);
					if (val2 != null && StaysInGrid(val2, item6.Kind) && ((Humanoid)player).IsItemEquiped(val2))
					{
						Vector2i value2;
						Vector2i val3 = ((ReturnCells.TryGetValue(val2, out value2) && SlotInventory.InGrid(inventory, value2) && inventory.GetItemAt(value2.x, value2.y) == null) ? value2 : SlotInventory.FreeGridCellPreferBag(inventory));
						ReturnCells.Remove(val2);
						if (val3.x >= 0)
						{
							val2.m_gridPos = val3;
							flag = true;
						}
					}
				}
				if (ReturnCells.Count > 32)
				{
					ReturnCells.Clear();
				}
				foreach (SlotCell item7 in SlotLayout.Stash)
				{
					ItemData val4 = SlotInventory.ItemIn(inventory, item7);
					if (val4 != null)
					{
						Vector2i val5 = SlotInventory.FreeGridCellPreferBag(inventory);
						if (val5.x < 0)
						{
							break;
						}
						val4.m_gridPos = val5;
						flag = true;
					}
				}
				Items.Clear();
				return flag;
			}
		}
	}
	[HarmonyPatch]
	internal static class GamepadQuickSlots
	{
		private const string Left = "JoyHotbarLeft";

		private const string Right = "JoyHotbarRight";

		private const string Use = "JoyHotbarUse";

		private static int s_takenFrame = -1;

		private static bool s_takeLeft;

		private static bool s_takeRight;

		private static bool s_takeUse;

		internal static int Selected { get; private set; } = -1;

		internal static bool Takes(string name)
		{
			if (s_takenFrame != Time.frameCount || Time.inFixedTimeStep)
			{
				return false;
			}
			if ((!s_takeLeft || !(name == "JoyHotbarLeft")) && (!s_takeRight || !(name == "JoyHotbarRight")))
			{
				if (s_takeUse)
				{
					return name == "JoyHotbarUse";
				}
				return false;
			}
			return true;
		}

		internal static void Reset()
		{
			Selected = -1;
		}

		[HarmonyPatch(typeof(HotkeyBar), "Update")]
		[HarmonyPrefix]
		private static void Step(HotkeyBar __instance)
		{
			if (!Plugin.Active || !ModConfig.GamepadHotbar.Value || !ModConfig.HudEnabled.Value)
			{
				Selected = -1;
				return;
			}
			try
			{
				Player localPlayer = Player.m_localPlayer;
				if ((Object)(object)localPlayer == (Object)null || !HotbarTakesInput() || ZInput.GetButton("JoyAltKeys"))
				{
					return;
				}
				bool buttonDown = ZInput.GetButtonDown("JoyHotbarLeft");
				bool buttonDown2 = ZInput.GetButtonDown("JoyHotbarRight");
				bool buttonDown3 = ZInput.GetButtonDown("JoyHotbarUse");
				if (!buttonDown && !buttonDown2 && !buttonDown3)
				{
					return;
				}
				int num = __instance.m_elements.Count - 1;
				bool flag = false;
				bool flag2 = false;
				bool flag3 = false;
				if (Selected >= 0)
				{
					if (buttonDown2)
					{
						flag2 = true;
						Selected++;
						if (Selected >= 6)
						{
							Selected = -1;
							__instance.m_selected = 0;
						}
					}
					else if (buttonDown)
					{
						flag = true;
						Selected--;
						if (Selected < 0)
						{
							__instance.m_selected = Mathf.Max(0, num);
						}
					}
					if (buttonDown3 && Selected >= 0)
					{
						flag3 = true;
						SlotCell slotCell = SlotLayout.QuickCell(Selected);
						ItemData itemAt = ((Humanoid)localPlayer).m_inventory.GetItemAt(slotCell.Pos.x, slotCell.Pos.y);
						if (itemAt != null)
						{
							((Humanoid)localPlayer).UseItem((Inventory)null, itemAt, false);
						}
					}
				}
				else if (buttonDown2 && __instance.m_selected >= num)
				{
					flag2 = true;
					Selected = 0;
				}
				else if (buttonDown && __instance.m_selected <= 0)
				{
					flag = true;
					Selected = 5;
				}
				s_takenFrame = Time.frameCount;
				s_takeLeft = flag;
				s_takeRight = flag2;
				s_takeUse = flag3;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Controller quick slots failed: " + ex.Message));
				Selected = -1;
			}
		}

		[HarmonyPatch(typeof(HotkeyBar), "UpdateIcons")]
		[HarmonyPostfix]
		private static void HideHotbarSelection(HotkeyBar __instance)
		{
			if (Selected < 0 || !Plugin.Active)
			{
				return;
			}
			foreach (ElementData element in __instance.m_elements)
			{
				if ((Object)(object)element?.m_selection != (Object)null && element.m_selection.activeSelf)
				{
					element.m_selection.SetActive(false);
				}
			}
		}

		private static bool HotbarTakesInput()
		{
			if (!InventoryGui.IsVisible() && !Menu.IsVisible() && !GameCamera.InFreeFly() && !Minimap.IsOpen() && !Hud.IsPieceSelectionVisible() && !StoreGui.IsVisible() && !Console.IsVisible() && (!((Object)(object)Chat.instance != (Object)null) || !Chat.instance.HasFocus()) && !PlayerCustomizaton.IsBarberGuiVisible())
			{
				return !Hud.InRadial();
			}
			return false;
		}
	}
	internal static class Jewelry
	{
		private static readonly Dictionary<string, SlotKind> FromConfig = new Dictionary<string, SlotKind>(StringComparer.Ordinal);

		private static readonly Dictionary<string, SlotKind> FromApi = new Dictionary<string, SlotKind>(StringComparer.Ordinal);

		private static readonly Dictionary<SharedData, SlotKind> Cache = new Dictionary<SharedData, SlotKind>();

		private static readonly ConditionalWeakTable<Humanoid, HashSet<StatusEffect>> Effects = new ConditionalWeakTable<Humanoid, HashSet<StatusEffect>>();

		private static readonly HashSet<StatusEffect> Wanted = new HashSet<StatusEffect>();

		private static readonly List<StatusEffect> Stale = new List<StatusEffect>();

		private static readonly List<ItemData> Worn = new List<ItemData>();

		internal static bool AnyKnown
		{
			get
			{
				if (FromApi.Count <= 0)
				{
					return FromConfig.Count > 0;
				}
				return true;
			}
		}

		internal static void ReloadConfig()
		{
			FromConfig.Clear();
			Read(ModConfig.Rings.Value, SlotKind.Ring);
			Read(ModConfig.Earrings.Value, SlotKind.Earring);
			Read(ModConfig.Amulets.Value, SlotKind.Amulet);
			Cache.Clear();
		}

		internal static void Register(string prefabName, SlotKind kind)
		{
			if (!string.IsNullOrWhiteSpace(prefabName) && SlotLayout.IsJewelryKind(kind))
			{
				FromApi[prefabName.Trim()] = kind;
				Cache.Clear();
			}
		}

		internal static void Unregister(string prefabName)
		{
			if (prefabName != null && FromApi.Remove(prefabName.Trim()))
			{
				Cache.Clear();
			}
		}

		private static void Read(string list, SlotKind kind)
		{
			if (string.IsNullOrEmpty(list))
			{
				return;
			}
			string[] array = list.Split(new char[2] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
			foreach (string text in array)
			{
				string text2 = text.Trim();
				if (text2.Length > 0)
				{
					FromConfig[text2] = kind;
				}
			}
		}

		internal static SlotKind KindOf(ItemData item)
		{
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Invalid comparison between Unknown and I4
			if (item?.m_shared == null || (Object)(object)item.m_dropPrefab == (Object)null)
			{
				return SlotKind.None;
			}
			if (Cache.TryGetValue(item.m_shared, out var value))
			{
				return value;
			}
			string name = ((Object)item.m_dropPrefab).name;
			if (!FromConfig.TryGetValue(name, out value) && !FromApi.TryGetValue(name, out value))
			{
				value = SlotKind.None;
			}
			if (value != SlotKind.None && (item.IsEquipableVanilla() || (int)item.m_shared.m_itemType == 2))
			{
				Plugin.Log.LogWarning((object)$"{name} is listed as jewelry but is a {item.m_shared.m_itemType}; ignored.");
				value = SlotKind.None;
			}
			Cache[item.m_shared] = value;
			return value;
		}

		internal static bool IsJewelry(ItemData item)
		{
			return KindOf(item) != SlotKind.None;
		}

		internal static bool IsWorn(Humanoid humanoid, ItemData item)
		{
			if (item.m_equipped && IsJewelry(item) && SlotInventory.InOwnCell(item))
			{
				return humanoid.m_inventory.ContainsItem(item);
			}
			return false;
		}

		internal static void CollectWorn(Humanoid humanoid, List<ItemData> worn)
		{
			worn.Clear();
			Inventory inventory = humanoid.m_inventory;
			if (inventory == null)
			{
				return;
			}
			foreach (SlotCell item in SlotLayout.Equipment)
			{
				if (SlotLayout.IsJewelryKind(item.Kind))
				{
					ItemData val = SlotInventory.ItemIn(inventory, item);
					if (val != null && val.m_equipped && KindOf(val) == item.Kind)
					{
						worn.Add(val);
					}
				}
			}
		}

		internal static float Armor(Humanoid humanoid)
		{
			CollectWorn(humanoid, Worn);
			float num = 0f;
			foreach (ItemData item in Worn)
			{
				num += item.GetArmor();
			}
			Worn.Clear();
			return num;
		}

		internal static void SyncStatusEffects(Humanoid humanoid)
		{
			if (((Character)humanoid).m_seman == null)
			{
				return;
			}
			HashSet<StatusEffect> orCreateValue = Effects.GetOrCreateValue(humanoid);
			CollectWorn(humanoid, Worn);
			Wanted.Clear();
			foreach (ItemData item in Worn)
			{
				if ((Object)(object)item.m_shared.m_equipStatusEffect != (Object)null)
				{
					Wanted.Add(item.m_shared.m_equipStatusEffect);
				}
			}
			Worn.Clear();
			Stale.Clear();
			foreach (StatusEffect item2 in orCreateValue)
			{
				if (!Wanted.Contains(item2))
				{
					Stale.Add(item2);
				}
			}
			foreach (StatusEffect item3 in Stale)
			{
				orCreateValue.Remove(item3);
				if (!humanoid.m_equipmentStatusEffects.Contains(item3))
				{
					((Character)humanoid).m_seman.RemoveStatusEffect(item3.NameHash(), true);
				}
			}
			foreach (StatusEffect item4 in Wanted)
			{
				orCreateValue.Add(item4);
				if (!((Character)humanoid).m_seman.HaveStatusEffect(item4.NameHash()))
				{
					((Character)humanoid).m_seman.AddStatusEffect(item4, false, 0, 0f, (short)(-1));
				}
			}
			Stale.Clear();
			Wanted.Clear();
		}

		private static bool IsEquipableVanilla(this ItemData item)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected I4, but got Unknown
			ItemType itemType = item.m_shared.m_itemType;
			switch (itemType - 3)
			{
			case 0:
			case 1:
			case 2:
			case 3:
			case 4:
			case 6:
			case 8:
			case 11:
			case 12:
			case 14:
			case 15:
			case 16:
			case 19:
			case 21:
				return true;
			default:
				return false;
			}
		}
	}
	public static class EquipmentSlotsApi
	{
		public static bool RegisterJewelry(string prefabName, string kind)
		{
			SlotKind kind2;
			switch ((kind ?? "").Trim().ToLowerInvariant())
			{
			case "ring":
				kind2 = SlotKind.Ring;
				break;
			case "earring":
				kind2 = SlotKind.Earring;
				break;
			case "amulet":
			case "necklace":
				kind2 = SlotKind.Amulet;
				break;
			default:
				return false;
			}
			Jewelry.Register(prefabName, kind2);
			return true;
		}

		public static void GetWornJewelry(Humanoid humanoid, List<ItemData> worn)
		{
			if ((Object)(object)humanoid == (Object)null || worn == null)
			{
				worn?.Clear();
			}
			else
			{
				Jewelry.CollectWorn(humanoid, worn);
			}
		}
	}
	internal static class Locks
	{
		internal const string DataKey = "cdev_es_locks";

		private static readonly HashSet<int> Cells = new HashSet<int>();

		private static Player s_for;

		internal static bool Any
		{
			get
			{
				EnsureLoaded(Player.m_localPlayer);
				return Cells.Count > 0;
			}
		}

		private static int Key(Vector2i pos)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			return (pos.y << 8) | pos.x;
		}

		private static void EnsureLoaded(Player player)
		{
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)player == (Object)null || player == s_for)
			{
				return;
			}
			s_for = player;
			Cells.Clear();
			if (player.m_customData == null || !player.m_customData.TryGetValue("cdev_es_locks", out var value) || string.IsNullOrEmpty(value))
			{
				return;
			}
			string[] array = value.Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries);
			foreach (string text in array)
			{
				string[] array2 = text.Split(new char[1] { ',' });
				if (array2.Length == 2 && int.TryParse(array2[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result) && int.TryParse(array2[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result2) && result >= 0 && result < 256 && result2 >= 0)
				{
					Cells.Add(Key(new Vector2i(result, result2)));
				}
			}
		}

		internal static bool IsLocked(Vector2i pos)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			if (pos.x < 0 || pos.y < 0)
			{
				return false;
			}
			EnsureLoaded(Player.m_localPlayer);
			if (Cells.Count > 0)
			{
				return Cells.Contains(Key(pos));
			}
			return false;
		}

		internal static void Toggle(Vector2i pos)
		{
			//IL_000f: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null) && pos.x >= 0 && pos.y >= 0)
			{
				EnsureLoaded(localPlayer);
				int item = Key(pos);
				if (!Cells.Remove(item))
				{
					Cells.Add(item);
				}
				Save(localPlayer);
			}
		}

		private static void Save(Player player)
		{
			if (player.m_customData == null)
			{
				return;
			}
			if (Cells.Count == 0)
			{
				player.m_customData.Remove("cdev_es_locks");
				return;
			}
			StringBuilder stringBuilder = new StringBuilder();
			foreach (int cell in Cells)
			{
				if (stringBuilder.Length > 0)
				{
					stringBuilder.Append(';');
				}
				stringBuilder.Append(cell & 0xFF).Append(',').Append(cell >> 8);
			}
			player.m_customData["cdev_es_locks"] = stringBuilder.ToString();
		}
	}
	internal static class Migration
	{
		private const string EaqsSlot = "eaqs_slot";

		private const string EaqsPlayer = "eaqs_player";

		internal static int Normalize(Inventory inventory, int visibleRows)
		{
			//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_002c: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: 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_0179: 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_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			List<ItemData> list = new List<ItemData>();
			HashSet<Vector2i> hashSet = new HashSet<Vector2i>();
			foreach (ItemData item in inventory.m_inventory)
			{
				Vector2i gridPos = item.m_gridPos;
				if (((gridPos.x < 0 || gridPos.x >= inventory.m_width || gridPos.y < 0 || gridPos.y >= visibleRows) && !SlotLayout.InRegion(gridPos)) || !hashSet.Add(gridPos))
				{
					list.Add(item);
				}
			}
			if (list.Count == 0)
			{
				return 0;
			}
			list.Sort((ItemData a, ItemData b) => StampRank(a).CompareTo(StampRank(b)));
			int num = 0;
			foreach (ItemData item2 in list)
			{
				Vector2i gridPos2 = item2.m_gridPos;
				SlotCell slotCell = FromEaqsStamp(item2);
				if (slotCell == null && item2.m_equipped)
				{
					SlotKind slotKind = SlotLayout.HomeKind(item2);
					if (slotKind != SlotKind.None)
					{
						foreach (SlotCell item3 in SlotLayout.CellsOf(slotKind))
						{
							if (!hashSet.Contains(item3.Pos))
							{
								slotCell = item3;
								break;
							}
						}
					}
				}
				Vector2i val;
				if (slotCell != null && !hashSet.Contains(slotCell.Pos) && (slotCell.Kind == SlotKind.Quiver || SlotLayout.Accepts(slotCell, item2)))
				{
					val = slotCell.Pos;
				}
				else
				{
					val = FreeCell(inventory, visibleRows, hashSet);
					if (val.x < 0)
					{
						continue;
					}
					if (SlotLayout.At(val) == null || !SlotLayout.At(val).IsEquipment)
					{
						item2.m_equipped = false;
					}
				}
				hashSet.Add(val);
				item2.m_gridPos = val;
				if (item2.m_customData != null)
				{
					item2.m_customData.Remove("eaqs_slot");
					item2.m_customData.Remove("eaqs_player");
				}
				SlotCell slotCell2 = SlotLayout.At(val);
				num++;
			}
			return num;
		}

		private static int StampRank(ItemData item)
		{
			if (FromEaqsStamp(item) == null)
			{
				if (!item.m_equipped)
				{
					return 2;
				}
				return 1;
			}
			return 0;
		}

		private static SlotCell FromEaqsStamp(ItemData item)
		{
			if (item.m_customData == null || !item.m_customData.TryGetValue("eaqs_slot", out var value) || string.IsNullOrEmpty(value))
			{
				return null;
			}
			if (value.StartsWith("Quick") && int.TryParse(value.Substring(5), out var result) && result >= 1 && result <= 6)
			{
				return SlotLayout.Quick[result - 1];
			}
			if (value.StartsWith("CustomBetterArcheryQuiver") && int.TryParse(value.Substring("CustomBetterArcheryQuiver".Length), out var result2) && result2 >= 1 && result2 <= 3)
			{
				return SlotLayout.Quiver[result2 - 1];
			}
			SlotKind kind;
			switch (value)
			{
			case "Helmet":
				kind = SlotKind.Helmet;
				break;
			case "Chest":
				kind = SlotKind.Chest;
				break;
			case "Legs":
				kind = SlotKind.Legs;
				break;
			case "Shoulder":
				kind = SlotKind.Cape;
				break;
			case "Utility":
				kind = SlotKind.Belt;
				break;
			case "Trinket":
				kind = SlotKind.Trinket;
				break;
			default:
				return null;
			}
			using (IEnumerator<SlotCell> enumerator = SlotLayout.CellsOf(kind).GetEnumerator())
			{
				if (enumerator.MoveNext())
				{
					return enumerator.Current;
				}
			}
			return null;
		}

		private static Vector2i FreeCell(Inventory inventory, int visibleRows, HashSet<Vector2i> taken)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			Vector2i val = default(Vector2i);
			for (int i = 1; i < visibleRows; i++)
			{
				for (int j = 0; j < inventory.m_width; j++)
				{
					((Vector2i)(ref val))..ctor(j, i);
					if (!taken.Contains(val))
					{
						return val;
					}
				}
			}
			Vector2i val2 = default(Vector2i);
			for (int k = 0; k < inventory.m_width; k++)
			{
				((Vector2i)(ref val2))..ctor(k, 0);
				if (!taken.Contains(val2))
				{
					return val2;
				}
			}
			foreach (SlotCell item in SlotLayout.Stash)
			{
				if (!taken.Contains(item.Pos))
				{
					return item.Pos;
				}
			}
			return new Vector2i(-1, -1);
		}

		private static string Name(ItemData item)
		{
			string text = (((Object)(object)item.m_dropPrefab != (Object)null) ? ((Object)item.m_dropPrefab).name : (item.m_shared?.m_name ?? "?"));
			if (item.m_stack <= 1)
			{
				return text;
			}
			return $"{text} x{item.m_stack}";
		}

		internal static int VisibleRows(Player player)
		{
			string s = default(string);
			if (player.TryGetUniqueKeyValue("invrows", ref s) && int.TryParse(s, out var result))
			{
				return Mathf.Clamp(result, 1, 9);
			}
			return Mathf.Max(((Humanoid)player).m_inventory.m_height, 4);
		}
	}
	internal static class ModConfig
	{
		internal static ConfigEntry<KeyboardShortcut> Quick1;

		internal static ConfigEntry<KeyboardShortcut> Quick2;

		internal static ConfigEntry<KeyboardShortcut> Quick3;

		internal static ConfigEntry<KeyboardShortcut> Quick4;

		internal static ConfigEntry<KeyboardShortcut> Quick5;

		internal static ConfigEntry<KeyboardShortcut> Quick6;

		internal static ConfigEntry<KeyboardShortcut> AltModifier;

		internal static ConfigEntry<bool> KeysWinOverVanilla;

		internal static ConfigEntry<bool> ShowKeyConflicts;

		internal static ConfigEntry<bool> GamepadHotbar;

		internal static ConfigEntry<bool> ShowKeys;

		internal static ConfigEntry<int> KeysVersion;

		internal static ConfigEntry<bool> HudEnabled;

		internal static ConfigEntry<Vector2> HudOffset;

		internal static ConfigEntry<float> HudSpacing;

		internal static ConfigEntry<bool> CellLockIcons;

		internal static ConfigEntry<bool> AmmoOnHotbar;

		internal static ConfigEntry<bool> AutoEquipAmmo;

		internal static ConfigEntry<Vector2> PanelOffset;

		internal static ConfigEntry<bool> PanelCharacter;

		internal static ConfigEntry<bool> KeepWornInInventory;

		internal static ConfigEntry<bool> ShowOnKey;

		internal static ConfigEntry<KeyboardShortcut> PanelKey;

		internal static ConfigEntry<string> Rings;

		internal static ConfigEntry<string> Earrings;

		internal static ConfigEntry<string> Amulets;

		internal static void Bind(ConfigFile config)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_008d: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Expected O, but got Unknown
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Expected O, but got Unknown
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Expected O, but got Unknown
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0319: Unknown result type (might be due to invalid IL or missing references)
			//IL_034b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			//IL_0358: Expected O, but got Unknown
			//IL_0358: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Expected O, but got Unknown
			//IL_0385: Unknown result type (might be due to invalid IL or missing references)
			//IL_038a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0392: Expected O, but got Unknown
			//IL_0392: Unknown result type (might be due to invalid IL or missing references)
			//IL_039c: Expected O, but got Unknown
			//IL_03bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cc: Expected O, but got Unknown
			//IL_03cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d6: Expected O, but got Unknown
			Quick1 = config.Bind<KeyboardShortcut>("QuickSlots", "Key1", new KeyboardShortcut((KeyCode)122, Array.Empty<KeyCode>()), "Uses quick slot 1. Any key, or a key with modifiers such as \"O + LeftAlt\"; empty: no key.");
			Quick2 = config.Bind<KeyboardShortcut>("QuickSlots", "Key2", new KeyboardShortcut((KeyCode)118, Array.Empty<KeyCode>()), "Uses quick slot 2. Any key, or a key with modifiers such as \"O + LeftAlt\"; empty: no key.");
			Quick3 = config.Bind<KeyboardShortcut>("QuickSlots", "Key3", new KeyboardShortcut((KeyCode)98, Array.Empty<KeyCode>()), "Uses quick slot 3. Any key, or a key with modifiers such as \"O + LeftAlt\"; empty: no key.");
			Quick4 = config.Bind<KeyboardShortcut>("QuickSlots", "Key4", new KeyboardShortcut((KeyCode)122, (KeyCode[])(object)new KeyCode[1] { (KeyCode)308 }), "Uses quick slot 4. Any key, or a key with modifiers such as \"O + LeftAlt\"; empty: no key.");
			Quick5 = config.Bind<KeyboardShortcut>("QuickSlots", "Key5", new KeyboardShortcut((KeyCode)118, (KeyCode[])(object)new KeyCode[1] { (KeyCode)308 }), "Uses quick slot 5. Any key, or a key with modifiers such as \"O + LeftAlt\"; empty: no key.");
			Quick6 = config.Bind<KeyboardShortcut>("QuickSlots", "Key6", new KeyboardShortcut((KeyCode)98, (KeyCode[])(object)new KeyCode[1] { (KeyCode)308 }), "Uses quick slot 6. Any key, or a key with modifiers such as \"O + LeftAlt\"; empty: no key.");
			AltModifier = config.Bind<KeyboardShortcut>("QuickSlots", "AltModifier", new KeyboardShortcut((KeyCode)308, Array.Empty<KeyCode>()), "While it is held the HUD shows quick slots 4-6 instead of 1-3. Empty or None: always 1-3.");
			KeysVersion = config.Bind<int>("QuickSlots", "KeysVersion", 0, new ConfigDescription("Internal: the key format this file was last converted to. Do not change.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				Browsable = false
			} }));
			KeysWinOverVanilla = config.Bind<bool>("QuickSlots", "KeysWinOverVanilla", false, "A quick slot key without modifiers that is also bound to a game action (vanilla: V auto-pickup, 1-8 the hotbar): false - the key does both, and the clash is shown under the hotbar; true - it does only the quick slot. A key with modifiers (Alt+1) never also does the game action.");
			MigrateKeys();
			ShowKeyConflicts = config.Bind<bool>("QuickSlots", "ShowKeyConflicts", true, "Show a note under the hotbar (while the inventory is closed) when a quick slot key or the equipment window key is also used by something else.");
			GamepadHotbar = config.Bind<bool>("QuickSlots", "GamepadHotbar", true, "With a controller: the hotbar's left / right buttons step on past slot 8 onto the six quick slots, and its use button uses the one selected there.");
			ShowKeys = config.Bind<bool>("QuickSlots", "ShowKeys", true, "Show each quick slot's key (Z, V, B, Alt+Z...) on the slot, on the HUD and in the equipment panel.");
			HudEnabled = config.Bind<bool>("Hud", "Enabled", true, "Show the quick slots next to the forsaken power.");
			HudOffset = config.Bind<Vector2>("Hud", "Offset", Vector2.zero, "Moves the HUD quick slots from their place right of the forsaken power (pixels, x right, y up).");
			HudSpacing = config.Bind<float>("Hud", "Spacing", 8f, new ConfigDescription("Gap between the HUD quick slots.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 64f), Array.Empty<object>()));
			AmmoOnHotbar = config.Bind<bool>("Ammo", "ShowOnHotbar", true, "Above a bow, crossbow or fishing rod on the hotbar (1-8): the ammo it shoots next and how many of it are left.");
			AutoEquipAmmo = config.Bind<bool>("Ammo", "AutoEquip", true, "When the worn arrows (bolts, bait) run out, put on the next of the same kind, else any other that fits the weapon.");
			CellLockIcons = config.Bind<bool>("Inventory", "CellLocks", true, "Show a padlock in the bottom left corner of every inventory cell. Click it to lock the cell: its item is then never moved into a chest by a button that empties the inventory - vanilla's \"stack similar\" and QuickStackStore's quick stack, store and sort.");
			PanelOffset = config.Bind<Vector2>("Panel", "Offset", Vector2.zero, "Moves the equipment panel from its place between the inventory and the crafting panel (pixels, x right, y up).");
			PanelCharacter = config.Bind<bool>("Panel", "ShowCharacter", true, "Draw your character, as it is dressed right now, behind the equipment slots.");
			KeepWornInInventory = config.Bind<bool>("Panel", "KeepWornInInventory", false, "Worn armour, cape, belt, trinket and arrows stay in their inventory cell, as without this mod, and the panel shows them in their slots as well - one item, shown in both places. Off: a worn item moves into its slot and leaves the inventory.");
			ShowOnKey = config.Bind<bool>("Panel", "ShowOnKey", false, "The equipment panel shows only after pressing Key: in the open inventory it shows / hides the panel, with the inventory closed it opens the inventory with the panel. Off: the panel shows whenever the inventory is open.");
			PanelKey = config.Bind<KeyboardShortcut>("Panel", "Key", new KeyboardShortcut((KeyCode)117, Array.Empty<KeyCode>()), "The key of the equipment panel when ShowOnKey is on. Any key, or a key with modifiers such as \"E + LeftAlt\".");
			Rings = config.Bind<string>("Jewelry", "Rings", "", new ConfigDescription("Item prefab names worn in the ring slots, comma-separated.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			Earrings = config.Bind<string>("Jewelry", "Earrings", "", new ConfigDescription("Item prefab names worn in the earring slots, comma-separated.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			Amulets = config.Bind<string>("Jewelry", "Amulets", "", new ConfigDescription("Item prefab names worn in the amulet slot, comma-separated.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			Rings.SettingChanged += delegate
			{
				Jewelry.ReloadConfig();
			};
			Earrings.SettingChanged += delegate
			{
				Jewelry.ReloadConfig();
			};
			Amulets.SettingChanged += delegate
			{
				Jewelry.ReloadConfig();
			};
			Jewelry.ReloadConfig();
		}

		internal static KeyboardShortcut SlotKey(int ordinal)
		{
			//IL_0025: 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_003b: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			return (KeyboardShortcut)(ordinal switch
			{
				0 => Quick1.Value, 
				1 => Quick2.Value, 
				2 => Quick3.Value, 
				3 => Quick4.Value, 
				4 => Quick5.Value, 
				5 => Quick6.Value, 
				_ => KeyboardShortcut.Empty, 
			});
		}

		internal static KeyCode[] AltKeys()
		{
			//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_0013: 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)
			List<KeyCode> list = new List<KeyCode>();
			KeyboardShortcut value = AltModifier.Value;
			if ((int)((KeyboardShortcut)(ref value)).MainKey != 0)
			{
				list.Add(((KeyboardShortcut)(ref value)).MainKey);
				list.AddRange(((KeyboardShortcut)(ref value)).Modifiers);
			}
			return list.ToArray();
		}

		private static void MigrateKeys()
		{
			if (KeysVersion.Value < 2)
			{
				MigrateSlotKeys();
			}
			if (KeysVersion.Value < 3)
			{
				KeysWinOverVanilla.Value = false;
			}
			KeysVersion.Value = 3;
		}

		private static void MigrateSlotKeys()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Invalid comparison between Unknown and I4
			KeyCode[] array = AltKeys();
			ConfigEntry<KeyboardShortcut>[] array2 = new ConfigEntry<KeyboardShortcut>[3] { Quick4, Quick5, Quick6 };
			for (int i = 0; i < 3; i++)
			{
				KeyboardShortcut value = array2[i].Value;
				List<KeyCode> list = new List<KeyCode>(array);
				if (array.Length == 0)
				{
					continue;
				}
				if ((int)((KeyboardShortcut)(ref value)).MainKey == 0)
				{
					KeyboardShortcut val = SlotKey(i);
					if ((int)((KeyboardShortcut)(ref val)).MainKey != 0)
					{
						list.AddRange(((KeyboardShortcut)(ref val)).Modifiers);
						array2[i].Value = new KeyboardShortcut(((KeyboardShortcut)(ref val)).MainKey, list.ToArray());
					}
				}
				else if (((KeyboardShortcut)(ref value)).Modifiers.Count() == 0 && ((int)((KeyboardShortcut)(ref value)).MainKey < 323 || (int)((KeyboardShortcut)(ref value)).MainKey > 329))
				{
					array2[i].Value = new KeyboardShortcut(((KeyboardShortcut)(ref value)).MainKey, list.ToArray());
				}
			}
		}
	}
	[BepInPlugin("cdev.equipmentslots", "CDEV.EquipmentSlots", "0.1.23")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		internal const string EaqsGuid = "randyknapp.mods.equipmentandquickslots";

		internal static ManualLogSource Log;

		private Harmony _harmony;

		internal static bool Active { get; private set; }

		private void Awake()
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			ModConfig.Bind(((BaseUnityPlugin)this).Config);
			Translations.Register();
			Localization.OnLanguageChange = (Action)Delegate.Combine(Localization.OnLanguageChange, new Action(SlotPanel.Invalidate));
			if (Chainloader.PluginInfos.ContainsKey("randyknapp.mods.equipmentandquickslots"))
			{
				Log.LogError((object)"EquipmentAndQuickSlots is installed: CDEV.EquipmentSlots replaces it and stays switched off. Remove EquipmentAndQuickSlots; its slot items are converted on the next load.");
				return;
			}
			Active = true;
			BetterArcheryHost.Setup();
			MultiUtilityHost.Setup();
			_harmony = new Harmony("cdev.equipmentslots");
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
			QuickStackStoreHost.Setup(_harmony);
			LocalCraftFromStorageHost.Setup(_harmony);
			BetterUiHost.Setup();
			EpicLootHost.Setup();
			ModConfig.Quick1.SettingChanged += delegate
			{
				SlotPanel.Invalidate();
				QuickSlots.Invalidate();
			};
			ModConfig.Quick2.SettingChanged += delegate
			{
				SlotPanel.Invalidate();
				QuickSlots.Invalidate();
			};
			ModConfig.Quick3.SettingChanged += delegate
			{
				SlotPanel.Invalidate();
				QuickSlots.Invalidate();
			};
			ModConfig.Quick4.SettingChanged += delegate
			{
				SlotPanel.Invalidate();
				QuickSlots.Invalidate();
			};
			ModConfig.Quick5.SettingChanged += delegate
			{
				SlotPanel.Invalidate();
				QuickSlots.Invalidate();
			};
			ModConfig.Quick6.SettingChanged += delegate
			{
				SlotPanel.Invalidate();
				QuickSlots.Invalidate();
			};
			ModConfig.AltModifier.SettingChanged += delegate
			{
				SlotPanel.Invalidate();
				QuickSlots.Invalidate();
			};
			ModConfig.ShowKeys.SettingChanged += delegate
			{
				SlotPanel.Invalidate();
			};
			ModConfig.KeepWornInInventory.SettingChanged += delegate
			{
				EquipSync.MarkDirty();
			};
			ModConfig.ShowKeyConflicts.SettingChanged += delegate
			{
				KeyConflicts.Recheck();
			};
			ModConfig.ShowOnKey.SettingChanged += delegate
			{
				KeyConflicts.Recheck();
			};
			ModConfig.PanelKey.SettingChanged += delegate
			{
				KeyConflicts.Recheck();
			};
			StartLate();
		}

		private static void StartLate()
		{
			if ((Object)(object)Player.m_localPlayer != (Object)null)
			{
				SlotInventory.Register(((Humanoid)Player.m_localPlayer).m_inventory);
			}
			if ((Object)(object)Hud.instance != (Object)null)
			{
				QuickBar.Create(Hud.instance);
			}
			if ((Object)(object)InventoryGui.instance != (Object)null)
			{
				SlotPanel.Create(InventoryGui.instance);
			}
		}

		private void Update()
		{
			if (Active)
			{
				QuickSlots.Tick();
				SlotPanel.TickKey();
				AmmoRefill.Tick();
				KeyConflicts.Tick();
				EquipSync.Tick();
				QuickBar.Tick();
				PlayerPreview.Tick();
			}
		}

		private void LateUpdate()
		{
			InventoryGui instance = InventoryGui.instance;
			if (Active && (Object)(object)instance != (Object)null && InventoryGui.IsVisible() && (Object)(object)Player.m_localPlayer != (Object)null && SlotPanel.ApplyShown())
			{
				SlotPanel.Refresh(instance, Player.m_localPlayer);
			}
		}

		private void OnDestroy()
		{
			Localization.OnLanguageChange = (Action)Delegate.Remove(Localization.OnLanguageChange, new Action(SlotPanel.Invalidate));
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			SlotPanel.Destroy();
			QuickBar.Destroy();
			KeyConflicts.Destroy();
			HotbarAmmo.Destroy();
			PlayerPreview.Destroy();
		}
	}
	internal static class QuickSlots
	{
		private struct Binding
		{
			internal KeyCode Main;

			internal KeyCode[] Modifiers;

			internal int Slot;
		}

		private static readonly List<Binding> Bindings = new List<Binding>();

		private static readonly bool[] Wanted = new bool[6];

		private static readonly List<KeyCode> FiredKeys = new List<KeyCode>();

		private static readonly List<bool> FiredWithModifiers = new List<bool>();

		private static int s_resolvedFrame = -1;

		private static bool s_bindingsDirty = true;

		private static readonly HashSet<KeyCode> Warned = new HashSet<KeyCode>();

		internal static void Invalidate()
		{
			s_bindingsDirty = true;
		}

		internal static bool AltHeld()
		{
			KeyCode[] array = ModConfig.AltKeys();
			if (array.Length != 0)
			{
				return AllHeld(array);
			}
			return false;
		}

		private static void BuildBindings()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			s_bindingsDirty = false;
			Bindings.Clear();
			for (int i = 0; i < 6; i++)
			{
				Binding item = BindingOf(i);
				if ((int)item.Main == 0)
				{
					continue;
				}
				string text = Unreadable(ModConfig.SlotKey(i));
				if (text != null)
				{
					if (Warned.Add(item.Main))
					{
						Plugin.Log.LogWarning((object)($"Quick slot {i + 1}: the key {text} cannot be read by the game's input system " + "and is ignored - choose another key for QuickSlots.Key" + (i + 1) + "."));