From a6ba394ecd1ce957c487a9f27355f43086eb4371 Mon Sep 17 00:00:00 2001 From: AltoXorg <56553686+Alto1772@users.noreply.github.com> Date: Thu, 31 Jul 2025 09:33:02 +0800 Subject: [PATCH 1/6] Fix non-portable build --- src/port/Engine.cpp | 24 ++++++++++-------------- src/port/extractor/GameExtractor.cpp | 7 +++++-- tools/Torch | 2 +- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/port/Engine.cpp b/src/port/Engine.cpp index d2bee9ecf..bc0ccb1f7 100644 --- a/src/port/Engine.cpp +++ b/src/port/Engine.cpp @@ -63,6 +63,9 @@ std::vector MemoryPool; GameEngine* GameEngine::Instance; GameEngine::GameEngine() { + // Initialize context properties early to recognize paths properly for non-portable builds + this->context = Ship::Context::CreateUninitializedInstance("Starship", "ship", "starship.cfg.json"); + #ifdef __SWITCH__ Ship::Switch::Init(Ship::PreInitPhase); Ship::Switch::Init(Ship::PostInitPhase); @@ -70,21 +73,12 @@ GameEngine::GameEngine() { std::vector archiveFiles; const std::string main_path = Ship::Context::GetPathRelativeToAppDirectory("sf64.o2r"); -#ifdef __linux__ - const std::string assets_path = Ship::Context::GetPathRelativeToAppBundle("starship.o2r"); -#else - const std::string assets_path = Ship::Context::GetPathRelativeToAppDirectory("starship.o2r"); -#endif - + const std::string assets_path = Ship::Context::LocateFileAcrossAppDirs("starship.o2r"); #ifdef _WIN32 AllocConsole(); #endif - if (!fs::exists("mods")) { - fs::create_directories("mods"); - } - if (std::filesystem::exists(main_path)) { archiveFiles.push_back(main_path); } else { @@ -111,7 +105,11 @@ GameEngine::GameEngine() { } if (const std::string patches_path = Ship::Context::GetPathRelativeToAppDirectory("mods"); - !patches_path.empty() && std::filesystem::exists(patches_path)) { + !patches_path.empty()) { + if (!std::filesystem::exists(patches_path)) { + std::filesystem::create_directories(patches_path); + } + if (std::filesystem::is_directory(patches_path)) { for (const auto& p : std::filesystem::recursive_directory_iterator(patches_path)) { const auto ext = p.path().extension().string(); @@ -127,8 +125,6 @@ GameEngine::GameEngine() { } } - this->context = Ship::Context::CreateUninitializedInstance("Starship", "ship", "starship.cfg.json"); - this->context->InitConfiguration(); // without this line InitConsoleVariables fails at Config::Reload() this->context->InitConsoleVariables(); // without this line the controldeck constructor failes in // ShipDeviceIndexMappingManager::UpdateControllerNamesFromConfig() @@ -849,4 +845,4 @@ extern "C" void GameEngine_Free(void* ptr) { break; } } -} \ No newline at end of file +} diff --git a/src/port/extractor/GameExtractor.cpp b/src/port/extractor/GameExtractor.cpp index f8392bc8b..d75ab3c3a 100644 --- a/src/port/extractor/GameExtractor.cpp +++ b/src/port/extractor/GameExtractor.cpp @@ -54,7 +54,10 @@ std::optional GameExtractor::ValidateChecksum() const { } bool GameExtractor::GenerateOTR() const { - Companion::Instance = new Companion(this->mGameData, ArchiveType::O2R, false); + const std::string assets_path = Ship::Context::GetAppBundlePath(); + const std::string game_path = Ship::Context::GetAppDirectoryPath(); + + Companion::Instance = new Companion(this->mGameData, ArchiveType::O2R, false, assets_path, game_path); try { Companion::Instance->Init(ExportType::Binary); @@ -63,4 +66,4 @@ bool GameExtractor::GenerateOTR() const { } return true; -} \ No newline at end of file +} diff --git a/tools/Torch b/tools/Torch index f75facb20..a81b16b01 160000 --- a/tools/Torch +++ b/tools/Torch @@ -1 +1 @@ -Subproject commit f75facb20883570ed091e8ae733ec0539f606e57 +Subproject commit a81b16b01fdda0dc82e26cb37f19e3e54b275cf4 From c03d73664dd2a9a46d9dbb05f6e1f9c96a19fa61 Mon Sep 17 00:00:00 2001 From: AltoXorg <56553686+Alto1772@users.noreply.github.com> Date: Thu, 31 Jul 2025 22:12:17 +0800 Subject: [PATCH 2/6] Renamed to `ObjectInitResource` from src/port --- src/port/resource/importers/ObjectInitFactory.cpp | 2 +- src/port/resource/type/ObjectInit.cpp | 4 ++-- src/port/resource/type/ObjectInit.h | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/port/resource/importers/ObjectInitFactory.cpp b/src/port/resource/importers/ObjectInitFactory.cpp index 9ebe330c7..b8965b8d8 100644 --- a/src/port/resource/importers/ObjectInitFactory.cpp +++ b/src/port/resource/importers/ObjectInitFactory.cpp @@ -12,7 +12,7 @@ std::shared_ptr ResourceFactoryBinaryObjectInitV0::ReadResource return nullptr; } - auto obj = std::make_shared(initData); + auto obj = std::make_shared(initData); auto reader = std::get>(file->Reader); auto count = reader->ReadUInt32(); diff --git a/src/port/resource/type/ObjectInit.cpp b/src/port/resource/type/ObjectInit.cpp index 3fe6e95b7..766befe3b 100644 --- a/src/port/resource/type/ObjectInit.cpp +++ b/src/port/resource/type/ObjectInit.cpp @@ -1,11 +1,11 @@ #include "ObjectInit.h" namespace SF64 { -ObjectInitData* ObjectInit::GetPointer() { +ObjectInitData* ObjectInitResource::GetPointer() { return mObjects.data(); } -size_t ObjectInit::GetPointerSize() { +size_t ObjectInitResource::GetPointerSize() { return sizeof(ObjectInitData) * mObjects.size(); } } \ No newline at end of file diff --git a/src/port/resource/type/ObjectInit.h b/src/port/resource/type/ObjectInit.h index e6da7023d..3e57240c6 100644 --- a/src/port/resource/type/ObjectInit.h +++ b/src/port/resource/type/ObjectInit.h @@ -16,11 +16,12 @@ struct ObjectInitData { /* 0x10 */ int16_t id; }; // size = 0x14 -class ObjectInit : public Ship::Resource { +// Renamed from ObjectInit to prevent clashing with Torch of same namespace +class ObjectInitResource : public Ship::Resource { public: using Resource::Resource; - ObjectInit() : Resource(std::shared_ptr()) {} + ObjectInitResource() : Resource(std::shared_ptr()) {} ObjectInitData* GetPointer(); size_t GetPointerSize(); From c352a7a90994e1fecf02ee0dc173a6b397e4d0f2 Mon Sep 17 00:00:00 2001 From: AltoXorg <56553686+Alto1772@users.noreply.github.com> Date: Sun, 3 Aug 2025 19:32:27 +0800 Subject: [PATCH 3/6] submodule update Torch, [TEMP] libultraship --- libultraship | 2 +- tools/Torch | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libultraship b/libultraship index 45c4f8d6c..8ddd3650b 160000 --- a/libultraship +++ b/libultraship @@ -1 +1 @@ -Subproject commit 45c4f8d6c19c6176f5e0918917c655ea09ecc212 +Subproject commit 8ddd3650bb174ac6d3ec1eff8a79594ab1d1f308 diff --git a/tools/Torch b/tools/Torch index a81b16b01..cd92cc0f1 160000 --- a/tools/Torch +++ b/tools/Torch @@ -1 +1 @@ -Subproject commit a81b16b01fdda0dc82e26cb37f19e3e54b275cf4 +Subproject commit cd92cc0f161c5e79e36f5dda0d0029edd3fc8d50 From 60bf0579789790ae9efcf58f8e7ee2bf31a46dd5 Mon Sep 17 00:00:00 2001 From: AltoXorg <56553686+Alto1772@users.noreply.github.com> Date: Sat, 9 Aug 2025 14:48:36 +0800 Subject: [PATCH 4/6] submodule update libultraship --- libultraship | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libultraship b/libultraship index 8ddd3650b..09dfab5fb 160000 --- a/libultraship +++ b/libultraship @@ -1 +1 @@ -Subproject commit 8ddd3650bb174ac6d3ec1eff8a79594ab1d1f308 +Subproject commit 09dfab5fb2a9a047a6e268dc9db2daad9b2ce5f0 From 788fe19f9207bd7d0754f1963929b7a7341642ba Mon Sep 17 00:00:00 2001 From: AltoXorg <56553686+Alto1772@users.noreply.github.com> Date: Sat, 9 Aug 2025 16:06:36 +0800 Subject: [PATCH 5/6] place assets in exe's dir on post build --- CMakeLists.txt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 95e07b00d..d95644030 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,11 +49,6 @@ set_property(DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT set_property(DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY VS_DEBUGGER_WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) endif() -if(NOT EXISTS ${CMAKE_BINARY_DIR}/config.yml) - execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_SOURCE_DIR}/config.yml" "${CMAKE_BINARY_DIR}/config.yml") - execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/assets/" "${CMAKE_BINARY_DIR}/assets/") -endif() - if (MSVC) set(CPP "${CMAKE_C_COMPILER}" "/EP") else() @@ -602,6 +597,13 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang") endif() endif() +add_custom_command( + TARGET ${PROJECT_NAME} POST_BUILD + COMMENT "Copying asset yamls..." + COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_SOURCE_DIR}/config.yml" "$/config.yml" + COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/assets/" "$/assets/" +) + if(NOT CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch") include(ExternalProject) ExternalProject_Add(TorchExternal @@ -670,4 +672,4 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin") endif() set(CPACK_PROJECT_CONFIG_FILE ${CMAKE_SOURCE_DIR}/cmake/configure-packaging.cmake) -include(cmake/packaging.cmake) \ No newline at end of file +include(cmake/packaging.cmake) From 2c7dd5e1f5c750a7934cb059b1a086e7f0aef44b Mon Sep 17 00:00:00 2001 From: AltoXorg <56553686+Alto1772@users.noreply.github.com> Date: Sun, 10 Aug 2025 10:15:28 +0800 Subject: [PATCH 6/6] add NOMINMAX --- src/port/ui/UIWidgets.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/port/ui/UIWidgets.cpp b/src/port/ui/UIWidgets.cpp index 00f6499b5..1aa98ec15 100644 --- a/src/port/ui/UIWidgets.cpp +++ b/src/port/ui/UIWidgets.cpp @@ -1,3 +1,4 @@ +#define NOMINMAX // prevent defining min/max macros on windows #include "UIWidgets.h" #include "libultraship/src/Context.h"