From 7da8ae8e25d6c1267792941bf9ac56c1acc384ae Mon Sep 17 00:00:00 2001 From: Lywx Date: Wed, 15 Jan 2025 19:29:27 -0600 Subject: [PATCH] Added options to have a better lib implementation (#158) * Added options to have a better lib implementation * Cleaned up possible conflicts * Fixed compilation errors * Fixed more compilation errors * Compiled library on windows as MT * Fixed MT * Readded cmake deps * Fixed stormlib and some ifdefs * Added an option to ignore cache * Added no auto link when working as an standalone * Fixes for torchlib build/inclusion. * Fix standalone building. Fix extraction initialization in lib mode. * Fix stack size declaration. * Implemented comptool and preprocess system * Fixed cmake * Cleaned up a little bit * Added support for disabling stormlib * Fixed compilation errors and added support for disabling fzero and naudio * Renamed from CreateFile to AddFile because windows is stupid * Added STORMLIB_NO_AUTO_LINK * Trying to fix windows again * Fixed spdlog * Fixed enum parsing --------- Co-authored-by: Malkierian Co-authored-by: Malkierian --- CMakeLists.txt | 158 ++++++++++++------ lib/binarytools/BinaryReader.cpp | 4 +- lib/binarytools/BinaryWriter.cpp | 4 +- src/Companion.cpp | 39 +++-- src/archive/BinaryWrapper.h | 2 +- src/archive/SWrapper.cpp | 14 +- src/archive/SWrapper.h | 8 +- src/archive/ZWrapper.cpp | 2 +- src/archive/ZWrapper.h | 2 +- src/factories/DisplayListFactory.cpp | 29 ++-- src/factories/DisplayListFactory.h | 4 + src/factories/DisplayListOverrides.cpp | 14 +- src/factories/DisplayListOverrides.h | 22 +-- src/factories/naudio/v0/AIFCDecode.cpp | 4 +- src/factories/naudio/v0/AIFCDecode.h | 2 +- src/factories/naudio/v0/AudioManager.cpp | 2 +- src/factories/naudio/v0/AudioManager.h | 2 +- src/factories/sf64/ScriptFactory.cpp | 2 +- src/factories/sf64/SkeletonFactory.cpp | 2 +- src/factories/sm64/behavior/BehaviorCommand.h | 2 +- src/factories/sm64/geo/GeoCommand.h | 2 +- src/factories/sm64/level/LevelCommand.h | 2 +- src/n64/Cartridge.cpp | 2 +- src/n64/gbi-otr.h | 30 ++-- 24 files changed, 227 insertions(+), 127 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ce9dd62..3b29309 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,17 @@ include(FetchContent) set(CMAKE_CXX_STANDARD 20) set(CMAKE_C_STANDARD 11) +# Set build options +option(USE_STANDALONE "Build as a standalone executable" ON) +option(BUILD_STORMLIB "Build with StormLib support" ON) +option(ENABLE_ASAN "Enable AddressSanitizer" OFF) + +option(BUILD_SM64 "Build with Super Mario 64 support" ON) +option(BUILD_MK64 "Build with Mario Kart 64 support" ON) +option(BUILD_SF64 "Build with Star Fox 64 support" ON) +option(BUILD_FZERO "Build with F-Zero X support" ON) +option(BUILD_NAUDIO "Build with NAudio support" ON) + ################################################################################ # Set target arch type if empty. Visual studio solution generator provides it. ################################################################################ @@ -20,27 +31,26 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Windows") endif() endif() +if(USE_STANDALONE) + # Link libgfxd + # Because libgfxd is not a CMake project, we have to manually fetch it and add it to the build + FetchContent_Declare( + libgfxd + GIT_REPOSITORY https://github.com/glankk/libgfxd.git + GIT_TAG 96fd3b849f38b3a7c7b7f3ff03c5921d328e6cdf + ) -# Link libgfxd -# Because libgfxd is not a CMake project, we have to manually fetch it and add it to the build + FetchContent_GetProperties(libgfxd) -FetchContent_Declare( - libgfxd - GIT_REPOSITORY https://github.com/glankk/libgfxd.git - GIT_TAG 96fd3b849f38b3a7c7b7f3ff03c5921d328e6cdf -) - -FetchContent_GetProperties(libgfxd) - -if(NOT libgfxd_POPULATED) - FetchContent_Populate(libgfxd) - include_directories(${libgfxd_SOURCE_DIR}) - set(LGFXD_SRC gfxd.c uc_f3d.c uc_f3db.c uc_f3dex.c uc_f3dexb.c uc_f3dex2.c) - foreach (LGFXD_FILE ${LGFXD_SRC}) - list(APPEND LGFXD_FILES "${libgfxd_SOURCE_DIR}/${LGFXD_FILE}") - endforeach() + if(NOT libgfxd_POPULATED) + FetchContent_Populate(libgfxd) + include_directories(${libgfxd_SOURCE_DIR}) + set(LGFXD_SRC gfxd.c uc_f3d.c uc_f3db.c uc_f3dex.c uc_f3dexb.c uc_f3dex2.c) + foreach (LGFXD_FILE ${LGFXD_SRC}) + list(APPEND LGFXD_FILES "${libgfxd_SOURCE_DIR}/${LGFXD_FILE}") + endforeach() + endif() endif() - # Source files include_directories(${CMAKE_CURRENT_SOURCE_DIR}) @@ -50,11 +60,37 @@ file(GLOB_RECURSE CXX_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp ${CMAKE_CURREN file(GLOB C_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.c ${CMAKE_CURRENT_SOURCE_DIR}/src/**/*.c ${CMAKE_CURRENT_SOURCE_DIR}/lib/**/*.c) set(SRC_DIR ${CXX_FILES} ${C_FILES} ${LGFXD_FILES}) -option(USE_STANDALONE "Build as a standalone executable" ON) -option(BUILD_STORMLIB "Build with StormLib support" ON) -option(BUILD_ASAN "Build with AddressSanitizer" OFF) +if(BUILD_SM64) + add_definitions(-DSM64_SUPPORT) +else() + list(FILTER SRC_DIR EXCLUDE REGEX "${CMAKE_CURRENT_SOURCE_DIR}/src/factories/sm64/*") +endif() -if (BUILD_ASAN) +if(BUILD_SF64) + add_definitions(-DSF64_SUPPORT) +else() + list(FILTER SRC_DIR EXCLUDE REGEX "${CMAKE_CURRENT_SOURCE_DIR}/src/factories/sf64/*") +endif() + +if(BUILD_MK64) + add_definitions(-DMK64_SUPPORT) +else() + list(FILTER SRC_DIR EXCLUDE REGEX "${CMAKE_CURRENT_SOURCE_DIR}/src/factories/mk64/*") +endif() + +if(BUILD_FZERO) + add_definitions(-DFZERO_SUPPORT) +else() + list(FILTER SRC_DIR EXCLUDE REGEX "${CMAKE_CURRENT_SOURCE_DIR}/src/factories/fzerox/*") +endif() + +if(BUILD_NAUDIO) + add_definitions(-DNAUDIO_SUPPORT) +else() + list(FILTER SRC_DIR EXCLUDE REGEX "${CMAKE_CURRENT_SOURCE_DIR}/src/factories/naudio/*") +endif() + +if(ENABLE_ASAN) add_compile_options(-fsanitize=address) add_link_options(-fsanitize=address) endif() @@ -63,8 +99,14 @@ endif() if (USE_STANDALONE) add_definitions(-DSTANDALONE) add_executable(${PROJECT_NAME} ${SRC_DIR}) + set(LINK_TYPE "MD") else() - add_library(${PROJECT_NAME} SHARED ${SRC_DIR}) + add_library(${PROJECT_NAME} STATIC ${SRC_DIR}) + set(LINK_TYPE "MT") +endif() + +if (BUILD_STORMLIB) + add_definitions(-DUSE_STORMLIB) endif() if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC") @@ -77,13 +119,13 @@ else() /w; /Od; /ZI; - /MDd + /${LINK_TYPE}d > $<$: - /Oi; + /O3; /Gy; /W3; - /MD + /${LINK_TYPE} > /bigobj /permissive-; @@ -101,19 +143,19 @@ else() /INCREMENTAL:NO; /FORCE:MULTIPLE > - /bigobj + /bigobj; /MANIFEST:NO; /DEBUG; /SUBSYSTEM:CONSOLE ) -endif() -# Fetch Dependencies - -if(MSVC) + add_definitions(-DSTORMLIB_NO_AUTO_LINK) set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") endif() + +# Fetch Dependencies + if(NOT USE_STANDALONE AND EXISTS "/mnt/c/WINDOWS/system32/wsl.exe") FetchContent_Declare( GSL @@ -135,10 +177,25 @@ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/n64graphics) add_dependencies(${PROJECT_NAME} N64Graphics) # Link StormLib - if (BUILD_STORMLIB) + set(STORM_BUILD_TESTS OFF) set(STORMLIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib/StormLib) add_subdirectory(${STORMLIB_DIR}) + if(USE_STANDALONE) + if((CMAKE_SYSTEM_NAME MATCHES "Windows") AND ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")) + include(../cmake/HandleCompilerRT.cmake) + find_compiler_rt_library(builtins CLANG_RT_BUILTINS_LIBRARY) + get_filename_component(LIBDIR "${CLANG_RT_BUILTINS_LIBRARY}" DIRECTORY) + if(USE_STANDALONE AND IS_DIRECTORY "${LIBDIR}") + target_link_libraries(storm ${CLANG_RT_BUILTINS_LIBRARY}) + endif() + else() + target_link_libraries(${PROJECT_NAME} PRIVATE storm) + endif() + if (CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch") + target_compile_definitions(storm PRIVATE -D_POSIX_C_SOURCE=200809L) + endif() + endif () endif() # Link YamlCpp @@ -154,15 +211,24 @@ FetchContent_Declare( set(YAML_CPP_BUILD_TESTS OFF) FetchContent_MakeAvailable(yaml-cpp) -#Link Spdlog +target_link_libraries(${PROJECT_NAME} PRIVATE yaml-cpp) +if(NOT USE_STANDALONE) + target_compile_definitions(yaml-cpp PRIVATE YAML_CPP_STATIC_DEFINE) +endif() -FetchContent_Declare( - spdlog - GIT_REPOSITORY https://github.com/gabime/spdlog.git - GIT_TAG 7e635fca68d014934b4af8a1cf874f63989352b7 -) +if(USE_STANDALONE) + FetchContent_Declare( + spdlog + GIT_REPOSITORY https://github.com/gabime/spdlog.git + GIT_TAG 7e635fca68d014934b4af8a1cf874f63989352b7 + ) -FetchContent_MakeAvailable(spdlog) + FetchContent_MakeAvailable(spdlog) + target_link_libraries(${PROJECT_NAME} PRIVATE spdlog) +else() + find_package(spdlog REQUIRED) + target_link_libraries(${PROJECT_NAME} PUBLIC spdlog::spdlog) +endif() # Link TinyXML2 set(tinyxml2_BUILD_TESTING OFF) @@ -174,19 +240,7 @@ FetchContent_Declare( ) FetchContent_MakeAvailable(tinyxml2) -target_link_libraries(${PROJECT_NAME} PRIVATE spdlog tinyxml2 yaml-cpp storm N64Graphics BinaryTools) - -if((CMAKE_SYSTEM_NAME MATCHES "Windows") AND ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")) - include(../cmake/HandleCompilerRT.cmake) - find_compiler_rt_library(builtins CLANG_RT_BUILTINS_LIBRARY) - get_filename_component(LIBDIR "${CLANG_RT_BUILTINS_LIBRARY}" DIRECTORY) - if(IS_DIRECTORY "${LIBDIR}") - target_link_libraries(storm ${CLANG_RT_BUILTINS_LIBRARY}) - endif() -endif() -if (CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch") - target_compile_definitions(storm PRIVATE -D_POSIX_C_SOURCE=200809L) -endif() +target_link_libraries(${PROJECT_NAME} PRIVATE tinyxml2 yaml-cpp N64Graphics BinaryTools) if(NOT USE_STANDALONE) target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/lib/binarytools/BinaryReader.cpp b/lib/binarytools/BinaryReader.cpp index 622ed21..8032a2b 100644 --- a/lib/binarytools/BinaryReader.cpp +++ b/lib/binarytools/BinaryReader.cpp @@ -1,5 +1,5 @@ -#include "BinaryReader.h" -#include "MemoryStream.h" +#include "./BinaryReader.h" +#include "./MemoryStream.h" #include #include #include diff --git a/lib/binarytools/BinaryWriter.cpp b/lib/binarytools/BinaryWriter.cpp index 9aa5d6f..83c0b4c 100644 --- a/lib/binarytools/BinaryWriter.cpp +++ b/lib/binarytools/BinaryWriter.cpp @@ -1,5 +1,5 @@ -#include "BinaryWriter.h" -#include "MemoryStream.h" +#include "./BinaryWriter.h" +#include "./MemoryStream.h" #include LUS::BinaryWriter::BinaryWriter() { diff --git a/src/Companion.cpp b/src/Companion.cpp index 4e9eefd..cde1083 100644 --- a/src/Companion.cpp +++ b/src/Companion.cpp @@ -28,6 +28,7 @@ #include "factories/ViewportFactory.h" #include "factories/CompressedTextureFactory.h" +#ifdef SM64_SUPPORT #include "factories/sm64/AnimationFactory.h" #include "factories/sm64/BehaviorScriptFactory.h" #include "factories/sm64/CollisionFactory.h" @@ -43,7 +44,9 @@ #include "factories/sm64/PaintingMapFactory.h" #include "factories/sm64/TrajectoryFactory.h" #include "factories/sm64/WaterDropletFactory.h" +#endif +#ifdef MK64_SUPPORT #include "factories/mk64/CourseVtx.h" #include "factories/mk64/Waypoints.h" #include "factories/mk64/TrackSections.h" @@ -52,7 +55,9 @@ #include "factories/mk64/DrivingBehaviour.h" #include "factories/mk64/ItemCurve.h" #include "factories/mk64/CourseMetadata.h" +#endif +#ifdef SF64_SUPPORT #include "factories/sf64/ColPolyFactory.h" #include "factories/sf64/MessageFactory.h" #include "factories/sf64/MessageLookupFactory.h" @@ -63,9 +68,13 @@ #include "factories/sf64/EnvironmentFactory.h" #include "factories/sf64/ObjInitFactory.h" #include "factories/sf64/TriangleFactory.h" +#endif +#ifdef FZERO_SUPPORT #include "factories/fzerox/CourseFactory.h" +#endif +#ifdef NAUDIO_SUPPORT #include "factories/naudio/v0/AudioHeaderFactory.h" #include "factories/naudio/v0/BankFactory.h" #include "factories/naudio/v0/SampleFactory.h" @@ -81,6 +90,7 @@ #include "factories/naudio/v1/LoopFactory.h" #include "factories/naudio/v1/BookFactory.h" #include "factories/naudio/v1/SequenceFactory.h" +#endif #include "preprocess/CompTool.h" @@ -90,8 +100,6 @@ namespace fs = std::filesystem; static const std::string regular = "[%Y-%m-%d %H:%M:%S.%e] [%l] %v"; static const std::string line = "[%Y-%m-%d %H:%M:%S.%e] [%l] > %v"; -#define ABS(x) ((x) < 0 ? -(x) : (x)) - void Companion::Init(const ExportType type) { spdlog::set_level(spdlog::level::debug); @@ -113,7 +121,7 @@ void Companion::Init(const ExportType type) { this->RegisterFactory("VP", std::make_shared()); this->RegisterFactory("COMPRESSED_TEXTURE", std::make_shared()); - // SM64 specific +#ifdef SM64_SUPPORT this->RegisterFactory("SM64:DIALOG", std::make_shared()); this->RegisterFactory("SM64:TEXT", std::make_shared()); this->RegisterFactory("SM64:DICTIONARY", std::make_shared()); @@ -129,8 +137,9 @@ void Companion::Init(const ExportType type) { this->RegisterFactory("SM64:PAINTING_MAP", std::make_shared()); this->RegisterFactory("SM64:TRAJECTORY", std::make_shared()); this->RegisterFactory("SM64:WATER_DROPLET", std::make_shared()); +#endif - // MK64 specific +#ifdef MK64_SUPPORT this->RegisterFactory("MK64:COURSE_VTX", std::make_shared()); this->RegisterFactory("MK64:TRACK_WAYPOINTS", std::make_shared()); this->RegisterFactory("MK64:TRACK_SECTIONS", std::make_shared()); @@ -139,8 +148,9 @@ void Companion::Init(const ExportType type) { this->RegisterFactory("MK64:DRIVING_BEHAVIOUR", std::make_shared()); this->RegisterFactory("MK64:ITEM_CURVE", std::make_shared()); // Item curve for decomp only this->RegisterFactory("MK64:METADATA", std::make_shared()); +#endif - // SF64 specific +#ifdef SF64_SUPPORT this->RegisterFactory("SF64:ANIM", std::make_shared()); this->RegisterFactory("SF64:SKELETON", std::make_shared()); this->RegisterFactory("SF64:MESSAGE", std::make_shared()); @@ -151,11 +161,13 @@ void Companion::Init(const ExportType type) { this->RegisterFactory("SF64:OBJECT_INIT", std::make_shared()); this->RegisterFactory("SF64:COLPOLY", std::make_shared()); this->RegisterFactory("SF64:TRIANGLE", std::make_shared()); +#endif - // F-Zero X specific +#ifdef FZERO_SUPPORT this->RegisterFactory("FZX:COURSE", std::make_shared()); +#endif - // NAudio specific +#ifdef NAUDIO_SUPPORT this->RegisterFactory("NAUDIO:V0:AUDIO_HEADER", std::make_shared()); this->RegisterFactory("NAUDIO:V0:SEQUENCE", std::make_shared()); this->RegisterFactory("NAUDIO:V0:SAMPLE", std::make_shared()); @@ -171,6 +183,7 @@ void Companion::Init(const ExportType type) { this->RegisterFactory("NAUDIO:V1:ADPCM_LOOP", std::make_shared()); this->RegisterFactory("NAUDIO:V1:ADPCM_BOOK", std::make_shared()); this->RegisterFactory("NAUDIO:V1:SEQUENCE", std::make_shared()); +#endif this->Process(); } @@ -657,12 +670,12 @@ void Companion::ProcessFile(YAML::Node root) { stream.clear(); exporter->get()->Export(stream, data, result.name, result.node, &result.name); auto data = stream.str(); - this->gCurrentWrapper->CreateFile(result.name, std::vector(data.begin(), data.end())); + this->gCurrentWrapper->AddFile(result.name, std::vector(data.begin(), data.end())); for(auto& entry : this->gCompanionFiles){ auto output = (this->gCurrentDirectory / entry.first).string(); std::replace(output.begin(), output.end(), '\\', '/'); - this->gCurrentWrapper->CreateFile(output, entry.second); + this->gCurrentWrapper->AddFile(output, entry.second); } break; @@ -956,6 +969,7 @@ void Companion::Process() { SPDLOG_ERROR("No config found for {}", this->gCartridge->GetHash()); return; } + this->gConfig.parseMode = ParseMode::Default; } else { this->gConfig.parseMode = ParseMode::Directory; @@ -1101,13 +1115,14 @@ void Companion::Process() { entries.push_back(key); } } - +#ifdef STANDALONE if(cfg["enums"]) { auto enums = GetSafeNode>(cfg, "enums"); for (auto& file : enums) { this->ParseEnums(file); } } +#endif if(cfg["logging"]){ auto level = cfg["logging"].as(); @@ -1207,7 +1222,7 @@ void Companion::Process() { if(wrapper != nullptr) { SPDLOG_INFO("Writing version file"); - wrapper->CreateFile("version", vWriter.ToVector()); + wrapper->AddFile("version", vWriter.ToVector()); vWriter.Close(); wrapper->Close(); } @@ -1272,7 +1287,7 @@ void Companion::Pack(const std::string& folder, const std::string& output, const std::replace(normalized.begin(), normalized.end(), '\\', '/'); // Remove parent folder normalized = normalized.substr(folder.length() + 1); - wrapper->CreateFile(normalized, data); + wrapper->AddFile(normalized, data); SPDLOG_INFO("> Added {}", normalized); } diff --git a/src/archive/BinaryWrapper.h b/src/archive/BinaryWrapper.h index b88e8b0..d6f4b39 100644 --- a/src/archive/BinaryWrapper.h +++ b/src/archive/BinaryWrapper.h @@ -11,7 +11,7 @@ public: virtual ~BinaryWrapper() = default; virtual int32_t CreateArchive(void) = 0; - virtual bool CreateFile(const std::string& path, std::vector data) = 0; + virtual bool AddFile(const std::string& path, std::vector data) = 0; virtual int32_t Close(void) = 0; protected: std::mutex mMutex; diff --git a/src/archive/SWrapper.cpp b/src/archive/SWrapper.cpp index 087d401..fab0caf 100644 --- a/src/archive/SWrapper.cpp +++ b/src/archive/SWrapper.cpp @@ -13,6 +13,9 @@ SWrapper::SWrapper(const std::string& path) { } int32_t SWrapper::CreateArchive() { +#ifndef USE_STORMLIB + throw std::runtime_error("StormLib is not enabled. Cannot create archive"); +#else if(fs::exists(mPath)) { fs::remove(mPath); } @@ -23,9 +26,13 @@ int32_t SWrapper::CreateArchive() { } return 0; +#endif } -bool SWrapper::CreateFile(const std::string& path, std::vector data) { +bool SWrapper::AddFile(const std::string& path, std::vector data) { +#ifndef USE_STORMLIB + throw std::runtime_error("StormLib is not enabled. Cannot create file"); +#else if(Companion::Instance != nullptr && Companion::Instance->IsDebug()){ SPDLOG_INFO("Creating debug file: debug/{}", path); std::string dpath = "debug/" + path; @@ -74,9 +81,13 @@ bool SWrapper::CreateFile(const std::string& path, std::vector data) { } return true; +#endif } int32_t SWrapper::Close(void) { +#ifndef USE_STORMLIB + throw std::runtime_error("StormLib is not enabled. Cannot close archive"); +#else if(this->hMpq == nullptr) { SPDLOG_ERROR("Archive already closed"); return -1; @@ -86,4 +97,5 @@ int32_t SWrapper::Close(void) { return -1; } return 0; +#endif } diff --git a/src/archive/SWrapper.h b/src/archive/SWrapper.h index 5182775..5e0096e 100644 --- a/src/archive/SWrapper.h +++ b/src/archive/SWrapper.h @@ -2,16 +2,20 @@ #include #include -#include #include "BinaryWrapper.h" +#ifdef USE_STORMLIB +#include +#endif class SWrapper : public BinaryWrapper { public: explicit SWrapper(const std::string& path); int32_t CreateArchive(void) override; - bool CreateFile(const std::string& path, std::vector data) override; + bool AddFile(const std::string& path, std::vector data) override; int32_t Close(void) override; +#ifdef USE_STORMLIB private: HANDLE hMpq{}; +#endif }; diff --git a/src/archive/ZWrapper.cpp b/src/archive/ZWrapper.cpp index ce4fb9b..b94b631 100644 --- a/src/archive/ZWrapper.cpp +++ b/src/archive/ZWrapper.cpp @@ -19,7 +19,7 @@ int32_t ZWrapper::CreateArchive() { return 0; } -bool ZWrapper::CreateFile(const std::string& path, std::vector data) { +bool ZWrapper::AddFile(const std::string& path, std::vector data) { char* fileData = data.data(); size_t fileSize = data.size(); diff --git a/src/archive/ZWrapper.h b/src/archive/ZWrapper.h index 3cad072..b297ac5 100644 --- a/src/archive/ZWrapper.h +++ b/src/archive/ZWrapper.h @@ -9,6 +9,6 @@ public: explicit ZWrapper(const std::string& path); int32_t CreateArchive(void) override; - bool CreateFile(const std::string& path, std::vector data) override; + bool AddFile(const std::string& path, std::vector data) override; int32_t Close(void) override; }; diff --git a/src/factories/DisplayListFactory.cpp b/src/factories/DisplayListFactory.cpp index 344bca3..c64fab8 100644 --- a/src/factories/DisplayListFactory.cpp +++ b/src/factories/DisplayListFactory.cpp @@ -3,11 +3,13 @@ #include "utils/Decompressor.h" #include "spdlog/spdlog.h" #include "Companion.h" -#include #include -#include #include "n64/gbi-otr.h" +#ifdef STANDALONE +#include +#endif + #define C0(pos, width) ((w0 >> (pos)) & ((1U << width) - 1)) #define ALIGN16(val) (((val) + 0xF) & ~0xF) @@ -58,6 +60,7 @@ std::unordered_map> gGBITab #define GBI(cmd) gGBITable[Companion::Instance->GetGBIVersion()][#cmd] +#ifdef STANDALONE void GFXDSetGBIVersion(){ switch (Companion::Instance->GetGBIVersion()) { case GBIVersion::f3d: @@ -77,6 +80,7 @@ void GFXDSetGBIVersion(){ break; } } +#endif ExportResult DListHeaderExporter::Export(std::ostream &write, std::shared_ptr raw, std::string& entryName, YAML::Node &node, std::string* replacement) { const auto symbol = GetSafeNode(node, "symbol", entryName); @@ -90,8 +94,8 @@ ExportResult DListHeaderExporter::Export(std::ostream &write, std::shared_ptr raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { const auto cmds = std::static_pointer_cast(raw)->mGfxs; const auto symbol = GetSafeNode(node, "symbol", entryName); @@ -109,7 +113,7 @@ ExportResult DListCodeExporter::Export(std::ostream &write, std::shared_ptr(gfxd_macro_data()); + auto gfx = static_cast(gfxd_macro_data()); const uint8_t opcode = (gfx->words.w0 >> 24) & 0xFF; if(hasTable) { @@ -206,6 +210,7 @@ void DebugDisplayList(uint32_t w0, uint32_t w1){ GFXDSetGBIVersion(); gfxd_execute(); } +#endif std::optional> SearchVtx(uint32_t ptr){ auto decs = Companion::Instance->GetNodesByType("VTX"); @@ -219,7 +224,7 @@ std::optional> SearchVtx(uint32_t ptr){ auto offset = GetSafeNode(node, "offset"); auto count = GetSafeNode(node, "count"); - auto end = ALIGN16((count * sizeof(Vtx_t))); + auto end = ALIGN16((count * sizeof(N64Vtx_t))); if(ptr > offset && ptr <= offset + end){ return std::make_tuple(GetSafeNode(node, "symbol", name), node); @@ -267,7 +272,7 @@ ExportResult DListBinaryExporter::Export(std::ostream &write, std::shared_ptr(ovnode, "count"); auto diff = ASSET_PTR(ptr) - ASSET_PTR(offset); - Gfx value = gsSPVertexOTR(diff, nvtx, didx); + N64Gfx value = gsSPVertexOTR(diff, nvtx, didx); SPDLOG_INFO("gsSPVertexOTR({}, {}, {})", diff, nvtx, didx); @@ -316,7 +321,7 @@ ExportResult DListBinaryExporter::Export(std::ostream &write, std::shared_ptr(dec.value())); - Gfx value = gsSPVertexOTR(0, nvtx, didx); + N64Gfx value = gsSPVertexOTR(0, nvtx, didx); SPDLOG_INFO("gsSPVertex({}, {}, 0x{:X})", nvtx, didx, ptr); @@ -334,7 +339,7 @@ ExportResult DListBinaryExporter::Export(std::ostream &write, std::shared_ptrGetNodeByAddr(ptr); auto branch = (w0 >> 16) & G_DL_NO_PUSH; @@ -434,7 +439,7 @@ ExportResult DListBinaryExporter::Export(std::ostream &write, std::shared_ptr> DListFactory::parse(std::vectorGetNodeByAddr(w1); @@ -579,7 +584,7 @@ std::optional> DListFactory::parse(std::vector(vtx, "offset"); auto lCount = GetSafeNode(vtx, "count"); - auto lSize = ALIGN16(lCount * sizeof(Vtx_t)); + auto lSize = ALIGN16(lCount * sizeof(N64Vtx_t)); if(w1 > lOffset && w1 <= lOffset + lSize){ SPDLOG_INFO("Found vtx at 0x{:X} matching last vtx at 0x{:X}", w1, lOffset); diff --git a/src/factories/DisplayListFactory.h b/src/factories/DisplayListFactory.h index 27efae4..e46ab22 100644 --- a/src/factories/DisplayListFactory.h +++ b/src/factories/DisplayListFactory.h @@ -20,9 +20,11 @@ class DListBinaryExporter : public BaseExporter { ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; +#ifdef STANDALONE class DListCodeExporter : public BaseExporter { ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; +#endif class DListFactory : public BaseFactory { public: @@ -31,7 +33,9 @@ public: return { REGISTER(Header, DListHeaderExporter) REGISTER(Binary, DListBinaryExporter) + #ifdef STANDALONE REGISTER(Code, DListCodeExporter) + #endif }; } uint32_t GetAlignment() override { diff --git a/src/factories/DisplayListOverrides.cpp b/src/factories/DisplayListOverrides.cpp index 1d8e027..f684899 100644 --- a/src/factories/DisplayListOverrides.cpp +++ b/src/factories/DisplayListOverrides.cpp @@ -4,15 +4,18 @@ #include "DisplayListFactory.h" #include "spdlog/spdlog.h" #include "Companion.h" - -#include #include +#ifdef STANDALONE +#include +#endif + namespace GFXDOverride { std::unordered_map> mVtxOverlaps; -void Triangle2(const Gfx* gfx) { +#ifdef STANDALONE +void Triangle2(const N64Gfx* gfx) { auto w0 = gfx->words.w0; auto w1 = gfx->words.w1; @@ -32,7 +35,7 @@ void Triangle2(const Gfx* gfx) { gfxd_puts(")"); } -void Quadrangle(const Gfx* gfx) { +void Quadrangle(const N64Gfx* gfx) { auto w1 = gfx->words.w1; auto v1 = std::to_string( ((w1 >> 16) & 0xFF) / 2 ); @@ -57,7 +60,7 @@ int Vtx(uint32_t ptr, int32_t num) { auto offset = GetSafeNode(node, "offset"); auto count = GetSafeNode(node, "count"); - auto idx = (ptr - offset) / sizeof(Vtx_t); + auto idx = (ptr - offset) / sizeof(N64Vtx_t); SPDLOG_INFO("Replaced Vtx Overlapped: 0x{:X} Symbol: {}", ptr, symbol); gfxd_puts("&"); @@ -181,6 +184,7 @@ int Viewport(uint32_t ptr) { SPDLOG_TRACE("Could not find viewport to override at 0x{:X}", ptr); return 0; } +#endif std::optional> GetVtxOverlap(uint32_t ptr){ if(mVtxOverlaps.contains(ptr)){ diff --git a/src/factories/DisplayListOverrides.h b/src/factories/DisplayListOverrides.h index 5597449..e580f7c 100644 --- a/src/factories/DisplayListOverrides.h +++ b/src/factories/DisplayListOverrides.h @@ -9,19 +9,19 @@ typedef struct { uint32_t w0; uint32_t w1; -} Words; +} N64Words; typedef union { - Words words; + N64Words words; long long int force_structure_alignment; -} Gfx; +} N64Gfx; typedef struct { int16_t ob[3]; uint16_t flag; int16_t tc[2]; unsigned char cn[4]; -} Vtx_t; +} N64Vtx_t; typedef struct { int16_t ob[3]; @@ -29,16 +29,17 @@ typedef struct { int16_t tc[2]; signed char n[3]; unsigned char a; -} Vtx_tn; +} N64Vtx_tn; typedef union { - Vtx_t v; - Vtx_tn n; -} Vtx; + N64Vtx_t v; + N64Vtx_tn n; +} N64Vtx; namespace GFXDOverride { -void Quadrangle(const Gfx* gfx); -void Triangle2(const Gfx* gfx); +#ifdef STANDALONE +void Quadrangle(const N64Gfx* gfx); +void Triangle2(const N64Gfx* gfx); int Vtx(uint32_t vtx, int32_t num); int Texture(uint32_t timg, int32_t fmt, int32_t siz, int32_t width, int32_t height, int32_t pal); int Palette(uint32_t tlut, int32_t idx, int32_t count); @@ -46,6 +47,7 @@ int Lights(uint32_t lightsn, int32_t count); int Light(uint32_t light); int DisplayList(uint32_t dl); int Viewport(uint32_t vp); +#endif void RegisterVTXOverlap(uint32_t ptr, std::tuple& vtx); std::optional> GetVtxOverlap(uint32_t ptr); void ClearVtx(); diff --git a/src/factories/naudio/v0/AIFCDecode.cpp b/src/factories/naudio/v0/AIFCDecode.cpp index a4ff8b5..cddf398 100644 --- a/src/factories/naudio/v0/AIFCDecode.cpp +++ b/src/factories/naudio/v0/AIFCDecode.cpp @@ -9,8 +9,8 @@ #include #include #include -#include "binarytools/BinaryWriter.h" -#include "BinaryReader.h" +#include "lib/binarytools/BinaryWriter.h" +#include "lib/binarytools/BinaryReader.h" typedef signed char s8; typedef short s16; diff --git a/src/factories/naudio/v0/AIFCDecode.h b/src/factories/naudio/v0/AIFCDecode.h index e141a80..44a5962 100644 --- a/src/factories/naudio/v0/AIFCDecode.h +++ b/src/factories/naudio/v0/AIFCDecode.h @@ -1,6 +1,6 @@ #pragma once #include -#include "BinaryWriter.h" +#include "lib/binarytools/BinaryWriter.h" void write_aiff(std::vector data, LUS::BinaryWriter& writer); \ No newline at end of file diff --git a/src/factories/naudio/v0/AudioManager.cpp b/src/factories/naudio/v0/AudioManager.cpp index 4c836a9..1e7fc9a 100644 --- a/src/factories/naudio/v0/AudioManager.cpp +++ b/src/factories/naudio/v0/AudioManager.cpp @@ -11,7 +11,7 @@ #include "hj/zip.h" #include "hj/pyutils.h" #include "spdlog/spdlog.h" -#include "binarytools/BinaryReader.h" +#include "lib/binarytools/BinaryReader.h" #include "spdlog/spdlog.h" std::unordered_map name_table; diff --git a/src/factories/naudio/v0/AudioManager.h b/src/factories/naudio/v0/AudioManager.h index 644ce15..6f4a880 100644 --- a/src/factories/naudio/v0/AudioManager.h +++ b/src/factories/naudio/v0/AudioManager.h @@ -5,7 +5,7 @@ #include #include #include -#include "binarytools/BinaryWriter.h" +#include "lib/binarytools/BinaryWriter.h" #include #include diff --git a/src/factories/sf64/ScriptFactory.cpp b/src/factories/sf64/ScriptFactory.cpp index b3c49db..2b1b498 100644 --- a/src/factories/sf64/ScriptFactory.cpp +++ b/src/factories/sf64/ScriptFactory.cpp @@ -299,7 +299,7 @@ ExportResult SF64::ScriptBinaryExporter::Export(std::ostream &write, std::shared cmdWriter.Finish(stream); auto data = stream.str(); - wrapper->CreateFile(entryName + "_cmd_" + std::to_string(ptrCount), std::vector(data.begin(), data.end())); + wrapper->AddFile(entryName + "_cmd_" + std::to_string(ptrCount), std::vector(data.begin(), data.end())); std::ostringstream cmdName; cmdName << entryName << "_cmd_" << std::dec << ptrCount; diff --git a/src/factories/sf64/SkeletonFactory.cpp b/src/factories/sf64/SkeletonFactory.cpp index db247e9..469222c 100644 --- a/src/factories/sf64/SkeletonFactory.cpp +++ b/src/factories/sf64/SkeletonFactory.cpp @@ -140,7 +140,7 @@ ExportResult SF64::SkeletonBinaryExporter::Export(std::ostream &write, std::shar limbWriter.Finish(stream); auto data = stream.str(); - wrapper->CreateFile(entryName + "_limb_" + std::to_string(limb.mIndex), std::vector(data.begin(), data.end())); + wrapper->AddFile(entryName + "_limb_" + std::to_string(limb.mIndex), std::vector(data.begin(), data.end())); } // Export Skeleton diff --git a/src/factories/sm64/behavior/BehaviorCommand.h b/src/factories/sm64/behavior/BehaviorCommand.h index 6effad3..74bc22c 100644 --- a/src/factories/sm64/behavior/BehaviorCommand.h +++ b/src/factories/sm64/behavior/BehaviorCommand.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include enum class BehaviorOpcode { diff --git a/src/factories/sm64/geo/GeoCommand.h b/src/factories/sm64/geo/GeoCommand.h index 2fdad6b..4600d22 100644 --- a/src/factories/sm64/geo/GeoCommand.h +++ b/src/factories/sm64/geo/GeoCommand.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include enum class GeoOpcode { diff --git a/src/factories/sm64/level/LevelCommand.h b/src/factories/sm64/level/LevelCommand.h index 8c19609..b47d84a 100644 --- a/src/factories/sm64/level/LevelCommand.h +++ b/src/factories/sm64/level/LevelCommand.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include enum class LevelOpcode { diff --git a/src/n64/Cartridge.cpp b/src/n64/Cartridge.cpp index e26913e..f3c1f83 100644 --- a/src/n64/Cartridge.cpp +++ b/src/n64/Cartridge.cpp @@ -1,6 +1,6 @@ #include "Cartridge.h" -#include "binarytools/BinaryReader.h" +#include "lib/binarytools/BinaryReader.h" #include void N64::Cartridge::Initialize() { diff --git a/src/n64/gbi-otr.h b/src/n64/gbi-otr.h index a5bb09e..5590ca7 100644 --- a/src/n64/gbi-otr.h +++ b/src/n64/gbi-otr.h @@ -34,7 +34,7 @@ #define gDPFillWideRectangle(pkt, ulx, uly, lrx, lry) \ { \ - Gfx *_g0 = (Gfx*)(pkt), *_g1 = (Gfx*)(pkt); \ + N64Gfx *_g0 = (N64Gfx*)(pkt), *_g1 = (N64Gfx*)(pkt); \ _g0->words.w0 = _SHIFTL(G_FILLWIDERECT, 24, 8) | _SHIFTL((lrx), 2, 22); \ _g0->words.w1 = _SHIFTL((lry), 2, 22); \ _g1->words.w0 = _SHIFTL((ulx), 2, 22); \ @@ -43,7 +43,7 @@ #define gSPWideTextureRectangle(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ { \ - Gfx *_g0 = (Gfx*)(pkt), *_g1 = (Gfx*)(pkt), *_g2 = (Gfx*)(pkt); \ + N64Gfx *_g0 = (N64Gfx*)(pkt), *_g1 = (N64Gfx*)(pkt), *_g2 = (N64Gfx*)(pkt); \ \ _g0->words.w0 = _SHIFTL(G_TEXRECT_WIDE, 24, 8) | _SHIFTL((xh), 0, 24); \ _g0->words.w1 = _SHIFTL((yh), 0, 24); \ @@ -68,7 +68,7 @@ #define gSPExtraGeometryMode(pkt, c, s) \ _DW({ \ - Gfx* _g = (Gfx*)(pkt); \ + N64Gfx* _g = (N64Gfx*)(pkt); \ \ _g->words.w0 = _SHIFTL(G_EXTRAGEOMETRYMODE, 24, 8) | _SHIFTL(~(u32)(c), 0, 24); \ _g->words.w1 = (u32)(s); \ @@ -79,7 +79,7 @@ _DW({ #define __gSPInvalidateTexCache(pkt, addr) \ _DW({ \ - Gfx* _g = (Gfx*)(pkt); \ + N64Gfx* _g = (N64Gfx*)(pkt); \ \ _g->words.w0 = _SHIFTL(G_INVALTEXCACHE, 24, 8); \ _g->words.w1 = addr; \ @@ -90,7 +90,7 @@ _DW({ #define gsSPSetFB(pkt, fb) \ { \ - Gfx* _g = (Gfx*)(pkt); \ + N64Gfx* _g = (N64Gfx*)(pkt); \ \ _g->words.w0 = _SHIFTL(G_SETFB, 24, 8); \ _g->words.w1 = fb; \ @@ -98,7 +98,7 @@ _DW({ #define gsSPResetFB(pkt) \ { \ - Gfx* _g = (Gfx*)(pkt); \ + N64Gfx* _g = (N64Gfx*)(pkt); \ \ _g->words.w0 = _SHIFTL(G_RESETFB, 24, 8); \ _g->words.w1 = 0; \ @@ -106,7 +106,7 @@ _DW({ #define gSPGrayscale(pkt, state) \ { \ - Gfx* _g = (Gfx*)(pkt); \ + N64Gfx* _g = (N64Gfx*)(pkt); \ \ _g->words.w0 = _SHIFTL(G_SETGRAYSCALE, 24, 8); \ _g->words.w1 = state; \ @@ -117,7 +117,7 @@ _DW({ #define gSPDisableFiltering(pkt, state) \ { \ - Gfx* _g = (Gfx*)(pkt); \ + N64Gfx* _g = (N64Gfx*)(pkt); \ \ _g->words.w0 = _SHIFTL(G_SETFILTERING, 24, 8); \ _g->words.w1 = state; \ @@ -130,7 +130,7 @@ _DW({ { _SHIFTL(G_TRI1_OTR, 24, 8) | __gsSP1Triangle_w1f(v0, v1, v2, flag), 0 } #define gsSPVertexOTR(v, n, v0) \ - { (_SHIFTL(G_VTX_OTR_HASH, 24, 8) | _SHIFTL((n), 12, 8) | _SHIFTL((v0) + (n), 1, 7)), (uintptr_t)(v) } + { (_SHIFTL(G_VTX_OTR_HASH, 24, 8) | _SHIFTL((n), 12, 8) | _SHIFTL((v0) + (n), 1, 7)), (uint32_t)(v) } #define gsSPRawOpcode(opcode) \ { _SHIFTL(opcode, 24, 8), 0 } @@ -139,42 +139,42 @@ _DW({ {{ \ _SHIFTL(G_SETTIMG_OTR_HASH, 24, 8) | _SHIFTL(fmt, 21, 3) | \ _SHIFTL(siz, 19, 2) | _SHIFTL((width)-1, 0, 12), \ - (uintptr_t)(i) \ + (uint32_t)(i) \ }} #define gsSPBranchListOTRHash(dl) \ {{ \ (_SHIFTL((G_DL_OTR_HASH), 24, 8) | _SHIFTL((0x01), 16, 8) | \ _SHIFTL((0), 1, 16)), \ - (uintptr_t)(dl) \ + (uint32_t)(dl) \ }} #define gsSPBranchListOTRFilePath(dl) \ {{ \ (_SHIFTL((G_DL_OTR_FILEPATH), 24, 8) | _SHIFTL((0x01), 16, 8) | \ _SHIFTL((0), 0, 16)), \ - (uintptr_t)(dl) \ + (uint32_t)(dl) \ }} #define gsSPDisplayListOTRHash(dl) \ {{ \ (_SHIFTL((G_DL_OTR_HASH), 24, 8) | _SHIFTL((0x00), 16, 8) | \ _SHIFTL((0), 0, 16)), \ - (uintptr_t)(dl) \ + (uint32_t)(dl) \ }} #define gsSPDisplayListOTRIndex(dl) \ {{ \ (_SHIFTL((G_DL_OTR_INDEX), 24, 8) | _SHIFTL((0x00), 16, 8) | \ _SHIFTL((0), 0, 16)), \ - (uintptr_t)((SEGMENT_NUMBER(dl) << 24) | ((SEGMENT_OFFSET(dl) / 8) & 0x00FFFFFF)) \ + (uint32_t)((SEGMENT_NUMBER(dl) << 24) | ((SEGMENT_OFFSET(dl) / 8) & 0x00FFFFFF)) \ }} #define gsSPDisplayListOTRFilePath(dl) \ {{ \ (_SHIFTL((G_DL_OTR_FILEPATH), 24, 8) | _SHIFTL((0x00), 16, 8) | \ _SHIFTL((0), 0, 16)), \ - (uintptr_t)(dl) \ + (uint32_t)(dl) \ }} #define gDPSetGrayscaleColor(pkt, r, g, b, lerp) DPRGBColor(pkt, G_SETINTENSITY, r, g, b, lerp) #define gsDPSetGrayscaleColor(r, g, b, a) sDPRGBColor(G_SETINTENSITY, r, g, b, a)