From ee051da66d32ee3413a5a5e909dbf483f71bd17e 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 | 22 +++++++++++++++++++--- Source/Core/Core/AchievementManager.h | 2 ++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Source/Core/Core/AchievementManager.cpp b/Source/Core/Core/AchievementManager.cpp index 41a6fd4919..41ebb99be3 100644 --- a/Source/Core/Core/AchievementManager.cpp +++ b/Source/Core/Core/AchievementManager.cpp @@ -182,12 +182,19 @@ 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 + size_t estimate_start = file_path.find_last_of("\\/"); + size_t estimate_end = file_path.find_first_of('.'); + m_title_estimate = file_path.substr(estimate_start + 1, estimate_end - estimate_start - 1); +#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}; @@ -1479,6 +1486,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; @@ -1544,6 +1552,14 @@ void AchievementManager::MemoryPoker(u32 address, u8* buffer, u32 num_bytes, rc_ PowerPC::RequestedAddressSpace::Physical); } } +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(), + std::min(instance.m_title_estimate.size(), 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 1958d35744..ba9dc37d2e 100644 --- a/Source/Core/Core/AchievementManager.h +++ b/Source/Core/Core/AchievementManager.h @@ -253,6 +253,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::function m_hardcore_callback; std::vector m_cloned_memory; + std::string m_title_estimate; #endif // RC_CLIENT_SUPPORTS_RAINTEGRATION Common::WorkQueueThread> m_queue;