diff --git a/src/d_clisrv.c b/src/d_clisrv.c index f91b15f58..832b8659e 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1454,7 +1454,7 @@ static void SV_SendServerInfo(INT32 node, tic_t servertime) CopyCaretColors(netbuffer->u.serverinfo.servername, cv_servername.string, MAXSERVERNAME); - strncpy(netbuffer->u.serverinfo.mapname, G_BuildMapName(gamemap), 7); + strncpy(netbuffer->u.serverinfo.mapname, globalmapname, 7); M_Memcpy(netbuffer->u.serverinfo.mapmd5, mapmd5, 16); @@ -1839,7 +1839,7 @@ static void CL_LoadReceivedSavegame(boolean reloading) { if (!reloading) { - CON_LogMessage(va(M_GetText("Map is now \"%s"), G_BuildMapName(gamemap))); + CON_LogMessage(va(M_GetText("Map is now \"%s"), globalmapname)); if (strlen(mapheaderinfo[gamemap-1]->lvlttl) > 0) { CON_LogMessage(va(": %s", mapheaderinfo[gamemap-1]->lvlttl)); diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 96de8ed95..256cf5a85 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -5010,16 +5010,16 @@ static void Command_Showmap_f(void) if (mapheaderinfo[gamemap-1]->zonttl[0] && !(mapheaderinfo[gamemap-1]->levelflags & LF_NOZONE)) { if (mapheaderinfo[gamemap-1]->actnum[0]) - CONS_Printf("%s (%d): %s %s %s\n", G_BuildMapName(gamemap), gamemap, mapheaderinfo[gamemap-1]->lvlttl, mapheaderinfo[gamemap-1]->zonttl, mapheaderinfo[gamemap-1]->actnum); + CONS_Printf("%s (%d): %s %s %s\n", globalmapname, gamemap, mapheaderinfo[gamemap-1]->lvlttl, mapheaderinfo[gamemap-1]->zonttl, mapheaderinfo[gamemap-1]->actnum); else - CONS_Printf("%s (%d): %s %s\n", G_BuildMapName(gamemap), gamemap, mapheaderinfo[gamemap-1]->lvlttl, mapheaderinfo[gamemap-1]->zonttl); + CONS_Printf("%s (%d): %s %s\n", globalmapname, gamemap, mapheaderinfo[gamemap-1]->lvlttl, mapheaderinfo[gamemap-1]->zonttl); } else { if (mapheaderinfo[gamemap-1]->actnum[0]) - CONS_Printf("%s (%d): %s %s\n", G_BuildMapName(gamemap), gamemap, mapheaderinfo[gamemap-1]->lvlttl, mapheaderinfo[gamemap-1]->actnum); + CONS_Printf("%s (%d): %s %s\n", globalmapname, gamemap, mapheaderinfo[gamemap-1]->lvlttl, mapheaderinfo[gamemap-1]->actnum); else - CONS_Printf("%s (%d): %s\n", G_BuildMapName(gamemap), gamemap, mapheaderinfo[gamemap-1]->lvlttl); + CONS_Printf("%s (%d): %s\n", globalmapname, gamemap, mapheaderinfo[gamemap-1]->lvlttl); } } else @@ -5034,7 +5034,7 @@ static void Command_Mapmd5_f(void) char md5tmp[33]; for (i = 0; i < 16; ++i) sprintf(&md5tmp[i*2], "%02x", mapmd5[i]); - CONS_Printf("%s: %s\n", G_BuildMapName(gamemap), md5tmp); + CONS_Printf("%s: %s\n", globalmapname, md5tmp); } else CONS_Printf(M_GetText("You must be in a level to use this.\n")); diff --git a/src/discord.c b/src/discord.c index 17b8ea836..6941eac2b 100644 --- a/src/discord.c +++ b/src/discord.c @@ -547,7 +547,7 @@ void DRPC_UpdatePresence(void) if ((gamemap >= 1 && gamemap <= 60) // supported race maps || (gamemap >= 136 && gamemap <= 164)) // supported battle maps { - snprintf(mapimg, 8, "%s", G_BuildMapName(gamemap)); + snprintf(mapimg, 8, "%s", globalmapname); strlwr(mapimg); discordPresence.largeImageKey = mapimg; // Map image } diff --git a/src/doomstat.h b/src/doomstat.h index f69402f25..5e6c07f91 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -32,6 +32,7 @@ // Selected by user. extern INT16 gamemap; extern char *maptitle; +extern const char *globalmapname; extern char mapmusname[7]; extern UINT16 mapmusflags; extern UINT32 mapmusposition; diff --git a/src/g_game.c b/src/g_game.c index 980ff8b8b..839aa69e1 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -92,6 +92,7 @@ UINT32 mapmusresume; INT16 gamemap = 1; char *maptitle = NULL; +const char *globalmapname = NULL; INT16 maptol; UINT8 globalweather = 0; INT32 curWeather = PRECIP_NONE; @@ -570,6 +571,14 @@ INT16 rw_maximums[NUM_WEAPONS] = 50 // MAX_RAIL }; +void G_AllocMapTitles(INT16 map) +{ + if (maptitle) + Z_Free(maptitle); + maptitle = G_BuildMapTitle(map); + globalmapname = G_BuildMapName(map); +} + // Allocation for time and nights data void G_AllocMainRecordData(INT16 i) { @@ -4249,9 +4258,7 @@ void G_InitNew(UINT8 pencoremode, const char *mapname, boolean resetplayer, bool gamemap = (INT16)M_MapNumber(mapname[3], mapname[4]); // get xx out of MAPxx - if (maptitle) - Z_Free(maptitle); - maptitle = G_BuildMapTitle(gamemap); + G_AllocMapTitles(gamemap); // gamemap changed; we assume that its map header is always valid, // so make it so @@ -4278,7 +4285,7 @@ void G_InitNew(UINT8 pencoremode, const char *mapname, boolean resetplayer, bool if (netgame) { - CON_LogMessage(va(M_GetText("Map is now \"%s"), G_BuildMapName(gamemap))); + CON_LogMessage(va(M_GetText("Map is now \"%s"), globalmapname)); if (maptitle) CON_LogMessage(va(": %s", maptitle)); CON_LogMessage("\"\n"); @@ -7954,7 +7961,7 @@ void G_DoPlayMetal(void) thinker_t *th; // it's an internal demo - if ((l = W_CheckNumForName(va("%sMS",G_BuildMapName(gamemap)))) == LUMPERROR) + if ((l = W_CheckNumForName(va("%sMS", globalmapname))) == LUMPERROR) { CONS_Alert(CONS_WARNING, M_GetText("No bot recording for this map.\n")); return; @@ -8059,13 +8066,13 @@ ATTRNORETURN void FUNCNORETURN G_StopMetalRecording(void) WRITEUINT8(demobuf.p, DEMOMARKER); // add the demo end marker md5_buffer((char *)p+16, demobuf.p - (p+16), (void *)p); // make a checksum of everything after the checksum in the file. #endif - saved = FIL_WriteFile(va("%sMS.LMP", G_BuildMapName(gamemap)), demobuf.buffer, demobuf.p - demobuf.buffer); // finally output the file. + saved = FIL_WriteFile(va("%sMS.LMP", globalmapname), demobuf.buffer, demobuf.p - demobuf.buffer); // finally output the file. } free(demobuf.buffer); demobuf.buffer = NULL; metalrecording = false; if (saved) - I_Error("Saved to %sMS.LMP", G_BuildMapName(gamemap)); + I_Error("Saved to %sMS.LMP", globalmapname); I_Error("Failed to save demo!"); } diff --git a/src/g_game.h b/src/g_game.h index c92e0652a..fb352bee9 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -337,6 +337,8 @@ void G_WriteMetalTic(mobj_t *metal); void G_SaveMetal(UINT8 **buffer); void G_LoadMetal(UINT8 **buffer); +void G_AllocMapTitles(INT16 map); + // Your naming conventions are stupid and useless. // There is no conflict here. typedef struct demoghost { diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 0af7f2c36..4c7ad808e 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -679,10 +679,10 @@ static int libd_drawOnMinimap(lua_State *L) if (stplyr != &players[displayplayers[0]]) return 0; - lumpnum = W_CheckNumForName(va("%sR", G_BuildMapName(gamemap))); + lumpnum = W_CheckNumForName(va("%sR", globalmapname)); if (lumpnum != -1) - AutomapPic = W_CachePatchName(va("%sR", G_BuildMapName(gamemap)), PU_HUDGFX); + AutomapPic = W_CachePatchName(va("%sR", globalmapname), PU_HUDGFX); else return 0; // no pic, just get outta here @@ -1612,4 +1612,4 @@ void LUAh_VoteHUD(huddrawlist_h list) lua_pushlightuserdata(gL, NULL); lua_setfield(gL, LUA_REGISTRYINDEX, "HUD_DRAW_LIST"); -} \ No newline at end of file +} diff --git a/src/m_cheat.c b/src/m_cheat.c index 22126bd4f..1c6a0f185 100644 --- a/src/m_cheat.c +++ b/src/m_cheat.c @@ -1226,7 +1226,7 @@ void Command_Writethings_f(void) REQUIRE_SINGLEPLAYER; REQUIRE_OBJECTPLACE; - P_WriteThings(W_GetNumForName(G_BuildMapName(gamemap)) + ML_THINGS); + P_WriteThings(W_GetNumForName(globalmapname) + ML_THINGS); } void Command_ObjectPlace_f(void) diff --git a/src/m_misc.c b/src/m_misc.c index c6e4bca8f..604c14e8c 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -793,7 +793,7 @@ static void M_PNGText(png_structp png_ptr, png_infop png_info_ptr, PNG_CONST png } if (gamestate == GS_LEVEL) - snprintf(maptext, 8, "%s", G_BuildMapName(gamemap)); + snprintf(maptext, 8, "%s", globalmapname); else snprintf(maptext, 8, "Unknown"); @@ -1616,11 +1616,11 @@ void M_MinimapGenerate(void) return; } - filepath = va("%s" PATHSEP "%s-MINIMAP-%d.png", srb2home, G_BuildMapName(gamemap), mul); + filepath = va("%s" PATHSEP "%s-MINIMAP-%d.png", srb2home, globalmapname, mul); } else { - filepath = va("%s" PATHSEP "%s-MINIMAP.png", srb2home, G_BuildMapName(gamemap)); + filepath = va("%s" PATHSEP "%s-MINIMAP.png", srb2home, globalmapname); } minigen = AM_MinimapGenerate(mul); diff --git a/src/p_saveg.c b/src/p_saveg.c index efb96f75c..39d29c8c4 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -3186,6 +3186,8 @@ static inline void P_UnArchiveSPGame(savebuffer_t *save, INT16 mapoverride) else gamecomplete = false; + G_AllocMapTitles(gamemap); + // gamemap changed; we assume that its map header is always valid, // so make it so if(!mapheaderinfo[gamemap-1]) @@ -3330,6 +3332,8 @@ FUNCINLINE static ATTRINLINE boolean P_NetUnArchiveMisc(savebuffer_t *save, bool gamemap = READINT16(save->p); + G_AllocMapTitles(gamemap); + // gamemap changed; we assume that its map header is always valid, // so make it so if(!mapheaderinfo[gamemap-1]) @@ -3503,7 +3507,7 @@ boolean P_LoadGame(savebuffer_t *save, INT16 mapoverride) } // Only do this after confirming savegame is ok - G_DeferedInitNew(false, G_BuildMapName(gamemap), savedata.skin, 0, true); + G_DeferedInitNew(false, globalmapname, savedata.skin, 0, true); COM_BufAddText("dummyconsvar 1\n"); // G_DeferedInitNew doesn't do this return true; diff --git a/src/p_setup.c b/src/p_setup.c index ab567de22..d345e9f3b 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2315,7 +2315,7 @@ static void P_LoadRecordGhosts(void) if (!gpath) return; - sprintf(gpath,"%s"PATHSEP"replay"PATHSEP"%s"PATHSEP"%s", srb2home, timeattackfolder, G_BuildMapName(gamemap)); + sprintf(gpath,"%s"PATHSEP"replay"PATHSEP"%s"PATHSEP"%s", srb2home, timeattackfolder, globalmapname); // Best Time ghost if (cv_ghost_besttime.value) @@ -2365,9 +2365,9 @@ static void P_LoadRecordGhosts(void) { lumpnum_t l; UINT8 j = 1; - while (j <= 99 && (l = W_CheckNumForName(va("%sS%02u",G_BuildMapName(gamemap),j))) != LUMPERROR) + while (j <= 99 && (l = W_CheckNumForName(va("%sS%02u", globalmapname, j))) != LUMPERROR) { - G_AddGhost(va("%sS%02u",G_BuildMapName(gamemap),j)); + G_AddGhost(va("%sS%02u", globalmapname, j)); j++; } } @@ -2450,10 +2450,10 @@ static void P_InitMinimapInfo(void) fixed_t a; fixed_t b; node_t *bsp = &nodes[numnodes-1]; - lumpnum = W_CheckNumForName(va("%sR", G_BuildMapName(gamemap))); + lumpnum = W_CheckNumForName(va("%sR", globalmapname)); if (lumpnum != -1) - minimapinfo.minimap_pic = W_CachePatchName(va("%sR", G_BuildMapName(gamemap)), PU_HUDGFX); + minimapinfo.minimap_pic = W_CachePatchName(va("%sR", globalmapname), PU_HUDGFX); minimapinfo.mapthingcount = 0; // TODO iterate over mapthings to look for possible user-defined bounds @@ -2714,7 +2714,7 @@ boolean P_SetupLevel(boolean skipprecip, boolean reloadinggamestate) } // internal game map - maplumpname = G_BuildMapName(gamemap); + maplumpname = globalmapname; lastloadedmaplumpnum = W_CheckNumForName(maplumpname); if (lastloadedmaplumpnum == INT16_MAX) I_Error("Map %s not found.\n", maplumpname); @@ -2823,7 +2823,7 @@ boolean P_SetupLevel(boolean skipprecip, boolean reloadinggamestate) //Ensure dedis only record a replay if there is a player at the start of the map, otherwise we get invalid replays! if (!demo.playback && multiplayer && D_NumPlayers()) { static char buf[256]; - sprintf(buf, "replay"PATHSEP"online"PATHSEP"%d-%s", (int) (time(NULL)), G_BuildMapName(gamemap)); + sprintf(buf, "replay"PATHSEP"online"PATHSEP"%d-%s", (int) (time(NULL)), globalmapname); I_mkdir(va("%s"PATHSEP"replay", srb2home), 0755); I_mkdir(va("%s"PATHSEP"replay"PATHSEP"online", srb2home), 0755); diff --git a/src/p_spec.c b/src/p_spec.c index 61ddd7ebb..5d5d6593d 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2308,7 +2308,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) lumpnum_t lumpnum; char newname[9]; - strcpy(newname, G_BuildMapName(gamemap)); + strcpy(newname, globalmapname); newname[0] = 'S'; newname[1] = 'C'; newname[2] = 'R'; diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index b77832260..be8c9cf03 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -351,7 +351,7 @@ static void write_backtrace(bt_crash_reason_t reason) fprintf(out, "Compiled: %s %s, commit %s, branch %s\n", compdate, comptime, comprevision, compbranch); if (gamestate == GS_LEVEL) - fprintf(out, "Game map: %s\n", G_BuildMapName(gamemap)); + fprintf(out, "Game map: %s\n", globalmapname); fprintf(out, "Time of crash: %s\n", asctime(timeinfo)); diff --git a/src/y_inter.c b/src/y_inter.c index bf6dfe359..38a0b9146 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -728,7 +728,7 @@ static void Y_UpdateRecordReplays(void) if ((gpath = malloc(glen)) == NULL) I_Error("Out of memory for replay filepath\n"); - sprintf(gpath,"%s"PATHSEP"replay"PATHSEP"%s"PATHSEP"%s", srb2home, timeattackfolder, G_BuildMapName(gamemap)); + sprintf(gpath,"%s"PATHSEP"replay"PATHSEP"%s"PATHSEP"%s", srb2home, timeattackfolder, globalmapname); snprintf(lastdemo, 255, "%s-%s-last.lmp", gpath, cv_chooseskin.string); if (FIL_FileExists(lastdemo))