summaryrefslogtreecommitdiff
path: root/src/utils/Decompressor.cpp
diff options
context:
space:
mode:
author= <=>2024-04-30 17:17:14 -0600
committerLywx <kiritodev01@gmail.com>2024-05-02 18:32:48 -0600
commitce958fdb4f79c40b1fecd0103d9d8ce58047301a (patch)
treebc42ad0901507da692bd1c5f6406179daff260ec /src/utils/Decompressor.cpp
parent5d0a282ba4e7d6ea816478e8037d0dc0e93f5eac (diff)
Update as per comments
Diffstat (limited to 'src/utils/Decompressor.cpp')
-rw-r--r--src/utils/Decompressor.cpp34
1 files changed, 13 insertions, 21 deletions
diff --git a/src/utils/Decompressor.cpp b/src/utils/Decompressor.cpp
index 8b7347c..7435bb7 100644
--- a/src/utils/Decompressor.cpp
+++ b/src/utils/Decompressor.cpp
@@ -41,36 +41,28 @@ DecompressedData Decompressor::AutoDecode(YAML::Node& node, std::vector<uint8_t>
CompressionType type = Companion::Instance->GetCurrCompressionType();
+ auto fileOffset = TranslateAddr(offset, true);
- // 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);
+ // Extract compressed assets.
+ if (node["mio0"]) {
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 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 }
- };
- }
+ 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
+ // Extract compressed files that contain many assets.
switch(type) {
case CompressionType::MIO0:
{
- auto fileOffset = TranslateAddr(offset, true);
offset = ASSET_PTR(offset);
auto decoded = Decode(buffer, fileOffset, CompressionType::MIO0);
@@ -86,7 +78,7 @@ DecompressedData Decompressor::AutoDecode(YAML::Node& node, std::vector<uint8_t>
throw std::runtime_error("Found compressed yaz0 segment.\nDecompression of yaz0 has not been implemented yet.");
case CompressionType::None: // The data does not have compression
{
- auto fileOffset = TranslateAddr(offset);
+ fileOffset = TranslateAddr(offset, false);
auto size = node["size"] ? node["size"].as<size_t>() : manualSize.value_or(buffer.size() - fileOffset);