Commit Graph

31 Commits

Author SHA1 Message Date
6769d87fc0 rbf0_index: ask report_paths for the report-path guard 2026-12-01 19:44:41 -05:00
0f67037d05 rbf0_index: restore write mode before unlink on replace failure and publish mode on Windows (RBF0-INDEX-STAGE-CLEANUP)
agent: yes
AI-assisted: yes
2026-11-24 16:51:11 +03:00
fdcf6351e1 rbf0_index: stage JSON report write via temp file and replace_retry 2026-11-23 21:49:41 +02:00
efb6595024 Merge pull request #3393 from Leo Leahy
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:07:26 -05:00
d6f1df1511 Merge pull request #3202 from Marco Luzzaro
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:07:00 -05:00
76eaa4f0ce rbf0_index: drop unreachable content_started guard on value count and update stack comment 2026-11-22 22:22:24 -03:00
070a187866 Merge commit 'aa2988cc555bad7ecd508b48a702adbb32fe7c95' into fix/rbf0-protect-carve-input
# Conflicts:
#	tools/rbf0_index.py
2026-11-23 00:21:03 +01:00
6c377077a9 Merge pull request #3393 from Leo Leahy 2026-11-22 17:01:50 -05:00
9a2317be66 rbf0_index: record attribute mismatch at content transition so truncated inputs keep it 2026-11-22 17:49:32 -03:00
939554670c rbf0_index: count attribute mismatches once per element and stop consuming attributes after content 2026-11-22 17:24:48 -03:00
88e3e48ef7 Merge pull request #3017 from IAmNotSiob 2026-11-22 15:14:05 -05:00
73bd50e269 Merge pull request #2726 from Rafael 2026-11-22 15:11:30 -05:00
5b421a4ad0 Protect RBF0 carve inputs from report overwrites 2026-11-22 20:40:21 +01:00
24a3c441ba tools: drop never-called analyze_4240_full.walk_stream and rbf0_index._categorise 2026-11-22 20:07:17 +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
da37a4dbde rbf0_index: avoid offset collisions in scan_dir and stop joining on trailing status
In tools/rbf0_index.py, scan_dir() mapped rows by offset in a dict and assigned non-hex names offset=len(entries), so colliding offsets silently dropped/duplicated resources or crashed with RbfError when a colliding file was non-RBF0. Also join_resource() only stopped on complete or bad, swallowing subsequent chunks after status==trailing. Place unnamed files past max hex offset, look up row bytes by row identity, stop joining when status != truncated (matching rbf0_tree), and add synthetic regression tests.
2026-11-22 17:15:44 +00: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
22e17b94d3 Index tools: refuse to overwrite the source file 2026-11-22 03:24:01 -06:00
034677275a Merge pull request #1165 from Tayar 2026-11-22 03:14:19 -05:00
53061577b2 rbf0_index: reject archive range flags for directory scans 2026-11-22 04:50:02 -03:00
3a92d04133 rbf0_index: a short continuation stream ends the resource
join_resource only checked that the first stream was 64 KiB; after a short
continuation it kept appending the next stream, which docs/rbf0.md rules
out, so an unrelated stream was glued on and the row disagreed with
rbf0_tree.decode_source on the same bytes.
2026-11-22 13:10:20 +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
f2a6304080 story/anim/rbf0_index: skip the carver's index.json and .csv reports in a carve folder
In directory mode the three tools read every regular file, so rpf9_carve.py's index.json (and any
.csv report next to the streams) was counted as a payload, with a made-up offset (its position in
the listing). On a 1.0.2.1 copy's script.rpf carve (1,057 streams) each reported 1,058 files, and
the inflated total was off by exactly the index's size; on the data.rpf carve rbf0_index reported
28,510 streams for 28,509.

page_index.py and navmesh_decode.py already skip .json and .csv; the three tools now do the same.
story_index keeps skipping its own report as well (#712).

Tests: each tool gets a carve folder with three streams plus an index.json and a report.csv, and
must list only the three streams. All three fail on the old code (offsets 3 and 4, or 4 streams
for 2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 7372a903afdb4b6f1a9aa7df7e60283848965dc5)
2026-11-22 00:33:52 -05:00
b101b57187 rbf0_index.py: a negative --strings is an error, not a slice from the end
--strings was used as a slice bound, so --strings -1 dropped the last string
of every resource's sample (and -N the last N) and still exited 0. A negative
count is now an argparse-style error (exit 2) before any index is written.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 06:29:21 +01:00
092b028bcd Tools: close archive mmaps on error and reject empty rpf9_names inputs 2026-11-21 22:12:32 -03:00
86d82da20b rbf0_index.py: report a missing source, and check the output path before scanning
A missing source file ended in a FileNotFoundError traceback from os.path.getsize.
It now exits 1 with "<source>: No such file or directory", like the existing
"empty file" message. An --out in a folder that doesn't exist, or one that is a
folder, used to fail only after the whole archive had been scanned; both are now
usage errors (exit 2) before the scan starts.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-22 02:47:03 +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
9bc8453baa docs: measured RBF0 composition in data.rpf, with rbf0_index
1,263 RBF0 resources parse to their exact last byte under the measured record grammar: 1,243 single-stream and 20 multi-chunk, 1,260 with the FB FF 01 00 prologue and 64-bit scalars, 3 without it and 32-bit scalars. No section directory or name-hash table exists. The anim.rpf rig-set blob is the same format with a different root schema.

tools/rbf0_index.py indexes an RPF9 data area or a carved directory and writes CSV/JSON; tests/test_rbf0_index.py builds synthetic headers only. No game data is added.
2026-11-21 19:08:57 +00:00