From 27fc9b148381a84cb20749657c4d387f640fdf64 Mon Sep 17 00:00:00 2001 From: comex Date: Fri, 6 Feb 2009 18:54:49 -0500 Subject: Initial RLAN write support. --- parse-brlan.py | 14 ++++++++------ testrlan.py | 20 +++++++++++++++++++- testrlyt.py | 59 ++++------------------------------------------------------ write-brlan.py | 47 +++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 75 insertions(+), 65 deletions(-) diff --git a/parse-brlan.py b/parse-brlan.py index 03d8133..eeea240 100644 --- a/parse-brlan.py +++ b/parse-brlan.py @@ -25,6 +25,7 @@ assert len(ch) == nel for typ, chunk in ch: assert typ == 'pai1' framesize, flags, _, num_timgs, num_anims, anim_offset = struct.unpack('>hbbhhI', chunk[:0xc]) + print 'Framesize: %x\nFlags: %x' % (framesize, flags) for n in xrange(num_timgs): pos = 0x10 + 4*n offs = struct.unpack('>I', chunk[pos:pos+4]) @@ -32,11 +33,13 @@ for typ, chunk in ch: for n in xrange(num_anims): pos = anim_offset - 8 + 4*n offs = struct.unpack('>I', chunk[pos:pos+4])[0] - 8 - name = chunk[offs:offs + 20].rstrip('\0') + + name = chunk[offs:offs + 0x14].rstrip('\0') aunk, aoffs = struct.unpack('>II', chunk[offs + 0x14:offs + 0x1c]) aoffs += offs atyp = chunk[aoffs:aoffs+4] #print hex(aoffs), hex(offs), name + num_aents = ord(chunk[aoffs + 4]) print atyp, name, hex(aunk) @@ -44,11 +47,10 @@ for typ, chunk in ch: boffs = aoffs + 8 + 4*m coffs, = struct.unpack('>I', chunk[boffs:boffs + 4]) coffs += aoffs - if atyp in ('RLMC', 'RLVC', 'RLPA', 'RLTP', 'RLIM', 'RLTS'): # doesn't cover RLTS, RLVI - byte1 = ord(chunk[coffs+1]) - byte2 = ord(chunk[coffs+2]) - num_cookies, pad, cookies_offs = struct.unpack('>HHI', chunk[coffs+4:coffs+0xc]) - print hex(byte1), hex(byte2), num_cookies + if atyp in ('RLMC', 'RLVC', 'RLPA', 'RLTP', 'RLIM', 'RLTS'): # doesn't cover RLVI + byte0, byte1, byte2, byte3, num_cookies, pad, cookies_offs = struct.unpack('>BBBBHHI', chunk[coffs:coffs+0xc]) + #print 'cookies_offs: %x' % cookies_offs + print hex(byte0), hex(byte1), hex(byte2), hex(byte3), num_cookies for o in xrange(num_cookies): cookie_offs = coffs + cookies_offs + 0xc*o coords = struct.unpack('>fff', chunk[cookie_offs:cookie_offs + 0xc]) diff --git a/testrlan.py b/testrlan.py index dd626a0..a3a3675 100644 --- a/testrlan.py +++ b/testrlan.py @@ -1 +1,19 @@ -() \ No newline at end of file +{ +'framesize': 70, +'flags': 1, +'anims': [ + ('RLPA', 'pic', CAT_COORDS, [ + (COORD_X, [ + (20.0, 0.0, 3.0), + (40.0, 15.0, 3.0) + ]), + (COORD_Y, [ + (10.0, 0.0, 3.0), + (30.0, 15.0, 3.0) + ]) + + ]), + + +] +} \ No newline at end of file diff --git a/testrlyt.py b/testrlyt.py index d9722e4..b260f49 100644 --- a/testrlyt.py +++ b/testrlyt.py @@ -6,8 +6,7 @@ }), ('txl1', { 'textures': [ - {'unk': 0, 'name': 'icon.tpl'}, - {'unk': 1, 'name': 'opera.tpl'}, + {'unk': 0, 'name': 'smiley.tpl'}, ] }), ('fnl1', { @@ -24,7 +23,7 @@ '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': 'opera.tpl', 'wrap_s': 0, 'wrap_t': 0 } ], # screwed up with wrap on + 'texref': [ { 'tex': 'smiley.tpl', 'wrap_s': 0, 'wrap_t': 0 } ], # screwed up with wrap on 'ua2': [ (0.0, 0.0, 0.0, 1.0, 1.0) ], 'ua3': [ (1, 4, 0x1e, 0) ], # Changing this --> image disappears (not text, though) 'ua4': None, @@ -57,64 +56,14 @@ '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': random.randint(0, 600), - #'y': random.randint(0, 600), - #'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': 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, - #}) for i in xrange(2, 29)], ('pic1', { 'alpha': 0xff, 'alpha_2': 0x0, 'angle': 0, 'flags_1': 1, # Black if omitted 'flags_2': 4, # "X, Y at center?" - 'width': 608, - 'height': 456, + 'width': 152, + 'height': 152, 'name': 'pic', 'x': 0, 'y': 0, diff --git a/write-brlan.py b/write-brlan.py index a79bcc6..a01f287 100644 --- a/write-brlan.py +++ b/write-brlan.py @@ -1,17 +1,58 @@ import sys, struct, re from ethyl import * +CAT_COORDS = 0x1000000 +CAT_2_UNK = 0x2000000 # alpha and stuff +COORD_X = 0 +COORD_Y = 1 + f = open(sys.argv[1], 'r') -chunks = eval(f.read()) +data = eval(f.read()) f.close() -assert len(chunks) == 0 # :/ +anims = data['anims'] +framesize = data['framesize'] +flags = data['flags'] + +# Assumptions: No timgs, only one pai1 +ab = '' +_b = '' +_os = '' +i = 0 +# No, by the time you ask, I won't understand this either +for animtype, elname, animcat, animents in anims: + cs = [] + for byte1, cookies in animents: + byte0 = 0 + byte2 = 2 + byte3 = 0 + c = struct.pack('>BBBBHHI', byte0, byte1, byte2, byte3, len(cookies), 0, 0xc) + for cookie in cookies: + c += struct.pack('>fff', *cookie) + cs.append(c) + assert len(animtype) == 4 + a = animtype + chr(len(animents)) + '\0\0\0' + csb = '' + for c in cs: + a += struct.pack('>I', 8 + 4*len(cs) + len(csb)) # offset + csb += c + a += csb + _ = unnullterm(elname, 0x14) + struct.pack('>II', animcat, len(ab) + 0x1c*(len(anims) - i)) + _os += struct.pack('>I', 0x14 + 4*len(anims) + len(_b)) + ab += a + _b += _ + i += 1 + +pai = struct.pack('>hbbhhI', framesize, flags, 0, 0, len(anims), +0x14) + _os + _b + ab + rlan = 'RLAN\xfe\xff\x00\x08\x00\x00\x00\x00' # size later -rlan += struct.pack('>hh', 0x10, len(chunks)) +rlan += struct.pack('>hh', 0x10, 1) rlan = rlan[:8] + struct.pack('>I', len(rlan)) + rlan[0xc:] +rlan += 'pai1' + struct.pack('>I', len(pai)+8) + pai g = open(sys.argv[2], 'wb') g.write(rlan) -- cgit v1.3.1