Repository navigation
Recover clip dictionaries and list animation clip names - #16
Conversation
Adds Rpf9ClipRecovery: finds clip dictionary resources (zlib blocks at page + 16, continued while a block is a multiple of 64 KiB), reads the dictionary name, clip names and animation count, and lists them as recovered entries with an Animations filter and a names-only preview. The full archive scan and index cache gain a clips stage, and IndexBuilder gets a clips command that exports the names as TSV. Animation tracks are not decoded. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
breadbbbb
left a comment
There was a problem hiding this comment.
Checked a0671c4. The supplied recovery smoke passes, and 22 retained native dictionaries matched a separate Python map/string traversal for 34 clip names. Two generated malformed-input cases still expose validation problems: cumulative name allocation and duplicate map entries. Please address the inline findings before merging. A bounded-name-budget and global visited-entry guard retained the saved native results in local checks.
The feature scope is clear: dictionary and clip-name metadata is recovered; animation tracks and playback are not decoded.
| if (entry < 0 || clips.Count == count) return null; | ||
| long clip = Pointer(U64(system, (int)entry + 8), system.Length - 0x38); | ||
| if (clip < 0) return null; | ||
| string? clipName = Text(system, (int)clip + 0x28); |
There was a problem hiding this comment.
[P2] Bound cumulative decoded clip-name allocation
The input-size and entry-count caps do not bound the total strings allocated here. A 43,265-byte generated dictionary with 128 distinct map entries whose name fields reference one 32,768-byte ASCII string is accepted and allocates 8,392,832 bytes. At the allowed 65,536 entries, the same construction scales to roughly 4 GiB of strings from about 5 MiB of system data; that extreme was not allocated during review. Archive opening calls this recovery automatically, so a crafted file can exhaust application memory. Bound cumulative decoded-name characters or use a bounded lazy representation before accepting each name.
| for (ulong link = U64(system, (int)buckets + b * 8); link != 0;) | ||
| { | ||
| long entry = Pointer(link, system.Length - 24); | ||
| if (entry < 0 || clips.Count == count) return null; |
There was a problem hiding this comment.
[P2] Reject map entries visited from multiple buckets
The count guard bounds traversal but does not establish that each map entry is distinct. With count=2 and two bucket heads pointing to the same zero-terminated entry, Decode returns a dictionary containing that entry twice, because the duplicated visits happen to equal the declared count. Track visited entry addresses across all buckets and reject repeated pointers so malformed/shared chains are not reported as a validated dictionary.
breadbbbb
left a comment
There was a problem hiding this comment.
Requesting changes for the verified issues in the earlier review.
Bound cumulative decoded clip-name allocation and reject repeated map-entry addresses across buckets. Both malformed-input cases are reproduced in the previous inline review.
|
Merged with maintainer fixes in bd54fb0: decoded names have a total budget and map-entry addresses are tracked across buckets, rejecting shared/cyclic nodes. The PSIN merge conflicts were resolved while preserving the existing five-argument PayloadIndexResult constructor and reporting both PSIN and clip counts. 277 focused checks and 22 saved clip dictionaries pass. A combined PSIN/clip fixture verifies exact readback, unique entry indexes and monotonic progress. App, IndexBuilder and Leonida checks also pass. |
Why
Animation archives are full of clip dictionaries, and
mainlists none of them: openinganim.rpfshows no recovered entries. A clip dictionary is stored the same way as the resources the model scan already handles (zlib blocks at page + 16), so its names can be read without decoding the archive directory.Change
Core/Rpf9ClipRecovery.cs. Finds clip dictionaries, joins their blocks and reads the dictionary name, the clip names and the animation count.+0x38; clip hash map at+0x48, with the bucket count at+0x50and the entry count at+0x58; animation count at+0x90.+0x28.recovered/clips/<name>_at_<offset>.r9clipdatawith compressionRecovered clip dictionary. The app gets an Animations filter (type:animation,type:animations,type:clips) and a Details view with the names.PayloadIndexBuilder.Buildgains a fifth stage andRecoveryIndexCacheaclipskind, so Scan entire archive finds them. On open, only the first 16 MiB is searched, like the other kinds.IndexBuilder clips <source> <output.tsv>writes one line per dictionary: offset, name, animation count, clip names.Rpf9ModelRecovery.Block,TryInflate,ZeroPaddingandZlibHeaderbecomeinternalso the new file reuses them instead of carrying a third copy.Animation tracks are not decoded. This PR reads names only.
Results
Measured on the 1.0.2.1 package, on the archives I have complete copies of.
anim.rpfpack/story000_restofworld/story000_restofworld.rpfcommon.rpf,appdata0.rpf,pack/story000/story000_script.rpf,pack/story000_bvh4/story000_bvh4.rpfanim.rpfcandidates that are not recovered are not clip dictionaries. They are motion sets. They share the container header, but their map records use a different layout:+0x20is a pointer instead of the value 2, and the name string is at+0x30(16,543 records, all ending in.motion) or at+0x38(180 records, all ending in.motionmatcher). Walking them with that layout accounts for all 7,878, and none of them has a clip-style record. This PR does not list them; they are rejected by the name check rather than listed under a guessed name.pack:/and end with.clip. All 52,952 dictionary names are distinct and use onlya-z,0-9,_,-and@.ArchiveReader.Openlists 52,918 entries foranim.rpfin 2.6 s. Every 25th entry (2,116) was read back throughReadPreviewand decoded again: 0 failures. One entry (20.6 MiB) is over the 16 MiB preview limit and shows as hex only.anim.rpf(4.4 GB): 47 s to find candidates, 134 s to recover them.I could not measure the larger archives the other PRs use (
levels.rpf,packs.rpf,data.rpf): my copies are incomplete.Tests
mainignoresTests/, so, as in #8 to #11, the fixture is below rather than in the PR. It builds a clip dictionary in code with three clips: two chained in one bucket and one with a name short enough to be stored inline. It checks:ArchiveReader.OpenandReadPreview.The fixture is generated in code and contains no game data.
Copy both files to
Tests/ClipDictionarySmoke/and rundotnet run --project Tests/ClipDictionarySmoke -c Release.Tests/ClipDictionarySmoke/ClipDictionarySmoke.csprojTests/ClipDictionarySmoke/Program.csTesting environment
Tested on Windows 10 x64 with .NET SDK 10.0.101.
Core,AppandTools/IndexBuilderbuild in Release with 0 warnings and 0 errors, on top ofe293917. I did not exercise the new filter and Details view in the running app window; the listing, search kind and read path behind them were checked throughCoreas described above.AI-assisted: an AI agent (Claude, Anthropic) did the investigation, code, tests and measurements on the author's behalf, and a second agent pass reviewed the diff independently. No game data is included here.
🤖 Generated with Claude Code