diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 0523c2079..a8449040a 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -2007,7 +2007,8 @@ Command_LeaveParty_f (void) // UINT8 *demofile; // demo file buffer static void Command_Playdemo_f(void) { - char name[256]; + const char *arg1 = NULL; + menudemo_t menudemo = {0}; if (COM_Argc() < 2) { @@ -2026,30 +2027,44 @@ static void Command_Playdemo_f(void) return; } + arg1 = COM_Argv(1); + + // Internal if no extension, external if one exists + if (FIL_CheckExtension(arg1)) + { + // External demos must be checked first + sprintf(menudemo.filepath, "%s" PATHSEP "%s", srb2home, arg1); + G_LoadDemoInfo(&menudemo, /*allownonmultiplayer*/ true); + + if (menudemo.type != MD_LOADED) + { + // Do nothing because the demo can't be played + CONS_Alert(CONS_ERROR, "Unable to playdemo %s", menudemo.filepath); + return; + } + } + else + { + strlcpy(menudemo.filepath, arg1, sizeof(menudemo.filepath)); + } + // disconnect from server here? if (demo.playback) G_StopDemo(); - // open the demo file - strcpy(name, COM_Argv(1)); - // dont add .lmp so internal game demos can be played - - CONS_Printf(M_GetText("Playing back demo '%s'.\n"), name); + CONS_Printf(M_GetText("Playing back demo '%s'.\n"), menudemo.filepath); demo.loadfiles = strcmp(COM_Argv(2), "-addfiles") == 0; demo.ignorefiles = strcmp(COM_Argv(2), "-force") == 0; - // Internal if no extension, external if one exists - // If external, convert the file name to a path in SRB2's home directory - if (FIL_CheckExtension(name)) - G_DoPlayDemo(va("%s"PATHSEP"%s", srb2home, name)); - else - G_DoPlayDemo(name); + G_DoPlayDemo(menudemo.filepath); } static void Command_Timedemo_f(void) { size_t i = 0; + const char *arg1 = NULL; + menudemo_t menudemo = {0}; if (COM_Argc() < 2) { @@ -2063,14 +2078,33 @@ static void Command_Timedemo_f(void) return; } + arg1 = COM_Argv(1); + + // Internal if no extension, external if one exists + if (FIL_CheckExtension(arg1)) + { + // External demos must be checked first + sprintf(menudemo.filepath, "%s" PATHSEP "%s", srb2home, arg1); + G_LoadDemoInfo(&menudemo, /*allownonmultiplayer*/ true); + + if (menudemo.type != MD_LOADED) + { + // Do nothing because the demo can't be played + CONS_Alert(CONS_ERROR, "Unable to timedemo %s", menudemo.filepath); + return; + } + + strlcpy(timedemo_name, menudemo.filepath, sizeof(timedemo_name)); + } + else + { + strlcpy(timedemo_name, arg1, sizeof(timedemo_name)); + } + // disconnect from server here? if (demo.playback) G_StopDemo(); - // open the demo file - strcpy (timedemo_name, COM_Argv(1)); - // dont add .lmp so internal game demos can be played - // print timedemo results as CSV? i = COM_CheckParm("-csv"); timedemo_csv = (i > 0); diff --git a/src/menus/play-local-race-time-attack.c b/src/menus/play-local-race-time-attack.c index c8395c26c..2db63ca73 100644 --- a/src/menus/play-local-race-time-attack.c +++ b/src/menus/play-local-race-time-attack.c @@ -8,6 +8,7 @@ #include "../v_video.h" #include "../d_main.h" // srb2home #include "../m_misc.h" // M_MkdirEach +#include "../s_sound.h" // S_StartSound #include "../z_zone.h" // Z_StrDup/Z_Free #include "../m_cond.h" @@ -433,14 +434,8 @@ void M_HandleStaffReplay(INT32 choice) void M_ReplayTimeAttack(INT32 choice) { - const char *which; - - restoreMenu = &PLAY_TimeAttackDef; - - M_ClearMenus(true); - demo.loadfiles = false; - demo.ignorefiles = true; // Just assume that record attack replays have the files needed - + menudemo_t menudemo = {0}; + const char *which = NULL; const char *modeprefix = ""; if (cv_dummyspbattack.value) @@ -459,11 +454,32 @@ void M_ReplayTimeAttack(INT32 choice) which = "last"; break; case tareplay_guest: - G_DoPlayDemo(va("%s"PATHSEP"media"PATHSEP"replay"PATHSEP"%s"PATHSEP"%s-%sguest.lmp", srb2home, timeattackfolder, G_BuildMapName(levellist.choosemap+1), modeprefix)); - return; + sprintf(menudemo.filepath, "%s"PATHSEP"media"PATHSEP"replay"PATHSEP"%s"PATHSEP"%s-%sguest.lmp", srb2home, timeattackfolder, G_BuildMapName(levellist.choosemap+1), modeprefix); + break; } - G_DoPlayDemo(va("%s"PATHSEP"media"PATHSEP"replay"PATHSEP"%s"PATHSEP"%s-%s-%s%s.lmp", srb2home, timeattackfolder, G_BuildMapName(levellist.choosemap+1), cv_skin[0].string, modeprefix, which)); + if (which) + { + sprintf(menudemo.filepath, "%s"PATHSEP"media"PATHSEP"replay"PATHSEP"%s"PATHSEP"%s-%s-%s%s.lmp", srb2home, timeattackfolder, G_BuildMapName(levellist.choosemap+1), cv_skin[0].string, modeprefix, which); + } + + G_LoadDemoInfo(&menudemo, /*allownonmultiplayer*/ true); + + if (menudemo.type != MD_LOADED || menudemo.addonstatus > 0) + { + // Do nothing because the demo can't be played + S_StartSound(NULL, sfx_tmxerr); + M_StartMessage("Invalid Replay", "Replay cannot be played on this version of the game", NULL, MM_NOTHING, NULL, "Back"); + return; + } + + restoreMenu = &PLAY_TimeAttackDef; + + M_ClearMenus(true); + demo.loadfiles = false; + demo.ignorefiles = true; // Just assume that record attack replays have the files needed + + G_DoPlayDemo(menudemo.filepath); } static const char *TA_GuestReplay_Str = NULL;