using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Logging; using DiskCardGame; using HarmonyLib; using InscryptionAPI.Ascension; using InscryptionAPI.Helpers; using OLD_SA.Random; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("OldSa_Challenge")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("OldSa_Challenge")] [assembly: AssemblyCopyright("Copyright © 2026")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("7bddb5c6-b65b-44d7-8bf7-754e15af94f3")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] namespace OldSa_Challenge; public static class ChallengeRegistry { public static AscensionChallengeInfo NoGrowthChallenge; public const string NoGrowthName = "No Growth"; public const string NoGrowthDescription = "Fledgling sigils no longer evolve. They only grant +1 Power and +1 Health."; public static AscensionChallengeInfo NoWoodcarverChallenge; public const string NoWoodcarverName = "No Woodcarver"; public const string NoWoodcarverDescription = "You will no longer encounter Woodcarver choice nodes."; public static AscensionChallengeInfo DizzyStartersChallenge; public const string DizzyStartersName = "Dizzy Starters"; public const string DizzyStartersDescription = "All creatures in your starting deck gain the Random sigil."; public static AscensionChallenge NoGrowthChallengeType => (AscensionChallenge)(((Object)(object)NoGrowthChallenge != (Object)null) ? ((int)NoGrowthChallenge.challengeType) : 0); public static AscensionChallenge NoWoodcarverChallengeType => (AscensionChallenge)(((Object)(object)NoWoodcarverChallenge != (Object)null) ? ((int)NoWoodcarverChallenge.challengeType) : 0); public static AscensionChallenge DizzyStartersChallengeType => (AscensionChallenge)(((Object)(object)DizzyStartersChallenge != (Object)null) ? ((int)DizzyStartersChallenge.challengeType) : 0); public static void Register() { Plugin.Log.LogInfo((object)"[OldSa Challenge] Registering challenges..."); NoGrowthChallenge = FullChallenge.op_Implicit(ChallengeManager.Add("OLD_SA.Challenge", "No Growth", "Fledgling sigils no longer evolve. They only grant +1 Power and +1 Health.", 30, TextureHelper.GetImageAsTexture("NoGrowth.png", (FilterMode)0), TextureHelper.GetImageAsTexture("NoGrowth_Activated.png", (FilterMode)0), 0, false)); Plugin.Log.LogInfo((object)("[OldSa Challenge] Registered: No Growth | ID: " + ((object)Unsafe.As(ref NoGrowthChallenge.challengeType)/*cast due to .constrained prefix*/).ToString())); NoWoodcarverChallenge = FullChallenge.op_Implicit(ChallengeManager.Add("OLD_SA.Challenge", "No Woodcarver", "You will no longer encounter Woodcarver choice nodes.", 30, TextureHelper.GetImageAsTexture("NoWoodcarver.png", (FilterMode)0), TextureHelper.GetImageAsTexture("NoWoodcarver_Activated.png", (FilterMode)0), 0, false)); Plugin.Log.LogInfo((object)("[OldSa Challenge] Registered: No Woodcarver | ID: " + ((object)Unsafe.As(ref NoWoodcarverChallenge.challengeType)/*cast due to .constrained prefix*/).ToString())); DizzyStartersChallenge = FullChallenge.op_Implicit(ChallengeManager.Add("OLD_SA.Challenge", "Dizzy Starters", "All creatures in your starting deck gain the Random sigil.", 30, TextureHelper.GetImageAsTexture("DizzyStarters.png", (FilterMode)0), TextureHelper.GetImageAsTexture("DizzyStarters_Activated.png", (FilterMode)0), 0, false)); Plugin.Log.LogInfo((object)("[OldSa Challenge] Registered: Dizzy Starters | ID: " + ((object)Unsafe.As(ref DizzyStartersChallenge.challengeType)/*cast due to .constrained prefix*/).ToString())); Plugin.Log.LogInfo((object)"[OldSa Challenge] All challenges registered."); } } [HarmonyPatch(typeof(AscensionSaveData), "NewRun")] public static class DizzyStartersPatch { [HarmonyPostfix] public static void Postfix(AscensionSaveData __instance) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Invalid comparison between Unknown and I4 //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Expected O, but got Unknown if (!__instance.ChallengeIsActive(ChallengeRegistry.DizzyStartersChallengeType) || __instance.currentRun == null || __instance.currentRun.playerDeck == null) { return; } Ability randomAbility = RandomAPI.RandomAbility; if ((int)randomAbility == 0) { Plugin.Log.LogError((object)"[OldSa Challenge] Dizzy Starters: Random ability is invalid."); return; } foreach (CardInfo card in ((CardCollectionInfo)__instance.currentRun.playerDeck).Cards) { if (!((Object)(object)card == (Object)null) && !card.HasTrait((Trait)13) && !card.HasAbility(randomAbility)) { CardModificationInfo val = new CardModificationInfo(randomAbility); __instance.currentRun.playerDeck.ModifyCard(card, val); Plugin.Log.LogInfo((object)("[OldSa Challenge] Dizzy Starters: Added Random to " + ((Object)card).name)); } } } } [HarmonyPatch(typeof(Evolve), "OnUpkeep")] public static class NoGrowthPatch { private static readonly FieldRef NumTurnsInPlay = AccessTools.FieldRefAccess("numTurnsInPlay"); private static readonly MethodInfo PreSuccessfulTriggerSequenceMethod = AccessTools.Method(typeof(AbilityBehaviour), "PreSuccessfulTriggerSequence", (Type[])null, (Type[])null); private static readonly PropertyInfo CardProperty = AccessTools.Property(typeof(AbilityBehaviour), "Card"); private static readonly HashSet ProcessedEvolves = new HashSet(); [HarmonyPrefix] public static bool Prefix(Evolve __instance, bool playerUpkeep, ref IEnumerator __result) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance == (Object)null) { return true; } if ((Object)(object)ChallengeRegistry.NoGrowthChallenge == (Object)null || AscensionSaveData.Data == null || !AscensionSaveData.Data.ChallengeIsActive(ChallengeRegistry.NoGrowthChallenge.challengeType)) { return true; } PlayableCard card = GetCard(__instance); if ((Object)(object)card == (Object)null || card.Dead) { return true; } if (card.OpponentCard) { return true; } if (ProcessedEvolves.Contains(__instance)) { __result = EmptySequence(); return false; } __result = NoGrowthOnUpkeep(__instance, card, playerUpkeep); return false; } private static IEnumerator EmptySequence() { yield break; } private static PlayableCard GetCard(Evolve evolve) { if ((Object)(object)evolve == (Object)null || CardProperty == null) { return null; } object? value = CardProperty.GetValue(evolve, null); return (PlayableCard)((value is PlayableCard) ? value : null); } private static IEnumerator NoGrowthOnUpkeep(Evolve evolve, PlayableCard card, bool playerUpkeep) { if ((Object)(object)evolve == (Object)null || (Object)(object)card == (Object)null || card.Dead || card.OpponentCard == playerUpkeep) { yield break; } int turnsToEvolve = ((!((Object)(object)((Card)card).Info != (Object)null) || ((Card)card).Info.evolveParams == null) ? 1 : ((Card)card).Info.evolveParams.turnsToEvolve); int numTurnsInPlay = NumTurnsInPlay.Invoke(evolve); numTurnsInPlay++; NumTurnsInPlay.Invoke(evolve) = numTurnsInPlay; int remaining = Mathf.Max(1, turnsToEvolve - numTurnsInPlay); ((Card)card).RenderInfo.OverrideAbilityIcon((Ability)5, ResourceBank.Get("Art/Cards/AbilityIcons/ability_evolve_" + remaining)); ((Card)card).RenderCard(); if (numTurnsInPlay >= turnsToEvolve) { ProcessedEvolves.Add(evolve); yield return InvokePreSuccessfulTriggerSequence(evolve); if (!((Object)(object)card == (Object)null) && !card.Dead) { Singleton.Instance.SwitchToView((View)4, false, false); yield return (object)new WaitForSeconds(0.15f); ((Card)card).Anim.PlayTransformAnimation(); yield return (object)new WaitForSeconds(0.15f); CardModificationInfo growth = new CardModificationInfo { attackAdjustment = 1, healthAdjustment = 1, singletonId = "OLD_SA_NoGrowth_StatIncrease" }; card.AddTemporaryMod(growth); HideEvolve(card); card.OnStatsChanged(); ((Card)card).RenderCard(); card.UpdateFaceUpOnBoardEffects(); } } } private static void HideEvolve(PlayableCard card) { if (!((Object)(object)card == (Object)null) && card.Status != null) { if (card.Status.hiddenAbilities == null) { card.Status.hiddenAbilities = new List(); } if (!card.Status.hiddenAbilities.Contains((Ability)5)) { card.Status.hiddenAbilities.Add((Ability)5); } ((Card)card).RenderInfo.OverrideAbilityIcon((Ability)5, (Texture)null); ((Card)card).RenderCard(); } } private static IEnumerator InvokePreSuccessfulTriggerSequence(Evolve evolve) { if ((Object)(object)evolve == (Object)null || PreSuccessfulTriggerSequenceMethod == null) { yield break; } object result = PreSuccessfulTriggerSequenceMethod.Invoke(evolve, null); if (result is IEnumerator sequence) { while (sequence.MoveNext()) { yield return sequence.Current; } } } } [HarmonyPatch(typeof(MapGenerator), "ChooseSpecialNodeFromPossibilities")] public static class NoWoodcarverPatch { [HarmonyPrefix] public static void Prefix(List possibilities) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) if (possibilities != null && !((Object)(object)ChallengeRegistry.NoWoodcarverChallenge == (Object)null) && SaveFile.IsAscension && AscensionSaveData.Data.ChallengeIsActive(ChallengeRegistry.NoWoodcarverChallenge.challengeType)) { possibilities.RemoveAll((NodeData node) => node is BuildTotemNodeData); } } } [BepInPlugin("OLD_SA.Challenge", "OLD SA Challenge", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public const string PluginGuid = "OLD_SA.Challenge"; public const string PluginName = "OLD SA Challenge"; public const string PluginVersion = "1.0.0"; internal static ManualLogSource Log; private void Awake() { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; Log.LogInfo((object)"[OldSa Challenge] Plugin loaded."); Harmony val = new Harmony("OLD_SA.Challenge"); val.PatchAll(); Log.LogInfo((object)"[OldSa Challenge] Harmony patches applied."); ChallengeRegistry.Register(); Log.LogInfo((object)"[OldSa Challenge] Initialization complete."); } public static Texture2D LoadTexture(string name) { //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Expected O, but got Unknown using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("OldSa_Challenge.Resources." + name); if (stream == null) { Log.LogError((object)("[World Rules] Missing texture: " + name)); return null; } byte[] array = new byte[stream.Length]; stream.Read(array, 0, array.Length); Texture2D val = new Texture2D(2, 2); ImageConversion.LoadImage(val, array); ((Object)val).name = name; return val; } }