Decompiled source of ComfyQuickSlots v1.7.1

ComfyQuickSlots.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ComfyLib;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ComfyQuickSlots")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ComfyQuickSlots")]
[assembly: AssemblyCopyright("Copyright ©  2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("08d30e30-98ba-4364-8410-f0d2534129ba")]
[assembly: AssemblyFileVersion("1.7.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.7.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ComfyQuickSlots
{
	public static class QuickSlotsManager
	{
		public const int Rows = 5;

		public const int Columns = 8;

		public const string PlayerDataKey = "ComfyQuickSlotsInventory";

		public const int QuickSlotsCount = 3;

		public static readonly string PlayerInventoryName = "ComfyQuickSlotsInventory";

		public static readonly int IsAdditionalTombstoneField = StringExtensionMethods.GetStableHashCode("cqs.tombstone");

		public static readonly List<ItemType> ArmorSlotTypes = new List<ItemType>(5)
		{
			(ItemType)6,
			(ItemType)7,
			(ItemType)11,
			(ItemType)17,
			(ItemType)18
		};

		public static bool FirstLoad = false;

		public static List<ItemData> InitialEquippedArmor = new List<ItemData>();

		public static Vector2i HelmetSlot = new Vector2i(0, 4);

		public static Vector2i ChestSlot = new Vector2i(1, 4);

		public static Vector2i LegsSlot = new Vector2i(2, 4);

		public static Vector2i ShoulderSlot = new Vector2i(3, 4);

		public static Vector2i UtilitySlot = new Vector2i(4, 4);

		public static Vector2i QuickSlot1 = new Vector2i(5, 4);

		public static Vector2i QuickSlot2 = new Vector2i(6, 4);

		public static Vector2i QuickSlot3 = new Vector2i(7, 4);

		public static List<Vector2i> ArmorSlots = new List<Vector2i>(5) { HelmetSlot, ChestSlot, LegsSlot, ShoulderSlot, UtilitySlot };

		public static List<Vector2i> QuickSlots = new List<Vector2i>(3) { QuickSlot1, QuickSlot2, QuickSlot3 };

		public static bool OnMenuLoad = false;

		public static bool ShouldRefreshPlayerGrid { get; set; }

		public static void RefreshBindings()
		{
			ShouldRefreshPlayerGrid = true;
		}

		public static bool AddItemToExistingStacks(Inventory inventory, ItemData item)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			int i = 0;
			if (item.m_shared.m_maxStackSize > 1)
			{
				for (; i < item.m_stack; i++)
				{
					ItemData val = inventory.FindFreeStackItem(item.m_shared.m_name, item.m_quality, (float)item.m_worldLevel);
					if (val != null)
					{
						val.m_stack++;
						continue;
					}
					item.m_stack -= i;
					Vector2i emptyInventorySlot = GetEmptyInventorySlot(inventory, topFirst: true);
					if (emptyInventorySlot.x >= 0)
					{
						item.m_gridPos = emptyInventorySlot;
						inventory.m_inventory.Add(item);
						return true;
					}
					return false;
				}
			}
			return false;
		}

		public static bool AddItemToSlot(Humanoid humanoid, ItemData item, int x, int y)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			humanoid.GetInventory().m_inventory.Add(item);
			item.m_gridPos = new Vector2i(x, y);
			return true;
		}

		public static void EquipAndAddItem(Humanoid humanoid, ItemData item)
		{
			humanoid.m_inventory.AddItem(item);
			EquipItem(humanoid, item);
		}

		public static bool EquipArmorInArmorSlots(Player player)
		{
			for (int i = 0; i < 5; i++)
			{
				if (((Humanoid)player).GetInventory().GetItemAt(i, 4) != null)
				{
					EquipItem((Humanoid)(object)player, ((Humanoid)player).GetInventory().GetItemAt(i, 4));
				}
			}
			return true;
		}

		public static void EquipItem(Humanoid humanoid, ItemData item)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Invalid comparison between Unknown and I4
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Invalid comparison between Unknown and I4
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Invalid comparison between Unknown and I4
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Invalid comparison between Unknown and I4
			if ((int)item.m_shared.m_itemType == 6)
			{
				humanoid.m_helmetItem = item;
			}
			else if ((int)item.m_shared.m_itemType == 7)
			{
				humanoid.m_chestItem = item;
			}
			else if ((int)item.m_shared.m_itemType == 11)
			{
				humanoid.m_legItem = item;
			}
			else if ((int)item.m_shared.m_itemType == 17)
			{
				humanoid.m_shoulderItem = item;
			}
			else if ((int)item.m_shared.m_itemType == 18)
			{
				humanoid.m_utilityItem = item;
			}
			item.m_equipped = true;
			humanoid.SetupEquipment();
			humanoid.TriggerEquipEffect(item);
		}

		public static void GetAllArmorFirst(Player player)
		{
			if (((Humanoid)player).m_helmetItem != null)
			{
				InitialEquippedArmor.Add(((Humanoid)player).m_helmetItem);
			}
			if (((Humanoid)player).m_chestItem != null)
			{
				InitialEquippedArmor.Add(((Humanoid)player).m_chestItem);
			}
			if (((Humanoid)player).m_legItem != null)
			{
				InitialEquippedArmor.Add(((Humanoid)player).m_legItem);
			}
			if (((Humanoid)player).m_shoulderItem != null)
			{
				InitialEquippedArmor.Add(((Humanoid)player).m_shoulderItem);
			}
			if (((Humanoid)player).m_utilityItem != null)
			{
				InitialEquippedArmor.Add(((Humanoid)player).m_utilityItem);
			}
		}

		public static ItemData GetArmorItemToSwap(Humanoid humanoid, 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: Invalid comparison between Unknown and I4
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Invalid comparison between Unknown and I4
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Invalid comparison between Unknown and I4
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Invalid comparison between Unknown and I4
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Invalid comparison between Unknown and I4
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Invalid comparison between Unknown and I4
			ItemType itemType = item.m_shared.m_itemType;
			if ((int)itemType <= 7)
			{
				if ((int)itemType == 6)
				{
					return humanoid.m_helmetItem;
				}
				if ((int)itemType == 7)
				{
					return humanoid.m_chestItem;
				}
			}
			else
			{
				if ((int)itemType == 11)
				{
					return humanoid.m_legItem;
				}
				if ((int)itemType == 17)
				{
					return humanoid.m_shoulderItem;
				}
				if ((int)itemType == 18)
				{
					return humanoid.m_utilityItem;
				}
			}
			return null;
		}

		public static Vector2i GetArmorSlot(ItemData item)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			return ArmorSlots[GetArmorTypeIndex(item)];
		}

		public static int GetArmorSlotIndex(Vector2i loc)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return ArmorSlots.IndexOf(loc);
		}

		public static int GetArmorTypeIndex(ItemData item)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			return ArmorSlotTypes.IndexOf(item.m_shared.m_itemType);
		}

		public static Vector2i GetEmptyInventorySlot(Inventory inventory, bool topFirst)
		{
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			if (topFirst)
			{
				for (int i = 0; i < 5; i++)
				{
					for (int j = 0; j < 8; j++)
					{
						if (inventory.GetItemAt(j, i) == null && i != 4)
						{
							return new Vector2i(j, i);
						}
						if (j > 4 && i == 4 && inventory.GetItemAt(j, i) == null)
						{
							return new Vector2i(j, i);
						}
					}
				}
			}
			else
			{
				for (int num = 4; num >= 0; num--)
				{
					for (int k = 0; k < 8; k++)
					{
						if (inventory.GetItemAt(k, num) == null && num != 4)
						{
							return new Vector2i(k, num);
						}
						if (k > 4 && num == 4 && inventory.GetItemAt(k, num) == null)
						{
							return new Vector2i(k, num);
						}
					}
				}
			}
			return new Vector2i(-1, -1);
		}

		public static bool HaveEmptyInventorySlot(Inventory inventory)
		{
			for (int i = 0; i < 8; i++)
			{
				for (int j = 0; j < 5; j++)
				{
					if (inventory.GetItemAt(i, j) == null && j != 4)
					{
						return true;
					}
					if (i > 4 && j == 4 && inventory.GetItemAt(i, j) == null)
					{
						return true;
					}
				}
			}
			return false;
		}

		public static bool IsArmor(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: Invalid comparison between Unknown and I4
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Invalid comparison between Unknown and I4
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Invalid comparison between Unknown and I4
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Invalid comparison between Unknown and I4
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Invalid comparison between Unknown and I4
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Invalid comparison between Unknown and I4
			ItemType itemType = item.m_shared.m_itemType;
			if ((int)itemType <= 7)
			{
				if ((int)itemType == 6)
				{
					return true;
				}
				if ((int)itemType == 7)
				{
					return true;
				}
			}
			else
			{
				if ((int)itemType == 11)
				{
					return true;
				}
				if ((int)itemType == 17)
				{
					return true;
				}
				if ((int)itemType == 18)
				{
					return true;
				}
			}
			return false;
		}

		public static bool IsArmorSlot(Vector2i loc)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			if (ArmorSlots.Contains(loc))
			{
				return true;
			}
			return false;
		}

		public static bool IsArmorTypeEquipped(Humanoid humanoid, 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: Invalid comparison between Unknown and I4
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Invalid comparison between Unknown and I4
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Invalid comparison between Unknown and I4
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Invalid comparison between Unknown and I4
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Invalid comparison between Unknown and I4
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Invalid comparison between Unknown and I4
			ItemType itemType = item.m_shared.m_itemType;
			if ((int)itemType <= 7)
			{
				if ((int)itemType == 6)
				{
					return humanoid.m_helmetItem != null;
				}
				if ((int)itemType == 7)
				{
					return humanoid.m_chestItem != null;
				}
			}
			else
			{
				if ((int)itemType == 11)
				{
					return humanoid.m_legItem != null;
				}
				if ((int)itemType == 17)
				{
					return humanoid.m_shoulderItem != null;
				}
				if ((int)itemType == 18)
				{
					return humanoid.m_utilityItem != null;
				}
			}
			return false;
		}

		public static bool IsQuickSlot(Vector2i loc)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			if (QuickSlots.Contains(loc))
			{
				return true;
			}
			return false;
		}

		public static bool IsSimilarItemEquipped(ItemData item)
		{
			foreach (ItemData equippedItem in ((Humanoid)Player.m_localPlayer).GetInventory().GetEquippedItems())
			{
				if (item.m_shared.m_name.Equals(equippedItem.m_shared.m_name))
				{
					return true;
				}
			}
			return false;
		}

		public static int ItemCountInInventory(ItemData item)
		{
			int num = 0;
			for (int i = 0; i < 5; i++)
			{
				for (int j = 0; j < 8; j++)
				{
					if (((Humanoid)Player.m_localPlayer).GetInventory().GetItemAt(j, i).m_shared.m_name == item.m_shared.m_name)
					{
						num++;
					}
				}
			}
			return num;
		}

		public static bool MoveArmorItemToSlot(Humanoid humanoid, ItemData item, int x, int y)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			ItemData itemAt = humanoid.GetInventory().GetItemAt(x, y);
			if (itemAt != null && !((object)itemAt).Equals((object?)item))
			{
				return SwapArmorItems(humanoid, item, itemAt, x, y);
			}
			item.m_gridPos = new Vector2i(x, y);
			if (!humanoid.GetInventory().m_inventory.Contains(item))
			{
				humanoid.GetInventory().AddItem(item);
				humanoid.GetInventory().Changed();
				return true;
			}
			return false;
		}

		public static bool Save(Player player)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			ZPackage val = new ZPackage();
			((Humanoid)player).GetInventory().Save(val);
			if (player.m_knownTexts.ContainsKey("ComfyQuickSlotsInventory"))
			{
				player.m_knownTexts["ComfyQuickSlotsInventory"] = val.GetBase64();
			}
			else
			{
				player.m_knownTexts.Add("ComfyQuickSlotsInventory", val.GetBase64());
			}
			return true;
		}

		public static bool SwapArmorItems(Humanoid humanoid, ItemData itemToMove, ItemData itemInArmorSlot, int armorSlotX, int armorSlotY)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//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_0010: 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_0017: Unknown result type (might be due to invalid IL or missing references)
			Vector2i gridPos = itemToMove.m_gridPos;
			itemToMove.m_gridPos = new Vector2i(armorSlotX, armorSlotY);
			itemInArmorSlot.m_gridPos = gridPos;
			humanoid.GetInventory().Changed();
			return false;
		}

		public static bool UnequipAllArmor(Player player)
		{
			for (int i = 0; i < 5; i++)
			{
				ItemData itemAt = ((Humanoid)player).GetInventory().GetItemAt(i, 4);
				if (itemAt != null)
				{
					UnequipItem((Humanoid)(object)player, itemAt);
				}
			}
			return true;
		}

		public static bool UnequipItem(Humanoid player, ItemData item)
		{
			if (player.m_helmetItem == item)
			{
				player.m_helmetItem = null;
				item.m_equipped = false;
				player.SetupEquipment();
				player.TriggerEquipEffect(item);
				return true;
			}
			if (player.m_chestItem == item)
			{
				player.m_chestItem = null;
				item.m_equipped = false;
				player.SetupEquipment();
				player.TriggerEquipEffect(item);
				return true;
			}
			if (player.m_legItem == item)
			{
				player.m_legItem = null;
				item.m_equipped = false;
				player.SetupEquipment();
				player.TriggerEquipEffect(item);
				return true;
			}
			if (player.m_shoulderItem == item)
			{
				player.m_shoulderItem = null;
				item.m_equipped = false;
				player.SetupEquipment();
				player.TriggerEquipEffect(item);
				return true;
			}
			if (player.m_utilityItem == item)
			{
				player.m_utilityItem = null;
				item.m_equipped = false;
				player.SetupEquipment();
				player.TriggerEquipEffect(item);
				return true;
			}
			return false;
		}

		public static bool CanAddItem(Inventory inventory, ItemData item, int stack)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			int num = inventory.m_width * inventory.m_height - 5;
			int num2 = 0;
			string name = item.m_shared.m_name;
			int worldLevel = item.m_worldLevel;
			foreach (ItemData item2 in inventory.m_inventory)
			{
				Vector2i gridPos = item2.m_gridPos;
				if (gridPos.y != 4 || gridPos.x > 4)
				{
					num--;
					if (item2.m_shared.m_name == name && item2.m_worldLevel == worldLevel)
					{
						num2 += item2.m_shared.m_maxStackSize - item2.m_stack;
					}
				}
			}
			if (stack <= 0)
			{
				stack = item.m_stack;
			}
			if (num <= 0)
			{
				return num2 + num * item.m_shared.m_maxStackSize >= stack;
			}
			return true;
		}

		public static bool HasEmptyNonEquipmentSlot(Inventory inventory)
		{
			//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_002b: 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)
			int num = inventory.m_width * inventory.m_height - 5;
			foreach (ItemData item in inventory.m_inventory)
			{
				Vector2i gridPos = item.m_gridPos;
				if (gridPos.y != 4 || gridPos.x > 4)
				{
					num--;
				}
			}
			return num > 0;
		}

		public static int FindFreeNonEquipmentStackSpace(Inventory inventory, string itemName, int worldLevel)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: 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)
			int num = 0;
			foreach (ItemData item in inventory.m_inventory)
			{
				Vector2i gridPos = item.m_gridPos;
				if ((gridPos.y != 4 || gridPos.x > 4) && item.m_shared.m_name == itemName && item.m_worldLevel == worldLevel)
				{
					num += item.m_shared.m_maxStackSize - item.m_stack;
				}
			}
			return num;
		}
	}
	public static class KeyCodeUtils
	{
		public static readonly Dictionary<KeyCode, string> KeyCodeToShortText = new Dictionary<KeyCode, string>
		{
			{
				(KeyCode)97,
				"A"
			},
			{
				(KeyCode)98,
				"B"
			},
			{
				(KeyCode)99,
				"C"
			},
			{
				(KeyCode)100,
				"D"
			},
			{
				(KeyCode)101,
				"E"
			},
			{
				(KeyCode)102,
				"F"
			},
			{
				(KeyCode)103,
				"G"
			},
			{
				(KeyCode)104,
				"H"
			},
			{
				(KeyCode)105,
				"I"
			},
			{
				(KeyCode)106,
				"J"
			},
			{
				(KeyCode)107,
				"K"
			},
			{
				(KeyCode)108,
				"L"
			},
			{
				(KeyCode)109,
				"M"
			},
			{
				(KeyCode)110,
				"N"
			},
			{
				(KeyCode)111,
				"O"
			},
			{
				(KeyCode)112,
				"P"
			},
			{
				(KeyCode)113,
				"Q"
			},
			{
				(KeyCode)114,
				"R"
			},
			{
				(KeyCode)115,
				"S"
			},
			{
				(KeyCode)116,
				"T"
			},
			{
				(KeyCode)117,
				"U"
			},
			{
				(KeyCode)118,
				"V"
			},
			{
				(KeyCode)119,
				"W"
			},
			{
				(KeyCode)120,
				"X"
			},
			{
				(KeyCode)121,
				"Y"
			},
			{
				(KeyCode)122,
				"Z"
			},
			{
				(KeyCode)257,
				"kp1"
			},
			{
				(KeyCode)258,
				"kp2"
			},
			{
				(KeyCode)259,
				"kp3"
			},
			{
				(KeyCode)260,
				"kp4"
			},
			{
				(KeyCode)261,
				"kp5"
			},
			{
				(KeyCode)262,
				"kp6"
			},
			{
				(KeyCode)263,
				"kp7"
			},
			{
				(KeyCode)264,
				"kp8"
			},
			{
				(KeyCode)265,
				"kp9"
			},
			{
				(KeyCode)256,
				"kp10"
			},
			{
				(KeyCode)33,
				"!"
			},
			{
				(KeyCode)34,
				"\""
			},
			{
				(KeyCode)35,
				"#"
			},
			{
				(KeyCode)36,
				"$"
			},
			{
				(KeyCode)38,
				"&"
			},
			{
				(KeyCode)39,
				"'"
			},
			{
				(KeyCode)40,
				"("
			},
			{
				(KeyCode)41,
				")"
			},
			{
				(KeyCode)42,
				"*"
			},
			{
				(KeyCode)43,
				"+"
			},
			{
				(KeyCode)44,
				","
			},
			{
				(KeyCode)45,
				"-"
			},
			{
				(KeyCode)46,
				"."
			},
			{
				(KeyCode)47,
				"/"
			},
			{
				(KeyCode)58,
				":"
			},
			{
				(KeyCode)59,
				";"
			},
			{
				(KeyCode)60,
				"<"
			},
			{
				(KeyCode)61,
				"="
			},
			{
				(KeyCode)62,
				">"
			},
			{
				(KeyCode)63,
				"?"
			},
			{
				(KeyCode)64,
				"@"
			},
			{
				(KeyCode)91,
				"["
			},
			{
				(KeyCode)92,
				"\\"
			},
			{
				(KeyCode)93,
				"]"
			},
			{
				(KeyCode)94,
				"^"
			},
			{
				(KeyCode)95,
				"_"
			},
			{
				(KeyCode)96,
				"`"
			},
			{
				(KeyCode)49,
				"1"
			},
			{
				(KeyCode)50,
				"2"
			},
			{
				(KeyCode)51,
				"3"
			},
			{
				(KeyCode)52,
				"4"
			},
			{
				(KeyCode)53,
				"5"
			},
			{
				(KeyCode)54,
				"6"
			},
			{
				(KeyCode)55,
				"7"
			},
			{
				(KeyCode)56,
				"8"
			},
			{
				(KeyCode)57,
				"9"
			},
			{
				(KeyCode)48,
				"0"
			},
			{
				(KeyCode)266,
				"kp ."
			},
			{
				(KeyCode)267,
				"kp //"
			},
			{
				(KeyCode)268,
				"kp *"
			},
			{
				(KeyCode)269,
				"kp -"
			},
			{
				(KeyCode)270,
				"kp +"
			},
			{
				(KeyCode)272,
				"kp ="
			}
		};

		public static string ToShortString(this KeyCode keyCode)
		{
			//IL_0005: 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 (!KeyCodeToShortText.ContainsKey(keyCode))
			{
				return ((object)(KeyCode)(ref keyCode)).ToString();
			}
			return KeyCodeToShortText[keyCode];
		}

		public static string ToShortString(this KeyboardShortcut keyboardShortcut)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			return string.Join(" + ", ((KeyboardShortcut)(ref keyboardShortcut)).Modifiers.Concat(Enumerable.Repeat<KeyCode>(((KeyboardShortcut)(ref keyboardShortcut)).MainKey, 1)).Select(ToShortString));
		}
	}
	[HarmonyPatch(typeof(FejdStartup))]
	internal static class FejdStartupPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("SetupCharacterPreview")]
		private static void SetupCharacterPreviewPrefix()
		{
			QuickSlotsManager.InitialEquippedArmor.Clear();
			QuickSlotsManager.FirstLoad = false;
		}
	}
	[HarmonyPatch(typeof(Hud))]
	internal static class HudPatch
	{
		private static HotkeyBar hotkeyBar;

		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		private static void AwakePostfix(Hud __instance)
		{
			hotkeyBar = ((Component)__instance).GetComponentInChildren<HotkeyBar>();
			if (PluginConfig.IsModEnabled.Value && !Object.op_Implicit((Object)(object)HotkeyBarPatch.QuickSlotsHotkeyBar) && PluginConfig.EnableQuickslots.Value)
			{
				HotkeyBarPatch.QuickSlotsHotkeyBar = Object.Instantiate<GameObject>(((Component)hotkeyBar).gameObject, __instance.m_rootObject.transform, true);
				((Object)HotkeyBarPatch.QuickSlotsHotkeyBar).name = "QuickSlotsHotkeyBar";
				HotkeyBarPatch.QuickSlotsHotkeyBar.GetComponent<HotkeyBar>().m_selected = -1;
				ConfigPositionedElement configPositionedElement = HotkeyBarPatch.QuickSlotsHotkeyBar.AddComponent<ConfigPositionedElement>();
				configPositionedElement.PositionConfig = PluginConfig.QuickSlotsPosition;
				configPositionedElement.AnchorConfig = PluginConfig.QuickSlotsAnchor;
				configPositionedElement.EnsureCorrectPosition();
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("Update")]
		private static void UpdatePostfix(Hud __instance)
		{
			if (!PluginConfig.IsModEnabled.Value || Object.op_Implicit((Object)(object)HotkeyBarPatch.QuickSlotsHotkeyBar) || !PluginConfig.EnableQuickslots.Value)
			{
				return;
			}
			HotkeyBarPatch.QuickSlotsHotkeyBar = Object.Instantiate<GameObject>(((Component)hotkeyBar).gameObject, __instance.m_rootObject.transform, true);
			((Object)HotkeyBarPatch.QuickSlotsHotkeyBar).name = "QuickSlotsHotkeyBar";
			HotkeyBar component = HotkeyBarPatch.QuickSlotsHotkeyBar.GetComponent<HotkeyBar>();
			component.m_selected = -1;
			ConfigPositionedElement configPositionedElement = HotkeyBarPatch.QuickSlotsHotkeyBar.AddComponent<ConfigPositionedElement>();
			configPositionedElement.PositionConfig = PluginConfig.QuickSlotsPosition;
			configPositionedElement.AnchorConfig = PluginConfig.QuickSlotsAnchor;
			configPositionedElement.EnsureCorrectPosition();
			component.m_items.Clear();
			foreach (ElementData element in component.m_elements)
			{
				Object.Destroy((Object)(object)element.m_go);
			}
			component.m_elements.Clear();
		}
	}
	[HarmonyPatch(typeof(InventoryGrid))]
	internal static class InventoryGridPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("UpdateInventory")]
		private static void UpdateInventoryPostfix(InventoryGrid __instance)
		{
			if ((Object)(object)__instance == (Object)(object)InventoryGui.m_instance.m_playerGrid && QuickSlotsManager.ShouldRefreshPlayerGrid)
			{
				UpdatePlayerGrid(__instance);
			}
		}

		private static void UpdatePlayerGrid(InventoryGrid inventoryGrid)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			QuickSlotsManager.ShouldRefreshPlayerGrid = false;
			int num = 1;
			float num2 = -35f * (float)num;
			RectTransform orCreateBackground = GetOrCreateBackground(inventoryGrid, "ExtInvGrid");
			orCreateBackground.anchoredPosition = new Vector2(0f, num2);
			orCreateBackground.SetSizeWithCurrentAnchors((Axis)0, 590f);
			orCreateBackground.SetSizeWithCurrentAnchors((Axis)1, 300f + 75f * (float)num);
			SetupBindingLabel(inventoryGrid.m_elements[32], "Head");
			SetupBindingLabel(inventoryGrid.m_elements[33], "Chest");
			SetupBindingLabel(inventoryGrid.m_elements[34], "Legs");
			SetupBindingLabel(inventoryGrid.m_elements[35], "Cape");
			SetupBindingLabel(inventoryGrid.m_elements[36], "Util");
			if (PluginConfig.EnableQuickslots.Value)
			{
				SetupBindingLabel(inventoryGrid.m_elements[37], PluginConfig.QuickSlot1.Value.ToShortString());
				SetupBindingLabel(inventoryGrid.m_elements[38], PluginConfig.QuickSlot2.Value.ToShortString());
				SetupBindingLabel(inventoryGrid.m_elements[39], PluginConfig.QuickSlot3.Value.ToShortString());
			}
			else
			{
				SetupBindingLabel(inventoryGrid.m_elements[37], string.Empty, enabled: false);
				SetupBindingLabel(inventoryGrid.m_elements[38], string.Empty, enabled: false);
				SetupBindingLabel(inventoryGrid.m_elements[39], string.Empty, enabled: false);
			}
		}

		private static RectTransform GetOrCreateBackground(InventoryGrid inventoryGrid, string name)
		{
			Transform val = ((Component)inventoryGrid).transform.parent.Find(name);
			if (!Object.op_Implicit((Object)(object)val))
			{
				Transform val2 = ((Component)inventoryGrid).transform.parent.Find("Bkg");
				GameObject obj = Object.Instantiate<GameObject>(((Component)val2).gameObject, val2.parent);
				((Object)obj).name = name;
				val = obj.transform;
				val.SetSiblingIndex(val2.GetSiblingIndex() + 1);
			}
			return (RectTransform)(object)((val is RectTransform) ? val : null);
		}

		private static void SetupBindingLabel(Element element, string text, bool enabled = true)
		{
			Transform val = element.m_go.transform.Find("binding");
			TMP_Text val2 = default(TMP_Text);
			if (Object.op_Implicit((Object)(object)val) && ((Component)val).TryGetComponent<TMP_Text>(ref val2))
			{
				val2.text = text;
				((Behaviour)val2).enabled = enabled;
				val2.fontSize = 12f;
				val2.alignment = (TextAlignmentOptions)257;
				val2.overflowMode = (TextOverflowModes)0;
				val2.textWrappingMode = (TextWrappingModes)0;
			}
		}
	}
	[HarmonyPatch(typeof(InventoryGui))]
	internal static class InventoryGuiPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Show")]
		private static void ShowPostfix(InventoryGui __instance)
		{
			if (Object.op_Implicit((Object)(object)__instance.m_currentContainer))
			{
				SetContainerGridAnchoredPosition(__instance);
			}
			QuickSlotsManager.ShouldRefreshPlayerGrid = true;
		}

		private static void SetContainerGridAnchoredPosition(InventoryGui inventoryGui)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = default(RectTransform);
			if (((Component)((Component)inventoryGui.m_containerGrid).transform.parent).TryGetComponent<RectTransform>(ref val))
			{
				val.anchoredPosition = PluginConfig.ContainerInventoryGridAnchoredPosition.Value;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("OnSelectedItem")]
		private static bool OnSelectedItemPrefix(InventoryGrid grid, ItemData item, Vector2i pos)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			if (QuickSlotsManager.IsArmorSlot(pos))
			{
				return false;
			}
			if (Player.m_localPlayer.IsEquipActionQueued(item))
			{
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch("OnCraftPressed")]
		private static bool OnCraftPressedPrefix(InventoryGui __instance)
		{
			ItemData itemData = ((RecipeDataPair)(ref __instance.m_selectedRecipe)).ItemData;
			if (itemData != null && itemData.m_equipped && !QuickSlotsManager.HasEmptyNonEquipmentSlot(((Humanoid)Player.m_localPlayer).GetInventory()) && QuickSlotsManager.ItemCountInInventory(itemData) >= 1)
			{
				((Character)Player.m_localPlayer).Message((MessageType)2, "Inventory full. Make room to upgrade equipped item.", 0, (Sprite)null);
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(TombStone))]
	internal static class TombstonePatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("GiveBoost")]
		private static bool GiveBoostPrefix(TombStone __instance)
		{
			if (__instance.m_nview.m_zdo.GetBool(QuickSlotsManager.IsAdditionalTombstoneField, false))
			{
				return false;
			}
			return true;
		}
	}
	public sealed class PluginConfig
	{
		public static ConfigEntry<bool> IsModEnabled { get; private set; }

		public static ConfigEntry<bool> EnableQuickslots { get; private set; }

		public static ConfigEntry<KeyCode> QuickSlot1 { get; private set; }

		public static ConfigEntry<KeyCode> QuickSlot2 { get; private set; }

		public static ConfigEntry<KeyCode> QuickSlot3 { get; private set; }

		public static ConfigEntry<TextAnchor> QuickSlotsAnchor { get; private set; }

		public static ConfigEntry<Vector2> QuickSlotsPosition { get; private set; }

		public static ConfigEntry<Vector2> ContainerInventoryGridAnchoredPosition { get; private set; }

		public static ConfigEntry<string> LogFilesPath { get; private set; }

		public static void BindConfig(ConfigFile config)
		{
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			IsModEnabled = config.BindInOrder("_Global", "isModEnabled", defaultValue: true, "Globally enable or disable this mod.");
			EnableQuickslots = config.BindInOrder("QuickSlotToggles", "quickSlotEnable", defaultValue: true, "Enables or disables quickslots.");
			QuickSlot1 = config.BindInOrder<KeyCode>("QuickSlotBinding", "quickSlot1Use", (KeyCode)122, "Hot key for item use in quick slot 1");
			QuickSlot1.OnSettingChanged<KeyCode>(QuickSlotsManager.RefreshBindings);
			QuickSlot2 = config.BindInOrder<KeyCode>("QuickSlotBinding", "quickSlot2Use", (KeyCode)118, "Hot key for item use in quick slot 2");
			QuickSlot2.OnSettingChanged<KeyCode>(QuickSlotsManager.RefreshBindings);
			QuickSlot3 = config.BindInOrder<KeyCode>("QuickSlotBinding", "quickSlot3Use", (KeyCode)98, "Hot key for item use in quick slot 3");
			QuickSlot3.OnSettingChanged<KeyCode>(QuickSlotsManager.RefreshBindings);
			QuickSlotsAnchor = config.BindInOrder<TextAnchor>("QuickSlotsAnchor", "quickSlotsAnchor", (TextAnchor)6, "The point on the HUD to anchor the Quick Slots bar.\nChanging this also changes the pivot of the Quick Slots to that corner.");
			QuickSlotsPosition = config.BindInOrder<Vector2>("QuickSlotsOffset", "quickSlotsOffset", new Vector2(216f, 150f), "The position offset from the Quick Slots Anchor at which to place the QuickSlots.");
			ContainerInventoryGridAnchoredPosition = config.BindInOrder<Vector2>("Container.InventoryGrid", "anchoredPosition", new Vector2(40f, -437f), "The anchoredPosition for the the Container.InventoryGrid panel.");
			LogFilesPath = config.BindInOrder("Logging", "logFilesPath", "ItemsOnDeath/", "Path to where logging of items on death are saved.");
		}
	}
	public static class InventoryLogger
	{
		public static readonly string InventoryCsvHeaderRow = string.Join(",", "name", "crafterId", "crafterName", "gridpos.x", "gridpos.y", "quality", "stack", "variant");

		public static void LogInventoryToFile(Inventory inventory, string filename)
		{
			using StreamWriter streamWriter = File.CreateText(filename);
			streamWriter.AutoFlush = true;
			streamWriter.WriteLine(InventoryCsvHeaderRow);
			foreach (ItemData item in inventory.m_inventory)
			{
				streamWriter.WriteLine(ItemToCsvRow(item));
			}
		}

		private static string ItemToCsvRow(ItemData item)
		{
			return string.Join(",", EscapeCsvField(item.m_shared.m_name), item.m_crafterID, EscapeCsvField(item.m_crafterName), item.m_gridPos.x, item.m_gridPos.y, item.m_quality, item.m_stack, item.m_variant);
		}

		private static string EscapeCsvField(string valueToEscape)
		{
			if (valueToEscape.Contains(","))
			{
				return "\"" + valueToEscape + "\"";
			}
			return valueToEscape;
		}
	}
	[BepInPlugin("com.bruce.valheim.comfyquickslots", "ComfyQuickSlots", "1.7.1")]
	public sealed class ComfyQuickSlots : BaseUnityPlugin
	{
		public const string PluginGuid = "com.bruce.valheim.comfyquickslots";

		public const string PluginName = "ComfyQuickSlots";

		public const string PluginVersion = "1.7.1";

		private static ManualLogSource _logger;

		private void Awake()
		{
			_logger = ((BaseUnityPlugin)this).Logger;
			PluginConfig.BindConfig(((BaseUnityPlugin)this).Config);
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "com.bruce.valheim.comfyquickslots");
		}

		public static void LogInfo(object obj)
		{
			_logger.LogInfo((object)$"[{DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo)}] {obj}");
		}

		private void Update()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null) && PluginConfig.EnableQuickslots.Value && ((Character)localPlayer).TakeInput())
			{
				ItemData val = null;
				if (ZInput.GetKeyDown(PluginConfig.QuickSlot3.Value, true))
				{
					val = ((Humanoid)localPlayer).GetInventory().GetItemAt(7, 4);
				}
				if (ZInput.GetKeyDown(PluginConfig.QuickSlot2.Value, true))
				{
					val = ((Humanoid)localPlayer).GetInventory().GetItemAt(6, 4);
				}
				if (ZInput.GetKeyDown(PluginConfig.QuickSlot1.Value, true))
				{
					val = ((Humanoid)localPlayer).GetInventory().GetItemAt(5, 4);
				}
				if (val != null && !localPlayer.IsEquipActionQueued(val))
				{
					((Humanoid)localPlayer).UseItem((Inventory)null, val, false);
				}
			}
		}
	}
	public sealed class ConfigPositionedElement : MonoBehaviour
	{
		public ConfigEntry<TextAnchor> AnchorConfig;

		public ConfigEntry<Vector2> PositionConfig;

		private RectTransform _rt;

		private TextAnchor _currentAnchor;

		private void Awake()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			_rt = (RectTransform)((Component)this).transform;
			EnsureCorrectPosition();
		}

		private void Update()
		{
			EnsureCorrectPosition();
		}

		public void EnsureCorrectPosition()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: 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_004d: 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_0058: 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_0083: Expected I4, but got Unknown
			//IL_0029: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
			//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)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: 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_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			if (AnchorConfig != null && PositionConfig != null && (_currentAnchor != AnchorConfig.Value || !(_rt.anchoredPosition == PositionConfig.Value)))
			{
				_currentAnchor = AnchorConfig.Value;
				TextAnchor currentAnchor = _currentAnchor;
				Vector2 val = default(Vector2);
				switch ((int)currentAnchor)
				{
				case 0:
				{
					RectTransform rt25 = _rt;
					RectTransform rt26 = _rt;
					RectTransform rt27 = _rt;
					((Vector2)(ref val))..ctor(0f, 1f);
					rt27.anchorMax = val;
					Vector2 pivot = (rt26.anchorMin = val);
					rt25.pivot = pivot;
					break;
				}
				case 1:
				{
					RectTransform rt22 = _rt;
					RectTransform rt23 = _rt;
					RectTransform rt24 = _rt;
					((Vector2)(ref val))..ctor(0.5f, 1f);
					rt24.anchorMax = val;
					Vector2 pivot = (rt23.anchorMin = val);
					rt22.pivot = pivot;
					break;
				}
				case 2:
				{
					RectTransform rt19 = _rt;
					RectTransform rt20 = _rt;
					RectTransform rt21 = _rt;
					((Vector2)(ref val))..ctor(1f, 1f);
					rt21.anchorMax = val;
					Vector2 pivot = (rt20.anchorMin = val);
					rt19.pivot = pivot;
					break;
				}
				case 3:
				{
					RectTransform rt16 = _rt;
					RectTransform rt17 = _rt;
					RectTransform rt18 = _rt;
					((Vector2)(ref val))..ctor(0f, 0.5f);
					rt18.anchorMax = val;
					Vector2 pivot = (rt17.anchorMin = val);
					rt16.pivot = pivot;
					break;
				}
				case 4:
				{
					RectTransform rt13 = _rt;
					RectTransform rt14 = _rt;
					RectTransform rt15 = _rt;
					((Vector2)(ref val))..ctor(0.5f, 0.5f);
					rt15.anchorMax = val;
					Vector2 pivot = (rt14.anchorMin = val);
					rt13.pivot = pivot;
					break;
				}
				case 5:
				{
					RectTransform rt10 = _rt;
					RectTransform rt11 = _rt;
					RectTransform rt12 = _rt;
					((Vector2)(ref val))..ctor(1f, 0.5f);
					rt12.anchorMax = val;
					Vector2 pivot = (rt11.anchorMin = val);
					rt10.pivot = pivot;
					break;
				}
				case 6:
				{
					RectTransform rt7 = _rt;
					RectTransform rt8 = _rt;
					RectTransform rt9 = _rt;
					((Vector2)(ref val))..ctor(0f, 0f);
					rt9.anchorMax = val;
					Vector2 pivot = (rt8.anchorMin = val);
					rt7.pivot = pivot;
					break;
				}
				case 7:
				{
					RectTransform rt4 = _rt;
					RectTransform rt5 = _rt;
					RectTransform rt6 = _rt;
					((Vector2)(ref val))..ctor(0.5f, 0f);
					rt6.anchorMax = val;
					Vector2 pivot = (rt5.anchorMin = val);
					rt4.pivot = pivot;
					break;
				}
				case 8:
				{
					RectTransform rt = _rt;
					RectTransform rt2 = _rt;
					RectTransform rt3 = _rt;
					((Vector2)(ref val))..ctor(1f, 0f);
					rt3.anchorMax = val;
					Vector2 pivot = (rt2.anchorMin = val);
					rt.pivot = pivot;
					break;
				}
				}
				_rt.anchoredPosition = PositionConfig.Value;
			}
		}
	}
	[HarmonyPatch(typeof(HotkeyBar))]
	internal static class HotkeyBarPatch
	{
		public static GameObject QuickSlotsHotkeyBar;

		public static int SelectedHotkeyBarIndex = -1;

		public static int[] HotkeyIndices = new int[3] { 37, 38, 39 };

		public static string[] HotkeyTexts = new string[3]
		{
			PluginConfig.QuickSlot1.Value.ToShortString(),
			PluginConfig.QuickSlot2.Value.ToShortString(),
			PluginConfig.QuickSlot3.Value.ToShortString()
		};

		[HarmonyPrefix]
		[HarmonyPatch("UpdateIcons")]
		private static bool HotkeyBarPrefix(HotkeyBar __instance, Player player)
		{
			//IL_0095: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Expected O, but got Unknown
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0399: Unknown result type (might be due to invalid IL or missing references)
			//IL_0392: Unknown result type (might be due to invalid IL or missing references)
			if (((Object)__instance).name != "QuickSlotsHotkeyBar")
			{
				return true;
			}
			if (__instance.m_elements == null)
			{
				return false;
			}
			foreach (ElementData element in __instance.m_elements)
			{
				Object.Destroy((Object)(object)element.m_go);
			}
			__instance.m_elements.Clear();
			if ((Object)(object)player == (Object)null || ((Character)player).IsDead() || !PluginConfig.EnableQuickslots.Value || __instance.m_items == null)
			{
				return false;
			}
			HotkeyTexts = new string[3]
			{
				PluginConfig.QuickSlot1.Value.ToShortString(),
				PluginConfig.QuickSlot2.Value.ToShortString(),
				PluginConfig.QuickSlot3.Value.ToShortString()
			};
			__instance.m_items.Clear();
			for (int i = 5; i < 8; i++)
			{
				if (((Humanoid)player).GetInventory().GetItemAt(i, 4) != null)
				{
					__instance.m_items.Add(((Humanoid)player).GetInventory().GetItemAt(i, 4));
				}
			}
			for (int j = 0; j < 3; j++)
			{
				ElementData val = new ElementData
				{
					m_go = Object.Instantiate<GameObject>(__instance.m_elementPrefab, ((Component)__instance).transform)
				};
				val.m_go.transform.localPosition = new Vector3((float)j * __instance.m_elementSpace, 0f, 0f);
				val.m_icon = ((Component)((Component)val.m_go.transform).transform.Find("icon")).GetComponent<Image>();
				val.m_durability = ((Component)val.m_go.transform.Find("durability")).GetComponent<GuiBar>();
				val.m_amount = ((Component)val.m_go.transform.Find("amount")).GetComponent<TMP_Text>();
				val.m_equiped = ((Component)val.m_go.transform.Find("equiped")).gameObject;
				val.m_queued = ((Component)val.m_go.transform.Find("queued")).gameObject;
				val.m_selection = ((Component)val.m_go.transform.Find("selected")).gameObject;
				TMP_Text component = ((Component)val.m_go.transform.Find("binding")).GetComponent<TMP_Text>();
				((Behaviour)component).enabled = true;
				component.text = HotkeyTexts[j];
				__instance.m_elements.Add(val);
			}
			foreach (ElementData element2 in __instance.m_elements)
			{
				element2.m_used = false;
			}
			bool flag = ZInput.IsGamepadActive();
			foreach (ItemData item in __instance.m_items)
			{
				ElementData val2 = __instance.m_elements[item.m_gridPos.x - 5];
				val2.m_used = true;
				((Component)val2.m_icon).gameObject.SetActive(true);
				val2.m_icon.sprite = item.GetIcon();
				((Component)val2.m_durability).gameObject.SetActive(item.m_shared.m_useDurability);
				if (item.m_shared.m_useDurability)
				{
					if ((double)item.m_durability <= 0.0)
					{
						val2.m_durability.SetValue(1f);
						val2.m_durability.SetColor((Color)(((double)Mathf.Sin(Time.time * 10f) > 0.0) ? Color.red : new Color(0f, 0f, 0f, 0f)));
					}
					else
					{
						val2.m_durability.SetValue(item.GetDurabilityPercentage());
						val2.m_durability.ResetColor();
					}
				}
				val2.m_equiped.SetActive(item.m_equipped);
				val2.m_queued.SetActive(player.IsEquipActionQueued(item));
				if (item.m_shared.m_maxStackSize > 1)
				{
					((Component)val2.m_amount).gameObject.SetActive(true);
					val2.m_amount.text = item.m_stack + "/" + item.m_shared.m_maxStackSize;
				}
				else
				{
					((Component)val2.m_amount).gameObject.SetActive(false);
				}
			}
			for (int k = 0; k < __instance.m_elements.Count; k++)
			{
				ElementData val3 = __instance.m_elements[k];
				val3.m_selection.SetActive(flag && k == __instance.m_selected);
				if (!val3.m_used)
				{
					((Component)val3.m_icon).gameObject.SetActive(false);
					((Component)val3.m_durability).gameObject.SetActive(false);
					val3.m_equiped.SetActive(false);
					val3.m_queued.SetActive(false);
					((Component)val3.m_amount).gameObject.SetActive(false);
				}
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(Humanoid))]
	internal static class HumanoidPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("EquipItem")]
		private static bool EquipItemPrefix(Humanoid __instance, ref bool __result, ItemData item)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: 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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			if (QuickSlotsManager.IsArmor(item))
			{
				Vector2i armorSlot = QuickSlotsManager.GetArmorSlot(item);
				if (QuickSlotsManager.IsArmorTypeEquipped(__instance, item))
				{
					ItemData armorItemToSwap = QuickSlotsManager.GetArmorItemToSwap(__instance, item);
					QuickSlotsManager.UnequipItem(__instance, armorItemToSwap);
					QuickSlotsManager.EquipItem(__instance, item);
					QuickSlotsManager.MoveArmorItemToSlot(__instance, item, armorSlot.x, armorSlot.y);
					__result = true;
					return false;
				}
				QuickSlotsManager.EquipItem(__instance, item);
				if (item.m_gridPos.x != armorSlot.x || item.m_gridPos.y != armorSlot.y)
				{
					QuickSlotsManager.MoveArmorItemToSlot(__instance, item, armorSlot.x, armorSlot.y);
				}
				__result = true;
				return false;
			}
			return true;
		}

		[HarmonyPostfix]
		[HarmonyPatch("EquipItem")]
		private static void EquipItemPostfix(Humanoid __instance, ItemData item)
		{
			if ((Object)(object)__instance != (Object)null && item != null)
			{
				__instance.GetInventory().Changed();
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("UnequipItem")]
		private static bool UnequipItemPrefix(Humanoid __instance, ItemData item, bool triggerEquipEffects)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			if (item != null && QuickSlotsManager.IsArmor(item) && item.m_equipped)
			{
				if (!QuickSlotsManager.HasEmptyNonEquipmentSlot(__instance.GetInventory()))
				{
					((Character)__instance).Message((MessageType)2, "Inventory full. Item not unequipped.", 0, (Sprite)null);
					return false;
				}
				QuickSlotsManager.UnequipItem(__instance, item);
				Vector2i emptyInventorySlot = QuickSlotsManager.GetEmptyInventorySlot(__instance.GetInventory(), topFirst: true);
				QuickSlotsManager.MoveArmorItemToSlot(__instance, item, emptyInventorySlot.x, emptyInventorySlot.y);
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Inventory))]
	internal static class InventoryPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("AddItem", new Type[]
		{
			typeof(ItemData),
			typeof(int),
			typeof(int),
			typeof(int)
		})]
		private static bool AddItemPrefix(Inventory __instance, ItemData item, int amount, int x, int y)
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			if (item != null && __instance.m_name == "ComfyQuickSlotsInventory")
			{
				if (QuickSlotsManager.FirstLoad && QuickSlotsManager.IsArmor(item) && item.m_equipped)
				{
					if (!QuickSlotsManager.InitialEquippedArmor.Contains(item))
					{
						QuickSlotsManager.InitialEquippedArmor.Add(item);
					}
					return false;
				}
				if (item.m_equipped && QuickSlotsManager.IsArmor(item) && (Object)(object)Player.m_localPlayer != (Object)null)
				{
					QuickSlotsManager.UnequipItem((Humanoid)(object)Player.m_localPlayer, item);
					Vector2i armorSlot = QuickSlotsManager.GetArmorSlot(item);
					if (x == armorSlot.x && y == armorSlot.y)
					{
						return true;
					}
					return false;
				}
				if ((Object)(object)Player.m_localPlayer == (Object)null)
				{
					return true;
				}
				if (x < 5 && y == 4)
				{
					return false;
				}
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch("MoveItemToThis", new Type[]
		{
			typeof(Inventory),
			typeof(ItemData),
			typeof(int),
			typeof(int),
			typeof(int)
		})]
		private static bool MoveItemToThisPrefix(Inventory __instance, ref bool __result, int x, int y)
		{
			if (__instance.m_name == "ComfyQuickSlotsInventory" && x < 5 && y == 4)
			{
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch("FindEmptySlot")]
		private static bool FindEmptySlotPrefix(Inventory __instance, ref Vector2i __result, bool topFirst)
		{
			//IL_0015: 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)
			if (__instance.m_name == "ComfyQuickSlotsInventory")
			{
				__result = QuickSlotsManager.GetEmptyInventorySlot(__instance, topFirst);
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch("HaveEmptySlot")]
		private static bool HaveEmptySlotPrefix(Inventory __instance, ref bool __result)
		{
			if (__instance.m_name == "ComfyQuickSlotsInventory")
			{
				__result = QuickSlotsManager.HasEmptyNonEquipmentSlot(__instance);
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch("CanAddItem", new Type[]
		{
			typeof(ItemData),
			typeof(int)
		})]
		private static bool CanAddItemPrefix(Inventory __instance, ItemData item, int stack, ref bool __result)
		{
			if (__instance == ((Humanoid)Player.m_localPlayer).m_inventory)
			{
				__result = QuickSlotsManager.CanAddItem(__instance, item, stack);
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch("FindFreeStackSpace")]
		private static bool FindFreeStackSpacePrefix(Inventory __instance, string name, float worldLevel, ref int __result)
		{
			if (__instance == ((Humanoid)Player.m_localPlayer).m_inventory)
			{
				__result = QuickSlotsManager.FindFreeNonEquipmentStackSpace(__instance, name, Mathf.RoundToInt(worldLevel));
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Player))]
	internal static class PlayerPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("Awake")]
		private static void AwakePrefix(ref Player __instance)
		{
			((Humanoid)__instance).m_inventory.m_name = "ComfyQuickSlotsInventory";
			((Humanoid)__instance).m_inventory.m_height = 5;
			((Humanoid)__instance).m_inventory.m_width = 8;
		}

		[HarmonyPostfix]
		[HarmonyPatch("Load")]
		private static void LoadPostFix(Player __instance)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.m_knownTexts.ContainsKey("ComfyQuickSlotsInventory"))
			{
				ZPackage val = new ZPackage(__instance.m_knownTexts["ComfyQuickSlotsInventory"]);
				((Humanoid)__instance).GetInventory().Load(val);
				QuickSlotsManager.EquipArmorInArmorSlots(__instance);
				((Humanoid)__instance).GetInventory().Changed();
			}
			else
			{
				QuickSlotsManager.FirstLoad = true;
				foreach (ItemData item in QuickSlotsManager.InitialEquippedArmor)
				{
					QuickSlotsManager.UnequipItem((Humanoid)(object)__instance, item);
					((Humanoid)__instance).GetInventory().AddItem(item);
					((Humanoid)__instance).EquipItem(item, true);
					Vector2i armorSlot = QuickSlotsManager.GetArmorSlot(item);
					QuickSlotsManager.MoveArmorItemToSlot((Humanoid)(object)__instance, item, armorSlot.x, armorSlot.y);
					((Humanoid)__instance).GetInventory().Changed();
				}
				QuickSlotsManager.InitialEquippedArmor.Clear();
			}
			foreach (ItemData item2 in ((Humanoid)__instance).GetInventory().m_inventory)
			{
				if (item2.IsEquipable() && !QuickSlotsManager.IsArmor(item2) && item2.m_equipped)
				{
					((Humanoid)__instance).EquipItem(item2, true);
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("Save")]
		private static bool SavePrefix(Player __instance)
		{
			QuickSlotsManager.FirstLoad = false;
			return QuickSlotsManager.Save(__instance);
		}

		[HarmonyPrefix]
		[HarmonyPatch("UseHotbarItem")]
		private static bool UseHotbarItemPrefix(Player __instance, int index)
		{
			ItemData itemAt = ((Humanoid)__instance).m_inventory.GetItemAt(index - 1, 0);
			if (__instance.IsEquipActionQueued(itemAt))
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Player))]
	internal static class TombstonePatcher
	{
		[HarmonyPrefix]
		[HarmonyPatch("CreateTombStone")]
		private static void CreateTombStonePrefix(Player __instance)
		{
			Directory.CreateDirectory(PluginConfig.LogFilesPath.Value);
			string path = __instance.GetPlayerID() + ".csv";
			InventoryLogger.LogInventoryToFile(((Humanoid)__instance).GetInventory(), Path.Combine(PluginConfig.LogFilesPath.Value, path));
			QuickSlotsManager.UnequipAllArmor(__instance);
			GameObject obj = CreateAdditionalTombstone(__instance);
			SetupAdditionalTombstone(obj.GetComponent<TombStone>());
			Inventory inventory = obj.GetComponent<Container>().GetInventory();
			((Humanoid)__instance).UnequipAllItems();
			Inventory inventory2 = ((Humanoid)__instance).GetInventory();
			foreach (ItemData item in new List<ItemData>(inventory2.GetAllItems()))
			{
				if (item.m_gridPos.y >= 4 && !item.m_equipped)
				{
					inventory.AddItem(item);
					inventory2.RemoveItem(item);
				}
			}
			((Humanoid)__instance).GetInventory().m_height = 4;
			((Humanoid)__instance).GetInventory().m_width = 8;
		}

		private static GameObject CreateAdditionalTombstone(Player player)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = Object.Instantiate<GameObject>(player.m_tombstone, ((Character)player).GetCenterPoint() + Vector3.up * 1.25f, ((Component)player).transform.rotation);
			Transform transform = obj.transform;
			transform.localScale -= new Vector3(0.5f, 0.5f, 0.5f);
			return obj;
		}

		private static void SetupAdditionalTombstone(TombStone tombstone)
		{
			PlayerProfile playerProfile = Game.instance.GetPlayerProfile();
			tombstone.m_nview.m_zdo.Set(ZDOVars.s_owner, playerProfile.GetPlayerID());
			tombstone.m_nview.m_zdo.Set(ZDOVars.s_ownerName, playerProfile.GetName());
			tombstone.m_nview.m_zdo.Set(QuickSlotsManager.IsAdditionalTombstoneField, true);
		}

		[HarmonyPostfix]
		[HarmonyPatch("CreateTombStone")]
		private static void CreateTombStonePostfix(Player __instance)
		{
			((Humanoid)__instance).GetInventory().m_height = 5;
			((Humanoid)__instance).GetInventory().m_width = 8;
		}
	}
}
namespace ComfyLib
{
	public static class ConfigFileExtensions
	{
		internal sealed class ConfigurationManagerAttributes
		{
			public Action<ConfigEntryBase> CustomDrawer;

			public bool? Browsable;

			public bool? HideDefaultButton;

			public bool? HideSettingName;

			public bool? IsAdvanced;

			public int? Order;

			public bool? ReadOnly;
		}

		private static readonly Dictionary<string, int> _sectionToSettingOrder = new Dictionary<string, int>();

		private static int GetSettingOrder(string section)
		{
			if (!_sectionToSettingOrder.TryGetValue(section, out var value))
			{
				value = 0;
			}
			_sectionToSettingOrder[section] = value - 1;
			return value;
		}

		public static ConfigEntry<T> BindInOrder<T>(this ConfigFile config, string section, string key, T defaultValue, string description, AcceptableValueBase acceptableValues, bool browsable = true, bool hideDefaultButton = false, bool hideSettingName = false, bool isAdvanced = false, bool readOnly = false)
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			return config.Bind<T>(section, key, defaultValue, new ConfigDescription(description, acceptableValues, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Browsable = browsable,
					CustomDrawer = null,
					HideDefaultButton = hideDefaultButton,
					HideSettingName = hideSettingName,
					IsAdvanced = isAdvanced,
					Order = GetSettingOrder(section),
					ReadOnly = readOnly
				}
			}));
		}

		public static ConfigEntry<T> BindInOrder<T>(this ConfigFile config, string section, string key, T defaultValue, string description, Action<ConfigEntryBase> customDrawer = null, bool browsable = true, bool hideDefaultButton = false, bool hideSettingName = false, bool isAdvanced = false, bool readOnly = false)
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			return config.Bind<T>(section, key, defaultValue, new ConfigDescription(description, (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Browsable = browsable,
					CustomDrawer = customDrawer,
					HideDefaultButton = hideDefaultButton,
					HideSettingName = hideSettingName,
					IsAdvanced = isAdvanced,
					Order = GetSettingOrder(section),
					ReadOnly = readOnly
				}
			}));
		}

		public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action settingChangedHandler)
		{
			configEntry.SettingChanged += delegate
			{
				settingChangedHandler();
			};
		}

		public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action<T> settingChangedHandler)
		{
			configEntry.SettingChanged += delegate(object _, EventArgs eventArgs)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				settingChangedHandler((T)((SettingChangedEventArgs)eventArgs).ChangedSetting.BoxedValue);
			};
		}

		public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action<ConfigEntry<T>> settingChangedHandler)
		{
			configEntry.SettingChanged += delegate(object _, EventArgs eventArgs)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				settingChangedHandler((ConfigEntry<T>)((SettingChangedEventArgs)eventArgs).ChangedSetting.BoxedValue);
			};
		}
	}
}