mirror of
https://github.com/notwa/mm
synced 2024-11-05 02:19:03 -08:00
40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
def try_scene(f):
|
|
f.seek(0)
|
|
while True:
|
|
command = f.read(8)
|
|
if len(command) == 0:
|
|
return False
|
|
if command[2:4] != b'\x00\x00':
|
|
return False
|
|
if command[0] > 0x1e:
|
|
return False
|
|
if command[4] != 0x02 and command[4] != 0x00:
|
|
if command[0] not in (0x05, 0x10, 0x11, 0x12):
|
|
return False
|
|
if command == b'\x14\x00\x00\x00\x00\x00\x00\x00':
|
|
return True
|
|
|
|
def try_room(f):
|
|
# note: doesn't detect syotes_room_0 because it's missing a header
|
|
f.seek(0)
|
|
while True:
|
|
command = f.read(8)
|
|
if len(command) == 0:
|
|
return False
|
|
if command[2:4] != b'\x00\x00':
|
|
return False
|
|
if command[0] > 0x1e:
|
|
return False
|
|
if command[4] != 0x03 and command[4] != 0x00:
|
|
if command[0] not in (0x05, 0x10, 0x11, 0x12):
|
|
return False
|
|
if command == b'\x14\x00\x00\x00\x00\x00\x00\x00':
|
|
return True
|
|
|
|
def detect_format(f, fn=None):
|
|
if try_scene(f):
|
|
return 'scene'
|
|
if try_room(f):
|
|
return 'room'
|
|
|
|
return None
|