From b47ba0a853801be397f69b856f22f9788e2b5f30 Mon Sep 17 00:00:00 2001 From: coco875 Date: Tue, 12 Aug 2025 03:43:45 +0200 Subject: add manual_segments --- src/Companion.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'src/Companion.cpp') diff --git a/src/Companion.cpp b/src/Companion.cpp index 231b24c..d5cb096 100644 --- a/src/Companion.cpp +++ b/src/Companion.cpp @@ -400,6 +400,23 @@ void Companion::ParseCurrentFileConfig(YAML::Node node) { } } + if(node["manual_segments"]) { + auto manualSegments = node["manual_segments"]; + if (manualSegments.IsSequence() && manualSegments.size()) { + for(size_t i = 0; i < manualSegments.size(); i++) { + auto segment = manualSegments[i]; + if (segment.IsSequence() && segment.size() == 2) { + const auto id = segment[0].as(); + const auto replacement = segment[1].as(); + this->gManualSegments[id] = replacement; + SPDLOG_DEBUG("Manual Segment {} replaced with {}", id, replacement); + } else { + throw std::runtime_error("Incorrect yaml syntax for manual segments.\n\nThe yaml expects:\n:config:\n manual_segments:\n - [, ]\n\nLike so:\nmanual_segments:\n - [0x05000000, \"textures/other_textures/texture_6447C4\"]"); + } + } + } + } + if(node["segments"]) { auto segments = node["segments"]; @@ -646,6 +663,7 @@ void Companion::ProcessFile(YAML::Node root) { this->gCurrentFileOffset = 0; this->gTables.clear(); this->gCurrentExternalFiles.clear(); + this->gManualSegments.clear(); GFXDOverride::ClearVtx(); if(root[":config"]) { @@ -1482,6 +1500,20 @@ std::optional> Companion::GetNodeByAddr(uint return this->gAddrMap[this->gCurrentFile][addr]; } +std::optional Companion::GetStringByAddr(const uint32_t addr) { + if(this->gManualSegments.contains(addr)) { + return this->gManualSegments[addr]; + } + + auto node = this->GetNodeByAddr(addr); + + if(!node.has_value()) { + return std::nullopt; + } + + return std::get<0>(node.value()); +} + std::optional> Companion::GetSafeNodeByAddr(const uint32_t addr, std::string type) { auto node = this->GetNodeByAddr(addr); @@ -1500,6 +1532,27 @@ std::optional> Companion::GetSafeNodeByAddr( } +std::optional Companion::GetSafeStringByAddr(const uint32_t addr, std::string type) { + if(this->gManualSegments.contains(addr)) { + return this->gManualSegments[addr]; + } + + auto node = this->GetNodeByAddr(addr); + + if(!node.has_value()) { + return std::nullopt; + } + + auto [name, n] = node.value(); + auto n_type = GetTypeNode(n); + + if(n_type != type) { + throw std::runtime_error("Requested node type does not match with the target node type at " + Torch::to_hex(addr, false) + " Found: " + n_type + " Expected: " + type); + } + + return std::get<0>(node.value()); +} + std::string Companion::GetSymbolFromAddr(uint32_t address, bool validZero) { auto dec = Companion::Instance->GetNodeByAddr(address); std::ostringstream outSymbol; -- cgit v1.2.3