Mercurial > touhou
comparison pytouhou/formats/ecl.py @ 42:1b0ca2fb89f9
Refactor ECL parsing/etc.
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Thu, 18 Aug 2011 22:11:39 +0200 |
parents | 6ebf9539c077 |
children | 7195aaf95f6e |
comparison
equal
deleted
inserted
replaced
41:93c8dc2de923 | 42:1b0ca2fb89f9 |
---|---|
3 | 3 |
4 from collections import namedtuple | 4 from collections import namedtuple |
5 | 5 |
6 | 6 |
7 class ECL(object): | 7 class ECL(object): |
8 _instructions = {0: ('', 'noop?'), | |
9 1: ('I', 'delete?'), | |
10 2: ('Ii', 'relative_jump'), | |
11 3: ('Iii', 'relative_jump_ex'), | |
12 4: ('ii', 'set_counter'), | |
13 5: ('if', None), | |
14 6: ('ii', None), | |
15 8: ('if', None), | |
16 9: ('iff', None), | |
17 10: ('i', None), | |
18 13: ('iii', None), | |
19 14: ('iii', None), | |
20 15: ('iii', None), | |
21 16: ('iii', None), | |
22 17: ('iii', None), | |
23 18: ('i', None), | |
24 20: ('iff', None), | |
25 21: ('iff', None), | |
26 23: ('iff', None), | |
27 25: ('iffff', None), | |
28 26: ('i', None), | |
29 27: ('ii', None), | |
30 28: ('ff', None), | |
31 29: ('ii', None), | |
32 30: ('ii', None), | |
33 31: ('ii', None), | |
34 32: ('ii', None), | |
35 33: ('ii', None), | |
36 34: ('ii', None), | |
37 35: ('iif', None), | |
38 36: ('', 'return?'), | |
39 39: ('iiiii', None), | |
40 43: ('fff', 'set_position'), | |
41 45: ('ff', 'set_angle_and_speed'), | |
42 46: ('f', 'set_rotation_speed'), | |
43 47: ('f', 'set_speed'), | |
44 48: ('f', 'set_acceleration'), | |
45 49: ('ff', None), | |
46 50: ('ff', None), | |
47 51: ('ff', 'set_speed_towards_player'), | |
48 52: ('iff', None), | |
49 56: ('iffi', None), | |
50 57: ('ifff', 'move_to'), | |
51 59: ('iffi', None), | |
52 61: ('i', None), | |
53 63: ('i', None), | |
54 65: ('ffff', None), | |
55 66: ('', None), | |
56 67: ('hhiiffffi', 'set_bullet_attributes'), | |
57 68: ('hhiiffffi', 'set_bullet_attributes2'), | |
58 69: ('hhiiffffi', 'set_bullet_attributes3'), | |
59 70: ('hhiiffffi', 'set_bullet_attributes4'), | |
60 74: ('hhiiffffi', 'set_bullet_attributes5'), | |
61 75: ('hhiiffffi', 'set_bullet_attributes6'), | |
62 76: ('i', None), | |
63 77: ('i', 'set_bullet_interval'), | |
64 78: ('', None), | |
65 79: ('', None), | |
66 81: ('fff', 'set_bullet_launch_offset'), | |
67 82: ('iiiiffff', None), | |
68 83: ('', None), | |
69 84: ('i', None), | |
70 85: ('hhfiffffiiiiii', None), | |
71 86: ('hhffifffiiiiii', None), | |
72 87: ('i', None), | |
73 88: ('if', None), | |
74 90: ('iiii', None), | |
75 92: ('i', None), | |
76 #93: set_spellcard, a string is there | |
77 94: ('', None), | |
78 95: ('ifffhhi', None), | |
79 96: ('', None), | |
80 97: ('i', 'set_anim'), | |
81 98: ('hhhhhh', 'set_multiple_anims'), | |
82 99: ('ii', None), | |
83 100: ('i', 'set_death_anim'), | |
84 101: ('i', 'set_boss_mode?'), | |
85 102: ('iffff', None), | |
86 103: ('fff', 'set_enemy_hitbox'), | |
87 104: ('i', None), | |
88 105: ('i', 'set_vulnerable'), | |
89 106: ('i', 'play_sound'), | |
90 107: ('i', None), | |
91 108: ('i', 'set_death_callback?'), | |
92 109: ('ii', None), | |
93 111: ('i', None), | |
94 112: ('i', None), | |
95 113: ('i', 'set_low_life_trigger'), | |
96 114: ('i', 'set_low_life_callback'), | |
97 115: ('i', 'set_timeout'), | |
98 116: ('i', None), | |
99 117: ('i', None), | |
100 118: ('iihh', None), | |
101 119: ('i', None), | |
102 120: ('i', None), | |
103 121: ('ii', None), | |
104 122: ('i', None), | |
105 123: ('i', None), | |
106 124: ('i', None), | |
107 125: ('', None), | |
108 126: ('i', 'set_remaining_lives'), | |
109 127: ('i', None), | |
110 128: ('i', None), | |
111 129: ('ii', None), | |
112 130: ('i', None), | |
113 131: ('ffiiii', None), | |
114 132: ('i', None), | |
115 133: ('', None), | |
116 134: ('', None), | |
117 135: ('i', None)} #TODO | |
118 | |
8 def __init__(self): | 119 def __init__(self): |
9 self.main = [] | 120 self.main = [] |
10 self.subs = [[]] | 121 self.subs = [[]] |
11 | 122 |
12 | 123 |
29 time, opcode = unpack('<IH', file.read(6)) | 140 time, opcode = unpack('<IH', file.read(6)) |
30 if time == 0xffffffff or opcode == 0xffff: | 141 if time == 0xffffffff or opcode == 0xffff: |
31 break | 142 break |
32 size, rank_mask, param_mask = unpack('<HHH', file.read(6)) | 143 size, rank_mask, param_mask = unpack('<HHH', file.read(6)) |
33 data = file.read(size - 12) | 144 data = file.read(size - 12) |
34 #TODO: unpack data | 145 if opcode in cls._instructions: |
35 ecl.subs[-1].append((time, opcode, rank_mask, param_mask, data)) | 146 args = unpack('<%s' % cls._instructions[opcode][0], data) |
147 else: | |
148 args = (data, ) | |
149 print('Warning: unknown opcode %d' % opcode) #TODO | |
150 ecl.subs[-1].append((time, opcode, rank_mask, param_mask, args)) | |
36 | 151 |
37 # Read main | 152 # Read main |
38 file.seek(main_offset) | 153 file.seek(main_offset) |
39 while True: | 154 while True: |
40 time, = unpack('<H', file.read(2)) | 155 time, = unpack('<H', file.read(2)) |