mirror of
https://github.com/yquake2/zaero.git
synced 2024-11-25 05:11:18 +00:00
game data packing representation of the headers
This commit is contained in:
parent
f3912680ac
commit
4e97fe4c74
1 changed files with 28 additions and 33 deletions
|
@ -121,6 +121,15 @@ typedef struct
|
||||||
mmove_t *mmovePtr;
|
mmove_t *mmovePtr;
|
||||||
} mmoveList_t;
|
} mmoveList_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
char ver[32];
|
||||||
|
char game[32];
|
||||||
|
char os[32];
|
||||||
|
char arch[32];
|
||||||
|
} savegameHeader_t;
|
||||||
|
|
||||||
|
|
||||||
/* ========================================================= */
|
/* ========================================================= */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -739,12 +748,9 @@ ReadClient(FILE *f, gclient_t *client, short save_ver)
|
||||||
void
|
void
|
||||||
WriteGame(const char *filename, qboolean autosave)
|
WriteGame(const char *filename, qboolean autosave)
|
||||||
{
|
{
|
||||||
|
savegameHeader_t sv;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
int i;
|
int i;
|
||||||
char str_ver[32];
|
|
||||||
char str_game[32];
|
|
||||||
char str_os[32];
|
|
||||||
char str_arch[32];
|
|
||||||
|
|
||||||
if (!autosave)
|
if (!autosave)
|
||||||
{
|
{
|
||||||
|
@ -759,20 +765,14 @@ WriteGame(const char *filename, qboolean autosave)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Savegame identification */
|
/* Savegame identification */
|
||||||
memset(str_ver, 0, sizeof(str_ver));
|
memset(&sv, 0, sizeof(sv));
|
||||||
memset(str_game, 0, sizeof(str_game));
|
|
||||||
memset(str_os, 0, sizeof(str_os));
|
|
||||||
memset(str_arch, 0, sizeof(str_arch));
|
|
||||||
|
|
||||||
strncpy(str_ver, SAVEGAMEVER, sizeof(str_ver));
|
strncpy(sv.ver, SAVEGAMEVER, sizeof(sv.ver));
|
||||||
strncpy(str_game, GAMEVERSION, sizeof(str_game));
|
strncpy(sv.game, GAMEVERSION, sizeof(sv.game));
|
||||||
strncpy(str_os, YQ2OSTYPE, sizeof(str_os) - 1);
|
strncpy(sv.os, YQ2OSTYPE, sizeof(sv.os) - 1);
|
||||||
strncpy(str_arch, YQ2ARCH, sizeof(str_arch));
|
strncpy(sv.arch, YQ2ARCH, sizeof(sv.arch));
|
||||||
|
|
||||||
fwrite(str_ver, sizeof(str_ver), 1, f);
|
fwrite(&sv, sizeof(sv), 1, f);
|
||||||
fwrite(str_game, sizeof(str_game), 1, f);
|
|
||||||
fwrite(str_os, sizeof(str_os), 1, f);
|
|
||||||
fwrite(str_arch, sizeof(str_arch), 1, f);
|
|
||||||
|
|
||||||
game.autosaved = autosave;
|
game.autosaved = autosave;
|
||||||
fwrite(&game, sizeof(game), 1, f);
|
fwrite(&game, sizeof(game), 1, f);
|
||||||
|
@ -794,12 +794,10 @@ WriteGame(const char *filename, qboolean autosave)
|
||||||
void
|
void
|
||||||
ReadGame(const char *filename)
|
ReadGame(const char *filename)
|
||||||
{
|
{
|
||||||
|
savegameHeader_t sv;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
int i;
|
int i;
|
||||||
char str_ver[32];
|
|
||||||
char str_game[32];
|
|
||||||
char str_os[32];
|
|
||||||
char str_arch[32];
|
|
||||||
short save_ver = 0;
|
short save_ver = 0;
|
||||||
|
|
||||||
gi.FreeTags(TAG_GAME);
|
gi.FreeTags(TAG_GAME);
|
||||||
|
@ -812,10 +810,7 @@ ReadGame(const char *filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sanity checks */
|
/* Sanity checks */
|
||||||
fread(str_ver, sizeof(str_ver), 1, f);
|
fread(&sv, sizeof(sv), 1, f);
|
||||||
fread(str_game, sizeof(str_game), 1, f);
|
|
||||||
fread(str_os, sizeof(str_os), 1, f);
|
|
||||||
fread(str_arch, sizeof(str_arch), 1, f);
|
|
||||||
|
|
||||||
static const struct {
|
static const struct {
|
||||||
const char* verstr;
|
const char* verstr;
|
||||||
|
@ -829,7 +824,7 @@ ReadGame(const char *filename)
|
||||||
|
|
||||||
for (i=0; i < sizeof(version_mappings)/sizeof(version_mappings[0]); ++i)
|
for (i=0; i < sizeof(version_mappings)/sizeof(version_mappings[0]); ++i)
|
||||||
{
|
{
|
||||||
if (strcmp(version_mappings[i].verstr, str_ver) == 0)
|
if (strcmp(version_mappings[i].verstr, sv.ver) == 0)
|
||||||
{
|
{
|
||||||
save_ver = version_mappings[i].vernum;
|
save_ver = version_mappings[i].vernum;
|
||||||
break;
|
break;
|
||||||
|
@ -844,12 +839,12 @@ ReadGame(const char *filename)
|
||||||
|
|
||||||
if (save_ver == 1)
|
if (save_ver == 1)
|
||||||
{
|
{
|
||||||
if (strcmp(str_game, GAMEVERSION) != 0)
|
if (strcmp(sv.game, GAMEVERSION) != 0)
|
||||||
{
|
{
|
||||||
fclose(f);
|
fclose(f);
|
||||||
gi.error("Savegame from another game.so.\n");
|
gi.error("Savegame from another game.so.\n");
|
||||||
}
|
}
|
||||||
else if (strcmp(str_os, OSTYPE_1) != 0)
|
else if (strcmp(sv.os, OSTYPE_1) != 0)
|
||||||
{
|
{
|
||||||
fclose(f);
|
fclose(f);
|
||||||
gi.error("Savegame from another os.\n");
|
gi.error("Savegame from another os.\n");
|
||||||
|
@ -857,13 +852,13 @@ ReadGame(const char *filename)
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
/* Windows was forced to i386 */
|
/* Windows was forced to i386 */
|
||||||
if (strcmp(str_arch, "i386") != 0)
|
if (strcmp(sv.arch, "i386") != 0)
|
||||||
{
|
{
|
||||||
fclose(f);
|
fclose(f);
|
||||||
gi.error("Savegame from another architecture.\n");
|
gi.error("Savegame from another architecture.\n");
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (strcmp(str_arch, ARCH_1) != 0)
|
if (strcmp(sv.arch, ARCH_1) != 0)
|
||||||
{
|
{
|
||||||
fclose(f);
|
fclose(f);
|
||||||
gi.error("Savegame from another architecture.\n");
|
gi.error("Savegame from another architecture.\n");
|
||||||
|
@ -872,24 +867,24 @@ ReadGame(const char *filename)
|
||||||
}
|
}
|
||||||
else // all newer savegame versions
|
else // all newer savegame versions
|
||||||
{
|
{
|
||||||
if (strcmp(str_game, GAMEVERSION) != 0)
|
if (strcmp(sv.game, GAMEVERSION) != 0)
|
||||||
{
|
{
|
||||||
fclose(f);
|
fclose(f);
|
||||||
gi.error("Savegame from another game.so.\n");
|
gi.error("Savegame from another game.so.\n");
|
||||||
}
|
}
|
||||||
else if (strcmp(str_os, YQ2OSTYPE) != 0)
|
else if (strcmp(sv.os, YQ2OSTYPE) != 0)
|
||||||
{
|
{
|
||||||
fclose(f);
|
fclose(f);
|
||||||
gi.error("Savegame from another os.\n");
|
gi.error("Savegame from another os.\n");
|
||||||
}
|
}
|
||||||
else if (strcmp(str_arch, YQ2ARCH) != 0)
|
else if (strcmp(sv.arch, YQ2ARCH) != 0)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32) && (defined(__i386__) || defined(_M_IX86))
|
#if defined(_WIN32) && (defined(__i386__) || defined(_M_IX86))
|
||||||
// before savegame version "YQ2-4" (and after version 1),
|
// before savegame version "YQ2-4" (and after version 1),
|
||||||
// the official Win32 binaries accidentally had the YQ2ARCH "AMD64"
|
// the official Win32 binaries accidentally had the YQ2ARCH "AMD64"
|
||||||
// instead of "i386" set due to a bug in the Makefile.
|
// instead of "i386" set due to a bug in the Makefile.
|
||||||
// This quirk allows loading those savegames anyway
|
// This quirk allows loading those savegames anyway
|
||||||
if (save_ver >= 4 || strcmp(str_arch, "AMD64") != 0)
|
if (save_ver >= 4 || strcmp(sv.arch, "AMD64") != 0)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
Loading…
Reference in a new issue