summaryrefslogtreecommitdiff
path: root/src
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 /src
parent26a7b9bbf466dd01b5449ed5819c3e90ac398a1d (diff)
made readdemomap follow version
Diffstat (limited to 'src')
-rw-r--r--src/demo.c16
-rw-r--r--src/main.c4
2 files changed, 9 insertions, 11 deletions
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;