From b9a93794ffae64f0a7377288f75255fe28d054e4 Mon Sep 17 00:00:00 2001 From: LillyJadeKatrin Date: Mon, 22 Jul 2024 23:51:53 -0400 Subject: [PATCH] Added game title estimate for achievement development If the development system is started for a game with an unrecognized hash, RA_Integration opens a dialog for connecting the hash with a title. That dialog is prepopulated by the results of GameTitleEstimateHandler. --- Source/Core/Core/AchievementManager.cpp | 20 +++++++++++++++++--- Source/Core/Core/AchievementManager.h | 2 ++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Source/Core/Core/AchievementManager.cpp b/Source/Core/Core/AchievementManager.cpp index d78e383560..f13486ccd2 100644 --- a/Source/Core/Core/AchievementManager.cpp +++ b/Source/Core/Core/AchievementManager.cpp @@ -22,6 +22,7 @@ #include "Common/Image.h" #include "Common/Logging/Log.h" #include "Common/ScopeGuard.h" +#include "Common/StringUtil.h" #include "Common/Version.h" #include "Common/WorkQueueThread.h" #include "Core/ActionReplay.h" @@ -180,12 +181,17 @@ void AchievementManager::LoadGame(const std::string& file_path, const DiscIO::Vo rc_client_set_unofficial_enabled(m_client, Config::Get(Config::RA_UNOFFICIAL_ENABLED)); rc_client_set_encore_mode_enabled(m_client, Config::Get(Config::RA_ENCORE_ENABLED)); rc_client_set_spectator_mode_enabled(m_client, Config::Get(Config::RA_SPECTATOR_ENABLED)); - if (volume) { std::lock_guard lg{m_lock}; - if (!m_loading_volume) +#ifdef RC_CLIENT_SUPPORTS_RAINTEGRATION + SplitPath(file_path, nullptr, &m_title_estimate, nullptr); +#endif // RC_CLIENT_SUPPORTS_RAINTEGRATION + if (volume) { - m_loading_volume = DiscIO::CreateVolume(volume->GetBlobReader().CopyReader()); + if (!m_loading_volume) + { + m_loading_volume = DiscIO::CreateVolume(volume->GetBlobReader().CopyReader()); + } } } std::lock_guard lg{m_filereader_lock}; @@ -1494,6 +1500,7 @@ void AchievementManager::LoadIntegrationCallback(int result, const char* error_m instance.m_dll_found = true; rc_client_raintegration_set_event_handler(instance.m_client, RAIntegrationEventHandler); rc_client_raintegration_set_write_memory_function(instance.m_client, MemoryPoker); + rc_client_raintegration_set_get_game_name_function(instance.m_client, GameTitleEstimateHandler); instance.m_dev_menu_callback(); // TODO: hook up menu and dll event handlers break; @@ -1565,6 +1572,13 @@ void AchievementManager::MemoryPoker(u32 address, u8* buffer, u32 num_bytes, rc_ system->GetMemory().CopyToEmu(address, buffer, num_bytes); std::copy(buffer, buffer + num_bytes, instance.m_cloned_memory.begin() + address); } +void AchievementManager::GameTitleEstimateHandler(char* buffer, u32 buffer_size, + rc_client_t* client) +{ + auto& instance = AchievementManager::GetInstance(); + std::lock_guard lg{instance.m_lock}; + strncpy(buffer, instance.m_title_estimate.c_str(), static_cast(buffer_size)); +} #endif // RC_CLIENT_SUPPORTS_RAINTEGRATION #endif // USE_RETRO_ACHIEVEMENTS diff --git a/Source/Core/Core/AchievementManager.h b/Source/Core/Core/AchievementManager.h index 6938d6c88a..b1565d8f92 100644 --- a/Source/Core/Core/AchievementManager.h +++ b/Source/Core/Core/AchievementManager.h @@ -254,6 +254,7 @@ private: static void RAIntegrationEventHandler(const rc_client_raintegration_event_t* event, rc_client_t* client); static void MemoryPoker(u32 address, u8* buffer, u32 num_bytes, rc_client_t* client); + static void GameTitleEstimateHandler(char* buffer, u32 buffer_size, rc_client_t* client); #endif // RC_CLIENT_SUPPORTS_RAINTEGRATION rc_runtime_t m_runtime{}; @@ -292,6 +293,7 @@ private: std::function m_dev_menu_callback; std::vector m_cloned_memory; std::recursive_mutex m_memory_lock; + std::string m_title_estimate; #endif // RC_CLIENT_SUPPORTS_RAINTEGRATION Common::WorkQueueThread> m_queue;