From 3c318a82ccf5c94bb3d60bf4a4a5ab8b4c2704b1 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sat, 13 Dec 2025 14:55:53 +0100 Subject: [PATCH] Create function to trigger Steam download --- data/language/en-GB.txt | 3 +++ src/openrct2/config/Config.cpp | 17 ++++++++++++++ src/openrct2/localisation/StringIds.h | 3 +++ src/openrct2/platform/Platform.Common.cpp | 28 +++++++++++++++++++++++ src/openrct2/platform/Platform.h | 1 + 5 files changed, 52 insertions(+) diff --git a/data/language/en-GB.txt b/data/language/en-GB.txt index ce4f078c69..b10b65b668 100644 --- a/data/language/en-GB.txt +++ b/data/language/en-GB.txt @@ -3843,3 +3843,6 @@ STR_7010 :Could not start replay, file ‘{STRING}’ doesn’t exist or isn STR_7011 :Could not start replay STR_7012 :Polish Złoty (PLN) STR_7013 :Drag areas of path +STR_7014 :I own the game on Steam, but I haven’t installed it yet. +STR_7015 :Please close Steam if it’s running, then click ‘OK’. +STR_7016 :OpenRCT2 has tried to trigger a download in Steam. Please open Steam and let it download the game. When Steam is finished, click ‘OK’. diff --git a/src/openrct2/config/Config.cpp b/src/openrct2/config/Config.cpp index 5bbb005f26..60d46e9523 100644 --- a/src/openrct2/config/Config.cpp +++ b/src/openrct2/config/Config.cpp @@ -909,6 +909,7 @@ namespace OpenRCT2::Config { uiContext.ShowMessageBox(LanguageGetString(STR_NEEDS_RCT2_FILES)); std::string gog = LanguageGetString(STR_OWN_ON_GOG); + std::string steam = LanguageGetString(STR_OWN_ON_STEAM); std::string hdd = LanguageGetString(STR_INSTALLED_ON_HDD); std::vector options; @@ -918,6 +919,7 @@ namespace OpenRCT2::Config { options.push_back(hdd); options.push_back(gog); + options.push_back(steam); int optionIndex = uiContext.ShowMenuDialog( options, LanguageGetString(STR_OPENRCT2_SETUP), LanguageGetString(STR_WHICH_APPLIES_BEST)); if (optionIndex < 0 || static_cast(optionIndex) >= options.size()) @@ -975,6 +977,21 @@ namespace OpenRCT2::Config possibleInstallPaths.emplace_back(dest); possibleInstallPaths.emplace_back(Path::Combine(dest, u8"app")); } + else if (chosenOption == steam) + { + uiContext.ShowMessageBox(LanguageGetString(STR_PLEASE_CLOSE_STEAM)); + + Platform::triggerSteamDownload(); + + uiContext.ShowMessageBox(LanguageGetString(STR_WAIT_FOR_STEAM_DOWNLOAD)); + + auto steamPath = FindRCT2SteamPath(); + if (!steamPath.empty()) + { + Get().general.rct2Path = steamPath; + return true; + } + } if (possibleInstallPaths.empty()) { return false; diff --git a/src/openrct2/localisation/StringIds.h b/src/openrct2/localisation/StringIds.h index 397ec2d7da..89bf3294f8 100644 --- a/src/openrct2/localisation/StringIds.h +++ b/src/openrct2/localisation/StringIds.h @@ -1602,6 +1602,9 @@ enum : StringId STR_THIS_WILL_TAKE_A_FEW_MINUTES = 6407, STR_INSTALL_INNOEXTRACT = 6408, STR_NOT_THE_GOG_INSTALLER = 6409, + STR_OWN_ON_STEAM = 7014, + STR_PLEASE_CLOSE_STEAM = 7015, + STR_WAIT_FOR_STEAM_DOWNLOAD = 7016, STR_TILE_INSPECTOR_TOGGLE_INVISIBILITY_TIP = 6436, diff --git a/src/openrct2/platform/Platform.Common.cpp b/src/openrct2/platform/Platform.Common.cpp index f50c946328..fbe440fd2b 100644 --- a/src/openrct2/platform/Platform.Common.cpp +++ b/src/openrct2/platform/Platform.Common.cpp @@ -224,4 +224,32 @@ namespace OpenRCT2::Platform steamroot, downloadDepotFolder, "app_" + std::to_string(data.appId), "depot_" + std::to_string(data.depotId)); } + bool triggerSteamDownload() + { + const auto steamPaths = GetSteamPaths(); + if (!steamPaths.isSteamPresent() || steamPaths.manifests.empty()) + return false; + + const auto manifestsDir = Path::Combine(steamPaths.roots[0], steamPaths.manifests); + const std::array gamesToTrigger = { kSteamRCT2Data, kSteamRCTCData, kSteamRCT1Data }; + for (const auto& game : gamesToTrigger) + { + auto fullFilename = Path::Combine(manifestsDir, "appmanifest_" + std::to_string(game.appId) + ".acf"); + // If the file exists, we assume a download has been triggered already. + if (File::Exists(fullFilename)) + continue; + + // clang-format off + auto buffer = u8string("\"AppState\"\r\n") + u8string("{\r\n") + + u8string(" \"AppID\" \"" + std::to_string(game.appId) + "\"\r\n") + + u8string(" \"Universe\" \"1\"\r\n") + + u8string(" \"installdir\" \"" + game.nativeFolder + "\"\r\n") + + u8string(" \"StateFlags\" \"1026\"\r\n") + u8string("}\r\n"); + // clang-format on + File::WriteAllBytes(fullFilename, buffer.data(), buffer.size()); + } + + return true; + } + } // namespace OpenRCT2::Platform diff --git a/src/openrct2/platform/Platform.h b/src/openrct2/platform/Platform.h index 76037a58f2..6d477c7cf9 100644 --- a/src/openrct2/platform/Platform.h +++ b/src/openrct2/platform/Platform.h @@ -146,6 +146,7 @@ namespace OpenRCT2::Platform std::string GetUsername(); SteamPaths GetSteamPaths(); + bool triggerSteamDownload(); #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD__) || defined(__NetBSD__) std::string GetEnvironmentPath(const char* name); std::string GetHomePath();