Skip to content

Commit

Permalink
O2R support
Browse files Browse the repository at this point in the history
  • Loading branch information
louist103 committed May 14, 2024
1 parent 73d7bd8 commit 4262cc0
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 32 deletions.
16 changes: 8 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ set_property(TARGET mm PROPERTY APPIMAGE_ICON_FILE "${CMAKE_BINARY_DIR}/2s2hIcon

if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
install(PROGRAMS "${CMAKE_BINARY_DIR}/linux/2s2h.sh" DESTINATION . COMPONENT appimage)
install(FILES "${CMAKE_SOURCE_DIR}/2ship.otr" DESTINATION . COMPONENT ship)
install(FILES "${CMAKE_SOURCE_DIR}/2ship.zip" DESTINATION . COMPONENT ship)
install(TARGETS ZAPD DESTINATION ./assets/extractor COMPONENT extractor)
install(DIRECTORY "${CMAKE_SOURCE_DIR}/mm/assets/extractor/" DESTINATION ./assets/extractor COMPONENT extractor)
install(DIRECTORY "${CMAKE_SOURCE_DIR}/mm/assets/xml/" DESTINATION ./assets/extractor/xmls COMPONENT extractor)
Expand All @@ -134,13 +134,13 @@ find_package(Python3 COMPONENTS Interpreter)
add_custom_target(
ExtractAssets
# 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 mm.otr 2ship.otr
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/OTRExporter/extract_assets.py -z "$<TARGET_FILE:ZAPD>" --non-interactive --xml-root ../mm/assets/xml --custom-otr-file 2ship.otr "--custom-assets-path" ${CMAKE_CURRENT_SOURCE_DIR}/mm/assets/custom --port-ver "${CMAKE_PROJECT_VERSION}"
COMMAND ${CMAKE_COMMAND} -E $<IF:$<VERSION_LESS:${CMAKE_VERSION},3.17>,remove,rm> -f mm.zip 2ship.zip
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/OTRExporter/extract_assets.py -z "$<TARGET_FILE:ZAPD>" --non-interactive --xml-root ../mm/assets/xml --custom-otr-file 2ship.zip "--custom-assets-path" ${CMAKE_CURRENT_SOURCE_DIR}/mm/assets/custom --port-ver "${CMAKE_PROJECT_VERSION}"
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
BYPRODUCTS mm.otr ${CMAKE_SOURCE_DIR}/mm.otr ${CMAKE_SOURCE_DIR}/2ship.otr
BYPRODUCTS mm.zip ${CMAKE_SOURCE_DIR}/mm.zip ${CMAKE_SOURCE_DIR}/2ship.zip
)

# Target to generate headers
Expand All @@ -152,15 +152,15 @@ add_custom_target(
DEPENDS ZAPD
)

# Target to generate only 2ship.otr
# Target to generate only 2ship.zip
add_custom_target(
Generate2ShipOtr
# 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 2ship.otr
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/OTRExporter/extract_assets.py -z "$<TARGET_FILE:ZAPD>" --norom --custom-otr-file 2ship.otr "--custom-assets-path" ${CMAKE_CURRENT_SOURCE_DIR}/mm/assets/custom --port-ver "${CMAKE_PROJECT_VERSION}"
COMMAND ${CMAKE_COMMAND} -E $<IF:$<VERSION_LESS:${CMAKE_VERSION},3.17>,remove,rm> -f 2ship.zip
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/OTRExporter/extract_assets.py -z "$<TARGET_FILE:ZAPD>" --norom --custom-otr-file 2ship.zip "--custom-assets-path" ${CMAKE_CURRENT_SOURCE_DIR}/mm/assets/custom --port-ver "${CMAKE_PROJECT_VERSION}"
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} -DONLY2SHIPOTR=On -P ${CMAKE_CURRENT_SOURCE_DIR}/copy-existing-otrs.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/OTRExporter
COMMENT "Generating 2ship.otr..."
COMMENT "Generating 2ship.zip..."
DEPENDS ZAPD
)

Expand Down
32 changes: 16 additions & 16 deletions copy-existing-otrs.cmake
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
message(STATUS "Copying otr files...")

if(NOT ONLY2SHIPOTR AND EXISTS ${SOURCE_DIR}/OTRExporter/mm.otr)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy mm.otr ${SOURCE_DIR})
execute_process(COMMAND ${CMAKE_COMMAND} -E copy mm.otr ${BINARY_DIR}/mm/)
message(STATUS "Copied mm.otr")
if(NOT ONLY2SHIPOTR AND EXISTS ${SOURCE_DIR}/OTRExporter/mm.zip)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy mm.zip ${SOURCE_DIR})
execute_process(COMMAND ${CMAKE_COMMAND} -E copy mm.zip ${BINARY_DIR}/mm/)
message(STATUS "Copied mm.zip")
endif()
if(EXISTS ${SOURCE_DIR}/OTRExporter/2ship.otr)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy 2ship.otr ${SOURCE_DIR})
execute_process(COMMAND ${CMAKE_COMMAND} -E copy 2ship.otr ${BINARY_DIR}/mm/)
message(STATUS "Copied 2ship.otr")
if(EXISTS ${SOURCE_DIR}/OTRExporter/2ship.zip)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy 2ship.zip ${SOURCE_DIR})
execute_process(COMMAND ${CMAKE_COMMAND} -E copy 2ship.zip ${BINARY_DIR}/mm/)
message(STATUS "Copied 2ship.zip")
endif()

# Additionally for Windows, copy the otrs to the target dir, side by side with 2ship.exe
if(SYSTEM_NAME MATCHES "Windows")
if(NOT ONLY2SHIPOTR AND EXISTS ${SOURCE_DIR}/OTRExporter/mm.otr)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy mm.otr ${TARGET_DIR})
if(NOT ONLY2SHIPOTR AND EXISTS ${SOURCE_DIR}/OTRExporter/mm.zip)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy mm.zip ${TARGET_DIR})
endif()
if(EXISTS ${SOURCE_DIR}/OTRExporter/2ship.otr)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy 2ship.otr ${TARGET_DIR})
if(EXISTS ${SOURCE_DIR}/OTRExporter/2ship.zip)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy 2ship.zip ${TARGET_DIR})
endif()
endif()

if(NOT ONLY2SHIPOTR AND (NOT EXISTS ${SOURCE_DIR}/mm.otr))
message(FATAL_ERROR "Failed to copy. No OTR files found.")
if(NOT ONLY2SHIPOTR AND (NOT EXISTS ${SOURCE_DIR}/mm.zip))
message(FATAL_ERROR "Failed to copy. No ZIP files found.")
endif()
if(NOT EXISTS ${SOURCE_DIR}/2ship.otr)
message(FATAL_ERROR "Failed to copy. No 2ship OTR found.")
if(NOT EXISTS ${SOURCE_DIR}/2ship.zip)
message(FATAL_ERROR "Failed to copy. No 2ship ZIP found.")
endif()
8 changes: 4 additions & 4 deletions mm/2s2h/BenPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,19 @@ OTRGlobals::OTRGlobals() {
//if (std::filesystem::exists(mqPath)) {
// OTRFiles.push_back(mqPath);
//}
std::string ootPath = Ship::Context::LocateFileAcrossAppDirs("mm.otr", appShortName);
std::string ootPath = Ship::Context::LocateFileAcrossAppDirs("mm.zip", appShortName);
if (std::filesystem::exists(ootPath)) {
OTRFiles.push_back(ootPath);
}
std::string shipOtrPath = Ship::Context::GetPathRelativeToAppBundle("2ship.otr");
std::string shipOtrPath = Ship::Context::GetPathRelativeToAppBundle("2ship.zip");
if (std::filesystem::exists(shipOtrPath)) {
OTRFiles.push_back(shipOtrPath);
}
std::string patchesPath = Ship::Context::LocateFileAcrossAppDirs("mods", appShortName);
if (patchesPath.length() > 0 && std::filesystem::exists(patchesPath)) {
if (std::filesystem::is_directory(patchesPath)) {
for (const auto& p : std::filesystem::recursive_directory_iterator(patchesPath)) {
if (StringHelper::IEquals(p.path().extension().string(), ".otr")) {
if (StringHelper::IEquals(p.path().extension().string(), ".zip")) {
OTRFiles.push_back(p.path().generic_string());
}
}
Expand Down Expand Up @@ -397,7 +397,7 @@ extern "C" void OTRExtScanner() {

extern "C" void InitOTR() {
#if not defined(__SWITCH__) && not defined(__WIIU__)
if (!std::filesystem::exists(Ship::Context::LocateFileAcrossAppDirs("mm.otr", appShortName))) {
if (!std::filesystem::exists(Ship::Context::LocateFileAcrossAppDirs("mm.zip", appShortName))) {
std::string installPath = Ship::Context::GetAppBundlePath();
if (!std::filesystem::exists(installPath + "/assets/extractor")) {
Extractor::ShowErrorBox(
Expand Down
2 changes: 1 addition & 1 deletion mm/2s2h/Extractor/Extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ bool Extractor::CallZapd(std::string installPath, std::string exportdir) {
char portVersion[18]; // 5 digits for int16_max (x3) + separators + terminator
std::array<const char*, argc> argv;
const char* version = GetZapdVerStr();
const char* otrFile = "mm.otr";
const char* otrFile = "mm.zip";

std::string romPath = std::filesystem::absolute(mCurrentRomPath).string();
installPath = std::filesystem::absolute(installPath).string();
Expand Down
4 changes: 2 additions & 2 deletions mm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ endif()

if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
INSTALL(FILES $<TARGET_PDB_FILE:mm> DESTINATION ./debug COMPONENT 2s2h)
INSTALL(FILES ${CMAKE_BINARY_DIR}/mm/2ship.otr DESTINATION . COMPONENT 2s2h)
INSTALL(FILES ${CMAKE_BINARY_DIR}/mm/2ship.zip DESTINATION . COMPONENT 2s2h)
endif()

if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
Expand All @@ -707,7 +707,7 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/macosx/Info.plist.in ${CMAKE_BINARY_DIR}/macosx/Info.plist @ONLY)
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/macosx/2s2h-macos.sh.in ${CMAKE_BINARY_DIR}/macosx/2s2h-macos.sh @ONLY)
INSTALL(FILES ${CMAKE_BINARY_DIR}/gamecontrollerdb.txt DESTINATION ../MacOS COMPONENT 2s2h)
INSTALL(FILES ${CMAKE_BINARY_DIR}/mm/2ship.otr DESTINATION ../Resources COMPONENT 2s2h)
INSTALL(FILES ${CMAKE_BINARY_DIR}/mm/2ship.zip DESTINATION ../Resources COMPONENT 2s2h)
elseif(NOT "${CMAKE_SYSTEM_NAME}" MATCHES "NintendoSwitch|CafeOS")
INSTALL(FILES ${CMAKE_BINARY_DIR}/gamecontrollerdb.txt DESTINATION . COMPONENT 2s2h)
endif()
Expand Down

0 comments on commit 4262cc0

Please sign in to comment.