72 lines
2.9 KiB
Python
72 lines
2.9 KiB
Python
"""Build the two immutable resource packs from reviewed vanilla tile exports."""
|
|
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import struct
|
|
|
|
from plugin_supplied_item_art import read_pack
|
|
from plugin_wild_update import write_archive
|
|
|
|
|
|
BASE_SOURCE = "e9c8db19a000dea4625db70e724f1e615ceebf89"
|
|
BASE = {
|
|
"arrakis": "09fc179ca0ecc018a6906e2cc948dd671b19f1d7312c0819bd99bbedfbd87416",
|
|
"fleet": "ec4b46f0c6362cd4284a18e84b799c850b44f2bf14a36589af3c3bcaa8f7f595",
|
|
}
|
|
CATALOG = Path(__file__).with_name("realistic-stone-family-paths.json")
|
|
PNG = bytes.fromhex("89504e470d0a1a0a0000000d49484452")
|
|
|
|
|
|
def sha(data):
|
|
return hashlib.sha256(data).hexdigest()
|
|
|
|
|
|
def assemble(variant, baseline, export, receipt_sha, output, require_full=True):
|
|
if sha(baseline.read_bytes()) != BASE[variant]:
|
|
raise ValueError(f"{variant} pack differs from the accepted Soft Dune preimage")
|
|
receipt = (export / "stone-family.json").read_bytes()
|
|
if sha(receipt) != receipt_sha:
|
|
raise ValueError("Texture export receipt differs from the accepted hash")
|
|
manifest = json.loads(receipt)
|
|
catalog = set(json.loads(CATALOG.read_bytes()))
|
|
names = set(manifest["entries"])
|
|
if manifest["size"] != 256 or not names or not names <= catalog or (require_full and names != catalog):
|
|
raise ValueError("Unexpected vanilla block texture scope")
|
|
retained = read_pack(baseline)
|
|
updated = {}
|
|
for key in sorted(names):
|
|
data = (export / key).read_bytes()
|
|
if sha(data) != manifest["entries"][key]["sha256"]:
|
|
raise ValueError(f"Texture differs from the verified export: {key}")
|
|
if not data.startswith(PNG) or struct.unpack(">II", data[16:24]) != (256, 256):
|
|
raise ValueError(f"Invalid tile dimensions: {key}")
|
|
if key + ".mcmeta" in retained:
|
|
raise ValueError(f"Review inherited animation metadata before replacing {key}")
|
|
updated[key] = data
|
|
final = retained | updated
|
|
payload = write_archive(final)
|
|
with output.open("xb") as file:
|
|
file.write(payload)
|
|
if read_pack(output) != final:
|
|
raise ValueError("Unexpected ZIP entry after material merge")
|
|
return {
|
|
"filename": output.name,
|
|
"variant": variant,
|
|
"textureCount": len(updated),
|
|
"changed": sum(retained.get(k) != v for k, v in updated.items()),
|
|
"sha1": hashlib.sha1(payload).hexdigest(),
|
|
"sha256": sha(payload),
|
|
}
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("variant", choices=BASE)
|
|
parser.add_argument("baseline", type=Path)
|
|
parser.add_argument("export", type=Path)
|
|
parser.add_argument("receipt_sha")
|
|
parser.add_argument("output", type=Path)
|
|
parser.add_argument("--allow-partial", action="store_false", dest="require_full")
|
|
print(json.dumps(assemble(**vars(parser.parse_args())), indent=2))
|

Staff