summaryrefslogtreecommitdiff
path: root/src/utils/TorchUtils.cpp
diff options
context:
space:
mode:
authorJeod <47716344+JeodC@users.noreply.github.com>2026-06-20 16:30:58 -0400
committerLywx <kiritodev01@gmail.com>2026-06-29 18:48:27 -0600
commit89fd2f9ac9b69d5f6b77dca9347aa61f9850d3b4 (patch)
treeaa60856e631bd81db5b08fe7f94a6ac861fa9f8e /src/utils/TorchUtils.cpp
parentdd6eb7897a30b881c1f93e8a6f66b946e3b599a1 (diff)
Add bk_zip library and BK64 decompression foundation
Diffstat (limited to 'src/utils/TorchUtils.cpp')
-rw-r--r--src/utils/TorchUtils.cpp16
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);