Decompiled source of SlotKeybinds v1.0.1

daymxn.RogueTower.SlotKeybinds.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using JetBrains.Annotations;
using Microsoft.CodeAnalysis;
using SlotKeybindsPlugin.features.Banish;
using SlotKeybindsPlugin.features.BanishColors;
using SlotKeybindsPlugin.features.KeyOverlay;
using SlotKeybindsPlugin.features.SelectSlot;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("daymxn.RogueTower.SlotKeybinds")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+b6a278975ffa9428a872a4f7f1cc5186af4e4b80")]
[assembly: AssemblyProduct("Slot Keybinds")]
[assembly: AssemblyTitle("daymxn.RogueTower.SlotKeybinds")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 SlotKeybindsPlugin
{
	public static class Game
	{
		public static CardManager? GetCardManager()
		{
			return CardManager.instance;
		}

		public static TowerUnlockManager? GetTowerUnlockManager()
		{
			return TowerUnlockManager.instance;
		}

		public static SelectMode DetermineSelectMode()
		{
			if (!Object.op_Implicit((Object)(object)GetCardManager()))
			{
				return SelectMode.None;
			}
			if (!DrawingCards())
			{
				return SelectMode.TowerSelect;
			}
			return MonsterCardUIActive() ? SelectMode.MonsterCardSelect : SelectMode.CardSelect;
		}

		public static GameObject? GetCardHolder(int slot)
		{
			CardManager cardManager = GetCardManager();
			if (!Object.op_Implicit((Object)(object)cardManager))
			{
				return null;
			}
			if (!(AccessTools.Field(typeof(CardManager), "cardHolders")?.GetValue(cardManager) is GameObject[] array))
			{
				Plugin.Logger.LogWarning((object)"cardHolders field not found.");
				return null;
			}
			if (array.Length >= slot)
			{
				return array[slot];
			}
			Plugin.Logger.LogWarning((object)$"cardHolders array is smaller than slot number (length is {array.Length}, but slot was {slot}).");
			return null;
		}

		public static Text[] GetCardTitles()
		{
			CardManager cardManager = GetCardManager();
			if (!Object.op_Implicit((Object)(object)cardManager))
			{
				return Array.Empty<Text>();
			}
			Text[] array = AccessTools.Field(typeof(CardManager), "titles")?.GetValue(cardManager) as Text[];
			return array ?? Array.Empty<Text>();
		}

		public static Text[] GetMonsterCardTitles()
		{
			CardManager cardManager = GetCardManager();
			if (!Object.op_Implicit((Object)(object)cardManager))
			{
				return Array.Empty<Text>();
			}
			Text[] array = AccessTools.Field(typeof(CardManager), "monsterTitles")?.GetValue(cardManager) as Text[];
			return array ?? Array.Empty<Text>();
		}

		public static Image[] GetCardImages()
		{
			CardManager cardManager = GetCardManager();
			if (!Object.op_Implicit((Object)(object)cardManager))
			{
				return Array.Empty<Image>();
			}
			Image[] array = AccessTools.Field(typeof(CardManager), "images")?.GetValue(cardManager) as Image[];
			return array ?? Array.Empty<Image>();
		}

		public static BuildButtonUI? GetBuildingButton(int slot)
		{
			List<GameObject>? unlockedBuildings = GetUnlockedBuildings();
			object result;
			if (unlockedBuildings == null)
			{
				result = null;
			}
			else
			{
				GameObject? obj = unlockedBuildings.ElementAtOrDefault(slot);
				result = ((obj != null) ? obj.GetComponentInChildren<BuildButtonUI>() : null);
			}
			return (BuildButtonUI?)result;
		}

		public static BuildButtonUI? GetTowerButton(int slot)
		{
			List<GameObject>? unlockedTowers = GetUnlockedTowers();
			object result;
			if (unlockedTowers == null)
			{
				result = null;
			}
			else
			{
				GameObject? obj = unlockedTowers.ElementAtOrDefault(slot);
				result = ((obj != null) ? obj.GetComponentInChildren<BuildButtonUI>() : null);
			}
			return (BuildButtonUI?)result;
		}

		private static bool MonsterCardUIActive()
		{
			GameObject? obj = MonsterCardUI();
			return obj != null && obj.activeInHierarchy;
		}

		private static bool DrawingCards()
		{
			CardManager? cardManager = GetCardManager();
			return cardManager != null && cardManager.drawingCards;
		}

		private static GameObject? MonsterCardUI()
		{
			CardManager cardManager = GetCardManager();
			if (!Object.op_Implicit((Object)(object)cardManager))
			{
				return null;
			}
			object? obj = AccessTools.Field(typeof(CardManager), "monsterCardUI")?.GetValue(cardManager);
			return (GameObject?)((obj is GameObject) ? obj : null);
		}

		public static List<GameObject>? GetUnlockedTowers()
		{
			Plugin.Logger.LogDebug((object)"Getting unlocked towers.");
			TowerUnlockManager towerUnlockManager = GetTowerUnlockManager();
			if (!Object.op_Implicit((Object)(object)towerUnlockManager))
			{
				return null;
			}
			Plugin.Logger.LogDebug((object)"Getting unlocked towers field.");
			if (AccessTools.Field(typeof(TowerUnlockManager), "unlockedTowers")?.GetValue(towerUnlockManager) is List<GameObject> result)
			{
				return result;
			}
			Plugin.Logger.LogWarning((object)"unlockedTowers field not found.");
			return null;
		}

		public static List<GameObject>? GetUnlockedBuildings()
		{
			TowerUnlockManager towerUnlockManager = GetTowerUnlockManager();
			if (!Object.op_Implicit((Object)(object)towerUnlockManager))
			{
				return null;
			}
			if (AccessTools.Field(typeof(TowerUnlockManager), "unlockedBuildings")?.GetValue(towerUnlockManager) is List<GameObject> result)
			{
				return result;
			}
			Plugin.Logger.LogWarning((object)"unlockedBuildings field not found.");
			return null;
		}
	}
	public enum SelectMode
	{
		None,
		TowerSelect,
		CardSelect,
		MonsterCardSelect
	}
	[BepInProcess("Rogue Tower.exe")]
	[BepInProcess("RogueTower.exe")]
	[BepInPlugin("daymxn.RogueTower.SlotKeybinds", "Slot Keybinds", "1.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		public ConfigEntry<bool> PluginEnabled;

		public ConfigEntry<bool> UpgradeCardSelect;

		public ConfigEntry<bool> MonsterCardSelect;

		public ConfigEntry<bool> TowerSelect;

		public ConfigEntry<bool> BuildingSelect;

		public ConfigEntry<bool> BanishEnabled;

		public ConfigEntry<bool> BanishColorsEnabled;

		public ConfigEntry<bool> TowerKeyOverlay;

		public ConfigEntry<bool> UpgradeCardKeyOverlay;

		public ConfigEntry<bool> MonsterCardKeyOverlay;

		public ConfigEntry<Color> BanishColor;

		public ConfigEntry<KeyCode> BanishKey;

		public ConfigEntry<KeyCode> BuildingKey;

		public readonly ConfigEntry<KeyCode>[] SelectKeys = new ConfigEntry<KeyCode>[11];

		public bool BanishPluginPresent;

		public TowerKeyOverlay TowerKeyOverlayFeature;

		public BuildingKeyOverlay BuildingKeyOverlayFeature;

		public UpgradeCardKeyOverlay UpgradeCardKeyOverlayFeature;

		public MonsterCardKeyOverlay MonsterCardKeyOverlayFeature;

		public BanishColors BanishColorsFeature;

		public SelectSlot SelectSlotFeature;

		public Harmony Patches;

		public static Plugin Instance { get; private set; }

		private static KeyCode DefaultKeyCodeForSlot(int slot)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_001f: Unknown result type (might be due to invalid IL or missing references)
			if (1 == 0)
			{
			}
			KeyCode result = ((slot < 10) ? ((KeyCode)(49 + (slot - 1))) : ((slot != 10) ? ((KeyCode)0) : ((KeyCode)48)));
			if (1 == 0)
			{
			}
			return result;
		}

		private void Awake()
		{
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Expected O, but got Unknown
			Instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Loading plugin daymxn.RogueTower.SlotKeybinds");
			PluginEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable the plugin.");
			UpgradeCardSelect = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "UpgradeCardSelect", true, "Use the slot keys for selecting upgrade cards.");
			MonsterCardSelect = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "MonsterCardSelect", true, "Use the slot keys for monster buff cards drawn after special game modes.");
			TowerSelect = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "TowerSelect", true, "Use the slot keys for selecting towers to build.");
			BuildingSelect = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "BuildingSelect", true, "Toggle the key behavior for selecting building cards.");
			TowerKeyOverlay = ((BaseUnityPlugin)this).Config.Bind<bool>("Overlay", "Towers", true, "Displays text on tower and building cards showcasing the key said slot is bound to.");
			UpgradeCardKeyOverlay = ((BaseUnityPlugin)this).Config.Bind<bool>("Overlay", "UpgradeCards", true, "Displays text on upgrade cards showcasing the key said slot is bound to.");
			MonsterCardKeyOverlay = ((BaseUnityPlugin)this).Config.Bind<bool>("Overlay", "MonsterCards", true, "Displays text on monster cards showcasing the key said slot is bound to.");
			BanishEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Banish", "Enabled", true, "Toggle the banish feature; requires the Banish plugin.");
			BanishColorsEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Banish", "CardColors", true, "Change the colors of upgrade cards when the banish key is held.");
			BanishColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Banish", "Color", new Color(1f, 0f, 0f, 1f), "Color to change upgrade cards to when the banish key is held.");
			BanishKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Banish", "Key", (KeyCode)306, "While this key is held, using a slot key will banish a card instead of selecting it.");
			BuildingKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Keybinds", "BuildingKey", (KeyCode)304, "While this key is held, using a slot key will select a building card instead of a tower card.");
			for (int i = 1; i < SelectKeys.Length; i++)
			{
				SelectKeys[i] = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Keybinds", $"Slot{i}", DefaultKeyCodeForSlot(i), $"Key to quick select the item at slot {i}");
			}
			BanishPluginPresent = Chainloader.PluginInfos.ContainsKey("AgusBut.BanishCards");
			Logger.LogInfo((object)$"Banish plugin present: {BanishPluginPresent}");
			TowerKeyOverlayFeature = new TowerKeyOverlay();
			BuildingKeyOverlayFeature = new BuildingKeyOverlay();
			UpgradeCardKeyOverlayFeature = new UpgradeCardKeyOverlay();
			MonsterCardKeyOverlayFeature = new MonsterCardKeyOverlay();
			BanishColorsFeature = new BanishColors();
			SelectSlotFeature = new SelectSlot();
			SelectSlotFeature.OnStart();
			Patches = new Harmony("daymxn.RogueTower.SlotKeybinds");
			Patches.PatchAll();
			Logger.LogInfo((object)"Loaded plugin daymxn.RogueTower.SlotKeybinds!");
		}

		public void Update()
		{
			BanishColorsFeature.OnUpdate();
			SelectSlotFeature.OnUpdate();
		}

		public void OnDestroy()
		{
			Patches.UnpatchSelf();
			TowerKeyOverlayFeature?.OnDestroy();
			BuildingKeyOverlayFeature?.OnDestroy();
			UpgradeCardKeyOverlayFeature?.OnDestroy();
			MonsterCardKeyOverlayFeature?.OnDestroy();
			BanishColorsFeature?.OnDestroy();
		}

		public KeyCode GetKeyForSlot(int slot)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			ConfigEntry<KeyCode>? obj = SelectKeys.ElementAtOrDefault(slot + 1);
			return (KeyCode)((obj != null) ? ((int)obj.Value) : 0);
		}
	}
	public static class Util
	{
		public static List<GameObject> FindChildrenByName(this Transform parent, string name, bool recursive = false)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			List<GameObject> list = new List<GameObject>();
			foreach (Transform item in parent)
			{
				Transform val = item;
				if (((Object)val).name == name)
				{
					list.Add(((Component)val).gameObject);
				}
				if (recursive)
				{
					list.AddRange(val.FindChildrenByName(name, recursive: true));
				}
			}
			return list;
		}

		[CanBeNull]
		public static GameObject FindChildByName(this Transform parent, string name, bool recursive = false)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			Transform val = parent.Find(name);
			if (Object.op_Implicit((Object)(object)val))
			{
				return ((Component)val).gameObject;
			}
			if (!recursive)
			{
				return null;
			}
			foreach (Transform item in parent)
			{
				Transform parent2 = item;
				GameObject val2 = parent2.FindChildByName(name, recursive: true);
				if (Object.op_Implicit((Object)(object)val2))
				{
					return val2;
				}
			}
			return null;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "daymxn.RogueTower.SlotKeybinds";

		public const string PLUGIN_NAME = "Slot Keybinds";

		public const string PLUGIN_VERSION = "1.0.1";
	}
}
namespace SlotKeybindsPlugin.patches
{
	[HarmonyPatch(typeof(CardManager), "DisplayMonsterCards")]
	public class MonsterCardPatch
	{
		private static void Postfix(CardManager __instance, int count)
		{
			Plugin.Instance.MonsterCardKeyOverlayFeature.Refresh();
		}
	}
	[HarmonyPatch(typeof(TowerUnlockManager), "DisplayButtons")]
	public class TowerCardPatch
	{
		private static void Postfix(TowerUnlockManager __instance)
		{
			Plugin.Instance.TowerKeyOverlayFeature.Refresh();
			Plugin.Instance.BuildingKeyOverlayFeature.Refresh();
		}
	}
	[HarmonyPatch(typeof(CardManager), "DisplayCards")]
	public class UpgradeCardPatch
	{
		private static void Postfix(CardManager __instance, int count)
		{
			Plugin.Instance.UpgradeCardKeyOverlayFeature.Refresh();
		}
	}
}
namespace SlotKeybindsPlugin.features
{
	public abstract class Feature
	{
		protected static ManualLogSource Logger = Plugin.Logger;

		public virtual bool IsEnabled()
		{
			return Plugin.Instance.PluginEnabled.Value;
		}

		public virtual void OnUpdate()
		{
		}

		public virtual void OnStart()
		{
		}

		public virtual void OnDestroy()
		{
		}
	}
	public interface InternalFeature
	{
	}
}
namespace SlotKeybindsPlugin.features.SelectSlot
{
	public class SelectBuilding : SelectSlot, InternalFeature
	{
		public override bool IsEnabled()
		{
			return base.IsEnabled() && Plugin.Instance.BuildingSelect.Value;
		}

		public bool Select(int slot)
		{
			if (!IsEnabled())
			{
				return false;
			}
			BuildButtonUI buildingButton = Game.GetBuildingButton(slot);
			if (!Object.op_Implicit((Object)(object)buildingButton))
			{
				Feature.Logger.LogWarning((object)$"Building button not found for slot {slot}");
				return true;
			}
			buildingButton.Build();
			Feature.Logger.LogDebug((object)$"Pressed building slot {slot}");
			return true;
		}
	}
	public class SelectMonsterCard : SelectSlot, InternalFeature
	{
		public override bool IsEnabled()
		{
			return base.IsEnabled() && Plugin.Instance.MonsterCardSelect.Value;
		}

		public bool Select(int slot)
		{
			if (!IsEnabled())
			{
				return false;
			}
			CardManager? cardManager = Game.GetCardManager();
			if (cardManager != null)
			{
				cardManager.ActivateMonsterCard(slot);
			}
			Feature.Logger.LogDebug((object)$"Selected monster card slot {slot}");
			return true;
		}
	}
	public class SelectSlot : Feature
	{
		private SelectTower _selectTower;

		private SelectBuilding _selectBuilding;

		private SelectUpgradeCard _selectUpgradeCard;

		private SelectMonsterCard _selectMonsterCard;

		private BanishUpgradeCard _banishUpgradeCard;

		public override void OnStart()
		{
			_selectTower = new SelectTower();
			_selectBuilding = new SelectBuilding();
			_selectUpgradeCard = new SelectUpgradeCard();
			_selectMonsterCard = new SelectMonsterCard();
			_banishUpgradeCard = new BanishUpgradeCard();
		}

		public override void OnUpdate()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 1; i < Plugin.Instance.SelectKeys.Length; i++)
			{
				if (Input.GetKeyUp(Plugin.Instance.SelectKeys[i].Value) && !OnSlotSelected(i - 1))
				{
					Feature.Logger.LogWarning((object)$"Failed to select slot {i}");
				}
			}
		}

		private bool OnSlotSelected(int slot)
		{
			SelectMode selectMode = Game.DetermineSelectMode();
			if (1 == 0)
			{
			}
			bool result = selectMode switch
			{
				SelectMode.None => true, 
				SelectMode.CardSelect => (!BanishKeyHeld()) ? _selectUpgradeCard.Select(slot) : (_banishUpgradeCard.Banish(slot) || _selectUpgradeCard.Select(slot)), 
				SelectMode.MonsterCardSelect => _selectMonsterCard.Select(slot), 
				SelectMode.TowerSelect => (!BuildingKeyHeld()) ? _selectTower.Select(slot) : (_selectBuilding.Select(slot) || _selectTower.Select(slot)), 
				_ => throw new ArgumentOutOfRangeException(), 
			};
			if (1 == 0)
			{
			}
			return result;
		}

		private bool BanishKeyHeld()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			return Input.GetKey(Plugin.Instance.BanishKey.Value);
		}

		private bool BuildingKeyHeld()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			return Input.GetKey(Plugin.Instance.BuildingKey.Value);
		}
	}
	public class SelectTower : SelectSlot, InternalFeature
	{
		public override bool IsEnabled()
		{
			return base.IsEnabled() && Plugin.Instance.TowerSelect.Value;
		}

		public bool Select(int slot)
		{
			if (!IsEnabled())
			{
				return false;
			}
			BuildButtonUI towerButton = Game.GetTowerButton(slot);
			if (!Object.op_Implicit((Object)(object)towerButton))
			{
				Feature.Logger.LogWarning((object)$"Tower button not found for slot {slot}");
				return true;
			}
			towerButton.Build();
			Feature.Logger.LogDebug((object)$"Pressed tower slot {slot}");
			return true;
		}
	}
	public class SelectUpgradeCard : SelectSlot, InternalFeature
	{
		public override bool IsEnabled()
		{
			return base.IsEnabled() && Plugin.Instance.UpgradeCardSelect.Value;
		}

		public bool Select(int slot)
		{
			if (!IsEnabled())
			{
				return false;
			}
			CardManager? cardManager = Game.GetCardManager();
			if (cardManager != null)
			{
				cardManager.ActivateCard(slot);
			}
			Feature.Logger.LogDebug((object)$"Selected card slot {slot}");
			return true;
		}
	}
}
namespace SlotKeybindsPlugin.features.KeyOverlay
{
	public class BuildingKeyOverlay : KeyOverlay
	{
		public override bool IsEnabled()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Invalid comparison between Unknown and I4
			return base.IsEnabled() && Plugin.Instance.TowerKeyOverlay.Value && Plugin.Instance.BuildingSelect.Value && (int)Plugin.Instance.BuildingKey.Value > 0;
		}

		public void Refresh()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			List<GameObject> unlockedBuildings = Game.GetUnlockedBuildings();
			if (unlockedBuildings != null)
			{
				for (int i = 0; i < unlockedBuildings.Count; i++)
				{
					CheckSlot(unlockedBuildings[i], Plugin.Instance.GetKeyForSlot(i), i);
				}
			}
		}

		public override void OnDestroy()
		{
			List<GameObject> unlockedBuildings = Game.GetUnlockedBuildings();
			if (unlockedBuildings == null)
			{
				return;
			}
			foreach (GameObject item in unlockedBuildings)
			{
				GameObject val = item.transform.FindChildByName("KeyOverlay", recursive: true);
				if (Object.op_Implicit((Object)(object)val))
				{
					Object.Destroy((Object)(object)val);
				}
			}
		}

		private void CheckSlot(GameObject building, KeyCode code, int slot)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: 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)
			BuildButtonUI componentInChildren = building.GetComponentInChildren<BuildButtonUI>();
			if (!Object.op_Implicit((Object)(object)componentInChildren))
			{
				Feature.Logger.LogWarning((object)$"Failed to find BuildButtonUI (slot: {slot}).");
				return;
			}
			Transform parent = ((Component)componentInChildren).transform.parent;
			Transform val = parent.Find("KeybindOverlay");
			bool flag = IsEnabled() && (int)code > 0;
			if (Object.op_Implicit((Object)(object)val))
			{
				if (flag)
				{
					Text component = ((Component)val).GetComponent<Text>();
					component.text = "[ " + KeyOverlay.KeyCodeToString(Plugin.Instance.BuildingKey.Value) + " + " + KeyOverlay.KeyCodeToString(code) + " ]";
				}
				else
				{
					Object.Destroy((Object)(object)val);
				}
			}
			else if (flag)
			{
				object? obj = AccessTools.Field(typeof(BuildButtonUI), "priceTag")?.GetValue(componentInChildren);
				Text val2 = (Text)((obj is Text) ? obj : null);
				if (!Object.op_Implicit((Object)(object)val2))
				{
					Plugin.Logger.LogWarning((object)$"Failed to find price tag (slot: {slot}).");
					return;
				}
				KeyOverlay.ConfigureTextObject(Object.Instantiate<Transform>(((Component)val2).transform, parent), KeyOverlay.KeyCodeToString(Plugin.Instance.BuildingKey.Value) + " + " + KeyOverlay.KeyCodeToString(code), Color.black);
				Feature.Logger.LogDebug((object)$"Building key overlay created for slot {slot}");
			}
		}
	}
	public class KeyOverlay : Feature
	{
		protected static string KeyCodeToString(KeyCode code)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected I4, but got Unknown
			if (1 == 0)
			{
			}
			string result = (code - 48) switch
			{
				0 => "0", 
				1 => "1", 
				2 => "2", 
				3 => "3", 
				4 => "4", 
				5 => "5", 
				6 => "6", 
				7 => "7", 
				8 => "8", 
				9 => "9", 
				_ => ((object)(KeyCode)(ref code)).ToString(), 
			};
			if (1 == 0)
			{
			}
			return result;
		}

		protected static void ConfigureTextObject(Transform clonedTransform, string text, Color? color = null, int? fontSize = null)
		{
			//IL_001d: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			((Object)clonedTransform).name = "KeyOverlay";
			clonedTransform.localPosition = new Vector3(0f, 0f, 0f);
			Text component = ((Component)clonedTransform).GetComponent<Text>();
			component.fontStyle = (FontStyle)1;
			((Graphic)component).color = (Color)(((??)color) ?? ((Graphic)component).color);
			component.fontSize = fontSize ?? component.fontSize;
			component.text = "[ " + text + " ]";
			((Component)clonedTransform).transform.SetAsLastSibling();
		}
	}
	public class MonsterCardKeyOverlay : KeyOverlay
	{
		public override bool IsEnabled()
		{
			return base.IsEnabled() && Plugin.Instance.UpgradeCardSelect.Value && Plugin.Instance.MonsterCardKeyOverlay.Value;
		}

		public void Refresh()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			Text[] monsterCardTitles = Game.GetMonsterCardTitles();
			for (int i = 0; i < monsterCardTitles.Length; i++)
			{
				CheckSlot(monsterCardTitles[i], Plugin.Instance.GetKeyForSlot(i), i);
			}
		}

		public override void OnDestroy()
		{
			Text[] monsterCardTitles = Game.GetMonsterCardTitles();
			Text[] array = monsterCardTitles;
			foreach (Text val in array)
			{
				Transform val2 = ((Component)val).transform.parent.Find("KeybindOverlay");
				if (Object.op_Implicit((Object)(object)val2))
				{
					Object.Destroy((Object)(object)val2);
				}
			}
		}

		private void CheckSlot(Text title, KeyCode code, int slot)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Invalid comparison between Unknown and I4
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			Transform parent = ((Component)title).transform.parent;
			Transform val = parent.Find("KeybindOverlay");
			bool flag = IsEnabled() && (int)code > 0;
			if (Object.op_Implicit((Object)(object)val))
			{
				if (flag)
				{
					Text component = ((Component)val).GetComponent<Text>();
					component.text = "[ " + KeyOverlay.KeyCodeToString(code) + " ]";
				}
				else
				{
					Object.Destroy((Object)(object)val);
				}
			}
			else if (flag)
			{
				Transform clonedTransform = Object.Instantiate<Transform>(((Component)title).transform, parent);
				string text = KeyOverlay.KeyCodeToString(code);
				int? fontSize = 240;
				KeyOverlay.ConfigureTextObject(clonedTransform, text, null, fontSize);
				Feature.Logger.LogDebug((object)$"Monster card key overlay created for slot {slot}");
			}
		}
	}
	public class TowerKeyOverlay : KeyOverlay
	{
		public override bool IsEnabled()
		{
			return base.IsEnabled() && Plugin.Instance.TowerKeyOverlay.Value && Plugin.Instance.TowerSelect.Value;
		}

		public void Refresh()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			List<GameObject> unlockedTowers = Game.GetUnlockedTowers();
			if (unlockedTowers != null)
			{
				for (int i = 0; i < unlockedTowers.Count; i++)
				{
					CheckSlot(unlockedTowers[i], Plugin.Instance.GetKeyForSlot(i), i);
				}
			}
		}

		public override void OnDestroy()
		{
			List<GameObject> unlockedTowers = Game.GetUnlockedTowers();
			if (unlockedTowers == null)
			{
				return;
			}
			foreach (GameObject item in unlockedTowers)
			{
				GameObject val = item.transform.FindChildByName("KeyOverlay", recursive: true);
				if (Object.op_Implicit((Object)(object)val))
				{
					Object.Destroy((Object)(object)val);
				}
			}
		}

		private void CheckSlot(GameObject tower, KeyCode code, int slot)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Invalid comparison between Unknown and I4
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			BuildButtonUI componentInChildren = tower.GetComponentInChildren<BuildButtonUI>();
			if (!Object.op_Implicit((Object)(object)componentInChildren))
			{
				Feature.Logger.LogWarning((object)$"Failed to find BuildButtonUI (slot: {slot}).");
				return;
			}
			Transform parent = ((Component)componentInChildren).transform.parent;
			Transform val = parent.Find("KeybindOverlay");
			bool flag = IsEnabled() && (int)code > 0;
			if (Object.op_Implicit((Object)(object)val))
			{
				if (flag)
				{
					Text component = ((Component)val).GetComponent<Text>();
					component.text = "[ " + KeyOverlay.KeyCodeToString(code) + " ]";
				}
				else
				{
					Object.Destroy((Object)(object)val);
				}
			}
			else if (flag)
			{
				object? obj = AccessTools.Field(typeof(BuildButtonUI), "priceTag")?.GetValue(componentInChildren);
				Text val2 = (Text)((obj is Text) ? obj : null);
				if (!Object.op_Implicit((Object)(object)val2))
				{
					Plugin.Logger.LogWarning((object)$"Failed to find price tag (slot: {slot}).");
					return;
				}
				KeyOverlay.ConfigureTextObject(Object.Instantiate<Transform>(((Component)val2).transform, parent), KeyOverlay.KeyCodeToString(code), Color.black);
				Feature.Logger.LogDebug((object)$"Tower key overlay created for slot {slot}");
			}
		}
	}
	public class UpgradeCardKeyOverlay : KeyOverlay
	{
		public override bool IsEnabled()
		{
			return base.IsEnabled() && Plugin.Instance.UpgradeCardSelect.Value && Plugin.Instance.UpgradeCardKeyOverlay.Value;
		}

		public void Refresh()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			Text[] cardTitles = Game.GetCardTitles();
			for (int i = 0; i < cardTitles.Length; i++)
			{
				CheckSlot(cardTitles[i], Plugin.Instance.GetKeyForSlot(i), i);
			}
		}

		public override void OnDestroy()
		{
			Text[] cardTitles = Game.GetCardTitles();
			Text[] array = cardTitles;
			foreach (Text val in array)
			{
				Transform val2 = ((Component)val).transform.parent.Find("KeybindOverlay");
				if (Object.op_Implicit((Object)(object)val2))
				{
					Object.Destroy((Object)(object)val2);
				}
			}
		}

		private void CheckSlot(Text title, KeyCode code, int slot)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Invalid comparison between Unknown and I4
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			Transform parent = ((Component)title).transform.parent;
			Transform val = parent.Find("KeybindOverlay");
			bool flag = IsEnabled() && (int)code > 0;
			if (Object.op_Implicit((Object)(object)val))
			{
				if (flag)
				{
					Text component = ((Component)val).GetComponent<Text>();
					component.text = "[ " + KeyOverlay.KeyCodeToString(code) + " ]";
				}
				else
				{
					Object.Destroy((Object)(object)val);
				}
			}
			else if (flag)
			{
				KeyOverlay.ConfigureTextObject(Object.Instantiate<Transform>(((Component)title).transform, parent), KeyOverlay.KeyCodeToString(code), Color.black);
				Feature.Logger.LogDebug((object)$"Upgrade card key overlay created for slot {slot}");
			}
		}
	}
}
namespace SlotKeybindsPlugin.features.Banish
{
	public static class BanishInterop
	{
		public static void BanishCard(int slot)
		{
			Button banishButton = GetBanishButton(slot);
			if (!Object.op_Implicit((Object)(object)banishButton))
			{
				Plugin.Logger.LogWarning((object)$"No banish button found for slot {slot}!");
				return;
			}
			if (banishButton != null)
			{
				((UnityEvent)banishButton.onClick).Invoke();
			}
			Plugin.Logger.LogWarning((object)$"Banished card slot {slot}");
		}

		private static Button? GetBanishButton(int slot)
		{
			GameObject? cardHolder = Game.GetCardHolder(slot);
			object result;
			if (cardHolder == null)
			{
				result = null;
			}
			else
			{
				GameObject obj = cardHolder.transform.FindChildByName("BanishButton", recursive: true);
				result = ((obj != null) ? obj.GetComponent<Button>() : null);
			}
			return (Button?)result;
		}
	}
	public class BanishUpgradeCard : Feature
	{
		public override bool IsEnabled()
		{
			return base.IsEnabled() && Plugin.Instance.UpgradeCardSelect.Value && Plugin.Instance.BanishEnabled.Value && Plugin.Instance.BanishPluginPresent;
		}

		public bool Banish(int slot)
		{
			if (!IsEnabled())
			{
				return false;
			}
			BanishInterop.BanishCard(slot);
			Plugin.Instance.BanishColorsFeature.SetBanishColors();
			return true;
		}
	}
}
namespace SlotKeybindsPlugin.features.BanishColors
{
	public class BanishColors : Feature
	{
		private static readonly Color DefaultCardColor = new Color(1f, 1f, 1f, 1f);

		public override bool IsEnabled()
		{
			return base.IsEnabled() && Plugin.Instance.BanishEnabled.Value && Plugin.Instance.BanishColorsEnabled.Value;
		}

		public override void OnUpdate()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Invalid comparison between Unknown and I4
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			KeyCode value = Plugin.Instance.BanishKey.Value;
			if ((int)value != 0)
			{
				if (Input.GetKeyDown(value))
				{
					TriggerBanishColors(1);
				}
				if (Input.GetKeyUp(value))
				{
					RestoreCardColors(1);
				}
			}
		}

		public void SetBanishColors()
		{
			//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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Invalid comparison between Unknown and I4
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			if (IsEnabled())
			{
				KeyCode value = Plugin.Instance.BanishKey.Value;
				if ((int)value != 0 && Input.GetKey(value))
				{
					TriggerBanishColors(0);
				}
			}
		}

		public override void OnDestroy()
		{
			RestoreCardColors(0);
		}

		private void TriggerBanishColors(int duration)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			if (IsEnabled())
			{
				Image[] cardImages = Game.GetCardImages();
				Image[] array = cardImages;
				foreach (Image val in array)
				{
					((Graphic)val).CrossFadeColor(Plugin.Instance.BanishColor.Value, (float)duration, false, true);
				}
			}
		}

		private void RestoreCardColors(int duration)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			Image[] cardImages = Game.GetCardImages();
			Image[] array = cardImages;
			foreach (Image val in array)
			{
				((Graphic)val).CrossFadeColor(DefaultCardColor, (float)duration, false, true);
			}
		}
	}
}