From 0a3c27765d800f41964ae6b168bf5a58c1cb15e7 Mon Sep 17 00:00:00 2001 From: KamFretoZ <14798312+kamfretoz@users.noreply.github.com> Date: Fri, 17 Apr 2026 19:53:07 +0700 Subject: [PATCH] Achievements: Simplify sound effects playback --- pcsx2/Achievements.cpp | 35 ++++++++++++++--------------------- pcsx2/Achievements.h | 3 +++ 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/pcsx2/Achievements.cpp b/pcsx2/Achievements.cpp index ff672d2341..d118c59bac 100644 --- a/pcsx2/Achievements.cpp +++ b/pcsx2/Achievements.cpp @@ -934,6 +934,17 @@ void Achievements::UpdateRichPresence(std::unique_lock& lo lock.lock(); } +void Achievements::PlayAchievementSound(bool is_specific_sound_enabled, const std::string& custom_sound_name, const std::string& default_sound_name) +{ + if (!EmuConfig.Achievements.SoundEffects || !is_specific_sound_enabled) + return; + + if (custom_sound_name.empty() || !FileSystem::FileExists(custom_sound_name.c_str())) + Common::PlaySoundAsync(Path::Combine(EmuFolders::Resources, default_sound_name).c_str()); + else + Common::PlaySoundAsync(custom_sound_name.c_str()); +} + void Achievements::GameChanged(u32 disc_crc, u32 crc) { std::unique_lock lock(s_achievements_mutex); @@ -1151,13 +1162,7 @@ void Achievements::DisplayAchievementSummary() } }); } - - if (EmuConfig.Achievements.SoundEffects && EmuConfig.Achievements.InfoSound) - Common::PlaySoundAsync( - (EmuConfig.Achievements.InfoSoundName.empty() - ? Path::Combine(EmuFolders::Resources, DEFAULT_INFO_SOUND_NAME) - : EmuConfig.Achievements.InfoSoundName).c_str() - ); + Achievements::PlayAchievementSound(EmuConfig.Achievements.InfoSound, EmuConfig.Achievements.InfoSoundName, DEFAULT_INFO_SOUND_NAME); } void Achievements::DisplayHardcoreDeferredMessage() @@ -1207,13 +1212,7 @@ void Achievements::HandleUnlockEvent(const rc_client_event_t* event) std::move(title), std::move(summary), std::move(badge_path)); }); } - - if (EmuConfig.Achievements.SoundEffects && EmuConfig.Achievements.UnlockSound) - Common::PlaySoundAsync( - (EmuConfig.Achievements.UnlockSoundName.empty() - ? Path::Combine(EmuFolders::Resources, DEFAULT_UNLOCK_SOUND_NAME) - : EmuConfig.Achievements.UnlockSoundName).c_str() - ); + Achievements::PlayAchievementSound(EmuConfig.Achievements.UnlockSound, EmuConfig.Achievements.UnlockSoundName, DEFAULT_UNLOCK_SOUND_NAME); } void Achievements::HandleGameCompleteEvent(const rc_client_event_t* event) @@ -1332,13 +1331,7 @@ void Achievements::HandleLeaderboardSubmittedEvent(const rc_client_event_t* even } }); } - - if (EmuConfig.Achievements.SoundEffects && EmuConfig.Achievements.LBSubmitSound) - Common::PlaySoundAsync( - (EmuConfig.Achievements.LBSubmitSoundName.empty() - ? Path::Combine(EmuFolders::Resources, DEFAULT_LBSUBMIT_SOUND_NAME) - : EmuConfig.Achievements.LBSubmitSoundName).c_str() - ); + Achievements::PlayAchievementSound(EmuConfig.Achievements.LBSubmitSound, EmuConfig.Achievements.LBSubmitSoundName, DEFAULT_LBSUBMIT_SOUND_NAME); } void Achievements::HandleLeaderboardScoreboardEvent(const rc_client_event_t* event) diff --git a/pcsx2/Achievements.h b/pcsx2/Achievements.h index e3c37de1e4..da3cf50aaa 100644 --- a/pcsx2/Achievements.h +++ b/pcsx2/Achievements.h @@ -67,6 +67,9 @@ namespace Achievements /// Called when the system changes game, or is booting. void GameChanged(u32 disc_crc, u32 crc); + /// Play achievement related sounds effects + void PlayAchievementSound(bool is_specific_sound_enabled, const std::string& custom_sound_name, const std::string& default_sound_name); + /// Re-enables hardcode mode if it is enabled in the settings. bool ResetHardcoreMode(bool is_booting);