Decompiled source of MT2CheatGUI v1.0.1

plugins/MT2CheatGUI/MT2CheatGUI.dll

Decompiled 13 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using I2.Loc;
using Microsoft.CodeAnalysis;
using ShinyShoe;
using ShinyShoe.Loading;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MT2CheatGUI
{
	[BepInPlugin("jiesi.mt2.cheatgui", "MT2 Cheat GUI", "1.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		private class UpgradeRow
		{
			public CardUpgradeState state;

			public string name;

			public string desc;

			public Sprite icon;
		}

		private enum PickerMode
		{
			Cards,
			Relics,
			Enhancers,
			Deck
		}

		private class Entry
		{
			public GameData data;

			public string id;

			public string name;

			public string english;

			public string asset;

			public string info;

			public string clan;

			public int classIndex;

			public CardType cardType;

			public string searchKey;

			public CollectableRarity rarity = (CollectableRarity)(-1);

			public int cost = -1;

			public bool costX;

			public Sprite icon;

			public string desc;

			public CardState state;
		}

		private class Runner : MonoBehaviour
		{
			public Plugin owner;

			private void Update()
			{
				owner?.Tick();
			}

			private void OnGUI()
			{
				owner?.DrawGUI();
			}
		}

		private Entry pEditEntry;

		private RectTransform pPreviewRoot;

		private CardUI pPreviewUI;

		private Vector2 pEditScroll;

		private string pEditSearch = "";

		private Dictionary<string, EnhancerData> pEnhancerByUpgrade;

		private bool pEditIgnoreRules;

		private Action pPendingEdit;

		private bool pPreviewPending;

		private List<CardUpgradeMaskData> pDefaultUpgradeMasks;

		private ConfigEntry<bool> showButton;

		private ConfigEntry<float> buttonX;

		private ConfigEntry<float> buttonY;

		private const float BtnSize = 64f;

		private RectTransform pBtnBlocker;

		private bool btnDragging;

		private bool btnMoved;

		private bool btnToggleRequested;

		private Vector2 btnDragStartMouse;

		private Vector2 btnDragStartPos;

		private GUIStyle sFloatBtn;

		private ConfigEntry<bool> buttonInTopBar;

		private RectTransform hudClassesUI;

		private float hudLookupAt;

		private GUIStyle sFloatBtnOn;

		private GUIStyle sBtnTip;

		private bool btnForceHover;

		private Texture2D buttonIcon;

		private bool buttonIconTried;

		private static readonly FieldInfo I2CurrentLanguageField = typeof(LocalizationManager).GetField("mCurrentLanguage", BindingFlags.Static | BindingFlags.NonPublic);

		private static readonly Dictionary<string, string> En = new Dictionary<string, string>
		{
			["常用"] = "Common",
			["加卡"] = "Add Cards",
			["神器"] = "Artifacts",
			["牌组"] = "Deck",
			["强化石"] = "Upgrades",
			["全部"] = "All",
			["无派系"] = "No clan",
			["找不到游戏命令 "] = "Game command not found: ",
			["(游戏可能更新了)"] = " (the game may have been updated)",
			["执行失败:"] = "Failed: ",
			["要先开始或继续一局游戏才能用"] = "Start or continue a run first",
			["这个只能在战斗中用"] = "Only available in battle",
			["普通"] = "Common",
			["罕见"] = "Uncommon",
			["稀有"] = "Rare",
			["勇者"] = "Champion",
			["初始"] = "Starter",
			["法术"] = "Spell",
			["单位"] = "Unit",
			["灾祸"] = "Blight",
			["垃圾"] = "Junk",
			["装备"] = "Equipment",
			["房间"] = "Room",
			[" · 非图鉴"] = " · not in logbook",
			["游戏还没加载完,进入主菜单后再打开。"] = "The game hasn't finished loading. Open this again from the main menu.",
			["未加载"] = "Not loaded",
			["不在对局中(主菜单)"] = "Not in a run (main menu)",
			["金币"] = "Gold",
			["设为这个数"] = "Set to this",
			["金币 +"] = "Gold +",
			["金币设为 "] = "Gold set to ",
			["请输入非负整数"] = "Enter a number ≥ 0",
			["请输入正整数"] = "Enter a number > 0",
			["余烬(战斗中)"] = "Ember (in battle)",
			["余烬 +"] = "Ember +",
			["火炉"] = "Pyre",
			["回满血"] = "Full heal",
			["火炉已回满"] = "Pyre fully healed",
			["+10 血"] = "+10 HP",
			["火炉 +10"] = "Pyre +10",
			["上限"] = "Max",
			["设上限(≤999)"] = "Set max (≤999)",
			["火炉上限设为 "] = "Pyre max HP set to ",
			["开关"] = "Toggles",
			["开"] = "on",
			["关"] = "off",
			[" 无限余烬"] = " Unlimited ember",
			["无限余烬 "] = "Unlimited ember ",
			[" 我方单位无敌"] = " Invincible units",
			["我方单位无敌 "] = "Invincible units ",
			[" 火炉无敌"] = " Invincible pyre",
			["火炉无敌 "] = "Invincible pyre ",
			[" 敌人无敌"] = " Invincible enemies",
			["敌人无敌 "] = "Invincible enemies ",
			["开关只在本次游戏进程有效,重启游戏会恢复。"] = "Toggles last until the game is restarted.",
			["战斗"] = "Battle",
			["抽 1 张"] = "Draw 1",
			["抽 3 张"] = "Draw 3",
			["弃掉手牌"] = "Discard hand",
			["清除技能冷却"] = "Clear ability cooldowns",
			["已清除技能冷却"] = "Ability cooldowns cleared",
			["直接赢下本场战斗"] = "Win this battle now",
			["结束战斗"] = "Battle ended",
			["每层容量"] = "Capacity per floor",
			["三层都设为这个"] = "Set all 3 floors",
			["每层容量设为 "] = "Capacity per floor set to ",
			["随机奖励"] = "Random rewards",
			["随机一张卡"] = "Random card",
			["已给一张随机卡"] = "Gave a random card",
			["随机一个神器"] = "Random artifact",
			["已给一个随机神器"] = "Gave a random artifact",
			["主氏族经验 +1000"] = "Main clan XP +1000",
			["提示:点按钮时游戏本身也可能收到点击,尽量把窗口拖到空白处再点。加卡/神器在「加卡」「神器」页签里搜索。"] = "Tip: the Add Cards / Artifacts / Deck / Upgrades tabs open a full-screen picker with search and filters.",
			["读不到余烬"] = "Can't read ember",
			["默认"] = "Default",
			["费用"] = "Cost",
			["名字"] = "Name",
			["稀有度"] = "Rarity",
			["已拥有"] = "Owned",
			["未拥有"] = "Not owned",
			["小"] = "S",
			["中"] = "M",
			["大"] = "L",
			[" · 勇者"] = " · Champion",
			["勇者卡不能删"] = "Champion cards can't be removed",
			["游戏还在处理上一个操作,稍等一下"] = "The game is still busy, try again in a moment",
			["已删除:"] = "Removed: ",
			["删除失败:"] = "Remove failed: ",
			["复制一张:"] = "Copied: ",
			["(进手牌)"] = " (to hand)",
			["(进牌组)"] = " (to deck)",
			["已移除:"] = "Removed: ",
			["已获得:"] = "Got: ",
			["战斗中不能用强化石"] = "Upgrades can't be used in battle",
			["找不到游戏的强化接口(游戏可能更新了)"] = "Can't find the game's upgrade function (the game may have been updated)",
			["请选择要强化的卡:"] = "Choose a card to upgrade: ",
			["牌组/删牌"] = "Deck / Remove",
			["搜索"] = "Search",
			["清空"] = "Clear",
			["排序"] = "Sort",
			["点击卡牌"] = "On click",
			["删除"] = "Remove",
			["复制一张"] = "Copy",
			["改卡(去掉/加强化)"] = "Edit upgrades",
			["每次加"] = "Add",
			["卡牌大小"] = "Card size",
			["返回面板"] = "Back to panel",
			["✕ 关闭"] = "✕ Close",
			["点击图标获得神器,已拥有的(绿色)再点一下移除。"] = "Click to get an artifact; click an owned (green) one to remove it.",
			["点击强化石,会弹出游戏的选卡界面来升级一张卡。"] = "Click an upgrade stone, then pick a card in the game's card screen.",
			["点击:改这张卡的强化"] = "Click: edit this card's upgrades",
			["<color=#ff8a7a>点击:删除这张</color>"] = "<color=#ff8a7a>Click: remove this card</color>",
			["点击:复制一张"] = "Click: add a copy",
			["这里是你现在的牌组(含升级)。\n顶部选「删除」或「复制一张」,再点卡牌。"] = "Your current deck (with upgrades).\nChoose Remove / Copy / Edit at the top, then click a card.",
			["滚轮上下滚动,点击卡牌加入。\n鼠标移到卡牌上可看氏族和稀有度。"] = "Scroll with the mouse wheel, click a card to add it.\nHover a card to see its clan and rarity.",
			["<color=#ff9a6a>战斗中</color>:加卡直接进手牌"] = "<color=#ff9a6a>In battle</color>: added cards go to your hand",
			["地图/商店:加卡进牌组"] = "Map / shop: added cards go to your deck",
			["清除全部筛选"] = "Clear all filters",
			["氏族"] = "Clan",
			["只看本局的两个氏族"] = "Only this run's clans",
			["类型"] = "Type",
			[" 只显示图鉴里的正常卡"] = " Logbook cards only",
			[" 搜索也匹配卡牌描述"] = " Search card text too",
			["拥有"] = "Owned",
			[" 只显示正常能拿到的神器"] = " Obtainable artifacts only",
			["\n(卡图加载失败,仍可点击加入)"] = "\n(art failed to load, still clickable)",
			["\n加载中…"] = "\nLoading…",
			["已删除"] = "Removed",
			["牌组是空的"] = "Your deck is empty",
			["没有符合条件的卡"] = "No matching cards",
			["<color=#8fe08f>✔ 已拥有 · 点击移除</color>   "] = "<color=#8fe08f>✔ Owned · click to remove</color>   ",
			["(内部强化)"] = "(internal) ",
			["(未知强化)"] = "(unknown upgrade)",
			["已去掉:"] = "Removed: ",
			["去掉失败:"] = "Remove failed: ",
			["这个强化石没有可用的效果"] = "This stone has no usable effect",
			["已加上:"] = "Added: ",
			["加强化失败:"] = "Add failed: ",
			["卡图加载中…"] = "Loading card art…",
			["← 返回牌组"] = "← Back to deck",
			["改卡:"] = "Edit: ",
			["这张卡现在的强化"] = "Upgrades on this card",
			["(没有强化)"] = "(none)",
			["去掉"] = "Remove",
			["加一个强化石(只列出能用在这张卡上的)"] = "Add an upgrade (only ones that fit this card)",
			["(没有合适的强化石)"] = "(no fitting upgrades)",
			["加上"] = "Add",
			[" 显示全部强化石(无视游戏限制)"] = " Show all upgrades (ignore the game's rules)",
			["<color=#ff8a7a>游戏通常不允许用在这张卡上</color>"] = "<color=#ff8a7a>The game normally doesn't allow this on this card</color>",
			["关闭"] = "Close",
			["作弊"] = "Cheat"
		};

		private bool pickerOpen;

		private PickerMode pickerMode;

		private string pSearch = "";

		private bool pSearchText = true;

		private readonly HashSet<int> fClan = new HashSet<int>();

		private readonly HashSet<int> fType = new HashSet<int>();

		private readonly HashSet<int> fRarity = new HashSet<int>();

		private readonly HashSet<int> fCost = new HashSet<int>();

		private int fOwned;

		private bool pLogbookOnly = true;

		private int pSort;

		private int pAddCount = 1;

		private int pCardSize = 1;

		private Vector2 pSideScroll;

		private Vector2 pGridScroll;

		private float pScrollY;

		private Entry pHover;

		private Entry pHoverLatched;

		private Entry pFlash;

		private float pFlashUntil;

		private List<ClassData> classList = new List<ClassData>();

		private List<Entry> pFiltered = new List<Entry>();

		private string pFilterSig;

		private string pUserFilterSig;

		private GameObject pCanvasGo;

		private Canvas pCanvas;

		private RectTransform pCardRoot;

		private RectTransform pDim;

		private RectTransform pBlocker;

		private CardUI pPrefab;

		private Vector2 pCardNative = new Vector2(255f, 450f);

		private readonly Dictionary<int, CardUI> pAssigned = new Dictionary<int, CardUI>();

		private readonly List<CardUI> pAllCardUIs = new List<CardUI>();

		private readonly Stack<CardUI> pFree = new Stack<CardUI>();

		private readonly Dictionary<CardData, float> pRequestedAt = new Dictionary<CardData, float>();

		private string pAssignedSig;

		private int pCols;

		private int pVisFirst;

		private int pVisLast;

		private float pRowH;

		private float pCardK;

		private float pCardW;

		private float pCardH;

		private float pGridX0;

		private Rect pGridRect;

		private readonly Queue<string> pAddQueue = new Queue<string>();

		private bool pAddRunning;

		private Dictionary<string, int> pDeckCounts = new Dictionary<string, int>();

		private float pDeckCountsAt;

		private Dictionary<CardData, string> pCardText;

		private readonly List<float> pTileRowY = new List<float>();

		private string pTileSig;

		private bool pDeckDelete = true;

		private bool pDeckEdit;

		private string pDeckSig = "";

		private float pDeckSigAt;

		private Dictionary<string, Entry> pCardById;

		private GUIStyle sPanel;

		private GUIStyle sChip;

		private GUIStyle sChipOn;

		private GUIStyle sChipDanger;

		private GUIStyle sDeleteFrame;

		private GUIStyle sCellName;

		private GUIStyle sCellSub;

		private GUIStyle sHoverFrame;

		private GUIStyle sOwnedFrame;

		private GUIStyle sBadge;

		private GUIStyle sInfoTitle;

		private GUIStyle sInfo;

		private GUIStyle sTile;

		private GUIStyle sTileName;

		private GUIStyle sTileDesc;

		private static readonly CollectableRarity[] RarityValues;

		private static readonly string[] CostNames;

		private static readonly float[] RowsVisibleBySize;

		private const float TopH = 62f;

		private const float SideW = 300f;

		private const float Pad = 10f;

		private const float CardGap = 14f;

		private const float LabelH = 24f;

		private const float ScrollbarW = 18f;

		private const float TileW = 380f;

		private const float TileIcon = 84f;

		private const float TileGap = 10f;

		private ConfigEntry<KeyboardShortcut> toggleKey;

		private ConfigEntry<float> uiScale;

		private bool show;

		private Rect winRect = new Rect(30f, 60f, 760f, 900f);

		private int tab;

		private Vector2 scroll;

		private string goldInput = "9999";

		private string emberInput = "99";

		private string pyreMaxInput = "999";

		private string capacityInput = "20";

		private string status = "";

		private float statusUntil;

		private List<Entry> cardEntries;

		private List<Entry> relicEntries;

		private List<Entry> enhancerEntries;

		private string[] classNames = new string[1] { T("全部") };

		private string cachedLanguageProbe;

		private Font font;

		private bool stylesReady;

		private GUIStyle sWindow;

		private GUIStyle sLabel;

		private GUIStyle sLabelNW;

		private GUIStyle sSmall;

		private GUIStyle sButton;

		private GUIStyle sToggle;

		private GUIStyle sField;

		private GUIStyle sHeader;

		private GUIStyle sTab;

		private GUIStyle sTabOn;

		private GUIStyle sBox;

		private GUIStyle sBig;

		private static readonly BindingFlags AnyStatic;

		private static readonly FieldInfo SaveManagerField;

		private static readonly FieldInfo AllGameManagersField;

		private static readonly Regex TagRegex;

		private Runner runner;

		private static readonly CardType[] TypeFilterValues;

		private HashSet<CardData> logbookSet;

		private HashSet<CollectableRelicData> accessibleRelicSet;

		private bool TopBarMode
		{
			get
			{
				if (buttonInTopBar != null)
				{
					return buttonInTopBar.Value;
				}
				return true;
			}
		}

		private bool FloatButtonVisible
		{
			get
			{
				if (showButton != null && showButton.Value && !pickerOpen && (Object)(object)SM != (Object)null)
				{
					if (TopBarMode)
					{
						return (Object)(object)HudAnchor() != (Object)null;
					}
					return true;
				}
				return false;
			}
		}

		private static bool LocReady => GameLanguageOrNull() != null;

		private static bool IsZh => GameLanguageOrNull()?.StartsWith("Chinese", StringComparison.OrdinalIgnoreCase) ?? CultureInfo.CurrentUICulture.Name.StartsWith("zh", StringComparison.OrdinalIgnoreCase);

		private bool IsCardMode
		{
			get
			{
				if (pickerMode != PickerMode.Cards)
				{
					return pickerMode == PickerMode.Deck;
				}
				return true;
			}
		}

		private static string[] SortNames => new string[4]
		{
			T("默认"),
			T("费用"),
			T("名字"),
			T("稀有度")
		};

		private static string[] RarityNames => RarityValues.Select(RarityName).ToArray();

		private static string[] OwnedNames => new string[3]
		{
			T("全部"),
			T("已拥有"),
			T("未拥有")
		};

		private static string[] SizeNames => new string[3]
		{
			T("小"),
			T("中"),
			T("大")
		};

		private static string[] Tabs => new string[5]
		{
			T("常用"),
			T("加卡"),
			T("神器"),
			T("牌组"),
			T("强化石")
		};

		private static SaveManager SM
		{
			get
			{
				object? obj = SaveManagerField?.GetValue(null);
				return (SaveManager)((obj is SaveManager) ? obj : null);
			}
		}

		private static AllGameManagers AGM
		{
			get
			{
				object? obj = AllGameManagersField?.GetValue(null);
				return (AllGameManagers)((obj is AllGameManagers) ? obj : null);
			}
		}

		private static string[] TypeFilterNames => new string[1] { T("全部") }.Concat(TypeFilterValues.Select(TypeName)).ToArray();

		private void RunPendingEdit()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			if (pPreviewPending && pEditEntry != null && ArtReady((CardData)pEditEntry.data))
			{
				RefreshPreview();
			}
			Action action = pPendingEdit;
			pPendingEdit = null;
			if (action != null && pEditEntry != null)
			{
				action();
			}
		}

		private void OpenCardEdit(Entry e)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			if (e?.state != null)
			{
				pEditEntry = e;
				pEditScroll = Vector2.zero;
				pEditSearch = "";
				RefreshPreview();
			}
		}

		private void CloseCardEdit()
		{
			pEditEntry = null;
			if ((Object)(object)pPreviewUI != (Object)null)
			{
				((Component)pPreviewUI).gameObject.SetActive(false);
			}
			pAssignedSig = null;
		}

		private void EnsurePreviewRoot()
		{
			//IL_002b: 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_0051: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)pPreviewRoot != (Object)null))
			{
				pPreviewRoot = NewChild("Preview");
				pPreviewRoot.anchorMin = Vector2.zero;
				pPreviewRoot.anchorMax = Vector2.one;
				RectTransform obj = pPreviewRoot;
				Vector2 offsetMin = (pPreviewRoot.offsetMax = Vector2.zero);
				obj.offsetMin = offsetMin;
				((Component)pPreviewRoot).gameObject.layer = pCanvasGo.layer;
			}
		}

		private void RefreshPreview()
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Expected O, but got Unknown
			if (pEditEntry == null || (Object)(object)SM == (Object)null)
			{
				return;
			}
			EnsureCanvas();
			EnsurePreviewRoot();
			CardUI cardPrefab = GetCardPrefab();
			if ((Object)(object)cardPrefab == (Object)null)
			{
				return;
			}
			if ((Object)(object)pPreviewUI == (Object)null)
			{
				pPreviewUI = Object.Instantiate<CardUI>(cardPrefab, (Transform)(object)pPreviewRoot, false);
				((Object)pPreviewUI).name = "PickerPreviewCard";
			}
			CardData val = (CardData)pEditEntry.data;
			if (!ArtReady(val))
			{
				((Component)pPreviewUI).gameObject.SetActive(false);
				if (!pRequestedAt.ContainsKey(val))
				{
					pRequestedAt[val] = Time.realtimeSinceStartup;
					try
					{
						LoadingScreen.AddTask((LoadingTask)new LoadCardsForCompendium((IEnumerable<CardData>)new List<CardData> { val }, (DisplayStyle)0, (Action)null), true);
					}
					catch (Exception ex)
					{
						((BaseUnityPlugin)this).Logger.LogWarning((object)("preview art load failed: " + ex.Message));
					}
				}
				pPreviewPending = true;
				return;
			}
			pPreviewPending = false;
			((Component)pPreviewUI).gameObject.SetActive(true);
			try
			{
				pPreviewUI.SetCardVisibleAndInteractable(true, (HandUI)null);
				pPreviewUI.SetUIState((CardUIState)3);
				pPreviewUI.ApplyStateToUI(pEditEntry.state, (CardStatistics)null, (MonsterManager)null, (HeroManager)null, (RelicManager)null, SM, SM.GetMastery(pEditEntry.state), true, false, (List<CardUpgradeState>)null, (CardArtPool)null, (CardEdgeVfxPool)null);
			}
			catch (Exception ex2)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("preview render failed: " + ex2.Message));
			}
		}

		private EnhancerData EnhancerFor(string upgradeId)
		{
			if (pEnhancerByUpgrade == null)
			{
				pEnhancerByUpgrade = new Dictionary<string, EnhancerData>();
				foreach (EnhancerData allEnhancerDatum in SM.GetAllGameData().GetAllEnhancerData())
				{
					if ((Object)(object)allEnhancerDatum == (Object)null)
					{
						continue;
					}
					foreach (RelicEffectData item in ((RelicData)allEnhancerDatum).GetEffects() ?? new List<RelicEffectData>())
					{
						CardUpgradeData val = null;
						try
						{
							val = ((item != null) ? item.GetParamCardUpgradeData() : null);
						}
						catch
						{
						}
						if ((Object)(object)val != (Object)null && !pEnhancerByUpgrade.ContainsKey(((GameData)val).GetID()))
						{
							pEnhancerByUpgrade[((GameData)val).GetID()] = allEnhancerDatum;
						}
					}
				}
			}
			if (!pEnhancerByUpgrade.TryGetValue(upgradeId ?? "", out var value))
			{
				return null;
			}
			return value;
		}

		private static CardUpgradeData UpgradeDataOf(EnhancerData en)
		{
			foreach (RelicEffectData item in ((RelicData)en).GetEffects() ?? new List<RelicEffectData>())
			{
				try
				{
					CardUpgradeData val = ((item != null) ? item.GetParamCardUpgradeData() : null);
					if ((Object)(object)val != (Object)null)
					{
						return val;
					}
				}
				catch
				{
				}
			}
			return null;
		}

		private List<UpgradeRow> CurrentUpgrades(CardState cs)
		{
			List<UpgradeRow> list = new List<UpgradeRow>();
			List<CardUpgradeState> list2 = null;
			try
			{
				CardStateModifiers cardStateModifiers = cs.GetCardStateModifiers();
				list2 = ((cardStateModifiers != null) ? cardStateModifiers.GetCardUpgrades() : null);
			}
			catch
			{
			}
			if (list2 == null)
			{
				return list;
			}
			foreach (CardUpgradeState u in list2.ToList())
			{
				string upgradeId = Safe((Func<string>)u.GetCardUpgradeDataId);
				CardUpgradeData data = Safe2(() => u.GetSourceCardUpgradeData());
				EnhancerData val = EnhancerFor(upgradeId);
				string text = (((Object)(object)val != (Object)null) ? Clean(Safe((Func<string>)((RelicData)val).GetName)) : "");
				if (text.Length == 0 && (Object)(object)data != (Object)null)
				{
					text = Clean(Safe(() => LocalizationExtensions.Localize(data.GetUpgradeTitleKey(), (ILocalizationParameterContext)new CardEffectLocalizationContext((ILocalizationEffectPower)(object)data, (CharacterState)null, (CardState)null, (IRoomStateModifier)null, (CharacterStatusEffectAdjustments)null))));
				}
				if (text.Length == 0)
				{
					text = (((Object)(object)data != (Object)null) ? (T("(内部强化)") + ((Object)data).name) : T("(未知强化)"));
				}
				string text2 = (((Object)(object)val != (Object)null) ? Clean(Safe((Func<string>)((RelicData)val).GetDescription)) : "");
				if (text2.Length == 0 && (Object)(object)data != (Object)null)
				{
					text2 = Clean(Safe(() => LocalizationExtensions.Localize(data.GetUpgradeDescriptionKey(), (ILocalizationParameterContext)new CardEffectLocalizationContext((ILocalizationEffectPower)(object)data, (CharacterState)null, (CardState)null, (IRoomStateModifier)null, (CharacterStatusEffectAdjustments)null))));
				}
				Sprite icon = (((Object)(object)val != (Object)null) ? SafeIcon((RelicData)(object)val) : Safe2(delegate
				{
					CardUpgradeData obj2 = data;
					return (obj2 == null) ? null : obj2.GetUpgradeIcon();
				}));
				list.Add(new UpgradeRow
				{
					state = u,
					name = text,
					desc = text2,
					icon = icon
				});
			}
			return list;
		}

		private bool EnhancerFits(EnhancerData en, CardState cs)
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Invalid comparison between Unknown and I4
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			RelicEffectData val = null;
			foreach (RelicEffectData item in ((RelicData)en).GetEffects() ?? new List<RelicEffectData>())
			{
				try
				{
					if ((Object)(object)((item != null) ? item.GetParamCardUpgradeData() : null) != (Object)null)
					{
						val = item;
						break;
					}
				}
				catch
				{
				}
			}
			if (val == null)
			{
				return false;
			}
			CardUpgradeData paramCardUpgradeData = val.GetParamCardUpgradeData();
			try
			{
				if ((int)val.GetParamCardType() != 4 && cs.GetCardType() != val.GetParamCardType())
				{
					return false;
				}
				if (!val.GetParamCharacterSubtype().IsNone)
				{
					foreach (CardEffectState effectState in cs.GetEffectStates())
					{
						if (effectState.GetCardEffect() is CardEffectSpawnMonster && !effectState.GetParamCharacterData().GetSubtypes().Contains(val.GetParamCharacterSubtype()))
						{
							return false;
						}
					}
				}
				if (val.GetUseIntRange())
				{
					int costWithoutAnyModifications = cs.GetCostWithoutAnyModifications();
					if (costWithoutAnyModifications < val.GetParamMinInt() || costWithoutAnyModifications > val.GetParamMaxInt())
					{
						return false;
					}
				}
				RelicManager relicManager = AGM.GetRelicManager();
				List<CardUpgradeMaskData> list = new List<CardUpgradeMaskData>(paramCardUpgradeData.GetFilters() ?? new List<CardUpgradeMaskData>());
				if ((Object)(object)val.GetParamCardFilter() != (Object)null)
				{
					list.Add(val.GetParamCardFilter());
				}
				list.AddRange(DeckScreenDefaultUpgradeMasks());
				foreach (CardUpgradeMaskData item2 in list)
				{
					if ((Object)(object)item2 != (Object)null && !item2.FilterCard<CardState>(cs, relicManager))
					{
						return false;
					}
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("EnhancerFits " + ((Object)en).name + ": " + ex.Message));
			}
			return true;
		}

		private List<CardUpgradeMaskData> DeckScreenDefaultUpgradeMasks()
		{
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Invalid comparison between Unknown and I4
			if (pDefaultUpgradeMasks != null)
			{
				return pDefaultUpgradeMasks;
			}
			List<CardUpgradeMaskData> list = new List<CardUpgradeMaskData>();
			try
			{
				IScreen screen = AGM.GetScreenManager().GetScreen((ScreenName)3);
				DeckScreen obj = (DeckScreen)(object)((screen is DeckScreen) ? screen : null);
				if (typeof(DeckScreen).GetField("defaultFilters", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(obj) is IEnumerable enumerable)
				{
					foreach (object item in enumerable)
					{
						Type type = item.GetType();
						if (type.GetField("mode")?.GetValue(item) is Mode val && (int)val == 6 && type.GetField("masks")?.GetValue(item) is IEnumerable<CardUpgradeMaskData> collection)
						{
							list.AddRange(collection);
						}
					}
				}
				pDefaultUpgradeMasks = list;
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("default upgrade masks: " + ex.Message));
			}
			return list;
		}

		private void AfterCardChanged(string msg)
		{
			try
			{
				pEditEntry.state.RefreshCardBodyTextLocalization();
			}
			catch
			{
			}
			RefreshPreview();
			pAssignedSig = null;
			if (!InBattle())
			{
				Run("Command_Save");
			}
			Toast(msg);
		}

		private bool RemoveCardUpgrade(UpgradeRow row)
		{
			CardState state = pEditEntry.state;
			bool flag = false;
			try
			{
				flag = state.RemoveUpgrade(row.state, state.GetCardStateModifiers(), (string)null);
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)ex);
			}
			AfterCardChanged(flag ? (T("已去掉:") + row.name) : (T("去掉失败:") + row.name));
			return flag;
		}

		private bool AddCardUpgrade(EnhancerData en)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			CardState state = pEditEntry.state;
			CardUpgradeData val = UpgradeDataOf(en);
			if ((Object)(object)val == (Object)null)
			{
				Toast(T("这个强化石没有可用的效果"));
				return false;
			}
			try
			{
				CardUpgradeState val2 = new CardUpgradeState();
				val2.Setup(val, false, false);
				state.ApplyPermanentUpgrade(val2, SM, true, (string)null);
				AfterCardChanged(T("已加上:") + Clean(Safe((Func<string>)((RelicData)en).GetName)));
				return true;
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)ex);
				Toast(T("加强化失败:") + ex.Message);
				return false;
			}
		}

		private int CurrentUpgradeCount()
		{
			if (pEditEntry?.state != null)
			{
				return Safe2(delegate
				{
					CardStateModifiers cardStateModifiers = pEditEntry.state.GetCardStateModifiers();
					return (cardStateModifiers == null) ? null : cardStateModifiers.GetCardUpgrades();
				})?.Count ?? (-1);
			}
			return -1;
		}

		private void DrawCardEdit(Rect grid)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: 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_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: 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_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: 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_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0619: Unknown result type (might be due to invalid IL or missing references)
			//IL_0629: Expected O, but got Unknown
			//IL_0699: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a3: Expected O, but got Unknown
			CardState cs = pEditEntry.state;
			float num = Mathf.Min(((Rect)(ref grid)).width * 0.32f, 460f);
			GUI.Box(new Rect(((Rect)(ref grid)).x + num, ((Rect)(ref grid)).y - 10f, ((Rect)(ref grid)).width - num, ((Rect)(ref grid)).height + 10f), GUIContent.none, sPanel);
			float num2 = Mathf.Min((num - 40f) / pCardNative.x, (((Rect)(ref grid)).height - 120f) / (pCardNative.y * 1.08f));
			if ((Object)(object)pPreviewUI != (Object)null)
			{
				RectTransform val = (RectTransform)((Component)pPreviewUI).transform;
				Vector2 val2 = default(Vector2);
				((Vector2)(ref val2))..ctor(0f, 1f);
				val.anchorMax = val2;
				val.anchorMin = val2;
				val.pivot = new Vector2(0.5f, 0.5f);
				val.anchoredPosition = new Vector2(((Rect)(ref grid)).x + num / 2f, 0f - (((Rect)(ref grid)).y + (((Rect)(ref grid)).height - 60f) / 2f));
				((Transform)val).localScale = new Vector3(num2, num2, 1f);
			}
			if (pPreviewPending)
			{
				GUI.Label(new Rect(((Rect)(ref grid)).x, ((Rect)(ref grid)).y + ((Rect)(ref grid)).height / 2f - 20f, num, 40f), T("卡图加载中…"), sCellName);
			}
			if (GUI.Button(new Rect(((Rect)(ref grid)).x + 20f, ((Rect)(ref grid)).yMax - 52f, num - 40f, 40f), T("← 返回牌组"), sBig))
			{
				CloseCardEdit();
				return;
			}
			Rect val3 = default(Rect);
			((Rect)(ref val3))..ctor(((Rect)(ref grid)).x + num + 10f, ((Rect)(ref grid)).y, ((Rect)(ref grid)).width - num - 20f, ((Rect)(ref grid)).height - 4f);
			GUILayout.BeginArea(val3);
			try
			{
				GUILayout.Label(T("改卡:") + pEditEntry.name, sInfoTitle, Array.Empty<GUILayoutOption>());
				pEditScroll = GUILayout.BeginScrollView(pEditScroll, Array.Empty<GUILayoutOption>());
				try
				{
					GUILayout.Label(T("这张卡现在的强化"), sHeader, Array.Empty<GUILayoutOption>());
					List<UpgradeRow> list = CurrentUpgrades(cs);
					if (list.Count == 0)
					{
						GUILayout.Label(T("(没有强化)"), sSmall, Array.Empty<GUILayoutOption>());
					}
					foreach (UpgradeRow item in list)
					{
						GUILayout.BeginHorizontal(sBox, Array.Empty<GUILayoutOption>());
						DrawSprite(GUILayoutUtility.GetRect(56f, 56f, (GUILayoutOption[])(object)new GUILayoutOption[2]
						{
							GUILayout.Width(56f),
							GUILayout.Height(56f)
						}), item.icon);
						GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
						GUILayout.Label("<b>" + item.name + "</b>", sLabel, Array.Empty<GUILayoutOption>());
						if (item.desc.Length > 0)
						{
							GUILayout.Label(item.desc, sSmall, Array.Empty<GUILayoutOption>());
						}
						GUILayout.EndVertical();
						if (GUILayout.Button(T("去掉"), sChipDanger, (GUILayoutOption[])(object)new GUILayoutOption[2]
						{
							GUILayout.Width(80f),
							GUILayout.Height(40f)
						}))
						{
							UpgradeRow r = item;
							pPendingEdit = delegate
							{
								RemoveCardUpgrade(r);
							};
						}
						GUILayout.EndHorizontal();
					}
					GUILayout.Space(12f);
					GUILayout.Label(T("加一个强化石(只列出能用在这张卡上的)"), sHeader, Array.Empty<GUILayoutOption>());
					pEditIgnoreRules = GUILayout.Toggle(pEditIgnoreRules, T(" 显示全部强化石(无视游戏限制)"), sToggle, Array.Empty<GUILayoutOption>());
					GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
					GUILayout.Label(T("搜索"), sLabelNW, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
					pEditSearch = GUILayout.TextField(pEditSearch, 30, sField, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(260f) });
					GUILayout.EndHorizontal();
					string q = (pEditSearch ?? "").Trim().ToLowerInvariant();
					List<Entry> list2 = (enhancerEntries ?? new List<Entry>()).Where((Entry en) => (Object)(object)UpgradeDataOf((EnhancerData)en.data) != (Object)null && (pEditIgnoreRules || EnhancerFits((EnhancerData)en.data, cs)) && (q.Length == 0 || en.searchKey.Contains(q))).ToList();
					if (list2.Count == 0)
					{
						GUILayout.Label(T("(没有合适的强化石)"), sSmall, Array.Empty<GUILayoutOption>());
					}
					int num3 = Mathf.Max(1, Mathf.FloorToInt((((Rect)(ref val3)).width - 30f) / 330f));
					for (int num4 = 0; num4 < list2.Count; num4 += num3)
					{
						GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
						foreach (Entry item2 in list2.Skip(num4).Take(num3))
						{
							GUILayout.BeginHorizontal(sBox, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width((((Rect)(ref val3)).width - 30f) / (float)num3 - 6f) });
							DrawSprite(GUILayoutUtility.GetRect(44f, 44f, (GUILayoutOption[])(object)new GUILayoutOption[2]
							{
								GUILayout.Width(44f),
								GUILayout.Height(44f)
							}), item2.icon);
							GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
							GUILayout.Label("<b>" + item2.name + "</b>", sLabel, Array.Empty<GUILayoutOption>());
							GUILayout.Label(item2.desc ?? "", sSmall, Array.Empty<GUILayoutOption>());
							if (pEditIgnoreRules && !EnhancerFits((EnhancerData)item2.data, cs))
							{
								GUILayout.Label(T("<color=#ff8a7a>游戏通常不允许用在这张卡上</color>"), sSmall, Array.Empty<GUILayoutOption>());
							}
							GUILayout.EndVertical();
							if (GUILayout.Button(T("加上"), sChipOn, (GUILayoutOption[])(object)new GUILayoutOption[2]
							{
								GUILayout.Width(60f),
								GUILayout.Height(36f)
							}))
							{
								EnhancerData d = (EnhancerData)item2.data;
								pPendingEdit = delegate
								{
									AddCardUpgrade(d);
								};
							}
							GUILayout.EndHorizontal();
						}
						GUILayout.EndHorizontal();
					}
				}
				finally
				{
					GUILayout.EndScrollView();
				}
			}
			finally
			{
				GUILayout.EndArea();
			}
		}

		private static IEnumerator WaitReal(float seconds)
		{
			float until = Time.realtimeSinceStartup + seconds;
			while (Time.realtimeSinceStartup < until)
			{
				yield return null;
			}
		}

		private IEnumerator WaitFor(Func<bool> cond, float timeout, string what)
		{
			float until = Time.realtimeSinceStartup + timeout;
			while (Time.realtimeSinceStartup < until)
			{
				bool flag = false;
				try
				{
					flag = cond();
				}
				catch
				{
				}
				if (flag)
				{
					yield break;
				}
				yield return null;
			}
			((BaseUnityPlugin)this).Logger.LogWarning((object)("timeout waiting for " + what));
		}

		private static Rect ScreenRectOf(RectTransform rt)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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_0084: 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_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)rt == (Object)null)
			{
				return Rect.zero;
			}
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			rt.GetWorldCorners(array);
			Canvas componentInParent = ((Component)rt).GetComponentInParent<Canvas>();
			Canvas val = ((componentInParent != null) ? componentInParent.rootCanvas : null);
			Camera val2 = (((Object)(object)val != (Object)null && (int)val.renderMode != 0) ? val.worldCamera : null);
			float num = float.MaxValue;
			float num2 = float.MaxValue;
			float num3 = float.MinValue;
			float num4 = float.MinValue;
			Vector3[] array2 = array;
			foreach (Vector3 val3 in array2)
			{
				Vector2 val4 = RectTransformUtility.WorldToScreenPoint(val2, val3);
				num = Mathf.Min(num, val4.x);
				num3 = Mathf.Max(num3, val4.x);
				num2 = Mathf.Min(num2, val4.y);
				num4 = Mathf.Max(num4, val4.y);
			}
			return new Rect(num, (float)Screen.height - num4, num3 - num, num4 - num2);
		}

		private static Rect VisibleRectOf(GameObject go)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			Rect result = Rect.zero;
			bool flag = false;
			Graphic[] componentsInChildren = go.GetComponentsInChildren<Graphic>(false);
			foreach (Graphic val in componentsInChildren)
			{
				if (!((Behaviour)val).enabled || val.color.a < 0.05f || val.canvasRenderer.GetAlpha() < 0.05f)
				{
					continue;
				}
				Rect val2 = ScreenRectOf(val.rectTransform);
				if (!(((Rect)(ref val2)).width < 2f) && !(((Rect)(ref val2)).height < 2f))
				{
					if (!flag)
					{
						result = val2;
						flag = true;
					}
					else
					{
						result = Rect.MinMaxRect(Mathf.Min(((Rect)(ref result)).xMin, ((Rect)(ref val2)).xMin), Mathf.Min(((Rect)(ref result)).yMin, ((Rect)(ref val2)).yMin), Mathf.Max(((Rect)(ref result)).xMax, ((Rect)(ref val2)).xMax), Mathf.Max(((Rect)(ref result)).yMax, ((Rect)(ref val2)).yMax));
					}
				}
			}
			return result;
		}

		private static Texture2D MakeFramedTex(Color fill, Color rim)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			//IL_0039: 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)
			Texture2D val = new Texture2D(12, 12)
			{
				hideFlags = (HideFlags)61,
				filterMode = (FilterMode)0
			};
			for (int i = 0; i < 12; i++)
			{
				for (int j = 0; j < 12; j++)
				{
					val.SetPixel(j, i, (j < 2 || i < 2 || j > 9 || i > 9) ? rim : fill);
				}
			}
			val.Apply();
			return val;
		}

		private void BindButtonConfig()
		{
			showButton = ((BaseUnityPlugin)this).Config.Bind<bool>("Button", "ShowButton", true, "显示打开面板的按钮 / Show the button that opens the panel");
			buttonX = ((BaseUnityPlugin)this).Config.Bind<float>("Button", "PositionX", 0.004f, "自由位置模式下按钮的横向位置 0~1 / Button X (0~1) when InTopBar = false");
			buttonY = ((BaseUnityPlugin)this).Config.Bind<float>("Button", "PositionY", 0.4f, "自由位置模式下按钮的纵向位置 0~1 / Button Y (0~1) when InTopBar = false");
			buttonInTopBar = ((BaseUnityPlugin)this).Config.Bind<bool>("Button", "InTopBar", true, "true = 按钮在顶部状态栏(神器右边、氏族图标左边),false = 自由位置可拖动 / true = button in the top bar (between artifacts and clan icons), false = free draggable position");
		}

		private RectTransform HudAnchor()
		{
			if ((Object)(object)hudClassesUI == (Object)null && Time.realtimeSinceStartup > hudLookupAt)
			{
				hudLookupAt = Time.realtimeSinceStartup + 1f;
				try
				{
					AllGameManagers aGM = AGM;
					object obj;
					if (aGM == null)
					{
						obj = null;
					}
					else
					{
						ScreenManager screenManager = aGM.GetScreenManager();
						obj = ((screenManager != null) ? screenManager.GetScreen((ScreenName)14) : null);
					}
					IScreen val = (IScreen)obj;
					object? obj2 = ((object)val)?.GetType().GetField("classesUI", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(val);
					Component val2 = (Component)((obj2 is Component) ? obj2 : null);
					hudClassesUI = (RectTransform)(((Object)(object)val2 != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null);
				}
				catch
				{
					hudClassesUI = null;
				}
			}
			if (!((Object)(object)hudClassesUI != (Object)null) || !((Component)hudClassesUI).gameObject.activeInHierarchy)
			{
				return null;
			}
			return hudClassesUI;
		}

		private Rect FloatButtonRect(float s)
		{
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			if (TopBarMode)
			{
				RectTransform val = HudAnchor();
				if ((Object)(object)val != (Object)null)
				{
					Rect val2 = ScreenRectOf(val);
					float num = Mathf.Clamp(((Rect)(ref val2)).height / s - 18f, 36f, 60f);
					float num2 = num;
					return new Rect(((Rect)(ref val2)).x / s - num2 - 8f, ((Rect)(ref val2)).y / s + (((Rect)(ref val2)).height / s - num) / 2f, num2, num);
				}
			}
			float num3 = (float)Screen.width / s;
			float num4 = (float)Screen.height / s;
			float num5 = Mathf.Clamp(buttonX.Value * num3, 0f, num3 - 64f);
			float num6 = Mathf.Clamp(buttonY.Value * num4, 0f, num4 - 64f);
			return new Rect(num5, num6, 64f, 64f);
		}

		private void EnsureButtonBlocker()
		{
			//IL_0050: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)pBtnBlocker != (Object)null))
			{
				pBtnBlocker = NewChild("ButtonBlocker", typeof(Image));
				RectTransform obj = pBtnBlocker;
				RectTransform obj2 = pBtnBlocker;
				Vector2 val = default(Vector2);
				((Vector2)(ref val))..ctor(0f, 1f);
				obj2.anchorMax = val;
				obj.anchorMin = val;
				pBtnBlocker.pivot = new Vector2(0f, 1f);
				Image component = ((Component)pBtnBlocker).GetComponent<Image>();
				((Graphic)component).color = new Color(0f, 0f, 0f, 0.004f);
				((Graphic)component).raycastTarget = true;
			}
		}

		private void SyncButtonBlocker(float s, int layer)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			EnsureButtonBlocker();
			((Component)pBtnBlocker).gameObject.layer = layer;
			bool floatButtonVisible = FloatButtonVisible;
			((Component)pBtnBlocker).gameObject.SetActive(floatButtonVisible);
			if (floatButtonVisible)
			{
				Rect val = FloatButtonRect(s);
				pBtnBlocker.anchoredPosition = new Vector2(((Rect)(ref val)).x, 0f - ((Rect)(ref val)).y);
				pBtnBlocker.sizeDelta = new Vector2(((Rect)(ref val)).width, ((Rect)(ref val)).height);
			}
		}

		private void HandleButtonToggle()
		{
			if (btnToggleRequested)
			{
				btnToggleRequested = false;
				ToggleFromButton();
			}
		}

		private void ToggleFromButton()
		{
			if (pickerOpen)
			{
				ClosePicker();
				show = false;
			}
			else
			{
				show = !show;
			}
		}

		private void DrawFloatButton(float s)
		{
			//IL_052e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_004b: Expected O, but got Unknown
			//IL_0050: Expected O, but got Unknown
			//IL_006f: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Expected O, but got Unknown
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Expected O, but got Unknown
			//IL_01b0: Expected O, but got Unknown
			//IL_01cf: 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_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Expected O, but got Unknown
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Expected I4, but got Unknown
			//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03da: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: 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_03f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0465: Unknown result type (might be due to invalid IL or missing references)
			//IL_0456: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d6: Expected O, but got Unknown
			//IL_04de: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_050c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0513: Unknown result type (might be due to invalid IL or missing references)
			//IL_051a: Unknown result type (might be due to invalid IL or missing references)
			if (!FloatButtonVisible)
			{
				return;
			}
			if (sFloatBtn == null)
			{
				sFloatBtn = new GUIStyle
				{
					font = font,
					fontSize = 18,
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)4,
					border = new RectOffset(3, 3, 3, 3)
				};
				sFloatBtn.normal.background = MakeFramedTex(new Color(0.13f, 0.11f, 0.1f, 0.96f), new Color(0.86f, 0.66f, 0.3f, 1f));
				sFloatBtn.hover.background = MakeFramedTex(new Color(0.32f, 0.22f, 0.1f, 0.98f), new Color(1f, 0.82f, 0.45f, 1f));
				sFloatBtn.normal.textColor = new Color(1f, 0.84f, 0.5f);
				sFloatBtn.hover.textColor = Color.white;
				sFloatBtnOn = new GUIStyle(sFloatBtn);
				GUIStyleState normal = sFloatBtnOn.normal;
				Texture2D background = (sFloatBtnOn.hover.background = MakeFramedTex(new Color(0.45f, 0.3f, 0.1f, 0.98f), new Color(1f, 0.9f, 0.6f, 1f)));
				normal.background = background;
				sBtnTip = new GUIStyle(sSmall)
				{
					alignment = (TextAnchor)4,
					wordWrap = false,
					padding = new RectOffset(8, 8, 4, 4)
				};
				sBtnTip.normal.background = MakeFramedTex(new Color(0.08f, 0.07f, 0.09f, 0.96f), new Color(0.86f, 0.66f, 0.3f, 1f));
				sBtnTip.border = new RectOffset(3, 3, 3, 3);
				sBtnTip.normal.textColor = new Color(1f, 0.9f, 0.7f);
			}
			Texture2D val2 = ButtonIcon();
			Matrix4x4 matrix = GUI.matrix;
			GUI.matrix = Matrix4x4.Scale(new Vector3(s, s, 1f));
			try
			{
				Rect val3 = FloatButtonRect(s);
				Event current = Event.current;
				float num = (float)Screen.width / s;
				float num2 = (float)Screen.height / s;
				EventType type = current.type;
				switch ((int)type)
				{
				case 0:
					if (current.button == 0 && ((Rect)(ref val3)).Contains(current.mousePosition))
					{
						btnDragging = true;
						btnMoved = false;
						btnDragStartMouse = current.mousePosition;
						btnDragStartPos = new Vector2(((Rect)(ref val3)).x, ((Rect)(ref val3)).y);
						current.Use();
					}
					break;
				case 3:
					if (btnDragging)
					{
						Vector2 val4 = current.mousePosition - btnDragStartMouse;
						if (((Vector2)(ref val4)).magnitude > 4f && !TopBarMode)
						{
							btnMoved = true;
						}
						if (btnMoved)
						{
							buttonX.Value = Mathf.Clamp01((btnDragStartPos.x + val4.x) / num);
							buttonY.Value = Mathf.Clamp01((btnDragStartPos.y + val4.y) / num2);
						}
						current.Use();
					}
					break;
				case 1:
					if (btnDragging)
					{
						btnDragging = false;
						if (!btnMoved)
						{
							btnToggleRequested = true;
						}
						current.Use();
					}
					break;
				}
				bool flag = ((Rect)(ref val3)).Contains(current.mousePosition) || btnForceHover;
				if (show)
				{
					GUI.Box(val3, GUIContent.none, sFloatBtnOn);
				}
				else if (flag || !TopBarMode)
				{
					GUI.Box(val3, GUIContent.none, sFloatBtn);
				}
				if ((Object)(object)val2 != (Object)null)
				{
					float num3 = ((Rect)(ref val3)).height * 0.12f;
					GUI.DrawTexture(new Rect(((Rect)(ref val3)).x + num3, ((Rect)(ref val3)).y + num3, ((Rect)(ref val3)).width - 2f * num3, ((Rect)(ref val3)).height - 2f * num3), (Texture)(object)val2, (ScaleMode)2, true);
				}
				else
				{
					GUI.Box(val3, show ? T("关闭") : T("作弊"), sFloatBtn);
				}
				if (flag)
				{
					GUIContent val5 = new GUIContent(T($"作弊面板({toggleKey.Value})", $"Cheat panel ({toggleKey.Value})"));
					Vector2 val6 = sBtnTip.CalcSize(val5);
					GUI.Box(new Rect(((Rect)(ref val3)).center.x - val6.x / 2f, ((Rect)(ref val3)).yMax + 6f, val6.x, val6.y), val5, sBtnTip);
				}
			}
			finally
			{
				GUI.matrix = matrix;
			}
		}

		private Texture2D ButtonIcon()
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			if (buttonIconTried)
			{
				return buttonIcon;
			}
			buttonIconTried = true;
			try
			{
				using Stream stream = typeof(Plugin).Assembly.GetManifestResourceStream("MT2CheatGUI.button_icon.png");
				if (stream == null)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"button icon resource missing");
					return null;
				}
				byte[] array = new byte[stream.Length];
				stream.Read(array, 0, array.Length);
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false)
				{
					hideFlags = (HideFlags)61,
					filterMode = (FilterMode)1
				};
				if (ImageConversion.LoadImage(val, array))
				{
					buttonIcon = val;
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("button icon load failed: " + ex.Message));
			}
			return buttonIcon;
		}

		private static string GameLanguageOrNull()
		{
			try
			{
				string text = I2CurrentLanguageField?.GetValue(null) as string;
				return string.IsNullOrEmpty(text) ? null : text;
			}
			catch
			{
				return null;
			}
		}

		private static string T(string zh)
		{
			if (!IsZh)
			{
				if (!En.TryGetValue(zh, out var value))
				{
					return zh;
				}
				return value;
			}
			return zh;
		}

		private static string T(string zh, string en)
		{
			if (!IsZh)
			{
				return en;
			}
			return zh;
		}

		private static string GameTerm(string key, string fallbackZh)
		{
			try
			{
				if (LocReady && LocalizationExtensions.HasTranslation(key))
				{
					string text = LocalizationExtensions.Localize(key, (ILocalizationParameterContext)null);
					if (!string.IsNullOrWhiteSpace(text) && !text.Contains(">>"))
					{
						return text;
					}
				}
			}
			catch
			{
			}
			return T(fallbackZh);
		}

		private void BuildPickerStyles()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: 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_00b1: 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_00c0: Expected O, but got Unknown
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Expected O, but got Unknown
			//IL_00d4: Expected O, but got Unknown
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Expected O, but got Unknown
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: 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_0162: 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_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Expected O, but got Unknown
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Expected O, but got Unknown
			//IL_01d7: 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_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Expected O, but got Unknown
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Expected O, but got Unknown
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Expected O, but got Unknown
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Expected O, but got Unknown
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_0327: 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_0334: Unknown result type (might be due to invalid IL or missing references)
			//IL_033b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0347: Expected O, but got Unknown
			//IL_0361: Unknown result type (might be due to invalid IL or missing references)
			//IL_038a: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b2: Expected O, but got Unknown
			//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03be: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cb: Expected O, but got Unknown
			//IL_03cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d6: Expected O, but got Unknown
			//IL_03f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_040b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0410: Unknown result type (might be due to invalid IL or missing references)
			//IL_0418: Unknown result type (might be due to invalid IL or missing references)
			//IL_041f: Unknown result type (might be due to invalid IL or missing references)
			//IL_042b: Expected O, but got Unknown
			//IL_0445: Unknown result type (might be due to invalid IL or missing references)
			//IL_0456: Unknown result type (might be due to invalid IL or missing references)
			//IL_045b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0463: Unknown result type (might be due to invalid IL or missing references)
			//IL_046f: Expected O, but got Unknown
			//IL_0489: Unknown result type (might be due to invalid IL or missing references)
			sPanel = new GUIStyle(GUI.skin.box);
			sPanel.normal.background = MakeTex(new Color(0.07f, 0.07f, 0.1f, 1f));
			sPanel.normal.textColor = new Color(0.8f, 0.8f, 0.85f);
			sPanel.font = font;
			sPanel.fontSize = 14;
			sPanel.alignment = (TextAnchor)4;
			sPanel.wordWrap = true;
			sChip = new GUIStyle(sButton)
			{
				fontSize = 14,
				margin = new RectOffset(2, 2, 2, 2),
				padding = new RectOffset(4, 4, 3, 3)
			};
			sChipOn = new GUIStyle(sChip)
			{
				fontStyle = (FontStyle)1
			};
			GUIStyleState normal = sChipOn.normal;
			GUIStyleState hover = sChipOn.hover;
			Texture2D val = (sChipOn.active.background = MakeTex(new Color(0.75f, 0.48f, 0.15f, 1f)));
			Texture2D background = (hover.background = val);
			normal.background = background;
			GUIStyleState normal2 = sChipOn.normal;
			Color textColor = (sChipOn.hover.textColor = Color.white);
			normal2.textColor = textColor;
			sCellName = new GUIStyle(sLabel)
			{
				fontSize = 14,
				alignment = (TextAnchor)1,
				wordWrap = true
			};
			sCellName.normal.textColor = Color.white;
			sCellSub = new GUIStyle(sCellName)
			{
				fontSize = 13
			};
			sCellSub.normal.textColor = new Color(0.62f, 0.9f, 0.62f);
			sChipDanger = new GUIStyle(sChip)
			{
				fontStyle = (FontStyle)1
			};
			GUIStyleState normal3 = sChipDanger.normal;
			GUIStyleState hover2 = sChipDanger.hover;
			val = (sChipDanger.active.background = MakeTex(new Color(0.75f, 0.18f, 0.15f, 1f)));
			background = (hover2.background = val);
			normal3.background = background;
			GUIStyleState normal4 = sChipDanger.normal;
			textColor = (sChipDanger.hover.textColor = Color.white);
			normal4.textColor = textColor;
			sDeleteFrame = new GUIStyle();
			sDeleteFrame.normal.background = MakeTex(new Color(1f, 0.2f, 0.15f, 0.28f));
			sHoverFrame = new GUIStyle();
			sHoverFrame.normal.background = MakeTex(new Color(1f, 0.85f, 0.4f, 0.16f));
			sOwnedFrame = new GUIStyle();
			sOwnedFrame.normal.background = MakeTex(new Color(0.3f, 0.9f, 0.4f, 0.16f));
			sBadge = new GUIStyle(sLabel)
			{
				fontSize = 22,
				fontStyle = (FontStyle)1,
				alignment = (TextAnchor)4
			};
			sBadge.normal.textColor = new Color(0.55f, 1f, 0.55f);
			sBadge.normal.background = MakeTex(new Color(0f, 0f, 0f, 0.7f));
			sInfoTitle = new GUIStyle(sHeader)
			{
				fontSize = 17
			};
			sInfo = new GUIStyle(sLabel)
			{
				fontSize = 14
			};
			sTile = new GUIStyle();
			sTile.normal.background = MakeTex(new Color(1f, 1f, 1f, 0.06f));
			sTileName = new GUIStyle(sLabel)
			{
				fontSize = 16,
				fontStyle = (FontStyle)1,
				wordWrap = true
			};
			sTileName.normal.textColor = new Color(1f, 0.86f, 0.55f);
			sTileDesc = new GUIStyle(sLabel)
			{
				fontSize = 14,
				wordWrap = true
			};
			sTileDesc.normal.textColor = new Color(0.88f, 0.88f, 0.92f);
		}

		private void OpenPicker(PickerMode mode)
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			if (!InRun())
			{
				Toast(T("要先开始或继续一局游戏才能用"));
				return;
			}
			EnsureData();
			if (pickerMode != mode)
			{
				fClan.Clear();
				fType.Clear();
				fRarity.Clear();
				fCost.Clear();
				fOwned = 0;
				pSearch = "";
			}
			pickerMode = mode;
			pickerOpen = true;
			pScrollY = 0f;
			pGridScroll = Vector2.zero;
			pFilterSig = null;
			pTileSig = null;
		}

		private void ClosePicker()
		{
			pickerOpen = false;
			if (pEditEntry != null)
			{
				CloseCardEdit();
			}
			DestroyCardUIs();
			if ((Object)(object)pCardRoot != (Object)null)
			{
				((Component)pCardRoot).gameObject.SetActive(false);
			}
			if ((Object)(object)pDim != (Object)null)
			{
				((Component)pDim).gameObject.SetActive(false);
			}
		}

		private void DestroyCardUIs()
		{
			foreach (CardUI pAllCardUI in pAllCardUIs)
			{
				if ((Object)(object)pAllCardUI != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)pAllCardUI).gameObject);
				}
			}
			pAllCardUIs.Clear();
			pAssigned.Clear();
			pFree.Clear();
			pAssignedSig = null;
		}

		private RectTransform NewChild(string name, params Type[] comps)
		{
			//IL_001f: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) }.Concat(comps).ToArray());
			val.transform.SetParent(pCanvasGo.transform, false);
			return (RectTransform)val.transform;
		}

		private void EnsureCanvas()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: 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_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)pCanvasGo != (Object)null))
			{
				pCanvasGo = new GameObject("MT2CheatGUI_Canvas");
				Object.DontDestroyOnLoad((Object)(object)pCanvasGo);
				pCanvas = pCanvasGo.AddComponent<Canvas>();
				pCanvas.renderMode = (RenderMode)0;
				pCanvas.sortingOrder = 32000;
				pCanvasGo.AddComponent<GraphicRaycaster>();
				pDim = NewChild("Dim", typeof(Image));
				pDim.anchorMin = Vector2.zero;
				pDim.anchorMax = Vector2.one;
				Vector2 val = (pDim.offsetMin = (pDim.offsetMax = Vector2.zero));
				Image component = ((Component)pDim).GetComponent<Image>();
				((Graphic)component).color = new Color(0.035f, 0.035f, 0.055f, 1f);
				((Graphic)component).raycastTarget = true;
				pCardRoot = NewChild("Cards", typeof(CanvasGroup));
				pCardRoot.anchorMin = Vector2.zero;
				pCardRoot.anchorMax = Vector2.one;
				val = (pCardRoot.offsetMin = (pCardRoot.offsetMax = Vector2.zero));
				CanvasGroup component2 = ((Component)pCardRoot).GetComponent<CanvasGroup>();
				component2.interactable = false;
				component2.blocksRaycasts = false;
				pBlocker = NewChild("PanelBlocker", typeof(Image));
				RectTransform obj = pBlocker;
				RectTransform obj2 = pBlocker;
				((Vector2)(ref val))..ctor(0f, 1f);
				obj2.anchorMax = val;
				obj.anchorMin = val;
				pBlocker.pivot = new Vector2(0f, 1f);
				Image component3 = ((Component)pBlocker).GetComponent<Image>();
				((Graphic)component3).color = new Color(0f, 0f, 0f, 0.004f);
				((Graphic)component3).raycastTarget = true;
			}
		}

		private void SyncCanvas(float s, bool panelVisible)
		{
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			EnsureCanvas();
			pCanvas.scaleFactor = s;
			int num = GuiLayer();
			if (pCanvasGo.layer != num)
			{
				pCanvasGo.layer = num;
				((Component)pDim).gameObject.layer = num;
				((Component)pBlocker).gameObject.layer = num;
				((Component)pCardRoot).gameObject.layer = num;
			}
			((Component)pDim).gameObject.SetActive(pickerOpen);
			((Component)pCardRoot).gameObject.SetActive(pickerOpen && IsCardMode && pEditEntry == null);
			if ((Object)(object)pPreviewRoot != (Object)null)
			{
				((Component)pPreviewRoot).gameObject.SetActive(pickerOpen && pEditEntry != null);
			}
			SyncButtonBlocker(s, num);
			((Component)pBlocker).gameObject.SetActive(panelVisible && !pickerOpen);
			if (panelVisible)
			{
				pBlocker.anchoredPosition = new Vector2(((Rect)(ref winRect)).x, 0f - ((Rect)(ref winRect)).y);
				pBlocker.sizeDelta = new Vector2(((Rect)(ref winRect)).width, ((Rect)(ref winRect)).height);
			}
		}

		private static int GuiLayer()
		{
			//IL_0002: 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)
			int num = 0;
			try
			{
				LayerMask currentGuiLayers = CoreInput.currentGuiLayers;
				num = ((LayerMask)(ref currentGuiLayers)).value;
			}
			catch
			{
			}
			int num2 = LayerMask.NameToLayer("UI");
			if (num2 >= 0 && (num & (1 << num2)) != 0)
			{
				return num2;
			}
			for (int i = 0; i < 32; i++)
			{
				if ((num & (1 << i)) != 0)
				{
					return i;
				}
			}
			if (num2 < 0)
			{
				return 5;
			}
			return num2;
		}

		private CardUI GetCardPrefab()
		{
			if ((Object)(object)pPrefab != (Object)null)
			{
				return pPrefab;
			}
			try
			{
				IScreen screen = AGM.GetScreenManager().GetScreen((ScreenName)3);
				DeckScreen val = (DeckScreen)(object)((screen is DeckScreen) ? screen : null);
				if ((Object)(object)val != (Object)null)
				{
					ref CardUI reference = ref pPrefab;
					object? obj = typeof(DeckScreen).GetField("cardPrefab", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(val);
					reference = (CardUI)((obj is CardUI) ? obj : null);
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("card prefab via DeckScreen failed: " + ex.Message));
			}
			if ((Object)(object)pPrefab == (Object)null)
			{
				pPrefab = ((IEnumerable<CardUI>)Resources.FindObjectsOfTypeAll<CardUI>()).FirstOrDefault((Func<CardUI, bool>)delegate(CardUI c)
				{
					//IL_0006: Unknown result type (might be due to invalid IL or missing references)
					//IL_000b: Unknown result type (might be due to invalid IL or missing references)
					Scene scene = ((Component)c).gameObject.scene;
					return !((Scene)(ref scene)).IsValid();
				});
			}
			return pPrefab;
		}

		private static bool ArtReady(CardData cd)
		{
			try
			{
				GameObject val = default(GameObject);
				return cd.GetCardArtPrefabVariant(ref val);
			}
			catch
			{
				return false;
			}
		}

		private bool ArtFailed(CardData cd)
		{
			if (pRequestedAt.TryGetValue(cd, out var value) && Time.realtimeSinceStartup - value > 15f)
			{
				return !ArtReady(cd);
			}
			return false;
		}

		private void UpdateCardGrid()
		{
			//IL_0327: Unknown result type (might be due to invalid IL or missing references)
			//IL_032e: Expected O, but got Unknown
			//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0388: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Expected O, but got Unknown
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Expected O, but got Unknown
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Expected O, but got Unknown
			if (!pickerOpen || !IsCardMode || pCols <= 0)
			{
				return;
			}
			SaveManager sM = SM;
			if ((Object)(object)sM == (Object)null)
			{
				return;
			}
			if (pAssignedSig != pFilterSig)
			{
				foreach (KeyValuePair<int, CardUI> item in pAssigned)
				{
					((Component)item.Value).gameObject.SetActive(false);
					pFree.Push(item.Value);
				}
				pAssigned.Clear();
				pAssignedSig = pFilterSig;
			}
			int first = Mathf.Max(0, pVisFirst - pCols);
			int last = Mathf.Min(pFiltered.Count - 1, pVisLast + pCols);
			foreach (int item2 in pAssigned.Keys.Where((int i) => i < first || i > last).ToList())
			{
				CardUI val = pAssigned[item2];
				((Component)val).gameObject.SetActive(false);
				pFree.Push(val);
				pAssigned.Remove(item2);
			}
			List<CardData> list = new List<CardData>();
			for (int num = first; num <= last; num++)
			{
				if (!pAssigned.ContainsKey(num))
				{
					CardData val2 = (CardData)pFiltered[num].data;
					if (!ArtReady(val2) && !pRequestedAt.ContainsKey(val2))
					{
						list.Add(val2);
					}
				}
			}
			if (list.Count > 0)
			{
				foreach (CardData item3 in list)
				{
					pRequestedAt[item3] = Time.realtimeSinceStartup;
				}
				try
				{
					LoadingScreen.AddTask((LoadingTask)new LoadCardsForCompendium((IEnumerable<CardData>)list, (DisplayStyle)0, (Action)null), true);
				}
				catch (Exception ex)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("card art load request failed: " + ex.Message));
				}
			}
			CardUI cardPrefab = GetCardPrefab();
			if ((Object)(object)cardPrefab == (Object)null)
			{
				return;
			}
			int num2 = 6;
			foreach (int item4 in Enumerable.Range(pVisFirst, Mathf.Max(0, Mathf.Min(pVisLast, pFiltered.Count - 1) - pVisFirst + 1)).Concat(Enumerable.Range(first, last - first + 1)))
			{
				if (num2 <= 0)
				{
					break;
				}
				if (item4 < 0 || item4 >= pFiltered.Count || pAssigned.ContainsKey(item4))
				{
					continue;
				}
				CardData val3 = (CardData)pFiltered[item4].data;
				if (!ArtReady(val3))
				{
					continue;
				}
				CardUI val4 = ((pFree.Count > 0) ? pFree.Pop() : CreateCardUI(cardPrefab));
				((Component)val4).gameObject.SetActive(true);
				try
				{
					CardState val5 = pFiltered[item4].state;
					if (val5 == null)
					{
						val5 = new CardState(val3, sM, true, false);
						val5.RefetchAssets(val3);
						val5.RefreshCardBodyTextLocalization();
					}
					val4.SetCardVisibleAndInteractable(true, (HandUI)null);
					val4.SetUIState((CardUIState)3);
					val4.ApplyStateToUI(val5, (CardStatistics)null, (MonsterManager)null, (HeroManager)null, (RelicManager)null, sM, sM.GetMastery(val5), true, false, (List<CardUpgradeState>)null, (CardArtPool)null, (CardEdgeVfxPool)null);
				}
				catch (Exception ex2)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("render card " + pFiltered[item4].name + " failed: " + ex2.Message));
				}
				pAssigned[item4] = val4;
				PlaceCard(item4, val4);
				num2--;
			}
		}

		private CardUI CreateCardUI(CardUI prefab)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			CardUI val = Object.Instantiate<CardUI>(prefab, (Transform)(object)pCardRoot, false);
			((Object)val).name = "PickerCard" + pAllCardUIs.Count;
			pAllCardUIs.Add(val);
			RectTransform val2 = (RectTransform)((Component)val).transform;
			Rect rect = val2.rect;
			if (((Rect)(ref rect)).width > 10f)
			{
				rect = val2.rect;
				if (((Rect)(ref rect)).height > 10f)
				{
					rect = val2.rect;
					pCardNative = ((Rect)(ref rect)).size;
				}
			}
			return val;
		}

		private Rect CardRectFor(int i)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			int num = i / pCols;
			int num2 = i % pCols;
			float num3 = pGridX0 + (float)num2 * (pCardW + 14f);
			float num4 = ((Rect)(ref pGridRect)).y + (float)num * pRowH - pScrollY;
			return new Rect(num3, num4, pCardW, pCardH);
		}

		private void PlaceCard(int i, CardUI ui)
		{
			//IL_0002: 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)
			//IL_000e: 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)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: 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_004a: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			Rect val = CardRectFor(i);
			RectTransform val2 = (RectTransform)((Component)ui).transform;
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(0f, 1f);
			val2.anchorMax = val3;
			val2.anchorMin = val3;
			val2.pivot = new Vector2(0.5f, 0.5f);
			val2.anchoredPosition = new Vector2(((Rect)(ref val)).center.x, 0f - ((Rect)(ref val)).center.y);
			((Transform)val2).localScale = new Vector3(pCardK, pCardK, 1f);
		}

		private bool CardViewportReady()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			if (pCols <= 0)
			{
				return false;
			}
			for (int i = pVisFirst; i <= Mathf.Min(pVisLast, pFiltered.Count - 1); i++)
			{
				if (!pAssigned.ContainsKey(i) && !ArtFailed((CardData)pFiltered[i].data))
				{
					return false;
				}
			}
			return true;
		}

		private void ToggleIn(HashSet<int> set, int v)
		{
			if (!set.Remove(v))
			{
				set.Add(v);
			}
		}

		private void ClearFilters()
		{
			fClan.Clear();
			fType.Clear();
			fRarity.Clear();
			fCost.Clear();
			fOwned = 0;
			pSearch = "";
		}

		private string CurrentFilterSig()
		{
			return string.Format("{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}|{10}", pickerMode, (pickerMode == PickerMode.Deck) ? DeckSignature() : "", pSearch, pSearchText, string.Join(",", fClan), string.Join(",", fType), string.Join(",", fRarity), string.Join(",", fCost), fOwned, pLogbookOnly, pSort);
		}

		private void RefreshFiltered()
		{
			//IL_005e: 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)
			string text = CurrentFilterSig();
			if (text == pFilterSig)
			{
				return;
			}
			string text2 = text.Substring(text.IndexOf('|', text.IndexOf('|') + 1));
			if (pFilterSig != null && text2 != pUserFilterSig)
			{
				pScrollY = 0f;
				pGridScroll = Vector2.zero;
			}
			pUserFilterSig = text2;
			pFilterSig = text;
			pTileSig = null;
			IEnumerable<Entry> enumerable = ((pickerMode == PickerMode.Deck) ? BuildDeckEntries() : ((pickerMode == PickerMode.Cards) ? cardEntries : ((pickerMode == PickerMode.Relics) ? relicEntries : enhancerEntries)));
			if (enumerable == null)
			{
				pFiltered = new List<Entry>();
				return;
			}
			string q = (pSearch ?? "").Trim().ToLowerInvariant();
			IEnumerable<Entry> source = enumerable.Where(delegate(Entry e)
			{
				//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
				//IL_0134: Unknown result type (might be due to invalid IL or missing references)
				//IL_0102: Unknown result type (might be due to invalid IL or missing references)
				//IL_010c: Expected O, but got Unknown
				//IL_01df: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e9: Expected O, but got Unknown
				if (q.Length > 0 && !e.searchKey.Contains(q) && (!IsCardMode || !pSearchText || !CardTextOf(e).Contains(q)))
				{
					return false;
				}
				if (fClan.Count > 0 && !fClan.Contains(e.classIndex))
				{
					return false;
				}
				if (fRarity.Count > 0 && !fRarity.Contains(Array.IndexOf(RarityValues, e.rarity)))
				{
					return false;
				}
				if (IsCardMode)
				{
					if (pickerMode == PickerMode.Cards && pLogbookOnly && logbookSet != null && !logbookSet.Contains((CardData)e.data))
					{
						return false;
					}
					if (fType.Count > 0 && !fType.Contains(Array.IndexOf(TypeFilterValues, e.cardType)))
					{
						return false;
					}
					if (fCost.Count > 0)
					{
						int item = (e.costX ? 5 : ((e.cost >= 4) ? 4 : Mathf.Max(0, e.cost)));
						if (!fCost.Contains(item))
						{
							return false;
						}
					}
				}
				if (pickerMode == PickerMode.Relics)
				{
					if (pLogbookOnly && accessibleRelicSet != null && accessibleRelicSet.Count > 0 && !accessibleRelicSet.Contains((CollectableRelicData)e.data))
					{
						return false;
					}
					if (fOwned != 0 && fOwned == 1 != OwnsRelic(e))
					{
						return false;
					}
				}
				return true;
			});
			pFiltered = (pSort switch
			{
				1 => (from e in source
					orderby (!e.costX) ? e.cost : 99, e.classIndex
					select e).ThenBy<Entry, string>((Entry e) => e.name, StringComparer.Ordinal), 
				2 => source.OrderBy<Entry, string>((Entry e) => e.name, StringComparer.Ordinal), 
				3 => (from e in source
					orderby RarityOrder(e.rarity), e.classIndex
					select e).ThenBy<Entry, string>((Entry e) => e.name, StringComparer.Ordinal), 
				_ => IsCardMode ? (from e in source
					orderby e.classIndex, (int)e.cardType, (!e.costX) ? e.cost : 99
					select e).ThenBy<Entry, string>((Entry e) => e.name, StringComparer.Ordinal) : (from e in source
					orderby e.classIndex, RarityOrder(e.rarity)
					select e).ThenBy<Entry, string>((Entry e) => e.name, StringComparer.Ordinal), 
			}).ToList();
		}

		private static int RarityOrder(CollectableRarity r)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected I4, but got Unknown
			if ((int)r != 4)
			{
				return (int)r;
			}
			return -1;
		}

		private string CardTextOf(Entry e)
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Expected O, but got Unknown
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			if (pCardText == null)
			{
				pCardText = new Dictionary<CardData, string>();
				SaveManager sM = SM;
				foreach (Entry cardEntry in cardEntries)
				{
					string value = "";
					try
					{
						value = Clean(new CardState((CardData)cardEntry.data, sM, true, false).GetCardText((CardStatistics)null, sM, false)).ToLowerInvariant();
					}
					catch
					{
					}
					pCardText[(CardData)cardEntry.data] = value;
				}
			}
			if (!pCardText.TryGetValue((CardData)e.data, out var value2))
			{
				return "";
			}
			return value2;
		}

		private List<CardState> CurrentDeckCards()
		{
			try
			{
				return new List<CardState>(SM.GetDeckState() ?? new List<CardState>());
			}
			catch
			{
				return new List<CardState>();
			}
		}

		private string DeckSignature()
		{
			if (Time.realtimeSinceStartup > pDeckSigAt)
			{
				pDeckSigAt = Time.realtimeSinceStartup + 0.3f;
				List<CardState> list = CurrentDeckCards();
				int num = list.Count;
				foreach (CardState item in list)
				{
					num = num * 31 + RuntimeHelpers.GetHashCode(item);
				}
				pDeckSig = list.Count + ":" + num;
			}
			return pDeckSig;
		}

		private List<Entry> BuildDeckEntries()
		{
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: 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)
			if (pCardById == null)
			{
				pCardById = new Dictionary<string, Entry>();
				foreach (Entry cardEntry in cardEntries)
				{
					pCardById[cardEntry.id] = cardEntry;
				}
			}
			List<Entry> list = new List<Entry>();
			foreach (CardState cs in CurrentDeckCards())
			{
				if (cs == null)
				{
					continue;
				}
				string id = cs.GetCardDataID();
				CardData val = Safe2(() => SM.GetAllGameData().FindCardData(id));
				if (!((Object)(object)val == (Object)null))
				{
					pCardById.TryGetValue(id, out var value);
					string text = Clean(Safe((Func<string>)cs.GetTitle));
					list.Add(new Entry
					{
						data = (GameData)(object)val,
						id = id,
						state = cs,
						name = ((text.Length > 0) ? text : (value?.name ?? ((Object)val).name)),
						english = (value?.english ?? ""),
						asset = ((Object)val).name,
						clan = (value?.clan ?? ""),
						classIndex = (value?.classIndex ?? (classNames.Length - 1)),
						cardType = (CardType)((value == null) ? 4 : ((int)value.cardType)),
						rarity = (CollectableRarity)((value == null) ? (-1) : ((int)value.rarity)),
						cost = (value?.cost ?? 0),
						costX = (value?.costX ?? false),
						info = value?.info + ((Safe(() => cs.IsChampionCard().ToString()) == "True") ? T(" · 勇者") : ""),
						searchKey = (text + "|" + value?.searchKey).ToLowerInvariant()
					});
				}
			}
			return list;
		}

		private void DeleteFromDeck(Entry e)
		{
			CardState cs = e.state;
			if (cs == null)
			{
				return;
			}
			if (Safe(() => cs.IsChampionCard().ToString()) == "True")
			{
				Toast(T("勇者卡不能删"));
				return;
			}
			if (CheatManager.IsBusy)
			{
				Toast(T("游戏还在处理上一个操作,稍等一下"));
				return;
			}
			try
			{
				if (InBattle())
				{
					MethodInfo method = typeof(CheatManager).GetMethod("PurgeCard", AnyStatic);
					((MonoBehaviour)SM).StartCoroutine((IEnumerator)method.Invoke(null, new object[2]
					{
						AGM.GetCardManager(),
						cs
					}));
				}
				else
				{
					SM.RemoveCardFromDeck(cs);
				}
				Toast(T("已删除:") + e.name);
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)ex);
				Toast(T("删除失败:") + (ex.InnerException ?? ex).Message);
			}
			pDeckSigAt = 0f;
		}

		private bool OwnsRelic(Entry e)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			try
			{
				return InRun() && SM.GetHasRelic((RelicData)e.data);
			}
			catch
			{
				return false;
			}
		}

		private int DeckCount(string cardId)
		{
			if (Time.realtimeSinceStartup > pDeckCountsAt)
			{
				pDeckCountsAt = Time.realtimeSinceStartup + 0.4f;
				try
				{
					pDeckCounts = (from c in SM.GetDeckState()
						where c != null
						group c by c.GetCardDataID()).ToDictionary((IGrouping<string, CardState> g) => g.Key, (IGrouping<string, CardState> g) => g.Count());
				}
				catch
				{
					pDeckCounts = new Dictionary<string, int>();
				}
			}
			if (!pDeckCounts.TryGetValue(cardId, out var value))
			{
				return 0;
			}
			return value;
		}

		private void PickerActivate(Entry e)
		{
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Expected O, but got Unknown
			pFlash = e;
			pFlashUntil = Time.realtimeSinceStartup + 1.2f;
			switch (pickerMode)
			{
			case PickerMode.Deck:
				if (!NeedRun())
				{
					break;
				}
				if (pDeckEdit)
				{
					OpenCardEdit(e);
					break;
				}
				if (pDeckDelete)
				{
					DeleteFromDeck(e);
					break;
				}
				pAddQueue.Enqueue(e.id);
				if (!pAddRunning)
				{
					((MonoBehaviour)runner).StartCoroutine(ProcessAddQueue());
				}
				Toast(T("复制一张:") + e.name + (InBattle() ? T("(进手牌)") : T("(进牌组)")));
				pDeckSigAt = 0f;
				break;
			case PickerMode.Cards:
				if (NeedRun())
				{
					for (int i = 0; i < pAddCount; i++)
					{
						pAddQueue.Enqueue(e.id);
					}
					if (!pAddRunning)
					{
						((MonoBehaviour)runner).StartCoroutine(ProcessAddQueue());
					}
					Toast(T($"加入 {e.name} ×{pAddCount}", $"Added {e.name} ×{pAddCount}") + (InBattle() ? T("(进手牌)") : T("(进牌组)")));
				}
				break;
			case PickerMode.Relics:
				if (!NeedRun())
				{
					break;
				}
				if (OwnsRelic(e))
				{
					if (Run("Command_RemoveArtifact", e.id))
					{
						Toast(T("已移除:") + e.name);
					}
				}
				else if (Run("Command_AddArtifact", e.id))
				{
					Toast(T("已获得:") + e.name);
				}
				if (fOwned != 0)
				{
					pFilterSig = null;
				}
				break;
			case PickerMode.Enhancers:
			{
				if (!NeedRun())
				{
					break;
				}
				if (InBattle())
				{
					Toast(T("战斗中不能用强化石"));
					break;
				}
				if (CheatManager.IsBusy)
				{
					Toast(T("游戏还在处理上一个操作,稍等一下"));
					break;
				}
				MethodInfo method = typeof(CheatManager).GetMethod("UpgradeCardCoroutine", AnyStatic);
				if (method == null)
				{
					Toast(T("找不到游戏的强化接口(游戏可能更新了)"));
					break;
				}
				ClosePicker();
				show = false;
				((MonoBehaviour)SM).StartCoroutine((IEnumerator)method.Invoke(null, new object[1] { (object)(EnhancerData)e.data }));
				Toast(T("请选择要强化的卡:") + e.name);
				break;
			}
			}
		}

		private IEnumerator ProcessAddQueue()
		{
			pAddRunning = true;
			while (pAddQueue.Count > 0)
			{
				yield return WaitFor(() => !CheatManager.IsBusy, 30f, "picker add");
				string text = pAddQueue.Dequeue();
				Run("Command_AddCard", text, false);
				yield return null;
				yield return WaitFor(() => !CheatManager.IsBusy, 30f, "picker add done");
				pDeckCountsAt = 0f;
			}
			pAddRunning = false;
		}

		private void DrawPicker(float s)
		{
			//IL_00f3: 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_001f: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Invalid comparison between Unknown and I4
			//IL_009c: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)SM == (Object)null)
			{
				ClosePicker();
				return;
			}
			RefreshFiltered();
			Matrix4x4 matrix = GUI.matrix;
			GUI.matrix = Matrix4x4.Scale(new Vector3(s, s, 1f));
			float num = (float)Screen.width / s;
			float num2 = (float)Screen.height / s;
			if ((int)Event.current.type == 8)
			{
				pHoverLatched = pHover;
			}
			pHover = null;
			try
			{
				Rect grid = default(Rect);
				((Rect)(ref grid))..ctor(310f, 72f, num - 300f - 20f, num2 - 62f - 10f);
				if (pEditEntry != null)
				{
					DrawCardEdit(grid);
				}
				else if (IsCardMode)
				{
					DrawCardGrid(grid);
				}
				else
				{
					DrawTileGrid(grid);
				}
				DrawTopBar(num);
				DrawSidebar(num2);
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("picker draw: " + ex));
			}
			finally
			{
				GUI.matrix = matrix;
			}
		}

		private void DrawTopBar(float W)
		{
			//IL_0010: 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)
			GUI.Box(new Rect(0f, 0f, W, 62f), GUIContent.none, sPanel);
			GUILayout.BeginArea(new Rect(10f, 10f, W - 20f, 48f));
			try
			{
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				string[] array = new string[4]
				{
					T("加卡"),
					T("神器"),
					T("强化石"),
					T("牌组/删牌")
				};
				for (int i = 0; i < array.Length; i++)
				{
					if (GUILayout.Button(array[i], (pickerMode == (PickerMode)i) ? sTabOn : sTab, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width((float)((!IsZh) ? ((i == 3) ? 130 : 105) : ((i == 3) ? 110 : 80))) }) && pickerMode != (PickerMode)i)
					{
						if (pEditEntry != null)
						{
							CloseCardEdit();
						}
						pickerMode = (PickerMode)i;
						ClearFilters();
						pFilterSig = null;
						pTileSig = null;
					}
				}
				GUILayout.Space(16f);
				GUILayout.Label(T("搜索"), sLabelNW, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
				pSearch = GUILayout.TextField(pSearch, 40, sField, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(220f),
					GUILayout.Height(30f)
				});
				if (GUILayout.Button(T("清空"), sChip, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(50f),
					GUILayout.Height(30f)
				}))
				{
					pSearch = "";
					GUI.FocusControl((string)null);
				}
				GUILayout.Space(14f);
				GUILayout.Label(T("排序"), sLabelNW, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
				for (int j = 0; j < SortNames.Length; j++)
				{
					if (GUILayout.Button(SortNames[j], (pSort == j) ? sChipOn : sChip, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }))
					{
						pSort = j;
					}
				}
				if (IsCardMode)
				{
					if (pickerMode == PickerMode.Deck)
					{
						GUILayout.Space(14f);
						GUILayout.Label(T("点击卡牌"), sLabelNW, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
						if (GUILayout.Button(T("删除"), (pDeckDelete && !pDeckEdit) ? sChipDanger : sChip, (GUILayoutOption[])(object)new GUILayoutOption[2]
						{
							GUILayout.ExpandWidth(false),
							GUILayout.Height(30f)
						}))
						{
							pDeckDelete = true;
							pDeckEdit = false;
						}
						if (GUILayout.Button(T("复制一张"), (!pDeckDelete && !pDeckEdit) ? sChipOn : sChip, (GUILayoutOption[])(object)new GUILayoutOption[2]
						{
							GUILayout.ExpandWidth(false),
							GUILayout.Height(30f)
						}))
						{
							pDeckDelete = false;
							pDeckEdit = false;
						}
						if (GUILayout.Button(T("改卡(去掉/加强化)"), pDeckEdit ? sChipOn : sChip, (GUILayoutOption[])(object)new GUILayoutOption[2]
						{
							GUILayout.ExpandWidth(false),
							GUILayout.Height(30f)
						}))
						{
							pDeckDelete = false;
							pDeckEdit = true;
						}
					}
					else
					{
						GUILayout.Space(14f);
						GUILayout.Label(T("每次加"), sLabelNW, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
						int[] array2 = new int[4] { 1, 2, 3, 5 };
						for (int k = 0; k < array2.Length; k++)
						{
							int num = array2[k];
							if (GUILayout.Button("×" + num, (pAddCount == num) ? sChipOn : sChip, (GUILayoutOption[])(object)new GUILayoutOption[2]
							{
								GUILayout.Width(38f),
								GUILayout.Height(30f)
							}))
							{
								pAddCount = num;
							}
						}
					}
					GUILayout.Space(14f);
					GUILayout.Label(T("卡牌大小"), sLabelNW, (GUILayoutOption[])(obj