From b89dfe6e448ef0bcf11fae3568da563ab436f64c Mon Sep 17 00:00:00 2001 From: otavepto <153766569+otavepto@users.noreply.github.com> Date: Fri, 7 Jun 2024 19:52:31 +0300 Subject: [PATCH] don't exit early in `Steam_Overlay::AddAchievementNotification()`, allow the function to update the data but avoid posting notifications if not needed --- overlay_experimental/steam_overlay.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/overlay_experimental/steam_overlay.cpp b/overlay_experimental/steam_overlay.cpp index e1a56ccf..d5e87d7a 100644 --- a/overlay_experimental/steam_overlay.cpp +++ b/overlay_experimental/steam_overlay.cpp @@ -2019,7 +2019,6 @@ void Steam_Overlay::FriendDisconnect(Friend _friend) void Steam_Overlay::AddAchievementNotification(const std::string &ach_name, nlohmann::json const &ach, bool for_progress) { if (settings->disable_overlay) return; - if (for_progress && settings->disable_overlay_achievement_progress) return; PRINT_DEBUG_ENTRY(); std::lock_guard lock(overlay_mutex); @@ -2028,12 +2027,12 @@ void Steam_Overlay::AddAchievementNotification(const std::string &ach_name, nloh // don't return early when disable_overlay_achievement_notification is true // otherwise when you open the achievements list/menu you won't see the new unlock status - // adjust the local 'is_achieved' and 'unlock_time' - std::lock_guard lock2(global_mutex); - for (auto &a : achievements) { if (a.name == ach_name) { try { + // lock to prevent modifications to this json object + std::lock_guard lock2(global_mutex); + a.achieved = ach.value("earned", false); a.unlock_time = ach.value("earned_time", static_cast(0)); a.progress = ach.value("progress", static_cast(0)); @@ -2041,8 +2040,14 @@ void Steam_Overlay::AddAchievementNotification(const std::string &ach_name, nloh } catch(...) {} if (a.achieved) { - post_achievement_notification(a, for_progress); - if (!for_progress) notify_sound_user_achievement(); + // post notification if this isn't a progress, or a progress and the user didn't disable these notifications + if (!for_progress || !settings->disable_overlay_achievement_progress) { + post_achievement_notification(a, for_progress); + } + // don't play sound if this is progress + if (!for_progress) { + notify_sound_user_achievement(); + } } break; }