diff options
Diffstat (limited to 'src/Companion.cpp')
| -rw-r--r-- | src/Companion.cpp | 162 |
1 files changed, 63 insertions, 99 deletions
diff --git a/src/Companion.cpp b/src/Companion.cpp index e16c670..6b813b5 100644 --- a/src/Companion.cpp +++ b/src/Companion.cpp @@ -454,6 +454,7 @@ std::string ExportTypeToString(ExportType type) { case ExportType::Header: return "Header"; case ExportType::Code: return "Code"; case ExportType::Modding: return "Modding"; + case ExportType::XML: return "XML"; default: throw std::runtime_error("Invalid ExportType"); } @@ -559,66 +560,31 @@ void Companion::ProcessFile(YAML::Node root) { auto node = asset->second; auto entryName = asset->first.as<std::string>(); - // Parse horizontal assets - if(node["files"]){ - auto segment = node["segment"] ? node["segment"].as<uint8_t>() : -1; - const auto files = node["files"]; - for (const auto& file : files) { - auto assetNode = file.as<YAML::Node>(); - auto childName = assetNode["name"].as<std::string>(); - auto output = (this->gCurrentDirectory / entryName / childName).string(); - std::replace(output.begin(), output.end(), '\\', '/'); - - if(assetNode["type"]){ - const auto type = GetSafeNode<std::string>(assetNode, "type"); - if(type == "SAMPLE"){ - AudioManager::Instance->bind_sample(assetNode, output); - } - } - - if(!assetNode["offset"]) { - continue; - } - - if(segment != -1 || gCurrentSegmentNumber) { - assetNode["offset"] = (segment << 24) | assetNode["offset"].as<uint32_t>(); - } - - if(!gCurrentVirtualPath.empty()) { - node["path"] = gCurrentVirtualPath; - } - - this->gAddrMap[this->gCurrentFile][assetNode["offset"].as<uint32_t>()] = std::make_tuple(output, assetNode); - } - } else { - - auto output = (this->gCurrentDirectory / entryName).string(); - std::replace(output.begin(), output.end(), '\\', '/'); + auto output = (this->gCurrentDirectory / entryName).string(); + std::replace(output.begin(), output.end(), '\\', '/'); - - if(node["type"]){ - const auto type = GetSafeNode<std::string>(node, "type"); - if(type == "SAMPLE"){ - AudioManager::Instance->bind_sample(node, output); - } - } - - if(!node["offset"]) { - continue; + if(node["type"]){ + const auto type = GetSafeNode<std::string>(node, "type"); + if(type == "SAMPLE"){ + AudioManager::Instance->bind_sample(node, output); } + } - if(gCurrentSegmentNumber) { - if (IS_SEGMENTED(node["offset"].as<uint32_t>()) == false) { - node["offset"] = (gCurrentSegmentNumber << 24) | node["offset"].as<uint32_t>(); - } - } + if(!node["offset"]) { + continue; + } - if(!gCurrentVirtualPath.empty()) { - node["path"] = gCurrentVirtualPath; + if(gCurrentSegmentNumber) { + if (IS_SEGMENTED(node["offset"].as<uint32_t>()) == false) { + node["offset"] = (gCurrentSegmentNumber << 24) | node["offset"].as<uint32_t>(); } + } - this->gAddrMap[this->gCurrentFile][node["offset"].as<uint32_t>()] = std::make_tuple(output, node); + if(!gCurrentVirtualPath.empty()) { + node["path"] = gCurrentVirtualPath; } + + this->gAddrMap[this->gCurrentFile][node["offset"].as<uint32_t>()] = std::make_tuple(output, node); } // Stupid hack because the iteration broke the assets @@ -656,53 +622,23 @@ void Companion::ProcessFile(YAML::Node root) { continue; } - // Parse horizontal assets - if(assetNode["files"]){ - auto segment = assetNode["segment"] ? assetNode["segment"].as<uint8_t>() : -1; - auto files = assetNode["files"]; - for (const auto& file : files) { - auto node = file.as<YAML::Node>(); - auto childName = node["name"].as<std::string>(); - - if(!node["offset"]) { - continue; - } - - if(segment != -1 || gCurrentFileOffset) { - node["offset"] = (segment << 24) | node["offset"].as<uint32_t>(); - } - - if(!gCurrentVirtualPath.empty()) { - node["path"] = gCurrentVirtualPath; - } - - auto output = (this->gCurrentDirectory / entryName / childName).string(); - std::replace(output.begin(), output.end(), '\\', '/'); - this->gConfig.segment.temporal.clear(); - auto result = this->ParseNode(node, output); - if(result.has_value()) { - this->gParseResults[this->gCurrentFile].push_back(result.value()); - } - } - } else { - if(gCurrentFileOffset && assetNode["offset"]) { - const auto offset = assetNode["offset"].as<uint32_t>(); - if (!IS_SEGMENTED(offset)) { - assetNode["offset"] = (gCurrentSegmentNumber << 24) | offset; - } + if(gCurrentFileOffset && assetNode["offset"]) { + const auto offset = assetNode["offset"].as<uint32_t>(); + if (!IS_SEGMENTED(offset)) { + assetNode["offset"] = (gCurrentSegmentNumber << 24) | offset; } + } - if(!gCurrentVirtualPath.empty()) { - assetNode["path"] = gCurrentVirtualPath; - } + if(!gCurrentVirtualPath.empty()) { + assetNode["path"] = gCurrentVirtualPath; + } - std::string output = (this->gCurrentDirectory / entryName).string(); - std::replace(output.begin(), output.end(), '\\', '/'); - this->gConfig.segment.temporal.clear(); - auto result = this->ParseNode(assetNode, output); - if(result.has_value()) { - this->gParseResults[this->gCurrentFile].push_back(result.value()); - } + std::string output = (this->gCurrentDirectory / entryName).string(); + std::replace(output.begin(), output.end(), '\\', '/'); + this->gConfig.segment.temporal.clear(); + auto result = this->ParseNode(assetNode, output); + if(result.has_value()) { + this->gParseResults[this->gCurrentFile].push_back(result.value()); } spdlog::set_pattern(regular); @@ -730,8 +666,16 @@ void Companion::ProcessFile(YAML::Node root) { exporter->get()->Export(stream, data, result.name, result.node, &result.name); auto data = stream.str(); this->gCurrentWrapper->CreateFile(result.name, std::vector(data.begin(), data.end())); + + for(auto& entry : this->gCompanionFiles){ + auto output = (this->gCurrentDirectory / entry.first).string(); + std::replace(output.begin(), output.end(), '\\', '/'); + this->gCurrentWrapper->CreateFile(output, entry.second); + } + break; } + case ExportType::XML: case ExportType::Modding: { stream.str(""); stream.clear(); @@ -748,12 +692,24 @@ void Companion::ProcessFile(YAML::Node root) { create_directories(fs::path(dpath).parent_path()); } - SPDLOG_INFO(ogname); this->gModdedAssetPaths[ogname] = result.name; std::ofstream file(dpath, std::ios::binary); file.write(data.c_str(), data.size()); file.close(); + + for(auto& entry : this->gCompanionFiles){ + auto cpath = (Instance->GetOutputPath() / this->gCurrentDirectory / entry.first).string(); + std::replace(cpath.begin(), cpath.end(), '\\', '/'); + if(!exists(fs::path(cpath).parent_path())){ + create_directories(fs::path(cpath).parent_path()); + } + + std::ofstream cfile(cpath, std::ios::binary); + cfile.write(entry.second.data(), entry.second.size()); + cfile.close(); + } + break; } default: { @@ -762,6 +718,8 @@ void Companion::ProcessFile(YAML::Node root) { } } + this->gCompanionFiles.clear(); + if(result.node["offset"]) { auto alignment = GetSafeNode<uint32_t>(result.node, "alignment", impl->GetAlignment()); if(!endptr.has_value()) { @@ -807,7 +765,7 @@ void Companion::ProcessFile(YAML::Node root) { auto fsout = fs::path(this->gConfig.outputPath); - if(this->gConfig.exporterType == ExportType::Modding) { + if(this->gConfig.exporterType == ExportType::Modding || this->gConfig.exporterType == ExportType::XML) { fsout /= "modding.yml"; YAML::Node modding; @@ -1048,6 +1006,7 @@ void Companion::Process() { this->gConfig.outputPath = opath && opath["code"] ? opath["code"].as<std::string>() : "code"; break; } + case ExportType::XML: case ExportType::Modding: { this->gConfig.outputPath = modding_path; break; @@ -1420,6 +1379,11 @@ std::optional<std::vector<std::tuple<std::string, YAML::Node>>> Companion::GetNo } +void Companion::RegisterCompanionFile(const std::string path, std::vector<char> data) { + this->gCompanionFiles[path] = data; + SPDLOG_INFO("Registered companion file {}", path); +} + std::string Companion::NormalizeAsset(const std::string& name) const { auto path = fs::path(this->gCurrentFile).stem().string() + "_" + name; return path; |
