mirror of
https://github.com/izzy2lost/Torch.git
synced 2026-07-06 00:18:35 -07:00
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 <malkierian@gmail.com> Co-authored-by: Malkierian <malkierian@live.com>
This commit is contained in:
co-authored by
Malkierian
Malkierian
parent
82c4397160
commit
7da8ae8e25
+106
-52
@@ -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
|
||||
>
|
||||
$<$<CONFIG:Release>:
|
||||
/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$<$<CONFIG:Debug>: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})
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "BinaryReader.h"
|
||||
#include "MemoryStream.h"
|
||||
#include "./BinaryReader.h"
|
||||
#include "./MemoryStream.h"
|
||||
#include <cmath>
|
||||
#include <stdexcept>
|
||||
#include <locale>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "BinaryWriter.h"
|
||||
#include "MemoryStream.h"
|
||||
#include "./BinaryWriter.h"
|
||||
#include "./MemoryStream.h"
|
||||
#include <iostream>
|
||||
|
||||
LUS::BinaryWriter::BinaryWriter() {
|
||||
|
||||
+27
-12
@@ -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<ViewportFactory>());
|
||||
this->RegisterFactory("COMPRESSED_TEXTURE", std::make_shared<CompressedTextureFactory>());
|
||||
|
||||
// SM64 specific
|
||||
#ifdef SM64_SUPPORT
|
||||
this->RegisterFactory("SM64:DIALOG", std::make_shared<SM64::DialogFactory>());
|
||||
this->RegisterFactory("SM64:TEXT", std::make_shared<SM64::TextFactory>());
|
||||
this->RegisterFactory("SM64:DICTIONARY", std::make_shared<SM64::DictionaryFactory>());
|
||||
@@ -129,8 +137,9 @@ void Companion::Init(const ExportType type) {
|
||||
this->RegisterFactory("SM64:PAINTING_MAP", std::make_shared<SM64::PaintingMapFactory>());
|
||||
this->RegisterFactory("SM64:TRAJECTORY", std::make_shared<SM64::TrajectoryFactory>());
|
||||
this->RegisterFactory("SM64:WATER_DROPLET", std::make_shared<SM64::WaterDropletFactory>());
|
||||
#endif
|
||||
|
||||
// MK64 specific
|
||||
#ifdef MK64_SUPPORT
|
||||
this->RegisterFactory("MK64:COURSE_VTX", std::make_shared<MK64::CourseVtxFactory>());
|
||||
this->RegisterFactory("MK64:TRACK_WAYPOINTS", std::make_shared<MK64::WaypointsFactory>());
|
||||
this->RegisterFactory("MK64:TRACK_SECTIONS", std::make_shared<MK64::TrackSectionsFactory>());
|
||||
@@ -139,8 +148,9 @@ void Companion::Init(const ExportType type) {
|
||||
this->RegisterFactory("MK64:DRIVING_BEHAVIOUR", std::make_shared<MK64::DrivingBehaviourFactory>());
|
||||
this->RegisterFactory("MK64:ITEM_CURVE", std::make_shared<MK64::ItemCurveFactory>()); // Item curve for decomp only
|
||||
this->RegisterFactory("MK64:METADATA", std::make_shared<MK64::CourseMetadataFactory>());
|
||||
#endif
|
||||
|
||||
// SF64 specific
|
||||
#ifdef SF64_SUPPORT
|
||||
this->RegisterFactory("SF64:ANIM", std::make_shared<SF64::AnimFactory>());
|
||||
this->RegisterFactory("SF64:SKELETON", std::make_shared<SF64::SkeletonFactory>());
|
||||
this->RegisterFactory("SF64:MESSAGE", std::make_shared<SF64::MessageFactory>());
|
||||
@@ -151,11 +161,13 @@ void Companion::Init(const ExportType type) {
|
||||
this->RegisterFactory("SF64:OBJECT_INIT", std::make_shared<SF64::ObjInitFactory>());
|
||||
this->RegisterFactory("SF64:COLPOLY", std::make_shared<SF64::ColPolyFactory>());
|
||||
this->RegisterFactory("SF64:TRIANGLE", std::make_shared<SF64::TriangleFactory>());
|
||||
#endif
|
||||
|
||||
// F-Zero X specific
|
||||
#ifdef FZERO_SUPPORT
|
||||
this->RegisterFactory("FZX:COURSE", std::make_shared<FZX::CourseFactory>());
|
||||
#endif
|
||||
|
||||
// NAudio specific
|
||||
#ifdef NAUDIO_SUPPORT
|
||||
this->RegisterFactory("NAUDIO:V0:AUDIO_HEADER", std::make_shared<AudioHeaderFactory>());
|
||||
this->RegisterFactory("NAUDIO:V0:SEQUENCE", std::make_shared<SequenceFactory>());
|
||||
this->RegisterFactory("NAUDIO:V0:SAMPLE", std::make_shared<SampleFactory>());
|
||||
@@ -171,6 +183,7 @@ void Companion::Init(const ExportType type) {
|
||||
this->RegisterFactory("NAUDIO:V1:ADPCM_LOOP", std::make_shared<ADPCMLoopFactory>());
|
||||
this->RegisterFactory("NAUDIO:V1:ADPCM_BOOK", std::make_shared<ADPCMBookFactory>());
|
||||
this->RegisterFactory("NAUDIO:V1:SEQUENCE", std::make_shared<NSequenceFactory>());
|
||||
#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<std::vector<std::string>>(cfg, "enums");
|
||||
for (auto& file : enums) {
|
||||
this->ParseEnums(file);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if(cfg["logging"]){
|
||||
auto level = cfg["logging"].as<std::string>();
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ public:
|
||||
virtual ~BinaryWrapper() = default;
|
||||
|
||||
virtual int32_t CreateArchive(void) = 0;
|
||||
virtual bool CreateFile(const std::string& path, std::vector<char> data) = 0;
|
||||
virtual bool AddFile(const std::string& path, std::vector<char> data) = 0;
|
||||
virtual int32_t Close(void) = 0;
|
||||
protected:
|
||||
std::mutex mMutex;
|
||||
|
||||
@@ -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<char> data) {
|
||||
bool SWrapper::AddFile(const std::string& path, std::vector<char> 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<char> 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
|
||||
}
|
||||
|
||||
@@ -2,16 +2,20 @@
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <StormLib/src/StormLib.h>
|
||||
#include "BinaryWrapper.h"
|
||||
#ifdef USE_STORMLIB
|
||||
#include <StormLib/src/StormLib.h>
|
||||
#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<char> data) override;
|
||||
bool AddFile(const std::string& path, std::vector<char> data) override;
|
||||
int32_t Close(void) override;
|
||||
#ifdef USE_STORMLIB
|
||||
private:
|
||||
HANDLE hMpq{};
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -19,7 +19,7 @@ int32_t ZWrapper::CreateArchive() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool ZWrapper::CreateFile(const std::string& path, std::vector<char> data) {
|
||||
bool ZWrapper::AddFile(const std::string& path, std::vector<char> data) {
|
||||
char* fileData = data.data();
|
||||
size_t fileSize = data.size();
|
||||
|
||||
|
||||
@@ -9,6 +9,6 @@ public:
|
||||
explicit ZWrapper(const std::string& path);
|
||||
|
||||
int32_t CreateArchive(void) override;
|
||||
bool CreateFile(const std::string& path, std::vector<char> data) override;
|
||||
bool AddFile(const std::string& path, std::vector<char> data) override;
|
||||
int32_t Close(void) override;
|
||||
};
|
||||
|
||||
@@ -3,11 +3,13 @@
|
||||
#include "utils/Decompressor.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "Companion.h"
|
||||
#include <gfxd.h>
|
||||
#include <fstream>
|
||||
#include <utils/TorchUtils.h>
|
||||
#include "n64/gbi-otr.h"
|
||||
|
||||
#ifdef STANDALONE
|
||||
#include <gfxd.h>
|
||||
#endif
|
||||
|
||||
#define C0(pos, width) ((w0 >> (pos)) & ((1U << width) - 1))
|
||||
#define ALIGN16(val) (((val) + 0xF) & ~0xF)
|
||||
|
||||
@@ -58,6 +60,7 @@ std::unordered_map<GBIVersion, std::unordered_map<std::string, uint8_t>> 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<IParsedData> 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<IP
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
#ifdef STANDALONE
|
||||
bool hasTable = false;
|
||||
|
||||
ExportResult DListCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
|
||||
const auto cmds = std::static_pointer_cast<DListData>(raw)->mGfxs;
|
||||
const auto symbol = GetSafeNode(node, "symbol", entryName);
|
||||
@@ -109,7 +113,7 @@ ExportResult DListCodeExporter::Export(std::ostream &write, std::shared_ptr<IPar
|
||||
|
||||
gfxd_endian(gfxd_endian_host, sizeof(uint32_t));
|
||||
gfxd_macro_fn([] {
|
||||
auto gfx = static_cast<const Gfx*>(gfxd_macro_data());
|
||||
auto gfx = static_cast<const N64Gfx*>(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<std::tuple<std::string, YAML::Node>> SearchVtx(uint32_t ptr){
|
||||
auto decs = Companion::Instance->GetNodesByType("VTX");
|
||||
@@ -219,7 +224,7 @@ std::optional<std::tuple<std::string, YAML::Node>> SearchVtx(uint32_t ptr){
|
||||
|
||||
auto offset = GetSafeNode<uint32_t>(node, "offset");
|
||||
auto count = GetSafeNode<uint32_t>(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<std::string>(node, "symbol", name), node);
|
||||
@@ -267,7 +272,7 @@ ExportResult DListBinaryExporter::Export(std::ostream &write, std::shared_ptr<IP
|
||||
didx = C0(17, 7);
|
||||
break;
|
||||
default:
|
||||
nvtx = (C0(0, 16)) / sizeof(Vtx_t);
|
||||
nvtx = (C0(0, 16)) / sizeof(N64Vtx_t);
|
||||
didx = C0(16, 4);
|
||||
break;
|
||||
}
|
||||
@@ -290,7 +295,7 @@ ExportResult DListBinaryExporter::Export(std::ostream &write, std::shared_ptr<IP
|
||||
auto count = GetSafeNode<uint32_t>(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<IP
|
||||
|
||||
SPDLOG_INFO("Found vtx: 0x{:X} Hash: 0x{:X} Path: {}", ptr, hash, std::get<0>(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_ptr<IP
|
||||
}
|
||||
|
||||
if(opcode == GBI(G_DL)) {
|
||||
Gfx value;
|
||||
N64Gfx value;
|
||||
auto ptr = w1;
|
||||
auto dec = Companion::Instance->GetNodeByAddr(ptr);
|
||||
auto branch = (w0 >> 16) & G_DL_NO_PUSH;
|
||||
@@ -434,7 +439,7 @@ ExportResult DListBinaryExporter::Export(std::ostream &write, std::shared_ptr<IP
|
||||
writer.Write(w0);
|
||||
writer.Write(w1);
|
||||
} else {
|
||||
Gfx value = gsDPSetTextureOTRImage(C0(21, 3), C0(19, 2), C0(0, 10), ptr);
|
||||
N64Gfx value = gsDPSetTextureOTRImage(C0(21, 3), C0(19, 2), C0(0, 10), ptr);
|
||||
w0 = value.words.w0;
|
||||
w1 = value.words.w1;
|
||||
|
||||
@@ -564,7 +569,7 @@ std::optional<std::shared_ptr<IParsedData>> DListFactory::parse(std::vector<uint
|
||||
nvtx = C0(10, 6);
|
||||
break;
|
||||
default:
|
||||
nvtx = (C0(0, 16)) / sizeof(Vtx_t);
|
||||
nvtx = (C0(0, 16)) / sizeof(N64Vtx_t);
|
||||
break;
|
||||
}
|
||||
const auto decl = Companion::Instance->GetNodeByAddr(w1);
|
||||
@@ -579,7 +584,7 @@ std::optional<std::shared_ptr<IParsedData>> DListFactory::parse(std::vector<uint
|
||||
|
||||
auto lOffset = GetSafeNode<uint32_t>(vtx, "offset");
|
||||
auto lCount = GetSafeNode<uint32_t>(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);
|
||||
|
||||
@@ -20,9 +20,11 @@ class DListBinaryExporter : public BaseExporter {
|
||||
ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> 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<IParsedData> 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 {
|
||||
|
||||
@@ -4,15 +4,18 @@
|
||||
#include "DisplayListFactory.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "Companion.h"
|
||||
|
||||
#include <gfxd.h>
|
||||
#include <string>
|
||||
|
||||
#ifdef STANDALONE
|
||||
#include <gfxd.h>
|
||||
#endif
|
||||
|
||||
namespace GFXDOverride {
|
||||
|
||||
std::unordered_map<uint32_t, std::tuple<std::string, YAML::Node>> 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<uint32_t>(node, "offset");
|
||||
auto count = GetSafeNode<uint32_t>(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<std::tuple<std::string, YAML::Node>> GetVtxOverlap(uint32_t ptr){
|
||||
if(mVtxOverlaps.contains(ptr)){
|
||||
|
||||
@@ -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<std::string, YAML::Node>& vtx);
|
||||
std::optional<std::tuple<std::string, YAML::Node>> GetVtxOverlap(uint32_t ptr);
|
||||
void ClearVtx();
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
#include <cstdlib>
|
||||
#include <cstdarg>
|
||||
#include <stdexcept>
|
||||
#include "binarytools/BinaryWriter.h"
|
||||
#include "BinaryReader.h"
|
||||
#include "lib/binarytools/BinaryWriter.h"
|
||||
#include "lib/binarytools/BinaryReader.h"
|
||||
|
||||
typedef signed char s8;
|
||||
typedef short s16;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "BinaryWriter.h"
|
||||
#include "lib/binarytools/BinaryWriter.h"
|
||||
|
||||
void write_aiff(std::vector<char> data, LUS::BinaryWriter& writer);
|
||||
@@ -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<std::string, uint32_t> name_table;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <yaml-cpp/yaml.h>
|
||||
#include "binarytools/BinaryWriter.h"
|
||||
#include "lib/binarytools/BinaryWriter.h"
|
||||
#include <variant>
|
||||
#include <optional>
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <string>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <spdlog/fmt/ostr.h>
|
||||
#include <binarytools/BinaryWriter.h>
|
||||
#include <lib/binarytools/BinaryWriter.h>
|
||||
#include <types/Vec3D.h>
|
||||
|
||||
enum class BehaviorOpcode {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user