diff --git a/UnleashedRecomp/CMakeLists.txt b/UnleashedRecomp/CMakeLists.txt index 337b963..5af867b 100644 --- a/UnleashedRecomp/CMakeLists.txt +++ b/UnleashedRecomp/CMakeLists.txt @@ -4,10 +4,6 @@ if (WIN32) option(UNLEASHED_RECOMP_D3D12 "Add D3D12 support for rendering" ON) endif() -if (CMAKE_SYSTEM_NAME MATCHES "Linux") - option(UNLEASHED_RECOMP_FLATPAK "Configure the build for Flatpak compatibility." OFF) -endif() - function(BIN2C) cmake_parse_arguments(BIN2C_ARGS "" "TARGET_OBJ;SOURCE_FILE;DEST_FILE;ARRAY_NAME;COMPRESSION_TYPE" "" ${ARGN}) @@ -303,13 +299,6 @@ else() add_executable(UnleashedRecomp ${UNLEASHED_RECOMP_CXX_SOURCES}) endif() -if (UNLEASHED_RECOMP_FLATPAK) - target_compile_definitions(UnleashedRecomp PRIVATE - "UNLEASHED_RECOMP_FLATPAK" - "GAME_INSTALL_DIRECTORY=\"/var/data\"" - ) -endif() - if (UNLEASHED_RECOMP_D3D12) find_package(directx-headers CONFIG REQUIRED) find_package(directx12-agility CONFIG REQUIRED) diff --git a/UnleashedRecomp/app.cpp b/UnleashedRecomp/app.cpp index b298ebc..84d2376 100644 --- a/UnleashedRecomp/app.cpp +++ b/UnleashedRecomp/app.cpp @@ -33,7 +33,7 @@ PPC_FUNC_IMPL(__imp__sub_824EB490); PPC_FUNC(sub_824EB490) { App::s_isInit = true; - App::s_isMissingDLC = !Installer::checkAllDLC(GetGamePath()); + App::s_isMissingDLC = !Installer::checkAllDLC(g_gameInstallPath); App::s_language = Config::Language; SWA::SGlobals::Init(); diff --git a/UnleashedRecomp/kernel/xam.cpp b/UnleashedRecomp/kernel/xam.cpp index 3d7ca77..687df93 100644 --- a/UnleashedRecomp/kernel/xam.cpp +++ b/UnleashedRecomp/kernel/xam.cpp @@ -315,11 +315,11 @@ uint32_t XamContentCreateEx(uint32_t dwUserIndex, const char* szRootName, const } else if (pContentData->dwContentType == XCONTENTTYPE_DLC) { - root = GAME_INSTALL_DIRECTORY "/dlc"; + root = g_gameInstallPath / "dlc"; } else { - root = GAME_INSTALL_DIRECTORY; + root = g_gameInstallPath; } XamRegisterContent(*pContentData, root); diff --git a/UnleashedRecomp/main.cpp b/UnleashedRecomp/main.cpp index e8123b3..9c8778a 100644 --- a/UnleashedRecomp/main.cpp +++ b/UnleashedRecomp/main.cpp @@ -69,8 +69,12 @@ void KiSystemStartup() const auto gameContent = XamMakeContent(XCONTENTTYPE_RESERVED, "Game"); const auto updateContent = XamMakeContent(XCONTENTTYPE_RESERVED, "Update"); - XamRegisterContent(gameContent, GAME_INSTALL_DIRECTORY "/game"); - XamRegisterContent(updateContent, GAME_INSTALL_DIRECTORY "/update"); + + std::u8string gamePathU8 = (g_gameInstallPath / "game").u8string(); + std::u8string updatePathU8 = (g_gameInstallPath / "update").u8string(); + + XamRegisterContent(gameContent, (const char*)(gamePathU8.c_str())); + XamRegisterContent(updateContent, (const char*)(updatePathU8.c_str())); const auto saveFilePath = GetSaveFilePath(true); bool saveFileExists = std::filesystem::exists(saveFilePath); @@ -102,7 +106,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(GAME_INSTALL_DIRECTORY "/dlc", ec)) + for (auto& file : std::filesystem::directory_iterator(g_gameInstallPath / "dlc", ec)) { if (file.is_directory()) { @@ -321,7 +325,7 @@ int main(int argc, char *argv[]) HostStartup(); std::filesystem::path modulePath; - bool isGameInstalled = Installer::checkGameInstall(GAME_INSTALL_DIRECTORY, modulePath); + bool isGameInstalled = Installer::checkGameInstall(g_gameInstallPath, modulePath); bool runInstallerWizard = forceInstaller || forceDLCInstaller || !isGameInstalled; if (runInstallerWizard) { @@ -331,7 +335,7 @@ int main(int argc, char *argv[]) std::_Exit(1); } - if (!InstallerWizard::Run(GAME_INSTALL_DIRECTORY, isGameInstalled && forceDLCInstaller)) + if (!InstallerWizard::Run(g_gameInstallPath, isGameInstalled && forceDLCInstaller)) { std::_Exit(0); } diff --git a/UnleashedRecomp/mod/mod_loader.cpp b/UnleashedRecomp/mod/mod_loader.cpp index 6fc3aec..9847605 100644 --- a/UnleashedRecomp/mod/mod_loader.cpp +++ b/UnleashedRecomp/mod/mod_loader.cpp @@ -100,7 +100,7 @@ void ModLoader::Init() { configIni = {}; - if (!configIni.read(GAME_INSTALL_DIRECTORY "/cpkredir.ini")) + if (!configIni.read(g_gameInstallPath / "cpkredir.ini")) return; } diff --git a/UnleashedRecomp/user/config.cpp b/UnleashedRecomp/user/config.cpp index bd622b7..7db0510 100644 --- a/UnleashedRecomp/user/config.cpp +++ b/UnleashedRecomp/user/config.cpp @@ -3,6 +3,14 @@ #include #include +#if defined(__linux__) + const bool g_isRunningUnderFlatpak = []() + { + std::error_code ec; + return std::filesystem::exists("/.flatpak-info", ec); + }(); +#endif + std::vector g_configDefinitions; #define CONFIG_DEFINE_ENUM_TEMPLATE(type) \ diff --git a/UnleashedRecomp/user/config.h b/UnleashedRecomp/user/config.h index 9e87d12..9dde0af 100644 --- a/UnleashedRecomp/user/config.h +++ b/UnleashedRecomp/user/config.h @@ -2,6 +2,10 @@ #include +#if defined(__linux__) + extern const bool g_isRunningUnderFlatpak; +#endif + class IConfigDef { public: diff --git a/UnleashedRecomp/user/paths.cpp b/UnleashedRecomp/user/paths.cpp index 13a8588..ffb7e5c 100644 --- a/UnleashedRecomp/user/paths.cpp +++ b/UnleashedRecomp/user/paths.cpp @@ -3,6 +3,7 @@ std::filesystem::path g_executableRoot = os::process::GetExecutablePath().remove_filename(); std::filesystem::path g_userPath = BuildUserPath(); +extern const std::filesystem::path g_gameInstallPath = GetGamePath(); bool CheckPortable() { diff --git a/UnleashedRecomp/user/paths.h b/UnleashedRecomp/user/paths.h index c083520..403aca9 100644 --- a/UnleashedRecomp/user/paths.h +++ b/UnleashedRecomp/user/paths.h @@ -1,23 +1,26 @@ #pragma once #include +#include "config.h" #define USER_DIRECTORY "UnleashedRecomp" -#ifndef GAME_INSTALL_DIRECTORY -#define GAME_INSTALL_DIRECTORY "." -#endif - extern std::filesystem::path g_executableRoot; inline std::filesystem::path GetGamePath() { - return GAME_INSTALL_DIRECTORY; +#if defined(__linux__) + if (g_isRunningUnderFlatpak) + return "/var/data"; + else +#endif + return "."; } bool CheckPortable(); std::filesystem::path BuildUserPath(); const std::filesystem::path& GetUserPath(); +extern const std::filesystem::path g_gameInstallPath; inline std::filesystem::path GetSavePath(bool checkForMods) { diff --git a/flatpak/io.github.hedge_dev.unleashedrecomp.json b/flatpak/io.github.hedge_dev.unleashedrecomp.json index f6ae932..34926b5 100644 --- a/flatpak/io.github.hedge_dev.unleashedrecomp.json +++ b/flatpak/io.github.hedge_dev.unleashedrecomp.json @@ -20,7 +20,7 @@ "name": "UnleashedRecomp", "buildsystem": "simple", "build-commands": [ - "cmake --preset linux-release -DUNLEASHED_RECOMP_FLATPAK=ON -DSDL2MIXER_VORBIS=VORBISFILE -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache", + "cmake --preset linux-release -DSDL2MIXER_VORBIS=VORBISFILE -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache", "cmake --build out/build/linux-release --target UnleashedRecomp", "mkdir -p /app/bin", "cp out/build/linux-release/UnleashedRecomp/UnleashedRecomp /app/bin/UnleashedRecomp",