diff --git a/Makefile b/Makefile index 23ac41f..f945ff5 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ CFLAGS= -I"include" all: main -main: devil1pld.o devil1tex.o +main: devil1pld.o devil1tex.o src/devil1geo.o $(CC) $^ test/main.c $(CFLAGS) -o $(EX) devil1pld.o: src/devil1pld.c @@ -13,5 +13,8 @@ devil1pld.o: src/devil1pld.c devil1tex.o: src/devil1tex.c $(CC) -c $^ $(CFLAGS) +devil1geo.o: src/devil1geo.c + $(CC) -c $^ $(CFLAGS) + clean: rm *.o $(EX) diff --git a/include/devil1geo.h b/include/devil1geo.h index 8d07d1c..9f62e84 100644 --- a/include/devil1geo.h +++ b/include/devil1geo.h @@ -2,7 +2,10 @@ #ifndef DEVIL1GEO_H #define DEVIL1GEO_H #include -#pragma pack(1) +#include + + +#pragma pack(push, 1) struct Header { unsigned char numMesh; unsigned char unknownNumberB; @@ -12,7 +15,7 @@ struct Header { uint64_t unknownOffset; }; -struct MeshHeaders { +struct MeshHeader { int16_t numBatch; int16_t numVertex; uint32_t u; // @@ -39,6 +42,7 @@ struct BoneIndexes { struct BoneWeights { uint16_t weights; // }; +#pragma pack(pop) // This is where most of the parsing will be. // this struct is in-order of what the file format will have. @@ -65,5 +69,9 @@ struct Mesh { struct Batch b; }; +void printgheader(struct Header*); + +bool getmeshheaders(struct MeshHeader **, const char *, unsigned int); + #endif diff --git a/test/main.c b/test/main.c index 62ca3ac..6a89535 100644 --- a/test/main.c +++ b/test/main.c @@ -5,6 +5,7 @@ #include "devil1pld.h" #include "devil1tex.h" +#include "devil1geo.h" char *loadfile(const char *fname, unsigned int *s) { FILE *f = fopen(fname, "rb"); @@ -104,12 +105,33 @@ void exporttextures(const char *filedata, return; } +void extractmeshes(const char* filedata, + unsigned int filesize, + const char *filename) { + if (filedata == NULL || filesize <= 0) { + return; + } + struct Header *h = NULL; + h = (struct Header*)filedata; + printf("pointer %x\n", h); + printgheader(h); + struct MeshHeader **mh = NULL; + mh = (struct MeshHeader**) + malloc(sizeof(struct MeshHeader*) * h -> numMesh); + getmeshheaders(mh, filedata, filesize); + unsigned int i; + for (i = 0; i < h -> numMesh; i++) { + printf("returning %x \n", mh[i]); + } +} + int main(int argc, char ** argv) { char *f = argv[1]; unsigned int bufsize = 0; char *buffer = loadfile(f, &bufsize); - unpackpld(buffer, bufsize, f); +// unpackpld(buffer, bufsize, f); // exporttextures(buffer, bufsize, f); + extractmeshes(buffer, bufsize, f); free(buffer); return 0; }