comparison pytouhou/formats/ecl.py @ 95:e2d8f2a56ea4

Handle ECL opcodes with string.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 04 Sep 2011 12:52:47 -0700
parents fda176f07d6d
children 54929d495654
comparison
equal deleted inserted replaced
94:ca571697ec83 95:e2d8f2a56ea4
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ## GNU General Public License for more details. 12 ## GNU General Public License for more details.
13 ## 13 ##
14 14
15 15
16 from struct import pack, unpack 16 from struct import pack, unpack, calcsize
17 from pytouhou.utils.helpers import read_string 17 from pytouhou.utils.helpers import read_string
18 18
19 from pytouhou.utils.helpers import get_logger 19 from pytouhou.utils.helpers import get_logger
20 20
21 logger = get_logger(__name__) 21 logger = get_logger(__name__)
88 86: ('hhffffffiiiiii', 'laser2'), 88 86: ('hhffffffiiiiii', 'laser2'),
89 87: ('i', 'set_upcoming_id'), 89 87: ('i', 'set_upcoming_id'),
90 88: ('if','alter_laser_angle'), 90 88: ('if','alter_laser_angle'),
91 90: ('iiii', None), 91 90: ('iiii', None),
92 92: ('i', None), 92 92: ('i', None),
93 #93: set_spellcard, a string is there 93 93: ('hhs', 'set_spellcard'),
94 94: ('', 'end_spellcard'), 94 94: ('', 'end_spellcard'),
95 95: ('ifffhhi', None), 95 95: ('ifffhhi', None),
96 96: ('', None), 96 96: ('', None),
97 97: ('i', 'set_anim'), 97 97: ('i', 'set_anim'),
98 98: ('hhhhhxx', 'set_multiple_anims'), 98 98: ('hhhhhxx', 'set_multiple_anims'),
163 if time == 0xffffffff or opcode == 0xffff: 163 if time == 0xffffffff or opcode == 0xffff:
164 break 164 break
165 size, rank_mask, param_mask = unpack('<HHH', file.read(6)) 165 size, rank_mask, param_mask = unpack('<HHH', file.read(6))
166 data = file.read(size - 12) 166 data = file.read(size - 12)
167 if opcode in cls._instructions: 167 if opcode in cls._instructions:
168 args = unpack('<%s' % cls._instructions[opcode][0], data) 168 fmt = '<%s' % cls._instructions[opcode][0]
169 if fmt.endswith('s'):
170 fmt = fmt[:-1]
171 fmt = '%s%ds' % (fmt, size - 12 - calcsize(fmt))
172 args = unpack(fmt, data)
173 if fmt.endswith('s'):
174 args = args[:-1] + (args[-1].decode('shift_jis'),)
169 else: 175 else:
170 args = (data, ) 176 args = (data, )
171 logger.warn('unknown opcode %d', opcode) 177 logger.warn('unknown opcode %d', opcode)
172 178
173 ecl.subs[-1].append((time, opcode, rank_mask, param_mask, args)) 179 ecl.subs[-1].append((time, opcode, rank_mask, param_mask, args))