Decompiled source of SonicChestFilters v1.0.3

SonicChestFilters.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Entities;
using Jotunn.Managers;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SonicChestFilters")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3+9050a29db8455e9665c71eae165038e899382e68")]
[assembly: AssemblyProduct("SonicChestFilters")]
[assembly: AssemblyTitle("SonicChestFilters")]
[assembly: AssemblyVersion("1.0.3.0")]
[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 SonicChestFilters
{
	internal static class ChestFilter
	{
		private sealed class ElementVisualState
		{
			internal readonly bool IconEnabled;

			internal readonly bool AmountEnabled;

			internal readonly bool QualityEnabled;

			internal readonly bool EquippedEnabled;

			internal readonly bool QueuedEnabled;

			internal readonly bool NoTeleportEnabled;

			internal readonly bool FoodEnabled;

			internal readonly bool DurabilityActive;

			internal readonly bool ButtonInteractable;

			internal readonly bool TooltipEnabled;

			internal readonly bool CanBeDroppedOn;

			internal ElementVisualState(InventoryElement element)
			{
				//IL_0084: Unknown result type (might be due to invalid IL or missing references)
				//IL_008f: Expected O, but got Unknown
				//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bb: Expected O, but got Unknown
				//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e2: Expected O, but got Unknown
				IconEnabled = IsEnabled((Graphic)(object)element.m_icon);
				AmountEnabled = IsEnabled((Graphic)(object)element.m_amount);
				QualityEnabled = IsEnabled((Graphic)(object)element.m_quality);
				EquippedEnabled = IsEnabled((Graphic)(object)element.m_equiped);
				QueuedEnabled = IsEnabled((Graphic)(object)element.m_queued);
				NoTeleportEnabled = IsEnabled((Graphic)(object)element.m_noteleport);
				FoodEnabled = IsEnabled((Graphic)(object)element.m_food);
				DurabilityActive = (Object)element.m_durability != (Object)null && ((Component)element.m_durability).gameObject.activeSelf;
				ButtonInteractable = (Object)element.m_button != (Object)null && ((Selectable)element.m_button).interactable;
				TooltipEnabled = (Object)element.m_tooltip != (Object)null && ((Behaviour)element.m_tooltip).enabled;
				CanBeDroppedOn = element.m_canBeDroppedOn;
			}

			private static bool IsEnabled(Graphic graphic)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Expected O, but got Unknown
				if ((Object)graphic != (Object)null)
				{
					return ((Behaviour)graphic).enabled;
				}
				return false;
			}
		}

		private static readonly Dictionary<InventoryElement, ElementVisualState> HiddenElementStates = new Dictionary<InventoryElement, ElementVisualState>();

		internal static string Query { get; private set; } = string.Empty;

		internal static bool HasQuery => !string.IsNullOrWhiteSpace(Query);

		internal static void SetQuery(string query)
		{
			Query = query ?? string.Empty;
		}

		internal static void Clear()
		{
			Query = string.Empty;
		}

		internal static void Refresh()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			InventoryGui instance = InventoryGui.instance;
			if (!((Object)instance == (Object)null))
			{
				InventoryGrid val = GameAccess.Get<InventoryGrid>(instance, "m_containerGrid");
				Container val2 = GameAccess.Get<Container>(instance, "m_currentContainer");
				Inventory val3 = (((Object)val2 != (Object)null) ? val2.GetInventory() : null);
				if ((Object)val != (Object)null && val3 != null)
				{
					ApplyToGrid(val, val3);
				}
			}
		}

		internal static bool ItemIsVisible(ItemData item)
		{
			if (!HasQuery)
			{
				return true;
			}
			if (item?.m_shared == null)
			{
				return true;
			}
			string matchedLabel;
			return ItemMatch.ItemMatchesPattern(item, Query.Trim(), out matchedLabel);
		}

		internal static void ApplyToGrid(InventoryGrid grid, Inventory inventory)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)grid == (Object)null || inventory == null || !(AccessTools.Field(typeof(InventoryGrid), "m_elements")?.GetValue(grid) is List<InventoryElement> list))
			{
				return;
			}
			for (int i = 0; i < list.Count; i++)
			{
				InventoryElement val = list[i];
				if (!((Object)val == (Object)null))
				{
					if (!HasQuery || !val.m_used)
					{
						RestoreElement(val);
					}
					else if (ItemIsVisible(inventory.GetItemAt(val.Position.x, val.Position.y)))
					{
						RestoreElement(val);
					}
					else
					{
						HideOccupied(val);
					}
				}
			}
		}

		private static void RestoreClickable(InventoryElement element)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			if ((Object)element.m_button != (Object)null)
			{
				((Selectable)element.m_button).interactable = true;
			}
		}

		private static void RestoreElement(InventoryElement element)
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Expected O, but got Unknown
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Expected O, but got Unknown
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Expected O, but got Unknown
			if (HiddenElementStates.TryGetValue(element, out var value))
			{
				SetGraphicEnabled((Graphic)(object)element.m_icon, value.IconEnabled);
				SetGraphicEnabled((Graphic)(object)element.m_amount, value.AmountEnabled);
				SetGraphicEnabled((Graphic)(object)element.m_quality, value.QualityEnabled);
				SetGraphicEnabled((Graphic)(object)element.m_equiped, value.EquippedEnabled);
				SetGraphicEnabled((Graphic)(object)element.m_queued, value.QueuedEnabled);
				SetGraphicEnabled((Graphic)(object)element.m_noteleport, value.NoTeleportEnabled);
				SetGraphicEnabled((Graphic)(object)element.m_food, value.FoodEnabled);
				if ((Object)element.m_durability != (Object)null)
				{
					((Component)element.m_durability).gameObject.SetActive(value.DurabilityActive);
				}
				if ((Object)element.m_button != (Object)null)
				{
					((Selectable)element.m_button).interactable = value.ButtonInteractable;
				}
				if ((Object)element.m_tooltip != (Object)null)
				{
					((Behaviour)element.m_tooltip).enabled = value.TooltipEnabled;
				}
				element.m_canBeDroppedOn = value.CanBeDroppedOn;
				HiddenElementStates.Remove(element);
			}
			else
			{
				RestoreClickable(element);
				if (element.m_used)
				{
					RestoreTooltip(element);
				}
			}
		}

		private static void RestoreTooltip(InventoryElement element)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			if ((Object)element.m_tooltip != (Object)null)
			{
				((Behaviour)element.m_tooltip).enabled = true;
			}
		}

		private static void HideOccupied(InventoryElement element)
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			if (!HiddenElementStates.ContainsKey(element))
			{
				HiddenElementStates[element] = new ElementVisualState(element);
			}
			SetGraphicEnabled((Graphic)(object)element.m_icon, enabled: false);
			SetGraphicEnabled((Graphic)(object)element.m_amount, enabled: false);
			SetGraphicEnabled((Graphic)(object)element.m_quality, enabled: false);
			SetGraphicEnabled((Graphic)(object)element.m_equiped, enabled: false);
			SetGraphicEnabled((Graphic)(object)element.m_queued, enabled: false);
			SetGraphicEnabled((Graphic)(object)element.m_noteleport, enabled: false);
			SetGraphicEnabled((Graphic)(object)element.m_food, enabled: false);
			if ((Object)element.m_durability != (Object)null)
			{
				((Component)element.m_durability).gameObject.SetActive(false);
			}
			if ((Object)element.m_button != (Object)null)
			{
				((Selectable)element.m_button).interactable = false;
			}
			element.m_canBeDroppedOn = false;
		}

		private static void SetGraphicEnabled(Graphic graphic, bool enabled)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			if ((Object)graphic != (Object)null)
			{
				((Behaviour)graphic).enabled = enabled;
			}
		}
	}
	internal static class ChestPanelUi
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static UnityAction <0>__ToggleFilterPane;

			public static UnityAction <1>__ToggleSortOptionsPane;

			public static UnityAction <2>__OnSortClicked;

			public static UnityAction <3>__OnQuickStackClicked;

			public static UnityAction <4>__OnRestockClicked;

			public static UnityAction<string> <5>__ApplyFilterQuery;

			public static UnityAction <6>__OnClearClicked;

			public static UnityAction <7>__ApplyFilterFromButton;
		}

		private const string FilterRootName = "SonicChestFilters_Root";

		private const float ToolbarHeight = 0f;

		private const float FilterPaneHeight = 78f;

		private static GameObject _root;

		private static Button _clearButton;

		private static Button _applyButton;

		private static Button _filterButton;

		private static Button _sortButton;

		private static Button _sortOptionsButton;

		private static Button _quickStackButton;

		private static Button _restockButton;

		private static GameObject _filterPane;

		private static GameObject _sortOptionsPane;

		private static InputField _filterInput;

		private static Container _boundContainer;

		private static bool _expanded;

		private static bool _filterPaneExpanded;

		internal static bool FilterFieldFocused
		{
			get
			{
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Expected O, but got Unknown
				if ((Object)_filterInput != (Object)null)
				{
					return _filterInput.isFocused;
				}
				return false;
			}
		}

		internal static void EnsureControls(InventoryGui gui)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_005c: 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_006c: Expected O, but got Unknown
			//IL_006c: Expected O, but got Unknown
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Expected O, but got Unknown
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Expected O, but got Unknown
			if ((Object)gui == (Object)null || (Object)gui.m_container == (Object)null)
			{
				return;
			}
			if (SonicChestFiltersPlugin.Enabled == null || !SonicChestFiltersPlugin.Enabled.Value)
			{
				DestroyControls(gui);
				return;
			}
			Container val = GameAccess.Get<Container>(gui, "m_currentContainer");
			if ((Object)val == (Object)null)
			{
				return;
			}
			if ((Object)_boundContainer != (Object)val)
			{
				RestoreFrame(gui);
				DestroyWidgets();
			}
			if (GUIManager.Instance != null)
			{
				if ((Object)_root == (Object)null)
				{
					CreateToolbar(gui, val);
					_boundContainer = val;
				}
				ApplyFrameLayout(gui);
				if ((Object)_filterPane == (Object)null && (Object)_filterButton != (Object)null)
				{
					CreateFilterPane(_root.GetComponent<RectTransform>());
				}
				RefreshClearButton();
			}
		}

		internal static void ResetFilterText()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			ChestFilter.Clear();
			if ((Object)_filterInput != (Object)null)
			{
				_filterInput.SetTextWithoutNotify(string.Empty);
			}
			RefreshClearButton();
			ChestFilter.Refresh();
		}

		internal static void DestroyControls()
		{
			DestroyControls(InventoryGui.instance);
		}

		internal static void DestroyControls(InventoryGui gui)
		{
			RestoreFrame(gui);
			DestroyWidgets();
			_boundContainer = null;
		}

		private static void CreateToolbar(InventoryGui gui, Container current)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: 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_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Expected O, but got Unknown
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Expected O, but got Unknown
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Expected O, but got Unknown
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Expected O, but got Unknown
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Expected O, but got Unknown
			//IL_02a8: 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_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Expected O, but got Unknown
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Expected O, but got Unknown
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Expected O, but got Unknown
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			//IL_032d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0338: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			//IL_035b: Expected O, but got Unknown
			//IL_028d: 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_0298: Expected O, but got Unknown
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Expected O, but got Unknown
			//IL_0395: Unknown result type (might be due to invalid IL or missing references)
			//IL_039a: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Expected O, but got Unknown
			RectTransform container = gui.m_container;
			_root = new GameObject("SonicChestFilters_Root", new Type[1] { typeof(RectTransform) });
			_root.transform.SetParent((Transform)(object)container, false);
			RectTransform component = _root.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0f, 1f);
			component.anchorMax = new Vector2(1f, 1f);
			component.pivot = new Vector2(0.5f, 1f);
			component.sizeDelta = new Vector2(0f, 0f);
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(1f, 1f);
			if (SonicChestFiltersPlugin.EnableFilterBox == null || SonicChestFiltersPlugin.EnableFilterBox.Value)
			{
				GameObject val2 = GUIManager.Instance.CreateButton("Filter", (Transform)(object)component, val, val, new Vector2(42f, -16f), 84f, 28f);
				if ((Object)val2 != (Object)null)
				{
					((Object)val2).name = "SonicChestFilters_FilterButton";
					_filterButton = val2.GetComponent<Button>();
					if ((Object)_filterButton != (Object)null)
					{
						ButtonClickedEvent onClick = _filterButton.onClick;
						object obj = <>O.<0>__ToggleFilterPane;
						if (obj == null)
						{
							UnityAction val3 = ToggleFilterPane;
							<>O.<0>__ToggleFilterPane = val3;
							obj = (object)val3;
						}
						((UnityEvent)onClick).AddListener((UnityAction)obj);
					}
				}
			}
			GameObject val4 = GUIManager.Instance.CreateButton("Options", (Transform)(object)component, val, val, new Vector2(42f, -80f), 84f, 28f);
			if ((Object)val4 != (Object)null)
			{
				((Object)val4).name = "SonicChestFilters_SortOptionsButton";
				_sortOptionsButton = val4.GetComponent<Button>();
				Button sortOptionsButton = _sortOptionsButton;
				if (sortOptionsButton != null)
				{
					ButtonClickedEvent onClick2 = sortOptionsButton.onClick;
					object obj2 = <>O.<1>__ToggleSortOptionsPane;
					if (obj2 == null)
					{
						UnityAction val5 = ToggleSortOptionsPane;
						<>O.<1>__ToggleSortOptionsPane = val5;
						obj2 = (object)val5;
					}
					((UnityEvent)onClick2).AddListener((UnityAction)obj2);
				}
				_sortOptionsPane = SortOptionsPanel.Create(component, val, new Vector2(86f, -80f), chest: true, current);
			}
			if (SonicChestFiltersPlugin.EnableSortButton == null || SonicChestFiltersPlugin.EnableSortButton.Value)
			{
				GameObject val6 = GUIManager.Instance.CreateButton(ModLocalization.Translate("$sonic_chestfilters_sort", "Sort"), (Transform)(object)component, val, val, new Vector2(42f, -48f), 84f, 28f);
				if ((Object)val6 != (Object)null)
				{
					((Object)val6).name = "SonicChestFilters_Sort";
					_sortButton = val6.GetComponent<Button>();
					if ((Object)_sortButton != (Object)null)
					{
						ButtonClickedEvent onClick3 = _sortButton.onClick;
						object obj3 = <>O.<2>__OnSortClicked;
						if (obj3 == null)
						{
							UnityAction val7 = OnSortClicked;
							<>O.<2>__OnSortClicked = val7;
							obj3 = (object)val7;
						}
						((UnityEvent)onClick3).AddListener((UnityAction)obj3);
					}
				}
			}
			GameObject val8 = GUIManager.Instance.CreateButton("Quick Stack", (Transform)(object)component, val, val, new Vector2(42f, -112f), 84f, 28f);
			if ((Object)val8 != (Object)null)
			{
				((Object)val8).name = "SonicChestFilters_QuickStack";
				_quickStackButton = val8.GetComponent<Button>();
				Button quickStackButton = _quickStackButton;
				if (quickStackButton != null)
				{
					ButtonClickedEvent onClick4 = quickStackButton.onClick;
					object obj4 = <>O.<3>__OnQuickStackClicked;
					if (obj4 == null)
					{
						UnityAction val9 = OnQuickStackClicked;
						<>O.<3>__OnQuickStackClicked = val9;
						obj4 = (object)val9;
					}
					((UnityEvent)onClick4).AddListener((UnityAction)obj4);
				}
			}
			GameObject val10 = GUIManager.Instance.CreateButton("Restock", (Transform)(object)component, val, val, new Vector2(42f, -144f), 84f, 28f);
			if ((Object)val10 != (Object)null)
			{
				((Object)val10).name = "SonicChestFilters_Restock";
				_restockButton = val10.GetComponent<Button>();
				Button restockButton = _restockButton;
				if (restockButton != null)
				{
					ButtonClickedEvent onClick5 = restockButton.onClick;
					object obj5 = <>O.<4>__OnRestockClicked;
					if (obj5 == null)
					{
						UnityAction val11 = OnRestockClicked;
						<>O.<4>__OnRestockClicked = val11;
						obj5 = (object)val11;
					}
					((UnityEvent)onClick5).AddListener((UnityAction)obj5);
				}
			}
			ChestFilter.Clear();
			ChestSort.ResetSession();
		}

		private static void CreateFilterPane(RectTransform parent)
		{
			//IL_0010: 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_002e: 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_0058: Expected O, but got Unknown
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Expected O, but got Unknown
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Expected O, but got Unknown
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Expected O, but got Unknown
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Expected O, but got Unknown
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Expected O, but got Unknown
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Expected O, but got Unknown
			//IL_025d: 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_0268: Expected O, but got Unknown
			//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_0308: Expected O, but got Unknown
			_filterPane = GUIManager.Instance.CreateWoodpanel((Transform)(object)parent, new Vector2(1f, 1f), new Vector2(1f, 1f), new Vector2(68f, -16f), 220f, 78f, false);
			if ((Object)_filterPane == (Object)null)
			{
				return;
			}
			((Object)_filterPane).name = "SonicChestFilters_FilterPane";
			RectTransform component = _filterPane.GetComponent<RectTransform>();
			component.pivot = new Vector2(0f, 1f);
			RectTransform anchor = (((Object)_filterButton == (Object)null) ? null : ((Component)_filterButton).GetComponent<RectTransform>());
			if (!FilterPopupCanvas.MoveToFrontCanvas(_filterPane, anchor, new Vector2(4f, -14f)))
			{
				ManualLogSource modLogger = SonicChestFiltersPlugin.ModLogger;
				if (modLogger != null)
				{
					modLogger.LogWarning((object)"Could not place the chest filter pane on Jötunn's front canvas.");
				}
			}
			GameObject val = GUIManager.Instance.CreateInputField((Transform)(object)component, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -25f), (ContentType)0, ModLocalization.Translate("$sonic_chestfilters_filter", "Filter..."), 16, 194f, 28f);
			if ((Object)val != (Object)null)
			{
				((Object)val).name = "SonicChestFilters_FilterField";
				_filterInput = val.GetComponent<InputField>();
				if ((Object)_filterInput != (Object)null)
				{
					_filterInput.characterLimit = 64;
					_filterInput.SetTextWithoutNotify(ChestFilter.Query);
					((UnityEvent<string>)(object)_filterInput.onEndEdit).AddListener((UnityAction<string>)ApplyFilterQuery);
					val.AddComponent<FilterInputFocusHandler>().Bind(_filterInput);
				}
			}
			GameObject val2 = GUIManager.Instance.CreateButton(ModLocalization.Translate("$sonic_chestfilters_clear", "Clear"), (Transform)(object)component, new Vector2(0f, 0f), new Vector2(0f, 0f), new Vector2(48f, 17f), 72f, 28f);
			if ((Object)val2 != (Object)null)
			{
				((Object)val2).name = "SonicChestFilters_Clear";
				_clearButton = val2.GetComponent<Button>();
				if ((Object)_clearButton != (Object)null)
				{
					ButtonClickedEvent onClick = _clearButton.onClick;
					object obj = <>O.<6>__OnClearClicked;
					if (obj == null)
					{
						UnityAction val3 = OnClearClicked;
						<>O.<6>__OnClearClicked = val3;
						obj = (object)val3;
					}
					((UnityEvent)onClick).AddListener((UnityAction)obj);
				}
			}
			GameObject val4 = GUIManager.Instance.CreateButton("Apply", (Transform)(object)component, new Vector2(0f, 0f), new Vector2(0f, 0f), new Vector2(137f, 17f), 72f, 28f);
			if ((Object)val4 != (Object)null)
			{
				((Object)val4).name = "SonicChestFilters_Apply";
				_applyButton = val4.GetComponent<Button>();
				Button applyButton = _applyButton;
				if (applyButton != null)
				{
					ButtonClickedEvent onClick2 = applyButton.onClick;
					object obj2 = <>O.<7>__ApplyFilterFromButton;
					if (obj2 == null)
					{
						UnityAction val5 = ApplyFilterFromButton;
						<>O.<7>__ApplyFilterFromButton = val5;
						obj2 = (object)val5;
					}
					((UnityEvent)onClick2).AddListener((UnityAction)obj2);
				}
			}
			_filterPane.SetActive(false);
		}

		private static void ToggleFilterPane()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)_filterPane == (Object)null)
			{
				return;
			}
			bool num = !_filterPaneExpanded;
			if (num)
			{
				PlayerInventoryPanelUi.CloseAdvancedPane();
				FilterPopupCanvas.MoveToFrontCanvas(anchor: ((Object)_filterButton == (Object)null) ? null : ((Component)_filterButton).GetComponent<RectTransform>(), popup: _filterPane, localOffset: new Vector2(4f, -14f));
			}
			SetFilterPaneExpanded(num);
			_filterPane.SetActive(_filterPaneExpanded);
			if (_filterPaneExpanded && (Object)_sortOptionsPane != (Object)null)
			{
				_sortOptionsPane.SetActive(false);
			}
			if (_filterPaneExpanded)
			{
				InputField filterInput = _filterInput;
				if (filterInput != null)
				{
					filterInput.ActivateInputField();
				}
			}
			else
			{
				InputField filterInput2 = _filterInput;
				if (filterInput2 != null)
				{
					filterInput2.DeactivateInputField();
				}
			}
		}

		internal static void CloseFilterPane()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			if ((Object)_filterPane != (Object)null)
			{
				_filterPane.SetActive(false);
			}
			SetFilterPaneExpanded(expanded: false);
			InputField filterInput = _filterInput;
			if (filterInput != null)
			{
				filterInput.DeactivateInputField();
			}
		}

		private static void ToggleSortOptionsPane()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			if ((Object)_sortOptionsPane == (Object)null)
			{
				return;
			}
			if (_filterPaneExpanded)
			{
				SetFilterPaneExpanded(expanded: false);
				_filterPane.SetActive(false);
				InputField filterInput = _filterInput;
				if (filterInput != null)
				{
					filterInput.DeactivateInputField();
				}
			}
			_sortOptionsPane.SetActive(!_sortOptionsPane.activeSelf);
		}

		private static void SetFilterPaneExpanded(bool expanded)
		{
			if (_filterPaneExpanded != expanded)
			{
				_filterPaneExpanded = expanded;
			}
		}

		private static void ApplyFrameLayout(InventoryGui gui)
		{
			if (!_expanded)
			{
				_expanded = true;
			}
			PositionToolbar(gui);
		}

		private static void RestoreFrame(InventoryGui gui)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			if (!_expanded || (Object)gui == (Object)null || (Object)gui.m_container == (Object)null)
			{
				_expanded = false;
				return;
			}
			_filterPaneExpanded = false;
			_expanded = false;
		}

		private static void PositionToolbar(InventoryGui gui)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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_006b: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: 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_00d9: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)_root == (Object)null))
			{
				RectTransform container = gui.m_container;
				RectTransform component = _root.GetComponent<RectTransform>();
				component.anchorMin = new Vector2(0f, 1f);
				component.anchorMax = new Vector2(1f, 1f);
				component.pivot = new Vector2(0.5f, 1f);
				component.offsetMin = new Vector2(10f, component.offsetMin.y);
				component.offsetMax = new Vector2(-10f, component.offsetMax.y);
				float headerBottomLocalY = GetHeaderBottomLocalY(gui, container);
				Vector2 anchoredPosition = component.anchoredPosition;
				anchoredPosition.y = LocalYToTopOffset(container, headerBottomLocalY) - 2f;
				component.anchoredPosition = anchoredPosition;
				Vector2 sizeDelta = component.sizeDelta;
				sizeDelta.y = 0f;
				component.sizeDelta = sizeDelta;
			}
		}

		private static float LocalYToTopOffset(RectTransform container, float localY)
		{
			//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_0010: Unknown result type (might be due to invalid IL or missing references)
			Rect rect = container.rect;
			float height = ((Rect)(ref rect)).height;
			float y = container.pivot.y;
			float num = (1f - y) * height;
			return localY - num;
		}

		private static float GetHeaderBottomLocalY(InventoryGui gui, RectTransform container)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			float lowest = float.PositiveInfinity;
			ConsiderHeader((Component)(object)gui.m_stackAllButton, container, ref lowest);
			ConsiderHeader((Component)(object)gui.m_takeAllButton, container, ref lowest);
			ConsiderHeader((Component)(object)gui.m_containerName, container, ref lowest);
			if (float.IsPositiveInfinity(lowest))
			{
				Rect rect = container.rect;
				float height = ((Rect)(ref rect)).height;
				return (1f - container.pivot.y) * height - 36f;
			}
			return lowest;
		}

		private static void ConsiderHeader(Component component, RectTransform container, ref float lowest)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)component == (Object)null)
			{
				return;
			}
			RectTransform component2 = component.GetComponent<RectTransform>();
			if (!((Object)component2 == (Object)null) && ((Component)component2).gameObject.activeInHierarchy)
			{
				Vector3[] array = (Vector3[])(object)new Vector3[4];
				component2.GetWorldCorners(array);
				Vector3 val = ((Transform)container).InverseTransformPoint(array[0]);
				if (val.y < lowest)
				{
					lowest = val.y;
				}
			}
		}

		private static RectTransform GetGridShiftTarget(InventoryGui gui)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			//IL_0032: 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_0047: Expected O, but got Unknown
			//IL_0047: Expected O, but got Unknown
			//IL_0064: 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: Expected O, but got Unknown
			//IL_0079: Expected O, but got Unknown
			InventoryGrid val = GameAccess.Get<InventoryGrid>(gui, "m_containerGrid");
			if ((Object)val == (Object)null)
			{
				return null;
			}
			RectTransform component = ((Component)val).GetComponent<RectTransform>();
			if ((Object)component != (Object)null && (Object)component != (Object)gui.m_container)
			{
				return component;
			}
			if ((Object)val.m_gridRoot != (Object)null && (Object)val.m_gridRoot != (Object)gui.m_container)
			{
				return val.m_gridRoot;
			}
			return null;
		}

		private static RectTransform FindBackground(RectTransform container)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_0042: 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_0052: Expected O, but got Unknown
			//IL_0052: Expected O, but got Unknown
			if ((Object)container == (Object)null)
			{
				return null;
			}
			Transform val = ((Transform)container).Find("Bkg");
			if ((Object)val == (Object)null)
			{
				return null;
			}
			RectTransform val2 = (RectTransform)(object)((val is RectTransform) ? val : null);
			if ((Object)val2 == (Object)null || (Object)val2 == (Object)container)
			{
				return null;
			}
			return val2;
		}

		private static void GrowDown(RectTransform rt, float extra)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0010: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)rt == (Object)null))
			{
				if (!Mathf.Approximately(rt.anchorMin.y, rt.anchorMax.y))
				{
					Vector2 offsetMin = rt.offsetMin;
					offsetMin.y -= extra;
					rt.offsetMin = offsetMin;
				}
				else
				{
					Rect rect = rt.rect;
					float height = ((Rect)(ref rect)).height;
					rt.SetSizeWithCurrentAnchors((Axis)1, height + extra);
					rt.anchoredPosition += new Vector2(0f, (0f - extra) * (1f - rt.pivot.y));
				}
			}
		}

		private static void ShiftDown(RectTransform rt, float extra)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0011: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)rt == (Object)null))
			{
				rt.anchoredPosition += new Vector2(0f, 0f - extra);
			}
		}

		private static void DestroyWidgets()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			InputField filterInput = _filterInput;
			if (filterInput != null)
			{
				filterInput.DeactivateInputField();
			}
			if ((Object)_filterPane != (Object)null)
			{
				_filterPane.SetActive(false);
				Object.Destroy((Object)(object)_filterPane);
			}
			_filterInput = null;
			_clearButton = null;
			_applyButton = null;
			_filterButton = null;
			_sortButton = null;
			_sortOptionsButton = null;
			_quickStackButton = null;
			_restockButton = null;
			_filterPane = null;
			_sortOptionsPane = null;
			_filterPaneExpanded = false;
			if ((Object)_root != (Object)null)
			{
				Object.Destroy((Object)(object)_root);
				_root = null;
			}
		}

		private static void OnClearClicked()
		{
			ResetFilterText();
		}

		private static void ApplyFilterFromButton()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			ApplyFilterQuery(((Object)_filterInput == (Object)null) ? string.Empty : _filterInput.text);
		}

		private static void ApplyFilterQuery(string query)
		{
			query = query ?? string.Empty;
			if (!(query == ChestFilter.Query))
			{
				ChestFilter.SetQuery(query);
				RefreshClearButton();
				ChestFilter.Refresh();
			}
		}

		private static void OnSortClicked()
		{
			ChestSort.SortCurrent(InventoryGui.instance);
			RefreshContainerGrid();
		}

		private static void OnQuickStackClicked()
		{
			if (ChestTransferActions.QuickStack(InventoryGui.instance, out var movedCount, out var reason))
			{
				SonicChestFiltersPlugin.Debug((movedCount > 0) ? ("Quick stacked " + movedCount + " items into nearby chests.") : reason);
				RefreshPlayerGrid();
				RefreshContainerGrid();
				return;
			}
			ManualLogSource modLogger = SonicChestFiltersPlugin.ModLogger;
			if (modLogger != null)
			{
				modLogger.LogWarning((object)reason);
			}
		}

		private static void OnRestockClicked()
		{
			if (ChestTransferActions.Restock(InventoryGui.instance, out var movedCount, out var reason))
			{
				SonicChestFiltersPlugin.Debug((movedCount > 0) ? ("Restocked " + movedCount + " items into matching backpack stacks.") : reason);
				RefreshPlayerGrid();
				RefreshContainerGrid();
				return;
			}
			ManualLogSource modLogger = SonicChestFiltersPlugin.ModLogger;
			if (modLogger != null)
			{
				modLogger.LogWarning((object)reason);
			}
		}

		private static void RefreshClearButton()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			if ((Object)_clearButton != (Object)null)
			{
				((Selectable)_clearButton).interactable = ChestFilter.HasQuery;
			}
		}

		private static void RefreshContainerGrid()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			InventoryGui instance = InventoryGui.instance;
			InventoryGrid val = GameAccess.Get<InventoryGrid>(instance, "m_containerGrid");
			if ((Object)instance == (Object)null || (Object)val == (Object)null)
			{
				return;
			}
			Container val2 = GameAccess.Get<Container>(instance, "m_currentContainer");
			if (!((Object)val2 == (Object)null))
			{
				Inventory inventory = val2.GetInventory();
				if (inventory != null)
				{
					ItemData val3 = GameAccess.Get<ItemData>(instance, "m_dragItem");
					val.UpdateInventory(inventory, Player.m_localPlayer, val3);
				}
			}
		}

		private static void RefreshPlayerGrid()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			InventoryGui instance = InventoryGui.instance;
			InventoryGrid val = GameAccess.Get<InventoryGrid>(instance, "m_playerGrid");
			if (!((Object)instance == (Object)null) && !((Object)val == (Object)null) && !((Object)Player.m_localPlayer == (Object)null))
			{
				Inventory inventory = ((Humanoid)Player.m_localPlayer).GetInventory();
				if (inventory != null)
				{
					ItemData val2 = GameAccess.Get<ItemData>(instance, "m_dragItem");
					val.UpdateInventory(inventory, Player.m_localPlayer, val2);
				}
			}
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "UpdateContainer")]
	internal static class InventoryGui_UpdateContainer_Patch
	{
		private static void Postfix(InventoryGui __instance)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			if (!((Object)__instance == (Object)null) && !((Object)GameAccess.Get<Container>(__instance, "m_currentContainer") == (Object)null))
			{
				ChestPanelUi.EnsureControls(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "CloseContainer")]
	internal static class InventoryGui_CloseContainer_Patch
	{
		private static void Prefix()
		{
			ChestPanelUi.CloseFilterPane();
		}

		private static void Postfix(InventoryGui __instance)
		{
			ChestFilter.Clear();
			ChestSort.ResetSession();
			ChestPanelUi.DestroyControls(__instance);
		}
	}
	[HarmonyPatch(typeof(InventoryGrid), "UpdateInventory")]
	internal static class InventoryGrid_UpdateInventory_Patch
	{
		private static void Postfix(InventoryGrid __instance, Inventory inventory)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//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_0043: Expected O, but got Unknown
			//IL_0043: Expected O, but got Unknown
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			//IL_005e: Expected O, but got Unknown
			InventoryGui instance = InventoryGui.instance;
			InventoryGrid val = GameAccess.Get<InventoryGrid>(instance, "m_containerGrid");
			InventoryGrid val2 = GameAccess.Get<InventoryGrid>(instance, "m_playerGrid");
			if (!((Object)instance == (Object)null))
			{
				InventoryPinUi.Apply(__instance, inventory);
				if ((Object)__instance == (Object)val)
				{
					ChestFilter.ApplyToGrid(__instance, inventory);
				}
				else if ((Object)__instance == (Object)val2)
				{
					PlayerInventoryFilter.ApplyToGrid(__instance, inventory);
				}
			}
		}
	}
	internal static class ChestSort
	{
		internal static void ResetSession()
		{
		}

		internal static void SortCurrent(InventoryGui gui)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_00cc: 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)
			if ((Object)gui == (Object)null)
			{
				return;
			}
			if (IsDragging(gui))
			{
				Say("Cannot sort while dragging an item.");
				return;
			}
			Container val = GameAccess.Get<Container>(gui, "m_currentContainer");
			if ((Object)val == (Object)null)
			{
				return;
			}
			if (!val.IsOwner())
			{
				Say("Cannot sort: not the chest owner.");
				return;
			}
			Inventory inventory = val.GetInventory();
			if (inventory == null)
			{
				return;
			}
			SortProfile profile = SortOptions.GetChestProfile(val);
			if (profile.MergeStacks)
			{
				MergeStacks(inventory);
			}
			List<ItemData> list = new List<ItemData>(inventory.GetAllItems());
			int width = inventory.GetWidth();
			int height = inventory.GetHeight();
			list.Sort((ItemData a, ItemData b) => SortOptions.Compare(a, b, profile));
			int num = 0;
			for (int num2 = 0; num2 < height; num2++)
			{
				if (num >= list.Count)
				{
					break;
				}
				for (int num3 = 0; num3 < width; num3++)
				{
					if (num >= list.Count)
					{
						break;
					}
					list[num++].m_gridPos = new Vector2i(num3, num2);
				}
			}
			GameAccess.Call(inventory, "Changed", true, false);
			if (SonicChestFiltersPlugin.DebugEnabled)
			{
				SonicChestFiltersPlugin.Debug($"Sorted {list.Count} item stacks ({SortOptions.Describe(profile)}; merge={profile.MergeStacks}).");
			}
		}

		private static void MergeStacks(Inventory inventory)
		{
			bool flag;
			do
			{
				flag = false;
				List<ItemData> allItems = inventory.GetAllItems();
				for (int i = 0; i < allItems.Count; i++)
				{
					if (flag)
					{
						break;
					}
					ItemData val = allItems[i];
					int maxStackSize = val.m_shared.m_maxStackSize;
					if (maxStackSize <= 1 || val.m_stack >= maxStackSize)
					{
						continue;
					}
					for (int j = i + 1; j < allItems.Count; j++)
					{
						ItemData val2 = allItems[j];
						if (!CanStackTogether(val, val2))
						{
							continue;
						}
						int num = maxStackSize - val.m_stack;
						if (num > 0)
						{
							int num2 = Mathf.Min(num, val2.m_stack);
							val.m_stack += num2;
							val2.m_stack -= num2;
							if (val2.m_stack <= 0)
							{
								inventory.RemoveItem(val2);
							}
							flag = true;
						}
						break;
					}
				}
			}
			while (flag);
		}

		internal static bool CanStackTogether(ItemData source, ItemData target)
		{
			if (source == null || target == null || source.m_shared == null || target.m_shared == null)
			{
				return false;
			}
			if (source.m_shared.m_name != target.m_shared.m_name || source.m_quality != target.m_quality || source.m_variant != target.m_variant || source.m_worldLevel != target.m_worldLevel)
			{
				return false;
			}
			if (source.m_customData.Count != target.m_customData.Count)
			{
				return false;
			}
			foreach (KeyValuePair<string, string> customDatum in source.m_customData)
			{
				if (!target.m_customData.TryGetValue(customDatum.Key, out var value) || value != customDatum.Value)
				{
					return false;
				}
			}
			return true;
		}

		private static bool IsDragging(InventoryGui gui)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			object obj = AccessToolsField(gui, "m_dragGo");
			Object val = (Object)((obj is Object) ? obj : null);
			if (val != null && val != (Object)null)
			{
				return true;
			}
			return AccessToolsField(gui, "m_dragItem") != null;
		}

		private static object AccessToolsField(object instance, string name)
		{
			return AccessTools.Field(instance.GetType(), name)?.GetValue(instance);
		}

		private static void Say(string message)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			Player localPlayer = Player.m_localPlayer;
			if ((Object)localPlayer != (Object)null)
			{
				((Character)localPlayer).Message((MessageType)2, message, 0, (Sprite)null, false);
			}
			else if ((Object)Chat.instance != (Object)null)
			{
				((Terminal)Chat.instance).AddString(message);
			}
		}
	}
	internal static class ChestSortProfileStore
	{
		private static readonly Dictionary<string, SortProfile> Profiles = new Dictionary<string, SortProfile>(StringComparer.Ordinal);

		private static string _loadedWorldId;

		private static bool _hasLoadedWorld;

		private static bool _warnedMissingWorld;

		private static bool _warnedMissingChest;

		internal static bool TryGet(string chestId, out SortProfile profile)
		{
			profile = default(SortProfile);
			if (string.IsNullOrEmpty(chestId) || !EnsureLoaded())
			{
				return false;
			}
			return Profiles.TryGetValue(chestId, out profile);
		}

		internal static bool Set(string chestId, SortProfile profile, SortProfile defaults)
		{
			if (string.IsNullOrEmpty(chestId) || !EnsureLoaded())
			{
				return false;
			}
			if (SameProfile(profile, defaults))
			{
				if (!Profiles.Remove(chestId))
				{
					return true;
				}
			}
			else
			{
				Profiles[chestId] = profile;
			}
			return Save();
		}

		internal static bool Remove(string chestId)
		{
			if (string.IsNullOrEmpty(chestId) || !EnsureLoaded())
			{
				return false;
			}
			if (Profiles.Remove(chestId))
			{
				return Save();
			}
			return true;
		}

		internal static string GetChestId(Container chest)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			if ((Object)chest == (Object)null)
			{
				return null;
			}
			ZNetView val = GameAccess.Get<ZNetView>(chest, "m_nview");
			if ((Object)val != (Object)null && val.IsValid())
			{
				ZDO zDO = val.GetZDO();
				if (zDO != null && !((ZDOID)(ref zDO.m_uid)).IsNone())
				{
					return ((object)Unsafe.As<ZDOID, ZDOID>(ref zDO.m_uid)/*cast due to .constrained prefix*/).ToString();
				}
			}
			if (!_warnedMissingChest)
			{
				_warnedMissingChest = true;
				ManualLogSource modLogger = SonicChestFiltersPlugin.ModLogger;
				if (modLogger != null)
				{
					modLogger.LogWarning((object)"Cannot persist chest sort options because the open container has no valid ZDO ID.");
				}
			}
			return null;
		}

		private static bool EnsureLoaded()
		{
			if (!TryGetWorldId(out var worldId))
			{
				if (!_warnedMissingWorld)
				{
					_warnedMissingWorld = true;
					ManualLogSource modLogger = SonicChestFiltersPlugin.ModLogger;
					if (modLogger != null)
					{
						modLogger.LogWarning((object)"Cannot persist chest sort options because the active world ID is unavailable.");
					}
				}
				return false;
			}
			if (_hasLoadedWorld && string.Equals(_loadedWorldId, worldId, StringComparison.Ordinal))
			{
				return true;
			}
			_loadedWorldId = worldId;
			_hasLoadedWorld = true;
			Profiles.Clear();
			string path = GetPath(worldId);
			if (!File.Exists(path))
			{
				return true;
			}
			try
			{
				string[] array = File.ReadAllLines(path);
				for (int i = 0; i < array.Length; i++)
				{
					string[] array2 = array[i].Split('|');
					if (array2.Length == 6 && !string.IsNullOrEmpty(array2[0]) && int.TryParse(array2[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result) && int.TryParse(array2[2], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result2) && int.TryParse(array2[3], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result3) && bool.TryParse(array2[4], out var result4) && bool.TryParse(array2[5], out var result5) && SortOptions.IsSelectableField((SortField)result) && SortOptions.IsSelectableField((SortField)result2) && SortOptions.IsSelectableField((SortField)result3))
					{
						Profiles[array2[0]] = new SortProfile
						{
							Primary = (SortField)result,
							Secondary = (SortField)result2,
							Tertiary = (SortField)result3,
							Descending = result4,
							MergeStacks = result5
						};
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource modLogger2 = SonicChestFiltersPlugin.ModLogger;
				if (modLogger2 != null)
				{
					modLogger2.LogWarning((object)("Could not load world chest sort options: " + ex.Message));
				}
			}
			return true;
		}

		private static bool Save()
		{
			try
			{
				string path = GetPath(_loadedWorldId);
				Directory.CreateDirectory(Path.GetDirectoryName(path));
				if (Profiles.Count == 0)
				{
					if (File.Exists(path))
					{
						File.Delete(path);
					}
					return true;
				}
				List<string> list = new List<string>(Profiles.Count);
				foreach (KeyValuePair<string, SortProfile> profile in Profiles)
				{
					SortProfile value = profile.Value;
					string[] obj = new string[6] { profile.Key, null, null, null, null, null };
					int primary = (int)value.Primary;
					obj[1] = primary.ToString(CultureInfo.InvariantCulture);
					primary = (int)value.Secondary;
					obj[2] = primary.ToString(CultureInfo.InvariantCulture);
					primary = (int)value.Tertiary;
					obj[3] = primary.ToString(CultureInfo.InvariantCulture);
					obj[4] = value.Descending.ToString();
					obj[5] = value.MergeStacks.ToString();
					list.Add(string.Join("|", obj));
				}
				list.Sort(StringComparer.Ordinal);
				string text = path + ".tmp";
				File.WriteAllLines(text, list);
				if (File.Exists(path))
				{
					File.Replace(text, path, null);
				}
				else
				{
					File.Move(text, path);
				}
				return true;
			}
			catch (Exception ex)
			{
				ManualLogSource modLogger = SonicChestFiltersPlugin.ModLogger;
				if (modLogger != null)
				{
					modLogger.LogWarning((object)("Could not save world chest sort options: " + ex.Message));
				}
				return false;
			}
		}

		private static string GetPath(string worldId)
		{
			string text = SonicChestFiltersPlugin.PinDataDirectory;
			if (string.IsNullOrEmpty(text))
			{
				text = Path.Combine(Paths.ConfigPath, "SonicChestFilters");
			}
			return Path.Combine(text, "ChestSortProfiles_" + worldId + ".txt");
		}

		private static bool TryGetWorldId(out string worldId)
		{
			worldId = null;
			try
			{
				Type type = AccessTools.TypeByName("ZNet");
				if (type == null)
				{
					return false;
				}
				PropertyInfo property = type.GetProperty("instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				object obj = ((property == null) ? null : property.GetValue(null, null));
				if (obj == null)
				{
					FieldInfo field = type.GetField("instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
					obj = ((field == null) ? null : field.GetValue(null));
				}
				if (obj == null)
				{
					return false;
				}
				MethodInfo methodInfo = AccessTools.Method(type, "GetWorldUID", (Type[])null, (Type[])null);
				object obj2 = ((methodInfo == null) ? null : methodInfo.Invoke(obj, null));
				if (obj2 != null)
				{
					worldId = Convert.ToString(obj2, CultureInfo.InvariantCulture);
					if (!string.IsNullOrEmpty(worldId))
					{
						return true;
					}
				}
				FieldInfo field2 = type.GetField("m_world", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				object obj3 = ((field2 == null) ? null : field2.GetValue(field2.IsStatic ? null : obj));
				FieldInfo fieldInfo = obj3?.GetType().GetField("m_uid", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				object obj4 = ((fieldInfo == null) ? null : fieldInfo.GetValue(obj3));
				if (obj4 == null)
				{
					return false;
				}
				worldId = Convert.ToString(obj4, CultureInfo.InvariantCulture);
				return !string.IsNullOrEmpty(worldId);
			}
			catch (Exception ex)
			{
				ManualLogSource modLogger = SonicChestFiltersPlugin.ModLogger;
				if (modLogger != null)
				{
					modLogger.LogWarning((object)("Could not read active world ID for chest sort options: " + ex.Message));
				}
				return false;
			}
		}

		private static bool SameProfile(SortProfile a, SortProfile b)
		{
			if (a.Primary == b.Primary && a.Secondary == b.Secondary && a.Tertiary == b.Tertiary && a.Descending == b.Descending)
			{
				return a.MergeStacks == b.MergeStacks;
			}
			return false;
		}
	}
	internal static class ChestTransferActions
	{
		private static readonly Dictionary<ItemData, int> RestockedUnits = new Dictionary<ItemData, int>();

		internal static bool QuickStack(InventoryGui gui, out int movedCount, out string reason)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Expected O, but got Unknown
			movedCount = 0;
			if (SonicChestFiltersPlugin.Enabled == null || !SonicChestFiltersPlugin.Enabled.Value)
			{
				reason = "Sonic Chest Filters is disabled.";
				return false;
			}
			if ((Object)gui == (Object)null || (Object)Player.m_localPlayer == (Object)null)
			{
				reason = "Inventory is unavailable.";
				return false;
			}
			if (PlayerInventorySort.IsDragging(gui))
			{
				reason = "Cannot transfer items while dragging an item.";
				return false;
			}
			Inventory inventory = ((Humanoid)Player.m_localPlayer).GetInventory();
			if (inventory == null)
			{
				reason = "Player inventory is unavailable.";
				return false;
			}
			if (!PlayerInventorySort.TryGetMovableBackpackItems(inventory, out var _, out reason))
			{
				return false;
			}
			List<Container> list = NearbyContainers.Get(Player.m_localPlayer);
			List<Container> list2 = new List<Container>();
			for (int i = 0; i < list.Count; i++)
			{
				Container val = list[i];
				if ((Object)val == (Object)null)
				{
					continue;
				}
				try
				{
					if (!val.IsOwner())
					{
						continue;
					}
					Inventory inventory2 = val.GetInventory();
					if (inventory2 != null && inventory2 != inventory)
					{
						int num = QuickStackIntoContainer(inventory, inventory2);
						if (num > 0)
						{
							movedCount += num;
							NotifyInventoriesChanged(inventory, inventory2);
							list2.Add(val);
						}
					}
				}
				catch (Exception ex)
				{
					ManualLogSource modLogger = SonicChestFiltersPlugin.ModLogger;
					if (modLogger != null)
					{
						modLogger.LogWarning((object)("Quick Stack skipped a nearby container: " + ex.Message));
					}
				}
			}
			if (list2.Count > 0)
			{
				ItemLocate.HighlightContainers(list2);
			}
			reason = ((movedCount == 0) ? "No eligible nearby chests could accept backpack items." : string.Empty);
			return true;
		}

		private static int QuickStackIntoContainer(Inventory playerInventory, Inventory chestInventory)
		{
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			if (!PlayerInventorySort.TryGetMovableBackpackItems(playerInventory, out var items, out var _))
			{
				return 0;
			}
			for (int i = 0; i < items.Count; i++)
			{
				ItemData val = items[i];
				if (val == null || val.m_shared == null || val.m_stack <= 0 || val.m_shared.m_maxStackSize <= 1 || !playerInventory.GetAllItems().Contains(val))
				{
					continue;
				}
				int restockedUnits = GetRestockedUnits(val);
				List<ItemData> allItems = chestInventory.GetAllItems();
				bool flag = false;
				for (int j = 0; j < allItems.Count; j++)
				{
					if (val.m_stack <= restockedUnits)
					{
						break;
					}
					ItemData val2 = allItems[j];
					if (ChestSort.CanStackTogether(val, val2))
					{
						flag = true;
						int num2 = Mathf.Min(val2.m_shared.m_maxStackSize - val2.m_stack, val.m_stack - restockedUnits);
						if (num2 > 0)
						{
							int stack = val.m_stack;
							chestInventory.MoveItemToThis(playerInventory, val, num2, val2.m_gridPos.x, val2.m_gridPos.y);
							num += Mathf.Max(0, stack - val.m_stack);
						}
					}
				}
				if (!flag)
				{
					continue;
				}
				while (val.m_stack > restockedUnits)
				{
					Vector2i val3 = FindEmptySlot(chestInventory);
					if (val3.x < 0)
					{
						break;
					}
					int num3 = Mathf.Min(val.m_stack - restockedUnits, val.m_shared.m_maxStackSize);
					int stack2 = val.m_stack;
					chestInventory.MoveItemToThis(playerInventory, val, num3, val3.x, val3.y);
					int num4 = Mathf.Max(0, stack2 - val.m_stack);
					if (num4 <= 0)
					{
						break;
					}
					num += num4;
				}
			}
			return num;
		}

		private static Vector2i FindEmptySlot(Inventory inventory)
		{
			//IL_0036: 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)
			for (int i = 0; i < inventory.GetHeight(); i++)
			{
				for (int j = 0; j < inventory.GetWidth(); j++)
				{
					if (inventory.GetItemAt(j, i) == null)
					{
						return new Vector2i(j, i);
					}
				}
			}
			return new Vector2i(-1, -1);
		}

		internal static bool Restock(InventoryGui gui, out int movedCount, out string reason)
		{
			movedCount = 0;
			if (!TryGetInventories(gui, out var playerInventory, out var chestInventory, out reason))
			{
				return false;
			}
			if (!PlayerInventorySort.TryGetMovableBackpackItems(playerInventory, out var items, out reason, includePinnedTargets: true))
			{
				return false;
			}
			if (SonicChestFiltersPlugin.PreferPinnedStacks == null || SonicChestFiltersPlugin.PreferPinnedStacks.Value)
			{
				items.Sort((ItemData a, ItemData b) => InventoryPins.IsPinned(playerInventory, b).CompareTo(InventoryPins.IsPinned(playerInventory, a)));
			}
			for (int num = 0; num < items.Count; num++)
			{
				ItemData val = items[num];
				if (val == null || val.m_shared == null)
				{
					continue;
				}
				int num2 = val.m_shared.m_maxStackSize - val.m_stack;
				if (num2 <= 0)
				{
					continue;
				}
				List<ItemData> allItems = chestInventory.GetAllItems();
				for (int num3 = 0; num3 < allItems.Count; num3++)
				{
					if (num2 <= 0)
					{
						break;
					}
					ItemData val2 = allItems[num3];
					if (!ChestSort.CanStackTogether(val, val2))
					{
						continue;
					}
					int num4 = Mathf.Min(num2, val2.m_stack);
					if (num4 <= 0)
					{
						continue;
					}
					int stack = val.m_stack;
					if (playerInventory.MoveItemToThis(chestInventory, val2, num4, val.m_gridPos.x, val.m_gridPos.y))
					{
						int num5 = Mathf.Max(0, val.m_stack - stack);
						movedCount += num5;
						num2 -= num5;
						if (num5 > 0)
						{
							RestockedUnits[val] = GetRestockedUnits(val) + num5;
						}
					}
				}
			}
			if (movedCount > 0)
			{
				NotifyInventoriesChanged(playerInventory, chestInventory);
			}
			reason = ((movedCount == 0) ? "No matching backpack stacks needed restocking from this chest." : string.Empty);
			return true;
		}

		private static int GetRestockedUnits(ItemData item)
		{
			if (!RestockedUnits.TryGetValue(item, out var value))
			{
				return 0;
			}
			if (item == null || item.m_stack <= 0)
			{
				RestockedUnits.Remove(item);
				return 0;
			}
			value = Mathf.Clamp(value, 0, item.m_stack);
			RestockedUnits[item] = value;
			return value;
		}

		private static bool TryGetInventories(InventoryGui gui, out Inventory playerInventory, out Inventory chestInventory, out string reason)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			playerInventory = null;
			chestInventory = null;
			reason = string.Empty;
			if (SonicChestFiltersPlugin.Enabled == null || !SonicChestFiltersPlugin.Enabled.Value)
			{
				reason = "Sonic Chest Filters is disabled.";
				return false;
			}
			if ((Object)gui == (Object)null || (Object)Player.m_localPlayer == (Object)null)
			{
				reason = "Inventory is unavailable.";
				return false;
			}
			if (PlayerInventorySort.IsDragging(gui))
			{
				reason = "Cannot transfer items while dragging an item.";
				return false;
			}
			Container val = GameAccess.Get<Container>(gui, "m_currentContainer");
			if ((Object)val == (Object)null)
			{
				reason = "No chest is open.";
				return false;
			}
			if (!val.IsOwner())
			{
				reason = "Cannot transfer items: not the chest owner.";
				return false;
			}
			playerInventory = ((Humanoid)Player.m_localPlayer).GetInventory();
			chestInventory = val.GetInventory();
			if (playerInventory == null || chestInventory == null)
			{
				reason = "Inventory is unavailable.";
				return false;
			}
			return true;
		}

		private static void NotifyInventoriesChanged(Inventory playerInventory, Inventory chestInventory)
		{
			GameAccess.Call(playerInventory, "Changed", true, false);
			GameAccess.Call(chestInventory, "Changed", true, false);
		}
	}
	internal static class FilterInputBlocker
	{
		private static readonly HashSet<int> FocusedFields = new HashSet<int>();

		internal static void SetFocused(InputField field, bool focused)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			if ((Object)field == (Object)null)
			{
				return;
			}
			int instanceID = ((Object)field).GetInstanceID();
			if (focused)
			{
				if (FocusedFields.Add(instanceID) && GUIManager.Instance != null)
				{
					GUIManager.BlockInput(true);
				}
			}
			else if (FocusedFields.Remove(instanceID) && FocusedFields.Count == 0 && GUIManager.Instance != null)
			{
				GUIManager.BlockInput(false);
			}
		}

		internal static void ReleaseAll()
		{
			bool num = FocusedFields.Count > 0;
			FocusedFields.Clear();
			if (num && GUIManager.Instance != null)
			{
				GUIManager.BlockInput(false);
			}
		}
	}
	internal sealed class FilterInputFocusHandler : MonoBehaviour, ISelectHandler, IEventSystemHandler, IDeselectHandler
	{
		private InputField _field;

		internal void Bind(InputField field)
		{
			_field = field;
		}

		public void OnSelect(BaseEventData eventData)
		{
			FilterInputBlocker.SetFocused(_field, focused: true);
		}

		public void OnDeselect(BaseEventData eventData)
		{
			FilterInputBlocker.SetFocused(_field, focused: false);
		}

		private void OnDisable()
		{
			FilterInputBlocker.SetFocused(_field, focused: false);
		}
	}
	internal static class FilterPopupCanvas
	{
		internal static bool MoveToFrontCanvas(GameObject popup)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected O, but got Unknown
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)popup == (Object)null || (Object)GUIManager.CustomGUIFront == (Object)null)
			{
				return false;
			}
			RectTransform component = popup.GetComponent<RectTransform>();
			Transform transform = GUIManager.CustomGUIFront.transform;
			RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
			if ((Object)component == (Object)null || (Object)val == (Object)null)
			{
				return false;
			}
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			component.GetWorldCorners(array);
			Vector2 val2 = RectTransformUtility.WorldToScreenPoint((Camera)null, array[1]);
			Vector2 anchoredPosition = default(Vector2);
			if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(val, val2, (Camera)null, ref anchoredPosition))
			{
				return false;
			}
			float num = Mathf.Abs(((Transform)component).lossyScale.x);
			((Transform)component).SetParent((Transform)(object)val, false);
			component.anchorMin = new Vector2(0.5f, 0.5f);
			component.anchorMax = new Vector2(0.5f, 0.5f);
			component.pivot = new Vector2(0f, 1f);
			component.anchoredPosition = anchoredPosition;
			((Transform)component).localScale = new Vector3(num, num, num);
			popup.transform.SetAsLastSibling();
			return true;
		}

		internal static bool MoveToFrontCanvas(GameObject popup, RectTransform anchor, Vector2 localOffset)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected O, but got Unknown
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			//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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: 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_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)popup == (Object)null || (Object)anchor == (Object)null || (Object)GUIManager.CustomGUIFront == (Object)null)
			{
				return false;
			}
			RectTransform component = popup.GetComponent<RectTransform>();
			Transform transform = GUIManager.CustomGUIFront.transform;
			RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
			if ((Object)component == (Object)null || (Object)val == (Object)null)
			{
				return false;
			}
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			anchor.GetWorldCorners(array);
			Vector3 val2 = array[2];
			Vector2 val3 = RectTransformUtility.WorldToScreenPoint((Camera)null, val2);
			float num = Mathf.Abs(((Transform)anchor).lossyScale.x);
			val3 += localOffset * num;
			Vector2 anchoredPosition = default(Vector2);
			if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(val, val3, (Camera)null, ref anchoredPosition))
			{
				return false;
			}
			((Transform)component).SetParent((Transform)(object)val, false);
			component.anchorMin = new Vector2(0.5f, 0.5f);
			component.anchorMax = new Vector2(0.5f, 0.5f);
			component.pivot = new Vector2(0f, 1f);
			component.anchoredPosition = anchoredPosition;
			((Transform)component).localScale = new Vector3(num, num, num);
			popup.transform.SetAsLastSibling();
			return true;
		}
	}
	internal static class GameAccess
	{
		internal static T Get<T>(object instance, string fieldName) where T : class
		{
			if (instance == null)
			{
				return null;
			}
			return AccessTools.Field(instance.GetType(), fieldName)?.GetValue(instance) as T;
		}

		internal static object Get(object instance, string fieldName)
		{
			if (instance == null)
			{
				return null;
			}
			return AccessTools.Field(instance.GetType(), fieldName)?.GetValue(instance);
		}

		internal static void Call(object instance, string methodName, params object[] args)
		{
			if (instance != null)
			{
				MethodInfo methodInfo = AccessTools.Method(instance.GetType(), methodName, (Type[])null, (Type[])null);
				if (!(methodInfo == null))
				{
					methodInfo.Invoke(instance, BindArguments(methodInfo, args));
				}
			}
		}

		private static object[] BindArguments(MethodInfo method, object[] args)
		{
			ParameterInfo[] parameters = method.GetParameters();
			if (parameters.Length == 0)
			{
				return null;
			}
			object[] array = new object[parameters.Length];
			for (int i = 0; i < parameters.Length; i++)
			{
				if (args != null && i < args.Length)
				{
					array[i] = args[i];
					continue;
				}
				if (parameters[i].HasDefaultValue)
				{
					array[i] = parameters[i].DefaultValue;
					continue;
				}
				Type parameterType = parameters[i].ParameterType;
				array[i] = (parameterType.IsValueType ? Activator.CreateInstance(parameterType) : null);
			}
			return array;
		}
	}
	internal static class InputFieldTestPanel
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static UnityAction <0>__Close;
		}

		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static ConsoleEvent <>9__3_0;

			public static UnityAction<string> <>9__4_0;

			internal void <RegisterCommand>b__3_0(ConsoleEventArgs args)
			{
				Open(args.Context);
			}

			internal void <Open>b__4_0(string value)
			{
				SonicChestFiltersPlugin.Debug("Input test value changed: '" + value + "'.");
			}
		}

		private const string PanelName = "SonicChestFilters_InputFieldTest";

		private static GameObject _panel;

		private static InputField _input;

		internal static void RegisterCommand()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			try
			{
				object obj = <>c.<>9__3_0;
				if (obj == null)
				{
					ConsoleEvent val = delegate(ConsoleEventArgs args)
					{
						Open(args.Context);
					};
					<>c.<>9__3_0 = val;
					obj = (object)val;
				}
				new ConsoleCommand("scf_inputtest", "Open a plain Jötunn input-field test panel.", (ConsoleEvent)obj, false, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
				SonicChestFiltersPlugin.Debug("Registered hot-reloadable console command scf_inputtest.");
			}
			catch (Exception ex)
			{
				ManualLogSource modLogger = SonicChestFiltersPlugin.ModLogger;
				if (modLogger != null)
				{
					modLogger.LogWarning((object)("Could not register scf_inputtest: " + ex.Message));
				}
			}
		}

		private static void Open(Terminal context)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			//IL_00db: 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_00f9: 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_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Expected O, but got Unknown
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Expected O, but got Unknown
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Expected O, but got Unknown
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Expected O, but got Unknown
			if (GUIManager.Instance == null || (Object)GUIManager.CustomGUIFront == (Object)null)
			{
				if (context != null)
				{
					context.AddString("Jötunn custom UI is not ready yet. Try scf_inputtest again.");
				}
				return;
			}
			if ((Object)_panel != (Object)null)
			{
				Object.Destroy((Object)(object)_panel);
			}
			_panel = GUIManager.Instance.CreateWoodpanel(GUIManager.CustomGUIFront.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), Vector2.zero, 340f, 150f, false);
			if ((Object)_panel == (Object)null)
			{
				if (context != null)
				{
					context.AddString("Jötunn could not create the input test panel.");
				}
				return;
			}
			((Object)_panel).name = "SonicChestFilters_InputFieldTest";
			RectTransform component = _panel.GetComponent<RectTransform>();
			GUIManager.Instance.CreateText("Type into this standard Jötunn input field:", (Transform)(object)component, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -32f), GUIManager.Instance.AveriaSerifBold, 16, Color.white, false, Color.black, 300f, 24f, false);
			GameObject val = GUIManager.Instance.CreateInputField((Transform)(object)component, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0f, 8f), (ContentType)0, "Type here...", 16, 280f, 32f);
			_input = (((Object)val == (Object)null) ? null : val.GetComponent<InputField>());
			if ((Object)_input == (Object)null)
			{
				if (context != null)
				{
					context.AddString("Jötunn created the panel, but did not provide an InputField component.");
				}
				return;
			}
			((Object)val).name = "SonicChestFilters_InputFieldTestField";
			((UnityEvent<string>)(object)_input.onValueChanged).AddListener((UnityAction<string>)delegate(string value)
			{
				SonicChestFiltersPlugin.Debug("Input test value changed: '" + value + "'.");
			});
			GameObject val2 = GUIManager.Instance.CreateButton("Close", (Transform)(object)component, new Vector2(0.5f, 0f), new Vector2(0.5f, 0f), new Vector2(0f, 24f), 84f, 30f);
			if ((Object)val2 != (Object)null)
			{
				Button component2 = val2.GetComponent<Button>();
				if (component2 != null)
				{
					ButtonClickedEvent onClick = component2.onClick;
					object obj = <>O.<0>__Close;
					if (obj == null)
					{
						UnityAction val3 = Close;
						<>O.<0>__Close = val3;
						obj = (object)val3;
					}
					((UnityEvent)onClick).AddListener((UnityAction)obj);
				}
			}
			_panel.SetActive(true);
			_input.ActivateInputField();
			if (context != null)
			{
				context.AddString("Input test panel opened. Type normally; this panel does not block player input.");
			}
		}

		private static void Close()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			if ((Object)_input != (Object)null)
			{
				_input.DeactivateInputField();
			}
			if ((Object)_panel != (Object)null)
			{
				Object.Destroy((Object)(object)_panel);
			}
			_panel = null;
			_input = null;
		}
	}
	internal static class InventoryPins
	{
		private sealed class PinState
		{
			internal readonly string CharacterName;

			internal readonly string LegacyPinKey;

			internal readonly string FilePath;

			internal readonly HashSet<long> PinnedSlots;

			internal readonly HashSet<string> LegacyItemIds;

			internal bool LegacyMigrationComplete;

			internal PinState(string characterName, string legacyPinKey, string filePath, HashSet<long> pinnedSlots, HashSet<string> legacyItemIds)
			{
				CharacterName = characterName;
				LegacyPinKey = legacyPinKey;
				FilePath = filePath;
				PinnedSlots = pinnedSlots;
				LegacyItemIds = legacyItemIds;
			}
		}

		private const string ItemIdKey = "com.sonicdm.valheim.sonicchestfilters.pin_id";

		private const string LegacyPinKeyPrefix = "com.sonicdm.valheim.sonicchestfilters.pin.";

		private static PinState _activeState;

		internal static bool IsPinned(ItemData item)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			Player localPlayer = Player.m_localPlayer;
			Inventory val = (((Object)localPlayer == (Object)null) ? null : ((Humanoid)localPlayer).GetInventory());
			if (val == null || item == null || val.GetItemAt(item.m_gridPos.x, item.m_gridPos.y) != item)
			{
				return false;
			}
			MigrateLegacyPlayerPins(val);
			return IsSlotPinned(val, item.m_gridPos.x, item.m_gridPos.y);
		}

		internal static bool IsPinned(Inventory inventory, ItemData item)
		{
			if (item != null)
			{
				return IsSlotPinned(inventory, item.m_gridPos.x, item.m_gridPos.y);
			}
			return false;
		}

		internal static bool IsSlotPinned(Inventory inventory, int x, int y)
		{
			if (!SonicChestFiltersPlugin.PinningEnabled || !IsPlayerInventory(inventory))
			{
				return false;
			}
			return GetActiveState()?.PinnedSlots.Contains(SlotKey(x, y)) ?? false;
		}

		internal static bool ToggleSlot(Inventory inventory, int x, int y)
		{
			if (!SonicChestFiltersPlugin.PinningEnabled || !IsPlayerInventory(inventory))
			{
				return IsSlotPinned(inventory, x, y);
			}
			PinState activeState = GetActiveState();
			if (activeState == null)
			{
				return false;
			}
			long item = SlotKey(x, y);
			if (!activeState.PinnedSlots.Remove(item))
			{
				if (!PlayerInventorySort.CanPinSlot(inventory, x, y))
				{
					return false;
				}
				activeState.PinnedSlots.Add(item);
			}
			SaveState(activeState);
			return activeState.PinnedSlots.Contains(item);
		}

		private static PinState GetActiveState()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			Player localPlayer = Player.m_localPlayer;
			if ((Object)localPlayer == (Object)null)
			{
				return null;
			}
			string playerName = localPlayer.GetPlayerName();
			if (string.IsNullOrWhiteSpace(playerName) || string.IsNullOrEmpty(SonicChestFiltersPlugin.PinDataDirectory))
			{
				return null;
			}
			if (_activeState != null && string.Equals(_activeState.CharacterName, playerName, StringComparison.Ordinal))
			{
				return _activeState;
			}
			string text = string.Empty;
			string text2 = playerName;
			foreach (char c in text2)
			{
				text += ((char.IsLetterOrDigit(c) || c == '-' || c == '_') ? c : '_');
			}
			if (text.Length > 32)
			{
				text = text.Substring(0, 32);
			}
			string text3;
			using (SHA256 sHA = SHA256.Create())
			{
				text3 = BitConverter.ToString(sHA.ComputeHash(Encoding.UTF8.GetBytes(playerName)), 0, 8).Replace("-", string.Empty);
			}
			string text4 = Path.Combine(Path.Combine(SonicChestFiltersPlugin.PinDataDirectory, "Pins"), text + "-" + text3 + ".pins");
			HashSet<long> hashSet = new HashSet<long>();
			HashSet<string> hashSet2 = new HashSet<string>(StringComparer.Ordinal);
			try
			{
				if (File.Exists(text4))
				{
					string[] array = File.ReadAllLines(text4);
					foreach (string text5 in array)
					{
						if (!string.IsNullOrWhiteSpace(text5))
						{
							string[] array2 = text5.Trim().Split('|');
							if (array2.Length == 3 && array2[0] == "player" && int.TryParse(array2[1], out var result) && int.TryParse(array2[2], out var result2))
							{
								hashSet.Add(SlotKey(result, result2));
							}
							else
							{
								hashSet2.Add(text5.Trim());
							}
						}
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource modLogger = SonicChestFiltersPlugin.ModLogger;
				if (modLogger != null)
				{
					modLogger.LogWarning((object)("Could not load character pin data: " + ex.Message));
				}
			}
			_activeState = new PinState(playerName, "com.sonicdm.valheim.sonicchestfilters.pin." + playerName, text4, hashSet, hashSet2);
			return _activeState;
		}

		internal static void MigrateLegacyPlayerPins(Inventory inventory)
		{
			if (!SonicChestFiltersPlugin.PinningEnabled || !IsPlayerInventory(inventory))
			{
				return;
			}
			PinState activeState = GetActiveState();
			if (activeState == null || activeState.LegacyMigrationComplete)
			{
				return;
			}
			bool flag = false;
			bool flag2 = false;
			List<ItemData> allItems = inventory.GetAllItems();
			for (int i = 0; i < allItems.Count; i++)
			{
				ItemData val = allItems[i];
				if (val != null && val.m_customData != null)
				{
					string value;
					bool flag3 = val.m_customData.TryGetValue(activeState.LegacyPinKey, out value) && value == "1";
					if (val.m_customData.TryGetValue("com.sonicdm.valheim.sonicchestfilters.pin_id", out var value2))
					{
						flag3 |= activeState.LegacyItemIds.Remove(value2);
					}
					if (flag3 && PlayerInventorySort.CanPinSlot(inventory, val.m_gridPos.x, val.m_gridPos.y))
					{
						activeState.PinnedSlots.Add(SlotKey(val.m_gridPos.x, val.m_gridPos.y));
					}
					if (val.m_customData.Remove("com.sonicdm.valheim.sonicchestfilters.pin_id"))
					{
						flag = (flag2 = true);
					}
					if (val.m_customData.Remove(activeState.LegacyPinKey))
					{
						flag = (flag2 = true);
					}
				}
			}
			if (activeState.LegacyItemIds.Count > 0)
			{
				activeState.LegacyItemIds.Clear();
				flag = true;
			}
			activeState.LegacyMigrationComplete = true;
			if (flag2)
			{
				GameAccess.Call(inventory, "Changed", true, false);
			}
			if (flag)
			{
				SaveState(activeState);
			}
		}

		internal static void ClearLegacyItemPinData(Inventory inventory)
		{
			if (inventory == null)
			{
				return;
			}
			PinState activeState = GetActiveState();
			if (activeState == null)
			{
				return;
			}
			bool flag = false;
			List<ItemData> allItems = inventory.GetAllItems();
			for (int i = 0; i < allItems.Count; i++)
			{
				ItemData val = allItems[i];
				if (val != null && val.m_customData != null)
				{
					flag |= val.m_customData.Remove("com.sonicdm.valheim.sonicchestfilters.pin_id");
					flag |= val.m_customData.Remove(activeState.LegacyPinKey);
				}
			}
			if (flag)
			{
				GameAccess.Call(inventory, "Changed", true, false);
			}
		}

		private static void SaveState(PinState state)
		{
			try
			{
				Directory.CreateDirectory(Path.GetDirectoryName(state.FilePath));
				List<string> list = new List<string>(state.PinnedSlots.Count);
				foreach (long pinnedSlot in state.PinnedSlots)
				{
					list.Add("player|" + (int)pinnedSlot + "|" + (int)(pinnedSlot >> 32));
				}
				list.Sort(StringComparer.Ordinal);
				File.WriteAllLines(state.FilePath, list.ToArray());
			}
			catch (Exception ex)
			{
				ManualLogSource modLogger = SonicChestFiltersPlugin.ModLogger;
				if (modLogger != null)
				{
					modLogger.LogWarning((object)("Could not save character pin data: " + ex.Message));
				}
			}
		}

		private static bool IsPlayerInventory(Inventory inventory)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			Player localPlayer = Player.m_localPlayer;
			if (inventory != null && (Object)localPlayer != (Object)null)
			{
				return inventory == ((Humanoid)localPlayer).GetInventory();
			}
			return false;
		}

		private static long SlotKey(int x, int y)
		{
			return ((long)y << 32) | (uint)x;
		}
	}
	public static class SonicChestFiltersApi
	{
		public static bool IsItemPinned(ItemData item)
		{
			return InventoryPins.IsPinned(item);
		}

		public static bool IsFilterFieldFocused()
		{
			if (!ChestPanelUi.FilterFieldFocused)
			{
				return PlayerInventoryPanelUi.FilterFieldFocused;
			}
			return true;
		}
	}
	internal static class InventoryPinUi
	{
		private const string PinControlName = "SonicChestFilters_PinControl";

		private static readonly Sprite[] PinSprites = (Sprite[])(object)new Sprite[2];

		internal static void Apply(InventoryGrid grid, Inventory inventory)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Expected O, but got Unknown
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Expected O, but got Unknown
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Expected O, but got Unknown
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Expected O, but got Unknown
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Expected O, but got Unknown
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Expected O, but got Unknown
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Expected O, but got Unknown
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Expected O, but got Unknown
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Expected O, but got Unknown
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Expected O, but got Unknown
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Expected O, but got Unknown
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Expected O, but got Unknown
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)grid == (Object)null || inventory == null)
			{
				return;
			}
			List<InventoryElement> list = GameAccess.Get<List<InventoryElement>>(grid, "m_elements");
			if (list == null)
			{
				return;
			}
			bool flag = (Object)Player.m_localPlayer != (Object)null && inventory == ((Humanoid)Player.m_localPlayer).GetInventory();
			if (SonicChestFiltersPlugin.PinningEnabled && (Object)Player.m_localPlayer != (Object)null)
			{
				InventoryPins.MigrateLegacyPlayerPins(((Humanoid)Player.m_localPlayer).GetInventory());
			}
			if (SonicChestFiltersPlugin.PinningEnabled && !flag)
			{
				InventoryPins.ClearLegacyItemPinData(inventory);
			}
			if (!SonicChestFiltersPlugin.PinningEnabled || !flag)
			{
				for (int i = 0; i < list.Count; i++)
				{
					InventoryElement val = list[i];
					if (!((Object)val == (Object)null) && !((Object)val.m_button == (Object)null))
					{
						Transform val2 = ((Component)val.m_button).transform.Find("SonicChestFilters_PinControl");
						if ((Object)val2 != (Object)null)
						{
							Object.Destroy((Object)(object)((Component)val2).gameObject);
						}
					}
				}
				return;
			}
			for (int j = 0; j < list.Count; j++)
			{
				InventoryElement val3 = list[j];
				if ((Object)val3 == (Object)null || (Object)val3.m_button == (Object)null)
				{
					continue;
				}
				ItemData itemAt = inventory.GetItemAt(val3.Position.x, val3.Position.y);
				bool num = PlayerInventorySort.CanPinSlot(inventory, val3.Position.x, val3.Position.y);
				Transform val4 = ((Component)val3.m_button).transform.Find("SonicChestFilters_PinControl");
				if (!num)
				{
					if ((Object)val4 != (Object)null)
					{
						Object.Destroy((Object)(object)((Component)val4).gameObject);
					}
					continue;
				}
				PinControlClickHandler handler = null;
				Image icon = null;
				if ((Object)val4 != (Object)null)
				{
					handler = ((Component)val4).GetComponent<PinControlClickHandler>();
					icon = ((Component)val4).GetComponent<Image>();
					if ((Object)handler == (Object)null || (Object)icon == (Object)null)
					{
						Object.Destroy((Object)(object)((Component)val4).gameObject);
						val4 = null;
					}
				}
				if ((Object)val4 == (Object)null)
				{
					CreateControl(((Component)val3.m_button).transform, out handler, out icon);
				}
				if (!((Object)handler == (Object)null) && !((Object)icon == (Object)null))
				{
					handler.Bind(inventory, val3.Position.x, val3.Position.y, itemAt, icon);
				}
			}
		}

		private static void CreateControl(Transform parent, out PinControlClickHandler handler, out Image icon)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("SonicChestFilters_PinControl", new Type[4]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(Image),
				typeof(PinControlClickHandler)
			});
			val.transform.SetParent(parent, false);
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0f, 1f);
			component.anchorMax = new Vector2(0f, 1f);
			component.pivot = new Vector2(0f, 1f);
			component.anchoredPosition = new Vector2(1f, -1f);
			component.sizeDelta = new Vector2(18f, 18f);
			icon = val.GetComponent<Image>();
			icon.sprite = GetPinSprite(pinned: false);
			icon.preserveAspect = true;
			((Graphic)icon).raycastTarget = true;
			handler = val.GetComponent<PinControlClickHandler>();
		}

		internal static Sprite GetPinSprite(bool pinned)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Expected O, but got Unknown
			//IL_00bb: Unknown result type (might be