From 98a657dfd11a69abf19563815b304199bf1664ea Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Sat, 31 Oct 2026 14:23:58 +0300 Subject: [PATCH] Give 1.2.1 the camera aspect ratio and the HUD layouts of other shapes patches-v121.txt takes the aspect set at upstream's 1.2.1 sites (game_patches.c aspect_install): the same two camera loads and two viewport divisions as 1.4.3, with the same original words and the same replacement from page +56. The installer now builds the romfs-patches-x overlays for 1.2.1 too; ultrawide_layout.py passes on its Common.Product.110 at all ten sizes. Checked in game at 3440x1440 (camera 2.3889) and 1920x1200 (1.6000): wider or taller view, HUD at the corners or edges, no validation errors. Co-Authored-By: Claude Opus 5.5 --- README.md | 3 +-- docs/architecture.md | 4 ++-- docs/tester-guide.md | 4 ++-- installer/steps.py | 8 +++----- recomp/patches-v121.txt | 11 +++++++++++ runtime/cfg.c | 4 ++-- runtime/resolution.c | 8 ++++---- runtime/romfs.c | 4 ++-- tools/make_romfs_patches.py | 2 +- tools/ultrawide_layout.py | 4 ++-- totk.ini.example | 6 +++--- 11 files changed, 33 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index f3a41b6b..cd851018 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Report problems as issues, following [CONTRIBUTING.md](CONTRIBUTING.md). - Game updates 1.2.1 and 1.4.3, with saves that carry over between them - 60 fps by default; up to 144 fps or the monitor's refresh rate (experimental) - Custom resolutions (1080p, 2k...), supersampling and AMD FSR 1 upscaling -- 16:10 (Steam Deck, handhelds), 21:9 and 32:9 (ultrawide) game resolutions on 1.4.3, with the camera and the interface in that shape +- 16:10 (Steam Deck, handhelds), 21:9 and 32:9 (ultrawide) game resolutions, with the camera and the interface in that shape - In-game settings menu (F1) and performance overlay (F10) - Keyboard, mouse and gamepad with remapping, rumble and gyro - Xbox button prompts: a layout that keeps the Switch button positions and shows the Xbox labels @@ -29,7 +29,6 @@ Report problems as issues, following [CONTRIBUTING.md](CONTRIBUTING.md). - Linux and the Steam Deck - Mods made for emulators: unpack a mod into a `mods` folder -- 16:10 and ultrawide on 1.2.1 - VRR ## Installing diff --git a/docs/architecture.md b/docs/architecture.md index 2b65a3e1..12f75987 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -94,12 +94,12 @@ Every guest thread is a host thread. TotK assumes Horizon's scheduler: three app (MacNativeGames' sites); `resolution.c` sets them from `output_res` and `render_scale` and grows the texture heap and the application pool to match. When the window is larger than the output, `vk_fsr.c` runs AMD FSR 1 (EASU, RCAS) on the present. An `output_res` that is not 16:9 (more than 1% off, `res_is_16x9`) also switches on the - `aspect` patch set (1.4.3 only), which hands the output's ratio to the camera, and `romfs.c` `overlay_init` loads the + `aspect` patch set, which hands the output's ratio to the camera, and `romfs.c` `overlay_init` loads the `romfs-patches-x` overlay for it when it exists (`tools/make_romfs_patches.py --aspect`, laid out by `tools/ultrawide_layout.py`; the installer builds ten sizes: 21:9 2560x1080, 3440x1440, 3840x1600, 5120x2160, 32:9 3840x1080, 5120x1440 and 16:10 1280x800, 1680x1050, 1920x1200, 2560x1600). A wider layout moves the HUD to the screen's corners, a narrower one to its top and bottom edges. Other sizes get the camera of their shape and the 16:9 - HUD stretched over it. 1.2.1 has no camera patch: a size of another shape there keeps the 16:9 view. The `aspect` setting (`fit`, the default; `stretch`) decides what the present does + HUD stretched over it. The `aspect` setting (`fit`, the default; `stretch`) decides what the present does when the window's shape differs from the output's: `fit` letterboxes, where a 16:9 game in a wider window used to be stretched. - Occlusion queries never block the CPU; a result that is not ready counts as visible. diff --git a/docs/tester-guide.md b/docs/tester-guide.md index edf48ead..67a9fc70 100644 --- a/docs/tester-guide.md +++ b/docs/tester-guide.md @@ -69,7 +69,7 @@ Build or install on Linux ([installer.md](installer.md), "Linux release"), in De mode; for Game Mode, add `totk` from the install folder to Steam as a non-Steam game. The game recognises the Deck (LCD and OLED) and uses its device profile for every setting `totk.ini` does not set: -fullscreen, the screen's own 1280x800 (16:10: on 1.4.3 the camera and interface take that shape), the game's own 3D scale, +fullscreen, the screen's own 1280x800 (16:10: the camera and interface take that shape), the game's own 3D scale, vsync and a 40 fps limit. These are starting points, not measurements. What helps most: 1. The performance overlay (F10, or both stick clicks L3 + R3) in full mode: the frame rate, mean and longest frame @@ -77,7 +77,7 @@ vsync and a 40 fps limit. These are starting points, not measurements. What help 2. The same with `fps_limit` 30, 45 and 60 and `render_scale` 50, 67 and game, so the defaults can be picked from measurements. Steam's own performance overlay (the ... button) adds power draw and temperatures. 3. LCD or OLED, SteamOS version (`uname -r` in Desktop Mode's terminal), and the game update. -4. Anything that looks stretched, squeezed or cut off, with a screenshot. At 16:10 on 1.4.3 the menus keep their 16:9 +4. Anything that looks stretched, squeezed or cut off, with a screenshot. At 16:10 the menus keep their 16:9 proportions in the middle of the taller screen, the HUD sits at the top and bottom edges, and full-screen backgrounds reach them; pre-rendered cutscenes play stretched. diff --git a/installer/steps.py b/installer/steps.py index 93723d36..b03a69f1 100644 --- a/installer/steps.py +++ b/installer/steps.py @@ -669,14 +669,12 @@ class Prepare(Step): if code: raise InstallError('prepare.romfs_patches_failed', code=code, log=str(log)) # The same overlay with the UI laid out for each game resolution of another shape the settings menu offers - # (runtime/romfs.c overlay_init picks the one that matches). Only 1.4.3 has the camera aspect patch - # (recomp/patches-v143.txt) the layouts go with: 1.2.1 builds none. + # (runtime/romfs.c overlay_init picks the one that matches; the camera's side is the patch set aspect, + # recomp/patches-v.txt). for size in ASPECT_SIZES: remove(dest / f'romfs-patches-{size}') - if version_tag(game_version(ctx)) != 'v143': - continue code, log = run_tool(ctx, 'prepare', layout.tools / 'make_romfs_patches.py', - ['--version', 'v143', '--romfs', dest / 'romfs', '--out', + ['--version', version_tag(game_version(ctx)), '--romfs', dest / 'romfs', '--out', dest / f'romfs-patches-{size}', '--aspect', size]) if code: raise InstallError('prepare.romfs_patches_failed', code=code, log=str(log)) diff --git a/recomp/patches-v121.txt b/recomp/patches-v121.txt index 64793027..2d919d2f 100644 --- a/recomp/patches-v121.txt +++ b/recomp/patches-v121.txt @@ -64,6 +64,17 @@ site scene main cc3f68 5e21d900 @page:x9 # scvtf s0, s8 -> adrp x9, page site scene main cc3f70 bd0cc660 2d420520 # str s0, [x19, #0xcc4] -> ldp s0, s1, [x9, #16] site scene main cc3f74 5e21d921 bd0cc660 # scvtf s1, s9 -> str s0, [x19, #0xcc4] +# Camera aspect ratio for a game resolution that is not 16:9 (upstream game_patches.c, the 1.2.1 sites of aspect_install; +# runtime/resolution.c res_init writes the output's width / height to page +56 and switches the set on). The same four +# sites as patches-v143.txt, with the same original words: two camera sites (update and setup) load the camera's copy of +# DefaultAspect 1.777778, two viewport routines divide width by height. The replacement loads the ratio from the page +# instead (Hor+). x10 is kept on the stack, so no register liveness is assumed. +set aspect TOTK_ASPECT_PATCH 0 +site aspect main cb4b10 bd414260 f81f0fea @page:x10 bd403940 f84107ea # ldr s0, [x19, #0x140] (camera update) +site aspect main 12521cc bd414260 f81f0fea @page:x10 bd403940 f84107ea # ldr s0, [x19, #0x140] (camera setup) +site aspect main 19b36f0 1e211800 f81f0fea @page:x10 bd403940 f84107ea # fdiv s0, s0, s1 (viewport) +site aspect main 1ecdf68 1e211800 f81f0fea @page:x10 bd403940 f84107ea # fdiv s0, s0, s1 (viewport) + # Spin waits, from tools/spin_waits.py --exefs build/extracted/v121/exefs --patches recomp/patches-v121.txt: loops that only # another thread can end; their back-edges pass rt_spin_gate (runtime/kernel.c), TOTK_SPIN=0 keeps the core. spin main ac600 ac620 ac630 # 13 instructions; loads diff --git a/runtime/cfg.c b/runtime/cfg.c index 1b3aa1f5..2f989519 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -207,8 +207,8 @@ int cfg_load(const char *path) { // (default: the Steam Deck when the firmware says so), desktop (none) or deck. // // The Steam Deck (LCD Jupiter, OLED Galileo; 1280x800, 16:10, 4 Zen 2 cores, RDNA 2 with 8 CUs sharing 16 GB): the game -// at the screen's 1280x800 with its own 5/6 scene (on 1.4.3 the aspect patch gives the camera its 16:10, resolution.c, -// and the romfs-patches-1280x800 overlay the HUD's); +// at the screen's 1280x800 with its own 5/6 scene (the aspect patch gives the camera its 16:10, resolution.c, and the +// romfs-patches-1280x800 overlay the HUD's); // fullscreen and vsync, as gamescope composes Game Mode; 40 fps, which divides 40 Hz (and 120 Hz on the OLED). // Starting points to replace with measured ones (docs/tester-guide.md, Steam Deck). static const struct { const char *key, *value; } DECK[] = { diff --git a/runtime/resolution.c b/runtime/resolution.c index 514b3e6e..6bf0eccd 100644 --- a/runtime/resolution.c +++ b/runtime/resolution.c @@ -12,7 +12,7 @@ // // Patch page: +16 the scene size {w, h} as floats, +32 the output size and +48 the swapchain size as {w, h} in one // 64-bit word, +40 the renderer (1.2.1) or display configuration (1.4.3) the patched code stores there. -// +56 the camera's aspect ratio as a float when the output is not 16:9 (1.4.3, set aspect). +// +56 the camera's aspect ratio as a float when the output is not 16:9 (set aspect). // 1.4.3 scales the scene it reads by output width / 1920 (a 2560x1440 output renders its 1600x900 scene at 2128x1200; // MacNativeGames measured the same), so its page holds the wanted size divided by that factor and the game's 5/6 needs // no scene patch. 1.2.1 renders the size it reads (1600x900 on a 2560x1440 output): its page holds the wanted size, and @@ -219,8 +219,8 @@ void res_init(void) { rt_patch_switch(output, R.ow != BASE_W || R.oh != BASE_H); rt_patch_switch(scene, scene_on); R.on = 1; - // Another shape than 16:9 (more than 1% off): the camera takes the output's ratio (recomp/patches-v143.txt, set - // aspect), so a 21:9 output shows more of the world at the sides instead of a stretched 16:9 view. The HUD's layouts + // Another shape than 16:9 (more than 1% off): the camera takes the output's ratio (recomp/patches-v121.txt and + // patches-v143.txt, set aspect), so a 21:9 output shows more of the world at the sides instead of a stretched 16:9 view. The HUD's layouts // for that shape come from romfs-patches-x (romfs.c overlay_init, tools/make_romfs_patches.py --aspect). double ratio = (double)R.ow / R.oh, game = (double)BASE_W / BASE_H; int aspect = rt_patch_set("aspect"); @@ -248,7 +248,7 @@ int res_is_16x9(unsigned w, unsigned h) { } // The game resolution asks for a romfs-patches-x overlay: it is not 16:9 and the game version has the camera -// aspect patch (set aspect, 1.4.3 only); the wide UI layouts only fit a camera that follows the same shape. +// aspect patch (set aspect); the UI layouts of another shape only fit a camera that follows the same shape. int res_wants_wide_overlay(const unsigned out[2]) { return !res_is_16x9(out[0], out[1]) && rt_patch_set("aspect") >= 0; } diff --git a/runtime/romfs.c b/runtime/romfs.c index f6634712..64129b0d 100644 --- a/runtime/romfs.c +++ b/runtime/romfs.c @@ -382,8 +382,8 @@ int romfs_xbox_prompts_active(void) { return xbox_prompts_active; } 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). + // the UI laid out for that shape (make_romfs_patches.py --aspect), when the game version has the camera aspect patch + // the layout goes with (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 diff --git a/tools/make_romfs_patches.py b/tools/make_romfs_patches.py index 5e8b232e..34efe658 100644 --- a/tools/make_romfs_patches.py +++ b/tools/make_romfs_patches.py @@ -15,7 +15,7 @@ left out. for that shape (tools/ultrawide_layout.py): menus keep their 16:9 proportions in the middle, full-screen backgrounds cover the screen and the HUD moves to the screen's corners (wider) or its top and bottom edges (narrower). totk.exe loads that overlay from romfs-patches-x when the game resolution is that size (runtime/romfs.c overlay_init); -the camera's side of it is the patch set aspect (recomp/patches-v143.txt). +the camera's side of it is the patch set aspect (recomp/patches-v121.txt, patches-v143.txt). --xbox-prompts: the same overlay with the A and B, and the X and Y button prompts swapped, for pad_layout = xbox_prompts (runtime/romfs.c overlay_init loads romfs-patches-xbox in place of romfs-patches). That layout plays an Xbox pad by diff --git a/tools/ultrawide_layout.py b/tools/ultrawide_layout.py index 709f6c72..6c2fff1a 100644 --- a/tools/ultrawide_layout.py +++ b/tools/ultrawide_layout.py @@ -9,8 +9,8 @@ axis (scale x = 16/9 over the aspect when wider, scale y = the aspect over 16/9 cover the whole screen are stretched back, and the HUD's parts move out to the screen's corners (wider) or its top and bottom edges (narrower). The pane list and the distances are the ones the community TOTK-Ultrawide mod for emulators found for 1.0.0 .. 1.2.1 (GPL; only those values are taken, no code; THIRD_PARTY_NOTICES.md). This is an independent -implementation, checked against 1.4.3's Common.Product.140: every pane is found by name and every pane field and -animation key holds the value the edit expects before it is written. +implementation, checked against 1.2.1's Common.Product.110 and 1.4.3's Common.Product.140: every pane is found by name +and every pane field and animation key holds the value the edit expects before it is written. """ import struct diff --git a/totk.ini.example b/totk.ini.example index bb7b0e37..2b8c5d7d 100644 --- a/totk.ini.example +++ b/totk.ini.example @@ -122,9 +122,9 @@ # gpu_name = NVIDIA # Game resolution: the size the game draws its picture and interface in (1280x720 to 7680x4320). Above 1920x1080 the # game's texture heap and memory pool grow with it. Another shape than 16:9, such as 3440x1440 on a 21:9 monitor or -# the Steam Deck's 1280x800 (16:10), gives the camera's view that shape and lays the HUD out for it. That is 1.4.3 only -# (1.2.1 keeps the 16:9 view), and the installer prepares the UI layout for ten sizes: 2560x1080, 3440x1440, 3840x1600, -# 5120x2160 (21:9), 3840x1080, 5120x1440 (32:9), 1280x800, 1680x1050, 1920x1200 and 2560x1600 (16:10). Any other size +# the Steam Deck's 1280x800 (16:10), gives the camera's view that shape and lays the HUD out for it. The installer +# prepares the UI layout for ten sizes: 2560x1080, 3440x1440, 3840x1600, 5120x2160 (21:9), 3840x1080, 5120x1440 (32:9), +# 1280x800, 1680x1050, 1920x1200 and 2560x1600 (16:10). Any other size # gets the camera's view but a 16:9 HUD, stretched over the picture, unless you build its layout with # tools/make_romfs_patches.py --aspect WxH. Read at start. # output_res = 1920x1080