Commit Graph

28 Commits

Author SHA1 Message Date
66e2262b2b Merge pull request #2388 from syfyra/fix/restofworld-index-text-sample
restofworld_index: judge text on the same 512 bytes in an archive (RESTOFWORLD-INDEX-TEXT-SAMPLE)
2026-12-01 16:22:12 +01:00
16dde22775 restofworld_index: judge text on the same 512 bytes in an archive (RESTOFWORLD-INDEX-TEXT-SAMPLE)
_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>
2026-11-26 17:55:47 +01:00
1ca8b83b4a restofworld_index: validate scan bounds, fix carve index .bk2/BOM, harden I/O 2026-11-25 04:46:44 +01:00
8731cfed53 restofworld_index: stage JSON and CSV reports so failure keeps old file 2026-11-24 00:12:24 +03:00
a4c23feb47 Report restofworld_index write failures without a traceback 2026-11-22 23:36:25 +01:00
9fc3b2931f Merge pull request #2958 from Vonsek 2026-11-22 15:13:34 -05:00
73bd50e269 Merge pull request #2726 from Rafael 2026-11-22 15:11:30 -05:00
f847748cc7 Merge origin/main (7 pull requests merged on GitHub)
# Conflicts:
#	docs/design.md
#	tools/psin_data.py
2026-11-22 14:46:26 -05:00
24c30012cf fix(assets): count small textures in resource dictionaries
The independent rest-of-world scanner dropped textures below four pixels and misclassified dictionaries when their declared count included those descriptors.
2026-11-22 19:55:33 +01:00
8686aaf028 Merge pull request #2459 from bbareth 2026-11-22 13:15:28 -05:00
817b2ad784 Merge pull request #2363 from AAyberkU 2026-11-22 13:14:14 -05:00
a5a490efab restofworld_index: identify embedded 0x980 textures and companion TTPF pools (ASSET-148) 2026-11-22 19:12:22 +01:00
f206d479a6 tools: classify the gap between streams without copying it
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>
2026-11-22 15:07:15 -03:00
8b02dc9ae9 restofworld_index: protect directory-mode carve inputs 2026-11-22 18:06:54 +01:00
8e0f861199 story_index, anim_index, restofworld_index: control bytes are not text
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
2026-11-22 19:43:51 +03:00
74de9c73dc restofworld_index: folder mode takes stored sizes and span from the carve's index.json
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>
2026-11-22 13:20:50 -03:00
ec9b6cf22b tools: text reports are written with LF line ends on every platform (BUILD-468)
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.
2026-11-22 14:20:30 +00:00
c334c78477 tools: CSV reports end their lines with LF on Windows too
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>
2026-11-22 07:13:06 -06:00
f698bf2206 tools: a path outside the console's code page no longer crashes a tool's output
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>
2026-11-22 11:27:00 +00:00
0f5aafea60 Merge commit 'd3841c0c0ee41ec014699a985846c6dc76026440' into codex/restofworld-preserve-source 2026-11-22 04:53:44 -03:00
9e50ef29af restofworld_index: prevent overwriting the source archive 2026-11-22 04:40:19 -03:00
af55ea1b44 restofworld_index: an archive scan classifies a PSIN from its whole stream, not 256 bytes
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.
2026-11-22 12:08:47 +05:30
63f23a0da8 rpf9_carve and four indexers: under --limit, leave out a stream that runs past the window
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)
2026-11-22 00:33:53 -05:00
16b4d32e9c restofworld_index.py: validate directory options, enforce --max-inflate in scan_dir, and close mmap with context manager
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.
2026-11-22 00:44:10 +00:00
1e7b22f445 restofworld_index.py: report a missing source, and check the output path before scanning
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>
2026-11-22 02:47:04 +03:00
fe8cd6bc72 Tools: reject out-of-range --start/--limit in RPF index tools
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).
2026-11-21 16:53:41 -06:00
6516dfea46 fix(tools): report clear errors for empty, short and out-of-range input
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.
2026-11-21 23:31:48 +01:00
d3f69013c1 Docs: measure rest-of-world and script archive composition
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.
2026-11-21 20:30:47 +00:00