Add rc_client to AchievementManager

Also includes init and shutdown V2s.
This commit is contained in:
LillyJadeKatrin 2024-03-17 08:26:49 -04:00
parent 4ec662bcdf
commit ba519e4670
2 changed files with 20 additions and 11 deletions

View File

@ -33,13 +33,18 @@ AchievementManager& AchievementManager::GetInstance()
void AchievementManager::Init() void AchievementManager::Init()
{ {
if (!m_is_runtime_initialized && Config::Get(Config::RA_ENABLED)) if (!m_client && Config::Get(Config::RA_ENABLED))
{ {
m_client = rc_client_create(MemoryPeekerV2, RequestV2);
std::string host_url = Config::Get(Config::RA_HOST_URL); std::string host_url = Config::Get(Config::RA_HOST_URL);
if (!host_url.empty()) if (!host_url.empty())
rc_api_set_host(host_url.c_str()); rc_client_set_host(m_client, host_url.c_str());
rc_runtime_init(&m_runtime); rc_client_enable_logging(m_client, RC_CLIENT_LOG_LEVEL_VERBOSE,
m_is_runtime_initialized = true; [](const char* message, const rc_client_t* client) {
INFO_LOG_FMT(ACHIEVEMENTS, "{}", message);
});
rc_client_set_hardcore_enabled(m_client, 0);
rc_client_set_unofficial_enabled(m_client, 1);
m_queue.Reset("AchievementManagerQueue", [](const std::function<void()>& func) { func(); }); m_queue.Reset("AchievementManagerQueue", [](const std::function<void()>& func) { func(); });
m_image_queue.Reset("AchievementManagerImageQueue", m_image_queue.Reset("AchievementManagerImageQueue",
[](const std::function<void()>& func) { func(); }); [](const std::function<void()>& func) { func(); });
@ -942,13 +947,16 @@ void AchievementManager::Logout()
void AchievementManager::Shutdown() void AchievementManager::Shutdown()
{ {
CloseGame(); if (m_client)
SetDisabled(false); {
m_is_runtime_initialized = false; CloseGame();
m_queue.Shutdown(); SetDisabled(false);
// DON'T log out - keep those credentials for next run. m_queue.Shutdown();
rc_runtime_destroy(&m_runtime); // DON'T log out - keep those credentials for next run.
INFO_LOG_FMT(ACHIEVEMENTS, "Achievement Manager shut down."); rc_client_destroy(m_client);
m_client = nullptr;
INFO_LOG_FMT(ACHIEVEMENTS, "Achievement Manager shut down.");
}
} }
void* AchievementManager::FilereaderOpenByFilepath(const char* path_utf8) void* AchievementManager::FilereaderOpenByFilepath(const char* path_utf8)

View File

@ -210,6 +210,7 @@ private:
static u32 MemoryPeekerV2(u32 address, u8* buffer, u32 num_bytes, rc_client_t* client); static u32 MemoryPeekerV2(u32 address, u8* buffer, u32 num_bytes, rc_client_t* client);
rc_runtime_t m_runtime{}; rc_runtime_t m_runtime{};
rc_client_t* m_client{};
Core::System* m_system{}; Core::System* m_system{};
bool m_is_runtime_initialized = false; bool m_is_runtime_initialized = false;
UpdateCallback m_update_callback = [] {}; UpdateCallback m_update_callback = [] {};