Advertisement
Reisyukaku

[SK Estival Versus] tpkTool.c

Sep 8th, 2016
1,042
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.37 KB | None | 0 0
  1. /*
  2. *   tpkTool.c
  3. *       by Reisyukaku
  4. *
  5. *   Quick and dirty parser for TPK/BIN file pairs in Senran Kagura: EV
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <stdint.h>
  10. #include <malloc.h>
  11. #include <string.h>
  12.  
  13. typedef uint8_t u8;
  14. typedef uint32_t u32;
  15. typedef uint64_t u64;
  16.  
  17. int main(int argc, char **argv){
  18.     if(argc < 3){
  19.         printf("Usage: %s <ChunkX.bin> <ChunkX.tpk>\n", argv[0]);
  20.         return -1;
  21.     }
  22.    
  23.     FILE *bin;
  24.     FILE *tpk;
  25.     FILE *out;
  26.     size_t fileSizeBin = 0,
  27.            fileSizeTpk = 0;
  28.     u64 *bufBin;
  29.     u8 *bufTpk;
  30.     u64 fileEntries = 0;
  31.    
  32.     bin = fopen(argv[1], "rb");
  33.     tpk = fopen(argv[2], "rb");
  34.     if(!bin || !tpk){
  35.         printf("Files couldn't be found!\n");
  36.         fclose(bin);
  37.         fclose(tpk);
  38.         return -1;
  39.     }
  40.    
  41.     fseek(bin, 0, SEEK_END);
  42.     fseek(tpk, 0, SEEK_END);
  43.     fileSizeBin = ftell(bin);
  44.     fileSizeTpk = ftell(tpk);
  45.     fseek(bin, 0, SEEK_SET);
  46.     fseek(tpk, 0, SEEK_SET);
  47.    
  48.     bufBin = malloc(fileSizeBin);
  49.     fread(bufBin, 8, fileSizeBin/8, bin);
  50.    
  51.     fclose(bin);
  52.    
  53.     fileEntries = bufBin[1];
  54.     printf("Entries: 0x%08X\n\n", fileEntries);
  55.     u32 entrySize = 0,
  56.              entryStart = 0;
  57.     char newFilename[0x20];
  58.     int i; for(i = 0; i < fileEntries; i+=2){
  59.         entrySize = bufBin[2+i]; //Table starts after 0x10 bytes
  60.         entryStart = bufBin[2+(i+1)];
  61.         printf("File @ 0x%08X [0x%08X bytes]\n", entryStart, entrySize);
  62.         if(entrySize > 0){       //For some reason some entries are not proper entries
  63.             //Create buffer with file data
  64.             bufTpk = malloc(entrySize);
  65.             fseek(tpk, entryStart, SEEK_SET);
  66.             fread(bufTpk, 1, entrySize, tpk);
  67.             //Create output file name
  68.             memset(newFilename, 0, 0x20);
  69.             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)
  70.             //Open and write new file
  71.             out = fopen(newFilename, "wb");
  72.             if(!out){
  73.                 printf("File couldn't be created!\n");
  74.                 return -1;
  75.             }
  76.             fwrite(bufTpk, 1, entrySize, out);
  77.             //Finish up
  78.             fclose(out);
  79.             free(bufTpk);
  80.         }
  81.     }
  82.     free(bufBin);
  83.     fclose(tpk);
  84.    
  85.     return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement