diff --git a/src/acs/call-funcs.cpp b/src/acs/call-funcs.cpp index b74241a9a..df1f2043e 100644 --- a/src/acs/call-funcs.cpp +++ b/src/acs/call-funcs.cpp @@ -2409,6 +2409,8 @@ bool CallFunc_MusicStopAll(ACSVM::Thread *thread, const ACSVM::Word *argV, ACSVM bool CallFunc_MusicRemap(ACSVM::Thread *thread, const ACSVM::Word *argV, ACSVM::Word argC) { ACSVM::MapScope *map = thread->scopeMap; + ACSVM::String *tuneStr = nullptr; + const char *tune = nullptr; // 0: str tune - id for the tune to play // 1: str song - lump name for the song to map to @@ -2418,6 +2420,15 @@ bool CallFunc_MusicRemap(ACSVM::Thread *thread, const ACSVM::Word *argV, ACSVM:: { return false; } + + tuneStr = map->getString(argV[0]); + tune = tuneStr->str; + + // Do not allow ACS to remap Stereo Mode tunes. + if (strncmp("stere", tune, 5)) + { + return false; + } Music_Remap(map->getString(argV[0])->str, map->getString(argV[1])->str); diff --git a/src/g_game.c b/src/g_game.c index f86871a13..9bf67d600 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -5215,6 +5215,9 @@ static void G_DoContinued(void) // when something new is added. void G_EndGame(void) { + // Clean up ACS music remaps. + Music_TuneReset(); + // Handle voting if (nextmap == NEXTMAP_VOTING) { diff --git a/src/lua_baselib.c b/src/lua_baselib.c index b34f5bcae..102dde47d 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -480,6 +480,12 @@ static int lib_mMusicRemap(lua_State *L) { return LUA_ErrNoTune(L, tune_id); } + + // Do not allow Lua to remap Stereo Mode tunes. + if (strncmp("stere", tune_id, 5)) + { + return LUA_ErrStereo(L, tune_id); + } Music_Remap(tune_id, music_name); diff --git a/src/lua_script.h b/src/lua_script.h index 28f0fecad..41da2591f 100644 --- a/src/lua_script.h +++ b/src/lua_script.h @@ -117,6 +117,9 @@ void COM_Lua_f(void); // Music: "No tune" error. #define LUA_ErrNoTune(L, tune) luaL_error(L, "tune \"%s\" does not exist", tune) +// Music: "Stereo Mode" error. +#define LUA_ErrStereo(L, tune) luaL_error(L, "tune \"%s\" cannot be remapped (stereo mode)", tune) + // Deprecation warnings // Shows once upon use. Then doesn't show again. #define LUA_Deprecated(L,this_func,use_instead)\ diff --git a/src/music.cpp b/src/music.cpp index b50dfaf66..2213842f9 100644 --- a/src/music.cpp +++ b/src/music.cpp @@ -25,6 +25,7 @@ TuneManager g_tunes; void Music_Init(void) { + // Many tunes below now have their default songs set in Music_TuneReset. Check there first for changing those. { Tune& tune = g_tunes.insert("level"); @@ -55,21 +56,21 @@ void Music_Init(void) { Tune& tune = g_tunes.insert("battle_overtime", g_tunes.find("level")); - tune.song = "shwdwn"; + tune.song = ""; // Music_TuneReset tune.priority = 11; } { Tune& tune = g_tunes.insert("battle_overtime_stress", g_tunes.find("battle_overtime")); - tune.song = "shwdn2"; + tune.song = ""; // Music_TuneReset tune.priority = 10; } { Tune& tune = g_tunes.insert("grow"); - tune.song = "kgrow"; + tune.song = ""; // Music_TuneReset tune.priority = 20; tune.resume_fade_in = 200; tune.use_level_volume = true; @@ -78,7 +79,7 @@ void Music_Init(void) { Tune& tune = g_tunes.insert("invinc"); - tune.song = "kinvnc"; + tune.song = ""; // Music_TuneReset tune.priority = 21; tune.use_level_volume = true; } @@ -86,7 +87,7 @@ void Music_Init(void) { Tune& tune = g_tunes.insert("finish_silence"); - tune.song = ""; + tune.song = ""; // Music_TuneReset tune.priority = 30; } @@ -100,7 +101,7 @@ void Music_Init(void) { Tune& tune = g_tunes.insert("comeon"); - tune.song = "chalng"; + tune.song = ""; // Music_TuneReset tune.priority = 35; tune.loop = false; } @@ -116,7 +117,7 @@ void Music_Init(void) { Tune& tune = g_tunes.insert("vote"); - tune.song = "vote"; + tune.song = ""; // Music_TuneReset tune.priority = 50; tune.credit = true; } @@ -124,14 +125,14 @@ void Music_Init(void) { Tune& tune = g_tunes.insert("vote_suspense"); - tune.song = "voteea"; + tune.song = ""; // Music_TuneReset tune.priority = 51; } { Tune& tune = g_tunes.insert("vote_end"); - tune.song = "voteeb"; + tune.song = ""; // Music_TuneReset tune.priority = 52; tune.loop = false; } @@ -139,14 +140,14 @@ void Music_Init(void) { Tune& tune = g_tunes.insert("wait"); - tune.song = "WAIT2J"; + tune.song = ""; // Music_TuneReset tune.priority = 60; } { Tune& tune = g_tunes.insert("title"); - tune.song = "_title"; + tune.song = ""; // Music_TuneReset tune.priority = 100; tune.resist = true; } @@ -167,7 +168,7 @@ void Music_Init(void) { Tune& tune = g_tunes.insert("credits_silence"); - tune.song = ""; + tune.song = ""; // Music_TuneReset tune.priority = 100; } @@ -175,7 +176,7 @@ void Music_Init(void) Tune& tune = g_tunes.insert("credits"); tune.priority = 101; - tune.song = "_creds"; + tune.song = ""; // Music_TuneReset tune.credit = true; } @@ -213,10 +214,12 @@ void Music_Init(void) { Tune& tune = g_tunes.insert("lawyer"); - tune.song = "lawyer"; + tune.song = ""; // Music_TuneReset tune.priority = 35; tune.loop = false; } + + Music_TuneReset(); } @@ -522,3 +525,21 @@ void Music_ResetLevelVolume(void) { g_tunes.level_volume(100, true); } + +void Music_TuneReset(void) +{ + Music_Remap("battle_overtime", "shwdwn"); + Music_Remap("battle_overtime_stress", "shwdn2"); + Music_Remap("grow", "kgrow"); + Music_Remap("invinc", "kinvnc"); + Music_Remap("finish_silence", ""); + Music_Remap("comeon", "chalng"); + Music_Remap("vote", "vote"); + Music_Remap("vote_suspense", "voteea"); + Music_Remap("vote_end", "voteeb"); + Music_Remap("wait", "WAIT2J"); + Music_Remap("title", "_title"); + Music_Remap("credits_silence", ""); + Music_Remap("credits", "_creds"); + Music_Remap("lawyer", "lawyer"); +} diff --git a/src/music.h b/src/music.h index 630c7a98c..950016d4c 100644 --- a/src/music.h +++ b/src/music.h @@ -207,6 +207,10 @@ void Music_Tick(void); // the music plays again when re-enabled. void Music_Flip(void); +// Resets all non-dynamic tunes to default values. +// Keeps ACS music remapping from playing havoc after a map. +void Music_TuneReset(void); + #ifdef __cplusplus } // extern "C" diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 12e1c8f8b..e3f6824c5 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -9099,6 +9099,8 @@ void P_PostLoadLevel(void) { marathonmode = static_cast(marathonmode & ~MA_INIT); } + + Music_TuneReset(); // Placed before ACS scripts to allow remaps to occur on level start. ACS_RunLevelStartScripts(); LUA_HookInt(gamemap, HOOK(MapLoad));