diff --git a/src/Companion.cpp b/src/Companion.cpp index e16a99f..7815498 100644 --- a/src/Companion.cpp +++ b/src/Companion.cpp @@ -1405,12 +1405,7 @@ std::optional Companion::GetFileOffsetFromSegmentedAddr(const uin return std::nullopt; } -std::optional> Companion::GetNodeByAddr(uint32_t addr){ - if(!this->gAddrMap.contains(this->gCurrentFile)){ - return std::nullopt; - } - - // HACK: Adjust address to rom address if virtual address +uint32_t Companion::PatchVirtualAddr(uint32_t addr) { if (addr & 0x80000000) { if (gVirtualAddrMap.contains(gCurrentFile)) { addr -= std::get<0>(gVirtualAddrMap[gCurrentFile]); @@ -1418,6 +1413,17 @@ std::optional> Companion::GetNodeByAddr(uint } } + return addr; +} + +std::optional> Companion::GetNodeByAddr(uint32_t addr){ + if(!this->gAddrMap.contains(this->gCurrentFile)){ + return std::nullopt; + } + + // HACK: Adjust address to rom address if virtual address + addr = PatchVirtualAddr(addr); + if(!this->gAddrMap[this->gCurrentFile].contains(addr)){ for (auto &file : this->gCurrentExternalFiles) { if (!this->gAddrMap.contains(file)) { diff --git a/src/Companion.h b/src/Companion.h index 60f10b6..ad18323 100644 --- a/src/Companion.h +++ b/src/Companion.h @@ -153,6 +153,7 @@ public: std::optional GetFileOffsetFromSegmentedAddr(uint8_t segment) const; std::optional> GetFactory(const std::string& type); + uint32_t PatchVirtualAddr(uint32_t addr); std::optional> GetNodeByAddr(uint32_t addr); std::optional> GetSafeNodeByAddr(const uint32_t addr, std::string type); std::optional>> GetNodesByType(const std::string& type); diff --git a/src/factories/DisplayListFactory.cpp b/src/factories/DisplayListFactory.cpp index 20eea5b..5c3e165 100644 --- a/src/factories/DisplayListFactory.cpp +++ b/src/factories/DisplayListFactory.cpp @@ -606,7 +606,8 @@ std::optional> DListFactory::parse(std::vectorGetNodeByAddr(w1); if(!decl.has_value()){ - auto search = SearchVtx(w1); + auto adjPtr = Companion::Instance->PatchVirtualAddr(w1); + auto search = SearchVtx(adjPtr); if(search.has_value()){ auto [path, vtx] = search.value(); @@ -617,14 +618,14 @@ std::optional> DListFactory::parse(std::vector(vtx, "count"); auto lSize = ALIGN16(lCount * sizeof(N64Vtx_t)); - if(w1 > lOffset && w1 <= lOffset + lSize){ - SPDLOG_INFO("Found vtx at 0x{:X} matching last vtx at 0x{:X}", w1, lOffset); - GFXDOverride::RegisterVTXOverlap(w1, search.value()); + if(adjPtr > lOffset && adjPtr <= lOffset + lSize){ + SPDLOG_INFO("Found vtx at 0x{:X} matching last vtx at 0x{:X}", adjPtr, lOffset); + GFXDOverride::RegisterVTXOverlap(adjPtr, search.value()); } } else { YAML::Node vtx; vtx["type"] = "VTX"; - vtx["offset"] = w1; + vtx["offset"] = adjPtr; vtx["count"] = nvtx; Companion::Instance->AddAsset(vtx); } diff --git a/src/factories/DisplayListOverrides.cpp b/src/factories/DisplayListOverrides.cpp index 1f7c07f..59a7344 100644 --- a/src/factories/DisplayListOverrides.cpp +++ b/src/factories/DisplayListOverrides.cpp @@ -52,6 +52,7 @@ void Quadrangle(const N64Gfx* gfx) { } int Vtx(uint32_t ptr, int32_t num) { + ptr = Companion::Instance->PatchVirtualAddr(ptr); auto vtx = GetVtxOverlap(ptr); if(vtx.has_value()){