From d1732c7aa7a7bf6cae80d1e2684e883fcc5f37bb Mon Sep 17 00:00:00 2001 From: ocean Date: Sun, 26 Jul 2026 23:39:04 +0100 Subject: [PATCH 1/3] add "IPlayCustomPowerSfx" interface --- Hooks/IPlayCustomPowerSfx.cs | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Hooks/IPlayCustomPowerSfx.cs diff --git a/Hooks/IPlayCustomPowerSfx.cs b/Hooks/IPlayCustomPowerSfx.cs new file mode 100644 index 00000000..e8a6e4b3 --- /dev/null +++ b/Hooks/IPlayCustomPowerSfx.cs @@ -0,0 +1,47 @@ +using System.Reflection.Emit; +using BaseLib.Utils.Patching; +using Godot; +using HarmonyLib; +using MegaCrit.Sts2.Core.Commands; +using MegaCrit.Sts2.Core.Models; +using MegaCrit.Sts2.Core.Nodes.Combat; + +namespace BaseLib.Hooks; + +/// +/// Interface for a power that plays a sound when applied other than the default +/// +public interface IPlayCustomPowerSfx +{ + /// + /// Play the desired custom sfx using + /// + /// Is true if the buff sfx would have played, otherwise the debuff sfx would have played + /// Whether or not the sound played (if false, the default power apply sound plays) + public bool PlayCustomPowerSfx(bool isBuff); + + [HarmonyDebug] + [HarmonyPatch(typeof(NCreature), nameof(NCreature.OnPowerIncreased))] + private class IPlayCustomPowerSfxPatch + { + public static List Transpiler(IEnumerable instructions) => new InstructionPatcher(instructions) + .Match(new InstructionMatcher() + .callvirt(AccessTools.PropertyGetter(typeof(PowerModel), nameof(PowerModel.ShouldPlayVfx))) + ) + .GetOperandLabel(out var target) // where to go if we want to skip the default power sfx + .Step(1) + .Insert([ + CodeInstruction.LoadArgument(1), + CodeInstruction.LoadLocal(1), + CodeInstruction.Call(typeof(IPlayCustomPowerSfxPatch), nameof(PlaySfx)), // check if a custom sound should play and play it if so + new CodeInstruction(OpCodes.Brtrue_S, target), // if a custom sound played, skip playing the default one + ]); + + private static bool PlaySfx(PowerModel power, bool isBuff) + { + if (power is IPlayCustomPowerSfx custom) + return custom.PlayCustomPowerSfx(isBuff); + return false; + } + } +} \ No newline at end of file From c394064917161654e846625ec7e4f58dcb36ac81 Mon Sep 17 00:00:00 2001 From: ocean Date: Sun, 26 Jul 2026 23:39:51 +0100 Subject: [PATCH 2/3] remove harmonydebug annotation --- Hooks/IPlayCustomPowerSfx.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Hooks/IPlayCustomPowerSfx.cs b/Hooks/IPlayCustomPowerSfx.cs index e8a6e4b3..cb6b3018 100644 --- a/Hooks/IPlayCustomPowerSfx.cs +++ b/Hooks/IPlayCustomPowerSfx.cs @@ -20,7 +20,6 @@ public interface IPlayCustomPowerSfx /// Whether or not the sound played (if false, the default power apply sound plays) public bool PlayCustomPowerSfx(bool isBuff); - [HarmonyDebug] [HarmonyPatch(typeof(NCreature), nameof(NCreature.OnPowerIncreased))] private class IPlayCustomPowerSfxPatch { From 0c375bc9ac64c5ecb456d453f8ce1aabacaf2e8a Mon Sep 17 00:00:00 2001 From: ocean Date: Mon, 27 Jul 2026 04:40:24 +0100 Subject: [PATCH 3/3] add amount parameter --- Hooks/IPlayCustomPowerSfx.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Hooks/IPlayCustomPowerSfx.cs b/Hooks/IPlayCustomPowerSfx.cs index cb6b3018..f682ba87 100644 --- a/Hooks/IPlayCustomPowerSfx.cs +++ b/Hooks/IPlayCustomPowerSfx.cs @@ -1,6 +1,5 @@ using System.Reflection.Emit; using BaseLib.Utils.Patching; -using Godot; using HarmonyLib; using MegaCrit.Sts2.Core.Commands; using MegaCrit.Sts2.Core.Models; @@ -16,9 +15,10 @@ public interface IPlayCustomPowerSfx /// /// Play the desired custom sfx using /// + /// The amount of power applied /// Is true if the buff sfx would have played, otherwise the debuff sfx would have played /// Whether or not the sound played (if false, the default power apply sound plays) - public bool PlayCustomPowerSfx(bool isBuff); + public bool PlayCustomPowerSfx(int amount, bool isBuff); [HarmonyPatch(typeof(NCreature), nameof(NCreature.OnPowerIncreased))] private class IPlayCustomPowerSfxPatch @@ -31,15 +31,16 @@ private class IPlayCustomPowerSfxPatch .Step(1) .Insert([ CodeInstruction.LoadArgument(1), + CodeInstruction.LoadArgument(2), CodeInstruction.LoadLocal(1), CodeInstruction.Call(typeof(IPlayCustomPowerSfxPatch), nameof(PlaySfx)), // check if a custom sound should play and play it if so new CodeInstruction(OpCodes.Brtrue_S, target), // if a custom sound played, skip playing the default one ]); - private static bool PlaySfx(PowerModel power, bool isBuff) + private static bool PlaySfx(PowerModel power, int amount, bool isBuff) { if (power is IPlayCustomPowerSfx custom) - return custom.PlayCustomPowerSfx(isBuff); + return custom.PlayCustomPowerSfx(amount, isBuff); return false; } }