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 AddWatermark;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using HarmonyLib;
using LBoL.Base;
using LBoL.ConfigData;
using LBoL.Core;
using LBoL.Core.Adventures;
using LBoL.Core.Battle;
using LBoL.Core.Battle.BattleActions;
using LBoL.Core.Cards;
using LBoL.Core.Randoms;
using LBoL.Core.Units;
using LBoL.EntityLib.Adventures;
using LBoL.EntityLib.StatusEffects.Basic;
using LBoL.Presentation.UI.Panels;
using LBoL.Presentation.UI.Widgets;
using LBoLEntitySideloader;
using LBoLEntitySideloader.Attributes;
using LBoLEntitySideloader.Entities;
using LBoLEntitySideloader.Resource;
using LBoLEntitySideloader.Utils;
using UnityEngine;
using UnityEngine.Events;
using Yarn;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[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("CyanToolbox")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CyanToolbox")]
[assembly: AssemblyTitle("CyanToolbox")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace CyanToolbox
{
[BepInPlugin("cyaneko.lbol.mods.toolbox", "Cyan's Toolbox", "0.2.2")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[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 IResourceSource embeddedSource = (IResourceSource)new EmbeddedSource(Assembly.GetExecutingAssembly());
internal static TemplateSequenceTable sequenceTable = new TemplateSequenceTable(0);
internal static DirectorySource directorySource = new DirectorySource("cyaneko.lbol.mods.toolbox", "");
internal static BatchLocalization batchLoc = new BatchLocalization((IResourceSource)(object)directorySource, typeof(JadeBoxTemplate), "JadeBoxEX_", (Locale)0, false);
private void Awake()
{
log = ((BaseUnityPlugin)this).Logger;
Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
EntityManager.RegisterSelf();
harmony.PatchAll();
if (Chainloader.PluginInfos.ContainsKey("neo.lbol.tools.watermark"))
{
WatermarkWrapper.ActivateWatermark();
}
}
private void OnDestroy()
{
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
}
public class JadeBoxes
{
public sealed class HighlanderDef : JadeBoxTemplate
{
[EntityLogic(typeof(HighlanderDef))]
public sealed class HighlanderJadebox : JadeBox
{
[HarmonyPatch(typeof(GameRunController), "RollCards", new Type[]
{
typeof(RandomGen),
typeof(CardWeightTable),
typeof(int),
typeof(ManaGroup?),
typeof(bool),
typeof(bool),
typeof(bool),
typeof(bool),
typeof(Predicate<CardConfig>)
})]
private class GameRunController_RollCards
{
private static void Prefix(ref bool battleRolling, ref Predicate<CardConfig> filter, GameRunController __instance)
{
if (IsHighlander(__instance) && !battleRolling)
{
Predicate<CardConfig> predCopy = filter;
filter = (CardConfig cfg) => AlsoAbsentFromLibrary(__instance, predCopy, cfg);
}
}
}
public static bool IsHighlander(GameRunController run)
{
if (run == null)
{
return false;
}
return run.HasJadeBox<HighlanderJadebox>();
}
public static bool AlsoAbsentFromLibrary(GameRunController run, Predicate<CardConfig> prevPred, CardConfig cardCfg)
{
if (prevPred == null || prevPred(cardCfg))
{
return !run.BaseDeck.Any((Card card) => card.Config.Id == cardCfg.Id);
}
return false;
}
}
public override IdContainer GetId()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
return IdContainer.op_Implicit("HighlanderJadebox");
}
public override JadeBoxConfig MakeConfig()
{
return ((JadeBoxTemplate)this).DefaultConfig();
}
public override LocalizationOption LoadLocalization()
{
return (LocalizationOption)(object)BepinexPlugin.batchLoc.AddEntity((EntityDefinition)(object)this);
}
}
public sealed class NightOfNightmaresDef : JadeBoxTemplate
{
[EntityLogic(typeof(NightOfNightmaresDef))]
public sealed class NightOfNightmaresJadebox : JadeBox
{
[HarmonyPatch(typeof(ManaFreezer))]
private class ManaFreezer_FreezeLevel
{
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
[HarmonyPostfix]
private static void SetFreezeLevel(ManaFreezer __instance, ref int __result)
{
if (IsNightOfNightmares(((GameEntity)__instance).GameRun))
{
if (__instance is NightMana2)
{
__result = 2;
}
else if (__instance is NightMana3)
{
__result = 3;
}
else if (__instance is NightMana4)
{
__result = 4;
}
}
}
}
[HarmonyPatch(typeof(BattleController))]
private class BattleController_OnAddCardToHand
{
[HarmonyPatch("AddCardToHand", new Type[] { typeof(Card) })]
[HarmonyPostfix]
private static void SetFreezeTimes(BattleController __instance, ref Card card)
{
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
if (!IsNightOfNightmares(__instance.GameRun))
{
return;
}
Card obj = card;
ManaFreezer val = (ManaFreezer)(object)((obj is ManaFreezer) ? obj : null);
if (val != null)
{
CardConfig val2 = ObjectExtensions.Copy<CardConfig>(((Card)val).Config);
if (val is NightMana1)
{
val2.Mana = ManaGroup.Anys(1);
}
else if (val is NightMana2)
{
val2.Mana = ManaGroup.Anys(2);
}
else if (val is NightMana3)
{
val2.Mana = ManaGroup.Anys(3);
}
else if (val is NightMana4)
{
val2.Mana = ManaGroup.Anys(4);
}
val.FreezeTimes = 1;
((Card)val).Config = val2;
}
}
}
[HarmonyPatch(typeof(StartGamePanel))]
private class StartGamePanel_Awake_Patch
{
[HarmonyPatch("Awake")]
[HarmonyPostfix]
private static void EnsureLongNightIsOn(ref StartGamePanel __instance)
{
try
{
StartGamePanel sgp = __instance;
JadeBoxToggle jt = sgp._jadeBoxToggles.FirstOrDefault((KeyValuePair<JadeBox, JadeBoxToggle> t) => t.Value.JadeBox is NightOfNightmaresJadebox).Value;
JadeBoxToggle obj = jt;
if (obj == null)
{
return;
}
((UnityEvent<bool>)(object)obj.Toggle.onValueChanged).AddListener((UnityAction<bool>)delegate
{
if (jt.IsOn && (!sgp._puzzleToggles.TryGetValue((PuzzleFlag)64, out var value) || !value.Toggle.isOn))
{
jt.Toggle.isOn = false;
}
});
}
catch (Exception arg)
{
BepinexPlugin.log.LogError((object)$"Error while checking jadebox toggle and puzzle flags compat\n{arg}");
}
}
}
public static bool IsNightOfNightmares(GameRunController run)
{
if (run == null)
{
return false;
}
return run.HasJadeBox<NightOfNightmaresJadebox>();
}
}
public override IdContainer GetId()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
return IdContainer.op_Implicit("NightOfNightmaresJadebox");
}
public override JadeBoxConfig MakeConfig()
{
return ((JadeBoxTemplate)this).DefaultConfig();
}
public override LocalizationOption LoadLocalization()
{
return (LocalizationOption)(object)BepinexPlugin.batchLoc.AddEntity((EntityDefinition)(object)this);
}
}
public sealed class RainbowCardsDef : JadeBoxTemplate
{
[EntityLogic(typeof(RainbowCardsDef))]
public sealed class RainbowCardsJadebox : JadeBox
{
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
private class GameRunController_ctor
{
private static void Postfix(GameRunStartupParameters startupParameters, GameRunController __instance)
{
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
if (__instance.HasJadeBox<RainbowCardsJadebox>())
{
__instance.RewardAndShopCardColorLimitFlag += 1;
__instance.AdditionalRewardCardCount += 1;
initialExhibit = startupParameters.InitExhibit;
if (startupParameters.Player.Config.InitialMana + BaseManaGroup.op_Implicit(initialExhibit.BaseMana) == __instance.BaseMana)
{
__instance.GainBaseMana(ManaGroup.Single((ManaColor)7), false);
__instance.LoseBaseMana(BaseManaGroup.op_Implicit(initialExhibit.BaseMana), false);
}
}
}
}
[HarmonyPatch(typeof(Debut), "InitVariables", new Type[] { typeof(IVariableStorage) })]
private class Debut_InitVariables
{
private static void Postfix(Debut __instance, IVariableStorage storage)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
GameRunController gameRun = ((Adventure)__instance).GameRun;
if (gameRun.HasJadeBox<RainbowCardsJadebox>())
{
ManaGroup baseMana = gameRun.BaseMana;
if (initialExhibit == null || !ManaGroupExtensions.IsSuperset(baseMana, BaseManaGroup.op_Implicit(initialExhibit.BaseMana)))
{
storage.SetValue("$twoColorStart", true);
}
}
}
}
private static Exhibit initialExhibit;
}
private const int extraCards = 1;
public override IdContainer GetId()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
return IdContainer.op_Implicit("RainbowCardsJadebox");
}
public override JadeBoxConfig MakeConfig()
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
JadeBoxConfig obj = ((JadeBoxTemplate)this).DefaultConfig();
obj.Value1 = 1;
obj.Mana = ManaGroup.Single((ManaColor)7);
return obj;
}
public override LocalizationOption LoadLocalization()
{
return (LocalizationOption)(object)BepinexPlugin.batchLoc.AddEntity((EntityDefinition)(object)this);
}
}
public sealed class RustyBatteryDef : JadeBoxTemplate
{
[EntityLogic(typeof(RustyBatteryDef))]
public sealed class RustyBatteryJadebox : JadeBox
{
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
private class UltimateSkill_MaxPowerLevel
{
private static void Postfix(UltimateSkill __instance, ref int __result)
{
if (IsRustyBattery(((GameEntity)__instance).GameRun))
{
__result = Math.Max(__result - 1, 1);
}
}
}
public static bool IsRustyBattery(GameRunController run)
{
if (run == null)
{
return false;
}
return run.HasJadeBox<RustyBatteryJadebox>();
}
}
public override IdContainer GetId()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
return IdContainer.op_Implicit("RustyBatteryJadebox");
}
public override JadeBoxConfig MakeConfig()
{
return ((JadeBoxTemplate)this).DefaultConfig();
}
public override LocalizationOption LoadLocalization()
{
return (LocalizationOption)(object)BepinexPlugin.batchLoc.AddEntity((EntityDefinition)(object)this);
}
}
public sealed class ThunderlordDef : JadeBoxTemplate
{
[EntityLogic(typeof(ThunderlordDef))]
public sealed class ThunderlordJadebox : JadeBox
{
protected override void OnEnterBattle()
{
((JadeBox)this).ReactBattleEvent<GameEventArgs>(((JadeBox)this).Battle.BattleStarting, (EventSequencedReactor<GameEventArgs>)OnBattleStart);
((JadeBox)this).ReactBattleEvent<UnitEventArgs>(((JadeBox)this).Battle.EnemySpawned, (EventSequencedReactor<UnitEventArgs>)OnEnemySpawned);
}
private static int GetBuffLevel(int actNum)
{
return Math.Min(actNum, 3);
}
private IEnumerable<BattleAction> OnBattleStart(GameEventArgs args)
{
((JadeBox)this).NotifyActivating();
int actNum = ((GameEntity)this).GameRun._stageIndex + 1;
yield return (BattleAction)(object)new ApplyStatusEffectAction<Electric>((Unit)(object)((JadeBox)this).Battle.Player, (int?)(2 * GetBuffLevel(actNum)), (int?)null, (int?)null, (int?)null, 0f, true);
foreach (EnemyUnit allAliveEnemy in ((JadeBox)this).Battle.AllAliveEnemies)
{
yield return (BattleAction)(object)new ApplyStatusEffectAction<Electric>((Unit)(object)allAliveEnemy, (int?)GetBuffLevel(actNum), (int?)null, (int?)null, (int?)null, 0f, true);
}
}
private IEnumerable<BattleAction> OnEnemySpawned(UnitEventArgs args)
{
((JadeBox)this).NotifyActivating();
int actNum = ((GameEntity)this).GameRun._stageIndex + 1;
yield return (BattleAction)(object)new ApplyStatusEffectAction<Electric>(args.Unit, (int?)GetBuffLevel(actNum), (int?)null, (int?)null, (int?)null, 0f, true);
}
}
private const int playerBuffMultiplier = 2;
private const int enemyBuffMultiplier = 1;
private const int buffCap = 3;
public override IdContainer GetId()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
return IdContainer.op_Implicit("ThunderlordJadebox");
}
public override JadeBoxConfig MakeConfig()
{
JadeBoxConfig obj = ((JadeBoxTemplate)this).DefaultConfig();
obj.Value1 = 2;
obj.Value2 = 1;
return obj;
}
public override LocalizationOption LoadLocalization()
{
return (LocalizationOption)(object)BepinexPlugin.batchLoc.AddEntity((EntityDefinition)(object)this);
}
}
}
public static class PInfo
{
public const string GUID = "cyaneko.lbol.mods.toolbox";
public const string Name = "Cyan's Toolbox";
public const string version = "0.2.2";
public static readonly Harmony harmony = new Harmony("cyaneko.lbol.mods.toolbox");
}
internal class WatermarkWrapper
{
[MethodImpl(MethodImplOptions.NoInlining)]
internal static void ActivateWatermark()
{
API.ActivateWatermark();
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
internal IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}