From ceece5683a94c01e759ae4e172628b96bb8ea746 Mon Sep 17 00:00:00 2001 From: Wintego <17454585+Wintego@users.noreply.github.com> Date: Sun, 8 Nov 2026 13:20:17 +0300 Subject: [PATCH] Make the PC prompts for every game resolution the setup lays the UI out for The setup wrote romfs-patches-pc for 16:9 only, so prompts = pc on a 21:9, 32:9, 16:10 or 3:2 screen kept the game resolution at 1920x1080 (cfg.c) or, with output_res set to the screen's shape, fell back to the Switch prompts. - make_romfs_patches.py --reuse : a file of an earlier overlay whose contents match is hard-linked (copied where links fail) instead of compressed again; the output is byte for byte the same. - The setup builds romfs-patches-pc-x for each of ASPECT_SIZES from romfs-patches-pc with --reuse: only the Common archive is compressed, so the fifteen folders take about two minutes and 6 MiB each instead of 22 minutes and 73 MiB each. - cfg.c: the display-shaped output_res default applies with prompts = pc when romfs-patches-pc-x is there (romfs_shaped_pc_ready); Xbox prompts keep 1920x1080 as before. --- docs/controls.md | 2 +- docs/installer.md | 7 ++++-- installer/steps.py | 22 ++++++++++++++++-- runtime/cfg.c | 20 ++++++++++++----- runtime/host.h | 1 + runtime/romfs.c | 17 +++++++++----- runtime/ui/menu.cpp | 4 ++-- tests/romfs_prompts_test.py | 29 ++++++++++++++++++++++++ tools/make_romfs_patches.py | 45 ++++++++++++++++++++++++++++++++----- totk.ini.example | 4 ++-- 10 files changed, 125 insertions(+), 26 deletions(-) diff --git a/docs/controls.md b/docs/controls.md index 9c14b771..3200f001 100644 --- a/docs/controls.md +++ b/docs/controls.md @@ -73,7 +73,7 @@ The Switch prompts stay, with a note under *Button prompts* and a `RomFS overlay - The glyphs keep the width of the game's own, so the right-aligned guides do not run into their text. A key is a rounded square with its label cut out in the game's own text fonts; a mouse button is a mouse with that button filled and the others hollow. - The button guide in play draws every button from images of the Common archive (`Nt_KeyTexA/B/X/Y/L/ZL_00`, `Nt_KeyTexLSt_00` and `_01`, the stick tilted and pressed): all of them are painted with the same icons. The letters of the action prompt's diamond are one character of the Normal font each: E, an arrow for Shift, a bar for Space, L and R for the mouse buttons. - Like the Xbox prompts they follow the defaults and not the bindings. `--binds ` draws the first key of each `bind_` line of that file instead, for a folder made by hand. -- At a game resolution of another shape than 16:9 the game loads `romfs-patches-pc-x` in place of `romfs-patches-x` when it is there: the same prompts with that shape's UI layout, `make_romfs_patches.py --prompts pc --aspect x --out \romfs-patches-pc-x`. The setup does not write those, so without one the Switch prompts stay (*off at a game resolution not 16:9*). +- At a game resolution of another shape than 16:9 the game loads `romfs-patches-pc-x` in place of `romfs-patches-x`: the same prompts with that shape's UI layout, `make_romfs_patches.py --prompts pc --aspect x --reuse \romfs-patches-pc --out \romfs-patches-pc-x`. The setup writes one for each of the fifteen sizes it lays the UI out for, so on a display of one of those shapes the game resolution follows the display with these prompts too. At another size, without that folder, the Switch prompts stay (*off at a game resolution not 16:9*). ## Window keys diff --git a/docs/installer.md b/docs/installer.md index 46d8c5c9..5a8806ad 100644 --- a/docs/installer.md +++ b/docs/installer.md @@ -74,8 +74,11 @@ loads the saves 1.4.3 wrote. writes the translations it makes in play as loose files; running the tool again with the game closed folds those in. The patches are written four times: `romfs-patches`, `romfs-patches-xbox` and `romfs-patches-xbox-label` (`--prompts`: Xbox button prompts for `prompts = xbox`, the first for `pad_layout = nintendo`, the second for `xbox` - and `auto`), and `romfs-patches-pc` (keyboard and mouse prompts for `prompts = pc`). The three prompt folders are - optional: when one cannot be made, the setup warns and finishes. + and `auto`), and `romfs-patches-pc` (keyboard and mouse prompts for `prompts = pc`). The PC prompts are then laid + out once more for each game resolution of another shape, `romfs-patches-pc-x` (`--prompts pc --aspect`). + Those differ from `romfs-patches-pc` in the UI archive only, and `--reuse` hard-links the other files from it, so + the fifteen folders take seconds and a few MiB each. The prompt folders are optional: when one cannot be made, the + setup warns and finishes. When the graphics driver crashes while building the shaders, `prepare_shaders.py` runs that part again without the variants it was building ([building.md](building.md), step 6), and the setup finishes with a warning that names how many were left out. diff --git a/installer/steps.py b/installer/steps.py index 4db8a2b5..ba439a5f 100644 --- a/installer/steps.py +++ b/installer/steps.py @@ -8,7 +8,7 @@ with the bundled clang (hostcheck.c). Install folder: exefs/, romfs/ (romfs.bin, index.json), profile/, shared-fonts/ (Chinese and Korean text), totk.exe and its DLLs, nvngx_dlss.dll (with --dlss), romfs-index.bin, romfs-patches/, romfs-patches-xbox/, -romfs-patches-xbox-label/, romfs-patches-pc/, totk_xlate.exe, the +romfs-patches-xbox-label/, romfs-patches-pc/, romfs-patches-pc-x/, totk_xlate.exe, the shader state of totk.exe --prepare-shaders, totk.ini, totk-install.json. Temp folder (/-): check/ (ExeFS of both inputs, the host check), unpacked/ (the NSP of an NSZ or XCZ input until the extraction is done), gen/ (C), build/ (objects), logs/. The cleanup keeps gen/, build/ and @@ -1097,7 +1097,7 @@ class Prepare(Step): # input_prompts_folder). Both are written on every install, so the menu choices work without another run of # the setup. Optional: when one fails, the game keeps the Switch prompts with that layout and the menu says the # files are missing, so the setup warns once and goes on. romfs-patches-pc likewise, with keyboard and mouse - # prompts for prompts = pc (16:9 only: another shape takes make_romfs_patches.py --prompts pc --aspect). + # prompts for prompts = pc. failed = None for style in ('xbox', 'xbox-label', 'pc'): out = dest / f'romfs-patches-{style}' @@ -1108,6 +1108,24 @@ class Prepare(Step): if code: remove(out) failed = failed or (code, log) + # The PC prompts once more for each shape of ASPECT_SIZES, romfs-patches-pc-x with that shape's UI layout + # (--prompts pc --aspect), which runtime/romfs.c overlay_init loads in place of romfs-patches-x: without + # it a player with prompts = pc on a screen that is not 16:9 chose between the prompts and the screen's shape. + # Only the Common archive differs from romfs-patches-pc; --reuse links the fonts, messages and size table from + # there instead of compressing them again, so the fifteen folders take seconds and a few MiB each. Optional + # like romfs-patches-pc, and skipped without it. + pc = dest / 'romfs-patches-pc' + for size in ASPECT_SIZES: + out = dest / f'romfs-patches-pc-{size}' + remove(out) + if not (pc / 'manifest.tsv').is_file(): + continue + code, log = run_tool(ctx, f'prepare-pc-{size}', layout.tools / 'make_romfs_patches.py', + ['--version', version_tag(game_version(ctx)), '--romfs', dest / 'romfs', '--out', out, + '--prompts', 'pc', '--aspect', size, '--reuse', pc]) + if code: + remove(out) + failed = failed or (code, log) if failed: rep.warning('warn.xbox_prompts_failed', code=failed[0], log=str(failed[1])) diff --git a/runtime/cfg.c b/runtime/cfg.c index a660c26c..3ac171e3 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -337,8 +337,10 @@ static const char *raw_get(const char *name) { // picture between black bars. The sizes are the ones the installer lays the HUD out for (installer/steps.py // ASPECT_SIZES, ui/menu.cpp row_output_res): of the display's shape within 1%, the smallest at least 1080 high that fits // the display, else the largest that fits. A 16:9 display, an unknown one or one of another shape keeps 1920x1080. -// Xbox or keyboard prompts keep 1920x1080 too: the setup builds their folders for 16:9 only (romfs.c overlay_init), so -// a default of another shape would trade the prompts the player chose for the Switch ones. +// Xbox prompts keep 1920x1080 too: the setup builds their folders for 16:9 only (romfs.c overlay_init), so a default of +// another shape would trade the prompts the player chose for the Switch ones. Keyboard prompts have a folder for each +// of these sizes (romfs-patches-pc-x, installer/steps.py Prepare): they keep 1920x1080 only when the one for +// the display's size is missing, as in a source build without make_romfs_patches.py --prompts pc --aspect. static const unsigned SHAPED[][2] = { {2560, 1080}, {3440, 1440}, {3840, 1600}, {5120, 2160}, // 21:9 {3840, 1080}, {5120, 1440}, // 32:9 @@ -346,10 +348,14 @@ static const unsigned SHAPED[][2] = { {1920, 1280}, {2160, 1440}, {2256, 1504}, {2880, 1920}, {3000, 2000}, // 3:2 }; static char screen_res[16]; // set once by cfg_init, "" for none +static int screen_pc; // romfs-patches-pc- has a manifest (set once by cfg_init) -static int switch_prompts(void) { +// Whether the prompts in effect have their folder at screen_res. The same picks as input_map.c input_prompts_pick: an +// unknown or empty value is the Nintendo prompts, an unset one Xbox while the pad layout is "xbox_prompts". +static int shape_keeps_prompts(void) { const char *p = raw_get(PREFIX "PROMPTS"), *l = raw_get(PREFIX "PAD_LAYOUT"); - return (!p || !strcasecmp(p, "nintendo")) && !(l && !strcasecmp(l, "xbox_prompts")); + if (p && *p) return !strcasecmp(p, "pc") ? screen_pc : strcasecmp(p, "xbox") != 0; + return !(l && !strcasecmp(l, "xbox_prompts")); } static void screen_default(void) { @@ -367,7 +373,8 @@ static void screen_default(void) { if (best < 0) best = fit; if (best < 0) return; snprintf(screen_res, sizeof screen_res, "%ux%u", SHAPED[best][0], SHAPED[best][1]); - if (!raw_get(PREFIX "OUTPUT_RES") && switch_prompts()) + screen_pc = romfs_shaped_pc_ready(SHAPED[best][0], SHAPED[best][1]); + if (!raw_get(PREFIX "OUTPUT_RES") && shape_keeps_prompts()) rt_log("cfg: the display is %dx%d: output_res defaults to %s, its shape (totk.ini output_res sets another)", sw, sh, screen_res); } @@ -376,7 +383,8 @@ const char *cfg_get(const char *name) { const char *v = raw_get(name); if (v || strncmp(name, PREFIX, PREFIX_LEN)) return v; if (!profile_of()) - return screen_res[0] && !strcasecmp(name + PREFIX_LEN, "OUTPUT_RES") && switch_prompts() ? screen_res : NULL; + return screen_res[0] && !strcasecmp(name + PREFIX_LEN, "OUTPUT_RES") && shape_keeps_prompts() ? screen_res + : NULL; for (size_t i = 0; i < sizeof DECK / sizeof *DECK; i++) if (!strcasecmp(DECK[i].key, name + PREFIX_LEN)) return DECK[i].value; return NULL; diff --git a/runtime/host.h b/runtime/host.h index 066104e0..85f894d4 100644 --- a/runtime/host.h +++ b/runtime/host.h @@ -280,6 +280,7 @@ int res_is_16x9(unsigned w, unsigned h); // within 1% of 16:9 int res_wants_wide_overlay(const unsigned out[2]); // not 16:9 on a game version with the camera aspect patch int romfs_shaped_ready(unsigned w, unsigned h); // romfs-patches-x has a manifest (romfs.c; works // before fs_init) +int romfs_shaped_pc_ready(unsigned w, unsigned h); // the same for romfs-patches-pc-x void res_wanted(unsigned out[2]); // the output size TOTK_OUTPUT_RES asks for void res_fov_live(void); // TOTK_FOV to the camera (set fov); on a settings change // ---- code patches (patches.c) and the frame step (frame_rate.c) diff --git a/runtime/romfs.c b/runtime/romfs.c index 81665098..52c80481 100644 --- a/runtime/romfs.c +++ b/runtime/romfs.c @@ -1080,19 +1080,26 @@ static void index_path(char *out, size_t cap) { strcpy(out + k, "romfs-index.bin"); } -// 1 when the game resolution w x h has the UI layout of its shape: romfs-patches-x next to romfs-index.bin with a -// manifest, the folder overlay_init looks for. Works before fs_init: index_dir is not set that early (res_init and -// resolution.c decide run first), so the index path is worked out again here. -int romfs_shaped_ready(unsigned w, unsigned h) { +// 1 when -x has a manifest next to romfs-index.bin. Works before fs_init: index_dir is not set that early +// (cfg_init, res_init and resolution.c decide run first), so the index path is worked out again here. +static int shaped_folder_ready(const char *prefix, unsigned w, unsigned h) { char dir[2100], path[2200]; index_path(dir, sizeof dir); char *sep = plat_last_sep(dir); if (sep) *sep = 0; else strcpy(dir, "."); - return snprintf(path, sizeof path, "%s/romfs-patches-%ux%u/manifest.tsv", dir, w, h) < (int)sizeof path && + return snprintf(path, sizeof path, "%s/%s-%ux%u/manifest.tsv", dir, prefix, w, h) < (int)sizeof path && plat_file_exists(path); } +// 1 when the game resolution w x h has the UI layout of its shape: romfs-patches-x, the folder overlay_init +// looks for. +int romfs_shaped_ready(unsigned w, unsigned h) { return shaped_folder_ready("romfs-patches", w, h); } + +// 1 when it has the PC prompts with that layout too: romfs-patches-pc-x, which overlay_init loads in its place +// with prompts = pc. +int romfs_shaped_pc_ready(unsigned w, unsigned h) { return shaped_folder_ready("romfs-patches-pc", w, h); } + static void load_index(void) { char path[2100]; index_path(path, sizeof path); diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index aa845156..e8e57ef4 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -791,8 +791,8 @@ static const char *prompts_note(bool *restart) { 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; - // A game resolution of another shape needs a folder of its own for the PC prompts (romfs-patches-pc-x), which - // the setup does not write: the shape is the reason then, not the setup. + // A game resolution of another shape needs a folder of its own for the PC prompts (romfs-patches-pc-x). The + // setup writes one for each size the Screen tab offers; at any other size the shape is the reason, not the setup. int off = romfs_prompts_off(want); if (want && !romfs_prompts_ready(want) && off != ROMFS_PROMPTS_SHAPE) return menu_text(UI_MENU_PROMPTS_MISSING); switch (off) { diff --git a/tests/romfs_prompts_test.py b/tests/romfs_prompts_test.py index a21cdd50..0b9c55ee 100644 --- a/tests/romfs_prompts_test.py +++ b/tests/romfs_prompts_test.py @@ -13,6 +13,7 @@ import importlib.util import io import json import random +import shutil import struct import subprocess import sys @@ -572,6 +573,34 @@ class PromptsTest(unittest.TestCase): self.assertEqual(proc.returncode, 0, proc.stderr) self.assertEqual((out / 'manifest.tsv').read_bytes(), (self.outs['v121', 'xbox'][0] / 'manifest.tsv').read_bytes()) + def test_reuse_links_the_files_that_match_and_writes_the_same_overlay(self): + romfs = self.romfs['v143'] + pc, pc_summary = self.outs['v143', 'pc'] + source = self.base / 'reuse' / 'source' # a copy, so the class's folder is never linked or rewritten + shutil.copytree(pc, source) + out = self.base / 'reuse' / 'pc' + proc = romfs.run(out, '--prompts', 'pc', '--reuse', str(source)) + self.assertEqual(proc.returncode, 0, proc.stderr) + self.assertEqual((out / 'manifest.tsv').read_bytes(), (pc / 'manifest.tsv').read_bytes()) + self.assertEqual(sorted(json.loads(proc.stdout.strip().splitlines()[-1])['reused']), sorted(manifest(pc))) + self.assertEqual(pc_summary['reused'], []) + # From the Xbox prompts only what both share is taken; the rest is made, and the overlay is the same. + xbox = self.outs['v143', 'xbox'][0] + out = self.base / 'reuse' / 'from-xbox' + proc = romfs.run(out, '--prompts', 'pc', '--reuse', str(xbox)) + self.assertEqual(proc.returncode, 0, proc.stderr) + self.assertEqual((out / 'manifest.tsv').read_bytes(), (pc / 'manifest.tsv').read_bytes()) + shared = {p for p, row in manifest(pc).items() if manifest(xbox).get(p) == row} + self.assertEqual(set(json.loads(proc.stdout.strip().splitlines()[-1])['reused']), shared) + # A new run into the source folder replaces its files instead of writing through the links. + before = {p: (self.base / 'reuse' / 'pc' / p).read_bytes() for p in manifest(pc)} + ini = self.base / 'reuse' / 'totk.ini' + ini.write_text('[input]\nbind_A = key:F\n', encoding='utf-8') + proc = romfs.run(source, '--prompts', 'pc', '--binds', str(ini)) + self.assertEqual(proc.returncode, 0, proc.stderr) + self.assertNotEqual((source / 'manifest.tsv').read_bytes(), (pc / 'manifest.tsv').read_bytes()) + self.assertEqual({p: (self.base / 'reuse' / 'pc' / p).read_bytes() for p in manifest(pc)}, before) + def test_unrecognised_romfs_fails_before_writing(self): cases = {'no text fonts': (dict(text_fonts=False), icons.TEXT_FONTS[0]), 'no size entry': (dict(restbl_skips=(REGIONAL_FONT,)), 'has no entry in the resource size table'), diff --git a/tools/make_romfs_patches.py b/tools/make_romfs_patches.py index f9139543..0a3946d1 100644 --- a/tools/make_romfs_patches.py +++ b/tools/make_romfs_patches.py @@ -45,6 +45,10 @@ from the game's own files on the player's machine, nothing added (tools/button_i guide's images (A, B, X, Y, L, ZL and the stick's two). The one-letter panes around the action prompt name the keys with one character of the Normal font (E, an arrow for Shift, a bar for Space, L and R for the mouse buttons). +--reuse : an overlay made before, such as romfs-patches-pc for romfs-patches-pc-x. Each file of it whose +contents match the new one is hard-linked (copied where links fail) instead of compressed again; the summary's reused +lists them. The output is byte for byte the same as without it. + Input: build/extracted//romfs (romfs.bin and index.json, verified by tools/extract.py). Output: build//romfs-patches/ by default (romfs-patches-