Beispiel #1
0
void parse_brlan(char* filename, char *filenameout)
{
    FILE* fp = fopen(filename, "rb");
    if(fp == NULL) {
        printf("Error! Couldn't open %s!\n", filename);
        exit(1);
    }
    fseek(fp, 0, SEEK_END);
    u32 lengthOfFile = ftell(fp);
    fseek(fp, 0, SEEK_SET);
    u8 data[lengthOfFile];
    fread(data, lengthOfFile, 1, fp);

    int i, j;
    for(i = 0; i < 16; i++)
    {
        memset(tag_types_list[i], 0, 24);
        memset(tag_types_rlmc_list[i], 0, 24);
	memset(tag_types_rlvc_list[i], 0, 24);
    }
    strcpy(tag_types_list[0], "X Translation");
    strcpy(tag_types_list[1], "Y Translation");
    strcpy(tag_types_list[2], "Z Translation");
    strcpy(tag_types_list[3], "X Flip");
    strcpy(tag_types_list[4], "Y Flip");
    strcpy(tag_types_list[5], "Angle");
    strcpy(tag_types_list[6], "X Zoom");
    strcpy(tag_types_list[7], "Y Zoom");
    strcpy(tag_types_list[8], "Width");
    strcpy(tag_types_list[9], "Height");
    strcpy(tag_types_list[10], "0x0A");
    strcpy(tag_types_list[11], "0x0B");
    strcpy(tag_types_list[12], "0x0C");
    strcpy(tag_types_list[13], "0x0D");
    strcpy(tag_types_list[14], "0x0E");
    strcpy(tag_types_list[15], "0x0F");

    strcpy(tag_types_rlmc_list[0], "0x00");
    strcpy(tag_types_rlmc_list[1], "0x01");
    strcpy(tag_types_rlmc_list[2], "0x02");
    strcpy(tag_types_rlmc_list[3], "0x03");
    strcpy(tag_types_rlmc_list[4], "Blackcolor R");
    strcpy(tag_types_rlmc_list[5], "Blackcolor G");
    strcpy(tag_types_rlmc_list[6], "Blackcolor B");
    strcpy(tag_types_rlmc_list[7], "Blackcolor A");
    strcpy(tag_types_rlmc_list[8], "Whitecolor R");
    strcpy(tag_types_rlmc_list[9], "Whitecolor G");
    strcpy(tag_types_rlmc_list[10], "Whitecolor B");
    strcpy(tag_types_rlmc_list[11], "Whitecolor A");
    strcpy(tag_types_rlmc_list[12], "0x0C");
    strcpy(tag_types_rlmc_list[13], "0x0D");
    strcpy(tag_types_rlmc_list[14], "0x0E");
    strcpy(tag_types_rlmc_list[15], "0x0F");

    strcpy(tag_types_rlvc_list[0], "Top Left R");
    strcpy(tag_types_rlvc_list[1], "Top Left G");
    strcpy(tag_types_rlvc_list[2], "Top Left B");
    strcpy(tag_types_rlvc_list[3], "Top Left A");
    strcpy(tag_types_rlvc_list[4], "Top Right R");
    strcpy(tag_types_rlvc_list[5], "Top Right G");
    strcpy(tag_types_rlvc_list[6], "Top Right B");
    strcpy(tag_types_rlvc_list[7], "Top Right A");
    strcpy(tag_types_rlvc_list[8], "Bottom Left R");
    strcpy(tag_types_rlvc_list[9], "Bottom Left G");
    strcpy(tag_types_rlvc_list[10], "Bottom Left B");
    strcpy(tag_types_rlvc_list[11], "Bottom Left A");
    strcpy(tag_types_rlvc_list[12], "Bottom Right R");
    strcpy(tag_types_rlvc_list[13], "Bottom Right G");
    strcpy(tag_types_rlvc_list[14], "Bottom Right B");
    strcpy(tag_types_rlvc_list[15], "Bottom Right A");

    BRLAN_fileoffset = 0;
    brlan_header header;
    BRLAN_ReadDataFromMemoryX(&header, data, sizeof(brlan_header));
    BRLAN_fileoffset = short_swap_bytes(header.pai1_offset);
    brlan_pai1_universal universal;
    BRLAN_ReadDataFromMemoryX(&universal, data, sizeof(brlan_pai1_universal));
    
    int pai1_header_type;
    brlan_pai1_header_type1 pai1_header1;
    brlan_pai1_header_type2 pai1_header2;
    brlan_pai1_header_type2 pai1_header;

    if((be32(universal.flags) & (1 << 25)) >= 1) {
        pai1_header_type = 2;
        BRLAN_ReadDataFromMemory(&pai1_header2, data, sizeof(brlan_pai1_header_type2));
    } else {
        pai1_header_type = 1;
        BRLAN_ReadDataFromMemory(&pai1_header1, data, sizeof(brlan_pai1_header_type1));
    }

    CreateGlobal_pai1(&pai1_header, pai1_header1, pai1_header2, pai1_header_type);


    FILE *xmlFile;
    xmlFile = fopen(filenameout, "w");
    mxml_node_t *xml;
    mxml_node_t *xmlan;
    xml = mxmlNewXML("1.0");
    xmlan = mxmlNewElement(xml, "xmlan");
    mxmlElementSetAttrf(xmlan, "version", "%d.%d.%d%s", BENZIN_VERSION_MAJOR, BENZIN_VERSION_MINOR, BENZIN_VERSION_BUILD, BENZIN_VERSION_OTHER);
    mxmlElementSetAttrf(xmlan, "framesize", "%lu", (long unsigned int)short_swap_bytes(pai1_header.framesize));
    mxmlElementSetAttrf(xmlan, "flags", "%02x", pai1_header.flags);

    int timgs = short_swap_bytes(pai1_header.num_timgs);

    BRLAN_fileoffset = short_swap_bytes(header.pai1_offset) + sizeof(brlan_pai1_header_type1);
    if ( pai1_header_type == 2 ) BRLAN_fileoffset += 4;
    int tableoff = BRLAN_fileoffset;
    int currtableoff = BRLAN_fileoffset;

    mxml_node_t *timg;
    for( i = 0; i < timgs; i++) {
        u32 curr_timg_off = 0;
        BRLAN_ReadDataFromMemory(&curr_timg_off, data, 4);
        char timgname[256];
        memset(timgname, 0, 256);
        int z = tableoff + be32(curr_timg_off);
        for( j = 0; data[z] != 0; timgname[j++] = data[z], z++);
        {
            timg = mxmlNewElement(xmlan, "timg");
            mxmlElementSetAttrf(timg, "name", "%s", timgname);
        }
        currtableoff += 4;
    }

    int tagcount = short_swap_bytes(pai1_header.num_entries);
    u32 taglocations[tagcount];
    BRLAN_fileoffset = be32(pai1_header.entry_offset) + short_swap_bytes(header.pai1_offset);
    BRLAN_ReadDataFromMemory(taglocations, data, tagcount * sizeof(u32));

    for( i = 0; i < tagcount; i++) {
        brlan_entry brlanEntry;
        tag_header tagHeader;
        BRLAN_fileoffset = be32(taglocations[i]) + short_swap_bytes(header.pai1_offset);
        u32 brlanEntryOffset = BRLAN_fileoffset;
        BRLAN_ReadDataFromMemory(&brlanEntry, data, sizeof(brlan_entry));

        mxml_node_t *pane;
        pane = mxmlNewElement(xmlan, "pane"); mxmlElementSetAttrf(pane, "name", "%s", brlanEntry.name); mxmlElementSetAttrf(pane, "type", "%u", brlanEntry.is_material);

        u32 entrylocations[brlanEntry.num_tags];
        BRLAN_ReadDataFromMemory(entrylocations, data, brlanEntry.num_tags * sizeof(u32));
        for ( j = 0; j < brlanEntry.num_tags; j++)
        {
            BRLAN_CreateXMLTag(tagHeader, data, brlanEntryOffset + be32(entrylocations[j]), pane);
        }
     }
    mxmlSaveFile(xml, xmlFile, whitespace_cb);
    mxmlDelete(xml);
    fclose(xmlFile);
    fclose(fp);
}
Beispiel #2
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);

    int i, j;
    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;

    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);

    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);

    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);
        for( j = 0; data[z] != 0; timgname[j++] = 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));

    for( i = 0; i < tagcount; i++) {
        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));

		printf("\t<pane name=\"%s\" type=\"%u\">\n", brlanEntry.name, brlanEntry.is_material);

		u32 entrylocations[brlanEntry.num_tags];
		BRLAN_ReadDataFromMemory(entrylocations, data, brlanEntry.num_tags * sizeof(u32));
		for ( j = 0; j < brlanEntry.num_tags; j++)
		{
			BRLAN_CreateXMLTag(tagHeader, data, brlanEntryOffset + be32(entrylocations[j]));
		}
 		printf("\t</pane>\n");
 	}
    printf("</xmlan>\n");
    fclose(fp);
}