[bc874f]: ie_shell / formats / wmap.py Maximize Restore History

Download this file

wmap.py    368 lines (280 with data), 10.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
# -*-python-*-
# ie_shell.py - Simple shell for Infinity Engine-based game files
# Copyright (C) 2004 by Jaroslav Benkovsky, <edheldil@users.sf.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# RCS: $Id: wmap.py,v 1.1 2005/03/02 20:44:23 edheldil Exp $
from ie_shell.formats.format import Format, register_format
class WMAP_Format (Format):
def __init__ (self, filename):
Format.__init__ (self, filename)
self.expect_signature = 'WMAP'
self.wmap_list = []
# FIXME: maybe they should be local to wmap entries
self.area_list = []
self.arealink_list = []
self.header_desc = (
{ 'key': 'signature',
'type': 'STR4',
'off': 0x0000,
'label': 'Signature' },
{ 'key': 'version',
'type': 'STR4',
'off':0x0004,
'label': 'Version'},
{ 'key': 'num_of_wmaps',
'type': 'DWORD',
'off': 0x0008,
'label': '# of wmap entries'},
{ 'key': 'wmap_offset',
'type': 'DWORD',
'off': 0x000C,
'label': 'First wmap entry offset'},
)
self.wmap_record_desc = (
{ 'key': 'map_resref',
'type': 'RESREF',
'off': 0x0000,
'label': 'Map resource name' },
{ 'key': 'width',
'type': 'DWORD',
'off': 0x0008,
'label': 'Width' },
{ 'key': 'height',
'type': 'DWORD',
'off': 0x000C,
'label': 'Height' },
{ 'key': 'map_num',
'type': 'DWORD',
'off': 0x0010,
'label': 'Map number' },
{ 'key': 'area_name',
'type': 'DWORD',
'off': 0x0014,
'label': 'Area name' },
{ 'key': 'unknown',
'type': 'DWORD',
'off': 0x0018,
'label': '???' },
{ 'key': 'unknown',
'type': 'DWORD',
'off': 0x001C,
'label': '???' },
{ 'key': 'num_of_areas',
'type': 'DWORD',
'off': 0x0020,
'label': 'Num of area entries' },
{ 'key': 'area_offset',
'type': 'DWORD',
'off': 0x0024,
'label': 'Offset of first area entry' },
{ 'key': 'arealink_offset',
'type': 'DWORD',
'off': 0x0028,
'label': 'Offset of first arealink entry' },
{ 'key': 'num_of_arealinks',
'type': 'DWORD',
'off': 0x002C,
'label': 'Num of arealink entries' },
{ 'key': 'map_icon_resref',
'type': 'RESREF',
'off': 0x0030,
'label': 'Map icons resource name' },
)
self.area_record_desc = (
{ 'key': 'area_name',
'type': 'RESREF',
'off': 0x0000,
'label': 'Area name' },
{ 'key': 'area_resref',
'type': 'RESREF',
'off': 0x0008,
'label': 'Area resref' },
{ 'key': 'area_long_name',
'type': 'STR32',
'off': 0x0010,
'label': 'Area long name' },
{ 'key': 'area_status',
'type': 'DWORD',
'off': 0x0030,
'label': 'Area status flags' },
{ 'key': 'icon_seq_ndx',
'type': 'DWORD',
'off': 0x0034,
'label': 'Icon sequence index' },
{ 'key': 'xpos',
'type': 'DWORD',
'off': 0x0038,
'label': 'X coordinate on world map' },
{ 'key': 'ypos',
'type': 'DWORD',
'off': 0x003C,
'label': 'Y coordinate on world map' },
{ 'key': 'area_name_caption',
'type': 'STRREF',
'off': 0x0040,
'label': 'Area title for captions' },
{ 'key': 'area_name_tooltip',
'type': 'STRREF',
'off': 0x0044,
'label': 'Area title for tooltips' },
{ 'key': 'loading_screen',
'type': 'RESREF',
'off': 0x0048,
'label': 'Loading screen MOS file' },
{ 'key': 'arealink_ndx_north',
'type': 'DWORD',
'off': 0x0050,
'label': 'Index of 1st arealink north' },
{ 'key': 'arealinks_cnt_north',
'type': 'DWORD',
'off': 0x0054,
'label': '# of arealinks north' },
{ 'key': 'arealink_ndx_east',
'type': 'DWORD',
'off': 0x0058,
'label': 'Index of 1st arealink east' },
{ 'key': 'arealinks_cnt_east',
'type': 'DWORD',
'off': 0x005C,
'label': '# of arealinks east' },
{ 'key': 'arealink_ndx_south',
'type': 'DWORD',
'off': 0x0060,
'label': 'Index of 1st arealink south' },
{ 'key': 'arealinks_cnt_south',
'type': 'DWORD',
'off': 0x0064,
'label': '# of arealinks south' },
{ 'key': 'arealink_ndx_west',
'type': 'DWORD',
'off': 0x0068,
'label': 'Index of 1st arealink west' },
{ 'key': 'arealinks_cnt_west',
'type': 'DWORD',
'off': 0x006C,
'label': '# of arealinks west' },
)
self.arealink_record_desc = (
{ 'key': 'dest_map_ndx',
'type': 'DWORD',
'off': 0x0000,
'label': 'Destination map index' },
{ 'key': 'dest_map_entry_point',
'type': 'STR32',
'off': 0x0004,
'label': 'Destination map entry_point name' },
{ 'key': 'distance_scale',
'type': 'DWORD',
'off': 0x0024,
'label': 'Distance scale?' },
{ 'key': 'flags',
'type': 'DWORD',
'off': 0x0028,
'label': 'Flags' },
{ 'key': 'encounter_area0',
'type': 'RESREF',
'off': 0x002C,
'label': 'Area of random encounter 0' },
{ 'key': 'encounter_area1',
'type': 'RESREF',
'off': 0x0034,
'label': 'Area of random encounter 1' },
{ 'key': 'encounter_area2',
'type': 'RESREF',
'off': 0x003C,
'label': 'Area of random encounter 2' },
{ 'key': 'encounter_area3',
'type': 'RESREF',
'off': 0x0044,
'label': 'Area of random encounter 3' },
{ 'key': 'encounter_area4',
'type': 'RESREF',
'off': 0x004C,
'label': 'Area of random encounter 4' },
{ 'key': 'encounter_chance',
'type': 'DWORD',
'off': 0x0050,
'label': 'Random encounter chance' },
)
def decode_file (self):
self.decode_header ()
off = self.header['wmap_offset']
for i in range (self.header['num_of_wmaps']):
obj = {}
self.decode_wmap_record (off, obj)
self.wmap_list.append (obj)
off = off + 184
for wmap in self.wmap_list:
off = wmap['area_offset']
for i in range (wmap['num_of_areas']):
obj = {}
self.decode_area_record (off, obj)
self.area_list.append (obj)
off = off + 240
off = wmap['arealink_offset']
for i in range (wmap['num_of_arealinks']):
obj = {}
self.decode_arealink_record (off, obj)
self.arealink_list.append (obj)
off = off + 168
def print_file (self):
self.print_header ()
i = 0
for obj in self.wmap_list:
print '#%d' %i
self.print_wmap_record (obj)
i = i + 1
i = 0
for obj in self.arealink_list:
print '#%d' %i
self.print_arealink_record (obj)
i = i + 1
i = 0
for obj in self.area_list:
print '#%d' %i
self.print_area_record (obj)
i = i + 1
return
for i in range (self.header['num_of_res']):
self.decode_res_record (off, obj)
off = off + 14
print '#%d' %i
self.print_res_record (obj)
def decode_header (self):
self.header = {}
self.decode_by_desc (0x0000, self.header_desc, self.header)
def print_header (self):
self.print_by_desc (self.header, self.header_desc)
def decode_wmap_record (self, offset, obj):
self.decode_by_desc (offset, self.wmap_record_desc, obj)
def print_wmap_record (self, obj):
self.print_by_desc (obj, self.wmap_record_desc)
def decode_area_record (self, offset, obj):
self.decode_by_desc (offset, self.area_record_desc, obj)
def print_area_record (self, obj):
self.print_by_desc (obj, self.area_record_desc)
def decode_arealink_record (self, offset, obj):
self.decode_by_desc (offset, self.arealink_record_desc, obj)
def print_arealink_record (self, obj):
self.print_by_desc (obj, self.arealink_record_desc)
def get_file_res_data (self, obj):
obj['data'] = self.decode_blob (obj['data_offset'], obj['data_size'])
def save_file_res (self, filename, obj):
self.get_file_res_data (obj)
fh = open (filename, 'w')
fh.write (obj['data'])
fh.close ()
register_format ('WMAP', 'V1.0', WMAP_Format)