mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-22 21:15:57 +00:00
Lay the HUD out for 16:10 game resolutions on 1.4.3
ultrawide_layout.py handled canvases wider than 16:9 only, so the Steam Deck's 1280x800 got the 16:10 camera with the 16:9 HUD stretched 11% over it. A narrower canvas now scales each layout's root pane in y by the aspect over 16/9, stretches full-screen backgrounds back and moves the HUD to the top and bottom edges. The pane list and distances are the TALL table of tools/aspect_layouts.py from pull request #60, in the format of the wide edits; the minimap, discovery banner and dragon's tears keys are found by walking the animation's curves. Every value is checked against the shipped one before it is written: 1.4.3's Common.Product.140 and 1.2.1's Common.Product.110 pass at 1280x800 and 1920x1200, and the 3440x1440 overlay is byte-identical to the one before. The settings menu offers 1280x800, 1680x1050, 1920x1200 and 2560x1600, and the installer builds their overlays with the 21:9 and 32:9 ones. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
43a18a9bb1
commit
0db841c297
11 files changed
+168
-45
No files matched your search
@@ -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 <w>x<h> (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-<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-v143.txt).
|
||||
--aspect <w>x<h> (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-<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-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/<version>/romfs')
|
||||
ap.add_argument('--out', type=Path,
|
||||
help='default build/<version>/romfs-patches (romfs-patches-xbox with --xbox-prompts)')
|
||||
ap.add_argument('--aspect', help='<w>x<h> of a game resolution wider than 16:9: also lay the UI out for it')
|
||||
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('--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'
|
||||
|
||||
+127
-14
@@ -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('<H', blarc, lo + 6)[0], []
|
||||
for _ in range(struct.unpack_from('<H', blarc, lo + 0x10)[0]):
|
||||
magic, size = bytes(blarc[pos:pos + 4]), struct.unpack_from('<I', blarc, pos + 4)[0]
|
||||
if magic == b'pai1':
|
||||
table = pos + struct.unpack_from('<I', blarc, pos + 16)[0]
|
||||
for e in range(struct.unpack_from('<H', blarc, pos + 14)[0]):
|
||||
eo = pos + struct.unpack_from('<I', blarc, table + 4 * e)[0]
|
||||
if bytes(blarc[eo:eo + 28]).split(b'\0')[0].decode() != pane: continue
|
||||
for t in range(blarc[eo + 28]):
|
||||
to = eo + struct.unpack_from('<I', blarc, eo + 32 + 4 * t)[0]
|
||||
if bytes(blarc[to:to + 4]) != tag: continue
|
||||
for g in range(blarc[to + 4]):
|
||||
go = to + struct.unpack_from('<I', blarc, to + 8 + 4 * g)[0]
|
||||
if blarc[go + 1] != target: continue
|
||||
if blarc[go + 2] != 2: raise SystemExit(f'{pane}: a {tag.decode()} curve that is not hermite')
|
||||
keys = go + struct.unpack_from('<I', blarc, go + 8)[0]
|
||||
out.append([keys + 12 * i for i in range(struct.unpack_from('<H', blarc, go + 4)[0])])
|
||||
pos += size
|
||||
return out
|
||||
|
||||
def tall_anim(blarc, members, k, changed):
|
||||
"""The animation keys that hold positions or zooms on the screen's height, for a canvas narrower than 16:9."""
|
||||
h = 540 * (1 / k - 1)
|
||||
get = lambda at: struct.unpack_from('<f', blarc, at)[0]
|
||||
put = lambda at, v: struct.pack_into('<f', blarc, at, v)
|
||||
def anim(name):
|
||||
member = f'anim/{name}.bflan'
|
||||
if member not in members: raise SystemExit(f'{name}: no animation {member} in the archive')
|
||||
changed.add(member)
|
||||
return members[member][0]
|
||||
# The minimap's four cut panes slide in on straight lines from 0 at frame 0 to y -360, the bottom of a 16:9 layout
|
||||
# (hermite keys: the first one's slope is the end point); the end point moves with the screen's edge.
|
||||
lo = anim('AppMap_00_MiniMap')
|
||||
for pane in ('N_Cut_00', 'N_Cut_01', 'N_Cut_02', 'N_Cut_03'):
|
||||
curves = anim_keys(blarc, lo, pane, b'FLPA', FLPA_Y)
|
||||
if len(curves) != 1 or len(curves[0]) != 2: raise SystemExit(f'AppMap_00_MiniMap {pane}: {len(curves)} y curves')
|
||||
k0, k1 = curves[0]
|
||||
if not (get(k0) == 0 and get(k0 + 4) == 0 and abs(get(k0 + 8) + 360) < 1e-3 and get(k1) == 1 and
|
||||
abs(get(k1 + 4) + 360) < 1e-3 and get(k1 + 8) == 0):
|
||||
raise SystemExit(f'AppMap_00_MiniMap {pane}: not a line from 0 to y -360')
|
||||
put(k0 + 8, -(360 + h)), put(k1 + 4, -(360 + h))
|
||||
# The large place name of a discovery holds its height (285, then 260) in flat keys; they move to the top edge.
|
||||
curves = anim_keys(blarc, anim('Location_00_IsDiscovery'), 'N_Large_00', b'FLPA', FLPA_Y)
|
||||
values = [get(key + 4) for keys in curves for key in keys]
|
||||
if len(curves) != 1 or values != [285, 285, 260]: raise SystemExit(f'Location_00_IsDiscovery N_Large_00: keys {values}')
|
||||
for key in curves[0]: put(key + 4, get(key + 4) + h)
|
||||
# The dragon's tears map icon zooms its picture to 1.08 and 1.28 in flat keys; on the stretched axis by 1 / k more.
|
||||
curves = anim_keys(blarc, anim('PaMapIconDragonTears_00_Zoom'), 'P_Geoglyph_00', b'FLTS', FLTS_SY)
|
||||
values = [round(get(key + 4), 4) for keys in curves for key in keys]
|
||||
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)
|
||||
@@ -109,9 +214,13 @@ def find_pane(found, layout, name):
|
||||
return found[name]
|
||||
|
||||
def apply(blarc, members, width, height, hud_corner=True):
|
||||
"""Edits blarc (bytearray) in place for a width x height canvas. Returns the members it changed."""
|
||||
k = (16 / 9) / (width / height)
|
||||
assert k < 1, 'only for canvases wider than 16:9'
|
||||
"""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."""
|
||||
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'
|
||||
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('<f', blarc, at)[0]
|
||||
if abs(have - 1.0) > 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('<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.
|
||||
for (layout, pane, field, value), (_, _, _, shipped) in zip(edits(k, hud_corner), edits(1.0, hud_corner)):
|
||||
table = zip(edits(k, hud_corner), edits(1.0, hud_corner)) 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]
|
||||
if value != 10000.0 and abs(have - shipped) > 1e-3: raise SystemExit(f'{layout} {pane} {field}: {have}, expected {shipped}')
|
||||
struct.pack_into('<f', blarc, at, value)
|
||||
if not wide:
|
||||
tall_anim(blarc, members, k, changed)
|
||||
return sorted(changed)
|
||||
for anim, offset, shipped, value in anim_edits(k, hud_corner):
|
||||
member = f'anim/{anim}.bflan'
|
||||
if member not in members: raise SystemExit(f'{anim}: no animation {member} in the archive')
|
||||
|
||||
Reference in new issue
Block a user