Added MemoryPeeker to AchievementManager

MemoryPeeker is a function passed by pointer into rcheevos DoFrame functionality that forms the lynchpin of the rcheevos runtime - it provides the interface by which rcheevos accesses memory and determines if the fields provided by achievement, leaderboard, and rich presence definitions are meeting the criteria needed.
This commit is contained in:
LillyJadeKatrin 2023-04-15 12:28:58 -04:00
parent ed121a4033
commit 1b880564cb
2 changed files with 40 additions and 1 deletions

View File

@ -9,8 +9,10 @@
#include "Common/HttpRequest.h" #include "Common/HttpRequest.h"
#include "Common/WorkQueueThread.h" #include "Common/WorkQueueThread.h"
#include "Config/AchievementSettings.h" #include "Core/Config/AchievementSettings.h"
#include "Core/Core.h" #include "Core/Core.h"
#include "Core/PowerPC/MMU.h"
#include "Core/System.h"
#include "DiscIO/Volume.h" #include "DiscIO/Volume.h"
static constexpr bool hardcore_mode_enabled = false; static constexpr bool hardcore_mode_enabled = false;
@ -62,6 +64,7 @@ void AchievementManager::LoadGameByFilenameAsync(const std::string& iso_path,
callback(AchievementManager::ResponseType::MANAGER_NOT_INITIALIZED); callback(AchievementManager::ResponseType::MANAGER_NOT_INITIALIZED);
return; return;
} }
m_system = &Core::System::GetInstance();
struct FilereaderState struct FilereaderState
{ {
int64_t position = 0; int64_t position = 0;
@ -202,6 +205,34 @@ void AchievementManager::ActivateDeactivateRichPresence()
nullptr, 0); nullptr, 0);
} }
u32 AchievementManager::MemoryPeeker(u32 address, u32 num_bytes, void* ud)
{
if (!m_system)
return 0u;
Core::CPUThreadGuard threadguard(*m_system);
switch (num_bytes)
{
case 1:
return m_system->GetMMU()
.HostTryReadU8(threadguard, address)
.value_or(PowerPC::ReadResult<u8>(false, 0u))
.value;
case 2:
return m_system->GetMMU()
.HostTryReadU16(threadguard, address)
.value_or(PowerPC::ReadResult<u16>(false, 0u))
.value;
case 4:
return m_system->GetMMU()
.HostTryReadU32(threadguard, address)
.value_or(PowerPC::ReadResult<u32>(false, 0u))
.value;
default:
ASSERT(false);
return 0u;
}
}
void AchievementManager::AchievementEventHandler(const rc_runtime_event_t* runtime_event) void AchievementManager::AchievementEventHandler(const rc_runtime_event_t* runtime_event)
{ {
switch (runtime_event->type) switch (runtime_event->type)
@ -221,6 +252,7 @@ void AchievementManager::CloseGame()
m_game_id = 0; m_game_id = 0;
m_queue.Cancel(); m_queue.Cancel();
m_unlock_map.clear(); m_unlock_map.clear();
m_system = nullptr;
ActivateDeactivateAchievements(); ActivateDeactivateAchievements();
ActivateDeactivateLeaderboards(); ActivateDeactivateLeaderboards();
ActivateDeactivateRichPresence(); ActivateDeactivateRichPresence();

View File

@ -22,6 +22,11 @@ using AchievementId = u32;
constexpr size_t RP_SIZE = 256; constexpr size_t RP_SIZE = 256;
using RichPresence = std::array<char, RP_SIZE>; using RichPresence = std::array<char, RP_SIZE>;
namespace Core
{
class System;
}
class AchievementManager class AchievementManager
{ {
public: public:
@ -48,6 +53,7 @@ public:
void ActivateDeactivateLeaderboards(); void ActivateDeactivateLeaderboards();
void ActivateDeactivateRichPresence(); void ActivateDeactivateRichPresence();
u32 MemoryPeeker(u32 address, u32 num_bytes, void* ud);
void AchievementEventHandler(const rc_runtime_event_t* runtime_event); void AchievementEventHandler(const rc_runtime_event_t* runtime_event);
void CloseGame(); void CloseGame();
@ -80,6 +86,7 @@ private:
const std::function<int(RcResponse*, const char*)>& process_response); const std::function<int(RcResponse*, const char*)>& process_response);
rc_runtime_t m_runtime{}; rc_runtime_t m_runtime{};
Core::System* m_system{};
bool m_is_runtime_initialized = false; bool m_is_runtime_initialized = false;
std::array<char, HASH_LENGTH> m_game_hash{}; std::array<char, HASH_LENGTH> m_game_hash{};
u32 m_game_id = 0; u32 m_game_id = 0;