Resume now detects if a save has incompatible endianness.
This commit is contained in:
parent
4b08b726f9
commit
520d365f74
2 changed files with 12 additions and 1 deletions
|
@ -2,6 +2,10 @@
|
||||||
// SPDX-FileCopyrightText: Eric S. Raymond <esr@thyrsus.com>
|
// SPDX-FileCopyrightText: Eric S. Raymond <esr@thyrsus.com>
|
||||||
// SPDX-License-Identifier: CC-BY-4.0
|
// SPDX-License-Identifier: CC-BY-4.0
|
||||||
|
|
||||||
|
Reoisitory head::
|
||||||
|
Savefiles now have an identigting magic cookie at the front.
|
||||||
|
Resume detects if a save has incompatible endianness.
|
||||||
|
|
||||||
1.15: 2023-04-03::
|
1.15: 2023-04-03::
|
||||||
Commands in magic-word sequence now interrupt it, as in original.
|
Commands in magic-word sequence now interrupt it, as in original.
|
||||||
Bug fix for bird not starting caged in endgame.
|
Bug fix for bird not starting caged in endgame.
|
||||||
|
|
|
@ -18,6 +18,11 @@
|
||||||
#include "advent.h"
|
#include "advent.h"
|
||||||
#include "dungeon.h"
|
#include "dungeon.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Use this to detect endianness mismatch. Can't be unchanges by byte-swapping.
|
||||||
|
*/
|
||||||
|
#define ENDIAN_MAGIC 2317
|
||||||
|
|
||||||
struct save_t save;
|
struct save_t save;
|
||||||
|
|
||||||
#define IGNORE(r) do{if (r){}}while(0)
|
#define IGNORE(r) do{if (r){}}while(0)
|
||||||
|
@ -28,6 +33,8 @@ int savefile(FILE *fp)
|
||||||
memcpy(&save.magic, ADVENT_MAGIC, sizeof(ADVENT_MAGIC));
|
memcpy(&save.magic, ADVENT_MAGIC, sizeof(ADVENT_MAGIC));
|
||||||
if (save.version == 0)
|
if (save.version == 0)
|
||||||
save.version = SAVE_VERSION;
|
save.version = SAVE_VERSION;
|
||||||
|
if (save.canary == 0)
|
||||||
|
save.canary = ENDIAN_MAGIC;
|
||||||
|
|
||||||
save.game = game;
|
save.game = game;
|
||||||
IGNORE(fwrite(&save, sizeof(struct save_t), 1, fp));
|
IGNORE(fwrite(&save, sizeof(struct save_t), 1, fp));
|
||||||
|
@ -136,7 +143,7 @@ int restore(FILE* fp)
|
||||||
|
|
||||||
IGNORE(fread(&save, sizeof(struct save_t), 1, fp));
|
IGNORE(fread(&save, sizeof(struct save_t), 1, fp));
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
if (memcmp(save.magic, ADVENT_MAGIC, sizeof(ADVENT_MAGIC)) != 0)
|
if (memcmp(save.magic, ADVENT_MAGIC, sizeof(ADVENT_MAGIC)) != 0 || save.canary != ENDIAN_MAGIC)
|
||||||
rspeak(BAD_SAVE);
|
rspeak(BAD_SAVE);
|
||||||
else if (save.version != SAVE_VERSION) {
|
else if (save.version != SAVE_VERSION) {
|
||||||
rspeak(VERSION_SKEW, save.version / 10, MOD(save.version, 10), SAVE_VERSION / 10, MOD(SAVE_VERSION, 10));
|
rspeak(VERSION_SKEW, save.version / 10, MOD(save.version, 10), SAVE_VERSION / 10, MOD(SAVE_VERSION, 10));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue