Decompiled source of MasterChest v1.0.0

MasterChest.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MasterChest
{
	internal enum ChestMode
	{
		None,
		Master,
		Receiving
	}
	internal class ChestFilter
	{
		public readonly HashSet<string> Items = new HashSet<string>(StringComparer.Ordinal);

		public readonly HashSet<ItemType> Categories = new HashSet<ItemType>();

		public bool IsEmpty
		{
			get
			{
				if (Items.Count == 0)
				{
					return Categories.Count == 0;
				}
				return false;
			}
		}

		internal unsafe string Serialize()
		{
			return string.Join("|", Categories.Select((ItemType c) => "c:" + ((object)(*(ItemType*)(&c))/*cast due to .constrained prefix*/).ToString()).Concat(Items.Select((string i) => "i:" + i)));
		}

		internal static ChestFilter Parse(string s)
		{
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			ChestFilter chestFilter = new ChestFilter();
			if (string.IsNullOrEmpty(s))
			{
				return chestFilter;
			}
			string[] array = s.Split(new char[1] { '|' });
			foreach (string text in array)
			{
				if (text.Length >= 3 && text[1] == ':')
				{
					string text2 = text.Substring(2);
					ItemType result;
					if (text[0] == 'i')
					{
						chestFilter.Items.Add(text2);
					}
					else if (text[0] == 'c' && Enum.TryParse<ItemType>(text2, out result))
					{
						chestFilter.Categories.Add(result);
					}
				}
			}
			return chestFilter;
		}
	}
	internal static class ChestStore
	{
		internal static readonly int ModeKey = StringExtensionMethods.GetStableHashCode("squatch_masterchest_mode");

		internal static readonly int FilterKey = StringExtensionMethods.GetStableHashCode("squatch_masterchest_filter");

		private static ZDO GetZdo(Container c)
		{
			if (!((Object)(object)c != (Object)null) || !((Object)(object)c.m_nview != (Object)null) || !c.m_nview.IsValid())
			{
				return null;
			}
			return c.m_nview.GetZDO();
		}

		internal static ChestMode GetMode(Container container)
		{
			ZDO zdo = GetZdo(container);
			if (zdo == null)
			{
				return ChestMode.None;
			}
			int num = zdo.GetInt(ModeKey, 0);
			if (num < 0 || num > 2)
			{
				return ChestMode.None;
			}
			return (ChestMode)num;
		}

		internal static bool SetMode(Container container, ChestMode mode)
		{
			ZDO zdo = GetZdo(container);
			if (zdo == null)
			{
				return false;
			}
			container.m_nview.ClaimOwnership();
			zdo.Set(ModeKey, (int)mode, false);
			return true;
		}

		internal static ChestFilter GetFilter(Container container)
		{
			ZDO zdo = GetZdo(container);
			return ChestFilter.Parse((zdo != null) ? zdo.GetString(FilterKey, "") : null);
		}

		internal static bool SetFilter(Container container, ChestFilter filter)
		{
			ZDO zdo = GetZdo(container);
			if (zdo == null)
			{
				return false;
			}
			container.m_nview.ClaimOwnership();
			zdo.Set(FilterKey, filter.Serialize());
			return true;
		}
	}
	internal class CatalogItem
	{
		public string Prefab;

		public string Label;

		public ItemType Type;
	}
	internal static class ItemCatalog
	{
		private static List<CatalogItem> _items = new List<CatalogItem>();

		private static readonly Dictionary<string, string> SharedToPrefab = new Dictionary<string, string>();

		private static int _builtFrom = -1;

		private static ObjectDB _builtDb;

		internal static IReadOnlyList<CatalogItem> Items
		{
			get
			{
				EnsureBuilt();
				return _items;
			}
		}

		internal static IEnumerable<ItemType> Categories => from ItemType t in Enum.GetValues(typeof(ItemType))
			where (int)t > 0
			select t;

		internal unsafe static string CategoryLabel(ItemType t)
		{
			return Regex.Replace(((object)(*(ItemType*)(&t))/*cast due to .constrained prefix*/).ToString().Replace('_', ' '), "(?<=[a-z])(?=[A-Z])", " ");
		}

		internal static string PrefabNameOf(ItemData item)
		{
			if (item == null)
			{
				return null;
			}
			if ((Object)(object)item.m_dropPrefab != (Object)null)
			{
				return ((Object)item.m_dropPrefab).name;
			}
			EnsureBuilt();
			if (!SharedToPrefab.TryGetValue(item.m_shared.m_name, out var value))
			{
				return null;
			}
			return value;
		}

		private static void EnsureBuilt()
		{
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			ObjectDB instance = ObjectDB.instance;
			if ((Object)(object)instance == (Object)null || (instance == _builtDb && instance.m_items.Count == _builtFrom))
			{
				return;
			}
			_items = new List<CatalogItem>();
			SharedToPrefab.Clear();
			foreach (GameObject item in instance.m_items)
			{
				if ((Object)(object)item == (Object)null)
				{
					continue;
				}
				ItemDrop component = item.GetComponent<ItemDrop>();
				if ((Object)(object)component == (Object)null)
				{
					continue;
				}
				SharedData shared = component.m_itemData.m_shared;
				if (!string.IsNullOrEmpty(shared.m_name))
				{
					_items.Add(new CatalogItem
					{
						Prefab = ((Object)item).name,
						Label = Localization.instance.Localize(shared.m_name),
						Type = shared.m_itemType
					});
					if (!SharedToPrefab.ContainsKey(shared.m_name))
					{
						SharedToPrefab[shared.m_name] = ((Object)item).name;
					}
				}
			}
			_items = _items.OrderBy<CatalogItem, string>((CatalogItem i) => i.Label, StringComparer.OrdinalIgnoreCase).ToList();
			_builtDb = instance;
			_builtFrom = instance.m_items.Count;
			Plugin.Log.LogInfo((object)$"Item catalog built: {_items.Count} items.");
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "Awake")]
	internal static class InventoryGui_Awake_Patch
	{
		private static void Postfix(InventoryGui __instance)
		{
			SettingsUi.Build(__instance);
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "UpdateContainer")]
	internal static class InventoryGui_UpdateContainer_Patch
	{
		private static void Postfix(InventoryGui __instance)
		{
			try
			{
				SettingsUi.Reposition(__instance);
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Button placement failed: {arg}");
			}
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "Show")]
	internal static class InventoryGui_Show_Patch
	{
		private static void Postfix(Container container)
		{
			SettingsUi.HidePanel();
			if (!((Object)(object)container == (Object)null))
			{
				Plugin.Log.LogInfo((object)$"Opened '{container.m_name}' mode={ChestStore.GetMode(container)}");
			}
		}
	}
	[HarmonyPatch(typeof(ZInput), "GetButtonDown", new Type[] { typeof(string) })]
	internal static class ZInput_GetButtonDown_Patch
	{
		private static void Postfix(ref bool __result)
		{
			if (__result && PickerUi.SearchFocused)
			{
				__result = false;
			}
		}
	}
	[HarmonyPatch(typeof(ZInput), "GetButton", new Type[] { typeof(string) })]
	internal static class ZInput_GetButton_Patch
	{
		private static void Postfix(ref bool __result)
		{
			if (__result && PickerUi.SearchFocused)
			{
				__result = false;
			}
		}
	}
	[HarmonyPatch(typeof(ZInput), "GetKeyDown", new Type[]
	{
		typeof(KeyCode),
		typeof(bool)
	})]
	internal static class ZInput_GetKeyDown_Patch
	{
		private static void Postfix(ref bool __result)
		{
			if (__result && PickerUi.SearchFocused)
			{
				__result = false;
			}
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "Hide")]
	internal static class InventoryGui_Hide_Patch
	{
		private static void Prefix(InventoryGui __instance)
		{
			TransferGuard.Run(__instance.m_currentContainer);
		}

		private static void Postfix()
		{
			SettingsUi.HidePanel();
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "CloseContainer")]
	internal static class InventoryGui_CloseContainer_Patch
	{
		private static void Prefix(InventoryGui __instance)
		{
			TransferGuard.Run(__instance.m_currentContainer);
		}

		private static void Postfix()
		{
			SettingsUi.HidePanel();
		}
	}
	internal static class TransferGuard
	{
		internal static void Run(Container container)
		{
			try
			{
				Transfer.Run(container);
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Transfer failed: {arg}");
			}
		}
	}
	internal static class PickerUi
	{
		private class Row
		{
			public GameObject Go;

			public TMP_Text Text;

			public string Key;

			public string Label;
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static UnityAction <0>__Hide;
		}

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

			public static UnityAction <>9__15_0;

			public static UnityAction <>9__15_1;

			public static UnityAction<string> <>9__16_0;

			public static Func<KeyValuePair<string, string>, bool> <>9__21_0;

			internal void <Build>b__15_0()
			{
				SetTab(items: false);
			}

			internal void <Build>b__15_1()
			{
				SetTab(items: true);
			}

			internal void <BuildSearch>b__16_0(string _)
			{
				Rebuild();
			}

			internal bool <Rebuild>b__21_0(KeyValuePair<string, string> d)
			{
				return IsSelected(d.Key);
			}
		}

		private const int PoolSize = 60;

		private static GameObject _root;

		private static TMP_InputField _search;

		private static TMP_Text _status;

		private static ScrollRect _scroll;

		private static readonly List<Row> Rows = new List<Row>();

		private static bool _itemsTab;

		private static ChestFilter _filter = new ChestFilter();

		private static Container _container;

		private static int _lastTotal;

		internal static bool SearchFocused
		{
			get
			{
				if ((Object)(object)_search != (Object)null)
				{
					return _search.isFocused;
				}
				return false;
			}
		}

		internal static bool IsOpen
		{
			get
			{
				if ((Object)(object)_root != (Object)null)
				{
					return _root.activeSelf;
				}
				return false;
			}
		}

		internal static void Build(InventoryGui gui)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_0060: 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_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: 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_0098: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Expected O, but got Unknown
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Expected O, but got Unknown
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Expected O, but got Unknown
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Expected O, but got Unknown
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: 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_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: 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_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Expected O, but got Unknown
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Expected O, but got Unknown
			Button stackAllButton = gui.m_stackAllButton;
			Rows.Clear();
			_root = new GameObject("MasterChestPicker", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			_root.transform.SetParent((Transform)(object)gui.m_container, false);
			RectTransform val = (RectTransform)_root.transform;
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(0.5f, 0.5f);
			val.pivot = val2;
			Vector2 anchorMin = (val.anchorMax = val2);
			val.anchorMin = anchorMin;
			val.sizeDelta = new Vector2(440f, 520f);
			val.anchoredPosition = Vector2.zero;
			((Graphic)_root.GetComponent<Image>()).color = new Color(0.08f, 0.06f, 0.04f, 0.98f);
			Top((RectTransform)MakeText(gui, _root.transform, "Title", "Receiving Filters", 8f, 30f, 24f).transform, 0f, -8f, 400f, 30f);
			object obj = <>c.<>9__15_0;
			if (obj == null)
			{
				UnityAction val4 = delegate
				{
					SetTab(items: false);
				};
				<>c.<>9__15_0 = val4;
				obj = (object)val4;
			}
			Top((RectTransform)MakeButton(stackAllButton, "TabCategories", "Categories", (UnityAction)obj).transform, -105f, -44f, 200f, 32f);
			object obj2 = <>c.<>9__15_1;
			if (obj2 == null)
			{
				UnityAction val5 = delegate
				{
					SetTab(items: true);
				};
				<>c.<>9__15_1 = val5;
				obj2 = (object)val5;
			}
			Top((RectTransform)MakeButton(stackAllButton, "TabItems", "Items", (UnityAction)obj2).transform, 105f, -44f, 200f, 32f);
			BuildSearch(gui);
			BuildList(stackAllButton);
			_status = MakeText(gui, _root.transform, "Status", "", 0f, 0f, 16f);
			_status.alignment = (TextAlignmentOptions)513;
			RectTransform val6 = (RectTransform)_status.transform;
			((Vector2)(ref val2))..ctor(0f, 0f);
			val6.pivot = val2;
			anchorMin = (val6.anchorMax = val2);
			val6.anchorMin = anchorMin;
			val6.sizeDelta = new Vector2(250f, 36f);
			val6.anchoredPosition = new Vector2(20f, 10f);
			object obj3 = <>O.<0>__Hide;
			if (obj3 == null)
			{
				UnityAction val8 = Hide;
				<>O.<0>__Hide = val8;
				obj3 = (object)val8;
			}
			RectTransform val9 = (RectTransform)MakeButton(stackAllButton, "Close", "Close", (UnityAction)obj3).transform;
			((Vector2)(ref val2))..ctor(1f, 0f);
			val9.pivot = val2;
			anchorMin = (val9.anchorMax = val2);
			val9.anchorMin = anchorMin;
			val9.sizeDelta = new Vector2(130f, 36f);
			val9.anchoredPosition = new Vector2(-20f, 10f);
			_root.SetActive(false);
		}

		private static void BuildSearch(InventoryGui gui)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			//IL_008c: 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_00c1: Expected O, but got Unknown
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Expected O, but got Unknown
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Expected O, but got Unknown
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Expected O, but got Unknown
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Expected O, but got Unknown
			GameObject val = new GameObject("Search", new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(TMP_InputField)
			});
			val.transform.SetParent(_root.transform, false);
			Top((RectTransform)val.transform, 0f, -84f, 400f, 32f);
			((Graphic)val.GetComponent<Image>()).color = new Color(0f, 0f, 0f, 0.55f);
			GameObject val2 = new GameObject("TextArea", new Type[2]
			{
				typeof(RectTransform),
				typeof(RectMask2D)
			});
			val2.transform.SetParent(val.transform, false);
			Stretch((RectTransform)val2.transform, 8f, 2f);
			TMP_Text val3 = MakeText(gui, val2.transform, "Placeholder", "Search...", 0f, 0f, 18f);
			((Graphic)val3).color = new Color(1f, 1f, 1f, 0.4f);
			val3.alignment = (TextAlignmentOptions)513;
			Stretch((RectTransform)val3.transform, 0f, 0f);
			TMP_Text val4 = MakeText(gui, val2.transform, "Text", "", 0f, 0f, 18f);
			val4.alignment = (TextAlignmentOptions)513;
			Stretch((RectTransform)val4.transform, 0f, 0f);
			_search = val.GetComponent<TMP_InputField>();
			_search.textViewport = (RectTransform)val2.transform;
			_search.textComponent = val4;
			_search.placeholder = (Graphic)(object)val3;
			_search.restoreOriginalTextOnEscape = false;
			_search.richText = false;
			((UnityEvent<string>)(object)_search.onValueChanged).AddListener((UnityAction<string>)delegate
			{
				Rebuild();
			});
		}

		private static void BuildList(Button template)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Expected O, but got Unknown
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Expected O, but got Unknown
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Expected O, but got Unknown
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Expected O, but got Unknown
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Expected O, but got Unknown
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Expected O, but got Unknown
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Expected O, but got Unknown
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0326: Unknown result type (might be due to invalid IL or missing references)
			//IL_0330: Unknown result type (might be due to invalid IL or missing references)
			//IL_0355: Unknown result type (might be due to invalid IL or missing references)
			//IL_0377: Unknown result type (might be due to invalid IL or missing references)
			//IL_037e: Expected O, but got Unknown
			//IL_0399: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ad: Expected O, but got Unknown
			//IL_03d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f7: Expected O, but got Unknown
			//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0405: Unknown result type (might be due to invalid IL or missing references)
			//IL_0413: Unknown result type (might be due to invalid IL or missing references)
			//IL_0418: Unknown result type (might be due to invalid IL or missing references)
			//IL_0419: Unknown result type (might be due to invalid IL or missing references)
			//IL_0420: Unknown result type (might be due to invalid IL or missing references)
			//IL_0444: Unknown result type (might be due to invalid IL or missing references)
			//IL_050f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0519: Expected O, but got Unknown
			//IL_0525: Unknown result type (might be due to invalid IL or missing references)
			//IL_0534: Unknown result type (might be due to invalid IL or missing references)
			//IL_058e: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("List", new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(ScrollRect)
			});
			val.transform.SetParent(_root.transform, false);
			RectTransform val2 = (RectTransform)val.transform;
			val2.anchorMin = Vector2.zero;
			val2.anchorMax = Vector2.one;
			val2.offsetMin = new Vector2(20f, 56f);
			val2.offsetMax = new Vector2(-20f, -124f);
			((Graphic)val.GetComponent<Image>()).color = new Color(0f, 0f, 0f, 0.3f);
			GameObject val3 = new GameObject("Viewport", new Type[2]
			{
				typeof(RectTransform),
				typeof(RectMask2D)
			});
			val3.transform.SetParent(val.transform, false);
			Stretch((RectTransform)val3.transform, 0f, 0f);
			GameObject val4 = new GameObject("Content", new Type[3]
			{
				typeof(RectTransform),
				typeof(VerticalLayoutGroup),
				typeof(ContentSizeFitter)
			});
			val4.transform.SetParent(val3.transform, false);
			RectTransform val5 = (RectTransform)val4.transform;
			val5.anchorMin = new Vector2(0f, 1f);
			val5.anchorMax = new Vector2(1f, 1f);
			val5.pivot = new Vector2(0.5f, 1f);
			val5.anchoredPosition = Vector2.zero;
			val5.sizeDelta = Vector2.zero;
			VerticalLayoutGroup component = val4.GetComponent<VerticalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)component).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)component).childControlHeight = false;
			((HorizontalOrVerticalLayoutGroup)component).childForceExpandWidth = true;
			((HorizontalOrVerticalLayoutGroup)component).childForceExpandHeight = false;
			((HorizontalOrVerticalLayoutGroup)component).spacing = 2f;
			((LayoutGroup)component).padding = new RectOffset(4, 4, 4, 4);
			val4.GetComponent<ContentSizeFitter>().verticalFit = (FitMode)2;
			_scroll = val.GetComponent<ScrollRect>();
			_scroll.viewport = (RectTransform)val3.transform;
			_scroll.content = val5;
			_scroll.horizontal = false;
			_scroll.vertical = true;
			_scroll.movementType = (MovementType)2;
			_scroll.scrollSensitivity = Plugin.ScrollSpeed.Value;
			((RectTransform)val3.transform).offsetMax = new Vector2(-18f, 0f);
			GameObject val6 = new GameObject("Scrollbar", new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(Scrollbar)
			});
			val6.transform.SetParent(val.transform, false);
			RectTransform val7 = (RectTransform)val6.transform;
			val7.anchorMin = new Vector2(1f, 0f);
			val7.anchorMax = new Vector2(1f, 1f);
			val7.pivot = new Vector2(1f, 0.5f);
			val7.sizeDelta = new Vector2(16f, 0f);
			val7.anchoredPosition = Vector2.zero;
			((Graphic)val6.GetComponent<Image>()).color = new Color(1f, 1f, 1f, 0.08f);
			GameObject val8 = new GameObject("SlidingArea", new Type[1] { typeof(RectTransform) });
			val8.transform.SetParent(val6.transform, false);
			Stretch((RectTransform)val8.transform, 2f, 2f);
			GameObject val9 = new GameObject("Handle", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			val9.transform.SetParent(val8.transform, false);
			RectTransform val10 = (RectTransform)val9.transform;
			val10.anchorMin = Vector2.zero;
			val10.anchorMax = Vector2.one;
			Vector2 offsetMin = (val10.offsetMax = Vector2.zero);
			val10.offsetMin = offsetMin;
			Image component2 = val9.GetComponent<Image>();
			((Graphic)component2).color = new Color(0.85f, 0.7f, 0.4f, 0.85f);
			Scrollbar component3 = val6.GetComponent<Scrollbar>();
			component3.handleRect = val10;
			((Selectable)component3).targetGraphic = (Graphic)(object)component2;
			component3.direction = (Direction)2;
			_scroll.verticalScrollbar = component3;
			_scroll.verticalScrollbarVisibility = (ScrollbarVisibility)0;
			_scroll.verticalScrollbarSpacing = 0f;
			for (int i = 0; i < 60; i++)
			{
				Row row = new Row();
				row.Go = Object.Instantiate<GameObject>(((Component)template).gameObject, val4.transform);
				((Object)row.Go).name = "Row" + i;
				Button component4 = row.Go.GetComponent<Button>();
				((UnityEventBase)component4.onClick).RemoveAllListeners();
				Row captured = row;
				((UnityEvent)component4.onClick).AddListener((UnityAction)delegate
				{
					Toggle(captured);
				});
				((RectTransform)row.Go.transform).sizeDelta = new Vector2(0f, 30f);
				row.Text = row.Go.GetComponentInChildren<TMP_Text>();
				row.Text.text = "";
				row.Text.alignment = (TextAlignmentOptions)513;
				row.Text.margin = new Vector4(10f, 0f, 4f, 0f);
				row.Text.enableAutoSizing = true;
				row.Text.fontSizeMin = 10f;
				row.Text.fontSizeMax = 18f;
				row.Go.SetActive(false);
				Rows.Add(row);
			}
		}

		internal static void Show(Container container)
		{
			if (!((Object)(object)_root == (Object)null) && !((Object)(object)container == (Object)null))
			{
				_container = container;
				_filter = ChestStore.GetFilter(container);
				_itemsTab = false;
				_search.SetTextWithoutNotify("");
				_root.SetActive(true);
				_root.transform.SetAsLastSibling();
				Rebuild();
			}
		}

		internal static void Hide()
		{
			if ((Object)(object)_root != (Object)null)
			{
				_root.SetActive(false);
			}
			if ((Object)(object)_search != (Object)null)
			{
				_search.DeactivateInputField(false);
			}
			_container = null;
		}

		private static void SetTab(bool items)
		{
			_itemsTab = items;
			Rebuild();
		}

		private unsafe static void Rebuild()
		{
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			if (!IsOpen)
			{
				return;
			}
			string text = (_search.text ?? "").Trim();
			List<KeyValuePair<string, string>> list = new List<KeyValuePair<string, string>>();
			if (_itemsTab)
			{
				foreach (CatalogItem item in ItemCatalog.Items)
				{
					if (text.Length <= 0 || item.Label.IndexOf(text, StringComparison.OrdinalIgnoreCase) >= 0 || item.Prefab.IndexOf(text, StringComparison.OrdinalIgnoreCase) >= 0)
					{
						list.Add(new KeyValuePair<string, string>("i:" + item.Prefab, item.Label));
					}
				}
			}
			else
			{
				foreach (ItemType category in ItemCatalog.Categories)
				{
					string text2 = ItemCatalog.CategoryLabel(category);
					if (text.Length <= 0 || text2.IndexOf(text, StringComparison.OrdinalIgnoreCase) >= 0)
					{
						list.Add(new KeyValuePair<string, string>("c:" + ((object)(*(ItemType*)(&category))/*cast due to .constrained prefix*/).ToString(), text2));
					}
				}
			}
			List<KeyValuePair<string, string>> list2 = list.OrderByDescending((KeyValuePair<string, string> d) => IsSelected(d.Key)).ToList();
			_lastTotal = list2.Count;
			for (int num = 0; num < Rows.Count; num++)
			{
				Row row = Rows[num];
				if (num < list2.Count)
				{
					row.Key = list2[num].Key;
					row.Label = list2[num].Value;
					UpdateRowText(row);
					row.Go.SetActive(true);
				}
				else
				{
					row.Go.SetActive(false);
				}
			}
			_scroll.verticalNormalizedPosition = 1f;
			UpdateStatus();
		}

		private static bool IsSelected(string key)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			string text = key.Substring(2);
			if (key[0] == 'i')
			{
				return _filter.Items.Contains(text);
			}
			if (Enum.TryParse<ItemType>(text, out ItemType result))
			{
				return _filter.Categories.Contains(result);
			}
			return false;
		}

		private static void UpdateRowText(Row row)
		{
			row.Text.text = (IsSelected(row.Key) ? "[x]  " : "[   ]  ") + row.Label;
		}

		private static void Toggle(Row row)
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_container == (Object)null)
			{
				return;
			}
			string text = row.Key.Substring(2);
			ItemType result;
			if (row.Key[0] == 'i')
			{
				if (!_filter.Items.Remove(text))
				{
					_filter.Items.Add(text);
				}
			}
			else if (Enum.TryParse<ItemType>(text, out result) && !_filter.Categories.Remove(result))
			{
				_filter.Categories.Add(result);
			}
			ChestStore.SetFilter(_container, _filter);
			Plugin.Debug("Filter on '" + _container.m_name + "' now: " + _filter.Serialize());
			UpdateRowText(row);
			UpdateStatus();
			SettingsUi.Refresh();
		}

		private static void UpdateStatus()
		{
			string arg = ((_lastTotal > Rows.Count) ? $"first {Rows.Count} of {_lastTotal}, refine search" : $"{_lastTotal} shown");
			_status.text = $"{_filter.Categories.Count} cat, {_filter.Items.Count} items | {arg}";
		}

		private static GameObject MakeButton(Button template, string name, string label, UnityAction onClick)
		{
			GameObject obj = Object.Instantiate<GameObject>(((Component)template).gameObject, _root.transform);
			((Object)obj).name = name;
			Button component = obj.GetComponent<Button>();
			((UnityEventBase)component.onClick).RemoveAllListeners();
			((UnityEvent)component.onClick).AddListener(onClick);
			obj.GetComponentInChildren<TMP_Text>().text = label;
			return obj;
		}

		private static TMP_Text MakeText(InventoryGui gui, Transform parent, string name, string text, float x, float y, float size)
		{
			GameObject obj = Object.Instantiate<GameObject>(((Component)gui.m_containerName).gameObject, parent);
			((Object)obj).name = name;
			TMP_Text component = obj.GetComponent<TMP_Text>();
			component.text = text;
			component.alignment = (TextAlignmentOptions)514;
			component.enableAutoSizing = false;
			component.fontSize = size;
			return component;
		}

		private static void Top(RectTransform rt, float x, float y, float w, float h)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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)
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0.5f, 1f);
			rt.pivot = val;
			Vector2 anchorMin = (rt.anchorMax = val);
			rt.anchorMin = anchorMin;
			rt.sizeDelta = new Vector2(w, h);
			rt.anchoredPosition = new Vector2(x, y);
		}

		private static void Stretch(RectTransform rt, float padX, float padY)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			rt.anchorMin = Vector2.zero;
			rt.anchorMax = Vector2.one;
			rt.offsetMin = new Vector2(padX, padY);
			rt.offsetMax = new Vector2(0f - padX, 0f - padY);
		}
	}
	[BepInPlugin("squatch.masterchest", "MasterChest", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "squatch.masterchest";

		public const string Name = "MasterChest";

		public const string Version = "1.0.0";

		internal static Plugin Instance;

		internal static ManualLogSource Log;

		internal static ConfigEntry<float> ButtonOffsetX;

		internal static ConfigEntry<float> ButtonOffsetY;

		internal static ConfigEntry<float> TransferRadius;

		internal static ConfigEntry<bool> ShowMessage;

		internal static ConfigEntry<float> ScrollSpeed;

		internal static ConfigEntry<bool> VerboseLogging;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Expected O, but got Unknown
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			ButtonOffsetX = ((BaseUnityPlugin)this).Config.Bind<float>("UI", "ButtonOffsetX", 0f, "Nudge the Chest Settings button horizontally (pixels) from its default spot above the weight icon.");
			ButtonOffsetY = ((BaseUnityPlugin)this).Config.Bind<float>("UI", "ButtonOffsetY", 0f, "Nudge the Chest Settings button vertically (pixels). Positive moves it up.");
			TransferRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Transfer", "Radius", 30f, new ConfigDescription("Receiving chests within this many meters of the Master chest receive its items when you close it.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(2f, 100f), Array.Empty<object>()));
			ShowMessage = ((BaseUnityPlugin)this).Config.Bind<bool>("Transfer", "ShowMessage", true, "Show a short top-left message with how many items were moved.");
			ScrollSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("UI", "ScrollSpeed", 300f, new ConfigDescription("Pixels scrolled per mouse-wheel notch in the filter picker (a row is 30 px). Applies after the next world load.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(30f, 600f), Array.Empty<object>()));
			VerboseLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "VerboseLogging", false, "Log extra decisions to BepInEx/LogOutput.log.");
			_harmony = new Harmony("squatch.masterchest");
			_harmony.PatchAll();
			Log.LogInfo((object)"MasterChest 1.0.0 loaded.");
		}

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

		internal static void Debug(string msg)
		{
			if (VerboseLogging.Value)
			{
				Log.LogInfo((object)msg);
			}
		}
	}
	internal static class SettingsUi
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static UnityAction <0>__TogglePanel;

			public static UnityAction <1>__OnEditFilters;

			public static UnityAction <2>__HidePanel;
		}

		private static readonly ChestMode[] Modes = new ChestMode[3]
		{
			ChestMode.None,
			ChestMode.Master,
			ChestMode.Receiving
		};

		private static GameObject _button;

		private static GameObject _panel;

		private static TMP_Text _title;

		private static readonly TMP_Text[] ModeTexts = (TMP_Text[])(object)new TMP_Text[3];

		private static Button _filtersButton;

		private static TMP_Text _filtersText;

		private static Container _loggedContainer;

		private static int _loggedSlots = -1;

		private static Container Current
		{
			get
			{
				if (!((Object)(object)InventoryGui.instance != (Object)null))
				{
					return null;
				}
				return InventoryGui.instance.m_currentContainer;
			}
		}

		internal static void Build(InventoryGui gui)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			Button stackAllButton = gui.m_stackAllButton;
			_ = (RectTransform)((Component)stackAllButton).transform;
			_button = Object.Instantiate<GameObject>(((Component)stackAllButton).gameObject, ((Component)stackAllButton).transform.parent);
			((Object)_button).name = "MasterChestSettingsButton";
			_ = (RectTransform)_button.transform;
			Button component = _button.GetComponent<Button>();
			((UnityEventBase)component.onClick).RemoveAllListeners();
			ButtonClickedEvent onClick = component.onClick;
			object obj = <>O.<0>__TogglePanel;
			if (obj == null)
			{
				UnityAction val = TogglePanel;
				<>O.<0>__TogglePanel = val;
				obj = (object)val;
			}
			((UnityEvent)onClick).AddListener((UnityAction)obj);
			TMP_Text componentInChildren = _button.GetComponentInChildren<TMP_Text>();
			componentInChildren.text = "Chest\nSettings";
			componentInChildren.enableAutoSizing = true;
			componentInChildren.fontSizeMin = 10f;
			componentInChildren.fontSizeMax = 18f;
			Plugin.Log.LogInfo((object)("Settings button built (parent='" + ((Object)((Component)stackAllButton).transform.parent).name + "')."));
			BuildPanel(gui, stackAllButton);
			PickerUi.Build(gui);
		}

		internal static void Reposition(InventoryGui gui)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Expected O, but got Unknown
			//IL_00b2: 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_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			Container currentContainer = gui.m_currentContainer;
			if ((Object)(object)_button == (Object)null || (Object)(object)currentContainer == (Object)null || (Object)(object)gui.m_containerWeight == (Object)null)
			{
				return;
			}
			RectTransform val = (RectTransform)gui.m_containerWeight.transform;
			Transform parent = ((Transform)val).parent;
			RectTransform val2 = (RectTransform)(object)((parent is RectTransform) ? parent : null);
			Rect rect;
			int num;
			if ((Object)(object)val2 != (Object)null)
			{
				rect = val2.rect;
				if (((Rect)(ref rect)).width <= 150f)
				{
					rect = val2.rect;
					num = ((((Rect)(ref rect)).height <= 150f) ? 1 : 0);
					goto IL_0084;
				}
			}
			num = 0;
			goto IL_0084;
			IL_0084:
			bool flag = (byte)num != 0;
			RectTransform val3 = (flag ? val2 : val);
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			val3.GetWorldCorners(array);
			RectTransform val4 = (RectTransform)_button.transform;
			float num2 = ((((Transform)val4).lossyScale.y > 0f) ? ((Transform)val4).lossyScale.y : 1f);
			float num3 = Mathf.Clamp((array[3].x - array[0].x) / num2, 76f, 100f);
			float num4 = (flag ? 30f : 46f) + Plugin.ButtonOffsetY.Value;
			val4.pivot = new Vector2(0.5f, 0f);
			val4.SetSizeWithCurrentAnchors((Axis)0, num3);
			val4.SetSizeWithCurrentAnchors((Axis)1, 44f);
			((Transform)val4).position = new Vector3((array[0].x + array[3].x) / 2f + Plugin.ButtonOffsetX.Value * num2, array[1].y + num4 * num2, ((Transform)val4).position.z);
			if (_loggedContainer != currentContainer || _loggedSlots != gui.m_containerGrid.m_elements.Count)
			{
				_loggedContainer = currentContainer;
				_loggedSlots = gui.m_containerGrid.m_elements.Count;
				ManualLogSource log = Plugin.Log;
				string text = $"Settings button placed above weight for '{currentContainer.m_name}' ({_loggedSlots} slots): ";
				string arg = (flag ? "group" : "number");
				rect = val3.rect;
				object arg2 = ((Rect)(ref rect)).width;
				rect = val3.rect;
				string text2 = $"anchor={arg} size=({arg2:0},{((Rect)(ref rect)).height:0}) ";
				object arg3 = num3;
				Transform parent2 = ((Transform)val3).parent;
				log.LogInfo((object)(text + text2 + $"buttonWidth={arg3:0} parent='{((parent2 != null) ? ((Object)parent2).name : null)}'"));
			}
		}

		private static void BuildPanel(InventoryGui gui, Button template)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Expected O, but got Unknown
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Expected O, but got Unknown
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Expected O, but got Unknown
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Expected O, but got Unknown
			_panel = new GameObject("MasterChestPanel", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			_panel.transform.SetParent((Transform)(object)gui.m_container, false);
			RectTransform val = (RectTransform)_panel.transform;
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(0.5f, 0.5f);
			val.pivot = val2;
			Vector2 anchorMin = (val.anchorMax = val2);
			val.anchorMin = anchorMin;
			val.sizeDelta = new Vector2(300f, 275f);
			val.anchoredPosition = Vector2.zero;
			((Graphic)_panel.GetComponent<Image>()).color = new Color(0.08f, 0.06f, 0.04f, 0.97f);
			GameObject obj = Object.Instantiate<GameObject>(((Component)gui.m_containerName).gameObject, _panel.transform);
			((Object)obj).name = "Title";
			_title = obj.GetComponent<TMP_Text>();
			_title.alignment = (TextAlignmentOptions)514;
			Place((RectTransform)obj.transform, -8f, 30f, 280f);
			for (int i = 0; i < Modes.Length; i++)
			{
				ChestMode mode = Modes[i];
				GameObject val4 = MakeButton(template, _panel.transform, "Mode" + mode, -48f - (float)i * 44f, (UnityAction)delegate
				{
					OnModePicked(mode);
				});
				ModeTexts[i] = val4.GetComponentInChildren<TMP_Text>();
				ModeTexts[i].text = mode.ToString();
			}
			Transform transform = _panel.transform;
			float y = -48f - (float)Modes.Length * 44f;
			object obj2 = <>O.<1>__OnEditFilters;
			if (obj2 == null)
			{
				UnityAction val5 = OnEditFilters;
				<>O.<1>__OnEditFilters = val5;
				obj2 = (object)val5;
			}
			GameObject obj3 = MakeButton(template, transform, "EditFilters", y, (UnityAction)obj2);
			_filtersButton = obj3.GetComponent<Button>();
			_filtersText = obj3.GetComponentInChildren<TMP_Text>();
			_filtersText.text = "Edit Filters";
			Transform transform2 = _panel.transform;
			float y2 = -48f - (float)(Modes.Length + 1) * 44f;
			object obj4 = <>O.<2>__HidePanel;
			if (obj4 == null)
			{
				UnityAction val6 = HidePanel;
				<>O.<2>__HidePanel = val6;
				obj4 = (object)val6;
			}
			MakeButton(template, transform2, "Close", y2, (UnityAction)obj4).GetComponentInChildren<TMP_Text>().text = "Close";
			_panel.SetActive(false);
		}

		private static GameObject MakeButton(Button template, Transform parent, string name, float y, UnityAction onClick)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			GameObject obj = Object.Instantiate<GameObject>(((Component)template).gameObject, parent);
			((Object)obj).name = name;
			Button component = obj.GetComponent<Button>();
			((UnityEventBase)component.onClick).RemoveAllListeners();
			((UnityEvent)component.onClick).AddListener(onClick);
			Place((RectTransform)obj.transform, y, 36f, 240f);
			return obj;
		}

		private static void Place(RectTransform rt, float y, float height, float width)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0.5f, 1f);
			rt.pivot = val;
			Vector2 anchorMin = (rt.anchorMax = val);
			rt.anchorMin = anchorMin;
			rt.sizeDelta = new Vector2(width, height);
			rt.anchoredPosition = new Vector2(0f, y);
		}

		private static void TogglePanel()
		{
			if (!((Object)(object)_panel == (Object)null))
			{
				if (_panel.activeSelf)
				{
					HidePanel();
					return;
				}
				_panel.SetActive(true);
				_panel.transform.SetAsLastSibling();
				Refresh();
			}
		}

		internal static void HidePanel()
		{
			if ((Object)(object)_panel != (Object)null)
			{
				_panel.SetActive(false);
			}
			PickerUi.Hide();
		}

		private static void OnEditFilters()
		{
			Container current = Current;
			if (!((Object)(object)current == (Object)null) && ChestStore.GetMode(current) == ChestMode.Receiving)
			{
				_panel.SetActive(false);
				PickerUi.Show(current);
			}
		}

		private static void OnModePicked(ChestMode mode)
		{
			Container current = Current;
			if (!((Object)(object)current == (Object)null))
			{
				if (ChestStore.SetMode(current, mode))
				{
					Plugin.Log.LogInfo((object)$"'{current.m_name}' set to {mode} via Chest Settings (read back: {ChestStore.GetMode(current)})");
				}
				Refresh();
			}
		}

		internal static void Refresh()
		{
			if (!((Object)(object)_panel == (Object)null))
			{
				ChestMode mode = ChestStore.GetMode(Current);
				_title.text = "Chest Settings";
				for (int i = 0; i < Modes.Length; i++)
				{
					ModeTexts[i].text = ((Modes[i] == mode) ? "[x] " : "[  ] ") + Modes[i];
				}
				ChestFilter filter = ChestStore.GetFilter(Current);
				((Selectable)_filtersButton).interactable = mode == ChestMode.Receiving;
				_filtersText.text = (filter.IsEmpty ? "Edit Filters" : $"Edit Filters ({filter.Categories.Count}c, {filter.Items.Count}i)");
			}
		}
	}
	internal static class Transfer
	{
		private class Receiver
		{
			public Container Container;

			public ChestFilter Filter;

			public float Distance;

			public bool Prepared;
		}

		internal static void Run(Container master)
		{
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)master == (Object)null || ChestStore.GetMode(master) != ChestMode.Master || !master.IsOwner())
			{
				return;
			}
			Inventory inventory = master.GetInventory();
			if (inventory == null || inventory.NrOfItems() == 0)
			{
				return;
			}
			List<Receiver> list = FindReceivers(master);
			if (list.Count == 0)
			{
				Plugin.Debug($"Master '{master.m_name}' closed: no usable Receiving chests within {Plugin.TransferRadius.Value} m.");
				return;
			}
			ItemData val = (((Object)(object)InventoryGui.instance != (Object)null) ? InventoryGui.instance.m_dragItem : null);
			Dictionary<Container, int> dictionary = new Dictionary<Container, int>();
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			foreach (ItemData item in new List<ItemData>(inventory.GetAllItems()))
			{
				if (item == val)
				{
					continue;
				}
				string prefab = ItemCatalog.PrefabNameOf(item);
				ItemType type = item.m_shared.m_itemType;
				List<Receiver> exact = (from r in list
					where prefab != null && r.Filter.Items.Contains(prefab)
					orderby r.Distance
					select r).ToList();
				List<Receiver> second = (from r in list
					where r.Filter.Categories.Contains(type) && !exact.Contains(r)
					orderby r.Distance
					select r).ToList();
				foreach (Receiver item2 in exact.Concat(second))
				{
					int num4 = TryMove(inventory, item, item2);
					if (num4 > 0)
					{
						num3 += num4;
						dictionary[item2.Container] = (dictionary.TryGetValue(item2.Container, out var value) ? value : 0) + num4;
						if (exact.Contains(item2))
						{
							num++;
						}
						else
						{
							num2++;
						}
						Plugin.Debug(string.Format("  {0} x{1} -> '{2}' ({3}, {4:0.#} m)", prefab ?? item.m_shared.m_name, num4, item2.Container.m_name, exact.Contains(item2) ? "exact" : "category", item2.Distance));
						if (!inventory.ContainsItem(item))
						{
							break;
						}
					}
				}
			}
			string text = ((num3 == 0) ? $"Master '{master.m_name}' closed: nothing matched or fit ({list.Count} Receiving chests in range)." : $"Master '{master.m_name}' closed: moved {num3} items to {dictionary.Count} chest(s) ({num} exact, {num2} category).");
			Plugin.Log.LogInfo((object)text);
			if (num3 > 0 && Plugin.ShowMessage.Value && (Object)(object)Player.m_localPlayer != (Object)null)
			{
				((Character)Player.m_localPlayer).Message((MessageType)1, $"MasterChest: moved {num3} items to {dictionary.Count} chest(s)", 0, (Sprite)null, false);
			}
		}

		private static int TryMove(Inventory masterInv, ItemData item, Receiver r)
		{
			if (!Prepare(r))
			{
				return 0;
			}
			Inventory inventory = r.Container.GetInventory();
			if (!inventory.HaveEmptySlot() && inventory.FindFreeStackSpace(item.m_shared.m_name, (float)item.m_worldLevel) <= 0)
			{
				return 0;
			}
			int stack = item.m_stack;
			inventory.MoveItemToThis(masterInv, item);
			if (!masterInv.ContainsItem(item))
			{
				return stack;
			}
			return stack - item.m_stack;
		}

		private static bool Prepare(Receiver r)
		{
			if (r.Prepared)
			{
				return true;
			}
			Container container = r.Container;
			if ((Object)(object)container == (Object)null || (Object)(object)container.m_nview == (Object)null || !container.m_nview.IsValid() || container.GetInventory() == null)
			{
				return false;
			}
			container.m_nview.ClaimOwnership();
			if (!container.IsOwner())
			{
				return false;
			}
			container.Load();
			r.Prepared = true;
			return true;
		}

		private static List<Receiver> FindReceivers(Container master)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			List<Receiver> list = new List<Receiver>();
			HashSet<Container> hashSet = new HashSet<Container>();
			Vector3 position = ((Component)master).transform.position;
			float value = Plugin.TransferRadius.Value;
			Collider[] array = Physics.OverlapSphere(position, value, -1, (QueryTriggerInteraction)2);
			for (int i = 0; i < array.Length; i++)
			{
				Container componentInParent = ((Component)array[i]).GetComponentInParent<Container>();
				if ((Object)(object)componentInParent == (Object)null || (Object)(object)componentInParent == (Object)(object)master || !hashSet.Add(componentInParent) || (Object)(object)componentInParent.m_nview == (Object)null || !componentInParent.m_nview.IsValid() || componentInParent.GetInventory() == null || ChestStore.GetMode(componentInParent) != ChestMode.Receiving)
				{
					continue;
				}
				float num = Vector3.Distance(position, ((Component)componentInParent).transform.position);
				if (!(num > value) && (!componentInParent.m_checkGuardStone || PrivateArea.CheckAccess(((Component)componentInParent).transform.position, 0f, false, false)) && (componentInParent.IsOwner() || componentInParent.m_nview.GetZDO().GetInt(ZDOVars.s_inUse, 0) != 1))
				{
					ChestFilter filter = ChestStore.GetFilter(componentInParent);
					if (!filter.IsEmpty)
					{
						list.Add(new Receiver
						{
							Container = componentInParent,
							Filter = filter,
							Distance = num
						});
					}
				}
			}
			return list;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}