summaryrefslogtreecommitdiff
path: root/src/Companion.cpp
diff options
context:
space:
mode:
authorcoco875 <pereira.jannin@gmail.com>2025-08-12 03:43:45 +0200
committerLywx <kiritodev01@gmail.com>2025-12-01 12:39:42 -0600
commitb47ba0a853801be397f69b856f22f9788e2b5f30 (patch)
tree5bc5478c160aa484b39cbe77a1d13d0cb1fdddb7 /src/Companion.cpp
parent804d46a2df8d54885ce339f868cde6bdce0fff0a (diff)
add manual_segments
Diffstat (limited to 'src/Companion.cpp')
-rw-r--r--src/Companion.cpp53
1 files changed, 53 insertions, 0 deletions
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<uint32_t>();
+ const auto replacement = segment[1].as<std::string>();
+ 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 - [<addr>, <replacement>]\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<std::tuple<std::string, YAML::Node>> Companion::GetNodeByAddr(uint
return this->gAddrMap[this->gCurrentFile][addr];
}
+std::optional<std::string> 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<std::tuple<std::string, YAML::Node>> Companion::GetSafeNodeByAddr(const uint32_t addr, std::string type) {
auto node = this->GetNodeByAddr(addr);
@@ -1500,6 +1532,27 @@ std::optional<std::tuple<std::string, YAML::Node>> Companion::GetSafeNodeByAddr(
}
+std::optional<std::string> 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;