diff --git a/src/Companion.cpp b/src/Companion.cpp index ba0df34..ae568ef 100644 --- a/src/Companion.cpp +++ b/src/Companion.cpp @@ -64,12 +64,14 @@ void Companion::ExtractNode(YAML::Node& node, std::string& name, SWrapper* binar auto type = GetSafeNode(node, "type"); std::transform(type.begin(), type.end(), type.begin(), ::toupper); + spdlog::set_pattern(regular); if(node["offset"]) { auto offset = node["offset"].as(); - SPDLOG_INFO("[{}] Processing {} at 0x{:X}", type, name, offset); + SPDLOG_INFO("- [{}] Processing {} at 0x{:X}", type, name, offset); } else { - SPDLOG_INFO("[{}] Processing {}", type, name); + SPDLOG_INFO("- [{}] Processing {}", type, name); } + spdlog::set_pattern(line); auto factory = this->GetFactory(type); if(!factory.has_value()){ @@ -97,6 +99,9 @@ void Companion::ExtractNode(YAML::Node& node, std::string& name, SWrapper* binar std::replace(doutput.begin(), doutput.end(), '\\', '/'); this->gAssetDependencies[this->gCurrentFile][fst].second = true; this->ExtractNode(snd.first, doutput, binary); + spdlog::set_pattern(regular); + SPDLOG_INFO("------------------------------------------------"); + spdlog::set_pattern(line); } switch (this->gConfig.exporterType) { diff --git a/src/factories/TextureFactory.cpp b/src/factories/TextureFactory.cpp index cb1b520..df81174 100644 --- a/src/factories/TextureFactory.cpp +++ b/src/factories/TextureFactory.cpp @@ -17,6 +17,32 @@ static const std::unordered_map gTextureTypes = { { "IA16", TextureType::GrayscaleAlpha16bpp }, }; +size_t CalculateTextureSize(TextureType type, uint32_t width, uint32_t height) { + switch (type) { + // 4 bytes per pixel + case TextureType::RGBA32bpp: + return width * height * 4; + // 2 bytes per pixel + case TextureType::RGBA16bpp: + case TextureType::GrayscaleAlpha16bpp: + return width * height * 2; + // 1 byte per pixel + case TextureType::Grayscale8bpp: + case TextureType::Palette8bpp: + case TextureType::GrayscaleAlpha8bpp: + // TODO: We need to validate this MegaMech + case TextureType::GrayscaleAlpha1bpp: + return width * height; + // 1/2 byte per pixel + case TextureType::Palette4bpp: + case TextureType::Grayscale4bpp: + case TextureType::GrayscaleAlpha4bpp: + return (width * height) / 2; + default: + return 0; + } +} + std::vector alloc_ia8_text_from_i1(uint16_t *in, int16_t width, int16_t height) { int32_t inPos; uint16_t bitMask; @@ -110,7 +136,7 @@ std::optional> TextureFactory::parse(std::vector(node, "format"); auto width = GetSafeNode(node, "width"); auto height = GetSafeNode(node, "height"); - auto size = GetSafeNode(node, "size"); + auto size = GetSafeNode(node, "size", CalculateTextureSize(gTextureTypes.at(format), width, height)); auto offset = Decompressor::TranslateAddr(GetSafeNode(node, "offset")); if (format.empty()) { @@ -126,7 +152,7 @@ std::optional> TextureFactory::parse(std::vector result; if(type == TextureType::GrayscaleAlpha1bpp){ @@ -135,10 +161,12 @@ std::optional> TextureFactory::parse(std::vector& buffer, const uint32 } } -DecompressedData Decompressor::AutoDecode(YAML::Node& node, std::vector& buffer) { +DecompressedData Decompressor::AutoDecode(YAML::Node& node, std::vector& buffer, std::optional manualSize) { if(!node["offset"]){ throw std::runtime_error("Failed to find offset"); } @@ -45,7 +45,7 @@ DecompressedData Decompressor::AutoDecode(YAML::Node& node, std::vector if(node["mio0"]){ const auto mio0 = node["mio0"].as(); auto decoded = Decode(buffer, offset, CompressionType::MIO0); - auto size = node["size"] ? node["size"].as() : decoded->size - mio0; + auto size = node["size"] ? node["size"].as() : manualSize.value_or(decoded->size - mio0); return { .root = decoded, @@ -63,7 +63,7 @@ DecompressedData Decompressor::AutoDecode(YAML::Node& node, std::vector return { .root = nullptr, - .segment = { buffer.data() + offset, node["size"] ? node["size"].as() : buffer.size() - offset } + .segment = { buffer.data() + offset, node["size"] ? node["size"].as() : manualSize.value_or(buffer.size() - offset) } }; } diff --git a/src/utils/Decompressor.h b/src/utils/Decompressor.h index 1bd5c05..4e3c298 100644 --- a/src/utils/Decompressor.h +++ b/src/utils/Decompressor.h @@ -26,7 +26,7 @@ struct DecompressedData { class Decompressor { public: static DataChunk* Decode(const std::vector& buffer, uint32_t offset, CompressionType type); - static DecompressedData AutoDecode(YAML::Node& node, std::vector& buffer); + static DecompressedData AutoDecode(YAML::Node& node, std::vector& buffer, std::optional size = std::nullopt); static uint32_t TranslateAddr(uint32_t addr); static bool IsSegmented(uint32_t addr); static bool IsCompressed(YAML::Node& node);