Merge branch 'feature-IdentifyTexture' of scuti/lib3ddevil1 into master

This commit is contained in:
scuti 2018-04-09 21:24:24 -07:00 committed by Gitea
commit 7042060fb5
2 changed files with 16 additions and 3 deletions

1
.gitignore vendored
View File

@ -3,6 +3,7 @@
*.exe
*.stackdump
*.log
devil1test
# Test files
*.dds

View File

@ -6,6 +6,13 @@
#include "devil1pld.h"
#include "devil1tex.h"
#define TYPE_ID_LENGTH 4
char *loadfile(const char *fname, unsigned int *s) {
FILE *f = fopen(fname, "rb");
unsigned int size = 0; // number of elements to buffer;
@ -14,7 +21,7 @@ char *loadfile(const char *fname, unsigned int *s) {
perror("Error 1: ");
return NULL;
}
// this method of determining file size doesn't work until 2 GB.
// this method of determining file size works up to 2 GB.
fseek(f, 0, SEEK_END);
size = ftell(f);
rewind(f);
@ -64,10 +71,15 @@ bool unpackpld(const char *filedata,
fn = (char*)malloc(strlen(filename) + 3 + 4);
int size = 0;
unsigned int i = 0;
char textureid[TYPE_ID_LENGTH] = {'\0', '2', '3', 'T'};
for (i = 0; i < h.numOffset; i++) {
const char * currentfile = filedata + h.offsets[i];
size = sizeofpldstruct(&h, i, filesize);
sprintf(fn, "%s_%d", filename, i);
write(fn, filedata + h.offsets[i], size);
if (strncmp( currentfile, textureid, TYPE_ID_LENGTH ) == 0)
sprintf(fn, "%s_%d.txp", filename, i);
else
sprintf(fn, "%s_%d", filename, i);
write(fn, currentfile, size);
}
free(fn);
return true;