summaryrefslogtreecommitdiff
path: root/src/Companion.cpp
diff options
context:
space:
mode:
authorcoco875 <pereira.jannin@gmail.com>2025-07-09 00:22:59 +0200
committerLywx <kiritodev01@gmail.com>2025-07-08 20:32:34 -0600
commitc48e6290f8d224d0297f9124ea65721adc2b8d6e (patch)
treeed0e2dc18520ddee37eb93559d07a269af5c051e /src/Companion.cpp
parent9449a38a0b594dc0557cf61a5a09ec286b66113e (diff)
Update Companion.cpp
Diffstat (limited to 'src/Companion.cpp')
-rw-r--r--src/Companion.cpp26
1 files changed, 16 insertions, 10 deletions
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<std::string>(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<ParseResultData> Companion::ParseNode(YAML::Node& node, std::string& name) {
- auto type = GetSafeNode<std::string>(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<std::string>(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<std::string>(item, "method");
if (method == "mio0-comptool") {
- auto type = GetSafeNode<std::string>(item, "type");
+ auto type = GetTypeNode(item);
auto target = GetSafeNode<std::string>(item, "target");
auto restart = GetSafeNode<bool>(item, "restart");
- if (type == "decompress") {
+ if (type == "DECOMPRESS") {
this->gRomData = CompTool::Decompress(this->gRomData);
this->gCartridge = std::make_shared<N64::Cartridge>(this->gRomData);
this->gCartridge->Initialize();
@@ -1460,9 +1466,9 @@ std::optional<std::tuple<std::string, YAML::Node>> Companion::GetSafeNodeByAddr(
}
auto [name, n] = node.value();
- auto n_type = GetSafeNode<std::string>(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<std::vector<std::tuple<std::string, YAML::Node>>> Companion::GetNo
for(auto& [addr, tpl] : this->gAddrMap[this->gCurrentFile]){
auto [name, node] = tpl;
- const auto n_type = GetSafeNode<std::string>(node, "type");
+ const auto n_type = GetTypeNode(node);
if(node["autogen"]){
SPDLOG_DEBUG("Skipping autogenerated asset {}", name);
continue;
@@ -1577,15 +1583,15 @@ std::optional<YAML::Node> Companion::AddAsset(YAML::Node asset) {
if(!asset["offset"] || !asset["type"]) {
return std::nullopt;
}
- const auto type = GetSafeNode<std::string>(asset, "type");
+ const auto type = GetTypeNode(asset);
const auto offset = GetSafeNode<uint32_t>(asset, "offset");
const auto symbol = GetSafeNode<std::string>(asset, "symbol", "");
const auto decl = this->GetNodeByAddr(offset);
if(decl.has_value()) {
auto found = std::get<1>(decl.value());
- if(ConvertType(GetSafeNode<std::string>(found, "type")) != ConvertType(type)) {
- SPDLOG_ERROR("Asset clash detected {} vs {} at 0x{:X}", ConvertType(type), ConvertType(GetSafeNode<std::string>(found, "type")), offset);
+ if(GetTypeNode(found) != type) {
+ SPDLOG_ERROR("Asset clash detected {} vs {} at 0x{:X}", type, GetTypeNode(found), offset);
} else {
return found;
}