Add `tools/bcpack_history_calib.py` to derive external `--history <path>` JSON
tables (`bc1.json`..`bc7.json` or combined JSON) locally from a player's own
texture pools or exact reference block/DDS pairs using only the Python
standard library (`python -I`):
- Exact reference inversion (`--ref-dds POOL:INDEX=REF.dds`, `--ref-pairs`):
algebraically inverts direct built-in history references (`d > i` in blocks
0..255) across BC1/BC3/BC4/BC5/BC6H/BC7 into confirmed strict-mode entries.
- Read-only TTPF pool self-calibration (`inputs ...`): uses a prefix rANS lane
decoder (`decode_lanes_prefix`) together with exact BC6H/BC7 anchor MSB and
BC7 Mode-1 shared p-bit parity constraints, intra-block index smoothness
voting, and sibling raw/zlib mip endpoint fitting to derive provisional
tables usable with `--history <path> --allow-provisional`.
- Extend `tools/bcpack_tables_bptc.py`, `tools/bcpack.py`, and
`tools/ttpf_mips.py` so `--history` also accepts optional BC1-BC5 JSON
tables (`confirmed`, `provisional`, optional `replace`) alongside BC6H/BC7.
- Add synthetic unit tests in `tests/test_bcpack_history_calib.py` and document
the schemas and CLI workflow in `docs/textures.md`.
open(path, "w") without newline= turns each \n into \r\n on Windows, so the same JSON report, manifest or assembly
listing was CRLF there and LF elsewhere. 91 text-mode writes (open, os.fdopen, Path.write_text) under tools/, scripts/,
make_game.py and runtime/test/shaders/ now pass newline="\n". tests/test_text_write_line_endings.py reads the source
with ast and fails for a writer that forgets it; CONTRIBUTING.md names the convention.
AI-assisted (Claude), on behalf of dev-ewann.
A folder name with glob characters, like "Game [v1]", was used as a glob pattern, so no pool
matched and the new "no .ttpf pool in it" error would name a folder that does hold pools. The
folder is now passed through glob.escape; only the parts below it are patterns.
Test: test_scan_finds_pools_below_any_folder_and_rejects_paths_without_one now builds its game
folder as "game [v1]" (without the escape: 0 pools).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`scan` only looked for pools under <path>/data/ttdb and <path>/pack/*/data/ttdb, so pointing it at
data/ttdb itself, one of its folders or pack/ found nothing, and a mistyped path did the same: it
printed an all-zero summary and exited 0. A folder that holds no pool at those game-root places is
now searched recursively for .ttpf, and a path that still yields no pool is an ERROR line naming
it (no such file or folder / no .ttpf pool in it) with exit code 2.
Real data (counts only), pools found on my 1.0.2.1 copy, main -> this change: game root 57 -> 57
(same list), pack/story000 3 -> 3 (same list), data/ttdb 0 -> 46, data/ttdb/peds 0 -> 9,
pack 0 -> 11; a mistyped dat/ttdb now exits 2 instead of 0.
Tests: test_scan_finds_pools_below_any_folder_and_rejects_paths_without_one (main: 0 pools for
data/ttdb).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On Windows a redirected stdout uses the console's ANSI code page, and python -I ignores PYTHONUTF8 and
PYTHONIOENCODING, so a caller path with a character outside that code page ended a run with
UnicodeEncodeError as soon as a tool printed it. #1406 fixed make_game.py; every CLI tool in tools/ now starts
its __main__ block the same way (stdout errors="replace").
tests/test_tool_stdout_encoding.py checks every tool's __main__ block and reruns two measured crashes
(analyze_4240_full.py, meshlet_page.py) with a private-use-named input. Found by @abilliontokens.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ttpf_mips scan wrote --json after reading every pool, without checking
the path: a pool given as --json (directly or found under a game folder)
was replaced by the report, and a directory or a missing folder ended in
a traceback before the report was printed. Now a --json that is a
directory or one of the pools is refused before the scan, the report is
printed first, its folder is created, and a write that still fails is
one "cannot write" line (exit 2).
rbf0_tree wrote out and --csv after the decode: either naming the source
file replaced it (write_json's atomic os.replace included), and out and
--csv on the same file kept only the CSV. Both are refused up front.
Same checks as navmesh_decode/bvh_index (same_report_path /
same_output_path). Synthetic pools and RBF0 blobs only, no game files.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A truncated or unsupported .ttpf raised ValueError from Pool() after the
file was opened and mapped, without closing either, so the pool stayed
locked on Windows. Nothing caught it: one bad pool stopped `scan` with a
traceback and no report, and layout/check/export ended the same way, as
did an index past the pool (IndexError).
Pool() now closes what it opened when a check fails, and every command
prints one line that names the pool (or the valid index range) and exits
with 2. Tests build the pools by hand.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>