summaryrefslogtreecommitdiff
path: root/src/utils/MIODecoder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/MIODecoder.cpp')
-rw-r--r--src/utils/MIODecoder.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/utils/MIODecoder.cpp b/src/utils/MIODecoder.cpp
new file mode 100644
index 0000000..aed5eba
--- /dev/null
+++ b/src/utils/MIODecoder.cpp
@@ -0,0 +1,27 @@
+#include "MIODecoder.h"
+
+extern "C" {
+#include <libmio0/mio0.h>
+}
+
+std::unordered_map<uint32_t, std::vector<char>> MIO0Decoder::gCachedChunks;
+
+std::vector<char>& MIO0Decoder::Decode(std::vector<uint8_t>& buffer, uint32_t offset) {
+ const unsigned char* in_buf = buffer.data() + offset;
+
+ mio0_header_t head;
+ if(!mio0_decode_header(in_buf, &head)){
+ throw std::runtime_error("Invalid MIO0 header");
+ }
+
+ uint8_t* decompressed = new uint8_t[head.dest_size];
+ mio0_decode(in_buf, decompressed, nullptr);
+ gCachedChunks[offset] = std::vector<char>(decompressed, decompressed + head.dest_size);
+
+ delete[] decompressed;
+ return gCachedChunks[offset];
+}
+
+void MIO0Decoder::ClearCache() {
+ gCachedChunks.clear();
+} \ No newline at end of file