using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; 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.Card; using InscryptionAPI.Helpers; 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_Writhe_sigil")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("OldSa_Writhe_sigil")] [assembly: AssemblyCopyright("Copyright © 2026")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("3560dc46-299b-4da7-9e0a-7b7619f5384f")] [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 OLD_SA.Writhe; [BepInPlugin("OLD_SA.Writhe", "OLD SA Writhe", "1.0.0")] public class Plugin : BaseUnityPlugin { public static ManualLogSource Log; private void Awake() { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; Log.LogInfo((object)"OLD SA Writhe loading..."); WritheAPI.Init(); Harmony val = new Harmony("OLD_SA.Writhe"); val.PatchAll(); Log.LogInfo((object)"OLD SA Writhe loaded."); } } public static class WritheAPI { public static FullAbility ability; public static void Init() { //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) AbilityInfo val = ScriptableObject.CreateInstance(); ((Object)val).name = "Writhe"; val.rulebookName = "Writhe"; val.metaCategories = new List { (AbilityMetaCategory)0, (AbilityMetaCategory)1 }; val.powerLevel = 3; val.opponentUsable = true; val.canStack = false; Texture imageAsTexture = (Texture)(object)TextureHelper.GetImageAsTexture("OldSa_Writhe.png", (FilterMode)0); Texture2D imageAsTexture2 = TextureHelper.GetImageAsTexture("OldSa_Writhe_px.png", (FilterMode)0); val.pixelIcon = Sprite.Create(imageAsTexture2, new Rect(0f, 0f, (float)((Texture)imageAsTexture2).width, (float)((Texture)imageAsTexture2).height), new Vector2(0.5f, 0.5f)); FieldInfo field = typeof(AbilityInfo).GetField("rulebookDescription", BindingFlags.Instance | BindingFlags.NonPublic); if (field != null) { field.SetValue(val, "When [creature] would take lethal damage, it survives with 1 health and loses attack equal to the excess damage. If its attack is 0, it dies."); } ability = AbilityManager.Add("OLD_SA", val, typeof(WritheBehaviour), imageAsTexture); if (!ProgressionData.Data.learnedAbilities.Contains(ability.Id)) { ProgressionData.Data.learnedAbilities.Add(ability.Id); } } } public class WritheBehaviour : AbilityBehaviour { public override Ability Ability => WritheAPI.ability.Id; } [HarmonyPatch] public static class WrithePatch { private static MethodBase TargetMethod() { return AccessTools.Method(typeof(PlayableCard), "TakeDamage", new Type[2] { typeof(int), typeof(PlayableCard) }, (Type[])null); } [HarmonyPrefix] public static bool Prefix(PlayableCard __instance, int damage, PlayableCard attacker, ref IEnumerator __result) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance == (Object)null) { return true; } if (!__instance.HasAbility(WritheAPI.ability.Id) || __instance.Dead || damage <= 0) { return true; } int health = __instance.Health; int num = Mathf.Max(0, __instance.Attack); if (damage < health) { return true; } int num2 = Mathf.Max(0, health - 1); int num3 = damage - num2; if (num3 > num) { return true; } __result = WritheTakeDamageSequence(__instance, num2, num3, damage, attacker); return false; } private static IEnumerator WritheTakeDamageSequence(PlayableCard card, int healthDamage, int overflow, int originalDamage, PlayableCard attacker) { if ((Object)(object)card == (Object)null || card.Dead) { yield break; } AbilityBehaviour writhe = (AbilityBehaviour)(object)((Component)card).GetComponent(); MethodInfo preTriggerMethod = AccessTools.Method(typeof(AbilityBehaviour), "PreSuccessfulTriggerSequence", (Type[])null, (Type[])null); if ((Object)(object)writhe != (Object)null && preTriggerMethod != null && preTriggerMethod.Invoke(writhe, null) is IEnumerator sequence) { yield return sequence; } if ((Object)(object)card == (Object)null || card.Dead) { yield break; } if (healthDamage > 0) { PlayableCardStatus status = card.Status; status.damageTaken += healthDamage; } if ((Object)(object)((Card)card).Anim != (Object)null && card.Health > 0) { ((Card)card).Anim.PlayHitAnimation(); } if (overflow > 0) { CardModificationInfo attackLoss = new CardModificationInfo { attackAdjustment = -overflow }; card.AddTemporaryMod(attackLoss); } card.OnStatsChanged(); ((Card)card).RenderCard(); card.UpdateFaceUpOnBoardEffects(); if ((Object)(object)attacker != (Object)null) { if (attacker.TriggerHandler.RespondsToTrigger((Trigger)9, new object[2] { originalDamage, card })) { yield return attacker.TriggerHandler.OnTrigger((Trigger)9, new object[2] { originalDamage, card }); } yield return Singleton.Instance.TriggerCardsOnBoard((Trigger)19, false, new object[3] { attacker, attacker.Attack, card }); } } }