From e801a13a2e7f85d3a63c900de3b870545698db2e Mon Sep 17 00:00:00 2001 From: syfyra <258908070+syfyra@users.noreply.github.com> Date: Thu, 26 Nov 2026 17:41:06 +0100 Subject: [PATCH] world_archetypes: read a carved resource's continuation file too (WORLD-ARCHETYPES-FOLDER-CONTINUATION) On a folder of carved streams, world_index.scan_path joins a 0x7a resource whose blocks run past its stream with the file of the stream that followed it (rpf9_carve's index.json), and reports the joined length as the row's size but only the first file as its "file". iter_resources then re-read that first file alone, so every block in the continuation was lost without a warning: archetype definitions and, for --check-extents, map entity blocks. The same two streams in an RPF9 window are joined by WC.assemble and read in full. docs/world_census.md counts 2,868 maps that join a continuation. Join the same files in iter_resources: follow the carve's successors while the data is shorter than the row's size. Tested: new test_folder_joins_a_continuation_file_as_world_index_does (on main the folder gives 0 archetypes instead of 2). Co-Authored-By: Claude Opus 5.5 --- tests/test_world_archetypes.py | 18 ++++++++++++++++++ tools/world_archetypes.py | 15 ++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/tests/test_world_archetypes.py b/tests/test_world_archetypes.py index 250fc2fe3..569fd2827 100644 --- a/tests/test_world_archetypes.py +++ b/tests/test_world_archetypes.py @@ -310,6 +310,24 @@ class CliTest(unittest.TestCase): f.write(data) self.check(self.run_cli(folder)) + def test_folder_joins_a_continuation_file_as_world_index_does(self): + # rpf9_carve writes each stream as .bin plus index.json, and world_index.scan_path joins a resource + # whose block runs past its stream with the file of the stream that followed it. The archetypes stored in + # that continuation are read too, as in an RPF9 window. + defs, m = scene() + cut = len(defs) - 0x20 # the last archetype's tail lands in the continuation + folder = os.path.join(self.tmp.name, "carved") + os.makedirs(folder) + streams = [(0x1000, defs[:cut], 0x1000), (0x2000, defs[cut:], 0x100), (0x3000, m, 0x100)] + for off, data, _ in streams: + with open(os.path.join(folder, "%012x.bin" % off), "wb") as f: + f.write(data) + with open(os.path.join(folder, "index.json"), "w", encoding="utf-8", newline="\n") as f: + json.dump({"files": [{"off": off, "stored": stored} for off, _, stored in streams]}, f) + self.assertEqual([r["size"] for r in WA.WI.scan_path(folder)[0] if r["file"] == "%012x.bin" % 0x1000], + [len(defs)]) + self.check(self.run_cli(folder)) + def test_rpf9_window(self): defs, m = scene() path = os.path.join(self.tmp.name, "levels.rpf") diff --git a/tools/world_archetypes.py b/tools/world_archetypes.py index 142b16ad5..d2271c0a1 100644 --- a/tools/world_archetypes.py +++ b/tools/world_archetypes.py @@ -130,10 +130,23 @@ def iter_resources(path, start=None, limit=None): yield r, res["data"] return rows, _ = WI.scan_path(path, start, limit) + successors = {} # folder -> {carved file: the file of the stream that followed it} for r in rows: p = os.path.join(path, r["file"]) if os.path.isdir(path) else path with open(p, "rb") as f: - yield r, f.read(WI.CAP + 1) + data = f.read(WI.CAP + 1) + # scan_path parsed the resource joined with the carved file(s) of the stream(s) that followed it (row "size" + # is the joined length, "file" the first file): join the same files here, or the blocks in them are lost. + root, current = os.path.dirname(p), os.path.basename(p) + while len(data) < r["size"]: + if root not in successors: + successors[root] = WI._carve_successors(root) + current = successors[root].get(current) + if current is None: + break + with open(os.path.join(root, current), "rb") as f: + data += f.read() + yield r, data # ---- transforms (source axes: RAGE world, Z up, metres)