Decompiled source of Handpicked v1.0.0

Handpicked.dll

Decompiled 3 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Cards;
using Core;
using Core.Itens;
using Core.Kingdoms;
using GameplayInterface;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Handpicked")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Handpicked")]
[assembly: AssemblyTitle("Handpicked")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 Handpicked
{
	[BepInPlugin("crimsonotter.9kings.handpicked", "Handpicked", "1.0.0")]
	public class Plugin : BasePlugin
	{
		public const string Guid = "crimsonotter.9kings.handpicked";

		public const string Name = "Handpicked";

		public const string Version = "1.0.0";

		internal static ManualLogSource Logger;

		public override void Load()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			Logger = ((BasePlugin)this).Log;
			new Harmony("crimsonotter.9kings.handpicked").PatchAll(typeof(Patches));
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(76, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Handpicked");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.0");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded. F6 = card picker, F7 = permanent mode, F9 = clear permanent cards.");
			}
			log.LogInfo(val);
		}
	}
	internal class Entry
	{
		public string Key;

		public CardSo Card;
	}
	internal class PermInfo
	{
		public CardSo Card;

		public int Count;
	}
	internal class Pending
	{
		public string Key;

		public int Frames;
	}
	internal static class Patches
	{
		private const float RowH = 26f;

		private static bool _open;

		private static bool _permanentMode;

		private static int _perPage = 18;

		private static bool _inputBlocked;

		private static int _unblockIn;

		private static bool _pEsc;

		private static bool _pF6;

		private static bool _pF7;

		private static bool _pF9;

		private static bool _pUp;

		private static bool _pDown;

		private static bool _pPgUp;

		private static bool _pPgDn;

		private static bool _pEnter;

		private static bool _pBack;

		private static bool _pDel;

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

		private static bool _hasLabel = true;

		private static bool _hasButton = true;

		private static readonly List<Entry> _all = new List<Entry>();

		private static readonly List<Entry> _shown = new List<Entry>();

		private static string _filter = "";

		private static string _lastFilter = null;

		private static string _status = "";

		private static int _sel;

		private static readonly Dictionary<string, PermInfo> _perm = new Dictionary<string, PermInfo>(StringComparer.OrdinalIgnoreCase);

		private static readonly List<Pending> _pending = new List<Pending>();

		private static string _pitKey;

		private static int _pitFrames;

		private static int _pitLogs;

		private static int _placedLogs;

		private static int _frame;

		private static readonly Dictionary<string, int> _absent = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);

		private static KeyControl[] _tKeys;

		private static char[] _tChars;

		private static bool[] _tPrev;

		[HarmonyPatch(typeof(Game), "Update")]
		[HarmonyPostfix]
		private static void GameUpdate_Postfix()
		{
			try
			{
				Keyboard current = Keyboard.current;
				if (current == null)
				{
					return;
				}
				bool isPressed = ((ButtonControl)current.f6Key).isPressed;
				if (isPressed && !_pF6)
				{
					if (_open)
					{
						ClosePicker();
					}
					else
					{
						OpenPicker();
					}
				}
				_pF6 = isPressed;
				bool isPressed2 = ((ButtonControl)current.f7Key).isPressed;
				if (isPressed2 && !_pF7)
				{
					_permanentMode = !_permanentMode;
					_status = "Permanent mode " + (_permanentMode ? "ON" : "OFF");
					Plugin.Logger.LogInfo((object)_status);
				}
				_pF7 = isPressed2;
				bool isPressed3 = ((ButtonControl)current.f9Key).isPressed;
				if (isPressed3 && !_pF9)
				{
					_perm.Clear();
					_pending.Clear();
					_absent.Clear();
					_status = "Permanent list cleared";
					Plugin.Logger.LogInfo((object)_status);
				}
				_pF9 = isPressed3;
				ProcessPending();
				_frame++;
				if (_perm.Count > 0 && _frame % 30 == 0)
				{
					CheckPermanent();
				}
				if (_unblockIn > 0)
				{
					_unblockIn--;
					if (_unblockIn == 0 && !_open)
					{
						SetInputBlocked(block: false);
					}
				}
				if (_open && _frame % 60 == 0)
				{
					SetInputBlocked(block: true);
				}
				bool isPressed4 = ((ButtonControl)current.escapeKey).isPressed;
				if (isPressed4 && !_pEsc && _open)
				{
					ClosePicker();
				}
				_pEsc = isPressed4;
				if (_open)
				{
					bool isPressed5 = ((ButtonControl)current.upArrowKey).isPressed;
					bool isPressed6 = ((ButtonControl)current.downArrowKey).isPressed;
					bool isPressed7 = ((ButtonControl)current.pageUpKey).isPressed;
					bool isPressed8 = ((ButtonControl)current.pageDownKey).isPressed;
					bool isPressed9 = ((ButtonControl)current.enterKey).isPressed;
					if (isPressed5 && !_pUp)
					{
						MoveSel(-1);
					}
					if (isPressed6 && !_pDown)
					{
						MoveSel(1);
					}
					if (isPressed7 && !_pPgUp)
					{
						MoveSel(-_perPage);
					}
					if (isPressed8 && !_pPgDn)
					{
						MoveSel(_perPage);
					}
					if (isPressed9 && !_pEnter)
					{
						AddSelected();
					}
					_pUp = isPressed5;
					_pDown = isPressed6;
					_pPgUp = isPressed7;
					_pPgDn = isPressed8;
					_pEnter = isPressed9;
					PollTyping(current);
				}
			}
			catch (Exception ex)
			{
				LogOnce("update", "Update hook failed: " + ex.Message);
			}
		}

		private static void OpenPicker()
		{
			_open = true;
			_unblockIn = 0;
			RefreshCards();
			SetInputBlocked(block: true);
		}

		private static void ClosePicker()
		{
			_open = false;
			_unblockIn = 8;
		}

		private static void SetInputBlocked(bool block)
		{
			try
			{
				GameInput inputClass = Input.InputClass;
				if (inputClass != null)
				{
					if (block)
					{
						inputClass.Disable();
					}
					else
					{
						inputClass.Enable();
					}
					if (_inputBlocked != block)
					{
						Plugin.Logger.LogInfo((object)("Game input " + (block ? "blocked" : "restored")));
					}
					_inputBlocked = block;
				}
			}
			catch (Exception ex)
			{
				LogOnce("inputblock", "Could not switch game input: " + ex.Message);
			}
		}

		private static void PollTyping(Keyboard kb)
		{
			if (_tKeys == null)
			{
				BuildTypingKeys(kb);
			}
			string filter = _filter;
			for (int i = 0; i < _tKeys.Length; i++)
			{
				bool isPressed = ((ButtonControl)_tKeys[i]).isPressed;
				if (isPressed && !_tPrev[i])
				{
					_filter += _tChars[i];
				}
				_tPrev[i] = isPressed;
			}
			bool isPressed2 = ((ButtonControl)kb.backspaceKey).isPressed;
			if (isPressed2 && !_pBack && _filter.Length > 0)
			{
				_filter = _filter.Substring(0, _filter.Length - 1);
			}
			_pBack = isPressed2;
			bool isPressed3 = ((ButtonControl)kb.deleteKey).isPressed;
			if (isPressed3 && !_pDel)
			{
				_filter = "";
			}
			_pDel = isPressed3;
			if (_filter != filter)
			{
				ApplyFilter();
			}
		}

		private static void BuildTypingKeys(Keyboard kb)
		{
			List<KeyControl> keys = new List<KeyControl>();
			List<char> chars = new List<char>();
			A(kb.aKey, 'a');
			A(kb.bKey, 'b');
			A(kb.cKey, 'c');
			A(kb.dKey, 'd');
			A(kb.eKey, 'e');
			A(kb.fKey, 'f');
			A(kb.gKey, 'g');
			A(kb.hKey, 'h');
			A(kb.iKey, 'i');
			A(kb.jKey, 'j');
			A(kb.kKey, 'k');
			A(kb.lKey, 'l');
			A(kb.mKey, 'm');
			A(kb.nKey, 'n');
			A(kb.oKey, 'o');
			A(kb.pKey, 'p');
			A(kb.qKey, 'q');
			A(kb.rKey, 'r');
			A(kb.sKey, 's');
			A(kb.tKey, 't');
			A(kb.uKey, 'u');
			A(kb.vKey, 'v');
			A(kb.wKey, 'w');
			A(kb.xKey, 'x');
			A(kb.yKey, 'y');
			A(kb.zKey, 'z');
			A(kb.digit0Key, '0');
			A(kb.digit1Key, '1');
			A(kb.digit2Key, '2');
			A(kb.digit3Key, '3');
			A(kb.digit4Key, '4');
			A(kb.digit5Key, '5');
			A(kb.digit6Key, '6');
			A(kb.digit7Key, '7');
			A(kb.digit8Key, '8');
			A(kb.digit9Key, '9');
			A(kb.spaceKey, ' ');
			A(kb.minusKey, '_');
			_tKeys = keys.ToArray();
			_tChars = chars.ToArray();
			_tPrev = new bool[_tKeys.Length];
			void A(KeyControl k, char c)
			{
				keys.Add(k);
				chars.Add(c);
			}
		}

		[HarmonyPatch(typeof(KingdomArea), "OnCardPlaced")]
		[HarmonyPostfix]
		private static void OnCardPlaced_Postfix(CardSo card)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			try
			{
				if ((Object)(object)card == (Object)null)
				{
					return;
				}
				string text = Norm(((Object)card).name);
				if (_placedLogs < 40)
				{
					_placedLogs++;
					ManualLogSource logger = Plugin.Logger;
					bool flag = default(bool);
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(28, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("OnCardPlaced: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (permanent: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(_perm.ContainsKey(text));
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(")");
					}
					logger.LogInfo(val);
				}
				if (_pitKey != null && string.Equals(_pitKey, text, StringComparison.OrdinalIgnoreCase))
				{
					_pitKey = null;
				}
				if (!_perm.ContainsKey(text))
				{
					return;
				}
				foreach (Pending item in _pending)
				{
					if (string.Equals(item.Key, text, StringComparison.OrdinalIgnoreCase))
					{
						return;
					}
				}
				_pending.Add(new Pending
				{
					Key = text,
					Frames = 20
				});
			}
			catch (Exception ex)
			{
				LogOnce("placed", "OnCardPlaced hook failed: " + ex.Message);
			}
		}

		[HarmonyPatch(typeof(ThePit), "PlaceEvent")]
		[HarmonyPrefix]
		private static void PitPlace_Prefix(out string __state)
		{
			__state = null;
			try
			{
				GameplayUI_HandCards val = FindHand();
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				HandCard selectedCard = val.SelectedCard;
				if (!((Object)(object)selectedCard == (Object)null))
				{
					CardSo card = selectedCard.Card;
					if (!((Object)(object)card == (Object)null))
					{
						__state = Norm(((Object)card).name);
					}
				}
			}
			catch (Exception ex)
			{
				LogOnce("pitpre", "Pit prefix failed: " + ex.Message);
			}
		}

		[HarmonyPatch(typeof(ThePit), "PlaceEvent")]
		[HarmonyPostfix]
		private static void PitPlace_Postfix(bool __result, string __state)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			try
			{
				if (_pitLogs < 40)
				{
					_pitLogs++;
					ManualLogSource logger = Plugin.Logger;
					bool flag = default(bool);
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(31, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Well PlaceEvent: result=");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(__result);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", card=");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(__state ?? "(none)");
					}
					logger.LogInfo(val);
				}
				if (__result && __state != null && _perm.ContainsKey(__state))
				{
					_pitKey = __state;
					_pitFrames = 30;
					Plugin.Logger.LogInfo((object)("Permanent card dropped on the well: " + __state));
				}
			}
			catch (Exception ex)
			{
				LogOnce("pitpost", "Pit postfix failed: " + ex.Message);
			}
		}

		private static void ProcessPending()
		{
			if (_pitKey != null)
			{
				_pitFrames--;
				if (_pitFrames <= 0)
				{
					if (_perm.TryGetValue(_pitKey, out var value))
					{
						value.Count--;
						if (value.Count <= 0)
						{
							_perm.Remove(_pitKey);
						}
						Plugin.Logger.LogInfo((object)("Card thrown into the well, one permanent copy less: " + _pitKey));
						_status = "Thrown in the well, one permanent copy less: " + _pitKey;
					}
					_pitKey = null;
				}
			}
			for (int num = _pending.Count - 1; num >= 0; num--)
			{
				Pending pending = _pending[num];
				pending.Frames--;
				if (pending.Frames <= 0)
				{
					_pending.RemoveAt(num);
					ReAdd(pending.Key);
				}
			}
		}

		private static void CheckPermanent()
		{
			try
			{
				GameplayUI_HandCards val = FindHand();
				if ((Object)(object)val == (Object)null || !((Component)val).gameObject.activeInHierarchy)
				{
					_absent.Clear();
					return;
				}
				string text = null;
				HandCard selectedCard = val.SelectedCard;
				if ((Object)(object)selectedCard != (Object)null && (Object)(object)selectedCard.Card != (Object)null)
				{
					text = Norm(((Object)selectedCard.Card).name);
				}
				foreach (string item in new List<string>(_perm.Keys))
				{
					if (_pitKey != null && string.Equals(_pitKey, item, StringComparison.OrdinalIgnoreCase))
					{
						continue;
					}
					if (text != null && string.Equals(text, item, StringComparison.OrdinalIgnoreCase))
					{
						_absent[item] = 0;
					}
					else
					{
						if (!_perm.TryGetValue(item, out var value))
						{
							continue;
						}
						if (CountInHand(val, item) >= value.Count)
						{
							_absent[item] = 0;
							continue;
						}
						int value2;
						int num = ((!_absent.TryGetValue(item, out value2)) ? 1 : (value2 + 1));
						_absent[item] = num;
						if (num >= 2)
						{
							_absent[item] = 0;
							ReAdd(item);
						}
					}
				}
			}
			catch (Exception ex)
			{
				LogOnce("check", "Permanent check failed: " + ex.Message);
			}
		}

		private static int PermCopies()
		{
			int num = 0;
			foreach (KeyValuePair<string, PermInfo> item in _perm)
			{
				num += item.Value.Count;
			}
			return num;
		}

		private static int CountInHand(GameplayUI_HandCards hand, string key)
		{
			int num = 0;
			List<HandCard> cards = hand.Cards;
			if (cards == null)
			{
				return 0;
			}
			for (int i = 0; i < cards.Count; i++)
			{
				HandCard val = cards[i];
				if (!((Object)(object)val == (Object)null))
				{
					CardSo card = val.Card;
					if (!((Object)(object)card == (Object)null) && string.Equals(Norm(((Object)card).name), key, StringComparison.OrdinalIgnoreCase))
					{
						num++;
					}
				}
			}
			return num;
		}

		private static void ReAdd(string key)
		{
			try
			{
				if (!_perm.TryGetValue(key, out var value))
				{
					return;
				}
				CardSo card = value.Card;
				GameplayUI_HandCards val = FindHand();
				int num = value.Count;
				if ((Object)(object)val != (Object)null)
				{
					num = value.Count - CountInHand(val, key);
				}
				if (num <= 0)
				{
					return;
				}
				if ((Object)(object)card == (Object)null)
				{
					RefreshCards();
					foreach (Entry item in _all)
					{
						if (string.Equals(item.Key, key, StringComparison.OrdinalIgnoreCase))
						{
							card = item.Card;
							break;
						}
					}
					if ((Object)(object)card == (Object)null)
					{
						LogOnce("lost_" + key, "Permanent card not found any more: " + key);
						return;
					}
					value.Card = card;
				}
				if (AddToHand(card, quiet: true, num))
				{
					Plugin.Logger.LogInfo((object)("Permanent card put back in hand: " + key + " x" + num));
				}
			}
			catch (Exception ex)
			{
				LogOnce("readd", "Re-adding permanent card failed: " + ex.Message);
			}
		}

		[HarmonyPatch(typeof(Game), "OnGUI")]
		[HarmonyPostfix]
		private static void GameOnGUI_Postfix()
		{
			if (!_open)
			{
				return;
			}
			try
			{
				DrawPicker();
			}
			catch (Exception ex)
			{
				LogOnce("draw", "Picker drawing failed: " + ex.Message);
			}
		}

		private static void DrawPicker()
		{
			//IL_006b: 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_00bd: 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_0127: 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_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			float num = 560f;
			float num2 = 640f;
			if (num2 > (float)Screen.height - 20f)
			{
				num2 = (float)Screen.height - 20f;
			}
			float num3 = ((float)Screen.width - num) / 2f;
			float num4 = ((float)Screen.height - num2) / 2f;
			_perPage = (int)((num2 - 150f) / 26f);
			if (_perPage < 3)
			{
				_perPage = 3;
			}
			GUI.Box(new Rect(num3, num4, num, num2), "");
			GUI.Box(new Rect(num3 + 4f, num4 + 4f, num - 8f, 26f), "Card picker  (F6 or Esc closes)");
			Text(new Rect(num3 + 10f, num4 + 36f, num - 20f, 24f), "Search: " + _filter + "_");
			Text(new Rect(num3 + 10f, num4 + 60f, num - 20f, 24f), _status ?? "");
			Text(new Rect(num3 + 10f, num4 + 84f, num - 20f, 24f), "Permanent mode: " + (_permanentMode ? "ON" : "OFF") + " (F7)    permanent copies: " + PermCopies() + " (F9 clears)");
			int count = _shown.Count;
			int num5 = ((count == 0) ? 1 : ((count + _perPage - 1) / _perPage));
			int num6 = _sel / _perPage;
			Text(new Rect(num3 + 10f, num4 + 108f, num - 20f, 24f), "Page " + (num6 + 1) + "/" + num5 + "   " + count + " cards   type to search, Delete clears, Up/Down+Enter");
			int num7 = num6 * _perPage;
			int num8 = num7 + _perPage;
			if (num8 > count)
			{
				num8 = count;
			}
			Rect r = default(Rect);
			for (int i = num7; i < num8; i++)
			{
				Entry entry = _shown[i];
				if (entry == null || (Object)(object)entry.Card == (Object)null)
				{
					continue;
				}
				((Rect)(ref r))..ctor(num3 + 10f, num4 + 138f + (float)(i - num7) * 26f, num - 20f, 24f);
				string s = ((i == _sel) ? ">  " : "    ") + (_perm.ContainsKey(entry.Key) ? ("[P x" + _perm[entry.Key].Count + "] ") : "          ") + entry.Key;
				if (_hasButton)
				{
					if (TryButton(r, s))
					{
						_sel = i;
						AddSelected();
					}
				}
				else
				{
					Text(r, s);
				}
			}
		}

		private static void Text(Rect r, string s)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			if (_hasLabel)
			{
				try
				{
					GUI.Label(r, s);
					return;
				}
				catch (Exception ex)
				{
					_hasLabel = false;
					LogOnce("label", "GUI.Label unavailable: " + ex.Message);
				}
			}
			GUI.Box(r, s);
		}

		private static bool TryButton(Rect r, string s)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				return GUI.Button(r, s);
			}
			catch (Exception ex)
			{
				_hasButton = false;
				LogOnce("button", "GUI.Button unavailable (keyboard only): " + ex.Message);
				return false;
			}
		}

		private static string Norm(string n)
		{
			if (n == null)
			{
				return "";
			}
			return n.Replace("(Clone)", "").Trim();
		}

		private static int LevelOf(CardSo c)
		{
			try
			{
				return c.CardLevel;
			}
			catch
			{
				return 0;
			}
		}

		private static void MoveSel(int delta)
		{
			if (_shown.Count == 0)
			{
				_sel = 0;
				return;
			}
			int num = _sel + delta;
			if (num < 0)
			{
				num = 0;
			}
			if (num > _shown.Count - 1)
			{
				num = _shown.Count - 1;
			}
			_sel = num;
		}

		private static void RefreshCards()
		{
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Expected O, but got Unknown
			try
			{
				Dictionary<string, CardSo> dictionary = new Dictionary<string, CardSo>(StringComparer.OrdinalIgnoreCase);
				Dictionary<string, int> dictionary2 = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
				Il2CppArrayBase<CardSo> val = Resources.FindObjectsOfTypeAll<CardSo>();
				foreach (CardSo item in val)
				{
					if ((Object)(object)item == (Object)null)
					{
						continue;
					}
					string text = Norm(((Object)item).name);
					if (text.Length != 0)
					{
						int num = LevelOf(item);
						if (!dictionary.ContainsKey(text) || num < dictionary2[text])
						{
							dictionary[text] = item;
							dictionary2[text] = num;
						}
					}
				}
				_all.Clear();
				foreach (KeyValuePair<string, CardSo> item2 in dictionary)
				{
					_all.Add(new Entry
					{
						Key = item2.Key,
						Card = item2.Value
					});
				}
				_all.Sort((Entry a, Entry b) => string.Compare(a.Key, b.Key, StringComparison.OrdinalIgnoreCase));
				_lastFilter = null;
				ApplyFilter();
				_status = _all.Count + " different cards loaded.";
				ManualLogSource logger = Plugin.Logger;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(53, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Card list refreshed: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(_all.Count);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" different cards (from ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(val.Length);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" objects)");
				}
				logger.LogInfo(val2);
			}
			catch (Exception ex)
			{
				_status = "Could not list cards: " + ex.Message;
				Plugin.Logger.LogWarning((object)_status);
			}
		}

		private static void ApplyFilter()
		{
			_lastFilter = _filter;
			_shown.Clear();
			string text = (_filter ?? "").Trim();
			foreach (Entry item in _all)
			{
				if (text.Length == 0 || item.Key.IndexOf(text, StringComparison.OrdinalIgnoreCase) >= 0)
				{
					_shown.Add(item);
				}
			}
			_sel = 0;
		}

		private static void AddSelected()
		{
			if (_shown.Count == 0 || _sel < 0 || _sel >= _shown.Count)
			{
				return;
			}
			Entry entry = _shown[_sel];
			if (entry == null || (Object)(object)entry.Card == (Object)null || !AddToHand(entry.Card, quiet: false))
			{
				return;
			}
			if (_permanentMode)
			{
				if (_perm.TryGetValue(entry.Key, out var value))
				{
					value.Count++;
				}
				else
				{
					_perm[entry.Key] = new PermInfo
					{
						Card = entry.Card,
						Count = 1
					};
				}
				_status = "Added (permanent x" + _perm[entry.Key].Count + "): " + entry.Key;
				Plugin.Logger.LogInfo((object)("Marked permanent: " + entry.Key + " x" + _perm[entry.Key].Count));
			}
			else
			{
				_status = "Added: " + entry.Key;
			}
		}

		private static GameplayUI_HandCards FindHand()
		{
			//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)
			GameplayUI_HandCards val = null;
			foreach (GameplayUI_HandCards item in Resources.FindObjectsOfTypeAll<GameplayUI_HandCards>())
			{
				if ((Object)(object)item == (Object)null)
				{
					continue;
				}
				GameObject gameObject = ((Component)item).gameObject;
				Scene scene = gameObject.scene;
				if (((Scene)(ref scene)).IsValid())
				{
					if ((Object)(object)val == (Object)null || gameObject.activeInHierarchy)
					{
						val = item;
					}
					if (gameObject.activeInHierarchy)
					{
						break;
					}
				}
			}
			return val;
		}

		private static bool AddToHand(CardSo card, bool quiet, int amount = 1)
		{
			try
			{
				GameplayUI_HandCards val = FindHand();
				if ((Object)(object)val == (Object)null)
				{
					if (!quiet)
					{
						_status = "No hand found. Start a run first.";
					}
					return false;
				}
				val.Create(card, amount, false);
				if (!quiet)
				{
					Plugin.Logger.LogInfo((object)("Added card to hand: " + ((Object)card).name));
				}
				return true;
			}
			catch (Exception ex)
			{
				if (!quiet)
				{
					_status = "Could not add card: " + ex.Message;
				}
				Plugin.Logger.LogWarning((object)("Could not add card: " + ex.Message));
				return false;
			}
		}

		private static void LogOnce(string key, string msg)
		{
			if (_logged.Add(key))
			{
				Plugin.Logger.LogWarning((object)msg);
			}
		}
	}
}