Decompiled source of AdventureBackpacks v1.9.13

plugins/AdventureBackpacks.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Timers;
using APIManager;
using AdventureBackpacks.API;
using AdventureBackpacks.Assets;
using AdventureBackpacks.Assets.Effects;
using AdventureBackpacks.Assets.Factories;
using AdventureBackpacks.Assets.Items;
using AdventureBackpacks.Assets.Items.BackpackItems;
using AdventureBackpacks.Compats;
using AdventureBackpacks.Components;
using AdventureBackpacks.Configuration;
using AdventureBackpacks.Extensions;
using AdventureBackpacks.Features;
using AdventureBackpacks.Patches;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Preloader;
using BepInEx.Preloader.Patching;
using HarmonyLib;
using ItemManager;
using JetBrains.Annotations;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using Vapok.Common.Abstractions;
using Vapok.Common.Managers;
using Vapok.Common.Managers.Configuration;
using Vapok.Common.Managers.Creature;
using Vapok.Common.Managers.LocalizationManager;
using Vapok.Common.Managers.Location;
using Vapok.Common.Managers.PieceManager;
using Vapok.Common.Managers.Skill;
using Vapok.Common.Managers.StatusEffects;
using Vapok.Common.Shared;
using Vapok.Common.Tools;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("AdventureBackpacks")]
[assembly: AssemblyDescription("A Valheim Mod for adding progression multiple backpacks as an item/utility gear addition.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Vapok Gaming")]
[assembly: AssemblyProduct("AdventureBackpacks")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("997CB563-FCC7-44B7-8F71-069747D27CC5")]
[assembly: AssemblyFileVersion("1.9.13.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.9.13.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace AdventureBackpacks
{
	[BepInPlugin("vapok.mods.adventurebackpacks", "Adventure Backpacks", "1.9.13")]
	[BepInIncompatibility("JotunnBackpacks")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class AdventureBackpacks : BaseUnityPlugin, IPluginInfo
	{
		public class Waiting
		{
			public event EventHandler StatusChanged;

			public void ValheimIsAwake(bool awakeFlag)
			{
				if (awakeFlag)
				{
					this.StatusChanged?.Invoke(this, EventArgs.Empty);
				}
			}
		}

		private const string _pluginId = "vapok.mods.adventurebackpacks";

		private const string _displayName = "Adventure Backpacks";

		private const string _version = "1.9.13";

		public static bool ValheimAwake;

		public static bool PerformYardSale;

		public static bool QuickDropping;

		public static bool BypassMoveProtection;

		public static Waiting Waiter;

		private static AdventureBackpacks _instance;

		private static ConfigSyncBase _config;

		private static ILogIt _log;

		private Harmony _harmony;

		public string PluginId => "vapok.mods.adventurebackpacks";

		public string DisplayName => "Adventure Backpacks";

		public string Version => "1.9.13";

		public BaseUnityPlugin Instance => (BaseUnityPlugin)(object)_instance;

		public static ILogIt Log => _log;

		public static ConfigSyncBase ActiveConfig => _config;

		[UsedImplicitly]
		private void Awake()
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			_instance = this;
			Patcher.Patch(new string[1] { "AdventureBackpacks.API" });
			Waiter = new Waiting();
			CustomLocalization localization = LocalizationManager.Instance.GetLocalization();
			LogManager.Init(PluginId, out _log);
			Initializer.LoadManagers(localization, enableCreatureManager: false, enableItemManager: true, enableLocationManager: true, enableMaterialReplacer: true, enablePieceManager: false, enableSkillManager: false, enableEffectManager: true);
			_config = new ConfigRegistry(_instance);
			ItemManager.PrefabManager.Initalized = true;
			_harmony = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
			if (Chainloader.PluginInfos.ContainsKey("com.chebgonaz.ChebsNecromancy"))
			{
				ChebsNecromancy.SetupNecromancyBackpackUsingApi();
			}
			if (Chainloader.PluginInfos.ContainsKey("com.maxsch.valheim.contentswithin"))
			{
				ContentsWithin.Awake(_harmony, "com.maxsch.valheim.contentswithin");
			}
		}

		private void Start()
		{
			Localizer.Waiter.StatusChanged += InitializeBackpacks;
			QuickTransfer.FeatureInitialized = true;
		}

		private void Update()
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)Player.m_localPlayer) || !Object.op_Implicit((Object)(object)ZNetScene.instance))
			{
				return;
			}
			if (PerformYardSale)
			{
				BackpackComponent equippedBackpack = Player.m_localPlayer.GetEquippedBackpack();
				if (equippedBackpack != null)
				{
					Backpacks.PerformYardSale(Player.m_localPlayer, equippedBackpack.Item);
				}
			}
			if (ZInput.GetButton("Forward") || ZInput.GetButton("Backward") || ZInput.GetButton("Left") || ZInput.GetButton("Right"))
			{
				KeyboardShortcut value = ConfigRegistry.HotKeyDrop.Value;
				if (ZInput.GetKeyDown(((KeyboardShortcut)(ref value)).MainKey, true) && ConfigRegistry.OutwardMode.Value)
				{
					Player.m_localPlayer.QuickDropBackpack();
				}
			}
			EffectsFactory.Instance.ToggleEffects();
			InventoryPatches.ProcessItemsAddedQueue();
		}

		public void InitializeBackpacks(object send, EventArgs args)
		{
			if (!ValheimAwake)
			{
				new EffectsFactory(_log, _config).RegisterEffects();
				new BackpackFactory(_log, _config).CreateAssets();
				Backpacks.LoadBackpackTypes(BackpackFactory.BackpackTypes());
				BoneReorder.ApplyOnEquipmentChanged(((BaseUnityPlugin)this).Info.Metadata.GUID);
				ConfigRegistry.Waiter.ConfigurationComplete(configDone: true);
				ValheimAwake = true;
			}
		}

		private void OnDestroy()
		{
			_instance = null;
		}
	}
}
namespace AdventureBackpacks.API
{
	[PublicAPI]
	public class ABAPI
	{
		public struct Backpack
		{
			public string Name;

			public ItemData ItemData;

			public Inventory Inventory;

			public BackpackDefinition Definition;
		}

		public class BackpackDefinition
		{
			public GameObject BackPackGo;

			public AssetBundle AssetBundle;

			public string PrefabName;

			public string ItemName;

			public string ConfigSection = "";

			public string CraftingTable;

			public int StationLevel;

			public int MaxRequiredStationLevel;

			public readonly List<RecipeIngredient> RecipeIngredients = new List<RecipeIngredient>();

			public readonly List<RecipeIngredient> UpgradeIngredients = new List<RecipeIngredient>();

			public readonly List<DropTarget> DropsFrom = new List<DropTarget>();

			public readonly Dictionary<BackpackBiomes, KeyValuePair<StatusEffect, int>> EffectsToApply = new Dictionary<BackpackBiomes, KeyValuePair<StatusEffect, int>>();

			public Dictionary<int, Vector2> BackpackSizeByQuality = new Dictionary<int, Vector2>();

			public StatusEffect ItemSetStatusEffect;

			public float WeightMultiplier;

			public int CarryBonus;

			public float SpeedMod;

			public bool EnableFreezing;

			public BackpackBiomes BackpackBiome;

			public BackpackDefinition()
			{
			}

			public BackpackDefinition(GameObject backPackGo)
			{
				BackPackGo = backPackGo;
			}

			public BackpackDefinition(AssetBundle assetBundle, string prefabName)
			{
				AssetBundle = assetBundle;
				PrefabName = prefabName;
			}
		}

		public struct DropTarget
		{
			public string Creature;

			public int Min;

			public int? Max;

			public float Chance;

			public DropTarget(string creature, float chance, int min = 1, int? max = null)
			{
				Creature = creature;
				Chance = chance;
				Min = min;
				Max = max;
			}
		}

		public struct EffectDefinition
		{
			public readonly string Name;

			public readonly string LocalizedName;

			public readonly string EffectName;

			public readonly string Description;

			public readonly StatusEffect StatusEffect;

			public EffectDefinition(string name, string localizedName, string effectName, string description, StatusEffect statusEffect)
			{
				Name = name;
				LocalizedName = localizedName;
				EffectName = effectName;
				Description = description;
				StatusEffect = statusEffect;
			}
		}

		public struct RecipeIngredient
		{
			public string ItemPrefabName;

			public int Quantity;

			public RecipeIngredient(string itemPrefabName, int quantity)
			{
				ItemPrefabName = itemPrefabName;
				Quantity = quantity;
			}
		}

		public static bool IsLoaded()
		{
			return true;
		}

		public static bool IsBackpack(ItemData itemData)
		{
			return itemData?.IsBackpack() ?? false;
		}

		public static bool IsBackpackEquipped(Player player)
		{
			if ((Object)(object)player != (Object)null)
			{
				return player.IsBackpackEquipped();
			}
			return false;
		}

		public static bool CanOpenBackpack(Player player)
		{
			if ((Object)(object)player != (Object)null)
			{
				return player.CanOpenBackpack();
			}
			return false;
		}

		public static bool IsThisBackpackEquipped(Player player, ItemData itemData)
		{
			if ((Object)(object)player != (Object)null)
			{
				return player.IsThisBackpackEquipped(itemData);
			}
			return false;
		}

		public static Backpack? GetEquippedBackpack(Player player)
		{
			return ConvertBackpackItem(player.GetEquippedBackpack());
		}

		public static Backpack? GetBackpack(ItemData itemData)
		{
			return ConvertBackpackItem(itemData);
		}

		public static HashSet<StatusEffect> GetActiveBackpackStatusEffects()
		{
			return EquipmentEffectCache.ActiveEffects;
		}

		public static HashSet<StatusEffect> GetRegisterdStatusEffects()
		{
			return EffectsFactory.GetRegisteredEffects();
		}

		public static void OpenBackpack(Player player, InventoryGui gui)
		{
			if ((Object)(object)player != (Object)null)
			{
				player.OpenBackpack(gui);
			}
		}

		public static void RegisterEffect(EffectDefinition effectDefinition)
		{
			EffectsFactory.RegisterExternalEffect(effectDefinition);
		}

		public static void RegisterBackpack(BackpackDefinition definition)
		{
			BackpackFactory.RegisterExternalBackpack(definition);
		}

		private static Backpack? ConvertBackpackItem(BackpackComponent component)
		{
			BackpackDefinition backPackDefinitionFromComponent = GetBackPackDefinitionFromComponent(component);
			if (backPackDefinitionFromComponent == null)
			{
				return null;
			}
			Backpack value = default(Backpack);
			value.Name = backPackDefinitionFromComponent.ItemName;
			value.ItemData = component.Item;
			value.Definition = backPackDefinitionFromComponent;
			value.Inventory = component.GetInventory();
			return value;
		}

		private static Backpack? ConvertBackpackItem(ItemData itemData)
		{
			if (!itemData.IsBackpack())
			{
				return null;
			}
			return ConvertBackpackItem(itemData.Data().GetOrCreate<BackpackComponent>());
		}

		private static Dictionary<int, Vector2> GetBackpackSizing(BackpackItem backpack)
		{
			return backpack.BackpackSize.ToDictionary((KeyValuePair<int, ConfigEntry<Vector2>> entry) => entry.Key, (KeyValuePair<int, ConfigEntry<Vector2>> entry) => entry.Value.Value);
		}

		private static BackpackDefinition GetBackPackDefinitionFromComponent(BackpackComponent component)
		{
			if (component.Item.TryGetBackpackItem(out var backpack))
			{
				return null;
			}
			return GetBackPackDefinition(backpack);
		}

		private static BackpackDefinition GetBackPackDefinition(BackpackItem backpack)
		{
			return new BackpackDefinition
			{
				ItemName = backpack.ItemName,
				PrefabName = backpack.PrefabName,
				BackpackSizeByQuality = GetBackpackSizing(backpack),
				WeightMultiplier = backpack.WeightMultiplier.Value,
				CarryBonus = backpack.CarryBonus.Value,
				SpeedMod = backpack.SpeedMod.Value,
				EnableFreezing = backpack.EnableFreezing.Value,
				BackpackBiome = backpack.BackpackBiome.Value
			};
		}
	}
	[Flags]
	public enum BackpackBiomes : uint
	{
		None = 0u,
		Meadows = 1u,
		BlackForest = 2u,
		Swamp = 4u,
		Mountains = 8u,
		Plains = 0x10u,
		Mistlands = 0x20u,
		Ashlands = 0x40u,
		DeepNorth = 0x80u,
		EffectBiome1 = 0x100000u,
		EffectBiome2 = 0x200000u,
		EffectBiome3 = 0x400000u,
		EffectBiome4 = 0x800000u,
		EffectBiome5 = 0x1000000u
	}
}
namespace AdventureBackpacks.Compats
{
	public static class ChebsNecromancy
	{
		public static void SetupNecromancyBackpackUsingApi()
		{
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			string text = "SetEffect_NecromancyArmor";
			string text2 = "chebgonaz";
			string path = "Assets";
			string text3 = "";
			string text4 = "friendlyskeletonwand_necromancy_skill";
			StatusEffect val = null;
			if (!ABAPI.IsLoaded())
			{
				return;
			}
			PluginInfo val2 = Chainloader.PluginInfos["com.chebgonaz.ChebsNecromancy"];
			text3 = Path.Combine(Paths.PluginPath, Path.GetDirectoryName(val2.Location) ?? "", path, text2);
			if (!File.Exists(text3))
			{
				text3 = Path.Combine(Paths.PluginPath, Path.GetDirectoryName(val2.Location) ?? "", text2);
			}
			AssetBundle val3 = ((!File.Exists(text3)) ? null : AssetBundle.LoadFromFile(text3));
			if ((Object)(object)val3 == (Object)null)
			{
				AdventureBackpacks.Log.Error("Can't find Asset Bundle for Status Effect: " + text + " - Effect Not Registered");
				return;
			}
			SkillType skillLevel = (SkillType)Math.Abs(StringExtensionMethods.GetStableHashCode(text4));
			SE_Stats val4 = val3.LoadAsset<SE_Stats>(text);
			if ((Object)(object)val4 != (Object)null)
			{
				val4.m_skillLevel = skillLevel;
				val4.m_skillLevelModifier = 10f;
			}
			val = (StatusEffect)(object)val4;
			ABAPI.RegisterEffect(new ABAPI.EffectDefinition("Necromancy Armor Effect", "Necromancy Armor Effect", text, "When activated the backpack provides the Necromancy Armor effect from Cheb's Necromancy", val));
			AssetBundle val5 = Utilities.LoadAssetBundle("chebsbackpack", "Assets.Bundles");
			if ((Object)(object)val5 == (Object)null)
			{
				AdventureBackpacks.Log.Warning("Asset Bundle Not Found");
				return;
			}
			string prefabName = "BackpackNecromancy";
			ABAPI.RegisterBackpack(new ABAPI.BackpackDefinition(val5, prefabName)
			{
				ItemName = "$item_friendlyskeletonwand_spectralshroud_backpack",
				CraftingTable = "piece_workbench",
				StationLevel = 1,
				MaxRequiredStationLevel = 4,
				RecipeIngredients = 
				{
					new ABAPI.RecipeIngredient("ChebGonaz_SpectralShroud", 1),
					new ABAPI.RecipeIngredient("TrollHide", 5)
				},
				UpgradeIngredients = 
				{
					new ABAPI.RecipeIngredient("Chain", 1),
					new ABAPI.RecipeIngredient("TrollHide", 5)
				},
				DropsFrom = 
				{
					new ABAPI.DropTarget("ChebGonaz_GuardianWraith", 0.002f)
				},
				BackpackBiome = (BackpackBiomes.BlackForest | BackpackBiomes.EffectBiome1),
				BackpackSizeByQuality = 
				{
					{
						1,
						new Vector2(3f, 3f)
					},
					{
						2,
						new Vector2(4f, 3f)
					},
					{
						3,
						new Vector2(5f, 3f)
					},
					{
						4,
						new Vector2(6f, 3f)
					}
				},
				WeightMultiplier = 20f,
				EffectsToApply = { 
				{
					BackpackBiomes.EffectBiome1,
					new KeyValuePair<StatusEffect, int>(val, 1)
				} },
				ItemSetStatusEffect = val
			});
		}
	}
	public static class ContentsWithin
	{
		private static PluginInfo _plugin;

		private static Assembly _assembly;

		public static Type Main;

		public static Type InventoryGuiPatch;

		public static void Awake(Harmony harmony, string guidID)
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Expected O, but got Unknown
			if (Chainloader.PluginInfos.TryGetValue(guidID, out _plugin))
			{
				_assembly = Assembly.LoadFile(_plugin.Location);
				Main = _assembly.GetType("ContentsWithin.ContentsWithin");
				InventoryGuiPatch = Main.GetNestedType("InventoryGuiPatch");
				MethodInfo methodInfo = AccessTools.Method(InventoryGuiPatch, "HasContainerAccess", (Type[])null, (Type[])null);
				if (InventoryGuiPatch != null)
				{
					harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(ContentsWithin), "ContainerAccessPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
			}
		}

		private static bool ContainerAccessPrefix(Container container, ref bool __result)
		{
			if ((Object)(object)container == (Object)null)
			{
				return true;
			}
			if (!((Object)container).name.Equals("Player(Clone)"))
			{
				return true;
			}
			__result = false;
			return false;
		}
	}
}
namespace AdventureBackpacks.Patches
{
	public static class ArmorStandPatches
	{
		[HarmonyPatch(typeof(ArmorStand), "UpdateAttach")]
		private static class ArmorStandUpdateAttachPatch
		{
			private static void Prefix(ArmorStand __instance)
			{
				AdventureBackpacks.BypassMoveProtection = true;
			}

			private static void Postfix(ArmorStand __instance)
			{
				AdventureBackpacks.BypassMoveProtection = false;
			}
		}
	}
	public static class ContainerPatches
	{
		[HarmonyPatch(typeof(Container), "TakeAll")]
		private static class ContainerTakeAllPatch
		{
			private static void Prefix(Container __instance)
			{
				AdventureBackpacks.BypassMoveProtection = true;
			}

			private static void Postfix(Container __instance)
			{
				AdventureBackpacks.BypassMoveProtection = false;
			}
		}

		[HarmonyPatch(typeof(Container), "Interact")]
		private static class ContainerInteractPatch
		{
			private static bool Prefix(Container __instance, ref bool __result)
			{
				if (((Object)__instance).name.Equals("Player(Clone)"))
				{
					__result = false;
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Container), "Awake")]
		private static class ContainerAwakePatch
		{
			[StructLayout(LayoutKind.Auto)]
			[CompilerGenerated]
			private struct <>c__DisplayClass1_0
			{
				public int counter;
			}

			[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;

				private IEnumerable<CodeInstruction> instructions;

				public IEnumerable<CodeInstruction> <>3__instructions;

				private <>c__DisplayClass1_0 <>8__1;

				private bool <patchedSuccess>5__2;

				private List<CodeInstruction> <instrs>5__3;

				private MethodInfo <invokeRepeatingMethod>5__4;

				private FieldInfo <nviewField>5__5;

				private int <i>5__6;

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

				object IEnumerator.Current
				{
					[DebuggerHidden]
					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()
				{
					<instrs>5__3 = null;
					<invokeRepeatingMethod>5__4 = null;
					<nviewField>5__5 = null;
					<>1__state = -2;
				}

				private bool MoveNext()
				{
					//IL_0182: Unknown result type (might be due to invalid IL or missing references)
					//IL_018c: Expected O, but got Unknown
					//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
					//IL_01cc: Expected O, but got Unknown
					//IL_0212: Unknown result type (might be due to invalid IL or missing references)
					//IL_0222: Expected O, but got Unknown
					//IL_0147: Unknown result type (might be due to invalid IL or missing references)
					//IL_0151: Expected O, but got Unknown
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<patchedSuccess>5__2 = false;
						<instrs>5__3 = instructions.ToList();
						<>8__1.counter = 0;
						<invokeRepeatingMethod>5__4 = AccessTools.DeclaredMethod(typeof(MonoBehaviour), "InvokeRepeating", new Type[3]
						{
							typeof(string),
							typeof(float),
							typeof(float)
						}, (Type[])null);
						<nviewField>5__5 = AccessTools.DeclaredField(typeof(Container), "m_nview");
						<i>5__6 = 0;
						goto IL_02b4;
					case 1:
					{
						<>1__state = -1;
						int counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<>2__current = new CodeInstruction(OpCodes.Ldarg_0, (object)null);
						<>1__state = 2;
						return true;
					}
					case 2:
					{
						<>1__state = -1;
						int counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<>2__current = new CodeInstruction(OpCodes.Ldfld, (object)<nviewField>5__5);
						<>1__state = 3;
						return true;
					}
					case 3:
					{
						<>1__state = -1;
						int counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<>2__current = <Transpiler>g__LogMessage|1_0(new CodeInstruction(OpCodes.Call, (object)AccessTools.DeclaredMethod(typeof(ContainerAwakePatch), "UpdateZDO", (Type[])null, (Type[])null)), ref <>8__1);
						<>1__state = 4;
						return true;
					}
					case 4:
					{
						<>1__state = -1;
						int counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<patchedSuccess>5__2 = true;
						goto IL_0258;
					}
					case 5:
						{
							<>1__state = -1;
							int counter = <>8__1.counter;
							<>8__1.counter = counter + 1;
							counter = <i>5__6 + 1;
							<i>5__6 = counter;
							goto IL_02b4;
						}
						IL_02b4:
						if (<i>5__6 < <instrs>5__3.Count)
						{
							if (<i>5__6 > 5 && <instrs>5__3[<i>5__6].opcode == OpCodes.Ret && <instrs>5__3[<i>5__6 - 1].opcode == OpCodes.Call && <instrs>5__3[<i>5__6 - 1].operand.Equals(<invokeRepeatingMethod>5__4))
							{
								<>2__current = new CodeInstruction(OpCodes.Ldarg_0, (object)null);
								<>1__state = 1;
								return true;
							}
							goto IL_0258;
						}
						if (!<patchedSuccess>5__2)
						{
							AdventureBackpacks.Log.Error("Container.Awake Transpiler Failed To Patch");
							Thread.Sleep(5000);
						}
						return false;
						IL_0258:
						<>2__current = <Transpiler>g__LogMessage|1_0(<instrs>5__3[<i>5__6], ref <>8__1);
						<>1__state = 5;
						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]
				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__.instructions = <>3__instructions;
					return <Transpiler>d__;
				}

				[DebuggerHidden]
				IEnumerator IEnumerable.GetEnumerator()
				{
					return ((IEnumerable<CodeInstruction>)this).GetEnumerator();
				}
			}

			private static void UpdateZDO(Container instance, ZNetView nview)
			{
				if (((Object)instance).name.Equals("Player(Clone)"))
				{
					nview.GetZDO().Set(StringExtensionMethods.GetStableHashCode("creator"), 1L);
				}
			}

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

			[CompilerGenerated]
			internal static CodeInstruction <Transpiler>g__LogMessage|1_0(CodeInstruction instruction, ref <>c__DisplayClass1_0 P_1)
			{
				AdventureBackpacks.Log.Debug($"IL_{P_1.counter}: Opcode: {instruction.opcode} Operand: {instruction.operand}");
				return instruction;
			}
		}
	}
	public static class DoorPatches
	{
		[HarmonyPatch(typeof(Door), "HaveKey")]
		private static class HaveDoorKeyPatch
		{
			private static void Postfix(Door __instance, ref bool __result)
			{
				if (!((Object)(object)__instance == (Object)null) && !((Object)(object)Player.m_localPlayer == (Object)null) && Player.m_localPlayer.IsBackpackEquipped() && !__result)
				{
					BackpackComponent equippedBackpack = Player.m_localPlayer.GetEquippedBackpack();
					__result = (Object)(object)__instance.m_keyItem == (Object)null || equippedBackpack.GetInventory().HaveItem(__instance.m_keyItem.m_itemData.m_shared.m_name, true);
				}
			}
		}
	}
	public class EnvManPatches
	{
		[HarmonyPatch(typeof(EnvMan), "IsCold")]
		public static class EnvManIsCold
		{
			[UsedImplicitly]
			[HarmonyPriority(800)]
			public static bool Prefix(EnvMan __instance, ref bool __result)
			{
				if ((Object)(object)Player.m_localPlayer == (Object)null)
				{
					return true;
				}
				if (EffectsFactory.EffectList[BackpackEffect.ColdResistance].IsEffectActive((Humanoid)(object)Player.m_localPlayer))
				{
					__result = false;
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(EnvMan), "IsWet")]
		public static class EnvManIsWet
		{
			[UsedImplicitly]
			[HarmonyPriority(800)]
			public static bool Prefix(EnvMan __instance, ref bool __result)
			{
				if ((Object)(object)Player.m_localPlayer == (Object)null)
				{
					return true;
				}
				if (EffectsFactory.EffectList[BackpackEffect.WaterResistance].IsEffectActive((Humanoid)(object)Player.m_localPlayer))
				{
					__result = false;
					return false;
				}
				return true;
			}
		}
	}
	public class FejdStartupPatches
	{
		[HarmonyPatch(typeof(FejdStartup), "Start")]
		[HarmonyAfter(new string[] { "org.bepinex.helpers.LocalizationManager" })]
		[HarmonyBefore(new string[] { "org.bepinex.helpers.ItemManager" })]
		public static class FejdStartupAwakePatch
		{
			private static void Postfix()
			{
				AdventureBackpacks.Waiter.ValheimIsAwake(awakeFlag: true);
			}
		}
	}
	public class GuiBarPatches
	{
		[HarmonyPatch(typeof(GuiBar), "Awake")]
		public static class GuiBarAwakePatch
		{
			public const string eaqsGUID = "randyknapp.mods.equipmentandquickslots";

			private static bool Prefix(GuiBar __instance)
			{
				//IL_0029: 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)
				if (!Chainloader.PluginInfos.ContainsKey("randyknapp.mods.equipmentandquickslots") && ((Object)__instance).name == "durability" && __instance.m_bar.sizeDelta.x != 54f)
				{
					__instance.m_bar.sizeDelta = new Vector2(54f, 0f);
				}
				return true;
			}
		}
	}
	public class HumanoidPatches
	{
		[HarmonyPatch(typeof(Humanoid), "UpdateEquipmentStatusEffects")]
		private static class HumanoidUpdateEquipmentStatusEffectsPatch
		{
			[StructLayout(LayoutKind.Auto)]
			[CompilerGenerated]
			private struct <>c__DisplayClass0_0
			{
				public int counter;
			}

			[CompilerGenerated]
			private sealed class <Transpiler>d__0 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IDisposable, IEnumerator
			{
				private int <>1__state;

				private CodeInstruction <>2__current;

				private int <>l__initialThreadId;

				private IEnumerable<CodeInstruction> instructions;

				public IEnumerable<CodeInstruction> <>3__instructions;

				private <>c__DisplayClass0_0 <>8__1;

				private bool <patchedSuccess>5__2;

				private List<CodeInstruction> <instrs>5__3;

				private CodeInstruction <ldlocInstruction>5__4;

				private int <i>5__5;

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

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

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

				[DebuggerHidden]
				void IDisposable.Dispose()
				{
					<instrs>5__3 = null;
					<ldlocInstruction>5__4 = null;
					<>1__state = -2;
				}

				private bool MoveNext()
				{
					//IL_0059: Unknown result type (might be due to invalid IL or missing references)
					//IL_0063: Expected O, but got Unknown
					//IL_0196: Unknown result type (might be due to invalid IL or missing references)
					//IL_01a6: Expected O, but got Unknown
					//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
					//IL_0201: Expected O, but got Unknown
					//IL_0237: Unknown result type (might be due to invalid IL or missing references)
					//IL_0247: Expected O, but got Unknown
					int counter;
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<patchedSuccess>5__2 = false;
						<instrs>5__3 = instructions.ToList();
						<>8__1.counter = 0;
						<ldlocInstruction>5__4 = new CodeInstruction(OpCodes.Ldloc_0, (object)null);
						<i>5__5 = 0;
						break;
					case 1:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						if (<i>5__5 > 0 && <instrs>5__3[<i>5__5].opcode == OpCodes.Stloc_0 && <instrs>5__3[<i>5__5 - 1].opcode == OpCodes.Newobj)
						{
							if (<instrs>5__3[<i>5__5].labels.Count > 0)
							{
								CodeInstructionExtensions.MoveLabelsTo(<instrs>5__3[<i>5__5], <ldlocInstruction>5__4);
							}
							<>2__current = <Transpiler>g__LogMessage|0_0(<ldlocInstruction>5__4, ref <>8__1);
							<>1__state = 2;
							return true;
						}
						goto IL_027d;
					case 2:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<>2__current = <Transpiler>g__LogMessage|0_0(new CodeInstruction(OpCodes.Ldarg_0, (object)null), ref <>8__1);
						<>1__state = 3;
						return true;
					case 3:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<>2__current = <Transpiler>g__LogMessage|0_0(new CodeInstruction(OpCodes.Call, (object)AccessTools.DeclaredMethod(typeof(EquipmentEffectCache), "AddActiveBackpackEffects", (Type[])null, (Type[])null)), ref <>8__1);
						<>1__state = 4;
						return true;
					case 4:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<>2__current = <Transpiler>g__LogMessage|0_0(new CodeInstruction(OpCodes.Stloc_0, (object)null), ref <>8__1);
						<>1__state = 5;
						return true;
					case 5:
						{
							<>1__state = -1;
							counter = <>8__1.counter;
							<>8__1.counter = counter + 1;
							<patchedSuccess>5__2 = true;
							goto IL_027d;
						}
						IL_027d:
						counter = <i>5__5 + 1;
						<i>5__5 = counter;
						break;
					}
					if (<i>5__5 < <instrs>5__3.Count)
					{
						<>2__current = <Transpiler>g__LogMessage|0_0(<instrs>5__3[<i>5__5], ref <>8__1);
						<>1__state = 1;
						return true;
					}
					if (!<patchedSuccess>5__2)
					{
						AdventureBackpacks.Log.Error("UpdateEquipmentStatusEffects Transpiler Failed To Patch");
						Thread.Sleep(5000);
					}
					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]
				IEnumerator<CodeInstruction> IEnumerable<CodeInstruction>.GetEnumerator()
				{
					<Transpiler>d__0 <Transpiler>d__;
					if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
					{
						<>1__state = 0;
						<Transpiler>d__ = this;
					}
					else
					{
						<Transpiler>d__ = new <Transpiler>d__0(0);
					}
					<Transpiler>d__.instructions = <>3__instructions;
					return <Transpiler>d__;
				}

				[DebuggerHidden]
				IEnumerator IEnumerable.GetEnumerator()
				{
					return ((IEnumerable<CodeInstruction>)this).GetEnumerator();
				}
			}

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

			[CompilerGenerated]
			internal static CodeInstruction <Transpiler>g__LogMessage|0_0(CodeInstruction instruction, ref <>c__DisplayClass0_0 P_1)
			{
				AdventureBackpacks.Log.Debug($"IL_{P_1.counter}: Opcode: {instruction.opcode} Operand: {instruction.operand}");
				return instruction;
			}
		}

		[HarmonyPatch(typeof(Humanoid), "UnequipItem")]
		private static class HumanoidUnequipItemPatch
		{
			private static void Prefix(ItemData __0)
			{
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_009f: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a9: Expected O, but got Unknown
				if (__0 == null || (Object)(object)Player.m_localPlayer == (Object)null)
				{
					return;
				}
				Scene activeScene = SceneManager.GetActiveScene();
				if (((Scene)(ref activeScene)).name.Equals("start"))
				{
					return;
				}
				Player localPlayer = Player.m_localPlayer;
				if (!__0.IsBackpack() || ((Humanoid)localPlayer).m_shoulderItem != __0)
				{
					return;
				}
				BackpackComponent equippedBackpack = localPlayer.GetEquippedBackpack();
				if (equippedBackpack != null)
				{
					equippedBackpack.Save();
					InventoryGui instance = InventoryGui.instance;
					if ((Object)(object)instance != (Object)null && instance.IsContainerOpen())
					{
						instance.CloseContainer();
						InventoryGuiPatches.BackpackIsOpen = false;
					}
					Container component = ((Component)localPlayer).gameObject.GetComponent<Container>();
					if (!((Object)(object)component == (Object)null))
					{
						component.m_inventory = new Inventory("Empty", (Sprite)null, 1, 1);
						InventoryGuiPatches.BackpackEquipped = false;
					}
				}
			}
		}

		[HarmonyPatch(typeof(Humanoid), "EquipItem")]
		private static class HumanoidEquipItemPatch
		{
			private static void Postfix(ItemData __0, bool __result)
			{
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0087: Unknown result type (might be due to invalid IL or missing references)
				//IL_008c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0090: Unknown result type (might be due to invalid IL or missing references)
				AdventureBackpacks.Log.Debug("##########   EquipItem Start");
				if (__0 == null || !__result || (Object)(object)Player.m_localPlayer == (Object)null)
				{
					return;
				}
				Scene activeScene = SceneManager.GetActiveScene();
				if (((Scene)(ref activeScene)).name.Equals("start"))
				{
					return;
				}
				Player localPlayer = Player.m_localPlayer;
				if (__0.IsBackpack() && __0.TryGetBackpackItem(out var backpack))
				{
					InventoryGuiPatches.BackpackEquipped = true;
					BackpackComponent orCreate = __0.Data().GetOrCreate<BackpackComponent>();
					if (!orCreate.IsEmptyingBackpack)
					{
						Vector2i inventorySize = backpack.GetInventorySize(orCreate.Item.m_quality);
						if (orCreate.InventoryNeedsValidating(inventorySize))
						{
							Backpacks.ValidateBackpackInventorySizing(localPlayer, orCreate.Item);
						}
						else
						{
							Container backpackContainer = ((Component)localPlayer).gameObject.GetComponent<Container>();
							if ((Object)(object)backpackContainer != (Object)null)
							{
								orCreate.UpdateContainerSizing(ref backpackContainer);
							}
						}
					}
				}
				AdventureBackpacks.Log.Debug("##########   EquipItem End");
			}
		}
	}
	public static class InventoryPatches
	{
		[HarmonyPatch(typeof(Inventory), "Changed")]
		private static class InventoryChangedPatch
		{
			private static void Postfix(Inventory __instance)
			{
				if (__instance == null || (Object)(object)Player.m_localPlayer == (Object)null)
				{
					return;
				}
				Player localPlayer = Player.m_localPlayer;
				if (!__instance.IsBackPackInventory())
				{
					return;
				}
				new StackTrace();
				AdventureBackpacks.Log.Debug("#### Patch Inventory Changed: " + __instance.m_name);
				AdventureBackpacks.Log.Debug($"#### Patch Inventory Count: {__instance.m_inventory.Count}");
				if (!localPlayer.IsBackpackEquipped())
				{
					return;
				}
				BackpackComponent equippedBackpack = localPlayer.GetEquippedBackpack();
				AdventureBackpacks.Log.Debug("########################################");
				AdventureBackpacks.Log.Debug("####       Inventory.Changed       #####");
				AdventureBackpacks.Log.Debug("Inventory Instance: " + __instance.m_name);
				AdventureBackpacks.Log.Debug("Backpack Name: " + equippedBackpack.Item.m_shared.m_name);
				AdventureBackpacks.Log.Debug("########################################");
				if (equippedBackpack.GetInventory() == __instance)
				{
					AdventureBackpacks.Log.Debug($"#### Before Save BackpackComponent Inventory Count: {equippedBackpack.GetInventory().m_inventory.Count}");
					if (equippedBackpack.IsLoadingInventory)
					{
						AdventureBackpacks.Log.Debug("Bypassing Save - Inventory Is Loading ----->");
					}
					else
					{
						equippedBackpack.Save(__instance);
					}
					AdventureBackpacks.Log.Debug($"#### After Save BackpackComponent Inventory Count: {equippedBackpack.GetInventory().m_inventory.Count}");
				}
			}
		}

		[HarmonyPatch(typeof(InventoryGui), "OnDropOutside")]
		[HarmonyPriority(800)]
		private static class OnDropOutsideItemPatch
		{
			private static void Prefix(InventoryGui __instance)
			{
				if (!((Object)(object)__instance == (Object)null) && __instance.m_dragItem != null)
				{
					if (__instance.m_dragItem.IsBackpack() && __instance.m_dragItem.m_stack == 0)
					{
						__instance.m_dragItem.m_stack = 1;
					}
					_droppingOutside = true;
				}
			}

			private static void Postfix()
			{
				_droppingOutside = false;
			}
		}

		[HarmonyPatch(typeof(Humanoid), "DropItem", new Type[]
		{
			typeof(Inventory),
			typeof(ItemData),
			typeof(int)
		})]
		[HarmonyPriority(800)]
		private static class HumanoidDropItemPatch
		{
			private static void Prefix(ItemData item)
			{
				_droppingOutside = true;
			}

			private static void Postfix()
			{
				_droppingOutside = false;
			}
		}

		[HarmonyPatch(typeof(Inventory), "RemoveItem", new Type[] { typeof(ItemData) })]
		[HarmonyPriority(800)]
		private static class RemoveItem1Patch
		{
			private static bool Prefix(Inventory __instance, ItemData item, ref bool __result)
			{
				if (item == null || __instance == null)
				{
					return true;
				}
				if (!RemoveItemPrefix(__instance, item))
				{
					__result = false;
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Inventory), "RemoveItem", new Type[]
		{
			typeof(ItemData),
			typeof(int)
		})]
		[HarmonyPriority(800)]
		private static class RemoveItem2Patch
		{
			private static bool Prefix(Inventory __instance, ItemData item, ref bool __result)
			{
				if (item == null || __instance == null)
				{
					return true;
				}
				if (!RemoveItemPrefix(__instance, item))
				{
					__result = false;
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Inventory), "RemoveOneItem", new Type[] { typeof(ItemData) })]
		[HarmonyPriority(800)]
		private static class RemoveItem3Patch
		{
			private static bool Prefix(Inventory __instance, ItemData item, ref bool __result)
			{
				if (item == null || __instance == null)
				{
					return true;
				}
				if (!RemoveItemPrefix(__instance, item))
				{
					__result = false;
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Inventory), "AddItem", new Type[]
		{
			typeof(string),
			typeof(int),
			typeof(int),
			typeof(int),
			typeof(long),
			typeof(string),
			typeof(Vector2i),
			typeof(bool)
		})]
		[HarmonyPriority(800)]
		private static class AddItemCraftingPatch
		{
			private static void Postfix(Inventory __instance, ref ItemData __result)
			{
				if (IsDoingCrafting && __instance != null)
				{
					_savedBackpackData = null;
				}
			}
		}

		[HarmonyPatch(typeof(Inventory), "AddItem", new Type[] { typeof(ItemData) })]
		[HarmonyPriority(800)]
		private static class AddItemPatch
		{
			private static bool Prefix(Inventory __instance, ItemData item, ref bool __result)
			{
				if (item == null)
				{
					return false;
				}
				if (item.IsBackpack() && __instance.HaveEmptySlot())
				{
					bool flag = Backpacks.CheckForInception(__instance, item);
					if (flag && !_movingItemBetweenContainers)
					{
						ItemsAddedQueue.Enqueue(new KeyValuePair<ItemData, DateTime>(item, DateTime.Now));
					}
					__result = flag;
					return flag;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(InventoryGrid), "DropItem", new Type[]
		{
			typeof(Inventory),
			typeof(ItemData),
			typeof(int),
			typeof(Vector2i)
		})]
		[HarmonyPriority(800)]
		private static class InventoryGridDropItemPatch
		{
			private static bool Prefix(InventoryGrid __instance, Inventory fromInventory, ItemData item, int amount, Vector2i pos)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000d: Unknown result type (might be due to invalid IL or missing references)
				ItemData itemAt = __instance.m_inventory.GetItemAt(pos.x, pos.y);
				if (itemAt == item)
				{
					return true;
				}
				if (itemAt == null || (!(itemAt.m_shared.m_name != item.m_shared.m_name) && (item.m_shared.m_maxQuality <= 1 || itemAt.m_quality == item.m_quality) && itemAt.m_shared.m_maxStackSize != 1) || item.m_stack != amount)
				{
					return true;
				}
				if (AdventureBackpacks.PerformYardSale)
				{
					return true;
				}
				if (itemAt.IsBackpack() && fromInventory.IsBackPackInventory())
				{
					return Backpacks.CheckForInception(fromInventory, itemAt);
				}
				if (item.IsBackpack() && __instance.m_inventory.IsBackPackInventory())
				{
					return Backpacks.CheckForInception(__instance.m_inventory, item);
				}
				_movingItemBetweenContainers = true;
				return true;
			}
		}

		[HarmonyPatch(typeof(Inventory), "MoveAll", new Type[] { typeof(Inventory) })]
		[HarmonyPriority(800)]
		private static class MoveAllPatch
		{
			private static void Prefix(Inventory fromInventory, Inventory __instance)
			{
				if (fromInventory != null && !__instance.IsBackPackInventory())
				{
					_movingItemBetweenContainers = true;
				}
			}

			private static void Postfix()
			{
				_movingItemBetweenContainers = false;
			}
		}

		[HarmonyPatch(typeof(Inventory), "MoveItemToThis", new Type[]
		{
			typeof(Inventory),
			typeof(ItemData),
			typeof(int),
			typeof(int),
			typeof(int)
		})]
		[HarmonyPriority(800)]
		private static class MoveItemToThisPatch
		{
			private static bool Prefix(Inventory __0, ItemData __1, int __2, int __3, int __4, Inventory __instance)
			{
				if (__0 == null || __1 == null)
				{
					return false;
				}
				if (!__instance.IsBackPackInventory())
				{
					_movingItemBetweenContainers = true;
					return true;
				}
				return Backpacks.CheckForInception(__instance, __1);
			}

			private static void Postfix()
			{
				_movingItemBetweenContainers = false;
			}
		}

		[HarmonyPatch(typeof(Inventory), "MoveItemToThis", new Type[]
		{
			typeof(Inventory),
			typeof(ItemData)
		})]
		[HarmonyPriority(800)]
		private static class MoveItemToThisOtherPatch
		{
			private static bool Prefix(Inventory __0, ItemData __1, Inventory __instance)
			{
				if (__0 == null || __1 == null)
				{
					return false;
				}
				if (!__instance.IsBackPackInventory())
				{
					_movingItemBetweenContainers = true;
					return true;
				}
				return Backpacks.CheckForInception(__instance, __1);
			}

			private static void Postfix()
			{
				_movingItemBetweenContainers = false;
			}
		}

		[HarmonyPatch(typeof(Inventory), "UpdateTotalWeight")]
		private static class UpdateTotalWeightPatch
		{
			[HarmonyPatch(typeof(Inventory), "IsTeleportable")]
			private static class IsTeleportablePatch
			{
				private static void Postfix(Inventory __instance, ref bool __result)
				{
					if (__instance == null || (Object)(object)Player.m_localPlayer == (Object)null)
					{
						return;
					}
					List<ItemData> allItems = __instance.GetAllItems();
					if (__instance != ((Humanoid)Player.m_localPlayer).GetInventory())
					{
						return;
					}
					if (Player.m_localPlayer.IsBackpackEquipped())
					{
						BackpackComponent equippedBackpack = Player.m_localPlayer.GetEquippedBackpack();
						if (equippedBackpack != null && !equippedBackpack.GetInventory().IsTeleportable())
						{
							__result = false;
							return;
						}
					}
					foreach (ItemData item in allItems)
					{
						if (item != null && item.IsBackpack() && !item.Data().GetOrCreate<BackpackComponent>().GetInventory()
							.IsTeleportable())
						{
							__result = false;
							break;
						}
					}
				}
			}

			private static void Postfix(Inventory __instance)
			{
				if (__instance == null || (Object)(object)Player.m_localPlayer == (Object)null)
				{
					return;
				}
				Player localPlayer = Player.m_localPlayer;
				if (__instance.IsBackPackInventory() && localPlayer.IsBackpackEquipped())
				{
					BackpackComponent equippedBackpack = localPlayer.GetEquippedBackpack();
					AdventureBackpacks.Log.Debug("########################################");
					AdventureBackpacks.Log.Debug("####       UpdateTotalWeight       #####");
					AdventureBackpacks.Log.Debug("Inventory Instance: " + __instance.m_name);
					AdventureBackpacks.Log.Debug("Backpack Name: " + equippedBackpack.Item.m_shared.m_name);
					AdventureBackpacks.Log.Debug("########################################");
					if (equippedBackpack.GetInventory() == __instance)
					{
						((Humanoid)localPlayer).GetInventory().UpdateTotalWeight();
					}
				}
			}
		}

		private static bool _movingItemBetweenContainers;

		private static bool _droppingOutside;

		public static bool IsDoingCrafting = false;

		private static BackpackComponent _savedBackpackData = null;

		private static readonly Queue<KeyValuePair<ItemData, DateTime>> ItemsAddedQueue = new Queue<KeyValuePair<ItemData, DateTime>>();

		private static bool IsItemFromQueue(this ItemData item)
		{
			if (ItemsAddedQueue.Any((KeyValuePair<ItemData, DateTime> x) => ((object)x.Key).Equals((object?)item)))
			{
				AdventureBackpacks.Log.Debug("Item " + item.m_shared.m_name + " Found!");
				return true;
			}
			AdventureBackpacks.Log.Debug("Item Not Found!");
			return false;
		}

		public static void ProcessItemsAddedQueue()
		{
			while (ItemsAddedQueue.Any() && DateTime.Now.Subtract(ItemsAddedQueue.Peek().Value).TotalSeconds > 0.5)
			{
				AdventureBackpacks.Log.Debug($"Process Cache Removing {ItemsAddedQueue.Peek().Key.m_shared.m_name} for Date {ItemsAddedQueue.Peek().Value} with a difference of {DateTime.Now.Subtract(ItemsAddedQueue.Peek().Value).TotalSeconds} total seconds.");
				ItemsAddedQueue.Dequeue();
			}
		}

		private static bool RemoveItemPrefix(Inventory __instance, ItemData item)
		{
			if (__instance == null || (Object)(object)Player.m_localPlayer == (Object)null)
			{
				return true;
			}
			if (_movingItemBetweenContainers || _droppingOutside)
			{
				return true;
			}
			if (IsDoingCrafting)
			{
				if (item.IsBackpack())
				{
					_savedBackpackData = item.Data().Get<BackpackComponent>();
				}
				return true;
			}
			if (AdventureBackpacks.PerformYardSale || AdventureBackpacks.QuickDropping || AdventureBackpacks.BypassMoveProtection)
			{
				return true;
			}
			if (!item.TryGetBackpackItem(out var _))
			{
				return true;
			}
			AdventureBackpacks.Log.Debug("Checking for Backpack " + item.m_shared.m_name);
			if (item.IsItemFromQueue())
			{
				AdventureBackpacks.Log.Debug("Exiting RemoveItem for " + item.m_shared.m_name);
				return true;
			}
			BackpackComponent backpackComponent = item.Data().Get<BackpackComponent>();
			if (backpackComponent == null)
			{
				return true;
			}
			Inventory inventory = backpackComponent.GetInventory();
			if (inventory == null || inventory.m_inventory.Count == 0)
			{
				return true;
			}
			if (!Backpacks.PerformYardSale(Player.m_localPlayer, item, backpackOnly: true))
			{
				((Character)Player.m_localPlayer).Message((MessageType)2, "$vapok_mod_yard_sale_blocked", 0, (Sprite)null);
				return false;
			}
			return true;
		}
	}
	internal static class InventoryGuiPatches
	{
		[HarmonyPatch(typeof(InventoryGui), "DoCrafting")]
		private static class InventoryGuiDoCraftingPrefix
		{
			[UsedImplicitly]
			private static void Prefix(InventoryGui __instance)
			{
				AdventureBackpacks.Log.Debug("########################################");
				AdventureBackpacks.Log.Debug("####       DoCrafting.Prefix       #####");
				AdventureBackpacks.Log.Debug("########################################");
				InventoryPatches.IsDoingCrafting = true;
			}

			private static void Postfix(InventoryGui __instance)
			{
				AdventureBackpacks.Log.Debug("########################################");
				AdventureBackpacks.Log.Debug("####       DoCrafting.Postfix      #####");
				AdventureBackpacks.Log.Debug("########################################");
				InventoryPatches.IsDoingCrafting = false;
				if ((Object)(object)Player.m_localPlayer == (Object)null)
				{
					return;
				}
				Player localPlayer = Player.m_localPlayer;
				if (__instance.m_craftUpgradeItem == null || !__instance.m_craftUpgradeItem.IsBackpack())
				{
					return;
				}
				AdventureBackpacks.Log.Debug("Item: " + __instance.m_craftUpgradeItem.m_shared.m_name + " ");
				BackpackComponent backpackComponent = __instance.m_craftUpgradeItem.Data().Get<BackpackComponent>();
				AdventureBackpacks.Log.Debug("Backpack: " + __instance.m_craftUpgradeItem.m_shared.m_name + " ");
				if (backpackComponent != null)
				{
					backpackComponent?.Load();
					if (localPlayer.IsThisBackpackEquipped(backpackComponent.Item))
					{
						Container backpackContainer = ((Component)localPlayer).gameObject.GetComponent<Container>();
						backpackComponent?.UpdateContainerSizing(ref backpackContainer);
					}
					((Humanoid)localPlayer).UpdateEquipmentStatusEffects();
				}
			}
		}

		[HarmonyPatch(typeof(InventoryGui), "OnSelectedItem")]
		private static class InventoryGuiOnSelectedItem
		{
			[UsedImplicitly]
			private static Exception Finalizer(Exception __exception, InventoryGrid grid, ItemData item, Vector2i pos, Modifier mod, InventoryGui __instance)
			{
				if (__exception != null)
				{
					if (__exception is NullReferenceException && (Object)(object)__instance != (Object)null && (Object)(object)__instance.m_currentContainer == (Object)null && (Object)(object)grid != (Object)null && grid.GetInventory() != null && (Object)(object)Player.m_localPlayer != (Object)null && item != null && item.m_shared != null && Backpacks.BackpackTypes.Contains(item.m_shared.m_name))
					{
						((Humanoid)Player.m_localPlayer).DropItem(((Humanoid)Player.m_localPlayer).GetInventory(), item, 1);
						BackpackIsOpen = false;
						__instance.Hide();
						((Character)Player.m_localPlayer).Message((MessageType)1, "$vapok_mod_you_droped_bag", 0, (Sprite)null);
						return null;
					}
					AdventureBackpacks.Log.Warning("The following error was captured by Adventure Backpacks, but was caused by another mod. Advanced Backpacks is going to allow the operation to continue, but is going to replay the error below:");
					AdventureBackpacks.Log.Error("External Mod Error Message: " + __exception.Message);
					AdventureBackpacks.Log.Error("External Mod Error Source: " + __exception.Source);
					AdventureBackpacks.Log.Error("External Mod Error Stack Trace: " + __exception.StackTrace);
					AdventureBackpacks.Log.Warning("Please check with other mod authors listed above.");
				}
				return null;
			}
		}

		[HarmonyPatch(typeof(InventoryGui), "Update")]
		private static class InventoryGuiUpdateTranspiler
		{
			[StructLayout(LayoutKind.Auto)]
			[CompilerGenerated]
			private struct <>c__DisplayClass0_0
			{
				public int counter;
			}

			[CompilerGenerated]
			private sealed class <Transpiler>d__0 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IDisposable, IEnumerator
			{
				private int <>1__state;

				private CodeInstruction <>2__current;

				private int <>l__initialThreadId;

				private IEnumerable<CodeInstruction> instructions;

				public IEnumerable<CodeInstruction> <>3__instructions;

				private <>c__DisplayClass0_0 <>8__1;

				private ILGenerator ilGenerator;

				public ILGenerator <>3__ilGenerator;

				private List<CodeInstruction> <instrs>5__2;

				private bool <patchedHideBackpackMethod>5__3;

				private bool <patchedShowBackpackMethod>5__4;

				private bool <patchedDetectInputHideMethod>5__5;

				private bool <patchedDetectInputShowMethod>5__6;

				private MethodInfo <resetButtonStatus>5__7;

				private MethodInfo <hideMethod>5__8;

				private MethodInfo <showMethod>5__9;

				private MethodInfo <tutorialMethod>5__10;

				private MethodInfo <zInputKeyDown>5__11;

				private MethodInfo <zInputButtonDown>5__12;

				private int <i>5__13;

				private CodeInstruction <ldArgInstruction>5__14;

				private Label <detectHideLabel>5__15;

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

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

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

				[DebuggerHidden]
				void IDisposable.Dispose()
				{
					<instrs>5__2 = null;
					<resetButtonStatus>5__7 = null;
					<hideMethod>5__8 = null;
					<showMethod>5__9 = null;
					<tutorialMethod>5__10 = null;
					<zInputKeyDown>5__11 = null;
					<zInputButtonDown>5__12 = null;
					<ldArgInstruction>5__14 = null;
					<>1__state = -2;
				}

				private bool MoveNext()
				{
					//IL_0361: Unknown result type (might be due to invalid IL or missing references)
					//IL_0371: Expected O, but got Unknown
					//IL_05a2: Unknown result type (might be due to invalid IL or missing references)
					//IL_05b2: Expected O, but got Unknown
					//IL_05fd: Unknown result type (might be due to invalid IL or missing references)
					//IL_060d: Expected O, but got Unknown
					//IL_08db: Unknown result type (might be due to invalid IL or missing references)
					//IL_08eb: Expected O, but got Unknown
					//IL_0937: Unknown result type (might be due to invalid IL or missing references)
					//IL_0947: Expected O, but got Unknown
					//IL_0988: Unknown result type (might be due to invalid IL or missing references)
					//IL_0998: Expected O, but got Unknown
					//IL_0c3e: Unknown result type (might be due to invalid IL or missing references)
					//IL_0c4e: Expected O, but got Unknown
					//IL_0c9a: Unknown result type (might be due to invalid IL or missing references)
					//IL_0caa: Expected O, but got Unknown
					//IL_0ceb: Unknown result type (might be due to invalid IL or missing references)
					//IL_0cfb: Expected O, but got Unknown
					//IL_0894: Unknown result type (might be due to invalid IL or missing references)
					//IL_08a4: Expected O, but got Unknown
					//IL_0bf7: Unknown result type (might be due to invalid IL or missing references)
					//IL_0c07: Expected O, but got Unknown
					//IL_04c9: Unknown result type (might be due to invalid IL or missing references)
					//IL_04d3: Expected O, but got Unknown
					//IL_0273: Unknown result type (might be due to invalid IL or missing references)
					//IL_027d: Expected O, but got Unknown
					int counter;
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<instrs>5__2 = instructions.ToList();
						<>8__1.counter = 0;
						<patchedHideBackpackMethod>5__3 = false;
						<patchedShowBackpackMethod>5__4 = false;
						<patchedDetectInputHideMethod>5__5 = false;
						<patchedDetectInputShowMethod>5__6 = false;
						<resetButtonStatus>5__7 = AccessTools.DeclaredMethod(typeof(ZInput), "ResetButtonStatus", (Type[])null, (Type[])null);
						AccessTools.DeclaredMethod(typeof(Menu), "IsVisible", (Type[])null, (Type[])null);
						<hideMethod>5__8 = AccessTools.DeclaredMethod(typeof(InventoryGui), "Hide", (Type[])null, (Type[])null);
						<showMethod>5__9 = AccessTools.DeclaredMethod(typeof(InventoryGui), "Show", (Type[])null, (Type[])null);
						<tutorialMethod>5__10 = AccessTools.DeclaredMethod(typeof(Player), "ShowTutorial", (Type[])null, (Type[])null);
						<zInputKeyDown>5__11 = AccessTools.DeclaredMethod(typeof(ZInput), "GetKeyDown", new Type[2]
						{
							typeof(KeyCode),
							typeof(bool)
						}, (Type[])null);
						<zInputButtonDown>5__12 = AccessTools.DeclaredMethod(typeof(ZInput), "GetButtonDown", new Type[1] { typeof(string) }, (Type[])null);
						<i>5__13 = 0;
						break;
					case 1:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<>2__current = <Transpiler>g__LogMessage|0_0(<ldArgInstruction>5__14, ref <>8__1);
						<>1__state = 2;
						return true;
					case 2:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<>2__current = <Transpiler>g__LogMessage|0_0(new CodeInstruction(OpCodes.Call, (object)AccessTools.DeclaredMethod(typeof(InventoryGuiPatches), "HideBackpack", (Type[])null, (Type[])null)), ref <>8__1);
						<>1__state = 3;
						return true;
					case 3:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<patchedHideBackpackMethod>5__3 = true;
						<ldArgInstruction>5__14 = null;
						goto IL_0d81;
					case 4:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<>2__current = <Transpiler>g__LogMessage|0_0(<ldArgInstruction>5__14, ref <>8__1);
						<>1__state = 5;
						return true;
					case 5:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<>2__current = <Transpiler>g__LogMessage|0_0(new CodeInstruction(OpCodes.Ldarg_0, (object)null), ref <>8__1);
						<>1__state = 6;
						return true;
					case 6:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<>2__current = <Transpiler>g__LogMessage|0_0(new CodeInstruction(OpCodes.Call, (object)AccessTools.DeclaredMethod(typeof(InventoryGuiPatches), "ShowBackpack", (Type[])null, (Type[])null)), ref <>8__1);
						<>1__state = 7;
						return true;
					case 7:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<patchedShowBackpackMethod>5__4 = true;
						<ldArgInstruction>5__14 = null;
						goto IL_0d81;
					case 8:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<>2__current = <Transpiler>g__LogMessage|0_0(<instrs>5__2[<i>5__13 + 1], ref <>8__1);
						<>1__state = 9;
						return true;
					case 9:
					{
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						Label label2 = (Label)<instrs>5__2[<i>5__13 + 1].operand;
						CodeInstruction val2 = <Transpiler>g__FindInstructionWithLabel|0_1(<instrs>5__2, <i>5__13 + 2, label2);
						if (val2 == null)
						{
							AdventureBackpacks.Log.Error($"Can't Find Instruction with Label {label2}");
							goto IL_0d81;
						}
						<i>5__13++;
						<detectHideLabel>5__15 = ilGenerator.DefineLabel();
						val2.labels.Add(<detectHideLabel>5__15);
						<>2__current = <Transpiler>g__LogMessage|0_0(new CodeInstruction(OpCodes.Ldloc_1, (object)null), ref <>8__1);
						<>1__state = 10;
						return true;
					}
					case 10:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<>2__current = <Transpiler>g__LogMessage|0_0(new CodeInstruction(OpCodes.Ldarg_0, (object)null), ref <>8__1);
						<>1__state = 11;
						return true;
					case 11:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<>2__current = <Transpiler>g__LogMessage|0_0(new CodeInstruction(OpCodes.Call, (object)AccessTools.DeclaredMethod(typeof(InventoryGuiPatches), "DetectInputToHide", (Type[])null, (Type[])null)), ref <>8__1);
						<>1__state = 12;
						return true;
					case 12:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<>2__current = <Transpiler>g__LogMessage|0_0(new CodeInstruction(OpCodes.Brtrue, (object)<detectHideLabel>5__15), ref <>8__1);
						<>1__state = 13;
						return true;
					case 13:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<patchedDetectInputHideMethod>5__5 = true;
						goto IL_0d81;
					case 14:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<>2__current = <Transpiler>g__LogMessage|0_0(<instrs>5__2[<i>5__13 + 1], ref <>8__1);
						<>1__state = 15;
						return true;
					case 15:
					{
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						Label label = (Label)<instrs>5__2[<i>5__13 + 1].operand;
						CodeInstruction val = <Transpiler>g__FindInstructionWithLabel|0_1(<instrs>5__2, <i>5__13 + 2, label);
						if (val == null)
						{
							AdventureBackpacks.Log.Error($"Can't Find Instruction with Label {label}");
							goto IL_0d81;
						}
						<i>5__13++;
						<detectHideLabel>5__15 = ilGenerator.DefineLabel();
						val.labels.Add(<detectHideLabel>5__15);
						<>2__current = <Transpiler>g__LogMessage|0_0(new CodeInstruction(OpCodes.Ldloc_1, (object)null), ref <>8__1);
						<>1__state = 16;
						return true;
					}
					case 16:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<>2__current = <Transpiler>g__LogMessage|0_0(new CodeInstruction(OpCodes.Ldarg_0, (object)null), ref <>8__1);
						<>1__state = 17;
						return true;
					case 17:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<>2__current = <Transpiler>g__LogMessage|0_0(new CodeInstruction(OpCodes.Call, (object)AccessTools.DeclaredMethod(typeof(InventoryGuiPatches), "DetectInputToShow", (Type[])null, (Type[])null)), ref <>8__1);
						<>1__state = 18;
						return true;
					case 18:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<>2__current = <Transpiler>g__LogMessage|0_0(new CodeInstruction(OpCodes.Brtrue, (object)<detectHideLabel>5__15), ref <>8__1);
						<>1__state = 19;
						return true;
					case 19:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<patchedDetectInputShowMethod>5__6 = true;
						goto IL_0d81;
					case 20:
						{
							<>1__state = -1;
							counter = <>8__1.counter;
							<>8__1.counter = counter + 1;
							goto IL_0d81;
						}
						IL_0d81:
						counter = <i>5__13 + 1;
						<i>5__13 = counter;
						break;
					}
					if (<i>5__13 < <instrs>5__2.Count)
					{
						if (<i>5__13 > 6 && <instrs>5__2[<i>5__13].opcode == OpCodes.Call && <instrs>5__2[<i>5__13].operand.Equals(<resetButtonStatus>5__7) && <instrs>5__2[<i>5__13 + 1].opcode == OpCodes.Ldarg_0 && <instrs>5__2[<i>5__13 + 2].opcode == OpCodes.Call && <instrs>5__2[<i>5__13 + 2].operand.Equals(<hideMethod>5__8))
						{
							<ldArgInstruction>5__14 = new CodeInstruction(OpCodes.Ldarg_0, (object)null);
							if (<instrs>5__2[<i>5__13].labels.Count > 0)
							{
								CodeInstructionExtensions.MoveLabelsTo(<instrs>5__2[<i>5__13], <ldArgInstruction>5__14);
							}
							<>2__current = <Transpiler>g__LogMessage|0_0(<instrs>5__2[<i>5__13], ref <>8__1);
							<>1__state = 1;
							return true;
						}
						if (<i>5__13 > 6 && ((<instrs>5__2[<i>5__13].opcode == OpCodes.Call && <instrs>5__2[<i>5__13].operand.Equals(<showMethod>5__9) && <instrs>5__2[<i>5__13 - 1].opcode == OpCodes.Ldc_I4_1 && <instrs>5__2[<i>5__13 - 2].opcode == OpCodes.Ldnull && <instrs>5__2[<i>5__13 - 3].opcode == OpCodes.Ldarg_0) || (<instrs>5__2[<i>5__13 - 4].opcode == OpCodes.Callvirt && <instrs>5__2[<i>5__13 - 4].operand.Equals(<tutorialMethod>5__10))))
						{
							<ldArgInstruction>5__14 = new CodeInstruction(OpCodes.Ldloc_1, (object)null);
							if (<instrs>5__2[<i>5__13].labels.Count > 0)
							{
								CodeInstructionExtensions.MoveLabelsTo(<instrs>5__2[<i>5__13], <ldArgInstruction>5__14);
							}
							<>2__current = <Transpiler>g__LogMessage|0_0(<instrs>5__2[<i>5__13], ref <>8__1);
							<>1__state = 4;
							return true;
						}
						if (<i>5__13 > 6 && <instrs>5__2[<i>5__13].opcode == OpCodes.Call && <instrs>5__2[<i>5__13].operand.Equals(<zInputKeyDown>5__11) && <instrs>5__2[<i>5__13 - 1].opcode == OpCodes.Ldc_I4_1 && <instrs>5__2[<i>5__13 - 2].opcode == OpCodes.Ldc_I4_S && <instrs>5__2[<i>5__13 - 2].operand.Equals((sbyte)27) && <instrs>5__2[<i>5__13 + 2].opcode == OpCodes.Ldstr && <instrs>5__2[<i>5__13 + 2].operand.Equals("Use"))
						{
							<>2__current = <Transpiler>g__LogMessage|0_0(<instrs>5__2[<i>5__13], ref <>8__1);
							<>1__state = 8;
							return true;
						}
						if (<i>5__13 > 6 && <instrs>5__2[<i>5__13].opcode == OpCodes.Call && <instrs>5__2[<i>5__13].operand.Equals(<zInputButtonDown>5__12) && <instrs>5__2[<i>5__13 - 1].operand.Equals("Inventory") && <instrs>5__2[<i>5__13 + 1].opcode == OpCodes.Brtrue && <instrs>5__2[<i>5__13 + 2].opcode == OpCodes.Ldstr && <instrs>5__2[<i>5__13 + 2].operand.Equals("JoyButtonY"))
						{
							<>2__current = <Transpiler>g__LogMessage|0_0(<instrs>5__2[<i>5__13], ref <>8__1);
							<>1__state = 14;
							return true;
						}
						<>2__current = <Transpiler>g__LogMessage|0_0(<instrs>5__2[<i>5__13], ref <>8__1);
						<>1__state = 20;
						return true;
					}
					if (!<patchedHideBackpackMethod>5__3 || !<patchedShowBackpackMethod>5__4 || !<patchedDetectInputHideMethod>5__5 || !<patchedDetectInputShowMethod>5__6)
					{
						AdventureBackpacks.Log.Error("InventoryGui.Update Transpiler Failed To Patch");
						AdventureBackpacks.Log.Warning($" patchedHideBackpackMethod {<patchedHideBackpackMethod>5__3}");
						AdventureBackpacks.Log.Warning($" patchedShowBackpackMethod {<patchedShowBackpackMethod>5__4}");
						AdventureBackpacks.Log.Warning($" patchedDetectInputHideMethod {<patchedDetectInputHideMethod>5__5}");
						AdventureBackpacks.Log.Warning($" patchedDetectInputShowMethod {<patchedDetectInputShowMethod>5__6}");
						AdventureBackpacks.Log.Error("Please inform Mod Author.");
						Thread.Sleep(5000);
					}
					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]
				IEnumerator<CodeInstruction> IEnumerable<CodeInstruction>.GetEnumerator()
				{
					<Transpiler>d__0 <Transpiler>d__;
					if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
					{
						<>1__state = 0;
						<Transpiler>d__ = this;
					}
					else
					{
						<Transpiler>d__ = new <Transpiler>d__0(0);
					}
					<Transpiler>d__.instructions = <>3__instructions;
					<Transpiler>d__.ilGenerator = <>3__ilGenerator;
					return <Transpiler>d__;
				}

				[DebuggerHidden]
				IEnumerator IEnumerable.GetEnumerator()
				{
					return ((IEnumerable<CodeInstruction>)this).GetEnumerator();
				}
			}

			[IteratorStateMachine(typeof(<Transpiler>d__0))]
			[UsedImplicitly]
			public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator ilGenerator)
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <Transpiler>d__0(-2)
				{
					<>3__instructions = instructions,
					<>3__ilGenerator = ilGenerator
				};
			}

			[CompilerGenerated]
			internal static CodeInstruction <Transpiler>g__LogMessage|0_0(CodeInstruction instruction, ref <>c__DisplayClass0_0 P_1)
			{
				AdventureBackpacks.Log.Debug($"IL_{P_1.counter}: Opcode: {instruction.opcode} Operand: {instruction.operand}");
				return instruction;
			}

			[CompilerGenerated]
			internal static CodeInstruction <Transpiler>g__FindInstructionWithLabel|0_1(List<CodeInstruction> codeInstructions, int index, Label label)
			{
				if (index >= codeInstructions.Count)
				{
					return null;
				}
				if (codeInstructions[index].labels.Contains(label))
				{
					return codeInstructions[index];
				}
				return <Transpiler>g__FindInstructionWithLabel|0_1(codeInstructions, index + 1, label);
			}
		}

		[HarmonyPatch(typeof(InventoryGui), "SetupRequirement")]
		private static class InventoryGuiSetupRequirementPatch
		{
			[StructLayout(LayoutKind.Auto)]
			[CompilerGenerated]
			private struct <>c__DisplayClass0_0
			{
				public int counter;
			}

			[CompilerGenerated]
			private sealed class <Transpiler>d__0 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IDisposable, IEnumerator
			{
				private int <>1__state;

				private CodeInstruction <>2__current;

				private int <>l__initialThreadId;

				private IEnumerable<CodeInstruction> instructions;

				public IEnumerable<CodeInstruction> <>3__instructions;

				private <>c__DisplayClass0_0 <>8__1;

				private bool <patchedSuccess>5__2;

				private List<CodeInstruction> <instrs>5__3;

				private CodeInstruction <ldArgInstruction>5__4;

				private MethodInfo <countItemsMethod>5__5;

				private int <i>5__6;

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

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

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

				[DebuggerHidden]
				void IDisposable.Dispose()
				{
					<instrs>5__3 = null;
					<ldArgInstruction>5__4 = null;
					<countItemsMethod>5__5 = null;
					<>1__state = -2;
				}

				private bool MoveNext()
				{
					//IL_005d: Unknown result type (might be due to invalid IL or missing references)
					//IL_0067: Expected O, but got Unknown
					//IL_020a: Unknown result type (might be due to invalid IL or missing references)
					//IL_021a: Expected O, but got Unknown
					//IL_0265: Unknown result type (might be due to invalid IL or missing references)
					//IL_0275: Expected O, but got Unknown
					//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
					//IL_02d0: Expected O, but got Unknown
					//IL_031b: Unknown result type (might be due to invalid IL or missing references)
					//IL_032b: Expected O, but got Unknown
					int counter;
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<patchedSuccess>5__2 = false;
						<instrs>5__3 = instructions.ToList();
						<>8__1.counter = 0;
						<ldArgInstruction>5__4 = new CodeInstruction(OpCodes.Ldarg_2, (object)null);
						<countItemsMethod>5__5 = AccessTools.DeclaredMethod(typeof(Inventory), "CountItems", new Type[3]
						{
							typeof(string),
							typeof(int),
							typeof(bool)
						}, (Type[])null);
						<i>5__6 = 0;
						break;
					case 1:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						if (<i>5__6 > 5 && <instrs>5__3[<i>5__6 - 1].opcode == OpCodes.Callvirt && <instrs>5__3[<i>5__6 - 1].operand.Equals(<countItemsMethod>5__5) && <instrs>5__3[<i>5__6].opcode == OpCodes.Stloc_S)
						{
							if (<instrs>5__3[<i>5__6].labels.Count > 0)
							{
								CodeInstructionExtensions.MoveLabelsTo(<instrs>5__3[<i>5__6], <ldArgInstruction>5__4);
							}
							<>2__current = <Transpiler>g__LogMessage|0_0(<ldArgInstruction>5__4, ref <>8__1);
							<>1__state = 2;
							return true;
						}
						goto IL_0361;
					case 2:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<>2__current = <Transpiler>g__LogMessage|0_0(new CodeInstruction(OpCodes.Ldarg_1, (object)null), ref <>8__1);
						<>1__state = 3;
						return true;
					case 3:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<>2__current = <Transpiler>g__LogMessage|0_0(new CodeInstruction(OpCodes.Ldloc_S, <instrs>5__3[<i>5__6].operand), ref <>8__1);
						<>1__state = 4;
						return true;
					case 4:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<>2__current = <Transpiler>g__LogMessage|0_0(new CodeInstruction(OpCodes.Call, (object)AccessTools.DeclaredMethod(typeof(PlayerPatches), "AdjustCountIfEquipped", (Type[])null, (Type[])null)), ref <>8__1);
						<>1__state = 5;
						return true;
					case 5:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<>2__current = <Transpiler>g__LogMessage|0_0(new CodeInstruction(OpCodes.Stloc_S, <instrs>5__3[<i>5__6].operand), ref <>8__1);
						<>1__state = 6;
						return true;
					case 6:
						{
							<>1__state = -1;
							counter = <>8__1.counter;
							<>8__1.counter = counter + 1;
							<patchedSuccess>5__2 = true;
							goto IL_0361;
						}
						IL_0361:
						counter = <i>5__6 + 1;
						<i>5__6 = counter;
						break;
					}
					if (<i>5__6 < <instrs>5__3.Count)
					{
						<>2__current = <Transpiler>g__LogMessage|0_0(<instrs>5__3[<i>5__6], ref <>8__1);
						<>1__state = 1;
						return true;
					}
					if (!<patchedSuccess>5__2)
					{
						AdventureBackpacks.Log.Error("InventoryGui.SetupRequirement Transpiler Failed To Patch");
						Thread.Sleep(5000);
					}
					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]
				IEnumerator<CodeInstruction> IEnumerable<CodeInstruction>.GetEnumerator()
				{
					<Transpiler>d__0 <Transpiler>d__;
					if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
					{
						<>1__state = 0;
						<Transpiler>d__ = this;
					}
					else
					{
						<Transpiler>d__ = new <Transpiler>d__0(0);
					}
					<Transpiler>d__.instructions = <>3__instructions;
					return <Transpiler>d__;
				}

				[DebuggerHidden]
				IEnumerator IEnumerable.GetEnumerator()
				{
					return ((IEnumerable<CodeInstruction>)this).GetEnumerator();
				}
			}

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

			[CompilerGenerated]
			internal static CodeInstruction <Transpiler>g__LogMessage|0_0(CodeInstruction instruction, ref <>c__DisplayClass0_0 P_1)
			{
				AdventureBackpacks.Log.Debug($"IL_{P_1.counter}: Opcode: {instruction.opcode} Operand: {instruction.operand}");
				return instruction;
			}
		}

		public static bool BackpackIsOpen;

		public static bool BackpackEquipped;

		private static bool _showBackpack;

		public static bool CheckForTextInput()
		{
			return TextInput.IsVisible();
		}

		public static void ShowBackpack(Player player, InventoryGui instance)
		{
			if (ConfigRegistry.OpenWithInventory.Value && !BackpackIsOpen && player.CanOpenBackpack())
			{
				_showBackpack = true;
			}
			if (_showBackpack)
			{
				if (!BackpackIsOpen && (Object)(object)instance.m_currentContainer != (Object)null)
				{
					instance.m_currentContainer.SetInUse(false);
					instance.m_currentContainer = null;
				}
				_showBackpack = false;
				player.OpenBackpack(instance);
			}
		}

		public static void HideBackpack(InventoryGui instance)
		{
			if (BackpackIsOpen)
			{
				instance.CloseContainer();
				BackpackIsOpen = false;
				if (ConfigRegistry.CloseInventory.Value && !ConfigRegistry.OpenWithHoverInteract.Value)
				{
					instance.Hide();
				}
			}
		}

		public static bool DetectInputToHide(Player player, InventoryGui instance)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			KeyboardShortcut value = ConfigRegistry.HotKeyOpen.Value;
			bool keyDown = ZInput.GetKeyDown(((KeyboardShortcut)(ref value)).MainKey, true);
			bool flag = ConfigRegistry.CloseInventory.Value && keyDown && !ConfigRegistry.OpenWithHoverInteract.Value;
			int num;
			if (ConfigRegistry.OutwardMode.Value)
			{
				value = ConfigRegistry.HotKeyDrop.Value;
				num = (ZInput.GetKeyDown(((KeyboardShortcut)(ref value)).MainKey, true) ? 1 : 0);
			}
			else
			{
				num = 0;
			}
			bool flag2 = (byte)num != 0;
			bool flag3 = keyDown && !BackpackIsOpen && player.CanOpenBackpack() && !ConfigRegistry.OpenWithHoverInteract.Value;
			List<InventoryGrid> list = new List<InventoryGrid>();
			list.AddRange(((Component)instance.m_player).GetComponentsInChildren<InventoryGrid>());
			if (keyDown && !BackpackIsOpen && ConfigRegistry.OpenWithHoverInteract.Value && !CheckForTextInput())
			{
				ItemData val = null;
				foreach (InventoryGrid item in list)
				{
					if (item.GetHoveredElement() != null)
					{
						Element hoveredElement = item.GetHoveredElement();
						val = item.GetInventory().GetItemAt(hoveredElement.m_pos.x, hoveredElement.m_pos.y);
					}
				}
				if (ZInput.IsGamepadActive() && val == null)
				{
					foreach (InventoryGrid item2 in list)
					{
						if (item2.GetGamepadSelectedItem() != null)
						{
							val = item2.GetGamepadSelectedItem();
						}
					}
				}
				if (val != null && val.IsBackpack() && val.m_equipped && !BackpackIsOpen && player.CanOpenBackpack())
				{
					flag3 = true;
				}
			}
			if (flag3 & !CheckForTextInput())
			{
				if ((Object)(object)instance.m_currentContainer != (Object)null)
				{
					instance.m_currentContainer.SetInUse(false);
					instance.m_currentContainer = null;
				}
				player.OpenBackpack(instance);
				return false;
			}
			if (keyDown && BackpackIsOpen && (!flag || ConfigRegistry.OpenWithHoverInteract.Value) && !CheckForTextInput())
			{
				bool flag4 = false;
				if (ConfigRegistry.OpenWithHoverInteract.Value)
				{
					ItemData val2 = null;
					foreach (InventoryGrid item3 in list)
					{
						if (item3.GetHoveredElement() != null)
						{
							Element hoveredElement2 = item3.GetHoveredElement();
							val2 = item3.GetInventory().GetItemAt(hoveredElement2.m_pos.x, hoveredElement2.m_pos.y);
						}
					}
					if (ZInput.IsGamepadActive() && val2 == null)
					{
						foreach (InventoryGrid item4 in list)
						{
							if (item4.GetGamepadSelectedItem() != null)
							{
								val2 = item4.GetGamepadSelectedItem();
							}
						}
					}
					if (val2 != null && val2.IsBackpack() && val2.m_equipped && BackpackIsOpen)
					{
						flag4 = true;
					}
				}
				else
				{
					flag4 = true;
				}
				if (flag4)
				{
					instance.CloseContainer();
					BackpackIsOpen = false;
					return false;
				}
			}
			if (flag2 && !CheckForTextInput())
			{
				player.QuickDropBackpack();
			}
			if (flag || flag2)
			{
				return !CheckForTextInput();
			}
			return false;
		}

		public static bool DetectInputToShow(Player player, InventoryGui instance)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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_002e: 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)
			KeyboardShortcut value = ConfigRegistry.HotKeyOpen.Value;
			bool keyDown = ZInput.GetKeyDown(((KeyboardShortcut)(ref value)).MainKey, true);
			if (ConfigRegistry.OutwardMode.Value)
			{
				value = ConfigRegistry.HotKeyDrop.Value;
				if (ZInput.GetKeyDown(((KeyboardShortcut)(ref value)).MainKey, true) && !CheckForTextInput())
				{
					player.QuickDropBackpack();
				}
			}
			if (keyDown && !ConfigRegistry.OpenWithHoverInteract.Value && !BackpackIsOpen && player.CanOpenBackpack() && !CheckForTextInput())
			{
				_showBackpack = true;
			}
			if (_showBackpack)
			{
				return !CheckForTextInput();
			}
			return false;
		}
	}
	public class ItemDropPatches
	{
		[HarmonyPatch(typeof(ItemData), "GetWeight")]
		private static class ItemDataGetWeightTranspiler
		{
			[StructLayout(LayoutKind.Auto)]
			[CompilerGenerated]
			private struct <>c__DisplayClass1_0
			{
				public int counter;
			}

			[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;

				private IEnumerable<CodeInstruction> instructions;

				public IEnumerable<CodeInstruction> <>3__instructions;

				private <>c__DisplayClass1_0 <>8__1;

				private bool <patchedSuccess>5__2;

				private List<CodeInstruction> <instrs>5__3;

				private FieldInfo <scaleWeightByQualityField>5__4;

				private int <i>5__5;

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

				object IEnumerator.Current
				{
					[DebuggerHidden]
					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()
				{
					<instrs>5__3 = null;
					<scaleWeightByQualityField>5__4 = null;
					<>1__state = -2;
				}

				private bool MoveNext()
				{
					//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
					//IL_0206: Expected O, but got Unknown
					//IL_0251: Unknown result type (might be due to invalid IL or missing references)
					//IL_0261: Expected O, but got Unknown
					//IL_0297: Unknown result type (might be due to invalid IL or missing references)
					//IL_02a7: Expected O, but got Unknown
					//IL_0177: Unknown result type (might be due to invalid IL or missing references)
					//IL_017d: Expected O, but got Unknown
					int counter;
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<patchedSuccess>5__2 = false;
						<instrs>5__3 = instructions.ToList();
						<>8__1.counter = 0;
						<scaleWeightByQualityField>5__4 = AccessTools.DeclaredField(typeof(SharedData), "m_scaleWeightByQuality");
						<i>5__5 = 0;
						break;
					case 1:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<>2__current = <Transpiler>g__LogMessage|1_0(new CodeInstruction(OpCodes.Ldloc_1, (object)null), ref <>8__1);
						<>1__state = 2;
						return true;
					case 2:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<>2__current = <Transpiler>g__LogMessage|1_0(new CodeInstruction(OpCodes.Call, (object)AccessTools.DeclaredMethod(typeof(ItemDataGetWeightTranspiler), "OverrideBackpackWeight", (Type[])null, (Type[])null)), ref <>8__1);
						<>1__state = 3;
						return true;
					case 3:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<>2__current = <Transpiler>g__LogMessage|1_0(new CodeInstruction(OpCodes.Stloc_1, (object)null), ref <>8__1);
						<>1__state = 4;
						return true;
					case 4:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<>2__current = <Transpiler>g__LogMessage|1_0(<instrs>5__3[<i>5__5], ref <>8__1);
						<>1__state = 5;
						return true;
					case 5:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<patchedSuccess>5__2 = true;
						goto IL_0377;
					case 6:
						{
							<>1__state = -1;
							counter = <>8__1.counter;
							<>8__1.counter = counter + 1;
							goto IL_0377;
						}
						IL_0377:
						counter = <i>5__5 + 1;
						<i>5__5 = counter;
						break;
					}
					if (<i>5__5 < <instrs>5__3.Count)
					{
						if (<i>5__5 > 6 && <instrs>5__3[<i>5__5].opcode == OpCodes.Ldloc_1 && <instrs>5__3[<i>5__5 - 1].opcode == OpCodes.Stloc_1 && <instrs>5__3[<i>5__5 - 2].opcode == OpCodes.Add && <instrs>5__3[<i>5__5 - 3].opcode == OpCodes.Mul && <instrs>5__3[<i>5__5 - 4].opcode == OpCodes.Ldfld && <instrs>5__3[<i>5__5 - 4].operand.Equals(<scaleWeightByQualityField>5__4))
						{
							CodeInstruction val = new CodeInstruction(OpCodes.Ldarg_0, (object)null);
							if (<instrs>5__3[<i>5__5].labels.Count > 0)
							{
								CodeInstructionExtensions.MoveLabelsTo(<instrs>5__3[<i>5__5], val);
							}
							<>2__current = <Transpiler>g__LogMessage|1_0(val, ref <>8__1);
							<>1__state = 1;
							return true;
						}
						<>2__current = <Transpiler>g__LogMessage|1_0(<instrs>5__3[<i>5__5], ref <>8__1);
						<>1__state = 6;
						return true;
					}
					if (!<patchedSuccess>5__2)
					{
						AdventureBackpacks.Log.Error("GetWeight Transpiler Failed To Patch");
						Thread.Sleep(5000);
					}
					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]
				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__.instructions = <>3__instructions;
					return <Transpiler>d__;
				}

				[DebuggerHidden]
				IEnumerator IEnumerable.GetEnumerator()
				{
					return ((IEnumerable<CodeInstruction>)this).GetEnumerator();
				}
			}

			public static float OverrideBackpackWeight(ItemData item, float originalWeight)
			{
				//IL_0041: Unknown result type (might be due to invalid IL or missing references)
				//IL_0046: Unknown result type (might be due to invalid IL or missing references)
				//IL_0050: Unknown result type (might be due to invalid IL or missing references)
				float num = originalWeight;
				if (!string.IsNullOrEmpty(item.m_shared.m_name) && item.TryGetBackpackItem(out var backpack))
				{
					BackpackComponent orCreate = item.Data().GetOrCreate<BackpackComponent>();
					Vector2i inventorySize = backpack.GetInventorySize(orCreate.Item.m_quality);
					if (!orCreate.IsEmptyingBackpack && orCreate.InventoryNeedsValidating(inventorySize))
					{
						AdventureBackpacks.Log.Debug("[GetWeight() - Item Name: " + item.m_shared.m_name);
						AdventureBackpacks.Log.Debug("[GetWeight() - Backpack Item: " + orCreate.Item.m_shared.m_name);
						AdventureBackpacks.Log.Debug("[GetWeight() - Backpack: " + backpack.ItemName);
						Backpacks.ValidateBackpackInventorySizing(Player.m_localPlayer, orCreate.Item);
					}
					Inventory inventory = orCreate.GetInventory();
					float num2 = ((inventory != null) ? inventory.GetTotalWeight() : 0f);
					num += num2 * backpack.WeightMultiplier.Value;
				}
				return num;
			}

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

			[CompilerGenerated]
			internal static CodeInstruction <Transpiler>g__LogMessage|1_0(CodeInstruction instruction, ref <>c__DisplayClass1_0 P_1)
			{
				AdventureBackpacks.Log.Debug($"IL_{P_1.counter}: Opcode: {instruction.opcode} Operand: {instruction.operand}");
				return instruction;
			}
		}
	}
	public class PlayerPatches
	{
		[HarmonyPatch(typeof(Player), "Awake")]
		private static class PlayerAwakePatch
		{
			private static void Postfix(Player __instance)
			{
				((Component)__instance).gameObject.AddComponent<Container>();
			}
		}

		[HarmonyPatch(typeof(Player), "HaveRequirementItems")]
		private static class PlayerHaveRequirementItemsPatch
		{
			[StructLayout(LayoutKind.Auto)]
			[CompilerGenerated]
			private struct <>c__DisplayClass0_0
			{
				public int counter;
			}

			[CompilerGenerated]
			private sealed class <Transpiler>d__0 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IDisposable, IEnumerator
			{
				private int <>1__state;

				private CodeInstruction <>2__current;

				private int <>l__initialThreadId;

				private IEnumerable<CodeInstruction> instructions;

				public IEnumerable<CodeInstruction> <>3__instructions;

				private <>c__DisplayClass0_0 <>8__1;

				private bool <patchedSuccess>5__2;

				private List<CodeInstruction> <instrs>5__3;

				private CodeInstruction <ldArgInstruction>5__4;

				private int <i>5__5;

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

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

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

				[DebuggerHidden]
				void IDisposable.Dispose()
				{
					<instrs>5__3 = null;
					<ldArgInstruction>5__4 = null;
					<>1__state = -2;
				}

				private bool MoveNext()
				{
					//IL_0061: Unknown result type (might be due to invalid IL or missing references)
					//IL_006b: Expected O, but got Unknown
					//IL_022f: Unknown result type (might be due to invalid IL or missing references)
					//IL_023f: Expected O, but got Unknown
					//IL_028a: Unknown result type (might be due to invalid IL or missing references)
					//IL_029a: Expected O, but got Unknown
					//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
					//IL_02f5: Expected O, but got Unknown
					//IL_0340: Unknown result type (might be due to invalid IL or missing references)
					//IL_0350: Expected O, but got Unknown
					int counter;
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<patchedSuccess>5__2 = false;
						<instrs>5__3 = instructions.ToList();
						<>8__1.counter = 0;
						<ldArgInstruction>5__4 = new CodeInstruction(OpCodes.Ldarg_0, (object)null);
						AccessTools.DeclaredMethod(typeof(Inventory), "CountItems", new Type[3]
						{
							typeof(string),
							typeof(int),
							typeof(bool)
						}, (Type[])null);
						<i>5__5 = 0;
						break;
					case 1:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<>2__current = <Transpiler>g__LogMessage|0_0(<ldArgInstruction>5__4, ref <>8__1);
						<>1__state = 2;
						return true;
					case 2:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<>2__current = <Transpiler>g__LogMessage|0_0(new CodeInstruction(OpCodes.Ldloc_2, (object)null), ref <>8__1);
						<>1__state = 3;
						return true;
					case 3:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<>2__current = <Transpiler>g__LogMessage|0_0(new CodeInstruction(OpCodes.Ldloc_S, <instrs>5__3[<i>5__5].operand), ref <>8__1);
						<>1__state = 4;
						return true;
					case 4:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<>2__current = <Transpiler>g__LogMessage|0_0(new CodeInstruction(OpCodes.Call, (object)AccessTools.DeclaredMethod(typeof(PlayerPatches), "AdjustCountIfEquipped", (Type[])null, (Type[])null)), ref <>8__1);
						<>1__state = 5;
						return true;
					case 5:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<>2__current = <Transpiler>g__LogMessage|0_0(new CodeInstruction(OpCodes.Stloc_S, <instrs>5__3[<i>5__5].operand), ref <>8__1);
						<>1__state = 6;
						return true;
					case 6:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						<patchedSuccess>5__2 = true;
						goto IL_03d4;
					case 7:
						{
							<>1__state = -1;
							counter = <>8__1.counter;
							<>8__1.counter = counter + 1;
							goto IL_03d4;
						}
						IL_03d4:
						counter = <i>5__5 + 1;
						<i>5__5 = counter;
						break;
					}
					if (<i>5__5 < <instrs>5__3.Count)
					{
						if (<i>5__5 > 5 && <instrs>5__3[<i>5__5].opcode == OpCodes.Stloc_S && <instrs>5__3[<i>5__5 + 1].opcode == OpCodes.Ldloc_S && <instrs>5__3[<i>5__5 + 2].opcode == OpCodes.Ldloc_S && <instrs>5__3[<i>5__5 - 1].opcode == OpCodes.Callvirt)
						{
							if (<instrs>5__3[<i>5__5].labels.Count > 0)
							{
								CodeInstructionExtensions.MoveLabelsTo(<instrs>5__3[<i>5__5], <ldArgInstruction>5__4);
							}
							<>2__current = <Transpiler>g__LogMessage|0_0(<instrs>5__3[<i>5__5], ref <>8__1);
							<>1__state = 1;
							return true;
						}
						<>2__current = <Transpiler>g__LogMessage|0_0(<instrs>5__3[<i>5__5], ref <>8__1);
						<>1__state = 7;
						return true;
					}
					if (!<patchedSuccess>5__2)
					{
						AdventureBackpacks.Log.Error("HaveRequirementItems Transpiler Failed To Patch");
						Thread.Sleep(5000);
					}
					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]
				IEnumerator<CodeInstruction> IEnumerable<CodeInstruction>.GetEnumerator()
				{
					<Transpiler>d__0 <Transpiler>d__;
					if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
					{
						<>1__state = 0;
						<Transpiler>d__ = this;
					}
					else
					{
						<Transpiler>d__ = new <Transpiler>d__0(0);
					}
					<Transpiler>d__.instructions = <>3__instructions;
					return <Transpiler>d__;
				}

				[DebuggerHidden]
				IEnumerator IEnumerable.GetEnumerator()
				{
					return ((IEnumerable<CodeInstruction>)this).GetEnumerator();
				}
			}

			[IteratorStateMachine(typeof(<Transpiler>d__0))]
			public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator ilGenerator)
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <Transpiler>d__0(-2)
				{
					<>3__instructions = instructions
				};
			}

			[CompilerGenerated]
			internal static CodeInstruction <Transpiler>g__LogMessage|0_0(CodeInstruction instruction, ref <>c__DisplayClass0_0 P_1)
			{
				AdventureBackpacks.Log.Debug($"IL_{P_1.counter}: Opcode: {instruction.opcode} Operand: {instruction.operand}");
				return instruction;
			}
		}

		[HarmonyPatch(typeof(Player), "ConsumeResources")]
		private static class PlayerConsumeResourcesPatch
		{
			[StructLayout(LayoutKind.Auto)]
			[CompilerGenerated]
			private struct <>c__DisplayClass0_0
			{
				public int counter;
			}

			[CompilerGenerated]
			private sealed class <Transpiler>d__0 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IDisposable, IEnumerator
			{
				private int <>1__state;

				private CodeInstruction <>2__current;

				private int <>l__initialThreadId;

				private IEnumerable<CodeInstruction> instructions;

				public IEnumerable<CodeInstruction> <>3__instructions;

				private <>c__DisplayClass0_0 <>8__1;

				private bool <patchedSuccess>5__2;

				private List<CodeInstruction> <instrs>5__3;

				private CodeInstruction <ldArgInstruction>5__4;

				private MethodInfo <getAmountMethod>5__5;

				private int <i>5__6;

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

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

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

				[DebuggerHidden]
				void IDisposable.Dispose()
				{
					<instrs>5__3 = null;
					<ldArgInstruction>5__4 = null;
					<getAmountMethod>5__5 = null;
					<>1__state = -2;
				}

				private bool MoveNext()
				{
					//IL_005d: Unknown result type (might be due to invalid IL or missing references)
					//IL_0067: Expected O, but got Unknown
					//IL_023e: Unknown result type (might be due to invalid IL or missing references)
					//IL_024e: Expected O, but got Unknown
					//IL_0284: Unknown result type (might be due to invalid IL or missing references)
					//IL_0294: Expected O, but got Unknown
					//IL_02df: Unknown result type (might be due to invalid IL or missing references)
					//IL_02ef: Expected O, but got Unknown
					//IL_0325: Unknown result type (might be due to invalid IL or missing references)
					//IL_0335: Expected O, but got Unknown
					int counter;
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<patchedSuccess>5__2 = false;
						<instrs>5__3 = instructions.ToList();
						<>8__1.counter = 0;
						<ldArgInstruction>5__4 = new CodeInstruction(OpCodes.Ldarg_0, (object)null);
						<getAmountMethod>5__5 = AccessTools.DeclaredMethod(typeof(Requirement), "GetAmount", new Type[1] { typeof(int) }, (Type[])null);
						<i>5__6 = 0;
						break;
					case 1:
						<>1__state = -1;
						counter = <>8__1.counter;
						<>8__1.counter = counter + 1;
						if (<i>5__6 > 5 && <instrs>5__3[<i>5__6].opcode == OpCodes.Stloc_3 && <instrs>5__3[<i>5__6 - 1].opcode == OpCodes.Mul