Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RAIntegration fixes #19007

Merged
merged 3 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ static const ConfigSetting achievementSettings[] = {
// Core settings
ConfigSetting("AchievementsEnable", &g_Config.bAchievementsEnable, true, CfgFlag::DEFAULT),
ConfigSetting("AchievementsEnableRAIntegration", &g_Config.bAchievementsEnableRAIntegration, false, CfgFlag::DEFAULT),
ConfigSetting("AchievementsChallengeMode", &g_Config.bAchievementsChallengeMode, true, CfgFlag::PER_GAME | CfgFlag::DEFAULT),
ConfigSetting("AchievementsChallengeMode", &g_Config.bAchievementsHardcoreMode, true, CfgFlag::PER_GAME | CfgFlag::DEFAULT),
ConfigSetting("AchievementsEncoreMode", &g_Config.bAchievementsEncoreMode, false, CfgFlag::PER_GAME | CfgFlag::DEFAULT),
ConfigSetting("AchievementsUnofficial", &g_Config.bAchievementsUnofficial, false, CfgFlag::PER_GAME | CfgFlag::DEFAULT),
ConfigSetting("AchievementsLogBadMemReads", &g_Config.bAchievementsLogBadMemReads, false, CfgFlag::DEFAULT),
Expand Down
2 changes: 1 addition & 1 deletion Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ struct Config {
// Retro Achievement settings
// Copied from Duckstation, we might want to remove some.
bool bAchievementsEnable;
bool bAchievementsChallengeMode;
bool bAchievementsHardcoreMode;
bool bAchievementsEncoreMode;
bool bAchievementsUnofficial;
bool bAchievementsSoundEffects;
Expand Down
28 changes: 18 additions & 10 deletions Core/RetroAchievements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,15 @@ bool IsActive() {
return GetGameID() != 0;
}

static void raintegration_write_memory_handler(uint32_t address, uint8_t *buffer, uint32_t num_bytes, rc_client_t *client) {
// convert_retroachievements_address_to_real_address
uint32_t realAddress = address + PSP_MEMORY_OFFSET;
uint8_t *writePtr = Memory::GetPointerWriteRange(realAddress, num_bytes);
if (writePtr) {
memcpy(writePtr, buffer, num_bytes);
}
}

static uint32_t read_memory_callback(uint32_t address, uint8_t *buffer, uint32_t num_bytes, rc_client_t *client) {
// Achievements are traditionally defined relative to the base of main memory of the emulated console.
// This is some kind of RetroArch-related legacy. In the PSP's case, this is simply a straight offset of 0x08000000.
Expand Down Expand Up @@ -483,14 +492,7 @@ static void raintegration_get_game_name_handler(char *buffer, uint32_t buffer_si
snprintf(buffer, buffer_size, "%s", g_gamePath.GetFilename().c_str());
}

static void raintegration_write_memory_handler(uint32_t address, uint8_t *buffer, uint32_t num_bytes, rc_client_t *client) {
// convert_retroachievements_address_to_real_address
uint32_t realAddress = address + PSP_MEMORY_OFFSET;
uint8_t *writePtr = Memory::GetPointerWriteRange(address, num_bytes);
if (writePtr) {
memcpy(writePtr, buffer, num_bytes);
}
}
static void raintegration_write_memory_handler(uint32_t address, uint8_t *buffer, uint32_t num_bytes, rc_client_t *client);

static void raintegration_event_handler(const rc_client_raintegration_event_t *event, rc_client_t *client) {
switch (event->type) {
Expand All @@ -507,7 +509,7 @@ static void raintegration_event_handler(const rc_client_raintegration_event_t *e
// Hardcore mode has been changed (either directly by the user, or disabled through the use of the tools).
// The frontend doesn't necessarily need to know that this value changed, they can still query it whenever
// it's appropriate, but the event lets the frontend do things like enable/disable rewind or cheats.
// handle_hardcore_changed();
g_Config.bAchievementsHardcoreMode = rc_client_get_hardcore_enabled(client);
break;
default:
ERROR_LOG(ACHIEVEMENTS, "Unsupported raintegration event %u\n", event->type);
Expand All @@ -530,6 +532,7 @@ static void load_integration_callback(int result, const char *error_message, rc_
rc_client_raintegration_set_get_game_name_function(g_rcClient, &raintegration_get_game_name_handler);
HWND hWnd = (HWND)userdata;
rc_client_raintegration_rebuild_submenu(g_rcClient, GetMenu(hWnd));
DrawMenuBar(hWnd);
break;
}
case RC_MISSING_VALUE:
Expand Down Expand Up @@ -576,6 +579,11 @@ void Initialize() {

rc_client_set_event_handler(g_rcClient, event_handler_callback);

// Set initial settings properly. Hardcore mode is checked by RAIntegration.
rc_client_set_hardcore_enabled(g_rcClient, g_Config.bAchievementsHardcoreMode ? 1 : 0);
rc_client_set_encore_mode_enabled(g_rcClient, g_Config.bAchievementsEncoreMode ? 1 : 0);
rc_client_set_unofficial_enabled(g_rcClient, g_Config.bAchievementsUnofficial ? 1 : 0);

#ifdef RC_CLIENT_SUPPORTS_RAINTEGRATION
if (g_Config.bAchievementsEnableRAIntegration) {
wchar_t szFilePath[MAX_PATH];
Expand Down Expand Up @@ -961,7 +969,7 @@ void SetGame(const Path &path, IdentifiedFileType fileType, FileLoader *fileLoad
}

// Apply pre-load settings.
rc_client_set_hardcore_enabled(g_rcClient, g_Config.bAchievementsChallengeMode ? 1 : 0);
rc_client_set_hardcore_enabled(g_rcClient, g_Config.bAchievementsHardcoreMode ? 1 : 0);
rc_client_set_encore_mode_enabled(g_rcClient, g_Config.bAchievementsEncoreMode ? 1 : 0);
rc_client_set_unofficial_enabled(g_rcClient, g_Config.bAchievementsUnofficial ? 1 : 0);

Expand Down
2 changes: 1 addition & 1 deletion UI/RetroAchievementScreens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ void RetroAchievementsSettingsScreen::CreateAccountTab(UI::ViewGroup *viewGroup)
RecreateViews();
return UI::EVENT_DONE;
});
viewGroup->Add(new CheckBox(&g_Config.bAchievementsChallengeMode, ac->T("Hardcore Mode (no savestates)")))->SetEnabledPtr(&g_Config.bAchievementsEnable);
viewGroup->Add(new CheckBox(&g_Config.bAchievementsHardcoreMode, ac->T("Hardcore Mode (no savestates)")))->SetEnabledPtr(&g_Config.bAchievementsEnable);
viewGroup->Add(new CheckBox(&g_Config.bAchievementsSoundEffects, ac->T("Sound Effects")))->SetEnabledPtr(&g_Config.bAchievementsEnable); // not yet implemented

viewGroup->Add(new ItemHeader(di->T("Links")));
Expand Down
5 changes: 3 additions & 2 deletions Windows/Debugger/Debugger_Disasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,9 +676,10 @@ BOOL CDisasm::DlgProc(UINT message, WPARAM wParam, LPARAM lParam)
Show(false);
return TRUE;
case WM_ACTIVATE:
if (wParam == WA_ACTIVE || wParam == WA_CLICKACTIVE)
{
if (wParam == WA_ACTIVE || wParam == WA_CLICKACTIVE) {
g_activeWindow = WINDOW_CPUDEBUGGER;
} else {
g_activeWindow = WINDOW_OTHER;
}
break;

Expand Down
2 changes: 2 additions & 0 deletions Windows/GEDebugger/GEDebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,8 @@ BOOL CGEDebugger::DlgProc(UINT message, WPARAM wParam, LPARAM lParam) {
case WM_ACTIVATE:
if (wParam == WA_ACTIVE || wParam == WA_CLICKACTIVE) {
g_activeWindow = WINDOW_GEDEBUGGER;
} else {
g_activeWindow = WINDOW_OTHER;
}
break;

Expand Down
8 changes: 2 additions & 6 deletions Windows/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,12 +599,6 @@ namespace MainWindow
static bool firstErase = true;

switch (message) {
case WM_ACTIVATE:
if (wParam == WA_ACTIVE || wParam == WA_CLICKACTIVE) {
g_activeWindow = WINDOW_MAINWINDOW;
}
break;

case WM_SIZE:
break;

Expand Down Expand Up @@ -829,6 +823,8 @@ namespace MainWindow
}
g_activeWindow = WINDOW_MAINWINDOW;
pause = false;
} else {
g_activeWindow = WINDOW_OTHER;
}
if (!noFocusPause && g_Config.bPauseOnLostFocus && GetUIState() == UISTATE_INGAME) {
if (pause != Core_IsStepping()) { // != is xor for bools
Expand Down
2 changes: 1 addition & 1 deletion Windows/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ extern CGEDebugger* geDebuggerWindow;

extern int g_activeWindow;

enum { WINDOW_MAINWINDOW, WINDOW_CPUDEBUGGER, WINDOW_GEDEBUGGER };
enum { WINDOW_MAINWINDOW, WINDOW_CPUDEBUGGER, WINDOW_GEDEBUGGER, WINDOW_OTHER };
Loading