ASSET-316: TtpfReader accepts external BCPack BC1-BC5 history tables #22

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

@⁠throny on GitHub · 2026-11-22 23:08 UTC · original
asset-316-bcpack-history-tables → main · +271 −21 · 3 files · 1 commits · merged 2026-11-23 01:25 UTC

What was missing

Leonida's tools/bcpack_history_calib.py writes local BCPack initial-history tables (bc1.json..bc7.json), and Leonida's pure-Python decoder reads them with --history <path>. TtpfReader could only use the built-in BC1/BC3/BC4/BC5 tables, so the C# path could not use calibrated tables (Leonida docs/textures.md, "Next step" 2; item ASSET-316).

What changed

  • Core/BcpackHistory.cs (new): BcpackHistory.Load(path) reads a folder of bcN.json files or one JSON file with "bcN" sections. It follows the Python loader (tools/bcpack_tables_bptc.py load_bc_history, tools/bcpack.py _resolve_bc_history):
    • Lookup: bcN.json in a folder, or a "bcN" key or "codec": "bcN" in a file. A codec without a section keeps the built-in table.
    • Schema: confirmed / provisional tables as a 256-element list or an index-keyed object, holding endpoint tuples of 6 (BC1), 8 (BC3), 2 (BC4) or 4 (BC5) integers. Values are converted like Python's int().
    • Merge: the external entries are laid over the built-in tables. An external confirmed entry wins over everything; an external provisional entry never replaces a confirmed one. With replace set, the external entries stand alone.
    • Malformed tables throw InvalidDataException with the Python messages; a missing path throws FileNotFoundException.
    • bc6h.json / bc7.json are ignored until the BC6H/BC7 rebuilders exist.
  • BcpackDecoder.Decode / DecodeWithInfo: new overloads take a BcpackHistory?.
  • TtpfReader.CreateDds / DecodeTexturePixels / DecodeTexturePreview: new overloads take a BcpackHistory? next to allowProvisional, and it is passed down through ReadMip and DecodeChunk.
  • The existing overloads pass null and use the built-in tables, so nothing changes for callers that don't pass a history.

Tests

  • This repository has no test project, so the tests are in Leonida's tests/Rpf9DumpDiagnostics (the C# test project its CI runs), in the companion PR.
  • Synthetic decode cases (18): each decodes a one-block BCPack chunk from Leonida's tests/test_bcpack.py encoder against a synthetic history JSON. Every expected result is what tools/bcpack.py returns for the same chunk and table (bytes, provisional labels, or the refusal message). They cover:
    • built-in tables with no history (strict and provisional)
    • an external confirmed entry, and an external provisional entry over a built-in provisional one
    • an external provisional entry that must not replace a built-in confirmed one
    • replace, the 256-list form, and a combined file
    • a file without a codec marker, a folder without bc1.json, and Python-style int() values
    • BC4 unknown and provisional entries
  • Malformed tables (9): each must be refused with the Python message.
  • Other checks: a missing path, a folder holding only bc7.json (loads no table), and a null history decoding byte for byte like the built-in tables.
  • Local parity on my own copy of the game (not committed; counts only): I made bc1–bc5 tables with bcpack_history_calib.py --limit 20 (provisional entries only) and picked 34 BCPack textures from the 46 pools (2,618 candidates scanned; 2 of them change with these tables). Each texture was exported with Leonida's tools/ttpf_mips.py export --allow-provisional, with and without --history, and with TtpfReader.CreateDds(..., allowProvisional: true, history).
    • Decoded payload identical in 68 / 68 comparisons, 0 differing, including both textures the tables change.
    • 64 files are byte-identical. In the other 4 (single-mip textures) one DDS header flag differs: TtpfReader always sets DDSD_MIPMAPCOUNT, the Python exporter only when there is more than one mip. That difference is the same without the tables.
  • Release builds: Core (through Leonida's tools/rpf9dump and tests/Rpf9DumpDiagnostics) with TreatWarningsAsErrors=true: 0 warnings, 0 errors. App and Tools/IndexBuilder were not built.

Not done here

  • BC6H/BC7 tables are not used yet; that needs the BC6H/BC7 rebuilders (Leonida ASSET-315).
  • The Python decoder reads a codec's table the first time it decodes that codec. Load reads all four tables at once, so a malformed table is reported before any decode.

AI-assisted (Claude Code). No GPU needed (CPU-only decoding). Windows 11, .NET 8 target.

Companion Leonida PR: ItsNotRexed/Leonida#4050 (bumps the submodule, adds rpf9dump ttpf --history, tests and docs).

🤖 Generated with Claude Code

**@⁠throny** on GitHub · 2026-11-22 23:08 UTC · [original](https://github.com/breadbbbb/rpf9-explorer/pull/22) `asset-316-bcpack-history-tables` → `main` · +271 −21 · 3 files · 1 commits · merged 2026-11-23 01:25 UTC ## What was missing Leonida's `tools/bcpack_history_calib.py` writes local BCPack initial-history tables (`bc1.json`..`bc7.json`), and Leonida's pure-Python decoder reads them with `--history <path>`. `TtpfReader` could only use the built-in BC1/BC3/BC4/BC5 tables, so the C# path could not use calibrated tables (Leonida `docs/textures.md`, "Next step" 2; item ASSET-316). ## What changed - **`Core/BcpackHistory.cs` (new):** `BcpackHistory.Load(path)` reads a folder of `bcN.json` files or one JSON file with `"bcN"` sections. It follows the Python loader (`tools/bcpack_tables_bptc.py` `load_bc_history`, `tools/bcpack.py` `_resolve_bc_history`): - Lookup: `bcN.json` in a folder, or a `"bcN"` key or `"codec": "bcN"` in a file. A codec without a section keeps the built-in table. - Schema: `confirmed` / `provisional` tables as a 256-element list or an index-keyed object, holding endpoint tuples of 6 (BC1), 8 (BC3), 2 (BC4) or 4 (BC5) integers. Values are converted like Python's `int()`. - Merge: the external entries are laid over the built-in tables. An external confirmed entry wins over everything; an external provisional entry never replaces a confirmed one. With `replace` set, the external entries stand alone. - Malformed tables throw `InvalidDataException` with the Python messages; a missing path throws `FileNotFoundException`. - `bc6h.json` / `bc7.json` are ignored until the BC6H/BC7 rebuilders exist. - **`BcpackDecoder.Decode` / `DecodeWithInfo`:** new overloads take a `BcpackHistory?`. - **`TtpfReader.CreateDds` / `DecodeTexturePixels` / `DecodeTexturePreview`:** new overloads take a `BcpackHistory?` next to `allowProvisional`, and it is passed down through `ReadMip` and `DecodeChunk`. - The existing overloads pass `null` and use the built-in tables, so nothing changes for callers that don't pass a history. ## Tests - This repository has no test project, so the tests are in Leonida's `tests/Rpf9DumpDiagnostics` (the C# test project its CI runs), in the companion PR. - **Synthetic decode cases (18):** each decodes a one-block BCPack chunk from Leonida's `tests/test_bcpack.py` encoder against a synthetic history JSON. Every expected result is what `tools/bcpack.py` returns for the same chunk and table (bytes, provisional labels, or the refusal message). They cover: - built-in tables with no history (strict and provisional) - an external confirmed entry, and an external provisional entry over a built-in provisional one - an external provisional entry that must not replace a built-in confirmed one - `replace`, the 256-list form, and a combined file - a file without a codec marker, a folder without `bc1.json`, and Python-style `int()` values - BC4 unknown and provisional entries - **Malformed tables (9):** each must be refused with the Python message. - **Other checks:** a missing path, a folder holding only `bc7.json` (loads no table), and a null history decoding byte for byte like the built-in tables. - **Local parity on my own copy of the game (not committed; counts only):** I made bc1–bc5 tables with `bcpack_history_calib.py --limit 20` (provisional entries only) and picked 34 BCPack textures from the 46 pools (2,618 candidates scanned; 2 of them change with these tables). Each texture was exported with Leonida's `tools/ttpf_mips.py export --allow-provisional`, with and without `--history`, and with `TtpfReader.CreateDds(..., allowProvisional: true, history)`. - Decoded payload identical in **68 / 68** comparisons, **0** differing, including both textures the tables change. - 64 files are byte-identical. In the other 4 (single-mip textures) one DDS header flag differs: `TtpfReader` always sets `DDSD_MIPMAPCOUNT`, the Python exporter only when there is more than one mip. That difference is the same without the tables. - Release builds: `Core` (through Leonida's `tools/rpf9dump` and `tests/Rpf9DumpDiagnostics`) with `TreatWarningsAsErrors=true`: 0 warnings, 0 errors. `App` and `Tools/IndexBuilder` were not built. ## Not done here - BC6H/BC7 tables are not used yet; that needs the BC6H/BC7 rebuilders (Leonida ASSET-315). - The Python decoder reads a codec's table the first time it decodes that codec. `Load` reads all four tables at once, so a malformed table is reported before any decode. AI-assisted (Claude Code). No GPU needed (CPU-only decoding). Windows 11, .NET 8 target. Companion Leonida PR: ItsNotRexed/Leonida#4050 (bumps the submodule, adds `rpf9dump ttpf --history`, tests and docs). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
BcpackHistory.Load reads the bc1.json..bc5.json initial-history tables that
Leonida's tools/bcpack_history_calib.py writes (a folder of bcN.json files or
one JSON file with bcN sections), with the schema, lookup, merge/replace rules
and error messages of Leonida's pure-Python decoder. BcpackDecoder.Decode /
DecodeWithInfo and TtpfReader.CreateDds / DecodeTexturePixels /
DecodeTexturePreview take it next to allowProvisional; the existing overloads
keep the built-in tables, so nothing changes without it. bc6h.json and
bc7.json are ignored until the BC6H/BC7 rebuilders exist.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 19:05:41 +00:00
github manually merged commit d1fd04056f into gh-pr/22/base 2026-11-26 19:05:42 +00:00
Author
Owner

@⁠breadbbbb on GitHub · 2026-11-23 01:24 UTC · original · approved these changes

Reviewed d1fd04056f. The BC1/BC3/BC4/BC5 loader, precedence rules and optional API routing passed 4,196 independent assertions over generated streams and TTPF pools, plus 41 companion-exporter CLI checks. Supplied diagnostics and existing positional-default cancellation-token callers also passed. The combined Core, desktop app, IndexBuilder and pinned Leonida exporter build with zero warnings or errors.

This approval covers the documented BC1/BC3/BC4/BC5 scope. The desktop still uses built-in tables, and BC6H/BC7 histories remain unsupported. No retail calibrated-history corpus was available to reproduce the author's native parity run. PR #23 remains separate.

**@⁠breadbbbb** on GitHub · 2026-11-23 01:24 UTC · [original](https://github.com/breadbbbb/rpf9-explorer/pull/22#pullrequestreview-6015610924) · **approved these changes** Reviewed d1fd04056fa7ba594cc362a55d5d22f5a73e6ef7. The BC1/BC3/BC4/BC5 loader, precedence rules and optional API routing passed 4,196 independent assertions over generated streams and TTPF pools, plus 41 companion-exporter CLI checks. Supplied diagnostics and existing positional-default cancellation-token callers also passed. The combined Core, desktop app, IndexBuilder and pinned Leonida exporter build with zero warnings or errors. This approval covers the documented BC1/BC3/BC4/BC5 scope. The desktop still uses built-in tables, and BC6H/BC7 histories remain unsupported. No retail calibrated-history corpus was available to reproduce the author's native parity run. PR #23 remains separate.
This discussion has been locked. Commenting is limited to contributors.
No description provided.