Created
August 7, 2024 13:21
-
-
Save heisvoid/1b1331b264d3b063b062c1347645d07c to your computer and use it in GitHub Desktop.
Verify sprite type 5 in TWG(The War of Genesis 2).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import argparse | |
import struct | |
import os | |
parser = argparse.ArgumentParser(description='Verify sprites.') | |
parser.add_argument('-f', required=True, help='sprites file', dest='spr') | |
args = parser.parse_args() | |
with open(args.spr, 'rb') as f: | |
f.seek(0, os.SEEK_END) | |
file_len = f.tell() | |
f.seek(0, os.SEEK_SET) | |
# header | |
bytes = f.read(0x40) | |
assert b'New Fast&Compress Sprite Ver3.0 for 13h mode!!!. SOFTMAX(C)1994.' == bytes | |
f.seek(2, os.SEEK_CUR) | |
# total number of sprites | |
buf = f.read(2) | |
buf = struct.unpack('<H', buf) | |
num = buf[0] | |
# zero padding | |
f.seek(60, os.SEEK_CUR) | |
for n in range(num): | |
# total length of compressed pixel data | |
buf = f.read(4) | |
buf = struct.unpack('<I', buf) | |
length = buf[0] | |
# width | |
buf = f.read(2) | |
buf = struct.unpack('<H', buf) | |
width = buf[0] | |
assert 320 >= width | |
# height | |
buf = f.read(2) | |
buf = struct.unpack('<H', buf) | |
height = buf[0] | |
assert 200 >= height | |
# unknown | |
f.seek(24, os.SEEK_CUR) | |
# number of compressed chunks | |
buf = f.read(2) | |
buf = struct.unpack('<H', buf) | |
chunks = buf[0] | |
l = 0 | |
for c in range(chunks): | |
assert f.tell() < file_len | |
buf = f.read(2) | |
buf = struct.unpack('<H', buf) | |
blanks = buf[0] | |
assert f.tell() < file_len | |
buf = f.read(1) | |
buf = struct.unpack('<B', buf) | |
i = buf[0] | |
assert f.tell() < file_len | |
buf = f.read(1) | |
buf = struct.unpack('<B', buf) | |
j = buf[0] | |
f.read(4 * i + j) | |
l = l + 2 + 1 + 1 + 4 * i + j | |
assert (l + 2) == length | |
assert f.tell() == file_len |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment