diff options
| -rw-r--r-- | brlan.c | 2390 | ||||
| -rwxr-xr-x | brlan.h | 115 | ||||
| -rw-r--r-- | brlyt.c | 4480 | ||||
| -rw-r--r-- | brlyt.h | 140 | ||||
| -rwxr-xr-x | endian.c | 6 | ||||
| -rwxr-xr-x | endian.h | 6 | ||||
| -rw-r--r-- | ethyl.py | 40 | ||||
| -rw-r--r-- | general.h | 94 | ||||
| -rw-r--r-- | main.c | 84 | ||||
| -rw-r--r-- | memfile.c | 112 | ||||
| -rw-r--r-- | memfile.h | 28 | ||||
| -rw-r--r-- | parse-brlan.py | 67 | ||||
| -rw-r--r-- | xml.c | 120 | ||||
| -rwxr-xr-x | xml.h | 8 |
14 files changed, 3850 insertions, 3840 deletions
@@ -20,13 +20,13 @@ #include "xml.h" #if DEBUGBRLAN == 1 -#define dbgprintf printf +#define dbgprintf printf #else -#define dbgprintf // +#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" }; @@ -40,1309 +40,1309 @@ u8 somethingIsSet = 0; 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) + 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->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)); } 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 < 6; i++) - if(FourCCsMatch(cc, tag_FourCCs[i])) return 1; - return 0; + int i; + for(i = 0; i < 6; i++) + if(FourCCsMatch(cc, tag_FourCCs[i])) return 1; + return 0; } void parse_brlan(char* filename) { - 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); + 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; - for(i = 0; i < 16; i++) - memset(tag_types_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], "0x03"); - strcpy(tag_types_list[4], "0x04"); - 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"); + int i; + for(i = 0; i < 16; i++) + memset(tag_types_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], "0x03"); + strcpy(tag_types_list[4], "0x04"); + 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"); - BRLAN_fileoffset = 0; - brlan_header header; - BRLAN_ReadDataFromMemoryX(&header, data, sizeof(brlan_header)); - dbgprintf("brlan_header read to.\n"); - BRLAN_fileoffset = short_swap_bytes(header.pai1_offset); - brlan_pai1_universal universal; - BRLAN_ReadDataFromMemoryX(&universal, data, sizeof(brlan_pai1_universal)); - dbgprintf("pa1_universal read to.\n"); - - int pai1_header_type; - brlan_pai1_header_type1 pai1_header1; - brlan_pai1_header_type2 pai1_header2; - brlan_pai1_header_type2 pai1_header; + BRLAN_fileoffset = 0; + brlan_header header; + BRLAN_ReadDataFromMemoryX(&header, data, sizeof(brlan_header)); + dbgprintf("brlan_header read to.\n"); + BRLAN_fileoffset = short_swap_bytes(header.pai1_offset); + brlan_pai1_universal universal; + BRLAN_ReadDataFromMemoryX(&universal, data, sizeof(brlan_pai1_universal)); + dbgprintf("pa1_universal read to.\n"); + + 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)); - } + 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); + CreateGlobal_pai1(&pai1_header, pai1_header1, pai1_header2, pai1_header_type); - printf("<?xml version=\"1.0\"?>\n" \ - "<xmlan framesize=\"%lu\" flags=\"%02x\">\n", (long unsigned int)short_swap_bytes(pai1_header.framesize), pai1_header.flags); + printf("<?xml version=\"1.0\"?>\n" \ + "<xmlan framesize=\"%lu\" flags=\"%02x\">\n", (long unsigned int)short_swap_bytes(pai1_header.framesize), pai1_header.flags); - int timgs = short_swap_bytes(pai1_header.num_timgs); -// printf("Number of TPL files: %d\n", timgs); + int timgs = short_swap_bytes(pai1_header.num_timgs); +// printf("Number of TPL files: %d\n", 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; + 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; - 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); - int o; - for(o = 0; data[z] != 0; timgname[o++] = data[z], z++); - printf("\t<timg name=\"%s\" />\n", timgname); - currtableoff += 4; - } + 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); + int o; + for(o = 0; data[z] != 0; timgname[o++] = data[z], z++); + printf("\t<timg name=\"%s\" />\n", 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)); + 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++) { - u8 isTriplet = 0; - brlan_entry brlanEntry; - tag_header tagHeader; - tag_entry tagEntry; - tag_entryinfo tagEntryInfo; - BRLAN_fileoffset = be32(taglocations[i]) + short_swap_bytes(header.pai1_offset); - u32 brlanEntryOffset = BRLAN_fileoffset; - BRLAN_ReadDataFromMemory(&brlanEntry, data, sizeof(brlan_entry)); + for(i = 0; i < tagcount; i++) { + u8 isTriplet = 0; + brlan_entry brlanEntry; + tag_header tagHeader; + tag_entry tagEntry; + tag_entryinfo tagEntryInfo; + BRLAN_fileoffset = be32(taglocations[i]) + short_swap_bytes(header.pai1_offset); + u32 brlanEntryOffset = BRLAN_fileoffset; + BRLAN_ReadDataFromMemory(&brlanEntry, data, sizeof(brlan_entry)); - u32 offsetToExtras; - u32 offsetToOther; - if(((be32(brlanEntry.flags) & (1 << 24)) >= 1 ) && ((be32(brlanEntry.flags) & (1<<25)) >=1)) { - somethingElseIsSet = 1; - somethingIsSet = 1; - BRLAN_ReadDataFromMemory(&offsetToOther, data, 4); - BRLAN_ReadDataFromMemory(&offsetToExtras, data, 4); - }else if((be32(brlanEntry.flags) & (1 << 25)) >= 1) { - somethingIsSet = 1; - BRLAN_ReadDataFromMemory(&offsetToExtras, data, 4); - } + u32 offsetToExtras; + u32 offsetToOther; + if(((be32(brlanEntry.flags) & (1 << 24)) >= 1 ) && ((be32(brlanEntry.flags) & (1<<25)) >=1)) { + somethingElseIsSet = 1; + somethingIsSet = 1; + BRLAN_ReadDataFromMemory(&offsetToOther, data, 4); + BRLAN_ReadDataFromMemory(&offsetToExtras, data, 4); + }else if((be32(brlanEntry.flags) & (1 << 25)) >= 1) { + somethingIsSet = 1; + BRLAN_ReadDataFromMemory(&offsetToExtras, data, 4); + } - if ((be32(brlanEntry.flags) | 0x00000000 ) == 0 ) - { - printf("\t<mvit name=\"%s\" />\n", brlanEntry.name); - continue; - } + if ((be32(brlanEntry.flags) | 0x00000000 ) == 0 ) + { + printf("\t<mvit name=\"%s\" />\n", brlanEntry.name); + continue; + } - if (somethingElseIsSet == 1) - { - BRLAN_ReadDataFromMemory(&tagHeader, data, sizeof(tag_header)); - printf("\t<tag name=\"%s\" type=\"%c%c%c%c\" ", brlanEntry.name, tagHeader.magic[0], tagHeader.magic[1], tagHeader.magic[2], tagHeader.magic[3]); - printf("format=\"%08x\">\n", be32(brlanEntry.flags)); - u32 startOfEntries = BRLAN_fileoffset; - u32 sOE = startOfEntries; - u32 j; - for(j=0;j<tagHeader.entry_count;j++) - { - BRLAN_ReadDataFromMemory(&tagEntry, data, sizeof(tag_entry)); - memcpy(&tagEntryInfo, &data[sOE - 8 + be32(tagEntry.offset)], sizeof(tag_entryinfo)); - if(short_swap_bytes(tagEntryInfo.type) < 16) - printf("\t\t<entry type=\"%s\">\n", tag_types_list[short_swap_bytes(tagEntryInfo.type)]); - else - printf("\t\t<entry type=\"%u\">\n", short_swap_bytes(tagEntryInfo.type)); - if ( tagEntryInfo.unk1 == short_swap_bytes(0x0200) ) isTriplet = 1; - int k; for(k=0;k<short_swap_bytes(tagEntryInfo.coord_count);k++) - { - if ( isTriplet == 1 ) - { - tag_data tagData; - memcpy(&tagData, &data[sOE - 8 + be32(tagEntry.offset) + sizeof(tag_entryinfo)+ (k*sizeof(tag_data))], sizeof(tag_data)); + if (somethingElseIsSet == 1) + { + BRLAN_ReadDataFromMemory(&tagHeader, data, sizeof(tag_header)); + printf("\t<tag name=\"%s\" type=\"%c%c%c%c\" ", brlanEntry.name, tagHeader.magic[0], tagHeader.magic[1], tagHeader.magic[2], tagHeader.magic[3]); + printf("format=\"%08x\">\n", be32(brlanEntry.flags)); + u32 startOfEntries = BRLAN_fileoffset; + u32 sOE = startOfEntries; + u32 j; + for(j=0;j<tagHeader.entry_count;j++) + { + BRLAN_ReadDataFromMemory(&tagEntry, data, sizeof(tag_entry)); + memcpy(&tagEntryInfo, &data[sOE - 8 + be32(tagEntry.offset)], sizeof(tag_entryinfo)); + if(short_swap_bytes(tagEntryInfo.type) < 16) + printf("\t\t<entry type=\"%s\">\n", tag_types_list[short_swap_bytes(tagEntryInfo.type)]); + else + printf("\t\t<entry type=\"%u\">\n", short_swap_bytes(tagEntryInfo.type)); + if ( tagEntryInfo.unk1 == short_swap_bytes(0x0200) ) isTriplet = 1; + int k; for(k=0;k<short_swap_bytes(tagEntryInfo.coord_count);k++) + { + if ( isTriplet == 1 ) + { + tag_data tagData; + memcpy(&tagData, &data[sOE - 8 + be32(tagEntry.offset) + sizeof(tag_entryinfo)+ (k*sizeof(tag_data))], sizeof(tag_data)); - u32 p1 = be32(tagData.part1); - u32 p2 = be32(tagData.part2); - u32 p3 = be32(tagData.part3); - printf("\t\t\t<triplet>\n"); - printf("\t\t\t\t<frame>%.15f</frame>\n", *(f32*)(&p1)); - printf("\t\t\t\t<value>%.15f</value>\n", *(f32*)(&p2)); - printf("\t\t\t\t<blend>%.15f</blend>\n", *(f32*)(&p3)); - printf("\t\t\t</triplet>\n"); - - } else { - tag_data2 tagData2; - memcpy(&tagData2, &data[sOE -8+ be32(tagEntry.offset) + sizeof(tag_entryinfo)+ (k*sizeof(tag_data2))], sizeof(tag_data2)); - u32 p1 = be32(tagData2.part1); - u16 p2 = short_swap_bytes(tagData2.part2); - u16 p3 = short_swap_bytes(tagData2.padding); - printf("\t\t\t<pair>\n"); - printf("\t\t\t\t<data1>%.15f</data1>\n", *(f32*)(&p1)); - printf("\t\t\t\t<data2>%04x</data2>\n", p2); - printf("\t\t\t\t<padding>%04x</padding>\n", p3); - printf("\t\t\t</pair>\n"); + u32 p1 = be32(tagData.part1); + u32 p2 = be32(tagData.part2); + u32 p3 = be32(tagData.part3); + printf("\t\t\t<triplet>\n"); + printf("\t\t\t\t<frame>%.15f</frame>\n", *(f32*)(&p1)); + printf("\t\t\t\t<value>%.15f</value>\n", *(f32*)(&p2)); + printf("\t\t\t\t<blend>%.15f</blend>\n", *(f32*)(&p3)); + printf("\t\t\t</triplet>\n"); + + } else { + tag_data2 tagData2; + memcpy(&tagData2, &data[sOE -8+ be32(tagEntry.offset) + sizeof(tag_entryinfo)+ (k*sizeof(tag_data2))], sizeof(tag_data2)); + u32 p1 = be32(tagData2.part1); + u16 p2 = short_swap_bytes(tagData2.part2); + u16 p3 = short_swap_bytes(tagData2.padding); + printf("\t\t\t<pair>\n"); + printf("\t\t\t\t<data1>%.15f</data1>\n", *(f32*)(&p1)); + printf("\t\t\t\t<data2>%04x</data2>\n", p2); + printf("\t\t\t\t<padding>%04x</padding>\n", p3); + printf("\t\t\t</pair>\n"); - } - } - printf("\t\t</entry>\n"); - isTriplet = 0; - } - printf("\t</tag>\n"); + } + } + printf("\t\t</entry>\n"); + isTriplet = 0; + } + printf("\t</tag>\n"); - BRLAN_fileoffset = brlanEntryOffset + be32(offsetToOther); - BRLAN_ReadDataFromMemory(&tagHeader, data, sizeof(tag_header)); - printf("\t<monkey type=\"%c%c%c%c\">\n", tagHeader.magic[0], tagHeader.magic[1], tagHeader.magic[2], tagHeader.magic[3]); - startOfEntries = BRLAN_fileoffset; - sOE = startOfEntries; - - for(j=0;j<tagHeader.entry_count;j++) - { - BRLAN_ReadDataFromMemory(&tagEntry, data, sizeof(tag_entry)); - memcpy(&tagEntryInfo, &data[sOE - 8 + be32(tagEntry.offset)], sizeof(tag_entryinfo)); - if(short_swap_bytes(tagEntryInfo.type) < 16) - printf("\t\t<entry type=\"%s\">\n", tag_types_list[short_swap_bytes(tagEntryInfo.type)]); - else - printf("\t\t<entry type=\"%u\">\n", short_swap_bytes(tagEntryInfo.type)); - if ( tagEntryInfo.unk1 == short_swap_bytes(0x0200) ) isTriplet = 1; - int k; for(k=0;k<short_swap_bytes(tagEntryInfo.coord_count);k++) - { - if ( isTriplet == 1 ) - { - tag_data tagData; - memcpy(&tagData, &data[sOE - 8 + be32(tagEntry.offset) + sizeof(tag_entryinfo)+ (k*sizeof(tag_data))], sizeof(tag_data)); + BRLAN_fileoffset = brlanEntryOffset + be32(offsetToOther); + BRLAN_ReadDataFromMemory(&tagHeader, data, sizeof(tag_header)); + printf("\t<monkey type=\"%c%c%c%c\">\n", tagHeader.magic[0], tagHeader.magic[1], tagHeader.magic[2], tagHeader.magic[3]); + startOfEntries = BRLAN_fileoffset; + sOE = startOfEntries; + + for(j=0;j<tagHeader.entry_count;j++) + { + BRLAN_ReadDataFromMemory(&tagEntry, data, sizeof(tag_entry)); + memcpy(&tagEntryInfo, &data[sOE - 8 + be32(tagEntry.offset)], sizeof(tag_entryinfo)); + if(short_swap_bytes(tagEntryInfo.type) < 16) + printf("\t\t<entry type=\"%s\">\n", tag_types_list[short_swap_bytes(tagEntryInfo.type)]); + else + printf("\t\t<entry type=\"%u\">\n", short_swap_bytes(tagEntryInfo.type)); + if ( tagEntryInfo.unk1 == short_swap_bytes(0x0200) ) isTriplet = 1; + int k; for(k=0;k<short_swap_bytes(tagEntryInfo.coord_count);k++) + { + if ( isTriplet == 1 ) + { + tag_data tagData; + memcpy(&tagData, &data[sOE - 8 + be32(tagEntry.offset) + sizeof(tag_entryinfo)+ (k*sizeof(tag_data))], sizeof(tag_data)); - u32 p1 = be32(tagData.part1); - u32 p2 = be32(tagData.part2); - u32 p3 = be32(tagData.part3); - printf("\t\t\t<triplet>\n"); - printf("\t\t\t\t<frame>%.15f</frame>\n", *(f32*)(&p1)); - printf("\t\t\t\t<value>%.15f</value>\n", *(f32*)(&p2)); - printf("\t\t\t\t<blend>%.15f</blend>\n", *(f32*)(&p3)); - printf("\t\t\t</triplet>\n"); - - } else { - tag_data2 tagData2; - memcpy(&tagData2, &data[sOE -8+ be32(tagEntry.offset) + sizeof(tag_entryinfo)+ (k*sizeof(tag_data2))], sizeof(tag_data2)); - u32 p1 = be32(tagData2.part1); - u16 p2 = short_swap_bytes(tagData2.part2); - u16 p3 = short_swap_bytes(tagData2.padding); - printf("\t\t\t<pair>\n"); - printf("\t\t\t\t<data1>%.15f</data1>\n", *(f32*)(&p1)); - printf("\t\t\t\t<data2>%04x</data2>\n", p2); - printf("\t\t\t\t<padding>%04x</padding>\n", p3); - printf("\t\t\t</pair>\n"); + u32 p1 = be32(tagData.part1); + u32 p2 = be32(tagData.part2); + u32 p3 = be32(tagData.part3); + printf("\t\t\t<triplet>\n"); + printf("\t\t\t\t<frame>%.15f</frame>\n", *(f32*)(&p1)); + printf("\t\t\t\t<value>%.15f</value>\n", *(f32*)(&p2)); + printf("\t\t\t\t<blend>%.15f</blend>\n", *(f32*)(&p3)); + printf("\t\t\t</triplet>\n"); + + } else { + tag_data2 tagData2; + memcpy(&tagData2, &data[sOE -8+ be32(tagEntry.offset) + sizeof(tag_entryinfo)+ (k*sizeof(tag_data2))], sizeof(tag_data2)); + u32 p1 = be32(tagData2.part1); + u16 p2 = short_swap_bytes(tagData2.part2); + u16 p3 = short_swap_bytes(tagData2.padding); + printf("\t\t\t<pair>\n"); + printf("\t\t\t\t<data1>%.15f</data1>\n", *(f32*)(&p1)); + printf("\t\t\t\t<data2>%04x</data2>\n", p2); + printf("\t\t\t\t<padding>%04x</padding>\n", p3); + printf("\t\t\t</pair>\n"); - } - } - printf("\t\t</entry>\n"); - isTriplet = 0; - } - printf("\t</monkey>\n"); + } + } + printf("\t\t</entry>\n"); + isTriplet = 0; + } + printf("\t</monkey>\n"); - if (somethingIsSet == 1) - { - tag_header tagHeader; - tag_entry tagEntry; - tag_entryinfo tagEntryInfo; - memcpy(&tagHeader, &data[brlanEntryOffset + be32(offsetToExtras)], sizeof(tag_header)); - printf("\t<extratag type=\"%c%c%c%c\">\n", tagHeader.magic[0], tagHeader.magic[1], tagHeader.magic[2], tagHeader.magic[3]); - for(j=0;j<tagHeader.entry_count;j++) - { - memcpy(&tagEntry, &data[brlanEntryOffset + be32(offsetToExtras) + sizeof(tag_header) + (j*4)], 4); - memcpy(&tagEntryInfo, &data[brlanEntryOffset + be32(offsetToExtras) + be32(tagEntry.offset)], sizeof(tag_entryinfo)); - - if(short_swap_bytes(tagEntryInfo.type) < 16) - printf("\t\t<entry type=\"%s\">\n", tag_types_list[short_swap_bytes(tagEntryInfo.type)]); - else - printf("\t\t<entry type=\"%u\">\n", short_swap_bytes(tagEntryInfo.type)); - if ( tagEntryInfo.unk1 == short_swap_bytes(0x0200) ) isTriplet = 1; - int k; + if (somethingIsSet == 1) + { + tag_header tagHeader; + tag_entry tagEntry; + tag_entryinfo tagEntryInfo; + memcpy(&tagHeader, &data[brlanEntryOffset + be32(offsetToExtras)], sizeof(tag_header)); + printf("\t<extratag type=\"%c%c%c%c\">\n", tagHeader.magic[0], tagHeader.magic[1], tagHeader.magic[2], tagHeader.magic[3]); + for(j=0;j<tagHeader.entry_count;j++) + { + memcpy(&tagEntry, &data[brlanEntryOffset + be32(offsetToExtras) + sizeof(tag_header) + (j*4)], 4); + memcpy(&tagEntryInfo, &data[brlanEntryOffset + be32(offsetToExtras) + be32(tagEntry.offset)], sizeof(tag_entryinfo)); + + if(short_swap_bytes(tagEntryInfo.type) < 16) + printf("\t\t<entry type=\"%s\">\n", tag_types_list[short_swap_bytes(tagEntryInfo.type)]); + else + printf("\t\t<entry type=\"%u\">\n", short_swap_bytes(tagEntryInfo.type)); + if ( tagEntryInfo.unk1 == short_swap_bytes(0x0200) ) isTriplet = 1; + int k; - for(k=0;k<short_swap_bytes(tagEntryInfo.coord_count);k++) - { - if ( isTriplet == 1 ) - { - tag_data tagData; - memcpy(&tagData, &data[brlanEntryOffset + be32(offsetToExtras) + be32(tagEntry.offset)+ sizeof(tag_entryinfo) + (k*sizeof(tag_data))], sizeof(tag_data)); - u32 p1 = be32(tagData.part1); - u32 p2 = be32(tagData.part2); - u32 p3 = be32(tagData.part3); - printf("\t\t\t<triplet>\n"); - printf("\t\t\t\t<frame>%.15f</frame>\n", *(f32*)(&p1)); - printf("\t\t\t\t<value>%.15f</value>\n", *(f32*)(&p2)); - printf("\t\t\t\t<blend>%.15f</blend>\n", *(f32*)(&p3)); - printf("\t\t\t</triplet>\n"); - - } else { - tag_data2 tagData2; - memcpy(&tagData2, &data[brlanEntryOffset + be32(offsetToExtras) + be32(tagEntry.offset) + sizeof(tag_entryinfo)+ (k*sizeof(tag_data2))], sizeof(tag_data2)); - u32 p1 = be32(tagData2.part1); - u16 p2 = short_swap_bytes(tagData2.part2); - u16 p3 = short_swap_bytes(tagData2.padding); - printf("\t\t\t<pair>\n"); - printf("\t\t\t\t<data1>%.15f</data1>\n", *(f32*)(&p1)); - printf("\t\t\t\t<data2>%04x</data2>\n", p2); - printf("\t\t\t\t<padding>%04x</padding>\n", p3); - printf("\t\t\t</pair>\n"); + for(k=0;k<short_swap_bytes(tagEntryInfo.coord_count);k++) + { + if ( isTriplet == 1 ) + { + tag_data tagData; + memcpy(&tagData, &data[brlanEntryOffset + be32(offsetToExtras) + be32(tagEntry.offset)+ sizeof(tag_entryinfo) + (k*sizeof(tag_data))], sizeof(tag_data)); + u32 p1 = be32(tagData.part1); + u32 p2 = be32(tagData.part2); + u32 p3 = be32(tagData.part3); + printf("\t\t\t<triplet>\n"); + printf("\t\t\t\t<frame>%.15f</frame>\n", *(f32*)(&p1)); + printf("\t\t\t\t<value>%.15f</value>\n", *(f32*)(&p2)); + printf("\t\t\t\t<blend>%.15f</blend>\n", *(f32*)(&p3)); + printf("\t\t\t</triplet>\n"); + + } else { + tag_data2 tagData2; + memcpy(&tagData2, &data[brlanEntryOffset + be32(offsetToExtras) + be32(tagEntry.offset) + sizeof(tag_entryinfo)+ (k*sizeof(tag_data2))], sizeof(tag_data2)); + u32 p1 = be32(tagData2.part1); + u16 p2 = short_swap_bytes(tagData2.part2); + u16 p3 = short_swap_bytes(tagData2.padding); + printf("\t\t\t<pair>\n"); + printf("\t\t\t\t<data1>%.15f</data1>\n", *(f32*)(&p1)); + printf("\t\t\t\t<data2>%04x</data2>\n", p2); + printf("\t\t\t\t<padding>%04x</padding>\n", p3); + printf("\t\t\t</pair>\n"); - } - } - printf("\t\t</entry>\n"); - isTriplet = 0; - } - printf("\t</extratag>\n"); - } - somethingIsSet = 0; - somethingElseIsSet = 0; - } else { + } + } + printf("\t\t</entry>\n"); + isTriplet = 0; + } + printf("\t</extratag>\n"); + } + somethingIsSet = 0; + somethingElseIsSet = 0; + } else { - BRLAN_ReadDataFromMemory(&tagHeader, data, sizeof(tag_header)); - printf("\t<tag name=\"%s\" type=\"%c%c%c%c\" ", brlanEntry.name, tagHeader.magic[0], tagHeader.magic[1], tagHeader.magic[2], tagHeader.magic[3]); - if(be32(brlanEntry.flags) == 0x01000000) - printf("format=\"%s\">\n", "Normal"); - else - { - printf("format=\"%08x\">\n", be32(brlanEntry.flags)); - } + BRLAN_ReadDataFromMemory(&tagHeader, data, sizeof(tag_header)); + printf("\t<tag name=\"%s\" type=\"%c%c%c%c\" ", brlanEntry.name, tagHeader.magic[0], tagHeader.magic[1], tagHeader.magic[2], tagHeader.magic[3]); + if(be32(brlanEntry.flags) == 0x01000000) + printf("format=\"%s\">\n", "Normal"); + else + { + printf("format=\"%08x\">\n", be32(brlanEntry.flags)); + } - u32 startOfEntries = BRLAN_fileoffset; - u32 sOE = startOfEntries; - u32 j; - for (j=0;j<tagHeader.entry_count;j++) - { - BRLAN_ReadDataFromMemory(&tagEntry, data, sizeof(tag_entry)); - memcpy(&tagEntryInfo, &data[sOE - 8 + be32(tagEntry.offset)], sizeof(tag_entryinfo)); + u32 startOfEntries = BRLAN_fileoffset; + u32 sOE = startOfEntries; + u32 j; + for (j=0;j<tagHeader.entry_count;j++) + { + BRLAN_ReadDataFromMemory(&tagEntry, data, sizeof(tag_entry)); + memcpy(&tagEntryInfo, &data[sOE - 8 + be32(tagEntry.offset)], sizeof(tag_entryinfo)); - if(short_swap_bytes(tagEntryInfo.type) < 16) - printf("\t\t<entry type=\"%s\">\n", tag_types_list[short_swap_bytes(tagEntryInfo.type)]); - else - printf("\t\t<entry type=\"%u\">\n", short_swap_bytes(tagEntryInfo.type)); - if( tagEntryInfo.unk1 == 0x2) isTriplet = 1; + if(short_swap_bytes(tagEntryInfo.type) < 16) + printf("\t\t<entry type=\"%s\">\n", tag_types_list[short_swap_bytes(tagEntryInfo.type)]); + else + printf("\t\t<entry type=\"%u\">\n", short_swap_bytes(tagEntryInfo.type)); + if( tagEntryInfo.unk1 == 0x2) isTriplet = 1; - int k; - for(k=0;k<short_swap_bytes(tagEntryInfo.coord_count);k++) - { - if ( isTriplet == 1 ) - { - tag_data tagData; - memcpy(&tagData, &data[sOE - 8 + be32(tagEntry.offset) + sizeof(tag_entryinfo)+ (k*sizeof(tag_data))], sizeof(tag_data)); + int k; + for(k=0;k<short_swap_bytes(tagEntryInfo.coord_count);k++) + { + if ( isTriplet == 1 ) + { + tag_data tagData; + memcpy(&tagData, &data[sOE - 8 + be32(tagEntry.offset) + sizeof(tag_entryinfo)+ (k*sizeof(tag_data))], sizeof(tag_data)); - u32 p1 = be32(tagData.part1); - u32 p2 = be32(tagData.part2); - u32 p3 = be32(tagData.part3); - printf("\t\t\t<triplet>\n"); - printf("\t\t\t\t<frame>%.15f</frame>\n", *(f32*)(&p1)); - printf("\t\t\t\t<value>%.15f</value>\n", *(f32*)(&p2)); - printf("\t\t\t\t<blend>%.15f</blend>\n", *(f32*)(&p3)); - printf("\t\t\t</triplet>\n"); - - } else { - tag_data2 tagData2; - memcpy(&tagData2, &data[sOE -8+ be32(tagEntry.offset) + sizeof(tag_entryinfo)+ (k*sizeof(tag_data2))], sizeof(tag_data2)); - u32 p1 = be32(tagData2.part1); - u16 p2 = short_swap_bytes(tagData2.part2); - u16 p3 = short_swap_bytes(tagData2.padding); - printf("\t\t\t<pair>\n"); - printf("\t\t\t\t<data1>%.15f</data1>\n", *(f32*)(&p1)); - printf("\t\t\t\t<data2>%04x</data2>\n", p2); - printf("\t\t\t\t<padding>%04x</padding>\n", p3); - printf("\t\t\t</pair>\n"); + u32 p1 = be32(tagData.part1); + u32 p2 = be32(tagData.part2); + u32 p3 = be32(tagData.part3); + printf("\t\t\t<triplet>\n"); + printf("\t\t\t\t<frame>%.15f</frame>\n", *(f32*)(&p1)); + printf("\t\t\t\t<value>%.15f</value>\n", *(f32*)(&p2)); + printf("\t\t\t\t<blend>%.15f</blend>\n", *(f32*)(&p3)); + printf("\t\t\t</triplet>\n"); + + } else { + tag_data2 tagData2; + memcpy(&tagData2, &data[sOE -8+ be32(tagEntry.offset) + sizeof(tag_entryinfo)+ (k*sizeof(tag_data2))], sizeof(tag_data2)); + u32 p1 = be32(tagData2.part1); + u16 p2 = short_swap_bytes(tagData2.part2); + u16 p3 = short_swap_bytes(tagData2.padding); + printf("\t\t\t<pair>\n"); + printf("\t\t\t\t<data1>%.15f</data1>\n", *(f32*)(&p1)); + printf("\t\t\t\t<data2>%04x</data2>\n", p2); + printf("\t\t\t\t<padding>%04x</padding>\n", p3); + printf("\t\t\t</pair>\n"); - } - } - printf("\t\t</entry>\n"); - isTriplet = 0; - } - printf("\t</tag>\n"); - if (somethingIsSet == 1) - { - tag_header tagHeader; - tag_entry tagEntry; - tag_entryinfo tagEntryInfo; - memcpy(&tagHeader, &data[brlanEntryOffset + be32(offsetToExtras)], sizeof(tag_header)); - printf("\t<extratag type=\"%c%c%c%c\">\n", tagHeader.magic[0], tagHeader.magic[1], tagHeader.magic[2], tagHeader.magic[3]); - for(j=0;j<tagHeader.entry_count;j++) - { - memcpy(&tagEntry, &data[brlanEntryOffset + be32(offsetToExtras) + sizeof(tag_header) + (j*4)], 4); - memcpy(&tagEntryInfo, &data[brlanEntryOffset + be32(offsetToExtras) + be32(tagEntry.offset)], sizeof(tag_entryinfo)); - - if(short_swap_bytes(tagEntryInfo.type) < 16) - printf("\t\t<entry type=\"%s\">\n", tag_types_list[short_swap_bytes(tagEntryInfo.type)]); - else - printf("\t\t<entry type=\"%u\">\n", short_swap_bytes(tagEntryInfo.type)); - if ( tagEntryInfo.unk1 == short_swap_bytes(0x0200) ) isTriplet = 1; - int k; + } + } + printf("\t\t</entry>\n"); + isTriplet = 0; + } + printf("\t</tag>\n"); + if (somethingIsSet == 1) + { + tag_header tagHeader; + tag_entry tagEntry; + tag_entryinfo tagEntryInfo; + memcpy(&tagHeader, &data[brlanEntryOffset + be32(offsetToExtras)], sizeof(tag_header)); + printf("\t<extratag type=\"%c%c%c%c\">\n", tagHeader.magic[0], tagHeader.magic[1], tagHeader.magic[2], tagHeader.magic[3]); + for(j=0;j<tagHeader.entry_count;j++) + { + memcpy(&tagEntry, &data[brlanEntryOffset + be32(offsetToExtras) + sizeof(tag_header) + (j*4)], 4); + memcpy(&tagEntryInfo, &data[brlanEntryOffset + be32(offsetToExtras) + be32(tagEntry.offset)], sizeof(tag_entryinfo)); + + if(short_swap_bytes(tagEntryInfo.type) < 16) + printf("\t\t<entry type=\"%s\">\n", tag_types_list[short_swap_bytes(tagEntryInfo.type)]); + else + printf("\t\t<entry type=\"%u\">\n", short_swap_bytes(tagEntryInfo.type)); + if ( tagEntryInfo.unk1 == short_swap_bytes(0x0200) ) isTriplet = 1; + int k; - for(k=0;k<short_swap_bytes(tagEntryInfo.coord_count);k++) - { - if ( isTriplet == 1 ) - { - tag_data tagData; - memcpy(&tagData, &data[brlanEntryOffset + be32(offsetToExtras) + be32(tagEntry.offset)+ sizeof(tag_entryinfo) + (k*sizeof(tag_data))], sizeof(tag_data)); - u32 p1 = be32(tagData.part1); - u32 p2 = be32(tagData.part2); - u32 p3 = be32(tagData.part3); - printf("\t\t\t<triplet>\n"); - printf("\t\t\t\t<frame>%.15f</frame>\n", *(f32*)(&p1)); - printf("\t\t\t\t<value>%.15f</value>\n", *(f32*)(&p2)); - printf("\t\t\t\t<blend>%.15f</blend>\n", *(f32*)(&p3)); - printf("\t\t\t</triplet>\n"); - - } else { - tag_data2 tagData2; - memcpy(&tagData2, &data[brlanEntryOffset + be32(offsetToExtras) + be32(tagEntry.offset) + sizeof(tag_entryinfo)+ (k*sizeof(tag_data2))], sizeof(tag_data2)); - u32 p1 = be32(tagData2.part1); - u16 p2 = short_swap_bytes(tagData2.part2); - u16 p3 = short_swap_bytes(tagData2.padding); - printf("\t\t\t<pair>\n"); - printf("\t\t\t\t<data1>%.15f</data1>\n", *(f32*)(&p1)); - printf("\t\t\t\t<data2>%04x</data2>\n", p2); - printf("\t\t\t\t<padding>%04x</padding>\n", p3); - printf("\t\t\t</pair>\n"); + for(k=0;k<short_swap_bytes(tagEntryInfo.coord_count);k++) + { + if ( isTriplet == 1 ) + { + tag_data tagData; + memcpy(&tagData, &data[brlanEntryOffset + be32(offsetToExtras) + be32(tagEntry.offset)+ sizeof(tag_entryinfo) + (k*sizeof(tag_data))], sizeof(tag_data)); + u32 p1 = be32(tagData.part1); + u32 p2 = be32(tagData.part2); + u32 p3 = be32(tagData.part3); + printf("\t\t\t<triplet>\n"); + printf("\t\t\t\t<frame>%.15f</frame>\n", *(f32*)(&p1)); + printf("\t\t\t\t<value>%.15f</value>\n", *(f32*)(&p2)); + printf("\t\t\t\t<blend>%.15f</blend>\n", *(f32*)(&p3)); + printf("\t\t\t</triplet>\n"); + + } else { + tag_data2 tagData2; + memcpy(&tagData2, &data[brlanEntryOffset + be32(offsetToExtras) + be32(tagEntry.offset) + sizeof(tag_entryinfo)+ (k*sizeof(tag_data2))], sizeof(tag_data2)); + u32 p1 = be32(tagData2.part1); + u16 p2 = short_swap_bytes(tagData2.part2); + u16 p3 = short_swap_bytes(tagData2.padding); + printf("\t\t\t<pair>\n"); + printf("\t\t\t\t<data1>%.15f</data1>\n", *(f32*)(&p1)); + printf("\t\t\t\t<data2>%04x</data2>\n", p2); + printf("\t\t\t\t<padding>%04x</padding>\n", p3); + printf("\t\t\t</pair>\n"); - } - } - printf("\t\t</entry>\n"); - isTriplet = 0; - } - printf("\t</extratag>\n"); - } - somethingIsSet = 0; - } - } + } + } + printf("\t\t</entry>\n"); + isTriplet = 0; + } + printf("\t</extratag>\n"); + } + somethingIsSet = 0; + } + } - printf("</xmlan>\n"); + printf("</xmlan>\n"); - fclose(fp); + 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 WriteBRLANTagEntryinfos(tag_entryinfo entryinfo, FILE* fp) { - tag_entryinfo writeentryinfo; - writeentryinfo.type = short_swap_bytes(entryinfo.type); - writeentryinfo.unk1 = short_swap_bytes(entryinfo.unk1); - writeentryinfo.coord_count = short_swap_bytes(entryinfo.coord_count); - writeentryinfo.pad1 = short_swap_bytes(entryinfo.pad1); - writeentryinfo.unk2 = be32(entryinfo.unk2); - fwrite(&writeentryinfo, sizeof(tag_entryinfo), 1, fp); + tag_entryinfo writeentryinfo; + writeentryinfo.type = short_swap_bytes(entryinfo.type); + writeentryinfo.unk1 = short_swap_bytes(entryinfo.unk1); + writeentryinfo.coord_count = short_swap_bytes(entryinfo.coord_count); + writeentryinfo.pad1 = short_swap_bytes(entryinfo.pad1); + writeentryinfo.unk2 = be32(entryinfo.unk2); + fwrite(&writeentryinfo, sizeof(tag_entryinfo), 1, fp); } void WriteBRLANTagData(tag_data* data, u16 count, FILE* fp) { - tag_data writedata; - int i; - for(i = 0; i < count; i++) { - writedata.part1 = be32(data[i].part1); - writedata.part2 = be32(data[i].part2); - writedata.part3 = be32(data[i].part3); - fwrite(&writedata, sizeof(tag_data), 1, fp); - } + tag_data writedata; + int i; + for(i = 0; i < count; i++) { + writedata.part1 = be32(data[i].part1); + writedata.part2 = be32(data[i].part2); + writedata.part3 = be32(data[i].part3); + fwrite(&writedata, sizeof(tag_data), 1, fp); + } } void WriteBRLANEntry(brlan_entry *entr, FILE* fp) { - brlan_entry writeentr; - memset(writeentr.name, 0, 20); - strncpy(writeentr.name, entr->name, 20); - writeentr.flags = be32(entr->flags); - writeentr.anim_header_len = be32(entr->anim_header_len); - fwrite(&writeentr, sizeof(brlan_entry), 1, fp); + brlan_entry writeentr; + memset(writeentr.name, 0, 20); + strncpy(writeentr.name, entr->name, 20); + writeentr.flags = be32(entr->flags); + writeentr.anim_header_len = be32(entr->anim_header_len); + fwrite(&writeentr, sizeof(brlan_entry), 1, fp); } u32 create_entries_from_xml(mxml_node_t *tree, mxml_node_t *node, brlan_entry *entr, tag_header* head, u8** tagblob, u32* blobsize) { - 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; + 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; - for(i = 0; i < 16; i++) - memset(temp3[i], 0, 24); - for(x = 0; x < 16; x++) - 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++) { - 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++) { + for(i = 0; i < 16; i++) + memset(temp3[i], 0, 24); + for(x = 0; x < 16; x++) + 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++) { + 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); - } - get_value(tempnode, temp, 256); - data2[x][i].padding = short_swap_bytes(strtoul(temp, NULL, 16)); - } - } - FILE* fp = fopen("temp.blan", "wb+"); - if(fp == NULL) { - printf("Couldn't open temporary temp.blan file\n"); - exit(1); - } - fseek(fp, 0, SEEK_SET); - entr->anim_header_len = 0; - WriteBRLANEntry(entr, fp); - u32 fillerIntOffset = ftell(fp); - u32 fillerInt = be32(0x60); - u32 fillerInt2 = be32(0x60); - if ((entr->flags & ( 1 << 25 )) && (entr->flags & ( 1 << 24 ))) - { - fillerInt2 = be32(0x60); - fwrite(&fillerInt, sizeof(u32), 1, fp); - fwrite(&fillerInt2, sizeof(u32), 1, fp); - BRLAN_fileoffset += 8; - } else if (entr->flags & 0x02000000) - { - fillerInt = be32(0x60); - fwrite(&fillerInt, sizeof(u32), 1, fp); - BRLAN_fileoffset += 4; - } - 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) ) - { - entry[x].offset = entry[x-1].offset + sizeof(tag_entryinfo) + (entryinfo[x-1].coord_count * sizeof(tag_data)); - } - if ( entryinfo[x].unk1 == (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].unk1 == 0x200 ) - WriteBRLANTagData(data[x], entryinfo[x].coord_count, fp); - if ( entryinfo[x].unk1 == 0x100 ) - { - tag_data2 writedata; - int i; - 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].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); - u32 filesz = ftell(fp); - fseek(fp, 0, SEEK_SET); - u32 monkeyOffset; - entr->anim_header_len = sizeof(brlan_entry); - if ((entr->flags & (1 << 25)) && (entr->flags & (1 << 24))) - { - entr->anim_header_len += 8; - u32 tempOffset = ftell(fp); - fillerInt = be32(filesz); - fseek(fp, fillerIntOffset, SEEK_SET); - fwrite(&fillerInt, sizeof(u32), 1, fp); // MONKEY OFFSET - monkeyOffset = ftell(fp); - fwrite(&fillerInt, sizeof(u32), 1, fp); // GO BACK FOR EXTRA OFFSET - fseek(fp, tempOffset, SEEK_SET); - } else if (entr->flags & 0x02000000) - { - entr->anim_header_len += 4; - u32 tempOffset = ftell(fp); - fillerInt = be32(filesz); - fseek(fp, fillerIntOffset, SEEK_SET); - fwrite(&fillerInt, sizeof(u32), 1, fp); - fseek(fp, tempOffset, SEEK_SET); - } - WriteBRLANEntry(entr, fp); + 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); + } + get_value(tempnode, temp, 256); + data2[x][i].padding = short_swap_bytes(strtoul(temp, NULL, 16)); + } + } + FILE* fp = fopen("temp.blan", "wb+"); + if(fp == NULL) { + printf("Couldn't open temporary temp.blan file\n"); + exit(1); + } + fseek(fp, 0, SEEK_SET); + entr->anim_header_len = 0; + WriteBRLANEntry(entr, fp); + u32 fillerIntOffset = ftell(fp); + u32 fillerInt = be32(0x60); + u32 fillerInt2 = be32(0x60); + if ((entr->flags & ( 1 << 25 )) && (entr->flags & ( 1 << 24 ))) + { + fillerInt2 = be32(0x60); + fwrite(&fillerInt, sizeof(u32), 1, fp); + fwrite(&fillerInt2, sizeof(u32), 1, fp); + BRLAN_fileoffset += 8; + } else if (entr->flags & 0x02000000) + { + fillerInt = be32(0x60); + fwrite(&fillerInt, sizeof(u32), 1, fp); + BRLAN_fileoffset += 4; + } + 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) ) + { + entry[x].offset = entry[x-1].offset + sizeof(tag_entryinfo) + (entryinfo[x-1].coord_count * sizeof(tag_data)); + } + if ( entryinfo[x].unk1 == (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].unk1 == 0x200 ) + WriteBRLANTagData(data[x], entryinfo[x].coord_count, fp); + if ( entryinfo[x].unk1 == 0x100 ) + { + tag_data2 writedata; + int i; + 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].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); + u32 filesz = ftell(fp); + fseek(fp, 0, SEEK_SET); + u32 monkeyOffset; + entr->anim_header_len = sizeof(brlan_entry); + if ((entr->flags & (1 << 25)) && (entr->flags & (1 << 24))) + { + entr->anim_header_len += 8; + u32 tempOffset = ftell(fp); + fillerInt = be32(filesz); + fseek(fp, fillerIntOffset, SEEK_SET); + fwrite(&fillerInt, sizeof(u32), 1, fp); // MONKEY OFFSET + monkeyOffset = ftell(fp); + fwrite(&fillerInt, sizeof(u32), 1, fp); // GO BACK FOR EXTRA OFFSET + fseek(fp, tempOffset, SEEK_SET); + } else if (entr->flags & 0x02000000) + { + entr->anim_header_len += 4; + u32 tempOffset = ftell(fp); + fillerInt = be32(filesz); + fseek(fp, fillerIntOffset, SEEK_SET); + fwrite(&fillerInt, sizeof(u32), 1, fp); + fseek(fp, tempOffset, SEEK_SET); + } + WriteBRLANEntry(entr, fp); - if ((entr->flags & ( 1 << 25 )) && (entr->flags & ( 1 << 24 ))) - { - mxml_node_t *monkeynode = NULL; - mxml_node_t *monkeysubnode = NULL; - mxml_node_t *monkeysubsubnode = NULL; - tag_header monkeyTagHeader; - tag_entry monkeyTagEntry[256]; - tag_entryinfo monkeyTagEntryInfo[256]; - tag_data *monkeyTagData[1024]; - tag_data2 *monkeyTagData2[1024]; - char tempChar[256]; - if(entr->flags & 0x02000000) - { - monkeynode = mxmlFindElement(node, tree, "monkey", NULL, NULL, MXML_DESCEND); - if (monkeynode != NULL) - { - if(mxmlElementGetAttr(monkeynode, "type") != NULL) - strcpy(temp, mxmlElementGetAttr(monkeynode, "type")); - else{ - printf("No type attribute found!\nSkipping this entry!\n"); - } - memcpy(monkeyTagHeader.magic, temp, 4); - monkeyTagHeader.entry_count = 0x00; - monkeyTagHeader.pad1 = 0x0; - monkeyTagHeader.pad2 = 0x0; - monkeyTagHeader.pad3 = 0x0; - fseek(fp, oldpos, SEEK_SET); - fwrite(&monkeyTagHeader, sizeof(tag_header), 1, fp); - - mxml_node_t *monkeyentrynode; - for(monkeyentrynode = mxmlFindElement(monkeynode, monkeynode, "entry", NULL, NULL, MXML_DESCEND); monkeyentrynode != NULL; monkeyentrynode = mxmlFindElement(monkeyentrynode, monkeynode, "entry", NULL, NULL, MXML_DESCEND)) - { - memset(temp, 0, 256); - memset(temp2, 0, 256); - if(mxmlElementGetAttr(monkeyentrynode, "type") != NULL) - strcpy(temp, mxmlElementGetAttr(monkeyentrynode, "type")); - else{ - printf("No type attribute found!\nSkipping this entry!\n"); - head->entry_count--; - } - 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--; - monkeyTagEntryInfo[monkeyTagHeader.entry_count].type = short_swap_bytes(i); - monkeyTagEntryInfo[monkeyTagHeader.entry_count].unk1 = short_swap_bytes(0x0200); - monkeyTagEntryInfo[monkeyTagHeader.entry_count].pad1 = 0x0000; - monkeyTagEntryInfo[monkeyTagHeader.entry_count].unk2 = be32(0x0000000C); - monkeyTagEntryInfo[monkeyTagHeader.entry_count].coord_count = 0x0; - - for(monkeysubnode = mxmlFindElement(monkeyentrynode, monkeyentrynode, "triplet", NULL, NULL, MXML_DESCEND); monkeysubnode != NULL; monkeysubnode = mxmlFindElement(monkeysubnode, monkeyentrynode, "triplet", NULL, NULL, MXML_DESCEND)) - { - monkeyTagEntryInfo[monkeyTagHeader.entry_count].unk1 = short_swap_bytes(0x0200); - monkeyTagEntryInfo[monkeyTagHeader.entry_count].coord_count += 1; - u32 tC = monkeyTagEntryInfo[monkeyTagHeader.entry_count].coord_count; - - monkeyTagData[monkeyTagHeader.entry_count] = realloc(monkeyTagData[monkeyTagHeader.entry_count], sizeof(tag_data) * tC); // S E R I O U S H E L P N E E D E D // - monkeysubsubnode = mxmlFindElement(monkeysubnode, monkeysubnode, "frame", NULL, NULL, MXML_DESCEND); - if (monkeysubsubnode != NULL) - { - get_value(monkeysubsubnode, tempChar, 256); - f32 f1 = atof(tempChar); - monkeyTagData[monkeyTagHeader.entry_count][tC-1].part1 = *(u32*)&f1; - monkeyTagData[monkeyTagHeader.entry_count][tC-1].part1 = int_swap_bytes(monkeyTagData[monkeyTagHeader.entry_count][tC-1].part1); - } - monkeysubsubnode = mxmlFindElement(monkeysubnode, monkeysubnode, "value", NULL, NULL, MXML_DESCEND); - if (monkeysubsubnode != NULL) - { - get_value(monkeysubsubnode, tempChar, 256); - f32 f2 = atof(tempChar); - monkeyTagData[monkeyTagHeader.entry_count][tC-1].part2 = *(u32*)&f2; - monkeyTagData[monkeyTagHeader.entry_count][tC-1].part2 = int_swap_bytes(monkeyTagData[monkeyTagHeader.entry_count][tC-1].part2); - } - monkeysubsubnode = mxmlFindElement(monkeysubnode, monkeysubnode, "blend", NULL, NULL, MXML_DESCEND); - if(monkeysubsubnode != NULL) - { - get_value(monkeysubsubnode, tempChar, 256); - f32 f3 = atof(tempChar); - monkeyTagData[monkeyTagHeader.entry_count][tC-1].part3 = *(u32*)&f3; - monkeyTagData[monkeyTagHeader.entry_count][tC-1].part3 = int_swap_bytes(monkeyTagData[monkeyTagHeader.entry_count][tC-1].part3); - } - } - for(monkeysubnode = mxmlFindElement(monkeyentrynode, monkeyentrynode, "pair", NULL, NULL, MXML_DESCEND); monkeysubnode != NULL; monkeysubnode = mxmlFindElement(monkeysubnode, monkeyentrynode, "pair", NULL, NULL, MXML_DESCEND)) - { - monkeyTagEntryInfo[monkeyTagHeader.entry_count].unk1 = short_swap_bytes(0x0100); - monkeyTagEntryInfo[monkeyTagHeader.entry_count].coord_count +=1; - u32 tC = monkeyTagEntryInfo[monkeyTagHeader.entry_count].coord_count; - - monkeyTagData2[monkeyTagHeader.entry_count] = realloc(monkeyTagData2[monkeyTagHeader.entry_count], sizeof(tag_data2) * tC); - monkeysubsubnode = mxmlFindElement(monkeysubnode, monkeysubnode, "data1", NULL, NULL, MXML_DESCEND); - if (monkeysubsubnode != NULL) - { - get_value(monkeysubsubnode, tempChar, 256); - f32 f1 = atof(tempChar); - monkeyTagData2[monkeyTagHeader.entry_count][tC-1].part1 = *(u32*)&f1; - monkeyTagData2[monkeyTagHeader.entry_count][tC-1].part1 = int_swap_bytes(monkeyTagData2[monkeyTagHeader.entry_count][tC-1].part1); - } - monkeysubsubnode = mxmlFindElement(monkeysubnode, monkeysubnode, "data2", NULL, NULL, MXML_DESCEND); - if (monkeysubsubnode != NULL) - { - get_value(monkeysubsubnode, tempChar, 256); - monkeyTagData2[monkeyTagHeader.entry_count][tC-1].part2 = short_swap_bytes((short)strtoul(tempChar, NULL, 16)); - } - monkeysubsubnode = mxmlFindElement(monkeysubnode, monkeysubnode, "padding", NULL, NULL, MXML_DESCEND); - if(monkeysubsubnode != NULL) - { - get_value(monkeysubsubnode, tempChar, 256); - monkeyTagData2[monkeyTagHeader.entry_count][tC-1].padding = short_swap_bytes((short)strtoul(tempChar, NULL, 16)); - } - } - u32 eC = monkeyTagHeader.entry_count; - u32 cC = monkeyTagEntryInfo[eC].coord_count; - if (monkeyTagHeader.entry_count > 0) - { - cC = short_swap_bytes(monkeyTagEntryInfo[eC-1].coord_count); - printf("cC: %08x\n", cC); - } - monkeyTagEntry[monkeyTagHeader.entry_count].offset = sizeof(tag_header); - if (monkeyTagHeader.entry_count > 0) - { - if (monkeyTagEntryInfo[eC-1].unk1 == 0x2) - { - monkeyTagEntry[monkeyTagHeader.entry_count].offset = monkeyTagEntry[monkeyTagHeader.entry_count-1].offset + sizeof(tag_entryinfo) + (sizeof(tag_data) * cC); - } - if (monkeyTagEntryInfo[eC-1].unk1 == 0x1) - { - monkeyTagEntry[monkeyTagHeader.entry_count].offset = monkeyTagEntry[monkeyTagHeader.entry_count-1].offset + sizeof(tag_entryinfo) + (sizeof(tag_data2) * cC); - } - } - - monkeyTagEntryInfo[eC].coord_count = short_swap_bytes(monkeyTagEntryInfo[eC].coord_count); - monkeyTagHeader.entry_count++; - } - fseek(fp, oldpos, SEEK_SET); - fwrite(&monkeyTagHeader, sizeof(tag_header), 1, fp); - int l; for (l=0;l<monkeyTagHeader.entry_count;l++) - { - monkeyTagEntry[l].offset += ( sizeof(tag_entry) * monkeyTagHeader.entry_count ); - monkeyTagEntry[l].offset = int_swap_bytes(monkeyTagEntry[l].offset); - } - fwrite(&monkeyTagEntry, sizeof(tag_entry), monkeyTagHeader.entry_count, fp); - - for (l=0;l<monkeyTagHeader.entry_count;l++) - { - fwrite(&monkeyTagEntryInfo[l], sizeof(tag_entryinfo), 1, fp); - if(monkeyTagEntryInfo[l].unk1 == 0x2) - { - fwrite(monkeyTagData[l], sizeof(tag_data), short_swap_bytes(monkeyTagEntryInfo[l].coord_count), fp); - } - if(monkeyTagEntryInfo[l].unk1 == 0x1) - { - fwrite(monkeyTagData2[l], sizeof(tag_data2), short_swap_bytes(monkeyTagEntryInfo[l].coord_count), fp); - } - } - filesz = ftell(fp); - } - } - oldpos = ftell(fp); - fillerInt = be32(filesz); - fseek(fp, monkeyOffset, SEEK_SET); - fwrite(&fillerInt, sizeof(u32), 1, fp); - fseek(fp, oldpos, SEEK_SET); - } + if ((entr->flags & ( 1 << 25 )) && (entr->flags & ( 1 << 24 ))) + { + mxml_node_t *monkeynode = NULL; + mxml_node_t *monkeysubnode = NULL; + mxml_node_t *monkeysubsubnode = NULL; + tag_header monkeyTagHeader; + tag_entry monkeyTagEntry[256]; + tag_entryinfo monkeyTagEntryInfo[256]; + tag_data *monkeyTagData[1024]; + tag_data2 *monkeyTagData2[1024]; + char tempChar[256]; + if(entr->flags & 0x02000000) + { + monkeynode = mxmlFindElement(node, tree, "monkey", NULL, NULL, MXML_DESCEND); + if (monkeynode != NULL) + { + if(mxmlElementGetAttr(monkeynode, "type") != NULL) + strcpy(temp, mxmlElementGetAttr(monkeynode, "type")); + else{ + printf("No type attribute found!\nSkipping this entry!\n"); + } + memcpy(monkeyTagHeader.magic, temp, 4); + monkeyTagHeader.entry_count = 0x00; + monkeyTagHeader.pad1 = 0x0; + monkeyTagHeader.pad2 = 0x0; + monkeyTagHeader.pad3 = 0x0; + fseek(fp, oldpos, SEEK_SET); + fwrite(&monkeyTagHeader, sizeof(tag_header), 1, fp); + + mxml_node_t *monkeyentrynode; + for(monkeyentrynode = mxmlFindElement(monkeynode, monkeynode, "entry", NULL, NULL, MXML_DESCEND); monkeyentrynode != NULL; monkeyentrynode = mxmlFindElement(monkeyentrynode, monkeynode, "entry", NULL, NULL, MXML_DESCEND)) + { + memset(temp, 0, 256); + memset(temp2, 0, 256); + if(mxmlElementGetAttr(monkeyentrynode, "type") != NULL) + strcpy(temp, mxmlElementGetAttr(monkeyentrynode, "type")); + else{ + printf("No type attribute found!\nSkipping this entry!\n"); + head->entry_count--; + } + 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--; + monkeyTagEntryInfo[monkeyTagHeader.entry_count].type = short_swap_bytes(i); + monkeyTagEntryInfo[monkeyTagHeader.entry_count].unk1 = short_swap_bytes(0x0200); + monkeyTagEntryInfo[monkeyTagHeader.entry_count].pad1 = 0x0000; + monkeyTagEntryInfo[monkeyTagHeader.entry_count].unk2 = be32(0x0000000C); + monkeyTagEntryInfo[monkeyTagHeader.entry_count].coord_count = 0x0; + + for(monkeysubnode = mxmlFindElement(monkeyentrynode, monkeyentrynode, "triplet", NULL, NULL, MXML_DESCEND); monkeysubnode != NULL; monkeysubnode = mxmlFindElement(monkeysubnode, monkeyentrynode, "triplet", NULL, NULL, MXML_DESCEND)) + { + monkeyTagEntryInfo[monkeyTagHeader.entry_count].unk1 = short_swap_bytes(0x0200); + monkeyTagEntryInfo[monkeyTagHeader.entry_count].coord_count += 1; + u32 tC = monkeyTagEntryInfo[monkeyTagHeader.entry_count].coord_count; + + monkeyTagData[monkeyTagHeader.entry_count] = realloc(monkeyTagData[monkeyTagHeader.entry_count], sizeof(tag_data) * tC); // S E R I O U S H E L P N E E D E D // + monkeysubsubnode = mxmlFindElement(monkeysubnode, monkeysubnode, "frame", NULL, NULL, MXML_DESCEND); + if (monkeysubsubnode != NULL) + { + get_value(monkeysubsubnode, tempChar, 256); + f32 f1 = atof(tempChar); + monkeyTagData[monkeyTagHeader.entry_count][tC-1].part1 = *(u32*)&f1; + monkeyTagData[monkeyTagHeader.entry_count][tC-1].part1 = int_swap_bytes(monkeyTagData[monkeyTagHeader.entry_count][tC-1].part1); + } + monkeysubsubnode = mxmlFindElement(monkeysubnode, monkeysubnode, "value", NULL, NULL, MXML_DESCEND); + if (monkeysubsubnode != NULL) + { + get_value(monkeysubsubnode, tempChar, 256); + f32 f2 = atof(tempChar); + monkeyTagData[monkeyTagHeader.entry_count][tC-1].part2 = *(u32*)&f2; + monkeyTagData[monkeyTagHeader.entry_count][tC-1].part2 = int_swap_bytes(monkeyTagData[monkeyTagHeader.entry_count][tC-1].part2); + } + monkeysubsubnode = mxmlFindElement(monkeysubnode, monkeysubnode, "blend", NULL, NULL, MXML_DESCEND); + if(monkeysubsubnode != NULL) + { + get_value(monkeysubsubnode, tempChar, 256); + f32 f3 = atof(tempChar); + monkeyTagData[monkeyTagHeader.entry_count][tC-1].part3 = *(u32*)&f3; + monkeyTagData[monkeyTagHeader.entry_count][tC-1].part3 = int_swap_bytes(monkeyTagData[monkeyTagHeader.entry_count][tC-1].part3); + } + } + for(monkeysubnode = mxmlFindElement(monkeyentrynode, monkeyentrynode, "pair", NULL, NULL, MXML_DESCEND); monkeysubnode != NULL; monkeysubnode = mxmlFindElement(monkeysubnode, monkeyentrynode, "pair", NULL, NULL, MXML_DESCEND)) + { + monkeyTagEntryInfo[monkeyTagHeader.entry_count].unk1 = short_swap_bytes(0x0100); + monkeyTagEntryInfo[monkeyTagHeader.entry_count].coord_count +=1; + u32 tC = monkeyTagEntryInfo[monkeyTagHeader.entry_count].coord_count; + + monkeyTagData2[monkeyTagHeader.entry_count] = realloc(monkeyTagData2[monkeyTagHeader.entry_count], sizeof(tag_data2) * tC); + monkeysubsubnode = mxmlFindElement(monkeysubnode, monkeysubnode, "data1", NULL, NULL, MXML_DESCEND); + if (monkeysubsubnode != NULL) + { + get_value(monkeysubsubnode, tempChar, 256); + f32 f1 = atof(tempChar); + monkeyTagData2[monkeyTagHeader.entry_count][tC-1].part1 = *(u32*)&f1; + monkeyTagData2[monkeyTagHeader.entry_count][tC-1].part1 = int_swap_bytes(monkeyTagData2[monkeyTagHeader.entry_count][tC-1].part1); + } + monkeysubsubnode = mxmlFindElement(monkeysubnode, monkeysubnode, "data2", NULL, NULL, MXML_DESCEND); + if (monkeysubsubnode != NULL) + { + get_value(monkeysubsubnode, tempChar, 256); + monkeyTagData2[monkeyTagHeader.entry_count][tC-1].part2 = short_swap_bytes((short)strtoul(tempChar, NULL, 16)); + } + monkeysubsubnode = mxmlFindElement(monkeysubnode, monkeysubnode, "padding", NULL, NULL, MXML_DESCEND); + if(monkeysubsubnode != NULL) + { + get_value(monkeysubsubnode, tempChar, 256); + monkeyTagData2[monkeyTagHeader.entry_count][tC-1].padding = short_swap_bytes((short)strtoul(tempChar, NULL, 16)); + } + } + u32 eC = monkeyTagHeader.entry_count; + u32 cC = monkeyTagEntryInfo[eC].coord_count; + if (monkeyTagHeader.entry_count > 0) + { + cC = short_swap_bytes(monkeyTagEntryInfo[eC-1].coord_count); + printf("cC: %08x\n", cC); + } + monkeyTagEntry[monkeyTagHeader.entry_count].offset = sizeof(tag_header); + if (monkeyTagHeader.entry_count > 0) + { + if (monkeyTagEntryInfo[eC-1].unk1 == 0x2) + { + monkeyTagEntry[monkeyTagHeader.entry_count].offset = monkeyTagEntry[monkeyTagHeader.entry_count-1].offset + sizeof(tag_entryinfo) + (sizeof(tag_data) * cC); + } + if (monkeyTagEntryInfo[eC-1].unk1 == 0x1) + { + monkeyTagEntry[monkeyTagHeader.entry_count].offset = monkeyTagEntry[monkeyTagHeader.entry_count-1].offset + sizeof(tag_entryinfo) + (sizeof(tag_data2) * cC); + } + } + + monkeyTagEntryInfo[eC].coord_count = short_swap_bytes(monkeyTagEntryInfo[eC].coord_count); + monkeyTagHeader.entry_count++; + } + fseek(fp, oldpos, SEEK_SET); + fwrite(&monkeyTagHeader, sizeof(tag_header), 1, fp); + int l; for (l=0;l<monkeyTagHeader.entry_count;l++) + { + monkeyTagEntry[l].offset += ( sizeof(tag_entry) * monkeyTagHeader.entry_count ); + monkeyTagEntry[l].offset = int_swap_bytes(monkeyTagEntry[l].offset); + } + fwrite(&monkeyTagEntry, sizeof(tag_entry), monkeyTagHeader.entry_count, fp); + + for (l=0;l<monkeyTagHeader.entry_count;l++) + { + fwrite(&monkeyTagEntryInfo[l], sizeof(tag_entryinfo), 1, fp); + if(monkeyTagEntryInfo[l].unk1 == 0x2) + { + fwrite(monkeyTagData[l], sizeof(tag_data), short_swap_bytes(monkeyTagEntryInfo[l].coord_count), fp); + } + if(monkeyTagEntryInfo[l].unk1 == 0x1) + { + fwrite(monkeyTagData2[l], sizeof(tag_data2), short_swap_bytes(monkeyTagEntryInfo[l].coord_count), fp); + } + } + filesz = ftell(fp); + } + } + oldpos = ftell(fp); + fillerInt = be32(filesz); + fseek(fp, monkeyOffset, SEEK_SET); + fwrite(&fillerInt, sizeof(u32), 1, fp); + fseek(fp, oldpos, SEEK_SET); + } - mxml_node_t *addonnode = NULL; - mxml_node_t *addonsubnode = NULL; - mxml_node_t *addonsubsubnode = NULL; - tag_header addonTagHeader; - tag_entry addonTagEntry[256]; - tag_entryinfo addonTagEntryInfo[256]; - tag_data *addonTagData[1024]; - tag_data2 *addonTagData2[1024]; - char tempChar[256]; - if(entr->flags & 0x02000000) - { - addonnode = mxmlFindElement(node, tree, "extratag", NULL, NULL, MXML_DESCEND); - if (addonnode != NULL) - { - if(mxmlElementGetAttr(addonnode, "type") != NULL) - strcpy(temp, mxmlElementGetAttr(addonnode, "type")); - else{ - printf("No type attribute found!\nSkipping this entry!\n"); - } - memcpy(addonTagHeader.magic, temp, 4); - addonTagHeader.entry_count = 0x00; - addonTagHeader.pad1 = 0x0; - addonTagHeader.pad2 = 0x0; - addonTagHeader.pad3 = 0x0; - fseek(fp, oldpos, SEEK_SET); - fwrite(&addonTagHeader, sizeof(tag_header), 1, fp); + mxml_node_t *addonnode = NULL; + mxml_node_t *addonsubnode = NULL; + mxml_node_t *addonsubsubnode = NULL; + tag_header addonTagHeader; + tag_entry addonTagEntry[256]; + tag_entryinfo addonTagEntryInfo[256]; + tag_data *addonTagData[1024]; + tag_data2 *addonTagData2[1024]; + char tempChar[256]; + if(entr->flags & 0x02000000) + { + addonnode = mxmlFindElement(node, tree, "extratag", NULL, NULL, MXML_DESCEND); + if (addonnode != NULL) + { + if(mxmlElementGetAttr(addonnode, "type") != NULL) + strcpy(temp, mxmlElementGetAttr(addonnode, "type")); + else{ + printf("No type attribute found!\nSkipping this entry!\n"); + } + memcpy(addonTagHeader.magic, temp, 4); + addonTagHeader.entry_count = 0x00; + addonTagHeader.pad1 = 0x0; + addonTagHeader.pad2 = 0x0; + addonTagHeader.pad3 = 0x0; + fseek(fp, oldpos, SEEK_SET); + fwrite(&addonTagHeader, sizeof(tag_header), 1, fp); - mxml_node_t *entrynode; - for(entrynode = mxmlFindElement(addonnode, addonnode, "entry", NULL, NULL, MXML_DESCEND); entrynode != NULL; entrynode = mxmlFindElement(entrynode, addonnode, "entry", NULL, NULL, MXML_DESCEND)) - { - memset(temp, 0, 256); - memset(temp2, 0, 256); - if(mxmlElementGetAttr(entrynode, "type") != NULL) - strcpy(temp, mxmlElementGetAttr(entrynode, "type")); - else{ - printf("No type attribute found!\nSkipping this entry!\n"); - head->entry_count--; - } - 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--; - addonTagEntryInfo[addonTagHeader.entry_count].type = short_swap_bytes(i); - addonTagEntryInfo[addonTagHeader.entry_count].unk1 = short_swap_bytes(0x0200); - addonTagEntryInfo[addonTagHeader.entry_count].pad1 = 0x0000; - addonTagEntryInfo[addonTagHeader.entry_count].unk2 = be32(0x0000000C); - addonTagEntryInfo[addonTagHeader.entry_count].coord_count = 0x0; - - for(addonsubnode = mxmlFindElement(entrynode, entrynode, "triplet", NULL, NULL, MXML_DESCEND); addonsubnode != NULL; addonsubnode = mxmlFindElement(addonsubnode, entrynode, "triplet", NULL, NULL, MXML_DESCEND)) - { - addonTagEntryInfo[addonTagHeader.entry_count].unk1 = short_swap_bytes(0x0200); - addonTagEntryInfo[addonTagHeader.entry_count].coord_count += 1; - u32 tC = addonTagEntryInfo[addonTagHeader.entry_count].coord_count; + mxml_node_t *entrynode; + for(entrynode = mxmlFindElement(addonnode, addonnode, "entry", NULL, NULL, MXML_DESCEND); entrynode != NULL; entrynode = mxmlFindElement(entrynode, addonnode, "entry", NULL, NULL, MXML_DESCEND)) + { + memset(temp, 0, 256); + memset(temp2, 0, 256); + if(mxmlElementGetAttr(entrynode, "type") != NULL) + strcpy(temp, mxmlElementGetAttr(entrynode, "type")); + else{ + printf("No type attribute found!\nSkipping this entry!\n"); + head->entry_count--; + } + 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--; + addonTagEntryInfo[addonTagHeader.entry_count].type = short_swap_bytes(i); + addonTagEntryInfo[addonTagHeader.entry_count].unk1 = short_swap_bytes(0x0200); + addonTagEntryInfo[addonTagHeader.entry_count].pad1 = 0x0000; + addonTagEntryInfo[addonTagHeader.entry_count].unk2 = be32(0x0000000C); + addonTagEntryInfo[addonTagHeader.entry_count].coord_count = 0x0; + + for(addonsubnode = mxmlFindElement(entrynode, entrynode, "triplet", NULL, NULL, MXML_DESCEND); addonsubnode != NULL; addonsubnode = mxmlFindElement(addonsubnode, entrynode, "triplet", NULL, NULL, MXML_DESCEND)) + { + addonTagEntryInfo[addonTagHeader.entry_count].unk1 = short_swap_bytes(0x0200); + addonTagEntryInfo[addonTagHeader.entry_count].coord_count += 1; + u32 tC = addonTagEntryInfo[addonTagHeader.entry_count].coord_count; - addonTagData[addonTagHeader.entry_count] = realloc(addonTagData[addonTagHeader.entry_count], sizeof(tag_data) * tC); // S E R I O U S H E L P N E E D E D // - addonsubsubnode = mxmlFindElement(addonsubnode, addonsubnode, "frame", NULL, NULL, MXML_DESCEND); - if (addonsubsubnode != NULL) - { - get_value(addonsubsubnode, tempChar, 256); - f32 f1 = atof(tempChar); - addonTagData[addonTagHeader.entry_count][tC-1].part1 = *(u32*)&f1; - addonTagData[addonTagHeader.entry_count][tC-1].part1 = int_swap_bytes(addonTagData[addonTagHeader.entry_count][tC-1].part1); - } - addonsubsubnode = mxmlFindElement(addonsubnode, addonsubnode, "value", NULL, NULL, MXML_DESCEND); - if (addonsubsubnode != NULL) - { - get_value(addonsubsubnode, tempChar, 256); - f32 f2 = atof(tempChar); - addonTagData[addonTagHeader.entry_count][tC-1].part2 = *(u32*)&f2; - addonTagData[addonTagHeader.entry_count][tC-1].part2 = int_swap_bytes(addonTagData[addonTagHeader.entry_count][tC-1].part2); - } - addonsubsubnode = mxmlFindElement(addonsubnode, addonsubnode, "blend", NULL, NULL, MXML_DESCEND); - if(addonsubsubnode != NULL) - { - get_value(addonsubsubnode, tempChar, 256); - f32 f3 = atof(tempChar); - addonTagData[addonTagHeader.entry_count][tC-1].part3 = *(u32*)&f3; - addonTagData[addonTagHeader.entry_count][tC-1].part3 = int_swap_bytes(addonTagData[addonTagHeader.entry_count][tC-1].part3); - } - } - for(addonsubnode = mxmlFindElement(entrynode, entrynode, "pair", NULL, NULL, MXML_DESCEND); addonsubnode != NULL; addonsubnode = mxmlFindElement(addonsubnode, entrynode, "pair", NULL, NULL, MXML_DESCEND)) - { - addonTagEntryInfo[addonTagHeader.entry_count].unk1 = short_swap_bytes(0x0100); - addonTagEntryInfo[addonTagHeader.entry_count].coord_count +=1; - u32 tC = addonTagEntryInfo[addonTagHeader.entry_count].coord_count; + addonTagData[addonTagHeader.entry_count] = realloc(addonTagData[addonTagHeader.entry_count], sizeof(tag_data) * tC); // S E R I O U S H E L P N E E D E D // + addonsubsubnode = mxmlFindElement(addonsubnode, addonsubnode, "frame", NULL, NULL, MXML_DESCEND); + if (addonsubsubnode != NULL) + { + get_value(addonsubsubnode, tempChar, 256); + f32 f1 = atof(tempChar); + addonTagData[addonTagHeader.entry_count][tC-1].part1 = *(u32*)&f1; + addonTagData[addonTagHeader.entry_count][tC-1].part1 = int_swap_bytes(addonTagData[addonTagHeader.entry_count][tC-1].part1); + } + addonsubsubnode = mxmlFindElement(addonsubnode, addonsubnode, "value", NULL, NULL, MXML_DESCEND); + if (addonsubsubnode != NULL) + { + get_value(addonsubsubnode, tempChar, 256); + f32 f2 = atof(tempChar); + addonTagData[addonTagHeader.entry_count][tC-1].part2 = *(u32*)&f2; + addonTagData[addonTagHeader.entry_count][tC-1].part2 = int_swap_bytes(addonTagData[addonTagHeader.entry_count][tC-1].part2); + } + addonsubsubnode = mxmlFindElement(addonsubnode, addonsubnode, "blend", NULL, NULL, MXML_DESCEND); + if(addonsubsubnode != NULL) + { + get_value(addonsubsubnode, tempChar, 256); + f32 f3 = atof(tempChar); + addonTagData[addonTagHeader.entry_count][tC-1].part3 = *(u32*)&f3; + addonTagData[addonTagHeader.entry_count][tC-1].part3 = int_swap_bytes(addonTagData[addonTagHeader.entry_count][tC-1].part3); + } + } + for(addonsubnode = mxmlFindElement(entrynode, entrynode, "pair", NULL, NULL, MXML_DESCEND); addonsubnode != NULL; addonsubnode = mxmlFindElement(addonsubnode, entrynode, "pair", NULL, NULL, MXML_DESCEND)) + { + addonTagEntryInfo[addonTagHeader.entry_count].unk1 = short_swap_bytes(0x0100); + addonTagEntryInfo[addonTagHeader.entry_count].coord_count +=1; + u32 tC = addonTagEntryInfo[addonTagHeader.entry_count].coord_count; - addonTagData2[addonTagHeader.entry_count] = realloc(addonTagData2[addonTagHeader.entry_count], sizeof(tag_data2) * tC); - addonsubsubnode = mxmlFindElement(addonsubnode, addonsubnode, "data1", NULL, NULL, MXML_DESCEND); - if (addonsubsubnode != NULL) - { - get_value(addonsubsubnode, tempChar, 256); - f32 f1 = atof(tempChar); - addonTagData2[addonTagHeader.entry_count][tC-1].part1 = *(u32*)&f1; - addonTagData2[addonTagHeader.entry_count][tC-1].part1 = int_swap_bytes(addonTagData2[addonTagHeader.entry_count][tC-1].part1); - } - addonsubsubnode = mxmlFindElement(addonsubnode, addonsubnode, "data2", NULL, NULL, MXML_DESCEND); - if (addonsubsubnode != NULL) - { - get_value(addonsubsubnode, tempChar, 256); - addonTagData2[addonTagHeader.entry_count][tC-1].part2 = short_swap_bytes((short)strtoul(tempChar, NULL, 16)); - } - addonsubsubnode = mxmlFindElement(addonsubnode, addonsubnode, "padding", NULL, NULL, MXML_DESCEND); - if(addonsubsubnode != NULL) - { - get_value(addonsubsubnode, tempChar, 256); - addonTagData2[addonTagHeader.entry_count][tC-1].padding = short_swap_bytes((short)strtoul(tempChar, NULL, 16)); - } - } - u32 eC = addonTagHeader.entry_count; - u32 cC = addonTagEntryInfo[eC].coord_count; - if (addonTagHeader.entry_count > 0) - { - cC = short_swap_bytes(addonTagEntryInfo[eC-1].coord_count); - printf("cC: %08x\n", cC); - } - addonTagEntry[addonTagHeader.entry_count].offset = sizeof(tag_header); - if (addonTagHeader.entry_count > 0) - { - if (addonTagEntryInfo[eC-1].unk1 == 0x2) - { - addonTagEntry[addonTagHeader.entry_count].offset = addonTagEntry[addonTagHeader.entry_count-1].offset + sizeof(tag_entryinfo) + (sizeof(tag_data) * cC); - } - if (addonTagEntryInfo[eC-1].unk1 == 0x1) - { - addonTagEntry[addonTagHeader.entry_count].offset = addonTagEntry[addonTagHeader.entry_count-1].offset + sizeof(tag_entryinfo) + (sizeof(tag_data2) * cC); - } - } + addonTagData2[addonTagHeader.entry_count] = realloc(addonTagData2[addonTagHeader.entry_count], sizeof(tag_data2) * tC); + addonsubsubnode = mxmlFindElement(addonsubnode, addonsubnode, "data1", NULL, NULL, MXML_DESCEND); + if (addonsubsubnode != NULL) + { + get_value(addonsubsubnode, tempChar, 256); + f32 f1 = atof(tempChar); + addonTagData2[addonTagHeader.entry_count][tC-1].part1 = *(u32*)&f1; + addonTagData2[addonTagHeader.entry_count][tC-1].part1 = int_swap_bytes(addonTagData2[addonTagHeader.entry_count][tC-1].part1); + } + addonsubsubnode = mxmlFindElement(addonsubnode, addonsubnode, "data2", NULL, NULL, MXML_DESCEND); + if (addonsubsubnode != NULL) + { + get_value(addonsubsubnode, tempChar, 256); + addonTagData2[addonTagHeader.entry_count][tC-1].part2 = short_swap_bytes((short)strtoul(tempChar, NULL, 16)); + } + addonsubsubnode = mxmlFindElement(addonsubnode, addonsubnode, "padding", NULL, NULL, MXML_DESCEND); + if(addonsubsubnode != NULL) + { + get_value(addonsubsubnode, tempChar, 256); + addonTagData2[addonTagHeader.entry_count][tC-1].padding = short_swap_bytes((short)strtoul(tempChar, NULL, 16)); + } + } + u32 eC = addonTagHeader.entry_count; + u32 cC = addonTagEntryInfo[eC].coord_count; + if (addonTagHeader.entry_count > 0) + { + cC = short_swap_bytes(addonTagEntryInfo[eC-1].coord_count); + printf("cC: %08x\n", cC); + } + addonTagEntry[addonTagHeader.entry_count].offset = sizeof(tag_header); + if (addonTagHeader.entry_count > 0) + { + if (addonTagEntryInfo[eC-1].unk1 == 0x2) + { + addonTagEntry[addonTagHeader.entry_count].offset = addonTagEntry[addonTagHeader.entry_count-1].offset + sizeof(tag_entryinfo) + (sizeof(tag_data) * cC); + } + if (addonTagEntryInfo[eC-1].unk1 == 0x1) + { + addonTagEntry[addonTagHeader.entry_count].offset = addonTagEntry[addonTagHeader.entry_count-1].offset + sizeof(tag_entryinfo) + (sizeof(tag_data2) * cC); + } + } - addonTagEntryInfo[eC].coord_count = short_swap_bytes(addonTagEntryInfo[eC].coord_count); - addonTagHeader.entry_count++; - } - fseek(fp, oldpos, SEEK_SET); - fwrite(&addonTagHeader, sizeof(tag_header), 1, fp); - int l; for (l=0;l<addonTagHeader.entry_count;l++) - { - addonTagEntry[l].offset += ( sizeof(tag_entry) * addonTagHeader.entry_count ); - addonTagEntry[l].offset = int_swap_bytes(addonTagEntry[l].offset); - } - fwrite(&addonTagEntry, sizeof(tag_entry), addonTagHeader.entry_count, fp); + addonTagEntryInfo[eC].coord_count = short_swap_bytes(addonTagEntryInfo[eC].coord_count); + addonTagHeader.entry_count++; + } + fseek(fp, oldpos, SEEK_SET); + fwrite(&addonTagHeader, sizeof(tag_header), 1, fp); + int l; for (l=0;l<addonTagHeader.entry_count;l++) + { + addonTagEntry[l].offset += ( sizeof(tag_entry) * addonTagHeader.entry_count ); + addonTagEntry[l].offset = int_swap_bytes(addonTagEntry[l].offset); + } + fwrite(&addonTagEntry, sizeof(tag_entry), addonTagHeader.entry_count, fp); - for (l=0;l<addonTagHeader.entry_count;l++) - { - fwrite(&addonTagEntryInfo[l], sizeof(tag_entryinfo), 1, fp); - if(addonTagEntryInfo[l].unk1 == 0x2) - { - fwrite(addonTagData[l], sizeof(tag_data), short_swap_bytes(addonTagEntryInfo[l].coord_count), fp); - } - if(addonTagEntryInfo[l].unk1 == 0x1) - { - fwrite(addonTagData2[l], sizeof(tag_data2), short_swap_bytes(addonTagEntryInfo[l].coord_count), fp); - } - } - filesz = ftell(fp); - } - } + for (l=0;l<addonTagHeader.entry_count;l++) + { + fwrite(&addonTagEntryInfo[l], sizeof(tag_entryinfo), 1, fp); + if(addonTagEntryInfo[l].unk1 == 0x2) + { + fwrite(addonTagData[l], sizeof(tag_data), short_swap_bytes(addonTagEntryInfo[l].coord_count), fp); + } + if(addonTagEntryInfo[l].unk1 == 0x1) + { + fwrite(addonTagData2[l], sizeof(tag_data2), short_swap_bytes(addonTagEntryInfo[l].coord_count), fp); + } + } + filesz = ftell(fp); + } + } - *blobsize = filesz; - *tagblob = (u8*)malloc(*blobsize); - fseek(fp, 0, SEEK_SET); - fread(*tagblob, *blobsize, 1, fp); - free(entry); - free(entryinfo); - fclose(fp); - remove("temp.blan"); - return filesz; + *blobsize = filesz; + *tagblob = (u8*)malloc(*blobsize); + fseek(fp, 0, SEEK_SET); + fread(*tagblob, *blobsize, 1, fp); + free(entry); + free(entryinfo); + fclose(fp); + remove("temp.blan"); + return filesz; } void create_tag_from_xml(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* blobsize) { - tag_header head; - brlan_entry entr; - 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")); - else{ - printf("No type attribute found!\nQuitting!\n"); - exit(1); - } - head.magic[0] = temp[0]; - head.magic[1] = temp[1]; - head.magic[2] = temp[2]; - head.magic[3] = temp[3]; - head.pad1 = 0; - head.pad2 = 0; - head.pad3 = 0; - memset(temp, 0, 256); - if(mxmlElementGetAttr(node, "format") != NULL) - strcpy(temp, mxmlElementGetAttr(node, "format")); - else{ - printf("No format attribute found!\nQuitting!\n"); - exit(1); - } - int x; - for(x = 0; x < strlen(temp); x++) - temp[x] = toupper(temp[x]); - if(strcmp(temp, "NORMAL") == 0) - entr.flags = 0x01000000; - else - entr.flags = strtoul(temp, NULL, 16); - create_entries_from_xml(tree, node, &entr, &head, tagblob, blobsize); + tag_header head; + brlan_entry entr; + 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")); + else{ + printf("No type attribute found!\nQuitting!\n"); + exit(1); + } + head.magic[0] = temp[0]; + head.magic[1] = temp[1]; + head.magic[2] = temp[2]; + head.magic[3] = temp[3]; + head.pad1 = 0; + head.pad2 = 0; + head.pad3 = 0; + memset(temp, 0, 256); + if(mxmlElementGetAttr(node, "format") != NULL) + strcpy(temp, mxmlElementGetAttr(node, "format")); + else{ + printf("No format attribute found!\nQuitting!\n"); + exit(1); + } + int x; + for(x = 0; x < strlen(temp); x++) + temp[x] = toupper(temp[x]); + if(strcmp(temp, "NORMAL") == 0) + entr.flags = 0x01000000; + else + entr.flags = strtoul(temp, NULL, 16); + create_entries_from_xml(tree, node, &entr, &head, tagblob, blobsize); } 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.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); } 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.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); } void write_brlan(char *infile, char* outfile) { - int i; - for(i = 0; i < 16; i++) - memset(tag_types_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], "0x03"); - strcpy(tag_types_list[4], "0x04"); - 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"); - 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); - } - u8* tagblob; - u32 blobsize; - u16 blobcount = 0; - u32 bloboffset; - 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); + int i; + for(i = 0; i < 16; i++) + memset(tag_types_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], "0x03"); + strcpy(tag_types_list[4], "0x04"); + 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"); + 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); + } + u8* tagblob; + u32 blobsize; + u16 blobcount = 0; + u32 bloboffset; + 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); - u8* tagchunksbig = (u8*)calloc(MAXIMUM_TAGS_SIZE, 1); - MEMORY* tagsmem = mopen(tagchunksbig, MAXIMUM_TAGS_SIZE, 3); - u32 totaltagsize = 0; + u8* tagchunksbig = (u8*)calloc(MAXIMUM_TAGS_SIZE, 1); + MEMORY* tagsmem = mopen(tagchunksbig, MAXIMUM_TAGS_SIZE, 3); + u32 totaltagsize = 0; - u32 headerOffset; - u32 tagsbigOffset; - u32 blobOffsets[256]; - u8* timgblob; - u32 timgsize; - u16 timgcount = 0; - u32 timgoffset; - u8* timgchunksbig = (u8*)calloc(MAXIMUM_TIMGS_SIZE, 1); - MEMORY* timgmem = mopen(timgchunksbig, MAXIMUM_TIMGS_SIZE, 3); - u32 totaltimgize = 0; - u32 timgStartOffset = ftell(fp); - u32 timgOffsets[256]; - for(node = mxmlFindElement(tree, tree, "timg", NULL, NULL, MXML_DESCEND); node != NULL; node = mxmlFindElement(node, tree, "timg", NULL, NULL, MXML_DESCEND)) { - timgcount++; - timgoffset = ftell(fp) + mtell(timgmem) - (4 * (timgcount + 1)); - timgOffsets[timgcount-1] = mtell(timgmem); - timgoffset = be32(timgoffset); - fwrite(&timgoffset, sizeof(u32), 1, fp); - if(mxmlElementGetAttr(node, "name") != NULL) - strcpy(temp, mxmlElementGetAttr(node, "name")); - else{ - printf("No name attribute found!\n"); - exit(1); - } - mwrite(temp, strlen(temp) + 1, 1, timgmem); - totaltimgize += strlen(temp) + 1; - } - if ((totaltimgize % 4) != 0) totaltimgize += (4 - (totaltimgize % 4)); - u32 tempoOffset = ftell(fp); - int q; - for(q=0;q<timgcount;q++) - { - timgOffsets[q] += 4 * timgcount; - timgOffsets[q] = be32(timgOffsets[q]); - } - fseek(fp, timgStartOffset, SEEK_SET); - fwrite(timgOffsets, sizeof(u32), timgcount, fp); - u32 timgbigOffset = ftell(fp); - fseek(fp, tempoOffset, SEEK_SET); + u32 headerOffset; + u32 tagsbigOffset; + u32 blobOffsets[256]; + u8* timgblob; + u32 timgsize; + u16 timgcount = 0; + u32 timgoffset; + u8* timgchunksbig = (u8*)calloc(MAXIMUM_TIMGS_SIZE, 1); + MEMORY* timgmem = mopen(timgchunksbig, MAXIMUM_TIMGS_SIZE, 3); + u32 totaltimgize = 0; + u32 timgStartOffset = ftell(fp); + u32 timgOffsets[256]; + for(node = mxmlFindElement(tree, tree, "timg", NULL, NULL, MXML_DESCEND); node != NULL; node = mxmlFindElement(node, tree, "timg", NULL, NULL, MXML_DESCEND)) { + timgcount++; + timgoffset = ftell(fp) + mtell(timgmem) - (4 * (timgcount + 1)); + timgOffsets[timgcount-1] = mtell(timgmem); + timgoffset = be32(timgoffset); + fwrite(&timgoffset, sizeof(u32), 1, fp); + if(mxmlElementGetAttr(node, "name") != NULL) + strcpy(temp, mxmlElementGetAttr(node, "name")); + else{ + printf("No name attribute found!\n"); + exit(1); + } + mwrite(temp, strlen(temp) + 1, 1, timgmem); + totaltimgize += strlen(temp) + 1; + } + if ((totaltimgize % 4) != 0) totaltimgize += (4 - (totaltimgize % 4)); + u32 tempoOffset = ftell(fp); + int q; + for(q=0;q<timgcount;q++) + { + timgOffsets[q] += 4 * timgcount; + timgOffsets[q] = be32(timgOffsets[q]); + } + fseek(fp, timgStartOffset, SEEK_SET); + fwrite(timgOffsets, sizeof(u32), timgcount, fp); + u32 timgbigOffset = ftell(fp); + fseek(fp, tempoOffset, SEEK_SET); - mxml_node_t *mvitnode = NULL; - mxml_node_t *lastmvit = NULL; - mxml_node_t *testfortag = NULL; - mxml_node_t *testfortagmvit = NULL; + mxml_node_t *mvitnode = NULL; + mxml_node_t *lastmvit = NULL; + mxml_node_t *testfortag = NULL; + mxml_node_t *testfortagmvit = NULL; - for(node = mxmlFindElement(tree, tree, "tag", NULL, NULL, MXML_DESCEND); node != NULL; node = mxmlFindElement(node, tree, "tag", NULL, NULL, MXML_DESCEND)) { - blobcount++; - bloboffset = ftell(fp) + mtell(tagsmem) - (4 * (blobcount + 1)); - blobOffsets[blobcount-1] = sizeof(brlan_pai1_header_type1) +mtell(tagsmem); - bloboffset = be32(bloboffset); - fwrite(&bloboffset, sizeof(u32), 1, fp); - create_tag_from_xml(tree, node, &tagblob, &blobsize); - mwrite(tagblob, blobsize, 1, tagsmem); - totaltagsize += blobsize; + for(node = mxmlFindElement(tree, tree, "tag", NULL, NULL, MXML_DESCEND); node != NULL; node = mxmlFindElement(node, tree, "tag", NULL, NULL, MXML_DESCEND)) { + blobcount++; + bloboffset = ftell(fp) + mtell(tagsmem) - (4 * (blobcount + 1)); + blobOffsets[blobcount-1] = sizeof(brlan_pai1_header_type1) +mtell(tagsmem); + bloboffset = be32(bloboffset); + fwrite(&bloboffset, sizeof(u32), 1, fp); + create_tag_from_xml(tree, node, &tagblob, &blobsize); + mwrite(tagblob, blobsize, 1, tagsmem); + totaltagsize += blobsize; - mvitnode = mxmlFindElement(node, tree, "mvit", NULL, NULL, MXML_DESCEND); - if (mvitnode != NULL) - { - testfortag = mxmlFindElement(node, tree, "tag", NULL, NULL, MXML_DESCEND); - testfortagmvit = mxmlFindElement(testfortag, tree, "mvit", NULL, NULL, MXML_DESCEND); - if (mvitnode == testfortagmvit) continue; + mvitnode = mxmlFindElement(node, tree, "mvit", NULL, NULL, MXML_DESCEND); + if (mvitnode != NULL) + { + testfortag = mxmlFindElement(node, tree, "tag", NULL, NULL, MXML_DESCEND); + testfortagmvit = mxmlFindElement(testfortag, tree, "mvit", NULL, NULL, MXML_DESCEND); + if (mvitnode == testfortagmvit) continue; -// if(mvitnode == lastmvit) continue; - blobcount++; - bloboffset = ftell(fp) + mtell(tagsmem) - (4 * (blobcount + 1)); - blobOffsets[blobcount-1] = sizeof(brlan_pai1_header_type1) + mtell(tagsmem); - bloboffset = be32(bloboffset); - fwrite(&bloboffset, sizeof(u32), 1, fp); - char name[24]; - char tempChars[256]; - strcpy(tempChars, mxmlElementGetAttr(mvitnode, "name")); - memset(name, 0, 24); - strcpy(name, tempChars); - mwrite(name, 24, 1, tagsmem); - totaltagsize += 24; -// lastmvit = mvitnode; - } - } - tagsbigOffset = ftell(fp); - fseek(fp, headerOffset, SEEK_SET); +// if(mvitnode == lastmvit) continue; + blobcount++; + bloboffset = ftell(fp) + mtell(tagsmem) - (4 * (blobcount + 1)); + blobOffsets[blobcount-1] = sizeof(brlan_pai1_header_type1) + mtell(tagsmem); + bloboffset = be32(bloboffset); + fwrite(&bloboffset, sizeof(u32), 1, fp); + char name[24]; + char tempChars[256]; + strcpy(tempChars, mxmlElementGetAttr(mvitnode, "name")); + memset(name, 0, 24); + strcpy(name, tempChars); + mwrite(name, 24, 1, tagsmem); + totaltagsize += 24; +// lastmvit = mvitnode; + } + } + tagsbigOffset = ftell(fp); + fseek(fp, headerOffset, SEEK_SET); - fseek(fp, tagsbigOffset, SEEK_SET); + fseek(fp, tagsbigOffset, SEEK_SET); - tagchunksbig = (u8*)mclose(tagsmem); - timgchunksbig = (u8*)mclose(timgmem); - fseek(fp, timgbigOffset, SEEK_SET); - fwrite(timgchunksbig, totaltimgize, 1, fp); - u32 whereToGo = timgbigOffset + totaltimgize; - fseek(fp, whereToGo, SEEK_SET); - int j; for (j=0;j<blobcount;j++) - { - blobOffsets[j] += (blobcount * 4)+(4*timgcount) + totaltimgize; - blobOffsets[j] = be32(blobOffsets[j]); - fwrite(&blobOffsets[j], sizeof(u32), 1, fp); - } - fwrite(tagchunksbig, totaltagsize, 1, 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 = ftell(fp) - rlanhead.pai1_offset; - rlanhead.file_size = ftell(fp); - fseek(fp, 0, SEEK_SET); - WriteBRLANHeader(rlanhead, fp); - WriteBRLANPaiHeader(paihead, fp); + tagchunksbig = (u8*)mclose(tagsmem); + timgchunksbig = (u8*)mclose(timgmem); + fseek(fp, timgbigOffset, SEEK_SET); + fwrite(timgchunksbig, totaltimgize, 1, fp); + u32 whereToGo = timgbigOffset + totaltimgize; + fseek(fp, whereToGo, SEEK_SET); + int j; for (j=0;j<blobcount;j++) + { + blobOffsets[j] += (blobcount * 4)+(4*timgcount) + totaltimgize; + blobOffsets[j] = be32(blobOffsets[j]); + fwrite(&blobOffsets[j], sizeof(u32), 1, fp); + } + fwrite(tagchunksbig, totaltagsize, 1, 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 = ftell(fp) - rlanhead.pai1_offset; + rlanhead.file_size = ftell(fp); + 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); } @@ -5,102 +5,103 @@ typedef enum { - RLPA_ENTRY = 0, - RLTS_ENTRY = 1, - RLVI_ENTRY = 2, - RLVC_ENTRY = 3, - RLMC_ENTRY = 4, - RLTP_ENTRY = 5 + RLPA_ENTRY = 0, + RLTS_ENTRY = 1, + RLVI_ENTRY = 2, + RLVC_ENTRY = 3, + RLMC_ENTRY = 4, + RLTP_ENTRY = 5 } 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 + 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.) } 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 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?) } 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 unk1; // Unknown + 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.) + 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 { - char name[20]; // Name of the BRLAN entry. (Must be defined in the BRLYT) - u32 flags; // Flags? (If bit 25 is set, we have another u32 after the entry. It's use is known. It is the offset to another tag) - u32 anim_header_len; // Length of the animation header which is directly after this 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; typedef struct { - 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) + 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. } 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; @@ -21,12 +21,12 @@ #include "xml.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"; @@ -54,103 +54,103 @@ int lengthOfTextures; static int FourCCsMatch(fourcc cc1, fourcc cc2) { - dbgprintf("FourCCs\n"); - int ret[4]; - dbgprintf("Let's go %08x %08x\n", cc1, cc2); - ret[0] = (cc1[0] == cc2[0]); - dbgprintf("Got zero |%02x| |%02x| %d\n", cc1[0], cc2[0], ret[0]); - ret[1] = (cc1[1] == cc2[1]); - dbgprintf("Got one |%02x| |%02x| %d\n", cc1[1], cc2[1], ret[1]); - ret[2] = (cc1[2] == cc2[2]); - dbgprintf("Got two |%02x| |%02x| %d\n", cc1[2], cc2[2], ret[2]); - ret[3] = (cc1[3] == cc2[3]); - dbgprintf("Got three |%02x| |%02x| %d\n", cc1[3], cc2[3], ret[3]); - int retval; - if(ret[0] && ret[1] && ret[2] && ret[3]) - retval = 1; - else - retval = 0; - dbgprintf("Got retval %d\n", retval); - return retval; + dbgprintf("FourCCs\n"); + int ret[4]; + dbgprintf("Let's go %08x %08x\n", cc1, cc2); + ret[0] = (cc1[0] == cc2[0]); + dbgprintf("Got zero |%02x| |%02x| %d\n", cc1[0], cc2[0], ret[0]); + ret[1] = (cc1[1] == cc2[1]); + dbgprintf("Got one |%02x| |%02x| %d\n", cc1[1], cc2[1], ret[1]); + ret[2] = (cc1[2] == cc2[2]); + dbgprintf("Got two |%02x| |%02x| %d\n", cc1[2], cc2[2], ret[2]); + ret[3] = (cc1[3] == cc2[3]); + dbgprintf("Got three |%02x| |%02x| %d\n", cc1[3], cc2[3], ret[3]); + int retval; + if(ret[0] && ret[1] && ret[2] && ret[3]) + retval = 1; + else + retval = 0; + dbgprintf("Got retval %d\n", retval); + 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) { - unsigned char *float1c; float1c = (unsigned char*)&float1; + unsigned char *float1c; float1c = (unsigned char*)&float1; unsigned char charTemp = 0x00; - charTemp = float1c[0]; float1c[0] = float1c[3]; float1c[3] = charTemp; - charTemp = 0x00; - charTemp = float1c[1]; float1c[1] = float1c[2]; float1c[2] = charTemp; + 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; } /* u16 short_swap_bytes(u16 short1) { - unsigned char* short1c; short1c = (unsigned char*)&short1; - unsigned char charTemp = 0x00; - charTemp = short1c[0]; short1c[0] = short1c[1]; short1c[1] = charTemp; + unsigned char* short1c; short1c = (unsigned char*)&short1; + unsigned char charTemp = 0x00; + charTemp = short1c[0]; short1c[0] = short1c[1]; short1c[1] = charTemp; - unsigned short *newShort; newShort = (unsigned short*)short1c; - return *newShort; + unsigned short *newShort; newShort = (unsigned short*)short1c; + return *newShort; } */ unsigned int bit_extract(unsigned int num, unsigned int start, unsigned int end) { - if (end == 100) end = start; - //simple bitmask, figure out when awake - //unsigned int mask = (2**(31 - start + 1) - 1) - (2**(31 - end) - 1) - unsigned int mask; - int first = 0; - int firstMask = 1; - for (first;first<31-start+1;first++) - { - firstMask *= 2; - } - firstMask -= 1; - first = 0; - int secondMask = 1; + if (end == 100) end = start; + //simple bitmask, figure out when awake + //unsigned int mask = (2**(31 - start + 1) - 1) - (2**(31 - end) - 1) + unsigned int mask; + int first = 0; + int firstMask = 1; + for (first;first<31-start+1;first++) + { + firstMask *= 2; + } + firstMask -= 1; + first = 0; + int secondMask = 1; - for (first;first< 31-end;first++) - { - secondMask *=2; - } - secondMask -= 1; - mask = firstMask - secondMask; - int ret = (num & mask) >> (31 - end); - return ret; + for (first;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 = 1; - for (n; n<offset;n++) - mat = mat + strlen(mat) + 1; - } - return mat; + if (offset > 1) + { + int n = 1; + for (n; n<offset;n++) + mat = mat + strlen(mat) + 1; + } + return mat; } char* getTexture(u16 offset) @@ -170,16 +170,16 @@ char* getTexture(u16 offset) u16 findMatOffset(char *mats) { - int isEqual = 1; - char* mat = materials; - int i; - for (i = 0; isEqual != 0; ) - { - isEqual = strcmp(mats, mat); - if (isEqual != 0) i++; - mat = mat + strlen(mat) + 1; - } - return i; + int isEqual = 1; + char* mat = materials; + int i; + for (i = 0; isEqual != 0; ) + { + isEqual = strcmp(mats, mat); + if (isEqual != 0) i++; + mat = mat + strlen(mat) + 1; + } + return i; } u16 findTexOffset(char *tex) @@ -198,29 +198,29 @@ u16 findTexOffset(char *tex) void ASCIIfromUnicode(unsigned char* bufferOut, unsigned char* bufferIn, u32 size) { - unsigned char tempBuffer; - unsigned char charOne[2] = { 0,0 }; - unsigned char charTwo[2] = { 0,0 }; - int i; - for (i=0;i<size;i++) - { - charOne[0] = bufferIn[(i*2)+0]; - charTwo[0] = bufferIn[(i*2)+1]; - tempBuffer = (strtoul(charOne, NULL, 16)*16) + strtoul(charTwo, NULL, 16); - //bufferOut[i] = strtoul(tempBuffer, NULL, 16); -// if (tempBuffer[0] != 0x30) -// { - bufferOut[i] = tempBuffer; -// } else { -// bufferOut[i] = 0x00; -// } - } - return; + unsigned char tempBuffer; + unsigned char charOne[2] = { 0,0 }; + unsigned char charTwo[2] = { 0,0 }; + int i; + for (i=0;i<size;i++) + { + charOne[0] = bufferIn[(i*2)+0]; + charTwo[0] = bufferIn[(i*2)+1]; + tempBuffer = (strtoul(charOne, NULL, 16)*16) + strtoul(charTwo, NULL, 16); + //bufferOut[i] = strtoul(tempBuffer, NULL, 16); +// if (tempBuffer[0] != 0x30) +// { + bufferOut[i] = tempBuffer; +// } else { +// bufferOut[i] = 0x00; +// } + } + return; } char* getUnicodeFromASCII(char* buffer) { - return buffer; + return buffer; } int BRLYT_ReadEntries(u8* brlyt_file, size_t file_size, brlyt_header header, brlyt_entry* entries) @@ -229,91 +229,91 @@ int BRLYT_ReadEntries(u8* brlyt_file, size_t file_size, brlyt_header header, brl 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! %c%c%c%c\n", header.magic[0], header.magic[1], header.magic[2], header.magic[3]); - exit(1); - } - if(filesize != be32(header.filesize)) { - printf("BRLYT filesize doesn't match!\n"); - exit(1); - } + if((header.magic[0] != 'R') || (header.magic[1] != 'L') || (header.magic[2] != 'Y') || (header.magic[3] != 'T')) { + printf("BRLYT magic doesn't match! %c%c%c%c\n", header.magic[0], header.magic[1], header.magic[2], header.magic[3]); + exit(1); + } + if(filesize != be32(header.filesize)) { + printf("BRLYT filesize doesn't match!\n"); + exit(1); + } } void PrintBRLYTEntry_lyt1(brlyt_entry entry, u8* brlyt_file) { - brlyt_lytheader_chunk data; - BRLYT_fileoffset = entry.data_location; - BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_lytheader_chunk)); + brlyt_lytheader_chunk data; + BRLYT_fileoffset = entry.data_location; + BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_lytheader_chunk)); #ifdef OLD_BRLYT_OUTSTYLE - printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); - printf(" a: %08x\n", data.a); - printf(" width: %f\n", float_swap_bytes(data.width)); - printf(" height: %f\n", float_swap_bytes(data.height)); + printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); + printf(" a: %08x\n", data.a); + printf(" width: %f\n", float_swap_bytes(data.width)); + printf(" height: %f\n", float_swap_bytes(data.height)); #else - printf("type=\"%c%c%c%c\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); - printf(" <a>%08x</a>\n", data.a); - printf(" <size>\n"); - printf(" <width>%f</width>\n", float_swap_bytes(data.width)); - printf(" <height>%f</height>\n", float_swap_bytes(data.height)); - printf(" </size>\n"); - printf(" </tag>\n"); + printf("type=\"%c%c%c%c\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); + printf(" <a>%08x</a>\n", data.a); + printf(" <size>\n"); + printf(" <width>%f</width>\n", float_swap_bytes(data.width)); + printf(" <height>%f</height>\n", float_swap_bytes(data.height)); + printf(" </size>\n"); + printf(" </tag>\n"); #endif //OLD_BRLYT_OUTSTYLE } void PrintBRLYTEntry_grp1(brlyt_entry entry, u8* brlyt_file) { - brlyt_group_chunk data; - BRLYT_fileoffset = entry.data_location; - BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_group_chunk)); + brlyt_group_chunk data; + BRLYT_fileoffset = entry.data_location; + BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_group_chunk)); #ifdef OLD_BRLYT_OUTSTYLE - printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); - printf(" Name: %s\n", data.name); - printf(" Number of subs: %08x\n", be16(data.numsubs)); - printf(" unk: %08x\n", be16(data.unk)); + printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); + printf(" Name: %s\n", data.name); + printf(" Number of subs: %08x\n", be16(data.numsubs)); + printf(" unk: %08x\n", be16(data.unk)); #else - printf("type=\"%c%c%c%c\" name=\"%s\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3], data.name); - printf(" <subs>\n"); + printf("type=\"%c%c%c%c\" name=\"%s\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3], data.name); + printf(" <subs>\n"); #endif //OLD_BRLYT_OUTSTYLE - int offset; - offset = 20; - int n = 0; - for (n;n<short_swap_bytes(data.numsubs);n++) - { - char sub[16]; - BRLYT_ReadDataFromMemory(sub, brlyt_file, sizeof(sub)); + int offset; + offset = 20; + int n = 0; + for (n;n<short_swap_bytes(data.numsubs);n++) + { + char sub[16]; + BRLYT_ReadDataFromMemory(sub, brlyt_file, sizeof(sub)); #ifdef OLD_BRLYT_OUTSTYLE - printf(" sub: %s\n", sub); + printf(" sub: %s\n", sub); #else - printf(" <sub>%s</sub>\n", sub); + printf(" <sub>%s</sub>\n", sub); #endif //OLD_BRLYT_OUTSTYLE - offset += 16; - } + offset += 16; + } #ifndef OLD_BRLYT_OUTSTYLE - printf(" </subs>\n"); - printf(" </tag>\n"); + printf(" </subs>\n"); + printf(" </tag>\n"); #endif //OLD_BRLYT_OUTSTYLE } void PrintBRLYTEntry_txl1(brlyt_entry entry, u8* brlyt_file) { - brlyt_numoffs_chunk data; - BRLYT_fileoffset = entry.data_location; - BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_numoffs_chunk)); + brlyt_numoffs_chunk data; + BRLYT_fileoffset = entry.data_location; + BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_numoffs_chunk)); #ifdef OLD_BRLYT_OUTSTYLE - printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); - printf(" num: %08x\n", be16(data.num)); - printf(" offs: %08x\n", be16(data.offs)); + printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); + printf(" num: %08x\n", be16(data.num)); + printf(" offs: %08x\n", be16(data.offs)); #else - printf("type=\"%c%c%c%c\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); - printf(" <entries>\n"); + printf("type=\"%c%c%c%c\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); + printf(" <entries>\n"); #endif //OLD_BRLYT_OUTSTYLE - int pos = 4; - pos += data.offs; - int bpos = pos; - int n = 0; - for (n;n<short_swap_bytes(data.num);n++) - { + int pos = 4; + pos += data.offs; + int bpos = pos; + int n = 0; + for (n;n<short_swap_bytes(data.num);n++) + { brlyt_offsunk_chunk data2; BRLYT_ReadDataFromMemory(&data2, brlyt_file, sizeof(brlyt_offsunk_chunk)); #ifdef OLD_BRLYT_OUTSTYLE @@ -323,33 +323,33 @@ void PrintBRLYTEntry_txl1(brlyt_entry entry, u8* brlyt_file) #endif //OLD_BRLYT_OUTSTYLE int tempLocation = BRLYT_fileoffset; BRLYT_fileoffset = entry.data_location + bpos + be32(data2.offset); - int toRead = (be32(entry.length) + entry.data_location - 8) - BRLYT_fileoffset; - char nameRead[toRead]; + int toRead = (be32(entry.length) + entry.data_location - 8) - BRLYT_fileoffset; + char nameRead[toRead]; BRLYT_ReadDataFromMemory(nameRead, brlyt_file, sizeof(nameRead)); - char tpl = 0; - char *ending = memchr(nameRead, tpl, toRead); - int end = ending - nameRead; - char name[end+1]; - memcpy(name, nameRead, sizeof(name)); + char tpl = 0; + char *ending = memchr(nameRead, tpl, toRead); + int end = ending - nameRead; + char name[end+1]; + memcpy(name, nameRead, sizeof(name)); #ifdef OLD_BRLYT_OUTSTYLE - printf(" name: %s\n", name); + printf(" name: %s\n", name); #else - printf(" <name>%s</name>\n", name); + printf(" <name>%s</name>\n", name); #endif //OLD_BRLYT_OUTSTYLE BRLYT_fileoffset = tempLocation; - int oldsize = sizeof(name); - dbgprintf("size of textures before: %08x\n", sizeof(textures)); - int newSize = lengthOfTextures+sizeof(name); - textures = realloc(textures, newSize); - numberOfTextures += 1; - memcpy(textures+lengthOfTextures, name, sizeof(name)); - dbgprintf("tex: %s\tnamsize: %08x\ttexsize: %08x\tnewsize: %08x\n", textures+lengthOfMaterials, sizeof(name), lengthOfTextures, newSize); - lengthOfTextures = newSize; - } + int oldsize = sizeof(name); + dbgprintf("size of textures before: %08x\n", sizeof(textures)); + int newSize = lengthOfTextures+sizeof(name); + textures = realloc(textures, newSize); + numberOfTextures += 1; + memcpy(textures+lengthOfTextures, name, sizeof(name)); + dbgprintf("tex: %s\tnamsize: %08x\ttexsize: %08x\tnewsize: %08x\n", textures+lengthOfMaterials, sizeof(name), lengthOfTextures, newSize); + lengthOfTextures = newSize; + } #ifndef OLD_BRLYT_OUTSTYLE - printf(" </entries>\n"); - printf(" </tag>\n"); + printf(" </entries>\n"); + printf(" </tag>\n"); #endif //OLD_BRLYT_OUTSTYLE } @@ -359,18 +359,18 @@ void PrintBRLYTEntry_fnl1(brlyt_entry entry, u8* brlyt_file) BRLYT_fileoffset = entry.data_location; BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_numoffs_chunk)); #ifdef OLD_BRLYT_OUTSTYLE - printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); + printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); printf(" num: %08x\n", be16(data.num)); printf(" offs: %08x\n", be16(data.offs)); #else - printf("type=\"%c%c%c%c\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); - printf(" <entries>\n"); + printf("type=\"%c%c%c%c\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); + printf(" <entries>\n"); #endif //OLD_BRLYT_OUTSTYLE int pos = 4; pos += data.offs; int bpos = pos; int n = 0; - for (n;n<short_swap_bytes(data.num);n++) + for (n;n<short_swap_bytes(data.num);n++) { brlyt_offsunk_chunk data2; BRLYT_ReadDataFromMemory(&data2, brlyt_file, sizeof(brlyt_offsunk_chunk)); @@ -393,21 +393,21 @@ void PrintBRLYTEntry_fnl1(brlyt_entry entry, u8* brlyt_file) #ifdef OLD_BRLYT_OUTSTYLE printf(" name: %s\n", name); #else - printf(" <name>%s</name>\n", name); + printf(" <name>%s</name>\n", name); #endif //OLD_BRLYT_OUTSTYLE BRLYT_fileoffset = tempLocation; } #ifndef OLD_BRLYT_OUTSTYLE - printf(" </entries>\n"); - printf(" </tag>\n"); + printf(" </entries>\n"); + printf(" </tag>\n"); #endif //OLD_BRLYT_OUTSTYLE } void PrintBRLYTEntry_pan1(brlyt_entry entry, u8* brlyt_file) { - brlyt_pane_chunk data; - BRLYT_fileoffset = entry.data_location; - BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_pane_chunk)); + brlyt_pane_chunk data; + BRLYT_fileoffset = entry.data_location; + BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_pane_chunk)); #ifdef OLD_BRLYT_OUTSTYLE printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); printf(" flag1: %08x\n", data.flag1); @@ -426,28 +426,28 @@ void PrintBRLYTEntry_pan1(brlyt_entry entry, u8* brlyt_file) printf(" width: %f\n", float_swap_bytes(data.width)); printf(" height: %f\n", float_swap_bytes(data.height)); #else - printf("type=\"%c%c%c%c\" name=\"%s\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3], data.name); - printf(" <flags>%08x-%08x</flags>\n", data.flag1, data.flag2); - printf(" <alpha>%08x-%08x</alpha>\n", data.alpha, data.alpha2); - printf(" <coords>\n"); - printf(" <x>%.16f</x>\n", float_swap_bytes(data.x)); - printf(" <y>%.16f</y>\n", float_swap_bytes(data.y)); - printf(" <z>%.16f</z>\n", float_swap_bytes(data.z)); - printf(" </coords>\n"); - printf(" <flip>\n"); - printf(" <x>%f</x>\n", float_swap_bytes(data.flip_x)); - printf(" <y>%f</y>\n", float_swap_bytes(data.flip_y)); - printf(" </flip>\n"); - printf(" <rotate>%f</rotate>\n", float_swap_bytes(data.angle)); - printf(" <zoom>\n"); - printf(" <x>%.10f</x>\n", float_swap_bytes(data.xmag)); - printf(" <y>%.10f</y>\n", float_swap_bytes(data.ymag)); - printf(" </zoom>\n"); - printf(" <size>\n"); - printf(" <width>%f</width>\n", float_swap_bytes(data.width)); - printf(" <height>%f</height>\n", float_swap_bytes(data.height)); - printf(" </size>\n"); - printf(" </tag>\n"); + printf("type=\"%c%c%c%c\" name=\"%s\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3], data.name); + printf(" <flags>%08x-%08x</flags>\n", data.flag1, data.flag2); + printf(" <alpha>%08x-%08x</alpha>\n", data.alpha, data.alpha2); + printf(" <coords>\n"); + printf(" <x>%.16f</x>\n", float_swap_bytes(data.x)); + printf(" <y>%.16f</y>\n", float_swap_bytes(data.y)); + printf(" <z>%.16f</z>\n", float_swap_bytes(data.z)); + printf(" </coords>\n"); + printf(" <flip>\n"); + printf(" <x>%f</x>\n", float_swap_bytes(data.flip_x)); + printf(" <y>%f</y>\n", float_swap_bytes(data.flip_y)); + printf(" </flip>\n"); + printf(" <rotate>%f</rotate>\n", float_swap_bytes(data.angle)); + printf(" <zoom>\n"); + printf(" <x>%.10f</x>\n", float_swap_bytes(data.xmag)); + printf(" <y>%.10f</y>\n", float_swap_bytes(data.ymag)); + printf(" </zoom>\n"); + printf(" <size>\n"); + printf(" <width>%f</width>\n", float_swap_bytes(data.width)); + printf(" <height>%f</height>\n", float_swap_bytes(data.height)); + printf(" </size>\n"); + printf(" </tag>\n"); #endif //OLD_BRLYT_OUTSTYLE } @@ -474,36 +474,36 @@ void PrintBRLYTEntry_wnd1(brlyt_entry entry, u8* brlyt_file) printf(" width: %f\n", float_swap_bytes(data.width)); printf(" height: %f\n", float_swap_bytes(data.height)); #else - printf("type=\"%c%c%c%c\" name=\"%s\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3], data.name); - printf(" <flags>%08x-%08x</flags>\n", data.flag1, data.flag2); - printf(" <alpha>%08x-%08x</alpha>\n", data.alpha, data.alpha2); - printf(" <coords>\n"); - printf(" <x>%f</x>\n", float_swap_bytes(data.x)); - printf(" <y>%f</y>\n", float_swap_bytes(data.y)); - printf(" <z>%f</z>\n", float_swap_bytes(data.z)); - printf(" </coords>\n"); - printf(" <flip>\n"); - printf(" <x>%f</x>\n", float_swap_bytes(data.flip_x)); - printf(" <y>%f</y>\n", float_swap_bytes(data.flip_y)); - printf(" </flip>\n"); - printf(" <rotate>%f</rotate>\n", float_swap_bytes(data.angle)); - printf(" <zoom>\n"); - printf(" <x>%.10f</x>\n", float_swap_bytes(data.xmag)); - printf(" <y>%.10f</y>\n", float_swap_bytes(data.ymag)); - printf(" </zoom>\n"); - printf(" <size>\n"); - printf(" <width>%f</width>\n", float_swap_bytes(data.width)); - printf(" <height>%f</height>\n", float_swap_bytes(data.height)); - printf(" </size>\n"); - printf(" </tag>\n"); + printf("type=\"%c%c%c%c\" name=\"%s\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3], data.name); + printf(" <flags>%08x-%08x</flags>\n", data.flag1, data.flag2); + printf(" <alpha>%08x-%08x</alpha>\n", data.alpha, data.alpha2); + printf(" <coords>\n"); + printf(" <x>%f</x>\n", float_swap_bytes(data.x)); + printf(" <y>%f</y>\n", float_swap_bytes(data.y)); + printf(" <z>%f</z>\n", float_swap_bytes(data.z)); + printf(" </coords>\n"); + printf(" <flip>\n"); + printf(" <x>%f</x>\n", float_swap_bytes(data.flip_x)); + printf(" <y>%f</y>\n", float_swap_bytes(data.flip_y)); + printf(" </flip>\n"); + printf(" <rotate>%f</rotate>\n", float_swap_bytes(data.angle)); + printf(" <zoom>\n"); + printf(" <x>%.10f</x>\n", float_swap_bytes(data.xmag)); + printf(" <y>%.10f</y>\n", float_swap_bytes(data.ymag)); + printf(" </zoom>\n"); + printf(" <size>\n"); + printf(" <width>%f</width>\n", float_swap_bytes(data.width)); + printf(" <height>%f</height>\n", float_swap_bytes(data.height)); + printf(" </size>\n"); + printf(" </tag>\n"); #endif //OLD_BRLYT_OUTSTYLE } void PrintBRLYTEntry_bnd1(brlyt_entry entry, u8* brlyt_file) { - dbgprintf("entry length: %08x\n", be32(entry.length)); - int w; - for (w=0;w<be32(entry.length);w++) dbgprintf("byte %x: %02x\n", w, brlyt_file[w]); + dbgprintf("entry length: %08x\n", be32(entry.length)); + int w; + for (w=0;w<be32(entry.length);w++) dbgprintf("byte %x: %02x\n", w, brlyt_file[w]); brlyt_pane_chunk data; BRLYT_fileoffset = entry.data_location; @@ -526,28 +526,28 @@ void PrintBRLYTEntry_bnd1(brlyt_entry entry, u8* brlyt_file) printf(" width: %f\n", float_swap_bytes(data.width)); printf(" height: %f\n", float_swap_bytes(data.height)); #else - printf("type=\"%c%c%c%c\" name=\"%s\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3], data.name); - printf(" <flags>%08x-%08x</flags>\n", data.flag1, data.flag2); - printf(" <alpha>%08x-%08x</alpha>\n", data.alpha, data.alpha2); - printf(" <coords>\n"); - printf(" <x>%.16f</x>\n", float_swap_bytes(data.x)); - printf(" <y>%.16f</y>\n", float_swap_bytes(data.y)); - printf(" <z>%.16f</z>\n", float_swap_bytes(data.z)); - printf(" </coords>\n"); - printf(" <flip>\n"); - printf(" <x>%f</x>\n", float_swap_bytes(data.flip_x)); - printf(" <y>%f</y>\n", float_swap_bytes(data.flip_y)); - printf(" </flip>\n"); - printf(" <rotate>%f</rotate>\n", float_swap_bytes(data.angle)); - printf(" <zoom>\n"); - printf(" <x>%.10f</x>\n", float_swap_bytes(data.xmag)); - printf(" <y>%.10f</y>\n", float_swap_bytes(data.ymag)); - printf(" </zoom>\n"); - printf(" <size>\n"); - printf(" <width>%f</width>\n", float_swap_bytes(data.width)); - printf(" <height>%f</height>\n", float_swap_bytes(data.height)); - printf(" </size>\n"); - printf(" </tag>\n"); + printf("type=\"%c%c%c%c\" name=\"%s\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3], data.name); + printf(" <flags>%08x-%08x</flags>\n", data.flag1, data.flag2); + printf(" <alpha>%08x-%08x</alpha>\n", data.alpha, data.alpha2); + printf(" <coords>\n"); + printf(" <x>%.16f</x>\n", float_swap_bytes(data.x)); + printf(" <y>%.16f</y>\n", float_swap_bytes(data.y)); + printf(" <z>%.16f</z>\n", float_swap_bytes(data.z)); + printf(" </coords>\n"); + printf(" <flip>\n"); + printf(" <x>%f</x>\n", float_swap_bytes(data.flip_x)); + printf(" <y>%f</y>\n", float_swap_bytes(data.flip_y)); + printf(" </flip>\n"); + printf(" <rotate>%f</rotate>\n", float_swap_bytes(data.angle)); + printf(" <zoom>\n"); + printf(" <x>%.10f</x>\n", float_swap_bytes(data.xmag)); + printf(" <y>%.10f</y>\n", float_swap_bytes(data.ymag)); + printf(" </zoom>\n"); + printf(" <size>\n"); + printf(" <width>%f</width>\n", float_swap_bytes(data.width)); + printf(" <height>%f</height>\n", float_swap_bytes(data.height)); + printf(" </size>\n"); + printf(" </tag>\n"); #endif //OLD_BRLYT_OUTSTYLE } @@ -556,81 +556,81 @@ void PrintBRLYTEntry_pic1(brlyt_entry entry, u8* brlyt_file) 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)); + brlyt_pic_chunk data2; + BRLYT_ReadDataFromMemory(&data2, brlyt_file, sizeof(brlyt_pic_chunk)); #ifdef OLD_BRLYT_OUTSTYLE printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); printf(" flag1: %08x\n", data.flag1); - printf(" flag2: %08x\n", data.flag2); - printf(" alpha: %08x\n", data.alpha); - printf(" alpha2: %08x\n", data.alpha2); - printf(" name: %s\n", data.name); - printf(" x: %f\n", float_swap_bytes(data.x)); - printf(" y: %f\n", float_swap_bytes(data.y)); - printf(" z: %f\n", float_swap_bytes(data.z)); - printf(" flip_x: %f\n", float_swap_bytes(data.flip_x)); - printf(" flip_y: %f\n", float_swap_bytes(data.flip_y)); - printf(" angle: %f\n", float_swap_bytes(data.angle)); - printf(" xmag: %f\n", float_swap_bytes(data.xmag)); - printf(" ymag: %f\n", float_swap_bytes(data.ymag)); - printf(" width: %f\n", float_swap_bytes(data.width)); - printf(" height: %f\n", float_swap_bytes(data.height)); + printf(" flag2: %08x\n", data.flag2); + printf(" alpha: %08x\n", data.alpha); + printf(" alpha2: %08x\n", data.alpha2); + printf(" name: %s\n", data.name); + printf(" x: %f\n", float_swap_bytes(data.x)); + printf(" y: %f\n", float_swap_bytes(data.y)); + printf(" z: %f\n", float_swap_bytes(data.z)); + printf(" flip_x: %f\n", float_swap_bytes(data.flip_x)); + printf(" flip_y: %f\n", float_swap_bytes(data.flip_y)); + printf(" angle: %f\n", float_swap_bytes(data.angle)); + printf(" xmag: %f\n", float_swap_bytes(data.xmag)); + printf(" ymag: %f\n", float_swap_bytes(data.ymag)); + printf(" width: %f\n", float_swap_bytes(data.width)); + printf(" height: %f\n", float_swap_bytes(data.height)); #else - printf("type=\"%c%c%c%c\" name=\"%s\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3], data.name); - printf(" <flags>%08x-%08x</flags>\n", data.flag1, data.flag2); - printf(" <alpha>%08x-%08x</alpha>\n", data.alpha, data.alpha2); - printf(" <coords>\n"); - printf(" <x>%.20f</x>\n", float_swap_bytes(data.x)); - printf(" <y>%.20f</y>\n", float_swap_bytes(data.y)); - printf(" <z>%.20f</z>\n", float_swap_bytes(data.z)); - printf(" </coords>\n"); - printf(" <flip>\n"); - printf(" <x>%f</x>\n", float_swap_bytes(data.flip_x)); - printf(" <y>%f</y>\n", float_swap_bytes(data.flip_y)); - printf(" </flip>\n"); - printf(" <rotate>%f</rotate>\n", float_swap_bytes(data.angle)); - printf(" <zoom>\n"); - printf(" <x>%.10f</x>\n", float_swap_bytes(data.xmag)); - printf(" <y>%.10f</y>\n", float_swap_bytes(data.ymag)); - printf(" </zoom>\n"); - printf(" <size>\n"); - printf(" <width>%f</width>\n", float_swap_bytes(data.width)); - printf(" <height>%f</height>\n", float_swap_bytes(data.height)); - printf(" </size>\n"); + printf("type=\"%c%c%c%c\" name=\"%s\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3], data.name); + printf(" <flags>%08x-%08x</flags>\n", data.flag1, data.flag2); + printf(" <alpha>%08x-%08x</alpha>\n", data.alpha, data.alpha2); + printf(" <coords>\n"); + printf(" <x>%.20f</x>\n", float_swap_bytes(data.x)); + printf(" <y>%.20f</y>\n", float_swap_bytes(data.y)); + printf(" <z>%.20f</z>\n", float_swap_bytes(data.z)); + printf(" </coords>\n"); + printf(" <flip>\n"); + printf(" <x>%f</x>\n", float_swap_bytes(data.flip_x)); + printf(" <y>%f</y>\n", float_swap_bytes(data.flip_y)); + printf(" </flip>\n"); + printf(" <rotate>%f</rotate>\n", float_swap_bytes(data.angle)); + printf(" <zoom>\n"); + printf(" <x>%.10f</x>\n", float_swap_bytes(data.xmag)); + printf(" <y>%.10f</y>\n", float_swap_bytes(data.ymag)); + printf(" </zoom>\n"); + printf(" <size>\n"); + printf(" <width>%f</width>\n", float_swap_bytes(data.width)); + printf(" <height>%f</height>\n", float_swap_bytes(data.height)); + printf(" </size>\n"); #endif //OLD_BRLYT_OUTSTYLE #ifdef OLD_BRLYT_OUTSTYLE - printf(" vtx_colors: %u,%u,%u,%u\n", be32(data2.vtx_colors[0]), be32(data2.vtx_colors[1]), be32(data2.vtx_colors[2]), be32(data2.vtx_colors[3])); - printf(" mat_off: %08x\n", short_swap_bytes(data2.mat_off)); - printf(" num_texcoords: %08x\n", data2.num_texcoords); - printf(" padding: %08x\n", data2.padding); + printf(" vtx_colors: %u,%u,%u,%u\n", be32(data2.vtx_colors[0]), be32(data2.vtx_colors[1]), be32(data2.vtx_colors[2]), be32(data2.vtx_colors[3])); + printf(" mat_off: %08x\n", short_swap_bytes(data2.mat_off)); + printf(" num_texcoords: %08x\n", data2.num_texcoords); + printf(" padding: %08x\n", data2.padding); #else - printf(" <tpl name=\"%s\"></tpl>\n", getMaterial(short_swap_bytes(data2.mat_off))); - printf(" <colors>\n"); - printf(" <vtx>0x%08X</vtx>\n", be32(data2.vtx_colors[0])); - printf(" <vtx>0x%08X</vtx>\n", be32(data2.vtx_colors[1])); - printf(" <vtx>0x%08X</vtx>\n", be32(data2.vtx_colors[2])); - printf(" <vtx>0x%08X</vtx>\n", be32(data2.vtx_colors[3])); - printf(" </colors>\n"); - printf(" <coordinates>\n"); + printf(" <tpl name=\"%s\"></tpl>\n", getMaterial(short_swap_bytes(data2.mat_off))); + printf(" <colors>\n"); + printf(" <vtx>0x%08X</vtx>\n", be32(data2.vtx_colors[0])); + printf(" <vtx>0x%08X</vtx>\n", be32(data2.vtx_colors[1])); + printf(" <vtx>0x%08X</vtx>\n", be32(data2.vtx_colors[2])); + printf(" <vtx>0x%08X</vtx>\n", be32(data2.vtx_colors[3])); + printf(" </colors>\n"); + printf(" <coordinates>\n"); #endif //OLD_BRLYT_OUTSTYLE - int n = 0; - for (n;n<data2.num_texcoords;n++) - { - float texcoords[8]; - BRLYT_ReadDataFromMemory(texcoords, brlyt_file, sizeof(texcoords)); + int n = 0; + for (n;n<data2.num_texcoords;n++) + { + float texcoords[8]; + BRLYT_ReadDataFromMemory(texcoords, brlyt_file, sizeof(texcoords)); #ifdef OLD_BRLYT_OUTSTYLE - printf(" tex coords: %f,%f,%f,%f,%f,%f,%f,%f\n", float_swap_bytes(texcoords[0]), float_swap_bytes(texcoords[1]), float_swap_bytes(texcoords[2]), float_swap_bytes(texcoords[3]), float_swap_bytes(texcoords[4]), float_swap_bytes(texcoords[5]), float_swap_bytes(texcoords[6]), float_swap_bytes(texcoords[7])); + printf(" tex coords: %f,%f,%f,%f,%f,%f,%f,%f\n", float_swap_bytes(texcoords[0]), float_swap_bytes(texcoords[1]), float_swap_bytes(texcoords[2]), float_swap_bytes(texcoords[3]), float_swap_bytes(texcoords[4]), float_swap_bytes(texcoords[5]), float_swap_bytes(texcoords[6]), float_swap_bytes(texcoords[7])); #else - int i; - printf(" <set>\n"); - for(i = 0; i < 8; i++) - printf(" <coord>%f</coord>\n", float_swap_bytes(texcoords[i])); - printf(" </set>\n"); + int i; + printf(" <set>\n"); + for(i = 0; i < 8; i++) + printf(" <coord>%f</coord>\n", float_swap_bytes(texcoords[i])); + printf(" </set>\n"); #endif //OLD_BRLYT_OUTSTYLE - } + } #ifndef OLD_BRLYT_OUTSTYLE - printf(" </coordinates>\n"); - printf(" </tag>\n"); + printf(" </coordinates>\n"); + printf(" </tag>\n"); #endif //OLD_BRLYT_OUTSTYLE } @@ -657,159 +657,159 @@ void PrintBRLYTEntry_txt1(brlyt_entry entry, u8* brlyt_file) printf(" width: %f\n", float_swap_bytes(data.width)); printf(" height: %f\n", float_swap_bytes(data.height)); #else - printf("type=\"%c%c%c%c\" name=\"%s\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3], data.name); - printf(" <flags>%08x-%08x</flags>\n", data.flag1, data.flag2); - printf(" <alpha>%08x-%08x</alpha>\n", data.alpha, data.alpha2); - printf(" <coords>\n"); - printf(" <x>%.16f</x>\n", float_swap_bytes(data.x)); - printf(" <y>%.16f</y>\n", float_swap_bytes(data.y)); - printf(" <z>%.16f</z>\n", float_swap_bytes(data.z)); - printf(" </coords>\n"); - printf(" <flip>\n"); - printf(" <x>%f</x>\n", float_swap_bytes(data.flip_x)); - printf(" <y>%f</y>\n", float_swap_bytes(data.flip_y)); - printf(" </flip>\n"); - printf(" <rotate>%f</rotate>\n", float_swap_bytes(data.angle)); - printf(" <zoom>\n"); - printf(" <x>%.10f</x>\n", float_swap_bytes(data.xmag)); - printf(" <y>%.10f</y>\n", float_swap_bytes(data.ymag)); - printf(" </zoom>\n"); - printf(" <size>\n"); - printf(" <width>%f</width>\n", float_swap_bytes(data.width)); - printf(" <height>%f</height>\n", float_swap_bytes(data.height)); - printf(" </size>\n"); -// for (i;i<something;i++) -// { + printf("type=\"%c%c%c%c\" name=\"%s\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3], data.name); + printf(" <flags>%08x-%08x</flags>\n", data.flag1, data.flag2); + printf(" <alpha>%08x-%08x</alpha>\n", data.alpha, data.alpha2); + printf(" <coords>\n"); + printf(" <x>%.16f</x>\n", float_swap_bytes(data.x)); + printf(" <y>%.16f</y>\n", float_swap_bytes(data.y)); + printf(" <z>%.16f</z>\n", float_swap_bytes(data.z)); + printf(" </coords>\n"); + printf(" <flip>\n"); + printf(" <x>%f</x>\n", float_swap_bytes(data.flip_x)); + printf(" <y>%f</y>\n", float_swap_bytes(data.flip_y)); + printf(" </flip>\n"); + printf(" <rotate>%f</rotate>\n", float_swap_bytes(data.angle)); + printf(" <zoom>\n"); + printf(" <x>%.10f</x>\n", float_swap_bytes(data.xmag)); + printf(" <y>%.10f</y>\n", float_swap_bytes(data.ymag)); + printf(" </zoom>\n"); + printf(" <size>\n"); + printf(" <width>%f</width>\n", float_swap_bytes(data.width)); + printf(" <height>%f</height>\n", float_swap_bytes(data.height)); + printf(" </size>\n"); +// for (i;i<something;i++) +// { #endif //OLD_BRLYT_OUTSTYLE - brlyt_text_chunk data2; - BRLYT_ReadDataFromMemory(&data2, brlyt_file, sizeof(brlyt_text_chunk)); - unsigned char texty[be16(data2.len2)]; - memcpy(texty, &brlyt_file[BRLYT_fileoffset], short_swap_bytes(data2.len2)); + brlyt_text_chunk data2; + BRLYT_ReadDataFromMemory(&data2, brlyt_file, sizeof(brlyt_text_chunk)); + unsigned char texty[be16(data2.len2)]; + memcpy(texty, &brlyt_file[BRLYT_fileoffset], short_swap_bytes(data2.len2)); #ifdef OLD_BRLYT_OUTSTYLE - printf(" len1: %08x\n", be16(data2.len1)); - printf(" len2: %08x\n", short_swap_bytes(data2.len2)); - printf(" mat_off: %08x\n", be16(data2.mat_off)); - printf(" font_idx: %08x\n", be16(data2.font_idx)); - printf(" unk4: %08x\n", data2.unk4); - printf(" pad[3]: %08x\n", data2.pad[0], data2.pad[1], data2.pad[2]); - printf(" name_offs: %08x\n", be32(data2.name_offs)); - printf(" color1: %08x\n", be32(data2.color1)); - printf(" color2: %08x\n", be32(data2.color2)); + printf(" len1: %08x\n", be16(data2.len1)); + printf(" len2: %08x\n", short_swap_bytes(data2.len2)); + printf(" mat_off: %08x\n", be16(data2.mat_off)); + printf(" font_idx: %08x\n", be16(data2.font_idx)); + printf(" unk4: %08x\n", data2.unk4); + printf(" pad[3]: %08x\n", data2.pad[0], data2.pad[1], data2.pad[2]); + printf(" name_offs: %08x\n", be32(data2.name_offs)); + printf(" color1: %08x\n", be32(data2.color1)); + printf(" color2: %08x\n", be32(data2.color2)); printf(" font_size_x: %f\n", float_swap_bytes(data2.font_size_x)); printf(" font_size_y: %f\n", float_swap_bytes(data2.font_size_y)); printf(" char_space: %f\n", float_swap_bytes(data2.char_space)); printf(" line_space: %f\n", float_swap_bytes(data2.line_space)); - printf(" text: "); - int q; for (q=0;q<short_swap_bytes(data2.len2);q++) - { - printf("%02x", texty[q]); - } - printf("\n"); + printf(" text: "); + int q; for (q=0;q<short_swap_bytes(data2.len2);q++) + { + printf("%02x", texty[q]); + } + printf("\n"); #else - printf(" <length>%04x-%04x</length>\n", short_swap_bytes(data2.len1), short_swap_bytes(data2.len2)); - printf(" <font index=\"%d\">\n", short_swap_bytes(data2.font_idx)); - printf(" <xsize>%f</xsize>\n", float_swap_bytes(data2.font_size_x)); - printf(" <ysize>%f</ysize>\n", float_swap_bytes(data2.font_size_y)); - printf(" <charsize>%f</charsize>\n", float_swap_bytes(data2.char_space)); - printf(" <linesize>%f</linesize>\n", float_swap_bytes(data2.line_space)); - printf(" <unk>%02x</unk>\n", data2.unk4); - printf(" </font>\n"); - printf(" <color>%08x-%08x</color>\n", be32(data2.color1), be32(data2.color2)); - printf(" <text>"); - int q; for (q=0;q<short_swap_bytes(data2.len2);q++) - { - printf("%02x", texty[q]); - } - printf("</text>>\n"); - printf(" </tag>\n"); + printf(" <length>%04x-%04x</length>\n", short_swap_bytes(data2.len1), short_swap_bytes(data2.len2)); + printf(" <font index=\"%d\">\n", short_swap_bytes(data2.font_idx)); + printf(" <xsize>%f</xsize>\n", float_swap_bytes(data2.font_size_x)); + printf(" <ysize>%f</ysize>\n", float_swap_bytes(data2.font_size_y)); + printf(" <charsize>%f</charsize>\n", float_swap_bytes(data2.char_space)); + printf(" <linesize>%f</linesize>\n", float_swap_bytes(data2.line_space)); + printf(" <unk>%02x</unk>\n", data2.unk4); + printf(" </font>\n"); + printf(" <color>%08x-%08x</color>\n", be32(data2.color1), be32(data2.color2)); + printf(" <text>"); + int q; for (q=0;q<short_swap_bytes(data2.len2);q++) + { + printf("%02x", texty[q]); + } + printf("</text>>\n"); + printf(" </tag>\n"); #endif //OLD_BRLYT_OUTSTYLE -// } +// } } void PrintBRLYTEntry_mat1(brlyt_entry entry, u8* brlyt_file) { - brlyt_numoffs_chunk data; - BRLYT_fileoffset = entry.data_location; - BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_numoffs_chunk)); + brlyt_numoffs_chunk data; + BRLYT_fileoffset = entry.data_location; + BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_numoffs_chunk)); #ifdef OLD_BRLYT_OUTSTYLE - printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); - printf(" num: %08x\n", be16(data.num)); - printf(" offs: %08x\n", be16(data.offs)); + printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); + printf(" num: %08x\n", be16(data.num)); + printf(" offs: %08x\n", be16(data.offs)); #else - printf("type=\"%c%c%c%c\" count=\"%d\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3], short_swap_bytes(data.num)); + printf("type=\"%c%c%c%c\" count=\"%d\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3], short_swap_bytes(data.num)); #endif //OLD_BRLYT_OUTSTYLE - int n = 0; - for (n;n<short_swap_bytes(data.num);n++) - { - int offset; - BRLYT_ReadDataFromMemory(&offset, brlyt_file, sizeof(offset)); - int tempDataLocation = BRLYT_fileoffset; - BRLYT_fileoffset = entry.data_location + be32(offset) - 8; - brlyt_material_chunk data3; - BRLYT_ReadDataFromMemory(&data3, brlyt_file, sizeof(brlyt_material_chunk)); + int n = 0; + for (n;n<short_swap_bytes(data.num);n++) + { + int offset; + BRLYT_ReadDataFromMemory(&offset, brlyt_file, sizeof(offset)); + int tempDataLocation = BRLYT_fileoffset; + BRLYT_fileoffset = entry.data_location + be32(offset) - 8; + brlyt_material_chunk data3; + BRLYT_ReadDataFromMemory(&data3, brlyt_file, sizeof(brlyt_material_chunk)); - unsigned int flaggs = be32(data3.flags); + unsigned int flaggs = be32(data3.flags); #ifdef OLD_BRLYT_OUTSTYLE - printf(" offset: %08x\n", be32(offset)); - printf(" name: %s\n", data3.name); - printf(" tev_color: %#x,%#x,%#x,%#x\n", be16(data3.tev_color[0]), be16(data3.tev_color[1]), be16(data3.tev_color[2]), be16(data3.tev_color[3])); - printf(" unk_color: %#x,%#x,%#x,%#x\n", be16(data3.unk_color[0]), be16(data3.unk_color[1]), be16(data3.unk_color[2]), be16(data3.unk_color[3])); - printf(" unk_color_2: %#x,%#x,%#x,%#x\n", be16(data3.unk_color_2[0]), be16(data3.unk_color_2[1]), be16(data3.unk_color_2[2]), be16(data3.unk_color_2[3])); - printf(" tev_kcolor: %#x,%#x,%#x,%#x\n", be32(data3.tev_kcolor[0]), be32(data3.tev_kcolor[1]), be32(data3.tev_kcolor[2]), be32(data3.tev_kcolor[3])); - printf(" flags: %08x\n", be32(data3.flags)); - printf(" bitmask: %08x\n", bit_extract(flaggs, 28, 31)); + printf(" offset: %08x\n", be32(offset)); + printf(" name: %s\n", data3.name); + printf(" tev_color: %#x,%#x,%#x,%#x\n", be16(data3.tev_color[0]), be16(data3.tev_color[1]), be16(data3.tev_color[2]), be16(data3.tev_color[3])); + printf(" unk_color: %#x,%#x,%#x,%#x\n", be16(data3.unk_color[0]), be16(data3.unk_color[1]), be16(data3.unk_color[2]), be16(data3.unk_color[3])); + printf(" unk_color_2: %#x,%#x,%#x,%#x\n", be16(data3.unk_color_2[0]), be16(data3.unk_color_2[1]), be16(data3.unk_color_2[2]), be16(data3.unk_color_2[3])); + printf(" tev_kcolor: %#x,%#x,%#x,%#x\n", be32(data3.tev_kcolor[0]), be32(data3.tev_kcolor[1]), be32(data3.tev_kcolor[2]), be32(data3.tev_kcolor[3])); + printf(" flags: %08x\n", be32(data3.flags)); + printf(" bitmask: %08x\n", bit_extract(flaggs, 28, 31)); #else - printf(" <entries name=\"%s\">\n", data3.name); - printf(" <colors>\n"); - printf(" <tev>%#x</tev>\n", short_swap_bytes(data3.tev_color[0])); - printf(" <tev>%#x</tev>\n", short_swap_bytes(data3.tev_color[1])); - printf(" <tev>%#x</tev>\n", short_swap_bytes(data3.tev_color[2])); - printf(" <tev>%#x</tev>\n", short_swap_bytes(data3.tev_color[3])); - printf(" <unk>%#x</unk>\n", short_swap_bytes(data3.unk_color[0])); - printf(" <unk>%#x</unk>\n", short_swap_bytes(data3.unk_color[1])); - printf(" <unk>%#x</unk>\n", short_swap_bytes(data3.unk_color[2])); - printf(" <unk>%#x</unk>\n", short_swap_bytes(data3.unk_color[3])); - printf(" <unk2>%#x</unk2>\n", short_swap_bytes(data3.unk_color_2[0])); - printf(" <unk2>%#x</unk2>\n", short_swap_bytes(data3.unk_color_2[1])); - printf(" <unk2>%#x</unk2>\n", short_swap_bytes(data3.unk_color_2[2])); - printf(" <unk2>%#x</unk2>\n", short_swap_bytes(data3.unk_color_2[3])); - printf(" <tev_k>%#x</tev_k>\n", be32(data3.tev_kcolor[0])); - printf(" <tev_k>%#x</tev_k>\n", be32(data3.tev_kcolor[1])); - printf(" <tev_k>%#x</tev_k>\n", be32(data3.tev_kcolor[2])); - printf(" <tev_k>%#x</tev_k>\n", be32(data3.tev_kcolor[3])); - printf(" </colors>\n"); - printf(" <flags>%08x</flags>\n", be32(data3.flags)); + printf(" <entries name=\"%s\">\n", data3.name); + printf(" <colors>\n"); + printf(" <tev>%#x</tev>\n", short_swap_bytes(data3.tev_color[0])); + printf(" <tev>%#x</tev>\n", short_swap_bytes(data3.tev_color[1])); + printf(" <tev>%#x</tev>\n", short_swap_bytes(data3.tev_color[2])); + printf(" <tev>%#x</tev>\n", short_swap_bytes(data3.tev_color[3])); + printf(" <unk>%#x</unk>\n", short_swap_bytes(data3.unk_color[0])); + printf(" <unk>%#x</unk>\n", short_swap_bytes(data3.unk_color[1])); + printf(" <unk>%#x</unk>\n", short_swap_bytes(data3.unk_color[2])); + printf(" <unk>%#x</unk>\n", short_swap_bytes(data3.unk_color[3])); + printf(" <unk2>%#x</unk2>\n", short_swap_bytes(data3.unk_color_2[0])); + printf(" <unk2>%#x</unk2>\n", short_swap_bytes(data3.unk_color_2[1])); + printf(" <unk2>%#x</unk2>\n", short_swap_bytes(data3.unk_color_2[2])); + printf(" <unk2>%#x</unk2>\n", short_swap_bytes(data3.unk_color_2[3])); + printf(" <tev_k>%#x</tev_k>\n", be32(data3.tev_kcolor[0])); + printf(" <tev_k>%#x</tev_k>\n", be32(data3.tev_kcolor[1])); + printf(" <tev_k>%#x</tev_k>\n", be32(data3.tev_kcolor[2])); + printf(" <tev_k>%#x</tev_k>\n", be32(data3.tev_kcolor[3])); + printf(" </colors>\n"); + printf(" <flags>%08x</flags>\n", be32(data3.flags)); #endif //OLD_BRLYT_OUTSTYLE - int oldsize = 1+strlen(data3.name); - dbgprintf("size of materials before: %08x\n", sizeof(materials)); - int newSize = lengthOfMaterials+strlen(data3.name)+1; - materials = realloc(materials, newSize); - numberOfMaterials += 1; - memcpy(materials+lengthOfMaterials, data3.name, 1+strlen(data3.name)); - dbgprintf("mats: %s\tnamsize: %08x\tmatsize: %08x\tnewsize: %08x\n", materials+lengthOfMaterials, strlen(data3.name), lengthOfMaterials, newSize); - lengthOfMaterials = newSize; + int oldsize = 1+strlen(data3.name); + dbgprintf("size of materials before: %08x\n", sizeof(materials)); + int newSize = lengthOfMaterials+strlen(data3.name)+1; + materials = realloc(materials, newSize); + numberOfMaterials += 1; + memcpy(materials+lengthOfMaterials, data3.name, 1+strlen(data3.name)); + dbgprintf("mats: %s\tnamsize: %08x\tmatsize: %08x\tnewsize: %08x\n", materials+lengthOfMaterials, strlen(data3.name), lengthOfMaterials, newSize); + lengthOfMaterials = newSize; - int n = 0; - for (n;n<bit_extract(flaggs, 28,31);n++) - { - brlyt_texref_chunk data4; - BRLYT_ReadDataFromMemory(&data4, brlyt_file, sizeof(brlyt_texref_chunk)); - int tplOffset = short_swap_bytes(data4.tex_offs); + int n = 0; + for (n;n<bit_extract(flaggs, 28,31);n++) + { + brlyt_texref_chunk data4; + BRLYT_ReadDataFromMemory(&data4, brlyt_file, sizeof(brlyt_texref_chunk)); + int tplOffset = short_swap_bytes(data4.tex_offs); #ifdef OLD_BRLYT_OUTSTYLE - printf(" texoffs: %08x\n", be16(data4.tex_offs)); - printf(" wrap_s: %08x\n", data4.wrap_s); - printf(" wrap_t: %08x\n", data4.wrap_t); - printf(" name: %s\n", getTexture(tplOffset)); + printf(" texoffs: %08x\n", be16(data4.tex_offs)); + printf(" wrap_s: %08x\n", data4.wrap_s); + printf(" wrap_t: %08x\n", data4.wrap_t); + printf(" name: %s\n", getTexture(tplOffset)); #else - printf(" <material name=\"%s\">\n", getTexture(tplOffset)); - printf(" <wrap_s>%08x</wrap_s>\n", data4.wrap_s); - printf(" <wrap_t>%08x</wrap_t>\n", data4.wrap_t); - printf(" </material>\n"); + printf(" <material name=\"%s\">\n", getTexture(tplOffset)); + printf(" <wrap_s>%08x</wrap_s>\n", data4.wrap_s); + printf(" <wrap_t>%08x</wrap_t>\n", data4.wrap_t); + printf(" </material>\n"); #endif //OLD_BRLYT_OUTSTYLE - } + } -// # 0x14 * flags[24-27], followed by +// # 0x14 * flags[24-27], followed by n = 0; for (n;n<bit_extract(flaggs, 24,27);n++) { @@ -817,20 +817,20 @@ void PrintBRLYTEntry_mat1(brlyt_entry entry, u8* brlyt_file) BRLYT_ReadDataFromMemory(&data4, brlyt_file, sizeof(brlyt_ua2_chunk)); #ifdef OLD_BRLYT_OUTSTYLE printf(" ua2: %08x, %08x, %08x, %08x, %08x\n", data4.unk[0], data4.unk[1], data4.unk[2], data4.unk[3], data4.unk[4]); - int s; for (s=0;s<20;s++) printf("%02x ", brlyt_file[BRLYT_fileoffset + s -20]); printf("\n"); - for (s=0;s<5;s++) printf("%f", float_swap_bytes(data4.unk[s])); - printf("\n"); + int s; for (s=0;s<20;s++) printf("%02x ", brlyt_file[BRLYT_fileoffset + s -20]); printf("\n"); + for (s=0;s<5;s++) printf("%f", float_swap_bytes(data4.unk[s])); + printf("\n"); #else - printf(" <ua2>\n"); - printf(" <data>%f</data>\n", float_swap_bytes(data4.unk[0])); - printf(" <data>%f</data>\n", float_swap_bytes(data4.unk[1])); - printf(" <data>%f</data>\n", float_swap_bytes(data4.unk[2])); - printf(" <data>%f</data>\n", float_swap_bytes(data4.unk[3])); - printf(" <data>%f</data>\n", float_swap_bytes(data4.unk[4])); - printf(" </ua2>\n"); + printf(" <ua2>\n"); + printf(" <data>%f</data>\n", float_swap_bytes(data4.unk[0])); + printf(" <data>%f</data>\n", float_swap_bytes(data4.unk[1])); + printf(" <data>%f</data>\n", float_swap_bytes(data4.unk[2])); + printf(" <data>%f</data>\n", float_swap_bytes(data4.unk[3])); + printf(" <data>%f</data>\n", float_swap_bytes(data4.unk[4])); + printf(" </ua2>\n"); #endif //OLD_BRLYT_OUTSTYLE } - //# 4*flags[20-23], followed by + //# 4*flags[20-23], followed by n = 0; for (n;n<bit_extract(flaggs, 20,23);n++) { @@ -839,21 +839,21 @@ void PrintBRLYTEntry_mat1(brlyt_entry entry, u8* brlyt_file) #ifdef OLD_BRLYT_OUTSTYLE printf(" ua3: %08x, %08x, %08x, %08x\n", data4.unk[0], data4.unk[1], data4.unk[2], data4.unk[3]); #else - printf(" <ua3>\n"); - printf(" <data>%08x</data>\n", data4.unk[0]); - printf(" <data>%08x</data>\n", data4.unk[1]); - printf(" <data>%08x</data>\n", data4.unk[2]); - printf(" <data>%08x</data>\n", data4.unk[3]); - printf(" </ua3>\n"); + printf(" <ua3>\n"); + printf(" <data>%08x</data>\n", data4.unk[0]); + printf(" <data>%08x</data>\n", data4.unk[1]); + printf(" <data>%08x</data>\n", data4.unk[2]); + printf(" <data>%08x</data>\n", data4.unk[3]); + printf(" </ua3>\n"); #endif //OLD_BRLYT_OUTSTYLE } - //# Changing ua3 things - //# 1st --> disappears. - //# 2nd --> no visible effect. - //# 3rd --> disappears. - //# 4th --> no visible effect. + //# Changing ua3 things + //# 1st --> disappears. + //# 2nd --> no visible effect. + //# 3rd --> disappears. + //# 4th --> no visible effect. - //# 4 * flags[6] + //# 4 * flags[6] n = 0; for (n;n<bit_extract(flaggs, 6,100);n++) { @@ -862,15 +862,15 @@ void PrintBRLYTEntry_mat1(brlyt_entry entry, u8* brlyt_file) #ifdef OLD_BRLYT_OUTSTYLE printf(" ua4: %08x, %08x, %08x, %08x\n", data4.unk[0], data4.unk[1], data4.unk[2], data4.unk[3]); #else - printf(" <ua4>\n"); - printf(" <data>%08x</data>\n", data4.unk[0]); - printf(" <data>%08x</data>\n", data4.unk[1]); - printf(" <data>%08x</data>\n", data4.unk[2]); - printf(" <data>%08x</data>\n", data4.unk[3]); - printf(" </ua4>\n"); + printf(" <ua4>\n"); + printf(" <data>%08x</data>\n", data4.unk[0]); + printf(" <data>%08x</data>\n", data4.unk[1]); + printf(" <data>%08x</data>\n", data4.unk[2]); + printf(" <data>%08x</data>\n", data4.unk[3]); + printf(" </ua4>\n"); #endif //OLD_BRLYT_OUTSTYLE } - //# 4 * flags[4] + //# 4 * flags[4] n = 0; for (n;n<bit_extract(flaggs, 4,100);n++) { @@ -879,15 +879,15 @@ void PrintBRLYTEntry_mat1(brlyt_entry entry, u8* brlyt_file) #ifdef OLD_BRLYT_OUTSTYLE printf(" ua5: %08x, %08x, %08x, %08x\n", data4.unk[0], data4.unk[1], data4.unk[2], data4.unk[3]); #else - printf(" <ua5>\n"); - printf(" <data>%08x</data>\n", data4.unk[0]); - printf(" <data>%08x</data>\n", data4.unk[1]); - printf(" <data>%08x</data>\n", data4.unk[2]); - printf(" <data>%08x</data>\n", data4.unk[3]); - printf(" </ua5>\n"); + printf(" <ua5>\n"); + printf(" <data>%08x</data>\n", data4.unk[0]); + printf(" <data>%08x</data>\n", data4.unk[1]); + printf(" <data>%08x</data>\n", data4.unk[2]); + printf(" <data>%08x</data>\n", data4.unk[3]); + printf(" </ua5>\n"); #endif //OLD_BRLYT_OUTSTYLE } - //# 4 * flags[19] + //# 4 * flags[19] n = 0; for (n;n<bit_extract(flaggs, 19,100);n++) { @@ -896,12 +896,12 @@ void PrintBRLYTEntry_mat1(brlyt_entry entry, u8* brlyt_file) #ifdef OLD_BRLYT_OUTSTYLE printf(" ua6: %08x, %08x, %08x, %08x\n", data4.unk[0], data4.unk[1], data4.unk[2], data4.unk[3]); #else - printf(" <ua6>\n"); - printf(" <data>%08x</data>\n", data4.unk[0]); - printf(" <data>%08x</data>\n", data4.unk[1]); - printf(" <data>%08x</data>\n", data4.unk[2]); - printf(" <data>%08x</data>\n", data4.unk[3]); - printf(" </ua6>\n"); + printf(" <ua6>\n"); + printf(" <data>%08x</data>\n", data4.unk[0]); + printf(" <data>%08x</data>\n", data4.unk[1]); + printf(" <data>%08x</data>\n", data4.unk[2]); + printf(" <data>%08x</data>\n", data4.unk[3]); + printf(" </ua6>\n"); #endif //OLD_BRLYT_OUTSTYLE } n = 0; @@ -911,21 +911,21 @@ void PrintBRLYTEntry_mat1(brlyt_entry entry, u8* brlyt_file) BRLYT_ReadDataFromMemory(&data4, brlyt_file, sizeof(brlyt_ua7_chunk)); #ifdef OLD_BRLYT_OUTSTYLE printf(" ua7 a: %08x\n", be32(data4.a)); - printf(" ua7 b: %08x\n", be32(data4.b)); - printf(" ua7 c: %f\n", float_swap_bytes(data4.c)); - printf(" ua7 d: %08x\n", be32(data4.d)); - printf(" ua7 e: %08x\n", be32(data4.e)); + printf(" ua7 b: %08x\n", be32(data4.b)); + printf(" ua7 c: %f\n", float_swap_bytes(data4.c)); + printf(" ua7 d: %08x\n", be32(data4.d)); + printf(" ua7 e: %08x\n", be32(data4.e)); #else - printf(" <ua7>\n"); - printf(" <a>%08x</a>\n", be32(data4.a)); - printf(" <b>%08x</b>\n", be32(data4.b)); - printf(" <c>%f</c>\n", float_swap_bytes(data4.c)); - printf(" <d>%08x</d>\n", be32(data4.d)); - printf(" <e>%08x</e>\n", be32(data4.e)); - printf(" </ua7>\n"); + printf(" <ua7>\n"); + printf(" <a>%08x</a>\n", be32(data4.a)); + printf(" <b>%08x</b>\n", be32(data4.b)); + printf(" <c>%f</c>\n", float_swap_bytes(data4.c)); + printf(" <d>%08x</d>\n", be32(data4.d)); + printf(" <e>%08x</e>\n", be32(data4.e)); + printf(" </ua7>\n"); #endif //OLD_BRLYT_OUTSTYLE } - //# 4 * flags[14-16] + //# 4 * flags[14-16] n = 0; for (n;n<bit_extract(flaggs, 14,16);n++) { @@ -934,15 +934,15 @@ void PrintBRLYTEntry_mat1(brlyt_entry entry, u8* brlyt_file) #ifdef OLD_BRLYT_OUTSTYLE printf(" ua8: %08x, %08x, %08x, %08x\n", data4.unk[0], data4.unk[1], data4.unk[2], data4.unk[3]); #else - printf(" <ua8>\n"); - printf(" <data>%08x</data>\n", data4.unk[0]); - printf(" <data>%08x</data>\n", data4.unk[1]); - printf(" <data>%08x</data>\n", data4.unk[2]); - printf(" <data>%08x</data>\n", data4.unk[3]); - printf(" </ua8>\n"); + printf(" <ua8>\n"); + printf(" <data>%08x</data>\n", data4.unk[0]); + printf(" <data>%08x</data>\n", data4.unk[1]); + printf(" <data>%08x</data>\n", data4.unk[2]); + printf(" <data>%08x</data>\n", data4.unk[3]); + printf(" </ua8>\n"); #endif //OLD_BRLYT_OUTSTYLE } - //# 0x10 * flags[9-13] + //# 0x10 * flags[9-13] n = 0; for (n;n<bit_extract(flaggs, 9,13);n++) { @@ -951,27 +951,27 @@ void PrintBRLYTEntry_mat1(brlyt_entry entry, u8* brlyt_file) #ifdef OLD_BRLYT_OUTSTYLE printf(" ua8: %08x, %08x, %08x, %08x, %08x, %08x, %08x, %08x, %08x, %08x, %08x, %08x, %08x, %08x, %08x, %08x\n", data4.unk[0], data4.unk[1], data4.unk[2], data4.unk[3], data4.unk[4], data4.unk[5], data4.unk[6], data4.unk[7], data4.unk[8], data4.unk[9], data4.unk[10], data4.unk[11], data4.unk[12], data4.unk[13], data4.unk[14], data4.unk[15]); #else - printf(" <ua9>\n"); - printf(" <data>%08x</data>\n", data4.unk[0]); - printf(" <data>%08x</data>\n", data4.unk[1]); - printf(" <data>%08x</data>\n", data4.unk[2]); - printf(" <data>%08x</data>\n", data4.unk[3]); - printf(" <data>%08x</data>\n", data4.unk[4]); - printf(" <data>%08x</data>\n", data4.unk[5]); - printf(" <data>%08x</data>\n", data4.unk[6]); - printf(" <data>%08x</data>\n", data4.unk[7]); - printf(" <data>%08x</data>\n", data4.unk[8]); - printf(" <data>%08x</data>\n", data4.unk[9]); - printf(" <data>%08x</data>\n", data4.unk[10]); - printf(" <data>%08x</data>\n", data4.unk[11]); - printf(" <data>%08x</data>\n", data4.unk[12]); - printf(" <data>%08x</data>\n", data4.unk[13]); - printf(" <data>%08x</data>\n", data4.unk[14]); - printf(" <data>%08x</data>\n", data4.unk[15]); - printf(" </ua9>\n"); + printf(" <ua9>\n"); + printf(" <data>%08x</data>\n", data4.unk[0]); + printf(" <data>%08x</data>\n", data4.unk[1]); + printf(" <data>%08x</data>\n", data4.unk[2]); + printf(" <data>%08x</data>\n", data4.unk[3]); + printf(" <data>%08x</data>\n", data4.unk[4]); + printf(" <data>%08x</data>\n", data4.unk[5]); + printf(" <data>%08x</data>\n", data4.unk[6]); + printf(" <data>%08x</data>\n", data4.unk[7]); + printf(" <data>%08x</data>\n", data4.unk[8]); + printf(" <data>%08x</data>\n", data4.unk[9]); + printf(" <data>%08x</data>\n", data4.unk[10]); + printf(" <data>%08x</data>\n", data4.unk[11]); + printf(" <data>%08x</data>\n", data4.unk[12]); + printf(" <data>%08x</data>\n", data4.unk[13]); + printf(" <data>%08x</data>\n", data4.unk[14]); + printf(" <data>%08x</data>\n", data4.unk[15]); + printf(" </ua9>\n"); #endif //OLD_BRLYT_OUTSTYLE } - //# 4 * flags[8], these are bytes btw + //# 4 * flags[8], these are bytes btw n = 0; for (n;n<bit_extract(flaggs, 8,8);n++) { @@ -980,15 +980,15 @@ void PrintBRLYTEntry_mat1(brlyt_entry entry, u8* brlyt_file) #ifdef OLD_BRLYT_OUTSTYLE printf(" uaa: %08x, %08x, %08x, %08x\n", data4.unk[0], data4.unk[1], data4.unk[2], data4.unk[3]); #else - printf(" <uaa>\n"); - printf(" <data>%08x</data>\n", data4.unk[0]); - printf(" <data>%08x</data>\n", data4.unk[1]); - printf(" <data>%08x</data>\n", data4.unk[2]); - printf(" <data>%08x</data>\n", data4.unk[3]); - printf(" </uaa>\n"); + printf(" <uaa>\n"); + printf(" <data>%08x</data>\n", data4.unk[0]); + printf(" <data>%08x</data>\n", data4.unk[1]); + printf(" <data>%08x</data>\n", data4.unk[2]); + printf(" <data>%08x</data>\n", data4.unk[3]); + printf(" </uaa>\n"); #endif //OLD_BRLYT_OUTSTYLE } - //# 4 * flags[7] + //# 4 * flags[7] n = 0; for (n;n<bit_extract(flaggs, 7,7);n++) { @@ -997,21 +997,21 @@ void PrintBRLYTEntry_mat1(brlyt_entry entry, u8* brlyt_file) #ifdef OLD_BRLYT_OUTSTYLE printf(" uab: %08x, %08x, %08x, %08x\n", data4.unk[0], data4.unk[1], data4.unk[2], data4.unk[3]); #else - printf(" <uab>\n"); - printf(" <data>%08x</data>\n", data4.unk[0]); - printf(" <data>%08x</data>\n", data4.unk[1]); - printf(" <data>%08x</data>\n", data4.unk[2]); - printf(" <data>%08x</data>\n", data4.unk[3]); - printf(" </uab>\n"); + printf(" <uab>\n"); + printf(" <data>%08x</data>\n", data4.unk[0]); + printf(" <data>%08x</data>\n", data4.unk[1]); + printf(" <data>%08x</data>\n", data4.unk[2]); + printf(" <data>%08x</data>\n", data4.unk[3]); + printf(" </uab>\n"); #endif //OLD_BRLYT_OUTSTYLE } #ifndef OLD_BRLYT_OUTSTYLE - printf(" </entries>\n"); + printf(" </entries>\n"); #endif //OLD_BRLYT_OUTSTYLE - BRLYT_fileoffset = tempDataLocation; - } + BRLYT_fileoffset = tempDataLocation; + } #ifndef OLD_BRLYT_OUTSTYLE - printf(" </tag>\n"); + printf(" </tag>\n"); #endif //OLD_BRLYT_OUTSTYLE } @@ -1020,7 +1020,7 @@ void PrintBRLYTEntry_gre1(brlyt_entry entry, u8* brlyt_file) #ifdef OLD_BRLYT_OUTSTYLE printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); #else - printf("type=\"%c%c%c%c\" />\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); + printf("type=\"%c%c%c%c\" />\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); #endif //OLD_BRLYT_OUTSTYLE } @@ -1029,7 +1029,7 @@ void PrintBRLYTEntry_grs1(brlyt_entry entry, u8* brlyt_file) #ifdef OLD_BRLYT_OUTSTYLE printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); #else - printf("type=\"%c%c%c%c\" />\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); + printf("type=\"%c%c%c%c\" />\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); #endif //OLD_BRLYT_OUTSTYLE } @@ -1038,7 +1038,7 @@ void PrintBRLYTEntry_pae1(brlyt_entry entry, u8* brlyt_file) #ifdef OLD_BRLYT_OUTSTYLE printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); #else - printf("type=\"%c%c%c%c\" />\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); + printf("type=\"%c%c%c%c\" />\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); #endif //OLD_BRLYT_OUTSTYLE } @@ -1047,54 +1047,54 @@ void PrintBRLYTEntry_pas1(brlyt_entry entry, u8* brlyt_file) #ifdef OLD_BRLYT_OUTSTYLE printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); #else - printf("type=\"%c%c%c%c\" />\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); + printf("type=\"%c%c%c%c\" />\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); #endif //OLD_BRLYT_OUTSTYLE } void PrintBRLYTEntries(brlyt_entry *entries, int entrycnt, u8* brlyt_file) { - dbgprintf("Printing BRLYT Entries"); - int i; - - for(i = 0; i < entrycnt; i++) { + dbgprintf("Printing BRLYT Entries"); + int i; + + for(i = 0; i < entrycnt; i++) { #ifdef OLD_BRLYT_OUTSTYLE - printf("\n Index %d (@%08x):\n", i, entries[i].data_location - 8); + printf("\n Index %d (@%08x):\n", i, entries[i].data_location - 8); #else - printf(" <tag "); + printf(" <tag "); #endif //OLD_BRLYT_OUTSTYLE - if((FourCCsMatch(entries[i].magic, pan1_magic) == 1)) { - dbgprintf("pan1\n"); - PrintBRLYTEntry_pan1(entries[i], brlyt_file); - }else if((FourCCsMatch(entries[i].magic, txt1_magic) == 1)) { - dbgprintf("txt1\n"); - PrintBRLYTEntry_txt1(entries[i], brlyt_file); - }else if((FourCCsMatch(entries[i].magic, pic1_magic) == 1)) { - dbgprintf("pic1\n"); - PrintBRLYTEntry_pic1(entries[i], brlyt_file); - }else if((FourCCsMatch(entries[i].magic, wnd1_magic) == 1)) { - dbgprintf("wnd1\n"); - PrintBRLYTEntry_wnd1(entries[i], brlyt_file); - }else if((FourCCsMatch(entries[i].magic, bnd1_magic) == 1)) { - dbgprintf("bnd1\n"); - PrintBRLYTEntry_bnd1(entries[i], brlyt_file); - }else if((FourCCsMatch(entries[i].magic, lyt1_magic) == 1)) { - dbgprintf("lyt1\n"); - PrintBRLYTEntry_lyt1(entries[i], brlyt_file); - }else if((FourCCsMatch(entries[i].magic, grp1_magic) == 1)) { - dbgprintf("grp1\n"); - PrintBRLYTEntry_grp1(entries[i], brlyt_file); - }else if((FourCCsMatch(entries[i].magic, txl1_magic) == 1)) { - dbgprintf("txl1\n"); - PrintBRLYTEntry_txl1(entries[i], brlyt_file); - }else if((FourCCsMatch(entries[i].magic, fnl1_magic) == 1)) { - dbgprintf("img\n"); - PrintBRLYTEntry_fnl1(entries[i], brlyt_file); - }else if((FourCCsMatch(entries[i].magic, mat1_magic) == 1)) { - dbgprintf("mat1\n"); - PrintBRLYTEntry_mat1(entries[i], brlyt_file); - }else if((FourCCsMatch(entries[i].magic, gre1_magic) == 1)) { - dbgprintf("gre1\n"); - PrintBRLYTEntry_gre1(entries[i], brlyt_file); + if((FourCCsMatch(entries[i].magic, pan1_magic) == 1)) { + dbgprintf("pan1\n"); + PrintBRLYTEntry_pan1(entries[i], brlyt_file); + }else if((FourCCsMatch(entries[i].magic, txt1_magic) == 1)) { + dbgprintf("txt1\n"); + PrintBRLYTEntry_txt1(entries[i], brlyt_file); + }else if((FourCCsMatch(entries[i].magic, pic1_magic) == 1)) { + dbgprintf("pic1\n"); + PrintBRLYTEntry_pic1(entries[i], brlyt_file); + }else if((FourCCsMatch(entries[i].magic, wnd1_magic) == 1)) { + dbgprintf("wnd1\n"); + PrintBRLYTEntry_wnd1(entries[i], brlyt_file); + }else if((FourCCsMatch(entries[i].magic, bnd1_magic) == 1)) { + dbgprintf("bnd1\n"); + PrintBRLYTEntry_bnd1(entries[i], brlyt_file); + }else if((FourCCsMatch(entries[i].magic, lyt1_magic) == 1)) { + dbgprintf("lyt1\n"); + PrintBRLYTEntry_lyt1(entries[i], brlyt_file); + }else if((FourCCsMatch(entries[i].magic, grp1_magic) == 1)) { + dbgprintf("grp1\n"); + PrintBRLYTEntry_grp1(entries[i], brlyt_file); + }else if((FourCCsMatch(entries[i].magic, txl1_magic) == 1)) { + dbgprintf("txl1\n"); + PrintBRLYTEntry_txl1(entries[i], brlyt_file); + }else if((FourCCsMatch(entries[i].magic, fnl1_magic) == 1)) { + dbgprintf("img\n"); + PrintBRLYTEntry_fnl1(entries[i], brlyt_file); + }else if((FourCCsMatch(entries[i].magic, mat1_magic) == 1)) { + dbgprintf("mat1\n"); + PrintBRLYTEntry_mat1(entries[i], brlyt_file); + }else if((FourCCsMatch(entries[i].magic, gre1_magic) == 1)) { + dbgprintf("gre1\n"); + PrintBRLYTEntry_gre1(entries[i], brlyt_file); }else if((FourCCsMatch(entries[i].magic, grs1_magic) == 1)) { dbgprintf("grs1\n"); PrintBRLYTEntry_grs1(entries[i], brlyt_file); @@ -1104,90 +1104,90 @@ void PrintBRLYTEntries(brlyt_entry *entries, int entrycnt, u8* brlyt_file) }else if((FourCCsMatch(entries[i].magic, pas1_magic) == 1)) { dbgprintf("pas1\n"); PrintBRLYTEntry_pas1(entries[i], brlyt_file); - }else{ + }else{ #ifdef OLD_BRLYT_OUTSTYLE - printf(" Unknown tag (%c%c%c%c)!\n",entries[i].magic[0],entries[i].magic[1],entries[i].magic[2],entries[i].magic[3]); + printf(" Unknown tag (%c%c%c%c)!\n",entries[i].magic[0],entries[i].magic[1],entries[i].magic[2],entries[i].magic[3]); #else - printf("/>\n"); + printf("/>\n"); #endif //OLD_BRLYT_OUTSTYLE - } - } + } + } } void parse_brlyt(char *filename) { - materials = (char*)malloc(12); - numberOfMaterials = 0; - lengthOfMaterials = 0; - textures = (char*)malloc(12); - numberOfTextures = 0; - lengthOfTextures = 0; - FILE* fp = fopen(filename, "rb"); - if(fp == NULL) { - printf("Error! Couldn't open %s!\n", filename); - exit(1); - } - fseek(fp, 0, SEEK_END); - size_t file_size = ftell(fp); - dbgprintf("Filesize is %d\n", file_size); - u8* brlyt_file = (u8*)malloc(file_size); - dbgprintf("brlyt_file allocated\n"); - fseek(fp, 0, SEEK_SET); - fread(brlyt_file, file_size, 1, fp); - dbgprintf("brlyt_file read to.\n"); - BRLYT_fileoffset = 0; - brlyt_header header; - BRLYT_ReadDataFromMemory(&header, brlyt_file, sizeof(brlyt_header)); - BRLYT_CheckHeaderSanity(header, file_size); - brlyt_entry *entries; - BRLYT_fileoffset = short_swap_bytes(header.lyt_offset); - brlyt_entry_header tempentry; - int i; - dbgprintf("curr %08x max %08x\n", BRLYT_fileoffset, file_size); - for(i = 0; BRLYT_fileoffset < file_size; i++) { - BRLYT_ReadDataFromMemoryX(&tempentry, brlyt_file, sizeof(brlyt_entry_header)); - BRLYT_fileoffset += be32(tempentry.length); - dbgprintf("curr %08x max %08x\n", BRLYT_fileoffset, file_size); - } - int entrycount = i; - entries = (brlyt_entry*)calloc(entrycount, sizeof(brlyt_entry)); - dbgprintf("%08x\n", entries); - if(entries == NULL) { - printf("Couldn't allocate for entries!\n"); - exit(1); - } - BRLYT_fileoffset = short_swap_bytes(header.lyt_offset); - for(i = 0; i < entrycount; i++) { - dbgprintf("&(entries[i]) = %08x\n", &(entries[i])); - BRLYT_ReadDataFromMemoryX(&tempentry, brlyt_file, sizeof(brlyt_entry_header)); - memcpy(entries[i].magic, tempentry.magic, 4); - entries[i].length = tempentry.length; - entries[i].data_location = BRLYT_fileoffset + sizeof(brlyt_entry_header); - BRLYT_fileoffset += be32(tempentry.length); - } + materials = (char*)malloc(12); + numberOfMaterials = 0; + lengthOfMaterials = 0; + textures = (char*)malloc(12); + numberOfTextures = 0; + lengthOfTextures = 0; + FILE* fp = fopen(filename, "rb"); + if(fp == NULL) { + printf("Error! Couldn't open %s!\n", filename); + exit(1); + } + fseek(fp, 0, SEEK_END); + size_t file_size = ftell(fp); + dbgprintf("Filesize is %d\n", file_size); + u8* brlyt_file = (u8*)malloc(file_size); + dbgprintf("brlyt_file allocated\n"); + fseek(fp, 0, SEEK_SET); + fread(brlyt_file, file_size, 1, fp); + dbgprintf("brlyt_file read to.\n"); + BRLYT_fileoffset = 0; + brlyt_header header; + BRLYT_ReadDataFromMemory(&header, brlyt_file, sizeof(brlyt_header)); + BRLYT_CheckHeaderSanity(header, file_size); + brlyt_entry *entries; + BRLYT_fileoffset = short_swap_bytes(header.lyt_offset); + brlyt_entry_header tempentry; + int i; + dbgprintf("curr %08x max %08x\n", BRLYT_fileoffset, file_size); + for(i = 0; BRLYT_fileoffset < file_size; i++) { + BRLYT_ReadDataFromMemoryX(&tempentry, brlyt_file, sizeof(brlyt_entry_header)); + BRLYT_fileoffset += be32(tempentry.length); + dbgprintf("curr %08x max %08x\n", BRLYT_fileoffset, file_size); + } + int entrycount = i; + entries = (brlyt_entry*)calloc(entrycount, sizeof(brlyt_entry)); + dbgprintf("%08x\n", entries); + if(entries == NULL) { + printf("Couldn't allocate for entries!\n"); + exit(1); + } + BRLYT_fileoffset = short_swap_bytes(header.lyt_offset); + for(i = 0; i < entrycount; i++) { + dbgprintf("&(entries[i]) = %08x\n", &(entries[i])); + BRLYT_ReadDataFromMemoryX(&tempentry, brlyt_file, sizeof(brlyt_entry_header)); + memcpy(entries[i].magic, tempentry.magic, 4); + entries[i].length = tempentry.length; + entries[i].data_location = BRLYT_fileoffset + sizeof(brlyt_entry_header); + BRLYT_fileoffset += be32(tempentry.length); + } - dbgprintf("%08x\n", entries); + dbgprintf("%08x\n", entries); #ifdef OLD_BRLYT_OUTSTYLE - printf("Parsed BRLYT! Information:\n"); - printf("Main header:\n"); - printf(" Magic: %c%c%c%c\n", header.magic[0], header.magic[1], header.magic[2], header.magic[3]); - printf(" Unk1: %08x\n", be32(header.unk1)); - printf(" Filesize: %lu\n", be32(header.filesize)); - printf(" %s real file size!\n", be32(header.filesize) == file_size ? "Matches" : "Does not match"); - printf(" Offset to lyt1: %04x\n", short_swap_bytes(header.lyt_offset)); - printf(" Unk2: %04x\n", short_swap_bytes(header.unk2)); - printf("\nBRLYT Entries:"); + printf("Parsed BRLYT! Information:\n"); + printf("Main header:\n"); + printf(" Magic: %c%c%c%c\n", header.magic[0], header.magic[1], header.magic[2], header.magic[3]); + printf(" Unk1: %08x\n", be32(header.unk1)); + printf(" Filesize: %lu\n", be32(header.filesize)); + printf(" %s real file size!\n", be32(header.filesize) == file_size ? "Matches" : "Does not match"); + printf(" Offset to lyt1: %04x\n", short_swap_bytes(header.lyt_offset)); + printf(" Unk2: %04x\n", short_swap_bytes(header.unk2)); + printf("\nBRLYT Entries:"); #else - printf("<?xml version=\"1.0\"?>\n" \ - "<xmlyt>\n"); + printf("<?xml version=\"1.0\"?>\n" \ + "<xmlyt>\n"); #endif //OLD_BRLYT_OUTSTYLE - PrintBRLYTEntries(entries, entrycount, brlyt_file); + PrintBRLYTEntries(entries, entrycount, brlyt_file); #ifndef OLD_BRLYT_OUTSTYLE - printf("</xmlyt>\n"); + printf("</xmlyt>\n"); #endif //OLD_BRLYT_OUTSTYLE - free(materials); - free(textures); + free(materials); + free(textures); } @@ -1195,118 +1195,118 @@ void parse_brlyt(char *filename) u32 create_entries_from_xml(mxml_node_t *tree, mxml_node_t *node, brlan_entry *entr, tag_header* head, u8** tagblob, u32* blobsize) { - tag_entry* entry = NULL; - tag_entryinfo* entryinfo = NULL; - tag_data** data = NULL; - mxml_node_t *tempnode = NULL; - mxml_node_t *subnode = NULL; - mxml_node_t *subsubnode = NULL; - char temp[256]; - char temp2[256]; - char temp3[15][24]; - int i, x; + tag_entry* entry = NULL; + tag_entryinfo* entryinfo = NULL; + tag_data** data = NULL; + mxml_node_t *tempnode = NULL; + mxml_node_t *subnode = NULL; + mxml_node_t *subsubnode = NULL; + char temp[256]; + char temp2[256]; + char temp3[15][24]; + int i, x; - for(i = 0; i < 16; i++) - memset(temp3[i], 0, 24); - for(x = 0; x < 16; x++) - 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++) { - 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); - else - data = (tag_data**)realloc(data, sizeof(tag_data*) * head->entry_count); - data[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 < 16) && (strcmp(temp3[i - 1], temp2) != 0); i++); - if(i == 16) - 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); - } - } - FILE* fp = fopen("temp.blan", "wb+"); - if(fp == NULL) { - printf("Couldn't open temporary temp.blan file\n"); - exit(1); - } - fseek(fp, 0, SEEK_SET); - entr->anim_header_len = 0; - WriteBRLANEntry(entr, fp); - WriteBRLANTagHeader(head, fp); - u32 entryloc = ftell(fp); - 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); - entry[x].offset = entryinfolocs[x] - sizeof(brlan_entry); - WriteBRLANTagEntryinfos(entryinfo[x], fp); - WriteBRLANTagData(data[x], entryinfo[x].coord_count, fp); - } - u32 oldpos = ftell(fp); - fseek(fp, entryloc, SEEK_SET); - WriteBRLANTagEntries(entry, head->entry_count, fp); - fseek(fp, oldpos, SEEK_SET); - u32 filesz = ftell(fp); - fseek(fp, 0, SEEK_SET); - entr->anim_header_len = sizeof(tag_header) + (sizeof(tag_entry) * head->entry_count); - WriteBRLANEntry(entr, fp); - *blobsize = filesz; - *tagblob = (u8*)malloc(*blobsize); - fseek(fp, 0, SEEK_SET); - fread(*tagblob, *blobsize, 1, fp); - free(entry); - free(entryinfo); - free(data); - fclose(fp); - remove("temp.blan"); - return filesz; + for(i = 0; i < 16; i++) + memset(temp3[i], 0, 24); + for(x = 0; x < 16; x++) + 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++) { + 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); + else + data = (tag_data**)realloc(data, sizeof(tag_data*) * head->entry_count); + data[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 < 16) && (strcmp(temp3[i - 1], temp2) != 0); i++); + if(i == 16) + 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); + } + } + FILE* fp = fopen("temp.blan", "wb+"); + if(fp == NULL) { + printf("Couldn't open temporary temp.blan file\n"); + exit(1); + } + fseek(fp, 0, SEEK_SET); + entr->anim_header_len = 0; + WriteBRLANEntry(entr, fp); + WriteBRLANTagHeader(head, fp); + u32 entryloc = ftell(fp); + 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); + entry[x].offset = entryinfolocs[x] - sizeof(brlan_entry); + WriteBRLANTagEntryinfos(entryinfo[x], fp); + WriteBRLANTagData(data[x], entryinfo[x].coord_count, fp); + } + u32 oldpos = ftell(fp); + fseek(fp, entryloc, SEEK_SET); + WriteBRLANTagEntries(entry, head->entry_count, fp); + fseek(fp, oldpos, SEEK_SET); + u32 filesz = ftell(fp); + fseek(fp, 0, SEEK_SET); + entr->anim_header_len = sizeof(tag_header) + (sizeof(tag_entry) * head->entry_count); + WriteBRLANEntry(entr, fp); + *blobsize = filesz; + *tagblob = (u8*)malloc(*blobsize); + fseek(fp, 0, SEEK_SET); + fread(*tagblob, *blobsize, 1, fp); + free(entry); + free(entryinfo); + free(data); + fclose(fp); + remove("temp.blan"); + return filesz; } */ @@ -1314,1554 +1314,1554 @@ u32 create_entries_from_xml(mxml_node_t *tree, mxml_node_t *node, brlan_entry *e void create_tag_from_xml(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* blobsize) { -// tag_header head; - brlyt_entry entry; - char temp[256]; - memset(entry.name, 0, 20); +// tag_header head; + brlyt_entry entry; + char temp[256]; + memset(entry.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")); - else{ - printf("No type attribute found!\nQuitting!\n"); - exit(1); - } - entry.magic[0] = temp[0]; - entry.magic[1] = temp[1]; - entry.magic[2] = temp[2]; - entry.magic[3] = temp[3]; - entry.length = 0; - entry.data_location = 0; + if(mxmlElementGetAttr(node, "type") != NULL) + strcpy(temp, mxmlElementGetAttr(node, "type")); + else{ + printf("No type attribute found!\nQuitting!\n"); + exit(1); + } + entry.magic[0] = temp[0]; + entry.magic[1] = temp[1]; + entry.magic[2] = temp[2]; + entry.magic[3] = temp[3]; + entry.length = 0; + entry.data_location = 0; -// if(mxmlElementGetAttr(node, "format") != NULL) -// strcpy(temp, mxmlElementGetAttr(node, "format")); -// else{ -// printf("No format attribute found!\nQuitting!\n"); -// exit(1); -// } - int x; -// for(x = 0; x < strlen(temp); x++) -// temp[x] = toupper(temp[x]); -// if(strcmp(temp, "NORMAL") == 0) -// entr.flags = 0x01000000; -// else -// entr.flags = atoi(temp); - create_entries_from_xml(tree, node, &entr, &head, tagblob, blobsize); +// if(mxmlElementGetAttr(node, "format") != NULL) +// strcpy(temp, mxmlElementGetAttr(node, "format")); +// else{ +// printf("No format attribute found!\nQuitting!\n"); +// exit(1); +// } + int x; +// for(x = 0; x < strlen(temp); x++) +// temp[x] = toupper(temp[x]); +// if(strcmp(temp, "NORMAL") == 0) +// entr.flags = 0x01000000; +// else +// entr.flags = atoi(temp); + create_entries_from_xml(tree, node, &entr, &head, tagblob, blobsize); } */ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* blobsize, char temp[4], FILE* fp, unsigned int *fileOffset) { - unsigned int startOfChunk = *fileOffset; + unsigned int 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'}; + 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; + if ( memcmp(temp, lyt1, sizeof(lyt1)) == 0) + { + brlyt_lytheader_chunk lytheader; - mxml_node_t *subnode = mxmlFindElement(node , node , "a", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempChar[4]; - get_value(subnode, tempChar, 256); - lytheader.a = 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 something; - *(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); + mxml_node_t *subnode = mxmlFindElement(node , node , "a", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempChar[4]; + get_value(subnode, tempChar, 256); + lytheader.a = 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 something; + *(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); + 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; + 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; + u32 *offsunks; - offsunks = malloc(sizeof(u32)); + 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)) { + 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) - { + if (valnode != NULL) + { - char tempSub[256]; - get_value(valnode, tempSub, 256); + char tempSub[256]; + get_value(valnode, tempSub, 256); - oldNameLength = lengthOfNames; - lengthOfNames += strlen(tempSub); + oldNameLength = lengthOfNames; + lengthOfNames += strlen(tempSub); - offsunks = realloc(offsunks, (numEntries + 1)*(2 * sizeof(u32))); - if (offsunks == NULL) printf("NULLed by a realloc\n"); + 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; + offsunks[(numEntries*2)+0] = baseOffset; + offsunks[(numEntries*2)+1] = 0; - *fileOffset = *fileOffset + sizeof(chunk2); - numEntries++; - - baseOffset += (strlen(tempSub) + 1); + *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); + 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<numEntries;i++) { - offsunks[(i*2)+0] = be32(offsunks[(i*2)+0] + (numEntries * 8)); - offsunks[i*2+1] = 0; // MIGHT NOT BE 0 ? // + int i; + for(i=0;i<numEntries;i++) { + offsunks[(i*2)+0] = be32(offsunks[(i*2)+0] + (numEntries * 8)); + offsunks[i*2+1] = 0; // MIGHT NOT BE 0 ? // - fwrite(&offsunks[i*2], sizeof(u32), 1, fp); - fwrite(&offsunks[i*2+1], sizeof(u32), 1, fp); - } - free(offsunks); - } - fseek(fp, *fileOffset, SEEK_SET); - fwrite(names, lengthOfNames, 1, fp); - *fileOffset = *fileOffset + lengthOfNames; - if ((*fileOffset % 4) > 0) - { - u8 toAdd = 4-(*fileOffset % 4); - char nuller[3] = {'\0', '\0', '\0'}; - fwrite(&nuller, sizeof(char), toAdd, fp); - *fileOffset = *fileOffset + toAdd; - } -// materials = malloc(lengthOfNames * sizeof(char)); -// memcpy(materials, names, lengthOfNames * sizeof(char)); -// free(names); - 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); + fwrite(&offsunks[i*2], sizeof(u32), 1, fp); + fwrite(&offsunks[i*2+1], sizeof(u32), 1, fp); + } + free(offsunks); + } + fseek(fp, *fileOffset, SEEK_SET); + fwrite(names, lengthOfNames, 1, fp); + *fileOffset = *fileOffset + lengthOfNames; + if ((*fileOffset % 4) > 0) + { + u8 toAdd = 4-(*fileOffset % 4); + char nuller[3] = {'\0', '\0', '\0'}; + fwrite(&nuller, sizeof(char), toAdd, fp); + *fileOffset = *fileOffset + toAdd; + } +// materials = malloc(lengthOfNames * sizeof(char)); +// memcpy(materials, names, lengthOfNames * sizeof(char)); +// free(names); + 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; + 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; + int oldNameLength; + int baseOffset = 0; + int numoffsOffset = *fileOffset - 4; - u32 *offsunks; - offsunks = malloc(sizeof(u32)); + 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)) { + 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); + if (valnode != NULL) + { + char tempSub[256]; + get_value(valnode, tempSub, 256); - oldNameLength = lengthOfNames; - lengthOfNames += strlen(tempSub); + oldNameLength = lengthOfNames; + lengthOfNames += strlen(tempSub); - offsunks = realloc(offsunks, (numEntries + 1)*(2 * sizeof(u32))); - offsunks[(numEntries*2)+0] = baseOffset; - offsunks[(numEntries*2)+1] = 0; + 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); + *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<numEntries;i++) { - offsunks[(i*2)+0] = be32(offsunks[(i*2)+0] + (numEntries * 8)); - offsunks[i*2+1] = 0; + int i; + for(i=0;i<numEntries;i++) { + offsunks[(i*2)+0] = be32(offsunks[(i*2)+0] + (numEntries * 8)); + offsunks[i*2+1] = 0; - fwrite(&offsunks[i*2], sizeof(u32), 1, fp); - fwrite(&offsunks[i*2+1], sizeof(u32), 1, fp); - } - free(offsunks); - } - fseek(fp, *fileOffset, SEEK_SET); - fwrite(names, lengthOfNames, 1, fp); - *fileOffset = *fileOffset + lengthOfNames; - if ((*fileOffset % 4) > 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) - { + fwrite(&offsunks[i*2], sizeof(u32), 1, fp); + fwrite(&offsunks[i*2+1], sizeof(u32), 1, fp); + } + free(offsunks); + } + fseek(fp, *fileOffset, SEEK_SET); + fwrite(names, lengthOfNames, 1, fp); + *fileOffset = *fileOffset + lengthOfNames; + if ((*fileOffset % 4) > 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++; + 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); + 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)); + 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); //changed from numberOfEntries + offsets[numberOfEntries] = be32(matSize + initialOffset); + fwrite(&offsets[0], sizeof(int), actualNumber, fp); + *fileOffset = *fileOffset + (actualNumber * 4); //changed from numberOfEntries - 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); - } - char zeroed[24]; - int j; - for (j=0; j<24; j++) - { - zeroed[j] = 0; - } - memcpy(chunk.name, zeroed, 20 * sizeof(char)); - strcpy(chunk.name, temp); + 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); + } + char zeroed[24]; + int j; + for (j=0; j<24; j++) + { + zeroed[j] = 0; + } + memcpy(chunk.name, zeroed, 20 * sizeof(char)); + 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; + 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, "tev", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "tev", NULL, NULL, MXML_DESCEND) ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - - chunk.tev_color[colorNumber] = strtoul(tempCoord, NULL, 16); + 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, "tev", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "tev", NULL, NULL, MXML_DESCEND) ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + + chunk.tev_color[colorNumber] = strtoul(tempCoord, NULL, 16); - chunk.tev_color[colorNumber] = short_swap_bytes(chunk.tev_color[colorNumber]); + chunk.tev_color[colorNumber] = short_swap_bytes(chunk.tev_color[colorNumber]); - colorNumber+=1; - } - colorNumber = 0; - for (valnode=mxmlFindElement(setnode, setnode, "unk", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "unk", NULL, NULL, MXML_DESCEND) ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - - chunk.unk_color[colorNumber] = strtoul(tempCoord, NULL, 16); + colorNumber+=1; + } + colorNumber = 0; + for (valnode=mxmlFindElement(setnode, setnode, "unk", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "unk", NULL, NULL, MXML_DESCEND) ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + + chunk.unk_color[colorNumber] = strtoul(tempCoord, NULL, 16); - chunk.unk_color[colorNumber] = short_swap_bytes(chunk.unk_color[colorNumber]); + chunk.unk_color[colorNumber] = short_swap_bytes(chunk.unk_color[colorNumber]); - colorNumber+=1; - } - colorNumber = 0; - for (valnode=mxmlFindElement(setnode, setnode, "unk2", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "unk2", NULL, NULL, MXML_DESCEND) ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - - chunk.unk_color_2[colorNumber] = strtoul(tempCoord, NULL, 16); + colorNumber+=1; + } + colorNumber = 0; + for (valnode=mxmlFindElement(setnode, setnode, "unk2", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "unk2", NULL, NULL, MXML_DESCEND) ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + + chunk.unk_color_2[colorNumber] = strtoul(tempCoord, NULL, 16); - chunk.unk_color_2[colorNumber] = short_swap_bytes(chunk.unk_color_2[colorNumber]); + chunk.unk_color_2[colorNumber] = short_swap_bytes(chunk.unk_color_2[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)); - } + 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)); + } - fwrite(&chunk, sizeof(chunk), 1, fp); - *fileOffset = *fileOffset + sizeof(chunk); - matSize += sizeof(chunk); + fwrite(&chunk, sizeof(chunk), 1, fp); + *fileOffset = *fileOffset + sizeof(chunk); + matSize += sizeof(chunk); - brlyt_texref_chunk chunkTexRef; - setnode = mxmlFindElement(subnode, subnode, "material", NULL, NULL, MXML_DESCEND); - if (setnode != NULL) - { - 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)); + brlyt_texref_chunk chunkTexRef; + setnode = mxmlFindElement(subnode, subnode, "material", NULL, NULL, MXML_DESCEND); + if (setnode != NULL) + { + 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); + valnode=mxmlFindElement(setnode, setnode, "wrap_s", NULL, NULL, MXML_DESCEND); - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunkTexRef.wrap_s = strtoul(tempCoord, NULL, 16); + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunkTexRef.wrap_s = strtoul(tempCoord, NULL, 16); - 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); - chunkTexRef.wrap_t = strtoul(tempCoord, NULL, 16); + get_value(valnode, tempCoord, 256); + chunkTexRef.wrap_t = strtoul(tempCoord, NULL, 16); - fwrite(&chunkTexRef, sizeof(chunkTexRef), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkTexRef); - matSize += sizeof(chunkTexRef); - } + fwrite(&chunkTexRef, sizeof(chunkTexRef), 1, fp); + *fileOffset = *fileOffset + sizeof(chunkTexRef); + matSize += sizeof(chunkTexRef); + } - brlyt_ua2_chunk chunkUa2; - setnode = mxmlFindElement(subnode, subnode, "ua2", NULL, NULL, MXML_DESCEND); - if (setnode != NULL) - { - 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); + brlyt_ua2_chunk chunkUa2; + setnode = mxmlFindElement(subnode, subnode, "ua2", NULL, NULL, MXML_DESCEND); + if (setnode != NULL) + { + 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); - chunkUa2.unk[dataNumber] = float_swap_bytes(atof(tempCoord)); - - dataNumber+=1; - } - fwrite(&chunkUa2, sizeof(chunkUa2), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkUa2); - matSize += sizeof(chunkUa2); - } - brlyt_4b_chunk chunkUa3; - setnode = mxmlFindElement(subnode, subnode, "ua3", NULL, NULL, MXML_DESCEND); - if (setnode != NULL) - { - 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); + chunkUa2.unk[dataNumber] = float_swap_bytes(atof(tempCoord)); + + dataNumber+=1; + } + fwrite(&chunkUa2, sizeof(chunkUa2), 1, fp); + *fileOffset = *fileOffset + sizeof(chunkUa2); + matSize += sizeof(chunkUa2); + } + brlyt_4b_chunk chunkUa3; + setnode = mxmlFindElement(subnode, subnode, "ua3", NULL, NULL, MXML_DESCEND); + if (setnode != NULL) + { + 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); - chunkUa3.unk[dataNumber] = strtoul(tempCoord, NULL, 16); + chunkUa3.unk[dataNumber] = strtoul(tempCoord, NULL, 16); - dataNumber+=1; - } - fwrite(&chunkUa3, sizeof(chunkUa3), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkUa3); - matSize += sizeof(chunkUa3); - } - brlyt_4b_chunk chunkUa4; - setnode = mxmlFindElement(subnode, subnode, "ua4", NULL, NULL, MXML_DESCEND); - if (setnode != NULL) - { - 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); + dataNumber+=1; + } + fwrite(&chunkUa3, sizeof(chunkUa3), 1, fp); + *fileOffset = *fileOffset + sizeof(chunkUa3); + matSize += sizeof(chunkUa3); + } + brlyt_4b_chunk chunkUa4; + setnode = mxmlFindElement(subnode, subnode, "ua4", NULL, NULL, MXML_DESCEND); + if (setnode != NULL) + { + 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); - chunkUa4.unk[dataNumber] = strtoul(tempCoord, NULL, 16); + chunkUa4.unk[dataNumber] = strtoul(tempCoord, NULL, 16); - dataNumber+=1; - } - fwrite(&chunkUa4, sizeof(chunkUa4), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkUa4); - matSize += sizeof(chunkUa4); - } - brlyt_4b_chunk chunkUa5; - setnode = mxmlFindElement(subnode, subnode, "ua5", NULL, NULL, MXML_DESCEND); - if (setnode != NULL) - { - 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); + dataNumber+=1; + } + fwrite(&chunkUa4, sizeof(chunkUa4), 1, fp); + *fileOffset = *fileOffset + sizeof(chunkUa4); + matSize += sizeof(chunkUa4); + } + brlyt_4b_chunk chunkUa5; + setnode = mxmlFindElement(subnode, subnode, "ua5", NULL, NULL, MXML_DESCEND); + if (setnode != NULL) + { + 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); - chunkUa5.unk[dataNumber] = strtoul(tempCoord, NULL, 16); + chunkUa5.unk[dataNumber] = strtoul(tempCoord, NULL, 16); - dataNumber+=1; - } - fwrite(&chunkUa5, sizeof(chunkUa5), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkUa5); - matSize += sizeof(chunkUa5); - } - brlyt_4b_chunk chunkUa6; - setnode = mxmlFindElement(subnode, subnode, "ua6", NULL, NULL, MXML_DESCEND); - if (setnode != NULL) - { - 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); + dataNumber+=1; + } + fwrite(&chunkUa5, sizeof(chunkUa5), 1, fp); + *fileOffset = *fileOffset + sizeof(chunkUa5); + matSize += sizeof(chunkUa5); + } + brlyt_4b_chunk chunkUa6; + setnode = mxmlFindElement(subnode, subnode, "ua6", NULL, NULL, MXML_DESCEND); + if (setnode != NULL) + { + 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); - chunkUa6.unk[dataNumber] = strtoul(tempCoord, NULL, 16); + chunkUa6.unk[dataNumber] = strtoul(tempCoord, NULL, 16); - dataNumber+=1; - } - fwrite(&chunkUa6, sizeof(chunkUa6), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkUa6); - matSize += sizeof(chunkUa6); - } - brlyt_ua7_chunk chunkUa7; - setnode = mxmlFindElement(subnode, subnode, "ua7", NULL, NULL, MXML_DESCEND); - if (setnode != NULL) - { - mxml_node_t *valnode; - valnode=mxmlFindElement(setnode, setnode, "a", NULL, NULL, MXML_DESCEND); - if ( valnode != NULL ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); + dataNumber+=1; + } + fwrite(&chunkUa6, sizeof(chunkUa6), 1, fp); + *fileOffset = *fileOffset + sizeof(chunkUa6); + matSize += sizeof(chunkUa6); + } + brlyt_ua7_chunk chunkUa7; + setnode = mxmlFindElement(subnode, subnode, "ua7", NULL, NULL, MXML_DESCEND); + if (setnode != NULL) + { + mxml_node_t *valnode; + valnode=mxmlFindElement(setnode, setnode, "a", NULL, NULL, MXML_DESCEND); + if ( valnode != NULL ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); - chunkUa7.a = be32(strtoul(tempCoord, NULL, 16)); - } - valnode=mxmlFindElement(setnode, setnode, "b", NULL, NULL, MXML_DESCEND); - if ( valnode != NULL ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); + chunkUa7.a = be32(strtoul(tempCoord, NULL, 16)); + } + valnode=mxmlFindElement(setnode, setnode, "b", NULL, NULL, MXML_DESCEND); + if ( valnode != NULL ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); - chunkUa7.b = be32(strtoul(tempCoord, NULL, 16)); - } - valnode=mxmlFindElement(setnode, setnode, "c", NULL, NULL, MXML_DESCEND); - if ( valnode != NULL ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); + chunkUa7.b = be32(strtoul(tempCoord, NULL, 16)); + } + valnode=mxmlFindElement(setnode, setnode, "c", NULL, NULL, MXML_DESCEND); + if ( valnode != NULL ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); - chunkUa7.c = float_swap_bytes(atof(tempCoord)); - } - valnode=mxmlFindElement(setnode, setnode, "d", NULL, NULL, MXML_DESCEND); - if ( valnode != NULL ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); + chunkUa7.c = float_swap_bytes(atof(tempCoord)); + } + valnode=mxmlFindElement(setnode, setnode, "d", NULL, NULL, MXML_DESCEND); + if ( valnode != NULL ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); - chunkUa7.d = be32(strtoul(tempCoord, NULL, 16)); - } - valnode=mxmlFindElement(setnode, setnode, "e", NULL, NULL, MXML_DESCEND); - if ( valnode != NULL ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); + chunkUa7.d = be32(strtoul(tempCoord, NULL, 16)); + } + valnode=mxmlFindElement(setnode, setnode, "e", NULL, NULL, MXML_DESCEND); + if ( valnode != NULL ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); - chunkUa7.e = be32(strtoul(tempCoord, NULL, 16)); - } - fwrite(&chunkUa7, sizeof(chunkUa7), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkUa7); - matSize += sizeof(chunkUa7); - } - brlyt_4b_chunk chunkUa8; - setnode = mxmlFindElement(subnode, subnode, "ua8", NULL, NULL, MXML_DESCEND); - if (setnode != NULL) - { - 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); + chunkUa7.e = be32(strtoul(tempCoord, NULL, 16)); + } + fwrite(&chunkUa7, sizeof(chunkUa7), 1, fp); + *fileOffset = *fileOffset + sizeof(chunkUa7); + matSize += sizeof(chunkUa7); + } + brlyt_4b_chunk chunkUa8; + setnode = mxmlFindElement(subnode, subnode, "ua8", NULL, NULL, MXML_DESCEND); + if (setnode != NULL) + { + 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); - chunkUa8.unk[dataNumber] = strtoul(tempCoord, NULL, 16); + chunkUa8.unk[dataNumber] = strtoul(tempCoord, NULL, 16); - dataNumber+=1; - } - fwrite(&chunkUa8, sizeof(chunkUa8), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkUa8); - matSize += sizeof(chunkUa8); - } - brlyt_10b_chunk chunkUa9; - for (setnode = mxmlFindElement(subnode, subnode, "ua9", NULL, NULL, MXML_DESCEND); setnode != NULL; setnode = mxmlFindElement(setnode, subnode, "ua9", NULL, NULL, MXML_DESCEND)) -// if (setnode != NULL) - { - 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); + dataNumber+=1; + } + fwrite(&chunkUa8, sizeof(chunkUa8), 1, fp); + *fileOffset = *fileOffset + sizeof(chunkUa8); + matSize += sizeof(chunkUa8); + } + brlyt_10b_chunk chunkUa9; + for (setnode = mxmlFindElement(subnode, subnode, "ua9", NULL, NULL, MXML_DESCEND); setnode != NULL; setnode = mxmlFindElement(setnode, subnode, "ua9", NULL, NULL, MXML_DESCEND)) +// if (setnode != NULL) + { + 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); - chunkUa9.unk[dataNumber] = strtoul(tempCoord, NULL, 16); + chunkUa9.unk[dataNumber] = strtoul(tempCoord, NULL, 16); - dataNumber+=1; - } - fwrite(&chunkUa9, sizeof(chunkUa9), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkUa9); - matSize += sizeof(chunkUa9); - } - brlyt_4b_chunk chunkUaa; - setnode = mxmlFindElement(subnode, subnode, "uaa", NULL, NULL, MXML_DESCEND); - if (setnode != NULL) - { - 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); + dataNumber+=1; + } + fwrite(&chunkUa9, sizeof(chunkUa9), 1, fp); + *fileOffset = *fileOffset + sizeof(chunkUa9); + matSize += sizeof(chunkUa9); + } + brlyt_4b_chunk chunkUaa; + setnode = mxmlFindElement(subnode, subnode, "uaa", NULL, NULL, MXML_DESCEND); + if (setnode != NULL) + { + 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); + chunkUaa.unk[dataNumber] = strtoul(tempCoord, NULL, 16); - dataNumber+=1; - } - fwrite(&chunkUaa, sizeof(chunkUaa), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkUaa); - matSize += sizeof(chunkUaa); - } - brlyt_4b_chunk chunkUab; - setnode = mxmlFindElement(subnode, subnode, "uab", NULL, NULL, MXML_DESCEND); - if (setnode != NULL) - { - 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); + dataNumber+=1; + } + fwrite(&chunkUaa, sizeof(chunkUaa), 1, fp); + *fileOffset = *fileOffset + sizeof(chunkUaa); + matSize += sizeof(chunkUaa); + } + brlyt_4b_chunk chunkUab; + setnode = mxmlFindElement(subnode, subnode, "uab", NULL, NULL, MXML_DESCEND); + if (setnode != NULL) + { + 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); + chunkUab.unk[dataNumber] = strtoul(tempCoord, NULL, 16); - dataNumber+=1; - } - fwrite(&chunkUab, sizeof(chunkUab), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkUab); - matSize += sizeof(chunkUab); - } - 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; + dataNumber+=1; + } + fwrite(&chunkUab, sizeof(chunkUab), 1, fp); + *fileOffset = *fileOffset + sizeof(chunkUab); + matSize += sizeof(chunkUab); + } + 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; - if(mxmlElementGetAttr(node, "name") != NULL) - strcpy(temp, mxmlElementGetAttr(node, "name")); - else{ - printf("No name attribute found!\nQuitting!\n"); - exit(1); - } - char zeroed[24]; - int j; - for (j=0; j<24; j++) - { - zeroed[j] = 0; - } - memcpy(chunk.name, zeroed, 24 * sizeof(char)); - strcpy(chunk.name, temp); + if(mxmlElementGetAttr(node, "name") != NULL) + strcpy(temp, mxmlElementGetAttr(node, "name")); + else{ + printf("No name attribute found!\nQuitting!\n"); + exit(1); + } + char zeroed[24]; + int j; + for (j=0; j<24; j++) + { + zeroed[j] = 0; + } + memcpy(chunk.name, zeroed, 24 * sizeof(char)); + strcpy(chunk.name, temp); - mxml_node_t *subnode = mxmlFindElement(node, node, "coords", 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.x = 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)); - } - 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)); - } - } - subnode = mxmlFindElement(node, node, "flip", 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.flip_x = 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)); - } - } - subnode = mxmlFindElement(node, node, "zoom", 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.xmag = 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)); - } - } - 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, "flags", 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[9]), NULL, 16); - } - 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); - chunk.alpha2 = strtol(&(tempCoord[9]), NULL, 16); - } - subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - chunk.angle = float_swap_bytes(atof(tempCoord)); - } - fwrite(&chunk, sizeof(chunk), 1, fp); - *fileOffset = *fileOffset + sizeof(chunk); - } - if ( memcmp(temp, bnd1, sizeof(bnd1)) == 0) - { - brlyt_pane_chunk chunk; + mxml_node_t *subnode = mxmlFindElement(node, node, "coords", 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.x = 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)); + } + 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)); + } + } + subnode = mxmlFindElement(node, node, "flip", 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.flip_x = 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)); + } + } + subnode = mxmlFindElement(node, node, "zoom", 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.xmag = 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)); + } + } + 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, "flags", 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[9]), NULL, 16); + } + 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); + chunk.alpha2 = strtol(&(tempCoord[9]), NULL, 16); + } + subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + chunk.angle = float_swap_bytes(atof(tempCoord)); + } + fwrite(&chunk, sizeof(chunk), 1, fp); + *fileOffset = *fileOffset + sizeof(chunk); + } + if ( memcmp(temp, bnd1, sizeof(bnd1)) == 0) + { + brlyt_pane_chunk chunk; - if(mxmlElementGetAttr(node, "name") != NULL) - strcpy(temp, mxmlElementGetAttr(node, "name")); - else{ - printf("No name attribute found!\nQuitting!\n"); - exit(1); - } - char zeroed[24]; - int j; - for (j=0; j<24; j++) - { - zeroed[j] = 0; - } - memcpy(chunk.name, zeroed, 24 * sizeof(char)); - strcpy(chunk.name, temp); + if(mxmlElementGetAttr(node, "name") != NULL) + strcpy(temp, mxmlElementGetAttr(node, "name")); + else{ + printf("No name attribute found!\nQuitting!\n"); + exit(1); + } + char zeroed[24]; + int j; + for (j=0; j<24; j++) + { + zeroed[j] = 0; + } + memcpy(chunk.name, zeroed, 24 * sizeof(char)); + strcpy(chunk.name, temp); - mxml_node_t *subnode = mxmlFindElement(node, node, "coords", 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.x = 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)); - } - 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)); - } - } - subnode = mxmlFindElement(node, node, "flip", 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.flip_x = 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)); - } - } - subnode = mxmlFindElement(node, node, "zoom", 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.xmag = 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)); - } - } - 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, "flags", 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[9]), NULL, 16); - } - 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); - chunk.alpha2 = strtol(&(tempCoord[9]), NULL, 16); - } - subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - chunk.angle = float_swap_bytes(atof(tempCoord)); - } - fwrite(&chunk, sizeof(chunk), 1, fp); - *fileOffset = *fileOffset + sizeof(chunk); - } - if ( memcmp(temp, wnd1, sizeof(wnd1)) == 0) - { - brlyt_pane_chunk chunk; + mxml_node_t *subnode = mxmlFindElement(node, node, "coords", 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.x = 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)); + } + 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)); + } + } + subnode = mxmlFindElement(node, node, "flip", 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.flip_x = 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)); + } + } + subnode = mxmlFindElement(node, node, "zoom", 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.xmag = 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)); + } + } + 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, "flags", 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[9]), NULL, 16); + } + 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); + chunk.alpha2 = strtol(&(tempCoord[9]), NULL, 16); + } + subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + chunk.angle = float_swap_bytes(atof(tempCoord)); + } + fwrite(&chunk, sizeof(chunk), 1, fp); + *fileOffset = *fileOffset + sizeof(chunk); + } + if ( memcmp(temp, wnd1, sizeof(wnd1)) == 0) + { + brlyt_pane_chunk chunk; - if(mxmlElementGetAttr(node, "name") != NULL) - strcpy(temp, mxmlElementGetAttr(node, "name")); - else{ - printf("No name attribute found!\nQuitting!\n"); - exit(1); - } - char zeroed[24]; - int j; - for (j=0; j<24; j++) zeroed[j] = 0; - memcpy(chunk.name, zeroed, 24 * sizeof(char)); - strcpy(chunk.name, temp); + if(mxmlElementGetAttr(node, "name") != NULL) + strcpy(temp, mxmlElementGetAttr(node, "name")); + else{ + printf("No name attribute found!\nQuitting!\n"); + exit(1); + } + char zeroed[24]; + int j; + for (j=0; j<24; j++) zeroed[j] = 0; + memcpy(chunk.name, zeroed, 24 * sizeof(char)); + strcpy(chunk.name, temp); - mxml_node_t *subnode = mxmlFindElement(node, node, "coords", 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.x = 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)); - } - 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)); - } - } - subnode = mxmlFindElement(node, node, "flip", 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.flip_x = 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)); - } - } - subnode = mxmlFindElement(node, node, "zoom", 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.xmag = 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)); - } - } - 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, "flags", 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[9]), NULL, 16); - } - 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); - chunk.alpha2 = strtol(&(tempCoord[9]), NULL, 16); - } - subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - chunk.angle = float_swap_bytes(atof(tempCoord)); - } - fwrite(&chunk, sizeof(chunk), 1, fp); - *fileOffset = *fileOffset + sizeof(chunk); - } - if ( memcmp(temp, txt1, sizeof(txt1)) == 0) - { - brlyt_pane_chunk chunk; - brlyt_text_chunk chunk2; + mxml_node_t *subnode = mxmlFindElement(node, node, "coords", 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.x = 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)); + } + 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)); + } + } + subnode = mxmlFindElement(node, node, "flip", 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.flip_x = 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)); + } + } + subnode = mxmlFindElement(node, node, "zoom", 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.xmag = 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)); + } + } + 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, "flags", 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[9]), NULL, 16); + } + 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); + chunk.alpha2 = strtol(&(tempCoord[9]), NULL, 16); + } + subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + chunk.angle = float_swap_bytes(atof(tempCoord)); + } + fwrite(&chunk, sizeof(chunk), 1, fp); + *fileOffset = *fileOffset + sizeof(chunk); + } + if ( memcmp(temp, txt1, sizeof(txt1)) == 0) + { + brlyt_pane_chunk chunk; + brlyt_text_chunk chunk2; - if(mxmlElementGetAttr(node, "name") != NULL) - strcpy(temp, mxmlElementGetAttr(node, "name")); - else{ - printf("No name attribute found!\nQuitting!\n"); - exit(1); - } - char zeroed[24]; - int j; - for (j=0; j<24; j++) zeroed[j] = 0; - memcpy(chunk.name, zeroed, 24 * sizeof(char)); - strcpy(chunk.name, temp); - chunk2.mat_off = short_swap_bytes(findMatOffset(temp)); + if(mxmlElementGetAttr(node, "name") != NULL) + strcpy(temp, mxmlElementGetAttr(node, "name")); + else{ + printf("No name attribute found!\nQuitting!\n"); + exit(1); + } + char zeroed[24]; + int j; + for (j=0; j<24; j++) zeroed[j] = 0; + memcpy(chunk.name, zeroed, 24 * sizeof(char)); + strcpy(chunk.name, temp); + chunk2.mat_off = short_swap_bytes(findMatOffset(temp)); - mxml_node_t *subnode = mxmlFindElement(node, node, "coords", 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.x = 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)); - } - 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)); - } - } - subnode = mxmlFindElement(node, node, "flip", 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.flip_x = 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)); - } - } - subnode = mxmlFindElement(node, node, "zoom", 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.xmag = 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)); - } - } - 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, "flags", 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[9]), NULL, 16); - } - 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); - chunk.alpha2 = strtol(&(tempCoord[9]), NULL, 16); - } - subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - chunk.angle = float_swap_bytes(atof(tempCoord)); - } + mxml_node_t *subnode = mxmlFindElement(node, node, "coords", 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.x = 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)); + } + 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)); + } + } + subnode = mxmlFindElement(node, node, "flip", 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.flip_x = 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)); + } + } + subnode = mxmlFindElement(node, node, "zoom", 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.xmag = 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)); + } + } + 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, "flags", 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[9]), NULL, 16); + } + 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); + chunk.alpha2 = strtol(&(tempCoord[9]), NULL, 16); + } + subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + chunk.angle = float_swap_bytes(atof(tempCoord)); + } -// brlyt_text_chunk chunk2; - 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); +// brlyt_text_chunk chunk2; + 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, "unk", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk2.unk4 = strtol(tempCoord, NULL, 16); - } - } + 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, "unk", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk2.unk4 = strtol(tempCoord, NULL, 16); + } + } - 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, "color", 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)); - } - u8 textyLength = short_swap_bytes(chunk2.len2); - if ((textyLength % 4) != 0) - textyLength += (4 - (textyLength % 4)); - unsigned char texty[textyLength]; - subnode = mxmlFindElement(node, node, "text", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - //memcpy(texty, tempCoord, short_swap_bytes(chunk2.len2)); - ASCIIfromUnicode(texty, tempCoord, short_swap_bytes(chunk2.len2)); - } - fwrite(&chunk, sizeof(chunk), 1, fp); - *fileOffset = *fileOffset + sizeof(chunk); + 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, "color", 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)); + } + u8 textyLength = short_swap_bytes(chunk2.len2); + if ((textyLength % 4) != 0) + textyLength += (4 - (textyLength % 4)); + unsigned char texty[textyLength]; + subnode = mxmlFindElement(node, node, "text", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + //memcpy(texty, tempCoord, short_swap_bytes(chunk2.len2)); + ASCIIfromUnicode(texty, tempCoord, short_swap_bytes(chunk2.len2)); + } + fwrite(&chunk, sizeof(chunk), 1, fp); + *fileOffset = *fileOffset + sizeof(chunk); - chunk2.name_offs=be32(0x74); - chunk2.pad[0]= 0;chunk2.pad[1]=0;chunk2.pad[2]=0; - fwrite(&chunk2, sizeof(chunk2), 1, fp); - *fileOffset = *fileOffset + sizeof(chunk2); - int q; for (q=short_swap_bytes(chunk2.len2);q<textyLength;q++) - { - q++; - texty[q] = 0x00; - } - fwrite(texty, textyLength, 1, fp); - *fileOffset = *fileOffset + textyLength; - } - if ( memcmp(temp, pic1, sizeof(pic1)) == 0) - { - brlyt_pane_chunk chunk; + chunk2.name_offs=be32(0x74); + chunk2.pad[0]= 0;chunk2.pad[1]=0;chunk2.pad[2]=0; + fwrite(&chunk2, sizeof(chunk2), 1, fp); + *fileOffset = *fileOffset + sizeof(chunk2); + int q; for (q=short_swap_bytes(chunk2.len2);q<textyLength;q++) + { + q++; + texty[q] = 0x00; + } + fwrite(texty, textyLength, 1, fp); + *fileOffset = *fileOffset + textyLength; + } + if ( memcmp(temp, pic1, sizeof(pic1)) == 0) + { + brlyt_pane_chunk chunk; - if(mxmlElementGetAttr(node, "name") != NULL) - strcpy(temp, mxmlElementGetAttr(node, "name")); - else{ - printf("No name attribute found!\nQuitting!\n"); - exit(1); - } - char zeroed[24]; - int j; - for (j=0; j<24; j++) zeroed[j] = 0; - memcpy(chunk.name, zeroed, 24 * sizeof(char)); - strcpy(chunk.name, temp); + if(mxmlElementGetAttr(node, "name") != NULL) + strcpy(temp, mxmlElementGetAttr(node, "name")); + else{ + printf("No name attribute found!\nQuitting!\n"); + exit(1); + } + char zeroed[24]; + int j; + for (j=0; j<24; j++) zeroed[j] = 0; + memcpy(chunk.name, zeroed, 24 * sizeof(char)); + strcpy(chunk.name, temp); - mxml_node_t *subnode = mxmlFindElement(node, node, "coords", 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.x = 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)); - } - 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)); - } - } - subnode = mxmlFindElement(node, node, "flip", 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.flip_x = 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)); - } - } - subnode = mxmlFindElement(node, node, "zoom", 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.xmag = 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)); - } - } - 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, "flags", 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[9]), NULL, 16); - } - 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); - chunk.alpha2 = strtol(&(tempCoord[9]), NULL, 16); - } - subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - chunk.angle = float_swap_bytes(atof(tempCoord)); - } + mxml_node_t *subnode = mxmlFindElement(node, node, "coords", 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.x = 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)); + } + 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)); + } + } + subnode = mxmlFindElement(node, node, "flip", 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.flip_x = 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)); + } + } + subnode = mxmlFindElement(node, node, "zoom", 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.xmag = 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)); + } + } + 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, "flags", 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[9]), NULL, 16); + } + 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); + chunk.alpha2 = strtol(&(tempCoord[9]), NULL, 16); + } + subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + chunk.angle = float_swap_bytes(atof(tempCoord)); + } - brlyt_pic_chunk chunk2; - subnode = mxmlFindElement(node, node, "tpl", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char temp[256]; - if(mxmlElementGetAttr(subnode, "name") != NULL) - strcpy(temp, mxmlElementGetAttr(subnode, "name")); - else{ - printf("No name attribute found!\nQuitting!\n"); - exit(1); - } - chunk2.mat_off = short_swap_bytes(findMatOffset(temp)); - } - subnode = mxmlFindElement(node, node, "colors", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - int i=0; - for(valnode = mxmlFindElement(subnode, subnode, "vtx", NULL, NULL, MXML_DESCEND); valnode != NULL; valnode = mxmlFindElement(valnode, subnode, "vtx", NULL, NULL, MXML_DESCEND)) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk2.vtx_colors[i] = be32(strtoul(&(tempCoord[2]), NULL, 16)); - i++; - } - } - u32 numberOfPicCoords = 0; - u32 sets = 1; - float* picCoords = malloc(8 * sizeof(float)); - subnode = mxmlFindElement(node, node, "coordinates", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *setnode; - for (setnode = mxmlFindElement(subnode, subnode, "set", NULL, NULL, MXML_DESCEND); setnode != NULL; setnode = mxmlFindElement(setnode, subnode, "set", NULL, NULL, MXML_DESCEND)) -// if (setnode != NULL) - { - picCoords = realloc(picCoords, sizeof(float) * 8 * sets); - mxml_node_t *valnode; - int numberOfCoordinates; - for (valnode=mxmlFindElement(setnode, setnode, "coord", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "coord", NULL, NULL, MXML_DESCEND) ) - { - - char tempCoord[256]; - int j; - for (j=0;j<256;j++) tempCoord[j]=0; - get_value(valnode, tempCoord, 256); - float tempCoordGotten = atof(tempCoord); - float coordGotten = float_swap_bytes(tempCoordGotten); - int picOffset = numberOfPicCoords * sizeof(float); - memcpy(&picCoords[numberOfPicCoords], &coordGotten, sizeof(float)); - numberOfPicCoords++; - } - sets++; - } - } - fwrite(&chunk, sizeof(chunk), 1, fp); - *fileOffset = *fileOffset + sizeof(chunk); - chunk2.num_texcoords = (sets - 1); - chunk2.padding = 0; - fwrite(&chunk2, sizeof(chunk2), 1, fp); - *fileOffset = *fileOffset + sizeof(chunk2); - fwrite(picCoords, numberOfPicCoords * sizeof(float), 1, fp); - *fileOffset = *fileOffset + (sizeof(float) * numberOfPicCoords); - free(picCoords); - } - if ( memcmp(temp, grp1, sizeof(grp1)) == 0) - { - brlyt_group_chunk chunk; - chunk.unk = 0; + brlyt_pic_chunk chunk2; + subnode = mxmlFindElement(node, node, "tpl", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char temp[256]; + if(mxmlElementGetAttr(subnode, "name") != NULL) + strcpy(temp, mxmlElementGetAttr(subnode, "name")); + else{ + printf("No name attribute found!\nQuitting!\n"); + exit(1); + } + chunk2.mat_off = short_swap_bytes(findMatOffset(temp)); + } + subnode = mxmlFindElement(node, node, "colors", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + int i=0; + for(valnode = mxmlFindElement(subnode, subnode, "vtx", NULL, NULL, MXML_DESCEND); valnode != NULL; valnode = mxmlFindElement(valnode, subnode, "vtx", NULL, NULL, MXML_DESCEND)) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk2.vtx_colors[i] = be32(strtoul(&(tempCoord[2]), NULL, 16)); + i++; + } + } + u32 numberOfPicCoords = 0; + u32 sets = 1; + float* picCoords = malloc(8 * sizeof(float)); + subnode = mxmlFindElement(node, node, "coordinates", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *setnode; + for (setnode = mxmlFindElement(subnode, subnode, "set", NULL, NULL, MXML_DESCEND); setnode != NULL; setnode = mxmlFindElement(setnode, subnode, "set", NULL, NULL, MXML_DESCEND)) +// if (setnode != NULL) + { + picCoords = realloc(picCoords, sizeof(float) * 8 * sets); + mxml_node_t *valnode; + int numberOfCoordinates; + for (valnode=mxmlFindElement(setnode, setnode, "coord", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "coord", NULL, NULL, MXML_DESCEND) ) + { + + char tempCoord[256]; + int j; + for (j=0;j<256;j++) tempCoord[j]=0; + get_value(valnode, tempCoord, 256); + float tempCoordGotten = atof(tempCoord); + float coordGotten = float_swap_bytes(tempCoordGotten); + int picOffset = numberOfPicCoords * sizeof(float); + memcpy(&picCoords[numberOfPicCoords], &coordGotten, sizeof(float)); + numberOfPicCoords++; + } + sets++; + } + } + fwrite(&chunk, sizeof(chunk), 1, fp); + *fileOffset = *fileOffset + sizeof(chunk); + chunk2.num_texcoords = (sets - 1); + chunk2.padding = 0; + fwrite(&chunk2, sizeof(chunk2), 1, fp); + *fileOffset = *fileOffset + sizeof(chunk2); + fwrite(picCoords, numberOfPicCoords * sizeof(float), 1, fp); + *fileOffset = *fileOffset + (sizeof(float) * numberOfPicCoords); + free(picCoords); + } + if ( memcmp(temp, grp1, sizeof(grp1)) == 0) + { + brlyt_group_chunk chunk; + chunk.unk = 0; - if(mxmlElementGetAttr(node, "name") != NULL) - strcpy(temp, mxmlElementGetAttr(node, "name")); - else{ - printf("No name attribute found!\nQuitting!\n"); - exit(1); - } - int j;char zeroed[16]; for (j=0;j<16;j++) zeroed[j]=0; - memcpy(chunk.name, zeroed, 16 * sizeof(char)); - strcpy(chunk.name, temp); - int numSubs = 0; - char *subs; - subs=malloc(0); - u32 subsLength = 0; + if(mxmlElementGetAttr(node, "name") != NULL) + strcpy(temp, mxmlElementGetAttr(node, "name")); + else{ + printf("No name attribute found!\nQuitting!\n"); + exit(1); + } + int j;char zeroed[16]; for (j=0;j<16;j++) zeroed[j]=0; + memcpy(chunk.name, zeroed, 16 * sizeof(char)); + strcpy(chunk.name, temp); + int numSubs = 0; + char *subs; + subs=malloc(0); + u32 subsLength = 0; - mxml_node_t *subnode = mxmlFindElement(node, node, "subs", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - for(valnode = mxmlFindElement(subnode, subnode, "sub", NULL, NULL, MXML_DESCEND); valnode != NULL; valnode = mxmlFindElement(valnode, subnode, "sub", NULL, NULL, MXML_DESCEND)) { - if (valnode != NULL) - { - u32 oldSubsLength = subsLength; - char tempSub[256]; - get_value(valnode, tempSub, 256); - subsLength += 16; - u8 stringLength = strlen(tempSub) + 1; - subs = realloc(subs, 1 + sizeof(char) * subsLength); - strcpy(&subs[oldSubsLength], tempSub); - for (stringLength;stringLength<17;stringLength++) - subs[oldSubsLength+stringLength] = 0x00; - numSubs++; - } - } - } - chunk.numsubs = short_swap_bytes(numSubs); - fwrite(&chunk, sizeof(chunk), 1, fp); - *fileOffset = *fileOffset + sizeof(chunk); - fwrite(subs, sizeof(char) * subsLength, 1, fp); - *fileOffset = *fileOffset + subsLength; - if (subsLength > 0) free(subs); - } - if ( memcmp(temp, grs1, sizeof(grs1)) == 0) - { + mxml_node_t *subnode = mxmlFindElement(node, node, "subs", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + for(valnode = mxmlFindElement(subnode, subnode, "sub", NULL, NULL, MXML_DESCEND); valnode != NULL; valnode = mxmlFindElement(valnode, subnode, "sub", NULL, NULL, MXML_DESCEND)) { + if (valnode != NULL) + { + u32 oldSubsLength = subsLength; + char tempSub[256]; + get_value(valnode, tempSub, 256); + subsLength += 16; + u8 stringLength = strlen(tempSub) + 1; + subs = realloc(subs, 1 + sizeof(char) * subsLength); + strcpy(&subs[oldSubsLength], tempSub); + for (stringLength;stringLength<17;stringLength++) + subs[oldSubsLength+stringLength] = 0x00; + numSubs++; + } + } + } + chunk.numsubs = short_swap_bytes(numSubs); + fwrite(&chunk, sizeof(chunk), 1, fp); + *fileOffset = *fileOffset + sizeof(chunk); + fwrite(subs, sizeof(char) * subsLength, 1, fp); + *fileOffset = *fileOffset + subsLength; + if (subsLength > 0) free(subs); + } + if ( memcmp(temp, grs1, sizeof(grs1)) == 0) + { - } - if ( memcmp(temp, gre1, sizeof(gre1)) == 0) - { + } + if ( memcmp(temp, gre1, sizeof(gre1)) == 0) + { - } - if ( memcmp(temp, pas1, sizeof(pas1)) == 0) - { + } + if ( memcmp(temp, pas1, sizeof(pas1)) == 0) + { - } - if ( memcmp(temp, pae1, sizeof(pae1)) == 0) - { + } + if ( memcmp(temp, pae1, sizeof(pae1)) == 0) + { - } + } - *blobsize = *fileOffset - startOfChunk; + *blobsize = *fileOffset - startOfChunk; } void WriteBRLYTHeader(brlyt_header rlythead, FILE* fp) { - brlyt_header writehead; - writehead.magic[0] = rlythead.magic[0]; - writehead.magic[1] = rlythead.magic[1]; - writehead.magic[2] = rlythead.magic[2]; - writehead.magic[3] = rlythead.magic[3]; - writehead.unk1 = be32(rlythead.unk1); - writehead.filesize = be32(rlythead.filesize); - writehead.lyt_offset = short_swap_bytes(rlythead.lyt_offset); - writehead.unk2 = short_swap_bytes(rlythead.unk2); + brlyt_header writehead; + writehead.magic[0] = rlythead.magic[0]; + writehead.magic[1] = rlythead.magic[1]; + writehead.magic[2] = rlythead.magic[2]; + writehead.magic[3] = rlythead.magic[3]; + writehead.unk1 = be32(rlythead.unk1); + writehead.filesize = be32(rlythead.filesize); + writehead.lyt_offset = short_swap_bytes(rlythead.lyt_offset); + writehead.unk2 = short_swap_bytes(rlythead.unk2); - fwrite(&writehead, sizeof(brlyt_header), 1, fp); + fwrite(&writehead, sizeof(brlyt_header), 1, fp); } void write_brlyt(char *infile, char *outfile) { - u32 timesIn = 0; - unsigned int fileOffset = 0; - FILE* fpx = fopen(infile, "r"); - if(fpx == NULL) { - printf("xmlyt 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, "xmlyt", 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(fp == NULL) { - printf("destination brlyt couldn't be opened!\n"); - exit(1); - } + u32 timesIn = 0; + unsigned int fileOffset = 0; + FILE* fpx = fopen(infile, "r"); + if(fpx == NULL) { + printf("xmlyt 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, "xmlyt", 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(fp == NULL) { + printf("destination brlyt couldn't be opened!\n"); + exit(1); + } - u32 fileError = ferror(fp); + u32 fileError = ferror(fp); - u8* tagblob; - u32 blobsize; - u16 blobcount = 0; - u32 bloboffset; - brlyt_header rlythead; + u8* tagblob; + u32 blobsize; + u16 blobcount = 0; + u32 bloboffset; + brlyt_header rlythead; rlythead.magic[0] = 'R'; rlythead.magic[1] = 'L'; rlythead.magic[2] = 'Y'; @@ -2871,65 +2871,65 @@ void write_brlyt(char *infile, char *outfile) rlythead.lyt_offset = sizeof(brlyt_header); rlythead.unk2 = 1; WriteBRLYTHeader(rlythead, fp); - char temp[256]; + char temp[256]; - fileOffset += sizeof(brlyt_header); + fileOffset += sizeof(brlyt_header); - u32 numberOfEntries; + u32 numberOfEntries; - for(node = mxmlFindElement(tree, tree, "tag", NULL, NULL, MXML_DESCEND); node != NULL; node = mxmlFindElement(node, tree, "tag", NULL, NULL, MXML_DESCEND)) { + for(node = mxmlFindElement(tree, tree, "tag", NULL, NULL, MXML_DESCEND); node != NULL; node = mxmlFindElement(node, tree, "tag", NULL, NULL, MXML_DESCEND)) { - char tempType[4]; - if(mxmlElementGetAttr(node, "type") != NULL) - strcpy(tempType, mxmlElementGetAttr(node, "type")); - else{ - printf("No type attribute found!\n"); - exit(1); - } + char tempType[4]; + if(mxmlElementGetAttr(node, "type") != NULL) + strcpy(tempType, mxmlElementGetAttr(node, "type")); + else{ + printf("No type attribute found!\n"); + exit(1); + } - unsigned int chunkHeaderOffset = fileOffset; + unsigned int chunkHeaderOffset = fileOffset; - brlyt_entry_header chunk; - chunk.magic[0]=tempType[0]; - chunk.magic[1]=tempType[1]; - chunk.magic[2]=tempType[2]; - chunk.magic[3]=tempType[3]; - chunk.length = 0; + brlyt_entry_header chunk; + chunk.magic[0]=tempType[0]; + chunk.magic[1]=tempType[1]; + chunk.magic[2]=tempType[2]; + chunk.magic[3]=tempType[3]; + chunk.length = 0; - fwrite(&chunk, sizeof(chunk), 1, fp); + fwrite(&chunk, sizeof(chunk), 1, fp); - fileOffset += sizeof(chunk); + fileOffset += sizeof(chunk); - WriteBRLYTEntry(tree, node, &tagblob, &blobsize, tempType, fp, &fileOffset); + WriteBRLYTEntry(tree, node, &tagblob, &blobsize, tempType, fp, &fileOffset); - chunk.length = be32(blobsize + sizeof(chunk)); + chunk.length = be32(blobsize + sizeof(chunk)); - fseek(fp, chunkHeaderOffset, SEEK_SET); - fwrite(&chunk, sizeof(chunk), 1, fp); - fseek(fp, fileOffset, SEEK_SET); + fseek(fp, chunkHeaderOffset, SEEK_SET); + fwrite(&chunk, sizeof(chunk), 1, fp); + fseek(fp, fileOffset, SEEK_SET); - numberOfEntries++; + numberOfEntries++; - blobcount++; + blobcount++; - } + } - rlythead.filesize = fileOffset; - rlythead.unk2 = blobcount; - fseek(fp, 0, SEEK_SET); - WriteBRLYTHeader(rlythead, fp); + rlythead.filesize = fileOffset; + rlythead.unk2 = blobcount; + fseek(fp, 0, SEEK_SET); + WriteBRLYTHeader(rlythead, fp); - fclose(fpx); - fclose(fp); + fclose(fpx); + fclose(fp); } void make_brlyt(char* infile, char* outfile) { - printf("\x1b[33mParsing XMLYT @ \x1b[0m%s.\n", infile); - write_brlyt(infile, outfile); - free(materials); - free(textures); - printf("\x1b[34mParsing XMLYT @ \x1b[0m%s complete.\n", infile); + printf("\x1b[33mParsing XMLYT @ \x1b[0m%s.\n", infile); + write_brlyt(infile, outfile); + free(materials); + free(textures); + printf("\x1b[34mParsing XMLYT @ \x1b[0m%s complete.\n", infile); } @@ -15,136 +15,136 @@ typedef struct { - fourcc magic; // RLYT - u32 unk1; // 0xFEFF0008 - u32 filesize; // The filesize of the brlyt. - u16 lyt_offset; // Offset to the lyt1 section. - u16 unk2; // Number of sections. + fourcc magic; // RLYT + u32 unk1; // 0xFEFF0008 + u32 filesize; // The filesize of the brlyt. + u16 lyt_offset; // Offset to the lyt1 section. + u16 unk2; // Number of sections. } brlyt_header; typedef struct { - fourcc magic; // The magic. - u32 length; // How long the entry is. + fourcc magic; // The magic. + u32 length; // How long the entry is. } brlyt_entry_header; typedef struct { - fourcc magic; // The magic. - u32 length; // How long the entry is. - u32 data_location; // The location of the data in the BRLYT file. + fourcc magic; // The magic. + u32 length; // How long the entry is. + u32 data_location; // The location of the data in the BRLYT file. } brlyt_entry; typedef struct { - unsigned char flag1; - unsigned char flag2; - unsigned char alpha; - unsigned char alpha2; - char name[24]; - float x; - float y; - float z; - float flip_x; - float flip_y; - float angle; - float xmag; - float ymag; - float width; - float height; + unsigned char flag1; + unsigned char flag2; + unsigned char alpha; + unsigned char alpha2; + char name[24]; + float x; + float y; + float z; + float flip_x; + float flip_y; + float angle; + float xmag; + float ymag; + float width; + float height; } brlyt_pane_chunk; typedef struct { - u16 len1; - u16 len2; - u16 mat_off; - u16 font_idx; - u8 unk4; - u8 pad[3]; // [0, 0, 0] - u32 name_offs; - u32 color1; - u32 color2; - float font_size_x; - float font_size_y; - float char_space; - float line_space; + u16 len1; + u16 len2; + u16 mat_off; + u16 font_idx; + u8 unk4; + u8 pad[3]; // [0, 0, 0] + u32 name_offs; + u32 color1; + u32 color2; + float font_size_x; + float font_size_y; + float char_space; + float line_space; } brlyt_text_chunk; typedef struct { - u32 vtx_colors[4]; // [4294967295L, 4294967295L, 4294967295L, 4294967295L] - u16 mat_off; - u8 num_texcoords; - u8 padding; // 0 + u32 vtx_colors[4]; // [4294967295L, 4294967295L, 4294967295L, 4294967295L] + u16 mat_off; + u8 num_texcoords; + u8 padding; // 0 } brlyt_pic_chunk; typedef struct { - char a; - char pad[3]; - float width; - float height; + char a; + char pad[3]; + float width; + float height; } brlyt_lytheader_chunk; typedef struct { - char name[16]; - u16 numsubs; - u16 unk; + char name[16]; + u16 numsubs; + u16 unk; } brlyt_group_chunk; typedef struct { - u16 num; - u16 offs; + u16 num; + u16 offs; } brlyt_numoffs_chunk; typedef struct { - char name[20]; - s16 tev_color[4]; - s16 unk_color[4]; - s16 unk_color_2[4]; - u32 tev_kcolor[4]; - u32 flags; + char name[20]; + s16 tev_color[4]; + s16 unk_color[4]; + s16 unk_color_2[4]; + u32 tev_kcolor[4]; + u32 flags; } brlyt_material_chunk; typedef struct { - int offset; - int unk; + int offset; + int unk; } brlyt_offsunk_chunk; typedef struct { - u16 tex_offs; - u8 wrap_s; - u8 wrap_t; + u16 tex_offs; + u8 wrap_s; + u8 wrap_t; } brlyt_texref_chunk; typedef struct { - float unk[5]; + float unk[5]; } brlyt_ua2_chunk; typedef struct { - u8 unk[4]; + u8 unk[4]; } brlyt_4b_chunk; typedef struct { - u32 a; - u32 b; - float c; - u32 d; - u32 e; + u32 a; + u32 b; + float c; + u32 d; + u32 e; } brlyt_ua7_chunk; typedef struct { - u8 unk[16]; + u8 unk[16]; } brlyt_10b_chunk; void swapBytes(unsigned char* char1, unsigned char* char2); @@ -4,9 +4,9 @@ #include "types.h" #include "endian.h" -//#define be16(x) ((x>>8)|(x<<8)) -//#define be32(x) ((x>>24)|((x<<8)&0x00FF0000)|((x>>8)&0x0000FF00)|(x<<24)) -//#define be64(x) ((x>>56)|((x<<40)&(u64)0x00FF000000000000)|((x<<24)&(u64)0x0000FF0000000000)|((x<<8)&(u64)0x000000FF00000000)|((x>>8)&(u64)0x00000000FF000000)|((x>>24)&(u64)0x0000000000FF0000)|((x<<40)&(u64)0x000000000000FF00)|(x<<56)) +//#define be16(x) ((x>>8)|(x<<8)) +//#define be32(x) ((x>>24)|((x<<8)&0x00FF0000)|((x>>8)&0x0000FF00)|(x<<24)) +//#define be64(x) ((x>>56)|((x<<40)&(u64)0x00FF000000000000)|((x<<24)&(u64)0x0000FF0000000000)|((x<<8)&(u64)0x000000FF00000000)|((x>>8)&(u64)0x00000000FF000000)|((x>>24)&(u64)0x0000000000FF0000)|((x<<40)&(u64)0x000000000000FF00)|(x<<56)) u16 be16(u16 x) { @@ -3,9 +3,9 @@ #include "types.h" -//#define be16(x) ((x>>8)|(x<<8)) -//#define be32(x) ((x>>24)|((x<<8)&0x00FF0000)|((x>>8)&0x0000FF00)|(x<<24)) -//#define be64(x) ((x>>56)|((x<<40)&(u64)0x00FF000000000000)|((x<<24)&(u64)0x0000FF0000000000)|((x<<8)&(u64)0x000000FF00000000)|((x>>8)&(u64)0x00000000FF000000)|((x>>24)&(u64)0x0000000000FF0000)|((x<<40)&(u64)0x000000000000FF00)|(x<<56)) +//#define be16(x) ((x>>8)|(x<<8)) +//#define be32(x) ((x>>24)|((x<<8)&0x00FF0000)|((x>>8)&0x0000FF00)|(x<<24)) +//#define be64(x) ((x>>56)|((x<<40)&(u64)0x00FF000000000000)|((x<<24)&(u64)0x0000FF0000000000)|((x<<8)&(u64)0x000000FF00000000)|((x>>8)&(u64)0x00000000FF000000)|((x>>24)&(u64)0x0000000000FF0000)|((x<<40)&(u64)0x000000000000FF00)|(x<<56)) u16 be16(u16 x); @@ -43,11 +43,11 @@ formats = { ''', 'window': ''' float unk1 // 4c - float unk2 // 50 - float unk3 // 54 - float unk4 // 58 - u32 unk5 // 5c - ??? - u32 offs // 60 - from start of pane + float unk2 // 50 + float unk3 // 54 + float unk4 // 58 + u32 unk5 // 5c - ??? + u32 offs // 60 - from start of pane etc! ''', 'window2': ''' // (r29) @@ -60,7 +60,7 @@ formats = { u8 pad // 13 etc! // followed by the texcoord array ''', - + 'group': ''' char name[16] u16 numsubs @@ -142,7 +142,7 @@ for (dname, definition) in formats.items(): else: df.append((typ, name, default)) formats[dname] = df, etc, etcn - + # Dumb pretty printer def my_repr(b, start=''): '''scrap this shit and implement new one eventually''' @@ -179,10 +179,10 @@ def my_repr(b, start=''): else: rep = repr(b) return re.sub(re.compile('^', re.M), start, rep) - + def pr_dict(*args): print my_repr(*args) - + types = { 'u8': 'B', 'u16': 'H', @@ -213,18 +213,18 @@ def nullterm(str_plus): return str_plus[:z] else: return str_plus - + def unnullterm(var, size): if len(var) > size: raise Exception('unnullterm: "%s" too long' % var) return var.ljust(size, '\0') - + def untv(name): #assert '\0' not in name lex = len(name) + 16 lex -= lex % 16 return name.ljust(lex, '\0') - + def parse_data(chunk, definition, prefix=None, start=0): df, etc, etcn = formats[definition] #print df, repr(definition) @@ -271,12 +271,12 @@ def parse_data(chunk, definition, prefix=None, start=0): ret = ret['_'] return (ret, pos) if etcn else ret - + def unparse_var(typ, var): if not types.has_key(typ): raise Exception('What\'s a %s?' % typ) return struct.pack('>' + types[typ], var) - + def unparse_data(vars, definition, prefix=None): df, etc, etcn = formats[definition] ret = '' @@ -317,7 +317,7 @@ def unparse_data(vars, definition, prefix=None): for v in var: ret += unparse_var(typ, v) return ret - + def iff_to_chunks(z): pos = 0 chunks = [] @@ -330,7 +330,7 @@ def iff_to_chunks(z): pos += length chunks.append((cc, data)) return chunks - + def bit_extract(num, start, end=None): if end is None: end = start @@ -338,14 +338,14 @@ def bit_extract(num, start, end=None): ret = (num & mask) >> (31 - end) return ret - + def bit_place(num, start, end=None): # Just for sanity if end is None: end = start assert num <= 2**(end - start) return num << (31 - end) - + def get_array(chunk, startpos, array_size, item_size, item_type=None): ar = [] pos = startpos @@ -354,7 +354,7 @@ def get_array(chunk, startpos, array_size, item_size, item_type=None): ar.append(get_opt(chunk, pos, True, item_size, item_type)[0]) pos += item_size return ar, pos - + def get_opt(chunk, startpos, enabled, size, item_type=None): if not enabled: return None, startpos @@ -390,6 +390,6 @@ def put_opt(var, flags, bit, size, item_type=None): else: raise Exception('unhandled') return ret, flags - + def i2f(int): return struct.unpack('>f', struct.pack('>I', int))[0]
\ No newline at end of file @@ -7,12 +7,12 @@ * */ -#define BENZIN_VERSION_MAJOR 0 -#define BENZIN_VERSION_MINOR 1 -#define BENZIN_VERSION_BUILD 927 -#define BENZIN_VERSION_OTHER "WIP" +#define BENZIN_VERSION_MAJOR 0 +#define BENZIN_VERSION_MINOR 1 +#define BENZIN_VERSION_BUILD 927 +#define BENZIN_VERSION_OTHER "WIP" -#define INFORMATION_TEXT \ +#define INFORMATION_TEXT \ "Benzin %d.%d.%d%s.\n" \ "Written by SquidMan (Alex Marshall), comex, and megazig.\n" \ "(c) 2009 HACKERCHANNEL\n", BENZIN_VERSION_MAJOR, BENZIN_VERSION_MINOR, BENZIN_VERSION_BUILD, BENZIN_VERSION_OTHER @@ -23,52 +23,52 @@ //#define OLD_BRLAN_OUTSTYLE //#define OLD_BRLYT_OUTSTYLE -//#define DEBUGBRLAN 1 -//#define DEBUGMAIN 1 -//#define DEBUGBRLYT 1 +//#define DEBUGBRLAN 1 +//#define DEBUGMAIN 1 +//#define DEBUGBRLYT 1 -#define fatal(x) printf(x); exit(1) +#define fatal(x) printf(x); exit(1) // WTF is this doing here? /*void LZ77Decompress(void *indata, size_t dlen, u8* ret) { - int inp = 0; - u8* data = (u8*)calloc(dlen + 16, 1); - memcpy(data, indata, dlen); - int i; - u8 bitmask; - ret = (u8*)calloc(dlen, 256); // HORRIBLY INEFFICIENT. - // FIGURE SOMETHING ELSE OUT - int retoff = 0; - - while(inp < dlen) { - bitmask = data[inp]; - inp++; - - for(i = 0; i < 8; i++) { - if(bitmask & 0x80) { - u8 rep = data[inp]; - u8 repLength = (rep >> 4) + 3; - inp++; - u16 repOff = data[inp] | ((rep & 0x0F) << 8); - inp++; - - if(repOff <= retoff) { - fatal("Offset too high!\nQuitting\n"); - } - - while(repLength > 0) { - ret[retoff] = ret[(retoff - repOff) - 1]; - repLength--; - retoff++; - } - }else{ - ret[retoff] = data[inp]; - retoff++; - inp++; - } - bitmask = bitmask << 1; - } - } + int inp = 0; + u8* data = (u8*)calloc(dlen + 16, 1); + memcpy(data, indata, dlen); + int i; + u8 bitmask; + ret = (u8*)calloc(dlen, 256); // HORRIBLY INEFFICIENT. + // FIGURE SOMETHING ELSE OUT + int retoff = 0; + + while(inp < dlen) { + bitmask = data[inp]; + inp++; + + for(i = 0; i < 8; i++) { + if(bitmask & 0x80) { + u8 rep = data[inp]; + u8 repLength = (rep >> 4) + 3; + inp++; + u16 repOff = data[inp] | ((rep & 0x0F) << 8); + inp++; + + if(repOff <= retoff) { + fatal("Offset too high!\nQuitting\n"); + } + + while(repLength > 0) { + ret[retoff] = ret[(retoff - repOff) - 1]; + repLength--; + retoff++; + } + }else{ + ret[retoff] = data[inp]; + retoff++; + inp++; + } + bitmask = bitmask << 1; + } + } } */ @@ -9,70 +9,70 @@ #include "general.h" #ifdef DEBUGMAIN -#define dbgprintf printf +#define dbgprintf printf #else -#define dbgprintf // +#define dbgprintf // #endif //DEBUGMAIN int main(int argc, char* argv[]) { - 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]); + 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]); #ifdef USE_BRLAN - brlanargread = currentarg; - strcat(helpstrread, " <*.brlan>"); - brlanargmake = currentarg++; - strcat(helpstrmake, " <*.xmlan>"); + brlanargread = currentarg; + strcat(helpstrread, " <*.brlan>"); + brlanargmake = currentarg++; + strcat(helpstrmake, " <*.xmlan>"); #endif //USE_BRLAN #ifdef USE_BRLYT - brlytargread = currentarg; - strcat(helpstrread, " <*.brlyt>"); - brlytargmake = currentarg++; - strcat(helpstrmake, " <*.xmlyt>"); + brlytargread = currentarg; + strcat(helpstrread, " <*.brlyt>"); + brlytargmake = currentarg++; + strcat(helpstrmake, " <*.xmlyt>"); #endif //USE_BRLYT - reqargs = currentarg; + reqargs = currentarg; #ifdef USE_BRLAN - brlanargdestmake = currentarg++; - strcat(helpstrmake, " <out.brlan>"); + brlanargdestmake = currentarg++; + strcat(helpstrmake, " <out.brlan>"); #endif //USE_BRLAN #ifdef USE_BRLYT - brlytargdestmake = currentarg++; - strcat(helpstrmake, " <out.brlyt>"); + brlytargdestmake = currentarg++; + strcat(helpstrmake, " <out.brlyt>"); #endif //USE_BRLYT - 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') { + 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') { #ifdef USE_BRLAN - parse_brlan(argv[brlanargread]); + parse_brlan(argv[brlanargread]); #endif //USE_BRLAN #ifdef USE_BRLYT - parse_brlyt(argv[brlytargread]); + parse_brlyt(argv[brlytargread]); #endif //USE_BRLYT - }else if(argv[1][0] == 'm') { + }else if(argv[1][0] == 'm') { #ifdef USE_BRLAN - dbgprintf("1:%d 2:%d f1:%s f2:%s\n", brlanargmake, brlanargdestmake, argv[brlanargmake], argv[brlanargdestmake]); - make_brlan(argv[brlanargmake], argv[brlanargdestmake]); + dbgprintf("1:%d 2:%d f1:%s f2:%s\n", brlanargmake, brlanargdestmake, argv[brlanargmake], argv[brlanargdestmake]); + make_brlan(argv[brlanargmake], argv[brlanargdestmake]); #endif //USE_BRLAN #ifdef USE_BRLYT - dbgprintf("1:%d 2:%d f1:%s f2:%s\n", brlytargmake, brlytargdestmake, argv[brlytargmake], argv[brlytargdestmake]); - make_brlyt(argv[brlytargmake], argv[brlytargdestmake]); + dbgprintf("1:%d 2:%d f1:%s f2:%s\n", brlytargmake, brlytargdestmake, argv[brlytargmake], argv[brlytargdestmake]); + make_brlyt(argv[brlytargmake], argv[brlytargdestmake]); #endif //USE_BRLYT - } - return 0; + } + return 0; } @@ -15,96 +15,96 @@ void ReadMemory(void* dst, size_t size, size_t count, MEMORY* src) { - if((src->mode & 0x1) == 0) { - printf("Invalid mode for reading!\n"); - return; - } - u8* data = (u8*)dst; - if(((size * count) + src->position) > src->memorysize) { - printf("Tried to over read.\n"); - return; - } - memcpy(data, ((u8*)src->memory) + src->position, size * count); - src->position += size * count; + if((src->mode & 0x1) == 0) { + printf("Invalid mode for reading!\n"); + return; + } + u8* data = (u8*)dst; + if(((size * count) + src->position) > src->memorysize) { + printf("Tried to over read.\n"); + return; + } + memcpy(data, ((u8*)src->memory) + src->position, size * count); + src->position += size * count; } char ReadMemoryChar(MEMORY* src) { - char ret; - ReadMemory(&ret, 1, 1, src); - return ret; + char ret; + ReadMemory(&ret, 1, 1, src); + return ret; } void WriteMemory(void* dst, size_t size, size_t count, MEMORY* src) { - if((src->mode & 0x2) == 0) { - printf("Invalid mode for writing!\n"); - return; - } - u8* data = (u8*)dst; - if(((size * count) + src->position) > src->memorysize) { - printf("Tried to over read.\n"); - return; - } - memcpy(((u8*)src->memory) + src->position, data, size * count); - src->position += size * count; + if((src->mode & 0x2) == 0) { + printf("Invalid mode for writing!\n"); + return; + } + u8* data = (u8*)dst; + if(((size * count) + src->position) > src->memorysize) { + printf("Tried to over read.\n"); + return; + } + memcpy(((u8*)src->memory) + src->position, data, size * count); + src->position += size * count; } void WriteMemoryChar(char inchar, MEMORY* src) { - WriteMemory(&inchar, 1, 1, src); + WriteMemory(&inchar, 1, 1, src); } MEMORY* OpenMemory(void* indata, size_t size, char mode) { - MEMORY* mem = malloc(sizeof(MEMORY)); - if((mode & 0x2) == 0x0) - mem->memory = indata; - else - mem->memory = calloc(size, 1); - if(mem->memory == NULL) - return NULL; - mem->memorysize = size; - mem->position = 0; - mem->mode = mode; - return mem; + MEMORY* mem = malloc(sizeof(MEMORY)); + if((mode & 0x2) == 0x0) + mem->memory = indata; + else + mem->memory = calloc(size, 1); + if(mem->memory == NULL) + return NULL; + mem->memorysize = size; + mem->position = 0; + mem->mode = mode; + return mem; } void* CloseMemory(MEMORY* mem) { - void* ret = mem->memory; - mem->memory = NULL; - mem->memorysize = 0; - mem->position = 0; - mem->mode = 0; - free(mem); - return ret; + void* ret = mem->memory; + mem->memory = NULL; + mem->memorysize = 0; + mem->position = 0; + mem->mode = 0; + free(mem); + return ret; } void* GetMemory(MEMORY* mem) { - return mem->memory; + return mem->memory; } void SeekMemory(MEMORY* mem, size_t location, int type) { - switch(type) { - case SEEK_SET: - mem->position = location; - break; - - case SEEK_END: - mem->position = mem->memorysize - location; - break; - } + switch(type) { + case SEEK_SET: + mem->position = location; + break; + + case SEEK_END: + mem->position = mem->memorysize - location; + break; + } } size_t TellMemory(MEMORY* mem) { - return mem->position; + return mem->position; } size_t SizeMemory(MEMORY* mem) { - return mem->memorysize; + return mem->memorysize; } @@ -12,23 +12,23 @@ #include "types.h" -#define mread ReadMemory -#define mwrite WriteMemory -#define mopen OpenMemory -#define mclose CloseMemory -#define mseek SeekMemory -#define mgetc ReadMemoryChar -#define mputc WriteMemoryChar -#define mtell TellMemory -#define msize SizeMemory -#define mgetm GetMemory +#define mread ReadMemory +#define mwrite WriteMemory +#define mopen OpenMemory +#define mclose CloseMemory +#define mseek SeekMemory +#define mgetc ReadMemoryChar +#define mputc WriteMemoryChar +#define mtell TellMemory +#define msize SizeMemory +#define mgetm GetMemory typedef struct { - void* memory; // Pointer. - size_t memorysize; // Size. - size_t position; // Where we are. - char mode; // What mode opened (1 = read, 2 = write, 3 = both) + void* memory; // Pointer. + size_t memorysize; // Size. + size_t position; // Where we are. + char mode; // What mode opened (1 = read, 2 = write, 3 = both) } MEMORY; void ReadMemory(void* dst, size_t size, size_t count, MEMORY* src); diff --git a/parse-brlan.py b/parse-brlan.py index f698cbf..59a4d84 100644 --- a/parse-brlan.py +++ b/parse-brlan.py @@ -28,7 +28,14 @@ assert len(ch) == nel for typ, chunk in ch: assert typ == 'pai1' - framesize, flags, _, num_timgs, num_anims, anim_offset = struct.unpack('>hbbhhI', chunk[:0xc]) + # 8, a, b, c, e, 10 + framesize, \ + flags, \ + _, \ + num_timgs, \ + num_anims, \ + anim_offset \ + = struct.unpack('>hbbhhI', chunk[:0xc]) print 'Framesize: %d\nFlags: %x' % (framesize, flags) for n in xrange(num_timgs): pos = 0x10 + 4*n @@ -39,34 +46,36 @@ for typ, chunk in ch: offs = struct.unpack('>I', chunk[pos:pos+4])[0] - 8 name = chunk[offs:offs + 0x14].rstrip('\0') - - aunk, aoffs = struct.unpack('>II', chunk[offs + 0x14:offs + 0x1c]) - if aunk == 0: - # I don't know what a mvit is but it apparently is one - print 'lemmings: %s' % name - continue - print name, hex(aoffs) - aoffs += offs - atyp = chunk[aoffs:aoffs+4] - #print hex(aoffs), hex(offs), name - - num_aents = ord(chunk[aoffs + 4]) - print atyp, name, hex(aunk) - - for m in xrange(num_aents): - boffs = aoffs + 8 + 4*m - coffs, = struct.unpack('>I', chunk[boffs:boffs + 4]) - coffs += aoffs - if atyp in ('RLMC', 'RLVC', 'RLPA', 'RLTP', 'RLIM', 'RLTS'): # doesn't cover RLVI - byte0, byte1, byte2, byte3, num_cookies, pad, cookies_offs = struct.unpack('>BBBBHHI', chunk[coffs:coffs+0xc]) - #print 'cookies_offs: %x' % cookies_offs - print hex(byte0), hex(byte1), hex(byte2), hex(byte3), num_cookies - for o in xrange(num_cookies): - cookie_offs = coffs + cookies_offs + 0xc*o - coords = struct.unpack('>fff', chunk[cookie_offs:cookie_offs + 0xc]) - print ' ', coords - print ' ', '---' - + num_aent_groups, is_material, aunk3, aunk4 = struct.unpack('>BBBB', chunk[offs + 0x14:offs + 0x18]) + + print 'name:%s num_aent_groups:%d is_material:%d aunk3:%d aunk4:%d' % (name, num_aent_groups, is_material, aunk3, aunk4) + + for g in xrange(num_aent_groups): + q = offs + 0x18 + 4*g + aoffs, = struct.unpack('>I', chunk[q:q+4]) + print name, hex(aoffs) + aoffs += offs + atyp = chunk[aoffs:aoffs+4] + #print hex(aoffs), hex(offs), name + + num_aents = ord(chunk[aoffs + 4]) + print atyp + + for m in xrange(num_aents): + boffs = aoffs + 8 + 4*m + coffs, = struct.unpack('>I', chunk[boffs:boffs + 4]) + coffs += aoffs + if atyp in ('RLMC', 'RLVC', 'RLPA', 'RLTP', 'RLIM', 'RLTS'): # doesn't cover RLVI + byte0, byte1, byte2, byte3, num_cookies, pad, cookies_offs = struct.unpack('>BBBBHHI', chunk[coffs:coffs+0xc]) + #print 'cookies_offs: %x' % cookies_offs + print hex(byte0), hex(byte1), hex(byte2), hex(byte3), num_cookies + for o in xrange(num_cookies): + cookie_offs = coffs + cookies_offs + 0xc*o + coords = struct.unpack('>fff', chunk[cookie_offs:cookie_offs + 0xc]) + print ' ', coords + print ' ', '---' + print '******' + #print repr(name) #unk, anim_header_len = struct.unpack('>II', chunk[offs + 20:offs + 28]) #atyp = chunk[offs + 28:offs + 32] @@ -4,65 +4,65 @@ #include "types.h" #include "xml.h" -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 */ - - - ptr = (char*)buffer; - end = (char*)buffer + buflen - 1; - char tempbuf[256]; - 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; + 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[256]; + 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; } @@ -1,9 +1,9 @@ #ifndef _XML_H_ #define _XML_H_ -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 */ #endif //_XML_H_ |
