feat(libSceNpTrophy2,libSceNpUniversalDataSystem): record trophy unlocks and statistics #7335
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7335"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-18T00:49:36Z.
What
Trophies now unlock the way a title defines them. This is the second half of the split asked for on #7262 (merged), which reports the title's trophy data with every trophy locked: this PR records unlocks and statistics and connects those queries to them. It is built on #7262's head
61e12c75fd, so with #7262 merged its diff shows only its own commits. The title's ownsce_sys/uds/udsNN.ucpis read once per service label, on first use, like the trophy data._UnlockTrophywith an int32_trophy_idunlocks that trophy for the title, user and service label. The unlock goes in a host file next to save data (/_trophy/<user id>_<service label>.txt) and survives restarts.stats_extraction.jsoninudsNN.ucp). A rule sets a statistic from one of the event's properties. After each event that sets one, every trophy'sunlockConditionis checked (ge,gt,leorltagainst its target) on the values that event set and the stored values of the others, and reached trophies unlock the same way. Statistics keep their latest value in/_trophy/<user id>_<service label>.stats.txt, so progress also survives restarts.platinumTrophyIdis unlocked, whichever way they were unlocked._UnlockTrophyof an id that isn't in it, of the platinum, or of a progressive trophy is refused with one line ([trophy] ignored the posted unlock of trophy 0 for user 268435456: it is the platinum, which unlocks with the last trophy that names it), as KytyPS5 does; those unlock through their statistics and the platinum rule instead. Without trophy data, every posted id of 0 or more is recorded, and no platinum unlocks by itself, since the rule needs the data.progress_percentage.[trophy] <title id> unlocked trophy <id> for user <user>. WithAPS5_TRACE_UDS=1, every post and every statistic it sets is printed too.Planet of Lana (PPSA19450) earns its trophies this way. Its statistics rules are all of kinds this PR skips (see Not covered):
Sneaking past the chef at the start of Chapter 1 posts the unlock of trophy 12, "Sneaky Sisters" ("Sneak past the chef" in the title's own data):
The unlock is stored as
12 63927864523936811in_trophy/268435456_0.txt, next to the title'sapp0/.Titles that ship no
udsNN.ucp, or post no trophy events, behave as with #7262:[uds]line withAPS5_TRACE_UDS).[trophy] <file> is malformed, so ...: <reason>line and turns off only its own feature: without statistics rules, events set no statistic._UnlockTrophykeeps working either way.CreateEventdidn't return, or one already destroyed now throws, as the library's other invalid arguments do. Before, it was ignored.How:
Destroy*on anything else, such as an event's own property object, does nothing, because its owner frees it.$.pathproperty (nested objects givea.bpaths). The value is used if it's a non-negative integer that fits the statistic's type and lies within itsminValue/maxValue. Otherwise it's ignored with one[trophy] ignored <event> $.<path> for stat <id>: <reason>line. A statistic that was never set reaches nothing, soleandlttrophies don't unlock at a start value of 0. Well-formed entries this doesn't support (for example asumaggregation) are skipped, each with one log line.RecordWrittenPath_nid_no_patchlike other host writes. A statistic is written only when its value changes (StatStore::Setreturns early otherwise, TrophyStore.cpp:173), so a statistic that changes with every event writes its file each time. A damaged file throws with its name and line (a debt entry, below).NpTrophy2AddUnlockListener_nid_no_patch) is there for a later pop-up. Removing a listener waits for an unlock callback that is running, so a removed listener is never called.sceNpTrophy2RegisterUnlockCallbackis still not called, because its callback signature isn't public.Choices the public data leaves open, each listed as debt:
SetInt32still counts. The one public implementation requires the exact width.min(statistic, target), and its target once unlocked.progress_percentageweighs gold 6, silver 2 and bronze 1 and leaves the platinum out, as KytyPS5 does; the console's formula is not known._trophy/<user id>_<service label>.txtor.stats.txtthat isn't a new<id> <value>pair (a blank line or one ending in a carriage return included) throws in every trophy query, posted unlock and statistic update that reads that record for its user and service label. The export doesn't return, which stops the title, and the record is read again each time, so it keeps failing until the file is fixed or deleted. Onmainthese calls returned 0.Sources. Interface facts only, no code, from KytyPS5 (GPL-2.0) at 9e41d8320a:
src/common/trophies.cpp: thestats_definition.jsonandstats_extraction.jsonkeys, and the four comparators;src/libs/libTrophy.cpp: the_UnlockTrophyevent and its_trophy_id,CreateEvent's property ownership, and the platinum rule;KytyPS5's error codes aren't adopted, since no other public source confirms them. The return codes are unchanged.
Commits on #7262's head (each builds and passes the tests that exist at it):
feat(libSceNpTrophy2): record trophy unlocks per title and user: the unlock store, the reported unlocks, the listener hook with its dispatch lock, the queries' connection to the store and the platinum, andnp_trophy2_store.feat(libSceNpUniversalDataSystem): keep event properties and record posted trophy unlocks: events and properties with real contents, the_UnlockTrophypath, andnp_uds_events,guest_np_trophy_unlocksandguest_np_trophy_data's posted unlocks.docs: describe trophy unlocks in USAGE.feat(libSceNpUniversalDataSystem): unlock trophies through the title's statistics: the statistics rules, their store and the unlock check, withguest_np_trophy_stats.docs: describe trophy statistics in USAGE.test(libSceNpUniversalDataSystem): check that a stat with a sum aggregation unlocks nothing: it pins the behaviour, so it passes before the next commit.fix(libSceNpTrophy2): refuse a posted unlock of an unknown, platinum or progressive trophy: refused when the title's trophy data is loaded; the statistics path and the platinum award keep recording.docs: say which posted trophy unlocks are refused and what stops a title.docs: say that a malformed trophy or stat record line fails the query: the damaged-records debt entry above.Overlap (checked against
mainf1af6c5915and the 38 open PRs that touch the same files; the ones that merge intomainmerge with this PR too):src/Export.cppto libSceNpUniversalDataSystem'sCMakeLists.txt, and lines to its debt file. None of its stubs is a function this PR defines, so whichever lands second keeps both lists.mainthemselves weren't merged against this one. They share onlySceTypes.hpp(#7081, #6977, #6138),USAGE.md(#6946, #6788, #6171, #6111, #5925, #4891, #3998) or libSceNpTrophy2's test registration in itsCMakeLists.txt(#6044); #7201, #6947, #6447, #6248, #6222 and #5021 share none of this PR's files.Tested
Every test builds its own synthetic
.ucpfiles in a fresh directory; none uses a title's data. This PR's head is #7262's series split from the one reviewed there: withmain5361e69de3merged into that series, the trees are the same apart from commit 9's debt entry, so the red runs below, measured on it before the split, are the same code.np_trophy2_package(unit), on top of #7262's checks: progress, the platinum after the last trophy that names it and only once, counts and the percentage; the statistics rules kept and skipped, 7 bad input paths, each comparator below, at and above its target, and the statistics store across a restart with 8 damaged files.guest_np_trophy_data, through the built libraries' exports only, on top of #7262's checks: direct unlocks giving counts, the percentage and the platinum with the last trophy that names it, in listener order.guest_np_trophy_stats, through the exports only:ge9 locked, 10 unlocks;gt100 locked, 101 unlocks;le6 locked, 5 unlocks;ltwith −1 and a float ignored, 2 unlocks;player.stepsprogressive trophy at 4, then unlocked at 5, with the platinum after it;10 3\n20 101\n30 2\n40 5\nand the unlock file;uds03.ucp, each turning off only its own feature.np_uds_events,np_trophy2_storeandguest_np_trophy_unlockscover the posted-unlock path: every property setter, ownership, unlock recognition and near-miss names, persistence, damaged records (a carriage return included), and_UnlockTrophy {"_trophy_id":12}through the exports.guest_nptrophy2still passes unchanged.np_trophy2_store'stestListenerRemovalWaitsForItsCallback): removing a listener while its callback runs waits for the callback. Without the dispatch lock it fails 3 of 3 runs (a listener was removed while its callback was still running, so its context could be freed under it); with it, it passes 3 of 3.std::runtime_error. None reads out of bounds, leaks, or throws anything else: 48 malformed files and 2 valid packages, every truncation of both packages (1,190), 200,000 random byte mutations and 200,000 random JSON texts.np_trophy2_store'stestPostedUnlockRulesandguest_np_trophy_data, through the exports): with trophy data loaded, an unknown id, the platinum and a progressive trophy posted through UDS stay locked, record nothing, call no listener and log their line, and the counts don't move; the progressive trophy still unlocks through its statistic and the platinum with the last trophy that names it; without trophy data, any id is still recorded. Without the fix commit both fail:an unknown, platinum or progressive trophy posted through UDS was recordedanda progressive, platinum or unknown trophy posted through UDS unlocked, or changed the counts.guest_np_trophy_stats): asumstatistic logsstat 10 has aggregation "sum"; only "latest" is supported, stores nothing and unlocks nothing.gtread asge, no platinum, statistics not saved, truncation not checked, and progress ignoring the statistic each turnnp_trophy2_packagered, and four of themguest_np_trophy_statstoo.main5361e69de3with #7262: 1,411 tests, 1,338 passed, 68 skipped, 5 failed.mainon the same machine gives 1,405, 1,332, 68 and 5.guest_datagram_*andguest_tcp), which fail on that machine onmaintoo, andguest_sce_netskips there for the same reason.check_test_registration.pyandcheck_conventions.pypass.8e927be27f: 1,438 tests, 0 failed (run). The macOS and Ubuntu jobs pass too.APS5_TRACE_UDS=1, played by hand into Chapter 1. It ran on our test tree for the title (notmain; it carries the open fixes the title needs) with the whole trophy series before the split, at e06a4f2c7c, before the reviews' last fixes were folded in. Those fixes are off this path: the title registers no unlock listener (the dispatch lock), its trophy JSON is far below the value cap, and it has no statistics rule this PR reads (the statistics fix and the language message). The title unlocked "Sneaky Sisters" as shown under What. The log has no fatal error and no[trophy]or[uds]error or refused post.Not covered, and why:
latest: other aggregations (sum,count,max,collection,eachLatest), data types other thanuint32anduint64, and rule conditions beyond the event name. No public source gives their meaning, and KytyPS5 skips them too. Each such rule logs one line naming it, and a trophy that depends on one doesn't unlock. Planet of Lana (PPSA19450) has only such statistics, so this PR reads none of them ([trophy] /app0/sce_sys/uds/uds00.ucp: 0 stats, 0 rules for 0 events). That doesn't stop its trophies: each of its 24 stat-linked trophies is non-progressive and unlocks when the title posts_UnlockTrophywith its_trophy_id, which this PR records directly. Itscountstatistics count those same posts, and itscollectionandeachLateststatistics feed activities._UpdateTrophyProgress: logged once per trophy and not interpreted, because its properties aren't public.sceNpTrophy2RegisterUnlockCallback: the callback's signature isn't public.Checklist
main5361e69de3and #7262's head61e12c75fd(merged intomainas199e2ceb2f); no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T01:10:34Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/debt/libSceNpUniversalDataSystem.mdSome 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.
docs/user/USAGE.mddocs/user/USAGE.mddocs/user/USAGE.mddocs/user/USAGE.mdcore/libs/prx/libSceNpTrophy2/CMakeLists.txtdocs/user/USAGE.mdcore/libs/SceTypes.hppdocs/user/USAGE.mdcore/libs/prx/libSceNpUniversalDataSystem/CMakeLists.txtdocs/dev/debt/libSceNpUniversalDataSystem.mddocs/user/USAGE.mddocs/user/USAGE.mddocs/user/USAGE.mddocs/user/USAGE.mdcore/libs/SceTypes.hppdocs/user/USAGE.md