mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2024-11-24 13:21:20 +00:00
Pass save_t to NetVar save/load function
This commit is contained in:
parent
0cf3ce91e9
commit
7061c30744
5 changed files with 65 additions and 46 deletions
|
@ -1722,8 +1722,7 @@ badinput:
|
|||
|
||||
static boolean serverloading = false;
|
||||
|
||||
static consvar_t *
|
||||
ReadNetVar (UINT8 **p, char **return_value, boolean *return_stealth)
|
||||
static consvar_t *ReadNetVar(save_t *p, char **return_value, boolean *return_stealth)
|
||||
{
|
||||
UINT16 netid;
|
||||
char *val;
|
||||
|
@ -1731,10 +1730,10 @@ ReadNetVar (UINT8 **p, char **return_value, boolean *return_stealth)
|
|||
|
||||
consvar_t *cvar;
|
||||
|
||||
netid = READUINT16 (*p);
|
||||
val = (char *)*p;
|
||||
SKIPSTRING (*p);
|
||||
stealth = READUINT8 (*p);
|
||||
netid = P_ReadUINT16(p);
|
||||
val = (char *)&p->buf[p->pos];
|
||||
P_SkipString(p);
|
||||
stealth = P_ReadUINT8(p);
|
||||
|
||||
cvar = CV_FindNetVar(netid);
|
||||
|
||||
|
@ -1752,8 +1751,7 @@ ReadNetVar (UINT8 **p, char **return_value, boolean *return_stealth)
|
|||
}
|
||||
|
||||
#ifdef OLD22DEMOCOMPAT
|
||||
static consvar_t *
|
||||
ReadOldDemoVar (UINT8 **p, char **return_value, boolean *return_stealth)
|
||||
static consvar_t *ReadOldDemoVar(save_t *p, char **return_value, boolean *return_stealth)
|
||||
{
|
||||
UINT16 id;
|
||||
char *val;
|
||||
|
@ -1761,10 +1759,10 @@ ReadOldDemoVar (UINT8 **p, char **return_value, boolean *return_stealth)
|
|||
|
||||
old_demo_var_t *demovar;
|
||||
|
||||
id = READUINT16 (*p);
|
||||
val = (char *)*p;
|
||||
SKIPSTRING (*p);
|
||||
stealth = READUINT8 (*p);
|
||||
id = P_ReadUINT16(p);
|
||||
val = (char *)&p->buf[p->pos];
|
||||
P_SkipString(p);
|
||||
stealth = P_ReadUINT8(p);
|
||||
|
||||
demovar = CV_FindOldDemoVar(id);
|
||||
|
||||
|
@ -1783,8 +1781,7 @@ ReadOldDemoVar (UINT8 **p, char **return_value, boolean *return_stealth)
|
|||
}
|
||||
#endif/*OLD22DEMOCOMPAT*/
|
||||
|
||||
static consvar_t *
|
||||
ReadDemoVar (UINT8 **p, char **return_value, boolean *return_stealth)
|
||||
static consvar_t *ReadDemoVar(save_t *p, char **return_value, boolean *return_stealth)
|
||||
{
|
||||
char *name;
|
||||
char *val;
|
||||
|
@ -1792,11 +1789,11 @@ ReadDemoVar (UINT8 **p, char **return_value, boolean *return_stealth)
|
|||
|
||||
consvar_t *cvar;
|
||||
|
||||
name = (char *)*p;
|
||||
SKIPSTRING (*p);
|
||||
val = (char *)*p;
|
||||
SKIPSTRING (*p);
|
||||
stealth = READUINT8 (*p);
|
||||
name = (char *)&p->buf[p->pos];
|
||||
P_SkipString(p);
|
||||
val = (char *)&p->buf[p->pos];
|
||||
P_SkipString(p);
|
||||
stealth = P_ReadUINT8(p);
|
||||
|
||||
cvar = CV_FindVar(name);
|
||||
|
||||
|
@ -1826,41 +1823,46 @@ static void Got_NetVar(UINT8 **p, INT32 playernum)
|
|||
return;
|
||||
}
|
||||
|
||||
cvar = ReadNetVar(p, &svalue, &stealth);
|
||||
save_t save_p;
|
||||
save_p.buf = *p;
|
||||
save_p.size = MAXTEXTCMD;
|
||||
save_p.pos = 0;
|
||||
cvar = ReadNetVar(&save_p, &svalue, &stealth);
|
||||
*p = &save_p.buf[save_p.pos];
|
||||
|
||||
if (cvar)
|
||||
Setvalue(cvar, svalue, stealth);
|
||||
}
|
||||
|
||||
void CV_SaveVars(UINT8 **p, boolean in_demo)
|
||||
void CV_SaveVars(save_t *p, boolean in_demo)
|
||||
{
|
||||
consvar_t *cvar;
|
||||
UINT8 *count_p = *p;
|
||||
UINT8 *count_p = &p->buf[p->pos];
|
||||
UINT16 count = 0;
|
||||
|
||||
// send only changed cvars ...
|
||||
// the client will reset all netvars to default before loading
|
||||
WRITEUINT16(*p, 0x0000);
|
||||
P_WriteUINT16(p, 0x0000);
|
||||
for (cvar = consvar_vars; cvar; cvar = cvar->next)
|
||||
if ((cvar->flags & CV_NETVAR) && !CV_IsSetToDefault(cvar))
|
||||
{
|
||||
if (in_demo)
|
||||
{
|
||||
WRITESTRING(*p, cvar->name);
|
||||
P_WriteString(p, cvar->name);
|
||||
}
|
||||
else
|
||||
{
|
||||
WRITEUINT16(*p, cvar->netid);
|
||||
P_WriteUINT16(p, cvar->netid);
|
||||
}
|
||||
WRITESTRING(*p, cvar->string);
|
||||
WRITEUINT8(*p, false);
|
||||
P_WriteString(p, cvar->string);
|
||||
P_WriteUINT8(p, false);
|
||||
++count;
|
||||
}
|
||||
WRITEUINT16(count_p, count);
|
||||
}
|
||||
|
||||
static void CV_LoadVars(UINT8 **p,
|
||||
consvar_t *(*got)(UINT8 **p, char **ret_value, boolean *ret_stealth))
|
||||
static void CV_LoadVars(save_t *p,
|
||||
consvar_t *(*got)(save_t *p, char **ret_value, boolean *ret_stealth))
|
||||
{
|
||||
const boolean store = (client || demoplayback);
|
||||
|
||||
|
@ -1888,7 +1890,7 @@ static void CV_LoadVars(UINT8 **p,
|
|||
}
|
||||
}
|
||||
|
||||
count = READUINT16(*p);
|
||||
count = P_ReadUINT16(p);
|
||||
while (count--)
|
||||
{
|
||||
cvar = (*got)(p, &val, &stealth);
|
||||
|
@ -1921,19 +1923,19 @@ void CV_RevertNetVars(void)
|
|||
}
|
||||
}
|
||||
|
||||
void CV_LoadNetVars(UINT8 **p)
|
||||
void CV_LoadNetVars(save_t *p)
|
||||
{
|
||||
CV_LoadVars(p, ReadNetVar);
|
||||
}
|
||||
|
||||
#ifdef OLD22DEMOCOMPAT
|
||||
void CV_LoadOldDemoVars(UINT8 **p)
|
||||
void CV_LoadOldDemoVars(save_t *p)
|
||||
{
|
||||
CV_LoadVars(p, ReadOldDemoVar);
|
||||
}
|
||||
#endif
|
||||
|
||||
void CV_LoadDemoVars(UINT8 **p)
|
||||
void CV_LoadDemoVars(save_t *p)
|
||||
{
|
||||
CV_LoadVars(p, ReadDemoVar);
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include "doomdef.h"
|
||||
#include "p_saveg.h"
|
||||
|
||||
//===================================
|
||||
// Command buffer & command execution
|
||||
|
@ -218,19 +219,19 @@ 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_SaveVars(UINT8 **p, boolean in_demo);
|
||||
void CV_SaveVars(save_t *p, boolean in_demo);
|
||||
|
||||
#define CV_SaveNetVars(p) CV_SaveVars(p, false)
|
||||
void CV_LoadNetVars(UINT8 **p);
|
||||
void CV_LoadNetVars(save_t *p);
|
||||
|
||||
// then revert after leaving a netgame
|
||||
void CV_RevertNetVars(void);
|
||||
|
||||
#define CV_SaveDemoVars(p) CV_SaveVars(p, true)
|
||||
void CV_LoadDemoVars(UINT8 **p);
|
||||
void CV_LoadDemoVars(save_t *p);
|
||||
|
||||
#ifdef OLD22DEMOCOMPAT
|
||||
void CV_LoadOldDemoVars(UINT8 **p);
|
||||
void CV_LoadOldDemoVars(save_t *p);
|
||||
#endif
|
||||
|
||||
// reset cheat netvars after cheats is deactivated
|
||||
|
|
25
src/g_demo.c
25
src/g_demo.c
|
@ -1454,6 +1454,7 @@ void G_BeginRecording(void)
|
|||
char *filename;
|
||||
UINT16 totalfiles;
|
||||
UINT8 *m;
|
||||
save_t savebuffer;
|
||||
|
||||
if (demo_p)
|
||||
return;
|
||||
|
@ -1603,7 +1604,11 @@ void G_BeginRecording(void)
|
|||
}
|
||||
|
||||
// Save netvar data
|
||||
CV_SaveDemoVars(&demo_p);
|
||||
savebuffer.buf = demo_p;
|
||||
savebuffer.size = demoend - demo_p;
|
||||
savebuffer.pos = 0;
|
||||
CV_SaveDemoVars(&savebuffer);
|
||||
demo_p = &savebuffer.buf[savebuffer.pos];
|
||||
|
||||
memset(&oldcmd,0,sizeof(oldcmd));
|
||||
memset(&oldghost,0,sizeof(oldghost));
|
||||
|
@ -2236,10 +2241,24 @@ void G_DoPlayDemo(char *defdemoname)
|
|||
// net var data
|
||||
#ifdef OLD22DEMOCOMPAT
|
||||
if (demoversion < 0x000d)
|
||||
CV_LoadOldDemoVars(&demo_p);
|
||||
{
|
||||
save_t savebuffer;
|
||||
savebuffer.buf = demo_p;
|
||||
savebuffer.size = demoend - demo_p;
|
||||
savebuffer.pos = 0;
|
||||
CV_LoadOldDemoVars(&savebuffer);
|
||||
demo_p = &savebuffer.buf[savebuffer.pos];
|
||||
}
|
||||
else
|
||||
#endif
|
||||
CV_LoadDemoVars(&demo_p);
|
||||
{
|
||||
save_t savebuffer;
|
||||
savebuffer.buf = demo_p;
|
||||
savebuffer.size = demoend - demo_p;
|
||||
savebuffer.pos = 0;
|
||||
CV_LoadDemoVars(&savebuffer);
|
||||
demo_p = &savebuffer.buf[savebuffer.pos];
|
||||
}
|
||||
|
||||
// Sigh ... it's an empty demo.
|
||||
if (*demo_p == DEMOMARKER)
|
||||
|
|
|
@ -80,6 +80,7 @@ void SV_SendSaveGame(INT32 node, boolean resending)
|
|||
if (!compressedsave)
|
||||
{
|
||||
CONS_Alert(CONS_ERROR, M_GetText("No more free memory for savegame\n"));
|
||||
free(savebuffer.buf);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -5356,9 +5356,7 @@ void P_SaveNetGame(save_t *save_p, boolean resending)
|
|||
mobj_t *mobj;
|
||||
INT32 i = 1; // don't start from 0, it'd be confused with a blank pointer otherwise
|
||||
|
||||
UINT8 *p = &save_p->buf[save_p->pos];
|
||||
CV_SaveNetVars(&p);
|
||||
save_p->pos = p - save_p->buf;
|
||||
CV_SaveNetVars(save_p);
|
||||
P_NetArchiveMisc(save_p, resending);
|
||||
P_NetArchiveEmblems(save_p);
|
||||
|
||||
|
@ -5411,9 +5409,7 @@ boolean P_LoadGame(save_t *save_p, INT16 mapoverride)
|
|||
|
||||
boolean P_LoadNetGame(save_t *save_p, boolean reloading)
|
||||
{
|
||||
UINT8 *p = &save_p->buf[save_p->pos];
|
||||
CV_LoadNetVars(&p);
|
||||
save_p->pos = p - save_p->buf;
|
||||
CV_LoadNetVars(save_p);
|
||||
if (!P_NetUnArchiveMisc(save_p, reloading))
|
||||
return false;
|
||||
P_NetUnArchiveEmblems(save_p);
|
||||
|
|
Loading…
Reference in a new issue