Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Pokemon Sun & Moon map Vec4 parser
- * by Rei
- */
- #include <stdio.h>
- #include <malloc.h>
- #include <string.h>
- int main(int argc, char **argv){
- if(argc < 2){
- printf("Usage: %s <file>\n", argv[0]);
- return 1;
- }
- //Read file
- unsigned *magic = malloc(sizeof(unsigned));
- unsigned *entries = malloc(sizeof(unsigned));
- float *buffer;
- unsigned fileSize = 0;
- FILE *fp;
- fp = fopen(argv[1], "rb");
- fseek(fp, 0, SEEK_END);
- fileSize = ftell(fp);
- fseek(fp, 0, SEEK_SET);
- buffer = malloc(fileSize-8);
- fread(magic, sizeof(unsigned), 1, fp);
- fread(entries, sizeof(unsigned), 1, fp);
- fread(buffer, sizeof(unsigned), (fileSize-8)/4, fp);
- fclose(fp);
- //Parse file
- printf("Magic: %X\n", *magic);
- printf("Entries: %d\n", *entries);
- int i, pos;
- for(i = 0, pos = 0; i < *entries; i++, pos+=0x12){
- printf("\n"
- "X=%.3f, Y=%.3f, Z=%.3f, W=%.3f\n"
- "X=%.3f, Y=%.3f, Z=%.3f, W=%.3f\n"
- "X=%.3f, Y=%.3f, Z=%.3f, W=%.3f\n",
- buffer[pos], buffer[pos+1], buffer[pos+2], buffer[pos+3],
- buffer[pos+4], buffer[pos+5], buffer[pos+6], buffer[pos+7],
- buffer[pos+8], buffer[pos+9], buffer[pos+10], buffer[pos+11]
- );
- }
- //Write SMD
- FILE *smd;
- smd = fopen("C:\\test.smd", "w");
- char *header = "version 1\nnodes\nend\nskeleton\ntime 0\nend\ntriangles\n";
- fwrite(header, sizeof(char), strlen(header), smd);
- for(i = 0, pos = 0; i < *entries; i++, pos+=0x12){
- char entry[0x100] = {0};
- snprintf(entry, 0x100,
- "my_material\n"
- "0 %.3f %.3f %.3f\t0 0 0\t0 0\t0 0 0\n"
- "0 %.3f %.3f %.3f\t0 0 0\t0 0\t0 0 0\n"
- "0 %.3f %.3f %.3f\t0 0 0\t0 0\t0 0 0\n",
- buffer[pos], buffer[pos+1], buffer[pos+2],
- buffer[pos+4], buffer[pos+5], buffer[pos+6],
- buffer[pos+8], buffer[pos+9], buffer[pos+10]
- );
- fwrite(entry, sizeof(char), strlen(entry), smd);
- }
- fwrite("end", sizeof(char), strlen("end"), smd);
- fclose(smd);
- free(magic);
- free(entries);
- free(buffer);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement