From 54dbe01aa5a9b8b10a3fc67bb19731b754f6852b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Zumer?= Date: Tue, 16 Jul 2019 18:31:10 -0400 Subject: [PATCH 1/2] Squashed 'RAppleWin/' changes from 0131740b3..a43a5f280 a43a5f280 Set is_initialized correctly in RetroAchievements.cpp 10138ffe6 Update the RA window handle on system change 1849b3127 Update RAIntegration to 0.76.1 ec83e5c59 Do not propagate overlay input while out of focus 53d898695 Check for safe loaded file data initialization with RA 8cb546d8d Fix narrowing cast warnings for RA memory offsets git-subtree-dir: RAppleWin git-subtree-split: a43a5f2807ee41fdfb071eeacada72a390e34016 --- RAIntegration | 2 +- source/Applewin.cpp | 6 +++-- source/Frame.cpp | 2 +- source/Frame.h | 1 + source/RetroAchievements.cpp | 50 +++++++++++++++++++++++++----------- 5 files changed, 42 insertions(+), 19 deletions(-) diff --git a/RAIntegration b/RAIntegration index d0808881..b101ed7a 160000 --- a/RAIntegration +++ b/RAIntegration @@ -1 +1 @@ -Subproject commit d08088818055baafafea7c1ddc0f035115778ac6 +Subproject commit b101ed7a05f3710c9937897b6cadacae6bb745bf diff --git a/source/Applewin.cpp b/source/Applewin.cpp index 2f7cc7d5..614ce4e5 100644 --- a/source/Applewin.cpp +++ b/source/Applewin.cpp @@ -1766,9 +1766,11 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) bSetFullScreen = g_bRestartFullScreen; g_bRestartFullScreen = false; } - #if USE_RETROACHIEVEMENTS - RA_Shutdown(); + else + { + RA_Shutdown(); + } #endif MB_Reset(); diff --git a/source/Frame.cpp b/source/Frame.cpp index ee7cfb1c..15674923 100644 --- a/source/Frame.cpp +++ b/source/Frame.cpp @@ -172,7 +172,7 @@ static FULLSCREEN_SCALE_TYPE g_win_fullscreen_scale = 1; static int g_win_fullscreen_offsetx = 0; static int g_win_fullscreen_offsety = 0; -static bool g_bFrameActive = false; +bool g_bFrameActive = false; // __ Prototypes __________________________________________________________________________________ void DrawCrosshairs (int x, int y); diff --git a/source/Frame.h b/source/Frame.h index d3a156d6..0aa84a10 100644 --- a/source/Frame.h +++ b/source/Frame.h @@ -9,6 +9,7 @@ extern int g_nViewportCY; extern BOOL g_bConfirmReboot; // saved PageConfig REGSAVE extern BOOL g_bMultiMon; + extern bool g_bFrameActive; // Emulator diff --git a/source/RetroAchievements.cpp b/source/RetroAchievements.cpp index 60c7c17e..963e5640 100644 --- a/source/RetroAchievements.cpp +++ b/source/RetroAchievements.cpp @@ -1,5 +1,6 @@ #if USE_RETROACHIEVEMENTS +#include #include #include "RetroAchievements.h" @@ -48,23 +49,27 @@ void free_file_info(FileInfo *file) unsigned char MainRAMReader(size_t nOffs) { - return *MemGetMainPtr(nOffs); + assert(nOffs <= 0xFFFF); + return *MemGetMainPtr((WORD)nOffs); } void MainRAMWriter(size_t nOffs, unsigned char nVal) { - *MemGetMainPtr(nOffs) = nVal; + assert(nOffs <= 0xFFFF); + *MemGetMainPtr((WORD)nOffs) = nVal; } #if RA_ENABLE_AUXRAM unsigned char AuxRAMReader(size_t nOffs) { - return *MemGetAuxPtr(nOffs); + assert(nOffs <= 0xFFFF); + return *MemGetAuxPtr((WORD)nOffs); } void AuxRAMWriter(size_t nOffs, unsigned char nVal) { - *MemGetAuxPtr(nOffs) = nVal; + assert(nOffs <= 0xFFFF); + *MemGetAuxPtr((WORD)nOffs) = nVal; } #endif @@ -161,9 +166,17 @@ void RA_InitShared() void RA_InitSystem() { - RA_Init(g_hFrameWindow, RA_AppleWin, RAPPLEWIN_VERSION_SHORT); - RA_InitShared(); - RA_AttemptLogin(true); + if (is_initialized) + { + RA_UpdateHWnd(g_hFrameWindow); + } + else + { + RA_Init(g_hFrameWindow, RA_AppleWin, RAPPLEWIN_VERSION_SHORT); + RA_InitShared(); + RA_AttemptLogin(true); + is_initialized = true; + } confirmed_quitting = false; } @@ -217,6 +230,9 @@ int RA_PrepareLoadNewRom(const char *file_name, FileType file_type) loading_file.data_len = file_size; BYTE * const file_data = (BYTE *)malloc(file_size * sizeof(BYTE)); + if (!file_data) + return FALSE; + loading_file.data = file_data; fseek(f, 0, SEEK_SET); fread(file_data, sizeof(BYTE), file_size, f); @@ -392,14 +408,18 @@ void RA_RenderOverlayFrame(HDC hdc) int width = GetFrameBufferBorderlessWidth(), height = GetFrameBufferBorderlessHeight(); RECT window_size = { 0, 0, width, height }; - ControllerInput input; - input.m_bConfirmPressed = GetKeyState(VK_RETURN) & WM_KEYDOWN; - input.m_bCancelPressed = GetKeyState(VK_BACK) & WM_KEYDOWN; - input.m_bQuitPressed = GetKeyState(VK_ESCAPE) & WM_KEYDOWN; - input.m_bLeftPressed = GetKeyState(VK_LEFT) & WM_KEYDOWN; - input.m_bRightPressed = GetKeyState(VK_RIGHT) & WM_KEYDOWN; - input.m_bUpPressed = GetKeyState(VK_UP) & WM_KEYDOWN; - input.m_bDownPressed = GetKeyState(VK_DOWN) & WM_KEYDOWN; + ControllerInput input = {}; + + if (g_bFrameActive) // Do not process input while out of focus + { + input.m_bConfirmPressed = GetKeyState(VK_RETURN) & WM_KEYDOWN; + input.m_bCancelPressed = GetKeyState(VK_BACK) & WM_KEYDOWN; + input.m_bQuitPressed = GetKeyState(VK_ESCAPE) & WM_KEYDOWN; + input.m_bLeftPressed = GetKeyState(VK_LEFT) & WM_KEYDOWN; + input.m_bRightPressed = GetKeyState(VK_RIGHT) & WM_KEYDOWN; + input.m_bUpPressed = GetKeyState(VK_UP) & WM_KEYDOWN; + input.m_bDownPressed = GetKeyState(VK_DOWN) & WM_KEYDOWN; + } RA_UpdateRenderOverlay(hdc, &input, delta_time, &window_size, IsFullScreen(), g_nAppMode == MODE_PAUSED); From c293b525dc6a9578d203a5364f9058d327c0c11e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Zumer?= Date: Tue, 16 Jul 2019 18:32:33 -0400 Subject: [PATCH 2/2] Update RAIntegration to 0.76.1 --- RA_Integration | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RA_Integration b/RA_Integration index 8baa8494..b101ed7a 160000 --- a/RA_Integration +++ b/RA_Integration @@ -1 +1 @@ -Subproject commit 8baa8494f81c59cb9af15bd8be104fd03ff9ade0 +Subproject commit b101ed7a05f3710c9937897b6cadacae6bb745bf