Merge pull request #12212 from LillyJadeKatrin/retroachievements-bugfix

Added error checking and logging to AchievementManager::GetAchievemen…
This commit is contained in:
Admiral H. Curtiss 2023-10-01 16:50:30 +02:00 committed by GitHub
commit d55d878b17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 7 deletions

View File

@ -688,12 +688,25 @@ AchievementManager::GetUnlockStatus(AchievementId achievement_id) const
return m_unlock_map.at(achievement_id); return m_unlock_map.at(achievement_id);
} }
void AchievementManager::GetAchievementProgress(AchievementId achievement_id, u32* value, AchievementManager::ResponseType
u32* target) AchievementManager::GetAchievementProgress(AchievementId achievement_id, u32* value, u32* target)
{ {
if (!IsGameLoaded()) if (!IsGameLoaded())
return; {
rc_runtime_get_achievement_measured(&m_runtime, achievement_id, value, target); ERROR_LOG_FMT(
ACHIEVEMENTS,
"Attempted to request measured data for achievement ID {} when no game is running.",
achievement_id);
return ResponseType::INVALID_REQUEST;
}
int result = rc_runtime_get_achievement_measured(&m_runtime, achievement_id, value, target);
if (result == 0)
{
WARN_LOG_FMT(ACHIEVEMENTS, "Failed to get measured data for achievement ID {}.",
achievement_id);
return ResponseType::MALFORMED_OBJECT;
}
return ResponseType::SUCCESS;
} }
AchievementManager::RichPresence AchievementManager::GetRichPresence() AchievementManager::RichPresence AchievementManager::GetRichPresence()

View File

@ -111,7 +111,8 @@ public:
rc_api_fetch_game_data_response_t* GetGameData(); rc_api_fetch_game_data_response_t* GetGameData();
const BadgeStatus& GetGameBadge() const; const BadgeStatus& GetGameBadge() const;
const UnlockStatus& GetUnlockStatus(AchievementId achievement_id) const; const UnlockStatus& GetUnlockStatus(AchievementId achievement_id) const;
void GetAchievementProgress(AchievementId achievement_id, u32* value, u32* target); AchievementManager::ResponseType GetAchievementProgress(AchievementId achievement_id, u32* value,
u32* target);
RichPresence GetRichPresence(); RichPresence GetRichPresence();
void CloseGame(); void CloseGame();

View File

@ -105,8 +105,9 @@ AchievementProgressWidget::CreateAchievementBox(const rc_api_achievement_definit
a_progress_bar->setSizePolicy(sp_retain); a_progress_bar->setSizePolicy(sp_retain);
unsigned int value = 0; unsigned int value = 0;
unsigned int target = 0; unsigned int target = 0;
AchievementManager::GetInstance()->GetAchievementProgress(achievement->id, &value, &target); if (AchievementManager::GetInstance()->GetAchievementProgress(achievement->id, &value, &target) ==
if (target > 0) AchievementManager::ResponseType::SUCCESS &&
target > 0)
{ {
a_progress_bar->setRange(0, target); a_progress_bar->setRange(0, target);
a_progress_bar->setValue(value); a_progress_bar->setValue(value);