mirror of
https://github.com/ZDoom/Raze.git
synced 2024-11-15 00:42:08 +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)
|
||||
{
|
||||
long dummy;
|
||||
long dummy,j;
|
||||
short i;
|
||||
char fn[13];
|
||||
BFILE *fil;
|
||||
|
@ -524,8 +524,9 @@ void readsavenames(void)
|
|||
{
|
||||
fn[4] = i+'0';
|
||||
if ((fil = Bfopen(fn,"rb")) == NULL ) continue;
|
||||
if (dfread(&dummy,4,1,fil) != 1) { Bfclose(fil); 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(dummy != BYTEVERSION) return;
|
||||
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; }
|
||||
|
|
|
@ -338,7 +338,7 @@ extern void ResetSystemDefaults(void);
|
|||
extern void InitGameVarPointers(void);
|
||||
extern void InitGameVars(void);
|
||||
extern void SaveGameVars(FILE *fil);
|
||||
extern void ReadGameVars(long fil);
|
||||
extern int ReadGameVars(long fil);
|
||||
|
||||
extern int GetGameID(char *szGameLabel);
|
||||
extern long GetGameVarID(int id, short sActor, short sPlayer);
|
||||
|
|
|
@ -346,7 +346,7 @@ void getpackets(void)
|
|||
}
|
||||
|
||||
// only dispatch commands here when not in a game
|
||||
if( !(ps[myconnectindex].gm&MODE_GAME) ) { OSD_DispatchQueued(); }
|
||||
if( !(ps[myconnectindex].gm&MODE_GAME) ) { OSD_DispatchQueued(); }
|
||||
|
||||
if(qe == 0 && KB_KeyPressed(sc_LeftControl) && KB_KeyPressed(sc_LeftAlt) && KB_KeyPressed(sc_Delete))
|
||||
{
|
||||
|
@ -368,30 +368,30 @@ void getpackets(void)
|
|||
if (i != other)
|
||||
sendpacket(i,packbuf,packbufleng);
|
||||
}
|
||||
/*
|
||||
j = packbuf[1];
|
||||
playerquitflag[j] = 0;
|
||||
/*
|
||||
j = packbuf[1];
|
||||
playerquitflag[j] = 0;
|
||||
|
||||
j = -1;
|
||||
for(i=connecthead;i>=0;i=connectpoint2[i])
|
||||
{
|
||||
if (playerquitflag[i]) { j = i; continue; }
|
||||
j = -1;
|
||||
for(i=connecthead;i>=0;i=connectpoint2[i])
|
||||
{
|
||||
if (playerquitflag[i]) { j = i; continue; }
|
||||
|
||||
if (i == connecthead) connecthead = connectpoint2[connecthead];
|
||||
else connectpoint2[j] = connectpoint2[i];
|
||||
if (i == connecthead) connecthead = connectpoint2[connecthead];
|
||||
else connectpoint2[j] = connectpoint2[i];
|
||||
|
||||
numplayers--;
|
||||
ud.multimode--;
|
||||
numplayers--;
|
||||
ud.multimode--;
|
||||
|
||||
Bsprintf(buf,"%s is history!",ud.user_name[i]);
|
||||
adduserquote(buf);
|
||||
Bsprintf(buf,"%s is history!",ud.user_name[i]);
|
||||
adduserquote(buf);
|
||||
|
||||
if (numplayers < 2)
|
||||
sound(GENERIC_AMBIENCE17);
|
||||
if (numplayers < 2)
|
||||
sound(GENERIC_AMBIENCE17);
|
||||
|
||||
if(i == 0 && networkmode == 0 ) */
|
||||
gameexit( "Game aborted from menu; disconnected.");
|
||||
// }
|
||||
if(i == 0 && networkmode == 0 ) */
|
||||
gameexit( "Game aborted from menu; disconnected.");
|
||||
// }
|
||||
|
||||
break;
|
||||
|
||||
|
|
|
@ -1031,29 +1031,24 @@ void AddLog(char *psz)
|
|||
|
||||
char AddGameVar(char *pszLabel, long lValue, unsigned long dwFlags);
|
||||
|
||||
void ReadGameVars(long fil)
|
||||
int ReadGameVars(long fil)
|
||||
{
|
||||
int i;
|
||||
long l;
|
||||
|
||||
// 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...
|
||||
// Bsprintf(g_szBuf,"CP:%s %d",__FILE__,__LINE__);
|
||||
// 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++)
|
||||
{
|
||||
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));
|
||||
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__);
|
||||
|
@ -1081,20 +1076,20 @@ void ReadGameVars(long fil)
|
|||
{
|
||||
//Bsprintf(g_szBuf,"Reading value array for %s (%d)",aGameVars[i].szLabel,sizeof(long) * MAXPLAYERS);
|
||||
//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)
|
||||
{
|
||||
//Bsprintf(g_szBuf,"Reading value array for %s (%d)",aGameVars[i].szLabel,sizeof(long) * MAXSPRITES);
|
||||
//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...'
|
||||
}
|
||||
|
||||
// Bsprintf(g_szBuf,"CP:%s %d",__FILE__,__LINE__);
|
||||
// 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++)
|
||||
if(apScriptGameEvent[i])
|
||||
{
|
||||
|
@ -1104,8 +1099,8 @@ void ReadGameVars(long fil)
|
|||
|
||||
// Bsprintf(g_szBuf,"CP:%s %d",__FILE__,__LINE__);
|
||||
// AddLog(g_szBuf);
|
||||
kdfread(&l,sizeof(l),1,fil);
|
||||
kdfread(g_szBuf,l,1,fil);
|
||||
if(kdfread(&l,sizeof(l),1,fil) != 1) goto corrupt;
|
||||
if(kdfread(g_szBuf,l,1,fil) != 1) goto corrupt;
|
||||
g_szBuf[l]=0;
|
||||
AddLog(g_szBuf);
|
||||
|
||||
|
@ -1122,6 +1117,9 @@ void ReadGameVars(long fil)
|
|||
AddLog("Done Dumping...");
|
||||
}
|
||||
#endif
|
||||
return(0);
|
||||
corrupt:
|
||||
return(1);
|
||||
}
|
||||
|
||||
void SaveGameVars(FILE *fil)
|
||||
|
@ -1130,11 +1128,6 @@ void SaveGameVars(FILE *fil)
|
|||
long l;
|
||||
|
||||
// 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);
|
||||
|
||||
for(i=0;i<iGameVarCount;i++)
|
||||
|
|
|
@ -4078,7 +4078,7 @@ SKIPJIBS:
|
|||
lVar3 = *insptr++;
|
||||
|
||||
SetGameVarID(lVar3, cansee(sprite[lVar1].x,sprite[lVar1].y,sprite[lVar1].z,sprite[lVar1].sectnum,
|
||||
sprite[lVar2].x,sprite[lVar2].y,sprite[lVar2].z,sprite[lVar2].sectnum), g_i, g_p);
|
||||
sprite[lVar2].x,sprite[lVar2].y,sprite[lVar2].z,sprite[lVar2].sectnum), g_i, g_p);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -258,9 +258,6 @@ short aim(spritetype *s,short aang,short atwith)
|
|||
long dx1, dy1, dx2, dy2, dx3, dy3, smax, sdist;
|
||||
long xv, yv;
|
||||
|
||||
a = s->ang;
|
||||
|
||||
j = -1;
|
||||
if(s->picnum == APLAYER) {
|
||||
if(!ps[s->yvel].auto_aim)
|
||||
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;
|
||||
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;
|
||||
|
||||
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(bv != BYTEVERSION) {
|
||||
FTA(114,&ps[myconnectindex]);
|
||||
|
@ -105,6 +110,11 @@ int loadplayer(signed char spot)
|
|||
|
||||
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(bv != BYTEVERSION)
|
||||
{
|
||||
|
@ -315,7 +325,7 @@ int loadplayer(signed char spot)
|
|||
|
||||
if (kdfread(&dynamictostatic[0],sizeof(dynamictostatic[0]),MAXTILES,fil) != MAXTILES) goto corrupt;
|
||||
|
||||
ReadGameVars(fil);
|
||||
if(ReadGameVars(fil)) goto corrupt;
|
||||
|
||||
kclose(fil);
|
||||
|
||||
|
@ -476,6 +486,11 @@ int saveplayer(signed char spot)
|
|||
|
||||
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(&ud.multimode,sizeof(ud.multimode),1,fil);
|
||||
|
||||
|
|
Loading…
Reference in a new issue