diff options
author | 2023-09-09 20:09:50 -0400 | |
---|---|---|
committer | 2023-09-09 20:09:50 -0400 | |
commit | 93cf929f29dea490ed60e5300cacdd99886c988e (patch) | |
tree | 0f8669c56e22a287047ee20846b92f1580d7364f /mapman/src/mapdump.cpp | |
parent | 40432e083b11271cf3148b9c38156cf759436699 (diff) | |
download | meteor-trashy-addon-93cf929f29dea490ed60e5300cacdd99886c988e.tar.xz |
Add the standalone portion of mapman.
Diffstat (limited to 'mapman/src/mapdump.cpp')
-rw-r--r-- | mapman/src/mapdump.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
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 <zlib.h> + +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<map_t> &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<int> load_tally(const char *fn) +{ + std::vector<int> ret; + gzFile f = gzopen(fn, "rb"); + while (!gzeof(f)) + { + int t; + gzread(f, &t, 4); + ret.push_back(t); + } + return ret; +} |