Decompiled source of ExtraSlots v1.0.3

ExtraSlots.dll

Decompiled 10 hours ago
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using HarmonyLib;
using JetBrains.Annotations;
using LocalizationManager;
using Microsoft.CodeAnalysis;
using ServerSync;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Core.Tokens;
using YamlDotNet.Helpers;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.Converters;
using YamlDotNet.Serialization.EventEmitters;
using YamlDotNet.Serialization.NamingConventions;
using YamlDotNet.Serialization.NodeDeserializers;
using YamlDotNet.Serialization.NodeTypeResolvers;
using YamlDotNet.Serialization.ObjectFactories;
using YamlDotNet.Serialization.ObjectGraphTraversalStrategies;
using YamlDotNet.Serialization.ObjectGraphVisitors;
using YamlDotNet.Serialization.Schemas;
using YamlDotNet.Serialization.TypeInspectors;
using YamlDotNet.Serialization.TypeResolvers;
using YamlDotNet.Serialization.Utilities;
using YamlDotNet.Serialization.ValueDeserializers;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ExtraSlots")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ExtraSlots")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("7e559c9a-ba1c-45b5-a260-ec3a1455248b")]
[assembly: AssemblyFileVersion("1.0.3")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.0")]
[module: UnverifiableCode]
namespace ExtraSlots
{
	public static class BetterArcheryCompat
	{
		[HarmonyPatch(typeof(FejdStartup), "Start")]
		private static class FejdStartup_Start_DisableBetterArcheryQuiver
		{
			private static void Postfix()
			{
				DisableQuiver();
			}
		}

		public const string betterArcheryGUID = "ishid4.mods.betterarchery";

		public static PluginInfo pluginBetterArchery;

		public static ConfigEntry<bool> baEnableQuiver;

		public static void CheckForCompatibility()
		{
			if (!Chainloader.PluginInfos.TryGetValue("ishid4.mods.betterarchery", out pluginBetterArchery))
			{
				return;
			}
			if (pluginBetterArchery.Instance.Config.TryGetEntry<bool>("Quiver", "Enable Quiver", ref baEnableQuiver))
			{
				baEnableQuiver.SettingChanged += delegate
				{
					DisableQuiver();
				};
			}
			MethodInfo methodInfo = AccessTools.Method("TombStone:OnTakeAllSuccess", (Type[])null, (Type[])null);
			MethodInfo methodInfo2 = AccessTools.Method("BetterArchery.Tombstone+TombStone_OnTakeAllSuccess_Patch:Postfix", (Type[])null, (Type[])null);
			if (methodInfo != null && methodInfo2 != null)
			{
				ExtraSlots.instance.harmony.Unpatch((MethodBase)methodInfo, methodInfo2);
				ExtraSlots.LogInfo("BetterArchery's BetterArchery.Tombstone+TombStone_OnTakeAllSuccess_Patch:Postfix was unpatched.");
			}
		}

		private static void DisableQuiver()
		{
			if (pluginBetterArchery != null && baEnableQuiver != null && baEnableQuiver.Value)
			{
				baEnableQuiver.Value = false;
				ExtraSlots.LogWarning("BetterArchery's Quiver was disabled to prevent issues with inventory grid. You will not lose arrows if you had Quiver enabled in your previous session." + $"\nThis logic is designed for BetterArchery version 1.9.8, current version is {pluginBetterArchery.Metadata.Version}. If quiver implementation was changed pls contact me at any platform.");
			}
		}
	}
	internal class EquipmentAndQuickSlotsCompat
	{
		[HarmonyPatch(typeof(Player), "Load")]
		public static class Player_Load_TryLoadEaQSData
		{
			[HarmonyPriority(300)]
			public static void Postfix(Player __instance)
			{
				if (__instance.m_customData.ContainsKey("EquipmentSlotInventory") && (Object.op_Implicit((Object)(object)FejdStartup.instance) || Slots.IsValidPlayer((Humanoid)(object)__instance)))
				{
					playerToLoad = __instance;
					Load();
					playerToLoad = null;
				}
			}
		}

		public const int QuickSlotCount = 3;

		public const int EquipSlotCount = 5;

		public static Inventory QuickSlotInventory = new Inventory("QuickSlotInventory", (Sprite)null, 3, 1);

		public static Inventory EquipmentSlotInventory = new Inventory("EquipmentSlotInventory", (Sprite)null, 5, 1);

		internal static Player playerToLoad;

		public const string Sentinel = "<|>";

		public static void Load()
		{
			if (!((Object)(object)playerToLoad == (Object)null))
			{
				LoadInventory(EquipmentSlotInventory, equipItem: true, (Object)(object)Player.m_localPlayer == (Object)null);
				LoadInventory(QuickSlotInventory, equipItem: false, (Object)(object)Player.m_localPlayer == (Object)null);
			}
		}

		private static void LoadInventory(Inventory inventory, bool equipItem, bool loadOnly)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			if (LoadValue(playerToLoad, inventory.m_name, out var value))
			{
				ZPackage val = new ZPackage(value);
				inventory.Load(val);
				TransferItemsToPlayerInventory(inventory, equipItem);
				if (!loadOnly)
				{
					val = new ZPackage();
					inventory.Save(val);
					SaveValue(playerToLoad, inventory.m_name, val.GetBase64());
				}
			}
		}

		private static void TransferItemsToPlayerInventory(Inventory fromInventory, bool equipItem)
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			foreach (ItemData item in from item in fromInventory.GetAllItemsInGridOrder()
				where item != null
				select item)
			{
				if (!(TryFindSlotForItem(item, out var slot) ? Slots.PlayerInventory.AddItem(item, slot.GridPosition) : Slots.PlayerInventory.AddItem(item)))
				{
					if (Slots.TryMakeFreeSpaceInPlayerInventory(tryFindRegularInventorySlot: true, out var gridPos))
					{
						ExtraSlots.LogInfo($"Item {item.m_shared.m_name} from EaQS was put to created free space {gridPos}");
						item.m_gridPos = gridPos;
					}
					else
					{
						ExtraSlots.LogWarning("Item " + item.m_shared.m_name + " was temporary put out of grid. It will return to inventory first free slot.");
						item.m_gridPos = new Vector2i(0, Slots.InventoryHeightFull);
					}
					Slots.PlayerInventory.m_inventory.Add(item);
				}
				ExtraSlots.LogMessage("Item " + item.m_shared.m_name + " was loaded from EquipmentAndQuickSlots " + fromInventory.m_name);
				if (equipItem)
				{
					((Humanoid)playerToLoad).UseItem(((Humanoid)playerToLoad).GetInventory(), item, false);
				}
			}
			fromInventory.m_inventory.Clear();
		}

		private static bool TryFindSlotForItem(ItemData item, out Slots.Slot slot)
		{
			return Slots.TryFindFreeEquipmentSlotForItem(item, out slot) || Slots.TryFindFreeSlotForItem(item, out slot);
		}

		private static bool LoadValue(Player player, string key, out string value)
		{
			if (player.m_customData.TryGetValue(key, out value))
			{
				return true;
			}
			if (!player.m_knownTexts.TryGetValue(key, out var _))
			{
				key = "<|>" + key;
			}
			bool flag = player.m_knownTexts.TryGetValue(key, out value);
			if (flag)
			{
				ExtraSlots.LogWarning("Loaded data from knownTexts. Will be converted to customData on save.");
			}
			return flag;
		}

		private static void SaveValue(Player player, string key, string value)
		{
			if (player.m_knownTexts.ContainsKey(key))
			{
				ExtraSlots.LogWarning("Found KnownText for save data, converting to customData");
				player.m_knownTexts.Remove(key);
			}
			if (player.m_customData.ContainsKey(key))
			{
				player.m_customData[key] = value;
			}
			else
			{
				player.m_customData.Add(key, value);
			}
		}
	}
	public static class EquipmentPanel
	{
		private static class SlotPositions
		{
			private static int Column(int i)
			{
				return i / 3;
			}

			private static int Row(int i)
			{
				return i % 3;
			}

			private static int LastEquipmentRow()
			{
				return Row(equipmentSlotsCount - 1);
			}

			internal static int LastEquipmentColumn()
			{
				return Column(equipmentSlotsCount - 1);
			}

			internal static Vector2 GetEquipmentTileOffset(int i)
			{
				//IL_0079: Unknown result type (might be due to invalid IL or missing references)
				//IL_007e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0081: Unknown result type (might be due to invalid IL or missing references)
				int x = Column(i) * 4 + ((ExtraSlots.equipmentSlotsAlignment.Value == ExtraSlots.SlotsAlignment.VerticalTopHorizontalMiddle && Row(i) > LastEquipmentRow()) ? 1 : 0) * 2 + Math.Max(quickSlotsCount - 1 - LastEquipmentColumn(), 0) * 2;
				int y = Row(i) * 4 + Math.Max((ExtraSlots.equipmentSlotsAlignment.Value == ExtraSlots.SlotsAlignment.VerticalMiddleHorizontalLeft && Column(i) == LastEquipmentColumn()) ? (2 - LastEquipmentRow()) : 0, 0) * 2;
				return GetSlotPosition(x, y);
			}

			internal static Vector2 GetQuickSlotTileOffset(int i)
			{
				//IL_0034: 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_003c: Unknown result type (might be due to invalid IL or missing references)
				int x = i * 4 + Math.Max(ExtraSlots.quickSlotsAlignmentCenter.Value ? (LastEquipmentColumn() + 1 - quickSlotsCount) : 0, 0);
				int y = EquipmentHeight * 4 + 1;
				return GetSlotPosition(x, y);
			}

			internal static Vector2 GetFoodSlotTileOffset(int i)
			{
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				int x = Math.Max(LastEquipmentColumn() + 1, quickSlotsCount) * 4 + 1;
				int y = i * 4;
				return GetSlotPosition(x, y);
			}

			internal static Vector2 GetAmmoSlotTileOffset(int i)
			{
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				int x = Math.Max(LastEquipmentColumn() + 1, quickSlotsCount) * 4 + 1 + (Slots.IsFoodSlotAvailable() ? 4 : 0);
				int y = i * 4;
				return GetSlotPosition(x, y);
			}

			internal static Vector2 GetMiscSlotTileOffset(int i)
			{
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				//IL_002f: Unknown result type (might be due to invalid IL or missing references)
				int x = Math.Max(LastEquipmentColumn() + 1, quickSlotsCount) * 4 + i * 4 + 1;
				int y = EquipmentHeight * 4 + 1;
				return GetSlotPosition(x, y);
			}

			private static Vector2 GetSlotPosition(int x, int y)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				return PanelPosition + new Vector2((float)x * 70f / 4f, (float)(-y) * 70f / 4f);
			}
		}

		[HarmonyPatch(typeof(InventoryGui), "Show")]
		private static class InventoryGui_Show_UpdatePanel
		{
			private static void Postfix()
			{
				if (!((Object)(object)Player.m_localPlayer == (Object)null))
				{
					UpdatePanel();
				}
			}
		}

		[HarmonyPatch(typeof(InventoryGui), "OnDestroy")]
		private static class InventoryGui_OnDestroy_ClearObjects
		{
			private static void Postfix()
			{
				ClearPanel();
			}
		}

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

		[HarmonyPatch(typeof(InventoryGrid), "UpdateGui")]
		internal static class InventoryGrid_UpdateGui_UpdateSlotsOnDirty
		{
			private static void Prefix(InventoryGrid __instance, ref int __state)
			{
				if (!((Object)(object)__instance != (Object)(object)InventoryGui.instance.m_playerGrid))
				{
					__state = __instance.m_elements.Count;
				}
			}

			private static void Postfix(InventoryGrid __instance, int __state)
			{
				if (!((Object)(object)__instance != (Object)(object)InventoryGui.instance.m_playerGrid))
				{
					if (__state != __instance.m_elements.Count)
					{
						MarkDirty();
					}
					UpdateInventorySlots();
				}
			}
		}

		[HarmonyPatch(typeof(InventoryGui), "SetupDragItem")]
		private static class InventoryGui_SetupDragItem_UpdateSlotsOnItemDrag
		{
			private static void Postfix()
			{
				MarkDirty();
			}
		}

		[HarmonyPatch(typeof(InventoryGrid), "UpdateGamepad")]
		public static class InventoryGrid_UpdateGamepad_GamepadSupport
		{
			public static Vector2i FindEquipmentSlot(int row = -1, Slots.Slot slotRow = null, int col = -1, Slots.Slot slotCol = null, bool right = false, Slots.Slot before = null, Slots.Slot after = null)
			{
				//IL_010b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0110: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
				Slots.Slot[] equipmentSlots = Slots.GetEquipmentSlots();
				if (row == -1 && slotRow != null)
				{
					row = Array.IndexOf(equipmentSlots, slotRow) % 3;
				}
				if (col == -1 && slotCol != null)
				{
					col = Array.IndexOf(equipmentSlots, slotCol) / 3;
				}
				int num = ((before == null) ? (-1) : Array.IndexOf(equipmentSlots, before));
				int num2 = ((after == null) ? (-1) : Array.IndexOf(equipmentSlots, after));
				int num3 = (right ? equipmentSlots.Length : (-1));
				while (true)
				{
					num3 = ((!right) ? (num3 + 1) : (num3 - 1));
					if (num3 < 0 || num3 == equipmentSlots.Length)
					{
						break;
					}
					if ((num <= -1 || num3 < num) && (num2 <= -1 || num3 > num2))
					{
						if (row == -1 && col == -1)
						{
							return equipmentSlots[num3].GridPosition;
						}
						if ((row != -1 && row == num3 % 3) || (col != -1 && col == num3 / 3))
						{
							return equipmentSlots[num3].GridPosition;
						}
					}
				}
				return Slots.emptyPosition;
			}

			private static bool Prefix(InventoryGrid __instance)
			{
				//IL_0034: Unknown result type (might be due to invalid IL or missing references)
				//IL_0066: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
				//IL_0367: 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_014c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0152: Unknown result type (might be due to invalid IL or missing references)
				//IL_0157: Unknown result type (might be due to invalid IL or missing references)
				//IL_0171: Unknown result type (might be due to invalid IL or missing references)
				//IL_0176: Unknown result type (might be due to invalid IL or missing references)
				//IL_04f1: Unknown result type (might be due to invalid IL or missing references)
				//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
				//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
				//IL_01bb: 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_00e7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
				//IL_0797: Unknown result type (might be due to invalid IL or missing references)
				//IL_049c: Unknown result type (might be due to invalid IL or missing references)
				//IL_04a1: Unknown result type (might be due to invalid IL or missing references)
				//IL_04a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_04a5: Unknown result type (might be due to invalid IL or missing references)
				//IL_032b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0330: Unknown result type (might be due to invalid IL or missing references)
				//IL_020f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0214: Unknown result type (might be due to invalid IL or missing references)
				//IL_0111: Unknown result type (might be due to invalid IL or missing references)
				//IL_0116: Unknown result type (might be due to invalid IL or missing references)
				//IL_055d: Unknown result type (might be due to invalid IL or missing references)
				//IL_04b6: Unknown result type (might be due to invalid IL or missing references)
				//IL_04b8: Unknown result type (might be due to invalid IL or missing references)
				//IL_065e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0663: Unknown result type (might be due to invalid IL or missing references)
				//IL_0514: Unknown result type (might be due to invalid IL or missing references)
				//IL_0519: Unknown result type (might be due to invalid IL or missing references)
				//IL_0405: Unknown result type (might be due to invalid IL or missing references)
				//IL_040a: Unknown result type (might be due to invalid IL or missing references)
				//IL_09de: Unknown result type (might be due to invalid IL or missing references)
				//IL_07ee: Unknown result type (might be due to invalid IL or missing references)
				//IL_07f3: Unknown result type (might be due to invalid IL or missing references)
				//IL_05d3: Unknown result type (might be due to invalid IL or missing references)
				//IL_0831: Unknown result type (might be due to invalid IL or missing references)
				//IL_0836: Unknown result type (might be due to invalid IL or missing references)
				//IL_075b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0760: Unknown result type (might be due to invalid IL or missing references)
				//IL_0580: Unknown result type (might be due to invalid IL or missing references)
				//IL_0585: Unknown result type (might be due to invalid IL or missing references)
				//IL_0471: Unknown result type (might be due to invalid IL or missing references)
				//IL_0476: Unknown result type (might be due to invalid IL or missing references)
				//IL_0458: Unknown result type (might be due to invalid IL or missing references)
				//IL_045d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0296: Unknown result type (might be due to invalid IL or missing references)
				//IL_029b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0281: Unknown result type (might be due to invalid IL or missing references)
				//IL_0286: Unknown result type (might be due to invalid IL or missing references)
				//IL_0982: Unknown result type (might be due to invalid IL or missing references)
				//IL_0987: Unknown result type (might be due to invalid IL or missing references)
				//IL_0919: Unknown result type (might be due to invalid IL or missing references)
				//IL_091e: Unknown result type (might be due to invalid IL or missing references)
				//IL_06d0: Unknown result type (might be due to invalid IL or missing references)
				//IL_06d5: Unknown result type (might be due to invalid IL or missing references)
				//IL_0644: Unknown result type (might be due to invalid IL or missing references)
				//IL_0649: Unknown result type (might be due to invalid IL or missing references)
				//IL_02de: Unknown result type (might be due to invalid IL or missing references)
				//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
				//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
				//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
				//IL_0bd1: Unknown result type (might be due to invalid IL or missing references)
				//IL_09a2: Unknown result type (might be due to invalid IL or missing references)
				//IL_09a7: Unknown result type (might be due to invalid IL or missing references)
				//IL_093f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0944: Unknown result type (might be due to invalid IL or missing references)
				//IL_08b9: Unknown result type (might be due to invalid IL or missing references)
				//IL_08ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_08b3: Unknown result type (might be due to invalid IL or missing references)
				//IL_05f6: Unknown result type (might be due to invalid IL or missing references)
				//IL_05fb: Unknown result type (might be due to invalid IL or missing references)
				//IL_095f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0964: Unknown result type (might be due to invalid IL or missing references)
				//IL_0888: Unknown result type (might be due to invalid IL or missing references)
				//IL_088d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0732: Unknown result type (might be due to invalid IL or missing references)
				//IL_0737: Unknown result type (might be due to invalid IL or missing references)
				//IL_0a3d: Unknown result type (might be due to invalid IL or missing references)
				//IL_08de: Unknown result type (might be due to invalid IL or missing references)
				//IL_08e3: Unknown result type (might be due to invalid IL or missing references)
				//IL_0b51: Unknown result type (might be due to invalid IL or missing references)
				//IL_0b1e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0b23: Unknown result type (might be due to invalid IL or missing references)
				//IL_0aeb: Unknown result type (might be due to invalid IL or missing references)
				//IL_0af0: Unknown result type (might be due to invalid IL or missing references)
				//IL_0b45: Unknown result type (might be due to invalid IL or missing references)
				//IL_0b4a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0aa2: Unknown result type (might be due to invalid IL or missing references)
				//IL_0aa7: Unknown result type (might be due to invalid IL or missing references)
				//IL_0b95: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)__instance != (Object)(object)InventoryGui.instance.m_playerGrid || !__instance.m_uiGroup.IsActive || Console.IsVisible())
				{
					return true;
				}
				Slots.Slot slotInGrid = Slots.GetSlotInGrid(__instance.m_selected);
				if (ZInput.GetButtonDown("JoyDPadLeft") || ZInput.GetButtonDown("JoyLStickLeft"))
				{
					ExtraSlots.LogDebug($"From {__instance.m_selected} {slotInGrid} left");
					if (slotInGrid != null)
					{
						if (slotInGrid.IsAmmoSlot)
						{
							__instance.m_selected.x += 3;
							Slots.Slot slotInGrid2 = Slots.GetSlotInGrid(__instance.m_selected);
							if (slotInGrid2 == null || !slotInGrid2.IsActive)
							{
								int num = __instance.m_selected.x % 3;
								__instance.m_selected = FindEquipmentSlot(num, null, -1, null, right: true);
								if (__instance.m_selected == Slots.emptyPosition)
								{
									__instance.m_selected = new Vector2i(Slots.InventoryWidth - 1, num);
								}
							}
						}
						else if (slotInGrid.IsFoodSlot)
						{
							int num2 = __instance.m_selected.x % 3;
							__instance.m_selected = FindEquipmentSlot(num2, null, -1, null, right: true);
							if (__instance.m_selected == Slots.emptyPosition)
							{
								__instance.m_selected = new Vector2i(Slots.InventoryWidth - 1, num2);
							}
						}
						else if (slotInGrid.IsQuickSlot)
						{
							__instance.m_selected.x--;
							if (__instance.m_selected.x < 0)
							{
								__instance.m_selected = new Vector2i(Slots.InventoryWidth - 1, 3);
							}
						}
						else if (slotInGrid.IsMiscSlot)
						{
							__instance.m_selected.x--;
							Slots.Slot slotInGrid3 = Slots.GetSlotInGrid(__instance.m_selected);
							if (slotInGrid3 == null)
							{
								__instance.m_selected = new Vector2i(Slots.InventoryWidth - 1, 3);
							}
							else if (!slotInGrid3.IsActive)
							{
								if (slotInGrid3.IsQuickSlot)
								{
									IEnumerable<Slots.Slot> source = from slot in Slots.GetQuickSlots()
										where slot.IsActive
										select slot;
									if (source.Any())
									{
										__instance.m_selected = source.Last().GridPosition;
									}
									else
									{
										__instance.m_selected = new Vector2i(Slots.InventoryWidth - 1, 3);
									}
								}
								else if (slotInGrid3.IsMiscSlot && quickSlotsCount == 0)
								{
									__instance.m_selected = new Vector2i(Slots.InventoryWidth - 1, 3);
								}
								else
								{
									__instance.m_selected = new Vector2i(Slots.InventoryWidth - 1, 3);
								}
							}
						}
						else
						{
							__instance.m_selected = FindEquipmentSlot(-1, slotInGrid, -1, null, right: true, slotInGrid);
							if (__instance.m_selected.x < 0)
							{
								__instance.m_selected = new Vector2i(Slots.InventoryWidth - 1, Array.IndexOf(Slots.GetEquipmentSlots(), slotInGrid) % 3);
							}
						}
						return false;
					}
				}
				if (ZInput.GetButtonDown("JoyDPadRight") || ZInput.GetButtonDown("JoyLStickRight"))
				{
					ExtraSlots.LogDebug($"From {__instance.m_selected} {slotInGrid} right");
					if (slotInGrid != null)
					{
						if (slotInGrid.IsFoodSlot)
						{
							Slots.Slot slotInGrid4 = Slots.GetSlotInGrid(new Vector2i(__instance.m_selected.x - 3, __instance.m_selected.y));
							if (slotInGrid4 != null && slotInGrid4.IsActive)
							{
								__instance.m_selected = slotInGrid4.GridPosition;
							}
						}
						else
						{
							if (slotInGrid.IsAmmoSlot)
							{
								return false;
							}
							if (slotInGrid.IsMiscSlot)
							{
								Slots.Slot slotInGrid5 = Slots.GetSlotInGrid(new Vector2i(__instance.m_selected.x + 1, __instance.m_selected.y));
								if (slotInGrid5 != null && slotInGrid5.IsActive)
								{
									__instance.m_selected = slotInGrid5.GridPosition;
								}
							}
							else if (slotInGrid.IsQuickSlot)
							{
								if (__instance.m_selected.x < quickSlotsCount - 1)
								{
									Slots.Slot slotInGrid6 = Slots.GetSlotInGrid(new Vector2i(__instance.m_selected.x + 1, __instance.m_selected.y));
									if (slotInGrid6 != null && slotInGrid6.IsActive)
									{
										__instance.m_selected = slotInGrid6.GridPosition;
									}
								}
								else
								{
									IEnumerable<Slots.Slot> source2 = from slot in Slots.GetMiscSlots()
										where slot.IsActive
										select slot;
									if (source2.Any())
									{
										__instance.m_selected = source2.First().GridPosition;
									}
								}
							}
							else
							{
								__instance.m_selected = FindEquipmentSlot(-1, slotInGrid, -1, null, right: false, null, slotInGrid);
								if (__instance.m_selected.x < 0)
								{
									Slots.Slot[] array = (from slot in Slots.GetFoodSlots()
										where slot.IsActive
										select slot).ToArray();
									if (array.Length == 3)
									{
										__instance.m_selected = array[Array.IndexOf(Slots.GetEquipmentSlots(), slotInGrid) % 3].GridPosition;
										return false;
									}
									Slots.Slot[] array2 = (from slot in Slots.GetAmmoSlots()
										where slot.IsActive
										select slot).ToArray();
									if (array2.Length == 3)
									{
										__instance.m_selected = array2[Array.IndexOf(Slots.GetEquipmentSlots(), slotInGrid) % 3].GridPosition;
										return false;
									}
								}
								if (__instance.m_selected.x < 0)
								{
									__instance.m_selected = slotInGrid.GridPosition;
								}
							}
						}
						return false;
					}
					if (__instance.m_selected.x >= Slots.InventoryWidth - 1)
					{
						if (__instance.m_selected.y > 2)
						{
							IEnumerable<Slots.Slot> source3 = from slot in Slots.GetQuickSlots()
								where slot.IsActive
								select slot;
							if (source3.Any())
							{
								__instance.m_selected = source3.First().GridPosition;
								return false;
							}
							IEnumerable<Slots.Slot> source4 = from slot in Slots.GetMiscSlots()
								where slot.IsActive
								select slot;
							if (source4.Any())
							{
								__instance.m_selected = source4.First().GridPosition;
								return false;
							}
							__instance.m_selected = new Vector2i(0, Slots.InventoryHeightPlayer);
						}
						else
						{
							Vector2i val = FindEquipmentSlot(Math.Min(__instance.m_selected.y, equipmentSlotsCount - 1));
							if (val != Slots.emptyPosition)
							{
								__instance.m_selected = val;
							}
						}
						return false;
					}
				}
				if (ZInput.GetButtonDown("JoyDPadUp") || ZInput.GetButtonDown("JoyLStickUp"))
				{
					ExtraSlots.LogDebug($"From {__instance.m_selected} {slotInGrid} up");
					if (slotInGrid != null)
					{
						if (slotInGrid.IsFoodSlot)
						{
							__instance.m_selected.x--;
							if (__instance.m_selected.x < 3)
							{
								__instance.m_selected = slotInGrid.GridPosition;
							}
						}
						else if (slotInGrid.IsAmmoSlot)
						{
							__instance.m_selected.x--;
							if (__instance.m_selected.x < 0)
							{
								__instance.m_selected = slotInGrid.GridPosition;
							}
						}
						else if (slotInGrid.IsMiscSlot)
						{
							if (slotInGrid.Index == 6)
							{
								Slots.Slot slot2 = Slots.GetFoodSlots().Last();
								__instance.m_selected = ((slot2 != null && slot2.IsActive) ? slot2 : Slots.GetAmmoSlots().Last()).GridPosition;
							}
							else if (slotInGrid.Index == 7)
							{
								__instance.m_selected = Slots.GetAmmoSlots().Last().GridPosition;
							}
							Slots.Slot slotInGrid7 = Slots.GetSlotInGrid(__instance.m_selected);
							if (slotInGrid7 == null || !slotInGrid7.IsActive)
							{
								__instance.m_selected = slotInGrid.GridPosition;
							}
						}
						else if (slotInGrid.IsQuickSlot)
						{
							__instance.m_selected = FindEquipmentSlot(-1, null, Math.Min(__instance.m_selected.x, equipmentSlotsCount / 3), null, right: true);
							if (__instance.m_selected.x < 0)
							{
								__instance.m_selected = FindEquipmentSlot(-1, null, -1, null, right: true);
							}
							if (__instance.m_selected.x < 0)
							{
								__instance.m_selected = slotInGrid.GridPosition;
							}
						}
						else
						{
							__instance.m_selected = FindEquipmentSlot(-1, null, Array.IndexOf(Slots.GetEquipmentSlots(), slotInGrid) / 3, null, right: true, slotInGrid);
							if (__instance.m_selected.x < 0)
							{
								__instance.m_selected = slotInGrid.GridPosition;
							}
						}
						return false;
					}
				}
				if (ZInput.GetButtonDown("JoyDPadDown") || ZInput.GetButtonDown("JoyLStickDown"))
				{
					ExtraSlots.LogDebug($"From {__instance.m_selected} {slotInGrid} down");
					if (slotInGrid != null)
					{
						if (slotInGrid.IsQuickSlot || slotInGrid.IsMiscSlot)
						{
							if (!__instance.jumpToNextContainer)
							{
								return false;
							}
							__instance.OnMoveToLowerInventoryGrid?.Invoke(__instance.m_selected);
							return false;
						}
						if (slotInGrid.IsAmmoSlot)
						{
							__instance.m_selected.x++;
							if (__instance.m_selected.x > 2)
							{
								Slots.Slot slot3 = Slots.GetMiscSlots()[1];
								__instance.m_selected = ((slot3 != null && slot3.IsActive) ? slot3 : Slots.GetMiscSlots()[0]).GridPosition;
							}
						}
						else if (slotInGrid.IsFoodSlot)
						{
							__instance.m_selected.x++;
							if (__instance.m_selected.x > 5)
							{
								__instance.m_selected = Slots.GetMiscSlots()[0].GridPosition;
							}
						}
						else if (slotInGrid.IsEquipmentSlot)
						{
							int num3 = Array.IndexOf(Slots.GetEquipmentSlots(), slotInGrid) / 3;
							__instance.m_selected = FindEquipmentSlot(-1, null, num3, null, right: false, null, slotInGrid);
							if (__instance.m_selected.x < 0)
							{
								__instance.m_selected = Slots.GetQuickSlots()[num3].GridPosition;
							}
						}
						Slots.Slot slotInGrid8 = Slots.GetSlotInGrid(__instance.m_selected);
						if (slotInGrid8 == null || !slotInGrid8.IsActive)
						{
							if (!__instance.jumpToNextContainer)
							{
								return false;
							}
							__instance.OnMoveToLowerInventoryGrid?.Invoke(__instance.m_selected);
						}
						return false;
					}
					if (__instance.m_selected.y >= Slots.InventoryHeightPlayer - 1)
					{
						__instance.OnMoveToLowerInventoryGrid?.Invoke(__instance.m_selected);
						return false;
					}
				}
				return true;
			}

			private static void Postfix(InventoryGrid __instance, bool __runOriginal)
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				if (!__runOriginal)
				{
					ExtraSlots.LogDebug($"Selected {__instance.m_selected}");
				}
			}
		}

		[HarmonyPatch(typeof(InventoryGrid), "SetSelection")]
		public static class InventoryGrid_SetSelection_GamepadSupport
		{
			private static void Postfix(Vector2i pos)
			{
				//IL_0003: 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)
				pos.y = Math.Min(pos.y, Slots.InventoryHeightPlayer - 1);
				ExtraSlots.LogDebug($"SetSelection {pos}");
			}
		}

		private const string BackgroundName = "ExtraSlotsEquipmentPanel";

		private const float tileSpace = 6f;

		private const float tileSize = 70f;

		private const float interslotSpaceInTiles = 0.25f;

		private static int equipmentSlotsCount = 0;

		internal static int quickSlotsCount = 0;

		public static RectTransform inventoryDarken = null;

		public static RectTransform inventoryBackground = null;

		public static Image inventoryBackgroundImage = null;

		public static RectTransform equipmentBackground = null;

		public static Image equipmentBackgroundImage = null;

		public static RectTransform selectedFrame = null;

		public static RectTransform inventorySelectedFrame = null;

		private static bool isDirty = true;

		private static Color normalColor = Color.clear;

		private static Color highlightedColor = Color.clear;

		private static Color normalColorUnfit = Color.clear;

		private static Color highlightedColorUnfit = Color.clear;

		private static Material iconMaterial;

		private static Vector3 originalScale = Vector3.zero;

		private static Vector2 originalTooltipPosition = Vector2.zero;

		internal static Sprite ammoSlot;

		internal static Sprite miscSlot;

		internal static Sprite quickSlot;

		internal static Sprite background;

		private static float InventoryPanelWidth
		{
			get
			{
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				float result;
				if (!Object.op_Implicit((Object)(object)InventoryGui.instance))
				{
					result = 0f;
				}
				else
				{
					Rect rect = InventoryGui.instance.m_player.rect;
					result = ((Rect)(ref rect)).width;
				}
				return result;
			}
		}

		private static float PanelWidth => ((float)Math.Max(quickSlotsCount, SlotPositions.LastEquipmentColumn() + 1) + FoodAmmoSlotsWidthInTiles) * 70f + 3f;

		private static float PanelHeight => (((quickSlotsCount > 0 || Slots.IsFirstMiscSlotAvailable()) ? 1.25f : 0f) + (float)EquipmentHeight) * 70f + 3f;

		private static Vector2 PanelOffset => new Vector2(ExtraSlots.equipmentPanelOffset.Value.x, 0f - ExtraSlots.equipmentPanelOffset.Value.y);

		private static Vector2 PanelPosition => new Vector2(InventoryPanelWidth + 100f, 0f) + PanelOffset;

		private static float FoodAmmoSlotsWidthInTiles => ((Slots.IsFoodSlotAvailable() || Slots.IsAmmoSlotAvailable()) ? 0.25f : 0f) + (Slots.IsFoodSlotAvailable() ? 1f : 0f) + (Slots.IsAmmoSlotAvailable() ? 1f : 0f);

		private static int EquipmentHeight => (equipmentSlotsCount > 3 || Slots.IsFoodSlotAvailable() || Slots.IsAmmoSlotAvailable()) ? 3 : equipmentSlotsCount;

		public static void MarkDirty()
		{
			isDirty = true;
		}

		internal static void UpdateSlotsCount()
		{
			equipmentSlotsCount = Slots.GetEquipmentSlotsCount();
			quickSlotsCount = Slots.GetQuickSlotsCount();
		}

		internal static void ReorderVanillaSlots()
		{
			string[] newSlotsOrder = (from str in ExtraSlots.vanillaSlotsOrder.Value.Split(new char[1] { ',' })
				select str.Trim()).Distinct().ToArray();
			Slots.Slot[] array = Slots.slots.Where((Slots.Slot slot) => slot?.IsVanillaEquipment() ?? false).ToArray();
			int i;
			for (i = 0; i < Mathf.Min(newSlotsOrder.Length, array.Length); i++)
			{
				int num = Array.FindIndex(Slots.slots, (Slots.Slot slot) => slot.ID == newSlotsOrder[i]);
				if (num >= 0)
				{
					int num2 = Array.IndexOf(Slots.slots, array[i]);
					if (num2 >= 0)
					{
						Slots.SwapSlots(num, num2);
					}
				}
			}
			SetSlotsPositions();
		}

		internal static void UpdatePanel()
		{
			UpdateSlotsCount();
			UpdateBackground();
			SetSlotsPositions();
			MarkDirty();
		}

		internal static void UpdateInventorySlots()
		{
			//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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			if (originalScale == Vector3.zero && InventoryGui.instance.m_playerGrid.m_elements.Count > 0 && (Object)(object)((Graphic)InventoryGui.instance.m_playerGrid.m_elements[0].m_icon).material != (Object)null && ((Component)InventoryGui.instance.m_playerGrid.m_elements[0].m_icon).transform.localScale != Vector3.one)
			{
				originalScale = ((Component)InventoryGui.instance.m_playerGrid.m_elements[0].m_icon).transform.localScale;
			}
			int inventorySizePlayer = Slots.InventorySizePlayer;
			for (int i = 0; i < Math.Min(Slots.slots.Length, InventoryGui.instance.m_playerGrid.m_elements.Count - inventorySizePlayer); i++)
			{
				SetSlotBackgroundImage(InventoryGui.instance.m_playerGrid.m_elements[inventorySizePlayer + i], Slots.slots[i]);
			}
			if (!isDirty || Slots.PlayerInventory == null || !Object.op_Implicit((Object)(object)InventoryGui.instance.m_playerGrid))
			{
				return;
			}
			for (int j = 0; j < Math.Min(Slots.slots.Length, InventoryGui.instance.m_playerGrid.m_elements.Count - inventorySizePlayer); j++)
			{
				SetSlotElement(InventoryGui.instance.m_playerGrid.m_elements[inventorySizePlayer + j], Slots.slots[j]);
			}
			for (int k = inventorySizePlayer + Slots.slots.Length; k < InventoryGui.instance.m_playerGrid.m_elements.Count; k++)
			{
				Element obj = InventoryGui.instance.m_playerGrid.m_elements[k];
				if (obj != null)
				{
					GameObject go = obj.m_go;
					if (go != null)
					{
						go.SetActive(false);
					}
				}
			}
			if (originalTooltipPosition == Vector2.zero)
			{
				originalTooltipPosition = InventoryGui.instance.m_playerGrid.m_tooltipAnchor.anchoredPosition;
			}
			if (ExtraSlots.equipmentPanelTooltipOffset.Value == Vector2.zero)
			{
				InventoryGui.instance.m_playerGrid.m_tooltipAnchor.anchoredPosition = originalTooltipPosition - new Vector2(0f, PanelHeight + 21f);
			}
			else
			{
				InventoryGui.instance.m_playerGrid.m_tooltipAnchor.anchoredPosition = originalTooltipPosition + new Vector2(ExtraSlots.equipmentPanelTooltipOffset.Value.x, 0f - ExtraSlots.equipmentPanelTooltipOffset.Value.y);
			}
			isDirty = false;
		}

		public static void UpdateBackground()
		{
			//IL_0026: 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_0052: 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_006c: 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_007b: 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_0095: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)equipmentBackground))
			{
				equipmentBackground.sizeDelta = new Vector2(PanelWidth, PanelHeight);
				equipmentBackground.anchoredPosition = PanelPosition + new Vector2(PanelWidth / 2f, (0f - PanelHeight) / 2f);
				selectedFrame.sizeDelta = equipmentBackground.sizeDelta + Vector2.one * 26f;
				selectedFrame.anchoredPosition = equipmentBackground.anchoredPosition;
			}
		}

		internal static void SetSlotElement(Element element, Slots.Slot slot)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = element?.m_go;
			if (Object.op_Implicit((Object)(object)val))
			{
				val.gameObject.SetActive(slot.IsActive);
				val.GetComponent<RectTransform>().anchoredPosition = slot.Position;
				SetSlotLabel(val.transform.Find("binding"), slot);
				SetSlotColor(val.GetComponent<Button>(), slot);
			}
		}

		internal static void SetSlotLabel(Transform binding, Slots.Slot slot, bool hotbarElement = false)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: 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_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)binding) && slot.IsActive)
			{
				RectTransform component = ((Component)binding).GetComponent<RectTransform>();
				component.anchorMin = Vector2.zero;
				component.anchorMax = Vector2.one;
				component.offsetMin = Vector2.zero;
				component.offsetMax = Vector2.zero;
				component.sizeDelta = Vector2.zero;
				component.anchoredPosition = Vector2.zero;
				TMP_Text component2 = ((Component)binding).GetComponent<TMP_Text>();
				component2.enableAutoSizing = true;
				component2.text = (hotbarElement ? slot.GetShortcutText() : slot.Name);
				((Behaviour)component2).enabled = true;
				component2.overflowMode = (TextOverflowModes)0;
				component2.fontSizeMin = ((!slot.IsHotkeySlot) ? ExtraSlots.equipmentSlotLabelFontSize.Value.x : (slot.IsAmmoSlot ? ExtraSlots.ammoSlotLabelFontSize.Value.x : ExtraSlots.quickSlotLabelFontSize.Value.x));
				component2.fontSizeMax = ((!slot.IsHotkeySlot) ? ExtraSlots.equipmentSlotLabelFontSize.Value.y : (slot.IsAmmoSlot ? ExtraSlots.ammoSlotLabelFontSize.Value.y : ExtraSlots.quickSlotLabelFontSize.Value.y));
				((Graphic)component2).color = ((!slot.IsHotkeySlot) ? ExtraSlots.equipmentSlotLabelFontColor.Value : (slot.IsAmmoSlot ? ExtraSlots.ammoSlotLabelFontColor.Value : ExtraSlots.quickSlotLabelFontColor.Value));
				component2.margin = ((!slot.IsHotkeySlot) ? ExtraSlots.equipmentSlotLabelMargin.Value : (slot.IsAmmoSlot ? ExtraSlots.ammoSlotLabelMargin.Value : ExtraSlots.quickSlotLabelMargin.Value));
				component2.textWrappingMode = ((!slot.IsHotkeySlot) ? ExtraSlots.equipmentSlotLabelWrappingMode.Value : (slot.IsAmmoSlot ? ExtraSlots.ammoSlotLabelWrappingMode.Value : ExtraSlots.quickSlotLabelWrappingMode.Value));
				component2.horizontalAlignment = ((!slot.IsHotkeySlot) ? ExtraSlots.equipmentSlotLabelAlignment.Value : (slot.IsAmmoSlot ? ExtraSlots.ammoSlotLabelAlignment.Value : ExtraSlots.quickSlotLabelAlignment.Value));
				component2.verticalAlignment = (VerticalAlignmentOptions)256;
			}
		}

		internal static void SetSlotColor(Button button, Slots.Slot slot)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_00bc: 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_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: 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_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)button) && slot.IsActive && !((Object)(object)InventoryGui.instance == (Object)null))
			{
				ColorBlock colors;
				if (normalColor == Color.clear)
				{
					colors = ((Selectable)button).colors;
					normalColor = ((ColorBlock)(ref colors)).normalColor;
				}
				if (highlightedColor == Color.clear)
				{
					colors = ((Selectable)button).colors;
					highlightedColor = ((ColorBlock)(ref colors)).highlightedColor;
				}
				if (normalColorUnfit == Color.clear)
				{
					colors = ((Selectable)button).colors;
					normalColorUnfit = ((ColorBlock)(ref colors)).normalColor + new Color(0.3f, 0f, 0f, 0.1f);
				}
				if (highlightedColorUnfit == Color.clear)
				{
					colors = ((Selectable)button).colors;
					highlightedColorUnfit = ((ColorBlock)(ref colors)).highlightedColor + new Color(0.3f, 0f, 0f, 0.1f);
				}
				ColorBlock colors2 = ((Selectable)button).colors;
				((ColorBlock)(ref colors2)).normalColor = ((InventoryGui.instance.m_dragItem != null && !slot.ItemFits(InventoryGui.instance.m_dragItem)) ? normalColorUnfit : normalColor);
				((ColorBlock)(ref colors2)).highlightedColor = ((InventoryGui.instance.m_dragItem != null && !slot.ItemFits(InventoryGui.instance.m_dragItem)) ? highlightedColorUnfit : highlightedColor);
				((Selectable)button).colors = colors2;
			}
		}

		private static void SetSlotBackgroundImage(Element element, Slots.Slot slot)
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0304: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_032e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0416: Unknown result type (might be due to invalid IL or missing references)
			//IL_041b: Unknown result type (might be due to invalid IL or missing references)
			//IL_037f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0385: Unknown result type (might be due to invalid IL or missing references)
			//IL_0499: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0457: Unknown result type (might be due to invalid IL or missing references)
			//IL_045d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f9: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)iconMaterial == (Object)null && (Object)(object)((Graphic)element.m_icon).material != (Object)null)
			{
				iconMaterial = ((Graphic)element.m_icon).material;
			}
			if ((Object)(object)((Graphic)element.m_icon).material == (Object)null)
			{
				((Graphic)element.m_icon).material = iconMaterial;
			}
			bool isFree = slot.IsFree;
			if (!isFree)
			{
				ItemData item = slot.Item;
				element.m_tooltip.Set(item.m_shared.m_name, item.GetTooltip(-1), InventoryGui.instance.m_playerGrid.m_tooltipAnchor, default(Vector2));
				((Component)element.m_icon).transform.localScale = ((originalScale == Vector3.zero) ? Vector3.one : originalScale);
				if (!ExtraSlots.isEpicLootEnabled || ExtraSlots.epicLootMagicItemUnequippedAlpha.Value == 1f || item.m_equipped)
				{
					return;
				}
				Transform val = element.m_go.transform.Find("magicItem");
				if (val != null)
				{
					Image component = ((Component)val).GetComponent<Image>();
					if (component != null)
					{
						((Graphic)component).color = new Color(((Graphic)component).color.r, ((Graphic)component).color.g, ((Graphic)component).color.b, ExtraSlots.epicLootMagicItemUnequippedAlpha.Value);
					}
				}
			}
			else if (slot.IsEquipmentSlot)
			{
				if (ExtraSlots.equipmentSlotsShowTooltip.Value)
				{
					element.m_tooltip.Set("$exsl_slot_equipment", "$exsl_slot_equipment_desc", InventoryGui.instance.m_playerGrid.m_tooltipAnchor, default(Vector2));
				}
			}
			else if (slot.IsAmmoSlot)
			{
				((Behaviour)element.m_icon).enabled = ExtraSlots.ammoSlotsShowHintImage.Value;
				((Graphic)element.m_icon).material = null;
				element.m_icon.sprite = ammoSlot;
				((Component)element.m_icon).transform.localScale = Vector3.one * 0.8f;
				((Graphic)element.m_icon).color = Color.grey - new Color(0f, 0f, 0f, 0.1f);
				if (ExtraSlots.ammoSlotsShowTooltip.Value)
				{
					element.m_tooltip.Set("$exsl_slot_ammo (" + slot.GetShortcutText() + ")", "$exsl_slot_ammo_desc", InventoryGui.instance.m_playerGrid.m_tooltipAnchor, default(Vector2));
				}
			}
			else if (slot.IsQuickSlot)
			{
				((Behaviour)element.m_icon).enabled = ExtraSlots.quickSlotsShowHintImage.Value;
				((Graphic)element.m_icon).material = null;
				element.m_icon.sprite = quickSlot;
				((Component)element.m_icon).transform.localScale = Vector3.one * 0.6f;
				((Graphic)element.m_icon).color = Color.grey - new Color(0f, 0f, 0f, 0.6f);
				if (ExtraSlots.quickSlotsShowTooltip.Value)
				{
					element.m_tooltip.Set("$exsl_slot_quick (" + slot.GetShortcutText() + ")", "$exsl_slot_quick_desc", InventoryGui.instance.m_playerGrid.m_tooltipAnchor, default(Vector2));
				}
			}
			else if (slot.IsMiscSlot)
			{
				((Behaviour)element.m_icon).enabled = ExtraSlots.miscSlotsShowHintImage.Value;
				((Graphic)element.m_icon).material = null;
				element.m_icon.sprite = miscSlot;
				((Component)element.m_icon).transform.localScale = Vector3.one * 0.8f;
				((Graphic)element.m_icon).color = Color.grey - new Color(0f, 0f, 0f, 0.75f);
				if (ExtraSlots.miscSlotsShowTooltip.Value)
				{
					element.m_tooltip.Set("$exsl_slot_misc", "$exsl_slot_misc_desc", InventoryGui.instance.m_playerGrid.m_tooltipAnchor, default(Vector2));
				}
			}
			else if (slot.IsFoodSlot && isFree)
			{
				((Behaviour)element.m_food).enabled = ExtraSlots.foodSlotsShowHintImage.Value;
				((Graphic)element.m_food).color = Color.grey - new Color(0f, 0f, 0f, 0.5f);
				if (ExtraSlots.foodSlotsShowTooltip.Value)
				{
					element.m_tooltip.Set("$exsl_slot_food", "$exsl_slot_food_desc", InventoryGui.instance.m_playerGrid.m_tooltipAnchor, default(Vector2));
				}
			}
		}

		internal static void SetSlotsPositions()
		{
			SetPosition(Slots.GetEquipmentSlots(), SlotPositions.GetEquipmentTileOffset);
			SetPosition(Slots.GetQuickSlots(), SlotPositions.GetQuickSlotTileOffset);
			SetPosition(Slots.GetFoodSlots(), SlotPositions.GetFoodSlotTileOffset);
			SetPosition(Slots.GetAmmoSlots(), SlotPositions.GetAmmoSlotTileOffset);
			SetPosition(Slots.GetMiscSlots(), SlotPositions.GetMiscSlotTileOffset);
			static void SetPosition(Slots.Slot[] collection, Func<int, Vector2> offsetFunc)
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				for (int i = 0; i < collection.Length; i++)
				{
					collection[i].SetPosition(offsetFunc(i));
				}
			}
		}

		internal static void UpdateEquipmentBackground()
		{
			//IL_0395: Unknown result type (might be due to invalid IL or missing references)
			//IL_03aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: 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_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: 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)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)InventoryGui.instance))
			{
				return;
			}
			if (inventoryBackground == null)
			{
				inventoryBackground = ((Component)((Transform)InventoryGui.instance.m_player).Find("Bkg")).GetComponent<RectTransform>();
			}
			if (!Object.op_Implicit((Object)(object)inventoryBackground))
			{
				return;
			}
			if (!Object.op_Implicit((Object)(object)equipmentBackground))
			{
				UIGroupHandler component = ((Component)InventoryGui.instance.m_player).GetComponent<UIGroupHandler>();
				Transform val = ((component != null) ? component.m_enableWhenActiveAndGamepad.transform : null);
				inventoryDarken = ((Component)((Transform)InventoryGui.instance.m_player).Find("Darken")).GetComponent<RectTransform>();
				equipmentBackground = new GameObject("ExtraSlotsEquipmentPanel", new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>();
				((Component)equipmentBackground).gameObject.layer = ((Component)inventoryBackground).gameObject.layer;
				((Transform)equipmentBackground).SetParent((Transform)(object)InventoryGui.instance.m_player, false);
				((Transform)equipmentBackground).SetSiblingIndex(1 + (((Object)(object)val == (Object)null) ? ((Transform)inventoryDarken).GetSiblingIndex() : val.GetSiblingIndex()));
				equipmentBackground.offsetMin = Vector2.zero;
				equipmentBackground.offsetMax = Vector2.zero;
				equipmentBackground.sizeDelta = Vector2.zero;
				equipmentBackground.anchoredPosition = Vector2.zero;
				equipmentBackground.anchorMin = new Vector2(0f, 1f);
				equipmentBackground.anchorMax = new Vector2(0f, 1f);
				RectTransform val2 = Object.Instantiate<RectTransform>(inventoryDarken, (Transform)(object)equipmentBackground);
				((Object)val2).name = "Darken";
				val2.sizeDelta = Vector2.one * 70f;
				Transform val3 = Object.Instantiate<Transform>(((Component)inventoryBackground).transform, (Transform)(object)equipmentBackground);
				((Object)val3).name = "Bkg";
				equipmentBackgroundImage = ((Component)val3).GetComponent<Image>();
				inventoryBackgroundImage = ((Component)((Component)inventoryBackground).transform).GetComponent<Image>();
				Transform child = val.GetChild(0);
				inventorySelectedFrame = (RectTransform)(object)((child is RectTransform) ? child : null);
				selectedFrame = Object.Instantiate<RectTransform>(inventorySelectedFrame, val);
				((Object)selectedFrame).name = "selected (ExtraSlots)";
				selectedFrame.offsetMin = equipmentBackground.offsetMin;
				selectedFrame.offsetMax = equipmentBackground.offsetMax;
				selectedFrame.sizeDelta = equipmentBackground.sizeDelta;
				selectedFrame.anchoredPosition = equipmentBackground.anchoredPosition;
				selectedFrame.anchorMin = equipmentBackground.anchorMin;
				selectedFrame.anchorMax = equipmentBackground.anchorMax;
				UpdateBackground();
			}
			if (Object.op_Implicit((Object)(object)equipmentBackgroundImage))
			{
				if (Object.op_Implicit((Object)(object)inventoryBackgroundImage))
				{
					equipmentBackgroundImage.sprite = inventoryBackgroundImage.sprite;
					equipmentBackgroundImage.overrideSprite = inventoryBackgroundImage.overrideSprite;
					((Graphic)equipmentBackgroundImage).color = ((Graphic)inventoryBackgroundImage).color;
				}
				if (Object.op_Implicit((Object)(object)background))
				{
					equipmentBackgroundImage.sprite = background;
					equipmentBackgroundImage.overrideSprite = background;
				}
			}
			inventoryBackground.anchorMin = new Vector2(0f, -1f * ((float)Slots.ExtraRowsPlayer / 4f - 0.01f * (float)Math.Max(Slots.ExtraRowsPlayer - 1, 0)));
			inventorySelectedFrame.anchorMin = inventoryBackground.anchorMin;
			if (ExtraSlots.fixContainerPosition.Value)
			{
				InventoryGui.instance.m_container.pivot = new Vector2(0f, 1f + (float)Slots.ExtraRowsPlayer * 0.2f);
			}
		}

		internal static void ClearPanel()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//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_0049: 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_0059: 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)
			inventoryDarken = null;
			inventoryBackground = null;
			equipmentBackground = null;
			equipmentBackgroundImage = null;
			inventoryBackgroundImage = null;
			selectedFrame = null;
			inventorySelectedFrame = null;
			normalColor = Color.clear;
			highlightedColor = Color.clear;
			normalColorUnfit = Color.clear;
			highlightedColorUnfit = Color.clear;
			iconMaterial = null;
			originalScale = Vector3.zero;
		}
	}
	internal class InventoryInteraction
	{
		[HarmonyPatch(typeof(Player), "Awake")]
		private static class Player_Awake_ExcludeRedundantSlots
		{
			private static void Postfix(Player __instance)
			{
				((Humanoid)__instance).m_inventory.m_height = Slots.InventoryHeightFull;
			}
		}

		[HarmonyPatch(typeof(Player), "OnSpawned")]
		private static class Player_OnSpawned_UpdateInventoryOnSpawn
		{
			private static void Postfix(Player __instance)
			{
				if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
				{
					UpdatePlayerInventorySize();
				}
			}
		}

		[HarmonyPatch(typeof(Player), "Update")]
		private static class Player_Update_UpdateInventoryHeight
		{
			private static Container tombstoneContainer;

			private static void Postfix(Player __instance)
			{
				((Humanoid)__instance).m_inventory.m_height = Slots.InventoryHeightFull;
				if (tombstoneContainer == null)
				{
					tombstoneContainer = __instance.m_tombstone.GetComponent<Container>();
				}
				if ((Object)(object)tombstoneContainer != (Object)null)
				{
					tombstoneContainer.m_height = ((Humanoid)__instance).m_inventory.m_height;
				}
			}
		}

		[HarmonyPatch(typeof(Player), "Save")]
		private static class Player_Save_SaveLastEquippedSlots
		{
			private static void Prefix(Player __instance)
			{
				if (((Humanoid)__instance).GetInventory() == Slots.PlayerInventory)
				{
					Slots.SaveLastEquippedSlotsToItems();
				}
			}
		}

		[HarmonyPatch(typeof(Inventory), "SlotsUsedPercentage")]
		private static class Inventory_SlotsUsedPercentage_ExcludeRedundantSlots
		{
			private static void Postfix(Inventory __instance, ref float __result)
			{
				if (__instance == Slots.PlayerInventory)
				{
					__result = (float)__instance.m_inventory.Count / (float)Slots.InventorySizeActive * 100f;
					ExtraSlots.LogDebug($"Inventory.SlotsUsedPercentage: {__result}");
				}
			}
		}

		[HarmonyPatch(typeof(Inventory), "GetEmptySlots")]
		private static class Inventory_GetEmptySlots_CheckRegularInventoryAndQuickSlots
		{
			[HarmonyPriority(800)]
			private static void Postfix(Inventory __instance, ref int __result)
			{
				if (__instance == Slots.PlayerInventory)
				{
					__result = Slots.InventoryHeightPlayer * __instance.m_width - __instance.m_inventory.Count((ItemData item) => !API.IsItemInSlot(item)) + Slots.GetEmptyQuickSlots();
					ExtraSlots.LogDebug($"Inventory.GetEmptySlots: {__result}");
				}
			}
		}

		[HarmonyPatch(typeof(Inventory), "FindEmptySlot")]
		private static class Inventory_FindEmptySlot_FindAppropriateSlot
		{
			[HarmonyPriority(800)]
			private static void Prefix(Inventory __instance)
			{
				if (__instance == Slots.PlayerInventory)
				{
					__instance.m_height = Slots.InventoryHeightPlayer;
				}
			}

			[HarmonyPriority(800)]
			private static void Postfix(Inventory __instance, ref Vector2i __result)
			{
				//IL_0023: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_006c: 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_0087: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
				//IL_0102: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
				//IL_015c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0161: Unknown result type (might be due to invalid IL or missing references)
				//IL_0126: 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_0145: Unknown result type (might be due to invalid IL or missing references)
				//IL_019a: Unknown result type (might be due to invalid IL or missing references)
				//IL_019f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0173: Unknown result type (might be due to invalid IL or missing references)
				//IL_0178: Unknown result type (might be due to invalid IL or missing references)
				//IL_0183: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
				if (__instance != Slots.PlayerInventory)
				{
					return;
				}
				__instance.m_height = Slots.InventoryHeightFull;
				if (__result == Slots.emptyPosition && InventoryGui.instance.m_craftTimer >= InventoryGui.instance.m_craftDuration)
				{
					ItemData craftUpgradeItem = InventoryGui.instance.m_craftUpgradeItem;
					if (craftUpgradeItem != null && Slots.TryFindFreeSlotForItem(craftUpgradeItem, out var slot))
					{
						__result = slot.GridPosition;
						ExtraSlots.LogDebug($"Inventory.FindEmptySlot for upgraded item {craftUpgradeItem.m_shared.m_name} {__result}");
					}
				}
				if (__result == Slots.emptyPosition && Slots.TryFindFreeEquipmentSlotForItem(Inventory_AddItem_ByName_FindAppropriateSlot.itemToFindSlot, out var slot2))
				{
					__result = slot2.GridPosition;
					ExtraSlots.LogDebug($"Inventory.FindEmptySlot free equipment slot for AddItem_ByName item {Inventory_AddItem_ByName_FindAppropriateSlot.itemToFindSlot.m_shared.m_name} {__result}");
				}
				if (__result == Slots.emptyPosition && Slots.TryFindFreeSlotForItem(Inventory_AddItem_ByName_FindAppropriateSlot.itemToFindSlot, out var slot3))
				{
					__result = slot3.GridPosition;
					ExtraSlots.LogDebug($"Inventory.FindEmptySlot free slot for AddItem_ByName item {Inventory_AddItem_ByName_FindAppropriateSlot.itemToFindSlot.m_shared.m_name} {__result}");
				}
				if (__result == Slots.emptyPosition)
				{
					__result = Slots.FindEmptyQuickSlot();
					ExtraSlots.LogDebug($"Inventory.FindEmptySlot free quick slot {__result}");
				}
				if (__result == Slots.emptyPosition && Inventory_AddItem_ByName_FindAppropriateSlot.itemToFindSlot != null && Slots.TryMakeFreeSpaceInPlayerInventory(tryFindRegularInventorySlot: true, out var gridPos))
				{
					__result = gridPos;
					ExtraSlots.LogDebug($"Inventory.FindEmptySlot made free space for AddItem_ByName item {Inventory_AddItem_ByName_FindAppropriateSlot.itemToFindSlot.m_shared.m_name} {__result}");
				}
			}
		}

		[HarmonyPatch(typeof(Inventory), "HaveEmptySlot")]
		private static class Inventory_HaveEmptySlot_CheckRegularInventoryAndQuickSlots
		{
			[HarmonyPriority(800)]
			private static void Postfix(Inventory __instance, ref bool __result, bool __state)
			{
				if (__state)
				{
					__result = __instance.GetEmptySlots() > 0;
				}
			}
		}

		[HarmonyPatch(typeof(InventoryGui), "OnSelectedItem")]
		public static class InventoryGui_OnSelectedItem_GetEquippedDragItem
		{
			public static void Prefix(InventoryGui __instance)
			{
				Player localPlayer = Player.m_localPlayer;
				if (!((Character)localPlayer).IsTeleporting() && Object.op_Implicit((Object)(object)__instance.m_dragGo) && ((Humanoid)localPlayer).IsItemEquiped(__instance.m_dragItem))
				{
					InventoryGrid_DropItem_DropPrevention.equippedDragItem = __instance.m_dragItem;
				}
			}

			public static void Postfix()
			{
				InventoryGrid_DropItem_DropPrevention.equippedDragItem = null;
			}
		}

		[HarmonyPatch(typeof(InventoryGrid), "DropItem")]
		public static class InventoryGrid_DropItem_DropPrevention
		{
			public static ItemData equippedDragItem;

			public static bool Prefix(InventoryGrid __instance, Inventory fromInventory, ItemData item, Vector2i pos)
			{
				//IL_0019: 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_008e: 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_00b8: 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_010e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0161: Unknown result type (might be due to invalid IL or missing references)
				if (item == null)
				{
					return true;
				}
				ItemData itemAt = __instance.m_inventory.GetItemAt(pos.x, pos.y);
				if (itemAt == item)
				{
					return true;
				}
				if (__instance.m_inventory == Slots.PlayerInventory && item == equippedDragItem)
				{
					Slots.Slot itemSlot = Slots.GetItemSlot(item);
					if (itemSlot != null)
					{
						Slots.Slot slotInGrid = Slots.GetSlotInGrid(pos);
						if (slotInGrid == null || !Slots.IsSameSlotType(itemSlot, slotInGrid))
						{
							ExtraSlots.LogDebug($"InventoryGrid.DropItem Prevented dropping equipped item {item.m_shared.m_name} {item.m_gridPos} into slot with other type");
							return false;
						}
					}
				}
				if (__instance.m_inventory == Slots.PlayerInventory)
				{
					Slots.Slot slotInGrid2 = Slots.GetSlotInGrid(pos);
					if (slotInGrid2 != null && !slotInGrid2.ItemFits(item))
					{
						ExtraSlots.LogDebug($"InventoryGrid.DropItem Prevented dropping {item.m_shared.m_name} {item.m_gridPos} into unfit slot {slotInGrid2}");
						return false;
					}
				}
				if (itemAt != null && fromInventory == Slots.PlayerInventory)
				{
					Slots.Slot slotInGrid3 = Slots.GetSlotInGrid(item.m_gridPos);
					if (slotInGrid3 != null && !slotInGrid3.ItemFits(itemAt))
					{
						ExtraSlots.LogDebug($"InventoryGrid.DropItem Prevented swapping {item.m_shared.m_name} {slotInGrid3} with unfit item {itemAt.m_shared.m_name} {pos}");
						return false;
					}
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Inventory), "AddItem", new Type[]
		{
			typeof(ItemData),
			typeof(int),
			typeof(int),
			typeof(int)
		})]
		private static class Inventory_AddItem_ItemData_amount_x_y_TargetPositionRerouting
		{
			[HarmonyPriority(0)]
			private static void Prefix(Inventory __instance, ItemData item, ref int x, ref int y)
			{
				//IL_008b: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
				//IL_013b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0153: Unknown result type (might be due to invalid IL or missing references)
				//IL_0160: Unknown result type (might be due to invalid IL or missing references)
				//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
				//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
				if (__instance != Slots.PlayerInventory || item == null)
				{
					return;
				}
				ItemData itemAt = __instance.GetItemAt(x, y);
				if (itemAt != null)
				{
					ExtraSlots.LogDebug($"Inventory.AddItem X Y item {item.m_shared.m_name} adding at {x},{y} position is taken {itemAt.m_shared.m_name}");
					return;
				}
				Slots.Slot slotInGrid = Slots.GetSlotInGrid(new Vector2i(x, y));
				if (slotInGrid != null && !slotInGrid.ItemFits(item))
				{
					ExtraSlots.LogDebug($"Inventory.AddItem X Y item {item.m_shared.m_name} adding at {x},{y} unfits slot {slotInGrid} {slotInGrid.GridPosition}");
					if (Slots.TryFindFreeSlotForItem(item, out var slot))
					{
						ExtraSlots.LogDebug($"Inventory.AddItem X Y Rerouted {item.m_shared.m_name} from {x},{y} to free slot {slot} {slot.GridPosition}");
						x = slot.GridPosition.x;
						y = slot.GridPosition.y;
					}
					if (Slots.TryMakeFreeSpaceInPlayerInventory(tryFindRegularInventorySlot: true, out var gridPos))
					{
						ExtraSlots.LogDebug($"Inventory.AddItem X Y Rerouted {item.m_shared.m_name} from {x},{y} to created free space {gridPos}");
						x = gridPos.x;
						y = gridPos.y;
					}
				}
			}

			[HarmonyPriority(0)]
			private static void Postfix(Inventory __instance, ItemData item, int x, int y, int amount, ref bool __result)
			{
				//IL_008e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0093: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
				//IL_012c: 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_01bb: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
				//IL_0158: Unknown result type (might be due to invalid IL or missing references)
				//IL_015a: Unknown result type (might be due to invalid IL or missing references)
				//IL_018d: Unknown result type (might be due to invalid IL or missing references)
				if (__instance == Slots.PlayerInventory && Inventory_AddItem_OnLoad_FindAppropriateSlot.inCall && !__result)
				{
					amount = Mathf.Min(amount, item.m_stack);
					ItemData val = item.Clone();
					val.m_stack = amount;
					ExtraSlots.LogMessage($"Item dissappearing prevention at Inventory.AddItem_OnLoad -> Inventory.AddItem_ItemData_amount_x_y: item {item.m_shared.m_name} at {x},{y} amount {amount}");
					Slots.Slot slot2;
					Vector2i gridPos;
					if (Slots.TryFindFreeEquipmentSlotForItem(val, out var slot))
					{
						val.m_gridPos = slot.GridPosition;
						ExtraSlots.LogDebug($"Inventory.AddItem_ItemData_amount_x_y found free equipment slot for item {val.m_shared.m_name}. Position rerouted {x},{y} -> {val.m_gridPos}");
					}
					else if (Slots.TryFindFreeSlotForItem(val, out slot2))
					{
						val.m_gridPos = slot2.GridPosition;
						ExtraSlots.LogDebug($"Inventory.AddItem_ItemData_amount_x_y found free slot for item {val.m_shared.m_name}. Position rerouted {x},{y} -> {val.m_gridPos}");
					}
					else if (Slots.TryMakeFreeSpaceInPlayerInventory(tryFindRegularInventorySlot: true, out gridPos))
					{
						val.m_gridPos = gridPos;
						ExtraSlots.LogDebug($"Inventory.AddItem_ItemData_amount_x_y made free space for item {val.m_shared.m_name}. Position rerouted {x},{y} -> {val.m_gridPos}");
					}
					else
					{
						val.m_gridPos = new Vector2i(Slots.InventoryWidth - 1, Slots.InventoryHeightFull - 1);
						ExtraSlots.LogDebug($"Inventory.AddItem_ItemData_amount_x_y item {val.m_shared.m_name} put in the last slot to find place later. Position rerouted {x},{y} -> {val.m_gridPos}");
					}
					__instance.m_inventory.Add(val);
					item.m_stack -= amount;
					__result = true;
					__instance.Changed();
				}
			}
		}

		[HarmonyPatch(typeof(Inventory), "CanAddItem", new Type[]
		{
			typeof(ItemData),
			typeof(int)
		})]
		private static class Inventory_CanAddItem_ItemData_TryFindAppropriateExtraSlot
		{
			[HarmonyPriority(800)]
			private static void Prefix(Inventory __instance)
			{
				if (__instance == Slots.PlayerInventory)
				{
					__instance.m_height = Slots.InventoryHeightPlayer;
				}
			}

			[HarmonyPriority(800)]
			private static void Postfix(Inventory __instance, ItemData item, int stack, ref bool __result)
			{
				//IL_011d: Unknown result type (might be due to invalid IL or missing references)
				if (__instance != Slots.PlayerInventory)
				{
					return;
				}
				__instance.m_height = Slots.InventoryHeightFull;
				if (!__result)
				{
					int num = __instance.FindFreeStackSpace(item.m_shared.m_name, (float)item.m_worldLevel);
					int num2 = __instance.GetEmptySlots() * item.m_shared.m_maxStackSize;
					Slots.Slot slot;
					if (__result = num + num2 >= stack)
					{
						ExtraSlots.LogDebug($"Inventory.CanAddItem_ItemData_int item {item.m_shared.m_name} result {__result}, free stack space: {num}, free quick slot stack space: {num2}, have free stack space");
					}
					else if (stack <= item.m_shared.m_maxStackSize && (__result = Slots.TryFindFreeSlotForItem(item, out slot)))
					{
						ExtraSlots.LogDebug($"Inventory.CanAddItem_ItemData_int item {item.m_shared.m_name} result {__result}, free stack space: {num}, free quick slot stack space: {num2}, no free stack space, free single slot found {slot} {slot.GridPosition}");
					}
				}
			}
		}

		[HarmonyPatch(typeof(Inventory), "AddItem", new Type[] { typeof(ItemData) })]
		private static class Inventory_AddItem_ItemData_TryFindAppropriateExtraSlot
		{
			[HarmonyPriority(800)]
			private static void Postfix(Inventory __instance, ItemData item, ref bool __result)
			{
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0054: Unknown result type (might be due to invalid IL or missing references)
				//IL_0059: Unknown result type (might be due to invalid IL or missing references)
				if (__instance == Slots.PlayerInventory && !__result && Slots.TryFindFreeSlotForItem(item, out var slot))
				{
					ExtraSlots.LogDebug($"Inventory.AddItem_Item item {item.m_shared.m_name} found free slot {slot} {slot.GridPosition}");
					item.m_gridPos = slot.GridPosition;
					__instance.m_inventory.Add(item);
					__instance.Changed();
					__result = true;
				}
			}
		}

		[HarmonyPatch(typeof(Inventory), "AddItem", new Type[]
		{
			typeof(ItemData),
			typeof(Vector2i)
		})]
		private static class Inventory_AddItem_ItemData_pos_TargetPositionRerouting
		{
			[HarmonyPriority(800)]
			private static void Prefix(Inventory __instance, ItemData item, ref Vector2i pos)
			{
				//IL_004d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0173: Unknown result type (might be due to invalid IL or missing references)
				//IL_0185: Unknown result type (might be due to invalid IL or missing references)
				//IL_019d: 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_01ce: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
				//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
				//IL_011d: Unknown result type (might be due to invalid IL or missing references)
				if (__instance != Slots.PlayerInventory || item == null || __instance.GetItemAt(pos.x, pos.y) != null)
				{
					return;
				}
				Slots.Slot slotInGrid = Slots.GetSlotInGrid(pos);
				if (slotInGrid == null || slotInGrid.ItemFits(item))
				{
					return;
				}
				if (item.m_shared.m_maxStackSize > 1)
				{
					int num = (from itemInv in __instance.GetAllItems()
						where item.m_shared.m_name == itemInv.m_shared.m_name && item.m_quality == itemInv.m_quality && item.m_worldLevel == itemInv.m_worldLevel
						select itemInv).Sum((ItemData itemInv) => itemInv.m_shared.m_maxStackSize - itemInv.m_stack);
					if (num > item.m_stack)
					{
						return;
					}
					ExtraSlots.LogDebug($"Inventory.AddItem_Item_Vector2i item {item.m_shared.m_name}x{item.m_stack} adding at {pos} not enough free stack space {num}");
				}
				Vector2i gridPos;
				if (Slots.TryFindFreeSlotForItem(item, out var slot))
				{
					ExtraSlots.LogDebug($"Inventory.AddItem_Item_Vector2i Rerouted {item.m_shared.m_name} from {pos} to free slot {slot} {slot.GridPosition}");
					pos = slot.GridPosition;
				}
				else if (Slots.TryMakeFreeSpaceInPlayerInventory(tryFindRegularInventorySlot: true, out gridPos))
				{
					ExtraSlots.LogDebug($"Inventory.AddItem_Item_Vector2i Rerouted {item.m_shared.m_name} from {pos} to created free space {gridPos}");
					pos = gridPos;
				}
			}
		}

		[HarmonyPatch(typeof(Inventory), "AddItem", new Type[]
		{
			typeof(string),
			typeof(int),
			typeof(int),
			typeof(int),
			typeof(long),
			typeof(string),
			typeof(Vector2i),
			typeof(bool)
		})]
		public static class Inventory_AddItem_ByName_FindAppropriateSlot
		{
			public static ItemData itemToFindSlot;

			[HarmonyPriority(800)]
			private static void Prefix(Inventory __instance, string name)
			{
				if (__instance == Slots.PlayerInventory)
				{
					ObjectDB instance = ObjectDB.instance;
					object obj;
					if (instance == null)
					{
						obj = null;
					}
					else
					{
						GameObject itemPrefab = instance.GetItemPrefab(name);
						obj = ((itemPrefab != null) ? itemPrefab.GetComponent<ItemDrop>() : null);
					}
					ItemDrop val = (ItemDrop)obj;
					if (!((Object)(object)val == (Object)null) && val.m_itemData.m_shared.m_maxStackSize <= 1)
					{
						itemToFindSlot = val.m_itemData;
					}
				}
			}

			[HarmonyPriority(800)]
			private static void Postfix()
			{
				itemToFindSlot = null;
			}
		}

		[HarmonyPatch(typeof(Inventory), "AddItem", new Type[]
		{
			typeof(string),
			typeof(int),
			typeof(float),
			typeof(Vector2i),
			typeof(bool),
			typeof(int),
			typeof(int),
			typeof(long),
			typeof(string),
			typeof(Dictionary<string, string>),
			typeof(int),
			typeof(bool)
		})]
		public static class Inventory_AddItem_OnLoad_FindAppropriateSlot
		{
			public static bool inCall;

			[HarmonyPriority(800)]
			private static void Prefix()
			{
				inCall = true;
			}

			[HarmonyPriority(800)]
			private static void Postfix()
			{
				inCall = false;
			}
		}

		[HarmonyPatch(typeof(Inventory), "MoveInventoryToGrave")]
		private static class Inventory_MoveInventoryToGrave_UpdateGraveInventory
		{
			private static void Prefix(Inventory original)
			{
				if (original == Slots.PlayerInventory)
				{
					original.m_height = Slots.InventoryHeightFull;
				}
			}
		}

		public static void UpdatePlayerInventorySize()
		{
			if (!((Object)(object)Player.m_localPlayer == (Object)null))
			{
				if (((Humanoid)Player.m_localPlayer).m_inventory.m_height != Slots.InventoryHeightFull)
				{
					ExtraSlots.LogInfo($"Player inventory height changed {((Humanoid)Player.m_localPlayer).m_inventory.m_height} -> {Slots.InventoryHeightFull}");
				}
				((Humanoid)Player.m_localPlayer).m_inventory.m_height = Slots.InventoryHeightFull;
				Player.m_localPlayer.m_tombstone.GetComponent<Container>().m_height = Slots.InventoryHeightFull;
				((Humanoid)Player.m_localPlayer).m_inventory.Changed();
				ItemsSlotsValidation.ValidateItems();
			}
		}
	}
	public static class AmmoSlotsHotBar
	{
		[HarmonyPatch(typeof(Player), "Update")]
		private static class Player_Update_SlotsUse
		{
			private static void Postfix(Player __instance)
			{
				if (Slots.IsValidPlayer((Humanoid)(object)__instance))
				{
					UpdateItemUse();
				}
			}
		}

		[HarmonyPatch(typeof(Hud), "Update")]
		private static class Hud_Update_SlotsPosition
		{
			private static void Postfix()
			{
				UpdatePosition();
			}
		}

		public const string barName = "ExtraSlotsAmmoHotBar";

		public static bool isDirty = true;

		private static HotkeyBar hotBar = null;

		private static RectTransform hotBarRect = null;

		private static Slots.Slot[] hotBarSlots = Array.Empty<Slots.Slot>();

		internal static void UpdateSlots()
		{
			hotBarSlots = Slots.GetAmmoSlots();
		}

		public static void GetItems(List<ItemData> bound)
		{
			if (Slots.PlayerInventory != null)
			{
				bound.AddRange(GetItems());
			}
		}

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

		public static ItemData GetItemInSlot(int slotIndex)
		{
			return Slots.slots[slotIndex + 8].Item;
		}

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

		internal static void CreateBar()
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			hotBarRect = ((Component)Object.Instantiate<Transform>(Hud.instance.m_rootObject.transform.Find("HotKeyBar"), Hud.instance.m_rootObject.transform, true)).GetComponent<RectTransform>();
			((Object)hotBarRect).name = "ExtraSlotsAmmoHotBar";
			((Transform)hotBarRect).localPosition = Vector3.zero;
			if (!Object.op_Implicit((Object)(object)(hotBar = ((Component)hotBarRect).GetComponent<HotkeyBar>())))
			{
				return;
			}
			hotBar.m_selected = -1;
			foreach (ElementData element in hotBar.m_elements)
			{
				Object.Destroy((Object)(object)element.m_go);
			}
			for (int num = ((Transform)hotBarRect).childCount - 1; num >= 0; num--)
			{
				Object.Destroy((Object)(object)((Component)((Transform)hotBarRect).GetChild(num)).gameObject);
			}
			hotBar.m_elements.Clear();
			hotBar.m_items.Clear();
		}

		internal static bool Refresh()
		{
			if (!isDirty)
			{
				return false;
			}
			if (ExtraSlots.ammoSlotsHotBarEnabled.Value && (Object)(object)hotBarRect == (Object)null)
			{
				CreateBar();
			}
			else if (!ExtraSlots.ammoSlotsHotBarEnabled.Value && (Object)(object)hotBarRect != (Object)null)
			{
				ClearBar();
			}
			isDirty = false;
			return true;
		}

		internal static void ClearBar()
		{
			if ((Object)(object)hotBarRect != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)((Component)hotBarRect).gameObject);
			}
			hotBar = null;
			hotBarRect = null;
		}

		internal static void UpdateItemUse()
		{
			if (((Character)Player.m_localPlayer).TakeInput() && hotBarSlots.Length != 0)
			{
				CollectionExtensions.DoIf<Slots.Slot>((IEnumerable<Slots.Slot>)hotBarSlots, (Func<Slots.Slot, bool>)((Slots.Slot slot) => slot.IsShortcutDown()), (Action<Slots.Slot>)delegate(Slots.Slot slot)
				{
					((Humanoid)Player.m_localPlayer).UseItem(Slots.PlayerInventory, slot.Item, false);
				});
			}
		}

		internal static void UpdatePosition()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_0057: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)hotBar))
			{
				hotBarRect.anchoredPosition = new Vector2(ExtraSlots.ammoSlotsHotBarOffset.Value.x, 0f - ExtraSlots.ammoSlotsHotBarOffset.Value.y);
				((Transform)hotBarRect).localScale = Vector3.one * ExtraSlots.ammoSlotsHotBarScale.Value;
			}
		}
	}
	public static class PreventSimilarHotkeys
	{
		[HarmonyPatch(typeof(ZInput), "TryGetButtonState")]
		private static class ZInput_TryGetButtonState_PreventSimilarHotkeys
		{
			private static bool Prefix(string name)
			{
				Slots.Slot value;
				return !similarHotkey.TryGetValue(name, out value) || !value.IsShortcutDown() || !value.IsActive || value.IsFree;
			}
		}

		[HarmonyPatch]
		public static class ZInput_SimilarHotkeyOnBind
		{
			private static IEnumerable<MethodBase> TargetMethods()
			{
				yield return AccessTools.Method(typeof(ZInput), "ResetKBMButtons", (Type[])null, (Type[])null);
				yield return AccessTools.Method(typeof(ZInput), "ResetGamepadButtonsGeneric", (Type[])null, (Type[])null);
				yield return AccessTools.Method(typeof(ZInput), "ResetGamepadToClassic", (Type[])null, (Type[])null);
				yield return AccessTools.Method(typeof(ZInput), "ResetGamepadToAlt1", (Type[])null, (Type[])null);
				yield return AccessTools.Method(typeof(ZInput), "ResetGamepadToAlt2", (Type[])null, (Type[])null);
				yield return AccessTools.Method(typeof(ZInput), "OnRebindComplete", (Type[])null, (Type[])null);
				yield return AccessTools.Method(typeof(ZInput), "ResetToDefault", (Type[])null, (Type[])null);
				yield return AccessTools.Method(typeof(ZInput), "Load", (Type[])null, (Type[])null);
			}

			private static void Postfix(ZInput __instance)
			{
				FillSimilarHotkey(__instance);
			}
		}

		private static readonly Dictionary<string, Slots.Slot> similarHotkey = new Dictionary<string, Slots.Slot>();

		public static void FillSimilarHotkey()
		{
			FillSimilarHotkey(ZInput.instance);
		}

		internal static void FillSimilarHotkey(ZInput __instance)
		{
			//IL_006d: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			if (__instance == null || __instance.m_buttons == null)
			{
				return;
			}
			similarHotkey.Clear();
			Key key = default(Key);
			foreach (Slots.Slot item in Slots.slots.Where((Slots.Slot slot) => slot.IsHotkeySlot))
			{
				KeyboardShortcut shortcut = item.GetShortcut();
				if (ZInput.TryKeyCodeToKey(((KeyboardShortcut)(ref shortcut)).MainKey, ref key))
				{
					KeyValuePair<string, ButtonDef> keyValuePair = __instance.m_buttons.FirstOrDefault((KeyValuePair<string, ButtonDef> kvp) => kvp.Value.GetActionPath(true) == ZInput.KeyToPath(key));
					if (keyValuePair.Key != null)
					{
						similarHotkey[keyValuePair.Key] = item;
					}
				}
			}
		}
	}
	public static class TombStoneInteraction
	{
		[HarmonyPatch(typeof(TombStone), "OnTakeAllSuccess")]
		private static class TombStone_OnTakeAllSuccess_AutoEquip
		{
			private static void Postfix(TombStone __instance)
			{
				if (Slots.PlayerInventory != null)
				{
					FloatingTerrain val = default(FloatingTerrain);
					if (Player.m_enableAutoPickup && (Object)(object)((Component)((Component)__instance.m_body).transform.root).gameObject != (Object)(object)((Component)__instance).gameObject && ((Component)__instance).TryGetComponent<FloatingTerrain>(ref val))
					{
						Rigidbody body = __instance.m_body;
						ExtraSlots.LogDebug($"Destroyed tombstone component {((body != null) ? ((Component)body).gameObject : null)} to prevent NRE on AutoPickup");
						val.m_lastHeightmap = null;
						Rigidbody body2 = __instance.m_body;
						Object.Destroy((Object)(object)((body2 != null) ? ((Component)body2).gameObject : null));
					}
					if (ExtraSlots.slotsTombstoneAutoEquipEnabled.Value || ExtraSlots.slotsTombstoneAutoEquipCarryWeightItemsEnabled.Value)
					{
						EquipItemsInSlots();
					}
				}
			}
		}

		[HarmonyPatch(typeof(Container), "Awake")]
		private static class Container_Awake_TombstoneContainerHeightAdjustment
		{
			private static void Prefix(Container __instance)
			{
				if (Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<TombStone>()))
				{
					int targetInventoryHeight = Slots.GetTargetInventoryHeight(Slots.InventorySizeFull, __instance.m_width);
					if (targetInventoryHeight > __instance.m_height)
					{
						ExtraSlots.LogDebug($"TombStone Container Awake height {__instance.m_height} -> {targetInventoryHeight}");
						__instance.m_height = targetInventoryHeight;
					}
				}
			}
		}

		[HarmonyPatch(typeof(TombStone), "Interact")]
		internal static class TombStone_Interact_AdjustHeightAndStopAutoPickup
		{
			[HarmonyPriority(800)]
			private static void Prefix(TombStone __instance, bool hold)
			{
				if (!hold)
				{
					int targetInventoryHeight = Slots.GetTargetInventoryHeight(Slots.InventorySizeFull, __instance.m_container.m_width);
					if (targetInventoryHeight > __instance.m_container.m_height)
					{
						ExtraSlots.LogDebug($"TombStone Interact height {__instance.m_container.m_height} -> {targetInventoryHeight}. Inventory reloaded.");
						__instance.m_container.m_height = targetInventoryHeight;
						__instance.m_container.m_inventory.m_height = targetInventoryHeight;
						__instance.m_container.m_lastRevision = 0u;
						__instance.m_container.m_lastDataString = "";
						__instance.m_container.Load();
					}
				}
			}
		}

		[HarmonyPatch(typeof(TombStone), "EasyFitInInventory")]
		private static class TombStone_EasyFitInInventory_HeightAdjustment
		{
			private static void Prefix(TombStone __instance, Player player, ref float __state)
			{
				if (Slots.IsValidPlayer((Humanoid)(object)player))
				{
					StatusEffect lootStatusEffect = __instance.m_lootStatusEffect;
					__state = ((SE_Stats)(((lootStatusEffect is SE_Stats) ? lootStatusEffect : null)?)).m_addMaxCarryWeight ?? 0f;
					Player localPlayer = Player.m_localPlayer;
					localPlayer.m_maxCarryWeight += __state;
				}
			}

			private static void Postfix(TombStone __instance, Player player, float __state, ref bool __result)
			{
				//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
				if (!Slots.IsValidPlayer((Humanoid)(object)player))
				{
					return;
				}
				Player localPlayer = Player.m_localPlayer;
				localPlayer.m_maxCarryWeight -= __state;
				if (__result || __instance.m_container.GetInventory().NrOfItems() > Slots.InventorySizeActive)
				{
					return;
				}
				int num = 0;
				HashSet<Slots.Slot> hashSet = new HashSet<Slots.Slot>();
				foreach (ItemData item in __instance.m_container.GetInventory().GetAllItemsInGridOrder())
				{
					if (item.m_gridPos.y < Slots.InventoryHeightPlayer)
					{
						num++;
						continue;
					}
					Slots.Slot slotInGrid = Slots.GetSlotInGrid(item.m_gridPos);
					if (slotInGrid == null)
					{
						num++;
						continue;
					}
					if (hashSet.Contains(slot