MC/tools/patch-worm-transport.py
2026-11-27 23:43:05 +00:00

27 lines
1.8 KiB
Python

"""Preserve the exact installed Core and Connector; change only approved worm classes/policy."""
import pathlib,sys,zipfile,hashlib,json
source,classes,resources,output=map(pathlib.Path,sys.argv[1:5]);expected,mode=sys.argv[5:7]
assert mode in ('core','jarvis') and not output.exists()
assert hashlib.sha256(source.read_bytes()).hexdigest()==expected
with zipfile.ZipFile(source) as z:
entries={n:z.read(n) for n in z.namelist()};assert len(entries)==len(z.namelist())
before=dict(entries)
if mode=='core':
prefix='com/example/dunerealms/'
allowed={prefix+n+'.class' for n in ['SandwormMobs','SandwormModel','WormHitboxes','WormTransport','WormTransport$Rig']}
assert prefix+'DuneCore.class' in entries
for name in allowed:
data=(classes/name).read_bytes();assert data[:4]==b'\xca\xfe\xba\xbe' and int.from_bytes(data[6:8],'big')==65;entries[name]=data
descriptor=entries['plugin.yml'].decode();assert 'worms2' not in descriptor
import re
entries['plugin.yml']=re.sub(r'(?m)^(version: [^\r\n]+)',r'\1-worms2',descriptor).encode()
assert entries[prefix+'DuneCore.class']==before[prefix+'DuneCore.class']
else:
allowed={'item-templates.json'};entries['item-templates.json']=(resources/'item-templates.json').read_bytes()
entries['plugin.yml']=entries['plugin.yml'].decode().replace('version: 0.5.30','version: 0.5.31').encode()
assert entries['plugin.yml']!=before['plugin.yml']
allowed.add('plugin.yml')
assert all(entries[name]==data for name,data in before.items() if name not in allowed)
with zipfile.ZipFile(output,'x',zipfile.ZIP_DEFLATED) as z:
for name,data in entries.items():z.writestr(name,data)
print(json.dumps({'mode':mode,'sha256':hashlib.sha256(output.read_bytes()).hexdigest(),'changed':[n for n in before if entries[n]!=before[n]],'added':[n for n in entries if n not in before],'worldGenerationChanged':False}))