Repository navigation
feat(libSceNpTrophy2,libSceNpUniversalDataSystem): record trophy unlocks and statistics - #7335
Merged
oneandonlydean merged 13 commits intoOct 18, 2026
Merged
Conversation
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.
Unlocks are kept in _trophy/<user id>_<service label>.txt in the title's run directory, one "<trophy id> <RTC tick>" line per trophy, and each new unlock logs "[trophy] <title id> unlocked trophy <id> for user <id>". GetTrophyInfo, GetTrophyInfoArray, GetGroupInfo, GetGroupInfoArray and GetGameInfo report the recorded unlocks, their times, the unlocked counts by grade and the progress percentage. An unlock also unlocks the platinum the trophy names once every trophy naming that platinum is unlocked. Unlock listeners let a later notification subscribe. Removing a listener waits for its running callback, and a listener removed during a dispatch is not called by it.
…osted trophy unlocks Events and property objects keep their typed properties instead of dropping them. PostEvent records an _UnlockTrophy event with an int32 _trophy_id for the user and service label of its context, logs why a trophy event is ignored, and prints every posted event with APS5_TRACE_UDS.
…s statistics Events other than the trophy events go through the title's sce_sys/uds/udsNN.ucp: stats_definition.json gives the statistics that keep their latest uint32 or uint64 value, and stats_extraction.json the event property ($.name, dotted for nested objects) that sets each one. Statistics are kept per user and service label in _trophy/<user id>_<service label>.stats.txt next to the unlocks. After each event that sets a statistic, every trophy's unlockCondition (ge, gt, le or lt against its targetValue) is checked on the values that event set and the stored values of the other statistics, so a later event setting the same statistic cannot hide what this one reached. Reached trophies unlock through the same path as _UnlockTrophy. Progressive trophies report their statistic as progress, and APS5_TRACE_UDS prints each statistic an event sets. A missing udsNN.ucp is ignored and a malformed one is logged once.
…gation unlocks nothing A title whose uds file defines a stat with an aggregation other than latest gets one log line naming the stat. Posting an event for it through the exports stores no stat and unlocks no trophy.
…or progressive trophy With the title's trophy data loaded, an _UnlockTrophy posted through UDS no longer records an id the data does not have, the platinum, or a progressive trophy. Each refusal logs the trophy and the reason, returns false and calls no listener. The statistics path and the platinum award now use an internal record that keeps part 1's behaviour, so a progressive trophy still unlocks through its statistic and the platinum with the last trophy that names it. Without trophy data every id of 0 or more is recorded as before.
USAGE.md describes the refused posted unlocks and their log line, and says that the icon queries and a damaged or unwritable unlock or statistics file stop the game with an error. The debt entries of libSceNpTrophy2 and libSceNpUniversalDataSystem no longer say that any posted id is stored. Both USAGE.md and the libSceNpTrophy2 entry say that without trophy data the platinum is not unlocked when the other trophies are.
11 tasks done
|
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.
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.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 61e12c7, so with #7262 merged its diff shows only its own commits. The title's own
sce_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
mainf1af6c5 and 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(fix(libs): share Sony CRT handler and lconv state between libc and libSceAmpr #7081, feat: run PS4 games on the AGC driver — Limbo (CUSA01664) in game (integration branch) #6977, fix(libSceNetCtl): keep the callback argument and deliver the state from sceNetCtlCheckCallback #6138),USAGE.md(perf(agc): draw finisher pipeline (APS5_DRAW_PIPELINE) #6946, feat(agc): select Vulkan devices by driver name #6788, fix(tools): recognize guest module identities in import audit #6171, fix(relinker): report processor 0 from RDTSCP under --to-rosetta #6111, perf(agc): build the pipelines of a submission ahead on a compile pool #5925, feat(agc,videoout): save the displayed frame as a PNG with a screenshot key #4891, feat(pad): queue timed controller button sequences #3998) or libSceNpTrophy2's test registration in itsCMakeLists.txt(test: organize library tests and label CTest suites #6044); Macos port #7201, perf(agc): GPU descriptor heap (APS5_GPU_HEAP) #6947, fix: complete compatibility gaps #6447, feat(libSceSystemService): LoadExec on macOS hosts #6248, Macos m4 #6222 and feat(aot): consolidate native ARM64 compiler, runtime and consumers #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: withmain5361e69 merged 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 feat(libSceNpTrophy2): report the title's trophy data from trophyNN.ucp #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 feat(libSceNpTrophy2): report the title's trophy data from trophyNN.ucp #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.main5361e69 with feat(libSceNpTrophy2): report the title's trophy data from trophyNN.ucp #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.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 e06a4f2, 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
main5361e69 and feat(libSceNpTrophy2): report the title's trophy data from trophyNN.ucp #7262's head 61e12c7 (merged intomainas 199e2ce); 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)