Merge pull request #12633 from LillyJadeKatrin/retroachievements-toggle-spam

Added locks to achievement runtime calls
This commit is contained in:
Admiral H. Curtiss 2024-03-15 02:58:02 +01:00 committed by GitHub
commit 9cdd571745
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 29 additions and 28 deletions

View File

@ -350,6 +350,7 @@ void AchievementManager::LoadUnlockData(const ResponseCallback& callback)
void AchievementManager::ActivateDeactivateAchievements() void AchievementManager::ActivateDeactivateAchievements()
{ {
std::lock_guard lg{m_lock};
if (!Config::Get(Config::RA_ENABLED) || !IsLoggedIn()) if (!Config::Get(Config::RA_ENABLED) || !IsLoggedIn())
return; return;
bool enabled = Config::Get(Config::RA_ACHIEVEMENTS_ENABLED); bool enabled = Config::Get(Config::RA_ACHIEVEMENTS_ENABLED);
@ -369,6 +370,7 @@ void AchievementManager::ActivateDeactivateAchievements()
void AchievementManager::ActivateDeactivateLeaderboards() void AchievementManager::ActivateDeactivateLeaderboards()
{ {
std::lock_guard lg{m_lock};
if (!Config::Get(Config::RA_ENABLED) || !IsLoggedIn()) if (!Config::Get(Config::RA_ENABLED) || !IsLoggedIn())
return; return;
bool leaderboards_enabled = bool leaderboards_enabled =
@ -395,6 +397,7 @@ void AchievementManager::ActivateDeactivateLeaderboards()
void AchievementManager::ActivateDeactivateRichPresence() void AchievementManager::ActivateDeactivateRichPresence()
{ {
std::lock_guard lg{m_lock};
if (!Config::Get(Config::RA_ENABLED) || !IsLoggedIn()) if (!Config::Get(Config::RA_ENABLED) || !IsLoggedIn())
return; return;
rc_runtime_activate_richpresence( rc_runtime_activate_richpresence(
@ -659,7 +662,7 @@ void AchievementManager::FetchBadges()
void AchievementManager::DoFrame() void AchievementManager::DoFrame()
{ {
if (!m_is_game_loaded) if (!m_is_game_loaded || !Core::IsCPUThread())
return; return;
if (m_framecount == 0x200) if (m_framecount == 0x200)
{ {
@ -669,7 +672,8 @@ void AchievementManager::DoFrame()
{ {
m_framecount++; m_framecount++;
} }
Core::RunAsCPUThread([&] { {
std::lock_guard lg{m_lock};
rc_runtime_do_frame( rc_runtime_do_frame(
&m_runtime, &m_runtime,
[](const rc_runtime_event_t* runtime_event) { [](const rc_runtime_event_t* runtime_event) {
@ -679,7 +683,7 @@ void AchievementManager::DoFrame()
return static_cast<AchievementManager*>(ud)->MemoryPeeker(address, num_bytes, ud); return static_cast<AchievementManager*>(ud)->MemoryPeeker(address, num_bytes, ud);
}, },
this, nullptr); this, nullptr);
}); }
if (!m_system) if (!m_system)
return; return;
time_t current_time = std::time(nullptr); time_t current_time = std::time(nullptr);
@ -724,32 +728,29 @@ u32 AchievementManager::MemoryPeeker(u32 address, u32 num_bytes, void* ud)
void AchievementManager::AchievementEventHandler(const rc_runtime_event_t* runtime_event) void AchievementManager::AchievementEventHandler(const rc_runtime_event_t* runtime_event)
{ {
switch (runtime_event->type)
{ {
std::lock_guard lg{m_lock}; case RC_RUNTIME_EVENT_ACHIEVEMENT_TRIGGERED:
switch (runtime_event->type) HandleAchievementTriggeredEvent(runtime_event);
{ break;
case RC_RUNTIME_EVENT_ACHIEVEMENT_TRIGGERED: case RC_RUNTIME_EVENT_ACHIEVEMENT_PROGRESS_UPDATED:
HandleAchievementTriggeredEvent(runtime_event); HandleAchievementProgressUpdatedEvent(runtime_event);
break; break;
case RC_RUNTIME_EVENT_ACHIEVEMENT_PROGRESS_UPDATED: case RC_RUNTIME_EVENT_ACHIEVEMENT_PRIMED:
HandleAchievementProgressUpdatedEvent(runtime_event); HandleAchievementPrimedEvent(runtime_event);
break; break;
case RC_RUNTIME_EVENT_ACHIEVEMENT_PRIMED: case RC_RUNTIME_EVENT_ACHIEVEMENT_UNPRIMED:
HandleAchievementPrimedEvent(runtime_event); HandleAchievementUnprimedEvent(runtime_event);
break; break;
case RC_RUNTIME_EVENT_ACHIEVEMENT_UNPRIMED: case RC_RUNTIME_EVENT_LBOARD_STARTED:
HandleAchievementUnprimedEvent(runtime_event); HandleLeaderboardStartedEvent(runtime_event);
break; break;
case RC_RUNTIME_EVENT_LBOARD_STARTED: case RC_RUNTIME_EVENT_LBOARD_CANCELED:
HandleLeaderboardStartedEvent(runtime_event); HandleLeaderboardCanceledEvent(runtime_event);
break; break;
case RC_RUNTIME_EVENT_LBOARD_CANCELED: case RC_RUNTIME_EVENT_LBOARD_TRIGGERED:
HandleLeaderboardCanceledEvent(runtime_event); HandleLeaderboardTriggeredEvent(runtime_event);
break; break;
case RC_RUNTIME_EVENT_LBOARD_TRIGGERED:
HandleLeaderboardTriggeredEvent(runtime_event);
break;
}
} }
} }