using System;
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 System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LBoL.Core;
using LBoL.Core.Battle;
using LBoL.Core.Battle.BattleActions;
using LBoL.Core.Cards;
using LBoL.Core.Units;
using LBoL.EntityLib.StatusEffects.ExtraTurn;
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: 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("LongNightTimeLimitMod_Windows")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+b2b53ee366eaab92cebc98a5f168951df5b37195")]
[assembly: AssemblyProduct("LongNightTimeLimitMod_Windows")]
[assembly: AssemblyTitle("LongNightTimeLimitMod_Windows")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace LongNightTimeLimit
{
[BepInPlugin("rokk.lbol.gameplay.LongNightTimeLimit", "LongNightTimeLimit", "0.0.2")]
[BepInProcess("LBoL.exe")]
public class BepinexPlugin : BaseUnityPlugin
{
public static string modUniqueID = "LongNightTimeLimitMod";
private static readonly Harmony harmony = PInfo.harmony;
internal static ManualLogSource log;
private static ConfigEntry<int> FreeReshuffles;
private static ConfigEntry<bool> DrawStepIsFree;
private static ConfigEntry<int> EveryXReshuffles;
private static ConfigEntry<int> TimeLimitStackGainCount;
private static ConfigEntry<bool> GiftsGivenIsFree;
public static int ConfigFreeReshuffles => FreeReshuffles.Value;
public static bool ConfigDrawStepIsFree => DrawStepIsFree.Value;
public static int ConfigEveryXReshuffles => EveryXReshuffles.Value;
public static int ConfigTimeLimitStackGainCount => TimeLimitStackGainCount.Value;
public static bool ConfigGiftsGivenIsFree => GiftsGivenIsFree.Value;
private void Awake()
{
log = ((BaseUnityPlugin)this).Logger;
Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
log.LogDebug((object)"Setting up config for LongNightTimeLimitMod v0.0.2");
SetupConfig();
log.LogDebug((object)"Done setting up config for LongNightTimeLimitMod");
log.LogDebug((object)"Running Harmony patches for LongNightTimeLimitMod");
harmony.PatchAll();
log.LogDebug((object)"Done running Harmony patches for LongNightTimeLimitMod");
}
private void OnDestroy()
{
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
private void SetupConfig()
{
FreeReshuffles = ((BaseUnityPlugin)this).Config.Bind<int>("Tweaks", "FreeReshuffles", 0, "Amount of reshuffles that are ignored before Time Limit starts being added.");
DrawStepIsFree = ((BaseUnityPlugin)this).Config.Bind<bool>("Tweaks", "DrawStepIsFree", false, "If true, reshuffling during the draw step is always considered free and won't be counted.");
EveryXReshuffles = ((BaseUnityPlugin)this).Config.Bind<int>("Tweaks", "EveryXReshuffles", 2, "1 in X reshuffles will add Time Limit, where X is this value. Only starts counting after the free reshuffles are exhausted.");
TimeLimitStackGainCount = ((BaseUnityPlugin)this).Config.Bind<int>("Tweaks", "TimeLimitStackGainCount", 1, "The amount of Time Limit to be added.");
GiftsGivenIsFree = ((BaseUnityPlugin)this).Config.Bind<bool>("Tweaks", "GiftsGivenIsFree", true, "If true, cards that trigger reshuffles forcibly when played (such as Gifts Given) are considered free and won't be counted. (Currently unused because work in progress, it's unclear if this card even counts in the first place)");
}
}
public static class PInfo
{
public const string GUID = "rokk.lbol.gameplay.LongNightTimeLimit";
public const string Name = "LongNightTimeLimit";
public const string version = "0.0.2";
public static readonly Harmony harmony = new Harmony("rokk.lbol.gameplay.LongNightTimeLimit");
}
}
namespace LongNightTimeLimit.Patches
{
[HarmonyPatch(typeof(BattleController), "StartBattle")]
internal class BattleControllerStartBattlePatches
{
private static int ReshufflesThisTurn;
private static void Postfix(BattleController __instance)
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
ReshufflesThisTurn = 0;
if (((Enum)__instance.GameRun.Puzzles).HasFlag((Enum)(object)(PuzzleFlag)64))
{
((Unit)__instance.Player).TurnStarting.AddHandler((GameEventHandler<UnitEventArgs>)delegate(UnitEventArgs args)
{
HandlePlayerTurnStarting(args, __instance);
}, (GameEventPriority)10);
__instance.Reshuffled.AddHandler((GameEventHandler<GameEventArgs>)delegate(GameEventArgs args)
{
HandleReshuffle(args, __instance);
}, (GameEventPriority)10);
__instance.CardsAddingToHand.AddHandler((GameEventHandler<CardsEventArgs>)delegate(CardsEventArgs args)
{
HandleCardsAddingToHand(args, __instance);
}, (GameEventPriority)int.MinValue);
}
}
private static void HandlePlayerTurnStarting(UnitEventArgs args, BattleController controller)
{
ReshufflesThisTurn = 0;
}
private static void HandleReshuffle(GameEventArgs args, BattleController controller)
{
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Expected O, but got Unknown
if (!controller.BattleShouldEnd && (((Unit)controller.Player).IsInTurn || !BepinexPlugin.ConfigDrawStepIsFree))
{
ReshufflesThisTurn++;
if (ReshufflesThisTurn > BepinexPlugin.ConfigFreeReshuffles && (ReshufflesThisTurn - BepinexPlugin.ConfigFreeReshuffles) % BepinexPlugin.ConfigEveryXReshuffles == 0)
{
controller.React(new Reactor((BattleAction)(object)new ApplyStatusEffectAction<TimeIsLimited>((Unit)(object)controller.Player, (int?)BepinexPlugin.ConfigTimeLimitStackGainCount, (int?)null, (int?)null, (int?)null, 0f, true)), (GameEntity)(object)controller.Player, (ActionCause)9);
}
}
}
private static void HandleCardsAddingToHand(CardsEventArgs args, BattleController controller)
{
if (args.Cards.Any((Card card) => ((GameEntity)card).Id.StartsWith("NightMana")))
{
((GameEventArgs)args).CancelBy((GameEntity)(object)controller.Player);
}
}
}
[HarmonyPatch(typeof(PuzzleFlagDisplayWord))]
[HarmonyPatch("Description")]
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
internal class PuzzleFlagDisplayWordPatches
{
private static void Postfix(ref string __result)
{
if (__result.StartsWith("At the start of combat, add a"))
{
StringBuilder stringBuilder = new StringBuilder("Whenever you reshuffle the discard pile into the draw pile");
if (BepinexPlugin.ConfigFreeReshuffles > 0)
{
stringBuilder.Append(" more than ");
stringBuilder.Append(BepinexPlugin.ConfigFreeReshuffles);
stringBuilder.Append((BepinexPlugin.ConfigFreeReshuffles != 1) ? " times" : " time");
}
stringBuilder.Append($" during your turn, gain Time Limit <sprite=\"ManaSprite\" name=\"{BepinexPlugin.ConfigTimeLimitStackGainCount}\">");
if (BepinexPlugin.ConfigEveryXReshuffles > 1)
{
stringBuilder.Append($" every {BepinexPlugin.ConfigEveryXReshuffles} reshuffles.");
}
else
{
stringBuilder.Append(".");
}
if (BepinexPlugin.ConfigDrawStepIsFree)
{
stringBuilder.Append(" Reshuffling during the draw step does not count towards this penalty.");
}
__result = stringBuilder.ToString();
}
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
internal IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}