Recover RPF9 models with packed vertices and mixed blocks #1

Manually merged
github merged 1 commit from gh-pr/1/head into gh-pr/1/base 2026-11-26 19:04:06 +00:00
Owner

@⁠Mulkku on GitHub · 2026-11-21 15:48 UTC · original
Mulkku:model-layout-recovery → main · +321 −56 · 8 files · 1 commits · merged 2026-11-21 23:20 UTC

Why

The previous local model scan accepted 190,623 of 190,792 candidates. The remaining 169 came from levels.rpf (167) and story000.rpf (2). They exposed cases in resource assembly, mesh metadata, and packed vertex bounds.

Changes

  1. Resource extents and mesh counts. Walk all four drawable LOD slots when measuring the system and graphics ranges. Use the existing 1,024-mesh limit per LOD for matching per-part counts. Include optional texture extents when measurable and validate the geometry when auxiliary data extends past the walked ranges.
  2. Cluster index buffers and bone palettes. Accept descriptor marker 0x00 for the observed 0xC000 header flags (16-bit references with a bone palette). Allow palettes that reference an external skeleton and data after the index tables. Keep all cluster count, table length, triangle reference, and local bone range checks where those ranges are available.
  3. Packed position bounds. Accept about 0.01 model units of deviation for the packed position format. Also accept a conservative mesh box when it agrees with the decoded quantizer domain and contains the vertices. Float positions retain their existing tolerance.
  4. Mixed zlib and raw blocks. Recover the observed 16-byte system remainder and 48-byte graphics remainder after full 64 KiB pages. Require complete metadata and a valid following zlib block for the system remainder. Require the exact missing extent and successful mesh decoding for the graphics remainder. Read existing v1 caches and write v2 when a model index contains raw blocks.

Verification

AI-assisted implementation. Verification ran on Windows 11 x64 and exercised CPU-side archive and geometry decoding.

  • 190,792 / 190,792 recognized candidates decoded across the ten RPF9 archives configured in Leonida's model scan.
  • 169 / 169 previously rejected candidates decoded and decoded again after readback through ArchiveReader.ReadResourceData. This included 33 entries with raw segments.
  • An asset-free fixture passed candidate discovery, mixed-block recovery, packed-triangle decoding, v1/v2 cache round-trip, and byte-exact readback. It also verified rejection of an invalid raw segment length and an out-of-range vertex reference.
  • Release builds passed for the Windows viewer (.NET 10), IndexBuilder, and Leonida's rpf9dump against the patched Core (.NET 8 targets).

Run the redistributable smoke fixture with dotnet run --project Tests/ModelRecoverySmoke -c Release. To rebuild a model index from a local archive, use Scan entire archive or run dotnet run --project Tools/IndexBuilder -c Release -- models <archive.rpf> <report-directory>.

The counts cover recognized drawable and fragment candidates in the tested archives. The viewer continues to preview the primary LOD, and the original RPF9 directory and skeleton animation are outside this patch.

**@⁠Mulkku** on GitHub · 2026-11-21 15:48 UTC · [original](https://github.com/breadbbbb/rpf9-explorer/pull/1) `Mulkku:model-layout-recovery` → `main` · +321 −56 · 8 files · 1 commits · merged 2026-11-21 23:20 UTC ## Why The previous local model scan accepted 190,623 of 190,792 candidates. The remaining 169 came from `levels.rpf` (167) and `story000.rpf` (2). They exposed cases in resource assembly, mesh metadata, and packed vertex bounds. ## Changes 1. **Resource extents and mesh counts.** Walk all four drawable LOD slots when measuring the system and graphics ranges. Use the existing 1,024-mesh limit per LOD for matching per-part counts. Include optional texture extents when measurable and validate the geometry when auxiliary data extends past the walked ranges. 2. **Cluster index buffers and bone palettes.** Accept descriptor marker `0x00` for the observed `0xC000` header flags (16-bit references with a bone palette). Allow palettes that reference an external skeleton and data after the index tables. Keep all cluster count, table length, triangle reference, and local bone range checks where those ranges are available. 3. **Packed position bounds.** Accept about 0.01 model units of deviation for the packed position format. Also accept a conservative mesh box when it agrees with the decoded quantizer domain and contains the vertices. Float positions retain their existing tolerance. 4. **Mixed zlib and raw blocks.** Recover the observed 16-byte system remainder and 48-byte graphics remainder after full 64 KiB pages. Require complete metadata and a valid following zlib block for the system remainder. Require the exact missing extent and successful mesh decoding for the graphics remainder. Read existing v1 caches and write v2 when a model index contains raw blocks. ## Verification AI-assisted implementation. Verification ran on Windows 11 x64 and exercised CPU-side archive and geometry decoding. - **190,792 / 190,792** recognized candidates decoded across the ten RPF9 archives configured in Leonida's model scan. - **169 / 169** previously rejected candidates decoded and decoded again after readback through `ArchiveReader.ReadResourceData`. This included **33** entries with raw segments. - An asset-free fixture passed candidate discovery, mixed-block recovery, packed-triangle decoding, v1/v2 cache round-trip, and byte-exact readback. It also verified rejection of an invalid raw segment length and an out-of-range vertex reference. - Release builds passed for the Windows viewer (.NET 10), IndexBuilder, and Leonida's `rpf9dump` against the patched Core (.NET 8 targets). Run the redistributable smoke fixture with `dotnet run --project Tests/ModelRecoverySmoke -c Release`. To rebuild a model index from a local archive, use **Scan entire archive** or run `dotnet run --project Tools/IndexBuilder -c Release -- models <archive.rpf> <report-directory>`. The counts cover recognized drawable and fragment candidates in the tested archives. The viewer continues to preview the primary LOD, and the original RPF9 directory and skeleton animation are outside this patch.
Walk all drawable LOD references when determining resource extents. Handle
alternate bone palette markers and packed position domains while keeping
mesh table, reference, and vertex checks.

Recover raw metadata and graphics tails after zlib blocks. Exercise
candidate recovery, mixed readback, and legacy cache compatibility with
a synthetic packed drawable.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 19:04:05 +00:00
github manually merged commit c3708fb032 into gh-pr/1/base 2026-11-26 19:04:06 +00:00
Author
Owner

@⁠Kam471 on GitHub · 2026-11-21 18:23 UTC · original

Independent validation at c3708fb on the Xbox Series GTA VI package 1.0.2.1 (.NET 8.0.428), using the PR Core through a copy of Leonida's tools/rpf9dump and a direct FindCandidateOffsets/RecoverAtOffsets harness.

  • data.rpf full (481,544,304 bytes): 2,313 / 2,313 candidates recovered, 0 rejects; 2,313 / 2,313 read back and decoded. This includes all 963 candidates the 48557ea decoder rejected. All 1,350 pre-PR OBJ files are byte-identical, and the export has 2,313 unique stems with no collisions.
  • common.rpf full: 0 / 0 candidates, 0 models.
  • levels.rpf 0-8 GiB: 28,748 / 28,748 (pre-PR 26,184).
  • levels.rpf 4-4.5 GiB: 4,010 / 4,010 (pre-PR 3,821).
  • levels.rpf 12-16 GiB: 10,429 / 10,429 (not previously measured).
  • All sampled levels.rpf entries read back and decoded, including the 2 entries with raw segments (both 48-byte graphics tails).
  • v1/v2 cache round-trip checked: real v1 caches load; a 28,748-entry index with one raw segment saves as schema 2 and preserves the raw flag, and the same entries save/reload as schema 1 when flattened.

The PR's own Tests/ModelRecoverySmoke passes.

Scope caveat: I did not scan full levels.rpf or the other seven archives, so I did not independently reproduce the ten-archive 190,792 / 190,792 total or the 169 / 169 subset. No counterexample appeared in the tested scopes. The 16-byte raw system tail was exercised only by the smoke fixture; the real samples above contained 48-byte raw graphics tails only. No game data is included in this comment.

**@⁠Kam471** on GitHub · 2026-11-21 18:23 UTC · [original](https://github.com/breadbbbb/rpf9-explorer/pull/1#issuecomment-7067215511) Independent validation at `c3708fb` on the Xbox Series GTA VI package `1.0.2.1` (`.NET 8.0.428`), using the PR Core through a copy of Leonida's `tools/rpf9dump` and a direct `FindCandidateOffsets`/`RecoverAtOffsets` harness. - `data.rpf` full (481,544,304 bytes): **2,313 / 2,313** candidates recovered, 0 rejects; **2,313 / 2,313** read back and decoded. This includes all **963** candidates the `48557ea` decoder rejected. All 1,350 pre-PR OBJ files are byte-identical, and the export has 2,313 unique stems with no collisions. - `common.rpf` full: **0 / 0** candidates, 0 models. - `levels.rpf` 0-8 GiB: **28,748 / 28,748** (pre-PR 26,184). - `levels.rpf` 4-4.5 GiB: **4,010 / 4,010** (pre-PR 3,821). - `levels.rpf` 12-16 GiB: **10,429 / 10,429** (not previously measured). - All sampled `levels.rpf` entries read back and decoded, including the 2 entries with raw segments (both 48-byte graphics tails). - v1/v2 cache round-trip checked: real v1 caches load; a 28,748-entry index with one raw segment saves as schema 2 and preserves the raw flag, and the same entries save/reload as schema 1 when flattened. The PR's own `Tests/ModelRecoverySmoke` passes. Scope caveat: I did not scan full `levels.rpf` or the other seven archives, so I did not independently reproduce the ten-archive **190,792 / 190,792** total or the **169 / 169** subset. No counterexample appeared in the tested scopes. The 16-byte raw system tail was exercised only by the smoke fixture; the real samples above contained 48-byte raw graphics tails only. No game data is included in this comment.
Author
Owner

@⁠Spaghetih on GitHub · 2026-11-21 22:42 UTC · original

Full-archive validation at c3708fb on the Xbox Series package 1.0.2.1. It completes @⁠Kam471's scoped run above: full levels.rpf plus the other archives Leonida exports models from.

Method. A small harness against Core follows the same path as Leonida's tools/rpf9dump models: FindCandidateOffsets, then RecoverAtOffsets in chunks of 32, RecoveryIndexCache.Save, ArchiveReader.Open, ReadResourceData (readback) and RageModelDecoder.Decode. No OBJ is written. Each archive was run at both 48557ea and c3708fb. As a control, the 48557ea totals reproduce Leonida's documented figures exactly (155,598 models, with the same per-archive counts).

Archive Candidates 48557ea c3708fb
levels.rpf (full, 70.9 GiB) 183,801 149,811 183,801
pack/story000/story000.rpf 3,305 3,303 3,305
data.rpf 2,313 1,350 2,313
pack/shared_minigame000/shared_minigame000.rpf 971 783 971
packs.rpf 314 314 314
pack/core_restofworld/core_restofworld.rpf 88 37 88
common, textures, story000_restofworld, core_restofworld001 0 0 0
Total 190,792 155,598 190,792

At c3708fb, every candidate is recovered, read back and decoded: 0 decode failures, 0 readback failures, and no duplicate model names (190,792 unique). That is 2.22 billion triangles, against 1.95 billion before. This independently reproduces the PR's 190,792 / 190,792 ten-archive total.

Not covered. The OBJ text itself (export and file comparison) was not checked in this run; @⁠Kam471's byte-identical check on data.rpf still stands for that. The 169-candidate subset is a different scope and was not isolated. No game data is included here: only counts.

AI-assisted (Claude Code).

**@⁠Spaghetih** on GitHub · 2026-11-21 22:42 UTC · [original](https://github.com/breadbbbb/rpf9-explorer/pull/1#issuecomment-7070365746) Full-archive validation at `c3708fb` on the Xbox Series package `1.0.2.1`. It completes @⁠Kam471's scoped run above: full `levels.rpf` plus the other archives Leonida exports models from. **Method.** A small harness against Core follows the same path as Leonida's `tools/rpf9dump models`: `FindCandidateOffsets`, then `RecoverAtOffsets` in chunks of 32, `RecoveryIndexCache.Save`, `ArchiveReader.Open`, `ReadResourceData` (readback) and `RageModelDecoder.Decode`. No OBJ is written. Each archive was run at both `48557ea` and `c3708fb`. As a control, the `48557ea` totals reproduce Leonida's documented figures exactly (155,598 models, with the same per-archive counts). | Archive | Candidates | `48557ea` | `c3708fb` | |---|---:|---:|---:| | `levels.rpf` (full, 70.9 GiB) | 183,801 | 149,811 | **183,801** | | `pack/story000/story000.rpf` | 3,305 | 3,303 | **3,305** | | `data.rpf` | 2,313 | 1,350 | **2,313** | | `pack/shared_minigame000/shared_minigame000.rpf` | 971 | 783 | **971** | | `packs.rpf` | 314 | 314 | 314 | | `pack/core_restofworld/core_restofworld.rpf` | 88 | 37 | **88** | | `common`, `textures`, `story000_restofworld`, `core_restofworld001` | 0 | 0 | 0 | | **Total** | **190,792** | **155,598** | **190,792** | At `c3708fb`, every candidate is recovered, read back and decoded: 0 decode failures, 0 readback failures, and no duplicate model names (190,792 unique). That is 2.22 billion triangles, against 1.95 billion before. This independently reproduces the PR's **190,792 / 190,792** ten-archive total. **Not covered.** The OBJ text itself (export and file comparison) was not checked in this run; @⁠Kam471's byte-identical check on `data.rpf` still stands for that. The 169-candidate subset is a different scope and was not isolated. No game data is included here: only counts. AI-assisted (Claude Code).
Author
Owner

@⁠Kam471 on GitHub · 2026-11-21 23:11 UTC · original

Recorded the full-archive validation (190,792 / 190,792 at c3708fb, 2.22 billion triangles) in Leonida's docs via ItsNotRexed/Leonida#347.

**@⁠Kam471** on GitHub · 2026-11-21 23:11 UTC · [original](https://github.com/breadbbbb/rpf9-explorer/pull/1#issuecomment-7070702667) Recorded the full-archive validation (190,792 / 190,792 at c3708fb, 2.22 billion triangles) in Leonida's docs via ItsNotRexed/Leonida#347.
This discussion has been locked. Commenting is limited to contributors.
No description provided.