Skip to content

Commit

Permalink
Fix demo footer after level restart
Browse files Browse the repository at this point in the history
Co-Authored-By: Roman Fomin <rfomin@gmail.com>
  • Loading branch information
JNechaevsky and rfomin committed Jan 23, 2025
1 parent 06112b2 commit c88d2ce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
15 changes: 9 additions & 6 deletions src/doom/g_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -3531,10 +3531,10 @@ static size_t WriteCmdLineLump(MEMFILE *stream)
return mem_ftell(stream) - pos;
}

static void WriteFileInfo(const char *name, size_t size, MEMFILE *stream)
static long WriteFileInfo(const char *name, size_t size, long filepos,
MEMFILE *stream)
{
filelump_t fileinfo = { 0 };
static long filepos = sizeof(wadinfo_t);

fileinfo.filepos = LONG(filepos);
fileinfo.size = LONG(size);
Expand All @@ -3552,12 +3552,14 @@ static void WriteFileInfo(const char *name, size_t size, MEMFILE *stream)
mem_fwrite(&fileinfo, 1, sizeof(fileinfo), stream);

filepos += size;
return filepos;
}

static void G_AddDemoFooter(void)
{
byte *data;
size_t size;
long filepos;

MEMFILE *stream = mem_fopen_write();

Expand All @@ -3575,10 +3577,11 @@ static void G_AddDemoFooter(void)
mem_fwrite(&header, 1, sizeof(header), stream);
mem_fseek(stream, 0, MEM_SEEK_END);

WriteFileInfo("PORTNAME", strlen(PACKAGE_STRING), stream);
WriteFileInfo(NULL, strlen(DEMO_FOOTER_SEPARATOR), stream);
WriteFileInfo("CMDLINE", size, stream);
WriteFileInfo(NULL, strlen(DEMO_FOOTER_SEPARATOR), stream);
filepos = sizeof(wadinfo_t);
filepos = WriteFileInfo("PORTNAME", strlen(PACKAGE_FULLNAME), filepos, stream);
filepos = WriteFileInfo(NULL, strlen(DEMO_FOOTER_SEPARATOR), filepos, stream);
filepos = WriteFileInfo("CMDLINE", size, filepos, stream);
WriteFileInfo(NULL, strlen(DEMO_FOOTER_SEPARATOR), filepos, stream);

mem_get_buf(stream, (void **)&data, &size);

Expand Down
15 changes: 9 additions & 6 deletions src/heretic/g_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -3223,10 +3223,10 @@ static size_t WriteCmdLineLump(MEMFILE *stream)
return mem_ftell(stream) - pos;
}

static void WriteFileInfo(const char *name, size_t size, MEMFILE *stream)
static long WriteFileInfo(const char *name, size_t size, long filepos,
MEMFILE *stream)
{
filelump_t fileinfo = { 0 };
static long filepos = sizeof(wadinfo_t);

fileinfo.filepos = LONG(filepos);
fileinfo.size = LONG(size);
Expand All @@ -3244,12 +3244,14 @@ static void WriteFileInfo(const char *name, size_t size, MEMFILE *stream)
mem_fwrite(&fileinfo, 1, sizeof(fileinfo), stream);

filepos += size;
return filepos;
}

static void G_AddDemoFooter(void)
{
byte *data;
size_t size;
long filepos;

MEMFILE *stream = mem_fopen_write();

Expand All @@ -3267,10 +3269,11 @@ static void G_AddDemoFooter(void)
mem_fwrite(&header, 1, sizeof(header), stream);
mem_fseek(stream, 0, MEM_SEEK_END);

WriteFileInfo("PORTNAME", strlen(PACKAGE_STRING), stream);
WriteFileInfo(NULL, strlen(DEMO_FOOTER_SEPARATOR), stream);
WriteFileInfo("CMDLINE", size, stream);
WriteFileInfo(NULL, strlen(DEMO_FOOTER_SEPARATOR), stream);
filepos = sizeof(wadinfo_t);
filepos = WriteFileInfo("PORTNAME", strlen(PACKAGE_FULLNAME_HERETIC), filepos, stream);
filepos = WriteFileInfo(NULL, strlen(DEMO_FOOTER_SEPARATOR), filepos, stream);
filepos = WriteFileInfo("CMDLINE", size, filepos, stream);
WriteFileInfo(NULL, strlen(DEMO_FOOTER_SEPARATOR), filepos, stream);

mem_get_buf(stream, (void **)&data, &size);

Expand Down

0 comments on commit c88d2ce

Please sign in to comment.