diff --git a/README.md b/README.md index fe8def04..f3a41b6b 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) and 21:9 (ultrawide) game resolutions, with the camera and the interface in that shape +- 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 - 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,7 @@ 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 -- Ultrawide on 1.2.1 (1.4.3 has it for 2560x1080, 3440x1440, 3840x1600, 5120x2160, 3840x1080 and 5120x1440; other shapes get the wide camera with a 16:9 HUD) +- 16:10 and ultrawide on 1.2.1 - VRR ## Installing diff --git a/docs/architecture.md b/docs/architecture.md index ec74fd2f..2b65a3e1 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -96,9 +96,10 @@ Every guest thread is a host thread. TotK assumes Horizon's scheduler: three app 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 `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 six sizes: 21:9 2560x1080, 3440x1440, 3840x1600, 5120x2160 and - 32:9 3840x1080, 5120x1440). Other shapes, such as 16:10, get the wide camera and the 16:9 HUD stretched over it. 1.2.1 has no camera patch: a - wide size there keeps the 16:9 view. The `aspect` setting (`fit`, the default; `stretch`) decides what the present does + `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 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/building.md b/docs/building.md index a2f828c0..e7d48480 100644 --- a/docs/building.md +++ b/docs/building.md @@ -80,8 +80,8 @@ From the repository root, in PowerShell. Every step that depends on the game ver .venv\Scripts\python tools\build_xlate.py ``` -5. Lift the modules to C, write the RomFS overlays (the frame-rate fix, and the interface at 16:10 and 21:9), then - compile and link `build\\totk.exe`: +5. Lift the modules to C, write the RomFS overlay (the frame-rate fix), then compile and link + `build\\totk.exe`: ```powershell .venv\Scripts\python recomp\gen.py --exefs build\extracted\\exefs --out generated\ --patches recomp\patches-.txt diff --git a/docs/tester-guide.md b/docs/tester-guide.md index 67a9fc70..edf48ead 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: the camera and interface take that shape), the game's own 3D scale, +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, 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 the menus keep their 16:9 +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 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 4124f13a..93723d36 100644 --- a/installer/steps.py +++ b/installer/steps.py @@ -625,8 +625,10 @@ class Compile(Step): TRANSLATED = re.compile(r'gfx_shader: prepare: (\d+) of (\d+) pairs') -# 21:9 and 32:9 monitor sizes, as runtime/ui/menu.cpp row_output_res lists them -WIDE_SIZES = ('2560x1080', '3440x1440', '3840x1600', '5120x2160', '3840x1080', '5120x1440') +# The game resolutions of another shape than 16:9 that runtime/ui/menu.cpp row_output_res lists: 21:9 and 32:9 monitors, +# and 16:10 screens (the Steam Deck's 1280x800, handhelds and laptops) +ASPECT_SIZES = ('2560x1080', '3440x1440', '3840x1600', '5120x2160', '3840x1080', '5120x1440', + '1280x800', '1680x1050', '1920x1200', '2560x1600') class Prepare(Step): @@ -666,10 +668,10 @@ class Prepare(Step): dest / 'romfs-patches']) if code: raise InstallError('prepare.romfs_patches_failed', code=code, log=str(log)) - # The same overlay with the UI laid out for the 21:9 game resolutions 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, and ultrawide_layout.py is checked against 1.4.3's layout archive: 1.2.1 builds none. - for size in WIDE_SIZES: + # 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. + for size in ASPECT_SIZES: remove(dest / f'romfs-patches-{size}') if version_tag(game_version(ctx)) != 'v143': continue diff --git a/runtime/cfg.c b/runtime/cfg.c index 26c0023a..1b3aa1f5 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -207,7 +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 (the aspect patch gives camera and interface its 16:10, resolution.c); +// 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); // 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/ui/menu.cpp b/runtime/ui/menu.cpp index b48accf8..b6c08720 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -418,11 +418,13 @@ static void row_window_size(void) { } // The game resolution (resolution.c): 16:9 sizes from its smallest, 1280x720 (for weak GPUs), up, the common 21:9 and -// 32:9 monitor sizes (the camera and the HUD follow a wider shape, resolution.c res_init; the installer lays the HUD out -// for each, installer/steps.py WIDE_SIZES), and the current value when it is another size. +// 32:9 monitor sizes and the 16:10 screens of the Steam Deck, handhelds and laptops (the camera and the HUD follow +// another shape, resolution.c res_init; the installer lays the HUD out for each, installer/steps.py ASPECT_SIZES), and +// the current value when it is another size. static void row_output_res(void) { static const char *const vals[] = {"1280x720", "1600x900", "1920x1080", "2560x1440", "3200x1800", "3840x2160", - "2560x1080", "3440x1440", "3840x1600", "5120x2160", "3840x1080", "5120x1440"}; + "2560x1080", "3440x1440", "3840x1600", "5120x2160", "3840x1080", "5120x1440", + "1280x800", "1680x1050", "1920x1200", "2560x1600"}; enum { N = sizeof vals / sizeof *vals }; char shown[N][32]; const char *names[N]; diff --git a/runtime/ui_text.c b/runtime/ui_text.c index b0353285..a8ac7155 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -53,7 +53,8 @@ static const char *const text_en[UI_TEXT_COUNT] = { [UI_MENU_OUTPUT_RES] = "Game resolution", [UI_MENU_OUTPUT_RES_DESC] = "The size the game draws its picture and interface in. Above 1920 x 1080 the game needs " "more video memory and GPU time. A wider size (21:9) widens the camera's view and moves " - "the HUD to the screen's corners.", + "the HUD to the screen's corners; a taller one (16:10, Steam Deck) moves it to the top " + "and bottom edges.", [UI_MENU_RENDER_SCALE] = "3D render scale", [UI_MENU_RENDER_SCALE_DESC] = "Size of the 3D scene relative to the game resolution; the game's FSR scales it to " "that size. Above 100 % smooths jagged edges (supersampling) at a high GPU cost.", @@ -297,7 +298,8 @@ static const char *const text_ru[UI_TEXT_COUNT] = { [UI_MENU_OUTPUT_RES] = "Разрешение игры", [UI_MENU_OUTPUT_RES_DESC] = "Размер, в котором игра рисует картинку и интерфейс. Выше 1920 × 1080 игре нужно больше " "видеопамяти и времени GPU. Более широкий размер (21:9) расширяет обзор камеры и " - "переносит интерфейс в углы экрана.", + "переносит интерфейс в углы экрана, более высокий (16:10, Steam Deck) переносит его к " + "верхнему и нижнему краям.", [UI_MENU_RENDER_SCALE] = "Масштаб 3D-отрисовки", [UI_MENU_RENDER_SCALE_DESC] = "Размер 3D-сцены относительно разрешения игры; FSR игры доводит её до этого размера. " "Выше 100 % сглаживает лесенки на краях (суперсэмплинг) ценой большой нагрузки на GPU.", diff --git a/tools/make_romfs_patches.py b/tools/make_romfs_patches.py index 4b8b6629..5e8b232e 100644 --- a/tools/make_romfs_patches.py +++ b/tools/make_romfs_patches.py @@ -11,10 +11,11 @@ captured at once (upstream checked weapon, shield, material and ability wheel at The game-over flow fix of the same upstream script is 1.0.0 only (1.2.1 and 1.4.3 run DmF_SY_GameOver.110) and is left out. ---aspect x (a game resolution wider than 16:9, such as 3440x1440) also lays the UI out for that shape -(tools/ultrawide_layout.py): menus stay 16:9 in the middle, full-screen backgrounds cover the width and the HUD moves -to the screen's corners. 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). +--aspect x (a game resolution of another shape than 16:9, such as 3440x1440 or 1280x800) also lays the UI 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). --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 @@ -47,7 +48,7 @@ ap.add_argument('--version', choices=('v121', 'v143'), default='v121') ap.add_argument('--romfs', type=Path, help='default build/extracted//romfs') ap.add_argument('--out', type=Path, help='default build//romfs-patches (romfs-patches-xbox with --xbox-prompts)') -ap.add_argument('--aspect', help='x of a game resolution wider than 16:9: also lay the UI out for it') +ap.add_argument('--aspect', help='x of a game resolution of another shape than 16:9: also lay the UI out for it') ap.add_argument('--xbox-prompts', action='store_true', help='swap the A/B and X/Y button prompts as well') args = ap.parse_args() args.romfs = args.romfs or root / 'build/extracted' / args.version / 'romfs' diff --git a/tools/ultrawide_layout.py b/tools/ultrawide_layout.py index c93d413e..709f6c72 100644 --- a/tools/ultrawide_layout.py +++ b/tools/ultrawide_layout.py @@ -1,15 +1,16 @@ # Adapted from MacNativeGames games/totk/scripts/ultrawide_layout.py @ 933b6a0 (MIT, Copyright (c) 2026 # MacNativeGames contributors). Used by tools/make_romfs_patches.py --aspect. -"""The game's UI layouts for a canvas wider than 16:9 (output_res = 3440x1440 in totk.ini), edited in place in the -decompressed UI/LayoutArchive/Common.Product.*.blarc (tools/make_romfs_patches.py --aspect). +"""The game's UI layouts for a canvas of another shape than 16:9 (output_res = 3440x1440 or 1280x800 in totk.ini), +edited in place in the decompressed UI/LayoutArchive/Common.Product.*.blarc (tools/make_romfs_patches.py --aspect). The game lays its UI out on a 1920x1080 grid and maps that grid onto the canvas, so on a 21:9 canvas every layout comes -out 34% too wide. Here each layout's root pane is narrowed to 16:9 (scale x = 16/9 over the aspect), backgrounds that -must cover the whole screen are widened back, and the HUD's parts move out to the screen's corners. 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. +out 34% too wide and on a 16:10 one 11% too tall. Here each layout's root pane is scaled back to 16:9 on the stretched +axis (scale x = 16/9 over the aspect when wider, scale y = the aspect over 16/9 when narrower), backgrounds that must +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. """ import struct @@ -82,6 +83,110 @@ def edits(k, hud_corner): ('PlayerStatus_00', 'Pa_CompanionLife_00', 'x', -(840 + w))] return out +SYSTEM_MENUS = ('SystemLoadList_00', 'SystemOption_00', 'SystemSaveLoad_00') + +def tall_edits(k): + """(layout, pane, field, value) for a canvas narrower than 16:9: k = the aspect over 16/9 (the root's scale y), + h = how far a 1080-high layout's edge moves out in its own units (540 * (1 / k - 1)).""" + h, tall = 540 * (1 / k - 1), 1 / k + out = [('AppAlbum_00', 'N_FadeInOut_00', 'scale_y', k), ('AppAlbum_00', 'N_Open_01', 'scale_y', tall), + *[('AppMenuOverlay_00', p, 'scale_y', k) for p in ('N_FadeInOut_00', 'N_FadeInOut_01', 'N_Icon_00', + 'N_TitleOne_01')], + ('CameraPointer_00', 'N_Type_01', 'scale_y', k), ('CameraSystemWindow_00', 'N_FirstOut_00', 'scale_y', k), + *[('LoadingFade_00', p, 'scale_y', k) for p in ('Pa_IconPlayer_00', 'Pa_LargeDungeonMap_00', + 'Pa_LargeDungeonMap_01', 'Pa_Map_00', 'Pa_Map_01')], + *[('AppMap_00', f'N_BlurInOut_0{i}', 'scale_y', tall) for i in range(4)], + *[(layout, 'P_BG_00', 'scale_y', tall) for layout in ('AppOpenDemoWindow_00', 'GameOver_00', 'LoadingFade_00', + 'PaLargeDungeonMap_00', 'PaRecipeCardList_00')], + ('LoadingFade_00', 'N_Base_00', 'scale_y', tall), + *[(layout, 'N_BG_00', 'scale_y', tall) for layout in ('AutoBuilder_00', 'OwnedHorseList_00', 'ShopMenu_00', + 'StaffRoll_00')], + *[('CameraPointer_00', p, 'scale_y', tall) for p in ('N_InOutScope_00', 'Pa_CameraFocus_00', 'S_Scissor_00', + 'W_Shadow_01')], + ('CameraSystemWindow_00', 'N_InOut_00', 'scale_y', tall), ('MessageLog_01', 'P_Capture_00', 'scale_y', tall), + *[(layout, 'N_SystemBG_00', 'scale_y', tall) for layout in ('SystemActionGuide_00',) + SYSTEM_MENUS]] + # The HUD at the screen's top and bottom edges instead of the middle 16:9 + out += [(name, 'RootPane', 'y', 540 * (1 - k)) for name in ( + 'AppAlbum_00', 'AppPictureBook_00', 'ChallengeLog_00', 'Challenge_00', 'InstantTipsWithPict_00', 'InstantTips_00', + 'MiniGameTimer_00', 'NumDisplaySecond_00', 'NumDisplay_00', 'PickUpWin_00', 'PlayerStatus_00', 'Pouch_00', + 'ShopMenu_00', 'SystemActionGuide_00') + SYSTEM_MENUS] + out += [(name, 'RootPane', 'y', -540 * (1 - k)) for name in ( + 'CtrlGuide_00', 'DoCommand_00', 'EnvironmentInfo_00', 'HorseGauge_00', 'MessageDialog_00', 'MessageLog_01', + 'PauseMenuOverlay_00', 'SaveLoadIcon_00', 'TreasureFullShortCut_00')] + out += [('AppAlbum_00', 'N_PicLoad_01', 'y', -540 * (1 - k)), ('AppMap_00', 'N_AllMapTime_00', 'y', -h), + ('AppMenuOverlay_00', 'A_Align_00', 'y', -(505 + h)), ('AppMenuOverlay_00', 'Pa_GuideLeft_00', 'y', -(505 + h)), + ('AppMenuOverlay_00', 'N_TitleTab_00', 'y', 491 + h), + ('LoadingFade_00', 'N_Logo_00', 'y', -h), ('LoadingFade_00', 'N_Sage_00', 'y', -477 - 2 * h), + ('LoadingFade_00', 'N_Status_00', 'y', h), ('LoadingFade_00', 'N_Tips_00', 'y', -(360 + h)), + ('Location_00', 'N_Large_00', 'y', 270 + h), ('Location_00', 'N_Small_00', 'y', -(395 + h)), + ('MessageLog_01', 'P_Capture_00', 'y', h), + ('PaExtraStaminaGauge_00', 'N_BasePattern_00', 'y', h), ('PaExtraStaminaGauge_00', 'N_GaugeMainPattern_00', 'y', h), + ('Pouch_00', 'N_Info_00', 'y', -h), ('Pouch_00', 'Pa_ExtraStamina_00', 'y', -h), + ('ShopMenu_00', 'A_AlignGuide_00', 'y', -(477 + h)), + *[(layout, 'N_SystemBG_00', 'y', -h) for layout in ('SystemActionGuide_00',) + SYSTEM_MENUS], + ('SystemLoadList_00', 'Pa_Guide_00', 'y', -(474 + h)), ('SystemOption_00', 'A_Guide_00', 'y', -(474 + h))] + return out + +# BFLAN animation targets: FLPA (pane SRT) translate y, FLTS (texture SRT) scale y +FLPA_Y, FLTS_SY = 1, 4 + +def anim_keys(blarc, lo, pane, tag, target): + """The absolute offsets of each key (frame, value, slope: 12 bytes) of the hermite curves of one pane, animation + tag (b'FLPA', b'FLTS') and target in the BFLAN at blarc[lo:], one list per curve. Found by walking the pai1 section, + so they hold in any version whose animation has that curve.""" + if blarc[lo:lo + 4] != b'FLAN': raise SystemExit(f'{lo:#x}: not a BFLAN') + pos, out = lo + struct.unpack_from(' 16 / 9 + k = (16 / 9) / (width / height) if wide else (width / height) / (16 / 9) + assert k < 1, 'only for canvases of another shape than 16:9' + root_scale = 'scale_x' if wide else 'scale_y' changed, layouts = set(), {} unknown = sorted(n for n in KEEP_ROOT if f'blyt/{n}.bflyt' not in members) if unknown: raise SystemExit(f'KEEP_ROOT names no layout: {unknown}') @@ -123,17 +232,21 @@ def apply(blarc, members, width, height, hud_corner=True): return find_pane(layouts[member], layout, pane) for member in sorted(m for m in members if m.startswith('blyt/') and m.endswith('.bflyt')): if member[5:-6] in KEEP_ROOT: continue - at = pane_offset(member[5:-6], 'RootPane') + FIELD['scale_x'] + at = pane_offset(member[5:-6], 'RootPane') + FIELD[root_scale] have = struct.unpack_from(' 1e-3: raise SystemExit(f'{member[5:-6]} RootPane scale_x: {have}, expected 1.0') + if abs(have - 1.0) > 1e-3: raise SystemExit(f'{member[5:-6]} RootPane {root_scale}: {have}, expected 1.0') struct.pack_into(' 1e-3: raise SystemExit(f'{layout} {pane} {field}: {have}, expected {shipped}') struct.pack_into('