projects
/
open-adventure.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
4b08b72
)
Resume now detects if a save has incompatible endianness.
author
Eric S. Raymond
<esr@thyrsus.com>
Thu, 6 Apr 2023 23:35:56 +0000
(19:35 -0400)
committer
Eric S. Raymond
<esr@thyrsus.com>
Thu, 6 Apr 2023 23:41:22 +0000
(19:41 -0400)
NEWS.adoc
patch
|
blob
|
history
saveresume.c
patch
|
blob
|
history
diff --git
a/NEWS.adoc
b/NEWS.adoc
index f01d4f30f32a796815e09abe30bcd38d4bbb0490..da58c799e98161d0a38a731be4ec25530e668c3f 100644
(file)
--- a/
NEWS.adoc
+++ b/
NEWS.adoc
@@
-2,6
+2,10
@@
// SPDX-FileCopyrightText: Eric S. Raymond <esr@thyrsus.com>
// SPDX-License-Identifier: CC-BY-4.0
// SPDX-FileCopyrightText: Eric S. Raymond <esr@thyrsus.com>
// 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::
Commands in magic-word sequence now interrupt it, as in original.
Bug fix for bird not starting caged in endgame.
1.15: 2023-04-03::
Commands in magic-word sequence now interrupt it, as in original.
Bug fix for bird not starting caged in endgame.
diff --git
a/saveresume.c
b/saveresume.c
index 0b71319c0dc835368eb95f0df39d1dc6e8f5d292..c6d0ba0f274d3e73271e92b171a95521caf96694 100644
(file)
--- a/
saveresume.c
+++ b/
saveresume.c
@@
-18,6
+18,11
@@
#include "advent.h"
#include "dungeon.h"
#include "advent.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;
#define IGNORE(r) do{if (r){}}while(0)
struct save_t save;
#define IGNORE(r) do{if (r){}}while(0)
@@
-28,6
+33,8
@@
int savefile(FILE *fp)
memcpy(&save.magic, ADVENT_MAGIC, sizeof(ADVENT_MAGIC));
if (save.version == 0)
save.version = SAVE_VERSION;
memcpy(&save.magic, ADVENT_MAGIC, sizeof(ADVENT_MAGIC));
if (save.version == 0)
save.version = SAVE_VERSION;
+ if (save.canary == 0)
+ save.canary = ENDIAN_MAGIC;
save.game = game;
IGNORE(fwrite(&save, sizeof(struct save_t), 1, fp));
save.game = game;
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));
fclose(fp);
IGNORE(fread(&save, sizeof(struct save_t), 1, 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);
else if (save.version != SAVE_VERSION) {
rspeak(VERSION_SKEW, save.version / 10, MOD(save.version, 10), SAVE_VERSION / 10, MOD(SAVE_VERSION, 10));
rspeak(BAD_SAVE);
else if (save.version != SAVE_VERSION) {
rspeak(VERSION_SKEW, save.version / 10, MOD(save.version, 10), SAVE_VERSION / 10, MOD(SAVE_VERSION, 10));