summaryrefslogtreecommitdiff
path: root/inc/demo.h
blob: 645e2a29df203b977ea946c86c57d28db9edbe06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#ifndef DEMO_H
#define DEMO_H

#include <stdio.h>

typedef enum
{
    DEMOTICK = 0,
    DEMOSNAP = 1,
    DEMOMESSAGE = 2,
    DEMODELTA = 3
} demochunktype;

/* demoheader struct */
typedef struct
{
    unsigned char version;
    char netversion[64];
    char mapname[64];
    int mapsize;
    int mapcrc;
    char type[8];
    int length;
    char timestamp[20];
} demoheader;

/* demotimeline struct, only contains the raw data */
typedef struct
{
    char data[260];
} demotimeline;

/* demomap struct */
typedef struct
{
    unsigned char sha256[32];
    char *data;
} demomap;

typedef struct
{
    unsigned short type;
    unsigned short id;
    int numdata;
    int *data;
} demosnapitem;

/* Chunk types */
typedef struct
{
    int datasize;
    int numitems;
    int *offsets;
    demosnapitem *items;
} demosnap;

typedef struct
{
    char keyframe;
    char innline;
    int delta;
} demotick;

typedef struct
{
    int datasize;
    char *data;
} demodelta;

typedef struct
{
    int datasize;
    char *data;
} demomessage;

/* union for different chunks */
typedef union {
    demosnap *snap;
    demotick *tick;
    demodelta *delta;
    demomessage *message;
} chunkdata;

/* demochunk struct */
typedef struct
{
    demochunktype type;
    chunkdata data;
} demochunk;

/* demodata struct, stores all chunks */
typedef struct
{
    int numchunks;
    demochunk *chunks;
} demodata;

/* Read demo header from demofile into given demoheader */
/* Returns a positive number on success, negative on fail */
int readdemoheader(FILE *demofile, demoheader *header);

/* Read demo timeline from demofile into given demoheader */
/* Returns a positive number on success, negative on fail */
/* Must have read the header from demofile beforehand */
int readdemotimeline(FILE *demofile, demotimeline *timeline);

/* Read demo map from demofile into given demomap */
/* Returns a positive number on success, negative on fail */
/* Must have read the demoheader and demotimeline beforehand */
int readdemomap(FILE *demofile, demomap *map, int mapsize, unsigned char version);

/* Reads a chunk from demofile into given chunk */
/* Returns a positive number on success, 0 on EOF, and negative number on error */
/* Will allocate memory if chunk is snap, delta or message */
int readdemochunk(FILE *demofile, demochunk *chunk, unsigned char version);

int readdemochunks(FILE *fp, demodata *dd, unsigned char ver);

int writedemoheader(FILE *outfile, demoheader *header);
int writedemotimeline(FILE *outfile, demotimeline *timeline);
int writedemomap(FILE *outfile, demomap *map, int mapsize, unsigned char version);

#endif // DEMO_H