Skip to content
11 changes: 0 additions & 11 deletions UnleashedRecomp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down Expand Up @@ -300,13 +296,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)
Expand Down
2 changes: 1 addition & 1 deletion UnleashedRecomp/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions UnleashedRecomp/kernel/xam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 9 additions & 5 deletions UnleashedRecomp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,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);
Expand Down Expand Up @@ -94,7 +98,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())
{
Expand Down Expand Up @@ -244,7 +248,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)
{
Expand All @@ -254,7 +258,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);
}
Expand Down
2 changes: 1 addition & 1 deletion UnleashedRecomp/mod/mod_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void ModLoader::Init()
{
configIni = {};

if (!configIni.read(GAME_INSTALL_DIRECTORY "/cpkredir.ini"))
if (!configIni.read(g_gameInstallPath / "cpkredir.ini"))
return;
}

Expand Down
8 changes: 8 additions & 0 deletions UnleashedRecomp/user/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
#include <ui/game_window.h>
#include <user/paths.h>

#if defined(__linux__)
const bool g_isRunningUnderFlatpak = []()
{
std::error_code ec;
return std::filesystem::exists("/.flatpak-info", ec);
}();
#endif

std::vector<IConfigDef*> g_configDefinitions;

#define CONFIG_DEFINE_ENUM_TEMPLATE(type) \
Expand Down
4 changes: 4 additions & 0 deletions UnleashedRecomp/user/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

#include <locale/locale.h>

#if defined(__linux__)
extern const bool g_isRunningUnderFlatpak;
#endif

class IConfigDef
{
public:
Expand Down
1 change: 1 addition & 0 deletions UnleashedRecomp/user/paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
13 changes: 8 additions & 5 deletions UnleashedRecomp/user/paths.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
#pragma once

#include <mod/mod_loader.h>
#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)
{
Expand Down
2 changes: 1 addition & 1 deletion flatpak/io.github.hedge_dev.unleashedrecomp.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading