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+319d506cf91c5e238e48ff8cad3c10ccc4f7be3b")]
[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.1.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<bool> cardRewardRemoveInstead;
public static ConfigEntry<bool> cardRewardReplaceWithOtherPool;
public static ConfigEntry<bool> shopReplaceWithOtherPool;
private void Awake()
{
log = ((BaseUnityPlugin)this).Logger;
allowCardRewardReplacement = ((BaseUnityPlugin)this).Config.Bind<bool>("ReplaceNeutralCards", "AllowCardRewardReplacement", true, "Allows replacing from card rewards");
allowShopReplacement = ((BaseUnityPlugin)this).Config.Bind<bool>("ReplaceNeutralCards", "AllowShopReplacement", true, "Allows replacing from shops");
cardRewardRemoveInstead = ((BaseUnityPlugin)this).Config.Bind<bool>("ReplaceNeutralCards", "CardRewardRemoveInstead", false, "Removes any neutral cards from card rewards instead of replacing them");
cardRewardReplaceWithOtherPool = ((BaseUnityPlugin)this).Config.Bind<bool>("ReplaceNeutralCards", "CardRewardReplaceWithOtherPool", false, "Replaces card reward neutral cards with cards from other pools");
shopReplaceWithOtherPool = ((BaseUnityPlugin)this).Config.Bind<bool>("ReplaceNeutralCards", "ShopReplaceWithOtherPool", false, "Replaces shop neutral cards with cards from other pools");
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.1.0";
public static readonly Harmony harmony = new Harmony("cramps-neutralcardreplacer");
}
[HarmonyPatch]
internal class NeutralCardReplacer
{
[HarmonyPatch(typeof(Station), "AddReward")]
private static void Prefix(Station __instance, StationReward reward)
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Invalid comparison between Unknown and I4
if (!__instance.GameRun.HasJadeBox<ReplacementJadebox>() || (int)reward.Type != 1)
{
return;
}
for (int i = 0; i < reward.Cards.Count; i++)
{
if (reward.Cards[i].Config.Owner != null)
{
continue;
}
if (BepinexPlugin.cardRewardRemoveInstead.Value)
{
BepinexPlugin.log.LogInfo((object)("Removing neutral card reward: " + ((GameEntity)reward.Cards[i]).Name));
reward.Cards.RemoveAt(i);
i--;
}
else if (BepinexPlugin.allowCardRewardReplacement.Value)
{
BepinexPlugin.log.LogInfo((object)("Replacing neutral card reward: " + ((GameEntity)reward.Cards[i]).Name));
Card val = ReplacementRewardCard(__instance, reward.Cards);
if (val != null)
{
reward.Cards[i] = val;
}
else
{
BepinexPlugin.log.LogInfo((object)"No new card found");
}
}
else
{
BepinexPlugin.log.LogInfo((object)"Not allowing replacement or removal of neutral card rewards");
}
}
}
[HarmonyPatch(typeof(Stage), "GetShopNormalCards")]
private static void Postfix(Stage __instance, ref Card[] __result)
{
if (!((GameEntity)__instance).GameRun.HasJadeBox<ReplacementJadebox>() || !BepinexPlugin.allowShopReplacement.Value)
{
return;
}
for (int i = 0; i < __result.Length; i++)
{
if (__result[i].Config.Owner == null)
{
BepinexPlugin.log.LogInfo((object)("Replacing neutral card in shop: " + ((GameEntity)__result[i]).Name + " at slot " + (i + 1)));
Card val = ReplacementShopCard(__instance, __result[i], __result.Select((Card c) => ((GameEntity)c).Id).ToList());
if (val != null)
{
__result[i] = val;
}
else
{
BepinexPlugin.log.LogInfo((object)("No new card found for slot " + (i + 1)));
}
}
}
}
private static Card ReplacementRewardCard(Station __instance, List<Card> oldCards)
{
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Expected O, but got Unknown
OwnerWeightTable val = (BepinexPlugin.cardRewardReplaceWithOtherPool.Value ? OwnerWeightTable.OnlyOther : OwnerWeightTable.PlayerAndFriend);
Predicate<CardConfig> predicate = (CardConfig config) => !oldCards.Any((Card oc) => ((GameEntity)oc).Id == config.Id);
string name = ((object)__instance).GetType().Name;
if (1 == 0)
{
}
RarityWeightTable val2 = (RarityWeightTable)(name switch
{
"EnemyStation" => RarityWeightTable.EnemyCard,
"EliteEnemyStation" => RarityWeightTable.EliteCard,
"BossStation" => RarityWeightTable.OnlyRare,
_ => RarityWeightTable.EnemyCard,
});
if (1 == 0)
{
}
RarityWeightTable val3 = val2;
return __instance.GameRun.RollCard(__instance.GameRun.CardRng, new CardWeightTable(val3, val, CardTypeWeightTable.CanBeLoot, false), false, false, predicate);
}
private static Card ReplacementShopCard(Stage __instance, Card oldCard, List<string> oldCardIds)
{
//IL_001b: 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_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Expected I4, but got Unknown
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Expected O, but got Unknown
OwnerWeightTable val = (BepinexPlugin.shopReplaceWithOtherPool.Value ? OwnerWeightTable.OnlyOther : OwnerWeightTable.PlayerAndFriend);
CardType cardType = oldCard.CardType;
if (1 == 0)
{
}
CardTypeWeightTable val2 = (CardTypeWeightTable)((cardType - 1) switch
{
0 => CardTypeWeightTable.OnlyAttack,
1 => CardTypeWeightTable.OnlyDefense,
2 => CardTypeWeightTable.OnlySkill,
3 => CardTypeWeightTable.OnlyAbility,
_ => CardTypeWeightTable.OnlyAttack,
});
if (1 == 0)
{
}
CardTypeWeightTable val3 = val2;
return ((GameEntity)__instance).GameRun.GetShopCards(1, new CardWeightTable(RarityWeightTable.ShopCard, val, val3, true), oldCardIds)[0];
}
}
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)
{
}
}
}