1
0
Fork 0
mirror of https://github.com/notwa/mm synced 2024-05-18 05:23:22 -07:00
mm/heuristics.py

41 lines
1.1 KiB
Python
Raw Normal View History

2015-03-04 04:37:37 -08:00
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