From 1c145ff154f11545a8b70a10e7aed53253406e3b Mon Sep 17 00:00:00 2001 From: tomcw Date: Mon, 3 Jul 2017 21:48:21 +0100 Subject: [PATCH] 1.26.3.0: Apply bounds and error checking for the joystick configuration (fixes #434) --- resource/Applewin.rc | 8 ++++---- source/Applewin.cpp | 12 ++++++++---- source/Common.h | 10 ++++++---- source/Configuration/PageInput.cpp | 12 ++++++++---- source/Configuration/PropertySheetHelper.cpp | 7 ++++++- source/Joystick.cpp | 13 +++++++++++++ source/Joystick.h | 2 +- 7 files changed, 46 insertions(+), 18 deletions(-) diff --git a/resource/Applewin.rc b/resource/Applewin.rc index 5fb94e1e..63209e84 100644 --- a/resource/Applewin.rc +++ b/resource/Applewin.rc @@ -251,8 +251,8 @@ DISK_ICON ICON "DISK.ICO" // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,26,2,4 - PRODUCTVERSION 1,26,2,4 + FILEVERSION 1,26,3,0 + PRODUCTVERSION 1,26,3,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -270,12 +270,12 @@ BEGIN VALUE "Comments", "https://github.com/AppleWin" VALUE "CompanyName", "AppleWin" VALUE "FileDescription", "Apple //e Emulator for Windows" - VALUE "FileVersion", "1, 26, 2, 4" + VALUE "FileVersion", "1, 26, 3, 0" VALUE "InternalName", "APPLEWIN" VALUE "LegalCopyright", " 1994-2017 Michael O'Brien, Oliver Schmidt, Tom Charlesworth, Michael Pohoreski, Nick Westgate, Linards Ticmanis" VALUE "OriginalFilename", "APPLEWIN.EXE" VALUE "ProductName", "Apple //e Emulator" - VALUE "ProductVersion", "1, 26, 2, 4" + VALUE "ProductVersion", "1, 26, 3, 0" END END BLOCK "VarFileInfo" diff --git a/source/Applewin.cpp b/source/Applewin.cpp index 8b948b10..c8d8ddd1 100644 --- a/source/Applewin.cpp +++ b/source/Applewin.cpp @@ -460,10 +460,10 @@ void GetProgramDirectory(void) //=========================================================================== // Backwards compatibility with AppleWin <1.24.0 -static void LoadConfigOldJoystick(const UINT uJoyNum) +static void LoadConfigOldJoystick_v1(const UINT uJoyNum) { DWORD dwOldJoyType; - if (!REGLOAD(TEXT(uJoyNum==0 ? REGVALUE_OLD_JOYSTICK0_EMU_TYPE : REGVALUE_OLD_JOYSTICK1_EMU_TYPE), &dwOldJoyType)) + if (!REGLOAD(TEXT(uJoyNum==0 ? REGVALUE_OLD_JOYSTICK0_EMU_TYPE1 : REGVALUE_OLD_JOYSTICK1_EMU_TYPE1), &dwOldJoyType)) return; // EG. Old AppleWin never installed UINT uNewJoyType; @@ -567,13 +567,17 @@ void LoadConfiguration(void) DWORD dwJoyType; if (REGLOAD(TEXT(REGVALUE_JOYSTICK0_EMU_TYPE), &dwJoyType)) JoySetJoyType(JN_JOYSTICK0, dwJoyType); + else if (REGLOAD(TEXT(REGVALUE_OLD_JOYSTICK0_EMU_TYPE2), &dwJoyType)) // GH#434 + JoySetJoyType(JN_JOYSTICK0, dwJoyType); else - LoadConfigOldJoystick(JN_JOYSTICK0); + LoadConfigOldJoystick_v1(JN_JOYSTICK0); if (REGLOAD(TEXT(REGVALUE_JOYSTICK1_EMU_TYPE), &dwJoyType)) JoySetJoyType(JN_JOYSTICK1, dwJoyType); + else if (REGLOAD(TEXT(REGVALUE_OLD_JOYSTICK1_EMU_TYPE2), &dwJoyType)) // GH#434 + JoySetJoyType(JN_JOYSTICK1, dwJoyType); else - LoadConfigOldJoystick(JN_JOYSTICK1); + LoadConfigOldJoystick_v1(JN_JOYSTICK1); DWORD dwSoundType; REGLOAD(TEXT("Sound Emulation"), &dwSoundType); diff --git a/source/Common.h b/source/Common.h index bb8215db..9e36136d 100644 --- a/source/Common.h +++ b/source/Common.h @@ -80,10 +80,12 @@ enum AppMode_e #define REGVALUE_SAVESTATE_FILENAME "Save State Filename" #define REGVALUE_SAVE_STATE_ON_EXIT "Save State On Exit" #define REGVALUE_HDD_ENABLED "Harddisk Enable" -#define REGVALUE_JOYSTICK0_EMU_TYPE "Joystick0 Emu Type" // Added at 1.24.0 (previously was "Joystick 0 Emulation") -#define REGVALUE_JOYSTICK1_EMU_TYPE "Joystick1 Emu Type" // Added at 1.24.0 (previously was "Joystick 1 Emulation") -#define REGVALUE_OLD_JOYSTICK0_EMU_TYPE "Joystick 0 Emulation" // Deprecated from 1.24.0 -#define REGVALUE_OLD_JOYSTICK1_EMU_TYPE "Joystick 1 Emulation" // Deprecated from 1.24.0 +#define REGVALUE_JOYSTICK0_EMU_TYPE "Joystick0 Emu Type v3" // GH#434: Added at 1.26.3.0 (previously was "Joystick0 Emu Type") +#define REGVALUE_JOYSTICK1_EMU_TYPE "Joystick1 Emu Type v3" // GH#434: Added at 1.26.3.0 (previously was "Joystick1 Emu Type") +#define REGVALUE_OLD_JOYSTICK0_EMU_TYPE2 "Joystick0 Emu Type" // GH#434: Deprecated from 1.26.3.0 (previously was "Joystick 0 Emulation") +#define REGVALUE_OLD_JOYSTICK1_EMU_TYPE2 "Joystick1 Emu Type" // GH#434: Deprecated from 1.26.3.0 (previously was "Joystick 1 Emulation") +#define REGVALUE_OLD_JOYSTICK0_EMU_TYPE1 "Joystick 0 Emulation" // Deprecated from 1.24.0 +#define REGVALUE_OLD_JOYSTICK1_EMU_TYPE1 "Joystick 1 Emulation" // Deprecated from 1.24.0 #define REGVALUE_PDL_XTRIM "PDL X-Trim" #define REGVALUE_PDL_YTRIM "PDL Y-Trim" #define REGVALUE_SCROLLLOCK_TOGGLE "ScrollLock Toggle" diff --git a/source/Configuration/PageInput.cpp b/source/Configuration/PageInput.cpp index 2a9c5f40..61aec80e 100644 --- a/source/Configuration/PageInput.cpp +++ b/source/Configuration/PageInput.cpp @@ -211,8 +211,12 @@ BOOL CPageInput::DlgProcInternal(HWND hWnd, UINT message, WPARAM wparam, LPARAM void CPageInput::DlgOK(HWND hWnd) { - const UINT uNewJoyType0 = SendDlgItemMessage(hWnd, IDC_JOYSTICK0, CB_GETCURSEL, 0, 0); - const UINT uNewJoyType1 = SendDlgItemMessage(hWnd, IDC_JOYSTICK1, CB_GETCURSEL, 0, 0); + UINT uNewJoyType0 = SendDlgItemMessage(hWnd, IDC_JOYSTICK0, CB_GETCURSEL, 0, 0); + if (uNewJoyType0 >= J0C_MAX) uNewJoyType0 = 0; // GH#434 + + UINT uNewJoyType1 = SendDlgItemMessage(hWnd, IDC_JOYSTICK1, CB_GETCURSEL, 0, 0); + if (uNewJoyType1 >= J1C_MAX) uNewJoyType1 = 0; // GH#434 + const bool bIsSlot4Mouse = m_PropertySheetHelper.GetConfigNew().m_Slot[4] == CT_MouseInterface; if (JoySetEmulationType(hWnd, m_nJoy0ChoiceTranlationTbl[uNewJoyType0], JN_JOYSTICK0, bIsSlot4Mouse)) @@ -306,9 +310,9 @@ void CPageInput::InitJoystickChoices(HWND hWnd, int nJoyNum, int nIdcValue) // . the other Joystick type (if it exists) from this new list // . the mouse if the mousecard is plugged in int removedItemCompensation = 0; - for(UINT i=nJC_KEYBD_CURSORS; i JN_JOYSTICK1) return; + if (num == JN_JOYSTICK0) // GH#434 + { + _ASSERT(type < J0C_MAX); + if (type >= J0C_MAX) + return; + } + else + { + _ASSERT(type < J1C_MAX); + if (type >= J1C_MAX) + return; + } + joytype[num] = type; // Refresh centre positions whenever 'joytype' changes diff --git a/source/Joystick.h b/source/Joystick.h index b92c9f8f..97515c44 100644 --- a/source/Joystick.h +++ b/source/Joystick.h @@ -3,7 +3,7 @@ enum JOYNUM {JN_JOYSTICK0=0, JN_JOYSTICK1}; enum JOY0CHOICE {J0C_DISABLED=0, J0C_JOYSTICK1, J0C_KEYBD_CURSORS, J0C_KEYBD_NUMPAD, J0C_MOUSE, J0C_MAX}; -enum JOY1CHOICE {J1C_DISABLED=0, J1C_JOYSTICK2, J1C_KEYBD_CURSORS, J1C_KEYBD_NUMPAD, J1C_MOUSE, J0C_JOYSTICK1_THUMBSTICK2, J1C_MAX}; +enum JOY1CHOICE {J1C_DISABLED=0, J1C_JOYSTICK2, J1C_KEYBD_CURSORS, J1C_KEYBD_NUMPAD, J1C_MOUSE, J1C_JOYSTICK1_THUMBSTICK2, J1C_MAX}; enum {JOYSTICK_MODE_FLOATING=0, JOYSTICK_MODE_CENTERING}; // Joystick centering control