From 6ed6a0a04b8def21049e85b8fa8303601fa9dfe8 Mon Sep 17 00:00:00 2001 From: otavepto Date: Mon, 18 Dec 2023 05:21:31 +0200 Subject: [PATCH] + changed the behavior of GetCurrentBetaName() to comply with the docs, might break stuff + allow customizing the behavior via is_beta_branch.txt + force_branch_name.txt config files --- dll/settings.h | 4 +++ dll/settings_parser.cpp | 28 +++++++++++++++++++ dll/steam_apps.cpp | 10 +++---- .../force_branch_name.EXAMPLE.txt | 2 ++ .../is_beta_branch.EXAMPLE.txt | 1 + 5 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 files_example/steam_settings.EXAMPLE/force_branch_name.EXAMPLE.txt create mode 100644 files_example/steam_settings.EXAMPLE/is_beta_branch.EXAMPLE.txt diff --git a/dll/settings.h b/dll/settings.h index e23e5b57..96e4e451 100644 --- a/dll/settings.h +++ b/dll/settings.h @@ -211,6 +211,10 @@ public: bool assume_any_app_installed = true; bool appIsInstalled(AppId_t appID); + //is playing on beta branch + current/forced branch name + bool is_beta_branch = false; + std::string current_branch_name = "public"; + //controller struct Controller_Settings controller_settings; std::string glyphs_directory; diff --git a/dll/settings_parser.cpp b/dll/settings_parser.cpp index fcdf55bb..1257f072 100644 --- a/dll/settings_parser.cpp +++ b/dll/settings_parser.cpp @@ -461,6 +461,7 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s bool disable_source_query = false; bool disable_account_avatar = false; bool achievement_bypass = false; + bool is_beta_branch = false; int build_id = 10; bool warn_forced = false; @@ -495,6 +496,8 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s disable_account_avatar = true; } else if (p == "achievements_bypass.txt") { achievement_bypass = true; + } else if (p == "is_beta_branch.txt") { + is_beta_branch = true; } else if (p == "force_language.txt") { int len = Local_Storage::get_file_data(steam_settings_path + "force_language.txt", language, sizeof(language) - 1); if (len > 0) { @@ -567,6 +570,8 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s settings_server->http_online = steamhttp_online_mode; settings_client->achievement_bypass = achievement_bypass; settings_server->achievement_bypass = achievement_bypass; + settings_client->is_beta_branch = is_beta_branch; + settings_server->is_beta_branch = is_beta_branch; if (local_save) { settings_client->local_save = save_path; @@ -836,6 +841,29 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s } } + { + std::string installed_apps_list_path = Local_Storage::get_game_settings_path() + "force_branch_name.txt"; + std::ifstream input( utf8_decode(installed_apps_list_path) ); + if (input.is_open()) { + consume_bom(input); + std::string line; + getline( input, line ); + + constexpr const char * const whitespaces = " \t\r\n"; + size_t start = line.find_first_not_of(whitespaces); + size_t end = line.find_last_not_of(whitespaces); + line = start == end + ? std::string() + : line.substr(start, end - start + 1); + + if (!line.empty()) { + settings_client->current_branch_name = line; + settings_server->current_branch_name = line; + PRINT_DEBUG("Forcing current branch name to '%s'\n", line.c_str()); + } + } + } + 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 4f8d4ba1..7441264d 100644 --- a/dll/steam_apps.cpp +++ b/dll/steam_apps.cpp @@ -170,17 +170,17 @@ void Steam_Apps::RequestAppProofOfPurchaseKey( AppId_t nAppID ) } // returns current beta branch name, 'public' is the default branch +// "true if the user is on a beta branch; otherwise, false" +// https://partner.steamgames.com/doc/api/ISteamApps bool Steam_Apps::GetCurrentBetaName( char *pchName, int cchNameBufferSize ) { PRINT_DEBUG("GetCurrentBetaName %i\n", cchNameBufferSize); - if (!pchName) return false; - if (sizeof("public") > cchNameBufferSize) { - return false; + if (pchName && cchNameBufferSize > settings->current_branch_name.size()) { + memcpy(pchName, settings->current_branch_name.c_str(), settings->current_branch_name.size()); } - memcpy(pchName, "public", sizeof("public")); - return true; + return settings->is_beta_branch; } // signal Steam that game files seems corrupt or missing diff --git a/files_example/steam_settings.EXAMPLE/force_branch_name.EXAMPLE.txt b/files_example/steam_settings.EXAMPLE/force_branch_name.EXAMPLE.txt new file mode 100644 index 00000000..b970350c --- /dev/null +++ b/files_example/steam_settings.EXAMPLE/force_branch_name.EXAMPLE.txt @@ -0,0 +1,2 @@ +rename to: force_branch_name.txt and put the name of the branch on a single line that you wish to report to the game. +by default this is "public", you might want to look at is_beta_branch.EXAMPLE.txt diff --git a/files_example/steam_settings.EXAMPLE/is_beta_branch.EXAMPLE.txt b/files_example/steam_settings.EXAMPLE/is_beta_branch.EXAMPLE.txt new file mode 100644 index 00000000..e93f7e1c --- /dev/null +++ b/files_example/steam_settings.EXAMPLE/is_beta_branch.EXAMPLE.txt @@ -0,0 +1 @@ +rename to: is_beta_branch.txt to tell the game that we're playing on a beta branch.