summaryrefslogtreecommitdiff
path: root/src/Companion.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Companion.cpp')
-rw-r--r--src/Companion.cpp40
1 files changed, 39 insertions, 1 deletions
diff --git a/src/Companion.cpp b/src/Companion.cpp
index 3fca4e3..199d649 100644
--- a/src/Companion.cpp
+++ b/src/Companion.cpp
@@ -79,6 +79,8 @@
#include "factories/naudio/v1/BookFactory.h"
#include "factories/naudio/v1/SequenceFactory.h"
+#include "preprocess/CompTool.h"
+
using namespace std::chrono;
namespace fs = std::filesystem;
@@ -1013,8 +1015,44 @@ void Companion::Process() {
}
auto rom = !isDirectoryMode ? config[this->gCartridge->GetHash()] : config;
- auto cfg = rom["config"];
+ if(rom["preprocess"]) {
+ auto preprocess = rom["preprocess"];
+ for(auto job = preprocess.begin(); job != preprocess.end(); job++) {
+ auto name = job->first.as<std::string>();
+ auto item = job->second;
+ auto method = GetSafeNode<std::string>(item, "method");
+ if (method == "mio0-comptool") {
+ auto type = GetSafeNode<std::string>(item, "type");
+ auto target = GetSafeNode<std::string>(item, "target");
+ auto restart = GetSafeNode<bool>(item, "restart");
+
+ if (type == "decompress") {
+ this->gRomData = CompTool::Decompress(this->gRomData);
+ this->gCartridge = std::make_shared<N64::Cartridge>(this->gRomData);
+ this->gCartridge->Initialize();
+
+ auto hash = this->gCartridge->GetHash();
+
+ SPDLOG_INFO("ROM decompressed to {}", hash);
+
+ if (hash != target) {
+ throw std::runtime_error("Hash mismatch");
+ }
+
+ if(restart){
+ rom = config[this->gCartridge->GetHash()];
+ }
+ } else {
+ throw std::runtime_error("Only decompression is supported");
+ }
+ } else {
+ throw std::runtime_error("Invalid preprocess method");
+ }
+ }
+ }
+
+ auto cfg = rom["config"];
if(!cfg) {
SPDLOG_ERROR("No config found for {}", !isDirectoryMode ? this->gCartridge->GetHash() : GetSafeNode<std::string>(config, "folder"));
return;