aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcomex <comexk@gmail.com>2009-02-03 11:02:20 -0500
committercomex <comexk@gmail.com>2009-02-03 11:02:20 -0500
commit43595980673a98759c8da9671bf19023d8ee9877 (patch)
tree4fee3ae98cdd38142793b8997b822671179a0d40
parent653eab5bfe95a42ebb2ebba7aa4a1249710f5ba0 (diff)
More fixes. More cake.
-rw-r--r--ethyl.py66
-rw-r--r--parse-brlyt.py28
2 files changed, 60 insertions, 34 deletions
diff --git a/ethyl.py b/ethyl.py
index 870c438..cb208b2 100644
--- a/ethyl.py
+++ b/ethyl.py
@@ -62,18 +62,34 @@ formats = {
'material': '''
char name[0x14] // 0
s16 tev_color[4] // 14
- s16 unkx // 1c
- s16 unky // 1e
- s16 unk5 // 20
- s16 unk6 // 22
- s16 unk7 // 24
- s16 unk8 // 26
- s16 unk9 // 28
- s16 unka // 2a
+ s16 unk_color[4] // 1c
+ s16 unk_color_2[4] // 24
u32 tev_kcolor[4] // 2c
u32 flags // 3c - 814fee68 - see doc
etc!
''',
+ 'texref': '''
+ u16 tex_offs
+ u8 wrap_s
+ u8 wrap_t
+ ''',
+ '4b': '''
+ u8 _[4]
+ ''',
+ '10b': '''
+ u8 _[0x10]
+ ''',
+ 'ua2': '''
+ float _[5]
+ ''',
+ 'ua7': '''
+ u32 a
+ u32 b
+ float c
+ u32 d
+ u32 e
+ ''',
+
}
@@ -223,6 +239,10 @@ def parse_data(chunk, definition, prefix=None, start=0):
for (k, v) in ret.items():
ret2[prefix + '.' + k] = v
ret = ret2
+
+ if ret.keys() == ['_']: # just an array
+ ret = ret['_']
+
return (ret, pos) if etcn else ret
def unparse_var(typ, var):
if not types.has_key(typ):
@@ -276,25 +296,29 @@ def bit_extract(num, start, end=None):
ret = (num & mask) >> (31 - end)
return ret
-def get_array(chunk, startpos, array_size, item_size):
+def bit_place(num, start, end=None):
+ # Just for sanity
+ if end is None:
+ end = start
+ assert num <= 2**(start - end)
+ return num << (31 - end)
+def get_array(chunk, startpos, array_size, item_size, item_type=None):
ar = []
pos = startpos
+
for n in xrange(array_size):
- if item_size == 4:
- ar.append(struct.unpack('>I', chunk[pos:pos+4])[0])
- elif item_size == 1:
- ar.append(struct.unpack('>B', chunk[pos:pos+4])[0])
- elif item_size % 4 == 0:
- ar.append(struct.unpack('>' + 'I'*(item_size/4), chunk[pos:pos+item_size]))
- else:
- raise Exception('unhandled')
+ ar.append(get_opt(chunk, pos, True, item_size, item_type)[0])
pos += item_size
-
return ar, pos
-def get_opt(chunk, startpos, enabled, size):
+def get_opt(chunk, startpos, enabled, size, item_type=None):
if not enabled:
return None, startpos
+ elif item_type is not None:
+ ret = parse_data(chunk[startpos:startpos+size], item_type)
elif size == 4:
- return struct.unpack('>I', chunk[startpos:startpos+4])[0], startpos + 4
+ ret = struct.unpack('>I', chunk[startpos:startpos+4])[0]
+ elif size % 4 == 0:
+ ret = struct.unpack('>' + 'I'*(size/4), chunk[startpos:startpos+size])
else:
- raise Exception('unhandled') \ No newline at end of file
+ raise Exception('unhandled')
+ return ret, startpos + size
diff --git a/parse-brlyt.py b/parse-brlyt.py
index d79b382..43020d4 100644
--- a/parse-brlyt.py
+++ b/parse-brlyt.py
@@ -23,10 +23,12 @@ for typ, chunk in ch:
os = vars2['~text.name_offs'] - 8
txt = chunk[os:os + vars2['~text.len2']]
vars2['~text.text'] = unicode(txt, 'utf_16_be').rstrip('\x00')
+ vars2['~text.material'] = materials[vars2['~text.mat_off']]
vars.update(vars2)
#print vars['~text.cnt2'], len(vars2['~text.text']), len(txt), repr(txt)
elif typ == 'pic1':
vars2, pos = parse_data(chunk, 'pic', prefix='~pic', start=pos)
+ vars2['~pic.material'] = materials[vars2['~pic.mat_off']]
vars2['~pic.texcoords'] = []
for n in xrange(vars2['~pic.num_texcoords']):
vars2['~pic.texcoords'].append(struct.unpack('>ffffffff', chunk[pos:pos+0x20]))
@@ -59,12 +61,13 @@ for typ, chunk in ch:
pos += vars['offs']
bpos = pos
del vars['offs']
+ materials = []
for n in xrange(vars['num']):
offset, = struct.unpack('>I', chunk[pos:pos+4])
mat, mpos = parse_data(chunk, 'material', start = offset - 8)
#vars['materials'].append(mat)
flags = mat['flags']
-
+ materials.append(mat['name'])
assert mpos == 0x40 + offset - 8
@@ -75,47 +78,47 @@ for typ, chunk in ch:
# 4 * flags[28-31], followed by
- mat['ua1'], mpos = get_array(chunk, mpos, bit_extract(flags, 28, 31), 4)
+ mat['texref'], mpos = get_array(chunk, mpos, bit_extract(flags, 28, 31), 4, 'texref')
# 0x14 * flags[24-27], followed by
- mat['ua2'], mpos = get_array(chunk, mpos, bit_extract(flags, 24, 27), 0x14)
+ mat['ua2'], mpos = get_array(chunk, mpos, bit_extract(flags, 24, 27), 0x14, 'ua2')
# 4*flags[20-23], followed by
- mat['ua3'], mpos = get_array(chunk, mpos, bit_extract(flags, 20, 23), 4)
+ mat['ua3'], mpos = get_array(chunk, mpos, bit_extract(flags, 20, 23), 4, '4b')
# 4 * flags[6]
- mat['ua4'], mpos = get_opt(chunk, mpos, bit_extract(flags, 6), 4)
+ mat['ua4'], mpos = get_opt(chunk, mpos, bit_extract(flags, 6), 4, '4b')
# 4 * flags[4]
- mat['ua5'], mpos = get_opt(chunk, mpos, bit_extract(flags, 4), 4)
+ mat['ua5'], mpos = get_opt(chunk, mpos, bit_extract(flags, 4), 4, '4b')
# 4 * flags[19]
- mat['ua6'], mpos = get_opt(chunk, mpos, bit_extract(flags, 19), 4)
+ mat['ua6'], mpos = get_opt(chunk, mpos, bit_extract(flags, 19), 4, '4b')
# 0x14 * flags[17-18]
- mat['ua7'], mpos = get_array(chunk, mpos, bit_extract(flags, 17, 18), 0x14)
+ mat['ua7'], mpos = get_array(chunk, mpos, bit_extract(flags, 17, 18), 0x14, 'ua7')
# 4 * flags[14-16]
- mat['ua8'], mpos = get_array(chunk, mpos, bit_extract(flags, 14, 16), 4)
+ mat['ua8'], mpos = get_array(chunk, mpos, bit_extract(flags, 14, 16), 4, '4b')
# 0x10 * flags[9-13]
- mat['ua8'], mpos = get_array(chunk, mpos, bit_extract(flags, 9, 13), 0x10)
+ mat['ua8'], mpos = get_array(chunk, mpos, bit_extract(flags, 9, 13), 0x10, '10b')
# 4 * flags[8], these are bytes btw
- mat['uaa'], mpos = get_opt(chunk, mpos, bit_extract(flags, 8), 4)
+ mat['uaa'], mpos = get_opt(chunk, mpos, bit_extract(flags, 8), 4, '4b')
# 4 * flags[7]
- mat['uab'], mpos = get_opt(chunk, mpos, bit_extract(flags, 7), 4)
+ mat['uab'], mpos = get_opt(chunk, mpos, bit_extract(flags, 7), 4, '4b')
if n < vars['num'] - 1:
next_offset, = struct.unpack('>I', chunk[pos+4:pos+8])
@@ -124,7 +127,6 @@ for typ, chunk in ch:
vars['materials'].append(mat)
pos += 4
-
elif typ in ('grs1', 'pas1'):
indent += 1
elif typ in ('gre1', 'pae1'):