Decompiled source of Upgrade Champions 2 v1.1.2

plugins/Upgrade_Champions_2.Plugin.dll

Decompiled 2 months 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 BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ShinyShoe;
using UnityEngine;

[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("Upgrade_Champions_2.Plugin")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.2.0")]
[assembly: AssemblyInformationalVersion("1.1.2+d3217e1b8a9995921b4590df0e462a40d82f457a")]
[assembly: AssemblyProduct("Upgrade_Champions_2.Plugin")]
[assembly: AssemblyTitle("Upgrade_Champions_2.Plugin")]
[assembly: AssemblyVersion("1.1.2.0")]
[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 Upgrade_Champions_2.Plugin
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Upgrade_Champions_2.Plugin";

		public const string PLUGIN_NAME = "Upgrade_Champions_2.Plugin";

		public const string PLUGIN_VERSION = "1.1.2";
	}
}
namespace UpgradeChampions2
{
	[BepInPlugin("com.jacelendro.upgradechampions2", "Upgrade Champions 2", "1.1.0")]
	public class UpgradeChampions2 : BaseUnityPlugin
	{
		public const string pluginGuid = "com.jacelendro.upgradechampions2";

		public const string pluginName = "Upgrade Champions 2";

		public const string pluginVersion = "1.1.0";

		public void Awake()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Loading Upgrade Champions 2...");
			new Harmony("com.jacelendro.upgradechampions2").PatchAll();
		}
	}
	[HarmonyPatch(typeof(DeckScreen), "CollectCardsForMode")]
	public class AddChampionCardsToUpgradeList
	{
		public static readonly ManualLogSource Log = Logger.CreateLogSource("AddChampionCardsToUpgradeList");

		public static void Postfix(SaveManager ___saveManager, Mode ___mode, RelicEffectData ___relicEffectData, object ___cardUpgradesToApply, CardUpgradeMaskData ___cardUpgradeMaskData, List<CardState> __result, CardState ___forceExcludeCard, CardType ___cardTypeFilter, bool ___ignoreUpgradeLimit, Source ___rewardSource, RelicManager ___relicManager, bool ___excludeFilteredOutCards)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Invalid comparison between Unknown and I4
			//IL_0023: 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_0014: Invalid comparison between Unknown and I4
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Invalid comparison between Unknown and I4
			//IL_0320: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Invalid comparison between Unknown and I4
			//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_0366: Unknown result type (might be due to invalid IL or missing references)
			//IL_0369: Invalid comparison between Unknown and I4
			//IL_0341: Unknown result type (might be due to invalid IL or missing references)
			//IL_0370: Unknown result type (might be due to invalid IL or missing references)
			//IL_0375: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0503: Unknown result type (might be due to invalid IL or missing references)
			//IL_050e: Unknown result type (might be due to invalid IL or missing references)
			RelicEffectData ___relicEffectData2 = ___relicEffectData;
			if ((int)___mode != 6 && (int)___mode != 12)
			{
				return;
			}
			Log.LogInfo((object)$"Adding champion cards to upgrade list for mode: {___mode}...");
			List<CardState> source = new List<CardState>(___saveManager.GetDeckState());
			source = source.Where((CardState x) => x.IsChampionCard()).ToList();
			if (IEnumerableUtility.IsNullOrEmpty<CardState>(source))
			{
				Log.LogInfo((object)"No champion cards found.");
				return;
			}
			if (___relicEffectData2 != null)
			{
				Log.LogInfo((object)"Filtering by relic effect data...");
				if ((int)___relicEffectData2.GetParamCardType() != 4)
				{
					source.RemoveAll((CardState c) => c.GetCardType() != ___relicEffectData2.GetParamCardType());
				}
				if (!___relicEffectData2.GetParamCharacterSubtype().IsNone)
				{
					for (int num = source.Count - 1; num >= 0; num--)
					{
						foreach (CardEffectState effectState in source[num].GetEffectStates())
						{
							if (effectState.GetCardEffect() is CardEffectSpawnMonster && !effectState.GetParamCharacterData().GetSubtypes().Contains(___relicEffectData2.GetParamCharacterSubtype()))
							{
								source.RemoveAt(num);
							}
						}
					}
				}
				if (___relicEffectData2.GetUseIntRange())
				{
					source.RemoveAll((CardState c) => c.GetCostWithoutAnyModifications() < ___relicEffectData2.GetParamMinInt() || c.GetCostWithoutAnyModifications() > ___relicEffectData2.GetParamMaxInt());
				}
			}
			if (IEnumerableUtility.IsNullOrEmpty<CardState>(source))
			{
				Log.LogInfo((object)"No champion cards left after checking relic effect data.");
				return;
			}
			List<CardUpgradeMaskData> list = new List<CardUpgradeMaskData>();
			if (___cardUpgradesToApply != null)
			{
				List<CardUpgradeData> list2 = (List<CardUpgradeData>)Traverse.Create(___cardUpgradesToApply).Field("UpgradeDatas").GetValue();
				if (!IEnumerableUtility.IsNullOrEmpty<CardUpgradeData>(list2))
				{
					foreach (CardUpgradeData item in list2)
					{
						Log.LogInfo((object)("Found upgrade data: " + item.Cheat_GetNameEnglish() + " (" + item.GetDebugName() + ")."));
						list.AddRange(item.GetFilters());
					}
				}
			}
			if ((Object)(object)___cardUpgradeMaskData != (Object)null)
			{
				list.Add(___cardUpgradeMaskData);
			}
			if (!IEnumerableUtility.IsNullOrEmpty<CardUpgradeMaskData>(list))
			{
				Log.LogInfo((object)$"Found {list.Count} filter(s) to check :");
				foreach (CardUpgradeMaskData item2 in list)
				{
					Log.LogInfo((object)(((Object)item2).name ?? ""));
				}
			}
			List<IModifyCardUpgradeSlotCountRelicEffect> list3 = default(List<IModifyCardUpgradeSlotCountRelicEffect>);
			foreach (CardState item3 in source)
			{
				if (__result.Contains(item3))
				{
					Log.LogInfo((object)("Card " + item3.GetAssetName() + " is already in the upgrade list, skipping."));
					continue;
				}
				if (___forceExcludeCard == item3)
				{
					Log.LogInfo((object)("Card " + item3.GetAssetName() + " is force excluded, skipping."));
					continue;
				}
				if ((int)___cardTypeFilter != 4 && item3.GetCardType() != ___cardTypeFilter)
				{
					Log.LogInfo((object)$"Card {item3.GetAssetName()} does not match the card type filter {___cardTypeFilter}, skipping.");
					continue;
				}
				item3.CurrentDisabledReason = (UpgradeDisabledReason)0;
				if (!___ignoreUpgradeLimit && (int)___rewardSource != 2)
				{
					UsingGenericPoolObject<List<IModifyCardUpgradeSlotCountRelicEffect>> list4 = GenericPools.GetList<IModifyCardUpgradeSlotCountRelicEffect>(ref list3);
					try
					{
						int visibleUpgradeCount = item3.GetVisibleUpgradeCount();
						int upgradeSlots = ___saveManager.GetBalanceData().GetUpgradeSlots(item3, ((Object)(object)___relicManager != (Object)null) ? ___relicManager.GetRelicEffects<IModifyCardUpgradeSlotCountRelicEffect>(list3) : null, ___relicManager);
						if (visibleUpgradeCount >= upgradeSlots)
						{
							Log.LogInfo((object)$"Card {item3.GetAssetName()} has reached the maximum upgrade slots ({visibleUpgradeCount}/{upgradeSlots}).");
							if (!___excludeFilteredOutCards)
							{
								item3.CurrentDisabledReason = (UpgradeDisabledReason)2;
								__result.Add(item3);
							}
							continue;
						}
					}
					finally
					{
						((IDisposable)list4).Dispose();
					}
				}
				if (IEnumerableUtility.IsNullOrEmpty<CardUpgradeMaskData>(list))
				{
					__result.Add(item3);
					continue;
				}
				bool flag = true;
				foreach (CardUpgradeMaskData item4 in list)
				{
					Log.LogInfo((object)("Checking upgrade eligibility for card " + item3.GetAssetName() + " with filter " + item4.GetName() + "."));
					if (item4.GetName() == "OnlyUnitExcludingChamps")
					{
						continue;
					}
					if (item4.GetName() == "OnlyEquipment" || item4.GetName() == "OnlySpells" || item4.GetName() == "OnlyEquipment_EquipmentMerge")
					{
						flag = false;
						break;
					}
					if (!item4.FilterCard<CardState>(item3, ___relicManager))
					{
						Log.LogInfo((object)$"Card {item3.GetAssetName()} is not eligible for upgrade due to reason: {item4.GetUpgradeDisabledReason()}.");
						if (___excludeFilteredOutCards)
						{
							flag = false;
						}
						else if ((int)item4.GetUpgradeDisabledReason() != 0)
						{
							item3.CurrentDisabledReason = item4.GetUpgradeDisabledReason();
						}
						else
						{
							item3.CurrentDisabledReason = (UpgradeDisabledReason)3;
						}
						break;
					}
				}
				if (flag)
				{
					__result.Add(item3);
				}
			}
		}
	}
}