From a4f96f6cabf98da6987ed6e32e6bbcd88f587400 Mon Sep 17 00:00:00 2001 From: KiritoDv Date: Sun, 24 Sep 2023 15:59:09 -0600 Subject: [PATCH] Added flag to work as a library --- CMakeLists.txt | 8 +++++++- src/Companion.cpp | 1 + src/factories/BankFactory.cpp | 3 +-- src/factories/RawFactory.h | 9 +++++++++ src/main.cpp | 4 +++- 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 015d559..03e025d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,12 +13,18 @@ file(GLOB C_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.c ${CMAKE_CURRENT_SOURCE_DIR set(SRC_DIR ${CXX_FILES} ${C_FILES}) set(CMAKE_CXX_FLAGS_RELEASE "-O3") +set(USE_STANDALONE ON) set(VPKTOOL_BUILD_GUI OFF) set(VPKTOOL_BUILD_TESTS OFF) set(VPKTOOL_BUILD_INSTALLER OFF) # Build -add_executable(${PROJECT_NAME} ${SRC_DIR}) +if (USE_STANDALONE) + add_definitions(-DSTANDALONE) + add_executable(${PROJECT_NAME} ${SRC_DIR}) +else() + add_library(${PROJECT_NAME} SHARED ${SRC_DIR}) +endif() # Fetch Dependencies add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/binarytools) diff --git a/src/Companion.cpp b/src/Companion.cpp index 2528ce9..41d5a65 100644 --- a/src/Companion.cpp +++ b/src/Companion.cpp @@ -97,6 +97,7 @@ void Companion::Process() { LUS::BinaryWriter write = LUS::BinaryWriter(); RawFactory* factory = this->GetFactory(type); + factory->SetCartridge(cartridge); spdlog::set_pattern(regular); SPDLOG_INFO("------------------------------------------------"); diff --git a/src/factories/BankFactory.cpp b/src/factories/BankFactory.cpp index f247c3d..d388c22 100644 --- a/src/factories/BankFactory.cpp +++ b/src/factories/BankFactory.cpp @@ -4,14 +4,13 @@ #include "audio/AudioManager.h" #include "audio/samples_table.h" #include "binarytools/BinaryReader.h" -#include "Companion.h" bool BankFactory::process(LUS::BinaryWriter* writer, YAML::Node& data, std::vector& buffer) { auto banks = AudioManager::Instance->get_banks(); auto bankId = data["id"].as(); auto bank = banks[bankId]; - auto gSampleTable = Companion::Instance->GetCartridge()->GetCountry() == N64::CountryCode::Japan ? gJPSampleTable : gUSSampleTable; + auto gSampleTable = this->GetCartridge()->GetCountry() == N64::CountryCode::Japan ? gJPSampleTable : gUSSampleTable; WRITE_HEADER(LUS::ResourceType::Bank, 0); diff --git a/src/factories/RawFactory.h b/src/factories/RawFactory.h index 9a23d71..89f35df 100644 --- a/src/factories/RawFactory.h +++ b/src/factories/RawFactory.h @@ -1,6 +1,7 @@ #pragma once #include "ResourceType.h" +#include "n64/Cartridge.h" #include #include #include @@ -27,4 +28,12 @@ public: RawFactory() = default; virtual bool process(LUS::BinaryWriter* write, YAML::Node& data, std::vector& buffer) = 0; void WriteHeader(LUS::BinaryWriter* write, LUS::ResourceType resType, int32_t version); + inline void SetCartridge(N64::Cartridge* cart) { + this->cartdrige = cart; + } + inline N64::Cartridge* GetCartridge() { + return this->cartdrige; + } +private: + N64::Cartridge* cartdrige; }; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index ab1f8d3..3149b66 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,6 +2,7 @@ #include "CLI11.hpp" #include "Companion.h" +#ifdef STANDALONE Companion* Companion::Instance; int main(int argc, char *argv[]) { @@ -19,4 +20,5 @@ int main(int argc, char *argv[]) { Companion::Instance = new Companion(filename); Companion::Instance->Init(); return 0; -} \ No newline at end of file +} +#endif \ No newline at end of file