Decompiled source of Backpack v1.0.0

Backpack.dll

Decompiled 13 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Backpack.Client;
using Backpack.Game;
using Backpack.Net;
using Backpack.Server;
using Backpack.UI;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Mirror;
using MyBox;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UIElements;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("Digger.Core")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Backpack")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("A backpack on the emote wheel (hold B): 2 slots to start, up to 12 bought with gold in the lobby shop. Drag items in and out; it empties when the run ends. Works with or without the mod on the host.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+ada79418f154c2c643367dff18e627a7e793bbd6")]
[assembly: AssemblyProduct("Backpack")]
[assembly: AssemblyTitle("Backpack")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.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 Backpack
{
	public static class BackpackApi
	{
		public const int Version = 1;

		public static event Action LocalChanged
		{
			add
			{
				BackpackClient.Changed += value;
			}
			remove
			{
				BackpackClient.Changed -= value;
			}
		}

		public static bool TryGetItems(FirstPersonController player, List<(int slot, string itemId, int count)> into)
		{
			try
			{
				into?.Clear();
				PlayerBackpack playerBackpack = HostBackpack(player);
				if (playerBackpack == null || into == null)
				{
					return false;
				}
				for (int i = 0; i < playerBackpack.Slots; i++)
				{
					if (!playerBackpack.IsEmpty(i))
					{
						into.Add((i, playerBackpack.Ids[i], playerBackpack.Counts[i]));
					}
				}
				return true;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Backpack: erro em BackpackApi.TryGetItems: " + ex.Message));
				return false;
			}
		}

		public static bool TryRemove(FirstPersonController player, int slot, string itemId, int count)
		{
			try
			{
				PlayerBackpack playerBackpack = HostBackpack(player);
				if (playerBackpack == null || !BackpackOps.RemoveExact(playerBackpack, slot, itemId, count))
				{
					return false;
				}
				playerBackpack.Dirty = true;
				Plugin.Log.LogInfo((object)$"Backpack: {playerBackpack.Name} teve {count}x {itemId} tirado da mochila por outro mod.");
				return true;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Backpack: erro em BackpackApi.TryRemove: " + ex.Message));
				return false;
			}
		}

		public static bool TryGetLocalItems(List<(int slot, string itemId, int count)> into)
		{
			try
			{
				into?.Clear();
				if (into == null || !BackpackClient.HasState || LocalBackpack.Active)
				{
					return false;
				}
				BackpackStateSnapshot(into);
				return true;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Backpack: erro em BackpackApi.TryGetLocalItems: " + ex.Message));
				return false;
			}
		}

		private static PlayerBackpack HostBackpack(FirstPersonController player)
		{
			if (!NetworkServer.active || (Object)(object)player == (Object)null || (Object)(object)BackpackServer.Instance == (Object)null)
			{
				return null;
			}
			return BackpackServer.Instance.FindFor(player);
		}

		private static void BackpackStateSnapshot(List<(int slot, string itemId, int count)> into)
		{
			BackpackStateMsg state = BackpackClient.State;
			if (state.ItemIds == null || state.Counts == null)
			{
				return;
			}
			int num = Math.Min(state.Slots, Math.Min(state.ItemIds.Length, state.Counts.Length));
			for (int i = 0; i < num; i++)
			{
				if (!string.IsNullOrEmpty(state.ItemIds[i]) && state.Counts[i] > 0)
				{
					into.Add((i, state.ItemIds[i], state.Counts[i]));
				}
			}
		}
	}
	[BepInPlugin("catedralemchamas.stonewards.backpack", "Backpack", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		internal const int BaseSlots = 2;

		internal const int MaxSlots = 12;

		internal const int FirstSlotPrice = 200;

		internal const int SlotPriceStep = 150;

		internal const int FirstInventorySlot = 2;

		internal static readonly bool VerboseLog;

		private Harmony _harmony;

		internal static int SlotPrice(int slot)
		{
			return 200 + 150 * (Math.Max(3, slot) - 3);
		}

		internal static void Verbose(string text)
		{
			if (VerboseLog)
			{
				Log.LogInfo((object)text);
			}
		}

		private void Awake()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			BackpackSave.Load();
			BackpackNet.RegisterSerializers();
			_harmony = new Harmony("catedralemchamas.stonewards.backpack");
			PatchEachClass();
			((Component)this).gameObject.AddComponent<BackpackServer>();
			((Component)this).gameObject.AddComponent<BackpackClient>();
			((Component)this).gameObject.AddComponent<BackpackWindow>();
			((Component)this).gameObject.AddComponent<InputGuard>();
			((Component)this).gameObject.AddComponent<QuickStore>();
			Log.LogInfo((object)string.Format("{0} v{1} carregado. {2} espaços na mochila.", "Backpack", "1.0.0", BackpackSave.Slots));
		}

		private void PatchEachClass()
		{
			Type[] typesFromAssembly = AccessTools.GetTypesFromAssembly(Assembly.GetExecutingAssembly());
			foreach (Type type in typesFromAssembly)
			{
				if (type.GetCustomAttributes(typeof(HarmonyPatch), inherit: false).Length != 0)
				{
					try
					{
						_harmony.CreateClassProcessor(type).Patch();
					}
					catch (Exception ex)
					{
						Log.LogError((object)("Backpack: não deu para aplicar " + type.Name + " (o jogo mudou?): " + ex.GetBaseException().Message));
					}
				}
			}
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	internal static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "catedralemchamas.stonewards.backpack";

		public const string PLUGIN_NAME = "Backpack";

		public const string PLUGIN_VERSION = "1.0.0";

		public const string PLUGIN_AUTHOR = "CatedralEmChamas";
	}
}
namespace Backpack.UI
{
	internal class BackpackWindow : MonoBehaviour
	{
		private enum Side : byte
		{
			None,
			Backpack,
			Inventory
		}

		public static BackpackWindow Instance;

		private const int Columns = 6;

		private const float SlotSize = 80f;

		private const float Gap = 8f;

		private const float PanelWidth = 620f;

		private const float DiscardMarkSize = 24f;

		private const float ConfirmWidth = 460f;

		private const int ConfirmListLines = 4;

		private const float DragThreshold = 6f;

		private const int MaxInventoryTiles = 48;

		private bool _open;

		private float _openedAt;

		private Side _hoverSide;

		private int _hoverSlot = -1;

		private bool _selectMode;

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

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

		private bool _confirmOpen;

		private readonly List<int> _dropped = new List<int>();

		private int _knownRevision = -1;

		private Side _dragSide;

		private int _dragSlot = -1;

		private string _dragId;

		private int _dragCount;

		private int _dragAmount;

		private int _dragButton;

		private Vector2 _dragStart;

		private bool _dragging;

		private readonly Rect[] _backpackRects = (Rect[])(object)new Rect[12];

		private int _backpackRectCount;

		private readonly Rect[] _inventoryRects = (Rect[])(object)new Rect[48];

		private readonly int[] _inventorySlots = new int[48];

		private int _inventoryRectCount;

		private string _status;

		private float _statusUntil;

		private GUIStyle _countStyle;

		private Font _countFont;

		private CachedText _usedText;

		private CachedText _hoverText;

		private CachedText _selectedText;

		private CachedText _discardText;

		private CachedText _confirmTitle;

		private CachedText _confirmMore;

		private string _hoverId;

		private readonly List<int> _sendSlots = new List<int>();

		private readonly List<string> _sendIds = new List<string>();

		private readonly List<int> _sendCounts = new List<int>();

		public bool IsOpen => _open;

		private static float BackpackCardTop => 156f;

		private void Awake()
		{
			Instance = this;
		}

		public void OpenFromWheel()
		{
			if (!_open && BackpackClient.InMatch)
			{
				if (LocalBackpack.Active || (BackpackNet.NetworkingEnabled && BackpackClient.HostHasMod && BackpackNet.ServerCompatible))
				{
					Open();
				}
				else
				{
					Notices.Show((NetworkServer.active && !BackpackNet.NetworkingEnabled) ? "A mochila está desligada (veja o log)." : "A mochila ainda está chegando.");
				}
			}
		}

		private void Open()
		{
			if (!_open && !((Object)(object)InputManager.Instance == (Object)null))
			{
				_open = true;
				_openedAt = Time.unscaledTime;
				_status = null;
				ResetSelection();
				ResetDrag();
				InputManager.Instance.SetState((InputState)13, true);
			}
		}

		public void Close(bool restoreInput = true)
		{
			if (_open)
			{
				_open = false;
				ResetSelection();
				ResetDrag();
				if (GUIUtility.hotControl != 0)
				{
					GUIUtility.hotControl = 0;
				}
				if (restoreInput)
				{
					InputGuard.RestoreGameplay();
				}
			}
		}

		public void ShowStatus(string text)
		{
			_status = text;
			_statusUntil = Time.unscaledTime + 3f;
		}

		private void ResetSelection()
		{
			_selectMode = false;
			_selected.Clear();
			_confirm.Clear();
			_confirmOpen = false;
		}

		private void ResetDrag()
		{
			_dragSide = Side.None;
			_dragSlot = -1;
			_dragId = null;
			_dragging = false;
		}

		private void Update()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Invalid comparison between Unknown and I4
			if (!_open)
			{
				return;
			}
			if ((Object)(object)InputManager.Instance == (Object)null || (int)InputManager.Instance.CurrentInputState != 13 || !BackpackClient.InMatch)
			{
				Close();
				return;
			}
			if (_dragSlot >= 0 && !Input.GetMouseButton(_dragButton) && !Input.GetMouseButtonUp(_dragButton))
			{
				ResetDrag();
			}
			if (Time.unscaledTime - _openedAt > 0.3f && (Input.GetKeyDown((KeyCode)27) || Input.GetKeyDown((KeyCode)9)))
			{
				if (_dragSlot >= 0)
				{
					ResetDrag();
				}
				else if (_confirmOpen)
				{
					CloseConfirm();
				}
				else if (_selectMode)
				{
					LeaveSelectMode();
				}
				else
				{
					Close();
				}
			}
		}

		private void OnGUI()
		{
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: 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_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_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			if (!_open)
			{
				return;
			}
			GUI.depth = -1000;
			int slots = (BackpackClient.HasState ? BackpackClient.State.Slots : BackpackSave.Slots);
			InventorySystem val = LocalInventory();
			int invCount = (((Object)(object)val != (Object)null) ? Mathf.Clamp(val.InventoryEntries.Count - 2, 0, 48) : 0);
			float num = PanelHeight(slots, invCount);
			float num2 = Mathf.Clamp01((Time.unscaledTime - _openedAt) / 0.16f);
			float num3 = 1f - (1f - num2) * (1f - num2) * (1f - num2);
			float num4 = Ui.WindowScale(620f, num) * Mathf.Lerp(0.96f, 1f, num3);
			Matrix4x4 matrix = GUI.matrix;
			Color color = GUI.color;
			GUI.matrix = Matrix4x4.Scale(new Vector3(num4, num4, 1f));
			GUI.color = new Color(1f, 1f, 1f, Mathf.Lerp(0.2f, 1f, num3));
			try
			{
				float num5 = (float)Screen.width / num4;
				float num6 = (float)Screen.height / num4;
				Ui.BeginWindow();
				EnsureStyles();
				DrawWindow(new Rect((num5 - 620f) / 2f, (num6 - num) / 2f, 620f, num), slots, val, invCount);
				Ui.EndWindow(num5, num6);
			}
			catch (Exception ex)
			{
				Ui.LogOnce("janela", ex);
			}
			finally
			{
				GUI.matrix = matrix;
				GUI.color = color;
			}
		}

		private static int Rows(int tiles)
		{
			return Mathf.Max(1, (tiles + 6 - 1) / 6);
		}

		private static float GridHeight(int tiles)
		{
			return (float)Rows(tiles) * 88f - 8f;
		}

		private static float PanelHeight(int slots, int invCount)
		{
			return BackpackCardTop + GridHeight(slots) + 28f + 10f + 34f + GridHeight(invCount) + 28f + 12f + 56f + 22f;
		}

		private void DrawWindow(Rect panel, int slots, InventorySystem inv, int invCount)
		{
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: 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_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Invalid comparison between Unknown and I4
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0300: Unknown result type (might be due to invalid IL or missing references)
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_0351: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0403: Unknown result type (might be due to invalid IL or missing references)
			//IL_0405: Unknown result type (might be due to invalid IL or missing references)
			//IL_040e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0455: Unknown result type (might be due to invalid IL or missing references)
			//IL_0464: Unknown result type (might be due to invalid IL or missing references)
			//IL_0490: Unknown result type (might be due to invalid IL or missing references)
			//IL_049f: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0513: Unknown result type (might be due to invalid IL or missing references)
			//IL_0515: Unknown result type (might be due to invalid IL or missing references)
			//IL_0529: Unknown result type (might be due to invalid IL or missing references)
			//IL_0534: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_058b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0597: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0547: Unknown result type (might be due to invalid IL or missing references)
			//IL_0562: Unknown result type (might be due to invalid IL or missing references)
			//IL_0564: Unknown result type (might be due to invalid IL or missing references)
			bool hasState = BackpackClient.HasState;
			string[] ids = (hasState ? BackpackClient.State.ItemIds : null);
			int[] counts = (hasState ? BackpackClient.State.Counts : null);
			slots = Mathf.Clamp(slots, 0, 12);
			if (_knownRevision != BackpackClient.Revision)
			{
				_knownRevision = BackpackClient.Revision;
				Prune(_selected, ids);
				Prune(_confirm, ids);
				if (_confirmOpen && _confirm.Count == 0)
				{
					CloseConfirm();
				}
				if (_dragSide == Side.Backpack && _dragSlot >= 0 && BackpackId(ids, _dragSlot) != _dragId)
				{
					ResetDrag();
				}
			}
			if (_confirmOpen)
			{
				Rect val = ConfirmRect(panel, _confirm.Count);
				Event current = Event.current;
				if (((int)current.type == 0 || (int)current.type == 6) && !((Rect)(ref val)).Contains(current.mousePosition))
				{
					current.Use();
				}
			}
			_hoverSide = Side.None;
			_hoverSlot = -1;
			Ui.Window(panel);
			Rect r = default(Rect);
			((Rect)(ref r))..ctor(((Rect)(ref panel)).x + 12f, ((Rect)(ref panel)).y + 12f, ((Rect)(ref panel)).width - 24f, 68f);
			Ui.Header(r);
			Ui.Sprite(new Rect(((Rect)(ref r)).x + 14f, ((Rect)(ref r)).y + 10f, 44f, 44f), PixelArt.Backpack);
			Ui.Label(new Rect(((Rect)(ref r)).x + 68f, ((Rect)(ref r)).y + 2f, 300f, 60f), "Mochila", Ui.TitleStyle, Ui.Title);
			Rect r2 = default(Rect);
			((Rect)(ref r2))..ctor(((Rect)(ref r)).xMax - 64f, ((Rect)(ref r)).y + 10f, 52f, 48f);
			if (Ui.Button(r2, null, ButtonKind.Red, enabled: true, PixelArt.Icon(UiIcon.Close), "Fechar (Esc)"))
			{
				Close();
				return;
			}
			int num = CountUsed(ids, counts, slots);
			long key = CachedText.Key(num, slots);
			string text = (_usedText.Needs(key) ? _usedText.Set(key, $"{num} / {slots}") : _usedText.Text);
			Rect r3 = default(Rect);
			((Rect)(ref r3))..ctor(((Rect)(ref r2)).x - 12f - 130f, ((Rect)(ref r)).y + 10f, 130f, 48f);
			Ui.Inset(r3);
			Ui.Icon(new Rect(((Rect)(ref r3)).x + 10f, ((Rect)(ref r3)).y + 10f, 28f, 28f), PixelArt.Icon(UiIcon.Slots));
			Ui.Label(new Rect(((Rect)(ref r3)).x + 44f, ((Rect)(ref r3)).y - 1f, ((Rect)(ref r3)).width - 54f, ((Rect)(ref r3)).height), text, Ui.H3, (num >= slots) ? Ui.Bad : Ui.Text, (TextAnchor)4);
			DrawToolbar(new Rect(((Rect)(ref panel)).x + 24f, ((Rect)(ref panel)).y + 92f, ((Rect)(ref panel)).width - 48f, 52f), ids, counts, slots);
			float num2 = ((Rect)(ref panel)).x + 24f;
			float num3 = ((Rect)(ref panel)).width - 48f;
			Rect val2 = default(Rect);
			((Rect)(ref val2))..ctor(num2, ((Rect)(ref panel)).y + BackpackCardTop, num3, GridHeight(slots) + 28f);
			Ui.Card(val2);
			_backpackRectCount = slots;
			float num4 = GridLeft(val2, Mathf.Min(slots, 6));
			Rect val3 = default(Rect);
			for (int i = 0; i < slots; i++)
			{
				((Rect)(ref val3))..ctor(num4 + (float)(i % 6) * 88f, ((Rect)(ref val2)).y + 14f + (float)(i / 6) * 88f, 80f, 80f);
				_backpackRects[i] = val3;
				DrawSlot(Side.Backpack, i, val3, BackpackId(ids, i), BackpackCount(counts, ids, i), null);
			}
			float num5 = ((Rect)(ref val2)).yMax + 10f;
			Ui.Label(new Rect(num2 + 6f, num5, 300f, 30f), "Inventário", Ui.Body, Ui.Muted, (TextAnchor)3);
			Rect val4 = default(Rect);
			((Rect)(ref val4))..ctor(num2, num5 + 34f, num3, GridHeight(invCount) + 28f);
			Ui.Card(val4);
			_inventoryRectCount = invCount;
			float num6 = GridLeft(val4, Mathf.Min(Mathf.Max(invCount, 1), 6));
			Rect val6 = default(Rect);
			for (int j = 0; j < invCount; j++)
			{
				int num7 = 2 + j;
				InventoryEntry val5 = inv.InventoryEntries[num7];
				((Rect)(ref val6))..ctor(num6 + (float)(j % 6) * 88f, ((Rect)(ref val4)).y + 14f + (float)(j / 6) * 88f, 80f, 80f);
				_inventoryRects[j] = val6;
				_inventorySlots[j] = num7;
				DrawSlot(Side.Inventory, num7, val6, ((InventoryEntry)(ref val5)).IsEmpty ? null : val5.itemID, (!((InventoryEntry)(ref val5)).IsEmpty) ? val5.count : 0, ((SlotParameters)(ref val5.slotParameters)).IsForcedItem ? val5.slotParameters.forcedItemID : null);
			}
			if ((Object)(object)inv == (Object)null)
			{
				Ui.Label(val4, "...", Ui.Body, Ui.Dim, (TextAnchor)4);
			}
			DrawFooter(new Rect(((Rect)(ref panel)).x + 26f, ((Rect)(ref val4)).yMax + 12f, ((Rect)(ref panel)).width - 52f, 56f), ids, counts, inv, hasState);
			HandleDrag(ids, counts, inv);
			if (_confirmOpen)
			{
				DrawConfirm(panel, ConfirmRect(panel, _confirm.Count), ids, counts);
			}
		}

		private static float GridLeft(Rect card, int columns)
		{
			float num = (float)columns * 80f + (float)(columns - 1) * 8f;
			return ((Rect)(ref card)).x + Mathf.Max(14f, (((Rect)(ref card)).width - num) / 2f);
		}

		private static string BackpackId(string[] ids, int i)
		{
			if (ids == null || i < 0 || i >= ids.Length || string.IsNullOrEmpty(ids[i]))
			{
				return null;
			}
			return ids[i];
		}

		private static int BackpackCount(int[] counts, string[] ids, int i)
		{
			if (BackpackId(ids, i) == null || counts == null || i >= counts.Length)
			{
				return 0;
			}
			return counts[i];
		}

		private static int CountUsed(string[] ids, int[] counts, int slots)
		{
			int num = 0;
			for (int i = 0; i < slots; i++)
			{
				if (BackpackCount(counts, ids, i) > 0)
				{
					num++;
				}
			}
			return num;
		}

		private static InventorySystem LocalInventory()
		{
			FirstPersonController localPlayer = Match.LocalPlayer;
			InventorySystem val = (((Object)(object)localPlayer != (Object)null) ? localPlayer.InventorySystem : null);
			if (!((Object)(object)val != (Object)null) || val.InventoryEntries == null)
			{
				return null;
			}
			return val;
		}

		private void DrawToolbar(Rect r, string[] ids, int[] counts, int slots)
		{
			//IL_00a6: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			bool enabled = CountUsed(ids, counts, slots) > 0;
			if (!_selectMode)
			{
				if (Ui.Button(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y, 190f, 52f), "Organizar", ButtonKind.Blue, enabled, PixelArt.Icon(UiIcon.Slots)))
				{
					SendSimple(BackpackAction.Sort);
				}
				if (Ui.Button(new Rect(((Rect)(ref r)).x + 198f, ((Rect)(ref r)).y, 190f, 52f), "Selecionar", ButtonKind.Dark, enabled, PixelArt.Icon(UiIcon.Check)))
				{
					EnterSelectMode();
				}
				return;
			}
			if (Ui.Button(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y, 176f, 52f), "Selecionar tudo", ButtonKind.Blue, enabled, PixelArt.Icon(UiIcon.Check), null, small: true))
			{
				SelectAll(ids, counts, slots);
			}
			if (Ui.Button(new Rect(((Rect)(ref r)).x + 184f, ((Rect)(ref r)).y, 176f, 52f), "Limpar seleção", ButtonKind.Dark, _selected.Count > 0, PixelArt.Icon(UiIcon.Back), null, small: true))
			{
				_selected.Clear();
			}
			if (Ui.Button(new Rect(((Rect)(ref r)).x + 368f, ((Rect)(ref r)).y, 140f, 52f), "Cancelar", ButtonKind.Red, enabled: true, PixelArt.Icon(UiIcon.Close), "Esc", small: true))
			{
				LeaveSelectMode();
			}
		}

		private void DrawFooter(Rect footer, string[] ids, int[] counts, InventorySystem inv, bool hasState)
		{
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: 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_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0304: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: 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)
			if (_selectMode)
			{
				Rect val = default(Rect);
				((Rect)(ref val))..ctor(((Rect)(ref footer)).x, ((Rect)(ref footer)).y, ((Rect)(ref footer)).width - 230f - 12f, ((Rect)(ref footer)).height);
				CountSelection(counts, out var stacks, out var items);
				long key = CachedText.Key(stacks, items);
				string text = (_selectedText.Needs(key) ? _selectedText.Set(key, (stacks == 0) ? "Nenhuma pilha marcada" : string.Format("{0} {1}  ·  {2} {3}", stacks, (stacks == 1) ? "pilha marcada" : "pilhas marcadas", items, (items == 1) ? "item" : "itens")) : _selectedText.Text);
				Ui.Label(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y, ((Rect)(ref val)).width, 32f), text, Ui.Body, (stacks > 0) ? Ui.Warn : Ui.Muted, (TextAnchor)3);
				Color color;
				ItemDataSO data;
				string text2 = HoverLine(ids, counts, inv, out color, out data);
				if (text2 != null)
				{
					Ui.Label(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y + 30f, ((Rect)(ref val)).width, 26f), text2, Ui.Small, color, (TextAnchor)3);
				}
				string text3 = (_discardText.Needs(stacks) ? _discardText.Set(stacks, $"Jogar fora ({stacks})") : _discardText.Text);
				if (Ui.Button(new Rect(((Rect)(ref footer)).xMax - 230f, ((Rect)(ref footer)).y + 2f, 230f, 54f), text3, ButtonKind.Red, stacks > 0, PixelArt.Icon(UiIcon.Close)))
				{
					AskDiscardSelection();
				}
			}
			else if (_status != null && Time.unscaledTime < _statusUntil)
			{
				Ui.Label(new Rect(((Rect)(ref footer)).x, ((Rect)(ref footer)).y + 12f, ((Rect)(ref footer)).width, 32f), _status, Ui.Body, Ui.Warn, (TextAnchor)3);
			}
			else
			{
				Color color2;
				ItemDataSO data2;
				string text4 = HoverLine(ids, counts, inv, out color2, out data2);
				if (text4 != null)
				{
					Ui.Label(new Rect(((Rect)(ref footer)).x, ((Rect)(ref footer)).y, ((Rect)(ref footer)).width, 32f), text4, Ui.Body, color2, (TextAnchor)3);
					Ui.Label(new Rect(((Rect)(ref footer)).x, ((Rect)(ref footer)).y + 30f, ((Rect)(ref footer)).width, 26f), ((Object)(object)data2 != (Object)null) ? ItemInfo.RarityName(data2.Rarity) : "", Ui.Small, Ui.WithAlpha(color2, 0.8f), (TextAnchor)3);
				}
				else
				{
					Ui.Label(new Rect(((Rect)(ref footer)).x, ((Rect)(ref footer)).y + 12f, ((Rect)(ref footer)).width, 30f), hasState ? "Botão direito: arrasta 1  ·  Ctrl + clique: marcar" : "Carregando a mochila...", Ui.Small, Ui.Dim, (TextAnchor)3);
				}
			}
		}

		private string HoverLine(string[] ids, int[] counts, InventorySystem inv, out Color color, out ItemDataSO data)
		{
			//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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: 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_0122: 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_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			color = Ui.Text;
			data = null;
			string text = null;
			int num = 0;
			if (_hoverSide == Side.Backpack)
			{
				text = BackpackId(ids, _hoverSlot);
				num = BackpackCount(counts, ids, _hoverSlot);
			}
			else if (_hoverSide == Side.Inventory && (Object)(object)inv != (Object)null && _hoverSlot >= 0 && _hoverSlot < inv.InventoryEntries.Count)
			{
				InventoryEntry val = inv.InventoryEntries[_hoverSlot];
				text = (((InventoryEntry)(ref val)).IsEmpty ? null : val.itemID);
				num = ((!((InventoryEntry)(ref val)).IsEmpty) ? val.count : 0);
			}
			if (text == null || num <= 0)
			{
				return null;
			}
			long key = CachedText.Key((int)_hoverSide * 1000 + _hoverSlot, num);
			if (_hoverText.Needs(key) || _hoverId != text)
			{
				_hoverId = text;
				_hoverText.Set(key, $"{ItemInfo.Name(text)}  x{num}");
			}
			data = ItemInfo.Get(text);
			if ((Object)(object)data != (Object)null)
			{
				color = ItemInfo.RarityColor(data.Rarity);
			}
			return _hoverText.Text;
		}

		private static Rect DiscardMarkRect(Rect slot)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			return new Rect(((Rect)(ref slot)).xMax - 24f - 3f, ((Rect)(ref slot)).y + 3f, 24f, 24f);
		}

		private void DrawSlot(Side side, int index, Rect r, string id, int count, string forcedId)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Invalid comparison between Unknown and I4
			//IL_007b: 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_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: 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_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_035e: Unknown result type (might be due to invalid IL or missing references)
			//IL_036a: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0404: Unknown result type (might be due to invalid IL or missing references)
			//IL_041a: Unknown result type (might be due to invalid IL or missing references)
			//IL_044c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0457: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0467: Unknown result type (might be due to invalid IL or missing references)
			//IL_0468: Unknown result type (might be due to invalid IL or missing references)
			//IL_046d: Unknown result type (might be due to invalid IL or missing references)
			//IL_046f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0478: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_0492: Unknown result type (might be due to invalid IL or missing references)
			//IL_04eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0501: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fa: Unknown result type (might be due to invalid IL or missing references)
			bool flag = id != null && count > 0;
			bool flag2 = Ui.MouseOver(r) && !_confirmOpen;
			if (flag2)
			{
				_hoverSide = side;
				_hoverSlot = index;
			}
			bool flag3 = side == Side.Backpack && flag && _selected.ContainsKey(index);
			bool flag4 = side == Side.Backpack && flag && flag2 && !_selectMode && _dragSlot < 0;
			Event current = Event.current;
			if (flag && flag2 && (int)current.type == 0 && (current.button == 0 || current.button == 1))
			{
				if (side == Side.Backpack && (_selectMode || (current.button == 0 && current.control)))
				{
					ToggleSelected(index, id);
				}
				else if (!_selectMode && flag4 && current.button == 0 && Ui.MouseOver(DiscardMarkRect(r)))
				{
					AskDiscardOne(index, id);
				}
				else if (!_selectMode)
				{
					BeginDrag(side, index, id, count, current.button, current.mousePosition);
				}
				current.Use();
			}
			if ((int)current.type != 7)
			{
				return;
			}
			bool flag5 = _dragging && _dragSide == side && _dragSlot == index;
			if (_dragging && flag2 && !flag5 && (side == Side.Backpack || _dragSide == Side.Backpack))
			{
				Ui.Glow(new Rect(((Rect)(ref r)).x - 16f, ((Rect)(ref r)).y - 16f, ((Rect)(ref r)).width + 32f, ((Rect)(ref r)).height + 32f), new Color(1f, 0.85f, 0.45f, 0.45f));
			}
			else if (flag3)
			{
				Ui.Glow(new Rect(((Rect)(ref r)).x - 14f, ((Rect)(ref r)).y - 14f, ((Rect)(ref r)).width + 28f, ((Rect)(ref r)).height + 28f), new Color(1f, 0.42f, 0.32f, 0.38f));
			}
			else if (flag2 && flag && _dragSlot < 0)
			{
				Ui.Glow(new Rect(((Rect)(ref r)).x - 14f, ((Rect)(ref r)).y - 14f, ((Rect)(ref r)).width + 28f, ((Rect)(ref r)).height + 28f), new Color(1f, 0.85f, 0.45f, 0.3f));
			}
			if (!flag)
			{
				Ui.Inset(r);
				ItemDataSO val = ((forcedId != null) ? ItemInfo.Get(forcedId) : null);
				if ((Object)(object)val != (Object)null && (Object)(object)val.itemIcon != (Object)null)
				{
					Ui.SpriteFit(new Rect(((Rect)(ref r)).x + 18f, ((Rect)(ref r)).y + 18f, ((Rect)(ref r)).width - 36f, ((Rect)(ref r)).height - 36f), val.itemIcon, 0.25f);
				}
			}
			else
			{
				Ui.ItemSlot(r, id, flag5 ? 0.35f : 1f);
				if ((Object)(object)ItemInfo.Get(id) == (Object)null)
				{
					Ui.Label(new Rect(((Rect)(ref r)).x + 6f, ((Rect)(ref r)).y, ((Rect)(ref r)).width - 12f, ((Rect)(ref r)).height), id, Ui.Tiny, Ui.Text, (TextAnchor)4);
				}
				if (count > 1)
				{
					Ui.Outlined(new Rect(((Rect)(ref r)).x + 4f, ((Rect)(ref r)).yMax - 32f, ((Rect)(ref r)).width - 12f, 28f), Txt.Int(count), _countStyle, flag5 ? Ui.Dim : Color.white, 1.5f);
				}
			}
			if (flag3)
			{
				Rect r2 = default(Rect);
				((Rect)(ref r2))..ctor(((Rect)(ref r)).x + 3f, ((Rect)(ref r)).y + 3f, 24f, 24f);
				Ui.Solid(r2, new Color(0.84f, 0.24f, 0.2f, 0.95f));
				Ui.Icon(new Rect(((Rect)(ref r2)).x + 2f, ((Rect)(ref r2)).y, ((Rect)(ref r2)).width - 4f, ((Rect)(ref r2)).height), PixelArt.Icon(UiIcon.Check), Color.white);
			}
			if (flag4)
			{
				Rect r3 = DiscardMarkRect(r);
				bool flag6 = Ui.MouseOver(r3);
				Ui.Solid(r3, flag6 ? new Color(0.9f, 0.27f, 0.22f, 0.98f) : new Color(0.22f, 0.07f, 0.07f, 0.85f));
				Ui.Icon(new Rect(((Rect)(ref r3)).x + 5f, ((Rect)(ref r3)).y + 5f, ((Rect)(ref r3)).width - 10f, ((Rect)(ref r3)).height - 10f), PixelArt.Icon(UiIcon.Close), flag6 ? Color.white : Ui.Bad);
			}
		}

		private void BeginDrag(Side side, int slot, string id, int count, int button, Vector2 mouse)
		{
			//IL_0036: 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)
			_dragSide = side;
			_dragSlot = slot;
			_dragId = id;
			_dragCount = count;
			_dragAmount = ((button == 1) ? 1 : count);
			_dragButton = button;
			_dragStart = mouse;
			_dragging = false;
		}

		private void HandleDrag(string[] ids, int[] counts, InventorySystem inv)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Invalid comparison between Unknown and I4
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Invalid comparison between Unknown and I4
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Invalid comparison between Unknown and I4
			//IL_0075: 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_0033: 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_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_00a2: 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_0104: 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_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			if (_dragSlot < 0)
			{
				return;
			}
			Event current = Event.current;
			EventType type = current.type;
			if ((int)type != 1)
			{
				if ((int)type != 3)
				{
					if ((int)type == 7 && _dragging)
					{
						Vector2 mousePosition = current.mousePosition;
						Rect r = default(Rect);
						((Rect)(ref r))..ctor(mousePosition.x - 34f, mousePosition.y - 34f, 68f, 68f);
						ItemDataSO val = ItemInfo.Get(_dragId);
						if ((Object)(object)val != (Object)null && (Object)(object)val.itemIcon != (Object)null)
						{
							Ui.SpriteFit(r, val.itemIcon, 0.9f);
						}
						else
						{
							Ui.Icon(r, PixelArt.Icon(UiIcon.Sword), 0.6f);
						}
						if (_dragAmount > 1)
						{
							Ui.Outlined(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).yMax - 26f, ((Rect)(ref r)).width, 26f), Txt.Int(_dragAmount), _countStyle, Color.white, 1.5f);
						}
					}
					return;
				}
				if (!_dragging)
				{
					Vector2 val2 = current.mousePosition - _dragStart;
					if (((Vector2)(ref val2)).sqrMagnitude > 36f)
					{
						_dragging = true;
					}
				}
				current.Use();
			}
			else if (current.button == _dragButton)
			{
				if (_dragging)
				{
					Drop(current.mousePosition, ids, inv);
				}
				ResetDrag();
				current.Use();
			}
		}

		private void Drop(Vector2 m, string[] ids, InventorySystem inv)
		{
			//IL_0016: 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)
			Side side = Side.None;
			int num = -1;
			for (int i = 0; i < _backpackRectCount; i++)
			{
				if (side != Side.None)
				{
					break;
				}
				if (((Rect)(ref _backpackRects[i])).Contains(m))
				{
					side = Side.Backpack;
					num = i;
				}
			}
			for (int j = 0; j < _inventoryRectCount; j++)
			{
				if (side != Side.None)
				{
					break;
				}
				if (((Rect)(ref _inventoryRects[j])).Contains(m))
				{
					side = Side.Inventory;
					num = _inventorySlots[j];
				}
			}
			if (side == Side.None || (side == _dragSide && num == _dragSlot))
			{
				return;
			}
			BackpackAction action;
			string text;
			if (_dragSide == Side.Inventory && side == Side.Backpack)
			{
				action = BackpackAction.Store;
				text = BackpackId(ids, num);
			}
			else if (_dragSide == Side.Backpack && side == Side.Inventory)
			{
				action = BackpackAction.Take;
				text = InventoryId(inv, num);
			}
			else
			{
				if (_dragSide != Side.Backpack || side != Side.Backpack)
				{
					return;
				}
				action = BackpackAction.Move;
				text = BackpackId(ids, num);
			}
			BackpackClient.Send(new BackpackActionMsg
			{
				Action = action,
				From = _dragSlot,
				To = num,
				ItemId = _dragId,
				Count = _dragCount,
				ToItemId = (text ?? ""),
				Amount = _dragAmount
			});
			GameSounds.PlayUi("UI_BUTTON_SELECTION", 0.5f);
		}

		private static string InventoryId(InventorySystem inv, int slot)
		{
			//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)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)inv == (Object)null || slot < 0 || slot >= inv.InventoryEntries.Count)
			{
				return null;
			}
			InventoryEntry val = inv.InventoryEntries[slot];
			if (!((InventoryEntry)(ref val)).IsEmpty)
			{
				return val.itemID;
			}
			return null;
		}

		private void EnterSelectMode()
		{
			_selectMode = true;
			_selected.Clear();
			ResetDrag();
		}

		private void LeaveSelectMode()
		{
			_selectMode = false;
			_selected.Clear();
		}

		private void ToggleSelected(int slot, string id)
		{
			_selectMode = true;
			if (!_selected.Remove(slot))
			{
				_selected[slot] = id;
			}
			GameSounds.PlayUi("UI_BUTTON_SELECTION", 0.5f);
		}

		private void SelectAll(string[] ids, int[] counts, int slots)
		{
			for (int i = 0; i < slots; i++)
			{
				string text = BackpackId(ids, i);
				if (text != null && BackpackCount(counts, ids, i) > 0)
				{
					_selected[i] = text;
				}
			}
		}

		private void Prune(Dictionary<int, string> map, string[] ids)
		{
			if (map.Count == 0)
			{
				return;
			}
			_dropped.Clear();
			foreach (KeyValuePair<int, string> item in map)
			{
				if (BackpackId(ids, item.Key) != item.Value)
				{
					_dropped.Add(item.Key);
				}
			}
			for (int i = 0; i < _dropped.Count; i++)
			{
				map.Remove(_dropped[i]);
			}
			_dropped.Clear();
		}

		private void CountSelection(int[] counts, out int stacks, out int items)
		{
			stacks = _selected.Count;
			items = 0;
			if (counts == null)
			{
				return;
			}
			foreach (KeyValuePair<int, string> item in _selected)
			{
				if (item.Key >= 0 && item.Key < counts.Length)
				{
					items += counts[item.Key];
				}
			}
		}

		private void AskDiscardOne(int slot, string id)
		{
			_confirm.Clear();
			_confirm[slot] = id;
			_confirmOpen = true;
			GameSounds.PlayUi("UI_BUTTON_SELECTION", 0.5f);
		}

		private void AskDiscardSelection()
		{
			if (_selected.Count == 0)
			{
				return;
			}
			_confirm.Clear();
			foreach (KeyValuePair<int, string> item in _selected)
			{
				_confirm[item.Key] = item.Value;
			}
			_confirmOpen = true;
		}

		private void CloseConfirm()
		{
			_confirm.Clear();
			_confirmOpen = false;
		}

		private static Rect ConfirmRect(Rect panel, int stacks)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			float num = ((stacks > 1) ? (262f + (float)Mathf.Min(stacks, 5) * 26f) : 288f);
			return new Rect(((Rect)(ref panel)).x + (((Rect)(ref panel)).width - 460f) / 2f, ((Rect)(ref panel)).y + (((Rect)(ref panel)).height - num) / 2f, 460f, num);
		}

		private void DrawConfirm(Rect panel, Rect card, string[] ids, int[] counts)
		{
			//IL_0000: 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_001f: 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_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: 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_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0439: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: 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_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0386: Unknown result type (might be due to invalid IL or missing references)
			//IL_0392: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			Ui.Solid(panel, new Color(0.02f, 0.03f, 0.05f, 0.76f));
			Ui.Window(card);
			float num = ((Rect)(ref card)).x + 26f;
			float num2 = ((Rect)(ref card)).width - 52f;
			Ui.Label(new Rect(num, ((Rect)(ref card)).y + 14f, num2, 46f), "Jogar fora?", Ui.H1, Ui.Bad, (TextAnchor)4);
			CountConfirm(counts, out var stacks, out var items);
			float num3 = ((Rect)(ref card)).y + 70f;
			if (stacks == 1)
			{
				using (Dictionary<int, string>.Enumerator enumerator = _confirm.GetEnumerator())
				{
					if (enumerator.MoveNext())
					{
						KeyValuePair<int, string> current = enumerator.Current;
						int num4 = BackpackCount(counts, ids, current.Key);
						ItemDataSO val = ItemInfo.Get(current.Value);
						Color val2 = (((Object)(object)val != (Object)null) ? ItemInfo.RarityColor(val.Rarity) : Ui.Text);
						long key = CachedText.Key(current.Key, num4);
						string text = (_confirmTitle.Needs(key) ? _confirmTitle.Set(key, $"{num4}x {ItemInfo.Name(current.Value)}") : _confirmTitle.Text);
						Ui.Label(new Rect(num, num3, num2, 44f), text, Ui.H2, val2, (TextAnchor)4);
						Ui.Label(new Rect(num, num3 + 44f, num2, 28f), ((Object)(object)val != (Object)null) ? ItemInfo.RarityName(val.Rarity) : "", Ui.Small, Ui.WithAlpha(val2, 0.8f), (TextAnchor)4);
					}
				}
				num3 += 80f;
			}
			else
			{
				long key2 = CachedText.Key(stacks, items);
				string text2 = (_confirmTitle.Needs(key2) ? _confirmTitle.Set(key2, string.Format("{0} pilhas  ·  {1} {2}", stacks, items, (items == 1) ? "item" : "itens")) : _confirmTitle.Text);
				Ui.Label(new Rect(num, num3, num2, 40f), text2, Ui.H2, Ui.Warn, (TextAnchor)4);
				num3 += 44f;
				int num5 = 0;
				int num6 = 0;
				foreach (KeyValuePair<int, string> item in _confirm)
				{
					if (num5 >= 4 && _confirm.Count > 5)
					{
						num6++;
						continue;
					}
					int num7 = BackpackCount(counts, ids, item.Key);
					ItemDataSO val3 = ItemInfo.Get(item.Value);
					Ui.Label(new Rect(num, num3, num2, 26f), $"{num7}x {ItemInfo.Name(item.Value)}", Ui.Small, ((Object)(object)val3 != (Object)null) ? ItemInfo.RarityColor(val3.Rarity) : Ui.Text, (TextAnchor)4);
					num3 += 26f;
					num5++;
				}
				if (num6 > 0)
				{
					string text3 = (_confirmMore.Needs(num6) ? _confirmMore.Set(num6, $"e mais {num6}...") : _confirmMore.Text);
					Ui.Label(new Rect(num, num3, num2, 26f), text3, Ui.Small, Ui.Muted, (TextAnchor)4);
					num3 += 26f;
				}
				num3 += 6f;
			}
			Ui.Label(new Rect(num, num3, num2, 46f), "Somem de vez, não caem no chão.", Ui.SmallWrap, Ui.Muted, (TextAnchor)1);
			float num8 = ((Rect)(ref card)).yMax - 76f;
			if (Ui.Button(new Rect(((Rect)(ref card)).x + 22f, num8, 190f, 58f), "Cancelar", ButtonKind.Dark, enabled: true, PixelArt.Icon(UiIcon.Back)))
			{
				CloseConfirm();
			}
			else if (Ui.Button(new Rect(((Rect)(ref card)).xMax - 212f, num8, 190f, 58f), "Jogar fora", ButtonKind.Red, stacks > 0, PixelArt.Icon(UiIcon.Close)))
			{
				SendDiscard(ids, counts);
			}
		}

		private void CountConfirm(int[] counts, out int stacks, out int items)
		{
			stacks = _confirm.Count;
			items = 0;
			if (counts == null)
			{
				return;
			}
			foreach (KeyValuePair<int, string> item in _confirm)
			{
				if (item.Key >= 0 && item.Key < counts.Length)
				{
					items += counts[item.Key];
				}
			}
		}

		private void EnsureStyles()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			if (_countStyle == null || !((Object)(object)_countFont == (Object)(object)Ui.GameFont))
			{
				_countFont = Ui.GameFont;
				_countStyle = new GUIStyle(Ui.H3)
				{
					alignment = (TextAnchor)8
				};
			}
		}

		private static void SendSimple(BackpackAction action)
		{
			BackpackClient.Send(new BackpackActionMsg
			{
				Action = action,
				ItemId = "",
				ToItemId = ""
			});
		}

		private void SendDiscard(string[] ids, int[] counts)
		{
			_sendSlots.Clear();
			_sendIds.Clear();
			_sendCounts.Clear();
			foreach (KeyValuePair<int, string> item in _confirm)
			{
				int key = item.Key;
				string text = BackpackId(ids, key);
				int num = BackpackCount(counts, ids, key);
				if (text != null && !(text != item.Value) && num > 0)
				{
					_sendSlots.Add(key);
					_sendIds.Add(text);
					_sendCounts.Add(num);
				}
			}
			CloseConfirm();
			LeaveSelectMode();
			if (_sendSlots.Count != 0)
			{
				BackpackClient.Send(new BackpackActionMsg
				{
					Action = BackpackAction.Discard,
					ItemId = "",
					ToItemId = "",
					Slots = _sendSlots.ToArray(),
					ItemIds = _sendIds.ToArray(),
					Counts = _sendCounts.ToArray()
				});
			}
		}
	}
	internal class InputGuard : MonoBehaviour
	{
		private const float PendingTimeout = 60f;

		private static float _pendingUntil = -1f;

		private bool _ourWindowWasOpen;

		private InputState _lastState;

		private float _nextCheck;

		private static bool Pending => _pendingUntil > Time.unscaledTime;

		internal static void MarkPending()
		{
			_pendingUntil = Time.unscaledTime + 60f;
		}

		private static void ClearPending()
		{
			_pendingUntil = -1f;
		}

		internal static bool OurWindowOpen()
		{
			if ((Object)(object)BackpackWindow.Instance != (Object)null)
			{
				return BackpackWindow.Instance.IsOpen;
			}
			return false;
		}

		private void LateUpdate()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Invalid comparison between Unknown and I4
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Invalid comparison between Unknown and I4
			//IL_003b: 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_005d: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Invalid comparison between Unknown and I4
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Invalid comparison between Unknown and I4
			InputManager instance = InputManager.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				_ourWindowWasOpen = false;
				ClearPending();
				return;
			}
			InputState currentInputState = instance.CurrentInputState;
			bool flag = OurWindowOpen();
			if (_ourWindowWasOpen && (int)_lastState == 13 && IsVanillaMenuState(currentInputState))
			{
				MarkPending();
				FixOpenMenus();
			}
			if (Pending)
			{
				if ((int)currentInputState == 2 || (int)currentInputState == 4 || (int)currentInputState == 1 || (Object)(object)GameManager.Instance == (Object)null)
				{
					ClearPending();
				}
				else if (currentInputState != _lastState || Time.unscaledTime >= _nextCheck)
				{
					bool flag2 = IsVanillaMenuState(currentInputState);
					_nextCheck = Time.unscaledTime + (flag2 ? 1f : 0.25f);
					if (flag2)
					{
						FixOpenMenus();
					}
					else if ((int)currentInputState == 13 && !flag && !VanillaGeneralMenuOpen())
					{
						Plugin.Log.LogInfo((object)"Backpack: input preso em GeneralMenu depois de um menu do jogo; voltando para o jogo.");
						RestoreGameplay();
						ClearPending();
					}
				}
			}
			_ourWindowWasOpen = flag;
			_lastState = currentInputState;
		}

		private static bool IsVanillaMenuState(InputState state)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//IL_000d: 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_0012: Invalid comparison between Unknown and I4
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Invalid comparison between Unknown and I4
			if ((int)state != 13 && (int)state != 2 && (int)state != 4 && (int)state != 0 && (int)state != 1)
			{
				return (int)state != 12;
			}
			return false;
		}

		internal static InputState GameplayState()
		{
			FirstPersonController val = (((Object)(object)GameManager.Instance != (Object)null) ? GameManager.Instance.LocalPlayer : null);
			if ((Object)(object)val != (Object)null && (Object)(object)val.PlayerStats != (Object)null && val.PlayerStats.isDead)
			{
				return (InputState)4;
			}
			return (InputState)2;
		}

		internal static void RestoreGameplay()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Invalid comparison between Unknown and I4
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)InputManager.Instance != (Object)null && (int)InputManager.Instance.CurrentInputState == 13)
			{
				InputManager.Instance.SetState(GameplayState(), true);
			}
		}

		private static void FixOpenMenus()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: 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_002f: Invalid comparison between Unknown and I4
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Invalid comparison between Unknown and I4
			//IL_003c: 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)
			InputState previousState = GameplayState();
			BaseMenu[] array = Object.FindObjectsByType<BaseMenu>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			foreach (BaseMenu val in array)
			{
				if ((Object)(object)val != (Object)null && val.IsOpen && (int)val.previousState == 13 && (int)val.InputState != 13)
				{
					val.previousState = previousState;
				}
			}
		}

		private static bool VanillaGeneralMenuOpen()
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Invalid comparison between Unknown and I4
			if ((Object)(object)CraftManager.Instance != (Object)null && (Object)(object)CraftManager.Instance.craftMenu != (Object)null && ((BaseMenu)CraftManager.Instance.craftMenu).IsOpen)
			{
				return true;
			}
			BaseMenu[] array = Object.FindObjectsByType<BaseMenu>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			foreach (BaseMenu val in array)
			{
				if ((Object)(object)val != (Object)null && val.IsOpen && (int)val.InputState == 13)
				{
					return true;
				}
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(BaseMenu), "HandleInput")]
	internal static class BackpackBaseMenuHandleInputPatch
	{
		private static void Prefix(bool _Show, out bool __state)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Invalid comparison between Unknown and I4
			__state = false;
			try
			{
				__state = _Show && (Object)(object)InputManager.Instance != (Object)null && (int)InputManager.Instance.CurrentInputState == 13 && InputGuard.OurWindowOpen();
			}
			catch
			{
			}
		}

		private static void Postfix(BaseMenu __instance, bool __state)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Invalid comparison between Unknown and I4
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			if (!__state)
			{
				return;
			}
			try
			{
				if ((int)__instance.previousState == 13 && (int)__instance.InputState != 13)
				{
					__instance.previousState = InputGuard.GameplayState();
					InputGuard.MarkPending();
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Backpack: não consegui ajustar o menu do jogo: " + ex.Message));
			}
		}
	}
	internal static class Notices
	{
		private static string _last;

		private static float _lastAt;

		public static void Show(string text)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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_0072: Expected O, but got Unknown
			if (string.IsNullOrEmpty(text) || (text == _last && Time.unscaledTime - _lastAt < 3f))
			{
				return;
			}
			_last = text;
			_lastAt = Time.unscaledTime;
			try
			{
				if ((Object)(object)NotificationHolder.Instance != (Object)null)
				{
					NotificationHolder.Instance.CreateNotification((INotification)new BasicNotification
					{
						Icon = PixelArt.Backpack,
						Description = text,
						DisplayTime = 3f
					});
					return;
				}
			}
			catch (Exception ex)
			{
				Plugin.Verbose("Backpack: notificação do jogo falhou: " + ex.Message);
			}
			Plugin.Log.LogInfo((object)("Backpack: " + text));
		}
	}
	internal enum UiIcon
	{
		Close,
		Check,
		Back,
		Slots,
		Sword
	}
	internal static class PixelArt
	{
		private const string BackpackPalette = "O:24140A S:4A2E1A s:7A4E2C B:B8743E k:E0A060 b:8A5226 F:A8432E f:D0674A e:7A2E20 G:FFD84A Y:FFF2A8 g:C8961C P:9A6034 p:C08048";

		private static readonly string[] BackpackPixels = new string[32]
		{
			"................................", "................................", "............OOOOOOOO............", "...........OSssssssSO...........", "...........OSSOOOOSSO...........", "...........OSO....OSO...........", "........OOOOSOOOOOOSOOOO........", ".......OFfffSffffffSfffFO.......", "......OfFFFFFFFFFFFFFFFeeO......", "......OfFFFFFFFFFFFFFFFeeO......",
			"......OfFFFFFFFFFFFFFFFeeO......", "......OfFFFFFFSSSSFFFFFeeO......", "......OfFFFFFFSSSSFFFFFeeO......", "......OOOOFFFFSSSSFFFFOOOO......", "......OkBBOOOFSSSSFOOOBbbO......", "....OOOkBBBBBOSSSSOBBBBbbOOO....", "....OSOkBBBBOOOOOOOOBBBbbOSO....", "....OSOkBBBBOYYGGGgOBBBbbOSO....", "....OSOkBBBBOGOOOOgOBBBbbOSO....", "....OSOkBBBBOGgggggOBBBbbOSO....",
			"....OSOkBBBBOOOOOOOOBBBbbOSO....", "....OSOkBBBBBBSSSSBBBBBbbOSO....", "....OSOkBOOOOOOOOOOOOOObbOSO....", "....OSOkBOppppppppppppObbOSO....", "....OOOkBOOOOOOGGOOOOOObbOOO....", "......OkBOPPPPPPPPPPPPObbO......", "......OkBOPPPPPPPPPPPPObbO......", "......OkbOPPPPPPPPPPPPObbO......", "......ObbOOOOOOOOOOOOOObbO......", ".......ObbbbbbbbbbbbbbbbO.......",
			"........OOOOOOOOOOOOOOOO........", "................................"
		};

		private static readonly string[] BackpackWhitePixels = new string[32]
		{
			"................................", "................................", "............WWWWWWWW............", "...........WWWWWWWWWW...........", "...........WWW....WWW...........", "...........WW......WW...........", "........WWW.W......W.WWW........", ".......WWWWWWWWWWWWWWWWWW.......", "......WWWWWWWWWWWWWWWWWWWW......", "......WWWWWWWWWWWWWWWWWWWW......",
			"......WWWWWWWWWWWWWWWWWWWW......", "......WWWWWWWWWWWWWWWWWWWW......", "......WWWWWWWWWWWWWWWWWWWW......", "......W...WWWWWWWWWWWW...W......", "......WWWW...WWWWWW...WWWW......", "....WW.WWWWWW.WWWW.WWWWWW.WW....", "....WW.WWWWW........WWWWW.WW....", "....WW.WWWWW.WWWWWW.WWWWW.WW....", "....WW.WWWWW.W....W.WWWWW.WW....", "....WW.WWWWW.WWWWWW.WWWWW.WW....",
			"....WW.WWWWW........WWWWW.WW....", "....WW.WWWWWWWWWWWWWWWWWW.WW....", "....WW.WW..............WW.WW....", "....WW.WW.WWWWWWWWWWWW.WW.WW....", "....WW.WW......WW......WW.WW....", "......WWW.WWWWWWWWWWWW.WWW......", "......WWW.WWWWWWWWWWWW.WWW......", "......WWW.WWWWWWWWWWWW.WWW......", "......WWW..............WWW......", ".......WWWWWWWWWWWWWWWWWW.......",
			"........WWWWWWWWWWWWWWWW........", "................................"
		};

		private static Sprite _backpack;

		private static Sprite _backpackWhite;

		private static readonly (string palette, string[] rows)[] IconData = new(string, string[])[5]
		{
			("O:14100A W:F4F1E8 g:B8B2A2", new string[16]
			{
				"................", "................", "...OO......OO...", "..OWWO....OWWO..", "..OgWWO..OWWgO..", "...OgWWOOWWgO...", "....OgWWWWgO....", ".....OgWWgO.....", ".....OWWWWO.....", "....OWWggWWO....",
				"...OWWgOOgWWO...", "..OWWgO..OgWWO..", "..OggO....OggO..", "...OO......OO...", "................", "................"
			}),
			("O:0C200E G:6EE86E g:2F9A3A", new string[16]
			{
				"................", "................", "...........OOO..", "..........OGGgO.", ".........OGGgO..", "..OO....OGGgO...", ".OGGO..OGGgO....", ".OgGGOOGGgO.....", "..OgGGGGgO......", "...OgGGgO.......",
				"....OggO........", ".....OO.........", "................", "................", "................", "................"
			}),
			("O:14100A W:F4F1E8 g:B8B2A2", new string[16]
			{
				"................", "................", "................", "......OO........", ".....OWO........", "....OWWOOOOOOO..", "...OWWWWWWWWWWO.", "..OWWWWWWWWWWWgO", "...OgggWWggggggO", "....OggOOOOOOOO.",
				".....OgO........", "......OO........", "................", "................", "................", "................"
			}),
			("O:101418 A:8FD8A8 a:3F9A60 h:D8FFE4", new string[16]
			{
				"................", "................", "..OOOOO..OOOOO..", "..OhAAO..OhAAO..", "..OAAaO..OAAaO..", "..OAaaO..OAaaO..", "..OOOOO..OOOOO..", "................", "..OOOOO...OO....", "..OhAAO..OhAO...",
				"..OAAaO.OOhAOO..", "..OAaaO.OhhhaO..", "..OOOOO.OOaaOO..", "..........OaO...", "..........OO....", "................"
			}),
			("O:12141A W:EEF3F8 g:A6B2C0 Y:E8B840 y:A67A20 b:6E4424", new string[16]
			{
				"................", "............OOO.", "...........OWWO.", "..........OWWgO.", ".........OWWgO..", "........OWWgO...", ".......OWWgO....", "..OO..OWWgO.....", "..OYOOWWgO......", "...OYYWgO.......",
				"....OYyO........", "...ObOYyO.......", "..ObO.OYyO......", ".ObO...OO.......", ".OO.............", "................"
			})
		};

		private static readonly Texture2D[] Icons = (Texture2D[])(object)new Texture2D[IconData.Length];

		public static Sprite Backpack
		{
			get
			{
				if (!((Object)(object)_backpack != (Object)null))
				{
					return _backpack = Build(BackpackPixels, "O:24140A S:4A2E1A s:7A4E2C B:B8743E k:E0A060 b:8A5226 F:A8432E f:D0674A e:7A2E20 G:FFD84A Y:FFF2A8 g:C8961C P:9A6034 p:C08048", "Backpack_Icon");
				}
				return _backpack;
			}
		}

		public static Sprite BackpackWhite
		{
			get
			{
				if (!((Object)(object)_backpackWhite != (Object)null))
				{
					return _backpackWhite = Build(BackpackWhitePixels, "W:FFFFFF", "Backpack_WheelIcon");
				}
				return _backpackWhite;
			}
		}

		public static Texture2D Icon(UiIcon icon)
		{
			int num = (int)icon;
			if (num < 0 || num >= Icons.Length)
			{
				return Texture2D.whiteTexture;
			}
			if ((Object)(object)Icons[num] != (Object)null)
			{
				return Icons[num];
			}
			Icons[num] = BuildTexture(IconData[num].rows, IconData[num].palette, "Backpack_Icon_" + icon);
			return Icons[num];
		}

		public static Rect UV(Sprite sprite)
		{
			//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_004a: Unknown result type (might be due to invalid IL or missing references)
			Rect textureRect = sprite.textureRect;
			Texture2D texture = sprite.texture;
			return new Rect(((Rect)(ref textureRect)).x / (float)((Texture)texture).width, ((Rect)(ref textureRect)).y / (float)((Texture)texture).height, ((Rect)(ref textureRect)).width / (float)((Texture)texture).width, ((Rect)(ref textureRect)).height / (float)((Texture)texture).height);
		}

		private static Dictionary<char, Color> ParsePalette(string spec)
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<char, Color> dictionary = new Dictionary<char, Color>();
			string[] array = spec.Split(' ');
			foreach (string text in array)
			{
				if (text.Length == 8 && text[1] == ':')
				{
					int num = Convert.ToInt32(text.Substring(2), 16);
					dictionary[text[0]] = new Color((float)((num >> 16) & 0xFF) / 255f, (float)((num >> 8) & 0xFF) / 255f, (float)(num & 0xFF) / 255f, 1f);
				}
			}
			return dictionary;
		}

		private static Texture2D BuildTexture(string[] rows, string paletteSpec, string name)
		{
			//IL_0018: 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_0024: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<char, Color> dictionary = ParsePalette(paletteSpec);
			int num = rows.Length;
			int length = rows[0].Length;
			Texture2D val = new Texture2D(length, num, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)0,
				wrapMode = (TextureWrapMode)1,
				hideFlags = (HideFlags)61,
				name = name
			};
			Color[] array = (Color[])(object)new Color[length * num];
			for (int i = 0; i < num; i++)
			{
				if (rows[i].Length != length)
				{
					throw new InvalidOperationException($"{name}: linha {i} tem {rows[i].Length} pixels (esperado {length}).");
				}
				for (int j = 0; j < length; j++)
				{
					array[(num - 1 - i) * length + j] = (dictionary.TryGetValue(rows[i][j], out var value) ? value : Color.clear);
				}
			}
			val.SetPixels(array);
			val.Apply(false, false);
			return val;
		}

		private static Sprite Build(string[] rows, string paletteSpec, string name)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = BuildTexture(rows, paletteSpec, name);
			Sprite obj = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 32f, 0u, (SpriteMeshType)0);
			((Object)obj).name = name;
			((Object)obj).hideFlags = (HideFlags)61;
			return obj;
		}
	}
	internal enum ButtonKind
	{
		Green,
		Blue,
		Red,
		Gold,
		Dark
	}
	internal static class Ui
	{
		private sealed class Px
		{
			private readonly int _w;

			private readonly int _h;

			private readonly Color32[] _c;

			public Px(int w, int h)
			{
				_w = w;
				_h = h;
				_c = (Color32[])(object)new Color32[w * h];
			}

			public void Set(int x, int y, Color32 color)
			{
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: Unknown result type (might be due to invalid IL or missing references)
				if (x >= 0 && y >= 0 && x < _w && y < _h)
				{
					_c[(_h - 1 - y) * _w + x] = color;
				}
			}

			public void Fill(int x, int y, int w, int h, Color32 color)
			{
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				for (int i = y; i < y + h; i++)
				{
					for (int j = x; j < x + w; j++)
					{
						Set(j, i, color);
					}
				}
			}

			public void Round(int x0, int y0, int w, int h, int r, Color32 color)
			{
				//IL_002b: Unknown result type (might be due to invalid IL or missing references)
				for (int i = 0; i < h; i++)
				{
					for (int j = 0; j < w; j++)
					{
						if (Mathf.Min(j, w - 1 - j) + Mathf.Min(i, h - 1 - i) >= r)
						{
							Set(x0 + j, y0 + i, color);
						}
					}
				}
			}

			public Texture2D ToTexture(string name, int scale)
			{
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: 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)
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_0039: Expected O, but got Unknown
				//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)
				int num = _w * scale;
				int num2 = _h * scale;
				Texture2D val = new Texture2D(num, num2, (TextureFormat)4, false)
				{
					filterMode = (FilterMode)0,
					wrapMode = (TextureWrapMode)1,
					hideFlags = (HideFlags)61,
					name = name
				};
				Color32[] array = (Color32[])(object)new Color32[num * num2];
				for (int i = 0; i < num2; i++)
				{
					for (int j = 0; j < num; j++)
					{
						array[i * num + j] = _c[i / scale * _w + j / scale];
					}
				}
				val.SetPixels32(array);
				val.Apply(false, true);
				return val;
			}
		}

		public static readonly Color Ink = Rgb(724242);

		public static readonly Color Navy = Rgb(1251104);

		public static readonly Color NavyLight = Rgb(1777968);

		public static readonly Color Gold = Rgb(11903600);

		public static readonly Color Wood = Rgb(4992561);

		public static readonly Color WoodLight = Rgb(7029574);

		public static readonly Color WoodDark = Rgb(3021597);

		public static readonly Color Title = Rgb(16767370);

		public static readonly Color Text = Rgb(16052194);

		public static readonly Color Muted = Rgb(11120832);

		public static readonly Color Dim = Rgb(7107461);

		public static readonly Color Good = Rgb(10478490);

		public static readonly Color Bad = Rgb(16747136);

		public static readonly Color Warn = Rgb(16762489);

		private static Font _gameFont;

		private static float _nextFontSearch;

		private static int _fontSearches;

		private static Font _stylesFont;

		private static bool _stylesBuilt;

		public static GUIStyle TitleStyle;

		public static GUIStyle H1;

		public static GUIStyle H2;

		public static GUIStyle H3;

		public static GUIStyle Body;

		public static GUIStyle Small;

		public static GUIStyle Tiny;

		public static GUIStyle SmallWrap;

		public static GUIStyle ButtonText;

		public static GUIStyle ButtonSmallText;

		private static readonly GUIContent TempContent = new GUIContent();

		private static bool _texturesBuilt;

		private static GUIStyle _window;

		private static GUIStyle _header;

		private static GUIStyle _card;

		private static GUIStyle _inset;

		private static GUIStyle _tooltipBox;

		private static GUIStyle _slot;

		private static readonly GUIStyle[] ButtonNormal = (GUIStyle[])(object)new GUIStyle[5];

		private static readonly GUIStyle[] ButtonHover = (GUIStyle[])(object)new GUIStyle[5];

		private static readonly GUIStyle[] ButtonPressed = (GUIStyle[])(object)new GUIStyle[5];

		private static GUIStyle _buttonDisabled;

		private static Texture2D _glow;

		private static Texture2D _shade;

		private static readonly Vector2[] OutlineOffsets = (Vector2[])(object)new Vector2[8]
		{
			new Vector2(-1f, 0f),
			new Vector2(1f, 0f),
			new Vector2(0f, -1f),
			new Vector2(0f, 1f),
			new Vector2(-0.7f, -0.7f),
			new Vector2(0.7f, -0.7f),
			new Vector2(-0.7f, 0.7f),
			new Vector2(0.7f, 0.7f)
		};

		private static readonly Dictionary<int, float> HoverAmounts = new Dictionary<int, float>();

		private static readonly int ButtonHash = "BackpackUiButton".GetHashCode();

		private static string _tooltip;

		private static string _tooltipShown;

		private static float _tooltipSince;

		private static float _nextLog;

		public static Font GameFont
		{
			get
			{
				if ((Object)(object)_gameFont != (Object)null || Time.unscaledTime < _nextFontSearch)
				{
					return _gameFont;
				}
				_fontSearches++;
				_nextFontSearch = Time.unscaledTime + ((_fontSearches > 30) ? 30f : 2f);
				try
				{
					Font val = null;
					Font[] array = Resources.FindObjectsOfTypeAll<Font>();
					foreach (Font val2 in array)
					{
						if (!((Object)(object)val2 == (Object)null) && ((Object)val2).name != null && ((Object)val2).name.StartsWith("Jersey10", StringComparison.OrdinalIgnoreCase) && ((Object)(object)val == (Object)null || ((Object)val2).name.Equals("Jersey10-Regular", StringComparison.OrdinalIgnoreCase)))
						{
							val = val2;
						}
					}
					_gameFont = val;
				}
				catch (Exception ex)
				{
					LogOnce("fonte do jogo", ex);
				}
				return _gameFont;
			}
		}

		private static bool Repaint => (int)Event.current.type == 7;

		private static Color Rgb(int rgb)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			return new Color((float)((rgb >> 16) & 0xFF) / 255f, (float)((rgb >> 8) & 0xFF) / 255f, (float)(rgb & 0xFF) / 255f, 1f);
		}

		public static Color WithAlpha(Color c, float a)
		{
			//IL_0000: 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_000c: 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)
			return new Color(c.r, c.g, c.b, a);
		}

		public static float WindowScale(float width, float height, float margin = 16f)
		{
			float num = Mathf.Max(1f, (float)Screen.height / 1080f);
			float num2 = Mathf.Min(((float)Screen.width - margin) / width, ((float)Screen.height - margin) / height);
			return Mathf.Clamp(Mathf.Min(num, num2), 0.4f, 4f);
		}

		public static void EnsureStyles()
		{
			Font gameFont = GameFont;
			if (!_stylesBuilt || !((Object)(object)gameFont == (Object)(object)_stylesFont))
			{
				_stylesBuilt = true;
				_stylesFont = gameFont;
				float k = (((Object)(object)gameFont != (Object)null) ? 1f : 0.7f);
				TitleStyle = Make(gameFont, 42, k, (TextAnchor)3, wrap: false);
				H1 = Make(gameFont, 46, k, (TextAnchor)3, wrap: false);
				H2 = Make(gameFont, 32, k, (TextAnchor)3, wrap: false);
				H3 = Make(gameFont, 27, k, (TextAnchor)3, wrap: false);
				Body = Make(gameFont, 25, k, (TextAnchor)3, wrap: false);
				Small = Make(gameFont, 22, k, (TextAnchor)3, wrap: false);
				Tiny = Make(gameFont, 20, k, (TextAnchor)3, wrap: false);
				SmallWrap = Make(gameFont, 22, k, (TextAnchor)0, wrap: true);
				ButtonText = Make(gameFont, 27, k, (TextAnchor)3, wrap: false);
				ButtonSmallText = Make(gameFont, 23, k, (TextAnchor)3, wrap: false);
			}
		}

		private static GUIStyle Make(Font font, int size, float k, TextAnchor anchor, bool wrap)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: 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_0056: 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_0065: Expected O, but got Unknown
			//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_0074: Expected O, but got Unknown
			//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_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: 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_00a5: Expected O, but got Unknown
			GUIStyle val = new GUIStyle(GUI.skin.label)
			{
				font = font,
				fontSize = Mathf.Max(8, Mathf.RoundToInt((float)size * k)),
				fontStyle = (FontStyle)0,
				alignment = anchor,
				wordWrap = wrap,
				richText = false,
				clipping = (TextClipping)(wrap ? 1 : 0),
				padding = new RectOffset(0, 0, 0, 0),
				margin = new RectOffset(0, 0, 0, 0)
			};
			val.normal.textColor = Color.white;
			val.hover.textColor = Color.white;
			val.active.textColor = Color.white;
			return val;
		}

		public static float TextWidth(string text, GUIStyle style)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrEmpty(text))
			{
				return 0f;
			}
			TempContent.text = text;
			return style.CalcSize(TempContent).x;
		}

		public static float TextHeight(string text, GUIStyle style, float width)
		{
			if (string.IsNullOrEmpty(text))
			{
				return 0f;
			}
			TempContent.text = text;
			return style.CalcHeight(TempContent, width);
		}

		private static void EnsureTextures()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: 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_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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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_0075: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: 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_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: 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_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0335: Unknown result type (might be due to invalid IL or missing references)
			//IL_0365: Unknown result type (might be due to invalid IL or missing references)
			//IL_037b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03af: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0403: Unknown result type (might be due to invalid IL or missing references)
			//IL_041e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0457: Unknown result type (might be due to invalid IL or missing references)
			//IL_046a: Unknown result type (might be due to invalid IL or missing references)
			//IL_047a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0499: Unknown result type (might be due to invalid IL or missing references)
			//IL_04af: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0504: Unknown result type (might be due to invalid IL or missing references)
			//IL_0526: Unknown result type (might be due to invalid IL or missing references)
			//IL_053c: Unknown result type (might be due to invalid IL or missing references)
			//IL_054b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0567: Unknown result type (might be due to invalid IL or missing references)
			//IL_0577: Unknown result type (might be due to invalid IL or missing references)
			//IL_0587: Unknown result type (might be due to invalid IL or missing references)
			//IL_05aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_05af: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_05be: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05da: Unknown result type (might be due to invalid IL or missing references)
			//IL_05dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_05de: Unknown result type (might be due to invalid IL or missing references)
			//IL_0608: Unknown result type (might be due to invalid IL or missing references)
			//IL_060f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0614: Unknown result type (might be due to invalid IL or missing references)
			//IL_061b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0620: Unknown result type (might be due to invalid IL or missing references)
			//IL_0636: Unknown result type (might be due to invalid IL or missing references)
			//IL_0664: Unknown result type (might be due to invalid IL or missing references)
			//IL_066b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0670: Unknown result type (might be due to invalid IL or missing references)
			//IL_0672: Unknown result type (might be due to invalid IL or missing references)
			//IL_0674: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d7: Unknown result type (might be due to invalid IL or missing references)
			if (!_texturesBuilt || _window == null || !((Object)(object)_window.normal.background != (Object)null))
			{
				_texturesBuilt = true;
				Color32 val = Color32.op_Implicit(Ink);
				Color32 color = Color32.op_Implicit(Navy);
				Color32 color2 = Color32.op_Implicit(NavyLight);
				Color32 color3 = Color32.op_Implicit(Gold);
				Color32 color4 = Color32.op_Implicit(Wood);
				Color32 color5 = Color32.op_Implicit(WoodLight);
				Color32 color6 = Color32.op_Implicit(WoodDark);
				Color32 color7 = default(Color32);
				((Color32)(ref color7))..ctor((byte)37, (byte)44, (byte)61, byte.MaxValue);
				Color32 color8 = default(Color32);
				((Color32)(ref color8))..ctor((byte)96, (byte)91, (byte)77, byte.MaxValue);
				Px px = new Px(24, 24);
				px.Round(0, 0, 24, 24, 2, val);
				px.Round(1, 1, 22, 22, 1, color4);
				px.Fill(2, 1, 20, 1, color5);
				px.Fill(1, 2, 1, 19, color5);
				px.Fill(1, 22, 22, 1, color6);
				px.Fill(22, 2, 1, 20, color6);
				px.Fill(4, 4, 16, 16, color3);
				px.Fill(5, 5, 14, 14, val);
				px.Fill(6, 6, 12, 12, color);
				(int, int)[] array = new(int, int)[4]
				{
					(2, 2),
					(21, 2),
					(2, 21),
					(21, 21)
				};
				for (int i = 0; i < array.Length; i++)
				{
					var (x, y) = array[i];
					px.Set(x, y, new Color32(byte.MaxValue, (byte)216, (byte)106, byte.MaxValue));
				}
				_window = Nine(px.ToTexture("Backpack_UiWindow", 2), 12, 12, 12, 12);
				Px px2 = new Px(8, 16);
				px2.Fill(0, 0, 8, 16, color4);
				px2.Fill(0, 0, 8, 1, color5);
				px2.Fill(0, 5, 8, 1, color6);
				px2.Fill(0, 10, 8, 1, color6);
				px2.Fill(0, 6, 8, 1, new Color32((byte)88, (byte)54, (byte)57, byte.MaxValue));
				px2.Fill(0, 11, 8, 1, new Color32((byte)88, (byte)54, (byte)57, byte.MaxValue));
				px2.Fill(0, 13, 8, 1, color6);
				px2.Fill(0, 14, 8, 1, color3);
				px2.Fill(0, 15, 8, 1, val);
				_header = Nine(px2.ToTexture("Backpack_UiHeader", 2), 0, 0, 4, 6);
				Px px3 = new Px(12, 12);
				px3.Round(0, 0, 12, 12, 2, val);
				px3.Round(1, 1, 10, 10, 1, color8);
				px3.Fill(2, 2, 8, 8, color2);
				px3.Fill(2, 2, 8, 1, color7);
				_card = Nine(px3.ToTexture("Backpack_UiCard", 2), 8, 8, 8, 8);
				Px px4 = new Px(8, 8);
				px4.Round(0, 0, 8, 8, 1, val);
				px4.Fill(1, 1, 6, 6, new Color32((byte)14, (byte)17, (byte)24, byte.MaxValue));
				px4.Fill(1, 1, 6, 1, new Color32((byte)6, (byte)8, (byte)12, byte.MaxValue));
				px4.Fill(1, 6, 6, 1, new Color32((byte)36, (byte)42, (byte)58, byte.MaxValue));
				_inset = Nine(px4.ToTexture("Backpack_UiInset", 2), 6, 6, 6, 6);
				Px px5 = new Px(8, 8);
				px5.Round(0, 0, 8, 8, 1, color3);
				px5.Fill(1, 1, 6, 6, new Color32((byte)11, (byte)14, (byte)20, (byte)245));
				_tooltipBox = Nine(px5.ToTexture("Backpack_UiTooltip", 2), 6, 6, 6, 6);
				Px px6 = new Px(12, 12);
				px6.Round(0, 0, 12, 12, 2, val);
				px6.Round(1, 1, 10, 10, 1, new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue));
				px6.Fill(2, 2, 8, 8, new Color32((byte)16, (byte)19, (byte)28, byte.MaxValue));
				px6.Fill(2, 2, 8, 1, new Color32((byte)5, (byte)6, (byte)9, byte.MaxValue));
				px6.Fill(2, 9, 8, 1, new Color32((byte)34, (byte)40, (byte)54, byte.MaxValue));
				_slot = Nine(px6.ToTexture("Backpack_UiSlot", 2), 8, 8, 8, 8);
				(Color32, Color32, Color32)[] array2 = new(Color32, Color32, Color32)[5]
				{
					(new Color32((byte)31, (byte)154, (byte)18, byte.MaxValue), new Color32((byte)92, (byte)207, (byte)74, byte.MaxValue), new Color32((byte)12, (byte)69, (byte)10, byte.MaxValue)),
					(new Color32((byte)10, (byte)115, (byte)192, byte.MaxValue), new Color32((byte)72, (byte)168, (byte)240, byte.MaxValue), new Color32((byte)46, (byte)49, (byte)146, byte.MaxValue)),
					(new Color32((byte)178, (byte)36, (byte)46, byte.MaxValue), new Color32((byte)228, (byte)90, (byte)100, byte.MaxValue), new Color32((byte)109, (byte)36, (byte)46, byte.MaxValue)),
					(new Color32((byte)217, (byte)154, (byte)18, byte.MaxValue), new Color32(byte.MaxValue, (byte)212, (byte)90, byte.MaxValue), new Color32((byte)122, (byte)74, (byte)8, byte.MaxValue)),
					(new Color32((byte)43, (byte)49, (byte)66, byte.MaxValue), new Color32((byte)70, (byte)80, (byte)106, byte.MaxValue), new Color32((byte)20, (byte)24, (byte)33, byte.MaxValue))
				};
				for (int j = 0; j < array2.Length; j++)
				{
					var (val2, val3, lip) = array2[j];
					ButtonNormal[j] = Nine(ButtonTexture($"Backpack_UiButton{j}", val2, val3, lip, val, pressed: false), 6, 6, 6, 10);
					ButtonHover[j] = Nine(ButtonTexture($"Backpack_UiButton{j}Hover", Lighten(val2, 0.16f), Lighten(val3, 0.2f), lip, new Color32(byte.MaxValue, (byte)226, (byte)154, byte.MaxValue), pressed: false), 6, 6, 6, 10);
					ButtonPressed[j] = Nine(ButtonTexture($"Backpack_UiButton{j}Pressed", Darken(val2, 0.1f), val2, lip, val, pressed: true), 6, 6, 6, 10);
				}
				_buttonDisabled = Nine(ButtonTexture("Backpack_UiButtonDisabled", new Color32((byte)58, (byte)63, (byte)74, byte.MaxValue), new Color32((byte)74, (byte)80, (byte)92, byte.MaxValue), new Color32((byte)35, (byte)38, (byte)45, byte.MaxValue), new Color32((byte)17, (byte)19, (byte)24, byte.MaxValue), pressed: false), 6, 6, 6, 10);
				_glow = RadialTexture("Backpack_UiGlow", 48, 2f);
				_shade = RadialTexture("Backpack_UiShade", 48, 1.2f);
			}
		}

		private static Texture2D ButtonTexture(string name, Color32 fill, Color32 light, Color32 lip, Color32 outline, bool pressed)
		{
			//IL_0012: 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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			Px px = new Px(16, 16);
			px.Round(0, 0, 16, 16, 2, outline);
			px.Round(1, 1, 14, 14, 1, lip);
			if (pressed)
			{
				px.Fill(1, 3, 14, 11, fill);
				px.Fill(2, 3, 12, 1, light);
			}
			else
			{
				px.Fill(2, 1, 12, 11, fill);
				px.Fill(1, 2, 14, 10, fill);
				px.Fill(2, 1, 12, 1, light);
				px.Set(1, 2, light);
				px.Set(14, 2, light);
				px.Fill(1, 11, 14, 1, Darken(fill, 0.12f));
			}
			return px.ToTexture(name, 2);
		}

		private static Texture2D RadialTexture(string name, int size, float power)
		{
			//IL_0004: 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_0010: 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_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(size, size, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)1,
				wrapMode = (TextureWrapMode)1,
				hideFlags = (HideFlags)61,
				name = name
			};
			Color32[] array = (Color32[])(object)new Color32[size * size];
			float num = (float)(size - 1) / 2f;
			for (int i = 0; i < size; i++)
			{
				for (int j = 0; j < size; j++)
				{
					float num2 = Mathf.Sqrt(((float)j - num) * ((float)j - num) + ((float)i - num) * ((float)i - num)) / num;
					float num3 = Mathf.Pow(Mathf.Clamp01(1f - num2), power);
					array[i * size + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)Mathf.RoundToInt(num3 * 255f));
				}
			}
			val.SetPixels32(array);
			val.Apply(false, true);
			return val;
		}

		private static Color32 Lighten(Color32 c, float k)
		{
			//IL_0005: 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_0027: 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_0049: 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_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			return new Color32((byte)Mathf.Min(255f, (float)(int)c.r + (float)(255 - c.r) * k), (byte)Mathf.Min(255f, (float)(int)c.g + (float)(255 - c.g) * k), (byte)Mathf.Min(255f, (float)(int)c.b + (float)(255 - c.b) * k), c.a);
		}

		private static Color32 Darken(Color32 c, float k)
		{
			//IL_0000: 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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			return new Color32((byte)((float)(int)c.r * (1f - k)), (byte)((float)(int)c.g * (1f - k)), (byte)((float)(int)c.b * (1f - k)), c.a);
		}

		private static GUIStyle Nine(Texture2D tex, int left, int right, int top, int bottom)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: 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_0015: Expected O, but got Unknown
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			GUIStyle val = new GUIStyle
			{
				border = new RectOffset(left, right, top, bottom)
			};
			val.normal.background = tex;
			return val;
		}

		private static void Draw(Rect r, GUIStyle style)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			if (Repaint && style != null && ((Rect)(ref r)).width > 0f && ((Rect)(ref r)).height > 0f)
			{
				style.Draw(r, false, false, false, false);
			}
		}

		private static void Draw(Rect r, GUIStyle style, Color tint)
		{
			//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_000e: 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_001b: 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_0028: 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_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_0042: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			if (Repaint)
			{
				Color color =