Skip to content

feat(libSceNpTrophy): answer the trophy set, group and count helpers as firmware 13.42 does - #13005

Merged
oneandonlydean merged 3 commits into
boykopovar:mainfrom
zaryabzip:feat/nptrophy-set-helpers
Nov 2, 2026
Merged

oneandonlydean merged 3 commits into
boykopovar:mainfrom
zaryabzip:feat/nptrophy-set-helpers

Conversation

@zaryabzip

@zaryabzip zaryabzip commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

What

Five libSceNpTrophy helpers that read only their arguments now do what firmware 13.42's module does. @BunnyFl sorted the 78 remaining NpTrophy exports from the disassembly (comment) and ran the first four natively, three runs with identical output:

  • sceNpTrophyNumInfoGetTotal(numInfo): the sum of the four uint32 counts, wrapping at 32 bits. {1, 20, 300, 4000} gives 4321, and {0xffffffff, 2, 0, 0} gives 1.
  • sceNpTrophyGroupArrayGetNum(groupArray): the number of set bits in the first uint32 only.
  • sceNpTrophySetInfoGetTrophyNum(setInfo): the number of set bits in bytes 0x00–0x3F, the four 16-byte trophy flag arrays. Later bytes aren't read.
  • sceNpTrophySetInfoGetTrophyFlagArray(setInfo, flagArray): writes the OR of the four arrays into the first 16 bytes of flagArray and leaves the rest alone. It returns the number of set bits in that output, 0 to 128. BunnyFl's follow-up read this from the disassembly, where the export tail-calls the bit loop that counts, and confirmed it natively: 0, 1, 120 and 128 for four inputs.
  • sceNpTrophyConfigHasGroupFeature(config): 0 for a null config, otherwise bit 0 of the byte at +0x90.

The first four have no null checks in the module, so they fault on null here too. The declarations gain these parameters. libSceNpTrophy goes from 17 to 22 of 97. Of the 78, the module sends 45 to the trophy service and the rest read its state or its config object, so those keep throwing.

GuestNpTrophyHelpers.cpp looks the five up at runtime, because main declares them without parameters. It checks BunnyFl's values: the sums, the bit counts, that bytes past 0x3F and past the 16-byte output are left alone, the OR and the feature bit. On main it builds and aborts at the first call.

#12957, which this was stacked on, has merged.

Tested

Windows 11 Home 10.0.26200 (WinLibs MinGW-w64 GCC 15.2.0 UCRT r7, CMake 4.3.1, Ninja 1.13.2) at 85ff681, and Ubuntu 24.04.5 on WSL2 (GCC 13.3.0, CMake 3.28.3, Ninja 1.11.1) with it merged into main 7a225bb:

  • No new warnings on either host. Linux shows only the two -Wformat-truncation lines main already has in Export.cpp, one line lower because of the new <bit> include.
  • ctest -R "^guest_np_trophy": all pass (7 on Windows, 6 on Linux). The new test prints NpTrophy helper tests passed and passes 3 of 3 on --repeat until-fail:3. guest_np_ps4_imports, which also includes the header, passes too.
  • Every file that includes libSceNpTrophy/include/Api.hpp rebuilds without new warnings, and the header builds on its own.
  • Baseline: on feat(libSceNpTrophy): return 0x80551692 from the system debug calls as firmware 13.42 does #12957's head 161792d with only the new test file and its CMakeLists.txt block, the test builds and then aborts with sceNpTrophyNumInfoGetTotal not implemented on both hosts (Windows exit 0xc0000409, Linux SIGABRT).
  • The return-value fix (85ff681): on the previous head 34b21b0 with only the new test, the test stops at a full flag array did not return 128 set bits on both hosts.
  • tools/check_conventions.py passes. No other open PR touches libSceNpTrophy.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)

…s firmware 13.42 does

Firmware 13.42's sceNpTrophySystemDbgCtl, GetDbgParam, GetDbgParamInt,
SetDbgParam and SetDbgParamInt each return 0x80551692 and do nothing else.
…as firmware 13.42 does

Firmware 13.42's sceNpTrophyNumInfoGetTotal, GroupArrayGetNum,
SetInfoGetTrophyNum, SetInfoGetTrophyFlagArray and ConfigHasGroupFeature
read only their arguments: sums, bit counts, an OR of the flag arrays and
one feature bit.
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Progress report (7d5f46e → 85ff681)

📈 System libraries: 44.73% (+0.06%, +10 implemented functions)

✅ 10 implemented
Library Name
libSceNpTrophy sceNpTrophyConfigHasGroupFeature
libSceNpTrophy sceNpTrophyGroupArrayGetNum
libSceNpTrophy sceNpTrophyNumInfoGetTotal
libSceNpTrophy sceNpTrophySetInfoGetTrophyFlagArray
libSceNpTrophy sceNpTrophySetInfoGetTrophyNum
libSceNpTrophy sceNpTrophySystemDbgCtl
libSceNpTrophy sceNpTrophySystemGetDbgParam
libSceNpTrophy sceNpTrophySystemGetDbgParamInt
libSceNpTrophy sceNpTrophySystemSetDbgParam
libSceNpTrophy sceNpTrophySystemSetDbgParamInt

Changed libraries (implemented exports)

Library Before After Change
libSceNpTrophy 12/97 (12.37%) 22/97 (22.68%) +10.31%

@rooklz rooklz 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.

Approving. I checked the diff against BunnyFl's section-2 measurements and section-3 reading (comment) and against the PR's own test.

Provenance / scope

  • The five helpers match the comment exactly: the 4-word wrapping sum, popcount of word 0 only, popcount of bytes 0x00–0x3F, a 16-byte OR of +0x00/+0x10/+0x20/+0x30 with the rest of the output untouched, and HasGroupFeature returning 0 for null and otherwise config[0x90] & 1. Like the module, the first four have no null check. The other 73 stay throwing, which matches sections 3–5. Source 2 is cited in the debt entry.
  • No other code in main calls these exports, so the parameterised declarations break no callers.

Mechanics (head 34b21b0, base bb04a4f, main 52f212e)

  • git merge-tree against main and git diff --check are both clean. check_conventions.py passes.
  • pr_overlap.py: 0 of 1443 open PRs overlap. #12957 is the declared parent.
  • clang x86_64 -fsyntax-only on Export.cpp and GuestNpTrophyHelpers.cpp: 0 errors. The windows lane passes.

Behaviour (standalone on macOS, x86_64, ASan+UBSan)

  • I built the five PR function bodies verbatim into a dylib and ran the unmodified GuestNpTrophyHelpers.cpp against it: NpTrophy helper tests passed, rc=0.
  • 13 mutants, 13 killed (134): null config → 1, & 3, offset 0x8f, popcount of words 0+1, sum of 3 words, saturating 64-bit sum, 32-byte output, OR missing the 4th array, & instead of |, off-by-one array offset, flag-array call returning 1, popcount over 128 and over 48 bytes.

Non-blocking

  • The sceNpTrophySetInfoGetTrophyFlagArray return value wasn't measured. The PR answers 0 and says so in the Functional entry. Since the result is assumed, a maintainer may want that one sentence moved under Silent stubs, or the return value read in BunnyFl's next native run (the test already pins it to 0, so the change would be a single row).

AI-assisted: yes (Claude Code)

@MarcZX10 MarcZX10 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.

Reviewed — changes requested

The five helpers are otherwise supported by the reported module analysis and tests, but the flag-array helper's return value is unknown while the implementation and test both assume success is 0.

What I ran

Reviewed head 34b21b0b3f838085d7f47b0abfddb066c7216d08 against current upstream main 52f212ec053f917455f2f87674ddb708dcc545d8; the merge preview is clean. The PR is explicitly stacked on open #12957. I inspected the changed exports, declarations, tests and debt entry and ran the repository checks below. No local build or tests were run.

git merge-tree --write-tree refs/remotes/upstream/main refs/review/pr-13005-head
git diff --check refs/remotes/upstream/main...refs/review/pr-13005-head
python3 tools/check_conventions.py --base upstream/main --head refs/review/pr-13005-head

Results

Check Result
Merge preview Clean
Diff check Passed (no output)
Repository conventions Passed
Hosted Windows workflow Passed
Focused tests Author reports 7/7 Windows and 6/6 Linux guest_np_trophy tests passing, with the new helper test repeated 3 times; not independently rerun
Negative control Author reports the helper test aborts on the #12957-only baseline at the first new helper; not independently reproduced

Findings

Blocking

  • sceNpTrophySetInfoGetTrophyFlagArray returns 0, and GuestNpTrophyHelpers.cpp asserts that return value. The debt entry and PR body both say the firmware module's return value was not reported. The function's output bytes are measured, but its return is part of the public ABI and is not established by those observations.

    Please capture the helper's return value from the firmware 13.42 module or confirm it from the disassembly, then update the implementation and assertion. If it remains unmeasured, keep that result explicitly unresolved rather than treating 0 as firmware-matched.

Non-blocking

  • The four argument-only helper calculations are consistent with the reported firmware-module runs; the config feature helper is described from disassembly. The reported module execution is not a physical-console measurement.

Sources

Not verified

I did not locally build or run tests. The reported Windows/WSL2 test results are author-provided; no physical PS5 run is reported.

To get this to a good state

Please provide the measured or disassembled return result and update the code, test and debt entry to agree. I will re-run the same source checks on the new head.

@zaryabzip

Copy link
Copy Markdown
Contributor Author

@MarcZX10 Agreed. The return value isn't established, and the test shouldn't pin 0.

@BunnyFl One more detail from the same 13.42 runs, if you have it: what does sceNpTrophySetInfoGetTrophyFlagArray(setInfo, flagArray) return in eax/rax? Is it a fixed value, the output pointer, or something left over from the OR loop (a void function)? If it's void or leftover, I'll drop this helper from the PR and keep it throwing. The other four stay as they are.

@BunnyFl

BunnyFl commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

@zaryabzip @MarcZX10 It returns a value: the number of set bits in the 16-byte flag array it has just written, from 0 to 128.

From the disassembly (firmware 13.42 libSceNpTrophy.sprx):

  • The export zeroes flagArray[0..15] and then ORs in the four arrays with three calls to an internal helper; the first call takes +0x00 and +0x10 together. The third call is a tail jump (jmp, not call), so the export returns whatever that call returns.
  • For each of 128 bits, the helper sets the bit in the output and increments eax when the bit is set in either input, and skips it otherwise. It starts from eax = 0.
  • The last call's inputs are the output array (already +0x00 | +0x10 | +0x20) and +0x30, so its count is the set-bit count of the final array.

Native run (the same harness as before; 3 runs, identical apart from the stack address):

setInfo bytes 0x00–0x3F return (rax) set bits in flagArray[0..15]
all zero 0x0 0
only bit 0 of byte 0x00 0x1 1
a mixed byte pattern 0x78 120
all ones 0x80 128

The full rax holds the count. The helper writes eax, which clears the upper half. So a test can pin the return to the set-bit count of the output.

AI-assisted: yes (Claude Code)

…GetTrophyFlagArray

Firmware 13.42's helper tail-calls its bit loop, which counts the set bits
of the output it writes, so the export returns 0 to 128.
@zaryabzip

Copy link
Copy Markdown
Contributor Author

@MarcZX10 Fixed in 85ff681. BunnyFl settled the return value from the disassembly and a native run: it's the set-bit count of the 16-byte output, 0 to 128. The export now returns that count. The test pins 128, 4, 0 and 1, and the debt entry and description cite the reading. It passes on Windows and on WSL2 merged into main 7a225bb. On the old head, the new test stops at the 128 check.

@MarcZX10 MarcZX10 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.

Reviewed — looks good

The exact head implements the five measured trophy helpers, including the corrected set-bit return value, and the available test evidence supports the change.

What I ran

Reviewed PR head 85ff6817f0732bdb9965f102a07aa764f504b3d2 against base 9624d8c6bb9e96b7aa92b815f55690f69b0a88d5; refreshed current main is f46f453a56f91d77e29ce0cbd7fe5bfb2fb69834. The merge preview with current main is clean (tree 36d0d39c6b66c8c055d71ff7925fb1dcb01bedb0). Environment: Linux 6.1.0-54-amd64 x86_64; no local compiler, build, or test run.

git diff --check upstream/main...refs/review/pr-13005-current
python3 tools/check_conventions.py --base upstream/main
git merge-tree --write-tree upstream/main refs/review/pr-13005-current
gh pr checks 13005 --repo boykopovar/AnyPS5

Results

Check Result
Diff whitespace check Pass; exit 0, no output.
Repository conventions Pass.
Merge preview with current main Clean.
Hosted Windows job Pass on this exact head; 11m41s.
Other hosted jobs Eligibility, labels, report pass; Linux and specialized jobs skipped.
Focused trophy tests The author reports 7 Windows tests and 6 WSL2 tests pass, with the new helper test passing 3/3 on both hosts. WSL2 was tested with this PR merged into main at 7a225bb303; I did not rerun either environment.
Unedited output from local and hosted checks
$ git diff --check upstream/main...refs/review/pr-13005-current
(exit 0; no output)
$ python3 tools/check_conventions.py --base upstream/main
All conventions checks passed.
$ git merge-tree --write-tree upstream/main refs/review/pr-13005-current
36d0d39c6b66c8c055d71ff7925fb1dcb01bedb0
$ gh pr checks 13005 --repo boykopovar/AnyPS5
conventions	pass	21s	https://github.com/boykopovar/AnyPS5/actions/runs/40970129188/job/123784511071
labels	pass	7s	https://github.com/boykopovar/AnyPS5/actions/runs/40970129177/job/123786982471
windows	pass	11m41s	https://github.com/boykopovar/AnyPS5/actions/runs/40970131246/job/123786593567
linux	skipping	0	https://github.com/boykopovar/AnyPS5/actions/runs/40970131246/job/123786596405
register-context	skipping	0	https://github.com/boykopovar/AnyPS5/actions/runs/40970131246/job/123786595212
relinker	skipping	0	https://github.com/boykopovar/AnyPS5/actions/runs/40970131246/job/123786595146
relinker-asan	skipping	0	https://github.com/boykopovar/AnyPS5/actions/runs/40970131246/job/123786596254
write-watch	skipping	0	https://github.com/boykopovar/AnyPS5/actions/runs/40970131246/job/123786595233
eligibility	pass	4s	https://github.com/boykopovar/AnyPS5/actions/runs/40970131246/job/123784513129
report	pass	29s	https://github.com/boykopovar/AnyPS5/actions/runs/40970131561/job/123784513881

The Windows/WSL2 focused results are author-reported in the PR description, not local runs. PR #12957 is still open; this PR contains its already-approved dependency commit 161792da247e010f24fa9c5924ab44daf215eb47.

Negative control

Assertion Change to code under test Did the new test fail?
Unimplemented trophy helpers are detected The author reports testing the added helper test against #12957 with the helpers unimplemented. Yes; it stopped at sceNpTrophyNumInfoGetTotal not implemented.
The flag-array return count is checked The author reports testing the new test against the previous implementation, which returned 0. Yes; it failed the expected 128-bit result.

Findings

Blocking

None found in the reviewed head. The implementation and tests cover the wrapping count sum, relevant bit counts, 16-byte OR output with untouched trailing bytes, the config feature bit, and the measured 0–128 return count.

Non-blocking

The behavior is based on firmware 13.42 disassembly and native-emulator runs reported by the author; it was not independently measured on a physical console.

Sources

Not verified

I did not build or run tests locally, independently reproduce the Windows or WSL2 results, run Linux hosted product tests, or test on a physical console. The specialized hosted jobs were skipped.

@bunbeans2-arch

Copy link
Copy Markdown
Contributor

Windows run (Windows 11, MSYS2 UCRT64 GCC 16.1), this PR (85ff681) merged onto main f7f03da, 3x each:

  • guest_np_trophy_helpers + guest_np_trophy_system_debug: 3/3 pass (the _WIN32 GetProcAddress(LoadLibraryA("libSceNpTrophy.prx"), ...) path resolves all five helpers)
  • same tree with libSceNpTrophy/Export.cpp and include/Api.hpp put back to main: guest_np_trophy_helpers fails 3/3 (sceNpTrophyNumInfoGetTotal not implemented, abort), so the test catches the missing helpers on Windows

Note: GuestNpTrophySystemDebug.cpp and its CMake block already reached main through #12957, so after a merge this PR only adds the helpers part; guest_np_trophy_system_debug passes with or without it.

AI-assisted: yes (Claude Code)

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 14212 docs/dev/debt/libSceNpTrophy.md

@oneandonlydean
oneandonlydean merged commit 49ce360 into boykopovar:main Nov 2, 2026
13 of 14 checks passed
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.

6 participants