diff --git a/Source/Core/Core/AchievementManager.cpp b/Source/Core/Core/AchievementManager.cpp index 7e0fa5a9d9..4cd3aad766 100644 --- a/Source/Core/Core/AchievementManager.cpp +++ b/Source/Core/Core/AchievementManager.cpp @@ -4,6 +4,10 @@ #ifdef USE_RETRO_ACHIEVEMENTS #include "Core/AchievementManager.h" + +#include +#include + #include "Common/HttpRequest.h" #include "Common/WorkQueueThread.h" #include "Config/AchievementSettings.h" @@ -71,6 +75,23 @@ AchievementManager::ResponseType AchievementManager::VerifyCredentials(const std return r_type; } +AchievementManager::ResponseType +AchievementManager::ResolveHash(std::array game_hash) +{ + rc_api_resolve_hash_response_t hash_data{}; + std::string username = Config::Get(Config::RA_USERNAME); + std::string api_token = Config::Get(Config::RA_API_TOKEN); + rc_api_resolve_hash_request_t resolve_hash_request = { + .username = username.c_str(), .api_token = api_token.c_str(), .game_hash = game_hash.data()}; + ResponseType r_type = Request( + resolve_hash_request, &hash_data, rc_api_init_resolve_hash_request, + rc_api_process_resolve_hash_response); + if (r_type == ResponseType::SUCCESS) + m_game_id = hash_data.game_id; + rc_api_destroy_resolve_hash_response(&hash_data); + return r_type; +} + // Every RetroAchievements API call, with only a partial exception for fetch_image, follows // the same design pattern (here, X is the name of the call): // Create a specific rc_api_X_request_t struct and populate with the necessary values diff --git a/Source/Core/Core/AchievementManager.h b/Source/Core/Core/AchievementManager.h index 91fd9339ef..4132db23af 100644 --- a/Source/Core/Core/AchievementManager.h +++ b/Source/Core/Core/AchievementManager.h @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -38,7 +39,10 @@ public: private: AchievementManager() = default; + static constexpr int HASH_LENGTH = 33; + ResponseType VerifyCredentials(const std::string& password); + ResponseType ResolveHash(std::array game_hash); template ResponseType Request(RcRequest rc_request, RcResponse* rc_response, @@ -47,7 +51,10 @@ private: rc_runtime_t m_runtime{}; bool m_is_runtime_initialized = false; + unsigned int m_game_id = 0; rc_api_login_response_t m_login_data{}; + + Common::WorkQueueThread> m_queue; }; // class AchievementManager