summaryrefslogtreecommitdiff
path: root/src/Companion.cpp
diff options
context:
space:
mode:
authorKiritoDv <kiritodev01@gmail.com>2023-08-17 00:40:00 -0600
committerKiritoDv <kiritodev01@gmail.com>2023-08-17 00:40:00 -0600
commit1c5b3de55c72dca9a16c58a0f4dba3eee9b1f8e6 (patch)
treeb6d3cdb0411b0e0ef8e802516fd6f65462d79c1b /src/Companion.cpp
parent6fd8e5ee43dd0f87eb4e57b86e84770fcd95db25 (diff)
Starting CUBE-OS v0.1...
Diffstat (limited to 'src/Companion.cpp')
-rw-r--r--src/Companion.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/Companion.cpp b/src/Companion.cpp
new file mode 100644
index 0000000..a5fcb1b
--- /dev/null
+++ b/src/Companion.cpp
@@ -0,0 +1,60 @@
+#include "Companion.h"
+
+#include "storm/SWrapper.h"
+#include "utils/MIODecoder.h"
+#include "factories/RawFactory.h"
+#include "factories/TextureFactory.h"
+
+#include <fstream>
+#include <iostream>
+#include <filesystem>
+#include <nlohmann/json.hpp>
+
+using json = nlohmann::json;
+namespace fs = std::filesystem;
+
+static const std::unordered_map<std::string, RawFactory*> gFactories = {
+ { ".png", new TextureFactory() }
+};
+
+void Companion::Start() {
+ std::cout << "Super Mario 64 Rom Path: " << this->gRomPath << '\n';
+
+ std::ifstream input( this->gRomPath, std::ios::binary );
+ this->gRomData = std::vector<uint8_t>( std::istreambuf_iterator<char>( input ), {} );
+ input.close();
+
+ // TODO: Validate hash
+
+ std::cout << "Detected Rom Size: " << this->gRomData.size() << '\n';
+
+ this->ProcessAssets();
+}
+
+void Companion::ProcessAssets() {
+ json assets = json::parse( std::ifstream( "assets.json" ) );
+
+ SWrapper wrapper = SWrapper("smcube.otr");
+
+ for( auto& [asset, data] : assets.items() ) {
+ std::string extension = fs::path(asset).extension().string();
+ if( gFactories.find(extension) == gFactories.end() ) {
+ std::cout << "No factory found for " << asset << '\n';
+ continue;
+ }
+ LUS::BinaryWriter write = LUS::BinaryWriter();
+ std::string path = asset.substr(0, asset.find_last_of('.'));
+ json entry = {
+ { "path", path },
+ { "offsets", data }
+ };
+ gFactories.at(extension)->process(&write, entry, this->gRomData);
+
+ auto buffer = write.ToVector();
+ wrapper.CreateFile(path, buffer);
+ write.Close();
+ }
+
+ MIO0Decoder::ClearCache();
+ wrapper.Close();
+} \ No newline at end of file