Skip to content

Commit

Permalink
Implement built in Extractor for Windows (HarbourMasters#2730)
Browse files Browse the repository at this point in the history
* wip

* const

* split zapd into two targets

* Workingish.

* fix working dir and copy xmls on build (#2)

* dont change current working dir with dialog prompts

* copy asset xmls to target dir

* make zpadlib public

* Messagebox.

* Check for WIN32

* threading

* Cleanups to the exporter and main.

* Multi extraction.

* Fix byteswap header includes.

* Fix another byteswap include.

* fix again.

* stddef size_t

* Add other targets for ZAPDLib

* Non windows.

* IDYES IDNO

* Linux fixes

* hopefully remove switch and wiiu from building extractor

* Please?

* validate roms and add another valid rom

* ifdef out extract.h for switch and wiiu

* Maybe update lux

* Remove ZAPDlib from switch and WiiU

* more rules

* Update soh/soh/Extractor/Extract.cpp

Co-authored-by: briaguya <70942617+briaguya-ai@users.noreply.github.com>

* Update ZAPDTR/ZAPD/ExecutableMain.cpp

Co-authored-by: briaguya <70942617+briaguya-ai@users.noreply.github.com>

* Update ZAPDTR/ZAPD/CMakeLists.txt

Co-authored-by: briaguya <70942617+briaguya-ai@users.noreply.github.com>

* Update ZAPDTR/ZAPD/GameConfig.cpp

Co-authored-by: briaguya <70942617+briaguya-ai@users.noreply.github.com>

* Update ZAPDTR/ZAPD/Globals.cpp

Co-authored-by: briaguya <70942617+briaguya-ai@users.noreply.github.com>

* Update ZAPDTR/ZAPD/Main.cpp

Co-authored-by: briaguya <70942617+briaguya-ai@users.noreply.github.com>

* Update soh/CMakeLists.txt

Co-authored-by: briaguya <70942617+briaguya-ai@users.noreply.github.com>

* Update soh/soh/Extractor/Extract.cpp

Co-authored-by: briaguya <70942617+briaguya-ai@users.noreply.github.com>

* Update soh/soh/Extractor/Extract.cpp

Co-authored-by: briaguya <70942617+briaguya-ai@users.noreply.github.com>

* Update soh/soh/Extractor/Extract.cpp

Co-authored-by: briaguya <70942617+briaguya-ai@users.noreply.github.com>

* the last fix

* Add context to a comment

---------

Co-authored-by: Adam Bird <archez39@me.com>
Co-authored-by: Adam Bird <Archez@users.noreply.github.com>
Co-authored-by: briaguya <70942617+briaguya-ai@users.noreply.github.com>
  • Loading branch information
4 people committed Apr 25, 2023
1 parent 44d3f1c commit aea46e7
Show file tree
Hide file tree
Showing 15 changed files with 2,758 additions and 50 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ add_custom_target(
# CMake versions prior to 3.17 do not have the rm command, use remove instead for older versions
COMMAND ${CMAKE_COMMAND} -E $<IF:$<VERSION_LESS:${CMAKE_VERSION},3.17>,remove,rm> -f oot.otr oot-mq.otr soh.otr
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/OTRExporter/extract_assets.py -z "$<TARGET_FILE:ZAPD>" --non-interactive
COMMAND ${CMAKE_COMMAND} -DSYSTEM_NAME=${CMAKE_SYSTEM_NAME} -DTARGET_DIR="$<TARGET_FILE_DIR:soh>" -DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR} -DBINARY_DIR=${CMAKE_BINARY_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/copy-existing-otrs.cmake
COMMAND ${CMAKE_COMMAND} -DSYSTEM_NAME=${CMAKE_SYSTEM_NAME} -DTARGET_DIR="$<TARGET_FILE_DIR:ZAPD>" -DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR} -DBINARY_DIR=${CMAKE_BINARY_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/copy-existing-otrs.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/OTRExporter
COMMENT "Running asset extraction..."
DEPENDS ZAPD
Expand Down
10 changes: 6 additions & 4 deletions OTRExporter/OTRExporter/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,13 @@ static void ExporterProgramEnd()
}
}
otrArchive = nullptr;
delete fileWriter;
files.clear();

// Add any additional files that need to be manually copied...
if (File::Exists("soh.otr")) {
return;
}
const auto& lst = Directory::ListFiles("Extract");
std::shared_ptr<Ship::Archive> sohOtr = Ship::Archive::CreateArchive("soh.otr", 4096);
//sohOtr->AddFile("version", (uintptr_t)versionStream->ToVector().data(), versionStream->GetLength());
Expand Down Expand Up @@ -273,7 +278,7 @@ void AddFile(std::string fName, std::vector<char> data)
}
}

static void ImportExporters()
void ImportExporters()
{
// In this example we set up a new exporter called "EXAMPLE".
// By running ZAPD with the argument -se EXAMPLE, we tell it that we want to use this exporter for our resources.
Expand Down Expand Up @@ -312,6 +317,3 @@ static void ImportExporters()

InitVersionInfo();
}

// When ZAPD starts up, it will automatically call the below function, which in turn sets up our exporters.
REGISTER_EXPORTER(ImportExporters);
29 changes: 19 additions & 10 deletions ZAPDTR/ZAPD/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(PROJECT_NAME ZAPD)
set(PROJECT_NAME ZAPDLib)

set(CMAKE_CXX_STANDARD 20 CACHE STRING "The C++ standard to use")
#set(CMAKE_C_STANDARD 11 CACHE STRING "The C standard to use")
Expand Down Expand Up @@ -260,10 +260,17 @@ set(ALL_FILES
################################################################################
# Target
################################################################################
add_executable(${PROJECT_NAME} ${ALL_FILES})

add_library(${PROJECT_NAME} STATIC ${ALL_FILES})

add_executable(ZAPD ExecutableMain.cpp)
target_link_libraries(ZAPD ${PROJECT_NAME})



if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
use_props(${PROJECT_NAME} "${CMAKE_CONFIGURATION_TYPES}" "${DEFAULT_CXX_PROPS}")
use_props(ZAPD "${CMAKE_CONFIGURATION_TYPES}" "${DEFAULT_CXX_PROPS}")
endif()
################################################################################
# Includes for CMake from *.props
Expand All @@ -282,15 +289,16 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
)
endif()
elseif (CMAKE_SYSTEM_NAME MATCHES "Linux|Darwin")
set_target_properties(${PROJECT_NAME} PROPERTIES
set_target_properties(ZAPD PROPERTIES
OUTPUT_NAME "ZAPD.out"
)
endif()
################################################################################
# MSVC runtime library
################################################################################
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
get_property(MSVC_RUNTIME_LIBRARY_DEFAULT TARGET ${PROJECT_NAME} PROPERTY MSVC_RUNTIME_LIBRARY)
foreach(ZTarget ${PROJECT_NAME} ZAPD)
get_property(MSVC_RUNTIME_LIBRARY_DEFAULT TARGET ${ZTarget} PROPERTY MSVC_RUNTIME_LIBRARY)
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
string(CONCAT "MSVC_RUNTIME_LIBRARY_STR"
$<$<CONFIG:Debug>:
Expand All @@ -302,7 +310,8 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
$<$<NOT:$<OR:$<CONFIG:Debug>,$<CONFIG:Release>>>:${MSVC_RUNTIME_LIBRARY_DEFAULT}>
)
endif()
set_target_properties(${PROJECT_NAME} PROPERTIES MSVC_RUNTIME_LIBRARY ${MSVC_RUNTIME_LIBRARY_STR})
set_target_properties(${ZTarget} PROPERTIES MSVC_RUNTIME_LIBRARY ${MSVC_RUNTIME_LIBRARY_STR})
endforeach()
endif()
################################################################################
# Compile definitions
Expand Down Expand Up @@ -404,7 +413,7 @@ if(MSVC)
endif()

if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU|Clang|AppleClang")
target_compile_options(${PROJECT_NAME} PRIVATE
target_compile_options(${PROJECT_NAME} PUBLIC
-Wall -Wextra -Wno-error
-Wno-unused-parameter
-Wno-unused-function
Expand All @@ -417,11 +426,11 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU|Clang|AppleClang")
)

if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
target_link_options(${PROJECT_NAME} PRIVATE
target_link_options(${PROJECT_NAME} PUBLIC
-pthread
)
else()
target_link_options(${PROJECT_NAME} PRIVATE
target_link_options(${PROJECT_NAME} PUBLIC
-pthread
-Wl,-export-dynamic
)
Expand Down Expand Up @@ -491,7 +500,7 @@ endif()

if(CMAKE_SYSTEM_NAME MATCHES "NintendoSwitch|CafeOS")
add_library(pathconf OBJECT pathconf.c)
target_link_libraries(${PROJECT_NAME} PRIVATE "${ADDITIONAL_LIBRARY_DEPENDENCIES}" $<TARGET_OBJECTS:pathconf> )
target_link_libraries(${PROJECT_NAME} PUBLIC "${ADDITIONAL_LIBRARY_DEPENDENCIES}" $<TARGET_OBJECTS:pathconf> )
else()
target_link_libraries(${PROJECT_NAME} PRIVATE "${ADDITIONAL_LIBRARY_DEPENDENCIES}")
target_link_libraries(${PROJECT_NAME} PUBLIC "${ADDITIONAL_LIBRARY_DEPENDENCIES}")
endif()
5 changes: 5 additions & 0 deletions ZAPDTR/ZAPD/ExecutableMain.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extern "C" int zapd_main(int argc, char* argv[]);

int main(int argc, char* argv[]) {
return zapd_main(argc, argv);
}
11 changes: 7 additions & 4 deletions ZAPDTR/ZAPD/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ Globals::Globals()

Globals::~Globals()
{
auto& exporters = GetExporterMap();

for (auto& it : exporters)
for (const auto& w : workerData)
{
delete it.second;
delete w.second;
}

if (rom != nullptr)
{
delete rom;
}
}

Expand Down
2 changes: 1 addition & 1 deletion ZAPDTR/ZAPD/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Globals
bool buildRawTexture = false;
bool onlyGenSohOtr = false;

ZRom* rom;
ZRom* rom = nullptr;
std::vector<ZFile*> files;
std::vector<ZFile*> externalFiles;
std::vector<int32_t> segments;
Expand Down
93 changes: 69 additions & 24 deletions ZAPDTR/ZAPD/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,71 @@
#include "Utils/File.h"
#include "Utils/Path.h"
#include "WarningHandler.h"

#include "ZAnimation.h"
ZNormalAnimation nAnim(nullptr);
ZCurveAnimation cAnim(nullptr);
ZLinkAnimation lAnim(nullptr);
ZLegacyAnimation lAnim2(nullptr);

#include "ZArray.h"
ZArray arr(nullptr);

#include "ZAudio.h"
ZAudio audio(nullptr);

#include "ZBackground.h"
ZBackground back(nullptr);

#include "ZBlob.h"
ZBlob blob(nullptr);

#include "ZCollision.h"
ZCollisionHeader colHeader(nullptr);

#include "ZCutscene.h"
ZCutscene cs(nullptr);

#include "ZLimb.h"
ZLimb limb(nullptr);

#include "ZMtx.h"
ZMtx mtx(nullptr);

#include "ZPath.h"
ZPath path(nullptr);

#include "ZPlayerAnimationData.h"
ZPlayerAnimationData pAnimData(nullptr);

#include "ZScalar.h"
ZScalar scalar(nullptr);

#include "ZSkeleton.h"
ZLimbTable limbTbl(nullptr);
ZSkeleton skel(nullptr);

#include "ZString.h"
ZString str(nullptr);

#include "ZSymbol.h"
ZSymbol sym(nullptr);

#include "ZText.h"
ZText txt(nullptr);

#include "ZTexture.h"
ZTexture tex(nullptr);

#include "ZVector.h"
ZVector vec(nullptr);

#include "ZVtx.h"
ZVtx vtx(nullptr);

#include "ZRoom/ZRoom.h"
ZRoom room(nullptr);

#include "ZFile.h"
#include "ZTexture.h"

Expand All @@ -29,29 +91,6 @@
const char gBuildHash[] = "";

// LINUX_TODO: remove, those are because of soh <-> lus dependency problems
float divisor_num = 0.0f;

extern "C" void Audio_SetGameVolume(int player_id, float volume)
{

}


extern "C" int ResourceMgr_OTRSigCheck(char* imgData)
{
return 0;
}

void DebugConsole_SaveCVars()
{

}

void DebugConsole_LoadCVars()
{

}


bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, const fs::path& outPath,
ZFileMode fileMode, int workerID);
Expand Down Expand Up @@ -119,7 +158,9 @@ void ErrorHandler(int sig)
}
#endif

int main(int argc, char* argv[])
extern void ImportExporters();

extern "C" int zapd_main(int argc, char* argv[])
{
// Syntax: ZAPD.out [mode (btex/bovl/e)] (Arbritrary Number of Arguments)

Expand Down Expand Up @@ -242,6 +283,7 @@ int main(int argc, char* argv[])
}
else if (arg == "-se" || arg == "--set-exporter") // Set Current Exporter
{
ImportExporters();
Globals::Instance->currentExporter = argv[++i];
}
else if (arg == "--gcc-compat") // GCC compatibility
Expand Down Expand Up @@ -434,6 +476,9 @@ int main(int argc, char* argv[])
exporterSet->endProgramFunc();

end:
delete exporterSet;

//Globals::Instance->GetExporterSet() = nullptr; //TODO NULL this out. Compiler complains about lvalue assignment.

delete g;
return 0;
Expand Down
Loading

0 comments on commit aea46e7

Please sign in to comment.