From 81aec7d5f4bd8fb8015af32c89c4f77dd20d9a3e Mon Sep 17 00:00:00 2001 From: Dario Date: Tue, 17 Dec 2024 22:16:14 -0300 Subject: [PATCH] Add game install directory override for flatpak. --- UnleashedRecomp/CMakeLists.txt | 99 ++++++++++--------- UnleashedRecomp/kernel/xam.cpp | 4 +- UnleashedRecomp/main.cpp | 10 +- UnleashedRecomp/ui/installer_wizard.cpp | 6 +- UnleashedRecomp/ui/installer_wizard.h | 2 +- UnleashedRecomp/user/config.h | 2 +- UnleashedRecomp/user/paths.h | 4 + .../io.github.hedge_dev.unleashedrecomp.json | 4 +- 8 files changed, 73 insertions(+), 58 deletions(-) diff --git a/UnleashedRecomp/CMakeLists.txt b/UnleashedRecomp/CMakeLists.txt index d28a29fb..9c29fb6f 100644 --- a/UnleashedRecomp/CMakeLists.txt +++ b/UnleashedRecomp/CMakeLists.txt @@ -1,6 +1,10 @@ project("UnleashedRecomp") set(TARGET_NAME "SWA") +if (CMAKE_SYSTEM_NAME MATCHES "Linux") + option(SWA_FLATPAK "Configure the build for Flatpak compatibility." OFF) +endif() + if (WIN32) option(SWA_D3D12 "Add D3D12 support for rendering" ON) endif() @@ -49,14 +53,14 @@ add_compile_options( -Wno-int-to-void-pointer-cast -Wno-invalid-offsetof -Wno-null-arithmetic - -Wno-null-conversion + -Wno-null-conversion -Wno-tautological-undefined-compare -) - -if (WIN32) - add_compile_options(/fp:strict) -else() - add_compile_options(-ffp-model=strict) +) + +if (WIN32) + add_compile_options(/fp:strict) +else() + add_compile_options(-ffp-model=strict) endif() add_compile_definitions( @@ -183,46 +187,46 @@ set(SWA_INSTALL_CXX_SOURCES "install/hashes/mazuri.cpp" "install/hashes/spagonia.cpp" "install/hashes/update.cpp" -) - +) + set(SWA_USER_CXX_SOURCES "user/achievement_data.cpp" "user/config.cpp" -) - -set(SWA_THIRDPARTY_SOURCES - "${SWA_THIRDPARTY_ROOT}/imgui/backends/imgui_impl_sdl2.cpp" - "${SWA_THIRDPARTY_ROOT}/imgui/imgui.cpp" - "${SWA_THIRDPARTY_ROOT}/imgui/imgui_demo.cpp" - "${SWA_THIRDPARTY_ROOT}/imgui/imgui_draw.cpp" - "${SWA_THIRDPARTY_ROOT}/imgui/imgui_tables.cpp" - "${SWA_THIRDPARTY_ROOT}/imgui/imgui_widgets.cpp" - "${SWA_THIRDPARTY_ROOT}/libmspack/libmspack/mspack/lzxd.c" - "${SWA_THIRDPARTY_ROOT}/tiny-AES-c/aes.c" - "${SWA_TOOLS_ROOT}/ShaderRecomp/thirdparty/smol-v/source/smolv.cpp" -) - -set(SWA_THIRDPARTY_INCLUDES - "${SWA_THIRDPARTY_ROOT}/concurrentqueue" +) + +set(SWA_THIRDPARTY_SOURCES + "${SWA_THIRDPARTY_ROOT}/imgui/backends/imgui_impl_sdl2.cpp" + "${SWA_THIRDPARTY_ROOT}/imgui/imgui.cpp" + "${SWA_THIRDPARTY_ROOT}/imgui/imgui_demo.cpp" + "${SWA_THIRDPARTY_ROOT}/imgui/imgui_draw.cpp" + "${SWA_THIRDPARTY_ROOT}/imgui/imgui_tables.cpp" + "${SWA_THIRDPARTY_ROOT}/imgui/imgui_widgets.cpp" + "${SWA_THIRDPARTY_ROOT}/libmspack/libmspack/mspack/lzxd.c" + "${SWA_THIRDPARTY_ROOT}/tiny-AES-c/aes.c" + "${SWA_TOOLS_ROOT}/ShaderRecomp/thirdparty/smol-v/source/smolv.cpp" +) + +set(SWA_THIRDPARTY_INCLUDES + "${SWA_THIRDPARTY_ROOT}/concurrentqueue" "${SWA_THIRDPARTY_ROOT}/ddspp" - "${SWA_THIRDPARTY_ROOT}/imgui" + "${SWA_THIRDPARTY_ROOT}/imgui" "${SWA_THIRDPARTY_ROOT}/libmspack/libmspack/mspack" - "${SWA_THIRDPARTY_ROOT}/magic_enum/include" + "${SWA_THIRDPARTY_ROOT}/magic_enum/include" "${SWA_THIRDPARTY_ROOT}/miniaudio" - "${SWA_THIRDPARTY_ROOT}/stb" - "${SWA_THIRDPARTY_ROOT}/tiny-AES-c" + "${SWA_THIRDPARTY_ROOT}/stb" + "${SWA_THIRDPARTY_ROOT}/tiny-AES-c" "${SWA_THIRDPARTY_ROOT}/TinySHA1" "${SWA_THIRDPARTY_ROOT}/unordered_dense/include" - "${SWA_THIRDPARTY_ROOT}/volk" - "${SWA_THIRDPARTY_ROOT}/Vulkan-Headers/include" - "${SWA_THIRDPARTY_ROOT}/VulkanMemoryAllocator/include" - "${SWA_TOOLS_ROOT}/bc_diff" + "${SWA_THIRDPARTY_ROOT}/volk" + "${SWA_THIRDPARTY_ROOT}/Vulkan-Headers/include" + "${SWA_THIRDPARTY_ROOT}/VulkanMemoryAllocator/include" + "${SWA_TOOLS_ROOT}/bc_diff" "${SWA_TOOLS_ROOT}/ShaderRecomp/thirdparty/smol-v/source" -) - -if (SWA_D3D12) - list(APPEND SWA_THIRDPARTY_INCLUDES "${SWA_THIRDPARTY_ROOT}/D3D12MemoryAllocator/include") - list(APPEND SWA_THIRDPARTY_SOURCES "${SWA_THIRDPARTY_ROOT}/D3D12MemoryAllocator/src/D3D12MemAlloc.cpp") +) + +if (SWA_D3D12) + list(APPEND SWA_THIRDPARTY_INCLUDES "${SWA_THIRDPARTY_ROOT}/D3D12MemoryAllocator/include") + list(APPEND SWA_THIRDPARTY_SOURCES "${SWA_THIRDPARTY_ROOT}/D3D12MemoryAllocator/src/D3D12MemAlloc.cpp") endif() set_source_files_properties(${SWA_THIRDPARTY_SOURCES} PROPERTIES SKIP_PRECOMPILE_HEADERS ON) @@ -244,7 +248,7 @@ set(SWA_CXX_SOURCES ${SWA_PATCHES_CXX_SOURCES} ${SWA_UI_CXX_SOURCES} ${SWA_INSTALL_CXX_SOURCES} - ${SWA_USER_CXX_SOURCES} + ${SWA_USER_CXX_SOURCES} ${SWA_THIRDPARTY_SOURCES} ) @@ -259,13 +263,17 @@ endif() set_target_properties(UnleashedRecomp PROPERTIES OUTPUT_NAME ${TARGET_NAME}) +if (SWA_FLATPAK) + target_compile_definitions(UnleashedRecomp PRIVATE "GAME_INSTALL_DIRECTORY=\"/var/data\"") +endif() + if (SWA_D3D12) find_package(directx-headers CONFIG REQUIRED) find_package(directx12-agility CONFIG REQUIRED) target_compile_definitions(UnleashedRecomp PRIVATE SWA_D3D12) endif() -find_package(directx-dxc REQUIRED) +find_package(directx-dxc REQUIRED) if (SWA_D3D12) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/D3D12) @@ -281,7 +289,7 @@ if (SWA_D3D12) Microsoft::DirectX-Headers Microsoft::DirectX-Guids Microsoft::DirectX12-Agility - Microsoft::DirectXShaderCompiler + Microsoft::DirectXShaderCompiler Microsoft::DXIL dxgi ) @@ -299,7 +307,7 @@ if (WIN32) endif() target_link_libraries(UnleashedRecomp PRIVATE - fmt::fmt + fmt::fmt libzstd_static msdf-atlas-gen::msdf-atlas-gen nfd::nfd @@ -308,12 +316,13 @@ target_link_libraries(UnleashedRecomp PRIVATE SDL2::SDL2-static tomlplusplus::tomlplusplus UnleashedRecompLib - Vorbis::vorbisfile - xxHash::xxhash ) + Vorbis::vorbisfile + xxHash::xxhash +) target_include_directories(UnleashedRecomp PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - "${CMAKE_CURRENT_SOURCE_DIR}/api" + "${CMAKE_CURRENT_SOURCE_DIR}/api" ${SWA_THIRDPARTY_INCLUDES} ) diff --git a/UnleashedRecomp/kernel/xam.cpp b/UnleashedRecomp/kernel/xam.cpp index 23b53e50..21732034 100644 --- a/UnleashedRecomp/kernel/xam.cpp +++ b/UnleashedRecomp/kernel/xam.cpp @@ -313,11 +313,11 @@ SWA_API uint32_t XamContentCreateEx(uint32_t dwUserIndex, const char* szRootName } else if (pContentData->dwContentType == XCONTENTTYPE_DLC) { - root = "./dlc"; + root = GAME_INSTALL_DIRECTORY "/dlc"; } else { - root = "."; + root = GAME_INSTALL_DIRECTORY; } XamRegisterContent(*pContentData, root); diff --git a/UnleashedRecomp/main.cpp b/UnleashedRecomp/main.cpp index c269435d..47fae078 100644 --- a/UnleashedRecomp/main.cpp +++ b/UnleashedRecomp/main.cpp @@ -50,8 +50,8 @@ void KiSystemStartup() { const auto gameContent = XamMakeContent(XCONTENTTYPE_RESERVED, "Game"); const auto updateContent = XamMakeContent(XCONTENTTYPE_RESERVED, "Update"); - XamRegisterContent(gameContent, std::filesystem::exists("./game") ? "./game" : "."); - XamRegisterContent(updateContent, "./update"); + XamRegisterContent(gameContent, GAME_INSTALL_DIRECTORY "/game"); + XamRegisterContent(updateContent, GAME_INSTALL_DIRECTORY "/update"); const auto savePath = GetSavePath(); const auto saveName = "SYS-DATA"; @@ -70,7 +70,7 @@ void KiSystemStartup() XamContentCreateEx(0, "D", &gameContent, OPEN_EXISTING, nullptr, nullptr, 0, 0, nullptr); std::error_code ec; - for (auto& file : std::filesystem::directory_iterator("./dlc", ec)) + for (auto& file : std::filesystem::directory_iterator(GAME_INSTALL_DIRECTORY "/dlc", ec)) { if (file.is_directory()) { @@ -151,13 +151,13 @@ int main(int argc, char *argv[]) HostStartup(); - bool isGameInstalled = Installer::checkGameInstall("."); + bool isGameInstalled = Installer::checkGameInstall(GAME_INSTALL_DIRECTORY); bool runInstallerWizard = forceInstaller || forceDLCInstaller || !isGameInstalled; if (runInstallerWizard) { Video::CreateHostDevice(); - if (!InstallerWizard::Run(isGameInstalled && forceDLCInstaller)) + if (!InstallerWizard::Run(GAME_INSTALL_DIRECTORY, isGameInstalled && forceDLCInstaller)) { return 1; } diff --git a/UnleashedRecomp/ui/installer_wizard.cpp b/UnleashedRecomp/ui/installer_wizard.cpp index 67c96017..764d10b7 100644 --- a/UnleashedRecomp/ui/installer_wizard.cpp +++ b/UnleashedRecomp/ui/installer_wizard.cpp @@ -96,7 +96,7 @@ static double g_appearTime = 0.0; static double g_disappearTime = DBL_MAX; static bool g_isDisappearing = false; -static std::filesystem::path g_installPath = "."; +static std::filesystem::path g_installPath; static std::filesystem::path g_gameSourcePath; static std::filesystem::path g_updateSourcePath; static std::array g_dlcSourcePaths; @@ -1426,8 +1426,10 @@ void InstallerWizard::Shutdown() } } -bool InstallerWizard::Run(bool skipGame) +bool InstallerWizard::Run(std::filesystem::path installPath, bool skipGame) { + g_installPath = installPath; + EmbeddedPlayer::Init(); NFD_Init(); diff --git a/UnleashedRecomp/ui/installer_wizard.h b/UnleashedRecomp/ui/installer_wizard.h index 1b7545b8..488cc0e7 100644 --- a/UnleashedRecomp/ui/installer_wizard.h +++ b/UnleashedRecomp/ui/installer_wizard.h @@ -9,5 +9,5 @@ struct InstallerWizard static void Init(); static void Draw(); static void Shutdown(); - static bool Run(bool skipGame); + static bool Run(std::filesystem::path installPath, bool skipGame); }; diff --git a/UnleashedRecomp/user/config.h b/UnleashedRecomp/user/config.h index fdba970f..52f9e848 100644 --- a/UnleashedRecomp/user/config.h +++ b/UnleashedRecomp/user/config.h @@ -50,7 +50,7 @@ public: #define WINDOWPOS_CENTRED 0x2FFF0000 -static inline std::vector g_configDefinitions{}; +inline std::vector g_configDefinitions; CONFIG_DEFINE_ENUM_TEMPLATE(ELanguage) { diff --git a/UnleashedRecomp/user/paths.h b/UnleashedRecomp/user/paths.h index 7eb7dd42..f68c7eac 100644 --- a/UnleashedRecomp/user/paths.h +++ b/UnleashedRecomp/user/paths.h @@ -2,6 +2,10 @@ #define USER_DIRECTORY "SWA" +#ifndef GAME_INSTALL_DIRECTORY +#define GAME_INSTALL_DIRECTORY "." +#endif + inline std::filesystem::path GetGamePath() { return std::filesystem::current_path(); diff --git a/flatpak/io.github.hedge_dev.unleashedrecomp.json b/flatpak/io.github.hedge_dev.unleashedrecomp.json index fc59dc0a..b7aff701 100644 --- a/flatpak/io.github.hedge_dev.unleashedrecomp.json +++ b/flatpak/io.github.hedge_dev.unleashedrecomp.json @@ -19,7 +19,7 @@ "name": "UnleashedRecomp", "buildsystem": "simple", "build-commands": [ - "cmake --preset linux-release", + "cmake --preset linux-release -DSWA_FLATPAK=ON", "cmake --build out/build/linux-release", "mkdir -p /app/bin", "cp out/build/linux-release/UnleashedRecomp/SWA /app/bin/SWA" @@ -27,7 +27,7 @@ "sources": [ { "type": "git", - "branch": "linux", + "branch": "linux-flatpak", "disable-shallow-clone": true, "url": "https://github.com/hedge-dev/UnleashedRecomp.git" },