Skip to content

hle_time: CreateWithAdjustableSystemClock, and the snapshot type byte - #385

Closed
v0lumehi wants to merge 1 commit into
seedds:mainfrom
v0lumehi:adjustable-clock-snapshot
Closed

v0lumehi wants to merge 1 commit into
seedds:mainfrom
v0lumehi:adjustable-clock-snapshot

Conversation

@v0lumehi

Copy link
Copy Markdown
Contributor

ClockSnapshot::CreateWithAdjustableSystemClock had no HLE entry. A game that snapshots the adjustable user clock went through the SDK's time-service session, which the host never makes, and read a null.

Change

  • A forced entry for _ZN2nn4time13ClockSnapshot31CreateWithAdjustableSystemClockEPS1_ reuses h_time_Snapshot, the standard snapshot's fill path, so both snapshots carry the same context, calendar, steady time point and location name.
  • The type byte at +0xcd is set: 1 for the standard clock, 2 for the adjustable one. CalculateSpanBetween and the user-difference check read it to tell the two clocks apart. Before, the standard snapshot left it at 0 from the memset.

This sits beside the existing AdjustableUserSystemClock::GetCurrentTime take-over and does not change it. #20 covered Adjust/GetCurrentTime, not the snapshot.

Tests

dm/host/tests/t_time.c:

  • The entry writes exactly the 0xd0 bytes of a ClockSnapshot, with guard bytes on both sides.
  • The calendar under DM_FIXED_TIME is right to the second.
  • A change of type alone does not read as a user clock change.

make -C dm/host/tests GAME=010015100B514000 build/t_time gives time: 24 checks, 0 failed on this base (75065df).

Context

This is m1guelpf's fix from LNPANDY/NX2Apple#26, kept with them as the author, in the form LNPANDY reviewed and landed it there (DM_FIXED_TIME is set before the first snapshot, because h_time_GetCurrentTime reads it once). Together with LNPANDY/NX2Apple#24 it got Tomodachi Life: Living the Dream to boot. Until it is here, the fork has to hold hle_time.c back from its upstream sync (LNPANDY/NX2Apple#29). Once it lands, the file comes back with the sync.

The adjustable user clock had no snapshot entry, so a game that calls
ClockSnapshot::CreateWithAdjustableSystemClock read through the SDK's
time-service session, which the host never makes, into a null. The new
entry fills the snapshot the way the standard one does (h_time_Snapshot)
and sets the type byte at +0xcd: 1 for the standard clock, 2 for the
adjustable one, which CalculateSpanBetween and the user-difference check
read to tell the two clocks apart.

With LNPANDY/NX2Apple#24 this got Tomodachi Life: Living the Dream to
boot (reported there). t_time checks that the entry writes exactly the
0xd0 bytes of a ClockSnapshot (guard bytes either side), the calendar
under DM_FIXED_TIME to the second, and that a change of type alone does
not read as a user clock change: 24 checks, 0 failed.

From LNPANDY/NX2Apple#26 (m1guelpf), as LNPANDY reviewed and merged it
there (1f15ad6, which moved DM_FIXED_TIME before the first snapshot:
h_time_GetCurrentTime reads it once).
seedds added a commit that referenced this pull request Oct 27, 2026
Add the missing adjustable-clock snapshot takeover and set the SDK type
byte for both snapshot variants. Both clocks already use host time, so
the new entry shares the existing snapshot fill path without game gates.

Verify the session access and type values in the original SDK, extend the
contributed buffer/calendar tests to 28 checks, and document the ABI and
gameplay validation limits. Correct the comment claiming the current host
snapshot arithmetic inspects the type byte.

The full host and Metal test targets and 379 Python tool tests passed
(16 skipped). The final main-based clock and documentation checks pass.
Odyssey's quick comparison was inconclusive: both runs missed the frame
target, the candidate screenshot was missing and sampled FPS fell. No
new shader failures, interface changes or red-log kinds were found.
Tomodachi gameplay and a full gameplay regression remain untested.

Co-authored-by: v0lumehi <aljic.zijad@gmail.com>
Co-authored-by: Miguel Piedrafita <github@miguel.build>
@seedds

seedds commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Landed on main in 4d2dc7d, with Co-authored-by credit to v0lumehi and Miguel Piedrafita. The contribution was substantive: the missing adjustable snapshot entry and the guarded-buffer/calendar tests are included, with additional coverage and ABI documentation.

The missing HLE registration was reproduced by running the contributed test against the original host. The original Tears of the Kingdom SDK confirms that both snapshot entries read the time-service session and pass type 1 for standard snapshots and 2 for adjustable snapshots. The fix applies to every caller of these SDK APIs, with no game-specific runtime conditions. Both entries share the existing host-clock snapshot fill path.

One comment correction: the current host implementations of CalculateSpanBetween and the user-difference check do not inspect the type byte. The byte is still required SDK snapshot metadata.

Validation:

  • 28 clock checks pass, covering both registrations, guarded buffers, fixed-time calendar, location, source identity and arithmetic.
  • Full host unit and Metal graphics test targets pass; 379 Python tool tests pass with 16 skips.
  • After applying the change to current main, the host build, 28 clock checks and 10 documentation tests pass again. The generated symptom index is current and the final diff was reviewed.
  • Gameplay of a snapshot caller remains unverified here. The usage manifest identifies Tears of the Kingdom, whose local build lacks a runnable Mac host; Tomodachi was not available for testing.

Only Super Mario Odyssey was selected for a narrow shared-host regression check. It has no snapshot imports or snapshot fixups, and the new registration is unreferenced there; four additional unrelated routes would not exercise the changed APIs. Its quick result below is inconclusive, not a passing gameplay check: both revisions missed the route's frame target, the candidate screenshot was missing, and sampled FPS fell. Both logs contain focus changes. Shader/interface checks found no changes or new failures, and there were no new red-log kinds. Other game routes are unchecked. The full Odyssey attempt was stopped during its 32,864-pipeline prebuild, so no full gameplay regression is claimed.

Odyssey quick regression report (earlier patch validation against c589ded)

regress.py check (quick): NEW-FAIL

Baseline c589ded c589ded, candidate worktree c589ded (+ uncommitted changes); Apple M6, macOS 27.0.1, Xcode 27.1; 177.3 s

game status shaders (base → cand) newly failing newly building changed MSL interface (new / known) boot fps p50 frame p99 ms peak MB prepare s new RED
SUPER MARIO ODYSSEY 0100000000010000 NEW-FAIL 27984/27984 → 27984/27984 0 0 0 0 / 0 FAIL 54.1 → 28.5 35.79 → 37.93 3004 → 2983 None → None 0

SUPER MARIO ODYSSEY 0100000000010000: NEW-FAIL

  • NEW-FAIL: frame 2400 not reached by 60 s (max 2668)
  • NEW-FAIL: screenshot at 70 s missing
  • REGRESSION: fps 54.1 → 28.5 (-47.3 %)
    • baseline: exit None, first frame 1.5 s, max frame 2678, reached False, prepare None s, fps 54.1, p50/p99 16.68/35.79 ms, peak 3004 MB
    • candidate: exit None, first frame 1.8 s, max frame 2668, reached False, prepare None s, fps 28.5, p50/p99 34.88/37.93 ms, peak 2983 MB
    • time: chain 21.1 s, smoke 156 s

Closing this PR because the reviewed implementation has landed directly on main.

@seedds seedds closed this Oct 27, 2026
Know-It-All-Brother pushed a commit to Know-It-All-Brother/nxnative that referenced this pull request Nov 9, 2026
Add the missing adjustable-clock snapshot takeover and set the SDK type
byte for both snapshot variants. Both clocks already use host time, so
the new entry shares the existing snapshot fill path without game gates.

Verify the session access and type values in the original SDK, extend the
contributed buffer/calendar tests to 28 checks, and document the ABI and
gameplay validation limits. Correct the comment claiming the current host
snapshot arithmetic inspects the type byte.

The full host and Metal test targets and 379 Python tool tests passed
(16 skipped). The final main-based clock and documentation checks pass.
Odyssey's quick comparison was inconclusive: both runs missed the frame
target, the candidate screenshot was missing and sampled FPS fell. No
new shader failures, interface changes or red-log kinds were found.
Tomodachi gameplay and a full gameplay regression remain untested.

Co-authored-by: v0lumehi <aljic.zijad@gmail.com>
Co-authored-by: Miguel Piedrafita <github@miguel.build>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants