Decompiled source of InventoryActions v1.2.0

InventoryActions.dll

Decompiled 2 days 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.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using InventoryActions.LocalizationManager;
using InventoryCompatibility;
using InventoryPersistence;
using JetBrains.Annotations;
using Microsoft.CodeAnalysis;
using ServerSync;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Core.ObjectPool;
using YamlDotNet.Core.Tokens;
using YamlDotNet.Helpers;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.BufferedDeserialization;
using YamlDotNet.Serialization.BufferedDeserialization.TypeDiscriminators;
using YamlDotNet.Serialization.Callbacks;
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: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("InventoryActions")]
[assembly: AssemblyDescription("Standalone inventory actions for Valheim")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("InventoryActions")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("1FBE0C8C-42DE-4C9A-9C7F-74280DC0B9AB")]
[assembly: AssemblyFileVersion("1.2.0")]
[assembly: IgnoresAccessChecksTo("assembly_guiutils")]
[assembly: IgnoresAccessChecksTo("assembly_utils")]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace InventoryPersistence
{
	internal static class LinkCompatibleFileWriter
	{
		private const int ErrorSymlinkNotSupported = 1464;

		internal static Exception? WriteAllText(string destinationPath, string contents)
		{
			string? directoryName = Path.GetDirectoryName(destinationPath);
			if (string.IsNullOrEmpty(directoryName))
			{
				throw new ArgumentException("The destination must include a directory.", "destinationPath");
			}
			Directory.CreateDirectory(directoryName);
			string text = destinationPath + "." + Guid.NewGuid().ToString("N") + ".tmp";
			try
			{
				File.WriteAllText(text, contents);
				if (!File.Exists(destinationPath))
				{
					File.Move(text, destinationPath);
					text = null;
					return null;
				}
				try
				{
					File.Replace(text, destinationPath, null);
					text = null;
					return null;
				}
				catch (Exception ex) when (IsLinkReplacementUnsupported(ex))
				{
					File.WriteAllText(destinationPath, contents);
					Exception ex2 = ex;
					return ex;
				}
			}
			finally
			{
				if (!string.IsNullOrEmpty(text) && File.Exists(text))
				{
					File.Delete(text);
				}
			}
		}

		internal static bool IsLinkReplacementUnsupported(Exception exception)
		{
			if (!(exception is NotSupportedException))
			{
				if (exception is IOException)
				{
					return (exception.HResult & 0xFFFF) == 1464;
				}
				return false;
			}
			return true;
		}
	}
}
namespace InventoryCompatibility
{
	internal static class PathOfValheimanActions
	{
		private const string PovOwner = "treextr.pathofvalheiman";

		private static Harmony? _patches;

		private static readonly List<(MethodBase Target, Patch Patch, HarmonyPatchType Kind)> Removed = new List<(MethodBase, Patch, HarmonyPatchType)>();

		private static Action<string>? _hostButtons;

		private static Func<string>? _buttonsHost;

		private static string? _previousHost;

		private static string? _owner;

		internal static void Install(Assembly assembly, string owner)
		{
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Expected O, but got Unknown
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Expected O, but got Unknown
			if (_patches != null)
			{
				return;
			}
			Type type = assembly.GetType("PassiveTree.QuickStack", throwOnError: true);
			Type type2 = assembly.GetType("Valheiman.Api.QuickStack", throwOnError: true);
			MethodInfo methodInfo = Require(type2, "HostButtons", typeof(void), new Type[1] { typeof(string) });
			MethodInfo methodInfo2 = Require(type2, "get_ButtonsHostedBy", typeof(string), Array.Empty<Type>());
			if (!type2.IsVisible || !methodInfo.IsPublic || !methodInfo2.IsPublic)
			{
				throw new MissingMethodException(type2.FullName, "HostButtons");
			}
			MethodInfo methodInfo3 = Require(type, "Run", typeof(void), new Type[1] { typeof(Player) });
			MethodInfo methodInfo4 = Require(type, "Sort", typeof(void), new Type[1] { typeof(Player) });
			MethodInfo methodInfo5 = Require(type, "Make", typeof(void), new Type[1] { typeof(InventoryGui) });
			Type declaring = type.GetNestedType("Response", BindingFlags.NonPublic) ?? throw new TypeLoadException("PoV QuickStack.Response");
			Type declaring2 = type.GetNestedType("Keys", BindingFlags.NonPublic) ?? throw new TypeLoadException("PoV QuickStack.Keys");
			MethodInfo target = AccessTools.DeclaredMethod(typeof(Container), "RPC_StackResponse", new Type[2]
			{
				typeof(long),
				typeof(bool)
			}, (Type[])null);
			MethodInfo target2 = AccessTools.DeclaredMethod(typeof(Player), "Update", Type.EmptyTypes, (Type[])null);
			List<(MethodBase Target, Patch Patch, HarmonyPatchType Kind)> observers = new List<(MethodBase, Patch, HarmonyPatchType)>();
			Find(target, declaring, (HarmonyPatchType)1);
			Find(target, declaring, (HarmonyPatchType)4);
			Find(target2, declaring2, (HarmonyPatchType)2);
			_hostButtons = (Action<string>)Delegate.CreateDelegate(typeof(Action<string>), methodInfo);
			_buttonsHost = (Func<string>)Delegate.CreateDelegate(typeof(Func<string>), methodInfo2);
			_previousHost = _buttonsHost();
			_owner = owner;
			_patches = new Harmony(owner + ".pov.actions");
			try
			{
				HarmonyMethod val = new HarmonyMethod(typeof(PathOfValheimanActions), "Suppress", (Type[])null);
				_patches.Patch((MethodBase)methodInfo3, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				_patches.Patch((MethodBase)methodInfo4, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				_patches.Patch((MethodBase)methodInfo5, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				_hostButtons(owner);
				foreach (var item in observers)
				{
					Removed.Add(item);
					_patches.Unpatch(item.Target, item.Patch.PatchMethod);
				}
			}
			catch
			{
				Dispose();
				throw;
			}
			unsafe void Find(MethodBase methodBase, Type type3, HarmonyPatchType kind)
			{
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Invalid comparison between Unknown and I4
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_001a: Invalid comparison between Unknown and I4
				//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
				Patches patchInfo = Harmony.GetPatchInfo(methodBase);
				Patch[] array = (((int)kind != 1) ? (((int)kind != 2) ? patchInfo?.Finalizers : patchInfo?.Postfixes) : patchInfo?.Prefixes)?.Where((Patch p) => p.owner == "treextr.pathofvalheiman" && p.PatchMethod.DeclaringType == type3).ToArray() ?? Array.Empty<Patch>();
				if (array.Length != 1)
				{
					throw new NotSupportedException("PoV action observer changed: " + type3.FullName + "/" + ((object)(*(HarmonyPatchType*)(&kind))/*cast due to .constrained prefix*/).ToString());
				}
				observers.Add((methodBase, array[0], kind));
			}
			static MethodInfo Require(Type type3, string name, Type result, params Type[] args)
			{
				MethodInfo methodInfo6 = AccessTools.DeclaredMethod(type3, name, args, (Type[])null);
				if (methodInfo6 == null || !methodInfo6.IsStatic || methodInfo6.ReturnType != result)
				{
					throw new MissingMethodException(type3.FullName, name);
				}
				return methodInfo6;
			}
		}

		private static bool Suppress()
		{
			return false;
		}

		internal static void Dispose()
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Invalid comparison between Unknown and I4
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Invalid comparison between Unknown and I4
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Expected O, but got Unknown
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Invalid comparison between Unknown and I4
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Invalid comparison between Unknown and I4
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Invalid comparison between Unknown and I4
			foreach (var observer in Removed)
			{
				Patches patchInfo = Harmony.GetPatchInfo(observer.Target);
				ReadOnlyCollection<Patch> obj = (((int)observer.Kind != 1) ? (((int)observer.Kind != 2) ? patchInfo?.Finalizers : patchInfo?.Postfixes) : patchInfo?.Prefixes);
				if (obj == null || !obj.Any((Patch p) => p.owner == observer.Patch.owner && p.PatchMethod == observer.Patch.PatchMethod))
				{
					HarmonyMethod val = new HarmonyMethod(observer.Patch.PatchMethod)
					{
						priority = observer.Patch.priority,
						before = observer.Patch.before,
						after = observer.Patch.after,
						debug = observer.Patch.debug
					};
					new Harmony(observer.Patch.owner).Patch(observer.Target, ((int)observer.Kind == 1) ? val : null, ((int)observer.Kind == 2) ? val : null, (HarmonyMethod)null, ((int)observer.Kind == 4) ? val : null, (HarmonyMethod)null);
				}
			}
			Removed.Clear();
			if (_buttonsHost != null && _buttonsHost() == _owner)
			{
				_hostButtons(_previousHost);
			}
			Harmony? patches = _patches;
			if (patches != null)
			{
				patches.UnpatchSelf();
			}
			_patches = null;
			_hostButtons = null;
			_buttonsHost = null;
			_previousHost = (_owner = null);
		}
	}
	internal static class PathOfValheimanTrashMode
	{
		private static Harmony? _patches;

		private static Func<bool>? _active;

		private static Func<bool>? _popup;

		private static Func<int>? _count;

		private static Action? _exit;

		private static Func<RectTransform>? _plate;

		private static RectTransform? _hiddenPlate;

		internal static void Install(Assembly assembly, string owner)
		{
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Expected O, but got Unknown
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Expected O, but got Unknown
			if (_patches != null)
			{
				return;
			}
			Type type = assembly.GetType("PassiveTree.UI.TrashMode", throwOnError: true);
			MethodInfo methodInfo = Require("Build", typeof(void), new Type[1] { typeof(InventoryGui) });
			MethodInfo methodInfo2 = Require("Enter", typeof(void), Array.Empty<Type>());
			MethodInfo methodInfo3 = Require("Press", typeof(void), Array.Empty<Type>());
			_active = (Func<bool>)Delegate.CreateDelegate(typeof(Func<bool>), Require("get_Active", typeof(bool), Array.Empty<Type>()));
			_popup = (Func<bool>)Delegate.CreateDelegate(typeof(Func<bool>), Require("get_PopupOpen", typeof(bool), Array.Empty<Type>()));
			_count = (Func<int>)Delegate.CreateDelegate(typeof(Func<int>), Require("get_Count", typeof(int), Array.Empty<Type>()));
			_exit = (Action)Delegate.CreateDelegate(typeof(Action), Require("Exit", typeof(void), Array.Empty<Type>()));
			FieldInfo fieldInfo = AccessTools.DeclaredField(type, "plate");
			if (fieldInfo == null || !fieldInfo.IsStatic || fieldInfo.FieldType != typeof(RectTransform))
			{
				throw new MissingFieldException(type.FullName, "plate");
			}
			_plate = Expression.Lambda<Func<RectTransform>>(Expression.Field(null, fieldInfo), Array.Empty<ParameterExpression>()).Compile();
			_patches = new Harmony(owner + ".pov.delete-ui");
			try
			{
				HarmonyMethod val = new HarmonyMethod(typeof(PathOfValheimanTrashMode), "Suppress", (Type[])null);
				_patches.Patch((MethodBase)methodInfo, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				_patches.Patch((MethodBase)methodInfo2, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				_patches.Patch((MethodBase)methodInfo3, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				Suppress();
			}
			catch
			{
				Dispose();
				throw;
			}
			MethodInfo Require(string name, Type result, params Type[] args)
			{
				MethodInfo methodInfo4 = AccessTools.DeclaredMethod(type, name, args, (Type[])null);
				if (methodInfo4 == null || !methodInfo4.IsStatic || methodInfo4.ReturnType != result)
				{
					throw new MissingMethodException(type.FullName, name);
				}
				return methodInfo4;
			}
		}

		private static bool Suppress()
		{
			if (_active() || _popup() || _count() != 0)
			{
				_exit();
			}
			RectTransform val = _plate();
			if ((Object)(object)val != (Object)null && ((Component)val).gameObject.activeSelf)
			{
				_hiddenPlate = val;
				((Component)val).gameObject.SetActive(false);
			}
			return false;
		}

		internal static void Dispose()
		{
			Harmony? patches = _patches;
			if (patches != null)
			{
				patches.UnpatchSelf();
			}
			_patches = null;
			if ((Object)(object)_hiddenPlate != (Object)null)
			{
				((Component)_hiddenPlate).gameObject.SetActive(true);
			}
			_hiddenPlate = null;
			_active = (_popup = null);
			_count = null;
			_exit = null;
			_plate = null;
		}
	}
}
namespace InventoryActions
{
	[BepInPlugin("sighsorry.InventoryActions", "InventoryActions", "1.2.0")]
	[BepInIncompatibility("sighsorry.InventorySlots")]
	[BepInIncompatibility("goldenrevolver.quick_stack_store")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class InventoryActionsPlugin : BaseUnityPlugin
	{
		private enum RestockMode
		{
			CurrentContainerMatchingStacks,
			AreaFavoriteRestock
		}

		private enum AreaOwnershipFailure
		{
			None,
			InvalidRequest,
			NotOwner,
			Unsupported,
			Busy,
			InUse,
			NoAccess,
			OutOfRange,
			Unavailable
		}

		private sealed class AreaContainerTransferSession
		{
			public Player Player;

			public Inventory PlayerInventory;

			public Container Anchor;

			public ZDOID AnchorId;

			public AreaContainerActionKind Action;

			public List<Container> Targets;

			public int NextTargetIndex;

			public Container? PendingTarget;

			public bool PendingNative;

			public AreaOwnershipRequestIdentity PendingIdentity;

			public long PendingGrantToken;

			public AreaOwnershipHandoffDecision PendingDecision;

			public uint GrantDataRevision;

			public ushort GrantOwnerRevision;

			public long GrantExpiresAt;

			public int TotalMoved;

			public bool PlayerInventoryChanged;

			public int ChangedContainerVfxCount;

			public int VfxLimit;

			public bool AllowOpenQuickStackAnchor;
		}

		private enum SortButtonSide
		{
			Right,
			Left
		}

		private sealed class ButtonPositionOffsetEditorState
		{
			public string LastEntryValue { get; set; } = "";

			public string X { get; set; } = "0";

			public string Y { get; set; } = "0";
		}

		private sealed 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);
			}
		}

		private sealed class ConfigurationManagerAttributes
		{
			public bool? Browsable { get; set; }

			public int? Order { get; set; }

			public Action<ConfigEntryBase>? CustomDrawer { get; set; }
		}

		private sealed class MultiUserChestTransferApi
		{
			internal readonly Type RequestType;

			internal readonly Type DepositRequestType;

			internal readonly MethodInfo Remove;

			internal readonly MethodInfo Deposit;

			internal readonly MethodInfo AddPackage;

			internal readonly MethodInfo ApplyResponse;

			internal readonly MethodInfo ApplyDepositResponse;

			internal readonly MethodInfo GetBlock;

			internal readonly MethodInfo AnyBlocked;

			internal readonly MethodInfo FindChanges;

			internal readonly ConstructorInfo DepositConstructor;

			internal readonly PropertyInfo RequestId;

			internal readonly PropertyInfo Source;

			internal readonly PropertyInfo Target;

			internal readonly PropertyInfo ResponseId;

			internal readonly PropertyInfo Success;

			internal readonly PropertyInfo Amount;

			internal readonly FieldInfo From;

			internal readonly FieldInfo To;

			internal readonly FieldInfo DragAmount;

			internal readonly FieldInfo ResponseItem;

			internal readonly FieldInfo HasSwitched;

			internal readonly FieldInfo DepositTo;

			internal readonly FieldInfo DepositItem;

			internal readonly FieldInfo AllowSwitch;

			internal readonly FieldInfo RefundItem;

			internal readonly FieldInfo RefundPosition;

			internal readonly object Changes;

			internal MultiUserChestTransferApi(Assembly assembly)
			{
				RequestType = Type("RequestChestRemove");
				DepositRequestType = Type("RequestChestAdd");
				Type type = Type("IRequest");
				Type type2 = Type("IResponse");
				Type type3 = Type("RequestChestRemoveResponse");
				Type type4 = Type("InventoryPreview");
				Type type5 = Type("InventoryBlock");
				Type type6 = Type("RequestChestAddResponse");
				RequireContract(RequestType, type);
				RequireContract(DepositRequestType, type);
				RequireContract(type3, type2);
				RequireContract(type6, type2);
				Remove = Method(Type("ContainerHandler"), "RemoveItemFromChest", RequestType, isStatic: true, new Type[7]
				{
					typeof(Container),
					typeof(ItemData),
					typeof(Inventory),
					typeof(Vector2i),
					typeof(ZDOID),
					typeof(int),
					typeof(ItemData)
				});
				Deposit = Method(Type("ContainerHandler"), "AddItemToChest", DepositRequestType, isStatic: true, new Type[6]
				{
					typeof(Container),
					typeof(ItemData),
					typeof(Inventory),
					typeof(Vector2i),
					typeof(ZDOID),
					typeof(int)
				});
				Type[] array = new Type[5]
				{
					typeof(Vector2i),
					typeof(int),
					typeof(ItemData),
					typeof(Inventory),
					typeof(Inventory)
				};
				DepositConstructor = DepositRequestType.GetConstructor(array) ?? throw new MissingMethodException("MUC RequestChestAdd constructor");
				if (!(from parameter in DepositConstructor.GetParameters()
					select parameter.ParameterType).SequenceEqual(array))
				{
					throw new MissingMethodException("MUC RequestChestAdd constructor parameters");
				}
				AddPackage = Method(type4, "AddPackage", typeof(void), isStatic: true, new Type[1] { type });
				ApplyResponse = Method(Type("InventoryHandler"), "RPC_RequestItemRemoveResponse", typeof(void), isStatic: true, new Type[2]
				{
					typeof(Inventory),
					type3
				});
				ApplyDepositResponse = Method(Type("InventoryHandler"), "RPC_RequestItemAddResponse", typeof(void), isStatic: true, new Type[2]
				{
					typeof(Inventory),
					type6
				});
				RequestId = Property(type, "RequestID", typeof(int));
				Source = Property(type, "SourceInventory", typeof(Inventory));
				Target = Property(type, "TargetInventory", typeof(Inventory));
				From = Field(RequestType, "fromPos", typeof(Vector2i));
				To = Field(RequestType, "toPos", typeof(Vector2i));
				DragAmount = Field(RequestType, "dragAmount", typeof(int));
				ResponseId = Property(type2, "SourceID", typeof(int));
				Success = Property(type2, "Success", typeof(bool));
				Amount = Property(type2, "Amount", typeof(int));
				ResponseItem = Field(type3, "responseItem", typeof(ItemData));
				HasSwitched = Field(type3, "hasSwitched", typeof(bool));
				DepositTo = Field(DepositRequestType, "toPos", typeof(Vector2i));
				DepositItem = Field(DepositRequestType, "dragItem", typeof(ItemData));
				AllowSwitch = Field(DepositRequestType, "allowSwitch", typeof(bool));
				RefundItem = Field(type6, "switchItem", typeof(ItemData));
				RefundPosition = Field(type6, "inventoryPos", typeof(Vector2i));
				GetBlock = Method(type5, "Get", type5, isStatic: true, new Type[1] { typeof(Inventory) });
				AnyBlocked = Method(type5, "IsAnySlotBlocked", typeof(bool), isStatic: false, Array.Empty<Type>());
				Changes = type4.GetField("PackageChanges", BindingFlags.Static | BindingFlags.Public)?.GetValue(null) ?? throw new MissingFieldException("MUC InventoryPreview.PackageChanges");
				Type type7 = typeof(List<>).MakeGenericType(Type("IRequest"));
				FindChanges = Method(Changes.GetType(), "TryGetValue", typeof(bool), isStatic: false, new Type[2]
				{
					typeof(Inventory),
					type7.MakeByRefType()
				});
				static FieldInfo Field(Type type8, string name, Type value)
				{
					FieldInfo field = type8.GetField(name, BindingFlags.Instance | BindingFlags.Public);
					if ((object)field == null || !(field.FieldType == value))
					{
						throw new MissingFieldException(type8.FullName, name);
					}
					return field;
				}
				static MethodInfo Method(Type type8, string name, Type result, bool isStatic, params Type[] args)
				{
					MethodInfo method = type8.GetMethod(name, (BindingFlags)(0x10 | (isStatic ? 8 : 4)), null, args, null);
					if ((object)method == null || method.ContainsGenericParameters || !(method.ReturnType == result) || !(from parameter in method.GetParameters()
						select parameter.ParameterType).SequenceEqual(args))
					{
						throw new MissingMethodException(type8.FullName, name);
					}
					return method;
				}
				static PropertyInfo Property(Type type8, string name, Type value)
				{
					PropertyInfo property = type8.GetProperty(name, BindingFlags.Instance | BindingFlags.Public);
					if ((object)property != null && property.PropertyType == value && property.GetIndexParameters().Length == 0)
					{
						MethodInfo getMethod = property.GetGetMethod();
						if ((object)getMethod != null && !getMethod.IsStatic)
						{
							return property;
						}
					}
					throw new MissingMemberException(type8.FullName, name);
				}
				static void RequireContract(Type concrete, Type contract)
				{
					if (!concrete.IsClass || concrete.IsAbstract || !contract.IsInterface || !contract.IsAssignableFrom(concrete))
					{
						throw new TypeLoadException("MUC " + concrete.FullName + " must implement " + contract.FullName + " as a concrete class");
					}
				}
				Type Type(string name)
				{
					return assembly.GetType("MultiUserChest." + name, throwOnError: true);
				}
			}

			internal bool HasPendingChanges(Inventory inventory)
			{
				object[] array = new object[2] { inventory, null };
				if (!(bool)FindChanges.Invoke(Changes, array) || ((IList)array[1]).Count == 0)
				{
					return (bool)AnyBlocked.Invoke(GetBlock.Invoke(null, new object[1] { inventory }), null);
				}
				return true;
			}
		}

		private sealed class MucTransferSession
		{
			internal Player Player;

			internal Inventory Inventory;

			internal Container Anchor;

			internal List<Container> Containers;

			internal AreaContainerActionKind Action;

			internal readonly HashSet<ItemData> MovedSources = new HashSet<ItemData>();

			internal int Index;

			internal int Moved;
		}

		private sealed class MucTransferPending
		{
			internal readonly MultiUserChestRequestGate Gate = new MultiUserChestRequestGate();

			internal MucTransferSession Session;

			internal Inventory SourceInventory;

			internal Inventory DestinationInventory;

			internal ItemData Source;

			internal ItemData OriginalSource;

			internal ItemData? Target;

			internal Vector2i From;

			internal Vector2i To;

			internal int Requested;

			internal int Returned;

			internal int Before;

			internal int Applied;

			internal int Refund;

			internal bool ValidResponse;

			internal bool TargetStillEligible;

			internal bool SeedEmpty;

			internal bool EmptyBeforeResponse;

			internal bool NoSwitchPrepared;

			internal float CompletedAt;

			internal bool Deposit => Session.Action == AreaContainerActionKind.QuickStack;
		}

		[HarmonyPatch(typeof(ZNet), "StopAll", new Type[] { typeof(bool) })]
		private static class MucTransferNetworkStoppedPatch
		{
			private static void Postfix()
			{
				ClearMucTransferSession();
			}
		}

		public enum Toggle
		{
			Off,
			On
		}

		private sealed class RestockTargetLimitEditorRow
		{
			public string Item { get; set; }

			public string Amount { get; set; }

			public RestockRuleMode Mode { get; set; }

			public RestockTargetLimitEditorRow(string item, string amount, RestockRuleMode mode = RestockRuleMode.Existing)
			{
				Item = item;
				Amount = amount;
				Mode = mode;
			}
		}

		private sealed class ConfigDrawerMeasurement
		{
			internal float MeasuredWidth = 240f;

			internal float LayoutWidth = 240f;
		}

		private static class FavoriteMemoryAccess
		{
			internal static readonly FieldRef<Player, bool> IsLoading = AccessTools.FieldRefAccess<Player, bool>("m_isLoading");
		}

		public enum FeatureGuideState
		{
			Expanded,
			Collapsed,
			Hidden
		}

		[HarmonyPatch(typeof(InventoryGui), "Awake")]
		private static class FeatureGuideLayoutAwakePatch
		{
			[HarmonyPriority(0)]
			private static void Postfix(InventoryGui __instance)
			{
				CaptureFeatureGuideLayout(__instance);
			}
		}

		[HarmonyPatch(typeof(InventoryGui), "OnDestroy")]
		private static class FeatureGuideLayoutDestroyPatch
		{
			private static void Postfix(InventoryGui __instance)
			{
				if ((Object)(object)_featureGuideLayoutGui == (Object)(object)__instance)
				{
					ClearFeatureGuideLayout();
				}
			}
		}

		private enum InventorySlideButton
		{
			Trash,
			Restock,
			Exclude
		}

		private sealed class InventoryButtonSlide : MonoBehaviour, ICanvasRaycastFilter
		{
			private const float Peek = 7f;

			private const float Duration = 0.15f;

			private const float CloseDelay = 0.3f;

			internal InventoryGui Owner;

			internal RectTransform Content;

			private InventorySlideButton _kind;

			private RectTransform _clip;

			private CanvasGroup _input;

			private Animator? _animator;

			private Camera? _camera;

			private EventSystem? _eventSystem;

			private PointerEventData? _pointer;

			private readonly List<RaycastResult> _hits = new List<RaycastResult>();

			private float _progress;

			private float _size;

			private float _lastInside = float.NegativeInfinity;

			private bool _wasOpen;

			private bool _hasButtons;

			internal bool PointerOver { get; private set; }

			internal Camera? Camera => _camera;

			private bool ButtonEnabled
			{
				get
				{
					if (_kind != InventorySlideButton.Trash)
					{
						return IsItemRuleButtonEnabled(_kind == InventorySlideButton.Restock);
					}
					return IsInventoryTrashButtonEnabled();
				}
			}

			private InventoryButtonMode Mode => ((_kind == InventorySlideButton.Trash) ? _trashButtonMode : ((_kind == InventorySlideButton.Restock) ? _restockButtonMode : _autoPickupButtonMode))?.Value ?? InventoryButtonMode.On;

			private float VisibleHeight => Mathf.Lerp(7f, _size, _progress);

			internal void Initialize(InventoryGui gui, InventorySlideButton kind)
			{
				//IL_0039: Unknown result type (might be due to invalid IL or missing references)
				//IL_0043: Expected O, but got Unknown
				//IL_0066: Unknown result type (might be due to invalid IL or missing references)
				//IL_006c: Unknown result type (might be due to invalid IL or missing references)
				//IL_006d: Unknown result type (might be due to invalid IL or missing references)
				//IL_006e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0074: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a9: Expected O, but got Unknown
				//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ba: Expected O, but got Unknown
				//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
				//IL_0109: Unknown result type (might be due to invalid IL or missing references)
				Owner = gui;
				_kind = kind;
				_animator = ((Component)gui).GetComponent<Animator>();
				Canvas componentInParent = ((Component)gui).GetComponentInParent<Canvas>();
				_camera = ((componentInParent != null) ? componentInParent.worldCamera : null);
				_clip = (RectTransform)((Component)this).transform;
				RectTransform clip = _clip;
				RectTransform clip2 = _clip;
				RectTransform clip3 = _clip;
				Vector2 val = default(Vector2);
				((Vector2)(ref val))..ctor(0f, 1f);
				clip3.pivot = val;
				Vector2 anchorMin = (clip2.anchorMax = val);
				clip.anchorMin = anchorMin;
				_input = ((Component)this).gameObject.AddComponent<CanvasGroup>();
				GameObject val3 = new GameObject("Buttons", new Type[1] { typeof(RectTransform) });
				Content = (RectTransform)val3.transform;
				((Transform)Content).SetParent(((Component)this).transform, false);
				RectTransform content = Content;
				RectTransform content2 = Content;
				RectTransform content3 = Content;
				((Vector2)(ref val))..ctor(0f, 1f);
				content3.pivot = val;
				anchorMin = (content2.anchorMax = val);
				content.anchorMin = anchorMin;
				Content.sizeDelta = Vector2.zero;
			}

			internal void Layout(Vector3 origin, int rows)
			{
				//IL_007c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0087: Unknown result type (might be due to invalid IL or missing references)
				//IL_008c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0091: Unknown result type (might be due to invalid IL or missing references)
				//IL_0099: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
				InventoryGrid playerGrid = Owner.m_playerGrid;
				float num = Mathf.Max(1f, playerGrid.m_elementSpace);
				_size = Mathf.Clamp(num * 0.72f, 42f, 58f);
				int columns = Mathf.Max(1, (playerGrid.m_inventory != null) ? playerGrid.m_inventory.GetWidth() : 8);
				_hasButtons = ButtonEnabled;
				int columnsFromRight = ((_kind != InventorySlideButton.Trash) ? GetItemRuleColumnsFromRight(_kind == InventorySlideButton.Restock) : 0);
				Vector3 localPosition = origin + CalculateInventoryBottomButtonPosition(columns, rows, num, _size, columnsFromRight);
				((Transform)_clip).localPosition = localPosition;
				_clip.sizeDelta = new Vector2(_size, _size);
				ApplyOffset();
			}

			public bool IsRaycastLocationValid(Vector2 screenPoint, Camera eventCamera)
			{
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0032: Unknown result type (might be due to invalid IL or missing references)
				//IL_0037: Unknown result type (might be due to invalid IL or missing references)
				//IL_0041: Unknown result type (might be due to invalid IL or missing references)
				//IL_004e: Unknown result type (might be due to invalid IL or missing references)
				Vector2 val = default(Vector2);
				if (_hasButtons && RectTransformUtility.ScreenPointToLocalPointInRectangle(_clip, screenPoint, eventCamera, ref val) && val.x >= 0f)
				{
					float x = val.x;
					Rect rect = _clip.rect;
					if (x <= ((Rect)(ref rect)).width && val.y <= 0f)
					{
						return val.y >= 0f - VisibleHeight;
					}
				}
				return false;
			}

			private void ApplyOffset()
			{
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				((Transform)Content).localPosition = -((Transform)_clip).localPosition + Vector3.up * (_size - VisibleHeight);
			}

			private bool HitVisibleStrip()
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_005d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: Unknown result type (might be due to invalid IL or missing references)
				//IL_0042: Unknown result type (might be due to invalid IL or missing references)
				//IL_004c: Expected O, but got Unknown
				//IL_009e: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
				if (!IsRaycastLocationValid(Vector2.op_Implicit(Input.mousePosition), _camera))
				{
					return false;
				}
				EventSystem current = EventSystem.current;
				if ((Object)(object)current == (Object)null)
				{
					return false;
				}
				if ((Object)(object)_eventSystem != (Object)(object)current)
				{
					_eventSystem = current;
					_pointer = new PointerEventData(current);
				}
				((AbstractEventData)_pointer).Reset();
				_pointer.position = Vector2.op_Implicit(Input.mousePosition);
				_hits.Clear();
				current.RaycastAll(_pointer, _hits);
				if (_hits.Count > 0)
				{
					RaycastResult val = _hits[0];
					return ((RaycastResult)(ref val)).gameObject.transform.IsChildOf(((Component)this).transform);
				}
				return false;
			}

			private void LateUpdate()
			{
				if ((Object)(object)Owner == (Object)null || (Object)(object)_instance == (Object)null)
				{
					return;
				}
				bool flag = InventoryGui.IsVisible() && ((Object)(object)_animator == (Object)null || _animator.GetBool("visible"));
				bool flag2 = ((Behaviour)_instance).isActiveAndEnabled && (Object)(object)Player.m_localPlayer != (Object)null && !Player.m_localPlayer.m_isLoading && CanShowItemRules(Owner);
				_hasButtons = ButtonEnabled;
				_input.blocksRaycasts = flag && flag2 && _hasButtons;
				if (!flag || !flag2)
				{
					PointerOver = false;
					_wasOpen = false;
					return;
				}
				if (!_wasOpen)
				{
					_progress = 0f;
					_lastInside = float.NegativeInfinity;
					ApplyOffset();
				}
				_wasOpen = true;
				bool flag3 = ZInput.IsExclusiveGamepadActive();
				PointerOver = !flag3 && HitVisibleStrip();
				int num;
				int num2;
				if (_kind != InventorySlideButton.Trash && (Object)(object)_itemRuleEditor != (Object)null)
				{
					num = (_itemRuleEditor.IsPopupOpenFor(_kind == InventorySlideButton.Restock) ? 1 : 0);
					if (num != 0)
					{
						num2 = 1;
						goto IL_0140;
					}
				}
				else
				{
					num = 0;
				}
				num2 = ((flag3 ? IsControllerInventoryButtonFocused(_kind) : PointerOver) ? 1 : 0);
				goto IL_0140;
				IL_0140:
				bool flag4 = (byte)num2 != 0;
				if (flag3)
				{
					_lastInside = float.NegativeInfinity;
				}
				else if (flag4)
				{
					_lastInside = Time.unscaledTime;
				}
				float num3 = ((flag4 || (!flag3 && Time.unscaledTime - _lastInside < 0.3f)) ? 1 : 0);
				_progress = ((Mode == InventoryButtonMode.On) ? 1f : Mathf.MoveTowards(_progress, num3, Time.unscaledDeltaTime / 0.15f));
				ApplyOffset();
				if (num != 0)
				{
					_itemRuleEditor.PositionPopup();
				}
			}

			private void OnDisable()
			{
				PointerOver = false;
				_wasOpen = false;
			}

			private void OnDestroy()
			{
				if (InventoryButtonSlides[(int)_kind] == this)
				{
					InventoryButtonSlides[(int)_kind] = null;
				}
			}
		}

		private enum InventoryControllerModifier
		{
			Off,
			JoyRStick,
			JoyLStick,
			JoyLTrigger,
			JoyRTrigger
		}

		private enum RestockControllerModifier
		{
			Off,
			JoyAltKeys,
			JoyRStick,
			JoyLStick,
			JoyLTrigger,
			JoyRTrigger
		}

		private static class InventoryControllerAccess
		{
			internal static readonly FieldRef<InventoryGrid, Vector2i> Selection = AccessTools.FieldRefAccess<InventoryGrid, Vector2i>("m_selected");

			internal static readonly FieldRef<InventoryGui, GameObject> DragObject = AccessTools.FieldRefAccess<InventoryGui, GameObject>("m_dragGo");
		}

		private enum InventoryButtonMode
		{
			Off,
			Auto,
			On
		}

		private sealed class ItemRuleEditor : MonoBehaviour
		{
			private sealed class ControllerRow
			{
				internal ItemRuleConfigCore.Entry Entry;

				internal Image Background;

				internal TMP_InputField? Quantity;

				internal Button? Mode;

				internal Button? Remove;
			}

			private const float RowHeight = 38f;

			private const float PopupWidth = 300f;

			private const float PopupChromeHeight = 116f;

			internal InventoryGui Owner;

			private RectTransform _root;

			private RectTransform _toolbar;

			private RectTransform _popup;

			private RectTransform _content;

			private RectTransform _viewport;

			private Button _restockButton;

			private Button _excludeButton;

			private Button _backdrop;

			private Sprite _restockIcon;

			private Sprite _excludeIcon;

			private Sprite? _ruleButtonSprite;

			private int _visibleRowCount = 1;

			private TMP_Text _title;

			private TMP_Text _scope;

			private TMP_Text _status;

			private TMP_FontAsset _font;

			private Material _fontMaterial;

			private readonly List<Button> _rowButtons = new List<Button>();

			private readonly List<UITooltip> _ruleTooltips = new List<UITooltip>();

			private readonly List<TMP_InputField> _fields = new List<TMP_InputField>();

			private readonly List<ControllerRow> _controllerRows = new List<ControllerRow>();

			private readonly ItemRuleControllerState _controllerFocus = new ItemRuleControllerState();

			private RectTransform? _controllerCellHighlight;

			private readonly List<Image> _controllerCellEdges = new List<Image>();

			private int _controllerInputFrame = -1;

			private bool _controllerActive;

			private bool _controllerStatus;

			private string _mouseScope = "";

			private readonly List<Sprite> _ownedIcons = new List<Sprite>();

			private readonly Dictionary<string, ItemData?> _resolved = new Dictionary<string, ItemData>(StringComparer.Ordinal);

			private List<ItemRuleConfigCore.Entry> _entries = new List<ItemRuleConfigCore.Entry>();

			private ItemRuleConfigCore.Entry? _registration;

			private string _snapshot = "";

			private bool _restock = true;

			private float _hoverStarted = -1f;

			private float _outsideStarted = -1f;

			private bool? _hoverMode;

			private Camera? _camera;

			internal Animator? _animator;

			private static readonly int VisibleParameter = Animator.StringToHash("visible");

			private ScrollRect _scroll;

			private readonly Color _text = new Color(1f, 0.94f, 0.8f);

			private readonly Color _gold = new Color(1f, 0.8f, 0.36f);

			internal bool Pinned { get; private set; }

			private ConfigEntry<string> Setting
			{
				get
				{
					if (!_restock)
					{
						return _autoPickupExcludedItemsConfig;
					}
					return _restockTargetStackLimitsConfig;
				}
			}

			private bool Open
			{
				get
				{
					if ((Object)(object)_popup != (Object)null)
					{
						return ((Component)_popup).gameObject.activeSelf;
					}
					return false;
				}
			}

			private bool CanShow
			{
				get
				{
					if ((Object)(object)_instance != (Object)null && ((Behaviour)_instance).isActiveAndEnabled && (Object)(object)Owner != (Object)null && InventoryGui.IsVisible() && ((Object)(object)_animator == (Object)null || _animator.GetBool(VisibleParameter)) && !Menu.IsVisible() && !Console.IsVisible())
					{
						return CanShowItemRules(Owner);
					}
					return false;
				}
			}

			private bool HasBlockingDialog
			{
				get
				{
					if (!IsDialogActive((Component?)(object)Owner.m_splitDialog) && !IsDialogActive((Component?)(object)Owner.m_variantDialog) && !IsDialogActive((Component?)(object)Owner.m_skillsDialog) && !IsDialogActive((Component?)(object)Owner.m_textsDialog) && !IsDialogActive((Component?)(object)Owner.m_achievementsPanel) && (!((Object)(object)Owner.m_trophiesPanel != (Object)null) || !Owner.m_trophiesPanel.activeInHierarchy))
					{
						if ((Object)(object)Runtime.TrashConfirmDialog != (Object)null)
						{
							return Runtime.TrashConfirmDialog.activeInHierarchy;
						}
						return false;
					}
					return true;
				}
			}

			internal bool OwnsPointer
			{
				get
				{
					if (Open)
					{
						return Contains(_popup);
					}
					return false;
				}
			}

			private static ColorBlock InputColors
			{
				get
				{
					//IL_0002: Unknown result type (might be due to invalid IL or missing references)
					//IL_001e: Unknown result type (might be due to invalid IL or missing references)
					//IL_003e: Unknown result type (might be due to invalid IL or missing references)
					//IL_005e: Unknown result type (might be due to invalid IL or missing references)
					//IL_007e: Unknown result type (might be due to invalid IL or missing references)
					//IL_009e: Unknown result type (might be due to invalid IL or missing references)
					//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
					ColorBlock result = default(ColorBlock);
					((ColorBlock)(ref result)).normalColor = new Color(0.132f, 0.132f, 0.132f, 0.502f);
					((ColorBlock)(ref result)).highlightedColor = new Color(0.39f, 0.4f, 0.4f, 0.502f);
					((ColorBlock)(ref result)).selectedColor = new Color(0.39f, 0.4f, 0.4f, 0.502f);
					((ColorBlock)(ref result)).pressedColor = new Color(0.132f, 0.132f, 0.132f, 0.65f);
					((ColorBlock)(ref result)).disabledColor = new Color(0.132f, 0.132f, 0.132f, 0.35f);
					((ColorBlock)(ref result)).colorMultiplier = 1f;
					((ColorBlock)(ref result)).fadeDuration = 0.08f;
					return result;
				}
			}

			internal bool IsPopupOpenFor(bool restock)
			{
				if (Open)
				{
					return _restock == restock;
				}
				return false;
			}

			private static bool IsDialogActive(Component? dialog)
			{
				if ((Object)(object)dialog != (Object)null)
				{
					return dialog.gameObject.activeInHierarchy;
				}
				return false;
			}

			private string L(string key, string fallback)
			{
				return LocalizeUi("$" + "InventoryActions".ToLowerInvariant() + "_rules_" + key, fallback);
			}

			internal bool Initialize(InventoryGui gui)
			{
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Expected O, but got Unknown
				//IL_00da: Unknown result type (might be due to invalid IL or missing references)
				//IL_00df: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c1: Expected O, but got Unknown
				//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
				//IL_01db: Expected O, but got Unknown
				//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
				//IL_0218: Unknown result type (might be due to invalid IL or missing references)
				//IL_021d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0252: Unknown result type (might be due to invalid IL or missing references)
				//IL_0304: Unknown result type (might be due to invalid IL or missing references)
				//IL_0313: Unknown result type (might be due to invalid IL or missing references)
				//IL_0332: Unknown result type (might be due to invalid IL or missing references)
				//IL_0364: Unknown result type (might be due to invalid IL or missing references)
				//IL_0369: Unknown result type (might be due to invalid IL or missing references)
				Owner = gui;
				_animator = ((Component)gui).GetComponent<Animator>();
				_root = (RectTransform)((Component)this).transform;
				Canvas componentInParent = ((Component)gui).GetComponentInParent<Canvas>();
				_camera = ((componentInParent != null) ? componentInParent.worldCamera : null);
				TMP_Text val = InventoryActionsPlugin.GetInventoryButtonCaptionTexts<TMP_Text>(gui.m_takeAllButton).FirstOrDefault();
				if ((Object)(object)val == (Object)null || (Object)(object)val.font == (Object)null)
				{
					val = ((IEnumerable<TMP_Text>)((Component)gui).GetComponentsInChildren<TMP_Text>(true)).FirstOrDefault((Func<TMP_Text, bool>)((TMP_Text text) => (Object)(object)text.font != (Object)null));
				}
				if ((Object)(object)val == (Object)null)
				{
					return false;
				}
				_font = val.font;
				_fontMaterial = ((val != null) ? val.fontSharedMaterial : null) ?? ((TMP_Asset)_font).material;
				_toolbar = Rect("Toolbar", (Transform)(object)gui.m_playerGrid.m_gridRoot, Vector2.zero, Vector2.zero);
				_restockButton = RuleButton("InventoryActions_RestockRules", restock: true);
				_excludeButton = RuleButton("InventoryActions_AutoPickupRules", restock: false);
				RegisterControllerInventoryButton(gui, InventorySlideButton.Restock, _restockButton);
				RegisterControllerInventoryButton(gui, InventorySlideButton.Exclude, _excludeButton);
				_ruleButtonSprite = ((Selectable)_restockButton).image.sprite;
				((Component)_restockButton).gameObject.AddComponent<UIDragHandler>().m_onReleasedOn = delegate
				{
					ClickTool(restock: true);
				};
				((Component)_excludeButton).gameObject.AddComponent<UIDragHandler>().m_onReleasedOn = delegate
				{
					ClickTool(restock: false);
				};
				_restockIcon = CreateRuleIcon(restock: true);
				_excludeIcon = CreateRuleIcon(restock: false);
				_backdrop = Button((Transform)(object)_root, "Outside", "", new UnityAction(Close));
				Stretch((RectTransform)((Component)_backdrop).transform);
				((Graphic)((Component)_backdrop).GetComponent<Image>()).color = Color.clear;
				((Component)_backdrop).gameObject.SetActive(false);
				_popup = Rect("Popup", (Transform)(object)_root, new Vector2(300f, 160f), Vector2.zero);
				Image val2 = ((Component)_popup).gameObject.AddComponent<Image>();
				((Graphic)val2).color = new Color(0.15f, 0.13f, 0.14f, 0.99f);
				ApplyWoodenPanelStyle(val2);
				_title = Text((Transform)(object)_popup, "Title", "", 19f);
				Frame(_title.rectTransform, 12f, -10f, 276f, 28f);
				_scope = Text((Transform)(object)_popup, "Scope", "", 13f);
				Frame(_scope.rectTransform, 12f, -39f, 276f, 34f);
				_viewport = Rect("Viewport", (Transform)(object)_popup, new Vector2(276f, 38f), new Vector2(12f, -78f));
				((Graphic)((Component)_viewport).gameObject.AddComponent<Image>()).color = Color.clear;
				((Component)_viewport).gameObject.AddComponent<RectMask2D>();
				_content = Rect("Content", (Transform)(object)_viewport, new Vector2(276f, 38f), Vector2.zero);
				_scroll = ((Component)_viewport).gameObject.AddComponent<ScrollRect>();
				_scroll.viewport = _viewport;
				_scroll.content = _content;
				_scroll.horizontal = false;
				_scroll.vertical = true;
				_scroll.movementType = (MovementType)2;
				_scroll.inertia = false;
				_scroll.scrollSensitivity = 30f;
				_status = Text((Transform)(object)_popup, "Status", "", 12f);
				((Component)_popup).gameObject.SetActive(false);
				return true;
			}

			internal void PositionToolbar(Vector3 gridOrigin, int visibleRows)
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
				if (!CanShow)
				{
					EndInteraction();
					return;
				}
				if (Open && (!IsItemRuleButtonEnabled(_restock) || HasBlockingDialog))
				{
					Close();
				}
				InventoryGrid grid = Owner.m_playerGrid;
				RectTransform gridRoot = grid.m_gridRoot;
				if ((Object)(object)((Transform)_toolbar).parent != (Object)(object)gridRoot)
				{
					((Transform)_toolbar).SetParent((Transform)(object)gridRoot, false);
				}
				float size = Mathf.Clamp(Mathf.Max(1f, grid.m_elementSpace) * 0.72f, 42f, 58f);
				((Transform)_toolbar).localPosition = Vector3.zero;
				Place(_restockButton, restock: true);
				Place(_excludeButton, restock: false);
				ConfigureInventoryActionIcon(_restockButton, size, _restockIcon);
				ConfigureInventoryActionIcon(_excludeButton, size, _excludeIcon);
				bool acceptsHeldItem = CanRegisterHeldItem();
				UpdateRuleButtonVisual(_restockButton, acceptsHeldItem);
				UpdateRuleButtonVisual(_excludeButton, acceptsHeldItem);
				((Component)_toolbar).gameObject.SetActive(true);
				if (Open)
				{
					PositionPopup();
				}
				void Place(Button button, bool restock)
				{
					//IL_0026: Unknown result type (might be due to invalid IL or missing references)
					//IL_0064: Unknown result type (might be due to invalid IL or missing references)
					//IL_0084: Expected O, but got Unknown
					//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
					//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
					//IL_00de: Unknown result type (might be due to invalid IL or missing references)
					//IL_00e3: 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)
					bool flag = IsItemRuleButtonEnabled(restock);
					((Component)button).gameObject.SetActive(flag);
					if (flag)
					{
						InventorySlideButton kind = (restock ? InventorySlideButton.Restock : InventorySlideButton.Exclude);
						RectTransform val = EnsureInventoryButtonSlide(Owner, gridOrigin, visibleRows, kind, (Transform?)(object)_toolbar);
						if ((Object)(object)((Component)button).transform.parent != (Object)(object)val)
						{
							((Component)button).transform.SetParent((Transform)(object)val, false);
						}
						Frame((RectTransform)((Component)button).transform, 0f, 0f, size, size);
						int columns = Mathf.Max(1, (grid.m_inventory != null) ? grid.m_inventory.GetWidth() : 8);
						Vector3 localPosition = gridOrigin + CalculateInventoryBottomButtonPosition(columns, visibleRows, Mathf.Max(1f, grid.m_elementSpace), size, GetItemRuleColumnsFromRight(restock));
						((Component)button).transform.localPosition = localPosition;
					}
				}
			}

			internal void PositionPopup()
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Expected O, but got Unknown
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_0049: Unknown result type (might be due to invalid IL or missing references)
				//IL_0052: Unknown result type (might be due to invalid IL or missing references)
				//IL_0057: Unknown result type (might be due to invalid IL or missing references)
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0061: Unknown result type (might be due to invalid IL or missing references)
				//IL_006d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
				//IL_0124: Unknown result type (might be due to invalid IL or missing references)
				//IL_0129: Unknown result type (might be due to invalid IL or missing references)
				//IL_0146: Unknown result type (might be due to invalid IL or missing references)
				//IL_014b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0180: Unknown result type (might be due to invalid IL or missing references)
				Rect rect = _root.rect;
				RectTransform val = (RectTransform)((Component)(_restock ? _restockButton : _excludeButton)).transform;
				RectTransform root = _root;
				Rect rect2 = val.rect;
				float xMax = ((Rect)(ref rect2)).xMax;
				rect2 = val.rect;
				Vector3 val2 = ((Transform)root).InverseTransformPoint(((Transform)val).TransformPoint(new Vector3(xMax, ((Rect)(ref rect2)).yMin)));
				float x = val2.x;
				rect2 = _popup.rect;
				float num = x - ((Rect)(ref rect2)).width;
				float num2 = val2.y - 6f;
				float num3 = num2 - ((Rect)(ref rect)).yMin - 8f;
				float height = Mathf.Min((float)Mathf.Min(6, _visibleRowCount) * 38f, Mathf.Max(38f, num3 - 116f));
				ResizePopupViewport(height);
				float num4 = num;
				float num5 = ((Rect)(ref rect)).xMin + 8f;
				float num6 = ((Rect)(ref rect)).xMin + 8f;
				float xMax2 = ((Rect)(ref rect)).xMax;
				rect2 = _popup.rect;
				num = Mathf.Clamp(num4, num5, Mathf.Max(num6, xMax2 - ((Rect)(ref rect2)).width - 8f));
				float num7 = num2;
				float yMin = ((Rect)(ref rect)).yMin;
				rect2 = _popup.rect;
				float num8 = yMin + ((Rect)(ref rect2)).height + 8f;
				float yMin2 = ((Rect)(ref rect)).yMin;
				rect2 = _popup.rect;
				num2 = Mathf.Clamp(num7, num8, Mathf.Max(yMin2 + ((Rect)(ref rect2)).height + 8f, ((Rect)(ref rect)).yMax - 8f));
				((Transform)_popup).localPosition = new Vector3(num, num2, 0f);
			}

			private void ResizePopupViewport(float height)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0048: Unknown result type (might be due to invalid IL or missing references)
				//IL_004d: Unknown result type (might be due to invalid IL or missing references)
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
				Rect rect = _viewport.rect;
				if (!(Mathf.Abs(((Rect)(ref rect)).height - height) < 0.1f))
				{
					rect = _popup.rect;
					float width = ((Rect)(ref rect)).width - 24f;
					RectTransform popup = _popup;
					rect = _popup.rect;
					popup.sizeDelta = new Vector2(((Rect)(ref rect)).width, 116f + height);
					Frame(_viewport, 12f, -78f, width, height);
					Frame(_status.rectTransform, 12f, -82f - height, width, 30f);
					Vector2 anchoredPosition = _content.anchoredPosition;
					float y = anchoredPosition.y;
					rect = _content.rect;
					anchoredPosition.y = Mathf.Clamp(y, 0f, Mathf.Max(0f, ((Rect)(ref rect)).height - height));
					_content.anchoredPosition = anchoredPosition;
				}
			}

			private bool CanRegisterHeldItem()
			{
				Player localPlayer = Player.m_localPlayer;
				ItemData dragItem = Owner.m_dragItem;
				if (HasHeldTrashCandidate(Owner) && (Object)(object)localPlayer != (Object)null && dragItem?.m_shared != null && (Object)(object)dragItem.m_dropPrefab != (Object)null && Owner.m_dragInventory == ((Humanoid)localPlayer).GetInventory() && Owner.m_dragInventory.ContainsItem(dragItem))
				{
					if (!((Object)(object)Owner.m_splitDialog == (Object)null))
					{
						return !Owner.m_splitDialog.IsActive;
					}
					return true;
				}
				return false;
			}

			private void UpdateRuleButtonVisual(Button button, bool acceptsHeldItem)
			{
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				SetInventoryActionIconVisual(button, acceptsHeldItem);
				Image image = ((Selectable)button).image;
				Sprite? obj;
				if (!acceptsHeldItem)
				{
					SpriteState spriteState = ((Selectable)button).spriteState;
					if ((Object)(object)((SpriteState)(ref spriteState)).disabledSprite != (Object)null)
					{
						spriteState = ((Selectable)button).spriteState;
						obj = ((SpriteState)(ref spriteState)).disabledSprite;
						goto IL_003d;
					}
				}
				obj = _ruleButtonSprite;
				goto IL_003d;
				IL_003d:
				Sprite val = obj;
				if ((Object)(object)image.sprite != (Object)(object)val)
				{
					image.sprite = val;
				}
			}

			private Button RuleButton(string name, bool restock)
			{
				//IL_0032: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: Expected O, but got Unknown
				//IL_003e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0048: Expected O, but got Unknown
				//IL_0055: Unknown result type (might be due to invalid IL or missing references)
				//IL_005f: Expected O, but got Unknown
				Button val = EnsureActionButton(_toolbar, Owner.m_takeAllButton, name, "", (UnityAction)delegate
				{
					ClickTool(restock);
				});
				val.onClick = new ButtonClickedEvent();
				((UnityEvent)val.onClick).AddListener((UnityAction)delegate
				{
					ClickTool(restock);
				});
				((Selectable)val).interactable = true;
				UIGamePad[] componentsInChildren = ((Component)val).GetComponentsInChildren<UIGamePad>(true);
				foreach (UIGamePad val2 in componentsInChildren)
				{
					((Behaviour)val2).enabled = false;
					if ((Object)(object)val2.m_hint != (Object)null && val2.m_hint.transform.IsChildOf(((Component)val).transform))
					{
						val2.m_hint.SetActive(false);
					}
				}
				UITooltip component = ((Component)val).GetComponent<UITooltip>();
				if ((Object)(object)component != (Object)null)
				{
					((Behaviour)component).enabled = false;
				}
				return val;
			}

			private void ApplyWoodenPanelStyle(Image target)
			{
				//IL_0101: Unknown result type (might be due to invalid IL or missing references)
				//IL_0119: Unknown result type (might be due to invalid IL or missing references)
				object obj;
				if (!((Object)(object)Owner.m_splitDialog != (Object)null))
				{
					obj = null;
				}
				else
				{
					Transform obj2 = ((Component)Owner.m_splitDialog).transform.Find("win_bkg/border (1)");
					obj = ((obj2 != null) ? ((Component)obj2).GetComponent<Image>() : null);
				}
				Image val = (Image)obj;
				if ((Object)(object)val == (Object)null || (Object)(object)val.sprite == (Object)null)
				{
					object obj3;
					if (!((Object)(object)Owner.m_player != (Object)null))
					{
						obj3 = null;
					}
					else
					{
						Transform obj4 = ((Transform)Owner.m_player).Find("Bkg");
						obj3 = ((obj4 != null) ? ((Component)obj4).GetComponent<Image>() : null);
					}
					val = (Image)obj3;
				}
				if ((Object)(object)val == (Object)null || (Object)(object)val.sprite == (Object)null)
				{
					object obj5;
					if (!((Object)(object)Owner.m_crafting != (Object)null))
					{
						obj5 = null;
					}
					else
					{
						Transform obj6 = ((Transform)Owner.m_crafting).Find("Bkg");
						obj5 = ((obj6 != null) ? ((Component)obj6).GetComponent<Image>() : null);
					}
					val = (Image)obj5;
				}
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val.sprite == (Object)null))
				{
					target.sprite = val.sprite;
					target.type = val.type;
					((Graphic)target).material = ((Graphic)val).material;
					((Graphic)target).color = ((Graphic)val).color;
					target.pixelsPerUnitMultiplier = val.pixelsPerUnitMultiplier;
					target.fillCenter = val.fillCenter;
					target.preserveAspect = val.preserveAspect;
				}
			}

			private bool Contains(RectTransform rect)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				return RectTransformUtility.RectangleContainsScreenPoint(rect, Vector2.op_Implicit(Input.mousePosition), _camera);
			}

			internal void OpenController(bool restock)
			{
				ClickTool(restock);
				if (Open && Pinned)
				{
					_controllerInputFrame = Time.frameCount;
					SetControllerActive(ZInput.IsExclusiveGamepadActive());
				}
			}

			internal void UpdateControllerInput()
			{
				if (_controllerInputFrame == Time.frameCount || !IsControllerInputUpdated() || !Open || !Pinned)
				{
					return;
				}
				if (!CanShow || (Object)(object)Player.m_localPlayer == (Object)null || FavoriteMemoryAccess.IsLoading.Invoke(Player.m_localPlayer) || HasBlockingDialog || !IsItemRuleButtonEnabled(_restock))
				{
					Close();
					return;
				}
				SetControllerActive(ZInput.IsExclusiveGamepadActive());
				if (!_controllerActive)
				{
					return;
				}
				ClearControllerSubmitTarget();
				if (!string.Equals(_snapshot, Setting.Value, StringComparison.Ordinal))
				{
					LoadList(_restock, pin: true);
				}
				ItemRuleControllerState.Input? input = null;
				if (TakeControllerButton("JoyButtonB"))
				{
					input = ItemRuleControllerState.Input.Cancel;
				}
				else if (TakeControllerButton("JoyButtonX"))
				{
					input = ItemRuleControllerState.Input.QuickRemove;
				}
				else if (TakeControllerButton("JoyButtonA"))
				{
					input = ItemRuleControllerState.Input.Submit;
				}
				bool flag = IsControllerDirectionDown("JoyDPadUp", "JoyLStickUp");
				bool flag2 = IsControllerDirectionDown("JoyDPadDown", "JoyLStickDown");
				bool flag3 = IsControllerDirectionDown("JoyDPadLeft", "JoyLStickLeft");
				bool flag4 = IsControllerDirectionDown("JoyDPadRight", "JoyLStickRight");
				if (!input.HasValue && flag != flag2)
				{
					input = ((!flag) ? ItemRuleControllerState.Input.Down : ItemRuleControllerState.Input.Up);
				}
				if (!input.HasValue && flag3 != flag4)
				{
					input = (flag3 ? ItemRuleControllerState.Input.Left : ItemRuleControllerState.Input.Right);
				}
				if (!input.HasValue)
				{
					return;
				}
				_controllerInputFrame = Time.frameCount;
				ItemRuleControllerState.Effect effect = _controllerFocus.Apply(input.Value, _controllerRows.Count, _restock, _registration == null);
				switch (effect)
				{
				case ItemRuleControllerState.Effect.Close:
					Close();
					return;
				case ItemRuleControllerState.Effect.None:
					return;
				case ItemRuleControllerState.Effect.FocusChanged:
					RefreshControllerSelection();
					return;
				}
				ControllerRow controllerRow = _controllerRows[_controllerFocus.Row];
				switch (effect)
				{
				case ItemRuleControllerState.Effect.Remove:
					RemoveEntry(controllerRow.Entry);
					RefreshControllerSelection(updateStatus: false);
					return;
				case ItemRuleControllerState.Effect.ToggleMode:
					if ((Object)(object)controllerRow.Mode != (Object)null)
					{
						RestockRuleMode mode = controllerRow.Entry.Mode;
						bool excluded = controllerRow.Entry.Excluded;
						((UnityEvent)controllerRow.Mode.onClick).Invoke();
						RefreshControllerSelection(controllerRow.Entry.Mode != mode || controllerRow.Entry.Excluded != excluded);
						return;
					}
					break;
				}
				if ((effect != ItemRuleControllerState.Effect.IncreaseQuantity && effect != ItemRuleControllerState.Effect.DecreaseQuantity) || !((Object)(object)controllerRow.Quantity != (Object)null) || !int.TryParse(controllerRow.Entry.Amount, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result))
				{
					return;
				}
				int num = ((effect == ItemRuleControllerState.Effect.IncreaseQuantity) ? 1 : (-1));
				int num2 = (int)Math.Min(2147483647L, Math.Max(1L, (long)result + (long)num));
				if (num2 != result)
				{
					string amount = controllerRow.Entry.Amount;
					controllerRow.Entry.Amount = num2.ToString(CultureInfo.InvariantCulture);
					bool flag5 = Save();
					if (!flag5)
					{
						controllerRow.Entry.Amount = amount;
					}
					controllerRow.Quantity.SetTextWithoutNotify(controllerRow.Entry.Amount);
					RefreshControllerSelection(flag5);
				}
			}

			private static bool TakeControllerButton(string button)
			{
				if (!ZInput.GetButtonDown(button))
				{
					return false;
				}
				ZInput.ResetButtonStatus(button);
				ZInput.ResetButtonStatus("Inventory");
				ZInput.ResetButtonStatus("Use");
				ZInput.ResetButtonStatus("JoyUse");
				return true;
			}

			private static bool IsControllerDirectionDown(string dpad, string stick)
			{
				if (!ZInput.GetButtonDown(dpad))
				{
					return ZInput.GetButtonDown(stick);
				}
				return true;
			}

			private void ClearControllerSubmitTarget()
			{
				GameObject val = (((Object)(object)EventSystem.current != (Object)null) ? EventSystem.current.currentSelectedGameObject : null);
				if ((Object)(object)val != (Object)null && (val.transform.IsChildOf(((Component)Owner).transform) || val.transform.IsChildOf((Transform)(object)_root)))
				{
					EventSystem.current.SetSelectedGameObject((GameObject)null);
				}
			}

			private void SetControllerActive(bool active)
			{
				if (_controllerActive == active)
				{
					return;
				}
				_controllerActive = active;
				_controllerFocus.EndEditing();
				bool flag = false;
				if (active)
				{
					foreach (TMP_InputField field in _fields)
					{
						if ((Object)(object)field != (Object)null && field.isFocused)
						{
							flag = true;
							field.DeactivateInputField(false);
						}
					}
					ClearControllerSubmitTarget();
				}
				else if (_controllerStatus)
				{
					_status.text = "";
					_controllerStatus = false;
				}
				RefreshControllerSelection(!flag);
			}

			private void RefreshControllerSelection(bool updateStatus = true)
			{
				//IL_0053: Unknown result type (might be due to invalid IL or missing references)
				//IL_006e: Unknown result type (might be due to invalid IL or missing references)
				//IL_032b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0353: Unknown result type (might be due to invalid IL or missing references)
				//IL_0358: Unknown result type (might be due to invalid IL or missing references)
				//IL_0389: Unknown result type (might be due to invalid IL or missing references)
				//IL_0399: Unknown result type (might be due to invalid IL or missing references)
				//IL_039e: Unknown result type (might be due to invalid IL or missing references)
				//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
				//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
				//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
				//IL_03cd: Unknown result type (might be due to invalid IL or missing references)
				//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
				//IL_0372: Unknown result type (might be due to invalid IL or missing references)
				//IL_0377: Unknown result type (might be due to invalid IL or missing references)
				_controllerFocus.Normalize(_controllerRows.Count, _restock, _registration == null);
				for (int i = 0; i < _controllerRows.Count; i++)
				{
					((Graphic)_controllerRows[i].Background).color = (Color)((_controllerActive && i == _controllerFocus.Row) ? new Color(0.95f, 0.7f, 0.24f, 0.1f) : Color.clear);
				}
				ControllerRow controllerRow = ((_controllerRows.Count > 0) ? _controllerRows[_controllerFocus.Row] : null);
				Component val = (Component)((controllerRow != null) ? (_controllerFocus.Column switch
				{
					ItemRuleControllerState.Control.Quantity => controllerRow.Quantity, 
					ItemRuleControllerState.Control.Remove => controllerRow.Remove, 
					_ => controllerRow.Mode, 
				}) : null);
				Component val2 = val;
				UpdateControllerCellHighlight((RectTransform?)(_controllerActive ? /*isinst with value type is only supported in some contexts*/: null));
				Localization instance = Localization.instance;
				bool flag = string.Equals((instance != null) ? instance.GetSelectedLanguage() : null, "Korean", StringComparison.OrdinalIgnoreCase);
				string newValue = ((_controllerFocus.Column == ItemRuleControllerState.Control.Quantity) ? L("pad_edit", flag ? "편집" : "edit") : ((_controllerFocus.Column == ItemRuleControllerState.Control.Remove) ? L("remove", "Remove") : L("pad_change", flag ? "전환" : "change")));
				_scope.text = ((!_controllerActive) ? _mouseScope : ((controllerRow == null) ? L("pad_empty", flag ? "{close}: 닫기" : "{close}: close") : (_controllerFocus.EditingQuantity ? L("pad_quantity_edit", flag ? "↑: 증가 · ↓: 감소\n{submit}/{close}: 편집 종료" : "↑: increase · ↓: decrease\n{submit}/{close}: finish editing") : L("pad_browse", flag ? "↑↓: 항목 · ←→: 조작 선택\n{submit}: {action} · {remove}: 제거 · {close}: 닫기" : "↑↓: item · ←→: control\n{submit}: {action} · {remove}: remove · {close}: close"))).Replace("{submit}", GetInventoryControllerActionDisplay("JoyButtonA")).Replace("{action}", newValue).Replace("{remove}", GetInventoryControllerActionDisplay("JoyButtonX"))
					.Replace("{close}", GetInventoryControllerActionDisplay("JoyButtonB")));
				if (!_controllerActive || controllerRow == null)
				{
					return;
				}
				if (updateStatus)
				{
					TMP_Text status = _status;
					status.text = _controllerFocus.Column switch
					{
						ItemRuleControllerState.Control.Quantity => L("quantity", "Target quantity") + ": " + controllerRow.Entry.Amount, 
						ItemRuleControllerState.Control.Remove => L("remove_help", "Remove this entry from the list."), 
						_ => _restock ? GetRestockModeTitle(controllerRow.Entry.Mode) : GetExclusionTitle(controllerRow.Entry.Excluded), 
					};
					_controllerStatus = true;
				}
				float num = (float)_controllerFocus.Row * 38f;
				float num2 = _content.anchoredPosition.y;
				Rect rect;
				if (num < num2)
				{
					num2 = num;
				}
				else
				{
					float num3 = num + 38f;
					float num4 = num2;
					rect = _viewport.rect;
					if (num3 > num4 + ((Rect)(ref rect)).height)
					{
						float num5 = num + 38f;
						rect = _viewport.rect;
						num2 = num5 - ((Rect)(ref rect)).height;
					}
				}
				_scroll.velocity = Vector2.zero;
				Vector2 anchoredPosition = _content.anchoredPosition;
				float num6 = num2;
				rect = _content.rect;
				float height = ((Rect)(ref rect)).height;
				rect = _viewport.rect;
				anchoredPosition.y = Mathf.Clamp(num6, 0f, Mathf.Max(0f, height - ((Rect)(ref rect)).height));
				_content.anchoredPosition = anchoredPosition;
			}

			private void UpdateControllerCellHighlight(RectTransform? target)
			{
				//IL_004d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0052: Unknown result type (might be due to invalid IL or missing references)
				//IL_0174: Unknown result type (might be due to invalid IL or missing references)
				//IL_018e: Unknown result type (might be due to invalid IL or missing references)
				//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
				//IL_0074: Unknown result type (might be due to invalid IL or missing references)
				//IL_0079: Unknown result type (might be due to invalid IL or missing references)
				//IL_0093: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
				//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
				//IL_0106: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)target == (Object)null)
				{
					if ((Object)(object)_controllerCellHighlight != (Object)null)
					{
						((Component)_controllerCellHighlight).gameObject.SetActive(false);
					}
					return;
				}
				if ((Object)(object)_controllerCellHighlight == (Object)null)
				{
					_controllerCellEdges.Clear();
					_controllerCellHighlight = Rect("ControllerFocus", (Transform)(object)target, Vector2.zero, Vector2.zero);
					for (int i = 0; i < 4; i++)
					{
						RectTransform obj = Rect("Edge", (Transform)(object)_controllerCellHighlight, Vector2.zero, Vector2.zero);
						bool flag = i < 2;
						obj.pivot = new Vector2(0.5f, 0.5f);
						obj.anchorMin = (flag ? new Vector2(0f, (float)i) : new Vector2((float)(i - 2), 0f));
						obj.anchorMax = (flag ? new Vector2(1f, (float)i) : new Vector2((float)(i - 2), 1f));
						obj.sizeDelta = (flag ? new Vector2(0f, 2f) : new Vector2(2f, 0f));
						Image val = ((Component)obj).gameObject.AddComponent<Image>();
						((Graphic)val).raycastTarget = false;
						_controllerCellEdges.Add(val);
					}
				}
				if ((Object)(object)((Transform)_controllerCellHighlight).parent != (Object)(object)target)
				{
					((Transform)_controllerCellHighlight).SetParent((Transform)(object)target, false);
				}
				Stretch(_controllerCellHighlight);
				_controllerCellHighlight.offsetMin = new Vector2(1f, 1f);
				_controllerCellHighlight.offsetMax = new Vector2(-1f, -1f);
				Color color = (Color)(_controllerFocus.EditingQuantity ? new Color(0.45f, 0.82f, 1f) : _gold);
				foreach (Image controllerCellEdge in _controllerCellEdges)
				{
					((Graphic)controllerCellEdge).color = color;
				}
				((Component)_controllerCellHighlight).gameObject.SetActive(true);
			}

			private void Update()
			{
				//IL_0130: Unknown result type (might be due to invalid IL or missing references)
				//IL_013a: Expected O, but got Unknown
				//IL_016a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0174: Expected O, but got Unknown
				if (!CanShow || (Object)(object)Player.m_localPlayer == (Object)null || Player.m_localPlayer.m_isLoading)
				{
					EndInteraction();
					return;
				}
				if (Open && !IsItemRuleButtonEnabled(_restock))
				{
					Close();
				}
				if (!IsItemRuleButtonEnabled(restock: true) && !IsItemRuleButtonEnabled(restock: false))
				{
					Hide();
					return;
				}
				if (HasBlockingDialog)
				{
					Close();
					return;
				}
				UpdateControllerInput();
				if (Open && Pinned && (ZInput.GetKeyDown((KeyCode)27, true) || (IsControllerInputUpdated() && TakeControllerButton("JoyButtonB"))))
				{
					Close();
					return;
				}
				if (Open && !string.Equals(_snapshot, Setting.Value, StringComparison.Ordinal) && !_fields.Any((TMP_InputField field) => field.isFocused))
				{
					LoadList(_restock, Pinned);
				}
				bool? flag = ((IsPointerOverSlide(InventorySlideButton.Restock) && IsItemRuleButtonEnabled(restock: true) && ((Component)_restockButton).gameObject.activeInHierarchy && Contains((RectTransform)((Component)_restockButton).transform)) ? new bool?(true) : ((IsPointerOverSlide(InventorySlideButton.Exclude) && IsItemRuleButtonEnabled(restock: false) && ((Component)_excludeButton).gameObject.activeInHierarchy && Contains((RectTransform)((Component)_excludeButton).transform)) ? new bool?(false) : ((bool?)null)));
				if (Pinned)
				{
					return;
				}
				if (HasHeldTrashCandidate(Owner))
				{
					if (Open)
					{
						Close();
					}
					return;
				}
				if (flag != _hoverMode)
				{
					_hoverMode = flag;
					_hoverStarted = Time.unscaledTime;
				}
				if (flag.HasValue)
				{
					_outsideStarted = -1f;
					if (Time.unscaledTime - _hoverStarted >= 0.3f && (!Open || _restock != flag.Value))
					{
						LoadList(flag.Value, pin: false);
					}
				}
				else if (Open && Contains(_popup))
				{
					_outsideStarted = -1f;
				}
				else if (Open)
				{
					if (_outsideStarted < 0f)
					{
						_outsideStarted = Time.unscaledTime;
					}
					if (Time.unscaledTime - _outsideStarted >= 0.25f)
					{
						Close();
					}
				}
			}

			private void ClickTool(bool restock)
			{
				if (CanShow && !HasBlockingDialog && IsItemRuleButtonEnabled(restock))
				{
					if (HasHeldTrashCandidate(Owner))
					{
						RegisterHeldItem(restock);
					}
					else
					{
						LoadList(restock, pin: true);
					}
				}
			}

			private void LoadList(bool restock, bool pin)
			{
				if (CanShow && !HasBlockingDialog && IsItemRuleButtonEnabled(restock))
				{
					CloseInventoryTrashConfirmDialog();
					if (_restock != restock)
					{
						_controllerFocus.Reset();
						_controllerRows.Clear();
					}
					_restock = restock;
					_snapshot = Setting.Value;
					_entries = ItemRuleConfigCore.Read(_snapshot, restock);
					_resolved.Clear();
					_registration = null;
					Pinned = pin;
					((Component)_popup).gameObject.SetActive(true);
					((Component)_backdrop).gameObject.SetActive(pin);
					Render();
				}
			}

			private void RegisterHeldItem(bool restock)
			{
				Player localPlayer = Player.m_localPlayer;
				ItemData dragItem = Owner.m_dragItem;
				if (!CanRegisterHeldItem() || (Object)(object)localPlayer == (Object)null || dragItem?.m_shared == null || (Object)(object)dragItem.m_dropPrefab == (Object)null)
				{
					return;
				}
				string key = ItemRuleConfigCore.PrefabKey(((Object)dragItem.m_dropPrefab).name);
				if (key.Length == 0)
				{
					return;
				}
				LoadList(restock, pin: true);
				ItemRuleConfigCore.Entry entry = _entries.LastOrDefault((ItemRuleConfigCore.Entry e) => (!restock) ? string.Equals(ItemRuleConfigCore.PrefabKey(e.Key), key, StringComparison.OrdinalIgnoreCase) : (RestockTargetLimitCore.NormalizeResourceToken(e.Key) == RestockTargetLimitCore.NormalizeResourceToken(key)));
				bool flag = entry == null;
				if (entry == null)
				{
					ItemRuleConfigCore.Entry entry2 = null;
					if (restock)
					{
						foreach (string restockTargetLookupToken in GetRestockTargetLookupTokens(dragItem))
						{
							string normalized = RestockTargetLimitCore.NormalizeResourceToken(restockTargetLookupToken);
							entry2 = _entries.LastOrDefault((ItemRuleConfigCore.Entry e) => RestockTargetLimitCore.NormalizeResourceToken(e.Key) == normalized);
							if (entry2 != null)
							{
								break;
							}
						}
					}
					entry = new ItemRuleConfigCore.Entry
					{
						Start = -1,
						Key = key,
						Mode = (entry2?.Mode ?? RestockRuleMode.Existing),
						Amount = (entry2?.Amount ?? Mathf.Max(1, dragItem.m_shared.m_maxStackSize).ToString(CultureInfo.InvariantCulture))
					};
					_entries.Add(entry);
				}
				_resolved[entry.Key] = dragItem;
				Owner.SetupDragItem((ItemData)null, (Inventory)null, 0);
				bool excluded = entry.Excluded;
				if (!restock)
				{
					entry.Excluded = true;
				}
				if ((flag || (!restock && !excluded)) && !Save())
				{
					entry.Excluded = excluded;
					if (flag)
					{
						_entries.Remove(entry);
					}
				}
				else if (restock)
				{
					_registration = entry;
					Pin();
					Render();
					if (_fields.Count > 0 && !ZInput.IsExclusiveGamepadActive())
					{
						((Selectable)_fields[0]).Select();
						_fields[0].ActivateInputField();
					}
				}
				else
				{
					Render();
					_status.text = L("registered", "Registered") + ": " + GetLocalizedItemName(dragItem);
					ScrollTo(entry.Key);
				}
			}

			private void Pin()
			{
				Pinned = true;
				((Component)_backdrop).gameObject.SetActive(true);
			}

			private bool Save()
			{
				_controllerStatus = false;
				if (!string.Equals(Setting.Value, _snapshot, StringComparison.Ordinal))
				{
					_status.text = L("conflict", "Config changed. Finish editing to reload.");
					return false;
				}
				string text = ItemRuleConfigCore.Write(_snapshot, _entries, _restock);
				List<ItemRuleConfigCore.Entry> list = ItemRuleConfigCore.Read(text, _restock);
				if (!(from entry in _entries
					where !entry.Removed
					select (Key: entry.Key, Excluded: entry.Excluded)).SequenceEqual(list.Select((ItemRuleConfigCore.Entry entry) => (Key: entry.Key, Excluded: entry.Excluded))))
				{
					_status.text = L("save_failed", "Could not save config.");
					return false;
				}
				try
				{
					if (text != _snapshot && !ItemRuleConfigStore.Save(Setting, _snapshot, text))
					{
						_status.text = L("conflict", "Config changed. Finish editing to reload.");
						return false;
					}
				}
				catch (Exception ex)
				{
					Log.LogWarning((object)("Could not save item rules: " + ex.Message));
					_status.text = L("save_failed", "Could not save config.");
					return false;
				}
				ItemRuleConfigCore.AcceptSaved(_entries, list);
				_snapshot = text;
				_status.text = L("saved", "Saved");
				return true;
			}

			private void ScrollTo(string key)
			{
				int num = _controllerRows.FindLastIndex((ControllerRow row) => (!_restock) ? SameExclusion(row.Entry.Key, key) : (row.Entry.Key == key));
				if (num >= 0)
				{
					_scroll.verticalNormalizedPosition = ((_controllerRows.Count <= 1) ? 1f : (1f - (float)num / (float)(_controllerRows.Count - 1)));
				}
			}

			private ItemData? Resolve(string key)
			{
				if (_resolved.TryGetValue(key, out ItemData value))
				{
					return value;
				}
				if ((Object)(object)ObjectDB.instance != (Object)null)
				{
					GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(ItemRuleConfigCore.PrefabKey(key));
					value = ((!((Object)(object)itemPrefab != (Object)null)) ? null : itemPrefab.GetComponent<ItemDrop>()?.m_itemData);
					if (value == null && _restock)
					{
						string normalized = RestockTargetLimitCore.NormalizeResourceToken(key);
						foreach (GameObject item in ObjectDB.instance.m_items)
						{
							ItemData val = ((!((Object)(object)item != (Object)null)) ? null : item.GetComponent<ItemDrop>()?.m_itemData);
							if (val?.m_shared != null && GetRestockTargetLookupTokens(val).Any((string k) => RestockTargetLimitCore.NormalizeResourceToken(k) == normalized))
							{
								value = val;
								break;
							}
						}
					}
				}
				_resolved[key] = value;
				return value;
			}

			private void ClearRows()
			{
				if ((Object)(object)_controllerCellHighlight != (Object)null)
				{
					((Component)_controllerCellHighlight).gameObject.SetActive(false);
					((Transform)_controllerCellHighlight).SetParent((Transform)(object)_popup, false);
				}
				_ruleTooltips.Clear();
				if ((Object)(object)_content == (Object)null)
				{
					_fields.Clear();
					_rowButtons.Clear();
					_controllerRows.Clear();
					return;
				}
				if ((Object)(object)EventSystem.current != (Object)null && (Object)(object)EventSystem.current.currentSelectedGameObject != (Object)null && EventSystem.current.currentSelectedGameObject.transform.IsChildOf((Transform)(object)_content))
				{
					EventSystem.current.SetSelectedGameObject((GameObject)null);
				}
				foreach (TMP_InputField field in _fields)
				{
					if (!((Object)(object)field == (Object)null))
					{
						((UnityEventBase)field.onValueChanged).RemoveAllListeners();
						((UnityEventBase)field.onSelect).RemoveAllListeners();
						((UnityEventBase)field.onEndEdit).RemoveAllListeners();
						field.DeactivateInputField(false);
					}
				}
				foreach (Button rowButton in _rowButtons)
				{
					if ((Object)(object)rowButton != (Object)null)
					{
						((UnityEventBase)rowButton.onClick).RemoveAllListeners();
					}
				}
				_fields.Clear();
				_rowButtons.Clear();
				_controllerRows.Clear();
				for (int num = ((Transform)_content).childCount - 1; num >= 0; num--)
				{
					GameObject gameObject = ((Component)((Transform)_content).GetChild(num)).gameObject;
					gameObject.SetActive(false);
					Object.Destroy((Object)(object)gameObject);
				}
			}

			private void Render()
			{
				//IL_0073: Unknown result type (might be due to invalid IL or missing references)
				//IL_0078: Unknown result type (might be due to invalid IL or missing references)
				//IL_0182: Unknown result type (might be due to invalid IL or missing references)
				//IL_0208: Unknown result type (might be due to invalid IL or missing references)
				//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_02be: Unknown result type (might be due to invalid IL or missing references)
				//IL_037b: Unknown result type (might be due to invalid IL or missing references)
				//IL_038f: Unknown result type (might be due to invalid IL or missing references)
				//IL_03ab: Unknown result type (might be due to invalid IL or missing references)
				//IL_0436: Unknown result type (might be due to invalid IL or missing references)
				//IL_043b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0453: Unknown result type (might be due to invalid IL or missing references)
				//IL_0483: Unknown result type (might be due to invalid IL or missing references)
				//IL_0492: Unknown result type (might be due to invalid IL or missing references)
				//IL_071d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0727: Expected O, but got Unknown
				//IL_0739: Unknown result type (might be due to invalid IL or missing references)
				//IL_0754: Expected O, but got Unknown
				//IL_076d: Unknown result type (might be due to invalid IL or missing references)
				//IL_077c: Unknown result type (might be due to invalid IL or missing references)
				//IL_079d: Unknown result type (might be due to invalid IL or missing references)
				//IL_07ac: Unknown result type (might be due to invalid IL or missing references)
				//IL_07c8: Unknown result type (might be due to invalid IL or missing references)
				//IL_07d7: Unknown result type (might be due to invalid IL or missing references)
				//IL_05f2: Unknown result type (might be due to invalid IL or missing references)
				//IL_060d: Expected O, but got Unknown
				//IL_0632: Unknown result type (might be due to invalid IL or missing references)
				//IL_063c: Expected O, but got Unknown
				//IL_064e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0669: Expected O, but got Unknown
				//IL_0682: Unknown result type (might be due to invalid IL or missing references)
				//IL_0691: Unknown result type (might be due to invalid IL or missing references)
				//IL_082d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0837: Expected O, but got Unknown
				//IL_0840: Unknown result type (might be due to invalid IL or missing references)
				//IL_0860: Expected O, but got Unknown
				string selectedKey = ((_controllerFocus.Row >= 0 && _controllerFocus.Row < _controllerRows.Count) ? _controllerRows[_controllerFocus.Row].Entry.Key : null);
				_controllerFocus.EndEditing();
				ClearRows();
				Rect rect = _root.rect;
				float num = Mathf.Clamp(((Rect)(ref rect)).width - 16f, 260f, 300f);
				float num2 = num - 24f;
				List<ItemRuleConfigCore.Entry> list = ((_registration != null) ? new List<ItemRuleConfigCore.Entry> { _registration } : _entries.Where((ItemRuleConfigCore.Entry e) => !e.Removed).ToList());
				if (!_restock)
				{
					list = (from @group in list.GroupBy<ItemRuleConfigCore.Entry, string>((ItemRuleConfigCore.Entry entry2) => ItemRuleConfigCore.PrefabKey(entry2.Key), StringComparer.OrdinalIgnoreCase)
						select @group.LastOrDefault((ItemRuleConfigCore.Entry entry2) => entry2.Excluded) ?? @group.Last()).ToList();
				}
				_visibleRowCount = Mathf.Max(1, list.Count);
				float num3 = (float)Mathf.Max(1, Mathf.Min(6, list.Count)) * 38f;
				_popup.sizeDelta = new Vector2(num, 116f + num3);
				Frame(_title.rectTransform, 12f, -10f, num2, 28f);
				Frame(_scope.rectTransform, 12f, -39f, num2, 34f);
				_title.text = (_restock ? L("restock_title", "Restock targets") : L("exclude_title", "Auto pickup exclusions"));
				((Graphic)_title).color = _gold;
				_mouseScope = ((_registration != null) ? L("quantity_scope", "Target quantity · 1 or more") : (_restock ? L("restock_scope", "{key} · mode and target per favorite stack").Replace("{key}", GetContainerRestockKeyDisplayText()) : L("exclude_scope", "Manual E pickup is still available")));
				_scope.text = _mouseScope;
				Frame(_viewport, 12f, -78f, num2, num3);
				_content.sizeDelta = new Vector2(num2, (float)Mathf.Max(1, list.Count) * 38f);
				_content.anchoredPosition = Vector2.zero;
				Frame(_status.rectTransform, 12f, -82f - num3, num2, 30f);
				_status.text = "";
				if (list.Count == 0)
				{
					Frame(Text((Transform)(object)_content, "Empty", L("empty", "No registered items"), 16f).rectTransform, 0f, 0f, num2, 38f);
				}
				for (int num4 = 0; num4 < list.Count; num4++)
				{
					ItemRuleConfigCore.Entry entry = list[num4];
					RectTransform val = Rect("Row", (Transform)(object)_content, new Vector2(num2, 38f), new Vector2(0f, (float)(-num4) * 38f));
					Image val2 = ((Component)val).gameObject.AddComponent<Image>();
					((Graphic)val2).color = Color.clear;
					ControllerRow controllerRow = new ControllerRow
					{
						Entry = entry,
						Background = val2
					};
					_controllerRows.Add(controllerRow);
					float num5 = num2 - (float)((_registration != null) ? 58 : 94);
					float num6 = (_restock ? (num5 - 38f) : (num2 - 68f));
					float num7 = (_restock ? (num6 - 6f) : (num2 - 74f));
					RectTransform val3 = Rect("ItemInfo", (Transform)(object)val, new Vector2(num7, 38f), Vector2.zero);
					((Graphic)((Component)val3).gameObject.AddComponent<Image>()).color = Color.clear;
					ItemData val4 = Resolve(entry.Key);
					RectTransform val5 = Rect("Icon", (Transform)(object)val3, new Vector2(26f, 26f), new Vector2(0f, -5f));
					Image graphic = ((Component)val5).gameObject.AddComponent<Image>();
					((Graphic)graphic).raycastTarget = false;
					graphic.sprite = ((val4 != null) ? val4.GetIcon() : null);
					((Behaviour)graphic).enabled = (Object)(object)graphic.sprite != (Object)null;
					graphic.preserveAspect = true;
					TMP_Text obj = Text((Transform)(object)val3, "Name", (val4 == null) ? entry.Key : GetLocalizedItemName(val4), 16f);
					obj.textWrappingMode = (TextWrappingModes)0;
					obj.overflowMode = (TextOverflowModes)1;
					Frame(obj.rectTransform, 32f, -2f, num7 - 32f, 32f);
					UITooltip obj2 = ((Component)val3).gameObject.AddComponent<UITooltip>();
					EnsureTooltipPrefab(obj2);
					((Behaviour)obj2).enabled = (Object)(object)obj2.m_tooltipPrefab != (Object)null;
					obj2.m_topic = ((val4 == null) ? entry.Key : GetLocalizedItemName(val4));
					obj2.m_text = entry.Key;
					Image modeIcon;
					UITooltip modeTip;
					RectTransform checkmark;
					UITooltip exclusionTip;
					if (_restock)
					{
						Frame((RectTransform)((Component)(controllerRow.Quantity = NumberField(val, entry))).transform, num5, -2f, 58f, 32f);
						modeIcon = null;
						modeTip = null;
						Button val6 = Button((Transform)(object)val, "RestockMode", "", (UnityAction)delegate
						{
							Pin();
							RestockRuleMode mode = entry.Mode;
							entry.Mode = RestockTargetLimitCore.NextMode(entry.Mode);
							if (!Save())
							{
								entry.Mode = mode;
							}
							RefreshMode();
						});
						ApplyCraftButtonStyle(val6);
						Frame((RectTransform)((Component)val6).transform, num6, -2f, 32f, 32f);
						modeIcon = ((Component)Rect("ModeIcon", ((Component)val6).transform, new Vector2(28f, 28f), new Vector2(2f, -2f))).gameObject.AddComponent<Image>();
						((Graphic)modeIcon).raycastTarget = false;
						modeTip = RuleTooltip(val6);
						RefreshMode();
						_rowButtons.Add(val6);
						controllerRow.Mode = val6;
					}
					else
					{
						checkmark = null;
						exclusionTip = null;
						Button val7 = Button((Transform)(object)val, "Excluded", "", (UnityAction)delegate
						{
							Pin();
							List<(ItemRuleConfigCore.Entry, bool)> list2 = (from candidate in _entries
								where !candidate.Removed && SameExclusion(candidate.Key, entry.Key)
								select (Entry: candidate, Previous: candidate.Excluded)).ToList();
							bool excluded = !entry.Excluded;
							foreach (var item in list2)
							{
								item.Item1.Excluded = excluded;
							}
							if (!Save())
							{
								foreach (var item2 in list2)
								{
									item2.Item1.Excluded = item2.Item2;
								}
							}
							RefreshExclusion();
						});
						ApplyCraftButtonStyle(val7);
						Frame((RectTransform)((Component)val7).transform, num6, -2f, 32f, 32f);
						checkmark = Rect("Checkmark", ((Component)val7).transform, new Vector2(24f, 24f), new Vector2(4f, -4f));
						CheckmarkLine(checkmark, new Vector2(3f, -12f), new Vector2(9f, -18f));
						CheckmarkLine(checkmark, new Vector2(9f, -18f), new Vector2(21f, -5f));
						exclusionTip = RuleTooltip(val7);
						RefreshExclusion();
						_rowButtons.Add(val7);
						controllerRow.Mode = val7;
					}
					if (_registration == null)
					{
						Button val8 = Button((Transform)(object)val, "Remove", "×", (UnityAction)delegate
						{
							RemoveEntry(entry);
						});
						Frame((RectTransform)((Component)val8).transform, num2 - 30f, -2f, 30f, 32f);
						SetRuleTooltipText(RuleTooltip(val8), L("remove", "Remove"), L("remove_help", "Remove this entry from the list."));
						_rowButtons.Add(val8);
						controllerRow.Remove = val8;
					}
					void RefreshExclusion()
					{
						//IL_0058: Unknown result type (might be due to invalid IL or missing references)
						((Component)checkmark).gameObject.SetActive(entry.Excluded);
						((Graphic)graphic).color = new Color(1f, 1f, 1f, entry.Excluded ? 1f : 0.5f);
						SetRuleTooltipText(exclusionTip, GetExclusionTitle(entry.Excluded), L("exclusion_help", "Checked: exclude this item from automatic pickup. Unchecked: allow pickup while keeping this entry. Manual pickup remains available."));
					}
					void RefreshMode()
					{
						modeIcon.sprite = GetRestockModeIcon(entry.Mode);
						SetRuleTooltipText(modeTip, GetRestockModeTitle(entry.Mode), GetRestockModeHelp(entry.Mode));
					}
				}
				PositionPopup();
				int num8 = ((selectedKey == null) ? (-1) : _controllerRows.FindIndex((ControllerRow row) => (!_restock) ? SameExclusion(row.Entry.Key, selectedKey) : (row.Entry.Key == selectedKey)));
				if (num8 >= 0)
				{
					_controllerFocus.Row = num8;
				}
				RefreshControllerSelection();
			}

			private string GetExclusionTitle(bool excluded)
			{
				if (!excluded)
				{
					return L("exclusion_off", "Automatic pickup: Allowed");
				}
				return L("exclusion_on", "Automatic pickup: Excluded");
			}

			private static bool SameExclusion(string left, string right)
			{
				return string.Equals(ItemRuleConfigCore.PrefabKey(left), ItemRuleConfigCore.PrefabKey(right), StringComparison.OrdinalIgnoreCase);
			}

			private void CheckmarkLine(RectTransform parent, Vector2 from, Vector2 to)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_0046: Unknown result type (might be due to invalid IL or missing references)
				//IL_004c: Unknown result type (might be due to invalid IL or missing references)
				//IL_005d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0073: Unknown result type (might be due to invalid IL or missing references)
				Vector2 val = to - from;
				RectTransform obj = Rect("Check", (Transform)(object)parent, new Vector2(((Vector2)(ref val)).magnitude, 3f), from);
				obj.pivot = new Vector2(0f, 0.5f);
				((Transform)obj).localRotation = Quaternion.Euler(0f, 0f, Mathf.Atan2(val.y, val.x) * 57.29578f);
				Image obj2 = ((Component)obj).gameObject.AddComponent<Image>();
				((Graphic)obj2).color = _gold;
				((Graphic)obj2).raycastTarget = false;
			}

			private UITooltip RuleTooltip(Button button)
			{
				UITooltip val = ((Component)button).gameObject.AddComponent<UITooltip>();
				EnsureTooltipPrefab(val);
				((Behaviour)val).enabled = ShowRuleTooltips && (Object)(object)val.m_tooltipPrefab != (Object)null;
				_ruleTooltips.Add(val);
				return val;
			}

			private static void SetRuleTooltipText(UITooltip tooltip, string topic, string text)
			{
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				if (((Behaviour)tooltip).enabled)
				{
					tooltip.Set(topic, text, (RectTransform)null, default(Vector2));
					return;
				}
				tooltip.m_topic = topic;
				tooltip.m_text = text;
			}

			internal void RefreshRuleTooltipVisibility()
			{
				foreach (UITooltip ruleTooltip in _ruleTooltips)
				{
					if ((Object)(object)ruleTooltip != (Object)null)
					{
						((Behaviour)ruleTooltip).enabled = ShowRuleTooltips && (Object)(object)ruleTooltip.m_tooltipPrefab != (Object)null;
					}
				}
			}

			private void RemoveEntry(ItemRuleConfigCore.Entry entry)
			{
				Pin();
				List<ItemRuleConfigCore.Entry> list = (_restock ? new List<ItemRuleConfigCore.Entry> { entry } : _entri