Skip to content

Free games for graphing calculators: NumWorks, TI-Nspire CX, Casio fx-CG50 and soon TI-84 Plus CE. Balatro, Celeste, Hollow Knight, Minecraft and more.

Saves: one line on top of each copy instead of three

Mason363f7bad5d19731
diff --git a/games/angrybirds/src/save.c b/games/angrybirds/src/save.c
index ffa1d81b..faa10a65 100644
--- a/games/angrybirds/src/save.c
+++ b/games/angrybirds/src/save.c
@@ -28,8 +28,7 @@ bool save_ok(const SaveFile *f) {
return true;
}
-static const char head[] = "# Angry Birds keeps a copy of your progress here,\n"
- "# so that installing it again doesn't erase it.\n";
+static const char head[] = "# Angry Birds' saves: keep this file\n";
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
#define COPY_BYTES (1 + sizeof head + 2 + sizeof AB_SAVE_NAME + 1 + (sizeof(SaveFile) + 2) / 3 * 4 + 2)
diff --git a/games/badtime/src/save.c b/games/badtime/src/save.c
index 4a727ac6..9e621b40 100644
--- a/games/badtime/src/save.c
+++ b/games/badtime/src/save.c
@@ -22,8 +22,7 @@ bool bt_file_ok(const bt_file *f) {
return p->best <= 24 && p->guide <= 1;
}
-static const char head[] = "# Bad Time Simulator keeps a copy of your record here,\n"
- "# so that installing it again doesn't erase it.\n";
+static const char head[] = "# Bad Time Simulator's saves: keep this file\n";
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static uint8_t copy[1 + sizeof head + 2 + sizeof BT_SAVE_NAME + 1 + (sizeof(bt_file) + 2) / 3 * 4 + 2];
diff --git a/games/celeste/src/save.c b/games/celeste/src/save.c
index b7e68ca0..4218cee0 100644
--- a/games/celeste/src/save.c
+++ b/games/celeste/src/save.c
@@ -59,10 +59,7 @@ void save_keep_binds(void) { /* g_bind into the save (written with the next sa
* also kept in one, as a comment line "#>celeste.sav:base64" (the way NumPlay keeps its games'
* saves), and comes back from it when the save itself is gone. */
#define COPY_NAME "celeste_saves.py"
-static const char copy_head[] =
- "# Celeste keeps a copy of your progress here, so that\n"
- "# reinstalling it doesn't erase it. If you delete this file,\n"
- "# Celeste writes it again: your progress stays either way.\n";
+static const char copy_head[] = "# Celeste's saves: keep this file\n";
static const char tag[] = "#>" SAVE_NAME ":";
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static void save_copy(void) {
diff --git a/games/championisland/src/store.c b/games/championisland/src/store.c
index b5fb54e1..efed0a2e 100644
--- a/games/championisland/src/store.c
+++ b/games/championisland/src/store.c
@@ -114,10 +114,7 @@ bool store_dirty(void) { return dirty; }
* "#>champion.sav:base64" (the way NumPlay keeps its games' saves), and
* comes back from it when the save itself is gone. */
#define COPY_NAME "champion_saves.py"
-static const char copy_head[] =
- "# Champion Island keeps a copy of your progress here, so that\n"
- "# reinstalling it doesn't erase it. If you delete this file,\n"
- "# Champion Island writes it again: your progress stays either way.\n";
+static const char copy_head[] = "# Champion Island's saves: keep this file\n";
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static void save_copy(const uint8_t *d, uint32_t n, uint8_t *o, uint32_t cap) {
diff --git a/games/cookieclicker/src/save.c b/games/cookieclicker/src/save.c
index baf2cae7..f3cd9d77 100644
--- a/games/cookieclicker/src/save.c
+++ b/games/cookieclicker/src/save.c
@@ -9,13 +9,9 @@
#define COPY_NAME "cookieclicker_saves.py"
#define MAGIC 0x314B4343u /* "CCK1" */
-/* (the line is about 4000 characters: the Python editor doesn't draw a line that long, so the script looks empty
- * there, and the head says so) */
-static const char copy_head[] =
- "# Cookie Clicker's save: the long line below is a copy of\n"
- "# your bakery. It is too long for the editor to show, so\n"
- "# the script looks empty there. Installing the game again\n"
- "# brings your bakery back from it.\n";
+/* (the line is about 4000 characters: the Python editor doesn't draw a line that long, so the head is all the
+ * script shows there) */
+static const char copy_head[] = "# Cookie Clicker's saves: keep this file\n";
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static void copy_write(void) {
diff --git a/games/donkeykong/src/save.c b/games/donkeykong/src/save.c
index 4d87f98f..e7eafdd6 100644
--- a/games/donkeykong/src/save.c
+++ b/games/donkeykong/src/save.c
@@ -93,8 +93,7 @@ bool dk_file_ok(const uint8_t *d, uint32_t n, dk_profile *p, dk_state *s) {
return true;
}
-static const char head[] = "# Donkey Kong keeps a copy of your best score and of a game\n"
- "# left with Home here, so that installing it again keeps them.\n";
+static const char head[] = "# Donkey Kong's saves: keep this file\n";
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static uint8_t copy[1 + sizeof head + 2 + sizeof DK_SAVE_NAME + 1 + (DK_SAVE_MAX + 2) / 3 * 4 + 2];
diff --git a/games/doom/src/nw/saves.c b/games/doom/src/nw/saves.c
index 972f3911..b29b156d 100644
--- a/games/doom/src/nw/saves.c
+++ b/games/doom/src/nw/saves.c
@@ -26,10 +26,7 @@ static const char *const kept[NW_SLOTS + 1] = {
"doomres.sav", CFG_NAME
};
#define NKEPT (int)(sizeof kept / sizeof kept[0])
-static const char copy_head[] =
- "# Doom keeps a copy of your saved games here, so that\n"
- "# reinstalling it doesn't erase them. If you delete this file,\n"
- "# the game writes it again: your saves stay either way.\n";
+static const char copy_head[] = "# Doom's saves: keep this file\n";
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static void copy_write(void) {
diff --git a/games/dune/src/save.c b/games/dune/src/save.c
index 84c7bac5..c461172b 100644
--- a/games/dune/src/save.c
+++ b/games/dune/src/save.c
@@ -30,8 +30,7 @@ bool dn_file_ok(const dn_file *f, dn_run *scratch) {
return dn_valid(scratch) && scratch->ball == p->ball && scratch->land == p->land;
}
-static const char head[] = "# Dune keeps a copy of your best, your coins and what you bought\n"
- "# here, so that installing it again doesn't erase them.\n";
+static const char head[] = "# Dune's saves: keep this file\n";
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static uint8_t copy[1 + sizeof head + 2 + sizeof DN_SAVE_NAME + 1 + (sizeof(dn_file) + 2) / 3 * 4 + 2];
diff --git a/games/famidash/src/main.c b/games/famidash/src/main.c
index da1fa373..f9616b2f 100644
--- a/games/famidash/src/main.c
+++ b/games/famidash/src/main.c
@@ -49,7 +49,8 @@ static bool save_ok(const save_t *s) {
return true;
}
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-static const char head[] = "# Famidash keeps a copy of your game here,\n# so that installing it again doesn't erase it.\n#>" SAVE_NAME ":";
+#define TAG "#>" SAVE_NAME ":" /* the copy's line (found anywhere: an older copy has a longer head) */
+static const char head[] = "# Famidash's saves: keep this file\n" TAG;
static uint8_t copy[1 + sizeof head + (sizeof(save_t) + 2) / 3 * 4 + 2];
static void sync_out(void) { /* the game's settings into the save */
@@ -92,9 +93,9 @@ static bool copy_read(save_t *out) {
uint32_t n;
const uint8_t *c = plat_load(COPY_NAME, &n);
if (!c) return false;
- const uint32_t hl = sizeof head - 1, m = (sizeof(save_t) + 2) / 3 * 4;
+ const uint32_t hl = sizeof TAG - 1, m = (sizeof(save_t) + 2) / 3 * 4;
for (uint32_t i = 0; i + hl + m <= n; i++) {
- if (memcmp(c + i, head, hl)) continue;
+ if (memcmp(c + i, head + sizeof head - sizeof TAG, hl)) continue;
const uint8_t *l = c + i + hl;
static uint8_t buf[(sizeof(save_t) + 2) / 3 * 3];
for (uint32_t k = 0; k < m; k += 4) {
diff --git a/games/famidash/tests/play.c b/games/famidash/tests/play.c
index 0ce6fa6e..48c0028f 100644
--- a/games/famidash/tests/play.c
+++ b/games/famidash/tests/play.c
@@ -64,6 +64,15 @@ static void forget(const char *name) {
for (int i = 0; i < 4; i++)
if (files[i].on && !strcmp(files[i].name, name)) files[i].on = false;
}
+/* the copy as the game wrote it before, under a longer head */
+static void old_copy(const char *head) {
+ static uint8_t buf[sizeof files[0].data];
+ uint32_t n, at = 1, hl = (uint32_t)strlen(head);
+ const uint8_t *c = file_of(COPY_NAME, &n);
+ while (at + 1 < n && !(c[at] == '#' && c[at + 1] == '>')) at++;
+ buf[0] = 0, memcpy(buf + 1, head, hl), memcpy(buf + 1 + hl, c + at, n - at);
+ plat_save(COPY_NAME, buf, 1 + hl + n - at);
+}
static void ppm(const char *path) {
FILE *f = fopen(path, "wb");
@@ -414,6 +423,10 @@ static void test_saves(void) {
icon = 0, memset(&prog, 0, sizeof prog);
load();
CHECK(icon == 7 && prog.normal[5] == 42, "lost: from the copy");
+ old_copy("# Famidash keeps a copy of your game here,\n# so that installing it again doesn't erase it.\n");
+ icon = 0, memset(&prog, 0, sizeof prog);
+ load();
+ CHECK(icon == 7 && prog.normal[5] == 42, "lost: from an older copy");
/* both damaged: a fresh game, no crash */
memcpy(file_of(COPY_NAME, &n) + 120, "!!!!", 4);
plat_save(SAVE_NAME, keep, 10);
diff --git a/games/finalearth2/src/savecopy.c b/games/finalearth2/src/savecopy.c
index 8d79ce12..864f5f40 100644
--- a/games/finalearth2/src/savecopy.c
+++ b/games/finalearth2/src/savecopy.c
@@ -11,10 +11,7 @@
#define COPY_NAME "finalearth2_saves.py"
static const char *const kept[] = {"finalearth2.sav", "fe2meta.dat"};
#define NKEPT (int)(sizeof kept / sizeof kept[0])
-static const char copy_head[] =
- "# The Final Earth 2 keeps a copy of your city here, so that\n"
- "# reinstalling it doesn't erase it. If you delete this file,\n"
- "# the game writes it again: your city stays either way.\n";
+static const char copy_head[] = "# The Final Earth 2's saves: keep this file\n";
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
void save_copy_drop(void) { plat_remove(COPY_NAME); }
diff --git a/games/fnaf/src/save.c b/games/fnaf/src/save.c
index 62bc04b5..518f671b 100644
--- a/games/fnaf/src/save.c
+++ b/games/fnaf/src/save.c
@@ -26,10 +26,7 @@ typedef struct {
static const char *const kept[] = {SAVE_NAME, RESUME_NAME};
#define NKEPT (int)(sizeof kept / sizeof kept[0])
-static const char copy_head[] =
- "# Five Nights at Freddy's keeps a copy of your nights\n"
- "# and stars here, so that reinstalling it doesn't erase\n"
- "# them. If you delete this file, the game writes it again.\n";
+static const char copy_head[] = "# Five Nights at Freddy's saves: keep this file\n";
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static void copy_write(void) {
diff --git a/games/fnaf2/src/save.c b/games/fnaf2/src/save.c
index 76fae6ad..91a1bb04 100644
--- a/games/fnaf2/src/save.c
+++ b/games/fnaf2/src/save.c
@@ -27,10 +27,7 @@ typedef struct {
static const char *const kept[] = {SAVE_NAME, RESUME_NAME};
#define NKEPT (int)(sizeof kept / sizeof kept[0])
-static const char copy_head[] =
- "# Five Nights at Freddy's 2 keeps a copy of your nights\n"
- "# and stars here, so that reinstalling it doesn't erase\n"
- "# them. If you delete this file, the game writes it again.\n";
+static const char copy_head[] = "# Five Nights at Freddy's 2's saves: keep this file\n";
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static void copy_write(void) {
diff --git a/games/fnf/src/save.c b/games/fnf/src/save.c
index aa95db02..2c2e2cae 100644
--- a/games/fnf/src/save.c
+++ b/games/fnf/src/save.c
@@ -31,8 +31,7 @@ bool fnf_file_ok(const fnf_file_t *f) {
return true;
}
-static const char head[] = "# Friday Night Funkin' keeps a copy of your scores here,\n"
- "# so that installing it again doesn't erase them.\n";
+static const char head[] = "# Friday Night Funkin' saves: keep this file\n";
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static uint8_t copy[1 + sizeof head + 2 + sizeof FNF_SAVE_NAME + 1 + (sizeof(fnf_file_t) + 2) / 3 * 4 + 2];
diff --git a/games/hillclimb/src/save.c b/games/hillclimb/src/save.c
index f739f62a..0829be54 100644
--- a/games/hillclimb/src/save.c
+++ b/games/hillclimb/src/save.c
@@ -43,10 +43,7 @@ static const uint16_t OLD_COST[OLD_V][4] = {{1000, 1000, 1000, 1000}, {1500, 100
{1500, 1200, 1200, 1200}, {1500, 1500, 1500, 2500}, {2000, 2000, 2000, 3000},
{3000, 3000, 3000, 3000}, {3000, 3000, 3000, 3000}};
-static const char copy_head[] =
- "# Hill Climb Racing keeps a copy of your progress here, so\n"
- "# that reinstalling it doesn't erase it. If you delete this\n"
- "# file, the game writes it again: your progress stays.\n";
+static const char copy_head[] = "# Hill Climb Racing's saves: keep this file\n";
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static void copy_write(void) {
diff --git a/games/hollowknight/src/save.c b/games/hollowknight/src/save.c
index e1db7182..74d4ffda 100644
--- a/games/hollowknight/src/save.c
+++ b/games/hollowknight/src/save.c
@@ -94,10 +94,7 @@ static const uint8_t *checked(int slot, uint32_t *count, uint32_t *pd_size) {
* a comment line "#>hk1.sav:base64" a slot (the way NumPlay keeps its games' saves), and come back from it when a
* save itself is gone. */
#define COPY_NAME "hollowknight_saves.py"
-static const char copy_head[] =
- "# Hollow Knight keeps a copy of your saves here, so that\n"
- "# reinstalling it doesn't erase them. If you delete this file,\n"
- "# Hollow Knight writes it again: your saves stay either way.\n";
+static const char copy_head[] = "# Hollow Knight's saves: keep this file\n";
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static void save_copy(void) {
diff --git a/games/isaac/src/save.c b/games/isaac/src/save.c
index 251d36cb..bd39606f 100644
--- a/games/isaac/src/save.c
+++ b/games/isaac/src/save.c
@@ -17,10 +17,7 @@ extern uint8_t item_taken[ITEM_MAX];
static const char *const kept[] = {PROGRESS_NAME, RUN_NAME};
#define NKEPT (int)(sizeof kept / sizeof kept[0])
-static const char copy_head[] =
- "# The Binding of Isaac keeps a copy of your run and progress\n"
- "# here, so that reinstalling it doesn't erase them. If you\n"
- "# delete this file, the game writes it again.\n";
+static const char copy_head[] = "# The Binding of Isaac's saves: keep this file\n";
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static void copy_write(void) {
diff --git a/games/jetpackjoyride/src/save.c b/games/jetpackjoyride/src/save.c
index d4de8567..3c4f1183 100644
--- a/games/jetpackjoyride/src/save.c
+++ b/games/jetpackjoyride/src/save.c
@@ -40,8 +40,7 @@ bool jj_file_v1(const uint8_t *d, uint32_t n, jj_profile *p) {
return true;
}
-static const char head[] = "# Jetpack Joyride keeps a copy of your best and your coins\n"
- "# here, so that installing it again doesn't erase them.\n";
+static const char head[] = "# Jetpack Joyride's saves: keep this file\n";
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static uint8_t copy[1 + sizeof head + 2 + sizeof JJ_SAVE_NAME + 1 + (sizeof(jj_file) + 2) / 3 * 4 + 2];
diff --git a/games/leveldevil/src/main.c b/games/leveldevil/src/main.c
index 8268a205..c2f9afc6 100644
--- a/games/leveldevil/src/main.c
+++ b/games/leveldevil/src/main.c
@@ -167,9 +167,8 @@ static char *label(char *o, const char *s, uint32_t v) {
Python scripts, so the save comes back from the copy when the file itself is gone. The copy is a
comment line "#>leveldevil.sav:base64" (the way NumPlay and the big games keep theirs). */
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-static const char copy_head[] = "# Level Devil keeps a copy of your progress here, so that\n"
- "# reinstalling it doesn't erase it. If you delete this\n"
- "# file, the game writes it again.\n#>" SAVE_NAME ":";
+#define TAG "#>" SAVE_NAME ":" /* the copy's line (found anywhere: an older copy has a longer head) */
+static const char copy_head[] = "# Level Devil's saves: keep this file\n" TAG;
static void save(void) {
static char copy[sizeof copy_head + 72];
const uint8_t *d = (const uint8_t *)&sv;
@@ -185,15 +184,16 @@ static void save(void) {
*p++ = '\n', *p++ = 0;
ef_write(COPY_NAME, copy, (uint32_t)(p - copy));
}
-/* the save back from the copy, if only the copy is left */
+/* the save back from the copy, if only the copy is left: the line after its tag */
static void restore(void) {
- uint32_t len, n = sizeof copy_head;
- const uint8_t *c = ef_read(COPY_NAME, &len);
+ const char *tag = copy_head + sizeof copy_head - sizeof TAG;
+ uint32_t len, j = 0, m = 0;
+ const uint8_t *c;
uint8_t out[sizeof sv];
- if (ef_read(SAVE_NAME, &len) || !(c = ef_read(COPY_NAME, &len)) || len < n + 64) return;
- for (uint32_t i = 0; i < n - 1; i++)
- if (c[1 + i] != (uint8_t)copy_head[i]) return;
- for (unsigned i = 0, j = n; i < sizeof sv; i += 3, j += 4) {
+ if (ef_read(SAVE_NAME, &len) || !(c = ef_read(COPY_NAME, &len))) return;
+ while (m < sizeof TAG - 1 && j + sizeof TAG - 1 <= len) m = c[j + m] == (uint8_t)tag[m] ? m + 1 : (j++, 0u);
+ if ((j += sizeof TAG - 1) + 64 > len) return;
+ for (unsigned i = 0; i < sizeof sv; i += 3, j += 4) {
uint32_t v = 0;
for (int k = 0; k < 4; k++) {
int x = 0;
diff --git a/games/mahjong/src/main.c b/games/mahjong/src/main.c
index 7d60e228..e8398eb1 100644
--- a/games/mahjong/src/main.c
+++ b/games/mahjong/src/main.c
@@ -205,7 +205,8 @@ static uint32_t fnv(const void *p, uint32_t n) {
/* the copy: the save in base 64, in a comment of a script (installing apps keeps only scripts) */
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-static const char head[] = "# Mahjong keeps a copy of your game here,\n# so that installing it again doesn't erase it.\n#>" SAVE_NAME ":";
+#define TAG "#>" SAVE_NAME ":" /* the copy's line (found anywhere: an older copy has a longer head) */
+static const char head[] = "# Mahjong's saves: keep this file\n" TAG;
static uint8_t copy[1 + sizeof head + (sizeof sv + 2) / 3 * 4 + 1];
static void save(void) {
sv.magic = 'M', sv.version = 1, sv.sum = fnv(&sv, SUMMED);
@@ -242,8 +243,11 @@ static void load(void) {
uint8_t *v = (uint8_t *)&sv;
for (uint32_t i = 0; i < sizeof sv; i++) v[i] = d && n == sizeof sv ? d[i] : 0;
if (valid()) return;
- d = file_read(COPY_NAME, &n); /* the copy, after an install */
- uint32_t o = 0, at = sizeof head; /* (the 0, then the head without its own 0) */
+ d = file_read(COPY_NAME, &n); /* the copy, after an install: the line after its tag */
+ const char *tag = head + sizeof head - sizeof TAG;
+ uint32_t o = 0, at = 0, m = 0;
+ while (d && m < sizeof TAG - 1 && at + sizeof TAG - 1 <= n) m = d[at + m] == (uint8_t)tag[m] ? m + 1 : (at++, 0u);
+ at += sizeof TAG - 1;
for (uint32_t i = 0; d && n >= at + (sizeof sv + 2) / 3 * 4 && i < (sizeof sv + 2) / 3 * 4; i += 4) {
uint32_t w = 0;
for (int k = 0; k < 4; k++) {
diff --git a/games/mahjong/tests/play.c b/games/mahjong/tests/play.c
index 17cde115..b5c946d1 100644
--- a/games/mahjong/tests/play.c
+++ b/games/mahjong/tests/play.c
@@ -260,6 +260,19 @@ static void check_saves(void) {
memset(&sv, 0, sizeof sv);
load();
CHECK(sv.flags == 2, "how to play read, no game");
+ /* the copy as the game wrote it before, under a longer head: read the same */
+ sv.best[1] = 4321, save(), memcpy(kept, &sv, sizeof sv);
+ static const char old[] = "# Mahjong keeps a copy of your game here,\n# so that installing it again doesn't erase it.\n";
+ uint8_t buf[sizeof files[0].data];
+ const uint8_t *c = files[find(COPY_NAME)].data;
+ uint32_t n = files[find(COPY_NAME)].len, at = 1;
+ while (at + 1 < n && !(c[at] == '#' && c[at + 1] == '>')) at++;
+ buf[0] = 0, memcpy(buf + 1, old, sizeof old - 1), memcpy(buf + sizeof old, c + at, n - at);
+ host_write(COPY_NAME, buf, sizeof old + n - at);
+ files[find(SAVE_NAME)].len = 0;
+ memset(&sv, 0, sizeof sv);
+ load();
+ CHECK(!memcmp(kept, &sv, sizeof sv) && sv.best[1] == 4321, "an older copy read back");
}
/* the keys that take the cursor from tile c to tile t (the arrows alone), found by trying them */
diff --git a/games/monkeymart/src/save.c b/games/monkeymart/src/save.c
index aa393a12..3199a82c 100644
--- a/games/monkeymart/src/save.c
+++ b/games/monkeymart/src/save.c
@@ -18,8 +18,7 @@ bool mm_file_ok(const mm_file *f) {
return mm_progress_ok(&f->p);
}
-static const char head[] = "# Monkey Mart keeps a copy of your marts, coins and hats\n"
- "# here, so that installing it again doesn't erase them.\n";
+static const char head[] = "# Monkey Mart's saves: keep this file\n";
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static uint8_t copy[1 + sizeof head + 2 + sizeof MM_SAVE_NAME + 1 + (sizeof(mm_file) + 2) / 3 * 4 + 2];
diff --git a/games/numblocks/src/save.c b/games/numblocks/src/save.c
index 6fd0c7fe..ebe3e859 100644
--- a/games/numblocks/src/save.c
+++ b/games/numblocks/src/save.c
@@ -326,10 +326,7 @@ void delete_world(int s) {
* games' saves, and in NumPlay it leaves that to NumPlay), and when none of its saves are left, they
* come back from it. */
#define COPY_REC "numblocks_saves.py"
-static const char copy_head[] =
- "# NumBlocks keeps a copy of your worlds here, so that installing\n"
- "# it again doesn't erase them. If you delete this file, NumBlocks\n"
- "# writes it again: your worlds stay either way.\n";
+static const char copy_head[] = "# NumBlocks' saves: keep this file\n";
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static bool ours(const char *n) { return !strcmp(n, OPTIONS_REC) || (n[0] == 'n' && n[1] == 'b' && n[2] >= '1' && n[2] <= '9'); }
diff --git a/games/numpowder/src/ui_save.c b/games/numpowder/src/ui_save.c
index 456b4c0f..5c549be2 100644
--- a/games/numpowder/src/ui_save.c
+++ b/games/numpowder/src/ui_save.c
@@ -16,10 +16,7 @@ static const char *const kept[] = {"numpowder.cfg", "numpowder.sav", "numpowder1
#define NKEPT (int)(sizeof kept / sizeof kept[0])
/* ---------------------------------------------------------------- the copy in a Python script */
-static const char copy_head[] =
- "# NumPowder keeps a copy of your simulations here, so that\n"
- "# reinstalling it doesn't erase them. If you delete this file,\n"
- "# the game writes it again: your saves stay either way.\n";
+static const char copy_head[] = "# NumPowder's saves: keep this file\n";
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static void save_copy(void) {
diff --git a/games/paperclips/src/save.c b/games/paperclips/src/save.c
index 1f391270..1e6e59c6 100644
--- a/games/paperclips/src/save.c
+++ b/games/paperclips/src/save.c
@@ -79,8 +79,7 @@ void save_pack(const pc_game *s, uint8_t guide, uint8_t tab, uint8_t *out) {
memcpy(out + PC_FILE_SIZE - 4, &sum, 4);
}
-static const char head[] = "# Universal Paperclips keeps a copy of your game here,\n"
- "# so that installing it again doesn't erase it.\n";
+static const char head[] = "# Universal Paperclips' saves: keep this file\n";
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static uint8_t file[PC_FILE_SIZE];
static uint8_t copy[1 + sizeof head + 2 + sizeof PC_SAVE_NAME + 1 + (PC_FILE_SIZE + 2) / 3 * 4 + 2];
diff --git a/games/polytrack/src/save.c b/games/polytrack/src/save.c
index bad56a11..ad0f73ad 100644
--- a/games/polytrack/src/save.c
+++ b/games/polytrack/src/save.c
@@ -33,8 +33,7 @@ bool pt_file_ok(const pt_file *f) {
return profile_ok(&f->p);
}
-static const char head[] = "# PolyTrack keeps a copy of your progress here,\n"
- "# so that installing it again doesn't erase it.\n";
+static const char head[] = "# PolyTrack's saves: keep this file\n";
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static uint8_t copy[1 + sizeof head + 2 + sizeof PT_SAVE_NAME + 1 + (sizeof(pt_file) + 2) / 3 * 4 + 2];
diff --git a/games/pvz/src/save.c b/games/pvz/src/save.c
index 111a4844..1729ed19 100644
--- a/games/pvz/src/save.c
+++ b/games/pvz/src/save.c
@@ -16,10 +16,7 @@ Progress progress;
static const char *const kept[] = {SAVE_NAME, LEVEL_NAME};
#define NKEPT (int)(sizeof kept / sizeof kept[0])
-static const char copy_head[] =
- "# Plants vs. Zombies keeps a copy of your progress here, so\n"
- "# that reinstalling it doesn't erase it. If you delete this\n"
- "# file, the game writes it again: your progress stays.\n";
+static const char copy_head[] = "# Plants vs. Zombies' saves: keep this file\n";
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static void copy_write(void) {
diff --git a/games/rider/src/main.c b/games/rider/src/main.c
index 24705c59..54fa3b17 100644
--- a/games/rider/src/main.c
+++ b/games/rider/src/main.c
@@ -61,7 +61,8 @@ static bool save_ok(const save_t *s) {
}
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-static const char head[] = "# Rider keeps a copy of your game here,\n# so that installing it again doesn't erase it.\n#>" SAVE_NAME ":";
+#define TAG "#>" SAVE_NAME ":" /* the copy's line (found anywhere: an older copy has a longer head) */
+static const char head[] = "# Rider's saves: keep this file\n" TAG;
static uint8_t copy[1 + sizeof head + (sizeof(save_t) + 2) / 3 * 4 + 2];
static void save(void) {
@@ -89,9 +90,9 @@ static bool copy_read(save_t *out) {
uint32_t n;
const uint8_t *c = plat_load(COPY_NAME, &n);
if (!c) return false;
- const uint32_t hl = sizeof head - 1, m = (sizeof(save_t) + 2) / 3 * 4;
+ const uint32_t hl = sizeof TAG - 1, m = (sizeof(save_t) + 2) / 3 * 4;
for (uint32_t i = 0; i + hl + m <= n; i++) {
- if (memcmp(c + i, head, hl)) continue;
+ if (memcmp(c + i, head + sizeof head - sizeof TAG, hl)) continue;
const uint8_t *l = c + i + hl;
uint8_t buf[(sizeof(save_t) + 2) / 3 * 3];
for (uint32_t k = 0; k < m; k += 4) {
diff --git a/games/rider/tests/play.c b/games/rider/tests/play.c
index 604e2761..e0deca0b 100644
--- a/games/rider/tests/play.c
+++ b/games/rider/tests/play.c
@@ -64,6 +64,15 @@ static void forget(const char *name) {
for (int i = 0; i < 4; i++)
if (files[i].on && !strcmp(files[i].name, name)) files[i].on = false;
}
+/* the copy as the game wrote it before, under a longer head */
+static void old_copy(const char *head) {
+ static uint8_t buf[sizeof files[0].data];
+ uint32_t n, at = 1, hl = (uint32_t)strlen(head);
+ const uint8_t *c = file_of(COPY_NAME, &n);
+ while (at + 1 < n && !(c[at] == '#' && c[at + 1] == '>')) at++;
+ buf[0] = 0, memcpy(buf + 1, head, hl), memcpy(buf + 1 + hl, c + at, n - at);
+ plat_save(COPY_NAME, buf, 1 + hl + n - at);
+}
static void ppm(const char *path) {
FILE *f = fopen(path, "wb");
@@ -305,6 +314,10 @@ static void test_app(void) {
forget(SAVE_NAME);
load();
CHECK(sv.gems == 4321, "a lost save comes back from the copy (%u)", (unsigned)sv.gems);
+ old_copy("# Rider keeps a copy of your game here,\n# so that installing it again doesn't erase it.\n");
+ sv.gems = 0;
+ load();
+ CHECK(sv.gems == 4321, "a lost save comes back from an older copy (%u)", (unsigned)sv.gems);
forget(COPY_NAME), forget(SAVE_NAME);
load();
CHECK(sv.gems == 0 && owned(0), "nothing left: a fresh start");
diff --git a/games/snowrider/src/save.c b/games/snowrider/src/save.c
index 4f3c07ce..2c0d86bb 100644
--- a/games/snowrider/src/save.c
+++ b/games/snowrider/src/save.c
@@ -31,8 +31,7 @@ bool sr_file_ok(const SaveFile *f) {
return true;
}
-static const char head[] = "# Snow Rider 3D keeps a copy of your progress here,\n"
- "# so that installing it again doesn't erase it.\n";
+static const char head[] = "# Snow Rider 3D's saves: keep this file\n";
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static bool copy_write(const SaveFile *f) {
diff --git a/games/sonic/src/save.c b/games/sonic/src/save.c
index 7a5fa73c..fc7e240d 100644
--- a/games/sonic/src/save.c
+++ b/games/sonic/src/save.c
@@ -23,10 +23,7 @@ static SaveFile sv;
static bool loaded;
static uint32_t counted; /* the frames already added to sv.frames */
-static const char copy_head[] =
- "# Sonic the Hedgehog keeps a copy of your game here, so that\n"
- "# reinstalling it doesn't erase it. If you delete this file,\n"
- "# the game writes it again: your game stays either way.\n";
+static const char copy_head[] = "# Sonic the Hedgehog's saves: keep this file\n";
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static void copy_write(const uint8_t *d, uint32_t len) {
diff --git a/games/stickmanhook/src/save.c b/games/stickmanhook/src/save.c
index cc32a891..550add3c 100644
--- a/games/stickmanhook/src/save.c
+++ b/games/stickmanhook/src/save.c
@@ -22,8 +22,7 @@ bool sh_file_ok(const sh_file *f) {
return f->sum == sum(f, offsetof(sh_file, sum)) && sh_profile_ok(&f->p);
}
-static const char head[] = "# Stickman Hook keeps a copy of your levels and skin\n"
- "# here, so that installing it again doesn't erase them.\n";
+static const char head[] = "# Stickman Hook's saves: keep this file\n";
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static uint8_t copy[1 + sizeof head + 2 + sizeof SH_SAVE_NAME + 1 + (sizeof(sh_file) + 2) / 3 * 4 + 2];
diff --git a/games/subway/src/save.c b/games/subway/src/save.c
index 9e47a89a..68c4f286 100644
--- a/games/subway/src/save.c
+++ b/games/subway/src/save.c
@@ -16,10 +16,7 @@ typedef struct {
Progress p;
} SaveFile;
-static const char copy_head[] =
- "# Subway Surfers keeps a copy of your coins and progress\n"
- "# here, so that reinstalling it doesn't erase them. If you\n"
- "# delete this file, the game writes it again.\n";
+static const char copy_head[] = "# Subway Surfers' saves: keep this file\n";
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static void copy_write(const uint8_t *d, uint32_t len) {
diff --git a/games/templerun/src/save.c b/games/templerun/src/save.c
index c3852b35..a4327cef 100644
--- a/games/templerun/src/save.c
+++ b/games/templerun/src/save.c
@@ -17,10 +17,7 @@ typedef struct {
Progress p;
} SaveFile;
-static const char copy_head[] =
- "# Temple Run keeps a copy of your coins and progress\n"
- "# here, so that reinstalling it doesn't erase them. If you\n"
- "# delete this file, the game writes it again.\n";
+static const char copy_head[] = "# Temple Run's saves: keep this file\n";
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static void copy_write(const uint8_t *d, uint32_t len) {
diff --git a/games/tombofthemask/src/save.c b/games/tombofthemask/src/save.c
index 8bcef01c..ba0c3ab8 100644
--- a/games/tombofthemask/src/save.c
+++ b/games/tombofthemask/src/save.c
@@ -18,8 +18,7 @@ bool tm_file_ok(const tm_file *f) {
return tm_progress_ok(&f->p);
}
-static const char head[] = "# Tomb of the Mask keeps a copy of your stages, coins and masks\n"
- "# here, so that installing it again doesn't erase them.\n";
+static const char head[] = "# Tomb of the Mask's saves: keep this file\n";
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static uint8_t copy[1 + sizeof head + 2 + sizeof TM_SAVE_NAME + 1 + (sizeof(tm_file) + 2) / 3 * 4 + 2];
diff --git a/games/turborush/src/save.c b/games/turborush/src/save.c
index 71a570ba..ed593a3d 100644
--- a/games/turborush/src/save.c
+++ b/games/turborush/src/save.c
@@ -66,8 +66,7 @@ bool tr_file_ok(const tr_file *f) {
return r->mode != MODE_GP || (f->gp.on && r->track == f->gp.round);
}
-static const char head[] = "# Turbo Rush keeps a copy of your progress here,\n"
- "# so that installing it again doesn't erase it.\n";
+static const char head[] = "# Turbo Rush's saves: keep this file\n";
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static uint8_t copy[1 + sizeof head + 2 + sizeof TR_SAVE_NAME + 1 + (sizeof(tr_file) + 2) / 3 * 4 + 2];
diff --git a/games/undertale/src/save.c b/games/undertale/src/save.c
index f89a62f1..c8ad94fa 100644
--- a/games/undertale/src/save.c
+++ b/games/undertale/src/save.c
@@ -25,10 +25,7 @@ typedef struct {
static const char *const kept[] = {SAVE_NAME, RESUME_NAME, CONFIG_NAME};
#define NKEPT (int)(sizeof kept / sizeof kept[0])
-static const char copy_head[] =
- "# Undertale keeps a copy of your SAVE and settings here, so that\n"
- "# reinstalling it doesn't erase it. If you delete this file,\n"
- "# the game writes it again: your SAVE stays either way.\n";
+static const char copy_head[] = "# Undertale's saves: keep this file\n";
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static void copy_write(void) {
diff --git a/games/uno/src/save.c b/games/uno/src/save.c
index 0164974e..99838f2f 100644
--- a/games/uno/src/save.c
+++ b/games/uno/src/save.c
@@ -28,8 +28,7 @@ bool uno_file_ok(const uno_file *f) {
return !p->has_game || uno_valid(&p->g);
}
-static const char head[] = "# UNO keeps a copy of your game here,\n"
- "# so that installing it again doesn't erase it.\n";
+static const char head[] = "# UNO's saves: keep this file\n";
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static uint8_t copy[1 + sizeof head + 2 + sizeof UNO_SAVE_NAME + 1 + (sizeof(uno_file) + 2) / 3 * 4 + 2];
diff --git a/launcher/src/storage.c b/launcher/src/storage.c
index 64d87f62..d0d2c501 100644
--- a/launcher/src/storage.c
+++ b/launcher/src/storage.c
@@ -116,10 +116,7 @@ bool np_file_write(const char *name, const void *data, uint32_t len) { return ef
* "#=name:size:base64" packed (games/common/np_lz.h), when that is smaller: the file system holds
* 42 KB, and a copy that takes less of it leaves more to the saves. */
#define COPY_NAME "numplay_saves.py"
-static const char copy_head[] =
- "# NumPlay keeps a copy of your game progress here, so that\n"
- "# updating NumPlay doesn't erase it. If you delete this file,\n"
- "# NumPlay writes it again: your progress stays either way.\n";
+static const char copy_head[] = "# NumPlay's saves: keep this file\n";
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static uint32_t b64_len(uint32_t n) { return (n + 2) / 3 * 4; }