Skip to content

Commit aea46e7

Browse files
louist103Archezbriaguya0
authored
Implement built in Extractor for Windows (HarbourMasters#2730)
* 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>
1 parent 44d3f1c commit aea46e7

File tree

15 files changed

+2758
-50
lines changed

15 files changed

+2758
-50
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ add_custom_target(
111111
# CMake versions prior to 3.17 do not have the rm command, use remove instead for older versions
112112
COMMAND ${CMAKE_COMMAND} -E $<IF:$<VERSION_LESS:${CMAKE_VERSION},3.17>,remove,rm> -f oot.otr oot-mq.otr soh.otr
113113
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/OTRExporter/extract_assets.py -z "$<TARGET_FILE:ZAPD>" --non-interactive
114-
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
114+
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
115115
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/OTRExporter
116116
COMMENT "Running asset extraction..."
117117
DEPENDS ZAPD

OTRExporter/OTRExporter/Main.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,13 @@ static void ExporterProgramEnd()
107107
}
108108
}
109109
otrArchive = nullptr;
110+
delete fileWriter;
111+
files.clear();
110112

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

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

313318
InitVersionInfo();
314319
}
315-
316-
// When ZAPD starts up, it will automatically call the below function, which in turn sets up our exporters.
317-
REGISTER_EXPORTER(ImportExporters);

ZAPDTR/ZAPD/CMakeLists.txt

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
set(PROJECT_NAME ZAPD)
1+
set(PROJECT_NAME ZAPDLib)
22

33
set(CMAKE_CXX_STANDARD 20 CACHE STRING "The C++ standard to use")
44
#set(CMAKE_C_STANDARD 11 CACHE STRING "The C standard to use")
@@ -260,10 +260,17 @@ set(ALL_FILES
260260
################################################################################
261261
# Target
262262
################################################################################
263-
add_executable(${PROJECT_NAME} ${ALL_FILES})
263+
264+
add_library(${PROJECT_NAME} STATIC ${ALL_FILES})
265+
266+
add_executable(ZAPD ExecutableMain.cpp)
267+
target_link_libraries(ZAPD ${PROJECT_NAME})
268+
269+
264270

265271
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
266272
use_props(${PROJECT_NAME} "${CMAKE_CONFIGURATION_TYPES}" "${DEFAULT_CXX_PROPS}")
273+
use_props(ZAPD "${CMAKE_CONFIGURATION_TYPES}" "${DEFAULT_CXX_PROPS}")
267274
endif()
268275
################################################################################
269276
# Includes for CMake from *.props
@@ -282,15 +289,16 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
282289
)
283290
endif()
284291
elseif (CMAKE_SYSTEM_NAME MATCHES "Linux|Darwin")
285-
set_target_properties(${PROJECT_NAME} PROPERTIES
292+
set_target_properties(ZAPD PROPERTIES
286293
OUTPUT_NAME "ZAPD.out"
287294
)
288295
endif()
289296
################################################################################
290297
# MSVC runtime library
291298
################################################################################
292299
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
293-
get_property(MSVC_RUNTIME_LIBRARY_DEFAULT TARGET ${PROJECT_NAME} PROPERTY MSVC_RUNTIME_LIBRARY)
300+
foreach(ZTarget ${PROJECT_NAME} ZAPD)
301+
get_property(MSVC_RUNTIME_LIBRARY_DEFAULT TARGET ${ZTarget} PROPERTY MSVC_RUNTIME_LIBRARY)
294302
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
295303
string(CONCAT "MSVC_RUNTIME_LIBRARY_STR"
296304
$<$<CONFIG:Debug>:
@@ -302,7 +310,8 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
302310
$<$<NOT:$<OR:$<CONFIG:Debug>,$<CONFIG:Release>>>:${MSVC_RUNTIME_LIBRARY_DEFAULT}>
303311
)
304312
endif()
305-
set_target_properties(${PROJECT_NAME} PROPERTIES MSVC_RUNTIME_LIBRARY ${MSVC_RUNTIME_LIBRARY_STR})
313+
set_target_properties(${ZTarget} PROPERTIES MSVC_RUNTIME_LIBRARY ${MSVC_RUNTIME_LIBRARY_STR})
314+
endforeach()
306315
endif()
307316
################################################################################
308317
# Compile definitions
@@ -404,7 +413,7 @@ if(MSVC)
404413
endif()
405414

406415
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU|Clang|AppleClang")
407-
target_compile_options(${PROJECT_NAME} PRIVATE
416+
target_compile_options(${PROJECT_NAME} PUBLIC
408417
-Wall -Wextra -Wno-error
409418
-Wno-unused-parameter
410419
-Wno-unused-function
@@ -417,11 +426,11 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU|Clang|AppleClang")
417426
)
418427

419428
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
420-
target_link_options(${PROJECT_NAME} PRIVATE
429+
target_link_options(${PROJECT_NAME} PUBLIC
421430
-pthread
422431
)
423432
else()
424-
target_link_options(${PROJECT_NAME} PRIVATE
433+
target_link_options(${PROJECT_NAME} PUBLIC
425434
-pthread
426435
-Wl,-export-dynamic
427436
)
@@ -491,7 +500,7 @@ endif()
491500

492501
if(CMAKE_SYSTEM_NAME MATCHES "NintendoSwitch|CafeOS")
493502
add_library(pathconf OBJECT pathconf.c)
494-
target_link_libraries(${PROJECT_NAME} PRIVATE "${ADDITIONAL_LIBRARY_DEPENDENCIES}" $<TARGET_OBJECTS:pathconf> )
503+
target_link_libraries(${PROJECT_NAME} PUBLIC "${ADDITIONAL_LIBRARY_DEPENDENCIES}" $<TARGET_OBJECTS:pathconf> )
495504
else()
496-
target_link_libraries(${PROJECT_NAME} PRIVATE "${ADDITIONAL_LIBRARY_DEPENDENCIES}")
505+
target_link_libraries(${PROJECT_NAME} PUBLIC "${ADDITIONAL_LIBRARY_DEPENDENCIES}")
497506
endif()

ZAPDTR/ZAPD/ExecutableMain.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
extern "C" int zapd_main(int argc, char* argv[]);
2+
3+
int main(int argc, char* argv[]) {
4+
return zapd_main(argc, argv);
5+
}

ZAPDTR/ZAPD/Globals.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@ Globals::Globals()
2727

2828
Globals::~Globals()
2929
{
30-
auto& exporters = GetExporterMap();
31-
32-
for (auto& it : exporters)
30+
for (const auto& w : workerData)
3331
{
34-
delete it.second;
32+
delete w.second;
33+
}
34+
35+
if (rom != nullptr)
36+
{
37+
delete rom;
3538
}
3639
}
3740

ZAPDTR/ZAPD/Globals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Globals
6767
bool buildRawTexture = false;
6868
bool onlyGenSohOtr = false;
6969

70-
ZRom* rom;
70+
ZRom* rom = nullptr;
7171
std::vector<ZFile*> files;
7272
std::vector<ZFile*> externalFiles;
7373
std::vector<int32_t> segments;

ZAPDTR/ZAPD/Main.cpp

Lines changed: 69 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,71 @@
44
#include "Utils/File.h"
55
#include "Utils/Path.h"
66
#include "WarningHandler.h"
7+
78
#include "ZAnimation.h"
9+
ZNormalAnimation nAnim(nullptr);
10+
ZCurveAnimation cAnim(nullptr);
11+
ZLinkAnimation lAnim(nullptr);
12+
ZLegacyAnimation lAnim2(nullptr);
13+
14+
#include "ZArray.h"
15+
ZArray arr(nullptr);
16+
17+
#include "ZAudio.h"
18+
ZAudio audio(nullptr);
19+
820
#include "ZBackground.h"
21+
ZBackground back(nullptr);
22+
923
#include "ZBlob.h"
24+
ZBlob blob(nullptr);
25+
26+
#include "ZCollision.h"
27+
ZCollisionHeader colHeader(nullptr);
28+
29+
#include "ZCutscene.h"
30+
ZCutscene cs(nullptr);
31+
32+
#include "ZLimb.h"
33+
ZLimb limb(nullptr);
34+
35+
#include "ZMtx.h"
36+
ZMtx mtx(nullptr);
37+
38+
#include "ZPath.h"
39+
ZPath path(nullptr);
40+
41+
#include "ZPlayerAnimationData.h"
42+
ZPlayerAnimationData pAnimData(nullptr);
43+
44+
#include "ZScalar.h"
45+
ZScalar scalar(nullptr);
46+
47+
#include "ZSkeleton.h"
48+
ZLimbTable limbTbl(nullptr);
49+
ZSkeleton skel(nullptr);
50+
51+
#include "ZString.h"
52+
ZString str(nullptr);
53+
54+
#include "ZSymbol.h"
55+
ZSymbol sym(nullptr);
56+
57+
#include "ZText.h"
58+
ZText txt(nullptr);
59+
60+
#include "ZTexture.h"
61+
ZTexture tex(nullptr);
62+
63+
#include "ZVector.h"
64+
ZVector vec(nullptr);
65+
66+
#include "ZVtx.h"
67+
ZVtx vtx(nullptr);
68+
69+
#include "ZRoom/ZRoom.h"
70+
ZRoom room(nullptr);
71+
1072
#include "ZFile.h"
1173
#include "ZTexture.h"
1274

@@ -29,29 +91,6 @@
2991
const char gBuildHash[] = "";
3092

3193
// LINUX_TODO: remove, those are because of soh <-> lus dependency problems
32-
float divisor_num = 0.0f;
33-
34-
extern "C" void Audio_SetGameVolume(int player_id, float volume)
35-
{
36-
37-
}
38-
39-
40-
extern "C" int ResourceMgr_OTRSigCheck(char* imgData)
41-
{
42-
return 0;
43-
}
44-
45-
void DebugConsole_SaveCVars()
46-
{
47-
48-
}
49-
50-
void DebugConsole_LoadCVars()
51-
{
52-
53-
}
54-
5594

5695
bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, const fs::path& outPath,
5796
ZFileMode fileMode, int workerID);
@@ -119,7 +158,9 @@ void ErrorHandler(int sig)
119158
}
120159
#endif
121160

122-
int main(int argc, char* argv[])
161+
extern void ImportExporters();
162+
163+
extern "C" int zapd_main(int argc, char* argv[])
123164
{
124165
// Syntax: ZAPD.out [mode (btex/bovl/e)] (Arbritrary Number of Arguments)
125166

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

436478
end:
479+
delete exporterSet;
480+
481+
//Globals::Instance->GetExporterSet() = nullptr; //TODO NULL this out. Compiler complains about lvalue assignment.
437482

438483
delete g;
439484
return 0;

0 commit comments

Comments
 (0)