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.
C calculatorcalculator-gamescasiochesscrossy-roaddrive-madfx-cg50gamesgeometry-dashgraphing-calculatorndlessnumworksnumworks-appsnumworks-calculatornumworks-gamenumworks-gamestetristi-84-plus-ceti-nspire
Celeste: the game's cheat code, and a room picker
Mason Chen1af194f28783
diff --git a/games/celeste/src/celeste.h b/games/celeste/src/celeste.hindex 85609b0a..64779a36 100644--- a/games/celeste/src/celeste.h+++ b/games/celeste/src/celeste.h@@ -56,7 +56,7 @@ char *path2(char *buf, const char *a, const char *b, int n);enum {K_LEFT = 1 << 0, K_RIGHT = 1 << 1, K_UP = 1 << 2, K_DOWN = 1 << 3,K_JUMP = 1 << 4, K_DASH = 1 << 5, K_GRAB = 1 << 6, K_TALK = 1 << 7,- K_PAUSE = 1 << 8, K_HOME = 1 << 9, K_OK = 1 << 10, K_BACK = 1 << 11,+ K_PAUSE = 1 << 8, K_HOME = 1 << 9, K_OK = 1 << 10, K_BACK = 1 << 11, K_JOURNAL = 1 << 12,K_ANY = 1 << 15};uint32_t plat_keys(void);diff --git a/games/celeste/src/ch0.c b/games/celeste/src/ch0.cindex fa80d172..fe396221 100644--- a/games/celeste/src/ch0.c+++ b/games/celeste/src/ch0.c@@ -674,6 +674,50 @@ void prologue_ending_start(Player *p, Ent *bird) {cutscene_start(e, ending_end, false, true);}+/* ---------------------------------------------------------------- UnlockEverythingThingy */+/* a CheatListener in room -1 (Level.LoadLevel adds it until cheat mode is on): left, right, journal, grab, up, up,+ * down, left, grab, confirm unlock every chapter and turn cheat mode on */+typedef struct {+ char in[10]; /* CurrentInput: the last 10 */+} Cheat;+static void unlock_everything(void) {+ g_save.revealed_ch9 = 1;+ g_save.unlocked_areas = AREAS - 1; /* MaxArea */+ g_save.cheat_mode = 1;+ g_session.in_area = 0;+ game_level_exit(LEXIT_GIVEUP);+}+static void cheat_update(Ent *e) {+ Cheat *c = ST(e, Cheat);+ uint32_t down = g_in.keys & ~g_in.prev; /* (Pressed, not Repeating) */+ bool journal = down & K_JOURNAL;+ char got[7];+ int n = 0;+ if (down & K_UP) got[n++] = 'u';+ if (down & K_DOWN) got[n++] = 'd';+ if (down & K_RIGHT) got[n++] = 'r';+ if (down & K_LEFT) got[n++] = 'l';+ if (g_in.confirm.edge) got[n++] = 'A';+ if (journal) got[n++] = 'L';+ if (g_in.grab.edge && !journal) got[n++] = 'R';+ if (!n) return;+ memmove(c->in, c->in + n, sizeof c->in - (size_t)n);+ memcpy(c->in + sizeof c->in - n, got, (size_t)n);+ if (memcmp(c->in, "lrLRuudlRA", sizeof c->in)) return;+ /* EnteredCheat */+ g_level.pause_lock = true;+ g_level.frozen = true;+ level_flash(0xFFFF, false);+ wipe_start(WIPE_FADE, false, unlock_everything);+ g_wipe.duration = 2;+ ent_remove(e);+}+static const EntClass CHEAT = {.size = sizeof(Cheat), .name = "UnlockEverythingThingy", .update = cheat_update};+void unlock_everything_new(void) {+ Ent *e = ent_new(&CHEAT, 0, 0);+ if (e) e->visible = 0, e->collidable = 0;+}+/* ---------------------------------------------------------------- the factory */bool ents_ch0(const EData *d) {switch (d->type) {diff --git a/games/celeste/src/ch9.c b/games/celeste/src/ch9.cindex 932ece78..35c40c4f 100644--- a/games/celeste/src/ch9.c+++ b/games/celeste/src/ch9.c@@ -1184,7 +1184,7 @@ static void hd_update(Ent *e) {counting:if (!h->opened && h->counter < h->requires) {if (p && fabsf(p->ent->x - e_cxm(e)) < 80 && p->ent->x < e->x) {- int hearts = hearts_total();+ int hearts = g_save.cheat_mode ? h->requires : hearts_total(); /* HeartGems */if (hearts < h->requires) level_set_flag("granny_door", true);int was = (int)h->counter, target = hearts < h->requires ? hearts : h->requires;h->counter = approach(h->counter, (float)target, DT * h->requires * 0.8f);diff --git a/games/celeste/src/level.c b/games/celeste/src/level.cindex df5a9af7..8317933e 100644--- a/games/celeste/src/level.c+++ b/games/celeste/src/level.c@@ -195,6 +195,7 @@ static bool room_load(int slot, int index, int intro) {g_level.has_start_position = false;g_level.in_space = (r[RR_FLAGS] & 2) != 0; /* InSpace (LevelData.Space) */session_enter(index, intro);+ if (g_session.area == 0 && !g_save.cheat_mode && !strcmp(str(rd16(r + RR_NAME)), "-1")) unlock_everything_new();entities_load(rm, blob, slot);g_res_can_load = true;g_level.room_slot = was, g_level.room = was_room;@@ -743,7 +744,7 @@ void level_update(void) {ents_flush_removed();return;}- /* CanPause: Back (Input.Pause) */+ /* CanPause: backspace (Input.Pause) */Player *pp = level_player();if (btn_pressed(&g_in.pause) && pp && !pp->dead && !g_level.pause_lock && !g_level.skipping_cutscene &&!g_level.transitioning && !g_wipe.active) {diff --git a/games/celeste/src/level.h b/games/celeste/src/level.hindex 67e47ff0..d4b16045 100644--- a/games/celeste/src/level.h+++ b/games/celeste/src/level.h@@ -208,6 +208,7 @@ void save_set_flag(int bit);void save_register_cassette(void);void save_register_completion(void);void session_start(int chapter, int checkpoint); /* new Session(area, checkpoint) */+void session_start_room(int chapter, int room); /* in any room (cheat mode) */void session_restart(int room); /* Session.Restart(into room), -1 for its start */int session_intro(bool just_started); /* INTRO_ for LevelLoader */int level_start_room(void);@@ -221,6 +222,7 @@ void level_load_room_near(int index, int intro, float fx, float fy);void level_complete_area(bool spotlight_wipe, bool skip_wipe);enum { LEXIT_COMPLETED, LEXIT_SAVEQUIT, LEXIT_RESTART, LEXIT_GIVEUP, LEXIT_GOLDEN_RESTART };void game_level_exit(int mode); /* game.c: LevelExit */+void unlock_everything_new(void); /* ch0.c: the cheat code's listener */void level_extra_textures(const uint16_t *ids, int n); /* kept loaded with the rooms' (n = 0: none) */int chapter_find_room(int chapter, const char *name); /* -1 if none */const char *chapter_room_name(int chapter, int i); /* NULL past its last room */diff --git a/games/celeste/src/menu.c b/games/celeste/src/menu.cindex f63a75f6..84b637d8 100644--- a/games/celeste/src/menu.c+++ b/games/celeste/src/menu.c@@ -13,6 +13,7 @@ enum { S_NONE, S_SHEET, S_TITLE, S_MAIN, S_CHAPTERS, S_PANEL, S_OPTIONS, S_KEYS,static struct {uint8_t screen, back; /* back: where Back goes from the options (S_PAUSE or S_MAIN) */int8_t sel, area, mode, cp, binding, confirm;+ int16_t room; /* the panel's room picker (cheat mode): the room chosen, -1 when closed */uint8_t hold, last_dir; /* the arrows' repeat */uint8_t advance; /* after a first completion: 1 the panel waits, 2 and 3 the chapter select moves on */float t, wig, repeat;@@ -84,7 +85,7 @@ static void inputs_end(void) {if (!g_in.move_x && !g_in.move_y) M.last_dir = 0;}static void go(int screen, int sel) {- M.screen = (uint8_t)screen, M.sel = (int8_t)sel, M.t = 0, M.wig = 0;+ M.screen = (uint8_t)screen, M.sel = (int8_t)sel, M.t = 0, M.wig = 0, M.room = -1;g_menu = (uint8_t)screen;btn_consume(&g_in.confirm);btn_consume(&g_in.back);@@ -108,7 +109,7 @@ static int max_area(void) { /* the last chapter there is, up to the ones unloc}static bool has_mode(int a, int mode) {if (chapter_index(a, mode) < 0 || interlude(a)) return mode == M_A && chapter_index(a, M_A) >= 0;- if (mode == M_B) return (g_save.cassettes >> a & 1) != 0;+ if (mode == M_B) return (g_save.cassettes >> a & 1) || g_save.cheat_mode;if (mode == M_C) return save_unlocked_modes() >= 3;return true;}@@ -120,7 +121,9 @@ static int popcount64(uint64_t v) {static bool session_here(void) {return g_save.has_session && g_session.in_area && g_session.area == M.area && g_session.mode == M.mode;}-/* the panel's start points: Continue (a session here), Start, then the checkpoints reached */+/* SaveData.GetCheckpoints: the checkpoints reached, all of them in cheat mode */+static bool cp_open(int i) { return g_save.cheat_mode || (g_save.modes[M.area][M.mode].checkpoints >> i & 1); }+/* the panel's start points: Continue (a session here), Start, the checkpoints, then in cheat mode the room picker */static int start_count(int *ncp) {int ch = chapter_index(M.area, M.mode);*ncp = 0;@@ -128,15 +131,20 @@ static int start_count(int *ncp) {const uint8_t *c = chapter_at(ch);int n = c[CH_NCHECKPOINTS], k = 0;for (int i = 0; i < n; i++)- if (g_save.modes[M.area][M.mode].checkpoints >> i & 1) k++;+ if (cp_open(i)) k++;*ncp = k;- return (session_here() ? 1 : 0) + 1 + k;+ return (session_here() ? 1 : 0) + 1 + k + (g_save.cheat_mode ? 1 : 0);}-static int nth_checkpoint(int k) { /* the k-th checkpoint reached */+static int nth_checkpoint(int k) { /* the k-th checkpoint open */for (int i = 0; i < 8; i++)- if (g_save.modes[M.area][M.mode].checkpoints >> i & 1 && k-- == 0) return i;+ if (cp_open(i) && k-- == 0) return i;return 0;}+static int room_count(int ch) {+ int n = 0;+ while (chapter_room_name(ch, n)) n++;+ return n;+}static void checkpoint_name(int i, char *out) { /* Dialog checkpoint_{area}{h}_{i} (Core's are 8's) */static const char *const ids[10] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "8"};char k[24] = "checkpoint_";@@ -148,6 +156,11 @@ static void checkpoint_name(int i, char *out) { /* Dialog checkpoint_{area}{h}}/* ---------------------------------------------------------------- game flow */+static void play_room(int room) { /* the room picker's choice */+ g_menu = M.screen = S_NONE;+ session_start_room(chapter_index(M.area, M.mode), room);+ game_play(-1, -1);+}static void play_chapter(int start) { /* the panel's choice: Continue, Start or a checkpoint */int ncp;int n = start_count(&ncp);@@ -357,15 +370,20 @@ static void panel_draw(void) {if (m == M.mode) box(mx, y + 314, text_width(w, 0.8f), 8, rgb(TITLE_BASE[M.area]), 255);mx += text_width(w, 0.8f) + 60;}- /* where to start */- int ncp, n = start_count(&ncp);+ /* where to start (or the rooms, picking one): five rows at a time */+ int ncp, n = start_count(&ncp), ch = chapter_index(M.area, M.mode);bool cont = session_here();- for (int i = 0; i < n; i++) {+ int count = M.room >= 0 ? room_count(ch) : n, at = M.room >= 0 ? M.room : M.sel;+ int first = at - 2 < count - 5 ? at - 2 : count - 5;+ if (first < 0) first = 0;+ for (int i = first; i < count && i < first + 5; i++) {char name[48];- if (cont && i == 0) strcpy(name, ui_str("FILE_CONTINUE"));+ if (M.room >= 0) strcpy(name, chapter_room_name(ch, i));+ else if (cont && i == 0) strcpy(name, ui_str("FILE_CONTINUE"));else if (i == (cont ? 1 : 0)) strcpy(name, ui_str("OVERWORLD_START"));+ else if (g_save.cheat_mode && i == n - 1) strcpy(name, "Room...");else checkpoint_name(nth_checkpoint(i - (cont ? 2 : 1)), name);- say(name, x + 60, y + 400 + i * 72, 0, 0.5f, 0.9f, i == M.sel ? highlight() : rgb(0x303030), 255);+ say(name, x + 60, y + 400 + (i - first) * 72, 0, 0.5f, 0.9f, i == at ? highlight() : rgb(0x303030), 255);}/* the stats: strawberries, deaths, the heart, the cassette */ModeStats *ms = &g_save.modes[M.area][M.mode];@@ -400,6 +418,15 @@ static void panel_update(void) {}return;}+ if (M.room >= 0) { /* the room picker: up and down, left and right ten at a time */+ int rooms = room_count(chapter_index(M.area, M.mode)), d = dir_pressed(1);+ if (d) M.room = (int16_t)((M.room + d + rooms) % rooms);+ d = dir_pressed(0) * 10;+ if (d) M.room = (int16_t)(M.room + d < 0 ? 0 : M.room + d >= rooms ? rooms - 1 : M.room + d);+ if (cancel()) M.room = -1;+ else if (confirm()) play_room(M.room);+ return;+ }int ncp, n = start_count(&ncp);int d = dir_pressed(1);if (d && n) M.sel = (int8_t)((M.sel + d + n) % n);@@ -410,7 +437,10 @@ static void panel_update(void) {if (m >= 0 && m < 3) M.mode = (int8_t)m, M.sel = 0;}if (cancel()) go(S_CHAPTERS, 0);- else if (confirm() && n) play_chapter(M.sel);+ else if (confirm() && n) {+ if (g_save.cheat_mode && M.sel == n - 1) M.room = 0;+ else play_chapter(M.sel);+ }}/* ---------------------------------------------------------------- options and keys (TextMenu) */@@ -548,7 +578,7 @@ static int pause_items(int8_t *items) {items[n++] = P_OPTIONS;items[n++] = P_SAVEQUIT;items[n++] = P_RESTART;- if (g_save.modes[0][0].flags & MS_COMPLETED) items[n++] = P_RETURN;+ if ((g_save.modes[0][0].flags & MS_COMPLETED) || g_save.cheat_mode) items[n++] = P_RETURN;return n;}static bool pause_disabled(int item) {diff --git a/games/celeste/src/plat_eadk.c b/games/celeste/src/plat_eadk.cindex a1b487c8..652d91fb 100644--- a/games/celeste/src/plat_eadk.c+++ b/games/celeste/src/plat_eadk.c@@ -33,6 +33,7 @@ uint32_t plat_keys(void) {if (k & (KEY(eadk_key_ok) | KEY(eadk_key_exe))) r |= K_OK;if (k & KEY(eadk_key_back)) r |= K_BACK; /* (menus: cancel) */if (k & KEY(eadk_key_backspace)) r |= K_PAUSE;+ if (k & KEY(eadk_key_var)) r |= K_JOURNAL; /* (Input.MenuJournal: only the cheat code reads it) */if (k & (KEY(eadk_key_home) | KEY(eadk_key_on_off))) r |= K_HOME;if (k) r |= K_ANY;return r;diff --git a/games/celeste/src/save.c b/games/celeste/src/save.cindex c7b057a8..f4e43e7f 100644--- a/games/celeste/src/save.c+++ b/games/celeste/src/save.c@@ -115,6 +115,7 @@ void save_load(void) {memset(&g_save, 0, sizeof g_save);if (p && len <= sizeof g_save) memcpy(&g_save, p, len); /* the record is not aligned: copy it */if (!(p && whole(len)) && !restore_copy()) save_new();+ if (g_save.cheat_mode) g_save.unlocked_areas = AREAS - 1; /* SaveData.AfterInitialize: MaxArea */if (!g_save.binds_set) { /* 1.6.0's keys: what was on backspace (pause now) goes to Back, as the defaults did */for (int a = 0; a < 4; a++)if (g_save.bind[a] == KEY_BACKSPACE) g_save.bind[a] = KEY_BACK;@@ -281,6 +282,22 @@ void session_start(int chapter, int checkpoint) {g_save.last_mode = s->mode;}+/* a session in any room (the room picker, in cheat mode), as the game's "load" command: from its checkpoint if it is+ * one, else from the start with the inventory the chapter ends with (rooms come in any order) */+void session_start_room(int chapter, int room) {+ const uint8_t *ch = chapter_at(chapter);+ int inv = ch[CH_INVENTORY], cp = -1;+ for (int i = 0; i < ch[CH_NCHECKPOINTS]; i++) {+ const uint8_t *c = ch + rd16(ch + CH_CHECKPOINTS) + 4 * i;+ if (rd16(c) == room) cp = i;+ if (c[2] != 255) inv = c[2];+ }+ session_start(chapter, cp);+ if (cp < 0) set_inventory(inv);+ g_session.level = (uint8_t)room;+ g_session.first_level = 0, g_session.started_from_beginning = 0;+}+/* Session.Restart(intoLevel) */void session_restart(int room) {Session old = g_session;diff --git a/games/celeste/tests/check.py b/games/celeste/tests/check.pyindex 16e83b53..ae24f1a9 100644--- a/games/celeste/tests/check.py+++ b/games/celeste/tests/check.py@@ -88,6 +88,18 @@ for old, new in (([4, 17, 16, 17], "4 5 16 5"), ([17, 16, 4, 29], "5 16 4 29")):check("keys " + new in out, f"the keys {old} of a 1.6.0 save did not become {new}: {out[-60:]}")shutil.rmtree(d, ignore_errors=True)+# the cheat code in the Prologue's room -1 (left, right, journal, grab, up, up, down, left, grab, confirm): cheat+# mode and every chapter; then the panel's room picker (6A, its 13th room)+d = tempfile.mkdtemp(prefix="celeste_check_")+run(["--chapter", "0", "--room", "-1", "--nowipe"], 400,+ "20-21:l,30-31:r,40-41:n,50-51:g,60-61:u,70-71:u,80-81:d,90-91:l,100-101:g,110-111:o", saves=d, what="the cheat code")+sav = open(d + "/celeste.sav", "rb").read() if os.path.exists(d + "/celeste.sav") else b""+check(len(sav) == 1680 and sav[1672] == 1 and sav[1066] == 10, "the cheat code did not turn cheat mode on")+out = run([], 700, "40-41:o,100-101:o,160-161:o," + ",".join("%d-%d:r" % (f, f + 1) for f in range(200, 360, 30))+ + ",380-381:o,420-421:u,440-441:o,470-471:d,490-491:d,510-511:r,540-541:o", saves=d, what="the room picker")+check("room 07 " in out and "area 6 mode 0" in out, f"the room picker did not start 6A in room 07: {out[-200:]}")+shutil.rmtree(d, ignore_errors=True)+# the pause menu: Retry is a deathout = run(["--chapter", "1", "--room", "1"], 300, "200-201:p,215-216:d,230-231:o", what="Retry from the pause menu")s = session(out)diff --git a/games/celeste/tests/play.c b/games/celeste/tests/play.cindex 9bc06a1b..e8997f04 100644--- a/games/celeste/tests/play.c+++ b/games/celeste/tests/play.c@@ -4,7 +4,7 @@* [--load F:ROOM:INTRO:FX:FY: at frame F, LoadLevel(INTRO) into ROOM at the spawn nearest (FX, FY) of it]* [--record A-B:DIR: every frame from A to B as DIR/NNNNN.ppm (for the README's GIFs)]* [--nowipe: no wipe into the room] [--cam X,Y: the view's top-left there (in the room) when drawn]- * keys: l r u d j(ump) x(dash) g(rab) p(ause) o(k) b(ack) */+ * keys: l r u d j(ump) x(dash) g(rab) p(ause) o(k) b(ack) n (journal) h(ome) */#include <stdio.h>#include <stdlib.h>#include <string.h>@@ -31,7 +31,9 @@ static uint32_t parse_keys(const char *s) {case 'j': k |= K_JUMP; break;case 'x': k |= K_DASH | K_TALK; break;case 'g': k |= K_GRAB; break;- case 'p': k |= K_PAUSE | K_BACK; break;+ case 'p': k |= K_PAUSE; break;+ case 'b': k |= K_BACK; break;+ case 'n': k |= K_JOURNAL; break;case 'o': k |= K_OK; break;case 'h': k |= K_HOME; break;}