I wrote this but never used it for anything so I'm not 100% sure if it is all correct:
<?php
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
// PTH format header
typedef struct {
char LFSPTH[6];
unsigned char version;
unsigned char revision;
int numNodes;
int finishLine;
} PTHHEADER;
// PTH format block
typedef struct {
int cX, cY, cZ; // Centre
float dirX, dirY, dirZ; // Dir
float limitLeft, limitRight;
float driveLeft, driveRight;
} NODEBLOCK;
// PTH file
typedef struct {
PTHHEADER header;
NODEBLOCK *nodes;
bool loaded;
} PTHFILE;
#define fptof(x) (float) x/65536
// Loads a pth file or releases if fname = null
bool loadPTH(PTHFILE* pthf, char *fname) {
// Release memory if loaded
if(pthf->loaded && pthf->nodes != NULL) {
delete[] pthf->nodes;
pthf->nodes = NULL;
pthf->loaded = false;
}
if(!fname)
return false;
// Open file
FILE *f = fopen(fname, "rb");
if(!f)
return false;
// Load header
fread(&pthf->header, sizeof(PTHHEADER), 1, f);
if(strcmp(pthf->header.LFSPTH, "LFSPTH")) {
// Not a pth file? TODO: add more checking here (file size etc.)
fclose(f);
return false;
}
// Allocate memory & load nodes
pthf->nodes = new NODEBLOCK[pthf->header.numNodes];
for(int i=0;i<pthf->header.numNodes;i++)
fread(&pthf->nodes[i], sizeof(NODEBLOCK), 1, f);
pthf->loaded = true;
fclose(f);
return true;
}
void main(void) {
PTHFILE pthf;
pthf.loaded = false;
if(!loadPTH(&pthf, "FE1.pth")) {
printf("Cant load PTH\n");
return;
}
printf("PTH loaded, numnodes: %d, finishline: %d\n", pthf.header.numNodes, pthf.header.finishLine);
for(int i=0;i<pthf.header.numNodes;i++) {
NODEBLOCK* n = &pthf.nodes[i];
printf(" - node %04d: c(%.2f %.2f %.2f) dir(%.2f %.2f %.2f)\n", i, fptof(n->cX), fptof(n->cY), fptof(n->cZ), n->dirX, n->dirY, n->dirZ);
printf(" limit(%.2f %.2f) drive(%.2f %.2f)\n", n->limitLeft, n->limitRight, n->driveLeft, n->driveRight);
}
// Release memory
loadPTH(&pthf, NULL);
}
?>