From c55e7a4107ccb341c8eb7a92e892fa11dbb8e62b Mon Sep 17 00:00:00 2001 From: staphen Date: Fri, 5 Dec 2025 14:43:12 -0500 Subject: [PATCH] Reload sfx when reloading active mods --- Source/diablo.cpp | 2 +- Source/effects.cpp | 7 ++++++- Source/effects.h | 2 +- Source/engine/sound.cpp | 2 +- Source/lua/lua_global.cpp | 8 ++++++++ 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 756a842fc..f006b2a53 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -1790,7 +1790,7 @@ void OptionLanguageCodeChanged() UnloadFonts(); LanguageInitialize(); LoadLanguageArchive(); - effects_cleanup_sfx(); + effects_cleanup_sfx(false); if (gbRunGame) sound_init(); else diff --git a/Source/effects.cpp b/Source/effects.cpp index 703cb6362..fd7aec011 100644 --- a/Source/effects.cpp +++ b/Source/effects.cpp @@ -246,10 +246,15 @@ void sound_update() StreamUpdate(); } -void effects_cleanup_sfx() +void effects_cleanup_sfx(bool fullUnload) { sound_stop(); + if (fullUnload) { + sgSFX.clear(); + return; + } + for (auto &sfx : sgSFX) sfx.pSnd = nullptr; } diff --git a/Source/effects.h b/Source/effects.h index dd1aa258b..e10743279 100644 --- a/Source/effects.h +++ b/Source/effects.h @@ -31,7 +31,7 @@ void PlaySFX(SfxID psfx); void PlaySfxLoc(SfxID psfx, Point position, bool randomizeByCategory = true); void sound_stop(); void sound_update(); -void effects_cleanup_sfx(); +void effects_cleanup_sfx(bool fullUnload = true); void sound_init(); void ui_sound_init(); void effects_play_sound(SfxID); diff --git a/Source/engine/sound.cpp b/Source/engine/sound.cpp index a64848c90..6879c02e8 100644 --- a/Source/engine/sound.cpp +++ b/Source/engine/sound.cpp @@ -171,7 +171,7 @@ int CapVolume(int volume) void OptionAudioChanged() { - effects_cleanup_sfx(); + effects_cleanup_sfx(false); music_stop(); snd_deinit(); snd_init(); diff --git a/Source/lua/lua_global.cpp b/Source/lua/lua_global.cpp index 724c3457c..97043a31d 100644 --- a/Source/lua/lua_global.cpp +++ b/Source/lua/lua_global.cpp @@ -10,6 +10,7 @@ #include #include "appfat.h" +#include "effects.h" #include "engine/assets.hpp" #include "lua/modules/audio.hpp" #include "lua/modules/hellfire.hpp" @@ -229,6 +230,13 @@ void LuaReloadActiveMods() handler(); } + // Reload sound effects in case a mod archive overrides effects.tsv + effects_cleanup_sfx(); + if (gbRunGame) + sound_init(); + else + ui_sound_init(); + // Reload game data (this can probably be done later in the process to avoid having to reload it) LoadTextData(); LoadPlayerDataFiles();