Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // © Copyright Dasda 2008
- // Thanks to StoneWood.
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <unistd.h>
- #include <string.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include "tools.h"
- int file_len(FILE *f)
- {
- int pos;
- int end;
- pos = ftell (f);
- fseek (f, 0, SEEK_END);
- end = ftell (f);
- fseek (f, pos, SEEK_SET);
- return end;
- }
- int main(int argc, char* argv[])
- {
- printf("-----------------------------------------------------\n");
- printf(" DisPac, .PAC extractor (from SMBB) written by dasda\n");
- printf("-----------------------------------------------------\n");
- if(argc == 2)
- {
- FILE* fileIn = fopen(argv[1], "rb");
- if(!fileIn)
- {
- printf("File cannot be found.\n");
- exit(1);
- }
- int fileIn_len = file_len(fileIn);
- u8* fileIn_buf = (u8*) malloc(fileIn_len);
- fread(fileIn_buf, fileIn_len, 1, fileIn);
- if(strncmp(fileIn_buf, "ARC", 3) != 0)
- {
- printf("File isn't a PAC.\n");
- exit(1);
- }
- int fileOut_name_len = strlen(fileIn_buf + 0x10);
- char* fileOut_name_buf = malloc(fileOut_name_len + 20); // For file extension.
- strcpy(fileOut_name_buf, fileIn_buf + 0x10);
- // Different file types.
- u8 fileOut_type = 0;
- memcpy(&fileOut_type, fileIn_buf + 0x7, 1);
- if(fileOut_type == 0x6 || fileOut_type == 0x3)
- strcat(fileOut_name_buf, ".brres");
- else if(fileOut_type == 0x2)
- strcat(fileOut_name_buf, ".bmg");
- else
- strcat(fileOut_name_buf, ".unk");
- printf("File type: %x\n", fileOut_type);
- printf("Writing to file: %s\n", fileOut_name_buf);
- FILE* fileOut = fopen(fileOut_name_buf, "wb");
- if(!fileOut)
- {
- printf("Cannot open file for writing.\n");
- exit(1);
- }
- fwrite(fileIn_buf + 0x60, fileIn_len - 0x60, 1, fileOut);
- // Free stuff. :)
- free(fileIn_buf);
- free(fileOut_name_buf);
- }
- else printf("Usage: DisPac <File>\n");
- }
Add Comment
Please, Sign In to add comment