mirror of
https://github.com/ZDoom/raze-gles.git
synced 2025-01-12 03:00:38 +00:00
Improved error checking for savegames
git-svn-id: https://svn.eduke32.com/eduke32@120 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
9d147dcfaa
commit
a1db735f69
7 changed files with 58 additions and 47 deletions
|
@ -513,7 +513,7 @@ void CONFIG_SetupJoystick( void )
|
||||||
|
|
||||||
void readsavenames(void)
|
void readsavenames(void)
|
||||||
{
|
{
|
||||||
long dummy;
|
long dummy,j;
|
||||||
short i;
|
short i;
|
||||||
char fn[13];
|
char fn[13];
|
||||||
BFILE *fil;
|
BFILE *fil;
|
||||||
|
@ -524,8 +524,9 @@ void readsavenames(void)
|
||||||
{
|
{
|
||||||
fn[4] = i+'0';
|
fn[4] = i+'0';
|
||||||
if ((fil = Bfopen(fn,"rb")) == NULL ) continue;
|
if ((fil = Bfopen(fn,"rb")) == NULL ) continue;
|
||||||
|
if(dfread(&j,sizeof(long),1,fil) != 1) { Bfclose(fil); continue; }
|
||||||
|
if(dfread(g_szBuf,j,1,fil) != 1) { Bfclose(fil); continue; }
|
||||||
if (dfread(&dummy,4,1,fil) != 1) { Bfclose(fil); continue; }
|
if (dfread(&dummy,4,1,fil) != 1) { Bfclose(fil); continue; }
|
||||||
|
|
||||||
if(dummy != BYTEVERSION) return;
|
if(dummy != BYTEVERSION) return;
|
||||||
if (dfread(&dummy,4,1,fil) != 1) { Bfclose(fil); continue; }
|
if (dfread(&dummy,4,1,fil) != 1) { Bfclose(fil); continue; }
|
||||||
if (dfread(&ud.savegame[i][0],19,1,fil) != 1) { ud.savegame[i][0] = 0; }
|
if (dfread(&ud.savegame[i][0],19,1,fil) != 1) { ud.savegame[i][0] = 0; }
|
||||||
|
|
|
@ -338,7 +338,7 @@ extern void ResetSystemDefaults(void);
|
||||||
extern void InitGameVarPointers(void);
|
extern void InitGameVarPointers(void);
|
||||||
extern void InitGameVars(void);
|
extern void InitGameVars(void);
|
||||||
extern void SaveGameVars(FILE *fil);
|
extern void SaveGameVars(FILE *fil);
|
||||||
extern void ReadGameVars(long fil);
|
extern int ReadGameVars(long fil);
|
||||||
|
|
||||||
extern int GetGameID(char *szGameLabel);
|
extern int GetGameID(char *szGameLabel);
|
||||||
extern long GetGameVarID(int id, short sActor, short sPlayer);
|
extern long GetGameVarID(int id, short sActor, short sPlayer);
|
||||||
|
|
|
@ -1031,29 +1031,24 @@ void AddLog(char *psz)
|
||||||
|
|
||||||
char AddGameVar(char *pszLabel, long lValue, unsigned long dwFlags);
|
char AddGameVar(char *pszLabel, long lValue, unsigned long dwFlags);
|
||||||
|
|
||||||
void ReadGameVars(long fil)
|
int ReadGameVars(long fil)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
long l;
|
long l;
|
||||||
|
|
||||||
// AddLog("Reading gamevars from savegame");
|
// AddLog("Reading gamevars from savegame");
|
||||||
|
|
||||||
kdfread(&l,sizeof(l),1,fil);
|
|
||||||
kdfread(g_szBuf,l,1,fil);
|
|
||||||
g_szBuf[l]=0;
|
|
||||||
AddLog(g_szBuf);
|
|
||||||
|
|
||||||
FreeGameVars(); // nuke 'em from orbit, it's the only way to be sure...
|
FreeGameVars(); // nuke 'em from orbit, it's the only way to be sure...
|
||||||
// Bsprintf(g_szBuf,"CP:%s %d",__FILE__,__LINE__);
|
// Bsprintf(g_szBuf,"CP:%s %d",__FILE__,__LINE__);
|
||||||
// AddLog(g_szBuf);
|
// AddLog(g_szBuf);
|
||||||
|
|
||||||
kdfread(&iGameVarCount,sizeof(iGameVarCount),1,fil);
|
if(kdfread(&iGameVarCount,sizeof(iGameVarCount),1,fil) != 1) goto corrupt;
|
||||||
|
|
||||||
for(i=0;i<iGameVarCount;i++)
|
for(i=0;i<iGameVarCount;i++)
|
||||||
{
|
{
|
||||||
kdfread(&(aGameVars[i]),sizeof(MATTGAMEVAR),1,fil);
|
if(kdfread(&(aGameVars[i]),sizeof(MATTGAMEVAR),1,fil) != 1) goto corrupt;
|
||||||
aGameVars[i].szLabel=Bcalloc(MAXVARLABEL,sizeof(char));
|
aGameVars[i].szLabel=Bcalloc(MAXVARLABEL,sizeof(char));
|
||||||
kdfread(aGameVars[i].szLabel,sizeof(char) * MAXVARLABEL, 1, fil);
|
if(kdfread(aGameVars[i].szLabel,sizeof(char) * MAXVARLABEL, 1, fil) != 1) goto corrupt;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bsprintf(g_szBuf,"CP:%s %d",__FILE__,__LINE__);
|
// Bsprintf(g_szBuf,"CP:%s %d",__FILE__,__LINE__);
|
||||||
|
@ -1081,20 +1076,20 @@ void ReadGameVars(long fil)
|
||||||
{
|
{
|
||||||
//Bsprintf(g_szBuf,"Reading value array for %s (%d)",aGameVars[i].szLabel,sizeof(long) * MAXPLAYERS);
|
//Bsprintf(g_szBuf,"Reading value array for %s (%d)",aGameVars[i].szLabel,sizeof(long) * MAXPLAYERS);
|
||||||
//AddLog(g_szBuf);
|
//AddLog(g_szBuf);
|
||||||
kdfread(aGameVars[i].plValues,sizeof(long) * MAXPLAYERS, 1, fil);
|
if(kdfread(aGameVars[i].plValues,sizeof(long) * MAXPLAYERS, 1, fil) != 1) goto corrupt;
|
||||||
}
|
}
|
||||||
else if( aGameVars[i].dwFlags & GAMEVAR_FLAG_PERACTOR)
|
else if( aGameVars[i].dwFlags & GAMEVAR_FLAG_PERACTOR)
|
||||||
{
|
{
|
||||||
//Bsprintf(g_szBuf,"Reading value array for %s (%d)",aGameVars[i].szLabel,sizeof(long) * MAXSPRITES);
|
//Bsprintf(g_szBuf,"Reading value array for %s (%d)",aGameVars[i].szLabel,sizeof(long) * MAXSPRITES);
|
||||||
//AddLog(g_szBuf);
|
//AddLog(g_szBuf);
|
||||||
kdfread(aGameVars[i].plValues,sizeof(long) * MAXSPRITES, 1, fil);
|
if(kdfread(aGameVars[i].plValues,sizeof(long) * MAXSPRITES, 1, fil) != 1) goto corrupt;
|
||||||
}
|
}
|
||||||
// else nothing 'extra...'
|
// else nothing 'extra...'
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bsprintf(g_szBuf,"CP:%s %d",__FILE__,__LINE__);
|
// Bsprintf(g_szBuf,"CP:%s %d",__FILE__,__LINE__);
|
||||||
// AddLog(g_szBuf);
|
// AddLog(g_szBuf);
|
||||||
kdfread(apScriptGameEvent,sizeof(apScriptGameEvent),1,fil);
|
if(kdfread(apScriptGameEvent,sizeof(apScriptGameEvent),1,fil) != 1) goto corrupt;
|
||||||
for(i=0;i<MAXGAMEEVENTS;i++)
|
for(i=0;i<MAXGAMEEVENTS;i++)
|
||||||
if(apScriptGameEvent[i])
|
if(apScriptGameEvent[i])
|
||||||
{
|
{
|
||||||
|
@ -1104,8 +1099,8 @@ void ReadGameVars(long fil)
|
||||||
|
|
||||||
// Bsprintf(g_szBuf,"CP:%s %d",__FILE__,__LINE__);
|
// Bsprintf(g_szBuf,"CP:%s %d",__FILE__,__LINE__);
|
||||||
// AddLog(g_szBuf);
|
// AddLog(g_szBuf);
|
||||||
kdfread(&l,sizeof(l),1,fil);
|
if(kdfread(&l,sizeof(l),1,fil) != 1) goto corrupt;
|
||||||
kdfread(g_szBuf,l,1,fil);
|
if(kdfread(g_szBuf,l,1,fil) != 1) goto corrupt;
|
||||||
g_szBuf[l]=0;
|
g_szBuf[l]=0;
|
||||||
AddLog(g_szBuf);
|
AddLog(g_szBuf);
|
||||||
|
|
||||||
|
@ -1122,6 +1117,9 @@ void ReadGameVars(long fil)
|
||||||
AddLog("Done Dumping...");
|
AddLog("Done Dumping...");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
return(0);
|
||||||
|
corrupt:
|
||||||
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveGameVars(FILE *fil)
|
void SaveGameVars(FILE *fil)
|
||||||
|
@ -1130,11 +1128,6 @@ void SaveGameVars(FILE *fil)
|
||||||
long l;
|
long l;
|
||||||
|
|
||||||
// AddLog("Saving Game Vars to File");
|
// AddLog("Saving Game Vars to File");
|
||||||
Bsprintf(g_szBuf,"EDuke32");
|
|
||||||
l=strlen(g_szBuf);
|
|
||||||
dfwrite(&l,sizeof(l),1,fil);
|
|
||||||
dfwrite(g_szBuf,l,1,fil);
|
|
||||||
|
|
||||||
dfwrite(&iGameVarCount,sizeof(iGameVarCount),1,fil);
|
dfwrite(&iGameVarCount,sizeof(iGameVarCount),1,fil);
|
||||||
|
|
||||||
for(i=0;i<iGameVarCount;i++)
|
for(i=0;i<iGameVarCount;i++)
|
||||||
|
|
|
@ -258,9 +258,6 @@ short aim(spritetype *s,short aang,short atwith)
|
||||||
long dx1, dy1, dx2, dy2, dx3, dy3, smax, sdist;
|
long dx1, dy1, dx2, dy2, dx3, dy3, smax, sdist;
|
||||||
long xv, yv;
|
long xv, yv;
|
||||||
|
|
||||||
a = s->ang;
|
|
||||||
|
|
||||||
j = -1;
|
|
||||||
if(s->picnum == APLAYER) {
|
if(s->picnum == APLAYER) {
|
||||||
if(!ps[s->yvel].auto_aim)
|
if(!ps[s->yvel].auto_aim)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -283,6 +280,11 @@ short aim(spritetype *s,short aang,short atwith)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a = s->ang;
|
||||||
|
|
||||||
|
j = -1;
|
||||||
|
|
||||||
gotshrinker = s->picnum == APLAYER && *aplWeaponWorksLike[ps[s->yvel].curr_weapon] == SHRINKER_WEAPON;
|
gotshrinker = s->picnum == APLAYER && *aplWeaponWorksLike[ps[s->yvel].curr_weapon] == SHRINKER_WEAPON;
|
||||||
gotfreezer = s->picnum == APLAYER && *aplWeaponWorksLike[ps[s->yvel].curr_weapon] == FREEZE_WEAPON;
|
gotfreezer = s->picnum == APLAYER && *aplWeaponWorksLike[ps[s->yvel].curr_weapon] == FREEZE_WEAPON;
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,11 @@ int loadpheader(char spot,struct savehead *saveh)
|
||||||
|
|
||||||
walock[TILE_LOADSHOT] = 255;
|
walock[TILE_LOADSHOT] = 255;
|
||||||
|
|
||||||
|
if(kdfread(&bv,sizeof(bv),1,fil) != 1) goto corrupt;
|
||||||
|
if(kdfread(g_szBuf,bv,1,fil) != 1) goto corrupt;
|
||||||
|
g_szBuf[bv]=0;
|
||||||
|
AddLog(g_szBuf);
|
||||||
|
|
||||||
if (kdfread(&bv,4,1,fil) != 1) goto corrupt;
|
if (kdfread(&bv,4,1,fil) != 1) goto corrupt;
|
||||||
if(bv != BYTEVERSION) {
|
if(bv != BYTEVERSION) {
|
||||||
FTA(114,&ps[myconnectindex]);
|
FTA(114,&ps[myconnectindex]);
|
||||||
|
@ -105,6 +110,11 @@ int loadplayer(signed char spot)
|
||||||
|
|
||||||
ready2send = 0;
|
ready2send = 0;
|
||||||
|
|
||||||
|
if(kdfread(&bv,sizeof(bv),1,fil) != 1) goto corrupt;
|
||||||
|
if(kdfread(g_szBuf,bv,1,fil) != 1) goto corrupt;
|
||||||
|
g_szBuf[bv]=0;
|
||||||
|
AddLog(g_szBuf);
|
||||||
|
|
||||||
if (kdfread(&bv,4,1,fil) != 1) return -1;
|
if (kdfread(&bv,4,1,fil) != 1) return -1;
|
||||||
if(bv != BYTEVERSION)
|
if(bv != BYTEVERSION)
|
||||||
{
|
{
|
||||||
|
@ -315,7 +325,7 @@ int loadplayer(signed char spot)
|
||||||
|
|
||||||
if (kdfread(&dynamictostatic[0],sizeof(dynamictostatic[0]),MAXTILES,fil) != MAXTILES) goto corrupt;
|
if (kdfread(&dynamictostatic[0],sizeof(dynamictostatic[0]),MAXTILES,fil) != MAXTILES) goto corrupt;
|
||||||
|
|
||||||
ReadGameVars(fil);
|
if(ReadGameVars(fil)) goto corrupt;
|
||||||
|
|
||||||
kclose(fil);
|
kclose(fil);
|
||||||
|
|
||||||
|
@ -476,6 +486,11 @@ int saveplayer(signed char spot)
|
||||||
|
|
||||||
ready2send = 0;
|
ready2send = 0;
|
||||||
|
|
||||||
|
Bsprintf(g_szBuf,"EDuke32");
|
||||||
|
i=strlen(g_szBuf);
|
||||||
|
dfwrite(&i,sizeof(i),1,fil);
|
||||||
|
dfwrite(g_szBuf,i,1,fil);
|
||||||
|
|
||||||
dfwrite(&bv,4,1,fil);
|
dfwrite(&bv,4,1,fil);
|
||||||
dfwrite(&ud.multimode,sizeof(ud.multimode),1,fil);
|
dfwrite(&ud.multimode,sizeof(ud.multimode),1,fil);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue