Decompiled source of NeutralCardReplacer v1.2.0

NeutralCardReplacer.dll

Decompiled 4 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 System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LBoL.Base;
using LBoL.ConfigData;
using LBoL.Core;
using LBoL.Core.Cards;
using LBoL.Core.Randoms;
using LBoL.Core.Stations;
using LBoLEntitySideloader;
using LBoLEntitySideloader.Attributes;
using LBoLEntitySideloader.Entities;
using LBoLEntitySideloader.Resource;
using UnityEngine;

[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.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("LBoL.Base")]
[assembly: IgnoresAccessChecksTo("LBoL.ConfigData")]
[assembly: IgnoresAccessChecksTo("LBoL.Core")]
[assembly: IgnoresAccessChecksTo("LBoL.EntityLib")]
[assembly: IgnoresAccessChecksTo("LBoL.Presentation")]
[assembly: IgnoresAccessChecksTo("Untitled.ConfigDataBuilder.Base")]
[assembly: AssemblyCompany("NeutralCardReplacer")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+423f55fc3a772deac2db777a9b0409952ee7bd9a")]
[assembly: AssemblyProduct("NeutralCardReplacer")]
[assembly: AssemblyTitle("NeutralCardReplacer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace NeutralCardReplacer
{
	[BepInPlugin("cramps-neutralcardreplacer", "NeutralCardReplacer", "1.2.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInProcess("LBoL.exe")]
	public class BepinexPlugin : BaseUnityPlugin
	{
		private static readonly Harmony harmony = PInfo.harmony;

		internal static ManualLogSource log;

		internal static TemplateSequenceTable sequenceTable = new TemplateSequenceTable(0);

		internal static IResourceSource embeddedSource = (IResourceSource)new EmbeddedSource(Assembly.GetExecutingAssembly());

		internal static DirectorySource directorySource = new DirectorySource("cramps-neutralcardreplacer", "");

		internal static BatchLocalization jadeboxLoc = new BatchLocalization((IResourceSource)(object)directorySource, typeof(JadeBoxTemplate), "jadebox", (Locale)0, false);

		public static ConfigEntry<bool> allowCardRewardReplacement;

		public static ConfigEntry<bool> allowShopReplacement;

		public static ConfigEntry<Vector4> cardReward1CardPoolWeight;

		public static ConfigEntry<Vector4> cardReward2CardPoolWeight;

		public static ConfigEntry<Vector4> cardReward3CardPoolWeight;

		public static ConfigEntry<Vector4> additionalCardRewardCardPoolWeight;

		public static ConfigEntry<Vector3> extraCardReward1AppearChance;

		public static ConfigEntry<Vector4> extraCardReward1CardPoolWeight;

		public static ConfigEntry<Vector3> extraCardReward2AppearChance;

		public static ConfigEntry<Vector4> extraCardReward2CardPoolWeight;

		public static ConfigEntry<Vector4> shopOption1CardPoolWeight;

		public static ConfigEntry<Vector4> shopOption2CardPoolWeight;

		public static ConfigEntry<Vector4> shopOption3CardPoolWeight;

		public static ConfigEntry<Vector4> shopOption4CardPoolWeight;

		public static ConfigEntry<Vector4> shopOption5CardPoolWeight;

		public static ConfigEntry<Vector4> shopOption6CardPoolWeight;

		public static ConfigEntry<Vector4> shopOption7CardPoolWeight;

		public static ConfigEntry<Vector4> shopOption8CardPoolWeight;

		private void Awake()
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			//IL_033e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0376: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ae: Unknown result type (might be due to invalid IL or missing references)
			log = ((BaseUnityPlugin)this).Logger;
			allowCardRewardReplacement = ((BaseUnityPlugin)this).Config.Bind<bool>("ReplaceCardRewards", "AllowCardRewardReplacement", true, "Allows replacing from card rewards");
			allowShopReplacement = ((BaseUnityPlugin)this).Config.Bind<bool>("ReplaceShopOptions", "AllowShopReplacement", true, "Allows replacing from shops");
			cardReward1CardPoolWeight = ((BaseUnityPlugin)this).Config.Bind<Vector4>("ReplaceCardRewards", "CardReward1CardPoolWeight", new Vector4(1f, 1f, 0f, 0f), "Card slot 1 - The ratio of which card pools to choose from, (x:Player, y:Exhibit, z:OtherChars, w:Neutral)");
			cardReward2CardPoolWeight = ((BaseUnityPlugin)this).Config.Bind<Vector4>("ReplaceCardRewards", "CardReward2CardPoolWeight", new Vector4(1f, 1f, 0f, 0f), "Card slot 2 - The ratio of which card pools to choose from, (x:Player, y:Exhibit, z:OtherChars, w:Neutral)");
			cardReward3CardPoolWeight = ((BaseUnityPlugin)this).Config.Bind<Vector4>("ReplaceCardRewards", "CardReward3CardPoolWeight", new Vector4(1f, 1f, 0f, 0f), "Card slot 3 - The ratio of which card pools to choose from, (x:Player, y:Exhibit, z:OtherChars, w:Neutral)");
			additionalCardRewardCardPoolWeight = ((BaseUnityPlugin)this).Config.Bind<Vector4>("ReplaceCardRewards", "AdditionalCardRewardCardPoolWeight", new Vector4(1f, 1f, 0f, 0f), "Card slots 4 and beyond - The ratio of which card pools to choose from, (x:Player, y:Exhibit, z:OtherChars, w:Neutral)");
			extraCardReward1AppearChance = ((BaseUnityPlugin)this).Config.Bind<Vector3>("ExtraCardRewards", "ExtraCardReward1AppearChance", new Vector3(0f, 0f, 0f), "Extra card slot 1 - Percentages for free extra card rewards, between 0 and 100, (x:Normal battle, y:Elite, z:Boss)");
			extraCardReward1CardPoolWeight = ((BaseUnityPlugin)this).Config.Bind<Vector4>("ExtraCardRewards", "ExtraCardReward1CardPoolWeight", new Vector4(1f, 1f, 0f, 0f), "Extra card slot 1 - The ratio of which card pools to choose from, (x:Player, y:Exhibit, z:OtherChars, w:Neutral)");
			extraCardReward2AppearChance = ((BaseUnityPlugin)this).Config.Bind<Vector3>("ExtraCardRewards", "ExtraCardReward2AppearChance", new Vector3(0f, 0f, 0f), "Extra card slot 2 - Percentages for free extra card rewards, between 0 and 100, (x:Normal battle, y:Elite, z:Boss)");
			extraCardReward2CardPoolWeight = ((BaseUnityPlugin)this).Config.Bind<Vector4>("ExtraCardRewards", "ExtraCardReward2CardPoolWeight", new Vector4(1f, 1f, 0f, 0f), "Extra card slot 2 - The ratio of which card pools to choose from, (x:Player, y:Exhibit, z:OtherChars, w:Neutral)");
			shopOption1CardPoolWeight = ((BaseUnityPlugin)this).Config.Bind<Vector4>("ReplaceShopOptions", "ShopOption1CardPoolWeight", new Vector4(1f, 1f, 0f, 0f), "Shop option 1, The ratio of which card pools to choose from, (x:Player, y:Exhibit, z:OtherChars, w:Neutral)");
			shopOption2CardPoolWeight = ((BaseUnityPlugin)this).Config.Bind<Vector4>("ReplaceShopOptions", "ShopOption2CardPoolWeight", new Vector4(1f, 1f, 0f, 0f), "Shop option 2, The ratio of which card pools to choose from, (x:Player, y:Exhibit, z:OtherChars, w:Neutral)");
			shopOption3CardPoolWeight = ((BaseUnityPlugin)this).Config.Bind<Vector4>("ReplaceShopOptions", "ShopOption3CardPoolWeight", new Vector4(1f, 1f, 0f, 0f), "Shop option 3, The ratio of which card pools to choose from, (x:Player, y:Exhibit, z:OtherChars, w:Neutral)");
			shopOption4CardPoolWeight = ((BaseUnityPlugin)this).Config.Bind<Vector4>("ReplaceShopOptions", "ShopOption4CardPoolWeight", new Vector4(1f, 1f, 0f, 0f), "Shop option 4, The ratio of which card pools to choose from, (x:Player, y:Exhibit, z:OtherChars, w:Neutral)");
			shopOption5CardPoolWeight = ((BaseUnityPlugin)this).Config.Bind<Vector4>("ReplaceShopOptions", "ShopOption5CardPoolWeight", new Vector4(1f, 1f, 0f, 0f), "Shop option 5, The ratio of which card pools to choose from, (x:Player, y:Exhibit, z:OtherChars, w:Neutral)");
			shopOption6CardPoolWeight = ((BaseUnityPlugin)this).Config.Bind<Vector4>("ReplaceShopOptions", "ShopOption6CardPoolWeight", new Vector4(1f, 1f, 0f, 0f), "Shop option 6, The ratio of which card pools to choose from, (x:Player, y:Exhibit, z:OtherChars, w:Neutral)");
			shopOption7CardPoolWeight = ((BaseUnityPlugin)this).Config.Bind<Vector4>("ReplaceShopOptions", "ShopOption7CardPoolWeight", new Vector4(1f, 1f, 0f, 0f), "Shop option 7, The ratio of which card pools to choose from, (x:Player, y:Exhibit, z:OtherChars, w:Neutral)");
			shopOption8CardPoolWeight = ((BaseUnityPlugin)this).Config.Bind<Vector4>("ReplaceShopOptions", "ShopOption8CardPoolWeight", new Vector4(1f, 1f, 0f, 0f), "Shop option 8, The ratio of which card pools to choose from, (x:Player, y:Exhibit, z:OtherChars, w:Neutral)");
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			EntityManager.RegisterSelf();
			harmony.PatchAll();
		}

		private void OnDestroy()
		{
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	public static class PInfo
	{
		public const string GUID = "cramps-neutralcardreplacer";

		public const string Name = "NeutralCardReplacer";

		public const string version = "1.2.0";

		public static readonly Harmony harmony = new Harmony("cramps-neutralcardreplacer");
	}
	[HarmonyPatch]
	internal class NeutralCardReplacer
	{
		private static Func<Vector4, OwnerWeightTable> convertToWeight = (Vector4 vector) => new OwnerWeightTable(vector.x, vector.y, vector.z, vector.w);

		[HarmonyPatch(typeof(Station), "AddReward")]
		private static void Prefix(Station __instance, StationReward reward)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.GameRun.HasJadeBox<ReplacementJadebox>() && BepinexPlugin.allowCardRewardReplacement.Value && (int)reward.Type == 1)
			{
				RewardCardReplace(0, ref reward, __instance, convertToWeight(BepinexPlugin.cardReward1CardPoolWeight.Value));
				RewardCardReplace(1, ref reward, __instance, convertToWeight(BepinexPlugin.cardReward2CardPoolWeight.Value));
				RewardCardReplace(2, ref reward, __instance, convertToWeight(BepinexPlugin.cardReward3CardPoolWeight.Value));
				for (int i = 3; i < reward.Cards.Count; i++)
				{
					RewardCardReplace(i, ref reward, __instance, convertToWeight(BepinexPlugin.additionalCardRewardCardPoolWeight.Value));
				}
				ExtraCardReward(__instance, ref reward, BepinexPlugin.extraCardReward1AppearChance.Value, convertToWeight(BepinexPlugin.extraCardReward1CardPoolWeight.Value));
				ExtraCardReward(__instance, ref reward, BepinexPlugin.extraCardReward2AppearChance.Value, convertToWeight(BepinexPlugin.extraCardReward2CardPoolWeight.Value));
			}
		}

		private static void RewardCardReplace(int slot, ref StationReward reward, Station __instance, OwnerWeightTable ownerWeight)
		{
			if (reward.Cards[slot] != null)
			{
				BepinexPlugin.log.LogInfo((object)$"Replacing card reward: {((GameEntity)reward.Cards[slot]).Name} at slot {slot + 1}");
				Card val = NewRewardCard(__instance, reward.Cards, ownerWeight);
				if (val != null)
				{
					reward.Cards[slot] = val;
				}
				else
				{
					BepinexPlugin.log.LogInfo((object)"No new card found");
				}
			}
			else
			{
				BepinexPlugin.log.LogInfo((object)$"Card slot {slot + 1} doesn't exist");
			}
		}

		private static void ExtraCardReward(Station __instance, ref StationReward reward, Vector3 appearChances, OwnerWeightTable ownerWeight)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			if (Utils.CheckPercent(appearChances, __instance))
			{
				Card val = NewRewardCard(__instance, reward.Cards, ownerWeight);
				if (val != null)
				{
					BepinexPlugin.log.LogInfo((object)("Adding extra card reward " + ((GameEntity)val).Name));
					reward.Cards.Add(val);
				}
				else
				{
					BepinexPlugin.log.LogInfo((object)"Failed adding extra card reward");
				}
			}
		}

		private static Card NewRewardCard(Station __instance, List<Card> oldCards, OwnerWeightTable ownerWeight)
		{
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Expected O, but got Unknown
			Predicate<CardConfig> predicate = (CardConfig config) => !oldCards.Any((Card oc) => ((GameEntity)oc).Id == config.Id);
			string name = ((object)__instance).GetType().Name;
			if (1 == 0)
			{
			}
			RarityWeightTable val = (RarityWeightTable)(name switch
			{
				"EnemyStation" => RarityWeightTable.EnemyCard, 
				"EliteEnemyStation" => RarityWeightTable.EliteCard, 
				"BossStation" => RarityWeightTable.OnlyRare, 
				_ => RarityWeightTable.EnemyCard, 
			});
			if (1 == 0)
			{
			}
			RarityWeightTable val2 = val;
			return __instance.GameRun.RollCard(__instance.GameRun.CardRng, new CardWeightTable(val2, ownerWeight, CardTypeWeightTable.CanBeLoot, false), false, false, predicate);
		}

		[HarmonyPatch(typeof(Stage), "GetShopNormalCards")]
		private static void Postfix(Stage __instance, ref Card[] __result)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			if (((GameEntity)__instance).GameRun.HasJadeBox<ReplacementJadebox>() && BepinexPlugin.allowShopReplacement.Value)
			{
				ShopCardReplace(0, ref __result, __instance, convertToWeight(BepinexPlugin.shopOption1CardPoolWeight.Value));
				ShopCardReplace(1, ref __result, __instance, convertToWeight(BepinexPlugin.shopOption2CardPoolWeight.Value));
				ShopCardReplace(2, ref __result, __instance, convertToWeight(BepinexPlugin.shopOption3CardPoolWeight.Value));
				ShopCardReplace(3, ref __result, __instance, convertToWeight(BepinexPlugin.shopOption4CardPoolWeight.Value));
				ShopCardReplace(4, ref __result, __instance, convertToWeight(BepinexPlugin.shopOption5CardPoolWeight.Value));
				ShopCardReplace(5, ref __result, __instance, convertToWeight(BepinexPlugin.shopOption6CardPoolWeight.Value));
				ShopCardReplace(6, ref __result, __instance, convertToWeight(BepinexPlugin.shopOption7CardPoolWeight.Value));
				ShopCardReplace(7, ref __result, __instance, convertToWeight(BepinexPlugin.shopOption8CardPoolWeight.Value));
			}
		}

		private static void ShopCardReplace(int slot, ref Card[] __result, Stage __instance, OwnerWeightTable ownerWeight)
		{
			BepinexPlugin.log.LogInfo((object)$"Replacing card in shop: {((GameEntity)__result[slot]).Name} at slot {slot + 1}");
			Card val = NewShopCard(__instance, __result[slot], __result.Select((Card c) => ((GameEntity)c).Id).ToList(), ownerWeight);
			if (val != null)
			{
				__result[slot] = val;
			}
			else
			{
				BepinexPlugin.log.LogInfo((object)$"No new card found for slot {slot + 1}");
			}
		}

		private static Card NewShopCard(Stage __instance, Card oldCard, List<string> oldCardIds, OwnerWeightTable ownerWeight)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected I4, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			CardType cardType = oldCard.CardType;
			if (1 == 0)
			{
			}
			CardTypeWeightTable val = (CardTypeWeightTable)((cardType - 1) switch
			{
				0 => CardTypeWeightTable.OnlyAttack, 
				1 => CardTypeWeightTable.OnlyDefense, 
				2 => CardTypeWeightTable.OnlySkill, 
				3 => CardTypeWeightTable.OnlyAbility, 
				_ => CardTypeWeightTable.OnlyAttack, 
			});
			if (1 == 0)
			{
			}
			CardTypeWeightTable val2 = val;
			return ((GameEntity)__instance).GameRun.GetShopCards(1, new CardWeightTable(RarityWeightTable.ShopCard, ownerWeight, val2, true), oldCardIds)[0];
		}
	}
	internal class Utils
	{
		internal static bool CheckPercent(Vector3 percentages, Station __instance)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			string name = ((object)__instance).GetType().Name;
			if (1 == 0)
			{
			}
			float num = name switch
			{
				"EnemyStation" => percentages.x, 
				"EliteEnemyStation" => percentages.y, 
				"BossStation" => percentages.z, 
				_ => 0f, 
			};
			if (1 == 0)
			{
			}
			float num2 = num;
			int num3 = __instance.GameRun.StationRng.NextInt(1, 100);
			return (float)num3 <= num2;
		}
	}
	public sealed class ReplacementJadeboxDef : JadeBoxTemplate
	{
		public override IdContainer GetId()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			return IdContainer.op_Implicit("ReplacementJadebox");
		}

		public override LocalizationOption LoadLocalization()
		{
			return (LocalizationOption)(object)BepinexPlugin.jadeboxLoc.AddEntity((EntityDefinition)(object)this);
		}

		public override JadeBoxConfig MakeConfig()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			return new JadeBoxConfig(0, "", 10, (IReadOnlyList<string>)new List<string>(), (int?)null, (int?)null, (int?)null, (ManaGroup?)null, (Keyword)0, (IReadOnlyList<string>)new List<string>(), (IReadOnlyList<string>)new List<string>());
		}
	}
	[EntityLogic(typeof(ReplacementJadeboxDef))]
	public sealed class ReplacementJadebox : JadeBox
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}