mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2024-11-26 00:38:55 +05:30
Added function that determines size of pld section
This commit is contained in:
parent
c9e4e99f1a
commit
0ea47e44c3
@ -17,6 +17,10 @@ struct PldHeader {
|
|||||||
// * = pass by reference of a struct PldHeader
|
// * = pass by reference of a struct PldHeader
|
||||||
bool getpldh(struct PldHeader*, const char*);
|
bool getpldh(struct PldHeader*, const char*);
|
||||||
|
|
||||||
|
// input: pointer to header, index of offset, filesize
|
||||||
|
// * = pass by reference of a struct PldHeader
|
||||||
|
int sizeofpldstruct(struct PldHeader*, unsigned int, unsigned int);
|
||||||
|
|
||||||
// input: a pld header struct.
|
// input: a pld header struct.
|
||||||
// * = pass by reference of a struct PldHeader
|
// * = pass by reference of a struct PldHeader
|
||||||
void printpldh(struct PldHeader*);
|
void printpldh(struct PldHeader*);
|
||||||
|
@ -11,6 +11,24 @@ bool getpldh(struct PldHeader *ph, const char *filedata) {
|
|||||||
return good;
|
return good;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// determine the size of the i-th pld structure
|
||||||
|
int sizeofpldstruct(struct PldHeader *ph, unsigned int i, unsigned int max) {
|
||||||
|
unsigned int size = -1;
|
||||||
|
if (ph == NULL) {
|
||||||
|
fprintf(stderr, "Error: given null pointer\n");
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
if (i > ph -> numOffset) {
|
||||||
|
fprintf(stderr, "Error: i exceeds pldHeader -> numOffset\n");
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
unsigned int start = 0, end = 0;
|
||||||
|
start = ph -> offsets[i];
|
||||||
|
end = (i == (ph -> numOffset) - 1) ? max : ph -> offsets[i + 1];
|
||||||
|
size = end - start;
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
void printpldh(struct PldHeader *ph) {
|
void printpldh(struct PldHeader *ph) {
|
||||||
if (ph == NULL) {
|
if (ph == NULL) {
|
||||||
return;
|
return;
|
||||||
|
11
test/main.c
11
test/main.c
@ -96,7 +96,12 @@ bool unpackpld(const char *filedata,
|
|||||||
struct PldHeader h;
|
struct PldHeader h;
|
||||||
if (filedata != NULL && filesize > 0) {
|
if (filedata != NULL && filesize > 0) {
|
||||||
getpldh(&h, filedata);
|
getpldh(&h, filedata);
|
||||||
printpldh(&h);
|
}
|
||||||
|
int size = 0;
|
||||||
|
unsigned int i = 0;
|
||||||
|
for (i = 0; i < h.numOffset; i++) {
|
||||||
|
size = sizeofpldstruct(&h, i, filesize);
|
||||||
|
printf("%x\n", size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,8 +157,8 @@ int main(int argc, char ** argv) {
|
|||||||
char *f = argv[1];
|
char *f = argv[1];
|
||||||
unsigned int bufsize = 0;
|
unsigned int bufsize = 0;
|
||||||
char *buffer = loadfile(f, &bufsize);
|
char *buffer = loadfile(f, &bufsize);
|
||||||
// unpackpld(buffer, bufsize, f);
|
unpackpld(buffer, bufsize, f);
|
||||||
exporttextures(buffer, bufsize, f);
|
// exporttextures(buffer, bufsize, f);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user