From 8f80b52b8daec619516c0f9b37d791a88937a549 Mon Sep 17 00:00:00 2001 From: KiritoDv Date: Wed, 31 Jan 2024 00:11:31 -0600 Subject: Fixed segment validation and added size fallback on decompressor --- src/factories/BaseFactory.h | 2 +- src/factories/TextureFactory.cpp | 8 ++++---- src/utils/Decompressor.cpp | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/factories/BaseFactory.h b/src/factories/BaseFactory.h index b5e5b65..cf00685 100644 --- a/src/factories/BaseFactory.h +++ b/src/factories/BaseFactory.h @@ -17,7 +17,7 @@ #define SEGMENT_OFFSET(a) ((uint32_t)(a) & 0x00FFFFFF) #define SEGMENT_NUMBER(x) (((uint32_t)(x) >> 24) & 0xFF) -#define IS_SEGMENTED(x) (((x) & 0x01000000 > 0) && (SEGMENT_NUMBER(x) < 0x20)) +#define IS_SEGMENTED(x) (((x) > 0x01000000) && (SEGMENT_NUMBER(x) < 0x20)) #define tab "\t" #define fourSpaceTab " " diff --git a/src/factories/TextureFactory.cpp b/src/factories/TextureFactory.cpp index c08c26c..cb1b520 100644 --- a/src/factories/TextureFactory.cpp +++ b/src/factories/TextureFactory.cpp @@ -111,7 +111,7 @@ std::optional> TextureFactory::parse(std::vector(node, "width"); auto height = GetSafeNode(node, "height"); auto size = GetSafeNode(node, "size"); - auto offset = GetSafeNode(node, "offset"); + auto offset = Decompressor::TranslateAddr(GetSafeNode(node, "offset")); if (format.empty()) { SPDLOG_ERROR("Texture entry at {:X} in yaml missing format node\n\ @@ -130,14 +130,14 @@ std::optional> TextureFactory::parse(std::vector result; if(type == TextureType::GrayscaleAlpha1bpp){ - result = alloc_ia8_text_from_i1((uint16_t*) segment.data, 8, 16); + result = alloc_ia8_text_from_i1(reinterpret_cast(segment.data), 8, 16); } else { result = std::vector(segment.data, segment.data + segment.size); } SPDLOG_INFO("Texture: {} {}x{} {}", format, width, height, size); - SPDLOG_INFO("Offset: {}", offset); - SPDLOG_INFO("Has MIO0: {}", Decompressor::IsCompressed(node) ? "true" : "false"); + SPDLOG_INFO("Offset: 0x{:X}", offset); + SPDLOG_INFO("Is Compressed: {}", Decompressor::IsCompressed(node) ? "true" : "false"); SPDLOG_INFO("Size: {}", result.size()); if(result.size() == 0){ diff --git a/src/utils/Decompressor.cpp b/src/utils/Decompressor.cpp index 4e89cb7..7de4338 100644 --- a/src/utils/Decompressor.cpp +++ b/src/utils/Decompressor.cpp @@ -63,7 +63,7 @@ DecompressedData Decompressor::AutoDecode(YAML::Node& node, std::vector return { .root = nullptr, - .segment = { buffer.data() + offset, buffer.size() - offset } + .segment = { buffer.data() + offset, node["size"] ? node["size"].as() : buffer.size() - offset } }; } -- cgit v1.2.3