From 89fd2f9ac9b69d5f6b77dca9347aa61f9850d3b4 Mon Sep 17 00:00:00 2001 From: Jeod <47716344+JeodC@users.noreply.github.com> Date: Sat, 20 Jun 2026 16:30:58 -0400 Subject: Add bk_zip library and BK64 decompression foundation --- src/utils/TorchUtils.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/utils/TorchUtils.cpp') 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); -- cgit v1.2.3