aboutsummaryrefslogtreecommitdiff
path: root/mapman/src/mapdump.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mapman/src/mapdump.cpp')
-rw-r--r--mapman/src/mapdump.cpp52
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;
+}