mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2025-05-31 14:11:42 +05:30
Added texture pack headers correctly read in
This commit is contained in:
54
src/devil1tex.c
Normal file
54
src/devil1tex.c
Normal file
@@ -0,0 +1,54 @@
|
||||
#include "devil1tex.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
// get texture pack header
|
||||
void gettph (struct TexturePack *tp, const char *filedata) {
|
||||
// Assume the Texture Pack Header is already allocated memory.
|
||||
if (tp != NULL && filedata != NULL) {
|
||||
memcpy(tp, filedata, sizeof(struct TexturePack));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void printtph (struct TexturePack *tp) {
|
||||
if (tp != NULL) {
|
||||
printf("id: \t %c %c %c %c \n", tp -> id[3],
|
||||
tp -> id[2],
|
||||
tp -> id[1],
|
||||
tp -> id[0]);
|
||||
printf("batch#: \t %i \n", tp -> batchNumber);
|
||||
printf("1st batch: \t %i \n", tp -> firstBatchOffset);
|
||||
printf("unknownA: \t %i\n", tp -> unknownA);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// get texture pack descriptors
|
||||
void gettbd (struct TextureBatchDescriptor *tbd,
|
||||
struct TexturePack* tph,
|
||||
const char *filedata,
|
||||
unsigned int filesize) {
|
||||
if (tbd == NULL || tph == NULL || filedata == NULL) {
|
||||
// any of these being null will cause segmentation fault.
|
||||
return;
|
||||
}
|
||||
// do some checks regarding the header
|
||||
if (tph -> firstBatchOffset >= filesize ||
|
||||
tph -> firstBatchOffset <= 0) {
|
||||
return;
|
||||
}
|
||||
unsigned int index = tph -> firstBatchOffset;
|
||||
// Batch Descriptors are structured one after another.
|
||||
// therefore the next one is at
|
||||
// current index + sizeof(TextureBatchDescriptor)
|
||||
unsigned int i = 0;
|
||||
do {
|
||||
index += (sizeof(struct TextureBatchDescriptor) * i);
|
||||
printf("batch descriptor start: %x\n", index);
|
||||
tbd = (struct TextureBatchDescriptor*)(filedata + index);
|
||||
// <do something with the batch descriptor found>
|
||||
} while(i < (tph -> batchNumber));
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user