Add MemoryPoker for RAIntegration

This commit is contained in:
LillyJadeKatrin 2024-07-22 02:28:50 -04:00
parent baf4e07213
commit e1517883b3
2 changed files with 37 additions and 5 deletions

View File

@ -32,6 +32,7 @@
#include "Core/GeckoCode.h"
#include "Core/HW/Memmap.h"
#include "Core/HW/VideoInterface.h"
#include "Core/Host.h"
#include "Core/PatchEngine.h"
#include "Core/PowerPC/MMU.h"
#include "Core/System.h"
@ -89,7 +90,7 @@ void AchievementManager::Init(void* hwnd)
rc_client_begin_load_raintegration(m_client, szFilePath, reinterpret_cast<HWND>(hwnd),
"MyClient", "1.0", LoadIntegrationCallback, NULL);
#else // RC_CLIENT_SUPPORTS_RAINTEGRATION
#else // RC_CLIENT_SUPPORTS_RAINTEGRATION
if (HasAPIToken())
Login("");
INFO_LOG_FMT(ACHIEVEMENTS, "Achievement Manager Initialized");
@ -314,6 +315,10 @@ void AchievementManager::DoFrame()
return;
{
std::lock_guard lg{m_lock};
#ifdef RC_CLIENT_SUPPORTS_RAINTEGRATION
Core::System::GetInstance().GetMemory().CopyFromEmu(m_cloned_memory.data(), 0x80000000U,
m_cloned_memory.size());
#endif // RC_CLIENT_SUPPORTS_RAINTEGRATION
rc_client_do_frame(m_client);
}
Core::System* system = m_system.load(std::memory_order_acquire);
@ -1266,8 +1271,16 @@ u32 AchievementManager::MemoryPeeker(u32 address, u8* buffer, u32 num_bytes, rc_
auto& system = Core::System::GetInstance();
if (!(Core::IsHostThread() || Core::IsCPUThread()))
{
#ifdef RC_CLIENT_SUPPORTS_RAINTEGRATION
auto& instance = AchievementManager::GetInstance();
u32 bytes_read = 0;
for (u32 ix = address; ix < address + num_bytes && ix < instance.m_cloned_memory.size(); ix++)
buffer[bytes_read++] = instance.m_cloned_memory[ix];
return bytes_read;
#else // RC_CLIENT_SUPPORTS_RAINTEGRATION
ASSERT_MSG(ACHIEVEMENTS, false, "MemoryPeeker called from wrong thread");
return 0;
#endif // RC_CLIENT_SUPPORTS_RAINTEGRATION
}
Core::CPUThreadGuard threadguard(system);
for (u32 num_read = 0; num_read < num_bytes; num_read++)
@ -1440,6 +1453,7 @@ void AchievementManager::LoadIntegrationCallback(int result, const char* error_m
INFO_LOG_FMT(ACHIEVEMENTS, "RAIntegration.dll found.");
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);
instance.m_dev_menu_callback();
// TODO: hook up menu and dll event handlers
break;
@ -1486,6 +1500,25 @@ void AchievementManager::RAIntegrationEventHandler(const rc_client_raintegration
break;
}
}
void AchievementManager::MemoryPoker(u32 address, u8* buffer, u32 num_bytes, rc_client_t* client)
{
if (buffer == nullptr)
return;
auto& system = Core::System::GetInstance();
if (!(Core::IsHostThread() || Core::IsCPUThread()))
{
Core::QueueHostJob([address, buffer, num_bytes, client](Core::System& system) {
MemoryPoker(address, buffer, num_bytes, client);
});
}
Core::CPUThreadGuard threadguard(system);
for (u32 num_write = 0; num_write < num_bytes; num_write++)
{
system.GetMMU().HostTryWriteU8(threadguard, buffer[num_write], address + num_write,
PowerPC::RequestedAddressSpace::Physical);
}
}
#endif // RC_CLIENT_SUPPORTS_RAINTEGRATION
#endif // USE_RETRO_ACHIEVEMENTS

View File

@ -172,10 +172,7 @@ public:
{
m_dev_menu_callback = callback;
};
void SetHardcoreCallback(std::function<void(void)> callback)
{
m_hardcore_callback = callback;
};
void SetHardcoreCallback(std::function<void(void)> callback) { m_hardcore_callback = callback; };
#endif // RC_CLIENT_SUPPORTS_RAINTEGRATION
void DoState(PointerWrap& p);
@ -255,6 +252,7 @@ private:
void* userdata);
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);
#endif // RC_CLIENT_SUPPORTS_RAINTEGRATION
rc_runtime_t m_runtime{};
@ -293,6 +291,7 @@ private:
#ifdef RC_CLIENT_SUPPORTS_RAINTEGRATION
std::function<void(void)> m_dev_menu_callback;
std::function<void(void)> m_hardcore_callback;
std::vector<u8> m_cloned_memory;
#endif // RC_CLIENT_SUPPORTS_RAINTEGRATION
Common::WorkQueueThread<std::function<void()>> m_queue;