diff --git a/source/duke3d/src/game.cpp b/source/duke3d/src/game.cpp index f901b9d08..0ae38848c 100644 --- a/source/duke3d/src/game.cpp +++ b/source/duke3d/src/game.cpp @@ -4760,6 +4760,7 @@ void G_HandleLocalKeys(void) { const unsigned int maxi = VOLUMEALL ? MUS_FIRST_SPECIAL : 6; + unsigned int const oldMusicIndex = g_musicIndex; unsigned int MyMusicIndex = g_musicIndex; do { @@ -4767,7 +4768,7 @@ void G_HandleLocalKeys(void) if (MyMusicIndex >= maxi) MyMusicIndex = 0; } - while (S_TryPlayLevelMusic(MyMusicIndex)); + while (S_TryPlayLevelMusic(MyMusicIndex) && MyMusicIndex != oldMusicIndex); G_PrintCurrentMusic(); diff --git a/source/duke3d/src/game.h b/source/duke3d/src/game.h index 598b66f52..8b0d20036 100644 --- a/source/duke3d/src/game.h +++ b/source/duke3d/src/game.h @@ -301,6 +301,9 @@ extern user_defs ud; extern const char *s_buildDate; extern char boardfilename[BMAX_PATH], currentboardfilename[BMAX_PATH]; +#define USERMAPMUSICFAKEVOLUME MAXVOLUMES +#define USERMAPMUSICFAKELEVEL (MAXLEVELS-1) +#define USERMAPMUSICFAKESLOT ((USERMAPMUSICFAKEVOLUME * MAXLEVELS) + USERMAPMUSICFAKELEVEL) static inline int G_HaveUserMap(void) { diff --git a/source/duke3d/src/gameexec.cpp b/source/duke3d/src/gameexec.cpp index 5ab0de25b..a8cc64645 100644 --- a/source/duke3d/src/gameexec.cpp +++ b/source/duke3d/src/gameexec.cpp @@ -3817,6 +3817,12 @@ badindex: case STR_MAPNAME: case STR_MAPFILENAME: { + if (G_HaveUserMap()) + { + snprintf(apStrings[q], MAXQUOTELEN, "%s", boardfilename); + break; + } + int const levelNum = ud.volume_number * MAXLEVELS + ud.level_number; const char *pName; @@ -3848,6 +3854,12 @@ badindex: break; case STR_GAMETYPE: Bstrcpy(apStrings[q], g_gametypeNames[ud.coop]); break; case STR_VOLUMENAME: + if (G_HaveUserMap()) + { + apStrings[q][0] = '\0'; + break; + } + if (EDUKE32_PREDICT_FALSE((unsigned)ud.volume_number >= MAXVOLUMES)) { CON_ERRPRINTF("invalid volume %d\n", ud.volume_number); @@ -3859,7 +3871,7 @@ badindex: case STR_PARTIME: Bstrcpy(apStrings[q], G_PrintParTime()); break; case STR_DESIGNERTIME: Bstrcpy(apStrings[q], G_PrintDesignerTime()); break; case STR_BESTTIME: Bstrcpy(apStrings[q], G_PrintBestTime()); break; - case STR_USERMAPFILENAME: Bstrcpy(apStrings[q], boardfilename); break; + case STR_USERMAPFILENAME: snprintf(apStrings[q], MAXQUOTELEN, "%s", boardfilename); break; default: CON_ERRPRINTF("invalid string index %d or %d\n", q, j); abort_after_error(); } break; diff --git a/source/duke3d/src/premap.cpp b/source/duke3d/src/premap.cpp index bcc1e6c47..96fecf3ac 100644 --- a/source/duke3d/src/premap.cpp +++ b/source/duke3d/src/premap.cpp @@ -1758,7 +1758,7 @@ static void G_LoadMapHack(char *outbuf, const char *filename) } // levnamebuf should have at least size BMAX_PATH -void G_SetupFilenameBasedMusic(char *nameBuf, const char *fileName, int levelNum) +void G_SetupFilenameBasedMusic(char *nameBuf, const char *fileName) { char *p; char const *exts[] = { @@ -1797,14 +1797,29 @@ void G_SetupFilenameBasedMusic(char *nameBuf, const char *fileName, int levelNum if ((kFile = kopen4loadfrommod(nameBuf, 0)) != buildvfs_kfd_invalid) { kclose(kFile); - realloc_copy(&g_mapInfo[levelNum].musicfn, nameBuf); + realloc_copy(&g_mapInfo[USERMAPMUSICFAKESLOT].musicfn, nameBuf); return; } } char const * usermapMusic = g_mapInfo[MUS_USERMAP].musicfn; if (usermapMusic != nullptr) - realloc_copy(&g_mapInfo[levelNum].musicfn, usermapMusic); + { + realloc_copy(&g_mapInfo[USERMAPMUSICFAKESLOT].musicfn, usermapMusic); + return; + } + +#ifndef EDUKE32_STANDALONE + if (!FURY) + { + char const * e1l8 = g_mapInfo[7].musicfn; + if (e1l8 != nullptr) + { + realloc_copy(&g_mapInfo[USERMAPMUSICFAKESLOT].musicfn, e1l8); + return; + } + } +#endif } static void G_CheckIfStateless() @@ -1870,6 +1885,8 @@ int G_EnterLevel(int gameMode) boardfilename[0] = 0; } } + else + boardfilename[0] = '\0'; int const mapidx = (ud.volume_number * MAXLEVELS) + ud.level_number; @@ -1877,17 +1894,9 @@ int G_EnterLevel(int gameMode) auto &m = g_mapInfo[mapidx]; - if (m.name == NULL || m.filename == NULL) + if (VOLUMEONE || !Menu_HaveUserMap()) { - if (Menu_HaveUserMap()) - { - if (m.filename == NULL) - m.filename = (char *)Xcalloc(BMAX_PATH, sizeof(uint8_t)); - - if (m.name == NULL) - m.name = Xstrdup("User Map"); - } - else + if (m.name == NULL || m.filename == NULL) { OSD_Printf(OSDTEXT_RED "Map E%dL%d not defined!\n", ud.volume_number+1, ud.level_number+1); return 1; @@ -1944,7 +1953,7 @@ int G_EnterLevel(int gameMode) } G_LoadMapHack(levelName, boardfilename); - G_SetupFilenameBasedMusic(levelName, boardfilename, ud.m_level_number); + G_SetupFilenameBasedMusic(levelName, boardfilename); } else if (engineLoadBoard(m.filename, VOLUMEONE, &p0.pos, &playerAngle, &p0.cursectnum) < 0) { @@ -1982,7 +1991,11 @@ int G_EnterLevel(int gameMode) if (ud.recstat != 2) { - if (g_mapInfo[g_musicIndex].musicfn == NULL || m.musicfn == NULL || + if (Menu_HaveUserMap()) + { + S_PlayLevelMusicOrNothing(USERMAPMUSICFAKESLOT); + } + else if (g_mapInfo[g_musicIndex].musicfn == NULL || m.musicfn == NULL || strcmp(g_mapInfo[g_musicIndex].musicfn, m.musicfn) || g_musicSize == 0 || ud.last_level == -1) { S_PlayLevelMusicOrNothing(mapidx); diff --git a/source/duke3d/src/premap.h b/source/duke3d/src/premap.h index d0981971f..6e6a8ebe7 100644 --- a/source/duke3d/src/premap.h +++ b/source/duke3d/src/premap.h @@ -30,7 +30,7 @@ extern "C" { extern int32_t g_levelTextTime; extern int32_t voting,vote_map,vote_episode; extern palette_t CrosshairColors; -void G_SetupFilenameBasedMusic(char *nameBuf, const char *fileName, int levelNum); +void G_SetupFilenameBasedMusic(char *nameBuf, const char *fileName); int G_EnterLevel(int gameMode); int G_FindLevelByFile(const char *fileName); void G_CacheMapData(void); diff --git a/source/duke3d/src/savegame.cpp b/source/duke3d/src/savegame.cpp index 880ed8b04..b40040f4d 100644 --- a/source/duke3d/src/savegame.cpp +++ b/source/duke3d/src/savegame.cpp @@ -2454,10 +2454,10 @@ static void postloadplayer(int32_t savegamep) S_ClearSoundLocks(); G_CacheMapData(); - if (boardfilename[0] != 0 && ud.level_number == 7 && ud.volume_number == 0 && ud.music_level == 7 && ud.music_episode == 0) + if (boardfilename[0] != 0 && ud.level_number == 7 && ud.volume_number == 0 && ud.music_level == USERMAPMUSICFAKELEVEL && ud.music_episode == USERMAPMUSICFAKEVOLUME) { char levname[BMAX_PATH]; - G_SetupFilenameBasedMusic(levname, boardfilename, ud.level_number); + G_SetupFilenameBasedMusic(levname, boardfilename); } if (g_mapInfo[musicIdx].musicfn != NULL && (musicIdx != g_musicIndex || different_user_map)) diff --git a/source/duke3d/src/screens.cpp b/source/duke3d/src/screens.cpp index 9a888dc7f..10324af0e 100644 --- a/source/duke3d/src/screens.cpp +++ b/source/duke3d/src/screens.cpp @@ -1118,9 +1118,12 @@ void G_DisplayRest(int32_t smoothratio) if (textret == 0 && ud.overhead_on == 2) { const int32_t a = (ud.screen_size > 0) ? 147 : 179; - if (!(G_GetLogoFlags() & LOGO_HIDEEPISODE) && !G_HaveUserMap()) + char const * levelname = g_mapInfo[ud.volume_number*MAXLEVELS + ud.level_number].name; + if (G_HaveUserMap()) + levelname = boardfilename; + else if (!(G_GetLogoFlags() & LOGO_HIDEEPISODE)) minitext(5, a+6, g_volumeNames[ud.volume_number], 0, 2+8+16+256); - minitext(5, a+6+6, g_mapInfo[ud.volume_number*MAXLEVELS + ud.level_number].name, 0, 2+8+16+256); + minitext(5, a+6+6, levelname, 0, 2+8+16+256); } } }