summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjohannes <johannes.herman@gmail.com>2024-02-06 14:14:57 +0100
committerjohannes <johannes.herman@gmail.com>2024-02-06 14:14:57 +0100
commitec6a5c1ff3bb7731e17b798f9bbfdb0aedf94baa (patch)
treee766d76d0dcb2468ac34b6f096054d87513727ff
parent26a7b9bbf466dd01b5449ed5819c3e90ac398a1d (diff)
made readdemomap follow version
-rw-r--r--inc/demo.h2
-rw-r--r--src/demo.c16
-rw-r--r--src/main.c4
3 files changed, 10 insertions, 12 deletions
diff --git a/inc/demo.h b/inc/demo.h
index efb3a23..6a8a04a 100644
--- a/inc/demo.h
+++ b/inc/demo.h
@@ -103,7 +103,7 @@ 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);
+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 */
diff --git a/src/demo.c b/src/demo.c
index 155d67c..23995ff 100644
--- a/src/demo.c
+++ b/src/demo.c
@@ -22,11 +22,11 @@ int readdemoheader(FILE *fp, demoheader *dh)
{
char magicbuff[sizeof(headermagic)];
unsigned char intbuff[4];
-
+
fread(magicbuff, 1, sizeof(headermagic), fp);
if (strcmp(magicbuff, headermagic) != 0)
return -1;
-
+
if (fread(&dh->version, 1, 1, fp) != 1)
return -2;
@@ -67,22 +67,22 @@ int readdemoheader(FILE *fp, demoheader *dh)
int readdemotimeline(FILE *fp, demotimeline *dt)
{
- if (fscanf(fp, "%260c", dt->data) != 1)
+ if (fread(dt->data, 1, 260, fp) != 260)
return -1;
return 1;
}
-// TODO make version sensitive
-int readdemomap(FILE *fp, demomap *dm, int mapsize)
+int readdemomap(FILE *fp, demomap *dm, int mapsize, unsigned char ver)
{
char magicbuf[sizeof(mapmagic)];
- fread(magicbuf, 1, sizeof(mapmagic), fp);
+ fread(magicbuf, 1, sizeof(mapmagic), fp);
if (memcmp(magicbuf, mapmagic, sizeof(mapmagic)) != 0)
return -1;
- if (fread(dm->sha256, 1, 32, fp) != 32)
- return -2;
+ if (ver >= 4)
+ if (fread(dm->sha256, 1, 32, fp) != 32)
+ return -2;
if (fread(dm->data, 1, mapsize, fp) != mapsize)
return -3;
diff --git a/src/main.c b/src/main.c
index 758504b..a3ea478 100644
--- a/src/main.c
+++ b/src/main.c
@@ -132,9 +132,7 @@ int main()
printf("timeline: %i\n", ret);
- // TODO should be able to read 5 aswell, change readdemomap to fit
- if (dh.version >= 6)
- ret = readdemomap(fp, &dm, dh.mapsize);
+ ret = readdemomap(fp, &dm, dh.mapsize, dh.version);
printf("readdemomap ret: %d\n\n", ret);
demochunk dc;