Decompiled source of TrophyPouch v0.2.1

TrophyPouch.dll

Decompiled a month 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.EventSystems;
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+6af4a39408baa66ba0e45af523b986c6e1d866ec")]
[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 Filters
	{
		public static readonly string[] Names;

		private static readonly HashSet<string> s_bosses;

		private static readonly Dictionary<string, string> s_biome;

		static Filters()
		{
			Names = new string[13]
			{
				"All", "Creatures", "Bosses", "Meadows", "Black Forest", "Swamp", "Mountain", "Ocean", "Plains", "Mistlands",
				"Ashlands", "Deep North", "Other"
			};
			s_bosses = new HashSet<string> { "TrophyEikthyr", "TrophyTheElder", "TrophyBonemass", "TrophyDragonQueen", "TrophyGoblinKing", "TrophySeekerQueen", "TrophyFader" };
			s_biome = new Dictionary<string, string>();
			Biome("Meadows", "TrophyBoar", "TrophyDeer", "TrophyNeck", "TrophyEikthyr");
			Biome("Black Forest", "TrophyGreydwarf", "TrophyGreydwarfBrute", "TrophyGreydwarfShaman", "TrophySkeleton", "TrophySkeletonPoison", "TrophyGhost", "TrophyFrostTroll", "TrophyBjorn", "TrophySkeletonHildir", "TrophyTheElder");
			Biome("Swamp", "TrophyAbomination", "TrophyBlob", "TrophyDraugr", "TrophyDraugrElite", "TrophyLeech", "TrophySurtling", "TrophyWraith", "TrophyKvastur", "TrophyWrithan", "TrophyBonemass");
			Biome("Mountain", "TrophyCultist", "TrophyHatchling", "TrophyFenring", "TrophyBlob_Frost", "TrophySGolem", "TrophyUlv", "TrophyWolf", "TrophyCultist_Hildir", "TrophyDragonQueen");
			Biome("Ocean", "TrophySerpent");
			Biome("Plains", "TrophyDeathsquito", "TrophyGoblin", "TrophyGoblinBrute", "TrophyGoblinShaman", "TrophyGrowth", "TrophyLox", "TrophyBjornUndead", "TrophyGoblinBruteBrosShaman", "TrophyGoblinBruteBrosBrute", "TrophyGoblinKing");
			Biome("Mistlands", "TrophyDvergr", "TrophyHare", "TrophyGjall", "TrophySeeker", "TrophySeekerBrute", "TrophyTick", "TrophySeekerQueen");
			Biome("Ashlands", "TrophyAsksvin", "TrophyBonemawSerpent", "TrophyFallenValkyrie", "TrophyCharredArcher", "TrophyMorgen", "TrophyVolture", "TrophyCharredMage", "TrophyCharredMelee", "TrophyBlob_Lava", "TrophyFader");
			Biome("Deep North", "TrophyBarka", "TrophyElaking", "TrophyMole", "TrophyJotunWitch", "TrophyJotunWarrior", "TrophyMoose", "TrophyBlob_Morkhalla", "TrophySeal");
		}

		private static void Biome(string biome, params string[] prefabs)
		{
			foreach (string key in prefabs)
			{
				s_biome[key] = biome;
			}
		}

		public static bool Matches(int filter, string prefab)
		{
			switch (Names[filter])
			{
			case "All":
				return true;
			case "Creatures":
				return !s_bosses.Contains(prefab);
			case "Bosses":
				return s_bosses.Contains(prefab);
			case "Other":
				return !s_biome.ContainsKey(prefab);
			default:
			{
				if (s_biome.TryGetValue(prefab, out var value))
				{
					return value == Names[filter];
				}
				return false;
			}
			}
		}
	}
	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 || !TrophyPouchPlugin.AutoPull.Value || !IsLocal(__instance) || !IsTrophy(item))
				{
					return true;
				}
				if (!Add(item, item.m_stack))
				{
					return true;
				}
				__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 || !TrophyPouchPlugin.AutoPull.Value || !IsLocal(__instance) || !IsTrophy(item))
				{
					return true;
				}
				amount = Mathf.Min(amount, item.m_stack);
				if (!Add(item, amount))
				{
					return true;
				}
				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 && TrophyPouchPlugin.AutoPull.Value)
				{
					s_swept = true;
					Sweep(__instance);
				}
			}
		}

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

		[HarmonyPatch(typeof(InventoryGui), "OnRightClickItem")]
		private static class SendBack
		{
			private static bool Prefix(InventoryGrid grid, ItemData item)
			{
				Inventory val = (Object.op_Implicit((Object)(object)grid) ? grid.GetInventory() : null);
				if (!IsTrophy(item) || !IsLocal(val))
				{
					return true;
				}
				if (Add(item, item.m_stack))
				{
					val.RemoveItem(item);
				}
				return 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 bool Add(ItemData item, int amount)
		{
			EnsureLoaded();
			string text = PrefabName(item);
			if (text == null || amount <= 0)
			{
				return false;
			}
			s_counts.TryGetValue(text, out var value);
			s_counts[text] = value + amount;
			Save();
			return true;
		}

		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, bool stack = false)
		{
			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);
			ItemDrop val = (Object.op_Implicit((Object)(object)itemPrefab) ? itemPrefab.GetComponent<ItemDrop>() : null);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return false;
			}
			Inventory inventory = ((Humanoid)localPlayer).GetInventory();
			SharedData shared = val.m_itemData.m_shared;
			int num = inventory.FindFreeStackSpace(shared.m_name, (float)Game.m_worldLevel) + inventory.GetEmptySlots() * shared.m_maxStackSize;
			int num2 = Mathf.Min((!stack) ? 1 : Mathf.Min(value, shared.m_maxStackSize), num);
			if (num2 <= 0)
			{
				((Character)localPlayer).Message((MessageType)2, "$msg_noroom", 0, (Sprite)null, false);
				return false;
			}
			Bypass = true;
			bool flag;
			try
			{
				flag = inventory.AddItem(itemPrefab, num2);
			}
			finally
			{
				Bypass = false;
			}
			if (!flag)
			{
				((Character)localPlayer).Message((MessageType)2, "$msg_noroom", 0, (Sprite)null, false);
				return false;
			}
			if (value - num2 <= 0)
			{
				s_counts.Remove(prefab);
			}
			else
			{
				s_counts[prefab] = value - num2;
			}
			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_00ef: 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);
					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;
					Relayout();
					ShowAutoPull();
				}
			}
		}

		private class RightClick : MonoBehaviour, IPointerClickHandler, IEventSystemHandler
		{
			public Action OnRight;

			public void OnPointerClick(PointerEventData e)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Invalid comparison between Unknown and I4
				if ((int)e.button == 1)
				{
					OnRight?.Invoke();
				}
			}
		}

		[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();
					}
				}
			}
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static UnityAction <0>__ToggleAutoPull;
		}

		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__13_0;

			public static UnityAction <>9__13_1;

			public static Comparison<KeyValuePair<string, int>> <>9__17_0;

			internal void <Build>b__13_0()
			{
				CycleFilter(-1);
			}

			internal void <Build>b__13_1()
			{
				CycleFilter(1);
			}

			internal int <Refresh>b__17_0(KeyValuePair<string, int> a, KeyValuePair<string, int> b)
			{
				return string.CompareOrdinal(a.Key, b.Key);
			}
		}

		private static GameObject s_panel;

		private static Transform s_content;

		private static Button s_button;

		private static RectTransform s_scroll;

		private static GameObject s_filterLabel;

		private static GameObject s_autoButton;

		private static int s_filter;

		private static bool s_open;

		private const int PerRow = 4;

		public static void Relayout()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: 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_0096: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)s_button))
			{
				((Component)s_button).GetComponent<RectTransform>().anchoredPosition = new Vector2(TrophyPouchPlugin.ButtonX.Value, TrophyPouchPlugin.ButtonY.Value);
			}
			if (Object.op_Implicit((Object)(object)s_panel))
			{
				float value = TrophyPouchPlugin.PanelHeight.Value;
				RectTransform component = s_panel.GetComponent<RectTransform>();
				component.anchoredPosition = new Vector2(TrophyPouchPlugin.PanelX.Value, TrophyPouchPlugin.PanelY.Value);
				component.sizeDelta = new Vector2(300f, value);
				s_scroll.sizeDelta = new Vector2(270f, value - 120f);
			}
		}

		public static void ShowAutoPull()
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			bool value = TrophyPouchPlugin.AutoPull.Value;
			if (Object.op_Implicit((Object)(object)s_button) && Object.op_Implicit((Object)(object)((Selectable)s_button).image))
			{
				((Graphic)((Selectable)s_button).image).color = (Color)(value ? Color.white : new Color(0.7f, 0.35f, 0.3f));
			}
			if (Object.op_Implicit((Object)(object)s_autoButton))
			{
				SetLabel(s_autoButton, value ? "Auto-pull: on" : "Auto-pull: off");
			}
		}

		private static void SetLabel(GameObject go, string text)
		{
			Text componentInChildren = go.GetComponentInChildren<Text>();
			if (Object.op_Implicit((Object)(object)componentInChildren))
			{
				componentInChildren.text = text;
			}
			TMP_Text componentInChildren2 = go.GetComponentInChildren<TMP_Text>();
			if (Object.op_Implicit((Object)(object)componentInChildren2))
			{
				componentInChildren2.text = text;
			}
		}

		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_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Expected O, but got Unknown
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: 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_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Expected O, but got Unknown
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Expected O, but got Unknown
			//IL_03c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03df: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)s_panel))
			{
				return;
			}
			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();
			s_panel.GetComponent<RectTransform>().pivot = new Vector2(0f, 1f);
			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);
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0.5f, 1f);
			ButtonClickedEvent onClick = GUIManager.Instance.CreateButton("<", s_panel.transform, val, val, new Vector2(-105f, -54f), 34f, 28f).GetComponent<Button>().onClick;
			object obj = <>c.<>9__13_0;
			if (obj == null)
			{
				UnityAction val2 = delegate
				{
					CycleFilter(-1);
				};
				<>c.<>9__13_0 = val2;
				obj = (object)val2;
			}
			((UnityEvent)onClick).AddListener((UnityAction)obj);
			ButtonClickedEvent onClick2 = GUIManager.Instance.CreateButton(">", s_panel.transform, val, val, new Vector2(105f, -54f), 34f, 28f).GetComponent<Button>().onClick;
			object obj2 = <>c.<>9__13_1;
			if (obj2 == null)
			{
				UnityAction val3 = delegate
				{
					CycleFilter(1);
				};
				<>c.<>9__13_1 = val3;
				obj2 = (object)val3;
			}
			((UnityEvent)onClick2).AddListener((UnityAction)obj2);
			s_filterLabel = GUIManager.Instance.CreateText("", s_panel.transform, val, val, new Vector2(0f, -54f), GUIManager.Instance.AveriaSerif, 16, Color.white, true, Color.black, 160f, 28f, false);
			Text component = s_filterLabel.GetComponent<Text>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.alignment = (TextAnchor)4;
			}
			SetLabel(s_filterLabel, Filters.Names[s_filter]);
			Vector2 val4 = default(Vector2);
			((Vector2)(ref val4))..ctor(0.5f, 0f);
			s_autoButton = GUIManager.Instance.CreateButton("", s_panel.transform, val4, val4, new Vector2(0f, 30f), 180f, 32f);
			ButtonClickedEvent onClick3 = s_autoButton.GetComponent<Button>().onClick;
			object obj3 = <>O.<0>__ToggleAutoPull;
			if (obj3 == null)
			{
				UnityAction val5 = TrophyPouchPlugin.ToggleAutoPull;
				<>O.<0>__ToggleAutoPull = val5;
				obj3 = (object)val5;
			}
			((UnityEvent)onClick3).AddListener((UnityAction)obj3);
			ShowAutoPull();
			GameObject val6 = GUIManager.Instance.CreateScrollView(s_panel.transform, false, true, 8f, 4f, GUIManager.Instance.ValheimScrollbarHandleColorBlock, new Color(0f, 0f, 0f, 0.3f), 270f, value - 120f);
			GraphicRaycaster[] componentsInChildren = val6.GetComponentsInChildren<GraphicRaycaster>(true);
			for (int num = 0; num < componentsInChildren.Length; num++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren[num]);
			}
			CanvasScaler[] componentsInChildren2 = val6.GetComponentsInChildren<CanvasScaler>(true);
			for (int num = 0; num < componentsInChildren2.Length; num++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren2[num]);
			}
			Canvas[] componentsInChildren3 = val6.GetComponentsInChildren<Canvas>(true);
			for (int num = 0; num < componentsInChildren3.Length; num++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren3[num]);
			}
			RectTransform component2 = val6.GetComponent<RectTransform>();
			Vector2 val7 = default(Vector2);
			((Vector2)(ref val7))..ctor(0.5f, 1f);
			component2.anchorMax = val7;
			component2.anchorMin = val7;
			component2.pivot = new Vector2(0.5f, 1f);
			component2.anchoredPosition = new Vector2(0f, -72f);
			s_scroll = component2;
			s_content = ((Component)val6.GetComponentInChildren<VerticalLayoutGroup>()).transform;
			Relayout();
		}

		private static void CycleFilter(int dir)
		{
			int num = Filters.Names.Length;
			int num2 = s_filter;
			do
			{
				num2 = (num2 + dir + num) % num;
			}
			while (num2 != 0 && !Any(num2));
			s_filter = num2;
			SetLabel(s_filterLabel, Filters.Names[num2]);
			Refresh();
		}

		private static bool Any(int filter)
		{
			foreach (KeyValuePair<string, int> item in Pouch.All)
			{
				if (Filters.Matches(filter, item.Key))
				{
					return true;
				}
			}
			return false;
		}

		private static void Refresh()
		{
			//IL_00e1: 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_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: 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>>();
			foreach (KeyValuePair<string, int> item in Pouch.All)
			{
				if (Filters.Matches(s_filter, item.Key))
				{
					list.Add(item);
				}
			}
			list.Sort((KeyValuePair<string, int> a, KeyValuePair<string, int> b) => string.CompareOrdinal(a.Key, b.Key));
			if (list.Count == 0)
			{
				GUIManager.Instance.CreateText((Pouch.Total == 0) ? "Nothing yet." : "None here.", 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, right-click for a stack.";
					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();
				}
			});
			val2.AddComponent<RightClick>().OnRight = delegate
			{
				if (Pouch.Take(prefab, stack: true))
				{
					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.2.1")]
	[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.2.1";

		public static ConfigEntry<bool> SweepOnLoad;

		public static ConfigEntry<bool> AutoPull;

		public static ConfigEntry<KeyboardShortcut> AutoPullKey;

		public static ConfigEntry<float> ButtonX;

		public static ConfigEntry<float> ButtonY;

		public static ConfigEntry<float> PanelX;

		public static ConfigEntry<float> PanelY;

		public static ConfigEntry<float> PanelHeight;

		private void Awake()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: 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.");
			AutoPull = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AutoPull", true, "Picked-up trophies go straight into the pouch. Off: they land in your bag like vanilla (the pouch still counts for crafting).");
			AutoPullKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("General", "AutoPullKey", KeyboardShortcut.Empty, "Key that toggles AutoPull. Unbound by default; the panel has a toggle too.");
			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.");
			PanelX = ((BaseUnityPlugin)this).Config.Bind<float>("General", "PanelX", 90f, "Pouch panel's top-left corner, relative to the inventory's top-right corner.");
			PanelY = ((BaseUnityPlugin)this).Config.Bind<float>("General", "PanelY", 0f, "Pouch panel's top-left corner, relative to the inventory's top-right corner.");
			PanelHeight = ((BaseUnityPlugin)this).Config.Bind<float>("General", "PanelHeight", 580f, "Height (px) of the pouch panel. It scrolls past that.");
			ButtonX.SettingChanged += delegate
			{
				PouchPanel.Relayout();
			};
			ButtonY.SettingChanged += delegate
			{
				PouchPanel.Relayout();
			};
			PanelX.SettingChanged += delegate
			{
				PouchPanel.Relayout();
			};
			PanelY.SettingChanged += delegate
			{
				PouchPanel.Relayout();
			};
			PanelHeight.SettingChanged += delegate
			{
				PouchPanel.Relayout();
			};
			AutoPull.SettingChanged += delegate
			{
				PouchPanel.ShowAutoPull();
			};
			Harmony val = new Harmony("games.loxley.trophypouch");
			val.PatchAll();
			StashHook.TryHookReforged(val);
		}

		private void Update()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				return;
			}
			KeyboardShortcut value = AutoPullKey.Value;
			if (((KeyboardShortcut)(ref value)).IsDown() && !Console.IsVisible())
			{
				Chat instance = Chat.instance;
				if ((instance == null || !instance.HasFocus()) && !TextInput.IsVisible() && !Menu.IsVisible())
				{
					ToggleAutoPull();
				}
			}
		}

		public static void ToggleAutoPull()
		{
			AutoPull.Value = !AutoPull.Value;
			Player localPlayer = Player.m_localPlayer;
			if (localPlayer != null)
			{
				((Character)localPlayer).Message((MessageType)2, AutoPull.Value ? "Trophies go to the pouch" : "Trophies go to your bag", 0, (Sprite)null, false);
			}
		}
	}
}