Decompiled source of MonsterCard and InfiniteEnchantment v1.1.2

plugins/ATO_mod_pch.dll

Decompiled 4 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using TMPro;
using UnityEngine;
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: AssemblyTitle("ATO_mod_pch")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ATO_mod_pch")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("7c86a674-d42a-4931-a5cc-103cb2fc2136")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ATO_mod_pch;

[BepInPlugin("me.pxh1998.plugin.ato", "ATO_mod_pch", "1.0.0")]
public class ATO_mod_pch : BaseUnityPlugin
{
	public class CastCardState
	{
		public int CastCardState_AddCard;

		public string CastCardState_AddCardId;
	}

	public static Harmony Harmony = new Harmony("me.pxh1998.plugin.ftk");

	public static ATO_mod_pch Instance;

	public static bool isNpcCard = false;

	public static string heroClass = string.Empty;

	public static CastCardState SaveCastCardState = new CastCardState
	{
		CastCardState_AddCard = 0,
		CastCardState_AddCardId = ""
	};

	public static Transform targetTransform_pxh;

	public static bool castIsHeroToNpc_pxh;

	public static List<string> addCardIDList = new List<string>();

	public static List<string> KillNpcChooseCardList = new List<string>();

	public static Coroutine OpenAddCardWindowCoroutine;

	public static bool isCoroutine = false;

	public static int killNpcAddChooseNum = 3;

	public static int maxNumOfSelectCard = 1;

	private void Awake()
	{
		Debug.developerConsoleEnabled = true;
		Debug.LogError((object)"I am an Error");
		Harmony.PatchAll();
		Debug.Log((object)("Hello, world! " + Application.unityVersion));
		Instance = this;
	}

	private void Start()
	{
	}

	private void Update()
	{
		KeyboardShortcut val = default(KeyboardShortcut);
		((KeyboardShortcut)(ref val))..ctor((KeyCode)290, Array.Empty<KeyCode>());
		if (((KeyboardShortcut)(ref val)).IsDown())
		{
			Debug.Log((object)"当你看到这条消息时,表示按下了F9");
		}
	}

	private void OnDestroy()
	{
	}
}
public class PxhToolsClass
{
	public static IEnumerable<int> GenerateNoDuplicateRandom(int minValue, int maxValue)
	{
		return from g in Enumerable.Range(minValue, maxValue)
			orderby Guid.NewGuid()
			select g;
	}

	public static int[] FisherYates(int min, int max, int count)
	{
		int num = max - min + 1;
		int[] array = new int[num];
		Random random = new Random();
		if (count > max - min + 1)
		{
			count = max - min + 1;
		}
		if (count < 0)
		{
			count = 0;
		}
		for (int i = 0; i < num; i++)
		{
			array[i] = min + i;
		}
		for (int j = 0; j < count; j++)
		{
			int num2 = random.Next(j, num);
			ref int reference = ref array[j];
			ref int reference2 = ref array[num2];
			int num3 = array[num2];
			int num4 = array[j];
			reference = num3;
			reference2 = num4;
		}
		int[] array2 = new int[count];
		Array.Copy(array, array2, count);
		return array2;
	}

	public Hero GetRandomHero(Hero[] arr)
	{
		Random random = new Random();
		int num = random.Next(arr.Length - 1);
		return arr[num];
	}
}
[HarmonyPatch(typeof(Character), "GetEnergyTurn")]
public class Character_GetEnergyTurn_Patch
{
	[HarmonyPrefix]
	public static bool Character_GetEnergyTurn_Prefix(Character __instance, ref int __result)
	{
		int num = __instance.GetAuraStatModifiers(__instance.EnergyTurn, (CharacterStat)3) + __instance.GetItemStatModifiers((CharacterStat)4);
		if (num < 0)
		{
			num = 0;
		}
		__result = num;
		return false;
	}
}
[HarmonyPatch(typeof(CardData), "SetTarget")]
public class CardData_SetTarget_Patch_Pre
{
	[HarmonyPrefix]
	public static bool CardData_SetTarget_Patch_Prefix()
	{
		return true;
	}
}
[HarmonyPatch(typeof(MatchManager), "GetCardData")]
public class MatchManager_GetCardData_Patch_Post
{
	[HarmonyPostfix]
	public static void MatchManager_GetCardData_Patch_Postfix(Globals __instance, ref CardData __result)
	{
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Invalid comparison between Unknown and I4
		Traverse val = Traverse.Create((object)__instance);
		Hero value = val.Field("theHero").GetValue<Hero>();
		int value2 = val.Field("heroActive").GetValue<int>();
		if ((Object)(object)__result != (Object)null && value != null && (int)__result.CardClass == 5)
		{
			CardItem_SetCard_Patch.addTagFromHero(value, ref __result);
		}
		if (!((Object)(object)__result != (Object)null))
		{
			return;
		}
		foreach (string addCardID in ATO_mod_pch.addCardIDList)
		{
			if (__result.Id.Contains(addCardID))
			{
				__result.Corrupted = true;
				Debug.Log((object)("[MatchManager_GetCardData_Patch_Postfix]常显的卡牌ID: " + __result.Id));
			}
		}
	}
}
[HarmonyPatch(typeof(Globals), "GetCardData")]
public class Globals_GetCardData_Patch_Pre
{
	[HarmonyPrefix]
	public static bool Globals_GetCardData_Patch_Prefix(Globals __instance, string id, bool instantiate = true)
	{
		return true;
	}
}
[HarmonyPatch(typeof(Globals), "GetCardData")]
public class Globals_GetCardData_Patch_Post
{
	[HarmonyPostfix]
	public static void Globals_GetCardData_Patch_Postfix(Globals __instance, ref CardData __result)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)__result != (Object)null)
		{
			string text = Enum.GetName(typeof(CardClass), __result.CardClass).ToLower();
			if ((Object)(object)__result.ItemEnchantment != (Object)null && text != "monster" && __result.ItemEnchantment.DestroyAfterUses >= 3)
			{
				__result.ItemEnchantment.DestroyAfterUses = 77;
			}
			if ((Object)(object)__result.ItemEnchantment != (Object)null && text != "monster" && __result.ItemEnchantment.DestroyAfterUses < 3 && __result.ItemEnchantment.DestroyAfterUses > 0)
			{
				__result.ItemEnchantment.DestroyAfterUses = 0;
				__result.ItemEnchantment.TimesPerTurn = 3;
			}
			if ((Object)(object)__result.ItemEnchantment != (Object)null && text != "monster" && (__result.ItemEnchantment.DestroyStartOfTurn || (__result.ItemEnchantment.DestroyEndOfTurn && __result.ItemEnchantment.DestroyAfterUses == 0)))
			{
				__result.ItemEnchantment.DestroyEndOfTurn = false;
				__result.ItemEnchantment.DestroyStartOfTurn = false;
			}
			if (ATO_mod_pch.isNpcCard)
			{
				Debug.Log((object)("[Globals][GetCardData]卡牌target : " + __result.Target + " 卡牌ID Name: " + __result.Id + " " + __result.CardName));
				__result.Playable = true;
			}
			if (text == "monster")
			{
				__result.Playable = true;
			}
		}
	}
}
[HarmonyPatch(typeof(Item), "DoItem")]
public class Item_DoItem_Patch_Pre
{
	[HarmonyPrefix]
	public static bool Item_DoItem_Patch_Prefix(Item __instance, ref CardData _cardData, Character _character, Character _target)
	{
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Invalid comparison between Unknown and I4
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Invalid comparison between Unknown and I4
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Invalid comparison between Unknown and I4
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Invalid comparison between Unknown and I4
		//IL_0215: Unknown result type (might be due to invalid IL or missing references)
		//IL_021c: Invalid comparison between Unknown and I4
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Invalid comparison between Unknown and I4
		//IL_0220: Unknown result type (might be due to invalid IL or missing references)
		//IL_0226: Invalid comparison between Unknown and I4
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_016e: Invalid comparison between Unknown and I4
		//IL_025f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0266: Invalid comparison between Unknown and I4
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: Invalid comparison between Unknown and I4
		//IL_026a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0270: Invalid comparison between Unknown and I4
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bb: Invalid comparison between Unknown and I4
		if (_character != null)
		{
			Debug.Log((object)("[Item_DoItem_Patch_Prefix] _character来源为: " + _character.GameName + _character.SourceName));
		}
		if (_target != null)
		{
			Debug.Log((object)("[Item_DoItem_Patch_Prefix] _target目标为: " + _target.GameName + _target.SourceName));
		}
		if ((Object)(object)_cardData.Item == (Object)null)
		{
			string text = JsonUtility.ToJson((object)_cardData);
			CardData val = ScriptableObject.CreateInstance<CardData>();
			JsonUtility.FromJsonOverwrite(text, (object)val);
			string text2 = JsonUtility.ToJson((object)val.ItemEnchantment);
			ItemData val2 = ScriptableObject.CreateInstance<ItemData>();
			JsonUtility.FromJsonOverwrite(text2, (object)val2);
			val.ItemEnchantment = val2;
			if ((int)val.CardClass == 5 && (Object)(object)val.ItemEnchantment != (Object)null && (int)val.CardType != 27)
			{
				if (_character != null && _character.IsHero)
				{
					if ((int)Globals.Instance.GetItemData(val.Id).ItemTarget == 3 && (int)val.ItemEnchantment.ItemTarget != 4)
					{
						val.ItemEnchantment.ItemTarget = (ItemTarget)4;
						Debug.Log((object)("[Item_DoItem_Patch_Prefix]群体减益效果目标修改 目标: 全体英雄 -> 全体怪物 卡牌: " + val.Id));
					}
					if ((int)Globals.Instance.GetItemData(val.Id).ItemTarget == 4 && (int)val.ItemEnchantment.ItemTarget != 3)
					{
						val.ItemEnchantment.ItemTarget = (ItemTarget)3;
						Debug.Log((object)("[Item_DoItem_Patch_Prefix]群体增益效果目标修改 目标: 全体怪物 -> 全体英雄 卡牌: " + val.Id));
					}
					if ((int)val.ItemEnchantment.ItemTarget == 10 && (int)val.TargetType != 1)
					{
						val.ItemEnchantment.ItemTarget = (ItemTarget)8;
						Debug.Log((object)("[Item_DoItem_Patch_Prefix]单体附魔目标增益修改. 目标: 生命值最低怪物 -> 英雄 卡牌: " + val.Id));
					}
					_cardData = val;
				}
				if (_character != null && !_character.IsHero)
				{
					if ((int)val.ItemEnchantment.ItemTarget == 10 && (int)val.TargetType == 1)
					{
						val.ItemEnchantment.ItemTarget = (ItemTarget)8;
						Debug.Log((object)("[Item_DoItem_Patch_Prefix]群体附魔目标增益修改. 目标: 生命值最低怪物 -> 英雄 卡牌: " + val.Id));
					}
					if ((int)val.ItemEnchantment.ItemTarget == 9 && (int)val.TargetType == 1)
					{
						val.ItemEnchantment.ItemTarget = (ItemTarget)7;
						Debug.Log((object)("[Item_DoItem_Patch_Prefix]群体附魔目标增益修改. 目标: 生命值最高怪物 -> 英雄 卡牌: " + val.Id));
					}
					_cardData = val;
				}
			}
			return true;
		}
		return true;
	}
}
[HarmonyPatch(typeof(CardItem), "SetCard")]
public class CardItem_SetCard_Patch
{
	[HarmonyPostfix]
	public static void CardItem_SetCard_Patch_Postfix(CardItem __instance, string id, Hero _theHero, NPC _theNPC, bool GetFromGlobal)
	{
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Invalid comparison between Unknown and I4
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Invalid comparison between Unknown and I4
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Invalid comparison between Unknown and I4
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Invalid comparison between Unknown and I4
		//IL_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0211: Invalid comparison between Unknown and I4
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: 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_01c7: 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_0241: Invalid comparison between Unknown and I4
		//IL_026d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0273: Invalid comparison between Unknown and I4
		//IL_0292: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_030d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0312: Unknown result type (might be due to invalid IL or missing references)
		if (ATO_mod_pch.isCoroutine)
		{
			return;
		}
		Traverse val = Traverse.Create((object)__instance);
		CardData cardData = val.Field("cardData").GetValue<CardData>();
		TMP_Text typeTextTM = val.Field("typeTextTM").GetValue<TMP_Text>();
		TMP_Text value = val.Field("requireTextTM").GetValue<TMP_Text>();
		TMP_Text value2 = val.Field("targetTextTM").GetValue<TMP_Text>();
		if (!((Object)(object)cardData != (Object)null))
		{
			return;
		}
		if ((Object)(object)value != (Object)null)
		{
		}
		if (_theHero != null && (int)cardData.CardClass == 5)
		{
			string target = cardData.Target;
			cardData.Target = target.Replace("英雄", "怪物");
			cardData.Playable = true;
			if ((Object)(object)value2 != (Object)null)
			{
				target = value2.text;
				if ((int)cardData.TargetSide == 0)
				{
					value2.text = target.Replace("英雄", "怪物");
				}
				if ((int)cardData.TargetSide == 1 || (int)cardData.TargetSide == 4)
				{
					value2.text = target.Replace("怪物", "英雄");
				}
			}
		}
		HeroClass heroClass;
		CardClass cardClass;
		if ((Object)(object)value2 != (Object)null && ATO_mod_pch.isNpcCard)
		{
			Debug.Log((object)("[SetCard.targetTextTM]测试文本: " + value2.text));
			if (_theHero != null)
			{
				string[] obj = new string[10] { "[SetCard.addTagFromHero]测试文本:  英雄职业: ", null, null, null, null, null, null, null, null, null };
				heroClass = ((Character)_theHero).HeroData.HeroClass;
				obj[1] = ((object)(HeroClass)(ref heroClass)).ToString();
				obj[2] = " 卡牌ID: ";
				obj[3] = cardData.Id;
				obj[4] = " 卡牌职业: ";
				cardClass = cardData.CardClass;
				obj[5] = ((object)(CardClass)(ref cardClass)).ToString();
				obj[6] = " 英雄ID: ";
				obj[7] = ((Character)_theHero).Id;
				obj[8] = " 英雄名字: ";
				obj[9] = ((Character)_theHero).SourceName;
				Debug.Log((object)string.Concat(obj));
			}
		}
		if (_theHero != null && (int)cardData.CardClass == 5)
		{
			cardData.Playable = true;
			addEnergyCostFromRarity(_theHero, ref cardData);
			__instance.DrawEnergyCost(true);
		}
		if (_theHero != null && (int)cardData.CardClass == 5)
		{
			addTagFromHero(_theHero, ref cardData);
			((Component)__instance.typeText).gameObject.SetActive(true);
		}
		if (_theHero != null && (int)cardData.CardClass == 5 && Enum.IsDefined(typeof(CardClass), (object)(CardClass)((Character)_theHero).HeroData.HeroClass))
		{
			cardData.CardClass = (CardClass)((Character)_theHero).HeroData.HeroClass;
			string[] obj2 = new string[7] { "[SetCard]测试文本:  将怪物卡: ", cardData.Id, cardData.CardName, " 转换为英雄职业卡: ", null, null, null };
			heroClass = ((Character)_theHero).HeroData.HeroClass;
			obj2[4] = ((object)(HeroClass)(ref heroClass)).ToString();
			obj2[5] = " 卡牌职业为: ";
			cardClass = cardData.CardClass;
			obj2[6] = ((object)(CardClass)(ref cardClass)).ToString();
			Debug.Log((object)string.Concat(obj2));
		}
		addCardTagDisplay(cardData, ref typeTextTM, ref __instance);
	}

	public static void addCardTagDisplay(CardData cardData, ref TMP_Text typeTextTM, ref CardItem cardItemInstance)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Invalid comparison between Unknown and I4
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_0371: Unknown result type (might be due to invalid IL or missing references)
		//IL_023c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0335: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_027b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_0562: Unknown result type (might be due to invalid IL or missing references)
		//IL_06f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_05d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0689: Unknown result type (might be due to invalid IL or missing references)
		//IL_0527: Unknown result type (might be due to invalid IL or missing references)
		//IL_06c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_064e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0613: Unknown result type (might be due to invalid IL or missing references)
		//IL_059d: Unknown result type (might be due to invalid IL or missing references)
		string text = Enum.GetName(typeof(CardType), cardData.CardType).ToLower();
		if ((int)cardData.CardType != 0 && (int)cardData.CardClass != 8)
		{
			StringBuilder stringBuilder = new StringBuilder();
			switch (text)
			{
			default:
				stringBuilder.Append(string.Format(" <size=-.2>[</size><size=-.2>{0}</size> <size=-.2>]</size>", Texts.Instance.GetText(Enum.GetName(typeof(CardType), cardData.CardType), "")));
				break;
			case "cold_spell":
				stringBuilder.Append(string.Format(" <size=-.2>[</size><size=-.2><color=#00FFFF>{0}</color></size> <size=-.2>]</size>", Texts.Instance.GetText(Enum.GetName(typeof(CardType), cardData.CardType), "")));
				break;
			case "fire_spell":
				stringBuilder.Append(string.Format(" <size=-.2>[</size><size=-.2><color=red>{0}</color></size> <size=-.2>]</size>", Texts.Instance.GetText(Enum.GetName(typeof(CardType), cardData.CardType), "")));
				break;
			case "lightning_spell":
				stringBuilder.Append(string.Format(" <size=-.2>[</size><size=-.2><color=#FFFF66>{0}</color></size> <size=-.2>]</size>", Texts.Instance.GetText(Enum.GetName(typeof(CardType), cardData.CardType), "")));
				break;
			case "mind_spell":
				stringBuilder.Append(string.Format(" <size=-.2>[</size><size=-.2><color=#FF66B2>{0}</color></size> <size=-.2>]</size>", Texts.Instance.GetText(Enum.GetName(typeof(CardType), cardData.CardType), "")));
				break;
			case "shadow_spell":
				stringBuilder.Append(string.Format(" <size=-.2>[</size><size=-.2><color=#000000>{0}</color></size> <size=-.2>]</size>", Texts.Instance.GetText(Enum.GetName(typeof(CardType), cardData.CardType), "")));
				break;
			case "holy_spell":
				stringBuilder.Append(string.Format(" <size=-.2>[</size><size=-.2><color=#FFFF99>{0}</color></size> <size=-.2>]</size>", Texts.Instance.GetText(Enum.GetName(typeof(CardType), cardData.CardType), "")));
				break;
			case "curse_spell":
				stringBuilder.Append(string.Format(" <size=-.2>[</size><size=-.2><color=#B266FF>{0}</color></size> <size=-.2>]</size>", Texts.Instance.GetText(Enum.GetName(typeof(CardType), cardData.CardType), "")));
				break;
			case "healing_spell":
				stringBuilder.Append(string.Format(" <size=-.2>[</size><size=-.2><color=#00FF00>{0}</color></size> <size=-.2>]</size>", Texts.Instance.GetText(Enum.GetName(typeof(CardType), cardData.CardType), "")));
				break;
			}
			if (cardData.CardTypeAux.Length != 0)
			{
				CardType[] cardTypeAux = cardData.CardTypeAux;
				foreach (CardType val in cardTypeAux)
				{
					switch (Enum.GetName(typeof(CardType), val).ToLower())
					{
					default:
						stringBuilder.Append(string.Format(" <size=-.2>[</size><size=-.2>{0}</size> <size=-.2>]</size>", Texts.Instance.GetText(Enum.GetName(typeof(CardType), val), "")));
						break;
					case "cold_spell":
						stringBuilder.Append(string.Format(" <size=-.2>[</size><size=-.2><color=#00FFFF>{0}</color></size> <size=-.2>]</size>", Texts.Instance.GetText(Enum.GetName(typeof(CardType), val), "")));
						break;
					case "fire_spell":
						stringBuilder.Append(string.Format(" <size=-.2>[</size><size=-.2><color=red>{0}</color></size> <size=-.2>]</size>", Texts.Instance.GetText(Enum.GetName(typeof(CardType), val), "")));
						break;
					case "lightning_spell":
						stringBuilder.Append(string.Format(" <size=-.2>[</size><size=-.2><color=#FFFF66>{0}</color></size> <size=-.2>]</size>", Texts.Instance.GetText(Enum.GetName(typeof(CardType), val), "")));
						break;
					case "mind_spell":
						stringBuilder.Append(string.Format(" <size=-.2>[</size><size=-.2><color=#FF66B2>{0}</color></size> <size=-.2>]</size>", Texts.Instance.GetText(Enum.GetName(typeof(CardType), val), "")));
						break;
					case "shadow_spell":
						stringBuilder.Append(string.Format(" <size=-.2>[</size><size=-.2><color=#000000>{0}</color></size> <size=-.2>]</size>", Texts.Instance.GetText(Enum.GetName(typeof(CardType), val), "")));
						break;
					case "holy_spell":
						stringBuilder.Append(string.Format(" <size=-.2>[</size><size=-.2><color=#FFFF99>{0}</color></size> <size=-.2>]</size>", Texts.Instance.GetText(Enum.GetName(typeof(CardType), val), "")));
						break;
					case "curse_spell":
						stringBuilder.Append(string.Format(" <size=-.2>[</size><size=-.2><color=#B266FF>{0}</color></size> <size=-.2>]</size>", Texts.Instance.GetText(Enum.GetName(typeof(CardType), val), "")));
						break;
					case "healing_spell":
						stringBuilder.Append(string.Format(" <size=-.2>[</size><size=-.2><color=#00FF00>{0}</color></size> <size=-.2>]</size>", Texts.Instance.GetText(Enum.GetName(typeof(CardType), val), "")));
						break;
					}
				}
			}
			if (stringBuilder != null && (Object)(object)typeTextTM != (Object)null)
			{
				typeTextTM.text = stringBuilder.ToString();
				((Component)cardItemInstance.typeTextImage).gameObject.SetActive(true);
			}
		}
		else
		{
			typeTextTM.text = "";
		}
	}

	public static void addEnergyCostFromRarity(Hero theHero, ref CardData cardData)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Invalid comparison between Unknown and I4
		//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_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_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Expected I4, but got Unknown
		if ((int)cardData.CardType == 28)
		{
			return;
		}
		CardRarity cardRarity = cardData.CardRarity;
		CardRarity val = cardRarity;
		switch ((int)val)
		{
		case 0:
			cardData.EnergyCost = 0;
			cardData.EnergyCostOriginal = 0;
			break;
		case 1:
			cardData.EnergyCost = 1;
			cardData.EnergyCostOriginal = 1;
			if (cardData.Vanish)
			{
				cardData.EnergyCost = 0;
				cardData.EnergyCostOriginal = 0;
			}
			break;
		case 2:
			cardData.EnergyCost = 1;
			cardData.EnergyCostOriginal = 1;
			break;
		case 3:
			cardData.EnergyCost = 2;
			cardData.EnergyCostOriginal = 2;
			break;
		case 4:
			cardData.EnergyCost = 3;
			cardData.EnergyCostOriginal = 3;
			break;
		}
	}

	public static void addTagFromHero(Hero theHero, ref CardData cardData)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Invalid comparison between Unknown and I4
		//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a7: Invalid comparison between Unknown and I4
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: 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_01c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Expected I4, but got Unknown
		if ((int)cardData.CardType == 28)
		{
			return;
		}
		bool flag = false;
		if (((Character)theHero).Id.Contains("warden"))
		{
			flag = true;
			cardData.CardType = (CardType)1;
			cardData.CardTypeAux = (CardType[])(object)new CardType[3];
			cardData.CardTypeAux[0] = (CardType)19;
			cardData.CardTypeAux[1] = (CardType)4;
			cardData.CardTypeAux[2] = (CardType)16;
		}
		else if (((Character)theHero).Id.Contains("minstrel"))
		{
			flag = true;
			cardData.CardType = (CardType)2;
			cardData.CardTypeAux = (CardType[])(object)new CardType[4];
			cardData.CardTypeAux[0] = (CardType)19;
			cardData.CardTypeAux[1] = (CardType)14;
			cardData.CardTypeAux[2] = (CardType)15;
			cardData.CardTypeAux[3] = (CardType)20;
		}
		else if (((Character)theHero).Id.Contains("warlock"))
		{
			flag = true;
			cardData.CardType = (CardType)6;
			cardData.CardTypeAux = (CardType[])(object)new CardType[4];
			cardData.CardTypeAux[0] = (CardType)20;
			cardData.CardTypeAux[1] = (CardType)9;
			cardData.CardTypeAux[2] = (CardType)11;
			cardData.CardTypeAux[3] = (CardType)13;
		}
		else if (((Character)theHero).Id.Contains("alchemist"))
		{
			flag = true;
			cardData.CardType = (CardType)12;
			cardData.CardTypeAux = (CardType[])(object)new CardType[4];
			cardData.CardTypeAux[0] = (CardType)20;
			cardData.CardTypeAux[1] = (CardType)4;
			cardData.CardTypeAux[2] = (CardType)16;
			cardData.CardTypeAux[3] = (CardType)30;
		}
		if (!flag && (int)((Character)theHero).HeroData.HeroSubClass.HeroClassSecondary == 6)
		{
			HeroClass heroClass = ((Character)theHero).HeroData.HeroClass;
			HeroClass val = heroClass;
			switch ((int)val)
			{
			case 0:
				cardData.CardType = (CardType)1;
				cardData.CardTypeAux = (CardType[])(object)new CardType[3];
				cardData.CardTypeAux[0] = (CardType)19;
				cardData.CardTypeAux[1] = (CardType)4;
				cardData.CardTypeAux[2] = (CardType)16;
				break;
			case 3:
				cardData.CardType = (CardType)2;
				cardData.CardTypeAux = (CardType[])(object)new CardType[3];
				cardData.CardTypeAux[0] = (CardType)19;
				cardData.CardTypeAux[1] = (CardType)14;
				cardData.CardTypeAux[2] = (CardType)16;
				break;
			case 1:
				cardData.CardType = (CardType)6;
				cardData.CardTypeAux = (CardType[])(object)new CardType[4];
				cardData.CardTypeAux[0] = (CardType)13;
				cardData.CardTypeAux[1] = (CardType)5;
				cardData.CardTypeAux[2] = (CardType)7;
				cardData.CardTypeAux[3] = (CardType)20;
				break;
			case 2:
				cardData.CardType = (CardType)12;
				cardData.CardTypeAux = (CardType[])(object)new CardType[4];
				cardData.CardTypeAux[0] = (CardType)20;
				cardData.CardTypeAux[1] = (CardType)4;
				cardData.CardTypeAux[2] = (CardType)16;
				cardData.CardTypeAux[3] = (CardType)10;
				break;
			}
		}
	}

	public static void SpecialCardEnchantmentRules(Hero theHero, ref CardData cardData)
	{
	}
}
[HarmonyPatch(typeof(Globals), "GetItemData")]
public class Globals_GetItemData_Patch_Pre
{
	[HarmonyPrefix]
	public static bool Globals_GetItemData_Patch_Prefix(Globals __instance, string id, ref ItemData __result)
	{
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Invalid comparison between Unknown and I4
		Traverse val = Traverse.Create((object)__instance);
		Dictionary<string, ItemData> value = val.Field("_ItemDataSource").GetValue<Dictionary<string, ItemData>>();
		if (value != null && value.ContainsKey(id))
		{
			__result = value[id];
			if ((Object)(object)__instance.GetCardData(__result.Id, false) != (Object)null && (int)__instance.GetCardData(__result.Id, false).CardClass != 5 && __result.IsEnchantment)
			{
				__result.DestroyEndOfTurn = false;
				__result.DestroyStartOfTurn = false;
			}
			return false;
		}
		__result = null;
		return false;
	}
}
[HarmonyPatch(typeof(Character), "BeginTurn")]
public class Character_Character_Patch_Post
{
	[HarmonyPostfix]
	public static void Character_Character_Patch_Postfix(Character __instance)
	{
		if (ATO_mod_pch.KillNpcChooseCardList.Count > 0)
		{
			ATO_mod_pch.KillNpcChooseCardList.Clear();
		}
		if (ATO_mod_pch.maxNumOfSelectCard != 1)
		{
			ATO_mod_pch.maxNumOfSelectCard = 1;
		}
		Traverse val = Traverse.Create((object)__instance);
		string value = val.Field("enchantment").GetValue<string>();
		string value2 = val.Field("enchantment2").GetValue<string>();
		string value3 = val.Field("enchantment3").GetValue<string>();
		for (int i = 0; i < 3; i++)
		{
			switch (i)
			{
			case 0:
			{
				ItemData itemData2 = Globals.Instance.GetItemData(value);
				if ((Object)(object)itemData2 != (Object)null)
				{
					Debug.Log((object)("角色: " + __instance.Id + " 身上的附魔1为: " + value));
				}
				break;
			}
			case 1:
			{
				ItemData itemData3 = Globals.Instance.GetItemData(value2);
				if ((Object)(object)itemData3 != (Object)null)
				{
					Debug.Log((object)("角色: " + __instance.Id + " 身上的附魔2为: " + value2));
				}
				break;
			}
			case 2:
			{
				ItemData itemData = Globals.Instance.GetItemData(value3);
				if ((Object)(object)itemData != (Object)null)
				{
					Debug.Log((object)("角色: " + __instance.Id + " 身上的附魔3为: " + value3));
				}
				break;
			}
			}
		}
	}
}
[HarmonyPatch(typeof(ItemCombatIcon), "SetTimesExecuted")]
public class ItemCombatIcon_SetTimesExecuted_Patch
{
	[HarmonyPrefix]
	public static bool ItemCombatIcon_SetTimesExecuted_Prefix(ref ItemCombatIcon __instance, int times, bool doAnim = true)
	{
		return true;
	}
}
[HarmonyPatch(typeof(MatchManager), "FinishCombat")]
public class MatchManager_FinishCombat_Patch : MonoBehaviour
{
	private static Coroutine waitFinishCombatCoroutine;

	[HarmonyPrefix]
	public static bool MatchManager_FinishCombat_Patch_Prefix(MatchManager __instance)
	{
		if (ATO_mod_pch.OpenAddCardWindowCoroutine != null || ATO_mod_pch.isCoroutine)
		{
			if (!ATO_mod_pch.isCoroutine)
			{
				return true;
			}
			if (waitFinishCombatCoroutine == null)
			{
				Debug.Log((object)"[MatchManager_FinishCombat_Patch_Prefix] 协程方法触发");
				waitFinishCombatCoroutine = ((MonoBehaviour)__instance).StartCoroutine(waitFinishCombatCo(__instance));
			}
			return false;
		}
		return true;
	}

	public static IEnumerator waitFinishCombatCo(MatchManager __instance)
	{
		while (ATO_mod_pch.OpenAddCardWindowCoroutine != null && ATO_mod_pch.isCoroutine)
		{
			yield return Globals.Instance.WaitForSeconds(0.5f);
		}
		ATO_mod_pch.isCoroutine = false;
		Debug.Log((object)("[MatchManager_FinishCombat_Patch_Prefix] FinishCombat方法触发 MatchIsOver: " + __instance.MatchIsOver + " 存活英雄: " + __instance.AnyHeroAlive()));
		MatchManager.Instance.FinishCombat();
	}
}
[HarmonyPatch(typeof(MatchManager), "KillNPC")]
public class MatchManager_KillNPC_Patch : MonoBehaviour
{
	private static Coroutine runningCoroutine;

	[HarmonyPrefix]
	public static bool MatchManager_KillNPC_Patch_Prefix(MatchManager __instance, NPC _npc)
	{
		Debug.Log((object)"MatchManager_KillNPC_Patch_Prefix 方法触发");
		if ((Object)(object)__instance != (Object)null)
		{
			Debug.Log((object)"MatchManager_KillNPC_Patch_Prefix 判断1触发");
			Traverse val = Traverse.Create((object)__instance);
			int value = val.Field("heroActive").GetValue<int>();
			Hero[] value2 = val.Field("TeamHero").GetValue<Hero[]>();
			string value3 = val.Field("gameStatus").GetValue<string>();
			int count = ((Character)_npc).Cards.Count;
			if (_npc != null && !((Character)_npc).IsHero && !((Character)_npc).Alive && count > 0)
			{
				KillNpcGiveCard(value, value2, _npc, count, value3);
			}
		}
		return true;
	}

	public static void KillNpcGiveCard(int heroActive, Hero[] TeamHero, NPC _npc, int npcCardNum, string gameStatus)
	{
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Invalid comparison between Unknown and I4
		ATO_mod_pch.isCoroutine = false;
		Traverse val = Traverse.Create((object)MatchManager.Instance);
		Random random = new Random();
		Random random2 = new Random();
		List<int> list = new List<int>();
		bool flag = true;
		bool flag2 = false;
		Hero hero = MatchManager.Instance.GetHero(heroActive);
		if (hero != null && heroActive != -1 && ((Character)hero).Alive && hero == TeamHero[heroActive])
		{
			Debug.Log((object)("[MatchManager_KillNPC_Patch_Prefix][KillNpcGiveCard] 英雄回合击杀触发, 英雄Index: " + heroActive));
			flag = false;
			ATO_mod_pch.heroClass = ((Character)hero).ClassName;
			ATO_mod_pch.isNpcCard = true;
			for (int i = 0; i < npcCardNum; i++)
			{
				if ((int)Globals.Instance.GetCardData(((Character)_npc).Cards[i], false).CardType == 28 || (Object)(object)Globals.Instance.GetCardData(((Character)_npc).Cards[i], false).ItemEnchantment != (Object)null)
				{
					list.Add(i);
				}
			}
			int index;
			if (list.Count > 0)
			{
				index = list[random.Next(0, list.Count)];
				ATO_mod_pch.KillNpcChooseCardList.Add(((Character)_npc).Cards[index]);
				Debug.Log((object)"[MatchManager_KillNPC_Patch_Prefix][KillNpcGiveCard] 怪物有附魔卡触发");
			}
			else
			{
				index = random.Next(0, npcCardNum);
			}
			if (MatchManager.Instance.NumNPCsAlive() != 100)
			{
				if (_npc.NPCIsBoss())
				{
					ATO_mod_pch.maxNumOfSelectCard = 2;
					ATO_mod_pch.KillNpcChooseCardList.Add(((Character)_npc).Cards[random.Next(0, npcCardNum)]);
				}
				Debug.Log((object)("[MatchManager_KillNPC_Patch_Prefix][KillNpcGiveCard]回合状态码: " + gameStatus + " NPC存活数: " + MatchManager.Instance.NumNPCsAlive()));
				if (ATO_mod_pch.killNpcAddChooseNum <= ((Character)_npc).Cards.Count)
				{
					Debug.Log((object)"[MatchManager_KillNPC_Patch_Prefix][KillNpcGiveCard]不重复的怪物卡池");
					int[] array = PxhToolsClass.FisherYates(0, ATO_mod_pch.killNpcAddChooseNum - 1, ATO_mod_pch.killNpcAddChooseNum);
					int[] array2 = array;
					foreach (int index2 in array2)
					{
						ATO_mod_pch.KillNpcChooseCardList.Add(((Character)_npc).Cards[index2]);
					}
				}
				else
				{
					Debug.Log((object)"[MatchManager_KillNPC_Patch_Prefix][KillNpcGiveCard]可重复的怪物卡池");
					for (int k = 0; k < ATO_mod_pch.killNpcAddChooseNum; k++)
					{
						ATO_mod_pch.KillNpcChooseCardList.Add(((Character)_npc).Cards[random.Next(0, npcCardNum)]);
					}
				}
				if (val.Field("waitingForAddcardAssignment").GetValue<bool>() && runningCoroutine != null)
				{
					((MonoBehaviour)MatchManager.Instance).StopCoroutine(runningCoroutine);
					ATO_mod_pch.isCoroutine = false;
					ATO_mod_pch.maxNumOfSelectCard++;
				}
				flag2 = true;
				runningCoroutine = ((MonoBehaviour)MatchManager.Instance).StartCoroutine(OpenAddCardWindowCo(ATO_mod_pch.KillNpcChooseCardList, hero));
				ATO_mod_pch.OpenAddCardWindowCoroutine = runningCoroutine;
				Debug.Log((object)("[MatchManager_KillNPC_Patch_Prefix][KillNpcGiveCard]敌人卡牌数量: " + npcCardNum + " 怪物附魔卡数量: " + list.Count + " 当前行动的英雄: " + ((Character)hero).Id));
			}
			if (!flag2)
			{
				AtOManager.Instance.AddCardToHero(heroActive, ((Character)_npc).Cards[index]);
				AtOManager.Instance.SideBarRefreshCards(heroActive);
				if (MatchManager.Instance.CountHeroHand(heroActive) <= 0)
				{
					MatchManager.Instance.GenerateNewCard(1, MatchManager.Instance.CreateCardInDictionary(((Character)_npc).Cards[index], "", false), true, (CardPlace)1, (CardData)null, (CardData)null, heroActive, true, 0);
					Debug.Log((object)("[MatchManager_KillNPC_Patch_Prefix][KillNpcGiveCard] 英雄回合抽牌前击杀触发. 击杀时英雄手牌数为: " + MatchManager.Instance.CountHeroHand(heroActive)));
				}
				else
				{
					MatchManager.Instance.GenerateNewCard(1, MatchManager.Instance.CreateCardInDictionary(((Character)_npc).Cards[index], "", false), true, (CardPlace)5, (CardData)null, (CardData)null, heroActive, true, 0);
				}
				Debug.Log((object)("给英雄单位发牌: " + ((Character)_npc).Cards[index] + ", 敌人卡牌数量: " + npcCardNum + " 怪物的第几张牌: " + index + " 怪物附魔卡数量: " + list.Count + " 当前行动的英雄: " + ((Character)hero).Id));
			}
			ATO_mod_pch.heroClass = string.Empty;
			list.Clear();
			ATO_mod_pch.isNpcCard = false;
		}
		if (flag)
		{
			Debug.Log((object)"[MatchManager_KillNPC_Patch_Prefix][KillNpcGiveCard] 非----英雄回合击杀触发");
			int num = random2.Next(0, TeamHero.Length);
			ATO_mod_pch.isNpcCard = true;
			int index = random.Next(0, npcCardNum);
			AtOManager.Instance.AddCardToHero(num, ((Character)_npc).Cards[index]);
			AtOManager.Instance.SideBarRefreshCards(num);
			if (((Character)TeamHero[num]).Alive)
			{
				MatchManager.Instance.GenerateNewCard(1, MatchManager.Instance.CreateCardInDictionary(((Character)_npc).Cards[index], "", false), true, (CardPlace)1, (CardData)null, (CardData)null, num, true, 0);
			}
			ATO_mod_pch.heroClass = string.Empty;
			ATO_mod_pch.isNpcCard = false;
			Debug.Log((object)("给英雄单位发牌: " + ((Character)_npc).Cards[index] + ", 敌人卡牌数量: " + npcCardNum + " 怪物的第几张牌: " + index + " 获得卡牌的英雄: " + ((Character)TeamHero[num]).Id));
		}
		if (_npc.NPCIsBoss())
		{
			Debug.Log((object)"[MatchManager_KillNPC_Patch_Prefix][KillNpcGiveCard] 击杀Boss触发");
			int num = random2.Next(0, TeamHero.Length);
			ATO_mod_pch.isNpcCard = true;
			int index = random.Next(0, npcCardNum);
			AtOManager.Instance.AddCardToHero(num, ((Character)_npc).Cards[index]);
			AtOManager.Instance.SideBarRefreshCards(num);
			if (((Character)TeamHero[num]).Alive)
			{
				MatchManager.Instance.GenerateNewCard(1, MatchManager.Instance.CreateCardInDictionary(((Character)_npc).Cards[index], "", false), true, (CardPlace)1, (CardData)null, (CardData)null, num, true, 0);
			}
			ATO_mod_pch.heroClass = string.Empty;
			ATO_mod_pch.isNpcCard = false;
			Debug.Log((object)("[MatchManager_KillNPC_Patch_Prefix][KillNpcGiveCard]击杀Boss额外发牌: " + ((Character)_npc).Cards[index] + ", 敌人卡牌数量: " + npcCardNum + " 怪物的第几张牌: " + index + " 获得卡牌的英雄: " + ((Character)TeamHero[num]).Id));
		}
	}

	public static IEnumerator OpenAddCardWindowCo(List<string> KillNpcChooseCardList, Hero hero)
	{
		if ((Object)(object)MatchManager.Instance == (Object)null && KillNpcChooseCardList.Count == 0)
		{
			yield break;
		}
		ATO_mod_pch.isCoroutine = true;
		Traverse matchManagerInstanceTraverse = Traverse.Create((object)MatchManager.Instance);
		UIDeckCards deckCardsWindow = matchManagerInstanceTraverse.Field("deckCardsWindow").GetValue<UIDeckCards>();
		matchManagerInstanceTraverse.Field("GO_List").GetValue<List<GameObject>>();
		Dictionary<string, GameObject> cardGos = matchManagerInstanceTraverse.Field("cardGos").GetValue<Dictionary<string, GameObject>>();
		Hero theHero = matchManagerInstanceTraverse.Field("theHero").GetValue<Hero>();
		List<CardItem> CICardAddcard = matchManagerInstanceTraverse.Field("CICardAddcard").GetValue<List<CardItem>>();
		CICardAddcard.Clear();
		matchManagerInstanceTraverse.Field("CICardAddcard").SetValue((object)CICardAddcard);
		if (matchManagerInstanceTraverse.Field("waitingForAddcardAssignment").GetValue<bool>())
		{
			MatchManager.Instance.DrawDeckScreenDestroy();
			deckCardsWindow.TurnOff();
		}
		int selectCardNum = ATO_mod_pch.maxNumOfSelectCard;
		matchManagerInstanceTraverse.Field("GlobalAddcardCardsNum").SetValue((object)selectCardNum);
		new List<GameObject>();
		deckCardsWindow.TurnOn(3, selectCardNum, KillNpcChooseCardList.Count, false);
		List<GameObject> GO_List = new List<GameObject>();
		cardGos.Clear();
		for (int i = 0; i < KillNpcChooseCardList.Count; i++)
		{
			GameObject gameObject = Object.Instantiate<GameObject>(GameManager.Instance.CardPrefab, Vector3.zero, Quaternion.identity, deckCardsWindow.cardContainer);
			GO_List.Add(gameObject);
			matchManagerInstanceTraverse.Field("GO_List").SetValue((object)GO_List);
			CardItem CI = gameObject.GetComponent<CardItem>();
			((Object)gameObject).name = "TMP_" + i;
			cardGos.Add(((Object)gameObject).name, gameObject);
			CI.SetCard(KillNpcChooseCardList[i], false, hero, (NPC)null, false, false);
			CI.DrawEnergyCost(false);
			yield return Globals.Instance.WaitForSeconds(0.01f);
			CI.cardforaddcard = true;
			CI.AmplifyForSelection(i, KillNpcChooseCardList.Count);
			CI.SetDestination(CI.GetDestination() - new Vector3(2.5f, -4.5f, 0f));
			CI.DisableTrail();
			CI.active = true;
			CI.HideRarityParticles();
			CI.HideCardIconParticles();
			Debug.Log((object)("[OpenAddCardWindow]击杀选牌窗口触发 可选卡牌 " + i + ": " + KillNpcChooseCardList[i] + " : " + ((Object)CI).name + " : " + CI.CardData.CardName));
			if (MatchManager.Instance.IsYourTurnForAddDiscard())
			{
				CI.ShowKeyNum(true, (i + 1).ToString(), false);
			}
			yield return null;
		}
		UIDeckCards[] UIinstanceList = Object.FindObjectsOfType<UIDeckCards>();
		if (UIinstanceList != null)
		{
			UIDeckCards[] array = UIinstanceList;
			foreach (UIDeckCards UIinstance in array)
			{
				Traverse UIinstanceTraverse = Traverse.Create((object)UIinstance);
				Button buttonAction = UIinstanceTraverse.Field("buttonAction").GetValue<Button>();
				UIinstanceTraverse.Field("buttonCloseB").GetValue<Button>();
				UIinstanceTraverse.Field("mustSelect").SetValue((object)false);
				((Selectable)buttonAction).interactable = true;
				((Component)buttonAction).gameObject.SetActive(true);
				UIinstanceTraverse.Field("buttonAction").SetValue((object)buttonAction);
			}
		}
		matchManagerInstanceTraverse.Field("waitingForAddcardAssignment").SetValue((object)true);
		while (matchManagerInstanceTraverse.Field("waitingForAddcardAssignment").GetValue<bool>())
		{
			yield return Globals.Instance.WaitForSeconds(0.1f);
		}
		CICardAddcard = matchManagerInstanceTraverse.Field("CICardAddcard").GetValue<List<CardItem>>();
		if (selectCardNum > CICardAddcard.Count)
		{
			selectCardNum = CICardAddcard.Count;
			matchManagerInstanceTraverse.Field("GlobalAddcardCardsNum").SetValue((object)selectCardNum);
		}
		for (int addCardIndex = 0; addCardIndex < selectCardNum; addCardIndex++)
		{
			if (((Character)theHero).Alive && CICardAddcard.Count > 0)
			{
				MatchManager.Instance.GenerateNewCard(1, CICardAddcard[addCardIndex].CardData.Id, true, (CardPlace)5, (CardData)null, (CardData)null, ((Character)hero).HeroIndex, true, 0);
			}
			if (CICardAddcard.Count > 0)
			{
				AtOManager.Instance.AddCardToHero(((Character)hero).HeroIndex, CICardAddcard[addCardIndex].CardData.Id.Split(new string[1] { "_" }, StringSplitOptions.None)[0]);
				AtOManager.Instance.SideBarRefreshCards(((Character)hero).HeroIndex);
				Debug.Log((object)("[MatchManager_KillNPC_Patch_Prefix][OpenAddCardWindow]击杀选牌: " + CICardAddcard[addCardIndex].CardData.CardName + " 添加到英雄牌库"));
			}
		}
		CICardAddcard.Clear();
		matchManagerInstanceTraverse.Field("CICardAddcard").SetValue((object)CICardAddcard);
		Debug.Log((object)"[MatchManager_KillNPC_Patch_Prefix][OpenAddCardWindow]击杀选牌窗口触发7");
		MatchManager.Instance.DrawDeckScreenDestroy();
		deckCardsWindow.TurnOff();
		KillNpcChooseCardList.Clear();
		ATO_mod_pch.isCoroutine = false;
	}
}
[HarmonyPatch(typeof(MatchManager), "CastCard")]
public class MatchManager_CastCard_Patch_Pre_Post
{
	[HarmonyPrefix]
	public static bool MatchManager_CastCard_Patch_Prefix(MatchManager __instance, ref CardItem theCardItem, ref CardData _card, ref ATO_mod_pch.CastCardState __state)
	{
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Invalid comparison between Unknown and I4
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		bool flag = false;
		Traverse val = Traverse.Create((object)__instance);
		int value = val.Field("heroActive").GetValue<int>();
		NPC[] value2 = val.Field("TeamNPC").GetValue<NPC[]>();
		List<string>[] value3 = val.Field("NPCHand").GetValue<List<string>[]>();
		if (value < 0)
		{
			return true;
		}
		if ((Object)(object)theCardItem == (Object)null && (Object)(object)_card == (Object)null)
		{
			return true;
		}
		CardData val2;
		if ((Object)(object)theCardItem != (Object)null)
		{
			val2 = theCardItem.CardData;
			flag = true;
		}
		else
		{
			val2 = _card;
		}
		if (val2.AddCardId == "" || (int)val2.TargetSide != 0 || (int)Globals.Instance.GetCardData(val2.Id, false).CardClass != 5)
		{
			CardClass cardClass = __instance.GetCardData(val2.Id, false).CardClass;
			string? text = ((object)(CardClass)(ref cardClass)).ToString();
			cardClass = Globals.Instance.GetCardData(val2.Id, false).CardClass;
			Debug.Log((object)("[MatchManager_CastCard_Patch_Prefix]卡牌的原始Class: " + text + ((object)(CardClass)(ref cardClass)).ToString()));
			return true;
		}
		int addCard = val2.AddCard;
		for (int i = 0; i < 4; i++)
		{
			if (((Character)value2[i]).Alive)
			{
			}
		}
		__state = new ATO_mod_pch.CastCardState
		{
			CastCardState_AddCard = val2.AddCard,
			CastCardState_AddCardId = val2.AddCardId
		};
		ATO_mod_pch.SaveCastCardState = __state;
		ATO_mod_pch.castIsHeroToNpc_pxh = true;
		Debug.Log((object)("[MatchManager_CastCard_Patch_Prefix]存储的卡牌: " + val2.Id));
		Debug.Log((object)("[MatchManager_CastCard_Patch_Prefix]添加的卡牌: " + val2.AddCardId));
		if (flag)
		{
			theCardItem.CardData.AddCard = 0;
			theCardItem.CardData.AddCardId = "";
		}
		else
		{
			_card.AddCard = 0;
			_card.AddCardId = "";
		}
		return true;
	}

	[HarmonyPostfix]
	public static void MatchManager_CastCard_Patch_Postfix(MatchManager __instance, ref ATO_mod_pch.CastCardState __state)
	{
		Traverse val = Traverse.Create((object)__instance);
		Transform value = val.Field("targetTransform").GetValue<Transform>();
		if ((__state != null || !((Object)(object)value == (Object)null)) && (Object)(object)ATO_mod_pch.targetTransform_pxh != (Object)null && (Object)(object)((Component)ATO_mod_pch.targetTransform_pxh).GetComponent<NPCItem>() != (Object)null)
		{
			NPC nPCById = __instance.GetNPCById(((Object)ATO_mod_pch.targetTransform_pxh).name);
			if (!((Character)nPCById).Alive)
			{
			}
		}
	}
}
[HarmonyPatch(typeof(MatchManager), "CastCardAction")]
public class MatchManager_CastCardAction_Patch_Pre
{
	[HarmonyPrefix]
	public static bool MatchManager_CastCardAction_Patch_Prefix(MatchManager __instance, Transform targetTransformCast, CardData _cardActive)
	{
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		NPC val = null;
		Traverse val2 = Traverse.Create((object)__instance);
		int value = val2.Field("heroActive").GetValue<int>();
		NPC[] value2 = val2.Field("TeamNPC").GetValue<NPC[]>();
		List<string>[] value3 = val2.Field("NPCHand").GetValue<List<string>[]>();
		if ((Object)(object)targetTransformCast != (Object)null)
		{
			ATO_mod_pch.targetTransform_pxh = targetTransformCast;
			Debug.Log((object)("[MatchManager_CastCardAction_Patch_Prefix]存储的targetTransform NAME: " + ((Object)ATO_mod_pch.targetTransform_pxh).name));
			if (ATO_mod_pch.castIsHeroToNpc_pxh)
			{
				if ((Object)(object)((Component)ATO_mod_pch.targetTransform_pxh).GetComponent<NPCItem>() != (Object)null)
				{
					if (__instance.GetNPCById(((Object)ATO_mod_pch.targetTransform_pxh).name) != null)
					{
						val = __instance.GetNPCById(((Object)ATO_mod_pch.targetTransform_pxh).name);
					}
					if (val != null && ((Character)val).Alive)
					{
						if (!ATO_mod_pch.addCardIDList.Contains(ATO_mod_pch.SaveCastCardState.CastCardState_AddCardId))
						{
							ATO_mod_pch.addCardIDList.Add(ATO_mod_pch.SaveCastCardState.CastCardState_AddCardId);
							Debug.Log((object)("[MatchManager_CastCardAction_Patch_Prefix]需要常显的卡牌: " + ATO_mod_pch.SaveCastCardState.CastCardState_AddCardId));
						}
						if (((Character)value2[((Character)val).NPCIndex]).NPCItem.cardsCI.Length != 0)
						{
							GameObject val3 = Object.Instantiate<GameObject>(GameManager.Instance.CardPrefab, Vector3.zero, Quaternion.identity, ((Character)value2[((Character)val).NPCIndex]).NPCItem.cardsGOT);
							val3.gameObject.SetActive(false);
							val3.transform.localScale = Vector3.zero;
							CardItem component = val3.GetComponent<CardItem>();
							component.SetCard(ATO_mod_pch.SaveCastCardState.CastCardState_AddCardId, false, (Hero)null, value2[((Character)val).NPCIndex], false, false);
							List<CardItem> list = ((Character)value2[((Character)val).NPCIndex]).NPCItem.cardsCI.ToList();
							List<Transform> list2 = ((Character)value2[((Character)val).NPCIndex]).NPCItem.cardsT.ToList();
							list.Add(component);
							list2.Add(val3.transform);
							((Character)value2[((Character)val).NPCIndex]).NPCItem.cardsCI = list.ToArray();
							((Character)value2[((Character)val).NPCIndex]).NPCItem.cardsT = list2.ToArray();
							int num = ((Character)value2[((Character)val).NPCIndex]).NPCItem.cardsCI.Length;
							component.PositionCardInNPC(0, num);
							component.DefaultElementsLayeringOrder(100 * num - 1);
							component.CreateColliderAdjusted(0f, 0f);
							component.ShowBackImage(true);
							component.ShowCardNPC(num);
							component.RevealCard();
							value3[((Character)val).NPCIndex].Add(ATO_mod_pch.SaveCastCardState.CastCardState_AddCardId);
						}
						else
						{
							__instance.GenerateNewCard(ATO_mod_pch.SaveCastCardState.CastCardState_AddCard, ATO_mod_pch.SaveCastCardState.CastCardState_AddCardId, true, (CardPlace)1, (CardData)null, (CardData)null, ((Character)val).NPCIndex, false, 0);
						}
						Debug.Log((object)("[MatchManager_CastCardAction_Patch_Prefix]添加的卡牌: " + ATO_mod_pch.SaveCastCardState.CastCardState_AddCardId + " 来源卡牌: " + _cardActive.Id + " 怪物名字: " + ((Object)ATO_mod_pch.targetTransform_pxh).name + " 怪物Index: " + ((Character)val).NPCIndex));
					}
					ATO_mod_pch.castIsHeroToNpc_pxh = false;
				}
				_cardActive.AddCard = ATO_mod_pch.SaveCastCardState.CastCardState_AddCard;
				_cardActive.AddCardId = ATO_mod_pch.SaveCastCardState.CastCardState_AddCardId;
			}
		}
		ATO_mod_pch.targetTransform_pxh = null;
		ATO_mod_pch.SaveCastCardState.CastCardState_AddCard = 0;
		ATO_mod_pch.SaveCastCardState.CastCardState_AddCardId = "";
		return true;
	}
}