From 5c7f8f8b27887fe4aeaa342f45593d39a88e6455 Mon Sep 17 00:00:00 2001 From: MegaMech Date: Wed, 24 Jul 2024 15:53:50 -0600 Subject: Fix Spaghetti texture loading for segments 3 & 5 (#144) * Update DisplayListFactory.cpp * Update DisplayListFactory.cpp --- src/factories/DisplayListFactory.cpp | 38 ++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'src/factories/DisplayListFactory.cpp') diff --git a/src/factories/DisplayListFactory.cpp b/src/factories/DisplayListFactory.cpp index b544d9d..a596ab4 100644 --- a/src/factories/DisplayListFactory.cpp +++ b/src/factories/DisplayListFactory.cpp @@ -376,25 +376,33 @@ ExportResult DListBinaryExporter::Export(std::ostream &write, std::shared_ptrGetNodeByAddr(ptr); - Gfx value = gsDPSetTextureOTRImage(C0(21, 3), C0(19, 2), C0(0, 10), ptr); - w0 = value.words.w0; - w1 = value.words.w1; + // Export texture segment addresses as segmented addresses + if ((Companion::Instance->GetGBIMinorVersion() == GBIMinorVersion::Mk64) && ((SEGMENT_NUMBER(w1) == 0x03) || (SEGMENT_NUMBER(w1) == 0x05))) { + w1 |= 1; + writer.Write(w0); + writer.Write(w1); + } else { + Gfx value = gsDPSetTextureOTRImage(C0(21, 3), C0(19, 2), C0(0, 10), ptr); + w0 = value.words.w0; + w1 = value.words.w1; + - writer.Write(w0); - writer.Write(w1); + writer.Write(w0); + writer.Write(w1); - if(dec.has_value()){ - uint64_t hash = CRC64(std::get<0>(dec.value()).c_str()); + if(dec.has_value()){ + uint64_t hash = CRC64(std::get<0>(dec.value()).c_str()); - if(hash == 0){ - throw std::runtime_error("Texture hash is 0 for " + std::get<0>(dec.value())); - } + if(hash == 0){ + throw std::runtime_error("Texture hash is 0 for " + std::get<0>(dec.value())); + } - SPDLOG_INFO("Found texture: 0x{:X} Hash: 0x{:X} Path: {}", ptr, hash, std::get<0>(dec.value())); - w0 = hash >> 32; - w1 = hash & 0xFFFFFFFF; - } else { - SPDLOG_WARN("Could not find texture at 0x{:X}", ptr); + SPDLOG_INFO("Found texture: 0x{:X} Hash: 0x{:X} Path: {}", ptr, hash, std::get<0>(dec.value())); + w0 = hash >> 32; + w1 = hash & 0xFFFFFFFF; + } else { + SPDLOG_WARN("Could not find texture at 0x{:X}", ptr); + } } } -- cgit v1.2.3