summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorLillyJadeKatrin <lilly.kitty.1988@gmail.com>2023-10-02 08:27:59 -0400
committerLillyJadeKatrin <lilly.kitty.1988@gmail.com>2023-12-05 16:17:18 -0500
commitebf2ef1d82990c17bbb9201bd68f2ec9156ab551 (patch)
tree4a4adcfb210bf96afe4970f1cb191706365b519f /Source/Core
parentc8d8ca2ff7c33ec9dca6dc40092b4bb092ae923c (diff)
Refactored hash process to check prior game ID
If the new game ID is a different title than the previous game ID, the achievement manager is compromised.
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Core/AchievementManager.cpp38
-rw-r--r--Source/Core/Core/AchievementManager.h2
2 files changed, 33 insertions, 7 deletions
diff --git a/Source/Core/Core/AchievementManager.cpp b/Source/Core/Core/AchievementManager.cpp
index e41cc43eb5..ebb83ac801 100644
--- a/Source/Core/Core/AchievementManager.cpp
+++ b/Source/Core/Core/AchievementManager.cpp
@@ -224,13 +224,14 @@ void AchievementManager::HashGame(const DiscIO::Volume* volume, const ResponseCa
void AchievementManager::LoadGameSync(const ResponseCallback& callback)
{
+ u32 new_game_id = 0;
Hash current_hash;
{
std::lock_guard lg{m_lock};
current_hash = m_game_hash;
}
- const auto resolve_hash_response = ResolveHash(current_hash);
- if (resolve_hash_response != ResponseType::SUCCESS || m_game_id == 0)
+ const auto resolve_hash_response = ResolveHash(current_hash, &new_game_id);
+ if (resolve_hash_response != ResponseType::SUCCESS || new_game_id == 0)
{
INFO_LOG_FMT(ACHIEVEMENTS, "No RetroAchievements data found for this game.");
OSD::AddMessage("No RetroAchievements data found for this game.", OSD::Duration::VERY_LONG,
@@ -239,6 +240,31 @@ void AchievementManager::LoadGameSync(const ResponseCallback& callback)
callback(resolve_hash_response);
return;
}
+ u32 old_game_id;
+ {
+ std::lock_guard lg{m_lock};
+ old_game_id = m_game_id;
+ }
+ if (new_game_id == old_game_id)
+ {
+ INFO_LOG_FMT(ACHIEVEMENTS, "Alternate hash resolved for current game {}.", old_game_id);
+ callback(ResponseType::SUCCESS);
+ return;
+ }
+ else if (old_game_id != 0)
+ {
+ INFO_LOG_FMT(ACHIEVEMENTS, "Swapping game {} for game {}; achievements disabled.", old_game_id,
+ new_game_id);
+ OSD::AddMessage("Achievements are now disabled. Please close emulation to re-enable.",
+ OSD::Duration::VERY_LONG, OSD::Color::RED);
+ SetDisabled(true);
+ callback(ResponseType::EXPIRED_CONTEXT);
+ return;
+ }
+ {
+ std::lock_guard lg{m_lock};
+ m_game_id = new_game_id;
+ }
const auto start_session_response = StartRASession();
if (start_session_response != ResponseType::SUCCESS)
@@ -979,7 +1005,8 @@ AchievementManager::ResponseType AchievementManager::VerifyCredentials(const std
return r_type;
}
-AchievementManager::ResponseType AchievementManager::ResolveHash(Hash game_hash)
+AchievementManager::ResponseType AchievementManager::ResolveHash(const Hash& game_hash,
+ u32* game_id)
{
rc_api_resolve_hash_response_t hash_data{};
std::string username, api_token;
@@ -995,9 +1022,8 @@ AchievementManager::ResponseType AchievementManager::ResolveHash(Hash game_hash)
rc_api_process_resolve_hash_response);
if (r_type == ResponseType::SUCCESS)
{
- std::lock_guard lg{m_lock};
- m_game_id = hash_data.game_id;
- INFO_LOG_FMT(ACHIEVEMENTS, "Hashed game ID {} for RetroAchievements.", m_game_id);
+ *game_id = hash_data.game_id;
+ INFO_LOG_FMT(ACHIEVEMENTS, "Hashed game ID {} for RetroAchievements.", *game_id);
}
else
{
diff --git a/Source/Core/Core/AchievementManager.h b/Source/Core/Core/AchievementManager.h
index 9e994cc59e..7d93b7d781 100644
--- a/Source/Core/Core/AchievementManager.h
+++ b/Source/Core/Core/AchievementManager.h
@@ -160,7 +160,7 @@ private:
static void FilereaderClose(void* file_handle);
ResponseType VerifyCredentials(const std::string& password);
- ResponseType ResolveHash(Hash game_hash);
+ ResponseType ResolveHash(const Hash& game_hash, u32* game_id);
void LoadGameSync(const ResponseCallback& callback);
ResponseType StartRASession();
ResponseType FetchGameData();