Skip to content

world: texture dictionaries and where material textures resolve (ASSET-397) - #4980

Open
throny wants to merge 21 commits into
ItsNotRexed:mainfrom
throny:texture-dicts
Open

throny wants to merge 21 commits into
ItsNotRexed:mainfrom
throny:texture-dicts

Conversation

@throny

@throny throny commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Depends on: #4946 (this branch now builds on its shared tools/manifest_stream.py).

ASSET-397, claimed in the coordination issue: #4933 (comment)

What and why

docs/world.md:384 said no .#td system page was found in the sampled levels.rpf windows, and that world textures are the loose RDS5 pools plus textures.rpf. This PR measures both points over a full asset export and rewrites the bullet with the counts. It also says what the counts do and don't establish.

tools/texture_dicts.py (stdlib, python -I) reads a make_game.py export, enumerating everything with os.listdir:

  • Dictionaries: every <archive>/textures/manifest.json (rpf9dump textures). Dictionary and texture counts are checked against each manifest's Count. It also reports single-texture and empty dictionaries, distinct hashes, formats, the offset band, the offset position within a 4 KiB page, and whether Hash == joaat(Name).
  • Texture pools: the 57 TTPF manifests (ttpf/<pool>/, ttpf_pack/<pack>/<pool>/), each checked against its Count.
  • Material references: every <archive>/models/manifest.json. These are streamed item by item, since the levels manifest is several GB, and include the textures embedded in models.

Each distinct material texture key (Id64) is an exact 64-bit key match (pool AssetKey or embedded Key), else a 32-bit name-hash candidate, else unresolved; the three add up to the total, and per-source counts (which overlap) are listed too. Name hashes are compared as stored: rpf9dump writes a material binding's Name as its stored name hash in eight hex digits (NameHash.ToString("X8")), and dictionary and embedded rows carry a stored Hash (corrected in c6562aa0 after review; the first version hashed the hex digits again). A candidate is ambiguous when its hash is on more than one entry. Output is counts only, and --json may not be inside the export folder (another drive counts as outside).

Result on my own Xbox Series 1.0.2.1 copy

  • levels.rpf dictionaries: the export's full page+16 scan (rpf9-explorer's texture recovery) finds 23,180 candidates and recovers 1,009 texture dictionaries, holding 1,013 textures. Every offset sits at page+16, all of them at 70.80-70.92 GiB, inside the tail window that world.md lists as sampled. Their 1,013 textures have only 9 distinct name hashes, and 1,008 of the dictionaries hold a single texture. Hash == joaat(Name) holds for all 1,013, and none has a 64-bit key.
  • Not the models' embedded dictionaries: none of the 1,293 levels models with embedded textures lies in that band (those sit at 62.9-70.6 GiB), and the two sets share no name hash.
  • textures.rpf: 1,356 dictionaries with 4,604 textures and 1,972 distinct hashes, at 0-0.18 GiB, all at page+16.
  • Pools: 57 manifests, 357,115 textures, 357,067 distinct keys.
  • Where material references resolve (corrected run, c6562aa0): 382,781 models, 20,781,927 bindings (all with the stored hex hash), 418,714 distinct keys. 296,789 match exactly by 64-bit key (296,785 a pool AssetKey, 137 an embedded Key, 133 both), 8 only by a 32-bit name hash in a dictionary (2 ambiguous), and 121,917 (29.1%) match nothing. 50 keys share a hash with a dictionary entry (38 in core_restofworld's dictionaries, 12 in textures.rpf's; 42 of them also match a pool key exactly), and none shares a hash with a levels.rpf dictionary entry. The first version reported 0 dictionary matches and 121,925 unresolved because it hashed the stored hex names again; the old-vs-new table is in the PR thread.

Limits, stated plainly

  • .#td link not established: whether these 1,009 dictionaries are what a .#td entry name would label can't be told until the RPF9 directory is decoded. The earlier note doesn't record how .#td pages were looked for. So the doc says "standalone texture dictionaries found by the full scan", not "the .#td pages exist after all".
  • Name-hash candidates: a 32-bit hash match is a candidate, not proof of the same asset; only the 64-bit key matches are exact.
  • Unresolved references: 121,917 keys match none of the exported sources. This PR doesn't explain why and doesn't guess.
  • world.md wording: the earlier sentence "World textures ... plus textures.rpf" is replaced by what was measured: the material textures that resolve exactly come from the 57 pools and a few embedded textures; textures.rpf's and core_restofworld's dictionaries only share name hashes with 50 keys, and levels.rpf's with none.

Tested

Windows 11, Python 3.13, CPU only:

No game data in the PR: synthetic fixtures only, and counts only in the doc. AI-assisted.

🤖 Generated with Claude Code

throny and others added 2 commits November 23, 2026 07:40
tools/render_buckets.py streams every rpf9dump models manifest's Items (the
levels manifest is several GB), enumerates archives with os.listdir, checks
each archive's total against the manifest's Count, and counts RenderBucket & 0x7F,
bit 7, values outside 0-6 and distinct shader hashes per bucket, per material
and per unique model. docs/models.md gets the whole-export table next to the
3,000-model sample; the RenderBucketMask rule stays sample-only (the field is
not in the manifests). Synthetic tests only; counts only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tsNotRexed#4946)

iter_items returned at the closing bracket of Items, so a top-level Count after
Items was never read. After Items closes it now parses the remaining top-level
members one by one (a Count nested in a later value doesn't count), keeping the
incremental read of the items. Tests cover Count before and after Items, a nested
Count after Items, small read chunks, and the exit code on a mismatch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

At fd3f310d, a Windows user can create a JSON report on another drive, but the same command fails when it refreshes that report.

Run this from the repository root with py -3.14 -I - on a machine with C: and E:. The export can be empty.

from pathlib import Path
from tempfile import TemporaryDirectory
import subprocess, sys

with TemporaryDirectory(dir="E:/") as export, TemporaryDirectory() as tmp:
    report = Path(tmp) / "report.json"  # TEMP is on C:
    cmd = [sys.executable, "-I", "tools/texture_dicts.py", export, "--json", str(report)]
    for _ in range(2):
        print(subprocess.run(cmd).returncode)

On Windows 11 with CPython 3.14.7, the first run writes the report and exits with code 0. The second exits with code 1 and prints ValueError: Paths don't have the same drive. Both runs should write the report.

In main(), the second run reaches os.path.commonpath because the report now exists. Please handle distinct drives as separate directory trees and add a repeat-write test. All eight existing tests pass. The tool is new in this PR.

AI-assisted.

…earer unique counts (review on ItsNotRexed#4946)

- A value after Items that reaches the end of the read buffer is read on before
  it is accepted: the digits of a Count split between reads gave a shorter number
  (shdann). Test sweeps every chunk size over a four-digit Count.
- A material without a shader hash is counted on its own, not as a "none" hash.
- Docstring and docs/models.md say exactly what a unique model is (the ordered
  material list: reordered materials count again, full collisions merge), that
  per-archive unique figures are first-seen-in-listing-order, and that the
  sample's "Shaders" column counts rows while the new column counts hashes
  (tupacfan04). Counts on the export are unchanged; 0 materials lack a hash.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@throny

throny commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Head moved to c9828cc2 with one fix: the JSON reader shared with #4946 accepted the digits of a top-level Count after Items as a shorter number when they were split between reads (found by shdann on #4946). It now reads on before accepting a value that ends the buffer. The real export's manifests all put Count first, so the numbers in this PR are unchanged. python -I tests/test_texture_dicts.py: OK. AI-assisted.

@Atomic258

Copy link
Copy Markdown
Contributor

Independent check of c9828cc2 — pass (first check on this PR).

Environment: Windows 11, CPython 3.15.2, CPU only. Synthetic export fixtures, no game files, no GPU.

  • python -I tests/test_texture_dicts.py → 8/8 pass
  • CLI smoke test on a synthetic <work>/assets tree (built with the test's own fixture helpers): prints the expected census — dictionaries/pools/embedded counts, per-archive reference resolution (pool: 3, embedded: 2, dictionary: 2, unresolved: 1), exit 0
  • compileall clean, git diff --check main...HEAD clean

Read the tool: counts-only output (no names — consistent with the no-game-data rule), chunked manifest parsing with the buffer-boundary fix in the head commit, --json guarded by same_report_path against overwriting an input, stdlib only. New file so no negative control possible.

One caveat worth noting: the manifest shapes it parses (textures/manifest.json Items/Offset/Textures, ttpf/ttpf_pack pools, models/manifest.json bindings) are documented assumptions about rpf9dump output — first run against a real export may surface format drift the fixtures can't. That run needs the assets stage, so it's untested against real data by anyone so far.

AI-assisted (Devin).

@kacper-serewis kacper-serewis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Material texture Name is already the stored 32-bit hash formatted as eight hexadecimal digits by rpf9dump (Program.cs, r.NameHash.ToString("X8")). The census hashes those digits again. This representation occurred throughout three cached retail manifests, and the same nh = joaat(t["Name"]) expression remains at c9828cc2. Please parse the hexadecimal value, compare stored hashes, and distinguish candidate 32-bit matches from exact 64-bit key matches. A synthetic case with two candidates sharing a hash would cover the ambiguity. The published dictionary and embedded match counts need a corrected run. We verified the material denominators on each of three cached subsets. Those subsets contained no texture dictionaries or embedded textures. AI-assisted Windows CPU review.

@tupacfan04

Copy link
Copy Markdown
Contributor

Approve with two small fixes; nothing blocking.

Verified: tests/test_texture_dicts.py 8/8, test_docs_links/design_rows/tool_startup, compileall and check_no_game_data.py clean, merge clean; the tool is absent on main (negative control exits 2). Arithmetic is self-consistent (1,008 + 5 textures = 1,013; 1,009 dicts; 29.1% = 121,925/418,714; the 70.8-70.92 tail window matches docs/world.md:29), and both Count-after-Items and nested-Count paths work.

Issues:

  • tools/texture_dicts.py:322-324: os.path.commonpath raises an uncaught ValueError ("Paths don't have the same drive") when --json names an existing file on another drive than the export; reproduced, and no report is written. Catch it and emit the usual one-line usage error.
  • The same guard accepts a new path inside the export (exit 0, file created), which contradicts the error text "is inside the export folder" and the test name at tests/test_texture_dicts.py:114; the docstring only promises no overwrite. Decide which rule you want and align the message/test.
  • docs/world.md:391-393 claims the dictionary cross-check was repeated "by exact name", but the tool stores only 32-bit hashes (texture_dicts.py:191-206), so that is not reproducible as shipped.
  • Minor: resolution counts are per-source, so 296,785 + 137 + 121,925 = 418,847, not 418,714 (133 pool-and-embedded); world.md:394-396 should say the counts can overlap.

AI-assisted review, no game files, no GPU.

…eview on ItsNotRexed#4946)

The reader now parses the top-level object member by member: Count is the
top-level member wherever it stands, and a missing, doubled, leading or trailing
comma in Items, an unclosed object or data after it raise ValueError; the CLI
reports that and exits 2 (kacper-serewis). A second manifest with an archive
label already used gets a numbered label, so per-archive entries no longer
overwrite each other while both stay in the totals. Tests cover the malformed
cases at several read sizes, top-level-only Count, and the label collision.
Counts on the export are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@throny

throny commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Head moved to 14761193: the streaming reader is replaced by the validating parser from review on #4946. Top-level members are parsed one by one, and separators and the enclosing object are checked. python -I tests/test_texture_dicts.py: 10 tests, OK. A re-run on the export gives the same numbers. AI-assisted.

@whattheflop

Copy link
Copy Markdown
Contributor

Independent Windows review at 14761193, AI-assisted, uv CPython 3.12.13. All ten stock tests passed. Three findings still reproduce with valid, synthetic exporter-shaped manifests.

  1. Please compare the stored name hashes directly and rerun the name-based and unresolved counts. The exporter writes material Name as NameHash.ToString("X8"); embedded and standalone rows carry a separate stored Hash. A synthetic material with Name: "6BACDAD2" missed the dictionary with Hash: "6BACDAD2" (0 dictionary, 1 unresolved) and matched the decoy with Hash: "87FCDADC" (1 dictionary, 0 unresolved). The census hashes the material's hex string again and hashes embedded display names. The pool join correctly preserved full 64-bit equality in the earlier c9828cc2 fixture.
  2. A model manifest with Count: 2, one emitted row and one decode failure exited 1. The exporter can omit failed rows. Please report positive gaps as export coverage and keep a consistency error for impossible counts.
  3. The synthetic Windows JSON report contained 65 CRLFs. Open the writer with newline="\n" for the repository's LF convention.

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

The census rejects a valid manifest when a read ends at the e in 1e3. At tools/texture_dicts.py:81, raw_decode returns 1 from the partial buffer. The next check reads e as a separator. Check that the next character ends the number before accepting the value.

Run this script from the repository root with py -3.14 -I. It uses a temporary synthetic export.

import json, pathlib, subprocess, sys, tempfile
with tempfile.TemporaryDirectory() as d:
    p = pathlib.Path(d, "a", "models", "manifest.json")
    p.parent.mkdir(parents=True)
    for pad in (0, (8 << 20) - len('{"scale":1e')):
        s = " " * pad + '{"scale":1e3,"Items":[{}],"Count":1}'
        p.write_text(s, encoding="ascii")
        assert json.loads(s)["Count"] == 1
        r = subprocess.run([sys.executable, "-I", "tools/texture_dicts.py", d], capture_output=True, text=True)
        print(pad, r.returncode, r.stderr.splitlines()[-1:] or r.stdout.splitlines()[-1:])

Expected: both runs exit 0 and report one model. The parent c9828cc2 gives that result. At 14761193, the unpadded input passes. With 8388597 spaces the command exits 1 with ValueError: expected ',' between top-level members, found 'e'. All 10 tests in tests/test_texture_dicts.py pass on this head.

AI-assisted.

@kotekompotek

Copy link
Copy Markdown

Independent Windows CPU verification on 14761193:

  • python -m pytest tests/test_texture_dicts.py --basetemp D:\temp\pytest_tmp -q: 10 passed in 0.71s

… (review on ItsNotRexed#4946)

Members other than Items and Count (e.g. a large ModelDecodeFailures list before a
trailing Count) were decoded into Python lists and dicts just to step over them
(shdann). They are now skipped structurally: brackets must match and strings end,
nothing is built. On shdann's 14.8 MB fixture the peak traced allocation is the
same with Count first or last (about 29.6 MB, the read buffer). Tests cover the
memory bound and malformed skipped values. Counts on the export are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@throny

throny commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Head moved to 7be3c50d: the reader now skips unrelated top-level values (e.g. a large ModelDecodeFailures) without decoding them, after shdann's memory finding on #4946. python -I tests/test_texture_dicts.py: 12 tests, OK. A re-run on the export gives the same numbers. AI-assisted.

shdann found on ItsNotRexed#4980 that the shared reader accepted "1" from "1e3" when a read
ended at the e. When the number characters run on to the end of the buffer, the
reader now reads more before it accepts the number. Test sweeps every chunk size.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
throny added a commit to throny/Leonida that referenced this pull request Nov 23, 2026
…, coverage gaps (review on ItsNotRexed#4980)

- rpf9dump writes a material binding's Name as its stored 32-bit name hash in
  eight hex digits; the census hashed those digits again, so the dictionary and
  embedded name matches were wrong (kacper-serewis, whattheflop). Stored hashes
  are now compared (joaat only for a name that is not eight hex digits), and
  embedded rows use their stored Hash.
- Each reference is an exact 64-bit key match, else a 32-bit name-hash
  candidate (ambiguous when the hash is on more than one entry), else unresolved;
  the three add up, per-source counts are listed separately and can overlap.
- A manifest Count above its rows is export coverage, not a problem; more rows
  than Count is (whattheflop).
- --json: never inside the export folder, new path or existing; a different
  drive is outside (no commonpath ValueError); written with LF (shdann,
  tupacfan04, whattheflop).
- A number cut at a read boundary ("1e" of "1e3") is read on before it is
  accepted (shdann).
- docs/world.md:384 rewritten with the corrected run. Still 0 references match a
  levels.rpf dictionary entry; 50 share a hash with core_restofworld's or
  textures.rpf's dictionaries (42 also match a pool key exactly).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@throny

throny commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Fix round at c6562aa0, covering every finding so far. The main result was wrong in one place, and the corrected numbers are below.

Name hashes (@kacper-serewis, @whattheflop): confirmed, and it changes the numbers. rpf9dump writes a material binding's Name as NameHash.ToString("X8"), and the census hashed those digits again. On my export, all 20,781,927 material bindings carry the stored hex form. The census now compares stored hashes: a binding's hex Name (joaat only for a name that isn't eight hex digits), a dictionary entry's Hash, and an embedded row's Hash (no longer its display name). Each distinct reference is now an exact 64-bit key match (pool AssetKey or embedded Key), else a 32-bit name-hash candidate (ambiguous when the hash is on more than one entry), else unresolved. These three add up to the total, and the per-source counts are listed separately and can overlap. New tests cover whattheflop's case (a binding Name: "6BACDAD2" matches Hash: "6BACDAD2" and not the decoy whose hash is joaat of the hex text) and a hash shared by two entries counted as ambiguous.

Old and new numbers over the same export (418,714 distinct material texture keys, 20,781,927 bindings):

old (fd3f310d…7be3c50d) new (c6562aa0)
exact 64-bit key (pool or embedded) (per source) 296,785 pool, 137 embedded 296,789 (296,785 pool, 137 embedded, 133 both)
32-bit name-hash candidate only (counted as "dictionary") 0 8 (2 ambiguous)
unresolved 121,925 121,917 (29.1%)
keys sharing a hash with any dictionary entry 0 50: 38 in core_restofworld's dictionaries, 12 in textures.rpf's; 42 of them also match a pool key exactly
keys sharing a hash with a levels.rpf dictionary entry 0 0

The conclusion docs/world.md:384 draws about levels.rpf stands: no material names those 1,009 dictionaries. The claims that textures.rpf's dictionaries match nothing, and that this was cross-checked "by exact name" (thanks @tupacfan04), were wrong. Both are gone. The bullet now gives the table above and says that name-hash candidates aren't proof of the same asset, and that the per-source counts overlap (296,785 + 137 counts 133 keys twice).

Count gaps (@whattheflop): a manifest Count above the rows it holds is now reported as export coverage, not a problem, because rpf9dump can leave out rows that failed to decode. More rows than Count stays a problem, and both cases are tested. On my export, no manifest has a gap.

--json guard (@shdann, @tupacfan04): the rule is now "never inside the export folder", for an existing path or a new one, so the message and the test agree. A path on another drive is outside: the guard compares drives first and never reaches commonpath, so shdann's repeat write to another drive works. The test writes the same report twice and refuses both an input and a new path inside the export. On Windows, a unit test covers the drive rule.

LF report (@whattheflop): the writer opens with newline="\n", and the test checks there's no CR. My real report has 0 CRs.

1e3 at a read boundary (@shdann): confirmed and fixed. When the number characters run on to the end of the read buffer, the reader reads more before it accepts the number. Tests sweep every chunk size over 1e3, -1.5E-3 and 12e+3. #4946's reader had the same bug and got the same fix.

python -I tests/test_texture_dicts.py: 16 tests, OK. test_docs_links.py, test_docs_design_rows.py and test_tool_startup.py are OK, and git diff --check is clean. The re-run on the export took 110 s and exited 0 with no problems.

Thanks @Atomic258 and @kotekompotek for the checks, and @Atomic258 for the caveat about running against a real export, which turned out to matter.

AI-assisted.

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

I verified both earlier fixes at c6562aa0. A synthetic 1e3 split at the 8 MiB boundary now counts one model. Writing its report from E: to C: succeeds on both the first run and the overwrite. All 16 tests in tests/test_texture_dicts.py pass on Windows.

One non-blocking performance finding at tools/texture_dicts.py:452: when dict_cand is empty, summarise still intersects it with each archive set for each reference. With 20,000 distinct unresolved references and 256 archives, this makes 5,120,000 empty intersections. The per-archive result is empty for every input size below. An if dict_cand: guard around the archive loop removes this work for references with no dictionary hit.

Run this synthetic probe with py -3.14 -I from the repository root. Median times here were 0.016 s for one archive, 0.079 s for 64, and 0.257 s for 256. These times cover summarise only.

import sys,time,statistics
from pathlib import Path
sys.path.insert(0,str(Path("tools").resolve()))
import texture_dicts as t
refs={k:{123456} for k in range(20000)}
for n in (1,64,256):
    archives={str(i):{i} for i in range(n)}
    src=(set(),set(),set(),set(range(n)),archives,{})
    times=[]
    for _ in range(3):
        start=time.perf_counter()
        result=t.summarise(refs,src,len(refs),0,1)
        times.append(time.perf_counter()-start)
    print(n,result["resolution"]["unresolved"],round(statistics.median(times),3))

AI-assisted.

@kacper-serewis kacper-serewis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TEST-1133 at c6562aa0: the exporter’s stored hexadecimal hash now matches directly and the double-hashed decoy stays unresolved. An independent collision fixture confirmed exact 64-bit precedence and an ambiguous 32-bit-only candidate. All 16 focused tests passed. The 89-entry retail window confirmed the dictionary representation. The author’s full-export partition reconciles to 418,714 distinct keys; we checked its arithmetic without repeating the full export. This resolves my original change request. AI-assisted CPU review.

…ts uses it (review on ItsNotRexed#4946)

tools/manifest_stream.py holds the reader both census tools need, with one rule
in one place: a decoded value is accepted only when a terminator (, } ] :, or
whitespace) is visible after it or the file has ended; otherwise it is read on and
decoded again from its start. That covers every split the reviews found (digits,
".", "e", signs) and split literals and strings (kacper-serewis). Members other
than Items and Count are validated without being built: commas, colons, keys and
brackets are checked while discarding (shdann's missing comma between skipped
records), with memory bounded.

tests/test_manifest_stream.py reads 8 valid documents at every read size from 1
to their length and requires json.loads' result, rejects 44 invalid ones at every
read size, checks the reviewers' splits at the default 8 MiB read, and bounds
memory for a large skipped member. Counts on the export are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@whattheflop

Copy link
Copy Markdown
Contributor

Retested the three findings from my earlier review on c6562aa0 with uv CPython 3.12.13 on Windows. All are resolved. On the same synthetic repro, stored hash 6BACDAD2 is now one name-hash candidate, and the 87FCDADC decoy is unresolved. Both cases had a declared count of two with one emitted model; the CLI exited 0 and reported one missing row as coverage. Both reports had zero carriage returns. All 16 focused tests passed. AI-assisted, synthetic inputs only.

throny added a commit to throny/Leonida that referenced this pull request Nov 23, 2026
…, coverage gaps (review on ItsNotRexed#4980)

- rpf9dump writes a material binding's Name as its stored 32-bit name hash in
  eight hex digits; the census hashed those digits again, so the dictionary and
  embedded name matches were wrong (kacper-serewis, whattheflop). Stored hashes
  are now compared (joaat only for a name that is not eight hex digits), and
  embedded rows use their stored Hash.
- Each reference is an exact 64-bit key match, else a 32-bit name-hash
  candidate (ambiguous when the hash is on more than one entry), else unresolved;
  the three add up, per-source counts are listed separately and can overlap.
- A manifest Count above its rows is export coverage, not a problem; more rows
  than Count is (whattheflop).
- --json: never inside the export folder, new path or existing; a different
  drive is outside (no commonpath ValueError); written with LF (shdann,
  tupacfan04, whattheflop).
- A number cut at a read boundary ("1e" of "1e3") is read on before it is
  accepted (shdann).
- docs/world.md:384 rewritten with the corrected run. Still 0 references match a
  levels.rpf dictionary entry; 50 share a hash with core_restofworld's or
  textures.rpf's dictionaries (42 also match a pool key exactly).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@throny

throny commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Head is now f0d1c348, rebased onto #4946 (Depends on: #4946, added at the top of the description):

  • Shared reader: texture_dicts.py no longer has its own copy. It imports tools/manifest_stream.py from models: render buckets over the whole export (ASSET-396) #4946, which is exhaustively tested at every read size against json.loads and also validates skipped members without building them.
  • @shdann's performance note: summarise() now only walks the dictionary archives when a reference has a name-hash candidate.
  • Numbers: the census re-run on the export gives an identical report to c6562aa0's (references, dictionaries, pools, embedded), with no problems and no coverage gaps.
  • Tests: tests/test_texture_dicts.py has 16 tests and tests/test_manifest_stream.py 4, all OK.

AI-assisted.

…mber for real (review on ItsNotRexed#4946)

Python's json accepts NaN, Infinity and -Infinity, so the shared decoder let them
through in skipped members and as metadata values (kacper-serewis). The decoder
now rejects them, and six such documents join the invalid set that is checked at
every read size. The default-read boundary test computed its padding from a
different prefix than it wrote, so the boundary missed the number; it now pads
from the exact prefix and asserts that the read ends inside the number, in both
field orders. Counts on the export are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
throny and others added 7 commits November 23, 2026 17:17
Same parser as render_buckets after review on ItsNotRexed#4946: top-level members parsed one
by one, separators and the enclosing object checked. Numbers unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Same change as render_buckets after review on ItsNotRexed#4946. Numbers unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, coverage gaps (review on ItsNotRexed#4980)

- rpf9dump writes a material binding's Name as its stored 32-bit name hash in
  eight hex digits; the census hashed those digits again, so the dictionary and
  embedded name matches were wrong (kacper-serewis, whattheflop). Stored hashes
  are now compared (joaat only for a name that is not eight hex digits), and
  embedded rows use their stored Hash.
- Each reference is an exact 64-bit key match, else a 32-bit name-hash
  candidate (ambiguous when the hash is on more than one entry), else unresolved;
  the three add up, per-source counts are listed separately and can overlap.
- A manifest Count above its rows is export coverage, not a problem; more rows
  than Count is (whattheflop).
- --json: never inside the export folder, new path or existing; a different
  drive is outside (no commonpath ValueError); written with LF (shdann,
  tupacfan04, whattheflop).
- A number cut at a read boundary ("1e" of "1e3") is read on before it is
  accepted (shdann).
- docs/world.md:384 rewritten with the corrected run. Still 0 references match a
  levels.rpf dictionary entry; 50 share a hash with core_restofworld's or
  textures.rpf's dictionaries (42 also match a pool key exactly).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e loop without candidates

The private copy of the streaming reader is gone: texture_dicts imports
tools/manifest_stream.py from ItsNotRexed#4946 (one reader, exhaustively tested at every
read size), so the two tools cannot drift apart. summarise() only walks the
dictionary archives when a reference has a name-hash candidate (shdann's
performance note). Numbers on the export are identical.

Depends on: ItsNotRexed#4946

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r's ItsNotRexed#4946 pattern)

Manifest arrays read by the census must hold objects; a top level, model
entry, material, texture or dictionary that is not one exits 2 instead of
raising AttributeError. A non-string dictionary Name is no longer hashed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r names in the docstring (review on ItsNotRexed#4980)

- A stored hash is ambiguous only when it is on more than one distinct
  texture (same 64-bit Key, or without a key the same format and size, is
  one texture); one texture embedded in several models no longer counts as
  ambiguous (tedin7).
- Embedded must be absent, null, a list of objects or an object whose
  Textures is one; Materials {} / "" / 0 / false is an input error
  (LILILI2007).
- The docstring says the counts are keyed by archive and pool folder names
  (cynbun, TheAnirudhan).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he count stays 2) (ItsNotRexed#4980)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
throny added a commit to throny/Leonida that referenced this pull request Nov 23, 2026
…d, folder names in the docstring (review on ItsNotRexed#4980/ItsNotRexed#5067)

- A name hash is a candidate when it is on one distinct texture (same
  usable Key, or without one the same format and size); one texture
  embedded in several models is no longer ambiguous (tedin7).
- Embedded and Materials go through texture_dicts' strict readers, so
  {} / "" / 0 / false is an input error (LILILI2007).
- The docstring says the output is keyed by archive and pool folder names
  (cynbun).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@throny

throny commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @tedin7, @cynbun (and @TheAnirudhan for the original finding). Fixed in b9a0e828 and 6565b4ab, on top of #4946's 5c174474:

  • tedin7 1, rows counted instead of textures: a stored hash is now ambiguous only when it is on more than one distinct texture. Rows count as one texture when they have the same 64-bit Key, or, without a key, the same format and size (texture_identity). Your probe is the regression test_one_texture_embedded_in_two_models_is_not_ambiguous: one texture embedded in 1 or 2 models gives ambiguous 0. I re-ran the full export and the published numbers do not change: 296,789 exact, 8 candidates (2 ambiguous), 121,917 unresolved. Those 2 hashes really are on different textures. docs/world.md now says "more than one distinct texture".
  • tedin7 2, the reader: fixed in models: render buckets over the whole export (ASSET-396) #4946 (see my reply there).
  • cynbun / TheAnirudhan, docstring vs output: the docstring now says the counts are keyed by the export's archive and pool folder names, with no texture, model or shader names. The same wording is in textures: DXGI formats per material parameter slot over the whole export (ASSET-398) #5067's tool.
  • Also, LILILI2007's pattern on models: render buckets over the whole export (ASSET-396) #4946: Embedded must be absent, null, a list of objects or an object whose Textures is one, and a falsy Materials is an input error (8 more shapes in test_non_object_entries_exit_2).

Tests: test_texture_dicts (19), test_render_buckets, test_manifest_stream, test_text_write_line_endings and test_docs_table_rows pass (Windows 11, CPython 3.13). Atomic258, TheAnirudhan: thanks for the passes.

@whattheflop

Copy link
Copy Markdown
Contributor

Follow-up on 6565b4a with an exporter-shaped synthetic dictionary fixture. Two rows at separate dictionary offsets had the same stored name/hash, null Key, 4x4 dimensions and BC1_UNORM format. Both DDS files were valid. The decoder returned solid red for one and solid green for the other. Adding the second row kept the result at 1 candidate and 0 ambiguous. #5067 at daa3ff3 reproduced that classification in its slot report.

The keyed repeat control still counted one candidate as intended. Changing the second keyless row's dimensions made both tools report ambiguity. Exact pool and embedded keys continued to take precedence over ambiguous name-hash fallback.

Matching format and dimensions establishes a metadata group. The rows in it can represent distinct textures. Could the report and docs describe the result as one matching metadata group with unknown texture identity, or surface the multiple keyless rows as uncertain? This fixture does not establish a change to the published full-export counts.

The 19 census tests passed on both snapshots. Windows, uv CPython 3.12.13, synthetic CPU inputs. AI-assisted.

…mat and size is uncertain (review on ItsNotRexed#4980)

Keyless rows with the same format and size form one metadata group, but they
can be different textures (whattheflop). Such a candidate is now counted as
"uncertain" instead of a clean match. On the full export none of the 8
candidates is uncertain (2 stay ambiguous).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
throny added a commit to throny/Leonida that referenced this pull request Nov 23, 2026
…d, folder names in the docstring (review on ItsNotRexed#4980/ItsNotRexed#5067)

- A name hash is a candidate when it is on one distinct texture (same
  usable Key, or without one the same format and size); one texture
  embedded in several models is no longer ambiguous (tedin7).
- Embedded and Materials go through texture_dicts' strict readers, so
  {} / "" / 0 / false is an input error (LILILI2007).
- The docstring says the output is keyed by archive and pool folder names
  (cynbun).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
throny added a commit to throny/Leonida that referenced this pull request Nov 23, 2026
…s of one format and size as uncertain (review on ItsNotRexed#4980)

Same rule as texture_dicts (whattheflop): such rows form one metadata group
but can be different textures. On the map none of the 35 candidates is
uncertain.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@whattheflop

Copy link
Copy Markdown
Contributor

Independent retest at a1e701e, AI-assisted. The original pair of distinct keyless DDS files with equal metadata now reports one uncertain candidate. Combining two matching hashes with equal keyless metadata also reports one uncertain candidate. Different metadata groups still report ambiguity, same-key repeats stay a single ordinary candidate, and both exact-key controls retain precedence.

The synthetic two-archive report also reconciled: seven distinct keys overall, two exact, four name-hash candidates (one ordinary, one ambiguous, two uncertain), and one unresolved. One key with an ordinary candidate in each archive becomes uncertain when the overall report combines their hashes.

All 20 census, 23 render-bucket and 5 manifest-reader tests passed on Windows with uv CPython 3.12.13. Synthetic CPU inputs only. This resolves the keyless finding here. The dependent slot branch's separate behavior is recorded on #5067.

@throny

throny commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @whattheflop, agreed: matching format and size only makes a metadata group, and the rows in it can be different textures. Fixed in a1e701e2, and in #5067 as 003f31c2:

  • Rows that share a 64-bit Key still count as one texture, so one texture embedded in several models is not ambiguous.
  • A candidate whose only metadata group holds several keyless rows is now reported as uncertain. It is a separate line under the candidates, next to "ambiguous", instead of a clean match. In textures: DXGI formats per material parameter slot over the whole export (ASSET-398) #5067 it is candidate_uncertain, printed as n (k uncertain).
  • Your fixture is now a regression test in both tools: one keyless row gives a clean candidate, two keyless rows with the same hash, format and size give an uncertain one. Changing the dimensions still gives ambiguous.

Full export: nothing moves. #4980 still has 8 candidates, 2 ambiguous and 0 uncertain. #5067 has 35 candidates on the map, 0 of them uncertain. docs/world.md and docs/textures.md say so. test_texture_dicts (20) and test_texture_slot_formats (21) pass along with the other suites (Windows 11, CPython 3.13).

throny added a commit to throny/Leonida that referenced this pull request Nov 23, 2026
…s an uncertain candidate again, as in texture_dicts

71e8636 made two matching hashes ambiguous, but texture_dicts (ItsNotRexed#4980,
a1e701e) reports one keyless metadata group reached through two hashes as an
uncertain candidate, and whattheflop confirmed that rule on both tools. This
restores it; two metadata groups stay ambiguous. The test covers both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@isfcrctfs isfcrctfs left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read the PR's own three files at a1e701e (the rest of the range is #4946, which this branch carries): tests/test_texture_dicts.py 20 OK (1 skip), tests/test_manifest_stream.py 5 OK, tests/test_render_buckets.py 23 OK, and the ten test_docs_* files OK at this head. I cannot reproduce the corpus numbers in docs/world.md without an export, but they are arithmetically self-consistent with the tool's categories (296,789 + 8 + 121,917 = 418,714; 296,785 + 137 - 133 = 296,789; 38 + 12 = 50 keys share a dictionary hash, 42 of them exact, leaving 8 candidates).

One defect: a texture-dictionary or pool manifest whose top-level Count is not an integer crashes with a traceback instead of the tool's input error. iter_items ignores a non-integer Count for models manifests (_is_count accepts only int), but census passes json.load's value straight to check_count, which compares rows > declared:

mkdir -p /tmp/e/lv/textures
printf '{"Count": "3", "Items": []}' > /tmp/e/lv/textures/manifest.json
python -I tools/texture_dicts.py /tmp/e     # TypeError: '>' not supported between 'int' and 'str'; exit 1

Same on the pool path (ttpf/<pool>/manifest.json with {"Count": "2", "Textures": []}, line 218). This should exit 2 with invalid manifest JSON, like the other fourteen malformed shapes in test_non_object_entries_exit_2; validating declared as int and not bool in check_count would make the two paths agree with the shared reader.

Minor: read_all() (texture_dicts.py:43) is unused (CHUNK is re-exported for the tests and is still used there); read_all is not.

AI-assisted.

@throny

throny commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @isfcrctfs. The docs/world.md numbers come from a full run on a real export, last repeated at head a1e701e2.

  • python -I tools/texture_dicts.py <work>/assets over all 382,781 models and 20,781,927 bindings: 418,714 distinct keys, 296,789 exact (296,785 pool, 137 embedded, 133 both), 8 name-hash candidates only (2 ambiguous, 0 uncertain), 121,917 unresolved.
  • 50 keys share a dictionary hash (38 core_restofworld, 12 textures.rpf), and 0 share one with levels.rpf.
  • Every rule change in this review cycle was re-run on the full export, and none moved these figures.
  • Unverified: nothing in that paragraph. It rests on one export of package 1.0.2.1 (game/xbox-1.0.2.1.json).

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.