From 551df9d933a3f8d4c7dd633f62671433dc70cc1d Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Tue, 24 Sep 2013 20:52:59 +0000 Subject: Add portable functions to read integers from savegame files and use these instead of reading directly from memory buffers. Subversion-branch: /branches/v2-branch Subversion-revision: 2682 --- src/heretic/g_game.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'src/heretic/g_game.c') diff --git a/src/heretic/g_game.c b/src/heretic/g_game.c index 85e57ca9..e9302e83 100644 --- a/src/heretic/g_game.c +++ b/src/heretic/g_game.c @@ -126,9 +126,7 @@ boolean precache = true; // if true, load all graphics at start // TODO: Heretic uses 16-bit shorts for consistency? byte consistancy[MAXPLAYERS][BACKUPTICS]; - char *savegamedir; -byte *savebuffer, *save_p; boolean testcontrols = false; int testcontrols_mousespeed; @@ -1413,39 +1411,41 @@ void G_DoLoadGame(void) { int i; int a, b, c; - char vcheck[VERSIONSIZE]; + char savestr[SAVESTRINGSIZE]; + char vcheck[VERSIONSIZE], readversion[VERSIONSIZE]; gameaction = ga_nothing; - M_ReadFile(savename, &savebuffer); + SV_OpenRead(savename); + free(savename); savename = NULL; - save_p = savebuffer + SAVESTRINGSIZE; // Skip the description field - memset(vcheck, 0, sizeof(vcheck)); + SV_Read(savestr, SAVESTRINGSIZE); + memset(vcheck, 0, sizeof(vcheck)); DEH_snprintf(vcheck, VERSIONSIZE, "version %i", HERETIC_VERSION); + SV_Read(readversion, VERSIONSIZE); - if (strcmp((char *) save_p, vcheck) != 0) + if (strncmp(readversion, vcheck, VERSIONSIZE) != 0) { // Bad version return; } - save_p += VERSIONSIZE; - gameskill = *save_p++; - gameepisode = *save_p++; - gamemap = *save_p++; + gameskill = SV_ReadByte(); + gameepisode = SV_ReadByte(); + gamemap = SV_ReadByte(); for (i = 0; i < MAXPLAYERS; i++) { - playeringame[i] = *save_p++; + playeringame[i] = SV_ReadByte(); } // Load a base level G_InitNew(gameskill, gameepisode, gamemap); // Create leveltime - a = *save_p++; - b = *save_p++; - c = *save_p++; + a = SV_ReadByte(); + b = SV_ReadByte(); + c = SV_ReadByte(); leveltime = (a << 16) + (b << 8) + c; // De-archive all the modifications @@ -1454,11 +1454,10 @@ void G_DoLoadGame(void) P_UnArchiveThinkers(); P_UnArchiveSpecials(); - if (*save_p != SAVE_GAME_TERMINATOR) + if (SV_ReadByte() != SAVE_GAME_TERMINATOR) { // Missing savegame termination marker I_Error("Bad savegame"); } - Z_Free(savebuffer); } -- cgit v1.2.3