From 93cf929f29dea490ed60e5300cacdd99886c988e Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Sat, 9 Sep 2023 20:09:50 -0400 Subject: Add the standalone portion of mapman. --- mapman/src/mapdump.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 mapman/src/mapdump.cpp (limited to 'mapman/src/mapdump.cpp') diff --git a/mapman/src/mapdump.cpp b/mapman/src/mapdump.cpp new file mode 100644 index 0000000..6d8fbcc --- /dev/null +++ b/mapman/src/mapdump.cpp @@ -0,0 +1,52 @@ +#include "mapdump.hpp" + +#include + +bool load_dump(gzFile f, map_t &d) +{ + map_t ret; + if (gzread(f, &d.id, 4) < 4) return false; + int name_len; + if (gzread(f, &name_len, 4) < 4) return false; + if (name_len) + { + char *name = new char[name_len]; + if (gzread(f, name, name_len) != name_len) + { + delete[] name; + return false; + } + d.custom_name = std::string(name); + delete[] name; + } else d.custom_name = std::string(); + if (gzread(f, d.map_data.data(), 128 * 128) < 128 * 128) + return false; + return true; +} + +bool load_dumps(const char *fn, std::vector &dumps) +{ + gzFile f = gzopen(fn, "rb"); + dumps.clear(); + while (!gzeof(f)) + { + map_t d; + if (load_dump(f, d)) + dumps.emplace_back(std::move(d)); + } + gzclose(f); + return dumps.size() != 0; +} + +std::vector load_tally(const char *fn) +{ + std::vector ret; + gzFile f = gzopen(fn, "rb"); + while (!gzeof(f)) + { + int t; + gzread(f, &t, 4); + ret.push_back(t); + } + return ret; +} -- cgit v1.2.3