summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/g_game.c53
-rw-r--r--src/m_misc.c25
-rw-r--r--src/p_saveg.c154
-rw-r--r--src/p_saveg.h11
4 files changed, 155 insertions, 88 deletions
diff --git a/src/g_game.c b/src/g_game.c
index f7265a72..004e555f 100644
--- a/src/g_game.c
+++ b/src/g_game.c
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: g_game.c 351 2006-01-27 18:23:08Z fraggle $
+// $Id: g_game.c 367 2006-02-15 12:57:58Z fraggle $
//
// Copyright(C) 1993-1996 Id Software, Inc.
// Copyright(C) 2005 Simon Howard
@@ -22,6 +22,11 @@
// 02111-1307, USA.
//
// $Log$
+// Revision 1.24 2006/02/15 12:57:58 fraggle
+// Remove the savegame buffer entirely. Keep the old savegame size limit
+// bug add a "vanilla_savegame_limit" config file option which allows
+// the limit to be disabled if necessary.
+//
// Revision 1.23 2006/01/27 18:23:08 fraggle
// Exit with an error when playing a demo with the wrong version, like Vanilla Doom
//
@@ -114,7 +119,7 @@
static const char
-rcsid[] = "$Id: g_game.c 351 2006-01-27 18:23:08Z fraggle $";
+rcsid[] = "$Id: g_game.c 367 2006-02-15 12:57:58Z fraggle $";
#include <string.h>
#include <stdlib.h>
@@ -234,8 +239,6 @@ wbstartstruct_t wminfo; // parms for world map / intermission
short consistancy[MAXPLAYERS][BACKUPTICS];
-byte* savebuffer;
-
//
// Controls
@@ -313,6 +316,7 @@ char savedescription[32];
mobj_t* bodyque[BODYQUESIZE];
int bodyqueslot;
+int vanilla_savegame_limit = 1;
int G_CmdChecksum (ticcmd_t* cmd)
@@ -1337,17 +1341,20 @@ void G_LoadGame (char* name)
void G_DoLoadGame (void)
{
- int length;
int savedleveltime;
gameaction = ga_nothing;
- length = M_ReadFile (savename, &savebuffer);
- save_p = savebuffer;
+ save_stream = fopen(savename, "rb");
+
+ if (save_stream == NULL)
+ {
+ return;
+ }
if (!P_ReadSaveGameHeader())
{
- Z_Free(savebuffer);
+ fclose(save_stream);
return;
}
@@ -1366,10 +1373,9 @@ void G_DoLoadGame (void)
if (!P_ReadSaveGameEOF())
I_Error ("Bad savegame");
+
+ fclose(save_stream);
- // done
- Z_Free (savebuffer);
-
if (setsizeneeded)
R_ExecuteSetViewSize ();
@@ -1397,14 +1403,19 @@ void G_DoSaveGame (void)
{
char name[100];
char* description;
- int length;
+ unsigned long length;
strcpy(name, P_SaveGameFile(savegameslot));
description = savedescription;
- save_p = savebuffer = screens[1]+0x4000;
-
+ save_stream = fopen(name, "wb");
+
+ if (save_stream == NULL)
+ {
+ return;
+ }
+
P_WriteSaveGameHeader(description);
P_ArchivePlayers ();
@@ -1414,10 +1425,16 @@ void G_DoSaveGame (void)
P_WriteSaveGameEOF();
- length = save_p - savebuffer;
- if (length > SAVEGAMESIZE)
- I_Error ("Savegame buffer overrun");
- M_WriteFile (name, savebuffer, length);
+ // Enforce the same savegame size limit as in Vanilla Doom,
+ // except if the vanilla_savegame_limit setting is turned off.
+
+ if (vanilla_savegame_limit && ftell(save_stream) > SAVEGAMESIZE)
+ {
+ I_Error ("Savegame buffer overrun");
+ }
+
+ fclose(save_stream);
+
gameaction = ga_nothing;
strcpy(savedescription, "");
diff --git a/src/m_misc.c b/src/m_misc.c
index 4caf5659..7345f819 100644
--- a/src/m_misc.c
+++ b/src/m_misc.c
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: m_misc.c 309 2006-01-20 21:04:59Z fraggle $
+// $Id: m_misc.c 367 2006-02-15 12:57:58Z fraggle $
//
// Copyright(C) 1993-1996 Id Software, Inc.
// Copyright(C) 2005 Simon Howard
@@ -23,6 +23,11 @@
//
//
// $Log$
+// Revision 1.19 2006/02/15 12:57:58 fraggle
+// Remove the savegame buffer entirely. Keep the old savegame size limit
+// bug add a "vanilla_savegame_limit" config file option which allows
+// the limit to be disabled if necessary.
+//
// Revision 1.18 2006/01/20 21:04:59 fraggle
// Import differences from stable branch.
//
@@ -101,7 +106,7 @@
//-----------------------------------------------------------------------------
static const char
-rcsid[] = "$Id: m_misc.c 309 2006-01-20 21:04:59Z fraggle $";
+rcsid[] = "$Id: m_misc.c 367 2006-02-15 12:57:58Z fraggle $";
#include <stdio.h>
#include <stdlib.h>
@@ -289,6 +294,7 @@ extern int numChannels;
extern char* chat_macros[];
extern int show_endoom;
+extern int vanilla_savegame_limit;
// dos specific options: these are unused but should be maintained
// so that the config file can be shared between chocolate
@@ -388,13 +394,14 @@ static default_collection_t doom_defaults =
static default_t extra_defaults_list[] =
{
- {"grabmouse", &grabmouse},
- {"fullscreen", &fullscreen},
- {"screenmultiply", &screenmultiply},
- {"novert", &novert},
- {"mouse_acceleration", &mouse_acceleration, DEFAULT_FLOAT},
- {"show_endoom", &show_endoom},
- {"player_name", &net_player_name, DEFAULT_STRING},
+ {"grabmouse", &grabmouse},
+ {"fullscreen", &fullscreen},
+ {"screenmultiply", &screenmultiply},
+ {"novert", &novert},
+ {"mouse_acceleration", &mouse_acceleration, DEFAULT_FLOAT},
+ {"show_endoom", &show_endoom},
+ {"vanilla_savegame_limit", &vanilla_savegame_limit},
+ {"player_name", &net_player_name, DEFAULT_STRING},
};
static default_collection_t extra_defaults =
diff --git a/src/p_saveg.c b/src/p_saveg.c
index fbec93a0..558d7d8c 100644
--- a/src/p_saveg.c
+++ b/src/p_saveg.c
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: p_saveg.c 300 2006-01-19 18:46:24Z fraggle $
+// $Id: p_saveg.c 367 2006-02-15 12:57:58Z fraggle $
//
// Copyright(C) 1993-1996 Id Software, Inc.
// Copyright(C) 2005 Simon Howard
@@ -22,6 +22,11 @@
// 02111-1307, USA.
//
// $Log$
+// Revision 1.8 2006/02/15 12:57:58 fraggle
+// Remove the savegame buffer entirely. Keep the old savegame size limit
+// bug add a "vanilla_savegame_limit" config file option which allows
+// the limit to be disabled if necessary.
+//
// Revision 1.7 2006/01/19 18:46:24 fraggle
// Move savegame header read/write code into p_saveg.c
//
@@ -55,7 +60,9 @@
//-----------------------------------------------------------------------------
static const char
-rcsid[] = "$Id: p_saveg.c 300 2006-01-19 18:46:24Z fraggle $";
+rcsid[] = "$Id: p_saveg.c 367 2006-02-15 12:57:58Z fraggle $";
+
+#include <stdio.h>
#include "dstrings.h"
#include "deh_main.h"
@@ -71,13 +78,8 @@ rcsid[] = "$Id: p_saveg.c 300 2006-01-19 18:46:24Z fraggle $";
#define SAVEGAME_EOF 0x1d
#define VERSIONSIZE 16
-byte* save_p;
-
-
-// Pads save_p to a 4-byte boundary
-// so that the load/save works on SGI&Gecko.
-#define PADSAVEP() save_p += (4 - ((int) save_p & 3)) & 3
-
+FILE *save_stream;
+int savegamelength;
char *P_SaveGameFile(int slot)
{
@@ -95,63 +97,89 @@ char *P_SaveGameFile(int slot)
static byte saveg_read8(void)
{
- int result;
-
- result = *save_p;
+ byte result;
- save_p += 1;
+ fread(&result, 1, 1, save_stream);
return result;
}
static void saveg_write8(byte value)
{
- *save_p = value;
-
- save_p += 1;
+ fwrite(&value, 1, 1, save_stream);
}
static short saveg_read16(void)
{
int result;
- result = save_p[0] | (save_p[1] << 8);
-
- save_p += 2;
+ result = saveg_read8();
+ result |= saveg_read8() << 8;
return result;
}
static void saveg_write16(short value)
{
- save_p[0] = value & 0xff;
- save_p[1] = (value >> 8) & 0xff;
-
- save_p += 2;
+ saveg_write8(value & 0xff);
+ saveg_write8((value >> 8) & 0xff);
}
static int saveg_read32(void)
{
int result;
- result = save_p[0] | (save_p[1] << 8)
- | (save_p[2] << 16) | (save_p[3] << 24);
-
- save_p += 4;
+ result = saveg_read8();
+ result |= saveg_read8() << 8;
+ result |= saveg_read8() << 16;
+ result |= saveg_read8() << 24;
return result;
}
static void saveg_write32(int value)
{
- save_p[0] = value & 0xff;
- save_p[1] = (value >> 8) & 0xff;
- save_p[2] = (value >> 16) & 0xff;
- save_p[3] = (value >> 24) & 0xff;
+ saveg_write8(value & 0xff);
+ saveg_write8((value >> 8) & 0xff);
+ saveg_write8((value >> 16) & 0xff);
+ saveg_write8((value >> 24) & 0xff);
+}
+
+// Pad to 4-byte boundaries
+
+static void saveg_read_pad(void)
+{
+ unsigned long pos;
+ int padding;
+ int i;
+
+ pos = ftell(save_stream);
+
+ padding = (4 - (pos & 3)) & 3;
- save_p += 4;
+ for (i=0; i<padding; ++i)
+ {
+ saveg_read8();
+ }
}
+static void saveg_write_pad(void)
+{
+ unsigned long pos;
+ int padding;
+ int i;
+
+ pos = ftell(save_stream);
+
+ padding = (4 - (pos & 3)) & 3;
+
+ for (i=0; i<padding; ++i)
+ {
+ saveg_write8(0);
+ }
+}
+
+
// Pointers
static void *saveg_readp(void)
@@ -1321,13 +1349,16 @@ void P_WriteSaveGameHeader(char *description)
char name[VERSIONSIZE];
int i;
- memcpy (save_p, description, SAVESTRINGSIZE);
- save_p += SAVESTRINGSIZE;
+ for (i=0; description[i] != '\0'; ++i)
+ saveg_write8(description[i]);
+ for (; i<SAVESTRINGSIZE; ++i)
+ saveg_write8(0);
memset (name,0,sizeof(name));
sprintf (name,"version %i",DOOM_VERSION);
- memcpy (save_p, name, VERSIONSIZE);
- save_p += VERSIONSIZE;
+
+ for (i=0; i<VERSIONSIZE; ++i)
+ saveg_write8(name[i]);
saveg_write8(gameskill);
saveg_write8(gameepisode);
@@ -1350,15 +1381,20 @@ boolean P_ReadSaveGameHeader(void)
int i;
byte a, b, c;
char vcheck[VERSIONSIZE];
+ char read_vcheck[VERSIONSIZE];
- save_p += SAVESTRINGSIZE;
-
// skip the description field
+
+ for (i=0; i<SAVESTRINGSIZE; ++i)
+ saveg_read8();
+
+ for (i=0; i<VERSIONSIZE; ++i)
+ read_vcheck[i] = saveg_read8();
+
memset (vcheck,0,sizeof(vcheck));
sprintf (vcheck,"version %i",DOOM_VERSION);
- if (strcmp ((char *) save_p, vcheck))
+ if (strcmp(read_vcheck, vcheck) != 0)
return false; // bad version
- save_p += VERSIONSIZE;
gameskill = saveg_read8();
gameepisode = saveg_read8();
@@ -1410,7 +1446,7 @@ void P_ArchivePlayers (void)
if (!playeringame[i])
continue;
- PADSAVEP();
+ saveg_write_pad();
saveg_write_player_t(&players[i]);
}
@@ -1430,7 +1466,7 @@ void P_UnArchivePlayers (void)
if (!playeringame[i])
continue;
- PADSAVEP();
+ saveg_read_pad();
saveg_read_player_t(&players[i]);
@@ -1563,7 +1599,7 @@ void P_ArchiveThinkers (void)
if (th->function.acp1 == (actionf_p1)P_MobjThinker)
{
saveg_write8(tc_mobj);
- PADSAVEP();
+ saveg_write_pad();
saveg_write_mobj_t((mobj_t *) th);
continue;
@@ -1613,7 +1649,7 @@ void P_UnArchiveThinkers (void)
return; // end of list
case tc_mobj:
- PADSAVEP();
+ saveg_read_pad();
mobj = Z_Malloc (sizeof(*mobj), PU_LEVEL, NULL);
saveg_read_mobj_t(mobj);
@@ -1681,7 +1717,7 @@ void P_ArchiveSpecials (void)
if (i<MAXCEILINGS)
{
saveg_write8(tc_ceiling);
- PADSAVEP();
+ saveg_write_pad();
saveg_write_ceiling_t((ceiling_t *) th);
}
continue;
@@ -1690,7 +1726,7 @@ void P_ArchiveSpecials (void)
if (th->function.acp1 == (actionf_p1)T_MoveCeiling)
{
saveg_write8(tc_ceiling);
- PADSAVEP();
+ saveg_write_pad();
saveg_write_ceiling_t((ceiling_t *) th);
continue;
}
@@ -1698,7 +1734,7 @@ void P_ArchiveSpecials (void)
if (th->function.acp1 == (actionf_p1)T_VerticalDoor)
{
saveg_write8(tc_door);
- PADSAVEP();
+ saveg_write_pad();
saveg_write_vldoor_t((vldoor_t *) th);
continue;
}
@@ -1706,7 +1742,7 @@ void P_ArchiveSpecials (void)
if (th->function.acp1 == (actionf_p1)T_MoveFloor)
{
saveg_write8(tc_floor);
- PADSAVEP();
+ saveg_write_pad();
saveg_write_floormove_t((floormove_t *) th);
continue;
}
@@ -1714,7 +1750,7 @@ void P_ArchiveSpecials (void)
if (th->function.acp1 == (actionf_p1)T_PlatRaise)
{
saveg_write8(tc_plat);
- PADSAVEP();
+ saveg_write_pad();
saveg_write_plat_t((plat_t *) th);
continue;
}
@@ -1722,7 +1758,7 @@ void P_ArchiveSpecials (void)
if (th->function.acp1 == (actionf_p1)T_LightFlash)
{
saveg_write8(tc_flash);
- PADSAVEP();
+ saveg_write_pad();
saveg_write_lightflash_t((lightflash_t *) th);
continue;
}
@@ -1730,7 +1766,7 @@ void P_ArchiveSpecials (void)
if (th->function.acp1 == (actionf_p1)T_StrobeFlash)
{
saveg_write8(tc_strobe);
- PADSAVEP();
+ saveg_write_pad();
saveg_write_strobe_t((strobe_t *) th);
continue;
}
@@ -1738,7 +1774,7 @@ void P_ArchiveSpecials (void)
if (th->function.acp1 == (actionf_p1)T_Glow)
{
saveg_write8(tc_glow);
- PADSAVEP();
+ saveg_write_pad();
saveg_write_glow_t((glow_t *) th);
continue;
}
@@ -1776,7 +1812,7 @@ void P_UnArchiveSpecials (void)
return; // end of list
case tc_ceiling:
- PADSAVEP();
+ saveg_read_pad();
ceiling = Z_Malloc (sizeof(*ceiling), PU_LEVEL, NULL);
saveg_read_ceiling_t(ceiling);
ceiling->sector->specialdata = ceiling;
@@ -1789,7 +1825,7 @@ void P_UnArchiveSpecials (void)
break;
case tc_door:
- PADSAVEP();
+ saveg_read_pad();
door = Z_Malloc (sizeof(*door), PU_LEVEL, NULL);
saveg_read_vldoor_t(door);
door->sector->specialdata = door;
@@ -1798,7 +1834,7 @@ void P_UnArchiveSpecials (void)
break;
case tc_floor:
- PADSAVEP();
+ saveg_read_pad();
floor = Z_Malloc (sizeof(*floor), PU_LEVEL, NULL);
saveg_read_floormove_t(floor);
floor->sector->specialdata = floor;
@@ -1807,7 +1843,7 @@ void P_UnArchiveSpecials (void)
break;
case tc_plat:
- PADSAVEP();
+ saveg_read_pad();
plat = Z_Malloc (sizeof(*plat), PU_LEVEL, NULL);
saveg_read_plat_t(plat);
plat->sector->specialdata = plat;
@@ -1820,7 +1856,7 @@ void P_UnArchiveSpecials (void)
break;
case tc_flash:
- PADSAVEP();
+ saveg_read_pad();
flash = Z_Malloc (sizeof(*flash), PU_LEVEL, NULL);
saveg_read_lightflash_t(flash);
flash->thinker.function.acp1 = (actionf_p1)T_LightFlash;
@@ -1828,7 +1864,7 @@ void P_UnArchiveSpecials (void)
break;
case tc_strobe:
- PADSAVEP();
+ saveg_read_pad();
strobe = Z_Malloc (sizeof(*strobe), PU_LEVEL, NULL);
saveg_read_strobe_t(strobe);
strobe->thinker.function.acp1 = (actionf_p1)T_StrobeFlash;
@@ -1836,7 +1872,7 @@ void P_UnArchiveSpecials (void)
break;
case tc_glow:
- PADSAVEP();
+ saveg_read_pad();
glow = Z_Malloc (sizeof(*glow), PU_LEVEL, NULL);
saveg_read_glow_t(glow);
glow->thinker.function.acp1 = (actionf_p1)T_Glow;
diff --git a/src/p_saveg.h b/src/p_saveg.h
index 3217e9d3..4176f20a 100644
--- a/src/p_saveg.h
+++ b/src/p_saveg.h
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: p_saveg.h 300 2006-01-19 18:46:24Z fraggle $
+// $Id: p_saveg.h 367 2006-02-15 12:57:58Z fraggle $
//
// Copyright(C) 1993-1996 Id Software, Inc.
// Copyright(C) 2005 Simon Howard
@@ -30,6 +30,8 @@
#ifndef __P_SAVEG__
#define __P_SAVEG__
+#include <stdio.h>
+
// maximum size of a savegame description
#define SAVESTRINGSIZE 24
@@ -59,13 +61,18 @@ void P_UnArchiveThinkers (void);
void P_ArchiveSpecials (void);
void P_UnArchiveSpecials (void);
-extern byte* save_p;
+extern FILE *save_stream;
#endif
//-----------------------------------------------------------------------------
//
// $Log$
+// Revision 1.6 2006/02/15 12:57:58 fraggle
+// Remove the savegame buffer entirely. Keep the old savegame size limit
+// bug add a "vanilla_savegame_limit" config file option which allows
+// the limit to be disabled if necessary.
+//
// Revision 1.5 2006/01/19 18:46:24 fraggle
// Move savegame header read/write code into p_saveg.c
//