_printable decides "text" from the first 512 bytes of a stream (more
than 90% printable). A carved file is classified from its whole data,
but scan_rpf passed only a 256-byte head for streams it does not keep
whole, so one stream could get two signatures: a stream whose first
306 bytes are printable read as "text" from the archive and as
"raw:..." from its carved file. af55ea1b4 removed the same split for
PSIN streams.
Keep a 512-byte head in the archive scan, the sample _printable takes.
The other head checks read at most 16 bytes, so nothing else changes.
Tested: new test_text_is_judged_on_the_same_512_bytes_as_a_carved_file
(fails before: 'text' from the archive, 'raw:6e616d65' from the data).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The independent rest-of-world scanner dropped textures below four pixels and misclassified dictionaries when their declared count included those descriptors.
Nine archive scanners sliced every gap out of the mmap to test whether it
was all zero (`gap = m[last:s]; gap.count(0) == len(gap)`). The slice is a
copy, so a gap of N bytes allocated N bytes at once; about half of
story000.rpf (~20 GB) is non-zlib, which ends in MemoryError on a 16 GB
machine.
tools/zero_span.py compares the gap with zeros 4 MiB at a time and stops at
the first non-zero window, with the same counts (all of a gap is padding
when every byte is zero, otherwise all of it is unread). rpf9_carve,
rpf9_names, bvh_index, navmesh_index, navmesh_decode, rbf0_index,
anim_index, restofworld_index and story_index use it.
tests/test_zero_span.py checks the counts against the old expression and
runs each scanner on a 48 MiB gap under tracemalloc: 50-51 MiB heap peak
on main, under 24 MiB with this change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The three tools share `_printable`, whose test was `9 <= b < 127 or b in (10, 13)`. The second half can never
add anything (10 and 13 are already in 9..126), and the first half counts the C0 control bytes 0x0B, 0x0C and
0x0E..0x1F as printable, so a binary stream made of them was classified "text" instead of `raw:<hex>`. The test
is now printable ASCII plus tab, LF and CR, as in `gamedata_index.printable`.
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016ABh36DZ2sZNq3ChN6EZJs
scan_dir passed each carved file's inflated length as its stored size, so in folder mode
compressed_bytes equalled inflated_bytes and readable_fraction was always 1.0, while the same numbers
in archive mode are the compressed sizes and stored / span. With rpf9_carve.py's index.json in the
folder, each file's stored size and the carve's span, zero padding and unread bytes now come from it;
without one, the length on disk is still used.
Real data (counts only), script.rpf: archive mode and its carve folder now give the same summary,
1,057 files, compressed 2,581,192, inflated 6,180,256, zero padding 1,335,290, unread 441,870,
readable 0.59224; main's folder mode gave compressed 6,180,256 and readable 1.0.
Tests: FolderModeStoredBytesTest (main: the index case reports 1,000 stored bytes instead of 300).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
csv.writer and csv.DictWriter default to lineterminator="\r\n", and every
one of these tools opens its report with newline="", which turns that into
CRLF on Windows and LF elsewhere: the same archive gave different report
bytes depending on the machine that exported it. awc_manifest and awc_shorts
already pin "\n" and bink_index documents why its stdout writer needs it, so
this brings the remaining 16 writers onto the same convention. A structural
test keeps new writers on it, and three tools are run end to end to check the
bytes.
Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.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>
scan_rpf passed classify only the first 256 inflated bytes, so a PSIN whose
section chain runs past them lost its tags and complete flag, while scan_dir
read the same resource whole. The PSIN stream is kept (already capped by
max_inflate) and classified like a carved file.
rpf9_carve.py, anim_index.py, rbf0_index.py, restofworld_index.py and bvh_index.py inflated up to
the end of the archive even with --limit, so a stream that started inside the window and ended
after it was counted at its full stored size as readable while the gap before it counted as
unread: readable + zero + unread exceeded the span. On a 1.0.2.1 copy's common.rpf with
--limit 0x2000 all five reported 114.2% (one stream for 2,568 bytes that end past the window).
They now inflate only inside the window, as story_index (#712) and navmesh_index (#766) do: a
stream that doesn't end inside it is left out, and a Bink video must fit in it. Without --limit
the window is the whole archive, so nothing changes: common.rpf still gives 954 streams and 100%
in all five. bvh_index passed the window's end already but its read slices ignored it; they are
now cut at that end too.
Tests: test_rpf9_carve's LimitWindowTest and the new test_limit_window.py (anim/rbf0/restofworld/
bvh_index) put the limit inside the first of two incompressible streams; all five fail on main
and pass now (108 tests across the touched files).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 518343b7850361a5d8046bd456e80e261a9f1e1d)
Follow-up to #498 and #530 (claimed in #374):
- Reject --start and --limit when source is a directory (exit code 2 via ap.error).
- Pass --max-inflate to scan_dir() and skip .bin files larger than max_inflate, incrementing skipped_candidates.
- Wrap mmap.mmap() in scan_rpf() with a context manager so out-of-range start errors always close the mapping.
- Add unit tests covering all three fixes.
Same two problems as rbf0_index.py: a missing source ended in a traceback from
os.path.getsize, and an unwritable --out was found only after the full scan.
The source error is now "<source>: No such file or directory" (exit 1) and the
output path is checked first (exit 2).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Adds the #283 argparse validators to anim_index, rbf0_index, restofworld_index and rpf9_carve: --start >= 0, --limit >= 1 (decimal or 0x hex), and --max-inflate >= 1 in restofworld_index. Bad ranges now exit 2 before any scan or output instead of silently scanning everything, less, or nothing. Synthetic CLI tests in all four test files; docs notes for each tool.
New item claimed in #156. AI-assisted (OpenCode).
BUILD-30: anim_index, rbf0_index and restofworld_index now reject an
empty archive with a named error instead of mmap's traceback.
rpf9_carve rejects an empty or shorter-than-header archive and a
--start at or past the file size before it divides by the span.
audio_config exits with a named error when the input has no records
instead of formatting None as a hex id.
The new synthetic test covers every case; the existing tests for the
five tools still pass.
Add the full core_restofworld scan (1.21 GiB, 96% Bink 2 plus model/page data), re-measure story000_restofworld and story000_script, and cover the three small archives. Cross-check PSIN against script.rpf/story000 and core pages/models against packs.rpf/levels.rpf. Add a stdlib-only stream index tool and synthetic-header tests. No game data.