comparison pytouhou/formats/t6rp.py @ 189:ba3297ab3bde

Fix handling for replay files not beginning with stage 1
author Thibaut Girka <thib@sitedethib.com>
date Thu, 27 Oct 2011 21:53:26 +0200
parents 008f90ebfdc0
children 9f58e2a6e950
comparison
equal deleted inserted replaced
188:008f90ebfdc0 189:ba3297ab3bde
39 def __init__(self): 39 def __init__(self):
40 self.version = 0x102 40 self.version = 0x102
41 self.character = 0 41 self.character = 0
42 self.rank = 0 42 self.rank = 0
43 self.key = 0 43 self.key = 0
44 self.levels = [] 44 self.levels = [None] * 7
45 45
46 46
47 @classmethod 47 @classmethod
48 def read(cls, file, decrypt=True, verify=True): 48 def read(cls, file, decrypt=True, verify=True):
49 if file.read(4) != b'T6RP': 49 if file.read(4) != b'T6RP':
75 replay.name = read_string(file, 9, 'ascii').rstrip() 75 replay.name = read_string(file, 9, 'ascii').rstrip()
76 replay.unknown4, replay.score, replay.unknown5, replay.slowdown, replay.unknown6 = unpack('<HIIfI', file.read(18)) 76 replay.unknown4, replay.score, replay.unknown5, replay.slowdown, replay.unknown6 = unpack('<HIIfI', file.read(18))
77 77
78 stages_offsets = unpack('<7I', file.read(28)) 78 stages_offsets = unpack('<7I', file.read(28))
79 79
80 replay.levels = [] 80 for i, offset in enumerate(stages_offsets):
81
82 for offset in stages_offsets:
83 if offset == 0: 81 if offset == 0:
84 continue 82 continue
85 83
86 level = Level() 84 level = Level()
87 replay.levels.append(level) 85 replay.levels[i] = level
88 86
89 file.seek(offset) 87 file.seek(offset)
90 (level.score, level.random_seed, level.unknown1, level.power, 88 (level.score, level.random_seed, level.unknown1, level.power,
91 level.lives, level.bombs, level.difficulty, level.unknown2) = unpack('<IHHBbbBI', file.read(16)) 89 level.lives, level.bombs, level.difficulty, level.unknown2) = unpack('<IHHBbbBI', file.read(16))
92 90