Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * tpkTool.c
- * by Reisyukaku
- *
- * Quick and dirty parser for TPK/BIN file pairs in Senran Kagura: EV
- */
- #include <stdio.h>
- #include <stdint.h>
- #include <malloc.h>
- #include <string.h>
- typedef uint8_t u8;
- typedef uint32_t u32;
- typedef uint64_t u64;
- int main(int argc, char **argv){
- if(argc < 3){
- printf("Usage: %s <ChunkX.bin> <ChunkX.tpk>\n", argv[0]);
- return -1;
- }
- FILE *bin;
- FILE *tpk;
- FILE *out;
- size_t fileSizeBin = 0,
- fileSizeTpk = 0;
- u64 *bufBin;
- u8 *bufTpk;
- u64 fileEntries = 0;
- bin = fopen(argv[1], "rb");
- tpk = fopen(argv[2], "rb");
- if(!bin || !tpk){
- printf("Files couldn't be found!\n");
- fclose(bin);
- fclose(tpk);
- return -1;
- }
- fseek(bin, 0, SEEK_END);
- fseek(tpk, 0, SEEK_END);
- fileSizeBin = ftell(bin);
- fileSizeTpk = ftell(tpk);
- fseek(bin, 0, SEEK_SET);
- fseek(tpk, 0, SEEK_SET);
- bufBin = malloc(fileSizeBin);
- fread(bufBin, 8, fileSizeBin/8, bin);
- fclose(bin);
- fileEntries = bufBin[1];
- printf("Entries: 0x%08X\n\n", fileEntries);
- u32 entrySize = 0,
- entryStart = 0;
- char newFilename[0x20];
- int i; for(i = 0; i < fileEntries; i+=2){
- entrySize = bufBin[2+i]; //Table starts after 0x10 bytes
- entryStart = bufBin[2+(i+1)];
- printf("File @ 0x%08X [0x%08X bytes]\n", entryStart, entrySize);
- if(entrySize > 0){ //For some reason some entries are not proper entries
- //Create buffer with file data
- bufTpk = malloc(entrySize);
- fseek(tpk, entryStart, SEEK_SET);
- fread(bufTpk, 1, entrySize, tpk);
- //Create output file name
- memset(newFilename, 0, 0x20);
- snprintf(newFilename, 0x20, "file_%04d[0x%08X].bin", i/2, entryStart); //For the record, the real names of each file is defined in fnames.bin (see fnames.c)
- //Open and write new file
- out = fopen(newFilename, "wb");
- if(!out){
- printf("File couldn't be created!\n");
- return -1;
- }
- fwrite(bufTpk, 1, entrySize, out);
- //Finish up
- fclose(out);
- free(bufTpk);
- }
- }
- free(bufBin);
- fclose(tpk);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement