mirror of
https://github.com/izzy2lost/Torch.git
synced 2026-07-06 00:18:35 -07:00
Fixed a crash on aasets that were autogenerated and compressed
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) && (SEGMENT_NUMBER(x) < 0x20))
|
||||
#define IS_SEGMENTED(x) (((uint32_t)(x) > 0x01000000) && (SEGMENT_NUMBER(x) < 0x20))
|
||||
|
||||
#define tab "\t"
|
||||
#define fourSpaceTab " "
|
||||
|
||||
@@ -40,10 +40,13 @@ DecompressedData Decompressor::AutoDecode(YAML::Node& node, std::vector<uint8_t>
|
||||
throw std::runtime_error("Failed to find offset");
|
||||
}
|
||||
|
||||
const auto offset = TranslateAddr(node["offset"].as<uint32_t>());
|
||||
auto offset = node["offset"].as<uint32_t>();
|
||||
|
||||
if(node["mio0"]){
|
||||
const auto mio0 = node["mio0"].as<uint32_t>();
|
||||
|
||||
offset = TranslateAddr(offset, IS_SEGMENTED(offset));
|
||||
|
||||
auto decoded = Decode(buffer, offset, CompressionType::MIO0);
|
||||
auto size = node["size"] ? node["size"].as<size_t>() : manualSize.value_or(decoded->size - mio0);
|
||||
|
||||
@@ -61,13 +64,15 @@ DecompressedData Decompressor::AutoDecode(YAML::Node& node, std::vector<uint8_t>
|
||||
throw std::runtime_error("Yaz0 not implemented");
|
||||
}
|
||||
|
||||
offset = TranslateAddr(offset);
|
||||
|
||||
return {
|
||||
.root = nullptr,
|
||||
.segment = { buffer.data() + offset, node["size"] ? node["size"].as<size_t>() : manualSize.value_or(buffer.size() - offset) }
|
||||
};
|
||||
}
|
||||
|
||||
uint32_t Decompressor::TranslateAddr(uint32_t addr){
|
||||
uint32_t Decompressor::TranslateAddr(uint32_t addr, bool baseAddress){
|
||||
if(IS_SEGMENTED(addr)){
|
||||
const auto segment = Companion::Instance->GetSegmentedAddr(SEGMENT_NUMBER(addr));
|
||||
|
||||
@@ -76,7 +81,7 @@ uint32_t Decompressor::TranslateAddr(uint32_t addr){
|
||||
return 0;
|
||||
}
|
||||
|
||||
return segment.value() + SEGMENT_OFFSET(addr);
|
||||
return segment.value() + (!baseAddress ? SEGMENT_OFFSET(addr) : 0);
|
||||
}
|
||||
|
||||
return addr;
|
||||
|
||||
@@ -29,7 +29,7 @@ class Decompressor {
|
||||
public:
|
||||
static DataChunk* Decode(const std::vector<uint8_t>& buffer, uint32_t offset, CompressionType type);
|
||||
static DecompressedData AutoDecode(YAML::Node& node, std::vector<uint8_t>& buffer, std::optional<size_t> size = std::nullopt);
|
||||
static uint32_t TranslateAddr(uint32_t addr);
|
||||
static uint32_t TranslateAddr(uint32_t addr, bool baseAddress = false);
|
||||
static bool IsSegmented(uint32_t addr);
|
||||
static bool IsCompressed(YAML::Node& node);
|
||||
static void CopyCompression(YAML::Node& from, YAML::Node& to);
|
||||
|
||||
Reference in New Issue
Block a user