Decompiled source of Dual Champions 2 v1.1.2

plugins/Dual_Champions_2.Plugin.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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("Dual_Champions_2.Plugin")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.2.0")]
[assembly: AssemblyInformationalVersion("1.1.2+6a2dee8ebef9ec18376c901f233f4d427642db46")]
[assembly: AssemblyProduct("Dual_Champions_2.Plugin")]
[assembly: AssemblyTitle("Dual_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 Dual_Champions_2.Plugin
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Dual_Champions_2.Plugin";

		public const string PLUGIN_NAME = "Dual_Champions_2.Plugin";

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

		public const string pluginName = "Dual 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 Dual Champions 2...");
			new Harmony("com.jacelendro.dualchampions2").PatchAll();
		}
	}
	[HarmonyPatch(typeof(SaveManager), "SetupRun")]
	internal class AddSubclassChampionCard
	{
		public static readonly ManualLogSource Log = Logger.CreateLogSource("AddSubclassChampionCard");

		public static void Postfix(SaveManager __instance, AllGameData ___allGameData)
		{
			if (__instance.HasAlliedChampion)
			{
				Log.LogInfo((object)"Allied champion enabled via mutator, skipping subclass champion card addition.");
				return;
			}
			ClassData subClass = __instance.GetSubClass();
			if (__instance.HasCardById(((GameData)subClass.GetChampionCard(__instance.GetSubChampionIndex())).GetID()))
			{
				Log.LogInfo((object)"Subclass champion card already exists.");
				return;
			}
			__instance.AddCardToDeck(subClass.GetChampionCard(__instance.GetSubChampionIndex()), (CardStateModifiers)null, false, 0, false, false, true, true);
			Log.LogInfo((object)("Added subclass champion card: " + subClass.GetChampionCard(__instance.GetSubChampionIndex()).GetName()));
		}
	}
	[HarmonyPatch(typeof(ChampionUpgradeScreen), "ReturnToMap")]
	internal class OverrideReturnToMap
	{
		public static readonly ManualLogSource Log = Logger.CreateLogSource("OverrideReturnToMap");

		public static bool Prefix(ChampionUpgradeScreen __instance, SaveManager ___saveManager, string ___targetChampionClassId, Source ___rewardSource, RewardState ___rewardState, Action<GrantResult> ___rewardGrantedCallback)
		{
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Expected O, but got Unknown
			SaveManager ___saveManager2 = ___saveManager;
			if (___saveManager2.HasAlliedChampion)
			{
				Log.LogInfo((object)"Allied champion enabled via mutator, skipping return to map override.");
				return true;
			}
			List<CardState> list = ___saveManager2.GetDeckState().FindAll((CardState cs) => cs.IsChampionCard());
			if ((Object)(object)___saveManager2.GetMainClass() == (Object)(object)___saveManager2.GetSubClass() || list.Count > 2)
			{
				Log.LogInfo((object)"Same main and allied clan or more than two champion cards detected. Random upgrades will be given instead.");
				foreach (CardState item in list)
				{
					if (item.GetCardDataID() != ((GameData)___saveManager2.GetMainClass().GetChampionCard(___saveManager2.GetMainChampionIndex())).GetID())
					{
						CardUpgradeTreeData upgradeTree = ChampionUpgradeRewardData.GetUpgradeTree(item.GetSpawnCharacterData(), ___saveManager2.GetBalanceData());
						List<CardUpgradeData> randomChoices = upgradeTree.GetRandomChoices(1, item);
						CardUpgradeState val = new CardUpgradeState();
						val.Setup(randomChoices[0], false, false);
						item.Upgrade(val, ___saveManager2, true, (string)null);
						item.RemoveEarlierTreeUpgrades(val, upgradeTree);
					}
				}
				return true;
			}
			Log.LogInfo((object)"Returning to map from ChampionUpgradeScreen...");
			if (___targetChampionClassId == ((GameData)___saveManager2.GetMainClass()).GetID())
			{
				Log.LogInfo((object)"Setting up for Subclass Champion...");
				CardUpgradeTreeData upgradeTree2 = ChampionUpgradeRewardData.GetUpgradeTree(___saveManager2.GetDeckState().Find((CardState cs) => cs.IsChampionCard() && cs.GetCardDataID() == ((GameData)___saveManager2.GetSubClass().GetChampionCard(___saveManager2.GetSubChampionIndex())).GetID()).GetSpawnCharacterData(), ___saveManager2.GetBalanceData());
				___rewardState.RemainingUses = 1;
				GrantParams val2 = default(GrantParams);
				val2.source = (Source)1;
				val2.correspondingReward = ___rewardState;
				GrantParams val3 = val2;
				__instance.Setup(((GameData)___saveManager2.GetSubClass()).GetID(), upgradeTree2, val3, ___rewardGrantedCallback);
				Log.LogInfo((object)"Subclass Champion setup complete.");
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(DeckScreen), "SortCards")]
	internal class SwapFirstAndSecondChampionCards
	{
		public static readonly ManualLogSource Log = Logger.CreateLogSource("SwapFirstAndSecondChampionCards");

		public static void Postfix(DeckScreen __instance, SaveManager ___saveManager, List<CardInfo> ___cardInfos, SortOrder ___sortOrder)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			if (___saveManager.HasAlliedChampion)
			{
				Log.LogInfo((object)"Allied champion enabled via mutator, skipping sort cards override.");
			}
			else if (___cardInfos.Count > 1 && (int)___sortOrder == 0)
			{
				CardInfo val = ___cardInfos[0];
				CardInfo val2 = ___cardInfos[1];
				if (val.cardState.IsChampionCard() && val2.cardState.IsChampionCard() && ((GameData)___saveManager.GetSubClass().GetChampionCard(___saveManager.GetSubChampionIndex())).GetID() == val.cardState.GetCardDataID() && ((GameData)___saveManager.GetMainClass().GetChampionCard(___saveManager.GetMainChampionIndex())).GetID() == val2.cardState.GetCardDataID())
				{
					___cardInfos[0] = val2;
					___cardInfos[1] = val;
					Log.Log((LogLevel)16, (object)"Swapped first and second champion cards.");
				}
			}
		}
	}
}