Decompiled source of LootFilterUI v1.1.0

plugins\ValheimLootFilter.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
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.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn;
using Jotunn.Entities;
using Jotunn.GUI;
using Jotunn.Managers;
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: AssemblyTitle("ValheimLootFilter")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ValheimLootFilter")]
[assembly: AssemblyCopyright("Copyright ukie© 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("1.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
namespace ValheimLootFilter;

internal static class Hotkeys
{
	public static bool IsDown(KeyboardShortcut shortcut)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		if ((int)((KeyboardShortcut)(ref shortcut)).MainKey == 0)
		{
			return false;
		}
		if (UnityInput.Current.GetKeyDown(((KeyboardShortcut)(ref shortcut)).MainKey))
		{
			return ((KeyboardShortcut)(ref shortcut)).Modifiers.All(IsHeld);
		}
		return false;
	}

	public static bool IsHeld(KeyCode key)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		if (!UnityInput.Current.GetKey(key))
		{
			return UnityInput.Current.GetKey(OtherSide(key));
		}
		return true;
	}

	private static KeyCode OtherSide(KeyCode key)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected I4, but got Unknown
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		return (KeyCode)((key - 303) switch
		{
			3 => 305, 
			2 => 306, 
			1 => 303, 
			0 => 304, 
			5 => 307, 
			4 => 308, 
			_ => key, 
		});
	}
}
[HarmonyPatch]
public static class InventoryFilterPatch
{
	private static ConfigEntry<KeyCode> _cfgModifier;

	public static void Init(ConfigFile config)
	{
		_cfgModifier = config.Bind<KeyCode>("Keybinds", "Inventory toggle modifier", (KeyCode)308, "Hold this and left-click an item in your inventory to exclude it from (or allow it for) auto-pickup. None turns this off");
	}

	[HarmonyPatch(typeof(InventoryGrid), "OnLeftDown")]
	[HarmonyPrefix]
	private static bool OnLeftDown_Prefix(InventoryGrid __instance, UIInputHandler clickHandler)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: 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_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		if (_cfgModifier == null || (int)_cfgModifier.Value == 0 || !Hotkeys.IsHeld(_cfgModifier.Value))
		{
			return true;
		}
		Vector2i buttonPos = __instance.GetButtonPos(((Component)clickHandler).gameObject);
		Inventory inventory = __instance.m_inventory;
		ItemData val = ((inventory != null) ? inventory.GetItemAt(buttonPos.x, buttonPos.y) : null);
		GameObject val2 = val?.m_dropPrefab;
		if ((Object)(object)val2 == (Object)null)
		{
			return true;
		}
		string text = ((Localization.instance != null) ? Localization.instance.Localize(val.m_shared.m_name) : val.m_shared.m_name);
		string text2;
		if (LootFilterService.IsCategoryExcluded(val.m_shared.m_itemType))
		{
			text2 = $"{text}: whole {val.m_shared.m_itemType} category is excluded. Allow it in the loot filter panel";
		}
		else
		{
			bool flag = LootFilterService.ToggleExcluded(((Object)val2).name);
			text2 = (flag ? (text + " excluded from auto-pickup") : (text + " allowed for auto-pickup"));
			Logger.LogInfo((object)$"[LootFilter] {((Object)val2).name} excluded={flag} (inventory)");
		}
		Player localPlayer = Player.m_localPlayer;
		if (localPlayer != null)
		{
			((Character)localPlayer).Message((MessageType)1, text2, 0, (Sprite)null, false);
		}
		return false;
	}
}
[HarmonyPatch(typeof(InventoryGui), "Awake")]
public static class InventoryGuiPatch
{
	private const string ButtonName = "lootfilter_button";

	private const string IconItemPrefab = "Coins";

	private const float FallbackGap = 8f;

	private const float SideMargin = 8f;

	private static readonly Vector3[] Corners = (Vector3[])(object)new Vector3[4];

	[HarmonyPostfix]
	public static void Postfix(InventoryGui __instance)
	{
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Expected O, but got Unknown
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Expected O, but got Unknown
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Invalid comparison between Unknown and I4
		Toggle pvp = __instance.m_pvp;
		if ((Object)(object)pvp == (Object)null)
		{
			Logger.LogWarning((object)"[LootFilter] m_pvp not found — skipping button injection");
			return;
		}
		Transform parent = ((Component)pvp).transform.parent;
		if ((Object)(object)parent.Find("lootfilter_button") != (Object)null)
		{
			return;
		}
		Button val = FindTrophiesButton(parent, pvp);
		if ((Object)(object)val == (Object)null)
		{
			Logger.LogWarning((object)"[LootFilter] Trophies button not found — skipping button injection");
			return;
		}
		GameObject val2 = Object.Instantiate<GameObject>(((Component)val).gameObject, parent);
		((Object)val2).name = "lootfilter_button";
		Button component = val2.GetComponent<Button>();
		component.onClick = new ButtonClickedEvent();
		((UnityEvent)component.onClick).AddListener(new UnityAction(LootFilterUI.TogglePanel));
		TMP_Text componentInChildren = val2.GetComponentInChildren<TMP_Text>();
		if ((Object)(object)componentInChildren != (Object)null)
		{
			componentInChildren.text = "Loot Filter";
		}
		else
		{
			Text componentInChildren2 = val2.GetComponentInChildren<Text>();
			if ((Object)(object)componentInChildren2 != (Object)null)
			{
				componentInChildren2.text = "Loot Filter";
			}
		}
		UITooltip componentInChildren3 = val2.GetComponentInChildren<UITooltip>();
		if ((Object)(object)componentInChildren3 != (Object)null)
		{
			componentInChildren3.m_topic = "";
			componentInChildren3.m_text = "Loot Filter";
		}
		Image val3 = FindIconImage(val2);
		if ((Object)(object)val3 != (Object)null)
		{
			if ((int)((Selectable)component).transition == 2 && (Object)(object)((Selectable)component).targetGraphic == (Object)(object)val3)
			{
				((Selectable)component).transition = (Transition)1;
			}
			((MonoBehaviour)__instance).StartCoroutine(SwapIconWhenReady(val3));
		}
		else
		{
			Logger.LogWarning((object)"[LootFilter] No icon Image found on cloned button — keeping trophy icon");
		}
		LayoutRow(parent, ((Component)val).GetComponent<RectTransform>(), val2.GetComponent<RectTransform>());
		Logger.LogInfo((object)"[LootFilter] Loot Filter button injected into InventoryGui");
	}

	private static Button FindTrophiesButton(Transform bar, Toggle pvpToggle)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Expected O, but got Unknown
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Expected O, but got Unknown
		Button result = null;
		float num = float.MaxValue;
		float num2 = WorldLeft(((Component)pvpToggle).GetComponent<RectTransform>());
		foreach (Transform item in bar)
		{
			Transform val = item;
			Button component = ((Component)val).GetComponent<Button>();
			if (!((Object)(object)component == (Object)null))
			{
				if (((Object)val).name.IndexOf("Trophies", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					return component;
				}
				float num3 = WorldRight((RectTransform)val);
				float num4 = num2 - num3;
				if (num4 > 0f && num4 < num)
				{
					num = num4;
					result = component;
				}
			}
		}
		return result;
	}

	private static Image FindIconImage(GameObject buttonGO)
	{
		Image val = null;
		Image[] componentsInChildren = buttonGO.GetComponentsInChildren<Image>(true);
		foreach (Image val2 in componentsInChildren)
		{
			if (!((Object)(object)((Component)val2).gameObject == (Object)(object)buttonGO))
			{
				val = val2;
			}
		}
		if (!((Object)(object)val != (Object)null))
		{
			return buttonGO.GetComponent<Image>();
		}
		return val;
	}

	private static IEnumerator SwapIconWhenReady(Image iconImage)
	{
		while ((Object)(object)ObjectDB.instance == (Object)null || ObjectDB.instance.m_items.Count == 0)
		{
			yield return null;
		}
		if ((Object)(object)iconImage == (Object)null)
		{
			yield break;
		}
		GameObject itemPrefab = ObjectDB.instance.GetItemPrefab("Coins");
		object obj;
		if (!((Object)(object)itemPrefab != (Object)null))
		{
			obj = null;
		}
		else
		{
			ItemDrop component = itemPrefab.GetComponent<ItemDrop>();
			if (component == null)
			{
				obj = null;
			}
			else
			{
				ItemData itemData = component.m_itemData;
				obj = ((itemData != null) ? itemData.GetIcon() : null);
			}
		}
		Sprite val = (Sprite)obj;
		if ((Object)(object)val != (Object)null)
		{
			iconImage.sprite = val;
		}
		else
		{
			Logger.LogWarning((object)"[LootFilter] Could not resolve icon sprite from prefab 'Coins'");
		}
	}

	private static void LayoutRow(Transform bar, RectTransform trophiesRT, RectTransform insertedRT)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Expected O, but got Unknown
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Expected O, but got Unknown
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_018d: 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_0198: Expected O, but got Unknown
		//IL_019f: Expected O, but got Unknown
		//IL_0283: Unknown result type (might be due to invalid IL or missing references)
		//IL_0288: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
		List<RectTransform> list = new List<RectTransform>();
		foreach (Transform item in bar)
		{
			Transform val = item;
			if (((Component)val).gameObject.activeSelf && !((Object)(object)val == (Object)(object)((Component)insertedRT).transform) && !((Object)(object)((Component)val).GetComponent<Selectable>() == (Object)null))
			{
				list.Add((RectTransform)val);
			}
		}
		if (list.Count == 0)
		{
			return;
		}
		list.Sort((RectTransform a, RectTransform b) => WorldLeft(a).CompareTo(WorldLeft(b)));
		float num = bar.lossyScale.x;
		if (num <= 0f)
		{
			num = 1f;
		}
		List<float> list2 = new List<float>();
		for (int num2 = 1; num2 < list.Count; num2++)
		{
			list2.Add(WorldLeft(list[num2]) - WorldRight(list[num2 - 1]));
		}
		list2.Sort();
		float num3 = ((list2.Count > 0) ? list2[list2.Count / 2] : (8f * num));
		int num4 = list.IndexOf(trophiesRT);
		list.Insert((num4 >= 0) ? (num4 + 1) : list.Count, insertedRT);
		float num5 = 0f;
		foreach (RectTransform item2 in list)
		{
			num5 += WorldRight(item2) - WorldLeft(item2);
		}
		RectTransform val2 = (RectTransform)bar;
		float num6 = WorldLeft(val2);
		float num7 = WorldRight(val2);
		float num8 = num7 - num6;
		float num9 = Mathf.Min(8f * num, Mathf.Max(0f, (num8 - num5) * 0.5f));
		float num10 = ((list.Count > 1) ? ((num8 - 2f * num9 - num5) / (float)(list.Count - 1)) : 0f);
		float num11 = Mathf.Max(0f, Mathf.Min(num3, num10));
		float num12 = num7 - num9;
		if (num8 < num5)
		{
			Logger.LogWarning((object)$"[LootFilter] Bar rect ({num8 / num:F0}) narrower than buttons ({num5 / num:F0}) — ignoring section bounds");
			num12 = WorldRight(list[list.Count - 1]);
		}
		for (int num13 = list.Count - 1; num13 >= 0; num13--)
		{
			float num14 = WorldLeft(list[num13]);
			float num15 = WorldRight(list[num13]) - num14;
			float num16 = num12 - num15;
			Vector2 anchoredPosition = list[num13].anchoredPosition;
			anchoredPosition.x += (num16 - num14) / num;
			list[num13].anchoredPosition = anchoredPosition;
			num12 = num16 - num11;
		}
	}

	private static float WorldLeft(RectTransform rt)
	{
		rt.GetWorldCorners(Corners);
		return Corners[0].x;
	}

	private static float WorldRight(RectTransform rt)
	{
		rt.GetWorldCorners(Corners);
		return Corners[2].x;
	}
}
public static class LootFilterService
{
	[HarmonyPatch]
	public static class Patches
	{
		[HarmonyPatch(typeof(Player), "AutoPickup")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> AutoPickup_Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			FieldInfo autoPickupField = AccessTools.Field(typeof(ItemDrop), "m_autoPickup");
			MethodInfo allowMethod = AccessTools.Method(typeof(LootFilterService), "AllowAutoPickup", (Type[])null, (Type[])null);
			bool patched = false;
			foreach (CodeInstruction instruction in instructions)
			{
				if (!patched && CodeInstructionExtensions.LoadsField(instruction, autoPickupField, false))
				{
					instruction.opcode = OpCodes.Call;
					instruction.operand = allowMethod;
					patched = true;
				}
				yield return instruction;
			}
			if (!patched)
			{
				Logger.LogError((object)"[LootFilter] m_autoPickup check not found in Player.AutoPickup — filter is inactive");
			}
		}
	}

	private static ConfigEntry<string> _cfgExcluded;

	private static ConfigEntry<bool> _cfgEnabled;

	private static ConfigEntry<string> _cfgExcludedCategories;

	private static ConfigEntry<string> _cfgQuantityLimits;

	private static readonly HashSet<string> ExcludedItems = new HashSet<string>();

	private static readonly HashSet<ItemType> ExcludedCategories = new HashSet<ItemType>();

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

	public static bool Enabled
	{
		get
		{
			if (_cfgEnabled != null)
			{
				return _cfgEnabled.Value;
			}
			return true;
		}
		set
		{
			if (_cfgEnabled != null)
			{
				_cfgEnabled.Value = value;
			}
		}
	}

	public static int QuantityLimitCount => QuantityLimits.Count;

	public static event Action<bool> EnabledChanged;

	public static void Init(ConfigFile config)
	{
		_cfgEnabled = config.Bind<bool>("General", "Enabled", true, "Turn the loot filter on or off. When off, everything is auto-picked up as usual.");
		_cfgEnabled.SettingChanged += delegate
		{
			LootFilterService.EnabledChanged?.Invoke(_cfgEnabled.Value);
		};
		_cfgExcluded = config.Bind<string>("LootFilter", "ExcludedItems", "", "Comma-separated list of prefab names excluded from auto-pickup");
		_cfgExcludedCategories = config.Bind<string>("LootFilter", "ExcludedCategories", "", "Comma-separated item categories (e.g. Material, Trophy) excluded from auto-pickup, including items you haven't found yet");
		_cfgQuantityLimits = config.Bind<string>("LootFilter", "QuantityLimits", "", "Comma-separated prefab:amount pairs (e.g. Wood:50). Auto-pickup of that item stops once you carry that many");
		LoadExcludedItems();
		LoadExcludedCategories();
		LoadQuantityLimits();
		_cfgExcluded.SettingChanged += delegate
		{
			LoadExcludedItems();
		};
		_cfgExcludedCategories.SettingChanged += delegate
		{
			LoadExcludedCategories();
		};
		_cfgQuantityLimits.SettingChanged += delegate
		{
			LoadQuantityLimits();
		};
	}

	private static IEnumerable<string> SplitList(string value)
	{
		return from s in (value ?? "").Split(new char[1] { ',' })
			select s.Trim() into s
			where s.Length > 0
			select s;
	}

	private static void LoadExcludedItems()
	{
		ExcludedItems.Clear();
		foreach (string item in SplitList(_cfgExcluded.Value))
		{
			ExcludedItems.Add(item);
		}
	}

	private static void LoadExcludedCategories()
	{
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		ExcludedCategories.Clear();
		foreach (string item in SplitList(_cfgExcludedCategories.Value))
		{
			if (Enum.TryParse<ItemType>(item, ignoreCase: true, out ItemType result))
			{
				ExcludedCategories.Add(result);
			}
			else
			{
				Logger.LogWarning((object)("[LootFilter] Unknown item category '" + item + "' in ExcludedCategories"));
			}
		}
	}

	private static void LoadQuantityLimits()
	{
		QuantityLimits.Clear();
		foreach (string item in SplitList(_cfgQuantityLimits.Value))
		{
			string[] array = item.Split(new char[1] { ':' });
			if (array.Length == 2 && int.TryParse(array[1].Trim(), out var result) && result > 0)
			{
				QuantityLimits[array[0].Trim()] = result;
			}
			else
			{
				Logger.LogWarning((object)("[LootFilter] Ignoring invalid quantity limit '" + item + "'"));
			}
		}
	}

	public static bool ToggleEnabled()
	{
		Enabled = !Enabled;
		return Enabled;
	}

	public static bool IsExcluded(string prefabName)
	{
		return ExcludedItems.Contains(prefabName);
	}

	public static bool ToggleExcluded(string prefabName)
	{
		bool result;
		if (ExcludedItems.Contains(prefabName))
		{
			ExcludedItems.Remove(prefabName);
			result = false;
		}
		else
		{
			ExcludedItems.Add(prefabName);
			result = true;
		}
		Save();
		return result;
	}

	private static void Save()
	{
		if (_cfgExcluded != null)
		{
			_cfgExcluded.Value = string.Join(",", ExcludedItems);
		}
	}

	public static bool IsBlocked(ItemDrop item)
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		SharedData val = item.m_itemData?.m_shared;
		if (val == null || !ExcludedCategories.Contains(val.m_itemType))
		{
			return IsExcluded(((Object)item).name);
		}
		return true;
	}

	public static bool IsCategoryExcluded(ItemType category)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		return ExcludedCategories.Contains(category);
	}

	public static bool ToggleCategoryExcluded(ItemType category)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		bool num = ExcludedCategories.Add(category);
		if (!num)
		{
			ExcludedCategories.Remove(category);
		}
		if (_cfgExcludedCategories != null)
		{
			_cfgExcludedCategories.Value = string.Join(",", ExcludedCategories);
		}
		return num;
	}

	public static int GetQuantityLimit(string prefabName)
	{
		if (!QuantityLimits.TryGetValue(prefabName, out var value))
		{
			return 0;
		}
		return value;
	}

	public static void SetQuantityLimit(string prefabName, int limit)
	{
		if (limit > 0)
		{
			QuantityLimits[prefabName] = limit;
		}
		else
		{
			QuantityLimits.Remove(prefabName);
		}
		if (_cfgQuantityLimits != null)
		{
			_cfgQuantityLimits.Value = string.Join(",", QuantityLimits.Select((KeyValuePair<string, int> kv) => $"{kv.Key}:{kv.Value}"));
		}
	}

	public static List<ItemDrop> GetAllItems()
	{
		if (!((Object)(object)ObjectDB.instance == (Object)null))
		{
			return (from go in ObjectDB.instance.m_items
				select go.GetComponent<ItemDrop>() into id
				where (Object)(object)id != (Object)null
				select id).ToList();
		}
		return new List<ItemDrop>();
	}

	public static bool AllowAutoPickup(ItemDrop item)
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		if (!item.m_autoPickup)
		{
			return false;
		}
		if (!Enabled)
		{
			return true;
		}
		SharedData val = item.m_itemData?.m_shared;
		if (val != null && ExcludedCategories.Contains(val.m_itemType))
		{
			return false;
		}
		string prefabName = GetPrefabName(item);
		if (IsExcluded(prefabName))
		{
			return false;
		}
		if (val != null && QuantityLimits.TryGetValue(prefabName, out var value))
		{
			Player localPlayer = Player.m_localPlayer;
			Inventory val2 = ((localPlayer != null) ? ((Humanoid)localPlayer).GetInventory() : null);
			if (val2 != null && val2.CountItems(val.m_name, -1, false) >= value)
			{
				return false;
			}
		}
		return true;
	}

	private static string GetPrefabName(ItemDrop item)
	{
		GameObject val = item.m_itemData?.m_dropPrefab;
		if (!((Object)(object)val != (Object)null))
		{
			return ((Object)((Component)item).gameObject).name.Replace("(Clone)", "").Trim();
		}
		return ((Object)val).name;
	}
}
public static class LootFilterUI
{
	private class CellView
	{
		public GameObject Cell;

		public GameObject Section;

		public string SearchName;

		public bool Discovered;

		public ItemDrop Item;

		public string PrefabName;

		public string DisplayName;

		public ItemType Category;

		public Image Icon;

		public GameObject XOverlay;

		public Text LimitLabel;

		public CellTooltip Tooltip;
	}

	[HarmonyPatch]
	public static class Patches
	{
		[HarmonyPatch(typeof(Menu), "Update")]
		[HarmonyPatch(typeof(InventoryGui), "Update")]
		[HarmonyPrefix]
		private static bool SkipOnEscapeFrame()
		{
			return _closedByEscapeFrame != Time.frameCount;
		}
	}

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

		public static UnityAction<string> <>9__38_0;

		public static UnityAction<bool> <>9__38_1;

		public static UnityAction<bool> <>9__38_2;

		public static UnityAction <>9__38_3;

		public static Action<bool> <>9__38_4;

		public static Func<ItemDrop, ItemType> <>9__40_0;

		public static Func<IGrouping<ItemType, ItemDrop>, string> <>9__40_1;

		public static UnityAction<string> <>9__51_0;

		public static UnityAction <>9__51_1;

		internal void <BuildPanel>b__38_0(string _)
		{
			ApplyFilters();
		}

		internal void <BuildPanel>b__38_1(bool on)
		{
			_showOnlyExcluded = on;
			ApplyFilters();
		}

		internal void <BuildPanel>b__38_2(bool on)
		{
			_showUndiscovered = on;
			RefreshContent();
		}

		internal void <BuildPanel>b__38_3()
		{
			LootFilterService.ToggleEnabled();
		}

		internal void <BuildPanel>b__38_4(bool _)
		{
			UpdateFilterToggleLabel();
		}

		internal ItemType <RefreshContent>b__40_0(ItemDrop i)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			return (ItemType)(((??)i.m_itemData?.m_shared?.m_itemType) ?? 16);
		}

		internal string <RefreshContent>b__40_1(IGrouping<ItemType, ItemDrop> g)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return ((object)g.Key/*cast due to .constrained prefix*/).ToString();
		}

		internal void <BuildLimitPopup>b__51_0(string _)
		{
			if (ZInput.GetKeyDown((KeyCode)13, false) || ZInput.GetKeyDown((KeyCode)271, false))
			{
				SaveLimitPopup();
			}
		}

		internal void <BuildLimitPopup>b__51_1()
		{
			_limitField.text = "";
			SaveLimitPopup();
		}
	}

	private static GameObject _filtersPanel;

	private static GameObject _scrollView;

	private static Transform _contentRoot;

	private static InputField _searchField;

	private static Text _filterToggleLabel;

	private static readonly List<CellView> _cellViews = new List<CellView>();

	private static readonly Dictionary<ItemType, Text> _categoryButtonLabels = new Dictionary<ItemType, Text>();

	private static readonly Dictionary<ItemType, Text> _categoryHeaders = new Dictionary<ItemType, Text>();

	private static GameObject _limitPopup;

	private static Text _limitPopupTitle;

	private static InputField _limitField;

	private static CellView _limitTarget;

	private static bool _showOnlyExcluded;

	private static bool _showUndiscovered;

	private static Text _titleText;

	private static int _closedByEscapeFrame = -1;

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

	private static readonly Color ColNormal = new Color(1f, 1f, 1f, 1f);

	private static readonly Color ColExcluded = new Color(1f, 0.2f, 0.2f, 1f);

	private static readonly Color ColLimit = new Color(1f, 0.85f, 0.35f, 1f);

	private static readonly Color ColUndiscovered = new Color(0.45f, 0.45f, 0.45f, 0.6f);

	private static readonly Color ColUndiscoveredExcluded = new Color(0.6f, 0.15f, 0.15f, 0.6f);

	private const float PanelW = 1050f;

	private const float PanelH = 800f;

	private const float ScrollW = 970f;

	private const float ScrollH = 600f;

	private const float CellSize = 64f;

	private const float CellSpacing = 8f;

	private const float GroupHeaderH = 30f;

	private const float GroupHeaderFontSize = 18f;

	public static bool IsOpen
	{
		get
		{
			if (Object.op_Implicit((Object)(object)_filtersPanel))
			{
				return _filtersPanel.activeSelf;
			}
			return false;
		}
	}

	public static bool IsTyping
	{
		get
		{
			if (!Object.op_Implicit((Object)(object)_searchField) || !_searchField.isFocused)
			{
				if (Object.op_Implicit((Object)(object)_limitField))
				{
					return _limitField.isFocused;
				}
				return false;
			}
			return true;
		}
	}

	public static void TogglePanel()
	{
		if (!Object.op_Implicit((Object)(object)_filtersPanel))
		{
			BuildPanel();
		}
		if (!Object.op_Implicit((Object)(object)_filtersPanel))
		{
			return;
		}
		bool flag = !_filtersPanel.activeSelf;
		_filtersPanel.SetActive(flag);
		GUIManager.BlockInput(flag);
		if (flag)
		{
			RefreshContent();
			return;
		}
		if (Object.op_Implicit((Object)(object)_searchField))
		{
			_searchField.DeactivateInputField();
		}
		CloseLimitPopup();
	}

	public static void HandleEscape()
	{
		if (IsOpen && (ZInput.GetKeyDown((KeyCode)27, true) || ZInput.GetButtonDown("JoyButtonB")))
		{
			_closedByEscapeFrame = Time.frameCount;
			if (Object.op_Implicit((Object)(object)_limitPopup) && _limitPopup.activeSelf)
			{
				CloseLimitPopup();
			}
			else
			{
				TogglePanel();
			}
		}
	}

	private static void BuildPanel()
	{
		//IL_0037: 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_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: 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_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01eb: 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_02df: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0317: Unknown result type (might be due to invalid IL or missing references)
		//IL_032c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0341: Unknown result type (might be due to invalid IL or missing references)
		//IL_0355: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d8: Expected O, but got Unknown
		//IL_0412: Unknown result type (might be due to invalid IL or missing references)
		//IL_0421: Unknown result type (might be due to invalid IL or missing references)
		//IL_0430: Unknown result type (might be due to invalid IL or missing references)
		//IL_045c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0466: Expected O, but got Unknown
		//IL_0484: Unknown result type (might be due to invalid IL or missing references)
		//IL_0493: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_04dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e7: Expected O, but got Unknown
		if (GUIManager.Instance == null || !Object.op_Implicit((Object)(object)GUIManager.CustomGUIFront))
		{
			Logger.LogError((object)"GUIManager not ready");
			return;
		}
		_filtersPanel = GUIManager.Instance.CreateWoodpanel(GUIManager.CustomGUIFront.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), Vector2.zero, 1050f, 800f, true);
		_filtersPanel.SetActive(false);
		if (!Object.op_Implicit((Object)(object)_filtersPanel.GetComponent<DragWindowCntrl>()))
		{
			_filtersPanel.AddComponent<DragWindowCntrl>();
		}
		GameObject obj = GUIManager.Instance.CreateText("Loot Filter", _filtersPanel.transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -20f), GUIManager.Instance.AveriaSerifBold, 30, GUIManager.Instance.ValheimOrange, true, Color.black, 400f, 40f, false);
		obj.GetComponent<RectTransform>().pivot = new Vector2(0.5f, 1f);
		_titleText = obj.GetComponent<Text>();
		_titleText.supportRichText = true;
		_titleText.horizontalOverflow = (HorizontalWrapMode)1;
		GUIManager.Instance.CreateText("Click: toggle auto-pickup    Right-click: keep-up-to amount    [ red = excluded ]", _filtersPanel.transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -56f), GUIManager.Instance.AveriaSerifBold, 13, Color.white, true, Color.black, 700f, 24f, false).GetComponent<RectTransform>().pivot = new Vector2(0.5f, 1f);
		GameObject obj2 = GUIManager.Instance.CreateInputField(_filtersPanel.transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(-200f, -86f), (ContentType)0, "Search items...", 16, 400f, 32f);
		obj2.GetComponent<RectTransform>().pivot = new Vector2(0.5f, 1f);
		_searchField = obj2.GetComponent<InputField>();
		((UnityEvent<string>)(object)_searchField.onValueChanged).AddListener((UnityAction<string>)delegate
		{
			ApplyFilters();
		});
		CreateOptionToggle("Only excluded", 70f, _showOnlyExcluded, delegate(bool on)
		{
			_showOnlyExcluded = on;
			ApplyFilters();
		});
		CreateOptionToggle("Show undiscovered", 290f, _showUndiscovered, delegate(bool on)
		{
			_showUndiscovered = on;
			RefreshContent();
		});
		_scrollView = GUIManager.Instance.CreateScrollView(_filtersPanel.transform, false, true, 5f, 2f, GUIManager.Instance.ValheimScrollbarHandleColorBlock, GUIManager.Instance.ValheimBeige, 970f, 600f);
		RectTransform component = _scrollView.GetComponent<RectTransform>();
		component.anchorMin = new Vector2(0.5f, 1f);
		component.anchorMax = new Vector2(0.5f, 1f);
		component.pivot = new Vector2(0.5f, 1f);
		component.anchoredPosition = new Vector2(0f, -126f);
		ScrollRect componentInChildren = _scrollView.GetComponentInChildren<ScrollRect>();
		if ((Object)(object)componentInChildren == (Object)null)
		{
			Logger.LogError((object)"ScrollRect not found inside CreateScrollView result");
			return;
		}
		_contentRoot = (Transform)(object)componentInChildren.content;
		VerticalLayoutGroup orAddComponent = ((Component)_contentRoot).gameObject.GetOrAddComponent<VerticalLayoutGroup>();
		((LayoutGroup)orAddComponent).childAlignment = (TextAnchor)0;
		((HorizontalOrVerticalLayoutGroup)orAddComponent).childControlHeight = false;
		((HorizontalOrVerticalLayoutGroup)orAddComponent).childControlWidth = false;
		((HorizontalOrVerticalLayoutGroup)orAddComponent).childForceExpandHeight = false;
		((HorizontalOrVerticalLayoutGroup)orAddComponent).childForceExpandWidth = false;
		((HorizontalOrVerticalLayoutGroup)orAddComponent).spacing = 10f;
		((LayoutGroup)orAddComponent).padding = new RectOffset(10, 10, 10, 10);
		ContentSizeFitter orAddComponent2 = ((Component)_contentRoot).gameObject.GetOrAddComponent<ContentSizeFitter>();
		orAddComponent2.verticalFit = (FitMode)2;
		orAddComponent2.horizontalFit = (FitMode)0;
		GameObject obj3 = GUIManager.Instance.CreateButton("Close", _filtersPanel.transform, new Vector2(0.5f, 0f), new Vector2(0.5f, 0f), new Vector2(0f, 40f), 250f, 60f);
		obj3.SetActive(true);
		((UnityEvent)obj3.GetComponent<Button>().onClick).AddListener(new UnityAction(TogglePanel));
		GameObject obj4 = GUIManager.Instance.CreateButton("", _filtersPanel.transform, new Vector2(0f, 0f), new Vector2(0f, 0f), new Vector2(170f, 40f), 220f, 60f);
		obj4.SetActive(true);
		ButtonClickedEvent onClick = obj4.GetComponent<Button>().onClick;
		object obj5 = <>c.<>9__38_3;
		if (obj5 == null)
		{
			UnityAction val = delegate
			{
				LootFilterService.ToggleEnabled();
			};
			<>c.<>9__38_3 = val;
			obj5 = (object)val;
		}
		((UnityEvent)onClick).AddListener((UnityAction)obj5);
		_filterToggleLabel = obj4.GetComponentInChildren<Text>();
		LootFilterService.EnabledChanged += delegate
		{
			UpdateFilterToggleLabel();
		};
		UpdateFilterToggleLabel();
		BuildLimitPopup();
	}

	private static void UpdateFilterToggleLabel()
	{
		if (Object.op_Implicit((Object)(object)_filterToggleLabel))
		{
			_filterToggleLabel.text = (LootFilterService.Enabled ? "Filter: <color=#7fd17f>On</color>" : "Filter: <color=#ff5050>Off</color>");
			_filterToggleLabel.supportRichText = true;
		}
	}

	private static void RefreshContent()
	{
		//IL_0031: 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_01be: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_contentRoot == (Object)null)
		{
			Logger.LogError((object)"Content root is null — panel was not built correctly");
			return;
		}
		foreach (Transform item in _contentRoot)
		{
			Object.Destroy((Object)(object)((Component)item).gameObject);
		}
		_cellViews.Clear();
		_categoryButtonLabels.Clear();
		_categoryHeaders.Clear();
		List<ItemDrop> allItems = LootFilterService.GetAllItems();
		Logger.LogInfo((object)$"Found {allItems.Count} total items in ObjectDB");
		HashSet<string> knownNames = (((Object)(object)Player.m_localPlayer != (Object)null) ? Player.m_localPlayer.m_knownMaterial : new HashSet<string>());
		Logger.LogInfo((object)$"{knownNames.Count} items are known");
		IOrderedEnumerable<IGrouping<ItemType, ItemDrop>> orderedEnumerable = from i in allItems
			group i by (ItemType)(((??)i.m_itemData?.m_shared?.m_itemType) ?? 16) into g
			orderby ((object)g.Key/*cast due to .constrained prefix*/).ToString()
			select g;
		Logger.LogInfo((object)$"{orderedEnumerable.Count()} groups will be created");
		foreach (IGrouping<ItemType, ItemDrop> item2 in orderedEnumerable)
		{
			List<ItemDrop> list = (from i in item2
				where IsDiscovered(i, knownNames) || (_showUndiscovered && IsRealItem(i))
				orderby (!IsDiscovered(i, knownNames)) ? 1 : 0
				select i).ToList();
			if (list.Count == 0)
			{
				Logger.LogInfo((object)$"{item2.Key} group has no items to show, skipping...");
			}
			else
			{
				CreateGroupSection(item2.Key, list, knownNames);
			}
		}
		ApplyFilters();
		UpdateTitle();
	}

	private static bool IsDiscovered(ItemDrop item, HashSet<string> knownNames)
	{
		if (knownNames.Count != 0)
		{
			return knownNames.Contains(item.m_itemData?.m_shared?.m_name);
		}
		return true;
	}

	private static bool IsRealItem(ItemDrop item)
	{
		SharedData val = item.m_itemData?.m_shared;
		if (val == null || val.m_icons == null || val.m_icons.Length == 0 || !Object.op_Implicit((Object)(object)val.m_icons[0]))
		{
			return false;
		}
		if (string.IsNullOrEmpty(val.m_name) || !val.m_name.StartsWith("$"))
		{
			return false;
		}
		return !((Localization.instance != null) ? Localization.instance.Localize(val.m_name) : val.m_name).StartsWith("[");
	}

	private static void CreateOptionToggle(string label, float x, bool initial, UnityAction<bool> onChanged)
	{
		//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_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: 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_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: 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)
		GameObject val = GUIManager.Instance.CreateToggle(_filtersPanel.transform, 26f, 26f);
		RectTransform val2 = (RectTransform)val.transform;
		((Transform)val2).localScale = Vector3.one;
		Vector2 val3 = default(Vector2);
		((Vector2)(ref val3))..ctor(0.5f, 1f);
		val2.anchorMax = val3;
		val2.anchorMin = val3;
		val2.pivot = new Vector2(0f, 1f);
		val2.anchoredPosition = new Vector2(x, -89f);
		Transform val4 = val.transform.Find("Label");
		if (Object.op_Implicit((Object)(object)val4))
		{
			((Component)val4).gameObject.SetActive(false);
		}
		GameObject obj = GUIManager.Instance.CreateText(label, val.transform, new Vector2(1f, 0.5f), new Vector2(1f, 0.5f), new Vector2(8f, 0f), GUIManager.Instance.AveriaSerifBold, 15, Color.white, true, Color.black, 160f, 26f, false);
		obj.GetComponent<RectTransform>().pivot = new Vector2(0f, 0.5f);
		obj.GetComponent<Text>().alignment = (TextAnchor)3;
		Toggle component = val.GetComponent<Toggle>();
		component.isOn = initial;
		((UnityEvent<bool>)(object)component.onValueChanged).AddListener(onChanged);
	}

	private static void UpdateTitle()
	{
		if (Object.op_Implicit((Object)(object)_titleText))
		{
			int num = LootFilterService.GetAllItems().Count(LootFilterService.IsBlocked);
			int quantityLimitCount = LootFilterService.QuantityLimitCount;
			List<string> list = new List<string>();
			if (num > 0)
			{
				list.Add($"{num} excluded");
			}
			if (quantityLimitCount > 0)
			{
				list.Add($"{quantityLimitCount} limited");
			}
			_titleText.text = ((list.Count == 0) ? "Loot Filter" : ("Loot Filter  <size=18><color=#ffffff>(" + string.Join(", ", list) + ")</color></size>"));
		}
	}

	private static void ApplyFilters()
	{
		string text = (Object.op_Implicit((Object)(object)_searchField) ? _searchField.text : "").Trim().ToLowerInvariant();
		HashSet<GameObject> hashSet = new HashSet<GameObject>();
		foreach (CellView cellView in _cellViews)
		{
			bool flag = (text.Length == 0 || cellView.SearchName.Contains(text)) && (!_showOnlyExcluded || LootFilterService.IsBlocked(cellView.Item));
			cellView.Cell.SetActive(flag);
			if (flag)
			{
				hashSet.Add(cellView.Section);
			}
		}
		foreach (CellView cellView2 in _cellViews)
		{
			cellView2.Section.SetActive(hashSet.Contains(cellView2.Section));
		}
		if (Object.op_Implicit((Object)(object)_contentRoot))
		{
			Transform contentRoot = _contentRoot;
			LayoutRebuilder.ForceRebuildLayoutImmediate((RectTransform)(object)((contentRoot is RectTransform) ? contentRoot : null));
		}
	}

	private static string TooltipText(CellView view)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		string text;
		if (LootFilterService.IsCategoryExcluded(view.Category))
		{
			text = "<color=#ff5050>Excluded with its category</color>\nUse the category button to allow";
		}
		else if (LootFilterService.IsExcluded(view.PrefabName))
		{
			text = "<color=#ff5050>Excluded from auto-pickup</color>\nClick to allow";
		}
		else
		{
			int quantityLimit = LootFilterService.GetQuantityLimit(view.PrefabName);
			text = ((quantityLimit > 0) ? $"Auto-pickup until you carry {quantityLimit}\nClick to exclude" : "Auto-pickup allowed\nClick to exclude");
		}
		if (!view.Discovered)
		{
			text = "<color=#a0a0a0>Not found yet</color>\n" + text;
		}
		return text + "\nRight-click to set a keep-up-to amount";
	}

	private static void RefreshCell(CellView view)
	{
		//IL_0001: 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_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		bool flag = LootFilterService.IsCategoryExcluded(view.Category) || LootFilterService.IsExcluded(view.PrefabName);
		int quantityLimit = LootFilterService.GetQuantityLimit(view.PrefabName);
		((Graphic)view.Icon).color = ((!view.Discovered) ? (flag ? ColUndiscoveredExcluded : ColUndiscovered) : (flag ? ColExcluded : ColNormal));
		view.XOverlay.SetActive(flag);
		view.LimitLabel.text = ((quantityLimit > 0) ? quantityLimit.ToString() : "");
		((Component)view.LimitLabel).gameObject.SetActive(quantityLimit > 0 && !flag);
		view.Tooltip.Set(view.DisplayName, TooltipText(view));
	}

	private unsafe static void RefreshCategory(ItemType category)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		bool flag = LootFilterService.IsCategoryExcluded(category);
		if (_categoryButtonLabels.TryGetValue(category, out var value) && Object.op_Implicit((Object)(object)value))
		{
			value.text = (flag ? "Allow all" : "Exclude all");
		}
		if (_categoryHeaders.TryGetValue(category, out var value2) && Object.op_Implicit((Object)(object)value2))
		{
			value2.text = (flag ? $"{category}  <color=#ff5050>(whole category excluded)</color>" : ((object)(*(ItemType*)(&category))/*cast due to .constrained prefix*/).ToString());
		}
		foreach (CellView cellView in _cellViews)
		{
			if (cellView.Category == category)
			{
				RefreshCell(cellView);
			}
		}
	}

	private unsafe static void CreateGroupSection(ItemType category, List<ItemDrop> items, HashSet<string> knownNames)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Expected O, but got Unknown
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Expected O, but got Unknown
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Expected O, but got Unknown
		//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e8: 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_0204: Unknown result type (might be due to invalid IL or missing references)
		//IL_022a: Unknown result type (might be due to invalid IL or missing references)
		//IL_023e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0197: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b0: Expected O, but got Unknown
		//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0305: Unknown result type (might be due to invalid IL or missing references)
		//IL_027f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0374: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
		string text = ((object)(*(ItemType*)(&category))/*cast due to .constrained prefix*/).ToString();
		Logger.LogInfo((object)$"Creating section for category '{text}' with {items.Count} items");
		GameObject val = new GameObject("Section_" + text, new Type[1] { typeof(RectTransform) });
		val.transform.SetParent(_contentRoot, false);
		val.GetComponent<RectTransform>().sizeDelta = new Vector2(946f, 0f);
		VerticalLayoutGroup obj = val.AddComponent<VerticalLayoutGroup>();
		((LayoutGroup)obj).childAlignment = (TextAnchor)0;
		((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = false;
		((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = false;
		((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false;
		((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = false;
		((HorizontalOrVerticalLayoutGroup)obj).spacing = 4f;
		ContentSizeFitter obj2 = val.AddComponent<ContentSizeFitter>();
		obj2.verticalFit = (FitMode)2;
		obj2.horizontalFit = (FitMode)0;
		GameObject val2 = new GameObject("Header_" + text, new Type[1] { typeof(RectTransform) });
		val2.transform.SetParent(val.transform, false);
		((RectTransform)val2.transform).sizeDelta = new Vector2(946f, 30f);
		GameObject obj3 = GUIManager.Instance.CreateButton("", val2.transform, new Vector2(1f, 0.5f), new Vector2(1f, 0.5f), new Vector2(-100f, 0f), 200f, 30f);
		obj3.SetActive(true);
		Text componentInChildren = obj3.GetComponentInChildren<Text>();
		if (Object.op_Implicit((Object)(object)componentInChildren))
		{
			componentInChildren.fontSize = 14;
			_categoryButtonLabels[category] = componentInChildren;
		}
		((UnityEvent)obj3.GetComponent<Button>().onClick).AddListener((UnityAction)delegate
		{
			//IL_0001: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			bool flag = LootFilterService.ToggleCategoryExcluded(category);
			RefreshCategory(category);
			UpdateTitle();
			Logger.LogInfo((object)$"[LootFilter] category {category} excluded={flag}");
		});
		GameObject obj4 = GUIManager.Instance.CreateText(text, val2.transform, new Vector2(0f, 1f), new Vector2(1f, 1f), Vector2.zero, GUIManager.Instance.AveriaSerifBold, 18, GUIManager.Instance.ValheimOrange, true, Color.black, 946f, 30f, false);
		RectTransform component = obj4.GetComponent<RectTransform>();
		component.pivot = new Vector2(0f, 1f);
		component.sizeDelta = new Vector2(946f, 30f);
		Text component2 = obj4.GetComponent<Text>();
		if (Object.op_Implicit((Object)(object)component2))
		{
			component2.alignment = (TextAnchor)3;
		}
		if (Object.op_Implicit((Object)(object)component2))
		{
			((Graphic)component2).raycastTarget = false;
			component2.supportRichText = true;
			_categoryHeaders[category] = component2;
		}
		GameObject val3 = new GameObject("Grid_" + text, new Type[1] { typeof(RectTransform) });
		val3.transform.SetParent(val.transform, false);
		val3.GetComponent<RectTransform>().sizeDelta = new Vector2(946f, 0f);
		GridLayoutGroup obj5 = val3.AddComponent<GridLayoutGroup>();
		obj5.cellSize = new Vector2(64f, 64f);
		obj5.spacing = new Vector2(8f, 8f);
		obj5.startCorner = (Corner)0;
		obj5.startAxis = (Axis)0;
		((LayoutGroup)obj5).childAlignment = (TextAnchor)0;
		obj5.constraint = (Constraint)1;
		int num = Mathf.FloorToInt(13.25f);
		obj5.constraintCount = Mathf.Max(1, num);
		ContentSizeFitter obj6 = val3.AddComponent<ContentSizeFitter>();
		obj6.verticalFit = (FitMode)2;
		obj6.horizontalFit = (FitMode)0;
		foreach (ItemDrop item in items)
		{
			CreateItemCell(val3.transform, val, category, item, IsDiscovered(item, knownNames));
		}
		RefreshCategory(category);
	}

	private static void CreateItemCell(Transform parent, GameObject section, ItemType category, ItemDrop item, bool discovered)
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Expected O, but got Unknown
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_0197: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0295: Unknown result type (might be due to invalid IL or missing references)
		//IL_0296: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f6: Expected O, but got Unknown
		//IL_030e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0313: Unknown result type (might be due to invalid IL or missing references)
		//IL_0317: Unknown result type (might be due to invalid IL or missing references)
		//IL_0337: Unknown result type (might be due to invalid IL or missing references)
		//IL_0357: Unknown result type (might be due to invalid IL or missing references)
		//IL_0362: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("Cell_" + ((Object)item).name, new Type[1] { typeof(RectTransform) });
		val.transform.SetParent(parent, false);
		Button val2 = val.AddComponent<Button>();
		Image val3 = val.AddComponent<Image>();
		((Graphic)val3).color = new Color(0f, 0f, 0f, 0.45f);
		GameObject val4 = new GameObject("Icon", new Type[1] { typeof(RectTransform) });
		val4.transform.SetParent(val.transform, false);
		RectTransform component = val4.GetComponent<RectTransform>();
		component.anchorMin = new Vector2(0.1f, 0.1f);
		component.anchorMax = new Vector2(0.9f, 0.9f);
		component.offsetMin = Vector2.zero;
		component.offsetMax = Vector2.zero;
		Image val5 = val4.AddComponent<Image>();
		Sprite itemSprite = GetItemSprite(item);
		if (Object.op_Implicit((Object)(object)itemSprite))
		{
			val5.sprite = itemSprite;
		}
		GameObject xOverlay = GUIManager.Instance.CreateText("✕", val.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), Vector2.zero, GUIManager.Instance.AveriaSerifBold, 28, new Color(1f, 0.15f, 0.15f, 0.9f), true, Color.black, 64f, 64f, false);
		GameObject obj = GUIManager.Instance.CreateText("", val.transform, new Vector2(1f, 0f), new Vector2(1f, 0f), new Vector2(-3f, 2f), GUIManager.Instance.AveriaSerifBold, 14, ColLimit, true, Color.black, 64f, 18f, false);
		obj.GetComponent<RectTransform>().pivot = new Vector2(1f, 0f);
		Text component2 = obj.GetComponent<Text>();
		component2.alignment = (TextAnchor)8;
		((Graphic)component2).raycastTarget = false;
		string text = item.m_itemData?.m_shared?.m_name ?? ((Object)item).name;
		if (Localization.instance != null && text.StartsWith("$"))
		{
			text = Localization.instance.Localize(text);
		}
		CellView view = new CellView
		{
			Cell = val,
			Section = section,
			SearchName = text.ToLowerInvariant(),
			Discovered = discovered,
			Item = item,
			PrefabName = ((Object)item).name,
			DisplayName = text,
			Category = category,
			Icon = val5,
			XOverlay = xOverlay,
			LimitLabel = component2,
			Tooltip = val.AddComponent<CellTooltip>()
		};
		_cellViews.Add(view);
		RefreshCell(view);
		((UnityEvent)val2.onClick).AddListener((UnityAction)delegate
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			if (!LootFilterService.IsCategoryExcluded(view.Category))
			{
				bool flag = LootFilterService.ToggleExcluded(view.PrefabName);
				RefreshCell(view);
				UpdateTitle();
				Logger.LogInfo((object)$"[LootFilter] {view.PrefabName} excluded={flag}");
			}
		});
		val.AddComponent<RightClickHandler>().OnRightClick = delegate
		{
			OpenLimitPopup(view);
		};
		ColorBlock colors = ((Selectable)val2).colors;
		((ColorBlock)(ref colors)).normalColor = Color.white;
		((ColorBlock)(ref colors)).highlightedColor = new Color(1.3f, 1.3f, 0.7f, 1f);
		((ColorBlock)(ref colors)).pressedColor = new Color(0.7f, 0.7f, 0.7f, 1f);
		((Selectable)val2).colors = colors;
		((Selectable)val2).targetGraphic = (Graphic)(object)val3;
	}

	private static void BuildLimitPopup()
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Expected O, but got Unknown
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: 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_00f6: 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_012a: 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)
		//IL_015d: Unknown result type (might be due to invalid IL or missing references)
		//IL_016c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0182: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: 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_01e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_025b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0265: Expected O, but got Unknown
		//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ba: Expected O, but got Unknown
		//IL_0289: Unknown result type (might be due to invalid IL or missing references)
		//IL_028e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0294: Expected O, but got Unknown
		_limitPopup = new GameObject("LimitPopup", new Type[1] { typeof(RectTransform) });
		_limitPopup.transform.SetParent(_filtersPanel.transform, false);
		RectTransform val = (RectTransform)_limitPopup.transform;
		val.anchorMin = Vector2.zero;
		val.anchorMax = Vector2.one;
		val.offsetMin = Vector2.zero;
		val.offsetMax = Vector2.zero;
		((Graphic)_limitPopup.AddComponent<Image>()).color = new Color(0f, 0f, 0f, 0.5f);
		GameObject val2 = new GameObject("Box", new Type[1] { typeof(RectTransform) });
		val2.transform.SetParent(_limitPopup.transform, false);
		RectTransform val3 = (RectTransform)val2.transform;
		Vector2 val4 = default(Vector2);
		((Vector2)(ref val4))..ctor(0.5f, 0.5f);
		val3.anchorMax = val4;
		val3.anchorMin = val4;
		val3.sizeDelta = new Vector2(420f, 200f);
		((Graphic)val2.AddComponent<Image>()).color = new Color(0.12f, 0.1f, 0.08f, 0.97f);
		_limitPopupTitle = GUIManager.Instance.CreateText("", val2.transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -30f), GUIManager.Instance.AveriaSerifBold, 18, GUIManager.Instance.ValheimOrange, true, Color.black, 400f, 50f, false).GetComponent<Text>();
		_limitPopupTitle.alignment = (TextAnchor)4;
		_limitField = GUIManager.Instance.CreateInputField(val2.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0f, 5f), (ContentType)2, "No limit", 18, 160f, 34f).GetComponent<InputField>();
		_limitField.characterLimit = 6;
		((UnityEvent<string>)(object)_limitField.onEndEdit).AddListener((UnityAction<string>)delegate
		{
			if (ZInput.GetKeyDown((KeyCode)13, false) || ZInput.GetKeyDown((KeyCode)271, false))
			{
				SaveLimitPopup();
			}
		});
		CreatePopupButton(val2.transform, "Save", -135f, new UnityAction(SaveLimitPopup));
		Transform transform = val2.transform;
		object obj = <>c.<>9__51_1;
		if (obj == null)
		{
			UnityAction val5 = delegate
			{
				_limitField.text = "";
				SaveLimitPopup();
			};
			<>c.<>9__51_1 = val5;
			obj = (object)val5;
		}
		CreatePopupButton(transform, "No limit", 0f, (UnityAction)obj);
		CreatePopupButton(val2.transform, "Cancel", 135f, new UnityAction(CloseLimitPopup));
		_limitPopup.SetActive(false);
	}

	private static void CreatePopupButton(Transform parent, string text, float x, UnityAction onClick)
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		GameObject obj = GUIManager.Instance.CreateButton(text, parent, new Vector2(0.5f, 0f), new Vector2(0.5f, 0f), new Vector2(x, 35f), 125f, 40f);
		obj.SetActive(true);
		((UnityEvent)obj.GetComponent<Button>().onClick).AddListener(onClick);
	}

	private static void OpenLimitPopup(CellView view)
	{
		if (Object.op_Implicit((Object)(object)_limitPopup))
		{
			_limitTarget = view;
			_limitPopupTitle.text = "Keep up to how many\n" + view.DisplayName + "?";
			int quantityLimit = LootFilterService.GetQuantityLimit(view.PrefabName);
			_limitField.text = ((quantityLimit > 0) ? quantityLimit.ToString() : "");
			_limitPopup.SetActive(true);
			_limitPopup.transform.SetAsLastSibling();
			((Selectable)_limitField).Select();
			_limitField.ActivateInputField();
		}
	}

	private static void SaveLimitPopup()
	{
		if (_limitTarget != null)
		{
			int.TryParse(_limitField.text, out var result);
			LootFilterService.SetQuantityLimit(_limitTarget.PrefabName, result);
			RefreshCell(_limitTarget);
			UpdateTitle();
			Logger.LogInfo((object)$"[LootFilter] {_limitTarget.PrefabName} limit={result}");
		}
		CloseLimitPopup();
	}

	private static void CloseLimitPopup()
	{
		_limitTarget = null;
		if (Object.op_Implicit((Object)(object)_limitField))
		{
			_limitField.DeactivateInputField();
		}
		if (Object.op_Implicit((Object)(object)_limitPopup))
		{
			_limitPopup.SetActive(false);
		}
	}

	private static Sprite GetItemSprite(ItemDrop item)
	{
		if (_iconCache.TryGetValue(((Object)item).name, out var value))
		{
			return value;
		}
		ItemData itemData = item.m_itemData;
		Sprite val = ((itemData != null && itemData.m_shared?.m_icons?.Length > 0) ? item.m_itemData.m_shared.m_icons[0] : null);
		_iconCache[((Object)item).name] = val;
		return val;
	}
}
internal class CellTooltip : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler
{
	private const float ShowDelay = 0.3f;

	private static readonly Vector2 CursorOffset = new Vector2(20f, -20f);

	private static RectTransform s_tooltip;

	private static Text s_topicText;

	private static Text s_bodyText;

	private static CellTooltip s_owner;

	private string _topic = "";

	private string _text = "";

	private bool _hovered;

	private float _timer;

	public void Set(string topic, string text)
	{
		_topic = topic;
		_text = text;
		if ((Object)(object)s_owner == (Object)(object)this)
		{
			UpdateText();
		}
	}

	public void OnPointerEnter(PointerEventData eventData)
	{
		_hovered = true;
		_timer = 0f;
	}

	public void OnPointerExit(PointerEventData eventData)
	{
		_hovered = false;
		Hide();
	}

	private void OnDisable()
	{
		_hovered = false;
		Hide();
	}

	private void LateUpdate()
	{
		if (!_hovered)
		{
			return;
		}
		if ((Object)(object)s_owner != (Object)(object)this)
		{
			_timer += Time.unscaledDeltaTime;
			if (_timer < 0.3f)
			{
				return;
			}
			Show();
		}
		if (Object.op_Implicit((Object)(object)s_tooltip))
		{
			PositionAtCursor();
		}
	}

	private void Show()
	{
		if (!Object.op_Implicit((Object)(object)s_tooltip))
		{
			BuildTooltip();
		}
		s_owner = this;
		UpdateText();
		((Transform)s_tooltip).SetAsLastSibling();
		((Component)s_tooltip).gameObject.SetActive(true);
	}

	private void Hide()
	{
		if (!((Object)(object)s_owner != (Object)(object)this))
		{
			s_owner = null;
			if (Object.op_Implicit((Object)(object)s_tooltip))
			{
				((Component)s_tooltip).gameObject.SetActive(false);
			}
		}
	}

	private void UpdateText()
	{
		s_topicText.text = _topic;
		s_bodyText.text = _text;
		LayoutRebuilder.ForceRebuildLayoutImmediate(s_tooltip);
	}

	private static void BuildTooltip()
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Expected O, but got Unknown
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Expected O, but got Unknown
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: 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)
		GameObject val = new GameObject("LootFilterTooltip", new Type[1] { typeof(RectTransform) });
		val.transform.SetParent(GUIManager.CustomGUIFront.transform, false);
		s_tooltip = (RectTransform)val.transform;
		RectTransform obj = s_tooltip;
		Vector2 anchorMin = (s_tooltip.anchorMax = Vector2.zero);
		obj.anchorMin = anchorMin;
		s_tooltip.pivot = new Vector2(0f, 1f);
		Image obj2 = val.AddComponent<Image>();
		((Graphic)obj2).color = new Color(0f, 0f, 0f, 0.85f);
		((Graphic)obj2).raycastTarget = false;
		VerticalLayoutGroup obj3 = val.AddComponent<VerticalLayoutGroup>();
		((LayoutGroup)obj3).padding = new RectOffset(10, 10, 6, 8);
		((HorizontalOrVerticalLayoutGroup)obj3).spacing = 2f;
		((LayoutGroup)obj3).childAlignment = (TextAnchor)0;
		((HorizontalOrVerticalLayoutGroup)obj3).childControlWidth = true;
		((HorizontalOrVerticalLayoutGroup)obj3).childControlHeight = true;
		((HorizontalOrVerticalLayoutGroup)obj3).childForceExpandWidth = false;
		((HorizontalOrVerticalLayoutGroup)obj3).childForceExpandHeight = false;
		ContentSizeFitter obj4 = val.AddComponent<ContentSizeFitter>();
		obj4.horizontalFit = (FitMode)2;
		obj4.verticalFit = (FitMode)2;
		s_topicText = CreateLine(val.transform, 18, GUIManager.Instance.ValheimOrange);
		s_bodyText = CreateLine(val.transform, 14, Color.white);
		val.SetActive(false);
	}

	private static Text CreateLine(Transform parent, int fontSize, Color color)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		Text component = GUIManager.Instance.CreateText("", parent, Vector2.zero, Vector2.zero, Vector2.zero, GUIManager.Instance.AveriaSerifBold, fontSize, color, true, Color.black, 0f, 0f, false).GetComponent<Text>();
		component.alignment = (TextAnchor)0;
		component.horizontalOverflow = (HorizontalWrapMode)1;
		component.verticalOverflow = (VerticalWrapMode)1;
		component.supportRichText = true;
		((Graphic)component).raycastTarget = false;
		return component;
	}

	private static void PositionAtCursor()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: 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_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: 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: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: 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_009c: 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)
		float x = ((Transform)s_tooltip).lossyScale.x;
		Rect rect = s_tooltip.rect;
		Vector2 val = ((Rect)(ref rect)).size * x;
		Vector2 val2 = CursorOffset * x;
		Vector2 val3 = Vector2.op_Implicit(ZInput.pointerPosition);
		float num = val3.x + val2.x;
		if (num + val.x > (float)Screen.width)
		{
			num = val3.x - val2.x - val.x;
		}
		float num2 = val3.y + val2.y;
		if (num2 - val.y < 0f)
		{
			num2 = val3.y - val2.y + val.y;
		}
		num = Mathf.Clamp(num, 0f, Mathf.Max(0f, (float)Screen.width - val.x));
		num2 = Mathf.Clamp(num2, Mathf.Min(val.y, (float)Screen.height), (float)Screen.height);
		((Transform)s_tooltip).position = new Vector3(num, num2, 0f);
	}
}
internal class RightClickHandler : MonoBehaviour, IPointerClickHandler, IEventSystemHandler
{
	public Action OnRightClick;

	public void OnPointerClick(PointerEventData eventData)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Invalid comparison between Unknown and I4
		if ((int)eventData.button == 1)
		{
			OnRightClick?.Invoke();
		}
	}
}
internal static class GameObjectExtensions
{
	public static T GetOrAddComponent<T>(this GameObject go) where T : Component
	{
		return go.GetComponent<T>() ?? go.AddComponent<T>();
	}
}
[BepInPlugin("com.ukie.ValheimLootFilter", "LootFilter", "1.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
internal class ValheimLootFilter : BaseUnityPlugin
{
	public const string PluginGUID = "com.ukie.ValheimLootFilter";

	public const string PluginName = "LootFilter";

	public const string PluginVersion = "1.1.0";

	public static CustomLocalization Localization = LocalizationManager.Instance.GetLocalization();

	private Harmony _harmony;

	private ConfigEntry<KeyboardShortcut> _openPanelKey;

	private ConfigEntry<KeyboardShortcut> _toggleFilterKey;

	private void Awake()
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Expected O, but got Unknown
		LootFilterService.Init(((BaseUnityPlugin)this).Config);
		InventoryFilterPatch.Init(((BaseUnityPlugin)this).Config);
		_openPanelKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Keybinds", "Open panel", new KeyboardShortcut((KeyCode)108, Array.Empty<KeyCode>()), "Open or close the loot filter panel");
		_toggleFilterKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Keybinds", "Toggle filter", new KeyboardShortcut((KeyCode)108, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }), "Turn the loot filter on or off");
		_harmony = new Harmony("com.ukie.ValheimLootFilter");
		_harmony.PatchAll(typeof(LootFilterService.Patches));
		_harmony.PatchAll(typeof(InventoryGuiPatch));
		_harmony.PatchAll(typeof(LootFilterUI.Patches));
		_harmony.PatchAll(typeof(InventoryFilterPatch));
		Logger.LogInfo((object)"LootFilter has landed");
	}

	private void Update()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		if (ZInput.instance == null)
		{
			return;
		}
		LootFilterUI.HandleEscape();
		if (!CanUseHotkeys())
		{
			return;
		}
		KeyboardShortcut value = _toggleFilterKey.Value;
		KeyboardShortcut value2 = _openPanelKey.Value;
		bool flag = Hotkeys.IsDown(value);
		bool flag2 = Hotkeys.IsDown(value2);
		if (flag && flag2)
		{
			if (((KeyboardShortcut)(ref value)).Modifiers.Count() >= ((KeyboardShortcut)(ref value2)).Modifiers.Count())
			{
				flag2 = false;
			}
			else
			{
				flag = false;
			}
		}
		if (flag)
		{
			ToggleFilter();
		}
		if (flag2)
		{
			LootFilterUI.TogglePanel();
		}
	}

	private static bool CanUseHotkeys()
	{
		if (!LootFilterUI.IsTyping && (Object)(object)Player.m_localPlayer != (Object)null)
		{
			return ((Character)Player.m_localPlayer).TakeInput();
		}
		return false;
	}

	private static void ToggleFilter()
	{
		bool flag = LootFilterService.ToggleEnabled();
		Player localPlayer = Player.m_localPlayer;
		if (localPlayer != null)
		{
			((Character)localPlayer).Message((MessageType)2, flag ? "Loot filter on" : "Loot filter off", 0, (Sprite)null, false);
		}
	}
}