Prevent non-dynamic tunes remapped by ACS from remaining remapped after map ends.

This commit is contained in:
Freaky Mutant Man 2025-10-16 02:28:48 +00:00 committed by Eidolon
parent 2270813eee
commit 9fb3719a8d
7 changed files with 64 additions and 14 deletions

View file

@ -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);

View file

@ -5135,6 +5135,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)
{

View file

@ -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);

View file

@ -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)\

View file

@ -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");
}

View file

@ -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"

View file

@ -9099,6 +9099,8 @@ void P_PostLoadLevel(void)
{
marathonmode = static_cast<marathonmode_t>(marathonmode & ~MA_INIT);
}
Music_TuneReset(); // Placed before ACS scripts to allow remaps to occur on level start.
ACS_RunLevelStartScripts();
LUA_HookInt(gamemap, HOOK(MapLoad));