mirror of
https://github.com/izzy2lost/Torch.git
synced 2026-07-06 00:18:35 -07:00
Fixed segment validation and added size fallback on decompressor
This commit is contained in:
@@ -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 " "
|
||||
|
||||
@@ -111,7 +111,7 @@ std::optional<std::shared_ptr<IParsedData>> TextureFactory::parse(std::vector<ui
|
||||
auto width = GetSafeNode<uint32_t>(node, "width");
|
||||
auto height = GetSafeNode<uint32_t>(node, "height");
|
||||
auto size = GetSafeNode<uint32_t>(node, "size");
|
||||
auto offset = GetSafeNode<uint32_t>(node, "offset");
|
||||
auto offset = Decompressor::TranslateAddr(GetSafeNode<uint32_t>(node, "offset"));
|
||||
|
||||
if (format.empty()) {
|
||||
SPDLOG_ERROR("Texture entry at {:X} in yaml missing format node\n\
|
||||
@@ -130,14 +130,14 @@ std::optional<std::shared_ptr<IParsedData>> TextureFactory::parse(std::vector<ui
|
||||
std::vector<uint8_t> 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<uint16_t*>(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){
|
||||
|
||||
@@ -63,7 +63,7 @@ DecompressedData Decompressor::AutoDecode(YAML::Node& node, std::vector<uint8_t>
|
||||
|
||||
return {
|
||||
.root = nullptr,
|
||||
.segment = { buffer.data() + offset, buffer.size() - offset }
|
||||
.segment = { buffer.data() + offset, node["size"] ? node["size"].as<size_t>() : buffer.size() - offset }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user