From 6fbc37630b0dd80a9e871f5680b8f9fba853649a Mon Sep 17 00:00:00 2001 From: otavepto <153766569+otavepto@users.noreply.github.com> Date: Mon, 6 May 2024 21:29:59 +0300 Subject: [PATCH] * special function for the overlay `Steam_Friends::get_friend_rich_presence_silent` to avoid spamming the debug log * refactor private method name --- dll/dll/steam_friends.h | 5 ++++- dll/steam_friends.cpp | 24 +++++++++++++++++------- overlay_experimental/steam_overlay.cpp | 6 +++--- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/dll/dll/steam_friends.h b/dll/dll/steam_friends.h index 087fb984..73f7c6ef 100644 --- a/dll/dll/steam_friends.h +++ b/dll/dll/steam_friends.h @@ -67,7 +67,7 @@ public ISteamFriends void rich_presence_updated(CSteamID id, AppId_t appid); - bool isAppIdCompatible(Friend *f); + bool is_appid_compatible(Friend *f); struct Avatar_Numbers add_friend_avatars(CSteamID id); @@ -315,6 +315,9 @@ public: void ClearRichPresence(); + // the overlay will keep calling GetFriendRichPresence() and spam the debug log, hence this function + const char *get_friend_rich_presence_silent( CSteamID steamIDFriend, const char *pchKey ); + const char *GetFriendRichPresence( CSteamID steamIDFriend, const char *pchKey ); int GetFriendRichPresenceKeyCount( CSteamID steamIDFriend ); diff --git a/dll/steam_friends.cpp b/dll/steam_friends.cpp index 85fb161a..69094449 100644 --- a/dll/steam_friends.cpp +++ b/dll/steam_friends.cpp @@ -45,7 +45,7 @@ void Steam_Friends::rich_presence_updated(CSteamID id, AppId_t appid) callbacks->addCBResult(data.k_iCallback, &data, sizeof(data)); } -bool Steam_Friends::isAppIdCompatible(Friend *f) +bool Steam_Friends::is_appid_compatible(Friend *f) { if (settings->is_lobby_connect) return true; if (f == &us) return true; @@ -826,9 +826,9 @@ void Steam_Friends::ClearRichPresence() } -const char* Steam_Friends::GetFriendRichPresence( CSteamID steamIDFriend, const char *pchKey ) +// the overlay will keep calling GetFriendRichPresence() and spam the debug log, hence this function +const char* Steam_Friends::get_friend_rich_presence_silent( CSteamID steamIDFriend, const char *pchKey ) { - PRINT_DEBUG("%llu '%s'", steamIDFriend.ConvertToUint64(), pchKey); std::lock_guard lock(global_mutex); const char *value = ""; @@ -839,11 +839,21 @@ const char* Steam_Friends::GetFriendRichPresence( CSteamID steamIDFriend, const f = find_friend(steamIDFriend); } - if (f && isAppIdCompatible(f)) { + if (f && is_appid_compatible(f)) { auto result = f->rich_presence().find(pchKey); if (result != f->rich_presence().end()) value = result->second.c_str(); } + return value; +} + +const char* Steam_Friends::GetFriendRichPresence( CSteamID steamIDFriend, const char *pchKey ) +{ + PRINT_DEBUG("%llu '%s'", steamIDFriend.ConvertToUint64(), pchKey); + std::lock_guard lock(global_mutex); + + const char *value = get_friend_rich_presence_silent(steamIDFriend, pchKey); + PRINT_DEBUG("returned '%s'", value); return value; } @@ -861,7 +871,7 @@ int Steam_Friends::GetFriendRichPresenceKeyCount( CSteamID steamIDFriend ) f = find_friend(steamIDFriend); } - if (f && isAppIdCompatible(f)) num = f->rich_presence().size(); + if (f && is_appid_compatible(f)) num = f->rich_presence().size(); return num; } @@ -879,7 +889,7 @@ const char* Steam_Friends::GetFriendRichPresenceKeyByIndex( CSteamID steamIDFrie f = find_friend(steamIDFriend); } - if (f && isAppIdCompatible(f) && f->rich_presence().size() > iKey && iKey >= 0) { + if (f && is_appid_compatible(f) && f->rich_presence().size() > iKey && iKey >= 0) { auto friend_data = f->rich_presence().begin(); for (int i = 0; i < iKey; ++i) ++friend_data; key = friend_data->first.c_str(); @@ -1234,7 +1244,7 @@ void Steam_Friends::Callback(Common_Message *msg) if (map1 != map2) { //The App ID of the game. This should always be the current game. - if (isAppIdCompatible(f)) { + if (is_appid_compatible(f)) { rich_presence_updated((uint64)msg->friend_().id(), (uint64)msg->friend_().appid()); } } diff --git a/overlay_experimental/steam_overlay.cpp b/overlay_experimental/steam_overlay.cpp index 4c15085f..97983d74 100644 --- a/overlay_experimental/steam_overlay.cpp +++ b/overlay_experimental/steam_overlay.cpp @@ -652,7 +652,7 @@ bool Steam_Overlay::is_friend_joinable(std::pair lock(global_mutex); Steam_Friends* steamFriends = get_steam_client()->steam_friends; - if (std::string(steamFriends->GetFriendRichPresence((uint64)f.first.id(), "connect")).length() > 0 ) { + if (std::string(steamFriends->get_friend_rich_presence_silent((uint64)f.first.id(), "connect")).length() > 0 ) { PRINT_DEBUG("%" PRIu64 " true (connect string)", f.first.id()); return true; } @@ -672,7 +672,7 @@ bool Steam_Overlay::got_lobby() { std::lock_guard lock(global_mutex); Steam_Friends* steamFriends = get_steam_client()->steam_friends; - if (std::string(steamFriends->GetFriendRichPresence(settings->get_local_steam_id(), "connect")).length() > 0) + if (std::string(steamFriends->get_friend_rich_presence_silent(settings->get_local_steam_id(), "connect")).length() > 0) return true; if (settings->get_lobby().IsValid()) @@ -1152,7 +1152,7 @@ void Steam_Overlay::post_achievement_notification(Overlay_Achievement &ach) void Steam_Overlay::invite_friend(uint64 friend_id, class Steam_Friends* steamFriends, class Steam_Matchmaking* steamMatchmaking) { - std::string connect_str = steamFriends->GetFriendRichPresence(settings->get_local_steam_id(), "connect"); + std::string connect_str = steamFriends->get_friend_rich_presence_silent(settings->get_local_steam_id(), "connect"); if (connect_str.length() > 0) { steamFriends->InviteUserToGame(friend_id, connect_str.c_str()); PRINT_DEBUG("sent game invitation to friend with id = %llu", friend_id);