Skip to content

Instantly share code, notes, and snippets.

@heisvoid
Last active August 29, 2015 14:02
Show Gist options
  • Save heisvoid/ae34b3e777067a926556 to your computer and use it in GitHub Desktop.
Save heisvoid/ae34b3e777067a926556 to your computer and use it in GitHub Desktop.
Verify /characte/*.nc2, *.bcr, *.wcr, *.mar, *.rcr in TWG
# -*- coding: utf-8 -*-
# .nc2, .bcr, .wcr, .mar, .rcr
import argparse
import struct
import os
parser = argparse.ArgumentParser(description='Verify sprite file.')
parser.add_argument('-f', required=True, help='sprite file', dest='spr')
args = parser.parse_args()
bn = os.path.basename(args.spr)
ext = os.path.splitext(bn)
ext = ext[1]
kind = 0
if ".nc2" == ext:
kind = 0
elif ".bcr" == ext or ".wcr" == ext or ".mar" == ext:
kind = 1
elif ".rcr" == ext:
kind = 2
else:
assert False, "can not recognize format"
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 'New Fast&Compress Sprite Ver3.0 for 13h mode!!!. SOFTMAX(C)1994.' == bytes
f.seek(2, os.SEEK_CUR)
# unknown
f.read(2)
# zero padding
f.seek(60, os.SEEK_CUR)
if 0 == kind:
bytes = f.read(1)
bytes = struct.unpack('<B', bytes)
i = bytes[0]
if 0 != i:
for i in range(4):
for j in range(2):
f.read(1)
f.read(1)
f.read(1)
f.read(1)
f.read(1)
i = 0
while 44 > i:
bytes = f.read(4)
bytes = struct.unpack('<I', bytes)
len = bytes[0]
f.read(1)
f.seek(1, os.SEEK_CUR)
f.read(1)
f.seek(1, os.SEEK_CUR)
f.read(1)
f.seek(1, os.SEEK_CUR)
f.read(1)
f.seek(1, os.SEEK_CUR)
if 2 > kind:
f.read(1)
f.read(1)
if 1 == kind:
f.read(1)
f.read(1)
f.read(1)
f.read(len)
if 0 < kind:
tmp = ((i + 1) % 11) % 8
if 0 == tmp:
i = i + 3
i = i + 1
assert f.tell() == file_len
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment