Decompiled source of AzuAutoStore v2.1.6

AzuAutoStore.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using AzuAutoStore.Patches.Favoriting;
using AzuAutoStore.Util;
using AzuAutoStore.Util.Compatibility.WardIsLove;
using AzuExtendedPlayerInventory;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using JetBrains.Annotations;
using Microsoft.CodeAnalysis;
using ServerSync;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Core.Tokens;
using YamlDotNet.Helpers;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.BufferedDeserialization;
using YamlDotNet.Serialization.BufferedDeserialization.TypeDiscriminators;
using YamlDotNet.Serialization.Converters;
using YamlDotNet.Serialization.EventEmitters;
using YamlDotNet.Serialization.NamingConventions;
using YamlDotNet.Serialization.NodeDeserializers;
using YamlDotNet.Serialization.NodeTypeResolvers;
using YamlDotNet.Serialization.ObjectFactories;
using YamlDotNet.Serialization.ObjectGraphTraversalStrategies;
using YamlDotNet.Serialization.ObjectGraphVisitors;
using YamlDotNet.Serialization.Schemas;
using YamlDotNet.Serialization.TypeInspectors;
using YamlDotNet.Serialization.TypeResolvers;
using YamlDotNet.Serialization.Utilities;
using YamlDotNet.Serialization.ValueDeserializers;

[assembly: AssemblyFileVersion("2.1.6")]
[assembly: Guid("4358610B-F3F4-4843-B7AF-98B7BC60DCDE")]
[assembly: ComVisible(false)]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyProduct("AzuAutoStore")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyTitle("AzuAutoStore")]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: CompilationRelaxations(8)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("Azumatt")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.1.6.0")]
[module: <aac616d2-9428-454f-a764-8e56eaa45ae7>RefSafetyRules(11)]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[<44b0f4a9-1364-4803-b3e2-57b8f98100cd>Embedded]
	internal sealed class <44b0f4a9-1364-4803-b3e2-57b8f98100cd>EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[<44b0f4a9-1364-4803-b3e2-57b8f98100cd>Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class <c3ab1a27-299d-4c52-9c11-b49797a03bf2>NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public <c3ab1a27-299d-4c52-9c11-b49797a03bf2>NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public <c3ab1a27-299d-4c52-9c11-b49797a03bf2>NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[<44b0f4a9-1364-4803-b3e2-57b8f98100cd>Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class <1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public <1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[<44b0f4a9-1364-4803-b3e2-57b8f98100cd>Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class <aac616d2-9428-454f-a764-8e56eaa45ae7>RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public <aac616d2-9428-454f-a764-8e56eaa45ae7>RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace LocalizationManager
{
	[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(0)]
	[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(1)]
	[PublicAPI]
	public class Localizer
	{
		private static readonly Dictionary<string, Dictionary<string, Func<string>>> PlaceholderProcessors;

		private static readonly Dictionary<string, Dictionary<string, string>> loadedTexts;

		private static readonly ConditionalWeakTable<Localization, string> localizationLanguage;

		private static readonly List<WeakReference<Localization>> localizationObjects;

		[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(2)]
		private static BaseUnityPlugin _plugin;

		private static readonly List<string> fileExtensions;

		private static BaseUnityPlugin plugin
		{
			get
			{
				//IL_009b: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a5: Expected O, but got Unknown
				if (_plugin == null)
				{
					IEnumerable<TypeInfo> source;
					try
					{
						source = Assembly.GetExecutingAssembly().DefinedTypes.ToList();
					}
					catch (ReflectionTypeLoadException ex)
					{
						source = from t in ex.Types
							where t != null
							select t.GetTypeInfo();
					}
					_plugin = (BaseUnityPlugin)Chainloader.ManagerObject.GetComponent((Type)source.First([<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(0)] (TypeInfo t) => t.IsClass && typeof(BaseUnityPlugin).IsAssignableFrom(t)));
				}
				return _plugin;
			}
		}

		private static void UpdatePlaceholderText(Localization localization, string key)
		{
			localizationLanguage.TryGetValue(localization, out var value);
			string text = loadedTexts[value][key];
			if (PlaceholderProcessors.TryGetValue(key, out var value2))
			{
				text = value2.Aggregate(text, [<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(0)] (string current, KeyValuePair<string, Func<string>> kv) => current.Replace("{" + kv.Key + "}", kv.Value()));
			}
			localization.AddWord(key, text);
		}

		public static void AddPlaceholder<T>(string key, string placeholder, ConfigEntry<T> config, [<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(new byte[] { 2, 1, 1 })] Func<T, string> convertConfigValue = null)
		{
			if (convertConfigValue == null)
			{
				convertConfigValue = [<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(0)] [return: <c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(1)] (T val) => val.ToString();
			}
			if (!PlaceholderProcessors.ContainsKey(key))
			{
				PlaceholderProcessors[key] = new Dictionary<string, Func<string>>();
			}
			config.SettingChanged += [<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(0)] (object _, EventArgs _) =>
			{
				UpdatePlaceholder();
			};
			if (loadedTexts.ContainsKey(Localization.instance.GetSelectedLanguage()))
			{
				UpdatePlaceholder();
			}
			void UpdatePlaceholder()
			{
				PlaceholderProcessors[key][placeholder] = () => convertConfigValue(config.Value);
				UpdatePlaceholderText(Localization.instance, key);
			}
		}

		public static void AddText(string key, string text)
		{
			List<WeakReference<Localization>> list = new List<WeakReference<Localization>>();
			foreach (WeakReference<Localization> localizationObject in localizationObjects)
			{
				if (localizationObject.TryGetTarget(out var target))
				{
					Dictionary<string, string> dictionary = loadedTexts[localizationLanguage.GetOrCreateValue(target)];
					if (!target.m_translations.ContainsKey(key))
					{
						dictionary[key] = text;
						target.AddWord(key, text);
					}
				}
				else
				{
					list.Add(localizationObject);
				}
			}
			foreach (WeakReference<Localization> item in list)
			{
				localizationObjects.Remove(item);
			}
		}

		public static void Load()
		{
			LoadLocalization(Localization.instance, Localization.instance.GetSelectedLanguage());
		}

		private static void LoadLocalization(Localization __instance, string language)
		{
			if (!localizationLanguage.Remove(__instance))
			{
				localizationObjects.Add(new WeakReference<Localization>(__instance));
			}
			localizationLanguage.Add(__instance, language);
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			foreach (string item in from f in Directory.GetFiles(Path.GetDirectoryName(Paths.PluginPath), plugin.Info.Metadata.Name + ".*", SearchOption.AllDirectories)
				where fileExtensions.IndexOf(Path.GetExtension(f)) >= 0
				select f)
			{
				string text = Path.GetFileNameWithoutExtension(item).Split(new char[1] { '.' })[1];
				if (dictionary.ContainsKey(text))
				{
					Debug.LogWarning((object)("Duplicate key " + text + " found for " + plugin.Info.Metadata.Name + ". The duplicate file found at " + item + " will be skipped."));
				}
				else
				{
					dictionary[text] = item;
				}
			}
			byte[] array = LoadTranslationFromAssembly("English");
			if (array == null)
			{
				throw new Exception("Found no English localizations in mod " + plugin.Info.Metadata.Name + ". Expected an embedded resource translations/English.json or translations/English.yml.");
			}
			Dictionary<string, string> dictionary2 = new DeserializerBuilder().IgnoreFields().Build().Deserialize<Dictionary<string, string>>(Encoding.UTF8.GetString(array));
			if (dictionary2 == null)
			{
				throw new Exception("Localization for mod " + plugin.Info.Metadata.Name + " failed: Localization file was empty.");
			}
			string text2 = null;
			if (language != "English")
			{
				if (dictionary.ContainsKey(language))
				{
					text2 = File.ReadAllText(dictionary[language]);
				}
				else
				{
					byte[] array2 = LoadTranslationFromAssembly(language);
					if (array2 != null)
					{
						text2 = Encoding.UTF8.GetString(array2);
					}
				}
			}
			if (text2 == null && dictionary.ContainsKey("English"))
			{
				text2 = File.ReadAllText(dictionary["English"]);
			}
			if (text2 != null)
			{
				foreach (KeyValuePair<string, string> item2 in new DeserializerBuilder().IgnoreFields().Build().Deserialize<Dictionary<string, string>>(text2) ?? new Dictionary<string, string>())
				{
					dictionary2[item2.Key] = item2.Value;
				}
			}
			loadedTexts[language] = dictionary2;
			foreach (KeyValuePair<string, string> item3 in dictionary2)
			{
				UpdatePlaceholderText(__instance, item3.Key);
			}
		}

		static Localizer()
		{
			//IL_004d: 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_008c: Expected O, but got Unknown
			PlaceholderProcessors = new Dictionary<string, Dictionary<string, Func<string>>>();
			loadedTexts = new Dictionary<string, Dictionary<string, string>>();
			localizationLanguage = new ConditionalWeakTable<Localization, string>();
			localizationObjects = new List<WeakReference<Localization>>();
			fileExtensions = new List<string> { ".json", ".yml" };
			new Harmony("org.bepinex.helpers.LocalizationManager").Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Localization), "LoadCSV", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Localizer), "LoadLocalization", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		[return: <c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(2)]
		private static byte[] LoadTranslationFromAssembly(string language)
		{
			foreach (string fileExtension in fileExtensions)
			{
				byte[] array = ReadEmbeddedFileBytes("translations." + language + fileExtension);
				if (array != null)
				{
					return array;
				}
			}
			return null;
		}

		[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(2)]
		public static byte[] ReadEmbeddedFileBytes([<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(1)] string resourceFileName, Assembly containingAssembly = null)
		{
			using MemoryStream memoryStream = new MemoryStream();
			if ((object)containingAssembly == null)
			{
				containingAssembly = Assembly.GetCallingAssembly();
			}
			string text = containingAssembly.GetManifestResourceNames().FirstOrDefault([<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(0)] (string str) => str.EndsWith(resourceFileName, StringComparison.Ordinal));
			if (text != null)
			{
				containingAssembly.GetManifestResourceStream(text)?.CopyTo(memoryStream);
			}
			return (memoryStream.Length == 0L) ? null : memoryStream.ToArray();
		}
	}
}
namespace AzuAutoStore
{
	[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(1)]
	[HarmonyPatch(typeof(Terminal), "InitTerminal")]
	[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(0)]
	internal static class TerminalInitTerminalPatch
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(0)]
			public static readonly <>c <>9 = new <>c();

			[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(0)]
			public static Func<Piece, bool> <>9__2_6;

			[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(0)]
			public static Func<ItemData, int> <>9__2_9;

			[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(0)]
			public static ConsoleEvent <>9__2_0;

			[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(0)]
			public static ConsoleOptionsFetcher <>9__2_1;

			[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(0)]
			internal void <Postfix>b__2_0(ConsoleEventArgs args)
			{
				<>c__DisplayClass2_0 <>c__DisplayClass2_ = new <>c__DisplayClass2_0();
				if (args.Length > 1 && Object.op_Implicit((Object)(object)ZNetScene.instance))
				{
					<>c__DisplayClass2_.itemCount = 0;
					bool flag = <>c__DisplayClass2_.<Postfix>g__SearchNearbyContainersFor|2(args[1]);
					((Character)Player.m_localPlayer).Message((MessageType)2, flag ? $"Found {<>c__DisplayClass2_.itemCount} items matching '{args[1]}' in nearby containers." : ("<color=red>No items matching '" + args[1] + "' found in nearby containers.</color>"), 0, (Sprite)null);
				}
			}

			[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(0)]
			internal bool <Postfix>b__2_6(Piece p)
			{
				return Object.op_Implicit((Object)(object)((Component)p).GetComponent<Container>());
			}

			[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(0)]
			internal int <Postfix>b__2_9(ItemData item)
			{
				return item.m_stack;
			}

			[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(0)]
			internal List<string> <Postfix>b__2_1()
			{
				if (Object.op_Implicit((Object)(object)ZNetScene.instance))
				{
					return ZNetScene.instance.GetPrefabNames();
				}
				return new List<string>();
			}
		}

		[CompilerGenerated]
		private sealed class <>c__DisplayClass2_0
		{
			public int itemCount;
		}

		private const float SearchRadius = 50f;

		public static void GetAllPiecesInRadius(Vector3 p, float radius, List<Piece> pieces)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			if (Piece.s_ghostLayer == 0)
			{
				Piece.s_ghostLayer = LayerMask.NameToLayer("ghost");
			}
			foreach (Piece s_allPiece in Piece.s_allPieces)
			{
				if (((Component)s_allPiece).gameObject.layer != Piece.s_ghostLayer && (double)Vector3.Distance(p, ((Component)s_allPiece).transform.position) < (double)radius)
				{
					pieces.Add(s_allPiece);
				}
			}
		}

		private static void Postfix(Terminal __instance)
		{
			//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
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			object obj = <>c.<>9__2_0;
			if (obj == null)
			{
				ConsoleEvent val = [<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(0)] (ConsoleEventArgs args) =>
				{
					int itemCount;
					if (args.Length > 1 && Object.op_Implicit((Object)(object)ZNetScene.instance))
					{
						itemCount = 0;
						bool flag = SearchNearbyContainersFor(args[1]);
						((Character)Player.m_localPlayer).Message((MessageType)2, flag ? $"Found {itemCount} items matching '{args[1]}' in nearby containers." : ("<color=red>No items matching '" + args[1] + "' found in nearby containers.</color>"), 0, (Sprite)null);
					}
					IEnumerable<Piece> GetNearbyMatchingPieces(string query)
					{
						//IL_0024: Unknown result type (might be due to invalid IL or missing references)
						List<Piece> list = new List<Piece>();
						GetAllPiecesInRadius(((Component)Player.m_localPlayer).transform.position, 50f, list);
						return from p in list
							where Object.op_Implicit((Object)(object)((Component)p).GetComponent<Container>())
							where ContainerContainsMatchingItem((Component)(object)p, query.ToLower(), ref itemCount)
							select p;
					}
					bool SearchNearbyContainersFor(string query)
					{
						//IL_0031: 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)
						//IL_007a: Unknown result type (might be due to invalid IL or missing references)
						//IL_007f: Unknown result type (might be due to invalid IL or missing references)
						//IL_0086: Unknown result type (might be due to invalid IL or missing references)
						//IL_0092: Unknown result type (might be due to invalid IL or missing references)
						//IL_0097: Unknown result type (might be due to invalid IL or missing references)
						bool result = false;
						Piece val3 = null;
						float num = float.MaxValue;
						foreach (Piece nearbyMatchingPiece in GetNearbyMatchingPieces(query))
						{
							Functions.PingContainer((Component)(object)nearbyMatchingPiece);
							result = true;
							float num2 = Vector3.Distance(((Component)nearbyMatchingPiece).transform.position, ((Component)Player.m_localPlayer).transform.position);
							if (num2 < num)
							{
								num = num2;
								val3 = nearbyMatchingPiece;
							}
						}
						if ((Object)(object)val3 != (Object)null)
						{
							Vector3 position = ((Component)val3).transform.position;
							((Character)Player.m_localPlayer).SetLookDir(position - ((Component)Player.m_localPlayer).transform.position, 3.5f);
						}
						return result;
					}
				};
				<>c.<>9__2_0 = val;
				obj = (object)val;
			}
			object obj2 = <>c.<>9__2_1;
			if (obj2 == null)
			{
				ConsoleOptionsFetcher val2 = [<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(0)] () => Object.op_Implicit((Object)(object)ZNetScene.instance) ? ZNetScene.instance.GetPrefabNames() : new List<string>();
				<>c.<>9__2_1 = val2;
				obj2 = (object)val2;
			}
			new ConsoleCommand("azuautostoresearch", "[prefab name/query text] - search for items in chests near the player. It uses the prefab name", (ConsoleEvent)obj, false, false, false, false, false, (ConsoleOptionsFetcher)obj2, false, false, false);
			static bool ContainerContainsMatchingItem(Component container, string query, ref int count)
			{
				IEnumerable<ItemData> source = (from i in container.GetComponent<Container>().GetInventory().GetAllItems()
					where NormalizedItemName(i).Contains(query) || i.m_shared.m_name.ToLower().Contains(query)
					select i).ToList();
				count += source.Sum([<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(0)] (ItemData item) => item.m_stack);
				return source.Any();
			}
			static string NormalizedItemName(ItemData itemData)
			{
				return Utils.GetPrefabName(itemData.m_dropPrefab).ToLower();
			}
		}
	}
	[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(1)]
	[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(0)]
	[BepInPlugin("Azumatt.AzuAutoStore", "AzuAutoStore", "2.1.6")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class AzuAutoStorePlugin : BaseUnityPlugin
	{
		[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(0)]
		public enum Toggle
		{
			Off,
			On
		}

		[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(0)]
		private class ConfigurationManagerAttributes
		{
			[UsedImplicitly]
			public int? Order;

			[UsedImplicitly]
			public bool? Browsable;

			[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(1)]
			[UsedImplicitly]
			public string Category;

			[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(new byte[] { 2, 1 })]
			[UsedImplicitly]
			public Action<ConfigEntryBase> CustomDrawer;
		}

		[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(0)]
		private class AcceptableShortcuts : AcceptableValueBase
		{
			public AcceptableShortcuts()
				: base(typeof(KeyboardShortcut))
			{
			}

			public override object Clamp(object value)
			{
				return value;
			}

			public override bool IsValid(object value)
			{
				return true;
			}

			public override string ToDescriptionString()
			{
				return "# Acceptable values: " + string.Join(", ", UnityInput.Current.SupportedKeyCodes);
			}
		}

		internal const string ModName = "AzuAutoStore";

		internal const string ModVersion = "2.1.6";

		internal const string Author = "Azumatt";

		internal const string ModGUID = "Azumatt.AzuAutoStore";

		private static readonly string ConfigFileName = "Azumatt.AzuAutoStore.cfg";

		private static readonly string ConfigFileFullPath;

		internal static string ConnectionError;

		private readonly Harmony _harmony = new Harmony("Azumatt.AzuAutoStore");

		public static readonly ManualLogSource AzuAutoStoreLogger;

		private static readonly ConfigSync ConfigSync;

		internal static readonly string yamlFileName;

		internal static readonly string yamlPath;

		internal static readonly CustomSyncedValue<string> AzuAutoStoreContainerData;

		internal static readonly CustomSyncedValue<string> CraftyContainerGroupsData;

		[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(new byte[] { 2, 1, 1 })]
		internal static Dictionary<string, object> yamlData;

		[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(new byte[] { 1, 2, 1, 2 })]
		internal static Dictionary<string, HashSet<string>> groups;

		internal static AzuAutoStorePlugin self;

		private static ConfigEntry<Toggle> _serverConfigLocked;

		internal static ConfigEntry<Toggle> MustHaveExistingItemToPull;

		private static ConfigEntry<KeyboardShortcut> _storeShortcut;

		private static ConfigEntry<KeyboardShortcut> _pauseShortcut;

		internal static ConfigEntry<int> SecondsToWaitBeforeStoring;

		internal static ConfigEntry<float> IntervalSeconds;

		internal static ConfigEntry<float> PlayerRange;

		internal static ConfigEntry<float> FallbackRange;

		internal static ConfigEntry<Toggle> PlayerIgnoreHotbar;

		internal static ConfigEntry<Toggle> PlayerIgnoreQuickSlots;

		internal static ConfigEntry<string> PingVfxString;

		internal static ConfigEntry<Toggle> HighlightContainers;

		internal static ConfigEntry<Toggle> PingContainers;

		public static ConfigEntry<Color> BorderColorFavoritedItem;

		public static ConfigEntry<Color> BorderColorFavoritedItemOnFavoritedSlot;

		public static ConfigEntry<Color> BorderColorFavoritedSlot;

		public static ConfigEntry<bool> DisplayTooltipHint;

		public static ConfigEntry<KeyboardShortcut> FavoritingModifierKeybind1;

		public static ConfigEntry<KeyboardShortcut> FavoritingModifierKeybind2;

		public static ConfigEntry<KeyboardShortcut> SearchModifierKeybind;

		public static ConfigEntry<string> FavoritedItemTooltip;

		public static ConfigEntry<string> FavoritedSlotTooltip;

		public static ConfigEntry<string> ItemOnFavoritedSlotTooltip;

		public void Awake()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: 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_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Expected O, but got Unknown
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Expected O, but got Unknown
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Expected O, but got Unknown
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Expected O, but got Unknown
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: 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_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Expected O, but got Unknown
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Expected O, but got Unknown
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: Expected O, but got Unknown
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e8: Expected O, but got Unknown
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e5: 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_0449: Unknown result type (might be due to invalid IL or missing references)
			self = this;
			_serverConfigLocked = config("1 - General", "Lock Configuration", Toggle.On, new ConfigDescription("If on, the configuration is locked and can be changed by server admins only.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 8
				}
			}));
			ConfigSync.AddLockingConfigEntry<Toggle>(_serverConfigLocked);
			MustHaveExistingItemToPull = config("1 - General", "Must Have Existing Item To Pull", Toggle.On, new ConfigDescription("If on, the chest must already have the item in its inventory to pull it from the world or player into the chest.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 7
				}
			}));
			PlayerRange = config("1 - General", "Player Range", 5f, new ConfigDescription("The maximum distance from the player to store items in chests when the Store Shortcut is pressed. Follows storage rules for allowed items.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 100f), new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 6
				}
			}));
			FallbackRange = config("1 - General", "Fallback Range", 10f, new ConfigDescription("The range to use if the container has no range set in the yml file. This will be the fallback range for all containers.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 5
				}
			}));
			PlayerIgnoreHotbar = config("1 - General", "Player Ignore Hotbar", Toggle.On, new ConfigDescription("If on, the player's hotbar will not be stored when the Store Shortcut is pressed.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 4
				}
			}), synchronizedSetting: false);
			PlayerIgnoreQuickSlots = config("1 - General", "Player Ignore Quick Slots", Toggle.Off, new ConfigDescription("If on, the player's quick slots will not be stored when the Store Shortcut is pressed. (Requires Quick Slots mod, turn on only if you need it!)", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 3
				}
			}), synchronizedSetting: false);
			PingVfxString = TextEntryConfig("1 - General", "Ping VFX", "vfx_Potion_health_medium", new ConfigDescription("The VFX to play when a chest is pinged. Leave blank to disable and only highlight the chest. (Full prefab list: https://valheim-modding.github.io/Jotunn/data/prefabs/prefab-list.html)", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 2
				}
			}));
			HighlightContainers = config("1 - General", "Highlight Containers", Toggle.On, new ConfigDescription("If on, the containers will be highlighted when something is stored in them. If off, the containers will not be highlighted if something is stored in them.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 1
				}
			}), synchronizedSetting: false);
			PingContainers = config("1 - General", "Ping Containers", Toggle.On, new ConfigDescription("If on, the containers will be pinged with the Ping VFX when something is stored in them. If off, the containers will not be pinged if something is stored in them.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 0
				}
			}), synchronizedSetting: false);
			SecondsToWaitBeforeStoring = config("1 - General", "Seconds To Wait Before Storing", 10, new ConfigDescription("The number of seconds to wait before storing items into chests nearby automatically after you have pressed your hotkey to pause.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 60), Array.Empty<object>()));
			IntervalSeconds = config("1 - General", "IntervalSeconds", 10f, new ConfigDescription("The number of seconds that must pass before the chest will do an automatic check for items nearby, WARNING: Reducing this will decrease performance!", (AcceptableValueBase)null, Array.Empty<object>()));
			_storeShortcut = config<KeyboardShortcut>("2 - Shortcuts", "Store Shortcut", new KeyboardShortcut((KeyCode)46, Array.Empty<KeyCode>()), new ConfigDescription("Keyboard shortcut/Hotkey to store your inventory into nearby containers.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 1
				}
			}), synchronizedSetting: false);
			_pauseShortcut = config<KeyboardShortcut>("2 - Shortcuts", "Pause Shortcut", new KeyboardShortcut((KeyCode)46, (KeyCode[])(object)new KeyCode[1] { (KeyCode)304 }), "Keyboard shortcut/Hotkey to temporarily stop storing items into chests nearby automatically. Does not override the player hotkey store.", synchronizedSetting: false);
			SearchModifierKeybind = config<KeyboardShortcut>("2 - Shortcuts", "SearchModifierKeybind", new KeyboardShortcut((KeyCode)121, Array.Empty<KeyCode>()), "While holding this, you can search nearby chests for the prefab you clicked in your inventory.", synchronizedSetting: false);
			string group = "3 - Favoriting";
			string text = "While holding this, left clicking on items or right clicking on slots favorites them, disallowing storing";
			BorderColorFavoritedItem = config<Color>(group, "BorderColorFavoritedItem", new Color(1f, 0.8482759f, 0f), "Color of the border for slots containing favorited items.", synchronizedSetting: false);
			BorderColorFavoritedItem.SettingChanged += [<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(0)] (object a, EventArgs b) =>
			{
				FavoritingMode.RefreshDisplay();
			};
			BorderColorFavoritedItemOnFavoritedSlot = config<Color>(group, "BorderColorFavoritedItemOnFavoritedSlot", new Color(0.5f, 0.67413795f, 0.5f), "Color of the border of a favorited slot that also contains a favorited item.", synchronizedSetting: false);
			BorderColorFavoritedSlot = config<Color>(group, "BorderColorFavoritedSlot", new Color(0f, 0.5f, 1f), "Color of the border for favorited slots.", synchronizedSetting: false);
			DisplayTooltipHint = config(group, "DisplayTooltipHint", value: true, "Whether to add additional info the item tooltip of a favorited or trash flagged item.", synchronizedSetting: false);
			FavoritingModifierKeybind1 = config<KeyboardShortcut>(group, "FavoritingModifierKeybind1", new KeyboardShortcut((KeyCode)122, Array.Empty<KeyCode>()), text + " Identical to FavoritingModifierKeybind2.", synchronizedSetting: false);
			FavoritingModifierKeybind2 = config<KeyboardShortcut>(group, "FavoritingModifierKeybind2", new KeyboardShortcut((KeyCode)122, Array.Empty<KeyCode>()), text + " Identical to FavoritingModifierKeybind1.", synchronizedSetting: false);
			FavoritedItemTooltip = config(group, "FavoritedItemTooltip", "Item is favorited and won't be stored", string.Empty, synchronizedSetting: false);
			FavoritedSlotTooltip = config(group, "FavoritedSlotTooltip", "Slot is favorited and won't be stored", string.Empty, synchronizedSetting: false);
			ItemOnFavoritedSlotTooltip = config(group, "ItemOnFavoritedSlotTooltip", "Item & Slot are favorited and won't be stored", string.Empty, synchronizedSetting: false);
			if (!File.Exists(yamlPath))
			{
				WriteConfigFileFromResource(yamlPath);
			}
			AzuAutoStoreContainerData.ValueChanged += OnValChangedUpdate;
			AzuAutoStoreContainerData.AssignLocalValue(File.ReadAllText(yamlPath));
			AutoDoc();
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			_harmony.PatchAll(executingAssembly);
			SetupWatcher();
		}

		public void Start()
		{
			BorderRenderer.Border = loadSprite("border.png");
		}

		private void AutoDoc()
		{
		}

		private static void WriteConfigFileFromResource(string configFilePath)
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			string text = "AzuAutoStore.Example.yml";
			using Stream stream = executingAssembly.GetManifestResourceStream(text);
			if (stream == null)
			{
				throw new FileNotFoundException("Resource '" + text + "' not found in the assembly.");
			}
			using StreamReader streamReader = new StreamReader(stream);
			string contents = streamReader.ReadToEnd();
			File.WriteAllText(configFilePath, contents);
		}

		private void Update()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Player.m_localPlayer == (Object)null)
			{
				return;
			}
			KeyboardShortcut value = _storeShortcut.Value;
			if (((KeyboardShortcut)(ref value)).IsDown() && ((Character)Player.m_localPlayer).TakeInput())
			{
				Functions.TryStore();
			}
			value = _pauseShortcut.Value;
			if (!((KeyboardShortcut)(ref value)).IsDown() || !((Character)Player.m_localPlayer).TakeInput())
			{
				return;
			}
			Boxes.StoringPaused = !Boxes.StoringPaused;
			foreach (Container container in Boxes.Containers)
			{
				if (container.m_nview.IsValid())
				{
					container.m_nview.InvokeRPC("RequestPause", new object[1] { Boxes.StoringPaused });
				}
			}
		}

		private void OnDestroy()
		{
			((BaseUnityPlugin)this).Config.Save();
		}

		private void SetupWatcher()
		{
			FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, ConfigFileName);
			fileSystemWatcher.Changed += ReadConfigValues;
			fileSystemWatcher.Created += ReadConfigValues;
			fileSystemWatcher.Renamed += ReadConfigValues;
			fileSystemWatcher.IncludeSubdirectories = true;
			fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
			fileSystemWatcher.EnableRaisingEvents = true;
			FileSystemWatcher fileSystemWatcher2 = new FileSystemWatcher(Paths.ConfigPath, yamlFileName);
			fileSystemWatcher2.Changed += ReadYamlFiles;
			fileSystemWatcher2.Created += ReadYamlFiles;
			fileSystemWatcher2.Renamed += ReadYamlFiles;
			fileSystemWatcher2.IncludeSubdirectories = true;
			fileSystemWatcher2.SynchronizingObject = ThreadingHelper.SynchronizingObject;
			fileSystemWatcher2.EnableRaisingEvents = true;
		}

		private void ReadConfigValues(object sender, FileSystemEventArgs e)
		{
			if (!File.Exists(ConfigFileFullPath))
			{
				return;
			}
			try
			{
				Functions.LogDebug("ReadConfigValues called");
				((BaseUnityPlugin)this).Config.Reload();
			}
			catch
			{
				Functions.LogError("There was an issue loading your " + ConfigFileName);
				Functions.LogError("Please check your config entries for spelling and format!");
			}
		}

		private void ReadYamlFiles(object sender, FileSystemEventArgs e)
		{
			if (!File.Exists(yamlPath))
			{
				return;
			}
			try
			{
				AzuAutoStoreLogger.LogDebug((object)"ReadConfigValues called");
				AzuAutoStoreContainerData.AssignLocalValue(File.ReadAllText(yamlPath));
			}
			catch
			{
				AzuAutoStoreLogger.LogError((object)("There was an issue loading your " + yamlFileName));
				AzuAutoStoreLogger.LogError((object)"Please check your entries for spelling and format!");
			}
		}

		private static void OnValChangedUpdate()
		{
			AzuAutoStoreLogger.LogDebug((object)"OnValChanged called");
			try
			{
				YamlUtils.ReadYaml(AzuAutoStoreContainerData.Value);
				YamlUtils.ParseGroups();
			}
			catch (Exception arg)
			{
				AzuAutoStoreLogger.LogError((object)$"Failed to deserialize {yamlFileName}: {arg}");
			}
		}

		private static byte[] ReadEmbeddedFileBytes(string name)
		{
			using MemoryStream memoryStream = new MemoryStream();
			Assembly.GetExecutingAssembly().GetManifestResourceStream(Assembly.GetExecutingAssembly().GetName().Name + "." + name).CopyTo(memoryStream);
			return memoryStream.ToArray();
		}

		private static Texture2D loadTexture(string name)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//IL_001f: Expected O, but got Unknown
			Texture2D val = new Texture2D(0, 0);
			ImageConversion.LoadImage(val, ReadEmbeddedFileBytes("assets." + name));
			return val;
		}

		internal static Sprite loadSprite(string name)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = loadTexture(name);
			if ((Object)(object)val != (Object)null)
			{
				return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), Vector2.zero);
			}
			return null;
		}

		private ConfigEntry<T> config<[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(2)] T>(string group, string name, T value, ConfigDescription description, bool synchronizedSetting = true)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			ConfigDescription val = new ConfigDescription(description.Description + (synchronizedSetting ? " [Synced with Server]" : " [Not Synced with Server]"), description.AcceptableValues, description.Tags);
			ConfigEntry<T> val2 = ((BaseUnityPlugin)this).Config.Bind<T>(group, name, value, val);
			ConfigSync.AddConfigEntry<T>(val2).SynchronizedConfig = synchronizedSetting;
			return val2;
		}

		private ConfigEntry<T> config<[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(2)] T>(string group, string name, T value, string description, bool synchronizedSetting = true)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			return config(group, name, value, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>()), synchronizedSetting);
		}

		private ConfigEntry<T> TextEntryConfig<[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(2)] T>(string group, string name, T value, ConfigDescription description, bool synchronizedSetting = true)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			ConfigDescription val = new ConfigDescription(description.Description + (synchronizedSetting ? " [Synced with Server]" : " [Not Synced with Server]"), description.AcceptableValues, description.Tags);
			ConfigEntry<T> val2 = ((BaseUnityPlugin)this).Config.Bind<T>(group, name, value, val);
			ConfigSync.AddConfigEntry<T>(val2).SynchronizedConfig = synchronizedSetting;
			return val2;
		}

		private ConfigEntry<T> TextEntryConfig<[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(2)] T>(string group, string name, T value, string desc, bool synchronizedSetting = true)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			ConfigurationManagerAttributes configurationManagerAttributes = new ConfigurationManagerAttributes
			{
				CustomDrawer = Functions.TextAreaDrawer
			};
			return TextEntryConfig(group, name, value, new ConfigDescription(desc, (AcceptableValueBase)null, new object[1] { configurationManagerAttributes }), synchronizedSetting);
		}

		static AzuAutoStorePlugin()
		{
			string configPath = Paths.ConfigPath;
			char directorySeparatorChar = Path.DirectorySeparatorChar;
			ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName;
			ConnectionError = "";
			AzuAutoStoreLogger = Logger.CreateLogSource("AzuAutoStore");
			ConfigSync = new ConfigSync("Azumatt.AzuAutoStore")
			{
				DisplayName = "AzuAutoStore",
				CurrentVersion = "2.1.6",
				MinimumRequiredVersion = "2.1.6"
			};
			yamlFileName = "Azumatt.AzuAutoStore.yml";
			string configPath2 = Paths.ConfigPath;
			directorySeparatorChar = Path.DirectorySeparatorChar;
			yamlPath = configPath2 + directorySeparatorChar + yamlFileName;
			AzuAutoStoreContainerData = new CustomSyncedValue<string>(ConfigSync, "azuautostoreData", "");
			CraftyContainerGroupsData = new CustomSyncedValue<string>(ConfigSync, "azuautostoreGroupsData", "");
			groups = null;
			self = null;
			_serverConfigLocked = null;
			MustHaveExistingItemToPull = null;
			_storeShortcut = null;
			_pauseShortcut = null;
			SecondsToWaitBeforeStoring = null;
			IntervalSeconds = null;
			PlayerRange = null;
			FallbackRange = null;
			PlayerIgnoreHotbar = null;
			PlayerIgnoreQuickSlots = null;
			PingVfxString = null;
			HighlightContainers = null;
			PingContainers = null;
			BorderColorFavoritedItem = null;
			BorderColorFavoritedItemOnFavoritedSlot = null;
			BorderColorFavoritedSlot = null;
			DisplayTooltipHint = null;
			FavoritingModifierKeybind1 = null;
			FavoritingModifierKeybind2 = null;
			SearchModifierKeybind = null;
			FavoritedItemTooltip = null;
			FavoritedSlotTooltip = null;
			ItemOnFavoritedSlotTooltip = null;
		}
	}
	public static class KeyboardExtensions
	{
		public static bool IsKeyDown(this KeyboardShortcut shortcut)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			if ((int)((KeyboardShortcut)(ref shortcut)).MainKey != 0 && Input.GetKeyDown(((KeyboardShortcut)(ref shortcut)).MainKey))
			{
				return ((KeyboardShortcut)(ref shortcut)).Modifiers.All((Func<KeyCode, bool>)Input.GetKey);
			}
			return false;
		}

		public static bool IsKeyHeld(this KeyboardShortcut shortcut)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			if ((int)((KeyboardShortcut)(ref shortcut)).MainKey != 0 && Input.GetKey(((KeyboardShortcut)(ref shortcut)).MainKey))
			{
				return ((KeyboardShortcut)(ref shortcut)).Modifiers.All((Func<KeyCode, bool>)Input.GetKey);
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(ZNet), "OnNewConnection")]
	public static class RegisterAndCheckVersion
	{
		[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(1)]
		private static void Prefix(ZNetPeer peer, ref ZNet __instance)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			AzuAutoStorePlugin.AzuAutoStoreLogger.LogDebug((object)"Registering version RPC handler");
			peer.m_rpc.Register<ZPackage>("AzuAutoStore_VersionCheck", (Action<ZRpc, ZPackage>)RpcHandlers.RPC_AzuAutoStore_Version);
			AzuAutoStorePlugin.AzuAutoStoreLogger.LogInfo((object)"Invoking version check");
			ZPackage val = new ZPackage();
			val.Write("2.1.6");
			peer.m_rpc.Invoke("AzuAutoStore_VersionCheck", new object[1] { val });
		}
	}
	[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(1)]
	[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(0)]
	[HarmonyPatch(typeof(ZNet), "RPC_PeerInfo")]
	public static class VerifyClient
	{
		private static bool Prefix(ZRpc rpc, ZPackage pkg, ref ZNet __instance)
		{
			if (!__instance.IsServer() || RpcHandlers.ValidatedPeers.Contains(rpc))
			{
				return true;
			}
			AzuAutoStorePlugin.AzuAutoStoreLogger.LogWarning((object)("Peer (" + rpc.m_socket.GetHostName() + ") never sent version or couldn't due to previous disconnect, disconnecting"));
			rpc.Invoke("Error", new object[1] { 3 });
			return false;
		}

		private static void Postfix(ZNet __instance)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), "AzuAutoStoreRequestAdminSync", new object[1] { (object)new ZPackage() });
		}
	}
	[HarmonyPatch(typeof(FejdStartup), "ShowConnectError")]
	public class ShowConnectionError
	{
		[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(1)]
		private static void Postfix(FejdStartup __instance)
		{
			if (__instance.m_connectionFailedPanel.activeSelf)
			{
				__instance.m_connectionFailedError.fontSizeMax = 25f;
				__instance.m_connectionFailedError.fontSizeMin = 15f;
				TMP_Text connectionFailedError = __instance.m_connectionFailedError;
				connectionFailedError.text = connectionFailedError.text + "\n" + AzuAutoStorePlugin.ConnectionError;
			}
		}
	}
	[HarmonyPatch(typeof(ZNet), "Disconnect")]
	public static class RemoveDisconnectedPeerFromVerified
	{
		[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(1)]
		private static void Prefix(ZNetPeer peer, ref ZNet __instance)
		{
			if (__instance.IsServer())
			{
				AzuAutoStorePlugin.AzuAutoStoreLogger.LogInfo((object)("Peer (" + peer.m_rpc.m_socket.GetHostName() + ") disconnected, removing from validated list"));
				RpcHandlers.ValidatedPeers.Remove(peer.m_rpc);
			}
		}
	}
	[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(0)]
	[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(1)]
	public static class RpcHandlers
	{
		public static readonly List<ZRpc> ValidatedPeers = new List<ZRpc>();

		public static void RPC_AzuAutoStore_Version(ZRpc rpc, ZPackage pkg)
		{
			string text = pkg.ReadString();
			AzuAutoStorePlugin.AzuAutoStoreLogger.LogInfo((object)("Version check, local: 2.1.6,  remote: " + text));
			if (text != "2.1.6")
			{
				AzuAutoStorePlugin.ConnectionError = "AzuAutoStore Installed: 2.1.6\n Needed: " + text;
				if (ZNet.instance.IsServer())
				{
					AzuAutoStorePlugin.AzuAutoStoreLogger.LogWarning((object)("Peer (" + rpc.m_socket.GetHostName() + ") has incompatible version, disconnecting..."));
					rpc.Invoke("Error", new object[1] { 3 });
				}
			}
			else if (!ZNet.instance.IsServer())
			{
				AzuAutoStorePlugin.AzuAutoStoreLogger.LogInfo((object)"Received same version from server!");
			}
			else
			{
				AzuAutoStorePlugin.AzuAutoStoreLogger.LogInfo((object)("Adding peer (" + rpc.m_socket.GetHostName() + ") to validated list"));
				ValidatedPeers.Add(rpc);
			}
		}
	}
}
namespace AzuAutoStore.Util
{
	[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(1)]
	[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(0)]
	public class Boxes
	{
		internal static readonly List<Container> Containers = new List<Container>();

		private static readonly List<Container> ContainersToAdd = new List<Container>();

		private static readonly List<Container> ContainersToRemove = new List<Container>();

		internal static readonly List<Container> ContainersToPing = new List<Container>();

		internal static bool StoringPaused;

		internal static void AddContainer(Container container)
		{
			if (!Containers.Contains(container))
			{
				ContainersToAdd.Add(container);
				AzuAutoStorePlugin.AzuAutoStoreLogger.LogDebug((object)("Added container " + ((Object)container).name + " to list"));
			}
			UpdateContainers();
		}

		internal static void RemoveContainer(Container container)
		{
			if (Containers.Contains(container))
			{
				ContainersToRemove.Add(container);
				AzuAutoStorePlugin.AzuAutoStoreLogger.LogDebug((object)("Removed container " + ((Object)container).name + " from list"));
			}
			UpdateContainers();
		}

		internal static void UpdateContainers()
		{
			foreach (Container item in ContainersToAdd)
			{
				Containers.Add(item);
			}
			ContainersToAdd.Clear();
			foreach (Container item2 in ContainersToRemove)
			{
				Containers.Remove(item2);
			}
			ContainersToRemove.Clear();
		}

		internal static List<Container> GetNearbyContainers<[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(0)] T>(T gameObject, float rangeToUse) where T : Component
		{
			//IL_0038: 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)
			List<Container> list = new List<Container>();
			foreach (Container container in Containers)
			{
				if (!((Object)(object)gameObject == (Object)null) && !((Object)(object)container == (Object)null))
				{
					float num = Vector3.Distance(((Component)container).transform.position, ((Component)gameObject).transform.position);
					if (num <= rangeToUse)
					{
						AzuAutoStorePlugin.AzuAutoStoreLogger.LogDebug((object)$"Distance to container {((Object)container).name} is {num}m, within the range of {rangeToUse}m set to store items for this chest");
						list.Add(container);
					}
				}
			}
			return list;
		}

		public static void AddContainerIfNotExists(string containerName)
		{
			if (AzuAutoStorePlugin.yamlData != null && !AzuAutoStorePlugin.yamlData.ContainsKey(containerName))
			{
				AzuAutoStorePlugin.yamlData[containerName] = new Dictionary<string, object>
				{
					{
						"exclude",
						new List<string>()
					},
					{
						"includeOverride",
						new List<string>()
					}
				};
				YamlUtils.WriteYaml(AzuAutoStorePlugin.yamlPath);
			}
		}

		[return: <c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(new byte[] { 1, 1, 1, 2 })]
		public static Dictionary<string, List<string>> GetExcludedPrefabsForAllContainers()
		{
			Dictionary<string, List<string>> dictionary = new Dictionary<string, List<string>>();
			foreach (string allContainer in GetAllContainers())
			{
				dictionary[allContainer] = GetExcludedPrefabs(allContainer);
			}
			return dictionary;
		}

		[return: <c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(new byte[] { 2, 1 })]
		public static List<string> GetAllContainers()
		{
			return AzuAutoStorePlugin.yamlData?.Keys.Where([<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(0)] (string key) => key != "groups").ToList();
		}

		public static bool CanItemBeStored(string container, string prefab)
		{
			if (AzuAutoStorePlugin.yamlData == null)
			{
				AzuAutoStorePlugin.AzuAutoStoreLogger.LogError((object)"yamlData is null.");
				return false;
			}
			if (!AzuAutoStorePlugin.yamlData.ContainsKey(container))
			{
				return true;
			}
			if (!(AzuAutoStorePlugin.yamlData[container] is Dictionary<object, object> dictionary))
			{
				AzuAutoStorePlugin.AzuAutoStoreLogger.LogError((object)("Unable to cast containerData for container '" + container + "' to Dictionary<object, object>."));
				return false;
			}
			object value;
			List<object> list = (dictionary.TryGetValue("exclude", out value) ? (value as List<object>) : new List<object>());
			object value2;
			List<object> list2 = (dictionary.TryGetValue("includeOverride", out value2) ? (value2 as List<object>) : new List<object>());
			if (list == null)
			{
				AzuAutoStorePlugin.AzuAutoStoreLogger.LogError((object)("Unable to cast excludeList for container '" + container + "' to List<object>."));
				return false;
			}
			if (list2 == null)
			{
				AzuAutoStorePlugin.AzuAutoStoreLogger.LogError((object)("Unable to cast includeOverrideList for container '" + container + "' to List<object>."));
				return false;
			}
			if (list2.Contains(prefab))
			{
				return true;
			}
			foreach (object item in list)
			{
				if (prefab.Equals(item))
				{
					return false;
				}
				if (GroupUtils.IsGroupDefined((string)item) && GroupUtils.GetItemsInGroup((string)item).Contains(prefab))
				{
					return false;
				}
			}
			return true;
		}

		internal static bool IsPrefabExcluded(string prefab, List<object> exclusionList)
		{
			if (exclusionList != null)
			{
				foreach (object exclusion in exclusionList)
				{
					string text = exclusion.ToString();
					if (AzuAutoStorePlugin.groups.TryGetValue(text, out var value))
					{
						if (value.Contains(prefab))
						{
							return true;
						}
					}
					else if (text == prefab)
					{
						return true;
					}
				}
			}
			return false;
		}

		[return: <c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(new byte[] { 1, 2 })]
		public static List<string> GetExcludedPrefabs(string container)
		{
			if (AzuAutoStorePlugin.yamlData != null && AzuAutoStorePlugin.yamlData.TryGetValue(container, out var value) && value is Dictionary<object, object> dictionary && dictionary.TryGetValue("exclude", out var value2) && value2 is List<object> list)
			{
				List<string> list2 = new List<string>();
				{
					foreach (object item in list)
					{
						string text = item.ToString();
						if (AzuAutoStorePlugin.groups.TryGetValue(text, out var value3))
						{
							list2.AddRange(value3);
						}
						else
						{
							list2.Add(text);
						}
					}
					return list2;
				}
			}
			return new List<string>();
		}

		public static void RPC_Ownership(Container container, long uid)
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			if ((container.IsInUse() || (Object.op_Implicit((Object)(object)container.m_wagon) && container.m_wagon.InUse())) && uid != ZNet.GetUID())
			{
				container.m_nview.InvokeRPC(uid, "Autostore OpenResponse", new object[1] { false });
				return;
			}
			ZDOMan.instance.ForceSendZDO(uid, container.m_nview.GetZDO().m_uid);
			container.m_nview.GetZDO().SetOwner(uid);
			container.m_nview.InvokeRPC(uid, "Autostore OpenResponse", new object[1] { true });
		}

		public static void RPC_OpenResponse(Container container, bool response)
		{
			if (response)
			{
				Functions.InProgressTotal += Functions.TryStoreInContainer(container);
			}
			if (--Functions.InProgressStores == 0)
			{
				Functions.StoreSuccess(Functions.InProgressTotal);
			}
		}

		internal static void RPC_RequestPause(long sender, bool pause, Container container)
		{
			if (container.m_nview.IsValid() && container.m_nview.IsOwner())
			{
				container.m_nview.GetZDO().Set(StringExtensionMethods.GetStableHashCode("storingPaused"), pause);
			}
		}
	}
	public class ChestPingEffect : MonoBehaviour
	{
		private void Awake()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			if (!string.IsNullOrWhiteSpace(AzuAutoStorePlugin.PingVfxString.Value))
			{
				Object.Instantiate<GameObject>(ZNetScene.instance.GetPrefab(AzuAutoStorePlugin.PingVfxString.Value), ((Component)this).transform.position, Quaternion.identity);
				Trigger();
			}
		}

		public void Trigger()
		{
			((MonoBehaviour)this).InvokeRepeating("DestroyNow", 10f, 1f);
		}

		public void DestroyNow()
		{
			Object.DestroyImmediate((Object)(object)this);
		}
	}
	[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(0)]
	[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(1)]
	public static class YamlUtils
	{
		internal static void ReadYaml(string yamlInput)
		{
			AzuAutoStorePlugin.yamlData = new DeserializerBuilder().Build().Deserialize<Dictionary<string, object>>(yamlInput);
			AzuAutoStorePlugin.AzuAutoStoreLogger.LogDebug((object)("yamlData:\n" + yamlInput));
		}

		internal static void ParseGroups()
		{
			if (AzuAutoStorePlugin.groups == null)
			{
				AzuAutoStorePlugin.groups = new Dictionary<string, HashSet<string>>();
			}
			object value;
			if (AzuAutoStorePlugin.yamlData == null)
			{
				AzuAutoStorePlugin.AzuAutoStoreLogger.LogError((object)"yamlData is null.");
			}
			else if (AzuAutoStorePlugin.yamlData.TryGetValue("groups", out value))
			{
				if (value is Dictionary<object, object> dictionary)
				{
					{
						foreach (KeyValuePair<object, object> item in dictionary)
						{
							string text = item.Key?.ToString();
							if (text == null || !(item.Value is List<object> list))
							{
								continue;
							}
							HashSet<string> hashSet = new HashSet<string>();
							foreach (object item2 in list)
							{
								string text2 = item2?.ToString();
								if (text2 != null)
								{
									hashSet.Add(text2);
								}
							}
							AzuAutoStorePlugin.groups[text] = hashSet;
						}
						return;
					}
				}
				AzuAutoStorePlugin.AzuAutoStoreLogger.LogError((object)"groupData is not of type Dictionary<object, object>.");
			}
			else
			{
				AzuAutoStorePlugin.AzuAutoStoreLogger.LogError((object)"No 'groups' key found in yamlData.");
			}
		}

		public static void WriteYaml(string filePath)
		{
			ISerializer serializer = new SerializerBuilder().Build();
			using StreamWriter writer = new StreamWriter(filePath);
			serializer.Serialize(writer, AzuAutoStorePlugin.yamlData);
			string contents = serializer.Serialize(AzuAutoStorePlugin.yamlData);
			File.AppendAllText(filePath, contents);
		}
	}
	[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(1)]
	[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(0)]
	public class Functions
	{
		internal static int InProgressStores;

		internal static int InProgressTotal;

		internal static void TextAreaDrawer(ConfigEntryBase entry)
		{
			GUILayout.ExpandHeight(true);
			GUILayout.ExpandWidth(true);
			entry.BoxedValue = GUILayout.TextArea((string)entry.BoxedValue, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.ExpandWidth(true),
				GUILayout.ExpandHeight(true)
			});
		}

		internal static float GetContainerRange(Container container)
		{
			if (AzuAutoStorePlugin.yamlData == null)
			{
				AzuAutoStorePlugin.AzuAutoStoreLogger.LogError((object)"yamlData is null when trying to get the container range for a container. Make sure that your YAML file is not empty or to call DeserializeYamlFile() before using GetContainerRange.");
				return -1f;
			}
			if (container.GetInventory() == null)
			{
				return -1f;
			}
			string prefabName = MiscFunctions.GetPrefabName(((Object)((Component)container).transform.root).name);
			if (AzuAutoStorePlugin.yamlData.TryGetValue(prefabName, out var value))
			{
				if (!(value is Dictionary<object, object> dictionary))
				{
					AzuAutoStorePlugin.AzuAutoStoreLogger.LogError((object)("Unable to cast containerData for container '" + prefabName + "' to Dictionary<object, object>."));
					return -1f;
				}
				if (dictionary.TryGetValue("range", out var value2) && float.TryParse(value2.ToString(), out var result))
				{
					return result;
				}
			}
			return AzuAutoStorePlugin.FallbackRange.Value;
		}

		private static bool CantStoreFavorite(ItemData item, UserConfig playerConfig)
		{
			return playerConfig.IsItemNameOrSlotFavorited(item);
		}

		internal static bool TryStore(Container nearbyContainer, ref ItemData item, bool fromPlayer = false)
		{
			bool flag = false;
			LogDebug("Checking container " + ((Object)nearbyContainer).name);
			if (!MiscFunctions.CheckItemSharedIntegrity(item))
			{
				return flag;
			}
			if (AzuAutoStorePlugin.MustHaveExistingItemToPull.Value == AzuAutoStorePlugin.Toggle.On && !nearbyContainer.GetInventory().HaveItem(item.m_shared.m_name, true))
			{
				return false;
			}
			if (!Boxes.CanItemBeStored(MiscFunctions.GetPrefabName(((Object)((Component)nearbyContainer).transform.root).name), ((Object)item.m_dropPrefab).name))
			{
				return false;
			}
			LogDebug("Auto storing " + ((Object)item.m_dropPrefab).name + " in " + ((Object)nearbyContainer).name);
			while (item.m_stack > 1 && nearbyContainer.GetInventory().CanAddItem(item, 1))
			{
				flag = true;
				ItemData obj = item;
				obj.m_stack--;
				ItemData val = item.Clone();
				val.m_stack = 1;
				nearbyContainer.GetInventory().AddItem(val);
			}
			if (item.m_stack == 1 && nearbyContainer.GetInventory().CanAddItem(item, 1))
			{
				ItemData val2 = item.Clone();
				item.m_stack = 0;
				nearbyContainer.GetInventory().AddItem(val2);
				flag = true;
			}
			if (!flag)
			{
				return flag;
			}
			if (!fromPlayer)
			{
				PingContainer((Component)(object)nearbyContainer);
			}
			nearbyContainer.Save();
			return flag;
		}

		internal static int TryStoreInContainer(Container nearbyContainer)
		{
			if ((Object)(object)Player.m_localPlayer == (Object)null)
			{
				return 0;
			}
			int num = 0;
			List<ItemData> allItems = ((Humanoid)Player.m_localPlayer).GetInventory().GetAllItems();
			for (int num2 = allItems.Count - 1; num2 >= 0; num2--)
			{
				ItemData item = allItems[num2];
				if (item.m_equipped)
				{
					LogDebug("Skipping equipped item " + ((Object)item.m_dropPrefab).name);
				}
				else
				{
					int x = item.m_gridPos.x;
					if (x >= 0 && x <= 8 && item.m_gridPos.y == 0 && AzuAutoStorePlugin.PlayerIgnoreHotbar.Value == AzuAutoStorePlugin.Toggle.On)
					{
						LogDebug("Skipping item " + ((Object)item.m_dropPrefab).name + " because it is in the hotbar");
					}
					else if (API.IsLoaded() && API.GetQuickSlotsItems().Any([<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(0)] (ItemData quickSlotItem) => quickSlotItem.m_gridPos == item.m_gridPos))
					{
						LogDebug("Skipping item " + ((Object)item.m_dropPrefab).name + " because it is in your quick slots");
					}
					else if (CantStoreFavorite(item, UserConfig.GetPlayerConfig(Player.m_localPlayer.GetPlayerID())))
					{
						LogDebug("Skipping favorited item/slot " + ((Object)item.m_dropPrefab).name);
					}
					else
					{
						LogDebug("Checking item " + ((Object)item.m_dropPrefab).name);
						int stack = item.m_stack;
						if (TryStore(nearbyContainer, ref item, fromPlayer: true) && item.m_stack < stack)
						{
							num += stack - item.m_stack;
							((Humanoid)Player.m_localPlayer).GetInventory().RemoveItem(item, stack - item.m_stack);
							LogDebug($"Stored {stack - item.m_stack} {((Object)item.m_dropPrefab).name} into {((Object)nearbyContainer).name}");
							if (!Boxes.ContainersToPing.Contains(nearbyContainer))
							{
								Boxes.ContainersToPing.Add(nearbyContainer);
							}
						}
					}
				}
			}
			return num;
		}

		internal static void TryStore()
		{
			if ((Object)(object)Player.m_localPlayer == (Object)null)
			{
				return;
			}
			LogDebug("Trying to store items from player inventory");
			Container[] array = Boxes.GetNearbyContainers<Player>(Player.m_localPlayer, AzuAutoStorePlugin.PlayerRange.Value).ToArray();
			int num = 0;
			for (int i = 0; i < array.Length; i++)
			{
				Container val = array[i];
				if (val != null && val.m_nview.IsOwner())
				{
					array[i] = null;
					num += TryStoreInContainer(val);
				}
			}
			if (InProgressStores > 0)
			{
				LogDebug($"Found {InProgressStores} requests for container ownership still pending...");
				InProgressTotal += num;
				return;
			}
			InProgressStores = array.Count([<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(0)] (Container c) => c != null);
			if (InProgressStores > 0)
			{
				InProgressTotal = num;
				((MonoBehaviour)AzuAutoStorePlugin.self).StartCoroutine(End());
				Container[] array2 = array;
				foreach (Container val2 in array2)
				{
					Player val3 = ((val2 != null) ? ((Component)val2.m_nview).GetComponent<Player>() : null);
					if ((!Object.op_Implicit((Object)(object)val3) || (Object)(object)val3 == (Object)(object)Player.m_localPlayer) && val2 != null)
					{
						val2.m_nview.InvokeRPC("Autostore Ownership", Array.Empty<object>());
					}
				}
			}
			else
			{
				StoreSuccess(num);
			}
			static IEnumerator End()
			{
				yield return (object)new WaitForSeconds(1f);
				StoreSuccess(InProgressTotal);
				InProgressStores = 0;
			}
		}

		internal static void StoreSuccess(int total)
		{
			if (total <= 0)
			{
				return;
			}
			InProgressTotal = 0;
			((Character)Player.m_localPlayer).Message((MessageType)2, $"Stored {total} items from your inventory into nearby containers", 0, (Sprite)null);
			foreach (Container item in Boxes.ContainersToPing)
			{
				PingContainer((Component)(object)item);
			}
			Boxes.ContainersToPing.Clear();
		}

		internal static void PingContainer(Component container)
		{
			if (AzuAutoStorePlugin.PingContainers.Value == AzuAutoStorePlugin.Toggle.On && (Object)(object)container.gameObject.GetComponent<ChestPingEffect>() == (Object)null)
			{
				container.gameObject.AddComponent<ChestPingEffect>();
			}
			if (AzuAutoStorePlugin.HighlightContainers.Value == AzuAutoStorePlugin.Toggle.On && (Object)(object)container.gameObject.GetComponent<HighLightChest>() == (Object)null)
			{
				container.gameObject.AddComponent<HighLightChest>();
			}
		}

		internal static void LogDebug(string data)
		{
			AzuAutoStorePlugin.AzuAutoStoreLogger.LogDebug((object)data);
		}

		internal static void LogError(string data)
		{
			AzuAutoStorePlugin.AzuAutoStoreLogger.LogError((object)data);
		}

		internal static void LogInfo(string data)
		{
			AzuAutoStorePlugin.AzuAutoStoreLogger.LogInfo((object)data);
		}

		internal static void LogWarning(string data)
		{
			AzuAutoStorePlugin.AzuAutoStoreLogger.LogWarning((object)data);
		}
	}
	[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(2)]
	[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(0)]
	public class GroupUtils
	{
		[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(1)]
		public static List<string> GetExcludedGroups(string container)
		{
			if (AzuAutoStorePlugin.yamlData != null && AzuAutoStorePlugin.yamlData.TryGetValue(container, out var value) && value is Dictionary<object, object> dictionary && dictionary.TryGetValue("exclude", out var value2) && value2 is List<object> source)
			{
				return (from excludeItem in source
					where AzuAutoStorePlugin.groups.ContainsKey(excludeItem.ToString())
					select excludeItem.ToString()).ToList();
			}
			return new List<string>();
		}

		public static bool IsGroupDefined(string groupName)
		{
			if (AzuAutoStorePlugin.yamlData == null)
			{
				AzuAutoStorePlugin.AzuAutoStoreLogger.LogError((object)"yamlData is null. Make sure that your YAML file is not empty or to call DeserializeYamlFile() before using IsGroupDefined.");
				return false;
			}
			bool flag = false;
			if (AzuAutoStorePlugin.yamlData.ContainsKey("groups"))
			{
				if (AzuAutoStorePlugin.yamlData["groups"] is Dictionary<object, object> dictionary)
				{
					if (groupName != null)
					{
						flag = dictionary.ContainsKey(groupName);
					}
				}
				else
				{
					AzuAutoStorePlugin.AzuAutoStoreLogger.LogError((object)"Unable to cast groupsData to Dictionary<object, object>.");
				}
			}
			if (!flag)
			{
				return AzuAutoStorePlugin.groups.ContainsKey(groupName);
			}
			return true;
		}

		public static bool GroupExists(string groupName)
		{
			return AzuAutoStorePlugin.groups.ContainsKey(groupName);
		}

		[return: <c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(new byte[] { 1, 2 })]
		public static List<string> GetAllGroups()
		{
			return AzuAutoStorePlugin.groups.Keys.ToList();
		}

		[return: <c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(new byte[] { 1, 2 })]
		public static List<string> GetItemsInGroup(string groupName)
		{
			if (AzuAutoStorePlugin.groups.TryGetValue(groupName, out var value))
			{
				return value.ToList();
			}
			return new List<string>();
		}
	}
	public class HighLightChest : MonoBehaviour
	{
		[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(2)]
		private WearNTear wnt;

		private void Awake()
		{
			WearNTear val = default(WearNTear);
			wnt = (((Component)this).TryGetComponent<WearNTear>(ref val) ? val : null);
			if ((Object)(object)wnt == (Object)null)
			{
				DestroyNow();
			}
			else
			{
				Trigger();
			}
		}

		public void Trigger()
		{
			((MonoBehaviour)this).InvokeRepeating("DestroyNow", 10f, 1f);
		}

		public void DestroyNow()
		{
			Object.DestroyImmediate((Object)(object)this);
		}

		private void Update()
		{
			WearNTear obj = wnt;
			if (obj != null)
			{
				obj.Highlight();
			}
		}
	}
	[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(1)]
	[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(0)]
	public class MiscFunctions
	{
		private static bool dataChanged;

		private static void LogResourceInfo(int totalAmount, int totalRequirement, string reqName)
		{
			AzuAutoStorePlugin.AzuAutoStoreLogger.LogDebug((object)$"(ConsumeResourcesPatch) Have {totalAmount}/{totalRequirement} {reqName} in player inventory");
		}

		public static string GetPrefabName(string name)
		{
			char[] anyOf = new char[2] { '(', ' ' };
			int num = name.IndexOfAny(anyOf);
			if (num >= 0)
			{
				return name.Substring(0, num);
			}
			return name;
		}

		[return: <c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(2)]
		internal static GameObject GetItemPrefabFromGameObject(ItemDrop itemDropComponent, GameObject inputGameObject)
		{
			GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(GetPrefabName(((Object)inputGameObject).name));
			itemDropComponent.m_itemData.m_dropPrefab = itemPrefab;
			if (!((Object)(object)itemPrefab != (Object)null))
			{
				return null;
			}
			return itemPrefab;
		}

		internal static bool CheckItemDropIntegrity(ItemDrop itemDropComp)
		{
			if (itemDropComp.m_itemData == null)
			{
				return false;
			}
			return itemDropComp.m_itemData.m_shared != null;
		}

		internal static bool CheckItemSharedIntegrity(ItemData itemData)
		{
			return itemData.m_shared != null;
		}

		internal static void CreatePredefinedGroups(ObjectDB __instance)
		{
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: 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_0223: Expected I4, but got Unknown
			//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)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Expected I4, but got Unknown
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Invalid comparison between Unknown and I4
			foreach (GameObject item in __instance.m_items.Where([<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(0)] (GameObject x) => (Object)(object)x.GetComponentInChildren<ItemDrop>() != (Object)null))
			{
				ItemDrop componentInChildren = item.GetComponentInChildren<ItemDrop>();
				if (!CheckItemDropIntegrity(componentInChildren))
				{
					continue;
				}
				GameObject itemPrefabFromGameObject = GetItemPrefabFromGameObject(componentInChildren, item);
				componentInChildren.m_itemData.m_dropPrefab = ((Component)componentInChildren).gameObject;
				if (!((Object)(object)itemPrefabFromGameObject != (Object)null))
				{
					continue;
				}
				SharedData sharedData = componentInChildren.m_itemData.m_shared;
				List<string> list = new List<string>();
				if ((double)sharedData.m_food > 0.0 && (double)sharedData.m_foodStamina > 0.0)
				{
					list.Add("Food");
				}
				if ((Object)(object)sharedData.m_consumeStatusEffect != (Object)null)
				{
					if (((double)sharedData.m_food > 0.0 && (double)sharedData.m_foodStamina == 0.0) || ((Object)sharedData.m_consumeStatusEffect).name.ToLower().Contains("potion") || sharedData.m_consumeStatusEffect.m_name.ToLower().Contains("potion") || sharedData.m_consumeStatusEffect.m_category.ToLower().Contains("potion") || sharedData.m_ammoType.ToLower().Contains("mead"))
					{
						list.Add("Potion");
					}
					else if ((int)sharedData.m_itemType == 21)
					{
						list.Add("Fish");
					}
				}
				ItemType itemType = sharedData.m_itemType;
				switch (itemType - 1)
				{
				case 2:
				case 3:
				case 13:
				case 21:
				{
					bool flag = true;
					SkillType skillType = sharedData.m_skillType;
					switch (skillType - 1)
					{
					case 0:
						list.Add("Swords");
						break;
					case 7:
						list.Add("Bows");
						break;
					case 13:
						list.Add("Crossbows");
						break;
					case 6:
						list.Add("Axes");
						break;
					case 2:
						list.Add("Clubs");
						break;
					case 1:
						list.Add("Knives");
						break;
					case 11:
						list.Add("Pickaxes");
						break;
					case 3:
						list.Add("Polearms");
						break;
					case 4:
						list.Add("Spears");
						break;
					case 8:
						list.Add("ElementalMagic");
						break;
					case 9:
						list.Add("BloodMagic");
						break;
					default:
						flag = false;
						break;
					}
					if (flag)
					{
						list.Add("Weapons");
					}
					break;
				}
				case 4:
					list.Add("Shield");
					list.Add(((double)sharedData.m_timedBlockBonus > 0.0) ? "Round Shield" : "Tower Shield");
					break;
				case 5:
					list.AddRange(new string[2] { "Armor", "Helmet" });
					break;
				case 6:
					list.AddRange(new string[2] { "Armor", "Chest" });
					break;
				case 10:
					list.AddRange(new string[2] { "Armor", "Legs" });
					break;
				case 16:
					list.AddRange(new string[2] { "Armor", "Shoulder" });
					break;
				case 17:
					list.AddRange(new string[1] { "Utility" });
					break;
				case 8:
				{
					string ammoType = sharedData.m_ammoType;
					if (ammoType != "$ammo_bolts")
					{
						if (ammoType == "$ammo_arrows")
						{
							list.Add("Arrows");
						}
					}
					else
					{
						list.Add("Bolts");
					}
					list.Add("Ammo");
					break;
				}
				case 14:
				case 18:
					list.Add("Equipment");
					break;
				case 12:
				{
					string[] source = new string[6] { "eikthyr", "elder", "bonemass", "dragonqueen", "goblinking", "SeekerQueen" };
					list.Add(source.Any(sharedData.m_name.EndsWith) ? "Boss Trophy" : "Trophy");
					break;
				}
				case 0:
				{
					GameObject val = ((IEnumerable<GameObject>)ObjectDB.instance.GetItemPrefab("Cultivator").GetComponent<ItemDrop>().m_itemData.m_shared.m_buildPieces.m_pieces).FirstOrDefault((Func<GameObject, bool>)([<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(0)] (GameObject p) =>
					{
						Requirement[] resources = p.GetComponent<Piece>().m_resources;
						return resources.Length == 1 && resources[0].m_resItem.m_itemData.m_shared.m_name == sharedData.m_name;
					}));
					if (val != null)
					{
						Plant component = val.GetComponent<Plant>();
						list.Add((component != null && component.m_grownPrefabs[0].GetComponent<Pickable>()?.m_amount > 1) ? "Crops" : "Seeds");
					}
					if (ZNetScene.instance.GetPrefab("smelter").GetComponent<Smelter>().m_conversion.Any([<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(0)] (ItemConversion c) => c.m_from.m_itemData.m_shared.m_name == sharedData.m_name))
					{
						list.Add("Ores");
					}
					if (ZNetScene.instance.GetPrefab("smelter").GetComponent<Smelter>().m_conversion.Any([<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(0)] (ItemConversion c) => c.m_to.m_itemData.m_shared.m_name == sharedData.m_name))
					{
						list.Add("Metals");
					}
					if (ZNetScene.instance.GetPrefab("blastfurnace").GetComponent<Smelter>().m_conversion.Any([<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(0)] (ItemConversion c) => c.m_from.m_itemData.m_shared.m_name == sharedData.m_name))
					{
						list.Add("Ores");
					}
					if (ZNetScene.instance.GetPrefab("blastfurnace").GetComponent<Smelter>().m_conversion.Any([<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(0)] (ItemConversion c) => c.m_to.m_itemData.m_shared.m_name == sharedData.m_name))
					{
						list.Add("Metals");
					}
					if (ZNetScene.instance.GetPrefab("charcoal_kiln").GetComponent<Smelter>().m_conversion.Any([<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(0)] (ItemConversion c) => c.m_from.m_itemData.m_shared.m_name == sharedData.m_name))
					{
						list.Add("Woods");
					}
					if (sharedData.m_name == "$item_elderbark")
					{
						list.Add("Woods");
					}
					break;
				}
				}
				foreach (string item2 in list)
				{
					if (!string.IsNullOrEmpty(item2))
					{
						AzuAutoStorePlugin.AzuAutoStoreLogger.LogDebug((object)("(CreatePredefinedGroups) Adding " + ((Object)componentInChildren.m_itemData.m_dropPrefab).name + " to " + item2));
						AddItemToGroup(item2, componentInChildren);
					}
				}
				if (sharedData != null)
				{
					AddItemToGroup("All", componentInChildren);
				}
			}
			SaveGroupsToFile();
		}

		private static void AddItemToGroup([<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(2)] string groupName, ItemDrop itemDrop)
		{
			if (!GroupUtils.GroupExists(groupName))
			{
				AzuAutoStorePlugin.groups[groupName] = new HashSet<string>();
			}
			string prefabName = Utils.GetPrefabName(itemDrop.m_itemData.m_dropPrefab);
			if (!AzuAutoStorePlugin.groups[groupName].Contains(prefabName))
			{
				AzuAutoStorePlugin.groups[groupName].Add(prefabName);
				AzuAutoStorePlugin.AzuAutoStoreLogger.LogDebug((object)("(CreatePredefinedGroups) Added " + prefabName + " to " + groupName));
			}
		}

		private static void SaveGroupsToFile()
		{
			if (!dataChanged)
			{
				return;
			}
			using StreamWriter streamWriter = new StreamWriter(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty, "AzuAutoStore_PredefinedGroups.txt"), append: false);
			foreach (string item in AzuAutoStorePlugin.groups.Keys.OrderBy([<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(0)] (string x) => x))
			{
				streamWriter.WriteLine(item);
				if (item == null)
				{
					continue;
				}
				foreach (string item2 in AzuAutoStorePlugin.groups[item].OrderBy([<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(0)] (string x) => x))
				{
					streamWriter.WriteLine("\t" + item2);
				}
			}
			dataChanged = false;
		}
	}
}
namespace AzuAutoStore.Util.Compatibility
{
	[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(0)]
	[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(1)]
	public class WILCompat
	{
		protected static T InvokeMethod<[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(2)] T>(Type type, object instance, string methodName, object[] parameter)
		{
			return (T)(type.GetMethod(methodName)?.Invoke(instance, parameter));
		}

		[return: <c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(2)]
		protected static T GetField<[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(2)] T>(Type type, object instance, string fieldName)
		{
			return (T)(type.GetField(fieldName)?.GetValue(instance));
		}
	}
}
namespace AzuAutoStore.Util.Compatibility.WardIsLove
{
	[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(0)]
	[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(1)]
	public class WardIsLovePlugin : WILCompat
	{
		private const string GUID = "Azumatt.WardIsLove";

		private static readonly System.Version MinVersion = new System.Version(2, 3, 3);

		private static Type ClassType()
		{
			return Type.GetType("WardIsLove.WardIsLovePlugin, WardIsLove");
		}

		public static bool IsLoaded()
		{
			if (Chainloader.PluginInfos.ContainsKey("Azumatt.WardIsLove"))
			{
				return Chainloader.PluginInfos["Azumatt.WardIsLove"].Metadata.Version >= MinVersion;
			}
			return false;
		}

		[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(2)]
		public static ConfigEntry<bool> WardEnabled()
		{
			return WILCompat.GetField<ConfigEntry<bool>>(ClassType(), null, "WardEnabled");
		}
	}
	public class WardMonoscript : WILCompat
	{
		[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(1)]
		public static Type ClassType()
		{
			return Type.GetType("WardIsLove.Util.WardMonoscript, WardIsLove");
		}

		public static bool CheckInWardMonoscript(Vector3 point, bool flash = false)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			return WILCompat.InvokeMethod<bool>(ClassType(), null, "CheckInWardMonoscript", new object[2] { point, flash });
		}

		public static bool CheckAccess(Vector3 point, float radius = 0f, bool flash = true, bool wardCheck = false)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			return WILCompat.InvokeMethod<bool>(ClassType(), null, "CheckAccess", new object[4] { point, radius, flash, wardCheck });
		}

		public static bool InsideWard(Vector3 pos)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			if (WardIsLovePlugin.WardEnabled().Value)
			{
				return CheckInWardMonoscript(pos);
			}
			return false;
		}
	}
}
namespace AzuAutoStore.Patches
{
	[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(0)]
	[HarmonyPatch(typeof(Container), "Awake")]
	[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(1)]
	internal static class ContainerAwakePatch
	{
		internal static Dictionary<Container, Coroutine> containerCoroutines = new Dictionary<Container, Coroutine>();

		internal static int pausedSeconds = 0;

		internal static int lastCount = 0;

		internal static readonly int storingPausedHash = StringExtensionMethods.GetStableHashCode("storingPaused");

		private static void Postfix(Container __instance)
		{
			//IL_0116: 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)
			if (__instance.m_nview.GetZDO() == null)
			{
				return;
			}
			if (Object.op_Implicit((Object)(object)__instance.m_nview))
			{
				__instance.m_nview.Register<bool>("RequestPause", (Action<long, bool>)delegate(long sender, bool pause)
				{
					Boxes.RPC_RequestPause(sender, pause, __instance);
				});
				__instance.m_nview.Register("Autostore Ownership", (Action<long>)delegate(long uid)
				{
					Boxes.RPC_Ownership(__instance, uid);
				});
				__instance.m_nview.Register<bool>("Autostore OpenResponse", (Action<long, bool>)delegate(long _, bool response)
				{
					Boxes.RPC_OpenResponse(__instance, response);
				});
			}
			if (((Object)__instance).name.StartsWith("Treasure") || __instance.GetInventory() == null || !__instance.m_nview.IsValid())
			{
				return;
			}
			try
			{
				if (WardIsLovePlugin.IsLoaded() && WardIsLovePlugin.WardEnabled().Value && WardMonoscript.CheckAccess(((Component)__instance).transform.position, 0f, flash: false, wardCheck: true))
				{
					Boxes.AddContainer(__instance);
				}
				else if (PrivateArea.CheckAccess(((Component)__instance).transform.position, 0f, false, true))
				{
					Boxes.AddContainer(__instance);
				}
			}
			catch
			{
			}
			Coroutine value = ((MonoBehaviour)__instance).StartCoroutine(PeriodicCheck(__instance));
			containerCoroutines[__instance] = value;
		}

		private static IEnumerator PeriodicCheck(Container containerInstance, bool execNext = false)
		{
			float regularSearchInterval = AzuAutoStorePlugin.IntervalSeconds.Value;
			float quickSearchInterval = 0f;
			float currentInterval = regularSearchInterval;
			while (true)
			{
				if (containerInstance.m_nview.GetZDO().GetBool(storingPausedHash, false))
				{
					pausedSeconds++;
					AzuAutoStorePlugin.AzuAutoStoreLogger.LogDebug((object)$"Paused for {pausedSeconds} seconds");
					if (pausedSeconds >= AzuAutoStorePlugin.SecondsToWaitBeforeStoring.Value)
					{
						containerInstance.m_nview.GetZDO().Set(storingPausedHash, false);
						AzuAutoStorePlugin.AzuAutoStoreLogger.LogDebug((object)$"Paused for {pausedSeconds} seconds, resuming");
						pausedSeconds = 0;
					}
					yield return (object)new WaitForSeconds(1f);
					continue;
				}
				if (execNext)
				{
					execNext = false;
					currentInterval = quickSearchInterval;
				}
				yield return (object)new WaitForSeconds(currentInterval);
				Collider[] array = Physics.OverlapSphere(((Component)containerInstance).transform.position, Functions.GetContainerRange(containerInstance), LayerMask.GetMask(new string[1] { "item" }));
				foreach (Collider val in array)
				{
					if (!Object.op_Implicit((Object)(object)((val != null) ? val.attachedRigidbody : null)) || (Object)(object)val == (Object)null)
					{
						continue;
					}
					ItemDrop component = ((Component)val.attachedRigidbody).GetComponent<ItemDrop>();
					if (!Object.op_Implicit((Object)(object)component))
					{
						continue;
					}
					Functions.LogDebug("Nearby item name: " + ((Object)component.m_itemData.m_dropPrefab).name);
					int num;
					if (component == null)
					{
						num = 1;
					}
					else
					{
						ZNetView component2 = ((Component)component).GetComponent<ZNetView>();
						num = ((((component2 != null) ? new bool?(component2.IsValid()) : null) != true) ? 1 : 0);
					}
					if (num != 0 || !((Component)component).GetComponent<ZNetView>().IsOwner() || !Functions.TryStore(containerInstance, ref component.m_itemData))
					{
						continue;
					}
					component.Save();
					if (component.m_itemData.m_stack <= 0)
					{
						if ((Object)(object)((Component)component).GetComponent<ZNetView>() == (Object)null)
						{
							Object.DestroyImmediate((Object)(object)((Component)component).gameObject);
						}
						else
						{
							ZNetScene.instance.Destroy(((Component)component).gameObject);
						}
					}
				}
				currentInterval = regularSearchInterval;
			}
		}

		public static void ItemDroppedNearby(Container containerInstance)
		{
			if (containerCoroutines != null && Object.op_Implicit((Object)(object)containerInstance) && containerCoroutines.TryGetValue(containerInstance, out var value) && value != null)
			{
				((MonoBehaviour)containerInstance).StopCoroutine(value);
				Coroutine val = ((MonoBehaviour)containerInstance).StartCoroutine(PeriodicCheck(containerInstance, execNext: true));
				if (val != null)
				{
					containerCoroutines[containerInstance] = val;
				}
			}
		}
	}
	[HarmonyPatch(typeof(Container), "OnDestroyed")]
	internal static class ContainerOnDestroyedPatch
	{
		[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(1)]
		private static void Postfix(Container __instance)
		{
			if (((Object)__instance).name.StartsWith("Treasure") || __instance.GetInventory() == null || !__instance.m_nview.IsValid())
			{
				return;
			}
			Boxes.RemoveContainer(__instance);
			try
			{
				if (Object.op_Implicit((Object)(object)__instance) && ContainerAwakePatch.containerCoroutines.ContainsKey(__instance))
				{
					((MonoBehaviour)__instance).StopCoroutine(ContainerAwakePatch.containerCoroutines[__instance]);
					ContainerAwakePatch.containerCoroutines.Remove(__instance);
				}
			}
			catch (Exception arg)
			{
				Functions.LogError($"Error in ContainerOnDestroyedPatch Couldn't remove container coroutine: {arg}");
			}
		}
	}
	[HarmonyPatch(typeof(Container), "Interact")]
	internal static class ContainerInteractPatch
	{
		[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(1)]
		private static void Postfix(Container __instance, Humanoid character, bool hold, bool alt)
		{
			//IL_001e: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			long playerID = Game.instance.GetPlayerProfile().GetPlayerID();
			if ((!__instance.m_checkGuardStone || PrivateArea.CheckAccess(((Component)__instance).transform.position, 0f, true, false)) && __instance.CheckAccess(playerID))
			{
				if (WardIsLovePlugin.IsLoaded() && WardIsLovePlugin.WardEnabled().Value && WardMonoscript.CheckAccess(((Component)__instance).transform.position, 0f, flash: false, wardCheck: true))
				{
					Boxes.AddContainer(__instance);
				}
				else if (PrivateArea.CheckAccess(((Component)__instance).transform.position, 0f, false, true))
				{
					Boxes.AddContainer(__instance);
				}
			}
		}
	}
	[HarmonyPatch(typeof(ZNetScene), "Awake")]
	internal static class ZNetSceneAwakePatch
	{
		[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(1)]
		private static void Postfix(ZNetScene __instance)
		{
			Container[] array = Resources.FindObjectsOfTypeAll<Container>();
			foreach (Container val in array)
			{
				Functions.LogDebug("Found container by the name of " + ((Object)val).name + " in your game.");
			}
		}
	}
	[HarmonyPatch(typeof(Player), "UpdateTeleport")]
	public static class PlayerUpdateTeleportPatchCleanupContainers
	{
		public static void Prefix(float dt)
		{
			if (!((Object)(object)Player.m_localPlayer != (Object)null) || !Player.m_localPlayer.m_teleporting)
			{
				return;
			}
			foreach (Container item in from container in Boxes.Containers.ToList()
				where !((Object)(object)container != (Object)null) || !((Object)(object)((Component)container).transform != (Object)null) || container.GetInventory() == null
				where (Object)(object)container != (Object)null
				select container)
			{
				Boxes.RemoveContainer(item);
			}
		}
	}
	[HarmonyPatch(typeof(ItemDrop), "Start")]
	internal static class ItemDropStartPatch
	{
		[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(1)]
		private static void Postfix(ItemDrop __instance)
		{
			//IL_005d: 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)
			if (Boxes.Containers == null || (Object)(object)__instance == (Object)null || (Object)(object)((Component)__instance).transform == (Object)null)
			{
				return;
			}
			for (int i = 0; i < Boxes.Containers.Count; i++)
			{
				Container val = Boxes.Containers[i];
				if (!((Object)(object)val == (Object)null) && !((Object)(object)((Component)val).transform == (Object)null) && ItemDrop.s_instances.Count != ContainerAwakePatch.lastCount && !(Vector3.Distance(((Component)val).transform.position, ((Component)__instance).transform.position) > Functions.GetContainerRange(val)))
				{
					ContainerAwakePatch.ItemDroppedNearby(val);
					ContainerAwakePatch.lastCount = ItemDrop.s_instances.Count;
				}
			}
		}
	}
	[HarmonyPatch(typeof(ObjectDB), "Awake")]
	internal static class PredefinedGroupGrab
	{
		[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(1)]
		private static void Postfix(ObjectDB __instance)
		{
			if (Object.op_Implicit((Object)(object)ZNetScene.instance))
			{
				MiscFunctions.CreatePredefinedGroups(__instance);
			}
		}
	}
}
namespace AzuAutoStore.Patches.Favoriting
{
	[HarmonyPatch(typeof(InventoryGrid), "UpdateGui")]
	[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(0)]
	[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(1)]
	internal static class BorderRenderer
	{
		public static Sprite Border;

		public const string BorderName = "AzuAutoStoreFavoritingBorder";

		[HarmonyPriority(300)]
		[HarmonyAfter(new string[] { "goldenrevolver.quick_stack_store" })]
		[HarmonyPostfix]
		private static void UpdateGui(InventoryGrid __instance, Player player, Inventory ___m_inventory, List<Element> ___m_elements)
		{
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)player == (Object)null || ((Humanoid)player).m_inventory != ___m_inventory)
			{
				return;
			}
			int width = ___m_inventory.GetWidth();
			UserConfig playerConfig = UserConfig.GetPlayerConfig(player.GetPlayerID());
			for (int i = 0; i < ___m_inventory.GetHeight(); i++)
			{
				for (int j = 0; j < ___m_inventory.GetWidth(); j++)
				{
					int index = i * width + j;
					Image obj = ((((Component)___m_elements[index].m_queued).transform.childCount > 0 && (Object)(object)Utils.FindChild(((Component)___m_elements[index].m_queued).transform, "AzuAutoStoreFavoritingBorder", (IterativeSearchType)0) != (Object)null) ? ((Component)Utils.FindChild(((Component)___m_elements[index].m_queued).transform, "AzuAutoStoreFavoritingBorder", (IterativeSearchType)0)).GetComponent<Image>() : CreateBorderImage(___m_elements[index].m_queued));
					((Graphic)obj).color = AzuAutoStorePlugin.BorderColorFavoritedSlot.Value;
					((Behaviour)obj).enabled = playerConfig.IsSlotFavorited(new Vector2i(j, i));
				}
			}
			foreach (ItemData item in ___m_inventory.m_inventory)
			{
				int index2 = item.GridVectorToGridIndex(width);
				Image val = ((((Component)___m_elements[index2].m_queued).transform.childCount > 0 && (Object)(object)Utils.FindChild(((Component)___m_elements[index2].m_queued).transform, "AzuAutoStoreFavoritingBorder", (IterativeSearchType)0) != (Object)null) ? ((Component)Utils.FindChild(((Component)___m_elements[index2].m_queued).transform, "AzuAutoStoreFavoritingBorder", (IterativeSearchType)0)).GetComponent<Image>() : CreateBorderImage(___m_elements[index2].m_queued));
				bool flag = playerConfig.IsItemNameFavorited(item.m_shared);
				if (flag)
				{
					((Graphic)val).color = (((Behaviour)val).enabled ? AzuAutoStorePlugin.BorderColorFavoritedItemOnFavoritedSlot.Value : AzuAutoStorePlugin.BorderColorFavoritedItem.Value);
					((Behaviour)val).enabled = ((Behaviour)val).enabled || flag;
				}
			}
		}

		private static Image CreateBorderImage(Image baseImg)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			Image val = Object.Instantiate<Image>(baseImg, ((Component)baseImg).transform);
			foreach (Transform item in ((Component)val).transform)
			{
				Object.Destroy((Object)(object)((Component)item).gameObject);
			}
			((Object)val).name = "AzuAutoStoreFavoritingBorder";
			((Component)val).transform.SetParent(((Component)baseImg).transform);
			val.sprite = Border;
			return val;
		}
	}
	public static class ItemDataExtension
	{
		[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(1)]
		public static int GridVectorToGridIndex(this ItemData item, int width)
		{
			return item.m_gridPos.y * width + item.m_gridPos.x;
		}
	}
	internal class ButtonRenderer
	{
		internal class MainButtonUpdate
		{
			[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(1)]
			internal static void UpdateInventoryGuiButtons(InventoryGui __instance)
			{
				if (hasOpenedInventoryOnce && !((Object)(object)__instance != (Object)(object)InventoryGui.instance) && Object.op_Implicit((Object)(object)Player.m_localPlayer))
				{
					FavoritingMode.HasCurrentlyToggledFavoriting = false;
				}
			}
		}

		internal static bool hasOpenedInventoryOnce;

		[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(1)]
		internal static Button favoritingTogglingButton;

		[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(1)]
		internal static IEnumerator WaitAFrameToUpdateUIElements(InventoryGui instance, bool includeTrashButton)
		{
			yield return null;
			if (!((Object)(object)instance == (Object)null))
			{
				MainButtonUpdate.UpdateInventoryGuiButtons(instance);
			}
		}
	}
	internal class FavoritingMode
	{
		private static bool hasCurrentlyToggledFavoriting;

		internal static bool HasCurrentlyToggledFavoriting
		{
			get
			{
				return hasCurrentlyToggledFavoriting;
			}
			set
			{
				hasCurrentlyToggledFavoriting = value;
			}
		}

		internal static void RefreshDisplay()
		{
			HasCurrentlyToggledFavoriting = HasCurrentlyToggledFavoriting;
		}

		internal static bool IsInFavoritingMode()
		{
			//IL_000c: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			if (!HasCurrentlyToggledFavoriting && !AzuAutoStorePlugin.FavoritingModifierKeybind1.Value.IsKeyHeld() && !AzuAutoStorePlugin.FavoritingModifierKeybind2.Value.IsKeyHeld())
			{
				return AzuAutoStorePlugin.SearchModifierKeybind.Value.IsKeyHeld();
			}
			return true;
		}
	}
	[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(1)]
	[<c3ab1a27-299d-4c52-9c11-b49797a03bf2>Nullable(0)]
	[HarmonyPatch(typeof(InventoryGrid))]
	internal class InventoryGridButtonHandlingPatches
	{
		[HarmonyPatch("OnRightClick")]
		[HarmonyPrefix]
		internal static bool OnRightClick(InventoryGrid __instance, UIInputHandler element)
		{
			return HandleClick(__instance, element, isLeftClick: false);
		}

		[HarmonyPatch("OnLeftClick")]
		[HarmonyPrefix]
		internal static bool OnLeftClick(InventoryGrid __instance, UIInputHandler clickHandler)
		{
			return HandleClick(__instance, clickHandler, isLeftClick: true);
		}

		internal static bool HandleClick(InventoryGrid __instance, UIInputHandler clickHandler, bool isLeftClick)
		{
			//IL_0007: 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_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			Vector2i buttonPos = __instance.GetButtonPos(((Component)clickHandler).gameObject);
			return HandleClick(__instance, buttonPos, isLeftClick, AzuAutoStorePlugin.SearchModifierKeybind.Value.IsKeyHeld());
		}

		[HarmonyPatch("UpdateGamepad")]
		private static void Postfix(InventoryGrid __instance)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance != (Object)(object)InventoryGui.instance.m_playerGrid) && __instance.m_uiGroup.IsActive)
			{
				if (ZInput.GetButtonDown("JoyButtonA"))
				{
					HandleClick(__instance, __instance.m_selected, isLeftClick: true);
				}
				else if (ZInput.GetButtonDown("JoyButtonX"))
				{
					HandleClick(__instance, __instance.m_selected, isLeftClick: false);
				}
			}
		}

		internal static bool HandleClick(InventoryGrid __instance, Vector2i buttonPos, bool isLeftClick, bool searchBypass = false)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: 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)
			//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)
			if ((Object)(object)InventoryGui.instance.m_playerGrid != (Object)(object)__instance)
			{
				return true;
			}
			Player localPlayer = Player.m_localPlayer;
			if (((Character)localPlayer).IsTeleporting())
			{
				return true;
			}
			if (Object.op_Implicit((Object)(object)InventoryGui.instance.m_dragGo))
			{
				return true;
			}
			if (!FavoritingMode.IsInFavoritingMode())
			{
				return true;
			}
			if (buttonPos == new Vector2i(-1, -1))
			{
				return true;
			}
			if (!isLeftClick)
			{
				UserConfig.GetPlayerConfig(localPlayer.GetPlayerID()).ToggleSlotFavoriting(buttonPos);
			}
			else if (searchBypass)
			{
				ItemData itemAt = __instance.m_inventory.GetItemAt(buttonPos.x, buttonPos.y);
				((Terminal)Chat.instance).TryRunCommand("azuautostoresearch " + ((Object)itemAt.m_dropPrefab).name.ToLower(), false, true);
			}
			else
			{
				ItemData itemAt2 = __instance.m_inventory.GetItemAt(buttonPos.x, buttonPos.y);
				if (itemAt2 == null)
				{
					return true;
				}
				UserConfig.GetPlayerConfig(localPlayer.GetPlayerID()).ToggleItemNameFavoriting(itemAt2.m_shared);
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "Show")]
	internal static class InventoryGuiShowPatch
	{
		[HarmonyPriority(300)]
		[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(1)]
		private static void Postfix(InventoryGui __instance)
		{
			ButtonRenderer.hasOpenedInventoryOnce = true;
			ButtonRenderer.MainButtonUpdate.UpdateInventoryGuiButtons(__instance);
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "Hide")]
	internal static class InventoryGuiHidePatch
	{
		[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(1)]
		[HarmonyPriority(300)]
		private static void Postfix(InventoryGui __instance)
		{
			FavoritingMode.HasCurrentlyToggledFavoriting = false;
		}
	}
	[HarmonyPatch(typeof(ItemData))]
	internal static class TooltipRenderer
	{
		[<1b263659-0d8e-44ba-8ad3-a1a150f8fea6>NullableContext(1)]
		[HarmonyPatch("GetTooltip", new Type[]
		{
			typeof(ItemData),
			typeof(int),
			typeof(bool),
			typeof(fl