From c48e6290f8d224d0297f9124ea65721adc2b8d6e Mon Sep 17 00:00:00 2001 From: coco875 Date: Wed, 9 Jul 2025 00:22:59 +0200 Subject: Update Companion.cpp --- src/Companion.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'src/Companion.cpp') diff --git a/src/Companion.cpp b/src/Companion.cpp index 76b7ed2..35f63f5 100644 --- a/src/Companion.cpp +++ b/src/Companion.cpp @@ -115,6 +115,12 @@ static std::string ConvertType(std::string type) { return type; } +static std::string GetTypeNode(const YAML::Node& node) { + auto type = GetSafeNode(node, "type"); + std::transform(type.begin(), type.end(), type.begin(), toupper); + return type; +} + void Companion::Init(const ExportType type) { spdlog::set_level(spdlog::level::debug); @@ -257,7 +263,7 @@ void Companion::ParseEnums(std::string& header) { } std::optional Companion::ParseNode(YAML::Node& node, std::string& name) { - auto type = GetSafeNode(node, "type"); + auto type = GetTypeNode(node); std::transform(type.begin(), type.end(), type.begin(), ::toupper); spdlog::set_pattern(regular); @@ -594,7 +600,7 @@ void Companion::ProcessFile(YAML::Node root) { std::replace(output.begin(), output.end(), '\\', '/'); if(node["type"]){ - const auto type = GetSafeNode(node, "type"); + const auto type = GetTypeNode(node); if(type == "NAUDIO:V0:SAMPLE"){ AudioManager::Instance->bind_sample(node, output); } @@ -1017,11 +1023,11 @@ void Companion::Process() { auto item = job->second; auto method = GetSafeNode(item, "method"); if (method == "mio0-comptool") { - auto type = GetSafeNode(item, "type"); + auto type = GetTypeNode(item); auto target = GetSafeNode(item, "target"); auto restart = GetSafeNode(item, "restart"); - if (type == "decompress") { + if (type == "DECOMPRESS") { this->gRomData = CompTool::Decompress(this->gRomData); this->gCartridge = std::make_shared(this->gRomData); this->gCartridge->Initialize(); @@ -1460,9 +1466,9 @@ std::optional> Companion::GetSafeNodeByAddr( } auto [name, n] = node.value(); - auto n_type = GetSafeNode(n, "type"); + auto n_type = GetTypeNode(n); - if(ConvertType(n_type) != ConvertType(type)) { + 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: " + ConvertType(n_type) + " Expected: " + ConvertType(type)); } @@ -1539,7 +1545,7 @@ std::optional>> Companion::GetNo for(auto& [addr, tpl] : this->gAddrMap[this->gCurrentFile]){ auto [name, node] = tpl; - const auto n_type = GetSafeNode(node, "type"); + const auto n_type = GetTypeNode(node); if(node["autogen"]){ SPDLOG_DEBUG("Skipping autogenerated asset {}", name); continue; @@ -1577,15 +1583,15 @@ std::optional Companion::AddAsset(YAML::Node asset) { if(!asset["offset"] || !asset["type"]) { return std::nullopt; } - const auto type = GetSafeNode(asset, "type"); + const auto type = GetTypeNode(asset); const auto offset = GetSafeNode(asset, "offset"); const auto symbol = GetSafeNode(asset, "symbol", ""); const auto decl = this->GetNodeByAddr(offset); if(decl.has_value()) { auto found = std::get<1>(decl.value()); - if(ConvertType(GetSafeNode(found, "type")) != ConvertType(type)) { - SPDLOG_ERROR("Asset clash detected {} vs {} at 0x{:X}", ConvertType(type), ConvertType(GetSafeNode(found, "type")), offset); + if(GetTypeNode(found) != type) { + SPDLOG_ERROR("Asset clash detected {} vs {} at 0x{:X}", type, GetTypeNode(found), offset); } else { return found; } -- cgit v1.2.3