diff --git a/runtime/cfg.c b/runtime/cfg.c index b0fe439f..c2885148 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -43,7 +43,7 @@ static const char *const known[] = { "MENU_TEST_DIR", "MENU_TEST_SET", "MINIMAL_LAYOUT", "MIRROR_GAP", "MOTION", "MOUSE_SENS", "MOVIE_HOST", "MOVIE_PACE", "ONE_PER_CORE", "OPERATION_MODE", "OUTPUT_RES", "PAD_LAYOUT", "PATCH_OUTPUT", "PATCH_SCENE", "PERF_OVERLAY", "PERF_SLOW_MS", "PIPELINE_CACHE", "PIPE_MEMO", "PIPE_PREBUILD", "PIPE_SKIP", "PIPE_SYNC", "PIPE_WAIT", "PREWARM_XLATE", "PROBE_MOVIE", "PROBE_MOVIE_SHOT", "PROFILE", "PROFILE_CHAINS", "PROFILE_DIR", "PROFILE_FRAMES", - "PROFILE_MAIN", "PROFILE_RENDER", "PUSH_SKIP", "PUSH_STAGE", "RDOC", "RDOC_DIR", "RDOC_DLL", "REALTIME", "REC_END", "REEXEC", + "PROFILE_MAIN", "PROFILE_RENDER", "PROMPTS", "PUSH_SKIP", "PUSH_STAGE", "RDOC", "RDOC_DIR", "RDOC_DLL", "REALTIME", "REC_END", "REEXEC", "RENDER_SCALE", "REPLAY_ASYNC", "REPLAY_CHECK", "RESOLVE_CHECK", "ROMFS", "ROMFS_INDEX", "ROMFS_MMAP", "ROMFS_MODS", "ROMFS_PATCHES", "ROMFS_PROOF_DIR", "ROMFS_VERIFY", "RUMBLE", "RUMBLE_CURVE", "RUMBLE_STRENGTH", "RUMBLE_TRIGGERS", "SHADER_CACHE", @@ -63,7 +63,8 @@ static const struct { const char *key, *section; } sections[] = { {"MENU_LANG", "language"}, {"LANG", "language"}, {"OPERATION_MODE", "language"}, {"VOLUME", "audio"}, {"MOTION", "input"}, {"RUMBLE_STRENGTH", "input"}, {"RUMBLE_CURVE", "input"}, {"RUMBLE_TRIGGERS", "input"}, - {"PAD_LAYOUT", "input"}, {"STICK_DEADZONE", "input"}, {"MOUSE_SENS", "input"}, {"INPUT_RECORD", "input"}, + {"PAD_LAYOUT", "input"}, {"PROMPTS", "input"}, {"STICK_DEADZONE", "input"}, {"MOUSE_SENS", "input"}, + {"INPUT_RECORD", "input"}, {"BIND_A", "input"}, {"BIND_B", "input"}, {"BIND_X", "input"}, {"BIND_Y", "input"}, {"BIND_LCLICK", "input"}, {"BIND_RCLICK", "input"}, {"BIND_L", "input"}, {"BIND_R", "input"}, {"BIND_ZL", "input"}, {"BIND_ZR", "input"}, {"BIND_PLUS", "input"}, {"BIND_MINUS", "input"}, {"BIND_LEFT", "input"}, {"BIND_UP", "input"}, @@ -105,7 +106,8 @@ static const CfgMeta metas[] = { // Sound, Controls, Menu {"VOLUME", "100", "0..100", LIVE}, {"MOTION", "1", "0|1", LIVE}, {"RUMBLE_STRENGTH", "130", "0..300", LIVE}, {"RUMBLE_CURVE", "0.6", "0.2..1.5", LIVE}, - {"RUMBLE_TRIGGERS", "0", "0|1", LIVE}, {"PAD_LAYOUT", "auto", "auto|nintendo|xbox|xbox_prompts", LIVE}, + {"RUMBLE_TRIGGERS", "0", "0|1", LIVE}, {"PAD_LAYOUT", "auto", "auto|nintendo|xbox", LIVE}, + {"PROMPTS", "nintendo", "nintendo|xbox", RESTART}, {"STICK_DEADZONE", "8", "0..50", LIVE}, {"MOUSE_SENS", "1", "0..10", LIVE}, {"MENU_LANG", "", "en|ru", LIVE}, // Advanced: scheduling @@ -174,6 +176,24 @@ static void add(char *key, char *value, int line) { entries[n_entries++] = (CfgEntry){_strdup(key), _strdup(value), 0, 0}; } +// 0.1.9 had the Xbox prompts as a pad layout: pad_layout = xbox_prompts is pad_layout = nintendo with prompts = xbox. +// Read as those two, which the menu shows and the next cfg_save writes; a prompts line of the file's own wins. The +// value still works from the environment (input_pad_layout_pick, input_prompts_pick). +static void migrate(void) { + CfgEntry *layout = NULL, *prompts = NULL; + for (int i = 0; i < n_entries; i++) { + if (!strcmp(entries[i].key, "PAD_LAYOUT")) layout = &entries[i]; + if (!strcmp(entries[i].key, "PROMPTS")) prompts = &entries[i]; + } + if (!layout || _stricmp(layout->value, "xbox_prompts")) return; + free(layout->value); + layout->value = _strdup("nintendo"); + layout->dirty = 1; + if (!prompts && n_entries < CFG_MAX_KEYS) entries[n_entries++] = (CfgEntry){_strdup("PROMPTS"), _strdup("xbox"), 1, 0}; + rt_log("cfg: totk.ini pad_layout = xbox_prompts is read as pad_layout = nintendo and prompts = %s", + prompts ? prompts->value : "xbox"); +} + int cfg_load(const char *path) { clear(); uint64_t size = 0; @@ -197,6 +217,7 @@ int cfg_load(const char *path) { p = eol + 1; } free(data); + migrate(); return 1; } diff --git a/runtime/cfg_probe.c b/runtime/cfg_probe.c index c1318ce0..d4a7f170 100644 --- a/runtime/cfg_probe.c +++ b/runtime/cfg_probe.c @@ -279,7 +279,30 @@ int probe_cfg(void) { "pad layout: a set layout wins over the labels"); CHECK(input_pad_layout_pick("xbox_prompts", 0) == PAD_LAYOUT_NINTENDO && input_pad_layout_pick("Xbox_Prompts", 1) == PAD_LAYOUT_NINTENDO, - "pad layout: Xbox prompts keep the Nintendo positions (only the prompts change, romfs.c overlay_init)"); + "pad layout: 0.1.9's xbox_prompts keeps the Nintendo positions (only the prompts change, romfs.c overlay_init)"); + // Button prompts (input_map.c) + CHECK(input_prompts_pick(NULL, "auto") == PROMPTS_NINTENDO && input_prompts_pick("", "xbox") == PROMPTS_NINTENDO && + input_prompts_pick("Xbox", "nintendo") == PROMPTS_XBOX && input_prompts_pick("nintendo", "xbox") == PROMPTS_NINTENDO, + "prompts: the game's own unless set to Xbox"); + CHECK(input_prompts_pick(NULL, "xbox_prompts") == PROMPTS_XBOX && input_prompts_pick("nintendo", "xbox_prompts") == PROMPTS_NINTENDO, + "prompts: 0.1.9's pad_layout = xbox_prompts means Xbox while prompts is unset"); + CHECK(!input_prompts_folder(PROMPTS_NINTENDO, "nintendo") && !input_prompts_folder(PROMPTS_NINTENDO, "xbox"), + "prompts: the game's own need no folder"); + CHECK(EQ(input_prompts_folder(PROMPTS_XBOX, "nintendo"), "romfs-patches-xbox") && + EQ(input_prompts_folder(PROMPTS_XBOX, "xbox_prompts"), "romfs-patches-xbox") && + EQ(input_prompts_folder(PROMPTS_XBOX, "xbox"), "romfs-patches-xbox-label") && + EQ(input_prompts_folder(PROMPTS_XBOX, "auto"), "romfs-patches-xbox-label") && + EQ(input_prompts_folder(PROMPTS_XBOX, NULL), "romfs-patches-xbox-label"), + "prompts: the face buttons by position for the Nintendo layout, by label for xbox and auto"); + // romfs-patches-xbox shows A as B (tests/romfs_prompts_test.py checks the folders' contents). It is right exactly + // where the layout puts A on the east button, which an Xbox pad labels B. + input_map_reset(); + static const char *const layouts[] = {"nintendo", "xbox", "auto", "xbox_prompts"}; + for (int i = 0; i < 4; i++) { + int a_east = input_map_pad_buttons((uint8_t[PAD_COUNT]){[PAD_EAST] = 1}, input_pad_layout_pick(layouts[i], 0)) == 1ull << B_A; + CHECK(a_east == EQ(input_prompts_folder(PROMPTS_XBOX, layouts[i]), "romfs-patches-xbox"), + "prompts: the folder names A as B exactly when the layout puts A on the button labelled B"); + } uint8_t pd[PAD_COUNT] = {0}; pd[PAD_SOUTH] = pd[PAD_NORTH] = 1; CHECK(input_map_pad_buttons(pd, PAD_LAYOUT_NINTENDO) == (1ull << B_B | 1ull << B_X) && @@ -370,6 +393,24 @@ int probe_cfg(void) { _putenv_s("TOTK_FREE_CORES", "1"); CHECK(cfg_bool("TOTK_FREE_CORES") == 1, "free_cores 1: on"); _putenv_s("TOTK_FREE_CORES", ""); + // 0.1.9's pad_layout = xbox_prompts (cfg.c migrate): read as the Nintendo layout with the Xbox prompts, saved so + _putenv_s("TOTK_PAD_LAYOUT", ""); + _putenv_s("TOTK_PROMPTS", ""); + static const char old_layout[] = "[input]\r\npad_layout = xbox_prompts\r\n"; + CHECK(plat_file_write(path, old_layout, sizeof old_layout - 1) && cfg_load(path) == 1 && + EQ(cfg_get("TOTK_PAD_LAYOUT"), "nintendo") && EQ(cfg_get("TOTK_PROMPTS"), "xbox"), + "0.1.9's pad_layout = xbox_prompts reads as nintendo with prompts = xbox"); + CHECK(cfg_save_to(path) == 1, "the read pad layout and prompts save"); + uint64_t saved_n = 0; + char *saved = (char *)plat_file_read(path, &saved_n); + CHECK(saved && strstr(saved, "pad_layout = nintendo") && strstr(saved, "prompts = xbox") && !strstr(saved, "xbox_prompts"), + "the next save writes the pad layout and the prompts"); + free(saved); + static const char old_layout_own[] = "[input]\r\npad_layout = xbox_prompts\r\nprompts = nintendo\r\n"; + CHECK(plat_file_write(path, old_layout_own, sizeof old_layout_own - 1) && cfg_load(path) == 1 && + EQ(cfg_get("TOTK_PAD_LAYOUT"), "nintendo") && EQ(cfg_get("TOTK_PROMPTS"), "nintendo"), + "a prompts line of the file's own wins over 0.1.9's pad_layout = xbox_prompts"); + plat_file_delete(path); cfg_load("cfg-probe-missing.ini"); int listed = 0; for (int i = 0; cfg_meta_at(i); i++) { diff --git a/runtime/fs.h b/runtime/fs.h index 8584959b..4104faf3 100644 --- a/runtime/fs.h +++ b/runtime/fs.h @@ -38,8 +38,14 @@ uint64_t romfs_file_count(void); // files in the index const char *romfs_entry(uint64_t i, uint64_t *offset, uint64_t *size); // path, image offset and size of index row i const char *romfs_image_path(void); // the romfs.bin path fs_init opened size_t romfs_overlay_count(void); -int romfs_xbox_prompts_ready(void); // romfs-patches-xbox was there at start -int romfs_xbox_prompts_active(void); // and was loaded (pad_layout = xbox_prompts at start) +// The button prompts (input_prompts_folder): the folder loaded at start, NULL for the game's own prompts; whether a +// folder had a manifest at start; and why the folder the settings asked for at start was not loaded (ROMFS_PROMPTS_OK +// for any other folder: it was not asked for). +enum { ROMFS_PROMPTS_OK, ROMFS_PROMPTS_MISSING, ROMFS_PROMPTS_FAILED, ROMFS_PROMPTS_WIDE, ROMFS_PROMPTS_MODS, + ROMFS_PROMPTS_PATCHES }; +const char *romfs_prompts(void); +int romfs_prompts_ready(const char *folder); +int romfs_prompts_off(const char *folder); const char *romfs_overlay(size_t k, const char **file, uint64_t *size, int *is_added); // RomFS path of overlay k void fs_trace(const char *what, const char *path); // TOTK_TRACE=fs: one line per open diff --git a/runtime/input_map.c b/runtime/input_map.c index 1ae7e4a3..589446af 100644 --- a/runtime/input_map.c +++ b/runtime/input_map.c @@ -288,6 +288,18 @@ int input_pad_layout_pick(const char *setting, int east_labelled_a) { return east_labelled_a ? PAD_LAYOUT_NINTENDO : PAD_LAYOUT_XBOX; } +int input_prompts_pick(const char *prompts, const char *pad_layout) { + if (prompts && *prompts) return !_stricmp(prompts, "xbox") ? PROMPTS_XBOX : PROMPTS_NINTENDO; + return pad_layout && !_stricmp(pad_layout, "xbox_prompts") ? PROMPTS_XBOX : PROMPTS_NINTENDO; +} + +const char *input_prompts_folder(int prompts, const char *pad_layout) { + if (prompts != PROMPTS_XBOX) return NULL; + // The folders are read at start, before a pad is open: auto counts as Xbox, as for a pad without Nintendo labels. + // A Nintendo-labelled pad under auto plays by label too (its A is on the button labelled A), so it matches as well. + return input_pad_layout_pick(pad_layout, 0) == PAD_LAYOUT_NINTENDO ? "romfs-patches-xbox" : "romfs-patches-xbox-label"; +} + uint64_t input_map_pad_buttons(const uint8_t down[PAD_COUNT], int layout) { const PadBinding *t = input_map.pads[layout]; uint64_t b = 0; diff --git a/runtime/input_map.h b/runtime/input_map.h index 6e66b4ab..545eae89 100644 --- a/runtime/input_map.h +++ b/runtime/input_map.h @@ -80,11 +80,23 @@ int input_map_bind(const char *button, const char *list); // Applies the TOTK_BIND_ settings (cfg_get) over the defaults: at start, and again when one of them changes. void input_map_configure(void); -// The layout for a TOTK_PAD_LAYOUT value: "nintendo" or "xbox" (any case); "xbox_prompts" is the Nintendo layout with -// the A/B and X/Y prompts swapped (runtime/romfs.c overlay_init), so the buttons map as "nintendo". Anything else -// ("auto", NULL) picks Nintendo when the pad's east button is labelled A (a Switch Pro Controller, a GuliKit) and Xbox -// otherwise. +// The layout for a TOTK_PAD_LAYOUT value: "nintendo" or "xbox" (any case); "xbox_prompts", 0.1.9's name for the Nintendo +// layout with the Xbox prompts, maps the buttons as "nintendo". Anything else ("auto", NULL) picks Nintendo when the +// pad's east button is labelled A (a Switch Pro Controller, a GuliKit) and Xbox otherwise. int input_pad_layout_pick(const char *setting, int east_labelled_a); + +// Button prompts (TOTK_PROMPTS): the controller whose buttons the game's prompts show. Nintendo: the game's own. Xbox: +// LB RB LT RT, Menu, View and a d-pad cross for the other buttons, and the face buttons named by the label of the +// button the pad layout presses (runtime/romfs.c overlay_init, tools/make_romfs_patches.py --prompts). +enum { PROMPTS_NINTENDO, PROMPTS_XBOX }; +// The prompts for a TOTK_PROMPTS value ("nintendo" or "xbox", any case). Unset or empty: Xbox while the pad layout +// setting is "xbox_prompts", else Nintendo. +int input_prompts_pick(const char *prompts, const char *pad_layout); +// The folder next to romfs-index.bin that holds those prompts for a TOTK_PAD_LAYOUT value, NULL for the game's own. The +// Nintendo layout plays an Xbox pad by position, so its folder names the face buttons the other way round +// (romfs-patches-xbox: the right button does A and is labelled B); xbox and auto put every Switch button on the button +// labelled with its letter (auto picks the layout per pad by its labels), so they share romfs-patches-xbox-label. +const char *input_prompts_folder(int prompts, const char *pad_layout); // down[pad] != 0 for the gamepad inputs held. Returns the Switch button bits (0..15) the layout's pad table presses. uint64_t input_map_pad_buttons(const uint8_t down[PAD_COUNT], int layout); diff --git a/runtime/romfs.c b/runtime/romfs.c index b5c73c09..095482f4 100644 --- a/runtime/romfs.c +++ b/runtime/romfs.c @@ -26,6 +26,7 @@ #include "cfg.h" #include "fs.h" #include "host.h" +#include "input_map.h" #include "romfs_config.h" #include "romfs_path.h" @@ -423,23 +424,56 @@ static void heapdef_overlay(void) { res_heapdef_served(); } -static int xbox_prompts_ready; // romfs-patches-xbox/manifest.tsv was next to romfs-index.bin at start -static int xbox_prompts_active; // and overlay_init loaded it +// The button prompts' folders (input_prompts_folder) and whether each had a manifest next to romfs-index.bin at start; +// the one the settings asked for at start, the one overlay_init loaded (NULL: the game's own prompts) and why the first +// did not load (ROMFS_PROMPTS_*). The menu compares them with the settings in effect (ui/menu.cpp prompts_note). +static struct { const char *name; int ready; } prompts_folders[2]; +static const char *prompts_wanted, *prompts_loaded; +static int prompts_off; -int romfs_xbox_prompts_ready(void) { return xbox_prompts_ready; } -int romfs_xbox_prompts_active(void) { return xbox_prompts_active; } +const char *romfs_prompts(void) { return prompts_loaded; } + +int romfs_prompts_ready(const char *folder) { + for (int i = 0; i < 2; i++) + if (folder && prompts_folders[i].name && !strcmp(prompts_folders[i].name, folder)) return prompts_folders[i].ready; + return 0; +} + +int romfs_prompts_off(const char *folder) { + return folder && prompts_wanted && !strcmp(folder, prompts_wanted) ? prompts_off : ROMFS_PROMPTS_OK; +} + +// The first RomFS file that the overlays [a, b) and [c, d) both replace, or NULL. +static const char *overlay_clash(size_t a, size_t b, size_t c, size_t d) { + for (size_t i = a; i < b; i++) + for (size_t j = c; j < d; j++) + if (overlays[i].index != ADDED && overlays[i].index == overlays[j].index) return overlays[i].name; + return NULL; +} + +// Drops the overlays [a, b), the ones after them moving down. +static void overlay_drop(size_t a, size_t b) { + for (size_t k = a; k < b; k++) { + free((void *)overlays[k].path); + free((void *)overlays[k].name); + } + memmove(overlays + a, overlays + b, (noverlay - b) * sizeof *overlays); + noverlay -= b - a; +} static void overlay_init(void) { // TOTK_ROMFS_PATCHES unset: romfs-patches next to romfs-index.bin if it has a manifest (tools/make_romfs_patches.py). // A game resolution that is not 16:9 takes romfs-patches-x instead when it is there: the same overlay with // the UI laid out for that shape (make_romfs_patches.py --aspect). 1.2.1 has no camera aspect patch, so it keeps // the 16:9 layout (res_wants_wide_overlay). - // With pad_layout = xbox_prompts, romfs-patches-xbox in its place: the same patches with the A/B and X/Y prompts - // swapped (make_romfs_patches.py --xbox-prompts). The game reads the archives once at boot, so the prompts stay - // until restart even though the layout itself changes live. Each folder replaces romfs-patches as a whole and the - // setup builds no wide folder with Xbox prompts, so a wide game resolution keeps the Switch prompts. - char def[2100], xbox[2100]; - const char *patches = cfg_get("TOTK_ROMFS_PATCHES"); + // With prompts = xbox, the Xbox prompts' folder for the pad layout in its place (input_prompts_folder): the same + // patches with Xbox button icons (make_romfs_patches.py --prompts). The game reads the archives once at boot, so + // the prompts stay until restart even though the layout itself changes live. Each folder replaces romfs-patches as + // a whole and the setup builds no wide folder with Xbox prompts, so a wide game resolution keeps the Switch + // prompts. So does a RomFS mod that replaces one of the prompts' files (the fonts, the resource size table): + // romfs-patches loads in their place, where two overlays replacing one file would stop the game. + char def[2100], path[2100]; + const char *patches = cfg_get("TOTK_ROMFS_PATCHES"), *mods = cfg_get("TOTK_ROMFS_MODS"); int wide = 0; unsigned out[2]; res_wanted(out); @@ -453,29 +487,54 @@ static void overlay_init(void) { "(tools/make_romfs_patches.py --aspect %ux%u)", out[0], out[1], out[0], out[1]); } } - xbox_prompts_ready = - snprintf(xbox, sizeof xbox, "%s/romfs-patches-xbox/manifest.tsv", index_dir) < (int)sizeof xbox && - GetFileAttributesA(xbox) != INVALID_FILE_ATTRIBUTES; - int want_xbox = !_stricmp(cfg_value("TOTK_PAD_LAYOUT"), "xbox_prompts"); - if (!patches && want_xbox && xbox_prompts_ready) { - xbox[strlen(xbox) - strlen("/manifest.tsv")] = 0; - xbox_prompts_active = overlay_load(xbox, 1); - if (xbox_prompts_active) rt_log("RomFS overlay: Xbox button prompts (%s)", xbox); - else rt_log("RomFS overlay: %s failed its check (run the setup again); romfs-patches loads instead", xbox); - } else if (want_xbox) { - rt_log("RomFS overlay: pad_layout = xbox_prompts, but %s; Switch prompts stay", - wide ? "the game resolution takes the wide UI layout" - : patches ? "TOTK_ROMFS_PATCHES is set" - : "romfs-patches-xbox has no manifest.tsv (run the setup again)"); + static const char *const layouts[2] = {"nintendo", "xbox"}; // one of each folder + for (int i = 0; i < 2; i++) { + prompts_folders[i].name = input_prompts_folder(PROMPTS_XBOX, layouts[i]); + prompts_folders[i].ready = + snprintf(path, sizeof path, "%s/%s/manifest.tsv", index_dir, prompts_folders[i].name) < (int)sizeof path && + GetFileAttributesA(path) != INVALID_FILE_ATTRIBUTES; } - if (!patches && !xbox_prompts_active && snprintf(def, sizeof def, "%s/romfs-patches/manifest.tsv", index_dir) < (int)sizeof def && - GetFileAttributesA(def) != INVALID_FILE_ATTRIBUTES) { - def[strlen(def) - strlen("/manifest.tsv")] = 0; - patches = def; + const char *layout = cfg_value("TOTK_PAD_LAYOUT"); + prompts_wanted = input_prompts_folder(input_prompts_pick(cfg_get("TOTK_PROMPTS"), layout), layout); + prompts_off = !prompts_wanted ? ROMFS_PROMPTS_OK + : wide ? ROMFS_PROMPTS_WIDE + : patches ? ROMFS_PROMPTS_PATCHES + : !romfs_prompts_ready(prompts_wanted) ? ROMFS_PROMPTS_MISSING + : ROMFS_PROMPTS_OK; + size_t first = noverlay; + if (prompts_wanted && prompts_off == ROMFS_PROMPTS_OK) { + snprintf(path, sizeof path, "%s/%s", index_dir, prompts_wanted); // fits: its manifest path did + if (overlay_load(path, 1)) { + prompts_loaded = prompts_wanted; + rt_log("RomFS overlay: Xbox button prompts (%s)", path); + } else { + prompts_off = ROMFS_PROMPTS_FAILED; + rt_log("RomFS overlay: %s failed its check (run the setup again); romfs-patches loads instead", path); + } + } else if (prompts_wanted) { + rt_log("RomFS overlay: prompts = xbox, but %s; Switch prompts stay", + prompts_off == ROMFS_PROMPTS_WIDE ? "the game resolution takes the wide UI layout" + : prompts_off == ROMFS_PROMPTS_PATCHES ? "TOTK_ROMFS_PATCHES is set" + : "their folder has no manifest.tsv (run the setup again)"); + } + size_t prompts_end = noverlay; + char plain[2100]; // romfs-patches, when it has a manifest + int plain_ok = snprintf(plain, sizeof plain, "%s/romfs-patches/manifest.tsv", index_dir) < (int)sizeof plain && + GetFileAttributesA(plain) != INVALID_FILE_ATTRIBUTES; + if (plain_ok) plain[strlen(plain) - strlen("/manifest.tsv")] = 0; + if (!patches && !prompts_loaded && plain_ok) patches = plain; + if (patches && *patches && strcmp(patches, "0")) overlay_load(patches, 0); + size_t mods_first = noverlay; + if (mods && *mods && strcmp(mods, "0")) overlay_load(mods, 0); + const char *clash = prompts_loaded ? overlay_clash(first, prompts_end, mods_first, noverlay) : NULL; + if (clash) { + rt_log("RomFS overlay: the RomFS mods folder replaces %s, which the Xbox prompts change too; Switch prompts stay", + clash); + overlay_drop(first, prompts_end); + prompts_loaded = NULL; + prompts_off = ROMFS_PROMPTS_MODS; + if (plain_ok) overlay_load(plain, 0); } - const char *dirs[2] = {patches, cfg_get("TOTK_ROMFS_MODS")}; - for (int i = 0; i < 2; i++) - if (dirs[i] && *dirs[i] && strcmp(dirs[i], "0")) overlay_load(dirs[i], 0); heapdef_overlay(); added_init(); if (noverlay) qsort(overlays, noverlay, sizeof *overlays, overlay_order); diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index 957a2d60..ab4f9477 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -24,6 +24,7 @@ extern "C" { #include "cfg.h" +#include "fs.h" #include "input.h" #include "input_map.h" #include "perfmon.h" @@ -38,9 +39,6 @@ void vk_queue_unlock(void); void res_sizes(unsigned out[2], unsigned scene[2]); double frame_step_limit_hz(void); extern const int rt_game_version; -// fs.h (romfs.c): romfs-patches-xbox was next to romfs-index.bin at start, and was loaded. -int romfs_xbox_prompts_ready(void); -int romfs_xbox_prompts_active(void); extern const char rt_port_version[]; } @@ -563,14 +561,8 @@ static void tab_sound(float scale) { opt_end(); } -// The note under the layout. Xbox prompts (the Nintendo layout with the A/B and X/Y prompts swapped, romfs.c -// overlay_init) change the buttons at once but the prompts only at the next start: "files missing" without -// romfs-patches-xbox, "prompts change after restart" while the prompts in use differ from the choice. Automatic with a -// gamepad connected: "in use: Xbox". NULL otherwise. +// The note under the layout: Automatic with a gamepad connected, the layout it picked ("in use: Xbox"). NULL otherwise. static const char *pad_layout_note(void) { - bool want = !_stricmp(cfg_value("TOTK_PAD_LAYOUT"), "xbox_prompts"); - if (want && !romfs_xbox_prompts_ready()) return menu_text(UI_MENU_PAD_LAYOUT_PROMPTS_MISSING); - if (want != (romfs_xbox_prompts_active() != 0)) return menu_text(UI_MENU_PAD_LAYOUT_PROMPTS_RESTART); int got = input_pad_layout(); if (got < 0 || strcmp(cfg_value("TOTK_PAD_LAYOUT"), "auto")) return nullptr; static char note[96]; @@ -579,11 +571,32 @@ static const char *pad_layout_note(void) { return note; } +// The note under the prompts. The settings name a folder of prompts (input_prompts_folder: the prompts and the pad +// layout, as a layout that puts A on the right button needs the face buttons named the other way round), but the game +// reads its fonts and UI archive once at start (romfs.c overlay_init). While the folder in use differs: "files +// missing" when the setup did not write the one asked for, why it was left out at start (damaged, a wide game +// resolution, a RomFS mod with the same files, TOTK_ROMFS_PATCHES), else "prompts change after restart". NULL when +// they match. +static const char *prompts_note(void) { + const char *layout = cfg_value("TOTK_PAD_LAYOUT"), *used = romfs_prompts(); + const char *want = input_prompts_folder(input_prompts_pick(cfg_get("TOTK_PROMPTS"), layout), layout); + if (want == used || (want && used && !strcmp(want, used))) return nullptr; + if (want && !romfs_prompts_ready(want)) return menu_text(UI_MENU_PROMPTS_MISSING); + switch (romfs_prompts_off(want)) { + case ROMFS_PROMPTS_FAILED: return menu_text(UI_MENU_PROMPTS_FAILED); + case ROMFS_PROMPTS_WIDE: return menu_text(UI_MENU_PROMPTS_OFF_WIDE); + case ROMFS_PROMPTS_MODS: return menu_text(UI_MENU_PROMPTS_OFF_MODS); + case ROMFS_PROMPTS_PATCHES: return menu_text(UI_MENU_PROMPTS_OFF_PATCHES); + default: return menu_text(UI_MENU_PROMPTS_RESTART); + } +} + static void tab_controls(float scale) { opt_begin("##controls", scale); - static const UiTextId layout[] = {UI_MENU_PAD_LAYOUT_AUTO, UI_MENU_PAD_LAYOUT_NINTENDO, UI_MENU_PAD_LAYOUT_XBOX, - UI_MENU_PAD_LAYOUT_XBOX_PROMPTS}; - opt_choice("TOTK_PAD_LAYOUT", UI_MENU_PAD_LAYOUT, layout, 4, UI_MENU_PAD_LAYOUT_DESC, pad_layout_note()); + static const UiTextId layout[] = {UI_MENU_PAD_LAYOUT_AUTO, UI_MENU_PAD_LAYOUT_NINTENDO, UI_MENU_PAD_LAYOUT_XBOX}; + opt_choice("TOTK_PAD_LAYOUT", UI_MENU_PAD_LAYOUT, layout, 3, UI_MENU_PAD_LAYOUT_DESC, pad_layout_note()); + static const UiTextId prompts[] = {UI_MENU_PROMPTS_NINTENDO, UI_MENU_PROMPTS_XBOX}; + opt_choice("TOTK_PROMPTS", UI_MENU_PROMPTS, prompts, 2, UI_MENU_PROMPTS_DESC, prompts_note()); opt_toggle("TOTK_MOTION", UI_MENU_MOTION, UI_MENU_MOTION_DESC); opt_slider("TOTK_RUMBLE_STRENGTH", UI_MENU_RUMBLE_STRENGTH, 0, 300, UI_MENU_RUMBLE_STRENGTH_DESC, 10, "%.0f %%"); opt_slider("TOTK_RUMBLE_CURVE", UI_MENU_RUMBLE_CURVE, 0.2f, 1.5f, UI_MENU_RUMBLE_CURVE_DESC, 0.05f, "%.2f"); diff --git a/runtime/ui_text.c b/runtime/ui_text.c index deaa3f5a..83964e10 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -103,15 +103,25 @@ static const char *const text_en[UI_TEXT_COUNT] = { [UI_MENU_PAD_LAYOUT] = "Button layout", [UI_MENU_PAD_LAYOUT_DESC] = "Which button is A. Nintendo: the right one, as on a Switch. Xbox: the bottom one, as " "labelled on an Xbox controller (cross on a PlayStation controller). Automatic picks " - "Nintendo for controllers with Nintendo labels and Xbox for the others. Xbox prompts: " - "A is the right one as with Nintendo, and the game shows the Xbox labels (B for A, A " - "for B, Y for X, X for Y); the prompts change after a restart. The letters are part of the " - "game's files, so a button you remap in Controls keeps the old letter on screen.", + "Nintendo for controllers with Nintendo labels and Xbox for the others. Which " + "controller the game's prompts show is set under Button prompts.", [UI_MENU_PAD_LAYOUT_AUTO] = "Automatic", [UI_MENU_PAD_LAYOUT_NINTENDO] = "Nintendo (A right)", - [UI_MENU_PAD_LAYOUT_XBOX] = "Xbox (A bottom)", [UI_MENU_PAD_LAYOUT_XBOX_PROMPTS] = "Xbox prompts (A right)", + [UI_MENU_PAD_LAYOUT_XBOX] = "Xbox (A bottom)", [UI_MENU_PAD_LAYOUT_IN_USE] = "in use: %s", - [UI_MENU_PAD_LAYOUT_PROMPTS_MISSING] = "prompt files missing: run the setup again", - [UI_MENU_PAD_LAYOUT_PROMPTS_RESTART] = "prompts change after restart", + [UI_MENU_PROMPTS] = "Button prompts", + [UI_MENU_PROMPTS_DESC] = "Which controller's buttons the game's prompts show. Nintendo: the game's own. Xbox: LB, " + "RB, LT, RT, Menu, View and a d-pad cross, and A, B, X and Y as labelled on the button " + "the layout above presses (with Nintendo (A right) the right button is labelled B, so the " + "prompts for A show B). The game reads its prompts at start, so they change after a " + "restart. They are part of the game's files, so a button you remap in Controls keeps its " + "old prompt on screen.", + [UI_MENU_PROMPTS_NINTENDO] = "Nintendo", [UI_MENU_PROMPTS_XBOX] = "Xbox", + [UI_MENU_PROMPTS_MISSING] = "prompt files missing: run the setup again", + [UI_MENU_PROMPTS_FAILED] = "prompt files damaged: run the setup again", + [UI_MENU_PROMPTS_RESTART] = "prompts change after restart", + [UI_MENU_PROMPTS_OFF_WIDE] = "off with a wide game resolution", + [UI_MENU_PROMPTS_OFF_MODS] = "off: a RomFS mod replaces their files", + [UI_MENU_PROMPTS_OFF_PATCHES] = "off while TOTK_ROMFS_PATCHES is set", [UI_MENU_STICK_DEADZONE] = "Stick dead zone", [UI_MENU_STICK_DEADZONE_DESC] = "How far a gamepad stick moves before the game sees it. Raise it if the character or the camera moves on its own.", [UI_MENU_MOUSE_SENS] = "Mouse camera sensitivity", @@ -344,16 +354,25 @@ static const char *const text_ru[UI_TEXT_COUNT] = { [UI_MENU_PAD_LAYOUT] = "Раскладка кнопок", [UI_MENU_PAD_LAYOUT_DESC] = "Какая кнопка работает как A. Nintendo: правая, как на Switch. Xbox: нижняя, как " "подписано на контроллере Xbox (крест на контроллере PlayStation). Автоматически: " - "Nintendo для контроллеров с подписями Nintendo, Xbox для остальных. Подсказки Xbox: " - "A справа, как в Nintendo, а игра показывает надписи Xbox (B вместо A, A вместо B, Y " - "вместо X, X вместо Y); подсказки меняются после перезапуска. Буквы записаны в файлах " - "игры, поэтому у кнопки, переназначенной на вкладке управления, на экране остаётся " - "прежняя буква.", + "Nintendo для контроллеров с подписями Nintendo, Xbox для остальных. Кнопки какого " + "контроллера показывают подсказки игры, задаётся в строке «Подсказки кнопок».", [UI_MENU_PAD_LAYOUT_AUTO] = "Автоматически", [UI_MENU_PAD_LAYOUT_NINTENDO] = "Nintendo (A справа)", - [UI_MENU_PAD_LAYOUT_XBOX] = "Xbox (A снизу)", [UI_MENU_PAD_LAYOUT_XBOX_PROMPTS] = "Подсказки Xbox (A справа)", + [UI_MENU_PAD_LAYOUT_XBOX] = "Xbox (A снизу)", [UI_MENU_PAD_LAYOUT_IN_USE] = "сейчас: %s", - [UI_MENU_PAD_LAYOUT_PROMPTS_MISSING] = "нет файлов подсказок: запустите установку снова", - [UI_MENU_PAD_LAYOUT_PROMPTS_RESTART] = "подсказки сменятся после перезапуска", + [UI_MENU_PROMPTS] = "Подсказки кнопок", + [UI_MENU_PROMPTS_DESC] = "Кнопки какого контроллера показывают подсказки игры. Nintendo: как в самой игре. Xbox: " + "LB, RB, LT, RT, Menu, View и крестовина, а A, B, X и Y подписаны так же, как кнопка, " + "которую нажимает раскладка выше (в Nintendo (A справа) правая кнопка подписана B, и " + "подсказки A показывают B). Игра читает подсказки при запуске, так что они меняются после " + "перезапуска. Подсказки записаны в файлах игры, поэтому у кнопки, переназначенной на " + "вкладке управления, на экране остаётся прежняя подсказка.", + [UI_MENU_PROMPTS_NINTENDO] = "Nintendo", [UI_MENU_PROMPTS_XBOX] = "Xbox", + [UI_MENU_PROMPTS_MISSING] = "нет файлов подсказок: запустите установку снова", + [UI_MENU_PROMPTS_FAILED] = "файлы подсказок повреждены: запустите установку снова", + [UI_MENU_PROMPTS_RESTART] = "подсказки сменятся после перезапуска", + [UI_MENU_PROMPTS_OFF_WIDE] = "выкл. при широком разрешении игры", + [UI_MENU_PROMPTS_OFF_MODS] = "выкл.: мод RomFS заменяет их файлы", + [UI_MENU_PROMPTS_OFF_PATCHES] = "выкл., пока задан TOTK_ROMFS_PATCHES", [UI_MENU_STICK_DEADZONE] = "Мёртвая зона стиков", [UI_MENU_STICK_DEADZONE_DESC] = "Насколько нужно отклонить стик геймпада, чтобы игра это заметила. Увеличьте, если персонаж или камера двигаются сами.", [UI_MENU_MOUSE_SENS] = "Чувствительность мыши", diff --git a/runtime/ui_text.h b/runtime/ui_text.h index 6200df89..89d13337 100644 --- a/runtime/ui_text.h +++ b/runtime/ui_text.h @@ -58,8 +58,11 @@ typedef enum { UI_MENU_RUMBLE_CURVE, UI_MENU_RUMBLE_CURVE_DESC, UI_MENU_RUMBLE_TRIGGERS, UI_MENU_RUMBLE_TRIGGERS_DESC, UI_MENU_PAD_LAYOUT, UI_MENU_PAD_LAYOUT_DESC, UI_MENU_PAD_LAYOUT_AUTO, UI_MENU_PAD_LAYOUT_NINTENDO, - UI_MENU_PAD_LAYOUT_XBOX, UI_MENU_PAD_LAYOUT_XBOX_PROMPTS, UI_MENU_PAD_LAYOUT_IN_USE, - UI_MENU_PAD_LAYOUT_PROMPTS_MISSING, UI_MENU_PAD_LAYOUT_PROMPTS_RESTART, + UI_MENU_PAD_LAYOUT_XBOX, UI_MENU_PAD_LAYOUT_IN_USE, + UI_MENU_PROMPTS, UI_MENU_PROMPTS_DESC, UI_MENU_PROMPTS_NINTENDO, UI_MENU_PROMPTS_XBOX, + // the notes under the prompts: their files are missing or damaged, they change after restart, or why they are off + UI_MENU_PROMPTS_MISSING, UI_MENU_PROMPTS_FAILED, UI_MENU_PROMPTS_RESTART, UI_MENU_PROMPTS_OFF_WIDE, + UI_MENU_PROMPTS_OFF_MODS, UI_MENU_PROMPTS_OFF_PATCHES, UI_MENU_STICK_DEADZONE, UI_MENU_STICK_DEADZONE_DESC, UI_MENU_MOUSE_SENS, UI_MENU_MOUSE_SENS_DESC,