Mercurial > touhou
comparison pytouhou/formats/ecl.py @ 18:ca26a84916cb
Add preliminary ECL viewer/interpreter.
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Tue, 09 Aug 2011 11:40:48 +0200 |
parents | |
children | 6ebf9539c077 |
comparison
equal
deleted
inserted
replaced
17:d940d004b840 | 18:ca26a84916cb |
---|---|
1 from struct import pack, unpack | |
2 from pytouhou.utils.helpers import read_string | |
3 | |
4 from collections import namedtuple | |
5 | |
6 | |
7 class ECL(object): | |
8 def __init__(self): | |
9 self.main = [] | |
10 self.subs = [[]] | |
11 | |
12 | |
13 @classmethod | |
14 def read(cls, file): | |
15 sub_count, main_offset = unpack('<II', file.read(8)) | |
16 if file.read(8) != b'\x00\x00\x00\x00\x00\x00\x00\x00': | |
17 raise Exception #TODO | |
18 sub_offsets = unpack('<%s' % ('I' * sub_count), file.read(4 * sub_count)) | |
19 | |
20 ecl = cls() | |
21 ecl.subs = [] | |
22 ecl.main = [] | |
23 | |
24 # Read subs | |
25 for offset in sub_offsets: | |
26 file.seek(offset) | |
27 ecl.subs.append([]) | |
28 while True: | |
29 time, opcode = unpack('<IH', file.read(6)) | |
30 if time == 0xffffffff or opcode == 0xffff: | |
31 break | |
32 size, rank_mask, param_mask = unpack('<HHH', file.read(6)) | |
33 data = file.read(size - 12) | |
34 #TODO: unpack data | |
35 ecl.subs[-1].append((time, opcode, rank_mask, param_mask, data)) | |
36 | |
37 # Read main | |
38 file.seek(main_offset) | |
39 while True: | |
40 time, = unpack('<H', file.read(2)) | |
41 if time == 0xffff: | |
42 break | |
43 sub, instr_type, size = unpack('<HHH', file.read(6)) | |
44 data = file.read(size - 8) | |
45 if instr_type == 0: # Normal enemy | |
46 args = unpack('<ffIhHHH', data) | |
47 elif instr_type == 2: # Mirrored enemy | |
48 args = unpack('<ffIhHHH', data) | |
49 else: | |
50 print('ECL: Warning: unknown opcode %d (%r)' % (instr_type, data)) #TODO | |
51 args = (data,) | |
52 ecl.main.append((time, sub, instr_type, args)) | |
53 | |
54 return ecl | |
55 |