Decompiled source of TrophyPouch v0.1.2

TrophyPouch.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn.Managers;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("TrophyPouch")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+dec50e41e583b474ca073cfec7303ef9f0d18999")]
[assembly: AssemblyProduct("TrophyPouch")]
[assembly: AssemblyTitle("TrophyPouch")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace TrophyPouch
{
	public static class Pouch
	{
		[HarmonyPatch(typeof(Inventory), "AddItem", new Type[] { typeof(ItemData) })]
		private static class CaptureAdd
		{
			private static bool Prefix(Inventory __instance, ItemData item, ref bool __result)
			{
				if (Bypass || !IsLocal(__instance) || !IsTrophy(item))
				{
					return true;
				}
				Add(item, item.m_stack);
				__result = true;
				return false;
			}
		}

		[HarmonyPatch(typeof(Inventory), "AddItem", new Type[]
		{
			typeof(ItemData),
			typeof(int),
			typeof(int),
			typeof(int),
			typeof(bool)
		})]
		private static class CaptureAddAt
		{
			private static bool Prefix(Inventory __instance, ItemData item, int amount, ref bool __result)
			{
				if (Bypass || !IsLocal(__instance) || !IsTrophy(item))
				{
					return true;
				}
				amount = Mathf.Min(amount, item.m_stack);
				Add(item, amount);
				item.m_stack -= amount;
				__result = true;
				return false;
			}
		}

		[HarmonyPatch(typeof(Player), "Update")]
		private static class SweepOnSpawn
		{
			private static void Postfix(Player __instance)
			{
				if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && !s_swept && TrophyPouchPlugin.SweepOnLoad.Value)
				{
					s_swept = true;
					Sweep(__instance);
				}
			}
		}

		[HarmonyPatch(typeof(Player), "Awake")]
		private static class ResetSweep
		{
			private static void Postfix()
			{
				s_swept = false;
			}
		}

		[HarmonyPatch(typeof(Inventory), "CountItems")]
		private static class PoolCount
		{
			private static void Postfix(Inventory __instance, string name, ref int __result)
			{
				if (!Bypass && IsLocal(__instance))
				{
					__result += Count(name);
				}
			}
		}

		[HarmonyPatch(typeof(Inventory), "HaveItem", new Type[]
		{
			typeof(string),
			typeof(bool)
		})]
		private static class PoolHave
		{
			private static void Postfix(Inventory __instance, string name, ref bool __result)
			{
				if (!__result && !Bypass && IsLocal(__instance))
				{
					__result = Count(name) > 0;
				}
			}
		}

		[HarmonyPatch(typeof(Inventory), "RemoveItem", new Type[]
		{
			typeof(string),
			typeof(int),
			typeof(int),
			typeof(bool)
		})]
		private static class PoolRemove
		{
			private static int s_depth;

			[HarmonyPriority(800)]
			private static void Prefix(Inventory __instance, string name, ref int amount)
			{
				if (s_depth++ <= 0 && IsLocal(__instance) && amount > 0 && Count(name) != 0)
				{
					Bypass = true;
					int num;
					try
					{
						num = __instance.CountItems(name, -1, true);
					}
					finally
					{
						Bypass = false;
					}
					int num2 = Mathf.Max(0, amount - num);
					if (num2 > 0)
					{
						Remove(name, num2);
						amount -= num2;
					}
				}
			}

			private static void Postfix()
			{
				s_depth--;
			}
		}

		private const string Key = "TrophyPouch";

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

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

		private static Player s_loadedFor;

		public static bool Bypass;

		public static bool Dirty = true;

		private static bool s_swept;

		public static IEnumerable<KeyValuePair<string, int>> All => s_counts;

		public static int Total
		{
			get
			{
				int num = 0;
				foreach (int value in s_counts.Values)
				{
					num += value;
				}
				return num;
			}
		}

		public static bool IsTrophy(ItemData item)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Invalid comparison between Unknown and I4
			if (item?.m_shared != null)
			{
				return (int)item.m_shared.m_itemType == 13;
			}
			return false;
		}

		public static bool IsLocal(Inventory inv)
		{
			if (Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				return ((Humanoid)Player.m_localPlayer).GetInventory() == inv;
			}
			return false;
		}

		private static void EnsureLoaded()
		{
			Player localPlayer = Player.m_localPlayer;
			if (!Object.op_Implicit((Object)(object)localPlayer) || (Object)(object)s_loadedFor == (Object)(object)localPlayer)
			{
				return;
			}
			s_loadedFor = localPlayer;
			s_counts.Clear();
			if (localPlayer.m_customData.TryGetValue("TrophyPouch", out var value))
			{
				string[] array = value.Split(new char[1] { ',' });
				for (int i = 0; i < array.Length; i++)
				{
					string[] array2 = array[i].Split(new char[1] { ':' });
					if (array2.Length == 2 && int.TryParse(array2[1], out var result) && result > 0)
					{
						s_counts[array2[0]] = result;
					}
				}
			}
			Dirty = true;
		}

		private static void Save()
		{
			Player localPlayer = Player.m_localPlayer;
			if (!Object.op_Implicit((Object)(object)localPlayer))
			{
				return;
			}
			StringBuilder stringBuilder = new StringBuilder();
			foreach (KeyValuePair<string, int> s_count in s_counts)
			{
				if (stringBuilder.Length > 0)
				{
					stringBuilder.Append(',');
				}
				stringBuilder.Append(s_count.Key).Append(':').Append(s_count.Value);
			}
			localPlayer.m_customData["TrophyPouch"] = stringBuilder.ToString();
			Dirty = true;
		}

		public static string PrefabName(ItemData item)
		{
			if (Object.op_Implicit((Object)(object)item.m_dropPrefab))
			{
				return ((Object)item.m_dropPrefab).name;
			}
			return SharedToPrefab(item.m_shared.m_name);
		}

		private static string SharedToPrefab(string shared)
		{
			if (s_prefabByShared.Count == 0 && Object.op_Implicit((Object)(object)ObjectDB.instance))
			{
				foreach (GameObject item in ObjectDB.instance.m_items)
				{
					ItemDrop val = (Object.op_Implicit((Object)(object)item) ? item.GetComponent<ItemDrop>() : null);
					if (Object.op_Implicit((Object)(object)val) && IsTrophy(val.m_itemData))
					{
						s_prefabByShared[val.m_itemData.m_shared.m_name] = ((Object)item).name;
					}
				}
			}
			if (!s_prefabByShared.TryGetValue(shared, out var value))
			{
				return null;
			}
			return value;
		}

		public static void Add(ItemData item, int amount)
		{
			EnsureLoaded();
			string text = PrefabName(item);
			if (text != null && amount > 0)
			{
				s_counts.TryGetValue(text, out var value);
				s_counts[text] = value + amount;
				Save();
			}
		}

		public static int Count(string sharedName)
		{
			EnsureLoaded();
			string text = SharedToPrefab(sharedName);
			if (text == null || !s_counts.TryGetValue(text, out var value))
			{
				return 0;
			}
			return value;
		}

		public static int Remove(string sharedName, int amount)
		{
			EnsureLoaded();
			string text = SharedToPrefab(sharedName);
			if (text == null || !s_counts.TryGetValue(text, out var value))
			{
				return 0;
			}
			int num = Mathf.Min(value, amount);
			if (value - num <= 0)
			{
				s_counts.Remove(text);
			}
			else
			{
				s_counts[text] = value - num;
			}
			Save();
			return num;
		}

		public static int RemoveByPrefab(string prefab, int amount)
		{
			EnsureLoaded();
			if (!s_counts.TryGetValue(prefab, out var value))
			{
				return 0;
			}
			int num = Mathf.Min(value, amount);
			if (value - num <= 0)
			{
				s_counts.Remove(prefab);
			}
			else
			{
				s_counts[prefab] = value - num;
			}
			Save();
			return num;
		}

		public static bool Take(string prefab)
		{
			EnsureLoaded();
			Player localPlayer = Player.m_localPlayer;
			if (!Object.op_Implicit((Object)(object)localPlayer) || !s_counts.TryGetValue(prefab, out var value) || value <= 0)
			{
				return false;
			}
			GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(prefab);
			if (!Object.op_Implicit((Object)(object)itemPrefab))
			{
				return false;
			}
			Bypass = true;
			bool flag;
			try
			{
				flag = ((Humanoid)localPlayer).GetInventory().AddItem(itemPrefab, 1);
			}
			finally
			{
				Bypass = false;
			}
			if (!flag)
			{
				((Character)localPlayer).Message((MessageType)2, "$msg_noroom", 0, (Sprite)null, false);
				return false;
			}
			if (value - 1 <= 0)
			{
				s_counts.Remove(prefab);
			}
			else
			{
				s_counts[prefab] = value - 1;
			}
			Save();
			return true;
		}

		public static void Sweep(Player p)
		{
			Inventory inventory = ((Humanoid)p).GetInventory();
			foreach (ItemData item in new List<ItemData>(inventory.GetAllItems()))
			{
				if (IsTrophy(item))
				{
					Add(item, item.m_stack);
					inventory.RemoveItem(item);
				}
			}
		}
	}
	public static class PouchPanel
	{
		[HarmonyPatch(typeof(InventoryGui), "Awake")]
		private static class MakeButton
		{
			[CompilerGenerated]
			private static class <>O
			{
				public static UnityAction <0>__Toggle;
			}

			private static void Postfix(InventoryGui __instance)
			{
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_0042: Expected O, but got Unknown
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0061: Unknown result type (might be due to invalid IL or missing references)
				//IL_0067: Expected O, but got Unknown
				//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
				//IL_00db: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
				//IL_010e: Unknown result type (might be due to invalid IL or missing references)
				if (Object.op_Implicit((Object)(object)__instance.m_takeAllButton))
				{
					s_button = Object.Instantiate<Button>(__instance.m_takeAllButton, (Transform)(object)__instance.m_player);
					((Object)s_button).name = "TrophyPouchButton";
					s_button.onClick = new ButtonClickedEvent();
					ButtonClickedEvent onClick = s_button.onClick;
					object obj = <>O.<0>__Toggle;
					if (obj == null)
					{
						UnityAction val = Toggle;
						<>O.<0>__Toggle = val;
						obj = (object)val;
					}
					((UnityEvent)onClick).AddListener((UnityAction)obj);
					TMP_Text componentInChildren = ((Component)s_button).GetComponentInChildren<TMP_Text>();
					if (Object.op_Implicit((Object)(object)componentInChildren))
					{
						componentInChildren.text = "T";
						componentInChildren.alignment = (TextAlignmentOptions)514;
						componentInChildren.enableAutoSizing = false;
						componentInChildren.fontSize = 20f;
					}
					RectTransform component = ((Component)s_button).GetComponent<RectTransform>();
					Vector2 val2 = default(Vector2);
					((Vector2)(ref val2))..ctor(1f, 0f);
					component.anchorMax = val2;
					component.anchorMin = val2;
					component.pivot = new Vector2(0.5f, 0.5f);
					component.sizeDelta = new Vector2(38f, 38f);
					component.anchoredPosition = new Vector2(TrophyPouchPlugin.ButtonX.Value, TrophyPouchPlugin.ButtonY.Value);
					UITooltip component2 = ((Component)s_button).GetComponent<UITooltip>();
					if (Object.op_Implicit((Object)(object)component2))
					{
						component2.m_text = "Trophy pouch";
						component2.m_topic = "";
					}
					s_panel = null;
					s_open = false;
				}
			}
		}

		[HarmonyPatch(typeof(InventoryGui), "Update")]
		private static class Tick
		{
			private static void Postfix()
			{
				if (Object.op_Implicit((Object)(object)s_panel))
				{
					if (!InventoryGui.IsVisible() && s_open)
					{
						s_open = false;
						s_panel.SetActive(false);
					}
					if (s_open && Pouch.Dirty)
					{
						Refresh();
					}
				}
			}
		}

		private static GameObject s_panel;

		private static Transform s_content;

		private static Button s_button;

		private static bool s_open;

		private const int PerRow = 4;

		private static void Toggle()
		{
			s_open = !s_open;
			if (s_open)
			{
				Build();
				Refresh();
			}
			if (Object.op_Implicit((Object)(object)s_panel))
			{
				s_panel.SetActive(s_open);
			}
		}

		private static void Build()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)s_panel))
			{
				InventoryGui instance = InventoryGui.instance;
				float value = TrophyPouchPlugin.PanelHeight.Value;
				s_panel = GUIManager.Instance.CreateWoodpanel((Transform)(object)instance.m_player, new Vector2(1f, 1f), new Vector2(1f, 1f), new Vector2(240f, 0f), 300f, value, false);
				((Object)s_panel).name = "TrophyPouchPanel";
				s_panel.transform.SetAsFirstSibling();
				RectTransform component = s_panel.GetComponent<RectTransform>();
				component.pivot = new Vector2(0f, 1f);
				component.anchoredPosition = new Vector2(90f, 0f);
				GUIManager.Instance.CreateText("Trophies", s_panel.transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -22f), GUIManager.Instance.AveriaSerifBold, 20, GUIManager.Instance.ValheimOrange, true, Color.black, 260f, 30f, false);
				GameObject val = GUIManager.Instance.CreateScrollView(s_panel.transform, false, true, 8f, 4f, GUIManager.Instance.ValheimScrollbarHandleColorBlock, new Color(0f, 0f, 0f, 0.3f), 270f, value - 60f);
				GraphicRaycaster[] componentsInChildren = val.GetComponentsInChildren<GraphicRaycaster>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					Object.DestroyImmediate((Object)(object)componentsInChildren[i]);
				}
				CanvasScaler[] componentsInChildren2 = val.GetComponentsInChildren<CanvasScaler>(true);
				for (int i = 0; i < componentsInChildren2.Length; i++)
				{
					Object.DestroyImmediate((Object)(object)componentsInChildren2[i]);
				}
				Canvas[] componentsInChildren3 = val.GetComponentsInChildren<Canvas>(true);
				for (int i = 0; i < componentsInChildren3.Length; i++)
				{
					Object.DestroyImmediate((Object)(object)componentsInChildren3[i]);
				}
				RectTransform component2 = val.GetComponent<RectTransform>();
				Vector2 val2 = default(Vector2);
				((Vector2)(ref val2))..ctor(0.5f, 1f);
				component2.anchorMax = val2;
				component2.anchorMin = val2;
				component2.pivot = new Vector2(0.5f, 1f);
				component2.anchoredPosition = new Vector2(0f, -44f);
				s_content = ((Component)val.GetComponentInChildren<VerticalLayoutGroup>()).transform;
			}
		}

		private static void Refresh()
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)s_content))
			{
				return;
			}
			for (int num = s_content.childCount - 1; num >= 0; num--)
			{
				Object.Destroy((Object)(object)((Component)s_content.GetChild(num)).gameObject);
			}
			List<KeyValuePair<string, int>> list = new List<KeyValuePair<string, int>>(Pouch.All);
			list.Sort((KeyValuePair<string, int> a, KeyValuePair<string, int> b) => string.CompareOrdinal(a.Key, b.Key));
			if (list.Count == 0)
			{
				GUIManager.Instance.CreateText("Nothing yet.", s_content, new Vector2(0f, 1f), new Vector2(1f, 1f), Vector2.zero, GUIManager.Instance.AveriaSerif, 16, Color.grey, true, Color.black, 240f, 30f, false);
				Pouch.Dirty = false;
				return;
			}
			InventoryGrid playerGrid = InventoryGui.instance.m_playerGrid;
			float elementSpace = playerGrid.m_elementSpace;
			Transform row = null;
			for (int num2 = 0; num2 < list.Count; num2++)
			{
				if (num2 % 4 == 0)
				{
					GameObject val = new GameObject("row", new Type[2]
					{
						typeof(RectTransform),
						typeof(LayoutElement)
					});
					val.transform.SetParent(s_content, false);
					val.GetComponent<LayoutElement>().preferredHeight = elementSpace;
					val.GetComponent<RectTransform>().sizeDelta = new Vector2(4f * elementSpace, elementSpace);
					row = val.transform;
				}
				Slot(row, playerGrid.m_elementPrefab, list[num2].Key, list[num2].Value, (float)(num2 % 4) * elementSpace);
			}
			Pouch.Dirty = false;
		}

		private static void Slot(Transform row, GameObject elementPrefab, string prefab, int count, float x)
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Expected O, but got Unknown
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Expected O, but got Unknown
			GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(prefab);
			ItemDrop val = (Object.op_Implicit((Object)(object)itemPrefab) ? itemPrefab.GetComponent<ItemDrop>() : null);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			ItemData itemData = val.m_itemData;
			GameObject val2 = Object.Instantiate<GameObject>(elementPrefab, row);
			((Object)val2).name = prefab;
			RectTransform component = val2.GetComponent<RectTransform>();
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(0f, 1f);
			component.anchorMax = val3;
			component.anchorMin = val3;
			component.pivot = new Vector2(0f, 1f);
			component.anchoredPosition = new Vector2(x, 0f);
			InventoryElement component2 = val2.GetComponent<InventoryElement>();
			if (Object.op_Implicit((Object)(object)component2))
			{
				((Behaviour)component2.m_icon).enabled = true;
				component2.m_icon.sprite = itemData.GetIcon();
				((Behaviour)component2.m_amount).enabled = true;
				component2.m_amount.text = count.ToString();
				((Behaviour)component2.m_quality).enabled = false;
				((Behaviour)component2.m_equiped).enabled = false;
				((Behaviour)component2.m_queued).enabled = false;
				((Behaviour)component2.m_noteleport).enabled = false;
				((Behaviour)component2.m_food).enabled = false;
				((Component)component2.m_durability).gameObject.SetActive(false);
				if (Object.op_Implicit((Object)(object)component2.m_selected))
				{
					component2.m_selected.SetActive(false);
				}
				if (Object.op_Implicit((Object)(object)component2.m_tooltip))
				{
					UITooltip tooltip = component2.m_tooltip;
					string text = Localization.instance.Localize(itemData.m_shared.m_name);
					string text2 = Localization.instance.Localize(itemData.m_shared.m_description) + "\n\n<color=orange>" + count + "</color> in pouch. Click to take one.";
					val3 = default(Vector2);
					tooltip.Set(text, text2, (RectTransform)null, val3);
				}
			}
			Transform val4 = val2.transform.Find("binding");
			if (Object.op_Implicit((Object)(object)val4))
			{
				((Component)val4).gameObject.SetActive(false);
			}
			UIInputHandler[] componentsInChildren = val2.GetComponentsInChildren<UIInputHandler>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Object.Destroy((Object)(object)componentsInChildren[i]);
			}
			UIDragHandler[] componentsInChildren2 = val2.GetComponentsInChildren<UIDragHandler>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				Object.Destroy((Object)(object)componentsInChildren2[i]);
			}
			Button obj = val2.GetComponent<Button>() ?? val2.AddComponent<Button>();
			obj.onClick = new ButtonClickedEvent();
			((UnityEvent)obj.onClick).AddListener((UnityAction)delegate
			{
				if (Pouch.Take(prefab))
				{
					Refresh();
				}
			});
		}
	}
	public static class StashHook
	{
		[HarmonyPatch(typeof(Inventory), "StackAll")]
		private static class VanillaPlaceStacks
		{
			private static void Postfix(Inventory __instance, Inventory fromInventory, ref int __result)
			{
				if (Pouch.IsLocal(fromInventory) && !Pouch.IsLocal(__instance))
				{
					__result += PourInto(__instance);
				}
			}
		}

		public static int PourInto(Inventory chest)
		{
			int num = 0;
			foreach (KeyValuePair<string, int> item in new List<KeyValuePair<string, int>>(Pouch.All))
			{
				GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(item.Key);
				ItemDrop val = (Object.op_Implicit((Object)(object)itemPrefab) ? itemPrefab.GetComponent<ItemDrop>() : null);
				if (!Object.op_Implicit((Object)(object)val) || !chest.ContainsItemByName(val.m_itemData.m_shared.m_name))
				{
					continue;
				}
				int num2 = item.Value;
				while (num2 > 0)
				{
					ItemData val2 = val.m_itemData.Clone();
					val2.m_stack = Mathf.Min(num2, val2.m_shared.m_maxStackSize);
					int stack = val2.m_stack;
					bool flag = chest.AddItem(val2);
					int num3 = (flag ? stack : (stack - val2.m_stack));
					if (num3 <= 0)
					{
						break;
					}
					Pouch.RemoveByPrefab(item.Key, num3);
					num += num3;
					num2 -= num3;
					if (!flag)
					{
						break;
					}
				}
			}
			return num;
		}

		public static void TryHookReforged(Harmony harmony)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			MethodInfo methodInfo = Type.GetType("InventoryReforged.Stash, InventoryReforged")?.GetMethod("StackInto", BindingFlags.Static | BindingFlags.Public);
			if (!(methodInfo == null))
			{
				harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(StashHook), "ReforgedPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
		}

		private static void ReforgedPostfix(Inventory chest, Inventory from, ref int __result)
		{
			if (Pouch.IsLocal(from))
			{
				__result += PourInto(chest);
			}
		}
	}
	[BepInPlugin("games.loxley.trophypouch", "TrophyPouch", "0.1.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class TrophyPouchPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "games.loxley.trophypouch";

		public const string PluginName = "TrophyPouch";

		public const string PluginVersion = "0.1.2";

		public static ConfigEntry<bool> SweepOnLoad;

		public static ConfigEntry<float> ButtonX;

		public static ConfigEntry<float> ButtonY;

		public static ConfigEntry<float> PanelHeight;

		private void Awake()
		{
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Expected O, but got Unknown
			SweepOnLoad = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "SweepOnLoad", true, "Move trophies already in your bag into the pouch when you spawn.");
			ButtonX = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ButtonX", 33f, "Pouch button centre, relative to the bottom-right corner of the inventory panel.");
			ButtonY = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ButtonY", 126f, "Pouch button centre, relative to the bottom-right corner of the inventory panel.");
			PanelHeight = ((BaseUnityPlugin)this).Config.Bind<float>("General", "PanelHeight", 580f, "Height (px) of the pouch panel. It scrolls past that.");
			Harmony val = new Harmony("games.loxley.trophypouch");
			val.PatchAll();
			StashHook.TryHookReforged(val);
		}
	}
}