From 31c3288fd52704f41dde9c7304b0233c53accb19 Mon Sep 17 00:00:00 2001 From: LillyJadeKatrin Date: Thu, 13 Apr 2023 23:35:49 -0400 Subject: [PATCH] Added ActivateDeactivateRichPresence to AchievementManager RetroAchievements Rich Presence is a script that is run periodically on a game's memory to provide a detailed text description of what the player is doing. Existing Discord presence on Dolphin would update a player's Discord status to say not just that they are using Dolphin but that they are playing, for example, Sonic Adventure 2 Battle; Rich Presence would detail that the player is in City Escape with 5 lives and 142 rings. Activating this in the runtime simply entails loading that text script, as returned by the FetchGameData API call, into the runtime, here only determined by whether rich presence is enabled in the achievement settings. Deactivating this is done via the same rcheevos method by setting the rich presence to an empty string. --- Source/Core/Core/AchievementManager.cpp | 12 ++++++++++++ Source/Core/Core/AchievementManager.h | 2 ++ Source/Core/Core/Config/AchievementSettings.cpp | 2 ++ Source/Core/Core/Config/AchievementSettings.h | 1 + 4 files changed, 17 insertions(+) diff --git a/Source/Core/Core/AchievementManager.cpp b/Source/Core/Core/AchievementManager.cpp index 1b44ab8a4e..a274ac11b7 100644 --- a/Source/Core/Core/AchievementManager.cpp +++ b/Source/Core/Core/AchievementManager.cpp @@ -142,6 +142,7 @@ void AchievementManager::LoadGameByFilenameAsync(const std::string& iso_path, ActivateDeactivateAchievements(); } ActivateDeactivateLeaderboards(); + ActivateDeactivateRichPresence(); callback(fetch_game_data_response); }); @@ -191,6 +192,16 @@ void AchievementManager::ActivateDeactivateLeaderboards() } } +void AchievementManager::ActivateDeactivateRichPresence() +{ + rc_runtime_activate_richpresence( + &m_runtime, + (m_is_game_loaded && Config::Get(Config::RA_RICH_PRESENCE_ENABLED)) ? + m_game_data.rich_presence_script : + "", + nullptr, 0); +} + void AchievementManager::CloseGame() { m_is_game_loaded = false; @@ -199,6 +210,7 @@ void AchievementManager::CloseGame() m_unlock_map.clear(); ActivateDeactivateAchievements(); ActivateDeactivateLeaderboards(); + ActivateDeactivateRichPresence(); } void AchievementManager::Logout() diff --git a/Source/Core/Core/AchievementManager.h b/Source/Core/Core/AchievementManager.h index d2e37329f0..b759386721 100644 --- a/Source/Core/Core/AchievementManager.h +++ b/Source/Core/Core/AchievementManager.h @@ -42,6 +42,8 @@ public: void LoadUnlockData(const ResponseCallback& callback); void ActivateDeactivateAchievements(); void ActivateDeactivateLeaderboards(); + void ActivateDeactivateRichPresence(); + void CloseGame(); void Logout(); void Shutdown(); diff --git a/Source/Core/Core/Config/AchievementSettings.cpp b/Source/Core/Core/Config/AchievementSettings.cpp index 6da342cbc4..3499fcc791 100644 --- a/Source/Core/Core/Config/AchievementSettings.cpp +++ b/Source/Core/Core/Config/AchievementSettings.cpp @@ -17,6 +17,8 @@ const Info RA_ACHIEVEMENTS_ENABLED{ {System::Achievements, "Achievements", "AchievementsEnabled"}, false}; const Info RA_LEADERBOARDS_ENABLED{ {System::Achievements, "Achievements", "LeaderboardsEnabled"}, false}; +const Info RA_RICH_PRESENCE_ENABLED{ + {System::Achievements, "Achievements", "RichPresenceEnabled"}, false}; const Info RA_UNOFFICIAL_ENABLED{{System::Achievements, "Achievements", "UnofficialEnabled"}, false}; const Info RA_ENCORE_ENABLED{{System::Achievements, "Achievements", "EncoreEnabled"}, false}; diff --git a/Source/Core/Core/Config/AchievementSettings.h b/Source/Core/Core/Config/AchievementSettings.h index f49537ec39..33318f7400 100644 --- a/Source/Core/Core/Config/AchievementSettings.h +++ b/Source/Core/Core/Config/AchievementSettings.h @@ -13,6 +13,7 @@ extern const Info RA_USERNAME; extern const Info RA_API_TOKEN; extern const Info RA_ACHIEVEMENTS_ENABLED; extern const Info RA_LEADERBOARDS_ENABLED; +extern const Info RA_RICH_PRESENCE_ENABLED; extern const Info RA_UNOFFICIAL_ENABLED; extern const Info RA_ENCORE_ENABLED; } // namespace Config