diff options
| author | megazig <megazig@megazig-desktop.(none)> | 2009-04-22 00:53:28 -0500 |
|---|---|---|
| committer | megazig <megazig@megazig-desktop.(none)> | 2009-04-22 00:53:28 -0500 |
| commit | 1fefc8ed20827dff12fcfa8928d7d0074f740641 (patch) | |
| tree | a870c126f0baf451053be4cc6c0b3afdd5e53cf7 /brlan.c | |
| parent | 6054311dacd847239162a6f3ba87f085defddcad (diff) | |
fixed brlan.c for new struct
Diffstat (limited to '')
| -rw-r--r-- | brlan.c | 949 |
1 files changed, 160 insertions, 789 deletions
@@ -87,6 +87,60 @@ static int FourCCInList(fourcc cc) return 0; } +void BRLAN_CreateXMLTag(tag_header tagHeader, void* data, u32 offset) +{ + BRLAN_fileoffset = offset; + BRLAN_ReadDataFromMemory(&tagHeader, data, sizeof(tag_header)); + + printf("\t\t<tag type=\"%c%c%c%c\">\n", tagHeader.magic[0], tagHeader.magic[1], tagHeader.magic[2], tagHeader.magic[3]); + + tag_entryinfo tagEntryInfo; + u32 tagentrylocations[tagHeader.entry_count]; + BRLAN_ReadDataFromMemory(&tagentrylocations, data, tagHeader.entry_count * sizeof(u32)); + u32 i, j; + for ( i = 0; i < tagHeader.entry_count; i++) + { + BRLAN_fileoffset = offset + be32(tagentrylocations[i]); + BRLAN_ReadDataFromMemory(&tagEntryInfo, data, sizeof(tag_entryinfo)); + if(short_swap_bytes(tagEntryInfo.type) < 16) + printf("\t\t\t<entry type=\"%s\">\n", tag_types_list[short_swap_bytes(tagEntryInfo.type)]); + else + printf("\t\t\t<entry type=\"%u\">\n", short_swap_bytes(tagEntryInfo.type)); + + for( j = 0; j < short_swap_bytes(tagEntryInfo.coord_count); j++) + { + if ( tagEntryInfo.unk1 == 0x2 ) + { + tag_data tagData; + BRLAN_ReadDataFromMemory(&tagData, data, sizeof(tag_data)); + + u32 p1 = be32(tagData.part1); + u32 p2 = be32(tagData.part2); + u32 p3 = be32(tagData.part3); + printf("\t\t\t\t<triplet>\n"); + printf("\t\t\t\t\t<frame>%.15f</frame>\n", *(f32*)(&p1)); + printf("\t\t\t\t\t<value>%.15f</value>\n", *(f32*)(&p2)); + printf("\t\t\t\t\t<blend>%.15f</blend>\n", *(f32*)(&p3)); + printf("\t\t\t\t</triplet>\n"); + } else { + tag_data2 tagData2; + BRLAN_ReadDataFromMemory(&tagData2, data, 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\t<pair>\n"); + printf("\t\t\t\t\t<data1>%.15f</data1>\n", *(f32*)(&p1)); + printf("\t\t\t\t\t<data2>%04x</data2>\n", p2); + printf("\t\t\t\t\t<padding>%04x</padding>\n", p3); + printf("\t\t\t\t</pair>\n"); + } + } + printf("\t\t\t</entry>\n"); + } + printf("\t\t</tag>\n"); +} + void parse_brlan(char* filename) { FILE* fp = fopen(filename, "rb"); @@ -100,7 +154,7 @@ void parse_brlan(char* filename) u8 data[lengthOfFile]; fread(data, lengthOfFile, 1, fp); - int i; + int i, j; for(i = 0; i < 16; i++) memset(tag_types_list[i], 0, 24); strcpy(tag_types_list[0], "X Translation"); @@ -148,21 +202,19 @@ void parse_brlan(char* filename) "<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); 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++) { + 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++); + for( j = 0; data[z] != 0; timgname[j++] = data[z], z++); printf("\t<timg name=\"%s\" />\n", timgname); currtableoff += 4; } @@ -172,8 +224,7 @@ void parse_brlan(char* filename) 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; + for( i = 0; i < tagcount; i++) { brlan_entry brlanEntry; tag_header tagHeader; tag_entry tagEntry; @@ -182,300 +233,17 @@ void parse_brlan(char* filename) 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); - } - - 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)); - - 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"); - - 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"); - - } - } - 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; - - 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 { - - 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)); - - 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)); - - 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; - - 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<pane name=\"%s\">\n", brlanEntry.name); + u32 entrylocations[brlanEntry.num_tags]; + BRLAN_ReadDataFromMemory(entrylocations, data, brlanEntry.num_tags * sizeof(u32)); + for ( j = 0; j < brlanEntry.num_tags; j++) + { + BRLAN_CreateXMLTag(tagHeader, data, brlanEntryOffset + be32(entrylocations[j])); + } + printf("\t</pane>\n"); + } printf("</xmlan>\n"); - fclose(fp); } @@ -494,6 +262,14 @@ void WriteBRLANTagEntries(tag_entry* entry, u8 count, FILE* fp) } } +void WriteBRLANOffsets(u32* offsets, u32 number, FILE* fp) +{ + u32 tempoffsets[number]; + int i; + for(i=0;i<number;i++) tempoffsets[i] = be32(offsets[i]); + fwrite(tempoffsets, number * sizeof(u32), 1, fp); +} + void WriteBRLANTagEntryinfos(tag_entryinfo entryinfo, FILE* fp) { tag_entryinfo writeentryinfo; @@ -522,12 +298,14 @@ 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); + writeentr.num_tags = entr->num_tags; + writeentr.is_material = entr->is_material; + writeentr.pad[0] = 0x0; + writeentr.pad[1] = 0x0; fwrite(&writeentr, sizeof(brlan_entry), 1, fp); } -u32 create_entries_from_xml(mxml_node_t *tree, mxml_node_t *node, brlan_entry *entr, tag_header* head, u8** tagblob, u32* blobsize) +void create_entries_from_xml(mxml_node_t *tree, mxml_node_t *node, brlan_entry *entr, tag_header* head, FILE* fp) { tag_entry* entry = NULL; tag_entryinfo* entryinfo = NULL; @@ -642,29 +420,8 @@ u32 create_entries_from_xml(mxml_node_t *tree, mxml_node_t *node, brlan_entry *e 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; - } + + head->pad1 = 0x0; head->pad2 = 0x0; head->pad3 = 0x0; WriteBRLANTagHeader(head, fp); u32 entryloc = ftell(fp); u32 animLen; @@ -692,7 +449,6 @@ u32 create_entries_from_xml(mxml_node_t *tree, mxml_node_t *node, brlan_entry *e 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); @@ -707,410 +463,60 @@ u32 create_entries_from_xml(mxml_node_t *tree, mxml_node_t *node, brlan_entry *e free(data2); u32 oldpos = ftell(fp); fseek(fp, entryloc, SEEK_SET); - for(x=0;x<head->entry_count;x++) + 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); - } - - 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; - - 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); - } - } - - 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); - } - } - - *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) +void create_tag_from_xml(mxml_node_t *tree, mxml_node_t *node, FILE* fp) { - tag_header head; brlan_entry entr; + entr.num_tags = 0x0; + entr.is_material = 0x0; + entr.pad[0] = 0x0; + entr.pad[1] = 0x0; + char temp[256]; memset(entr.name, 0, 20); if(mxmlElementGetAttr(node, "name") != NULL) strcpy(entr.name, mxmlElementGetAttr(node, "name")); else{ } - if(mxmlElementGetAttr(node, "type") != NULL) - strcpy(temp, mxmlElementGetAttr(node, "type")); - 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; + mxml_node_t *tagnode; + for(tagnode = mxmlFindElement(node, node, "tag", NULL, NULL, MXML_DESCEND); tagnode != NULL; tagnode = mxmlFindElement(tagnode, node, "tag", NULL, NULL, MXML_DESCEND)) + { + entr.num_tags++; + } + u32 brlanentryoffset = ftell(fp); + WriteBRLANEntry(&entr, fp); + + u32 entrylocations[entr.num_tags]; + int i; for ( i = 0; i < entr.num_tags; i++) entrylocations[i] = brlanentryoffset; + WriteBRLANOffsets(entrylocations, entr.num_tags, fp); + + entr.num_tags = 0x0; + for(tagnode = mxmlFindElement(node, node, "tag", NULL, NULL, MXML_DESCEND); tagnode != NULL; tagnode = mxmlFindElement(tagnode, node, "tag", NULL, NULL, MXML_DESCEND)) + { + entrylocations[entr.num_tags] = ftell(fp) - entrylocations[entr.num_tags]; + if(mxmlElementGetAttr(tagnode, "type") != NULL) + strcpy(temp, mxmlElementGetAttr(tagnode, "type")); + else { + printf("No type attribute found!\nQuitting!\n"); + exit(1); + } + for ( i = 0; i < 4; i++) head.magic[i] = temp[i]; + create_entries_from_xml(node, tagnode, &entr, &head, fp); + entr.num_tags++; + } + u32 tempOffset = ftell(fp); + fseek(fp, brlanentryoffset + sizeof(brlan_entry), SEEK_SET); + WriteBRLANOffsets(entrylocations, entr.num_tags, fp); + fseek(fp, tempOffset, SEEK_SET); } void WriteBRLANHeader(brlan_header rlanhead, FILE* fp) @@ -1186,8 +592,6 @@ void write_brlan(char *infile, char* outfile) printf("destination brlan couldn't be opened!\n"); exit(1); } - u8* tagblob; - u32 blobsize; u16 blobcount = 0; u32 bloboffset; brlan_header rlanhead; @@ -1245,96 +649,64 @@ void write_brlan(char *infile, char* outfile) u32 totaltimgize = 0; u32 timgStartOffset = ftell(fp); u32 timgOffsets[256]; + + u32 timgnumber = 0x0; + for(node = mxmlFindElement(tree, tree, "timg", NULL, NULL, MXML_DESCEND); node != NULL; node = mxmlFindElement(node, tree, "timg", NULL, NULL, MXML_DESCEND)) + { + timgnumber++; + } + u32 imageoffsets[timgnumber]; + u32 imagefileoffset = sizeof(brlan_header) + sizeof(brlan_pai1_header_type1) + (timgnumber * sizeof(u32)); + memset(imageoffsets, imagefileoffset, timgnumber); + WriteBRLANOffsets(imageoffsets, timgnumber, fp); + for(node = mxmlFindElement(tree, tree, "timg", NULL, NULL, MXML_DESCEND); node != NULL; node = mxmlFindElement(node, tree, "timg", NULL, NULL, MXML_DESCEND)) { timgcount++; - timgoffset = ftell(fp) + mtell(timgmem) - (4 * (timgcount + 1)); - timgOffsets[timgcount-1] = mtell(timgmem); - timgoffset = be32(timgoffset); - fwrite(&timgoffset, sizeof(u32), 1, fp); + imageoffsets[timgcount-1] += totaltimgize; 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); + fwrite(temp, strlen(temp) + 1, 1, fp); 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, imagefileoffset, SEEK_SET); + WriteBRLANOffsets(imageoffsets, timgnumber, 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; - - 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; + u32 panecount = 0x0; + for(node = mxmlFindElement(tree, tree, "pane", NULL, NULL, MXML_DESCEND); node != NULL; node = mxmlFindElement(node, tree, "pane", NULL, NULL, MXML_DESCEND)) + { + panecount++; + } + u32 paneoffsets[panecount]; + u32 tagoffset = sizeof(brlan_header) + sizeof(brlan_pai1_header_type1) + (timgcount * sizeof(u32)) + totaltimgize; + tagoffset = ftell(fp); + for(i = 0; i < panecount; i++) paneoffsets[i]=sizeof(brlan_header); + WriteBRLANOffsets(paneoffsets, panecount, fp); + + for(node = mxmlFindElement(tree, tree, "pane", NULL, NULL, MXML_DESCEND); node != NULL; node = mxmlFindElement(node, tree, "pane", NULL, NULL, MXML_DESCEND)) + { + blobcount++; + paneoffsets[blobcount-1] = ftell(fp) - paneoffsets[blobcount-1]; + create_tag_from_xml(tree, node, fp); + totaltagsize = ftell(fp) - tagoffset; + } + u32 fileSize = ftell(fp); + fseek(fp, tagoffset, SEEK_SET); + WriteBRLANOffsets(paneoffsets, blobcount, fp); + -// 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); - - 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); + paihead.size = fileSize - rlanhead.pai1_offset; + rlanhead.file_size = fileSize; fseek(fp, 0, SEEK_SET); WriteBRLANHeader(rlanhead, fp); WriteBRLANPaiHeader(paihead, fp); @@ -1345,4 +717,3 @@ void make_brlan(char* infile, char* outfile) printf("Parsing XMLAN @ %s.\n", infile); write_brlan(infile, outfile); } - |
