summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjohannes <johannes.herman@gmail.com>2024-02-10 20:08:33 +0100
committerjohannes <johannes.herman@gmail.com>2024-02-10 20:08:33 +0100
commitcb4a7637943d407187184b28d602b750c9547fa5 (patch)
tree2c08a8f0220fe03397baccec909eeda41033c2c9
parented4d43d281e92b28bbed5c730440b428fe0b171e (diff)
finalized changemap
-rw-r--r--inc/commands.h3
-rw-r--r--src/commands.c10
2 files changed, 12 insertions, 1 deletions
diff --git a/inc/commands.h b/inc/commands.h
index 53d17f7..654d8b7 100644
--- a/inc/commands.h
+++ b/inc/commands.h
@@ -9,6 +9,9 @@ int setnamebyname(char *oldname, char *newname, demo *demo);
int setskinbyid(int id, char *skin, demo *demo);
int setskinbyname(char *name, char *skin, demo *demo);
+/* Changes demos map to given map */
+/* Changes demo version to 5 if it is 6 */
+/* Will fail if mapname >= 31, or map is not a teeworlds datafile */
int changemap(FILE *map, char *mapname, demo *demo);
#endif // COMMANDS_H
diff --git a/src/commands.c b/src/commands.c
index 180f4e1..599c6d0 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -148,11 +148,19 @@ int changemap(FILE *map, char *mapname, demo *demo)
return -1;
fread(mapbuff, 1, mapsize, map);
+
+ if (memcmp(mapbuff, "DATA", 4) != 0)
+ {
+ free(mapbuff);
+ return -1;
+ }
free(demo->map.data);
demo->map.data = mapbuff;
- demo->header.version = 5;
+ if (demo->header.version >= 6)
+ demo->header.version = 5;
+
demo->header.mapsize = mapsize;
demo->header.mapcrc = mapsize;
memcpy(demo->header.mapname, mapname, namelen + 1);