From fa8f5942070379688cdb221682be2b7a9e44e559 Mon Sep 17 00:00:00 2001 From: otavepto Date: Mon, 18 Dec 2023 05:08:23 +0200 Subject: [PATCH] + more accurate implementation for BIsAppInstalled, it now rejects uint32_max + allow behavior customizization via installed_app_ids.txt config file + limit/lock list of installed apps on an empty file (similar to dlc.txt) --- dll/settings.cpp | 11 +++++++ dll/settings.h | 5 +++ dll/settings_parser.cpp | 31 +++++++++++++++++++ dll/steam_apps.cpp | 10 +++++- .../installed_app_ids.EXAMPLE.txt | 8 +++++ 5 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 files_example/steam_settings.EXAMPLE/installed_app_ids.EXAMPLE.txt diff --git a/dll/settings.cpp b/dll/settings.cpp index 6e8b1db9..95793aa2 100644 --- a/dll/settings.cpp +++ b/dll/settings.cpp @@ -280,3 +280,14 @@ int Settings::add_image(std::string data, uint32 width, uint32 height) images[last] = dt; return last; } + +bool Settings::appIsInstalled(AppId_t appID) +{ + if (this->assume_any_app_installed) return true; + + auto f = std::find_if(installed_app_ids.begin(), installed_app_ids.end(), [&appID](AppId_t const& item) { return item == appID; }); + if (installed_app_ids.end() == f) + return false; + + return true; +} diff --git a/dll/settings.h b/dll/settings.h index 43b8c6bc..e23e5b57 100644 --- a/dll/settings.h +++ b/dll/settings.h @@ -206,6 +206,11 @@ public: int add_image(std::string data, uint32 width, uint32 height); bool disable_account_avatar = false; + //installed app ids, Steam_Apps::BIsAppInstalled() + std::set installed_app_ids; + bool assume_any_app_installed = true; + bool appIsInstalled(AppId_t appID); + //controller struct Controller_Settings controller_settings; std::string glyphs_directory; diff --git a/dll/settings_parser.cpp b/dll/settings_parser.cpp index 877e7f4b..fcdf55bb 100644 --- a/dll/settings_parser.cpp +++ b/dll/settings_parser.cpp @@ -805,6 +805,37 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s } } + { + std::string installed_apps_list_path = Local_Storage::get_game_settings_path() + "installed_app_ids.txt"; + std::ifstream input( utf8_decode(installed_apps_list_path) ); + if (input.is_open()) { + settings_client->assume_any_app_installed = false; + settings_server->assume_any_app_installed = false; + PRINT_DEBUG("Limiting/Locking installed apps\n"); + consume_bom(input); + for( std::string line; getline( input, line ); ) { + if (!line.empty() && line[line.length()-1] == '\n') { + line.pop_back(); + } + + if (!line.empty() && line[line.length()-1] == '\r') { + line.pop_back(); + } + + try { + AppId_t app_id = std::stoul(line); + settings_client->installed_app_ids.insert(app_id); + settings_server->installed_app_ids.insert(app_id); + PRINT_DEBUG("Added installed app with ID %u\n", app_id); + } catch (...) {} + } + } else { + settings_client->assume_any_app_installed = true; + settings_server->assume_any_app_installed = true; + PRINT_DEBUG("Assuming any app is installed\n"); + } + } + load_subscribed_groups_clans(local_storage->get_global_settings_path() + "subscribed_groups_clans.txt", settings_client, settings_server); load_subscribed_groups_clans(Local_Storage::get_game_settings_path() + "subscribed_groups_clans.txt", settings_client, settings_server); diff --git a/dll/steam_apps.cpp b/dll/steam_apps.cpp index edb2616a..4f8d4ba1 100644 --- a/dll/steam_apps.cpp +++ b/dll/steam_apps.cpp @@ -240,10 +240,18 @@ uint32 Steam_Apps::GetAppInstallDir( AppId_t appID, char *pchFolder, uint32 cchF } // returns true if that app is installed (not necessarily owned) +// "This only works for base applications, not Downloadable Content (DLC). Use BIsDlcInstalled for DLC instead" +// https://partner.steamgames.com/doc/api/ISteamApps bool Steam_Apps::BIsAppInstalled( AppId_t appID ) { PRINT_DEBUG("BIsAppInstalled %u\n", appID); - return true; + // is this true? it seems to indicate a non-steam game + if (appID == 0) return true; + // game LEGO® 2K Drive (app id 1451810) checks for a proper steam behavior by sending uint32_max and expects false in return + if (appID == UINT32_MAX) return false; + if (appID == settings->get_local_game_id().AppID()) return true; + + return settings->appIsInstalled(appID); } // returns the SteamID of the original owner. If different from current user, it's borrowed diff --git a/files_example/steam_settings.EXAMPLE/installed_app_ids.EXAMPLE.txt b/files_example/steam_settings.EXAMPLE/installed_app_ids.EXAMPLE.txt new file mode 100644 index 00000000..5e4ab12c --- /dev/null +++ b/files_example/steam_settings.EXAMPLE/installed_app_ids.EXAMPLE.txt @@ -0,0 +1,8 @@ +1. Rename this to: installed_app_ids.txt +2. Add all apps IDs (each on a separate line) that should be reported as insatlled, they could be NOT owned, that is allowed +3. Or, remove the file installed_app_ids.txt if it exists to: + * Allow app ID 0, this seems to be a special denotation to "non-steam apps" + * Allow app ID of the current game (you must create the file steam_appid.txt) + * Allow anything else + +In all cases app ID 4294967295 is disallowed