mirror of
https://github.com/izzy2lost/Torch.git
synced 2026-07-06 00:18:35 -07:00
Decompress every asset
This commit is contained in:
@@ -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) {
|
||||
|
||||
if(!node["offset"]){
|
||||
throw std::runtime_error("Failed to find offset");
|
||||
}
|
||||
|
||||
auto offset = node["offset"].as<uint32_t>();
|
||||
auto offset = GetSafeNode<uint32_t>(node, "offset");
|
||||
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user