Last active
August 7, 2024 04:43
-
-
Save heisvoid/f6d4166437429fe10e8c to your computer and use it in GitHub Desktop.
Verify sprite type 4 in TWG
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 -*- | |
| # Verity sprite file | |
| import argparse | |
| import struct | |
| import os | |
| parser = argparse.ArgumentParser(description='Check sprite file.') | |
| parser.add_argument('-f', required=True, help='sprite 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) | |
| 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) | |
| # number of sprites maybe | |
| bytes = f.read(2) | |
| bytes = struct.unpack('<H', bytes) | |
| num = bytes[0] | |
| # zero padding | |
| f.seek(60, os.SEEK_CUR) | |
| for n in range(num): | |
| bytes = f.read(4) | |
| bytes = struct.unpack('<I', bytes) | |
| len = bytes[0] | |
| # width maybe | |
| bytes = f.read(2) | |
| bytes = struct.unpack('<H', bytes) | |
| width = bytes[0] | |
| # height maybe | |
| bytes = f.read(2) | |
| bytes = struct.unpack('<H', bytes) | |
| height = bytes[0] | |
| assert (width * height + 4) == len | |
| f.seek(4, os.SEEK_CUR) | |
| # unknown | |
| f.read(2) | |
| f.read(2) | |
| f.seek(16, os.SEEK_CUR) | |
| bytes = f.read(2) | |
| bytes = struct.unpack('<H', bytes) | |
| assert bytes[0] == width | |
| bytes = f.read(2) | |
| bytes = struct.unpack('<H', bytes) | |
| assert bytes[0] == height | |
| f.read(len - 4) | |
| assert f.tell() == file_len |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment