Skip to content

tools: read story content-definition XML (ASSET-149) - #2268

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
kacper-serewis:asset149-content-definitions
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
kacper-serewis:asset149-content-definitions

Conversation

@kacper-serewis

Copy link
Copy Markdown
Contributor

Claimed as ASSET-149: #2078 (comment)

What and why

The story/rest-of-world archives contain readable content change sets, content definitions and setup XML, but the existing index only classifies those payloads. tools/content_definitions.py now reads the three measured roots into ordered immutable records and exposes file entries, included change sets/sets, and setup groups. Unknown fields, attributes, text and tails are preserved; symbolic references and values are not resolved or coerced.

The CLI accepts local XML files or existing carve directories and prints aggregate counts only. Missing blocks and malformed/ambiguous input fail explicitly; DTDs are refused. Documentation explains the API, parser limits, existing grouping limitations and the remaining runtime/resource-mapping work. This is independent of ASSET-139 and PR #1995; neither patch is included.

Tested

Windows 11 Pro 10.0.26200, Python 3.13.15. CPU-only change: no GPU required or exercised (host GPU: RTX 5070, driver 32.0.16.1656).

  • python -I tests/test_content_definitions.py: 11 passed.
  • Existing test_gamedata_index.py (19), test_gamedata_xml.py (6), test_restofworld_index.py (23), test_docs_links.py (5), and test_text_write_line_endings.py (2): all passed.
  • python -m compileall -q make_game.py tools tests and git diff --check: passed.
  • Complete local scans of core_restofworld, story000_restofworld, core_restofworld001, and core_licenses_data: all 30 recovered content XML documents accepted (22 change sets, 4 content definitions, 4 setup documents), 65 file entries, 22 included change-set references, 8 setup groups. Zero record differences against an independent ElementTree parse of each reassembled payload (tags, attributes, text, tails, child order). No claim about the separate 20 GB story000.rpf or runtime interpretation.

Checklist

  • No game data, keys or decryption, including in reports quoted here. Fixtures are self-authored; local validation shares aggregate counts only.
  • AI-assisted implementation and validation (Codex).
  • Translator contract update: not applicable; no translator changes.

Preserve ordered records and expose file/include/setup views, with synthetic tests and counts from four complete archives. No game data included. AI-assisted.
@leoleahy

Copy link
Copy Markdown
Contributor

Independent review & local CPU verification (AI-assisted) on Windows 11 x64 / Python 3.14.8 against commit 5943dcea:

Tests run locally:

  • python -I tests/test_content_definitions.py -v -> 11/11 OK (0.729s)
  • python -I tests/test_docs_links.py -> 5/5 OK
  • python -I tests/test_text_write_line_endings.py -> 2/2 OK

Code & diff review (tools/content_definitions.py, tests/test_content_definitions.py, docs/restofworld.md):

  • parse_content enforces max_bytes, 128-level nesting depth, rejects DTDs and namespaced roots, and avoids echoing input values or paths in ContentError.
  • Record.scalar preserves absent (None) vs empty (""), rejects repeated/nested/text+value ambiguity, and eagerly validates known scalar convenience fields (filename, fileType, loadPath) during parse.
  • carve_documents overrides DirectorySource.read with strict file reads so missing .bin blocks raise OSError instead of substituting header bytes, and maps gamedata_index.build_rows spans cleanly back to contiguous source.rows slices.
  • CLI prints aggregate counts only and exits non-zero on failed_inputs; tests use purely synthetic fixtures and newline='\n'.

No issues found; looks ready to merge from a CPU/code-read perspective.

@jbot1324

Copy link
Copy Markdown

AI-assisted code read (Claude), not run. One functional issue, otherwise looks good.

1. One bad document in a carve directory aborts the rest of that directory and leaves partial counts.
carve_documents() lets a ContentError from parse_content() escape the generator. In main(), the except around for _, _, doc in carve_documents(path) then counts the whole directory as one failed_inputs, but the documents already passed to add() stay counted, and every XML payload after the bad one is never read. With a carve, truncated payloads are realistic: #2278's validation of the common.rpf carve rejected 8 of 267 XML payloads. So a single unrecoverable payload in story000_restofworld gives counts that depend on carve order and silently skip the remainder.

Suggested fix: report the error per payload instead of raising it. For example, yield the exception as the third value and let callers decide:

try:
    doc = parse_content(source.read(r) for r in group)
except ContentError as exc:
    doc = exc
yield row["offset"], row["stored"], doc

Then have main() count isinstance(doc, ContentError) as invalid, as tools/gamedata_reader.py in #2278 does. Also add a test with one valid and one truncated content payload in the same synthetic carve.

2. Minor. The except (OSError, ContentError, ValueError, KeyError, TypeError) in main() also turns bugs (a KeyError from an unexpected row shape) into a plain failed_inputs count. Printing the exception class name to stderr (no values or paths) would keep it diagnosable without leaking data.

Everything else checks out: the scalar rules (None, "", ambiguous) match the docs, DTDs are refused before entity expansion, the depth and byte limits are applied before feeding, and namespaced roots are rejected as documented.

@mrp1no

mrp1no commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Independent check of 5943dcea7032d67b6631bf61278f82e138b073a7 on my own Xbox Series 1.0.2.1 copy (Windows 11 Pro 26300, Python 3.15.2, CPU only): pass, the aggregate counts reproduce exactly.

rpf9_carve.py on core_restofworld, story000_restofworld, core_restofworld001 and core_licenses_data, then python -I tools/content_definitions.py <the four carve folders>:

{"change_sets": 22, "contents": 4, "documents": 30, "failed_inputs": 0, "files": 65, "groups": 8, "included_changesets": 22, "included_sets": 0, "other_xml": 0, "setups": 4}

So: 30 documents, all accepted (22 change sets, 4 content definitions, 4 setup documents), 65 file entries, 22 included change-set references and 8 setup groups, as in the description. I didn't repeat the record-by-record ElementTree comparison. @jbot1324's point about one bad document aborting the rest of a carve folder doesn't show up on this data: failed_inputs is 0.

python -I tests/test_content_definitions.py: OK. Nothing from the package is attached. AI-assisted (Claude Code).

@JRamos1993

Copy link
Copy Markdown
Contributor

Ran this on main 4947579 (Windows 11, Python 3.14). It merges cleanly.

  • Tests: test_content_definitions.py 11 OK. Also OK: test_gamedata_index.py 21, test_gamedata_xml.py 7, test_restofworld_index.py 23, test_docs_links.py 5, test_text_write_line_endings.py 2.
  • Mutation check: removing any of these fails the tests: the DTD refusal, the depth limit, the strict block read, the multi-row grouping, or value= handling in scalar.

One failure: python -I tests/test_tool_stdout_encoding.py fails with ['content_definitions.py']. The __main__ block (tools/content_definitions.py:221) needs sys.stdout.reconfigure(errors="replace"). Same on the head as-is.

jbot1324's point 1 reproduces with the PR's own fixtures in a synthetic carve: [CHANGE[:180], CONTENT, SETUP] gives documents 0, failed_inputs 1, while the same carve with the truncated payload last gives documents 2, failed_inputs 1. A ContentError from one payload (:185) is caught per directory (:215), so every payload after it is skipped.

AI-assisted (Claude Code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants