Load RA_Integration.DLL At Init If Present

This commit is contained in:
LillyJadeKatrin 2024-07-19 22:18:13 -04:00
parent ca5fc105c0
commit 6b87de0df0
4 changed files with 55 additions and 4 deletions

View File

@ -41,6 +41,12 @@
#include "VideoCommon/OnScreenDisplay.h"
#include "VideoCommon/VideoEvents.h"
#ifdef RC_CLIENT_SUPPORTS_RAINTEGRATION
#include <libloaderapi.h>
#include <rcheevos/include/rc_client_raintegration.h>
#include <shlwapi.h>
#endif // RC_CLIENT_SUPPORTS_RAINTEGRATION
static const Common::HttpRequest::Headers USER_AGENT_HEADER = {
{"User-Agent", Common::GetUserAgentStr()}};
@ -50,7 +56,7 @@ AchievementManager& AchievementManager::GetInstance()
return s_instance;
}
void AchievementManager::Init()
void AchievementManager::Init(void* hwnd)
{
LoadDefaultBadges();
if (!m_client && Config::Get(Config::RA_ENABLED))
@ -72,9 +78,22 @@ void AchievementManager::Init()
m_queue.Reset("AchievementManagerQueue", [](const std::function<void()>& func) { func(); });
m_image_queue.Reset("AchievementManagerImageQueue",
[](const std::function<void()>& 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
wchar_t szFilePath[MAX_PATH];
GetModuleFileNameW(NULL, szFilePath, MAX_PATH);
PathRemoveFileSpecW(szFilePath);
rc_client_begin_load_raintegration(m_client, szFilePath, reinterpret_cast<HWND>(hwnd),
"MyClient", "1.0", LoadIntegrationCallback, NULL);
#else // RC_CLIENT_SUPPORTS_RAINTEGRATION
if (HasAPIToken())
Login("");
INFO_LOG_FMT(ACHIEVEMENTS, "Achievement Manager Initialized");
#endif // RC_CLIENT_SUPPORTS_RAINTEGRATION
}
}
@ -1393,4 +1412,31 @@ 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)
{
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

View File

@ -113,7 +113,7 @@ public:
using UpdateCallback = std::function<void(const UpdatedItems&)>;
static AchievementManager& GetInstance();
void Init();
void Init(void* hwnd);
void SetUpdateCallback(UpdateCallback callback);
void Login(const std::string& password);
bool HasAPIToken() const;
@ -233,6 +233,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<Core::System*> m_system{};

View File

@ -256,7 +256,7 @@ void AchievementSettingsWidget::ToggleRAIntegration()
auto& instance = AchievementManager::GetInstance();
if (Config::Get(Config::RA_ENABLED))
instance.Init();
instance.Init(reinterpret_cast<void*>(winId()));
else
instance.Shutdown();
UpdateHardcoreMode();

View File

@ -272,7 +272,7 @@ MainWindow::MainWindow(Core::System& system, std::unique_ptr<BootParameters> boo
NetPlayInit();
#ifdef USE_RETRO_ACHIEVEMENTS
AchievementManager::GetInstance().Init();
AchievementManager::GetInstance().Init(reinterpret_cast<void*>(winId()));
if (AchievementManager::GetInstance().IsHardcoreModeActive())
Settings::Instance().SetDebugModeEnabled(false);
#endif // USE_RETRO_ACHIEVEMENTS