Commit Graph

14 Commits

Author SHA1 Message Date
c70e673e12 rbf0_encode: fail report export when resources are refused (#6560)
Squash-merged after diff review of PR #6560
2026-11-23 12:44:31 -06:00
cb168f4647 rbf0_tree: identify source files in the flat node CSV (#6886)
Squash-merged after diff review of PR #6886 - rbf0_tree: identify source files in the flat node CSV
2026-11-23 09:44:43 -06:00
a2f8aae55c rbf0_encode: --check fails on a refused resource; refuse attribute records the count does not cover (BUILD-1084)
Four findings by @HQasper on tools/rbf0_encode.py:

- `--check` exited 0 when resources were refused, so a round trip that verified nothing read as success.
  It now exits 0 only when every resource is byte-identical, as rbf0_tree.py does for a resource that is
  not ok.
- The element header count came from `attrs_declared` while every node of `attributes` was written, so an
  attribute appended by hand encoded as the element's first content value: a different tree with status
  ok. encode() now refuses more attribute records than the count (value), and an element short of its
  count that has a value in its content, which would decode as an attribute (order). A parsed element
  short of its count with no such value still round-trips exactly.
- `blob[:doc["size"]]` in resources() could not trim anything. The slice is gone and check() compares
  the joined length with the recorded size; two carved streams of one name are refused instead of the
  last one silently winning.
- docs/rbf0.md 9.6 lists the `value` refusals and says what `--check` exits with.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-22 18:46:57 -03:00
5d4285f383 rbf0_encode: write an rbf0_tree document back to bytes, with a round-trip check
docs/rbf0.md called the tree output "a rendering, not a round-trip" and
nothing wrote RBF0. encode(doc) rebuilds the record stream from the tree
rbf0_tree.parse_resource returns, in both layouts: descriptor names at
first use, element words 0, 0, attribute count, attributes then content
in tree order, text and strings with their recorded NUL.

It fails closed, with a reason, when the tree cannot hold the original:
an incomplete parse, invalid UTF-8 the decoder replaced, a NaN float
(infinities are exact), an attribute after content, a descriptor out of
order, or a string or text whose byte length changed.

--check decodes, encodes and compares every resource of a carve and
prints counts only. A report-and-directory form writes the resources of
an rbf0_tree.py JSON report (possibly edited) as .rbf files.

Measured on the 1,263 data.rpf resources: 1,240 byte-identical, 0
different, 23 refused, all for invalid UTF-8. They are the resources
holding the 26 invalid payloads docs/rbf0.md already lists. Counts are
in docs/rbf0.md 9.6.

tests/test_rbf0_encode.py: synthetic streams only. Every record type in
both widths, infinities, narrow float bits, the largest integers, the
JSON report form, an edited tree, each refusal reason, and the CLI with
a resource split over two 64 KiB streams.
2026-11-22 12:30:26 -03:00
60c624ec9b tools/imhex: ImHex patterns for the RPF9 header and RBF0 records
rpf9.hexpat names the measured header fields (magic, data offset at +4;
the u32s at +8 and +12 unnamed) and shows the rest of the header and the
TOC as one opaque range; it decodes nothing there. rbf0.hexpat follows
the grammar in docs/rbf0.md section 3: 1-byte descriptor index and type,
all record types including 0x50, 8- or 4-byte values from the prologue,
and it stops where the root closes, as rbf0_index.parse_rbf0 does.

tests/test_imhex_patterns.py builds synthetic wide and narrow RBF0
streams and RPF9 headers, checks them with parse_rbf0, and when ImHex
is installed runs each pattern through `imhex --pl format -f json` and
compares the result with the parser's.
2026-11-22 11:07:12 -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
019f0fc241 Docs: update the full tree JSON size 2026-11-21 21:38:51 +00:00
2992956624 rbf0_tree: record child counts, add CSV rows and tree-shape summary
Each element now carries attrs_actual, children and content_count. The JSON summary reports the measured depth and child-count histograms, leaf/empty/text-only counts and parent-child edges. --csv writes one flat row per node with parent, slot and sibling columns. Tests cover sibling order, malformed close tags against the flat parser, tree-shape summary and CSV output. The docs replace the game-name sample trees with aggregate tree shape and a synthetic example.
2026-11-21 21:30:42 +00:00
57544ab7a9 Docs: note the full tree JSON size 2026-11-21 21:23:50 +00:00
084cf31b82 rbf0_tree: record the XML error status 2026-11-21 21:23:50 +00:00
37ab207e58 Docs: correct the UIScreen sample nesting 2026-11-21 21:23:50 +00:00
d50ba56650 Tools: decode RBF0 trees for UI and subtitles
Add a stdlib record/tree decoder for the measured RBF0 format. It joins 64 KiB continuations, parses the inline descriptor table, builds element/attribute/content/text trees, and writes JSON plus optional generic XML. Unknown descriptors, record types and malformed framing fail closed with a partial tree. Add synthetic tests and the measured grammar, samples and remaining unknowns to docs/rbf0.md; note the rig-set blob tree result in docs/animation.md.
2026-11-21 21:01:14 +00:00
241b03c9bf docs: note that all multi-chunk RBF0 resources are wide
The three narrow resources are single-stream; also drop a no-op line from the attribute test.
2026-11-21 19:10:11 +00: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