diff options
| author | comex <comexk@gmail.com> | 2009-02-03 13:45:43 -0500 |
|---|---|---|
| committer | comex <comexk@gmail.com> | 2009-02-03 13:45:43 -0500 |
| commit | d43d30a57cc5bc098d4872be52dbaefe3bd38658 (patch) | |
| tree | 07a85e0d268473ac533cc54bbef767be635a8e42 | |
| parent | 43595980673a98759c8da9671bf19023d8ee9877 (diff) | |
horribltastic
Diffstat (limited to '')
| -rw-r--r-- | ethyl.py | 38 | ||||
| -rw-r--r-- | parse-brlyt.py | 16 | ||||
| -rw-r--r-- | testrlyt.py | 138 | ||||
| -rw-r--r-- | write-brlyt.py | 63 |
4 files changed, 186 insertions, 69 deletions
@@ -65,7 +65,7 @@ formats = { s16 unk_color[4] // 1c s16 unk_color_2[4] // 24 u32 tev_kcolor[4] // 2c - u32 flags // 3c - 814fee68 - see doc + u32 flags = 0 // 3c - 814fee68 - see doc etc! ''', 'texref': ''' @@ -251,6 +251,17 @@ def unparse_var(typ, var): def unparse_data(vars, definition, prefix=None): df, etc, etcn = formats[definition] ret = '' + + #print df, vars + + if len(df) == 1: + try: + assert df[0][1] == '_' or df[0][1][0] == '_' + except: + pass + else: + vars = {'_': vars} + for typ, name, default in df: size = None try: @@ -300,7 +311,7 @@ def bit_place(num, start, end=None): # Just for sanity if end is None: end = start - assert num <= 2**(start - end) + assert num <= 2**(end - start) return num << (31 - end) def get_array(chunk, startpos, array_size, item_size, item_type=None): ar = [] @@ -322,3 +333,26 @@ def get_opt(chunk, startpos, enabled, size, item_type=None): else: raise Exception('unhandled') return ret, startpos + size + +def put_array(var, flags, start, end, item_size, item_type=None): + ret = '' + for el in var: + dat, _ = put_opt(el, flags, 0, item_size, item_type) + ret += dat + flags |= bit_place(len(var), start, end) + return ret, flags + +def put_opt(var, flags, bit, size, item_type=None): + if var is None: + return '', flags + else: + flags |= bit_place(1, bit) + if item_type is not None: + ret = unparse_data(var, item_type) + elif size == 4: + ret = struct.pack('>I', var) + elif size % 4 == 0: + ret = struct.pack('>' + 'I'*(size/4), *var) + else: + raise Exception('unhandled') + return ret, flags diff --git a/parse-brlyt.py b/parse-brlyt.py index 43020d4..694cc12 100644 --- a/parse-brlyt.py +++ b/parse-brlyt.py @@ -55,6 +55,8 @@ for typ, chunk in ch: name = nullterm(chunk[offset + bpos:]) vars[things].append({'name': name, 'unk': unk}) pos += 8 + if typ == 'txl1': + textures = vars['textures'] elif typ == 'mat1': vars, pos = parse_data(chunk, 'numoffs') vars['materials'] = [] @@ -80,6 +82,9 @@ for typ, chunk in ch: mat['texref'], mpos = get_array(chunk, mpos, bit_extract(flags, 28, 31), 4, 'texref') + for a in mat['texref']: + a['tex'] = textures[a['tex_offs']]['name'] + # 0x14 * flags[24-27], followed by mat['ua2'], mpos = get_array(chunk, mpos, bit_extract(flags, 24, 27), 0x14, 'ua2') @@ -88,6 +93,12 @@ for typ, chunk in ch: mat['ua3'], mpos = get_array(chunk, mpos, bit_extract(flags, 20, 23), 4, '4b') + # Changing ua3 things + # 1st --> disappears. + # 2nd --> no visible effect. + # 3rd --> disappears. + # 4th --> no visible effect. + # 4 * flags[6] mat['ua4'], mpos = get_opt(chunk, mpos, bit_extract(flags, 6), 4, '4b') @@ -110,7 +121,7 @@ for typ, chunk in ch: # 0x10 * flags[9-13] - mat['ua8'], mpos = get_array(chunk, mpos, bit_extract(flags, 9, 13), 0x10, '10b') + mat['ua9'], mpos = get_array(chunk, mpos, bit_extract(flags, 9, 13), 0x10, '10b') # 4 * flags[8], these are bytes btw @@ -125,6 +136,9 @@ for typ, chunk in ch: if next_offset - 8 != mpos: mat['~_insane'] = next_offset - 8 - mpos # Extra shit we didn't parse :( + mat['unk_bit_5'] = bit_extract(flags, 5) + mat['unk_bits_0_3'] = bit_extract(flags, 0, 3) # Overwritten by stuff + vars['materials'].append(mat) pos += 4 elif typ in ('grs1', 'pas1'): diff --git a/testrlyt.py b/testrlyt.py index 2687a7d..131a4c2 100644 --- a/testrlyt.py +++ b/testrlyt.py @@ -6,7 +6,7 @@ }), ('txl1', { 'textures': [ - {'unk': 0, 'name': 'spam12345'}, + {'unk': 0, 'name': 'icon.tpl'}, {'unk': 1, 'name': 'spamnonexist'}, ] }), @@ -17,7 +17,29 @@ ] }), ('mat1', { - 'materials': ['textmat'] + 'materials': [ + { + 'name': 'textmat', + 'tev_color': [0x0, 0x0, 0x0, 0x0], # Possibly background color + 'tev_kcolor': [0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, ], + 'unk_color': [0xff, 0xff, 0xff, 0xff], # Possibly the color of the thing itself + 'unk_color_2': [0xff, 0xff, 0xff, 0xff], + 'texref': [ { 'tex': 'icon.tpl', 'wrap_s': 0, 'wrap_t': 0 } ], + 'ua2': [ (0.0, 0.0, 0.0, 1.0, 1.0) ], + 'ua3': [ (1, 0xff, 30, 0xff) ], # Changing this --> image disappears (not text, though) + 'ua4': None, + 'ua5': None, + 'ua6': None, + 'ua7': [], + 'ua8': [], + 'ua9': [], + 'uaa': [0x77, 0x77, 0x77, 0x77], + 'uab': None, + + + } + + ] }), ('pan1', { 'alpha': 0xff, @@ -35,69 +57,69 @@ 'z': 0 }), 'pas1', - ('txt1', { - 'alpha': 0xff, - 'alpha_2': 0x0, - 'angle': 0, - 'flags_1': 1, - 'flags_2': 0, - 'height': 38, - 'name': 'textbox', - 'width': 400, - 'x': 0, - 'y': 50, - 'xmag': 1, - 'ymag': 1, - 'z': 0, - '~text.material': 'textmat', - '~text.text': 'Some Text', - '~text.font_idx': 0, - '~text.unk4': 0, - '~text.color1': 0xffffffff, - '~text.color2': 0xffffffff, - '~text.font_size_x': 32.0, - '~text.font_size_y': 38.0, - '~text.char_space': -1.0, - '~text.line_space': -1.0, - }), - [('txt1', { - 'alpha': 0xff, - 'alpha_2': 0x0, - 'angle': 0, - 'flags_1': 1, - 'flags_2': 0, - 'height': 38, - 'name': 'textbox%d' % i, - 'width': 400, - 'x': -250, - 'y': -50 + i, - 'xmag': 1, - 'ymag': 1, - 'z': 0, - '~text.material': 'textmat', - '~text.text': 'benzin (and built-in fonts) ftw!', - '~text.font_idx': 1, - '~text.unk4': 0, - '~text.color1': 0xff + 0x01080800*i, - '~text.color2': 0xff + 0x08080100*i, - '~text.font_size_x': 32.0, - '~text.font_size_y': 38.0, - '~text.char_space': -1.0, - '~text.line_space': -1.0, - }) for i in xrange(2, 30)], + #('txt1', { + #'alpha': 0xff, + #'alpha_2': 0x0, + #'angle': 0, + #'flags_1': 1, + #'flags_2': 0, + #'height': 38, + #'name': 'textbox', + #'width': 400, + #'x': 0, + #'y': 50, + #'xmag': 1, + #'ymag': 1, + #'z': 0, + #'~text.material': 'textmat', + #'~text.text': 'Some Text', + #'~text.font_idx': 0, + #'~text.unk4': 0, + #'~text.color1': 0xffffffff, + #'~text.color2': 0xffffffff, + #'~text.font_size_x': 32.0, + #'~text.font_size_y': 38.0, + #'~text.char_space': -1.0, + #'~text.line_space': -1.0, + #}), + #[('txt1', { + #'alpha': 0xff, + #'alpha_2': 0x0, + #'angle': 0, + #'flags_1': 1, + #'flags_2': 0, + #'height': 38, + #'name': 'textbox%d' % i, + #'width': 400, + #'x': -250, + #'y': -50 + i, + #'xmag': 1, + #'ymag': 1, + #'z': 0, + #'~text.material': 'textmat', + #'~text.text': 'benzin (and built-in fonts) ftw!', + #'~text.font_idx': 1, + #'~text.unk4': 0, + #'~text.color1': 0xff + 0x01080800*i, + #'~text.color2': 0xff + 0x08080100*i, + #'~text.font_size_x': 32.0, + #'~text.font_size_y': 38.0, + #'~text.char_space': -1.0, + #'~text.line_space': -1.0, + #}) for i in xrange(2, 30)], ('pic1', { 'alpha': 0xff, 'alpha_2': 0x0, 'angle': 0, - 'flags_1': 5, + 'flags_1': 1, 'flags_2': 4, - 'height': 38, + 'width': 120, + 'height': 66, 'name': 'pic', - 'width': 400, - 'x': 200, + 'x': 150, 'y': 50, - 'xmag': 1, - 'ymag': 2, + 'xmag': 0.75, + 'ymag': 0.75, 'z': 0, '~pic.material': 'textmat', '~pic.texcoords': [(0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0)], diff --git a/write-brlyt.py b/write-brlyt.py index 79b47be..c3572e3 100644 --- a/write-brlyt.py +++ b/write-brlyt.py @@ -36,23 +36,70 @@ for c in chunks: chunk = unparse_data(vars, 'group') for sub in vars['subs']: chunk += unnullterm(sub, 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] ls = vars[things] chunk = struct.pack('>hh', len(ls), 0) strings = '' offss = [] for thing in ls: - name = untv(thing['name'] if typ != 'mat1' else thing) + name = untv(thing['name']) offss.append(len(strings)) strings += name for n, thing in enumerate(ls): - chunk += struct.pack('>I', offss[n] + (12 if typ == 'mat1' else 0) + (4 if typ == 'mat1' else 8) * len(ls)) - if typ != 'mat1': - chunk += struct.pack('>I', thing['unk']) + chunk += struct.pack('>II', offss[n] + 8 * len(ls), thing['unk']) chunk += strings - if typ == 'mat1': - materials = ls + if typ == 'txl1': + textures = ls + else: + filenames = ls + elif typ == 'mat1': + materials = [] + mchunks = [] + for mat in vars['materials']: + flags = mat['flags'] if mat.has_key('flags') else 0 + + for a in mat['texref']: + a['tex_offs'] = [i for i in xrange(len(textures)) if textures[i]['name'] == a['tex']][0] + + c1, flags = put_array(mat['texref'], flags, 28, 31, 4, 'texref') + + c2, flags = put_array(mat['ua2'], flags, 24, 27, 0x14, 'ua2') + + c3, flags = put_array(mat['ua3'], flags, 20, 23, 4, '4b') + + c4, flags = put_opt(mat['ua4'], flags, 6, 4, '4b') + + c5, flags = put_opt(mat['ua5'], flags, 4, 4, '4b') + + c6, flags = put_opt(mat['ua6'], flags, 19, 4, '4b') + + c7, flags = put_array(mat['ua7'], flags, 17, 18, 0x14, 'ua7') + + c8, flags = put_array(mat['ua8'], flags, 14, 16, 4, '4b') + + c9, flags = put_array(mat['ua9'], flags, 9, 13, 0x10, '10b') + + ca, flags = put_opt(mat['uaa'], flags, 8, 4, '4b') + + cb, flags = put_opt(mat['uab'], flags, 7, 4, '4b') + + + mat['flags'] = flags + mchunk = unparse_data(mat, 'material') + assert len(mchunk) == 0x40 + + mchunk += c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 + c9 + ca + cb + + mchunks.append(mchunk) + materials.append(mat['name']) + chunk = struct.pack('>hh', len(mchunks), 0) + zchunk = '' + for a in mchunks: + chunk += struct.pack('>I', 0xc + 4*len(mchunks) + len(zchunk)) + zchunk += a + chunk += zchunk + elif typ in ('pic1', 'pan1', 'bnd1', 'wnd1', 'txt1'): chunk = unparse_data(vars, 'pane') if typ == 'txt1': |
