Merge pull request #2382 from syfyra/fix/world-archetypes-folder-continuation

world_archetypes: read a carved resource's continuation file too (WORLD-ARCHETYPES-FOLDER-CONTINUATION)
This commit is contained in:
Aslan2142
2026-12-01 16:21:34 +01:00
committed by GitHub
2 changed files with 32 additions and 1 deletions

View File

@ -347,6 +347,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 <offset>.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")

View File

@ -139,10 +139,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)