extractpld.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include "common.h"
  2. #include "devil1pld.h"
  3. #define TYPE_ID_LENGTH 4
  4. bool extractpld(const char *filedata,
  5. unsigned int filesize,
  6. const char *filename) {
  7. if (filedata == NULL || filesize <= 0 || filename == NULL) {
  8. return false;
  9. }
  10. struct PldHeader h;
  11. DEVIL1PLD.getheader(&h, filedata);
  12. char *fn = NULL;
  13. fn = (char*)malloc(strlen(filename) + 3 + 4);
  14. int size = 0;
  15. unsigned int i = 0;
  16. char textureid[TYPE_ID_LENGTH] = {'\0', '2', '3', 'T'};
  17. for (i = 0; i < h.numOffset; i++) {
  18. const char * currentfile = filedata + h.offsets[i];
  19. size = DEVIL1PLD.sizeofsector(&h, i, filesize);
  20. if (strncmp( currentfile, textureid, TYPE_ID_LENGTH ) == 0)
  21. sprintf(fn, "%s_%d.txp", filename, i);
  22. else
  23. sprintf(fn, "%s_%d", filename, i);
  24. write(fn, currentfile, size);
  25. }
  26. free(fn);
  27. return true;
  28. }
  29. int main(int argc, char ** argv) {
  30. char *f = argv[1];
  31. unsigned int bufsize = 0;
  32. char *buffer = loadfile(f, &bufsize);
  33. extractpld(buffer, bufsize, f);
  34. free(buffer);
  35. return 0;
  36. }