diff options
| author | johannes <johannes.herman@gmail.com> | 2024-01-31 10:01:01 +0100 |
|---|---|---|
| committer | johannes <johannes.herman@gmail.com> | 2024-01-31 10:01:01 +0100 |
| commit | 1bdee2153953e23bf71f7a5e83145bb4d67db567 (patch) | |
| tree | 878890b78170f9e72e09d89e92631b9b6f060fa1 /src/demo.c | |
initial init, huffman and demoheader
Diffstat (limited to 'src/demo.c')
| -rw-r--r-- | src/demo.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/demo.c b/src/demo.c new file mode 100644 index 0000000..0be8611 --- /dev/null +++ b/src/demo.c @@ -0,0 +1,44 @@ +#include "../inc/demo.h" + +#include <stdio.h> + +int reverseint(const unsigned char in[4]) +{ + return (in[0] << 24) | (in[1] << 16) | (in[2] << 8) | in[3]; +} + +int readdemoheader(FILE *fp, demoheader *dh) +{ + if (fscanf(fp,"TWDEMO%*c%c", &dh->version) != 1) + return -1; + if (fscanf(fp, "%64c", dh->netversion) != 1) + return -2; + if (fscanf(fp, "%64c", dh->mapname) != 1) + return -3; + if (fread(dh->mapsize, 1, 4, fp) != 4) + return -4; + if (fread(dh->mapcrc, 1, 4, fp) != 4) + return -5; + if (fscanf(fp, "%8c", dh->type) != 1) + return -6; + if (fread(dh->length, 1, 4, fp) != 4) + return -7; + if (fscanf(fp, "%20c", dh->timestamp) != 1) + return -8; + printf("version: %hhu\n", dh->version); + printf("net_version: %s\n", dh->netversion); + printf("mapname: %s\n", dh->mapname); + printf("mapsize: %i\n", reverseint(dh->mapsize)); + printf("mapcrc: %i\n", reverseint(dh->mapcrc)); + printf("type: %s\n", dh->type); + printf("length: %i\n", reverseint(dh->length)); + printf("timestamp: %s\n", dh->timestamp); + return 1; +} + +int readdemotimeline(FILE *fp, demotimeline *dt) +{ + if (fscanf(fp, "%260c", dt->data) != 1) + return -1; + return 1; +}
\ No newline at end of file |
