diff --git a/src/openrct2/config/Config.cpp b/src/openrct2/config/Config.cpp index 5dac3ef768..be37a4209b 100644 --- a/src/openrct2/config/Config.cpp +++ b/src/openrct2/config/Config.cpp @@ -614,6 +614,17 @@ namespace Config return location; } } + + utf8 steamPath[2048] = { 0 }; + if (platform_get_steam_path(steamPath, sizeof(steamPath))) + { + std::string location = Path::Combine(steamPath, "Rollercoaster Tycoon 2"); + if (platform_original_game_data_exists(location.c_str())) + { + return location; + } + } + if (platform_original_game_data_exists(gExePath)) { return gExePath; diff --git a/src/openrct2/platform/linux.c b/src/openrct2/platform/linux.c index 2870d9c704..fc41f5a6fa 100644 --- a/src/openrct2/platform/linux.c +++ b/src/openrct2/platform/linux.c @@ -34,6 +34,7 @@ #endif // NO_TTF #include #include +#include #include "../config/Config.h" #include "../localisation/language.h" @@ -253,6 +254,52 @@ void platform_get_changelog_path(utf8 *outPath, size_t outSize) safe_strcat_path(outPath, "changelog.txt", outSize); } +bool platform_get_steam_path(utf8 * outPath, size_t outSize) +{ + const char * steamRoot = getenv("STEAMROOT"); + if (steamRoot != NULL) + { + safe_strcpy(outPath, steamRoot, outSize); + safe_strcat_path(outPath, "steamapps/common", outSize); + return true; + } + + char steamPath[1024] = { 0 }; + const char * localSharePath = getenv("XDG_DATA_HOME"); + if (localSharePath != NULL) + { + safe_strcpy(steamPath, localSharePath, sizeof(steamPath)); + safe_strcat_path(steamPath, "Steam/steamapps/common", sizeof(steamPath)); + if (platform_directory_exists(steamPath)) + { + safe_strcpy(outPath, steamPath, outSize); + return true; + } + } + + const char * homeDir = getpwuid(getuid())->pw_dir; + if (homeDir != NULL) + { + safe_strcpy(steamPath, homeDir, sizeof(steamPath)); + safe_strcat_path(steamPath, ".local/share/Steam/steamapps/common", sizeof(steamPath)); + if (platform_directory_exists(steamPath)) + { + safe_strcpy(outPath, steamPath, outSize); + return true; + } + + memset(steamPath, 0, sizeof(steamPath)); + safe_strcpy(steamPath, homeDir, sizeof(steamPath)); + safe_strcat_path(steamPath, ".steam/steam/steamapps/common", sizeof(steamPath)); + if (platform_directory_exists(steamPath)) + { + safe_strcpy(outPath, steamPath, outSize); + return true; + } + } + return false; +} + #ifndef NO_TTF bool platform_get_font_path(TTFFontDescriptor *font, utf8 *buffer, size_t size) { diff --git a/src/openrct2/platform/macos.m b/src/openrct2/platform/macos.m index 593df07a87..b439b81463 100644 --- a/src/openrct2/platform/macos.m +++ b/src/openrct2/platform/macos.m @@ -19,6 +19,7 @@ @import AppKit; @import Foundation; #include +#include #include "platform.h" #include "../util/util.h" #include "../localisation/language.h" @@ -215,4 +216,21 @@ void platform_get_changelog_path(utf8 *outPath, size_t outSize) safe_strcat_path(outPath, "changelog.txt", outSize); } +bool platform_get_steam_path(utf8 * outPath, size_t outSize) +{ + char steamPath[1024] = { 0 }; + const char * homeDir = getpwuid(getuid())->pw_dir; + if (homeDir != NULL) + { + safe_strcpy(steamPath, homeDir, sizeof(steamPath)); + safe_strcat_path(steamPath, "Library/Application Support/Steam/steamapps/common", sizeof(steamPath)); + if (platform_directory_exists(steamPath)) + { + safe_strcpy(outPath, steamPath, outSize); + return true; + } + } + return false; +} + #endif diff --git a/src/openrct2/platform/platform.h b/src/openrct2/platform/platform.h index c669d4b079..6413612ea5 100644 --- a/src/openrct2/platform/platform.h +++ b/src/openrct2/platform/platform.h @@ -135,6 +135,7 @@ uint8 platform_get_locale_temperature_format(); uint8 platform_get_locale_date_format(); bool platform_process_is_elevated(); void platform_get_changelog_path(utf8 *outPath, size_t outSize); +bool platform_get_steam_path(utf8 * outPath, size_t outSize); #ifndef NO_TTF bool platform_get_font_path(TTFFontDescriptor *font, utf8 *buffer, size_t size); diff --git a/src/openrct2/platform/posix.c b/src/openrct2/platform/posix.c index 54621d5d3f..7b1831068f 100644 --- a/src/openrct2/platform/posix.c +++ b/src/openrct2/platform/posix.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include diff --git a/src/openrct2/platform/windows.c b/src/openrct2/platform/windows.c index 293e146a0c..d2cda97134 100644 --- a/src/openrct2/platform/windows.c +++ b/src/openrct2/platform/windows.c @@ -506,6 +506,37 @@ void platform_get_user_directory(utf8 *outPath, const utf8 *subDirectory, size_t } } +bool platform_get_steam_path(utf8 * outPath, size_t outSize) +{ + wchar_t * wSteamPath; + HKEY hKey; + DWORD type, size; + LRESULT result; + + if (RegOpenKeyW(HKEY_CURRENT_USER, L"Software\\Valve\\Steam", &hKey) != ERROR_SUCCESS) + return false; + + // Get the size of the path first + if (RegQueryValueExW(hKey, L"SteamPath", 0, &type, NULL, &size) != ERROR_SUCCESS) + { + RegCloseKey(hKey); + return false; + } + + wSteamPath = (wchar_t*)malloc(size); + result = RegQueryValueExW(hKey, L"SteamPath", 0, &type, (LPBYTE)wSteamPath, &size); + if (result == ERROR_SUCCESS) + { + utf8 * utf8SteamPath = widechar_to_utf8(wSteamPath); + safe_strcpy(outPath, utf8SteamPath, outSize); + safe_strcat_path(outPath, "steamapps\\common", outSize); + free(utf8SteamPath); + } + free(wSteamPath); + RegCloseKey(hKey); + return result == ERROR_SUCCESS; +} + /** * * rct2: 0x00407978