36 lines
1.5 KiB
Python
36 lines
1.5 KiB
Python
# Build GRP fixtures (tools/fixtures.py): GRP files written here from Ken Silverman's layout ("KenSilverman", count,
|
|
# 12-byte names + u32 sizes, files back to back), with the entries an independent Python reader sees.
|
|
# tests/gen/grp.luau { { name, data, entries = { { name, size, crc } }, files = { { name, data } } } }
|
|
import struct, zlib
|
|
|
|
|
|
def write(files):
|
|
out = bytearray(b"KenSilverman" + struct.pack("<I", len(files)))
|
|
for name, data in files:
|
|
out += struct.pack("<12sI", name.encode(), len(data))
|
|
for _, data in files:
|
|
out += data
|
|
return bytes(out)
|
|
|
|
|
|
def read(data):
|
|
n = struct.unpack_from("<I", data, 12)[0]
|
|
at, out = 16 + 16 * n, []
|
|
for i in range(n):
|
|
name, size = struct.unpack_from("<12sI", data, 16 + 16 * i)
|
|
out.append({"name": name.split(b"\0")[0].decode(), "size": size, "crc": zlib.crc32(data[at:at + size])})
|
|
at += size
|
|
return out
|
|
|
|
|
|
def generate(ctx):
|
|
rng = ctx.rng(23)
|
|
base = [("TILES000.ART", rng.randbytes(4000)), ("PALETTE.DAT", rng.randbytes(768 + 2 + 32 * 256)),
|
|
("GAME.CON", b"// con\ndefine X 1\n"), ("E1L1.MAP", rng.randbytes(900)), ("EMPTY.VOC", b""),
|
|
("TWELVECHARSX", b"12 bytes, no NUL")]
|
|
out = []
|
|
for name, files in (("duke", base), ("empty", []), ("one", base[:1])):
|
|
data = write(files)
|
|
out.append({"name": name, "data": data, "entries": read(data), "files": [{"name": n, "data": d} for n, d in files]})
|
|
ctx.emit("grp", out)
|