From 872a7b2efde01039ad2aa888ae6460467704ff71 Mon Sep 17 00:00:00 2001 From: megazig Date: Sat, 19 Sep 2009 11:57:34 -0500 Subject: updated to 1.9 with lots of changes --- brlan.c | 1565 +++++++++++++++++++++------------------ brlan.h | 146 ++-- brlyt.c | 2422 +++++++++++++++++++++++++++++++++++++++++++++++++------------ brlyt.h | 280 ++++--- general.h | 4 +- 5 files changed, 3107 insertions(+), 1310 deletions(-) diff --git a/brlan.c b/brlan.c index 5a6f6e2..4ab2e8b 100644 --- a/brlan.c +++ b/brlan.c @@ -24,823 +24,968 @@ #define dbgprintf // #endif //DEBUGBRLAN -#define MAXIMUM_TAGS_SIZE (0xf000) -#define MAXIMUM_TIMGS_SIZE (0x1000) +#define MAXIMUM_TAGS_SIZE (0xf000) +#define MAXIMUM_TIMGS_SIZE (0x1000) fourcc tag_FourCCs[] = { "RLPA", "RLTS", "RLVI", "RLVC", "RLMC", "RLTP" , "RLIM" }; char tag_types_list[15][24]; -char tag_types_rlmc_list[15][24]; +char tag_types_rlpa_list[15][24]; +char tag_types_rlts_list[15][24]; +char tag_types_rlvi_list[15][24]; char tag_types_rlvc_list[15][24]; +char tag_types_rlmc_list[15][24]; +char tag_types_rltp_list[15][24]; +char tag_types_rlim_list[15][24]; static size_t BRLAN_fileoffset = 0; FILE* xmlanout; static void BRLAN_ReadDataFromMemoryX(void* destination, void* input, size_t size) { - u8* out = (u8*)destination; - u8* in = ((u8*)input) + BRLAN_fileoffset; - memcpy(out, in, size); + u8* out = (u8*)destination; + u8* in = ((u8*)input) + BRLAN_fileoffset; + memcpy(out, in, size); } static void BRLAN_ReadDataFromMemory(void* destination, void* input, size_t size) { - BRLAN_ReadDataFromMemoryX(destination, input, size); - BRLAN_fileoffset += size; + BRLAN_ReadDataFromMemoryX(destination, input, size); + BRLAN_fileoffset += size; } -static void CreateGlobal_pai1(brlan_pai1_header_type2 *pai1_header, brlan_pai1_header_type1 pai1_header1, - brlan_pai1_header_type2 pai1_header2, int pai1_header_type) +static void CreateGlobal_pai1(brlan_pai1_header_type2 *pai1_header, brlan_pai1_header_type1 pai1_header1, brlan_pai1_header_type2 pai1_header2, int pai1_header_type) { - if(pai1_header_type == 1) { - pai1_header->magic[0] = pai1_header1.magic[0]; - pai1_header->magic[1] = pai1_header1.magic[1]; - pai1_header->magic[2] = pai1_header1.magic[2]; - pai1_header->magic[3] = pai1_header1.magic[3]; - pai1_header->size = pai1_header1.size; - pai1_header->framesize = pai1_header1.framesize; - pai1_header->flags = pai1_header1.flags; - pai1_header->unk1 = pai1_header1.unk1; - pai1_header->num_timgs = pai1_header1.num_timgs; - pai1_header->num_entries = pai1_header1.num_entries; - pai1_header->unk2 = 0; - pai1_header->entry_offset = pai1_header1.entry_offset; - }else - memcpy(pai1_header, &pai1_header2, sizeof(brlan_pai1_header_type2)); + if(pai1_header_type == 1) { + pai1_header->magic[0] = pai1_header1.magic[0]; + pai1_header->magic[1] = pai1_header1.magic[1]; + pai1_header->magic[2] = pai1_header1.magic[2]; + pai1_header->magic[3] = pai1_header1.magic[3]; + pai1_header->size = pai1_header1.size; + pai1_header->framesize = pai1_header1.framesize; + pai1_header->flags = pai1_header1.flags; + pai1_header->padding = pai1_header1.padding; + pai1_header->num_timgs = pai1_header1.num_timgs; + pai1_header->num_entries = pai1_header1.num_entries; + pai1_header->padding2 = 0; + pai1_header->entry_offset = pai1_header1.entry_offset; + }else + memcpy(pai1_header, &pai1_header2, sizeof(brlan_pai1_header_type2)); } static int FourCCsMatch(fourcc cc1, fourcc cc2) { - if((cc1[0] == cc2[0]) && (cc1[1] == cc2[1]) && (cc1[2] == cc2[2]) && (cc1[3] == cc2[3])) - return 1; - else - return 0; + if((cc1[0] == cc2[0]) && (cc1[1] == cc2[1]) && (cc1[2] == cc2[2]) && (cc1[3] == cc2[3])) + return 1; + else + return 0; } static int FourCCInList(fourcc cc) { - int i; - for(i = 0; i < 7; i++) - if(FourCCsMatch(cc, tag_FourCCs[i])) return 1; - return 0; + int i; + for(i = 0; i < 7; i++) + if(FourCCsMatch(cc, tag_FourCCs[i])) return 1; + return 0; } void BRLAN_CreateXMLTag(tag_header tagHeader, void* data, u32 offset, mxml_node_t *pane) { - BRLAN_fileoffset = offset; - BRLAN_ReadDataFromMemory(&tagHeader, data, sizeof(tag_header)); - - mxml_node_t *tag; - tag = mxmlNewElement(pane, "tag"); mxmlElementSetAttrf(tag, "type", "%c%c%c%c", tagHeader.magic[0], tagHeader.magic[1], tagHeader.magic[2], tagHeader.magic[3]); - - tag_entryinfo tagEntryInfo; - u32 tagentrylocations[tagHeader.entry_count]; - BRLAN_ReadDataFromMemory(&tagentrylocations, data, tagHeader.entry_count * sizeof(u32)); - u32 i, j; - for ( i = 0; i < tagHeader.entry_count; i++) - { - mxml_node_t *entry; - BRLAN_fileoffset = offset + be32(tagentrylocations[i]); - BRLAN_ReadDataFromMemory(&tagEntryInfo, data, sizeof(tag_entryinfo)); - if(short_swap_bytes(tagEntryInfo.type) < 16) - { - char type_rlmc[4] = {'R', 'L', 'M', 'C'}; - char type_rlvc[4] = {'R', 'L', 'V', 'C'}; - if(memcmp(tagHeader.magic, type_rlmc, 4) == 0) - { - entry = mxmlNewElement(tag, "entry"); mxmlElementSetAttrf(entry, "type", "%s", tag_types_rlmc_list[short_swap_bytes(tagEntryInfo.type)]); - } else if (memcmp(tagHeader.magic, type_rlvc, 4) == 0) { - entry = mxmlNewElement(tag, "entry"); mxmlElementSetAttrf(entry, "type", "%s", tag_types_rlvc_list[short_swap_bytes(tagEntryInfo.type)]); - } else { - entry = mxmlNewElement(tag, "entry"); mxmlElementSetAttrf(entry, "type", "%s", tag_types_list[short_swap_bytes(tagEntryInfo.type)]); - } - } else { - entry = mxmlNewElement(tag, "entry"); mxmlElementSetAttrf(entry, "type", "%u", short_swap_bytes(tagEntryInfo.type)); - } + BRLAN_fileoffset = offset; + BRLAN_ReadDataFromMemory(&tagHeader, data, sizeof(tag_header)); - for( j = 0; j < short_swap_bytes(tagEntryInfo.coord_count); j++) - { - if ( tagEntryInfo.unk1 == 0x2 ) - { - mxml_node_t *triplet; - mxml_node_t *frame; - mxml_node_t *value; - mxml_node_t *blend; - tag_data tagData; - BRLAN_ReadDataFromMemory(&tagData, data, sizeof(tag_data)); - - u32 p1 = be32(tagData.part1); - u32 p2 = be32(tagData.part2); - u32 p3 = be32(tagData.part3); - triplet = mxmlNewElement(entry, "triplet"); - frame = mxmlNewElement(triplet, "frame"); mxmlNewTextf(frame, 0, "%.15f", *(f32*)(&p1)); - value = mxmlNewElement(triplet, "value"); mxmlNewTextf(value, 0, "%.15f", *(f32*)(&p2)); - blend = mxmlNewElement(triplet, "blend"); mxmlNewTextf(blend, 0, "%.15f", *(f32*)(&p3)); - } else { - tag_data2 tagData2; - BRLAN_ReadDataFromMemory(&tagData2, data, sizeof(tag_data2)); - - mxml_node_t *pair; - mxml_node_t *data1; - mxml_node_t *data2; - mxml_node_t *padding; - u32 p1 = be32(tagData2.part1); - u16 p2 = short_swap_bytes(tagData2.part2); - u16 p3 = short_swap_bytes(tagData2.padding); - pair = mxmlNewElement(entry, "pair"); - data1 = mxmlNewElement(pair, "data1"); mxmlNewTextf(data1, 0, "%.15f", *(f32*)(&p1)); - data2 = mxmlNewElement(pair, "data2"); mxmlNewTextf(data2, 0, "%04x", p2); - padding = mxmlNewElement(pair, "padding"); mxmlNewTextf(padding, 0, "%04x", p3); - } - } - } + mxml_node_t *tag; + tag = mxmlNewElement(pane, "tag"); mxmlElementSetAttrf(tag, "type", "%c%c%c%c", tagHeader.magic[0], tagHeader.magic[1], tagHeader.magic[2], tagHeader.magic[3]); + + tag_entryinfo tagEntryInfo; + u32 tagentrylocations[tagHeader.entry_count]; + BRLAN_ReadDataFromMemory(&tagentrylocations, data, tagHeader.entry_count * sizeof(u32)); + u32 i, j; + for ( i = 0; i < tagHeader.entry_count; i++) + { + mxml_node_t *entry; + BRLAN_fileoffset = offset + be32(tagentrylocations[i]); + BRLAN_ReadDataFromMemory(&tagEntryInfo, data, sizeof(tag_entryinfo)); + entry = mxmlNewElement(tag, "entry"); + mxmlElementSetAttrf(entry, "type1", "%u", tagEntryInfo.type1); + if(tagEntryInfo.type2 < 16) + { + char type_rlpa[4] = {'R', 'L', 'P', 'A'}; + char type_rlts[4] = {'R', 'L', 'T', 'S'}; + char type_rlvi[4] = {'R', 'L', 'V', 'I'}; + char type_rlvc[4] = {'R', 'L', 'V', 'C'}; + char type_rlmc[4] = {'R', 'L', 'M', 'C'}; + char type_rltp[4] = {'R', 'L', 'T', 'P'}; + char type_rlim[4] = {'R', 'L', 'I', 'M'}; + if(memcmp(tagHeader.magic, type_rlpa, 4) == 0) + { + mxmlElementSetAttrf(entry, "type2", "%s", tag_types_rlpa_list[tagEntryInfo.type2]); + } else if (memcmp(tagHeader.magic, type_rlts, 4) == 0) { + mxmlElementSetAttrf(entry, "type2", "%s", tag_types_rlts_list[tagEntryInfo.type2]); + } else if (memcmp(tagHeader.magic, type_rlvi, 4) == 0) { + mxmlElementSetAttrf(entry, "type2", "%s", tag_types_rlvi_list[tagEntryInfo.type2]); + } else if (memcmp(tagHeader.magic, type_rlvc, 4) == 0) { + mxmlElementSetAttrf(entry, "type2", "%s", tag_types_rlvc_list[tagEntryInfo.type2]); + } else if (memcmp(tagHeader.magic, type_rlmc, 4) == 0) { + mxmlElementSetAttrf(entry, "type2", "%s", tag_types_rlmc_list[tagEntryInfo.type2]); + } else if (memcmp(tagHeader.magic, type_rltp, 4) == 0) { + mxmlElementSetAttrf(entry, "type2", "%s", tag_types_rltp_list[tagEntryInfo.type2]); + } else if (memcmp(tagHeader.magic, type_rlim, 4) == 0) { + mxmlElementSetAttrf(entry, "type2", "%s", tag_types_rlim_list[tagEntryInfo.type2]); + } else { + mxmlElementSetAttrf(entry, "type2", "%s", tag_types_list[tagEntryInfo.type2]); + } + } else { + mxmlElementSetAttrf(entry, "type2", "%u", tagEntryInfo.type2); + } + + for( j = 0; j < short_swap_bytes(tagEntryInfo.coord_count); j++) + { + if ( tagEntryInfo.data_type == 0x2 ) + { + mxml_node_t *triplet; + mxml_node_t *frame; + mxml_node_t *value; + mxml_node_t *blend; + tag_data tagData; + BRLAN_ReadDataFromMemory(&tagData, data, sizeof(tag_data)); + + u32 p1 = be32(tagData.part1); + u32 p2 = be32(tagData.part2); + u32 p3 = be32(tagData.part3); + triplet = mxmlNewElement(entry, "triplet"); + frame = mxmlNewElement(triplet, "frame"); mxmlNewTextf(frame, 0, "%.15f", *(f32*)(&p1)); + value = mxmlNewElement(triplet, "value"); mxmlNewTextf(value, 0, "%.15f", *(f32*)(&p2)); + blend = mxmlNewElement(triplet, "blend"); mxmlNewTextf(blend, 0, "%.15f", *(f32*)(&p3)); + } else { + tag_data2 tagData2; + BRLAN_ReadDataFromMemory(&tagData2, data, sizeof(tag_data2)); + + mxml_node_t *pair; + mxml_node_t *data1; + mxml_node_t *data2; + mxml_node_t *padding; + u32 p1 = be32(tagData2.part1); + u16 p2 = short_swap_bytes(tagData2.part2); + u16 p3 = short_swap_bytes(tagData2.padding); + pair = mxmlNewElement(entry, "pair"); + data1 = mxmlNewElement(pair, "data1"); mxmlNewTextf(data1, 0, "%.15f", *(f32*)(&p1)); + data2 = mxmlNewElement(pair, "data2"); mxmlNewTextf(data2, 0, "%04x", p2); + padding = mxmlNewElement(pair, "padding"); mxmlNewTextf(padding, 0, "%04x", p3); + } + } + } } void parse_brlan(char* filename, char *filenameout) { - FILE* fp = fopen(filename, "rb"); - if(fp == NULL) { - printf("Error! Couldn't open %s!\n", filename); - exit(1); - } - fseek(fp, 0, SEEK_END); - u32 lengthOfFile = ftell(fp); - fseek(fp, 0, SEEK_SET); - u8 data[lengthOfFile]; - fread(data, lengthOfFile, 1, fp); - - int i, j; - for(i = 0; i < 16; i++) - { - memset(tag_types_list[i], 0, 24); - memset(tag_types_rlmc_list[i], 0, 24); - memset(tag_types_rlvc_list[i], 0, 24); - } - strcpy(tag_types_list[0], "X Translation"); - strcpy(tag_types_list[1], "Y Translation"); - strcpy(tag_types_list[2], "Z Translation"); - strcpy(tag_types_list[3], "X Flip"); - strcpy(tag_types_list[4], "Y Flip"); - strcpy(tag_types_list[5], "Angle"); - strcpy(tag_types_list[6], "X Zoom"); - strcpy(tag_types_list[7], "Y Zoom"); - strcpy(tag_types_list[8], "Width"); - strcpy(tag_types_list[9], "Height"); - strcpy(tag_types_list[10], "0x0A"); - strcpy(tag_types_list[11], "0x0B"); - strcpy(tag_types_list[12], "0x0C"); - strcpy(tag_types_list[13], "0x0D"); - strcpy(tag_types_list[14], "0x0E"); - strcpy(tag_types_list[15], "0x0F"); - - strcpy(tag_types_rlmc_list[0], "0x00"); - strcpy(tag_types_rlmc_list[1], "0x01"); - strcpy(tag_types_rlmc_list[2], "0x02"); - strcpy(tag_types_rlmc_list[3], "0x03"); - strcpy(tag_types_rlmc_list[4], "Blackcolor R"); - strcpy(tag_types_rlmc_list[5], "Blackcolor G"); - strcpy(tag_types_rlmc_list[6], "Blackcolor B"); - strcpy(tag_types_rlmc_list[7], "Blackcolor A"); - strcpy(tag_types_rlmc_list[8], "Whitecolor R"); - strcpy(tag_types_rlmc_list[9], "Whitecolor G"); - strcpy(tag_types_rlmc_list[10], "Whitecolor B"); - strcpy(tag_types_rlmc_list[11], "Whitecolor A"); - strcpy(tag_types_rlmc_list[12], "0x0C"); - strcpy(tag_types_rlmc_list[13], "0x0D"); - strcpy(tag_types_rlmc_list[14], "0x0E"); - strcpy(tag_types_rlmc_list[15], "0x0F"); - - strcpy(tag_types_rlvc_list[0], "Top Left R"); - strcpy(tag_types_rlvc_list[1], "Top Left G"); - strcpy(tag_types_rlvc_list[2], "Top Left B"); - strcpy(tag_types_rlvc_list[3], "Top Left A"); - strcpy(tag_types_rlvc_list[4], "Top Right R"); - strcpy(tag_types_rlvc_list[5], "Top Right G"); - strcpy(tag_types_rlvc_list[6], "Top Right B"); - strcpy(tag_types_rlvc_list[7], "Top Right A"); - strcpy(tag_types_rlvc_list[8], "Bottom Left R"); - strcpy(tag_types_rlvc_list[9], "Bottom Left G"); - strcpy(tag_types_rlvc_list[10], "Bottom Left B"); - strcpy(tag_types_rlvc_list[11], "Bottom Left A"); - strcpy(tag_types_rlvc_list[12], "Bottom Right R"); - strcpy(tag_types_rlvc_list[13], "Bottom Right G"); - strcpy(tag_types_rlvc_list[14], "Bottom Right B"); - strcpy(tag_types_rlvc_list[15], "Bottom Right A"); - - BRLAN_fileoffset = 0; - brlan_header header; - BRLAN_ReadDataFromMemoryX(&header, data, sizeof(brlan_header)); - BRLAN_fileoffset = short_swap_bytes(header.pai1_offset); - brlan_pai1_universal universal; - BRLAN_ReadDataFromMemoryX(&universal, data, sizeof(brlan_pai1_universal)); - - int pai1_header_type; - brlan_pai1_header_type1 pai1_header1; - brlan_pai1_header_type2 pai1_header2; - brlan_pai1_header_type2 pai1_header; - - if((be32(universal.flags) & (1 << 25)) >= 1) { - pai1_header_type = 2; - BRLAN_ReadDataFromMemory(&pai1_header2, data, sizeof(brlan_pai1_header_type2)); - } else { - pai1_header_type = 1; - BRLAN_ReadDataFromMemory(&pai1_header1, data, sizeof(brlan_pai1_header_type1)); - } - - CreateGlobal_pai1(&pai1_header, pai1_header1, pai1_header2, pai1_header_type); - - - FILE *xmlFile; - xmlFile = fopen(filenameout, "w"); - mxml_node_t *xml; - mxml_node_t *xmlan; - xml = mxmlNewXML("1.0"); - xmlan = mxmlNewElement(xml, "xmlan"); - mxmlElementSetAttrf(xmlan, "version", "%d.%d.%d%s", BENZIN_VERSION_MAJOR, BENZIN_VERSION_MINOR, BENZIN_VERSION_BUILD, BENZIN_VERSION_OTHER); - mxmlElementSetAttrf(xmlan, "framesize", "%lu", (long unsigned int)short_swap_bytes(pai1_header.framesize)); - mxmlElementSetAttrf(xmlan, "flags", "%02x", pai1_header.flags); - - int timgs = short_swap_bytes(pai1_header.num_timgs); - - BRLAN_fileoffset = short_swap_bytes(header.pai1_offset) + sizeof(brlan_pai1_header_type1); - if ( pai1_header_type == 2 ) BRLAN_fileoffset += 4; - int tableoff = BRLAN_fileoffset; - int currtableoff = BRLAN_fileoffset; - - mxml_node_t *timg; - for( i = 0; i < timgs; i++) { - u32 curr_timg_off = 0; - BRLAN_ReadDataFromMemory(&curr_timg_off, data, 4); - char timgname[256]; - memset(timgname, 0, 256); - int z = tableoff + be32(curr_timg_off); - for( j = 0; data[z] != 0; timgname[j++] = data[z], z++); - { - timg = mxmlNewElement(xmlan, "timg"); - mxmlElementSetAttrf(timg, "name", "%s", timgname); - } - currtableoff += 4; - } - - int tagcount = short_swap_bytes(pai1_header.num_entries); - u32 taglocations[tagcount]; - BRLAN_fileoffset = be32(pai1_header.entry_offset) + short_swap_bytes(header.pai1_offset); - BRLAN_ReadDataFromMemory(taglocations, data, tagcount * sizeof(u32)); - - for( i = 0; i < tagcount; i++) { - brlan_entry brlanEntry; - tag_header tagHeader; - BRLAN_fileoffset = be32(taglocations[i]) + short_swap_bytes(header.pai1_offset); - u32 brlanEntryOffset = BRLAN_fileoffset; - BRLAN_ReadDataFromMemory(&brlanEntry, data, sizeof(brlan_entry)); - - mxml_node_t *pane; - pane = mxmlNewElement(xmlan, "pane"); mxmlElementSetAttrf(pane, "name", "%s", brlanEntry.name); mxmlElementSetAttrf(pane, "type", "%u", brlanEntry.is_material); - - u32 entrylocations[brlanEntry.num_tags]; - BRLAN_ReadDataFromMemory(entrylocations, data, brlanEntry.num_tags * sizeof(u32)); - for ( j = 0; j < brlanEntry.num_tags; j++) - { - BRLAN_CreateXMLTag(tagHeader, data, brlanEntryOffset + be32(entrylocations[j]), pane); - } - } - mxmlSaveFile(xml, xmlFile, whitespace_cb); - mxmlDelete(xml); - fclose(xmlFile); - fclose(fp); + FILE* fp = fopen(filename, "rb"); + if(fp == NULL) { + printf("Error! Couldn't open %s!\n", filename); + exit(1); + } + fseek(fp, 0, SEEK_END); + u32 lengthOfFile = ftell(fp); + fseek(fp, 0, SEEK_SET); + u8 data[lengthOfFile]; + fread(data, lengthOfFile, 1, fp); + + int i, j; + for(i = 0; i < 16; i++) + { + memset(tag_types_list[i], 0, 24); + memset(tag_types_rlpa_list[i], 0, 24); + memset(tag_types_rlts_list[i], 0, 24); + memset(tag_types_rlvi_list[i], 0, 24); + memset(tag_types_rlvc_list[i], 0, 24); + memset(tag_types_rlmc_list[i], 0, 24); + memset(tag_types_rltp_list[i], 0, 24); + memset(tag_types_rlim_list[i], 0, 24); + } + strcpy(tag_types_list[0], "X Translation"); + strcpy(tag_types_list[1], "Y Translation"); + strcpy(tag_types_list[2], "Z Translation"); + strcpy(tag_types_list[3], "X Rotate"); + strcpy(tag_types_list[4], "Y Rotate"); + strcpy(tag_types_list[5], "Z Rotate"); + strcpy(tag_types_list[6], "X Scale"); + strcpy(tag_types_list[7], "Y Scale"); + strcpy(tag_types_list[8], "Width"); + strcpy(tag_types_list[9], "Height"); + strcpy(tag_types_list[10], "0x0A"); // modified x + strcpy(tag_types_list[11], "0x0B"); // modified y + strcpy(tag_types_list[12], "0x0C"); // modified z + strcpy(tag_types_list[13], "0x0D"); + strcpy(tag_types_list[14], "0x0E"); + strcpy(tag_types_list[15], "0x0F"); + + strcpy(tag_types_rlpa_list[0], "X Translation"); + strcpy(tag_types_rlpa_list[1], "Y Translation"); + strcpy(tag_types_rlpa_list[2], "Z Translation"); + strcpy(tag_types_rlpa_list[3], "X Rotate"); + strcpy(tag_types_rlpa_list[4], "Y Rotate"); + strcpy(tag_types_rlpa_list[5], "Z Rotate"); + strcpy(tag_types_rlpa_list[6], "X Scale"); + strcpy(tag_types_rlpa_list[7], "Y Scale"); + strcpy(tag_types_rlpa_list[8], "Width"); + strcpy(tag_types_rlpa_list[9], "Height"); + strcpy(tag_types_rlpa_list[10], "0x0A"); // modified x + strcpy(tag_types_rlpa_list[11], "0x0B"); // modified y + strcpy(tag_types_rlpa_list[12], "0x0C"); // modified z + strcpy(tag_types_rlpa_list[13], "0x0D"); + strcpy(tag_types_rlpa_list[14], "0x0E"); + strcpy(tag_types_rlpa_list[15], "0x0F"); + + strcpy(tag_types_rlts_list[0], "XTrans"); + strcpy(tag_types_rlts_list[1], "YTrans"); + strcpy(tag_types_rlts_list[2], "Rotate"); + strcpy(tag_types_rlts_list[3], "XScale"); + strcpy(tag_types_rlts_list[4], "YScale"); + + strcpy(tag_types_rlvi_list[0], "Visibility"); + + strcpy(tag_types_rlvc_list[0], "Top Left R"); + strcpy(tag_types_rlvc_list[1], "Top Left G"); + strcpy(tag_types_rlvc_list[2], "Top Left B"); + strcpy(tag_types_rlvc_list[3], "Top Left A"); + strcpy(tag_types_rlvc_list[4], "Top Right R"); + strcpy(tag_types_rlvc_list[5], "Top Right G"); + strcpy(tag_types_rlvc_list[6], "Top Right B"); + strcpy(tag_types_rlvc_list[7], "Top Right A"); + strcpy(tag_types_rlvc_list[8], "Bottom Left R"); + strcpy(tag_types_rlvc_list[9], "Bottom Left G"); + strcpy(tag_types_rlvc_list[10], "Bottom Left B"); + strcpy(tag_types_rlvc_list[11], "Bottom Left A"); + strcpy(tag_types_rlvc_list[12], "Bottom Right R"); + strcpy(tag_types_rlvc_list[13], "Bottom Right G"); + strcpy(tag_types_rlvc_list[14], "Bottom Right B"); + strcpy(tag_types_rlvc_list[15], "Bottom Right A"); + + strcpy(tag_types_rlmc_list[0], "0x00"); + strcpy(tag_types_rlmc_list[1], "0x01"); + strcpy(tag_types_rlmc_list[2], "0x02"); + strcpy(tag_types_rlmc_list[3], "0x03"); + strcpy(tag_types_rlmc_list[4], "Blackcolor R"); + strcpy(tag_types_rlmc_list[5], "Blackcolor G"); + strcpy(tag_types_rlmc_list[6], "Blackcolor B"); + strcpy(tag_types_rlmc_list[7], "Blackcolor A"); + strcpy(tag_types_rlmc_list[8], "Whitecolor R"); + strcpy(tag_types_rlmc_list[9], "Whitecolor G"); + strcpy(tag_types_rlmc_list[10], "Whitecolor B"); + strcpy(tag_types_rlmc_list[11], "Whitecolor A"); + strcpy(tag_types_rlmc_list[12], "0x0C"); + strcpy(tag_types_rlmc_list[13], "0x0D"); + strcpy(tag_types_rlmc_list[14], "0x0E"); + strcpy(tag_types_rlmc_list[15], "0x0F"); + + strcpy(tag_types_rltp_list[0], "PaletteZero"); + strcpy(tag_types_rltp_list[1], "PaletteOne"); + strcpy(tag_types_rltp_list[2], "PaletteTwo"); + strcpy(tag_types_rltp_list[3], "PaletteThree"); + strcpy(tag_types_rltp_list[4], "PaletteFour"); + strcpy(tag_types_rltp_list[5], "PaletteFive"); + strcpy(tag_types_rltp_list[6], "PaletteSix"); + strcpy(tag_types_rltp_list[7], "PaletteSeven"); + strcpy(tag_types_rltp_list[8], "PaletteEight"); + strcpy(tag_types_rltp_list[9], "PaletteNine"); + strcpy(tag_types_rltp_list[10], "PaletteTen"); + strcpy(tag_types_rltp_list[11], "PaletteEleven"); + strcpy(tag_types_rltp_list[12], "PaletteTwelve"); + strcpy(tag_types_rltp_list[13], "PaletteThirteen"); + strcpy(tag_types_rltp_list[14], "PaletteFourteen"); + strcpy(tag_types_rltp_list[15], "PaletteFifteen"); + + strcpy(tag_types_rlim_list[0], "XTrans"); + strcpy(tag_types_rlim_list[1], "YTrans"); + strcpy(tag_types_rlim_list[2], "Rotate"); + strcpy(tag_types_rlim_list[3], "XScale"); + strcpy(tag_types_rlim_list[4], "YScale"); + + BRLAN_fileoffset = 0; + brlan_header header; + BRLAN_ReadDataFromMemoryX(&header, data, sizeof(brlan_header)); + BRLAN_fileoffset = short_swap_bytes(header.pai1_offset); + brlan_pai1_universal universal; + BRLAN_ReadDataFromMemoryX(&universal, data, sizeof(brlan_pai1_universal)); + + int pai1_header_type; + brlan_pai1_header_type1 pai1_header1; + brlan_pai1_header_type2 pai1_header2; + brlan_pai1_header_type2 pai1_header; + + if((be32(universal.flags) & (1 << 25)) >= 1) { + pai1_header_type = 2; + BRLAN_ReadDataFromMemory(&pai1_header2, data, sizeof(brlan_pai1_header_type2)); + } else { + pai1_header_type = 1; + BRLAN_ReadDataFromMemory(&pai1_header1, data, sizeof(brlan_pai1_header_type1)); + } + + CreateGlobal_pai1(&pai1_header, pai1_header1, pai1_header2, pai1_header_type); + + + FILE *xmlFile; + xmlFile = fopen(filenameout, "w"); + mxml_node_t *xml; + mxml_node_t *xmlan; + xml = mxmlNewXML("1.0"); + xmlan = mxmlNewElement(xml, "xmlan"); + mxmlElementSetAttrf(xmlan, "version", "%d.%d.%d%s", BENZIN_VERSION_MAJOR, BENZIN_VERSION_MINOR, BENZIN_VERSION_BUILD, BENZIN_VERSION_OTHER); + mxmlElementSetAttrf(xmlan, "framesize", "%lu", (long unsigned int)short_swap_bytes(pai1_header.framesize)); + mxmlElementSetAttrf(xmlan, "flags", "%02x", pai1_header.flags); + + int timgs = short_swap_bytes(pai1_header.num_timgs); + + BRLAN_fileoffset = short_swap_bytes(header.pai1_offset) + sizeof(brlan_pai1_header_type1); + if ( pai1_header_type == 2 ) BRLAN_fileoffset += 4; + int tableoff = BRLAN_fileoffset; + int currtableoff = BRLAN_fileoffset; + + mxml_node_t *timg; + for( i = 0; i < timgs; i++) { + u32 curr_timg_off = 0; + BRLAN_ReadDataFromMemory(&curr_timg_off, data, 4); + char timgname[256]; + memset(timgname, 0, 256); + int z = tableoff + be32(curr_timg_off); + for( j = 0; data[z] != 0; timgname[j++] = data[z], z++); + { + timg = mxmlNewElement(xmlan, "timg"); + mxmlElementSetAttrf(timg, "name", "%s", timgname); + } + currtableoff += 4; + } + + int tagcount = short_swap_bytes(pai1_header.num_entries); + u32 taglocations[tagcount]; + BRLAN_fileoffset = be32(pai1_header.entry_offset) + short_swap_bytes(header.pai1_offset); + BRLAN_ReadDataFromMemory(taglocations, data, tagcount * sizeof(u32)); + + for( i = 0; i < tagcount; i++) { + brlan_entry brlanEntry; + tag_header tagHeader; + BRLAN_fileoffset = be32(taglocations[i]) + short_swap_bytes(header.pai1_offset); + u32 brlanEntryOffset = BRLAN_fileoffset; + BRLAN_ReadDataFromMemory(&brlanEntry, data, sizeof(brlan_entry)); + + mxml_node_t *pane; + pane = mxmlNewElement(xmlan, "pane"); mxmlElementSetAttrf(pane, "name", "%s", brlanEntry.name); mxmlElementSetAttrf(pane, "type", "%u", brlanEntry.is_material); + + u32 entrylocations[brlanEntry.num_tags]; + BRLAN_ReadDataFromMemory(entrylocations, data, brlanEntry.num_tags * sizeof(u32)); + for ( j = 0; j < brlanEntry.num_tags; j++) + { + BRLAN_CreateXMLTag(tagHeader, data, brlanEntryOffset + be32(entrylocations[j]), pane); + } + } + mxmlSaveFile(xml, xmlFile, whitespace_cb); + mxmlDelete(xml); + fclose(xmlFile); + fclose(fp); } void WriteBRLANTagHeader(tag_header* head, FILE* fp) { - fwrite(head, sizeof(tag_header), 1, fp); + fwrite(head, sizeof(tag_header), 1, fp); } void WriteBRLANTagEntries(tag_entry* entry, u8 count, FILE* fp) { - tag_entry writeentry; - int i; - for(i = 0; i < count; i++) { - writeentry.offset = be32(entry[i].offset); - fwrite(&writeentry, sizeof(tag_entry), 1, fp); - } + tag_entry writeentry; + int i; + for(i = 0; i < count; i++) { + writeentry.offset = be32(entry[i].offset); + fwrite(&writeentry, sizeof(tag_entry), 1, fp); + } } void WriteBRLANOffsets(u32* offsets, u32 number, FILE* fp) { - u32 tempoffsets[number]; - int i; - for(i=0;iname, 20); - writeentr.num_tags = entr->num_tags; - writeentr.is_material = entr->is_material; - writeentr.pad[0] = 0x0; - writeentr.pad[1] = 0x0; - fwrite(&writeentr, sizeof(brlan_entry), 1, fp); + brlan_entry writeentr; + memset(writeentr.name, 0, 20); + strncpy(writeentr.name, entr->name, 20); + writeentr.num_tags = entr->num_tags; + writeentr.is_material = entr->is_material; + writeentr.pad[0] = 0x0; + writeentr.pad[1] = 0x0; + fwrite(&writeentr, sizeof(brlan_entry), 1, fp); } void create_entries_from_xml(mxml_node_t *tree, mxml_node_t *node, brlan_entry *entr, tag_header* head, FILE* fp) { - tag_entry* entry = NULL; - tag_entryinfo* entryinfo = NULL; - tag_data** data = NULL; - tag_data2** data2 = NULL; - mxml_node_t *tempnode = NULL; - mxml_node_t *subnode = NULL; - mxml_node_t *subsubnode = NULL; - char temp[256]; - char temp2[256]; - char temp3[16][24]; - int i, x; - - char tag_type[256]; - if(mxmlElementGetAttr(node, "type") != NULL) - strcpy(tag_type, mxmlElementGetAttr(node, "type")); - - char rlmc_type[5] = {'R', 'L', 'M', 'C'}; - char rlvc_type[5] = {'R', 'L', 'V', 'C'}; + tag_entry* entry = NULL; + tag_entryinfo* entryinfo = NULL; + tag_data** data = NULL; + tag_data2** data2 = NULL; + mxml_node_t *tempnode = NULL; + mxml_node_t *subnode = NULL; + mxml_node_t *subsubnode = NULL; + char temp[256]; + char temp2[256]; + char temp3[16][24]; + int i, x; + + char tag_type[256]; + if(mxmlElementGetAttr(node, "type2") != NULL) + strcpy(tag_type, mxmlElementGetAttr(node, "type2")); + + char rlpa_type[5] = {'R', 'L', 'P', 'A'}; + char rlts_type[5] = {'R', 'L', 'T', 'S'}; + char rlvi_type[5] = {'R', 'L', 'V', 'I'}; + char rlvc_type[5] = {'R', 'L', 'V', 'C'}; + char rlmc_type[5] = {'R', 'L', 'M', 'C'}; + char rltp_type[5] = {'R', 'L', 'T', 'P'}; + char rlim_type[5] = {'R', 'L', 'I', 'M'}; for(i = 0; i < 16; i++) memset(temp3[i], 0, 24); for(x = 0; x < 16; x++) - if(memcmp(tag_type, rlmc_type, 4) == 0) + if(memcmp(tag_type, rlpa_type, 4) == 0) { - for(i = 0; i < strlen(tag_types_rlmc_list[x]); i++) + for(i = 0; i < strlen(tag_types_rlpa_list[x]); i++) { - temp3[x][i] = toupper(tag_types_rlmc_list[x][i]); + temp3[x][i] = toupper(tag_types_rlpa_list[x][i]); + } + } else if(memcmp(tag_type, rlts_type, 4) == 0) { + for(i = 0; i < strlen(tag_types_rlts_list[x]); i++) + { + temp3[x][i] = toupper(tag_types_rlts_list[x][i]); + } + } else if(memcmp(tag_type, rlvi_type, 4) == 0) { + for(i = 0; i < strlen(tag_types_rlvi_list[x]); i++) + { + temp3[x][i] = toupper(tag_types_rlvi_list[x][i]); } } else if(memcmp(tag_type, rlvc_type, 4) == 0) { for(i = 0; i < strlen(tag_types_rlvc_list[x]); i++) { temp3[x][i] = toupper(tag_types_rlvc_list[x][i]); } - } else { - for(i = 0; i < strlen(tag_types_list[x]); i++) + } else if(memcmp(tag_type, rlmc_type, 4) == 0) { + for(i = 0; i < strlen(tag_types_rlmc_list[x]); i++) { - temp3[x][i] = toupper(tag_types_list[x][i]); - } - } - head->entry_count = 0; - subnode = node; - for (x = 0, subnode = mxmlFindElement(subnode, node, "entry", NULL, NULL, MXML_DESCEND); subnode != NULL; subnode = mxmlFindElement(subnode, node, "entry", NULL, NULL, MXML_DESCEND), x++) { - head->entry_count++; - entry = realloc(entry, sizeof(tag_entry) * head->entry_count); - entryinfo = realloc(entryinfo, sizeof(tag_entryinfo) * head->entry_count); - if(data == NULL) - { - data = (tag_data**)malloc(sizeof(tag_data*) * head->entry_count); - data2 = (tag_data2**)malloc(sizeof(tag_data2*) * head->entry_count); - } else { - data = (tag_data**)realloc(data, sizeof(tag_data*) * head->entry_count); - data2 = (tag_data2**)realloc(data, sizeof(tag_data2*) * head->entry_count); - } - data[x] = NULL; - data2[x] = NULL; - memset(temp, 0, 256); - memset(temp2, 0, 256); - if(mxmlElementGetAttr(subnode, "type") != NULL) - strcpy(temp, mxmlElementGetAttr(subnode, "type")); - else{ - printf("No type attribute found!\nSkipping this entry!\n"); - head->entry_count--; - continue; - } - for(i = 0; i < strlen(temp); i++) - temp2[i] = toupper(temp[i]); - for(i = 0; (i < 17) && (strcmp(temp3[i - 1], temp2) != 0); i++); - if(i == 17) - { - i = atoi(temp2); - } - else - { - i--; - } - entry[x].offset = 0; - entryinfo[x].type = i; - entryinfo[x].unk1 = 0x0200; - entryinfo[x].pad1 = 0x0000; - entryinfo[x].unk2 = 0x0000000C; - entryinfo[x].coord_count = 0; - subsubnode = subnode; - for (i = 0, subsubnode = mxmlFindElement(subsubnode, subnode, "triplet", NULL, NULL, MXML_DESCEND); subsubnode != NULL; subsubnode = mxmlFindElement(subsubnode, subnode, "triplet", NULL, NULL, MXML_DESCEND), i++) { - - entryinfo[x].coord_count++; - data[x] = realloc(data[x], sizeof(tag_data) * entryinfo[x].coord_count); - tempnode = mxmlFindElement(subsubnode, subsubnode, "frame", NULL, NULL, MXML_DESCEND); - if(tempnode == NULL) { - printf("Couldn't find attribute \"frame\"!\n"); - exit(1); - } - get_value(tempnode, temp, 256); - *(f32*)(&(data[x][i].part1)) = atof(temp); - tempnode = mxmlFindElement(subsubnode, subsubnode, "value", NULL, NULL, MXML_DESCEND); - if(tempnode == NULL) { - printf("Couldn't find attribute \"value\"!\n"); - exit(1); - } - get_value(tempnode, temp, 256); - *(f32*)(&(data[x][i].part2)) = atof(temp); - tempnode = mxmlFindElement(subsubnode, subsubnode, "blend", NULL, NULL, MXML_DESCEND); - if(tempnode == NULL) { - printf("Couldn't find attribute \"blend\"!\n"); - exit(1); - } - get_value(tempnode, temp, 256); - *(f32*)(&(data[x][i].part3)) = atof(temp); - } - for (i = 0, subsubnode = mxmlFindElement(subnode, subnode, "pair", NULL, NULL, MXML_DESCEND); subsubnode != NULL; subsubnode = mxmlFindElement(subsubnode, subnode, "pair", NULL, NULL, MXML_DESCEND), i++) { - entryinfo[x].unk1 = 0x100; - entryinfo[x].coord_count++; - data2[x] = realloc(data2[x], sizeof(tag_data2) * entryinfo[x].coord_count); - tempnode = mxmlFindElement(subsubnode, subsubnode, "data1", NULL, NULL, MXML_DESCEND); - if(tempnode == NULL) { - printf("Couldn't find attribute \"data1\"!\n"); - exit(1); - } - get_value(tempnode, temp, 256); - *(f32*)(&(data2[x][i].part1)) = atof(temp); - tempnode = mxmlFindElement(subsubnode, subsubnode, "data2", NULL, NULL, MXML_DESCEND); - if(tempnode == NULL) { - printf("Couldn't find attribute \"data2\"!\n"); - exit(1); - } - get_value(tempnode, temp, 256); - data2[x][i].part2 = short_swap_bytes(strtoul(temp, NULL, 16)); - tempnode = mxmlFindElement(subsubnode, subsubnode, "padding", NULL, NULL, MXML_DESCEND); - if(tempnode == NULL) { - printf("Couldn't find attribute \"padding\"!\n"); - exit(1); + temp3[x][i] = toupper(tag_types_rlmc_list[x][i]); } - get_value(tempnode, temp, 256); - data2[x][i].padding = short_swap_bytes(strtoul(temp, NULL, 16)); - } - } - - head->pad1 = 0x0; head->pad2 = 0x0; head->pad3 = 0x0; - WriteBRLANTagHeader(head, fp); - u32 entryloc = ftell(fp); - u32 animLen; - WriteBRLANTagEntries(entry, head->entry_count, fp); - u32* entryinfolocs = (u32*)calloc(head->entry_count, sizeof(u32)); - for(x = 0; x < head->entry_count; x++) { - entryinfolocs[x] = ftell(fp); - if (x>0) - { - if ( entryinfo[x].unk1 == (0x200) ) + } else if(memcmp(tag_type, rltp_type, 4) == 0) { + for(i = 0; i < strlen(tag_types_rltp_list[x]); i++) { - entry[x].offset = entry[x-1].offset + sizeof(tag_entryinfo) + (entryinfo[x-1].coord_count * sizeof(tag_data)); + temp3[x][i] = toupper(tag_types_rltp_list[x][i]); } - if ( entryinfo[x].unk1 == (0x100) ) + } else if(memcmp(tag_type, rlim_type, 4) == 0) { + for(i = 0; i < strlen(tag_types_rlim_list[x]); i++) { - entry[x].offset = entry[x-1].offset + sizeof(tag_entryinfo) + (entryinfo[x-1].coord_count * sizeof(tag_data2)); + temp3[x][i] = toupper(tag_types_rlim_list[x][i]); } } else { - entry[x].offset = x * (sizeof(tag_entryinfo) + sizeof(tag_data)); - } - WriteBRLANTagEntryinfos(entryinfo[x], fp); - if (x==0) animLen = ftell(fp); - if ( entryinfo[x].unk1 == 0x200 ) - WriteBRLANTagData(data[x], entryinfo[x].coord_count, fp); - if ( entryinfo[x].unk1 == 0x100 ) - { - tag_data2 writedata; - for(i = 0; i < entryinfo[x].coord_count; i++) { - writedata.part1 = be32(data2[x][i].part1); - writedata.part2 = (data2[x][i].part2); - writedata.padding = (data2[x][i].padding); - fwrite(&writedata, sizeof(tag_data2), 1, fp); + for(i = 0; i < strlen(tag_types_list[x]); i++) + { + temp3[x][i] = toupper(tag_types_list[x][i]); } } - } - if ( entryinfo[0].unk1 == 0x200 ) - free(data); - if ( entryinfo[0].unk1 == 0x100 ) - free(data2); - u32 oldpos = ftell(fp); - fseek(fp, entryloc, SEEK_SET); - for( x = 0; x < head->entry_count; x++) - entry[x].offset += sizeof(u32) * (head->entry_count) + 8; - WriteBRLANTagEntries(entry, head->entry_count, fp); - fseek(fp, oldpos, SEEK_SET); - free(entry); - free(entryinfo); + head->entry_count = 0; + subnode = node; + for (x = 0, subnode = mxmlFindElement(subnode, node, "entry", NULL, NULL, MXML_DESCEND); subnode != NULL; subnode = mxmlFindElement(subnode, node, "entry", NULL, NULL, MXML_DESCEND), x++) { + head->entry_count++; + entry = realloc(entry, sizeof(tag_entry) * head->entry_count); + entryinfo = realloc(entryinfo, sizeof(tag_entryinfo) * head->entry_count); + if(data == NULL) + { + data = (tag_data**)malloc(sizeof(tag_data*) * head->entry_count); + data2 = (tag_data2**)malloc(sizeof(tag_data2*) * head->entry_count); + } else { + data = (tag_data**)realloc(data, sizeof(tag_data*) * head->entry_count); + data2 = (tag_data2**)realloc(data, sizeof(tag_data2*) * head->entry_count); + } + data[x] = NULL; + data2[x] = NULL; + memset(temp, 0, 256); + memset(temp2, 0, 256); + u8 type1; + if(mxmlElementGetAttr(subnode, "type1") != NULL) + type1 = strtoul( mxmlElementGetAttr(subnode, "type1") , NULL , 16 ); + else + type1 = 0; + if(mxmlElementGetAttr(subnode, "type2") != NULL) + strcpy(temp, mxmlElementGetAttr(subnode, "type2")); + else{ + printf("No type attribute found!\nSkipping this entry!\n"); + head->entry_count--; + continue; + } + for(i = 0; i < strlen(temp); i++) + temp2[i] = toupper(temp[i]); + for(i = 0; (i < 17) && (strcmp(temp3[i - 1], temp2) != 0); i++); + if(i == 17) + { + i = atoi(temp2); + } else { + i--; + } + entry[x].offset = 0; + entryinfo[x].type1 = type1; + entryinfo[x].type2 = i; + entryinfo[x].data_type = 0x0200; + entryinfo[x].pad1 = 0x0000; + entryinfo[x].offset = 0x0000000C; + entryinfo[x].coord_count = 0; + subsubnode = subnode; + for (i = 0, subsubnode = mxmlFindElement(subsubnode, subnode, "triplet", NULL, NULL, MXML_DESCEND); subsubnode != NULL; subsubnode = mxmlFindElement(subsubnode, subnode, "triplet", NULL, NULL, MXML_DESCEND), i++) { + + entryinfo[x].coord_count++; + data[x] = realloc(data[x], sizeof(tag_data) * entryinfo[x].coord_count); + tempnode = mxmlFindElement(subsubnode, subsubnode, "frame", NULL, NULL, MXML_DESCEND); + if(tempnode == NULL) { + printf("Couldn't find attribute \"frame\"!\n"); + exit(1); + } + get_value(tempnode, temp, 256); + *(f32*)(&(data[x][i].part1)) = atof(temp); + tempnode = mxmlFindElement(subsubnode, subsubnode, "value", NULL, NULL, MXML_DESCEND); + if(tempnode == NULL) { + printf("Couldn't find attribute \"value\"!\n"); + exit(1); + } + get_value(tempnode, temp, 256); + *(f32*)(&(data[x][i].part2)) = atof(temp); + tempnode = mxmlFindElement(subsubnode, subsubnode, "blend", NULL, NULL, MXML_DESCEND); + if(tempnode == NULL) { + printf("Couldn't find attribute \"blend\"!\n"); + exit(1); + } + get_value(tempnode, temp, 256); + *(f32*)(&(data[x][i].part3)) = atof(temp); + } + for (i = 0, subsubnode = mxmlFindElement(subnode, subnode, "pair", NULL, NULL, MXML_DESCEND); subsubnode != NULL; subsubnode = mxmlFindElement(subsubnode, subnode, "pair", NULL, NULL, MXML_DESCEND), i++) { + entryinfo[x].data_type = 0x100; + entryinfo[x].coord_count++; + data2[x] = realloc(data2[x], sizeof(tag_data2) * entryinfo[x].coord_count); + tempnode = mxmlFindElement(subsubnode, subsubnode, "data1", NULL, NULL, MXML_DESCEND); + if(tempnode == NULL) { + printf("Couldn't find attribute \"data1\"!\n"); + exit(1); + } + get_value(tempnode, temp, 256); + *(f32*)(&(data2[x][i].part1)) = atof(temp); + tempnode = mxmlFindElement(subsubnode, subsubnode, "data2", NULL, NULL, MXML_DESCEND); + if(tempnode == NULL) { + printf("Couldn't find attribute \"data2\"!\n"); + exit(1); + } + get_value(tempnode, temp, 256); + data2[x][i].part2 = short_swap_bytes(strtoul(temp, NULL, 16)); + tempnode = mxmlFindElement(subsubnode, subsubnode, "padding", NULL, NULL, MXML_DESCEND); + if(tempnode == NULL) { + printf("Couldn't find attribute \"padding\"!\n"); + exit(1); + } + get_value(tempnode, temp, 256); + data2[x][i].padding = short_swap_bytes(strtoul(temp, NULL, 16)); + } + } + + head->pad1 = 0x0; head->pad2 = 0x0; head->pad3 = 0x0; + WriteBRLANTagHeader(head, fp); + u32 entryloc = ftell(fp); + u32 animLen; + WriteBRLANTagEntries(entry, head->entry_count, fp); + u32* entryinfolocs = (u32*)calloc(head->entry_count, sizeof(u32)); + for(x = 0; x < head->entry_count; x++) { + entryinfolocs[x] = ftell(fp); + if (x>0) + { + if ( entryinfo[x].data_type == (0x200) ) + { + entry[x].offset = entry[x-1].offset + sizeof(tag_entryinfo) + (entryinfo[x-1].coord_count * sizeof(tag_data)); + } + if ( entryinfo[x].data_type == (0x100) ) + { + entry[x].offset = entry[x-1].offset + sizeof(tag_entryinfo) + (entryinfo[x-1].coord_count * sizeof(tag_data2)); + } + } else { + entry[x].offset = x * (sizeof(tag_entryinfo) + sizeof(tag_data)); + } + WriteBRLANTagEntryinfos(entryinfo[x], fp); + if (x==0) animLen = ftell(fp); + if ( entryinfo[x].data_type == 0x200 ) + WriteBRLANTagData(data[x], entryinfo[x].coord_count, fp); + if ( entryinfo[x].data_type == 0x100 ) + { + tag_data2 writedata; + for(i = 0; i < entryinfo[x].coord_count; i++) { + writedata.part1 = be32(data2[x][i].part1); + writedata.part2 = (data2[x][i].part2); + writedata.padding = (data2[x][i].padding); + fwrite(&writedata, sizeof(tag_data2), 1, fp); + } + } + } + if ( entryinfo[0].data_type == 0x200 ) + free(data); + if ( entryinfo[0].data_type == 0x100 ) + free(data2); + u32 oldpos = ftell(fp); + fseek(fp, entryloc, SEEK_SET); + for( x = 0; x < head->entry_count; x++) + entry[x].offset += sizeof(u32) * (head->entry_count) + 8; + WriteBRLANTagEntries(entry, head->entry_count, fp); + fseek(fp, oldpos, SEEK_SET); + free(entry); + free(entryinfo); } void create_tag_from_xml(mxml_node_t *tree, mxml_node_t *node, FILE* fp) { - brlan_entry entr; - entr.num_tags = 0x0; - entr.is_material = 0x0; - entr.pad[0] = 0x0; - entr.pad[1] = 0x0; - - char temp[256]; - memset(entr.name, 0, 20); - if(mxmlElementGetAttr(node, "name") != NULL) - strcpy(entr.name, mxmlElementGetAttr(node, "name")); - else{ - } - if(mxmlElementGetAttr(node, "type") != NULL) { - strcpy(temp, mxmlElementGetAttr(node, "type")); - entr.is_material = (u8)atoi(temp); - } else { - } + brlan_entry entr; + entr.num_tags = 0x0; + entr.is_material = 0x0; + entr.pad[0] = 0x0; + entr.pad[1] = 0x0; + + char temp[256]; + memset(entr.name, 0, 20); + if(mxmlElementGetAttr(node, "name") != NULL) + strcpy(entr.name, mxmlElementGetAttr(node, "name")); + else{ + } + if(mxmlElementGetAttr(node, "type") != NULL) { + strcpy(temp, mxmlElementGetAttr(node, "type")); + entr.is_material = (u8)atoi(temp); + } else { + } - - tag_header head; - mxml_node_t *tagnode; - for(tagnode = mxmlFindElement(node, node, "tag", NULL, NULL, MXML_DESCEND); tagnode != NULL; tagnode = mxmlFindElement(tagnode, node, "tag", NULL, NULL, MXML_DESCEND)) - { - entr.num_tags++; - } - u32 brlanentryoffset = ftell(fp); - WriteBRLANEntry(&entr, fp); - - u32 entrylocations[entr.num_tags]; - int i; for ( i = 0; i < entr.num_tags; i++) entrylocations[i] = brlanentryoffset; - WriteBRLANOffsets(entrylocations, entr.num_tags, fp); - - entr.num_tags = 0x0; - for(tagnode = mxmlFindElement(node, node, "tag", NULL, NULL, MXML_DESCEND); tagnode != NULL; tagnode = mxmlFindElement(tagnode, node, "tag", NULL, NULL, MXML_DESCEND)) - { - entrylocations[entr.num_tags] = ftell(fp) - entrylocations[entr.num_tags]; - if(mxmlElementGetAttr(tagnode, "type") != NULL) - strcpy(temp, mxmlElementGetAttr(tagnode, "type")); - else { - printf("No type attribute found!\nQuitting!\n"); - exit(1); - } - for ( i = 0; i < 4; i++) head.magic[i] = temp[i]; - if (FourCCInList(head.magic) == 0) + tag_header head; + mxml_node_t *tagnode; + for(tagnode = mxmlFindElement(node, node, "tag", NULL, NULL, MXML_DESCEND); tagnode != NULL; tagnode = mxmlFindElement(tagnode, node, "tag", NULL, NULL, MXML_DESCEND)) { - printf("animation type not recognized: %.4s", head.magic); - exit(1); - } - create_entries_from_xml(node, tagnode, &entr, &head, fp); - entr.num_tags++; - } - u32 tempOffset = ftell(fp); - fseek(fp, brlanentryoffset + sizeof(brlan_entry), SEEK_SET); - WriteBRLANOffsets(entrylocations, entr.num_tags, fp); - fseek(fp, tempOffset, SEEK_SET); + entr.num_tags++; + } + u32 brlanentryoffset = ftell(fp); + WriteBRLANEntry(&entr, fp); + + u32 entrylocations[entr.num_tags]; + int i; for ( i = 0; i < entr.num_tags; i++) entrylocations[i] = brlanentryoffset; + WriteBRLANOffsets(entrylocations, entr.num_tags, fp); + + entr.num_tags = 0x0; + for(tagnode = mxmlFindElement(node, node, "tag", NULL, NULL, MXML_DESCEND); tagnode != NULL; tagnode = mxmlFindElement(tagnode, node, "tag", NULL, NULL, MXML_DESCEND)) + { + entrylocations[entr.num_tags] = ftell(fp) - entrylocations[entr.num_tags]; + if(mxmlElementGetAttr(tagnode, "type") != NULL) + strcpy(temp, mxmlElementGetAttr(tagnode, "type")); + else { + printf("No type attribute found!\nQuitting!\n"); + exit(1); + } + for ( i = 0; i < 4; i++) head.magic[i] = temp[i]; + if (FourCCInList(head.magic) == 0) + { + printf("animation type not recognized: %.4s", head.magic); + exit(1); + } + create_entries_from_xml(node, tagnode, &entr, &head, fp); + entr.num_tags++; + } + u32 tempOffset = ftell(fp); + fseek(fp, brlanentryoffset + sizeof(brlan_entry), SEEK_SET); + WriteBRLANOffsets(entrylocations, entr.num_tags, fp); + fseek(fp, tempOffset, SEEK_SET); } void WriteBRLANHeader(brlan_header rlanhead, FILE* fp) { - brlan_header writehead; - writehead.magic[0] = rlanhead.magic[0]; - writehead.magic[1] = rlanhead.magic[1]; - writehead.magic[2] = rlanhead.magic[2]; - writehead.magic[3] = rlanhead.magic[3]; - writehead.unk1 = be32(rlanhead.unk1); - writehead.file_size = be32(rlanhead.file_size); - writehead.pai1_offset = short_swap_bytes(rlanhead.pai1_offset); - writehead.pai1_count = short_swap_bytes(rlanhead.pai1_count); - fwrite(&writehead, sizeof(brlan_header), 1, fp); + brlan_header writehead; + writehead.magic[0] = rlanhead.magic[0]; + writehead.magic[1] = rlanhead.magic[1]; + writehead.magic[2] = rlanhead.magic[2]; + writehead.magic[3] = rlanhead.magic[3]; + writehead.version = be32(rlanhead.version); + writehead.file_size = be32(rlanhead.file_size); + writehead.pai1_offset = short_swap_bytes(rlanhead.pai1_offset); + writehead.pai1_count = short_swap_bytes(rlanhead.pai1_count); + fwrite(&writehead, sizeof(brlan_header), 1, fp); } void WriteBRLANPaiHeader(brlan_pai1_header_type1 paihead, FILE* fp) { - brlan_pai1_header_type1 writehead; - writehead.magic[0] = paihead.magic[0]; - writehead.magic[1] = paihead.magic[1]; - writehead.magic[2] = paihead.magic[2]; - writehead.magic[3] = paihead.magic[3]; - writehead.size = be32(paihead.size); - writehead.framesize = short_swap_bytes(paihead.framesize); - writehead.flags = paihead.flags; - writehead.unk1 = paihead.unk1; - writehead.num_timgs = short_swap_bytes(paihead.num_timgs); - writehead.num_entries = short_swap_bytes(paihead.num_entries); - writehead.entry_offset = be32(paihead.entry_offset); - fwrite(&writehead, sizeof(brlan_pai1_header_type1), 1, fp); + brlan_pai1_header_type1 writehead; + writehead.magic[0] = paihead.magic[0]; + writehead.magic[1] = paihead.magic[1]; + writehead.magic[2] = paihead.magic[2]; + writehead.magic[3] = paihead.magic[3]; + writehead.size = be32(paihead.size); + writehead.framesize = short_swap_bytes(paihead.framesize); + writehead.flags = paihead.flags; + writehead.padding = paihead.padding; + writehead.num_timgs = short_swap_bytes(paihead.num_timgs); + writehead.num_entries = short_swap_bytes(paihead.num_entries); + writehead.entry_offset = be32(paihead.entry_offset); + fwrite(&writehead, sizeof(brlan_pai1_header_type1), 1, fp); } void write_brlan(char *infile, char* outfile) { - int i; - for(i = 0; i < 16; i++) - { - memset(tag_types_list[i], 0, 24); - memset(tag_types_rlmc_list[i], 0, 24); - memset(tag_types_rlvc_list[i], 0, 24); - } - strcpy(tag_types_list[0], "X Translation"); - strcpy(tag_types_list[1], "Y Translation"); - strcpy(tag_types_list[2], "Z Translation"); - strcpy(tag_types_list[3], "X Flip"); - strcpy(tag_types_list[4], "Y Flip"); - strcpy(tag_types_list[5], "Angle"); - strcpy(tag_types_list[6], "X Zoom"); - strcpy(tag_types_list[7], "Y Zoom"); - strcpy(tag_types_list[8], "Width"); - strcpy(tag_types_list[9], "Height"); - strcpy(tag_types_list[10], "0x0A"); - strcpy(tag_types_list[11], "0x0B"); - strcpy(tag_types_list[12], "0x0C"); - strcpy(tag_types_list[13], "0x0D"); - strcpy(tag_types_list[14], "0x0E"); - strcpy(tag_types_list[15], "0x0F"); - - strcpy(tag_types_rlmc_list[0], "0x00"); - strcpy(tag_types_rlmc_list[1], "0x01"); - strcpy(tag_types_rlmc_list[2], "0x02"); - strcpy(tag_types_rlmc_list[3], "0x03"); - strcpy(tag_types_rlmc_list[4], "Blackcolor R"); - strcpy(tag_types_rlmc_list[5], "Blackcolor G"); - strcpy(tag_types_rlmc_list[6], "Blackcolor B"); - strcpy(tag_types_rlmc_list[7], "Blackcolor A"); - strcpy(tag_types_rlmc_list[8], "Whitecolor R"); - strcpy(tag_types_rlmc_list[9], "Whitecolor G"); - strcpy(tag_types_rlmc_list[10], "Whitecolor B"); - strcpy(tag_types_rlmc_list[11], "Whitecolor A"); - strcpy(tag_types_rlmc_list[12], "0x0C"); - strcpy(tag_types_rlmc_list[13], "0x0D"); - strcpy(tag_types_rlmc_list[14], "0x0E"); - strcpy(tag_types_rlmc_list[15], "0x0F"); - - strcpy(tag_types_rlvc_list[0], "Top Left R"); - strcpy(tag_types_rlvc_list[1], "Top Left G"); - strcpy(tag_types_rlvc_list[2], "Top Left B"); - strcpy(tag_types_rlvc_list[3], "Top Left A"); - strcpy(tag_types_rlvc_list[4], "Top Right R"); - strcpy(tag_types_rlvc_list[5], "Top Right G"); - strcpy(tag_types_rlvc_list[6], "Top Right B"); - strcpy(tag_types_rlvc_list[7], "Top Right A"); - strcpy(tag_types_rlvc_list[8], "Bottom Left R"); - strcpy(tag_types_rlvc_list[9], "Bottom Left G"); - strcpy(tag_types_rlvc_list[10], "Bottom Left B"); - strcpy(tag_types_rlvc_list[11], "Bottom Left A"); - strcpy(tag_types_rlvc_list[12], "Bottom Right R"); - strcpy(tag_types_rlvc_list[13], "Bottom Right G"); - strcpy(tag_types_rlvc_list[14], "Bottom Right B"); - strcpy(tag_types_rlvc_list[15], "Bottom Right A"); - - FILE* fpx = fopen(infile, "r"); - if(fpx == NULL) { - printf("xmlan couldn't be opened!\n"); - exit(1); - } - mxml_node_t *hightree = mxmlLoadFile(NULL, fpx, MXML_TEXT_CALLBACK); - if(hightree == NULL) { - printf("Couldn't open hightree!\n"); - exit(1); - } - mxml_node_t *tree = mxmlFindElement(hightree, hightree, "xmlan", NULL, NULL, MXML_DESCEND); - if(hightree == NULL) { - printf("Couldn't get tree!\n"); - exit(1); - } - mxml_node_t *node; - FILE* fp = fopen(outfile, "wb+"); - if(fpx == NULL) { - printf("destination brlan couldn't be opened!\n"); - exit(1); - } - u16 blobcount = 0; - brlan_header rlanhead; - rlanhead.magic[0] = 'R'; - rlanhead.magic[1] = 'L'; - rlanhead.magic[2] = 'A'; - rlanhead.magic[3] = 'N'; - rlanhead.unk1 = 0xFEFF0008; - rlanhead.file_size = 0; - rlanhead.pai1_offset = sizeof(brlan_header); - rlanhead.pai1_count = 1; - WriteBRLANHeader(rlanhead, fp); - brlan_pai1_header_type1 paihead; - paihead.magic[0] = 'p'; - paihead.magic[1] = 'a'; - paihead.magic[2] = 'i'; - paihead.magic[3] = '1'; - paihead.size = 0; - char temp[256]; - if(mxmlElementGetAttr(tree, "framesize") != NULL) - strcpy(temp, mxmlElementGetAttr(tree, "framesize")); - else{ - printf("No framesize attribute found!\nDefaulting to 20."); - strcpy(temp, "20"); - } - paihead.framesize = atoi(temp); - memset(temp, 0, 256); - if(mxmlElementGetAttr(tree, "flags") != NULL) - { - strcpy(temp, mxmlElementGetAttr(tree, "flags")); - } else { - printf("No flags attribute found!\nDefaulting to 1."); - paihead.flags = 1; - } - paihead.flags = atoi(temp); - paihead.unk1 = 0; - paihead.num_timgs = 0; - paihead.num_entries = 0; - paihead.entry_offset = sizeof(brlan_pai1_header_type1); - WriteBRLANPaiHeader(paihead, fp); - - u32 totaltagsize = 0; - - u16 timgcount = 0; - u32 totaltimgize = 0; - - u32 timgnumber = 0x0; - for(node = mxmlFindElement(tree, tree, "timg", NULL, NULL, MXML_DESCEND); node != NULL; node = mxmlFindElement(node, tree, "timg", NULL, NULL, MXML_DESCEND)) - { - timgnumber++; - } - u32 imageoffsets[timgnumber]; - u32 imagefileoffset = ftell(fp); - for( i = 0; i < timgnumber; i++) imageoffsets[i] = imagefileoffset; - WriteBRLANOffsets(imageoffsets, timgnumber, fp); - - for(node = mxmlFindElement(tree, tree, "timg", NULL, NULL, MXML_DESCEND); node != NULL; node = mxmlFindElement(node, tree, "timg", NULL, NULL, MXML_DESCEND)) { - timgcount++; - imageoffsets[timgcount-1] = ftell(fp) - imageoffsets[timgcount-1]; - if(mxmlElementGetAttr(node, "name") != NULL) - strcpy(temp, mxmlElementGetAttr(node, "name")); - else{ - printf("No name attribute found!\n"); - exit(1); - } - fwrite(temp, strlen(temp) + 1, 1, fp); - totaltimgize += strlen(temp) + 1; - } - if ((totaltimgize % 4) != 0) - { - u8 blank[3] = {0x0, 0x0, 0x0}; - fwrite(blank, (4 - (totaltimgize % 4)), 1, fp); - totaltimgize += (4 - (totaltimgize % 4)); - } - u32 tempoOffset = ftell(fp); - fseek(fp, imagefileoffset, SEEK_SET); - WriteBRLANOffsets(imageoffsets, timgnumber, fp); - fseek(fp, tempoOffset, SEEK_SET); - - u32 panecount = 0x0; - for(node = mxmlFindElement(tree, tree, "pane", NULL, NULL, MXML_DESCEND); node != NULL; node = mxmlFindElement(node, tree, "pane", NULL, NULL, MXML_DESCEND)) - { - panecount++; - } - u32 paneoffsets[panecount]; - u32 tagoffset = ftell(fp); - for(i = 0; i < panecount; i++) paneoffsets[i] = 0x10; - WriteBRLANOffsets(paneoffsets, panecount, fp); + int i; + for(i = 0; i < 16; i++) + { + memset(tag_types_list[i], 0, 24); + memset(tag_types_rlpa_list[i], 0, 24); + memset(tag_types_rlts_list[i], 0, 24); + memset(tag_types_rlvi_list[i], 0, 24); + memset(tag_types_rlvc_list[i], 0, 24); + memset(tag_types_rlmc_list[i], 0, 24); + memset(tag_types_rltp_list[i], 0, 24); + memset(tag_types_rlim_list[i], 0, 24); + } + + strcpy(tag_types_list[0], "X Translation"); + strcpy(tag_types_list[1], "Y Translation"); + strcpy(tag_types_list[2], "Z Translation"); + strcpy(tag_types_list[3], "X Rotate"); + strcpy(tag_types_list[4], "Y Rotate"); + strcpy(tag_types_list[5], "Z Rotate"); + strcpy(tag_types_list[6], "X Scale"); + strcpy(tag_types_list[7], "Y Scale"); + strcpy(tag_types_list[8], "Width"); + strcpy(tag_types_list[9], "Height"); + strcpy(tag_types_list[10], "0x0A"); + strcpy(tag_types_list[11], "0x0B"); + strcpy(tag_types_list[12], "0x0C"); + strcpy(tag_types_list[13], "0x0D"); + strcpy(tag_types_list[14], "0x0E"); + strcpy(tag_types_list[15], "0x0F"); + + strcpy(tag_types_rlts_list[0], "XTrans"); + strcpy(tag_types_rlts_list[1], "YTrans"); + strcpy(tag_types_rlts_list[2], "Rotate"); + strcpy(tag_types_rlts_list[3], "XScale"); + strcpy(tag_types_rlts_list[4], "YScale"); + + strcpy(tag_types_rlvi_list[0], "Visibility"); + + strcpy(tag_types_rlvc_list[0], "Top Left R"); + strcpy(tag_types_rlvc_list[1], "Top Left G"); + strcpy(tag_types_rlvc_list[2], "Top Left B"); + strcpy(tag_types_rlvc_list[3], "Top Left A"); + strcpy(tag_types_rlvc_list[4], "Top Right R"); + strcpy(tag_types_rlvc_list[5], "Top Right G"); + strcpy(tag_types_rlvc_list[6], "Top Right B"); + strcpy(tag_types_rlvc_list[7], "Top Right A"); + strcpy(tag_types_rlvc_list[8], "Bottom Left R"); + strcpy(tag_types_rlvc_list[9], "Bottom Left G"); + strcpy(tag_types_rlvc_list[10], "Bottom Left B"); + strcpy(tag_types_rlvc_list[11], "Bottom Left A"); + strcpy(tag_types_rlvc_list[12], "Bottom Right R"); + strcpy(tag_types_rlvc_list[13], "Bottom Right G"); + strcpy(tag_types_rlvc_list[14], "Bottom Right B"); + strcpy(tag_types_rlvc_list[15], "Bottom Right A"); + + strcpy(tag_types_rlmc_list[0], "0x00"); + strcpy(tag_types_rlmc_list[1], "0x01"); + strcpy(tag_types_rlmc_list[2], "0x02"); + strcpy(tag_types_rlmc_list[3], "0x03"); + strcpy(tag_types_rlmc_list[4], "Blackcolor R"); + strcpy(tag_types_rlmc_list[5], "Blackcolor G"); + strcpy(tag_types_rlmc_list[6], "Blackcolor B"); + strcpy(tag_types_rlmc_list[7], "Blackcolor A"); + strcpy(tag_types_rlmc_list[8], "Whitecolor R"); + strcpy(tag_types_rlmc_list[9], "Whitecolor G"); + strcpy(tag_types_rlmc_list[10], "Whitecolor B"); + strcpy(tag_types_rlmc_list[11], "Whitecolor A"); + strcpy(tag_types_rlmc_list[12], "0x0C"); + strcpy(tag_types_rlmc_list[13], "0x0D"); + strcpy(tag_types_rlmc_list[14], "0x0E"); + strcpy(tag_types_rlmc_list[15], "0x0F"); + + strcpy(tag_types_rltp_list[0], "PaletteZero"); + strcpy(tag_types_rltp_list[1], "PaletteOne"); + strcpy(tag_types_rltp_list[2], "PaletteTwo"); + strcpy(tag_types_rltp_list[3], "PaletteThree"); + strcpy(tag_types_rltp_list[4], "PaletteFour"); + strcpy(tag_types_rltp_list[5], "PaletteFive"); + strcpy(tag_types_rltp_list[6], "PaletteSix"); + strcpy(tag_types_rltp_list[7], "PaletteSeven"); + strcpy(tag_types_rltp_list[8], "PaletteEight"); + strcpy(tag_types_rltp_list[9], "PaletteNine"); + strcpy(tag_types_rltp_list[10], "PaletteTen"); + strcpy(tag_types_rltp_list[11], "PaletteEleven"); + strcpy(tag_types_rltp_list[12], "PaletteTwelve"); + strcpy(tag_types_rltp_list[13], "PaletteThirteen"); + strcpy(tag_types_rltp_list[14], "PaletteFourteen"); + strcpy(tag_types_rltp_list[15], "PaletteFifteen"); + + strcpy(tag_types_rlim_list[0], "XTrans"); + strcpy(tag_types_rlim_list[1], "YTrans"); + strcpy(tag_types_rlim_list[2], "Rotate"); + strcpy(tag_types_rlim_list[3], "XScale"); + strcpy(tag_types_rlim_list[4], "YScale"); + + FILE* fpx = fopen(infile, "r"); + if(fpx == NULL) { + printf("xmlan couldn't be opened!\n"); + exit(1); + } + mxml_node_t *hightree = mxmlLoadFile(NULL, fpx, MXML_TEXT_CALLBACK); + if(hightree == NULL) { + printf("Couldn't open hightree!\n"); + exit(1); + } + mxml_node_t *tree = mxmlFindElement(hightree, hightree, "xmlan", NULL, NULL, MXML_DESCEND); + if(hightree == NULL) { + printf("Couldn't get tree!\n"); + exit(1); + } + mxml_node_t *node; + FILE* fp = fopen(outfile, "wb+"); + if(fpx == NULL) { + printf("destination brlan couldn't be opened!\n"); + exit(1); + } + u16 blobcount = 0; + brlan_header rlanhead; + rlanhead.magic[0] = 'R'; + rlanhead.magic[1] = 'L'; + rlanhead.magic[2] = 'A'; + rlanhead.magic[3] = 'N'; + rlanhead.version = 0xFEFF0008; + rlanhead.file_size = 0; + rlanhead.pai1_offset = sizeof(brlan_header); + rlanhead.pai1_count = 1; + WriteBRLANHeader(rlanhead, fp); + brlan_pai1_header_type1 paihead; + paihead.magic[0] = 'p'; + paihead.magic[1] = 'a'; + paihead.magic[2] = 'i'; + paihead.magic[3] = '1'; + paihead.size = 0; + char temp[256]; + if(mxmlElementGetAttr(tree, "framesize") != NULL) + strcpy(temp, mxmlElementGetAttr(tree, "framesize")); + else{ + printf("No framesize attribute found!\nDefaulting to 20."); + strcpy(temp, "20"); + } + paihead.framesize = atoi(temp); + memset(temp, 0, 256); + if(mxmlElementGetAttr(tree, "flags") != NULL) + { + strcpy(temp, mxmlElementGetAttr(tree, "flags")); + } else { + printf("No flags attribute found!\nDefaulting to 1."); + paihead.flags = 1; + } + paihead.flags = atoi(temp); + paihead.padding = 0; + paihead.num_timgs = 0; + paihead.num_entries = 0; + paihead.entry_offset = sizeof(brlan_pai1_header_type1); + WriteBRLANPaiHeader(paihead, fp); + + u32 totaltagsize = 0; + + u16 timgcount = 0; + u32 totaltimgize = 0; - for(node = mxmlFindElement(tree, tree, "pane", NULL, NULL, MXML_DESCEND); node != NULL; node = mxmlFindElement(node, tree, "pane", NULL, NULL, MXML_DESCEND)) - { - blobcount++; - paneoffsets[blobcount-1] = ftell(fp) - paneoffsets[blobcount-1]; - create_tag_from_xml(tree, node, fp); - totaltagsize = ftell(fp) - tagoffset; - } - u32 fileSize = ftell(fp); - fseek(fp, tagoffset, SEEK_SET); - WriteBRLANOffsets(paneoffsets, blobcount, fp); + u32 timgnumber = 0x0; + for(node = mxmlFindElement(tree, tree, "timg", NULL, NULL, MXML_DESCEND); node != NULL; node = mxmlFindElement(node, tree, "timg", NULL, NULL, MXML_DESCEND)) + { + timgnumber++; + } + u32 imageoffsets[timgnumber]; + u32 imagefileoffset = ftell(fp); + for( i = 0; i < timgnumber; i++) imageoffsets[i] = imagefileoffset; + WriteBRLANOffsets(imageoffsets, timgnumber, fp); - - paihead.num_timgs = timgcount; - paihead.entry_offset = sizeof(brlan_pai1_header_type1) + totaltimgize + (4*paihead.num_timgs); - paihead.num_entries = blobcount; - fseek(fp, 0, SEEK_END); - paihead.size = fileSize - rlanhead.pai1_offset; - rlanhead.file_size = fileSize; - fseek(fp, 0, SEEK_SET); - WriteBRLANHeader(rlanhead, fp); - WriteBRLANPaiHeader(paihead, fp); + for(node = mxmlFindElement(tree, tree, "timg", NULL, NULL, MXML_DESCEND); node != NULL; node = mxmlFindElement(node, tree, "timg", NULL, NULL, MXML_DESCEND)) { + timgcount++; + imageoffsets[timgcount-1] = ftell(fp) - imageoffsets[timgcount-1]; + if(mxmlElementGetAttr(node, "name") != NULL) + strcpy(temp, mxmlElementGetAttr(node, "name")); + else{ + printf("No name attribute found!\n"); + exit(1); + } + fwrite(temp, strlen(temp) + 1, 1, fp); + totaltimgize += strlen(temp) + 1; + } + if ((totaltimgize % 4) != 0) + { + u8 blank[3] = {0x0, 0x0, 0x0}; + fwrite(blank, (4 - (totaltimgize % 4)), 1, fp); + totaltimgize += (4 - (totaltimgize % 4)); + } + u32 tempoOffset = ftell(fp); + fseek(fp, imagefileoffset, SEEK_SET); + WriteBRLANOffsets(imageoffsets, timgnumber, fp); + fseek(fp, tempoOffset, SEEK_SET); + + u32 panecount = 0x0; + for(node = mxmlFindElement(tree, tree, "pane", NULL, NULL, MXML_DESCEND); node != NULL; node = mxmlFindElement(node, tree, "pane", NULL, NULL, MXML_DESCEND)) + { + panecount++; + } + u32 paneoffsets[panecount]; + u32 tagoffset = ftell(fp); + for(i = 0; i < panecount; i++) paneoffsets[i] = 0x10; + WriteBRLANOffsets(paneoffsets, panecount, fp); + + for(node = mxmlFindElement(tree, tree, "pane", NULL, NULL, MXML_DESCEND); node != NULL; node = mxmlFindElement(node, tree, "pane", NULL, NULL, MXML_DESCEND)) + { + blobcount++; + paneoffsets[blobcount-1] = ftell(fp) - paneoffsets[blobcount-1]; + create_tag_from_xml(tree, node, fp); + totaltagsize = ftell(fp) - tagoffset; + } + u32 fileSize = ftell(fp); + fseek(fp, tagoffset, SEEK_SET); + WriteBRLANOffsets(paneoffsets, blobcount, fp); + + + paihead.num_timgs = timgcount; + paihead.entry_offset = sizeof(brlan_pai1_header_type1) + totaltimgize + (4*paihead.num_timgs); + paihead.num_entries = blobcount; + fseek(fp, 0, SEEK_END); + paihead.size = fileSize - rlanhead.pai1_offset; + rlanhead.file_size = fileSize; + fseek(fp, 0, SEEK_SET); + WriteBRLANHeader(rlanhead, fp); + WriteBRLANPaiHeader(paihead, fp); } void make_brlan(char* infile, char* outfile) { - printf("Parsing XMLAN @ %s.\n", infile); - write_brlan(infile, outfile); + printf("Parsing XMLAN @ %s.\n", infile); + write_brlan(infile, outfile); } diff --git a/brlan.h b/brlan.h index 2d7b1cb..5617185 100755 --- a/brlan.h +++ b/brlan.h @@ -12,104 +12,122 @@ typedef enum { - RLPA_ENTRY = 0, - RLTS_ENTRY = 1, - RLVI_ENTRY = 2, - RLVC_ENTRY = 3, - RLMC_ENTRY = 4, - RLTP_ENTRY = 5, - RLIM_ENTRY + RLPA_ENTRY = 0, // Pane Animation .aka. Pane variable animation + // byte 1 not used byte 2 is which variable + // *( &pane.XTrans + type2<<2 ) = result + RLTS_ENTRY = 1, // Texture ScaleRotateTranslate Mapping + // byte 1 is which SRT and byte 2 is which elem. + // *( GetTexSRTArray()[type1] + (type2*4) ) = result + RLVI_ENTRY = 2, // Visibility // stores data2 to bottom of flag1 + // bytes 1 and 2 arent' used + // ( pane.flag1 & 0xfe ) |= ( result & 0x01 ) + RLVC_ENTRY = 3, // Vertex Color // byte2 is passed to Pane::SetColorElement(); + // byte 1 not used byte 2 is which vertex and color + // 16-19 goes to unknown vars + // 20-23 goes to textureCoordinate pointer :D + // Pane::SetColorElement( type2 , result ); + RLMC_ENTRY = 4, // Material Color + // byte1 is not used byte 2 is which color + // Material::SetColorElement( type2 , color ); + RLTP_ENTRY = 5, // TPL Pallete + // byte 1 is which Texture byte 2 must be 0 + // SetTextureNoWrap( type1 , (return_val<<2) + anim_basic.pointer2 ); + RLIM_ENTRY // IndTexSRTAry Material + // byte 1 is which SRT and byte 2 is which elem. + // *( GetIndTexSRTArray()[type1] + (type2*4) ) = result } brlan_entry_type; typedef struct { - fourcc magic; // "pai1" in ASCII. - u32 size; // Size of section, which is rest of the file. (header.file_size - header.offset_pai1) - u16 framesize; // Framesize - u8 flags; // Flags - u8 unk1; // Unknown - u16 num_timgs; // Number of timgs? - u16 num_entries; // Number of tags in the brlan. - u32 unk2; // Only if bit 25 of flags is set. - u32 entry_offset; // Offset to entries. (Relative to start of pai1 header.) + fourcc magic; // "pai1" in ASCII. + u32 size; // Size of section, which is rest of the file. (header.file_size - header.offset_pai1) + u16 framesize; // Framesize + u8 flags; // Flags // isLoopData + u8 padding; // Padding + u16 num_timgs; // Number of timgs? + u16 num_entries; // Number of tags in the brlan. + u32 padding2; // Only if bit 25 of flags is set. + u32 entry_offset; // Offset to entries. (Relative to start of pai1 header.) } brlan_pai1_header_type2; typedef struct { - fourcc magic; // "RLAN" in ASCII. - u32 unk1; // Always 0xFEFF 0x0008. Possibly a versioning string. - u32 file_size; // Size of whole file, including the header. - u16 pai1_offset; // The offset to the pai1 header from the start of file. - u16 pai1_count; // How many pai1 sections there are (duh, only 1... wtf?) + fourcc magic; // "RLAN" in ASCII. + u32 version; // Always 0xFEFF 0x0008. Possibly a versioning string. + u32 file_size; // Size of whole file, including the header. + u16 pai1_offset; // The offset to the pai1 header from the start of file. + u16 pai1_count; // How many pai1 sections there are (duh, only 1... wtf?) } brlan_header; typedef struct { - fourcc magic; // "pai1" in ASCII. - u32 size; // Size of section, which is rest of the file. (header.file_size - header.offset_pai1) - u16 framesize; // Framesize - u8 flags; // Flags - u8 unk1; // Unknown - u16 num_timgs; // Number of timgs? - u16 num_entries; // Number of tags in the brlan. + fourcc magic; // "pai1" in ASCII. + u32 size; // Size of section, which is rest of the file. (header.file_size - header.offset_pai1) + u16 framesize; // Framesize + u8 flags; // Flags + u8 padding; // Padding + u16 num_timgs; // Number of timgs? + u16 num_entries; // Number of tags in the brlan. } brlan_pai1_universal; typedef struct { - fourcc magic; // "pai1" in ASCII. - u32 size; // Size of section, which is rest of the file. (header.file_size - header.offset_pai1) - u16 framesize; // Framesize - u8 flags; // Flags - u8 unk1; // Unknown - u16 num_timgs; // Number of timgs? - u16 num_entries; // Number of tags in the brlan. - u32 entry_offset; // Offset to entries. (Relative to start of pai1 header.) -} brlan_pai1_header_type1; - -typedef struct + fourcc magic; // "pai1" in ASCII. + u32 size; // Size of section, which is rest of the file. (header.file_size - header.offset_pai1) + u16 framesize; // Framesize + u8 flags; // Flags + u8 padding; // Padding + u16 num_timgs; // Number of timgs? + u16 num_entries; // Number of tags in the brlan. + u32 entry_offset; // Offset to entries. (Relative to start of pai1 header.) +} brlan_pai1_header_type1; // followed by offset list + +typedef struct // pointed at by offset list + pai1_header { - char name[20]; // Name of the BRLAN entry. (Must be defined in the BRLYT) - u8 num_tags; - u8 is_material; // if 0 it's the name of a pane - u8 pad[2]; -} brlan_entry; + char name[20]; // Name of the BRLAN entry. (Must be defined in the BRLYT) + u8 num_tags; + u8 is_material; // if 0 it's the name of a pane + u8 pad[2]; +} brlan_entry; // followed by offset list -typedef struct +typedef struct // pointed at by offset list + brlan_entry { - fourcc magic; - u8 entry_count; // How many entries in this chunk. - u8 pad1; // All cases I've seen is zero. - u8 pad2; // All cases I've seen is zero. - u8 pad3; // All cases I've seen is zero. + fourcc magic; + u8 entry_count; // How many entries in this chunk. + u8 pad1; // All cases I've seen is zero. + u8 pad2; // All cases I've seen is zero. + u8 pad3; // All cases I've seen is zero. } tag_header; typedef struct { - u32 offset; // Offset to the data pointed to by this entry. - // Relative to the start of the RLPA header. + u32 offset; // Offset to the data pointed to by this entry. + // Relative to the start of the RLPA header. } tag_entry; typedef struct { - u16 type; // Type (look at animtypes) - u16 unk1; // Every case has been 0x0200 // 0x0100 for pairs - u16 coord_count; // How many coordinates. - u16 pad1; // All cases I've seen is zero. - u32 unk2; // ??? In every case I've seen, it is 0x0000000C. + //u16 type; // Type (look at animtypes) + u8 type1; + u8 type2; + u16 data_type; // Every case has been 0x0200 // 0x0100 for pairs + u16 coord_count; // How many coordinates. + u16 pad1; // All cases I've seen is zero. + u32 offset; // Offset to tag data } tag_entryinfo; typedef struct -{ // Bits not listed here are currently unknown. - u32 part1; // If Bit 9 is set in flags, this is an f32, with a coordinate. (Bit 17 seems to act the same) - u32 part2; // If Bit 16 is set in flags, this is an f32, with another coordinate. (Bit 17 seems to act the same) - u32 part3; // With Bit 16 set in flags, this seems to be yet another coordinate. (Bit 17 seems to act the same) +{ // Bits not listed here are currently unknown. + u32 part1; // If Bit 9 is set in flags, this is an f32, with a coordinate. (Bit 17 seems to act the same) + u32 part2; // If Bit 16 is set in flags, this is an f32, with another coordinate. (Bit 17 seems to act the same) + u32 part3; // With Bit 16 set in flags, this seems to be yet another coordinate. (Bit 17 seems to act the same) } tag_data; typedef struct { - u32 part1; - u16 part2; - u16 padding; + u32 part1; + u16 part2; + u16 padding; } tag_data2; diff --git a/brlyt.c b/brlyt.c index 694e8f9..b7b3758 100644 --- a/brlyt.c +++ b/brlyt.c @@ -79,9 +79,9 @@ static void BRLYT_ReadDataFromMemory(void* destination, void* input, size_t size float float_swap_bytes(float float1) { - unsigned char *float1c; float1c = (unsigned char*)&float1; + u8 *float1c; float1c = (u8*)&float1; - unsigned char charTemp = 0x00; + u8 charTemp = 0x00; charTemp = float1c[0]; float1c[0] = float1c[3]; float1c[3] = charTemp; charTemp = 0x00; charTemp = float1c[1]; float1c[1] = float1c[2]; float1c[2] = charTemp; @@ -90,12 +90,10 @@ float float_swap_bytes(float float1) return *newFloat; } -unsigned int bit_extract(unsigned int num, unsigned int start, unsigned int end) +u32 bit_extract(u32 num, u32 start, u32 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; + u32 mask; int first; int firstMask = 1; for (first=0;first<31-start+1;first++) @@ -182,8 +180,14 @@ void BRLYT_CheckHeaderSanity(brlyt_header header, size_t filesize) { if((header.magic[0] != 'R') || (header.magic[1] != 'L') || (header.magic[2] != 'Y') || (header.magic[3] != 'T')) { printf("BRLYT magic doesn't match! %.4s\n", header.magic); + printf("magic: %.4s\n", header.magic); exit(1); } + if(header.version != be32(0xfeff0008) ){ + printf("BRLYT version not right\n"); + printf("version: %08x\n", be32(header.version) ); + exit(1); + } if(filesize != be32(header.filesize)) { printf("BRLYT filesize doesn't match!\n"); exit(1); @@ -200,7 +204,7 @@ void PrintBRLYTEntry_lyt1(brlyt_entry entry, u8* brlyt_file, mxml_node_t *tag) BRLYT_fileoffset = entry.data_location; BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_lytheader_chunk)); mxmlElementSetAttrf(tag, "type", "%.4s", entry.magic); - a = mxmlNewElement(tag, "a"); mxmlNewTextf(a, 0, "%02x", data.a); + a = mxmlNewElement(tag, "drawnFromMiddle"); mxmlNewTextf(a, 0, "%02x", data.drawnFromMiddle); size = mxmlNewElement(tag, "size"); width = mxmlNewElement(size, "width"); mxmlNewTextf(width, 0, "%f", float_swap_bytes(data.width)); height = mxmlNewElement(size, "height"); mxmlNewTextf(height, 0,"%f", float_swap_bytes(data.height)); @@ -300,28 +304,45 @@ void PrintBRLYTEntry_fnl1(brlyt_entry entry, u8* brlyt_file, mxml_node_t *tag) void PrintBRLYTEntry_pan1(brlyt_entry entry, u8* brlyt_file, mxml_node_t *tag) { - mxml_node_t *flags1, *alpha1; - mxml_node_t *coords, *x, *y, *z; - mxml_node_t *flip, *rotate, *zoom; + char origins[9][15]; + memset( origins , 0 , 8 * 20 ); + strcpy( origins[0] , "TOP LEFT" ); + strcpy( origins[1] , "TOP CENTER" ); + strcpy( origins[2] , "TOP RIGHT" ); + strcpy( origins[3] , "MIDDLE LEFT" ); + strcpy( origins[4] , "MIDDLE CENTER" ); + strcpy( origins[5] , "MIDDLE RIGHT" ); + strcpy( origins[6] , "BOTTOM LEFT" ); + strcpy( origins[7] , "BOTTOM CENTER" ); + strcpy( origins[8] , "BOTTOM RIGHT" ); + + mxml_node_t *flags, *origin, *alpha, *padding; + mxml_node_t *translate, *x, *y, *z; + mxml_node_t *rotate, *scale; mxml_node_t *size, *width, *height; brlyt_pane_chunk data; BRLYT_fileoffset = entry.data_location; BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_pane_chunk)); mxmlElementSetAttrf(tag, "type", "%.4s", entry.magic); mxmlElementSetAttrf(tag, "name", "%s", data.name); - flags1 = mxmlNewElement(tag, "flags"); mxmlNewTextf(flags1, 0, "%02x-%02x", data.flag1, data.flag2); - alpha1 = mxmlNewElement(tag, "alpha"); mxmlNewTextf(alpha1, 0, "%02x-%02x", data.alpha, data.alpha2); - coords = mxmlNewElement(tag, "coords"); - x = mxmlNewElement(coords, "x"); mxmlNewTextf(x, 0, "%.20f", float_swap_bytes(data.x)); - y = mxmlNewElement(coords, "y"); mxmlNewTextf(y, 0, "%.20f", float_swap_bytes(data.y)); - z = mxmlNewElement(coords, "z"); mxmlNewTextf(z, 0, "%.20f", float_swap_bytes(data.z)); - flip = mxmlNewElement(tag, "flip"); - x = mxmlNewElement(flip, "x"); mxmlNewTextf(x, 0, "%.20f", float_swap_bytes(data.flip_x)); - y = mxmlNewElement(flip, "y"); mxmlNewTextf(y, 0, "%.20f", float_swap_bytes(data.flip_y)); - rotate = mxmlNewElement(tag, "rotate"); mxmlNewTextf(rotate, 0, "%.20f", float_swap_bytes(data.angle)); - zoom = mxmlNewElement(tag, "zoom"); - x = mxmlNewElement(zoom, "x"); mxmlNewTextf(x, 0, "%.10f", float_swap_bytes(data.xmag)); - y = mxmlNewElement(zoom, "y"); mxmlNewTextf(y, 0, "%.10f", float_swap_bytes(data.ymag)); + mxmlElementSetAttrf(tag, "userdata", "%s", data.userdata); + flags = mxmlNewElement(tag, "visible"); mxmlNewTextf(flags, 0, "%02x", data.flag1 & 0x1); + flags = mxmlNewElement(tag, "WidescreenAffected"); mxmlNewTextf(flags, 0, "%02x", (data.flag1 & 0x2)>>1); + flags = mxmlNewElement(tag, "flag"); mxmlNewTextf(flags, 0, "%02x", (data.flag1 & 0x4)>>2); + origin = mxmlNewElement(tag, "origin"); mxmlNewTextf(origin,0,"%s",origins[data.origin%9]); + alpha = mxmlNewElement(tag, "alpha"); mxmlNewTextf(alpha, 0, "%02x", data.alpha); + padding = mxmlNewElement(tag, "padding"); mxmlNewTextf(padding, 0, "%02x", data.pad); + translate = mxmlNewElement(tag, "translate"); + x = mxmlNewElement(translate, "x"); mxmlNewTextf(x, 0, "%.20f", float_swap_bytes(data.XTrans)); + y = mxmlNewElement(translate, "y"); mxmlNewTextf(y, 0, "%.20f", float_swap_bytes(data.YTrans)); + z = mxmlNewElement(translate, "z"); mxmlNewTextf(z, 0, "%.20f", float_swap_bytes(data.ZTrans)); + rotate = mxmlNewElement(tag, "rotate"); + x = mxmlNewElement(rotate, "x"); mxmlNewTextf(x, 0, "%.20f", float_swap_bytes(data.XRotate)); + y = mxmlNewElement(rotate, "y"); mxmlNewTextf(y, 0, "%.20f", float_swap_bytes(data.YRotate)); + z = mxmlNewElement(rotate, "z"); mxmlNewTextf(z, 0, "%.20f", float_swap_bytes(data.ZRotate)); + scale = mxmlNewElement(tag, "scale"); + x = mxmlNewElement(scale, "x"); mxmlNewTextf(x, 0, "%.10f", float_swap_bytes(data.XScale)); + y = mxmlNewElement(scale, "y"); mxmlNewTextf(y, 0, "%.10f", float_swap_bytes(data.YScale)); size = mxmlNewElement(tag, "size"); width = mxmlNewElement(size, "width"); mxmlNewTextf(width, 0, "%f", float_swap_bytes(data.width)); height = mxmlNewElement(size, "height"); mxmlNewTextf(height, 0, "%f", float_swap_bytes(data.height)); @@ -329,76 +350,89 @@ void PrintBRLYTEntry_pan1(brlyt_entry entry, u8* brlyt_file, mxml_node_t *tag) void PrintBRLYTEntry_wnd1(brlyt_entry entry, u8* brlyt_file, mxml_node_t *tag) { - mxml_node_t *flags1, *alpha1; - mxml_node_t *coords, *x, *y, *z; - mxml_node_t *flip, *rotate, *zoom; + char origins[9][15]; + memset( origins , 0 , 8 * 20 ); + strcpy( origins[0] , "TOP LEFT" ); + strcpy( origins[1] , "TOP CENTER" ); + strcpy( origins[2] , "TOP RIGHT" ); + strcpy( origins[3] , "MIDDLE LEFT" ); + strcpy( origins[4] , "MIDDLE CENTER" ); + strcpy( origins[5] , "MIDDLE RIGHT" ); + strcpy( origins[6] , "BOTTOM LEFT" ); + strcpy( origins[7] , "BOTTOM CENTER" ); + strcpy( origins[8] , "BOTTOM RIGHT" ); + + mxml_node_t *flags, *origin, *alpha, *padding; + mxml_node_t *translate, *x, *y, *z; + mxml_node_t *rotate, *scale; mxml_node_t *size, *width, *height; brlyt_pane_chunk data; BRLYT_fileoffset = entry.data_location; BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_pane_chunk)); mxmlElementSetAttrf(tag, "type", "%.4s", entry.magic); mxmlElementSetAttrf(tag, "name", "%s", data.name); - flags1 = mxmlNewElement(tag, "flags"); mxmlNewTextf(flags1, 0, "%02x-%02x", data.flag1, data.flag2); - alpha1 = mxmlNewElement(tag, "alpha"); mxmlNewTextf(alpha1, 0, "%02x-%02x", data.alpha, data.alpha2); - coords = mxmlNewElement(tag, "coords"); - x = mxmlNewElement(coords, "x"); mxmlNewTextf(x, 0, "%.20f", float_swap_bytes(data.x)); - y = mxmlNewElement(coords, "y"); mxmlNewTextf(y, 0, "%.20f", float_swap_bytes(data.y)); - z = mxmlNewElement(coords, "z"); mxmlNewTextf(z, 0, "%.20f", float_swap_bytes(data.z)); - flip = mxmlNewElement(tag, "flip"); - x = mxmlNewElement(flip, "x"); mxmlNewTextf(x, 0, "%f", float_swap_bytes(data.flip_x)); - y = mxmlNewElement(flip, "y"); mxmlNewTextf(y, 0, "%f", float_swap_bytes(data.flip_y)); - rotate = mxmlNewElement(tag, "rotate"); mxmlNewTextf(rotate, 0, "%f", float_swap_bytes(data.angle)); - zoom = mxmlNewElement(tag, "zoom"); - x = mxmlNewElement(zoom, "x"); mxmlNewTextf(x, 0, "%.10f", float_swap_bytes(data.xmag)); - y = mxmlNewElement(zoom, "y"); mxmlNewTextf(y, 0, "%.10f", float_swap_bytes(data.ymag)); + mxmlElementSetAttrf(tag, "userdata", "%s", data.userdata); + flags = mxmlNewElement(tag, "visible"); mxmlNewTextf(flags, 0, "%02x", data.flag1 & 0x1); + flags = mxmlNewElement(tag, "WidescreenAffected"); mxmlNewTextf(flags, 0, "%02x", (data.flag1 & 0x2)>>1); + flags = mxmlNewElement(tag, "flag"); mxmlNewTextf(flags, 0, "%02x", (data.flag1 & 0x4)>>2); + origin = mxmlNewElement(tag, "origin"); mxmlNewTextf(origin,0,"%s", origins[data.origin%9]); + alpha = mxmlNewElement(tag, "alpha"); mxmlNewTextf(alpha, 0, "%02x", data.alpha); + padding = mxmlNewElement(tag, "padding"); mxmlNewTextf(padding, 0, "%02x", data.pad); + translate = mxmlNewElement(tag, "translate"); + x = mxmlNewElement(translate, "x"); mxmlNewTextf(x, 0, "%.20f", float_swap_bytes(data.XTrans)); + y = mxmlNewElement(translate, "y"); mxmlNewTextf(y, 0, "%.20f", float_swap_bytes(data.YTrans)); + z = mxmlNewElement(translate, "z"); mxmlNewTextf(z, 0, "%.20f", float_swap_bytes(data.ZTrans)); + rotate = mxmlNewElement(tag, "rotate"); + x = mxmlNewElement(rotate, "x"); mxmlNewTextf(x, 0, "%.20f", float_swap_bytes(data.XRotate)); + y = mxmlNewElement(rotate, "y"); mxmlNewTextf(y, 0, "%.20f", float_swap_bytes(data.YRotate)); + z = mxmlNewElement(rotate, "z"); mxmlNewTextf(z, 0, "%.20f", float_swap_bytes(data.ZRotate)); + scale = mxmlNewElement(tag, "scale"); + x = mxmlNewElement(scale, "x"); mxmlNewTextf(x, 0, "%.10f", float_swap_bytes(data.XScale)); + y = mxmlNewElement(scale, "y"); mxmlNewTextf(y, 0, "%.10f", float_swap_bytes(data.YScale)); size = mxmlNewElement(tag, "size"); width = mxmlNewElement(size, "width"); mxmlNewTextf(width, 0, "%f", float_swap_bytes(data.width)); height = mxmlNewElement(size, "height"); mxmlNewTextf(height, 0, "%f", float_swap_bytes(data.height)); mxml_node_t *wndd, *unkk, *count, *offset1, *offset2; - int i; + int i, j; brlyt_wnd wndy; BRLYT_ReadDataFromMemory(&wndy, brlyt_file, sizeof(brlyt_wnd)); wndd = mxmlNewElement(tag, "wnd"); for(i=0;i<4;i++) { - unkk = mxmlNewElement(wndd, "unk1"); mxmlNewTextf(unkk, 0, "%f", float_swap_bytes(wndy.unk1[i])); + unkk = mxmlNewElement(wndd, "coordinate"); mxmlNewTextf(unkk, 0, "%f", float_swap_bytes(wndy.coords[i])); } - count = mxmlNewElement(wndd, "count"); mxmlNewTextf(count, 0, "%02x", wndy.count); + count = mxmlNewElement(wndd, "FrameCount"); mxmlNewTextf(count, 0, "%02x", wndy.frame_count); offset1 = mxmlNewElement(wndd, "offset1"); mxmlNewTextf(offset1, 0, "%08x", be32(wndy.offset1)); offset2 = mxmlNewElement(wndd, "offset2"); mxmlNewTextf(offset2, 0, "%08x", be32(wndy.offset2)); - mxml_node_t *wnddd, *unkkk; + mxml_node_t *wnddd, *colors, *material; brlyt_wnd1 wndy1; BRLYT_ReadDataFromMemory(&wndy1, brlyt_file, sizeof(brlyt_wnd1)); wnddd = mxmlNewElement(tag, "wnd1"); for(i=0;i<4;i++) { - unkkk = mxmlNewElement(wnddd, "unk1"); mxmlNewTextf(unkkk, 0, "%08x", int_swap_bytes(wndy1.unk1[i])); + colors = mxmlNewElement(wnddd, "color"); mxmlNewTextf(colors, 0, "%08x", int_swap_bytes(wndy1.colors[i])); } - mxml_node_t *wndddd, *unkkkk, *unkkkk2; - brlyt_wnd2 wndy2; - BRLYT_ReadDataFromMemory(&wndy2, brlyt_file, sizeof(brlyt_wnd2)); - wndddd = mxmlNewElement(tag, "wnd2"); - unkkkk = mxmlNewElement(wndddd, "unk1"); mxmlNewTextf(unkkkk, 0, "%04x", short_swap_bytes(wndy2.unk1)); - unkkkk2 = mxmlNewElement(wndddd, "unk2"); mxmlNewTextf(unkkkk2, 0, "%04x", short_swap_bytes(wndy2.unk2)); + material = mxmlNewElement(wnddd, "material"); mxmlNewTextf(material, 0, "%04x", short_swap_bytes(wndy1.material)); + count = mxmlNewElement(wnddd, "CoordinateCount"); mxmlNewTextf(count, 0, "%02x", short_swap_bytes(wndy1.coordinate_count)); + padding = mxmlNewElement(wnddd, "padding"); mxmlNewTextf(padding, 0, "%02x", short_swap_bytes(wndy1.padding)); mxml_node_t *wnddddd, *texcoord; - if(wndy.offset2 == be32(0x0000009c)) - { - brlyt_wnd3 wndy3; - BRLYT_ReadDataFromMemory(&wndy3, brlyt_file, sizeof(brlyt_wnd3)); - wnddddd = mxmlNewElement(tag, "wnd3"); - for(i=0;i<8;i++) - { - texcoord = mxmlNewElement(wnddddd, "texcoord"); mxmlNewTextf(texcoord, 0, "%f", float_swap_bytes(wndy3.texcoords[i])); - } - } + for ( i = 0 ; i < wndy1.coordinate_count ; i++ ){ + brlyt_wnd3 wndy3; + BRLYT_ReadDataFromMemory(&wndy3, brlyt_file, sizeof(brlyt_wnd3)); + wnddddd = mxmlNewElement(tag, "Coords"); + for ( j = 0 ; j < 8 ; j++ ) { + texcoord = mxmlNewElement(wnddddd, "texcoord"); mxmlNewTextf(texcoord, 0, "%f", float_swap_bytes(wndy3.texcoords[j])); + } + + } mxml_node_t *wndddddd, *offsett; brlyt_wnd4 wndy4; - for(i=0;i>1); + flags = mxmlNewElement(tag, "flag"); mxmlNewTextf(flags, 0, "%02x", (data.flag1 & 0x4)>>2); + origin = mxmlNewElement(tag, "origin"); mxmlNewTextf(origin,0,"%s", origins[data.origin%9]); + alpha = mxmlNewElement(tag, "alpha"); mxmlNewTextf(alpha, 0, "%02x", data.alpha); + padding = mxmlNewElement(tag, "padding"); mxmlNewTextf(padding, 0, "%02x", data.pad); + translate = mxmlNewElement(tag, "translate"); + x = mxmlNewElement(translate, "x"); mxmlNewTextf(x, 0, "%.25f", float_swap_bytes(data.XTrans)); + y = mxmlNewElement(translate, "y"); mxmlNewTextf(y, 0, "%.25f", float_swap_bytes(data.YTrans)); + z = mxmlNewElement(translate, "z"); mxmlNewTextf(z, 0, "%.25f", float_swap_bytes(data.ZTrans)); + rotate = mxmlNewElement(tag, "rotate"); + x = mxmlNewElement(rotate, "x"); mxmlNewTextf(x, 0, "%.20f", float_swap_bytes(data.XRotate)); + y = mxmlNewElement(rotate, "y"); mxmlNewTextf(y, 0, "%.20f", float_swap_bytes(data.YRotate)); + z = mxmlNewElement(rotate, "z"); mxmlNewTextf(z, 0, "%.20f", float_swap_bytes(data.ZRotate)); + scale = mxmlNewElement(tag, "scale"); + x = mxmlNewElement(scale, "x"); mxmlNewTextf(x, 0, "%.10f", float_swap_bytes(data.XScale)); + y = mxmlNewElement(scale, "y"); mxmlNewTextf(y, 0, "%.10f", float_swap_bytes(data.YScale)); size = mxmlNewElement(tag, "size"); width = mxmlNewElement(size, "width"); mxmlNewTextf(width, 0, "%f", float_swap_bytes(data.width)); height = mxmlNewElement(size, "height"); mxmlNewTextf(height, 0, "%f", float_swap_bytes(data.height)); @@ -446,9 +499,21 @@ void PrintBRLYTEntry_bnd1(brlyt_entry entry, u8* brlyt_file, mxml_node_t *tag) void PrintBRLYTEntry_pic1(brlyt_entry entry, u8* brlyt_file, mxml_node_t *tag) { - mxml_node_t *flags1, *alpha1; - mxml_node_t *coords, *x, *y, *z; - mxml_node_t *flip, *rotate, *zoom; + char origins[9][15]; + memset( origins , 0 , 8 * 20 ); + strcpy( origins[0] , "TOP LEFT" ); + strcpy( origins[1] , "TOP CENTER" ); + strcpy( origins[2] , "TOP RIGHT" ); + strcpy( origins[3] , "MIDDLE LEFT" ); + strcpy( origins[4] , "MIDDLE CENTER" ); + strcpy( origins[5] , "MIDDLE RIGHT" ); + strcpy( origins[6] , "BOTTOM LEFT" ); + strcpy( origins[7] , "BOTTOM CENTER" ); + strcpy( origins[8] , "BOTTOM RIGHT" ); + + mxml_node_t *flags, *origin, *alpha, *padding; + mxml_node_t *translate, *x, *y, *z; + mxml_node_t *rotate, *scale; mxml_node_t *size, *width, *height; brlyt_pane_chunk data; BRLYT_fileoffset = entry.data_location; @@ -457,28 +522,34 @@ void PrintBRLYTEntry_pic1(brlyt_entry entry, u8* brlyt_file, mxml_node_t *tag) BRLYT_ReadDataFromMemory(&data2, brlyt_file, sizeof(brlyt_pic_chunk)); mxmlElementSetAttrf(tag, "type", "%.4s", entry.magic); mxmlElementSetAttrf(tag, "name", "%s", data.name); - flags1 = mxmlNewElement(tag, "flags"); mxmlNewTextf(flags1, 0, "%02x-%02x", data.flag1, data.flag2); - alpha1 = mxmlNewElement(tag, "alpha"); mxmlNewTextf(alpha1, 0, "%02x-%02x", data.alpha, data.alpha2); - coords = mxmlNewElement(tag, "coords"); - x = mxmlNewElement(coords, "x"); mxmlNewTextf(x, 0, "%.20f", float_swap_bytes(data.x)); - y = mxmlNewElement(coords, "y"); mxmlNewTextf(y, 0, "%.20f", float_swap_bytes(data.y)); - z = mxmlNewElement(coords, "z"); mxmlNewTextf(z, 0, "%.20f", float_swap_bytes(data.z)); - flip = mxmlNewElement(tag, "flip"); - x = mxmlNewElement(flip, "x"); mxmlNewTextf(x, 0, "%f", float_swap_bytes(data.flip_x)); - y = mxmlNewElement(flip, "y"); mxmlNewTextf(y, 0, "%f", float_swap_bytes(data.flip_y)); - rotate = mxmlNewElement(tag, "rotate"); mxmlNewTextf(rotate, 0, "%f", float_swap_bytes(data.angle)); - zoom = mxmlNewElement(tag, "zoom"); - x = mxmlNewElement(zoom, "x"); mxmlNewTextf(x, 0, "%.10f", float_swap_bytes(data.xmag)); - y = mxmlNewElement(zoom, "y"); mxmlNewTextf(y, 0, "%.10f", float_swap_bytes(data.ymag)); + mxmlElementSetAttrf(tag, "userdata", "%s", data.userdata); + flags = mxmlNewElement(tag, "visible"); mxmlNewTextf(flags, 0, "%02x", data.flag1 & 0x1); + flags = mxmlNewElement(tag, "WidescreenAffected"); mxmlNewTextf(flags, 0, "%02x", (data.flag1 & 0x2)>>1); + flags = mxmlNewElement(tag, "flag"); mxmlNewTextf(flags, 0, "%02x", (data.flag1 & 0x4)>>2); + origin = mxmlNewElement(tag, "origin"); mxmlNewTextf(origin,0,"%s", origins[data.origin%9]); + alpha = mxmlNewElement(tag, "alpha"); mxmlNewTextf(alpha, 0, "%02x", data.alpha); + padding = mxmlNewElement(tag, "padding"); mxmlNewTextf(padding, 0, "%02x", data.pad); + translate = mxmlNewElement(tag, "translate"); + x = mxmlNewElement(translate, "x"); mxmlNewTextf(x, 0, "%.20f", float_swap_bytes(data.XTrans)); + y = mxmlNewElement(translate, "y"); mxmlNewTextf(y, 0, "%.20f", float_swap_bytes(data.YTrans)); + z = mxmlNewElement(translate, "z"); mxmlNewTextf(z, 0, "%.20f", float_swap_bytes(data.ZTrans + )); + rotate = mxmlNewElement(tag, "rotate"); + x = mxmlNewElement(rotate, "x"); mxmlNewTextf(x, 0, "%.20f", float_swap_bytes(data.XRotate)); + y = mxmlNewElement(rotate, "y"); mxmlNewTextf(y, 0, "%.20f", float_swap_bytes(data.YRotate)); + z = mxmlNewElement(rotate, "z"); mxmlNewTextf(z, 0, "%.20f", float_swap_bytes(data.ZRotate)); + scale = mxmlNewElement(tag, "scale"); + x = mxmlNewElement(scale, "x"); mxmlNewTextf(x, 0, "%.10f", float_swap_bytes(data.XScale)); + y = mxmlNewElement(scale, "y"); mxmlNewTextf(y, 0, "%.10f", float_swap_bytes(data.YScale)); size = mxmlNewElement(tag, "size"); width = mxmlNewElement(size, "width"); mxmlNewTextf(width, 0, "%f", float_swap_bytes(data.width)); height = mxmlNewElement(size, "height"); mxmlNewTextf(height, 0, "%f", float_swap_bytes(data.height)); mxml_node_t *material, *color, *vtx, *coordinates, *set, *coord; - material = mxmlNewElement(tag, "material"); mxmlElementSetAttrf(material, "name", "%s", getMaterial(short_swap_bytes(data2.mat_off))); + material = mxmlNewElement(tag, "material"); mxmlElementSetAttrf(material, "name", "%s", getMaterial(short_swap_bytes(data2.mat_num))); color = mxmlNewElement(tag, "colors"); int n; for (n=0;n<4;n++) { - vtx = mxmlNewElement(color, "vtx"); mxmlNewTextf(vtx, 0, "%#08X", be32(data2.vtx_colors[n])); + vtx = mxmlNewElement(color, "vtx"); mxmlNewTextf(vtx, 0, "%08X", be32(data2.vtx_colors[n])); } coordinates = mxmlNewElement(tag, "coordinates"); for (n=0;n>1); + flags = mxmlNewElement(tag, "flag"); mxmlNewTextf(flags, 0, "%02x", (data.flag1 & 0x4)>>2); + origin = mxmlNewElement(tag, "origin"); mxmlNewTextf(origin,0,"%s", origins[data.origin%9]); + alpha = mxmlNewElement(tag, "alpha"); mxmlNewTextf(alpha, 0, "%02x", data.alpha); + padding = mxmlNewElement(tag, "padding"); mxmlNewTextf(padding, 0, "%02x", data.pad); + translate = mxmlNewElement(tag, "translate"); + x = mxmlNewElement(translate, "x"); mxmlNewTextf(x, 0, "%.16f", float_swap_bytes(data.XTrans)); + y = mxmlNewElement(translate, "y"); mxmlNewTextf(y, 0, "%.16f", float_swap_bytes(data.YTrans)); + z = mxmlNewElement(translate, "z"); mxmlNewTextf(z, 0, "%.16f", float_swap_bytes(data.ZTrans)); + rotate = mxmlNewElement(tag, "rotate"); + x = mxmlNewElement(rotate, "x"); mxmlNewTextf(x, 0, "%.20f", float_swap_bytes(data.XRotate)); + y = mxmlNewElement(rotate, "y"); mxmlNewTextf(y, 0, "%.20f", float_swap_bytes(data.YRotate)); + z = mxmlNewElement(rotate, "z"); mxmlNewTextf(z, 0, "%.20f", float_swap_bytes(data.ZRotate)); + scale = mxmlNewElement(tag, "scale"); + x = mxmlNewElement(scale, "x"); mxmlNewTextf(x, 0, "%.10f", float_swap_bytes(data.XScale)); + y = mxmlNewElement(scale, "y"); mxmlNewTextf(y, 0, "%.10f", float_swap_bytes(data.YScale)); size = mxmlNewElement(tag, "size"); width = mxmlNewElement(size, "width"); mxmlNewTextf(width, 0, "%.20f", float_swap_bytes(data.width)); height = mxmlNewElement(size, "height"); mxmlNewTextf(height, 0, "%.20f", float_swap_bytes(data.height)); - mxml_node_t *length, *font, *xsize, *ysize, *charsize, *linesize, *alignment, *color, *text; + mxml_node_t *length, *font, *xsize, *ysize, *charsize, *linesize, *alignment, *color1, *color2, *text; brlyt_text_chunk data2; BRLYT_ReadDataFromMemory(&data2, brlyt_file, sizeof(brlyt_text_chunk)); - unsigned char texty[short_swap_bytes(data2.len2)]; + u8 texty[short_swap_bytes(data2.len2)]; memcpy(texty, &brlyt_file[BRLYT_fileoffset], short_swap_bytes(data2.len2)); length = mxmlNewElement(tag, "length"); mxmlNewTextf(length, 0, "%04x-%04x", short_swap_bytes(data2.len2), short_swap_bytes(data2.len2)); font = mxmlNewElement(tag, "font"); mxmlElementSetAttrf(font, "index", "%d", short_swap_bytes(data2.font_idx)); @@ -532,10 +632,11 @@ void PrintBRLYTEntry_txt1(brlyt_entry entry, u8* brlyt_file, mxml_node_t *tag) ysize = mxmlNewElement(font, "ysize"); mxmlNewTextf(ysize, 0, "%f", float_swap_bytes(data2.font_size_y)); charsize = mxmlNewElement(font, "charsize"); mxmlNewTextf(charsize, 0, "%f", float_swap_bytes(data2.char_space)); linesize = mxmlNewElement(font, "linesize"); mxmlNewTextf(linesize, 0, "%f", float_swap_bytes(data2.line_space)); - alignment = mxmlNewElement(font, "alignment"); mxmlNewTextf(alignment, 0, "%02x", data2.alignment); - color = mxmlNewElement(tag, "color"); mxmlNewTextf(color, 0, "%08x-%08x", be32(data2.color1), be32(data2.color2)); + alignment = mxmlNewElement(font, "alignment"); mxmlNewTextf(alignment, 0, "%s", alignments[data2.alignment%9]); + color1 = mxmlNewElement(tag, "color1"); mxmlNewTextf(color1, 0, "%08x", be32(data2.color1) ); + color2 = mxmlNewElement(tag, "color2"); mxmlNewTextf(color2, 0, "%08x", be32(data2.color2) ); // int q; for(q=0;q disappears. - //# 2nd --> no visible effect. - //# 3rd --> disappears. - //# 4th --> no visible effect. mxml_node_t *ua4; //# 4 * flags[6] for (n=0;n> 0] ); + dataa = mxmlNewElement(ua6, "OneGreen"); + mxmlNewTextf(dataa, 0, "%s", tevcolor[(data4.one & 0x0C) >> 2] ); + dataa = mxmlNewElement(ua6, "OneBlue"); + mxmlNewTextf(dataa, 0, "%s", tevcolor[(data4.one & 0x30) >> 4] ); + dataa = mxmlNewElement(ua6, "OneAlpha"); + mxmlNewTextf(dataa, 0, "%s", tevcolor[(data4.one & 0xC0) >> 6] ); + + dataa = mxmlNewElement(ua6, "TwoRed"); + mxmlNewTextf(dataa, 0, "%s", tevcolor[(data4.two & 0x03) >> 0] ); + dataa = mxmlNewElement(ua6, "TwoGreen"); + mxmlNewTextf(dataa, 0, "%s", tevcolor[(data4.two & 0x0C) >> 2] ); + dataa = mxmlNewElement(ua6, "TwoBlue"); + mxmlNewTextf(dataa, 0, "%s", tevcolor[(data4.two & 0x30) >> 4] ); + dataa = mxmlNewElement(ua6, "TwoAlpha"); + mxmlNewTextf(dataa, 0, "%s", tevcolor[(data4.two & 0xC0) >> 6] ); + + dataa = mxmlNewElement(ua6, "ThreeRed"); + mxmlNewTextf(dataa, 0, "%s", tevcolor[(data4.three & 0x03) >> 0] ); + dataa = mxmlNewElement(ua6, "ThreeGreen"); + mxmlNewTextf(dataa, 0, "%s", tevcolor[(data4.three & 0x0C) >> 2] ); + dataa = mxmlNewElement(ua6, "ThreeBlue"); + mxmlNewTextf(dataa, 0, "%s", tevcolor[(data4.three & 0x30) >> 4] ); + dataa = mxmlNewElement(ua6, "ThreeAlpha"); + mxmlNewTextf(dataa, 0, "%s", tevcolor[(data4.three & 0xC0) >> 6] ); + + dataa = mxmlNewElement(ua6, "FourRed"); + mxmlNewTextf(dataa, 0, "%s", tevcolor[(data4.four & 0x03) >> 0] ); + dataa = mxmlNewElement(ua6, "FourGreen"); + mxmlNewTextf(dataa, 0, "%s", tevcolor[(data4.four & 0x0C) >> 2] ); + dataa = mxmlNewElement(ua6, "FourBlue"); + mxmlNewTextf(dataa, 0, "%s", tevcolor[(data4.four & 0x30) >> 4] ); + dataa = mxmlNewElement(ua6, "FourAlpha"); + mxmlNewTextf(dataa, 0, "%s", tevcolor[(data4.four & 0xC0) >> 6] ); + } mxml_node_t *ua7, *a, *b, *c, *d, *e; for (n=0;n> 8; + + valnode=mxmlFindElement(setnode, setnode, "Color", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.color = strtoul( tempCoord , NULL , 16 ); + + valnode=mxmlFindElement(setnode, setnode, "Padding1", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.empty1 = strtoul( tempCoord , NULL , 16 ); + chunkUa9.empty1 = 0; + + valnode=mxmlFindElement(setnode, setnode, "RasSelect", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.ras_sel = strtoul( tempCoord , NULL , 16 ); + + valnode=mxmlFindElement(setnode, setnode, "TexSelect", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.tex_sel = strtoul( tempCoord , NULL , 16 ); + + valnode=mxmlFindElement(setnode, setnode, "TevColorCombinerA", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.aC = strtoul( tempCoord , NULL , 16 ); + + valnode=mxmlFindElement(setnode, setnode, "TevColorCombinerB", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.bC = strtoul( tempCoord , NULL , 16 ); + + valnode=mxmlFindElement(setnode, setnode, "TevColorCombinerC", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.cC = strtoul( tempCoord , NULL , 16 ); + + valnode=mxmlFindElement(setnode, setnode, "TevColorCombinerD", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.dC = strtoul( tempCoord , NULL , 16 ); + + valnode=mxmlFindElement(setnode, setnode, "TevColorOp", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.tevopC = strtoul( tempCoord , NULL , 16 ); + + valnode=mxmlFindElement(setnode, setnode, "TevColorBias", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.tevbiasC = strtoul( tempCoord , NULL , 16 ); + + valnode=mxmlFindElement(setnode, setnode, "TevColorScale", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.tevscaleC = strtoul( tempCoord , NULL , 16 ); + + valnode=mxmlFindElement(setnode, setnode, "TevColorClamp", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.clampC = strtoul( tempCoord , NULL , 16 ); + + valnode=mxmlFindElement(setnode, setnode, "TevColorRegisterID", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.tevregidC = strtoul( tempCoord , NULL , 16 ); + + valnode=mxmlFindElement(setnode, setnode, "TevKColorSelect", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.selC = strtoul( tempCoord , NULL , 16 ); + + valnode=mxmlFindElement(setnode, setnode, "TevAlphaCombinerA", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.aA = strtoul( tempCoord , NULL , 16 ); + + valnode=mxmlFindElement(setnode, setnode, "TevAlphaCombinerB", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.bA = strtoul( tempCoord , NULL , 16 ); + + valnode=mxmlFindElement(setnode, setnode, "TevAlphaCombinerC", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.cA = strtoul( tempCoord , NULL , 16 ); + + valnode=mxmlFindElement(setnode, setnode, "TevAlphaCombinerD", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.dA = strtoul( tempCoord , NULL , 16 ); + + valnode=mxmlFindElement(setnode, setnode, "TevAlphaOp", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.tevopA = strtoul( tempCoord , NULL , 16 ); + + valnode=mxmlFindElement(setnode, setnode, "TevAlphaBias", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.tevbiasA = strtoul( tempCoord , NULL , 16 ); + + valnode=mxmlFindElement(setnode, setnode, "TevAlphaScale", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.tevscaleA = strtoul( tempCoord , NULL , 16 ); + + valnode=mxmlFindElement(setnode, setnode, "TevAlphaClamp", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.clampA = strtoul( tempCoord , NULL , 16 ); + + valnode=mxmlFindElement(setnode, setnode, "TevAlphaRegisterID", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.tevregidA = strtoul( tempCoord , NULL , 16 ); + + valnode=mxmlFindElement(setnode, setnode, "TevKAlphaSelect", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.selA = strtoul( tempCoord , NULL , 16 ); + + valnode=mxmlFindElement(setnode, setnode, "IndirectTextureID", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.indtexid = strtoul( tempCoord , NULL , 16 ); + + valnode=mxmlFindElement(setnode, setnode, "IndirectTextureFormat", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.format = strtoul( tempCoord , NULL , 16 ); + + valnode=mxmlFindElement(setnode, setnode, "IndirectTextureBias", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.bias = strtoul( tempCoord , NULL , 16 ); + + valnode=mxmlFindElement(setnode, setnode, "IndirectTextureMatrixID", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.mtxid = strtoul( tempCoord , NULL , 16 ); + + valnode=mxmlFindElement(setnode, setnode, "IndirectTextureWrapS", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.wrap_s = strtoul( tempCoord , NULL , 16 ); + + valnode=mxmlFindElement(setnode, setnode, "IndirectTextureWrapT", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.wrap_t = strtoul( tempCoord , NULL , 16 ); + + valnode=mxmlFindElement(setnode, setnode, "IndirectTextureAddPrevious", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.addprev = strtoul( tempCoord , NULL , 16 ); + + valnode=mxmlFindElement(setnode, setnode, "IndirectTextureUTClod", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.utclod = strtoul( tempCoord , NULL , 16 ); + + valnode=mxmlFindElement(setnode, setnode, "IndirectTextureA", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.aIND = strtoul( tempCoord , NULL , 16 ); + + valnode=mxmlFindElement(setnode, setnode, "Padding2", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.empty2 = strtoul( tempCoord , NULL , 16 ); + chunkUa9.empty2 = 0; + + valnode=mxmlFindElement(setnode, setnode, "Padding3", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.empty3 = strtoul( tempCoord , NULL , 16 ); + chunkUa9.empty3 = 0; + + valnode=mxmlFindElement(setnode, setnode, "Padding4", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUa9.empty4 = strtoul( tempCoord , NULL , 16 ); + chunkUa9.empty4 = 0; + + flags.flag.ua9++; + fwrite(&chunkUa9, sizeof(chunkUa9), 1, fp); *fileOffset = *fileOffset + sizeof(chunkUa9); matSize += sizeof(chunkUa9); } - brlyt_4b_chunk chunkUaa; - for(setnode = mxmlFindElement(subnode, subnode, "uaa", NULL, NULL, MXML_DESCEND); setnode != NULL; setnode = mxmlFindElement(setnode, subnode, "uaa", NULL, NULL, MXML_DESCEND)) - { + + brlyt_alpha_compare chunkUaa; + for(setnode = mxmlFindElement(subnode, subnode, "AlphaCompare", NULL, NULL, MXML_DESCEND); setnode != NULL; setnode = mxmlFindElement(setnode, subnode, "AlphaCompare", NULL, NULL, MXML_DESCEND)) + { + char compare[8][20]; + int l; + for ( l = 0 ; l < 8 ; l++ ) + memset( compare[l] , 0 , 20 ); + strcpy( compare[0] , "GX_NEVER" ); + strcpy( compare[1] , "GX_LESS" ); + strcpy( compare[2] , "GX_EQUAL" ); + strcpy( compare[3] , "GX_LEQUAL" ); + strcpy( compare[4] , "GX_GREATER" ); + strcpy( compare[5] , "GX_NEQUAL" ); + strcpy( compare[6] , "GX_GEQUAL" ); + strcpy( compare[7] , "GX_ALWAYS" ); + + char aop[5][20]; + for ( l = 0 ; l < 5 ; l++ ) + memset( aop[l] , 0 , 20 ); + strcpy( aop[0] , "GX_AOP_AND" ); + strcpy( aop[1] , "GX_AOP_OR" ); + strcpy( aop[2] , "GX_AOP_XOR" ); + strcpy( aop[3] , "GX_AOP_XNOR" ); + strcpy( aop[4] , "GX_MAX_ALPHAOP" ); + mxml_node_t *valnode; - int dataNumber = 0; - for (valnode=mxmlFindElement(setnode, setnode, "data", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "data", NULL, NULL, MXML_DESCEND) ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunkUaa.unk[dataNumber] = strtoul(tempCoord, NULL, 16); - dataNumber+=1; - } + char tempCoord[256]; + + valnode=mxmlFindElement(setnode, setnode, "comp0", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value(valnode, tempCoord, 256); + chunkUaa.comp0 = strtoul(tempCoord, NULL, 16); + for ( l = 0 ; l < 8 ; l++ ){ + if ( strncmp( compare[l] , tempCoord , 14 ) == 0 ) { + chunkUaa.comp0 = l; + break; + } + } + + valnode=mxmlFindElement(setnode, setnode, "comp1", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value(valnode, tempCoord, 256); + chunkUaa.comp1 = strtoul(tempCoord, NULL, 16); + for ( l = 0 ; l < 8 ; l++ ){ + if ( strncmp( compare[l] , tempCoord , 14 ) == 0 ) { + chunkUaa.comp1 = l; + break; + } + } + + valnode=mxmlFindElement(setnode, setnode, "aop", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value(valnode, tempCoord, 256); + chunkUaa.aop = strtoul(tempCoord, NULL, 16); + for ( l = 0 ; l < 5 ; l++ ){ + if ( strncmp( aop[l] , tempCoord , 14 ) == 0 ) { + chunkUaa.aop = l; + break; + } + } + + valnode=mxmlFindElement(setnode, setnode, "ref0", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value(valnode, tempCoord, 256); + chunkUaa.ref0 = strtoul(tempCoord, NULL, 16); + + valnode=mxmlFindElement(setnode, setnode, "ref1", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value(valnode, tempCoord, 256); + chunkUaa.ref1 = strtoul(tempCoord, NULL, 16); + + flags.flag.uaa++; + fwrite(&chunkUaa, sizeof(chunkUaa), 1, fp); *fileOffset = *fileOffset + sizeof(chunkUaa); matSize += sizeof(chunkUaa); } - brlyt_4b_chunk chunkUab; - for(setnode = mxmlFindElement(subnode, subnode, "uab", NULL, NULL, MXML_DESCEND); setnode != NULL; setnode = mxmlFindElement(setnode, subnode, "uab", NULL, NULL, MXML_DESCEND)) - { + + brlyt_blend_mode chunkUab; + for(setnode = mxmlFindElement(subnode, subnode, "BlendMode", NULL, NULL, MXML_DESCEND); setnode != NULL; setnode = mxmlFindElement(setnode, subnode, "BlendMode", NULL, NULL, MXML_DESCEND)) + { + char blendmode[5][20]; + int l; + for ( l = 0 ; l < 5 ; l++ ) + memset( blendmode[l] , 0 , 20 ); + strcpy( blendmode[0] , "GX_BM_NONE" ); + strcpy( blendmode[1] , "GX_BM_BLEND" ); + strcpy( blendmode[2] , "GX_BM_LOGIC" ); + strcpy( blendmode[3] , "GX_BM_SUBTRACT" ); + strcpy( blendmode[4] , "GX_MAX_BLENDMODE" ); + + char blendfactor[8][20]; + for ( l = 0 ; l < 8 ; l++ ) + memset( blendfactor[l] , 0 , 20 ); + strcpy( blendfactor[0] , "GX_BL_ZERO" ); + strcpy( blendfactor[1] , "GX_BL_ONE" ); + strcpy( blendfactor[2] , "GX_BL_SRCCLR" ); + strcpy( blendfactor[3] , "GX_BL_INVSRCCLR" ); + strcpy( blendfactor[4] , "GX_BL_SRCALPHA" ); + strcpy( blendfactor[5] , "GX_BL_INVSRCALPHA" ); + strcpy( blendfactor[6] , "GX_BL_DSTALPHA" ); + strcpy( blendfactor[7] , "GX_BL_INVDSTALPHA" ); + + char logicop[16][20]; + for ( l = 0 ; l < 16 ; l++ ) + memset( logicop[l] , 0 , 20 ); + strcpy( logicop[0] , "GX_LO_CLEAR" ); + strcpy( logicop[1] , "GX_LO_AND" ); + strcpy( logicop[2] , "GX_LO_REVAND" ); + strcpy( logicop[3] , "GX_LO_COPY" ); + strcpy( logicop[4] , "GX_LO_INVAND" ); + strcpy( logicop[5] , "GX_LO_NOOP" ); + strcpy( logicop[6] , "GX_LO_XOR" ); + strcpy( logicop[7] , "GX_LO_OR" ); + strcpy( logicop[8] , "GX_LO_NOR" ); + strcpy( logicop[9] , "GX_LO_EQUIV" ); + strcpy( logicop[10] , "GX_LO_INV" ); + strcpy( logicop[11] , "GX_LO_REVOR" ); + strcpy( logicop[12] , "GX_LO_INVCOPY" ); + strcpy( logicop[13] , "GX_LO_INVOR" ); + strcpy( logicop[14] , "GX_LO_NAND" ); + strcpy( logicop[15] , "GX_LO_SET" ); + mxml_node_t *valnode; - int dataNumber = 0; - for (valnode=mxmlFindElement(setnode, setnode, "data", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "data", NULL, NULL, MXML_DESCEND) ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunkUab.unk[dataNumber] = strtoul(tempCoord, NULL, 16); - dataNumber+=1; - } + char tempCoord[256]; + + valnode=mxmlFindElement(setnode, setnode, "type", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUab.type = strtoul( tempCoord , NULL , 16 ); + for ( l = 0 ; l < 5 ; l++ ){ + if ( strncmp( blendmode[l] , tempCoord , 14 ) == 0 ) { + chunkUab.type = l; + break; + } + } + + valnode=mxmlFindElement(setnode, setnode, "src_fact", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUab.src_fact = strtoul( tempCoord , NULL , 16 ); + for ( l = 0 ; l < 8 ; l++ ){ + if ( strncmp( blendfactor[l] , tempCoord , 14 ) == 0 ) { + chunkUab.src_fact = l; + break; + } + } + + valnode=mxmlFindElement(setnode, setnode, "dst_fact", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUab.dst_fact = strtoul( tempCoord , NULL , 16 ); + for ( l = 0 ; l < 8 ; l++ ){ + if ( strncmp( blendfactor[l] , tempCoord , 14 ) == 0 ) { + chunkUab.dst_fact = l; + break; + } + } + + valnode=mxmlFindElement(setnode, setnode, "op", NULL, NULL, MXML_DESCEND); + memset( tempCoord , 0 , 256 ); + get_value( valnode , tempCoord , 256 ); + chunkUab.op = strtoul( tempCoord , NULL , 16 ); + for ( l = 0 ; l < 16 ; l++ ){ + if ( strncmp( logicop[l] , tempCoord , 14 ) == 0 ) { + chunkUab.op = l; + break; + } + } + + flags.flag.uab++; + fwrite(&chunkUab, sizeof(chunkUab), 1, fp); *fileOffset = *fileOffset + sizeof(chunkUab); matSize += sizeof(chunkUab); } + + // write mat1_header with flags + chunk.flags = be32( flags.flags ); + u32 end = ftell(fp); + fseek( fp , tempFileOffset , SEEK_SET ); + fwrite(&chunk, sizeof(chunk), 1, fp); + fseek( fp , end , SEEK_SET ); + if (numberOfEntries < actualNumber) { offsets[numberOfEntries] = be32(matSize + initialOffset); @@ -1437,7 +2693,7 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl memset(chunk.name, 0, 24); strcpy(chunk.name, temp); - mxml_node_t *subnode = mxmlFindElement(node, node, "coords", NULL, NULL, MXML_DESCEND); + mxml_node_t *subnode = mxmlFindElement(node, node, "translate", NULL, NULL, MXML_DESCEND); if (subnode != NULL) { mxml_node_t *valnode; @@ -1446,24 +2702,24 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl { char tempCoord[256]; get_value(valnode, tempCoord, 256); - chunk.x = float_swap_bytes(atof(tempCoord)); + chunk.XTrans = float_swap_bytes(atof(tempCoord)); } valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); if (valnode != NULL) { char tempCoord[256]; get_value(valnode, tempCoord, 256); - chunk.y = float_swap_bytes(atof(tempCoord)); + chunk.YTrans = float_swap_bytes(atof(tempCoord)); } valnode = mxmlFindElement(subnode, subnode, "z", NULL, NULL, MXML_DESCEND); if (valnode != NULL) { char tempCoord[256]; get_value(valnode, tempCoord, 256); - chunk.z = float_swap_bytes(atof(tempCoord)); + chunk.ZTrans = float_swap_bytes(atof(tempCoord)); } } - subnode = mxmlFindElement(node, node, "flip", NULL, NULL, MXML_DESCEND); + subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); if (subnode != NULL) { mxml_node_t *valnode; @@ -1472,17 +2728,24 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl { char tempCoord[256]; get_value(valnode, tempCoord, 256); - chunk.flip_x = float_swap_bytes(atof(tempCoord)); + chunk.XRotate = float_swap_bytes(atof(tempCoord)); } valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); if (valnode != NULL) { char tempCoord[256]; get_value(valnode, tempCoord, 256); - chunk.flip_y = float_swap_bytes(atof(tempCoord)); + chunk.YRotate = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "z", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.ZRotate = float_swap_bytes(atof(tempCoord)); } } - subnode = mxmlFindElement(node, node, "zoom", NULL, NULL, MXML_DESCEND); + subnode = mxmlFindElement(node, node, "scale", NULL, NULL, MXML_DESCEND); if (subnode != NULL) { mxml_node_t *valnode; @@ -1491,14 +2754,14 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl { char tempCoord[256]; get_value(valnode, tempCoord, 256); - chunk.xmag = float_swap_bytes(atof(tempCoord)); + chunk.XScale = float_swap_bytes(atof(tempCoord)); } valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); if (valnode != NULL) { char tempCoord[256]; get_value(valnode, tempCoord, 256); - chunk.ymag = float_swap_bytes(atof(tempCoord)); + chunk.YScale = float_swap_bytes(atof(tempCoord)); } } subnode = mxmlFindElement(node, node, "size", NULL, NULL, MXML_DESCEND); @@ -1521,13 +2784,54 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl } } - subnode = mxmlFindElement(node, node, "flags", NULL, NULL, MXML_DESCEND); + u8 flag1 = 0; + subnode = mxmlFindElement(node, node, "visible", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + flag1 |= strtol(tempCoord, NULL, 16); + } + subnode = mxmlFindElement(node, node, "WidescreenAffected", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + flag1 |= ( strtol(tempCoord, NULL, 16) << 1 ); + } + subnode = mxmlFindElement(node, node, "flag", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + flag1 |= ( strtol(tempCoord, NULL, 16) << 2 ); + } + chunk.flag1 = flag1; + subnode = mxmlFindElement(node, node, "origin", NULL, NULL, MXML_DESCEND); if (subnode != NULL) { + char origins[9][15]; + memset( origins , 0 , 8 * 20 ); + strcpy( origins[0] , "TOP LEFT" ); + strcpy( origins[1] , "TOP CENTER" ); + strcpy( origins[2] , "TOP RIGHT" ); + strcpy( origins[3] , "MIDDLE LEFT" ); + strcpy( origins[4] , "MIDDLE CENTER" ); + strcpy( origins[5] , "MIDDLE RIGHT" ); + strcpy( origins[6] , "BOTTOM LEFT" ); + strcpy( origins[7] , "BOTTOM CENTER" ); + strcpy( origins[8] , "BOTTOM RIGHT" ); + char tempCoord[256]; get_value(subnode, tempCoord, 256); - chunk.flag1 = strtol(tempCoord, NULL, 16); - chunk.flag2 = strtol(&(tempCoord[3]), NULL, 16); + chunk.origin = strtol(tempCoord, NULL, 16); + int i; + for ( i = 0 ; i < 9 ; i++ ) { + if ( strncmp( origins[i] , tempCoord , 15 ) == 0 ) { + chunk.origin = i; + break; + } + } } subnode = mxmlFindElement(node, node, "alpha", NULL, NULL, MXML_DESCEND); if (subnode != NULL) @@ -1535,14 +2839,13 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl char tempCoord[256]; get_value(subnode, tempCoord, 256); chunk.alpha = strtol(tempCoord, NULL, 16); - chunk.alpha2 = strtol(&(tempCoord[3]), NULL, 16); } - subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); + subnode = mxmlFindElement(node, node, "padding", NULL, NULL, MXML_DESCEND); if (subnode != NULL) { char tempCoord[256]; get_value(subnode, tempCoord, 256); - chunk.angle = float_swap_bytes(atof(tempCoord)); + chunk.pad = strtol(tempCoord, NULL, 16); } fwrite(&chunk, sizeof(chunk), 1, fp); *fileOffset = *fileOffset + sizeof(chunk); @@ -1560,7 +2863,7 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl memset(chunk.name, 0, 24 * sizeof(char)); strcpy(chunk.name, temp); - mxml_node_t *subnode = mxmlFindElement(node, node, "coords", NULL, NULL, MXML_DESCEND); + mxml_node_t *subnode = mxmlFindElement(node, node, "translate", NULL, NULL, MXML_DESCEND); if (subnode != NULL) { mxml_node_t *valnode; @@ -1569,24 +2872,24 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl { char tempCoord[256]; get_value(valnode, tempCoord, 256); - chunk.x = float_swap_bytes(atof(tempCoord)); + chunk.XTrans = float_swap_bytes(atof(tempCoord)); } valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); if (valnode != NULL) { char tempCoord[256]; get_value(valnode, tempCoord, 256); - chunk.y = float_swap_bytes(atof(tempCoord)); + chunk.YTrans = float_swap_bytes(atof(tempCoord)); } valnode = mxmlFindElement(subnode, subnode, "z", NULL, NULL, MXML_DESCEND); if (valnode != NULL) { char tempCoord[256]; get_value(valnode, tempCoord, 256); - chunk.z = float_swap_bytes(atof(tempCoord)); + chunk.ZTrans = float_swap_bytes(atof(tempCoord)); } } - subnode = mxmlFindElement(node, node, "flip", NULL, NULL, MXML_DESCEND); + subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); if (subnode != NULL) { mxml_node_t *valnode; @@ -1595,17 +2898,24 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl { char tempCoord[256]; get_value(valnode, tempCoord, 256); - chunk.flip_x = float_swap_bytes(atof(tempCoord)); + chunk.XRotate = float_swap_bytes(atof(tempCoord)); } valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); if (valnode != NULL) { char tempCoord[256]; get_value(valnode, tempCoord, 256); - chunk.flip_y = float_swap_bytes(atof(tempCoord)); + chunk.YRotate = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "z", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.ZRotate = float_swap_bytes(atof(tempCoord)); } } - subnode = mxmlFindElement(node, node, "zoom", NULL, NULL, MXML_DESCEND); + subnode = mxmlFindElement(node, node, "scale", NULL, NULL, MXML_DESCEND); if (subnode != NULL) { mxml_node_t *valnode; @@ -1614,14 +2924,14 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl { char tempCoord[256]; get_value(valnode, tempCoord, 256); - chunk.xmag = float_swap_bytes(atof(tempCoord)); + chunk.XScale = float_swap_bytes(atof(tempCoord)); } valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); if (valnode != NULL) { char tempCoord[256]; get_value(valnode, tempCoord, 256); - chunk.ymag = float_swap_bytes(atof(tempCoord)); + chunk.YScale = float_swap_bytes(atof(tempCoord)); } } subnode = mxmlFindElement(node, node, "size", NULL, NULL, MXML_DESCEND); @@ -1644,13 +2954,54 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl } } - subnode = mxmlFindElement(node, node, "flags", NULL, NULL, MXML_DESCEND); + u8 flag1 = 0; + subnode = mxmlFindElement(node, node, "visible", NULL, NULL, MXML_DESCEND); if (subnode != NULL) { char tempCoord[256]; get_value(subnode, tempCoord, 256); - chunk.flag1 = strtol(tempCoord, NULL, 16); - chunk.flag2 = strtol(&(tempCoord[3]), NULL, 16); + flag1 |= strtol(tempCoord, NULL, 16); + } + subnode = mxmlFindElement(node, node, "WidescreenAffected", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + flag1 |= ( strtol(tempCoord, NULL, 16) << 1 ); + } + subnode = mxmlFindElement(node, node, "flag", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + flag1 |= ( strtol(tempCoord, NULL, 16) << 2 ); + } + chunk.flag1 = flag1; + subnode = mxmlFindElement(node, node, "origin", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char origins[9][15]; + memset( origins , 0 , 8 * 20 ); + strcpy( origins[0] , "TOP LEFT" ); + strcpy( origins[1] , "TOP CENTER" ); + strcpy( origins[2] , "TOP RIGHT" ); + strcpy( origins[3] , "MIDDLE LEFT" ); + strcpy( origins[4] , "MIDDLE CENTER" ); + strcpy( origins[5] , "MIDDLE RIGHT" ); + strcpy( origins[6] , "BOTTOM LEFT" ); + strcpy( origins[7] , "BOTTOM CENTER" ); + strcpy( origins[8] , "BOTTOM RIGHT" ); + + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + chunk.origin = strtol(tempCoord, NULL, 16); + int i; + for ( i = 0 ; i < 9 ; i++ ) { + if ( strncmp( origins[i] , tempCoord , 15 ) == 0 ) { + chunk.origin = i; + break; + } + } } subnode = mxmlFindElement(node, node, "alpha", NULL, NULL, MXML_DESCEND); if (subnode != NULL) @@ -1658,21 +3009,20 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl char tempCoord[256]; get_value(subnode, tempCoord, 256); chunk.alpha = strtol(tempCoord, NULL, 16); - chunk.alpha2 = strtol(&(tempCoord[3]), NULL, 16); } - subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); + subnode = mxmlFindElement(node, node, "padding", NULL, NULL, MXML_DESCEND); if (subnode != NULL) { char tempCoord[256]; get_value(subnode, tempCoord, 256); - chunk.angle = float_swap_bytes(atof(tempCoord)); + chunk.pad = strtol(tempCoord, NULL, 16); } fwrite(&chunk, sizeof(chunk), 1, fp); *fileOffset = *fileOffset + sizeof(chunk); } if ( memcmp(temp, wnd1, sizeof(wnd1)) == 0) { - brlyt_pane_chunk chunk; + brlyt_pane_chunk chunk; char temp[256]; if(mxmlElementGetAttr(node, "name") != NULL) strcpy(temp, mxmlElementGetAttr(node, "name")); @@ -1683,7 +3033,7 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl memset(chunk.name, 0, 24 * sizeof(char)); strcpy(chunk.name, temp); - mxml_node_t *subnode = mxmlFindElement(node, node, "coords", NULL, NULL, MXML_DESCEND); + mxml_node_t *subnode = mxmlFindElement(node, node, "translate", NULL, NULL, MXML_DESCEND); if (subnode != NULL) { mxml_node_t *valnode; @@ -1692,24 +3042,24 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl { char tempCoord[256]; get_value(valnode, tempCoord, 256); - chunk.x = float_swap_bytes(atof(tempCoord)); + chunk.XTrans = float_swap_bytes(atof(tempCoord)); } valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); if (valnode != NULL) { char tempCoord[256]; get_value(valnode, tempCoord, 256); - chunk.y = float_swap_bytes(atof(tempCoord)); + chunk.YTrans = float_swap_bytes(atof(tempCoord)); } valnode = mxmlFindElement(subnode, subnode, "z", NULL, NULL, MXML_DESCEND); if (valnode != NULL) { char tempCoord[256]; get_value(valnode, tempCoord, 256); - chunk.z = float_swap_bytes(atof(tempCoord)); + chunk.ZTrans = float_swap_bytes(atof(tempCoord)); } } - subnode = mxmlFindElement(node, node, "flip", NULL, NULL, MXML_DESCEND); + subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); if (subnode != NULL) { mxml_node_t *valnode; @@ -1718,17 +3068,24 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl { char tempCoord[256]; get_value(valnode, tempCoord, 256); - chunk.flip_x = float_swap_bytes(atof(tempCoord)); + chunk.XRotate = float_swap_bytes(atof(tempCoord)); } valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); if (valnode != NULL) { char tempCoord[256]; get_value(valnode, tempCoord, 256); - chunk.flip_y = float_swap_bytes(atof(tempCoord)); + chunk.YRotate = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "z", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.ZRotate = float_swap_bytes(atof(tempCoord)); } } - subnode = mxmlFindElement(node, node, "zoom", NULL, NULL, MXML_DESCEND); + subnode = mxmlFindElement(node, node, "scale", NULL, NULL, MXML_DESCEND); if (subnode != NULL) { mxml_node_t *valnode; @@ -1737,14 +3094,14 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl { char tempCoord[256]; get_value(valnode, tempCoord, 256); - chunk.xmag = float_swap_bytes(atof(tempCoord)); + chunk.XScale = float_swap_bytes(atof(tempCoord)); } valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); if (valnode != NULL) { char tempCoord[256]; get_value(valnode, tempCoord, 256); - chunk.ymag = float_swap_bytes(atof(tempCoord)); + chunk.YScale = float_swap_bytes(atof(tempCoord)); } } subnode = mxmlFindElement(node, node, "size", NULL, NULL, MXML_DESCEND); @@ -1767,13 +3124,54 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl } } - subnode = mxmlFindElement(node, node, "flags", NULL, NULL, MXML_DESCEND); + u8 flag1 = 0; + subnode = mxmlFindElement(node, node, "visible", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + flag1 |= strtol(tempCoord, NULL, 16); + } + subnode = mxmlFindElement(node, node, "WidescreenAffected", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + flag1 |= ( strtol(tempCoord, NULL, 16) << 1 ); + } + subnode = mxmlFindElement(node, node, "flag", NULL, NULL, MXML_DESCEND); if (subnode != NULL) { char tempCoord[256]; get_value(subnode, tempCoord, 256); - chunk.flag1 = strtol(tempCoord, NULL, 16); - chunk.flag2 = strtol(&(tempCoord[3]), NULL, 16); + flag1 |= ( strtol(tempCoord, NULL, 16) << 2 ); + } + chunk.flag1 = flag1; + subnode = mxmlFindElement(node, node, "origin", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char origins[9][15]; + memset( origins , 0 , 8 * 20 ); + strcpy( origins[0] , "TOP LEFT" ); + strcpy( origins[1] , "TOP CENTER" ); + strcpy( origins[2] , "TOP RIGHT" ); + strcpy( origins[3] , "MIDDLE LEFT" ); + strcpy( origins[4] , "MIDDLE CENTER" ); + strcpy( origins[5] , "MIDDLE RIGHT" ); + strcpy( origins[6] , "BOTTOM LEFT" ); + strcpy( origins[7] , "BOTTOM CENTER" ); + strcpy( origins[8] , "BOTTOM RIGHT" ); + + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + chunk.origin = strtol(tempCoord, NULL, 16); + int i; + for ( i = 0 ; i < 9 ; i++ ) { + if ( strncmp( origins[i] , tempCoord , 15 ) == 0 ) { + chunk.origin = i; + break; + } + } } subnode = mxmlFindElement(node, node, "alpha", NULL, NULL, MXML_DESCEND); if (subnode != NULL) @@ -1781,14 +3179,13 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl char tempCoord[256]; get_value(subnode, tempCoord, 256); chunk.alpha = strtol(tempCoord, NULL, 16); - chunk.alpha2 = strtol(&(tempCoord[3]), NULL, 16); } - subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); + subnode = mxmlFindElement(node, node, "padding", NULL, NULL, MXML_DESCEND); if (subnode != NULL) { char tempCoord[256]; get_value(subnode, tempCoord, 256); - chunk.angle = float_swap_bytes(atof(tempCoord)); + chunk.pad = strtol(tempCoord, NULL, 16); } fwrite(&chunk, sizeof(chunk), 1, fp); *fileOffset = *fileOffset + sizeof(chunk); @@ -1800,20 +3197,20 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl { i = 0; mxml_node_t *subsubnode; - for(subsubnode = mxmlFindElement(subnode, subnode, "unk1", NULL, NULL, MXML_DESCEND); subsubnode != NULL; subsubnode = mxmlFindElement(subsubnode, subnode, "unk1", NULL, NULL, MXML_DESCEND)) + for(subsubnode = mxmlFindElement(subnode, subnode, "coordinate", NULL, NULL, MXML_DESCEND); subsubnode != NULL; subsubnode = mxmlFindElement(subsubnode, subnode, "coordinate", NULL, NULL, MXML_DESCEND)) { char tempCoord[256]; get_value(subsubnode, tempCoord, 256); - wndy.unk1[i] = float_swap_bytes(atof(tempCoord)); + wndy.coords[i] = float_swap_bytes(atof(tempCoord)); i++; } - subsubnode = mxmlFindElement(subnode, subnode, "count", NULL, NULL, MXML_DESCEND); + subsubnode = mxmlFindElement(subnode, subnode, "FrameCount", NULL, NULL, MXML_DESCEND); if(subsubnode != NULL) { char tempCoord[256]; get_value(subsubnode, tempCoord, 256); - wndy.count = (u8)(strtoul(tempCoord, NULL, 16)); + wndy.frame_count = (u8)(strtoul(tempCoord, NULL, 16)); } wndy.padding[0] = 0x0; wndy.padding[1] = 0x0; @@ -1845,42 +3242,40 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl { i=0; mxml_node_t *subsubnode; - for(subsubnode = mxmlFindElement(subnode, subnode, "unk1", NULL, NULL, MXML_DESCEND); subsubnode != NULL; subsubnode = mxmlFindElement(subsubnode, subnode, "unk1", NULL, NULL, MXML_DESCEND)) + for(subsubnode = mxmlFindElement(subnode, subnode, "color", NULL, NULL, MXML_DESCEND); subsubnode != NULL; subsubnode = mxmlFindElement(subsubnode, subnode, "color", NULL, NULL, MXML_DESCEND)) { char tempCoord[256]; get_value(subsubnode, tempCoord, 256); - wndy1.unk1[i] = be32(strtoul(tempCoord, NULL, 16)); + wndy1.colors[i] = be32(strtoul(tempCoord, NULL, 16)); i++; } - fwrite(&wndy1, sizeof(brlyt_wnd1), 1, fp); - *fileOffset = *fileOffset + sizeof(brlyt_wnd1); - } - - brlyt_wnd2 wndy2; - subnode = mxmlFindElement(node, node, "wnd2", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *subsubnode; - subsubnode = mxmlFindElement(subnode, subnode, "unk1", NULL, NULL, MXML_DESCEND); + subsubnode = mxmlFindElement(subnode, subnode, "material", NULL, NULL, MXML_DESCEND); if (subnode != NULL) { char tempCoord[256]; get_value(subsubnode, tempCoord, 256); - wndy2.unk1 = short_swap_bytes(strtoul(tempCoord, NULL, 16)); + wndy1.material = short_swap_bytes(strtoul(tempCoord, NULL, 16)); } - subsubnode = mxmlFindElement(subnode, subnode, "unk2", NULL, NULL, MXML_DESCEND); + subsubnode = mxmlFindElement(subnode, subnode, "CoordinateCount", NULL, NULL, MXML_DESCEND); if (subsubnode != NULL) { char tempCoord[256]; get_value(subsubnode, tempCoord, 256); - wndy2.unk2 = short_swap_bytes(strtoul(tempCoord, NULL, 16)); + wndy1.coordinate_count = short_swap_bytes(strtoul(tempCoord, NULL, 16)); } - fwrite(&wndy2, sizeof(brlyt_wnd2), 1, fp); - *fileOffset = *fileOffset + sizeof(brlyt_wnd2); + subsubnode = mxmlFindElement(subnode, subnode, "padding", NULL, NULL, MXML_DESCEND); + if (subsubnode != NULL) + { + char tempCoord[256]; + get_value(subsubnode, tempCoord, 256); + wndy1.padding = short_swap_bytes(strtoul(tempCoord, NULL, 16)); + } + fwrite(&wndy1, sizeof(brlyt_wnd1), 1, fp); + *fileOffset = *fileOffset + sizeof(brlyt_wnd1); } brlyt_wnd3 wndy3; - subnode = mxmlFindElement(node, node, "wnd3", NULL, NULL, MXML_DESCEND); + subnode = mxmlFindElement(node, node, "Coords", NULL, NULL, MXML_DESCEND); if (subnode != NULL) { i=0; @@ -1922,9 +3317,23 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl { char tempCoord[256]; get_value(subsubnode, tempCoord, 256); - wndy4mat.unk1 = be32(strtoul(tempCoord, NULL, 16)); + wndy4mat.material = be16(strtoul(tempCoord, NULL, 16)); i++; } + subsubnode = mxmlFindElement(subnode, subnode, "index", NULL, NULL, MXML_DESCEND); + if (subsubnode != NULL) + { + char tempCoord[256]; + get_value(subsubnode, tempCoord, 256); + wndy4mat.index = strtoul(tempCoord, NULL, 16); + } + subsubnode = mxmlFindElement(subnode, subnode, "padding", NULL, NULL, MXML_DESCEND); + if (subsubnode != NULL) + { + char tempCoord[256]; + get_value(subsubnode, tempCoord, 256); + wndy4mat.padding = strtoul(tempCoord, NULL, 16); + } fwrite(&wndy4mat, sizeof(brlyt_wnd4_mat), 1, fp); *fileOffset = *fileOffset + sizeof(brlyt_wnd4_mat); } @@ -1942,9 +3351,9 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl } memset(chunk.name, 0, 24 * sizeof(char)); strcpy(chunk.name, temp); - chunk2.mat_off = short_swap_bytes(findMatOffset(temp)); + chunk2.mat_num = short_swap_bytes(findMatOffset(temp)); - mxml_node_t *subnode = mxmlFindElement(node, node, "coords", NULL, NULL, MXML_DESCEND); + mxml_node_t *subnode = mxmlFindElement(node, node, "translate", NULL, NULL, MXML_DESCEND); if (subnode != NULL) { mxml_node_t *valnode; @@ -1953,24 +3362,24 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl { char tempCoord[256]; get_value(valnode, tempCoord, 256); - chunk.x = float_swap_bytes(atof(tempCoord)); + chunk.XTrans = float_swap_bytes(atof(tempCoord)); } valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); if (valnode != NULL) { char tempCoord[256]; get_value(valnode, tempCoord, 256); - chunk.y = float_swap_bytes(atof(tempCoord)); + chunk.YTrans = float_swap_bytes(atof(tempCoord)); } valnode = mxmlFindElement(subnode, subnode, "z", NULL, NULL, MXML_DESCEND); if (valnode != NULL) { char tempCoord[256]; get_value(valnode, tempCoord, 256); - chunk.z = float_swap_bytes(atof(tempCoord)); + chunk.ZTrans = float_swap_bytes(atof(tempCoord)); } } - subnode = mxmlFindElement(node, node, "flip", NULL, NULL, MXML_DESCEND); + subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); if (subnode != NULL) { mxml_node_t *valnode; @@ -1979,17 +3388,24 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl { char tempCoord[256]; get_value(valnode, tempCoord, 256); - chunk.flip_x = float_swap_bytes(atof(tempCoord)); + chunk.XRotate = float_swap_bytes(atof(tempCoord)); } valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); if (valnode != NULL) { char tempCoord[256]; get_value(valnode, tempCoord, 256); - chunk.flip_y = float_swap_bytes(atof(tempCoord)); + chunk.YRotate = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "z", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.ZRotate = float_swap_bytes(atof(tempCoord)); } } - subnode = mxmlFindElement(node, node, "zoom", NULL, NULL, MXML_DESCEND); + subnode = mxmlFindElement(node, node, "scale", NULL, NULL, MXML_DESCEND); if (subnode != NULL) { mxml_node_t *valnode; @@ -1998,14 +3414,14 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl { char tempCoord[256]; get_value(valnode, tempCoord, 256); - chunk.xmag = float_swap_bytes(atof(tempCoord)); + chunk.XScale = float_swap_bytes(atof(tempCoord)); } valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); if (valnode != NULL) { char tempCoord[256]; get_value(valnode, tempCoord, 256); - chunk.ymag = float_swap_bytes(atof(tempCoord)); + chunk.YScale = float_swap_bytes(atof(tempCoord)); } } subnode = mxmlFindElement(node, node, "size", NULL, NULL, MXML_DESCEND); @@ -2028,13 +3444,54 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl } } - subnode = mxmlFindElement(node, node, "flags", NULL, NULL, MXML_DESCEND); + u8 flag1 = 0; + subnode = mxmlFindElement(node, node, "visible", NULL, NULL, MXML_DESCEND); if (subnode != NULL) { char tempCoord[256]; get_value(subnode, tempCoord, 256); - chunk.flag1 = strtol(tempCoord, NULL, 16); - chunk.flag2 = strtol(&(tempCoord[3]), NULL, 16); + flag1 |= strtol(tempCoord, NULL, 16); + } + subnode = mxmlFindElement(node, node, "WidescreenAffected", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + flag1 |= ( strtol(tempCoord, NULL, 16) << 1 ); + } + subnode = mxmlFindElement(node, node, "flag", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + flag1 |= ( strtol(tempCoord, NULL, 16) << 2 ); + } + chunk.flag1 = flag1; + subnode = mxmlFindElement(node, node, "origin", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char origins[9][15]; + memset( origins , 0 , 8 * 20 ); + strcpy( origins[0] , "TOP LEFT" ); + strcpy( origins[1] , "TOP CENTER" ); + strcpy( origins[2] , "TOP RIGHT" ); + strcpy( origins[3] , "MIDDLE LEFT" ); + strcpy( origins[4] , "MIDDLE CENTER" ); + strcpy( origins[5] , "MIDDLE RIGHT" ); + strcpy( origins[6] , "BOTTOM LEFT" ); + strcpy( origins[7] , "BOTTOM CENTER" ); + strcpy( origins[8] , "BOTTOM RIGHT" ); + + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + chunk.origin = strtol(tempCoord, NULL, 16); + int i; + for ( i = 0 ; i < 9 ; i++ ) { + if ( strncmp( origins[i] , tempCoord , 15 ) == 0 ) { + chunk.origin = i; + break; + } + } } subnode = mxmlFindElement(node, node, "alpha", NULL, NULL, MXML_DESCEND); if (subnode != NULL) @@ -2042,14 +3499,13 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl char tempCoord[256]; get_value(subnode, tempCoord, 256); chunk.alpha = strtol(tempCoord, NULL, 16); - chunk.alpha2 = strtol(&(tempCoord[3]), NULL, 16); } - subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); + subnode = mxmlFindElement(node, node, "padding", NULL, NULL, MXML_DESCEND); if (subnode != NULL) { char tempCoord[256]; get_value(subnode, tempCoord, 256); - chunk.angle = float_swap_bytes(atof(tempCoord)); + chunk.pad = strtol(tempCoord, NULL, 16); } subnode = mxmlFindElement(node, node, "font", NULL, NULL, MXML_DESCEND); @@ -2097,9 +3553,28 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl valnode = mxmlFindElement(subnode, subnode, "alignment", NULL, NULL, MXML_DESCEND); if (valnode != NULL) { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk2.alignment = strtol(tempCoord, NULL, 16); + char alignments[9][15]; + memset( alignments , 0 , 8 * 20 ); + strcpy( alignments[0] , "TOP LEFT" ); + strcpy( alignments[1] , "TOP CENTER" ); + strcpy( alignments[2] , "TOP RIGHT" ); + strcpy( alignments[3] , "MIDDLE LEFT" ); + strcpy( alignments[4] , "MIDDLE CENTER" ); + strcpy( alignments[5] , "MIDDLE RIGHT" ); + strcpy( alignments[6] , "BOTTOM LEFT" ); + strcpy( alignments[7] , "BOTTOM CENTER" ); + strcpy( alignments[8] , "BOTTOM RIGHT" ); + + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + chunk2.alignment = strtol(tempCoord, NULL, 16); + int i; + for ( i = 0 ; i < 9 ; i++ ) { + if ( strncmp( alignments[i] , tempCoord , 15 ) == 0 ) { + chunk2.alignment = i; + break; + } + } } } @@ -2113,23 +3588,29 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl chunk2.len2 = strtoul(tempCoord+5, NULL, 16); chunk2.len2 = short_swap_bytes(chunk2.len2); } - subnode = mxmlFindElement(node, node, "color", NULL, NULL, MXML_DESCEND); + subnode = mxmlFindElement(node, node, "color1", NULL, NULL, MXML_DESCEND); if (subnode != NULL) { char tempCoord[256]; get_value(subnode, tempCoord, 256); chunk2.color1 = be32(strtoul(tempCoord, NULL, 16)); - chunk2.color2 = be32(strtoul(tempCoord+9, NULL, 16)); + } + subnode = mxmlFindElement(node, node, "color2", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + chunk2.color2 = be32(strtoul(tempCoord, NULL, 16)); } u16 textyLength = short_swap_bytes(chunk2.len2); if ((textyLength % 4) != 0) textyLength += (4 - (textyLength % 4)); - unsigned char texty[textyLength + 1]; - unsigned char tempy[textyLength*2]; + u8 texty[textyLength + 1]; + u8 tempy[textyLength*2]; subnode = mxmlFindElement(node, node, "text", NULL, NULL, MXML_DESCEND); if (subnode != NULL) { - unsigned char tempCoord[8184]; + u8 tempCoord[8184]; get_value(subnode, tempCoord, 8184); memcpy(tempy, tempCoord, short_swap_bytes(chunk2.len2)*2); u32 w; for (w=0;w words that are an offset to a struct of (short, bytes) short is a mat offset - - typedef struct { - char a; + char drawnFromMiddle;// related to whether is drawn from middle // 1 = TRUE 2 = FALSE char pad[3]; float width; float height; @@ -159,7 +137,7 @@ typedef struct char name[20]; s16 forecolor[4]; s16 backcolor[4]; - s16 unk_color_2[4]; + s16 colorReg3[4]; u32 tev_kcolor[4]; u32 flags; } brlyt_material_chunk; @@ -177,36 +155,164 @@ typedef struct u8 wrap_t; } brlyt_texref_chunk; -typedef struct // SRT Array +typedef struct +{ + float XTrans; + float YTrans; + float Rotate; + float XScale; + float YScale; +} brlyt_tex_srt; + +typedef struct +{ + char tgen_type; + char tgen_src; + char mtxsrc; + char padding; +} brlyt_tex_coordgen; + +typedef struct +{ + char color_matsrc; + char alpha_matsrc; + char padding1; + char padding2; +} brlyt_tex_chanctrl; + +typedef struct +{ + u8 red; + u8 green; + u8 blue; + u8 alpha; +} brlyt_tex_matcol; + +typedef struct { - float x1; - float y1; - float angle; - float x2; - float y2; -} brlyt_tex_coords; + unsigned red : 2; + unsigned green : 2; + unsigned blue : 2; + unsigned alpha : 2; +} brlyt_tev_swapmode; typedef struct { - u8 unk[4]; -} brlyt_4b_chunk; + unsigned Texture : 4; + unsigned TexSRT : 4; + unsigned TexCoord : 4; + unsigned ua6 : 1; + unsigned ua7 : 2; + unsigned ua8 : 3; + unsigned ua9 : 5; + unsigned uaa : 1; + unsigned uab : 1; + unsigned ua4 : 1; + unsigned padding1 : 1; + unsigned ua5 : 1; + unsigned padding2 : 4; +} mat_flags; + +// 0000 0000 0000 0000 0000 0000 0000 0000 +// xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx +// ---- 5-4b a999 9988 8776 3333 2222 1111 typedef struct { - u32 a; // floating point - u32 b; // floating point - float c; - float d; - float e; -} brlyt_ua7_chunk; + union + { + mat_flags flag; + u32 flags; + }; +} mat1_flags; typedef struct { - u8 unk[16]; -} brlyt_10b_chunk; + u8 one; + u8 two; + u8 three; + u8 four; +} brlyt_tev_swapmodetable; -void swapBytes(unsigned char* char1, unsigned char* char2); -int bitExtraction(unsigned int num, unsigned int start, unsigned int end); +typedef struct +{ + float XTrans; + float YTrans; + float Rotate; + float XScale; + float YScale; +} brlyt_indtex_srt; + +typedef struct +{ + u8 tex_coord; + u8 tex_map; + u8 scale_s; + u8 scale_t; +} brlyt_indtex_order; + +typedef struct +{ + unsigned texcoord : 8; // GX_SetTevOrder( i , this , * , * ); + unsigned color : 8; // GX_SetTevOrder( i , * , * , this ); + unsigned texmapbot : 8; // GX_SetTevOrder( i , * , this | *2 , * ); *1 + unsigned texmaptop : 1; // GX_SetTevOrder( i , * , *1 | this , * ); *2 + unsigned ras_sel : 2; // GX_SetTevSwapMode( i , this , * ); + unsigned tex_sel : 2; // GX_SetTevSwapMode( i , * , this ); + unsigned empty1 : 3;//pad + unsigned aC : 4; // GX_SetTevColorIn( i , this , * , * , * ); + unsigned bC : 4; // GX_SetTevColorIn( i , * , this , * , * ); + unsigned cC : 4; // GX_SetTevColorIn( i , * , * , this , * ); + unsigned dC : 4; // GX_SetTevColorIn( i , * , * , * , this ); + unsigned tevscaleC : 2; // GX_SetTevColorOp( i , * , * , this , * , * ); + unsigned tevbiasC : 2; // GX_SetTevColorOp( i , * , this , * , * , * ); + unsigned tevopC : 4; // GX_SetTevColorOp( i , this , * , * , * , * ); + unsigned tevregidC : 1; // GX_SetTevColorOp( i , * , * , * , * , this ); + unsigned clampC : 2; // GX_SetTecColorOp( i , * , * , * , this , * ); + unsigned selC : 5; // GX_SetTevKColorSel( i , this ); + unsigned aA : 4; // GX_SetTevAlphaIn( i , this , * , * , * ); + unsigned bA : 4; // GX_SetTevAlphaIn( i , * , this , * , * ); + unsigned cA : 4; // GX_SetTevAlphaIn( i , * , * , this , * ); + unsigned dA : 4; // GX_SetTevAlphaIn( i , * , * , * , this ); + unsigned tevscaleA : 2; // GX_SetTevAlphaOp( i , * , * , this , * , * ); + unsigned tevbiasA : 2; // GX_SetTevAlphaOp( i , * , this , * , * , * ); + unsigned tevopA : 4; // GX_SetTevAlphaOp( i , this , * , * , * , * ); + unsigned tevregidA : 1; // GX_SetTevAlphaOp( i , * , * , * , * , this ); + unsigned clampA : 2; // GX_SetTecAlphaOp( i , * , * , * , this , * ); + unsigned selA : 5; // GX_SetTevKAlphaSel( i , this ); + unsigned indtexid : 8; // GX_SetTevIndirect( i , this , * , * , * , * , * , * , * , * ); + unsigned bias : 3; // GX_SetTevIndirect( i , * , * , this , * , * , * , * , * , * ); + unsigned mtxid : 4; // GX_SetTevIndirect( i , * , * , * , this , * , * , * , * , * ); + unsigned empty2 : 1;//pad + unsigned wrap_s : 3; // GX_SetTevIndirect( i , * , * , * , * , this , * , * , * , * ); + unsigned wrap_t : 3; // GX_SetTevIndirect( i , * , * , * , * , * , this , * , * , * ); + unsigned empty3 : 2;//pad + unsigned format : 2; // GX_SetTevIndirect( i , * , this , * , * , * , * , * , * , * ); + unsigned addprev : 1; // GX_SetTevIndirect( i , * , * , * , * , * , * , this , * , * ); + unsigned utclod : 1; // GX_SetTevIndirect( i , * , * , * , * , * , * , * , this , * ); + unsigned aIND : 2; // GX_SetTevIndirect( i , * , * , * , * , * , * , * , * , this ); + unsigned empty4 : 2;//pad +} TevStages; + +typedef struct +{ + unsigned comp0 : 4; + unsigned comp1 : 4; // had to switch + unsigned aop : 8; + unsigned ref0 : 8; + unsigned ref1 : 8; +} brlyt_alpha_compare; + +typedef struct +{ + u8 type; + u8 src_fact; + u8 dst_fact; + u8 op; +} brlyt_blend_mode; + +u8 swapBits( u8 char1 ); +u32 bitExtraction(u32 num, u32 start, u32 end); void parse_brlyt(char *filename, char *filenameout); void make_brlyt(char* infile, char* outfile); diff --git a/general.h b/general.h index dbf8831..9334b14 100644 --- a/general.h +++ b/general.h @@ -6,8 +6,8 @@ \******************************************************************************/ #define BENZIN_VERSION_MAJOR 1 -#define BENZIN_VERSION_MINOR 2 -#define BENZIN_VERSION_BUILD 1 +#define BENZIN_VERSION_MINOR 9 +#define BENZIN_VERSION_BUILD 0 #define BENZIN_VERSION_OTHER "BETA" #define INFORMATION_TEXT \ -- cgit v1.3.1