From b440e369ed1a68337101f3258c44ee91765284e9 Mon Sep 17 00:00:00 2001 From: comex Date: Mon, 20 Apr 2009 17:06:38 -0400 Subject: brlan.h and shit --- brlyt.c | 4682 +++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 2341 insertions(+), 2341 deletions(-) (limited to 'brlyt.c') diff --git a/brlyt.c b/brlyt.c index 1fb50e9..f779527 100644 --- a/brlyt.c +++ b/brlyt.c @@ -21,12 +21,12 @@ #include "xml.h" #ifdef DEBUGBRLYT -#define dbgprintf printf +#define dbgprintf printf #else -#define dbgprintf // +#define dbgprintf // #endif //DEBUGBRLYT -#define MAXIMUM_TAGS_SIZE (0x1000) +#define MAXIMUM_TAGS_SIZE (0x1000) char pic1_magic[] = "pic1"; char pan1_magic[] = "pan1"; @@ -54,103 +54,103 @@ int lengthOfTextures; static int FourCCsMatch(fourcc cc1, fourcc cc2) { - dbgprintf("FourCCs\n"); - int ret[4]; - dbgprintf("Let's go %08x %08x\n", cc1, cc2); - ret[0] = (cc1[0] == cc2[0]); - dbgprintf("Got zero |%02x| |%02x| %d\n", cc1[0], cc2[0], ret[0]); - ret[1] = (cc1[1] == cc2[1]); - dbgprintf("Got one |%02x| |%02x| %d\n", cc1[1], cc2[1], ret[1]); - ret[2] = (cc1[2] == cc2[2]); - dbgprintf("Got two |%02x| |%02x| %d\n", cc1[2], cc2[2], ret[2]); - ret[3] = (cc1[3] == cc2[3]); - dbgprintf("Got three |%02x| |%02x| %d\n", cc1[3], cc2[3], ret[3]); - int retval; - if(ret[0] && ret[1] && ret[2] && ret[3]) - retval = 1; - else - retval = 0; - dbgprintf("Got retval %d\n", retval); - return retval; + dbgprintf("FourCCs\n"); + int ret[4]; + dbgprintf("Let's go %08x %08x\n", cc1, cc2); + ret[0] = (cc1[0] == cc2[0]); + dbgprintf("Got zero |%02x| |%02x| %d\n", cc1[0], cc2[0], ret[0]); + ret[1] = (cc1[1] == cc2[1]); + dbgprintf("Got one |%02x| |%02x| %d\n", cc1[1], cc2[1], ret[1]); + ret[2] = (cc1[2] == cc2[2]); + dbgprintf("Got two |%02x| |%02x| %d\n", cc1[2], cc2[2], ret[2]); + ret[3] = (cc1[3] == cc2[3]); + dbgprintf("Got three |%02x| |%02x| %d\n", cc1[3], cc2[3], ret[3]); + int retval; + if(ret[0] && ret[1] && ret[2] && ret[3]) + retval = 1; + else + retval = 0; + dbgprintf("Got retval %d\n", retval); + return retval; } static void BRLYT_ReadDataFromMemoryX(void* destination, void* input, size_t size) { - u8* out = (u8*)destination; - u8* in = ((u8*)input) + BRLYT_fileoffset; - memcpy(out, in, size); + u8* out = (u8*)destination; + u8* in = ((u8*)input) + BRLYT_fileoffset; + memcpy(out, in, size); } static void BRLYT_ReadDataFromMemory(void* destination, void* input, size_t size) { - BRLYT_ReadDataFromMemoryX(destination, input, size); - BRLYT_fileoffset += size; + BRLYT_ReadDataFromMemoryX(destination, input, size); + BRLYT_fileoffset += size; } float float_swap_bytes(float float1) { - unsigned char *float1c; float1c = (unsigned char*)&float1; + unsigned char *float1c; float1c = (unsigned char*)&float1; unsigned char charTemp = 0x00; - charTemp = float1c[0]; float1c[0] = float1c[3]; float1c[3] = charTemp; - charTemp = 0x00; - charTemp = float1c[1]; float1c[1] = float1c[2]; float1c[2] = charTemp; + charTemp = float1c[0]; float1c[0] = float1c[3]; float1c[3] = charTemp; + charTemp = 0x00; + charTemp = float1c[1]; float1c[1] = float1c[2]; float1c[2] = charTemp; - float *newFloat; newFloat = (float*)float1c; - return *newFloat; + float *newFloat; newFloat = (float*)float1c; + return *newFloat; } /* u16 short_swap_bytes(u16 short1) { - unsigned char* short1c; short1c = (unsigned char*)&short1; - unsigned char charTemp = 0x00; - charTemp = short1c[0]; short1c[0] = short1c[1]; short1c[1] = charTemp; + unsigned char* short1c; short1c = (unsigned char*)&short1; + unsigned char charTemp = 0x00; + charTemp = short1c[0]; short1c[0] = short1c[1]; short1c[1] = charTemp; - unsigned short *newShort; newShort = (unsigned short*)short1c; - return *newShort; + unsigned short *newShort; newShort = (unsigned short*)short1c; + return *newShort; } */ unsigned int bit_extract(unsigned int num, unsigned int start, unsigned int end) { - if (end == 100) end = start; - //simple bitmask, figure out when awake - //unsigned int mask = (2**(31 - start + 1) - 1) - (2**(31 - end) - 1) - unsigned int mask; - int first = 0; - int firstMask = 1; - for (first;first<31-start+1;first++) - { - firstMask *= 2; - } - firstMask -= 1; - first = 0; - int secondMask = 1; - - for (first;first< 31-end;first++) - { - secondMask *=2; - } - secondMask -= 1; - mask = firstMask - secondMask; - int ret = (num & mask) >> (31 - end); - return ret; + if (end == 100) end = start; + //simple bitmask, figure out when awake + //unsigned int mask = (2**(31 - start + 1) - 1) - (2**(31 - end) - 1) + unsigned int mask; + int first = 0; + int firstMask = 1; + for (first;first<31-start+1;first++) + { + firstMask *= 2; + } + firstMask -= 1; + first = 0; + int secondMask = 1; + + for (first;first< 31-end;first++) + { + secondMask *=2; + } + secondMask -= 1; + mask = firstMask - secondMask; + int ret = (num & mask) >> (31 - end); + return ret; } char* getMaterial(u16 offset) { - if (offset == 0) return materials; - char *mat = materials + strlen(materials) + 1; + if (offset == 0) return materials; + char *mat = materials + strlen(materials) + 1; - if (offset > 1) - { - int n = 1; - for (n; n 1) + { + int n = 1; + for (n; n\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); - printf(" %08x\n", data.a); - printf(" \n"); - printf(" %f\n", float_swap_bytes(data.width)); - printf(" %f\n", float_swap_bytes(data.height)); - printf(" \n"); - printf(" \n"); + printf("type=\"%c%c%c%c\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); + printf(" %08x\n", data.a); + printf(" \n"); + printf(" %f\n", float_swap_bytes(data.width)); + printf(" %f\n", float_swap_bytes(data.height)); + printf(" \n"); + printf(" \n"); #endif //OLD_BRLYT_OUTSTYLE } void PrintBRLYTEntry_grp1(brlyt_entry entry, u8* brlyt_file) { - brlyt_group_chunk data; - BRLYT_fileoffset = entry.data_location; - BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_group_chunk)); + brlyt_group_chunk data; + BRLYT_fileoffset = entry.data_location; + BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_group_chunk)); #ifdef OLD_BRLYT_OUTSTYLE - printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); - printf(" Name: %s\n", data.name); - printf(" Number of subs: %08x\n", be16(data.numsubs)); - printf(" unk: %08x\n", be16(data.unk)); + printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); + printf(" Name: %s\n", data.name); + printf(" Number of subs: %08x\n", be16(data.numsubs)); + printf(" unk: %08x\n", be16(data.unk)); #else - printf("type=\"%c%c%c%c\" name=\"%s\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3], data.name); - printf(" \n"); + printf("type=\"%c%c%c%c\" name=\"%s\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3], data.name); + printf(" \n"); #endif //OLD_BRLYT_OUTSTYLE - int offset; - offset = 20; - int n = 0; - for (n;n%s\n", sub); + printf(" %s\n", sub); #endif //OLD_BRLYT_OUTSTYLE - offset += 16; - } + offset += 16; + } #ifndef OLD_BRLYT_OUTSTYLE - printf(" \n"); - printf(" \n"); + printf(" \n"); + printf(" \n"); #endif //OLD_BRLYT_OUTSTYLE } void PrintBRLYTEntry_txl1(brlyt_entry entry, u8* brlyt_file) { - brlyt_numoffs_chunk data; - BRLYT_fileoffset = entry.data_location; - BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_numoffs_chunk)); + brlyt_numoffs_chunk data; + BRLYT_fileoffset = entry.data_location; + BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_numoffs_chunk)); #ifdef OLD_BRLYT_OUTSTYLE - printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); - printf(" num: %08x\n", be16(data.num)); - printf(" offs: %08x\n", be16(data.offs)); + printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); + printf(" num: %08x\n", be16(data.num)); + printf(" offs: %08x\n", be16(data.offs)); #else - printf("type=\"%c%c%c%c\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); - printf(" \n"); + printf("type=\"%c%c%c%c\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); + printf(" \n"); #endif //OLD_BRLYT_OUTSTYLE - int pos = 4; - pos += data.offs; - int bpos = pos; - int n = 0; - for (n;n%s\n", name); + printf(" %s\n", name); #endif //OLD_BRLYT_OUTSTYLE BRLYT_fileoffset = tempLocation; - int oldsize = sizeof(name); - dbgprintf("size of textures before: %08x\n", sizeof(textures)); - int newSize = lengthOfTextures+sizeof(name); - textures = realloc(textures, newSize); - numberOfTextures += 1; - memcpy(textures+lengthOfTextures, name, sizeof(name)); - dbgprintf("tex: %s\tnamsize: %08x\ttexsize: %08x\tnewsize: %08x\n", textures+lengthOfMaterials, sizeof(name), lengthOfTextures, newSize); - lengthOfTextures = newSize; - } + int oldsize = sizeof(name); + dbgprintf("size of textures before: %08x\n", sizeof(textures)); + int newSize = lengthOfTextures+sizeof(name); + textures = realloc(textures, newSize); + numberOfTextures += 1; + memcpy(textures+lengthOfTextures, name, sizeof(name)); + dbgprintf("tex: %s\tnamsize: %08x\ttexsize: %08x\tnewsize: %08x\n", textures+lengthOfMaterials, sizeof(name), lengthOfTextures, newSize); + lengthOfTextures = newSize; + } #ifndef OLD_BRLYT_OUTSTYLE - printf(" \n"); - printf(" \n"); + printf(" \n"); + printf(" \n"); #endif //OLD_BRLYT_OUTSTYLE } @@ -359,18 +359,18 @@ void PrintBRLYTEntry_fnl1(brlyt_entry entry, u8* brlyt_file) BRLYT_fileoffset = entry.data_location; BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_numoffs_chunk)); #ifdef OLD_BRLYT_OUTSTYLE - printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); + printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); printf(" num: %08x\n", be16(data.num)); printf(" offs: %08x\n", be16(data.offs)); #else - printf("type=\"%c%c%c%c\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); - printf(" \n"); + printf("type=\"%c%c%c%c\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); + printf(" \n"); #endif //OLD_BRLYT_OUTSTYLE int pos = 4; pos += data.offs; int bpos = pos; int n = 0; - for (n;n%s\n", name); + printf(" %s\n", name); #endif //OLD_BRLYT_OUTSTYLE BRLYT_fileoffset = tempLocation; } #ifndef OLD_BRLYT_OUTSTYLE - printf(" \n"); - printf(" \n"); + printf(" \n"); + printf(" \n"); #endif //OLD_BRLYT_OUTSTYLE } void PrintBRLYTEntry_pan1(brlyt_entry entry, u8* brlyt_file) { - brlyt_pane_chunk data; - BRLYT_fileoffset = entry.data_location; - BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_pane_chunk)); + brlyt_pane_chunk data; + BRLYT_fileoffset = entry.data_location; + BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_pane_chunk)); #ifdef OLD_BRLYT_OUTSTYLE printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); printf(" flag1: %08x\n", data.flag1); @@ -426,28 +426,28 @@ void PrintBRLYTEntry_pan1(brlyt_entry entry, u8* brlyt_file) printf(" width: %f\n", float_swap_bytes(data.width)); printf(" height: %f\n", float_swap_bytes(data.height)); #else - printf("type=\"%c%c%c%c\" name=\"%s\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3], data.name); - printf(" %08x-%08x\n", data.flag1, data.flag2); - printf(" %08x-%08x\n", data.alpha, data.alpha2); - printf(" \n"); - printf(" %.16f\n", float_swap_bytes(data.x)); - printf(" %.16f\n", float_swap_bytes(data.y)); - printf(" %.16f\n", float_swap_bytes(data.z)); - printf(" \n"); - printf(" \n"); - printf(" %f\n", float_swap_bytes(data.flip_x)); - printf(" %f\n", float_swap_bytes(data.flip_y)); - printf(" \n"); - printf(" %f\n", float_swap_bytes(data.angle)); - printf(" \n"); - printf(" %.10f\n", float_swap_bytes(data.xmag)); - printf(" %.10f\n", float_swap_bytes(data.ymag)); - printf(" \n"); - printf(" \n"); - printf(" %f\n", float_swap_bytes(data.width)); - printf(" %f\n", float_swap_bytes(data.height)); - printf(" \n"); - printf(" \n"); + printf("type=\"%c%c%c%c\" name=\"%s\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3], data.name); + printf(" %08x-%08x\n", data.flag1, data.flag2); + printf(" %08x-%08x\n", data.alpha, data.alpha2); + printf(" \n"); + printf(" %.16f\n", float_swap_bytes(data.x)); + printf(" %.16f\n", float_swap_bytes(data.y)); + printf(" %.16f\n", float_swap_bytes(data.z)); + printf(" \n"); + printf(" \n"); + printf(" %f\n", float_swap_bytes(data.flip_x)); + printf(" %f\n", float_swap_bytes(data.flip_y)); + printf(" \n"); + printf(" %f\n", float_swap_bytes(data.angle)); + printf(" \n"); + printf(" %.10f\n", float_swap_bytes(data.xmag)); + printf(" %.10f\n", float_swap_bytes(data.ymag)); + printf(" \n"); + printf(" \n"); + printf(" %f\n", float_swap_bytes(data.width)); + printf(" %f\n", float_swap_bytes(data.height)); + printf(" \n"); + printf(" \n"); #endif //OLD_BRLYT_OUTSTYLE } @@ -474,36 +474,36 @@ void PrintBRLYTEntry_wnd1(brlyt_entry entry, u8* brlyt_file) printf(" width: %f\n", float_swap_bytes(data.width)); printf(" height: %f\n", float_swap_bytes(data.height)); #else - printf("type=\"%c%c%c%c\" name=\"%s\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3], data.name); - printf(" %08x-%08x\n", data.flag1, data.flag2); - printf(" %08x-%08x\n", data.alpha, data.alpha2); - printf(" \n"); - printf(" %f\n", float_swap_bytes(data.x)); - printf(" %f\n", float_swap_bytes(data.y)); - printf(" %f\n", float_swap_bytes(data.z)); - printf(" \n"); - printf(" \n"); - printf(" %f\n", float_swap_bytes(data.flip_x)); - printf(" %f\n", float_swap_bytes(data.flip_y)); - printf(" \n"); - printf(" %f\n", float_swap_bytes(data.angle)); - printf(" \n"); - printf(" %.10f\n", float_swap_bytes(data.xmag)); - printf(" %.10f\n", float_swap_bytes(data.ymag)); - printf(" \n"); - printf(" \n"); - printf(" %f\n", float_swap_bytes(data.width)); - printf(" %f\n", float_swap_bytes(data.height)); - printf(" \n"); - printf(" \n"); + printf("type=\"%c%c%c%c\" name=\"%s\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3], data.name); + printf(" %08x-%08x\n", data.flag1, data.flag2); + printf(" %08x-%08x\n", data.alpha, data.alpha2); + printf(" \n"); + printf(" %f\n", float_swap_bytes(data.x)); + printf(" %f\n", float_swap_bytes(data.y)); + printf(" %f\n", float_swap_bytes(data.z)); + printf(" \n"); + printf(" \n"); + printf(" %f\n", float_swap_bytes(data.flip_x)); + printf(" %f\n", float_swap_bytes(data.flip_y)); + printf(" \n"); + printf(" %f\n", float_swap_bytes(data.angle)); + printf(" \n"); + printf(" %.10f\n", float_swap_bytes(data.xmag)); + printf(" %.10f\n", float_swap_bytes(data.ymag)); + printf(" \n"); + printf(" \n"); + printf(" %f\n", float_swap_bytes(data.width)); + printf(" %f\n", float_swap_bytes(data.height)); + printf(" \n"); + printf(" \n"); #endif //OLD_BRLYT_OUTSTYLE } void PrintBRLYTEntry_bnd1(brlyt_entry entry, u8* brlyt_file) { - dbgprintf("entry length: %08x\n", be32(entry.length)); - int w; - for (w=0;w\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3], data.name); - printf(" %08x-%08x\n", data.flag1, data.flag2); - printf(" %08x-%08x\n", data.alpha, data.alpha2); - printf(" \n"); - printf(" %.16f\n", float_swap_bytes(data.x)); - printf(" %.16f\n", float_swap_bytes(data.y)); - printf(" %.16f\n", float_swap_bytes(data.z)); - printf(" \n"); - printf(" \n"); - printf(" %f\n", float_swap_bytes(data.flip_x)); - printf(" %f\n", float_swap_bytes(data.flip_y)); - printf(" \n"); - printf(" %f\n", float_swap_bytes(data.angle)); - printf(" \n"); - printf(" %.10f\n", float_swap_bytes(data.xmag)); - printf(" %.10f\n", float_swap_bytes(data.ymag)); - printf(" \n"); - printf(" \n"); - printf(" %f\n", float_swap_bytes(data.width)); - printf(" %f\n", float_swap_bytes(data.height)); - printf(" \n"); - printf(" \n"); + printf("type=\"%c%c%c%c\" name=\"%s\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3], data.name); + printf(" %08x-%08x\n", data.flag1, data.flag2); + printf(" %08x-%08x\n", data.alpha, data.alpha2); + printf(" \n"); + printf(" %.16f\n", float_swap_bytes(data.x)); + printf(" %.16f\n", float_swap_bytes(data.y)); + printf(" %.16f\n", float_swap_bytes(data.z)); + printf(" \n"); + printf(" \n"); + printf(" %f\n", float_swap_bytes(data.flip_x)); + printf(" %f\n", float_swap_bytes(data.flip_y)); + printf(" \n"); + printf(" %f\n", float_swap_bytes(data.angle)); + printf(" \n"); + printf(" %.10f\n", float_swap_bytes(data.xmag)); + printf(" %.10f\n", float_swap_bytes(data.ymag)); + printf(" \n"); + printf(" \n"); + printf(" %f\n", float_swap_bytes(data.width)); + printf(" %f\n", float_swap_bytes(data.height)); + printf(" \n"); + printf(" \n"); #endif //OLD_BRLYT_OUTSTYLE } @@ -556,81 +556,81 @@ void PrintBRLYTEntry_pic1(brlyt_entry entry, u8* brlyt_file) brlyt_pane_chunk data; BRLYT_fileoffset = entry.data_location; BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_pane_chunk)); - brlyt_pic_chunk data2; - BRLYT_ReadDataFromMemory(&data2, brlyt_file, sizeof(brlyt_pic_chunk)); + brlyt_pic_chunk data2; + BRLYT_ReadDataFromMemory(&data2, brlyt_file, sizeof(brlyt_pic_chunk)); #ifdef OLD_BRLYT_OUTSTYLE printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); printf(" flag1: %08x\n", data.flag1); - printf(" flag2: %08x\n", data.flag2); - printf(" alpha: %08x\n", data.alpha); - printf(" alpha2: %08x\n", data.alpha2); - printf(" name: %s\n", data.name); - printf(" x: %f\n", float_swap_bytes(data.x)); - printf(" y: %f\n", float_swap_bytes(data.y)); - printf(" z: %f\n", float_swap_bytes(data.z)); - printf(" flip_x: %f\n", float_swap_bytes(data.flip_x)); - printf(" flip_y: %f\n", float_swap_bytes(data.flip_y)); - printf(" angle: %f\n", float_swap_bytes(data.angle)); - printf(" xmag: %f\n", float_swap_bytes(data.xmag)); - printf(" ymag: %f\n", float_swap_bytes(data.ymag)); - printf(" width: %f\n", float_swap_bytes(data.width)); - printf(" height: %f\n", float_swap_bytes(data.height)); + printf(" flag2: %08x\n", data.flag2); + printf(" alpha: %08x\n", data.alpha); + printf(" alpha2: %08x\n", data.alpha2); + printf(" name: %s\n", data.name); + printf(" x: %f\n", float_swap_bytes(data.x)); + printf(" y: %f\n", float_swap_bytes(data.y)); + printf(" z: %f\n", float_swap_bytes(data.z)); + printf(" flip_x: %f\n", float_swap_bytes(data.flip_x)); + printf(" flip_y: %f\n", float_swap_bytes(data.flip_y)); + printf(" angle: %f\n", float_swap_bytes(data.angle)); + printf(" xmag: %f\n", float_swap_bytes(data.xmag)); + printf(" ymag: %f\n", float_swap_bytes(data.ymag)); + printf(" width: %f\n", float_swap_bytes(data.width)); + printf(" height: %f\n", float_swap_bytes(data.height)); #else - printf("type=\"%c%c%c%c\" name=\"%s\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3], data.name); - printf(" %08x-%08x\n", data.flag1, data.flag2); - printf(" %08x-%08x\n", data.alpha, data.alpha2); - printf(" \n"); - printf(" %.20f\n", float_swap_bytes(data.x)); - printf(" %.20f\n", float_swap_bytes(data.y)); - printf(" %.20f\n", float_swap_bytes(data.z)); - printf(" \n"); - printf(" \n"); - printf(" %f\n", float_swap_bytes(data.flip_x)); - printf(" %f\n", float_swap_bytes(data.flip_y)); - printf(" \n"); - printf(" %f\n", float_swap_bytes(data.angle)); - printf(" \n"); - printf(" %.10f\n", float_swap_bytes(data.xmag)); - printf(" %.10f\n", float_swap_bytes(data.ymag)); - printf(" \n"); - printf(" \n"); - printf(" %f\n", float_swap_bytes(data.width)); - printf(" %f\n", float_swap_bytes(data.height)); - printf(" \n"); + printf("type=\"%c%c%c%c\" name=\"%s\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3], data.name); + printf(" %08x-%08x\n", data.flag1, data.flag2); + printf(" %08x-%08x\n", data.alpha, data.alpha2); + printf(" \n"); + printf(" %.20f\n", float_swap_bytes(data.x)); + printf(" %.20f\n", float_swap_bytes(data.y)); + printf(" %.20f\n", float_swap_bytes(data.z)); + printf(" \n"); + printf(" \n"); + printf(" %f\n", float_swap_bytes(data.flip_x)); + printf(" %f\n", float_swap_bytes(data.flip_y)); + printf(" \n"); + printf(" %f\n", float_swap_bytes(data.angle)); + printf(" \n"); + printf(" %.10f\n", float_swap_bytes(data.xmag)); + printf(" %.10f\n", float_swap_bytes(data.ymag)); + printf(" \n"); + printf(" \n"); + printf(" %f\n", float_swap_bytes(data.width)); + printf(" %f\n", float_swap_bytes(data.height)); + printf(" \n"); #endif //OLD_BRLYT_OUTSTYLE #ifdef OLD_BRLYT_OUTSTYLE - printf(" vtx_colors: %u,%u,%u,%u\n", be32(data2.vtx_colors[0]), be32(data2.vtx_colors[1]), be32(data2.vtx_colors[2]), be32(data2.vtx_colors[3])); - printf(" mat_off: %08x\n", short_swap_bytes(data2.mat_off)); - printf(" num_texcoords: %08x\n", data2.num_texcoords); - printf(" padding: %08x\n", data2.padding); + printf(" vtx_colors: %u,%u,%u,%u\n", be32(data2.vtx_colors[0]), be32(data2.vtx_colors[1]), be32(data2.vtx_colors[2]), be32(data2.vtx_colors[3])); + printf(" mat_off: %08x\n", short_swap_bytes(data2.mat_off)); + printf(" num_texcoords: %08x\n", data2.num_texcoords); + printf(" padding: %08x\n", data2.padding); #else - printf(" \n", getMaterial(short_swap_bytes(data2.mat_off))); - printf(" \n"); - printf(" 0x%08X\n", be32(data2.vtx_colors[0])); - printf(" 0x%08X\n", be32(data2.vtx_colors[1])); - printf(" 0x%08X\n", be32(data2.vtx_colors[2])); - printf(" 0x%08X\n", be32(data2.vtx_colors[3])); - printf(" \n"); - printf(" \n"); + printf(" \n", getMaterial(short_swap_bytes(data2.mat_off))); + printf(" \n"); + printf(" 0x%08X\n", be32(data2.vtx_colors[0])); + printf(" 0x%08X\n", be32(data2.vtx_colors[1])); + printf(" 0x%08X\n", be32(data2.vtx_colors[2])); + printf(" 0x%08X\n", be32(data2.vtx_colors[3])); + printf(" \n"); + printf(" \n"); #endif //OLD_BRLYT_OUTSTYLE - int n = 0; - for (n;n\n"); - for(i = 0; i < 8; i++) - printf(" %f\n", float_swap_bytes(texcoords[i])); - printf(" \n"); + int i; + printf(" \n"); + for(i = 0; i < 8; i++) + printf(" %f\n", float_swap_bytes(texcoords[i])); + printf(" \n"); #endif //OLD_BRLYT_OUTSTYLE - } + } #ifndef OLD_BRLYT_OUTSTYLE - printf(" \n"); - printf(" \n"); + printf(" \n"); + printf(" \n"); #endif //OLD_BRLYT_OUTSTYLE } @@ -657,159 +657,159 @@ void PrintBRLYTEntry_txt1(brlyt_entry entry, u8* brlyt_file) printf(" width: %f\n", float_swap_bytes(data.width)); printf(" height: %f\n", float_swap_bytes(data.height)); #else - printf("type=\"%c%c%c%c\" name=\"%s\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3], data.name); - printf(" %08x-%08x\n", data.flag1, data.flag2); - printf(" %08x-%08x\n", data.alpha, data.alpha2); - printf(" \n"); - printf(" %.16f\n", float_swap_bytes(data.x)); - printf(" %.16f\n", float_swap_bytes(data.y)); - printf(" %.16f\n", float_swap_bytes(data.z)); - printf(" \n"); - printf(" \n"); - printf(" %f\n", float_swap_bytes(data.flip_x)); - printf(" %f\n", float_swap_bytes(data.flip_y)); - printf(" \n"); - printf(" %f\n", float_swap_bytes(data.angle)); - printf(" \n"); - printf(" %.10f\n", float_swap_bytes(data.xmag)); - printf(" %.10f\n", float_swap_bytes(data.ymag)); - printf(" \n"); - printf(" \n"); - printf(" %f\n", float_swap_bytes(data.width)); - printf(" %f\n", float_swap_bytes(data.height)); - printf(" \n"); -// for (i;i\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3], data.name); + printf(" %08x-%08x\n", data.flag1, data.flag2); + printf(" %08x-%08x\n", data.alpha, data.alpha2); + printf(" \n"); + printf(" %.16f\n", float_swap_bytes(data.x)); + printf(" %.16f\n", float_swap_bytes(data.y)); + printf(" %.16f\n", float_swap_bytes(data.z)); + printf(" \n"); + printf(" \n"); + printf(" %f\n", float_swap_bytes(data.flip_x)); + printf(" %f\n", float_swap_bytes(data.flip_y)); + printf(" \n"); + printf(" %f\n", float_swap_bytes(data.angle)); + printf(" \n"); + printf(" %.10f\n", float_swap_bytes(data.xmag)); + printf(" %.10f\n", float_swap_bytes(data.ymag)); + printf(" \n"); + printf(" \n"); + printf(" %f\n", float_swap_bytes(data.width)); + printf(" %f\n", float_swap_bytes(data.height)); + printf(" \n"); +// for (i;i%04x-%04x\n", short_swap_bytes(data2.len1), short_swap_bytes(data2.len2)); - printf(" \n", short_swap_bytes(data2.font_idx)); - printf(" %f\n", float_swap_bytes(data2.font_size_x)); - printf(" %f\n", float_swap_bytes(data2.font_size_y)); - printf(" %f\n", float_swap_bytes(data2.char_space)); - printf(" %f\n", float_swap_bytes(data2.line_space)); - printf(" %02x\n", data2.unk4); - printf(" \n"); - printf(" %08x-%08x\n", be32(data2.color1), be32(data2.color2)); - printf(" "); - int q; for (q=0;q>\n"); - printf(" \n"); + printf(" %04x-%04x\n", short_swap_bytes(data2.len1), short_swap_bytes(data2.len2)); + printf(" \n", short_swap_bytes(data2.font_idx)); + printf(" %f\n", float_swap_bytes(data2.font_size_x)); + printf(" %f\n", float_swap_bytes(data2.font_size_y)); + printf(" %f\n", float_swap_bytes(data2.char_space)); + printf(" %f\n", float_swap_bytes(data2.line_space)); + printf(" %02x\n", data2.unk4); + printf(" \n"); + printf(" %08x-%08x\n", be32(data2.color1), be32(data2.color2)); + printf(" "); + int q; for (q=0;q>\n"); + printf(" \n"); #endif //OLD_BRLYT_OUTSTYLE -// } +// } } void PrintBRLYTEntry_mat1(brlyt_entry entry, u8* brlyt_file) { - brlyt_numoffs_chunk data; - BRLYT_fileoffset = entry.data_location; - BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_numoffs_chunk)); + brlyt_numoffs_chunk data; + BRLYT_fileoffset = entry.data_location; + BRLYT_ReadDataFromMemory(&data, brlyt_file, sizeof(brlyt_numoffs_chunk)); #ifdef OLD_BRLYT_OUTSTYLE - printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); - printf(" num: %08x\n", be16(data.num)); - printf(" offs: %08x\n", be16(data.offs)); + printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); + printf(" num: %08x\n", be16(data.num)); + printf(" offs: %08x\n", be16(data.offs)); #else - printf("type=\"%c%c%c%c\" count=\"%d\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3], short_swap_bytes(data.num)); + printf("type=\"%c%c%c%c\" count=\"%d\">\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3], short_swap_bytes(data.num)); #endif //OLD_BRLYT_OUTSTYLE - int n = 0; - for (n;n\n", data3.name); - printf(" \n"); - printf(" %#x\n", short_swap_bytes(data3.tev_color[0])); - printf(" %#x\n", short_swap_bytes(data3.tev_color[1])); - printf(" %#x\n", short_swap_bytes(data3.tev_color[2])); - printf(" %#x\n", short_swap_bytes(data3.tev_color[3])); - printf(" %#x\n", short_swap_bytes(data3.unk_color[0])); - printf(" %#x\n", short_swap_bytes(data3.unk_color[1])); - printf(" %#x\n", short_swap_bytes(data3.unk_color[2])); - printf(" %#x\n", short_swap_bytes(data3.unk_color[3])); - printf(" %#x\n", short_swap_bytes(data3.unk_color_2[0])); - printf(" %#x\n", short_swap_bytes(data3.unk_color_2[1])); - printf(" %#x\n", short_swap_bytes(data3.unk_color_2[2])); - printf(" %#x\n", short_swap_bytes(data3.unk_color_2[3])); - printf(" %#x\n", be32(data3.tev_kcolor[0])); - printf(" %#x\n", be32(data3.tev_kcolor[1])); - printf(" %#x\n", be32(data3.tev_kcolor[2])); - printf(" %#x\n", be32(data3.tev_kcolor[3])); - printf(" \n"); - printf(" %08x\n", be32(data3.flags)); + printf(" \n", data3.name); + printf(" \n"); + printf(" %#x\n", short_swap_bytes(data3.tev_color[0])); + printf(" %#x\n", short_swap_bytes(data3.tev_color[1])); + printf(" %#x\n", short_swap_bytes(data3.tev_color[2])); + printf(" %#x\n", short_swap_bytes(data3.tev_color[3])); + printf(" %#x\n", short_swap_bytes(data3.unk_color[0])); + printf(" %#x\n", short_swap_bytes(data3.unk_color[1])); + printf(" %#x\n", short_swap_bytes(data3.unk_color[2])); + printf(" %#x\n", short_swap_bytes(data3.unk_color[3])); + printf(" %#x\n", short_swap_bytes(data3.unk_color_2[0])); + printf(" %#x\n", short_swap_bytes(data3.unk_color_2[1])); + printf(" %#x\n", short_swap_bytes(data3.unk_color_2[2])); + printf(" %#x\n", short_swap_bytes(data3.unk_color_2[3])); + printf(" %#x\n", be32(data3.tev_kcolor[0])); + printf(" %#x\n", be32(data3.tev_kcolor[1])); + printf(" %#x\n", be32(data3.tev_kcolor[2])); + printf(" %#x\n", be32(data3.tev_kcolor[3])); + printf(" \n"); + printf(" %08x\n", be32(data3.flags)); #endif //OLD_BRLYT_OUTSTYLE - int oldsize = 1+strlen(data3.name); - dbgprintf("size of materials before: %08x\n", sizeof(materials)); - int newSize = lengthOfMaterials+strlen(data3.name)+1; - materials = realloc(materials, newSize); - numberOfMaterials += 1; - memcpy(materials+lengthOfMaterials, data3.name, 1+strlen(data3.name)); - dbgprintf("mats: %s\tnamsize: %08x\tmatsize: %08x\tnewsize: %08x\n", materials+lengthOfMaterials, strlen(data3.name), lengthOfMaterials, newSize); - lengthOfMaterials = newSize; - - int n = 0; - for (n;n\n", getTexture(tplOffset)); - printf(" %08x\n", data4.wrap_s); - printf(" %08x\n", data4.wrap_t); - printf(" \n"); + printf(" \n", getTexture(tplOffset)); + printf(" %08x\n", data4.wrap_s); + printf(" %08x\n", data4.wrap_t); + printf(" \n"); #endif //OLD_BRLYT_OUTSTYLE - } + } -// # 0x14 * flags[24-27], followed by +// # 0x14 * flags[24-27], followed by n = 0; for (n;n\n"); - printf(" %f\n", float_swap_bytes(data4.unk[0])); - printf(" %f\n", float_swap_bytes(data4.unk[1])); - printf(" %f\n", float_swap_bytes(data4.unk[2])); - printf(" %f\n", float_swap_bytes(data4.unk[3])); - printf(" %f\n", float_swap_bytes(data4.unk[4])); - printf(" \n"); + printf(" \n"); + printf(" %f\n", float_swap_bytes(data4.unk[0])); + printf(" %f\n", float_swap_bytes(data4.unk[1])); + printf(" %f\n", float_swap_bytes(data4.unk[2])); + printf(" %f\n", float_swap_bytes(data4.unk[3])); + printf(" %f\n", float_swap_bytes(data4.unk[4])); + printf(" \n"); #endif //OLD_BRLYT_OUTSTYLE } - //# 4*flags[20-23], followed by + //# 4*flags[20-23], followed by n = 0; for (n;n\n"); - printf(" %08x\n", data4.unk[0]); - printf(" %08x\n", data4.unk[1]); - printf(" %08x\n", data4.unk[2]); - printf(" %08x\n", data4.unk[3]); - printf(" \n"); + printf(" \n"); + printf(" %08x\n", data4.unk[0]); + printf(" %08x\n", data4.unk[1]); + printf(" %08x\n", data4.unk[2]); + printf(" %08x\n", data4.unk[3]); + printf(" \n"); #endif //OLD_BRLYT_OUTSTYLE } - //# Changing ua3 things - //# 1st --> disappears. - //# 2nd --> no visible effect. - //# 3rd --> disappears. - //# 4th --> no visible effect. + //# Changing ua3 things + //# 1st --> disappears. + //# 2nd --> no visible effect. + //# 3rd --> disappears. + //# 4th --> no visible effect. - //# 4 * flags[6] + //# 4 * flags[6] n = 0; for (n;n\n"); - printf(" %08x\n", data4.unk[0]); - printf(" %08x\n", data4.unk[1]); - printf(" %08x\n", data4.unk[2]); - printf(" %08x\n", data4.unk[3]); - printf(" \n"); + printf(" \n"); + printf(" %08x\n", data4.unk[0]); + printf(" %08x\n", data4.unk[1]); + printf(" %08x\n", data4.unk[2]); + printf(" %08x\n", data4.unk[3]); + printf(" \n"); #endif //OLD_BRLYT_OUTSTYLE } - //# 4 * flags[4] + //# 4 * flags[4] n = 0; for (n;n\n"); - printf(" %08x\n", data4.unk[0]); - printf(" %08x\n", data4.unk[1]); - printf(" %08x\n", data4.unk[2]); - printf(" %08x\n", data4.unk[3]); - printf(" \n"); + printf(" \n"); + printf(" %08x\n", data4.unk[0]); + printf(" %08x\n", data4.unk[1]); + printf(" %08x\n", data4.unk[2]); + printf(" %08x\n", data4.unk[3]); + printf(" \n"); #endif //OLD_BRLYT_OUTSTYLE } - //# 4 * flags[19] + //# 4 * flags[19] n = 0; for (n;n\n"); - printf(" %08x\n", data4.unk[0]); - printf(" %08x\n", data4.unk[1]); - printf(" %08x\n", data4.unk[2]); - printf(" %08x\n", data4.unk[3]); - printf(" \n"); + printf(" \n"); + printf(" %08x\n", data4.unk[0]); + printf(" %08x\n", data4.unk[1]); + printf(" %08x\n", data4.unk[2]); + printf(" %08x\n", data4.unk[3]); + printf(" \n"); #endif //OLD_BRLYT_OUTSTYLE } n = 0; @@ -911,21 +911,21 @@ void PrintBRLYTEntry_mat1(brlyt_entry entry, u8* brlyt_file) BRLYT_ReadDataFromMemory(&data4, brlyt_file, sizeof(brlyt_ua7_chunk)); #ifdef OLD_BRLYT_OUTSTYLE printf(" ua7 a: %08x\n", be32(data4.a)); - printf(" ua7 b: %08x\n", be32(data4.b)); - printf(" ua7 c: %f\n", float_swap_bytes(data4.c)); - printf(" ua7 d: %08x\n", be32(data4.d)); - printf(" ua7 e: %08x\n", be32(data4.e)); + printf(" ua7 b: %08x\n", be32(data4.b)); + printf(" ua7 c: %f\n", float_swap_bytes(data4.c)); + printf(" ua7 d: %08x\n", be32(data4.d)); + printf(" ua7 e: %08x\n", be32(data4.e)); #else - printf(" \n"); - printf(" %08x\n", be32(data4.a)); - printf(" %08x\n", be32(data4.b)); - printf(" %f\n", float_swap_bytes(data4.c)); - printf(" %08x\n", be32(data4.d)); - printf(" %08x\n", be32(data4.e)); - printf(" \n"); + printf(" \n"); + printf(" %08x\n", be32(data4.a)); + printf(" %08x\n", be32(data4.b)); + printf(" %f\n", float_swap_bytes(data4.c)); + printf(" %08x\n", be32(data4.d)); + printf(" %08x\n", be32(data4.e)); + printf(" \n"); #endif //OLD_BRLYT_OUTSTYLE } - //# 4 * flags[14-16] + //# 4 * flags[14-16] n = 0; for (n;n\n"); - printf(" %08x\n", data4.unk[0]); - printf(" %08x\n", data4.unk[1]); - printf(" %08x\n", data4.unk[2]); - printf(" %08x\n", data4.unk[3]); - printf(" \n"); + printf(" \n"); + printf(" %08x\n", data4.unk[0]); + printf(" %08x\n", data4.unk[1]); + printf(" %08x\n", data4.unk[2]); + printf(" %08x\n", data4.unk[3]); + printf(" \n"); #endif //OLD_BRLYT_OUTSTYLE } - //# 0x10 * flags[9-13] + //# 0x10 * flags[9-13] n = 0; for (n;n\n"); - printf(" %08x\n", data4.unk[0]); - printf(" %08x\n", data4.unk[1]); - printf(" %08x\n", data4.unk[2]); - printf(" %08x\n", data4.unk[3]); - printf(" %08x\n", data4.unk[4]); - printf(" %08x\n", data4.unk[5]); - printf(" %08x\n", data4.unk[6]); - printf(" %08x\n", data4.unk[7]); - printf(" %08x\n", data4.unk[8]); - printf(" %08x\n", data4.unk[9]); - printf(" %08x\n", data4.unk[10]); - printf(" %08x\n", data4.unk[11]); - printf(" %08x\n", data4.unk[12]); - printf(" %08x\n", data4.unk[13]); - printf(" %08x\n", data4.unk[14]); - printf(" %08x\n", data4.unk[15]); - printf(" \n"); + printf(" \n"); + printf(" %08x\n", data4.unk[0]); + printf(" %08x\n", data4.unk[1]); + printf(" %08x\n", data4.unk[2]); + printf(" %08x\n", data4.unk[3]); + printf(" %08x\n", data4.unk[4]); + printf(" %08x\n", data4.unk[5]); + printf(" %08x\n", data4.unk[6]); + printf(" %08x\n", data4.unk[7]); + printf(" %08x\n", data4.unk[8]); + printf(" %08x\n", data4.unk[9]); + printf(" %08x\n", data4.unk[10]); + printf(" %08x\n", data4.unk[11]); + printf(" %08x\n", data4.unk[12]); + printf(" %08x\n", data4.unk[13]); + printf(" %08x\n", data4.unk[14]); + printf(" %08x\n", data4.unk[15]); + printf(" \n"); #endif //OLD_BRLYT_OUTSTYLE } - //# 4 * flags[8], these are bytes btw + //# 4 * flags[8], these are bytes btw n = 0; for (n;n\n"); - printf(" %08x\n", data4.unk[0]); - printf(" %08x\n", data4.unk[1]); - printf(" %08x\n", data4.unk[2]); - printf(" %08x\n", data4.unk[3]); - printf(" \n"); + printf(" \n"); + printf(" %08x\n", data4.unk[0]); + printf(" %08x\n", data4.unk[1]); + printf(" %08x\n", data4.unk[2]); + printf(" %08x\n", data4.unk[3]); + printf(" \n"); #endif //OLD_BRLYT_OUTSTYLE } - //# 4 * flags[7] + //# 4 * flags[7] n = 0; for (n;n\n"); - printf(" %08x\n", data4.unk[0]); - printf(" %08x\n", data4.unk[1]); - printf(" %08x\n", data4.unk[2]); - printf(" %08x\n", data4.unk[3]); - printf(" \n"); + printf(" \n"); + printf(" %08x\n", data4.unk[0]); + printf(" %08x\n", data4.unk[1]); + printf(" %08x\n", data4.unk[2]); + printf(" %08x\n", data4.unk[3]); + printf(" \n"); #endif //OLD_BRLYT_OUTSTYLE } #ifndef OLD_BRLYT_OUTSTYLE - printf(" \n"); + printf(" \n"); #endif //OLD_BRLYT_OUTSTYLE - BRLYT_fileoffset = tempDataLocation; - } + BRLYT_fileoffset = tempDataLocation; + } #ifndef OLD_BRLYT_OUTSTYLE - printf(" \n"); + printf(" \n"); #endif //OLD_BRLYT_OUTSTYLE } @@ -1020,7 +1020,7 @@ void PrintBRLYTEntry_gre1(brlyt_entry entry, u8* brlyt_file) #ifdef OLD_BRLYT_OUTSTYLE printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); #else - printf("type=\"%c%c%c%c\" />\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); + printf("type=\"%c%c%c%c\" />\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); #endif //OLD_BRLYT_OUTSTYLE } @@ -1029,7 +1029,7 @@ void PrintBRLYTEntry_grs1(brlyt_entry entry, u8* brlyt_file) #ifdef OLD_BRLYT_OUTSTYLE printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); #else - printf("type=\"%c%c%c%c\" />\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); + printf("type=\"%c%c%c%c\" />\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); #endif //OLD_BRLYT_OUTSTYLE } @@ -1038,7 +1038,7 @@ void PrintBRLYTEntry_pae1(brlyt_entry entry, u8* brlyt_file) #ifdef OLD_BRLYT_OUTSTYLE printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); #else - printf("type=\"%c%c%c%c\" />\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); + printf("type=\"%c%c%c%c\" />\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); #endif //OLD_BRLYT_OUTSTYLE } @@ -1047,54 +1047,54 @@ void PrintBRLYTEntry_pas1(brlyt_entry entry, u8* brlyt_file) #ifdef OLD_BRLYT_OUTSTYLE printf(" Type: %c%c%c%c\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); #else - printf("type=\"%c%c%c%c\" />\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); + printf("type=\"%c%c%c%c\" />\n", entry.magic[0], entry.magic[1], entry.magic[2], entry.magic[3]); #endif //OLD_BRLYT_OUTSTYLE } void PrintBRLYTEntries(brlyt_entry *entries, int entrycnt, u8* brlyt_file) { - dbgprintf("Printing BRLYT Entries"); - int i; - - for(i = 0; i < entrycnt; i++) { + dbgprintf("Printing BRLYT Entries"); + int i; + + for(i = 0; i < entrycnt; i++) { #ifdef OLD_BRLYT_OUTSTYLE - printf("\n Index %d (@%08x):\n", i, entries[i].data_location - 8); + printf("\n Index %d (@%08x):\n", i, entries[i].data_location - 8); #else - printf(" \n"); + printf("/>\n"); #endif //OLD_BRLYT_OUTSTYLE - } - } + } + } } void parse_brlyt(char *filename) { - materials = (char*)malloc(12); - numberOfMaterials = 0; - lengthOfMaterials = 0; - textures = (char*)malloc(12); - numberOfTextures = 0; - lengthOfTextures = 0; - FILE* fp = fopen(filename, "rb"); - if(fp == NULL) { - printf("Error! Couldn't open %s!\n", filename); - exit(1); - } - fseek(fp, 0, SEEK_END); - size_t file_size = ftell(fp); - dbgprintf("Filesize is %d\n", file_size); - u8* brlyt_file = (u8*)malloc(file_size); - dbgprintf("brlyt_file allocated\n"); - fseek(fp, 0, SEEK_SET); - fread(brlyt_file, file_size, 1, fp); - dbgprintf("brlyt_file read to.\n"); - BRLYT_fileoffset = 0; - brlyt_header header; - BRLYT_ReadDataFromMemory(&header, brlyt_file, sizeof(brlyt_header)); - BRLYT_CheckHeaderSanity(header, file_size); - brlyt_entry *entries; - BRLYT_fileoffset = short_swap_bytes(header.lyt_offset); - brlyt_entry_header tempentry; - int i; - dbgprintf("curr %08x max %08x\n", BRLYT_fileoffset, file_size); - for(i = 0; BRLYT_fileoffset < file_size; i++) { - BRLYT_ReadDataFromMemoryX(&tempentry, brlyt_file, sizeof(brlyt_entry_header)); - BRLYT_fileoffset += be32(tempentry.length); - dbgprintf("curr %08x max %08x\n", BRLYT_fileoffset, file_size); - } - int entrycount = i; - entries = (brlyt_entry*)calloc(entrycount, sizeof(brlyt_entry)); - dbgprintf("%08x\n", entries); - if(entries == NULL) { - printf("Couldn't allocate for entries!\n"); - exit(1); - } - BRLYT_fileoffset = short_swap_bytes(header.lyt_offset); - for(i = 0; i < entrycount; i++) { - dbgprintf("&(entries[i]) = %08x\n", &(entries[i])); - BRLYT_ReadDataFromMemoryX(&tempentry, brlyt_file, sizeof(brlyt_entry_header)); - memcpy(entries[i].magic, tempentry.magic, 4); - entries[i].length = tempentry.length; - entries[i].data_location = BRLYT_fileoffset + sizeof(brlyt_entry_header); - BRLYT_fileoffset += be32(tempentry.length); - } - - dbgprintf("%08x\n", entries); + materials = (char*)malloc(12); + numberOfMaterials = 0; + lengthOfMaterials = 0; + textures = (char*)malloc(12); + numberOfTextures = 0; + lengthOfTextures = 0; + FILE* fp = fopen(filename, "rb"); + if(fp == NULL) { + printf("Error! Couldn't open %s!\n", filename); + exit(1); + } + fseek(fp, 0, SEEK_END); + size_t file_size = ftell(fp); + dbgprintf("Filesize is %d\n", file_size); + u8* brlyt_file = (u8*)malloc(file_size); + dbgprintf("brlyt_file allocated\n"); + fseek(fp, 0, SEEK_SET); + fread(brlyt_file, file_size, 1, fp); + dbgprintf("brlyt_file read to.\n"); + BRLYT_fileoffset = 0; + brlyt_header header; + BRLYT_ReadDataFromMemory(&header, brlyt_file, sizeof(brlyt_header)); + BRLYT_CheckHeaderSanity(header, file_size); + brlyt_entry *entries; + BRLYT_fileoffset = short_swap_bytes(header.lyt_offset); + brlyt_entry_header tempentry; + int i; + dbgprintf("curr %08x max %08x\n", BRLYT_fileoffset, file_size); + for(i = 0; BRLYT_fileoffset < file_size; i++) { + BRLYT_ReadDataFromMemoryX(&tempentry, brlyt_file, sizeof(brlyt_entry_header)); + BRLYT_fileoffset += be32(tempentry.length); + dbgprintf("curr %08x max %08x\n", BRLYT_fileoffset, file_size); + } + int entrycount = i; + entries = (brlyt_entry*)calloc(entrycount, sizeof(brlyt_entry)); + dbgprintf("%08x\n", entries); + if(entries == NULL) { + printf("Couldn't allocate for entries!\n"); + exit(1); + } + BRLYT_fileoffset = short_swap_bytes(header.lyt_offset); + for(i = 0; i < entrycount; i++) { + dbgprintf("&(entries[i]) = %08x\n", &(entries[i])); + BRLYT_ReadDataFromMemoryX(&tempentry, brlyt_file, sizeof(brlyt_entry_header)); + memcpy(entries[i].magic, tempentry.magic, 4); + entries[i].length = tempentry.length; + entries[i].data_location = BRLYT_fileoffset + sizeof(brlyt_entry_header); + BRLYT_fileoffset += be32(tempentry.length); + } + + dbgprintf("%08x\n", entries); #ifdef OLD_BRLYT_OUTSTYLE - printf("Parsed BRLYT! Information:\n"); - printf("Main header:\n"); - printf(" Magic: %c%c%c%c\n", header.magic[0], header.magic[1], header.magic[2], header.magic[3]); - printf(" Unk1: %08x\n", be32(header.unk1)); - printf(" Filesize: %lu\n", be32(header.filesize)); - printf(" %s real file size!\n", be32(header.filesize) == file_size ? "Matches" : "Does not match"); - printf(" Offset to lyt1: %04x\n", short_swap_bytes(header.lyt_offset)); - printf(" Unk2: %04x\n", short_swap_bytes(header.unk2)); - printf("\nBRLYT Entries:"); + printf("Parsed BRLYT! Information:\n"); + printf("Main header:\n"); + printf(" Magic: %c%c%c%c\n", header.magic[0], header.magic[1], header.magic[2], header.magic[3]); + printf(" Unk1: %08x\n", be32(header.unk1)); + printf(" Filesize: %lu\n", be32(header.filesize)); + printf(" %s real file size!\n", be32(header.filesize) == file_size ? "Matches" : "Does not match"); + printf(" Offset to lyt1: %04x\n", short_swap_bytes(header.lyt_offset)); + printf(" Unk2: %04x\n", short_swap_bytes(header.unk2)); + printf("\nBRLYT Entries:"); #else - printf("\n" \ - "\n"); + printf("\n" \ + "\n"); #endif //OLD_BRLYT_OUTSTYLE - PrintBRLYTEntries(entries, entrycount, brlyt_file); + PrintBRLYTEntries(entries, entrycount, brlyt_file); #ifndef OLD_BRLYT_OUTSTYLE - printf("\n"); + printf("\n"); #endif //OLD_BRLYT_OUTSTYLE - free(materials); - free(textures); + free(materials); + free(textures); } @@ -1195,118 +1195,118 @@ void parse_brlyt(char *filename) u32 create_entries_from_xml(mxml_node_t *tree, mxml_node_t *node, brlan_entry *entr, tag_header* head, u8** tagblob, u32* blobsize) { - tag_entry* entry = NULL; - tag_entryinfo* entryinfo = NULL; - tag_data** data = NULL; - mxml_node_t *tempnode = NULL; - mxml_node_t *subnode = NULL; - mxml_node_t *subsubnode = NULL; - char temp[256]; - char temp2[256]; - char temp3[15][24]; - int i, x; - - for(i = 0; i < 16; i++) - memset(temp3[i], 0, 24); - for(x = 0; x < 16; x++) - for(i = 0; i < strlen(tag_types_list[x]); i++) - temp3[x][i] = toupper(tag_types_list[x][i]); - head->entry_count = 0; - subnode = node; - for (x = 0, subnode = mxmlFindElement(subnode, node, "entry", NULL, NULL, MXML_DESCEND); subnode != NULL; subnode = mxmlFindElement(subnode, node, "entry", NULL, NULL, MXML_DESCEND), x++) { - head->entry_count++; - entry = realloc(entry, sizeof(tag_entry) * head->entry_count); - entryinfo = realloc(entryinfo, sizeof(tag_entryinfo) * head->entry_count); - if(data == NULL) - data = (tag_data**)malloc(sizeof(tag_data*) * head->entry_count); - else - data = (tag_data**)realloc(data, sizeof(tag_data*) * head->entry_count); - data[x] = NULL; - memset(temp, 0, 256); - memset(temp2, 0, 256); - if(mxmlElementGetAttr(subnode, "type") != NULL) - strcpy(temp, mxmlElementGetAttr(subnode, "type")); - else{ - printf("No type attribute found!\nSkipping this entry!\n"); - head->entry_count--; - continue; - } - for(i = 0; i < strlen(temp); i++) - temp2[i] = toupper(temp[i]); - for(i = 0; (i < 16) && (strcmp(temp3[i - 1], temp2) != 0); i++); - if(i == 16) - i = atoi(temp2); - else - i--; - entry[x].offset = 0; - entryinfo[x].type = i; - entryinfo[x].unk1 = 0x0200; - entryinfo[x].pad1 = 0x0000; - entryinfo[x].unk2 = 0x0000000C; - entryinfo[x].coord_count = 0; - subsubnode = subnode; - for (i = 0, subsubnode = mxmlFindElement(subsubnode, subnode, "triplet", NULL, NULL, MXML_DESCEND); subsubnode != NULL; subsubnode = mxmlFindElement(subsubnode, subnode, "triplet", NULL, NULL, MXML_DESCEND), i++) { - entryinfo[x].coord_count++; - data[x] = realloc(data[x], sizeof(tag_data) * entryinfo[x].coord_count); - tempnode = mxmlFindElement(subsubnode, subsubnode, "frame", NULL, NULL, MXML_DESCEND); - if(tempnode == NULL) { - printf("Couldn't find attribute \"frame\"!\n"); - exit(1); - } - get_value(tempnode, temp, 256); - *(f32*)(&(data[x][i].part1)) = atof(temp); - tempnode = mxmlFindElement(subsubnode, subsubnode, "value", NULL, NULL, MXML_DESCEND); - if(tempnode == NULL) { - printf("Couldn't find attribute \"value\"!\n"); - exit(1); - } - get_value(tempnode, temp, 256); - *(f32*)(&(data[x][i].part2)) = atof(temp); - tempnode = mxmlFindElement(subsubnode, subsubnode, "blend", NULL, NULL, MXML_DESCEND); - if(tempnode == NULL) { - printf("Couldn't find attribute \"blend\"!\n"); - exit(1); - } - get_value(tempnode, temp, 256); - *(f32*)(&(data[x][i].part3)) = atof(temp); - } - } - FILE* fp = fopen("temp.blan", "wb+"); - if(fp == NULL) { - printf("Couldn't open temporary temp.blan file\n"); - exit(1); - } - fseek(fp, 0, SEEK_SET); - entr->anim_header_len = 0; - WriteBRLANEntry(entr, fp); - WriteBRLANTagHeader(head, fp); - u32 entryloc = ftell(fp); - WriteBRLANTagEntries(entry, head->entry_count, fp); - u32* entryinfolocs = (u32*)calloc(head->entry_count, sizeof(u32)); - for(x = 0; x < head->entry_count; x++) { - entryinfolocs[x] = ftell(fp); - entry[x].offset = entryinfolocs[x] - sizeof(brlan_entry); - WriteBRLANTagEntryinfos(entryinfo[x], fp); - WriteBRLANTagData(data[x], entryinfo[x].coord_count, fp); - } - u32 oldpos = ftell(fp); - fseek(fp, entryloc, SEEK_SET); - WriteBRLANTagEntries(entry, head->entry_count, fp); - fseek(fp, oldpos, SEEK_SET); - u32 filesz = ftell(fp); - fseek(fp, 0, SEEK_SET); - entr->anim_header_len = sizeof(tag_header) + (sizeof(tag_entry) * head->entry_count); - WriteBRLANEntry(entr, fp); - *blobsize = filesz; - *tagblob = (u8*)malloc(*blobsize); - fseek(fp, 0, SEEK_SET); - fread(*tagblob, *blobsize, 1, fp); - free(entry); - free(entryinfo); - free(data); - fclose(fp); - remove("temp.blan"); - return filesz; + tag_entry* entry = NULL; + tag_entryinfo* entryinfo = NULL; + tag_data** data = NULL; + mxml_node_t *tempnode = NULL; + mxml_node_t *subnode = NULL; + mxml_node_t *subsubnode = NULL; + char temp[256]; + char temp2[256]; + char temp3[15][24]; + int i, x; + + for(i = 0; i < 16; i++) + memset(temp3[i], 0, 24); + for(x = 0; x < 16; x++) + for(i = 0; i < strlen(tag_types_list[x]); i++) + temp3[x][i] = toupper(tag_types_list[x][i]); + head->entry_count = 0; + subnode = node; + for (x = 0, subnode = mxmlFindElement(subnode, node, "entry", NULL, NULL, MXML_DESCEND); subnode != NULL; subnode = mxmlFindElement(subnode, node, "entry", NULL, NULL, MXML_DESCEND), x++) { + head->entry_count++; + entry = realloc(entry, sizeof(tag_entry) * head->entry_count); + entryinfo = realloc(entryinfo, sizeof(tag_entryinfo) * head->entry_count); + if(data == NULL) + data = (tag_data**)malloc(sizeof(tag_data*) * head->entry_count); + else + data = (tag_data**)realloc(data, sizeof(tag_data*) * head->entry_count); + data[x] = NULL; + memset(temp, 0, 256); + memset(temp2, 0, 256); + if(mxmlElementGetAttr(subnode, "type") != NULL) + strcpy(temp, mxmlElementGetAttr(subnode, "type")); + else{ + printf("No type attribute found!\nSkipping this entry!\n"); + head->entry_count--; + continue; + } + for(i = 0; i < strlen(temp); i++) + temp2[i] = toupper(temp[i]); + for(i = 0; (i < 16) && (strcmp(temp3[i - 1], temp2) != 0); i++); + if(i == 16) + i = atoi(temp2); + else + i--; + entry[x].offset = 0; + entryinfo[x].type = i; + entryinfo[x].unk1 = 0x0200; + entryinfo[x].pad1 = 0x0000; + entryinfo[x].unk2 = 0x0000000C; + entryinfo[x].coord_count = 0; + subsubnode = subnode; + for (i = 0, subsubnode = mxmlFindElement(subsubnode, subnode, "triplet", NULL, NULL, MXML_DESCEND); subsubnode != NULL; subsubnode = mxmlFindElement(subsubnode, subnode, "triplet", NULL, NULL, MXML_DESCEND), i++) { + entryinfo[x].coord_count++; + data[x] = realloc(data[x], sizeof(tag_data) * entryinfo[x].coord_count); + tempnode = mxmlFindElement(subsubnode, subsubnode, "frame", NULL, NULL, MXML_DESCEND); + if(tempnode == NULL) { + printf("Couldn't find attribute \"frame\"!\n"); + exit(1); + } + get_value(tempnode, temp, 256); + *(f32*)(&(data[x][i].part1)) = atof(temp); + tempnode = mxmlFindElement(subsubnode, subsubnode, "value", NULL, NULL, MXML_DESCEND); + if(tempnode == NULL) { + printf("Couldn't find attribute \"value\"!\n"); + exit(1); + } + get_value(tempnode, temp, 256); + *(f32*)(&(data[x][i].part2)) = atof(temp); + tempnode = mxmlFindElement(subsubnode, subsubnode, "blend", NULL, NULL, MXML_DESCEND); + if(tempnode == NULL) { + printf("Couldn't find attribute \"blend\"!\n"); + exit(1); + } + get_value(tempnode, temp, 256); + *(f32*)(&(data[x][i].part3)) = atof(temp); + } + } + FILE* fp = fopen("temp.blan", "wb+"); + if(fp == NULL) { + printf("Couldn't open temporary temp.blan file\n"); + exit(1); + } + fseek(fp, 0, SEEK_SET); + entr->anim_header_len = 0; + WriteBRLANEntry(entr, fp); + WriteBRLANTagHeader(head, fp); + u32 entryloc = ftell(fp); + WriteBRLANTagEntries(entry, head->entry_count, fp); + u32* entryinfolocs = (u32*)calloc(head->entry_count, sizeof(u32)); + for(x = 0; x < head->entry_count; x++) { + entryinfolocs[x] = ftell(fp); + entry[x].offset = entryinfolocs[x] - sizeof(brlan_entry); + WriteBRLANTagEntryinfos(entryinfo[x], fp); + WriteBRLANTagData(data[x], entryinfo[x].coord_count, fp); + } + u32 oldpos = ftell(fp); + fseek(fp, entryloc, SEEK_SET); + WriteBRLANTagEntries(entry, head->entry_count, fp); + fseek(fp, oldpos, SEEK_SET); + u32 filesz = ftell(fp); + fseek(fp, 0, SEEK_SET); + entr->anim_header_len = sizeof(tag_header) + (sizeof(tag_entry) * head->entry_count); + WriteBRLANEntry(entr, fp); + *blobsize = filesz; + *tagblob = (u8*)malloc(*blobsize); + fseek(fp, 0, SEEK_SET); + fread(*tagblob, *blobsize, 1, fp); + free(entry); + free(entryinfo); + free(data); + fclose(fp); + remove("temp.blan"); + return filesz; } */ @@ -1314,1554 +1314,1554 @@ u32 create_entries_from_xml(mxml_node_t *tree, mxml_node_t *node, brlan_entry *e void create_tag_from_xml(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* blobsize) { -// tag_header head; - brlyt_entry entry; - char temp[256]; - memset(entry.name, 0, 20); +// tag_header head; + brlyt_entry entry; + char temp[256]; + memset(entry.name, 0, 20); // if(mxmlElementGetAttr(node, "name") != NULL) // strcpy(entr.name, mxmlElementGetAttr(node, "name")); // else{ // } - if(mxmlElementGetAttr(node, "type") != NULL) - strcpy(temp, mxmlElementGetAttr(node, "type")); - else{ - printf("No type attribute found!\nQuitting!\n"); - exit(1); - } - entry.magic[0] = temp[0]; - entry.magic[1] = temp[1]; - entry.magic[2] = temp[2]; - entry.magic[3] = temp[3]; - entry.length = 0; - entry.data_location = 0; - -// if(mxmlElementGetAttr(node, "format") != NULL) -// strcpy(temp, mxmlElementGetAttr(node, "format")); -// else{ -// printf("No format attribute found!\nQuitting!\n"); -// exit(1); -// } - int x; -// for(x = 0; x < strlen(temp); x++) -// temp[x] = toupper(temp[x]); -// if(strcmp(temp, "NORMAL") == 0) -// entr.flags = 0x01000000; -// else -// entr.flags = atoi(temp); - create_entries_from_xml(tree, node, &entr, &head, tagblob, blobsize); + if(mxmlElementGetAttr(node, "type") != NULL) + strcpy(temp, mxmlElementGetAttr(node, "type")); + else{ + printf("No type attribute found!\nQuitting!\n"); + exit(1); + } + entry.magic[0] = temp[0]; + entry.magic[1] = temp[1]; + entry.magic[2] = temp[2]; + entry.magic[3] = temp[3]; + entry.length = 0; + entry.data_location = 0; + +// if(mxmlElementGetAttr(node, "format") != NULL) +// strcpy(temp, mxmlElementGetAttr(node, "format")); +// else{ +// printf("No format attribute found!\nQuitting!\n"); +// exit(1); +// } + int x; +// for(x = 0; x < strlen(temp); x++) +// temp[x] = toupper(temp[x]); +// if(strcmp(temp, "NORMAL") == 0) +// entr.flags = 0x01000000; +// else +// entr.flags = atoi(temp); + create_entries_from_xml(tree, node, &entr, &head, tagblob, blobsize); } */ void WriteBRLYTEntry(mxml_node_t *tree, mxml_node_t *node, u8** tagblob, u32* blobsize, char temp[4], FILE* fp, unsigned int *fileOffset) { - unsigned int startOfChunk = *fileOffset; - - char lyt1[4] = {'l', 'y', 't', '1'}; // // - char txl1[4] = {'t', 'x', 'l', '1'}; // // - char fnl1[4] = {'f', 'n', 'l', '1'}; // // - char mat1[4] = {'m', 'a', 't', '1'}; - char pan1[4] = {'p', 'a', 'n', '1'}; // // - char wnd1[4] = {'w', 'n', 'd', '1'}; // // - char bnd1[4] = {'b', 'n', 'd', '1'}; // // - char pic1[4] = {'p', 'i', 'c', '1'}; // / - char txt1[4] = {'t', 'x', 't', '1'}; // / - char grp1[4] = {'g', 'r', 'p', '1'}; // // - char grs1[4] = {'g', 'r', 's', '1'}; - char gre1[4] = {'g', 'r', 'e', '1'}; - char pas1[4] = {'p', 'a', 's', '1'}; - char pae1[4] = {'p', 'a', 'e', '1'}; - - if ( memcmp(temp, lyt1, sizeof(lyt1)) == 0) - { - brlyt_lytheader_chunk lytheader; - - mxml_node_t *subnode = mxmlFindElement(node , node , "a", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempChar[4]; - get_value(subnode, tempChar, 256); - lytheader.a = atoi(tempChar); - lytheader.pad[0]=0;lytheader.pad[1]=0;lytheader.pad[2]=0; - } - subnode = mxmlFindElement(node, node, "size", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode = mxmlFindElement(subnode , subnode , "width", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempChar[4]; - get_value(valnode, tempChar, 256); - float something; - *(float*)(&(lytheader.width)) = atof(tempChar); - } - valnode = mxmlFindElement(subnode , subnode ,"height", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempChar[4]; - get_value(valnode, tempChar, 256); - - *(float*)(&(lytheader.height)) = atof(tempChar); - } - } - lytheader.pad[0] = 0; lytheader.pad[1] = 0; lytheader.pad[2] = 0; - lytheader.width = float_swap_bytes(lytheader.width); - lytheader.height = float_swap_bytes(lytheader.height); - fwrite(&lytheader, sizeof(brlyt_header), 1, fp); - *fileOffset = *fileOffset + sizeof(lytheader); - } - if ( memcmp(temp, txl1, sizeof(txl1)) == 0) - { - int numoffsOffset = ftell(fp); - - brlyt_numoffs_chunk chunk; - chunk.num = 0; - chunk.offs = 0; - fwrite(&chunk, sizeof(chunk), 1, fp); - *fileOffset = *fileOffset + sizeof(chunk); - - char *names; - names = malloc(sizeof(names)); - int lengthOfNames = 0; - mxml_node_t *subnode = mxmlFindElement(node, node, "entries", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - int numEntries = 0; - - int oldNameLength; - int baseOffset = 0; - - u32 *offsunks; - - offsunks = malloc(sizeof(u32)); - - brlyt_offsunk_chunk chunk2; - mxml_node_t *valnode; - for(valnode = mxmlFindElement(subnode, subnode, "name", NULL, NULL, MXML_DESCEND); valnode != NULL; valnode = mxmlFindElement(valnode, subnode, "name", NULL, NULL, MXML_DESCEND)) { - - if (valnode != NULL) - { - - char tempSub[256]; - get_value(valnode, tempSub, 256); - - oldNameLength = lengthOfNames; - lengthOfNames += strlen(tempSub); - - offsunks = realloc(offsunks, (numEntries + 1)*(2 * sizeof(u32))); - if (offsunks == NULL) printf("NULLed by a realloc\n"); - - offsunks[(numEntries*2)+0] = baseOffset; - offsunks[(numEntries*2)+1] = 0; - - *fileOffset = *fileOffset + sizeof(chunk2); - numEntries++; - - baseOffset += (strlen(tempSub) + 1); - - names = realloc(names, 1 + sizeof(char) * lengthOfNames); - strcpy(&names[oldNameLength], tempSub); - char nuller = '\0'; - memcpy(&names[lengthOfNames], &nuller, sizeof(char)); - lengthOfNames += 1; - } - } - chunk.num = short_swap_bytes(numEntries); - chunk.offs = 0; - fseek(fp, numoffsOffset, SEEK_SET); - fwrite(&chunk, sizeof(chunk), 1, fp); - - int i; - for(i=0;i 0) - { - u8 toAdd = 4-(*fileOffset % 4); - char nuller[3] = {'\0', '\0', '\0'}; - fwrite(&nuller, sizeof(char), toAdd, fp); - *fileOffset = *fileOffset + toAdd; - } -// materials = malloc(lengthOfNames * sizeof(char)); -// memcpy(materials, names, lengthOfNames * sizeof(char)); -// free(names); - textures = malloc(lengthOfNames * sizeof(char)); - memcpy(textures, names, lengthOfNames * sizeof(char)); - free(names); - } - if ( memcmp(temp, fnl1, sizeof(fnl1)) == 0) - { - brlyt_numoffs_chunk chunk; - chunk.num = 0; - chunk.offs = 0; - fwrite(&chunk, sizeof(chunk), 1, fp); - *fileOffset = *fileOffset + sizeof(chunk); - - char *names; - names = malloc(sizeof(char)); - int lengthOfNames = 0; - mxml_node_t *subnode = mxmlFindElement(node, node, "entries", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - int numEntries = 0; - - int oldNameLength; - int baseOffset = 0; - int numoffsOffset = *fileOffset - 4; - - u32 *offsunks; - offsunks = malloc(sizeof(u32)); - - brlyt_offsunk_chunk chunk2; - mxml_node_t *valnode; - for(valnode = mxmlFindElement(subnode, subnode, "name", NULL, NULL, MXML_DESCEND); valnode != NULL; valnode = mxmlFindElement(valnode, subnode, "name", NULL, NULL, MXML_DESCEND)) { - - if (valnode != NULL) - { - char tempSub[256]; - get_value(valnode, tempSub, 256); - - oldNameLength = lengthOfNames; - lengthOfNames += strlen(tempSub); - - offsunks = realloc(offsunks, (numEntries + 1)*(2 * sizeof(u32))); - offsunks[(numEntries*2)+0] = baseOffset; - offsunks[(numEntries*2)+1] = 0; - - *fileOffset = *fileOffset + sizeof(chunk2); - numEntries++; - - baseOffset += (strlen(tempSub) + 1); - names = realloc(names, 1 + sizeof(char) * lengthOfNames); - memcpy(&names[oldNameLength], tempSub, strlen(tempSub)); - char nuller = '\0'; - memcpy(&names[lengthOfNames], &nuller, sizeof(char)); - lengthOfNames += 1; - } - } - chunk.num = short_swap_bytes(numEntries); - chunk.offs = 0; - fseek(fp, numoffsOffset, SEEK_SET); - fwrite(&chunk, sizeof(chunk), 1, fp); - - int i; - for(i=0;i 0) - { - u8 toAdd = 4-(*fileOffset % 4); - char nuller[3] = {'\0', '\0', '\0'}; - fwrite(&nuller, sizeof(char), toAdd, fp); - *fileOffset = *fileOffset + toAdd; - } - free(names); - } - if ( memcmp(temp, mat1, sizeof(mat1)) == 0) - { - - int numberOfEntries = 0; - int actualNumber = 0; - brlyt_numoffs_chunk numchunk; - brlyt_material_chunk chunk; - mxml_node_t *subnode; - for(subnode=mxmlFindElement(node, node, "entries", NULL, NULL, MXML_DESCEND);subnode!=NULL;subnode=mxmlFindElement(subnode, node, "entries", NULL, NULL, MXML_DESCEND)) - numberOfEntries++; - - numchunk.num = short_swap_bytes(numberOfEntries); - numchunk.offs = 0; - fwrite(&numchunk, sizeof(numchunk), 1, fp); - *fileOffset = *fileOffset + sizeof(numchunk); - - int *offsets = calloc(numberOfEntries, sizeof(int)); - int offsetsOffset = ftell(fp); - int materialOffset = 0; - actualNumber = numberOfEntries; - numberOfEntries = 0; - int matSize = 0; - int initialOffset = sizeof(numchunk) + 8 + (actualNumber * sizeof(int)); - - offsets[numberOfEntries] = be32(matSize + initialOffset); - fwrite(&offsets[0], sizeof(int), actualNumber, fp); - *fileOffset = *fileOffset + (actualNumber * 4); //changed from numberOfEntries - - for(subnode=mxmlFindElement(node,node,"entries",NULL,NULL,MXML_DESCEND);subnode!=NULL;subnode=mxmlFindElement(subnode,node,"entries",NULL,NULL,MXML_DESCEND)) - { - numberOfEntries += 1; - char temp[256]; - if(mxmlElementGetAttr(subnode, "name") != NULL) - strcpy(temp, mxmlElementGetAttr(subnode, "name")); - else{ - printf("No name attribute found!\nQuitting!\n"); - exit(1); - } - char zeroed[24]; - int j; - for (j=0; j<24; j++) - { - zeroed[j] = 0; - } - memcpy(chunk.name, zeroed, 20 * sizeof(char)); - strcpy(chunk.name, temp); - - materials = realloc(materials, lengthOfMaterials + strlen(chunk.name) + 1); - memcpy(&materials[lengthOfMaterials], chunk.name, strlen(chunk.name) + 1); - lengthOfMaterials += (1 + strlen(chunk.name)); - numberOfMaterials += 1; - - mxml_node_t *setnode; - setnode = mxmlFindElement(subnode, subnode, "colors", NULL, NULL, MXML_DESCEND); - if (setnode != NULL) - { - mxml_node_t *valnode; - int colorNumber = 0; - for (valnode=mxmlFindElement(setnode, setnode, "tev", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "tev", NULL, NULL, MXML_DESCEND) ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - - chunk.tev_color[colorNumber] = strtoul(tempCoord, NULL, 16); - - chunk.tev_color[colorNumber] = short_swap_bytes(chunk.tev_color[colorNumber]); - - colorNumber+=1; - } - colorNumber = 0; - for (valnode=mxmlFindElement(setnode, setnode, "unk", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "unk", NULL, NULL, MXML_DESCEND) ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - - chunk.unk_color[colorNumber] = strtoul(tempCoord, NULL, 16); - - chunk.unk_color[colorNumber] = short_swap_bytes(chunk.unk_color[colorNumber]); - - colorNumber+=1; - } - colorNumber = 0; - for (valnode=mxmlFindElement(setnode, setnode, "unk2", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "unk2", NULL, NULL, MXML_DESCEND) ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - - chunk.unk_color_2[colorNumber] = strtoul(tempCoord, NULL, 16); - - chunk.unk_color_2[colorNumber] = short_swap_bytes(chunk.unk_color_2[colorNumber]); - - colorNumber+=1; - } - colorNumber = 0; - for (valnode=mxmlFindElement(setnode, setnode, "tev_k", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "tev_k", NULL, NULL, MXML_DESCEND) ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - - chunk.tev_kcolor[colorNumber] = be32(strtoul(tempCoord, NULL, 16)); - colorNumber+=1; - } - } - setnode = mxmlFindElement(subnode,subnode,"flags",NULL,NULL,MXML_DESCEND); - if (setnode != NULL) - { - char tempCoord[256]; - get_value(setnode, tempCoord, 256); - chunk.flags = be32(strtoul(tempCoord, NULL, 16)); - } - - fwrite(&chunk, sizeof(chunk), 1, fp); - *fileOffset = *fileOffset + sizeof(chunk); - matSize += sizeof(chunk); - - brlyt_texref_chunk chunkTexRef; - setnode = mxmlFindElement(subnode, subnode, "material", NULL, NULL, MXML_DESCEND); - if (setnode != NULL) - { - mxml_node_t *valnode; - char temp[256]; - if(mxmlElementGetAttr(setnode, "name") != NULL) - strcpy(temp, mxmlElementGetAttr(setnode, "name")); - else{ - printf("No name attribute found!\nQuitting!\n"); - exit(1); - } - chunkTexRef.tex_offs = short_swap_bytes(findTexOffset(temp)); - - valnode=mxmlFindElement(setnode, setnode, "wrap_s", NULL, NULL, MXML_DESCEND); - - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunkTexRef.wrap_s = strtoul(tempCoord, NULL, 16); - - valnode=mxmlFindElement(setnode, setnode, "wrap_t", NULL, NULL, MXML_DESCEND); - - get_value(valnode, tempCoord, 256); - chunkTexRef.wrap_t = strtoul(tempCoord, NULL, 16); - - fwrite(&chunkTexRef, sizeof(chunkTexRef), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkTexRef); - matSize += sizeof(chunkTexRef); - } - - brlyt_ua2_chunk chunkUa2; - setnode = mxmlFindElement(subnode, subnode, "ua2", NULL, NULL, MXML_DESCEND); - if (setnode != NULL) - { - mxml_node_t *valnode; - int dataNumber = 0; - for (valnode=mxmlFindElement(setnode, setnode, "data", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "data", NULL, NULL, MXML_DESCEND) ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - - chunkUa2.unk[dataNumber] = float_swap_bytes(atof(tempCoord)); - - dataNumber+=1; - } - fwrite(&chunkUa2, sizeof(chunkUa2), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkUa2); - matSize += sizeof(chunkUa2); - } - brlyt_4b_chunk chunkUa3; - setnode = mxmlFindElement(subnode, subnode, "ua3", NULL, NULL, MXML_DESCEND); - if (setnode != NULL) - { - mxml_node_t *valnode; - int dataNumber = 0; - for (valnode=mxmlFindElement(setnode, setnode, "data", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "data", NULL, NULL, MXML_DESCEND) ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - - chunkUa3.unk[dataNumber] = strtoul(tempCoord, NULL, 16); - - dataNumber+=1; - } - fwrite(&chunkUa3, sizeof(chunkUa3), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkUa3); - matSize += sizeof(chunkUa3); - } - brlyt_4b_chunk chunkUa4; - setnode = mxmlFindElement(subnode, subnode, "ua4", NULL, NULL, MXML_DESCEND); - if (setnode != NULL) - { - mxml_node_t *valnode; - int dataNumber = 0; - for (valnode=mxmlFindElement(setnode, setnode, "data", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "data", NULL, NULL, MXML_DESCEND) ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - - chunkUa4.unk[dataNumber] = strtoul(tempCoord, NULL, 16); - - dataNumber+=1; - } - fwrite(&chunkUa4, sizeof(chunkUa4), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkUa4); - matSize += sizeof(chunkUa4); - } - brlyt_4b_chunk chunkUa5; - setnode = mxmlFindElement(subnode, subnode, "ua5", NULL, NULL, MXML_DESCEND); - if (setnode != NULL) - { - mxml_node_t *valnode; - int dataNumber = 0; - for (valnode=mxmlFindElement(setnode, setnode, "data", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "data", NULL, NULL, MXML_DESCEND) ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - - chunkUa5.unk[dataNumber] = strtoul(tempCoord, NULL, 16); - - dataNumber+=1; - } - fwrite(&chunkUa5, sizeof(chunkUa5), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkUa5); - matSize += sizeof(chunkUa5); - } - brlyt_4b_chunk chunkUa6; - setnode = mxmlFindElement(subnode, subnode, "ua6", NULL, NULL, MXML_DESCEND); - if (setnode != NULL) - { - mxml_node_t *valnode; - int dataNumber = 0; - for (valnode=mxmlFindElement(setnode, setnode, "data", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "data", NULL, NULL, MXML_DESCEND) ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - - chunkUa6.unk[dataNumber] = strtoul(tempCoord, NULL, 16); - - dataNumber+=1; - } - fwrite(&chunkUa6, sizeof(chunkUa6), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkUa6); - matSize += sizeof(chunkUa6); - } - brlyt_ua7_chunk chunkUa7; - setnode = mxmlFindElement(subnode, subnode, "ua7", NULL, NULL, MXML_DESCEND); - if (setnode != NULL) - { - mxml_node_t *valnode; - valnode=mxmlFindElement(setnode, setnode, "a", NULL, NULL, MXML_DESCEND); - if ( valnode != NULL ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - - chunkUa7.a = be32(strtoul(tempCoord, NULL, 16)); - } - valnode=mxmlFindElement(setnode, setnode, "b", NULL, NULL, MXML_DESCEND); - if ( valnode != NULL ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - - chunkUa7.b = be32(strtoul(tempCoord, NULL, 16)); - } - valnode=mxmlFindElement(setnode, setnode, "c", NULL, NULL, MXML_DESCEND); - if ( valnode != NULL ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - - chunkUa7.c = float_swap_bytes(atof(tempCoord)); - } - valnode=mxmlFindElement(setnode, setnode, "d", NULL, NULL, MXML_DESCEND); - if ( valnode != NULL ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - - chunkUa7.d = be32(strtoul(tempCoord, NULL, 16)); - } - valnode=mxmlFindElement(setnode, setnode, "e", NULL, NULL, MXML_DESCEND); - if ( valnode != NULL ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - - chunkUa7.e = be32(strtoul(tempCoord, NULL, 16)); - } - fwrite(&chunkUa7, sizeof(chunkUa7), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkUa7); - matSize += sizeof(chunkUa7); - } - brlyt_4b_chunk chunkUa8; - setnode = mxmlFindElement(subnode, subnode, "ua8", NULL, NULL, MXML_DESCEND); - if (setnode != NULL) - { - mxml_node_t *valnode; - int dataNumber = 0; - for (valnode=mxmlFindElement(setnode, setnode, "data", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "data", NULL, NULL, MXML_DESCEND) ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - - chunkUa8.unk[dataNumber] = strtoul(tempCoord, NULL, 16); - - dataNumber+=1; - } - fwrite(&chunkUa8, sizeof(chunkUa8), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkUa8); - matSize += sizeof(chunkUa8); - } - brlyt_10b_chunk chunkUa9; - for (setnode = mxmlFindElement(subnode, subnode, "ua9", NULL, NULL, MXML_DESCEND); setnode != NULL; setnode = mxmlFindElement(setnode, subnode, "ua9", NULL, NULL, MXML_DESCEND)) -// if (setnode != NULL) - { - mxml_node_t *valnode; - int dataNumber = 0; - for (valnode=mxmlFindElement(setnode, setnode, "data", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "data", NULL, NULL, MXML_DESCEND) ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - - chunkUa9.unk[dataNumber] = strtoul(tempCoord, NULL, 16); - - dataNumber+=1; - } - fwrite(&chunkUa9, sizeof(chunkUa9), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkUa9); - matSize += sizeof(chunkUa9); - } - brlyt_4b_chunk chunkUaa; - setnode = mxmlFindElement(subnode, subnode, "uaa", NULL, NULL, MXML_DESCEND); - if (setnode != NULL) - { - mxml_node_t *valnode; - int dataNumber = 0; - for (valnode=mxmlFindElement(setnode, setnode, "data", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "data", NULL, NULL, MXML_DESCEND) ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - - chunkUaa.unk[dataNumber] = strtoul(tempCoord, NULL, 16); - - dataNumber+=1; - } - fwrite(&chunkUaa, sizeof(chunkUaa), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkUaa); - matSize += sizeof(chunkUaa); - } - brlyt_4b_chunk chunkUab; - setnode = mxmlFindElement(subnode, subnode, "uab", NULL, NULL, MXML_DESCEND); - if (setnode != NULL) - { - mxml_node_t *valnode; - int dataNumber = 0; - for (valnode=mxmlFindElement(setnode, setnode, "data", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "data", NULL, NULL, MXML_DESCEND) ) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - - chunkUab.unk[dataNumber] = strtoul(tempCoord, NULL, 16); - - dataNumber+=1; - } - fwrite(&chunkUab, sizeof(chunkUab), 1, fp); - *fileOffset = *fileOffset + sizeof(chunkUab); - matSize += sizeof(chunkUab); - } - if (numberOfEntries < actualNumber) - { - offsets[numberOfEntries] = be32(matSize + initialOffset); - materialOffset = ftell(fp); - fseek(fp, offsetsOffset+(numberOfEntries * sizeof(int)), SEEK_SET); - fwrite(&offsets[numberOfEntries], sizeof(int), 1, fp); - fseek(fp, materialOffset, SEEK_SET); - initialOffset += matSize; - matSize = 0; - } - } - free(offsets); - } - if ( memcmp(temp, pan1, sizeof(pan1)) == 0) - { - brlyt_pane_chunk chunk; - - if(mxmlElementGetAttr(node, "name") != NULL) - strcpy(temp, mxmlElementGetAttr(node, "name")); - else{ - printf("No name attribute found!\nQuitting!\n"); - exit(1); - } - char zeroed[24]; - int j; - for (j=0; j<24; j++) - { - zeroed[j] = 0; - } - memcpy(chunk.name, zeroed, 24 * sizeof(char)); - strcpy(chunk.name, temp); - - mxml_node_t *subnode = mxmlFindElement(node, node, "coords", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.x = float_swap_bytes(atof(tempCoord)); - } - valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.y = float_swap_bytes(atof(tempCoord)); - } - valnode = mxmlFindElement(subnode, subnode, "z", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.z = float_swap_bytes(atof(tempCoord)); - } - } - subnode = mxmlFindElement(node, node, "flip", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.flip_x = float_swap_bytes(atof(tempCoord)); - } - valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.flip_y = float_swap_bytes(atof(tempCoord)); - } - } - subnode = mxmlFindElement(node, node, "zoom", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.xmag = float_swap_bytes(atof(tempCoord)); - } - valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.ymag = float_swap_bytes(atof(tempCoord)); - } - } - subnode = mxmlFindElement(node, node, "size", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "width", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.width = float_swap_bytes(atof(tempCoord)); - } - valnode = mxmlFindElement(subnode, subnode, "height", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.height = float_swap_bytes(atof(tempCoord)); - } - } - - subnode = mxmlFindElement(node, node, "flags", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - chunk.flag1 = strtol(tempCoord, NULL, 16); - chunk.flag2 = strtol(&(tempCoord[9]), NULL, 16); - } - subnode = mxmlFindElement(node, node, "alpha", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - chunk.alpha = strtol(tempCoord, NULL, 16); - chunk.alpha2 = strtol(&(tempCoord[9]), NULL, 16); - } - subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - chunk.angle = float_swap_bytes(atof(tempCoord)); - } - fwrite(&chunk, sizeof(chunk), 1, fp); - *fileOffset = *fileOffset + sizeof(chunk); - } - if ( memcmp(temp, bnd1, sizeof(bnd1)) == 0) - { - brlyt_pane_chunk chunk; - - if(mxmlElementGetAttr(node, "name") != NULL) - strcpy(temp, mxmlElementGetAttr(node, "name")); - else{ - printf("No name attribute found!\nQuitting!\n"); - exit(1); - } - char zeroed[24]; - int j; - for (j=0; j<24; j++) - { - zeroed[j] = 0; - } - memcpy(chunk.name, zeroed, 24 * sizeof(char)); - strcpy(chunk.name, temp); - - mxml_node_t *subnode = mxmlFindElement(node, node, "coords", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.x = float_swap_bytes(atof(tempCoord)); - } - valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.y = float_swap_bytes(atof(tempCoord)); - } - valnode = mxmlFindElement(subnode, subnode, "z", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.z = float_swap_bytes(atof(tempCoord)); - } - } - subnode = mxmlFindElement(node, node, "flip", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.flip_x = float_swap_bytes(atof(tempCoord)); - } - valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.flip_y = float_swap_bytes(atof(tempCoord)); - } - } - subnode = mxmlFindElement(node, node, "zoom", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.xmag = float_swap_bytes(atof(tempCoord)); - } - valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.ymag = float_swap_bytes(atof(tempCoord)); - } - } - subnode = mxmlFindElement(node, node, "size", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "width", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.width = float_swap_bytes(atof(tempCoord)); - } - valnode = mxmlFindElement(subnode, subnode, "height", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.height = float_swap_bytes(atof(tempCoord)); - } - } - - subnode = mxmlFindElement(node, node, "flags", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - chunk.flag1 = strtol(tempCoord, NULL, 16); - chunk.flag2 = strtol(&(tempCoord[9]), NULL, 16); - } - subnode = mxmlFindElement(node, node, "alpha", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - chunk.alpha = strtol(tempCoord, NULL, 16); - chunk.alpha2 = strtol(&(tempCoord[9]), NULL, 16); - } - subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - chunk.angle = float_swap_bytes(atof(tempCoord)); - } - fwrite(&chunk, sizeof(chunk), 1, fp); - *fileOffset = *fileOffset + sizeof(chunk); - } - if ( memcmp(temp, wnd1, sizeof(wnd1)) == 0) - { - brlyt_pane_chunk chunk; - - if(mxmlElementGetAttr(node, "name") != NULL) - strcpy(temp, mxmlElementGetAttr(node, "name")); - else{ - printf("No name attribute found!\nQuitting!\n"); - exit(1); - } - char zeroed[24]; - int j; - for (j=0; j<24; j++) zeroed[j] = 0; - memcpy(chunk.name, zeroed, 24 * sizeof(char)); - strcpy(chunk.name, temp); - - mxml_node_t *subnode = mxmlFindElement(node, node, "coords", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.x = float_swap_bytes(atof(tempCoord)); - } - valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.y = float_swap_bytes(atof(tempCoord)); - } - valnode = mxmlFindElement(subnode, subnode, "z", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.z = float_swap_bytes(atof(tempCoord)); - } - } - subnode = mxmlFindElement(node, node, "flip", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.flip_x = float_swap_bytes(atof(tempCoord)); - } - valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.flip_y = float_swap_bytes(atof(tempCoord)); - } - } - subnode = mxmlFindElement(node, node, "zoom", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.xmag = float_swap_bytes(atof(tempCoord)); - } - valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.ymag = float_swap_bytes(atof(tempCoord)); - } - } - subnode = mxmlFindElement(node, node, "size", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "width", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.width = float_swap_bytes(atof(tempCoord)); - } - valnode = mxmlFindElement(subnode, subnode, "height", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.height = float_swap_bytes(atof(tempCoord)); - } - } - - subnode = mxmlFindElement(node, node, "flags", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - chunk.flag1 = strtol(tempCoord, NULL, 16); - chunk.flag2 = strtol(&(tempCoord[9]), NULL, 16); - } - subnode = mxmlFindElement(node, node, "alpha", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - chunk.alpha = strtol(tempCoord, NULL, 16); - chunk.alpha2 = strtol(&(tempCoord[9]), NULL, 16); - } - subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - chunk.angle = float_swap_bytes(atof(tempCoord)); - } - fwrite(&chunk, sizeof(chunk), 1, fp); - *fileOffset = *fileOffset + sizeof(chunk); - } - if ( memcmp(temp, txt1, sizeof(txt1)) == 0) - { - brlyt_pane_chunk chunk; - brlyt_text_chunk chunk2; - - if(mxmlElementGetAttr(node, "name") != NULL) - strcpy(temp, mxmlElementGetAttr(node, "name")); - else{ - printf("No name attribute found!\nQuitting!\n"); - exit(1); - } - char zeroed[24]; - int j; - for (j=0; j<24; j++) zeroed[j] = 0; - memcpy(chunk.name, zeroed, 24 * sizeof(char)); - strcpy(chunk.name, temp); - chunk2.mat_off = short_swap_bytes(findMatOffset(temp)); - - mxml_node_t *subnode = mxmlFindElement(node, node, "coords", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.x = float_swap_bytes(atof(tempCoord)); - } - valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.y = float_swap_bytes(atof(tempCoord)); - } - valnode = mxmlFindElement(subnode, subnode, "z", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.z = float_swap_bytes(atof(tempCoord)); - } - } - subnode = mxmlFindElement(node, node, "flip", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.flip_x = float_swap_bytes(atof(tempCoord)); - } - valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.flip_y = float_swap_bytes(atof(tempCoord)); - } - } - subnode = mxmlFindElement(node, node, "zoom", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.xmag = float_swap_bytes(atof(tempCoord)); - } - valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.ymag = float_swap_bytes(atof(tempCoord)); - } - } - subnode = mxmlFindElement(node, node, "size", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "width", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.width = float_swap_bytes(atof(tempCoord)); - } - valnode = mxmlFindElement(subnode, subnode, "height", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk.height = float_swap_bytes(atof(tempCoord)); - } - } - - subnode = mxmlFindElement(node, node, "flags", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - chunk.flag1 = strtol(tempCoord, NULL, 16); - chunk.flag2 = strtol(&(tempCoord[9]), NULL, 16); - } - subnode = mxmlFindElement(node, node, "alpha", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - chunk.alpha = strtol(tempCoord, NULL, 16); - chunk.alpha2 = strtol(&(tempCoord[9]), NULL, 16); - } - subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - chunk.angle = float_swap_bytes(atof(tempCoord)); - } - -// brlyt_text_chunk chunk2; - subnode = mxmlFindElement(node, node, "font", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char temp[256]; - if(mxmlElementGetAttr(subnode, "index") != NULL) - strcpy(temp, mxmlElementGetAttr(subnode, "index")); - else{ - printf("No index attribute found!\nQuitting!\n"); - exit(1); - } - chunk2.font_idx = atoi(temp); - chunk2.font_idx = short_swap_bytes(chunk2.font_idx); - - mxml_node_t *valnode; - valnode = mxmlFindElement(subnode, subnode, "xsize", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk2.font_size_x = float_swap_bytes(atof(tempCoord)); - } - valnode = mxmlFindElement(subnode, subnode, "ysize", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk2.font_size_y = float_swap_bytes(atof(tempCoord)); - } - valnode = mxmlFindElement(subnode, subnode, "charsize", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk2.char_space = float_swap_bytes(atof(tempCoord)); - } - valnode = mxmlFindElement(subnode, subnode, "linesize", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk2.line_space = float_swap_bytes(atof(tempCoord)); - } - valnode = mxmlFindElement(subnode, subnode, "unk", NULL, NULL, MXML_DESCEND); - if (valnode != NULL) - { - char tempCoord[256]; - get_value(valnode, tempCoord, 256); - chunk2.unk4 = strtol(tempCoord, NULL, 16); - } - } - - subnode = mxmlFindElement(node, node, "length", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - chunk2.len1 = strtoul(tempCoord, NULL, 16); - chunk2.len1 = short_swap_bytes(chunk2.len1); - chunk2.len2 = strtoul(tempCoord+5, NULL, 16); - chunk2.len2 = short_swap_bytes(chunk2.len2); - } - subnode = mxmlFindElement(node, node, "color", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - chunk2.color1 = be32(strtoul(tempCoord, NULL, 16)); - chunk2.color2 = be32(strtoul(tempCoord+9, NULL, 16)); - } - u8 textyLength = short_swap_bytes(chunk2.len2); - if ((textyLength % 4) != 0) - textyLength += (4 - (textyLength % 4)); - unsigned char texty[textyLength]; - subnode = mxmlFindElement(node, node, "text", NULL, NULL, MXML_DESCEND); - if (subnode != NULL) - { - char tempCoord[256]; - get_value(subnode, tempCoord, 256); - //memcpy(texty, tempCoord, short_swap_bytes(chunk2.len2)); - ASCIIfromUnicode(texty, tempCoord, short_swap_bytes(chunk2.len2)); - } - fwrite(&chunk, sizeof(chunk), 1, fp); - *fileOffset = *fileOffset + sizeof(chunk); - - chunk2.name_offs=be32(0x74); - chunk2.pad[0]= 0;chunk2.pad[1]=0;chunk2.pad[2]=0; - fwrite(&chunk2, sizeof(chunk2), 1, fp); - *fileOffset = *fileOffset + sizeof(chunk2); - int q; for (q=short_swap_bytes(chunk2.len2);q 0) free(subs); - } - if ( memcmp(temp, grs1, sizeof(grs1)) == 0) - { - - } - if ( memcmp(temp, gre1, sizeof(gre1)) == 0) - { - - } - if ( memcmp(temp, pas1, sizeof(pas1)) == 0) - { - - } - if ( memcmp(temp, pae1, sizeof(pae1)) == 0) - { - - } - - *blobsize = *fileOffset - startOfChunk; + unsigned int startOfChunk = *fileOffset; + + char lyt1[4] = {'l', 'y', 't', '1'}; // // + char txl1[4] = {'t', 'x', 'l', '1'}; // // + char fnl1[4] = {'f', 'n', 'l', '1'}; // // + char mat1[4] = {'m', 'a', 't', '1'}; + char pan1[4] = {'p', 'a', 'n', '1'}; // // + char wnd1[4] = {'w', 'n', 'd', '1'}; // // + char bnd1[4] = {'b', 'n', 'd', '1'}; // // + char pic1[4] = {'p', 'i', 'c', '1'}; // / + char txt1[4] = {'t', 'x', 't', '1'}; // / + char grp1[4] = {'g', 'r', 'p', '1'}; // // + char grs1[4] = {'g', 'r', 's', '1'}; + char gre1[4] = {'g', 'r', 'e', '1'}; + char pas1[4] = {'p', 'a', 's', '1'}; + char pae1[4] = {'p', 'a', 'e', '1'}; + + if ( memcmp(temp, lyt1, sizeof(lyt1)) == 0) + { + brlyt_lytheader_chunk lytheader; + + mxml_node_t *subnode = mxmlFindElement(node , node , "a", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempChar[4]; + get_value(subnode, tempChar, 256); + lytheader.a = atoi(tempChar); + lytheader.pad[0]=0;lytheader.pad[1]=0;lytheader.pad[2]=0; + } + subnode = mxmlFindElement(node, node, "size", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode = mxmlFindElement(subnode , subnode , "width", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempChar[4]; + get_value(valnode, tempChar, 256); + float something; + *(float*)(&(lytheader.width)) = atof(tempChar); + } + valnode = mxmlFindElement(subnode , subnode ,"height", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempChar[4]; + get_value(valnode, tempChar, 256); + + *(float*)(&(lytheader.height)) = atof(tempChar); + } + } + lytheader.pad[0] = 0; lytheader.pad[1] = 0; lytheader.pad[2] = 0; + lytheader.width = float_swap_bytes(lytheader.width); + lytheader.height = float_swap_bytes(lytheader.height); + fwrite(&lytheader, sizeof(brlyt_header), 1, fp); + *fileOffset = *fileOffset + sizeof(lytheader); + } + if ( memcmp(temp, txl1, sizeof(txl1)) == 0) + { + int numoffsOffset = ftell(fp); + + brlyt_numoffs_chunk chunk; + chunk.num = 0; + chunk.offs = 0; + fwrite(&chunk, sizeof(chunk), 1, fp); + *fileOffset = *fileOffset + sizeof(chunk); + + char *names; + names = malloc(sizeof(names)); + int lengthOfNames = 0; + mxml_node_t *subnode = mxmlFindElement(node, node, "entries", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + int numEntries = 0; + + int oldNameLength; + int baseOffset = 0; + + u32 *offsunks; + + offsunks = malloc(sizeof(u32)); + + brlyt_offsunk_chunk chunk2; + mxml_node_t *valnode; + for(valnode = mxmlFindElement(subnode, subnode, "name", NULL, NULL, MXML_DESCEND); valnode != NULL; valnode = mxmlFindElement(valnode, subnode, "name", NULL, NULL, MXML_DESCEND)) { + + if (valnode != NULL) + { + + char tempSub[256]; + get_value(valnode, tempSub, 256); + + oldNameLength = lengthOfNames; + lengthOfNames += strlen(tempSub); + + offsunks = realloc(offsunks, (numEntries + 1)*(2 * sizeof(u32))); + if (offsunks == NULL) printf("NULLed by a realloc\n"); + + offsunks[(numEntries*2)+0] = baseOffset; + offsunks[(numEntries*2)+1] = 0; + + *fileOffset = *fileOffset + sizeof(chunk2); + numEntries++; + + baseOffset += (strlen(tempSub) + 1); + + names = realloc(names, 1 + sizeof(char) * lengthOfNames); + strcpy(&names[oldNameLength], tempSub); + char nuller = '\0'; + memcpy(&names[lengthOfNames], &nuller, sizeof(char)); + lengthOfNames += 1; + } + } + chunk.num = short_swap_bytes(numEntries); + chunk.offs = 0; + fseek(fp, numoffsOffset, SEEK_SET); + fwrite(&chunk, sizeof(chunk), 1, fp); + + int i; + for(i=0;i 0) + { + u8 toAdd = 4-(*fileOffset % 4); + char nuller[3] = {'\0', '\0', '\0'}; + fwrite(&nuller, sizeof(char), toAdd, fp); + *fileOffset = *fileOffset + toAdd; + } +// materials = malloc(lengthOfNames * sizeof(char)); +// memcpy(materials, names, lengthOfNames * sizeof(char)); +// free(names); + textures = malloc(lengthOfNames * sizeof(char)); + memcpy(textures, names, lengthOfNames * sizeof(char)); + free(names); + } + if ( memcmp(temp, fnl1, sizeof(fnl1)) == 0) + { + brlyt_numoffs_chunk chunk; + chunk.num = 0; + chunk.offs = 0; + fwrite(&chunk, sizeof(chunk), 1, fp); + *fileOffset = *fileOffset + sizeof(chunk); + + char *names; + names = malloc(sizeof(char)); + int lengthOfNames = 0; + mxml_node_t *subnode = mxmlFindElement(node, node, "entries", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + int numEntries = 0; + + int oldNameLength; + int baseOffset = 0; + int numoffsOffset = *fileOffset - 4; + + u32 *offsunks; + offsunks = malloc(sizeof(u32)); + + brlyt_offsunk_chunk chunk2; + mxml_node_t *valnode; + for(valnode = mxmlFindElement(subnode, subnode, "name", NULL, NULL, MXML_DESCEND); valnode != NULL; valnode = mxmlFindElement(valnode, subnode, "name", NULL, NULL, MXML_DESCEND)) { + + if (valnode != NULL) + { + char tempSub[256]; + get_value(valnode, tempSub, 256); + + oldNameLength = lengthOfNames; + lengthOfNames += strlen(tempSub); + + offsunks = realloc(offsunks, (numEntries + 1)*(2 * sizeof(u32))); + offsunks[(numEntries*2)+0] = baseOffset; + offsunks[(numEntries*2)+1] = 0; + + *fileOffset = *fileOffset + sizeof(chunk2); + numEntries++; + + baseOffset += (strlen(tempSub) + 1); + names = realloc(names, 1 + sizeof(char) * lengthOfNames); + memcpy(&names[oldNameLength], tempSub, strlen(tempSub)); + char nuller = '\0'; + memcpy(&names[lengthOfNames], &nuller, sizeof(char)); + lengthOfNames += 1; + } + } + chunk.num = short_swap_bytes(numEntries); + chunk.offs = 0; + fseek(fp, numoffsOffset, SEEK_SET); + fwrite(&chunk, sizeof(chunk), 1, fp); + + int i; + for(i=0;i 0) + { + u8 toAdd = 4-(*fileOffset % 4); + char nuller[3] = {'\0', '\0', '\0'}; + fwrite(&nuller, sizeof(char), toAdd, fp); + *fileOffset = *fileOffset + toAdd; + } + free(names); + } + if ( memcmp(temp, mat1, sizeof(mat1)) == 0) + { + + int numberOfEntries = 0; + int actualNumber = 0; + brlyt_numoffs_chunk numchunk; + brlyt_material_chunk chunk; + mxml_node_t *subnode; + for(subnode=mxmlFindElement(node, node, "entries", NULL, NULL, MXML_DESCEND);subnode!=NULL;subnode=mxmlFindElement(subnode, node, "entries", NULL, NULL, MXML_DESCEND)) + numberOfEntries++; + + numchunk.num = short_swap_bytes(numberOfEntries); + numchunk.offs = 0; + fwrite(&numchunk, sizeof(numchunk), 1, fp); + *fileOffset = *fileOffset + sizeof(numchunk); + + int *offsets = calloc(numberOfEntries, sizeof(int)); + int offsetsOffset = ftell(fp); + int materialOffset = 0; + actualNumber = numberOfEntries; + numberOfEntries = 0; + int matSize = 0; + int initialOffset = sizeof(numchunk) + 8 + (actualNumber * sizeof(int)); + + offsets[numberOfEntries] = be32(matSize + initialOffset); + fwrite(&offsets[0], sizeof(int), actualNumber, fp); + *fileOffset = *fileOffset + (actualNumber * 4); //changed from numberOfEntries + + for(subnode=mxmlFindElement(node,node,"entries",NULL,NULL,MXML_DESCEND);subnode!=NULL;subnode=mxmlFindElement(subnode,node,"entries",NULL,NULL,MXML_DESCEND)) + { + numberOfEntries += 1; + char temp[256]; + if(mxmlElementGetAttr(subnode, "name") != NULL) + strcpy(temp, mxmlElementGetAttr(subnode, "name")); + else{ + printf("No name attribute found!\nQuitting!\n"); + exit(1); + } + char zeroed[24]; + int j; + for (j=0; j<24; j++) + { + zeroed[j] = 0; + } + memcpy(chunk.name, zeroed, 20 * sizeof(char)); + strcpy(chunk.name, temp); + + materials = realloc(materials, lengthOfMaterials + strlen(chunk.name) + 1); + memcpy(&materials[lengthOfMaterials], chunk.name, strlen(chunk.name) + 1); + lengthOfMaterials += (1 + strlen(chunk.name)); + numberOfMaterials += 1; + + mxml_node_t *setnode; + setnode = mxmlFindElement(subnode, subnode, "colors", NULL, NULL, MXML_DESCEND); + if (setnode != NULL) + { + mxml_node_t *valnode; + int colorNumber = 0; + for (valnode=mxmlFindElement(setnode, setnode, "tev", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "tev", NULL, NULL, MXML_DESCEND) ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + + chunk.tev_color[colorNumber] = strtoul(tempCoord, NULL, 16); + + chunk.tev_color[colorNumber] = short_swap_bytes(chunk.tev_color[colorNumber]); + + colorNumber+=1; + } + colorNumber = 0; + for (valnode=mxmlFindElement(setnode, setnode, "unk", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "unk", NULL, NULL, MXML_DESCEND) ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + + chunk.unk_color[colorNumber] = strtoul(tempCoord, NULL, 16); + + chunk.unk_color[colorNumber] = short_swap_bytes(chunk.unk_color[colorNumber]); + + colorNumber+=1; + } + colorNumber = 0; + for (valnode=mxmlFindElement(setnode, setnode, "unk2", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "unk2", NULL, NULL, MXML_DESCEND) ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + + chunk.unk_color_2[colorNumber] = strtoul(tempCoord, NULL, 16); + + chunk.unk_color_2[colorNumber] = short_swap_bytes(chunk.unk_color_2[colorNumber]); + + colorNumber+=1; + } + colorNumber = 0; + for (valnode=mxmlFindElement(setnode, setnode, "tev_k", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "tev_k", NULL, NULL, MXML_DESCEND) ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + + chunk.tev_kcolor[colorNumber] = be32(strtoul(tempCoord, NULL, 16)); + colorNumber+=1; + } + } + setnode = mxmlFindElement(subnode,subnode,"flags",NULL,NULL,MXML_DESCEND); + if (setnode != NULL) + { + char tempCoord[256]; + get_value(setnode, tempCoord, 256); + chunk.flags = be32(strtoul(tempCoord, NULL, 16)); + } + + fwrite(&chunk, sizeof(chunk), 1, fp); + *fileOffset = *fileOffset + sizeof(chunk); + matSize += sizeof(chunk); + + brlyt_texref_chunk chunkTexRef; + setnode = mxmlFindElement(subnode, subnode, "material", NULL, NULL, MXML_DESCEND); + if (setnode != NULL) + { + mxml_node_t *valnode; + char temp[256]; + if(mxmlElementGetAttr(setnode, "name") != NULL) + strcpy(temp, mxmlElementGetAttr(setnode, "name")); + else{ + printf("No name attribute found!\nQuitting!\n"); + exit(1); + } + chunkTexRef.tex_offs = short_swap_bytes(findTexOffset(temp)); + + valnode=mxmlFindElement(setnode, setnode, "wrap_s", NULL, NULL, MXML_DESCEND); + + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunkTexRef.wrap_s = strtoul(tempCoord, NULL, 16); + + valnode=mxmlFindElement(setnode, setnode, "wrap_t", NULL, NULL, MXML_DESCEND); + + get_value(valnode, tempCoord, 256); + chunkTexRef.wrap_t = strtoul(tempCoord, NULL, 16); + + fwrite(&chunkTexRef, sizeof(chunkTexRef), 1, fp); + *fileOffset = *fileOffset + sizeof(chunkTexRef); + matSize += sizeof(chunkTexRef); + } + + brlyt_ua2_chunk chunkUa2; + setnode = mxmlFindElement(subnode, subnode, "ua2", NULL, NULL, MXML_DESCEND); + if (setnode != NULL) + { + mxml_node_t *valnode; + int dataNumber = 0; + for (valnode=mxmlFindElement(setnode, setnode, "data", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "data", NULL, NULL, MXML_DESCEND) ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + + chunkUa2.unk[dataNumber] = float_swap_bytes(atof(tempCoord)); + + dataNumber+=1; + } + fwrite(&chunkUa2, sizeof(chunkUa2), 1, fp); + *fileOffset = *fileOffset + sizeof(chunkUa2); + matSize += sizeof(chunkUa2); + } + brlyt_4b_chunk chunkUa3; + setnode = mxmlFindElement(subnode, subnode, "ua3", NULL, NULL, MXML_DESCEND); + if (setnode != NULL) + { + mxml_node_t *valnode; + int dataNumber = 0; + for (valnode=mxmlFindElement(setnode, setnode, "data", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "data", NULL, NULL, MXML_DESCEND) ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + + chunkUa3.unk[dataNumber] = strtoul(tempCoord, NULL, 16); + + dataNumber+=1; + } + fwrite(&chunkUa3, sizeof(chunkUa3), 1, fp); + *fileOffset = *fileOffset + sizeof(chunkUa3); + matSize += sizeof(chunkUa3); + } + brlyt_4b_chunk chunkUa4; + setnode = mxmlFindElement(subnode, subnode, "ua4", NULL, NULL, MXML_DESCEND); + if (setnode != NULL) + { + mxml_node_t *valnode; + int dataNumber = 0; + for (valnode=mxmlFindElement(setnode, setnode, "data", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "data", NULL, NULL, MXML_DESCEND) ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + + chunkUa4.unk[dataNumber] = strtoul(tempCoord, NULL, 16); + + dataNumber+=1; + } + fwrite(&chunkUa4, sizeof(chunkUa4), 1, fp); + *fileOffset = *fileOffset + sizeof(chunkUa4); + matSize += sizeof(chunkUa4); + } + brlyt_4b_chunk chunkUa5; + setnode = mxmlFindElement(subnode, subnode, "ua5", NULL, NULL, MXML_DESCEND); + if (setnode != NULL) + { + mxml_node_t *valnode; + int dataNumber = 0; + for (valnode=mxmlFindElement(setnode, setnode, "data", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "data", NULL, NULL, MXML_DESCEND) ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + + chunkUa5.unk[dataNumber] = strtoul(tempCoord, NULL, 16); + + dataNumber+=1; + } + fwrite(&chunkUa5, sizeof(chunkUa5), 1, fp); + *fileOffset = *fileOffset + sizeof(chunkUa5); + matSize += sizeof(chunkUa5); + } + brlyt_4b_chunk chunkUa6; + setnode = mxmlFindElement(subnode, subnode, "ua6", NULL, NULL, MXML_DESCEND); + if (setnode != NULL) + { + mxml_node_t *valnode; + int dataNumber = 0; + for (valnode=mxmlFindElement(setnode, setnode, "data", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "data", NULL, NULL, MXML_DESCEND) ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + + chunkUa6.unk[dataNumber] = strtoul(tempCoord, NULL, 16); + + dataNumber+=1; + } + fwrite(&chunkUa6, sizeof(chunkUa6), 1, fp); + *fileOffset = *fileOffset + sizeof(chunkUa6); + matSize += sizeof(chunkUa6); + } + brlyt_ua7_chunk chunkUa7; + setnode = mxmlFindElement(subnode, subnode, "ua7", NULL, NULL, MXML_DESCEND); + if (setnode != NULL) + { + mxml_node_t *valnode; + valnode=mxmlFindElement(setnode, setnode, "a", NULL, NULL, MXML_DESCEND); + if ( valnode != NULL ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + + chunkUa7.a = be32(strtoul(tempCoord, NULL, 16)); + } + valnode=mxmlFindElement(setnode, setnode, "b", NULL, NULL, MXML_DESCEND); + if ( valnode != NULL ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + + chunkUa7.b = be32(strtoul(tempCoord, NULL, 16)); + } + valnode=mxmlFindElement(setnode, setnode, "c", NULL, NULL, MXML_DESCEND); + if ( valnode != NULL ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + + chunkUa7.c = float_swap_bytes(atof(tempCoord)); + } + valnode=mxmlFindElement(setnode, setnode, "d", NULL, NULL, MXML_DESCEND); + if ( valnode != NULL ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + + chunkUa7.d = be32(strtoul(tempCoord, NULL, 16)); + } + valnode=mxmlFindElement(setnode, setnode, "e", NULL, NULL, MXML_DESCEND); + if ( valnode != NULL ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + + chunkUa7.e = be32(strtoul(tempCoord, NULL, 16)); + } + fwrite(&chunkUa7, sizeof(chunkUa7), 1, fp); + *fileOffset = *fileOffset + sizeof(chunkUa7); + matSize += sizeof(chunkUa7); + } + brlyt_4b_chunk chunkUa8; + setnode = mxmlFindElement(subnode, subnode, "ua8", NULL, NULL, MXML_DESCEND); + if (setnode != NULL) + { + mxml_node_t *valnode; + int dataNumber = 0; + for (valnode=mxmlFindElement(setnode, setnode, "data", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "data", NULL, NULL, MXML_DESCEND) ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + + chunkUa8.unk[dataNumber] = strtoul(tempCoord, NULL, 16); + + dataNumber+=1; + } + fwrite(&chunkUa8, sizeof(chunkUa8), 1, fp); + *fileOffset = *fileOffset + sizeof(chunkUa8); + matSize += sizeof(chunkUa8); + } + brlyt_10b_chunk chunkUa9; + for (setnode = mxmlFindElement(subnode, subnode, "ua9", NULL, NULL, MXML_DESCEND); setnode != NULL; setnode = mxmlFindElement(setnode, subnode, "ua9", NULL, NULL, MXML_DESCEND)) +// if (setnode != NULL) + { + mxml_node_t *valnode; + int dataNumber = 0; + for (valnode=mxmlFindElement(setnode, setnode, "data", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "data", NULL, NULL, MXML_DESCEND) ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + + chunkUa9.unk[dataNumber] = strtoul(tempCoord, NULL, 16); + + dataNumber+=1; + } + fwrite(&chunkUa9, sizeof(chunkUa9), 1, fp); + *fileOffset = *fileOffset + sizeof(chunkUa9); + matSize += sizeof(chunkUa9); + } + brlyt_4b_chunk chunkUaa; + setnode = mxmlFindElement(subnode, subnode, "uaa", NULL, NULL, MXML_DESCEND); + if (setnode != NULL) + { + mxml_node_t *valnode; + int dataNumber = 0; + for (valnode=mxmlFindElement(setnode, setnode, "data", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "data", NULL, NULL, MXML_DESCEND) ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + + chunkUaa.unk[dataNumber] = strtoul(tempCoord, NULL, 16); + + dataNumber+=1; + } + fwrite(&chunkUaa, sizeof(chunkUaa), 1, fp); + *fileOffset = *fileOffset + sizeof(chunkUaa); + matSize += sizeof(chunkUaa); + } + brlyt_4b_chunk chunkUab; + setnode = mxmlFindElement(subnode, subnode, "uab", NULL, NULL, MXML_DESCEND); + if (setnode != NULL) + { + mxml_node_t *valnode; + int dataNumber = 0; + for (valnode=mxmlFindElement(setnode, setnode, "data", NULL, NULL, MXML_DESCEND) ; valnode != NULL ; valnode=mxmlFindElement(valnode, setnode, "data", NULL, NULL, MXML_DESCEND) ) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + + chunkUab.unk[dataNumber] = strtoul(tempCoord, NULL, 16); + + dataNumber+=1; + } + fwrite(&chunkUab, sizeof(chunkUab), 1, fp); + *fileOffset = *fileOffset + sizeof(chunkUab); + matSize += sizeof(chunkUab); + } + if (numberOfEntries < actualNumber) + { + offsets[numberOfEntries] = be32(matSize + initialOffset); + materialOffset = ftell(fp); + fseek(fp, offsetsOffset+(numberOfEntries * sizeof(int)), SEEK_SET); + fwrite(&offsets[numberOfEntries], sizeof(int), 1, fp); + fseek(fp, materialOffset, SEEK_SET); + initialOffset += matSize; + matSize = 0; + } + } + free(offsets); + } + if ( memcmp(temp, pan1, sizeof(pan1)) == 0) + { + brlyt_pane_chunk chunk; + + if(mxmlElementGetAttr(node, "name") != NULL) + strcpy(temp, mxmlElementGetAttr(node, "name")); + else{ + printf("No name attribute found!\nQuitting!\n"); + exit(1); + } + char zeroed[24]; + int j; + for (j=0; j<24; j++) + { + zeroed[j] = 0; + } + memcpy(chunk.name, zeroed, 24 * sizeof(char)); + strcpy(chunk.name, temp); + + mxml_node_t *subnode = mxmlFindElement(node, node, "coords", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.x = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.y = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "z", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.z = float_swap_bytes(atof(tempCoord)); + } + } + subnode = mxmlFindElement(node, node, "flip", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.flip_x = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.flip_y = float_swap_bytes(atof(tempCoord)); + } + } + subnode = mxmlFindElement(node, node, "zoom", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.xmag = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.ymag = float_swap_bytes(atof(tempCoord)); + } + } + subnode = mxmlFindElement(node, node, "size", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "width", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.width = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "height", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.height = float_swap_bytes(atof(tempCoord)); + } + } + + subnode = mxmlFindElement(node, node, "flags", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + chunk.flag1 = strtol(tempCoord, NULL, 16); + chunk.flag2 = strtol(&(tempCoord[9]), NULL, 16); + } + subnode = mxmlFindElement(node, node, "alpha", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + chunk.alpha = strtol(tempCoord, NULL, 16); + chunk.alpha2 = strtol(&(tempCoord[9]), NULL, 16); + } + subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + chunk.angle = float_swap_bytes(atof(tempCoord)); + } + fwrite(&chunk, sizeof(chunk), 1, fp); + *fileOffset = *fileOffset + sizeof(chunk); + } + if ( memcmp(temp, bnd1, sizeof(bnd1)) == 0) + { + brlyt_pane_chunk chunk; + + if(mxmlElementGetAttr(node, "name") != NULL) + strcpy(temp, mxmlElementGetAttr(node, "name")); + else{ + printf("No name attribute found!\nQuitting!\n"); + exit(1); + } + char zeroed[24]; + int j; + for (j=0; j<24; j++) + { + zeroed[j] = 0; + } + memcpy(chunk.name, zeroed, 24 * sizeof(char)); + strcpy(chunk.name, temp); + + mxml_node_t *subnode = mxmlFindElement(node, node, "coords", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.x = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.y = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "z", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.z = float_swap_bytes(atof(tempCoord)); + } + } + subnode = mxmlFindElement(node, node, "flip", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.flip_x = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.flip_y = float_swap_bytes(atof(tempCoord)); + } + } + subnode = mxmlFindElement(node, node, "zoom", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.xmag = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.ymag = float_swap_bytes(atof(tempCoord)); + } + } + subnode = mxmlFindElement(node, node, "size", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "width", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.width = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "height", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.height = float_swap_bytes(atof(tempCoord)); + } + } + + subnode = mxmlFindElement(node, node, "flags", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + chunk.flag1 = strtol(tempCoord, NULL, 16); + chunk.flag2 = strtol(&(tempCoord[9]), NULL, 16); + } + subnode = mxmlFindElement(node, node, "alpha", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + chunk.alpha = strtol(tempCoord, NULL, 16); + chunk.alpha2 = strtol(&(tempCoord[9]), NULL, 16); + } + subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + chunk.angle = float_swap_bytes(atof(tempCoord)); + } + fwrite(&chunk, sizeof(chunk), 1, fp); + *fileOffset = *fileOffset + sizeof(chunk); + } + if ( memcmp(temp, wnd1, sizeof(wnd1)) == 0) + { + brlyt_pane_chunk chunk; + + if(mxmlElementGetAttr(node, "name") != NULL) + strcpy(temp, mxmlElementGetAttr(node, "name")); + else{ + printf("No name attribute found!\nQuitting!\n"); + exit(1); + } + char zeroed[24]; + int j; + for (j=0; j<24; j++) zeroed[j] = 0; + memcpy(chunk.name, zeroed, 24 * sizeof(char)); + strcpy(chunk.name, temp); + + mxml_node_t *subnode = mxmlFindElement(node, node, "coords", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.x = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.y = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "z", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.z = float_swap_bytes(atof(tempCoord)); + } + } + subnode = mxmlFindElement(node, node, "flip", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.flip_x = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.flip_y = float_swap_bytes(atof(tempCoord)); + } + } + subnode = mxmlFindElement(node, node, "zoom", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.xmag = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.ymag = float_swap_bytes(atof(tempCoord)); + } + } + subnode = mxmlFindElement(node, node, "size", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "width", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.width = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "height", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.height = float_swap_bytes(atof(tempCoord)); + } + } + + subnode = mxmlFindElement(node, node, "flags", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + chunk.flag1 = strtol(tempCoord, NULL, 16); + chunk.flag2 = strtol(&(tempCoord[9]), NULL, 16); + } + subnode = mxmlFindElement(node, node, "alpha", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + chunk.alpha = strtol(tempCoord, NULL, 16); + chunk.alpha2 = strtol(&(tempCoord[9]), NULL, 16); + } + subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + chunk.angle = float_swap_bytes(atof(tempCoord)); + } + fwrite(&chunk, sizeof(chunk), 1, fp); + *fileOffset = *fileOffset + sizeof(chunk); + } + if ( memcmp(temp, txt1, sizeof(txt1)) == 0) + { + brlyt_pane_chunk chunk; + brlyt_text_chunk chunk2; + + if(mxmlElementGetAttr(node, "name") != NULL) + strcpy(temp, mxmlElementGetAttr(node, "name")); + else{ + printf("No name attribute found!\nQuitting!\n"); + exit(1); + } + char zeroed[24]; + int j; + for (j=0; j<24; j++) zeroed[j] = 0; + memcpy(chunk.name, zeroed, 24 * sizeof(char)); + strcpy(chunk.name, temp); + chunk2.mat_off = short_swap_bytes(findMatOffset(temp)); + + mxml_node_t *subnode = mxmlFindElement(node, node, "coords", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.x = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.y = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "z", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.z = float_swap_bytes(atof(tempCoord)); + } + } + subnode = mxmlFindElement(node, node, "flip", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.flip_x = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.flip_y = float_swap_bytes(atof(tempCoord)); + } + } + subnode = mxmlFindElement(node, node, "zoom", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "x", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.xmag = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "y", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.ymag = float_swap_bytes(atof(tempCoord)); + } + } + subnode = mxmlFindElement(node, node, "size", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "width", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.width = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "height", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk.height = float_swap_bytes(atof(tempCoord)); + } + } + + subnode = mxmlFindElement(node, node, "flags", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + chunk.flag1 = strtol(tempCoord, NULL, 16); + chunk.flag2 = strtol(&(tempCoord[9]), NULL, 16); + } + subnode = mxmlFindElement(node, node, "alpha", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + chunk.alpha = strtol(tempCoord, NULL, 16); + chunk.alpha2 = strtol(&(tempCoord[9]), NULL, 16); + } + subnode = mxmlFindElement(node, node, "rotate", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + chunk.angle = float_swap_bytes(atof(tempCoord)); + } + +// brlyt_text_chunk chunk2; + subnode = mxmlFindElement(node, node, "font", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char temp[256]; + if(mxmlElementGetAttr(subnode, "index") != NULL) + strcpy(temp, mxmlElementGetAttr(subnode, "index")); + else{ + printf("No index attribute found!\nQuitting!\n"); + exit(1); + } + chunk2.font_idx = atoi(temp); + chunk2.font_idx = short_swap_bytes(chunk2.font_idx); + + mxml_node_t *valnode; + valnode = mxmlFindElement(subnode, subnode, "xsize", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk2.font_size_x = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "ysize", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk2.font_size_y = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "charsize", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk2.char_space = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "linesize", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk2.line_space = float_swap_bytes(atof(tempCoord)); + } + valnode = mxmlFindElement(subnode, subnode, "unk", NULL, NULL, MXML_DESCEND); + if (valnode != NULL) + { + char tempCoord[256]; + get_value(valnode, tempCoord, 256); + chunk2.unk4 = strtol(tempCoord, NULL, 16); + } + } + + subnode = mxmlFindElement(node, node, "length", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + chunk2.len1 = strtoul(tempCoord, NULL, 16); + chunk2.len1 = short_swap_bytes(chunk2.len1); + chunk2.len2 = strtoul(tempCoord+5, NULL, 16); + chunk2.len2 = short_swap_bytes(chunk2.len2); + } + subnode = mxmlFindElement(node, node, "color", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + chunk2.color1 = be32(strtoul(tempCoord, NULL, 16)); + chunk2.color2 = be32(strtoul(tempCoord+9, NULL, 16)); + } + u8 textyLength = short_swap_bytes(chunk2.len2); + if ((textyLength % 4) != 0) + textyLength += (4 - (textyLength % 4)); + unsigned char texty[textyLength]; + subnode = mxmlFindElement(node, node, "text", NULL, NULL, MXML_DESCEND); + if (subnode != NULL) + { + char tempCoord[256]; + get_value(subnode, tempCoord, 256); + //memcpy(texty, tempCoord, short_swap_bytes(chunk2.len2)); + ASCIIfromUnicode(texty, tempCoord, short_swap_bytes(chunk2.len2)); + } + fwrite(&chunk, sizeof(chunk), 1, fp); + *fileOffset = *fileOffset + sizeof(chunk); + + chunk2.name_offs=be32(0x74); + chunk2.pad[0]= 0;chunk2.pad[1]=0;chunk2.pad[2]=0; + fwrite(&chunk2, sizeof(chunk2), 1, fp); + *fileOffset = *fileOffset + sizeof(chunk2); + int q; for (q=short_swap_bytes(chunk2.len2);q 0) free(subs); + } + if ( memcmp(temp, grs1, sizeof(grs1)) == 0) + { + + } + if ( memcmp(temp, gre1, sizeof(gre1)) == 0) + { + + } + if ( memcmp(temp, pas1, sizeof(pas1)) == 0) + { + + } + if ( memcmp(temp, pae1, sizeof(pae1)) == 0) + { + + } + + *blobsize = *fileOffset - startOfChunk; } void WriteBRLYTHeader(brlyt_header rlythead, FILE* fp) { - brlyt_header writehead; - writehead.magic[0] = rlythead.magic[0]; - writehead.magic[1] = rlythead.magic[1]; - writehead.magic[2] = rlythead.magic[2]; - writehead.magic[3] = rlythead.magic[3]; - writehead.unk1 = be32(rlythead.unk1); - writehead.filesize = be32(rlythead.filesize); - writehead.lyt_offset = short_swap_bytes(rlythead.lyt_offset); - writehead.unk2 = short_swap_bytes(rlythead.unk2); - - fwrite(&writehead, sizeof(brlyt_header), 1, fp); + brlyt_header writehead; + writehead.magic[0] = rlythead.magic[0]; + writehead.magic[1] = rlythead.magic[1]; + writehead.magic[2] = rlythead.magic[2]; + writehead.magic[3] = rlythead.magic[3]; + writehead.unk1 = be32(rlythead.unk1); + writehead.filesize = be32(rlythead.filesize); + writehead.lyt_offset = short_swap_bytes(rlythead.lyt_offset); + writehead.unk2 = short_swap_bytes(rlythead.unk2); + + fwrite(&writehead, sizeof(brlyt_header), 1, fp); } void write_brlyt(char *infile, char *outfile) { - u32 timesIn = 0; - unsigned int fileOffset = 0; - FILE* fpx = fopen(infile, "r"); - if(fpx == NULL) { - printf("xmlyt couldn't be opened!\n"); - exit(1); - } - mxml_node_t *hightree = mxmlLoadFile(NULL, fpx, MXML_TEXT_CALLBACK); - if(hightree == NULL) { - printf("Couldn't open hightree!\n"); - exit(1); - } - mxml_node_t *tree = mxmlFindElement(hightree, hightree, "xmlyt", NULL, NULL, MXML_DESCEND); - if(hightree == NULL) { - printf("Couldn't get tree!\n"); - exit(1); - } - mxml_node_t *node; - FILE* fp = fopen(outfile, "wb+"); - if(fp == NULL) { - printf("destination brlyt couldn't be opened!\n"); - exit(1); - } - - u32 fileError = ferror(fp); - - u8* tagblob; - u32 blobsize; - u16 blobcount = 0; - u32 bloboffset; - brlyt_header rlythead; + u32 timesIn = 0; + unsigned int fileOffset = 0; + FILE* fpx = fopen(infile, "r"); + if(fpx == NULL) { + printf("xmlyt couldn't be opened!\n"); + exit(1); + } + mxml_node_t *hightree = mxmlLoadFile(NULL, fpx, MXML_TEXT_CALLBACK); + if(hightree == NULL) { + printf("Couldn't open hightree!\n"); + exit(1); + } + mxml_node_t *tree = mxmlFindElement(hightree, hightree, "xmlyt", NULL, NULL, MXML_DESCEND); + if(hightree == NULL) { + printf("Couldn't get tree!\n"); + exit(1); + } + mxml_node_t *node; + FILE* fp = fopen(outfile, "wb+"); + if(fp == NULL) { + printf("destination brlyt couldn't be opened!\n"); + exit(1); + } + + u32 fileError = ferror(fp); + + u8* tagblob; + u32 blobsize; + u16 blobcount = 0; + u32 bloboffset; + brlyt_header rlythead; rlythead.magic[0] = 'R'; rlythead.magic[1] = 'L'; rlythead.magic[2] = 'Y'; @@ -2871,65 +2871,65 @@ void write_brlyt(char *infile, char *outfile) rlythead.lyt_offset = sizeof(brlyt_header); rlythead.unk2 = 1; WriteBRLYTHeader(rlythead, fp); - char temp[256]; + char temp[256]; - fileOffset += sizeof(brlyt_header); + fileOffset += sizeof(brlyt_header); - u32 numberOfEntries; + u32 numberOfEntries; - for(node = mxmlFindElement(tree, tree, "tag", NULL, NULL, MXML_DESCEND); node != NULL; node = mxmlFindElement(node, tree, "tag", NULL, NULL, MXML_DESCEND)) { + for(node = mxmlFindElement(tree, tree, "tag", NULL, NULL, MXML_DESCEND); node != NULL; node = mxmlFindElement(node, tree, "tag", NULL, NULL, MXML_DESCEND)) { - char tempType[4]; - if(mxmlElementGetAttr(node, "type") != NULL) - strcpy(tempType, mxmlElementGetAttr(node, "type")); - else{ - printf("No type attribute found!\n"); - exit(1); - } + char tempType[4]; + if(mxmlElementGetAttr(node, "type") != NULL) + strcpy(tempType, mxmlElementGetAttr(node, "type")); + else{ + printf("No type attribute found!\n"); + exit(1); + } - unsigned int chunkHeaderOffset = fileOffset; + unsigned int chunkHeaderOffset = fileOffset; - brlyt_entry_header chunk; - chunk.magic[0]=tempType[0]; - chunk.magic[1]=tempType[1]; - chunk.magic[2]=tempType[2]; - chunk.magic[3]=tempType[3]; - chunk.length = 0; + brlyt_entry_header chunk; + chunk.magic[0]=tempType[0]; + chunk.magic[1]=tempType[1]; + chunk.magic[2]=tempType[2]; + chunk.magic[3]=tempType[3]; + chunk.length = 0; - fwrite(&chunk, sizeof(chunk), 1, fp); + fwrite(&chunk, sizeof(chunk), 1, fp); - fileOffset += sizeof(chunk); + fileOffset += sizeof(chunk); - WriteBRLYTEntry(tree, node, &tagblob, &blobsize, tempType, fp, &fileOffset); + WriteBRLYTEntry(tree, node, &tagblob, &blobsize, tempType, fp, &fileOffset); - chunk.length = be32(blobsize + sizeof(chunk)); + chunk.length = be32(blobsize + sizeof(chunk)); - fseek(fp, chunkHeaderOffset, SEEK_SET); - fwrite(&chunk, sizeof(chunk), 1, fp); - fseek(fp, fileOffset, SEEK_SET); + fseek(fp, chunkHeaderOffset, SEEK_SET); + fwrite(&chunk, sizeof(chunk), 1, fp); + fseek(fp, fileOffset, SEEK_SET); - numberOfEntries++; + numberOfEntries++; - blobcount++; + blobcount++; - } + } - rlythead.filesize = fileOffset; - rlythead.unk2 = blobcount; - fseek(fp, 0, SEEK_SET); - WriteBRLYTHeader(rlythead, fp); + rlythead.filesize = fileOffset; + rlythead.unk2 = blobcount; + fseek(fp, 0, SEEK_SET); + WriteBRLYTHeader(rlythead, fp); - fclose(fpx); - fclose(fp); + fclose(fpx); + fclose(fp); } void make_brlyt(char* infile, char* outfile) { - printf("\x1b[33mParsing XMLYT @ \x1b[0m%s.\n", infile); - write_brlyt(infile, outfile); - free(materials); - free(textures); - printf("\x1b[34mParsing XMLYT @ \x1b[0m%s complete.\n", infile); + printf("\x1b[33mParsing XMLYT @ \x1b[0m%s.\n", infile); + write_brlyt(infile, outfile); + free(materials); + free(textures); + printf("\x1b[34mParsing XMLYT @ \x1b[0m%s complete.\n", infile); } -- cgit v1.3.1