mirror of
https://github.com/fabiangreffrath/woof.git
synced 2025-09-25 22:05:20 -04:00
indicate overflow emulation in demo footer (#566)
* rewrote G_AddDemoFooter to use memio.h * remove M_StringAdd * indicate overflow emulation in demo footer * fix gcc warning * fix declaration * fix dehfiles realloc
This commit is contained in:
parent
8fee16b76b
commit
06689b1753
@ -116,7 +116,7 @@ static int dehfseek(DEHFILE *fp, long offset)
|
||||
// variables used in other routines
|
||||
boolean deh_pars = FALSE; // in wi_stuff to allow pars in modified games
|
||||
|
||||
char *dehfiles = NULL; // filenames of .deh files for demo footer
|
||||
char **dehfiles = NULL; // filenames of .deh files for demo footer
|
||||
|
||||
// #include "d_deh.h" -- we don't do that here but we declare the
|
||||
// variables. This externalizes everything that there is a string
|
||||
@ -1621,15 +1621,18 @@ void ProcessDehFile(const char *filename, char *outfilename, int lumpnum)
|
||||
|
||||
if (filename)
|
||||
{
|
||||
char *tmp = NULL;
|
||||
static int i = 0;
|
||||
|
||||
if (!(infile.inp = (void *) fopen(filename,"rt")))
|
||||
{
|
||||
printf("-deh file %s not found\n",filename);
|
||||
return; // should be checked up front anyway
|
||||
}
|
||||
tmp = M_StringJoin(" \"", M_BaseName(filename), "\"", NULL);
|
||||
M_StringAdd(&dehfiles, tmp);
|
||||
free(tmp);
|
||||
|
||||
dehfiles = I_Realloc(dehfiles, (i + 2) * sizeof(*dehfiles));
|
||||
dehfiles[i++] = strdup(filename);
|
||||
dehfiles[i] = NULL;
|
||||
|
||||
infile.lump = NULL;
|
||||
}
|
||||
else // DEH file comes from lump indicated by third argument
|
||||
|
@ -48,7 +48,12 @@ int compatibility, default_compatibility; // killough 1/31/98
|
||||
int comp[COMP_TOTAL], default_comp[COMP_TOTAL]; // killough 10/98
|
||||
|
||||
// [FG] overflow emulation
|
||||
int emu_spechits, emu_reject, emu_intercepts;
|
||||
overflow_t overflow[EMU_TOTAL] = {
|
||||
{ true, false, "spechits_overflow"},
|
||||
{ true, false, "reject_overflow"},
|
||||
{ true, false, "intercepts_overflow"},
|
||||
{ true, false, "missedbackside_overflow"}
|
||||
};
|
||||
|
||||
int demo_version; // killough 7/19/98: Boom version of demo
|
||||
|
||||
|
@ -75,7 +75,22 @@ extern boolean modifiedgame;
|
||||
extern int compatibility, default_compatibility; // killough 1/31/98
|
||||
|
||||
// [FG] overflow emulation
|
||||
extern int emu_spechits, emu_reject, emu_intercepts;
|
||||
enum {
|
||||
emu_spechits,
|
||||
emu_reject,
|
||||
emu_intercepts,
|
||||
emu_missedbackside,
|
||||
|
||||
EMU_TOTAL
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
boolean enabled;
|
||||
boolean triggered;
|
||||
const char *str;
|
||||
} overflow_t;
|
||||
|
||||
extern overflow_t overflow[EMU_TOTAL];
|
||||
|
||||
extern int demo_version; // killough 7/19/98: Version of demo
|
||||
|
||||
|
@ -63,6 +63,7 @@
|
||||
#include "m_misc2.h"
|
||||
#include "u_mapinfo.h"
|
||||
#include "m_input.h"
|
||||
#include "memio.h"
|
||||
|
||||
#define SAVEGAMESIZE 0x20000
|
||||
#define SAVESTRINGSIZE 24
|
||||
@ -3378,50 +3379,76 @@ void G_DeferedPlayDemo(char* name)
|
||||
|
||||
#define DEMO_FOOTER_SEPARATOR "\n"
|
||||
extern const char* GetGameVersionCmdline(void);
|
||||
extern char *dehfiles;
|
||||
extern char **dehfiles;
|
||||
|
||||
static void G_AddDemoFooter(void)
|
||||
{
|
||||
ptrdiff_t position = demo_p - demobuffer;
|
||||
char *str = NULL;
|
||||
char *tmp = NULL;
|
||||
int len = 0;
|
||||
size_t len = 0;
|
||||
int i;
|
||||
|
||||
str = M_StringJoin(PROJECT_STRING, DEMO_FOOTER_SEPARATOR,
|
||||
MEMFILE *stream = mem_fopen_write();
|
||||
|
||||
tmp = M_StringJoin(PROJECT_STRING, DEMO_FOOTER_SEPARATOR,
|
||||
"-iwad \"", M_BaseName(wadfiles[0]), "\"", NULL);
|
||||
mem_fputs(tmp, stream);
|
||||
free(tmp);
|
||||
|
||||
for (i = 1; wadfiles[i]; i++)
|
||||
{
|
||||
if (i == 1)
|
||||
M_StringAdd(&str, " -file");
|
||||
mem_fputs(" -file", stream);
|
||||
|
||||
tmp = M_StringJoin(" \"", M_BaseName(wadfiles[i]), "\"", NULL);
|
||||
M_StringAdd(&str, tmp);
|
||||
mem_fputs(tmp, stream);
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
if (dehfiles)
|
||||
{
|
||||
M_StringAdd(&str, " -deh");
|
||||
M_StringAdd(&str, dehfiles);
|
||||
mem_fputs(" -deh", stream);
|
||||
for (i = 0; dehfiles[i]; ++i)
|
||||
{
|
||||
tmp = M_StringJoin(" \"", M_BaseName(dehfiles[i]), "\"", NULL);
|
||||
mem_fputs(tmp, stream);
|
||||
free(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
if (demo_compatibility)
|
||||
{
|
||||
M_StringAdd(&str, " -complevel vanilla");
|
||||
mem_fputs(" -complevel vanilla", stream);
|
||||
tmp = M_StringJoin(" -gameversion ", GetGameVersionCmdline(), NULL);
|
||||
M_StringAdd(&str, tmp);
|
||||
mem_fputs(tmp, stream);
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
if (coop_spawns)
|
||||
{
|
||||
M_StringAdd(&str, " -coop_spawns");
|
||||
mem_fputs(" -coop_spawns", stream);
|
||||
}
|
||||
|
||||
M_StringAdd(&str, DEMO_FOOTER_SEPARATOR);
|
||||
if (M_CheckParm("-solo-net"))
|
||||
{
|
||||
mem_fputs(" -solo-net", stream);
|
||||
}
|
||||
|
||||
len = strlen(str);
|
||||
for (i = 0; i < EMU_TOTAL; ++i)
|
||||
{
|
||||
if (overflow[i].triggered)
|
||||
{
|
||||
tmp = M_StringJoin(" -", overflow[i].str, NULL);
|
||||
mem_fputs(tmp, stream);
|
||||
free(tmp);
|
||||
|
||||
overflow[i].triggered = false;
|
||||
}
|
||||
}
|
||||
|
||||
mem_fputs(DEMO_FOOTER_SEPARATOR, stream);
|
||||
|
||||
mem_get_buf(stream, (void **)&tmp, &len);
|
||||
|
||||
if (position + len > maxdemosize)
|
||||
{
|
||||
@ -3430,10 +3457,10 @@ static void G_AddDemoFooter(void)
|
||||
demo_p = position + demobuffer;
|
||||
}
|
||||
|
||||
memcpy(demo_p, str, len);
|
||||
memcpy(demo_p, tmp, len);
|
||||
demo_p += len;
|
||||
|
||||
free(str);
|
||||
mem_fclose(stream);
|
||||
}
|
||||
|
||||
//===================
|
||||
|
@ -717,21 +717,21 @@ default_t defaults[] = {
|
||||
|
||||
{
|
||||
"emu_spechits",
|
||||
(config_t *) &emu_spechits, NULL,
|
||||
(config_t *) &overflow[emu_spechits].enabled, NULL,
|
||||
{1}, {0,1}, number, ss_comp, wad_no,
|
||||
"1 to enable SPECHITS overflow emulation"
|
||||
},
|
||||
|
||||
{
|
||||
"emu_reject",
|
||||
(config_t *) &emu_reject, NULL,
|
||||
(config_t *) &overflow[emu_reject].enabled, NULL,
|
||||
{1}, {0,1}, number, ss_comp, wad_no,
|
||||
"1 to enable REJECT overflow emulation"
|
||||
},
|
||||
|
||||
{
|
||||
"emu_intercepts",
|
||||
(config_t *) &emu_intercepts, NULL,
|
||||
(config_t *) &overflow[emu_intercepts].enabled, NULL,
|
||||
{1}, {0,1}, number, ss_comp, wad_no,
|
||||
"1 to enable INTERCEPTS overflow emulation"
|
||||
},
|
||||
|
@ -476,24 +476,3 @@ int M_snprintf(char *buf, size_t buf_len, const char *s, ...)
|
||||
va_end(args);
|
||||
return result;
|
||||
}
|
||||
|
||||
void M_StringAdd(char **dest, const char *src)
|
||||
{
|
||||
size_t size;
|
||||
|
||||
if (!dest || !src)
|
||||
return;
|
||||
|
||||
if (*dest)
|
||||
{
|
||||
size = strlen(*dest) + strlen(src) + 1;
|
||||
*dest = realloc(*dest, size);
|
||||
M_StringConcat(*dest, src, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
size = strlen(src) + 2;
|
||||
*dest = malloc(size);
|
||||
M_StringCopy(*dest, src, size);
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,4 @@ boolean M_StringEndsWith(const char *s, const char *suffix);
|
||||
int M_vsnprintf(char *buf, size_t buf_len, const char *s, va_list args) PRINTF_ATTR(3, 0);
|
||||
int M_snprintf(char *buf, size_t buf_len, const char *s, ...) PRINTF_ATTR(3, 4);
|
||||
|
||||
void M_StringAdd(char **dest, const char *src);
|
||||
|
||||
#endif
|
||||
|
@ -140,6 +140,16 @@ size_t mem_fwrite(const void *ptr, size_t size, size_t nmemb, MEMFILE *stream)
|
||||
return nmemb;
|
||||
}
|
||||
|
||||
int mem_fputs(const char *str, MEMFILE *stream)
|
||||
{
|
||||
if (str == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return mem_fwrite(str, sizeof(char), strlen(str), stream);
|
||||
}
|
||||
|
||||
void mem_get_buf(MEMFILE *stream, void **buf, size_t *buflen)
|
||||
{
|
||||
*buf = stream->buf;
|
||||
@ -182,8 +192,8 @@ int mem_fseek(MEMFILE *stream, signed long position, mem_rel_t whence)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// We should allow seeking to the end of a MEMFILE with MEM_SEEK_END to
|
||||
// match stdio.h behavior.
|
||||
// We should allow seeking to the end of a MEMFILE with MEM_SEEK_END to
|
||||
// match stdio.h behavior.
|
||||
|
||||
if (newpos <= stream->buflen)
|
||||
{
|
||||
|
@ -29,6 +29,7 @@ MEMFILE *mem_fopen_read(void *buf, size_t buflen);
|
||||
size_t mem_fread(void *buf, size_t size, size_t nmemb, MEMFILE *stream);
|
||||
MEMFILE *mem_fopen_write(void);
|
||||
size_t mem_fwrite(const void *ptr, size_t size, size_t nmemb, MEMFILE *stream);
|
||||
int mem_fputs(const char *str, MEMFILE *stream);
|
||||
void mem_get_buf(MEMFILE *stream, void **buf, size_t *buflen);
|
||||
void mem_fclose(MEMFILE *stream);
|
||||
long mem_ftell(MEMFILE *stream);
|
||||
|
@ -456,10 +456,14 @@ static boolean PIT_CheckLine(line_t *ld) // killough 3/26/98: make static
|
||||
spechit[numspechit++] = ld;
|
||||
|
||||
// [FG] SPECHITS overflow emulation from Chocolate Doom / PrBoom+
|
||||
if (numspechit > MAXSPECIALCROSS_ORIGINAL && demo_compatibility && emu_spechits)
|
||||
if (numspechit > MAXSPECIALCROSS_ORIGINAL && demo_compatibility
|
||||
&& overflow[emu_spechits].enabled)
|
||||
{
|
||||
if (numspechit == MAXSPECIALCROSS_ORIGINAL + 1)
|
||||
{
|
||||
overflow[emu_spechits].triggered = true;
|
||||
fprintf(stderr, "PIT_CheckLine: Triggered SPECHITS overflow!\n");
|
||||
}
|
||||
SpechitOverrun(ld);
|
||||
}
|
||||
}
|
||||
|
@ -687,12 +687,14 @@ static void InterceptsMemoryOverrun(int location, int value)
|
||||
|
||||
static void InterceptsOverrun(int num_intercepts, intercept_t *intercept)
|
||||
{
|
||||
if (num_intercepts > MAXINTERCEPTS_ORIGINAL && demo_compatibility && emu_intercepts)
|
||||
if (num_intercepts > MAXINTERCEPTS_ORIGINAL && demo_compatibility
|
||||
&& overflow[emu_intercepts].enabled)
|
||||
{
|
||||
int location;
|
||||
|
||||
if (num_intercepts == MAXINTERCEPTS_ORIGINAL + 1)
|
||||
{
|
||||
overflow[emu_intercepts].triggered = true;
|
||||
// [crispy] print a warning
|
||||
fprintf(stderr, "Triggered INTERCEPTS overflow!\n");
|
||||
}
|
||||
|
@ -161,6 +161,8 @@ sector_t* GetSectorAtNullAddress(void)
|
||||
|
||||
if (demo_compatibility)
|
||||
{
|
||||
overflow[emu_missedbackside].triggered = true;
|
||||
|
||||
if (!null_sector_is_initialized)
|
||||
{
|
||||
memset(&null_sector, 0, sizeof(null_sector));
|
||||
@ -1433,7 +1435,7 @@ static boolean P_LoadReject(int lumpnum, int totallines)
|
||||
|
||||
memset(rejectmatrix + lumplen, padvalue, minlength - lumplen);
|
||||
|
||||
if (demo_compatibility && emu_reject)
|
||||
if (demo_compatibility && overflow[emu_reject].enabled)
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned int byte_num;
|
||||
@ -1447,6 +1449,8 @@ static boolean P_LoadReject(int lumpnum, int totallines)
|
||||
0x1d4a11 // DOOM_CONST_ZONEID
|
||||
};
|
||||
|
||||
overflow[emu_reject].triggered = true;
|
||||
|
||||
rejectpad[0] = ((totallines * 4 + 3) & ~3) + 24;
|
||||
|
||||
// Copy values from rejectpad into the destination array.
|
||||
|
Loading…
x
Reference in New Issue
Block a user