diff options
Diffstat (limited to 'crodump.py')
-rw-r--r-- | crodump.py | 73 |
1 files changed, 37 insertions, 36 deletions
@@ -198,32 +198,16 @@ class Datafile: | |||
198 | C = zlib.decompressobj(-15) | 198 | C = zlib.decompressobj(-15) |
199 | return C.decompress(data[8:-3]) | 199 | return C.decompress(data[8:-3]) |
200 | 200 | ||
201 | def destruct_bank_definition(args, data): | 201 | def dump_bank_definition(args, bankdict): |
202 | """ | 202 | """ |
203 | decode the 'bank' / database definition | 203 | decode the 'bank' / database definition |
204 | """ | 204 | """ |
205 | rd = ByteReader(data) | 205 | for k, v in bankdict.items(): |
206 | 206 | if re.search(b'[^\x0d\x0a\x09\x20-\x7e\xc0-\xff]', v): | |
207 | version = rd.readbyte() | 207 | print("%-20s - %s" % (k, toout(args, v))) |
208 | print("bank version: %02x" % version) | ||
209 | |||
210 | d = dict() | ||
211 | while not rd.eof(): | ||
212 | keyname = rd.readname() | ||
213 | if keyname in d: | ||
214 | print("WARN: duplicate key: %s" % keyname) | ||
215 | |||
216 | index_or_length = rd.readdword() | ||
217 | if index_or_length >> 31: | ||
218 | value = d[keyname] = rd.readbytes(index_or_length & 0x7FFFFFFF) | ||
219 | if re.search(b'[^\x0d\x0a\x09\x20-\x7e\xc0-\xff]', value): | ||
220 | print("%-20s - %s" % (keyname, toout(args, d[keyname]))) | ||
221 | else: | ||
222 | print("%-20s - \"%s\"" % (keyname, strescape(d[keyname]))) | ||
223 | else: | 208 | else: |
224 | d[keyname] = index_or_length | 209 | print("%-20s - \"%s\"" % (k, strescape(v))) |
225 | print("%-20s -> #%s" % (keyname, d[keyname])) | 210 | |
226 | return d | ||
227 | 211 | ||
228 | def decode_field(data): | 212 | def decode_field(data): |
229 | rd = ByteReader(data) | 213 | rd = ByteReader(data) |
@@ -249,8 +233,6 @@ def destruct_base_definition(args, data): | |||
249 | """ | 233 | """ |
250 | rd = ByteReader(data) | 234 | rd = ByteReader(data) |
251 | 235 | ||
252 | version = rd.readbyte() | ||
253 | print("base version: %02x" % version) | ||
254 | unk123 = [rd.readword() for _ in range(3)] | 236 | unk123 = [rd.readword() for _ in range(3)] |
255 | unk45 = [rd.readdword() for _ in range(2)] | 237 | unk45 = [rd.readdword() for _ in range(2)] |
256 | tablename = rd.readname() | 238 | tablename = rd.readname() |
@@ -343,20 +325,39 @@ class Database: | |||
343 | return | 325 | return |
344 | self.dumptabledefs(args) | 326 | self.dumptabledefs(args) |
345 | 327 | ||
328 | def decode_bank_definition(self, data): | ||
329 | """ | ||
330 | decode the 'bank' / database definition | ||
331 | """ | ||
332 | rd = ByteReader(data) | ||
333 | |||
334 | d = dict() | ||
335 | while not rd.eof(): | ||
336 | keyname = rd.readname() | ||
337 | if keyname in d: | ||
338 | print("WARN: duplicate key: %s" % keyname) | ||
339 | |||
340 | index_or_length = rd.readdword() | ||
341 | if index_or_length >> 31: | ||
342 | d[keyname] = rd.readbytes(index_or_length & 0x7FFFFFFF) | ||
343 | else: | ||
344 | refdata = self.stru.readrec(index_or_length) | ||
345 | if refdata[:1] != b"\x04": | ||
346 | print("WARN: expected refdata to start with 0x04") | ||
347 | d[keyname] = refdata[1:] | ||
348 | return d | ||
349 | |||
346 | def dumptabledefs(self, args): | 350 | def dumptabledefs(self, args): |
347 | dbinfo = self.stru.readrec(1) | 351 | dbinfo = self.stru.readrec(1) |
348 | dbdef = destruct_bank_definition(args, dbinfo) | 352 | if dbinfo[:1] != b"\x03": |
349 | 353 | print("WARN: expected dbinfo to start with 0x03") | |
350 | for i in range(100): | 354 | dbdef = self.decode_bank_definition(dbinfo[1:]) |
351 | idx = dbdef.get("Base%03d" % i) | 355 | dump_bank_definition(args, dbdef) |
352 | if idx: | 356 | |
353 | print("== Base%03d ==" % i) | 357 | for k, v in dbdef.items(): |
354 | if type(idx)==int: | 358 | if k.startswith("Base") and k[4:].isnumeric(): |
355 | tbinfo = self.stru.readrec(idx) | 359 | print("== %s ==" % k) |
356 | else: | 360 | tbdef = destruct_base_definition(args, v) |
357 | # the table def is in the value. | ||
358 | tbinfo = struct.pack("<B", 4) + idx | ||
359 | tbdef = destruct_base_definition(args, tbinfo) | ||
360 | 361 | ||
361 | def bankdump(self, args): | 362 | def bankdump(self, args): |
362 | if not self.bank: | 363 | if not self.bank: |