From 32c186f304bd31b6b74e0d8c678cbf137b721fad Mon Sep 17 00:00:00 2001 From: megazig Date: Wed, 11 Mar 2009 21:56:25 -0500 Subject: first crack at brlyt --- brlyt.c | 548 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---------- brlyt.h | 133 +++++++++++++--- 2 files changed, 576 insertions(+), 105 deletions(-) diff --git a/brlyt.c b/brlyt.c index 64c99e6..7123b1d 100644 --- a/brlyt.c +++ b/brlyt.c @@ -3,6 +3,7 @@ * * * Created by Alex Marshall on 09/01/27. + * Updated by Stephen Simpson on 09/03/11. * Copyright 2009 __MyCompanyName__. All rights reserved. * */ @@ -29,9 +30,16 @@ char grp1_magic[] = "grp1"; char txl1_magic[] = "txl1"; char mat1_magic[] = "mat1"; char fnl1_magic[] = "fnl1"; +char txt1_magic[] = "txt1"; +char gre1_magic[] = "gre1"; +char grs1_magic[] = "grs1"; +char pae1_magic[] = "pae1"; +char pas1_magic[] = "pas1"; static size_t BRLYT_fileoffset = 0; +//linked_list_materials materials; + static int FourCCsMatch(fourcc cc1, fourcc cc2) { dbgprintf("FourCCs\n"); @@ -67,6 +75,91 @@ static void BRLYT_ReadDataFromMemory(void* destination, void* input, size_t size BRLYT_fileoffset += size; } +float float_swap_bytes(float float1) +{ + unsigned char *float1c; float1c = (unsigned char*)&float1; + + unsigned char charTemp = 0x00; + charTemp = float1c[0]; float1c[0] = float1c[3]; float1c[3] = charTemp; + charTemp = 0x00; + charTemp = float1c[1]; float1c[1] = float1c[2]; float1c[2] = charTemp; + + float *newFloat; newFloat = (float*)float1c; + return *newFloat; +} + +unsigned short short_swap_bytes(unsigned short short1) +{ + unsigned char *short1c; short1c = (unsigned char*)&short1; + + unsigned char charTemp = 0x00; + charTemp = short1c[0]; short1c[0] = short1c[1]; short1c[1] = charTemp; + + unsigned short *newShort; newShort = (unsigned short*)short1c; + return *newShort; +} + +int bit_extract(unsigned int num, unsigned int start, unsigned int end) +{ + if (end == 100) end = start; + //simple bitmask, figure out when awake + //unsigned int mask = (2**(31 - start + 1) - 1) - (2**(31 - end) - 1) + unsigned int mask; + int first = 0; + int firstMask = 0; + if (start<32) firstMask = 1; + + for (first;first<31-start+1;first++) + { + firstMask *= 2; + } + firstMask -= 1; + first = 0; + int secondMask = 0; + if (end<31) secondMask = 1; + + for (first;first< 31-end;first++) + { + secondMask *=2; + } + mask = firstMask = secondMask; + int ret = (num & mask) >> (31 - end); + return ret; +} + +/* +void get_opt(char* chunk, int startpos, bool enabled, int size, char* item_type) +{ +// if (!enabled) { +// return None, startpos + if (item_type != "None") { + //parse_data is your memcopy from chunk to struct_item_type + ret = parse_data(chunk[startpos:startpos+size], item_type) + }else if (size == 4) { + ret = struct.unpack('>I', chunk[startpos:startpos+4])[0] + }else if (size % 4 == 0) { + ret = struct.unpack('>' + 'I'*(size/4), chunk[startpos:startpos+size]) + }else + raise Exception('unhandled') + return ret, startpos + size +} + +void get_array(char *chunk, int startpos, int array_size, int item_size, char *item_type): +{ + ar = [] + int pos = startpos; + + int n = 0; + for (n;n 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') + //# 4 * flags[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, '4b') + //# 0x14 * flags[17-18] + 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, '4b') + //# 0x10 * flags[9-13] + mat['ua9'], 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, ' 4b') + //# 4 * flags[7] + 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]) + if next_offset - 8 != mpos: + mat['~_insane'] = next_offset - 8 - mpos //# Extra shit we di dn't parse :( + } + mat['unk_bit_5'] = bit_extract(flags, 5) + mat['unk_bits_0_3'] = bit_extract(flags, 0, 3) //# Overwritten by stu ff + vars['materials'].append(mat) + pos += 4 + */ + } +} + +void PrintBRLYTEntry_gre1(brlyt_entry entry, u8* brlyt_file) +{ + //brlyt_numoffs_chunk data; + //BRLYT_fileoffset = entry.data_location; + //BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_numoffs_chunk)); + //PRINT CRAP + printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); + //printf(" num: %08x\n", be16(data.num)); + //group end info +} + +void PrintBRLYTEntry_grs1(brlyt_entry entry, u8* brlyt_file) +{ + //brlyt_numoffs_chunk data; + //BRLYT_fileoffset = entry.data_location; + //BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_numoffs_chunk)); + //PRINT CRAP + printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); + //printf(" num: %08x\n", be16(data.num)); + //group start info +} + +void PrintBRLYTEntry_pae1(brlyt_entry entry, u8* brlyt_file) +{ + //brlyt_numoffs_chunk data; + //BRLYT_fileoffset = entry.data_location; + //BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_numoffs_chunk)); + //PRINT CRAP + printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); + //printf(" num: %08x\n", be16(data.num)); + //panel end info +} + +void PrintBRLYTEntry_pas1(brlyt_entry entry, u8* brlyt_file) +{ + //brlyt_numoffs_chunk data; + //BRLYT_fileoffset = entry.data_location; + //BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_numoffs_chunk)); + //PRINT CRAP + printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); + //printf(" num: %08x\n", be16(data.num)); + //panel start info } void PrintBRLYTEntries(brlyt_entry *entries, int entrycnt, u8* brlyt_file) { + dbgprintf("Printing BRLYT Entries"); int i; for(i = 0; i < entrycnt; i++) { printf("\n Index %d (@%08x):\n", i, entries[i].data_location - 8); - if((FourCCsMatch(entries[i].magic, pic1_magic) == 1) || (FourCCsMatch(entries[i].magic, pan1_magic) == 1) || - (FourCCsMatch(entries[i].magic, bnd1_magic) == 1) || (FourCCsMatch(entries[i].magic, wnd1_magic) == 1)) { + if((FourCCsMatch(entries[i].magic, pan1_magic) == 1)) { + dbgprintf("pan1\n"); + PrintBRLYTEntry_pan1(entries[i], brlyt_file); + }else if((FourCCsMatch(entries[i].magic, txt1_magic) == 1)) { + dbgprintf("txt1\n"); + PrintBRLYTEntry_txt1(entries[i], brlyt_file); + }else if((FourCCsMatch(entries[i].magic, pic1_magic) == 1)) { dbgprintf("pic1\n"); -// PrintBRLYTEntry_pic1(entries[i], brlyt_file); - brlyt_pic1_chunk data; - BRLYT_fileoffset = entries[i].data_location; - BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_pic1_chunk)); - printf("%08x\n", BRLYT_fileoffset); - printf(" Name: %s (%08x)\n", data.name); - printf(" Type: %c%c%c%c\n", entries[i].magic[0], entries[i].magic[1], entries[i].magic[2], entries[i].magic[3]); - printf(" Flags: %04x (%08x)\n", be16(data.flags)); - printf(" Alpha: %04x (%08x)\n", be16(data.alpha)); - printf(" X: %f (%08x) (%08x)\n", be32(data.x), &data.x, &data); - printf(" Y: %f (%08x)\n", be32(data.y)); - printf(" X Magnification: %f (%08x)\n", be32(data.xmag)); - printf(" Y Magnification: %f (%08x)\n", be32(data.ymag)); - printf(" Width: %f (%08x)\n", be32(data.width)); - printf(" Height: %f (%08x)\n", be32(data.height)); - printf(" Angle: %f (%08x)\n", be32(data.angle)); - printf(" unk1: %f (%08x)\n", be32(data.unk[0])); - printf(" unk2: %f (%08x)\n", be32(data.unk[1])); - printf(" unk3: %f (%08x)\n", be32(data.unk[2])); + PrintBRLYTEntry_pic1(entries[i], brlyt_file); + }else if((FourCCsMatch(entries[i].magic, wnd1_magic) == 1)) { + dbgprintf("wnd1\n"); + PrintBRLYTEntry_wnd1(entries[i], brlyt_file); + }else if((FourCCsMatch(entries[i].magic, bnd1_magic) == 1)) { + dbgprintf("bnd1\n"); + PrintBRLYTEntry_bnd1(entries[i], brlyt_file); }else if((FourCCsMatch(entries[i].magic, lyt1_magic) == 1)) { dbgprintf("lyt1\n"); PrintBRLYTEntry_lyt1(entries[i], brlyt_file); }else if((FourCCsMatch(entries[i].magic, grp1_magic) == 1)) { dbgprintf("grp1\n"); PrintBRLYTEntry_grp1(entries[i], brlyt_file); - }else if((FourCCsMatch(entries[i].magic, txl1_magic) == 1) || (FourCCsMatch(entries[i].magic, mat1_magic) == 1) || - (FourCCsMatch(entries[i].magic, fnl1_magic) == 1)) { + }else if((FourCCsMatch(entries[i].magic, txl1_magic) == 1)) { + dbgprintf("txl1\n"); + PrintBRLYTEntry_txl1(entries[i], brlyt_file); + }else if((FourCCsMatch(entries[i].magic, fnl1_magic) == 1)) { dbgprintf("img\n"); - PrintBRLYTEntry_img(entries[i], brlyt_file); + PrintBRLYTEntry_fnl1(entries[i], brlyt_file); + }else if((FourCCsMatch(entries[i].magic, mat1_magic) == 1)) { + dbgprintf("mat1\n"); + PrintBRLYTEntry_mat1(entries[i], brlyt_file); + }else if((FourCCsMatch(entries[i].magic, gre1_magic) == 1)) { + dbgprintf("gre1\n"); + PrintBRLYTEntry_gre1(entries[i], brlyt_file); + }else if((FourCCsMatch(entries[i].magic, grs1_magic) == 1)) { + dbgprintf("grs1\n"); + PrintBRLYTEntry_grs1(entries[i], brlyt_file); + }else if((FourCCsMatch(entries[i].magic, pae1_magic) == 1)) { + dbgprintf("pae1\n"); + PrintBRLYTEntry_pae1(entries[i], brlyt_file); + }else if((FourCCsMatch(entries[i].magic, pas1_magic) == 1)) { + dbgprintf("pas1\n"); + PrintBRLYTEntry_pas1(entries[i], brlyt_file); }else printf(" Unknown tag (%c%c%c%c)!\n",entries[i].magic[0],entries[i].magic[1],entries[i].magic[2],entries[i].magic[3]); } @@ -254,42 +673,3 @@ void make_brlyt(char* infile, char* outfile) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/brlyt.h b/brlyt.h index 57c9bc7..bb7afe8 100644 --- a/brlyt.h +++ b/brlyt.h @@ -1,8 +1,9 @@ /* * brlyt.h - * + * * * Created by Alex Marshall on 09/01/27. + * Updated by Stephen Simpson on 09/03/11. * Copyright 2009 __MyCompanyName__. All rights reserved. * */ @@ -12,6 +13,15 @@ #include "types.h" +//#define BIGENDSHORT(y) ((y >> 24) & 0xFF00) + ((y >>8) & 0x00FF) +//#define BIGENDINT(y) ( ( y << 24 ) & 0xFF000000) + ( ( y << 8 ) & 0x00FF0000 ) + ( ( y >> 8 ) & 0x0000FF00 ) + ( ( y >> 24 ) & 0x000000FF ) + +//struct linked_list_materials +//{ +// char name[12]; +// struct linked_list_materials *next; +//}; + typedef struct { fourcc magic; // RLYT @@ -36,39 +46,120 @@ typedef struct typedef struct { - u16 flags; - u16 alpha; - char name[0x18]; - f32 x; - f32 y; - f32 unk[3]; - f32 angle; - f32 xmag; - f32 ymag; - f32 width; - f32 height; -} brlyt_pic1_chunk; + unsigned char flag1; + unsigned char flag2; + unsigned char alpha; + unsigned char alpha2; + char name[24]; + float x; + float y; + float z; + float flip_x; + float flip_y; + float angle; + float xmag; + float ymag; + float width; + float height; +} brlyt_pane_chunk; + +typedef struct +{ + u16 len1; + u16 len2; + u16 mat_off; + u16 font_idx; + u8 unk4; + u8 pad[3]; // [0, 0, 0] + u32 name_offs; + u32 color1; + u32 color2; + float font_size_x; + float font_size_y; + float char_space; + float line_space; +} brlyt_text_chunk; + +typedef struct +{ + u32 vtx_colors[4]; // [4294967295L, 4294967295L, 4294967295L, 4294967295L] + u16 mat_off; + u8 num_texcoords; + u8 padding; // 0 +} brlyt_pic_chunk; typedef struct { - u32 unk[3]; -} brlyt_lyt1_chunk; + int a; + float width; + float height; +} brlyt_lytheader_chunk; typedef struct { - char name[16]; - u16 numsubs; - u16 unk; -} brlyt_grp1_chunkbase; + char name[16]; + u16 numsubs; + u16 unk; +} brlyt_group_chunk; typedef struct { u16 num; u16 offs; -} brlyt_img_chunk; -// grs1, gre1, pas1, and pae1 all don't have anything special. they seem to just be prefixes to some sections. +} brlyt_numoffs_chunk; + +typedef struct +{ + char name[20]; + s16 tev_color[4]; + s16 unk_color[4]; + s16 unk_color_2[4]; + u32 tev_kcolor[4]; + u32 flags; +} brlyt_material_chunk; + +typedef struct +{ + int offset; + int unk; +} brlyt_offsunk_chunk; + +typedef struct +{ + u16 tex_offs; + u8 wrap_s; + u8 wrap_t; +} brlyt_texref_chunk; + +typedef struct +{ + float unk[5]; +} brlyt_ua2_chunk; + +typedef struct +{ + u8 unk[4]; +} brlyt_4b_chunk; + +typedef struct +{ + u32 a; + u32 b; + float c; + u32 d; + u32 e; +} brlyt_ua7_chunk; + +typedef struct +{ + u8 unk[16]; +} brlyt_10b_chunk; + +void swapBytes(unsigned char* char1, unsigned char* char2); +int bitExtraction(unsigned int num, unsigned int start, unsigned int end); void parse_brlyt(char *filename); void make_brlyt(char* infile, char* outfile); #endif //BRLYT_H_ + -- cgit v1.3.1