1
0
Fork 0

Merge EnemyAI.OnDestroy patch with cleanups into existing Behaviour

That Harmony patch predated MuzikaGromcheJesterNetworkBehaviour, but
there is no need to have as a separate class, especially not with the
subclass check hack.
This commit is contained in:
ivan tkachenko 2026-01-16 18:21:33 +02:00
parent 908ddeb862
commit 3041d9f73c
1 changed files with 29 additions and 29 deletions

View File

@ -1186,7 +1186,6 @@ namespace MuzikaGromche
Harmony = new Harmony(MyPluginInfo.PLUGIN_NAME); Harmony = new Harmony(MyPluginInfo.PLUGIN_NAME);
Harmony.PatchAll(typeof(GameNetworkManagerPatch)); Harmony.PatchAll(typeof(GameNetworkManagerPatch));
Harmony.PatchAll(typeof(JesterPatch)); Harmony.PatchAll(typeof(JesterPatch));
Harmony.PatchAll(typeof(EnemyAIPatch));
Harmony.PatchAll(typeof(PoweredLightsAnimatorsPatch)); Harmony.PatchAll(typeof(PoweredLightsAnimatorsPatch));
Harmony.PatchAll(typeof(AllPoweredLightsPatch)); Harmony.PatchAll(typeof(AllPoweredLightsPatch));
Harmony.PatchAll(typeof(DiscoBallTilePatch)); Harmony.PatchAll(typeof(DiscoBallTilePatch));
@ -3116,6 +3115,9 @@ namespace MuzikaGromche
public override void OnDestroy() public override void OnDestroy()
{ {
Config.Volume.SettingChanged -= UpdateVolume; Config.Volume.SettingChanged -= UpdateVolume;
DeathScreenGameOverTextManager.Clear();
Stop();
} }
private void UpdateVolume(object sender, EventArgs e) private void UpdateVolume(object sender, EventArgs e)
@ -3247,6 +3249,30 @@ namespace MuzikaGromche
Plugin.Log.LogDebug($"Play Intro: dspTime={AudioSettings.dspTime:N4}, intro.time={IntroAudioSource.time:N4}/{IntroAudioSource.clip.length:N4}, scheduled Loop={loopStartDspTime}"); Plugin.Log.LogDebug($"Play Intro: dspTime={AudioSettings.dspTime:N4}, intro.time={IntroAudioSource.time:N4}/{IntroAudioSource.clip.length:N4}, scheduled Loop={loopStartDspTime}");
} }
public void Stop()
{
PoweredLightsBehaviour.Instance.ResetLightColor();
DiscoBallManager.Disable();
ScreenFiltersManager.Clear();
if (IntroAudioSource != null)
{
IntroAudioSource.Stop();
IntroAudioSource.clip = null;
}
if (LoopAudioSource != null)
{
LoopAudioSource.Stop();
LoopAudioSource.clip = null;
}
BeatTimeState = null;
// Just in case if players have spawned multiple Jesters,
// Don't reset Config.CurrentTrack to null,
// so that the latest chosen track remains set.
CurrentTrack = null;
}
public void OverrideDeathScreenGameOverText() public void OverrideDeathScreenGameOverText()
{ {
if (CurrentTrack == null) if (CurrentTrack == null)
@ -3266,8 +3292,7 @@ namespace MuzikaGromche
static void SetJesterInitialValuesPostfix(JesterAI __instance) static void SetJesterInitialValuesPostfix(JesterAI __instance)
{ {
var behaviour = __instance.GetComponent<MuzikaGromcheJesterNetworkBehaviour>(); var behaviour = __instance.GetComponent<MuzikaGromcheJesterNetworkBehaviour>();
behaviour.IntroAudioSource.Stop(); behaviour.Stop();
behaviour.LoopAudioSource.Stop();
#if DEBUG #if DEBUG
// Almost instant follow timer // Almost instant follow timer
@ -3415,12 +3440,9 @@ namespace MuzikaGromche
// transition away from state 2 ("poppedOut"), normally to state 0 // transition away from state 2 ("poppedOut"), normally to state 0
if (__state.previousState == 2 && __instance.previousState != 2) if (__state.previousState == 2 && __instance.previousState != 2)
{ {
PoweredLightsBehaviour.Instance.ResetLightColor(); behaviour.Stop();
DiscoBallManager.Disable();
ScreenFiltersManager.Clear();
// Rotate track groups // Rotate track groups
behaviour.ChooseTrack(); behaviour.ChooseTrack();
behaviour.BeatTimeState = null;
} }
// Manage the timeline: switch color of the lights according to the current playback/beat position. // Manage the timeline: switch color of the lights according to the current playback/beat position.
@ -3472,26 +3494,4 @@ namespace MuzikaGromche
} }
} }
} }
[HarmonyPatch(typeof(EnemyAI))]
static class EnemyAIPatch
{
// JesterAI class does not override abstract method OnDestroy,
// so we have to patch its superclass directly.
[HarmonyPatch(nameof(EnemyAI.OnDestroy))]
[HarmonyPrefix]
static void CleanUpOnDestroy(EnemyAI __instance)
{
if (__instance is JesterAI)
{
PoweredLightsBehaviour.Instance.ResetLightColor();
DiscoBallManager.Disable();
DeathScreenGameOverTextManager.Clear();
ScreenFiltersManager.Clear();
// Just in case if players have spawned multiple Jesters,
// Don't reset Config.CurrentTrack to null,
// so that the latest chosen track remains set.
}
}
}
} }