diff --git a/UnleashedRecomp/CMakeLists.txt b/UnleashedRecomp/CMakeLists.txt index d28a29fb..4b8d0302 100644 --- a/UnleashedRecomp/CMakeLists.txt +++ b/UnleashedRecomp/CMakeLists.txt @@ -5,6 +5,10 @@ if (WIN32) option(SWA_D3D12 "Add D3D12 support for rendering" ON) endif() +if (CMAKE_SYSTEM_NAME MATCHES "Linux") + option(SWA_FLATPAK "Configure the build for Flatpak compatibility." OFF) +endif() + option(SWA_XAUDIO2 "Use XAudio2 for audio playback" OFF) function(BIN2C) @@ -257,7 +261,11 @@ else() add_executable(UnleashedRecomp ${SWA_CXX_SOURCES}) endif() -set_target_properties(UnleashedRecomp PROPERTIES OUTPUT_NAME ${TARGET_NAME}) +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) 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..9574d47c 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; @@ -135,6 +135,7 @@ static std::string g_currentMessagePrompt = ""; static bool g_currentMessagePromptConfirmation = false; static std::list g_currentPickerResults; static std::atomic g_currentPickerResultsReady = false; +static std::string g_currentPickerErrorMessage; static std::unique_ptr g_currentPickerThread; static bool g_currentPickerVisible = false; static bool g_currentPickerFolderMode = false; @@ -872,15 +873,15 @@ static bool ConvertPathSet(const nfdpathset_t *pathSet, std::list 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..c6bf305b 100644 --- a/UnleashedRecomp/user/paths.h +++ b/UnleashedRecomp/user/paths.h @@ -2,15 +2,19 @@ #define USER_DIRECTORY "SWA" +#ifndef GAME_INSTALL_DIRECTORY +#define GAME_INSTALL_DIRECTORY "." +#endif + inline std::filesystem::path GetGamePath() { - return std::filesystem::current_path(); + return GAME_INSTALL_DIRECTORY; } inline std::filesystem::path GetUserPath() { - if (std::filesystem::exists("portable.txt")) - return std::filesystem::current_path(); + if (std::filesystem::exists(GAME_INSTALL_DIRECTORY "portable.txt")) + return GAME_INSTALL_DIRECTORY; std::filesystem::path userPath; diff --git a/flatpak/README.md b/flatpak/README.md new file mode 100644 index 00000000..e191c794 --- /dev/null +++ b/flatpak/README.md @@ -0,0 +1,10 @@ +Build +```sh +flatpak-builder --force-clean --user --install-deps-from=flathub --repo=repo --install builddir io.github.hedge_dev.unleashedrecomp.json +``` + +Bundle +```sh +flatpak build-bundle repo io.github.hedge_dev.unleashedrecomp.flatpak io.github.hedge_dev.unleashedrecomp --runtime-repo=https://flathub.org/repo/flathub.flatpakrepo +``` + diff --git a/flatpak/io.github.hedge_dev.unleashedrecomp.desktop b/flatpak/io.github.hedge_dev.unleashedrecomp.desktop new file mode 100644 index 00000000..8b4694ae --- /dev/null +++ b/flatpak/io.github.hedge_dev.unleashedrecomp.desktop @@ -0,0 +1,7 @@ +[Desktop Entry] +Name=Unleashed Recompiled +Exec=/app/bin/SWA +Type=Application +Icon=io.github.hedge_dev.unleashedrecomp +Categories=Game; +Comment=Static recompilation of Sonic Unleashed. \ No newline at end of file diff --git a/flatpak/io.github.hedge_dev.unleashedrecomp.json b/flatpak/io.github.hedge_dev.unleashedrecomp.json new file mode 100644 index 00000000..076f695a --- /dev/null +++ b/flatpak/io.github.hedge_dev.unleashedrecomp.json @@ -0,0 +1,58 @@ +{ + "id": "io.github.hedge_dev.unleashedrecomp", + "runtime": "org.freedesktop.Platform", + "runtime-version": "23.08", + "sdk": "org.freedesktop.Sdk", + "sdk-extensions" : [ "org.freedesktop.Sdk.Extension.llvm18" ], + "finish-args": [ + "--share=network", + "--socket=wayland", + "--socket=fallback-x11", + "--socket=pulseaudio", + "--device=all", + "--filesystem=host", + "--filesystem=/media", + "--filesystem=/run/media", + "--filesystem=/mnt" + ], + "modules": [ + { + "name": "UnleashedRecomp", + "buildsystem": "simple", + "build-commands": [ + "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", + "install -Dm644 UnleashedRecompResources/images/game_icon.png /app/share/icons/hicolor/128x128/apps/${FLATPAK_ID}.png", + "install -Dm644 flatpak/io.github.hedge_dev.unleashedrecomp.metainfo.xml /app/share/metainfo/${FLATPAK_ID}.metainfo.xml", + "install -Dm644 flatpak/io.github.hedge_dev.unleashedrecomp.desktop /app/share/applications/${FLATPAK_ID}.desktop" + ], + "sources": [ + { + "type": "git", + "branch": "linux-flatpak", + "disable-shallow-clone": true, + "url": "https://github.com/hedge-dev/UnleashedRecomp.git" + }, + { + "type": "file", + "path": "default.xex", + "dest": "UnleashedRecompLib/private" + }, + { + "type": "file", + "path": "shader.ar", + "dest": "UnleashedRecompLib/private" + } + ], + "build-options": { + "append-path": "/usr/lib/sdk/llvm18/bin", + "prepend-ld-library-path": "/usr/lib/sdk/llvm18/lib", + "build-args": [ + "--share=network" + ] + } + } + ] +} diff --git a/flatpak/io.github.hedge_dev.unleashedrecomp.metainfo.xml b/flatpak/io.github.hedge_dev.unleashedrecomp.metainfo.xml new file mode 100644 index 00000000..f268be3e --- /dev/null +++ b/flatpak/io.github.hedge_dev.unleashedrecomp.metainfo.xml @@ -0,0 +1,26 @@ + + + io.github.hedge_dev.unleashedrecomp + + Unleashed Recompiled + Static recompilation of Sonic Unleashed. + + CC0-1.0 + GPL-3.0+ + + + pointing + keyboard + touch + + + +

+ A native PC port of Sonic Unleashed for Xbox 360 achieved through static recompilation. + + https://github.com/hedge-dev/UnleashedRecomp +

+
+ + io.github.hedge_dev.unleashedrecomp.desktop +
\ No newline at end of file