mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2024-11-22 13:53:02 +05:30
Added header for .pld and main that correctly reads it in
This commit is contained in:
parent
1ba3b35dc1
commit
a67fa5a952
@ -1,14 +1,15 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifndef DEVIL1GEO_H
|
||||
#define DEVIL1GEO_H
|
||||
#include <stdint.h>
|
||||
#pragma pack(1)
|
||||
struct Header {
|
||||
char numMesh;
|
||||
char unknownNumberB;
|
||||
char unknownNumberC;
|
||||
char unknownNumberD;
|
||||
unsigned char numMesh;
|
||||
unsigned char unknownNumberB;
|
||||
unsigned char unknownNumberC;
|
||||
unsigned char unknownNumberD;
|
||||
uint32_t padding; // <format=hex>
|
||||
uint64_t unknowOffset;
|
||||
uint64_t unknownOffset;
|
||||
};
|
||||
|
||||
struct MeshHeaders {
|
||||
@ -40,7 +41,7 @@ struct BoneWeights {
|
||||
};
|
||||
|
||||
// This is where most of the parsing will be.
|
||||
// this struct is in-order of what the file format wil have.
|
||||
// this struct is in-order of what the file format will have.
|
||||
struct Batch {
|
||||
int16_t numVertex;
|
||||
int16_t uB;
|
||||
@ -64,12 +65,5 @@ struct Mesh {
|
||||
struct Batch b;
|
||||
};
|
||||
|
||||
// just for now
|
||||
// need to separate file operation from the lib later
|
||||
bool readin(const char *fname) {
|
||||
;
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
;
|
||||
}
|
12
devil1pld.h
Normal file
12
devil1pld.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef DEVIL1PLD_H
|
||||
#define DEVIL1PLD_H
|
||||
|
||||
#include <stdint.h>
|
||||
#pragma pack(1)
|
||||
struct PldHeader {
|
||||
int32_t numOffset;
|
||||
// array of numOffset elements
|
||||
uint32_t *offsets; // <format=hex>
|
||||
};
|
||||
|
||||
#endif
|
75
main.c
Normal file
75
main.c
Normal file
@ -0,0 +1,75 @@
|
||||
#include "devil1pld.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
void disp_pldheader(struct PldHeader *x) {
|
||||
printf("number of offsets = %i\n", x -> numOffset);
|
||||
unsigned int i;
|
||||
for (i = 0; i < x -> numOffset; i++) {
|
||||
printf("offset %i = %x\n", i, x -> offsets[i]);
|
||||
}
|
||||
}
|
||||
|
||||
bool read_pldheader(const char *buffer) {
|
||||
int32_t *n = (int32_t*)buffer;
|
||||
struct PldHeader *ph = (struct PldHeader*)malloc(1);
|
||||
unsigned int 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 false;
|
||||
}
|
||||
// set data of struct.
|
||||
ph -> numOffset = n[0];
|
||||
memcpy(ph -> offsets, buffer + sizeof(int32_t), size_offsets);
|
||||
disp_pldheader(ph);
|
||||
free(ph -> offsets);
|
||||
free(ph);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool readpld(const char *fname) {
|
||||
FILE *f = fopen(fname, "rb");
|
||||
char *buffer = NULL;
|
||||
unsigned int size = 0; // number of elements to buffer;
|
||||
unsigned int rcnt = 0; // number of char's read by fread(...)
|
||||
if (f == NULL) {
|
||||
perror("Error 1: ");
|
||||
return false;
|
||||
}
|
||||
// this method of determining file size doesn't work until 2 GB.
|
||||
fseek(f, 0, SEEK_END);
|
||||
size = ftell(f);
|
||||
rewind(f);
|
||||
buffer = (char*)malloc(sizeof(char) * size);
|
||||
if (buffer == NULL) {
|
||||
perror("Error 2: ");
|
||||
free(buffer);
|
||||
return false;
|
||||
}
|
||||
rcnt = fread(buffer, sizeof(char), size, f);
|
||||
if (rcnt < size) {
|
||||
perror("Error 3: ");
|
||||
free(buffer);
|
||||
return false;
|
||||
}
|
||||
read_pldheader(buffer);
|
||||
fclose(f);
|
||||
free(buffer);
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
char *filename = argv[1];
|
||||
bool status = readpld(filename);
|
||||
if (status) {
|
||||
printf("Read OK");
|
||||
} else {
|
||||
printf("Read not-OK");
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user