fix(libSceNpTrophy2): return INVALID_TROPHY_ID for a trophy that is not in the title's data #9115

Merged
thuanquang merged 1 commit from upstream-pr/9115 into main 2026-10-22 20:43:59 +00:00
thuanquang commented 2026-10-21 12:37:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-21T12:37:02Z.


What

METAL GEAR SOLID Master Collection Vol. 1 (PPSA14363) stops a few seconds after start-up on main 3e91c8edf5 (64 commits before this branch's base 2f161d4f33; no libSceNpTrophy2 file has changed since, and TrophyInfo.cpp:86 still throws on current main eaff87674c):

[trophy] /app0/sce_sys/trophy2/trophy00.ucp: 19 trophies, 1 group, texts in en-US
...
terminate called after throwing an instance of 'std::invalid_argument'
  what():  sceNpTrophy2GetTrophyInfo: trophy 19 is not in /app0/sce_sys/trophy2/trophy00.ucp
FATAL: abort() (SIGABRT) on thread 6512

The title's trophy data has ids 0 to 18, and the title asks for trophy 19. #7262 made sceNpTrophy2GetTrophyInfo read the title's trophyNN.ucp and throw for an id that is not in it, and chose not to adopt KytyPS5's error codes because no other public source confirmed them. KytyPS5 is still the only source for this code. REVERSE_ENGINEERING.md lists other implementations, KytyPS5 by name, as the third kind of source, after a console measurement and the library's own code; neither of those two is used here, and either would settle the value. main already returns error codes on KytyPS5's word alone: sceAudioOut2MasteringGetState returns 0x80268204 for a states id it does not know and 0x80268201 for a null state (libSceAudioOut debt).

KytyPS5 returns NP_TROPHY2_ERROR_INVALID_TROPHY_ID for such an id, before it writes either output. It defines the value as 0x8055390a (L123). This is the KytyPS5 commit the libSceNpTrophy2 debt file links for the structure layouts (its progress_percentage and platinum entries also follow KytyPS5, without naming a commit), and main already defines its NP_TROPHY2_ERROR_ICON_FILE_NOT_FOUND value (0x80553911, L25; added in 0c2cfe0564), though the icon queries throw instead of returning it. The code also has the low byte of the PS4 library's INVALID_TROPHY_ID, 0x8055160A (shadPS4), as KytyPS5's INVALID_ARGUMENT and INVALID_CONTEXT do (0x04 and 0x09, L121-L122, against the PS4 library's 0x80551604 and 0x80551609, shadPS4); that is a pattern, not a source. The only other project found to carry 0x8055390a, Orbistoun, takes its codes from "the reference emulators" and says they are "Assumed, not measured". With this change, sceNpTrophy2GetTrophyInfo returns SCE_NP_TROPHY2_ERROR_INVALID_TROPHY_ID (0x8055390A) and writes neither output. Whether the console returns the same code is not confirmed; the debt entry says so.

Unchanged: a group id that is not in the data still throws in sceNpTrophy2GetGroupInfo (KytyPS5 returns 0x8055390B there, L366 and L124, but no title is known to need it), and both outputs null still throws.

The "Trophy queries" debt entry is rewritten gap first (959 -> 992 characters). It keeps the other facts, and replaces "A trophy or group that is not in the file throws" with the new return of sceNpTrophy2GetTrophyInfo (named, since sceNpTrophy2GetTrophyIcon in the same file still throws for every id) and "A group that is not in the data throws".

Tested

Windows 11 26200, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. This branch is one commit (a42182ef49) on main 2f161d4f33. It differs from 6eb4376d7b, on which the results below were measured, only in the wording of the debt entry. Red, the first green run and the title run used the same change on main 3e91c8edf5; no file this change touches differs between the two, and green was repeated on 6eb4376d7b.

  • guest_np_trophy_data: trophy ids 8 (one past the synthetic package's last id, the title's pattern), 99 and -1 return 0x8055390A, and both outputs keep their 0x5a fill. The known-trophy checks around them (ids 0, 1, 5 and 6 report their data) and the unknown-group check (still throws) are the controls.
  • Red, main's library with only this test: guest_np_trophy_data fails with terminate called after throwing an instance of 'std::invalid_argument' / what(): sceNpTrophy2GetTrophyInfo: trophy 8 is not in /app0/sce_sys/trophy2/trophy00.ucp, the message the title stops on (8 where the title has 19).
  • Green: guest_np_trophy_data, guest_nptrophy2, guest_np_trophy_unlocks, guest_np_trophy_stats, np_trophy2_store, np_trophy2_package and np_uds_events pass 3 of 3, on 3e91c8edf5 and again on 6eb4376d7b.
  • Confirmed on PPSA14363 (own dump), RX 6700 XT: gets past the trophy 19 stop. With this change on main 3e91c8edf5 the title no longer aborts: it creates its save data after the trophy query and runs until the 300 s limit of the test run, with no throw or abort in the log. Unmodified main aborts about 7 s after start-up with the message above.
  • python tools/check_conventions.py --base origin/main with this title and body passes.
  • python tools/pr_overlap.py --branch fix/trophy2-unknown-id-error: only #8218 shares a file, docs/dev/debt/libSceNpTrophy2.md (not compared, because #8218 conflicts with main); #8218 changes other entries of that file, not "Trophy queries".
  • Windows 10 (@xXPBSXx, Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7, Release, head 6eb4376d7b): guest_np_trophy_data passes 3 of 3, and fails 3 of 3 (0xc0000409) with this PR's two library files taken from 2f161d4f33.
  • Not tested: Linux, and the console.

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: PPSA14363 #9615
  • GPUs tested: n/a (CPU tests); the title rerun used an AMD Radeon RX 6700 XT (gfx1031), driver 32.0.21045.5002
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4951650054 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9115). Originally posted by [thuanquang](https://github.com/thuanquang) on 2026-10-21T12:37:02Z. --- ### What METAL GEAR SOLID Master Collection Vol. 1 (PPSA14363) stops a few seconds after start-up on `main` 3e91c8edf5 (64 commits before this branch's base 2f161d4f33; no libSceNpTrophy2 file has changed since, and `TrophyInfo.cpp:86` still throws on current `main` eaff87674c): ``` [trophy] /app0/sce_sys/trophy2/trophy00.ucp: 19 trophies, 1 group, texts in en-US ... terminate called after throwing an instance of 'std::invalid_argument' what(): sceNpTrophy2GetTrophyInfo: trophy 19 is not in /app0/sce_sys/trophy2/trophy00.ucp FATAL: abort() (SIGABRT) on thread 6512 ``` The title's trophy data has ids 0 to 18, and the title asks for trophy 19. #7262 made `sceNpTrophy2GetTrophyInfo` read the title's `trophyNN.ucp` and throw for an id that is not in it, and chose not to adopt KytyPS5's error codes because no other public source confirmed them. KytyPS5 is still the only source for this code. [REVERSE_ENGINEERING.md](https://github.com/boykopovar/AnyPS5/blob/2f161d4f33f82bca2cc113cbd9432adf1dc0ec1e/docs/dev/REVERSE_ENGINEERING.md#L7-L16) lists other implementations, KytyPS5 by name, as the third kind of source, after a console measurement and the library's own code; neither of those two is used here, and either would settle the value. `main` already returns error codes on KytyPS5's word alone: `sceAudioOut2MasteringGetState` returns `0x80268204` for a states id it does not know and `0x80268201` for a null state ([libSceAudioOut debt](https://github.com/boykopovar/AnyPS5/blob/2f161d4f33f82bca2cc113cbd9432adf1dc0ec1e/docs/dev/debt/libSceAudioOut.md#L12)). [KytyPS5](https://github.com/KytyPS5/KytyPS5/blob/9e41d8320a2774b303fbad344c2347e8d0292e83/src/libs/libTrophy.cpp#L409-L412) returns `NP_TROPHY2_ERROR_INVALID_TROPHY_ID` for such an id, before it writes either output. It defines the value as `0x8055390a` ([L123](https://github.com/KytyPS5/KytyPS5/blob/9e41d8320a2774b303fbad344c2347e8d0292e83/src/libs/libTrophy.cpp#L123)). This is the KytyPS5 commit the libSceNpTrophy2 debt file links for the structure layouts (its `progress_percentage` and platinum entries also follow KytyPS5, without naming a commit), and `main` already defines its `NP_TROPHY2_ERROR_ICON_FILE_NOT_FOUND` value (`0x80553911`, [L25](https://github.com/KytyPS5/KytyPS5/blob/9e41d8320a2774b303fbad344c2347e8d0292e83/src/libs/libTrophy.cpp#L25); added in 0c2cfe0564), though the icon queries throw instead of returning it. The code also has the low byte of the PS4 library's `INVALID_TROPHY_ID`, `0x8055160A` ([shadPS4](https://github.com/shadps4-emu/shadPS4/blob/c2814041e546bf75c12756dbec9da911c721ce1c/src/core/libraries/np/np_error.h#L353)), as KytyPS5's `INVALID_ARGUMENT` and `INVALID_CONTEXT` do (`0x04` and `0x09`, [L121-L122](https://github.com/KytyPS5/KytyPS5/blob/9e41d8320a2774b303fbad344c2347e8d0292e83/src/libs/libTrophy.cpp#L121-L122), against the PS4 library's `0x80551604` and `0x80551609`, [shadPS4](https://github.com/shadps4-emu/shadPS4/blob/c2814041e546bf75c12756dbec9da911c721ce1c/src/core/libraries/np/np_error.h#L347-L352)); that is a pattern, not a source. The only other project found to carry `0x8055390a`, [Orbistoun](https://github.com/project-oops/Orbistoun/blob/d567da0172f681ca6d233f3873305d59318a8b4f/crates/orbistoun-systemservice/src/trophy.rs#L10-L13), takes its codes from "the reference emulators" and says they are "Assumed, not measured". With this change, `sceNpTrophy2GetTrophyInfo` returns `SCE_NP_TROPHY2_ERROR_INVALID_TROPHY_ID` (`0x8055390A`) and writes neither output. Whether the console returns the same code is not confirmed; the debt entry says so. Unchanged: a group id that is not in the data still throws in `sceNpTrophy2GetGroupInfo` (KytyPS5 returns `0x8055390B` there, [L366](https://github.com/KytyPS5/KytyPS5/blob/9e41d8320a2774b303fbad344c2347e8d0292e83/src/libs/libTrophy.cpp#L366) and [L124](https://github.com/KytyPS5/KytyPS5/blob/9e41d8320a2774b303fbad344c2347e8d0292e83/src/libs/libTrophy.cpp#L124), but no title is known to need it), and both outputs null still throws. The "Trophy queries" debt entry is rewritten gap first (959 -> 992 characters). It keeps the other facts, and replaces "A trophy or group that is not in the file throws" with the new return of `sceNpTrophy2GetTrophyInfo` (named, since `sceNpTrophy2GetTrophyIcon` in the same file still throws for every id) and "A group that is not in the data throws". ### Tested Windows 11 26200, WinLibs GCC 15.2.0 r7, Release, `BUILD_TESTING=ON`. This branch is one commit (a42182ef49) on `main` 2f161d4f33. It differs from 6eb4376d7b, on which the results below were measured, only in the wording of the debt entry. Red, the first green run and the title run used the same change on `main` 3e91c8edf5; no file this change touches differs between the two, and green was repeated on 6eb4376d7b. - `guest_np_trophy_data`: trophy ids 8 (one past the synthetic package's last id, the title's pattern), 99 and -1 return `0x8055390A`, and both outputs keep their `0x5a` fill. The known-trophy checks around them (ids 0, 1, 5 and 6 report their data) and the unknown-group check (still throws) are the controls. - Red, `main`'s library with only this test: `guest_np_trophy_data` fails with `terminate called after throwing an instance of 'std::invalid_argument'` / `what(): sceNpTrophy2GetTrophyInfo: trophy 8 is not in /app0/sce_sys/trophy2/trophy00.ucp`, the message the title stops on (8 where the title has 19). - Green: `guest_np_trophy_data`, `guest_nptrophy2`, `guest_np_trophy_unlocks`, `guest_np_trophy_stats`, `np_trophy2_store`, `np_trophy2_package` and `np_uds_events` pass 3 of 3, on 3e91c8edf5 and again on 6eb4376d7b. - Confirmed on PPSA14363 (own dump), RX 6700 XT: gets past the trophy 19 stop. With this change on `main` 3e91c8edf5 the title no longer aborts: it creates its save data after the trophy query and runs until the 300 s limit of the test run, with no throw or abort in the log. Unmodified `main` aborts about 7 s after start-up with the message above. - `python tools/check_conventions.py --base origin/main` with this title and body passes. - `python tools/pr_overlap.py --branch fix/trophy2-unknown-id-error`: only #8218 shares a file, `docs/dev/debt/libSceNpTrophy2.md` (not compared, because #8218 conflicts with `main`); #8218 changes other entries of that file, not "Trophy queries". - Windows 10 ([@xXPBSXx](https://github.com/boykopovar/AnyPS5/pull/9115#issuecomment-6321371323), Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7, Release, head `6eb4376d7b`): `guest_np_trophy_data` passes 3 of 3, and fails 3 of 3 (`0xc0000409`) with this PR's two library files taken from `2f161d4f33`. - Not tested: Linux, and the console. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: PPSA14363 #9615 - [x] GPUs tested: n/a (CPU tests); the title rerun used an AMD Radeon RX 6700 XT (gfx1031), driver 32.0.21045.5002 - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
xXPBSXx commented 2026-10-21 16:44:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T16:44:12Z.


Independent Windows run of this PR (data only).

Environment: Windows 10 Pro 10.0.19045, Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON. Merge-tree of the PR head against main is clean. I built only guest_np_trophy_data_tests; ctest -N -R guest_np_trophy_data lists exactly one test.

PR head tested: 6eb4376d7b9d5e54cf0b888c7c8a3e245a911df1.

Results (3 runs each):

  • PR head: guest_np_trophy_data passes 3/3.
  • Baseline: I kept the PR's test and replaced only these production files: core/libs/prx/libSceNpTrophy2/include/NpTrophy2Constants.hpp, core/libs/prx/libSceNpTrophy2/src/TrophyInfo.cpp with the version from the PR's merge base (2f161d4f33), then rebuilt. The test fails 3/3 (exit 0xc0000409). I restored the PR's files afterwards.

GPU: the run output has no Selected GPU line; no GPU claim is made.

Not run: other platforms, the other tests in the same family, the full repository CTest, and any title or console run.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6321371323 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9115#issuecomment-6321371323). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-21T16:44:12Z. --- Independent Windows run of this PR (data only). **Environment:** Windows 10 Pro 10.0.19045, Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON. Merge-tree of the PR head against `main` is clean. I built only `guest_np_trophy_data_tests`; `ctest -N -R guest_np_trophy_data` lists exactly one test. **PR head tested:** `6eb4376d7b9d5e54cf0b888c7c8a3e245a911df1`. **Results (3 runs each):** - PR head: `guest_np_trophy_data` passes 3/3. - Baseline: I kept the PR's test and replaced only these production files: `core/libs/prx/libSceNpTrophy2/include/NpTrophy2Constants.hpp`, `core/libs/prx/libSceNpTrophy2/src/TrophyInfo.cpp` with the version from the PR's merge base (`2f161d4f33`), then rebuilt. The test fails 3/3 (exit 0xc0000409). I restored the PR's files afterwards. **GPU:** the run output has no `Selected GPU` line; no GPU claim is made. **Not run:** other platforms, the other tests in the same family, the full repository CTest, and any title or console run. AI-assisted (Claude Code).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!9115
No description provided.