From 7b6370b0b06cead3711361ae94193a994e18684b Mon Sep 17 00:00:00 2001 From: WhistleWind <69230920+HumabHatterZed@users.noreply.github.com> Date: Wed, 18 Nov 2026 17:25:03 -0800 Subject: [PATCH 1/2] Add CardRenderInfoManager --- InscryptionAPI/Card/CardRenderInfoManager.cs | 137 +++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 InscryptionAPI/Card/CardRenderInfoManager.cs diff --git a/InscryptionAPI/Card/CardRenderInfoManager.cs b/InscryptionAPI/Card/CardRenderInfoManager.cs new file mode 100644 index 00000000..da60c706 --- /dev/null +++ b/InscryptionAPI/Card/CardRenderInfoManager.cs @@ -0,0 +1,137 @@ +using DiskCardGame; +using HarmonyLib; +using InscryptionAPI.Helpers; +using InscryptionAPI.Triggers; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Reflection.Emit; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace InscryptionAPI.Card; + +/// +/// Helper class that adds patchable methods for easily modifying a card's data during runtime. +/// +/// +/// Currently adds support for:
+/// modifying the attack text colour used in
+/// modifying the health text colour used in +///
+[HarmonyPatch] +public static class CardRenderInfoManager { + /// + /// This event runs every time is called. + /// By adding listeners to this event, you can modify what colour cards' attack text is. + /// + /// + /// Explanation of Func variables:
+ /// + /// defaultColthe vanilla attack text colour. + /// cardthe card whose attack text colour is being modified. + /// hasPassiveBuffsthe return value of . + /// + /// Returns the that the card's attack text will be set to. + ///
+ public static event Func ModifyAttackTextColour; + /// + /// This event runs every time is called. + /// By adding listeners to this event, you can modify what colour cards' health text is. + /// + /// + /// Explanation of Func variables:
+ /// + /// defaultColthe vanilla attack text colour. + /// cardthe card whose attack text colour is being modified. + /// renderInfothe render info for the current . + /// isUninjuredIf the card's health is greater or equal to its max. If card is null, this is true if the render info's current health is greater or equal to the base info's health. + /// + /// Returns the that the card's health text will be set to. + ///
+ public static event Func ModifyHealthTextColour; + + /// + /// Determines if the given has any attack buffs from passive attack sigils or stat icons. + /// + /// The to check. + /// True if the sum of this card's passive attack buffs is NOT zero. + public static bool HasAttackBuffs(PlayableCard card) { + return (card.GetPassiveAttackBuffs() + card.GetStatIconAttackBuffs()) != 0; + } + /// + /// Updates the attack text colour when is called. + /// + /// The to check. + /// The colour to set the attack text to. + public static Color UpdateAttackColour(PlayableCard card) { + bool hasPassiveAttackBuffs = HasAttackBuffs(card); + Color defaultColour = hasPassiveAttackBuffs ? GameColors.Instance.darkBlue : Color.black; + + if (ModifyAttackTextColour != null) { + return ModifyAttackTextColour.Invoke(defaultColour, card, hasPassiveAttackBuffs); + } + return defaultColour; + } + + /// + /// Updates the attack text colour when is called. + /// + /// If or 's health is greater or equal to its max or base health respectively. + /// The to check. Can be null. + /// The render info of the card being rendered. + /// The colour to set the health text to. + public static Color UpdateHealthColour(CardRenderInfo renderInfo, PlayableCard card, bool isUninjured) { + Color defaultColour = isUninjured ? renderInfo.healthTextColor : GameColors.Instance.darkFuschia; + + if (ModifyHealthTextColour != null) { + return ModifyHealthTextColour.Invoke(defaultColour, card, renderInfo, isUninjured); + } + return defaultColour; + } + + #region Transpilers + [HarmonyTranspiler, HarmonyPatch(typeof(PlayableCard), nameof(PlayableCard.OnStatsChanged))] + private static IEnumerable AddHookToModifyAttackTextColour(IEnumerable instructions) { + List codes = new(instructions); + + MethodBase customMethod = AccessTools.Method(typeof(CardRenderInfoManager), nameof(CardRenderInfoManager.UpdateAttackColour), + new Type[] { typeof(PlayableCard) }); + + int startIndex = codes.FindIndex( + x => x.opcode == OpCodes.Callvirt && x.operand.ToString() == "Int32 GetPassiveAttackBuffs()"); + + int endIndex = codes.FindIndex( + x => x.opcode == OpCodes.Stfld && x.operand.ToString() == "UnityEngine.Color attackTextColor"); + + codes.RemoveRange(startIndex, endIndex - startIndex); + codes.Insert(startIndex, new(OpCodes.Callvirt, customMethod)); + + return codes; + } + + [HarmonyTranspiler, HarmonyPatch(typeof(CardDisplayer), nameof(CardDisplayer.SetTextColors))] + private static IEnumerable AddHookToModifyHealthTextColour(IEnumerable instructions) { + List codes = new(instructions); + + MethodBase customMethod = AccessTools.Method(typeof(CardRenderInfoManager), nameof(CardRenderInfoManager.UpdateHealthColour), + new Type[] { typeof(CardRenderInfo), typeof(PlayableCard), typeof(bool) }); + + int startIndex = codes.FindIndex(x => x.opcode == OpCodes.Ldloc_0) - 1; + + int endIndex = codes.FindIndex( + x => x.opcode == OpCodes.Callvirt && x.operand.ToString() == "Void SetHealthTextColor(UnityEngine.Color)"); + + codes.RemoveRange(startIndex, endIndex - startIndex); + codes.Insert(startIndex, new(OpCodes.Callvirt, customMethod)); + codes.Insert(startIndex, new(OpCodes.Ldloc_0)); + codes.Insert(startIndex, new(OpCodes.Ldarg_2)); + codes.Insert(startIndex, new(OpCodes.Ldarg_1)); + codes.Insert(startIndex, new(OpCodes.Ldarg_0)); + + return codes; + } + #endregion +} From ab49bf94066a16d38110693817c3148f5f309ccf Mon Sep 17 00:00:00 2001 From: WhistleWind <69230920+HumabHatterZed@users.noreply.github.com> Date: Wed, 18 Nov 2026 17:27:25 -0800 Subject: [PATCH 2/2] Remove unused usings --- InscryptionAPI/Card/CardRenderInfoManager.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/InscryptionAPI/Card/CardRenderInfoManager.cs b/InscryptionAPI/Card/CardRenderInfoManager.cs index da60c706..219969b5 100644 --- a/InscryptionAPI/Card/CardRenderInfoManager.cs +++ b/InscryptionAPI/Card/CardRenderInfoManager.cs @@ -1,14 +1,7 @@ using DiskCardGame; using HarmonyLib; -using InscryptionAPI.Helpers; -using InscryptionAPI.Triggers; -using System; -using System.Collections.Generic; -using System.Linq; using System.Reflection; using System.Reflection.Emit; -using System.Text; -using System.Threading.Tasks; using UnityEngine; namespace InscryptionAPI.Card;