From ee7d9486d96d04c1928e145cda4223a93449cf5a Mon Sep 17 00:00:00 2001 From: megazig Date: Thu, 13 May 2010 03:51:05 -0500 Subject: xmlyt now keeps track of brlyt version. brlyt support added for newer brlyts from NSMBWii. ( usd1 support now and added a new element in txt1 after alignment that I'm not sure what it does though I assume it is for the drop shadow ) userdata is now handled properly even though I haven't found a use for it yet. --- brlyt.c | 169 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- brlyt.h | 19 ++++++- general.h | 6 +-- xml.c | 2 +- 4 files changed, 183 insertions(+), 13 deletions(-) diff --git a/brlyt.c b/brlyt.c index 27d1f0b..1907704 100644 --- a/brlyt.c +++ b/brlyt.c @@ -45,6 +45,7 @@ char gre1_magic[] = "gre1"; char grs1_magic[] = "grs1"; char pae1_magic[] = "pae1"; char pas1_magic[] = "pas1"; +char usd1_magic[] = "usd1"; // CONSTANTS char originX[3][15]; @@ -450,7 +451,7 @@ void BRLYT_CheckHeaderSanity(brlyt_header header, size_t filesize) printf("magic: %.4s\n", header.magic); exit(1); } - if(header.version != be32(0xfeff0008) ){ + if((header.version != be32(0xfeff0008) )&&(header.version != be32(0xfeff000a))){ printf("BRLYT version not right\n"); printf("version: %08x\n", be32(header.version) ); exit(1); @@ -672,6 +673,37 @@ void PrintBRLYTEntry_wnd1(brlyt_entry entry, u8* brlyt_file, mxml_node_t *tag) } } +void PrintBRLYTEntry_usd1(brlyt_entry entry, u8* brlyt_file, mxml_node_t *tag) +{ + // DO SOMETHING COOL + mxml_node_t *usd, *val, *isworking, *stringg; + brlyt_usdstart_chunk data; + BRLYT_fileoffset = entry.data_location; + BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_numoffs_chunk)); + mxmlElementSetAttrf(tag, "type", "%.4s", entry.magic); + int n = 0; + for (n=0;n> 24 ) & 0xff ); mxmlElementSetAttrf(color1, "g", "%02x", ( be32(data2.color1) >> 16 ) & 0xff ); @@ -1204,6 +1237,8 @@ void PrintBRLYTEntries(brlyt_entry *entries, int entrycnt, u8* brlyt_file, mxml_ PrintBRLYTEntry_wnd1(entries[i], brlyt_file, tag); }else if((FourCCsMatch(entries[i].magic, bnd1_magic) == 1)) { PrintBRLYTEntry_bnd1(entries[i], brlyt_file, tag); + }else if((FourCCsMatch(entries[i].magic, usd1_magic) == 1)) { + PrintBRLYTEntry_usd1(entries[i], brlyt_file, tag); }else if((FourCCsMatch(entries[i].magic, lyt1_magic) == 1)) { PrintBRLYTEntry_lyt1(entries[i], brlyt_file, tag); }else if((FourCCsMatch(entries[i].magic, grp1_magic) == 1)) { @@ -1285,6 +1320,7 @@ void parse_brlyt(char *filename, char *filenameout) xml = mxmlNewXML("1.0"); xmlyt = mxmlNewElement(xml, "xmlyt"); mxmlElementSetAttrf(xmlyt, "version", "%d.%d.%d%s", BENZIN_VERSION_MAJOR, BENZIN_VERSION_MINOR, BENZIN_VERSION_BUILD, BENZIN_VERSION_OTHER); + mxmlElementSetAttrf(xmlyt, "brlyt_version", "%08x", be32(header.version)); PrintBRLYTEntries(entries, entrycount, brlyt_file, xmlyt); mxmlSaveFile(xml, xmlFile, whitespace_cb); fclose(xmlFile); @@ -1299,14 +1335,24 @@ void WritePane( mxml_node_t * tree , mxml_node_t * node , u8** tagblob , u32 * b { brlyt_pane_chunk chunk; char temp[256]; + memset(temp, 0, 256); if(mxmlElementGetAttr(node, "name") != NULL) strcpy(temp, mxmlElementGetAttr(node, "name")); else{ printf("No name attribute found!\nQuitting!\n"); exit(1); } - memset(chunk.name, 0, 24); + memset(chunk.name, 0, 16); strcpy(chunk.name, temp); + memset(temp, 0, 256); + if(mxmlElementGetAttr(node, "userdata") != NULL) + strcpy(temp, mxmlElementGetAttr(node, "userdata")); + else{ + printf("No userdata attribute found!\nQuitting!\n"); + exit(1); + } + memset(chunk.userdata, 0, 8); + strcpy(chunk.userdata, temp); mxml_node_t *subnode = mxmlFindElement(node, node, "translate", NULL, NULL, MXML_DESCEND); if (subnode != NULL) @@ -1492,6 +1538,7 @@ void WriteBRLYTEntry( mxml_node_t * tree , mxml_node_t * node , u8** tagblob , u char gre1[4] = {'g', 'r', 'e', '1'}; char pas1[4] = {'p', 'a', 's', '1'}; char pae1[4] = {'p', 'a', 'e', '1'}; + char usd1[4] = {'u', 's', 'd', '1'}; if ( memcmp(temp, lyt1, sizeof(lyt1)) == 0) { @@ -1500,7 +1547,7 @@ void WriteBRLYTEntry( mxml_node_t * tree , mxml_node_t * node , u8** tagblob , u mxml_node_t *subnode = mxmlFindElement(node , node , "drawnFromMiddle", NULL, NULL, MXML_DESCEND); if (subnode != NULL) { - char tempChar[4]; + char tempChar[256]; get_value(subnode, tempChar, 256); lytheader.drawnFromMiddle = atoi(tempChar); lytheader.pad[0]=0;lytheader.pad[1]=0;lytheader.pad[2]=0; @@ -1511,14 +1558,14 @@ void WriteBRLYTEntry( mxml_node_t * tree , mxml_node_t * node , u8** tagblob , u mxml_node_t *valnode = mxmlFindElement(subnode , subnode , "width", NULL, NULL, MXML_DESCEND); if (valnode != NULL) { - char tempChar[4]; + char tempChar[256]; get_value(valnode, tempChar, 256); *(float*)(&(lytheader.width)) = atof(tempChar); } valnode = mxmlFindElement(subnode , subnode ,"height", NULL, NULL, MXML_DESCEND); if (valnode != NULL) { - char tempChar[4]; + char tempChar[256]; get_value(valnode, tempChar, 256); *(float*)(&(lytheader.height)) = atof(tempChar); @@ -3100,6 +3147,13 @@ void WriteBRLYTEntry( mxml_node_t * tree , mxml_node_t * node , u8** tagblob , u } chunk2.alignment = ( originH * 3 ) + ( originL ); } + valnode = mxmlFindElement(subnode, subnode, "whatAmI", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk2.unk_char = strtoul(tempCoord, NULL,16); + } } subnode = mxmlFindElement(node, node, "length", NULL, NULL, MXML_DESCEND); @@ -3215,7 +3269,7 @@ void WriteBRLYTEntry( mxml_node_t * tree , mxml_node_t * node , u8** tagblob , u } chunk2.name_offs=be32(0x74); - chunk2.pad[0]= 0;chunk2.pad[1]=0;chunk2.pad[2]=0; + chunk2.pad[0]= 0;chunk2.pad[1]=0; fwrite(&chunk2, sizeof(chunk2), 1, fp); *fileOffset = *fileOffset + sizeof(chunk2); @@ -3513,6 +3567,95 @@ void WriteBRLYTEntry( mxml_node_t * tree , mxml_node_t * node , u8** tagblob , u *fileOffset = *fileOffset + (sizeof(float) * numberOfPicCoords); free(picCoords); } + if ( memcmp(temp, usd1, sizeof(usd1)) == 0) + { + // DO SOMETHING COOL + brlyt_usdstart_chunk chunk; + chunk.string_count = 0; + chunk.unk2 = 0; // offset = 0 + + brlyt_usdmain_chunk chunk2; + chunk2.string_offset = 0x10; + chunk2.is_working_offset = 0xC; + chunk2.unk5 = 0; + chunk2.unk6 = 0; + chunk2.unk7 = 0; + + mxml_node_t* subnode; + for (subnode = mxmlFindElement(node, node, "usdentry", NULL, NULL, MXML_DESCEND); subnode != NULL; subnode = mxmlFindElement(subnode, node, "usdentry", NULL, NULL, MXML_DESCEND)) + { + chunk.string_count++; + } + chunk.string_count = short_swap_bytes(chunk.string_count); + fwrite(&chunk, sizeof(brlyt_usdstart_chunk), 1, fp); + *fileOffset = *fileOffset + sizeof(chunk); + + u32 * working = malloc(sizeof(u32) * short_swap_bytes(chunk.string_count)); + char * stringg = malloc(sizeof(char) * 8 * short_swap_bytes(chunk.string_count)); + memset(stringg, 0, sizeof(char) * 8 * short_swap_bytes(chunk.string_count)); + char * stringg_temp = stringg; + u32 index = 0; + + u32 big_offs = (0xC * short_swap_bytes(chunk.string_count)) + (0x4 * short_swap_bytes(chunk.string_count)); + u32 little_offs = (0xC * short_swap_bytes(chunk.string_count)); + + for (subnode = mxmlFindElement(node, node, "usdentry", NULL, NULL, MXML_DESCEND); subnode != NULL; subnode = mxmlFindElement(subnode, node, "usdentry", NULL, NULL, MXML_DESCEND)) + { + mxml_node_t *valnode = mxmlFindElement(subnode , subnode , "unk5", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempChar[256]; + get_value(valnode, tempChar, 256); + chunk2.unk5 = strtoul(tempChar, NULL, 16); + chunk2.unk5 = short_swap_bytes(chunk2.unk5); + } + valnode = mxmlFindElement(subnode , subnode , "unk6", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempChar[256]; + get_value(valnode, tempChar, 256); + chunk2.unk6 = strtoul(tempChar, NULL, 16); + } + valnode = mxmlFindElement(subnode , subnode , "unk7", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempChar[256]; + get_value(valnode, tempChar, 256); + chunk2.unk7 = strtoul(tempChar, NULL, 16); + } + valnode = mxmlFindElement(subnode , subnode , "isWorking", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempChar[256]; + get_value(valnode, tempChar, 256); + working[index] = strtoul(tempChar, NULL, 16); + working[index] = be32(working[index]); + } + valnode = mxmlFindElement(subnode , subnode , "string", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempChar[256]; + memset(tempChar, 0, 256); + get_value(valnode, tempChar, 256); + memcpy(stringg_temp, tempChar, 8); + } + chunk2.string_offset = be32(big_offs); + chunk2.is_working_offset = be32(little_offs); + fwrite(&chunk2, sizeof(brlyt_usdmain_chunk),1,fp); + *fileOffset = *fileOffset + sizeof(chunk2); + big_offs -= 0x4; // -0xC +0x8 + little_offs -=8; // -0xC +0x4 + index++; + stringg_temp+=8; + } + fwrite(working, sizeof(u32) * short_swap_bytes(chunk.string_count), 1, fp); + *fileOffset = *fileOffset + (sizeof(u32) * short_swap_bytes(chunk.string_count)); + fwrite(stringg, sizeof(char) * 8 * short_swap_bytes(chunk.string_count), 1, fp); + *fileOffset = *fileOffset + (sizeof(char) * 8 * short_swap_bytes(chunk.string_count)); + + free(working); + free(stringg); + } if ( memcmp(temp, grp1, sizeof(grp1)) == 0) { brlyt_group_chunk chunk; @@ -3611,6 +3754,15 @@ void write_brlyt(char *infile, char *outfile) printf("Couldn't get tree!\n"); exit(1); } + char tempVersion[9]; + if(mxmlElementGetAttr(tree, "brlyt_version") != NULL) + strcpy(tempVersion, mxmlElementGetAttr(tree, "brlyt_version")); + else{ + printf("No brlyt_version attribute found!\n"); + exit(1); + } + u32 versionn = strtoul(tempVersion, NULL, 16); + mxml_node_t *node; FILE* fp = fopen(outfile, "wb+"); if(fp == NULL) { @@ -3626,7 +3778,8 @@ void write_brlyt(char *infile, char *outfile) rlythead.magic[1] = 'L'; rlythead.magic[2] = 'Y'; rlythead.magic[3] = 'T'; - rlythead.version = 0xFEFF0008; + //rlythead.version = 0xFEFF0008; + rlythead.version = versionn; rlythead.filesize = 0; rlythead.lyt_offset = sizeof(brlyt_header); rlythead.sections = 1; diff --git a/brlyt.h b/brlyt.h index 8260e54..c4fafbb 100644 --- a/brlyt.h +++ b/brlyt.h @@ -64,7 +64,8 @@ typedef struct u16 mat_num; u16 font_idx; u8 alignment; - u8 pad[3]; + u8 unk_char; + u8 pad[2]; u32 name_offs; u32 color1; u32 color2; @@ -131,6 +132,22 @@ typedef struct u16 unk; } brlyt_group_chunk; +typedef struct +{ + /* possible a numoffs */ + u16 string_count; + u16 unk2; +} brlyt_usdstart_chunk; + +typedef struct +{ + u32 string_offset; + u32 is_working_offset; + u16 unk5; + u8 unk6; + u8 unk7; +} brlyt_usdmain_chunk; + typedef struct { u16 num; diff --git a/general.h b/general.h index 40419d4..7e87045 100644 --- a/general.h +++ b/general.h @@ -10,9 +10,9 @@ * All Rights Reserved, HACKERCHANNEL. * ******************************************************************************/ -#define BENZIN_VERSION_MAJOR 1 -#define BENZIN_VERSION_MINOR 9 -#define BENZIN_VERSION_BUILD 9 +#define BENZIN_VERSION_MAJOR 2 +#define BENZIN_VERSION_MINOR 1 +#define BENZIN_VERSION_BUILD 3 #define BENZIN_VERSION_OTHER "BETA" #define INFORMATION_TEXT \ diff --git a/xml.c b/xml.c index bb8c24c..8854408 100644 --- a/xml.c +++ b/xml.c @@ -96,7 +96,7 @@ const char *whitespace_cb(mxml_node_t *node, int where) } if (where == 3 || where == 1){ return ""; - }else if(((node->prev && where == 0) || node->parent) && !(where == 2 && strcmp(name, "rotate") && strcmp(name, "scale") && strcmp(name, "translate") && strcmp(name, "xmlyt") && strcmp(name, "xmlan") && strcmp(name, "entries") && strcmp(name, "triplet") && strcmp(name, "pair") && strcmp(name, "entry") && strcmp(name, "pane") && (strcmp(name, "tag") && strcmp(name, "size") && strcmp(name, "material") && strcmp(name, "vtx") && strcmp(name, "colors") && strcmp(name, "subs") && strcmp(name, "font") && strcmp(name, "wnd4") && strcmp(name, "wnd4mat") && strcmp(name, "set") && strcmp(name, "coordinates") && strcmp(name, "TevStage") && strcmp(name, "texture") && strcmp(name, "TextureSRT") && strcmp(name, "CoordGen") && strcmp(name, "ChanControl") && strcmp(name, "MaterialColor") && strcmp(name, "TevSwapModeTable") && strcmp(name, "IndTextureSRT") && strcmp(name, "IndTextureOrder") && strcmp(name, "AlphaCompare") && strcmp(name, "BlendMode") )) ){ + }else if(((node->prev && where == 0) || node->parent) && !(where == 2 && strcmp(name, "rotate") && strcmp(name, "scale") && strcmp(name, "translate") && strcmp(name, "xmlyt") && strcmp(name, "xmlan") && strcmp(name, "entries") && strcmp(name, "triplet") && strcmp(name, "pair") && strcmp(name, "entry") && strcmp(name, "pane") && (strcmp(name, "tag") && strcmp(name, "size") && strcmp(name, "material") && strcmp(name, "vtx") && strcmp(name, "colors") && strcmp(name, "subs") && strcmp(name, "usdentry") && strcmp(name, "font") && strcmp(name, "wnd4") && strcmp(name, "wnd4mat") && strcmp(name, "set") && strcmp(name, "coordinates") && strcmp(name, "TevStage") && strcmp(name, "texture") && strcmp(name, "TextureSRT") && strcmp(name, "CoordGen") && strcmp(name, "ChanControl") && strcmp(name, "MaterialColor") && strcmp(name, "TevSwapModeTable") && strcmp(name, "IndTextureSRT") && strcmp(name, "IndTextureOrder") && strcmp(name, "AlphaCompare") && strcmp(name, "BlendMode") )) ){ sprintf( xmlbuff , "\n%s" , tab_buffer ); }else{ return ""; -- cgit v1.3.1