diff options
| author | = <=> | 2024-05-01 18:33:32 -0600 |
|---|---|---|
| committer | Lywx <kiritodev01@gmail.com> | 2024-05-02 18:32:48 -0600 |
| commit | d24b5b3193e170b1e1153d5568827e00dfde5569 (patch) | |
| tree | 38c0556b955b3423de67ce5a4cae18d938b4b89a /src/utils/Decompressor.cpp | |
| parent | 4b21686e66de79dfedabcc3d6a1be83e47a218cd (diff) | |
Add tkmk00
Diffstat (limited to 'src/utils/Decompressor.cpp')
| -rw-r--r-- | src/utils/Decompressor.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/utils/Decompressor.cpp b/src/utils/Decompressor.cpp index 150ae5d..b12ba0e 100644 --- a/src/utils/Decompressor.cpp +++ b/src/utils/Decompressor.cpp @@ -6,6 +6,7 @@ extern "C" { #include <libmio0/mio0.h> +#include <libmio0/tkmk00.h> } std::unordered_map<uint32_t, DataChunk*> gCachedChunks; @@ -35,6 +36,23 @@ DataChunk* Decompressor::Decode(const std::vector<uint8_t>& buffer, const uint32 } } +DataChunk* Decompressor::DecodeTKMK00(const std::vector<uint8_t>& buffer, const uint32_t offset, const uint32_t size, const uint32_t alpha) { + + if(gCachedChunks.contains(offset)){ + return gCachedChunks[offset]; + } + + const uint8_t* in_buf = buffer.data() + offset; + + const auto decompressed = new uint8_t[size]; + const auto rgba = new uint8_t[size]; + SPDLOG_INFO("RUN?"); + tkmk00_decode(in_buf, decompressed, rgba, alpha); + SPDLOG_INFO("RUN2?"); + gCachedChunks[offset] = new DataChunk{ decompressed, size }; + return gCachedChunks[offset]; +} + DecompressedData Decompressor::AutoDecode(YAML::Node& node, std::vector<uint8_t>& buffer, std::optional<size_t> manualSize) { auto offset = GetSafeNode<uint32_t>(node, "offset"); @@ -58,6 +76,26 @@ DecompressedData Decompressor::AutoDecode(YAML::Node& node, std::vector<uint8_t> }; } + // Extract compressed tkmk00 assets in mk64. + if (node["tkmk00"]) { + const auto alpha = GetSafeNode<uint32_t>(node, "alpha"); + const auto width = GetSafeNode<uint32_t>(node, "width"); + const auto height = GetSafeNode<uint32_t>(node, "height"); + const auto textureSize = width * height * 2; + auto assetPtr = ASSET_PTR(offset); + auto gameSize = Companion::Instance->GetRomData().size(); + + auto fileOffset = TranslateAddr(offset, true); + offset = ASSET_PTR(offset); + + auto decoded = DecodeTKMK00(buffer, fileOffset + offset, textureSize, alpha); + auto size = node["size"] ? node["size"].as<size_t>() : manualSize.value_or(decoded->size); + return { + .root = decoded, + .segment = { decoded->data, size } + }; + } + // Extract compressed files that contain many assets. switch(type) { case CompressionType::MIO0: |
