plugins/tools/plugin_sigma_snow_weather.py
unimatrixgit c11f0031fc
Some checks failed
Sigma Snow Weather Build / sigma-snow-weather (push) Successful in 1m26s
DuneRealms Plugin CI / plugins (push) Successful in 9m3s
DuneRealms Resourcepack CI / resourcepack (push) Failing after 14s
Require precipitation for Sigma soil snowfall
2026-12-03 20:55:43 +01:00

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)