Repository navigation
Recover PSIN metadata across the whole archive, including stored blocks - #17
Conversation
Adds Rpf9PsinRecovery: a page scan that finds PSIN containers anywhere in an RPF9 file and joins their 64 KiB blocks, whether a block is zlib or stored as it is. A container is listed only when its sections, CHKS length and CHKS checksum match. PsinMetadata now verifies the checksum and accepts the PMAP section list next to the LSCH one. The full archive scan and index cache gain a PSIN stage. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
breadbbbb
left a comment
There was a problem hiding this comment.
Checked fe9159f. No blocking defect reproduced within the documented scope. The supplied smoke passed six compressed/stored framing layouts. An additional 15,002 checks over 1,154 retained PSIN containers verified historical source hashes, checksums, required lengths, altered-body rejection, prefix handling, and oversized-section controls. The new PMAP section-list branch was exercised synthetically; the retained ledger did not contain that variant. Core, App, and IndexBuilder Release builds passed without warnings or errors.
When combining this with #16, please preserve both cache kinds/result fields and both scan stages with correct progress totals. A merge-tree check found the expected conflicts in App/MainWindow.Indexing.cs, Core/PayloadIndexBuilder.cs, Core/RecoveryIndexCache.cs, README.md, and README.txt. Full archive-corpus counts were not reproduced because the original archives are unavailable.
breadbbbb
left a comment
There was a problem hiding this comment.
Approved at fe9159f. Leonida aa2988cc555b directly references this Core library. Its rpf9dump exporter and Rpf9DumpDiagnostics built with warnings treated as errors against this exact PR Core. The diagnostic suite and both exporter failure/retry tests passed. This verifies exporter compatibility; a complete game-engine or full-archive run was not performed.
The earlier retained-PSIN and generated framing checks also passed. Preserve the separate clip/PSIN cache and scan stages when rebasing alongside #16.
Why
PSIN metadata is only searched for in the first 16 MiB after the header, and only when every block of a container is zlib. Two things follow:
pack/story000/story000_script.rpfholds 2,309 PSIN containers, the first at0x3150000.mainlists none, and Scan entire archive does not look for PSIN at all.A third gap showed up while measuring:
anim.rpfhas two containers that use the section listPSIN, PMAP, PSCH, PSIG, STDN, STNS, CHKSinstead ofPSIN, LSCH, LENM, LSNS, LGID, LRSC, CHKS.Change
Core/Rpf9PsinRecovery.cs. A page scan over the whole file.PSIN. All 2,325 containers in the two archives below start on a page.Core/PsinMetadata.cs.InternalChecksumVerifiedis now computed. The checksum is Jenkins one-at-a-time over the whole container, seeded with0x3FAC7125, taking bytes as signed and reading the CHKS length and checksum fields as zero. It matches all 2,325 containers.PMAP…section list is accepted next to theLSCH…one, chosen by the second tag.RequiredLengthreturns the total length once the section headers are readable.PayloadIndexBuilder.Buildgains a PSIN stage andRecoveryIndexCacheapsinkind (stored segments allowed). On open, a container that is both in the first-16-MiB result and in the index is listed once, from the index.Rpf9ModelRecovery.Block,TryInflate,ZeroPaddingandZlibHeaderbecomeinternalso the new file reuses them.The existing first-16-MiB search in
Rpf9StructuredRecoveryis unchanged apart from accepting the second section list throughPsinMetadata.Inspect. It still does not require the checksum.Results
Measured on the 1.0.2.1 package, on the archives I have complete copies of.
e293917(open)pack/story000/story000_script.rpfanim.rpfcommon.rpf,appdata0.rpf,pack/story000_bvh4/story000_bvh4.rpf,pack/story000_restofworld/story000_restofworld.rpfstory000_script.rpfcontainers were first reassembled by a separate Python script written before this code. Reading each recovered entry back throughArchiveReader.OpenandReadPreviewgives the same bytes for all 2,309 (SHA-256).story000_script.rpf; the largest container, inanim.rpf, is 9.2 MB in 140 blocks, 88 of them stored.LSCH…; 2 inanim.rpfusePMAP….anim.rpfstill lists 1 PSIN entry,common.rpf259 XML documents andstory000_bvh4.rpf4.story000_script.rpf(78 MB): 0.7 s to scan, 1.1 s to recover.anim.rpf(4.4 GB): 45 s to scan.Not covered: a container whose stored last block would be 1 to 5 bytes long is skipped, because a segment under 6 bytes cannot be read back by
ZlibSegmentsStreamor stored in the index. None of the 2,325 is affected. I could not measure the larger archives (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 PSIN containers in code with a valid checksum and writes them to a test archive with each block either zlib or stored. It checks:RequiredLengthanswers for a complete container, a prefix and non-PSIN bytes;PMAP…section list is accepted;PMAP…container with a stored block;ArchiveReader.OpenandReadPreview;While writing it, the stored-last-block case failed: a stored block shorter than 64 KiB at the end of a file was skipped. That is fixed in this PR.
The fixture is generated in code and contains no game data.
Copy both files to
Tests/PsinRecoverySmoke/and rundotnet run --project Tests/PsinRecoverySmoke -c Release.Tests/PsinRecoverySmoke/PsinRecoverySmoke.csprojTests/PsinRecoverySmoke/Program.csOverlap with #16
#16 (clip dictionaries) and this PR are independent, but both add a kind to
RecoveryIndexCache, a stage toPayloadIndexBuilder.Buildand a field toPayloadIndexResult, and both make the same fourRpf9ModelRecoverymembersinternal. Whichever merges second needs a small rebase on those lines; I will do it.Testing 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 changed preview text in the running app window; the listing and read path behind it 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