Mercurial > touhou
comparison pytouhou/formats/std.py @ 377:70e2ed71b09c
Add meaningful exceptions in format parsing.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Wed, 29 Aug 2012 18:34:28 +0200 |
parents | 61adb5453e46 |
children | d1f0bb0b7a17 |
comparison
equal
deleted
inserted
replaced
376:69ec72b990a4 | 377:70e2ed71b09c |
---|---|
79 """ | 79 """ |
80 | 80 |
81 stage = Stage() | 81 stage = Stage() |
82 | 82 |
83 nb_models, nb_faces = unpack('<HH', file.read(4)) | 83 nb_models, nb_faces = unpack('<HH', file.read(4)) |
84 object_instances_offset, script_offset = unpack('<II', file.read(8)) | 84 object_instances_offset, script_offset, zero = unpack('<III', file.read(12)) |
85 if file.read(4) != b'\x00\x00\x00\x00': | 85 assert zero == 0 |
86 raise Exception #TODO | |
87 | 86 |
88 stage.name = read_string(file, 128, 'shift_jis') | 87 stage.name = read_string(file, 128, 'shift_jis') |
89 | 88 |
90 bgm_a = read_string(file, 128, 'shift_jis') | 89 bgm_a = read_string(file, 128, 'shift_jis') |
91 bgm_b = read_string(file, 128, 'shift_jis') | 90 bgm_b = read_string(file, 128, 'shift_jis') |
114 # Read model quads | 113 # Read model quads |
115 while True: | 114 while True: |
116 unknown, size = unpack('<HH', file.read(4)) | 115 unknown, size = unpack('<HH', file.read(4)) |
117 if unknown == 0xffff: | 116 if unknown == 0xffff: |
118 break | 117 break |
119 if size != 0x1c: | 118 assert size == 0x1c |
120 raise Exception #TODO | |
121 script_index, x, y, z, width, height = unpack('<Hxxfffff', file.read(24)) | 119 script_index, x, y, z, width, height = unpack('<Hxxfffff', file.read(24)) |
122 model.quads.append((script_index, x, y, z, width, height)) | 120 model.quads.append((script_index, x, y, z, width, height)) |
123 stage.models.append(model) | 121 stage.models.append(model) |
124 | 122 |
125 | 123 |
127 file.seek(object_instances_offset) | 125 file.seek(object_instances_offset) |
128 while True: | 126 while True: |
129 obj_id, unknown, x, y, z = unpack('<HHfff', file.read(16)) | 127 obj_id, unknown, x, y, z = unpack('<HHfff', file.read(16)) |
130 if (obj_id, unknown) == (0xffff, 0xffff): | 128 if (obj_id, unknown) == (0xffff, 0xffff): |
131 break | 129 break |
132 if unknown != 256: | 130 assert unknown == 256 #TODO: really? |
133 raise Exception #TODO | |
134 stage.object_instances.append((obj_id, x, y, z)) | 131 stage.object_instances.append((obj_id, x, y, z)) |
135 | 132 |
136 | 133 |
137 # Read other funny things (script) | 134 # Read the script |
138 file.seek(script_offset) | 135 file.seek(script_offset) |
139 while True: | 136 while True: |
140 frame, opcode, size = unpack('<IHH', file.read(8)) | 137 frame, opcode, size = unpack('<IHH', file.read(8)) |
141 if (frame, opcode, size) == (0xffffffff, 0xffff, 0xffff): | 138 if (frame, opcode, size) == (0xffffffff, 0xffff, 0xffff): |
142 break | 139 break |
143 if size != 0x0c: | 140 assert size == 0x0c |
144 raise Exception #TODO | |
145 data = file.read(size) | 141 data = file.read(size) |
146 if opcode in cls._instructions: | 142 if opcode in cls._instructions: |
147 args = unpack('<%s' % cls._instructions[opcode][0], data) | 143 args = unpack('<%s' % cls._instructions[opcode][0], data) |
148 else: | 144 else: |
149 args = (data,) | 145 args = (data,) |