Decompiled source of ExtraSlots v1.0.16

ExtraSlots.dll

Decompiled a week 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 ExtraSlots.Compatibility;
using ExtraSlots.HotBars;
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.16")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.16.0")]
[module: UnverifiableCode]
namespace ExtraSlots
{
	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}");
			}
		}

		[HarmonyPatch(typeof(RectTransformUtility), "RectangleContainsScreenPoint", new Type[]
		{
			typeof(RectTransform),
			typeof(Vector2)
		})]
		public static class RectTransformUtility_RectangleContainsScreenPoint_BackpacksCompat
		{
			private static void Postfix(RectTransform rect, Vector2 screenPoint, ref bool __result)
			{
				//IL_0059: Unknown result type (might be due to invalid IL or missing references)
				if (!Object.op_Implicit((Object)(object)InventoryGui.instance) || (Object)(object)rect != (Object)(object)InventoryGui.instance.m_playerGrid.m_gridRoot)
				{
					return;
				}
				for (int i = 0; i < Math.Min(Slots.slots.Length, InventoryGui.instance.m_playerGrid.m_elements.Count - Slots.InventorySizePlayer); i++)
				{
					Transform transform = InventoryGui.instance.m_playerGrid.m_elements[Slots.InventorySizePlayer + i].m_go.transform;
					if (RectTransformUtility.RectangleContainsScreenPoint((RectTransform)(object)((transform is RectTransform) ? transform : null), screenPoint))
					{
						__result = true;
						break;
					}
				}
			}
		}

		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_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0331: Unknown result type (might be due to invalid IL or missing references)
			//IL_033b: Unknown result type (might be due to invalid IL or missing references)
			//IL_034a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0355: Unknown result type (might be due to invalid IL or missing references)
			//IL_035a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0310: 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)
			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;
			}
			bool flag = InventoryGui.instance.m_dragItem != null && ((Humanoid)Slots.CurrentPlayer).IsItemEquiped(InventoryGui.instance.m_dragItem) && Slots.IsItemInEquipmentSlot(InventoryGui.instance.m_dragItem);
			for (int j = 0; j < Math.Min(InventoryGui.instance.m_playerGrid.m_elements.Count, inventorySizePlayer); j++)
			{
				Element obj = InventoryGui.instance.m_playerGrid.m_elements[j];
				object button;
				if (obj == null)
				{
					button = null;
				}
				else
				{
					GameObject go = obj.m_go;
					button = ((go != null) ? go.GetComponent<Button>() : null);
				}
				SetSlotColor((Button)button, flag);
			}
			for (int k = 0; k < Math.Min(Slots.slots.Length, InventoryGui.instance.m_playerGrid.m_elements.Count - inventorySizePlayer); k++)
			{
				SetSlotElement(InventoryGui.instance.m_playerGrid.m_elements[inventorySizePlayer + k], Slots.slots[k], flag);
			}
			for (int l = inventorySizePlayer + Slots.slots.Length; l < InventoryGui.instance.m_playerGrid.m_elements.Count; l++)
			{
				Element obj2 = InventoryGui.instance.m_playerGrid.m_elements[l];
				if (obj2 != null)
				{
					GameObject go2 = obj2.m_go;
					if (go2 != null)
					{
						go2.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, bool regularInventoryUnfitsForDragItem)
		{
			//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>(), InventoryGui.instance.m_dragItem != null && slot.IsActive && (!slot.ItemFits(InventoryGui.instance.m_dragItem) || (!slot.IsEquipmentSlot && regularInventoryUnfitsForDragItem)));
			}
		}

		internal static void SetSlotLabel(Transform binding, Slots.Slot slot, bool hotbarElement = false)
		{
			if (Object.op_Implicit((Object)(object)binding) && slot.IsActive)
			{
				SetSlotLabel(((Component)binding).GetComponent<RectTransform>(), ((Component)binding).GetComponent<TMP_Text>(), slot, hotbarElement);
			}
		}

		internal static void SetSlotLabel(RectTransform rectTransform, TMP_Text textComponent, Slots.Slot slot, bool hotbarElement = false)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			rectTransform.anchorMin = Vector2.zero;
			rectTransform.anchorMax = Vector2.one;
			rectTransform.offsetMin = Vector2.zero;
			rectTransform.offsetMax = Vector2.zero;
			rectTransform.sizeDelta = Vector2.zero;
			rectTransform.anchoredPosition = Vector2.zero;
			textComponent.enableAutoSizing = true;
			textComponent.text = ((!hotbarElement) ? slot.Name : (ZInput.IsGamepadActive() ? "" : slot.GetShortcutText()));
			((Behaviour)textComponent).enabled = true;
			textComponent.overflowMode = (TextOverflowModes)0;
			textComponent.fontSizeMin = ((!slot.IsHotkeySlot) ? ExtraSlots.equipmentSlotLabelFontSize.Value.x : (slot.IsAmmoSlot ? ExtraSlots.ammoSlotLabelFontSize.Value.x : ExtraSlots.quickSlotLabelFontSize.Value.x));
			textComponent.fontSizeMax = ((!slot.IsHotkeySlot) ? ExtraSlots.equipmentSlotLabelFontSize.Value.y : (slot.IsAmmoSlot ? ExtraSlots.ammoSlotLabelFontSize.Value.y : ExtraSlots.quickSlotLabelFontSize.Value.y));
			((Graphic)textComponent).color = ((!slot.IsHotkeySlot) ? ExtraSlots.equipmentSlotLabelFontColor.Value : (slot.IsAmmoSlot ? ExtraSlots.ammoSlotLabelFontColor.Value : ExtraSlots.quickSlotLabelFontColor.Value));
			textComponent.margin = ((!slot.IsHotkeySlot) ? ExtraSlots.equipmentSlotLabelMargin.Value : (slot.IsAmmoSlot ? ExtraSlots.ammoSlotLabelMargin.Value : ExtraSlots.quickSlotLabelMargin.Value));
			textComponent.textWrappingMode = ((!slot.IsHotkeySlot) ? ExtraSlots.equipmentSlotLabelWrappingMode.Value : (slot.IsAmmoSlot ? ExtraSlots.ammoSlotLabelWrappingMode.Value : ExtraSlots.quickSlotLabelWrappingMode.Value));
			textComponent.horizontalAlignment = ((!slot.IsHotkeySlot) ? ExtraSlots.equipmentSlotLabelAlignment.Value : (slot.IsAmmoSlot ? ExtraSlots.ammoSlotLabelAlignment.Value : ExtraSlots.quickSlotLabelAlignment.Value));
			textComponent.verticalAlignment = (VerticalAlignmentOptions)256;
		}

		internal static void SetSlotColor(Button button, bool useUnfitColor)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: 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_0117: 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_0123: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)button))
			{
				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 = (useUnfitColor ? normalColorUnfit : normalColor);
				((ColorBlock)(ref colors2)).highlightedColor = (useUnfitColor ? 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_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: 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_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_0322: Unknown result type (might be due to invalid IL or missing references)
			//IL_033b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_040f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0428: Unknown result type (might be due to invalid IL or missing references)
			//IL_042d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0391: Unknown result type (might be due to invalid IL or missing references)
			//IL_0397: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0469: Unknown result type (might be due to invalid IL or missing references)
			//IL_046f: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_051a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0520: 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 (!slot.IsEquipmentSlot || !EpicLootCompat.isEnabled || 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(string.Format(ExtraSlots.ammoSlotsTooltipNameFormat.Value, "$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(string.Format(ExtraSlots.quickSlotsTooltipNameFormat.Value, "$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(string.Format(ExtraSlots.foodSlotsTooltipNameFormat.Value, "$exsl_slot_food", slot.GetShortcutText()), "$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 static 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) && !ExtraSlots.IsAwaitingForSlotsUpdate())
				{
					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 bool Prefix(InventoryGui __instance, InventoryGrid grid, Vector2i pos)
			{
				//IL_0050: Unknown result type (might be due to invalid IL or missing references)
				if (Object.op_Implicit((Object)(object)Player.m_localPlayer) && !((Character)Player.m_localPlayer).IsTeleporting() && Object.op_Implicit((Object)(object)__instance.m_dragGo) && __instance.m_dragItem != null && __instance.m_dragInventory != null)
				{
					return PassDropItem("InventoryGui.OnSelectedItem", grid, __instance.m_dragInventory, __instance.m_dragItem, pos);
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(InventoryGrid), "DropItem")]
		public static class InventoryGrid_DropItem_DropPrevention
		{
			public static bool Prefix(InventoryGrid __instance, Inventory fromInventory, ItemData item, Vector2i pos)
			{
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				return PassDropItem("InventoryGrid.DropItem", __instance, fromInventory, item, pos);
			}
		}

		[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_00b6: Unknown result type (might be due to invalid IL or missing references)
				//IL_010d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0166: Unknown result type (might be due to invalid IL or missing references)
				//IL_017e: Unknown result type (might be due to invalid IL or missing references)
				//IL_018b: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
				if (__instance != Slots.PlayerInventory || (ExtraSlots.rowsProgressionEnabled.Value && Inventory_AddItem_OnLoad_FindAppropriateSlot.inCall && Slots.CurrentPlayer.m_isLoading) || 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)Slots.CurrentPlayer == (Object)null))
			{
				if (((Humanoid)Slots.CurrentPlayer).m_inventory.m_height != Slots.InventoryHeightFull)
				{
					ExtraSlots.LogInfo($"Player inventory height changed {((Humanoid)Slots.CurrentPlayer).m_inventory.m_height} -> {Slots.InventoryHeightFull}");
				}
				((Humanoid)Slots.CurrentPlayer).m_inventory.m_height = Slots.InventoryHeightFull;
				GameObject tombstone = Slots.CurrentPlayer.m_tombstone;
				Container val = ((tombstone != null) ? tombstone.GetComponent<Container>() : null);
				if (val != null)
				{
					val.m_height = Slots.InventoryHeightFull;
				}
				((Humanoid)Slots.CurrentPlayer).m_inventory.Changed();
				ItemsSlotsValidation.ValidateItems();
			}
		}

		private static bool PassDropItem(string source, InventoryGrid grid, Inventory fromInventory, ItemData item, Vector2i pos)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: 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_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			if (item.m_gridPos == pos)
			{
				return true;
			}
			if (grid.m_inventory == Slots.PlayerInventory)
			{
				Slots.Slot itemSlot = Slots.GetItemSlot(item);
				if (itemSlot != null && itemSlot.IsEquipmentSlot && ((Humanoid)Player.m_localPlayer).IsItemEquiped(item))
				{
					Slots.Slot slotInGrid = Slots.GetSlotInGrid(pos);
					if (slotInGrid == null)
					{
						ExtraSlots.LogDebug($"{source} Prevented dropping equipped item {item.m_shared.m_name} {item.m_gridPos} into regular inventory {pos}");
						return false;
					}
					if (!Slots.IsSameSlotType(itemSlot, slotInGrid))
					{
						ExtraSlots.LogDebug($"{source} Prevented dropping equipped item {item.m_shared.m_name} {item.m_gridPos} into slot with other type {slotInGrid}");
						return false;
					}
				}
			}
			if (grid.m_inventory == Slots.PlayerInventory)
			{
				Slots.Slot slotInGrid2 = Slots.GetSlotInGrid(pos);
				if (slotInGrid2 != null)
				{
					if (!slotInGrid2.ItemFits(item))
					{
						ExtraSlots.LogDebug($"{source} Prevented dropping {item.m_shared.m_name} {item.m_gridPos} into unfit slot {slotInGrid2}");
						return false;
					}
					if (slotInGrid2.IsEquipmentSlot && slotInGrid2.Item != null && ((Humanoid)Player.m_localPlayer).IsItemEquiped(slotInGrid2.Item))
					{
						Slots.Slot itemSlot2 = Slots.GetItemSlot(item);
						if (itemSlot2 == null || !itemSlot2.IsEquipmentSlot)
						{
							ExtraSlots.LogDebug($"{source} Prevented dropping {item.m_shared.m_name} {item.m_gridPos} into occupied equipment slot {slotInGrid2}");
							return false;
						}
					}
				}
			}
			ItemData itemAt = grid.m_inventory.GetItemAt(pos.x, pos.y);
			if (itemAt != null && fromInventory == Slots.PlayerInventory)
			{
				Slots.Slot slotInGrid3 = Slots.GetSlotInGrid(item.m_gridPos);
				if (slotInGrid3 != null && !slotInGrid3.ItemFits(itemAt))
				{
					ExtraSlots.LogDebug($"{source} Prevented swapping {item.m_shared.m_name} {slotInGrid3} with unfit item {itemAt.m_shared.m_name} {pos}");
					return false;
				}
			}
			return true;
		}
	}
	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();
						EquipWeaponShield();
					}
				}
			}
		}

		[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((Character)(object)player))
				{
					return;
				}
				StatusEffect lootStatusEffect = __instance.m_lootStatusEffect;
				__state = ((SE_Stats)(((lootStatusEffect is SE_Stats) ? lootStatusEffect : null)?)).m_addMaxCarryWeight ?? 0f;
				if (ExtraSlots.slotsTombstoneAutoEquipCarryWeightItemsEnabled.Value || ExtraSlots.slotsTombstoneAutoEquipEnabled.Value)
				{
					__state += __instance.m_container.GetInventory().GetAllItems().Where(delegate(ItemData item)
					{
						//IL_0025: Unknown result type (might be due to invalid IL or missing references)
						int result;
						if (item != null)
						{
							StatusEffect equipStatusEffect2 = item.m_shared.m_equipStatusEffect;
							SE_Stats val = (SE_Stats)(object)((equipStatusEffect2 is SE_Stats) ? equipStatusEffect2 : null);
							if (val != null && val.m_addMaxCarryWeight > 0f)
							{
								Slots.Slot slotInGrid = Slots.GetSlotInGrid(item.m_gridPos);
								if (slotInGrid != null)
								{
									result = (slotInGrid.IsEquipmentSlot ? 1 : 0);
									goto IL_003c;
								}
							}
						}
						result = 0;
						goto IL_003c;
						IL_003c:
						return (byte)result != 0;
					})
						.Sum(delegate(ItemData item)
						{
							StatusEffect equipStatusEffect = item.m_shared.m_equipStatusEffect;
							return ((SE_Stats)((equipStatusEffect is SE_Stats) ? equipStatusEffect : null)).m_addMaxCarryWeight;
						});
				}
				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((Character)(object)player))
				{
					return;
				}
				Player localPlayer = Player.m_localPlayer;
				localPlayer.m_maxCarryWeight -= __state;
				if (__result || __instance.m_container.GetInventory().NrOfItems() > Slots.InventorySizeActive)
				{
					return;
				}
				int num = 0;
				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(slotInGrid))
					{
						num++;
						continue;
					}
					hashSet.Add(slotInGrid);
					if (slotInGrid.IsQuickSlot)
					{
						num++;
					}
					else if (!slotInGrid.ItemFits(item))
					{
						num++;
					}
				}
				__result = num <= Slots.PlayerInventory.GetEmptySlots() && ((Humanoid)player).GetInventory().GetTotalWeight() + __instance.m_container.GetInventory().GetTotalWeight() < player.GetMaxCarryWeight() + __state;
			}
		}

		[HarmonyPatch(typeof(Character), "CheckDeath")]
		private static class Character_CheckDeath_OnDeathWrapping
		{
			[HarmonyPriority(800)]
			private static void Prefix(Character __instance)
			{
				if (Slots.IsValidPlayer(__instance) && !__instance.IsDead() && __instance.GetHealth() <= 0f)
				{
					OnDeathPrefix((Player)(object)((__instance is Player) ? __instance : null));
				}
			}
		}

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

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

		public static void EquipItemsInSlots()
		{
			Slots.ClearCachedItems();
			CollectionExtensions.Do<ItemData>((from slot in Slots.GetEquipmentSlots(onlyActive: false)
				select slot.Item).Where(IsItemToEquip), (Action<ItemData>)TryEquipItem);
		}

		private static bool IsItemToEquip(ItemData item)
		{
			int result;
			if (!ExtraSlots.slotsTombstoneAutoEquipEnabled.Value)
			{
				if (ExtraSlots.slotsTombstoneAutoEquipCarryWeightItemsEnabled.Value && item != null)
				{
					StatusEffect equipStatusEffect = item.m_shared.m_equipStatusEffect;
					SE_Stats val = (SE_Stats)(object)((equipStatusEffect is SE_Stats) ? equipStatusEffect : null);
					if (val != null)
					{
						result = ((val.m_addMaxCarryWeight > 0f) ? 1 : 0);
						goto IL_0042;
					}
				}
				result = 0;
			}
			else
			{
				result = 1;
			}
			goto IL_0042;
			IL_0042:
			return (byte)result != 0;
		}

		private static bool IsWeaponShieldToEquip(ItemData item)
		{
			string value;
			return ExtraSlots.slotsTombstoneAutoEquipWeaponShield.Value && item.m_customData.TryGetValue("ExtraSlotsEquippedWeaponShield", out value) && value == Game.instance.GetPlayerProfile().GetPlayerID().ToString();
		}

		private static void TryEquipItem(ItemData item)
		{
			if (item != null && !((Humanoid)Slots.CurrentPlayer).IsItemEquiped(item) && ((Humanoid)Slots.CurrentPlayer).EquipItem(item, true))
			{
				ExtraSlots.LogDebug("Item " + item.m_shared.m_name + " was equipped on tombstone interaction");
			}
		}

		public static void EquipWeaponShield()
		{
			CollectionExtensions.Do<ItemData>(Slots.PlayerInventory.GetAllItems().Where(IsWeaponShieldToEquip), (Action<ItemData>)TryEquipItem);
		}

		public static void OnDeathPrefix(Player player)
		{
			itemsToKeep.Clear();
			CollectionExtensions.DoIf<Slots.Slot>((IEnumerable<Slots.Slot>)Slots.slots, (Func<Slots.Slot, bool>)IsSlotToKeep, (Action<Slots.Slot>)delegate(Slots.Slot slot)
			{
				KeepItem(slot.Item);
			});
			Slots.ClearCachedItems();
			Slots.SaveLastEquippedSlotsToItems();
			Slots.SaveLastEquippedWeaponShieldToItems(player);
			static bool IsSlotToKeep(Slots.Slot slot)
			{
				if (slot.IsFree)
				{
					return false;
				}
				return (slot.IsEquipmentSlot && ExtraSlots.keepOnDeathEquipmentSlots.Value) || (slot.IsQuickSlot && ExtraSlots.keepOnDeathQuickSlots.Value) || (slot.IsAmmoSlot && ExtraSlots.keepOnDeathAmmoSlots.Value) || (slot.IsFoodSlot && ExtraSlots.keepOnDeathFoodSlots.Value) || (slot.IsMiscSlot && ExtraSlots.keepOnDeathMiscSlots.Value);
			}
			void KeepItem(ItemData item)
			{
				itemsToKeep.Add(item);
				((Humanoid)player).GetInventory().m_inventory.Remove(item);
			}
		}

		public static void OnDeathPostfix(Player player)
		{
			if (itemsToKeep.Count != 0)
			{
				((Humanoid)player).GetInventory().m_inventory.AddRange(itemsToKeep);
				itemsToKeep.Clear();
			}
		}
	}
	[Serializable]
	public class HumanoidExtraUtilitySlots
	{
		public ItemData utility1;

		public ItemData utility2;

		public ItemData utility3;

		public ItemData utility4;
	}
	public static class HumanoidExtension
	{
		private static readonly ConditionalWeakTable<Humanoid, HumanoidExtraUtilitySlots> data = new ConditionalWeakTable<Humanoid, HumanoidExtraUtilitySlots>();

		public static HumanoidExtraUtilitySlots GetExtraUtilityData(this Humanoid humanoid)
		{
			return data.GetOrCreateValue(humanoid);
		}

		public static ItemData GetExtraUtility(this Humanoid humanoid, int index)
		{
			if (1 == 0)
			{
			}
			ItemData result = (ItemData)(index switch
			{
				0 => humanoid.GetExtraUtilityData().utility1, 
				1 => humanoid.GetExtraUtilityData().utility2, 
				2 => humanoid.GetExtraUtilityData().utility3, 
				3 => humanoid.GetExtraUtilityData().utility4, 
				_ => null, 
			});
			if (1 == 0)
			{
			}
			return result;
		}

		public static ItemData SetExtraUtility(this Humanoid humanoid, int index, ItemData item)
		{
			if (1 == 0)
			{
			}
			ItemData result = (ItemData)(index switch
			{
				0 => humanoid.GetExtraUtilityData().utility1 = item, 
				1 => humanoid.GetExtraUtilityData().utility2 = item, 
				2 => humanoid.GetExtraUtilityData().utility3 = item, 
				3 => humanoid.GetExtraUtilityData().utility4 = item, 
				_ => null, 
			});
			if (1 == 0)
			{
			}
			return result;
		}
	}
	public static class ExtraUtilitySlots
	{
		public static class ExtraUtilityPatches
		{
			[HarmonyPatch(typeof(Humanoid), "UpdateEquipmentStatusEffects")]
			private static class Humanoid_UpdateEquipmentStatusEffects_ExtraUtility
			{
				private static void Prefix(Humanoid __instance)
				{
					if (!Slots.IsValidPlayer((Character)(object)__instance))
					{
						return;
					}
					tempEffects.Clear();
					foreach (ItemData equippedItem in GetEquippedItems())
					{
						if (Object.op_Implicit((Object)(object)equippedItem.m_shared.m_equipStatusEffect))
						{
							tempEffects.Add(equippedItem.m_shared.m_equipStatusEffect);
						}
						if (__instance.HaveSetEffect(equippedItem))
						{
							tempEffects.Add(equippedItem.m_shared.m_setStatusEffect);
						}
					}
				}

				private static void Postfix(Humanoid __instance)
				{
					foreach (StatusEffect item in tempEffects.Where((StatusEffect item) => !__instance.m_equipmentStatusEffects.Contains(item)))
					{
						((Character)__instance).m_seman.AddStatusEffect(item, false, 0, 0f);
					}
					__instance.m_equipmentStatusEffects.UnionWith(tempEffects);
					tempEffects.Clear();
				}
			}

			[HarmonyPatch(typeof(SEMan), "RemoveStatusEffect", new Type[]
			{
				typeof(int),
				typeof(bool)
			})]
			private static class SEMan_RemoveStatusEffect_ExtraUtilityPreventRemoval
			{
				private static void Prefix(SEMan __instance, ref int nameHash)
				{
					Player currentPlayer = Slots.CurrentPlayer;
					if (__instance != ((currentPlayer != null) ? ((Character)currentPlayer).GetSEMan() : null) || tempEffects.Count == 0)
					{
						return;
					}
					foreach (StatusEffect tempEffect in tempEffects)
					{
						if (tempEffect.NameHash() == nameHash)
						{
							nameHash = 0;
						}
					}
				}
			}

			[HarmonyPatch(typeof(Humanoid), "GetEquipmentWeight")]
			private static class Humanoid_GetEquipmentWeight_ExtraUtility
			{
				private static void Postfix(Humanoid __instance, ref float __result)
				{
					if (Slots.IsValidPlayer((Character)(object)__instance))
					{
						__result += GetEquippedItems().Sum((ItemData item) => item.m_shared.m_weight);
					}
				}
			}

			[HarmonyPatch(typeof(Humanoid), "EquipItem")]
			private static class Humanoid_EquipItem_ExtraUtility
			{
				private static readonly ItemType tempType = (ItemType)727;

				private static void Prefix(Humanoid __instance, ItemData item, ref int __state)
				{
					//IL_0057: 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_0093: Unknown result type (might be due to invalid IL or missing references)
					//IL_0098: Unkno