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
1 change: 1 addition & 0 deletions dm/games/0100A00019DE0000/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Base game v0 (the NACP's display version is 0.0.126424), SDK 19.3.9. Supergiant

## Rendering

- **Current: native render size on 1.0.131248 (Mac).** The game renders a fixed 1280x720, set by one constant in its app init: `mov x8,#0x500; movk x8,#0x2d0,lsl #32` at `main+0x2a4eb0` (v196608), stored to the app settings and the window rectangle; the swapchain and every screen-sized target follow it. A frame-step stub there takes the size from `DM_RENDER_SIZE` (the launcher's Resolution: 1280x720, 1920x1080, 2560x1440, 3840x2160). Headless on an M5 Max (macOS 26.6.2), opening into Erebus, one run per size: 45 full-size and 16 half-size targets follow the size, the HUD is laid out for it, no fault at 1600x900 to 3840x2160; GPU per frame (median of 43 windows of 300 frames, `DM_PRESENT_HZ=120`) 2.25 ms at 720p, 3.26 ms at 1080p, 4.83 ms at 1440p, 6.72 ms at 4K. The art is stored at 2/3 of its original size: the package manifests (`Packages/NVN/*.pkg_manifest`) give each sprite a scale of original / stored size, 1.5 for 3,764 of 4,797 sprites read and 1.48 to 1.52 for most others (720p-sized art if the originals were made for 1080p). A larger size sharpens the HUD, text and edges; the art is magnified 1.5x at 1080p and 3x at 4K (soft in a 4K still at 1:1). A player who applied the same change confirmed 1080p at a locked 60 fps on an M1 MacBook Air with 8 GB, version not stated ([issue 772](https://github.com/seedds/nxnative/issues/772)). v0 has no stub: PR 485 reports it crashing at 1600x900 (`main+0x48e5a4`) with the same two instructions patched at `main+0x2a6080`.
- **Current: textures at fixed, sparse slots.** Its 88 shaders bind combined textures at slots 0, 1, 3, 6, 8, 11, 15, 21, 25, 26, 30, 31 and 34. Slot 34 (`SceneFade.frag`, c2 0x130; `fp_t_tcb_4C`: c2 word 0x4C = 0x20 + 8 × 34) lies past the driver's 32 combined slots, inside the image table at 0x120. With a 32-slot table, `dmsh_build.py` reported that binding as not decoded (`shaders with a binding whose slot was not decoded 1`, which prints a red line when the shader loads). The combined table now runs up to the separate textures at 0x168 (41 slots); past slot 31 it shares its words with the image table, and the replay writes a bound texture there when the image slot is unbound (`nvn_mtl.m`). The game has no image bindings, so a bound texture there wins. The census of `fp_t_*` names in the translated libraries gives the slots in use.
- **Not a bug: two long lines through Melinoë.** While the staff's Omega attack charges, two thin white lines run from her to the screen edges, one forward and one back. They are that weapon's aim lines (`WeaponStaffSwing5`: `AimLineCountOverride = 2`, `AimLineAngleOffsetOverride = 180`, animation `AuraAimLineNoMovementStaff`). The sprite is a long arrow with white edges, a dark fill drawn emissive and its tip off-screen, and the game hides it while she moves. Traced with `DM_NVN_CBDUMP` vertex dumps and `DM_PROBE` on the aim-line update (`main+0x39ade0`); a scripted run that taps Y shows them often.

Expand Down
2 changes: 2 additions & 0 deletions dm/games/0100A00019DE0000/game.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pad_layout full

# ---- Versions ----
build v0 0.0.126424 main=5219053e5eb156be80fbb2f303779531 sdk=d83a56a5558798414c78ec722867a7da
# 1.0.131248 (v196608): registered for its render-size stub (patches.py); its shaders are not in the tables, so the NSP script packs it from a derived profile
build v196608 1.0.131248 main=e4f736641889b26f3194847d2b9dce57 sdk=190030518b5d64e5d87b84bc54661af9
package v0
shader_versions v0

Expand Down
32 changes: 32 additions & 0 deletions dm/games/0100A00019DE0000/patches.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Hades II (0100A00019DE0000): the rewriter's patches of this game's own builds. dm/tools/patch_nso.py loads every profile's patches.py and applies those of a module's NSO build ID;
# FRAME_STEP as described there ("Registered patches"). Patches of Nintendo SDK module builds are in dm/tools/sdk_patches.py
from nso_asm import ADRP, B, LDRX, NOP

# Render size. Supergiant's engine sizes the swapchain and every screen-sized target from the app settings' width and height. On the Switch the app's init (main+0x2a4d20 in
# 1.0.131248 = v196608, the function that also runs the main loop) writes them as one constant right after nn::vi::CreateLayer: mov x8,#0x500; movk x8,#0x2d0,lsl #32
# (1280 | 720 << 32) at main+0x2a4eb0, stored to settings +8 and to the window's rectangle {0, 0, w, h}. Next to it the init stores a pointer to the PC version's resolution
# table (main+0x6c837c: 1280x720, 1920x1080, 2560x1440, 3840x2160), which nothing reads. The stub takes the size from the state page (+0x38: u32 width, u32 height; DM_RENDER_SIZE,
# written by the loader) and keeps 1280x720 when it is 0. x8 is written by the stub before its only read. Measured headless on the Mac (M5 Max): at 1600x900, 1920x1080, 2560x1440
# and 3840x2160 the swapchain and the 45 full-size and 16 half-size targets of a frame follow the size, the HUD is laid out for it, and the game runs the opening into Erebus
# without a fault. PR #485 reports v0 crashing at 1600x900 (main+0x48e5a4) with the same two instructions patched at main+0x2a6080; that did not happen on this build
def frame_step_v196608(ctx):
ctx.site(0x2a4eb0, '08a080d2085ac0f2')
start = ctx.here(); ctx.emit(ADRP(8, ctx.here(), ctx.state)); ctx.emit(LDRX(8, 8, 0x38 // 8)) # ldr x8,[state,#0x38] width | height << 32
for w in (0xb5000068, # cbnz x8,back (+3)
0xd280a008, # mov x8,#0x500 1280 (the original)
0xf2c05a08): # movk x8,#0x2d0,lsl #32 720
ctx.emit(w)
ctx.emit(B(ctx.here(), 0x2a4eb8))
ctx.put(0x2a4eb0, [B(0x2a4eb0, start), NOP], 'app settings width and height: the state page\'s render size (DM_RENDER_SIZE), 1280x720 when it is 0')
ctx.capabilities.add('RENDER_SIZE')

FRAME_STEP = {'e4f736641889b26f3194847d2b9dce57': frame_step_v196608}

# How general each patch is and could be (dm/tools/docs_patches.py "Binding", listed in docs/agents/game-patches.md): what, its binding now, the loosest it could have (goal),
# purpose, why; blocked or kept: why the gap stays open (cannot close yet, or left open on purpose); checked: what was checked on game files (else a judgement)
BINDING = [
{'what': 'render size: the app settings\' width and height from the state page', 'now': 'build', 'goal': 'game', 'purpose': 'rendering',
'why': "the game's own init constant; the same two instructions sit at main+0x2a6080 in v0, so a function-matched rule could carry it over the updates",
'kept': 'tested on 1.0.131248 only; PR #485 saw v0 crash at 1600x900 with the same change, so each build needs its own run first',
'checked': '1.0.131248 headless at 1600x900, 1920x1080, 2560x1440 and 3840x2160 (M5 Max, macOS 26.6.2)'},
]
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.

## Render size

- The launcher's **Resolution** (`DM_RENDER_SIZE`, v131072, docked): the game sizes its docked output and render targets from fixed 2560x1440 constants, and stubs at those sites (`patches.py`, the sites [PR 1460](https://github.com/seedds/nxnative/pull/1460) found for its ultrawide cuts) take the chosen size instead. The swapchain and every target that follows the output take it; the game still draws 80 % of the output (`nvnWindowSetCrop`, 3072x1728 at 3840x2160) and its 3D at most at its top level, ×0.75 of that. Handheld (1920x1080) is left alone.
- Measured (M5 Max, macOS 26.6.2, 2026-11-08, a 1-minute headless route from a save, n=1 each): every size held 60 fps (frame p50 16.7 ms); GPU p50 8.9 ms at the game's own size, 9.2 ms at 2560x1440 through the stubs, 9.6 ms at 3840x2160. On this Mac the frame hardly follows the size (see Dynamic resolution). In play, 2026-11-08 and 09: 2560x1440 (three sessions, 2 to 14 minutes) and 3024x1702 (a size not in the launcher's list; five sessions, up to 28 minutes), through Kakariko, Death Mountain Trail, Hyrule Field and Castle Town.
- Not checked: 1920x1080 docked (below the game's own size), 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
55 changes: 55 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: render_size(ctx) # v131072's main (the only build the render-size 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,57 @@ 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')

# Render size (DM_RENDER_SIZE, the launcher's Resolution; v131072 only, guarded by the matched frame-step function's place): the game sizes its docked output and render
# targets from fixed 2560x1440 constants (the sites upstream PR #1460 found for its ultrawide cuts); these stubs take the state page's size instead (+0x38: u32 width,
# u32 height, read as one x = width | height << 32; 0 = the game's own). Each keeps the original instructions for size 0. Handheld (1920x1080) is left alone.
# main+0x1202ee0 the graphics setup config's output size (swap chain), x8 = 2560 | 1440 << 32 (mov/movk), stored at [x21+0x14]
# main+0x31f39f4 the docked render size, the same pattern, stored at [x19+0xb68]
# main+0x112c604 the display mode's output size, read from the table at main+0x3f58540: its 2560x1440 entry becomes the size
# main+0xecbc80 / +0xecbcb4 the float copies of the output width (w9 = 2560.0f) and height (w8 = 1440.0f) in the same object's init
# The float stubs convert through s31, saved below sp and restored (no FP register is known free there)
NOP = 0xd503201f
def render_size(ctx):
here, emit, fs_site, fs_put, ST = ctx.here, ctx.emit, ctx.site, ctx.put, ctx.state
for site in (0x1202ee0, 0x31f39f4): # mov x8,#0xa00; movk x8,#0x5a0,lsl #32
fs_site(site, '084081d208b4c0f2')
start = here(); emit(ADRP(8, here(), ST))
for w in (0xf9401d08, # ldr x8,[x8,#0x38] width | height << 32
0xb5000068, # cbnz x8,+12 set: keep it
0xd2814008, # mov x8,#0xa00 2560
0xf2c0b408): # movk x8,#0x5a0,lsl #32 1440
emit(w)
emit(B(here(), site + 8))
fs_put(site, [B(site, start), NOP], 'render size: %s from the state page (DM_RENDER_SIZE), 2560x1440 when it is 0' % ('output (swap chain) size' if site == 0x1202ee0 else 'docked render size'))
site = 0x112c604 # ldr x8,[x9,x8,lsl #3] the display mode's output size from the table
fs_site(site, '287968f8')
start = here(); emit(0xf8687928) # ldr x8,[x9,x8,lsl #3]
emit(ADRP(16, here(), ST))
for w in (0xf9401e10, # ldr x16,[x16,#0x38]
0xb40000b0, # cbz x16,+20 not set: the table's entry
0xd2814011, # mov x17,#0xa00
0xf2c0b411, # movk x17,#0x5a0,lsl #32
0xeb11011f, # cmp x8,x17 the 2560x1440 entry (docked)
0x9a880208): # csel x8,x16,x8,eq
emit(w)
emit(B(here(), site + 4))
fs_put(site, [B(site, start)], 'render size: the display mode\'s 2560x1440 output entry becomes the state page\'s size (DM_RENDER_SIZE)')
for site, orig, ldr, cbz, fmov, name in ((0xecbc80, 0x52a8a409, 0xb9403929, 0x340000c9, 0x1e2603e9, 'width'), # mov w9,#0x45200000 (2560.0f)
(0xecbcb4, 0x52a89688, 0xb9403d08, 0x340000c8, 0x1e2603e8, 'height')): # mov w8,#0x44b40000 (1440.0f)
r = 9 if name == 'width' else 8
fs_site(site, orig.to_bytes(4, 'little').hex())
start = here(); emit(ADRP(r, here(), ST))
for w in (ldr, # ldr wR,[xR,#0x38 / 0x3c]
cbz, # cbz wR,orig (+24)
0xfc1f0fff, # str d31,[sp,#-16]!
0x1e23001f | r << 5, # ucvtf s31,wR
fmov, # fmov wR,s31
0xfc4107ff): # ldr d31,[sp],#16
emit(w)
emit(B(here(), site + 4))
emit(orig); emit(B(here(), site + 4))
fs_put(site, [B(site, start)], 'render size: output %s as a float from the state page (DM_RENDER_SIZE)' % name)
ctx.capabilities.add('RENDER_SIZE')

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 +136,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': 'render size: the docked output and render size, the display mode\'s 2560x1440 entry and the float output size from the state page', 'now': 'build', 'goal': 'game', 'purpose': 'rendering',
'why': "five fixed 2560x1440 constants in v131072's main (the sites PR #1460 found for its ultrawide cuts), 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 headless at 2560x1440 and 3840x2160 (swapchain at the size, no crash, 60 fps held), in play at 2560x1440 and 3024x1702 (M5 Max, macOS 26.6.2, 2026-11-08 and 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_RENDER_SIZE choice 0=Game's own (as on the Switch),1920x1080=1920 × 1080,2560x1440=2560 × 1440,3840x2160=3840 × 2160 0 fixups:RENDER_SIZE Game Resolution Higher sizes take more GPU time per frame 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
10 changes: 10 additions & 0 deletions dm/host/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,16 @@ 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);
// Render size, for builds whose stub reads it (the RENDER_SIZE capability: Hades II 1.0.131248's app init): DM_RENDER_SIZE=<w>x<h>, 16:9 from 1280x720 to 3840x2160, sets the
// game's own swapchain and screen-sized targets; unset or 0 keeps the game's size. Builds without such a stub ignore the field
const char *rz = getenv("DM_RENDER_SIZE"); uint32_t wh[2] = {0, 0};
if (rz && strcmp(rz, "0")) {
unsigned w = 0, h = 0; char tail = 0;
if (sscanf(rz, "%ux%u%c", &w, &h, &tail) != 2 || w * 9 != h * 16 || w < 1280 || w > 3840)
LOG("[RED] DM_RENDER_SIZE=%s: must be <width>x<height>, 16:9, from 1280x720 to 3840x2160; keeping the game's size", rz);
else { wh[0] = w; wh[1] = h; LOG("%s: render size %ux%u (DM_RENDER_SIZE)", g_fps_mod, w, h); }
}
memcpy(dm_fps_state + 0x38, wh, sizeof wh);
// 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
Loading
Loading