comparison pytouhou/formats/exe.py @ 235:e59bd7979ddc

Do a little cleanup, and fix PCB SHT usage.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 31 Dec 2011 16:31:10 +0100
parents 1c24a6d93c1b
children 741860192b56
comparison
equal deleted inserted replaced
234:3cbfa2c11dec 235:e59bd7979ddc
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of 11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ## GNU General Public License for more details. 13 ## GNU General Public License for more details.
14 ## 14 ##
15 15
16 from copy import copy
16 from struct import Struct, unpack 17 from struct import Struct, unpack
18
17 from pytouhou.utils.pe import PEFile 19 from pytouhou.utils.pe import PEFile
18 20
19 from pytouhou.utils.helpers import get_logger 21 from pytouhou.utils.helpers import get_logger
20 22
21 logger = get_logger(__name__) 23 logger = get_logger(__name__)
123 pe_file = PEFile(file) 125 pe_file = PEFile(file)
124 126
125 character_records_va = list(cls.find_character_defs(pe_file))[0] 127 character_records_va = list(cls.find_character_defs(pe_file))[0]
126 128
127 characters = [] 129 characters = []
128 shots_offsets = [] 130 shots_offsets = {}
129 for character in xrange(4): 131 for character in xrange(4):
130 sht = cls() 132 sht = cls()
131 133
132 pe_file.seek_to_va(character_records_va + 6*4*character) 134 pe_file.seek_to_va(character_records_va + 6*4*character)
133 135
138 sht.horizontal_vertical_speed = speed 140 sht.horizontal_vertical_speed = speed
139 sht.horizontal_vertical_focused_speed = speed_focused 141 sht.horizontal_vertical_focused_speed = speed_focused
140 sht.diagonal_speed = speed * SQ2 142 sht.diagonal_speed = speed * SQ2
141 sht.diagonal_focused_speed = speed_focused * SQ2 143 sht.diagonal_focused_speed = speed_focused * SQ2
142 144
143 # Read from “push” operand 145 # Characters might have different shot types whether they are
144 pe_file.seek_to_va(shots_func_offset + 4) 146 # focused or not, but properties read earlier apply to both modes.
145 offset = unpack('<I', file.read(4))[0] 147 focused_sht = copy(sht)
146 shots_offsets.append(offset) 148 characters.append((sht, focused_sht))
147 149
148 characters.append(sht) 150 for sht, func_offset in ((sht, shots_func_offset), (focused_sht, shots_func_offset_focused)):
151 # Read from “push” operand
152 pe_file.seek_to_va(func_offset + 4)
153 offset, = unpack('<I', file.read(4))
154 if offset not in shots_offsets:
155 shots_offsets[offset] = []
156 shots_offsets[offset].append(sht)
149 157
150 character = 0 158 character = 0
151 for shots_offset in shots_offsets: 159 for shots_offset, shts in shots_offsets.iteritems():
152 pe_file.seek_to_va(shots_offset) 160 pe_file.seek_to_va(shots_offset)
153 161
154 level_count = 9 162 level_count = 9
155 levels = [] 163 levels = []
156 for i in xrange(level_count): 164 for i in xrange(level_count):
157 shots_count, power, offset = unpack('<III', file.read(3*4)) 165 shots_count, power, offset = unpack('<III', file.read(3*4))
158 levels.append((shots_count, power, offset)) 166 levels.append((shots_count, power, offset))
159 167
160 sht = characters[character] 168 shots = {}
161 sht.shots = {}
162 169
163 for shots_count, power, offset in levels: 170 for shots_count, power, offset in levels:
164 sht.shots[power] = [] 171 shots[power] = []
165 pe_file.seek_to_va(offset) 172 pe_file.seek_to_va(offset)
166 173
167 for i in xrange(shots_count): 174 for i in xrange(shots_count):
168 shot = Shot() 175 shot = Shot()
169 176
173 shot.sprite, shot.unknown1) = data 180 shot.sprite, shot.unknown1) = data
174 181
175 shot.pos = (x, y) 182 shot.pos = (x, y)
176 shot.hitbox = (hitbox_x, hitbox_y) 183 shot.hitbox = (hitbox_x, hitbox_y)
177 184
178 sht.shots[power].append(shot) 185 shots[power].append(shot)
186
187 for sht in shts:
188 sht.shots = shots
179 189
180 character += 1 190 character += 1
181 191
182 192
183 return characters 193 return characters