diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md index 2a07768d..862bed1a 100644 --- a/THIRD_PARTY_NOTICES.md +++ b/THIRD_PARTY_NOTICES.md @@ -10,6 +10,7 @@ Code copied or adapted from another project is listed here with its source, the | MacNativeGames TotK host runtime: dynamic linking, identity check, module permissions, guest memory and SVCs, threads, IPC, audio renderer, system services, RomFS and save storage, boot sequence, the NVN proc name list | https://github.com/ly05010419/MacNativeGames @ `b75be8cfa704df3701e86130c8ced268e79d6b11` (`games/totk/runtime/`, `games/totk/scripts/prepare_runtime.py`), Copyright (c) 2026 MacNativeGames contributors | MIT | `runtime/loader.c`, `runtime/memory.c`; `runtime/kernel.c`, `runtime/svc.c`, `runtime/ipc.c`, `runtime/ipc.h`, `runtime/audren.c`, `runtime/audren.h`, `runtime/audio_mixer.c`, `runtime/audio_effects.c`, `runtime/audio_effects.h`, `runtime/audio_reverb.c`, `runtime/audio_reverb.h` (SDL3 output replaces CoreAudio), `runtime/ov_system.c` (also `shared_font.c`: the BFTTF layout behind nn::pl), `runtime/ov_input.c` (also `hid_feedback.c`: vibration and six-axis handles and calls), `runtime/motion_fusion.c` (six-axis fusion of `motion_fusion.c`), `runtime/ov_media.c` (hardware Opus decoder over libopus), `runtime/swkbd_win.c` (`swkbd_host.c`: ShowKeyboardArg offsets, UTF-8/UTF-16 conversion, disabled-key filter, result codes; Win32 window replaces the macOS text bar), `runtime/ov_gfx.c`, `runtime/romfs.c`, `runtime/romfs_path.h`, `runtime/fs_host.c`, `runtime/fs.h`, `runtime/boot.c`; `runtime/gfx_window.c`; `tools/gen_nvn_procs.py`, `runtime/nvn_procs.inc` (`NVN/names.txt` and the `NVN_EXTRA` names of `totk_nvn_ext.c`) | | MacNativeGames TotK frame-rate patches: 60 fps present-interval controller, real-time frame step and its present sampling, hair and cloth clock, trampoline slow-motion check (instruction words and 1.2.1 sites), player position chain; quick-menu capture background RomFS overlay | https://github.com/ly05010419/MacNativeGames @ `ebe621de99bfc48f3c42f2d2aa73e04fbcc6eae2` (`games/totk/runtime/game_patches.c`, `game_version.h`, `world_survey.c`, `games/totk/scripts/make_romfs_patches.py`), Copyright (c) 2026 MacNativeGames contributors | MIT | `runtime/frame_rate.c`, `recomp/patches-v121.txt`, `tools/make_romfs_patches.py` | | MacNativeGames TotK 1.4.3 fade fix: the four distance / LOD and pre-actor fade sites, their instruction words and the floor of the fade step at 1 | https://github.com/ly05010419/MacNativeGames @ `3e9e7f67fdfdd3404134dcfa0f24969a9425a33f` (`games/totk/runtime/game_patches_v143.c` patch_fade_increment), Copyright (c) 2026 MacNativeGames contributors | MIT | `recomp/patches-v143.txt` (set fade; the floor without flags, clz >> 5, as in pull request #78) | +| MacNativeGames TotK aspect ratio: the camera and viewport sites that hand the perspective projection its aspect ratio, and the UI layout edits for a canvas wider than 16:9 | https://github.com/ly05010419/MacNativeGames @ `933b6a0d1438de160208a0a13eb5e8d7a2cb8094` (`games/totk/runtime/aspect_patch.h`, `aspect_math.h`, `game_patches_v143.c`, `games/totk/scripts/ultrawide_layout.py`), Copyright (c) 2026 MacNativeGames contributors | MIT | `recomp/patches-v143.txt` (set aspect), `tools/ultrawide_layout.py`, `tools/make_romfs_patches.py` (--aspect) | | MacNativeGames TotK virtual-core preemption: asynchronous preemption of an owner in top-level game code, priority inheritance through guest mutexes, the SDK's preemption-disable protocol (TLR+0x100/+0x102, SVC 0x36), the core-wait diagnostics | https://github.com/ly05010419/MacNativeGames @ `33e8fa83052ea1ae09a3583137008e9797e12950` (`games/totk/runtime/threads.c`, commits 8bf0893 and 19730cd), Copyright (c) 2026 MacNativeGames contributors | MIT | `runtime/kernel.c` (SuspendThread and a register-saving stub replace SIGUSR2), `runtime/hostfn.c`, `runtime/svc.c` (host depth) | | MacNativeGames RomFS index builder (`TOTKRFS1` layout) | https://github.com/ly05010419/MacNativeGames @ `b75be8cfa704df3701e86130c8ced268e79d6b11` (`games/totk/scripts/prepare_romfs_backend.py`), Copyright (c) 2026 MacNativeGames contributors | MIT | `tools/romfs_index.py` | | d2r-mobile host thread environment (TLR, TLS, thread object), the origin of MacNativeGames' thread layer; d2r-mobile NVN host object layouts, command record format and NVN front end, as adapted for TotK in MacNativeGames' `d2r_gfx` copy | https://github.com/jhaizhou-ops/d2r-mobile @ `53e7c5bb9ca3ea53e2160005be8fbe920cd9cb53` (`dm/host/thread.c`, `dm/host/hle_thread.c`); the NVN layouts and front end via https://github.com/ly05010419/MacNativeGames @ `b75be8cfa704df3701e86130c8ced268e79d6b11` (`games/totk/third_party/d2r_gfx/gfx/nvn/nvn_obj.h`, the two types of `nvn_tex.h`, `hle_nvn.c`, `totk_nvn_ext.c`, `nvn_impl.h`, `nvn_hmap.h`, `nvn_pool_index.h`, the request checks and mapping semantics of `totk_vpool.c`, the generation stamps of `nvn_dirty.c`, texture mirroring and texel copies of `nvn_mtl.m`; licence in `games/totk/third_party/d2r_gfx/LICENSE`), Copyright (c) 2026 jhaizhou | MIT | `runtime/kernel.c`; `runtime/nvn_obj.h`; `runtime/nvn_api.h`, `runtime/nvn_api_core.c`, `runtime/nvn_hmap.h`, `runtime/nvn_pool_index.h`; `runtime/nvn_api_obj.c` (also `nvn_pace.h`); `runtime/nvn_api_cmd.c`, `runtime/nvn_ext.c`; `runtime/vk_memory.c`, `runtime/vk_texture.c`; `runtime/vk_sync.c` (side effects written after GPU completion, `hle_nvn.c`); `runtime/vk_pipeline.c` (pipeline key and state mapping of `nvn_mtl.m` `pso_key_fill` / `pso_desc`, its `vfmt` vertex formats and the missing-varying fix-up of `msl_varyings`); `runtime/vk_exec.c`, `runtime/vk_exec.h` (op loop, pure-state ops and state defaults of `nvn_mtl.m` `mtl_exec` / `state_op` / `state_reset`); `runtime/vk_exec_xfer.c` (copy, clear, event, counter and conditional-render semantics of `nvn_mtl.m` `copy_t2b` / `copy_b2t` / `copy_t2t` / `clear_tex` / `cond_eval`); `runtime/vk_exec_draw.c` (bind ops, draw and dispatch flow, vertex streams of `nvn_mtl.m` `state_op` / `bind_vertex_streams` / `draw_inner` / `dispatch`) | diff --git a/installer/layout.py b/installer/layout.py index affcb63b..3ff47139 100644 --- a/installer/layout.py +++ b/installer/layout.py @@ -72,7 +72,8 @@ class Layout: def missing(self): """Paths the steps need that do not exist.""" need = [self.python, self.tools / 'extract.py', self.tools / 'build_game.py', self.tools / 'prepare_shaders.py', - self.tools / 'pack_shader_cache.py', self.tools / 'make_romfs_patches.py', self.recomp / 'gen.py', + self.tools / 'pack_shader_cache.py', self.tools / 'make_romfs_patches.py', self.tools / 'ultrawide_layout.py', + self.recomp / 'gen.py', self.clang, self.deps / 'include', self.deps / 'lib', self.runtime, self.runtime_lib, self.ninja, self.hactool, self.xlate, *self.dlls, *(f(v) for v in SUPPORTED for f in (self.patches, self.expected))] diff --git a/installer/steps.py b/installer/steps.py index b2109fa1..b22dacf3 100644 --- a/installer/steps.py +++ b/installer/steps.py @@ -581,6 +581,9 @@ class Compile(Step): TRANSLATED = re.compile(r'gfx_shader: prepare: (\d+) of (\d+) pairs') +WIDE_SIZES = ('2560x1080', '3440x1440', '3840x1600', '5120x2160') # runtime/ui/menu.cpp row_output_res + + class Prepare(Step): id = 'prepare' @@ -588,7 +591,7 @@ class Prepare(Step): layout = ctx.layout xlate_id = layout.xlate.with_suffix('.id') tools = [layout.tools / n for n in ('prepare_shaders.py', 'shader_census.py', 'make_romfs_patches.py', - 'pack_shader_cache.py')] + 'pack_shader_cache.py', 'ultrawide_layout.py')] return fingerprint('prepare-1', ctx.keys['compile'], layout.xlate, xlate_id, shader_list_text(layout), *tools) def current(self, ctx, record): @@ -618,6 +621,15 @@ 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) + for size in WIDE_SIZES: + remove(dest / f'romfs-patches-{size}') + code, log = run_tool(ctx, 'prepare', layout.tools / 'make_romfs_patches.py', + ['--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)) shader_list = layout.shader_list if not shader_list: diff --git a/recomp/patches-v143.txt b/recomp/patches-v143.txt index 498af650..34b5c0ad 100644 --- a/recomp/patches-v143.txt +++ b/recomp/patches-v143.txt @@ -73,6 +73,18 @@ site scene main 585e50 bd0cc660 2d420460 # str s0, [x19, #0xcc4] -> ldp s0, s site scene main 585e54 1e220140 bd0cc660 # scvtf s0, w10 -> str s0, [x19, #0xcc4] site scene main 585e60 bd0cca60 bd0cca61 # str s0, [x19, #0xcc8] -> str s1, [x19, #0xcc8] +# Camera aspect ratio for a game resolution that is not 16:9 (upstream game_patches_v143.c and aspect_patch.h +# aspect_install / aspect_stub; runtime/resolution.c res_init writes the output's width / height to page +56 and +# switches the set on). Each site leaves the ratio sead's perspective projection (+0xb0) takes in s0: 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, so a 21:9 output shows more of the world at the sides with +# the vertical view kept (Hor+). x10 is kept on the stack, so no register liveness is assumed. +set aspect TOTK_ASPECT_PATCH 0 +site aspect main 628c74 bd414260 f81f0fea @page:x10 bd403940 f84107ea # ldr s0, [x19, #0x140] (camera update) +site aspect main b43460 bd406ac0 f81f0fea @page:x10 bd403940 f84107ea # ldr s0, [x22, #0x68] (camera setup) +site aspect main 1ff04f4 1e211800 f81f0fea @page:x10 bd403940 f84107ea # fdiv s0, s0, s1 (viewport) +site aspect main 253fbb0 1e211800 f81f0fea @page:x10 bd403940 f84107ea # fdiv s0, s0, s1 (viewport) + # The game's zstd decoder (BSD zstd, statically linked into main) through the host's libzstd (runtime/ov_zstd.c): # every call of ZSTD_decompressMultiFrame (main+0x3a1f0: dctx, dst, capacity, src, size, dict, dict size, ddict) and of # its wrapper ZSTD_decompress_usingDDict (main+0x3a1e0, which tail-branches to it) goes to a host function on the patch diff --git a/runtime/cfg.c b/runtime/cfg.c index 417513e0..1cfbd56a 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -30,7 +30,7 @@ static int save_ok = 1; // the last cfg_save_to wrote (o // Every name the runtime reads (and the patch sets in generated/), without the prefix. A file key outside this list is // logged as unknown. A new variable goes here too, or its ini key logs a harmless "unknown key" line. static const char *const known[] = { - "AB", "APP_POOL", "ASSUME_FOCUS", "ASTC", "ASTC_BC", "ASTC_TIME", "ASYNC_PREEMPT", "AUDIO", "AUDIO_OFF", "AUDIO_PREFILL_MS", + "AB", "APP_POOL", "ASPECT", "ASPECT_PATCH", "ASSUME_FOCUS", "ASTC", "ASTC_BC", "ASTC_TIME", "ASYNC_PREEMPT", "AUDIO", "AUDIO_OFF", "AUDIO_PREFILL_MS", "BACKGROUND_WINDOW", "BIND_A", "BIND_B", "BIND_DOWN", "BIND_L", "BIND_LCLICK", "BIND_LEFT", "BIND_LSTICK_DOWN", "BIND_LSTICK_LEFT", "BIND_LSTICK_RIGHT", "BIND_LSTICK_UP", "BIND_MINUS", "BIND_PLUS", "BIND_R", "BIND_RCLICK", "BIND_RIGHT", "BIND_RSTICK_DOWN", "BIND_RSTICK_LEFT", "BIND_RSTICK_RIGHT", "BIND_RSTICK_UP", @@ -59,7 +59,7 @@ static const struct { const char *key, *section; } sections[] = { {"REALTIME", "frame rate"}, {"CLOTH_REALTIME", "frame rate"}, {"HIGHFPS_FIX", "frame rate"}, {"FULLSCREEN", "display"}, {"WINDOW_SIZE", "display"}, {"PERF_OVERLAY", "display"}, {"VK_PRESENT", "display"}, {"GPU_INDEX", "display"}, {"OUTPUT_RES", "display"}, {"RENDER_SCALE", "display"}, {"UPSCALER", "display"}, - {"SHARPNESS", "display"}, + {"SHARPNESS", "display"}, {"ASPECT", "display"}, {"MENU_LANG", "language"}, {"LANG", "language"}, {"OPERATION_MODE", "language"}, {"VOLUME", "audio"}, {"MOTION", "input"}, {"RUMBLE_STRENGTH", "input"}, {"RUMBLE_CURVE", "input"}, {"RUMBLE_TRIGGERS", "input"}, @@ -94,6 +94,7 @@ static const CfgMeta metas[] = { {"PERF_OVERLAY", "off", "off|fps|full", LIVE}, {"OUTPUT_RES", "1920x1080", NULL, RESTART}, {"RENDER_SCALE", "game", "game|50|67|75|100|125|150|200", RESTART}, {"UPSCALER", "fsr", "fsr|bilinear", LIVE}, {"SHARPNESS", "80", "0..100", LIVE}, + {"ASPECT", "fit", "fit|stretch", LIVE}, // Game {"FPS_LIMIT", "60", "30|60|90|120|144|display", LIVE}, {"FPS60", "1", "0|1", LIVE}, {"REALTIME", "1", "0|1", RESTART}, {"CLOTH_REALTIME", "1", "0|1", RESTART}, diff --git a/runtime/gfx_window.c b/runtime/gfx_window.c index 718474b3..021c53c0 100644 --- a/runtime/gfx_window.c +++ b/runtime/gfx_window.c @@ -796,6 +796,27 @@ static void save_capture(const char *path) { rt_log("gfx: menu test shot %s (%dx%d)", path, g_cap_w, g_cap_h); } +// Where the game's picture (cw x ch) goes on the sw x sh swapchain: TOTK_ASPECT=fit (default) keeps its shape and centres +// it, with black bars at the sides (a 16:9 picture in a 21:9 window) or above and below; stretch fills the swapchain. +// Bars under a pixel are not drawn. Returns 1 when the rectangle leaves bars to clear. +static int fit_rect(int cw, int ch, int sw, int sh, int out[4]) { + out[0] = 0, out[1] = 0, out[2] = sw, out[3] = sh; + if (cw <= 0 || ch <= 0 || strcmp(cfg_value("TOTK_ASPECT"), "fit")) return 0; + long long a = (long long)cw * sh, b = (long long)ch * sw; + if (a < b) { // narrower than the window: bars at the sides + int fw = (int)((a + ch / 2) / ch); + if (fw >= sw - 1) return 0; + out[0] = (sw - fw) / 2, out[2] = fw; + } else if (a > b) { // wider: bars above and below + int fh = (int)(((long long)ch * sw + cw / 2) / cw); + if (fh >= sh - 1) return 0; + out[1] = (sh - fh) / 2, out[3] = fh; + } else { + return 0; + } + return 1; +} + static void present_image(VkImage src, VkImageLayout layout, VkFormat fmt, int w, int h, const int crop[4], int defer) { int general = layout == VK_IMAGE_LAYOUT_GENERAL; gfx_window_start(); @@ -855,16 +876,26 @@ static void present_image(VkImage src, VkImageLayout layout, VkFormat fmt, int w sync_barrier(cb, dst, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_PIPELINE_STAGE_2_TRANSFER_BIT, 0, VK_PIPELINE_STAGE_2_TRANSFER_BIT, VK_ACCESS_2_TRANSFER_WRITE_BIT); const int rect[4] = {cx, cy, cw, ch}; - // FSR (TOTK_UPSCALER) when the swapchain is larger than the crop; else the bilinear blit - int fsr = general && vk_fsr_record(cb, slot, src, fmt, w, h, rect, dst, g_sc_ext.width, g_sc_ext.height); - g_scaler = fsr ? 2 : (uint32_t)cw != g_sc_ext.width || (uint32_t)ch != g_sc_ext.height; + int to[4]; + if (fit_rect(cw, ch, (int)g_sc_ext.width, (int)g_sc_ext.height, to)) { + // black bars: clear the whole image, then the picture's writes below wait for the clear + VkClearColorValue black = {{0, 0, 0, 1}}; + VkImageSubresourceRange all = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; + vkCmdClearColorImage(cb, dst, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &black, 1, &all); + sync_barrier(cb, dst, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + VK_PIPELINE_STAGE_2_TRANSFER_BIT, VK_ACCESS_2_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_2_TRANSFER_BIT, + VK_ACCESS_2_TRANSFER_WRITE_BIT); + } + // FSR (TOTK_UPSCALER) when the picture's place on the swapchain is larger than the crop; else the bilinear blit + int fsr = general && vk_fsr_record(cb, slot, src, fmt, w, h, rect, dst, to); + g_scaler = fsr ? 2 : cw != to[2] || ch != to[3]; if (!fsr) { if (general) // a GENERAL source (vk_texture.c images): earlier submissions' writes become visible to the blit here sync_barrier(cb, src, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL, VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT, VK_ACCESS_2_MEMORY_WRITE_BIT, VK_PIPELINE_STAGE_2_TRANSFER_BIT, VK_ACCESS_2_TRANSFER_READ_BIT); VkImageBlit region = { .srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, .srcOffsets = {{cx, cy, 0}, {cx + cw, cy + ch, 1}}, - .dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, .dstOffsets = {{0, 0, 0}, {(int)g_sc_ext.width, (int)g_sc_ext.height, 1}}}; + .dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, .dstOffsets = {{to[0], to[1], 0}, {to[0] + to[2], to[1] + to[3], 1}}}; vkCmdBlitImage(cb, src, general ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, dst, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion, VK_FILTER_LINEAR); if (general) // later submissions that write the source wait for the blit's read diff --git a/runtime/host.h b/runtime/host.h index 262b7b98..7bbfe5ed 100644 --- a/runtime/host.h +++ b/runtime/host.h @@ -242,6 +242,7 @@ void res_heapdef_served(void); // romfs.c serves the void res_init(void); // after rt_patches_init: the patch page and the sets void res_sizes(unsigned out[2], unsigned scene[2]); // the output and scene sizes in effect (the game's own // until res_init switched the sets on) +void res_wanted(unsigned out[2]); // the output size TOTK_OUTPUT_RES asks for // ---- code patches (patches.c) and the frame step (frame_rate.c) void rt_patches_init(void); // after ldr_load: switches from the environment, the patch // page committed; logs the sets diff --git a/runtime/resolution.c b/runtime/resolution.c index 2e4b1d7c..11ddd91c 100644 --- a/runtime/resolution.c +++ b/runtime/resolution.c @@ -12,6 +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). // 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 @@ -218,10 +219,33 @@ 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 + // 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"); + if (ratio / game < 0.99 || ratio / game > 1.01) { + if (aspect < 0) { + rt_log("resolution: output %ux%u is not 16:9 and this game version has no camera aspect patch; the view " + "is stretched", R.ow, R.oh); + } else { + float r = (float)ratio; + memcpy(page + 56, &r, sizeof r); + rt_patch_switch(aspect, 1); + rt_log("resolution: camera aspect ratio %.4f (16:9 is %.4f)", ratio, game); + } + } else { + rt_patch_switch(aspect, 0); // the page holds no ratio + } rt_log("resolution: output %ux%u, scene %ux%u%s; texture heap +%llu KiB", R.ow, R.oh, R.sw, R.sh, scene_on ? "" : " (the game's own 5/6 of the output)", (unsigned long long)res_heap_extra_kib()); } +void res_wanted(unsigned out[2]) { + decide(); + out[0] = R.ow, out[1] = R.oh; +} + void res_sizes(unsigned out[2], unsigned scene[2]) { decide(); out[0] = R.on ? R.ow : BASE_W, out[1] = R.on ? R.oh : BASE_H; diff --git a/runtime/romfs.c b/runtime/romfs.c index 0d7aee5b..e754e8f8 100644 --- a/runtime/romfs.c +++ b/runtime/romfs.c @@ -408,9 +408,23 @@ static void heapdef_overlay(void) { } 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) + // 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). char def[2100]; const char *patches = cfg_get("TOTK_ROMFS_PATCHES"); + unsigned out[2]; + res_wanted(out); + if (!patches && (unsigned long long)out[0] * 9 != (unsigned long long)out[1] * 16) { + if (snprintf(def, sizeof def, "%s/romfs-patches-%ux%u/manifest.tsv", index_dir, out[0], out[1]) < (int)sizeof def && + GetFileAttributesA(def) != INVALID_FILE_ATTRIBUTES) { + def[strlen(def) - strlen("/manifest.tsv")] = 0; + patches = def; + } else { + rt_log("RomFS overlay: no romfs-patches-%ux%u for this game resolution, the UI keeps its 16:9 layout " + "(tools/make_romfs_patches.py --aspect %ux%u)", out[0], out[1], out[0], out[1]); + } + } if (!patches && 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; diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index 45c4428e..1b0adbe8 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -414,10 +414,12 @@ static void row_window_size(void) { opt_choice_list("TOTK_WINDOW_SIZE", UI_MENU_WINDOW_SIZE, pv, pn, n, UI_MENU_WINDOW_SIZE_DESC); } -// The game resolution (resolution.c): 16:9 sizes from its smallest, 1280x720 (for weak GPUs), up, and the current value -// when it is another size. +// The game resolution (resolution.c): 16:9 sizes from its smallest, 1280x720 (for weak GPUs), up, the common 21:9 +// monitor sizes (the camera and the HUD follow a wider shape, resolution.c res_init), 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"}; + static const char *const vals[] = {"1280x720", "1600x900", "1920x1080", "2560x1440", "3200x1800", "3840x2160", + "2560x1080", "3440x1440", "3840x1600", "5120x2160"}; enum { N = sizeof vals / sizeof *vals }; char shown[N][32]; const char *names[N]; @@ -534,6 +536,8 @@ static void tab_screen(float scale) { static const UiTextId up[] = {UI_MENU_UPSCALER_FSR, UI_MENU_UPSCALER_BILINEAR}; opt_choice("TOTK_UPSCALER", UI_MENU_UPSCALER, up, 2, UI_MENU_UPSCALER_DESC); opt_slider("TOTK_SHARPNESS", UI_MENU_SHARPNESS, 0, 100, UI_MENU_SHARPNESS_DESC, 5, "%.0f %%"); + static const UiTextId aspect[] = {UI_MENU_ASPECT_FIT, UI_MENU_ASPECT_STRETCH}; + opt_choice("TOTK_ASPECT", UI_MENU_ASPECT, aspect, 2, UI_MENU_ASPECT_DESC); opt_end(); } diff --git a/runtime/ui_text.c b/runtime/ui_text.c index 33be5f0c..c7e29566 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -52,7 +52,8 @@ static const char *const text_en[UI_TEXT_COUNT] = { [UI_MENU_GRAPHICS] = "Picture", [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.", + "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.", [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.", @@ -61,6 +62,10 @@ static const char *const text_en[UI_TEXT_COUNT] = { [UI_MENU_UPSCALER_DESC] = "How the picture is scaled when the window is larger than the game resolution. FSR keeps " "edges and detail sharper than bilinear.", [UI_MENU_UPSCALER_FSR] = "AMD FSR 1", [UI_MENU_UPSCALER_BILINEAR] = "Bilinear", + [UI_MENU_ASPECT] = "Picture shape", + [UI_MENU_ASPECT_DESC] = "When the window's shape differs from the game resolution's (a 16:9 picture on a 21:9 " + "screen): keep the picture's shape with black bars, or stretch it over the window.", + [UI_MENU_ASPECT_FIT] = "Black bars", [UI_MENU_ASPECT_STRETCH] = "Stretch", [UI_MENU_SHARPNESS] = "FSR sharpness", [UI_MENU_SHARPNESS_DESC] = "Sharpening after FSR scaling; 0 turns it off.", @@ -276,7 +281,8 @@ static const char *const text_ru[UI_TEXT_COUNT] = { [UI_MENU_GRAPHICS] = "Изображение", [UI_MENU_OUTPUT_RES] = "Разрешение игры", [UI_MENU_OUTPUT_RES_DESC] = "Размер, в котором игра рисует картинку и интерфейс. Выше 1920 × 1080 игре нужно больше " - "видеопамяти и времени GPU.", + "видеопамяти и времени GPU. Более широкий размер (21:9) расширяет обзор камеры и " + "переносит интерфейс в углы экрана.", [UI_MENU_RENDER_SCALE] = "Масштаб 3D-отрисовки", [UI_MENU_RENDER_SCALE_DESC] = "Размер 3D-сцены относительно разрешения игры; FSR игры доводит её до этого размера. " "Выше 100 % сглаживает лесенки на краях (суперсэмплинг) ценой большой нагрузки на GPU.", @@ -285,6 +291,10 @@ static const char *const text_ru[UI_TEXT_COUNT] = { [UI_MENU_UPSCALER_DESC] = "Как картинка растягивается, когда окно больше разрешения игры. FSR сохраняет края и " "детали чётче билинейного.", [UI_MENU_UPSCALER_FSR] = "AMD FSR 1", [UI_MENU_UPSCALER_BILINEAR] = "Билинейное", + [UI_MENU_ASPECT] = "Форма картинки", + [UI_MENU_ASPECT_DESC] = "Когда форма окна отличается от разрешения игры (картинка 16:9 на экране 21:9): сохранить " + "форму картинки с чёрными полосами или растянуть её на всё окно.", + [UI_MENU_ASPECT_FIT] = "Чёрные полосы", [UI_MENU_ASPECT_STRETCH] = "Растянуть", [UI_MENU_SHARPNESS] = "Резкость FSR", [UI_MENU_SHARPNESS_DESC] = "Повышение резкости после масштабирования FSR; 0 выключает его.", diff --git a/runtime/ui_text.h b/runtime/ui_text.h index 8df6ff0f..a5d7f0e4 100644 --- a/runtime/ui_text.h +++ b/runtime/ui_text.h @@ -35,6 +35,7 @@ typedef enum { UI_MENU_OUTPUT_RES, UI_MENU_OUTPUT_RES_DESC, UI_MENU_RENDER_SCALE, UI_MENU_RENDER_SCALE_DESC, UI_MENU_RENDER_SCALE_GAME, UI_MENU_UPSCALER, UI_MENU_UPSCALER_DESC, UI_MENU_UPSCALER_FSR, UI_MENU_UPSCALER_BILINEAR, + UI_MENU_ASPECT, UI_MENU_ASPECT_DESC, UI_MENU_ASPECT_FIT, UI_MENU_ASPECT_STRETCH, UI_MENU_SHARPNESS, UI_MENU_SHARPNESS_DESC, // Game diff --git a/runtime/vk.h b/runtime/vk.h index 916a2b5c..40ff9c4d 100644 --- a/runtime/vk.h +++ b/runtime/vk.h @@ -100,11 +100,11 @@ void vk_present_image(VkImage src, VkImageLayout layout, VkFormat fmt, int w, in // vk_present_image split in two: vk_present_blit submits the blit and leaves the present waiting, vk_present_flip // queues it. The next blit or a swapchain rebuild queues a waiting present first. void vk_present_blit(VkImage src, VkImageLayout layout, VkFormat fmt, int w, int h, const int crop[4]); -// FSR 1 on the present (vk_fsr.c): records EASU (+ RCAS) of src's crop rectangle {x, y, w, h} into dst, a dw x dh -// swapchain image in TRANSFER_DST; src is in GENERAL and fmt its format. 0 = nothing recorded (the setting says -// bilinear, no upscale is needed, or FSR is not available): the caller blits. +// FSR 1 on the present (vk_fsr.c): records EASU (+ RCAS) of src's crop rectangle {x, y, w, h} into the rectangle out +// {x, y, w, h} of dst, a swapchain image in TRANSFER_DST; src is in GENERAL and fmt its format. 0 = nothing recorded +// (the setting says bilinear, no upscale is needed, or FSR is not available): the caller blits. int vk_fsr_record(VkCommandBuffer cb, unsigned slot, VkImage src, VkFormat fmt, int sw, int sh, const int crop[4], - VkImage dst, uint32_t dw, uint32_t dh); + VkImage dst, const int out[4]); void vk_fsr_release(void); // before the device goes away void vk_present_flip(void); // Every submission to ctx->gfx_queue (and xfer_queue when shared) takes this lock; vk_present_image and the swapchain diff --git a/runtime/vk_fsr.c b/runtime/vk_fsr.c index b88ac12c..5b4f50ac 100644 --- a/runtime/vk_fsr.c +++ b/runtime/vk_fsr.c @@ -4,8 +4,9 @@ // both apply at the next frame. // // Per frame: EASU reads the source through a view of its own format (the same colour conversion the blit does) and -// writes an RGBA16F image of the swapchain size; RCAS reads that and writes a second one; a 1:1 blit converts the -// result into the swapchain image, which the caller left in TRANSFER_DST. The shaders (runtime/shaders/fsr_*.comp) +// writes an RGBA16F image of the picture's size on the swapchain (all of it, or the part between black bars, +// gfx_window.c fit_rect); RCAS reads that and writes a second one; a 1:1 blit converts the result into its place in +// the swapchain image, which the caller left in TRANSFER_DST. The shaders (runtime/shaders/fsr_*.comp) // compute AMD's constants from the push constants. Cost: two compute passes over the swapchain size and one copy per // present; nothing on the game's draws. // @@ -156,8 +157,9 @@ static void bind_pass(VkCommandBuffer cb, VkPipeline p, VkImageView in, VkImageV } int vk_fsr_record(VkCommandBuffer cb, unsigned slot, VkImage src, VkFormat fmt, int sw, int sh, const int crop[4], - VkImage dst, uint32_t dw, uint32_t dh) { + VkImage dst, const int out[4]) { int cw = crop[2], ch = crop[3]; + uint32_t dw = (uint32_t)out[2], dh = (uint32_t)out[3]; if (strcmp(cfg_value("TOTK_UPSCALER"), "fsr") || (dw <= (uint32_t)cw && dh <= (uint32_t)ch) || !fmt) return 0; VkCtx *c = vk_ctx(); if (!F.tried) init(c); @@ -208,7 +210,7 @@ int vk_fsr_record(VkCommandBuffer cb, unsigned slot, VkImage src, VkFormat fmt, VkImageBlit region = {.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, .srcOffsets = {{0, 0, 0}, {(int)dw, (int)dh, 1}}, .dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, - .dstOffsets = {{0, 0, 0}, {(int)dw, (int)dh, 1}}}; + .dstOffsets = {{out[0], out[1], 0}, {out[0] + (int)dw, out[1] + (int)dh, 1}}}; vkCmdBlitImage(cb, F.img[last], VK_IMAGE_LAYOUT_GENERAL, dst, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion, VK_FILTER_NEAREST); return 1; diff --git a/tools/make_release.py b/tools/make_release.py index 9c3c5f92..067c2b34 100644 --- a/tools/make_release.py +++ b/tools/make_release.py @@ -98,7 +98,8 @@ LLVM_SKIP_SUFFIXES = {'.idl', '.tlb'} # tools/ files the installer steps run (and what they import), copied from the repo. TOOLS_FILES = ['build_game.py', 'build_shaders.py', 'check_content.py', 'extract.py', 'hostmem.py', 'make_romfs_patches.py', - 'pack_shader_cache.py', 'prepare_shaders.py', 'romfs_index.py', 'shader_census.py', 'shader_list.py'] + 'pack_shader_cache.py', 'prepare_shaders.py', 'romfs_index.py', 'shader_census.py', 'shader_list.py', + 'ultrawide_layout.py'] TOOLS_DIRS = ['vendor/macnativegames', 'data'] # data/: expected hashes RUNTIME_SUFFIXES = {'.h', '.inc', '.ico'} # .ico: the installer window icon diff --git a/tools/make_romfs_patches.py b/tools/make_romfs_patches.py index 21ddefff..b059140b 100644 --- a/tools/make_romfs_patches.py +++ b/tools/make_romfs_patches.py @@ -11,12 +11,18 @@ 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). + Input: build/extracted//romfs (romfs.bin and index.json, verified by tools/extract.py). Output: build//romfs-patches/ by default, and /manifest.tsv (path, size, SHA-256 of the overlay, SHA-256 of the original). Run with .venv-py314. """ import argparse import compression.zstd as zstd import hashlib +import importlib.util import json import struct from pathlib import Path @@ -26,6 +32,7 @@ ap = argparse.ArgumentParser(description=__doc__.splitlines()[0]) 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') +ap.add_argument('--aspect', help='x of a game resolution wider than 16:9: also lay the UI out for it') args = ap.parse_args() args.romfs = args.romfs or root / 'build/extracted' / args.version / 'romfs' args.out = args.out or root / 'build' / args.version / 'romfs-patches' @@ -115,8 +122,16 @@ for member, panes in MEMBERS.items(): changed.append(name) assert sorted(changed) == sorted(panes), (member, changed) patched[member] = changed +layout = [] +if args.aspect: + width, height = (int(v) for v in args.aspect.lower().split('x')) + spec = importlib.util.spec_from_file_location('ultrawide_layout', Path(__file__).with_name('ultrawide_layout.py')) + ultrawide = importlib.util.module_from_spec(spec) + spec.loader.exec_module(ultrawide) + layout = ultrawide.apply(blarc, members, width, height) diff = [i for i in range(len(original)) if original[i] != blarc[i]] -assert diff and all(any(lo <= i < hi for lo, hi in (members[m] for m in MEMBERS)) for i in diff), diff +touched = [members[m] for m in (*MEMBERS, *layout)] +assert diff and all(any(lo <= i < hi for lo, hi in touched) for i in diff), diff data = zstd.compress(bytes(blarc), level=19, zstd_dict=dictionary) assert zstd.decompress(data, zstd_dict=dictionary) == bytes(blarc) assert zstd.get_frame_info(data).dictionary_id == info.dictionary_id @@ -126,4 +141,5 @@ target.write_bytes(data) line = '\t'.join([ARCHIVE, str(len(data)), hashlib.sha256(data).hexdigest(), hashlib.sha256(raw).hexdigest()]) (args.out / 'manifest.tsv').write_text('# path\tsize\tsha256\toriginal_sha256 (tools/make_romfs_patches.py)\n' + line + '\n') -print(json.dumps(dict(status='pass', path=ARCHIVE, members=patched, size=len(data), changed_bytes=len(diff)))) +print(json.dumps(dict(status='pass', path=ARCHIVE, members=patched, size=len(data), changed_bytes=len(diff), + ultrawide_layout=dict(aspect=args.aspect, members=len(layout)) if args.aspect else None))) diff --git a/tools/ultrawide_layout.py b/tools/ultrawide_layout.py new file mode 100644 index 00000000..739fca37 --- /dev/null +++ b/tools/ultrawide_layout.py @@ -0,0 +1,141 @@ +# 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 runtime has no UI squeeze of its own, so +# the note below about nvn_mtl.m does not apply here. +"""The game's UI layouts for a canvas wider than 16:9 (TOTK_OUTPUT_RES=3440x1440 with TOTK_ASPECT), edited in place in +the decompressed UI/LayoutArchive/Common.Product.*.blarc (scripts/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; this is an +independent implementation (none of the mod's code), 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. + +The runtime's own UI squeeze (nvn_mtl.m, TOTK_UI_SQUEEZE) must be off with these layouts, or the UI is narrowed twice. +""" +import struct + +# BFLYT pane sections (pan1, pic1, txt1, ...): name at +12 (24 bytes), translate x / y at +44 / +48, scale x / y at +68 / +72. +PANE_MAGICS = (b'pan1', b'pic1', b'txt1', b'wnd1', b'bnd1', b'prt1', b'ali1', b'scr1') +FIELD = {'x': 44, 'y': 48, 'scale_x': 68, 'scale_y': 72} + +# Full-screen layouts whose root pane stays as wide as the canvas. +KEEP_ROOT = {'AppMenuBG_00', 'PauseMenuBG_00', 'ShopMenuParasailBG_00', 'ShortCutBG_00', 'TitleMenuBG_00', 'EventFade_00', + 'EventFadeWipe_00', 'CameraShutter_00', 'PaAppPictureBookDetail_00', 'AppMenuOverlay_00'} + +def edits(k, hud_corner): + """(layout, pane, field, value) for the aspect: k = 16/9 over the aspect (the root's scale), w = how far a 1920-wide + layout's edge moves out in its own units (960 * (1 / k - 1)). OFF moves a pane out of sight.""" + w, OFF = 960 * (1 / k - 1), 10000.0 + wide = 1 / k + out = [ + ('AppAlbum_00', 'N_FadeInOut_00', 'scale_x', k), ('AppAlbum_00', 'N_Open_01', 'scale_x', wide), + *[('AppMap_00', f'N_BlurInOut_0{i}', 'scale_x', wide) for i in range(4)], + ('AppMap_00', 'N_MiniMap_00', 'x', -270 * (1 - k)), + ('AppMenuOverlay_00', 'N_FadeInOut_00', 'scale_x', k), ('AppMenuOverlay_00', 'N_FadeInOut_01', 'scale_x', k), + ('AppMenuOverlay_00', 'N_Icon_00', 'scale_x', k), ('AppMenuOverlay_00', 'N_TitleOne_01', 'scale_x', k), + ('AppOpenDemoWindow_00', 'P_BG_00', 'scale_x', wide), ('AutoBuilder_00', 'N_BG_00', 'scale_x', wide), + ('CameraPointer_00', 'N_InOutScope_00', 'scale_x', wide), ('CameraPointer_00', 'N_InOutScope_00', 'scale_y', wide), + ('CameraPointer_00', 'N_Type_01', 'scale_x', k), ('CameraPointer_00', 'Pa_CameraFocus_00', 'scale_x', wide), + ('CameraPointer_00', 'S_Scissor_00', 'scale_x', wide), ('CameraPointer_00', 'W_Shadow_01', 'scale_x', wide), + ('CameraSystemWindow_00', 'N_AlbumCon_00', 'scale_x', k), ('CameraSystemWindow_00', 'N_InOut_00', 'scale_x', wide), + ('CameraSystemWindow_00', 'Pa_BtnL_00', 'scale_x', k), ('CameraSystemWindow_00', 'Pa_BtnR_00', 'scale_x', k), + ('CameraSystemWindow_00', 'T_Text_00', 'scale_x', k), + ('ChallengeLog_00', 'C_CaptureUp_00', 'x', OFF), ('ChallengeLog_00', 'C_CaptureUp_01', 'x', OFF), + ('GameOver_00', 'P_BG_00', 'scale_x', wide), + ('LoadingFade_00', 'N_Base_00', 'scale_x', wide), ('LoadingFade_00', 'N_Logo_00', 'x', w), + ('LoadingFade_00', 'N_Status_00', 'x', w), ('LoadingFade_00', 'N_Tips_00', 'x', -w), + ('LoadingFade_00', 'P_BG_00', 'scale_x', wide), ('LoadingFade_00', 'P_SideBGDeco_00', 'scale_x', k), + ('LoadingFade_00', 'Pa_IconPlayer_00', 'scale_x', k), ('LoadingFade_00', 'Pa_LargeDungeonMap_00', 'scale_x', k), + ('LoadingFade_00', 'Pa_LargeDungeonMap_01', 'scale_x', k), ('LoadingFade_00', 'Pa_Map_00', 'scale_x', k), + ('LoadingFade_00', 'Pa_Map_01', 'scale_x', k), + ('MessageLog_01', 'P_Capture_00', 'scale_x', wide), ('OwnedHorseList_00', 'N_BG_00', 'scale_x', wide), + ('PaCommonBtnTitle_00', 'B_Hit_00', 'x', OFF), ('PaCommonBtnTitle_00', 'N_Cursor_00', 'x', OFF), + ('PaLargeDungeonMap_00', 'P_BG_00', 'scale_x', wide), ('PaMessageBtn_00', 'B_Hit_00', 'x', OFF), + ('PaRecipeCardList_00', 'P_BG_00', 'scale_x', wide), + ('SaveLoadIcon_00', 'RootPane', 'x', -960 * (1 - k)), + ('ShopMenu_00', 'N_BG_00', 'scale_x', wide), ('StaffRoll_00', 'N_BG_00', 'scale_x', wide), + ] + # Menus framed by two side decorations, a header and a background: the frame stays at the screen's edges. + for layout, deco in (('PauseMenuOverlay_00', 'P_Deco{}_00'), ('SystemLoadList_00', 'P_Deco{}_00'), + ('SystemOption_00', 'P_Deco{}_00'), ('SystemSaveLoad_00', 'P_Deco{}_00')): + out += [(layout, deco.format('L'), 'scale_x', k), (layout, deco.format('L'), 'x', -(675 + w) * k), + (layout, deco.format('R'), 'scale_x', k), (layout, deco.format('R'), 'x', (737 + w) * k)] + if layout == 'PauseMenuOverlay_00': + out += [(layout, 'P_FooterBase_00', 'scale_x', wide), (layout, 'S_DecoScissor_00', 'scale_x', wide)] + else: + out += [(layout, 'A_Title_00', 'scale_x', k), (layout, 'N_Header_00', 'scale_x', wide), + (layout, 'N_SystemBG_00', 'scale_x', wide)] + out += [('SystemActionGuide_00', 'A_Title_00', 'scale_x', k), ('SystemActionGuide_00', 'N_Header_00', 'scale_x', wide), + ('SystemActionGuide_00', 'N_SystemBG_00', 'scale_x', wide), + ('SystemActionGuide_00', 'P_DecoL_01', 'scale_x', k), ('SystemActionGuide_00', 'P_DecoL_01', 'x', -(675 + w) * k), + ('SystemActionGuide_00', 'P_DecoL_02', 'scale_x', k), ('SystemActionGuide_00', 'P_DecoL_02', 'x', (675 + w) * k)] + if hud_corner: # the HUD in the screen's corners instead of the middle 16:9 + right = 960 * (1 - k) + out += [(name, 'RootPane', 'x', right) for name in ('EnvironmentInfo_00', 'EventSkip_00', 'InstantTipsAppMenu_00', + 'InstantTipsWithPict_00', 'InstantTips_00', 'NumDisplaySecond_00', + 'NumDisplay_00', 'PickUpWin_00')] + out += [('Location_00', 'N_Small_00', 'x', -(388 + w)), + ('PlayerStatus3D_00', 'N_ExtraStaminaTarget_01', 'x', -(745 + w)), + ('PlayerStatus_00', 'N_DevilDemoTargetC_00', 'x', -(284 + w)), + ('PlayerStatus_00', 'N_DevilDemoTargetLT_00', 'x', -(576 + w)), + ('PlayerStatus_00', 'N_HeartGaugeTargetLT_00', 'x', -(576 + w)), + ('PlayerStatus_00', 'N_HeartPos_00', 'x', -w), + ('PlayerStatus_00', 'Pa_CompanionLife_00', 'x', -(840 + w))] + return out + +def anim_edits(k, hud_corner): + """(animation, byte offset, value the game ships, new value): floats inside BFLAN key tables.""" + w = 960 * (1 / k - 1) + out = [('PaMapIconDragonTears_00_Zoom', 288, 1.08, 1.08 / k), ('PaMapIconDragonTears_00_Zoom', 300, 1.28, 1.28 / k)] + if hud_corner: # the minimap's slide-in keys end at x 765, the right edge of a 16:9 layout + out += [('AppMap_00_MiniMap', o, 765.0, 765 + w) for o in (872, 880, 1628, 1636, 3264, 3272, 3468, 3476)] + return out + +def panes(blarc, lo, hi): + """pane name -> absolute section offset, first occurrence, for the BFLYT at blarc[lo:hi].""" + assert blarc[lo:lo + 4] == b'FLYT', 'not a BFLYT' + head, count = struct.unpack_from(' 1e-3: raise SystemExit(f'{layout} {pane} {field}: {have}, expected {shipped}') + struct.pack_into(' hi - lo: raise SystemExit(f'{anim}: too short for +{offset}') + have = struct.unpack_from('= 1e-4: raise SystemExit(f'{anim} +{offset}: {have}, expected {shipped}') + struct.pack_into('