From f828cf27244d4bc3198db939e26b94c61b555649 Mon Sep 17 00:00:00 2001 From: unimatrixgit <95320811+unimatrixgit@users.noreply.github.com> Date: Sat, 5 Dec 2026 19:29:26 +0100 Subject: [PATCH] Assemble version-pinned Golden Path plugin overlays --- tools/plugin_golden_path.py | 86 +++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 tools/plugin_golden_path.py diff --git a/tools/plugin_golden_path.py b/tools/plugin_golden_path.py new file mode 100644 index 00000000..3683b1a0 --- /dev/null +++ b/tools/plugin_golden_path.py @@ -0,0 +1,86 @@ +"""Assemble the Golden Path graft over explicitly pinned retained plugin archives.""" +import argparse +import json +import os +from pathlib import Path +import subprocess +from tempfile import TemporaryDirectory + +from plugin_wild_update import digest, read_archive, write_archive + +MODULES = { + "gui": ( + "com/dunerealms/gui/", + ("PolQuestNpc",), + ("LetoQuestContacts", "LetoQuestContacts$Contact"), + "quest-categories.json", + ), + "jarvis": ( + "com/dunerealms/jarvis/", + ("ExchangeInventory", "JarvisTranslator", "QuestObservations", "StarterKitFlow"), + ("LetoQuestObservations", "LetoQuestObservations$Contact", "LetoQuestRewards", "LetoQuestRewards$Template"), + "leto-item-templates.json", + ), +} + + +def pinned(path, sha): + raw = path.read_bytes() + if digest(raw) != sha: + raise ValueError(f"Unexpected archive bytes: {path.name}") + return read_archive(raw) + + +def assemble(module, baseline, baseline_sha, donor, donor_sha, output, classpath): + prefix, retained, additions, resource = MODULES[module] + existing = pinned(baseline, baseline_sha) + compiled = pinned(donor, donor_sha) + if any(f"{prefix}{name}.class" in existing for name in additions): + raise ValueError("Golden Path classes already installed") + previous = json.loads(existing[resource]) if module == "gui" else None + if module == "gui": + updated = json.loads(compiled[resource]) + new_categories = updated.get("categories", []) + additions_rows = [category for category in new_categories if category.get("id") == "golden-path"] + if len(additions_rows) != 1 or { + **updated, "categories": [category for category in new_categories if category.get("id") != "golden-path"] + } != previous: + raise ValueError("Only the Golden Path category may be added") + elif resource in existing: + raise ValueError("Golden Path templates already installed") + + helper = Path(__file__).with_name("GoldenPathMerge.java") + with TemporaryDirectory() as temporary: + root = Path(temporary) + classes = root / "helper" + classes.mkdir() + subprocess.run(["javac", "-cp", classpath, "-d", str(classes), str(helper)], check=True) + separator = os.pathsep + for name in retained: + entry = prefix + name + ".class" + old, new, result = (root / f"{stem}.class" for stem in ("retained", "donor", "merged")) + old.write_bytes(existing[entry]) + new.write_bytes(compiled[entry]) + subprocess.run( + ["java", "-cp", str(classes) + separator + classpath, "GoldenPathMerge", str(old), str(new), str(result)], + check=True, + ) + existing[entry] = result.read_bytes() + for name in additions: + entry = prefix + name + ".class" + existing[entry] = compiled[entry] + existing[resource] = compiled[resource] + with output.open("xb") as target: + target.write(write_archive(existing)) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("module", choices=MODULES) + parser.add_argument("baseline", type=Path) + parser.add_argument("baseline_sha") + parser.add_argument("donor", type=Path) + parser.add_argument("donor_sha") + parser.add_argument("output", type=Path) + parser.add_argument("classpath", help="ASM core and tree JARs") + assemble(**vars(parser.parse_args()))