Decompiled source of Supermans Quiver v2.1.1

SupermansQuiver.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("assembly_utils")]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Quiver
{
	internal class ExtraPanel
	{
		public static ExtraPanel Quiver;

		public static ExtraPanel Gear;

		public static ExtraPanel Pouch;

		public static readonly List<ExtraPanel> All = new List<ExtraPanel>();

		private const float SnapDistance = 20f;

		private const float MinOnScreen = 40f;

		public readonly string Id;

		private readonly ConfigEntry<string> _dock;

		private readonly ConfigEntry<float> _x;

		private readonly ConfigEntry<float> _y;

		private readonly Func<Inventory> _inventory;

		private readonly Func<bool> _enabled;

		private readonly Func<float, float, float, float, Sprite> _art;

		private int _cols;

		private int _rows;

		private float _space;

		private float _padX;

		private float _top;

		private float _bottom;

		internal Vector2? DragPosition;

		private static InventoryGui _gui;

		private static RectTransform _layer;

		public InventoryGrid Grid { get; private set; }

		public RectTransform Root { get; private set; }

		public Inventory Inventory => _inventory();

		public bool Enabled
		{
			get
			{
				if (Plugin.ModEnabled.Value)
				{
					return _enabled();
				}
				return false;
			}
		}

		public bool Visible
		{
			get
			{
				if ((Object)(object)Root != (Object)null)
				{
					return ((Component)Root).gameObject.activeInHierarchy;
				}
				return false;
			}
		}

		public Vector2 Size => Root.sizeDelta;

		private ExtraPanel(string id, ConfigEntry<string> dock, ConfigEntry<float> x, ConfigEntry<float> y, Func<Inventory> inventory, Func<bool> enabled, Func<float, float, float, float, Sprite> art)
		{
			Id = id;
			_dock = dock;
			_x = x;
			_y = y;
			_inventory = inventory;
			_enabled = enabled;
			_art = art;
		}

		public static void CreateAll(InventoryGui gui)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			_gui = gui;
			_layer = (RectTransform)((Component)gui).transform;
			foreach (ExtraPanel item in All)
			{
				if ((Object)(object)item.Root != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)item.Root).gameObject);
				}
			}
			All.Clear();
			Quiver = Build(gui, new ExtraPanel("Quiver", Plugin.QuiverDock, Plugin.QuiverX, Plugin.QuiverY, () => QuiverStore.Inventory, () => true, QuiverArt.Create), 1, 6, 12f, 70f, 28f, delegate(ItemData item)
			{
				QuiverStore.EquipFromQuiver(Player.m_localPlayer, item);
			});
			Gear = Build(gui, new ExtraPanel("Gear", Plugin.GearDock, Plugin.GearX, Plugin.GearY, () => GearStore.Inventory, () => Plugin.GearEnabled.Value, PanelArt.Board), 2, GearStore.RowsFor(Plugin.UtilitySlots.Value), 10f, 10f, 10f, delegate(ItemData item)
			{
				GearStore.TakeOff(Player.m_localPlayer, item, ((Humanoid)Player.m_localPlayer).GetInventory());
			});
			Pouch = Build(gui, new ExtraPanel("QuickSlots", Plugin.PouchDock, Plugin.PouchX, Plugin.PouchY, () => PouchStore.Inventory, () => Plugin.PouchEnabled.Value, PanelArt.Board), 3, 2, 10f, 10f, 10f, delegate(ItemData item)
			{
				PouchStore.Use(Player.m_localPlayer, item);
			});
		}

		private static ExtraPanel Build(InventoryGui gui, ExtraPanel panel, int cols, int rows, float padX, float top, float bottom, Action<ItemData> rightClick)
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			//IL_00b9: 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_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			InventoryGrid playerGrid = gui.m_playerGrid;
			panel._space = playerGrid.m_elementSpace;
			panel._padX = padX;
			panel._top = top;
			panel._bottom = bottom;
			GameObject val = new GameObject("Supermans" + panel.Id, new Type[1] { typeof(RectTransform) });
			panel.Root = (RectTransform)val.transform;
			((Transform)panel.Root).SetParent((Transform)(object)_layer, false);
			((Transform)panel.Root).SetSiblingIndex(gui.m_inventoryRoot.GetSiblingIndex() + 1);
			RectTransform root = panel.Root;
			RectTransform root2 = panel.Root;
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(0.5f, 0.5f);
			root2.anchorMax = val2;
			root.anchorMin = val2;
			panel.Root.pivot = new Vector2(0f, 1f);
			val.SetActive(false);
			val.AddComponent<Image>().alphaHitTestMinimumThreshold = 0.5f;
			val.AddComponent<PanelDragHandle>().Panel = panel;
			GameObject val3 = Object.Instantiate<GameObject>(((Component)playerGrid).gameObject, (Transform)(object)panel.Root, false);
			((Object)val3).name = panel.Id + "Grid";
			InventoryGrid val4 = (panel.Grid = val3.GetComponent<InventoryGrid>());
			foreach (Transform item in (Transform)val4.m_gridRoot)
			{
				Object.Destroy((Object)(object)((Component)item).gameObject);
			}
			UIGroupHandler[] componentsInChildren = val3.GetComponentsInChildren<UIGroupHandler>(true);
			foreach (UIGroupHandler val5 in componentsInChildren)
			{
				if ((Object)(object)val5 != (Object)(object)playerGrid.m_uiGroup)
				{
					Object.Destroy((Object)(object)val5);
				}
			}
			val4.m_uiGroup = playerGrid.m_uiGroup;
			if ((Object)(object)val4.m_scrollbar != (Object)null && ((Component)val4.m_scrollbar).transform.IsChildOf(val3.transform))
			{
				((Component)val4.m_scrollbar).gameObject.SetActive(false);
			}
			Image component2 = val3.GetComponent<Image>();
			if ((Object)(object)component2 != (Object)null)
			{
				((Behaviour)component2).enabled = false;
			}
			RectTransform val6 = (RectTransform)val3.transform;
			((Vector2)(ref val2))..ctor(0.5f, 1f);
			val6.anchorMax = val2;
			val6.anchorMin = val2;
			val6.pivot = new Vector2(0.5f, 1f);
			val6.anchoredPosition = new Vector2(0f, 0f - top);
			val4.m_gridRoot.anchoredPosition = Vector2.zero;
			val4.m_onSelected = gui.OnSelectedItem;
			val4.m_onReleased = gui.OnReleasedItem;
			val4.m_onEnter = gui.OnEnterElement;
			val4.OnSetTouchSelection = gui.SetTouchSelection;
			val4.CanDropDragOntoItem = gui.CanDropDragOntoItem;
			val4.m_onRightClick = delegate(InventoryGrid g, ItemData item, Vector2i pos)
			{
				if (item != null && (Object)(object)Player.m_localPlayer != (Object)null)
				{
					rightClick(item);
				}
			};
			val4.OnMoveToUpperInventoryGrid = null;
			val4.OnMoveToLowerInventoryGrid = null;
			panel.Resize(cols, rows);
			All.Add(panel);
			return panel;
		}

		private void Resize(int cols, int rows)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			_cols = cols;
			_rows = rows;
			float num = _space * (float)cols + _padX * 2f;
			float num2 = _top + _space * (float)rows + _bottom;
			Root.sizeDelta = new Vector2(num, num2);
			((Component)Root).GetComponent<Image>().sprite = _art(num, num2, _top, _bottom);
			((RectTransform)((Component)Grid).transform).sizeDelta = new Vector2(_space * (float)cols, _space * (float)rows);
		}

		public static bool IsPanelGrid(InventoryGrid grid)
		{
			if ((Object)(object)grid != (Object)null)
			{
				if (!((Object)(object)grid == (Object)(object)Quiver?.Grid) && !((Object)(object)grid == (Object)(object)Gear?.Grid))
				{
					return (Object)(object)grid == (Object)(object)Pouch?.Grid;
				}
				return true;
			}
			return false;
		}

		public static void UpdateAll(InventoryGui gui, Player player)
		{
			foreach (ExtraPanel item in All)
			{
				item.Update(gui, player);
			}
			Layout();
		}

		public static void LateLayout()
		{
			if (All.Count == 0 || InventoryGui.IsVisible())
			{
				return;
			}
			foreach (ExtraPanel item in All)
			{
				if ((Object)(object)item.Root != (Object)null && ((Component)item.Root).gameObject.activeSelf)
				{
					((Component)item.Root).gameObject.SetActive(false);
				}
			}
		}

		private void Update(InventoryGui gui, Player player)
		{
			if ((Object)(object)Root == (Object)null)
			{
				return;
			}
			bool flag = Enabled && (Object)(object)player != (Object)null && (Object)(object)player == (Object)(object)QuiverStore.Owner && InventoryGui.IsVisible();
			if (((Component)Root).gameObject.activeSelf != flag)
			{
				((Component)Root).gameObject.SetActive(flag);
			}
			if (!flag)
			{
				return;
			}
			Inventory inventory = Inventory;
			if (inventory.GetWidth() != _cols || inventory.GetHeight() != _rows)
			{
				Resize(inventory.GetWidth(), inventory.GetHeight());
			}
			Grid.UpdateInventory(inventory, (Grid.m_elements.Count == 0) ? null : player, gui.m_dragItem);
			if (this != Gear)
			{
				return;
			}
			for (int i = 0; i < Grid.m_elements.Count; i++)
			{
				bool flag2 = GearStore.SlotAt(i) != GearSlot.None;
				if (((Component)Grid.m_elements[i]).gameObject.activeSelf != flag2)
				{
					((Component)Grid.m_elements[i]).gameObject.SetActive(flag2);
				}
			}
		}

		private static void Layout()
		{
			//IL_002a: 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)
			foreach (ExtraPanel item in All)
			{
				if (!((Object)(object)item.Root == (Object)null))
				{
					((Transform)item.Root).localPosition = Vector2.op_Implicit(item.TopLeft());
				}
			}
		}

		private static Vector2 InventoryCorner()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Expected O, but got Unknown
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			_gui.m_player.GetWorldCorners(array);
			Vector2 val = Vector2.op_Implicit(((Transform)_layer).InverseTransformPoint(array[2]));
			float num = val.x;
			TMP_Text[] array2 = (TMP_Text[])(object)new TMP_Text[2] { _gui.m_weight, _gui.m_armor };
			foreach (TMP_Text val2 in array2)
			{
				if (!((Object)(object)val2 == (Object)null) && ((Component)val2).gameObject.activeInHierarchy)
				{
					num = Mathf.Max(num, RightEdge((RectTransform)val2.transform, array));
					Transform parent = val2.transform.parent;
					RectTransform val3 = (RectTransform)(object)((parent is RectTransform) ? parent : null);
					if (val3 != null && (Object)(object)val3 != (Object)(object)_gui.m_player && !((Transform)_gui.m_player).IsChildOf((Transform)(object)val3))
					{
						num = Mathf.Max(num, RightEdge(val3, array));
					}
				}
			}
			if (num - val.x < 250f)
			{
				val.x = num;
			}
			return val;
		}

		private static float RightEdge(RectTransform rt, Vector3[] buffer)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			rt.GetWorldCorners(buffer);
			return ((Transform)_layer).InverseTransformPoint(buffer[2]).x;
		}

		public ExtraPanel DockTarget(out string side)
		{
			side = null;
			string text = _dock.Value ?? "";
			int num = text.IndexOf(':');
			if (num <= 0)
			{
				return null;
			}
			string b = text.Substring(0, num);
			side = text.Substring(num + 1);
			foreach (ExtraPanel item in All)
			{
				if (item != this && string.Equals(item.Id, b, StringComparison.OrdinalIgnoreCase))
				{
					return item;
				}
			}
			return null;
		}

		public ExtraPanel GroupRoot()
		{
			ExtraPanel extraPanel = this;
			for (int i = 0; i < All.Count; i++)
			{
				string side;
				ExtraPanel extraPanel2 = extraPanel.DockTarget(out side);
				if (extraPanel2 == null)
				{
					return extraPanel;
				}
				extraPanel = extraPanel2;
			}
			return this;
		}

		public bool IsInGroupOf(ExtraPanel root)
		{
			ExtraPanel extraPanel = this;
			for (int i = 0; i <= All.Count; i++)
			{
				if (extraPanel == null)
				{
					break;
				}
				if (extraPanel == root)
				{
					return true;
				}
				extraPanel = extraPanel.DockTarget(out var _);
			}
			return false;
		}

		public Vector2 TopLeft()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			return TopLeft(0);
		}

		private Vector2 TopLeft(int depth)
		{
			//IL_0013: 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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0037: 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)
			if (DragPosition.HasValue)
			{
				return DragPosition.Value;
			}
			string side = null;
			ExtraPanel extraPanel = ((depth < All.Count) ? DockTarget(out side) : null);
			if (extraPanel == null)
			{
				return InventoryCorner() + new Vector2(_x.Value, _y.Value);
			}
			return Anchor(extraPanel.TopLeft(depth + 1), extraPanel.Size, Size, side) + new Vector2(_x.Value, _y.Value);
		}

		private static Vector2 Anchor(Vector2 targetTopLeft, Vector2 targetSize, Vector2 size, string side)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			return (Vector2)(side switch
			{
				"Left" => targetTopLeft + new Vector2(0f - size.x, 0f), 
				"Below" => targetTopLeft + new Vector2(0f, 0f - targetSize.y), 
				"Above" => targetTopLeft + new Vector2(0f, size.y), 
				_ => targetTopLeft + new Vector2(targetSize.x, 0f), 
			});
		}

		public void Detach()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if (DockTarget(out var _) != null)
			{
				Vector2 val = TopLeft();
				_dock.Value = "";
				SetOffset(val - InventoryCorner());
			}
		}

		private void SetOffset(Vector2 offset)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			_x.Value = Mathf.Round(offset.x);
			_y.Value = Mathf.Round(offset.y);
		}

		public ExtraPanel DragTo(Vector2 wanted, out string snapSide)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: 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_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: 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_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: 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_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: 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_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: 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_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: 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_011c: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = KeepOnScreen(wanted);
			ExtraPanel extraPanel = null;
			string text = null;
			float num = 20f;
			foreach (ExtraPanel item in All)
			{
				if (!item.Visible || item.IsInGroupOf(this))
				{
					continue;
				}
				Vector2 val2 = item.TopLeft();
				Vector2 size = item.Size;
				string[] array = new string[4] { "Right", "Left", "Below", "Above" };
				foreach (string text2 in array)
				{
					Vector2 val3 = Anchor(val2, size, Size, text2);
					int num2;
					float num3;
					if (!(text2 == "Right"))
					{
						num2 = ((text2 == "Left") ? 1 : 0);
						if (num2 == 0)
						{
							num3 = Mathf.Abs(val.y - val3.y);
							goto IL_00e9;
						}
					}
					else
					{
						num2 = 1;
					}
					num3 = Mathf.Abs(val.x - val3.x);
					goto IL_00e9;
					IL_00e9:
					float num4 = num3;
					bool num5;
					if (num2 == 0)
					{
						if (!(val.x < val2.x + size.x + 20f))
						{
							continue;
						}
						num5 = val.x + Size.x > val2.x - 20f;
					}
					else
					{
						if (!(val.y - Size.y < val2.y + 20f))
						{
							continue;
						}
						num5 = val.y > val2.y - size.y - 20f;
					}
					if (num5 && !(num4 >= num))
					{
						num = num4;
						extraPanel = item;
						text = text2;
					}
				}
			}
			Vector2 val4;
			int num6;
			Vector2 val5;
			if (extraPanel != null)
			{
				val4 = Anchor(extraPanel.TopLeft(), extraPanel.Size, Size, text);
				if (!(text == "Right"))
				{
					num6 = ((text == "Left") ? 1 : 0);
					if (num6 == 0)
					{
						val5 = new Vector2(val.x, val4.y);
						goto IL_0212;
					}
				}
				else
				{
					num6 = 1;
				}
				val5 = new Vector2(val4.x, val.y);
				goto IL_0212;
			}
			goto IL_0268;
			IL_0212:
			val = val5;
			if (num6 != 0 && Mathf.Abs(val.y - val4.y) < 20f)
			{
				val.y = val4.y;
			}
			if (num6 == 0 && Mathf.Abs(val.x - val4.x) < 20f)
			{
				val.x = val4.x;
			}
			goto IL_0268;
			IL_0268:
			DragPosition = val;
			Layout();
			snapSide = text;
			return extraPanel;
		}

		public void Drop(ExtraPanel target, string side)
		{
			//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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_0033: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = TopLeft();
			DragPosition = null;
			if (target != null)
			{
				_dock.Value = target.Id + ":" + side;
				SetOffset(val - Anchor(target.TopLeft(), target.Size, Size, side));
			}
			else
			{
				_dock.Value = "";
				SetOffset(val - InventoryCorner());
			}
			Layout();
		}

		public void ResetLayout()
		{
			_dock.Value = (string)((ConfigEntryBase)_dock).DefaultValue;
			_x.Value = (float)((ConfigEntryBase)_x).DefaultValue;
			_y.Value = (float)((ConfigEntryBase)_y).DefaultValue;
			string side;
			ExtraPanel extraPanel = DockTarget(out side);
			if (extraPanel != null && extraPanel.IsInGroupOf(this))
			{
				_dock.Value = "";
			}
			Layout();
		}

		private Vector2 KeepOnScreen(Vector2 pos)
		{
			//IL_001a: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			Canvas componentInParent = ((Component)_layer).GetComponentInParent<Canvas>();
			Camera val = (((Object)(object)componentInParent != (Object)null && (int)componentInParent.rootCanvas.renderMode != 0) ? componentInParent.rootCanvas.worldCamera : null);
			Vector2 val2 = default(Vector2);
			RectTransformUtility.ScreenPointToLocalPointInRectangle(_layer, Vector2.zero, val, ref val2);
			Vector2 val3 = default(Vector2);
			RectTransformUtility.ScreenPointToLocalPointInRectangle(_layer, new Vector2((float)Screen.width, (float)Screen.height), val, ref val3);
			Rect val4 = Rect.MinMaxRect(val2.x, val2.y, val3.x, val3.y);
			pos.x = Mathf.Clamp(pos.x, ((Rect)(ref val4)).xMin - Size.x + 40f, ((Rect)(ref val4)).xMax - 40f);
			pos.y = Mathf.Clamp(pos.y, ((Rect)(ref val4)).yMin + 40f, ((Rect)(ref val4)).yMax + Size.y - 40f);
			return pos;
		}
	}
	internal enum GearSlot
	{
		None,
		Helmet,
		Cape,
		Chest,
		Trinket,
		Legs,
		Utility
	}
	internal static class GearStore
	{
		public const int Columns = 2;

		private const string SaveKey = "supermans.gear";

		private static GearSlot[] _layout = BuildLayout(1);

		public static readonly List<ItemData> ExtraUtilities = new List<ItemData>();

		private static readonly GearSlot[] WornSlots = new GearSlot[6]
		{
			GearSlot.Helmet,
			GearSlot.Cape,
			GearSlot.Chest,
			GearSlot.Trinket,
			GearSlot.Legs,
			GearSlot.Utility
		};

		public static Inventory Inventory { get; private set; } = new Inventory("Gear", (Sprite)null, 2, 3);

		public static int Rows => _layout.Length / 2;

		public static int RowsFor(int utilitySlots)
		{
			return BuildLayout(Mathf.Clamp(utilitySlots, 1, 4)).Length / 2;
		}

		private static GearSlot[] BuildLayout(int utilitySlots)
		{
			List<GearSlot> list = new List<GearSlot>
			{
				GearSlot.Helmet,
				GearSlot.Cape,
				GearSlot.Chest,
				GearSlot.Trinket,
				GearSlot.Legs
			};
			for (int i = 0; i < utilitySlots; i++)
			{
				list.Add(GearSlot.Utility);
			}
			if (list.Count % 2 != 0)
			{
				list.Add(GearSlot.None);
			}
			return list.ToArray();
		}

		public static GearSlot SlotAt(Vector2i pos)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			int num = pos.y * 2 + pos.x;
			if (pos.x >= 0 && pos.x < 2 && num >= 0 && num < _layout.Length)
			{
				return _layout[num];
			}
			return GearSlot.None;
		}

		public static GearSlot SlotAt(int index)
		{
			if (index < 0 || index >= _layout.Length)
			{
				return GearSlot.None;
			}
			return _layout[index];
		}

		public static GearSlot SlotFor(ItemData item)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Invalid comparison between Unknown and I4
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Invalid comparison between Unknown and I4
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Invalid comparison between Unknown and I4
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Invalid comparison between Unknown and I4
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Invalid comparison between Unknown and I4
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Invalid comparison between Unknown and I4
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Invalid comparison between Unknown and I4
			if (item == null)
			{
				return GearSlot.None;
			}
			ItemType itemType = item.m_shared.m_itemType;
			if ((int)itemType <= 11)
			{
				if ((int)itemType == 6)
				{
					return GearSlot.Helmet;
				}
				if ((int)itemType == 7)
				{
					return GearSlot.Chest;
				}
				if ((int)itemType == 11)
				{
					return GearSlot.Legs;
				}
			}
			else
			{
				if ((int)itemType == 17)
				{
					return GearSlot.Cape;
				}
				if ((int)itemType == 18)
				{
					return GearSlot.Utility;
				}
				if ((int)itemType == 24)
				{
					return GearSlot.Trinket;
				}
			}
			return GearSlot.None;
		}

		public static bool Accepts(Vector2i pos, ItemData item)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			GearSlot gearSlot = SlotAt(pos);
			if (gearSlot != GearSlot.None)
			{
				return gearSlot == SlotFor(item);
			}
			return false;
		}

		private static Vector2i PosOf(int index)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return new Vector2i(index % 2, index / 2);
		}

		private static IEnumerable<Vector2i> PositionsOf(GearSlot slot)
		{
			for (int i = 0; i < _layout.Length; i++)
			{
				if (_layout[i] == slot)
				{
					yield return PosOf(i);
				}
			}
		}

		private static Vector2i FirstPos(GearSlot slot)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			using (IEnumerator<Vector2i> enumerator = PositionsOf(slot).GetEnumerator())
			{
				if (enumerator.MoveNext())
				{
					return enumerator.Current;
				}
			}
			return new Vector2i(-1, -1);
		}

		private static bool IsFirstUtility(Vector2i pos)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			return pos == FirstPos(GearSlot.Utility);
		}

		public static void Load(Player player)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			_layout = BuildLayout(Mathf.Clamp(Plugin.UtilitySlots.Value, 1, 4));
			Inventory = new Inventory("Gear", (Sprite)null, 2, Rows);
			ExtraUtilities.Clear();
			SaveData.Load(player, "supermans.gear", Inventory);
			foreach (ItemData item in new List<ItemData>(Inventory.GetAllItems()))
			{
				if (!Accepts(item.m_gridPos, item))
				{
					Inventory.m_inventory.Remove(item);
					item.m_equipped = false;
					SaveData.GiveBack(player, item);
				}
			}
			Inventory.Changed(false, false);
		}

		public static void Relayout(Player player)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			//IL_0080: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: 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)
			int num = Mathf.Clamp(Plugin.UtilitySlots.Value, 1, 4);
			GearSlot[] array = BuildLayout(num);
			if (array.SequenceEqual(_layout))
			{
				return;
			}
			Inventory inventory = Inventory;
			_layout = array;
			Inventory = new Inventory("Gear", (Sprite)null, 2, Rows);
			if ((Object)(object)player == (Object)null || (Object)(object)player != (Object)(object)QuiverStore.Owner)
			{
				return;
			}
			List<ItemData> list = new List<ItemData>();
			foreach (ItemData allItem in inventory.GetAllItems())
			{
				if (Accepts(allItem.m_gridPos, allItem))
				{
					Inventory.m_inventory.Add(allItem);
				}
				else
				{
					list.Add(allItem);
				}
			}
			foreach (ItemData item in list)
			{
				Vector2i val = (Vector2i)((SlotFor(item) == GearSlot.Utility) ? FreeExtraUtility() : new Vector2i(-1, -1));
				if (val.x >= 0)
				{
					item.m_gridPos = val;
					Inventory.m_inventory.Add(item);
					continue;
				}
				if (((Humanoid)player).IsItemEquiped(item))
				{
					((Humanoid)player).UnequipItem(item, false);
				}
				item.m_equipped = false;
				SaveData.GiveBack(player, item);
			}
			Inventory.Changed(false, false);
			SyncExtraUtilities(player);
			((Character)player).Message((MessageType)1, $"Utility slots: {num}", 0, (Sprite)null, false);
		}

		public static void Save(Player player)
		{
			if ((Object)(object)player == (Object)(object)QuiverStore.Owner)
			{
				SaveData.Save(player, "supermans.gear", Inventory);
			}
		}

		private static ItemData Worn(Player p, GearSlot slot)
		{
			return (ItemData)(slot switch
			{
				GearSlot.Helmet => ((Humanoid)p).m_helmetItem, 
				GearSlot.Cape => ((Humanoid)p).m_shoulderItem, 
				GearSlot.Chest => ((Humanoid)p).m_chestItem, 
				GearSlot.Trinket => ((Humanoid)p).m_trinketItem, 
				GearSlot.Legs => ((Humanoid)p).m_legItem, 
				GearSlot.Utility => ((Humanoid)p).m_utilityItem, 
				_ => null, 
			});
		}

		public static void Sync(Player p)
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)p == (Object)null || (Object)(object)p != (Object)(object)QuiverStore.Owner || ((Character)p).IsDead() || p.m_isLoading)
			{
				return;
			}
			if (!Plugin.GearEnabled.Value)
			{
				if (Inventory.NrOfItems() > 0)
				{
					EmptyIntoInventory(p);
				}
				return;
			}
			Inventory inventory = ((Humanoid)p).GetInventory();
			GearSlot[] wornSlots = WornSlots;
			foreach (GearSlot slot in wornSlots)
			{
				Vector2i val = FirstPos(slot);
				ItemData itemAt = Inventory.GetItemAt(val.x, val.y);
				ItemData val2 = Worn(p, slot);
				if (val2 != itemAt)
				{
					if (val2 != null && inventory.ContainsItem(val2))
					{
						MoveIntoSlot(p, val2, val, itemAt);
					}
					else if (itemAt != null && !((Character)p).InAttack())
					{
						((Humanoid)p).EquipItem(itemAt, false);
					}
				}
			}
			SyncExtraUtilities(p);
		}

		private static void MoveIntoSlot(Player p, ItemData worn, Vector2i pos, ItemData previous)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			Inventory inventory = ((Humanoid)p).GetInventory();
			Vector2i gridPos = worn.m_gridPos;
			inventory.m_inventory.Remove(worn);
			if (previous != null)
			{
				Inventory.m_inventory.Remove(previous);
				Vector2i val = (Vector2i)((SlotFor(worn) == GearSlot.Utility) ? FreeExtraUtility() : new Vector2i(-1, -1));
				if (val.x >= 0)
				{
					previous.m_gridPos = val;
					Inventory.m_inventory.Add(previous);
				}
				else
				{
					previous.m_equipped = false;
					previous.m_gridPos = gridPos;
					inventory.m_inventory.Add(previous);
				}
			}
			worn.m_gridPos = pos;
			Inventory.m_inventory.Add(worn);
			inventory.Changed(false, false);
			Inventory.Changed(false, false);
		}

		private static Vector2i FreeExtraUtility()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: 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_004f: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			foreach (Vector2i item in PositionsOf(GearSlot.Utility))
			{
				if (!IsFirstUtility(item) && Inventory.GetItemAt(item.x, item.y) == null)
				{
					return item;
				}
			}
			return new Vector2i(-1, -1);
		}

		private static void SyncExtraUtilities(Player p)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			bool flag = false;
			List<ItemData> list = new List<ItemData>();
			foreach (Vector2i item in PositionsOf(GearSlot.Utility))
			{
				if (IsFirstUtility(item))
				{
					continue;
				}
				ItemData itemAt = Inventory.GetItemAt(item.x, item.y);
				if (itemAt != null && !((Humanoid)p).IsItemEquiped(itemAt))
				{
					list.Add(itemAt);
					if (!itemAt.m_equipped)
					{
						itemAt.m_equipped = true;
					}
					if (!ExtraUtilities.Contains(itemAt))
					{
						flag = true;
					}
				}
			}
			foreach (ItemData extraUtility in ExtraUtilities)
			{
				if (!list.Contains(extraUtility))
				{
					if (!((Humanoid)p).IsItemEquiped(extraUtility))
					{
						extraUtility.m_equipped = false;
					}
					flag = true;
				}
			}
			if (flag)
			{
				ExtraUtilities.Clear();
				ExtraUtilities.AddRange(list);
				((Humanoid)p).UpdateEquipmentStatusEffects();
				p.UpdateModifiers();
			}
		}

		public static void TakeOff(Player p, ItemData item, Inventory to)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)p == (Object)null) && item != null && Inventory.ContainsItem(item))
			{
				Vector2i val = to.FindEmptySlot(true);
				if (val.x < 0)
				{
					((Character)p).Message((MessageType)2, "$inventory_full", 0, (Sprite)null, false);
					return;
				}
				((Humanoid)p).UnequipItem(item, false);
				item.m_equipped = false;
				Inventory.m_inventory.Remove(item);
				item.m_gridPos = val;
				to.m_inventory.Add(item);
				Inventory.Changed(false, false);
				to.Changed(false, false);
				SyncExtraUtilities(p);
			}
		}

		private static void EmptyIntoInventory(Player p)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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)
			Inventory inventory = ((Humanoid)p).GetInventory();
			foreach (ItemData item in new List<ItemData>(Inventory.GetAllItems()))
			{
				Vector2i val = inventory.FindEmptySlot(true);
				if (val.x < 0)
				{
					break;
				}
				Inventory.m_inventory.Remove(item);
				if (!((Humanoid)p).IsItemEquiped(item))
				{
					item.m_equipped = false;
				}
				item.m_gridPos = val;
				inventory.m_inventory.Add(item);
			}
			Inventory.Changed(false, false);
			inventory.Changed(false, false);
			SyncExtraUtilities(p);
		}

		public static bool PrepareUpgrade(Player p, ItemData item)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			if (item == null || !Inventory.ContainsItem(item))
			{
				return true;
			}
			Inventory inventory = ((Humanoid)p).GetInventory();
			Vector2i val = inventory.FindEmptySlot(true);
			if (val.x < 0)
			{
				((Character)p).Message((MessageType)2, "Free an inventory slot to upgrade gear you're wearing", 0, (Sprite)null, false);
				return false;
			}
			Inventory.m_inventory.Remove(item);
			item.m_gridPos = val;
			inventory.m_inventory.Add(item);
			Inventory.Changed(false, false);
			inventory.Changed(false, false);
			return true;
		}

		public static string Label(GearSlot slot)
		{
			return slot switch
			{
				GearSlot.Helmet => "Head", 
				GearSlot.Cape => "Cape", 
				GearSlot.Chest => "Chest", 
				GearSlot.Trinket => "Trinket", 
				GearSlot.Legs => "Legs", 
				GearSlot.Utility => "Utility", 
				_ => "", 
			};
		}
	}
	internal static class PanelArt
	{
		private static readonly Color Wood = new Color(0.24f, 0.16f, 0.1f);

		private static readonly Color Edge = new Color(0.1f, 0.06f, 0.03f);

		private static readonly Color Brass = new Color(0.8f, 0.64f, 0.26f);

		public static Sprite Board(float width, float height, float top, float bottom)
		{
			//IL_016c: 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_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: 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_01b2: 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_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: 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)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Expected O, but got Unknown
			//IL_00b0: 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_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			float num = 128f / width;
			int num2 = Mathf.Max(16, Mathf.RoundToInt(height * num));
			Color[] array = (Color[])(object)new Color[128 * num2];
			for (int i = 0; i < num2; i++)
			{
				for (int j = 0; j < 128; j++)
				{
					float num3 = RoundedRectDistance((float)j + 0.5f, (float)i + 0.5f, 128, num2, 8f);
					if (!(num3 < 0f))
					{
						float num4 = Mathf.Sin((float)i * 0.9f + Mathf.Sin((float)j * 0.07f) * 3f) * 0.04f + (Hash(j, i) - 0.5f) * 0.06f;
						bool flag = i % 24 == 0;
						Color val = Wood * (1f + num4) * (flag ? 0.7f : 1f);
						if (num3 < 4f)
						{
							val = Color.Lerp(Edge, val, num3 / 4f);
						}
						else if (num3 < 5.5f)
						{
							val *= 1.25f;
						}
						val.a = Mathf.Clamp01(num3) * 0.94f;
						array[i * 128 + j] = val;
					}
				}
			}
			int num5 = 4;
			int num6 = 9;
			Vector2[] array2 = (Vector2[])(object)new Vector2[4]
			{
				new Vector2((float)num6, (float)num6),
				new Vector2((float)(128 - num6), (float)num6),
				new Vector2((float)num6, (float)(num2 - num6)),
				new Vector2((float)(128 - num6), (float)(num2 - num6))
			};
			foreach (Vector2 val2 in array2)
			{
				for (int l = (int)val2.y - num5; (float)l <= val2.y + (float)num5; l++)
				{
					for (int m = (int)val2.x - num5; (float)m <= val2.x + (float)num5; m++)
					{
						if (m >= 0 && l >= 0 && m < 128 && l < num2)
						{
							float num7 = Vector2.Distance(new Vector2((float)m, (float)l), val2);
							if (!(num7 > (float)num5))
							{
								Color val3 = Brass * (1.15f - num7 / (float)num5 * 0.5f);
								val3.a = 1f;
								array[l * 128 + m] = val3;
							}
						}
					}
				}
			}
			Texture2D val4 = new Texture2D(128, num2, (TextureFormat)4, false)
			{
				wrapMode = (TextureWrapMode)1,
				filterMode = (FilterMode)1
			};
			val4.SetPixels(array);
			val4.Apply();
			return Sprite.Create(val4, new Rect(0f, 0f, 128f, (float)num2), new Vector2(0.5f, 0.5f));
		}

		private static float RoundedRectDistance(float x, float y, int w, int h, float r)
		{
			float num = Mathf.Max(new float[3]
			{
				r - x,
				x - ((float)w - r),
				0f
			});
			float num2 = Mathf.Max(new float[3]
			{
				r - y,
				y - ((float)h - r),
				0f
			});
			float num3 = Mathf.Sqrt(num * num + num2 * num2);
			float result = Mathf.Min(Mathf.Min(x, (float)w - x), Mathf.Min(y, (float)h - y));
			if (!(num3 > 0f))
			{
				return result;
			}
			return r - num3;
		}

		private static float Hash(int x, int y)
		{
			int num = x * 374761393 + y * 668265263;
			return (float)(uint)(((num ^ (num >>> 13)) * 1274126177) & 0xFFFF) / 65535f;
		}
	}
	internal class PanelDragHandle : MonoBehaviour, IBeginDragHandler, IEventSystemHandler, IDragHandler, IEndDragHandler, IPointerClickHandler
	{
		public ExtraPanel Panel;

		private ExtraPanel _moving;

		private Canvas _canvas;

		private Vector2 _start;

		private Vector2 _total;

		private ExtraPanel _snapTarget;

		private string _snapSide;

		public void OnBeginDrag(PointerEventData eventData)
		{
			//IL_0008: 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_00a8: 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_00b3: Unknown result type (might be due to invalid IL or missing references)
			_moving = null;
			if ((int)eventData.button != 0 || ((Object)(object)InventoryGui.instance != (Object)null && (Object)(object)InventoryGui.instance.m_dragGo != (Object)null))
			{
				return;
			}
			if ((ZInput.GetKey((KeyCode)304, false) || ZInput.GetKey((KeyCode)303, false)) && Panel.DockTarget(out var _) != null)
			{
				Panel.Detach();
				Player localPlayer = Player.m_localPlayer;
				if (localPlayer != null)
				{
					((Character)localPlayer).Message((MessageType)1, "Panel disconnected", 0, (Sprite)null, false);
				}
			}
			_moving = Panel.GroupRoot();
			_canvas = ((Component)this).GetComponentInParent<Canvas>();
			_start = _moving.TopLeft();
			_total = Vector2.zero;
			_snapTarget = null;
		}

		public void OnDrag(PointerEventData eventData)
		{
			//IL_002c: 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_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			if (_moving != null)
			{
				float num = (((Object)(object)_canvas != (Object)null) ? _canvas.scaleFactor : 1f);
				_total += eventData.delta / num;
				_snapTarget = _moving.DragTo(_start + _total, out _snapSide);
			}
		}

		public void OnEndDrag(PointerEventData eventData)
		{
			if (_moving == null)
			{
				return;
			}
			_moving.Drop(_snapTarget, _snapSide);
			if (_snapTarget != null)
			{
				Player localPlayer = Player.m_localPlayer;
				if (localPlayer != null)
				{
					((Character)localPlayer).Message((MessageType)1, "Panels connected (Shift+drag to pull one off)", 0, (Sprite)null, false);
				}
			}
			_moving = null;
		}

		public void OnPointerClick(PointerEventData eventData)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			if ((int)eventData.button == 0 && eventData.clickCount == 2 && !eventData.dragging)
			{
				Panel.ResetLayout();
			}
		}
	}
	[HarmonyPatch(typeof(Player), "Load")]
	internal static class PlayerLoadPatch
	{
		private static void Postfix(Player __instance)
		{
			QuiverStore.Load(__instance);
			GearStore.Load(__instance);
			PouchStore.Load(__instance);
		}
	}
	[HarmonyPatch(typeof(Player), "Save")]
	internal static class PlayerSavePatch
	{
		private static void Prefix(Player __instance)
		{
			QuiverStore.Save(__instance);
			GearStore.Save(__instance);
			PouchStore.Save(__instance);
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "Awake")]
	internal static class InventoryGuiAwakePatch
	{
		private static void Postfix(InventoryGui __instance)
		{
			try
			{
				ExtraPanel.CreateAll(__instance);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Could not build the quiver/gear panels: " + ex));
			}
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "UpdateInventory")]
	internal static class InventoryGuiUpdatePatch
	{
		private static void Postfix(InventoryGui __instance, Player player)
		{
			ExtraPanel.UpdateAll(__instance, player);
		}
	}
	[HarmonyPatch(typeof(InventoryGrid), "DropItem")]
	internal static class InventoryGridDropPatch
	{
		private static bool Prefix(InventoryGrid __instance, Inventory fromInventory, ItemData item, Vector2i pos, ref bool __result)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			string text = Check(__instance.GetInventory(), fromInventory, item, pos);
			if (text == null)
			{
				return true;
			}
			Player localPlayer = Player.m_localPlayer;
			if (localPlayer != null)
			{
				((Character)localPlayer).Message((MessageType)2, text, 0, (Sprite)null, false);
			}
			__result = false;
			return false;
		}

		private static string Check(Inventory target, Inventory from, ItemData item, Vector2i pos)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: 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_0048: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
			Inventory inventory = QuiverStore.Inventory;
			Inventory inventory2 = GearStore.Inventory;
			Inventory inventory3 = PouchStore.Inventory;
			if (target == inventory && from != inventory && !QuiverStore.IsAmmo(item))
			{
				return "Only arrows and bolts fit in the quiver";
			}
			if (target == inventory2 && !GearStore.Accepts(pos, item))
			{
				return "That doesn't go in this slot";
			}
			if (target == inventory3 && !PouchStore.Accepts(pos, item))
			{
				if (!PouchStore.IsFoodRow(pos))
				{
					return "Only potions and meads go in these slots";
				}
				return "Only food goes in these slots";
			}
			ItemData itemAt = target.GetItemAt(pos.x, pos.y);
			if (itemAt == null || itemAt == item)
			{
				return null;
			}
			if (from == inventory && target != inventory && !QuiverStore.IsAmmo(itemAt))
			{
				return "Only arrows and bolts fit in the quiver";
			}
			if (from == inventory2 && !GearStore.Accepts(item.m_gridPos, itemAt))
			{
				return "That doesn't go in this slot";
			}
			if (from == inventory3 && !PouchStore.Accepts(item.m_gridPos, itemAt) && itemAt.m_shared.m_name != item.m_shared.m_name)
			{
				return "That doesn't go in this slot";
			}
			return null;
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "OnSelectedItem")]
	internal static class InventoryGuiSelectPatch
	{
		private static bool Prefix(InventoryGui __instance, InventoryGrid grid, ItemData item, Modifier mod, out bool __state)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Invalid comparison between Unknown and I4
			//IL_0192: 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_01a5: 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)
			__state = (Object)(object)__instance.m_dragGo != (Object)null && (__instance.m_dragInventory == GearStore.Inventory || (Object)(object)grid == (Object)(object)ExtraPanel.Gear?.Grid);
			Player localPlayer = Player.m_localPlayer;
			if (!Plugin.ModEnabled.Value || (Object)(object)localPlayer == (Object)null || (Object)(object)localPlayer != (Object)(object)QuiverStore.Owner || item == null || (Object)(object)__instance.m_dragGo != (Object)null || (int)mod != 2)
			{
				return true;
			}
			Inventory inventory = ((Humanoid)localPlayer).GetInventory();
			Inventory val = (((Object)(object)__instance.m_currentContainer != (Object)null) ? __instance.m_currentContainer.GetInventory() : null);
			if ((Object)(object)grid == (Object)(object)ExtraPanel.Gear?.Grid)
			{
				GearStore.TakeOff(localPlayer, item, val ?? inventory);
			}
			else if ((Object)(object)grid == (Object)(object)ExtraPanel.Quiver?.Grid || (Object)(object)grid == (Object)(object)ExtraPanel.Pouch?.Grid)
			{
				if (((Humanoid)localPlayer).IsItemEquiped(item))
				{
					((Humanoid)localPlayer).UnequipItem(item, false);
				}
				(val ?? inventory).MoveItemToThis(grid.GetInventory(), item);
			}
			else
			{
				if (!((Object)(object)grid == (Object)(object)__instance.m_playerGrid) || val != null || !Plugin.CtrlClickToQuiver.Value)
				{
					return true;
				}
				if (QuiverStore.IsAmmo(item))
				{
					QuiverStore.StoreFromInventory(localPlayer, item);
				}
				else if (!Plugin.PouchEnabled.Value || !PouchStore.StoreFromInventory(localPlayer, item))
				{
					if (!Plugin.GearEnabled.Value || GearStore.SlotFor(item) == GearSlot.None)
					{
						return true;
					}
					((Humanoid)localPlayer).EquipItem(item, true);
				}
			}
			__instance.m_moveItemEffects.Create(((Component)__instance).transform.position, Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID));
			return false;
		}

		private static void Postfix(bool __state)
		{
			Player localPlayer = Player.m_localPlayer;
			if (!__state || (Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			foreach (ItemData allItem in ((Humanoid)localPlayer).GetInventory().GetAllItems())
			{
				if (GearStore.SlotFor(allItem) != GearSlot.None && ((Humanoid)localPlayer).IsItemEquiped(allItem))
				{
					((Humanoid)localPlayer).UnequipItem(allItem, false);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Inventory), "GetTotalWeight")]
	internal static class InventoryWeightPatch
	{
		private static void Postfix(Inventory __instance, ref float __result)
		{
			if (Plugin.ModEnabled.Value && Plugin.CountWeight.Value && QuiverStore.IsOwnerInventory(__instance))
			{
				__result += QuiverStore.Inventory.GetTotalWeight() + GearStore.Inventory.GetTotalWeight() + PouchStore.Inventory.GetTotalWeight();
			}
		}
	}
	[HarmonyPatch(typeof(Inventory), "AddItem", new Type[] { typeof(ItemData) })]
	internal static class PickupTopUpPatch
	{
		private static bool Prefix(Inventory __instance, ItemData item, ref bool __result)
		{
			if (!Plugin.ModEnabled.Value || !Plugin.PickupTopUp.Value || item == null || !QuiverStore.IsOwnerInventory(__instance))
			{
				return true;
			}
			Inventory val = (QuiverStore.IsAmmo(item) ? QuiverStore.Inventory : ((Plugin.PouchEnabled.Value && (PouchStore.IsFood(item) || PouchStore.IsPotion(item))) ? PouchStore.Inventory : null));
			if (val == null || val.ContainsItem(item) || !QuiverStore.TopUp(val, item))
			{
				return true;
			}
			__result = true;
			return false;
		}
	}
	[HarmonyPatch(typeof(Inventory), "MoveInventoryToGrave")]
	internal static class GravePatch
	{
		private static void Postfix(Inventory __instance, Inventory original)
		{
			if (QuiverStore.IsOwnerInventory(original))
			{
				QuiverStore.MoveToGrave(__instance, QuiverStore.Inventory);
				QuiverStore.MoveToGrave(__instance, GearStore.Inventory);
				QuiverStore.MoveToGrave(__instance, PouchStore.Inventory);
			}
		}
	}
	[HarmonyPatch(typeof(Humanoid), "UnequipAllItems")]
	internal static class UnequipAllPatch
	{
		private static void Postfix(Humanoid __instance)
		{
			if ((Object)(object)__instance != (Object)(object)QuiverStore.Owner || GearStore.ExtraUtilities.Count == 0)
			{
				return;
			}
			foreach (ItemData extraUtility in GearStore.ExtraUtilities)
			{
				extraUtility.m_equipped = false;
			}
			GearStore.ExtraUtilities.Clear();
			__instance.UpdateEquipmentStatusEffects();
			QuiverStore.Owner.UpdateModifiers();
		}
	}
	[HarmonyPatch]
	internal static class AmmoPatches
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			yield return AccessTools.Method(typeof(Humanoid), "EquipItem", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(Attack), "FindAmmo", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(Attack), "EquipAmmoItem", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(Attack), "HaveAmmo", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(Attack), "UseAmmo", (Type[])null, (Type[])null);
		}

		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> code)
		{
			MethodInfo contains = AccessTools.Method(typeof(Inventory), "ContainsItem", (Type[])null, (Type[])null);
			MethodInfo getAmmo = AccessTools.Method(typeof(Inventory), "GetAmmoItem", (Type[])null, (Type[])null);
			MethodInfo remove = AccessTools.Method(typeof(Inventory), "RemoveItem", new Type[2]
			{
				typeof(ItemData),
				typeof(int)
			}, (Type[])null);
			foreach (CodeInstruction item in code)
			{
				if (CodeInstructionExtensions.Calls(item, contains))
				{
					Redirect(item, "Contains");
				}
				else if (CodeInstructionExtensions.Calls(item, getAmmo))
				{
					Redirect(item, "GetAmmoItem");
				}
				else if (CodeInstructionExtensions.Calls(item, remove))
				{
					Redirect(item, "RemoveItem");
				}
				yield return item;
			}
		}

		private static void Redirect(CodeInstruction ins, string method)
		{
			ins.opcode = OpCodes.Call;
			ins.operand = AccessTools.Method(typeof(QuiverStore), method, (Type[])null, (Type[])null);
		}
	}
	[HarmonyPatch(typeof(Humanoid), "UpdateEquipmentStatusEffects")]
	internal static class ExtraUtilityEffectsPatch
	{
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> code)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Expected O, but got Unknown
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Expected O, but got Unknown
			CodeMatcher val = new CodeMatcher(code, (ILGenerator)null);
			val.MatchStartForward((CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Newobj, (object)null, (string)null)
			}).Advance(1);
			CodeInstruction val2 = LoadFromStore(val.Instruction);
			val.MatchStartForward((CodeMatch[])(object)new CodeMatch[2]
			{
				new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(Humanoid), "m_equipmentStatusEffects"), (string)null)
			});
			if (val.IsInvalid || val2 == null)
			{
				Plugin.Log.LogError((object)"Could not hook equipment status effects; extra utility slots won't apply their effects.");
				return code;
			}
			List<Label> list = CodeInstructionExtensions.ExtractLabels(val.Instruction);
			val.Insert((CodeInstruction[])(object)new CodeInstruction[3]
			{
				CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Ldarg_0, (object)null), (IEnumerable<Label>)list),
				val2,
				new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(ExtraUtilityEffectsPatch), "AddExtraEffects", (Type[])null, (Type[])null))
			});
			return val.InstructionEnumeration();
		}

		private static CodeInstruction LoadFromStore(CodeInstruction store)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Expected O, but got Unknown
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Expected O, but got Unknown
			if (store.opcode == OpCodes.Stloc_0)
			{
				return new CodeInstruction(OpCodes.Ldloc_0, (object)null);
			}
			if (store.opcode == OpCodes.Stloc_1)
			{
				return new CodeInstruction(OpCodes.Ldloc_1, (object)null);
			}
			if (store.opcode == OpCodes.Stloc_2)
			{
				return new CodeInstruction(OpCodes.Ldloc_2, (object)null);
			}
			if (store.opcode == OpCodes.Stloc_3)
			{
				return new CodeInstruction(OpCodes.Ldloc_3, (object)null);
			}
			if (store.opcode == OpCodes.Stloc_S || store.opcode == OpCodes.Stloc)
			{
				return new CodeInstruction(OpCodes.Ldloc, store.operand);
			}
			return null;
		}

		private static void AddExtraEffects(Humanoid humanoid, HashSet<StatusEffect> effects)
		{
			if ((Object)(object)humanoid != (Object)(object)QuiverStore.Owner)
			{
				return;
			}
			foreach (ItemData extraUtility in GearStore.ExtraUtilities)
			{
				if ((Object)(object)extraUtility.m_shared.m_equipStatusEffect != (Object)null)
				{
					effects.Add(extraUtility.m_shared.m_equipStatusEffect);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Player), "UpdateModifiers")]
	internal static class ExtraUtilityModifiersPatch
	{
		private static void Postfix(Player __instance)
		{
			if ((Object)(object)__instance != (Object)(object)QuiverStore.Owner || Player.s_equipmentModifierSourceFields == null)
			{
				return;
			}
			foreach (ItemData extraUtility in GearStore.ExtraUtilities)
			{
				for (int i = 0; i < __instance.m_equipmentModifierValues.Length; i++)
				{
					__instance.m_equipmentModifierValues[i] += (float)Player.s_equipmentModifierSourceFields[i].GetValue(extraUtility.m_shared);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Humanoid), "GetEquipmentWeight")]
	internal static class ExtraUtilityWeightPatch
	{
		private static void Postfix(Humanoid __instance, ref float __result)
		{
			if ((Object)(object)__instance != (Object)(object)QuiverStore.Owner)
			{
				return;
			}
			foreach (ItemData extraUtility in GearStore.ExtraUtilities)
			{
				__result += extraUtility.m_shared.m_weight;
			}
		}
	}
	[HarmonyPatch(typeof(Inventory), "GetWornItems")]
	internal static class RepairPatch
	{
		private static void Postfix(Inventory __instance, List<ItemData> worn)
		{
			if (QuiverStore.IsOwnerInventory(__instance))
			{
				GearStore.Inventory.GetWornItems(worn);
			}
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "UpdateRecipeList")]
	internal static class UpgradeListPatch
	{
		internal static bool Active;

		private static void Prefix()
		{
			Active = true;
		}

		private static void Finalizer()
		{
			Active = false;
		}
	}
	[HarmonyPatch(typeof(Inventory), "GetAllItems", new Type[]
	{
		typeof(string),
		typeof(List<ItemData>)
	})]
	internal static class UpgradeItemsPatch
	{
		private static void Postfix(Inventory __instance, string name, List<ItemData> items)
		{
			if (!UpgradeListPatch.Active || !QuiverStore.IsOwnerInventory(__instance))
			{
				return;
			}
			foreach (ItemData allItem in GearStore.Inventory.GetAllItems())
			{
				if (allItem.m_shared.m_name == name)
				{
					items.Add(allItem);
				}
			}
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "DoCrafting")]
	internal static class UpgradeCraftPatch
	{
		private static bool Prefix(InventoryGui __instance, Player player)
		{
			return GearStore.PrepareUpgrade(player, __instance.m_craftUpgradeItem);
		}
	}
	[HarmonyPatch(typeof(ZInput), "GetButtonDown")]
	internal static class VanillaKeyPatch
	{
		private static bool Prefix(string name, ref bool __result)
		{
			bool num;
			switch (name)
			{
			case "Sit":
			case "ToggleWalk":
			case "AutoPickup":
				num = PouchHud.QuickKeyPressed();
				goto IL_0043;
			case "Hide":
				num = RadialMenu.SuppressHide;
				goto IL_0043;
			default:
				{
					return true;
				}
				IL_0043:
				if (num)
				{
					__result = false;
					return false;
				}
				goto default;
			}
		}
	}
	[HarmonyPatch(typeof(Player), "SetMouseLook")]
	internal static class MouseLookPatch
	{
		private static void Prefix(ref Vector2 mouseLook)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			if (RadialMenu.IsOpen)
			{
				mouseLook = Vector2.zero;
			}
		}
	}
	[BepInPlugin("supermans.quiver", "Supermans Quiver", "2.1.1")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "supermans.quiver";

		public const string Name = "Supermans Quiver";

		public const string Version = "2.1.1";

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> ModEnabled;

		internal static ConfigEntry<bool> CountWeight;

		internal static ConfigEntry<bool> AutoRefill;

		internal static ConfigEntry<bool> PickupTopUp;

		internal static ConfigEntry<bool> CtrlClickToQuiver;

		internal static ConfigEntry<bool> DropOnDeath;

		internal static ConfigEntry<KeyboardShortcut> RadialKey;

		internal static ConfigEntry<float> RadialSensitivity;

		internal static ConfigEntry<float> RadialScale;

		internal static ConfigEntry<bool> GearEnabled;

		internal static ConfigEntry<int> UtilitySlots;

		internal static ConfigEntry<bool> PouchEnabled;

		internal static readonly ConfigEntry<KeyCode>[] PouchKeys = new ConfigEntry<KeyCode>[6];

		internal static ConfigEntry<bool> ShowHud;

		internal static ConfigEntry<float> HudY;

		internal static ConfigEntry<string> QuiverDock;

		internal static ConfigEntry<string> GearDock;

		internal static ConfigEntry<string> PouchDock;

		internal static ConfigEntry<float> QuiverX;

		internal static ConfigEntry<float> QuiverY;

		internal static ConfigEntry<float> GearX;

		internal static ConfigEntry<float> GearY;

		internal static ConfigEntry<float> PouchX;

		internal static ConfigEntry<float> PouchY;

		private Harmony _harmony;

		private FileSystemWatcher _configWatcher;

		private volatile bool _configChanged;

		private float _configReloadAt = -1f;

		private void Awake()
		{
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Expected O, but got Unknown
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Expected O, but got Unknown
			//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Expected O, but got Unknown
			//IL_044a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0454: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			ModEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "Enabled", true, "Master switch for the whole mod.");
			CountWeight = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "CountWeight", true, "Items in the quiver and gear slots count toward your carry weight, like they would in your inventory.");
			AutoRefill = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "AutoRefill", true, "When the equipped arrow stack runs out, keep shooting with the next stack in the quiver (same arrow first).");
			PickupTopUp = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "PickupTopUp", true, "Arrows, food and potions you pick up top up matching stacks in the quiver and quick slots first.");
			CtrlClickToQuiver = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "CtrlClickToQuiver", true, "Ctrl+click arrows (or armor) in your inventory with no chest open to put them in the quiver (or gear slots) instead of dropping them.");
			DropOnDeath = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "DropOnDeath", true, "On: the quiver and gear slots go into your tombstone like the rest of your inventory. Off: you keep them.");
			RadialKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("2 - Radial menu", "RadialKey", new KeyboardShortcut((KeyCode)114, (KeyCode[])(object)new KeyCode[1] { (KeyCode)304 }), "Hold to open the arrow wheel, move the mouse toward an arrow, release to equip it.");
			RadialSensitivity = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Radial menu", "MouseSensitivity", 1f, new ConfigDescription("How far the mouse has to move to pick a slot. Higher = less movement needed.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.2f, 5f), Array.Empty<object>()));
			RadialScale = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Radial menu", "Scale", 1f, new ConfigDescription("Size of the arrow wheel.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 2f), Array.Empty<object>()));
			QuiverDock = ((BaseUnityPlugin)this).Config.Bind<string>("3 - Panel layout", "QuiverConnectedTo", "", "What this panel is connected to, like \"Quiver:Right\" (Right, Left, Below or Above another panel). Empty = not connected; then X/Y are measured from the top-right corner of the inventory. Set by dragging panels in the inventory screen.");
			QuiverX = ((BaseUnityPlugin)this).Config.Bind<float>("3 - Panel layout", "QuiverX", 12f, "Offset from where it's connected (or from the inventory's top-right corner). Set by dragging.");
			QuiverY = ((BaseUnityPlugin)this).Config.Bind<float>("3 - Panel layout", "QuiverY", 0f, "Offset from where it's connected (or from the inventory's top-right corner). Set by dragging.");
			GearDock = ((BaseUnityPlugin)this).Config.Bind<string>("3 - Panel layout", "GearConnectedTo", "Quiver:Right", "What this panel is connected to, like \"Quiver:Right\" (Right, Left, Below or Above another panel). Empty = not connected; then X/Y are measured from the top-right corner of the inventory. Set by dragging panels in the inventory screen.");
			GearX = ((BaseUnityPlugin)this).Config.Bind<float>("3 - Panel layout", "GearX", 0f, "Offset from where it's connected (or from the inventory's top-right corner). Set by dragging.");
			GearY = ((BaseUnityPlugin)this).Config.Bind<float>("3 - Panel layout", "GearY", 0f, "Offset from where it's connected (or from the inventory's top-right corner). Set by dragging.");
			PouchDock = ((BaseUnityPlugin)this).Config.Bind<string>("3 - Panel layout", "QuickSlotsConnectedTo", "Gear:Below", "What this panel is connected to, like \"Quiver:Right\" (Right, Left, Below or Above another panel). Empty = not connected; then X/Y are measured from the top-right corner of the inventory. Set by dragging panels in the inventory screen.");
			PouchX = ((BaseUnityPlugin)this).Config.Bind<float>("3 - Panel layout", "QuickSlotsX", 0f, "Offset from where it's connected (or from the inventory's top-right corner). Set by dragging.");
			PouchY = ((BaseUnityPlugin)this).Config.Bind<float>("3 - Panel layout", "QuickSlotsY", 0f, "Offset from where it's connected (or from the inventory's top-right corner). Set by dragging.");
			GearEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("4 - Gear panel", "Enabled", true, "Gear slots for helmet, chest, legs, cape, trinket and utility items next to the inventory. Gear you equip moves into these slots and frees up your inventory. Turning this off moves the gear back into your inventory.");
			UtilitySlots = ((BaseUnityPlugin)this).Config.Bind<int>("4 - Gear panel", "UtilitySlots", 1, new ConfigDescription("How many utility items (Megingjord belt, Demister wisp, Wishbone, ...) you can wear at once. 1 is vanilla. Changes apply right away; items in removed slots go back to your inventory.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 4), Array.Empty<object>()));
			UtilitySlots.SettingChanged += delegate
			{
				GearStore.Relayout(Player.m_localPlayer);
			};
			PouchEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("5 - Quick slots", "Enabled", true, "3 food and 3 potion slots next to the inventory, used with their own keys without opening the inventory.");
			KeyCode[] array = new KeyCode[6];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			KeyCode[] array2 = (KeyCode[])(object)array;
			for (int num = 0; num < 6; num++)
			{
				string text = ((num < 3) ? ("Food" + (num + 1) + "Key") : ("Potion" + (num - 2) + "Key"));
				PouchKeys[num] = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("5 - Quick slots", text, array2[num], "Eats/drinks what's in this slot. Vanilla actions on the same key (X sit, C walk, V auto-pickup) are skipped while it's used.");
			}
			ShowHud = ((BaseUnityPlugin)this).Config.Bind<bool>("5 - Quick slots", "ShowHud", true, "Show the quick slots at the bottom of the screen while playing.");
			HudY = ((BaseUnityPlugin)this).Config.Bind<float>("5 - Quick slots", "HudY", 150f, "Distance of the quick slot bar from the bottom of the screen (at 1080p).");
			RemoveOldSettings();
			WatchConfigFile();
			((Component)this).gameObject.AddComponent<RadialMenu>();
			((Component)this).gameObject.AddComponent<PouchHud>();
			((Component)this).gameObject.AddComponent<SlotLabels>();
			_harmony = new Harmony("supermans.quiver");
			_harmony.PatchAll(typeof(Plugin).Assembly);
			Log.LogInfo((object)"Supermans Quiver 2.1.1 loaded");
		}

		private void RemoveOldSettings()
		{
			try
			{
				if (!(AccessTools.Property(typeof(ConfigFile), "OrphanedEntries")?.GetValue(((BaseUnityPlugin)this).Config, null) is Dictionary<ConfigDefinition, string> dictionary))
				{
					return;
				}
				List<ConfigDefinition> list = new List<ConfigDefinition>();
				foreach (ConfigDefinition key in dictionary.Keys)
				{
					if (key.Section == "3 - Quiver panel")
					{
						list.Add(key);
					}
				}
				if (list.Count == 0)
				{
					return;
				}
				foreach (ConfigDefinition item in list)
				{
					dictionary.Remove(item);
				}
				((BaseUnityPlugin)this).Config.Save();
				Log.LogInfo((object)"Removed old \"3 - Quiver panel\" settings (use QuiverX/QuiverY under \"3 - Panel layout\")");
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Couldn't remove old settings: " + ex.Message));
			}
		}

		private void WatchConfigFile()
		{
			try
			{
				_configWatcher = new FileSystemWatcher(Path.GetDirectoryName(((BaseUnityPlugin)this).Config.ConfigFilePath), Path.GetFileName(((BaseUnityPlugin)this).Config.ConfigFilePath));
				_configWatcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.Size | NotifyFilters.LastWrite;
				_configWatcher.Changed += OnConfigFileChanged;
				_configWatcher.Created += OnConfigFileChanged;
				_configWatcher.Renamed += OnConfigFileChanged;
				_configWatcher.EnableRaisingEvents = true;
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Can't watch the config file, edits apply after a restart: " + ex.Message));
			}
		}

		private void OnConfigFileChanged(object sender, FileSystemEventArgs e)
		{
			_configChanged = true;
		}

		private void ReloadConfigIfChanged()
		{
			if (_configChanged)
			{
				_configChanged = false;
				_configReloadAt = Time.unscaledTime + 0.5f;
			}
			if (_configReloadAt < 0f || Time.unscaledTime < _configReloadAt)
			{
				return;
			}
			_configReloadAt = -1f;
			try
			{
				((BaseUnityPlugin)this).Config.Reload();
				Log.LogInfo((object)"Config reloaded from file");
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Config reload failed: " + ex.Message));
			}
		}

		private void Update()
		{
			ReloadConfigIfChanged();
			ExtraPanel.LateLayout();
			if (ModEnabled.Value)
			{
				Player localPlayer = Player.m_localPlayer;
				GearStore.Sync(localPlayer);
				PouchHud.HandleKeys(localPlayer);
			}
		}

		private void OnDestroy()
		{
			_configWatcher?.Dispose();
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		internal static bool IsTyping()
		{
			if ((!((Object)(object)Chat.instance != (Object)null) || !Chat.instance.HasFocus()) && !Console.IsVisible() && !TextInput.IsVisible() && !Minimap.InTextInput())
			{
				if ((Object)(object)TextViewer.instance != (Object)null)
				{
					return TextViewer.instance.IsVisible();
				}
				return false;
			}
			return true;
		}
	}
	internal class PouchHud : MonoBehaviour
	{
		private Texture2D _box;

		private GUIStyle _key;

		private GUIStyle _count;

		private static bool CanUse(Player player)
		{
			if (Plugin.PouchEnabled.Value && (Object)(object)player != (Object)null && (Object)(object)player == (Object)(object)QuiverStore.Owner && !((Character)player).IsDead() && !Plugin.IsTyping() && !Menu.IsVisible() && !Minimap.IsOpen() && !RadialMenu.IsOpen)
			{
				return !StoreGui.IsVisible();
			}
			return false;
		}

		public static void HandleKeys(Player player)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			if (ZInput.instance == null || !CanUse(player))
			{
				return;
			}
			for (int i = 0; i < 6; i++)
			{
				KeyCode val = PouchStore.KeyFor(i);
				if ((int)val != 0 && ZInput.GetKeyDown(val, false))
				{
					PouchStore.Use(player, i);
				}
			}
		}

		public static bool QuickKeyPressed()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			if (!Plugin.ModEnabled.Value || ZInput.instance == null || !CanUse(Player.m_localPlayer))
			{
				return false;
			}
			for (int i = 0; i < 6; i++)
			{
				KeyCode val = PouchStore.KeyFor(i);
				if ((int)val != 0 && ZInput.GetKeyDown(val, false))
				{
					return true;
				}
			}
			return false;
		}

		private void OnGUI()
		{
			//IL_0107: 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_0124: 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_0213: 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_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if (!Plugin.ModEnabled.Value || !Plugin.ShowHud.Value || !CanUse(localPlayer) || InventoryGui.IsVisible() || (Object)(object)Hud.instance == (Object)null || Hud.instance.m_userHidden || PouchStore.Inventory.NrOfItems() == 0)
			{
				return;
			}
			Init();
			float num = (float)Screen.height / 1080f;
			float num2 = 54f * num;
			float num3 = 6f * num;
			float num4 = 22f * num;
			float num5 = num2 * 6f + num3 * 4f + num4;
			float num6 = ((float)Screen.width - num5) * 0.5f;
			float num7 = (float)Screen.height - Plugin.HudY.Value * num - num2;
			_key.fontSize = Mathf.RoundToInt(13f * num);
			_count.fontSize = Mathf.RoundToInt(13f * num);
			Rect val = default(Rect);
			for (int i = 0; i < 6; i++)
			{
				((Rect)(ref val))..ctor(num6, num7, num2, num2);
				ItemData slot = PouchStore.GetSlot(i);
				Color color = GUI.color;
				GUI.color = ((slot != null) ? new Color(0f, 0f, 0f, 0.6f) : new Color(0f, 0f, 0f, 0.3f));
				GUI.DrawTexture(val, (Texture)(object)_box);
				GUI.color = color;
				if (slot != null)
				{
					DrawSprite(slot.GetIcon(), new Rect(((Rect)(ref val)).x + num2 * 0.12f, ((Rect)(ref val)).y + num2 * 0.12f, num2 * 0.76f, num2 * 0.76f));
					Shadowed(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y, ((Rect)(ref val)).width - 3f * num, ((Rect)(ref val)).height - 1f * num), slot.m_stack.ToString(), _count);
				}
				Shadowed(new Rect(((Rect)(ref val)).x + 3f * num, ((Rect)(ref val)).y + 1f * num, ((Rect)(ref val)).width, ((Rect)(ref val)).height), SlotLabels.KeyName(PouchStore.KeyFor(i)), _key);
				num6 += num2 + ((i == 2) ? num4 : num3);
			}
		}

		private void Init()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0024: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			//IL_0076: 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_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Expected O, but got Unknown
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_box != (Object)null))
			{
				_box = new Texture2D(1, 1);
				_box.SetPixel(0, 0, Color.white);
				_box.Apply();
				_key = new GUIStyle(GUI.skin.label)
				{
					alignment = (TextAnchor)0,
					fontStyle = (FontStyle)1
				};
				_key.normal.textColor = new Color(1f, 0.85f, 0.5f);
				_count = new GUIStyle(GUI.skin.label)
				{
					alignment = (TextAnchor)8,
					fontStyle = (FontStyle)1
				};
				_count.normal.textColor = Color.white;
			}
		}

		private static void DrawSprite(Sprite sprite, Rect rect)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)sprite == (Object)null))
			{
				Texture texture = (Texture)(object)sprite.texture;
				Rect textureRect = sprite.textureRect;
				GUI.DrawTextureWithTexCoords(rect, texture, new Rect(((Rect)(ref textureRect)).x / (float)texture.width, ((Rect)(ref textureRect)).y / (float)texture.height, ((Rect)(ref textureRect)).width / (float)texture.width, ((Rect)(ref textureRect)).height / (float)texture.height));
			}
		}

		private static void Shadowed(Rect rect, string text, GUIStyle style)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			Color textColor = style.normal.textColor;
			style.normal.textColor = new Color(0f, 0f, 0f, 0.85f);
			GUI.Label(new Rect(((Rect)(ref rect)).x + 1f, ((Rect)(ref rect)).y + 1f, ((Rect)(ref rect)).width, ((Rect)(ref rect)).height), text, style);
			style.normal.textColor = textColor;
			GUI.Label(rect, text, style);
		}
	}
	internal static class PouchStore
	{
		public const int Columns = 3;

		private const string SaveKey = "supermans.pouch";

		public static Inventory Inventory { get; private set; } = NewInventory();

		private static Inventory NewInventory()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Expected O, but got Unknown
			return new Inventory("Pouch", (Sprite)null, 3, 2);
		}

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

		public static bool IsPotion(ItemData item)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Invalid comparison between Unknown and I4
			if (item != null && (int)item.m_shared.m_itemType == 2)
			{
				return !IsFood(item);
			}
			return false;
		}

		public static bool IsFoodRow(Vector2i pos)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return pos.y == 0;
		}

		public static bool Accepts(Vector2i pos, ItemData item)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			if (pos.x >= 0 && pos.x < 3)
			{
				if (pos.y != 0)
				{
					if (pos.y == 1)
					{
						return IsPotion(item);
					}
					return false;
				}
				return IsFood(item);
			}
			return false;
		}

		public static ItemData GetSlot(int index)
		{
			return Inventory.GetItemAt(index % 3, index / 3);
		}

		public static KeyCode KeyFor(int index)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			return Plugin.PouchKeys[index].Value;
		}

		public static void Load(Player player)
		{
			Inventory = NewInventory();
			SaveData.Load(player, "supermans.pouch", Inventory);
		}

		public static void Save(Player player)
		{
			if ((Object)(object)player == (Object)(object)QuiverStore.Owner)
			{
				SaveData.Save(player, "supermans.pouch", Inventory);
			}
		}

		public static void Use(Player player, int index)
		{
			Use(player, GetSlot(index));
		}

		public static void Use(Player player, ItemData item)
		{
			if (!((Object)(object)player == (Object)null) && item != null && Inventory.ContainsItem(item))
			{
				((Humanoid)player).UseItem(Inventory, item, true);
			}
		}

		public static bool StoreFromInventory(Player player, ItemData item)
		{
			if (!IsFood(item) && !IsPotion(item))
			{
				return false;
			}
			Inventory inventory = ((Humanoid)player).GetInventory();
			int num = ((!IsFood(item)) ? 1 : 0);
			for (int i = 0; i < 3; i++)
			{
				if (item.m_stack <= 0)
				{
					break;
				}
				ItemData itemAt = Inventory.GetItemAt(i, num);
				if (itemAt != null && !(itemAt.m_shared.m_name != item.m_shared.m_name) && itemAt.m_quality == item.m_quality)
				{
					int num2 = Mathf.Min(itemAt.m_shared.m_maxStackSize - itemAt.m_stack, item.m_stack);
					if (num2 > 0)
					{
						Inventory.MoveItemToThis(inventory, item, num2, i, num);
					}
				}
			}
			for (int j = 0; j < 3; j++)
			{
				if (!inventory.ContainsItem(item))
				{
					break;
				}
				if (Inventory.GetItemAt(j, num) == null)
				{
					Inventory.MoveItemToThis(inventory, item, item.m_stack, j, num);
				}
			}
			if (inventory.ContainsItem(item))
			{
				((Character)player).Message((MessageType)2, IsFood(item) ? "Food slots are full" : "Potion slots are full", 0, (Sprite)null, false);
			}
			return true;
		}

		public static string Label(Vector2i pos)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			if (!IsFoodRow(pos))
			{
				return "Potion";
			}
			return "Food";
		}
	}
	internal static class QuiverArt
	{
		private static readonly Color Leather = new Color(0.42f, 0.26f, 0.14f);

		private static readonly Color Outline = new Color(0.13f, 0.08f, 0.04f);

		private static readonly Color Strap = new Color(0.22f, 0.13f, 0.07f);

		private static readonly Color Stitch = new Color(0.8f, 0.66f, 0.44f);

		private static readonly Color Brass = new Color(0.8f, 0.64f, 0.26f);

		private static readonly Color Shaft = new Color(0.58f, 0.44f, 0.28f);

		private static readonly Color[] Feathers = (Color[])(object)new Color[4]
		{
			new Color(0.72f, 0.16f, 0.12f),
			new Color(0.9f, 0.88f, 0.82f),
			new Color(0.3f, 0.3f, 0.32f),
			new Color(0.72f, 0.16f, 0.12f)
		};

		public static Sprite Create(float width, float height, float topArea, float bottomPad)
		{
			//IL_03d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03db: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0408: Unknown result type (might be due to invalid IL or missing references)
			//IL_0417: Unknown result type (might be due to invalid IL or missing references)
			//IL_0421: Expected O, but got Unknown
			//IL_00b3: 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_03b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: 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_017b: 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_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: 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_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_037d: Unknown result type (might be due to invalid IL or missing references)
			//IL_035c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0376: Unknown result type (might be due to invalid IL or missing references)
			float num = 128f / width;
			int num2 = Mathf.RoundToInt(height * num);
			int num3 = num2 - Mathf.RoundToInt(topArea * num) + 6;
			int num4 = 4;
			int num5 = 123;
			float radius = (float)(num5 - num4) * 0.5f;
			Color[] array = (Color[])(object)new Color[128 * num2];
			for (int i = 0; i < num2; i++)
			{
				for (int j = 0; j < 128; j++)
				{
					if (i > num3)
					{
						continue;
					}
					float num6 = TubeDistance(j, i, num4, num5, num3, radius);
					if (num6 < 0f)
					{
						continue;
					}
					float num7 = (float)(j - num4) / (float)(num5 - num4);
					float num8 = 0.62f + 0.48f * Mathf.Sin(num7 * (float)Math.PI);
					float num9 = (Hash(j, i) - 0.5f) * 0.08f;
					Color val = Leather * (num8 + num9);
					int num10 = Mathf.RoundToInt((float)num3 * 0.3f);
					int num11 = Mathf.RoundToInt((float)num3 * 0.68f);
					if (Mathf.Abs(i - num10) < 7 || Mathf.Abs(i - num11) < 7)
					{
						val = Strap * (num8 + num9);
						if (Mathf.Abs(i - num10) == 6 || Mathf.Abs(i - num11) == 6)
						{
							val *= 1.4f;
						}
						if (j > num5 - 22 && j < num5 - 8)
						{
							val = Brass * (0.8f + 0.