diff --git a/Source/Core/Core/AchievementManager.cpp b/Source/Core/Core/AchievementManager.cpp index 08df434fa5..813fc3a868 100644 --- a/Source/Core/Core/AchievementManager.cpp +++ b/Source/Core/Core/AchievementManager.cpp @@ -42,6 +42,12 @@ #include "VideoCommon/OnScreenDisplay.h" #include "VideoCommon/VideoEvents.h" +#ifdef RC_CLIENT_SUPPORTS_RAINTEGRATION +#include +#include +#include +#endif // RC_CLIENT_SUPPORTS_RAINTEGRATION + static const Common::HttpRequest::Headers USER_AGENT_HEADER = { {"User-Agent", Common::GetUserAgentStr()}}; @@ -51,7 +57,7 @@ AchievementManager& AchievementManager::GetInstance() return s_instance; } -void AchievementManager::Init() +void AchievementManager::Init(void* hwnd) { LoadDefaultBadges(); if (!m_client && Config::Get(Config::RA_ENABLED)) @@ -73,9 +79,19 @@ void AchievementManager::Init() m_queue.Reset("AchievementManagerQueue", [](const std::function& func) { func(); }); m_image_queue.Reset("AchievementManagerImageQueue", [](const std::function& func) { func(); }); + +#ifdef RC_CLIENT_SUPPORTS_RAINTEGRATION + // Attempt to load the integration DLL from the directory containing the main client executable. + // In x64 build, will look for RA_Integration-x64.dll, then RA_Integration.dll. + // In non-x64 build, will only look for RA_Integration.dll. + rc_client_begin_load_raintegration( + m_client, UTF8ToWString(File::GetExeDirectory()).c_str(), reinterpret_cast(hwnd), + "Dolphin", Common::GetScmDescStr().c_str(), LoadIntegrationCallback, NULL); +#else // RC_CLIENT_SUPPORTS_RAINTEGRATION if (HasAPIToken()) Login(""); INFO_LOG_FMT(ACHIEVEMENTS, "Achievement Manager Initialized"); +#endif // RC_CLIENT_SUPPORTS_RAINTEGRATION } } @@ -1395,4 +1411,32 @@ void AchievementManager::EventHandler(const rc_client_event_t* event, rc_client_ } } +#ifdef RC_CLIENT_SUPPORTS_RAINTEGRATION +void AchievementManager::LoadIntegrationCallback(int result, const char* error_message, + rc_client_t* client, void* userdata) +{ + auto& instance = AchievementManager::GetInstance(); + switch (result) + { + case RC_OK: + INFO_LOG_FMT(ACHIEVEMENTS, "RAIntegration.dll found."); + // TODO: hook up menu and dll event handlers + break; + + case RC_MISSING_VALUE: + INFO_LOG_FMT(ACHIEVEMENTS, "RAIntegration.dll not found."); + // DLL is not present; do nothing. + break; + + default: + WARN_LOG_FMT(ACHIEVEMENTS, "Failed to load RAIntegration.dll. {}", error_message); + break; + } + + if (instance.HasAPIToken()) + instance.Login(""); + INFO_LOG_FMT(ACHIEVEMENTS, "Achievement Manager Initialized"); +} +#endif // RC_CLIENT_SUPPORTS_RAINTEGRATION + #endif // USE_RETRO_ACHIEVEMENTS diff --git a/Source/Core/Core/AchievementManager.h b/Source/Core/Core/AchievementManager.h index f46b7e9da3..f65ffc8252 100644 --- a/Source/Core/Core/AchievementManager.h +++ b/Source/Core/Core/AchievementManager.h @@ -113,7 +113,7 @@ public: using UpdateCallback = std::function; static AchievementManager& GetInstance(); - void Init(); + void Init(void* hwnd); void SetUpdateCallback(UpdateCallback callback); void Login(const std::string& password); bool HasAPIToken() const; @@ -235,6 +235,11 @@ private: const UpdatedItems callback_data); static void EventHandler(const rc_client_event_t* event, rc_client_t* client); +#ifdef RC_CLIENT_SUPPORTS_RAINTEGRATION + static void LoadIntegrationCallback(int result, const char* error_message, rc_client_t* client, + void* userdata); +#endif // RC_CLIENT_SUPPORTS_RAINTEGRATION + rc_runtime_t m_runtime{}; rc_client_t* m_client{}; std::atomic m_system{}; diff --git a/Source/Core/DolphinQt/Achievements/AchievementSettingsWidget.cpp b/Source/Core/DolphinQt/Achievements/AchievementSettingsWidget.cpp index 75152c09ff..c58e3d6fae 100644 --- a/Source/Core/DolphinQt/Achievements/AchievementSettingsWidget.cpp +++ b/Source/Core/DolphinQt/Achievements/AchievementSettingsWidget.cpp @@ -256,7 +256,7 @@ void AchievementSettingsWidget::ToggleRAIntegration() auto& instance = AchievementManager::GetInstance(); if (Config::Get(Config::RA_ENABLED)) - instance.Init(); + instance.Init(reinterpret_cast(winId())); else instance.Shutdown(); UpdateHardcoreMode(); diff --git a/Source/Core/DolphinQt/MainWindow.cpp b/Source/Core/DolphinQt/MainWindow.cpp index 93ad16a59e..71fc949b7d 100644 --- a/Source/Core/DolphinQt/MainWindow.cpp +++ b/Source/Core/DolphinQt/MainWindow.cpp @@ -272,7 +272,7 @@ MainWindow::MainWindow(Core::System& system, std::unique_ptr boo NetPlayInit(); #ifdef USE_RETRO_ACHIEVEMENTS - AchievementManager::GetInstance().Init(); + AchievementManager::GetInstance().Init(reinterpret_cast(winId())); if (AchievementManager::GetInstance().IsHardcoreModeActive()) Settings::Instance().SetDebugModeEnabled(false); #endif // USE_RETRO_ACHIEVEMENTS