diff options
| author | megazig <megazig@megazig-desktop.(none)> | 2009-04-19 14:36:52 -0500 |
|---|---|---|
| committer | megazig <megazig@megazig-desktop.(none)> | 2009-04-19 14:36:52 -0500 |
| commit | 0a6bad6a04ebfb4b0723a118ab477af33c5a43b4 (patch) | |
| tree | 50d9f6f9e114c9c55da7fe3e29ad1df3cbcaf83e | |
| parent | 0c025bc83b0a889347fad1d128ab02a315656577 (diff) | |
big brlan fix
Diffstat (limited to '')
| -rw-r--r-- | brlan.c | 790 | ||||
| -rwxr-xr-x | brlan.h | 9 | ||||
| -rw-r--r-- | general.h | 2 |
3 files changed, 326 insertions, 475 deletions
@@ -25,7 +25,7 @@ #define dbgprintf // #endif //DEBUGBRLAN -#define MAXIMUM_TAGS_SIZE (0x1000) +#define MAXIMUM_TAGS_SIZE (0xf000) #define MAXIMUM_TIMGS_SIZE (0x1000) fourcc tag_FourCCs[] = { "RLPA", "RLTS", "RLVI", "RLVC", "RLMC", "RLTP" }; @@ -70,22 +70,6 @@ static void CreateGlobal_pai1(brlan_pai1_header_type2 *pai1_header, brlan_pai1_h memcpy(pai1_header, &pai1_header2, sizeof(brlan_pai1_header_type2)); } -static void DisplayTagData(tag_data data, int z) -{ - u32 p1 = be32(data.part1); - u32 p2 = be32(data.part2); - u32 p3 = be32(data.part3); -#ifndef OLD_BRLAN_OUTSTYLE - printf("\t\t\t<triplet>\n\t\t\t\t<frame>%.10f</frame>\n\t\t\t\t<value>%.10f</value>\n\t\t\t\t<blend>%.10f</blend>\n\t\t\t</triplet>\n", *(f32*)(&p1), *(f32*)(&p2), *(f32*)(&p3)); -#endif // OLD_BRLAN_OUTSTYLE -#ifdef OLD_BRLAN_OUTSTYLE - printf(" Triplet %d:\n", z); - printf(" Frame number: %f\n", *(f32*)(&p1)); - printf(" Value: %f\n", *(f32*)(&p2)); - printf(" Interpolation Value: %f\n", *(f32*)(&p3)); -#endif // OLD_BRLAN_OUTSTYLE -} - static int FourCCsMatch(fourcc cc1, fourcc cc2) { if((cc1[0] == cc2[0]) && (cc1[1] == cc2[1]) && (cc1[2] == cc2[2]) && (cc1[3] == cc2[3])) @@ -102,95 +86,6 @@ static int FourCCInList(fourcc cc) return 0; } -static void DisplayTagInformation(int idx, tag_header* heads, tag_entry** entriesx, - tag_entryinfo** entryinfosx, tag_data*** datasxx) -{ - tag_header head = heads[idx]; - tag_entry* entries = entriesx[idx]; - tag_entryinfo* entryinfos = entryinfosx[idx]; - tag_data** datas = datasxx[idx]; - int i, z; - -#ifdef OLD_BRLAN_OUTSTYLE - printf(" Number of entries: %u\n", head.entry_count); - -// Why should we show padding? It's 0 every single time. -/* printf(" Unk1: %02x\n", head.pad1); - printf(" Unk2: %02x\n", head.pad2); - printf(" Unk3: %02x\n", head.pad3); */ - - printf(" Entries:\n"); -#endif // OLD_BRLAN_OUTSTYLE - for(i = 0; i < head.entry_count; i++) { -#ifndef OLD_BRLAN_OUTSTYLE - if(short_swap_bytes(entryinfos[i].type) < 16) - printf("\t\t<entry type=\"%s\">\n", tag_types_list[short_swap_bytes(entryinfos[i].type)]); - else - printf("\t\t<entry type=\"%u\">\n", short_swap_bytes(entryinfos[i].type)); -#endif // OLD_BRLAN_OUTSTYLE -#ifdef OLD_BRLAN_OUTSTYLE - printf(" Entry %u:\n", i); - if(short_swap_bytes(entryinfos[i].type) < 16) - printf(" Type: %s (%04x)\n", tag_types_list[short_swap_bytes(entryinfos[i].type)], short_swap_bytes(entryinfos[i].type)); - else - printf(" Type: Unknown (%04x)\n", short_swap_bytes(entryinfos[i].type)); -// User doesn't need to know the offset -// printf(" Offset: %lu\n", be32(entries[i].offset)); - -// Yet again, these are always the same, and seem to maybe be some marker. don't bother to show. -/* printf(" Unk1: %04x\n", short_swap_bytes(entryinfos[i].pad1)); - printf(" Unk2: %04x\n", short_swap_bytes(entryinfos[i].unk1)); - printf(" Unk3: %08x\n", be32(entryinfos[i].unk2)); */ - printf(" Triplet Count: %u\n", short_swap_bytes(entryinfos[i].coord_count)); - printf(" Triplets:\n"); -#endif // OLD_BRLAN_OUTSTYLE - for(z = 0; z < short_swap_bytes(entryinfos[i].coord_count); z++) - DisplayTagData(datas[i][z], z); -#ifndef OLD_BRLAN_OUTSTYLE - printf("\t\t</entry>\n"); -#endif // OLD_BRLAN_OUTSTYLE - } -} - -static void ReadTagFromBRLAN(int idx, u8* brlan_file, tag_header *head, tag_entry** entries, tag_entryinfo** entryinfo, tag_data*** data) -{ - int taghead_location = BRLAN_fileoffset; - BRLAN_ReadDataFromMemory(&head[idx], brlan_file, sizeof(tag_header)); - int i, z; - entries[idx] = realloc(entries[idx], sizeof(tag_entry) * head[idx].entry_count); - dbgprintf("reallocated entries[idx]\n"); - entryinfo[idx] = realloc(entryinfo[idx], sizeof(tag_entryinfo) * head[idx].entry_count); - dbgprintf("reallocated entryinfo[idx]\n"); - if(data[idx] == NULL) { - dbgprintf("callocating data[idx]\n"); - data[idx] = (tag_data**)malloc(sizeof(tag_data) * head[idx].entry_count); - dbgprintf("callocated data[idx]\n"); - }else{ - dbgprintf("reallocating data[idx] %08x\n", data[idx]); - data[idx] = (tag_data**)realloc(data[idx], sizeof(tag_data) * head[idx].entry_count); - dbgprintf("reallocated data[idx]\n"); - } - for(i = 0; i < head[idx].entry_count; i++) { - dbgprintf("reading entry %d 0x%08x\n", i, &entries[idx][i]); - BRLAN_ReadDataFromMemory(&entries[idx][i], brlan_file, sizeof(tag_entry)); - dbgprintf("read entry.\n"); - } - for(i = 0; i < head[idx].entry_count; i++) { - dbgprintf("i %d cnt %d\n", i, head[idx].entry_count); - BRLAN_fileoffset = be32(entries[idx][i].offset) + taghead_location; - dbgprintf("read entry infos. 0x%08x\n", &entryinfo[idx][i]); - BRLAN_ReadDataFromMemory(&entryinfo[idx][i], brlan_file, sizeof(tag_entryinfo)); - dbgprintf("read entry info 0x%08x. %u\n", &data[idx][i][0], short_swap_bytes(entryinfo[idx][i].coord_count)); - data[idx][i] = realloc(NULL, sizeof(tag_data) * short_swap_bytes(entryinfo[idx][i].coord_count)); - dbgprintf("reallocated data[i].\n"); - for(z = 0; z < short_swap_bytes(entryinfo[idx][i].coord_count); z++) { - dbgprintf("reading data 0x%08x\n", &data[idx][i][z]); - BRLAN_ReadDataFromMemory(&data[idx][i][z], brlan_file, sizeof(tag_data)); - dbgprintf("read data.\n"); - } - } -} - void parse_brlan(char* filename) { FILE* fp = fopen(filename, "rb"); @@ -198,9 +93,12 @@ void parse_brlan(char* filename) printf("Error! Couldn't open %s!\n", filename); exit(1); } -#ifndef OLD_BRLAN_OUTSTYLE - xmlanout = fopen("testout.xmlan", "wb+"); -#endif // OLD_BRLAN_OUTSTYLE + 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); @@ -220,21 +118,14 @@ void parse_brlan(char* filename) strcpy(tag_types_list[13], "0x0D"); strcpy(tag_types_list[14], "0x0E"); strcpy(tag_types_list[15], "0x0F"); - fseek(fp, 0, SEEK_END); - int file_size = ftell(fp); - dbgprintf("Filesize is %d\n", file_size); - u8* brlan_file = (u8*)malloc(file_size); - dbgprintf("brlan_file allocated\n"); - fseek(fp, 0, SEEK_SET); - fread(brlan_file, file_size, 1, fp); - dbgprintf("brlan_file read to.\n"); + BRLAN_fileoffset = 0; brlan_header header; - BRLAN_ReadDataFromMemoryX(&header, brlan_file, sizeof(brlan_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, brlan_file, sizeof(brlan_pai1_universal)); + BRLAN_ReadDataFromMemoryX(&universal, data, sizeof(brlan_pai1_universal)); dbgprintf("pa1_universal read to.\n"); int pai1_header_type; @@ -244,226 +135,177 @@ void parse_brlan(char* filename) if((be32(universal.flags) & (1 << 25)) >= 1) { pai1_header_type = 2; - somethingIsSet = 1; - BRLAN_ReadDataFromMemory(&pai1_header2, brlan_file, sizeof(brlan_pai1_header_type2)); + BRLAN_ReadDataFromMemory(&pai1_header2, data, sizeof(brlan_pai1_header_type2)); } else { pai1_header_type = 1; - BRLAN_ReadDataFromMemory(&pai1_header1, brlan_file, sizeof(brlan_pai1_header_type1)); + BRLAN_ReadDataFromMemory(&pai1_header1, data, sizeof(brlan_pai1_header_type1)); } - dbgprintf("pai1 headers gotten.\n"); - + CreateGlobal_pai1(&pai1_header, pai1_header1, pai1_header2, pai1_header_type); - dbgprintf("pai1 global created.\n"); - - int tagcount = short_swap_bytes(pai1_header.num_entries); -// int tagcount = short_swap_bytes(pai1_header.num_entries); - dbgprintf("tagcount done.\n"); - u32 *taglocations = (u32*)calloc(tagcount, sizeof(u32)); - dbgprintf("allocated tag locations.\n"); - fourcc CCs[256]; - memset(CCs, 0, 256*4); - BRLAN_fileoffset = be32(pai1_header.entry_offset) + short_swap_bytes(header.pai1_offset); -// BRLAN_fileoffset = be32(pai1_header.entry_offset) + short_swap_bytes(header.pai1_offset); - dbgprintf("allocated fourccs.\n"); - BRLAN_ReadDataFromMemory(taglocations, brlan_file, tagcount * sizeof(u32)); - dbgprintf("read tag locations.\n"); - brlan_entry *tag_entries = (brlan_entry*)calloc(tagcount, sizeof(brlan_entry)); - dbgprintf("tag entries allocated.\n"); - tag_header *intag_heads = NULL; - dbgprintf("tag heads created.\n"); - tag_entry **intag_entries = NULL; - dbgprintf("tag entries created.\n"); - tag_entryinfo **intag_entryinfos = NULL; - dbgprintf("rlpa entry infos created.\n"); - tag_data ***intag_datas = NULL; - dbgprintf("rlpa datas created.\n"); - int intag_cnt = 1; - dbgprintf("Number of tagcount: %d\n", tagcount); - for(i = 0; i < tagcount; i++) { - BRLAN_fileoffset = be32(taglocations[i]) + short_swap_bytes(header.pai1_offset); - dbgprintf("fileoffset set.\n"); - BRLAN_ReadDataFromMemory(&(tag_entries[i]), brlan_file, sizeof(brlan_entry)); - dbgprintf("got tag entry.\n"); - if((be32(tag_entries[i].flags) & (1 << 25)) >= 1) { - somethingIsSet = 1; - BRLAN_fileoffset += sizeof(u32); - dbgprintf("skipped extra.\n"); - } - fourcc magick; - BRLAN_ReadDataFromMemoryX(magick, brlan_file, 4); - memcpy(CCs[i], magick, 4); - dbgprintf("read fourcc from %04x %02x%02x%02x%02x.\n", BRLAN_fileoffset, magick[0], magick[1], magick[2], magick[3]); - if(FourCCInList(CCs[i]) == 1) { - dbgprintf("we found a tag.\n"); - intag_heads = realloc(intag_heads, sizeof(tag_header) * intag_cnt); - dbgprintf("reallocated tag heads.\n"); - intag_entries = realloc(intag_entries, sizeof(tag_entry) * intag_cnt * 20); - dbgprintf("reallocated tag entries.\n"); - intag_entryinfos = realloc(intag_entryinfos, sizeof(tag_entryinfo) * intag_cnt * 20); - dbgprintf("reallocated tag entryinfos.\n"); - intag_datas = realloc(intag_datas, sizeof(tag_data) * intag_cnt * 20 * 6); - dbgprintf("reallocated tag datas.\n"); - if(intag_heads == NULL) { - printf("Error allocating heads.\n"); - exit(2); - } - if(intag_entries == NULL) { - printf("Error allocating entries.\n"); - exit(2); - } - if(intag_entryinfos == NULL) { - printf("Error allocating entryinfos.\n"); - exit(2); - } - if(intag_datas == NULL) { - printf("Error allocating datas.\n"); - exit(2); - } - ReadTagFromBRLAN(intag_cnt - 1, brlan_file, intag_heads, intag_entries, - intag_entryinfos, intag_datas); - intag_cnt++; - } - dbgprintf("looping.\n"); - } - -#ifndef OLD_BRLAN_OUTSTYLE + printf("<?xml version=\"1.0\"?>\n" \ "<xmlan framesize=\"%lu\" flags=\"%02x\">\n", short_swap_bytes(pai1_header.framesize), pai1_header.flags); -#endif // OLD_BRLAN_OUTSTYLE + int timgs = short_swap_bytes(pai1_header.num_timgs); printf("Number of TPL files: %d\n", timgs); - intag_cnt = 0; - int oldoffset = BRLAN_fileoffset; + BRLAN_fileoffset = short_swap_bytes(header.pai1_offset) + sizeof(brlan_pai1_header_type1); - dbgprintf("fileoffset %08x\n", BRLAN_fileoffset); + if ( pai1_header_type == 2 ) BRLAN_fileoffset += 4; int tableoff = BRLAN_fileoffset; int currtableoff = BRLAN_fileoffset; -#ifdef OLD_BRLAN_OUTSTYLE - printf("\nTIMG entries:"); - fflush(stdout); -#endif //OLD_BRLAN_OUTSTYLE + for(i = 0; i < timgs; i++) { u32 curr_timg_off = 0; - BRLAN_ReadDataFromMemory(&curr_timg_off, brlan_file, 4); - dbgprintf("currtimgoff %08x\n", be32(curr_timg_off)); + BRLAN_ReadDataFromMemory(&curr_timg_off, data, 4); char timgname[256]; memset(timgname, 0, 256); int z = tableoff + be32(curr_timg_off); - dbgprintf("z %08x\n", z); int o; - for(o = 0; brlan_file[z] != 0; timgname[o++] = brlan_file[z], z++); -#ifndef OLD_BRLAN_OUTSTYLE - printf("\t<timg name=\"%s\" />\n", timgname); -#else - printf(" Image name: %s\n", timgname); -#endif //OLD_BRLAN_OUTSTYLE + for(o = 0; data[z] != 0; timgname[o++] = data[z], z++); + printf("\t<timg name=\"%s\" />\n", timgname); currtableoff += 4; } - BRLAN_fileoffset = oldoffset; -#ifdef OLD_BRLAN_OUTSTYLE - printf("Parsed BRLAN! 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(" Filesize: %lu\n", be32(header.file_size)); - printf(" %s real file size!\n", be32(header.file_size) == file_size ? "Matches" : "Does not match"); - - // Not important to user, why bother. -/* printf(" pai1 Offset: %04x\n", short_swap_bytes(header.pai1_offset)); - printf(" pai1 Count: %04x\n", short_swap_bytes(header.pai1_count)); */ - printf("\npai1 header:\n"); - printf(" Type: %d\n", pai1_header_type); - printf(" Magic: %c%c%c%c\n", pai1_header.magic[0], pai1_header.magic[1], pai1_header.magic[2], pai1_header.magic[3]); - printf(" Size: %lu\n", be32(pai1_header.size)); - printf(" Framesize: %u\n", short_swap_bytes(pai1_header.framesize)); - printf(" Flags: %02x\n", pai1_header.flags); - printf(" unk1: %02x\n", pai1_header.unk1); - printf(" Number of Textures: %u\n", short_swap_bytes(pai1_header.num_timgs)); - printf(" Number of Entries: %u\n", short_swap_bytes(pai1_header.num_entries)); - printf(" unk2: %08lx\n", be32(pai1_header.unk2)); - - // Not important to user, why bother. -// printf(" Offset to Entries: 0x%08lx\n", be32(pai1_header.entry_offset)); - - printf("\nBRLAN entries:"); -#endif // OLD_BRLAN_OUTSTYLE + + 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++) printf("offset: %08x\n", taglocations[i]); + for(i = 0; i < tagcount; i++) { -#ifndef OLD_BRLAN_OUTSTYLE - printf("\t<tag "); - if(strlen(tag_entries[i].name) > 0) - printf("name=\"%s\" ", tag_entries[i].name); - printf("type=\"%c%c%c%c\" ", CCs[i][0], CCs[i][1], CCs[i][2], CCs[i][3]); - if(be32(tag_entries[i].flags) == 0x01000000) + 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; + if((be32(brlanEntry.flags) & (1 << 25)) >= 1) { + somethingIsSet = 1; + //BRLAN_fileoffset += sizeof(u32); + BRLAN_ReadDataFromMemory(&offsetToExtras, data, 4); + } + + 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 { - somethingIsSet = 1; - printf("format=\"%08x\">\n", be32(tag_entries[i].flags)); + printf("format=\"%08x\">\n", be32(brlanEntry.flags)); } -#endif // OLD_BRLAN_OUTSTYLE -#ifdef OLD_BRLAN_OUTSTYLE - printf("\n Entry %u:\n", i); - printf(" Name: %s\n", tag_entries[i].name); - if(be32(tag_entries[i].flags) == 0x01000000) - printf(" Type: %s\n", "Normal"); + 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(" Type: %08x\n", be32(tag_entries[i].flags)); + 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)); + + 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>%.12f</frame>\n", *(f32*)(&p1)); + printf("\t\t\t\t<value>%.12f</value>\n", *(f32*)(&p2)); + printf("\t\t\t\t<blend>%.12f</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>%.12f</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"); -// Not important to user, why bother. -// printf(" Animation Header Length: %lu\n", be32(tag_entries[i].anim_header_len)); - printf(" FourCC: %c%c%c%c\n", CCs[i][0], CCs[i][1], CCs[i][2], CCs[i][3]); -#endif // OLD_BRLAN_OUTSTYLE - if(FourCCInList(CCs[i]) == 1) { - DisplayTagInformation(intag_cnt, intag_heads, intag_entries, intag_entryinfos, intag_datas); - intag_cnt++; - }else{ -#ifdef OLD_BRLAN_OUTSTYLE - printf(" Sorry, this type is currently unknown.\n"); -#endif // OLD_BRLAN_OUTSTYLE } -#ifndef OLD_BRLAN_OUTSTYLE + } + printf("\t\t</entry>\n"); + isTriplet = 0; + } printf("\t</tag>\n"); -#endif // OLD_BRLAN_OUTSTYLE - } - if (somethingIsSet) - { - tag_header extraTagHeader; - tag_entry extraTagEntry; - tag_entryinfo extraTagEntryInfo; - tag_data extraTagData; - //read brlan_tag_header - BRLAN_ReadDataFromMemory(&extraTagHeader, brlan_file, sizeof(tag_header)); - //read brlan_tag_entry - BRLAN_ReadDataFromMemory(&extraTagEntry, brlan_file, sizeof(tag_entry)); - //read brlan_tag_entryinfo - BRLAN_ReadDataFromMemory(&extraTagEntryInfo, brlan_file, sizeof(tag_entryinfo)); - u32 p1 = be32(extraTagData.part1); - u32 p2 = be32(extraTagData.part2); - u32 p3 = be32(extraTagData.part3); - printf("\t<extratag type=\"%c%c%c%c\">\n", extraTagHeader.magic[0], extraTagHeader.magic[1], extraTagHeader.magic[2], extraTagHeader.magic[3]); - printf("\t\t<entry>\n"); - int q;for(q=0;q<short_swap_bytes(extraTagEntryInfo.coord_count);q++) + 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++) { - BRLAN_ReadDataFromMemory(&extraTagData, brlan_file, sizeof(tag_data)); - u32 p1 = be32(extraTagData.part1); - u32 p2 = be32(extraTagData.part2); - u32 p3 = be32(extraTagData.part3); + 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>%.6f</frame>\n", *(f32*)&p1); - printf("\t\t\t\t<value>%.6f</value>\n", *(f32*)&p2); - printf("\t\t\t\t<blend>%.6f</blend>\n", *(f32*)&p3); + printf("\t\t\t\t<frame>%.12f</frame>\n", *(f32*)(&p1)); + printf("\t\t\t\t<value>%.12f</value>\n", *(f32*)(&p2)); + printf("\t\t\t\t<blend>%.12f</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>%.12f</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"); - //free(extraBytesOne); - //free(extraBytesTwo); + } + somethingIsSet = 0; } -#ifndef OLD_BRLAN_OUTSTYLE + printf("</xmlan>\n"); -#endif // OLD_BRLAN_OUTSTYLE - free(brlan_file); + fclose(fp); } @@ -611,34 +453,31 @@ u32 create_entries_from_xml(mxml_node_t *tree, mxml_node_t *node, brlan_entry *e } 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); - entry[x].offset = entryinfolocs[x] - sizeof(brlan_entry); +// entry[x].offset = entryinfolocs[x] - sizeof(brlan_entry); // F I X + M E + if (x>0) + { + entry[x].offset = entry[x-1].offset + sizeof(tag_entryinfo) + (entryinfo[x-1].coord_count * sizeof(tag_data)); + } else { + entry[x].offset = x * (sizeof(tag_entryinfo) + sizeof(tag_data)); + } WriteBRLANTagEntryinfos(entryinfo[x], fp); + if (x==0) animLen = ftell(fp); WriteBRLANTagData(data[x], entryinfo[x].coord_count, fp); } 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 - 1); + 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); - char tagRLPA[4] = {'R','L','P','A' }; - char tagRLMC[4] = {'R','L','M','C' }; - char tagRLVC[4] = {'R','L','V','C' }; - char tagRLVI[4] = {'R','L','V','I' }; - if (memcmp(&head->magic, tagRLPA, 4) == 0) - { - entr->anim_header_len = sizeof(brlan_entry); - } else if ((memcmp(&head->magic, tagRLMC, 4) == 0) || (memcmp(&head->magic, tagRLVC, 4) == 0)) { - entr->anim_header_len = (head->entry_count * (sizeof(tag_entry) + sizeof(tag_data) + sizeof(tag_entryinfo))); - } else { - entr->anim_header_len = sizeof(tag_header) + (sizeof(tag_entry) * head->entry_count); - } + entr->anim_header_len = sizeof(brlan_entry); if (entr->flags & 0x02000000) { entr->anim_header_len += 4; @@ -646,106 +485,169 @@ u32 create_entries_from_xml(mxml_node_t *tree, mxml_node_t *node, brlan_entry *e fillerInt = be32(filesz); fseek(fp, fillerIntOffset, SEEK_SET); fwrite(&fillerInt, sizeof(u32), 1, fp); - BRLAN_fileoffset += 4; +// BRLAN_fileoffset += 4; fseek(fp, tempOffset, SEEK_SET); } WriteBRLANEntry(entr, fp); // write the final tag if flag & 0x02000000 - mxml_node_t *addonnode = NULL; - mxml_node_t *addonsubnode = NULL; - mxml_node_t *addonsubsubnode = NULL; - tag_header addonTagHeader; - tag_entry addonTagEntry; - tag_entryinfo addonTagEntryInfo; - tag_data *addonTagData; -// tag_data addonTagData; - char tempChar[256]; - addonnode = mxmlFindElement(tree, tree, "extratag", NULL, NULL, MXML_DESCEND); - if (addonnode != NULL) - { - printf("in the box\n"); + mxml_node_t *addonnode = NULL; + mxml_node_t *addonsubnode = NULL; + mxml_node_t *addonsubsubnode = NULL; + tag_header addonTagHeader; +// tag_entry *addonTagEntry; + tag_entry addonTagEntry[256]; +// tag_entryinfo *addonTagEntryInfo; + tag_entryinfo addonTagEntryInfo[256]; +// tag_data *addonTagData; + tag_data *addonTagData[1024]; +// tag_data2 *addonTagData2; + 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"); } - printf("addon magic: %c%c%c%c\n", temp[0], temp[1], temp[2], temp[3]); - //addonTagHeader.magic = temp; memcpy(addonTagHeader.magic, temp, 4); - printf("addon tagheader magic: %s\n", addonTagHeader.magic); - addonTagHeader.entry_count = 0x01; + addonTagHeader.entry_count = 0x00; addonTagHeader.pad1 = 0x0; addonTagHeader.pad2 = 0x0; addonTagHeader.pad3 = 0x0; - addonTagEntry.offset = be32(0x0c); - addonTagEntryInfo.type = short_swap_bytes(0x10); - addonTagEntryInfo.unk1 = short_swap_bytes(0x0200); - addonTagEntryInfo.pad1 = 0x0000; - addonTagEntryInfo.unk2 = be32(0x0000000C); - addonTagEntryInfo.coord_count = 0x0; - - for(addonsubnode = mxmlFindElement(addonnode, addonnode, "triplet", NULL, NULL, MXML_DESCEND); addonsubnode != NULL; addonsubnode = mxmlFindElement(addonsubnode, addonnode, "triplet", NULL, NULL, MXML_DESCEND)) + fseek(fp, oldpos, SEEK_SET); + fwrite(&addonTagHeader, sizeof(tag_header), 1, fp); // GET THIS IN PLACE +// addonTagEntry.offset = 0; + 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)) { - addonTagEntryInfo.coord_count +=1; - u8 tC = addonTagEntryInfo.coord_count; - addonTagData = realloc(addonTagData, sizeof(tag_data) * tC); - addonsubsubnode = mxmlFindElement(addonsubnode, addonsubnode, "frame", NULL, NULL, MXML_DESCEND); - if (addonsubsubnode != NULL) - { - get_value(addonsubsubnode, tempChar, 256); - f32 f1 = atof(tempChar); - addonTagData[tC-1].part1 = *(u32*)&f1; - addonTagData[tC-1].part1 = int_swap_bytes(addonTagData[tC-1].part1); - -// addonTagData.part1 = *(u32*)&f1; -// addonTagData.part1 = int_swap_bytes(addonTagData.part1); + 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 < 16) && (strcmp(temp3[i - 1], temp2) != 0); i++); + if(i == 16) + 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; - addonsubsubnode = mxmlFindElement(addonsubnode, addonsubnode, "value", NULL, NULL, MXML_DESCEND); - if (addonsubsubnode != NULL) + for(addonsubnode = mxmlFindElement(entrynode, entrynode, "triplet", NULL, NULL, MXML_DESCEND); addonsubnode != NULL; addonsubnode = mxmlFindElement(addonsubnode, entrynode, "triplet", NULL, NULL, MXML_DESCEND)) { - get_value(addonsubsubnode, tempChar, 256); - f32 f2 = atof(tempChar); - addonTagData[tC-1].part2 = *(u32*)&f2; - addonTagData[tC-1].part2 = int_swap_bytes(addonTagData[tC-1].part2); - -// addonTagData.part2 = *(u32*)&f2; -// addonTagData.part2 = int_swap_bytes(addonTagData.part2); + 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 = realloc(addonTagData, tC*4) + 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); + printf("f1: %.10f\tp1: %08x\n", f1, *(u32*)&f1); + printf("tagData: %08x\n", 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); + } } - - addonsubsubnode = mxmlFindElement(addonsubnode, addonsubnode, "blend", NULL, NULL, MXML_DESCEND); - if(addonsubsubnode != NULL) + for(addonsubnode = mxmlFindElement(entrynode, entrynode, "pair", NULL, NULL, MXML_DESCEND); addonsubnode != NULL; addonsubnode = mxmlFindElement(addonsubnode, entrynode, "pair", NULL, NULL, MXML_DESCEND)) { - get_value(addonsubsubnode, tempChar, 256); - f32 f3 = atof(tempChar); - printf("f3: %f\n", f3); - addonTagData[tC-1].part3 = *(u32*)&f3; - addonTagData[tC-1].part3 = int_swap_bytes(addonTagData[tC-1].part3); + printf("is the pair\n"); + 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.part3 = *(u32*)&f3; -// addonTagData.part3 = int_swap_bytes(addonTagData.part3); +// addonTagData2 = addonTagData2 = realloc(addonTagData2, tC * 4); + 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)); + } } +// fseek(fp, oldpos, SEEK_SET); +// fwrite(&addonTagHeader, sizeof(tag_header), 1, fp); // GET THIS IN PLACE + addonTagEntry[addonTagHeader.entry_count].offset = sizeof(tag_header); + if (addonTagHeader.entry_count > 1) + addonTagEntry[addonTagHeader.entry_count].offset = addonTagEntry[addonTagHeader.entry_count-1].offset + (sizeof(tag_data) * addonTagEntryInfo[addonTagHeader.entry_count-1].coord_count) + sizeof(tag_header); +// fwrite(&addonTagEntry, sizeof(tag_entry), 1, fp); // GET THIS FOR MULTIPLE ENTRIES + u32 eC = addonTagHeader.entry_count; +// addonTagEntryInfo[addonTagHeader.entry_count].coord_count = short_swap_bytes(addonTagEntryInfo[addonTagHeader.entry_count].coord_count); + addonTagEntryInfo[eC].coord_count = short_swap_bytes(addonTagEntryInfo[eC].coord_count); +// fwrite(&addonTagEntryInfo, sizeof(tag_entryinfo), 1, fp); +// if (addonTagEntryInfo[addonTagHeader.entry_count].unk1 == 0x2) +// fwrite(addonTagData, sizeof(tag_data), short_swap_bytes(addonTagEntryInfo.coord_count), fp); +// if (addonTagEntryInfo[addonTagHeader.entry_count].unk1 == 0x1) +// fwrite(addonTagData2, sizeof(tag_data2), short_swap_bytes(addonTagEntryInfo.coord_count), fp); + addonTagHeader.entry_count++; +// filesz = ftell(fp); } +// filesz = ftell(fp); fseek(fp, oldpos, SEEK_SET); - // WriteBRLANTagHeader(addonTagHeader, fp); - fwrite(&addonTagHeader, sizeof(tag_header), 1, fp); - // WriteBRLANTagEntry(addonTagEntry, fp); - fwrite(&addonTagEntry, sizeof(tag_entry), 1, fp); - // WriteBRLANTagInfo(addonTagEntryInfo, fp); - addonTagEntryInfo.coord_count = short_swap_bytes(addonTagEntryInfo.coord_count); - fwrite(&addonTagEntryInfo, sizeof(tag_entryinfo), 1, fp); - // WriteExtraBytes(byte, fp); -// u32 extraOne = 0x0; -// fwrite(&extraOne, 4, 1, fp); - // WriteBRLANTagData(addonTagData, fp); - fwrite(addonTagData, sizeof(tag_data), short_swap_bytes(addonTagEntryInfo.coord_count), fp); -// fwrite(&addonTagData, sizeof(tag_data), 1, fp); - // WriteBRLANTwoExtraBytes(extraBytes, fp); -// u32 extraTwo[2] = {0x0, 0x0}; -// fwrite(extraTwo, 8, 1, fp); + fwrite(&addonTagHeader, sizeof(tag_header), 1, fp); // GET THIS IN PLACE + 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); + fwrite(&addonTagEntryInfo, sizeof(tag_entryinfo), addonTagHeader.entry_count, fp); + + for (l=0;l<addonTagHeader.entry_count;l++) + { + 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); @@ -795,7 +697,6 @@ void create_tag_from_xml(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32 if(strcmp(temp, "NORMAL") == 0) entr.flags = 0x01000000; else -// entr.flags = atoi(temp); entr.flags = strtoul(temp, NULL, 16); create_entries_from_xml(tree, node, &entr, &head, tagblob, blobsize); } @@ -901,7 +802,6 @@ void write_brlan(char *infile, char* outfile) strcpy(temp, "20"); } paihead.framesize = atoi(temp); -// paihead.flags = 1; // NOT ALWAYS 1 memset(temp, 0, 256); if(mxmlElementGetAttr(tree, "flags") != NULL) { @@ -931,9 +831,12 @@ void write_brlan(char *infile, char* outfile) 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) @@ -945,7 +848,18 @@ void write_brlan(char *infile, char* outfile) mwrite(temp, strlen(temp) + 1, 1, timgmem); totaltimgize += strlen(temp) + 1; } - headerOffset = ftell(fp); + 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); + 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)); @@ -958,94 +872,24 @@ void write_brlan(char *infile, char* outfile) } tagsbigOffset = ftell(fp); fseek(fp, headerOffset, SEEK_SET); - int j; for (j=0;j<blobcount;j++) - { - blobOffsets[j] += (blobcount * 4); - blobOffsets[j] = be32(blobOffsets[j]); - fwrite(&blobOffsets[j], sizeof(u32), 1, fp); - } + fseek(fp, tagsbigOffset, SEEK_SET); -/* - //new home of the extra tag code - // write the final tag if flag & 0x02000000 - mxml_node_t *addonnode = NULL; - mxml_node_t *addonsubnode = NULL; - mxml_node_t *addonsubsubnode = NULL; - tag_header addonTagHeader; - tag_entry addonTagEntry; - tag_entryinfo addonTagEntryInfo; - tag_data addonTagData; - char tempChar[256]; - addonnode = mxmlFindElement(tree, tree, "extratag", NULL, NULL, MXML_DESCEND); - if (addonnode != NULL) - { - printf("in the second box\n"); - if(mxmlElementGetAttr(addonnode, "type") != NULL) - strcpy(temp, mxmlElementGetAttr(addonnode, "type")); - else{ - printf("No type attribute found!\nSkipping this entry!\n"); - } - //addonTagHeader.magic = temp; - memcpy(addonTagHeader.magic, temp, 4); - addonTagHeader.entry_count = 0x01; - addonTagHeader.pad1 = 0x0; - addonTagHeader.pad2 = 0x0; - addonTagHeader.pad3 = 0x0; - addonTagEntry.offset = be32(0x0c); - addonTagEntryInfo.type = short_swap_bytes(0x2); - addonTagEntryInfo.unk1 = short_swap_bytes(0x0200); - addonTagEntryInfo.pad1 = 0x0000; - addonTagEntryInfo.unk2 = be32(0x0000000C); - addonTagEntryInfo.coord_count = short_swap_bytes(0x01); - - for(addonsubnode = mxmlFindElement(addonnode, addonnode, "triplet", NULL, NULL, MXML_DESCEND); addonsubnode != NULL; addonsubnode = mxmlFindElement(addonsubnode, addonnode, "triplet", NULL, NULL, MXML_DESCEND)) - { - addonsubsubnode = mxmlFindElement(addonsubnode, addonsubnode, "frame", NULL, NULL, MXML_DESCEND); - if (addonsubsubnode != NULL) - { - get_value(addonsubsubnode, tempChar, 256); - addonTagData.part1 = float_swap_bytes(atof(tempChar)); - } - - addonsubsubnode = mxmlFindElement(addonsubnode, addonsubnode, "value", NULL, NULL, MXML_DESCEND); - if (addonsubsubnode != NULL) - { - get_value(addonsubsubnode, tempChar, 256); - addonTagData.part2 = float_swap_bytes(atof(tempChar)); - } - - addonsubsubnode = mxmlFindElement(addonsubnode, addonsubnode, "blend", NULL, NULL, MXML_DESCEND); - if(addonsubsubnode != NULL) - { - get_value(addonsubsubnode, tempChar, 256); - addonTagData.part3 = float_swap_bytes(atof(tempChar)); - } - } - fseek(fp, oldpos, SEEK_SET); - // WriteBRLANTagHeader(addonTagHeader, fp); - fwrite(&addonTagHeader, sizeof(tag_header), 1, fp); - // WriteBRLANTagEntry(addonTagEntry, fp); - fwrite(&addonTagEntry, sizeof(tag_entry), 1, fp); - // WriteBRLANTagInfo(addonTagEntryInfo, fp); - fwrite(&addonTagEntryInfo, sizeof(tag_entryinfo), 1, fp); - // WriteExtraBytes(byte, fp); - u32 extraOne = 0x0; - fwrite(&extraOne, 4, 1, fp); - // WriteBRLANTagData(addonTagData, fp); - fwrite(&addonTagData, sizeof(tag_data), 1, fp); - // WriteBRLANTwoExtraBytes(extraBytes, fp); - u32 extraTwo[2] = {0x0, 0x0}; - fwrite(extraTwo, 8, 1, fp); - filesz = ftell(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; + 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; @@ -83,7 +83,7 @@ typedef struct typedef struct { u16 type; // Type (look at animtypes) - u16 unk1; // ??? Every case has been 0x0200 + 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. @@ -96,6 +96,13 @@ typedef struct 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; +} tag_data2; + void parse_brlan(char* filename); void make_brlan(char* infile, char* outfile); @@ -9,7 +9,7 @@ #define BENZIN_VERSION_MAJOR 0 #define BENZIN_VERSION_MINOR 1 -#define BENZIN_VERSION_BUILD 576 +#define BENZIN_VERSION_BUILD 602 #define BENZIN_VERSION_OTHER "WIP" #define INFORMATION_TEXT \ |
