Add hud_width to keep the HUD narrower than a wide screen

On a game resolution wider than 16:9, hud_width = 21:9 or 16:9 keeps the HUD within the middle 21:9 or 16:9 of the
screen instead of its left and right edges; full, the default, is the old behaviour. tools/ultrawide_layout.py takes
the HUD's aspect in place of the corner flag and moves the HUD panes out only as far as that area, and
make_romfs_patches.py --hud writes the layout as romfs-patches-<w>x<h>-hud21x9 or -hud16x9. The runtime loads that
folder when the setting asks for it (the plain shaped folder otherwise, with a log line naming the command that
makes the missing one), the settings menu offers the choices that fit the game resolution, and the installer builds
the folders for every size wider than 16:9 (and wider than 2.5 for 21:9).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ProSepandClaude Sonnet 5.5 authored and Marjaperse committed 2026-11-17 03:28:55 +02:00
1 parent f85058070e
commit 757ee0b2bf
11 files changed
+240 -81

No files matched your search

+29 -6
View File
@@ -16,6 +16,9 @@ for that shape (tools/ultrawide_layout.py): menus keep their 16:9 proportions in
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-<w>x<h> 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-v121.txt, patches-v143.txt).
--hud 21:9 | 16:9 (with --aspect, a screen wider than that; default full) keeps the HUD within the middle 21:9 or 16:9 of
the screen instead of its corners (totk.ini hud_width). The folder is romfs-patches-<w>x<h>-hud21x9 or -hud16x9, which
runtime/romfs.c overlay_init loads in place of romfs-patches-<w>x<h> when hud_width asks for it.
--prompts xbox | xbox-label: the same overlay with Xbox button icons in the game's prompts, for prompts = xbox
(runtime/romfs.c overlay_init loads romfs-patches-xbox or romfs-patches-xbox-label in place of romfs-patches). Drawn
@@ -53,7 +56,8 @@ contents match the new one is hard-linked (copied where links fail) instead of c
lists them. The output is byte for byte the same as without it.
Input: build/extracted/<version>/romfs (romfs.bin and index.json, verified by tools/extract.py). Output:
build/<version>/romfs-patches/<path> by default (romfs-patches-<style> with --prompts), and <out>/manifest.tsv (path, size, SHA-256 of the overlay, SHA-256 of the original). Run with .venv-py314.
build/<version>/romfs-patches/<path> by default (romfs-patches-<style> with --prompts, -<w>x<h> with --aspect,
and -hud<a>x<b> with --hud), and <out>/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
@@ -70,8 +74,11 @@ ap = argparse.ArgumentParser(description=__doc__.splitlines()[0])
ap.add_argument('--version', choices=('v110', 'v121', 'v143'), default='v121')
ap.add_argument('--romfs', type=Path, help='default build/extracted/<version>/romfs')
ap.add_argument('--out', type=Path,
help='default build/<version>/romfs-patches (romfs-patches-<style> with --prompts)')
help='default build/<version>/romfs-patches[-<style>][-<w>x<h>][-hud<a>x<b>]')
ap.add_argument('--aspect', help='<w>x<h> of a game resolution of another shape than 16:9: also lay the UI out for it')
ap.add_argument('--hud', choices=('full', '21:9', '16:9'), default='full',
help='with --aspect on a wider screen: the HUD stays within the middle 21:9 or 16:9 (default full: the '
'screen\'s corners); the default --out gets a -hud21x9 or -hud16x9 suffix')
ap.add_argument('--prompts', choices=('xbox', 'xbox-label', 'pc'),
help='Xbox button icons in the prompts: xbox for pad_layout = nintendo (A shown as B, X as Y), '
'xbox-label for pad_layout = xbox or auto (the face buttons keep their letters), '
@@ -82,7 +89,24 @@ ap.add_argument('--reuse', type=Path,
help='an overlay folder made before: its files with the same contents are linked, not compressed again')
args = ap.parse_args()
args.romfs = args.romfs or root / 'build/extracted' / args.version / 'romfs'
args.out = args.out or root / 'build' / args.version / (f'romfs-patches-{args.prompts}' if args.prompts else 'romfs-patches')
width = height = None
if args.aspect:
match = re.fullmatch(r'([1-9][0-9]*)x([1-9][0-9]*)', args.aspect.lower())
if not match: ap.error('--aspect must be positive integer dimensions <w>x<h>')
width, height = map(int, match.groups())
if width * 9 == height * 16: ap.error('--aspect must have another shape than 16:9')
args.aspect = f'{width}x{height}'
HUD_CAP = {'full': None, '21:9': 21 / 9, '16:9': 16 / 9}[args.hud]
if HUD_CAP is not None:
if not args.aspect: ap.error('--hud needs --aspect')
if HUD_CAP >= width / height * 0.99:
ap.error(f'--hud {args.hud} is not narrower than a {width}x{height} screen (that is --hud full)')
if not args.out:
# Match runtime/romfs.c overlay_init, preserving the default 16:9 overlay.
name = f'romfs-patches-{args.prompts}' if args.prompts else 'romfs-patches'
if args.aspect: name += '-' + args.aspect
if args.hud != 'full': name += '-hud' + args.hud.replace(':', 'x')
args.out = root / 'build' / args.version / name
index = json.loads((args.romfs / 'index.json').read_text())
assert index['status'] == 'pass'
files = {f['path']: f for f in index['files']}
@@ -381,11 +405,10 @@ for member, panes in MEMBERS.items():
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)
layout = ultrawide.apply(blarc, members, width, height, HUD_CAP)
diff = [i for i in range(len(original)) if original[i] != blarc[i]]
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
@@ -496,5 +519,5 @@ for path, contents in outputs.items():
(args.out / 'manifest.tsv').write_text('# path\tsize\tsha256\toriginal_sha256 (tools/make_romfs_patches.py)\n'
+ ''.join(line + '\n' for line in lines))
print(json.dumps(dict(status='pass', path=ARCHIVE, members=patched, changed_bytes=len(diff),
ultrawide_layout=dict(aspect=args.aspect, members=len(layout)) if args.aspect else None,
ultrawide_layout=dict(aspect=args.aspect, hud=args.hud, members=len(layout)) if args.aspect else None,
prompts=prompts, reused=reused)))
+47 -23
View File
@@ -12,6 +12,7 @@ found for 1.0.0 .. 1.2.1 (GPL; only those values are taken, no code; THIRD_PARTY
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 math
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.
@@ -48,10 +49,24 @@ MARKER_ROOT = {
# animations only key alpha, visibility and N_Loop_00's y. (pane, x, y) as shipped.
BALLOON_PART = (('C_CaptureBase_00', 226.0, 20.0), ('N_InOut_00', 30.0, -10.0))
def edits(k, hud_corner):
def hud_extent(k, hud_aspect):
"""(w_hud, right_hud) for the HUD: how far its edge moves out in a 1920-wide layout's own units (960 * (1 / kc - 1))
and in the grid units of a root pane already scaled by k (960 * k * (1 / kc - 1)), where kc = (16/9) / C and C is
the HUD's aspect: hud_aspect, never wider than the screen's 16/9 / k. None (or a cap that is not narrower than the
screen) puts the HUD at the screen's edges: the same w and 960 * (1 - k) the screen itself uses. C = 16/9 gives
(0, 0), the HUD in the middle 16:9 as shipped."""
screen = (16 / 9) / k
if hud_aspect is None or hud_aspect >= screen * 0.99: return 960 * (1 / k - 1), 960 * (1 - k)
inner = 1 / ((16 / 9) / hud_aspect) - 1 # 1 / kc - 1
return 960 * inner, 960 * k * inner
def edits(k, hud_aspect):
"""(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."""
layout's edge moves out in its own units (960 * (1 / k - 1)). OFF moves a pane out of sight. hud_aspect: the
widest aspect the HUD spreads over (None = the screen's, see hud_extent); w_hud and right_hud replace w and the
root's x for the HUD panes below, everything else belongs to the screen and keeps w and k."""
w, OFF = 960 * (1 / k - 1), 10000.0
w_hud, right_hud = hud_extent(k, hud_aspect)
wide = 1 / k
out = [
('AppAlbum_00', 'N_FadeInOut_00', 'scale_x', k), ('AppAlbum_00', 'N_Open_01', 'scale_x', wide),
@@ -78,7 +93,8 @@ def edits(k, hud_corner):
('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)),
# The saving indicator follows the same selected HUD area as the other corner indicators.
('SaveLoadIcon_00', 'RootPane', 'x', -right_hud),
('ShopMenu_00', 'N_BG_00', 'scale_x', wide), ('StaffRoll_00', 'N_BG_00', 'scale_x', wide),
*[e for pane, x, _ in BALLOON_PART for e in (('PaBalloonMessage_00', pane, 'scale_x', k),
('PaBalloonMessage_00', pane, 'x', x * k))],
@@ -97,18 +113,17 @@ def edits(k, hud_corner):
('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',
if hud_aspect is None or hud_aspect > 16 / 9: # the HUD out to its area's edges; at 16:9 it stays as shipped
out += [(name, 'RootPane', 'x', right_hud) 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))]
out += [('Location_00', 'N_Small_00', 'x', -(388 + w_hud)),
('PlayerStatus3D_00', 'N_ExtraStaminaTarget_01', 'x', -(745 + w_hud)),
('PlayerStatus_00', 'N_DevilDemoTargetC_00', 'x', -(284 + w_hud)),
('PlayerStatus_00', 'N_DevilDemoTargetLT_00', 'x', -(576 + w_hud)),
('PlayerStatus_00', 'N_HeartGaugeTargetLT_00', 'x', -(576 + w_hud)),
('PlayerStatus_00', 'N_HeartPos_00', 'x', -w_hud),
('PlayerStatus_00', 'Pa_CompanionLife_00', 'x', -(840 + w_hud))]
return out
SYSTEM_MENUS = ('SystemLoadList_00', 'SystemOption_00', 'SystemSaveLoad_00')
@@ -217,12 +232,13 @@ def tall_anim(blarc, members, k, changed):
if len(curves) != 1 or values != [1.08, 1.28]: raise SystemExit(f'PaMapIconDragonTears_00_Zoom P_Geoglyph_00: keys {values}')
for key in curves[0]: put(key + 4, get(key + 4) / k)
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)
def anim_edits(k, hud_aspect):
"""(animation, byte offset, value the game ships, new value): floats inside BFLAN key tables. hud_aspect as in
edits."""
w_hud, _ = hud_extent(k, hud_aspect)
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)]
if hud_aspect is None or hud_aspect > 16 / 9: # 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_hud) for o in (872, 880, 1628, 1636, 3264, 3272, 3468, 3476)]
return out
def panes(blarc, lo, hi):
@@ -243,10 +259,18 @@ def find_pane(found, layout, name):
if name not in found: raise SystemExit(f'{layout}: no pane {name}')
return found[name]
def apply(blarc, members, width, height, hud_corner=True):
def apply(blarc, members, width, height, hud_aspect=None):
"""Edits blarc (bytearray) in place for a width x height canvas of another shape than 16:9. Returns the members it
changed. hud_corner (wider canvases): the HUD goes to the screen's corners; a narrower one always has it at the
top and bottom edges."""
changed. hud_aspect (wider canvases): the widest aspect the HUD spreads over, centred on the screen (21:9 =
21 / 9, 16:9 = 16 / 9); None, or one not narrower than the screen, puts it in the screen's corners. A taller canvas
always has the HUD at the top and bottom edges."""
if not all(isinstance(v, (int, float)) and math.isfinite(v) and v > 0 for v in (width, height)):
raise ValueError('canvas dimensions must be positive and finite')
if hud_aspect is not None:
if not math.isfinite(hud_aspect) or hud_aspect < 16 / 9:
raise ValueError('HUD aspect must be finite and at least 16:9')
# Runtime treats caps within one percent of the canvas as full width.
if hud_aspect >= width / height * 0.99: hud_aspect = None
wide = width / height > 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'
@@ -276,7 +300,7 @@ def apply(blarc, members, width, height, hud_corner=True):
struct.pack_into('<f', blarc, at, k)
# Every edit's value at k = 1 is the value the game ships (a scale of 1, the 16:9 position): checked before writing,
# so a version with other numbers stops here instead of getting wrong positions. OFF moves a pane away: not checked.
table = zip(edits(k, hud_corner), edits(1.0, hud_corner)) if wide else zip(tall_edits(k), tall_edits(1.0))
table = zip(edits(k, hud_aspect), edits(1.0, hud_aspect)) if wide else zip(tall_edits(k), tall_edits(1.0))
for (layout, pane, field, value), (_, _, _, shipped) in table:
at = pane_offset(layout, pane) + FIELD[field]
have = struct.unpack_from('<f', blarc, at)[0]
@@ -285,7 +309,7 @@ def apply(blarc, members, width, height, hud_corner=True):
if not wide:
tall_anim(blarc, members, k, changed)
return sorted(changed)
for anim, offset, shipped, value in anim_edits(k, hud_corner):
for anim, offset, shipped, value in anim_edits(k, hud_aspect):
member = f'anim/{anim}.bflan'
if member not in members: raise SystemExit(f'{anim}: no animation {member} in the archive')
lo, hi = members[member]