mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2024-11-22 13:53:02 +05:30
Identify texture packs, add .txp
This commit is contained in:
parent
b18e6fe486
commit
e3f942e3d7
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,6 +3,7 @@
|
|||||||
*.exe
|
*.exe
|
||||||
*.stackdump
|
*.stackdump
|
||||||
*.log
|
*.log
|
||||||
|
devil1test
|
||||||
|
|
||||||
# Test files
|
# Test files
|
||||||
*.dds
|
*.dds
|
||||||
|
20
test/main.c
20
test/main.c
@ -6,6 +6,13 @@
|
|||||||
#include "devil1pld.h"
|
#include "devil1pld.h"
|
||||||
#include "devil1tex.h"
|
#include "devil1tex.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define TYPE_ID_LENGTH 4
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
char *loadfile(const char *fname, unsigned int *s) {
|
char *loadfile(const char *fname, unsigned int *s) {
|
||||||
FILE *f = fopen(fname, "rb");
|
FILE *f = fopen(fname, "rb");
|
||||||
unsigned int size = 0; // number of elements to buffer;
|
unsigned int size = 0; // number of elements to buffer;
|
||||||
@ -14,7 +21,7 @@ char *loadfile(const char *fname, unsigned int *s) {
|
|||||||
perror("Error 1: ");
|
perror("Error 1: ");
|
||||||
return NULL;
|
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);
|
fseek(f, 0, SEEK_END);
|
||||||
size = ftell(f);
|
size = ftell(f);
|
||||||
rewind(f);
|
rewind(f);
|
||||||
@ -64,10 +71,17 @@ bool unpackpld(const char *filedata,
|
|||||||
fn = (char*)malloc(strlen(filename) + 3 + 4);
|
fn = (char*)malloc(strlen(filename) + 3 + 4);
|
||||||
int size = 0;
|
int size = 0;
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
|
char filetype[TYPE_ID_LENGTH];
|
||||||
|
char filetypetexture[TYPE_ID_LENGTH] = {'\0', '2', '3', 'T'};
|
||||||
for (i = 0; i < h.numOffset; i++) {
|
for (i = 0; i < h.numOffset; i++) {
|
||||||
|
const char * currentfile = filedata + h.offsets[i];
|
||||||
size = sizeofpldstruct(&h, i, filesize);
|
size = sizeofpldstruct(&h, i, filesize);
|
||||||
sprintf(fn, "%s_%d", filename, i);
|
memcpy(filetype, currentfile, TYPE_ID_LENGTH);
|
||||||
write(fn, filedata + h.offsets[i], size);
|
if (strcmp( filetype, filetypetexture ) == 0)
|
||||||
|
sprintf(fn, "%s_%d.txp", filename, i);
|
||||||
|
else
|
||||||
|
sprintf(fn, "%s_%d", filename, i);
|
||||||
|
write(fn, currentfile, size);
|
||||||
}
|
}
|
||||||
free(fn);
|
free(fn);
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user