diff options
| -rw-r--r-- | ethyl.py | 22 | ||||
| -rw-r--r-- | parse-brlyt.py | 39 |
2 files changed, 48 insertions, 13 deletions
@@ -59,6 +59,20 @@ formats = { float width float height ''', + 'material': ''' + char name[0x14] // 0 + s16 tev_color[4] // 14 + s16 unkx // 1c + s16 unk5 // 20 + s16 unk6 // 22 + s16 unk7 // 24 + s16 unk8 // 26 + s16 unk9 // 28 + s16 unka // 2a + u32 tev_kcolor[4] // 2c + u32 flags // 3c - 814fee68 - see doc + etc! + ''', } @@ -228,4 +242,10 @@ def iff_to_chunks(z): data = z[pos+8:pos+length] pos += length chunks.append((cc, data)) - return chunks
\ No newline at end of file + return chunks +def bit_extract(num, start, end): + mask = (2**(31 - start + 1) - 1) - (2**(31 - end) - 1) + ret = (num & mask) >> (31 - end) + + return ret + diff --git a/parse-brlyt.py b/parse-brlyt.py index 9ba2cd4..b69eba3 100644 --- a/parse-brlyt.py +++ b/parse-brlyt.py @@ -43,25 +43,40 @@ for typ, chunk in ch: for n in xrange(vars['numsubs']): vars['subs'].append(nullterm(chunk[pos:pos+16])) pos += 16 - elif typ in ('txl1', 'fnl1', 'mat1'): - things = {'txl1': 'textures', 'fnl1': 'files', 'mat1': 'materials'}[typ] + elif typ in ('txl1', 'fnl1'): + things = {'txl1': 'textures', 'fnl1': 'files'}[typ] vars, pos = parse_data(chunk, 'numoffs') vars[things] = [] pos += vars['offs'] bpos = pos del vars['offs'] # unneeded for n in xrange(vars['num']): - if typ == 'mat1': - offset, = struct.unpack('>I', chunk[pos:pos+4]) - pos += 4 - else: - offset, unk = struct.unpack('>II', chunk[pos:pos+8]) - pos += 8 + offset, unk = struct.unpack('>II', chunk[pos:pos+8]) + name = nullterm(chunk[offset + bpos:]) + vars[things].append({'name': name, 'unk': unk}) + pos += 8 + elif typ == 'mat1': + vars, pos = parse_data(chunk, 'numoffs') + vars['materials'] = [] + pos += vars['offs'] + bpos = pos + del vars['offs'] + for n in xrange(vars['num']): + offset, = struct.unpack('>I', chunk[pos:pos+4]) + mat, mpos = parse_data(chunk[offset - 8:], 'material') + #vars['materials'].append(mat) + flags = mat['flags'] + + offs1 = bit_extract(flags, 17, 18) * 0x14 + offs2 = (bit_extract(flags, 28, 31) * 4) + 0x40 + offs3 = offs2 + bit_extract(flags, 24, 27) * 0x14 + bit_extract(flags, 20, 23) * 4 + offs4 = bit_extract(flags, 8, 11) * 4 * 0x14 + print map(hex, [offs1, offs2, offs3, offs4]) - name = nullterm(chunk[(-8 if typ == 'mat1' else bpos) + offset:]) - vars[things].append(name if typ == 'mat1' else {'name': name, 'unk': unk}) - if typ == 'mat1': - materials = vars['materials'] + pr_dict(mat, ' ') + print + pos += 4 + elif typ in ('grs1', 'pas1'): indent += 1 elif typ in ('gre1', 'pae1'): |
