add a bunch of extra checks into demo stuff

buffer may be NULL in some cases
should fix dedis crashing when replay recording is disabled
This commit is contained in:
Alug committed 2024-12-29 15:34:10 +01:00
1 parent 2186fc6ce0
commit dad904967e
2 files changed
+40 -11

No files matched your search

+37 -9
View File
@@ -4809,6 +4809,7 @@ void G_WriteDemoTiccmd(ticcmd_t *cmd, INT32 playernum)
if (!demobuf.p)
return;
ziptic_p = demobuf.p++; // the ziptic, written at the end of this function
if (cmd->forwardmove != oldcmd[playernum].forwardmove)
@@ -4937,10 +4938,14 @@ void G_GhostAddHit(INT32 playernum, mobj_t *victim)
void G_WriteAllGhostTics(void)
{
if (!demobuf.p)
return;
UINT8 *save_demo_p = demobuf.p;
#define CHECKSPACE(num) if (demobuf.p+(num) > demoend) { demobuf.p = save_demo_p; G_CheckDemoStatus(); return; }
INT32 i, counter = leveltime;
for (i = 0; i < MAXPLAYERS; i++)
{
if (!playeringame[i] || players[i].spectator)
@@ -4974,11 +4979,12 @@ void G_WriteGhostTic(mobj_t *ghost, INT32 playernum)
UINT8 sprite;
UINT8 frame;
if (!demobuf.p)
return;
UINT8 *save_demo_p = demobuf.p;
#define CHECKSPACE(num) if (demobuf.p+(num) > demoend) { demobuf.p = save_demo_p; G_CheckDemoStatus(); return; }
if (!demobuf.p)
return;
if (!(demoflags & DF_GHOST))
return; // No ghost data to write.
@@ -5171,6 +5177,9 @@ void G_WriteGhostTic(mobj_t *ghost, INT32 playernum)
void G_ConsAllGhostTics(void)
{
if (!demobuf.p)
return;
UINT8 p = READUINT8(demobuf.p);
while (p != 0xFF)
@@ -5231,7 +5240,8 @@ void G_ConsGhostTic(INT32 playernum)
demobuf.p++;
if (ziptic & GZT_SPRITE)
demobuf.p++;
if(ziptic & GZT_NIGHTS) {
if (ziptic & GZT_NIGHTS)
{
if (!testmo || !testmo->player || !(testmo->player->pflags & PF_NIGHTSMODE) || !testmo->tracer)
nightsfail = true;
else
@@ -6069,8 +6079,12 @@ void G_BeginRecording(void)
UINT8 totalfiles;
UINT8 *m;
if (demobuf.p)
if (!cv_recordmultiplayerdemos.value)
return;
if (demobuf.p || demobuf.buffer == NULL)
return;
memset(name,0,sizeof(name));
demobuf.p = demobuf.buffer;
@@ -6080,7 +6094,7 @@ void G_BeginRecording(void)
demoflags |= DF_ENCORE;
if (!modeattacking && gL) // Ghosts don't read luavars, and you shouldn't ever need to save Lua in replays, you doof!
// SERIOUSLY THOUGH WHY WOULD YOU LOAD HOSTMOD AND RECORD A GHOST WITH IT !????
// SERIOUSLY THOUGH WHY WOULD YOU LOAD HOSTMOD AND RECORD A GHOST WITH IT !????
demoflags |= DF_LUAVARS;
// Setup header.
@@ -6148,7 +6162,7 @@ void G_BeginRecording(void)
break;
}
WRITEUINT32(demobuf.p,P_GetInitSeed());
WRITEUINT32(demobuf.p, P_GetInitSeed());
// Reserved for extrainfo location from start of file
demoinfo_p = demobuf.p;
@@ -6225,7 +6239,7 @@ void G_BeginMetal(void)
{
mobj_t *mo = players[consoleplayer].mo;
if (demobuf.p)
if (demobuf.p || demobuf.buffer == NULL)
return;
demobuf.p = demobuf.buffer;
@@ -6253,7 +6267,10 @@ void G_WriteStanding(UINT8 ranking, char *name, INT32 skinnum, UINT8 color, UINT
{
char temp[17];
if (demoinfo_p && *(UINT32 *)demoinfo_p == 0)
if (!demobuf.p)
return;
if (demoinfo_p && *(UINT32 *)demoinfo_p == 0 && demobuf.buffer != NULL)
{
WRITEUINT8(demobuf.p, DEMOMARKER); // add the demo end marker
*(UINT32 *)demoinfo_p = demobuf.p - demobuf.buffer;
@@ -6839,6 +6856,9 @@ void G_DoPlayDemo(char *defdemoname)
boolean spectator;
UINT8 slots[MAXPLAYERS], kartspeed[MAXPLAYERS], kartweight[MAXPLAYERS], numslots = 0;
if (demobuf.buffer == NULL)
return;
G_InitDemoRewind();
skin[16] = '\0';
@@ -7836,7 +7856,7 @@ void G_StopMetalDemo(void)
ATTRNORETURN void FUNCNORETURN G_StopMetalRecording(void)
{
boolean saved = false;
if (demobuf.p)
if (demobuf.p && demobuf.buffer != NULL)
{
UINT8 *p = demobuf.buffer+16; // checksum position
#ifdef NOMD5
@@ -8000,6 +8020,14 @@ void G_SaveDemo(void)
return;
}
if (demobuf.buffer == NULL)
{
CONS_Alert(CONS_ERROR, "Failed to save Demo. No Demo buffer allocated!\n");
// reset the demo buffer
G_ResetDemoRecording();
return;
}
UINT8 *p = demobuf.buffer+16; // after version
UINT32 length;
#ifdef NOMD5
+3 -2
View File
@@ -2993,8 +2993,9 @@ boolean P_SetupLevel(boolean skipprecip, boolean reloadinggamestate)
: mapheaderinfo[gamemap - 1]->numlaps);
// Start recording replay in multiplayer with a temp filename
//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()) {
// 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));