From 26770c5103dc0be80bf9a3ae383ad6ad63bfd1dc Mon Sep 17 00:00:00 2001 From: fickleheart Date: Sun, 27 Jan 2019 15:45:42 -0600 Subject: [PATCH] [HACK] Save correct lap count on netreplays --- src/command.c | 16 +++++++++++++--- src/command.h | 2 +- src/d_clisrv.c | 2 +- src/g_game.c | 4 ++-- src/p_saveg.c | 2 +- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/command.c b/src/command.c index bb2ea86e..164b0988 100644 --- a/src/command.c +++ b/src/command.c @@ -1355,7 +1355,7 @@ static void Got_NetVar(UINT8 **p, INT32 playernum) Setvalue(cvar, svalue, stealth); } -void CV_SaveNetVars(UINT8 **p) +void CV_SaveNetVars(UINT8 **p, boolean demorecording) { consvar_t *cvar; UINT8 *count_p = *p; @@ -1365,10 +1365,20 @@ void CV_SaveNetVars(UINT8 **p) // the client will reset all netvars to default before loading WRITEUINT16(*p, 0x0000); for (cvar = consvar_vars; cvar; cvar = cvar->next) - if ((cvar->flags & CV_NETVAR) && !CV_IsSetToDefault(cvar)) + if (((cvar->flags & CV_NETVAR) && !CV_IsSetToDefault(cvar)) || (demorecording && cvar->netid == cv_numlaps.netid)) { WRITEUINT16(*p, cvar->netid); - WRITESTRING(*p, cvar->string); + + // UGLY HACK: Save proper lap count in net replays + if (demorecording && cvar->netid == cv_numlaps.netid) + { + WRITESTRING(*p, cv_basenumlaps.string); + } + else + { + WRITESTRING(*p, cvar->string); + } + WRITEUINT8(*p, false); ++count; } diff --git a/src/command.h b/src/command.h index 82dfaf8a..70bf74a9 100644 --- a/src/command.h +++ b/src/command.h @@ -160,7 +160,7 @@ void CV_AddValue(consvar_t *var, INT32 increment); void CV_SaveVariables(FILE *f); // load/save gamesate (load and save option and for network join in game) -void CV_SaveNetVars(UINT8 **p); +void CV_SaveNetVars(UINT8 **p, boolean demorecording); void CV_LoadNetVars(UINT8 **p); // reset cheat netvars after cheats is deactivated diff --git a/src/d_clisrv.c b/src/d_clisrv.c index c84faa72..5369ff2c 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1500,7 +1500,7 @@ static boolean SV_SendServerConfig(INT32 node) op = p = netbuffer->u.servercfg.varlengthinputs; CV_SavePlayerNames(&p); - CV_SaveNetVars(&p); + CV_SaveNetVars(&p, false); { const size_t len = sizeof (serverconfig_pak) + (size_t)(p - op); diff --git a/src/g_game.c b/src/g_game.c index e548399b..d429ccd8 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -5494,7 +5494,7 @@ void G_BeginRecording(void) if (demoflags & DF_MULTIPLAYER) { // Netvars first :) - CV_SaveNetVars(&demo_p); + CV_SaveNetVars(&demo_p, true); // Now store a SIMPLIFIED data struct for each in-game player for (p = 0; p < MAXPLAYERS; p++) { @@ -5576,7 +5576,7 @@ void G_BeginRecording(void) WRITEFIXED(demo_p, player->jumpfactor); // Save netvar data (SONICCD, etc) - CV_SaveNetVars(&demo_p); + CV_SaveNetVars(&demo_p, false); //@TODO can this be true? it's not necessary for now but would be nice for consistency memset(&oldcmd,0,sizeof(oldcmd)); memset(&oldghost,0,sizeof(oldghost)); diff --git a/src/p_saveg.c b/src/p_saveg.c index 975a4a5d..52a35c37 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -3447,7 +3447,7 @@ void P_SaveNetGame(void) mobj_t *mobj; INT32 i = 1; // don't start from 0, it'd be confused with a blank pointer otherwise - CV_SaveNetVars(&save_p); + CV_SaveNetVars(&save_p, false); P_NetArchiveMisc(); // Assign the mobjnumber for pointer tracking