Skip to content

feat(libSceNpCppWebApi): answer the Matchmaking DateTime accessors - #19500

Merged
oneandonlydean merged 3 commits into
boykopovar:mainfrom
Opensource55:feat/npcpp-matchmaking-datetime
Nov 13, 2026
Merged

oneandonlydean merged 3 commits into
boykopovar:mainfrom
Opensource55:feat/npcpp-matchmaking-datetime

Conversation

@Opensource55

@Opensource55 Opensource55 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What

Answers eight Matchmaking2V1 accessors that were NotImplemented stubs, and corrects the four that were declared with a return type too narrow to hold what the console returns.

The offsets

Read off libSceNpCppWebApi.prx in Demon's Souls (PPSA01341). Every value is one eight-byte slot with a one-byte flag in the byte directly after it:

accessor module size
GetOfferResponseBody::getCreatedDateTime mov rax, [rdi + 0xe8] 8
GetOfferResponseBody::createdDateTimeIsSet movzx eax, byte [rdi + 0xf0] 8
GetOfferResponseBody::getUpdatedDateTime mov rax, [rdi + 0xf8] 8
GetOfferResponseBody::updatedDateTimeIsSet movzx eax, byte [rdi + 0x100] 8
GetTicketResponseBody::getCreatedDateTime mov rax, [rdi + 0x130] 8
GetTicketResponseBody::createdDateTimeIsSet movzx eax, byte [rdi + 0x138] 8
GetTicketResponseBody::getUpdatedDateTime mov rax, [rdi + 0x140] 8
GetTicketResponseBody::updatedDateTimeIsSet movzx eax, byte [rdi + 0x148] 8

The declaration change, and why it is not optional

The four getters were declared int. The module returns them in rax, eight bytes; through an int, 0x1122334455667788 becomes 0x55667788. Implementing them as declared would have produced code that compiles, passes a naive test, and silently drops every timestamp's upper half.

Three independent reasons to widen to std::uint64_t rather than pick something new:

  1. The module writes rax, not eax, so the return is 64-bit. The tree already reads this exact instruction shape as a 64-bit value elsewhere: Leaderboards2V1::Entry::getScore and TitleCloudStorage2V1::DataStatus::getLastUpdatedDateTime are both std::uint64_t over mov rax, qword ptr [rdi + N].
  2. The same API carries a date as SceRtcTick: Leaderboards2V1::RecordScoreRequestBody::setComparedDateTime takes const SceRtcTick&, and a tick is a single 64-bit count.
  3. The flag is its own byte right after the value, in both bodies. That makes each pair a value plus an optional marker, not a pointer that could be null-checked instead.

The four flags keep int: movzx of one byte yields 0 or 1, which fits.

No other translation unit references these symbols, so the widening touches nothing but the four declarations.

Verification

  • guest_np_cpp_web_api_matchmaking_datetime passes.
  • All nine other suites of this library still pass: 18 of 18.
  • All eight symbols appear as NID exports in the patched libSceNpCppWebApi.prx.
  • The library's measured count moves 1332 → 1340, nothing else changes.
  • tools/check_conventions.py --base upstream/main passes.

Scope note

Same-family accessors that need a different treatment are left alone here: GetRankingResponseBody::getLastUpdatedDateTime is declared const void*, which is eight bytes wide but the wrong type, and it is not a Matchmaking2V1 symbol. I would rather fix that separately than fold an unrelated declaration change into this one.

AI-assisted: yes.

Tested

guest_np_cpp_web_api_matchmaking_datetime deliberately uses fixtures whose high halves are non-zero (0x1122334455667788, 0x99aabbccddeeff00, 0xf0e0d0c0b0a09080, 0xffffffff00000001), so a 32-bit return fails rather than passing by accident. It also:

  • checks each flag both ways (0 and non-zero, including 0x80 to show it is a flag and not the byte value);
  • writes the bytes on either side of each value to prove the read window is exactly eight bytes and does not bleed into a neighbour.

Checklist

`libSceNpCppWebApi.prx` in Demon's Souls (PPSA01341) reads each of these
from one eight-byte slot, with a one-byte flag in the byte directly after
it:

    GetOfferResponseBody::getCreatedDateTime    mov rax, [rdi + 0xe8]
    GetOfferResponseBody::createdDateTimeIsSet  movzx eax, byte [rdi + 0xf0]
    GetOfferResponseBody::getUpdatedDateTime    mov rax, [rdi + 0xf8]
    GetOfferResponseBody::updatedDateTimeIsSet  movzx eax, byte [rdi + 0x100]
    GetTicketResponseBody::getCreatedDateTime   mov rax, [rdi + 0x130]
    GetTicketResponseBody::createdDateTimeIsSet movzx eax, byte [rdi + 0x138]
    GetTicketResponseBody::getUpdatedDateTime   mov rax, [rdi + 0x140]
    GetTicketResponseBody::updatedDateTimeIsSet movzx eax, byte [rdi + 0x148]

The getters, however, were declared `int` in `include/Api.hpp`, which
cannot carry what the module returns: the value comes back in `rax` as
eight bytes, and `0x1122334455667788` through an `int` leaves only
`0x55667788`. So the four declarations change to `std::uint64_t` and the
bodies read eight bytes; the four flags keep `int`, since `movzx` of a
single byte yields 0 or 1.

Three things back the widening rather than it being a guess:

- The module leaves the upper half in `rax`, not `eax`, so it is a
  64-bit return, and the tree already reads this exact shape the same
  way in two other places: `Leaderboards2V1::Entry::getScore` and
  `TitleCloudStorage2V1::DataStatus::getLastUpdatedDateTime` are both
  `std::uint64_t` over `mov rax, qword ptr [rdi + N]`.
- The same API passes a `DateTime` around as `SceRtcTick`:
  `Leaderboards2V1::RecordScoreRequestBody::setComparedDateTime` takes
  `const SceRtcTick&`, and a tick is one 64-bit count.
- Every flag is its own byte right after its value, in both bodies, so
  the pair is a value plus an optional marker rather than a pointer that
  could be null-checked instead.

`guest_np_cpp_web_api_matchmaking_datetime` stores values whose high
halves are non-zero, so a 32-bit return fails outright, and it checks
the flags both ways. It also writes the bytes on either side of each
value to prove the read window is exactly eight bytes. The library's
measured count moves from 1332 to 1340, and all eight symbols appear as
NID exports in the patched prx; the other nine suites of this library
still pass, 18 of 18 in total.
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Widening the four getters to std::uint64_t is right (an int return would drop the upper half of the timestamp), and the accessors read the slots the table lists. The PR touches no debt doc, and two statements need updating, the same two I raised on #19481:

  1. docs/dev/debt/libSceNpCppWebApi.md, the Matchmaking::V1 entry, still says "Response accessors throw: a failed request produces no response." These eight DateTime accessors now answer a field read; please say which ones, from which offsets, and that their declared return type is 64-bit.
  2. That entry says the Matchmaking behaviour comes from the module bundled with PPSA21564 and PPSA23732 (builds J03093737 and J03341606), while the offsets here come from the PPSA01341 module. Please say which build of that module the listing is from and whether the PPSA21564 module has the same offsets, or record in the entry that only the PPSA01341 build was read.

If #19481 merges first, the first point is one edit of the same sentence for both PRs.

@PrivacyOnion PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 34b6630c64:

  • Conventions: tools/check_conventions.py failed; git diff --check clean.
    (pull request): error: [pr-template] Fill in the pull request template: add the '### What' heading of the template
    (pull request): error: [pr-template] Fill in the pull request template: add the '### Tested' heading of the template
    (pull request): error: [pr-template] Fill in the pull request template: add the '### Checklist' heading of the template
    3 findings, 3 errors; GitHub shows at most 10 error annotations, the job summary lists all
    
  • Build: guest_np_cpp_web_api_matchmaking_datetime_tests built cleanly.
  • CTest (guest_np_cpp_web_api_matchmaking_datetime):
    1/1 Test #4073: guest_np_cpp_web_api_matchmaking_datetime ...   Passed    0.03 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceNpCppWebApi/Export.cpp, core/libs/prx/libSceNpCppWebApi/include/Api.hpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #4073: guest_np_cpp_web_api_matchmaking_datetime ...Subprocess aborted***Exception:   1.91 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified in core/libs/prx/libSceNpCppWebApi/Export.cpp that GetOfferResponseBody getCreatedDateTime and getUpdatedDateTime copy 8-byte values from offsets 0xe8 and 0xf8 via std::memcpy, returning std::uint64_t and avoiding unaligned dereference undefined behavior.
    • Verified in core/libs/prx/libSceNpCppWebApi/Export.cpp that GetTicketResponseBody getCreatedDateTime and getUpdatedDateTime read 8-byte values from offsets 0x130 and 0x140 via std::memcpy, accurately reflecting the 64-bit rax return seen in disassembly.
    • Verified in core/libs/prx/libSceNpCppWebApi/Export.cpp that createdDateTimeIsSet and updatedDateTimeIsSet on both response bodies check the one-byte flag directly following the value (offsets 0xf0, 0x100, 0x138, and 0x148) and return a normalized 0 or 1 matching movzx semantics.
    • Verified in core/libs/prx/libSceNpCppWebApi/include/Api.hpp that the declarations for all four timestamp getters were widened to std::uint64_t with matching APS5_VABI signatures, preserving LP64 and LLP64 portability between Linux and Windows.
    • Verified strict AGENTS.md compliance across modified files, ensuring no illegal code comments were introduced (only the permitted namespace end in GuestNpCppWebApiMatchmakingDateTime.cpp) and no prohibited stubs or special-cased values exist.
    • Verified that core/libs/tests/GuestNpCppWebApiMatchmakingDateTime.cpp comprehensively exercises the accessors with non-zero upper 32-bit timestamps, tests flag values beyond single-bit masks (0x80), and verifies that reads do not bleed into neighboring struct fields.
  • Note: the AI-assisted checkbox can stay.

Requesting changes for the points above.

@JJenkx

JJenkx commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 34b6630c64, merged onto main 28f73b40b4 (32710ed399, clean merge).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.

  • guest_np_cpp_web_api_matchmaking_datetime passes in 3 of 3 runs, none skipped.

AI-assisted: yes.

The four timestamps and their four flags this branch answers had no debt
entry. The new one lists them with their offsets, says they were
inspected statically and not executed, and records that the getters were
declared `int` before this change, which drops the upper half of the word
the module returns in `rax`.

It also states that these eight were read from the PPSA01341 v01.007.000
build only, so no cross-build comparison exists for them, and that the
values, the objects' other fields and any console value remain
unverified.
@Opensource55

Copy link
Copy Markdown
Contributor Author

Thanks for the Linux run and the negative control — that is the check I could not do here (no console, and the Windows host does not run these tests on PRs).

Conventions. The three pr-template errors were the PR body, not the branch: it used ## headings while .github/pull_request_template.md puts ### What / ### Tested / ### Checklist, and tools/check_conventions.py matches exactly those. The body now uses the template headings and I ran the same checker locally against this head before pushing:

python tools/check_conventions.py --base $(git merge-base main HEAD) --head $(git rev-parse HEAD) \
    --title "feat(libSceNpCppWebApi): answer the Matchmaking DateTime accessors" --body body.md
All conventions checks passed.

That is the checker from the base branch, so it is the same rule the job runs; the job should go green on the next event.

Debt entry. 4fb9470957 adds one for these eight accessors: GetOfferResponseBody getCreatedDateTime +0xe8 / createdDateTimeIsSet +0xf0 and getUpdatedDateTime +0xf8 / updatedDateTimeIsSet +0x100; GetTicketResponseBody +0x130 / +0x138 and +0x140 / +0x148. It records that the four getters were declared int before this change — which drops the upper half of the word the module returns in rax — that the offsets come from the PPSA01341 v01.007.000 module, that they were inspected statically and not executed, and that the values, the objects' other fields and any console value are unverified.

On the build question: only PPSA01341 is readable here. The PPSA21564 sce_module copy is a SELF container (4f 15 3d 1d), not a plain ELF, and there is no PPSA05347 or PPSA20397 dump, so no second build can be disassembled on this machine. What I can state is the direction of the difference: the 34 offsets this debt file records from PPSA21564 read back identical out of the PPSA01341 module (34 of 34, class, method and displacement), so the two builds share a layout family. No Matchmaking member is among those 34, so the entry keeps the per-member claim scoped to the one build that was readable rather than implying a second measurement.

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Progress report (135da47 → 41be57d)

📈 System libraries: 40.07% (+0.02%, +8 implemented functions)

✅ 8 implemented
Library Name
libSceNpCppWebApi _ZNK3sce2Np9CppWebApi11Matchmaking2V120GetOfferResponseBody18getCreatedDateTimeEv
libSceNpCppWebApi _ZNK3sce2Np9CppWebApi11Matchmaking2V120GetOfferResponseBody18getUpdatedDateTimeEv
libSceNpCppWebApi _ZNK3sce2Np9CppWebApi11Matchmaking2V120GetOfferResponseBody20createdDateTimeIsSetEv
libSceNpCppWebApi _ZNK3sce2Np9CppWebApi11Matchmaking2V120GetOfferResponseBody20updatedDateTimeIsSetEv
libSceNpCppWebApi _ZNK3sce2Np9CppWebApi11Matchmaking2V121GetTicketResponseBody18getCreatedDateTimeEv
libSceNpCppWebApi _ZNK3sce2Np9CppWebApi11Matchmaking2V121GetTicketResponseBody18getUpdatedDateTimeEv
libSceNpCppWebApi _ZNK3sce2Np9CppWebApi11Matchmaking2V121GetTicketResponseBody20createdDateTimeIsSetEv
libSceNpCppWebApi _ZNK3sce2Np9CppWebApi11Matchmaking2V121GetTicketResponseBody20updatedDateTimeIsSetEv

Changed libraries (implemented exports)

Library Before After Change
libSceNpCppWebApi 1342/1778 (75.48%) 1350/1778 (75.93%) +0.45%

@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed docs labels Nov 13, 2026
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 13, 2026

@PrivacyOnion PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 41be57d451:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_np_cpp_web_api_matchmaking_datetime_tests built cleanly.
  • CTest (guest_np_cpp_web_api_matchmaking_datetime):
    1/1 Test #4084: guest_np_cpp_web_api_matchmaking_datetime ...   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceNpCppWebApi/Export.cpp, core/libs/prx/libSceNpCppWebApi/include/Api.hpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #4084: guest_np_cpp_web_api_matchmaking_datetime ...Subprocess aborted***Exception:   1.42 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified in core/libs/prx/libSceNpCppWebApi/Export.cpp that GetOfferResponseBody (+0xe8, +0xf0, +0xf8, +0x100) and GetTicketResponseBody (+0x130, +0x138, +0x140, +0x148) accessors match the static disassembly offsets from the PPSA01341 module.
    • Verified in core/libs/prx/libSceNpCppWebApi/include/Api.hpp and Export.cpp that getCreatedDateTime and getUpdatedDateTime signatures return std::uint64_t rather than int, matching the 64-bit rax register return and avoiding upper-half timestamp truncation.
    • Verified memory safety and undefined behavior avoidance: std::memcpy correctly loads 64-bit integer values without unaligned access or strict aliasing hazards, and the boolean flags properly normalize non-zero values via != 0.
    • Verified cross-platform LP64 (Linux) and LLP64 (Windows) portability for std::uint64_t and APS5_VABI calling conventions.
    • Verified AGENTS.md compliance: zero forbidden comments in source code, no fake success stubs, no hardcoded game-specific branch hacks, and the technical debt is documented in docs/dev/debt/libSceNpCppWebApi.md.
    • Verified test coverage in core/libs/tests/GuestNpCppWebApiMatchmakingDateTime.cpp: exercises high-half 64-bit values, zero values, boolean flag values including 0x80, and neighbouring slot isolation.
  • Note: the AI-assisted checkbox can stay.

Looks Good To Me

@oneandonlydean
oneandonlydean merged commit 4c0ba9f into boykopovar:main Nov 13, 2026
13 checks passed
@Opensource55
Opensource55 deleted the feat/npcpp-matchmaking-datetime branch November 14, 2026 02:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants