48 lines
2.2 KiB
Python
48 lines
2.2 KiB
Python
import hashlib
|
|
from pathlib import Path
|
|
import sys
|
|
import zipfile
|
|
|
|
BASELINE_SHA256 = 'bad1022e2dab960808641fea15e3a6968d4aafeaaa46bedf4ee5c5e87bbd3534'
|
|
BASELINE_PACK = '25ae69ae7198002ebff65b1eafbb454be7df235f51cdc46bb6233aa0b3ceec7a'
|
|
RETAINED_TREE = '1ad55afb10d0876e584a9ca6530c622cb0364e724c6a8d3d6b25259b9ae43e78'
|
|
DESCRIPTOR_SHA256 = '7c0d29f057b9053cd78cd479b9a4a33d43346733414dcaca3c52123f73f8e175'
|
|
JERBOA_CLASS = 'com/example/duneterrain/JerboaMobs.class'
|
|
ASSETS = {
|
|
*(f'assets/dunerealms/models/entity/jerboa{pose}.json' for pose in ('', '_curled', '_walk_left', '_walk_right')),
|
|
'assets/dunerealms/textures/entity/jerboa.png',
|
|
}
|
|
|
|
|
|
def archive(path):
|
|
with zipfile.ZipFile(path) as file:
|
|
names = [name for name in file.namelist() if not name.endswith('/')]
|
|
if len(set(names)) != len(names):
|
|
raise ValueError('Duplicate archive entry')
|
|
return {name: file.read(name) for name in names}
|
|
|
|
|
|
def verify_terrain(path):
|
|
entries = archive(path)
|
|
if JERBOA_CLASS not in entries or hashlib.sha256(entries['plugin.yml']).hexdigest() != DESCRIPTOR_SHA256:
|
|
raise ValueError('Unexpected Jerboa Terrain identity')
|
|
rows = [name + '\0' + hashlib.sha256(data).hexdigest() for name, data in sorted(entries.items())
|
|
if name not in {JERBOA_CLASS, 'plugin.yml'}]
|
|
if hashlib.sha256('\n'.join(rows).encode()).hexdigest() != RETAINED_TREE:
|
|
raise ValueError('Terrain changes must be limited to JerboaMobs and the version label')
|
|
|
|
|
|
def verify_pack(before, after):
|
|
if hashlib.sha256(before.read_bytes()).hexdigest() != BASELINE_PACK:
|
|
raise ValueError('Unexpected Arrakis resource pack baseline')
|
|
old, new = archive(before), archive(after)
|
|
if old.keys() != new.keys() or {name for name in old if old[name] != new[name]} != ASSETS:
|
|
raise ValueError('Expected exactly four redesigned Jerboa poses and one texture')
|
|
assets = Path('network/resource-pack/central/legacy')
|
|
if any(new[name] != (assets / name).read_bytes() for name in ASSETS):
|
|
raise ValueError('Jerboa art differs from committed inputs')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
verify_terrain(Path(sys.argv[1]))
|
|
verify_pack(Path(sys.argv[2]), Path(sys.argv[3]))
|

Staff