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 From c6a4ee6a501d46ff391fefccdc3e30a9b9cdff64 Mon Sep 17 00:00:00 2001 From: megazig Date: Sun, 20 Sep 2009 00:58:22 -0500 Subject: forgot to add xml.c --- xml.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xml.c b/xml.c index cd8d8be..ea5efcb 100644 --- a/xml.c +++ b/xml.c @@ -88,7 +88,7 @@ const char *whitespace_cb(mxml_node_t *node, int where) } if (where == 3 || where == 1){ return ""; - }else if(((node->prev && where == 0) || node->parent) && !(where == 2 && strncmp(name, "ua", 2) && strcmp(name, "flip") && strcmp(name, "zoom") && strcmp(name, "coords") && strcmp(name, "entries") && strcmp(name, "xmlyt") && strcmp(name, "xmlan") && strcmp(name, "entries") && strcmp(name, "triplet") && strcmp(name, "pair") && strcmp(name, "entry") && strcmp(name, "pane") && (strcmp(name, "tag") && strcmp(name, "size") && strcmp(name, "material") && strcmp(name, "colors") && strcmp(name, "subs") && strcmp(name, "font") && strcmp(name, "wnd4") && strcmp(name, "wnd4mat") && strcmp(name, "set") && strcmp(name, "coordinates"))) ){ + }else if(((node->prev && where == 0) || node->parent) && !(where == 2 && strncmp(name, "ua", 2) && strcmp(name, "rotate") && strcmp(name, "scale") && strcmp(name, "translate") && strcmp(name, "entries") && strcmp(name, "xmlyt") && strcmp(name, "xmlan") && strcmp(name, "entries") && strcmp(name, "triplet") && strcmp(name, "pair") && strcmp(name, "entry") && strcmp(name, "pane") && (strcmp(name, "tag") && strcmp(name, "size") && strcmp(name, "material") && strcmp(name, "colors") && strcmp(name, "subs") && strcmp(name, "font") && strcmp(name, "wnd4") && strcmp(name, "wnd4mat") && strcmp(name, "set") && strcmp(name, "coordinates") && strcmp(name, "TevStage") && strcmp(name, "texture") && strcmp(name, "TextureSRT") && strcmp(name, "CoordGen") && strcmp(name, "ChanControl") && strcmp(name, "MaterialColor") && strcmp(name, "TevSwapModeTable") && strcmp(name, "IndTextureSRT") && strcmp(name, "IndTextureOrder") && strcmp(name, "AlphaCompare") && strcmp(name, "BlendMode") )) ){ sprintf(xmlbuff, "\n%*s", (depth-1)*4, ""); }else{ return ""; -- cgit v1.3.1 From 955dca65b0b526b1e79adb23cff6617d2436014c Mon Sep 17 00:00:00 2001 From: megazig Date: Sun, 20 Sep 2009 08:05:18 -0500 Subject: fixed whitespace to tabs --- general.h | 2 +- xml.c | 151 ++++++++++++++++++++++++++++++++------------------------------ 2 files changed, 79 insertions(+), 74 deletions(-) diff --git a/general.h b/general.h index 9334b14..cab4f28 100644 --- a/general.h +++ b/general.h @@ -7,7 +7,7 @@ #define BENZIN_VERSION_MAJOR 1 #define BENZIN_VERSION_MINOR 9 -#define BENZIN_VERSION_BUILD 0 +#define BENZIN_VERSION_BUILD 1 #define BENZIN_VERSION_OTHER "BETA" #define INFORMATION_TEXT \ diff --git a/xml.c b/xml.c index ea5efcb..80709df 100644 --- a/xml.c +++ b/xml.c @@ -13,86 +13,91 @@ char xmlbuff[4096]; -char * /* O - Buffer */ -get_value(mxml_node_t *node, /* I - Node to get */ - void *buffer, /* I - Buffer */ - int buflen) /* I - Size of buffer */ +char * /* O - Buffer */ +get_value(mxml_node_t *node, /* I - Node to get */ + void *buffer, /* I - Buffer */ + int buflen) /* I - Size of buffer */ { - char *ptr, /* Pointer into buffer */ - *end; /* End of buffer */ - int len; /* Length of node */ - mxml_node_t *current; /* Current node */ + char *ptr, /* Pointer into buffer */ + *end; /* End of buffer */ + int len; /* Length of node */ + mxml_node_t *current; /* Current node */ - ptr = (char*)buffer; - end = (char*)buffer + buflen - 1; - char tempbuf[4092]; - current = node->child; - for (current = node->child; current && ptr < end; current = current->next) - { - if (current->type == MXML_TEXT) - { - if (current->value.text.whitespace) - *ptr++ = ' '; - - len = (int)strlen(current->value.text.string); - if (len > (int)(end - ptr)) - len = (int)(end - ptr); - - memcpy(ptr, current->value.text.string, len); - ptr += len; - } - else if (current->type == MXML_OPAQUE) - { - len = (int)strlen(current->value.opaque); - if (len > (int)(end - ptr)) - len = (int)(end - ptr); - - memcpy(ptr, current->value.opaque, len); - ptr += len; - } - else if (current->type == MXML_INTEGER) - { - sprintf(tempbuf, "%d", current->value.integer); - len = (int)strlen(tempbuf); - if (len > (int)(end - ptr)) - len = (int)(end - ptr); - - memcpy(ptr, tempbuf, len); - ptr += len; - } - else if (current->type == MXML_REAL) - { - sprintf(tempbuf, "%f", current->value.real); - len = (int)strlen(tempbuf); - if (len > (int)(end - ptr)) - len = (int)(end - ptr); + ptr = (char*)buffer; + end = (char*)buffer + buflen - 1; + char tempbuf[4092]; + current = node->child; + for (current = node->child; current && ptr < end; current = current->next) + { + if (current->type == MXML_TEXT) + { + if (current->value.text.whitespace) + *ptr++ = ' '; + + len = (int)strlen(current->value.text.string); + if (len > (int)(end - ptr)) + len = (int)(end - ptr); + + memcpy(ptr, current->value.text.string, len); + ptr += len; + } + else if (current->type == MXML_OPAQUE) + { + len = (int)strlen(current->value.opaque); + if (len > (int)(end - ptr)) + len = (int)(end - ptr); + + memcpy(ptr, current->value.opaque, len); + ptr += len; + } + else if (current->type == MXML_INTEGER) + { + sprintf(tempbuf, "%d", current->value.integer); + len = (int)strlen(tempbuf); + if (len > (int)(end - ptr)) + len = (int)(end - ptr); + + memcpy(ptr, tempbuf, len); + ptr += len; + } + else if (current->type == MXML_REAL) + { + sprintf(tempbuf, "%f", current->value.real); + len = (int)strlen(tempbuf); + if (len > (int)(end - ptr)) + len = (int)(end - ptr); - memcpy(ptr, tempbuf, len); - ptr += len; - } - } - *ptr = 0; - return buffer; + memcpy(ptr, tempbuf, len); + ptr += len; + } + } + *ptr = 0; + return buffer; } const char *whitespace_cb(mxml_node_t *node, int where) { - /* code by Matt_P */ - const char *name = node->value.element.name; - mxml_node_t * temp = node; - int depth = 0; - while(temp){ - depth++; - temp = temp->parent; - } - if (where == 3 || where == 1){ - return ""; - }else if(((node->prev && where == 0) || node->parent) && !(where == 2 && strncmp(name, "ua", 2) && strcmp(name, "rotate") && strcmp(name, "scale") && strcmp(name, "translate") && strcmp(name, "entries") && strcmp(name, "xmlyt") && strcmp(name, "xmlan") && strcmp(name, "entries") && strcmp(name, "triplet") && strcmp(name, "pair") && strcmp(name, "entry") && strcmp(name, "pane") && (strcmp(name, "tag") && strcmp(name, "size") && strcmp(name, "material") && strcmp(name, "colors") && strcmp(name, "subs") && strcmp(name, "font") && strcmp(name, "wnd4") && strcmp(name, "wnd4mat") && strcmp(name, "set") && strcmp(name, "coordinates") && strcmp(name, "TevStage") && strcmp(name, "texture") && strcmp(name, "TextureSRT") && strcmp(name, "CoordGen") && strcmp(name, "ChanControl") && strcmp(name, "MaterialColor") && strcmp(name, "TevSwapModeTable") && strcmp(name, "IndTextureSRT") && strcmp(name, "IndTextureOrder") && strcmp(name, "AlphaCompare") && strcmp(name, "BlendMode") )) ){ - sprintf(xmlbuff, "\n%*s", (depth-1)*4, ""); - }else{ - return ""; - } - return xmlbuff; + /* code by Matt_P */ + const char *name = node->value.element.name; + mxml_node_t * temp = node; + char tab_buffer[25]; + memset( tab_buffer , 0 , 15 ); + int depth = 0; + while(temp){ + depth++; + tab_buffer[depth - 1] = '\t'; + temp = temp->parent; + } + if (where == 3 || where == 1){ + return ""; + }else if(((node->prev && where == 0) || node->parent) && !(where == 2 && strncmp(name, "ua", 2) && strcmp(name, "rotate") && strcmp(name, "scale") && strcmp(name, "translate") && strcmp(name, "entries") && strcmp(name, "xmlyt") && strcmp(name, "xmlan") && strcmp(name, "entries") && strcmp(name, "triplet") && strcmp(name, "pair") && strcmp(name, "entry") && strcmp(name, "pane") && (strcmp(name, "tag") && strcmp(name, "size") && strcmp(name, "material") && strcmp(name, "colors") && strcmp(name, "subs") && strcmp(name, "font") && strcmp(name, "wnd4") && strcmp(name, "wnd4mat") && strcmp(name, "set") && strcmp(name, "coordinates") && strcmp(name, "TevStage") && strcmp(name, "texture") && strcmp(name, "TextureSRT") && strcmp(name, "CoordGen") && strcmp(name, "ChanControl") && strcmp(name, "MaterialColor") && strcmp(name, "TevSwapModeTable") && strcmp(name, "IndTextureSRT") && strcmp(name, "IndTextureOrder") && strcmp(name, "AlphaCompare") && strcmp(name, "BlendMode") )) ){ + //sprintf(xmlbuff, "\n%*s", (depth-1)*4 , ""); + //sprintf(xmlbuff, "\n%*s", (depth)*4 , "\t"); + sprintf( xmlbuff , "\n%s" , tab_buffer ); + }else{ + return ""; + } + return xmlbuff; } -- cgit v1.3.1 From ac684b6c6b64d093b65069d2692c38b42fbdc0c1 Mon Sep 17 00:00:00 2001 From: megazig Date: Sun, 20 Sep 2009 14:16:12 -0500 Subject: added lots of cleanup and changed vtx to color pieces and cleaned up main --- benzin.sh | 11 + brlan.c | 337 ++--- brlan.h | 3 +- brlyt.c | 4775 +++++++++++++++++++++++++++++++------------------------------ general.h | 2 +- main.c | 205 ++- types.h | 9 + 7 files changed, 2691 insertions(+), 2651 deletions(-) create mode 100644 benzin.sh diff --git a/benzin.sh b/benzin.sh new file mode 100644 index 0000000..ba61649 --- /dev/null +++ b/benzin.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +sudo apt-get install git-core libmxml-dev build-essential +git clone git://github.com/SquidMan/benzin.git + +cd benzin + +make clean +make + +./benzin diff --git a/brlan.c b/brlan.c index 4ab2e8b..d2b37d8 100644 --- a/brlan.c +++ b/brlan.c @@ -19,9 +19,9 @@ #include "endian.h" #if DEBUGBRLAN == 1 -#define dbgprintf printf +#define dbgprintf printf #else -#define dbgprintf // +#define dbgprintf // #endif //DEBUGBRLAN #define MAXIMUM_TAGS_SIZE (0xf000) @@ -119,21 +119,21 @@ void BRLAN_CreateXMLTag(tag_header tagHeader, void* data, u32 offset, mxml_node_ 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]); + 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]); + 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]); + 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]); + 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]); + 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]); + 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]); + mxmlElementSetAttrf(entry, "type2", "%s",tag_types_rlim_list[tagEntryInfo.type2]); } else { - mxmlElementSetAttrf(entry, "type2", "%s", tag_types_list[tagEntryInfo.type2]); + mxmlElementSetAttrf(entry, "type2", "%s",tag_types_list[tagEntryInfo.type2]); } } else { mxmlElementSetAttrf(entry, "type2", "%u", tagEntryInfo.type2); @@ -154,9 +154,12 @@ void BRLAN_CreateXMLTag(tag_header tagHeader, void* data, u32 offset, mxml_node_ 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)); + 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)); @@ -169,9 +172,12 @@ void BRLAN_CreateXMLTag(tag_header tagHeader, void* data, u32 offset, mxml_node_ 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); + 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); } } } @@ -202,16 +208,16 @@ void parse_brlan(char* filename, char *filenameout) 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[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 @@ -219,16 +225,16 @@ void parse_brlan(char* filename, char *filenameout) 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[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 @@ -244,16 +250,16 @@ void parse_brlan(char* filename, char *filenameout) 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[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"); @@ -261,16 +267,16 @@ void parse_brlan(char* filename, char *filenameout) 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[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"); @@ -278,16 +284,16 @@ void parse_brlan(char* filename, char *filenameout) 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[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"); @@ -369,7 +375,9 @@ void parse_brlan(char* filename, char *filenameout) 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); + 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)); @@ -469,51 +477,51 @@ void create_entries_from_xml(mxml_node_t *tree, mxml_node_t *node, brlan_entry * 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, rlpa_type, 4) == 0) - { - for(i = 0; i < strlen(tag_types_rlpa_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 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_rlmc_list[x][i]); - } - } else if(memcmp(tag_type, rltp_type, 4) == 0) { - for(i = 0; i < strlen(tag_types_rltp_list[x]); i++) - { - temp3[x][i] = toupper(tag_types_rltp_list[x][i]); - } - } else if(memcmp(tag_type, rlim_type, 4) == 0) { - for(i = 0; i < strlen(tag_types_rlim_list[x]); i++) - { - temp3[x][i] = toupper(tag_types_rlim_list[x][i]); - } - } else { - for(i = 0; i < strlen(tag_types_list[x]); i++) - { - temp3[x][i] = toupper(tag_types_list[x][i]); - } - } + for(i = 0; i < 16; i++) + memset(temp3[i], 0, 24); + for(x = 0; x < 16; x++) + if(memcmp(tag_type, rlpa_type, 4) == 0) + { + for(i = 0; i < strlen(tag_types_rlpa_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 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_rlmc_list[x][i]); + } + } else if(memcmp(tag_type, rltp_type, 4) == 0) { + for(i = 0; i < strlen(tag_types_rltp_list[x]); i++) + { + temp3[x][i] = toupper(tag_types_rltp_list[x][i]); + } + } else if(memcmp(tag_type, rlim_type, 4) == 0) { + for(i = 0; i < strlen(tag_types_rlim_list[x]); i++) + { + temp3[x][i] = toupper(tag_types_rlim_list[x][i]); + } + } else { + for(i = 0; i < strlen(tag_types_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++) { @@ -605,7 +613,7 @@ void create_entries_from_xml(mxml_node_t *tree, mxml_node_t *node, brlan_entry * } 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); + tempnode = mxmlFindElement(subsubnode, subsubnode, "padding", NULL,NULL,MXML_DESCEND); if(tempnode == NULL) { printf("Couldn't find attribute \"padding\"!\n"); exit(1); @@ -654,7 +662,7 @@ void create_entries_from_xml(mxml_node_t *tree, mxml_node_t *node, brlan_entry * if ( entryinfo[0].data_type == 0x200 ) free(data); if ( entryinfo[0].data_type == 0x100 ) - free(data2); + free(data2); u32 oldpos = ftell(fp); fseek(fp, entryloc, SEEK_SET); for( x = 0; x < head->entry_count; x++) @@ -683,9 +691,10 @@ void create_tag_from_xml(mxml_node_t *tree, mxml_node_t *node, FILE* fp) strcpy(temp, mxmlElementGetAttr(node, "type")); entr.is_material = (u8)atoi(temp); } else { + // add nice safety } - + 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)) @@ -714,8 +723,8 @@ void create_tag_from_xml(mxml_node_t *tree, mxml_node_t *node, FILE* fp) { printf("animation type not recognized: %.4s", head.magic); exit(1); - } - create_entries_from_xml(node, tagnode, &entr, &head, fp); + } + create_entries_from_xml(node, tagnode, &entr, &head, fp); entr.num_tags++; } u32 tempOffset = ftell(fp); @@ -731,7 +740,8 @@ void WriteBRLANHeader(brlan_header rlanhead, FILE* fp) writehead.magic[1] = rlanhead.magic[1]; writehead.magic[2] = rlanhead.magic[2]; writehead.magic[3] = rlanhead.magic[3]; - writehead.version = be32(rlanhead.version); + writehead.endian = be16(rlanhead.endian); + writehead.version = be16(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); @@ -770,16 +780,16 @@ void write_brlan(char *infile, char* outfile) 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[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"); @@ -795,16 +805,16 @@ void write_brlan(char *infile, char* outfile) 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[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"); @@ -812,16 +822,16 @@ void write_brlan(char *infile, char* outfile) 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[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"); @@ -829,16 +839,16 @@ void write_brlan(char *infile, char* outfile) 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[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"); @@ -879,7 +889,8 @@ void write_brlan(char *infile, char* outfile) rlanhead.magic[1] = 'L'; rlanhead.magic[2] = 'A'; rlanhead.magic[3] = 'N'; - rlanhead.version = 0xFEFF0008; + rlanhead.endian = 0xFEFF; + rlanhead.version = 0x0008; rlanhead.file_size = 0; rlanhead.pai1_offset = sizeof(brlan_header); rlanhead.pai1_count = 1; @@ -896,7 +907,7 @@ void write_brlan(char *infile, char* outfile) 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) @@ -917,7 +928,7 @@ void write_brlan(char *infile, char* outfile) 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)) { @@ -927,7 +938,7 @@ void write_brlan(char *infile, char* outfile) 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]; @@ -974,7 +985,7 @@ void write_brlan(char *infile, char* outfile) paihead.num_timgs = timgcount; - paihead.entry_offset = sizeof(brlan_pai1_header_type1) + totaltimgize + (4*paihead.num_timgs); + 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; diff --git a/brlan.h b/brlan.h index 5617185..3cde79f 100755 --- a/brlan.h +++ b/brlan.h @@ -53,7 +53,8 @@ typedef struct typedef struct { fourcc magic; // "RLAN" in ASCII. - u32 version; // Always 0xFEFF 0x0008. Possibly a versioning string. + u16 endian; // Always 0xFEFF. Tells endian. + u16 version; // Always 0x0008. Version of brlan format 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?) diff --git a/brlyt.c b/brlyt.c index b7b3758..6a6fdb9 100644 --- a/brlyt.c +++ b/brlyt.c @@ -18,12 +18,12 @@ #include "endian.h" #ifdef DEBUGBRLYT -#define dbgprintf printf +#define dbgprintf printf #else -#define dbgprintf // +#define dbgprintf // #endif //DEBUGBRLYT -#define MAXIMUM_TAGS_SIZE (0x1000) +#define MAXIMUM_TAGS_SIZE (0x1000) char pic1_magic[] = "pic1"; char pan1_magic[] = "pan1"; @@ -51,124 +51,124 @@ int lengthOfTextures; static int FourCCsMatch(fourcc cc1, fourcc cc2) { - int ret[4]; - ret[0] = (cc1[0] == cc2[0]); - ret[1] = (cc1[1] == cc2[1]); - ret[2] = (cc1[2] == cc2[2]); - ret[3] = (cc1[3] == cc2[3]); - int retval; - if(ret[0] && ret[1] && ret[2] && ret[3]) - retval = 1; - else - retval = 0; - return retval; + int ret[4]; + ret[0] = (cc1[0] == cc2[0]); + ret[1] = (cc1[1] == cc2[1]); + ret[2] = (cc1[2] == cc2[2]); + ret[3] = (cc1[3] == cc2[3]); + int retval; + if(ret[0] && ret[1] && ret[2] && ret[3]) + retval = 1; + else + retval = 0; + return retval; } static void BRLYT_ReadDataFromMemoryX(void* destination, void* input, size_t size) { - u8* out = (u8*)destination; - u8* in = ((u8*)input) + BRLYT_fileoffset; - memcpy(out, in, size); + u8* out = (u8*)destination; + u8* in = ((u8*)input) + BRLYT_fileoffset; + memcpy(out, in, size); } static void BRLYT_ReadDataFromMemory(void* destination, void* input, size_t size) { - BRLYT_ReadDataFromMemoryX(destination, input, size); - BRLYT_fileoffset += size; + BRLYT_ReadDataFromMemoryX(destination, input, size); + BRLYT_fileoffset += size; } float float_swap_bytes(float float1) { - u8 *float1c; float1c = (u8*)&float1; + u8 *float1c; float1c = (u8*)&float1; - 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; + 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; - float *newFloat; newFloat = (float*)float1c; - return *newFloat; + float *newFloat; newFloat = (float*)float1c; + return *newFloat; } u32 bit_extract(u32 num, u32 start, u32 end) { - if (end == 100) end = start; - u32 mask; - int first; - int firstMask = 1; - for (first=0;first<31-start+1;first++) - { - firstMask *= 2; - } - firstMask -= 1; - int secondMask = 1; - - for (first=0;first< 31-end;first++) - { - secondMask *=2; - } - secondMask -= 1; - mask = firstMask - secondMask; - int ret = (num & mask) >> (31 - end); - return ret; + if (end == 100) end = start; + u32 mask; + int first; + int firstMask = 1; + for (first=0;first<31-start+1;first++) + { + firstMask *= 2; + } + firstMask -= 1; + int secondMask = 1; + + for (first=0;first< 31-end;first++) + { + secondMask *=2; + } + secondMask -= 1; + mask = firstMask - secondMask; + int ret = (num & mask) >> (31 - end); + return ret; } char* getMaterial(u16 offset) { - if (offset == 0) return materials; - char *mat = materials + strlen(materials) + 1; + if (offset == 0) return materials; + char *mat = materials + strlen(materials) + 1; - if (offset > 1) - { - int n; - for (n=1; n 1) + { + int n; + for (n=1; n 1) - { - int n; - for (n=1; n 1) + { + int n; + for (n=1; n 0) subs = mxmlNewElement(tag, "subs"); - - int n; - for (n=0;n 0) subs = mxmlNewElement(tag, "subs"); + + int i; + for (i=0;i>1); - flags = mxmlNewElement(tag, "flag"); mxmlNewTextf(flags, 0, "%02x", (data.flag1 & 0x4)>>2); + 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); + 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); + 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"); + 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)); + 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)); } void PrintBRLYTEntry_wnd1(brlyt_entry entry, u8* brlyt_file, mxml_node_t *tag) @@ -362,64 +362,64 @@ void PrintBRLYTEntry_wnd1(brlyt_entry entry, u8* brlyt_file, mxml_node_t *tag) 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); - 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); + 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); + 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); + 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, 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, "coordinate"); mxmlNewTextf(unkk, 0, "%f", float_swap_bytes(wndy.coords[i])); - } - 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, *colors, *material; - brlyt_wnd1 wndy1; - BRLYT_ReadDataFromMemory(&wndy1, brlyt_file, sizeof(brlyt_wnd1)); - wnddd = mxmlNewElement(tag, "wnd1"); - for(i=0;i<4;i++) - { - colors = mxmlNewElement(wnddd, "color"); mxmlNewTextf(colors, 0, "%08x", int_swap_bytes(wndy1.colors[i])); - } - - 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; + 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, 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, "coordinate"); mxmlNewTextf(unkk, 0, "%f", float_swap_bytes(wndy.coords[i])); + } + 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, *colors, *material; + brlyt_wnd1 wndy1; + BRLYT_ReadDataFromMemory(&wndy1, brlyt_file, sizeof(brlyt_wnd1)); + wnddd = mxmlNewElement(tag, "wnd1"); + for(i=0;i<4;i++) + { + colors = mxmlNewElement(wnddd, "color"); mxmlNewTextf(colors, 0, "%08x", int_swap_bytes(wndy1.colors[i])); + } + + 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; for ( i = 0 ; i < wndy1.coordinate_count ; i++ ){ brlyt_wnd3 wndy3; BRLYT_ReadDataFromMemory(&wndy3, brlyt_file, sizeof(brlyt_wnd3)); @@ -430,25 +430,25 @@ void PrintBRLYTEntry_wnd1(brlyt_entry entry, u8* brlyt_file, mxml_node_t *tag) } - 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); + 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); + 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); + 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)); + 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)); } void PrintBRLYTEntry_pic1(brlyt_entry entry, u8* brlyt_file, mxml_node_t *tag) @@ -511,58 +511,67 @@ void PrintBRLYTEntry_pic1(brlyt_entry entry, u8* brlyt_file, mxml_node_t *tag) 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)); - brlyt_pic_chunk data2; - BRLYT_ReadDataFromMemory(&data2, brlyt_file, sizeof(brlyt_pic_chunk)); - mxmlElementSetAttrf(tag, "type", "%.4s", entry.magic); - mxmlElementSetAttrf(tag, "name", "%s", data.name); - 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); + 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)); + brlyt_pic_chunk data2; + BRLYT_ReadDataFromMemory(&data2, brlyt_file, sizeof(brlyt_pic_chunk)); + mxmlElementSetAttrf(tag, "type", "%.4s", entry.magic); + mxmlElementSetAttrf(tag, "name", "%s", data.name); + 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); + 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 + 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_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])); - } - coordinates = mxmlNewElement(tag, "coordinates"); - for (n=0;n> 24 ) & 0xff ); + attr = mxmlNewElement(color, "red"); + mxmlNewTextf( attr , 0 , "%02x" , ( be32(data2.vtx_colors[n]) >> 16 ) & 0xff ); + attr = mxmlNewElement(color, "red"); + mxmlNewTextf( attr , 0 , "%02x" , ( be32(data2.vtx_colors[n]) >> 8 ) & 0xff ); + attr = mxmlNewElement(color, "red"); + mxmlNewTextf( attr , 0 , "%02x" , ( be32(data2.vtx_colors[n]) >> 0 ) & 0xff ); + + } + coordinates = mxmlNewElement(tag, "coordinates"); + for (n=0;n>1); - flags = mxmlNewElement(tag, "flag"); mxmlNewTextf(flags, 0, "%02x", (data.flag1 & 0x4)>>2); + 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); + 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); + 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, *color1, *color2, *text; - brlyt_text_chunk data2; - BRLYT_ReadDataFromMemory(&data2, brlyt_file, sizeof(brlyt_text_chunk)); - 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)); - xsize = mxmlNewElement(font, "xsize"); mxmlNewTextf(xsize, 0, "%f", float_swap_bytes(data2.font_size_x)); - 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, "%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> 0] ); @@ -898,7 +907,7 @@ void PrintBRLYTEntry_mat1(brlyt_entry entry, u8* brlyt_file, mxml_node_t *tag) 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"); @@ -907,7 +916,7 @@ void PrintBRLYTEntry_mat1(brlyt_entry entry, u8* brlyt_file, mxml_node_t *tag) 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"); @@ -916,7 +925,7 @@ void PrintBRLYTEntry_mat1(brlyt_entry entry, u8* brlyt_file, mxml_node_t *tag) 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"); @@ -925,26 +934,26 @@ void PrintBRLYTEntry_mat1(brlyt_entry entry, u8* brlyt_file, mxml_node_t *tag) 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 0) - { - u8 toAdd = 4-(*fileOffset % 4); - char nuller[3] = {'\0', '\0', '\0'}; - fwrite(&nuller, sizeof(char), toAdd, fp); - *fileOffset = *fileOffset + toAdd; - } - textures = malloc(lengthOfNames * sizeof(char)); - memcpy(textures, names, lengthOfNames * sizeof(char)); - free(names); - } - if ( memcmp(temp, fnl1, sizeof(fnl1)) == 0) - { - brlyt_numoffs_chunk chunk; - chunk.num = 0; - chunk.offs = 0; - fwrite(&chunk, sizeof(chunk), 1, fp); - *fileOffset = *fileOffset + sizeof(chunk); - - char *names; - names = malloc(sizeof(char)); - int lengthOfNames = 0; - mxml_node_t *subnode = mxmlFindElement(node, node, "entries", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - int numEntries = 0; - - int oldNameLength; - int baseOffset = 0; - int numoffsOffset = *fileOffset - 4; - - u32 *offsunks; - offsunks = malloc(sizeof(u32)); - - brlyt_offsunk_chunk chunk2; - mxml_node_t *valnode; - for(valnode = mxmlFindElement(subnode, subnode, "name", NULL, NULL, MXML_DESCEND); valnode != NULL; valnode = mxmlFindElement(valnode, subnode, "name", NULL, NULL, MXML_DESCEND)) { - if (valnode != NULL) - { - char tempSub[256]; - get_value(valnode, tempSub, 256); - - oldNameLength = lengthOfNames; - lengthOfNames += strlen(tempSub); - - offsunks = realloc(offsunks, (numEntries + 1)*(2 * sizeof(u32))); - offsunks[(numEntries*2)+0] = baseOffset; - offsunks[(numEntries*2)+1] = 0; - - *fileOffset = *fileOffset + sizeof(chunk2); - numEntries++; - - baseOffset += (strlen(tempSub) + 1); - names = realloc(names, 1 + sizeof(char) * lengthOfNames); - memcpy(&names[oldNameLength], tempSub, strlen(tempSub)); - char nuller = '\0'; - memcpy(&names[lengthOfNames], &nuller, sizeof(char)); - lengthOfNames += 1; - } - } - chunk.num = short_swap_bytes(numEntries); - chunk.offs = 0; - fseek(fp, numoffsOffset, SEEK_SET); - fwrite(&chunk, sizeof(chunk), 1, fp); - - int i; - for(i=0;i 0) - { - u8 toAdd = 4-(*fileOffset % 4); - char nuller[3] = {'\0', '\0', '\0'}; - fwrite(&nuller, sizeof(char), toAdd, fp); - *fileOffset = *fileOffset + toAdd; - } - free(names); - } - if ( memcmp(temp, mat1, sizeof(mat1)) == 0) - { - int numberOfEntries = 0; - int actualNumber = 0; - brlyt_numoffs_chunk numchunk; - brlyt_material_chunk chunk; - mxml_node_t *subnode; - for(subnode=mxmlFindElement(node, node, "entries", NULL, NULL, MXML_DESCEND);subnode!=NULL;subnode=mxmlFindElement(subnode, node, "entries", NULL, NULL, MXML_DESCEND)) - numberOfEntries++; - - numchunk.num = short_swap_bytes(numberOfEntries); - numchunk.offs = 0; - fwrite(&numchunk, sizeof(numchunk), 1, fp); - *fileOffset = *fileOffset + sizeof(numchunk); - - int *offsets = calloc(numberOfEntries, sizeof(int)); - int offsetsOffset = ftell(fp); - int materialOffset = 0; - actualNumber = numberOfEntries; - numberOfEntries = 0; - int matSize = 0; - int initialOffset = sizeof(numchunk) + 8 + (actualNumber * sizeof(int)); - - offsets[numberOfEntries] = be32(matSize + initialOffset); - fwrite(&offsets[0], sizeof(int), actualNumber, fp); - *fileOffset = *fileOffset + (actualNumber * 4); - - for(subnode=mxmlFindElement(node,node,"entries",NULL,NULL,MXML_DESCEND);subnode!=NULL;subnode=mxmlFindElement(subnode,node,"entries",NULL,NULL,MXML_DESCEND)) - { - numberOfEntries += 1; - char temp[256]; - if(mxmlElementGetAttr(subnode, "name") != NULL) - strcpy(temp, mxmlElementGetAttr(subnode, "name")); - else{ - printf("No name attribute found!\nQuitting!\n"); - exit(1); - } - memset(chunk.name, 0, 20); - strcpy(chunk.name, temp); - - materials = realloc(materials, lengthOfMaterials + strlen(chunk.name) + 1); - memcpy(&materials[lengthOfMaterials], chunk.name, strlen(chunk.name) + 1); - lengthOfMaterials += (1 + strlen(chunk.name)); - numberOfMaterials += 1; - - mxml_node_t *setnode; - setnode = mxmlFindElement(subnode, subnode, "colors", NULL, NULL, MXML_DESCEND); - if (setnode != NULL) - { - mxml_node_t *valnode; - int colorNumber = 0; - for (valnode=mxmlFindElement(setnode, setnode, "forecolor", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "forecolor", NULL, NULL, MXML_DESCEND) ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - - chunk.forecolor[colorNumber] = strtol(tempCoord, NULL, 10); - chunk.forecolor[colorNumber] = short_swap_bytes(chunk.forecolor[colorNumber]); - - colorNumber+=1; - } - colorNumber = 0; - for (valnode=mxmlFindElement(setnode, setnode, "backcolor", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "backcolor", NULL, NULL, MXML_DESCEND) ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - - chunk.backcolor[colorNumber] = strtol(tempCoord, NULL, 10); - chunk.backcolor[colorNumber] = short_swap_bytes(chunk.backcolor[colorNumber]); - - colorNumber+=1; - } - colorNumber = 0; - for (valnode=mxmlFindElement(setnode, setnode, "colorReg3", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "colorReg3", NULL, NULL, MXML_DESCEND) ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - - chunk.colorReg3[colorNumber] = strtol(tempCoord, NULL, 10); - chunk.colorReg3[colorNumber] = short_swap_bytes(chunk.colorReg3[colorNumber]); - - colorNumber+=1; - } - colorNumber = 0; - for (valnode=mxmlFindElement(setnode, setnode, "tev_k", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "tev_k", NULL, NULL, MXML_DESCEND) ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.tev_kcolor[colorNumber] = be32(strtoul(tempCoord, NULL, 16)); - colorNumber+=1; - } - } + u32 startOfChunk = *fileOffset; + + char lyt1[4] = {'l', 'y', 't', '1'}; + char txl1[4] = {'t', 'x', 'l', '1'}; + char fnl1[4] = {'f', 'n', 'l', '1'}; + char mat1[4] = {'m', 'a', 't', '1'}; + char pan1[4] = {'p', 'a', 'n', '1'}; + char wnd1[4] = {'w', 'n', 'd', '1'}; + char bnd1[4] = {'b', 'n', 'd', '1'}; + char pic1[4] = {'p', 'i', 'c', '1'}; + char txt1[4] = {'t', 'x', 't', '1'}; + char grp1[4] = {'g', 'r', 'p', '1'}; + char grs1[4] = {'g', 'r', 's', '1'}; + char gre1[4] = {'g', 'r', 'e', '1'}; + char pas1[4] = {'p', 'a', 's', '1'}; + char pae1[4] = {'p', 'a', 'e', '1'}; + + if ( memcmp(temp, lyt1, sizeof(lyt1)) == 0) + { + brlyt_lytheader_chunk lytheader; + + mxml_node_t *subnode = mxmlFindElement(node , node , "drawnFromMiddle", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempChar[4]; + get_value(subnode, tempChar, 256); + lytheader.drawnFromMiddle = atoi(tempChar); + lytheader.pad[0]=0;lytheader.pad[1]=0;lytheader.pad[2]=0; + } + subnode = mxmlFindElement(node, node, "size", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode = mxmlFindElement(subnode , subnode , "width", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempChar[4]; + get_value(valnode, tempChar, 256); + *(float*)(&(lytheader.width)) = atof(tempChar); + } + valnode = mxmlFindElement(subnode , subnode ,"height", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempChar[4]; + get_value(valnode, tempChar, 256); + + *(float*)(&(lytheader.height)) = atof(tempChar); + } + } + lytheader.pad[0] = 0; lytheader.pad[1] = 0; lytheader.pad[2] = 0; + lytheader.width = float_swap_bytes(lytheader.width); + lytheader.height = float_swap_bytes(lytheader.height); + fwrite(&lytheader, sizeof(brlyt_header), 1, fp); + *fileOffset = *fileOffset + sizeof(lytheader); + } + if ( memcmp(temp, txl1, sizeof(txl1)) == 0) + { + int numoffsOffset = ftell(fp); + + brlyt_numoffs_chunk chunk; + chunk.num = 0; + chunk.offs = 0; + fwrite(&chunk, sizeof(chunk), 1, fp); + *fileOffset = *fileOffset + sizeof(chunk); + + char *names; + names = malloc(sizeof(names)); + int lengthOfNames = 0; + mxml_node_t *subnode = mxmlFindElement(node, node, "entries", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + int numEntries = 0; + + int oldNameLength; + int baseOffset = 0; + + u32 *offsunks; + + offsunks = malloc(sizeof(u32)); + + brlyt_offsunk_chunk chunk2; + mxml_node_t *valnode; + for(valnode = mxmlFindElement(subnode, subnode, "name", NULL, NULL, MXML_DESCEND); valnode != NULL; valnode = mxmlFindElement(valnode, subnode, "name", NULL, NULL, MXML_DESCEND)) { + if (valnode != NULL) + { + char tempSub[256]; + get_value(valnode, tempSub, 256); + + oldNameLength = lengthOfNames; + lengthOfNames += strlen(tempSub); + + offsunks = realloc(offsunks, (numEntries + 1)*(2 * sizeof(u32))); + if (offsunks == NULL) printf("NULLed by a realloc\n"); + + offsunks[(numEntries*2)+0] = baseOffset; + offsunks[(numEntries*2)+1] = 0; + + *fileOffset = *fileOffset + sizeof(chunk2); + numEntries++; + + baseOffset += (strlen(tempSub) + 1); + + names = realloc(names, 1 + sizeof(char) * lengthOfNames); + strcpy(&names[oldNameLength], tempSub); + char nuller = '\0'; + memcpy(&names[lengthOfNames], &nuller, sizeof(char)); + lengthOfNames += 1; + } + } + chunk.num = short_swap_bytes(numEntries); + chunk.offs = 0; + fseek(fp, numoffsOffset, SEEK_SET); + fwrite(&chunk, sizeof(chunk), 1, fp); + + int i; + for(i=0;i 0) + { + u8 toAdd = 4-(*fileOffset % 4); + char nuller[3] = {'\0', '\0', '\0'}; + fwrite(&nuller, sizeof(char), toAdd, fp); + *fileOffset = *fileOffset + toAdd; + } + textures = malloc(lengthOfNames * sizeof(char)); + memcpy(textures, names, lengthOfNames * sizeof(char)); + free(names); + } + if ( memcmp(temp, fnl1, sizeof(fnl1)) == 0) + { + brlyt_numoffs_chunk chunk; + chunk.num = 0; + chunk.offs = 0; + fwrite(&chunk, sizeof(chunk), 1, fp); + *fileOffset = *fileOffset + sizeof(chunk); + + char *names; + names = malloc(sizeof(char)); + int lengthOfNames = 0; + mxml_node_t *subnode = mxmlFindElement(node, node, "entries", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + int numEntries = 0; + + int oldNameLength; + int baseOffset = 0; + int numoffsOffset = *fileOffset - 4; + + u32 *offsunks; + offsunks = malloc(sizeof(u32)); + + brlyt_offsunk_chunk chunk2; + mxml_node_t *valnode; + for(valnode = mxmlFindElement(subnode, subnode, "name", NULL, NULL, MXML_DESCEND); valnode != NULL; valnode = mxmlFindElement(valnode, subnode, "name", NULL, NULL, MXML_DESCEND)) { + if (valnode != NULL) + { + char tempSub[256]; + get_value(valnode, tempSub, 256); + + oldNameLength = lengthOfNames; + lengthOfNames += strlen(tempSub); + + offsunks = realloc(offsunks, (numEntries + 1)*(2 * sizeof(u32))); + offsunks[(numEntries*2)+0] = baseOffset; + offsunks[(numEntries*2)+1] = 0; + + *fileOffset = *fileOffset + sizeof(chunk2); + numEntries++; + + baseOffset += (strlen(tempSub) + 1); + names = realloc(names, 1 + sizeof(char) * lengthOfNames); + memcpy(&names[oldNameLength], tempSub, strlen(tempSub)); + char nuller = '\0'; + memcpy(&names[lengthOfNames], &nuller, sizeof(char)); + lengthOfNames += 1; + } + } + chunk.num = short_swap_bytes(numEntries); + chunk.offs = 0; + fseek(fp, numoffsOffset, SEEK_SET); + fwrite(&chunk, sizeof(chunk), 1, fp); + + int i; + for(i=0;i 0) + { + u8 toAdd = 4-(*fileOffset % 4); + char nuller[3] = {'\0', '\0', '\0'}; + fwrite(&nuller, sizeof(char), toAdd, fp); + *fileOffset = *fileOffset + toAdd; + } + free(names); + } + if ( memcmp(temp, mat1, sizeof(mat1)) == 0) + { + int numberOfEntries = 0; + int actualNumber = 0; + brlyt_numoffs_chunk numchunk; + brlyt_material_chunk chunk; + mxml_node_t *subnode; + for(subnode=mxmlFindElement(node, node, "entries", NULL, NULL, MXML_DESCEND);subnode!=NULL;subnode=mxmlFindElement(subnode, node, "entries", NULL, NULL, MXML_DESCEND)) + numberOfEntries++; + + numchunk.num = short_swap_bytes(numberOfEntries); + numchunk.offs = 0; + fwrite(&numchunk, sizeof(numchunk), 1, fp); + *fileOffset = *fileOffset + sizeof(numchunk); + + int *offsets = calloc(numberOfEntries, sizeof(int)); + int offsetsOffset = ftell(fp); + int materialOffset = 0; + actualNumber = numberOfEntries; + numberOfEntries = 0; + int matSize = 0; + int initialOffset = sizeof(numchunk) + 8 + (actualNumber * sizeof(int)); + + offsets[numberOfEntries] = be32(matSize + initialOffset); + fwrite(&offsets[0], sizeof(int), actualNumber, fp); + *fileOffset = *fileOffset + (actualNumber * 4); + + for(subnode=mxmlFindElement(node,node,"entries",NULL,NULL,MXML_DESCEND);subnode!=NULL;subnode=mxmlFindElement(subnode,node,"entries",NULL,NULL,MXML_DESCEND)) + { + numberOfEntries += 1; + char temp[256]; + if(mxmlElementGetAttr(subnode, "name") != NULL) + strcpy(temp, mxmlElementGetAttr(subnode, "name")); + else{ + printf("No name attribute found!\nQuitting!\n"); + exit(1); + } + memset(chunk.name, 0, 20); + strcpy(chunk.name, temp); + + materials = realloc(materials, lengthOfMaterials + strlen(chunk.name) + 1); + memcpy(&materials[lengthOfMaterials], chunk.name, strlen(chunk.name) + 1); + lengthOfMaterials += (1 + strlen(chunk.name)); + numberOfMaterials += 1; + + mxml_node_t *setnode; + setnode = mxmlFindElement(subnode, subnode, "colors", NULL, NULL, MXML_DESCEND); + if (setnode != NULL) + { + mxml_node_t *valnode; + int colorNumber = 0; + for (valnode=mxmlFindElement(setnode, setnode, "forecolor", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "forecolor", NULL, NULL, MXML_DESCEND) ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + + chunk.forecolor[colorNumber] = strtol(tempCoord, NULL, 10); + chunk.forecolor[colorNumber] = short_swap_bytes(chunk.forecolor[colorNumber]); + + colorNumber+=1; + } + colorNumber = 0; + for (valnode=mxmlFindElement(setnode, setnode, "backcolor", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "backcolor", NULL, NULL, MXML_DESCEND) ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + + chunk.backcolor[colorNumber] = strtol(tempCoord, NULL, 10); + chunk.backcolor[colorNumber] = short_swap_bytes(chunk.backcolor[colorNumber]); + + colorNumber+=1; + } + colorNumber = 0; + for (valnode=mxmlFindElement(setnode, setnode, "colorReg3", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "colorReg3", NULL, NULL, MXML_DESCEND) ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + + chunk.colorReg3[colorNumber] = strtol(tempCoord, NULL, 10); + chunk.colorReg3[colorNumber] = short_swap_bytes(chunk.colorReg3[colorNumber]); + + colorNumber+=1; + } + colorNumber = 0; + for (valnode=mxmlFindElement(setnode, setnode, "tev_k", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "tev_k", NULL, NULL, MXML_DESCEND) ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.tev_kcolor[colorNumber] = be32(strtoul(tempCoord, NULL, 16)); + colorNumber+=1; + } + } /* - setnode = mxmlFindElement(subnode,subnode,"flags",NULL,NULL,MXML_DESCEND); - if (setnode != NULL) - { - char tempCoord[256]; - get_value(setnode, tempCoord, 256); - chunk.flags = be32(strtoul(tempCoord, NULL, 16)); - } + setnode = mxmlFindElement(subnode,subnode,"flags",NULL,NULL,MXML_DESCEND); + if (setnode != NULL) + { + char tempCoord[256]; + get_value(setnode, tempCoord, 256); + chunk.flags = be32(strtoul(tempCoord, NULL, 16)); + } */ u32 tempFileOffset = ftell(fp); @@ -1644,24 +1653,24 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl flags.flags = 0; chunk.flags = 0; - fwrite(&chunk, sizeof(chunk), 1, fp); - *fileOffset = *fileOffset + sizeof(chunk); - matSize += sizeof(chunk); - - brlyt_texref_chunk chunkTexRef; - for(setnode = mxmlFindElement(subnode, subnode, "texture", NULL, NULL, MXML_DESCEND); setnode != NULL; setnode = mxmlFindElement(setnode, subnode, "texture", NULL, NULL, MXML_DESCEND)) - { - mxml_node_t *valnode; - char temp[256]; - if(mxmlElementGetAttr(setnode, "name") != NULL) - strcpy(temp, mxmlElementGetAttr(setnode, "name")); - else{ - printf("No name attribute found!\nQuitting!\n"); - exit(1); - } - chunkTexRef.tex_offs = short_swap_bytes(findTexOffset(temp)); - - valnode=mxmlFindElement(setnode, setnode, "wrap_s", NULL, NULL, MXML_DESCEND); + fwrite(&chunk, sizeof(chunk), 1, fp); + *fileOffset = *fileOffset + sizeof(chunk); + matSize += sizeof(chunk); + + brlyt_texref_chunk chunkTexRef; + for(setnode = mxmlFindElement(subnode, subnode, "texture", NULL, NULL, MXML_DESCEND); setnode != NULL; setnode = mxmlFindElement(setnode, subnode, "texture", NULL, NULL, MXML_DESCEND)) + { + mxml_node_t *valnode; + char temp[256]; + if(mxmlElementGetAttr(setnode, "name") != NULL) + strcpy(temp, mxmlElementGetAttr(setnode, "name")); + else{ + printf("No name attribute found!\nQuitting!\n"); + exit(1); + } + chunkTexRef.tex_offs = short_swap_bytes(findTexOffset(temp)); + + valnode=mxmlFindElement(setnode, setnode, "wrap_s", NULL, NULL, MXML_DESCEND); char wraps[4][20]; int l; @@ -1672,8 +1681,8 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl strcpy( wraps[2] , "GX_MIRROR" ); strcpy( wraps[3] , "GX_MAXTEXWRAPMODE" ); - char tempCoord[256]; - get_value(valnode, tempCoord, 256); + char tempCoord[256]; + get_value(valnode, tempCoord, 256); chunkTexRef.wrap_s = strtoul(tempCoord, NULL, 16); for ( l = 0 ; l < 4 ; l++ ) { if ( strncmp( wraps[l] , tempCoord , 17 ) == 0 ) { @@ -1682,9 +1691,9 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl } } - valnode=mxmlFindElement(setnode, setnode, "wrap_t", NULL, NULL, MXML_DESCEND); + valnode=mxmlFindElement(setnode, setnode, "wrap_t", NULL, NULL, MXML_DESCEND); - get_value(valnode, tempCoord, 256); + get_value(valnode, tempCoord, 256); chunkTexRef.wrap_t = strtoul(tempCoord, NULL, 16); for ( l = 0 ; l < 4 ; l++ ) { if ( strncmp( wraps[l] , tempCoord , 17 ) == 0 ) { @@ -1695,47 +1704,47 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl flags.flag.Texture++; - fwrite(&chunkTexRef, sizeof(chunkTexRef), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkTexRef); - matSize += sizeof(chunkTexRef); - } - - brlyt_tex_srt chunkTexCoords; - for(setnode = mxmlFindElement(subnode, subnode, "TextureSRT", NULL, NULL, MXML_DESCEND); setnode != NULL; setnode = mxmlFindElement(setnode, subnode, "TextureSRT", NULL, NULL, MXML_DESCEND)) - { - char tempCoord[256]; - mxml_node_t *valnode; - valnode=mxmlFindElement(setnode, setnode, "XTrans", NULL, NULL, MXML_DESCEND); + fwrite(&chunkTexRef, sizeof(chunkTexRef), 1, fp); + *fileOffset = *fileOffset + sizeof(chunkTexRef); + matSize += sizeof(chunkTexRef); + } + + brlyt_tex_srt chunkTexCoords; + for(setnode = mxmlFindElement(subnode, subnode, "TextureSRT", NULL, NULL, MXML_DESCEND); setnode != NULL; setnode = mxmlFindElement(setnode, subnode, "TextureSRT", NULL, NULL, MXML_DESCEND)) + { + char tempCoord[256]; + mxml_node_t *valnode; + valnode=mxmlFindElement(setnode, setnode, "XTrans", NULL, NULL, MXML_DESCEND); memset(tempCoord, 0, 256); - get_value(valnode, tempCoord, 256); - chunkTexCoords.XTrans = float_swap_bytes(atof(tempCoord)); - valnode=mxmlFindElement(setnode, setnode, "YTrans", NULL, NULL, MXML_DESCEND); + get_value(valnode, tempCoord, 256); + chunkTexCoords.XTrans = float_swap_bytes(atof(tempCoord)); + valnode=mxmlFindElement(setnode, setnode, "YTrans", NULL, NULL, MXML_DESCEND); memset(tempCoord, 0, 256); - get_value(valnode, tempCoord, 256); - chunkTexCoords.YTrans = float_swap_bytes(atof(tempCoord)); - valnode=mxmlFindElement(setnode, setnode, "Rotate", NULL, NULL, MXML_DESCEND); + get_value(valnode, tempCoord, 256); + chunkTexCoords.YTrans = float_swap_bytes(atof(tempCoord)); + valnode=mxmlFindElement(setnode, setnode, "Rotate", NULL, NULL, MXML_DESCEND); memset(tempCoord, 0, 256); - get_value(valnode, tempCoord, 256); - chunkTexCoords.Rotate = float_swap_bytes(atof(tempCoord)); - valnode=mxmlFindElement(setnode, setnode, "XScale", NULL, NULL, MXML_DESCEND); + get_value(valnode, tempCoord, 256); + chunkTexCoords.Rotate = float_swap_bytes(atof(tempCoord)); + valnode=mxmlFindElement(setnode, setnode, "XScale", NULL, NULL, MXML_DESCEND); memset(tempCoord, 0, 256); - get_value(valnode, tempCoord, 256); - chunkTexCoords.XScale = float_swap_bytes(atof(tempCoord)); - valnode=mxmlFindElement(setnode, setnode, "YScale", NULL, NULL, MXML_DESCEND); + get_value(valnode, tempCoord, 256); + chunkTexCoords.XScale = float_swap_bytes(atof(tempCoord)); + valnode=mxmlFindElement(setnode, setnode, "YScale", NULL, NULL, MXML_DESCEND); memset(tempCoord, 0, 256); - get_value(valnode, tempCoord, 256); - chunkTexCoords.YScale = float_swap_bytes(atof(tempCoord)); + get_value(valnode, tempCoord, 256); + chunkTexCoords.YScale = float_swap_bytes(atof(tempCoord)); flags.flag.TexSRT++; - fwrite(&chunkTexCoords, sizeof(chunkTexCoords), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkTexCoords); - matSize += sizeof(chunkTexCoords); - } + fwrite(&chunkTexCoords, sizeof(chunkTexCoords), 1, fp); + *fileOffset = *fileOffset + sizeof(chunkTexCoords); + matSize += sizeof(chunkTexCoords); + } - brlyt_tex_coordgen chunkUa3; - for(setnode = mxmlFindElement(subnode, subnode, "CoordGen", NULL, NULL, MXML_DESCEND); setnode != NULL; setnode = mxmlFindElement(setnode, subnode, "CoordGen", NULL, NULL, MXML_DESCEND)) - { + brlyt_tex_coordgen chunkUa3; + for(setnode = mxmlFindElement(subnode, subnode, "CoordGen", NULL, NULL, MXML_DESCEND); setnode != NULL; setnode = mxmlFindElement(setnode, subnode, "CoordGen", NULL, NULL, MXML_DESCEND)) + { char tgen_types[4][20]; int l; for ( l = 0 ; l < 4 ; l++ ) @@ -1823,7 +1832,7 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl strcpy( mtxsrc[40] , "GX_DTTMTX19" ); strcpy( mtxsrc[41] , "GX_DTTIDENTITY" ); // actually 125 not 124 - mxml_node_t *valnode; + mxml_node_t *valnode; char tempCoord[256]; valnode=mxmlFindElement(setnode, setnode, "tgen_type", NULL, NULL, MXML_DESCEND); @@ -1869,14 +1878,14 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl flags.flag.TexCoord++; - fwrite(&chunkUa3, sizeof(chunkUa3), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkUa3); - matSize += sizeof(chunkUa3); - } + fwrite(&chunkUa3, sizeof(chunkUa3), 1, fp); + *fileOffset = *fileOffset + sizeof(chunkUa3); + matSize += sizeof(chunkUa3); + } - brlyt_tex_chanctrl chunkUa4; - for(setnode = mxmlFindElement(subnode, subnode, "ChanControl", NULL, NULL, MXML_DESCEND); setnode != NULL; setnode = mxmlFindElement(setnode, subnode, "ChanControl", NULL, NULL, MXML_DESCEND)) - { + brlyt_tex_chanctrl chunkUa4; + for(setnode = mxmlFindElement(subnode, subnode, "ChanControl", NULL, NULL, MXML_DESCEND); setnode != NULL; setnode = mxmlFindElement(setnode, subnode, "ChanControl", NULL, NULL, MXML_DESCEND)) + { char matsrc[2][20]; int l; for ( l = 0 ; l < 2 ; l++ ) @@ -1884,7 +1893,7 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl strcpy( matsrc[0] , "GX_SRC_REG" ); strcpy( matsrc[1] , "GX_SRC_VTX" ); - mxml_node_t *valnode; + mxml_node_t *valnode; char tempCoord[256]; valnode=mxmlFindElement(setnode, setnode, "ColorMatSource", NULL, NULL, MXML_DESCEND); @@ -1925,15 +1934,15 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl flags.flag.ua4++; - fwrite(&chunkUa4, sizeof(chunkUa4), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkUa4); - matSize += sizeof(chunkUa4); - } + fwrite(&chunkUa4, sizeof(chunkUa4), 1, fp); + *fileOffset = *fileOffset + sizeof(chunkUa4); + matSize += sizeof(chunkUa4); + } - brlyt_tex_matcol chunkUa5; - for(setnode = mxmlFindElement(subnode, subnode, "MaterialColor", NULL, NULL, MXML_DESCEND); setnode != NULL; setnode = mxmlFindElement(setnode, subnode, "MaterialColor", NULL, NULL, MXML_DESCEND)) - { - mxml_node_t *valnode; + brlyt_tex_matcol chunkUa5; + for(setnode = mxmlFindElement(subnode, subnode, "MaterialColor", NULL, NULL, MXML_DESCEND); setnode != NULL; setnode = mxmlFindElement(setnode, subnode, "MaterialColor", NULL, NULL, MXML_DESCEND)) + { + mxml_node_t *valnode; char tempCoord[256]; valnode=mxmlFindElement(setnode, setnode, "red", NULL, NULL, MXML_DESCEND); @@ -1958,13 +1967,13 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl flags.flag.ua5++; - fwrite(&chunkUa5, sizeof(chunkUa5), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkUa5); - matSize += sizeof(chunkUa5); - } - brlyt_tev_swapmodetable chunkUa6; - for(setnode = mxmlFindElement(subnode, subnode, "TevSwapModeTable", NULL, NULL, MXML_DESCEND); setnode != NULL; setnode = mxmlFindElement(setnode, subnode, "TevSwapModeTable", NULL, NULL, MXML_DESCEND)) - { + fwrite(&chunkUa5, sizeof(chunkUa5), 1, fp); + *fileOffset = *fileOffset + sizeof(chunkUa5); + matSize += sizeof(chunkUa5); + } + brlyt_tev_swapmodetable chunkUa6; + for(setnode = mxmlFindElement(subnode, subnode, "TevSwapModeTable", NULL, NULL, MXML_DESCEND); setnode != NULL; setnode = mxmlFindElement(setnode, subnode, "TevSwapModeTable", NULL, NULL, MXML_DESCEND)) + { char tevcolor[4][20]; int l; for ( l = 0 ; l < 4 ; l++ ) @@ -1974,7 +1983,7 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl strcpy( tevcolor[2] , "GX_CH_BLUE" ); strcpy( tevcolor[3] , "GX_CH_ALPHA" ); - mxml_node_t *valnode; + mxml_node_t *valnode; char tempCoord[256]; valnode=mxmlFindElement(setnode, setnode, "OneRed", NULL, NULL, MXML_DESCEND); @@ -2163,60 +2172,60 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl flags.flag.ua6++; - fwrite(&chunkUa6, sizeof(chunkUa6), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkUa6); - matSize += sizeof(chunkUa6); - } - - brlyt_indtex_srt chunkUa7; - for(setnode = mxmlFindElement(subnode, subnode, "IndTextureSRT", NULL, NULL, MXML_DESCEND); setnode != NULL; setnode = mxmlFindElement(setnode, subnode, "IndTextureSRT", NULL, NULL, MXML_DESCEND)) - { - mxml_node_t *valnode; - valnode=mxmlFindElement(setnode, setnode, "XTrans", NULL, NULL, MXML_DESCEND); - if ( valnode != NULL ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunkUa7.XTrans = float_swap_bytes(atof(tempCoord)); - } - valnode=mxmlFindElement(setnode, setnode, "YTrans", NULL, NULL, MXML_DESCEND); - if ( valnode != NULL ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunkUa7.YTrans = float_swap_bytes(atof(tempCoord)); - } - valnode=mxmlFindElement(setnode, setnode, "Rotate", NULL, NULL, MXML_DESCEND); - if ( valnode != NULL ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunkUa7.Rotate = float_swap_bytes(atof(tempCoord)); - } - valnode=mxmlFindElement(setnode, setnode, "XScale", NULL, NULL, MXML_DESCEND); - if ( valnode != NULL ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunkUa7.XScale = float_swap_bytes(atof(tempCoord)); - } - valnode=mxmlFindElement(setnode, setnode, "YScale", NULL, NULL, MXML_DESCEND); - if ( valnode != NULL ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunkUa7.YScale = float_swap_bytes(atof(tempCoord)); - } + fwrite(&chunkUa6, sizeof(chunkUa6), 1, fp); + *fileOffset = *fileOffset + sizeof(chunkUa6); + matSize += sizeof(chunkUa6); + } + + brlyt_indtex_srt chunkUa7; + for(setnode = mxmlFindElement(subnode, subnode, "IndTextureSRT", NULL, NULL, MXML_DESCEND); setnode != NULL; setnode = mxmlFindElement(setnode, subnode, "IndTextureSRT", NULL, NULL, MXML_DESCEND)) + { + mxml_node_t *valnode; + valnode=mxmlFindElement(setnode, setnode, "XTrans", NULL, NULL, MXML_DESCEND); + if ( valnode != NULL ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunkUa7.XTrans = float_swap_bytes(atof(tempCoord)); + } + valnode=mxmlFindElement(setnode, setnode, "YTrans", NULL, NULL, MXML_DESCEND); + if ( valnode != NULL ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunkUa7.YTrans = float_swap_bytes(atof(tempCoord)); + } + valnode=mxmlFindElement(setnode, setnode, "Rotate", NULL, NULL, MXML_DESCEND); + if ( valnode != NULL ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunkUa7.Rotate = float_swap_bytes(atof(tempCoord)); + } + valnode=mxmlFindElement(setnode, setnode, "XScale", NULL, NULL, MXML_DESCEND); + if ( valnode != NULL ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunkUa7.XScale = float_swap_bytes(atof(tempCoord)); + } + valnode=mxmlFindElement(setnode, setnode, "YScale", NULL, NULL, MXML_DESCEND); + if ( valnode != NULL ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunkUa7.YScale = float_swap_bytes(atof(tempCoord)); + } flags.flag.ua7++; - fwrite(&chunkUa7, sizeof(chunkUa7), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkUa7); - matSize += sizeof(chunkUa7); - } - brlyt_indtex_order chunkUa8; - for(setnode = mxmlFindElement(subnode, subnode, "IndTextureOrder", NULL, NULL, MXML_DESCEND); setnode != NULL; setnode = mxmlFindElement(setnode, subnode, "IndTextureOrder", NULL, NULL, MXML_DESCEND)) - { + fwrite(&chunkUa7, sizeof(chunkUa7), 1, fp); + *fileOffset = *fileOffset + sizeof(chunkUa7); + matSize += sizeof(chunkUa7); + } + brlyt_indtex_order chunkUa8; + for(setnode = mxmlFindElement(subnode, subnode, "IndTextureOrder", NULL, NULL, MXML_DESCEND); setnode != NULL; setnode = mxmlFindElement(setnode, subnode, "IndTextureOrder", NULL, NULL, MXML_DESCEND)) + { char scale[10][20]; int l; for ( l = 0 ; l < 10 ; l++ ) @@ -2232,7 +2241,7 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl strcpy( scale[8] , "GX_ITS_256" ); strcpy( scale[9] , "GX_MAX_ITSCALE" ); - mxml_node_t *valnode; + mxml_node_t *valnode; char tempCoord[256]; valnode=mxmlFindElement(setnode, setnode, "TextureCoordinate", NULL, NULL, MXML_DESCEND); @@ -2269,15 +2278,15 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl flags.flag.ua8++; - fwrite(&chunkUa8, sizeof(chunkUa8), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkUa8); - matSize += sizeof(chunkUa8); - } + fwrite(&chunkUa8, sizeof(chunkUa8), 1, fp); + *fileOffset = *fileOffset + sizeof(chunkUa8); + matSize += sizeof(chunkUa8); + } TevStages chunkUa9; - for (setnode = mxmlFindElement(subnode, subnode, "TevStage", NULL, NULL, MXML_DESCEND); setnode != NULL; setnode = mxmlFindElement(setnode, subnode, "TevStage", NULL, NULL, MXML_DESCEND)) - { - mxml_node_t *valnode; + for (setnode = mxmlFindElement(subnode, subnode, "TevStage", NULL, NULL, MXML_DESCEND); setnode != NULL; setnode = mxmlFindElement(setnode, subnode, "TevStage", NULL, NULL, MXML_DESCEND)) + { + mxml_node_t *valnode; char tempCoord[256]; valnode=mxmlFindElement(setnode, setnode, "TextureCoordinate", NULL, NULL, MXML_DESCEND); @@ -2478,14 +2487,14 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl flags.flag.ua9++; - fwrite(&chunkUa9, sizeof(chunkUa9), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkUa9); - matSize += sizeof(chunkUa9); - } + fwrite(&chunkUa9, sizeof(chunkUa9), 1, fp); + *fileOffset = *fileOffset + sizeof(chunkUa9); + matSize += sizeof(chunkUa9); + } - 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)) - { + 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++ ) @@ -2508,7 +2517,7 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl strcpy( aop[3] , "GX_AOP_XNOR" ); strcpy( aop[4] , "GX_MAX_ALPHAOP" ); - mxml_node_t *valnode; + mxml_node_t *valnode; char tempCoord[256]; valnode=mxmlFindElement(setnode, setnode, "comp0", NULL, NULL, MXML_DESCEND); @@ -2556,14 +2565,14 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl flags.flag.uaa++; - fwrite(&chunkUaa, sizeof(chunkUaa), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkUaa); - matSize += sizeof(chunkUaa); - } + fwrite(&chunkUaa, sizeof(chunkUaa), 1, fp); + *fileOffset = *fileOffset + sizeof(chunkUaa); + matSize += sizeof(chunkUaa); + } - 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)) - { + 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++ ) @@ -2606,7 +2615,7 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl strcpy( logicop[14] , "GX_LO_NAND" ); strcpy( logicop[15] , "GX_LO_SET" ); - mxml_node_t *valnode; + mxml_node_t *valnode; char tempCoord[256]; valnode=mxmlFindElement(setnode, setnode, "type", NULL, NULL, MXML_DESCEND); @@ -2655,161 +2664,161 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl flags.flag.uab++; - fwrite(&chunkUab, sizeof(chunkUab), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkUab); - matSize += sizeof(chunkUab); - } + 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); + fwrite(&chunk, sizeof(chunk), 1, fp); fseek( fp , end , SEEK_SET ); - if (numberOfEntries < actualNumber) - { - offsets[numberOfEntries] = be32(matSize + initialOffset); - materialOffset = ftell(fp); - fseek(fp, offsetsOffset+(numberOfEntries * sizeof(int)), SEEK_SET); - fwrite(&offsets[numberOfEntries], sizeof(int), 1, fp); - fseek(fp, materialOffset, SEEK_SET); - initialOffset += matSize; - matSize = 0; - } - } - free(offsets); - } - if ( memcmp(temp, pan1, sizeof(pan1)) == 0) - { - brlyt_pane_chunk chunk; - char temp[256]; - if(mxmlElementGetAttr(node, "name") != NULL) - strcpy(temp, mxmlElementGetAttr(node, "name")); - else{ - printf("No name attribute found!\nQuitting!\n"); - exit(1); - } - memset(chunk.name, 0, 24); - strcpy(chunk.name, temp); - - mxml_node_t *subnode = mxmlFindElement(node, node, "translate", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - 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.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.ZTrans = float_swap_bytes(atof(tempCoord)); - } - } - subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - 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.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, "scale", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - 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.YScale = float_swap_bytes(atof(tempCoord)); - } - } - subnode = mxmlFindElement(node, node, "size", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "width", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.width = float_swap_bytes(atof(tempCoord)); - } - valnode = mxmlFindElement(subnode, subnode, "height", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.height = float_swap_bytes(atof(tempCoord)); - } - } - + if (numberOfEntries < actualNumber) + { + offsets[numberOfEntries] = be32(matSize + initialOffset); + materialOffset = ftell(fp); + fseek(fp, offsetsOffset+(numberOfEntries * sizeof(int)), SEEK_SET); + fwrite(&offsets[numberOfEntries], sizeof(int), 1, fp); + fseek(fp, materialOffset, SEEK_SET); + initialOffset += matSize; + matSize = 0; + } + } + free(offsets); + } + if ( memcmp(temp, pan1, sizeof(pan1)) == 0) + { + brlyt_pane_chunk chunk; + char temp[256]; + if(mxmlElementGetAttr(node, "name") != NULL) + strcpy(temp, mxmlElementGetAttr(node, "name")); + else{ + printf("No name attribute found!\nQuitting!\n"); + exit(1); + } + memset(chunk.name, 0, 24); + strcpy(chunk.name, temp); + + mxml_node_t *subnode = mxmlFindElement(node, node, "translate", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + 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.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.ZTrans = float_swap_bytes(atof(tempCoord)); + } + } + subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + 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.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, "scale", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + 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.YScale = float_swap_bytes(atof(tempCoord)); + } + } + subnode = mxmlFindElement(node, node, "size", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "width", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.width = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "height", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.height = float_swap_bytes(atof(tempCoord)); + } + } + 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 ); - } + 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) - { + 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" ); @@ -2822,9 +2831,9 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl strcpy( origins[7] , "BOTTOM CENTER" ); strcpy( origins[8] , "BOTTOM RIGHT" ); - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - chunk.origin = strtol(tempCoord, NULL, 16); + 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 ) { @@ -2832,154 +2841,154 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl break; } } - } - subnode = mxmlFindElement(node, node, "alpha", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - chunk.alpha = strtol(tempCoord, NULL, 16); - } - subnode = mxmlFindElement(node, node, "padding", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - chunk.pad = strtol(tempCoord, NULL, 16); - } - fwrite(&chunk, sizeof(chunk), 1, fp); - *fileOffset = *fileOffset + sizeof(chunk); - } - if ( memcmp(temp, bnd1, sizeof(bnd1)) == 0) - { - brlyt_pane_chunk chunk; - char temp[256]; - if(mxmlElementGetAttr(node, "name") != NULL) - strcpy(temp, mxmlElementGetAttr(node, "name")); - else{ - printf("No name attribute found!\nQuitting!\n"); - exit(1); - } - memset(chunk.name, 0, 24 * sizeof(char)); - strcpy(chunk.name, temp); - - mxml_node_t *subnode = mxmlFindElement(node, node, "translate", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - 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.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.ZTrans = float_swap_bytes(atof(tempCoord)); - } - } - subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - 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.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, "scale", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - 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.YScale = float_swap_bytes(atof(tempCoord)); - } - } - subnode = mxmlFindElement(node, node, "size", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "width", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.width = float_swap_bytes(atof(tempCoord)); - } - valnode = mxmlFindElement(subnode, subnode, "height", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.height = float_swap_bytes(atof(tempCoord)); - } - } - + } + subnode = mxmlFindElement(node, node, "alpha", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + chunk.alpha = strtol(tempCoord, NULL, 16); + } + subnode = mxmlFindElement(node, node, "padding", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + chunk.pad = strtol(tempCoord, NULL, 16); + } + fwrite(&chunk, sizeof(chunk), 1, fp); + *fileOffset = *fileOffset + sizeof(chunk); + } + if ( memcmp(temp, bnd1, sizeof(bnd1)) == 0) + { + brlyt_pane_chunk chunk; + char temp[256]; + if(mxmlElementGetAttr(node, "name") != NULL) + strcpy(temp, mxmlElementGetAttr(node, "name")); + else{ + printf("No name attribute found!\nQuitting!\n"); + exit(1); + } + memset(chunk.name, 0, 24 * sizeof(char)); + strcpy(chunk.name, temp); + + mxml_node_t *subnode = mxmlFindElement(node, node, "translate", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + 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.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.ZTrans = float_swap_bytes(atof(tempCoord)); + } + } + subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + 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.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, "scale", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + 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.YScale = float_swap_bytes(atof(tempCoord)); + } + } + subnode = mxmlFindElement(node, node, "size", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "width", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.width = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "height", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.height = float_swap_bytes(atof(tempCoord)); + } + } + 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 ); - } + 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) - { + 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" ); @@ -2992,9 +3001,9 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl strcpy( origins[7] , "BOTTOM CENTER" ); strcpy( origins[8] , "BOTTOM RIGHT" ); - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - chunk.origin = strtol(tempCoord, NULL, 16); + 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 ) { @@ -3002,154 +3011,154 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl break; } } - } - subnode = mxmlFindElement(node, node, "alpha", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - chunk.alpha = strtol(tempCoord, NULL, 16); - } - subnode = mxmlFindElement(node, node, "padding", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - 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; - char temp[256]; - if(mxmlElementGetAttr(node, "name") != NULL) - strcpy(temp, mxmlElementGetAttr(node, "name")); - else{ - printf("No name attribute found!\nQuitting!\n"); - exit(1); - } - memset(chunk.name, 0, 24 * sizeof(char)); - strcpy(chunk.name, temp); - - mxml_node_t *subnode = mxmlFindElement(node, node, "translate", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - 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.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.ZTrans = float_swap_bytes(atof(tempCoord)); - } - } - subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - 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.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, "scale", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - 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.YScale = float_swap_bytes(atof(tempCoord)); - } - } - subnode = mxmlFindElement(node, node, "size", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "width", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.width = float_swap_bytes(atof(tempCoord)); - } - valnode = mxmlFindElement(subnode, subnode, "height", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.height = float_swap_bytes(atof(tempCoord)); - } - } - + } + subnode = mxmlFindElement(node, node, "alpha", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + chunk.alpha = strtol(tempCoord, NULL, 16); + } + subnode = mxmlFindElement(node, node, "padding", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + 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; + char temp[256]; + if(mxmlElementGetAttr(node, "name") != NULL) + strcpy(temp, mxmlElementGetAttr(node, "name")); + else{ + printf("No name attribute found!\nQuitting!\n"); + exit(1); + } + memset(chunk.name, 0, 24 * sizeof(char)); + strcpy(chunk.name, temp); + + mxml_node_t *subnode = mxmlFindElement(node, node, "translate", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + 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.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.ZTrans = float_swap_bytes(atof(tempCoord)); + } + } + subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + 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.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, "scale", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + 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.YScale = float_swap_bytes(atof(tempCoord)); + } + } + subnode = mxmlFindElement(node, node, "size", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "width", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.width = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "height", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.height = float_swap_bytes(atof(tempCoord)); + } + } + 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 ); - } + 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) - { + 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" ); @@ -3162,9 +3171,9 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl strcpy( origins[7] , "BOTTOM CENTER" ); strcpy( origins[8] , "BOTTOM RIGHT" ); - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - chunk.origin = strtol(tempCoord, NULL, 16); + 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 ) { @@ -3172,304 +3181,304 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl break; } } - } - subnode = mxmlFindElement(node, node, "alpha", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - chunk.alpha = strtol(tempCoord, NULL, 16); - } - subnode = mxmlFindElement(node, node, "padding", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - chunk.pad = strtol(tempCoord, NULL, 16); - } - fwrite(&chunk, sizeof(chunk), 1, fp); - *fileOffset = *fileOffset + sizeof(chunk); - - int i; - brlyt_wnd wndy; - subnode = mxmlFindElement(node, node, "wnd", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - i = 0; - mxml_node_t *subsubnode; - 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.coords[i] = float_swap_bytes(atof(tempCoord)); - i++; - } - subsubnode = mxmlFindElement(subnode, subnode, "FrameCount", NULL, NULL, MXML_DESCEND); - if(subsubnode != NULL) - { - - char tempCoord[256]; - get_value(subsubnode, tempCoord, 256); - wndy.frame_count = (u8)(strtoul(tempCoord, NULL, 16)); - } - wndy.padding[0] = 0x0; - wndy.padding[1] = 0x0; - wndy.padding[2] = 0x0; - - subsubnode = mxmlFindElement(subnode, subnode, "offset1", NULL, NULL, MXML_DESCEND); - if(subsubnode != NULL) - { - - char tempCoord[256]; - get_value(subsubnode, tempCoord, 256); - wndy.offset1 = be32(strtoul(tempCoord, NULL, 16)); - } - subsubnode = mxmlFindElement(subnode, subnode, "offset2", NULL, NULL, MXML_DESCEND); - if(subsubnode != NULL) - { - - char tempCoord[256]; - get_value(subsubnode, tempCoord, 256); - wndy.offset2 = be32(strtoul(tempCoord, NULL, 16)); - } - fwrite(&wndy, sizeof(brlyt_wnd), 1, fp); - *fileOffset = *fileOffset + sizeof(brlyt_wnd); - } - - brlyt_wnd1 wndy1; - subnode = mxmlFindElement(node, node, "wnd1", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - i=0; - mxml_node_t *subsubnode; - 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.colors[i] = be32(strtoul(tempCoord, NULL, 16)); - i++; - } - subsubnode = mxmlFindElement(subnode, subnode, "material", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempCoord[256]; - get_value(subsubnode, tempCoord, 256); - wndy1.material = short_swap_bytes(strtoul(tempCoord, NULL, 16)); - } - subsubnode = mxmlFindElement(subnode, subnode, "CoordinateCount", NULL, NULL, MXML_DESCEND); - if (subsubnode != NULL) - { - char tempCoord[256]; - get_value(subsubnode, tempCoord, 256); - wndy1.coordinate_count = short_swap_bytes(strtoul(tempCoord, NULL, 16)); - } - 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, "Coords", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - i=0; - mxml_node_t *subsubnode; - for(subsubnode = mxmlFindElement(subnode, subnode, "texcoord", NULL, NULL, MXML_DESCEND); subsubnode != NULL; subsubnode = mxmlFindElement(subsubnode, subnode, "texcoord", NULL, NULL, MXML_DESCEND)) - { - char tempCoord[256]; - get_value(subsubnode, tempCoord, 256); - wndy3.texcoords[i] = float_swap_bytes(atof(tempCoord)); - i++; - } - fwrite(&wndy3, sizeof(brlyt_wnd3), 1, fp); - *fileOffset = *fileOffset + sizeof(brlyt_wnd3); - } - - brlyt_wnd4 wndy4; - for(subnode = mxmlFindElement(node, node, "wnd4", NULL, NULL, MXML_DESCEND); subnode != NULL; subnode = mxmlFindElement(subnode, node, "wnd4", NULL, NULL, MXML_DESCEND)) - { - i=0; - mxml_node_t *subsubnode; - subsubnode = mxmlFindElement(subnode, subnode, "offset", NULL, NULL, MXML_DESCEND); - if (subsubnode != NULL) - { - char tempCoord[256]; - get_value(subsubnode, tempCoord, 256); - wndy4.offset = be32(strtoul(tempCoord, NULL, 16)); - i++; - } - fwrite(&wndy4, sizeof(brlyt_wnd4), 1, fp); - *fileOffset = *fileOffset + sizeof(brlyt_wnd4); - } - brlyt_wnd4_mat wndy4mat; - for(subnode = mxmlFindElement(node, node, "wnd4mat", NULL, NULL, MXML_DESCEND); subnode != NULL; subnode = mxmlFindElement(subnode, node, "wnd4mat", NULL, NULL, MXML_DESCEND)) - { - i=0; - mxml_node_t *subsubnode; - subsubnode = mxmlFindElement(subnode, subnode, "material", NULL, NULL, MXML_DESCEND); - if (subsubnode != NULL) - { - char tempCoord[256]; - get_value(subsubnode, tempCoord, 256); - 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); - } - } - if ( memcmp(temp, txt1, sizeof(txt1)) == 0) - { - brlyt_pane_chunk chunk; - brlyt_text_chunk chunk2; - char temp[256]; - if(mxmlElementGetAttr(node, "name") != NULL) - strcpy(temp, mxmlElementGetAttr(node, "name")); - else{ - printf("No name attribute found!\nQuitting!\n"); - exit(1); - } - memset(chunk.name, 0, 24 * sizeof(char)); - strcpy(chunk.name, temp); - chunk2.mat_num = short_swap_bytes(findMatOffset(temp)); - - mxml_node_t *subnode = mxmlFindElement(node, node, "translate", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - 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.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.ZTrans = float_swap_bytes(atof(tempCoord)); - } - } - subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - 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.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, "scale", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - 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.YScale = float_swap_bytes(atof(tempCoord)); - } - } - subnode = mxmlFindElement(node, node, "size", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "width", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.width = float_swap_bytes(atof(tempCoord)); - } - valnode = mxmlFindElement(subnode, subnode, "height", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.height = float_swap_bytes(atof(tempCoord)); - } - } - + } + subnode = mxmlFindElement(node, node, "alpha", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + chunk.alpha = strtol(tempCoord, NULL, 16); + } + subnode = mxmlFindElement(node, node, "padding", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + chunk.pad = strtol(tempCoord, NULL, 16); + } + fwrite(&chunk, sizeof(chunk), 1, fp); + *fileOffset = *fileOffset + sizeof(chunk); + + int i; + brlyt_wnd wndy; + subnode = mxmlFindElement(node, node, "wnd", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + i = 0; + mxml_node_t *subsubnode; + 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.coords[i] = float_swap_bytes(atof(tempCoord)); + i++; + } + subsubnode = mxmlFindElement(subnode, subnode, "FrameCount", NULL, NULL, MXML_DESCEND); + if(subsubnode != NULL) + { + + char tempCoord[256]; + get_value(subsubnode, tempCoord, 256); + wndy.frame_count = (u8)(strtoul(tempCoord, NULL, 16)); + } + wndy.padding[0] = 0x0; + wndy.padding[1] = 0x0; + wndy.padding[2] = 0x0; + + subsubnode = mxmlFindElement(subnode, subnode, "offset1", NULL, NULL, MXML_DESCEND); + if(subsubnode != NULL) + { + + char tempCoord[256]; + get_value(subsubnode, tempCoord, 256); + wndy.offset1 = be32(strtoul(tempCoord, NULL, 16)); + } + subsubnode = mxmlFindElement(subnode, subnode, "offset2", NULL, NULL, MXML_DESCEND); + if(subsubnode != NULL) + { + + char tempCoord[256]; + get_value(subsubnode, tempCoord, 256); + wndy.offset2 = be32(strtoul(tempCoord, NULL, 16)); + } + fwrite(&wndy, sizeof(brlyt_wnd), 1, fp); + *fileOffset = *fileOffset + sizeof(brlyt_wnd); + } + + brlyt_wnd1 wndy1; + subnode = mxmlFindElement(node, node, "wnd1", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + i=0; + mxml_node_t *subsubnode; + 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.colors[i] = be32(strtoul(tempCoord, NULL, 16)); + i++; + } + subsubnode = mxmlFindElement(subnode, subnode, "material", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subsubnode, tempCoord, 256); + wndy1.material = short_swap_bytes(strtoul(tempCoord, NULL, 16)); + } + subsubnode = mxmlFindElement(subnode, subnode, "CoordinateCount", NULL, NULL, MXML_DESCEND); + if (subsubnode != NULL) + { + char tempCoord[256]; + get_value(subsubnode, tempCoord, 256); + wndy1.coordinate_count = short_swap_bytes(strtoul(tempCoord, NULL, 16)); + } + 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, "Coords", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + i=0; + mxml_node_t *subsubnode; + for(subsubnode = mxmlFindElement(subnode, subnode, "texcoord", NULL, NULL, MXML_DESCEND); subsubnode != NULL; subsubnode = mxmlFindElement(subsubnode, subnode, "texcoord", NULL, NULL, MXML_DESCEND)) + { + char tempCoord[256]; + get_value(subsubnode, tempCoord, 256); + wndy3.texcoords[i] = float_swap_bytes(atof(tempCoord)); + i++; + } + fwrite(&wndy3, sizeof(brlyt_wnd3), 1, fp); + *fileOffset = *fileOffset + sizeof(brlyt_wnd3); + } + + brlyt_wnd4 wndy4; + for(subnode = mxmlFindElement(node, node, "wnd4", NULL, NULL, MXML_DESCEND); subnode != NULL; subnode = mxmlFindElement(subnode, node, "wnd4", NULL, NULL, MXML_DESCEND)) + { + i=0; + mxml_node_t *subsubnode; + subsubnode = mxmlFindElement(subnode, subnode, "offset", NULL, NULL, MXML_DESCEND); + if (subsubnode != NULL) + { + char tempCoord[256]; + get_value(subsubnode, tempCoord, 256); + wndy4.offset = be32(strtoul(tempCoord, NULL, 16)); + i++; + } + fwrite(&wndy4, sizeof(brlyt_wnd4), 1, fp); + *fileOffset = *fileOffset + sizeof(brlyt_wnd4); + } + brlyt_wnd4_mat wndy4mat; + for(subnode = mxmlFindElement(node, node, "wnd4mat", NULL, NULL, MXML_DESCEND); subnode != NULL; subnode = mxmlFindElement(subnode, node, "wnd4mat", NULL, NULL, MXML_DESCEND)) + { + i=0; + mxml_node_t *subsubnode; + subsubnode = mxmlFindElement(subnode, subnode, "material", NULL, NULL, MXML_DESCEND); + if (subsubnode != NULL) + { + char tempCoord[256]; + get_value(subsubnode, tempCoord, 256); + 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); + } + } + if ( memcmp(temp, txt1, sizeof(txt1)) == 0) + { + brlyt_pane_chunk chunk; + brlyt_text_chunk chunk2; + char temp[256]; + if(mxmlElementGetAttr(node, "name") != NULL) + strcpy(temp, mxmlElementGetAttr(node, "name")); + else{ + printf("No name attribute found!\nQuitting!\n"); + exit(1); + } + memset(chunk.name, 0, 24 * sizeof(char)); + strcpy(chunk.name, temp); + chunk2.mat_num = short_swap_bytes(findMatOffset(temp)); + + mxml_node_t *subnode = mxmlFindElement(node, node, "translate", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + 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.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.ZTrans = float_swap_bytes(atof(tempCoord)); + } + } + subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + 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.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, "scale", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + 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.YScale = float_swap_bytes(atof(tempCoord)); + } + } + subnode = mxmlFindElement(node, node, "size", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "width", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.width = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "height", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.height = float_swap_bytes(atof(tempCoord)); + } + } + 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 ); - } + 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) - { + 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" ); @@ -3482,9 +3491,9 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl strcpy( origins[7] , "BOTTOM CENTER" ); strcpy( origins[8] , "BOTTOM RIGHT" ); - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - chunk.origin = strtol(tempCoord, NULL, 16); + 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 ) { @@ -3492,67 +3501,67 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl break; } } - } - subnode = mxmlFindElement(node, node, "alpha", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - chunk.alpha = strtol(tempCoord, NULL, 16); - } - subnode = mxmlFindElement(node, node, "padding", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - chunk.pad = strtol(tempCoord, NULL, 16); - } - - subnode = mxmlFindElement(node, node, "font", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char temp[256]; - if(mxmlElementGetAttr(subnode, "index") != NULL) - strcpy(temp, mxmlElementGetAttr(subnode, "index")); - else{ - printf("No index attribute found!\nQuitting!\n"); - exit(1); - } - chunk2.font_idx = atoi(temp); - chunk2.font_idx = short_swap_bytes(chunk2.font_idx); - - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "xsize", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk2.font_size_x = float_swap_bytes(atof(tempCoord)); - } - valnode = mxmlFindElement(subnode, subnode, "ysize", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk2.font_size_y = float_swap_bytes(atof(tempCoord)); - } - valnode = mxmlFindElement(subnode, subnode, "charsize", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk2.char_space = float_swap_bytes(atof(tempCoord)); - } - valnode = mxmlFindElement(subnode, subnode, "linesize", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk2.line_space = float_swap_bytes(atof(tempCoord)); - } - valnode = mxmlFindElement(subnode, subnode, "alignment", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { + } + subnode = mxmlFindElement(node, node, "alpha", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + chunk.alpha = strtol(tempCoord, NULL, 16); + } + subnode = mxmlFindElement(node, node, "padding", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + chunk.pad = strtol(tempCoord, NULL, 16); + } + + subnode = mxmlFindElement(node, node, "font", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char temp[256]; + if(mxmlElementGetAttr(subnode, "index") != NULL) + strcpy(temp, mxmlElementGetAttr(subnode, "index")); + else{ + printf("No index attribute found!\nQuitting!\n"); + exit(1); + } + chunk2.font_idx = atoi(temp); + chunk2.font_idx = short_swap_bytes(chunk2.font_idx); + + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "xsize", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk2.font_size_x = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "ysize", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk2.font_size_y = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "charsize", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk2.char_space = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "linesize", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk2.line_space = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "alignment", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { char alignments[9][15]; memset( alignments , 0 , 8 * 20 ); strcpy( alignments[0] , "TOP LEFT" ); @@ -3575,200 +3584,200 @@ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* bl break; } } - } - } - - subnode = mxmlFindElement(node, node, "length", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - chunk2.len1 = strtoul(tempCoord, NULL, 16); - chunk2.len1 = short_swap_bytes(chunk2.len1); - chunk2.len2 = strtoul(tempCoord+5, NULL, 16); - chunk2.len2 = short_swap_bytes(chunk2.len2); - } - 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)); - } - 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)); + } + } + + subnode = mxmlFindElement(node, node, "length", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + chunk2.len1 = strtoul(tempCoord, NULL, 16); + chunk2.len1 = short_swap_bytes(chunk2.len1); + chunk2.len2 = strtoul(tempCoord+5, NULL, 16); + chunk2.len2 = short_swap_bytes(chunk2.len2); + } + 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)); + } + 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)); u8 texty[textyLength + 1]; u8 tempy[textyLength*2]; - subnode = mxmlFindElement(node, node, "text", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - u8 tempCoord[8184]; - get_value(subnode, tempCoord, 8184); - memcpy(tempy, tempCoord, short_swap_bytes(chunk2.len2)*2); - u32 w; for (w=0;w 2) - { - printf("Unknown file extension\n"); - exit(1); - } - } - - int brlanargread; - int brlytargread; - int brlanargmake; - int brlytargmake; - int brlanargdestmake; - int brlytargdestmake; - int reqargs; - int currentarg = 2; - char helpstrmake[256]; - char helpstrread[256]; - sprintf(helpstrmake, "%s m", argv[0]); - sprintf(helpstrread, "%s r", argv[0]); -if(type == 2) -{ - brlanargread = currentarg; - strcat(helpstrread, " <*.brlan>"); - brlanargmake = currentarg++; - strcat(helpstrmake, " <*.xmlan>"); -} -if(type == 1) -{ - brlytargread = currentarg; - strcat(helpstrread, " <*.brlyt>"); - brlytargmake = currentarg++; - strcat(helpstrmake, " <*.xmlyt>"); -} - reqargs = currentarg; -if(type == 2) -{ - brlanargdestmake = currentarg++; - strcat(helpstrmake, " "); -} -if(type == 1) -{ - brlytargdestmake = currentarg++; - strcat(helpstrmake, " "); -} + u8 type = 3; + char *ext; - printf(INFORMATION_TEXT); - if(argc < reqargs) { - printf("Invalid arguments. Use like:\n\t%s\n\t\tor:\n\t%s\n", helpstrread, helpstrmake); - exit(1); - } - if((argv[1][0] == 'r') || (argv[1][0] == 'p')) { -if(type == 2) -{ - parse_brlan(argv[brlanargread], argv[3]); -} -if(type == 1) -{ - parse_brlyt(argv[brlytargread], argv[3]); -} - }else if((argv[1][0] == 'm') || (argv[1][0] == 'w')) { -if(type == 2) -{ - make_brlan(argv[brlanargmake], argv[brlanargdestmake]); -} -if(type == 1) -{ - make_brlyt(argv[brlytargmake], argv[brlytargdestmake]); -} - } - return 0; + if (argc < 4) + { + printf("Please use ./benzin r brlytfilename.brlyt xmlytfilename.xmlyt\n"); + printf(" - OR - \n"); + printf("Please use ./benzin m xmlytfilename.xmlyt brlytfilename.brlyt\n"); + exit(1); + } + + if ((strcmp(argv[1], "r") == 0) || (strcmp(argv[1], "p") == 0) || (strcmp(argv[1], "m") == 0) || (strcmp(argv[1], "w") == 0)) + { + ext = strrchr(argv[2], '.'); + } else { + printf("Please use ./benzin r brlytfilename.brlyt xmlytfilename.xmlyt\n"); + printf(" - OR - \n"); + printf("Please use ./benzin m xmlytfilename.xmlyt brlytfilename.brlyt\n"); + exit(1); + } + + if(!ext) + { + printf("No extension on file\n"); + printf("To see possible arguments type ./benzin\n"); + exit(1); + } else { + char* temp = ext; + if(strcmp(++ext, "brlyt") == 0) + { + type = 1; + } + ext = temp; + if(strcmp(++ext, "brlan") == 0) + { + type = 2; + } + if(type > 2) + { + printf("Unknown file extension\n"); + exit(1); + } + } + + int brlanargread; + int brlytargread; + int brlanargmake; + int brlytargmake; + int brlanargdestmake; + int brlytargdestmake; + int brlanargdestread; + int brlytargdestread; + int currentarg = 2; + + if(type == 1) + { + brlytargread = currentarg; + brlytargmake = currentarg++; + brlytargdestread = currentarg; + brlytargdestmake = currentarg++; + } + if(type == 2) + { + brlanargread = currentarg; + brlanargmake = currentarg++; + brlanargdestread = currentarg; + brlanargdestmake = currentarg++; + } + + printf(INFORMATION_TEXT); + + if((argv[1][0] == 'r') || (argv[1][0] == 'p')) { + if(type == 1) + parse_brlyt(argv[brlytargread], argv[brlytargdestread]); + + if(type == 2) + parse_brlan(argv[brlanargread], argv[brlanargdestread]); + + } else if( (argv[1][0] == 'm') || (argv[1][0] == 'w') ) { + if(type == 1) + make_brlyt(argv[brlytargmake], argv[brlytargdestmake]); + + if(type == 2) + make_brlan(argv[brlanargmake], argv[brlanargdestmake]); + + } + return 0; } diff --git a/types.h b/types.h index 43d21b3..956584b 100755 --- a/types.h +++ b/types.h @@ -17,6 +17,15 @@ typedef signed short s16; typedef signed int s32; typedef signed long long s64; +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long uint64_t; +typedef signed char int8_t; +typedef signed short int16_t; +typedef signed int int32_t; +typedef signed long long int64_t; + typedef float f32; typedef double f64; -- cgit v1.3.1 From 30d7029aa7e0da4f85284bb0e2a017823f53f842 Mon Sep 17 00:00:00 2001 From: megazig Date: Sun, 20 Sep 2009 14:20:55 -0500 Subject: fixed stupid vtx issue --- brlyt.c | 8 ++++---- xml.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/brlyt.c b/brlyt.c index 6a6fdb9..2f0b483 100644 --- a/brlyt.c +++ b/brlyt.c @@ -550,13 +550,13 @@ void PrintBRLYTEntry_pic1(brlyt_entry entry, u8* brlyt_file, mxml_node_t *tag) int n; for (n=0;n<4;n++) { vtx = mxmlNewElement(color, "vtx"); - attr = mxmlNewElement(color, "red"); + attr = mxmlNewElement(vtx, "red"); mxmlNewTextf( attr , 0 , "%02x" , ( be32(data2.vtx_colors[n]) >> 24 ) & 0xff ); - attr = mxmlNewElement(color, "red"); + attr = mxmlNewElement(vtx, "green"); mxmlNewTextf( attr , 0 , "%02x" , ( be32(data2.vtx_colors[n]) >> 16 ) & 0xff ); - attr = mxmlNewElement(color, "red"); + attr = mxmlNewElement(vtx, "blue"); mxmlNewTextf( attr , 0 , "%02x" , ( be32(data2.vtx_colors[n]) >> 8 ) & 0xff ); - attr = mxmlNewElement(color, "red"); + attr = mxmlNewElement(vtx, "alpha"); mxmlNewTextf( attr , 0 , "%02x" , ( be32(data2.vtx_colors[n]) >> 0 ) & 0xff ); } diff --git a/xml.c b/xml.c index 80709df..bb0e067 100644 --- a/xml.c +++ b/xml.c @@ -91,7 +91,7 @@ const char *whitespace_cb(mxml_node_t *node, int where) } if (where == 3 || where == 1){ return ""; - }else if(((node->prev && where == 0) || node->parent) && !(where == 2 && strncmp(name, "ua", 2) && strcmp(name, "rotate") && strcmp(name, "scale") && strcmp(name, "translate") && strcmp(name, "entries") && strcmp(name, "xmlyt") && strcmp(name, "xmlan") && strcmp(name, "entries") && strcmp(name, "triplet") && strcmp(name, "pair") && strcmp(name, "entry") && strcmp(name, "pane") && (strcmp(name, "tag") && strcmp(name, "size") && strcmp(name, "material") && strcmp(name, "colors") && strcmp(name, "subs") && strcmp(name, "font") && strcmp(name, "wnd4") && strcmp(name, "wnd4mat") && strcmp(name, "set") && strcmp(name, "coordinates") && strcmp(name, "TevStage") && strcmp(name, "texture") && strcmp(name, "TextureSRT") && strcmp(name, "CoordGen") && strcmp(name, "ChanControl") && strcmp(name, "MaterialColor") && strcmp(name, "TevSwapModeTable") && strcmp(name, "IndTextureSRT") && strcmp(name, "IndTextureOrder") && strcmp(name, "AlphaCompare") && strcmp(name, "BlendMode") )) ){ + }else if(((node->prev && where == 0) || node->parent) && !(where == 2 && strncmp(name, "ua", 2) && strcmp(name, "rotate") && strcmp(name, "scale") && strcmp(name, "translate") && strcmp(name, "entries") && strcmp(name, "xmlyt") && strcmp(name, "xmlan") && strcmp(name, "entries") && strcmp(name, "triplet") && strcmp(name, "pair") && strcmp(name, "entry") && strcmp(name, "pane") && (strcmp(name, "tag") && strcmp(name, "size") && strcmp(name, "material") && strcmp(name, "vtx") && strcmp(name, "colors") && strcmp(name, "subs") && strcmp(name, "font") && strcmp(name, "wnd4") && strcmp(name, "wnd4mat") && strcmp(name, "set") && strcmp(name, "coordinates") && strcmp(name, "TevStage") && strcmp(name, "texture") && strcmp(name, "TextureSRT") && strcmp(name, "CoordGen") && strcmp(name, "ChanControl") && strcmp(name, "MaterialColor") && strcmp(name, "TevSwapModeTable") && strcmp(name, "IndTextureSRT") && strcmp(name, "IndTextureOrder") && strcmp(name, "AlphaCompare") && strcmp(name, "BlendMode") )) ){ //sprintf(xmlbuff, "\n%*s", (depth-1)*4 , ""); //sprintf(xmlbuff, "\n%*s", (depth)*4 , "\t"); sprintf( xmlbuff , "\n%s" , tab_buffer ); -- cgit v1.3.1