Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions dm/games/0400486024DEC000/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ Measured on an M6 Mac with 16 GB, headless, on one walk with camera turns (`walk
- With a window, the first start on a new chain runs the pipeline prebuild first: 33,190 shader pairs, 691 s on this Mac. A run with no window skips it.
- The opening movie runs at the movie's own 24 fps pace during the story section and cannot be skipped: about 8 minutes on a new file.

## Native output

- The launcher's **Output** (`DM_OUTPUT`, v131072): the game draws its picture into 80 % of the output (`nvnWindowSetCrop`, 2048x1152 of the docked 2560x1440) and the system scales it up, the console's own frame. The 80 % is two multiplies in the game's code (`main+0x6505c4`, `+0x6505d4`; not in `ModelSceneExtensionParam`), and with **Native** stubs there skip them: the crop, the 3D and its depth are the full output size and nothing is scaled. Framing and field of view stay the same.
- Measured (M5 Max, macOS 26.6.2, 2026-11-09, Castle Town market, Link standing, headless, the 300 frames after the scene settled, n=1 each; at 3024x1702 with the 3D's levels at x1.0, both from our own build): the 80 % frame, 3D 2419x1361: frame p50 / p95 16.67 / 17.64 ms, GPU p50 / p95 13.36 / 14.20 ms; native, 3D 3024x1702: 19.47 / 21.29 ms, GPU 17.34 / 18.37 ms, and the market no longer held 60 at that size. A second pair, with the stubs: 16.64 / 17.92 ms, GPU 13.09 / 13.90 ms against 16.54 / 18.53 ms, GPU 14.37 / 15.41 ms. So 1.56 times the pixels cost 1.1 to 1.3 times the GPU; macOS sets the GPU clock per run. The pause menu, speech bubbles and button prompts draw at the full size.
- Not checked: the game's own 2560x1440 output (native makes the crop 2560x1440 instead of 2048x1152), other areas in play, handheld, other builds.

## Dynamic resolution

- The controller (v131072; found by fingerprint, so the addresses are only for reading): the parameters are `game__gfx__DynamicResolutionParam` (`LoadThreshold`, `ReduceCounterMax`, `IncreaseCounterMax`, and a list of levels, each a `ResolutionReduceScale` and a `Priority`). Once a frame the update (`main+0x805aa0`) reads the frame's GPU time, subtracts what its cost model predicts at the current size and keeps the trend of that residual. The level function (`main+0x8065e0`) adds the residual to the model's cost at each level and returns the best level under the threshold: 0, the full 1536x864, when the current size fits. The update moves down after `ReduceCounterMax` frames that ask for it and back up after `IncreaseCounterMax`. Scripted `GPULoad` hints from event data (`main+0x31c3de0`) and `OneshotSetDynamicResolutionLoadThreshold` adjust it in cutscenes.
Expand Down
23 changes: 23 additions & 0 deletions dm/games/0400486024DEC000/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def frame_step(ctx):
emit(0x1e201828); emit(B(here(), site + 4)) # orig: fdiv s8,s1,s0; back
fs_put(site, [B(site, start)], 'frame ratio: the host\'s step × base rate / 60 instead of base rate / the game\'s frame rate (state page target fps; 0 = the game\'s ratio)')
dynamic_resolution(ctx)
if base == 0x6e6be0: native_output(ctx) # v131072's main (the only build the crop sites are known for)

# The game's dynamic resolution (game__gfx__DynamicResolutionParam: LoadThreshold, ReduceCounterMax, IncreaseCounterMax and a list of levels, each a ResolutionReduceScale and a
# Priority; on v131072 levels 0..9 at 0.75..0.333 of 2048x1152, 1536x864 to 683x384). Its update (main+0x805aa0) reads the frame's GPU load (about 0.2 ms a unit) into +0x8, subtracts
Expand Down Expand Up @@ -71,6 +72,25 @@ def dynamic_resolution(ctx):
fs_put(site, [B(site, start)], 'dynamic resolution level: 0 (full resolution), or with state +0x40 (DM_DYNAMIC_RESOLUTION) a climb on the load measured at each level')
ctx.capabilities.add('DYNAMIC_RESOLUTION')

# Native output (DM_OUTPUT=native, the launcher's Output; v131072 only, guarded by the matched frame-step function's place): the game draws its picture into 80 % of the output
# and the system scales that up, the console's own frame. The crop is set in main+0x650380's function: crop = the base size ([entry+0x64], ints) times a float pair per mode and
# level, 0.8 here, read from [obj+0xf0 + mode * 0x208 + level * 0x60 + (signed byte [obj+0x54a]) * 8 + 0x1e4 / +0x1e8]; each side is clamped to the size from main+0x112c5e0
# and stored through main+0x1087f40, which main+0x650538 later reads for nvnWindowSetCrop (called from main+0x11e7b74). The 0.8 is in code, not in
# ModelSceneExtensionParam. Found by watching the crop object's size field: one store, 3024x1702 -> 2419x1361, pc main+0x1087f64, lr main+0x650604.
# The stubs skip the two multiplies when state +0x44 is 1, so the crop is the full base size and the picture, the 3D and its depth are the full output size. x16 is free at
# both sites: a call (bl main+0x112c5e0) follows within three instructions and nothing between reads x16
def native_output(ctx):
here, emit, fs_site, fs_put, ST = ctx.here, ctx.emit, ctx.site, ctx.put, ctx.state
for site, orig in ((0x6505c4, 0x1e200840), (0x6505d4, 0x1e200820)): # fmul s0,s2,s0 (width) / fmul s0,s1,s0 (height)
fs_site(site, orig.to_bytes(4, 'little').hex())
start = here(); emit(ADRP(16, here(), ST))
emit(0xb9404610) # ldr w16,[x16,#0x44] 1 = native output
emit(0x35000050) # cbnz w16,+8 skip the multiply
emit(orig) # the original multiply: the game's 80 %
emit(B(here(), site + 4))
fs_put(site, [B(site, start)], 'native output: the crop multiply skipped when state +0x44 is set (DM_OUTPUT=native), so the picture is the full output size')
ctx.capabilities.add('NATIVE_OUTPUT')

MATCH_FRAME_STEP = {'main': [
{'name': 'frame ratio from the host\'s step', 'size': 0x9b4, 'fingerprints': ['6ae2aff5344d14568e4dbaf93455e2d8278384bf892ed6c6eca87fef98fbcd1d'], 'stub': frame_step, # v131072 main+0x6e6be0
'others': {'dynamic resolution': {'size': 0x294, 'fingerprints': ['7af6ceb0aedf8e0c17dc08ce17fcd6a7cba6d394a0d09e3b504c6d668dc418e7']}, # v131072 main+0x8065e0
Expand All @@ -84,4 +104,7 @@ def dynamic_resolution(ctx):
{'what': 'dynamic resolution: full size, or a climb on the load measured at each level', 'now': 'game', 'goal': 'game', 'purpose': 'rendering',
'why': "the game's own dynamic-resolution level function and update, found by their functions' fingerprints on any build that keeps both; switchable (DM_DYNAMIC_RESOLUTION)",
'checked': 'v131072 main: one function with each fingerprint (the level function a leaf, x2..x11 / x16 / x17 / s0..s2 free), its callers, the update and the controller fields read by disassembly, the fields read in play (2026-11-08); the climb run natively against a model of the update and in play to full size (2026-11-09)'},
{'what': 'native output: the window crop\'s two 80 % multiplies skipped (DM_OUTPUT=native)', 'now': 'build', 'goal': 'game', 'purpose': 'rendering',
'why': "two multiplies in v131072's crop function, placed by address and only when the frame-step function sits at v131072's place; a function-matched rule could carry them to other builds",
'checked': 'v131072 main: the sites and x16 read by disassembly; the same skip (both multiplies as no-ops) run headless in Castle Town at 3024x1702 and checked for speech bubbles and button prompts (M5 Max, macOS 26.6.2, 2026-11-09)'},
]
1 change: 1 addition & 0 deletions dm/games/settings.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
DM_FPS_TARGET choice 30=30 fps,60=60 fps,120=120 fps?DM_GAME_FPS_MAX==120&platform:mac DM_GAME_FPS_TARGET DM_GAME_FPS_TARGET!=0 Game Frame rate level=basic
DM_DYNAMIC_RESOLUTION toggle - 0 fixups:DYNAMIC_RESOLUTION Game Dynamic resolution Lets the game lower its resolution under load. Turn off to keep full resolution for the selected console mode.
DM_RENDER_SCALE range 0.5:1.0:0.05 1.0 fixups:RENDER_SCALE Game Render scale level=basic
DM_OUTPUT choice 0=Game (80 % frame scaled up),native=Native (full size) 0 fixups:NATIVE_OUTPUT Game Output What the game draws into the picture: its own frame, 80 % of the size scaled up as on the console, or the full size, sharper and with more GPU time level=basic
DM_OPMODE choice 1=Docked,0=Handheld DM_GAME_OPMODE always Game Console mode level=basic
DM_PRESENT_UPSCALE choice off=Standard,metalfx=MetalFX off always Game Upscaling Uses more GPU time and can increase heat.
DM_UPSCALER choice game=Game's own,metalfx=MetalFX game DM_GAME_UPSCALER_N!=0 Game Game's upscaler
Expand Down
6 changes: 6 additions & 0 deletions dm/host/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,12 @@ void dm_fps_state_apply(void) {
const char *dr = getenv("DM_DYNAMIC_RESOLUTION"); uint32_t dyn = dr && !strcmp(dr, "1");
if (dr && strcmp(dr, "0") && strcmp(dr, "1")) LOG("[RED] DM_DYNAMIC_RESOLUTION=%s: must be 0 or 1; keeping full resolution", dr);
memcpy(dm_fps_state + 0x40, &dyn, sizeof dyn);
// Native output, for builds whose stubs read it (the NATIVE_OUTPUT capability: Ocarina of Time v131072's window crop): DM_OUTPUT=native draws the full output size instead
// of the game's 80 % frame scaled up; 0 or unset keeps the game's frame. Builds without such a stub ignore the field
const char *no = getenv("DM_OUTPUT"); uint32_t native = no && !strcmp(no, "native");
if (no && strcmp(no, "0") && !native) LOG("[RED] DM_OUTPUT=%s: must be 0 or native; keeping the game's frame", no);
else if (native) LOG("%s: output native (DM_OUTPUT): the picture is the full output size", g_fps_mod);
memcpy(dm_fps_state + 0x44, &native, sizeof native);
// Screen shape: DM_SCREEN_ASPECT, the screen's width / height between 1.3 and 1.77, makes the builds with screen-shape stubs
// (Breath of the Wild 1.9.0's patches.py) render that shape: the output keeps its width (1920) and takes the height that gives the ratio, a multiple of 48 so the
// 2/3-size layout space (1280 wide) stays whole: 1.43 → 1920x1344 and 1280x896. State +0x48 u32 output height, +0x4c u32 layout height, +0x50 its float; 0 = 16:9
Expand Down
3 changes: 2 additions & 1 deletion dm/tools/patch_nso.py
Original file line number Diff line number Diff line change
Expand Up @@ -1554,7 +1554,8 @@ def stdalloc_gates():
# runs the original instructions), +4 30 fps movie/cinematic flag, +8 double lead (TOTK), +0x10 float render scale (TOTK, BotW), +0x18 double game seconds (TOTK),
# +0x20 u32 step in vsyncs (host; 0 = not decided yet), +0x24 u32 a step the game fixes itself (BotW's VFR override; 0 = none), +0x28 u32 AoC's vsyncs per update, marked by
# its first stub (0 = off), +0x30 u64 vsyncs stepped (the stubs; logged by the host to check the game's speed), +0x40 u32 1 = the game's own dynamic resolution runs, 0 = its
# stub holds full resolution (DM_DYNAMIC_RESOLUTION, written by the loader; the stub declares the DYNAMIC_RESOLUTION capability). Stub bodies assembled with clang
# stub holds full resolution (DM_DYNAMIC_RESOLUTION, written by the loader; the stub declares the DYNAMIC_RESOLUTION capability), +0x44 u32 1 = native output, the game's
# frame crop skipped (Ocarina of Time v131072; DM_OUTPUT=native, written by the loader; the stub declares the NATIVE_OUTPUT capability). Stub bodies assembled with clang
# A build's stubs are FRAME_STEP[build ID](ctx) in its patches.py: ctx.here() / ctx.emit(word) assemble into the patch area, ctx.site(offset, original bytes) asserts a site and that it is
# no rewrite site, ctx.put(offset, words, reason) writes it (listed with the cuts), ctx.state is the state page's offset, ctx.render_scale = 1 marks a render-scale stub,
# ctx.others the other functions a MATCH_FRAME_STEP rule names, ctx.address(offset) the data address an adrp there and the add / load / store after it make (in the original
Expand Down
4 changes: 3 additions & 1 deletion docs/agents/game-patches.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Every patch bound tighter than it could be: the open gaps, then the blocked, kep
| `build` → `game` | interval controller: the lower bound and the GPU-time path | frame rate | gap | judgement | 1 | [The Legend of Zelda: Breath of the Wild](../../dm/games/01007EF00011E000/README.md) | sead::GameFrameworkNx's interval controller in this build; Tears of the Kingdom shares sead but not this code |
| `build` → `game` | job pool wake-up | race | gap | judgement | 1 | [FINAL FANTASY TACTICS - The Ivalice Chronicles](../../dm/games/010038B015560000/README.md) | a lost wake-up in the game's own job pool, not a host or SDK difference |
| `build` → `game` | malloc region 60 GB → 4 GB and its first arena | address space | gap | judgement | 1 | [Xenoblade Chronicles 3](../../dm/games/010074F013262000/README.md) | Monolith's own allocator; its constants span two functions (a multi-function rule). The cause, an iPhone's address space, is a platform limit |
| `build` → `game` | native output: the window crop's two 80 % multiplies skipped (DM_OUTPUT=native) | rendering | gap | checked: v131072 main: the sites and x16 read by disassembly; the same skip (both multiplies as no-ops) run headless in Castle Town at 3024x1702 and checked for speech bubbles and button prompts (M5 Max, macOS 26.6.2, 2026-11-09) | 1 | [The Legend of Zelda: Ocarina of Time](../../dm/games/0400486024DEC000/README.md) | two multiplies in v131072's crop function, placed by address and only when the frame-step function sits at v131072's place; a function-matched rule could carry them to other builds |
| `build` → `game` | PhysX completion task release | race | gap | judgement | 1 | [The Legend of Zelda: Link's Awakening](../../dm/games/01006BB00C6F0000/README.md) | a lifetime race in the game's own completion task (its release slot serves this one vtable) |
| `build` → `game` | render intervals, the forced-interval flag and the render-wait timeout | frame rate | gap | judgement | 1 | [Fire Emblem: Three Houses](../../dm/games/010055D009F78000/README.md) | the game's own tables, flag and timeout |
| `build` → `game` | task ring push and pop barriers | race | gap | judgement | 1 | [Batman: Arkham Knight](../../dm/games/0100ACD0163D0000/README.md) | a data race in the game's own task ring |
Expand Down Expand Up @@ -76,7 +77,7 @@ Every patch bound tighter than it could be: the open gaps, then the blocked, kep
| [Taiko Risshiden V DX](#taiko-risshiden-v-dx) | 1 | 0 | 0 | 2 | 0 | `game` |
| [The Legend of Zelda: Breath of the Wild](#the-legend-of-zelda-breath-of-the-wild) | 7 | 0 | 43 | 0 | 0 | `build` → `game` ×2 |
| [The Legend of Zelda: Link's Awakening](#the-legend-of-zelda-links-awakening) | 1 | 0 | 0 | 0 | 0 | `build` → `game` |
| [The Legend of Zelda: Ocarina of Time](#the-legend-of-zelda-ocarina-of-time) | 0 | 0 | 2 | 0 | 0 | `game` ×2 |
| [The Legend of Zelda: Ocarina of Time](#the-legend-of-zelda-ocarina-of-time) | 0 | 0 | 2 | 0 | 0 | `game` ×2, `build` → `game` |
| [The Legend of Zelda: Tears of the Kingdom](#the-legend-of-zelda-tears-of-the-kingdom) | 0 | 0 | 9 | 0 | 0 | `game` |
| [Xenoblade Chronicles 3](#xenoblade-chronicles-3) | 6 | 0 | 0 | 0 | 0 | `build` → `game` |

Expand Down Expand Up @@ -538,6 +539,7 @@ Every patch bound tighter than it could be: the open gaps, then the blocked, kep

- **`game`**, frame rate, at goal, checked: v131072 main: one function with this fingerprint, the site and its free registers read by disassembly (2026-11-08): frame ratio from the host's step. The game's own frame-ratio division, found by its function's fingerprint on any build that keeps the function
- **`game`**, rendering, at goal, checked: v131072 main: one function with each fingerprint (the level function a leaf, x2..x11 / x16 / x17 / s0..s2 free), its callers, the update and the controller fields read by disassembly, the fields read in play (2026-11-08); the climb run natively against a model of the update and in play to full size (2026-11-09): dynamic resolution: full size, or a climb on the load measured at each level. The game's own dynamic-resolution level function and update, found by their functions' fingerprints on any build that keeps both; switchable (DM_DYNAMIC_RESOLUTION)
- **`build` → `game`**, rendering, gap, checked: v131072 main: the sites and x16 read by disassembly; the same skip (both multiplies as no-ops) run headless in Castle Town at 3024x1702 and checked for speech bubbles and button prompts (M5 Max, macOS 26.6.2, 2026-11-09): native output: the window crop's two 80 % multiplies skipped (DM_OUTPUT=native). Two multiplies in v131072's crop function, placed by address and only when the frame-step function sits at v131072's place; a function-matched rule could carry them to other builds

- **function-matched frame step** (`main` of builds without FRAME_STEP): frame ratio from the host's step: a function of 0x9b4 bytes, `+0xe4` in it; dynamic resolution, a function of 0x294 bytes, `+0x0` in it; dynamic resolution update, a function of 0xb24 bytes, in it; launcher capabilities: DYNAMIC_RESOLUTION

Expand Down
1 change: 1 addition & 0 deletions docs/env_switches.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ DM_OODLE_JOB path `=<job file>`: the host runs the game's own Oodle decoder on e
DM_OODLE_MODULES path The rewritten modules the Mac host's Oodle tool mode loads when `shader_split.py` decodes Trinity packs; set by the NSP script
DM_OODLE_SERVE switch `=1`: the host answers decode requests on stdin / stdout with the game's own Oodle (or LZ5) decoder from the guest main thread before the SDK starts, until stdin ends
DM_OPMODE player The operation mode the game sees: `0` handheld, `1` console (default: the profile's `op_mode`, console unless set); read once at startup
DM_OUTPUT player `native` draws the full output size instead of the game's 80 % frame scaled up, for builds with a native-output stub (the NATIVE_OUTPUT capability: Ocarina of Time v131072); `0` or unset keeps the game's frame
DM_PAD_IDENTICAL switch `0` stops reading identical pads here when GameController lists fewer of their model than IOKit has, such as two Pro Controllers over USB (each a player of its own: a Pro Controller from its report 0x30, another model from its HID elements; `pad_hid_mac.h`, `pad_pro.h`); `DM_HID_PADS=0` stops it too; Mac only
DM_PAD_MERGE switch `=1` merges every controller into player 1, as before, instead of giving each controller a player of its own (Mac and iOS)
DM_PAD_PRESS_TO_JOIN player `1`: a controller is no player until one of its buttons is pressed, then it is the lowest player free, whatever its port, link or model, identical pads included (`front_mac.m`, `DmGamepad.m`, `pad_slots.h`); not with `DM_PAD_MERGE`. Launcher setting
Expand Down
Loading
Loading