51 lines
2.2 KiB
Python
51 lines
2.2 KiB
Python
"""Assemble the Citizens load barrier onto retained Wild Update JARs."""
|
|
import argparse
|
|
from pathlib import Path
|
|
|
|
from plugin_wild_update import BRIDGE, digest, read_archive, write_archive
|
|
|
|
SHARED = {BRIDGE + ".class", BRIDGE + "$Contact.class"}
|
|
EXTRA = {
|
|
"DuneLobby": {"com/example/dunelobby/DuneLobby.class"},
|
|
"DuneNPC": {"com/example/dunenpc/DuneNPC.class"},
|
|
}
|
|
MODULES = ("DuneLobby", "DuneNPC", "DuneRealmsGUI", "DuneTerrain", "JarvisConnector")
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
commands = parser.add_subparsers(dest="action", required=True)
|
|
pack = commands.add_parser("extract")
|
|
for path in ("npc", "lobby", "output"):
|
|
pack.add_argument(path, type=Path)
|
|
install = commands.add_parser("assemble")
|
|
install.add_argument("module", choices=MODULES)
|
|
for path in ("baseline", "overlay", "output"):
|
|
install.add_argument(path, type=Path)
|
|
install.add_argument("baseline_sha")
|
|
install.add_argument("overlay_sha")
|
|
args = parser.parse_args()
|
|
if args.action == "extract":
|
|
npc = read_archive(args.npc.read_bytes())
|
|
lobby = read_archive(args.lobby.read_bytes())
|
|
if any(npc[name] != lobby[name] for name in SHARED):
|
|
raise ValueError("Shared Citizens bridge differs by compiler input")
|
|
output = ({name: npc[name] for name in SHARED | EXTRA["DuneNPC"]}
|
|
| {name: lobby[name] for name in EXTRA["DuneLobby"]})
|
|
else:
|
|
baseline, delta = args.baseline.read_bytes(), args.overlay.read_bytes()
|
|
if digest(baseline) != args.baseline_sha or digest(delta) != args.overlay_sha:
|
|
raise ValueError("Unexpected Wild Update baseline or bridge overlay")
|
|
output, overlay = read_archive(baseline), read_archive(delta)
|
|
required = SHARED | EXTRA.get(args.module, set())
|
|
if (set(overlay) != SHARED | EXTRA["DuneNPC"] | EXTRA["DuneLobby"] or not required <= output.keys()):
|
|
raise ValueError("Expected bounded Citizens-ready overlay and existing Wild bridge")
|
|
output.update({name: overlay[name] for name in required})
|
|
data = write_archive(output)
|
|
with args.output.open("xb") as file:
|
|
file.write(data)
|
|
print(digest(data))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|

Staff