40 lines
1.6 KiB
Python
40 lines
1.6 KiB
Python
"""Build and assemble the Sigma precipitation guard without altering its generator."""
|
|
import argparse
|
|
import hashlib
|
|
from pathlib import Path
|
|
from zipfile import ZipFile
|
|
|
|
BASELINE = '26e314bad6f9573a98a40569b0d85a0d53f2b45a7061c3199eaa9a8cac8edaa1'
|
|
CLASS = 'com/example/duneterrain/PlanetSoil.class'
|
|
|
|
|
|
def extract(compiled, output):
|
|
with ZipFile(compiled) as jar, ZipFile(output, 'x') as patch:
|
|
patch.writestr(CLASS, jar.read(CLASS))
|
|
|
|
|
|
def assemble(baseline, patch, output):
|
|
if hashlib.sha256(baseline.read_bytes()).hexdigest() != BASELINE:
|
|
raise ValueError('Expected the exact retained Sigma Terrain')
|
|
with ZipFile(baseline) as original, ZipFile(patch) as updates:
|
|
entries = original.namelist()
|
|
if len(set(entries)) != len(entries) or updates.namelist() != [CLASS]:
|
|
raise ValueError('Expected only the reviewed soil class')
|
|
replacement = updates.read(CLASS)
|
|
if not replacement.startswith(b'\xca\xfe\xba\xbe') or replacement == original.read(CLASS):
|
|
raise ValueError('Invalid or unchanged soil patch')
|
|
with ZipFile(output, 'x') as candidate:
|
|
for info in original.infolist():
|
|
candidate.writestr(info, replacement if info.filename == CLASS else original.read(info))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('input', type=Path)
|
|
parser.add_argument('output', type=Path)
|
|
parser.add_argument('--baseline', type=Path)
|
|
args = parser.parse_args()
|
|
if args.baseline is None:
|
|
extract(args.input, args.output)
|
|
else:
|
|
assemble(args.baseline, args.input, args.output)
|

Staff