mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2024-11-26 00:38:55 +05:30
55 lines
1.4 KiB
C
55 lines
1.4 KiB
C
#include "devil1pld.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
/* struct PldHeader *getpldh(const char *filedata) {
|
|
if (filedata == NULL) {
|
|
return NULL;
|
|
}
|
|
int32_t *n = (int32_t*)filedata;
|
|
struct PldHeader *ph = (struct PldHeader*)malloc(
|
|
sizeof(struct PldHeader)
|
|
);
|
|
uint32_t size_offsets = sizeof(uint32_t) * n[0];
|
|
ph -> offsets = (uint32_t*)malloc(size_offsets);
|
|
if (ph -> offsets == NULL) {
|
|
perror("Error 4: ");
|
|
free(ph);
|
|
free(ph -> offsets);
|
|
return NULL;
|
|
}
|
|
// set data of struct.
|
|
ph -> numOffset = n[0];
|
|
memcpy(ph -> offsets, filedata + sizeof(int32_t), size_offsets);
|
|
return ph;
|
|
} */
|
|
|
|
void destroypldh(struct PldHeader *ph) {
|
|
free(ph -> offsets);
|
|
free(ph);
|
|
ph = NULL;
|
|
}
|
|
|
|
bool getpldh(struct PldHeader *ph, const char *filedata) {
|
|
bool good = false;
|
|
if (ph != NULL && filedata != NULL) {
|
|
ph -> numOffset = (int32_t)filedata[0];
|
|
ph -> offsets = (uint32_t*)(filedata + sizeof(int32_t));
|
|
good = true;
|
|
}
|
|
return good;
|
|
}
|
|
|
|
void printpldh(struct PldHeader *ph) {
|
|
if (ph == NULL) {
|
|
return;
|
|
}
|
|
printf("number of offsets = %i\n", ph -> numOffset);
|
|
printf("offsets = %x\n", ph -> offsets);
|
|
unsigned int i;
|
|
for (i = 0; i < ph -> numOffset; i++) {
|
|
printf("offset %i = %x\n", i, ph -> offsets[i]);
|
|
}
|
|
}
|