summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
authorjohannes <johannes.herman@gmail.com>2024-02-06 12:29:41 +0100
committerjohannes <johannes.herman@gmail.com>2024-02-06 12:29:41 +0100
commit0ab2c0afc6fd192f4008962ef400b92434e2dc2d (patch)
tree31ff61e1945850048ac6b82f23cb428d62e0cb70 /inc
parent1bdee2153953e23bf71f7a5e83145bb4d67db567 (diff)
added read snap and read tick
Diffstat (limited to 'inc')
-rw-r--r--inc/demo.h83
-rw-r--r--inc/pack.h10
2 files changed, 87 insertions, 6 deletions
diff --git a/inc/demo.h b/inc/demo.h
index 154a333..0b398b0 100644
--- a/inc/demo.h
+++ b/inc/demo.h
@@ -9,10 +9,10 @@ typedef struct
unsigned char version;
char netversion[64];
char mapname[64];
- unsigned char mapsize[4]; // Big endian int
- unsigned char mapcrc[4]; // Big endian int
+ unsigned char mapsize[4]; // Big endian int
+ unsigned char mapcrc[4]; // Big endian int
char type[8];
- unsigned char length[4]; // Big endian int
+ unsigned char length[4]; // Big endian int
char timestamp[20];
} demoheader;
@@ -22,13 +22,84 @@ typedef struct
char data[260];
} demotimeline;
+/* demomap struct */
+typedef struct
+{
+ unsigned char sha256[32];
+ unsigned 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
+{
+} demodelta;
+
+typedef struct
+{
+} demomessage;
+
+/* union for different chunks */
+typedef union {
+ demosnap *snap;
+ demotick *tick;
+ demodelta *delta;
+ demomessage *message;
+} chunkdata;
+
+/* demochunk struct */
+typedef struct
+{
+ unsigned char 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 *demoheader);
+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 *demotimeline);
+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);
+
+/* 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);
-#endif // DEMO_H \ No newline at end of file
+#endif // DEMO_H
diff --git a/inc/pack.h b/inc/pack.h
new file mode 100644
index 0000000..d04d6ca
--- /dev/null
+++ b/inc/pack.h
@@ -0,0 +1,10 @@
+#ifndef PACK_H
+#define PACK_H
+
+#include <stdio.h>
+
+/* reads a teeworlds packed int from given buffer */
+/* the given pointer is incremented */
+int readint(unsigned char **cp);
+
+#endif // PACK_H