Decompiled source of Backpacks v1.3.8

Backpacks.dll

Decompiled 7 months ago
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.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 APIManager;
using AzuEPI;
using AzuEPI.Core.Slots;
using AzuExtendedPlayerInventory;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Preloader;
using BepInEx.Preloader.Patching;
using HarmonyLib;
using ItemDataManager;
using ItemManager;
using JetBrains.Annotations;
using LocalizationManager;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Collections.Generic;
using ServerSync;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Core.Tokens;
using YamlDotNet.Helpers;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.BufferedDeserialization;
using YamlDotNet.Serialization.BufferedDeserialization.TypeDiscriminators;
using YamlDotNet.Serialization.Converters;
using YamlDotNet.Serialization.EventEmitters;
using YamlDotNet.Serialization.NamingConventions;
using YamlDotNet.Serialization.NodeDeserializers;
using YamlDotNet.Serialization.NodeTypeResolvers;
using YamlDotNet.Serialization.ObjectFactories;
using YamlDotNet.Serialization.ObjectGraphTraversalStrategies;
using YamlDotNet.Serialization.ObjectGraphVisitors;
using YamlDotNet.Serialization.Schemas;
using YamlDotNet.Serialization.TypeInspectors;
using YamlDotNet.Serialization.TypeResolvers;
using YamlDotNet.Serialization.Utilities;
using YamlDotNet.Serialization.ValueDeserializers;

[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: Guid("150BFDAF-FF35-4302-B7CC-BEDCE69118D5")]
[assembly: ComVisible(false)]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCopyright("Copyright ©  2022")]
[assembly: AssemblyProduct("Backpacks")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyDescription("https://valheim.thunderstore.io/package/Smoothbrain/Backpacks")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyTitle("Backpacks")]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: CompilationRelaxations(8)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyConfiguration("")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: <7fa4afde-22ae-4dc6-afdd-64d7dcd820e1>RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[<f1521304-6ddd-4a54-b462-4f64e06adc57>Embedded]
	[CompilerGenerated]
	internal sealed class <f1521304-6ddd-4a54-b462-4f64e06adc57>EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	[<f1521304-6ddd-4a54-b462-4f64e06adc57>Embedded]
	internal sealed class <82400168-f14d-44ea-b34c-f7901dbae490>NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public <82400168-f14d-44ea-b34c-f7901dbae490>NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public <82400168-f14d-44ea-b34c-f7901dbae490>NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	[<f1521304-6ddd-4a54-b462-4f64e06adc57>Embedded]
	internal sealed class <62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public <62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	[CompilerGenerated]
	[<f1521304-6ddd-4a54-b462-4f64e06adc57>Embedded]
	internal sealed class <7fa4afde-22ae-4dc6-afdd-64d7dcd820e1>RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public <7fa4afde-22ae-4dc6-afdd-64d7dcd820e1>RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Backpacks
{
	[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(0)]
	[PublicAPI]
	[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
	public static class API
	{
		[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(new byte[] { 2, 1 })]
		[method: <82400168-f14d-44ea-b34c-f7901dbae490>Nullable(new byte[] { 2, 1 })]
		[field: <82400168-f14d-44ea-b34c-f7901dbae490>Nullable(new byte[] { 2, 1 })]
		public static event Action<Player> EquippedBackpackUpdate;

		public static bool IsLoaded()
		{
			return true;
		}

		public static int CountItemsInBackpacks(Inventory inventory, string name, bool onlyRemoveable = true)
		{
			int num = 0;
			foreach (ItemData item in inventory.m_inventory)
			{
				ItemContainer itemContainer = item.Data().Get<ItemContainer>();
				if (itemContainer == null)
				{
					continue;
				}
				foreach (ItemData item2 in itemContainer.Inventory.m_inventory)
				{
					if (item2.m_shared.m_name == name && (!onlyRemoveable || itemContainer.CanRemoveItem(item2)))
					{
						num += item2.m_stack;
					}
				}
			}
			return num;
		}

		public static bool IsItemInBackpacks(Inventory inventory, string name)
		{
			return CountItemsInBackpacks(inventory, name) > 0;
		}

		public static bool AddItemToBackpack(ItemData backpack, ItemData item)
		{
			ItemContainer itemContainer = backpack.Data().Get<ItemContainer>();
			if (itemContainer != null && itemContainer.CanAddItem(item) && itemContainer.Inventory.AddItem(item))
			{
				itemContainer.Save();
				return true;
			}
			return false;
		}

		public static bool DeleteItemsFromBackpacks(Inventory inventory, string name, int count = 1)
		{
			Dictionary<ItemData, ItemContainer> dictionary = new Dictionary<ItemData, ItemContainer>();
			foreach (ItemData item in inventory.m_inventory)
			{
				ItemContainer itemContainer = item.Data().Get<ItemContainer>();
				if (itemContainer == null)
				{
					continue;
				}
				foreach (ItemData item2 in itemContainer.Inventory.m_inventory)
				{
					if (item2.m_shared.m_name == name && itemContainer.CanRemoveItem(item2))
					{
						dictionary.Add(item2, itemContainer);
					}
				}
			}
			if (dictionary.Sum([<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(0)] (KeyValuePair<ItemData, ItemContainer> i) => i.Key.m_stack) < count)
			{
				return false;
			}
			HashSet<ItemContainer> hashSet = new HashSet<ItemContainer>();
			try
			{
				foreach (KeyValuePair<ItemData, ItemContainer> item3 in dictionary)
				{
					hashSet.Add(item3.Value);
					if (item3.Key.m_stack <= count)
					{
						if (item3.Value.RemoveItem(item3.Key))
						{
							item3.Value.Inventory.RemoveItem(item3.Key);
						}
						count -= item3.Key.m_stack;
						if (count == 0)
						{
							return true;
						}
						continue;
					}
					ItemData key = item3.Key;
					key.m_stack -= count;
					return true;
				}
			}
			finally
			{
				foreach (ItemContainer item4 in hashSet)
				{
					item4.Save();
				}
			}
			return false;
		}

		public static List<GameObject> GetBackpackVisual(Player player)
		{
			if (Visual.visuals.TryGetValue(((Humanoid)player).m_visEquipment, out var value))
			{
				return value.backpackItemInstances;
			}
			return new List<GameObject>();
		}

		[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(2)]
		public static ItemData GetEquippedBackpack()
		{
			if (Object.op_Implicit((Object)(object)Player.m_localPlayer) && Visual.visuals.TryGetValue(((Humanoid)Player.m_localPlayer).m_visEquipment, out var value))
			{
				return value.equippedBackpackItem;
			}
			return null;
		}

		[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(2)]
		public static Inventory GetEquippedBackpackInventory()
		{
			return GetEquippedBackpack()?.Data().Get<ItemContainer>()?.Inventory;
		}

		public static List<Inventory> GetAllBackpackInventories(Inventory inventory)
		{
			List<Inventory> list = new List<Inventory>();
			foreach (ItemData item in inventory.m_inventory)
			{
				ItemContainer itemContainer = item.Data().Get<ItemContainer>();
				if (itemContainer != null)
				{
					list.Add(itemContainer.Inventory);
				}
			}
			return list;
		}

		internal static void InvokeEquippedBackpackUpdate(Player player)
		{
			API.EquippedBackpackUpdate?.Invoke(player);
		}
	}
	public enum Unique
	{
		None,
		Global,
		Restricted,
		Type,
		Bypass
	}
	[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
	[PublicAPI]
	[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(0)]
	public class ItemContainer : BackpacksItemData
	{
		[CompilerGenerated]
		private sealed class <>c__DisplayClass6_0
		{
			[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(0)]
			public ItemContainer <>4__this;

			public Vector2i dimensions;
		}

		public readonly Inventory Inventory;

		private bool hasClonedSharedData;

		private static readonly MethodInfo MemberwiseCloneMethod = AccessTools.DeclaredMethod(typeof(object), "MemberwiseClone", (Type[])null, (Type[])null);

		public ItemContainer()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			Vector2i defaultContainerSize = GetDefaultContainerSize();
			Player localPlayer = Player.m_localPlayer;
			Inventory = new Inventory("Items", (localPlayer != null) ? ((Humanoid)localPlayer).GetInventory().m_bkg : null, defaultContainerSize.x, defaultContainerSize.y);
			Inventory inventory = Inventory;
			inventory.m_onChanged = (Action)Delegate.Combine(inventory.m_onChanged, (Action)delegate
			{
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: Expected O, but got Unknown
				if (!IgnoresTeleportable())
				{
					if (!hasClonedSharedData)
					{
						base.Item.m_shared = (SharedData)MemberwiseCloneMethod.Invoke(base.Item.m_shared, Array.Empty<object>());
						hasClonedSharedData = true;
					}
					if (Object.op_Implicit((Object)(object)ZoneSystem.instance))
					{
						base.Item.m_shared.m_teleportable = Inventory.IsTeleportable();
					}
				}
				Player localPlayer2 = Player.m_localPlayer;
				if (localPlayer2 != null)
				{
					((Humanoid)localPlayer2).GetInventory().UpdateTotalWeight();
				}
			});
		}

		public virtual Vector2i GetDefaultContainerSize()
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			return new Vector2i(Backpacks.backpackColumnsByLevel[Math.Min(Backpacks.backpackColumnsByLevel.Count, base.Item.m_quality) - 1], Backpacks.backpackRowsByLevel[Math.Min(Backpacks.backpackColumnsByLevel.Count, base.Item.m_quality) - 1]);
		}

		public override void Upgraded()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			Resize(GetDefaultContainerSize());
		}

		public bool Resize(Vector2i dimensions)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			<>c__DisplayClass6_0 CS$<>8__locals0 = new <>c__DisplayClass6_0();
			CS$<>8__locals0.<>4__this = this;
			CS$<>8__locals0.dimensions = dimensions;
			if (Inventory.m_width * Inventory.m_height - Inventory.GetEmptySlots() > CS$<>8__locals0.dimensions.x * CS$<>8__locals0.dimensions.y)
			{
				return false;
			}
			IEnumerator<Vector2i> enumerator = enumerate();
			foreach (ItemData item in Inventory.m_inventory)
			{
				if (item.m_gridPos.x >= CS$<>8__locals0.dimensions.x || item.m_gridPos.y >= CS$<>8__locals0.dimensions.y)
				{
					item.m_gridPos = enumerator.Current;
					enumerator.MoveNext();
				}
			}
			Inventory.m_width = CS$<>8__locals0.dimensions.x;
			Inventory.m_height = CS$<>8__locals0.dimensions.y;
			Save();
			return true;
			[IteratorStateMachine(typeof(<>c__DisplayClass6_0.<<Resize>g__enumerate|0>d))]
			IEnumerator<Vector2i> enumerate()
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <>c__DisplayClass6_0.<<Resize>g__enumerate|0>d(0)
				{
					<>4__this = CS$<>8__locals0
				};
			}
		}

		public virtual bool IsEquipable()
		{
			return true;
		}

		public virtual Unique Uniqueness()
		{
			if (!(typeof(ItemContainer) == GetType()))
			{
				return Unique.Bypass;
			}
			return Backpacks.uniqueBackpack.Value;
		}

		public virtual bool ShowTakeAllButton()
		{
			return true;
		}

		public virtual bool AllowOpeningByKeypress()
		{
			return true;
		}

		public virtual string GetContainerTitle()
		{
			return Localization.instance.Localize(base.Item.m_shared.m_name);
		}

		public virtual string GetPressOpenText()
		{
			return "Press [" + Localization.instance.Localize("<color=yellow><b>$KEY_Use</b></color>") + "] to open";
		}

		public virtual bool IgnoresTeleportable()
		{
			return Backpacks.preventTeleportation.Value == Backpacks.Toggle.Off;
		}

		public virtual float WeightFactor()
		{
			return (float)Backpacks.backpackWeightFactor.Value / 100f;
		}

		public virtual bool CanAddItem(ItemData item)
		{
			switch (Backpacks.backpackCeption.Value)
			{
			case Backpacks.BackpackCeption.Allowed:
				return item != base.Item;
			case Backpacks.BackpackCeption.NotAllowedSameBackpack:
				return item.m_shared.m_name != base.Item.m_shared.m_name;
			case Backpacks.BackpackCeption.NotAllowedBackpacks:
			{
				ItemContainer itemContainer = item.Data().Get<ItemContainer>();
				return itemContainer == null || (!(itemContainer is CustomBackpack) && itemContainer.GetType() != typeof(ItemContainer));
			}
			case Backpacks.BackpackCeption.NotAllowed:
				return item.Data().Get<ItemContainer>() == null;
			default:
				throw new ArgumentOutOfRangeException();
			}
		}

		public virtual bool CanAddItemManually(ItemData item)
		{
			return CanAddItem(item);
		}

		public virtual bool CanRemoveItem(ItemData item)
		{
			return true;
		}

		public virtual bool RemoveItem(ItemData item)
		{
			return true;
		}

		public virtual bool MayAutoPickup(ItemData item)
		{
			return Backpacks.autoFillBackpacks.Value == Backpacks.Toggle.On;
		}

		public virtual bool AllowStacking()
		{
			return true;
		}

		public virtual bool CanBePutInContainer()
		{
			if (Backpacks.backpackChests.Value != Backpacks.Toggle.On)
			{
				return Inventory.m_inventory.Count == 0;
			}
			return true;
		}

		public virtual bool Open()
		{
			return true;
		}

		public virtual void Close()
		{
		}

		public override void Save()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			ZPackage val = new ZPackage();
			Inventory.Save(val);
			base.Value = $"{Inventory.m_width};{Inventory.m_height};{Convert.ToBase64String(val.GetArray())}";
		}

		public override void Load()
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			string[] array = base.Value.Split(new char[1] { ';' });
			if (array.Length > 2 && int.TryParse(array[0], out var result) && int.TryParse(array[1], out var result2))
			{
				Inventory.m_inventory.Clear();
				Inventory.m_width = result;
				Inventory.m_height = result2;
				Inventory.Load(new ZPackage(Convert.FromBase64String(array[2])));
			}
		}
	}
	public static class AutoPickup
	{
		[HarmonyPatch(typeof(Humanoid), "Pickup")]
		private static class AddItemToBackpack
		{
			[HarmonyPriority(300)]
			[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
			private static bool Prefix(Humanoid __instance, GameObject go, bool autoPickupDelay, bool __runOriginal, ref bool __result)
			{
				//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
				if (Backpacks.autoFillBackpacks.Value != 0 && __runOriginal)
				{
					Player val = (Player)(object)((__instance is Player) ? __instance : null);
					if (val != null)
					{
						ItemDrop component = go.GetComponent<ItemDrop>();
						if (component != null && !((Character)val).IsTeleporting() && component.CanPickup(autoPickupDelay) && component.m_nview.GetZDO() != null)
						{
							string itemName = component.m_itemData.m_shared.m_name;
							CheckAutoPickupActive.PickingUp = false;
							bool flag = ((Humanoid)val).GetInventory().CanAddItem(component.m_itemData, -1);
							if (((Humanoid)val).GetInventory().ContainsItemByName(itemName) && flag)
							{
								return true;
							}
							int stack = component.m_itemData.m_stack;
							ItemData itemData = component.m_itemData;
							if (itemData.m_dropPrefab == null)
							{
								itemData.m_dropPrefab = ObjectDB.instance.GetItemPrefab(Utils.GetPrefabName(((Component)component).gameObject));
							}
							foreach (KeyValuePair<ItemContainer, long> item in from kv in (from i in ((Humanoid)val).GetInventory().m_inventory
									select i.Data().Get<ItemContainer>() into i
									where i != null
									select i).Select(delegate(ItemContainer i)
								{
									long num = 1 + i.Item.m_gridPos.x + i.Item.m_gridPos.y * 100;
									if (i.Inventory.ContainsItemByName(itemName))
									{
										num += 10000;
									}
									List<string> value;
									if (!(i is CustomBackpack) && i.GetType() != typeof(ItemContainer))
									{
										num *= 400000000;
									}
									else if (i is CustomBackpack && CustomBackpack.AllowedItems.TryGetValue(i.Item.m_shared.m_name, out value) && value.Count > 0)
									{
										num *= 20000;
									}
									return new KeyValuePair<ItemContainer, long>(i, num);
								})
								orderby kv.Value descending
								select kv)
							{
								ItemContainer key = item.Key;
								if (item.Value < 10000 && flag)
								{
									return true;
								}
								if (key.Inventory.CanAddItem(component.m_itemData, -1) && key.CanAddItem(component.m_itemData) && key.MayAutoPickup(component.m_itemData))
								{
									key.Inventory.AddItem(component.m_itemData);
									key.Save();
									ZNetScene.instance.Destroy(go);
									((Humanoid)val).m_pickupEffects.Create(((Component)val).transform.position, Quaternion.identity, (Transform)null, 1f, -1);
									((Character)val).ShowPickupMessage(component.m_itemData, stack);
									__result = true;
									return false;
								}
							}
							return true;
						}
					}
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Player), "AutoPickup")]
		private static class CheckAutoPickupActive
		{
			public static bool PickingUp;

			private static void Prefix()
			{
				PickingUp = true;
			}

			private static void Finalizer()
			{
				PickingUp = false;
			}
		}

		[HarmonyPatch(typeof(Inventory), "CanAddItem", new Type[]
		{
			typeof(ItemData),
			typeof(int)
		})]
		private static class AutoPickupItemsWithFullInventory
		{
			[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
			private static void Postfix(Inventory __instance, ItemData item, ref bool __result)
			{
				if (__result || !CheckAutoPickupActive.PickingUp || Backpacks.autoFillBackpacks.Value != Backpacks.Toggle.On)
				{
					return;
				}
				foreach (ItemData item2 in __instance.m_inventory)
				{
					ItemContainer itemContainer = item2.Data().Get<ItemContainer>();
					if (itemContainer != null && itemContainer.Inventory.CanAddItem(item, -1) && itemContainer.CanAddItem(item) && itemContainer.MayAutoPickup(item))
					{
						__result = true;
					}
				}
			}
		}
	}
	[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInIncompatibility("org.bepinex.plugins.valheim_plus")]
	[BepInPlugin("org.bepinex.plugins.backpacks", "Backpacks", "1.3.8")]
	[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(0)]
	public class Backpacks : BaseUnityPlugin
	{
		[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(0)]
		public enum Toggle
		{
			On = 1,
			Off = 0
		}

		[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(0)]
		public enum BackpackCeption
		{
			Allowed,
			NotAllowed,
			NotAllowedBackpacks,
			NotAllowedSameBackpack
		}

		[PublicAPI]
		[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(0)]
		public class ConfigurationManagerAttributes
		{
			public bool? HideSettingName;

			public bool? HideDefaultButton;

			[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(new byte[] { 2, 1 })]
			public Action<ConfigEntryBase> CustomDrawer;
		}

		[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(0)]
		[HarmonyPatch(typeof(ObjectDB), "Awake")]
		private static class AddStatusEffectToBackpack
		{
			[HarmonyPriority(200)]
			[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
			public static void Postfix(ObjectDB __instance)
			{
				if (Object.op_Implicit((Object)(object)__instance))
				{
					Backpack.Prefab.GetComponent<ItemDrop>().m_itemData.m_shared.m_equipStatusEffect = __instance.GetStatusEffect(StringExtensionMethods.GetStableHashCode(equipStatusEffect.Value));
				}
			}
		}

		[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(0)]
		[HarmonyPatch]
		private static class PreventBackpacksInChests
		{
			private static IEnumerable<MethodInfo> TargetMethods()
			{
				return from m in typeof(Inventory).GetMethods()
					where m.Name == "MoveItemToThis"
					select m;
			}

			private static bool Prefix(Inventory __instance, ItemData item)
			{
				if (__instance == InventoryGui.instance.m_currentContainer?.m_inventory)
				{
					ItemContainer itemContainer = item.Data().Get<ItemContainer>();
					if (itemContainer != null && !itemContainer.CanBePutInContainer())
					{
						((Character)Player.m_localPlayer).Message((MessageType)2, Localization.instance.Localize("$bp_cant_put_in_chest"), 0, (Sprite)null);
						return false;
					}
				}
				return true;
			}
		}

		[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(0)]
		[HarmonyPatch(typeof(Inventory), "CanAddItem", new Type[]
		{
			typeof(ItemData),
			typeof(int)
		})]
		private static class PreventMultipleBackpacks
		{
			[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
			[HarmonyPriority(0)]
			public static void Postfix(Inventory __instance, ItemData item, ref bool __result)
			{
				if (!__result)
				{
					return;
				}
				Player localPlayer = Player.m_localPlayer;
				if (__instance != ((localPlayer != null) ? ((Humanoid)localPlayer).GetInventory() : null))
				{
					return;
				}
				Unique? unique = item.Data().Get<ItemContainer>()?.Uniqueness();
				if (!unique.HasValue)
				{
					return;
				}
				Unique valueOrDefault = unique.GetValueOrDefault();
				if (valueOrDefault == Unique.Bypass)
				{
					return;
				}
				foreach (ItemData item2 in __instance.m_inventory)
				{
					unique = item2.Data().Get<ItemContainer>()?.Uniqueness();
					if (unique.HasValue)
					{
						Unique valueOrDefault2 = unique.GetValueOrDefault();
						if (valueOrDefault2 != Unique.Bypass && item2 != item && (CheckUniqueConflict(valueOrDefault, item, item2) || (valueOrDefault != valueOrDefault2 && CheckUniqueConflict(valueOrDefault2, item2, item))))
						{
							__result = false;
							break;
						}
					}
				}
			}
		}

		[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(0)]
		[HarmonyPatch(typeof(Inventory), "AddItem", new Type[] { typeof(ItemData) })]
		private static class PreventMultipleBackpacksAddItem
		{
			private class SkipAddItemException : Exception
			{
			}

			[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
			[HarmonyPriority(100)]
			private static bool Prefix(Inventory __instance, ItemData item, bool __runOriginal, ref bool __result)
			{
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0043: Unknown result type (might be due to invalid IL or missing references)
				//IL_0048: Unknown result type (might be due to invalid IL or missing references)
				//IL_004e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0053: Unknown result type (might be due to invalid IL or missing references)
				//IL_0058: Unknown result type (might be due to invalid IL or missing references)
				if (!__runOriginal)
				{
					return true;
				}
				bool __result2 = true;
				PreventMultipleBackpacks.Postfix(__instance, item, ref __result2);
				if (!__result2)
				{
					((Character)Player.m_localPlayer).Message((MessageType)2, Localization.instance.Localize("$bp_cannot_pickup_backpack"), 0, (Sprite)null);
					Transform transform = ((Component)Player.m_localPlayer).transform;
					ItemDrop.DropItem(item, 1, transform.position + transform.forward + transform.up, Quaternion.identity);
					__result = true;
					throw new SkipAddItemException();
				}
				return __result2;
			}

			[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
			[return: <82400168-f14d-44ea-b34c-f7901dbae490>Nullable(2)]
			private static Exception Finalizer(Exception __exception)
			{
				if (!(__exception is SkipAddItemException))
				{
					return __exception;
				}
				return null;
			}
		}

		[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(0)]
		[HarmonyPatch(typeof(Inventory), "AddItem", new Type[]
		{
			typeof(ItemData),
			typeof(int),
			typeof(int),
			typeof(int)
		})]
		private static class PreventMultipleBackpacksAddItemWithAmount
		{
			private class SkipAddItemException : Exception
			{
			}

			[HarmonyPriority(100)]
			[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
			private static bool Prefix(Inventory __instance, ItemData item, bool __runOriginal, ref bool __result, int amount)
			{
				//IL_003e: 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_004f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0054: Unknown result type (might be due to invalid IL or missing references)
				//IL_0059: Unknown result type (might be due to invalid IL or missing references)
				if (!__runOriginal)
				{
					return true;
				}
				bool __result2 = true;
				PreventMultipleBackpacks.Postfix(__instance, item, ref __result2);
				if (!__result2)
				{
					((Character)Player.m_localPlayer).Message((MessageType)2, Localization.instance.Localize("$bp_cannot_pickup_backpack"), 0, (Sprite)null);
					Transform transform = ((Component)Player.m_localPlayer).transform;
					ItemDrop.DropItem(item, amount, transform.position + transform.forward + transform.up, Quaternion.identity);
					item.m_stack -= amount;
					__result = true;
					throw new SkipAddItemException();
				}
				return __result2;
			}

			[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
			[return: <82400168-f14d-44ea-b34c-f7901dbae490>Nullable(2)]
			private static Exception Finalizer(Exception __exception)
			{
				if (!(__exception is SkipAddItemException))
				{
					return __exception;
				}
				return null;
			}
		}

		[HarmonyPatch(typeof(InventoryGui), "Show")]
		[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(0)]
		private static class OpenBackpackAutomatically
		{
			[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
			private static void Postfix(InventoryGui __instance, [<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(2)] Container container)
			{
				if (container != null || autoOpenBackpack.Value != Toggle.On || !Object.op_Implicit((Object)(object)Player.m_localPlayer) || !Visual.visuals.TryGetValue(((Humanoid)Player.m_localPlayer).m_visEquipment, out var value))
				{
					return;
				}
				ItemData equippedBackpackItem = value.equippedBackpackItem;
				if (equippedBackpackItem != null)
				{
					if (__instance.m_playerGrid.GetInventory() == null)
					{
						__instance.m_playerGrid.m_inventory = ((Humanoid)Player.m_localPlayer).GetInventory();
					}
					CustomContainer.OpenFakeItemsContainer.Open(__instance, equippedBackpackItem);
				}
			}
		}

		[HarmonyPatch(typeof(InventoryGui), "UpdateRecipe")]
		[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(0)]
		private static class PreventCrafting
		{
			[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
			private static void Postfix(InventoryGui __instance)
			{
				if (((RecipeDataPair)(ref __instance.m_selectedRecipe)).ItemData != null)
				{
					return;
				}
				ItemContainer itemContainer = ((RecipeDataPair)(ref __instance.m_selectedRecipe)).Recipe?.m_item?.m_itemData.Data().Get<ItemContainer>();
				if (itemContainer != null)
				{
					bool __result = true;
					PreventMultipleBackpacks.Postfix(((Humanoid)Player.m_localPlayer).GetInventory(), itemContainer.Item, ref __result);
					if (!__result)
					{
						((Selectable)__instance.m_craftButton).interactable = false;
						((Component)__instance.m_craftButton).GetComponent<UITooltip>().m_text = Localization.instance.Localize("$bp_cannot_pickup_backpack");
					}
				}
			}
		}

		internal const string ModName = "Backpacks";

		private const string ModVersion = "1.3.8";

		private const string ModGUID = "org.bepinex.plugins.backpacks";

		internal static readonly ConfigSync configSync = new ConfigSync("Backpacks")
		{
			DisplayName = "Backpacks",
			CurrentVersion = "1.3.8",
			MinimumRequiredVersion = "1.3.8"
		};

		private static ConfigEntry<Toggle> serverConfigLocked = null;

		internal static SyncedConfigEntry<Toggle> useExternalYaml = null;

		public static ConfigEntry<Toggle> preventInventoryClosing = null;

		private static ConfigEntry<string> backpackRows = null;

		private static ConfigEntry<string> backpackColumns = null;

		public static ConfigEntry<int> backpackWeightFactor = null;

		public static ConfigEntry<Toggle> preventTeleportation = null;

		public static ConfigEntry<BackpackCeption> backpackCeption = null;

		public static ConfigEntry<Toggle> backpackChests = null;

		public static ConfigEntry<Unique> uniqueBackpack = null;

		public static ConfigEntry<Toggle> hiddenBackpack = null;

		private static ConfigEntry<Toggle> autoOpenBackpack = null;

		private static ConfigEntry<string> equipStatusEffect = null;

		public static ConfigEntry<Toggle> autoFillBackpacks = null;

		private static ConfigEntry<Toggle> backpackSlot = null;

		public static List<int> backpackRowsByLevel = new List<int>();

		public static List<int> backpackColumnsByLevel = new List<int>();

		internal static List<string> configFilePaths = null;

		internal static readonly CustomSyncedValue<List<string>> customBackpackDefinition = new CustomSyncedValue<List<string>>(configSync, "custom backpacks", new List<string>());

		public static Item Backpack = null;

		private const int WindowId = -669;

		private Rect yamlWindowRect;

		private Dictionary<string, string> currentYamlInput;

		private readonly Dictionary<string, bool> collapsed = new Dictionary<string, bool>();

		private readonly Dictionary<string, Vector2> yamlTextareaScrollPosition = new Dictionary<string, Vector2>();

		private Vector2 yamlErrorsScrollPosition;

		private bool hasErrors;

		[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(new byte[] { 2, 1, 1 })]
		private CustomSyncedValue<List<string>> activeConfigFileData;

		[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(new byte[] { 1, 2, 1, 1 })]
		private Func<object, List<string>> configChecker;

		private ConfigEntry<T> config<[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(2)] T>(string group, string name, T value, ConfigDescription description, bool synchronizedSetting = true)
		{
			ConfigEntry<T> val = ((BaseUnityPlugin)this).Config.Bind<T>(group, name, value, description);
			configSync.AddConfigEntry<T>(val).SynchronizedConfig = synchronizedSetting;
			return val;
		}

		private ConfigEntry<T> config<[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(2)] T>(string group, string name, T value, string description, bool synchronizedSetting = true)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			return config(group, name, value, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>()), synchronizedSetting);
		}

		public void Awake()
		{
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Expected O, but got Unknown
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Expected O, but got Unknown
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Expected O, but got Unknown
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Expected O, but got Unknown
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Expected O, but got Unknown
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Expected O, but got Unknown
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Expected O, but got Unknown
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Expected O, but got Unknown
			//IL_0319: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Expected O, but got Unknown
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_034b: Expected O, but got Unknown
			//IL_0390: Unknown result type (might be due to invalid IL or missing references)
			//IL_039b: Expected O, but got Unknown
			//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c6: Expected O, but got Unknown
			//IL_040b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0416: Expected O, but got Unknown
			//IL_0482: Unknown result type (might be due to invalid IL or missing references)
			//IL_0439: Unknown result type (might be due to invalid IL or missing references)
			//IL_0444: Expected O, but got Unknown
			Patcher.Patch(null, new string[1] { typeof(BackpacksItemData).FullName });
			Localizer.Load();
			configFilePaths = new List<string>(2)
			{
				Path.GetDirectoryName(((BaseUnityPlugin)this).Config.ConfigFilePath),
				Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
			};
			Backpack = new Item("bp_explorer", "bp_explorer");
			SkinnedMeshRenderer[] componentsInChildren = ((Component)Backpack.Prefab.transform.Find("attach_skin/Mesh")).GetComponentsInChildren<SkinnedMeshRenderer>(true);
			foreach (SkinnedMeshRenderer val in componentsInChildren)
			{
				CustomBackpackConfig.BackpackParts.Add(((Object)val).name);
			}
			serverConfigLocked = config("1 - General", "Lock Configuration", Toggle.On, "If on, the configuration is locked and can be changed by server admins only.");
			configSync.AddLockingConfigEntry<Toggle>(serverConfigLocked);
			useExternalYaml = configSync.AddConfigEntry<Toggle>(((BaseUnityPlugin)this).Config.Bind<Toggle>("2 - Backpack", "Use External YAML", Toggle.Off, "If set to on, the YAML file from your config folder will be used, to implement custom Backpacks inside of that file."));
			useExternalYaml.SourceConfig.SettingChanged += [<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(0)] (object _, EventArgs _) =>
			{
				ConfigLoader.reloadConfigFile();
			};
			config("2 - Backpack", "YAML Editor Anchor", 0, new ConfigDescription("Just ignore this.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					HideSettingName = true,
					HideDefaultButton = true,
					CustomDrawer = DrawYamlEditorButton
				}
			}), synchronizedSetting: false);
			preventInventoryClosing = config("2 - Backpack", "Prevent Closing", Toggle.On, new ConfigDescription("If on, pressing the interact key will not close the inventory.", (AcceptableValueBase)null, Array.Empty<object>()), synchronizedSetting: false);
			backpackRows = config("2 - Backpack", "Backpack Slot Rows", "3, 3, 4, 4, 4", new ConfigDescription("Rows in a Backpack. One number for each upgrade level. Adding more numbers adds more upgrades. Changing this value does not affect existing Backpacks.", (AcceptableValueBase)null, Array.Empty<object>()));
			backpackRows.SettingChanged += [<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(0)] (object _, EventArgs _) =>
			{
				ParseBackpackSize();
			};
			backpackColumns = config("2 - Backpack", "Backpack Slot Columns", "5, 6, 5, 6, 7", new ConfigDescription("Columns in a Backpack. One number for each upgrade level. Adding more numbers adds more upgrades. Changing this value does not affect existing Backpacks.", (AcceptableValueBase)null, Array.Empty<object>()));
			backpackColumns.SettingChanged += [<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(0)] (object _, EventArgs _) =>
			{
				ParseBackpackSize();
			};
			backpackWeightFactor = config("2 - Backpack", "Backpack Weight", 100, new ConfigDescription("Weight of items inside a Backpack.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			preventTeleportation = config("2 - Backpack", "Backpack Teleportation Check", Toggle.On, new ConfigDescription("If off, portals do not check the content of a backpack upon teleportation.", (AcceptableValueBase)null, Array.Empty<object>()));
			backpackCeption = config("2 - Backpack", "Backpacks in Backpacks", BackpackCeption.NotAllowed, new ConfigDescription("Allowed: Can put all backpacks into any other backpack.\nNot Allowed: Cannot put any backpacks into another backpack.\nNot Allowed Backpacks: Cannot put backpacks added by Backpacks into each other.\nNot Allowed Same Backpack: Cannot put the same backpack type into each other.", (AcceptableValueBase)null, Array.Empty<object>()));
			backpackChests = config("2 - Backpack", "Backpacks in Chests", Toggle.Off, new ConfigDescription("If on, you can put backpacks that aren't empty into chests, to make the chests bigger on the inside.", (AcceptableValueBase)null, Array.Empty<object>()));
			uniqueBackpack = config("2 - Backpack", "Unique Backpack", Unique.Global, new ConfigDescription("Can be used to restrict the number of backpacks a player can have in their inventory.\nGlobal: Only one backpack.\nRestricted: No other backpacks without item restrictions allowed.\nType: Only one backpack of each type.\nBypass: As many backpacks as you want.\nNone: Same as bypass, but doesn't overrule every other flag.", (AcceptableValueBase)null, Array.Empty<object>()));
			hiddenBackpack = config("2 - Backpack", "Hide Backpack", Toggle.Off, new ConfigDescription("If on, the backpack visual is hidden.", (AcceptableValueBase)null, Array.Empty<object>()), synchronizedSetting: false);
			hiddenBackpack.SettingChanged += [<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(0)] (object _, EventArgs _) =>
			{
				foreach (Visual value in Visual.visuals.Values)
				{
					value.forceSetBackpackEquipped(value.currentBackpackItemHash);
				}
			};
			autoOpenBackpack = config("2 - Backpack", "Auto Open Backpack", Toggle.On, new ConfigDescription("If on, the backpack in your backpack slot is opened automatically, if the inventory is opened.", (AcceptableValueBase)null, Array.Empty<object>()), synchronizedSetting: false);
			equipStatusEffect = config("2 - Backpack", "Equip Status Effect", "", new ConfigDescription("Name of a status effect that should be applied to the player, if the backpack is equipped.", (AcceptableValueBase)null, Array.Empty<object>()));
			equipStatusEffect.SettingChanged += [<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(0)] (object _, EventArgs _) =>
			{
				AddStatusEffectToBackpack.Postfix(ObjectDB.instance);
			};
			autoFillBackpacks = config("2 - Backpack", "Auto Fill Backpack", Toggle.On, new ConfigDescription("If on, items you pick up are added to your backpack. Conditions apply.", (AcceptableValueBase)null, Array.Empty<object>()), synchronizedSetting: false);
			if (AzuExtendedPlayerInventory.API.IsLoaded())
			{
				backpackSlot = config("2 - Backpack", "Backpack Slot", Toggle.On, new ConfigDescription("If on, there is a dedicated slot for your backpack. Requires AzuExtendedPlayerInventory.", (AcceptableValueBase)null, Array.Empty<object>()));
				backpackSlot.SettingChanged += [<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(0)] (object _, EventArgs _) =>
				{
					if (backpackSlot.Value == Toggle.On)
					{
						AddBackpackSlot();
					}
					else
					{
						AzuExtendedPlayerInventory.API.RemoveSlot(Localization.instance.Localize("$bp_backpack_slot_name"));
					}
				};
			}
			ParseBackpackSize();
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			new Harmony("org.bepinex.plugins.backpacks").PatchAll(executingAssembly);
			Backpack.Crafting.Add(CraftingTable.Workbench, 2);
			Backpack.RequiredItems.Add("BronzeNails", 5);
			Backpack.RequiredItems.Add("DeerHide", 10);
			Backpack.RequiredItems.Add("LeatherScraps", 10);
			Backpack.RequiredUpgradeItems.Add("Iron", 5, 2);
			Backpack.RequiredUpgradeItems.Add("ElderBark", 10, 2);
			Backpack.RequiredUpgradeItems.Add("Guck", 2, 2);
			Backpack.RequiredUpgradeItems.Add("Silver", 5, 3);
			Backpack.RequiredUpgradeItems.Add("WolfPelt", 3, 3);
			Backpack.RequiredUpgradeItems.Add("JuteRed", 2, 3);
			Backpack.RequiredUpgradeItems.Add("BlackMetal", 5, 4);
			Backpack.RequiredUpgradeItems.Add("LinenThread", 10, 4);
			Backpack.RequiredUpgradeItems.Add("LoxPelt", 2, 4);
			Backpack.RequiredUpgradeItems.Add("JuteBlue", 5, 5);
			Backpack.RequiredUpgradeItems.Add("ScaleHide", 5, 5);
			Backpack.RequiredUpgradeItems.Add("Carapace", 5, 5);
			Backpack.Prefab.GetComponent<ItemDrop>().m_itemData.Data().Add<ItemContainer>();
			Localizer.OnLocalizationComplete += CheckAndAddBackpackSlot;
		}

		private void OnDestroy()
		{
			Localizer.OnLocalizationComplete -= CheckAndAddBackpackSlot;
		}

		private static void AddBackpackSlot()
		{
			AzuExtendedPlayerInventory.API.AddSlot(Localization.instance.Localize("$bp_backpack_slot_name"), [return: <82400168-f14d-44ea-b34c-f7901dbae490>Nullable(2)] (Player player) => (!Visual.visuals.TryGetValue(((Humanoid)player).m_visEquipment, out var value)) ? null : value.equippedBackpackItem, validateBackpack);
		}

		private static void CheckAndAddBackpackSlot()
		{
			if (AzuExtendedPlayerInventory.API.IsLoaded() && backpackSlot.Value == Toggle.On)
			{
				AddBackpackSlot();
			}
		}

		private static bool validateBackpack(ItemData item)
		{
			return item.Data().Get<ItemContainer>()?.IsEquipable() ?? false;
		}

		private static void ParseBackpackSize()
		{
			backpackRowsByLevel.Clear();
			backpackColumnsByLevel.Clear();
			string[] array = backpackRows.Value.Split(new char[1] { ',' });
			for (int j = 0; j < array.Length; j++)
			{
				if (int.TryParse(array[j].Trim(), out var result))
				{
					if (result > 8)
					{
						Debug.LogWarning((object)"Found row configuration that exceeds 8 for Backpack. You should avoid this. Limited size to 8.");
						result = 8;
					}
					backpackRowsByLevel.Add(result);
				}
				else
				{
					Debug.LogError((object)"Found invalid row configuration for Backpack. Falling back to default config.");
					backpackRowsByLevel = (from s in ((string)((ConfigEntryBase)backpackRows).DefaultValue).Split(new char[1] { ',' })
						select int.Parse(s.Trim())).ToList();
				}
			}
			array = backpackColumns.Value.Split(new char[1] { ',' });
			for (int j = 0; j < array.Length; j++)
			{
				if (int.TryParse(array[j].Trim(), out var result2))
				{
					if (result2 > 8)
					{
						Debug.LogWarning((object)"Found column configuration that exceeds 8 for Backpack. You should avoid this. Limited size to 8.");
						result2 = 8;
					}
					backpackColumnsByLevel.Add(result2);
				}
				else
				{
					Debug.LogError((object)"Found invalid column configuration for Backpack. Falling back to default config.");
					backpackColumnsByLevel = (from s in ((string)((ConfigEntryBase)backpackRows).DefaultValue).Split(new char[1] { ',' })
						select int.Parse(s.Trim())).ToList();
				}
			}
			int maxQuality = Math.Min(backpackRowsByLevel.Count, backpackColumnsByLevel.Count);
			Backpack.Prefab.GetComponent<ItemDrop>().m_itemData.m_shared.m_maxQuality = maxQuality;
			if (!Object.op_Implicit((Object)(object)ObjectDB.instance))
			{
				return;
			}
			Inventory[] source = (from c in Player.s_players.Select([<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(0)] (Player p) => ((Humanoid)p).GetInventory()).Concat(from c in Object.FindObjectsByType<Container>((FindObjectsSortMode)0)
					select c.GetInventory())
				where c != null
				select c).ToArray();
			foreach (ItemData item in (from i in (from p in ObjectDB.instance.m_items
					select p.GetComponent<ItemDrop>() into c
					where Object.op_Implicit((Object)(object)c) && Object.op_Implicit((Object)(object)((Component)c).GetComponent<ZNetView>())
					select c).Concat(ItemDrop.s_instances)
				select i.m_itemData).Concat(source.SelectMany([<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(0)] (Inventory i) => i.GetAllItems())))
			{
				if (item.m_shared.m_name == ((Object)Backpack.Prefab).name)
				{
					item.m_shared.m_maxQuality = maxQuality;
				}
			}
		}

		private static bool CheckUniqueConflict(Unique unique, ItemData item_a, ItemData item_b)
		{
			switch (unique)
			{
			case Unique.Global:
				return true;
			case Unique.Restricted:
			{
				ItemContainer itemContainer = item_b.Data().Get<ItemContainer>();
				if (!(itemContainer is CustomBackpack))
				{
					return itemContainer?.GetType() == typeof(ItemContainer);
				}
				if (CustomBackpack.AllowedItems.TryGetValue(item_b.m_shared.m_name, out var value))
				{
					return value.Count > 0;
				}
				return false;
			}
			case Unique.Type:
				return item_a.m_shared.m_name == item_b.m_shared.m_name;
			default:
				return false;
			}
		}

		private void DrawYamlEditorButton(ConfigEntryBase _)
		{
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			ConfigLoader.Loader[] loaders = ConfigLoader.loaders;
			foreach (ConfigLoader.Loader loader in loaders)
			{
				if (loader.FileData.Value.Count <= 0 || !GUILayout.Button(loader.EditButtonName, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) }))
				{
					continue;
				}
				activeConfigFileData = loader.FileData;
				configChecker = loader.ErrorCheck;
				currentYamlInput = (from g in activeConfigFileData.Value.Select([<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(0)] (string f, int index) => new { f, index })
					group g by g.index / 2).ToDictionary([<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(0)] g => g.First().f, [<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(0)] g => g.Last().f);
				foreach (string key in currentYamlInput.Keys)
				{
					if (!collapsed.ContainsKey(key))
					{
						collapsed[key] = collapsed.Count > 3;
						yamlTextareaScrollPosition[key] = default(Vector2);
					}
				}
			}
			GUILayout.EndVertical();
		}

		private void Update()
		{
			if (activeConfigFileData != null)
			{
				Cursor.lockState = (CursorLockMode)0;
				Cursor.visible = true;
			}
		}

		private void LateUpdate()
		{
			Update();
		}

		private void OnGUI()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_005c: Expected O, but got Unknown
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			if (activeConfigFileData != null)
			{
				Update();
				yamlWindowRect = new Rect(10f, 10f, (float)(Screen.width - 20), (float)(Screen.height - 20));
				GUILayout.Window(-669, yamlWindowRect, new WindowFunction(yamlWindowDrawer), "Backpacks YAML Editor", Array.Empty<GUILayoutOption>());
			}
		}

		private void yamlWindowDrawer(int id)
		{
			//IL_0016: 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_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Invalid comparison between Unknown and I4
			//IL_0564: Unknown result type (might be due to invalid IL or missing references)
			//IL_057c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0581: Unknown result type (might be due to invalid IL or missing references)
			//IL_059d: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c3: Expected O, but got Unknown
			//IL_05c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_034a: Unknown result type (might be due to invalid IL or missing references)
			//IL_034f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: 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_0380: Expected O, but got Unknown
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Invalid comparison between Unknown and I4
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Invalid comparison between Unknown and I4
			//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Expected O, but got Unknown
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Invalid comparison between Unknown and I4
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Invalid comparison between Unknown and I4
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Invalid comparison between Unknown and I4
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Expected O, but got Unknown
			GUI.Box(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), (Texture)(object)Texture2D.blackTexture);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUI.enabled = !hasErrors && (!configSync.IsLocked || configSync.IsSourceOfTruth);
			if (GUILayout.Button(Localization.instance.Localize("$bp_config_editor_save"), Array.Empty<GUILayoutOption>()) && !hasErrors)
			{
				save();
				activeConfigFileData = null;
			}
			if (configSync.IsSourceOfTruth && GUILayout.Button(Localization.instance.Localize("$bp_config_editor_apply"), Array.Empty<GUILayoutOption>()) && !hasErrors)
			{
				ConfigLoader.SkipSavingOfValueChange = true;
				save();
				ConfigLoader.SkipSavingOfValueChange = false;
				activeConfigFileData = null;
			}
			GUI.enabled = true;
			if (GUILayout.Button(Localization.instance.Localize("$bp_config_editor_discard"), Array.Empty<GUILayoutOption>()))
			{
				activeConfigFileData = null;
			}
			GUILayout.EndHorizontal();
			hasErrors = false;
			string text = "";
			foreach (string item in currentYamlInput.Keys.ToList())
			{
				bool flag = GUI.GetNameOfFocusedControl() == "Backpacks yaml textarea for " + item;
				if (flag)
				{
					EventType type = Event.current.type;
					bool flag2 = type - 4 <= 1;
					flag = flag2;
				}
				if (flag && Event.current.isKey)
				{
					if ((int)Event.current.keyCode == 9 || Event.current.character == '\t')
					{
						if ((int)Event.current.type == 5)
						{
							TextEditor val = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
							val.Insert(' ');
							val.Insert(' ');
							currentYamlInput[item] = val.text;
						}
						Event.current.Use();
					}
					if ((int)Event.current.keyCode == 271 || (int)Event.current.keyCode == 13 || Event.current.character == '\n')
					{
						if ((int)Event.current.type == 5)
						{
							TextEditor val2 = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
							string text2 = val2.text;
							int num = val2.cursorIndex;
							if (num > 0)
							{
								while (text2[num - 1] != '\n' && --num > 0)
								{
								}
							}
							int num2 = num;
							if (num2 < text2.Length && text2[num2] == ' ')
							{
								while (true)
								{
									if (num2 >= text2.Length || text2[num2] == '\n')
									{
										num2 = num;
										break;
									}
									if (text2[num2] != ' ')
									{
										break;
									}
									num2++;
								}
							}
							if (num2 > val2.cursorIndex)
							{
								num2 = num;
							}
							val2.Insert('\n');
							for (int num3 = num2 - num; num3 > 0; num3--)
							{
								val2.Insert(' ');
							}
							currentYamlInput[item] = val2.text;
						}
						Event.current.Use();
					}
				}
				if (currentYamlInput.Count > 1)
				{
					GUILayout.BeginVertical(GUI.skin.box, Array.Empty<GUILayoutOption>());
					if (GUILayout.Button(Path.GetFileName(item), new GUIStyle(GUI.skin.label)
					{
						alignment = (TextAnchor)1,
						wordWrap = true,
						stretchWidth = true,
						fontSize = 15
					}, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) }))
					{
						collapsed[item] = !collapsed[item];
					}
				}
				else
				{
					collapsed[item] = false;
				}
				if (!collapsed[item])
				{
					yamlTextareaScrollPosition[item] = GUILayout.BeginScrollView(yamlTextareaScrollPosition[item], (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandHeight(true) });
					GUI.SetNextControlName("Backpacks yaml textarea for " + item);
					currentYamlInput[item] = GUILayout.TextArea(currentYamlInput[item], (GUILayoutOption[])(object)new GUILayoutOption[2]
					{
						GUILayout.ExpandWidth(true),
						GUILayout.ExpandHeight(true)
					});
					GUILayout.EndScrollView();
				}
				if (currentYamlInput.Count > 1)
				{
					GUILayout.EndVertical();
				}
				try
				{
					object arg = new DeserializerBuilder().Build().Deserialize<object>(currentYamlInput[item]);
					List<string> list = configChecker(arg);
					if (list.Count > 0)
					{
						hasErrors = true;
						text = text + "There are errors in your " + Path.GetFileName(item) + " config:\n" + string.Join("\n", list) + "\n";
					}
				}
				catch (YamlException ex)
				{
					hasErrors = true;
					text = text + "The syntax of your " + Path.GetFileName(item) + " config is invalid, parsing failed:\n" + ex.Message + ((ex.InnerException != null) ? (": " + ex.InnerException.Message) : "") + "\n";
				}
			}
			GUILayout.BeginVertical(GUI.skin.box, Array.Empty<GUILayoutOption>());
			yamlErrorsScrollPosition = GUILayout.BeginScrollView(yamlErrorsScrollPosition, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(100f) });
			if (text != "")
			{
				GUIStyle val3 = new GUIStyle(GUI.skin.label);
				val3.normal.textColor = new Color(200f, 50f, 50f);
				GUIStyle val4 = val3;
				Color contentColor = GUI.contentColor;
				GUI.contentColor = new Color(200f, 50f, 50f);
				GUILayout.Label(text, val4, Array.Empty<GUILayoutOption>());
				GUI.contentColor = contentColor;
			}
			else
			{
				GUILayout.Label("Configuration syntax is valid.", Array.Empty<GUILayoutOption>());
			}
			GUILayout.EndScrollView();
			GUILayout.EndVertical();
			void save()
			{
				activeConfigFileData.Value = currentYamlInput.SelectMany([<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(0)] (KeyValuePair<string, string> kv) => new string[2] { kv.Key, kv.Value }).ToList();
			}
		}
	}
	public class Visual
	{
		[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(0)]
		[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
		[HarmonyPatch(typeof(Humanoid), "UpdateEquipmentStatusEffects")]
		private static class ApplyStatusEffects
		{
			private static void CollectEffects(Humanoid humanoid, [<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(new byte[] { 1, 2 })] HashSet<StatusEffect> statusEffects)
			{
				Player val = (Player)(object)((humanoid is Player) ? humanoid : null);
				if (val != null && visuals.TryGetValue(((Humanoid)val).m_visEquipment, out var value))
				{
					StatusEffect val2 = value.equippedBackpackItem?.m_shared.m_equipStatusEffect;
					if (val2 != null)
					{
						statusEffects.Add(val2);
					}
					if (humanoid.HaveSetEffect(value.equippedBackpackItem))
					{
						statusEffects.Add(value.equippedBackpackItem.m_shared.m_equipStatusEffect);
					}
				}
			}

			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructionsEnumerable)
			{
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_001d: Expected O, but got Unknown
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_002b: Expected O, but got Unknown
				//IL_0048: Unknown result type (might be due to invalid IL or missing references)
				//IL_004e: Expected O, but got Unknown
				List<CodeInstruction> list = instructionsEnumerable.ToList();
				list.InsertRange(2, (IEnumerable<CodeInstruction>)(object)new CodeInstruction[3]
				{
					new CodeInstruction(OpCodes.Ldarg_0, (object)null),
					new CodeInstruction(OpCodes.Ldloc_0, (object)null),
					new CodeInstruction(OpCodes.Call, (object)AccessTools.DeclaredMethod(typeof(ApplyStatusEffects), "CollectEffects", (Type[])null, (Type[])null))
				});
				return list;
			}
		}

		[HarmonyPatch(typeof(ItemData), "IsEquipable")]
		private static class IsEquipable
		{
			[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
			private static void Postfix(ItemData __instance, ref bool __result)
			{
				ItemContainer itemContainer = __instance.Data().Get<ItemContainer>();
				if (itemContainer != null && itemContainer.IsEquipable())
				{
					__result = true;
				}
			}
		}

		[HarmonyPatch(typeof(Humanoid), "IsItemEquiped")]
		private static class IsItemEquiped
		{
			[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
			private static void Postfix(Humanoid __instance, ItemData item, ref bool __result)
			{
				Player val = (Player)(object)((__instance is Player) ? __instance : null);
				if (val != null && visuals.TryGetValue(((Humanoid)val).m_visEquipment, out var value) && value.equippedBackpackItem == item)
				{
					__result = true;
				}
			}
		}

		[HarmonyPatch(typeof(Player), "Awake")]
		private static class AddVisual
		{
			[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
			[HarmonyPriority(800)]
			private static void Prefix(Player __instance)
			{
				visuals.Add(((Component)__instance).GetComponent<VisEquipment>(), new Visual(((Component)__instance).GetComponent<VisEquipment>()));
			}
		}

		[HarmonyPatch(typeof(VisEquipment), "OnEnable")]
		private static class AddVisualOnEnable
		{
			[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
			private static void Postfix(VisEquipment __instance)
			{
				if (!visuals.ContainsKey(__instance) && __instance.m_isPlayer)
				{
					visuals[__instance] = new Visual(__instance);
				}
			}
		}

		[HarmonyPatch(typeof(VisEquipment), "OnDisable")]
		private static class RemoveVisualOnDisable
		{
			[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
			private static void Postfix(VisEquipment __instance)
			{
				visuals.Remove(__instance);
			}
		}

		[HarmonyPatch(typeof(Humanoid), "SetupVisEquipment")]
		private static class SetupVisEquipment
		{
			[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
			private static void Prefix(Humanoid __instance)
			{
				Player val = (Player)(object)((__instance is Player) ? __instance : null);
				if (val != null && visuals.TryGetValue(((Humanoid)val).m_visEquipment, out var value))
				{
					value.setBackpackItem((value.equippedBackpackItem == null) ? "" : ((Object)value.equippedBackpackItem.m_dropPrefab).name);
				}
			}
		}

		[HarmonyPatch(typeof(Humanoid), "UnequipAllItems")]
		private static class UnequipAllItems
		{
			[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
			private static void Prefix(Humanoid __instance)
			{
				Player val = (Player)(object)((__instance is Player) ? __instance : null);
				if (val != null)
				{
					((Humanoid)val).UnequipItem(visuals[((Humanoid)val).m_visEquipment].equippedBackpackItem, false);
				}
			}
		}

		[HarmonyPatch(typeof(VisEquipment), "UpdateEquipmentVisuals")]
		private static class UpdateEquipmentVisuals
		{
			[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
			private static void Postfix(VisEquipment __instance)
			{
				if (__instance.m_isPlayer)
				{
					visuals[__instance].updateEquipmentVisuals();
				}
			}
		}

		[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
		[HarmonyPatch(typeof(Humanoid), "EquipItem")]
		[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(0)]
		private static class EquipItem
		{
			private static void Equip(Humanoid humanoid, ItemData item, bool triggerEquipmentEffects)
			{
				Player val = (Player)(object)((humanoid is Player) ? humanoid : null);
				if (val != null)
				{
					ItemContainer itemContainer = item.Data().Get<ItemContainer>();
					if (itemContainer != null && itemContainer.IsEquipable())
					{
						((Humanoid)val).UnequipItem(visuals[((Humanoid)val).m_visEquipment].equippedBackpackItem, triggerEquipmentEffects);
						visuals[((Humanoid)val).m_visEquipment].equippedBackpackItem = item;
					}
				}
			}

			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructionEnumerable)
			{
				//IL_0058: Unknown result type (might be due to invalid IL or missing references)
				//IL_005d: Unknown result type (might be due to invalid IL or missing references)
				//IL_006a: Expected O, but got Unknown
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				//IL_0078: Expected O, but got Unknown
				//IL_0080: Unknown result type (might be due to invalid IL or missing references)
				//IL_0086: Expected O, but got Unknown
				//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a9: Expected O, but got Unknown
				MethodInfo itemEquipped = AccessTools.DeclaredMethod(typeof(Humanoid), "IsItemEquiped", (Type[])null, (Type[])null);
				List<CodeInstruction> list = instructionEnumerable.ToList();
				int num = list.FindLastIndex((CodeInstruction instruction) => CodeInstructionExtensions.Calls(instruction, itemEquipped));
				CodeInstruction val = list[num - 2];
				list.InsertRange(num - 2, (IEnumerable<CodeInstruction>)(object)new CodeInstruction[4]
				{
					new CodeInstruction(OpCodes.Ldarg_0, (object)null)
					{
						labels = val.labels
					},
					new CodeInstruction(OpCodes.Ldarg_1, (object)null),
					new CodeInstruction(OpCodes.Ldarg_2, (object)null),
					new CodeInstruction(OpCodes.Call, (object)AccessTools.DeclaredMethod(typeof(EquipItem), "Equip", (Type[])null, (Type[])null))
				});
				val.labels = new List<Label>();
				return list;
			}
		}

		[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
		[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(0)]
		[HarmonyPatch(typeof(Humanoid), "UnequipItem")]
		private static class UnequipItem
		{
			private static void Unequip(Humanoid humanoid, ItemData item)
			{
				Player val = (Player)(object)((humanoid is Player) ? humanoid : null);
				if (val != null && visuals[((Humanoid)val).m_visEquipment].equippedBackpackItem == item)
				{
					visuals[((Humanoid)val).m_visEquipment].equippedBackpackItem = null;
				}
			}

			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructionEnumerable)
			{
				//IL_004e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0054: Expected O, but got Unknown
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: Expected O, but got Unknown
				//IL_007f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0085: Expected O, but got Unknown
				MethodInfo setupEquipment = AccessTools.DeclaredMethod(typeof(Humanoid), "SetupEquipment", (Type[])null, (Type[])null);
				List<CodeInstruction> list = instructionEnumerable.ToList();
				int num = list.FindIndex((CodeInstruction instruction) => CodeInstructionExtensions.Calls(instruction, setupEquipment));
				list.InsertRange(num - 1, (IEnumerable<CodeInstruction>)(object)new CodeInstruction[3]
				{
					new CodeInstruction(OpCodes.Ldarg_0, (object)null),
					new CodeInstruction(OpCodes.Ldarg_1, (object)null),
					new CodeInstruction(OpCodes.Call, (object)AccessTools.DeclaredMethod(typeof(UnequipItem), "Unequip", (Type[])null, (Type[])null))
				});
				return list;
			}
		}

		[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(1)]
		public static readonly Dictionary<VisEquipment, Visual> visuals = new Dictionary<VisEquipment, Visual>();

		[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(1)]
		private readonly VisEquipment visEquipment;

		[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(2)]
		public ItemData equippedBackpackItem;

		[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(1)]
		private string backpackItem = "";

		[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(1)]
		public List<GameObject> backpackItemInstances = new List<GameObject>();

		public int currentBackpackItemHash;

		[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
		private Visual(VisEquipment visEquipment)
		{
			this.visEquipment = visEquipment;
		}

		private void updateEquipmentVisuals()
		{
			ZDO zDO = visEquipment.m_nview.GetZDO();
			int backpackEquipped = ((zDO == null) ? ((!string.IsNullOrEmpty(backpackItem)) ? StringExtensionMethods.GetStableHashCode(backpackItem) : 0) : zDO.GetInt("BackpackItem", 0));
			if (setBackpackEquipped(backpackEquipped))
			{
				visEquipment.UpdateLodgroup();
			}
		}

		private bool setBackpackEquipped(int hash)
		{
			if (currentBackpackItemHash == hash)
			{
				return false;
			}
			return forceSetBackpackEquipped(hash);
		}

		public bool forceSetBackpackEquipped(int hash)
		{
			foreach (GameObject backpackItemInstance in backpackItemInstances)
			{
				Object.Destroy((Object)(object)backpackItemInstance);
			}
			backpackItemInstances.Clear();
			currentBackpackItemHash = hash;
			if (hash != 0 && Backpacks.hiddenBackpack.Value == Backpacks.Toggle.Off)
			{
				backpackItemInstances = visEquipment.AttachArmor(hash, -1);
			}
			Player component = ((Component)visEquipment).GetComponent<Player>();
			if (component != null)
			{
				API.InvokeEquippedBackpackUpdate(component);
			}
			return true;
		}

		[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
		private void setBackpackItem(string name)
		{
			if (!(backpackItem == name))
			{
				backpackItem = name;
				ZDO zDO = visEquipment.m_nview.GetZDO();
				if (zDO != null && visEquipment.m_nview.IsOwner())
				{
					zDO.Set("BackpackItem", (!string.IsNullOrEmpty(name)) ? StringExtensionMethods.GetStableHashCode(name) : 0);
				}
			}
		}
	}
	internal static class CustomContainer
	{
		[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
		[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(0)]
		[HarmonyPatch]
		public class AddFakeItemContainer
		{
			[CompilerGenerated]
			private sealed class <Transpiler>d__4 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IDisposable, IEnumerator
			{
				private int <>1__state;

				private CodeInstruction <>2__current;

				private int <>l__initialThreadId;

				[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(new byte[] { 0, 1 })]
				private IEnumerable<CodeInstruction> instructionsList;

				[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(new byte[] { 0, 1 })]
				public IEnumerable<CodeInstruction> <>3__instructionsList;

				[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(0)]
				private ILGenerator ilg;

				[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(0)]
				public ILGenerator <>3__ilg;

				[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(0)]
				private MethodInfo <containerInventory>5__2;

				[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(0)]
				private FieldInfo <containerField>5__3;

				[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(0)]
				private MethodInfo <objectInequality>5__4;

				[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(0)]
				private MethodInfo <objectEquality>5__5;

				[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(0)]
				private MethodInfo <objectImplicit>5__6;

				[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(new byte[] { 0, 1 })]
				private List<CodeInstruction> <instructions>5__7;

				private int <i>5__8;

				[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(0)]
				private CodeInstruction <instruction>5__9;

				private Label <onWeaponInv>5__10;

				private Label <onInventoryFetch>5__11;

				CodeInstruction IEnumerator<CodeInstruction>.Current
				{
					[DebuggerHidden]
					get
					{
						return <>2__current;
					}
				}

				object IEnumerator.Current
				{
					[DebuggerHidden]
					[return: <82400168-f14d-44ea-b34c-f7901dbae490>Nullable(0)]
					get
					{
						return <>2__current;
					}
				}

				[DebuggerHidden]
				public <Transpiler>d__4(int <>1__state)
				{
					this.<>1__state = <>1__state;
					<>l__initialThreadId = Environment.CurrentManagedThreadId;
				}

				[DebuggerHidden]
				void IDisposable.Dispose()
				{
					<containerInventory>5__2 = null;
					<containerField>5__3 = null;
					<objectInequality>5__4 = null;
					<objectEquality>5__5 = null;
					<objectImplicit>5__6 = null;
					<instructions>5__7 = null;
					<instruction>5__9 = null;
					<>1__state = -2;
				}

				private bool MoveNext()
				{
					//IL_0181: Unknown result type (might be due to invalid IL or missing references)
					//IL_018b: Expected O, but got Unknown
					//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
					//IL_01c7: Expected O, but got Unknown
					//IL_01de: Unknown result type (might be due to invalid IL or missing references)
					//IL_01e8: Expected O, but got Unknown
					//IL_0236: Unknown result type (might be due to invalid IL or missing references)
					//IL_0240: Expected O, but got Unknown
					//IL_026b: Unknown result type (might be due to invalid IL or missing references)
					//IL_0271: Expected O, but got Unknown
					//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
					//IL_03d1: Expected O, but got Unknown
					//IL_03e9: Unknown result type (might be due to invalid IL or missing references)
					//IL_03f3: Expected O, but got Unknown
					//IL_04bc: Unknown result type (might be due to invalid IL or missing references)
					//IL_04c6: Expected O, but got Unknown
					//IL_04de: Unknown result type (might be due to invalid IL or missing references)
					//IL_04e8: Expected O, but got Unknown
					//IL_0500: Unknown result type (might be due to invalid IL or missing references)
					//IL_050a: Expected O, but got Unknown
					//IL_0160: Unknown result type (might be due to invalid IL or missing references)
					//IL_016a: Expected O, but got Unknown
					int num;
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<containerInventory>5__2 = AccessTools.DeclaredMethod(typeof(Container), "GetInventory", (Type[])null, (Type[])null);
						<containerField>5__3 = AccessTools.DeclaredField(typeof(InventoryGui), "m_currentContainer");
						<objectInequality>5__4 = AccessTools.DeclaredMethod(typeof(Object), "op_Inequality", (Type[])null, (Type[])null);
						<objectEquality>5__5 = AccessTools.DeclaredMethod(typeof(Object), "op_Equality", (Type[])null, (Type[])null);
						<objectImplicit>5__6 = AccessTools.DeclaredMethod(typeof(Object), "op_Implicit", (Type[])null, (Type[])null);
						<instructions>5__7 = instructionsList.ToList();
						<i>5__8 = 0;
						break;
					case 1:
						<>1__state = -1;
						<>2__current = new CodeInstruction(OpCodes.Dup, (object)null);
						<>1__state = 2;
						return true;
					case 2:
						<>1__state = -1;
						<onWeaponInv>5__10 = ilg.DefineLabel();
						<>2__current = new CodeInstruction(OpCodes.Brtrue, (object)<onWeaponInv>5__10);
						<>1__state = 3;
						return true;
					case 3:
						<>1__state = -1;
						<>2__current = new CodeInstruction(OpCodes.Pop, (object)null);
						<>1__state = 4;
						return true;
					case 4:
						<>1__state = -1;
						<>2__current = <instruction>5__9;
						<>1__state = 5;
						return true;
					case 5:
						<>1__state = -1;
						<onInventoryFetch>5__11 = ilg.DefineLabel();
						<>2__current = new CodeInstruction(OpCodes.Br, (object)<onInventoryFetch>5__11);
						<>1__state = 6;
						return true;
					case 6:
					{
						<>1__state = -1;
						CodeInstruction val = new CodeInstruction(OpCodes.Call, (object)AccessTools.DeclaredMethod(typeof(AddFakeItemContainer), "PopSecondValue", (Type[])null, (Type[])null));
						val.labels.Add(<onWeaponInv>5__10);
						<>2__current = val;
						<>1__state = 7;
						return true;
					}
					case 7:
						<>1__state = -1;
						<instructions>5__7[<i>5__8 + 1].labels.Add(<onInventoryFetch>5__11);
						goto IL_053a;
					case 8:
						<>1__state = -1;
						<>2__current = new CodeInstruction(OpCodes.Call, (object)AccessTools.DeclaredMethod(typeof(AddFakeItemContainer), "IsOpenInventory", (Type[])null, (Type[])null));
						<>1__state = 9;
						return true;
					case 9:
						<>1__state = -1;
						<>2__current = new CodeInstruction(OpCodes.Or, (object)null);
						<>1__state = 10;
						return true;
					case 10:
						<>1__state = -1;
						goto IL_053a;
					case 11:
						<>1__state = -1;
						<>2__current = new CodeInstruction(OpCodes.Call, (object)AccessTools.DeclaredMethod(typeof(AddFakeItemContainer), "IsOpenInventory", (Type[])null, (Type[])null));
						<>1__state = 12;
						return true;
					case 12:
						<>1__state = -1;
						<>2__current = new CodeInstruction(OpCodes.Not, (object)null);
						<>1__state = 13;
						return true;
					case 13:
						<>1__state = -1;
						<>2__current = new CodeInstruction(OpCodes.And, (object)null);
						<>1__state = 14;
						return true;
					case 14:
						<>1__state = -1;
						goto IL_053a;
					case 15:
						{
							<>1__state = -1;
							goto IL_053a;
						}
						IL_053a:
						<instruction>5__9 = null;
						num = <i>5__8 + 1;
						<i>5__8 = num;
						break;
					}
					if (<i>5__8 < <instructions>5__7.Count)
					{
						<instruction>5__9 = <instructions>5__7[<i>5__8];
						if (<instruction>5__9.opcode == OpCodes.Callvirt && CodeInstructionExtensions.OperandIs(<instruction>5__9, (MemberInfo)<containerInventory>5__2))
						{
							<>2__current = new CodeInstruction(OpCodes.Call, (object)AccessTools.DeclaredMethod(typeof(AddFakeItemContainer), "GetOpenInventory", (Type[])null, (Type[])null));
							<>1__state = 1;
							return true;
						}
						if (<instruction>5__9.opcode == OpCodes.Call && ((CodeInstructionExtensions.OperandIs(<instruction>5__9, (MemberInfo)<objectInequality>5__4) && <instructions>5__7[<i>5__8 - 2].opcode == OpCodes.Ldfld && CodeInstructionExtensions.OperandIs(<instructions>5__7[<i>5__8 - 2], (MemberInfo)<containerField>5__3)) || (CodeInstructionExtensions.OperandIs(<instruction>5__9, (MemberInfo)<objectImplicit>5__6) && <instructions>5__7[<i>5__8 - 1].opcode == OpCodes.Ldfld && CodeInstructionExtensions.OperandIs(<instructions>5__7[<i>5__8 - 1], (MemberInfo)<containerField>5__3))))
						{
							<>2__current = <instruction>5__9;
							<>1__state = 8;
							return true;
						}
						if (<instruction>5__9.opcode == OpCodes.Call && CodeInstructionExtensions.OperandIs(<instruction>5__9, (MemberInfo)<objectEquality>5__5) && <instructions>5__7[<i>5__8 - 2].opcode == OpCodes.Ldfld && CodeInstructionExtensions.OperandIs(<instructions>5__7[<i>5__8 - 2], (MemberInfo)<containerField>5__3))
						{
							<>2__current = <instruction>5__9;
							<>1__state = 11;
							return true;
						}
						<>2__current = <instruction>5__9;
						<>1__state = 15;
						return true;
					}
					return false;
				}

				bool IEnumerator.MoveNext()
				{
					//ILSpy generated this explicit interface implementation from .override directive in MoveNext
					return this.MoveNext();
				}

				[DebuggerHidden]
				void IEnumerator.Reset()
				{
					throw new NotSupportedException();
				}

				[DebuggerHidden]
				[return: <82400168-f14d-44ea-b34c-f7901dbae490>Nullable(0)]
				IEnumerator<CodeInstruction> IEnumerable<CodeInstruction>.GetEnumerator()
				{
					<Transpiler>d__4 <Transpiler>d__;
					if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
					{
						<>1__state = 0;
						<Transpiler>d__ = this;
					}
					else
					{
						<Transpiler>d__ = new <Transpiler>d__4(0);
					}
					<Transpiler>d__.instructionsList = <>3__instructionsList;
					<Transpiler>d__.ilg = <>3__ilg;
					return <Transpiler>d__;
				}

				[DebuggerHidden]
				[return: <82400168-f14d-44ea-b34c-f7901dbae490>Nullable(0)]
				IEnumerator IEnumerable.GetEnumerator()
				{
					return ((IEnumerable<CodeInstruction>)this).GetEnumerator();
				}
			}

			[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(2)]
			private static Inventory GetOpenInventory()
			{
				return OpenContainer?.Inventory;
			}

			private static bool IsOpenInventory()
			{
				return OpenContainer != null;
			}

			private static Inventory PopSecondValue(object _, Inventory inventory)
			{
				return inventory;
			}

			private static IEnumerable<MethodInfo> TargetMethods()
			{
				return new MethodInfo[5]
				{
					AccessTools.DeclaredMethod(typeof(InventoryGui), "OnTakeAll", (Type[])null, (Type[])null),
					AccessTools.DeclaredMethod(typeof(InventoryGui), "OnStackAll", (Type[])null, (Type[])null),
					AccessTools.DeclaredMethod(typeof(InventoryGui), "OnSelectedItem", (Type[])null, (Type[])null),
					AccessTools.DeclaredMethod(typeof(InventoryGui), "IsContainerOpen", (Type[])null, (Type[])null),
					AccessTools.DeclaredMethod(typeof(InventoryGui), "UpdateContainerWeight", (Type[])null, (Type[])null)
				};
			}

			[IteratorStateMachine(typeof(<Transpiler>d__4))]
			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructionsList, ILGenerator ilg)
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <Transpiler>d__4(-2)
				{
					<>3__instructionsList = instructionsList,
					<>3__ilg = ilg
				};
			}
		}

		[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(0)]
		[HarmonyPatch]
		[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
		private class CloseFakeItemContainer
		{
			private static IEnumerable<MethodInfo> TargetMethods()
			{
				return new MethodInfo[2]
				{
					AccessTools.DeclaredMethod(typeof(InventoryGui), "Hide", (Type[])null, (Type[])null),
					AccessTools.DeclaredMethod(typeof(InventoryGui), "CloseContainer", (Type[])null, (Type[])null)
				};
			}

			public static void Prefix(InventoryGui __instance)
			{
				ItemContainer openContainer = OpenContainer;
				if (openContainer != null)
				{
					((Component)__instance.m_takeAllButton).gameObject.SetActive(true);
					((Component)__instance.m_stackAllButton).gameObject.SetActive(true);
					containerCloseContainer.SetActive(false);
					openContainer.Close();
					Inventory inventory = openContainer.Inventory;
					inventory.m_onChanged = (Action)Delegate.Remove(inventory.m_onChanged, new Action(SaveItemContainer));
					OpenContainer = null;
				}
			}
		}

		[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(0)]
		[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
		[HarmonyPatch(typeof(InventoryGui), "UpdateContainer")]
		public class OpenFakeItemsContainer
		{
			public static bool Open(InventoryGui invGui, [<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(2)] ItemData item)
			{
				ItemContainer itemContainer = (item?.Data())?.Get<ItemContainer>();
				if (itemContainer != null)
				{
					if (invGui.IsContainerOpen())
					{
						invGui.CloseContainer();
					}
					if (!itemContainer.Open())
					{
						return true;
					}
					OpenContainer = itemContainer;
					Inventory inventory = itemContainer.Inventory;
					inventory.m_onChanged = (Action)Delegate.Combine(inventory.m_onChanged, new Action(SaveItemContainer));
					if (!itemContainer.ShowTakeAllButton())
					{
						((Component)invGui.m_takeAllButton).gameObject.SetActive(false);
					}
				}
				if (OpenContainer != null)
				{
					ItemData item2 = OpenContainer.Item;
					if (invGui.m_playerGrid.GetInventory().GetItemAt(item2.m_gridPos.x, item2.m_gridPos.y) != item2)
					{
						invGui.CloseContainer();
						return true;
					}
					((Component)invGui.m_stackAllButton).gameObject.SetActive(OpenContainer.AllowStacking());
					((Component)invGui.m_container).gameObject.SetActive(true);
					containerCloseContainer.SetActive(true);
					invGui.m_containerGrid.UpdateInventory(OpenContainer.Inventory, (Player)null, invGui.m_dragItem);
					invGui.m_containerName.text = OpenContainer.GetContainerTitle();
					if (invGui.m_firstContainerUpdate)
					{
						invGui.m_containerGrid.ResetView();
						invGui.m_firstContainerUpdate = false;
					}
					return false;
				}
				return true;
			}

			private static bool Prefix(InventoryGui __instance)
			{
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0042: 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_0054: Unknown result type (might be due to invalid IL or missing references)
				//IL_005f: Unknown result type (might be due to invalid IL or missing references)
				if (OpenContainer != null && !OpenContainer.AllowStacking())
				{
					__instance.m_containerHoldTime = 0f;
				}
				ItemData val = null;
				if (ZInput.GetButton("Use") || ZInput.GetButton("JoyUse"))
				{
					Vector2 val2 = Vector2.op_Implicit(Input.mousePosition);
					val = __instance.m_playerGrid.GetItem(new Vector2i(Mathf.RoundToInt(val2.x), Mathf.RoundToInt(val2.y)));
					ItemContainer itemContainer = val?.Data().Get<ItemContainer>();
					if (itemContainer == null || !itemContainer.AllowOpeningByKeypress())
					{
						return true;
					}
				}
				return Open(__instance, val);
			}
		}

		[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
		[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(0)]
		[HarmonyPatch(typeof(InventoryGui), "Update")]
		private class CatchInventoryUseButton
		{
			[CompilerGenerated]
			private sealed class <Transpiler>d__1 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IDisposable, IEnumerator
			{
				private int <>1__state;

				private CodeInstruction <>2__current;

				private int <>l__initialThreadId;

				[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(new byte[] { 0, 1 })]
				private IEnumerable<CodeInstruction> instructionsList;

				[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(new byte[] { 0, 1 })]
				public IEnumerable<CodeInstruction> <>3__instructionsList;

				[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(new byte[] { 0, 1 })]
				private List<CodeInstruction> <instructions>5__2;

				[<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(0)]
				private MethodInfo <buttonReset>5__3;

				private bool <first>5__4;

				private int <i>5__5;

				private Label? <target>5__6;

				CodeInstruction IEnumerator<CodeInstruction>.Current
				{
					[DebuggerHidden]
					get
					{
						return <>2__current;
					}
				}

				object IEnumerator.Current
				{
					[DebuggerHidden]
					[return: <82400168-f14d-44ea-b34c-f7901dbae490>Nullable(0)]
					get
					{
						return <>2__current;
					}
				}

				[DebuggerHidden]
				public <Transpiler>d__1(int <>1__state)
				{
					this.<>1__state = <>1__state;
					<>l__initialThreadId = Environment.CurrentManagedThreadId;
				}

				[DebuggerHidden]
				void IDisposable.Dispose()
				{
					<instructions>5__2 = null;
					<buttonReset>5__3 = null;
					<>1__state = -2;
				}

				private bool MoveNext()
				{
					//IL_0141: Unknown result type (might be due to invalid IL or missing references)
					//IL_014b: Expected O, but got Unknown
					//IL_0171: Unknown result type (might be due to invalid IL or missing references)
					//IL_017b: Expected O, but got Unknown
					//IL_010b: Unknown result type (might be due to invalid IL or missing references)
					//IL_0115: Expected O, but got Unknown
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<instructions>5__2 = instructionsList.ToList();
						<buttonReset>5__3 = AccessTools.DeclaredMethod(typeof(ZInput), "ResetButtonStatus", (Type[])null, (Type[])null);
						<first>5__4 = true;
						<i>5__5 = 0;
						goto IL_01c2;
					case 1:
						<>1__state = -1;
						<>2__current = new CodeInstruction(OpCodes.Call, (object)AccessTools.DeclaredMethod(typeof(CatchInventoryUseButton), "ShallPreventInventoryClose", (Type[])null, (Type[])null));
						<>1__state = 2;
						return true;
					case 2:
						<>1__state = -1;
						<>2__current = new CodeInstruction(OpCodes.Brtrue, (object)<target>5__6.Value);
						<>1__state = 3;
						return true;
					case 3:
						<>1__state = -1;
						goto IL_018b;
					case 4:
						{
							<>1__state = -1;
							int num = <i>5__5 + 1;
							<i>5__5 = num;
							goto IL_01c2;
						}
						IL_01c2:
						if (<i>5__5 < <instructions>5__2.Count)
						{
							if (<first>5__4 && <i>5__5 + 1 < <instructions>5__2.Count && <instructions>5__2[<i>5__5 + 1].opcode == OpCodes.Call && CodeInstructionExtensions.OperandIs(<instructions>5__2[<i>5__5 + 1], (MemberInfo)<buttonReset>5__3))
							{
								<first>5__4 = false;
								int num2 = <i>5__5;
								while (!CodeInstructionExtensions.Branches(<instructions>5__2[num2], ref <target>5__6))
								{
									num2--;
								}
								<>2__current = new CodeInstruction(OpCodes.Ldarg_0, (object)null);
								<>1__state = 1;
								return true;
							}
							goto IL_018b;
						}
						return false;
						IL_018b:
						<>2__current = <instructions>5__2[<i>5__5];
						<>1__state = 4;
						return true;
					}
				}

				bool IEnumerator.MoveNext()
				{
					//ILSpy generated this explicit interface implementation from .override directive in MoveNext
					return this.MoveNext();
				}

				[DebuggerHidden]
				void IEnumerator.Reset()
				{
					throw new NotSupportedException();
				}

				[DebuggerHidden]
				[return: <82400168-f14d-44ea-b34c-f7901dbae490>Nullable(0)]
				IEnumerator<CodeInstruction> IEnumerable<CodeInstruction>.GetEnumerator()
				{
					<Transpiler>d__1 <Transpiler>d__;
					if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
					{
						<>1__state = 0;
						<Transpiler>d__ = this;
					}
					else
					{
						<Transpiler>d__ = new <Transpiler>d__1(0);
					}
					<Transpiler>d__.instructionsList = <>3__instructionsList;
					return <Transpiler>d__;
				}

				[DebuggerHidden]
				[return: <82400168-f14d-44ea-b34c-f7901dbae490>Nullable(0)]
				IEnumerator IEnumerable.GetEnumerator()
				{
					return ((IEnumerable<CodeInstruction>)this).GetEnumerator();
				}
			}

			private static bool ShallPreventInventoryClose(InventoryGui invGui)
			{
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_004a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0051: 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_0067: 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)
				if (ZInput.GetButton("Use") || ZInput.GetButton("JoyUse"))
				{
					if (Backpacks.preventInventoryClosing.Value == Backpacks.Toggle.On)
					{
						return RectTransformUtility.RectangleContainsScreenPoint(invGui.m_playerGrid.m_gridRoot, Vector2.op_Implicit(Input.mousePosition));
					}
					Vector2 val = Vector2.op_Implicit(Input.mousePosition);
					return invGui.m_playerGrid.GetItem(new Vector2i(Mathf.RoundToInt(val.x), Mathf.RoundToInt(val.y)))?.Data().Get<ItemContainer>() != null;
				}
				return false;
			}

			[IteratorStateMachine(typeof(<Transpiler>d__1))]
			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructionsList)
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <Transpiler>d__1(-2)
				{
					<>3__instructionsList = instructionsList
				};
			}
		}

		[HarmonyPatch(typeof(InventoryGrid), "DropItem")]
		private class RestrictItemContainerItems
		{
			[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
			private static bool Prefix(InventoryGrid __instance, Inventory fromInventory, ItemData item, ref int amount, Vector2i pos, ref bool __result)
			{
				//IL_00df: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
				//IL_004c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0053: Unknown result type (might be due to invalid IL or missing references)
				//IL_0156: Unknown result type (might be due to invalid IL or missing references)
				//IL_015b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0166: Unknown result type (might be due to invalid IL or missing references)
				//IL_016c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0096: Unknown result type (might be due to invalid IL or missing references)
				//IL_009b: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
				if (__instance.m_inventory != OpenContainer?.Inventory)
				{
					if (fromInventory == OpenContainer?.Inventory)
					{
						if (!OpenContainer.CanRemoveItem(item))
						{
							__result = false;
							return false;
						}
						ItemData itemAt = __instance.m_inventory.GetItemAt(pos.x, pos.y);
						if (itemAt != null && itemAt != item)
						{
							if (!OpenContainer.CanAddItemManually(itemAt))
							{
								__result = false;
								return false;
							}
							if (!OpenContainer.AllowStacking() && itemAt.m_stack > 1)
							{
								Vector2i val = __instance.m_inventory.FindEmptySlot(false);
								if (!__instance.m_inventory.AddItem(itemAt, itemAt.m_stack - 1, val.x, val.y))
								{
									__result = false;
									return false;
								}
							}
						}
						if (!OpenContainer.RemoveItem(item))
						{
							__result = false;
							return false;
						}
					}
					return true;
				}
				ItemData itemAt2 = __instance.m_inventory.GetItemAt(pos.x, pos.y);
				if (itemAt2 == item)
				{
					return true;
				}
				if (itemAt2 != null && fromInventory != __instance.GetInventory() && !OpenContainer.CanRemoveItem(itemAt2))
				{
					__result = false;
					return false;
				}
				if (!OpenContainer.CanAddItemManually(item))
				{
					__result = false;
					return false;
				}
				if (itemAt2 != null && fromInventory != __instance.GetInventory())
				{
					OpenContainer.RemoveItem(itemAt2);
				}
				if (!OpenContainer.AllowStacking() && amount > 1)
				{
					Vector2i val2 = fromInventory.FindEmptySlot(false);
					fromInventory.AddItem(item, item.m_stack - 1, val2.x, val2.y);
					amount = 1;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(InventoryGui), "OnSelectedItem")]
		private class RestrictMovingItems
		{
			[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
			private static bool Prefix(InventoryGrid grid, [<82400168-f14d-44ea-b34c-f7901dbae490>Nullable(2)] ref ItemData item, Modifier mod)
			{
				//IL_0004: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Invalid comparison between Unknown and I4
				//IL_0059: Unknown result type (might be due to invalid IL or missing references)
				//IL_005b: Invalid comparison between Unknown and I4
				//IL_00a8: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
				if (item != null && (int)mod == 2 && OpenContainer?.Inventory == grid.m_inventory)
				{
					if (!OpenContainer.CanRemoveItem(item))
					{
						return false;
					}
					if (!OpenContainer.RemoveItem(item))
					{
						grid.m_inventory.RemoveItem(item);
						item = null;
					}
				}
				else if (item != null && (int)mod == 2)
				{
					Inventory val = OpenContainer?.Inventory;
					if (val != null && val != grid.m_inventory)
					{
						if (!OpenContainer.CanAddItemManually(item))
						{
							return false;
						}
						if (!OpenContainer.AllowStacking() && item.m_stack > 1)
						{
							Vector2i val2 = grid.m_inventory.FindEmptySlot(false);
							return grid.m_inventory.AddItem(item, item.m_stack - 1, val2.x, val2.y);
						}
					}
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Humanoid), "DropItem")]
		private static class RestrictThrowingItemContainerItemsOnGround
		{
			[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
			private static bool Prefix(ref bool __result, Inventory inventory, ItemData item)
			{
				if (inventory == OpenContainer?.Inventory && (!OpenContainer.CanRemoveItem(item) || !OpenContainer.RemoveItem(item)))
				{
					__result = false;
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(ItemData), "GetWeight")]
		private static class IncreaseWeightByContainerContents
		{
			[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
			private static void Postfix(ItemData __instance, ref float __result)
			{
				ItemContainer itemContainer = __instance.Data().Get<ItemContainer>();
				if (itemContainer != null)
				{
					__result += itemContainer.Inventory.GetTotalWeight() * itemContainer.WeightFactor();
				}
			}
		}

		[HarmonyPatch(typeof(InventoryGui), "Awake")]
		private static class AddPressKeyToOpenTooltip
		{
			private static bool Updated;

			[HarmonyPriority(100)]
			[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
			private static void Postfix(InventoryGui __instance)
			{
				//IL_0106: Unknown result type (might be due to invalid IL or missing references)
				//IL_010b: 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)
				//IL_0071: Unknown result type (might be due to invalid IL or missing references)
				//IL_0076: Unknown result type (might be due to invalid IL or missing references)
				//IL_0083: 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_01bb: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
				//IL_0205: Unknown result type (might be due to invalid IL or missing references)
				//IL_020f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0215: Expected O, but got Unknown
				//IL_021d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0227: Expected O, but got Unknown
				if (!Updated)
				{
					Updated = true;
					UITooltip component = __instance.m_playerGrid.m_elementPrefab.GetComponent<UITooltip>();
					((Component)component).gameObject.AddComponent<TooltipPressOpen>();
					Transform val = component.m_tooltipPrefab.transform.Find("Bkg");
					TextMeshProUGUI component2 = ((Component)((Component)val).transform.Find("Text")).GetComponent<TextMeshProUGUI>();
					GameObject val2 = new GameObject("PressToOpenItemContainer");
					val2.transform.SetParent(val);
					TextMeshProUGUI obj = val2.AddComponent<TextMeshProUGUI>();
					((TMP_Text)obj).font = ((TMP_Text)component2).font;
					((TMP_Text)obj).fontSize = ((TMP_Text)component2).fontSize;
					((TMP_Text)obj).alignment = (TextAlignmentOptions)514;
					ContentSizeFitter obj2 = val2.AddComponent<ContentSizeFitter>();
					obj2.horizontalFit = (FitMode)2;
					obj2.verticalFit = (FitMode)2;
					val2.SetActive(false);
				}
				Transform parent = __instance.m_containerWeight.transform.parent;
				containerCloseContainer = Object.Instantiate<GameObject>(((Component)parent).gameObject, parent.parent);
				Transform transform = containerCloseContainer.transform;
				Vector3 localPosition = containerCloseContainer.transform.localPosition;
				localPosition.y = -60f;
				transform.localPosition = localPosition;
				containerCloseContainer.SetActive(false);
				containerCloseContainer.transform.SetSiblingIndex(parent.GetSiblingIndex() + 1);
				for (int num = containerCloseContainer.transform.childCount - 1; num >= 0; num--)
				{
					Transform child = containerCloseContainer.transform.GetChild(num);
					if (((Object)child).name != "bkg")
					{
						Object.Destroy((Object)(object)((Component)child).gameObject);
					}
				}
				RectTransform component3 = Object.Instantiate<GameObject>(((Component)__instance.m_tabUpgrade).gameObject, containerCloseContainer.transform).GetComponent<RectTransform>();
				Vector2 sizeDelta = component3.sizeDelta;
				sizeDelta.x = component3.sizeDelta.y;
				component3.sizeDelta = sizeDelta;
				((TMP_Text)((Component)((Transform)component3).Find("Text")).GetComponent<TextMeshProUGUI>()).text = "X";
				((Transform)component3).localPosition = new Vector3(2f, 0f, 0f);
				ButtonClickedEvent val3 = new ButtonClickedEvent();
				((UnityEvent)val3).AddListener((UnityAction)delegate
				{
					CloseFakeItemContainer.Prefix(__instance);
				});
				((Component)component3).GetComponent<Button>().onClick = val3;
			}
		}

		[HarmonyPatch(typeof(UITooltip), "UpdateTextElements")]
		private static class SetPressKeyOnOpenTooltip
		{
			[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
			private static void Postfix(UITooltip __instance)
			{
				GameObject tooltip = UITooltip.m_tooltip;
				Transform val = ((tooltip != null) ? tooltip.transform.Find("Bkg/PressToOpenItemContainer") : null);
				if (val != null)
				{
					string text = ((Component)__instance).GetComponent<TooltipPressOpen>()?.text;
					if (text != null)
					{
						((TMP_Text)((Component)val).GetComponent<TextMeshProUGUI>()).text = text;
						((Component)val).gameObject.SetActive(true);
					}
					else
					{
						((Component)val).gameObject.SetActive(false);
					}
				}
			}
		}

		[HarmonyPatch(typeof(InventoryGrid), "CreateItemTooltip")]
		private static class SetPressOpenTooltipText
		{
			[<62f8cfdf-24c6-4a4e-93cb-eb1773b4b408>NullableContext(1)]
			private static void Prefix(ItemData item, UITooltip tooltip)
			{
				TooltipPressOpen component = ((Component)tooltip).GetComponent<TooltipPressOpen>();
				if (component != null)
				{
					component.text = item.D