summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKiritoDv <kiritodev01@gmail.com>2025-08-12 01:14:33 -0600
committerKiritoDv <kiritodev01@gmail.com>2025-08-12 01:14:33 -0600
commitcb68cf1bf2b3d24562e63f78a33a6419bd0864e9 (patch)
tree89f006e60d520bbaa71eb5fa8fa56dbbd56f788c /src
parent8bf444f1e9c8d0a9e5c28d0150be435e52d80ade (diff)
Fixed torch to build on emscripten
Diffstat (limited to 'src')
-rw-r--r--src/Companion.cpp49
-rw-r--r--src/lib/web.cpp53
-rw-r--r--src/main.cpp4
3 files changed, 81 insertions, 25 deletions
diff --git a/src/Companion.cpp b/src/Companion.cpp
index 1f865af..73e1923 100644
--- a/src/Companion.cpp
+++ b/src/Companion.cpp
@@ -210,8 +210,9 @@ void Companion::Init(const ExportType type) {
this->RegisterFactory("NAUDIO:V1:ADPCM_BOOK", std::make_shared<ADPCMBookFactory>());
this->RegisterFactory("NAUDIO:V1:SEQUENCE", std::make_shared<NSequenceFactory>());
#endif
-
+#ifndef __EMSCRIPTEN__ // We call this manually
this->Process();
+#else
}
void Companion::ParseEnums(std::string& header) {
@@ -1038,7 +1039,7 @@ void Companion::Process() {
auto hash = this->gCartridge->GetHash();
- SPDLOG_INFO("ROM decompressed to {}", hash);
+ SPDLOG_CRITICAL("ROM decompressed to {}", hash);
if (hash != target) {
throw std::runtime_error("Hash mismatch");
@@ -1204,23 +1205,25 @@ void Companion::Process() {
this->ParseHash();
- SPDLOG_INFO("------------------------------------------------");
+ SPDLOG_CRITICAL("------------------------------------------------");
spdlog::set_pattern(line);
- SPDLOG_INFO("Starting Torch...");
+ SPDLOG_CRITICAL("Starting Torch...");
if(this->gConfig.parseMode == ParseMode::Default) {
- 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);
+ SPDLOG_CRITICAL("Game: {}", this->gCartridge->GetGameTitle());
+ SPDLOG_CRITICAL("CRC: {}", this->gCartridge->GetCRC());
+ SPDLOG_CRITICAL("Version: {}", this->gCartridge->GetVersion());
+ SPDLOG_CRITICAL("Country: [{}]", this->gCartridge->GetCountryCode());
+ SPDLOG_CRITICAL("Hash: {}", this->gCartridge->GetHash());
+ SPDLOG_CRITICAL("Assets: {}", this->gAssetPath);
} else {
- SPDLOG_INFO("Mode: Directory");
- SPDLOG_INFO("Directory: {}", rom["folder"].as<std::string>());
+ SPDLOG_CRITICAL("Mode: Directory");
+ SPDLOG_CRITICAL("Directory: {}", rom["folder"].as<std::string>());
}
+ SPDLOG_CRITICAL("------------------------------------------------");
+
AudioManager::Instance = new AudioManager();
BinaryWrapper* wrapper = nullptr;
@@ -1278,7 +1281,7 @@ void Companion::Process() {
}
if(wrapper != nullptr) {
- SPDLOG_INFO("Writing version file");
+ SPDLOG_CRITICAL("Writing version file");
wrapper->AddFile("version", vWriter.ToVector());
vWriter.Close();
wrapper->Close();
@@ -1292,10 +1295,10 @@ void Companion::Process() {
auto end = duration_cast<milliseconds>(system_clock::now().time_since_epoch());
auto level = spdlog::get_level();
spdlog::set_level(spdlog::level::info);
- SPDLOG_INFO("Done! Took {}ms", end.count() - start.count());
+ SPDLOG_CRITICAL("Done! Took {}ms", end.count() - start.count());
+ SPDLOG_CRITICAL("------------------------------------------------");
spdlog::set_level(level);
spdlog::set_pattern(regular);
- SPDLOG_INFO("------------------------------------------------");
Decompressor::ClearCache();
this->gCartridge = nullptr;
@@ -1307,10 +1310,10 @@ void Companion::Pack(const std::string& folder, const std::string& output, const
spdlog::set_level(spdlog::level::debug);
spdlog::set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%l] %v");
- SPDLOG_INFO("------------------------------------------------");
+ SPDLOG_CRITICAL("------------------------------------------------");
- SPDLOG_INFO("Starting Torch...");
- SPDLOG_INFO("Scanning {}", folder);
+ SPDLOG_CRITICAL("Starting Torch...");
+ SPDLOG_CRITICAL("Scanning {}", folder);
auto start = duration_cast<milliseconds>(system_clock::now().time_since_epoch());
std::unordered_map<std::string, std::vector<char>> files;
@@ -1345,14 +1348,14 @@ void Companion::Pack(const std::string& folder, const std::string& output, const
// Remove parent folder
normalized = normalized.substr(folder.length() + 1);
wrapper->AddFile(normalized, data);
- SPDLOG_INFO("> Added {}", normalized);
+ SPDLOG_CRITICAL("> Added {}", normalized);
}
auto end = duration_cast<milliseconds>(system_clock::now().time_since_epoch());
- SPDLOG_INFO("Done! Took {}ms", end.count() - start.count());
- SPDLOG_INFO("Exported to {}", output);
+ SPDLOG_CRITICAL("Done! Took {}ms", end.count() - start.count());
+ SPDLOG_CRITICAL("Exported to {}", output);
spdlog::set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%l] %v");
- SPDLOG_INFO("------------------------------------------------");
+ SPDLOG_CRITICAL("------------------------------------------------");
wrapper->Close();
}
@@ -1380,7 +1383,7 @@ std::optional<std::tuple<std::string, YAML::Node>> Companion::RegisterAsset(cons
void Companion::RegisterFactory(const std::string& type, const std::shared_ptr<BaseFactory>& factory) {
this->gFactories[type] = factory;
- SPDLOG_DEBUG("Registered factory for {}", type);
+ SPDLOG_INFO("Registered factory for {}", type);
}
std::optional<std::shared_ptr<BaseFactory>> Companion::GetFactory(const std::string &type) {
diff --git a/src/lib/web.cpp b/src/lib/web.cpp
new file mode 100644
index 0000000..eed9c26
--- /dev/null
+++ b/src/lib/web.cpp
@@ -0,0 +1,53 @@
+#ifdef __EMSCRIPTEN__
+#include "Companion.h"
+
+#include <emscripten/bind.h>
+using namespace emscripten;
+
+Companion* Companion::Instance;
+
+void Bind(Companion* instance) {
+ Companion::Instance = instance;
+}
+
+EMSCRIPTEN_BINDINGS(Torch) {
+ register_vector<uint8_t>("VectorUInt8");
+
+ function("Bind", &Bind, allow_raw_pointers());
+
+ enum_<ExportType>("ExportType")
+ .value("Header", ExportType::Header)
+ .value("Code", ExportType::Code)
+ .value("Binary", ExportType::Binary)
+ .value("Modding", ExportType::Modding)
+ .value("XML", ExportType::XML);
+
+ enum_<ArchiveType>("ArchiveType")
+ .value("None", ArchiveType::None)
+ .value("OTR", ArchiveType::OTR)
+ .value("O2R", ArchiveType::O2R);
+
+ enum_<N64::CountryCode>("CountryCode")
+ .value("Japan", N64::CountryCode::Japan)
+ .value("NorthAmerica", N64::CountryCode::NorthAmerica)
+ .value("Europe", N64::CountryCode::Europe)
+ .value("Unknown", N64::CountryCode::Unknown);
+
+ class_<N64::Cartridge>("Cartridge")
+ .function("GetGameTitle", &N64::Cartridge::GetGameTitle)
+ .function("GetCountryCode", &N64::Cartridge::GetCountryCode)
+ .function("GetCountry", &N64::Cartridge::GetCountry)
+ .function("GetVersion", &N64::Cartridge::GetVersion)
+ .function("GetHash", &N64::Cartridge::GetHash)
+ .function("GetCRC", &N64::Cartridge::GetCRC);
+
+ class_<Companion>("Companion")
+ .constructor<std::vector<uint8_t>, ArchiveType, bool, bool, std::string, std::string>()
+ .constructor<std::vector<uint8_t>, ArchiveType, bool, bool, std::string>()
+ .constructor<std::vector<uint8_t>, ArchiveType, bool, bool>()
+ .function("Init", &Companion::Init)
+ .function("GetCartridge", &Companion::GetCartridge, allow_raw_pointers())
+ .function("Process", &Companion::Process)
+ .function("GetRomData", &Companion::GetRomData, allow_raw_pointers());
+}
+#endif \ No newline at end of file
diff --git a/src/main.cpp b/src/main.cpp
index 6fb356f..b5ea9fc 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -2,9 +2,9 @@
#include "CLI11.hpp"
#include "Companion.h"
-Companion* Companion::Instance;
+#if defined(STANDALONE) && !defined(__EMSCRIPTEN__)
-#ifdef STANDALONE
+Companion* Companion::Instance;
int main(int argc, char *argv[]) {
CLI::App app{"Torch - [T]orch is [O]ur [R]esource [C]onversion [H]elper\n\