Skip to content

feat(libSceNpTrophy2): report the title's trophy data from trophyNN.ucp - #7262

Merged
oneandonlydean merged 4 commits into
boykopovar:mainfrom
EagleBearerYS:prep/np-trophies
Oct 18, 2026
Merged

oneandonlydean merged 4 commits into
boykopovar:mainfrom
EagleBearerYS:prep/np-trophies

Conversation

@EagleBearerYS

@EagleBearerYS EagleBearerYS commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

What

The trophy queries report the title's own trophy data. Nothing is bundled: the title's own sce_sys/trophy2/trophyNN.ucp is read once per service label, on first use. This is the read-only first half of the split asked for in review: it writes no host files and leaves libSceNpUniversalDataSystem's code as on main. Recording unlocks and statistics is #7335, stacked on this PR.

  • The title's trophy data. sceNpTrophy2GetTrophyInfo, GetTrophyInfoArray, GetGameInfo, GetGroupInfo and GetGroupInfoArray report the names, descriptions, rewards, grades, groups, hidden and reward flags, trophy and grade counts, and a progressive trophy's target from trophyNN.ucp. Texts follow ANYPS5_LANGUAGE, then en-US, then the file's defaultLanguage. The first query prints what was read: [trophy] <file>: <n> trophies, <m> groups, texts in <tag>.
  • Every trophy reports as locked. Nothing records unlocks yet, so a trophy reports unlocked = false with no unlock time, a progressive trophy reports a progress of 0, and the unlocked counts and progress_percentage are 0, as on main. feat(libSceNpTrophy2,libSceNpUniversalDataSystem): record trophy unlocks and statistics #7335 records unlocks and connects these queries to them.
  • Contexts remember their user and service label, so a query reads the data of its own label. sceNpTrophy2CreateContext returns 1, 2, 3 and so on, where main always returned 1, and DestroyContext forgets the context.

Planet of Lana (PPSA19450) reads its own trophy data at boot. This line comes from this PR's reader:

[trophy] /app0/sce_sys/trophy2/trophy00.ucp: 25 trophies, 1 group, texts in en-US

Titles that ship no trophyNN.ucp behave as before: every return code is the same, and the queries keep today's placeholders. A missing file is silent (a [uds] line with APS5_TRACE_UDS). A malformed file logs one [trophy] <file> is malformed, so ...: <reason> line, and the queries keep the placeholders.

How:

  • The files. A bounds-checked reader for the .ucp container and a strict JSON reader (RFC 8259, with a 64-level depth limit and a cap of 1,048,576 values per document), both in libSceNpTrophy2, with no new dependency. Parsing does no I/O and throws with the reason on malformed input.
  • One layout change (its own commit): NpTrophy2Progress becomes {int32 type; 4 reserved bytes; uint64 value}, 16 bytes. It was a bare uint32, with no public source, while the constants already defined a progress type with no field to hold it. This puts a trophy's name at offset 32 and makes GetTrophyInfoArray's stride 1312 bytes. All six structure sizes are now pinned with static_asserts.
  • The console language. The parser sceSystemServiceParamGetInt used for the language moves inline into SystemService.hpp, so Trophy2 can use it without linking libSceSystemService. The error text is unchanged.
  • No host files. The only file this PR opens is trophyNN.ucp, for reading. guest_np_trophy_data is registered with the other trophy guest tests in libSceNpUniversalDataSystem's CMakeLists.txt, but at this PR it calls no UDS function.

Choices the public data leaves open, each listed as debt:

  • With trophy data loaded, a trophy or group id that isn't in the file throws, naming the id and the file, where main returned a placeholder for any id. The console's error codes for it aren't confirmed.
  • The base group is −1, listed first only when some trophy has no groupId. Hidden trophies report their names as they are.
  • The reader's limits: 256 MiB per file, 4,096 files per container, 64 nesting levels and 1,048,576 values per JSON document. A file past one is malformed, so the title runs without it. The console's limits aren't known.

Sources. Interface facts only, no code, from KytyPS5 (GPL-2.0) at 9e41d8320a:

  • src/common/trophies.cpp: the .ucp container layout, the file paths, tropconf.json's and tropmeta_<tag>.json's keys, and the locale tags;
  • src/libs/libTrophy.cpp: the query structures' layout.

KytyPS5's error codes aren't adopted, since no other public source confirms them. The return codes are unchanged.

Commits (each builds and passes the tests that exist at it):

  1. refactor(libSceSystemService): share the console language setting: the console language parser moves inline, for Trophy2.
  2. fix(libSceNpTrophy2): give progress values a type and a 64-bit value: the layout change above.
  3. feat(libSceNpTrophy2): report the title's trophy data from trophyNN.ucp: the reader with its limits, the trophy data in the queries, the contexts, and np_trophy2_package plus guest_np_trophy_data.
  4. docs: describe trophy data in USAGE: the "Trophies" section, saying that every trophy reports as locked for now.

Overlap (checked against main f1af6c5 and the 33 open PRs that touch the same files; the ones that merge into main merge with this PR too):

Tested

Every test builds its own synthetic .ucp files in a fresh directory; none uses a title's data.

  • np_trophy2_package (unit):
    • the container: names, contents, every truncation of a valid file rejected, and malformed headers and entries;
    • the JSON reader: escapes, surrogate pairs, the BOM, duplicate keys, number ranges, the depth limit, and malformed documents;
    • the value cap: exactly 1,048,576 values parse, one more is refused, and a tropconf.json padded past the cap is refused as malformed;
    • the message for missing texts names each language it tried once;
    • the trophy data: grades, groups, flags, platinum ids, the unlock conditions, the progressive target and the language fallbacks; malformed data (bad grades, ids and groups, a missing or invalid tropconf.json, too many groups, a file that isn't a container) throws;
    • progress and counts with nothing unlocked.
  • guest_np_trophy_data, through the built libraries' exports only: every query's names, grades, groups, flags and progressive target; an unknown trophy id throwing; the lists in id order from their offsets; no unlocks before any event; and a missing and a malformed file leaving the placeholders. guest_nptrophy2 still passes unchanged.
  • Linux (Ubuntu 24.04, GCC 13.3, CI's configure flags, as an unprivileged user), on main 5361e69: 1,407 tests, 1,334 passed, 68 skipped, 5 failed. main on the same machine gives 1,405, 1,332, 68 and 5.
    • Per test, the only difference is the 2 tests this PR adds, both passing.
    • The 5 failures are the IPv6 tests (guest_datagram_* and guest_tcp), which fail on that machine on main too, and guest_sce_net skips there for the same reason.
    • Each of the 4 commits builds and passes the trophy and system-service tests that exist at it (3, then 5), and check_test_registration.py and check_conventions.py pass.
  • Windows, the Build workflow's Windows job on my fork, at 61e12c7: 1,434 tests, 0 failed (run). The macOS and Ubuntu jobs pass too.
  • Planet of Lana (PPSA19450), Windows 11, NVIDIA GeForce RTX 3070 Laptop GPU (driver 617.42), played by hand into Chapter 1, on our test tree for the title (not main; it carries the open fixes the title needs) with the whole trophy series before the split: the title read its trophy data as shown under What, and the log has no fatal error and no [trophy] error.

Not covered, and why:

Checklist

  • Based on main 5361e69; 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 (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none (feat(libSceNpTrophy2,libSceNpUniversalDataSystem): record trophy unlocks and statistics #7335 unblocks PPSA19450's trophies)
  • GPUs tested: not GPU-related
  • AI-assisted: yes

@github-actions

github-actions Bot commented Oct 17, 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 3998 docs/user/USAGE.md
PR 4891 docs/user/USAGE.md
PR 5021 docs/user/USAGE.md
PR 5925 docs/user/USAGE.md
PR 6044 core/libs/prx/libSceNpTrophy2/CMakeLists.txt
PR 6111 docs/user/USAGE.md
PR 6171 docs/user/USAGE.md
PR 6248 core/libs/prx/libSceSystemService/Export.cpp
PR 6361 core/libs/prx/libSceNpUniversalDataSystem/CMakeLists.txt
PR 6447 core/libs/prx/libSceSystemService/Export.cpp
PR 6788 docs/user/USAGE.md
PR 6946 docs/user/USAGE.md
PR 6947 docs/user/USAGE.md
PR 7201 core/libs/prx/libSceSystemService/Export.cpp
PR 7332 core/libs/prx/libSceSystemService/Export.cpp
docs/user/USAGE.md

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Thanks for this. The code reads correct to me, and full CI on 34af9a6 passed on both lanes with all six new tests. Before it goes further, could you split it into two stacked PRs? It changes what nearly every title gets back at boot from two libraries, and two halves keep a regression bisectable to the half that caused it.

  1. Report the title's trophy data (read-only). Parsing trophyNN.ucp (TrophyPackage), TitleTrophies, the GameInfo/GroupInfo/TrophyInfo changes, the shared console language (ccd6799) and the typed 64-bit progress values (e9af6b6), with np_trophy2_package and the reporting half of guest_np_trophy_data. This half writes no host files and leaves UDS as it is on main.
  2. Record unlocks and statistics, stacked on 1. TrophyStore writes, unlock callbacks in Context, UDS event properties, PostEvent, stat rules and the refused unlocks (9073ee6), CreateContext ids, with np_trophy2_store, np_uds_events, guest_np_trophy_unlocks, guest_np_trophy_stats and the posting half of guest_np_trophy_data. The invalid_argument from PostEvent for an event CreateEvent didn't make is fine here, together with its test in Events.cpp.

One thing to decide: the reporting code in 1 asks UnlockedBy / TitleStore().UnlockTick whether a trophy is unlocked (GameInfo.cpp:43, GroupInfo.cpp:40, TrophyInfo.cpp:58). Since nothing records unlocks until 2, part 1 can report everything as locked and 2 can connect the query, or 1 can carry a read-only lookup of the store. Either works; go with whichever keeps 1 smaller.

Two small things for part 2, not blocking:

  • StatStore::Set rewrites and renames the stats file on every stat-setting event (TrophyStore.cpp:169-176). Skipping the write when the value hasn't changed would keep a title that maps a frequent event to a stat off synchronous file I/O.
  • A malformed line in a host record now throws into every PostEvent/unlock query for that user and label, where main returned 0. That's the usual handling for host errors here; a line in the debt entry saying so would help.

SystemServiceConsoleLanguage in SystemService.hpp reads ANYPS5_LANGUAGE
with the same default, range and error as sceSystemServiceParamGetInt,
which now calls it. Other libraries can pick the console language
without linking libSceSystemService.
A progress value is {int32 type, 4 reserved bytes, uint64 value}, as
KytyPS5 lays it out, which makes the trophy details 1312 bytes and the
trophy data 32 bytes. Size checks for every query structure keep the
layout fixed, and the technical debt names its single public source.
The title's sce_sys/trophy2/trophyNN.ucp is read on first use with a
bounds-checked .ucp reader and a small JSON reader. tropconf.json gives
each trophy's grade, group, hidden and reward flags, platinum and
unlock condition, and tropmeta_<tag>.json its texts in the console
language, then en-US, then the file's default language. Contexts
remember their user and service label, so the queries find the file.

The trophy, group and game queries report these names, grades, groups
and counts, list every trophy and group, and give progressive trophies
their target. Unlocks are not recorded yet, so every trophy reports as
locked and nothing is written to the host. A missing file is ignored
and a malformed one is logged once; either way the queries keep their
placeholders. A JSON document that nests deeper than 64 levels or holds
more than 1048576 values counts as malformed, which keeps the parsed
values to about 140 MiB.
@EagleBearerYS EagleBearerYS changed the title feat(libSceNpTrophy2,libSceNpUniversalDataSystem): record trophy unlocks and report the title's trophy data feat(libSceNpTrophy2): report the title's trophy data from trophyNN.ucp Oct 18, 2026
@EagleBearerYS

Copy link
Copy Markdown
Contributor Author

@oneandonlydean split as you asked. This PR is now part 1, the read-only half: 4 commits on main 5361e69, head 61e12c7. It reports the title's trophy data with every trophy locked, which kept it smallest: the unlock predicate, UnlockedBy and PlatinumToUnlock moved to part 2, and nothing here writes a host file or changes UDS's code. It does carry the context registry, since a query needs a context's user and service label to find its trophyNN.ucp.

Part 2 is #7335 (head 8e927be, 9 commits on this PR's head). It records unlocks and statistics and connects these queries to the store. For your two notes on it:

  • StatStore::Set already returns before writing when a statistic's value hasn't changed (TrophyStore.cpp:173), so only a changed value rewrites the file.
  • Its last commit adds the debt entry for a damaged record line: it now throws in every query and post that reads that record, where main returned 0.

With main merged into the head you reviewed, #7335's tree is the same apart from that debt entry. A run that mirrors CI's Linux job, and the Windows job on my fork, pass on both heads; the numbers are in each PR's Tested section.

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.

2 participants