From 730f125d629a9654b5d6b943bdd087eb4838bf9c Mon Sep 17 00:00:00 2001 From: ivan tkachenko Date: Mon, 21 Jul 2025 01:06:45 +0300 Subject: [PATCH] Patch Jester destructor to reset the light show It is needed to despawn Jester via Imperium's Object Explorer. --- MuzikaGromche/Plugin.cs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/MuzikaGromche/Plugin.cs b/MuzikaGromche/Plugin.cs index d8e7ec0..10a3d64 100644 --- a/MuzikaGromche/Plugin.cs +++ b/MuzikaGromche/Plugin.cs @@ -528,7 +528,9 @@ namespace MuzikaGromche } Config = new Config(base.Config); DiscoBallManager.Initialize(); - new Harmony(PluginInfo.PLUGIN_NAME).PatchAll(typeof(JesterPatch)); + var harmony = new Harmony(PluginInfo.PLUGIN_NAME); + harmony.PatchAll(typeof(JesterPatch)); + harmony.PatchAll(typeof(EnemyAIPatch)); } else { @@ -1875,6 +1877,26 @@ namespace MuzikaGromche } } + [HarmonyPatch(typeof(EnemyAI))] + internal class EnemyAIPatch + { + // JesterAI class does not override abstract method OnDestroy, + // so we have to patch its superclass directly. + [HarmonyPatch(nameof(EnemyAI.OnDestroy))] + [HarmonyPrefix] + public static void CleanUpOnDestroy(EnemyAI __instance) + { + if (__instance is JesterAI) + { + Plugin.ResetLightColor(); + DiscoBallManager.Disable(); + // Just in case if players have spawned multiple Jesters, + // Don't reset Plugin.CurrentTrack and Plugin.BeatTimeState to null, + // so that the code wouldn't crash without extra null checks. + } + } + } + internal class State { public AudioSource farAudio;