From aa184f9fd27f5246ce38211f0af15809533a9cf3 Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Tue, 17 Nov 2026 10:35:49 +0300 Subject: [PATCH] A mod plugin the build has whose file is gone starts the rebuild, which goes back to a build without it (#845) Removing a plugin mod left its module in the layout: the loader skipped the missing file and the game ran, but the rebuild that drops the plugin never came. The loader counts layout plugins whose file no longer exists (ldr_plugins_gone) and rebuild_if_needed treats them like files waiting for the rebuild. A changed file was already pending through its mod's status line. On the 1.4.3 install: The Second Quest removed, the start asked for the rebuild, the setup lifted and compiled the no-plugin build in 30.5 s, the game reached gameplay. Co-Authored-By: Claude Opus 5.5 --- runtime/cheats.c | 13 +++++++------ runtime/host.h | 1 + runtime/loader.c | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/runtime/cheats.c b/runtime/cheats.c index 11991dc3..b96962c8 100644 --- a/runtime/cheats.c +++ b/runtime/cheats.c @@ -517,8 +517,9 @@ static void plain_name(char *s) { // ---- rebuild: code cheats and ExeFS patches the build lacks // The setup writes build-cache\rebuild.txt (installer/steps.py write_rebuild_command), the command that starts its // window in rebuild mode on this install folder, one argument per line. When an enabled mod has code cheats this build -// lacks (CHEAT_REBUILD) or ExeFS patch files it lacks (mods_exefs_pending), the game runs it and exits; the setup lifts -// and compiles them in and starts the game again. +// lacks (CHEAT_REBUILD) or ExeFS patch files it lacks (mods_exefs_pending), or the build has a mod plugin whose file is +// gone (ldr_plugins_gone: its mod was removed), the game runs it and exits; the setup lifts and compiles them in (or the +// plugin out) and starts the game again. // build-cache\rebuild.skip holds the key of the cheats a rebuild was started for: a rebuild that failed or was // cancelled leaves them unbuilt, and the same set does not start it again. TOTK_MODS_REBUILD=off never starts it. // Scripted runs (--seconds, --boot) never start it. @@ -532,7 +533,7 @@ static void rebuild_if_needed(const char *dir) { key = (key ^ fnv(c->info.key, strlen(c->info.key))) * 0x01000193u; key = (key ^ c->content) * 0x01000193u; } - int patches = mods_exefs_pending(&key); + int patches = mods_exefs_pending(&key) + ldr_plugins_gone(&key); if (!need && !patches) return; char cmd_path[PLAT_PATH_MAX + 64], skip_path[PLAT_PATH_MAX + 64], skip[16] = "", want[16]; snprintf(cmd_path, sizeof cmd_path, "%sbuild-cache" SEP "rebuild.txt", dir); @@ -548,7 +549,7 @@ static void rebuild_if_needed(const char *dir) { char *cmd = why ? NULL : read_text(cmd_path); if (!why && !cmd) why = "no build-cache/rebuild.txt (a build without the setup)"; if (why) { - rt_log("cheats: %d code cheats and %d ExeFS patch files are not built into the game; no rebuild: %s", need, + rt_log("cheats: %d code cheats and %d ExeFS patch files or plugins differ from the build; no rebuild: %s", need, patches, why); free(cmd); return; @@ -565,12 +566,12 @@ static void rebuild_if_needed(const char *dir) { } argv[argc] = NULL; if (argc < 2 || !plat_file_write(skip_path, want, strlen(want))) { - rt_log("cheats: %d code cheats and %d ExeFS patch files are not built into the game; cannot start the " + rt_log("cheats: %d code cheats and %d ExeFS patch files or plugins differ from the build; cannot start the " "rebuild (%s)", need, patches, cmd_path); free(cmd); return; } - rt_log("cheats: %d code cheats and %d ExeFS patch files are not built into the game; starting the rebuild: %s", + rt_log("cheats: %d code cheats and %d ExeFS patch files or plugins differ from the build; starting the rebuild: %s", need, patches, argv[0]); int ok = plat_spawn(argv, dir); free(cmd); diff --git a/runtime/host.h b/runtime/host.h index 8bb2804a..401ba3ec 100644 --- a/runtime/host.h +++ b/runtime/host.h @@ -211,6 +211,7 @@ extern GuestFn ldr_plugin_import; // set before ldr_loa // before an install's layout (recomp/layout.py) adds its mod plugins after sdk, so they do not use that MOD_COUNT. #define RT_MAX_MODULES 32 int ldr_count(void); +int ldr_plugins_gone(uint32_t *key); // layout plugins whose file is gone; mixes their paths into key const RtLoaded *ldr_module(int i); // order: main, subsdk0, sdk uint64_t ldr_symbol(const char *name); // exported definition, 0 if none uint64_t ldr_plt_stub(const char *module, const char *name); // PLT stub whose GOT slot holds name, 0 if none diff --git a/runtime/loader.c b/runtime/loader.c index b1911fe7..635d4313 100644 --- a/runtime/loader.c +++ b/runtime/loader.c @@ -86,12 +86,26 @@ static uint8_t *read_path_verified(const char *path, const char *want, size_t *l return p; } +// Mod plugins of the layout whose file is gone (their mod was removed): a rebuild without them is due (cheats.c +// rebuild_if_needed), keyed by their paths. +static int plugins_gone; +static uint32_t plugins_gone_key = 0x811C9DC5u; + +int ldr_plugins_gone(uint32_t *key) { + if (plugins_gone) *key = (*key ^ plugins_gone_key) * 0x01000193u; + return plugins_gone; +} + // 1 when the plugin file of lay is the one the build lifted; logged when not. static int plugin_file_ok(const RtLayoutEntry *lay) { size_t len; uint8_t *p = read_file(lay->file, &len); if (!p) { rt_log("loader: %s: cannot read %s; the plugin is left out", lay->name, lay->file); + if (!plat_file_exists(lay->file)) { + plugins_gone++; + for (const char *c = lay->file; *c; c++) plugins_gone_key = (plugins_gone_key ^ (uint8_t)*c) * 0x01000193u; + } return 0; } uint8_t d[32];