mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2026-04-27 04:21:47 +00:00
Use G_LoadDemoInfo to validate in playdemo/TA menu
Fixes KartKrew/Kart#1096
This commit is contained in:
parent
5fd7f4ee65
commit
2775378ac2
2 changed files with 77 additions and 27 deletions
|
|
@ -2007,7 +2007,8 @@ Command_LeaveParty_f (void)
|
||||||
// UINT8 *demofile; // demo file buffer
|
// UINT8 *demofile; // demo file buffer
|
||||||
static void Command_Playdemo_f(void)
|
static void Command_Playdemo_f(void)
|
||||||
{
|
{
|
||||||
char name[256];
|
const char *arg1 = NULL;
|
||||||
|
menudemo_t menudemo = {0};
|
||||||
|
|
||||||
if (COM_Argc() < 2)
|
if (COM_Argc() < 2)
|
||||||
{
|
{
|
||||||
|
|
@ -2026,30 +2027,44 @@ static void Command_Playdemo_f(void)
|
||||||
return;
|
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?
|
// disconnect from server here?
|
||||||
if (demo.playback)
|
if (demo.playback)
|
||||||
G_StopDemo();
|
G_StopDemo();
|
||||||
|
|
||||||
// open the demo file
|
CONS_Printf(M_GetText("Playing back demo '%s'.\n"), menudemo.filepath);
|
||||||
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);
|
|
||||||
|
|
||||||
demo.loadfiles = strcmp(COM_Argv(2), "-addfiles") == 0;
|
demo.loadfiles = strcmp(COM_Argv(2), "-addfiles") == 0;
|
||||||
demo.ignorefiles = strcmp(COM_Argv(2), "-force") == 0;
|
demo.ignorefiles = strcmp(COM_Argv(2), "-force") == 0;
|
||||||
|
|
||||||
// Internal if no extension, external if one exists
|
G_DoPlayDemo(menudemo.filepath);
|
||||||
// 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Command_Timedemo_f(void)
|
static void Command_Timedemo_f(void)
|
||||||
{
|
{
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
const char *arg1 = NULL;
|
||||||
|
menudemo_t menudemo = {0};
|
||||||
|
|
||||||
if (COM_Argc() < 2)
|
if (COM_Argc() < 2)
|
||||||
{
|
{
|
||||||
|
|
@ -2063,14 +2078,33 @@ static void Command_Timedemo_f(void)
|
||||||
return;
|
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?
|
// disconnect from server here?
|
||||||
if (demo.playback)
|
if (demo.playback)
|
||||||
G_StopDemo();
|
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?
|
// print timedemo results as CSV?
|
||||||
i = COM_CheckParm("-csv");
|
i = COM_CheckParm("-csv");
|
||||||
timedemo_csv = (i > 0);
|
timedemo_csv = (i > 0);
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
#include "../v_video.h"
|
#include "../v_video.h"
|
||||||
#include "../d_main.h" // srb2home
|
#include "../d_main.h" // srb2home
|
||||||
#include "../m_misc.h" // M_MkdirEach
|
#include "../m_misc.h" // M_MkdirEach
|
||||||
|
#include "../s_sound.h" // S_StartSound
|
||||||
#include "../z_zone.h" // Z_StrDup/Z_Free
|
#include "../z_zone.h" // Z_StrDup/Z_Free
|
||||||
#include "../m_cond.h"
|
#include "../m_cond.h"
|
||||||
|
|
||||||
|
|
@ -433,14 +434,8 @@ void M_HandleStaffReplay(INT32 choice)
|
||||||
|
|
||||||
void M_ReplayTimeAttack(INT32 choice)
|
void M_ReplayTimeAttack(INT32 choice)
|
||||||
{
|
{
|
||||||
const char *which;
|
menudemo_t menudemo = {0};
|
||||||
|
const char *which = NULL;
|
||||||
restoreMenu = &PLAY_TimeAttackDef;
|
|
||||||
|
|
||||||
M_ClearMenus(true);
|
|
||||||
demo.loadfiles = false;
|
|
||||||
demo.ignorefiles = true; // Just assume that record attack replays have the files needed
|
|
||||||
|
|
||||||
const char *modeprefix = "";
|
const char *modeprefix = "";
|
||||||
|
|
||||||
if (cv_dummyspbattack.value)
|
if (cv_dummyspbattack.value)
|
||||||
|
|
@ -459,11 +454,32 @@ void M_ReplayTimeAttack(INT32 choice)
|
||||||
which = "last";
|
which = "last";
|
||||||
break;
|
break;
|
||||||
case tareplay_guest:
|
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));
|
sprintf(menudemo.filepath, "%s"PATHSEP"media"PATHSEP"replay"PATHSEP"%s"PATHSEP"%s-%sguest.lmp", srb2home, timeattackfolder, G_BuildMapName(levellist.choosemap+1), modeprefix);
|
||||||
return;
|
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;
|
static const char *TA_GuestReplay_Str = NULL;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue