diff options
Diffstat (limited to 'src/utils/TorchUtils.cpp')
| -rw-r--r-- | src/utils/TorchUtils.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/utils/TorchUtils.cpp b/src/utils/TorchUtils.cpp index 86c836f..ec95c4a 100644 --- a/src/utils/TorchUtils.cpp +++ b/src/utils/TorchUtils.cpp @@ -8,12 +8,22 @@ namespace fs = std::filesystem; uint32_t Torch::translate(const uint32_t offset) { - if (SEGMENT_NUMBER(offset) > 0x01) { + // Segment 0 is a raw offset. BK64 also translates segment 1 (it stores assets + // in compressed segments); other games leave segment 1 raw. + const uint32_t firstSegment = + Companion::Instance->GetGBIMinorVersion() == GBIMinorVersion::BK64 ? 0x00 : 0x01; + if (SEGMENT_NUMBER(offset) > firstSegment) { auto segment = SEGMENT_NUMBER(offset); const auto addr = Companion::Instance->GetFileOffsetFromSegmentedAddr(segment); if (!addr.has_value()) { - SPDLOG_ERROR("Segment data missing from game config\nPlease add an entry for segment {}", segment); - throw std::runtime_error("Failed to find offset"); + // Fall back to the compressed-segment map + const auto compressedSegmentPair = Companion::Instance->GetFileOffsetFromCompressedSegmentedAddr(segment); + + if (!compressedSegmentPair.has_value()) { + SPDLOG_ERROR("Segment data missing from game config\nPlease add an entry for segment {}", segment); + throw std::runtime_error("Failed to find offset"); + } + return compressedSegmentPair.value().first + compressedSegmentPair.value().second + SEGMENT_OFFSET(offset); } return addr.value() + SEGMENT_OFFSET(offset); |
