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) 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); } } public class WritheBehaviour : AbilityBehaviour { public override Ability Ability => WritheAPI.ability.Id; } [HarmonyPatch(typeof(PlayableCard), "TakeDamage")] public static class WrithePatch { private static readonly MethodInfo PreSuccessfulTriggerSequenceMethod = AccessTools.Method(typeof(AbilityBehaviour), "PreSuccessfulTriggerSequence", (Type[])null, (Type[])null); private static readonly FieldInfo StatusField = AccessTools.Field(typeof(PlayableCard), "Status"); [HarmonyPrefix] public static bool Prefix(PlayableCard __instance, int damage, PlayableCard attacker, ref IEnumerator __result) { //IL_001b: 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)) { return true; } if (__instance.Dead) { return true; } if (damage <= 0) { return true; } if (damage < __instance.Health) { return true; } int num = Mathf.Max(0, __instance.Attack); int num2 = Mathf.Max(0, __instance.Health - 1); int num3 = damage - num2; if (num3 > num) { return true; } __result = WritheTakeDamageSequence(__instance, damage, attacker, num2, num3); return false; } private static IEnumerator WritheTakeDamageSequence(PlayableCard card, int damage, PlayableCard attacker, int healthDamage, int overflow) { if ((Object)(object)card == (Object)null || card.Dead) { yield break; } WritheBehaviour writhe = ((Component)card).GetComponent(); if ((Object)(object)writhe != (Object)null && PreSuccessfulTriggerSequenceMethod != null) { object result = PreSuccessfulTriggerSequenceMethod.Invoke(writhe, null); if (result is IEnumerator sequence) { while (sequence.MoveNext()) { yield return sequence.Current; } } } if ((Object)(object)card == (Object)null || card.Dead) { yield break; } PlayableCardStatus status = card.Status; status.damageTaken += healthDamage; if (card.Health > 0) { ((Card)card).Anim.PlayHitAnimation(); } if (overflow > 0) { CardModificationInfo attackLoss = new CardModificationInfo { attackAdjustment = -overflow, singletonId = "OLD_SA_Writhe_AttackLoss" }; card.AddTemporaryMod(attackLoss); } card.OnStatsChanged(); ((Card)card).RenderCard(); card.UpdateFaceUpOnBoardEffects(); if ((Object)(object)card.TriggerHandler != (Object)null && card.TriggerHandler.RespondsToTrigger((Trigger)8, new object[1] { attacker })) { yield return card.TriggerHandler.OnTrigger((Trigger)8, new object[1] { attacker }); } if ((Object)(object)attacker != (Object)null) { if ((Object)(object)attacker.TriggerHandler != (Object)null && attacker.TriggerHandler.RespondsToTrigger((Trigger)9, new object[2] { damage, card })) { yield return attacker.TriggerHandler.OnTrigger((Trigger)9, new object[2] { damage, card }); } yield return Singleton.Instance.TriggerCardsOnBoard((Trigger)19, false, new object[3] { attacker, attacker.Attack, card }); } } }