From db22ff715cffbd21dd17424c9945f1fe53789107 Mon Sep 17 00:00:00 2001 From: evilclanker9000 <45567075+evilclanker9000@users.noreply.github.com> Date: Mon, 23 Nov 2026 14:20:08 +0100 Subject: [PATCH 1/3] meta_to_xml: refuse a negative -Limit instead of converting nothing A negative value is true in PowerShell, so the loop guard \\ -and \ -ge \\ broke before the first blob: exit 0, 'pso ok 0 failed 0' and an empty failures.txt on a mistyped limit. ValidateRange(0, ...) rejects it at binding time; 0 still means every blob. --- scripts/meta_to_xml.ps1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/meta_to_xml.ps1 b/scripts/meta_to_xml.ps1 index 28c6575f65..001f85f558 100644 --- a/scripts/meta_to_xml.ps1 +++ b/scripts/meta_to_xml.ps1 @@ -1,12 +1,15 @@ # Converts carved PSO ('PSIN') and RBF ('RBF0') metadata blobs to XML with CodeWalker.Core's parsers. # Run in Windows PowerShell 5.1. # .\meta_to_xml.ps1 -Carve \carve -Out \meta [-Limit N] +# -Limit N converts the first N blobs; 0 or no -Limit converts every blob. # Each blob becomes \\.xml. Failures go to \failures.txt (UTF-8 with BOM) with the error message. param( [string]$Carve = "\carve", [string]$Out = "\meta", [string]$CodeWalker = "\codewalker-gen9", - [int]$Limit = 0 + # A negative limit used to stop before the first blob: `$Limit` is true for any non-zero value, so the loop + # broke at once and the run ended with 'pso ok 0 failed 0' and an empty failures.txt. + [ValidateRange(0, 2147483647)][int]$Limit = 0 ) $ErrorActionPreference = "Stop" try { (Get-Process -Id $PID).PriorityClass = "BelowNormal" } catch {} From e911edcb2b77b5ba0d27f419f36713cd75ff9819 Mon Sep 17 00:00:00 2001 From: evilclanker9000 <45567075+evilclanker9000@users.noreply.github.com> Date: Mon, 23 Nov 2026 14:20:13 +0100 Subject: [PATCH 2/3] tests: meta_to_xml -Limit -5 converts nothing, exit 0 (the negative-limit bug) Runs the script against synthesized stand-ins for the three CodeWalker DLLs, so it needs no CodeWalker, no game files and no GPU. The fixture and the DLL stub builder move to module level for reuse; the existing path test keeps its fixture unchanged. --- tests/test_meta_to_xml_paths.py | 49 +++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/tests/test_meta_to_xml_paths.py b/tests/test_meta_to_xml_paths.py index aa43b6685b..cdd003f754 100644 --- a/tests/test_meta_to_xml_paths.py +++ b/tests/test_meta_to_xml_paths.py @@ -31,18 +31,35 @@ """ +def build_stub_deps(deps): + """Compile stand-ins for the three CodeWalker DLLs with PowerShell's own compiler.""" + deps.mkdir(parents=True, exist_ok=True) + return subprocess.run( + [*POWERSHELL, "-Command", "-"], cwd=deps, input=BUILD_STUB + "\n", + capture_output=True, text=True, timeout=60, + ) + + +def write_two_pso_blobs(carve): + """Two synthetic PSIN blobs in a carve folder: /archive/index.json plus the two .bin files.""" + archive = carve / "archive" + archive.mkdir(parents=True) + (archive / "index.json").write_text(json.dumps({"files": [ + {"head": "5053494e", "off": 0}, + {"head": "5053494e", "off": 16}, + ]}), encoding="utf-8") + (archive / "000000000000.bin").write_bytes(b"PSIN\x00") + (archive / "000000000010.bin").write_bytes(b"PSIN\x00") + return archive + + @unittest.skipUnless(os.name == "nt", "Windows PowerShell 5.1 script") class MetaToXmlPathsTest(unittest.TestCase): def test_plain_bracketed_and_unicode_paths(self): with tempfile.TemporaryDirectory() as tmp: root = Path(tmp) deps = root / "deps" - deps.mkdir() - # Use PowerShell's built-in compiler to stand in for the three DLLs. - build = subprocess.run( - [*POWERSHELL, "-Command", "-"], cwd=deps, input=BUILD_STUB + "\n", - capture_output=True, text=True, timeout=30, - ) + build = build_stub_deps(deps) self.assertEqual(build.returncode, 0, build.stdout + build.stderr) cases = ( @@ -80,6 +97,26 @@ def test_plain_bracketed_and_unicode_paths(self): self.assertTrue(failures[1].startswith(f"{archive_name}\\000000000008 pso : "), failures[1]) self.assertEqual(failures[2], f"{archive_name}\\000000000010 pso : synthetic parser failure") + def test_negative_limit_is_refused_before_anything_is_converted(self): + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + deps = build_stub_deps(root / "deps") + self.assertEqual(deps.returncode, 0, deps.stdout + deps.stderr) + carve, out = root / "carve", root / "out" + write_two_pso_blobs(carve) + + result = subprocess.run( + [*POWERSHELL, "-File", str(SCRIPT), "-Carve", str(carve), "-Out", str(out), + "-CodeWalker", str(root / "deps"), "-Limit", "-5"], + capture_output=True, text=True, timeout=60, + ) + # A negative limit is true in PowerShell, so the old guard broke out before the first blob and the run + # ended with "pso ok 0 failed 0" and an empty failures.txt. + self.assertNotEqual(result.returncode, 0, result.stdout) + self.assertIn("Limit", result.stderr) + self.assertNotIn("pso ok", result.stdout) + self.assertFalse(out.exists(), "the value is refused before the output folder is made") + if __name__ == "__main__": unittest.main() From a5ddf0c52207ba6edae07945dedfa29af52b175f Mon Sep 17 00:00:00 2001 From: evilclanker9000 <45567075+evilclanker9000@users.noreply.github.com> Date: Mon, 23 Nov 2026 14:20:34 +0100 Subject: [PATCH 3/3] tests: meta_to_xml -Limit 0 still converts every blob The default 0 must keep meaning 'no limit', so the new range cannot turn the documented default into a refusal. --- tests/test_meta_to_xml_paths.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_meta_to_xml_paths.py b/tests/test_meta_to_xml_paths.py index cdd003f754..fea3a6a6f7 100644 --- a/tests/test_meta_to_xml_paths.py +++ b/tests/test_meta_to_xml_paths.py @@ -117,6 +117,23 @@ def test_negative_limit_is_refused_before_anything_is_converted(self): self.assertNotIn("pso ok", result.stdout) self.assertFalse(out.exists(), "the value is refused before the output folder is made") + def test_zero_limit_still_converts_every_blob(self): + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + deps = build_stub_deps(root / "deps") + self.assertEqual(deps.returncode, 0, deps.stdout + deps.stderr) + carve, out = root / "carve", root / "out" + write_two_pso_blobs(carve) + + result = subprocess.run( + [*POWERSHELL, "-File", str(SCRIPT), "-Carve", str(carve), "-Out", str(out), + "-CodeWalker", str(root / "deps"), "-Limit", "0"], + capture_output=True, text=True, timeout=60, + ) + # 0 is the default and means "every blob"; the new range must not turn it into a refusal. + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + self.assertIn("pso ok 2 failed 0", result.stdout) + if __name__ == "__main__": unittest.main()