diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/utils/Decompressor.cpp | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/src/utils/Decompressor.cpp b/src/utils/Decompressor.cpp index 1dd326e..8b7347c 100644 --- a/src/utils/Decompressor.cpp +++ b/src/utils/Decompressor.cpp @@ -18,6 +18,7 @@ DataChunk* Decompressor::Decode(const std::vector<uint8_t>& buffer, const uint32 const unsigned char* in_buf = buffer.data() + offset; + SPDLOG_INFO("Offset: 0x{:X}", offset); switch (type) { case CompressionType::MIO0: { mio0_header_t head; @@ -36,15 +37,36 @@ DataChunk* Decompressor::Decode(const std::vector<uint8_t>& buffer, const uint32 } DecompressedData Decompressor::AutoDecode(YAML::Node& node, std::vector<uint8_t>& buffer, std::optional<size_t> manualSize) { + auto offset = GetSafeNode<uint32_t>(node, "offset"); - if(!node["offset"]){ - throw std::runtime_error("Failed to find offset"); - } + CompressionType type = Companion::Instance->GetCurrCompressionType(); - auto offset = node["offset"].as<uint32_t>(); - CompressionType type = Companion::Instance->GetCurrCompressionType(); + // Extract compressed assets. Do not run if the offset is 0x0 as that is handled in the below switch statement. + if (offset != 0x0) { + auto fileOffset = TranslateAddr(offset, true); + auto assetPtr = ASSET_PTR(offset); + auto gameSize = Companion::Instance->GetRomData().size(); + + LUS::BinaryReader reader((char*)buffer.data(), gameSize); + reader.SetEndianness(LUS::Endianness::Big); + reader.Seek(fileOffset + assetPtr, LUS::SeekOffsetType::Start); + std::string mio0 = reader.ReadCString(); + + if (mio0.compare("MIO0")) { + auto fileOffset = TranslateAddr(offset, true); + offset = ASSET_PTR(offset); + + auto decoded = Decode(buffer, fileOffset + offset, CompressionType::MIO0); + auto size = node["size"] ? node["size"].as<size_t>() : manualSize.value_or(decoded->size); + return { + .root = decoded, + .segment = { decoded->data, size } + }; + } + } + // Extract compressed files switch(type) { case CompressionType::MIO0: { @@ -62,7 +84,7 @@ DecompressedData Decompressor::AutoDecode(YAML::Node& node, std::vector<uint8_t> throw std::runtime_error("Found compressed yay0 segment.\nDecompression of yay0 has not been implemented yet."); case CompressionType::YAZ0: throw std::runtime_error("Found compressed yaz0 segment.\nDecompression of yaz0 has not been implemented yet."); - case CompressionType::None: + case CompressionType::None: // The data does not have compression { auto fileOffset = TranslateAddr(offset); |
