From e6de326810c4f56810e98d4e2812995df29bfbb9 Mon Sep 17 00:00:00 2001 From: KiritoDv Date: Mon, 29 Apr 2024 12:58:04 -0600 Subject: Added support for external files instead of a rom --- src/Companion.cpp | 66 +++++++++++++++++++++++++++++++++++++++---------------- src/Companion.h | 6 +++++ 2 files changed, 53 insertions(+), 19 deletions(-) diff --git a/src/Companion.cpp b/src/Companion.cpp index ecc400e..d87ec7f 100644 --- a/src/Companion.cpp +++ b/src/Companion.cpp @@ -223,8 +223,14 @@ std::optional Companion::ParseNode(YAML::Node& node, std::strin input.close(); result = impl->parse_modding(data, node); - } else { + } else if(this->gConfig.parseMode == ParseMode::Default) { result = impl->parse(this->gRomData, node); + } else if(this->gConfig.parseMode == ParseMode::Directory) { + auto path = GetSafeNode(node, "path"); + std::ifstream input( path, std::ios::binary ); + auto data = std::vector( std::istreambuf_iterator( input ), {} ); + result = impl->parse(data, node); + input.close(); } if(!result.has_value()){ @@ -910,26 +916,32 @@ void Companion::Process() { } auto start = duration_cast(system_clock::now().time_since_epoch()); + YAML::Node config = YAML::LoadFile("config.yml"); - std::ifstream input( this->gRomPath, std::ios::binary ); - this->gRomData = std::vector( std::istreambuf_iterator( input ), {} ); - input.close(); + bool isDirectoryMode = config["mode"] && config["mode"].as() == "directory"; - this->gCartridge = std::make_shared(this->gRomData); - this->gCartridge->Initialize(); + if(!isDirectoryMode) { + std::ifstream input( this->gRomPath, std::ios::binary ); + this->gRomData = std::vector( std::istreambuf_iterator( input ), {} ); + input.close(); - YAML::Node config = YAML::LoadFile("config.yml"); + this->gCartridge = std::make_shared(this->gRomData); + this->gCartridge->Initialize(); - if(!config[this->gCartridge->GetHash()]){ - SPDLOG_ERROR("No config found for {}", this->gCartridge->GetHash()); - return; + if(!config[this->gCartridge->GetHash()]){ + SPDLOG_ERROR("No config found for {}", this->gCartridge->GetHash()); + return; + } + this->gConfig.parseMode = ParseMode::Default; + } else { + this->gConfig.parseMode = ParseMode::Directory; } - auto rom = config[this->gCartridge->GetHash()]; + auto rom = !isDirectoryMode ? config[this->gCartridge->GetHash()] : config; auto cfg = rom["config"]; if(!cfg) { - SPDLOG_ERROR("No config found for {}", this->gCartridge->GetHash()); + SPDLOG_ERROR("No config found for {}", !isDirectoryMode ? this->gCartridge->GetHash() : GetSafeNode(config, "folder")); return; } @@ -1052,12 +1064,19 @@ void Companion::Process() { spdlog::set_pattern(line); SPDLOG_INFO("Starting Torch..."); - SPDLOG_INFO("Game: {}", this->gCartridge->GetGameTitle()); - SPDLOG_INFO("CRC: {}", this->gCartridge->GetCRC()); - SPDLOG_INFO("Version: {}", this->gCartridge->GetVersion()); - SPDLOG_INFO("Country: [{}]", this->gCartridge->GetCountryCode()); - SPDLOG_INFO("Hash: {}", this->gCartridge->GetHash()); - SPDLOG_INFO("Assets: {}", this->gAssetPath); + + if(this->gConfig.parseMode == ParseMode::Default) { + SPDLOG_INFO("ROM: {}", this->gRomPath); + SPDLOG_INFO("Game: {}", this->gCartridge->GetGameTitle()); + SPDLOG_INFO("CRC: {}", this->gCartridge->GetCRC()); + SPDLOG_INFO("Version: {}", this->gCartridge->GetVersion()); + SPDLOG_INFO("Country: [{}]", this->gCartridge->GetCountryCode()); + SPDLOG_INFO("Hash: {}", this->gCartridge->GetHash()); + SPDLOG_INFO("Assets: {}", this->gAssetPath); + } else { + SPDLOG_INFO("Mode: Directory"); + SPDLOG_INFO("Directory: {}", rom["folder"].as()); + } AudioManager::Instance = new AudioManager(); auto wrapper = this->gConfig.exporterType == ExportType::Binary ? new SWrapper(this->gConfig.outputPath) : nullptr; @@ -1066,7 +1085,12 @@ void Companion::Process() { auto vWriter = LUS::BinaryWriter(); vWriter.SetEndianness(LUS::Endianness::Big); vWriter.Write(static_cast(LUS::Endianness::Big)); - vWriter.Write(this->gCartridge->GetCRC()); + + if(this->gConfig.parseMode == ParseMode::Default) { + vWriter.Write(this->gCartridge->GetCRC()); + } else { + vWriter.Write((uint32_t) 0); + } for (const auto & entry : fs::recursive_directory_iterator(this->gAssetPath)){ if(entry.is_directory()) { @@ -1079,6 +1103,10 @@ void Companion::Process() { continue; } + if(yamlPath.find("config.yml") != std::string::npos) { + continue; + } + YAML::Node root = YAML::LoadFile(yamlPath); this->gCurrentDirectory = relative(entry.path(), this->gAssetPath).replace_extension(""); this->gCurrentFile = yamlPath; diff --git a/src/Companion.h b/src/Companion.h index 26c9253..f8990b5 100644 --- a/src/Companion.h +++ b/src/Companion.h @@ -16,6 +16,11 @@ class SWrapper; namespace fs = std::filesystem; +enum class ParseMode { + Default, + Directory +}; + enum class GBIVersion { f3d, f3dex, @@ -73,6 +78,7 @@ struct TorchConfig { std::string outputPath; std::string moddingPath; ExportType exporterType; + ParseMode parseMode; bool otrMode; bool debug; bool modding; -- cgit v1.2.3