Commit Graph

43 Commits

Author SHA1 Message Date
5accec0b72 bvh_index: ask report_paths for the report-path guard
The private same_output_path becomes an alias of report_paths.same_report_path,
and the import keeps same_report_path on its own line: tests/test_report_paths.py
looks for that exact line when the tool is added to SHARED.
2026-12-01 19:44:40 -05:00
070f9521bd bvh_index: require 208-byte head and mark truncated heads (BUILD-1533) 2026-11-25 13:56:02 +05:00
e6686e012c bvh_index: refuse only a report inside the folder the check cannot list
Any other unlistable folder is left to the scan, which names it and exits 1
with an incomplete report, so a second run is no longer refused just because
the first one wrote the report.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 15:35:54 -03:00
721341dc53 Merge main into fix/walk-bvh_index
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 15:35:34 -03:00
7f2f626ed0 bvh_index: name an unreadable target once, not through the OSError text (EGEN-BVHINDEX-MISSING-NAME) (#6699)
Squash-merged after diff review of PR #6699 - bvh_index: name an unreadable target once, not through the OSError text (EGEN-BVHINDEX-MISSING-NAME)
2026-11-23 10:03:59 -06:00
c8f2639171 bvh_index: a sub-folder the report check cannot list is an error, not a silent skip (BUILD-1374)
When --out or --csv names an existing file and the target is a folder,
main() walks the folder to make sure the report would not overwrite an
input. That os.walk had no onerror, so a sub-folder it could not list
was skipped and the check passed without having looked inside it: a
report file in that folder could be overwritten.

This is a safety check, so a folder it cannot list is an error: the
walk's onerror calls ap.error, which names the flag and the folder and
exits 2 before anything is written, like the other "would overwrite"
refusals. The scan itself (scan_dir, glob on main) is left to #4431,
which turns it into an os.walk whose unlistable folders are logged and
make the run exit 1 as incomplete.

The test forces os.scandir to raise PermissionError for one sub-folder
(chmod cannot lock a folder on Windows) and checks the exit code, the
folder in the message and that the existing report is untouched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 01:33:00 -03:00
923c3a8714 Merge pull request #4556 from sh1shu1
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:15:53 -05:00
4c4cb16bbf Merge pull request #4516 from bobcatchris
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:15:28 -05:00
4b865804d6 bvh_index: check the report paths before the scan and turn write errors into exit 2 (BUILD-454)
The overwrite refusals (source archive, carve manifest, input files, a folder as destination, --out equal to --csv)
were already in place. What remained of BUILD-454: a report path under a file or in a folder that can't be written
ended the run in a NotADirectoryError or PermissionError traceback, after the whole scan. report_path_problem()
now creates and probes each report's folder before scanning and argparse refuses the path with the reason; an
OSError while writing after the scan (a full disk, a folder removed since) is one stderr line and exit 2, and the
atomic publish still leaves no partial file. Two tests: a destination under a file is refused before scan_dir is
called; a write failure after the scan returns 2 with the message and no report. Both fail on main.

AI-assisted (Claude Code, Claude Fable 5.1).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GDgoLQVYG7p8mvxkwBroVz
2026-11-23 03:00:52 +01:00
d79bf5c500 Fix read-only temp cleanup in staged report writers
bvh_index, navmesh_index and rbf0_tree give the staging file the destination mode before os.replace. On Windows a read-only destination makes the replace fail and leaves a temp that cannot be unlinked. Restore 0600 in the failure path before unlink, and add regressions that pin the mode reset, old bytes and no leftovers.
2026-11-22 20:00:30 -06:00
59c3a1fc69 fix: bvh_index finds archives with os.walk so an unlistable sub-folder makes the run exit 1 (review) 2026-11-23 02:50:30 +01:00
b65bf4a03c bvh_index: a folder scan that skipped an archive exits 1, not 0 2026-11-23 02:24:42 +01:00
9b7f4f2829 Merge pull request #3181 from Leo Leahy 2026-11-22 15:15:29 -05:00
1ad7921fa6 Merge pull request #2989 from UNYTIX 2026-11-22 15:13:51 -05:00
73bd50e269 Merge pull request #2726 from Rafael 2026-11-22 15:11:30 -05:00
44daebd5fd bvh_index: parse XML root past encoding headers 2026-11-22 17:06:21 -03:00
2c45b7a33e tools: use native Windows process handles for scanner priority 2026-11-22 20:20:40 +01:00
50d5736032 Merge pull request #2684 from tikD1337 2026-11-22 13:17:04 -05:00
87f3b53036 Merge pull request #2468 from bbareth 2026-11-22 13:15:31 -05: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
a04ae223aa fix(bvh_index, navmesh_index): stage report writes so failed runs keep existing reports
write_outputs opened the JSON and CSV reports with open(dest, "w"), which empties
the previous report before the new one is serialized: a TypeError in json.dump, a
full disk or Ctrl+C left a truncated file where an intact report used to be.

Each report is now written to a NamedTemporaryFile in the destination folder
(.bvh_index-*.tmp / .navmesh_index-*.tmp), given published_mode(dest) and swapped
in with os.replace. On any exception the staging file is removed and the
existing report is left untouched.

Tests: PublishTest in tests/test_bvh_index.py and tests/test_navmesh_index.py
(JSON serialization failure, CSV write failure, KeyboardInterrupt, published_mode
applied to the staged file, POSIX bits kept). All synthetic, no game data.

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 18:50:54 +01:00
1badfebfd0 navmesh_index and bvh_index: scan literal carve directories 2026-11-22 18:08:48 +01:00
d9bdad3786 fix(tools): omit fill counts for incomplete carved BVH nodes
Archive scans only report fill for complete node buffers. Carved chunks exposed header metadata but recorded partial fill counts, so the same data produced different measurements.
2026-11-22 17:43:46 +01:00
99f8c77bcf Merge pull request #2011 from JavierBlanco23 2026-11-22 10:40:24 -05:00
8987f3bd4d bvh_index.py: flatten per-archive summaries in scan_dir() 2026-11-22 16:29:59 +01: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
12d4bcbea7 tools: report paths that differ only in case are one file on macOS
bvh_index, anim_index, gamedata_xml, gamedata_index and navmesh_decode compare
two report paths with os.path.normcase, which folds case only on Windows. On
macOS's case-insensitive APFS volume `--out o/B.json --csv o/b.json` passed and
the CSV replaced the JSON. The comparison now folds case and Unicode
normalization when the volume that will hold the path is case-insensitive
(pathconf _PC_CASE_SENSITIVE); case-sensitive volumes keep two reports.
Same fix as world_index in #1576.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 15:30:32 +03:00
89cf18645e Merge pull request #1428 from Dominik 2026-11-22 06:38:01 -05: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
736f9d6ebd bink_index, bvh_index: report paths cannot replace carve inputs
With a carve directory as the target, --out (and bvh_index's --csv) could
replace <dir>/index.json (or a carved payload through a hard link) and
exit 0; #1264 only compared the report with the target path itself, which
covers an .rpf target but not a directory. bvh_index also lost the report
to a FileNotFoundError in a missing folder, and ended in a PermissionError
traceback when the report path was an existing directory.

Refuse report paths that resolve to the carve manifest or an input file,
create the report folder before writing, and reject a directory report
path; tests cover each shape on synthetic fixtures.
2026-11-22 19:12:17 +08:00
22e17b94d3 Index tools: refuse to overwrite the source file 2026-11-22 03:24:01 -06:00
193add486e bvh_index: reject colliding report destinations 2026-11-22 04:28:04 -03:00
58a5a900fd Merge pull request #998 from bbareth 2026-11-22 01:08:15 -05:00
799069f9d1 bvh_index.py: a fill histogram only when every node byte was inflated
scan_rpf() built the fill histogram when the declared node bytes fit in the
stream's full size, but it only has the bytes it kept under --max-inflate. A
capped stream gave {'total': 0}, which looks like a BVH with no filled nodes.
The histogram now needs the declared bytes to be in what was kept; a capped
stream has no fill key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 06:35:29 +01:00
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
c73379d0fc Merge pull request #498 from Tomgamer 2026-11-21 19:43:47 -05:00
ce37e3c9b5 bvh/page/story_index: pass --max-inflate to directory scans, reject --start/--limit for a directory
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 01:08:28 +01:00
7b6139cdff Report invalid BVH roots and clarify index output 2026-11-21 23:46:04 +00:00
2a122c7cbc Cite BVH4 header source and report version field 2026-11-21 23:21:07 +00:00
eb629d41a8 Decode BVH4 header and node pointer fields
The indexer treated the pre-header wrapper words as the root and labelled the real header fields as counts. Parse the documented XboxBvh4Header fields, decode root node pointers, and document the runtime node and leaf layouts while keeping the dehydrated packed stream open.
2026-11-21 22:55:52 +00:00
76b7b5b329 Index tools: refuse --limit/--start values that scan nothing, survive empty archives
bvh_index, page_index, story_index, navmesh_index and psin_index:

- --limit 0 meant "no limit" (0 is falsy) and a negative --limit scanned
  nothing and still exited 0 with an empty index. --limit must now be at
  least 1 and --start 0 or more; argparse rejects anything else (rc 2).
- An empty .rpf crashed in mmap ("cannot mmap an empty file") and a file
  shorter than the header word crashed in struct.unpack_from. bvh, page and
  story now treat both as an archive with no streams.
- bvh_index directory mode: one bad archive no longer aborts the scan and
  loses the results of the others; it is reported and skipped.
- A --start past the end of the archive is a one-line error (rc 2) instead
  of a traceback (bvh also checked nothing and reported a negative span).
- page_index checks the output extension before the scan, not after it.

Docs: the accepted ranges and the empty-archive behaviour are written next
to each tool's usage in docs/{bvh,navmesh,page_directory,psin,story}.md.

Tests: synthetic cases for each tool; they fail on main and pass here.
2026-11-21 23:21:29 +01:00
1681676f5a Docs: measured BVH archive composition
Index the three *_bvh4 RPF9 packs with the fixed carver and record the measured stream/byte composition. Add tools/bvh_index.py for the 0x81020006 header family (tag + 0x140 + 64*n == end), with synthetic tests. No game data, keys or carved payloads are included.
2026-11-21 19:19:53 +00:00