From 891e43878b7b531ad0bd56d1db6a4c0226989f09 Mon Sep 17 00:00:00 2001 From: oddMLan Date: Sun, 9 Feb 2020 04:25:05 -0700 Subject: [PATCH 1/3] [Nrage-input] Code cleanup - Defined NOMINMAX macro to disable windef.h's min/max macros; they were clashing with the C++ standard library's std::min/std::max. - All uses of min/max that had ambiguous type deduction were explicitly instantiated as min and max. - Header includes were sorted Many thanks to DKO for the patch. --- Source/nragev20/Debug.cpp | 3 ++- Source/nragev20/DirectInput.cpp | 29 +++++++++++++++++------------ Source/nragev20/DirectInput.h | 2 ++ Source/nragev20/FileAccess.cpp | 17 ++++++++++------- Source/nragev20/FileAccess.h | 4 +++- Source/nragev20/GBCart.cpp | 5 +++-- Source/nragev20/GBCart.h | 3 ++- Source/nragev20/Interface.cpp | 12 +++++++----- Source/nragev20/International.cpp | 10 ++++++---- Source/nragev20/International.h | 3 ++- Source/nragev20/NRagePluginV2.cpp | 4 +++- Source/nragev20/NRagePluginV2.h | 1 + Source/nragev20/PakIO.cpp | 16 +++++++++++----- Source/nragev20/PakIO.h | 12 ------------ Source/nragev20/commonIncludes.h | 5 ++++- 15 files changed, 73 insertions(+), 53 deletions(-) diff --git a/Source/nragev20/Debug.cpp b/Source/nragev20/Debug.cpp index 5e41dcb83..4e3851eb2 100644 --- a/Source/nragev20/Debug.cpp +++ b/Source/nragev20/Debug.cpp @@ -21,8 +21,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "commonIncludes.h" #include + +#include "commonIncludes.h" #include "FileAccess.h" bool bDebug = true; diff --git a/Source/nragev20/DirectInput.cpp b/Source/nragev20/DirectInput.cpp index 0169984b4..dbd3440c9 100644 --- a/Source/nragev20/DirectInput.cpp +++ b/Source/nragev20/DirectInput.cpp @@ -21,16 +21,21 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include +#include #include -#include "commonIncludes.h" +#include #include + +#include "commonIncludes.h" +#include "DirectInput.h" #include "NRagePluginV2.h" #include "PakIO.h" -#include "DirectInput.h" #include "XInputController.h" -#include -#include + +using std::min; +using std::max; // ProtoTypes // HRESULT AcquireDevice( LPDIRECTINPUTDEVICE8 lpDirectInputDevice ); @@ -377,7 +382,7 @@ bool GetNControllerInput ( const int indexController, LPDWORD pdwData ) { if( pcController->wAxeBuffer[i] < MAXAXISVALUE ) { - l_Value = pcController->wAxeBuffer[i] = min(( pcController->wAxeBuffer[i] + N64DIVIDER*3), MAXAXISVALUE ); + l_Value = pcController->wAxeBuffer[i] = min(( pcController->wAxeBuffer[i] + N64DIVIDER*3), MAXAXISVALUE ); } else l_Value = MAXAXISVALUE; @@ -386,7 +391,7 @@ bool GetNControllerInput ( const int indexController, LPDWORD pdwData ) { if( pcController->wAxeBuffer[i] < MAXAXISVALUE ) { - l_Value = pcController->wAxeBuffer[i] = min(( pcController->wAxeBuffer[i] * 2 + N64DIVIDER*5 ), MAXAXISVALUE ); + l_Value = pcController->wAxeBuffer[i] = min(( pcController->wAxeBuffer[i] * 2 + N64DIVIDER*5 ), MAXAXISVALUE ); } else l_Value = MAXAXISVALUE; @@ -430,7 +435,7 @@ bool GetNControllerInput ( const int indexController, LPDWORD pdwData ) // wAxeBuffer is negative for axes 1 and 2 if buffer remains, else zero if(( pcController->bMouseMoveX == MM_ABS && i < 2 ) || ( pcController->bMouseMoveY == MM_ABS && i > 1 )) - pcController->wAxeBuffer[i] = min( max( MINAXISVALUE, pcController->wAxeBuffer[i]) , MAXAXISVALUE); + pcController->wAxeBuffer[i] = min( max( MINAXISVALUE, pcController->wAxeBuffer[i]) , MAXAXISVALUE); else if (( pcController->bMouseMoveX == MM_BUFF && i < 2 ) || ( pcController->bMouseMoveY == MM_BUFF && i > 1 )) pcController->wAxeBuffer[i] = pcController->wAxeBuffer[i] * MOUSEBUFFERDECAY / 100; else // "deadpan" mouse @@ -542,14 +547,14 @@ bool GetNControllerInput ( const int indexController, LPDWORD pdwData ) double dRel = MAXAXISVALUE / dRangeDiagonal; *pdwData = MAKELONG(w_Buttons, - MAKEWORD( (BYTE)(min( max( MINAXISVALUE, (long)(lAxisValueX * d_ModifierX * dRel )), MAXAXISVALUE) / N64DIVIDER ), - (BYTE)(min( max( MINAXISVALUE, (long)(lAxisValueY * d_ModifierY * dRel )), MAXAXISVALUE) / N64DIVIDER ))); + MAKEWORD( (BYTE)(min( max( MINAXISVALUE, (long)(lAxisValueX * d_ModifierX * dRel )), MAXAXISVALUE) / N64DIVIDER ), + (BYTE)(min( max( MINAXISVALUE, (long)(lAxisValueY * d_ModifierY * dRel )), MAXAXISVALUE) / N64DIVIDER ))); } else { *pdwData = MAKELONG(w_Buttons, - MAKEWORD( (BYTE)(min( max( MINAXISVALUE, (long)(lAxisValueX * d_ModifierX )), MAXAXISVALUE) / N64DIVIDER ), - (BYTE)(min( max( MINAXISVALUE, (long)(lAxisValueY * d_ModifierY )), MAXAXISVALUE) / N64DIVIDER ))); + MAKEWORD( (BYTE)(min( max( MINAXISVALUE, (long)(lAxisValueX * d_ModifierX )), MAXAXISVALUE) / N64DIVIDER ), + (BYTE)(min( max( MINAXISVALUE, (long)(lAxisValueY * d_ModifierY )), MAXAXISVALUE) / N64DIVIDER ))); } return true; @@ -887,7 +892,7 @@ bool CreateEffectHandle( HWND hWnd, LPDIRECTINPUTDEVICE8 lpDirectInputDevice, LP if( nAxes == 0 ) return false; - nAxes = min( nAxes, 2 ); + nAxes = min( nAxes, 2 ); // Must be unaquired for setting stuff like Co-op Level diff --git a/Source/nragev20/DirectInput.h b/Source/nragev20/DirectInput.h index b659dac82..19491a595 100644 --- a/Source/nragev20/DirectInput.h +++ b/Source/nragev20/DirectInput.h @@ -26,6 +26,8 @@ #include +#include "NRagePluginV2.h" + extern LPDIRECTINPUT8 g_pDIHandle; diff --git a/Source/nragev20/FileAccess.cpp b/Source/nragev20/FileAccess.cpp index ef9dbdd2c..990e09185 100644 --- a/Source/nragev20/FileAccess.cpp +++ b/Source/nragev20/FileAccess.cpp @@ -21,18 +21,21 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "commonIncludes.h" +#include +#include + #include #include -#include -#include #include +#include + +#include "commonIncludes.h" +#include "DirectInput.h" +#include "FileAccess.h" +#include "Interface.h" #include "NRagePluginV2.h" #include "PakIO.h" -#include "Interface.h" -#include "FileAccess.h" -#include "DirectInput.h" -#include + using std::string; #ifndef IDR_PROFILE_DEFAULT1 diff --git a/Source/nragev20/FileAccess.h b/Source/nragev20/FileAccess.h index e9159ebc9..4ab8d2565 100644 --- a/Source/nragev20/FileAccess.h +++ b/Source/nragev20/FileAccess.h @@ -24,9 +24,11 @@ #ifndef _FILEACCESS_H_ #define _FILEACCESS_H_ +#include + #include "NRagePluginV2.h" #include "Version.h" -#include + using std::string; bool GetDirectory( LPTSTR pszDirectory, WORD wDirID ); diff --git a/Source/nragev20/GBCart.cpp b/Source/nragev20/GBCart.cpp index 84f1e0176..ec0d11073 100644 --- a/Source/nragev20/GBCart.cpp +++ b/Source/nragev20/GBCart.cpp @@ -10,11 +10,12 @@ ** */ -#include "commonIncludes.h" #include + +#include "commonIncludes.h" +#include "GBCart.h" #include "NRagePluginV2.h" #include "PakIO.h" -#include "GBCart.h" void ClearData(BYTE *Data, int Length); diff --git a/Source/nragev20/GBCart.h b/Source/nragev20/GBCart.h index 529b9dbeb..543bc757e 100644 --- a/Source/nragev20/GBCart.h +++ b/Source/nragev20/GBCart.h @@ -1,9 +1,10 @@ #ifndef _GBCART_H_ #define _GBCART_H_ -#include #include +#include + typedef struct _gbCartRTC { UINT mapperSeconds; UINT mapperMinutes; diff --git a/Source/nragev20/Interface.cpp b/Source/nragev20/Interface.cpp index 2ac93f68e..ac8e82572 100644 --- a/Source/nragev20/Interface.cpp +++ b/Source/nragev20/Interface.cpp @@ -21,18 +21,20 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "commonIncludes.h" +#include + #include #include -#include -#include "NRagePluginV2.h" + +#include "commonIncludes.h" #include "DirectInput.h" -#include "XInputController.h" #include "FileAccess.h" -#include "PakIO.h" #include "Interface.h" #include "International.h" +#include "NRagePluginV2.h" +#include "PakIO.h" #include "Version.h" +#include "XInputController.h" // Prototypes // BOOL CALLBACK ControllerTabProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ); diff --git a/Source/nragev20/International.cpp b/Source/nragev20/International.cpp index 631973a36..5aa0ac3ce 100644 --- a/Source/nragev20/International.cpp +++ b/Source/nragev20/International.cpp @@ -23,12 +23,14 @@ // Internationalization routines go in this file. -#include "International.h" -#include -#include #include #include -#include "debug.h" + +#include +#include + +#include "International.h" +#include "Debug.h" LANGID GetNTDLLNativeLangID(); BOOL IsHongKongVersion(); diff --git a/Source/nragev20/International.h b/Source/nragev20/International.h index 54243ba87..abac85e56 100644 --- a/Source/nragev20/International.h +++ b/Source/nragev20/International.h @@ -21,9 +21,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "settings.h" #include +#include "settings.h" + #ifndef _NRINTERNATIONAL_ #define _NRINTERNATIONAL_ diff --git a/Source/nragev20/NRagePluginV2.cpp b/Source/nragev20/NRagePluginV2.cpp index c2054de72..a69bcd95b 100644 --- a/Source/nragev20/NRagePluginV2.cpp +++ b/Source/nragev20/NRagePluginV2.cpp @@ -21,11 +21,13 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "commonIncludes.h" #include #include #include #include + +#include "commonIncludes.h" + #include "NRagePluginV2.h" #include "Interface.h" #include "FileAccess.h" diff --git a/Source/nragev20/NRagePluginV2.h b/Source/nragev20/NRagePluginV2.h index 77695aed3..52fc95f3e 100644 --- a/Source/nragev20/NRagePluginV2.h +++ b/Source/nragev20/NRagePluginV2.h @@ -24,6 +24,7 @@ #define _NRAGEPLUGIN_ #include + #include "XInputController.h" ///////////////////////////////////////////////////////////////////////////////// diff --git a/Source/nragev20/PakIO.cpp b/Source/nragev20/PakIO.cpp index 85c5e909f..7be39855d 100644 --- a/Source/nragev20/PakIO.cpp +++ b/Source/nragev20/PakIO.cpp @@ -21,17 +21,23 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "commonIncludes.h" +#include +#include + #include #include #include -#include -#include "NRagePluginV2.h" + +#include "commonIncludes.h" #include "DirectInput.h" -#include "Interface.h" #include "FileAccess.h" -#include "PakIO.h" #include "GBCart.h" +#include "Interface.h" +#include "NRagePluginV2.h" +#include "PakIO.h" + +using std::min; +using std::max; // ProtoTypes BYTE AddressCRC( const unsigned char * Address ); diff --git a/Source/nragev20/PakIO.h b/Source/nragev20/PakIO.h index 9e5fa86d1..3def49a86 100644 --- a/Source/nragev20/PakIO.h +++ b/Source/nragev20/PakIO.h @@ -170,16 +170,4 @@ typedef struct _ADAPTOIDPAK bool fRumblePak; } ADAPTOIDPAK, *LPADAPTOIDPAK; -/* - * from under with MSVC defines these macros. - * For some reason, they are unavailable with MinGW's copy of . - */ -#ifndef max -#define max(a, b) (((a) > (b)) ? (a) : (b)) -#endif - -#ifndef min -#define min(a, b) (((a) < (b)) ? (a) : (b)) -#endif - #endif // #ifndef _PAKIO_H_ diff --git a/Source/nragev20/commonIncludes.h b/Source/nragev20/commonIncludes.h index d06df2c2e..e5bc55ab7 100644 --- a/Source/nragev20/commonIncludes.h +++ b/Source/nragev20/commonIncludes.h @@ -24,11 +24,14 @@ #ifndef _COMMONINCLUDES_H_ #define _COMMONINCLUDES_H_ +/* #undef WIN32_LEAN_AND_MEAN #pragma warning(disable:4201) +*/ + +#include #include "settings.h" -#include #include "resource.h" #include "Debug.h" From 2b15003e77ac1906b0ba0ba9d4ecd89a8b052a3e Mon Sep 17 00:00:00 2001 From: oddMLan Date: Sun, 9 Feb 2020 04:36:49 -0700 Subject: [PATCH 2/3] [Nrage-input] Tabs -> spaces --- .../ControllerSpecs/Controller #1.1.h | 380 +- Source/nragev20/Debug.cpp | 168 +- Source/nragev20/Debug.h | 20 +- Source/nragev20/DirectInput.cpp | 1842 ++--- Source/nragev20/DirectInput.h | 124 +- Source/nragev20/FileAccess.cpp | 2724 +++---- Source/nragev20/FileAccess.h | 172 +- Source/nragev20/GBCart.cpp | 2220 +++--- Source/nragev20/GBCart.h | 62 +- Source/nragev20/Interface.cpp | 6578 ++++++++--------- Source/nragev20/Interface.h | 84 +- Source/nragev20/International.cpp | 166 +- Source/nragev20/International.h | 14 +- Source/nragev20/NRagePluginV2.cpp | 1776 ++--- Source/nragev20/NRagePluginV2.h | 452 +- Source/nragev20/PakIO.cpp | 2370 +++--- Source/nragev20/PakIO.h | 150 +- Source/nragev20/XInputController.cpp | 1172 +-- Source/nragev20/XInputController.h | 114 +- Source/nragev20/commonIncludes.h | 10 +- Source/nragev20/resource.h | 4 +- Source/nragev20/settings.h | 54 +- 22 files changed, 10328 insertions(+), 10328 deletions(-) diff --git a/Source/nragev20/ControllerSpecs/Controller #1.1.h b/Source/nragev20/ControllerSpecs/Controller #1.1.h index b1bae5bec..7fbc27219 100644 --- a/Source/nragev20/ControllerSpecs/Controller #1.1.h +++ b/Source/nragev20/ControllerSpecs/Controller #1.1.h @@ -12,179 +12,179 @@ http://www.emutalk.net/cgi-bin/ikonboard/ikonboard.cgi?s=3bd272222f66ffff;act=SF extern "C" { #endif - /* Note: BOOL, BYTE, WORD, DWORD, TRUE, FALSE are defined in windows.h */ + /* Note: BOOL, BYTE, WORD, DWORD, TRUE, FALSE are defined in windows.h */ -#define PLUGIN_TYPE_CONTROLLER 4 +#define PLUGIN_TYPE_CONTROLLER 4 #ifndef SPECS_VERSION #define SPECS_VERSION 0x0101 #endif - /*** Conteroller plugin's ****/ -#define PLUGIN_NONE 1 -#define PLUGIN_MEMPAK 2 - // not implemeted for non raw data -#define PLUGIN_RUMBLE_PAK 3 - // not implemeted for non raw data -#define PLUGIN_TRANSFER_PAK 4 - // the controller plugin is passed in raw data -#define PLUGIN_RAW 5 + /*** Conteroller plugin's ****/ +#define PLUGIN_NONE 1 +#define PLUGIN_MEMPAK 2 + // not implemeted for non raw data +#define PLUGIN_RUMBLE_PAK 3 + // not implemeted for non raw data +#define PLUGIN_TRANSFER_PAK 4 + // the controller plugin is passed in raw data +#define PLUGIN_RAW 5 - /********************************************************************************* - Note about Conteroller plugin's: - the rumble pak needs a function for the force feed back joystick and tranfer pak - probaly needs a function for the plugin to be able to select the GB rom and - eeprom... maybe this should be done by the emu instead of the plugin, but I think - it probaly should be done by the plugin. I will see about adding these functions - in the next spec - **********************************************************************************/ + /********************************************************************************* + Note about Conteroller plugin's: + the rumble pak needs a function for the force feed back joystick and tranfer pak + probaly needs a function for the plugin to be able to select the GB rom and + eeprom... maybe this should be done by the emu instead of the plugin, but I think + it probaly should be done by the plugin. I will see about adding these functions + in the next spec + **********************************************************************************/ -#define EXPORT __declspec(dllexport) -#define CALL _cdecl +#define EXPORT __declspec(dllexport) +#define CALL _cdecl - /***** Structures *****/ - typedef struct - { - WORD Version; /* Should be set to 0x0101 */ - WORD Type; /* Set to PLUGIN_TYPE_CONTROLLER */ - char Name[100]; /* Name of the DLL */ - BOOL Reserved1; - BOOL Reserved2; - } PLUGIN_INFO; + /***** Structures *****/ + typedef struct + { + WORD Version; /* Should be set to 0x0101 */ + WORD Type; /* Set to PLUGIN_TYPE_CONTROLLER */ + char Name[100]; /* Name of the DLL */ + BOOL Reserved1; + BOOL Reserved2; + } PLUGIN_INFO; - typedef struct - { - BOOL Present; - BOOL RawData; - int Plugin; - } CONTROL; + typedef struct + { + BOOL Present; + BOOL RawData; + int Plugin; + } CONTROL; - typedef union - { - DWORD Value; - struct - { - unsigned R_DPAD : 1; - unsigned L_DPAD : 1; - unsigned D_DPAD : 1; - unsigned U_DPAD : 1; - unsigned START_BUTTON : 1; - unsigned Z_TRIG : 1; - unsigned B_BUTTON : 1; - unsigned A_BUTTON : 1; + typedef union + { + DWORD Value; + struct + { + unsigned R_DPAD : 1; + unsigned L_DPAD : 1; + unsigned D_DPAD : 1; + unsigned U_DPAD : 1; + unsigned START_BUTTON : 1; + unsigned Z_TRIG : 1; + unsigned B_BUTTON : 1; + unsigned A_BUTTON : 1; - unsigned R_CBUTTON : 1; - unsigned L_CBUTTON : 1; - unsigned D_CBUTTON : 1; - unsigned U_CBUTTON : 1; - unsigned R_TRIG : 1; - unsigned L_TRIG : 1; - unsigned Reserved1 : 1; - unsigned Reserved2 : 1; + unsigned R_CBUTTON : 1; + unsigned L_CBUTTON : 1; + unsigned D_CBUTTON : 1; + unsigned U_CBUTTON : 1; + unsigned R_TRIG : 1; + unsigned L_TRIG : 1; + unsigned Reserved1 : 1; + unsigned Reserved2 : 1; - signed Y_AXIS : 8; + signed Y_AXIS : 8; - signed X_AXIS : 8; - }; - } BUTTONS; + signed X_AXIS : 8; + }; + } BUTTONS; - typedef struct - { - HWND hMainWindow; - HINSTANCE hinst; + typedef struct + { + HWND hMainWindow; + HINSTANCE hinst; - BOOL MemoryBswaped; // If this is set to TRUE, then the memory has been pre - // bswap on a dword (32 bits) boundry, only effects header. - // eg. the first 8 bytes are stored like this: - // 4 3 2 1 8 7 6 5 - BYTE * HEADER; // This is the rom header (first 40h bytes of the rom) - CONTROL *Controls; // A pointer to an array of 4 controllers .. eg: - // CONTROL Controls[4]; - } CONTROL_INFO; + BOOL MemoryBswaped; // If this is set to TRUE, then the memory has been pre + // bswap on a dword (32 bits) boundry, only effects header. + // eg. the first 8 bytes are stored like this: + // 4 3 2 1 8 7 6 5 + BYTE * HEADER; // This is the rom header (first 40h bytes of the rom) + CONTROL *Controls; // A pointer to an array of 4 controllers .. eg: + // CONTROL Controls[4]; + } CONTROL_INFO; - /****************************************************************** - Function: CloseDLL - Purpose: This function is called when the emulator is closing - down allowing the dll to de-initialise. - input: none - output: none - *******************************************************************/ - EXPORT void CALL CloseDLL(void); + /****************************************************************** + Function: CloseDLL + Purpose: This function is called when the emulator is closing + down allowing the dll to de-initialise. + input: none + output: none + *******************************************************************/ + EXPORT void CALL CloseDLL(void); - /****************************************************************** - Function: ControllerCommand - Purpose: To process the raw data that has just been sent to a - specific controller. - input: - Controller Number (0 to 3) and -1 signalling end of - processing the pif ram. - - Pointer of data to be processed. - output: none + /****************************************************************** + Function: ControllerCommand + Purpose: To process the raw data that has just been sent to a + specific controller. + input: - Controller Number (0 to 3) and -1 signalling end of + processing the pif ram. + - Pointer of data to be processed. + output: none - note: This function is only needed if the DLL is allowing raw - data, or the plugin is set to raw + note: This function is only needed if the DLL is allowing raw + data, or the plugin is set to raw - the data that is being processed looks like this: - initilize controller: 01 03 00 FF FF FF - read controller: 01 04 01 FF FF FF FF - *******************************************************************/ - EXPORT void CALL ControllerCommand(int Control, BYTE * Command); + the data that is being processed looks like this: + initilize controller: 01 03 00 FF FF FF + read controller: 01 04 01 FF FF FF FF + *******************************************************************/ + EXPORT void CALL ControllerCommand(int Control, BYTE * Command); - /****************************************************************** - Function: DllAbout - Purpose: This function is optional function that is provided - to give further information about the DLL. - input: a handle to the window that calls this function - output: none - *******************************************************************/ - EXPORT void CALL DllAbout(HWND hParent); + /****************************************************************** + Function: DllAbout + Purpose: This function is optional function that is provided + to give further information about the DLL. + input: a handle to the window that calls this function + output: none + *******************************************************************/ + EXPORT void CALL DllAbout(HWND hParent); - /****************************************************************** - Function: DllConfig - Purpose: This function is optional function that is provided - to allow the user to configure the dll - input: a handle to the window that calls this function - output: none - *******************************************************************/ - EXPORT void CALL DllConfig(HWND hParent); + /****************************************************************** + Function: DllConfig + Purpose: This function is optional function that is provided + to allow the user to configure the dll + input: a handle to the window that calls this function + output: none + *******************************************************************/ + EXPORT void CALL DllConfig(HWND hParent); - /****************************************************************** - Function: DllTest - Purpose: This function is optional function that is provided - to allow the user to test the dll - input: a handle to the window that calls this function - output: none - *******************************************************************/ - EXPORT void CALL DllTest(HWND hParent); + /****************************************************************** + Function: DllTest + Purpose: This function is optional function that is provided + to allow the user to test the dll + input: a handle to the window that calls this function + output: none + *******************************************************************/ + EXPORT void CALL DllTest(HWND hParent); - /****************************************************************** - Function: GetDllInfo - Purpose: This function allows the emulator to gather information - about the dll by filling in the PluginInfo structure. - input: a pointer to a PLUGIN_INFO stucture that needs to be - filled by the function. (see def above) - output: none - *******************************************************************/ - EXPORT void CALL GetDllInfo(PLUGIN_INFO * PluginInfo); + /****************************************************************** + Function: GetDllInfo + Purpose: This function allows the emulator to gather information + about the dll by filling in the PluginInfo structure. + input: a pointer to a PLUGIN_INFO stucture that needs to be + filled by the function. (see def above) + output: none + *******************************************************************/ + EXPORT void CALL GetDllInfo(PLUGIN_INFO * PluginInfo); - /****************************************************************** - Function: GetKeys - Purpose: To get the current state of the controllers buttons. - input: - Controller Number (0 to 3) - - A pointer to a BUTTONS structure to be filled with - the controller state. - output: none - *******************************************************************/ - EXPORT void CALL GetKeys(int Control, BUTTONS * Keys); + /****************************************************************** + Function: GetKeys + Purpose: To get the current state of the controllers buttons. + input: - Controller Number (0 to 3) + - A pointer to a BUTTONS structure to be filled with + the controller state. + output: none + *******************************************************************/ + EXPORT void CALL GetKeys(int Control, BUTTONS * Keys); - /****************************************************************** - Function: InitiateControllers - Purpose: This function initialises how each of the controllers - should be handled. - input: - The handle to the main window. - - A controller structure that needs to be filled for - the emulator to know how to handle each controller. - output: none - *******************************************************************/ + /****************************************************************** + Function: InitiateControllers + Purpose: This function initialises how each of the controllers + should be handled. + input: - The handle to the main window. + - A controller structure that needs to be filled for + the emulator to know how to handle each controller. + output: none + *******************************************************************/ #if (SPECS_VERSION < 0x0101) EXPORT void CALL InitiateControllers(void * hMainWindow, CONTROL Controls[4]); #elif (SPECS_VERSION == 0x0101) @@ -194,53 +194,53 @@ EXPORT void CALL InitiateControllers(CONTROL_INFO ControlInfo); EXPORT void CALL InitiateControllers(CONTROL_INFO * ControlInfo); #endif - /****************************************************************** - Function: ReadController - Purpose: To process the raw data in the pif ram that is about to - be read. - input: - Controller Number (0 to 3) and -1 signalling end of - processing the pif ram. - - Pointer of data to be processed. - output: none - note: This function is only needed if the DLL is allowing raw - data. - *******************************************************************/ - EXPORT void CALL ReadController(int Control, BYTE * Command); + /****************************************************************** + Function: ReadController + Purpose: To process the raw data in the pif ram that is about to + be read. + input: - Controller Number (0 to 3) and -1 signalling end of + processing the pif ram. + - Pointer of data to be processed. + output: none + note: This function is only needed if the DLL is allowing raw + data. + *******************************************************************/ + EXPORT void CALL ReadController(int Control, BYTE * Command); - /****************************************************************** - Function: RomClosed - Purpose: This function is called when a rom is closed. - input: none - output: none - *******************************************************************/ - EXPORT void CALL RomClosed(void); + /****************************************************************** + Function: RomClosed + Purpose: This function is called when a rom is closed. + input: none + output: none + *******************************************************************/ + EXPORT void CALL RomClosed(void); - /****************************************************************** - Function: RomOpen - Purpose: This function is called when a rom is open. (from the - emulation thread) - input: none - output: none - *******************************************************************/ - EXPORT void CALL RomOpen(void); + /****************************************************************** + Function: RomOpen + Purpose: This function is called when a rom is open. (from the + emulation thread) + input: none + output: none + *******************************************************************/ + EXPORT void CALL RomOpen(void); - /****************************************************************** - Function: WM_KeyDown - Purpose: To pass the WM_KeyDown message from the emulator to the - plugin. - input: wParam and lParam of the WM_KEYDOWN message. - output: none - *******************************************************************/ - EXPORT void CALL WM_KeyDown(WPARAM wParam, LPARAM lParam); + /****************************************************************** + Function: WM_KeyDown + Purpose: To pass the WM_KeyDown message from the emulator to the + plugin. + input: wParam and lParam of the WM_KEYDOWN message. + output: none + *******************************************************************/ + EXPORT void CALL WM_KeyDown(WPARAM wParam, LPARAM lParam); - /****************************************************************** - Function: WM_KeyUp - Purpose: To pass the WM_KEYUP message from the emulator to the - plugin. - input: wParam and lParam of the WM_KEYDOWN message. - output: none - *******************************************************************/ - EXPORT void CALL WM_KeyUp(WPARAM wParam, LPARAM lParam); + /****************************************************************** + Function: WM_KeyUp + Purpose: To pass the WM_KEYUP message from the emulator to the + plugin. + input: wParam and lParam of the WM_KEYDOWN message. + output: none + *******************************************************************/ + EXPORT void CALL WM_KeyUp(WPARAM wParam, LPARAM lParam); #if defined(__cplusplus) } diff --git a/Source/nragev20/Debug.cpp b/Source/nragev20/Debug.cpp index 4e3851eb2..1220e758e 100644 --- a/Source/nragev20/Debug.cpp +++ b/Source/nragev20/Debug.cpp @@ -1,9 +1,9 @@ -/* - N-Rage`s Dinput8 Plugin +/* + N-Rage`s Dinput8 Plugin (C) 2002, 2006 Norbert Wladyka - Author`s Email: norbert.wladyka@chello.at - Website: http://go.to/nrage + Author`s Email: norbert.wladyka@chello.at + Website: http://go.to/nrage This program is free software; you can redistribute it and/or modify @@ -34,125 +34,125 @@ HANDLE hDebug = INVALID_HANDLE_VALUE; void _DebugAnsiFileWrite( LPCSTR szRemark ) { - if( !bDebug ) - return; + if( !bDebug ) + return; - if (hDebug == INVALID_HANDLE_VALUE) - { - TCHAR szFile[] = _T("NRage-Debug.txt"); - TCHAR szBuffer[MAX_PATH+1]; + if (hDebug == INVALID_HANDLE_VALUE) + { + TCHAR szFile[] = _T("NRage-Debug.txt"); + TCHAR szBuffer[MAX_PATH+1]; - GetAbsoluteFileName( szBuffer, szFile, DIRECTORY_LOG ); - hDebug = CreateFile( szBuffer, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); - if (hDebug != INVALID_HANDLE_VALUE) - SetFilePointer(hDebug, 0, 0, FILE_END); - } + GetAbsoluteFileName( szBuffer, szFile, DIRECTORY_LOG ); + hDebug = CreateFile( szBuffer, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); + if (hDebug != INVALID_HANDLE_VALUE) + SetFilePointer(hDebug, 0, 0, FILE_END); + } - if( hDebug != INVALID_HANDLE_VALUE ) - { - DWORD dwWritten; - LPCSTR szText = szRemark; - if( szText == NULL ) - szText = "\r\n"; + if( hDebug != INVALID_HANDLE_VALUE ) + { + DWORD dwWritten; + LPCSTR szText = szRemark; + if( szText == NULL ) + szText = "\r\n"; - LPCSTR szCurrPos = szText; + LPCSTR szCurrPos = szText; - while( ( szCurrPos = strchr( szCurrPos, '\n' )) != NULL ) - { - DWORD length = szCurrPos - szText; - if( length > 0 && szCurrPos[-1] == '\r' ) - --length; + while( ( szCurrPos = strchr( szCurrPos, '\n' )) != NULL ) + { + DWORD length = szCurrPos - szText; + if( length > 0 && szCurrPos[-1] == '\r' ) + --length; - if( length > 0 ) - WriteFile( hDebug, (LPCVOID)szText, length, &dwWritten, NULL ); - WriteFile( hDebug, "\r\n", 2, &dwWritten, NULL ); + if( length > 0 ) + WriteFile( hDebug, (LPCVOID)szText, length, &dwWritten, NULL ); + WriteFile( hDebug, "\r\n", 2, &dwWritten, NULL ); - szText = ++szCurrPos; - } + szText = ++szCurrPos; + } - DWORD length = lstrlenA( szText ); + DWORD length = lstrlenA( szText ); - if( length > 0 ) + if( length > 0 ) WriteFile( hDebug, (LPCVOID)szText, length, &dwWritten, NULL ); - } - return; + } + return; } void _cdecl _DebugWriteA( LPCSTR szFormat, ... ) { - if( szFormat != NULL ) - { - char szBuffer[4096]; + if( szFormat != NULL ) + { + char szBuffer[4096]; - va_list val; + va_list val; - va_start( val,szFormat ); - wvsprintfA( szBuffer, szFormat, val ); - va_end( val ); - szBuffer[sizeof(szBuffer)-1] = '\0'; + va_start( val,szFormat ); + wvsprintfA( szBuffer, szFormat, val ); + va_end( val ); + szBuffer[sizeof(szBuffer)-1] = '\0'; - _DebugAnsiFileWrite( szBuffer ); - } - else + _DebugAnsiFileWrite( szBuffer ); + } + else _DebugAnsiFileWrite( NULL ); } void _cdecl _DebugWriteW( const LPCWSTR szFormat, ... ) { - if( szFormat != NULL ) - { - WCHAR szBuffer[4096]; - va_list val; + if( szFormat != NULL ) + { + WCHAR szBuffer[4096]; + va_list val; - va_start( val,szFormat ); - wvsprintfW( szBuffer, szFormat, val ); - va_end( val ); - szBuffer[(sizeof(szBuffer) / sizeof(WCHAR))-1] = L'\0'; + va_start( val,szFormat ); + wvsprintfW( szBuffer, szFormat, val ); + va_end( val ); + szBuffer[(sizeof(szBuffer) / sizeof(WCHAR))-1] = L'\0'; - char szAnsi[sizeof(szBuffer) / sizeof(WCHAR)]; - WideCharToMultiByte( CP_ACP, 0, szBuffer, -1, szAnsi, sizeof(szAnsi), NULL, NULL ); - _DebugAnsiFileWrite( szAnsi ); - } - else - _DebugAnsiFileWrite( NULL ); + char szAnsi[sizeof(szBuffer) / sizeof(WCHAR)]; + WideCharToMultiByte( CP_ACP, 0, szBuffer, -1, szAnsi, sizeof(szAnsi), NULL, NULL ); + _DebugAnsiFileWrite( szAnsi ); + } + else + _DebugAnsiFileWrite( NULL ); } void _WriteDatasA( LPCSTR Header, const int Control, const unsigned char * Data, const HRESULT hr ) { - if( !bDebug || Data == NULL ) - return; + if( !bDebug || Data == NULL ) + return; - _DebugWriteA( "%d:%s\n", Control, Header); - - if( hr ) - { - _DebugWriteA( "Failed! ErrorCode: %08X\n", hr ); - } + _DebugWriteA( "%d:%s\n", Control, Header); + + if( hr ) + { + _DebugWriteA( "Failed! ErrorCode: %08X\n", hr ); + } - int iEnd = Data[0] + Data[1] + 2; + int iEnd = Data[0] + Data[1] + 2; - for( int i = -1; i < iEnd; i += 8 ) - { - _DebugWriteA( "%02X%02X%02X%02X %02X%02X%02X%02X\n", Data[i+0], Data[i+1], Data[i+2], Data[i+3], Data[i+4], Data[i+5], Data[i+6], Data[i+7] ); - } + for( int i = -1; i < iEnd; i += 8 ) + { + _DebugWriteA( "%02X%02X%02X%02X %02X%02X%02X%02X\n", Data[i+0], Data[i+1], Data[i+2], Data[i+3], Data[i+4], Data[i+5], Data[i+6], Data[i+7] ); + } - return; + return; } void _CloseDebugFile() { - if( hDebug != INVALID_HANDLE_VALUE ) - { - _DebugWriteA("---DEBUG FILE CLOSED---\n"); - CloseHandle( hDebug ); - } + if( hDebug != INVALID_HANDLE_VALUE ) + { + _DebugWriteA("---DEBUG FILE CLOSED---\n"); + CloseHandle( hDebug ); + } } void _DebugFlush() { - if( hDebug != INVALID_HANDLE_VALUE ) - { - FlushFileBuffers(hDebug); - } + if( hDebug != INVALID_HANDLE_VALUE ) + { + FlushFileBuffers(hDebug); + } } diff --git a/Source/nragev20/Debug.h b/Source/nragev20/Debug.h index 8cc618b7f..3565a12f4 100644 --- a/Source/nragev20/Debug.h +++ b/Source/nragev20/Debug.h @@ -1,9 +1,9 @@ -/* - N-Rage`s Dinput8 Plugin +/* + N-Rage`s Dinput8 Plugin (C) 2002, 2006 Norbert Wladyka - Author`s Email: norbert.wladyka@chello.at - Website: http://go.to/nrage + Author`s Email: norbert.wladyka@chello.at + Website: http://go.to/nrage This program is free software; you can redistribute it and/or modify @@ -37,9 +37,9 @@ void _cdecl _DebugWriteW( LPCWSTR szFormat, ... ); void _CloseDebugFile(); void _DebugFlush(); -#define DebugWriteA _DebugWriteA -#define DebugWriteW _DebugWriteW -#define WriteDatasA( header, control, data, hr ) _WriteDatasA( header, control, data, hr ) +#define DebugWriteA _DebugWriteA +#define DebugWriteW _DebugWriteW +#define WriteDatasA( header, control, data, hr ) _WriteDatasA( header, control, data, hr ) #define CloseDebugFile() _CloseDebugFile() #define DebugWriteByteA(str) DebugWriteA("%02X", str) #define DebugWriteWordA(str) DebugWriteA("%04X", str) @@ -48,9 +48,9 @@ void _DebugFlush(); #else // #ifndef _DEBUG #define DebugWriteByteA(str) #define DebugWriteWordA(str) -#define DebugWriteA ;// -#define DebugWriteW ;// -#define WriteDatasA(header,control,data,hr) +#define DebugWriteA ;// +#define DebugWriteW ;// +#define WriteDatasA(header,control,data,hr) #define CloseDebugFile() #define DebugFlush() diff --git a/Source/nragev20/DirectInput.cpp b/Source/nragev20/DirectInput.cpp index dbd3440c9..00a3911ba 100644 --- a/Source/nragev20/DirectInput.cpp +++ b/Source/nragev20/DirectInput.cpp @@ -1,9 +1,9 @@ -/* - N-Rage`s Dinput8 Plugin +/* + N-Rage`s Dinput8 Plugin (C) 2002, 2006 Norbert Wladyka - Author`s Email: norbert.wladyka@chello.at - Website: http://go.to/nrage + Author`s Email: norbert.wladyka@chello.at + Website: http://go.to/nrage This program is free software; you can redistribute it and/or modify @@ -41,1079 +41,1079 @@ using std::max; HRESULT AcquireDevice( LPDIRECTINPUTDEVICE8 lpDirectInputDevice ); // global Variables // -LPDIRECTINPUT8 g_pDIHandle = NULL; // Base DirectInput8-Handle +LPDIRECTINPUT8 g_pDIHandle = NULL; // Base DirectInput8-Handle -//LPDIRECTINPUTDEVICE8 g_apInputDevice[6] = { NULL, NULL, NULL, NULL, NULL, NULL }; // array of Handles for devices - // 0:Keyboard, 1:Mouse, the rest are FF gamepads +//LPDIRECTINPUTDEVICE8 g_apInputDevice[6] = { NULL, NULL, NULL, NULL, NULL, NULL }; // array of Handles for devices + // 0:Keyboard, 1:Mouse, the rest are FF gamepads -// BYTE g_acKeystate[256]; // use g_sysKeyboard.stateAs.rgbButtons instead -// DIMOUSESTATE2 g_msMouseState = { 0, 0, 0 }; // Store our mouse state data between reads (because every time we read data, it resets the device data) - // moved to g_sysMouse.stateAs... +// BYTE g_acKeystate[256]; // use g_sysKeyboard.stateAs.rgbButtons instead +// DIMOUSESTATE2 g_msMouseState = { 0, 0, 0 }; // Store our mouse state data between reads (because every time we read data, it resets the device data) + // moved to g_sysMouse.stateAs... // Update device data tables (so we only have to poll and read the devices once). This is called by GetKeys and ReadController. void GetDeviceDatas() { - HRESULT hr; + HRESULT hr; -/* if( g_sysKeyboard.didHandle ) - { - hr = g_sysKeyboard.didHandle->Poll(); - if( FAILED( hr )) - AcquireDevice( g_sysKeyboard.didHandle ); // we'll try again next time +/* if( g_sysKeyboard.didHandle ) + { + hr = g_sysKeyboard.didHandle->Poll(); + if( FAILED( hr )) + AcquireDevice( g_sysKeyboard.didHandle ); // we'll try again next time - hr = g_sysKeyboard.didHandle->GetDeviceState( sizeof(g_sysKeyboard.stateAs.rgbButtons), &g_sysKeyboard.stateAs.rgbButtons ); + hr = g_sysKeyboard.didHandle->GetDeviceState( sizeof(g_sysKeyboard.stateAs.rgbButtons), &g_sysKeyboard.stateAs.rgbButtons ); - if( FAILED( hr )) - ZeroMemory( g_sysKeyboard.stateAs.rgbButtons, sizeof(g_sysKeyboard.stateAs.rgbButtons) ); - } */ + if( FAILED( hr )) + ZeroMemory( g_sysKeyboard.stateAs.rgbButtons, sizeof(g_sysKeyboard.stateAs.rgbButtons) ); + } */ - if( g_sysMouse.didHandle ) - { - hr = g_sysMouse.didHandle->Poll(); + if( g_sysMouse.didHandle ) + { + hr = g_sysMouse.didHandle->Poll(); - if( FAILED( hr )) - AcquireDevice( g_sysMouse.didHandle ); // we'll try again next time + if( FAILED( hr )) + AcquireDevice( g_sysMouse.didHandle ); // we'll try again next time - hr = g_sysMouse.didHandle->GetDeviceState( sizeof(DIMOUSESTATE2), &g_sysMouse.stateAs.mouseState ); + hr = g_sysMouse.didHandle->GetDeviceState( sizeof(DIMOUSESTATE2), &g_sysMouse.stateAs.mouseState ); - if( FAILED( hr )) - ZeroMemory( &g_sysMouse.stateAs.mouseState, sizeof(DIMOUSESTATE2) ); - } + if( FAILED( hr )) + ZeroMemory( &g_sysMouse.stateAs.mouseState, sizeof(DIMOUSESTATE2) ); + } - // need to just poll every damn device we're using - for( int i = 0; i < g_nDevices; i++ ) - { - if( g_devList[i].didHandle ) - { - if( FAILED( g_devList[i].didHandle->Poll() )) - AcquireDevice( g_devList[i].didHandle ); // we'll try again next time - - switch (LOBYTE(g_devList[i].dwDevType)) - { - case DI8DEVTYPE_KEYBOARD: - hr = g_devList[i].didHandle->GetDeviceState( sizeof(g_devList[i].stateAs.rgbButtons), g_devList[i].stateAs.rgbButtons ); - break; - case DI8DEVTYPE_MOUSE: - hr = g_devList[i].didHandle->GetDeviceState( sizeof(g_devList[i].stateAs.mouseState), &g_devList[i].stateAs.mouseState ); - break; - default: - hr = g_devList[i].didHandle->GetDeviceState( sizeof(g_devList[i].stateAs.joyState), &g_devList[i].stateAs.joyState ); - } - } - else - hr = DIERR_NOTACQUIRED; + // need to just poll every damn device we're using + for( int i = 0; i < g_nDevices; i++ ) + { + if( g_devList[i].didHandle ) + { + if( FAILED( g_devList[i].didHandle->Poll() )) + AcquireDevice( g_devList[i].didHandle ); // we'll try again next time - if( hr == DIERR_NOTACQUIRED ) // changed this because in the rare condition that we lose input between polling and GetDeviceState we don't want to reset our current controls --rabid - { - ZeroMemory( &g_devList[i].stateAs.joyState, sizeof(DEVICE::INPUTSTATE)); - if (g_devList[i].dwDevType != DI8DEVTYPE_KEYBOARD && g_devList[i].dwDevType != DI8DEVTYPE_MOUSE) - FillMemory( g_devList[i].stateAs.joyState.rgdwPOV, sizeof(g_devList[i].stateAs.joyState.rgdwPOV), 0xFF ); // g_devList[i].stateAs.joyState.rgdwPOV = -1; // -1 is neutral - } - } + switch (LOBYTE(g_devList[i].dwDevType)) + { + case DI8DEVTYPE_KEYBOARD: + hr = g_devList[i].didHandle->GetDeviceState( sizeof(g_devList[i].stateAs.rgbButtons), g_devList[i].stateAs.rgbButtons ); + break; + case DI8DEVTYPE_MOUSE: + hr = g_devList[i].didHandle->GetDeviceState( sizeof(g_devList[i].stateAs.mouseState), &g_devList[i].stateAs.mouseState ); + break; + default: + hr = g_devList[i].didHandle->GetDeviceState( sizeof(g_devList[i].stateAs.joyState), &g_devList[i].stateAs.joyState ); + } + } + else + hr = DIERR_NOTACQUIRED; + + if( hr == DIERR_NOTACQUIRED ) // changed this because in the rare condition that we lose input between polling and GetDeviceState we don't want to reset our current controls --rabid + { + ZeroMemory( &g_devList[i].stateAs.joyState, sizeof(DEVICE::INPUTSTATE)); + if (g_devList[i].dwDevType != DI8DEVTYPE_KEYBOARD && g_devList[i].dwDevType != DI8DEVTYPE_MOUSE) + FillMemory( g_devList[i].stateAs.joyState.rgdwPOV, sizeof(g_devList[i].stateAs.joyState.rgdwPOV), 0xFF ); // g_devList[i].stateAs.joyState.rgdwPOV = -1; // -1 is neutral + } + } } // hacked up piece of shit, but it works inline bool GetJoyPadPOV( PDWORD dwDegree, BYTE AxeId ) // TRUE if specified Direction is Pressed { - if( LOWORD( *dwDegree ) == 0xFFFF ) - return false; + if( LOWORD( *dwDegree ) == 0xFFFF ) + return false; - bool bPressed; + bool bPressed; - switch( AxeId ) - { - case AI_POV_DOWN: - bPressed = (( *dwDegree >= 18000 - POVANGLETHRESH ) && (*dwDegree <= 18000 + POVANGLETHRESH )); - break; - case AI_POV_LEFT: - bPressed = (( *dwDegree >= 27000 - POVANGLETHRESH ) && (*dwDegree <= 27000 + POVANGLETHRESH )); - break; - case AI_POV_RIGHT: - bPressed = (( *dwDegree >= 9000 - POVANGLETHRESH ) && (*dwDegree <= 9000 + POVANGLETHRESH )); - break; - case AI_POV_UP: - bPressed = (( *dwDegree >= 36000 - POVANGLETHRESH ) || ( *dwDegree <= 0 + POVANGLETHRESH )); - break; - default: - bPressed = false; - } - - return bPressed; + switch( AxeId ) + { + case AI_POV_DOWN: + bPressed = (( *dwDegree >= 18000 - POVANGLETHRESH ) && (*dwDegree <= 18000 + POVANGLETHRESH )); + break; + case AI_POV_LEFT: + bPressed = (( *dwDegree >= 27000 - POVANGLETHRESH ) && (*dwDegree <= 27000 + POVANGLETHRESH )); + break; + case AI_POV_RIGHT: + bPressed = (( *dwDegree >= 9000 - POVANGLETHRESH ) && (*dwDegree <= 9000 + POVANGLETHRESH )); + break; + case AI_POV_UP: + bPressed = (( *dwDegree >= 36000 - POVANGLETHRESH ) || ( *dwDegree <= 0 + POVANGLETHRESH )); + break; + default: + bPressed = false; + } + + return bPressed; } // Fill in button states and axis states for controller indexController, into the struct pdwData. // pdwData is a pointer to a 4 byte BUTTONS union, if anyone cares bool GetNControllerInput ( const int indexController, LPDWORD pdwData ) { - *pdwData = 0; - WORD w_Buttons = 0; - // WORD w_Axes = 0; + *pdwData = 0; + WORD w_Buttons = 0; + // WORD w_Axes = 0; - LPCONTROLLER pcController = &g_pcControllers[indexController]; // still needs to be here, but not as important --rabid + LPCONTROLLER pcController = &g_pcControllers[indexController]; // still needs to be here, but not as important --rabid - bool b_Value; - long l_Value = 0; + bool b_Value; + long l_Value = 0; - long lAxisValueX = ZEROVALUE; - long lAxisValueY = ZEROVALUE; + long lAxisValueX = ZEROVALUE; + long lAxisValueY = ZEROVALUE; - // take this info from the N64 controller struct, regardless of input devices - float d_ModifierX = (float)pcController->bStickRange / 100.0f; - float d_ModifierY = (float)pcController->bStickRange / 100.0f; + // take this info from the N64 controller struct, regardless of input devices + float d_ModifierX = (float)pcController->bStickRange / 100.0f; + float d_ModifierY = (float)pcController->bStickRange / 100.0f; - int i; + int i; - // do N64-Buttons / modifiers - for (i = 0; i < pcController->nModifiers; i++ ) - { - BUTTON btnButton = pcController->pModifiers[i].btnButton; + // do N64-Buttons / modifiers + for (i = 0; i < pcController->nModifiers; i++ ) + { + BUTTON btnButton = pcController->pModifiers[i].btnButton; - b_Value = IsBtnPressed( btnButton ); + b_Value = IsBtnPressed( btnButton ); - bool fChangeMod = false; + bool fChangeMod = false; - if( pcController->pModifiers[i].bModType == MDT_CONFIG ) - { // Config-Type - if( pcController->pModifiers[i].fToggle ) - { - if( b_Value && !btnButton.fPrevPressed) - { - pcController->pModifiers[i].fStatus = !pcController->pModifiers[i].fStatus; - fChangeMod = true; - } - } - else - { - if( b_Value != (bool)(btnButton.fPrevPressed)) - fChangeMod = true; - } - } - else - { // Move / Macro Type - if( pcController->pModifiers[i].fToggle ) - { - if( b_Value && !btnButton.fPrevPressed ) - pcController->pModifiers[i].fStatus = !pcController->pModifiers[i].fStatus; - fChangeMod = ( pcController->pModifiers[i].fStatus != 0 ); - } - else - { - fChangeMod = b_Value; - } - } + if( pcController->pModifiers[i].bModType == MDT_CONFIG ) + { // Config-Type + if( pcController->pModifiers[i].fToggle ) + { + if( b_Value && !btnButton.fPrevPressed) + { + pcController->pModifiers[i].fStatus = !pcController->pModifiers[i].fStatus; + fChangeMod = true; + } + } + else + { + if( b_Value != (bool)(btnButton.fPrevPressed)) + fChangeMod = true; + } + } + else + { // Move / Macro Type + if( pcController->pModifiers[i].fToggle ) + { + if( b_Value && !btnButton.fPrevPressed ) + pcController->pModifiers[i].fStatus = !pcController->pModifiers[i].fStatus; + fChangeMod = ( pcController->pModifiers[i].fStatus != 0 ); + } + else + { + fChangeMod = b_Value; + } + } - if( fChangeMod ) - { - switch( pcController->pModifiers[i].bModType ) - { - case MDT_MOVE: - { - LPMODSPEC_MOVE args = (LPMODSPEC_MOVE)&pcController->pModifiers[i].dwSpecific; - d_ModifierX *= args->XModification / 100.0f; - d_ModifierY *= args->YModification / 100.0f; - } - break; - case MDT_MACRO: - { - LPMODSPEC_MACRO args = (LPMODSPEC_MACRO)&pcController->pModifiers[i].dwSpecific; + if( fChangeMod ) + { + switch( pcController->pModifiers[i].bModType ) + { + case MDT_MOVE: + { + LPMODSPEC_MOVE args = (LPMODSPEC_MOVE)&pcController->pModifiers[i].dwSpecific; + d_ModifierX *= args->XModification / 100.0f; + d_ModifierY *= args->YModification / 100.0f; + } + break; + case MDT_MACRO: + { + LPMODSPEC_MACRO args = (LPMODSPEC_MACRO)&pcController->pModifiers[i].dwSpecific; - if (args->fRapidFire) // w00t! Rapid Fire here - { - if ((unsigned) b_Value != btnButton.fPrevPressed) // New macro pressed - { - args->fPrevFireState = 0; - args->fPrevFireState2 = 0; - } - if(!args->fPrevFireState) // This round, a firing is needed - { - w_Buttons |= args->aButtons; - if( args->fAnalogRight ) - lAxisValueX += MAXAXISVALUE; - else if( args->fAnalogLeft ) - lAxisValueX -= MAXAXISVALUE; + if (args->fRapidFire) // w00t! Rapid Fire here + { + if ((unsigned) b_Value != btnButton.fPrevPressed) // New macro pressed + { + args->fPrevFireState = 0; + args->fPrevFireState2 = 0; + } + if(!args->fPrevFireState) // This round, a firing is needed + { + w_Buttons |= args->aButtons; + if( args->fAnalogRight ) + lAxisValueX += MAXAXISVALUE; + else if( args->fAnalogLeft ) + lAxisValueX -= MAXAXISVALUE; - if( args->fAnalogDown ) - lAxisValueY -= MAXAXISVALUE; - else if( args->fAnalogUp ) // up - lAxisValueY += MAXAXISVALUE; - } + if( args->fAnalogDown ) + lAxisValueY -= MAXAXISVALUE; + else if( args->fAnalogUp ) // up + lAxisValueY += MAXAXISVALUE; + } - // Ok, update the firing counters here - if (args->fRapidFireRate) // Do the rapid fire slowly - { // Note that this updates State2 before State... Makes a nice slower square-wave type pulse for the update - args->fPrevFireState2 = (args->fPrevFireState2 + 1) & 1; - if (!args->fPrevFireState2) - { - args->fPrevFireState = (args->fPrevFireState + 1) & 1; - DebugWriteA("Slow Rapid Fire - Mark 2\n"); - } - } - else // Do a fast rapid fire - { - args->fPrevFireState = (args->fPrevFireState + 1) & 1; - DebugWriteA("Fast Rapid Fire\n"); - } - } - else - { - w_Buttons |= args->aButtons; // Note this: It lets you push buttons as well as the macro buttons - if( args->fAnalogRight ) - lAxisValueX += MAXAXISVALUE; - else if( args->fAnalogLeft ) - lAxisValueX -= MAXAXISVALUE; + // Ok, update the firing counters here + if (args->fRapidFireRate) // Do the rapid fire slowly + { // Note that this updates State2 before State... Makes a nice slower square-wave type pulse for the update + args->fPrevFireState2 = (args->fPrevFireState2 + 1) & 1; + if (!args->fPrevFireState2) + { + args->fPrevFireState = (args->fPrevFireState + 1) & 1; + DebugWriteA("Slow Rapid Fire - Mark 2\n"); + } + } + else // Do a fast rapid fire + { + args->fPrevFireState = (args->fPrevFireState + 1) & 1; + DebugWriteA("Fast Rapid Fire\n"); + } + } + else + { + w_Buttons |= args->aButtons; // Note this: It lets you push buttons as well as the macro buttons + if( args->fAnalogRight ) + lAxisValueX += MAXAXISVALUE; + else if( args->fAnalogLeft ) + lAxisValueX -= MAXAXISVALUE; - if( args->fAnalogDown ) - lAxisValueY -= MAXAXISVALUE; - else if( args->fAnalogUp ) // up - lAxisValueY += MAXAXISVALUE; + if( args->fAnalogDown ) + lAxisValueY -= MAXAXISVALUE; + else if( args->fAnalogUp ) // up + lAxisValueY += MAXAXISVALUE; - args->fPrevFireState = 0; - } - } - break; - case MDT_CONFIG: - { - LPMODSPEC_CONFIG args = (LPMODSPEC_CONFIG)&pcController->pModifiers[i].dwSpecific; + args->fPrevFireState = 0; + } + } + break; + case MDT_CONFIG: + { + LPMODSPEC_CONFIG args = (LPMODSPEC_CONFIG)&pcController->pModifiers[i].dwSpecific; - if( args->fChangeAnalogConfig ) - { - BYTE bConfig = (BYTE)args->fAnalogStickMode; - if( bConfig < PF_AXESETS ) - pcController->bAxisSet = bConfig; - else - { - if( pcController->bAxisSet == PF_AXESETS-1 ) - pcController->bAxisSet = 0; - else - ++pcController->bAxisSet; - } + if( args->fChangeAnalogConfig ) + { + BYTE bConfig = (BYTE)args->fAnalogStickMode; + if( bConfig < PF_AXESETS ) + pcController->bAxisSet = bConfig; + else + { + if( pcController->bAxisSet == PF_AXESETS-1 ) + pcController->bAxisSet = 0; + else + ++pcController->bAxisSet; + } - } - if( args->fChangeMouseXAxis ) - if (pcController->bMouseMoveX == MM_BUFF) - pcController->bMouseMoveX = MM_ABS; - else if (pcController->bMouseMoveX == MM_ABS) - pcController->bMouseMoveX = MM_BUFF; - if( args->fChangeMouseYAxis ) - if (pcController->bMouseMoveY == MM_BUFF) - pcController->bMouseMoveY = MM_ABS; - else if (pcController->bMouseMoveY == MM_ABS) - pcController->bMouseMoveY = MM_BUFF; + } + if( args->fChangeMouseXAxis ) + if (pcController->bMouseMoveX == MM_BUFF) + pcController->bMouseMoveX = MM_ABS; + else if (pcController->bMouseMoveX == MM_ABS) + pcController->bMouseMoveX = MM_BUFF; + if( args->fChangeMouseYAxis ) + if (pcController->bMouseMoveY == MM_BUFF) + pcController->bMouseMoveY = MM_ABS; + else if (pcController->bMouseMoveY == MM_ABS) + pcController->bMouseMoveY = MM_BUFF; - if( args->fChangeKeyboardXAxis ) - pcController->fKeyAbsoluteX = !pcController->fKeyAbsoluteX; - if( args->fChangeKeyboardYAxis ) - pcController->fKeyAbsoluteY = !pcController->fKeyAbsoluteY; - } - break; - } - } + if( args->fChangeKeyboardXAxis ) + pcController->fKeyAbsoluteX = !pcController->fKeyAbsoluteX; + if( args->fChangeKeyboardYAxis ) + pcController->fKeyAbsoluteY = !pcController->fKeyAbsoluteY; + } + break; + } + } - btnButton.fPrevPressed = b_Value; - pcController->pModifiers[i].btnButton = btnButton; - } // END N64 MODIFIERS for + btnButton.fPrevPressed = b_Value; + pcController->pModifiers[i].btnButton = btnButton; + } // END N64 MODIFIERS for - // do N64-Buttons / modifiers - for( i = 0; i < PF_APADR; i++ ) - { - BUTTON btnButton = pcController->aButton[i]; + // do N64-Buttons / modifiers + for( i = 0; i < PF_APADR; i++ ) + { + BUTTON btnButton = pcController->aButton[i]; - b_Value = IsBtnPressed( btnButton ); + b_Value = IsBtnPressed( btnButton ); - w_Buttons |= (((WORD)b_Value) << i); - } // END N64 BUTTONS for + w_Buttons |= (((WORD)b_Value) << i); + } // END N64 BUTTONS for - long lDeadZoneValue = pcController->bPadDeadZone * RANGERELATIVE / 100; - float fDeadZoneRelation = (float)RANGERELATIVE / (float)( RANGERELATIVE - lDeadZoneValue ); + long lDeadZoneValue = pcController->bPadDeadZone * RANGERELATIVE / 100; + float fDeadZoneRelation = (float)RANGERELATIVE / (float)( RANGERELATIVE - lDeadZoneValue ); - // do N64 joystick axes - for ( i = 0; i < 4; i++ ) - { - // 0 : right - // 1 : left - // 2 : down - // 3 : up + // do N64 joystick axes + for ( i = 0; i < 4; i++ ) + { + // 0 : right + // 1 : left + // 2 : down + // 3 : up - bool fNegInput = (( i == 1 ) || ( i == 2 )); // Input has to be negated + bool fNegInput = (( i == 1 ) || ( i == 2 )); // Input has to be negated - BUTTON btnButton = pcController->aButton[PF_APADR + pcController->bAxisSet * 4 + i]; - LPLONG plRawState = (LPLONG)&btnButton.parentDevice->stateAs.joyState; - - switch( btnButton.bBtnType ) - { - case DT_JOYBUTTON: - l_Value = MAXAXISVALUE; - b_Value = ( btnButton.parentDevice->stateAs.joyState.rgbButtons[btnButton.bOffset] & 0x80 ) != 0; - break; + BUTTON btnButton = pcController->aButton[PF_APADR + pcController->bAxisSet * 4 + i]; + LPLONG plRawState = (LPLONG)&btnButton.parentDevice->stateAs.joyState; - case DT_JOYSLIDER: - case DT_JOYAXE: - l_Value = plRawState[btnButton.bOffset] - ZEROVALUE; + switch( btnButton.bBtnType ) + { + case DT_JOYBUTTON: + l_Value = MAXAXISVALUE; + b_Value = ( btnButton.parentDevice->stateAs.joyState.rgbButtons[btnButton.bOffset] & 0x80 ) != 0; + break; - if( btnButton.bAxisID ) // negative Range - { - fNegInput = !fNegInput; + case DT_JOYSLIDER: + case DT_JOYAXE: + l_Value = plRawState[btnButton.bOffset] - ZEROVALUE; - b_Value = ( l_Value <= -lDeadZoneValue ); - if( b_Value ) - l_Value = (long) ((float)(l_Value + lDeadZoneValue ) * fDeadZoneRelation ); - } - else - { - b_Value = ( l_Value >= lDeadZoneValue ); - if( b_Value ) - l_Value = (long) ((float)(l_Value - lDeadZoneValue ) * fDeadZoneRelation ); - } - break; + if( btnButton.bAxisID ) // negative Range + { + fNegInput = !fNegInput; - case DT_JOYPOV: - l_Value = MAXAXISVALUE; - b_Value = GetJoyPadPOV( (PDWORD)&plRawState[btnButton.bOffset] , btnButton.bAxisID ); - break; + b_Value = ( l_Value <= -lDeadZoneValue ); + if( b_Value ) + l_Value = (long) ((float)(l_Value + lDeadZoneValue ) * fDeadZoneRelation ); + } + else + { + b_Value = ( l_Value >= lDeadZoneValue ); + if( b_Value ) + l_Value = (long) ((float)(l_Value - lDeadZoneValue ) * fDeadZoneRelation ); + } + break; - case DT_KEYBUTTON: - if( btnButton.parentDevice->stateAs.rgbButtons[btnButton.bOffset] & 0x80 ) - { - b_Value = true; + case DT_JOYPOV: + l_Value = MAXAXISVALUE; + b_Value = GetJoyPadPOV( (PDWORD)&plRawState[btnButton.bOffset] , btnButton.bAxisID ); + break; - if(( pcController->fKeyAbsoluteX && i < 2 ) - || ( pcController->fKeyAbsoluteY && i > 1 )) - { - if( pcController->wAxeBuffer[i] < MAXAXISVALUE ) - { - l_Value = pcController->wAxeBuffer[i] = min(( pcController->wAxeBuffer[i] + N64DIVIDER*3), MAXAXISVALUE ); - } - else - l_Value = MAXAXISVALUE; - } - else - { - if( pcController->wAxeBuffer[i] < MAXAXISVALUE ) - { - l_Value = pcController->wAxeBuffer[i] = min(( pcController->wAxeBuffer[i] * 2 + N64DIVIDER*5 ), MAXAXISVALUE ); - } - else - l_Value = MAXAXISVALUE; - } - } - else - { - if(( pcController->fKeyAbsoluteX && i < 2 ) - || ( pcController->fKeyAbsoluteY && i > 1 )) - { - l_Value = pcController->wAxeBuffer[i]; - b_Value = true; - } - else - { - if( pcController->wAxeBuffer[i] > N64DIVIDER ) - { - b_Value = true; - l_Value = pcController->wAxeBuffer[i] = pcController->wAxeBuffer[i] / 2 ; - } - else - b_Value = false; - } - } - break; + case DT_KEYBUTTON: + if( btnButton.parentDevice->stateAs.rgbButtons[btnButton.bOffset] & 0x80 ) + { + b_Value = true; - case DT_MOUSEBUTTON: - l_Value = MAXAXISVALUE; - b_Value = ( btnButton.parentDevice->stateAs.mouseState.rgbButtons[btnButton.bOffset] & 0x80 ) != 0; - break; + if(( pcController->fKeyAbsoluteX && i < 2 ) + || ( pcController->fKeyAbsoluteY && i > 1 )) + { + if( pcController->wAxeBuffer[i] < MAXAXISVALUE ) + { + l_Value = pcController->wAxeBuffer[i] = min(( pcController->wAxeBuffer[i] + N64DIVIDER*3), MAXAXISVALUE ); + } + else + l_Value = MAXAXISVALUE; + } + else + { + if( pcController->wAxeBuffer[i] < MAXAXISVALUE ) + { + l_Value = pcController->wAxeBuffer[i] = min(( pcController->wAxeBuffer[i] * 2 + N64DIVIDER*5 ), MAXAXISVALUE ); + } + else + l_Value = MAXAXISVALUE; + } + } + else + { + if(( pcController->fKeyAbsoluteX && i < 2 ) + || ( pcController->fKeyAbsoluteY && i > 1 )) + { + l_Value = pcController->wAxeBuffer[i]; + b_Value = true; + } + else + { + if( pcController->wAxeBuffer[i] > N64DIVIDER ) + { + b_Value = true; + l_Value = pcController->wAxeBuffer[i] = pcController->wAxeBuffer[i] / 2 ; + } + else + b_Value = false; + } + } + break; - case DT_MOUSEAXE: - if( i < 2 ) - pcController->wAxeBuffer[i] += plRawState[btnButton.bOffset] * pcController->wMouseSensitivityX * MOUSESCALEVALUE; // l_Value = btnButton.parentDevice->stateAs.mouseState[btnButton.bOffset]; - else - pcController->wAxeBuffer[i] += plRawState[btnButton.bOffset] * pcController->wMouseSensitivityY * MOUSESCALEVALUE; // l_Value = btnButton.parentDevice->stateAs.mouseState[btnButton.bOffset]; + case DT_MOUSEBUTTON: + l_Value = MAXAXISVALUE; + b_Value = ( btnButton.parentDevice->stateAs.mouseState.rgbButtons[btnButton.bOffset] & 0x80 ) != 0; + break; - l_Value = pcController->wAxeBuffer[i]; + case DT_MOUSEAXE: + if( i < 2 ) + pcController->wAxeBuffer[i] += plRawState[btnButton.bOffset] * pcController->wMouseSensitivityX * MOUSESCALEVALUE; // l_Value = btnButton.parentDevice->stateAs.mouseState[btnButton.bOffset]; + else + pcController->wAxeBuffer[i] += plRawState[btnButton.bOffset] * pcController->wMouseSensitivityY * MOUSESCALEVALUE; // l_Value = btnButton.parentDevice->stateAs.mouseState[btnButton.bOffset]; - // wAxeBuffer is positive for axes 0 and 3 if buffer remains, else zero - // wAxeBuffer is negative for axes 1 and 2 if buffer remains, else zero + l_Value = pcController->wAxeBuffer[i]; - if(( pcController->bMouseMoveX == MM_ABS && i < 2 ) || ( pcController->bMouseMoveY == MM_ABS && i > 1 )) - pcController->wAxeBuffer[i] = min( max( MINAXISVALUE, pcController->wAxeBuffer[i]) , MAXAXISVALUE); - else if (( pcController->bMouseMoveX == MM_BUFF && i < 2 ) || ( pcController->bMouseMoveY == MM_BUFF && i > 1 )) - pcController->wAxeBuffer[i] = pcController->wAxeBuffer[i] * MOUSEBUFFERDECAY / 100; - else // "deadpan" mouse - { - pcController->wAxeBuffer[i] = 0; - } + // wAxeBuffer is positive for axes 0 and 3 if buffer remains, else zero + // wAxeBuffer is negative for axes 1 and 2 if buffer remains, else zero - if( btnButton.bAxisID == AI_AXE_N) // the mouse axis has the '-' flag set - { - fNegInput = !fNegInput; + if(( pcController->bMouseMoveX == MM_ABS && i < 2 ) || ( pcController->bMouseMoveY == MM_ABS && i > 1 )) + pcController->wAxeBuffer[i] = min( max( MINAXISVALUE, pcController->wAxeBuffer[i]) , MAXAXISVALUE); + else if (( pcController->bMouseMoveX == MM_BUFF && i < 2 ) || ( pcController->bMouseMoveY == MM_BUFF && i > 1 )) + pcController->wAxeBuffer[i] = pcController->wAxeBuffer[i] * MOUSEBUFFERDECAY / 100; + else // "deadpan" mouse + { + pcController->wAxeBuffer[i] = 0; + } - b_Value = ( l_Value < ZEROVALUE ); - } - else - { - b_Value = ( l_Value > ZEROVALUE ); - } + if( btnButton.bAxisID == AI_AXE_N) // the mouse axis has the '-' flag set + { + fNegInput = !fNegInput; - break; - - case DT_UNASSIGNED: - default: - b_Value = false; - } + b_Value = ( l_Value < ZEROVALUE ); + } + else + { + b_Value = ( l_Value > ZEROVALUE ); + } - if ( b_Value ) - { - if ( fNegInput ) - l_Value = -l_Value; - - if( i < 2 ) - lAxisValueX += l_Value; - else - lAxisValueY += l_Value; - } - } + break; - if( pcController->fKeyboard ) - { - if( pcController->fKeyAbsoluteX ) - { - if( pcController->wAxeBuffer[0] > pcController->wAxeBuffer[1] ) - { - pcController->wAxeBuffer[0] -= pcController->wAxeBuffer[1]; - pcController->wAxeBuffer[1] = 0; - } - else - { - pcController->wAxeBuffer[1] -= pcController->wAxeBuffer[0]; - pcController->wAxeBuffer[0] = 0; - } - } - if( pcController->fKeyAbsoluteY ) - { - if( pcController->wAxeBuffer[2] > pcController->wAxeBuffer[3] ) - { - pcController->wAxeBuffer[2] -= pcController->wAxeBuffer[3]; - pcController->wAxeBuffer[3] = 0; - } - else - { - pcController->wAxeBuffer[3] -= pcController->wAxeBuffer[2]; - pcController->wAxeBuffer[2] = 0; - } - } - } + case DT_UNASSIGNED: + default: + b_Value = false; + } + + if ( b_Value ) + { + if ( fNegInput ) + l_Value = -l_Value; + + if( i < 2 ) + lAxisValueX += l_Value; + else + lAxisValueY += l_Value; + } + } + + if( pcController->fKeyboard ) + { + if( pcController->fKeyAbsoluteX ) + { + if( pcController->wAxeBuffer[0] > pcController->wAxeBuffer[1] ) + { + pcController->wAxeBuffer[0] -= pcController->wAxeBuffer[1]; + pcController->wAxeBuffer[1] = 0; + } + else + { + pcController->wAxeBuffer[1] -= pcController->wAxeBuffer[0]; + pcController->wAxeBuffer[0] = 0; + } + } + if( pcController->fKeyAbsoluteY ) + { + if( pcController->wAxeBuffer[2] > pcController->wAxeBuffer[3] ) + { + pcController->wAxeBuffer[2] -= pcController->wAxeBuffer[3]; + pcController->wAxeBuffer[3] = 0; + } + else + { + pcController->wAxeBuffer[3] -= pcController->wAxeBuffer[2]; + pcController->wAxeBuffer[2] = 0; + } + } + } - if (pcController->bRapidFireEnabled) - { - if (pcController->bRapidFireCounter >= pcController->bRapidFireRate) - { - w_Buttons = (w_Buttons & 0xFF1F); - pcController->bRapidFireCounter = 0; - } - else - { - pcController->bRapidFireCounter = pcController->bRapidFireCounter + 1; - } - } + if (pcController->bRapidFireEnabled) + { + if (pcController->bRapidFireCounter >= pcController->bRapidFireRate) + { + w_Buttons = (w_Buttons & 0xFF1F); + pcController->bRapidFireCounter = 0; + } + else + { + pcController->bRapidFireCounter = pcController->bRapidFireCounter + 1; + } + } - if( pcController->fRealN64Range && ( lAxisValueX || lAxisValueY )) - { - long lAbsoluteX = ( lAxisValueX > 0 ) ? lAxisValueX : -lAxisValueX; - long lAbsoluteY = ( lAxisValueY > 0 ) ? lAxisValueY : -lAxisValueY; + if( pcController->fRealN64Range && ( lAxisValueX || lAxisValueY )) + { + long lAbsoluteX = ( lAxisValueX > 0 ) ? lAxisValueX : -lAxisValueX; + long lAbsoluteY = ( lAxisValueY > 0 ) ? lAxisValueY : -lAxisValueY; - long lRangeX; - long lRangeY; + long lRangeX; + long lRangeY; - if( lAbsoluteX > lAbsoluteY ) - { - lRangeX = MAXAXISVALUE; - lRangeY = lRangeX * lAbsoluteY / lAbsoluteX; - } - else - { - lRangeY = MAXAXISVALUE; - lRangeX = lRangeY * lAbsoluteX / lAbsoluteY; - } + if( lAbsoluteX > lAbsoluteY ) + { + lRangeX = MAXAXISVALUE; + lRangeY = lRangeX * lAbsoluteY / lAbsoluteX; + } + else + { + lRangeY = MAXAXISVALUE; + lRangeX = lRangeY * lAbsoluteX / lAbsoluteY; + } - // TODO: optimize this --rabid - double dRangeDiagonal = sqrt((double)(lRangeX * lRangeX + lRangeY * lRangeY)); -// __asm{ -// fld fRangeDiagonal -// fsqrt -// fstp fRangeDiagonal -// fwait -// } - double dRel = MAXAXISVALUE / dRangeDiagonal; + // TODO: optimize this --rabid + double dRangeDiagonal = sqrt((double)(lRangeX * lRangeX + lRangeY * lRangeY)); +// __asm{ +// fld fRangeDiagonal +// fsqrt +// fstp fRangeDiagonal +// fwait +// } + double dRel = MAXAXISVALUE / dRangeDiagonal; - *pdwData = MAKELONG(w_Buttons, - MAKEWORD( (BYTE)(min( max( MINAXISVALUE, (long)(lAxisValueX * d_ModifierX * dRel )), MAXAXISVALUE) / N64DIVIDER ), - (BYTE)(min( max( MINAXISVALUE, (long)(lAxisValueY * d_ModifierY * dRel )), MAXAXISVALUE) / N64DIVIDER ))); - } - else - { - *pdwData = MAKELONG(w_Buttons, - MAKEWORD( (BYTE)(min( max( MINAXISVALUE, (long)(lAxisValueX * d_ModifierX )), MAXAXISVALUE) / N64DIVIDER ), - (BYTE)(min( max( MINAXISVALUE, (long)(lAxisValueY * d_ModifierY )), MAXAXISVALUE) / N64DIVIDER ))); - } + *pdwData = MAKELONG(w_Buttons, + MAKEWORD( (BYTE)(min( max( MINAXISVALUE, (long)(lAxisValueX * d_ModifierX * dRel )), MAXAXISVALUE) / N64DIVIDER ), + (BYTE)(min( max( MINAXISVALUE, (long)(lAxisValueY * d_ModifierY * dRel )), MAXAXISVALUE) / N64DIVIDER ))); + } + else + { + *pdwData = MAKELONG(w_Buttons, + MAKEWORD( (BYTE)(min( max( MINAXISVALUE, (long)(lAxisValueX * d_ModifierX )), MAXAXISVALUE) / N64DIVIDER ), + (BYTE)(min( max( MINAXISVALUE, (long)(lAxisValueY * d_ModifierY )), MAXAXISVALUE) / N64DIVIDER ))); + } - return true; + return true; } bool InitDirectInput( HWND hWnd ) { - if( g_hDirectInputDLL == NULL ) - g_hDirectInputDLL = LoadLibrary( _T( "dinput8.dll" )); - if( g_hDirectInputDLL == NULL ) - { - ErrorMessage(IDS_ERR_DINOTFOUND, 0, false); - } - else if( !g_pDIHandle ) // is NULL if not yet initialized - { - HRESULT (WINAPI *lpGetDIHandle)( HINSTANCE, DWORD, REFIID, LPVOID*, LPUNKNOWN ) = NULL; - lpGetDIHandle = (HRESULT (WINAPI *)( HINSTANCE, DWORD, REFIID, LPVOID*, LPUNKNOWN ))GetProcAddress( g_hDirectInputDLL, "DirectInput8Create" ); + if( g_hDirectInputDLL == NULL ) + g_hDirectInputDLL = LoadLibrary( _T( "dinput8.dll" )); + if( g_hDirectInputDLL == NULL ) + { + ErrorMessage(IDS_ERR_DINOTFOUND, 0, false); + } + else if( !g_pDIHandle ) // is NULL if not yet initialized + { + HRESULT (WINAPI *lpGetDIHandle)( HINSTANCE, DWORD, REFIID, LPVOID*, LPUNKNOWN ) = NULL; + lpGetDIHandle = (HRESULT (WINAPI *)( HINSTANCE, DWORD, REFIID, LPVOID*, LPUNKNOWN ))GetProcAddress( g_hDirectInputDLL, "DirectInput8Create" ); - if( lpGetDIHandle != NULL ) - { - HRESULT hr; - hr = lpGetDIHandle( g_strEmuInfo.hinst, DIRECTINPUT_VERSION, - IID_IDirectInput8, (LPVOID*)&g_pDIHandle, NULL ); - if( FAILED( hr )) - { - ErrorMessage(IDS_ERR_DICREATE, 0, false); - g_pDIHandle = NULL; - FreeLibrary( g_hDirectInputDLL ); - g_hDirectInputDLL = NULL; - } - } - } + if( lpGetDIHandle != NULL ) + { + HRESULT hr; + hr = lpGetDIHandle( g_strEmuInfo.hinst, DIRECTINPUT_VERSION, + IID_IDirectInput8, (LPVOID*)&g_pDIHandle, NULL ); + if( FAILED( hr )) + { + ErrorMessage(IDS_ERR_DICREATE, 0, false); + g_pDIHandle = NULL; + FreeLibrary( g_hDirectInputDLL ); + g_hDirectInputDLL = NULL; + } + } + } - return (g_pDIHandle != NULL); + return (g_pDIHandle != NULL); } // release a DirectInput device. We don't need it anymore. void ReleaseDevice( LPDIRECTINPUTDEVICE8 &lpDirectInputDevice ) { - if( lpDirectInputDevice != NULL) - { - lpDirectInputDevice->Unacquire(); - lpDirectInputDevice->Release(); - lpDirectInputDevice = NULL; - } - return; + if( lpDirectInputDevice != NULL) + { + lpDirectInputDevice->Unacquire(); + lpDirectInputDevice->Release(); + lpDirectInputDevice = NULL; + } + return; } // release a DirectInput effect. We don't need it anymore. void ReleaseEffect( LPDIRECTINPUTEFFECT &lpDirectEffect ) { - if( lpDirectEffect != NULL) - { - // should unload the effect on release, I hope - lpDirectEffect->Release(); - lpDirectEffect = NULL; - } - return; + if( lpDirectEffect != NULL) + { + // should unload the effect on release, I hope + lpDirectEffect->Release(); + lpDirectEffect = NULL; + } + return; } // release our DirectInput effects and devices, our DirectInput handle, and then unload dinput library void FreeDirectInput () { - int i; - // release effects - for( i = 0; i < ARRAYSIZE( g_apdiEffect ); ++i ) - ReleaseEffect( g_apdiEffect[i] ); - ZeroMemory( g_apdiEffect, sizeof(g_apdiEffect) ); + int i; + // release effects + for( i = 0; i < ARRAYSIZE( g_apdiEffect ); ++i ) + ReleaseEffect( g_apdiEffect[i] ); + ZeroMemory( g_apdiEffect, sizeof(g_apdiEffect) ); - // release FF devices - for( i = 0; i << ARRAYSIZE(g_apFFDevice); ++i ) - ReleaseDevice( g_apFFDevice[i] ); - ZeroMemory( g_apFFDevice, sizeof(g_apFFDevice) ); + // release FF devices + for( i = 0; i << ARRAYSIZE(g_apFFDevice); ++i ) + ReleaseDevice( g_apFFDevice[i] ); + ZeroMemory( g_apFFDevice, sizeof(g_apFFDevice) ); - // release normal devices - for( i = 0; i < g_nDevices; i++ ) - ReleaseDevice( g_devList[i].didHandle ); - ZeroMemory( g_devList, sizeof(g_devList) ); - g_nDevices = 0; + // release normal devices + for( i = 0; i < g_nDevices; i++ ) + ReleaseDevice( g_devList[i].didHandle ); + ZeroMemory( g_devList, sizeof(g_devList) ); + g_nDevices = 0; - // release mouse device - ReleaseDevice( g_sysMouse.didHandle ); - ZeroMemory( &g_sysMouse, sizeof(g_sysMouse) ); + // release mouse device + ReleaseDevice( g_sysMouse.didHandle ); + ZeroMemory( &g_sysMouse, sizeof(g_sysMouse) ); // Release any DirectInput handles. - if( g_pDIHandle != NULL ) - { - g_pDIHandle->Release(); - g_pDIHandle = NULL; - } - // Unload the library. - if( g_hDirectInputDLL != NULL ) - { - FreeLibrary( g_hDirectInputDLL ); - g_hDirectInputDLL = NULL; - } - return; + if( g_pDIHandle != NULL ) + { + g_pDIHandle->Release(); + g_pDIHandle = NULL; + } + // Unload the library. + if( g_hDirectInputDLL != NULL ) + { + FreeLibrary( g_hDirectInputDLL ); + g_hDirectInputDLL = NULL; + } + return; } // Acquire our device. Our device might get unacquired for many many reasons, and we need to be able to reacquire it to get input again. // We use this a LOT. inline HRESULT AcquireDevice( LPDIRECTINPUTDEVICE8 lpDirectInputDevice ) { - HRESULT hResult = lpDirectInputDevice->Acquire(); - while( hResult == DIERR_INPUTLOST ) - hResult = lpDirectInputDevice->Acquire(); - if( SUCCEEDED( hResult )) - lpDirectInputDevice->Poll(); - return hResult; + HRESULT hResult = lpDirectInputDevice->Acquire(); + while( hResult == DIERR_INPUTLOST ) + hResult = lpDirectInputDevice->Acquire(); + if( SUCCEEDED( hResult )) + lpDirectInputDevice->Poll(); + return hResult; } // Called by the DirectInput enumerator for each FF device. What kind of force feedback effects does this device support? We'll store it in pvRef. BOOL CALLBACK EnumGetEffectTypes( LPCDIEFFECTINFO pdei, LPVOID pvRef ) { - BYTE bFFType = *(LPBYTE)pvRef; - bFFType |= ( pdei->dwEffType & DIEFT_CONSTANTFORCE ) ? RUMBLE_CONSTANT : 0; - bFFType |= ( pdei->dwEffType & DIEFT_RAMPFORCE ) ? RUMBLE_RAMP : 0; - bFFType |= ( pdei->dwEffType & DIEFT_CONDITION ) ? RUMBLE_CONDITION : 0; - bFFType |= ( pdei->dwEffType & DIEFT_PERIODIC ) ? RUMBLE_PERIODIC : 0; - bFFType |= ( pdei->dwEffType & DIEFT_CUSTOMFORCE ) ? RUMBLE_CUSTOM : 0; - *(WORD*)pvRef = bFFType; - return DIENUM_CONTINUE; + BYTE bFFType = *(LPBYTE)pvRef; + bFFType |= ( pdei->dwEffType & DIEFT_CONSTANTFORCE ) ? RUMBLE_CONSTANT : 0; + bFFType |= ( pdei->dwEffType & DIEFT_RAMPFORCE ) ? RUMBLE_RAMP : 0; + bFFType |= ( pdei->dwEffType & DIEFT_CONDITION ) ? RUMBLE_CONDITION : 0; + bFFType |= ( pdei->dwEffType & DIEFT_PERIODIC ) ? RUMBLE_PERIODIC : 0; + bFFType |= ( pdei->dwEffType & DIEFT_CUSTOMFORCE ) ? RUMBLE_CUSTOM : 0; + *(WORD*)pvRef = bFFType; + return DIENUM_CONTINUE; } // Called by the DirectInput enumerator for each attached DI device. We use it to make a list of devices. // EnumMakeDeviceList has been rewritten. --rabid BOOL CALLBACK EnumMakeDeviceList( LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef ) { - switch (GET_DIDEVICE_TYPE(lpddi->dwDevType)) { - // we don't need to do anything with these generic devices - case DI8DEVTYPE_DEVICE: - return DIENUM_CONTINUE; - break; - // these are potential xinput controllers, check them - case DI8DEVTYPE_GAMEPAD: - case DI8DEVTYPE_DRIVING: - case DI8DEVTYPE_JOYSTICK: - case DI8DEVTYPE_FLIGHT: - if (IsXInputDevice(&lpddi->guidProduct)) // Check if is XInput device --tecnicors - return DIENUM_CONTINUE; - break; - // for all other devices, continue on - default: - break; - } + switch (GET_DIDEVICE_TYPE(lpddi->dwDevType)) { + // we don't need to do anything with these generic devices + case DI8DEVTYPE_DEVICE: + return DIENUM_CONTINUE; + break; + // these are potential xinput controllers, check them + case DI8DEVTYPE_GAMEPAD: + case DI8DEVTYPE_DRIVING: + case DI8DEVTYPE_JOYSTICK: + case DI8DEVTYPE_FLIGHT: + if (IsXInputDevice(&lpddi->guidProduct)) // Check if is XInput device --tecnicors + return DIENUM_CONTINUE; + break; + // for all other devices, continue on + default: + break; + } - if (IsEqualGUID(g_sysMouse.guidInstance, lpddi->guidInstance)) - return DIENUM_CONTINUE; + if (IsEqualGUID(g_sysMouse.guidInstance, lpddi->guidInstance)) + return DIENUM_CONTINUE; - for (int i = 0; i < g_nDevices; i++) - if (IsEqualGUID(g_devList[i].guidInstance, lpddi->guidInstance)) - return ( g_nDevices < ARRAYSIZE(g_devList) ) ? DIENUM_CONTINUE : DIENUM_STOP; + for (int i = 0; i < g_nDevices; i++) + if (IsEqualGUID(g_devList[i].guidInstance, lpddi->guidInstance)) + return ( g_nDevices < ARRAYSIZE(g_devList) ) ? DIENUM_CONTINUE : DIENUM_STOP; - if (g_nDevices < ARRAYSIZE(g_devList)) // our buffer isn't full yet and the device doesn't already exist in our table - { - lstrcpyn( g_devList[g_nDevices].szProductName, lpddi->tszProductName, MAX_PATH ); - g_devList[g_nDevices].dwDevType = lpddi->dwDevType; - g_devList[g_nDevices].guidInstance = lpddi->guidInstance; + if (g_nDevices < ARRAYSIZE(g_devList)) // our buffer isn't full yet and the device doesn't already exist in our table + { + lstrcpyn( g_devList[g_nDevices].szProductName, lpddi->tszProductName, MAX_PATH ); + g_devList[g_nDevices].dwDevType = lpddi->dwDevType; + g_devList[g_nDevices].guidInstance = lpddi->guidInstance; - g_devList[g_nDevices].bProductCounter = 0; // counting similar devices - for( int i = 0; i < g_nDevices; ++i ) - { - if( !lstrcmp( lpddi->tszProductName, g_devList[i].szProductName )) - { - if( g_devList[g_nDevices].bProductCounter == 0 ) - { - g_devList[g_nDevices].bProductCounter = 2; - if( g_devList[i].bProductCounter == 0 ) - g_devList[i].bProductCounter = 1; - } - else - g_devList[g_nDevices].bProductCounter++; // give em instance numbers - } - } - if( !lstrcmp( lpddi->tszProductName, TEXT( STRING_ADAPTOID ))) - g_devList[g_nDevices].bEffType = RUMBLE_DIRECT; - else - g_devList[g_nDevices].bEffType = RUMBLE_NONE; + g_devList[g_nDevices].bProductCounter = 0; // counting similar devices + for( int i = 0; i < g_nDevices; ++i ) + { + if( !lstrcmp( lpddi->tszProductName, g_devList[i].szProductName )) + { + if( g_devList[g_nDevices].bProductCounter == 0 ) + { + g_devList[g_nDevices].bProductCounter = 2; + if( g_devList[i].bProductCounter == 0 ) + g_devList[i].bProductCounter = 1; + } + else + g_devList[g_nDevices].bProductCounter++; // give em instance numbers + } + } + if( !lstrcmp( lpddi->tszProductName, TEXT( STRING_ADAPTOID ))) + g_devList[g_nDevices].bEffType = RUMBLE_DIRECT; + else + g_devList[g_nDevices].bEffType = RUMBLE_NONE; - if ( GetInputDevice(g_strEmuInfo.hMainWindow, g_devList[g_nDevices].didHandle, lpddi->guidInstance, lpddi->dwDevType, DIB_DEVICE) ) - { - g_devList[g_nDevices].didHandle->EnumEffects( EnumGetEffectTypes, &g_devList[g_nDevices].bEffType, DIEFT_ALL ); - g_nDevices++; - } - else - ZeroMemory(&g_devList[g_nDevices], sizeof(DEVICE)); - } + if ( GetInputDevice(g_strEmuInfo.hMainWindow, g_devList[g_nDevices].didHandle, lpddi->guidInstance, lpddi->dwDevType, DIB_DEVICE) ) + { + g_devList[g_nDevices].didHandle->EnumEffects( EnumGetEffectTypes, &g_devList[g_nDevices].bEffType, DIEFT_ALL ); + g_nDevices++; + } + else + ZeroMemory(&g_devList[g_nDevices], sizeof(DEVICE)); + } - return ( g_nDevices < ARRAYSIZE(g_devList) ) ? DIENUM_CONTINUE : DIENUM_STOP; + return ( g_nDevices < ARRAYSIZE(g_devList) ) ? DIENUM_CONTINUE : DIENUM_STOP; } // Called by an enumerator in GetInputDevice to determine if a device is attached at all. BOOL CALLBACK EnumIsDeviceAvailable( LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef ) { - if( lpddi->guidInstance == *(GUID*)((LPVOID*)pvRef)[0] ) - { - *(bool*)((LPVOID*)pvRef)[1] = true; - return DIENUM_STOP; - } + if( lpddi->guidInstance == *(GUID*)((LPVOID*)pvRef)[0] ) + { + *(bool*)((LPVOID*)pvRef)[1] = true; + return DIENUM_STOP; + } - return DIENUM_CONTINUE; + return DIENUM_CONTINUE; } // Called by an axis enumerator in GetInputDevice. Set the min and max range so we can pass the rec'd value right to the emulator. BOOL CALLBACK EnumSetObjectsAxis( LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef) { - LPDIRECTINPUTDEVICE8 lpDirectInputDevice = (LPDIRECTINPUTDEVICE8)pvRef; - DIPROPRANGE diprg; + LPDIRECTINPUTDEVICE8 lpDirectInputDevice = (LPDIRECTINPUTDEVICE8)pvRef; + DIPROPRANGE diprg; - diprg.diph.dwSize = sizeof(DIPROPRANGE); - diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER); - diprg.diph.dwHow = DIPH_BYID; - diprg.diph.dwObj = lpddoi->dwType; - diprg.lMin = MINAXISVALUE; - diprg.lMax = MAXAXISVALUE; + diprg.diph.dwSize = sizeof(DIPROPRANGE); + diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER); + diprg.diph.dwHow = DIPH_BYID; + diprg.diph.dwObj = lpddoi->dwType; + diprg.lMin = MINAXISVALUE; + diprg.lMax = MAXAXISVALUE; - lpDirectInputDevice->SetProperty(DIPROP_RANGE, &diprg.diph); // HACK: Usually works, but not all devices support setting range. + lpDirectInputDevice->SetProperty(DIPROP_RANGE, &diprg.diph); // HACK: Usually works, but not all devices support setting range. - return DIENUM_CONTINUE; + return DIENUM_CONTINUE; } // **if passed an existing DirectInputDevice which matches gGuid -// unacquires it, and sets its cooperative level (reinitialize) +// unacquires it, and sets its cooperative level (reinitialize) // **if the existing device does not match the passed gGuid, the existing device is released // **if no device was passed or gGuid did not match -// searches for the controller matching gGuid in connected and available devices -// creates a DirectInputDevice -// sets its data format -// sets its cooperative level -// for joysticks, calls EnumSetObjectsAxis for each axis +// searches for the controller matching gGuid in connected and available devices +// creates a DirectInputDevice +// sets its data format +// sets its cooperative level +// for joysticks, calls EnumSetObjectsAxis for each axis // GetInputDevice always leaves the returned device in an UNACQUIRED state. bool GetInputDevice( HWND hWnd, LPDIRECTINPUTDEVICE8 &lpDirectInputDevice, GUID gGuid, DWORD dwDevType, DWORD dwCooperativeLevel ) { - DebugWriteA("GetInputDevice: gGuid is {%08.8lX-%04.4hX-%04.4hX-%02.2X%02.2X-%02.2X%02.2X%02.2X%02.2X%02.2X%02.2X}\n", gGuid.Data1, gGuid.Data2, gGuid.Data3, gGuid.Data4[0], gGuid.Data4[1], gGuid.Data4[2], gGuid.Data4[3], gGuid.Data4[4], gGuid.Data4[5], gGuid.Data4[6], gGuid.Data4[7]); - if( lpDirectInputDevice != NULL) - { - DIDEVICEINSTANCE didDev; - didDev.dwSize = sizeof(DIDEVICEINSTANCE); - lpDirectInputDevice->GetDeviceInfo( &didDev ); + DebugWriteA("GetInputDevice: gGuid is {%08.8lX-%04.4hX-%04.4hX-%02.2X%02.2X-%02.2X%02.2X%02.2X%02.2X%02.2X%02.2X}\n", gGuid.Data1, gGuid.Data2, gGuid.Data3, gGuid.Data4[0], gGuid.Data4[1], gGuid.Data4[2], gGuid.Data4[3], gGuid.Data4[4], gGuid.Data4[5], gGuid.Data4[6], gGuid.Data4[7]); + if( lpDirectInputDevice != NULL) + { + DIDEVICEINSTANCE didDev; + didDev.dwSize = sizeof(DIDEVICEINSTANCE); + lpDirectInputDevice->GetDeviceInfo( &didDev ); - if( didDev.guidInstance == gGuid ) - { // we've already gotten this device; unacquire it and initialize - DebugWriteA("GetInputDevice: already created, attempting to reinit\n"); - lpDirectInputDevice->Unacquire(); - lpDirectInputDevice->SetCooperativeLevel( hWnd, dwCooperativeLevel ); - return true; - } - else - ReleaseDevice( lpDirectInputDevice ); - } + if( didDev.guidInstance == gGuid ) + { // we've already gotten this device; unacquire it and initialize + DebugWriteA("GetInputDevice: already created, attempting to reinit\n"); + lpDirectInputDevice->Unacquire(); + lpDirectInputDevice->SetCooperativeLevel( hWnd, dwCooperativeLevel ); + return true; + } + else + ReleaseDevice( lpDirectInputDevice ); + } - HRESULT hResult; - - LPCDIDATAFORMAT ppDiDataFormat = NULL; - bool Success = false; + HRESULT hResult; - switch( LOBYTE(dwDevType) ) - { - case DI8DEVTYPE_KEYBOARD: - ppDiDataFormat = &c_dfDIKeyboard; - break; + LPCDIDATAFORMAT ppDiDataFormat = NULL; + bool Success = false; - case DI8DEVTYPE_MOUSE: - ppDiDataFormat = &c_dfDIMouse2; - break; + switch( LOBYTE(dwDevType) ) + { + case DI8DEVTYPE_KEYBOARD: + ppDiDataFormat = &c_dfDIKeyboard; + break; - //case DI8DEVTYPE_GAMEPAD: - //case DI8DEVTYPE_JOYSTICK: - //case DI8DEVTYPE_DRIVING: - //case DI8DEVTYPE_1STPERSON: - //case DI8DEVTYPE_FLIGHT: - default: // assume everything else is a gamepad; probably not the best idea but it works - ppDiDataFormat = &c_dfDIJoystick; - break; - } + case DI8DEVTYPE_MOUSE: + ppDiDataFormat = &c_dfDIMouse2; + break; - bool bDeviceAvailable = false; - - VOID* aRef[2] = { &gGuid, &bDeviceAvailable }; - - // for each available device in our dwDevType category, run EnumIsDeviceAvailable with params "aRef" - g_pDIHandle->EnumDevices( DI8DEVCLASS_ALL, EnumIsDeviceAvailable, (LPVOID)aRef, DIEDFL_ATTACHEDONLY ); - - if( !bDeviceAvailable ) - { - DebugWriteA("GetInputDevice: Device does not appear available\n"); - return false; - } - - hResult = g_pDIHandle->CreateDevice( gGuid, &lpDirectInputDevice, NULL ); - - if( SUCCEEDED( hResult )) - { - hResult = lpDirectInputDevice->SetDataFormat( ppDiDataFormat ); - hResult = lpDirectInputDevice->SetCooperativeLevel( hWnd, dwCooperativeLevel ); - - Success = SUCCEEDED( hResult ); - if (!Success) - { - DebugWriteA("GetInputDevice: SetCooperativeLevel failed\n"); - } - } - else - DebugWriteA("GetInputDevice: CreateDevice failed\n"); + //case DI8DEVTYPE_GAMEPAD: + //case DI8DEVTYPE_JOYSTICK: + //case DI8DEVTYPE_DRIVING: + //case DI8DEVTYPE_1STPERSON: + //case DI8DEVTYPE_FLIGHT: + default: // assume everything else is a gamepad; probably not the best idea but it works + ppDiDataFormat = &c_dfDIJoystick; + break; + } - if( Success && ( ppDiDataFormat == &c_dfDIJoystick )) - lpDirectInputDevice->EnumObjects( EnumSetObjectsAxis, lpDirectInputDevice, DIDFT_AXIS ); + bool bDeviceAvailable = false; - return Success; + VOID* aRef[2] = { &gGuid, &bDeviceAvailable }; + + // for each available device in our dwDevType category, run EnumIsDeviceAvailable with params "aRef" + g_pDIHandle->EnumDevices( DI8DEVCLASS_ALL, EnumIsDeviceAvailable, (LPVOID)aRef, DIEDFL_ATTACHEDONLY ); + + if( !bDeviceAvailable ) + { + DebugWriteA("GetInputDevice: Device does not appear available\n"); + return false; + } + + hResult = g_pDIHandle->CreateDevice( gGuid, &lpDirectInputDevice, NULL ); + + if( SUCCEEDED( hResult )) + { + hResult = lpDirectInputDevice->SetDataFormat( ppDiDataFormat ); + hResult = lpDirectInputDevice->SetCooperativeLevel( hWnd, dwCooperativeLevel ); + + Success = SUCCEEDED( hResult ); + if (!Success) + { + DebugWriteA("GetInputDevice: SetCooperativeLevel failed\n"); + } + } + else + DebugWriteA("GetInputDevice: CreateDevice failed\n"); + + if( Success && ( ppDiDataFormat == &c_dfDIJoystick )) + lpDirectInputDevice->EnumObjects( EnumSetObjectsAxis, lpDirectInputDevice, DIDFT_AXIS ); + + return Success; } // How many force feedback axes (motors) does our device have? We want to rumble them all. BOOL CALLBACK EnumCountFFAxes( LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pnAxes ) { - *(DWORD*)pnAxes += 1; - return DIENUM_CONTINUE; + *(DWORD*)pnAxes += 1; + return DIENUM_CONTINUE; } // Create a force feedback effect handle and downloads the effect. Parameters are self-explanatory. bool CreateEffectHandle( HWND hWnd, LPDIRECTINPUTDEVICE8 lpDirectInputDevice, LPDIRECTINPUTEFFECT &pDIEffect, BYTE bRumbleTyp, long lStrength ) { - if( pDIEffect ) - ReleaseEffect( pDIEffect ); + if( pDIEffect ) + ReleaseEffect( pDIEffect ); - if( !lpDirectInputDevice || bRumbleTyp == RUMBLE_DIRECT ) - return false; + if( !lpDirectInputDevice || bRumbleTyp == RUMBLE_DIRECT ) + return false; - DWORD nAxes = 0; - DWORD rgdwAxes[] = { DIJOFS_X, DIJOFS_Y }; + DWORD nAxes = 0; + DWORD rgdwAxes[] = { DIJOFS_X, DIJOFS_Y }; - HRESULT hResult; + HRESULT hResult; - // count the FF - axes of the joystick - lpDirectInputDevice->EnumObjects( EnumCountFFAxes, &nAxes, DIDFT_FFACTUATOR | DIDFT_AXIS ); + // count the FF - axes of the joystick + lpDirectInputDevice->EnumObjects( EnumCountFFAxes, &nAxes, DIDFT_FFACTUATOR | DIDFT_AXIS ); - if( nAxes == 0 ) - return false; - nAxes = min( nAxes, 2 ); + if( nAxes == 0 ) + return false; + nAxes = min( nAxes, 2 ); - // Must be unaquired for setting stuff like Co-op Level - hResult = lpDirectInputDevice->Unacquire(); - //FF Requires EXCLUSIVE LEVEL, took me hours to find the reason why it wasnt working - hResult = lpDirectInputDevice->SetCooperativeLevel( hWnd, DIB_FF ); + // Must be unaquired for setting stuff like Co-op Level + hResult = lpDirectInputDevice->Unacquire(); + //FF Requires EXCLUSIVE LEVEL, took me hours to find the reason why it wasnt working + hResult = lpDirectInputDevice->SetCooperativeLevel( hWnd, DIB_FF ); - // fail if we can't set coop level --rabid - if (hResult != DI_OK) - { - DebugWriteA("CreateEffectHandle: couldn't set coop level: %08X\n", hResult); - return false; - } + // fail if we can't set coop level --rabid + if (hResult != DI_OK) + { + DebugWriteA("CreateEffectHandle: couldn't set coop level: %08X\n", hResult); + return false; + } // Since we will be playing force feedback effects, we should disable the // auto-centering spring. - DIPROPDWORD dipdw; + DIPROPDWORD dipdw; dipdw.diph.dwSize = sizeof(DIPROPDWORD); dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); dipdw.diph.dwObj = 0; dipdw.diph.dwHow = DIPH_DEVICE; dipdw.dwData = FALSE; - - hResult = lpDirectInputDevice->SetProperty( DIPROP_AUTOCENTER, &dipdw.diph ); - long rglDirection[] = { 1, 1 }; - LPGUID EffectGuid; + hResult = lpDirectInputDevice->SetProperty( DIPROP_AUTOCENTER, &dipdw.diph ); + + long rglDirection[] = { 1, 1 }; + LPGUID EffectGuid; DIEFFECT eff; ZeroMemory( &eff, sizeof(eff) ); - eff.dwSize = sizeof(DIEFFECT); - eff.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS; - eff.dwGain = lStrength * 100; + eff.dwSize = sizeof(DIEFFECT); + eff.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS; + eff.dwGain = lStrength * 100; eff.dwTriggerButton = DIEB_NOTRIGGER; eff.dwTriggerRepeatInterval = 0; eff.cAxes = nAxes; //Number of Axes eff.rgdwAxes = rgdwAxes; eff.rglDirection = rglDirection; eff.lpEnvelope = NULL; - eff.dwStartDelay = 0; + eff.dwStartDelay = 0; - DICONSTANTFORCE cf; - DIRAMPFORCE rf; - DIPERIODIC pf; + DICONSTANTFORCE cf; + DIRAMPFORCE rf; + DIPERIODIC pf; - switch( bRumbleTyp ) - { - case RUMBLE_CONSTANT: - EffectGuid = (GUID*)&GUID_ConstantForce; + switch( bRumbleTyp ) + { + case RUMBLE_CONSTANT: + EffectGuid = (GUID*)&GUID_ConstantForce; - eff.dwDuration = 150000; // microseconds - eff.dwSamplePeriod = 0; - eff.cbTypeSpecificParams = sizeof(DICONSTANTFORCE); - eff.lpvTypeSpecificParams = &cf; + eff.dwDuration = 150000; // microseconds + eff.dwSamplePeriod = 0; + eff.cbTypeSpecificParams = sizeof(DICONSTANTFORCE); + eff.lpvTypeSpecificParams = &cf; - cf.lMagnitude = 10000; - break; - case RUMBLE_RAMP: - EffectGuid = (GUID*)&GUID_RampForce; - - eff.dwDuration = 300000; // microseconds - eff.dwSamplePeriod = 0; - eff.cbTypeSpecificParams = sizeof(DIRAMPFORCE); - eff.lpvTypeSpecificParams = &rf; + cf.lMagnitude = 10000; + break; + case RUMBLE_RAMP: + EffectGuid = (GUID*)&GUID_RampForce; - rf.lStart = 10000; - rf.lEnd = 2000; - break; - - case RUMBLE_CONDITION: - case RUMBLE_PERIODIC: - EffectGuid = (GUID*)&GUID_Sine; + eff.dwDuration = 300000; // microseconds + eff.dwSamplePeriod = 0; + eff.cbTypeSpecificParams = sizeof(DIRAMPFORCE); + eff.lpvTypeSpecificParams = &rf; - eff.dwDuration = 150000; // microseconds - eff.dwSamplePeriod = 0; - eff.cbTypeSpecificParams = sizeof(DIPERIODIC); - eff.lpvTypeSpecificParams = &pf; + rf.lStart = 10000; + rf.lEnd = 2000; + break; - pf.dwMagnitude = 10000; - pf.lOffset = 0; - pf.dwPhase = 0; - pf.dwPeriod = 2000; - break; + case RUMBLE_CONDITION: + case RUMBLE_PERIODIC: + EffectGuid = (GUID*)&GUID_Sine; - case RUMBLE_NONE: - case RUMBLE_CUSTOM: - default: - return false; - } + eff.dwDuration = 150000; // microseconds + eff.dwSamplePeriod = 0; + eff.cbTypeSpecificParams = sizeof(DIPERIODIC); + eff.lpvTypeSpecificParams = &pf; - hResult = lpDirectInputDevice->CreateEffect( *EffectGuid, &eff, &pDIEffect, NULL ); + pf.dwMagnitude = 10000; + pf.lOffset = 0; + pf.dwPhase = 0; + pf.dwPeriod = 2000; + break; - if (hResult == DI_OK) - { - hResult = lpDirectInputDevice->Acquire(); - hResult = pDIEffect->Download(); - } - else - { - DebugWriteA("CreateEffectHandle: didn't CreateEffect: %08X\n", hResult); - } - return SUCCEEDED( hResult ); + case RUMBLE_NONE: + case RUMBLE_CUSTOM: + default: + return false; + } + + hResult = lpDirectInputDevice->CreateEffect( *EffectGuid, &eff, &pDIEffect, NULL ); + + if (hResult == DI_OK) + { + hResult = lpDirectInputDevice->Acquire(); + hResult = pDIEffect->Download(); + } + else + { + DebugWriteA("CreateEffectHandle: didn't CreateEffect: %08X\n", hResult); + } + return SUCCEEDED( hResult ); } // Counts how many of each type of button assignment (keyboard, mouse, gamepad) DWORD CountControllerStructDevs( CONTROLLER *pController ) { - BYTE bMouse = 0, bKeyboard = 0, bGamePad = 0; - BYTE bDType; + BYTE bMouse = 0, bKeyboard = 0, bGamePad = 0; + BYTE bDType; - bool fModifier = ( pController->pModifiers != NULL ); - int i = ( fModifier ) ? pController->nModifiers : ARRAYSIZE( pController->aButton ); - i--; + bool fModifier = ( pController->pModifiers != NULL ); + int i = ( fModifier ) ? pController->nModifiers : ARRAYSIZE( pController->aButton ); + i--; - for( ; i >= 0 || fModifier; --i ) - { - if( i < 0 ) - { - i = ARRAYSIZE( pController->aButton ) - 1; - fModifier = false; - } + for( ; i >= 0 || fModifier; --i ) + { + if( i < 0 ) + { + i = ARRAYSIZE( pController->aButton ) - 1; + fModifier = false; + } - bDType = ( fModifier ) ? pController->pModifiers[i].btnButton.bBtnType - : pController->aButton[i].bBtnType; + bDType = ( fModifier ) ? pController->pModifiers[i].btnButton.bBtnType + : pController->aButton[i].bBtnType; - switch( bDType ) - { - case DT_JOYBUTTON: - case DT_JOYAXE: - case DT_JOYSLIDER: - case DT_JOYPOV: - ++bGamePad; - break; + switch( bDType ) + { + case DT_JOYBUTTON: + case DT_JOYAXE: + case DT_JOYSLIDER: + case DT_JOYPOV: + ++bGamePad; + break; - case DT_KEYBUTTON: - ++bKeyboard; - break; + case DT_KEYBUTTON: + ++bKeyboard; + break; - case DT_MOUSEBUTTON: - case DT_MOUSEAXE: - ++bMouse; - break; - } - } + case DT_MOUSEBUTTON: + case DT_MOUSEAXE: + ++bMouse; + break; + } + } - pController->fGamePad = bGamePad != 0; - pController->fKeyboard = bKeyboard != 0; - pController->fMouse = bMouse != 0; + pController->fGamePad = bGamePad != 0; + pController->fKeyboard = bKeyboard != 0; + pController->fMouse = bMouse != 0; - return MAKELONG( MAKEWORD( bGamePad, bMouse ), MAKEWORD( bKeyboard, ( bMouse + bKeyboard + bGamePad ))); + return MAKELONG( MAKEWORD( bGamePad, bMouse ), MAKEWORD( bKeyboard, ( bMouse + bKeyboard + bGamePad ))); } // PrepareInputDevices rewritten --rabid bool PrepareInputDevices() { - bool fKeyboard = false; - bool fMouse = false; - bool fGamePad = false; + bool fKeyboard = false; + bool fMouse = false; + bool fGamePad = false; - for( int i = 0; i < ARRAYSIZE( g_pcControllers ); ++i ) - { - fGamePad = false; - if( g_pcControllers[i].fPlugged ) - { - CountControllerStructDevs( &g_pcControllers[i] ); + for( int i = 0; i < ARRAYSIZE( g_pcControllers ); ++i ) + { + fGamePad = false; + if( g_pcControllers[i].fPlugged ) + { + CountControllerStructDevs( &g_pcControllers[i] ); - fKeyboard = g_pcControllers[i].fKeyboard != 0; - fMouse = g_pcControllers[i].fMouse != 0; - fGamePad = ( g_pcControllers[i].fGamePad != 0); // we'll assume for now that there's a gamepad to go with those buttons - } + fKeyboard = g_pcControllers[i].fKeyboard != 0; + fMouse = g_pcControllers[i].fMouse != 0; + fGamePad = ( g_pcControllers[i].fGamePad != 0); // we'll assume for now that there's a gamepad to go with those buttons + } - ReleaseEffect( g_apdiEffect[i] ); - if( g_pcControllers[i].guidFFDevice != GUID_NULL && GetInputDevice( g_strEmuInfo.hMainWindow, g_apFFDevice[i], g_pcControllers[i].guidFFDevice, DI8DEVTYPE_JOYSTICK, DIB_FF )) // not necessarily a joystick type device, but we don't use the data anyway - { - DIDEVICEINSTANCE diDev; - diDev.dwSize = sizeof( DIDEVICEINSTANCE ); + ReleaseEffect( g_apdiEffect[i] ); + if( g_pcControllers[i].guidFFDevice != GUID_NULL && GetInputDevice( g_strEmuInfo.hMainWindow, g_apFFDevice[i], g_pcControllers[i].guidFFDevice, DI8DEVTYPE_JOYSTICK, DIB_FF )) // not necessarily a joystick type device, but we don't use the data anyway + { + DIDEVICEINSTANCE diDev; + diDev.dwSize = sizeof( DIDEVICEINSTANCE ); - g_apFFDevice[i]->GetDeviceInfo( &diDev ); + g_apFFDevice[i]->GetDeviceInfo( &diDev ); - if( !lstrcmp( diDev.tszProductName, _T( STRING_ADAPTOID ))) - { - g_pcControllers[i].fIsAdaptoid = true; - DebugWriteA("FF device on controller %d is of type Adaptoid\n", i+1); - } - else - { - g_pcControllers[i].fIsAdaptoid = false; - } + if( !lstrcmp( diDev.tszProductName, _T( STRING_ADAPTOID ))) + { + g_pcControllers[i].fIsAdaptoid = true; + DebugWriteA("FF device on controller %d is of type Adaptoid\n", i+1); + } + else + { + g_pcControllers[i].fIsAdaptoid = false; + } - if ( CreateEffectHandle( i, g_pcControllers[i].bRumbleTyp, g_pcControllers[i].bRumbleStrength ) ) - { - AcquireDevice( g_apFFDevice[i] ); - DebugWriteA("Got FF device %d\n", i); - } - else - DebugWriteA("Couldn't get FF device: CreateEffectHandle failed!\n"); - } - else - { - g_apFFDevice[i] = NULL; - DebugWriteA("Didn't get FF device %d\n", i); - } - } + if ( CreateEffectHandle( i, g_pcControllers[i].bRumbleTyp, g_pcControllers[i].bRumbleStrength ) ) + { + AcquireDevice( g_apFFDevice[i] ); + DebugWriteA("Got FF device %d\n", i); + } + else + DebugWriteA("Couldn't get FF device: CreateEffectHandle failed!\n"); + } + else + { + g_apFFDevice[i] = NULL; + DebugWriteA("Didn't get FF device %d\n", i); + } + } - if( fMouse ) - { - if( !g_sysMouse.didHandle ) - { - if( GetInputDevice( g_strEmuInfo.hMainWindow, g_sysMouse.didHandle, GUID_SysMouse, DI8DEVTYPE_MOUSE, g_bExclusiveMouse ? DIB_MOUSE : DIB_KEYBOARD )) - { - AcquireDevice( g_sysMouse.didHandle ); - } - } - } - else - { - g_bExclusiveMouse = false; - } + if( fMouse ) + { + if( !g_sysMouse.didHandle ) + { + if( GetInputDevice( g_strEmuInfo.hMainWindow, g_sysMouse.didHandle, GUID_SysMouse, DI8DEVTYPE_MOUSE, g_bExclusiveMouse ? DIB_MOUSE : DIB_KEYBOARD )) + { + AcquireDevice( g_sysMouse.didHandle ); + } + } + } + else + { + g_bExclusiveMouse = false; + } - return true; + return true; } bool IsAdaptoidCommandSupported( LPDIRECTINPUTDEVICE8 lpDirectInputDevice, DWORD cmd ) @@ -1122,16 +1122,16 @@ bool IsAdaptoidCommandSupported( LPDIRECTINPUTDEVICE8 lpDirectInputDevice, DWORD DWORD inbuf, outbuf; HRESULT hr; - esc.dwSize = sizeof(esc); - esc.dwCommand = ADAPT_TEST; // command to determine if a command is supported - esc.lpvInBuffer = &inbuf; - esc.cbInBuffer = 4; - esc.lpvOutBuffer = &outbuf; - esc.cbOutBuffer = 4; - inbuf = cmd; // command that we are asking is supported - outbuf = 0; + esc.dwSize = sizeof(esc); + esc.dwCommand = ADAPT_TEST; // command to determine if a command is supported + esc.lpvInBuffer = &inbuf; + esc.cbInBuffer = 4; + esc.lpvOutBuffer = &outbuf; + esc.cbOutBuffer = 4; + inbuf = cmd; // command that we are asking is supported + outbuf = 0; - hr = lpDirectInputDevice->Escape(&esc); + hr = lpDirectInputDevice->Escape(&esc); return( SUCCEEDED(hr) && esc.cbOutBuffer == 4 && outbuf == 0xB0CAB0CA ); } @@ -1140,9 +1140,9 @@ bool IsAdaptoidCommandSupported( LPDIRECTINPUTDEVICE8 lpDirectInputDevice, DWORD // Direct Adaptoid debugging stuff. void _debugAd( LPCSTR szMessage, HRESULT res ) { - LPCSTR suc = (SUCCEEDED(res)) ? "OK" : "FAILED"; + LPCSTR suc = (SUCCEEDED(res)) ? "OK" : "FAILED"; - DebugWriteA( "%s: %s (RC:%08X)\n", szMessage, suc, res ); + DebugWriteA( "%s: %s (RC:%08X)\n", szMessage, suc, res ); } #endif // #ifdef _DEBUG @@ -1157,10 +1157,10 @@ HRESULT DirectRumbleCommand( LPDIRECTINPUTDEVICE8 lpDirectInputDevice, DWORD cmd esc.lpvOutBuffer = NULL; esc.cbOutBuffer = 0; - HRESULT hr = lpDirectInputDevice->Escape(&esc); + HRESULT hr = lpDirectInputDevice->Escape(&esc); #ifdef _DEBUG - _debugAd( "Direct Adaptoid RumbleCommand", hr ); + _debugAd( "Direct Adaptoid RumbleCommand", hr ); #endif // #ifdef _DEBUG return hr; @@ -1174,13 +1174,13 @@ HRESULT InitializeAdaptoid( LPDIRECTINPUTDEVICE8 lpDirectInputDevice, LPBYTE sta esc.dwCommand = ADAPT_INIT; // Initialize Pak esc.lpvInBuffer = NULL; esc.cbInBuffer = 0; - esc.lpvOutBuffer = status; + esc.lpvOutBuffer = status; esc.cbOutBuffer = 1; - HRESULT hr = lpDirectInputDevice->Escape(&esc); + HRESULT hr = lpDirectInputDevice->Escape(&esc); #ifdef _DEBUG - _debugAd( "Direct Adaptoid InitPak", hr ); + _debugAd( "Direct Adaptoid InitPak", hr ); #endif // #ifdef _DEBUG return hr; @@ -1194,15 +1194,15 @@ HRESULT ReadAdaptoidPak( LPDIRECTINPUTDEVICE8 lpDirectInputDevice, DWORD addr, L esc.dwCommand = ADAPT_READPAK; // Read 32 bytes from pak esc.lpvInBuffer = &addr; esc.cbInBuffer = 4; - esc.lpvOutBuffer = data; + esc.lpvOutBuffer = data; esc.cbOutBuffer = 32; - HRESULT hr = lpDirectInputDevice->Escape(&esc); + HRESULT hr = lpDirectInputDevice->Escape(&esc); #ifdef _DEBUG - LPCSTR suc = (SUCCEEDED(hr)) ? "OK" : "FAILED"; + LPCSTR suc = (SUCCEEDED(hr)) ? "OK" : "FAILED"; - DebugWriteA( "Direct Adaptoid ReadPak(Addr:%04X): %s (RC:%08X)\n", addr, suc, hr ); + DebugWriteA( "Direct Adaptoid ReadPak(Addr:%04X): %s (RC:%08X)\n", addr, suc, hr ); #endif // #ifdef _DEBUG return hr; @@ -1224,15 +1224,15 @@ HRESULT WriteAdaptoidPak( LPDIRECTINPUTDEVICE8 lpDirectInputDevice, DWORD addr, esc.dwCommand = ADAPT_WRITEPAK; // Write 32 bytes to pak esc.lpvInBuffer = &buf; esc.cbInBuffer = 36; - esc.lpvOutBuffer = NULL; + esc.lpvOutBuffer = NULL; esc.cbOutBuffer = 0; - - HRESULT hr = lpDirectInputDevice->Escape(&esc); + + HRESULT hr = lpDirectInputDevice->Escape(&esc); #ifdef _DEBUG - LPCSTR suc = (SUCCEEDED(hr)) ? "OK" : "FAILED"; + LPCSTR suc = (SUCCEEDED(hr)) ? "OK" : "FAILED"; - DebugWriteA( "Direct Adaptoid WritePak(Addr:%04X): %s (RC:%08X)\n", addr, suc, hr ); + DebugWriteA( "Direct Adaptoid WritePak(Addr:%04X): %s (RC:%08X)\n", addr, suc, hr ); #endif // #ifdef _DEBUG return hr; @@ -1240,75 +1240,75 @@ HRESULT WriteAdaptoidPak( LPDIRECTINPUTDEVICE8 lpDirectInputDevice, DWORD addr, BYTE GetAdaptoidStatus( LPDIRECTINPUTDEVICE8 lpDirectInputDevice ) { - HRESULT hr; - BYTE bStatus = 0; - hr = InitializeAdaptoid( lpDirectInputDevice, &bStatus ); + HRESULT hr; + BYTE bStatus = 0; + hr = InitializeAdaptoid( lpDirectInputDevice, &bStatus ); - int iRetrys = 10; - while( FAILED( hr ) && iRetrys > 0 ) - { - Sleep( 5 ); - hr = AcquireDevice( lpDirectInputDevice ); - hr = InitializeAdaptoid( lpDirectInputDevice, &bStatus ); - iRetrys--; - } + int iRetrys = 10; + while( FAILED( hr ) && iRetrys > 0 ) + { + Sleep( 5 ); + hr = AcquireDevice( lpDirectInputDevice ); + hr = InitializeAdaptoid( lpDirectInputDevice, &bStatus ); + iRetrys--; + } - return (SUCCEEDED(hr)) ? bStatus : RD_NOPLUGIN | RD_NOTINITIALIZED; + return (SUCCEEDED(hr)) ? bStatus : RD_NOPLUGIN | RD_NOTINITIALIZED; } // Fill the handle for g_sysMouse properly void InitMouse() { - if (GetInputDevice( g_strEmuInfo.hMainWindow, g_sysMouse.didHandle, GUID_SysMouse, DI8DEVTYPE_MOUSE, DIB_KEYBOARD )) - { - g_sysMouse.guidInstance = GUID_SysMouse; - g_sysMouse.dwDevType = DI8DEVTYPE_MOUSE; - _tcsncpy(g_sysMouse.szProductName, STRING_GUID_SYSMOUSE, ARRAYSIZE(g_sysMouse.szProductName)); - } - else - g_sysMouse.didHandle = NULL; + if (GetInputDevice( g_strEmuInfo.hMainWindow, g_sysMouse.didHandle, GUID_SysMouse, DI8DEVTYPE_MOUSE, DIB_KEYBOARD )) + { + g_sysMouse.guidInstance = GUID_SysMouse; + g_sysMouse.dwDevType = DI8DEVTYPE_MOUSE; + _tcsncpy(g_sysMouse.szProductName, STRING_GUID_SYSMOUSE, ARRAYSIZE(g_sysMouse.szProductName)); + } + else + g_sysMouse.didHandle = NULL; } // treat btnButton as a b_Value, and return whether it is pressed or not bool IsBtnPressed(BUTTON btnButton) { - long l_Value; - LPLONG plRawState = (LPLONG)&btnButton.parentDevice->stateAs.joyState; + long l_Value; + LPLONG plRawState = (LPLONG)&btnButton.parentDevice->stateAs.joyState; - switch ( btnButton.bBtnType ) - { - case DT_JOYBUTTON: - return ( btnButton.parentDevice->stateAs.joyState.rgbButtons[btnButton.bOffset] & 0x80 ) != 0; + switch ( btnButton.bBtnType ) + { + case DT_JOYBUTTON: + return ( btnButton.parentDevice->stateAs.joyState.rgbButtons[btnButton.bOffset] & 0x80 ) != 0; - case DT_JOYSLIDER: - case DT_JOYAXE: - l_Value = plRawState[btnButton.bOffset] - ZEROVALUE; + case DT_JOYSLIDER: + case DT_JOYAXE: + l_Value = plRawState[btnButton.bOffset] - ZEROVALUE; - if ( btnButton.bAxisID ) - return ( l_Value <= -ABSTHRESHOLD ); - else - return ( l_Value >= ABSTHRESHOLD ); + if ( btnButton.bAxisID ) + return ( l_Value <= -ABSTHRESHOLD ); + else + return ( l_Value >= ABSTHRESHOLD ); - case DT_JOYPOV: - return GetJoyPadPOV( (PDWORD)&plRawState[btnButton.bOffset] , btnButton.bAxisID ); + case DT_JOYPOV: + return GetJoyPadPOV( (PDWORD)&plRawState[btnButton.bOffset] , btnButton.bAxisID ); - case DT_KEYBUTTON: - return ( btnButton.parentDevice->stateAs.rgbButtons[btnButton.bOffset] & 0x80 ) != 0; + case DT_KEYBUTTON: + return ( btnButton.parentDevice->stateAs.rgbButtons[btnButton.bOffset] & 0x80 ) != 0; - case DT_MOUSEBUTTON: - return ( btnButton.parentDevice->stateAs.mouseState.rgbButtons[btnButton.bOffset] & 0x80 ) != 0; + case DT_MOUSEBUTTON: + return ( btnButton.parentDevice->stateAs.mouseState.rgbButtons[btnButton.bOffset] & 0x80 ) != 0; - case DT_MOUSEAXE: - l_Value = MOUSEMOVE; // a.k.a. lvalue is button threshold + case DT_MOUSEAXE: + l_Value = MOUSEMOVE; // a.k.a. lvalue is button threshold - if( btnButton.bAxisID ) - return ( ((LPLONG)(&btnButton.parentDevice->stateAs.mouseState))[btnButton.bOffset] < -l_Value ); - else - return ( ((LPLONG)(&btnButton.parentDevice->stateAs.mouseState))[btnButton.bOffset] > l_Value ); - break; + if( btnButton.bAxisID ) + return ( ((LPLONG)(&btnButton.parentDevice->stateAs.mouseState))[btnButton.bOffset] < -l_Value ); + else + return ( ((LPLONG)(&btnButton.parentDevice->stateAs.mouseState))[btnButton.bOffset] > l_Value ); + break; - case DT_UNASSIGNED: - default: - return false; - } + case DT_UNASSIGNED: + default: + return false; + } } diff --git a/Source/nragev20/DirectInput.h b/Source/nragev20/DirectInput.h index 19491a595..7b766186c 100644 --- a/Source/nragev20/DirectInput.h +++ b/Source/nragev20/DirectInput.h @@ -1,9 +1,9 @@ -/* - N-Rage`s Dinput8 Plugin +/* + N-Rage`s Dinput8 Plugin (C) 2002, 2006 Norbert Wladyka - Author`s Email: norbert.wladyka@chello.at - Website: http://go.to/nrage + Author`s Email: norbert.wladyka@chello.at + Website: http://go.to/nrage This program is free software; you can redistribute it and/or modify @@ -55,103 +55,103 @@ HRESULT ReadAdaptoidPak( LPDIRECTINPUTDEVICE8 lpDirectInputDevice, DWORD addr, L HRESULT WriteAdaptoidPak( LPDIRECTINPUTDEVICE8 lpDirectInputDevice, DWORD addr, LPBYTE data ); -#define MINAXISVALUE -32767 -#define MAXAXISVALUE 32767 -#define ZEROVALUE 0 -#define THRESHOLD 50 -#define RANGERELATIVE (MAXAXISVALUE - ZEROVALUE + 1) -#define ABSTHRESHOLD (RANGERELATIVE * THRESHOLD / 100) - // plus or minus this many 1/100 degrees counts as GetJoyPadPOV being pressed -#define POVANGLETHRESH 5675 +#define MINAXISVALUE -32767 +#define MAXAXISVALUE 32767 +#define ZEROVALUE 0 +#define THRESHOLD 50 +#define RANGERELATIVE (MAXAXISVALUE - ZEROVALUE + 1) +#define ABSTHRESHOLD (RANGERELATIVE * THRESHOLD / 100) + // plus or minus this many 1/100 degrees counts as GetJoyPadPOV being pressed +#define POVANGLETHRESH 5675 -#define MOUSEMOVE 5 - // by default, scale the mouse input by this much -#define MOUSESCALEVALUE 10 - // percent to decay mouse buffer every frame. - // Tweak this from 0-100 to control how much the mouse drifts; values closer to 100 drift more, - // while values closer to 0 are very stiff (deadpan) and don't turn well -#define MOUSEBUFFERDECAY 80 +#define MOUSEMOVE 5 + // by default, scale the mouse input by this much +#define MOUSESCALEVALUE 10 + // percent to decay mouse buffer every frame. + // Tweak this from 0-100 to control how much the mouse drifts; values closer to 100 drift more, + // while values closer to 0 are very stiff (deadpan) and don't turn well +#define MOUSEBUFFERDECAY 80 -#define N64DIVIDER 258 +#define N64DIVIDER 258 -#define DID_KEYBOARD 0 -#define DID_MOUSE 1 -#define DID_GAMEPAD 2 +#define DID_KEYBOARD 0 +#define DID_MOUSE 1 +#define DID_GAMEPAD 2 -#define DIB_KEYBOARD DISCL_NONEXCLUSIVE | DISCL_FOREGROUND -#define DIB_MOUSE DISCL_EXCLUSIVE | DISCL_FOREGROUND -#define DIB_FF DISCL_EXCLUSIVE | DISCL_BACKGROUND -#define DIB_DEVICE DISCL_NONEXCLUSIVE | DISCL_BACKGROUND +#define DIB_KEYBOARD DISCL_NONEXCLUSIVE | DISCL_FOREGROUND +#define DIB_MOUSE DISCL_EXCLUSIVE | DISCL_FOREGROUND +#define DIB_FF DISCL_EXCLUSIVE | DISCL_BACKGROUND +#define DIB_DEVICE DISCL_NONEXCLUSIVE | DISCL_BACKGROUND -#define DIB_CONFIG DISCL_NONEXCLUSIVE | DISCL_BACKGROUND +#define DIB_CONFIG DISCL_NONEXCLUSIVE | DISCL_BACKGROUND -#define RUMBLE_NONE 0x00 -#define RUMBLE_CONSTANT 0x01 -#define RUMBLE_RAMP 0x02 -#define RUMBLE_CONDITION 0x04 -#define RUMBLE_PERIODIC 0x08 -#define RUMBLE_CUSTOM 0x10 +#define RUMBLE_NONE 0x00 +#define RUMBLE_CONSTANT 0x01 +#define RUMBLE_RAMP 0x02 +#define RUMBLE_CONDITION 0x04 +#define RUMBLE_PERIODIC 0x08 +#define RUMBLE_CUSTOM 0x10 -#define RUMBLE_DIRECT 0x80 +#define RUMBLE_DIRECT 0x80 -#define RUMBLE_EFF1 RUMBLE_CONSTANT -#define RUMBLE_EFF2 RUMBLE_RAMP -#define RUMBLE_EFF3 RUMBLE_DIRECT +#define RUMBLE_EFF1 RUMBLE_CONSTANT +#define RUMBLE_EFF2 RUMBLE_RAMP +#define RUMBLE_EFF3 RUMBLE_DIRECT - // Reported Name of the Adaptoid -#define STRING_ADAPTOID "Adaptoid" -#define STRING_GUID_SYSKEYBOARD _T("Keyboard") -#define STRING_GUID_SYSMOUSE _T("SysMouse") + // Reported Name of the Adaptoid +#define STRING_ADAPTOID "Adaptoid" +#define STRING_GUID_SYSKEYBOARD _T("Keyboard") +#define STRING_GUID_SYSMOUSE _T("SysMouse") - // Query API - pass in command #, returns 0xB0CAB0CA if supported -#define ADAPT_TEST 0x7834BB00 - // Send command to rumble pack (DWORD 0=stop, 1=go) -#define ADAPT_RUMBLE 0x7834BB08 - // Initialize pak (returns pak status bit flags) -#define ADAPT_INIT 0x7834BB0C - // Read from pak (reads 32 bytes of data) -#define ADAPT_READPAK 0x7834BB0D - // Write to pak (writes 32 bytes of data) -#define ADAPT_WRITEPAK 0x7834BB0E - // Send command directly to controller - synchronous -#define ADAPT_DIRECTCOMMAND 0x7834BB28 + // Query API - pass in command #, returns 0xB0CAB0CA if supported +#define ADAPT_TEST 0x7834BB00 + // Send command to rumble pack (DWORD 0=stop, 1=go) +#define ADAPT_RUMBLE 0x7834BB08 + // Initialize pak (returns pak status bit flags) +#define ADAPT_INIT 0x7834BB0C + // Read from pak (reads 32 bytes of data) +#define ADAPT_READPAK 0x7834BB0D + // Write to pak (writes 32 bytes of data) +#define ADAPT_WRITEPAK 0x7834BB0E + // Send command directly to controller - synchronous +#define ADAPT_DIRECTCOMMAND 0x7834BB28 // The following inline functions are all overloads for existing functions inline bool CreateEffectHandle( int iDevice, BYTE bRumbleTyp, long lStrength ) { - return CreateEffectHandle( g_strEmuInfo.hMainWindow, g_apFFDevice[iDevice], g_apdiEffect[iDevice], bRumbleTyp, lStrength ); + return CreateEffectHandle( g_strEmuInfo.hMainWindow, g_apFFDevice[iDevice], g_apdiEffect[iDevice], bRumbleTyp, lStrength ); } // this used to exist, but it was only used once and makes things more confusing. Removed. --rabid //inline void ReleaseEffect( int iEffect ) //{ -// ReleaseEffect( g_apdiEffect[iEffect] ); +// ReleaseEffect( g_apdiEffect[iEffect] ); //} inline BYTE GetAdaptoidStatus( int iDevice ) { - return GetAdaptoidStatus( g_apFFDevice[iDevice] ); + return GetAdaptoidStatus( g_apFFDevice[iDevice] ); } inline HRESULT WriteAdaptoidPak( int iDevice, DWORD addr, LPBYTE data ) { - return WriteAdaptoidPak( g_apFFDevice[iDevice], addr, data ); + return WriteAdaptoidPak( g_apFFDevice[iDevice], addr, data ); } inline HRESULT ReadAdaptoidPak( int iDevice, DWORD addr, LPBYTE data ) { - return ReadAdaptoidPak( g_apFFDevice[iDevice], addr, data ); + return ReadAdaptoidPak( g_apFFDevice[iDevice], addr, data ); } inline HRESULT InitializeAdaptoid( int iDevice, LPBYTE status ) { - return InitializeAdaptoid( g_apFFDevice[iDevice], status ); + return InitializeAdaptoid( g_apFFDevice[iDevice], status ); } inline HRESULT DirectRumbleCommand( int iDevice, DWORD cmd ) { - return DirectRumbleCommand( g_apFFDevice[iDevice], cmd ); + return DirectRumbleCommand( g_apFFDevice[iDevice], cmd ); } inline bool IsAdaptoidCommandSupported( int iDevice, DWORD cmd ) { - return IsAdaptoidCommandSupported( g_apFFDevice[iDevice], cmd ); + return IsAdaptoidCommandSupported( g_apFFDevice[iDevice], cmd ); } diff --git a/Source/nragev20/FileAccess.cpp b/Source/nragev20/FileAccess.cpp index 990e09185..28e010af2 100644 --- a/Source/nragev20/FileAccess.cpp +++ b/Source/nragev20/FileAccess.cpp @@ -1,9 +1,9 @@ - /* - N-Rage`s Dinput8 Plugin + /* + N-Rage`s Dinput8 Plugin (C) 2002, 2006 Norbert Wladyka - Author`s Email: norbert.wladyka@chello.at - Website: http://go.to/nrage + Author`s Email: norbert.wladyka@chello.at + Website: http://go.to/nrage This program is free software; you can redistribute it and/or modify @@ -59,565 +59,565 @@ void FormatModifiersBlock(string * strMouse, string strDevs[], string * strNull, // return true if the file exists... let's just use CreateFile with OPEN_EXISTING bool CheckFileExists( LPCTSTR FileName ) { - HANDLE hFile = CreateFile(FileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (hFile == INVALID_HANDLE_VALUE ) - { - return false; - } - else - { - CloseHandle(hFile); - return true; - } + HANDLE hFile = CreateFile(FileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (hFile == INVALID_HANDLE_VALUE ) + { + return false; + } + else + { + CloseHandle(hFile); + return true; + } } // A rather ugly function, but does its job. Called by LoadProfile and LoadProfileFromResource. // Parses the config data that gets written to profile files. // returns: -// PL_CATEGORY and removes the brackets if the line looks like a keymapping -// PL_VERSIONSTRING and returns the version number if it's a version line -// for other cases, another PL return value and truncates before the equal sign; so strings like "Button=blah" -> "blah" +// PL_CATEGORY and removes the brackets if the line looks like a keymapping +// PL_VERSIONSTRING and returns the version number if it's a version line +// for other cases, another PL return value and truncates before the equal sign; so strings like "Button=blah" -> "blah" // TODO: Perhaps buffer overflow and crash potential here... needs auditing DWORD ParseLine( LPSTR pszLine ) { - DWORD dwReturn = PL_NOHIT; - char *pChar = pszLine; + DWORD dwReturn = PL_NOHIT; + char *pChar = pszLine; - switch (pszLine[0]) - { - case '\0': // shortcut out on null string - case '#': // # indicates comment line - return PL_NOHIT; - case '[': - while( *pChar != ']' && *pChar != '\0' ) - { - *pChar = toupper(*pChar); - ++pChar; - } - if( *pChar == ']' ) - { - MoveMemory( pszLine, pszLine+1, (pChar-pszLine) - 1 * sizeof(pszLine[0]) ); // TODO: please double check this --rabid - *(pChar - 1) = '\0'; // since we moved everything back one character, we need to change this ref as well - return PL_CATEGORY; - } - else - return PL_NOHIT; // an open bracket with no closing returns nohit - case '@': - switch( djbHash(pszLine)) // the hash check is case sensitive, and includes the @ symbol - { - case CHK_PROFILEVERSION20: - lstrcpyA( pszLine, "2.0" ); - return PL_VERSIONSTRING; - case CHK_PROFILEVERSION21: - lstrcpyA( pszLine, "2.1" ); - return PL_VERSIONSTRING; - case CHK_PROFILEVERSION22: - lstrcpyA( pszLine, "2.2" ); - return PL_VERSIONSTRING; - default: - DebugWriteA("Unknown version string found with hash %u: %s\n", djbHash(pszLine), pszLine); - return PL_NOHIT; - } // end switch (dbjHash(pszLine)) - // default: keep running - } + switch (pszLine[0]) + { + case '\0': // shortcut out on null string + case '#': // # indicates comment line + return PL_NOHIT; + case '[': + while( *pChar != ']' && *pChar != '\0' ) + { + *pChar = toupper(*pChar); + ++pChar; + } + if( *pChar == ']' ) + { + MoveMemory( pszLine, pszLine+1, (pChar-pszLine) - 1 * sizeof(pszLine[0]) ); // TODO: please double check this --rabid + *(pChar - 1) = '\0'; // since we moved everything back one character, we need to change this ref as well + return PL_CATEGORY; + } + else + return PL_NOHIT; // an open bracket with no closing returns nohit + case '@': + switch( djbHash(pszLine)) // the hash check is case sensitive, and includes the @ symbol + { + case CHK_PROFILEVERSION20: + lstrcpyA( pszLine, "2.0" ); + return PL_VERSIONSTRING; + case CHK_PROFILEVERSION21: + lstrcpyA( pszLine, "2.1" ); + return PL_VERSIONSTRING; + case CHK_PROFILEVERSION22: + lstrcpyA( pszLine, "2.2" ); + return PL_VERSIONSTRING; + default: + DebugWriteA("Unknown version string found with hash %u: %s\n", djbHash(pszLine), pszLine); + return PL_NOHIT; + } // end switch (dbjHash(pszLine)) + // default: keep running + } - pChar = strchr(pszLine, '='); - - if( !pChar ) // no = sign - { - return PL_NOHIT; - } - else // there is an '=' sign - { - // We hash the string. If the hash matches the hash of one of our targets, we compare strings to verify. - // If we don't use hashes, we have to compare vs a LOT of strings. - *pChar = '\0'; // truncate at the '=' for now - for (char *pIter = pszLine; *pIter; pIter++) - *pIter = toupper(*pIter); - dwReturn = djbHash(pszLine); + pChar = strchr(pszLine, '='); - pChar++; + if( !pChar ) // no = sign + { + return PL_NOHIT; + } + else // there is an '=' sign + { + // We hash the string. If the hash matches the hash of one of our targets, we compare strings to verify. + // If we don't use hashes, we have to compare vs a LOT of strings. + *pChar = '\0'; // truncate at the '=' for now + for (char *pIter = pszLine; *pIter; pIter++) + *pIter = toupper(*pIter); + dwReturn = djbHash(pszLine); - MoveMemory( pszLine, pChar, (lstrlenA(pChar) + 1) * sizeof(pszLine[0]) ); // change string to match what's to the right of '=' - } + pChar++; - return dwReturn; + MoveMemory( pszLine, pChar, (lstrlenA(pChar) + 1) * sizeof(pszLine[0]) ); // change string to match what's to the right of '=' + } + + return dwReturn; } // Called immediately after ParseLine to assign values based on whatever the keyname was // notes: pszFFDevice may be overwritten with whatever is in pszLine; please make sure pszLine is not too big! bool ProcessKey( DWORD dwKey, DWORD dwSection, LPCSTR pszLine, LPTSTR pszFFDevice, LPBYTE bFFDeviceNr, bool bIsInterface ) { - static TCHAR pszDeviceName[MAX_PATH]; - static BYTE bDeviceNr = 0; - static GUID gGUID; + static TCHAR pszDeviceName[MAX_PATH]; + static BYTE bDeviceNr = 0; + static GUID gGUID; - bool bReturn = true; - LPCONTROLLER pController = NULL; // used when we're assigning things in the [Controller X] category - LPSHORTCUTS pShortcuts = NULL; - unsigned int iLength = lstrlenA( pszLine ) / 2; // 2 HEX characters correspond to one BYTE; thus iLength represents the length of pszLine after conversion to BYTEs + bool bReturn = true; + LPCONTROLLER pController = NULL; // used when we're assigning things in the [Controller X] category + LPSHORTCUTS pShortcuts = NULL; + unsigned int iLength = lstrlenA( pszLine ) / 2; // 2 HEX characters correspond to one BYTE; thus iLength represents the length of pszLine after conversion to BYTEs - switch (dwSection) - { - case CHK_CONTROLLER_1: - if (bIsInterface) - pController = &(g_ivConfig->Controllers[0]); - else - pController = &(g_pcControllers[0]); - break; - case CHK_CONTROLLER_2: - if (bIsInterface) - pController = &(g_ivConfig->Controllers[1]); - else - pController = &(g_pcControllers[1]); - break; - case CHK_CONTROLLER_3: - if (bIsInterface) - pController = &(g_ivConfig->Controllers[2]); - else - pController = &(g_pcControllers[2]); - break; - case CHK_CONTROLLER_4: - if (bIsInterface) - pController = &(g_ivConfig->Controllers[3]); - else - pController = &(g_pcControllers[3]); - break; - case CHK_SHORTCUTS: - if (bIsInterface) - pShortcuts = &(g_ivConfig->Shortcuts); - else - pShortcuts = &g_scShortcuts; - break; - } + switch (dwSection) + { + case CHK_CONTROLLER_1: + if (bIsInterface) + pController = &(g_ivConfig->Controllers[0]); + else + pController = &(g_pcControllers[0]); + break; + case CHK_CONTROLLER_2: + if (bIsInterface) + pController = &(g_ivConfig->Controllers[1]); + else + pController = &(g_pcControllers[1]); + break; + case CHK_CONTROLLER_3: + if (bIsInterface) + pController = &(g_ivConfig->Controllers[2]); + else + pController = &(g_pcControllers[2]); + break; + case CHK_CONTROLLER_4: + if (bIsInterface) + pController = &(g_ivConfig->Controllers[3]); + else + pController = &(g_pcControllers[3]); + break; + case CHK_SHORTCUTS: + if (bIsInterface) + pShortcuts = &(g_ivConfig->Shortcuts); + else + pShortcuts = &g_scShortcuts; + break; + } - switch( dwKey ) - { - case PL_RESET: - ZeroMemory( pszDeviceName, sizeof(pszDeviceName) ); - gGUID = GUID_NULL; - bDeviceNr = 0; - break; + switch( dwKey ) + { + case PL_RESET: + ZeroMemory( pszDeviceName, sizeof(pszDeviceName) ); + gGUID = GUID_NULL; + bDeviceNr = 0; + break; - case CHK_LANGUAGE: - if (dwSection == CHK_GENERAL) - if (bIsInterface) - g_ivConfig->Language = atoi(pszLine); - else - g_strEmuInfo.Language = atoi(pszLine); - break; - case CHK_SHOWMESSAGES: - if (dwSection == CHK_GENERAL) - if (bIsInterface) - g_ivConfig->fDisplayShortPop = (atoi(pszLine) != 0); - else - g_strEmuInfo.fDisplayShortPop = (atoi(pszLine) != 0); - break; + case CHK_LANGUAGE: + if (dwSection == CHK_GENERAL) + if (bIsInterface) + g_ivConfig->Language = atoi(pszLine); + else + g_strEmuInfo.Language = atoi(pszLine); + break; + case CHK_SHOWMESSAGES: + if (dwSection == CHK_GENERAL) + if (bIsInterface) + g_ivConfig->fDisplayShortPop = (atoi(pszLine) != 0); + else + g_strEmuInfo.fDisplayShortPop = (atoi(pszLine) != 0); + break; - case CHK_MEMPAK: - if (dwSection == CHK_LASTBROWSERDIR) - CHAR_TO_TCHAR(g_aszLastBrowse[BF_MEMPAK], pszLine, MAX_PATH); - else if (dwSection == CHK_FOLDERS) - CHAR_TO_TCHAR(g_aszDefFolders[BF_MEMPAK], pszLine, MAX_PATH); - break; - case CHK_GBXROM: - if (dwSection == CHK_LASTBROWSERDIR) - CHAR_TO_TCHAR(g_aszLastBrowse[BF_GBROM], pszLine, MAX_PATH); - else if (dwSection == CHK_FOLDERS) - CHAR_TO_TCHAR(g_aszDefFolders[BF_GBROM], pszLine, MAX_PATH); - break; - case CHK_GBXSAVE: - if (dwSection == CHK_LASTBROWSERDIR) - CHAR_TO_TCHAR(g_aszLastBrowse[BF_GBSAVE], pszLine, MAX_PATH); - else if (dwSection == CHK_FOLDERS) - CHAR_TO_TCHAR(g_aszDefFolders[BF_GBSAVE], pszLine, MAX_PATH); - break; - case CHK_PROFILE: - if (dwSection == CHK_LASTBROWSERDIR) - CHAR_TO_TCHAR(g_aszLastBrowse[BF_PROFILE], pszLine, MAX_PATH); - break; - case CHK_NOTE: - if (dwSection == CHK_LASTBROWSERDIR) - CHAR_TO_TCHAR(g_aszLastBrowse[BF_NOTE], pszLine, MAX_PATH); - break; - case CHK_SHORTCUTS: - if (dwSection == CHK_LASTBROWSERDIR) - CHAR_TO_TCHAR(g_aszLastBrowse[BF_SHORTCUTS], pszLine, MAX_PATH); - break; - case CHK_PLUGGED: - if (pController) - pController->fPlugged = atoi(pszLine); - break; - case CHK_RAWDATA: - if (pController) - pController->fRawData = atoi(pszLine); - break; - case CHK_XINPUT: - if (pController) - pController->fXInput = atoi(pszLine); - break; - case CHK_N64MOUSE: - if (pController) - pController->fN64Mouse = atoi(pszLine); - break; - case CHK_BACKGROUNDINPUT: - if (pController) - pController->bBackgroundInput = atoi(pszLine); - break; - case CHK_PAKTYPE: - if (pController) - pController->PakType = atoi(pszLine); - break; - case CHK_REALN64RANGE: - if (pController) - pController->fRealN64Range = atoi(pszLine); - break; - case CHK_RAPIDFIREENABLED: - if (pController) - pController->bRapidFireEnabled = atoi(pszLine) != 0; - break; - case CHK_RAPIDFIRERATE: - if (pController) - pController->bRapidFireRate = atoi(pszLine); - break; - case CHK_STICKRANGE: - if (pController) - pController->bStickRange = atoi(pszLine); - break; - case CHK_MOUSEMOVEX: - if (pController) - pController->bMouseMoveX = atoi(pszLine); - break; - case CHK_MOUSEMOVEY: - if (pController) - pController->bMouseMoveY = atoi(pszLine); - break; - case CHK_AXISSET: - if (pController) - pController->bAxisSet = atoi(pszLine); - break; - case CHK_KEYABSOLUTEX: - if (pController) - pController->fKeyAbsoluteX = atoi(pszLine); - break; - case CHK_KEYABSOLUTEY: - if (pController) - pController->fKeyAbsoluteY = atoi(pszLine); - break; - case CHK_PADDEADZONE: - if (pController) - pController->bPadDeadZone = atoi(pszLine); - break; - case CHK_MOUSESENSITIVITYX: - if (pController) - pController->wMouseSensitivityX = atoi(pszLine); - break; - case CHK_MOUSESENSITIVITYY: - if (pController) - pController->wMouseSensitivityY = atoi(pszLine); - break; - case CHK_RUMBLETYPE: - if (pController) - pController->bRumbleTyp = atoi(pszLine); - break; - case CHK_RUMBLESTRENGTH: - if (pController) - pController->bRumbleStrength = atoi(pszLine); - break; - case CHK_VISUALRUMBLE: - if (pController) - pController->fVisualRumble = atoi(pszLine); - break; - case CHK_FFDEVICEGUID: - if (pController) - { - bReturn = StringtoGUIDA(&pController->guidFFDevice, pszLine); - if (bIsInterface && bReturn) - { - // For some reason, we use ONLY device names and numbers inside the interface for FF device selection. So if we don't set those, - // FFDevice won't load properly. - int nDevice = FindDeviceinList(pController->guidFFDevice); - if (nDevice != -1 && pszFFDevice && bFFDeviceNr) - { - _tcsncpy(pszFFDevice, g_devList[nDevice].szProductName, DEFAULT_BUFFER); - *bFFDeviceNr = g_devList[nDevice].bProductCounter; - } - else - { - pController->guidFFDevice = GUID_NULL; - return false; - } - } - else - return bReturn; - } - break; - case CHK_FFDEVICENAME: - if( pController && pszFFDevice ) - { - CHAR_TO_TCHAR( pszFFDevice, pszLine, MAX_PATH ); // HACK: pszLine is read from a file; could overflow easily. guessed size of pszFFDevice buffer. - return true; - } - break; + case CHK_MEMPAK: + if (dwSection == CHK_LASTBROWSERDIR) + CHAR_TO_TCHAR(g_aszLastBrowse[BF_MEMPAK], pszLine, MAX_PATH); + else if (dwSection == CHK_FOLDERS) + CHAR_TO_TCHAR(g_aszDefFolders[BF_MEMPAK], pszLine, MAX_PATH); + break; + case CHK_GBXROM: + if (dwSection == CHK_LASTBROWSERDIR) + CHAR_TO_TCHAR(g_aszLastBrowse[BF_GBROM], pszLine, MAX_PATH); + else if (dwSection == CHK_FOLDERS) + CHAR_TO_TCHAR(g_aszDefFolders[BF_GBROM], pszLine, MAX_PATH); + break; + case CHK_GBXSAVE: + if (dwSection == CHK_LASTBROWSERDIR) + CHAR_TO_TCHAR(g_aszLastBrowse[BF_GBSAVE], pszLine, MAX_PATH); + else if (dwSection == CHK_FOLDERS) + CHAR_TO_TCHAR(g_aszDefFolders[BF_GBSAVE], pszLine, MAX_PATH); + break; + case CHK_PROFILE: + if (dwSection == CHK_LASTBROWSERDIR) + CHAR_TO_TCHAR(g_aszLastBrowse[BF_PROFILE], pszLine, MAX_PATH); + break; + case CHK_NOTE: + if (dwSection == CHK_LASTBROWSERDIR) + CHAR_TO_TCHAR(g_aszLastBrowse[BF_NOTE], pszLine, MAX_PATH); + break; + case CHK_SHORTCUTS: + if (dwSection == CHK_LASTBROWSERDIR) + CHAR_TO_TCHAR(g_aszLastBrowse[BF_SHORTCUTS], pszLine, MAX_PATH); + break; + case CHK_PLUGGED: + if (pController) + pController->fPlugged = atoi(pszLine); + break; + case CHK_RAWDATA: + if (pController) + pController->fRawData = atoi(pszLine); + break; + case CHK_XINPUT: + if (pController) + pController->fXInput = atoi(pszLine); + break; + case CHK_N64MOUSE: + if (pController) + pController->fN64Mouse = atoi(pszLine); + break; + case CHK_BACKGROUNDINPUT: + if (pController) + pController->bBackgroundInput = atoi(pszLine); + break; + case CHK_PAKTYPE: + if (pController) + pController->PakType = atoi(pszLine); + break; + case CHK_REALN64RANGE: + if (pController) + pController->fRealN64Range = atoi(pszLine); + break; + case CHK_RAPIDFIREENABLED: + if (pController) + pController->bRapidFireEnabled = atoi(pszLine) != 0; + break; + case CHK_RAPIDFIRERATE: + if (pController) + pController->bRapidFireRate = atoi(pszLine); + break; + case CHK_STICKRANGE: + if (pController) + pController->bStickRange = atoi(pszLine); + break; + case CHK_MOUSEMOVEX: + if (pController) + pController->bMouseMoveX = atoi(pszLine); + break; + case CHK_MOUSEMOVEY: + if (pController) + pController->bMouseMoveY = atoi(pszLine); + break; + case CHK_AXISSET: + if (pController) + pController->bAxisSet = atoi(pszLine); + break; + case CHK_KEYABSOLUTEX: + if (pController) + pController->fKeyAbsoluteX = atoi(pszLine); + break; + case CHK_KEYABSOLUTEY: + if (pController) + pController->fKeyAbsoluteY = atoi(pszLine); + break; + case CHK_PADDEADZONE: + if (pController) + pController->bPadDeadZone = atoi(pszLine); + break; + case CHK_MOUSESENSITIVITYX: + if (pController) + pController->wMouseSensitivityX = atoi(pszLine); + break; + case CHK_MOUSESENSITIVITYY: + if (pController) + pController->wMouseSensitivityY = atoi(pszLine); + break; + case CHK_RUMBLETYPE: + if (pController) + pController->bRumbleTyp = atoi(pszLine); + break; + case CHK_RUMBLESTRENGTH: + if (pController) + pController->bRumbleStrength = atoi(pszLine); + break; + case CHK_VISUALRUMBLE: + if (pController) + pController->fVisualRumble = atoi(pszLine); + break; + case CHK_FFDEVICEGUID: + if (pController) + { + bReturn = StringtoGUIDA(&pController->guidFFDevice, pszLine); + if (bIsInterface && bReturn) + { + // For some reason, we use ONLY device names and numbers inside the interface for FF device selection. So if we don't set those, + // FFDevice won't load properly. + int nDevice = FindDeviceinList(pController->guidFFDevice); + if (nDevice != -1 && pszFFDevice && bFFDeviceNr) + { + _tcsncpy(pszFFDevice, g_devList[nDevice].szProductName, DEFAULT_BUFFER); + *bFFDeviceNr = g_devList[nDevice].bProductCounter; + } + else + { + pController->guidFFDevice = GUID_NULL; + return false; + } + } + else + return bReturn; + } + break; + case CHK_FFDEVICENAME: + if( pController && pszFFDevice ) + { + CHAR_TO_TCHAR( pszFFDevice, pszLine, MAX_PATH ); // HACK: pszLine is read from a file; could overflow easily. guessed size of pszFFDevice buffer. + return true; + } + break; - case CHK_FFDEVICENR: - if( pController && bFFDeviceNr && ( iLength >= sizeof(BYTE) )) - { - *bFFDeviceNr = atoi( pszLine ); - return true; - } - break; - case CHK_MEMPAKFILE: - if( pController ) - { - CHAR_TO_TCHAR( pController->szMempakFile, pszLine, MAX_PATH ); - } - break; - case CHK_GBROMFILE: - if( pController ) - { - CHAR_TO_TCHAR( pController->szTransferRom, pszLine, MAX_PATH ); - } - break; - case CHK_GBROMSAVE: - if( pController ) - { - CHAR_TO_TCHAR( pController->szTransferSave, pszLine, MAX_PATH ); - } - break; + case CHK_FFDEVICENR: + if( pController && bFFDeviceNr && ( iLength >= sizeof(BYTE) )) + { + *bFFDeviceNr = atoi( pszLine ); + return true; + } + break; + case CHK_MEMPAKFILE: + if( pController ) + { + CHAR_TO_TCHAR( pController->szMempakFile, pszLine, MAX_PATH ); + } + break; + case CHK_GBROMFILE: + if( pController ) + { + CHAR_TO_TCHAR( pController->szTransferRom, pszLine, MAX_PATH ); + } + break; + case CHK_GBROMSAVE: + if( pController ) + { + CHAR_TO_TCHAR( pController->szTransferSave, pszLine, MAX_PATH ); + } + break; - case CHK_DINPUTNAME: - gGUID = GUID_NULL; // invalidate current GUID - CHAR_TO_TCHAR( pszDeviceName, pszLine, MAX_PATH ); - break; + case CHK_DINPUTNAME: + gGUID = GUID_NULL; // invalidate current GUID + CHAR_TO_TCHAR( pszDeviceName, pszLine, MAX_PATH ); + break; - case CHK_DINPUTNR: - gGUID = GUID_NULL; // invalidate current GUID - if( iLength >= sizeof(BYTE) ) - { - TexttoHexA( pszLine, &bDeviceNr, sizeof(BYTE) ); - } - break; - case CHK_DINPUTGUID: - if (StringtoGUIDA(&gGUID, pszLine)) - return true; - else - { - gGUID = GUID_NULL; // invalidate current GUID - return false; - } - break; + case CHK_DINPUTNR: + gGUID = GUID_NULL; // invalidate current GUID + if( iLength >= sizeof(BYTE) ) + { + TexttoHexA( pszLine, &bDeviceNr, sizeof(BYTE) ); + } + break; + case CHK_DINPUTGUID: + if (StringtoGUIDA(&gGUID, pszLine)) + return true; + else + { + gGUID = GUID_NULL; // invalidate current GUID + return false; + } + break; - case CHK_BUTTON: - if ( dwSection == CHK_CONTROLS || pShortcuts || pController ) - { - int controlnum = 0, buttonID = 0; - BUTTON btnWorking; + case CHK_BUTTON: + if ( dwSection == CHK_CONTROLS || pShortcuts || pController ) + { + int controlnum = 0, buttonID = 0; + BUTTON btnWorking; - ZeroMemory(&btnWorking, sizeof(btnWorking)); + ZeroMemory(&btnWorking, sizeof(btnWorking)); - unsigned int tOffset, tAxisID, tBtnType; + unsigned int tOffset, tAxisID, tBtnType; - if (sscanf(pszLine, "%d %d %x %u %u", &controlnum, &buttonID, &tOffset, &tAxisID, &tBtnType) != 5) - return false; + if (sscanf(pszLine, "%d %d %x %u %u", &controlnum, &buttonID, &tOffset, &tAxisID, &tBtnType) != 5) + return false; - // done to overcome issues with sscanf and "small" data blocks - btnWorking.bOffset = tOffset; - btnWorking.bAxisID = tAxisID; - btnWorking.bBtnType = tBtnType; + // done to overcome issues with sscanf and "small" data blocks + btnWorking.bOffset = tOffset; + btnWorking.bAxisID = tAxisID; + btnWorking.bBtnType = tBtnType; - if (pController) - { - // special case: if we're in one of the categories CHK_CONTROLLER_n, assume we're processing a Profile file. - // Ignore the read controlnum and use our input controller number. - controlnum = (int)(dwSection - CHK_CONTROLLER_1); // HACK: assume our hash reproduces these linearly - } - - // Now we need to assign parentdevice. If we have a valid gGUID, we'll use that... - int found = FindDeviceinList(gGUID); - if (found != -1) - btnWorking.parentDevice = &g_devList[found]; - else - { - // ... otherwise, we do the following in order: - // 1. If bBtnType is of type DT_MOUSEBUTTON or DT_MOUSEAXE, set gGUID to that of g_sysMouse (ignoring the given name and number) - if ( btnWorking.bBtnType == DT_MOUSEBUTTON || btnWorking.bBtnType == DT_MOUSEAXE ) - { - btnWorking.parentDevice = &g_sysMouse; - } - // 2. If bBtnType is of type DT_KEYBUTTON, set gGUID to that of SysKeyboard - else if ( btnWorking.bBtnType == DT_KEYBUTTON ) - { - gGUID = GUID_SysKeyboard; - found = FindDeviceinList(gGUID); - if (found != -1) - btnWorking.parentDevice = &g_devList[found]; - else - btnWorking.parentDevice = NULL; - } - // 3. otherwise, look up the name and number using FindDeviceinList, and set gGUID to that - else - { - found = FindDeviceinList(pszDeviceName, bDeviceNr, true); - if (found != -1) - { - gGUID = g_devList[found].guidInstance; - btnWorking.parentDevice = &g_devList[found]; - } - else - { - DebugWrite(_T("ProcessKey: couldn't find a device in g_devList for %s %d\n"), pszDeviceName, bDeviceNr); - gGUID = GUID_NULL; - btnWorking.parentDevice = NULL; - return false; - } - } - } + if (pController) + { + // special case: if we're in one of the categories CHK_CONTROLLER_n, assume we're processing a Profile file. + // Ignore the read controlnum and use our input controller number. + controlnum = (int)(dwSection - CHK_CONTROLLER_1); // HACK: assume our hash reproduces these linearly + } - if (pShortcuts) - { - // bounds check on controlnum and buttonID - if ( (controlnum == -1 && buttonID != 0) && ((controlnum < 0) || (controlnum > 3) || (buttonID < 0) || (buttonID >= SC_TOTAL)) ) - { - gGUID = GUID_NULL; // since we may have cached an invalid GUID, invalidate it - return false; - } + // Now we need to assign parentdevice. If we have a valid gGUID, we'll use that... + int found = FindDeviceinList(gGUID); + if (found != -1) + btnWorking.parentDevice = &g_devList[found]; + else + { + // ... otherwise, we do the following in order: + // 1. If bBtnType is of type DT_MOUSEBUTTON or DT_MOUSEAXE, set gGUID to that of g_sysMouse (ignoring the given name and number) + if ( btnWorking.bBtnType == DT_MOUSEBUTTON || btnWorking.bBtnType == DT_MOUSEAXE ) + { + btnWorking.parentDevice = &g_sysMouse; + } + // 2. If bBtnType is of type DT_KEYBUTTON, set gGUID to that of SysKeyboard + else if ( btnWorking.bBtnType == DT_KEYBUTTON ) + { + gGUID = GUID_SysKeyboard; + found = FindDeviceinList(gGUID); + if (found != -1) + btnWorking.parentDevice = &g_devList[found]; + else + btnWorking.parentDevice = NULL; + } + // 3. otherwise, look up the name and number using FindDeviceinList, and set gGUID to that + else + { + found = FindDeviceinList(pszDeviceName, bDeviceNr, true); + if (found != -1) + { + gGUID = g_devList[found].guidInstance; + btnWorking.parentDevice = &g_devList[found]; + } + else + { + DebugWrite(_T("ProcessKey: couldn't find a device in g_devList for %s %d\n"), pszDeviceName, bDeviceNr); + gGUID = GUID_NULL; + btnWorking.parentDevice = NULL; + return false; + } + } + } - // Copy the completed button to the correct shortcut - if (bIsInterface) - if (controlnum == -1) - g_ivConfig->Shortcuts.bMouseLock = btnWorking; - else - g_ivConfig->Shortcuts.Player[controlnum].aButtons[buttonID] = btnWorking; - else // if (!bIsInterface) - if (controlnum == -1) - g_scShortcuts.bMouseLock = btnWorking; - else - g_scShortcuts.Player[controlnum].aButtons[buttonID] = btnWorking; - } - else // it's a controller button - { - // bounds check on controlnum and buttonID - if ( (controlnum < 0) || (controlnum > 3) || (buttonID < 0) || (buttonID >= ARRAYSIZE(g_pcControllers[0].aButton)) ) - { - gGUID = GUID_NULL; // since we may have cached an invalid GUID, invalidate it - return false; - } + if (pShortcuts) + { + // bounds check on controlnum and buttonID + if ( (controlnum == -1 && buttonID != 0) && ((controlnum < 0) || (controlnum > 3) || (buttonID < 0) || (buttonID >= SC_TOTAL)) ) + { + gGUID = GUID_NULL; // since we may have cached an invalid GUID, invalidate it + return false; + } - // Copy the completed button to the correct controller and buttonID - if (bIsInterface) - g_ivConfig->Controllers[controlnum].aButton[buttonID] = btnWorking; - else - g_pcControllers[controlnum].aButton[buttonID] = btnWorking; - } - } - break; + // Copy the completed button to the correct shortcut + if (bIsInterface) + if (controlnum == -1) + g_ivConfig->Shortcuts.bMouseLock = btnWorking; + else + g_ivConfig->Shortcuts.Player[controlnum].aButtons[buttonID] = btnWorking; + else // if (!bIsInterface) + if (controlnum == -1) + g_scShortcuts.bMouseLock = btnWorking; + else + g_scShortcuts.Player[controlnum].aButtons[buttonID] = btnWorking; + } + else // it's a controller button + { + // bounds check on controlnum and buttonID + if ( (controlnum < 0) || (controlnum > 3) || (buttonID < 0) || (buttonID >= ARRAYSIZE(g_pcControllers[0].aButton)) ) + { + gGUID = GUID_NULL; // since we may have cached an invalid GUID, invalidate it + return false; + } - case CHK_MODIFIER: - // Modifiers format: controlnum bOffset bAxisID bBtnType bModType fToggle fStatus dwSpecific - if ( dwSection == CHK_MODIFIERS || pController ) - { - int controlnum = 0; - MODIFIER modWorking; + // Copy the completed button to the correct controller and buttonID + if (bIsInterface) + g_ivConfig->Controllers[controlnum].aButton[buttonID] = btnWorking; + else + g_pcControllers[controlnum].aButton[buttonID] = btnWorking; + } + } + break; - ZeroMemory(&modWorking, sizeof(modWorking)); + case CHK_MODIFIER: + // Modifiers format: controlnum bOffset bAxisID bBtnType bModType fToggle fStatus dwSpecific + if ( dwSection == CHK_MODIFIERS || pController ) + { + int controlnum = 0; + MODIFIER modWorking; - unsigned int tOffset, tAxisID, tBtnType, tModType, tToggle, tStatus, tSpecific; + ZeroMemory(&modWorking, sizeof(modWorking)); - if (sscanf(pszLine, "%u %x %u %u %u %u %u %x", &controlnum, &tOffset, &tAxisID, - &tBtnType, &tModType, &tToggle, &tStatus, &tSpecific) != 8) - return false; + unsigned int tOffset, tAxisID, tBtnType, tModType, tToggle, tStatus, tSpecific; - // done to overcome issues with sscanf and "small" data blocks - modWorking.btnButton.bOffset = tOffset; - modWorking.btnButton.bAxisID = tAxisID; - modWorking.btnButton.bBtnType = tBtnType; - modWorking.bModType = tModType; - modWorking.fToggle = tToggle; - modWorking.fStatus = tStatus; - modWorking.dwSpecific = tSpecific; // looks stupid, but unsigned int might not always be DWORD32 - - // Now we need to assign parentdevice. If we have a valid gGUID, we'll use that... - int found = FindDeviceinList(gGUID); - if (found != -1) - modWorking.btnButton.parentDevice = &g_devList[found]; - else - { - // ... otherwise, we do the following in order: - // 1. If bBtnType is of type DT_MOUSEBUTTON or DT_MOUSEAXE, set gGUID to that of g_sysMouse (ignoring the given name and number) - if ( modWorking.btnButton.bBtnType == DT_MOUSEBUTTON || modWorking.btnButton.bBtnType == DT_MOUSEAXE ) - { - modWorking.btnButton.parentDevice = &g_sysMouse; - } - // 2. If bBtnType is of type DT_KEYBUTTON, set gGUID to that of SysKeyboard - else if ( modWorking.btnButton.bBtnType == DT_KEYBUTTON ) - { - gGUID = GUID_SysKeyboard; - int found = FindDeviceinList(gGUID); - if (found != -1) - modWorking.btnButton.parentDevice = &g_devList[found]; - else - modWorking.btnButton.parentDevice = NULL; - } - // 3. otherwise, look up the name and number using FindDeviceinList, and set gGUID to that - else - { - found = FindDeviceinList(pszDeviceName, bDeviceNr, true); - if (found != -1) - { - gGUID = g_devList[found].guidInstance; - modWorking.btnButton.parentDevice = &g_devList[found]; - } - else - { - DebugWrite(_T("ProcessKey: couldn't find a device in g_devList for %s %d\n"), pszDeviceName, bDeviceNr); - gGUID = GUID_NULL; - modWorking.btnButton.parentDevice = NULL; - return false; - } - } - } + if (sscanf(pszLine, "%u %x %u %u %u %u %u %x", &controlnum, &tOffset, &tAxisID, + &tBtnType, &tModType, &tToggle, &tStatus, &tSpecific) != 8) + return false; - // bounds check on controlnum and buttonID - if ( (controlnum < 0) || (controlnum > 3) ) - { - gGUID = GUID_NULL; // since we may have cached an invalid GUID, invalidate it - return false; - } + // done to overcome issues with sscanf and "small" data blocks + modWorking.btnButton.bOffset = tOffset; + modWorking.btnButton.bAxisID = tAxisID; + modWorking.btnButton.bBtnType = tBtnType; + modWorking.bModType = tModType; + modWorking.fToggle = tToggle; + modWorking.fStatus = tStatus; + modWorking.dwSpecific = tSpecific; // looks stupid, but unsigned int might not always be DWORD32 - // Allocate and add the completed modifier - if (bIsInterface) - { - if (g_ivConfig->Controllers[controlnum].nModifiers > 0) - { - g_ivConfig->Controllers[controlnum].pModifiers = (LPMODIFIER)P_realloc(g_ivConfig->Controllers[controlnum].pModifiers, (g_ivConfig->Controllers[controlnum].nModifiers + 1) * sizeof(MODIFIER)); - } - else - { - g_ivConfig->Controllers[controlnum].pModifiers = (LPMODIFIER)P_malloc( sizeof(MODIFIER)); - } - g_ivConfig->Controllers[controlnum].pModifiers[g_ivConfig->Controllers[controlnum].nModifiers] = modWorking; - (g_ivConfig->Controllers[controlnum].nModifiers)++; - } - else - { - if (g_pcControllers[controlnum].nModifiers > 0) - { - g_pcControllers[controlnum].pModifiers = (LPMODIFIER)P_realloc(g_pcControllers[controlnum].pModifiers, (g_pcControllers[controlnum].nModifiers + 1) * sizeof(MODIFIER)); - } - else - { - g_pcControllers[controlnum].pModifiers = (LPMODIFIER)P_malloc( sizeof(MODIFIER)); - } - g_pcControllers[controlnum].pModifiers[g_pcControllers[controlnum].nModifiers] = modWorking; - (g_pcControllers[controlnum].nModifiers)++; - } + // Now we need to assign parentdevice. If we have a valid gGUID, we'll use that... + int found = FindDeviceinList(gGUID); + if (found != -1) + modWorking.btnButton.parentDevice = &g_devList[found]; + else + { + // ... otherwise, we do the following in order: + // 1. If bBtnType is of type DT_MOUSEBUTTON or DT_MOUSEAXE, set gGUID to that of g_sysMouse (ignoring the given name and number) + if ( modWorking.btnButton.bBtnType == DT_MOUSEBUTTON || modWorking.btnButton.bBtnType == DT_MOUSEAXE ) + { + modWorking.btnButton.parentDevice = &g_sysMouse; + } + // 2. If bBtnType is of type DT_KEYBUTTON, set gGUID to that of SysKeyboard + else if ( modWorking.btnButton.bBtnType == DT_KEYBUTTON ) + { + gGUID = GUID_SysKeyboard; + int found = FindDeviceinList(gGUID); + if (found != -1) + modWorking.btnButton.parentDevice = &g_devList[found]; + else + modWorking.btnButton.parentDevice = NULL; + } + // 3. otherwise, look up the name and number using FindDeviceinList, and set gGUID to that + else + { + found = FindDeviceinList(pszDeviceName, bDeviceNr, true); + if (found != -1) + { + gGUID = g_devList[found].guidInstance; + modWorking.btnButton.parentDevice = &g_devList[found]; + } + else + { + DebugWrite(_T("ProcessKey: couldn't find a device in g_devList for %s %d\n"), pszDeviceName, bDeviceNr); + gGUID = GUID_NULL; + modWorking.btnButton.parentDevice = NULL; + return false; + } + } + } - } - break; - } + // bounds check on controlnum and buttonID + if ( (controlnum < 0) || (controlnum > 3) ) + { + gGUID = GUID_NULL; // since we may have cached an invalid GUID, invalidate it + return false; + } - return bReturn; + // Allocate and add the completed modifier + if (bIsInterface) + { + if (g_ivConfig->Controllers[controlnum].nModifiers > 0) + { + g_ivConfig->Controllers[controlnum].pModifiers = (LPMODIFIER)P_realloc(g_ivConfig->Controllers[controlnum].pModifiers, (g_ivConfig->Controllers[controlnum].nModifiers + 1) * sizeof(MODIFIER)); + } + else + { + g_ivConfig->Controllers[controlnum].pModifiers = (LPMODIFIER)P_malloc( sizeof(MODIFIER)); + } + g_ivConfig->Controllers[controlnum].pModifiers[g_ivConfig->Controllers[controlnum].nModifiers] = modWorking; + (g_ivConfig->Controllers[controlnum].nModifiers)++; + } + else + { + if (g_pcControllers[controlnum].nModifiers > 0) + { + g_pcControllers[controlnum].pModifiers = (LPMODIFIER)P_realloc(g_pcControllers[controlnum].pModifiers, (g_pcControllers[controlnum].nModifiers + 1) * sizeof(MODIFIER)); + } + else + { + g_pcControllers[controlnum].pModifiers = (LPMODIFIER)P_malloc( sizeof(MODIFIER)); + } + g_pcControllers[controlnum].pModifiers[g_pcControllers[controlnum].nModifiers] = modWorking; + (g_pcControllers[controlnum].nModifiers)++; + } + + } + break; + } + + return bReturn; } /****************** @@ -625,31 +625,31 @@ Load the default profile from the raw "resource" data (i.e. the builtin defaults ******************/ bool LoadProfileFromResource( LPCTSTR pszResource, int iController, bool bIsInterface ) { - const DWORD dwControllerSect[] = { CHK_CONTROLLER_1 , CHK_CONTROLLER_2, CHK_CONTROLLER_3, CHK_CONTROLLER_4 }; - if( iController > 3 || iController < 0 ) - return false; - HRSRC res = FindResource( g_strEmuInfo.hinst, pszResource, _T("PROFILE") ); - if( res == NULL ) - return false; - char *profile = (char*)LockResource( LoadResource( g_strEmuInfo.hinst, res )); - char *profileend = profile + SizeofResource( g_strEmuInfo.hinst, res ); - - ProcessKey( PL_RESET, 0, 0, 0, 0, bIsInterface ); - DWORD dwCommand = PL_NOHIT; - char szLine[4096]; - while( profile < profileend ) - { - while( profile < profileend && (CHECK_WHITESPACES( *profile ) || *profile == ' ' )) - ++profile; - int i = 0; - while( profile < profileend && i < sizeof(szLine)-1 && !(CHECK_WHITESPACES( *profile )) ) - szLine[i++] = *profile++; + const DWORD dwControllerSect[] = { CHK_CONTROLLER_1 , CHK_CONTROLLER_2, CHK_CONTROLLER_3, CHK_CONTROLLER_4 }; + if( iController > 3 || iController < 0 ) + return false; + HRSRC res = FindResource( g_strEmuInfo.hinst, pszResource, _T("PROFILE") ); + if( res == NULL ) + return false; + char *profile = (char*)LockResource( LoadResource( g_strEmuInfo.hinst, res )); + char *profileend = profile + SizeofResource( g_strEmuInfo.hinst, res ); - szLine[i] = '\0'; - dwCommand = ParseLine( szLine ); - ProcessKey( dwCommand, dwControllerSect[iController], szLine, 0, 0, bIsInterface ); // resource will not contain a FF device - } - return true; + ProcessKey( PL_RESET, 0, 0, 0, 0, bIsInterface ); + DWORD dwCommand = PL_NOHIT; + char szLine[4096]; + while( profile < profileend ) + { + while( profile < profileend && (CHECK_WHITESPACES( *profile ) || *profile == ' ' )) + ++profile; + int i = 0; + while( profile < profileend && i < sizeof(szLine)-1 && !(CHECK_WHITESPACES( *profile )) ) + szLine[i++] = *profile++; + + szLine[i] = '\0'; + dwCommand = ParseLine( szLine ); + ProcessKey( dwCommand, dwControllerSect[iController], szLine, 0, 0, bIsInterface ); // resource will not contain a FF device + } + return true; } /****************** @@ -657,447 +657,447 @@ See overloaded function above ******************/ bool LoadProfileFromResource( int indexController, bool bIsInterface ) { - const int resIds[] = { IDR_PROFILE_DEFAULT1, IDR_PROFILE_DEFAULT2, IDR_PROFILE_DEFAULT3, IDR_PROFILE_DEFAULT4 }; + const int resIds[] = { IDR_PROFILE_DEFAULT1, IDR_PROFILE_DEFAULT2, IDR_PROFILE_DEFAULT3, IDR_PROFILE_DEFAULT4 }; - TCHAR szId[20]; - wsprintf( szId, _T("#%i"), resIds[indexController] ); - return LoadProfileFromResource( szId, indexController, bIsInterface ); + TCHAR szId[20]; + wsprintf( szId, _T("#%i"), resIds[indexController] ); + return LoadProfileFromResource( szId, indexController, bIsInterface ); } // Load a controller profile from a saved configuration file // need to incorporate type (keyb/mouse/joy), GUID for joy, and bOffset bool LoadProfileFile( const TCHAR *pszFileName, int iController, TCHAR *pszFFDevice, BYTE *bFFDeviceNr ) { - const DWORD dwControllerSect[] = { CHK_CONTROLLER_1 , CHK_CONTROLLER_2, CHK_CONTROLLER_3, CHK_CONTROLLER_4 }; - FILE *proFile = NULL; - char szLine[4096]; - int iVersion = 0; + const DWORD dwControllerSect[] = { CHK_CONTROLLER_1 , CHK_CONTROLLER_2, CHK_CONTROLLER_3, CHK_CONTROLLER_4 }; + FILE *proFile = NULL; + char szLine[4096]; + int iVersion = 0; - if ( (proFile = _tfopen(pszFileName, _T("rS")) ) == NULL) - return false; - - // Test if right Version - while( !iVersion && ( fgets(szLine, sizeof(szLine) - 1, proFile) ) ) - { - szLine[strlen(szLine) - 1] = '\0'; // remove newline - if( ParseLine( szLine ) == PL_VERSIONSTRING ) - iVersion = (int)(atof( szLine ) * 100); - } - if( iVersion != 220 ) // HACK: this should probably not be a hardcoded value - { - fclose(proFile); - return false; - } + if ( (proFile = _tfopen(pszFileName, _T("rS")) ) == NULL) + return false; - SetControllerDefaults( &(g_ivConfig->Controllers[iController]) ); - pszFFDevice[0] = pszFFDevice[1] = '\0'; - *bFFDeviceNr = 0; + // Test if right Version + while( !iVersion && ( fgets(szLine, sizeof(szLine) - 1, proFile) ) ) + { + szLine[strlen(szLine) - 1] = '\0'; // remove newline + if( ParseLine( szLine ) == PL_VERSIONSTRING ) + iVersion = (int)(atof( szLine ) * 100); + } + if( iVersion != 220 ) // HACK: this should probably not be a hardcoded value + { + fclose(proFile); + return false; + } - ProcessKey( PL_RESET, 0, 0, 0, 0, true ); - DWORD dwCommand = PL_NOHIT; - while( fgets(szLine, sizeof(szLine) - 1, proFile) ) - { - szLine[strlen(szLine) - 1] = '\0'; // remove newline - dwCommand = ParseLine( szLine ); - ProcessKey( dwCommand, dwControllerSect[iController], szLine, pszFFDevice, bFFDeviceNr, true ); - } + SetControllerDefaults( &(g_ivConfig->Controllers[iController]) ); + pszFFDevice[0] = pszFFDevice[1] = '\0'; + *bFFDeviceNr = 0; - fclose(proFile); + ProcessKey( PL_RESET, 0, 0, 0, 0, true ); + DWORD dwCommand = PL_NOHIT; + while( fgets(szLine, sizeof(szLine) - 1, proFile) ) + { + szLine[strlen(szLine) - 1] = '\0'; // remove newline + dwCommand = ParseLine( szLine ); + ProcessKey( dwCommand, dwControllerSect[iController], szLine, pszFFDevice, bFFDeviceNr, true ); + } - return true; + fclose(proFile); + + return true; } // Load a controller profile from a saved configuration file // need to incorporate type (keyb/mouse/joy), GUID for joy, and bOffset bool LoadShortcutsFile( const TCHAR *pszFileName ) { - FILE *fShortsFile = NULL; - char szLine[4096]; - int iVersion = 0; + FILE *fShortsFile = NULL; + char szLine[4096]; + int iVersion = 0; - if ( (fShortsFile = _tfopen(pszFileName, _T("rS")) ) == NULL) - return false; - - // Test if right Version - while( !iVersion && ( fgets(szLine, sizeof(szLine) - 1, fShortsFile) ) ) - { - szLine[strlen(szLine) - 1] = '\0'; // remove newline - if( ParseLine( szLine ) == PL_VERSIONSTRING ) - iVersion = (int)(atof( szLine ) * 100); - } - if( iVersion != 220 ) // HACK: this should probably not be a hardcoded value - { - fclose(fShortsFile); - return false; - } + if ( (fShortsFile = _tfopen(pszFileName, _T("rS")) ) == NULL) + return false; - ZeroMemory( &(g_ivConfig->Shortcuts), sizeof(SHORTCUTS) ); + // Test if right Version + while( !iVersion && ( fgets(szLine, sizeof(szLine) - 1, fShortsFile) ) ) + { + szLine[strlen(szLine) - 1] = '\0'; // remove newline + if( ParseLine( szLine ) == PL_VERSIONSTRING ) + iVersion = (int)(atof( szLine ) * 100); + } + if( iVersion != 220 ) // HACK: this should probably not be a hardcoded value + { + fclose(fShortsFile); + return false; + } - ProcessKey( PL_RESET, 0, 0, 0, 0, true ); - DWORD dwCommand = PL_NOHIT; - while( fgets(szLine, sizeof(szLine) - 1, fShortsFile) ) - { - szLine[strlen(szLine) - 1] = '\0'; // remove newline - dwCommand = ParseLine( szLine ); - ProcessKey( dwCommand, CHK_SHORTCUTS, szLine, 0, 0, true ); - } + ZeroMemory( &(g_ivConfig->Shortcuts), sizeof(SHORTCUTS) ); - fclose(fShortsFile); + ProcessKey( PL_RESET, 0, 0, 0, 0, true ); + DWORD dwCommand = PL_NOHIT; + while( fgets(szLine, sizeof(szLine) - 1, fShortsFile) ) + { + szLine[strlen(szLine) - 1] = '\0'; // remove newline + dwCommand = ParseLine( szLine ); + ProcessKey( dwCommand, CHK_SHORTCUTS, szLine, 0, 0, true ); + } - return true; + fclose(fShortsFile); + + return true; } // Serializes the profile for the CURRENT controller for saving to a file // called in one place, from within Interface.cpp, ControllerTabProc (when you click "Save Profile") void FormatProfileBlock( FILE * fFile, const int i ) { - DumpControllerSettings(fFile, i, false); + DumpControllerSettings(fFile, i, false); - string strMouse; - string strDevs[MAX_DEVICES]; - string strNull; + string strMouse; + string strDevs[MAX_DEVICES]; + string strNull; - FormatControlsBlock(&strMouse, strDevs, &strNull, i); + FormatControlsBlock(&strMouse, strDevs, &strNull, i); - DumpStreams(fFile, strMouse, strDevs, strNull, false); + DumpStreams(fFile, strMouse, strDevs, strNull, false); - strMouse.clear(); - for (int j = 0; j < g_nDevices; j++) - strDevs[j].clear(); - strNull.clear(); + strMouse.clear(); + for (int j = 0; j < g_nDevices; j++) + strDevs[j].clear(); + strNull.clear(); - FormatModifiersBlock(&strMouse, strDevs, &strNull, i); + FormatModifiersBlock(&strMouse, strDevs, &strNull, i); - DumpStreams(fFile, strMouse, strDevs, strNull, false); + DumpStreams(fFile, strMouse, strDevs, strNull, false); } // same as FormatProfileBlock, but saves shortcuts instead void FormatShortcutsBlock(FILE * fFile, bool bIsINI) { - // I'm going to use STL strings here because I don't want to screw with buffer management - string strMouse; - string strDevs[MAX_DEVICES]; - string strNull; + // I'm going to use STL strings here because I don't want to screw with buffer management + string strMouse; + string strDevs[MAX_DEVICES]; + string strNull; - for ( int i = 0; i < 4; i++ ) // Player for - { - for ( int j = 0; j < SC_TOTAL; j++ ) // aButtons for - { - if (g_ivConfig->Shortcuts.Player[i].aButtons[j].parentDevice) // possibly unbound - { - if ( IsEqualGUID(g_sysMouse.guidInstance, g_ivConfig->Shortcuts.Player[i].aButtons[j].parentDevice->guidInstance) ) - { - char szBuf[DEFAULT_BUFFER]; - // add to the mouse stream - sprintf(szBuf, STRING_INI_BUTTON "=%d %d %02X %d %d\n", i, j, g_ivConfig->Shortcuts.Player[i].aButtons[j].bOffset, g_ivConfig->Shortcuts.Player[i].aButtons[j].bAxisID, g_ivConfig->Shortcuts.Player[i].aButtons[j].bBtnType); - strMouse.append(szBuf); - } - else - for (int match = 0; match < g_nDevices; match++) - if ( IsEqualGUID(g_devList[match].guidInstance, g_ivConfig->Shortcuts.Player[i].aButtons[j].parentDevice->guidInstance) ) - { - char szBuf[DEFAULT_BUFFER]; - // add to the appropriate device stream - sprintf(szBuf, STRING_INI_BUTTON "=%d %d %02X %d %d\n", i, j, g_ivConfig->Shortcuts.Player[i].aButtons[j].bOffset, g_ivConfig->Shortcuts.Player[i].aButtons[j].bAxisID, g_ivConfig->Shortcuts.Player[i].aButtons[j].bBtnType); - strDevs[match].append(szBuf); - break; - } - } - } // end buttons for - } // end Player for + for ( int i = 0; i < 4; i++ ) // Player for + { + for ( int j = 0; j < SC_TOTAL; j++ ) // aButtons for + { + if (g_ivConfig->Shortcuts.Player[i].aButtons[j].parentDevice) // possibly unbound + { + if ( IsEqualGUID(g_sysMouse.guidInstance, g_ivConfig->Shortcuts.Player[i].aButtons[j].parentDevice->guidInstance) ) + { + char szBuf[DEFAULT_BUFFER]; + // add to the mouse stream + sprintf(szBuf, STRING_INI_BUTTON "=%d %d %02X %d %d\n", i, j, g_ivConfig->Shortcuts.Player[i].aButtons[j].bOffset, g_ivConfig->Shortcuts.Player[i].aButtons[j].bAxisID, g_ivConfig->Shortcuts.Player[i].aButtons[j].bBtnType); + strMouse.append(szBuf); + } + else + for (int match = 0; match < g_nDevices; match++) + if ( IsEqualGUID(g_devList[match].guidInstance, g_ivConfig->Shortcuts.Player[i].aButtons[j].parentDevice->guidInstance) ) + { + char szBuf[DEFAULT_BUFFER]; + // add to the appropriate device stream + sprintf(szBuf, STRING_INI_BUTTON "=%d %d %02X %d %d\n", i, j, g_ivConfig->Shortcuts.Player[i].aButtons[j].bOffset, g_ivConfig->Shortcuts.Player[i].aButtons[j].bAxisID, g_ivConfig->Shortcuts.Player[i].aButtons[j].bBtnType); + strDevs[match].append(szBuf); + break; + } + } + } // end buttons for + } // end Player for - // gotta do it again for that one pesky mouselock button - if (g_ivConfig->Shortcuts.bMouseLock.parentDevice) // possibly unbound - { - if ( IsEqualGUID(g_sysMouse.guidInstance, g_ivConfig->Shortcuts.bMouseLock.parentDevice->guidInstance) ) - { - char szBuf[DEFAULT_BUFFER]; - // add to the mouse stream - sprintf(szBuf, STRING_INI_BUTTON "=%d %d %02X %d %d\n", -1, 0, g_ivConfig->Shortcuts.bMouseLock.bOffset, g_ivConfig->Shortcuts.bMouseLock.bAxisID, g_ivConfig->Shortcuts.bMouseLock.bBtnType); - strMouse.append(szBuf); - } - else - for (int match = 0; match < g_nDevices; match++) - if ( IsEqualGUID(g_devList[match].guidInstance, g_ivConfig->Shortcuts.bMouseLock.parentDevice->guidInstance) ) - { - char szBuf[DEFAULT_BUFFER]; - // add to the appropriate device stream - sprintf(szBuf, STRING_INI_BUTTON "=%d %d %02X %d %d\n", -1, 0, g_ivConfig->Shortcuts.bMouseLock.bOffset, g_ivConfig->Shortcuts.bMouseLock.bAxisID, g_ivConfig->Shortcuts.bMouseLock.bBtnType); - strDevs[match].append(szBuf); - break; - } - } // end shortcuts edge case + // gotta do it again for that one pesky mouselock button + if (g_ivConfig->Shortcuts.bMouseLock.parentDevice) // possibly unbound + { + if ( IsEqualGUID(g_sysMouse.guidInstance, g_ivConfig->Shortcuts.bMouseLock.parentDevice->guidInstance) ) + { + char szBuf[DEFAULT_BUFFER]; + // add to the mouse stream + sprintf(szBuf, STRING_INI_BUTTON "=%d %d %02X %d %d\n", -1, 0, g_ivConfig->Shortcuts.bMouseLock.bOffset, g_ivConfig->Shortcuts.bMouseLock.bAxisID, g_ivConfig->Shortcuts.bMouseLock.bBtnType); + strMouse.append(szBuf); + } + else + for (int match = 0; match < g_nDevices; match++) + if ( IsEqualGUID(g_devList[match].guidInstance, g_ivConfig->Shortcuts.bMouseLock.parentDevice->guidInstance) ) + { + char szBuf[DEFAULT_BUFFER]; + // add to the appropriate device stream + sprintf(szBuf, STRING_INI_BUTTON "=%d %d %02X %d %d\n", -1, 0, g_ivConfig->Shortcuts.bMouseLock.bOffset, g_ivConfig->Shortcuts.bMouseLock.bAxisID, g_ivConfig->Shortcuts.bMouseLock.bBtnType); + strDevs[match].append(szBuf); + break; + } + } // end shortcuts edge case - DumpStreams(fFile, strMouse, strDevs, strNull, bIsINI); + DumpStreams(fFile, strMouse, strDevs, strNull, bIsINI); } // load shortcuts from "resources", i.e. builtin defaults bool LoadShortcutsFromResource(bool bIsInterface) { - if (bIsInterface) - ZeroMemory( &(g_ivConfig->Shortcuts), sizeof(SHORTCUTS) ); - TCHAR szId[20]; - wsprintf( szId, _T("#%i"), IDR_SHORTCUTS_DEFAULT ); - HRSRC res = FindResource( g_strEmuInfo.hinst, szId, _T("SHORTCUT") ); - if( res == NULL ) - return false; - char *profile = (char*)LockResource( LoadResource( g_strEmuInfo.hinst, res )); - char *profileend = profile + SizeofResource( g_strEmuInfo.hinst, res ); - - ProcessKey( PL_RESET, 0, 0, 0, 0, bIsInterface ); - DWORD dwCommand = PL_NOHIT; - char szLine[4096]; - while( profile < profileend ) - { - while( profile < profileend && (CHECK_WHITESPACES( *profile ) || *profile == ' ' )) - ++profile; - int i = 0; - while( profile < profileend && i < sizeof(szLine)-1 && !(CHECK_WHITESPACES( *profile )) ) - szLine[i++] = *profile++; + if (bIsInterface) + ZeroMemory( &(g_ivConfig->Shortcuts), sizeof(SHORTCUTS) ); + TCHAR szId[20]; + wsprintf( szId, _T("#%i"), IDR_SHORTCUTS_DEFAULT ); + HRSRC res = FindResource( g_strEmuInfo.hinst, szId, _T("SHORTCUT") ); + if( res == NULL ) + return false; + char *profile = (char*)LockResource( LoadResource( g_strEmuInfo.hinst, res )); + char *profileend = profile + SizeofResource( g_strEmuInfo.hinst, res ); - szLine[i] = '\0'; - dwCommand = ParseLine( szLine ); - ProcessKey( dwCommand, CHK_SHORTCUTS, szLine, 0, 0, bIsInterface ); - } - return true; + ProcessKey( PL_RESET, 0, 0, 0, 0, bIsInterface ); + DWORD dwCommand = PL_NOHIT; + char szLine[4096]; + while( profile < profileend ) + { + while( profile < profileend && (CHECK_WHITESPACES( *profile ) || *profile == ' ' )) + ++profile; + int i = 0; + while( profile < profileend && i < sizeof(szLine)-1 && !(CHECK_WHITESPACES( *profile )) ) + szLine[i++] = *profile++; + + szLine[i] = '\0'; + dwCommand = ParseLine( szLine ); + ProcessKey( dwCommand, CHK_SHORTCUTS, szLine, 0, 0, bIsInterface ); + } + return true; } // returns the user-chosen default directory (path) for each of the following: -// application dir, mempak dir, gameboy rom dir, gameboyrom save dir -// Tries to query user settings; if blank or invalid, returns their defaults +// application dir, mempak dir, gameboy rom dir, gameboyrom save dir +// Tries to query user settings; if blank or invalid, returns their defaults // Massages the output directory a bit bool GetDirectory( LPTSTR pszDirectory, WORD wDirID ) { - bool bReturn = true; - TCHAR szBuffer[MAX_PATH + 1]; - const TCHAR szDefaultStrings[3][DEFAULT_BUFFER] = { STRING_DEF_MEMPAKFILE, STRING_DEF_GBROMFILE, STRING_DEF_GBROMSAVE }; - TCHAR *pSlash; + bool bReturn = true; + TCHAR szBuffer[MAX_PATH + 1]; + const TCHAR szDefaultStrings[3][DEFAULT_BUFFER] = { STRING_DEF_MEMPAKFILE, STRING_DEF_GBROMFILE, STRING_DEF_GBROMSAVE }; + TCHAR *pSlash; - pszDirectory[0] = pszDirectory[1] = '\0'; + pszDirectory[0] = pszDirectory[1] = '\0'; - switch( wDirID ) - { - case DIRECTORY_MEMPAK: - case DIRECTORY_GBROMS: - case DIRECTORY_GBSAVES: - if (g_aszDefFolders[wDirID][0] == 0) - lstrcpyn( pszDirectory, szDefaultStrings[wDirID], MAX_PATH); - else - lstrcpyn( pszDirectory, g_aszDefFolders[wDirID], MAX_PATH); - break; + switch( wDirID ) + { + case DIRECTORY_MEMPAK: + case DIRECTORY_GBROMS: + case DIRECTORY_GBSAVES: + if (g_aszDefFolders[wDirID][0] == 0) + lstrcpyn( pszDirectory, szDefaultStrings[wDirID], MAX_PATH); + else + lstrcpyn( pszDirectory, g_aszDefFolders[wDirID], MAX_PATH); + break; - case DIRECTORY_DLL: - if (GetModuleFileName(g_strEmuInfo.hinst, szBuffer, MAX_PATH)) - { - GetFullPathName( szBuffer, MAX_PATH, pszDirectory, &pSlash ); - *pSlash = 0; - } - break; - case DIRECTORY_LOG: - case DIRECTORY_CONFIG: - case DIRECTORY_APPLICATION: - break; + case DIRECTORY_DLL: + if (GetModuleFileName(g_strEmuInfo.hinst, szBuffer, MAX_PATH)) + { + GetFullPathName( szBuffer, MAX_PATH, pszDirectory, &pSlash ); + *pSlash = 0; + } + break; + case DIRECTORY_LOG: + case DIRECTORY_CONFIG: + case DIRECTORY_APPLICATION: + break; - default: - // we don't know what the hell you're talking about, set pszFileName to current .exe directory - // and return false - bReturn = false; - } + default: + // we don't know what the hell you're talking about, set pszFileName to current .exe directory + // and return false + bReturn = false; + } - if( pszDirectory[1] == ':' || ( pszDirectory[1] == '\\' && pszDirectory[0] == '\\' )) // Absolute Path( x: or \\ ) - lstrcpyn( szBuffer, pszDirectory, MAX_PATH ); - else - { - GetModuleFileName( NULL, szBuffer, MAX_PATH ); - pSlash = _tcsrchr( szBuffer, '\\' ); - ++pSlash; - lstrcpyn( pSlash, pszDirectory, MAX_PATH ); - } - GetFullPathName( szBuffer, MAX_PATH, pszDirectory, &pSlash ); + if( pszDirectory[1] == ':' || ( pszDirectory[1] == '\\' && pszDirectory[0] == '\\' )) // Absolute Path( x: or \\ ) + lstrcpyn( szBuffer, pszDirectory, MAX_PATH ); + else + { + GetModuleFileName( NULL, szBuffer, MAX_PATH ); + pSlash = _tcsrchr( szBuffer, '\\' ); + ++pSlash; + lstrcpyn( pSlash, pszDirectory, MAX_PATH ); + } + GetFullPathName( szBuffer, MAX_PATH, pszDirectory, &pSlash ); - pSlash = &pszDirectory[lstrlen( pszDirectory ) - 1]; - if( *pSlash != '\\' ) - { - pSlash[1] = '\\'; - pSlash[2] = '\0'; - } + pSlash = &pszDirectory[lstrlen( pszDirectory ) - 1]; + if( *pSlash != '\\' ) + { + pSlash[1] = '\\'; + pSlash[2] = '\0'; + } - if (bReturn && wDirID == DIRECTORY_CONFIG) - { - strcat(pszDirectory,"Config\\"); - } - if (bReturn && wDirID == DIRECTORY_LOG) - { - strcat(pszDirectory,"Logs\\"); - } - return bReturn; + if (bReturn && wDirID == DIRECTORY_CONFIG) + { + strcat(pszDirectory,"Config\\"); + } + if (bReturn && wDirID == DIRECTORY_LOG) + { + strcat(pszDirectory,"Logs\\"); + } + return bReturn; } // Attempts to store the "absolute" filename for a file; -// if szFileName is an absolute filename (starting with a letter and colon or two backslashes) it is simply copied -// otherwise, it is concatenated with the known directory, such as mempak directory (type given by wDirID) +// if szFileName is an absolute filename (starting with a letter and colon or two backslashes) it is simply copied +// otherwise, it is concatenated with the known directory, such as mempak directory (type given by wDirID) void GetAbsoluteFileName( TCHAR *szAbsolute, const TCHAR *szFileName, const WORD wDirID ) { - if( szFileName[1] == ':' || (szFileName[1] == '\\' && szFileName[0] == '\\')) - lstrcpyn( szAbsolute, szFileName, MAX_PATH ); - else - { - GetDirectory( szAbsolute, wDirID ); - lstrcat( szAbsolute, szFileName); // HACK: possible buffer overflow - } + if( szFileName[1] == ':' || (szFileName[1] == '\\' && szFileName[0] == '\\')) + lstrcpyn( szAbsolute, szFileName, MAX_PATH ); + else + { + GetDirectory( szAbsolute, wDirID ); + lstrcat( szAbsolute, szFileName); // HACK: possible buffer overflow + } } // Populates the list of mempak/transfer pak files from the config'd directory BOOL SendFilestoList( HWND hDlgItem, WORD wType ) { - HANDLE hFindFile; + HANDLE hFindFile; - WIN32_FIND_DATA FindFile; - TCHAR szPattern[MAX_PATH + 10]; - TCHAR *pszExtensions; - BOOL Success; + WIN32_FIND_DATA FindFile; + TCHAR szPattern[MAX_PATH + 10]; + TCHAR *pszExtensions; + BOOL Success; - switch( wType ) - { - case FILIST_MEM: - GetDirectory( szPattern, DIRECTORY_MEMPAK ); - lstrcat( szPattern, _T("*.*") ); - pszExtensions = _T(".mpk\0.n64\0"); - break; - case FILIST_TRANSFER: - GetDirectory( szPattern, DIRECTORY_GBROMS ); - lstrcat( szPattern, _T("*.gb?") ); - pszExtensions = _T(".gb\0.gbc\0"); - break; - default: - return FALSE; - } + switch( wType ) + { + case FILIST_MEM: + GetDirectory( szPattern, DIRECTORY_MEMPAK ); + lstrcat( szPattern, _T("*.*") ); + pszExtensions = _T(".mpk\0.n64\0"); + break; + case FILIST_TRANSFER: + GetDirectory( szPattern, DIRECTORY_GBROMS ); + lstrcat( szPattern, _T("*.gb?") ); + pszExtensions = _T(".gb\0.gbc\0"); + break; + default: + return FALSE; + } - TCHAR *pcPoint; - TCHAR *pszExt; - bool bValidFile; + TCHAR *pcPoint; + TCHAR *pszExt; + bool bValidFile; - hFindFile = FindFirstFile( szPattern, &FindFile ); - if( hFindFile != INVALID_HANDLE_VALUE ) - { - do - { - pszExt = pszExtensions; - pcPoint = _tcsrchr( FindFile.cFileName, _T('.') ); - bValidFile = false; - do - { - if( !lstrcmpi( pcPoint, pszExt )) - bValidFile = true; - pszExt += lstrlen( pszExt ) + 1; - } - while( *pszExt && !bValidFile ); + hFindFile = FindFirstFile( szPattern, &FindFile ); + if( hFindFile != INVALID_HANDLE_VALUE ) + { + do + { + pszExt = pszExtensions; + pcPoint = _tcsrchr( FindFile.cFileName, _T('.') ); + bValidFile = false; + do + { + if( !lstrcmpi( pcPoint, pszExt )) + bValidFile = true; + pszExt += lstrlen( pszExt ) + 1; + } + while( *pszExt && !bValidFile ); - if( bValidFile ) - SendMessage( hDlgItem, LB_ADDSTRING, 0, (LPARAM)FindFile.cFileName ); - } - while( FindNextFile( hFindFile, &FindFile )); - FindClose( hFindFile ); - Success = TRUE; - } - else - Success = FALSE; + if( bValidFile ) + SendMessage( hDlgItem, LB_ADDSTRING, 0, (LPARAM)FindFile.cFileName ); + } + while( FindNextFile( hFindFile, &FindFile )); + FindClose( hFindFile ); + Success = TRUE; + } + else + Success = FALSE; - return Success; + return Success; } bool BrowseFolders( HWND hwndParent, TCHAR *pszHeader, TCHAR *pszDirectory ) { - ITEMIDLIST *piStart = NULL; + ITEMIDLIST *piStart = NULL; - if( pszDirectory[0] != '\0') - { - IShellFolder* pDesktopFolder; - if( SUCCEEDED( SHGetDesktopFolder( &pDesktopFolder ))) - { - OLECHAR olePath[MAX_PATH]; - ULONG chEaten; + if( pszDirectory[0] != '\0') + { + IShellFolder* pDesktopFolder; + if( SUCCEEDED( SHGetDesktopFolder( &pDesktopFolder ))) + { + OLECHAR olePath[MAX_PATH]; + ULONG chEaten; - pDesktopFolder->ParseDisplayName( NULL, NULL, olePath, &chEaten, &piStart, NULL ); + pDesktopFolder->ParseDisplayName( NULL, NULL, olePath, &chEaten, &piStart, NULL ); - pDesktopFolder->Release(); - } - } + pDesktopFolder->Release(); + } + } - BROWSEINFO brInfo; - brInfo.hwndOwner = hwndParent; - brInfo.pidlRoot = piStart; - brInfo.pszDisplayName = pszDirectory; - brInfo.lpszTitle = pszHeader; - brInfo.ulFlags = BIF_RETURNONLYFSDIRS; - brInfo.lpfn = NULL; + BROWSEINFO brInfo; + brInfo.hwndOwner = hwndParent; + brInfo.pidlRoot = piStart; + brInfo.pszDisplayName = pszDirectory; + brInfo.lpszTitle = pszHeader; + brInfo.ulFlags = BIF_RETURNONLYFSDIRS; + brInfo.lpfn = NULL; - ITEMIDLIST *piList; + ITEMIDLIST *piList; - piList = SHBrowseForFolder( &brInfo ); - if( piList ) - { - SHGetPathFromIDList( (const LPITEMIDLIST)piList, pszDirectory ); - LPMALLOC pMal; - if( SUCCEEDED( SHGetMalloc( &pMal ))) - { - pMal->Free( piList ); - pMal->Release(); - } - return true; - } + piList = SHBrowseForFolder( &brInfo ); + if( piList ) + { + SHGetPathFromIDList( (const LPITEMIDLIST)piList, pszDirectory ); + LPMALLOC pMal; + if( SUCCEEDED( SHGetMalloc( &pMal ))) + { + pMal->Free( piList ); + pMal->Release(); + } + return true; + } - return false; + return false; } bool GetInitialBrowseDir( TCHAR *pszFileName, DWORD dwType ) { - // DIRECTORY_INVALID means there's no corresponding entry in g_aszDefFolders - const WORD wDirectory[] = { DIRECTORY_MEMPAK, DIRECTORY_GBROMS, DIRECTORY_GBSAVES, - DIRECTORY_INVALID, DIRECTORY_INVALID, DIRECTORY_INVALID }; - switch( dwType ) - { - case BF_PROFILE: - case BF_MEMPAK: - case BF_NOTE: - case BF_GBROM: - case BF_GBSAVE: - case BF_SHORTCUTS: - if (g_aszLastBrowse[dwType][0] == 0) - return GetDirectory( pszFileName, wDirectory[dwType]); - else - lstrcpyn(pszFileName, g_aszLastBrowse[dwType], MAX_PATH); - return true; + // DIRECTORY_INVALID means there's no corresponding entry in g_aszDefFolders + const WORD wDirectory[] = { DIRECTORY_MEMPAK, DIRECTORY_GBROMS, DIRECTORY_GBSAVES, + DIRECTORY_INVALID, DIRECTORY_INVALID, DIRECTORY_INVALID }; + switch( dwType ) + { + case BF_PROFILE: + case BF_MEMPAK: + case BF_NOTE: + case BF_GBROM: + case BF_GBSAVE: + case BF_SHORTCUTS: + if (g_aszLastBrowse[dwType][0] == 0) + return GetDirectory( pszFileName, wDirectory[dwType]); + else + lstrcpyn(pszFileName, g_aszLastBrowse[dwType], MAX_PATH); + return true; - default: // we don't know what the hell you're talking about - return GetDirectory( pszFileName, DIRECTORY_INVALID ); - } + default: // we don't know what the hell you're talking about + return GetDirectory( pszFileName, DIRECTORY_INVALID ); + } } bool SaveLastBrowseDir( TCHAR *pszFileName, DWORD dwType ) { - TCHAR *cSlash = _tcsrchr( pszFileName, _T('\\') ); - if( cSlash ) - { - switch( dwType ) - { - case BF_PROFILE: - case BF_MEMPAK: - case BF_NOTE: - case BF_GBROM: - case BF_GBSAVE: - case BF_SHORTCUTS: - *cSlash = '\0'; - lstrcpyn(g_aszLastBrowse[dwType], pszFileName, MAX_PATH); - *cSlash = '\\'; - return true; - default: - return false; - } - } - else - return true; + TCHAR *cSlash = _tcsrchr( pszFileName, _T('\\') ); + if( cSlash ) + { + switch( dwType ) + { + case BF_PROFILE: + case BF_MEMPAK: + case BF_NOTE: + case BF_GBROM: + case BF_GBSAVE: + case BF_SHORTCUTS: + *cSlash = '\0'; + lstrcpyn(g_aszLastBrowse[dwType], pszFileName, MAX_PATH); + *cSlash = '\\'; + return true; + default: + return false; + } + } + else + return true; } // Pop up a dialog asking for a filename from the user. Returns true if returning a valid filename, false if user cancelled. @@ -1105,188 +1105,188 @@ bool SaveLastBrowseDir( TCHAR *pszFileName, DWORD dwType ) // Handy, because it handles all our file type extensions for us. bool BrowseFile( HWND hDlg, TCHAR *pszFileName, DWORD dwType, bool fSave ) { - TCHAR pszFilter[DEFAULT_BUFFER]; - TCHAR pszTitle[DEFAULT_BUFFER]; - DWORD dwFlags = /*OFN_DONTADDTORECENT |*/ OFN_NOCHANGEDIR; - dwFlags |= (fSave) ? OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT - : OFN_HIDEREADONLY | OFN_FILEMUSTEXIST; - TCHAR *pszExt = NULL; + TCHAR pszFilter[DEFAULT_BUFFER]; + TCHAR pszTitle[DEFAULT_BUFFER]; + DWORD dwFlags = /*OFN_DONTADDTORECENT |*/ OFN_NOCHANGEDIR; + dwFlags |= (fSave) ? OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT + : OFN_HIDEREADONLY | OFN_FILEMUSTEXIST; + TCHAR *pszExt = NULL; - TCHAR *pszTemp = pszFilter; - int nFilters = 0; + TCHAR *pszTemp = pszFilter; + int nFilters = 0; - switch( dwType ) - { - case BF_PROFILE: - LoadString( g_hResourceDLL, IDS_DLG_CPF, pszFilter, DEFAULT_BUFFER ); - pszExt = _T("cpf"); - nFilters = 1; - break; - case BF_MEMPAK: - LoadString( g_hResourceDLL, IDS_DLG_MPKN64, pszFilter, DEFAULT_BUFFER ); - if( !fSave ) - { - LoadString( g_hResourceDLL, IDS_DLG_MPCHOOSE, pszTitle, DEFAULT_BUFFER ); - dwFlags = OFN_HIDEREADONLY; - } - pszExt = _T("mpk"); - nFilters = 2; - break; - case BF_NOTE: - LoadString( g_hResourceDLL, IDS_DLG_A64, pszFilter, DEFAULT_BUFFER ); - pszExt = _T("a64"); - nFilters = 1; - break; - case BF_GBROM: - LoadString( g_hResourceDLL, IDS_DLG_GBGBC, pszFilter, DEFAULT_BUFFER ); - pszExt = _T("gb"); - nFilters = 1; - break; - case BF_GBSAVE: - LoadString( g_hResourceDLL, IDS_DLG_SVSAV, pszFilter, DEFAULT_BUFFER ); - pszExt = _T("sv"); - nFilters = 1; - break; - case BF_SHORTCUTS: - LoadString( g_hResourceDLL, IDS_DLG_SC, pszFilter, DEFAULT_BUFFER ); - pszExt = _T("sc"); - nFilters = 1; - break; - default: - return false; - } + switch( dwType ) + { + case BF_PROFILE: + LoadString( g_hResourceDLL, IDS_DLG_CPF, pszFilter, DEFAULT_BUFFER ); + pszExt = _T("cpf"); + nFilters = 1; + break; + case BF_MEMPAK: + LoadString( g_hResourceDLL, IDS_DLG_MPKN64, pszFilter, DEFAULT_BUFFER ); + if( !fSave ) + { + LoadString( g_hResourceDLL, IDS_DLG_MPCHOOSE, pszTitle, DEFAULT_BUFFER ); + dwFlags = OFN_HIDEREADONLY; + } + pszExt = _T("mpk"); + nFilters = 2; + break; + case BF_NOTE: + LoadString( g_hResourceDLL, IDS_DLG_A64, pszFilter, DEFAULT_BUFFER ); + pszExt = _T("a64"); + nFilters = 1; + break; + case BF_GBROM: + LoadString( g_hResourceDLL, IDS_DLG_GBGBC, pszFilter, DEFAULT_BUFFER ); + pszExt = _T("gb"); + nFilters = 1; + break; + case BF_GBSAVE: + LoadString( g_hResourceDLL, IDS_DLG_SVSAV, pszFilter, DEFAULT_BUFFER ); + pszExt = _T("sv"); + nFilters = 1; + break; + case BF_SHORTCUTS: + LoadString( g_hResourceDLL, IDS_DLG_SC, pszFilter, DEFAULT_BUFFER ); + pszExt = _T("sc"); + nFilters = 1; + break; + default: + return false; + } - for ( ; nFilters > 0; nFilters--) - { - pszTemp += _tcslen(pszTemp); - pszTemp += 1; - pszTemp += _tcslen(pszTemp); - pszTemp += 1; - } - *pszTemp = _T('\0'); + for ( ; nFilters > 0; nFilters--) + { + pszTemp += _tcslen(pszTemp); + pszTemp += 1; + pszTemp += _tcslen(pszTemp); + pszTemp += 1; + } + *pszTemp = _T('\0'); - dwFlags |= OFN_NOCHANGEDIR; + dwFlags |= OFN_NOCHANGEDIR; - TCHAR szFileName[MAX_PATH+1] = _T(""), - szInitialDir[MAX_PATH+1] = _T(""), - *pcSlash; + TCHAR szFileName[MAX_PATH+1] = _T(""), + szInitialDir[MAX_PATH+1] = _T(""), + *pcSlash; - if( pszFileName[1] == _T(':') || ( pszFileName[1] == _T('\\') && pszFileName[0] == _T('\\') )) - { - lstrcpyn( szInitialDir, pszFileName, ARRAYSIZE(szInitialDir) ); - pcSlash = _tcsrchr( szInitialDir, _T('\\') ); - if( pcSlash ) - { - *pcSlash = _T('\0'); - lstrcpyn( szFileName, &pcSlash[1], ARRAYSIZE(szFileName) ); - } - } - else - { - if( !GetInitialBrowseDir( szInitialDir, dwType )) - GetDirectory( szInitialDir, DIRECTORY_APPLICATION ); - lstrcpyn( szFileName, pszFileName, ARRAYSIZE(szFileName) ); - } + if( pszFileName[1] == _T(':') || ( pszFileName[1] == _T('\\') && pszFileName[0] == _T('\\') )) + { + lstrcpyn( szInitialDir, pszFileName, ARRAYSIZE(szInitialDir) ); + pcSlash = _tcsrchr( szInitialDir, _T('\\') ); + if( pcSlash ) + { + *pcSlash = _T('\0'); + lstrcpyn( szFileName, &pcSlash[1], ARRAYSIZE(szFileName) ); + } + } + else + { + if( !GetInitialBrowseDir( szInitialDir, dwType )) + GetDirectory( szInitialDir, DIRECTORY_APPLICATION ); + lstrcpyn( szFileName, pszFileName, ARRAYSIZE(szFileName) ); + } - OPENFILENAME oFile; + OPENFILENAME oFile; - oFile.lStructSize = sizeof (OPENFILENAME); - oFile.hwndOwner = hDlg; - oFile.hInstance = NULL; - oFile.lpstrFilter = pszFilter; - oFile.lpstrCustomFilter = NULL; - oFile.nMaxCustFilter = 0; - oFile.nFilterIndex = 0; - oFile.lpstrFile = szFileName; - oFile.nMaxFile = MAX_PATH; - oFile.lpstrFileTitle = NULL; - oFile.nMaxFileTitle = MAX_PATH; // ignored - oFile.lpstrInitialDir = szInitialDir; - oFile.lpstrTitle = pszTitle; - oFile.Flags = dwFlags; - oFile.nFileOffset = 0; - oFile.nFileExtension = 0; - oFile.lpstrDefExt = pszExt; - oFile.lCustData = 0L; - oFile.lpfnHook = NULL; - oFile.lpTemplateName = NULL; + oFile.lStructSize = sizeof (OPENFILENAME); + oFile.hwndOwner = hDlg; + oFile.hInstance = NULL; + oFile.lpstrFilter = pszFilter; + oFile.lpstrCustomFilter = NULL; + oFile.nMaxCustFilter = 0; + oFile.nFilterIndex = 0; + oFile.lpstrFile = szFileName; + oFile.nMaxFile = MAX_PATH; + oFile.lpstrFileTitle = NULL; + oFile.nMaxFileTitle = MAX_PATH; // ignored + oFile.lpstrInitialDir = szInitialDir; + oFile.lpstrTitle = pszTitle; + oFile.Flags = dwFlags; + oFile.nFileOffset = 0; + oFile.nFileExtension = 0; + oFile.lpstrDefExt = pszExt; + oFile.lCustData = 0L; + oFile.lpfnHook = NULL; + oFile.lpTemplateName = NULL; - if( fSave ) - { - if( !GetSaveFileName( &oFile )) - return false; - } - else - { - if( !GetOpenFileName( &oFile )) - return false; - } + if( fSave ) + { + if( !GetSaveFileName( &oFile )) + return false; + } + else + { + if( !GetOpenFileName( &oFile )) + return false; + } - lstrcpy( pszFileName, szFileName ); - SaveLastBrowseDir( szFileName, dwType ); - return true; + lstrcpy( pszFileName, szFileName ); + SaveLastBrowseDir( szFileName, dwType ); + return true; } bool ReadMemPakFile( TCHAR *pszMemPakFile, BYTE *aMemPak, bool fCreate ) { - DWORD dwCreationDisposition = fCreate ? OPEN_ALWAYS : OPEN_EXISTING; + DWORD dwCreationDisposition = fCreate ? OPEN_ALWAYS : OPEN_EXISTING; - HANDLE hFile = CreateFile( pszMemPakFile, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, dwCreationDisposition, 0, NULL); - if ( hFile != INVALID_HANDLE_VALUE ) - { - ZeroMemory( aMemPak, PAK_MEM_SIZE ); - TCHAR *pcPoint = _tcsrchr( pszMemPakFile, '.' ); - if( !lstrcmpi( pcPoint, _T(".n64") ) ) - SetFilePointer( hFile, 0x1040, NULL, FILE_BEGIN ); - else - SetFilePointer( hFile, 0L, NULL, FILE_BEGIN ); - - DWORD dwBytesRead; - bool Success = ( ReadFile( hFile, aMemPak, PAK_MEM_SIZE, &dwBytesRead, NULL) != 0 ); + HANDLE hFile = CreateFile( pszMemPakFile, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, dwCreationDisposition, 0, NULL); + if ( hFile != INVALID_HANDLE_VALUE ) + { + ZeroMemory( aMemPak, PAK_MEM_SIZE ); + TCHAR *pcPoint = _tcsrchr( pszMemPakFile, '.' ); + if( !lstrcmpi( pcPoint, _T(".n64") ) ) + SetFilePointer( hFile, 0x1040, NULL, FILE_BEGIN ); + else + SetFilePointer( hFile, 0L, NULL, FILE_BEGIN ); - CloseHandle( hFile ); - return Success; - } - else - ErrorMessage( IDS_ERR_MPREAD, GetLastError(), false ); - return false; + DWORD dwBytesRead; + bool Success = ( ReadFile( hFile, aMemPak, PAK_MEM_SIZE, &dwBytesRead, NULL) != 0 ); + + CloseHandle( hFile ); + return Success; + } + else + ErrorMessage( IDS_ERR_MPREAD, GetLastError(), false ); + return false; } // Used by Interface to create or modify mempak files (not mapped). // pszMemPakFile is a filename, aMemPak is the data, fCreate tells whether to create a new file bool WriteMemPakFile( TCHAR *pszMemPakFile, BYTE *aMemPak, bool fCreate ) { - DWORD dwCreationDisposition = fCreate ? OPEN_ALWAYS : OPEN_EXISTING; + DWORD dwCreationDisposition = fCreate ? OPEN_ALWAYS : OPEN_EXISTING; - HANDLE hFile = CreateFile( pszMemPakFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, dwCreationDisposition, 0, NULL); - if ( hFile != INVALID_HANDLE_VALUE ) - { - DWORD dwBytesWritten = 0; - TCHAR *pcPoint = _tcsrchr( pszMemPakFile, _T('.') ); - if( !lstrcmpi( pcPoint, _T(".n64") ) ) - { - if( fCreate && !GetFileSize( hFile, NULL )) - { - char szHeader[] = "123-456-STD"; - SetFilePointer( hFile, 0L, NULL, FILE_BEGIN ); - WriteFile( hFile, szHeader, sizeof(szHeader), &dwBytesWritten, NULL ); - } - SetFilePointer( hFile, 0x1040, NULL, FILE_BEGIN ); - } - else - SetFilePointer( hFile, 0L, NULL, FILE_BEGIN ); - - bool Success = ( WriteFile( hFile, aMemPak, PAK_MEM_SIZE, &dwBytesWritten, NULL ) != 0 ); - if( Success ) - SetEndOfFile( hFile ); - - CloseHandle( hFile ); - return Success; - } - else - ErrorMessage( IDS_ERR_MPCREATE, GetLastError(), false ); + HANDLE hFile = CreateFile( pszMemPakFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, dwCreationDisposition, 0, NULL); + if ( hFile != INVALID_HANDLE_VALUE ) + { + DWORD dwBytesWritten = 0; + TCHAR *pcPoint = _tcsrchr( pszMemPakFile, _T('.') ); + if( !lstrcmpi( pcPoint, _T(".n64") ) ) + { + if( fCreate && !GetFileSize( hFile, NULL )) + { + char szHeader[] = "123-456-STD"; + SetFilePointer( hFile, 0L, NULL, FILE_BEGIN ); + WriteFile( hFile, szHeader, sizeof(szHeader), &dwBytesWritten, NULL ); + } + SetFilePointer( hFile, 0x1040, NULL, FILE_BEGIN ); + } + else + SetFilePointer( hFile, 0L, NULL, FILE_BEGIN ); - return false; + bool Success = ( WriteFile( hFile, aMemPak, PAK_MEM_SIZE, &dwBytesWritten, NULL ) != 0 ); + if( Success ) + SetEndOfFile( hFile ); + + CloseHandle( hFile ); + return Success; + } + else + ErrorMessage( IDS_ERR_MPCREATE, GetLastError(), false ); + + return false; } // This func stores the current config data to INI. It stores the Interface's idea of configuration @@ -1294,98 +1294,98 @@ bool WriteMemPakFile( TCHAR *pszMemPakFile, BYTE *aMemPak, bool fCreate ) // Returns true if saved OK, false if there was a problem. bool StoreConfigToINI() { - char szANSIBuf[DEFAULT_BUFFER]; - if (!g_ivConfig) - return false; + char szANSIBuf[DEFAULT_BUFFER]; + if (!g_ivConfig) + return false; - TCHAR szFilename[MAX_PATH]; - GetDirectory(szFilename, DIRECTORY_CONFIG); - _tcscat(szFilename, _T("NRage.ini")); - FILE *fFile = _tfopen(szFilename, _T("wS")); // write, optimize for sequential + TCHAR szFilename[MAX_PATH]; + GetDirectory(szFilename, DIRECTORY_CONFIG); + _tcscat(szFilename, _T("NRage.ini")); + FILE *fFile = _tfopen(szFilename, _T("wS")); // write, optimize for sequential - if (!fFile) - { - DebugWriteA("Couldn't open INI file for output!\n"); - return false; - } + if (!fFile) + { + DebugWriteA("Couldn't open INI file for output!\n"); + return false; + } - // first write out any standard header stuff here - fputs(STRING_INI_HEADER, fFile); + // first write out any standard header stuff here + fputs(STRING_INI_HEADER, fFile); - // General - fputs("\n[" STRING_INI_GENERAL "]\n", fFile); - fprintf(fFile, STRING_INI_LANGUAGE "=%d\n", g_ivConfig->Language); - fprintf(fFile, STRING_INI_SHOWMESSAGES "=%d\n", (int)(g_ivConfig->fDisplayShortPop)); + // General + fputs("\n[" STRING_INI_GENERAL "]\n", fFile); + fprintf(fFile, STRING_INI_LANGUAGE "=%d\n", g_ivConfig->Language); + fprintf(fFile, STRING_INI_SHOWMESSAGES "=%d\n", (int)(g_ivConfig->fDisplayShortPop)); - // Folders - fputs("\n[" STRING_INI_FOLDERS "]\n", fFile); - const char szFolders[ARRAYSIZE(g_aszDefFolders)][DEFAULT_BUFFER] = {STRING_INI_BRMEMPAK "=%s\n", STRING_INI_BRGBROM "=%s\n", STRING_INI_BRGBSAVE "=%s\n"}; - for (int i = 0; i < ARRAYSIZE(szFolders); i++) - { - TCHAR_TO_CHAR( szANSIBuf, g_aszDefFolders[i], DEFAULT_BUFFER ); - fprintf(fFile, szFolders[i], szANSIBuf); - } + // Folders + fputs("\n[" STRING_INI_FOLDERS "]\n", fFile); + const char szFolders[ARRAYSIZE(g_aszDefFolders)][DEFAULT_BUFFER] = {STRING_INI_BRMEMPAK "=%s\n", STRING_INI_BRGBROM "=%s\n", STRING_INI_BRGBSAVE "=%s\n"}; + for (int i = 0; i < ARRAYSIZE(szFolders); i++) + { + TCHAR_TO_CHAR( szANSIBuf, g_aszDefFolders[i], DEFAULT_BUFFER ); + fprintf(fFile, szFolders[i], szANSIBuf); + } - // lastBrowserDir - fputs("\n[" STRING_INI_BROWSER "]\n", fFile); - const char szBrowser[ARRAYSIZE(g_aszLastBrowse)][DEFAULT_BUFFER] = {STRING_INI_BRMEMPAK "=%s\n", STRING_INI_BRGBROM "=%s\n", STRING_INI_BRGBSAVE "=%s\n", - STRING_INI_BRPROFILE "=%s\n", STRING_INI_BRNOTE "=%s\n", STRING_INI_SHORTCUTS "=%s\n" }; - for (int i = 0; i < ARRAYSIZE(szBrowser); i++) - { - TCHAR_TO_CHAR( szANSIBuf, g_aszLastBrowse[i], DEFAULT_BUFFER ); - fprintf(fFile, szBrowser[i], szANSIBuf); - } + // lastBrowserDir + fputs("\n[" STRING_INI_BROWSER "]\n", fFile); + const char szBrowser[ARRAYSIZE(g_aszLastBrowse)][DEFAULT_BUFFER] = {STRING_INI_BRMEMPAK "=%s\n", STRING_INI_BRGBROM "=%s\n", STRING_INI_BRGBSAVE "=%s\n", + STRING_INI_BRPROFILE "=%s\n", STRING_INI_BRNOTE "=%s\n", STRING_INI_SHORTCUTS "=%s\n" }; + for (int i = 0; i < ARRAYSIZE(szBrowser); i++) + { + TCHAR_TO_CHAR( szANSIBuf, g_aszLastBrowse[i], DEFAULT_BUFFER ); + fprintf(fFile, szBrowser[i], szANSIBuf); + } - // Controller 1 through 4 - for (int i = 0; i < 4; i++) - { - fprintf(fFile, "\n[" STRING_INI_CONTROLLER " %d]\n", i + 1); - DumpControllerSettings(fFile, i, true); - } + // Controller 1 through 4 + for (int i = 0; i < 4; i++) + { + fprintf(fFile, "\n[" STRING_INI_CONTROLLER " %d]\n", i + 1); + DumpControllerSettings(fFile, i, true); + } - // Controls + // Controls - // I'm going to use STL strings here because I don't want to screw with buffer management - string strMouse; - string strDevs[MAX_DEVICES]; - string strNull; + // I'm going to use STL strings here because I don't want to screw with buffer management + string strMouse; + string strDevs[MAX_DEVICES]; + string strNull; - fputs("\n[" STRING_INI_CONTROLS "]\n", fFile); - fputs("# Button format: controlnum buttonID bOffset bAxisID bBtnType\n", fFile); + fputs("\n[" STRING_INI_CONTROLS "]\n", fFile); + fputs("# Button format: controlnum buttonID bOffset bAxisID bBtnType\n", fFile); - for ( int i = 0; i < 4; i++ ) // controllers for - { - FormatControlsBlock(&strMouse, strDevs, &strNull, i); - } // end controllers for + for ( int i = 0; i < 4; i++ ) // controllers for + { + FormatControlsBlock(&strMouse, strDevs, &strNull, i); + } // end controllers for - DumpStreams(fFile, strMouse, strDevs, strNull, true); + DumpStreams(fFile, strMouse, strDevs, strNull, true); - strMouse.clear(); - for (int i = 0; i < g_nDevices; i++) - strDevs[i].clear(); - strNull.clear(); + strMouse.clear(); + for (int i = 0; i < g_nDevices; i++) + strDevs[i].clear(); + strNull.clear(); - // Shortcuts + // Shortcuts - fputs("\n[" STRING_INI_SHORTCUTS "]\n", fFile); - fputs("# Shortcuts format: controlnum buttonID bOffset bAxisID bBtnType\n", fFile); + fputs("\n[" STRING_INI_SHORTCUTS "]\n", fFile); + fputs("# Shortcuts format: controlnum buttonID bOffset bAxisID bBtnType\n", fFile); - FormatShortcutsBlock(fFile, true); + FormatShortcutsBlock(fFile, true); - // Modifiers - fputs("\n[" STRING_INI_MODIFIERS "]\n", fFile); - fputs("# Modifiers format: controlnum bOffset bAxisID bBtnType bModType fToggle fStatus dwSpecific\n", fFile); + // Modifiers + fputs("\n[" STRING_INI_MODIFIERS "]\n", fFile); + fputs("# Modifiers format: controlnum bOffset bAxisID bBtnType bModType fToggle fStatus dwSpecific\n", fFile); - for ( int i = 0; i < 4; i++ ) // controllers for - { - FormatModifiersBlock(&strMouse, strDevs, &strNull, i); - } // end controllers for + for ( int i = 0; i < 4; i++ ) // controllers for + { + FormatModifiersBlock(&strMouse, strDevs, &strNull, i); + } // end controllers for - DumpStreams(fFile, strMouse, strDevs, strNull, true); + DumpStreams(fFile, strMouse, strDevs, strNull, true); - fclose(fFile); - DebugWriteA("Config stored to INI\n"); - return true; + fclose(fFile); + DebugWriteA("Config stored to INI\n"); + return true; } // This func loads the config data from INI into working emulator space. Does not copy into Interface; @@ -1393,301 +1393,301 @@ bool StoreConfigToINI() // Returns true if loaded OK, false if there was a problem. bool LoadConfigFromINI() { - FILE *fFile = NULL; - DWORD dwSection = 0; // this will eval to the bracketed "[Section]" we are currently in. - char szLine[4096]; + FILE *fFile = NULL; + DWORD dwSection = 0; // this will eval to the bracketed "[Section]" we are currently in. + char szLine[4096]; - TCHAR szFilename[MAX_PATH]; - GetDirectory(szFilename, DIRECTORY_CONFIG); - _tcscat(szFilename, _T("NRage.ini")); - fFile = _tfopen(szFilename, _T("rS")); // read, optimize for sequential + TCHAR szFilename[MAX_PATH]; + GetDirectory(szFilename, DIRECTORY_CONFIG); + _tcscat(szFilename, _T("NRage.ini")); + fFile = _tfopen(szFilename, _T("rS")); // read, optimize for sequential - if (!fFile) - { - DebugWriteA("Couldn't open INI file for input!\n"); - return false; - } - - for (int i = 0; i < 4; i++) - SetControllerDefaults( &(g_pcControllers[i]) ); + if (!fFile) + { + DebugWriteA("Couldn't open INI file for input!\n"); + return false; + } - ProcessKey( PL_RESET, 0, 0, 0, 0, false ); - DWORD dwCommand = PL_NOHIT; - while(( fgets(szLine, sizeof(szLine) - 1, fFile) ) ) - { - szLine[strlen(szLine) - 1] = '\0'; // remove newline - dwCommand = ParseLine( szLine ); - if (dwCommand == PL_NOHIT) - continue; - else if (dwCommand == PL_CATEGORY) - // section changed to szLine - dwSection = djbHash(szLine); - else - ProcessKey( dwCommand, dwSection, szLine, 0, 0, false ); - } + for (int i = 0; i < 4; i++) + SetControllerDefaults( &(g_pcControllers[i]) ); - fclose(fFile); + ProcessKey( PL_RESET, 0, 0, 0, 0, false ); + DWORD dwCommand = PL_NOHIT; + while(( fgets(szLine, sizeof(szLine) - 1, fFile) ) ) + { + szLine[strlen(szLine) - 1] = '\0'; // remove newline + dwCommand = ParseLine( szLine ); + if (dwCommand == PL_NOHIT) + continue; + else if (dwCommand == PL_CATEGORY) + // section changed to szLine + dwSection = djbHash(szLine); + else + ProcessKey( dwCommand, dwSection, szLine, 0, 0, false ); + } - return true; + fclose(fFile); + + return true; } // basically a stripped down version of GetConfigFromINI, called at the very beginning to get our language LANGID GetLanguageFromINI() { - FILE *fFile = NULL; - char szLine[4096]; + FILE *fFile = NULL; + char szLine[4096]; - TCHAR szFilename[MAX_PATH]; - GetDirectory(szFilename, DIRECTORY_CONFIG); - _tcscat(szFilename, _T("NRage.ini")); - fFile = _tfopen(szFilename, _T("rS")); // read, optimize for sequential + TCHAR szFilename[MAX_PATH]; + GetDirectory(szFilename, DIRECTORY_CONFIG); + _tcscat(szFilename, _T("NRage.ini")); + fFile = _tfopen(szFilename, _T("rS")); // read, optimize for sequential - if (!fFile) - { - DebugWriteA("Couldn't open INI file for input!\n"); - return 0; - } - - ProcessKey( PL_RESET, 0, 0, 0, 0, false ); - DWORD dwCommand = PL_NOHIT; - while(( fgets(szLine, sizeof(szLine) - 1, fFile) ) ) - { - szLine[strlen(szLine) - 1] = '\0'; // remove newline - dwCommand = ParseLine( szLine ); - if (dwCommand == CHK_LANGUAGE) - { - LANGID lTemp = 0; + if (!fFile) + { + DebugWriteA("Couldn't open INI file for input!\n"); + return 0; + } + + ProcessKey( PL_RESET, 0, 0, 0, 0, false ); + DWORD dwCommand = PL_NOHIT; + while(( fgets(szLine, sizeof(szLine) - 1, fFile) ) ) + { + szLine[strlen(szLine) - 1] = '\0'; // remove newline + dwCommand = ParseLine( szLine ); + if (dwCommand == CHK_LANGUAGE) + { + LANGID lTemp = 0; if (sscanf(szLine, "%hu", &lTemp)) - { - fclose(fFile); - return lTemp; - } - } - } + { + fclose(fFile); + return lTemp; + } + } + } - fclose(fFile); - DebugWriteA("Couldn't find a Language= line in INI file...\n"); - return 0; + fclose(fFile); + DebugWriteA("Couldn't find a Language= line in INI file...\n"); + return 0; } // both the following functions assume the buffer is big enough inline void GUIDtoStringA( char * szGUIDbuf, const GUID guid ) { - _snprintf( szGUIDbuf, GUID_STRINGLENGTH + 1, "{%08.8lX-%04.4hX-%04.4hX-%02.2X%02.2X-%02.2X%02.2X%02.2X%02.2X%02.2X%02.2X}", guid.Data1, guid.Data2, guid.Data3, guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]); + _snprintf( szGUIDbuf, GUID_STRINGLENGTH + 1, "{%08.8lX-%04.4hX-%04.4hX-%02.2X%02.2X-%02.2X%02.2X%02.2X%02.2X%02.2X%02.2X}", guid.Data1, guid.Data2, guid.Data3, guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]); } inline bool StringtoGUIDA( LPGUID guid, const char * szGUIDbuf ) { - short unsigned int lastbyte; - int blah = sscanf(szGUIDbuf, "{%08lX-%04hX-%04hX-%02hX%02hX-%02hX%02hX%02hX%02hX%02hX%02hX}", &guid->Data1, &guid->Data2, &guid->Data3, &guid->Data4[0], &guid->Data4[1], &guid->Data4[2], &guid->Data4[3], &guid->Data4[4], &guid->Data4[5], &guid->Data4[6], &lastbyte); - if (blah == 11) - { + short unsigned int lastbyte; + int blah = sscanf(szGUIDbuf, "{%08lX-%04hX-%04hX-%02hX%02hX-%02hX%02hX%02hX%02hX%02hX%02hX}", &guid->Data1, &guid->Data2, &guid->Data3, &guid->Data4[0], &guid->Data4[1], &guid->Data4[2], &guid->Data4[3], &guid->Data4[4], &guid->Data4[5], &guid->Data4[6], &lastbyte); + if (blah == 11) + { guid->Data4[7] = (BYTE)lastbyte; - return true; - } - else - return false; + return true; + } + else + return false; } // Takes in a file to dump to, and an int i telling which controller's settings to dump. Does not dump buttons or modifiers. void DumpControllerSettings(FILE * fFile, int i, bool bIsINI) { - char szANSIBuf[DEFAULT_BUFFER]; + char szANSIBuf[DEFAULT_BUFFER]; - fprintf(fFile, STRING_INI_PLUGGED "=%u\n", g_ivConfig->Controllers[i].fPlugged); - fprintf(fFile, STRING_INI_XINPUT "=%u\n", g_ivConfig->Controllers[i].fXInput); - fprintf(fFile, STRING_INI_N64MOUSE "=%u\n", g_ivConfig->Controllers[i].fN64Mouse); - fprintf(fFile, STRING_INI_BACKGROUNDINPUT "=%u\n", g_ivConfig->Controllers[i].bBackgroundInput); - fprintf(fFile, STRING_INI_RAWDATA "=%u\n", g_ivConfig->Controllers[i].fRawData); - fprintf(fFile, STRING_INI_PAKTYPE "=%u\n", g_ivConfig->Controllers[i].PakType); - fprintf(fFile, STRING_INI_REALN64RANGE "=%u\n", g_ivConfig->Controllers[i].fRealN64Range); - fprintf(fFile, STRING_INI_RAPIDFIREENABLED "=%u\n", g_ivConfig->Controllers[i].bRapidFireEnabled); - fprintf(fFile, STRING_INI_RAPIDFIRERATE "=%u\n", g_ivConfig->Controllers[i].bRapidFireRate); - fprintf(fFile, STRING_INI_STICKRANGE "=%u\n", g_ivConfig->Controllers[i].bStickRange); - fprintf(fFile, STRING_INI_MOUSEMOVEX "=%u\n", g_ivConfig->Controllers[i].bMouseMoveX); - fprintf(fFile, STRING_INI_MOUSEMOVEY "=%u\n", g_ivConfig->Controllers[i].bMouseMoveY); - fprintf(fFile, STRING_INI_AXISSET "=%u\n", g_ivConfig->Controllers[i].bAxisSet); - fprintf(fFile, STRING_INI_KEYABSOLUTEX "=%u\n", g_ivConfig->Controllers[i].fKeyAbsoluteX); - fprintf(fFile, STRING_INI_KEYABSOLUTEY "=%u\n", g_ivConfig->Controllers[i].fKeyAbsoluteY); - fprintf(fFile, STRING_INI_PADDEADZONE "=%u\n", g_ivConfig->Controllers[i].bPadDeadZone); - fprintf(fFile, STRING_INI_MOUSESENSX "=%u\n", g_ivConfig->Controllers[i].wMouseSensitivityX); - fprintf(fFile, STRING_INI_MOUSESENSY "=%u\n", g_ivConfig->Controllers[i].wMouseSensitivityY); - fprintf(fFile, STRING_INI_RUMBLETYPE "=%u\n", g_ivConfig->Controllers[i].bRumbleTyp); - fprintf(fFile, STRING_INI_RUMBLESTRENGTH "=%u\n", g_ivConfig->Controllers[i].bRumbleStrength); - fprintf(fFile, STRING_INI_VISUALRUMBLE "=%u\n", g_ivConfig->Controllers[i].fVisualRumble); + fprintf(fFile, STRING_INI_PLUGGED "=%u\n", g_ivConfig->Controllers[i].fPlugged); + fprintf(fFile, STRING_INI_XINPUT "=%u\n", g_ivConfig->Controllers[i].fXInput); + fprintf(fFile, STRING_INI_N64MOUSE "=%u\n", g_ivConfig->Controllers[i].fN64Mouse); + fprintf(fFile, STRING_INI_BACKGROUNDINPUT "=%u\n", g_ivConfig->Controllers[i].bBackgroundInput); + fprintf(fFile, STRING_INI_RAWDATA "=%u\n", g_ivConfig->Controllers[i].fRawData); + fprintf(fFile, STRING_INI_PAKTYPE "=%u\n", g_ivConfig->Controllers[i].PakType); + fprintf(fFile, STRING_INI_REALN64RANGE "=%u\n", g_ivConfig->Controllers[i].fRealN64Range); + fprintf(fFile, STRING_INI_RAPIDFIREENABLED "=%u\n", g_ivConfig->Controllers[i].bRapidFireEnabled); + fprintf(fFile, STRING_INI_RAPIDFIRERATE "=%u\n", g_ivConfig->Controllers[i].bRapidFireRate); + fprintf(fFile, STRING_INI_STICKRANGE "=%u\n", g_ivConfig->Controllers[i].bStickRange); + fprintf(fFile, STRING_INI_MOUSEMOVEX "=%u\n", g_ivConfig->Controllers[i].bMouseMoveX); + fprintf(fFile, STRING_INI_MOUSEMOVEY "=%u\n", g_ivConfig->Controllers[i].bMouseMoveY); + fprintf(fFile, STRING_INI_AXISSET "=%u\n", g_ivConfig->Controllers[i].bAxisSet); + fprintf(fFile, STRING_INI_KEYABSOLUTEX "=%u\n", g_ivConfig->Controllers[i].fKeyAbsoluteX); + fprintf(fFile, STRING_INI_KEYABSOLUTEY "=%u\n", g_ivConfig->Controllers[i].fKeyAbsoluteY); + fprintf(fFile, STRING_INI_PADDEADZONE "=%u\n", g_ivConfig->Controllers[i].bPadDeadZone); + fprintf(fFile, STRING_INI_MOUSESENSX "=%u\n", g_ivConfig->Controllers[i].wMouseSensitivityX); + fprintf(fFile, STRING_INI_MOUSESENSY "=%u\n", g_ivConfig->Controllers[i].wMouseSensitivityY); + fprintf(fFile, STRING_INI_RUMBLETYPE "=%u\n", g_ivConfig->Controllers[i].bRumbleTyp); + fprintf(fFile, STRING_INI_RUMBLESTRENGTH "=%u\n", g_ivConfig->Controllers[i].bRumbleStrength); + fprintf(fFile, STRING_INI_VISUALRUMBLE "=%u\n", g_ivConfig->Controllers[i].fVisualRumble); - if (bIsINI) - { - char szGUID[DEFAULT_BUFFER]; - int iDevice = FindDeviceinList( g_ivConfig->FFDevices[i].szProductName, g_ivConfig->FFDevices[i].bProductCounter, true ); - if (iDevice == -1) - { - fprintf(fFile, STRING_INI_FFDEVICEGUID "=\n"); - } - else - { - g_ivConfig->Controllers[i].guidFFDevice = g_devList[iDevice].guidInstance; - GUIDtoStringA(szGUID, g_ivConfig->Controllers[i].guidFFDevice); - fprintf(fFile, STRING_INI_FFDEVICEGUID "=%s\n", szGUID); - } - } - else - { - TCHAR_TO_CHAR(szANSIBuf, g_ivConfig->FFDevices[i].szProductName, DEFAULT_BUFFER); - fprintf(fFile, STRING_INI_FFDEVICENAME "=%s\n", szANSIBuf); - fprintf(fFile, STRING_INI_FFDEVICENR "=%u\n", g_ivConfig->FFDevices[i].bProductCounter); - } + if (bIsINI) + { + char szGUID[DEFAULT_BUFFER]; + int iDevice = FindDeviceinList( g_ivConfig->FFDevices[i].szProductName, g_ivConfig->FFDevices[i].bProductCounter, true ); + if (iDevice == -1) + { + fprintf(fFile, STRING_INI_FFDEVICEGUID "=\n"); + } + else + { + g_ivConfig->Controllers[i].guidFFDevice = g_devList[iDevice].guidInstance; + GUIDtoStringA(szGUID, g_ivConfig->Controllers[i].guidFFDevice); + fprintf(fFile, STRING_INI_FFDEVICEGUID "=%s\n", szGUID); + } + } + else + { + TCHAR_TO_CHAR(szANSIBuf, g_ivConfig->FFDevices[i].szProductName, DEFAULT_BUFFER); + fprintf(fFile, STRING_INI_FFDEVICENAME "=%s\n", szANSIBuf); + fprintf(fFile, STRING_INI_FFDEVICENR "=%u\n", g_ivConfig->FFDevices[i].bProductCounter); + } - TCHAR_TO_CHAR( szANSIBuf, g_ivConfig->Controllers[i].szMempakFile, DEFAULT_BUFFER ); - fprintf(fFile, STRING_INI_MEMPAKFILE "=%s\n", szANSIBuf); + TCHAR_TO_CHAR( szANSIBuf, g_ivConfig->Controllers[i].szMempakFile, DEFAULT_BUFFER ); + fprintf(fFile, STRING_INI_MEMPAKFILE "=%s\n", szANSIBuf); - TCHAR_TO_CHAR( szANSIBuf, g_ivConfig->Controllers[i].szTransferRom, DEFAULT_BUFFER ); - fprintf(fFile, STRING_INI_GBROMFILE "=%s\n", szANSIBuf); + TCHAR_TO_CHAR( szANSIBuf, g_ivConfig->Controllers[i].szTransferRom, DEFAULT_BUFFER ); + fprintf(fFile, STRING_INI_GBROMFILE "=%s\n", szANSIBuf); - TCHAR_TO_CHAR( szANSIBuf, g_ivConfig->Controllers[i].szTransferSave, DEFAULT_BUFFER ); - fprintf(fFile, STRING_INI_GBROMSAVE "=%s\n", szANSIBuf); + TCHAR_TO_CHAR( szANSIBuf, g_ivConfig->Controllers[i].szTransferSave, DEFAULT_BUFFER ); + fprintf(fFile, STRING_INI_GBROMSAVE "=%s\n", szANSIBuf); } // private func, called by StoreConfigToINI to dump cached Button strings to file void DumpStreams(FILE * fFile, string strMouse, string strDevs[], string strNull, bool bIsINI) { - // dump all streams to file, with appropriate DInput lines and name comment - char szANSIBuf[DEFAULT_BUFFER]; - if (!(strMouse.empty())) - { - TCHAR_TO_CHAR( szANSIBuf, g_sysMouse.szProductName, DEFAULT_BUFFER ); - if (bIsINI) - { - fprintf(fFile, "# %s\n", szANSIBuf); - char szGUID[DEFAULT_BUFFER]; - GUIDtoStringA(szGUID, g_sysMouse.guidInstance); - fprintf(fFile, STRING_INI_DINPUTGUID "=%s\n", szGUID); - } - else - { - fprintf(fFile, STRING_INI_DINPUTNAME "=%s\n", szANSIBuf); - fprintf(fFile, STRING_INI_DINPUTNR "=%d\n", 0); - } - fputs(strMouse.c_str(), fFile); - } - if (!(strNull.empty())) - { - fputs("# NOT ASSIGNED\n", fFile); - if (bIsINI) - { - char szGUID[DEFAULT_BUFFER]; - GUIDtoStringA(szGUID, GUID_NULL); - fprintf(fFile, STRING_INI_DINPUTGUID "=%s\n", szGUID); - } - else - { - fprintf(fFile, STRING_INI_DINPUTNAME "=\n"); // leave blank - fprintf(fFile, STRING_INI_DINPUTNR "=\n"); - } - fputs(strNull.c_str(), fFile); - } - for (int i = 0; i < g_nDevices; i++) - { - if (!(strDevs[i].empty())) - { - TCHAR_TO_CHAR( szANSIBuf, g_devList[i].szProductName, DEFAULT_BUFFER ); - if (bIsINI) - { - if (g_devList[i].bProductCounter > 0) - fprintf(fFile, "# %s %d\n", szANSIBuf, g_devList[i].bProductCounter); - else - fprintf(fFile, "# %s\n", szANSIBuf); - char szGUID[DEFAULT_BUFFER]; - GUIDtoStringA(szGUID, g_devList[i].guidInstance); - fprintf(fFile, STRING_INI_DINPUTGUID "=%s\n", szGUID); - } - else - { - fprintf(fFile, STRING_INI_DINPUTNAME "=%s\n", szANSIBuf); - fprintf(fFile, STRING_INI_DINPUTNR "=%d\n", g_devList[i].bProductCounter); - } - fputs(strDevs[i].c_str(), fFile); - } - } + // dump all streams to file, with appropriate DInput lines and name comment + char szANSIBuf[DEFAULT_BUFFER]; + if (!(strMouse.empty())) + { + TCHAR_TO_CHAR( szANSIBuf, g_sysMouse.szProductName, DEFAULT_BUFFER ); + if (bIsINI) + { + fprintf(fFile, "# %s\n", szANSIBuf); + char szGUID[DEFAULT_BUFFER]; + GUIDtoStringA(szGUID, g_sysMouse.guidInstance); + fprintf(fFile, STRING_INI_DINPUTGUID "=%s\n", szGUID); + } + else + { + fprintf(fFile, STRING_INI_DINPUTNAME "=%s\n", szANSIBuf); + fprintf(fFile, STRING_INI_DINPUTNR "=%d\n", 0); + } + fputs(strMouse.c_str(), fFile); + } + if (!(strNull.empty())) + { + fputs("# NOT ASSIGNED\n", fFile); + if (bIsINI) + { + char szGUID[DEFAULT_BUFFER]; + GUIDtoStringA(szGUID, GUID_NULL); + fprintf(fFile, STRING_INI_DINPUTGUID "=%s\n", szGUID); + } + else + { + fprintf(fFile, STRING_INI_DINPUTNAME "=\n"); // leave blank + fprintf(fFile, STRING_INI_DINPUTNR "=\n"); + } + fputs(strNull.c_str(), fFile); + } + for (int i = 0; i < g_nDevices; i++) + { + if (!(strDevs[i].empty())) + { + TCHAR_TO_CHAR( szANSIBuf, g_devList[i].szProductName, DEFAULT_BUFFER ); + if (bIsINI) + { + if (g_devList[i].bProductCounter > 0) + fprintf(fFile, "# %s %d\n", szANSIBuf, g_devList[i].bProductCounter); + else + fprintf(fFile, "# %s\n", szANSIBuf); + char szGUID[DEFAULT_BUFFER]; + GUIDtoStringA(szGUID, g_devList[i].guidInstance); + fprintf(fFile, STRING_INI_DINPUTGUID "=%s\n", szGUID); + } + else + { + fprintf(fFile, STRING_INI_DINPUTNAME "=%s\n", szANSIBuf); + fprintf(fFile, STRING_INI_DINPUTNR "=%d\n", g_devList[i].bProductCounter); + } + fputs(strDevs[i].c_str(), fFile); + } + } } void FormatControlsBlock(string * strMouse, string strDevs[], string * strNull, int i) { - for ( int j = 0; j < ARRAYSIZE(g_ivConfig->Controllers[i].aButton); j++ ) // buttons for - { - if (g_ivConfig->Controllers[i].aButton[j].parentDevice) // possibly unbound - { - if ( IsEqualGUID(g_sysMouse.guidInstance, g_ivConfig->Controllers[i].aButton[j].parentDevice->guidInstance) ) - { - char szBuf[DEFAULT_BUFFER]; - // add to the mouse stream - sprintf(szBuf, STRING_INI_BUTTON "=%d %d %02X %d %d\n", i, j, g_ivConfig->Controllers[i].aButton[j].bOffset, g_ivConfig->Controllers[i].aButton[j].bAxisID, g_ivConfig->Controllers[i].aButton[j].bBtnType); - strMouse->append(szBuf); - } - else - { - for (int match = 0; match < g_nDevices; match++) - { - if ( IsEqualGUID(g_devList[match].guidInstance, g_ivConfig->Controllers[i].aButton[j].parentDevice->guidInstance) ) - { - char szBuf[DEFAULT_BUFFER]; - // add to the appropriate device stream - sprintf(szBuf, STRING_INI_BUTTON "=%d %d %02X %d %d\n", i, j, g_ivConfig->Controllers[i].aButton[j].bOffset, g_ivConfig->Controllers[i].aButton[j].bAxisID, g_ivConfig->Controllers[i].aButton[j].bBtnType); - strDevs[match].append(szBuf); - break; - } - } - } - } - else if (g_ivConfig->Controllers[i].aButton[j].bBtnType != DT_UNASSIGNED) - { - int k = g_ivConfig->Controllers[i].aButton[j].bBtnType; - DebugWriteA("Controller %d button %d is of bBtnType %d but has no parentDevice!\n", i, j, k); - } - } // end buttons for + for ( int j = 0; j < ARRAYSIZE(g_ivConfig->Controllers[i].aButton); j++ ) // buttons for + { + if (g_ivConfig->Controllers[i].aButton[j].parentDevice) // possibly unbound + { + if ( IsEqualGUID(g_sysMouse.guidInstance, g_ivConfig->Controllers[i].aButton[j].parentDevice->guidInstance) ) + { + char szBuf[DEFAULT_BUFFER]; + // add to the mouse stream + sprintf(szBuf, STRING_INI_BUTTON "=%d %d %02X %d %d\n", i, j, g_ivConfig->Controllers[i].aButton[j].bOffset, g_ivConfig->Controllers[i].aButton[j].bAxisID, g_ivConfig->Controllers[i].aButton[j].bBtnType); + strMouse->append(szBuf); + } + else + { + for (int match = 0; match < g_nDevices; match++) + { + if ( IsEqualGUID(g_devList[match].guidInstance, g_ivConfig->Controllers[i].aButton[j].parentDevice->guidInstance) ) + { + char szBuf[DEFAULT_BUFFER]; + // add to the appropriate device stream + sprintf(szBuf, STRING_INI_BUTTON "=%d %d %02X %d %d\n", i, j, g_ivConfig->Controllers[i].aButton[j].bOffset, g_ivConfig->Controllers[i].aButton[j].bAxisID, g_ivConfig->Controllers[i].aButton[j].bBtnType); + strDevs[match].append(szBuf); + break; + } + } + } + } + else if (g_ivConfig->Controllers[i].aButton[j].bBtnType != DT_UNASSIGNED) + { + int k = g_ivConfig->Controllers[i].aButton[j].bBtnType; + DebugWriteA("Controller %d button %d is of bBtnType %d but has no parentDevice!\n", i, j, k); + } + } // end buttons for } void FormatModifiersBlock(string * strMouse, string strDevs[], string * strNull, int i) { - for ( int j = 0; j < g_ivConfig->Controllers[i].nModifiers; j++ ) - { - if (g_ivConfig->Controllers[i].pModifiers[j].btnButton.parentDevice) // is it assigned to a key? - { - if ( IsEqualGUID(g_sysMouse.guidInstance, g_ivConfig->Controllers[i].pModifiers[j].btnButton.parentDevice->guidInstance) ) - { - char szBuf[DEFAULT_BUFFER]; - // add to the mouse stream - sprintf(szBuf, STRING_INI_MODIFIER "=%d %02X %d %d %d %d %d %08X\n", i, g_ivConfig->Controllers[i].pModifiers[j].btnButton.bOffset, - g_ivConfig->Controllers[i].pModifiers[j].btnButton.bAxisID, g_ivConfig->Controllers[i].pModifiers[j].btnButton.bBtnType, - g_ivConfig->Controllers[i].pModifiers[j].bModType, g_ivConfig->Controllers[i].pModifiers[j].fToggle, - g_ivConfig->Controllers[i].pModifiers[j].fStatus, g_ivConfig->Controllers[i].pModifiers[j].dwSpecific); - strMouse->append(szBuf); - } - else - for (int match = 0; match < g_nDevices; match++) - if ( IsEqualGUID(g_devList[match].guidInstance, g_ivConfig->Controllers[i].pModifiers[j].btnButton.parentDevice->guidInstance) ) - { - char szBuf[DEFAULT_BUFFER]; - // add to the mouse stream - sprintf(szBuf, STRING_INI_MODIFIER "=%d %02X %d %d %d %d %d %08X\n", i, g_ivConfig->Controllers[i].pModifiers[j].btnButton.bOffset, - g_ivConfig->Controllers[i].pModifiers[j].btnButton.bAxisID, g_ivConfig->Controllers[i].pModifiers[j].btnButton.bBtnType, - g_ivConfig->Controllers[i].pModifiers[j].bModType, g_ivConfig->Controllers[i].pModifiers[j].fToggle, - g_ivConfig->Controllers[i].pModifiers[j].fStatus, g_ivConfig->Controllers[i].pModifiers[j].dwSpecific); - strDevs[match].append(szBuf); - break; - } - } - else // save modifiers without a keybind - { - char szBuf[DEFAULT_BUFFER]; - // add to the mouse stream - sprintf(szBuf, STRING_INI_MODIFIER "=%d %02X %d %d %d %d %d %08X\n", i, g_ivConfig->Controllers[i].pModifiers[j].btnButton.bOffset, - g_ivConfig->Controllers[i].pModifiers[j].btnButton.bAxisID, g_ivConfig->Controllers[i].pModifiers[j].btnButton.bBtnType, - g_ivConfig->Controllers[i].pModifiers[j].bModType, g_ivConfig->Controllers[i].pModifiers[j].fToggle, - g_ivConfig->Controllers[i].pModifiers[j].fStatus, g_ivConfig->Controllers[i].pModifiers[j].dwSpecific); - strNull->append(szBuf); - } - } + for ( int j = 0; j < g_ivConfig->Controllers[i].nModifiers; j++ ) + { + if (g_ivConfig->Controllers[i].pModifiers[j].btnButton.parentDevice) // is it assigned to a key? + { + if ( IsEqualGUID(g_sysMouse.guidInstance, g_ivConfig->Controllers[i].pModifiers[j].btnButton.parentDevice->guidInstance) ) + { + char szBuf[DEFAULT_BUFFER]; + // add to the mouse stream + sprintf(szBuf, STRING_INI_MODIFIER "=%d %02X %d %d %d %d %d %08X\n", i, g_ivConfig->Controllers[i].pModifiers[j].btnButton.bOffset, + g_ivConfig->Controllers[i].pModifiers[j].btnButton.bAxisID, g_ivConfig->Controllers[i].pModifiers[j].btnButton.bBtnType, + g_ivConfig->Controllers[i].pModifiers[j].bModType, g_ivConfig->Controllers[i].pModifiers[j].fToggle, + g_ivConfig->Controllers[i].pModifiers[j].fStatus, g_ivConfig->Controllers[i].pModifiers[j].dwSpecific); + strMouse->append(szBuf); + } + else + for (int match = 0; match < g_nDevices; match++) + if ( IsEqualGUID(g_devList[match].guidInstance, g_ivConfig->Controllers[i].pModifiers[j].btnButton.parentDevice->guidInstance) ) + { + char szBuf[DEFAULT_BUFFER]; + // add to the mouse stream + sprintf(szBuf, STRING_INI_MODIFIER "=%d %02X %d %d %d %d %d %08X\n", i, g_ivConfig->Controllers[i].pModifiers[j].btnButton.bOffset, + g_ivConfig->Controllers[i].pModifiers[j].btnButton.bAxisID, g_ivConfig->Controllers[i].pModifiers[j].btnButton.bBtnType, + g_ivConfig->Controllers[i].pModifiers[j].bModType, g_ivConfig->Controllers[i].pModifiers[j].fToggle, + g_ivConfig->Controllers[i].pModifiers[j].fStatus, g_ivConfig->Controllers[i].pModifiers[j].dwSpecific); + strDevs[match].append(szBuf); + break; + } + } + else // save modifiers without a keybind + { + char szBuf[DEFAULT_BUFFER]; + // add to the mouse stream + sprintf(szBuf, STRING_INI_MODIFIER "=%d %02X %d %d %d %d %d %08X\n", i, g_ivConfig->Controllers[i].pModifiers[j].btnButton.bOffset, + g_ivConfig->Controllers[i].pModifiers[j].btnButton.bAxisID, g_ivConfig->Controllers[i].pModifiers[j].btnButton.bBtnType, + g_ivConfig->Controllers[i].pModifiers[j].bModType, g_ivConfig->Controllers[i].pModifiers[j].fToggle, + g_ivConfig->Controllers[i].pModifiers[j].fStatus, g_ivConfig->Controllers[i].pModifiers[j].dwSpecific); + strNull->append(szBuf); + } + } } unsigned long djbHash(const char *str) diff --git a/Source/nragev20/FileAccess.h b/Source/nragev20/FileAccess.h index 4ab8d2565..6554454ca 100644 --- a/Source/nragev20/FileAccess.h +++ b/Source/nragev20/FileAccess.h @@ -1,9 +1,9 @@ /* - N-Rage`s Dinput8 Plugin + N-Rage`s Dinput8 Plugin (C) 2002, 2006 Norbert Wladyka - Author`s Email: norbert.wladyka@chello.at - Website: http://go.to/nrage + Author`s Email: norbert.wladyka@chello.at + Website: http://go.to/nrage This program is free software; you can redistribute it and/or modify @@ -55,75 +55,75 @@ inline bool StringtoGUIDA( LPGUID guid, const char * szGUIDbuf ); unsigned long djbHash(const char *str); #ifdef _UNICODE -#define TCHAR_TO_CHAR(x,y,z) wcstombs(x,y,z) -#define CHAR_TO_TCHAR(x,y,z) mbstowcs(x,y,z) +#define TCHAR_TO_CHAR(x,y,z) wcstombs(x,y,z) +#define CHAR_TO_TCHAR(x,y,z) mbstowcs(x,y,z) #else -#define TCHAR_TO_CHAR(x,y,z) strncpy(x,y,z) -#define CHAR_TO_TCHAR(x,y,z) strncpy(x,y,z) +#define TCHAR_TO_CHAR(x,y,z) strncpy(x,y,z) +#define CHAR_TO_TCHAR(x,y,z) strncpy(x,y,z) #endif -#define STRING_DEF_MEMPAKFILE _T("MemPaks") -#define STRING_DEF_GBROMFILE _T("GBxRoms") -#define STRING_DEF_GBROMSAVE _T("GBxSaves") +#define STRING_DEF_MEMPAKFILE _T("MemPaks") +#define STRING_DEF_GBROMFILE _T("GBxRoms") +#define STRING_DEF_GBROMSAVE _T("GBxSaves") -#define STRING_INI_HEADER "# Generated by NRage input plugin V2 version " VER_FILE_VERSION_STR "\n" +#define STRING_INI_HEADER "# Generated by NRage input plugin V2 version " VER_FILE_VERSION_STR "\n" // We use these names for loading from INI files and NRage config files -#define STRING_INI_GENERAL "General" -#define STRING_INI_CONTROLLER "Controller" -#define STRING_INI_FOLDERS "Folders" -#define STRING_INI_BROWSER "lastBrowserDir" -#define STRING_INI_CONTROLS "Controls" -#define STRING_INI_SHORTCUTS "Shortcuts" -#define STRING_INI_MODIFIERS "Modifiers" +#define STRING_INI_GENERAL "General" +#define STRING_INI_CONTROLLER "Controller" +#define STRING_INI_FOLDERS "Folders" +#define STRING_INI_BROWSER "lastBrowserDir" +#define STRING_INI_CONTROLS "Controls" +#define STRING_INI_SHORTCUTS "Shortcuts" +#define STRING_INI_MODIFIERS "Modifiers" -#define STRING_INI_LANGUAGE "Language" -#define STRING_INI_SHOWMESSAGES "ShowMessages" +#define STRING_INI_LANGUAGE "Language" +#define STRING_INI_SHOWMESSAGES "ShowMessages" -#define STRING_INI_BRPROFILE "Profile" -#define STRING_INI_BRNOTE "Note" -#define STRING_INI_BRMEMPAK "Mempak" -#define STRING_INI_BRGBROM "GBxRom" -#define STRING_INI_BRGBSAVE "GBxSave" -// #define STRING_INI_BRSHORTCUTS STRING_INI_SHORTCUTS +#define STRING_INI_BRPROFILE "Profile" +#define STRING_INI_BRNOTE "Note" +#define STRING_INI_BRMEMPAK "Mempak" +#define STRING_INI_BRGBROM "GBxRom" +#define STRING_INI_BRGBSAVE "GBxSave" +// #define STRING_INI_BRSHORTCUTS STRING_INI_SHORTCUTS -#define STRING_INI_PLUGGED "Plugged" -#define STRING_INI_XINPUT "xInput" -#define STRING_INI_N64MOUSE "N64Mouse" -#define STRING_INI_BACKGROUNDINPUT "BackgroundInput" -#define STRING_INI_RAWDATA "RawData" -#define STRING_INI_PAKTYPE "PakType" -#define STRING_INI_REALN64RANGE "RealN64Range" -#define STRING_INI_RAPIDFIREENABLED "RapidFireEnabled" -#define STRING_INI_RAPIDFIRERATE "RapidFireRate" -#define STRING_INI_STICKRANGE "StickRange" -#define STRING_INI_MOUSEMOVEX "MouseMoveX" -#define STRING_INI_MOUSEMOVEY "MouseMoveY" -#define STRING_INI_AXISSET "AxisSet" -#define STRING_INI_KEYABSOLUTEX "KeyAbsoluteX" -#define STRING_INI_KEYABSOLUTEY "KeyAbsoluteY" -#define STRING_INI_PADDEADZONE "PadDeadZone" -#define STRING_INI_MOUSESENSX "MouseSensitivityX" -#define STRING_INI_MOUSESENSY "MouseSensitivityY" -#define STRING_INI_RUMBLETYPE "RumbleType" -#define STRING_INI_RUMBLESTRENGTH "RumbleStrength" -#define STRING_INI_VISUALRUMBLE "VisualRumble" -#define STRING_INI_FFDEVICEGUID "FFDeviceGUID" -#define STRING_INI_MEMPAKFILE "MemPakFile" -#define STRING_INI_GBROMFILE "GBRomFile" -#define STRING_INI_GBROMSAVE "GBRomSave" +#define STRING_INI_PLUGGED "Plugged" +#define STRING_INI_XINPUT "xInput" +#define STRING_INI_N64MOUSE "N64Mouse" +#define STRING_INI_BACKGROUNDINPUT "BackgroundInput" +#define STRING_INI_RAWDATA "RawData" +#define STRING_INI_PAKTYPE "PakType" +#define STRING_INI_REALN64RANGE "RealN64Range" +#define STRING_INI_RAPIDFIREENABLED "RapidFireEnabled" +#define STRING_INI_RAPIDFIRERATE "RapidFireRate" +#define STRING_INI_STICKRANGE "StickRange" +#define STRING_INI_MOUSEMOVEX "MouseMoveX" +#define STRING_INI_MOUSEMOVEY "MouseMoveY" +#define STRING_INI_AXISSET "AxisSet" +#define STRING_INI_KEYABSOLUTEX "KeyAbsoluteX" +#define STRING_INI_KEYABSOLUTEY "KeyAbsoluteY" +#define STRING_INI_PADDEADZONE "PadDeadZone" +#define STRING_INI_MOUSESENSX "MouseSensitivityX" +#define STRING_INI_MOUSESENSY "MouseSensitivityY" +#define STRING_INI_RUMBLETYPE "RumbleType" +#define STRING_INI_RUMBLESTRENGTH "RumbleStrength" +#define STRING_INI_VISUALRUMBLE "VisualRumble" +#define STRING_INI_FFDEVICEGUID "FFDeviceGUID" +#define STRING_INI_MEMPAKFILE "MemPakFile" +#define STRING_INI_GBROMFILE "GBRomFile" +#define STRING_INI_GBROMSAVE "GBRomSave" -#define STRING_INI_DINPUTGUID "DInputGUID" -#define STRING_INI_BUTTON "Button" -#define STRING_INI_MODIFIER "Modifier" +#define STRING_INI_DINPUTGUID "DInputGUID" +#define STRING_INI_BUTTON "Button" +#define STRING_INI_MODIFIER "Modifier" // The following are not found in INI files; only profile and shortcuts files #define STRING_PROFILEVERSION22 "Controller Profile 2.2" -#define STRING_PROFILEVERSION STRING_PROFILEVERSION22 +#define STRING_PROFILEVERSION STRING_PROFILEVERSION22 -#define STRING_INI_FFDEVICENAME "FFDeviceName" -#define STRING_INI_FFDEVICENR "FFDeviceNr" -#define STRING_INI_DINPUTNAME "DInputName" -#define STRING_INI_DINPUTNR "DInputNr" +#define STRING_INI_FFDEVICENAME "FFDeviceName" +#define STRING_INI_FFDEVICENR "FFDeviceNr" +#define STRING_INI_DINPUTNAME "DInputName" +#define STRING_INI_DINPUTNR "DInputNr" // the following are hashes for the string values above @@ -197,40 +197,40 @@ unsigned long djbHash(const char *str); // If any of the following values conflict with djbHash return values (such as a blank string), there will be problems! // nothing -#define PL_NOHIT 0 - // [Category] -#define PL_CATEGORY 1 - // @STRING_PROFILEVERSION -#define PL_VERSIONSTRING 10 +#define PL_NOHIT 0 + // [Category] +#define PL_CATEGORY 1 + // @STRING_PROFILEVERSION +#define PL_VERSIONSTRING 10 - // resets the static vars in ProcessKey -#define PL_RESET 200 + // resets the static vars in ProcessKey +#define PL_RESET 200 -#define DIRECTORY_MEMPAK 0 -#define DIRECTORY_GBROMS 1 -#define DIRECTORY_GBSAVES 2 -#define DIRECTORY_CONFIG 252 -#define DIRECTORY_LOG 253 -#define DIRECTORY_DLL 254 -#define DIRECTORY_APPLICATION 255 -#define DIRECTORY_INVALID 256 +#define DIRECTORY_MEMPAK 0 +#define DIRECTORY_GBROMS 1 +#define DIRECTORY_GBSAVES 2 +#define DIRECTORY_CONFIG 252 +#define DIRECTORY_LOG 253 +#define DIRECTORY_DLL 254 +#define DIRECTORY_APPLICATION 255 +#define DIRECTORY_INVALID 256 -#define FILIST_MEM 1 -#define FILIST_TRANSFER 2 +#define FILIST_MEM 1 +#define FILIST_TRANSFER 2 -#define BF_LOAD false -#define BF_SAVE true +#define BF_LOAD false +#define BF_SAVE true -#define BF_MEMPAK 0 -#define BF_GBROM 1 -#define BF_GBSAVE 2 -#define BF_PROFILE 3 -#define BF_NOTE 4 -#define BF_SHORTCUTS 5 +#define BF_MEMPAK 0 +#define BF_GBROM 1 +#define BF_GBSAVE 2 +#define BF_PROFILE 3 +#define BF_NOTE 4 +#define BF_SHORTCUTS 5 - // 32 hex characters, 4 hyphens, 2 end braces -#define GUID_STRINGLENGTH 32+4+2 + // 32 hex characters, 4 hyphens, 2 end braces +#define GUID_STRINGLENGTH 32+4+2 #endif // #ifndef _FILEACCESS_H_ diff --git a/Source/nragev20/GBCart.cpp b/Source/nragev20/GBCart.cpp index ec0d11073..6a6493950 100644 --- a/Source/nragev20/GBCart.cpp +++ b/Source/nragev20/GBCart.cpp @@ -33,1232 +33,1232 @@ bool ReadCartCamera(LPGBCART Cart, WORD dwAddress, BYTE *Data); bool WriteCartCamera(LPGBCART Cart, WORD dwAddress, BYTE *Data); // Tries to read RTC data from separate file (not integrated into SAV) -// success sets the useTDF flag -// failure inits the RTC at zero and maybe throws a warning +// success sets the useTDF flag +// failure inits the RTC at zero and maybe throws a warning void ReadTDF(LPGBCART Cart) { } void WriteTDF(LPGBCART Cart) { - // check useTDF flag - // write data from RTC to TDF file + // check useTDF flag + // write data from RTC to TDF file } void UpdateRTC(LPGBCART Cart) { - time_t now, dif; - int days; + time_t now, dif; + int days; - now = time(NULL); - dif = now - Cart->timerLastUpdate; + now = time(NULL); + dif = now - Cart->timerLastUpdate; - Cart->TimerData[0] += (BYTE)(dif % 60); - dif /= 60; - Cart->TimerData[1] += (BYTE)(dif % 60); - dif /= 60; - Cart->TimerData[2] += (BYTE)(dif % 24); - dif /= 24; + Cart->TimerData[0] += (BYTE)(dif % 60); + dif /= 60; + Cart->TimerData[1] += (BYTE)(dif % 60); + dif /= 60; + Cart->TimerData[2] += (BYTE)(dif % 24); + dif /= 24; - days = (int)(Cart->TimerData[3] + ((Cart->TimerData[4] & 1) << 8) + dif); - Cart->TimerData[3] = (days & 0xFF); + days = (int)(Cart->TimerData[3] + ((Cart->TimerData[4] & 1) << 8) + dif); + Cart->TimerData[3] = (days & 0xFF); - if (days > 255) - { - if (days > 511) - { - days &= 511; - Cart->TimerData[4] |= 0x80; - } - if (days > 255) - { - Cart->TimerData[4] = (Cart->TimerData[4] & 0xFE) | (days > 255 ? 1 : 0); - } - } + if (days > 255) + { + if (days > 511) + { + days &= 511; + Cart->TimerData[4] |= 0x80; + } + if (days > 255) + { + Cart->TimerData[4] = (Cart->TimerData[4] & 0xFE) | (days > 255 ? 1 : 0); + } + } - Cart->timerLastUpdate = now; + Cart->timerLastUpdate = now; } // returns true if the ROM was loaded OK bool LoadCart(LPGBCART Cart, LPCTSTR RomFileName, LPCTSTR RamFileName, LPCTSTR TdfFileName) { - HANDLE hTemp; - DWORD dwFilesize; - DWORD NumQuarterBlocks = 0; + HANDLE hTemp; + DWORD dwFilesize; + DWORD NumQuarterBlocks = 0; - UnloadCart(Cart); // first, make sure any previous carts have been unloaded + UnloadCart(Cart); // first, make sure any previous carts have been unloaded - Cart->iCurrentRamBankNo = 0; - Cart->iCurrentRomBankNo = 1; - Cart->bRamEnableState = 0; - Cart->bMBC1RAMbanking = 0; + Cart->iCurrentRamBankNo = 0; + Cart->iCurrentRomBankNo = 1; + Cart->bRamEnableState = 0; + Cart->bMBC1RAMbanking = 0; - // Attempt to load the ROM file. - hTemp = CreateFile(RomFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); - if (hTemp != INVALID_HANDLE_VALUE && (Cart->hRomFile = CreateFileMapping(hTemp, NULL, PAGE_READONLY, 0, 0, NULL) ) ) - { - // if the first case fails, the file doesn't exist. The second case can fail if the file size is zero. - dwFilesize = GetFileSize(hTemp, NULL); - CloseHandle(hTemp); - Cart->RomData = (const unsigned char *)MapViewOfFile( Cart->hRomFile, FILE_MAP_READ, 0, 0, 0 ); - } - else - { - DebugWriteA("Couldn't load the ROM file, GetLastError returned %08x\n", GetLastError()); - if (hTemp != INVALID_HANDLE_VALUE) - CloseHandle(hTemp); // if file size was zero, make sure we don't leak the handle + // Attempt to load the ROM file. + hTemp = CreateFile(RomFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); + if (hTemp != INVALID_HANDLE_VALUE && (Cart->hRomFile = CreateFileMapping(hTemp, NULL, PAGE_READONLY, 0, 0, NULL) ) ) + { + // if the first case fails, the file doesn't exist. The second case can fail if the file size is zero. + dwFilesize = GetFileSize(hTemp, NULL); + CloseHandle(hTemp); + Cart->RomData = (const unsigned char *)MapViewOfFile( Cart->hRomFile, FILE_MAP_READ, 0, 0, 0 ); + } + else + { + DebugWriteA("Couldn't load the ROM file, GetLastError returned %08x\n", GetLastError()); + if (hTemp != INVALID_HANDLE_VALUE) + CloseHandle(hTemp); // if file size was zero, make sure we don't leak the handle - ErrorMessage(IDS_ERR_GBROM, 0, false); - return false; - } + ErrorMessage(IDS_ERR_GBROM, 0, false); + return false; + } - if (dwFilesize < 0x8000) // a Rom file has to be at least 32kb - { - DebugWriteA("ROM file wasn't big enough to be a GB ROM!\n"); - ErrorMessage(IDS_ERR_GBROM, 0, false); + if (dwFilesize < 0x8000) // a Rom file has to be at least 32kb + { + DebugWriteA("ROM file wasn't big enough to be a GB ROM!\n"); + ErrorMessage(IDS_ERR_GBROM, 0, false); - UnloadCart(Cart); - return false; - } + UnloadCart(Cart); + return false; + } - DebugWriteA(" Cartridge Type #:"); - DebugWriteByteA(Cart->RomData[0x147]); - DebugWriteA("\n"); - switch (Cart->RomData[0x147]) - { // if we hadn't checked the file size before, this might have caused an access violation - case 0x00: - Cart->iCartType = GB_NORM; - Cart->bHasRam = false; - Cart->bHasBattery = false; - Cart->bHasTimer = false; - Cart->bHasRumble = false; - break; - case 0x01: - Cart->iCartType = GB_MBC1; - Cart->bHasRam = false; - Cart->bHasBattery = false; - Cart->bHasTimer = false; - Cart->bHasRumble = false; - break; - case 0x02: - Cart->iCartType = GB_MBC1; - Cart->bHasRam = true; - Cart->bHasBattery = false; - Cart->bHasTimer = false; - Cart->bHasRumble = false; - break; - case 0x03: - Cart->iCartType = GB_MBC1; - Cart->bHasRam = true; - Cart->bHasBattery = true; - Cart->bHasTimer = false; - Cart->bHasRumble = false; - break; - case 0x05: - Cart->iCartType = GB_MBC2; - Cart->bHasRam = false; - Cart->bHasBattery = false; - Cart->bHasTimer = false; - Cart->bHasRumble = false; - break; - case 0x06: - Cart->iCartType = GB_MBC2; - Cart->bHasRam = false; - Cart->bHasBattery = true; - Cart->bHasTimer = false; - Cart->bHasRumble = false; - break; - case 0x08: - Cart->iCartType = GB_NORM; - Cart->bHasRam = true; - Cart->bHasBattery = false; - Cart->bHasTimer = false; - Cart->bHasRumble = false; - break; - case 0x09: - Cart->iCartType = GB_NORM; - Cart->bHasRam = true; - Cart->bHasBattery = true; - Cart->bHasTimer = false; - Cart->bHasRumble = false; - break; - case 0x0B: - Cart->iCartType = GB_MMMO1; - Cart->bHasRam = false; - Cart->bHasBattery = false; - Cart->bHasTimer = false; - Cart->bHasRumble = false; - break; - case 0x0C: - Cart->iCartType = GB_MMMO1; - Cart->bHasRam = true; - Cart->bHasBattery = false; - Cart->bHasTimer = false; - Cart->bHasRumble = false; - break; - case 0x0D: - Cart->iCartType = GB_MMMO1; - Cart->bHasRam = true; - Cart->bHasBattery = true; - Cart->bHasTimer = false; - Cart->bHasRumble = false; - break; - case 0x0F: - Cart->iCartType = GB_MBC3; - Cart->bHasRam = false; - Cart->bHasBattery = true; - Cart->bHasTimer = true; - Cart->bHasRumble = false; - break; - case 0x10: - Cart->iCartType = GB_MBC3; - Cart->bHasRam = true; - Cart->bHasBattery = true; - Cart->bHasTimer = true; - Cart->bHasRumble = false; - break; - case 0x11: - Cart->iCartType = GB_MBC3; - Cart->bHasRam = false; - Cart->bHasBattery = false; - Cart->bHasTimer = false; - Cart->bHasRumble = false; - break; - case 0x12: - Cart->iCartType = GB_MBC3; - Cart->bHasRam = true; - Cart->bHasBattery = true; - Cart->bHasTimer = false; - Cart->bHasRumble = false; - break; - case 0x13: - Cart->iCartType = GB_MBC3; - Cart->bHasRam = true; - Cart->bHasBattery = true; - Cart->bHasTimer = false; - Cart->bHasRumble = false; - break; - case 0x19: - Cart->iCartType = GB_MBC5; - Cart->bHasRam = false; - Cart->bHasBattery = false; - Cart->bHasTimer = false; - Cart->bHasRumble = false; - break; - case 0x1A: - Cart->iCartType = GB_MBC5; - Cart->bHasRam = true; - Cart->bHasBattery = false; - Cart->bHasTimer = false; - Cart->bHasRumble = false; - break; - case 0x1B: - Cart->iCartType = GB_MBC5; - Cart->bHasRam = true; - Cart->bHasBattery = true; - Cart->bHasTimer = false; - Cart->bHasRumble = false; - break; - case 0x1C: - Cart->iCartType = GB_MBC5; - Cart->bHasRam = false; - Cart->bHasBattery = false; - Cart->bHasTimer = false; - Cart->bHasRumble = true; - break; - case 0x1D: - Cart->iCartType = GB_MBC5; - Cart->bHasRam = true; - Cart->bHasBattery = false; - Cart->bHasTimer = false; - Cart->bHasRumble = true; - break; - case 0x1E: - Cart->iCartType = GB_MBC5; - Cart->bHasRam = true; - Cart->bHasBattery = true; - Cart->bHasTimer = false; - Cart->bHasRumble = true; - break; - case 0xFC: - //GAME BOY CAMERA - Cart->iCartType = GB_CAMERA; - Cart->bHasRam = true; - Cart->bHasBattery = true; - Cart->bHasTimer = false; - Cart->bHasRumble = false; - break; - default: - WarningMessage( IDS_ERR_GBROM, MB_OK | MB_ICONWARNING); - DebugWriteA("TPak: unsupported paktype\n"); - UnloadCart(Cart); - return false; - } + DebugWriteA(" Cartridge Type #:"); + DebugWriteByteA(Cart->RomData[0x147]); + DebugWriteA("\n"); + switch (Cart->RomData[0x147]) + { // if we hadn't checked the file size before, this might have caused an access violation + case 0x00: + Cart->iCartType = GB_NORM; + Cart->bHasRam = false; + Cart->bHasBattery = false; + Cart->bHasTimer = false; + Cart->bHasRumble = false; + break; + case 0x01: + Cart->iCartType = GB_MBC1; + Cart->bHasRam = false; + Cart->bHasBattery = false; + Cart->bHasTimer = false; + Cart->bHasRumble = false; + break; + case 0x02: + Cart->iCartType = GB_MBC1; + Cart->bHasRam = true; + Cart->bHasBattery = false; + Cart->bHasTimer = false; + Cart->bHasRumble = false; + break; + case 0x03: + Cart->iCartType = GB_MBC1; + Cart->bHasRam = true; + Cart->bHasBattery = true; + Cart->bHasTimer = false; + Cart->bHasRumble = false; + break; + case 0x05: + Cart->iCartType = GB_MBC2; + Cart->bHasRam = false; + Cart->bHasBattery = false; + Cart->bHasTimer = false; + Cart->bHasRumble = false; + break; + case 0x06: + Cart->iCartType = GB_MBC2; + Cart->bHasRam = false; + Cart->bHasBattery = true; + Cart->bHasTimer = false; + Cart->bHasRumble = false; + break; + case 0x08: + Cart->iCartType = GB_NORM; + Cart->bHasRam = true; + Cart->bHasBattery = false; + Cart->bHasTimer = false; + Cart->bHasRumble = false; + break; + case 0x09: + Cart->iCartType = GB_NORM; + Cart->bHasRam = true; + Cart->bHasBattery = true; + Cart->bHasTimer = false; + Cart->bHasRumble = false; + break; + case 0x0B: + Cart->iCartType = GB_MMMO1; + Cart->bHasRam = false; + Cart->bHasBattery = false; + Cart->bHasTimer = false; + Cart->bHasRumble = false; + break; + case 0x0C: + Cart->iCartType = GB_MMMO1; + Cart->bHasRam = true; + Cart->bHasBattery = false; + Cart->bHasTimer = false; + Cart->bHasRumble = false; + break; + case 0x0D: + Cart->iCartType = GB_MMMO1; + Cart->bHasRam = true; + Cart->bHasBattery = true; + Cart->bHasTimer = false; + Cart->bHasRumble = false; + break; + case 0x0F: + Cart->iCartType = GB_MBC3; + Cart->bHasRam = false; + Cart->bHasBattery = true; + Cart->bHasTimer = true; + Cart->bHasRumble = false; + break; + case 0x10: + Cart->iCartType = GB_MBC3; + Cart->bHasRam = true; + Cart->bHasBattery = true; + Cart->bHasTimer = true; + Cart->bHasRumble = false; + break; + case 0x11: + Cart->iCartType = GB_MBC3; + Cart->bHasRam = false; + Cart->bHasBattery = false; + Cart->bHasTimer = false; + Cart->bHasRumble = false; + break; + case 0x12: + Cart->iCartType = GB_MBC3; + Cart->bHasRam = true; + Cart->bHasBattery = true; + Cart->bHasTimer = false; + Cart->bHasRumble = false; + break; + case 0x13: + Cart->iCartType = GB_MBC3; + Cart->bHasRam = true; + Cart->bHasBattery = true; + Cart->bHasTimer = false; + Cart->bHasRumble = false; + break; + case 0x19: + Cart->iCartType = GB_MBC5; + Cart->bHasRam = false; + Cart->bHasBattery = false; + Cart->bHasTimer = false; + Cart->bHasRumble = false; + break; + case 0x1A: + Cart->iCartType = GB_MBC5; + Cart->bHasRam = true; + Cart->bHasBattery = false; + Cart->bHasTimer = false; + Cart->bHasRumble = false; + break; + case 0x1B: + Cart->iCartType = GB_MBC5; + Cart->bHasRam = true; + Cart->bHasBattery = true; + Cart->bHasTimer = false; + Cart->bHasRumble = false; + break; + case 0x1C: + Cart->iCartType = GB_MBC5; + Cart->bHasRam = false; + Cart->bHasBattery = false; + Cart->bHasTimer = false; + Cart->bHasRumble = true; + break; + case 0x1D: + Cart->iCartType = GB_MBC5; + Cart->bHasRam = true; + Cart->bHasBattery = false; + Cart->bHasTimer = false; + Cart->bHasRumble = true; + break; + case 0x1E: + Cart->iCartType = GB_MBC5; + Cart->bHasRam = true; + Cart->bHasBattery = true; + Cart->bHasTimer = false; + Cart->bHasRumble = true; + break; + case 0xFC: + //GAME BOY CAMERA + Cart->iCartType = GB_CAMERA; + Cart->bHasRam = true; + Cart->bHasBattery = true; + Cart->bHasTimer = false; + Cart->bHasRumble = false; + break; + default: + WarningMessage( IDS_ERR_GBROM, MB_OK | MB_ICONWARNING); + DebugWriteA("TPak: unsupported paktype\n"); + UnloadCart(Cart); + return false; + } - // assign read/write handlers - switch (Cart->iCartType) - { - case GB_NORM: // Raw cartridge - Cart->ptrfnReadCart = &ReadCartNorm; - Cart->ptrfnWriteCart = &WriteCartNorm; - break; - case GB_MBC1: - Cart->ptrfnReadCart = &ReadCartMBC1; - Cart->ptrfnWriteCart = &WriteCartMBC1; - break; - case GB_MBC2: - Cart->ptrfnReadCart = &ReadCartMBC2; - Cart->ptrfnWriteCart = &WriteCartMBC2; - break; - case GB_MBC3: - Cart->ptrfnReadCart = &ReadCartMBC3; - Cart->ptrfnWriteCart = &WriteCartMBC3; - break; - case GB_MBC5: - Cart->ptrfnReadCart = &ReadCartMBC5; - Cart->ptrfnWriteCart = &WriteCartMBC5; - break; - case GB_CAMERA: - Cart->ptrfnReadCart = &ReadCartCamera; - Cart->ptrfnWriteCart = &WriteCartCamera; - break; - default: // Don't pretend we know how to handle carts we don't support - Cart->ptrfnReadCart = NULL; - Cart->ptrfnWriteCart = NULL; - DebugWriteA("Unsupported paktype: can't read/write cart type %02X\n", Cart->iCartType); - UnloadCart(Cart); - return false; - } + // assign read/write handlers + switch (Cart->iCartType) + { + case GB_NORM: // Raw cartridge + Cart->ptrfnReadCart = &ReadCartNorm; + Cart->ptrfnWriteCart = &WriteCartNorm; + break; + case GB_MBC1: + Cart->ptrfnReadCart = &ReadCartMBC1; + Cart->ptrfnWriteCart = &WriteCartMBC1; + break; + case GB_MBC2: + Cart->ptrfnReadCart = &ReadCartMBC2; + Cart->ptrfnWriteCart = &WriteCartMBC2; + break; + case GB_MBC3: + Cart->ptrfnReadCart = &ReadCartMBC3; + Cart->ptrfnWriteCart = &WriteCartMBC3; + break; + case GB_MBC5: + Cart->ptrfnReadCart = &ReadCartMBC5; + Cart->ptrfnWriteCart = &WriteCartMBC5; + break; + case GB_CAMERA: + Cart->ptrfnReadCart = &ReadCartCamera; + Cart->ptrfnWriteCart = &WriteCartCamera; + break; + default: // Don't pretend we know how to handle carts we don't support + Cart->ptrfnReadCart = NULL; + Cart->ptrfnWriteCart = NULL; + DebugWriteA("Unsupported paktype: can't read/write cart type %02X\n", Cart->iCartType); + UnloadCart(Cart); + return false; + } - // Determine ROM size for paging checks - Cart->iNumRomBanks = 2; - switch (Cart->RomData[0x148]) - { - case 0x01: - Cart->iNumRomBanks = 4; - break; - case 0x02: - Cart->iNumRomBanks = 8; - break; - case 0x03: - Cart->iNumRomBanks = 16; - break; - case 0x04: - Cart->iNumRomBanks = 32; - break; - case 0x05: - Cart->iNumRomBanks = 64; - break; - case 0x06: - Cart->iNumRomBanks = 128; - break; - case 0x52: - Cart->iNumRomBanks = 72; - break; - case 0x53: - Cart->iNumRomBanks = 80; - break; - case 0x54: - Cart->iNumRomBanks = 96; - break; - } + // Determine ROM size for paging checks + Cart->iNumRomBanks = 2; + switch (Cart->RomData[0x148]) + { + case 0x01: + Cart->iNumRomBanks = 4; + break; + case 0x02: + Cart->iNumRomBanks = 8; + break; + case 0x03: + Cart->iNumRomBanks = 16; + break; + case 0x04: + Cart->iNumRomBanks = 32; + break; + case 0x05: + Cart->iNumRomBanks = 64; + break; + case 0x06: + Cart->iNumRomBanks = 128; + break; + case 0x52: + Cart->iNumRomBanks = 72; + break; + case 0x53: + Cart->iNumRomBanks = 80; + break; + case 0x54: + Cart->iNumRomBanks = 96; + break; + } - if (dwFilesize != 0x4000 * Cart->iNumRomBanks) // Now that we know how big the ROM is supposed to be, check it again - { - ErrorMessage(IDS_ERR_GBROM, 0, false); + if (dwFilesize != 0x4000 * Cart->iNumRomBanks) // Now that we know how big the ROM is supposed to be, check it again + { + ErrorMessage(IDS_ERR_GBROM, 0, false); - UnloadCart(Cart); - return false; - } + UnloadCart(Cart); + return false; + } - // Determine RAM size for paging checks - Cart->iNumRamBanks = 0; - switch (Cart->RomData[0x149]) { - case 0x01: - Cart->iNumRamBanks = 1; - NumQuarterBlocks = 1; - break; - case 0x02: - Cart->iNumRamBanks = 1; - NumQuarterBlocks = 4; - break; - case 0x03: - Cart->iNumRamBanks = 4; - NumQuarterBlocks = 16; - break; - case 0x04: - Cart->iNumRamBanks = 16; - NumQuarterBlocks = 64; - break; - case 0x05: - Cart->iNumRamBanks = 8; - NumQuarterBlocks = 32; - break; - } + // Determine RAM size for paging checks + Cart->iNumRamBanks = 0; + switch (Cart->RomData[0x149]) { + case 0x01: + Cart->iNumRamBanks = 1; + NumQuarterBlocks = 1; + break; + case 0x02: + Cart->iNumRamBanks = 1; + NumQuarterBlocks = 4; + break; + case 0x03: + Cart->iNumRamBanks = 4; + NumQuarterBlocks = 16; + break; + case 0x04: + Cart->iNumRamBanks = 16; + NumQuarterBlocks = 64; + break; + case 0x05: + Cart->iNumRamBanks = 8; + NumQuarterBlocks = 32; + break; + } - DebugWriteA("GB cart has %d ROM banks, %d RAM quarter banks\n", Cart->iNumRomBanks, NumQuarterBlocks); - if (Cart->bHasTimer) - { - DebugWriteA("GB cart timer present\n"); - } + DebugWriteA("GB cart has %d ROM banks, %d RAM quarter banks\n", Cart->iNumRomBanks, NumQuarterBlocks); + if (Cart->bHasTimer) + { + DebugWriteA("GB cart timer present\n"); + } - // Attempt to load the SRAM file, but only if RAM is supposed to be present. - // For saving back to a file, if we map too much it will expand the file. - if (Cart->bHasRam) - { - if (Cart->bHasBattery) - { - hTemp = CreateFile( RamFileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL ); - if( hTemp == INVALID_HANDLE_VALUE ) - {// test if Read-only access is possible - hTemp = CreateFile( RamFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL ); - if (Cart->bHasTimer && Cart->bHasBattery) - { - Cart->RamData = (LPBYTE)P_malloc(NumQuarterBlocks * 0x0800 + sizeof(gbCartRTC)); - ClearData(Cart->RamData, NumQuarterBlocks * 0x0800 + sizeof(gbCartRTC)); - } - else - { - Cart->RamData = (LPBYTE)P_malloc(NumQuarterBlocks * 0x0800); - ClearData(Cart->RamData, NumQuarterBlocks * 0x0800); - } + // Attempt to load the SRAM file, but only if RAM is supposed to be present. + // For saving back to a file, if we map too much it will expand the file. + if (Cart->bHasRam) + { + if (Cart->bHasBattery) + { + hTemp = CreateFile( RamFileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL ); + if( hTemp == INVALID_HANDLE_VALUE ) + {// test if Read-only access is possible + hTemp = CreateFile( RamFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL ); + if (Cart->bHasTimer && Cart->bHasBattery) + { + Cart->RamData = (LPBYTE)P_malloc(NumQuarterBlocks * 0x0800 + sizeof(gbCartRTC)); + ClearData(Cart->RamData, NumQuarterBlocks * 0x0800 + sizeof(gbCartRTC)); + } + else + { + Cart->RamData = (LPBYTE)P_malloc(NumQuarterBlocks * 0x0800); + ClearData(Cart->RamData, NumQuarterBlocks * 0x0800); + } - if( hTemp != INVALID_HANDLE_VALUE ) - { - DWORD dwBytesRead; + if( hTemp != INVALID_HANDLE_VALUE ) + { + DWORD dwBytesRead; - if (Cart->bHasTimer && Cart->bHasBattery) - ReadFile(hTemp, Cart->RamData, NumQuarterBlocks * 0x0800 + sizeof(gbCartRTC), &dwBytesRead, NULL); - else - ReadFile(hTemp, Cart->RamData, NumQuarterBlocks * 0x0800, &dwBytesRead, NULL); - WarningMessage( IDS_DLG_TPAK_READONLY, MB_OK | MB_ICONWARNING); - } - else - { - WarningMessage( IDS_ERR_GBSRAMERR, MB_OK | MB_ICONWARNING); - return true; - } - } - else - { // file is OK, use a mapping - if (Cart->bHasTimer && Cart->bHasBattery) - Cart->hRamFile = CreateFileMapping( hTemp, NULL, PAGE_READWRITE, 0, NumQuarterBlocks * 0x0800 + sizeof(gbCartRTC), NULL); - else - Cart->hRamFile = CreateFileMapping( hTemp, NULL, PAGE_READWRITE, 0, NumQuarterBlocks * 0x0800, NULL); + if (Cart->bHasTimer && Cart->bHasBattery) + ReadFile(hTemp, Cart->RamData, NumQuarterBlocks * 0x0800 + sizeof(gbCartRTC), &dwBytesRead, NULL); + else + ReadFile(hTemp, Cart->RamData, NumQuarterBlocks * 0x0800, &dwBytesRead, NULL); + WarningMessage( IDS_DLG_TPAK_READONLY, MB_OK | MB_ICONWARNING); + } + else + { + WarningMessage( IDS_ERR_GBSRAMERR, MB_OK | MB_ICONWARNING); + return true; + } + } + else + { // file is OK, use a mapping + if (Cart->bHasTimer && Cart->bHasBattery) + Cart->hRamFile = CreateFileMapping( hTemp, NULL, PAGE_READWRITE, 0, NumQuarterBlocks * 0x0800 + sizeof(gbCartRTC), NULL); + else + Cart->hRamFile = CreateFileMapping( hTemp, NULL, PAGE_READWRITE, 0, NumQuarterBlocks * 0x0800, NULL); - if (Cart->hRamFile != NULL) - { - Cart->RamData = (LPBYTE)MapViewOfFile( Cart->hRamFile, FILE_MAP_ALL_ACCESS, 0, 0, 0 ); - } - else - { // could happen, if the file isn't big enough AND can't be grown to fit - DWORD dwBytesRead; - if (Cart->bHasTimer && Cart->bHasBattery) - { - Cart->RamData = (LPBYTE)P_malloc(NumQuarterBlocks * 0x0800 + sizeof(gbCartRTC)); - ReadFile(hTemp, Cart->RamData, NumQuarterBlocks * 0x0800 + sizeof(gbCartRTC), &dwBytesRead, NULL); - } - else - { - Cart->RamData = (LPBYTE)P_malloc(NumQuarterBlocks * 0x0800); - ReadFile(hTemp, Cart->RamData, NumQuarterBlocks * 0x0800, &dwBytesRead, NULL); - } + if (Cart->hRamFile != NULL) + { + Cart->RamData = (LPBYTE)MapViewOfFile( Cart->hRamFile, FILE_MAP_ALL_ACCESS, 0, 0, 0 ); + } + else + { // could happen, if the file isn't big enough AND can't be grown to fit + DWORD dwBytesRead; + if (Cart->bHasTimer && Cart->bHasBattery) + { + Cart->RamData = (LPBYTE)P_malloc(NumQuarterBlocks * 0x0800 + sizeof(gbCartRTC)); + ReadFile(hTemp, Cart->RamData, NumQuarterBlocks * 0x0800 + sizeof(gbCartRTC), &dwBytesRead, NULL); + } + else + { + Cart->RamData = (LPBYTE)P_malloc(NumQuarterBlocks * 0x0800); + ReadFile(hTemp, Cart->RamData, NumQuarterBlocks * 0x0800, &dwBytesRead, NULL); + } - if (dwBytesRead < NumQuarterBlocks * 0x0800 + ((Cart->bHasTimer && Cart->bHasBattery) ? sizeof(gbCartRTC) : 0)) - { - ClearData(Cart->RamData, NumQuarterBlocks * 0x0800 + ((Cart->bHasTimer && Cart->bHasBattery) ? sizeof(gbCartRTC) : 0)); - WarningMessage( IDS_ERR_GBSRAMERR, MB_OK | MB_ICONWARNING); - } - else - { - WarningMessage( IDS_DLG_TPAK_READONLY, MB_OK | MB_ICONWARNING); - } - } - } + if (dwBytesRead < NumQuarterBlocks * 0x0800 + ((Cart->bHasTimer && Cart->bHasBattery) ? sizeof(gbCartRTC) : 0)) + { + ClearData(Cart->RamData, NumQuarterBlocks * 0x0800 + ((Cart->bHasTimer && Cart->bHasBattery) ? sizeof(gbCartRTC) : 0)); + WarningMessage( IDS_ERR_GBSRAMERR, MB_OK | MB_ICONWARNING); + } + else + { + WarningMessage( IDS_DLG_TPAK_READONLY, MB_OK | MB_ICONWARNING); + } + } + } - if (Cart->bHasTimer && Cart->bHasBattery) - { - dwFilesize = GetFileSize(hTemp, 0); - if (dwFilesize >= (NumQuarterBlocks * 0x0800 + sizeof(gbCartRTC) ) ) - { - // Looks like there is extra data in the SAV file than just RAM data... assume it is RTC data. - gbCartRTC RTCTimer; - CopyMemory( &RTCTimer, &Cart->RamData[NumQuarterBlocks * 0x0800], sizeof(RTCTimer) ); - Cart->TimerData[0] = RTCTimer.mapperSeconds; - Cart->TimerData[1] = RTCTimer.mapperMinutes; - Cart->TimerData[2] = RTCTimer.mapperHours; - Cart->TimerData[3] = RTCTimer.mapperDays; - Cart->TimerData[4] = RTCTimer.mapperControl; - Cart->LatchedTimerData[0] = RTCTimer.mapperLSeconds; - Cart->LatchedTimerData[1] = RTCTimer.mapperLMinutes; - Cart->LatchedTimerData[2] = RTCTimer.mapperLHours; - Cart->LatchedTimerData[3] = RTCTimer.mapperLDays; - Cart->LatchedTimerData[4] = RTCTimer.mapperLControl; - Cart->timerLastUpdate = RTCTimer.mapperLastTime; - UpdateRTC(Cart); - } - else - { - ReadTDF(Cart); // try to open TDF format, clear/init Cart->TimerData if that fails - } - } + if (Cart->bHasTimer && Cart->bHasBattery) + { + dwFilesize = GetFileSize(hTemp, 0); + if (dwFilesize >= (NumQuarterBlocks * 0x0800 + sizeof(gbCartRTC) ) ) + { + // Looks like there is extra data in the SAV file than just RAM data... assume it is RTC data. + gbCartRTC RTCTimer; + CopyMemory( &RTCTimer, &Cart->RamData[NumQuarterBlocks * 0x0800], sizeof(RTCTimer) ); + Cart->TimerData[0] = RTCTimer.mapperSeconds; + Cart->TimerData[1] = RTCTimer.mapperMinutes; + Cart->TimerData[2] = RTCTimer.mapperHours; + Cart->TimerData[3] = RTCTimer.mapperDays; + Cart->TimerData[4] = RTCTimer.mapperControl; + Cart->LatchedTimerData[0] = RTCTimer.mapperLSeconds; + Cart->LatchedTimerData[1] = RTCTimer.mapperLMinutes; + Cart->LatchedTimerData[2] = RTCTimer.mapperLHours; + Cart->LatchedTimerData[3] = RTCTimer.mapperLDays; + Cart->LatchedTimerData[4] = RTCTimer.mapperLControl; + Cart->timerLastUpdate = RTCTimer.mapperLastTime; + UpdateRTC(Cart); + } + else + { + ReadTDF(Cart); // try to open TDF format, clear/init Cart->TimerData if that fails + } + } - CloseHandle(hTemp); - } - else - { - // no battery; just allocate some RAM - Cart->RamData = (LPBYTE)P_malloc(Cart->iNumRamBanks * 0x2000); - } - } + CloseHandle(hTemp); + } + else + { + // no battery; just allocate some RAM + Cart->RamData = (LPBYTE)P_malloc(Cart->iNumRamBanks * 0x2000); + } + } - Cart->TimerDataLatched = false; + Cart->TimerDataLatched = false; - return true; + return true; } // Done bool ReadCartNorm(LPGBCART Cart, WORD dwAddress, BYTE *Data) // For all non-MBC carts; fixed 0x8000 ROM; fixed, optional 0x2000 RAM { - switch (dwAddress >> 13) // hack: examine highest 3 bits - { - case 0: - case 1: - case 2: - case 3: // if ((dwAddress >= 0) && (dwAddress <= 0x7FFF)) - CopyMemory(Data, &Cart->RomData[dwAddress], 32); - DebugWriteA("Nonbanked ROM read - RAW\n"); - break; - case 5: - if (Cart->bHasRam) // no MBC, so no enable state to check - { - if (Cart->RomData[0x149] == 1 && (dwAddress - 0xA000) / 0x0800 ) // Only 1/4 of the RAM space is used, and we're out of bounds - { - DebugWriteA("Failed RAM read: Unbanked (out of bounds)"); - ZeroMemory(Data, 32); - } - else - { - CopyMemory(Data, &Cart->RamData[dwAddress - 0xA000], 32); - DebugWriteA("RAM read: Unbanked\n"); - } - } - else - { - ZeroMemory(Data, 32); - DebugWriteA("Failed RAM read: Unbanked (RAM not present)\n"); - } - break; - default: - DebugWriteA("Bad read from RAW cart, address %04X\n", dwAddress); - } + switch (dwAddress >> 13) // hack: examine highest 3 bits + { + case 0: + case 1: + case 2: + case 3: // if ((dwAddress >= 0) && (dwAddress <= 0x7FFF)) + CopyMemory(Data, &Cart->RomData[dwAddress], 32); + DebugWriteA("Nonbanked ROM read - RAW\n"); + break; + case 5: + if (Cart->bHasRam) // no MBC, so no enable state to check + { + if (Cart->RomData[0x149] == 1 && (dwAddress - 0xA000) / 0x0800 ) // Only 1/4 of the RAM space is used, and we're out of bounds + { + DebugWriteA("Failed RAM read: Unbanked (out of bounds)"); + ZeroMemory(Data, 32); + } + else + { + CopyMemory(Data, &Cart->RamData[dwAddress - 0xA000], 32); + DebugWriteA("RAM read: Unbanked\n"); + } + } + else + { + ZeroMemory(Data, 32); + DebugWriteA("Failed RAM read: Unbanked (RAM not present)\n"); + } + break; + default: + DebugWriteA("Bad read from RAW cart, address %04X\n", dwAddress); + } - return true; + return true; } // Done bool WriteCartNorm(LPGBCART Cart, WORD dwAddress, BYTE *Data) { - if (!Cart->bHasRam) - { - DebugWriteA("RAM write: no RAM\n"); - return true; - } + if (!Cart->bHasRam) + { + DebugWriteA("RAM write: no RAM\n"); + return true; + } - if (Cart->RomData[0x149] == 1) - { // Whoops... Only 1/4 of the RAM space is used. - if ((dwAddress >= 0xA000) && (dwAddress <= 0xA7FF)) - { // Write to RAM - DebugWriteA("RAM write: Unbanked\n"); - CopyMemory(&Cart->RamData[dwAddress - 0xA000], Data, 32); - } - else - { - DebugWriteA("RAM write: Unbanked (out of range!)\n"); - } - } - else - { - if ((dwAddress >= 0xA000) && (dwAddress <= 0xBFFF)) - { // Write to RAM - DebugWriteA("RAM write: Unbanked\n"); - CopyMemory(&Cart->RamData[dwAddress - 0xA000], Data, 32); - } - } - return true; + if (Cart->RomData[0x149] == 1) + { // Whoops... Only 1/4 of the RAM space is used. + if ((dwAddress >= 0xA000) && (dwAddress <= 0xA7FF)) + { // Write to RAM + DebugWriteA("RAM write: Unbanked\n"); + CopyMemory(&Cart->RamData[dwAddress - 0xA000], Data, 32); + } + else + { + DebugWriteA("RAM write: Unbanked (out of range!)\n"); + } + } + else + { + if ((dwAddress >= 0xA000) && (dwAddress <= 0xBFFF)) + { // Write to RAM + DebugWriteA("RAM write: Unbanked\n"); + CopyMemory(&Cart->RamData[dwAddress - 0xA000], Data, 32); + } + } + return true; } // Done bool ReadCartMBC1(LPGBCART Cart, WORD dwAddress, BYTE *Data) { - if ((dwAddress >= 0) && (dwAddress <= 0x3FFF)) - { - CopyMemory(Data, &Cart->RomData[dwAddress], 32); - DebugWriteA("Nonbanked ROM read - MBC1\n"); - } - else if ((dwAddress >= 0x4000) && (dwAddress <= 0x7FFF)) - { - if (Cart->iCurrentRomBankNo >= Cart->iNumRomBanks) - { - ZeroMemory(Data, 32); - DebugWriteA("Banked ROM read: (Banking Error) Bank %02X\n", Cart->iCurrentRomBankNo); - } - else - { - // for (i=0; i<32; i++) Data[i] = Cart->RomData[(dwAddress - 0x4000) + i + (Cart->iCurrentRomBankNo * 0x4000)]; - CopyMemory(Data, &Cart->RomData[dwAddress - 0x4000 + (Cart->iCurrentRomBankNo << 14)], 32); - DebugWriteA("Banked ROM read: Bank %02X\n", Cart->iCurrentRomBankNo); - } - } - else if ((dwAddress >= 0xA000) && (dwAddress <= 0xBFFF)) - { - if (Cart->bHasRam/* && Cart->bRamEnableState)*/) - { - if (Cart->iCurrentRamBankNo >= Cart->iNumRamBanks) - { - ZeroMemory(Data, 32); - DebugWriteA("Failed RAM read: (Banking Error) %02X\n", Cart->iCurrentRamBankNo); - } - else - { - CopyMemory(Data, &Cart->RamData[dwAddress - 0xA000 + (Cart->iCurrentRamBankNo << 13)], 32); - DebugWriteA("RAM read: Bank %02X\n", Cart->iCurrentRamBankNo); - } - } - else - { - ZeroMemory(Data, 32); - DebugWriteA("Failed RAM read: (RAM not present)\n"); - } - } - else - { - DebugWriteA("Bad read from MBC1 cart, address %04X\n", dwAddress); - } + if ((dwAddress >= 0) && (dwAddress <= 0x3FFF)) + { + CopyMemory(Data, &Cart->RomData[dwAddress], 32); + DebugWriteA("Nonbanked ROM read - MBC1\n"); + } + else if ((dwAddress >= 0x4000) && (dwAddress <= 0x7FFF)) + { + if (Cart->iCurrentRomBankNo >= Cart->iNumRomBanks) + { + ZeroMemory(Data, 32); + DebugWriteA("Banked ROM read: (Banking Error) Bank %02X\n", Cart->iCurrentRomBankNo); + } + else + { + // for (i=0; i<32; i++) Data[i] = Cart->RomData[(dwAddress - 0x4000) + i + (Cart->iCurrentRomBankNo * 0x4000)]; + CopyMemory(Data, &Cart->RomData[dwAddress - 0x4000 + (Cart->iCurrentRomBankNo << 14)], 32); + DebugWriteA("Banked ROM read: Bank %02X\n", Cart->iCurrentRomBankNo); + } + } + else if ((dwAddress >= 0xA000) && (dwAddress <= 0xBFFF)) + { + if (Cart->bHasRam/* && Cart->bRamEnableState)*/) + { + if (Cart->iCurrentRamBankNo >= Cart->iNumRamBanks) + { + ZeroMemory(Data, 32); + DebugWriteA("Failed RAM read: (Banking Error) %02X\n", Cart->iCurrentRamBankNo); + } + else + { + CopyMemory(Data, &Cart->RamData[dwAddress - 0xA000 + (Cart->iCurrentRamBankNo << 13)], 32); + DebugWriteA("RAM read: Bank %02X\n", Cart->iCurrentRamBankNo); + } + } + else + { + ZeroMemory(Data, 32); + DebugWriteA("Failed RAM read: (RAM not present)\n"); + } + } + else + { + DebugWriteA("Bad read from MBC1 cart, address %04X\n", dwAddress); + } - return true; + return true; } // Done bool WriteCartMBC1(LPGBCART Cart, WORD dwAddress, BYTE *Data) { - if ((dwAddress >= 0x0000) && (dwAddress <= 0x1FFF)) // RAM enable - { - Cart->bRamEnableState = (Data[0] == 0x0A); - DebugWriteA("Set RAM enable: %d\n", Cart->bRamEnableState); - } - else if ((dwAddress >= 0x2000) && (dwAddress <= 0x3FFF)) // ROM bank select - { - Cart->iCurrentRomBankNo &= 0x60; // keep MSB - Cart->iCurrentRomBankNo |= Data[0] & 0x1F; + if ((dwAddress >= 0x0000) && (dwAddress <= 0x1FFF)) // RAM enable + { + Cart->bRamEnableState = (Data[0] == 0x0A); + DebugWriteA("Set RAM enable: %d\n", Cart->bRamEnableState); + } + else if ((dwAddress >= 0x2000) && (dwAddress <= 0x3FFF)) // ROM bank select + { + Cart->iCurrentRomBankNo &= 0x60; // keep MSB + Cart->iCurrentRomBankNo |= Data[0] & 0x1F; - // emulate quirk: 0x00 -> 0x01, 0x20 -> 0x21, 0x40->0x41, 0x60 -> 0x61 - if ((Cart->iCurrentRomBankNo & 0x1F) == 0) - { - Cart->iCurrentRomBankNo |= 0x01; - } - DebugWriteA("Set ROM Bank: %02X\n", Cart->iCurrentRomBankNo); - } - else if ((dwAddress >= 0x4000) && (dwAddress <= 0x5FFF)) // RAM bank select - { - if (Cart->bMBC1RAMbanking) - { - Cart->iCurrentRamBankNo = Data[0] & 0x03; - DebugWriteA("Set RAM Bank: %02X\n", Cart->iCurrentRamBankNo); - } - else - { - Cart->iCurrentRomBankNo &= 0x1F; - Cart->iCurrentRomBankNo |= ((Data[0] & 0x03) << 5); // set bits 5 and 6 of ROM bank - DebugWriteA("Set ROM Bank MSB, ROM bank now: %02X\n", Cart->iCurrentRomBankNo); - } - } - else if ((dwAddress >= 0x6000) && (dwAddress <= 0x7FFF)) // MBC1 mode select - { - // this is overly complicated, but it keeps us from having to do bitwise math later - // Basically we shuffle the 2 "magic bits" between iCurrentRomBankNo and iCurrentRamBankNo as necessary. - if (Cart->bMBC1RAMbanking != (Data[0] & 0x01)) - { - // we should only alter the ROM and RAM bank numbers if we have changed modes - Cart->bMBC1RAMbanking = Data[0] & 0x01; - if (Cart->bMBC1RAMbanking) - { - Cart->iCurrentRamBankNo = Cart->iCurrentRomBankNo >> 5; // set the ram bank to the "magic bits" - Cart->iCurrentRomBankNo &= 0x1F; // zero out bits 5 and 6 to keep consistency - } - else - { - Cart->iCurrentRomBankNo &= 0x1F; - Cart->iCurrentRomBankNo |= (Cart->iCurrentRamBankNo << 5); - Cart->iCurrentRamBankNo = 0x00; // we can only reach RAM page 0 - } - DebugWriteA("Set MBC1 mode: %s\n", Cart->bMBC1RAMbanking ? "ROMbanking" : "RAMbanking"); - } - else - { - DebugWriteA("Already in MBC1 mode: %s\n", Cart->bMBC1RAMbanking ? "ROMbanking" : "RAMbanking"); - } - } - else if ((dwAddress >= 0xA000) && (dwAddress <= 0xBFFF)) // Write to RAM - { - if (Cart->bHasRam) // && Cart->bRamEnableState) - { - DebugWriteA("RAM write: Bank %02X\n", Cart->iCurrentRamBankNo); - CopyMemory(&Cart->RamData[dwAddress - 0xA000 + (Cart->iCurrentRamBankNo << 13)], Data, 32); - } - else - { - DebugWriteA("Failed RAM write: (RAM not present)\n"); - } - } - else - { - DebugWriteA("Bad write to MBC1 cart, address %04X\n", dwAddress); - } + // emulate quirk: 0x00 -> 0x01, 0x20 -> 0x21, 0x40->0x41, 0x60 -> 0x61 + if ((Cart->iCurrentRomBankNo & 0x1F) == 0) + { + Cart->iCurrentRomBankNo |= 0x01; + } + DebugWriteA("Set ROM Bank: %02X\n", Cart->iCurrentRomBankNo); + } + else if ((dwAddress >= 0x4000) && (dwAddress <= 0x5FFF)) // RAM bank select + { + if (Cart->bMBC1RAMbanking) + { + Cart->iCurrentRamBankNo = Data[0] & 0x03; + DebugWriteA("Set RAM Bank: %02X\n", Cart->iCurrentRamBankNo); + } + else + { + Cart->iCurrentRomBankNo &= 0x1F; + Cart->iCurrentRomBankNo |= ((Data[0] & 0x03) << 5); // set bits 5 and 6 of ROM bank + DebugWriteA("Set ROM Bank MSB, ROM bank now: %02X\n", Cart->iCurrentRomBankNo); + } + } + else if ((dwAddress >= 0x6000) && (dwAddress <= 0x7FFF)) // MBC1 mode select + { + // this is overly complicated, but it keeps us from having to do bitwise math later + // Basically we shuffle the 2 "magic bits" between iCurrentRomBankNo and iCurrentRamBankNo as necessary. + if (Cart->bMBC1RAMbanking != (Data[0] & 0x01)) + { + // we should only alter the ROM and RAM bank numbers if we have changed modes + Cart->bMBC1RAMbanking = Data[0] & 0x01; + if (Cart->bMBC1RAMbanking) + { + Cart->iCurrentRamBankNo = Cart->iCurrentRomBankNo >> 5; // set the ram bank to the "magic bits" + Cart->iCurrentRomBankNo &= 0x1F; // zero out bits 5 and 6 to keep consistency + } + else + { + Cart->iCurrentRomBankNo &= 0x1F; + Cart->iCurrentRomBankNo |= (Cart->iCurrentRamBankNo << 5); + Cart->iCurrentRamBankNo = 0x00; // we can only reach RAM page 0 + } + DebugWriteA("Set MBC1 mode: %s\n", Cart->bMBC1RAMbanking ? "ROMbanking" : "RAMbanking"); + } + else + { + DebugWriteA("Already in MBC1 mode: %s\n", Cart->bMBC1RAMbanking ? "ROMbanking" : "RAMbanking"); + } + } + else if ((dwAddress >= 0xA000) && (dwAddress <= 0xBFFF)) // Write to RAM + { + if (Cart->bHasRam) // && Cart->bRamEnableState) + { + DebugWriteA("RAM write: Bank %02X\n", Cart->iCurrentRamBankNo); + CopyMemory(&Cart->RamData[dwAddress - 0xA000 + (Cart->iCurrentRamBankNo << 13)], Data, 32); + } + else + { + DebugWriteA("Failed RAM write: (RAM not present)\n"); + } + } + else + { + DebugWriteA("Bad write to MBC1 cart, address %04X\n", dwAddress); + } - return true; + return true; } // Done bool ReadCartMBC2(LPGBCART Cart, WORD dwAddress, BYTE *Data) { - if ((dwAddress <= 0x3FFF)) - { - CopyMemory(Data, &Cart->RomData[dwAddress], 32); - DebugWriteA("Nonbanked ROM read - MBC2\n"); - } - else if ((dwAddress >= 0x4000) && (dwAddress <= 0x7FFF)) - { - if (Cart->iCurrentRomBankNo >= Cart->iNumRomBanks) - { - ZeroMemory(Data, 32); - DebugWriteA("Banked ROM read: (Banking Error) %02X\n", Cart->iCurrentRomBankNo); - } - else - { - CopyMemory(Data, &Cart->RomData[dwAddress - 0x4000 + (Cart->iCurrentRomBankNo << 14)], 32); - DebugWriteA("Banked ROM read: Bank %02X\n", Cart->iCurrentRomBankNo); - } - } - else if ((dwAddress >= 0xA000) && (dwAddress <= 0xBFFF)) - { - if (Cart->bHasRam && Cart->bRamEnableState) - { - CopyMemory(Data, &Cart->RamData[dwAddress - 0xA000], 32); - DebugWriteA("RAM read: Unbanked\n"); - } - else - { - ZeroMemory(Data, 32); - DebugWriteA("Failed RAM read: (RAM not present or not active)\n"); - } - } - else - { - DebugWriteA("Bad read from MBC2 cart, address %04X\n", dwAddress); - } + if ((dwAddress <= 0x3FFF)) + { + CopyMemory(Data, &Cart->RomData[dwAddress], 32); + DebugWriteA("Nonbanked ROM read - MBC2\n"); + } + else if ((dwAddress >= 0x4000) && (dwAddress <= 0x7FFF)) + { + if (Cart->iCurrentRomBankNo >= Cart->iNumRomBanks) + { + ZeroMemory(Data, 32); + DebugWriteA("Banked ROM read: (Banking Error) %02X\n", Cart->iCurrentRomBankNo); + } + else + { + CopyMemory(Data, &Cart->RomData[dwAddress - 0x4000 + (Cart->iCurrentRomBankNo << 14)], 32); + DebugWriteA("Banked ROM read: Bank %02X\n", Cart->iCurrentRomBankNo); + } + } + else if ((dwAddress >= 0xA000) && (dwAddress <= 0xBFFF)) + { + if (Cart->bHasRam && Cart->bRamEnableState) + { + CopyMemory(Data, &Cart->RamData[dwAddress - 0xA000], 32); + DebugWriteA("RAM read: Unbanked\n"); + } + else + { + ZeroMemory(Data, 32); + DebugWriteA("Failed RAM read: (RAM not present or not active)\n"); + } + } + else + { + DebugWriteA("Bad read from MBC2 cart, address %04X\n", dwAddress); + } - return true; + return true; } // Done bool WriteCartMBC2(LPGBCART Cart, WORD dwAddress, BYTE *Data) { - if ((dwAddress >= 0x0000) && (dwAddress <= 0x1FFF)) // We shouldn't be able to read/write to RAM unless this is toggled on - { - Cart->bRamEnableState = (Data[0] == 0x0A); - DebugWriteA("Set RAM enable: %d\n", Cart->bRamEnableState); - } - else if ((dwAddress >= 0x2000) && (dwAddress <= 0x3FFF)) // ROM bank select - { - Cart->iCurrentRomBankNo = Data[0] & 0x0F; - if (Cart->iCurrentRomBankNo == 0) - { - Cart->iCurrentRomBankNo = 1; - } - DebugWriteA("Set ROM Bank: %02X\n", Cart->iCurrentRomBankNo); - } - else if ((dwAddress >= 0x4000) && (dwAddress <= 0x5FFF)) // RAM bank select - { - if (Cart->bHasRam) - { - Cart->iCurrentRamBankNo = Data[0] & 0x07; - DebugWriteA("Set RAM Bank: %02X\n", Cart->iCurrentRamBankNo); - } - } - else if ((dwAddress >= 0xA000) && (dwAddress <= 0xBFFF) && Cart->bRamEnableState) // Write to RAM - { - if (Cart->bHasRam) - { - DebugWriteA("RAM write: Bank %02X\n", Cart->iCurrentRamBankNo); - CopyMemory(&Cart->RamData[dwAddress - 0xA000 + (Cart->iCurrentRamBankNo << 13)], Data, 32); - } - } - else - { - DebugWriteA("Bad write to MBC2 cart, address %04X\n", dwAddress); - } + if ((dwAddress >= 0x0000) && (dwAddress <= 0x1FFF)) // We shouldn't be able to read/write to RAM unless this is toggled on + { + Cart->bRamEnableState = (Data[0] == 0x0A); + DebugWriteA("Set RAM enable: %d\n", Cart->bRamEnableState); + } + else if ((dwAddress >= 0x2000) && (dwAddress <= 0x3FFF)) // ROM bank select + { + Cart->iCurrentRomBankNo = Data[0] & 0x0F; + if (Cart->iCurrentRomBankNo == 0) + { + Cart->iCurrentRomBankNo = 1; + } + DebugWriteA("Set ROM Bank: %02X\n", Cart->iCurrentRomBankNo); + } + else if ((dwAddress >= 0x4000) && (dwAddress <= 0x5FFF)) // RAM bank select + { + if (Cart->bHasRam) + { + Cart->iCurrentRamBankNo = Data[0] & 0x07; + DebugWriteA("Set RAM Bank: %02X\n", Cart->iCurrentRamBankNo); + } + } + else if ((dwAddress >= 0xA000) && (dwAddress <= 0xBFFF) && Cart->bRamEnableState) // Write to RAM + { + if (Cart->bHasRam) + { + DebugWriteA("RAM write: Bank %02X\n", Cart->iCurrentRamBankNo); + CopyMemory(&Cart->RamData[dwAddress - 0xA000 + (Cart->iCurrentRamBankNo << 13)], Data, 32); + } + } + else + { + DebugWriteA("Bad write to MBC2 cart, address %04X\n", dwAddress); + } - return true; + return true; } // Done bool ReadCartMBC3(LPGBCART Cart, WORD dwAddress, BYTE *Data) { - if ((dwAddress < 0x4000)) //Rom Bank 0 - { - CopyMemory(Data, &Cart->RomData[dwAddress], 32); - DebugWriteA("Nonbanked ROM read - MBC3\n"); - } - else if ((dwAddress >= 0x4000) && (dwAddress < 0x8000)) //Switchable Rom Bank - { - if (Cart->iCurrentRomBankNo >= Cart->iNumRomBanks) - { - ZeroMemory(Data, 32); - DebugWriteA("Banked ROM read: (Banking Error) %02X\n", Cart->iCurrentRomBankNo); - } - else - { - CopyMemory(Data, &Cart->RomData[dwAddress - 0x4000 + (Cart->iCurrentRomBankNo * 0x4000)], 32); - DebugWriteA("Banked ROM read: Bank %02X\n", Cart->iCurrentRomBankNo); - } - } - else if ((dwAddress >= 0xA000) && (dwAddress <= 0xC000)) //Upper Bounds of memory map - { - if (Cart->bHasTimer && (Cart->iCurrentRamBankNo >= 0x08 && Cart->iCurrentRamBankNo <= 0x0c)) - { - // w00t! the Timer was just read!! - if (Cart->TimerDataLatched) - { - for (int i = 0; i < 32; i++) - Data[i] = Cart->LatchedTimerData[Cart->iCurrentRamBankNo - 0x08]; - } - else - { - UpdateRTC(Cart); - for (int i = 0; i < 32; i++) - Data[i] = Cart->TimerData[Cart->iCurrentRamBankNo - 0x08]; - } - } - else if (Cart->bHasRam) - { - if (Cart->iCurrentRamBankNo >= Cart->iNumRamBanks) - { - ZeroMemory(Data, 32); - DebugWriteA("Failed RAM read: (Banking Error) %02X\n", Cart->iCurrentRamBankNo); - } - else - { - CopyMemory(Data, &Cart->RamData[dwAddress - 0xA000 + (Cart->iCurrentRamBankNo * 0x2000)], 32); - DebugWriteA("RAM read: Bank %02X\n", Cart->iCurrentRamBankNo); - }/* - else - { - ZeroMemory(Data, 32); - //for (i=0; i<32; i++) Data[i] = 0; - DebugWriteA("Failed RAM read: (RAM not active)\n"); - }*/ - } - else - { - ZeroMemory(Data, 32); - DebugWriteA("Failed RAM read: (RAM not present)\n"); - } - } - else - { - DebugWriteA("Bad read from MBC3 cart, address %04X\n", dwAddress); - } + if ((dwAddress < 0x4000)) //Rom Bank 0 + { + CopyMemory(Data, &Cart->RomData[dwAddress], 32); + DebugWriteA("Nonbanked ROM read - MBC3\n"); + } + else if ((dwAddress >= 0x4000) && (dwAddress < 0x8000)) //Switchable Rom Bank + { + if (Cart->iCurrentRomBankNo >= Cart->iNumRomBanks) + { + ZeroMemory(Data, 32); + DebugWriteA("Banked ROM read: (Banking Error) %02X\n", Cart->iCurrentRomBankNo); + } + else + { + CopyMemory(Data, &Cart->RomData[dwAddress - 0x4000 + (Cart->iCurrentRomBankNo * 0x4000)], 32); + DebugWriteA("Banked ROM read: Bank %02X\n", Cart->iCurrentRomBankNo); + } + } + else if ((dwAddress >= 0xA000) && (dwAddress <= 0xC000)) //Upper Bounds of memory map + { + if (Cart->bHasTimer && (Cart->iCurrentRamBankNo >= 0x08 && Cart->iCurrentRamBankNo <= 0x0c)) + { + // w00t! the Timer was just read!! + if (Cart->TimerDataLatched) + { + for (int i = 0; i < 32; i++) + Data[i] = Cart->LatchedTimerData[Cart->iCurrentRamBankNo - 0x08]; + } + else + { + UpdateRTC(Cart); + for (int i = 0; i < 32; i++) + Data[i] = Cart->TimerData[Cart->iCurrentRamBankNo - 0x08]; + } + } + else if (Cart->bHasRam) + { + if (Cart->iCurrentRamBankNo >= Cart->iNumRamBanks) + { + ZeroMemory(Data, 32); + DebugWriteA("Failed RAM read: (Banking Error) %02X\n", Cart->iCurrentRamBankNo); + } + else + { + CopyMemory(Data, &Cart->RamData[dwAddress - 0xA000 + (Cart->iCurrentRamBankNo * 0x2000)], 32); + DebugWriteA("RAM read: Bank %02X\n", Cart->iCurrentRamBankNo); + }/* + else + { + ZeroMemory(Data, 32); + //for (i=0; i<32; i++) Data[i] = 0; + DebugWriteA("Failed RAM read: (RAM not active)\n"); + }*/ + } + else + { + ZeroMemory(Data, 32); + DebugWriteA("Failed RAM read: (RAM not present)\n"); + } + } + else + { + DebugWriteA("Bad read from MBC3 cart, address %04X\n", dwAddress); + } - return true; + return true; } // Done bool WriteCartMBC3(LPGBCART Cart, WORD dwAddress, BYTE *Data) { - int i; + int i; - if ((dwAddress >= 0x0000) && (dwAddress <= 0x1FFF)) // We shouldn't be able to read/write to RAM unless this is toggled on - { - Cart->bRamEnableState = (Data[0] == 0x0A); - DebugWriteA("Set RAM enable: %d\n", Cart->bRamEnableState); - } - else if ((dwAddress >= 0x2000) && (dwAddress <= 0x3FFF)) // ROM bank select - { - Cart->iCurrentRomBankNo = Data[0] & 0x7F; - if (Cart->iCurrentRomBankNo == 0) { - Cart->iCurrentRomBankNo = 1; - } - DebugWriteA("Set Rom Bank: %02X\n", Cart->iCurrentRomBankNo); - } - else if ((dwAddress >= 0x4000) && (dwAddress <= 0x5FFF)) // RAM/Clock bank select - { - if (Cart->bHasRam) - { - Cart->iCurrentRamBankNo = Data[0] & 0x03; - DebugWriteA("Set RAM Bank: %02X\n", Cart->iCurrentRamBankNo); - if (Cart->bHasTimer && (Data[0] >= 0x08 && Data[0] <= 0x0c)) - { - // Set the bank for the timer - Cart->iCurrentRamBankNo = Data[0]; - } - } - } - else if ((dwAddress >= 0x6000) && (dwAddress <= 0x7FFF)) // Latch timer data - { - CopyMemory(Cart->LatchedTimerData, Cart->TimerData, 5 * sizeof(Cart->TimerData[0])); - if (Data[0] & 1) - { - // Update timer, save latch values, and set latch state - UpdateRTC(Cart); - for (i = 0; i < 4; i++) - Cart->LatchedTimerData[i] = Cart->TimerData[i]; - Cart->TimerDataLatched = true; - DebugWriteA("Timer Data Latch: Enable\n"); - } - else - { - Cart->TimerDataLatched = false; - DebugWriteA("Timer Data Latch: Disable\n"); - } - } - else if ((dwAddress >= 0xA000) && (dwAddress <= 0xBFFF)) // Write to RAM - { - if (Cart->bHasRam) - { - if (Cart->iCurrentRamBankNo >= 0x08 && Cart->iCurrentRamBankNo <= 0x0c) - { - // Write to the timer - DebugWriteA("Timer write: Bank %02X\n", Cart->iCurrentRamBankNo); - Cart->TimerData[Cart->iCurrentRamBankNo - 0x08] = Data[0]; - } - else - { - DebugWriteA("RAM write: Bank %02X%s\n", Cart->iCurrentRamBankNo, Cart->bRamEnableState ? "" : " -- NOT ENABLED (but wrote anyway)"); - CopyMemory(&Cart->RamData[dwAddress - 0xA000 + (Cart->iCurrentRamBankNo * 0x2000)], Data, 32); - } - } - } - else - { - DebugWriteA("Bad write to MBC3 cart, address %04X\n", dwAddress); - } + if ((dwAddress >= 0x0000) && (dwAddress <= 0x1FFF)) // We shouldn't be able to read/write to RAM unless this is toggled on + { + Cart->bRamEnableState = (Data[0] == 0x0A); + DebugWriteA("Set RAM enable: %d\n", Cart->bRamEnableState); + } + else if ((dwAddress >= 0x2000) && (dwAddress <= 0x3FFF)) // ROM bank select + { + Cart->iCurrentRomBankNo = Data[0] & 0x7F; + if (Cart->iCurrentRomBankNo == 0) { + Cart->iCurrentRomBankNo = 1; + } + DebugWriteA("Set Rom Bank: %02X\n", Cart->iCurrentRomBankNo); + } + else if ((dwAddress >= 0x4000) && (dwAddress <= 0x5FFF)) // RAM/Clock bank select + { + if (Cart->bHasRam) + { + Cart->iCurrentRamBankNo = Data[0] & 0x03; + DebugWriteA("Set RAM Bank: %02X\n", Cart->iCurrentRamBankNo); + if (Cart->bHasTimer && (Data[0] >= 0x08 && Data[0] <= 0x0c)) + { + // Set the bank for the timer + Cart->iCurrentRamBankNo = Data[0]; + } + } + } + else if ((dwAddress >= 0x6000) && (dwAddress <= 0x7FFF)) // Latch timer data + { + CopyMemory(Cart->LatchedTimerData, Cart->TimerData, 5 * sizeof(Cart->TimerData[0])); + if (Data[0] & 1) + { + // Update timer, save latch values, and set latch state + UpdateRTC(Cart); + for (i = 0; i < 4; i++) + Cart->LatchedTimerData[i] = Cart->TimerData[i]; + Cart->TimerDataLatched = true; + DebugWriteA("Timer Data Latch: Enable\n"); + } + else + { + Cart->TimerDataLatched = false; + DebugWriteA("Timer Data Latch: Disable\n"); + } + } + else if ((dwAddress >= 0xA000) && (dwAddress <= 0xBFFF)) // Write to RAM + { + if (Cart->bHasRam) + { + if (Cart->iCurrentRamBankNo >= 0x08 && Cart->iCurrentRamBankNo <= 0x0c) + { + // Write to the timer + DebugWriteA("Timer write: Bank %02X\n", Cart->iCurrentRamBankNo); + Cart->TimerData[Cart->iCurrentRamBankNo - 0x08] = Data[0]; + } + else + { + DebugWriteA("RAM write: Bank %02X%s\n", Cart->iCurrentRamBankNo, Cart->bRamEnableState ? "" : " -- NOT ENABLED (but wrote anyway)"); + CopyMemory(&Cart->RamData[dwAddress - 0xA000 + (Cart->iCurrentRamBankNo * 0x2000)], Data, 32); + } + } + } + else + { + DebugWriteA("Bad write to MBC3 cart, address %04X\n", dwAddress); + } - return true; + return true; } // Done bool ReadCartMBC5(LPGBCART Cart, WORD dwAddress, BYTE *Data) { - if ((dwAddress < 0x4000)) //Rom Bank 0 - { - CopyMemory(Data, &Cart->RomData[dwAddress], 32); - DebugWriteA("Nonbanked ROM read - MBC5\n"); - } - else if ((dwAddress >= 0x4000) && (dwAddress < 0x8000)) //Switchable ROM BANK - { - if (Cart->iCurrentRomBankNo >= Cart->iNumRomBanks) - { - ZeroMemory(Data, 32); - DebugWriteA("Banked ROM read: (Banking Error)"); - DebugWriteByteA(Cart->iCurrentRomBankNo); - DebugWriteA("\n"); - } - else { - CopyMemory(Data, &Cart->RomData[dwAddress - 0x4000 + (Cart->iCurrentRomBankNo << 14)], 32); - DebugWriteA("Banked ROM read: Bank="); - DebugWriteByteA(Cart->iCurrentRomBankNo); - DebugWriteA("\n"); - } - } - else if ((dwAddress >= 0xA000) && (dwAddress <= 0xC000)) //Upper bounds of memory map - { - if (Cart->bHasRam) - { - if (Cart->iCurrentRamBankNo >= Cart->iNumRamBanks) - { - ZeroMemory(Data, 32); - DebugWriteA("Failed RAM read: (Banking Error) %02X\n", Cart->iCurrentRamBankNo); - } - else - { - CopyMemory(Data, &Cart->RamData[dwAddress - 0xA000 + (Cart->iCurrentRamBankNo << 13)], 32); - DebugWriteA("RAM read: Bank %02X\n", Cart->iCurrentRamBankNo); - } - } - else - { - ZeroMemory(Data, 32); - DebugWriteA("Failed RAM read: (RAM Not Present)\n"); - } - } - else - { - DebugWriteA("Bad read from MBC5 cart, address %04X\n", dwAddress); - } + if ((dwAddress < 0x4000)) //Rom Bank 0 + { + CopyMemory(Data, &Cart->RomData[dwAddress], 32); + DebugWriteA("Nonbanked ROM read - MBC5\n"); + } + else if ((dwAddress >= 0x4000) && (dwAddress < 0x8000)) //Switchable ROM BANK + { + if (Cart->iCurrentRomBankNo >= Cart->iNumRomBanks) + { + ZeroMemory(Data, 32); + DebugWriteA("Banked ROM read: (Banking Error)"); + DebugWriteByteA(Cart->iCurrentRomBankNo); + DebugWriteA("\n"); + } + else { + CopyMemory(Data, &Cart->RomData[dwAddress - 0x4000 + (Cart->iCurrentRomBankNo << 14)], 32); + DebugWriteA("Banked ROM read: Bank="); + DebugWriteByteA(Cart->iCurrentRomBankNo); + DebugWriteA("\n"); + } + } + else if ((dwAddress >= 0xA000) && (dwAddress <= 0xC000)) //Upper bounds of memory map + { + if (Cart->bHasRam) + { + if (Cart->iCurrentRamBankNo >= Cart->iNumRamBanks) + { + ZeroMemory(Data, 32); + DebugWriteA("Failed RAM read: (Banking Error) %02X\n", Cart->iCurrentRamBankNo); + } + else + { + CopyMemory(Data, &Cart->RamData[dwAddress - 0xA000 + (Cart->iCurrentRamBankNo << 13)], 32); + DebugWriteA("RAM read: Bank %02X\n", Cart->iCurrentRamBankNo); + } + } + else + { + ZeroMemory(Data, 32); + DebugWriteA("Failed RAM read: (RAM Not Present)\n"); + } + } + else + { + DebugWriteA("Bad read from MBC5 cart, address %04X\n", dwAddress); + } - return true; + return true; } // Done bool WriteCartMBC5(LPGBCART Cart, WORD dwAddress, BYTE *Data) { - if ((dwAddress >= 0x0000) && (dwAddress <= 0x1FFF)) // We shouldn't be able to read/write to RAM unless this is toggled on - { - Cart->bRamEnableState = (Data[0] == 0x0A); - DebugWriteA("Set RAM enable: %d\n", Cart->bRamEnableState); - } - else if ((dwAddress >= 0x2000) && (dwAddress <= 0x2FFF)) // ROM bank select, low bits - { - Cart->iCurrentRomBankNo &= 0xFF00; - Cart->iCurrentRomBankNo |= Data[0]; - // Cart->iCurrentRomBankNo = ((int) Data[0]) | (Cart->iCurrentRomBankNo & 0x100); - DebugWriteA("Set ROM Bank: %02X\n", Cart->iCurrentRomBankNo); - } - else if ((dwAddress >= 0x3000) && (dwAddress <= 0x3FFF)) // ROM bank select, high bit - { - Cart->iCurrentRomBankNo &= 0x00FF; - Cart->iCurrentRomBankNo |= (Data[0] & 0x01) << 8; - // Cart->iCurrentRomBankNo = (Cart->iCurrentRomBankNo & 0xFF) | ((((int) Data[0]) & 1) * 0x100); - DebugWriteA("Set ROM Bank: %02X\n", Cart->iCurrentRomBankNo); - } - else if ((dwAddress >= 0x4000) && (dwAddress <= 0x5FFF)) // RAM bank select - { - if (Cart->bHasRam) - { - Cart->iCurrentRamBankNo = Data[0] & 0x0F; - DebugWriteA("Set RAM Bank: %02X\n", Cart->iCurrentRamBankNo); - } - } - else if ((dwAddress >= 0xA000) && (dwAddress <= 0xBFFF)) // Write to RAM - { - if (Cart->bHasRam) - { - if (Cart->iCurrentRamBankNo >= Cart->iNumRamBanks) - { - DebugWriteA("RAM write: Buffer error on "); - DebugWriteByteA(Cart->iCurrentRamBankNo); - DebugWriteA("\n"); - } - else - { - DebugWriteA("RAM write: Bank %02X\n", Cart->iCurrentRamBankNo); - CopyMemory(&Cart->RamData[dwAddress - 0xA000 + (Cart->iCurrentRamBankNo << 13)], Data, 32); - } - } - } - else - { - DebugWriteA("Bad write to MBC5 cart, address %04X\n", dwAddress); - } + if ((dwAddress >= 0x0000) && (dwAddress <= 0x1FFF)) // We shouldn't be able to read/write to RAM unless this is toggled on + { + Cart->bRamEnableState = (Data[0] == 0x0A); + DebugWriteA("Set RAM enable: %d\n", Cart->bRamEnableState); + } + else if ((dwAddress >= 0x2000) && (dwAddress <= 0x2FFF)) // ROM bank select, low bits + { + Cart->iCurrentRomBankNo &= 0xFF00; + Cart->iCurrentRomBankNo |= Data[0]; + // Cart->iCurrentRomBankNo = ((int) Data[0]) | (Cart->iCurrentRomBankNo & 0x100); + DebugWriteA("Set ROM Bank: %02X\n", Cart->iCurrentRomBankNo); + } + else if ((dwAddress >= 0x3000) && (dwAddress <= 0x3FFF)) // ROM bank select, high bit + { + Cart->iCurrentRomBankNo &= 0x00FF; + Cart->iCurrentRomBankNo |= (Data[0] & 0x01) << 8; + // Cart->iCurrentRomBankNo = (Cart->iCurrentRomBankNo & 0xFF) | ((((int) Data[0]) & 1) * 0x100); + DebugWriteA("Set ROM Bank: %02X\n", Cart->iCurrentRomBankNo); + } + else if ((dwAddress >= 0x4000) && (dwAddress <= 0x5FFF)) // RAM bank select + { + if (Cart->bHasRam) + { + Cart->iCurrentRamBankNo = Data[0] & 0x0F; + DebugWriteA("Set RAM Bank: %02X\n", Cart->iCurrentRamBankNo); + } + } + else if ((dwAddress >= 0xA000) && (dwAddress <= 0xBFFF)) // Write to RAM + { + if (Cart->bHasRam) + { + if (Cart->iCurrentRamBankNo >= Cart->iNumRamBanks) + { + DebugWriteA("RAM write: Buffer error on "); + DebugWriteByteA(Cart->iCurrentRamBankNo); + DebugWriteA("\n"); + } + else + { + DebugWriteA("RAM write: Bank %02X\n", Cart->iCurrentRamBankNo); + CopyMemory(&Cart->RamData[dwAddress - 0xA000 + (Cart->iCurrentRamBankNo << 13)], Data, 32); + } + } + } + else + { + DebugWriteA("Bad write to MBC5 cart, address %04X\n", dwAddress); + } - return true; + return true; } // Done bool ReadCartCamera(LPGBCART Cart, WORD dwAddress, BYTE *Data) { - if ((dwAddress < 0x4000)) //Rom Bank 0 - { - CopyMemory(Data, &Cart->RomData[dwAddress], 32); - DebugWriteA("Nonbanked ROM read - CAMERA\n"); - } - else if ((dwAddress >= 0x4000) && (dwAddress < 0x8000)) //Switchable ROM BANK - { - if (Cart->iCurrentRomBankNo >= Cart->iNumRomBanks) - { - ZeroMemory(Data, 32); - DebugWriteA("Banked ROM read: (Banking Error)"); - DebugWriteByteA(Cart->iCurrentRomBankNo); - DebugWriteA("\n"); - } - else { - CopyMemory(Data, &Cart->RomData[dwAddress - 0x4000 + (Cart->iCurrentRomBankNo << 14)], 32); - DebugWriteA("Banked ROM read: Bank="); - DebugWriteByteA(Cart->iCurrentRomBankNo); - DebugWriteA("\n"); - } - } - else if ((dwAddress >= 0xA000) && (dwAddress <= 0xC000)) //Upper bounds of memory map - { - if (Cart->iCurrentRamBankNo & 0x10) - { - //REGISTER MODE - ZeroMemory(Data, 32); - DebugWriteA("REGISTER read (Camera): All Zero\n", Cart->iCurrentRamBankNo); - } - else - { - //RAM MODE - if (Cart->bHasRam) - { - if (Cart->iCurrentRamBankNo >= Cart->iNumRamBanks) - { - ZeroMemory(Data, 32); - DebugWriteA("Failed RAM read: (Banking Error) %02X\n", Cart->iCurrentRamBankNo); - } - else - { - CopyMemory(Data, &Cart->RamData[dwAddress - 0xA000 + (Cart->iCurrentRamBankNo << 13)], 32); - DebugWriteA("RAM read: Bank %02X\n", Cart->iCurrentRamBankNo); - } - } - else - { - ZeroMemory(Data, 32); - DebugWriteA("Failed RAM read: (RAM Not Present)\n"); - } - } - } - else - { - DebugWriteA("Bad read from GBCamera cart, address %04X\n", dwAddress); - } + if ((dwAddress < 0x4000)) //Rom Bank 0 + { + CopyMemory(Data, &Cart->RomData[dwAddress], 32); + DebugWriteA("Nonbanked ROM read - CAMERA\n"); + } + else if ((dwAddress >= 0x4000) && (dwAddress < 0x8000)) //Switchable ROM BANK + { + if (Cart->iCurrentRomBankNo >= Cart->iNumRomBanks) + { + ZeroMemory(Data, 32); + DebugWriteA("Banked ROM read: (Banking Error)"); + DebugWriteByteA(Cart->iCurrentRomBankNo); + DebugWriteA("\n"); + } + else { + CopyMemory(Data, &Cart->RomData[dwAddress - 0x4000 + (Cart->iCurrentRomBankNo << 14)], 32); + DebugWriteA("Banked ROM read: Bank="); + DebugWriteByteA(Cart->iCurrentRomBankNo); + DebugWriteA("\n"); + } + } + else if ((dwAddress >= 0xA000) && (dwAddress <= 0xC000)) //Upper bounds of memory map + { + if (Cart->iCurrentRamBankNo & 0x10) + { + //REGISTER MODE + ZeroMemory(Data, 32); + DebugWriteA("REGISTER read (Camera): All Zero\n", Cart->iCurrentRamBankNo); + } + else + { + //RAM MODE + if (Cart->bHasRam) + { + if (Cart->iCurrentRamBankNo >= Cart->iNumRamBanks) + { + ZeroMemory(Data, 32); + DebugWriteA("Failed RAM read: (Banking Error) %02X\n", Cart->iCurrentRamBankNo); + } + else + { + CopyMemory(Data, &Cart->RamData[dwAddress - 0xA000 + (Cart->iCurrentRamBankNo << 13)], 32); + DebugWriteA("RAM read: Bank %02X\n", Cart->iCurrentRamBankNo); + } + } + else + { + ZeroMemory(Data, 32); + DebugWriteA("Failed RAM read: (RAM Not Present)\n"); + } + } + } + else + { + DebugWriteA("Bad read from GBCamera cart, address %04X\n", dwAddress); + } - return true; + return true; } //Done bool WriteCartCamera(LPGBCART Cart, WORD dwAddress, BYTE *Data) { - if ((dwAddress >= 0x0000) && (dwAddress <= 0x1FFF)) // We shouldn't be able to read/write to RAM unless this is toggled on - { - Cart->bRamEnableState = (Data[0] == 0x0A); - DebugWriteA("Set RAM enable: %d\n", Cart->bRamEnableState); - } - else if ((dwAddress >= 0x2000) && (dwAddress <= 0x2FFF)) // ROM bank select, low bits - { - Cart->iCurrentRomBankNo &= 0xFF00; - Cart->iCurrentRomBankNo |= Data[0]; - // Cart->iCurrentRomBankNo = ((int) Data[0]) | (Cart->iCurrentRomBankNo & 0x100); - DebugWriteA("Set ROM Bank: %02X\n", Cart->iCurrentRomBankNo); - } - else if ((dwAddress >= 0x4000) && (dwAddress <= 0x4FFF)) // Camera Register & RAM bank select - { - if (Data[0] & 0x10) - { - //REGISTER MODE - Cart->iCurrentRamBankNo = Data[0]; - DebugWriteA("Set Register Bank (Camera): %02X\n", Cart->iCurrentRamBankNo); - } - else - { - //RAM MODE - if (Cart->bHasRam) - { - Cart->iCurrentRamBankNo = Data[0] & 0x0F; - DebugWriteA("Set RAM Bank: %02X\n", Cart->iCurrentRamBankNo); - } - } - } - else if ((dwAddress >= 0xA000) && (dwAddress <= 0xBFFF)) // Write to RAM - { - if (Cart->iCurrentRamBankNo & 0x10) - { - //REGISTER MODE (DO NOTHING) - DebugWriteA("REGISTER write (Camera): Do nothing\n"); - } - else - { - //RAM MODE - if (Cart->bHasRam) - { - if (Cart->iCurrentRamBankNo >= Cart->iNumRamBanks) - { - DebugWriteA("RAM write: Buffer error on "); - DebugWriteByteA(Cart->iCurrentRamBankNo); - DebugWriteA("\n"); - } - else - { - DebugWriteA("RAM write: Bank %02X\n", Cart->iCurrentRamBankNo); - CopyMemory(&Cart->RamData[dwAddress - 0xA000 + (Cart->iCurrentRamBankNo << 13)], Data, 32); - } - } - } - } - else - { - DebugWriteA("Bad write to GBCamera cart, address %04X\n", dwAddress); - } + if ((dwAddress >= 0x0000) && (dwAddress <= 0x1FFF)) // We shouldn't be able to read/write to RAM unless this is toggled on + { + Cart->bRamEnableState = (Data[0] == 0x0A); + DebugWriteA("Set RAM enable: %d\n", Cart->bRamEnableState); + } + else if ((dwAddress >= 0x2000) && (dwAddress <= 0x2FFF)) // ROM bank select, low bits + { + Cart->iCurrentRomBankNo &= 0xFF00; + Cart->iCurrentRomBankNo |= Data[0]; + // Cart->iCurrentRomBankNo = ((int) Data[0]) | (Cart->iCurrentRomBankNo & 0x100); + DebugWriteA("Set ROM Bank: %02X\n", Cart->iCurrentRomBankNo); + } + else if ((dwAddress >= 0x4000) && (dwAddress <= 0x4FFF)) // Camera Register & RAM bank select + { + if (Data[0] & 0x10) + { + //REGISTER MODE + Cart->iCurrentRamBankNo = Data[0]; + DebugWriteA("Set Register Bank (Camera): %02X\n", Cart->iCurrentRamBankNo); + } + else + { + //RAM MODE + if (Cart->bHasRam) + { + Cart->iCurrentRamBankNo = Data[0] & 0x0F; + DebugWriteA("Set RAM Bank: %02X\n", Cart->iCurrentRamBankNo); + } + } + } + else if ((dwAddress >= 0xA000) && (dwAddress <= 0xBFFF)) // Write to RAM + { + if (Cart->iCurrentRamBankNo & 0x10) + { + //REGISTER MODE (DO NOTHING) + DebugWriteA("REGISTER write (Camera): Do nothing\n"); + } + else + { + //RAM MODE + if (Cart->bHasRam) + { + if (Cart->iCurrentRamBankNo >= Cart->iNumRamBanks) + { + DebugWriteA("RAM write: Buffer error on "); + DebugWriteByteA(Cart->iCurrentRamBankNo); + DebugWriteA("\n"); + } + else + { + DebugWriteA("RAM write: Bank %02X\n", Cart->iCurrentRamBankNo); + CopyMemory(&Cart->RamData[dwAddress - 0xA000 + (Cart->iCurrentRamBankNo << 13)], Data, 32); + } + } + } + } + else + { + DebugWriteA("Bad write to GBCamera cart, address %04X\n", dwAddress); + } - return true; + return true; } bool SaveCart(LPGBCART Cart, LPTSTR SaveFile, LPTSTR TimeFile) { - DWORD NumQuarterBlocks = 0; - gbCartRTC RTCTimer; + DWORD NumQuarterBlocks = 0; + gbCartRTC RTCTimer; - if (Cart->bHasRam && Cart->bHasBattery) - { // Write only the bytes that NEED writing! - switch (Cart->RomData[0x149]) - { - case 1: - NumQuarterBlocks = 1; - break; - case 2: - NumQuarterBlocks = 4; - break; - case 3: - NumQuarterBlocks = 16; - break; - case 4: - NumQuarterBlocks = 64; - break; - } - FlushViewOfFile( Cart->RamData, NumQuarterBlocks * 0x0800 ); - if (Cart->bHasTimer) - { - // Save RTC in VisualBoy Advance format - // TODO: Check if VBA saves are compatible with other emus. - // TODO: Only write RTC data if VBA RTC data was originaly present - RTCTimer.mapperSeconds = Cart->TimerData[0]; - RTCTimer.mapperMinutes = Cart->TimerData[1]; - RTCTimer.mapperHours = Cart->TimerData[2]; - RTCTimer.mapperDays = Cart->TimerData[3]; - RTCTimer.mapperControl = Cart->TimerData[4]; - RTCTimer.mapperLSeconds = Cart->LatchedTimerData[0]; - RTCTimer.mapperLMinutes = Cart->LatchedTimerData[1]; - RTCTimer.mapperLHours = Cart->LatchedTimerData[2]; - RTCTimer.mapperLDays = Cart->LatchedTimerData[3]; - RTCTimer.mapperLControl = Cart->LatchedTimerData[4]; - RTCTimer.mapperLastTime = Cart->timerLastUpdate; + if (Cart->bHasRam && Cart->bHasBattery) + { // Write only the bytes that NEED writing! + switch (Cart->RomData[0x149]) + { + case 1: + NumQuarterBlocks = 1; + break; + case 2: + NumQuarterBlocks = 4; + break; + case 3: + NumQuarterBlocks = 16; + break; + case 4: + NumQuarterBlocks = 64; + break; + } + FlushViewOfFile( Cart->RamData, NumQuarterBlocks * 0x0800 ); + if (Cart->bHasTimer) + { + // Save RTC in VisualBoy Advance format + // TODO: Check if VBA saves are compatible with other emus. + // TODO: Only write RTC data if VBA RTC data was originaly present + RTCTimer.mapperSeconds = Cart->TimerData[0]; + RTCTimer.mapperMinutes = Cart->TimerData[1]; + RTCTimer.mapperHours = Cart->TimerData[2]; + RTCTimer.mapperDays = Cart->TimerData[3]; + RTCTimer.mapperControl = Cart->TimerData[4]; + RTCTimer.mapperLSeconds = Cart->LatchedTimerData[0]; + RTCTimer.mapperLMinutes = Cart->LatchedTimerData[1]; + RTCTimer.mapperLHours = Cart->LatchedTimerData[2]; + RTCTimer.mapperLDays = Cart->LatchedTimerData[3]; + RTCTimer.mapperLControl = Cart->LatchedTimerData[4]; + RTCTimer.mapperLastTime = Cart->timerLastUpdate; - CopyMemory(Cart->RamData + NumQuarterBlocks * 0x0800, &RTCTimer, sizeof(RTCTimer)); - FlushViewOfFile(Cart->RamData + NumQuarterBlocks * 0x0800, sizeof(gbCartRTC)); - } - } - return true; + CopyMemory(Cart->RamData + NumQuarterBlocks * 0x0800, &RTCTimer, sizeof(RTCTimer)); + FlushViewOfFile(Cart->RamData + NumQuarterBlocks * 0x0800, sizeof(gbCartRTC)); + } + } + return true; } bool UnloadCart(LPGBCART Cart) { - if (Cart->hRomFile != NULL) - { - UnmapViewOfFile(Cart->RomData); - CloseHandle(Cart->hRomFile); - Cart->hRomFile = NULL; - } - else if (Cart->RomData != NULL) - { - P_free((LPVOID)(Cart->RomData)); - Cart->RomData = NULL; - } + if (Cart->hRomFile != NULL) + { + UnmapViewOfFile(Cart->RomData); + CloseHandle(Cart->hRomFile); + Cart->hRomFile = NULL; + } + else if (Cart->RomData != NULL) + { + P_free((LPVOID)(Cart->RomData)); + Cart->RomData = NULL; + } - if (Cart->hRamFile != NULL) - { - UnmapViewOfFile(Cart->RamData); - CloseHandle(Cart->hRamFile); - Cart->hRamFile = NULL; - } - else if (Cart->RamData != NULL) - { - P_free(Cart->RamData); - Cart->RamData = NULL; - } - return true; + if (Cart->hRamFile != NULL) + { + UnmapViewOfFile(Cart->RamData); + CloseHandle(Cart->hRamFile); + Cart->hRamFile = NULL; + } + else if (Cart->RamData != NULL) + { + P_free(Cart->RamData); + Cart->RamData = NULL; + } + return true; } // This is used to clear the RAM data to look like it has just been turned on. @@ -1266,17 +1266,17 @@ bool UnloadCart(LPGBCART Cart) // blocks of 0x00 and 0xFF. void ClearData(BYTE *Data, int Length) { - int i; + int i; - for (i = 0; i < Length; i++) - { - if ((i & 0x80) != 0x80) - { - Data[i] = 0x00; - } - else - { - Data[i] = 0xFF; - } - } + for (i = 0; i < Length; i++) + { + if ((i & 0x80) != 0x80) + { + Data[i] = 0x00; + } + else + { + Data[i] = 0xFF; + } + } } diff --git a/Source/nragev20/GBCart.h b/Source/nragev20/GBCart.h index 543bc757e..91d14de65 100644 --- a/Source/nragev20/GBCart.h +++ b/Source/nragev20/GBCart.h @@ -21,27 +21,27 @@ typedef struct _gbCartRTC { typedef struct _GBCART { - unsigned int iCurrentRomBankNo; - unsigned int iCurrentRamBankNo; - int iCartType; - bool bHasRam; - bool bHasBattery; - bool bHasTimer; - bool bHasRumble; - bool bRamEnableState; - bool bMBC1RAMbanking; // if false, use 2 magic bits for Most Significant Bits of ROM banking (default); if true, use the 2 magic bits for RAM banking - unsigned int iNumRomBanks; - unsigned int iNumRamBanks; - BYTE TimerData[5]; - BYTE LatchedTimerData[5]; - time_t timerLastUpdate; - bool TimerDataLatched; - HANDLE hRomFile; // a file mapping handle - HANDLE hRamFile; // a file mapping handle, must be NULL if malloc'd ram is being used instead of a valid memory mapped file - const unsigned char * RomData; // max [0x200 * 0x4000]; - LPBYTE RamData; // max [0x10 * 0x2000]; - bool (*ptrfnReadCart)(_GBCART * Cart, WORD dwAddress, BYTE *Data); // ReadCart handler - bool (*ptrfnWriteCart)(_GBCART * Cart, WORD dwAddress, BYTE *Data); // WriteCart handler + unsigned int iCurrentRomBankNo; + unsigned int iCurrentRamBankNo; + int iCartType; + bool bHasRam; + bool bHasBattery; + bool bHasTimer; + bool bHasRumble; + bool bRamEnableState; + bool bMBC1RAMbanking; // if false, use 2 magic bits for Most Significant Bits of ROM banking (default); if true, use the 2 magic bits for RAM banking + unsigned int iNumRomBanks; + unsigned int iNumRamBanks; + BYTE TimerData[5]; + BYTE LatchedTimerData[5]; + time_t timerLastUpdate; + bool TimerDataLatched; + HANDLE hRomFile; // a file mapping handle + HANDLE hRamFile; // a file mapping handle, must be NULL if malloc'd ram is being used instead of a valid memory mapped file + const unsigned char * RomData; // max [0x200 * 0x4000]; + LPBYTE RamData; // max [0x10 * 0x2000]; + bool (*ptrfnReadCart)(_GBCART * Cart, WORD dwAddress, BYTE *Data); // ReadCart handler + bool (*ptrfnWriteCart)(_GBCART * Cart, WORD dwAddress, BYTE *Data); // WriteCart handler } GBCART, *LPGBCART; bool LoadCart(LPGBCART Cart, LPCTSTR RomFile, LPCTSTR RamFile, LPCTSTR TdfFile); @@ -65,15 +65,15 @@ iCartType values: Note, that 7 and up are not implemented yet. */ -#define GB_NORM 0x00 -#define GB_MBC1 0x01 -#define GB_MBC2 0x02 -#define GB_MMMO1 0x03 -#define GB_MBC3 0x04 -#define GB_MBC5 0x05 -#define GB_CAMERA 0x06 -#define GB_TAMA5 0x07 -#define GB_HUC3 0x08 -#define GB_HUC1 0x09 +#define GB_NORM 0x00 +#define GB_MBC1 0x01 +#define GB_MBC2 0x02 +#define GB_MMMO1 0x03 +#define GB_MBC3 0x04 +#define GB_MBC5 0x05 +#define GB_CAMERA 0x06 +#define GB_TAMA5 0x07 +#define GB_HUC3 0x08 +#define GB_HUC1 0x09 #endif // #ifndef _GBCART_H_ diff --git a/Source/nragev20/Interface.cpp b/Source/nragev20/Interface.cpp index ac8e82572..2a3ead60a 100644 --- a/Source/nragev20/Interface.cpp +++ b/Source/nragev20/Interface.cpp @@ -1,9 +1,9 @@ /* - N-Rage`s Dinput8 Plugin + N-Rage`s Dinput8 Plugin (C) 2002, 2006 Norbert Wladyka - Author`s Email: norbert.wladyka@chello.at - Website: http://go.to/nrage + Author`s Email: norbert.wladyka@chello.at + Website: http://go.to/nrage This program is free software; you can redistribute it and/or modify @@ -39,7 +39,7 @@ // Prototypes // BOOL CALLBACK ControllerTabProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ); BOOL CALLBACK ControlsTabProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ); -BOOL CALLBACK XControlsTabProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ); // Xinput Control main proc. --tecnicors +BOOL CALLBACK XControlsTabProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ); // Xinput Control main proc. --tecnicors BOOL CALLBACK DevicesTabProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ); BOOL CALLBACK ModifierTabProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ); BOOL CALLBACK ControllerPakTabProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ); @@ -63,3257 +63,3257 @@ void GetCurrentConfiguration(); void UpdateControllerStructures(); // global Variables // -INTERFACEVALUES *g_ivConfig = NULL; // this structure holds all GUI-Data; it points to a valid struct only if the config window is open -LPDIRECTINPUTDEVICE8 g_pConfigDevice = NULL; // one device handle for current FF device; between messages so it needs to be persistent -LPDIRECTINPUTEFFECT g_pConfigEffect = NULL; // FF-effect handle -HWND g_hMainDialog = NULL; // handle of base-dialog +INTERFACEVALUES *g_ivConfig = NULL; // this structure holds all GUI-Data; it points to a valid struct only if the config window is open +LPDIRECTINPUTDEVICE8 g_pConfigDevice = NULL; // one device handle for current FF device; between messages so it needs to be persistent +LPDIRECTINPUTEFFECT g_pConfigEffect = NULL; // FF-effect handle +HWND g_hMainDialog = NULL; // handle of base-dialog // Main dialog control handler BOOL CALLBACK MainDlgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) { - static HWND hTabControl; - HWND hDlgItem; - long i,j; + static HWND hTabControl; + HWND hDlgItem; + long i,j; - switch(uMsg) - { - case WM_INITDIALOG: - { - DebugWriteA("Config interface: Open\n"); - g_ivConfig = (INTERFACEVALUES*)P_malloc( sizeof(INTERFACEVALUES) ); // TODO: CHECK THIS MALLOC! - ZeroMemory( g_ivConfig, sizeof(INTERFACEVALUES) ); + switch(uMsg) + { + case WM_INITDIALOG: + { + DebugWriteA("Config interface: Open\n"); + g_ivConfig = (INTERFACEVALUES*)P_malloc( sizeof(INTERFACEVALUES) ); // TODO: CHECK THIS MALLOC! + ZeroMemory( g_ivConfig, sizeof(INTERFACEVALUES) ); - CopyMemory( &g_ivConfig->Shortcuts, &g_scShortcuts ,sizeof(SHORTCUTS) ); - for( i = 0; i < 4; ++i ) - DeleteControllerSettings( i ); + CopyMemory( &g_ivConfig->Shortcuts, &g_scShortcuts ,sizeof(SHORTCUTS) ); + for( i = 0; i < 4; ++i ) + DeleteControllerSettings( i ); - EnterCriticalSection( &g_critical ); // block because the InitiateControllers code may still be running. - if( !g_strEmuInfo.fInitialisedPlugin ) - { - LoadConfigFromINI(); - } + EnterCriticalSection( &g_critical ); // block because the InitiateControllers code may still be running. + if( !g_strEmuInfo.fInitialisedPlugin ) + { + LoadConfigFromINI(); + } - GetCurrentConfiguration(); + GetCurrentConfiguration(); - LeaveCriticalSection( &g_critical ); + LeaveCriticalSection( &g_critical ); - g_hMainDialog = hDlg; + g_hMainDialog = hDlg; - // Display Version - { - TCHAR tszBuffer[DEFAULT_BUFFER], tszMsg[DEFAULT_BUFFER / 2]; + // Display Version + { + TCHAR tszBuffer[DEFAULT_BUFFER], tszMsg[DEFAULT_BUFFER / 2]; - LoadString( g_hResourceDLL, IDS_VERSTRING, tszBuffer, DEFAULT_BUFFER / 2); - _stprintf(tszMsg, tszBuffer, VER_FILE_VERSION_STR); - SetDlgItemText( hDlg, IDC_VERSIONSTRING, tszMsg ); - } + LoadString( g_hResourceDLL, IDS_VERSTRING, tszBuffer, DEFAULT_BUFFER / 2); + _stprintf(tszMsg, tszBuffer, VER_FILE_VERSION_STR); + SetDlgItemText( hDlg, IDC_VERSIONSTRING, tszMsg ); + } - // Tab - Control // - hTabControl = NULL; - hDlgItem = GetDlgItem( hDlg, IDC_UPPERTAB ); + // Tab - Control // + hTabControl = NULL; + hDlgItem = GetDlgItem( hDlg, IDC_UPPERTAB ); - TCITEM tcItem; - tcItem.mask = TCIF_TEXT; + TCITEM tcItem; + tcItem.mask = TCIF_TEXT; - TCHAR tszText[DEFAULT_BUFFER], tszBuff[DEFAULT_BUFFER]; - tcItem.pszText = tszText; + TCHAR tszText[DEFAULT_BUFFER], tszBuff[DEFAULT_BUFFER]; + tcItem.pszText = tszText; - LoadString( g_hResourceDLL, IDS_TAB_CONTROLLER, tszBuff, DEFAULT_BUFFER ); + LoadString( g_hResourceDLL, IDS_TAB_CONTROLLER, tszBuff, DEFAULT_BUFFER ); - for (int i = 0; i < 4; i++ ) - { - wsprintf( tszText, tszBuff, i + 1 ); - TabCtrl_InsertItem( hDlgItem, i, &tcItem ); - } + for (int i = 0; i < 4; i++ ) + { + wsprintf( tszText, tszBuff, i + 1 ); + TabCtrl_InsertItem( hDlgItem, i, &tcItem ); + } - LoadString( g_hResourceDLL, IDS_TAB_SHORTCUTS, tszText, DEFAULT_BUFFER ); - TabCtrl_InsertItem( hDlgItem, TAB_SHORTCUTS, &tcItem ); - // Tab - Control End // + LoadString( g_hResourceDLL, IDS_TAB_SHORTCUTS, tszText, DEFAULT_BUFFER ); + TabCtrl_InsertItem( hDlgItem, TAB_SHORTCUTS, &tcItem ); + // Tab - Control End // - g_ivConfig->ChosenTab = TAB_CONTROLLER1; - TabCtrl_SetCurSel( GetDlgItem( hDlg, IDC_UPPERTAB), g_ivConfig->ChosenTab ); - NMHDR nmInit; - nmInit.hwndFrom = hDlgItem; - nmInit.idFrom = IDC_UPPERTAB; - nmInit.code = TCN_SELCHANGE; - MainDlgProc( hDlg, WM_NOTIFY, IDC_UPPERTAB, (LPARAM)&nmInit ); + g_ivConfig->ChosenTab = TAB_CONTROLLER1; + TabCtrl_SetCurSel( GetDlgItem( hDlg, IDC_UPPERTAB), g_ivConfig->ChosenTab ); + NMHDR nmInit; + nmInit.hwndFrom = hDlgItem; + nmInit.idFrom = IDC_UPPERTAB; + nmInit.code = TCN_SELCHANGE; + MainDlgProc( hDlg, WM_NOTIFY, IDC_UPPERTAB, (LPARAM)&nmInit ); - // we can't click "Use" without saving when not emulating, because the emu resets controls before loading a ROM - if( !g_bRunning ) - EnableWindow( GetDlgItem( hDlg, IDUSE ), FALSE ); + // we can't click "Use" without saving when not emulating, because the emu resets controls before loading a ROM + if( !g_bRunning ) + EnableWindow( GetDlgItem( hDlg, IDUSE ), FALSE ); #ifndef _UNICODE - EnableWindow( GetDlgItem( hDlg, IDC_LANGUAGE), FALSE ); + EnableWindow( GetDlgItem( hDlg, IDC_LANGUAGE), FALSE ); #endif // #ifdef _UNICODE - InitOverlay(); - } + InitOverlay(); + } - // call routine to show content( recursive call ) - MainDlgProc( hDlg, WM_USER_UPDATE, 0, 0 ); - return TRUE; // the system sets focus to one control element + // call routine to show content( recursive call ) + MainDlgProc( hDlg, WM_USER_UPDATE, 0, 0 ); + return TRUE; // the system sets focus to one control element - case WM_NOTIFY: - hDlgItem = ((LPNMHDR)lParam)->hwndFrom; - i = ((LPNMHDR)lParam)->code; - j = ((LPNMHDR)lParam)->idFrom; + case WM_NOTIFY: + hDlgItem = ((LPNMHDR)lParam)->hwndFrom; + i = ((LPNMHDR)lParam)->code; + j = ((LPNMHDR)lParam)->idFrom; - switch( j ) - { - case IDC_UPPERTAB: - if( i == TCN_SELCHANGE ) - { - i = g_ivConfig->ChosenTab; - g_ivConfig->ChosenTab = TabCtrl_GetCurSel( hDlgItem ); + switch( j ) + { + case IDC_UPPERTAB: + if( i == TCN_SELCHANGE ) + { + i = g_ivConfig->ChosenTab; + g_ivConfig->ChosenTab = TabCtrl_GetCurSel( hDlgItem ); - if( hTabControl ) - { - if( (( i == TAB_CONTROLLER1 ) || ( i == TAB_CONTROLLER2 ) || ( i == TAB_CONTROLLER3 ) || ( i == TAB_CONTROLLER4 )) && - (( g_ivConfig->ChosenTab == TAB_CONTROLLER1 ) || ( g_ivConfig->ChosenTab == TAB_CONTROLLER2 ) || ( g_ivConfig->ChosenTab == TAB_CONTROLLER3 ) || ( g_ivConfig->ChosenTab == TAB_CONTROLLER4 ))) - { - MainDlgProc( hDlg, WM_USER_UPDATE, 0, 0 ); - return TRUE; - } - else - DestroyWindow( hTabControl ); - } + if( hTabControl ) + { + if( (( i == TAB_CONTROLLER1 ) || ( i == TAB_CONTROLLER2 ) || ( i == TAB_CONTROLLER3 ) || ( i == TAB_CONTROLLER4 )) && + (( g_ivConfig->ChosenTab == TAB_CONTROLLER1 ) || ( g_ivConfig->ChosenTab == TAB_CONTROLLER2 ) || ( g_ivConfig->ChosenTab == TAB_CONTROLLER3 ) || ( g_ivConfig->ChosenTab == TAB_CONTROLLER4 ))) + { + MainDlgProc( hDlg, WM_USER_UPDATE, 0, 0 ); + return TRUE; + } + else + DestroyWindow( hTabControl ); + } - switch( g_ivConfig->ChosenTab ) - { - case TAB_CONTROLLER1: - case TAB_CONTROLLER2: - case TAB_CONTROLLER3: - case TAB_CONTROLLER4: - hTabControl = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_CONTROLLER), hDlg, (DLGPROC)ControllerTabProc); - break; - case TAB_SHORTCUTS: - hTabControl = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_SHORTCUT), hDlg, (DLGPROC)ShortcutsTabProc); - break; - default: - hTabControl = NULL; - return TRUE; - } + switch( g_ivConfig->ChosenTab ) + { + case TAB_CONTROLLER1: + case TAB_CONTROLLER2: + case TAB_CONTROLLER3: + case TAB_CONTROLLER4: + hTabControl = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_CONTROLLER), hDlg, (DLGPROC)ControllerTabProc); + break; + case TAB_SHORTCUTS: + hTabControl = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_SHORTCUT), hDlg, (DLGPROC)ShortcutsTabProc); + break; + default: + hTabControl = NULL; + return TRUE; + } - RECT rectWindow, - rectTab, rectMain; // need to know the position of the calling tab window relative to its parent + RECT rectWindow, + rectTab, rectMain; // need to know the position of the calling tab window relative to its parent - GetWindowRect( hDlg, &rectMain ); - GetWindowRect( hDlgItem, &rectTab ); + GetWindowRect( hDlg, &rectMain ); + GetWindowRect( hDlgItem, &rectTab ); - GetClientRect( hDlgItem, &rectWindow ); - TabCtrl_AdjustRect( hDlgItem, FALSE, &rectWindow ); + GetClientRect( hDlgItem, &rectWindow ); + TabCtrl_AdjustRect( hDlgItem, FALSE, &rectWindow ); - // second, third param: plus Tabwindow's position relative to main - MoveWindow( hTabControl, (rectTab.left - rectMain.left), (rectTab.top - rectMain.top), rectWindow.right - rectWindow.left, rectWindow.bottom - rectWindow.top, FALSE ); - ShowWindow( hTabControl, SW_SHOW ); - } - return TRUE; - default: - return FALSE; - } + // second, third param: plus Tabwindow's position relative to main + MoveWindow( hTabControl, (rectTab.left - rectMain.left), (rectTab.top - rectMain.top), rectWindow.right - rectWindow.left, rectWindow.bottom - rectWindow.top, FALSE ); + ShowWindow( hTabControl, SW_SHOW ); + } + return TRUE; + default: + return FALSE; + } - case WM_COMMAND: - hDlgItem = GetDlgItem( hDlg, LOWORD(wParam) ); + case WM_COMMAND: + hDlgItem = GetDlgItem( hDlg, LOWORD(wParam) ); - switch( LOWORD(wParam) ) - { - case IDSAVE: - if( hTabControl ) - { - DestroyWindow( hTabControl ); - hTabControl = NULL; - } - DebugWriteA("Config interface: Save\n"); - StoreConfigToINI(); - // NO BREAK-- this is intentional - case IDUSE: - if( hTabControl ) - { - DestroyWindow( hTabControl ); - hTabControl = NULL; - } - DebugWriteA("Config interface: Use\n"); - CopyMemory( &g_scShortcuts ,&g_ivConfig->Shortcuts, sizeof(SHORTCUTS) ); + switch( LOWORD(wParam) ) + { + case IDSAVE: + if( hTabControl ) + { + DestroyWindow( hTabControl ); + hTabControl = NULL; + } + DebugWriteA("Config interface: Save\n"); + StoreConfigToINI(); + // NO BREAK-- this is intentional + case IDUSE: + if( hTabControl ) + { + DestroyWindow( hTabControl ); + hTabControl = NULL; + } + DebugWriteA("Config interface: Use\n"); + CopyMemory( &g_scShortcuts ,&g_ivConfig->Shortcuts, sizeof(SHORTCUTS) ); - UpdateControllerStructures(); + UpdateControllerStructures(); - EndDialog( hDlg, TRUE ); - return TRUE; - case IDCANCEL: - if( hTabControl ) - { - DestroyWindow( hTabControl ); - hTabControl = NULL; - } - EndDialog( hDlg, FALSE ); - return TRUE; + EndDialog( hDlg, TRUE ); + return TRUE; + case IDCANCEL: + if( hTabControl ) + { + DestroyWindow( hTabControl ); + hTabControl = NULL; + } + EndDialog( hDlg, FALSE ); + return TRUE; - case IDC_LANGUAGE: - if( HIWORD(wParam) == CBN_SELCHANGE ) - { - i = SendMessage( hDlgItem, CB_GETCURSEL, 0, 0 ); - g_ivConfig->Language = (LANGID) SendMessage( hDlgItem, CB_GETITEMDATA, i, 0 ); - } - return TRUE; + case IDC_LANGUAGE: + if( HIWORD(wParam) == CBN_SELCHANGE ) + { + i = SendMessage( hDlgItem, CB_GETCURSEL, 0, 0 ); + g_ivConfig->Language = (LANGID) SendMessage( hDlgItem, CB_GETITEMDATA, i, 0 ); + } + return TRUE; - case IDC_STOREINDB: - case IDC_UPDATEDB: - case IDC_ERASEFROMDB: - case IDC_SAVEPROFILE: - case IDC_LOADPROFILE: - // we don't have handlers for these, so fall through to FALSE - default: - return FALSE; - } + case IDC_STOREINDB: + case IDC_UPDATEDB: + case IDC_ERASEFROMDB: + case IDC_SAVEPROFILE: + case IDC_LOADPROFILE: + // we don't have handlers for these, so fall through to FALSE + default: + return FALSE; + } - case WM_CLOSE: - if( hTabControl ) - { - DestroyWindow( hTabControl ); - hTabControl = NULL; - } - EndDialog( hDlg, FALSE ); - return TRUE; + case WM_CLOSE: + if( hTabControl ) + { + DestroyWindow( hTabControl ); + hTabControl = NULL; + } + EndDialog( hDlg, FALSE ); + return TRUE; - case WM_DESTROY: - if( hTabControl ) - { - DestroyWindow( hTabControl ); - hTabControl = NULL; - } - EnterCriticalSection(&g_critical); - ReleaseEffect( g_pConfigEffect ); - ReleaseDevice( g_pConfigDevice ); + case WM_DESTROY: + if( hTabControl ) + { + DestroyWindow( hTabControl ); + hTabControl = NULL; + } + EnterCriticalSection(&g_critical); + ReleaseEffect( g_pConfigEffect ); + ReleaseDevice( g_pConfigDevice ); - for( i = 0; i < 4; ++i ) - { - freePakData( &g_ivConfig->Controllers[i] ); - freeModifiers( &g_ivConfig->Controllers[i] ); - } - P_free( g_ivConfig ); - g_ivConfig = NULL; - DebugWriteA("Config interface: Closed\n"); - LeaveCriticalSection(&g_critical); - return TRUE; + for( i = 0; i < 4; ++i ) + { + freePakData( &g_ivConfig->Controllers[i] ); + freeModifiers( &g_ivConfig->Controllers[i] ); + } + P_free( g_ivConfig ); + g_ivConfig = NULL; + DebugWriteA("Config interface: Closed\n"); + LeaveCriticalSection(&g_critical); + return TRUE; - case WM_USER_UPDATE: + case WM_USER_UPDATE: #ifdef _UNICODE - // filling DropDownlist with languages - hDlgItem = GetDlgItem( hDlg, IDC_LANGUAGE ); - SendMessage (hDlgItem, CB_RESETCONTENT, 0, 0); - - { - TCHAR szBuffer[MAX_PATH]; - TCHAR * pSlash; - WIN32_FIND_DATA fData; - long lLangFound = 0; // the index matching our current language + // filling DropDownlist with languages + hDlgItem = GetDlgItem( hDlg, IDC_LANGUAGE ); + SendMessage (hDlgItem, CB_RESETCONTENT, 0, 0); - VerLanguageName(0x0009, szBuffer, DEFAULT_BUFFER); // English (default resource) - j = SendMessage( hDlgItem, CB_ADDSTRING, 0, (LPARAM)szBuffer ); - SendMessage( hDlgItem, CB_SETITEMDATA, j, 0 ); + { + TCHAR szBuffer[MAX_PATH]; + TCHAR * pSlash; + WIN32_FIND_DATA fData; + long lLangFound = 0; // the index matching our current language - GetModuleFileName( NULL, szBuffer, MAX_PATH ); - pSlash = _tcsrchr( szBuffer, '\\' ); - _tcscpy(pSlash + 1, _T("NRage-Language-*.dll")); + VerLanguageName(0x0009, szBuffer, DEFAULT_BUFFER); // English (default resource) + j = SendMessage( hDlgItem, CB_ADDSTRING, 0, (LPARAM)szBuffer ); + SendMessage( hDlgItem, CB_SETITEMDATA, j, 0 ); - // Search for any file available called NRage-Language-XXXX.dll (where X is numbers) - HANDLE fSearch = FindFirstFile(szBuffer, &fData); - - while ( fSearch != INVALID_HANDLE_VALUE ) - { - DWORD dwLangID = 0; - if (_stscanf(fData.cFileName, _T("NRage-Language-%u.dll"), &dwLangID)) - { - VerLanguageName(dwLangID, szBuffer, DEFAULT_BUFFER); - j = SendMessage( hDlgItem, CB_ADDSTRING, 0, (LPARAM)szBuffer ); - SendMessage( hDlgItem, CB_SETITEMDATA, j, dwLangID ); - if (dwLangID == g_ivConfig->Language) - lLangFound = j; - } - if (!FindNextFile(fSearch, &fData)) - fSearch = INVALID_HANDLE_VALUE; - } - FindClose(fSearch); + GetModuleFileName( NULL, szBuffer, MAX_PATH ); + pSlash = _tcsrchr( szBuffer, '\\' ); + _tcscpy(pSlash + 1, _T("NRage-Language-*.dll")); - SendMessage( hDlgItem, CB_SETCURSEL, lLangFound, 0 ); // set combo box selection - } - // DropDownlist End + // Search for any file available called NRage-Language-XXXX.dll (where X is numbers) + HANDLE fSearch = FindFirstFile(szBuffer, &fData); + + while ( fSearch != INVALID_HANDLE_VALUE ) + { + DWORD dwLangID = 0; + if (_stscanf(fData.cFileName, _T("NRage-Language-%u.dll"), &dwLangID)) + { + VerLanguageName(dwLangID, szBuffer, DEFAULT_BUFFER); + j = SendMessage( hDlgItem, CB_ADDSTRING, 0, (LPARAM)szBuffer ); + SendMessage( hDlgItem, CB_SETITEMDATA, j, dwLangID ); + if (dwLangID == g_ivConfig->Language) + lLangFound = j; + } + if (!FindNextFile(fSearch, &fData)) + fSearch = INVALID_HANDLE_VALUE; + } + FindClose(fSearch); + + SendMessage( hDlgItem, CB_SETCURSEL, lLangFound, 0 ); // set combo box selection + } + // DropDownlist End #else - hDlgItem = GetDlgItem( hDlg, IDC_LANGUAGE ); - SendMessage(hDlgItem, CB_RESETCONTENT, 0, 0); - j = SendMessage(hDlgItem, CB_ADDSTRING, 0, (LPARAM) _T("Language selection disabled")); - SendMessage( hDlgItem, CB_SETITEMDATA, j, 0 ); - SendMessage(hDlgItem, CB_SETCURSEL, 0, 0); + hDlgItem = GetDlgItem( hDlg, IDC_LANGUAGE ); + SendMessage(hDlgItem, CB_RESETCONTENT, 0, 0); + j = SendMessage(hDlgItem, CB_ADDSTRING, 0, (LPARAM) _T("Language selection disabled")); + SendMessage( hDlgItem, CB_SETITEMDATA, j, 0 ); + SendMessage(hDlgItem, CB_SETCURSEL, 0, 0); #endif // #ifdef _UNICODE - // call child-dialog(s) to update their content as well - if( hTabControl ) - SendMessage( hTabControl, WM_USER_UPDATE, 0, 0 ); - return TRUE; + // call child-dialog(s) to update their content as well + if( hTabControl ) + SendMessage( hTabControl, WM_USER_UPDATE, 0, 0 ); + return TRUE; - default: - return FALSE; //false means the msg didn't got processed - } -// return TRUE; //msg got processed + default: + return FALSE; //false means the msg didn't got processed + } +// return TRUE; //msg got processed } BOOL CALLBACK ControllerTabProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) { - static HWND hTabControl; + static HWND hTabControl; - CONTROLLER *pcController = &g_ivConfig->Controllers[g_ivConfig->ChosenTab];; - HWND hDlgItem; - long i,j; + CONTROLLER *pcController = &g_ivConfig->Controllers[g_ivConfig->ChosenTab];; + HWND hDlgItem; + long i,j; - switch(uMsg) - { - case WM_INITDIALOG: - hTabControl = NULL; + switch(uMsg) + { + case WM_INITDIALOG: + hTabControl = NULL; - // Tab - Control // - hDlgItem = GetDlgItem( hDlg, IDC_CONTROLLERTAB ); + // Tab - Control // + hDlgItem = GetDlgItem( hDlg, IDC_CONTROLLERTAB ); - TCITEM tcItem; - tcItem.mask = TCIF_TEXT; + TCITEM tcItem; + tcItem.mask = TCIF_TEXT; - TCHAR tszText[DEFAULT_BUFFER]; - tcItem.pszText = tszText; + TCHAR tszText[DEFAULT_BUFFER]; + tcItem.pszText = tszText; - LoadString( g_hResourceDLL, IDS_TAB_CONTROLS, tszText, DEFAULT_BUFFER ); - TabCtrl_InsertItem( hDlgItem, TAB_CONTROLS, &tcItem ); - LoadString( g_hResourceDLL, IDS_TAB_DEVICES, tszText, DEFAULT_BUFFER ); - TabCtrl_InsertItem( hDlgItem, TAB_DEVICES, &tcItem ); - LoadString( g_hResourceDLL, IDS_TAB_MODIFIERS, tszText, DEFAULT_BUFFER ); - TabCtrl_InsertItem( hDlgItem, TAB_MODIFIERS, &tcItem ); - LoadString( g_hResourceDLL, IDS_TAB_CONTROLLERPAK, tszText, DEFAULT_BUFFER ); - TabCtrl_InsertItem( hDlgItem, TAB_PAK, &tcItem ); + LoadString( g_hResourceDLL, IDS_TAB_CONTROLS, tszText, DEFAULT_BUFFER ); + TabCtrl_InsertItem( hDlgItem, TAB_CONTROLS, &tcItem ); + LoadString( g_hResourceDLL, IDS_TAB_DEVICES, tszText, DEFAULT_BUFFER ); + TabCtrl_InsertItem( hDlgItem, TAB_DEVICES, &tcItem ); + LoadString( g_hResourceDLL, IDS_TAB_MODIFIERS, tszText, DEFAULT_BUFFER ); + TabCtrl_InsertItem( hDlgItem, TAB_MODIFIERS, &tcItem ); + LoadString( g_hResourceDLL, IDS_TAB_CONTROLLERPAK, tszText, DEFAULT_BUFFER ); + TabCtrl_InsertItem( hDlgItem, TAB_PAK, &tcItem ); - NMHDR nmInit; - nmInit.hwndFrom = hDlgItem; - nmInit.idFrom = IDC_CONTROLLERTAB; - nmInit.code = TCN_SELCHANGE; + NMHDR nmInit; + nmInit.hwndFrom = hDlgItem; + nmInit.idFrom = IDC_CONTROLLERTAB; + nmInit.code = TCN_SELCHANGE; - // initiate Tab-Display - ControllerTabProc( hDlg, WM_NOTIFY, IDC_CONTROLLERTAB, (LPARAM)&nmInit ); - // Tab - Control End // + // initiate Tab-Display + ControllerTabProc( hDlg, WM_NOTIFY, IDC_CONTROLLERTAB, (LPARAM)&nmInit ); + // Tab - Control End // - // call routine to show content( recursive call ) - ControllerTabProc( hDlg, WM_USER_UPDATE, 0, 0 ); + // call routine to show content( recursive call ) + ControllerTabProc( hDlg, WM_USER_UPDATE, 0, 0 ); - return FALSE; // don't give it focus + return FALSE; // don't give it focus - case WM_NOTIFY: - hDlgItem = ((LPNMHDR)lParam)->hwndFrom; - i = ((LPNMHDR)lParam)->code; - j = ((LPNMHDR)lParam)->idFrom; + case WM_NOTIFY: + hDlgItem = ((LPNMHDR)lParam)->hwndFrom; + i = ((LPNMHDR)lParam)->code; + j = ((LPNMHDR)lParam)->idFrom; - switch( j ) - { - case IDC_CONTROLLERTAB: - if( i == TCN_SELCHANGE ) - { - if( hTabControl ) - DestroyWindow( hTabControl ); + switch( j ) + { + case IDC_CONTROLLERTAB: + if( i == TCN_SELCHANGE ) + { + if( hTabControl ) + DestroyWindow( hTabControl ); - i = TabCtrl_GetCurSel( hDlgItem ); + i = TabCtrl_GetCurSel( hDlgItem ); - switch( i ) - { - case TAB_CONTROLS: - if( pcController->fXInput) // added to show the xinput controller config tab --tecnicors - hTabControl = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_XCONTROLS), hDlg, (DLGPROC)XControlsTabProc); - else - hTabControl = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_CONTROLS), hDlg, (DLGPROC)ControlsTabProc); - break; - case TAB_DEVICES: - hTabControl = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_DEVICES), hDlg, (DLGPROC)DevicesTabProc); - break; - case TAB_MODIFIERS: - hTabControl = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_MODIFIER), hDlg, (DLGPROC)ModifierTabProc); - break; - case TAB_PAK: - hTabControl = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_CONTROLLERPAK), hDlg, (DLGPROC)ControllerPakTabProc); - break; - default: - hTabControl = NULL; - return TRUE; - } - hDlgItem = GetDlgItem( hDlg, IDC_CONTROLLERTAB ); + switch( i ) + { + case TAB_CONTROLS: + if( pcController->fXInput) // added to show the xinput controller config tab --tecnicors + hTabControl = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_XCONTROLS), hDlg, (DLGPROC)XControlsTabProc); + else + hTabControl = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_CONTROLS), hDlg, (DLGPROC)ControlsTabProc); + break; + case TAB_DEVICES: + hTabControl = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_DEVICES), hDlg, (DLGPROC)DevicesTabProc); + break; + case TAB_MODIFIERS: + hTabControl = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_MODIFIER), hDlg, (DLGPROC)ModifierTabProc); + break; + case TAB_PAK: + hTabControl = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_CONTROLLERPAK), hDlg, (DLGPROC)ControllerPakTabProc); + break; + default: + hTabControl = NULL; + return TRUE; + } + hDlgItem = GetDlgItem( hDlg, IDC_CONTROLLERTAB ); - RECT rectWindow, - rectTab, rectMain; // need to know the position of the calling tab window relative to its parent + RECT rectWindow, + rectTab, rectMain; // need to know the position of the calling tab window relative to its parent - GetWindowRect( hDlg, &rectMain ); - GetWindowRect( hDlgItem, &rectTab ); + GetWindowRect( hDlg, &rectMain ); + GetWindowRect( hDlgItem, &rectTab ); - GetClientRect( hDlgItem, &rectWindow ); - TabCtrl_AdjustRect( hDlgItem, FALSE, &rectWindow ); + GetClientRect( hDlgItem, &rectWindow ); + TabCtrl_AdjustRect( hDlgItem, FALSE, &rectWindow ); - MoveWindow( hTabControl, rectWindow.left + (rectTab.left - rectMain.left), rectWindow.top + (rectTab.top - rectMain.top), rectWindow.right - rectWindow.left, rectWindow.bottom - rectWindow.top, FALSE ); - ShowWindow( hTabControl, SW_SHOW ); - return TRUE; - } - else - return FALSE; - default: - return FALSE; - } + MoveWindow( hTabControl, rectWindow.left + (rectTab.left - rectMain.left), rectWindow.top + (rectTab.top - rectMain.top), rectWindow.right - rectWindow.left, rectWindow.bottom - rectWindow.top, FALSE ); + ShowWindow( hTabControl, SW_SHOW ); + return TRUE; + } + else + return FALSE; + default: + return FALSE; + } - case WM_COMMAND: - hDlgItem = GetDlgItem( hDlg, LOWORD(wParam) ); + case WM_COMMAND: + hDlgItem = GetDlgItem( hDlg, LOWORD(wParam) ); - switch( LOWORD(wParam) ) - { - TCHAR tszTitle[DEFAULT_BUFFER], tszText[DEFAULT_BUFFER]; - case IDC_PLUGGED: - pcController->fPlugged = ( IsDlgButtonChecked( hDlg, LOWORD(wParam) ) == BST_CHECKED ); - return TRUE; - case IDC_CLEARCONTROLLER: - LoadString( g_hResourceDLL, IDS_DLG_CLEAR, tszText, DEFAULT_BUFFER ); - LoadString( g_hResourceDLL, IDS_DLG_CLEAR_TITLE, tszTitle, DEFAULT_BUFFER ); - if( MessageBox( hDlg, tszText, tszTitle, MB_OKCANCEL | MB_ICONWARNING ) == IDOK ) - { - DeleteControllerSettings( g_ivConfig->ChosenTab ); - ControllerTabProc( hDlg, WM_USER_UPDATE, 0, 0 ); - } - return TRUE; - case IDC_SETDEFAULT: - LoadString( g_hResourceDLL, IDS_DLG_CONTROLRESTORE, tszText, DEFAULT_BUFFER ); - LoadString( g_hResourceDLL, IDS_DLG_CONTROLRESTORE_TITLE, tszTitle, DEFAULT_BUFFER ); - if( MessageBox( hDlg, tszText, tszTitle, MB_OKCANCEL | MB_ICONWARNING ) == IDOK ) - { - DeleteControllerSettings( g_ivConfig->ChosenTab ); - LoadProfileFromResource( g_ivConfig->ChosenTab, true); - *(g_ivConfig->FFDevices[g_ivConfig->ChosenTab].szProductName) = '\0'; // default profile has no FF device - g_ivConfig->FFDevices[g_ivConfig->ChosenTab].bProductCounter = 0; - ControllerTabProc( hDlg, WM_USER_UPDATE, 0, 0 ); - } - return TRUE; + switch( LOWORD(wParam) ) + { + TCHAR tszTitle[DEFAULT_BUFFER], tszText[DEFAULT_BUFFER]; + case IDC_PLUGGED: + pcController->fPlugged = ( IsDlgButtonChecked( hDlg, LOWORD(wParam) ) == BST_CHECKED ); + return TRUE; + case IDC_CLEARCONTROLLER: + LoadString( g_hResourceDLL, IDS_DLG_CLEAR, tszText, DEFAULT_BUFFER ); + LoadString( g_hResourceDLL, IDS_DLG_CLEAR_TITLE, tszTitle, DEFAULT_BUFFER ); + if( MessageBox( hDlg, tszText, tszTitle, MB_OKCANCEL | MB_ICONWARNING ) == IDOK ) + { + DeleteControllerSettings( g_ivConfig->ChosenTab ); + ControllerTabProc( hDlg, WM_USER_UPDATE, 0, 0 ); + } + return TRUE; + case IDC_SETDEFAULT: + LoadString( g_hResourceDLL, IDS_DLG_CONTROLRESTORE, tszText, DEFAULT_BUFFER ); + LoadString( g_hResourceDLL, IDS_DLG_CONTROLRESTORE_TITLE, tszTitle, DEFAULT_BUFFER ); + if( MessageBox( hDlg, tszText, tszTitle, MB_OKCANCEL | MB_ICONWARNING ) == IDOK ) + { + DeleteControllerSettings( g_ivConfig->ChosenTab ); + LoadProfileFromResource( g_ivConfig->ChosenTab, true); + *(g_ivConfig->FFDevices[g_ivConfig->ChosenTab].szProductName) = '\0'; // default profile has no FF device + g_ivConfig->FFDevices[g_ivConfig->ChosenTab].bProductCounter = 0; + ControllerTabProc( hDlg, WM_USER_UPDATE, 0, 0 ); + } + return TRUE; - case IDC_SAVEPROFILE: - { - TCHAR szFilename[MAX_PATH+1] = _T(""); - if( BrowseFile( hDlg, szFilename, BF_PROFILE, BF_SAVE )) - { - FILE * fFile = _tfopen( szFilename, _T("wS") ); - if (fFile) - { - fprintf(fFile, "@" STRING_PROFILEVERSION "\n\n"); - FormatProfileBlock( fFile, g_ivConfig->ChosenTab ); + case IDC_SAVEPROFILE: + { + TCHAR szFilename[MAX_PATH+1] = _T(""); + if( BrowseFile( hDlg, szFilename, BF_PROFILE, BF_SAVE )) + { + FILE * fFile = _tfopen( szFilename, _T("wS") ); + if (fFile) + { + fprintf(fFile, "@" STRING_PROFILEVERSION "\n\n"); + FormatProfileBlock( fFile, g_ivConfig->ChosenTab ); - fclose(fFile); - } - else - WarningMessage( IDS_ERR_PROFWRITE, MB_OK ); - } - } - return TRUE; + fclose(fFile); + } + else + WarningMessage( IDS_ERR_PROFWRITE, MB_OK ); + } + } + return TRUE; - case IDC_LOADPROFILE: - { - TCHAR szFilename[MAX_PATH+1] = TEXT( "" ); - if( BrowseFile( hDlg, szFilename, BF_PROFILE, BF_LOAD )) - { - DebugWrite(_T("Config interface: Load shortcuts file: %s\n"), szFilename); - if( LoadProfileFile( szFilename, g_ivConfig->ChosenTab, g_ivConfig->FFDevices[g_ivConfig->ChosenTab].szProductName, &g_ivConfig->FFDevices[g_ivConfig->ChosenTab].bProductCounter )) - ControllerTabProc( hDlg, WM_USER_UPDATE, 0, 0 ); - else - WarningMessage( IDS_ERR_PROFREAD, MB_OK ); + case IDC_LOADPROFILE: + { + TCHAR szFilename[MAX_PATH+1] = TEXT( "" ); + if( BrowseFile( hDlg, szFilename, BF_PROFILE, BF_LOAD )) + { + DebugWrite(_T("Config interface: Load shortcuts file: %s\n"), szFilename); + if( LoadProfileFile( szFilename, g_ivConfig->ChosenTab, g_ivConfig->FFDevices[g_ivConfig->ChosenTab].szProductName, &g_ivConfig->FFDevices[g_ivConfig->ChosenTab].bProductCounter )) + ControllerTabProc( hDlg, WM_USER_UPDATE, 0, 0 ); + else + WarningMessage( IDS_ERR_PROFREAD, MB_OK ); - } - } - return TRUE; - - case IDC_XINPUT_ENABLER: // change to xinput config --tecnicors - pcController->fXInput = ( IsDlgButtonChecked( hDlg, LOWORD(wParam) ) == BST_CHECKED ); - if( hTabControl ) - DestroyWindow( hTabControl ); - if( pcController->fXInput ) - hTabControl = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_XCONTROLS), hDlg, (DLGPROC)XControlsTabProc); - else - hTabControl = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_CONTROLS), hDlg, (DLGPROC)ControlsTabProc); - { - hDlgItem = GetDlgItem( hDlg, IDC_CONTROLLERTAB ); + } + } + return TRUE; - RECT rectWindow, - rectTab, rectMain; // need to know the position of the calling tab window relative to its parent + case IDC_XINPUT_ENABLER: // change to xinput config --tecnicors + pcController->fXInput = ( IsDlgButtonChecked( hDlg, LOWORD(wParam) ) == BST_CHECKED ); + if( hTabControl ) + DestroyWindow( hTabControl ); + if( pcController->fXInput ) + hTabControl = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_XCONTROLS), hDlg, (DLGPROC)XControlsTabProc); + else + hTabControl = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_CONTROLS), hDlg, (DLGPROC)ControlsTabProc); + { + hDlgItem = GetDlgItem( hDlg, IDC_CONTROLLERTAB ); - GetWindowRect( hDlg, &rectMain ); - GetWindowRect( hDlgItem, &rectTab ); + RECT rectWindow, + rectTab, rectMain; // need to know the position of the calling tab window relative to its parent - GetClientRect( hDlgItem, &rectWindow ); - TabCtrl_AdjustRect( hDlgItem, FALSE, &rectWindow ); + GetWindowRect( hDlg, &rectMain ); + GetWindowRect( hDlgItem, &rectTab ); - MoveWindow( hTabControl, rectWindow.left + (rectTab.left - rectMain.left), rectWindow.top + (rectTab.top - rectMain.top), rectWindow.right - rectWindow.left, rectWindow.bottom - rectWindow.top, FALSE ); - ShowWindow( hTabControl, SW_SHOW ); - } - return TRUE; // END IDC_XINPUT_ENABLER + GetClientRect( hDlgItem, &rectWindow ); + TabCtrl_AdjustRect( hDlgItem, FALSE, &rectWindow ); - case IDC_N64MOUSE: - pcController->fN64Mouse = (IsDlgButtonChecked(hDlg, LOWORD(wParam)) == BST_CHECKED); - return TRUE; + MoveWindow( hTabControl, rectWindow.left + (rectTab.left - rectMain.left), rectWindow.top + (rectTab.top - rectMain.top), rectWindow.right - rectWindow.left, rectWindow.bottom - rectWindow.top, FALSE ); + ShowWindow( hTabControl, SW_SHOW ); + } + return TRUE; // END IDC_XINPUT_ENABLER - case IDC_BACKGROUNDINPUT: - pcController->bBackgroundInput = (IsDlgButtonChecked(hDlg, LOWORD(wParam)) == BST_CHECKED); - return TRUE; + case IDC_N64MOUSE: + pcController->fN64Mouse = (IsDlgButtonChecked(hDlg, LOWORD(wParam)) == BST_CHECKED); + return TRUE; - default: - return FALSE; - } + case IDC_BACKGROUNDINPUT: + pcController->bBackgroundInput = (IsDlgButtonChecked(hDlg, LOWORD(wParam)) == BST_CHECKED); + return TRUE; - case WM_USER_UPDATE: - // for this dialog - CheckDlgButton( hDlg, IDC_PLUGGED, pcController->fPlugged ? BST_CHECKED : BST_UNCHECKED ); - CheckDlgButton( hDlg, IDC_XINPUT_ENABLER, pcController->fXInput ? BST_CHECKED : BST_UNCHECKED ); - CheckDlgButton( hDlg, IDC_N64MOUSE, pcController->fN64Mouse ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton( hDlg, IDC_BACKGROUNDINPUT, pcController->bBackgroundInput ? BST_CHECKED : BST_UNCHECKED); + default: + return FALSE; + } - if( hTabControl ) - DestroyWindow( hTabControl ); + case WM_USER_UPDATE: + // for this dialog + CheckDlgButton( hDlg, IDC_PLUGGED, pcController->fPlugged ? BST_CHECKED : BST_UNCHECKED ); + CheckDlgButton( hDlg, IDC_XINPUT_ENABLER, pcController->fXInput ? BST_CHECKED : BST_UNCHECKED ); + CheckDlgButton( hDlg, IDC_N64MOUSE, pcController->fN64Mouse ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton( hDlg, IDC_BACKGROUNDINPUT, pcController->bBackgroundInput ? BST_CHECKED : BST_UNCHECKED); - if( pcController->fXInput ) - hTabControl = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_XCONTROLS), hDlg, (DLGPROC)XControlsTabProc); - else - hTabControl = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_CONTROLS), hDlg, (DLGPROC)ControlsTabProc); + if( hTabControl ) + DestroyWindow( hTabControl ); - { - hDlgItem = GetDlgItem( hDlg, IDC_CONTROLLERTAB ); + if( pcController->fXInput ) + hTabControl = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_XCONTROLS), hDlg, (DLGPROC)XControlsTabProc); + else + hTabControl = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_CONTROLS), hDlg, (DLGPROC)ControlsTabProc); - RECT rectWindow, - rectTab, rectMain; // need to know the position of the calling tab window relative to its parent + { + hDlgItem = GetDlgItem( hDlg, IDC_CONTROLLERTAB ); - GetWindowRect( hDlg, &rectMain ); - GetWindowRect( hDlgItem, &rectTab ); + RECT rectWindow, + rectTab, rectMain; // need to know the position of the calling tab window relative to its parent - GetClientRect( hDlgItem, &rectWindow ); - TabCtrl_AdjustRect( hDlgItem, FALSE, &rectWindow ); + GetWindowRect( hDlg, &rectMain ); + GetWindowRect( hDlgItem, &rectTab ); - MoveWindow( hTabControl, rectWindow.left + (rectTab.left - rectMain.left), rectWindow.top + (rectTab.top - rectMain.top), rectWindow.right - rectWindow.left, rectWindow.bottom - rectWindow.top, FALSE ); - ShowWindow( hTabControl, SW_SHOW ); - } + GetClientRect( hDlgItem, &rectWindow ); + TabCtrl_AdjustRect( hDlgItem, FALSE, &rectWindow ); - // call child-dialog(s) to update their content as well - if( hTabControl ) - SendMessage( hTabControl, WM_USER_UPDATE, 0, 0 ); - return TRUE; - default: - return FALSE; //false means the msg didn't got processed - } + MoveWindow( hTabControl, rectWindow.left + (rectTab.left - rectMain.left), rectWindow.top + (rectTab.top - rectMain.top), rectWindow.right - rectWindow.left, rectWindow.bottom - rectWindow.top, FALSE ); + ShowWindow( hTabControl, SW_SHOW ); + } + + // call child-dialog(s) to update their content as well + if( hTabControl ) + SendMessage( hTabControl, WM_USER_UPDATE, 0, 0 ); + return TRUE; + default: + return FALSE; //false means the msg didn't got processed + } } // "Controls" tab BOOL CALLBACK ControlsTabProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) { - static LPBUTTON aButtons = NULL; // should point to g_ivConfig->Controllers[g_ivConfig->ChosenTab].aButton array - static DWORD dwButtonID[3]; // 0:ID of PushButton 1:ID of TextWindow 2:offset in aButtons struct - static DWORD dwCounter; - static bool bScanRunning; - static HWND hFocus = NULL; - static HWND hBlocker = NULL; + static LPBUTTON aButtons = NULL; // should point to g_ivConfig->Controllers[g_ivConfig->ChosenTab].aButton array + static DWORD dwButtonID[3]; // 0:ID of PushButton 1:ID of TextWindow 2:offset in aButtons struct + static DWORD dwCounter; + static bool bScanRunning; + static HWND hFocus = NULL; + static HWND hBlocker = NULL; - TCHAR szBuffer[40], szTemp[40]; - HWND hDlgItem; - long i; + TCHAR szBuffer[40], szTemp[40]; + HWND hDlgItem; + long i; - switch(uMsg) - { - case WM_INITDIALOG: - // SetTicks on TrackBar - hDlgItem = GetDlgItem( hDlg, IDC_CTRRANGE ); - SendMessage( hDlgItem, TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG( 0, 100 )); - SendMessage( hDlgItem, TBM_SETTICFREQ, (WPARAM) 10, 0 ); - SendMessage( hDlgItem, TBM_SETPAGESIZE, (WPARAM) 0, 1 ); + switch(uMsg) + { + case WM_INITDIALOG: + // SetTicks on TrackBar + hDlgItem = GetDlgItem( hDlg, IDC_CTRRANGE ); + SendMessage( hDlgItem, TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG( 0, 100 )); + SendMessage( hDlgItem, TBM_SETTICFREQ, (WPARAM) 10, 0 ); + SendMessage( hDlgItem, TBM_SETPAGESIZE, (WPARAM) 0, 1 ); - // SetTicks on RapidFire Bar - hDlgItem = GetDlgItem( hDlg, IDC_RAPIDFIRERATE ); - SendMessage( hDlgItem, TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG( 0, 32 )); - SendMessage( hDlgItem, TBM_SETTICFREQ, (WPARAM) 1, 0 ); - SendMessage( hDlgItem, TBM_SETPAGESIZE, (WPARAM) 0, 1 ); + // SetTicks on RapidFire Bar + hDlgItem = GetDlgItem( hDlg, IDC_RAPIDFIRERATE ); + SendMessage( hDlgItem, TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG( 0, 32 )); + SendMessage( hDlgItem, TBM_SETTICFREQ, (WPARAM) 1, 0 ); + SendMessage( hDlgItem, TBM_SETPAGESIZE, (WPARAM) 0, 1 ); - // call routine to show content( recursive call ) - ControlsTabProc( hDlg, WM_USER_UPDATE, 0, 0 ); - return FALSE; // don't give it focus + // call routine to show content( recursive call ) + ControlsTabProc( hDlg, WM_USER_UPDATE, 0, 0 ); + return FALSE; // don't give it focus - case WM_COMMAND: - hDlgItem = GetDlgItem( hDlg, LOWORD(wParam) ); + case WM_COMMAND: + hDlgItem = GetDlgItem( hDlg, LOWORD(wParam) ); - switch( LOWORD(wParam) ) - { - case IDC_N64RANGE: - g_ivConfig->Controllers[g_ivConfig->ChosenTab].fRealN64Range = ( IsDlgButtonChecked( hDlg, LOWORD(wParam) ) == BST_CHECKED ); - return TRUE; + switch( LOWORD(wParam) ) + { + case IDC_N64RANGE: + g_ivConfig->Controllers[g_ivConfig->ChosenTab].fRealN64Range = ( IsDlgButtonChecked( hDlg, LOWORD(wParam) ) == BST_CHECKED ); + return TRUE; - case IDC_RAPIDFIREENABLE: - g_ivConfig->Controllers[g_ivConfig->ChosenTab].bRapidFireEnabled = (IsDlgButtonChecked( hDlg, LOWORD(wParam)) == BST_CHECKED); - return TRUE; + case IDC_RAPIDFIREENABLE: + g_ivConfig->Controllers[g_ivConfig->ChosenTab].bRapidFireEnabled = (IsDlgButtonChecked( hDlg, LOWORD(wParam)) == BST_CHECKED); + return TRUE; - case IDC_CONFIG1: - case IDC_CONFIG2: - case IDC_CONFIG3: - if( HIWORD(wParam) == BN_CLICKED ) - { - if( LOWORD(wParam) == IDC_CONFIG1 ) - g_ivConfig->Controllers[g_ivConfig->ChosenTab].bAxisSet = 0; - else if( LOWORD(wParam) == IDC_CONFIG2 ) - g_ivConfig->Controllers[g_ivConfig->ChosenTab].bAxisSet = 1; - else if( LOWORD(wParam) == IDC_CONFIG3 ) - g_ivConfig->Controllers[g_ivConfig->ChosenTab].bAxisSet = 2; + case IDC_CONFIG1: + case IDC_CONFIG2: + case IDC_CONFIG3: + if( HIWORD(wParam) == BN_CLICKED ) + { + if( LOWORD(wParam) == IDC_CONFIG1 ) + g_ivConfig->Controllers[g_ivConfig->ChosenTab].bAxisSet = 0; + else if( LOWORD(wParam) == IDC_CONFIG2 ) + g_ivConfig->Controllers[g_ivConfig->ChosenTab].bAxisSet = 1; + else if( LOWORD(wParam) == IDC_CONFIG3 ) + g_ivConfig->Controllers[g_ivConfig->ChosenTab].bAxisSet = 2; - ControlsTabProc( hDlg, WM_USER_UPDATE, 1, 0 ); - } - return TRUE; + ControlsTabProc( hDlg, WM_USER_UPDATE, 1, 0 ); + } + return TRUE; - case IDC_LEFTTRIGGER: - case IDC_RIGHTTRIGGER: - case IDC_ZTRIGGER: - case IDC_DUP: - case IDC_DLEFT: - case IDC_DRIGHT: - case IDC_DDOWN: - case IDC_AUP: - case IDC_ALEFT: - case IDC_ARIGHT: - case IDC_ADOWN: - case IDC_CUP: - case IDC_CLEFT: - case IDC_CRIGHT: - case IDC_CDOWN: - case IDC_ABUTTON: - case IDC_BBUTTON: - case IDC_SBUTTON: // any of these cases means user wants to assign a button - if( bScanRunning ) - { ; // do nothing -/* bScanRunning = false; - KillTimer( hDlg, TIMER_BUTTON ); - GetButtonText( aButtons[dwButtonID[2]], szBuffer ); - SendMessage( GetDlgItem( hDlg, dwButtonID[1] ), WM_SETTEXT , 0, (LPARAM)szBuffer ); */ - } - else if( HIWORD(wParam) == BN_CLICKED ) - { - EnterCriticalSection(&g_critical); - dwButtonID[0] = LOWORD(wParam); - dwCounter = 0; - GetButtonID( dwButtonID, 0, BSET_CONTROLS ); - if( dwButtonID[2] >= PF_APADR ) - dwButtonID[2] += g_ivConfig->Controllers[g_ivConfig->ChosenTab].bAxisSet * 4; - if (hFocus == NULL) - hFocus = SetFocus( NULL ); - hBlocker = MakeOverlay(); + case IDC_LEFTTRIGGER: + case IDC_RIGHTTRIGGER: + case IDC_ZTRIGGER: + case IDC_DUP: + case IDC_DLEFT: + case IDC_DRIGHT: + case IDC_DDOWN: + case IDC_AUP: + case IDC_ALEFT: + case IDC_ARIGHT: + case IDC_ADOWN: + case IDC_CUP: + case IDC_CLEFT: + case IDC_CRIGHT: + case IDC_CDOWN: + case IDC_ABUTTON: + case IDC_BBUTTON: + case IDC_SBUTTON: // any of these cases means user wants to assign a button + if( bScanRunning ) + { ; // do nothing +/* bScanRunning = false; + KillTimer( hDlg, TIMER_BUTTON ); + GetButtonText( aButtons[dwButtonID[2]], szBuffer ); + SendMessage( GetDlgItem( hDlg, dwButtonID[1] ), WM_SETTEXT , 0, (LPARAM)szBuffer ); */ + } + else if( HIWORD(wParam) == BN_CLICKED ) + { + EnterCriticalSection(&g_critical); + dwButtonID[0] = LOWORD(wParam); + dwCounter = 0; + GetButtonID( dwButtonID, 0, BSET_CONTROLS ); + if( dwButtonID[2] >= PF_APADR ) + dwButtonID[2] += g_ivConfig->Controllers[g_ivConfig->ChosenTab].bAxisSet * 4; + if (hFocus == NULL) + hFocus = SetFocus( NULL ); + hBlocker = MakeOverlay(); - SetTimer( hDlg, TIMER_BUTTON, INTERVAL_BUTTON, NULL ); - bScanRunning = true; - LeaveCriticalSection(&g_critical); - } - return TRUE; + SetTimer( hDlg, TIMER_BUTTON, INTERVAL_BUTTON, NULL ); + bScanRunning = true; + LeaveCriticalSection(&g_critical); + } + return TRUE; - default: - return FALSE; - } + default: + return FALSE; + } - case WM_TIMER: // when assigning buttons, this gets called every 20ms (or value in INTERVAL_BUTTON) - if( wParam == TIMER_BUTTON && bScanRunning ) - { - BUTTON newButton; + case WM_TIMER: // when assigning buttons, this gets called every 20ms (or value in INTERVAL_BUTTON) + if( wParam == TIMER_BUTTON && bScanRunning ) + { + BUTTON newButton; - i = ScanDevices( &dwCounter, &newButton); - if( i || dwCounter > 500 ) - { - bScanRunning = false; - KillTimer( hDlg, TIMER_BUTTON ); + i = ScanDevices( &dwCounter, &newButton); + if( i || dwCounter > 500 ) + { + bScanRunning = false; + KillTimer( hDlg, TIMER_BUTTON ); - EnterCriticalSection(&g_critical); - if( i == SC_SCANESCAPE ) // Scan aborted - ZeroMemory(&aButtons[dwButtonID[2]], sizeof(BUTTON)); //aButtons[dwButtonID[2]].dwButton = 0; - else if( i == SC_SCANSUCCEED ) // Got a key, mouseclick, joybutton, or axis - aButtons[dwButtonID[2]] = newButton; - DestroyWindow( hBlocker ); + EnterCriticalSection(&g_critical); + if( i == SC_SCANESCAPE ) // Scan aborted + ZeroMemory(&aButtons[dwButtonID[2]], sizeof(BUTTON)); //aButtons[dwButtonID[2]].dwButton = 0; + else if( i == SC_SCANSUCCEED ) // Got a key, mouseclick, joybutton, or axis + aButtons[dwButtonID[2]] = newButton; + DestroyWindow( hBlocker ); - LeaveCriticalSection(&g_critical); + LeaveCriticalSection(&g_critical); - GetButtonText( aButtons[dwButtonID[2]], szBuffer ); - SendMessage( GetDlgItem( hDlg, dwButtonID[1] ), WM_SETTEXT , 0, (LPARAM)szBuffer ); - if( hFocus != NULL ) - { - SetFocus( hFocus ); - hFocus = NULL; - } - } - else - { - if(( dwCounter % 50 ) == 0 ) - { - TCHAR tszText[DEFAULT_BUFFER]; + GetButtonText( aButtons[dwButtonID[2]], szBuffer ); + SendMessage( GetDlgItem( hDlg, dwButtonID[1] ), WM_SETTEXT , 0, (LPARAM)szBuffer ); + if( hFocus != NULL ) + { + SetFocus( hFocus ); + hFocus = NULL; + } + } + else + { + if(( dwCounter % 50 ) == 0 ) + { + TCHAR tszText[DEFAULT_BUFFER]; - LoadString( g_hResourceDLL, IDS_C_POLLING, tszText, DEFAULT_BUFFER ); - wsprintf( szBuffer, tszText, 10 - dwCounter / 50 ); - SendMessage( GetDlgItem( hDlg, dwButtonID[1] ), WM_SETTEXT , 0, (LPARAM)szBuffer ); - } - ++dwCounter; - } - return TRUE; - } - else - return FALSE; + LoadString( g_hResourceDLL, IDS_C_POLLING, tszText, DEFAULT_BUFFER ); + wsprintf( szBuffer, tszText, 10 - dwCounter / 50 ); + SendMessage( GetDlgItem( hDlg, dwButtonID[1] ), WM_SETTEXT , 0, (LPARAM)szBuffer ); + } + ++dwCounter; + } + return TRUE; + } + else + return FALSE; - case WM_HSCROLL: // TrackBars - case WM_VSCROLL: - switch ( GetWindowLong( (HWND)lParam, GWL_ID ) ) - { - case IDC_CTRRANGE: - TCHAR tszText[DEFAULT_BUFFER]; + case WM_HSCROLL: // TrackBars + case WM_VSCROLL: + switch ( GetWindowLong( (HWND)lParam, GWL_ID ) ) + { + case IDC_CTRRANGE: + TCHAR tszText[DEFAULT_BUFFER]; - LoadString( g_hResourceDLL, IDS_C_RANGE, tszText, DEFAULT_BUFFER ); - g_ivConfig->Controllers[g_ivConfig->ChosenTab].bStickRange = (BYTE)SendMessage( (HWND)lParam, TBM_GETPOS, 0, 0 ); - wsprintf( szBuffer, tszText, g_ivConfig->Controllers[g_ivConfig->ChosenTab].bStickRange ); - SendMessage( GetDlgItem( hDlg, IDT_RANGE ), WM_SETTEXT , 0, (LPARAM)szBuffer ); - return TRUE; - case IDC_RAPIDFIRERATE: - g_ivConfig->Controllers[g_ivConfig->ChosenTab].bRapidFireRate = 33 - (BYTE)SendMessage( (HWND)lParam, TBM_GETPOS, 0, 0 ); - return TRUE; - default: - return FALSE; - } + LoadString( g_hResourceDLL, IDS_C_RANGE, tszText, DEFAULT_BUFFER ); + g_ivConfig->Controllers[g_ivConfig->ChosenTab].bStickRange = (BYTE)SendMessage( (HWND)lParam, TBM_GETPOS, 0, 0 ); + wsprintf( szBuffer, tszText, g_ivConfig->Controllers[g_ivConfig->ChosenTab].bStickRange ); + SendMessage( GetDlgItem( hDlg, IDT_RANGE ), WM_SETTEXT , 0, (LPARAM)szBuffer ); + return TRUE; + case IDC_RAPIDFIRERATE: + g_ivConfig->Controllers[g_ivConfig->ChosenTab].bRapidFireRate = 33 - (BYTE)SendMessage( (HWND)lParam, TBM_GETPOS, 0, 0 ); + return TRUE; + default: + return FALSE; + } - case WM_USER_UPDATE: - bScanRunning = false; - KillTimer( hDlg, TIMER_BUTTON ); - EnterCriticalSection(&g_critical); - aButtons = g_ivConfig->Controllers[g_ivConfig->ChosenTab].aButton; - LeaveCriticalSection(&g_critical); + case WM_USER_UPDATE: + bScanRunning = false; + KillTimer( hDlg, TIMER_BUTTON ); + EnterCriticalSection(&g_critical); + aButtons = g_ivConfig->Controllers[g_ivConfig->ChosenTab].aButton; + LeaveCriticalSection(&g_critical); - if( wParam == 0 ) - { - CheckDlgButton( hDlg, IDC_N64RANGE, g_ivConfig->Controllers[g_ivConfig->ChosenTab].fRealN64Range ? BST_CHECKED : BST_UNCHECKED ); - CheckDlgButton( hDlg, IDC_RAPIDFIREENABLE, g_ivConfig->Controllers[g_ivConfig->ChosenTab].bRapidFireEnabled ? BST_CHECKED : BST_UNCHECKED ); - CheckDlgButton( hDlg, IDC_CONFIG1, ( g_ivConfig->Controllers[g_ivConfig->ChosenTab].bAxisSet == 0 ) ? BST_CHECKED : BST_UNCHECKED ); - CheckDlgButton( hDlg, IDC_CONFIG2, ( g_ivConfig->Controllers[g_ivConfig->ChosenTab].bAxisSet == 1 ) ? BST_CHECKED : BST_UNCHECKED ); - CheckDlgButton( hDlg, IDC_CONFIG3, ( g_ivConfig->Controllers[g_ivConfig->ChosenTab].bAxisSet == 2 ) ? BST_CHECKED : BST_UNCHECKED ); + if( wParam == 0 ) + { + CheckDlgButton( hDlg, IDC_N64RANGE, g_ivConfig->Controllers[g_ivConfig->ChosenTab].fRealN64Range ? BST_CHECKED : BST_UNCHECKED ); + CheckDlgButton( hDlg, IDC_RAPIDFIREENABLE, g_ivConfig->Controllers[g_ivConfig->ChosenTab].bRapidFireEnabled ? BST_CHECKED : BST_UNCHECKED ); + CheckDlgButton( hDlg, IDC_CONFIG1, ( g_ivConfig->Controllers[g_ivConfig->ChosenTab].bAxisSet == 0 ) ? BST_CHECKED : BST_UNCHECKED ); + CheckDlgButton( hDlg, IDC_CONFIG2, ( g_ivConfig->Controllers[g_ivConfig->ChosenTab].bAxisSet == 1 ) ? BST_CHECKED : BST_UNCHECKED ); + CheckDlgButton( hDlg, IDC_CONFIG3, ( g_ivConfig->Controllers[g_ivConfig->ChosenTab].bAxisSet == 2 ) ? BST_CHECKED : BST_UNCHECKED ); - SendMessage( GetDlgItem( hDlg, IDC_CTRRANGE ), TBM_SETPOS, TRUE, g_ivConfig->Controllers[g_ivConfig->ChosenTab].bStickRange ); - LoadString( g_hResourceDLL, IDS_C_RANGE, szTemp, 40 ); - wsprintf( szBuffer, szTemp, g_ivConfig->Controllers[g_ivConfig->ChosenTab].bStickRange ); - SendMessage( GetDlgItem( hDlg, IDT_RANGE ), WM_SETTEXT , 0, (LPARAM)szBuffer ); - SendMessage( GetDlgItem( hDlg, IDC_RAPIDFIRERATE ), TBM_SETPOS, TRUE, 33 - g_ivConfig->Controllers[g_ivConfig->ChosenTab].bRapidFireRate ); + SendMessage( GetDlgItem( hDlg, IDC_CTRRANGE ), TBM_SETPOS, TRUE, g_ivConfig->Controllers[g_ivConfig->ChosenTab].bStickRange ); + LoadString( g_hResourceDLL, IDS_C_RANGE, szTemp, 40 ); + wsprintf( szBuffer, szTemp, g_ivConfig->Controllers[g_ivConfig->ChosenTab].bStickRange ); + SendMessage( GetDlgItem( hDlg, IDT_RANGE ), WM_SETTEXT , 0, (LPARAM)szBuffer ); + SendMessage( GetDlgItem( hDlg, IDC_RAPIDFIRERATE ), TBM_SETPOS, TRUE, 33 - g_ivConfig->Controllers[g_ivConfig->ChosenTab].bRapidFireRate ); - i = 0; - } - else - i = PF_APADR; + i = 0; + } + else + i = PF_APADR; - for( ;i < 18; ++i ) - { - DWORD dwIDs[3]; - dwIDs[2] = i; - if( !GetButtonID( dwIDs, 2, BSET_CONTROLS )) - continue; + for( ;i < 18; ++i ) + { + DWORD dwIDs[3]; + dwIDs[2] = i; + if( !GetButtonID( dwIDs, 2, BSET_CONTROLS )) + continue; - if( dwIDs[2] >= PF_APADR ) - dwIDs[2] += g_ivConfig->Controllers[g_ivConfig->ChosenTab].bAxisSet * 4; + if( dwIDs[2] >= PF_APADR ) + dwIDs[2] += g_ivConfig->Controllers[g_ivConfig->ChosenTab].bAxisSet * 4; - GetButtonText( aButtons[dwIDs[2]], szBuffer ); - SendMessage( GetDlgItem( hDlg, dwIDs[1] ), WM_SETTEXT , 0, (LPARAM)szBuffer ); - } - return TRUE; + GetButtonText( aButtons[dwIDs[2]], szBuffer ); + SendMessage( GetDlgItem( hDlg, dwIDs[1] ), WM_SETTEXT , 0, (LPARAM)szBuffer ); + } + return TRUE; - default: - return FALSE; //false means the msg didn't got processed - } -// return TRUE; //msg got processed + default: + return FALSE; //false means the msg didn't got processed + } +// return TRUE; //msg got processed } -// XInput controllers tab --tecnicors +// XInput controllers tab --tecnicors BOOL CALLBACK XControlsTabProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) { - LPXCONTROLLER gController = &g_ivConfig->Controllers[g_ivConfig->ChosenTab].xiController; + LPXCONTROLLER gController = &g_ivConfig->Controllers[g_ivConfig->ChosenTab].xiController; - switch( uMsg ) - { - case WM_INITDIALOG: - for( int i = IDC_XC_A; i <= IDC_XC_START; i++ ) - FillN64ButtonComboBox( hDlg, i ); - for( int i = IDC_XC_DPAD; i <= IDC_XC_RTS; i++ ) - FillN64AnalogComboBox( hDlg, i ); - XControlsTabProc( hDlg, WM_USER_UPDATE, 0, 0 ); - return FALSE; + switch( uMsg ) + { + case WM_INITDIALOG: + for( int i = IDC_XC_A; i <= IDC_XC_START; i++ ) + FillN64ButtonComboBox( hDlg, i ); + for( int i = IDC_XC_DPAD; i <= IDC_XC_RTS; i++ ) + FillN64AnalogComboBox( hDlg, i ); + XControlsTabProc( hDlg, WM_USER_UPDATE, 0, 0 ); + return FALSE; - case WM_USER_UPDATE: - { - TCHAR buffer[MAX_PATH]; - GetDirectory( buffer, DIRECTORY_CONFIG ); - _stprintf_s( buffer, _T("%sXInput Controller %d Config.xcc"), buffer, gController->nControl + 1 ); - FILE *saveFile = _tfopen( buffer, _T("rS") ); - if( saveFile ) - { - LoadXInputConfigFromFile( saveFile, gController ); - fclose( saveFile ); - } - } - if( !ReadXInputControllerKeys( hDlg, gController )) - for( int i = IDC_XC_A; i <= IDC_XC_RTS; i++ ) - SendDlgItemMessage( hDlg, i, CB_SETCURSEL, 0, ( LPARAM )0 ); - return TRUE; + case WM_USER_UPDATE: + { + TCHAR buffer[MAX_PATH]; + GetDirectory( buffer, DIRECTORY_CONFIG ); + _stprintf_s( buffer, _T("%sXInput Controller %d Config.xcc"), buffer, gController->nControl + 1 ); + FILE *saveFile = _tfopen( buffer, _T("rS") ); + if( saveFile ) + { + LoadXInputConfigFromFile( saveFile, gController ); + fclose( saveFile ); + } + } + if( !ReadXInputControllerKeys( hDlg, gController )) + for( int i = IDC_XC_A; i <= IDC_XC_RTS; i++ ) + SendDlgItemMessage( hDlg, i, CB_SETCURSEL, 0, ( LPARAM )0 ); + return TRUE; - case WM_COMMAND: - switch( LOWORD( wParam )) - { - case IDC_XC_USE: - StoreXInputControllerKeys( hDlg, gController ); - { - TCHAR buffer[MAX_PATH]; - GetDirectory( buffer, DIRECTORY_CONFIG ); - _stprintf_s( buffer, _T("%sXInput Controller %d Config.xcc"), buffer, gController->nControl + 1 ); - FILE *saveFile = _tfopen( buffer, _T("wS") ); - SaveXInputConfigToFile( saveFile, gController ); - fclose( saveFile ); - } - return TRUE; - } - return FALSE; - default: - return FALSE; - } + case WM_COMMAND: + switch( LOWORD( wParam )) + { + case IDC_XC_USE: + StoreXInputControllerKeys( hDlg, gController ); + { + TCHAR buffer[MAX_PATH]; + GetDirectory( buffer, DIRECTORY_CONFIG ); + _stprintf_s( buffer, _T("%sXInput Controller %d Config.xcc"), buffer, gController->nControl + 1 ); + FILE *saveFile = _tfopen( buffer, _T("wS") ); + SaveXInputConfigToFile( saveFile, gController ); + fclose( saveFile ); + } + return TRUE; + } + return FALSE; + default: + return FALSE; + } }// END Xinput Controller Tab --tecnicors BOOL CALLBACK DevicesTabProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) { - CONTROLLER *pcController = &g_ivConfig->Controllers[g_ivConfig->ChosenTab]; - TCHAR szBuffer[DEFAULT_BUFFER], szTemp[DEFAULT_BUFFER]; - HWND hDlgItem; - long i; + CONTROLLER *pcController = &g_ivConfig->Controllers[g_ivConfig->ChosenTab]; + TCHAR szBuffer[DEFAULT_BUFFER], szTemp[DEFAULT_BUFFER]; + HWND hDlgItem; + long i; - switch(uMsg) - { - case WM_INITDIALOG: + switch(uMsg) + { + case WM_INITDIALOG: - // TrackBars - hDlgItem = GetDlgItem( hDlg, IDC_DEADZONE ); + // TrackBars + hDlgItem = GetDlgItem( hDlg, IDC_DEADZONE ); - SendMessage( hDlgItem, TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG( 0, 100 )); - SendMessage( hDlgItem, TBM_SETTICFREQ, (WPARAM) 10, 0 ); - SendMessage( hDlgItem, TBM_SETPAGESIZE, (WPARAM) 0, 1 ); + SendMessage( hDlgItem, TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG( 0, 100 )); + SendMessage( hDlgItem, TBM_SETTICFREQ, (WPARAM) 10, 0 ); + SendMessage( hDlgItem, TBM_SETPAGESIZE, (WPARAM) 0, 1 ); - hDlgItem = GetDlgItem( hDlg, IDC_MSSENSITIVITY_X ); + hDlgItem = GetDlgItem( hDlg, IDC_MSSENSITIVITY_X ); - SendMessage( hDlgItem, TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG( 0, 1000 )); - SendMessage( hDlgItem, TBM_SETPAGESIZE, (WPARAM) 0, 1 ); + SendMessage( hDlgItem, TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG( 0, 1000 )); + SendMessage( hDlgItem, TBM_SETPAGESIZE, (WPARAM) 0, 1 ); - hDlgItem = GetDlgItem( hDlg, IDC_MSSENSITIVITY_Y ); + hDlgItem = GetDlgItem( hDlg, IDC_MSSENSITIVITY_Y ); - SendMessage( hDlgItem, TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG( 0, 1000 )); - SendMessage( hDlgItem, TBM_SETPAGESIZE, (WPARAM) 0, 1 ); - { - short sTics[] = { 25, 50, 75, 100, 125, 150, 200, 250, 300, 400, 500, 600, 700, 800, 900 }; - for( i = 0; i < (sizeof(sTics) / sizeof(short)); ++i ) - SendMessage( hDlgItem, TBM_SETTIC, 0, sTics[i] ); - } - // TrackBars End + SendMessage( hDlgItem, TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG( 0, 1000 )); + SendMessage( hDlgItem, TBM_SETPAGESIZE, (WPARAM) 0, 1 ); + { + short sTics[] = { 25, 50, 75, 100, 125, 150, 200, 250, 300, 400, 500, 600, 700, 800, 900 }; + for( i = 0; i < (sizeof(sTics) / sizeof(short)); ++i ) + SendMessage( hDlgItem, TBM_SETTIC, 0, sTics[i] ); + } + // TrackBars End - DevicesTabProc( hDlg, WM_USER_UPDATE, 0, 0 ); // setting values + DevicesTabProc( hDlg, WM_USER_UPDATE, 0, 0 ); // setting values - return FALSE; // don't give it focus + return FALSE; // don't give it focus - case WM_COMMAND: - hDlgItem = GetDlgItem( hDlg, LOWORD(wParam) ); + case WM_COMMAND: + hDlgItem = GetDlgItem( hDlg, LOWORD(wParam) ); - switch( LOWORD(wParam) ) - { - case IDC_DEADPANMOUSEX: - if( LOWORD(wParam) == IDC_DEADPANMOUSEX ) - i = MM_DEAD; - case IDC_BUFFEREDMOUSEX: - if( LOWORD(wParam) == IDC_BUFFEREDMOUSEX ) - i = MM_BUFF; - case IDC_ABSOLUTEMOUSEX: - if( LOWORD(wParam) == IDC_ABSOLUTEMOUSEX ) - i = MM_ABS; - if(( HIWORD(wParam) == BN_CLICKED ) && ( IsDlgButtonChecked( hDlg, LOWORD(wParam) ) == BST_CHECKED )) - pcController->bMouseMoveX = i; - return TRUE; + switch( LOWORD(wParam) ) + { + case IDC_DEADPANMOUSEX: + if( LOWORD(wParam) == IDC_DEADPANMOUSEX ) + i = MM_DEAD; + case IDC_BUFFEREDMOUSEX: + if( LOWORD(wParam) == IDC_BUFFEREDMOUSEX ) + i = MM_BUFF; + case IDC_ABSOLUTEMOUSEX: + if( LOWORD(wParam) == IDC_ABSOLUTEMOUSEX ) + i = MM_ABS; + if(( HIWORD(wParam) == BN_CLICKED ) && ( IsDlgButtonChecked( hDlg, LOWORD(wParam) ) == BST_CHECKED )) + pcController->bMouseMoveX = i; + return TRUE; - case IDC_DEADPANMOUSEY: - if( LOWORD(wParam) == IDC_DEADPANMOUSEY ) - i = MM_DEAD; - case IDC_BUFFEREDMOUSEY: - if( LOWORD(wParam) == IDC_BUFFEREDMOUSEY ) - i = MM_BUFF; - case IDC_ABSOLUTEMOUSEY: - if( LOWORD(wParam) == IDC_ABSOLUTEMOUSEY ) - i = MM_ABS; - if(( HIWORD(wParam) == BN_CLICKED ) && ( IsDlgButtonChecked( hDlg, LOWORD(wParam) ) == BST_CHECKED )) - pcController->bMouseMoveY = i; - return TRUE; + case IDC_DEADPANMOUSEY: + if( LOWORD(wParam) == IDC_DEADPANMOUSEY ) + i = MM_DEAD; + case IDC_BUFFEREDMOUSEY: + if( LOWORD(wParam) == IDC_BUFFEREDMOUSEY ) + i = MM_BUFF; + case IDC_ABSOLUTEMOUSEY: + if( LOWORD(wParam) == IDC_ABSOLUTEMOUSEY ) + i = MM_ABS; + if(( HIWORD(wParam) == BN_CLICKED ) && ( IsDlgButtonChecked( hDlg, LOWORD(wParam) ) == BST_CHECKED )) + pcController->bMouseMoveY = i; + return TRUE; - case IDC_ACCELERATEX: - pcController->fKeyAbsoluteX = ( IsDlgButtonChecked( hDlg, LOWORD(wParam) ) == BST_CHECKED ); - return TRUE; - case IDC_ACCELERATEY: - pcController->fKeyAbsoluteY = ( IsDlgButtonChecked( hDlg, LOWORD(wParam) ) == BST_CHECKED ); - return TRUE; + case IDC_ACCELERATEX: + pcController->fKeyAbsoluteX = ( IsDlgButtonChecked( hDlg, LOWORD(wParam) ) == BST_CHECKED ); + return TRUE; + case IDC_ACCELERATEY: + pcController->fKeyAbsoluteY = ( IsDlgButtonChecked( hDlg, LOWORD(wParam) ) == BST_CHECKED ); + return TRUE; - default: - return FALSE; - } + default: + return FALSE; + } - case WM_HSCROLL: // TrackBars - case WM_VSCROLL: - i = GetWindowLong( (HWND)lParam, GWL_ID ); - switch( i ) - { - case IDC_MSSENSITIVITY_X: - pcController->wMouseSensitivityX = (WORD)SendMessage( (HWND)lParam, TBM_GETPOS, 0, 0 ); - LoadString( g_hResourceDLL, IDS_D_MSX, szTemp, DEFAULT_BUFFER ); - wsprintf( szBuffer, szTemp, pcController->wMouseSensitivityX ); - SendMessage( GetDlgItem( hDlg, IDT_MSSENSITIVITY_X ), WM_SETTEXT , 0, (LPARAM)szBuffer ); - return TRUE; + case WM_HSCROLL: // TrackBars + case WM_VSCROLL: + i = GetWindowLong( (HWND)lParam, GWL_ID ); + switch( i ) + { + case IDC_MSSENSITIVITY_X: + pcController->wMouseSensitivityX = (WORD)SendMessage( (HWND)lParam, TBM_GETPOS, 0, 0 ); + LoadString( g_hResourceDLL, IDS_D_MSX, szTemp, DEFAULT_BUFFER ); + wsprintf( szBuffer, szTemp, pcController->wMouseSensitivityX ); + SendMessage( GetDlgItem( hDlg, IDT_MSSENSITIVITY_X ), WM_SETTEXT , 0, (LPARAM)szBuffer ); + return TRUE; - case IDC_MSSENSITIVITY_Y: - pcController->wMouseSensitivityY = (WORD)SendMessage( (HWND)lParam, TBM_GETPOS, 0, 0 ); - LoadString( g_hResourceDLL, IDS_D_MSY, szTemp, DEFAULT_BUFFER ); - wsprintf( szBuffer, szTemp, pcController->wMouseSensitivityY ); - SendMessage( GetDlgItem( hDlg, IDT_MSSENSITIVITY_Y ), WM_SETTEXT , 0, (LPARAM)szBuffer ); - return TRUE; + case IDC_MSSENSITIVITY_Y: + pcController->wMouseSensitivityY = (WORD)SendMessage( (HWND)lParam, TBM_GETPOS, 0, 0 ); + LoadString( g_hResourceDLL, IDS_D_MSY, szTemp, DEFAULT_BUFFER ); + wsprintf( szBuffer, szTemp, pcController->wMouseSensitivityY ); + SendMessage( GetDlgItem( hDlg, IDT_MSSENSITIVITY_Y ), WM_SETTEXT , 0, (LPARAM)szBuffer ); + return TRUE; - case IDC_DEADZONE: - pcController->bPadDeadZone = (BYTE)SendMessage( (HWND)lParam, TBM_GETPOS, 0, 0 ); - LoadString( g_hResourceDLL, IDS_D_DEADZONE, szTemp, DEFAULT_BUFFER ); - wsprintf( szBuffer, szTemp, pcController->bPadDeadZone ); - SendMessage( GetDlgItem( hDlg, IDT_DEADZONE ), WM_SETTEXT , 0, (LPARAM)szBuffer ); - return TRUE; - default: - return FALSE; - } + case IDC_DEADZONE: + pcController->bPadDeadZone = (BYTE)SendMessage( (HWND)lParam, TBM_GETPOS, 0, 0 ); + LoadString( g_hResourceDLL, IDS_D_DEADZONE, szTemp, DEFAULT_BUFFER ); + wsprintf( szBuffer, szTemp, pcController->bPadDeadZone ); + SendMessage( GetDlgItem( hDlg, IDT_DEADZONE ), WM_SETTEXT , 0, (LPARAM)szBuffer ); + return TRUE; + default: + return FALSE; + } - case WM_USER_UPDATE: - if( pcController->bMouseMoveX == MM_DEAD ) - CheckDlgButton( hDlg, IDC_DEADPANMOUSEX, BST_CHECKED ); - else - CheckDlgButton( hDlg, IDC_DEADPANMOUSEX, BST_UNCHECKED ); + case WM_USER_UPDATE: + if( pcController->bMouseMoveX == MM_DEAD ) + CheckDlgButton( hDlg, IDC_DEADPANMOUSEX, BST_CHECKED ); + else + CheckDlgButton( hDlg, IDC_DEADPANMOUSEX, BST_UNCHECKED ); - if( pcController->bMouseMoveX == MM_BUFF ) - CheckDlgButton( hDlg, IDC_BUFFEREDMOUSEX, BST_CHECKED ); - else - CheckDlgButton( hDlg, IDC_BUFFEREDMOUSEX, BST_UNCHECKED ); + if( pcController->bMouseMoveX == MM_BUFF ) + CheckDlgButton( hDlg, IDC_BUFFEREDMOUSEX, BST_CHECKED ); + else + CheckDlgButton( hDlg, IDC_BUFFEREDMOUSEX, BST_UNCHECKED ); - if( pcController->bMouseMoveX == MM_ABS ) - CheckDlgButton( hDlg, IDC_ABSOLUTEMOUSEX, BST_CHECKED ); - else - CheckDlgButton( hDlg, IDC_ABSOLUTEMOUSEX, BST_UNCHECKED ); + if( pcController->bMouseMoveX == MM_ABS ) + CheckDlgButton( hDlg, IDC_ABSOLUTEMOUSEX, BST_CHECKED ); + else + CheckDlgButton( hDlg, IDC_ABSOLUTEMOUSEX, BST_UNCHECKED ); - if( pcController->bMouseMoveY == MM_DEAD ) - CheckDlgButton( hDlg, IDC_DEADPANMOUSEY, BST_CHECKED ); - else - CheckDlgButton( hDlg, IDC_DEADPANMOUSEY, BST_UNCHECKED ); + if( pcController->bMouseMoveY == MM_DEAD ) + CheckDlgButton( hDlg, IDC_DEADPANMOUSEY, BST_CHECKED ); + else + CheckDlgButton( hDlg, IDC_DEADPANMOUSEY, BST_UNCHECKED ); - if( pcController->bMouseMoveY == MM_BUFF ) - CheckDlgButton( hDlg, IDC_BUFFEREDMOUSEY, BST_CHECKED ); - else - CheckDlgButton( hDlg, IDC_BUFFEREDMOUSEY, BST_UNCHECKED ); + if( pcController->bMouseMoveY == MM_BUFF ) + CheckDlgButton( hDlg, IDC_BUFFEREDMOUSEY, BST_CHECKED ); + else + CheckDlgButton( hDlg, IDC_BUFFEREDMOUSEY, BST_UNCHECKED ); - if( pcController->bMouseMoveY == MM_ABS ) - CheckDlgButton( hDlg, IDC_ABSOLUTEMOUSEY, BST_CHECKED ); - else - CheckDlgButton( hDlg, IDC_ABSOLUTEMOUSEY, BST_UNCHECKED ); + if( pcController->bMouseMoveY == MM_ABS ) + CheckDlgButton( hDlg, IDC_ABSOLUTEMOUSEY, BST_CHECKED ); + else + CheckDlgButton( hDlg, IDC_ABSOLUTEMOUSEY, BST_UNCHECKED ); - CheckDlgButton( hDlg, IDC_ACCELERATEX, pcController->fKeyAbsoluteX ? BST_CHECKED : BST_UNCHECKED ); - CheckDlgButton( hDlg, IDC_ACCELERATEY, pcController->fKeyAbsoluteY ? BST_CHECKED : BST_UNCHECKED ); + CheckDlgButton( hDlg, IDC_ACCELERATEX, pcController->fKeyAbsoluteX ? BST_CHECKED : BST_UNCHECKED ); + CheckDlgButton( hDlg, IDC_ACCELERATEY, pcController->fKeyAbsoluteY ? BST_CHECKED : BST_UNCHECKED ); - // TrackBars - SendMessage( GetDlgItem( hDlg, IDC_DEADZONE ), TBM_SETPOS, TRUE, pcController->bPadDeadZone ); - LoadString( g_hResourceDLL, IDS_D_DEADZONE, szTemp, DEFAULT_BUFFER ); - wsprintf( szBuffer, szTemp, pcController->bPadDeadZone ); - SendMessage( GetDlgItem( hDlg, IDT_DEADZONE ), WM_SETTEXT , 0, (LPARAM)szBuffer ); + // TrackBars + SendMessage( GetDlgItem( hDlg, IDC_DEADZONE ), TBM_SETPOS, TRUE, pcController->bPadDeadZone ); + LoadString( g_hResourceDLL, IDS_D_DEADZONE, szTemp, DEFAULT_BUFFER ); + wsprintf( szBuffer, szTemp, pcController->bPadDeadZone ); + SendMessage( GetDlgItem( hDlg, IDT_DEADZONE ), WM_SETTEXT , 0, (LPARAM)szBuffer ); - SendMessage( GetDlgItem( hDlg, IDC_MSSENSITIVITY_X ), TBM_SETPOS, TRUE, pcController->wMouseSensitivityX ); - LoadString( g_hResourceDLL, IDS_D_MSX, szTemp, DEFAULT_BUFFER ); - wsprintf( szBuffer, szTemp, pcController->wMouseSensitivityX ); - SendMessage( GetDlgItem( hDlg, IDT_MSSENSITIVITY_X ), WM_SETTEXT , 0, (LPARAM)szBuffer ); + SendMessage( GetDlgItem( hDlg, IDC_MSSENSITIVITY_X ), TBM_SETPOS, TRUE, pcController->wMouseSensitivityX ); + LoadString( g_hResourceDLL, IDS_D_MSX, szTemp, DEFAULT_BUFFER ); + wsprintf( szBuffer, szTemp, pcController->wMouseSensitivityX ); + SendMessage( GetDlgItem( hDlg, IDT_MSSENSITIVITY_X ), WM_SETTEXT , 0, (LPARAM)szBuffer ); - SendMessage( GetDlgItem( hDlg, IDC_MSSENSITIVITY_Y ), TBM_SETPOS, TRUE, pcController->wMouseSensitivityY ); - LoadString( g_hResourceDLL, IDS_D_MSY, szTemp, DEFAULT_BUFFER ); - wsprintf( szBuffer, szTemp, pcController->wMouseSensitivityY ); - SendMessage( GetDlgItem( hDlg, IDT_MSSENSITIVITY_Y ), WM_SETTEXT , 0, (LPARAM)szBuffer ); - // TrackBars End - return TRUE; + SendMessage( GetDlgItem( hDlg, IDC_MSSENSITIVITY_Y ), TBM_SETPOS, TRUE, pcController->wMouseSensitivityY ); + LoadString( g_hResourceDLL, IDS_D_MSY, szTemp, DEFAULT_BUFFER ); + wsprintf( szBuffer, szTemp, pcController->wMouseSensitivityY ); + SendMessage( GetDlgItem( hDlg, IDT_MSSENSITIVITY_Y ), WM_SETTEXT , 0, (LPARAM)szBuffer ); + // TrackBars End + return TRUE; - default: - return FALSE; //false means the msg didn't got processed - } + default: + return FALSE; //false means the msg didn't got processed + } } BOOL CALLBACK MoveModifierDialog( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) { - HWND hDlgItem; - long i,j; - DWORD dwValue; - TCHAR szBuffer[DEFAULT_BUFFER], szTemp[DEFAULT_BUFFER]; + HWND hDlgItem; + long i,j; + DWORD dwValue; + TCHAR szBuffer[DEFAULT_BUFFER], szTemp[DEFAULT_BUFFER]; - switch(uMsg) - { - case WM_INITDIALOG: - // TrackBars - hDlgItem = GetDlgItem( hDlg, IDC_XMODIFIER ); + switch(uMsg) + { + case WM_INITDIALOG: + // TrackBars + hDlgItem = GetDlgItem( hDlg, IDC_XMODIFIER ); - SendMessage( hDlgItem, TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG( 0, 500 )); - SendMessage( hDlgItem, TBM_SETPAGESIZE, (WPARAM) 0, 1 ); - { - short sTics[] = { 25, 50, 75, 100, 125, 150, 200, 250, 300, 400, 500 }; - for( i = 0; i < (sizeof(sTics) / sizeof(short)); ++i ) - SendMessage( hDlgItem, TBM_SETTIC, 0, sTics[i] ); - } + SendMessage( hDlgItem, TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG( 0, 500 )); + SendMessage( hDlgItem, TBM_SETPAGESIZE, (WPARAM) 0, 1 ); + { + short sTics[] = { 25, 50, 75, 100, 125, 150, 200, 250, 300, 400, 500 }; + for( i = 0; i < (sizeof(sTics) / sizeof(short)); ++i ) + SendMessage( hDlgItem, TBM_SETTIC, 0, sTics[i] ); + } - hDlgItem = GetDlgItem( hDlg, IDC_YMODIFIER ); + hDlgItem = GetDlgItem( hDlg, IDC_YMODIFIER ); - SendMessage( hDlgItem, TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG( 0, 500 )); - SendMessage( hDlgItem, TBM_SETPAGESIZE, (WPARAM) 0, 1 ); - { - short sTics[] = { 25, 50, 75, 100, 125, 150, 200, 250, 300, 400, 500 }; - for( i = 0; i < (sizeof(sTics) / sizeof(short)); ++i ) - SendMessage( hDlgItem, TBM_SETTIC, 0, sTics[i] ); - } - return FALSE; // don't give it focus + SendMessage( hDlgItem, TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG( 0, 500 )); + SendMessage( hDlgItem, TBM_SETPAGESIZE, (WPARAM) 0, 1 ); + { + short sTics[] = { 25, 50, 75, 100, 125, 150, 200, 250, 300, 400, 500 }; + for( i = 0; i < (sizeof(sTics) / sizeof(short)); ++i ) + SendMessage( hDlgItem, TBM_SETTIC, 0, sTics[i] ); + } + return FALSE; // don't give it focus - case WM_HSCROLL: // TrackBars - case WM_VSCROLL: - switch (GetWindowLong( (HWND)lParam, GWL_ID )) - { - case IDC_XMODIFIER: - i = SendMessage( (HWND)lParam, TBM_GETPOS, 0, 0 ); - LoadString( g_hResourceDLL, IDS_M_MOVEVALUE, szTemp, DEFAULT_BUFFER ); - wsprintf( szBuffer, szTemp, i ); - SendMessage( GetDlgItem( hDlg, IDT_XMODIFIER ), WM_SETTEXT , 0, (LPARAM)szBuffer ); - return TRUE; - case IDC_YMODIFIER: - i = SendMessage( (HWND)lParam, TBM_GETPOS, 0, 0 ); - LoadString( g_hResourceDLL, IDS_M_MOVEVALUE, szTemp, DEFAULT_BUFFER ); - wsprintf( szBuffer, szTemp, i ); - SendMessage( GetDlgItem( hDlg, IDT_YMODIFIER ), WM_SETTEXT , 0, (LPARAM)szBuffer ); - return TRUE; - default: - return FALSE; - } + case WM_HSCROLL: // TrackBars + case WM_VSCROLL: + switch (GetWindowLong( (HWND)lParam, GWL_ID )) + { + case IDC_XMODIFIER: + i = SendMessage( (HWND)lParam, TBM_GETPOS, 0, 0 ); + LoadString( g_hResourceDLL, IDS_M_MOVEVALUE, szTemp, DEFAULT_BUFFER ); + wsprintf( szBuffer, szTemp, i ); + SendMessage( GetDlgItem( hDlg, IDT_XMODIFIER ), WM_SETTEXT , 0, (LPARAM)szBuffer ); + return TRUE; + case IDC_YMODIFIER: + i = SendMessage( (HWND)lParam, TBM_GETPOS, 0, 0 ); + LoadString( g_hResourceDLL, IDS_M_MOVEVALUE, szTemp, DEFAULT_BUFFER ); + wsprintf( szBuffer, szTemp, i ); + SendMessage( GetDlgItem( hDlg, IDT_YMODIFIER ), WM_SETTEXT , 0, (LPARAM)szBuffer ); + return TRUE; + default: + return FALSE; + } - case WM_USER_UPDATE: - if( wParam == MDT_MOVE ) - dwValue = (DWORD)lParam; - else - dwValue = MAKELONG( 100, 100 ); + case WM_USER_UPDATE: + if( wParam == MDT_MOVE ) + dwValue = (DWORD)lParam; + else + dwValue = MAKELONG( 100, 100 ); - i = (short)(dwValue & 0x0000FFFF); + i = (short)(dwValue & 0x0000FFFF); - if( i < 0 ) - { - i = -i; - CheckDlgButton( hDlg, IDC_XNEGATE, BST_CHECKED ); - } - else - CheckDlgButton( hDlg, IDC_XNEGATE, BST_UNCHECKED ); - SendMessage( GetDlgItem( hDlg, IDC_XMODIFIER ), TBM_SETPOS, TRUE, i ); - LoadString( g_hResourceDLL, IDS_M_MOVEVALUE, szTemp, DEFAULT_BUFFER ); - wsprintf( szBuffer, szTemp, i ); - SendMessage( GetDlgItem( hDlg, IDT_XMODIFIER ), WM_SETTEXT , 0, (LPARAM)szBuffer ); + if( i < 0 ) + { + i = -i; + CheckDlgButton( hDlg, IDC_XNEGATE, BST_CHECKED ); + } + else + CheckDlgButton( hDlg, IDC_XNEGATE, BST_UNCHECKED ); + SendMessage( GetDlgItem( hDlg, IDC_XMODIFIER ), TBM_SETPOS, TRUE, i ); + LoadString( g_hResourceDLL, IDS_M_MOVEVALUE, szTemp, DEFAULT_BUFFER ); + wsprintf( szBuffer, szTemp, i ); + SendMessage( GetDlgItem( hDlg, IDT_XMODIFIER ), WM_SETTEXT , 0, (LPARAM)szBuffer ); - i = (short)((dwValue >> 16) & 0x0000FFFF); + i = (short)((dwValue >> 16) & 0x0000FFFF); - if( i < 0 ) - { - i = -i; - CheckDlgButton( hDlg, IDC_YNEGATE, BST_CHECKED ); - } - else - CheckDlgButton( hDlg, IDC_YNEGATE, BST_UNCHECKED ); - SendMessage( GetDlgItem( hDlg, IDC_YMODIFIER ), TBM_SETPOS, TRUE, i ); - LoadString( g_hResourceDLL, IDS_M_MOVEVALUE, szTemp, DEFAULT_BUFFER ); - wsprintf( szBuffer, szTemp, i ); - SendMessage( GetDlgItem( hDlg, IDT_YMODIFIER ), WM_SETTEXT , 0, (LPARAM)szBuffer ); - return TRUE; + if( i < 0 ) + { + i = -i; + CheckDlgButton( hDlg, IDC_YNEGATE, BST_CHECKED ); + } + else + CheckDlgButton( hDlg, IDC_YNEGATE, BST_UNCHECKED ); + SendMessage( GetDlgItem( hDlg, IDC_YMODIFIER ), TBM_SETPOS, TRUE, i ); + LoadString( g_hResourceDLL, IDS_M_MOVEVALUE, szTemp, DEFAULT_BUFFER ); + wsprintf( szBuffer, szTemp, i ); + SendMessage( GetDlgItem( hDlg, IDT_YMODIFIER ), WM_SETTEXT , 0, (LPARAM)szBuffer ); + return TRUE; - case WM_USER_READVALUES: - i = SendMessage( GetDlgItem( hDlg, IDC_XMODIFIER ), TBM_GETPOS, 0, 0 ); - if( IsDlgButtonChecked( hDlg, IDC_XNEGATE ) == BST_CHECKED ) - i = -i; + case WM_USER_READVALUES: + i = SendMessage( GetDlgItem( hDlg, IDC_XMODIFIER ), TBM_GETPOS, 0, 0 ); + if( IsDlgButtonChecked( hDlg, IDC_XNEGATE ) == BST_CHECKED ) + i = -i; - j = SendMessage( GetDlgItem( hDlg, IDC_YMODIFIER ), TBM_GETPOS, 0, 0 ); - if( IsDlgButtonChecked( hDlg, IDC_YNEGATE ) == BST_CHECKED ) - j = -j; + j = SendMessage( GetDlgItem( hDlg, IDC_YMODIFIER ), TBM_GETPOS, 0, 0 ); + if( IsDlgButtonChecked( hDlg, IDC_YNEGATE ) == BST_CHECKED ) + j = -j; - *(DWORD*)wParam = MAKELONG( (short)i, (short)j ); - return TRUE; + *(DWORD*)wParam = MAKELONG( (short)i, (short)j ); + return TRUE; - default: - return FALSE; //false means the msg didn't got processed - } + default: + return FALSE; //false means the msg didn't got processed + } } BOOL CALLBACK MacroModifierDialog( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) { - long i; - DWORD dwValue; + long i; + DWORD dwValue; - const DWORD aButtons[] ={ IDC_DRIGHT , IDC_DLEFT , IDC_DDOWN , IDC_DUP, - IDC_SBUTTON , IDC_ZTRIG , IDC_BBUTTON , IDC_ABUTTON, - IDC_CRIGHT , IDC_CLEFT , IDC_CDOWN , IDC_CUP, - IDC_RTRIG , IDC_LTRIG , 0 , 0, - IDC_ARIGHT , IDC_ALEFT , IDC_ADOWN , IDC_AUP, - IDC_RAPIDFIREMODE , IDC_RAPIDFIREMODERATE }; + const DWORD aButtons[] ={ IDC_DRIGHT , IDC_DLEFT , IDC_DDOWN , IDC_DUP, + IDC_SBUTTON , IDC_ZTRIG , IDC_BBUTTON , IDC_ABUTTON, + IDC_CRIGHT , IDC_CLEFT , IDC_CDOWN , IDC_CUP, + IDC_RTRIG , IDC_LTRIG , 0 , 0, + IDC_ARIGHT , IDC_ALEFT , IDC_ADOWN , IDC_AUP, + IDC_RAPIDFIREMODE , IDC_RAPIDFIREMODERATE }; - switch(uMsg) - { - case WM_INITDIALOG: - return FALSE; // don't give it focus + switch(uMsg) + { + case WM_INITDIALOG: + return FALSE; // don't give it focus - case WM_USER_UPDATE: - if( wParam == MDT_MACRO ) - dwValue = (DWORD)lParam; - else - dwValue = 0; + case WM_USER_UPDATE: + if( wParam == MDT_MACRO ) + dwValue = (DWORD)lParam; + else + dwValue = 0; - i = sizeof(aButtons) / sizeof(aButtons[0]) - 1; + i = sizeof(aButtons) / sizeof(aButtons[0]) - 1; - while( i >= 0 ) - { - if( aButtons[i] ) - { - if( dwValue & ( 1 << i ) ) - CheckDlgButton( hDlg, aButtons[i], BST_CHECKED ); - else - CheckDlgButton( hDlg, aButtons[i], BST_UNCHECKED ); - } + while( i >= 0 ) + { + if( aButtons[i] ) + { + if( dwValue & ( 1 << i ) ) + CheckDlgButton( hDlg, aButtons[i], BST_CHECKED ); + else + CheckDlgButton( hDlg, aButtons[i], BST_UNCHECKED ); + } - i--; - } - return TRUE; + i--; + } + return TRUE; - case WM_USER_READVALUES: - dwValue = 0; + case WM_USER_READVALUES: + dwValue = 0; - i = sizeof(aButtons) / sizeof(aButtons[0]) - 1; - while( i >= 0 ) - { - if( aButtons[i] && ( IsDlgButtonChecked( hDlg, aButtons[i] ) == BST_CHECKED )) - dwValue = dwValue | ( 1 << i ); + i = sizeof(aButtons) / sizeof(aButtons[0]) - 1; + while( i >= 0 ) + { + if( aButtons[i] && ( IsDlgButtonChecked( hDlg, aButtons[i] ) == BST_CHECKED )) + dwValue = dwValue | ( 1 << i ); - i--; - } + i--; + } - *(DWORD*)wParam = dwValue; - return TRUE; + *(DWORD*)wParam = dwValue; + return TRUE; - default: - return FALSE; //false means the msg didn't got processed - } + default: + return FALSE; //false means the msg didn't got processed + } } BOOL CALLBACK ConfigModifierDialog( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) { - DWORD dwValue; + DWORD dwValue; - const DWORD aButtons[] ={ IDC_CONFIG1 , 0x000001, - IDC_CONFIG2 , 0x000003, - IDC_CONFIG3 , 0x000005, - IDC_CONFIGCYCLE , 0x0000FF, - IDC_MOUSEX , 0x000100, - IDC_MOUSEY , 0x000200, - IDC_KEYX , 0x010000, - IDC_KEYY , 0x020000 }; + const DWORD aButtons[] ={ IDC_CONFIG1 , 0x000001, + IDC_CONFIG2 , 0x000003, + IDC_CONFIG3 , 0x000005, + IDC_CONFIGCYCLE , 0x0000FF, + IDC_MOUSEX , 0x000100, + IDC_MOUSEY , 0x000200, + IDC_KEYX , 0x010000, + IDC_KEYY , 0x020000 }; - int i; + int i; - switch(uMsg) - { - case WM_INITDIALOG: - return FALSE; // don't give it focus + switch(uMsg) + { + case WM_INITDIALOG: + return FALSE; // don't give it focus - case WM_COMMAND: - switch( LOWORD(wParam) ) - { - case IDC_CONFIG1: - case IDC_CONFIG2: - case IDC_CONFIG3: - case IDC_CONFIGCYCLE: - if(( HIWORD(wParam) == BN_CLICKED ) || ( HIWORD(wParam) == BN_DBLCLK )) - { - EnterCriticalSection(&g_critical); // has a possibility of affecting the buttons we're writing to - bool bCheck = ( IsDlgButtonChecked( hDlg, LOWORD(wParam) ) == BST_CHECKED ) ? false : true; - CheckDlgButton( hDlg, IDC_CONFIG1, BST_UNCHECKED ); - CheckDlgButton( hDlg, IDC_CONFIG2, BST_UNCHECKED ); - CheckDlgButton( hDlg, IDC_CONFIG3, BST_UNCHECKED ); - CheckDlgButton( hDlg, IDC_CONFIGCYCLE, BST_UNCHECKED ); - if( bCheck ) - CheckDlgButton( hDlg, LOWORD(wParam), BST_CHECKED ); - LeaveCriticalSection(&g_critical); - } - return TRUE; - default: - return FALSE; - } + case WM_COMMAND: + switch( LOWORD(wParam) ) + { + case IDC_CONFIG1: + case IDC_CONFIG2: + case IDC_CONFIG3: + case IDC_CONFIGCYCLE: + if(( HIWORD(wParam) == BN_CLICKED ) || ( HIWORD(wParam) == BN_DBLCLK )) + { + EnterCriticalSection(&g_critical); // has a possibility of affecting the buttons we're writing to + bool bCheck = ( IsDlgButtonChecked( hDlg, LOWORD(wParam) ) == BST_CHECKED ) ? false : true; + CheckDlgButton( hDlg, IDC_CONFIG1, BST_UNCHECKED ); + CheckDlgButton( hDlg, IDC_CONFIG2, BST_UNCHECKED ); + CheckDlgButton( hDlg, IDC_CONFIG3, BST_UNCHECKED ); + CheckDlgButton( hDlg, IDC_CONFIGCYCLE, BST_UNCHECKED ); + if( bCheck ) + CheckDlgButton( hDlg, LOWORD(wParam), BST_CHECKED ); + LeaveCriticalSection(&g_critical); + } + return TRUE; + default: + return FALSE; + } - case WM_USER_UPDATE: - if( wParam == MDT_CONFIG ) - dwValue = (DWORD)lParam; - else - dwValue = 0; - if( dwValue & 0x01 ) - { - BYTE bConfig = (BYTE)((dwValue >> 1) & 0x7F); - if( bConfig >= PF_AXESETS ) - { - CheckDlgButton( hDlg, IDC_CONFIG1, BST_UNCHECKED ); - CheckDlgButton( hDlg, IDC_CONFIG2, BST_UNCHECKED ); - CheckDlgButton( hDlg, IDC_CONFIG3, BST_UNCHECKED ); - CheckDlgButton( hDlg, IDC_CONFIGCYCLE, BST_CHECKED ); - } - else - { - i = PF_AXESETS - 1; - while( i >= 0 ) - { - if( bConfig == i ) - CheckDlgButton( hDlg, aButtons[i*2], BST_CHECKED ); - else - CheckDlgButton( hDlg, aButtons[i*2], BST_UNCHECKED ); + case WM_USER_UPDATE: + if( wParam == MDT_CONFIG ) + dwValue = (DWORD)lParam; + else + dwValue = 0; + if( dwValue & 0x01 ) + { + BYTE bConfig = (BYTE)((dwValue >> 1) & 0x7F); + if( bConfig >= PF_AXESETS ) + { + CheckDlgButton( hDlg, IDC_CONFIG1, BST_UNCHECKED ); + CheckDlgButton( hDlg, IDC_CONFIG2, BST_UNCHECKED ); + CheckDlgButton( hDlg, IDC_CONFIG3, BST_UNCHECKED ); + CheckDlgButton( hDlg, IDC_CONFIGCYCLE, BST_CHECKED ); + } + else + { + i = PF_AXESETS - 1; + while( i >= 0 ) + { + if( bConfig == i ) + CheckDlgButton( hDlg, aButtons[i*2], BST_CHECKED ); + else + CheckDlgButton( hDlg, aButtons[i*2], BST_UNCHECKED ); - i--; - } - } - } + i--; + } + } + } - i = sizeof(aButtons) / sizeof(aButtons[0]) - 2; - while( i >= 8 ) - { - if(( dwValue & aButtons[i+1] ) == aButtons[i+1] ) - CheckDlgButton( hDlg, aButtons[i], BST_CHECKED ); - else - CheckDlgButton( hDlg, aButtons[i], BST_UNCHECKED ); + i = sizeof(aButtons) / sizeof(aButtons[0]) - 2; + while( i >= 8 ) + { + if(( dwValue & aButtons[i+1] ) == aButtons[i+1] ) + CheckDlgButton( hDlg, aButtons[i], BST_CHECKED ); + else + CheckDlgButton( hDlg, aButtons[i], BST_UNCHECKED ); - i -= 2; - } - return TRUE; + i -= 2; + } + return TRUE; - case WM_USER_READVALUES: - dwValue = 0; + case WM_USER_READVALUES: + dwValue = 0; - i = sizeof(aButtons) / sizeof(aButtons[0]) - 2; - while( i >= 0 ) - { - if( IsDlgButtonChecked( hDlg, aButtons[i] ) == BST_CHECKED ) - dwValue |= aButtons[i+1]; - i -= 2; - } + i = sizeof(aButtons) / sizeof(aButtons[0]) - 2; + while( i >= 0 ) + { + if( IsDlgButtonChecked( hDlg, aButtons[i] ) == BST_CHECKED ) + dwValue |= aButtons[i+1]; + i -= 2; + } - *(DWORD*)wParam = dwValue; - return TRUE; + *(DWORD*)wParam = dwValue; + return TRUE; - default: - return FALSE; //false means the msg didn't got processed - } + default: + return FALSE; //false means the msg didn't got processed + } } void ModDescription( HWND hListView, int iEntry, const LPMODIFIER pModifier ) { - TCHAR szBuffer[DEFAULT_BUFFER]; - const UINT iModTypes[] = { IDS_M_TAB_NONE, IDS_M_TAB_MOVE, IDS_M_TAB_MACRO, IDS_M_TAB_CONFIG }; - TCHAR pszModTypes[4][16]; + TCHAR szBuffer[DEFAULT_BUFFER]; + const UINT iModTypes[] = { IDS_M_TAB_NONE, IDS_M_TAB_MOVE, IDS_M_TAB_MACRO, IDS_M_TAB_CONFIG }; + TCHAR pszModTypes[4][16]; - for (int i = 0; i < ARRAYSIZE(iModTypes); i++ ) - LoadString( g_hResourceDLL, iModTypes[i], pszModTypes[i], ARRAYSIZE(pszModTypes[i]) ); + for (int i = 0; i < ARRAYSIZE(iModTypes); i++ ) + LoadString( g_hResourceDLL, iModTypes[i], pszModTypes[i], ARRAYSIZE(pszModTypes[i]) ); - GetButtonText( pModifier->btnButton, szBuffer ); + GetButtonText( pModifier->btnButton, szBuffer ); - ListView_SetItemText( hListView, iEntry, 0,szBuffer ); + ListView_SetItemText( hListView, iEntry, 0,szBuffer ); - switch( pModifier->bModType ) - { - case MDT_MOVE: - ListView_SetItemText( hListView, iEntry, 1, pszModTypes[1] ); - wsprintf( szBuffer, _T("X:%i%% / Y:%i%%"), (short)(pModifier->dwSpecific & 0x0000FFFF), (short)((pModifier->dwSpecific >> 16) & 0x0000FFFF)); - break; - case MDT_MACRO: - ListView_SetItemText( hListView, iEntry, 1, pszModTypes[2] ); - szBuffer[0] = '\0'; - { - bool bGotKey = false; - DWORD dwValue = pModifier->dwSpecific; - const TCHAR *apszButtons[] ={ _T("Dp->"), _T("Dp<-"), _T("Dp\\/"), _T("Dp/\\"), _T("St"), _T("Z"), _T("B"), _T("A"), - _T("Cb->"), _T("Cb<-"), _T("Cb\\/"), _T("Cb/\\"), _T("R"), _T("L"), NULL, NULL, - _T("As->"), _T("As<-"), _T("As\\/"), _T("As/\\"), _T("()") }; + switch( pModifier->bModType ) + { + case MDT_MOVE: + ListView_SetItemText( hListView, iEntry, 1, pszModTypes[1] ); + wsprintf( szBuffer, _T("X:%i%% / Y:%i%%"), (short)(pModifier->dwSpecific & 0x0000FFFF), (short)((pModifier->dwSpecific >> 16) & 0x0000FFFF)); + break; + case MDT_MACRO: + ListView_SetItemText( hListView, iEntry, 1, pszModTypes[2] ); + szBuffer[0] = '\0'; + { + bool bGotKey = false; + DWORD dwValue = pModifier->dwSpecific; + const TCHAR *apszButtons[] ={ _T("Dp->"), _T("Dp<-"), _T("Dp\\/"), _T("Dp/\\"), _T("St"), _T("Z"), _T("B"), _T("A"), + _T("Cb->"), _T("Cb<-"), _T("Cb\\/"), _T("Cb/\\"), _T("R"), _T("L"), NULL, NULL, + _T("As->"), _T("As<-"), _T("As\\/"), _T("As/\\"), _T("()") }; - int i = sizeof(apszButtons) / sizeof(apszButtons[0]) - 1; + int i = sizeof(apszButtons) / sizeof(apszButtons[0]) - 1; - while( i >= 0 ) - { - if( apszButtons[i] && ( dwValue & ( 1 << i ) )) - { - if( bGotKey ) - lstrcat( szBuffer, _T(" ") ); - else - bGotKey = true; + while( i >= 0 ) + { + if( apszButtons[i] && ( dwValue & ( 1 << i ) )) + { + if( bGotKey ) + lstrcat( szBuffer, _T(" ") ); + else + bGotKey = true; - lstrcat( szBuffer, apszButtons[i] ); - } + lstrcat( szBuffer, apszButtons[i] ); + } - i--; - } - } - break; - case MDT_CONFIG: - ListView_SetItemText( hListView, iEntry, 1, pszModTypes[3] ); - szBuffer[0] = '\0'; - { - DWORD dwValue = pModifier->dwSpecific; - bool bGotKey = false; + i--; + } + } + break; + case MDT_CONFIG: + ListView_SetItemText( hListView, iEntry, 1, pszModTypes[3] ); + szBuffer[0] = '\0'; + { + DWORD dwValue = pModifier->dwSpecific; + bool bGotKey = false; - if( dwValue & 0x1 ) - { - lstrcat( szBuffer, _T("C-") ); - if((( dwValue >> 1 ) & 0x7F ) < PF_AXESETS ) - wsprintf( &szBuffer[lstrlen(szBuffer)], _T("%i"), (( dwValue >> 1 ) & 0x7F )); - else - lstrcat( szBuffer, _T("Sw") ); - bGotKey = true; - } + if( dwValue & 0x1 ) + { + lstrcat( szBuffer, _T("C-") ); + if((( dwValue >> 1 ) & 0x7F ) < PF_AXESETS ) + wsprintf( &szBuffer[lstrlen(szBuffer)], _T("%i"), (( dwValue >> 1 ) & 0x7F )); + else + lstrcat( szBuffer, _T("Sw") ); + bGotKey = true; + } - if( dwValue & 0x300 ) - { - if( bGotKey ) - lstrcat( szBuffer, _T(" ") ); - else - bGotKey = true; + if( dwValue & 0x300 ) + { + if( bGotKey ) + lstrcat( szBuffer, _T(" ") ); + else + bGotKey = true; - lstrcat( szBuffer, _T("Ms-") ); - if( dwValue & 0x100 ) - lstrcat( szBuffer, _T("X") ); - if( dwValue & 0x200 ) - lstrcat( szBuffer, _T("Y") ); - } + lstrcat( szBuffer, _T("Ms-") ); + if( dwValue & 0x100 ) + lstrcat( szBuffer, _T("X") ); + if( dwValue & 0x200 ) + lstrcat( szBuffer, _T("Y") ); + } - if( dwValue & 0x30000 ) - { - if( bGotKey ) - lstrcat( szBuffer, _T(" ") ); - else - bGotKey = true; + if( dwValue & 0x30000 ) + { + if( bGotKey ) + lstrcat( szBuffer, _T(" ") ); + else + bGotKey = true; - lstrcat( szBuffer, _T("Kb-") ); - if( dwValue & 0x10000 ) - lstrcat( szBuffer, _T("X") ); - if( dwValue & 0x20000 ) - lstrcat( szBuffer, _T("Y") ); - } - } - break; + lstrcat( szBuffer, _T("Kb-") ); + if( dwValue & 0x10000 ) + lstrcat( szBuffer, _T("X") ); + if( dwValue & 0x20000 ) + lstrcat( szBuffer, _T("Y") ); + } + } + break; - case MDT_NONE: - default: - ListView_SetItemText( hListView, iEntry, 1, pszModTypes[0] ); - szBuffer[0] = '\0'; - } - ListView_SetItemText( hListView, iEntry, 2, szBuffer ); + case MDT_NONE: + default: + ListView_SetItemText( hListView, iEntry, 1, pszModTypes[0] ); + szBuffer[0] = '\0'; + } + ListView_SetItemText( hListView, iEntry, 2, szBuffer ); } BOOL CALLBACK ModifierTabProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) { - static BUTTON storage; - static bool bScanRunning; - static DWORD dwCounter; - static HWND hFocus = NULL, hBlocker; - static int iSelectedMod; - static BYTE bDisplayedProbs; - static HWND hModProperties; - static LPCONTROLLER pcController; + static BUTTON storage; + static bool bScanRunning; + static DWORD dwCounter; + static HWND hFocus = NULL, hBlocker; + static int iSelectedMod; + static BYTE bDisplayedProbs; + static HWND hModProperties; + static LPCONTROLLER pcController; - const UINT iModTypes[] = { IDS_M_NONE, IDS_M_MOVE, IDS_M_MACRO, IDS_M_CONFIG }; - TCHAR pszModTypes[4][16]; + const UINT iModTypes[] = { IDS_M_NONE, IDS_M_MOVE, IDS_M_MACRO, IDS_M_CONFIG }; + TCHAR pszModTypes[4][16]; - for (int j = 0; j < ARRAYSIZE(iModTypes); j++ ) - LoadString( g_hResourceDLL, iModTypes[j], pszModTypes[j], ARRAYSIZE(pszModTypes[j]) ); + for (int j = 0; j < ARRAYSIZE(iModTypes); j++ ) + LoadString( g_hResourceDLL, iModTypes[j], pszModTypes[j], ARRAYSIZE(pszModTypes[j]) ); - TCHAR szBuffer[40]; - HWND hDlgItem; - long i; - BYTE bByte; + TCHAR szBuffer[40]; + HWND hDlgItem; + long i; + BYTE bByte; - switch(uMsg) - { - case WM_INITDIALOG: - bScanRunning = false; - hModProperties = NULL; - bDisplayedProbs = MDT_NONE; - // List View - hDlgItem = GetDlgItem( hDlg, IDC_MODIFIERLIST ); + switch(uMsg) + { + case WM_INITDIALOG: + bScanRunning = false; + hModProperties = NULL; + bDisplayedProbs = MDT_NONE; + // List View + hDlgItem = GetDlgItem( hDlg, IDC_MODIFIERLIST ); - LVCOLUMN lvColumn; + LVCOLUMN lvColumn; - lvColumn.mask = LVCFMT_CENTER | LVCF_WIDTH | LVCF_TEXT; - lvColumn.fmt = LVCFMT_LEFT; - lvColumn.cx = 100; - LoadString( g_hResourceDLL, IDS_M_ASSIGNED, szBuffer, 40 ); - lvColumn.pszText = szBuffer; - ListView_InsertColumn( hDlgItem, 0, &lvColumn ); + lvColumn.mask = LVCFMT_CENTER | LVCF_WIDTH | LVCF_TEXT; + lvColumn.fmt = LVCFMT_LEFT; + lvColumn.cx = 100; + LoadString( g_hResourceDLL, IDS_M_ASSIGNED, szBuffer, 40 ); + lvColumn.pszText = szBuffer; + ListView_InsertColumn( hDlgItem, 0, &lvColumn ); - lvColumn.fmt = LVCFMT_CENTER | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; - lvColumn.cx = 43; - lvColumn.iSubItem = 1; - LoadString( g_hResourceDLL, IDS_M_TYPE, szBuffer, 40 ); - lvColumn.pszText = szBuffer; - ListView_InsertColumn( hDlgItem, 1, &lvColumn ); + lvColumn.fmt = LVCFMT_CENTER | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; + lvColumn.cx = 43; + lvColumn.iSubItem = 1; + LoadString( g_hResourceDLL, IDS_M_TYPE, szBuffer, 40 ); + lvColumn.pszText = szBuffer; + ListView_InsertColumn( hDlgItem, 1, &lvColumn ); - lvColumn.cx = 128; - lvColumn.iSubItem = 2; - LoadString( g_hResourceDLL, IDS_M_PARAM, szBuffer, 40 ); - lvColumn.pszText = szBuffer; - ListView_InsertColumn( hDlgItem, 2, &lvColumn ); + lvColumn.cx = 128; + lvColumn.iSubItem = 2; + LoadString( g_hResourceDLL, IDS_M_PARAM, szBuffer, 40 ); + lvColumn.pszText = szBuffer; + ListView_InsertColumn( hDlgItem, 2, &lvColumn ); - ListView_SetExtendedListViewStyle( hDlgItem, LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP ); - // ListView End + ListView_SetExtendedListViewStyle( hDlgItem, LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP ); + // ListView End - // DropDown - hDlgItem = GetDlgItem( hDlg, IDC_MODTYP ); + // DropDown + hDlgItem = GetDlgItem( hDlg, IDC_MODTYP ); - i = SendMessage( hDlgItem, CB_ADDSTRING, 0, (LPARAM)pszModTypes[0] ); - SendMessage( hDlgItem, CB_SETITEMDATA, i, MDT_NONE ); + i = SendMessage( hDlgItem, CB_ADDSTRING, 0, (LPARAM)pszModTypes[0] ); + SendMessage( hDlgItem, CB_SETITEMDATA, i, MDT_NONE ); - i = SendMessage( hDlgItem, CB_ADDSTRING, 0, (LPARAM)pszModTypes[1] ); - SendMessage( hDlgItem, CB_SETITEMDATA, i, MDT_MOVE ); + i = SendMessage( hDlgItem, CB_ADDSTRING, 0, (LPARAM)pszModTypes[1] ); + SendMessage( hDlgItem, CB_SETITEMDATA, i, MDT_MOVE ); - i = SendMessage( hDlgItem, CB_ADDSTRING, 0, (LPARAM)pszModTypes[2] ); - SendMessage( hDlgItem, CB_SETITEMDATA, i, MDT_MACRO ); + i = SendMessage( hDlgItem, CB_ADDSTRING, 0, (LPARAM)pszModTypes[2] ); + SendMessage( hDlgItem, CB_SETITEMDATA, i, MDT_MACRO ); - i = SendMessage( hDlgItem, CB_ADDSTRING, 0, (LPARAM)pszModTypes[3] ); - SendMessage( hDlgItem, CB_SETITEMDATA, i, MDT_CONFIG ); - // DropDown End + i = SendMessage( hDlgItem, CB_ADDSTRING, 0, (LPARAM)pszModTypes[3] ); + SendMessage( hDlgItem, CB_SETITEMDATA, i, MDT_CONFIG ); + // DropDown End - ZeroMemory(&storage, sizeof(BUTTON)); + ZeroMemory(&storage, sizeof(BUTTON)); - ModifierTabProc( hDlg, WM_USER_UPDATE, 0, 0 ); // setting values + ModifierTabProc( hDlg, WM_USER_UPDATE, 0, 0 ); // setting values - return FALSE; // don't give it focus + return FALSE; // don't give it focus - case WM_COMMAND: - hDlgItem = GetDlgItem( hDlg, LOWORD(wParam) ); - switch( LOWORD(wParam) ) - { - case IDC_NEWMODIFIER: - if( pcController->nModifiers < MAX_MODIFIERS ) - { - EnterCriticalSection(&g_critical); - pcController->nModifiers++; - pcController->pModifiers = (MODIFIER*)P_realloc( pcController->pModifiers, sizeof(MODIFIER) * pcController->nModifiers ); + case WM_COMMAND: + hDlgItem = GetDlgItem( hDlg, LOWORD(wParam) ); + switch( LOWORD(wParam) ) + { + case IDC_NEWMODIFIER: + if( pcController->nModifiers < MAX_MODIFIERS ) + { + EnterCriticalSection(&g_critical); + pcController->nModifiers++; + pcController->pModifiers = (MODIFIER*)P_realloc( pcController->pModifiers, sizeof(MODIFIER) * pcController->nModifiers ); - ZeroMemory( &pcController->pModifiers[pcController->nModifiers - 1], sizeof(MODIFIER) ); - iSelectedMod = pcController->nModifiers - 1; - LeaveCriticalSection(&g_critical); + ZeroMemory( &pcController->pModifiers[pcController->nModifiers - 1], sizeof(MODIFIER) ); + iSelectedMod = pcController->nModifiers - 1; + LeaveCriticalSection(&g_critical); - ModifierTabProc( hDlg, WM_USER_UPDATE, 0, 1 ); - } - return TRUE; + ModifierTabProc( hDlg, WM_USER_UPDATE, 0, 1 ); + } + return TRUE; - case IDC_KILLMODIFIER: - hDlgItem = GetDlgItem( hDlg, IDC_MODIFIERLIST ); + case IDC_KILLMODIFIER: + hDlgItem = GetDlgItem( hDlg, IDC_MODIFIERLIST ); - if( ListView_GetSelectedCount( hDlgItem ) > 0 ) - { - EnterCriticalSection(&g_critical); - for( i = ListView_GetItemCount( hDlgItem ) - 1; i >= 0; i-- ) - { - if( ListView_GetItemState( hDlgItem, i, LVIS_SELECTED )) - { - MoveMemory( &pcController->pModifiers[i], &pcController->pModifiers[i+1], sizeof(MODIFIER) * ( pcController->nModifiers - 1 - i )); - pcController->nModifiers--; - } - } - pcController->pModifiers = (MODIFIER*)P_realloc( pcController->pModifiers, sizeof(MODIFIER) * pcController->nModifiers ); - LeaveCriticalSection(&g_critical); - ModifierTabProc( hDlg, WM_USER_UPDATE, 0, 0 ); - } - return TRUE; + if( ListView_GetSelectedCount( hDlgItem ) > 0 ) + { + EnterCriticalSection(&g_critical); + for( i = ListView_GetItemCount( hDlgItem ) - 1; i >= 0; i-- ) + { + if( ListView_GetItemState( hDlgItem, i, LVIS_SELECTED )) + { + MoveMemory( &pcController->pModifiers[i], &pcController->pModifiers[i+1], sizeof(MODIFIER) * ( pcController->nModifiers - 1 - i )); + pcController->nModifiers--; + } + } + pcController->pModifiers = (MODIFIER*)P_realloc( pcController->pModifiers, sizeof(MODIFIER) * pcController->nModifiers ); + LeaveCriticalSection(&g_critical); + ModifierTabProc( hDlg, WM_USER_UPDATE, 0, 0 ); + } + return TRUE; - case IDC_ASSIGNMOD: - EnterCriticalSection(&g_critical); - hDlgItem = GetDlgItem( hDlg, IDC_MODIFIERLIST ); - if( bScanRunning ) - { -/* bScanRunning = false; - KillTimer( hDlg, TIMER_BUTTON ); - BUTTON btnButton; - btnButton = storage; // btnButton.dwButton = GetWindowLong( hDlgItem, GWL_USERDATA ); - GetButtonText( btnButton, szBuffer ); - SendMessage( GetDlgItem( hDlg, IDT_ASSIGNMOD ), WM_SETTEXT , 0, (LPARAM)szBuffer ); */ ; - } - else if( HIWORD(wParam) == BN_CLICKED && ListView_GetItemCount( hDlgItem )) - { - dwCounter = 0; - if (hFocus == NULL) - hFocus = SetFocus( NULL ); - hBlocker = MakeOverlay(); + case IDC_ASSIGNMOD: + EnterCriticalSection(&g_critical); + hDlgItem = GetDlgItem( hDlg, IDC_MODIFIERLIST ); + if( bScanRunning ) + { +/* bScanRunning = false; + KillTimer( hDlg, TIMER_BUTTON ); + BUTTON btnButton; + btnButton = storage; // btnButton.dwButton = GetWindowLong( hDlgItem, GWL_USERDATA ); + GetButtonText( btnButton, szBuffer ); + SendMessage( GetDlgItem( hDlg, IDT_ASSIGNMOD ), WM_SETTEXT , 0, (LPARAM)szBuffer ); */ ; + } + else if( HIWORD(wParam) == BN_CLICKED && ListView_GetItemCount( hDlgItem )) + { + dwCounter = 0; + if (hFocus == NULL) + hFocus = SetFocus( NULL ); + hBlocker = MakeOverlay(); - SetTimer( hDlg, TIMER_BUTTON, INTERVAL_BUTTON, NULL ); - bScanRunning = true; - } - LeaveCriticalSection(&g_critical); - return TRUE; + SetTimer( hDlg, TIMER_BUTTON, INTERVAL_BUTTON, NULL ); + bScanRunning = true; + } + LeaveCriticalSection(&g_critical); + return TRUE; - case IDC_MODTYP: - if( HIWORD (wParam) == CBN_SELCHANGE ) - { - ModifierTabProc( hDlg, WM_USER_UPDATE, 1, 1 ); - } - return TRUE; + case IDC_MODTYP: + if( HIWORD (wParam) == CBN_SELCHANGE ) + { + ModifierTabProc( hDlg, WM_USER_UPDATE, 1, 1 ); + } + return TRUE; - case IDC_APPCHANGES: - // ModType - EnterCriticalSection(&g_critical); - hDlgItem = GetDlgItem( hDlg, IDC_MODTYP ); - i = SendMessage( hDlgItem, CB_GETCURSEL, 0, 0 ); - pcController->pModifiers[iSelectedMod].bModType = (BYTE)SendMessage( hDlgItem, CB_GETITEMDATA, i, 0 ); + case IDC_APPCHANGES: + // ModType + EnterCriticalSection(&g_critical); + hDlgItem = GetDlgItem( hDlg, IDC_MODTYP ); + i = SendMessage( hDlgItem, CB_GETCURSEL, 0, 0 ); + pcController->pModifiers[iSelectedMod].bModType = (BYTE)SendMessage( hDlgItem, CB_GETITEMDATA, i, 0 ); - // Toggle - pcController->pModifiers[iSelectedMod].fToggle = ( IsDlgButtonChecked( hDlg, IDC_TOGGLE ) == BST_CHECKED ); - // Status - pcController->pModifiers[iSelectedMod].fStatus = ( IsDlgButtonChecked( hDlg, IDC_STATE ) == BST_CHECKED ); + // Toggle + pcController->pModifiers[iSelectedMod].fToggle = ( IsDlgButtonChecked( hDlg, IDC_TOGGLE ) == BST_CHECKED ); + // Status + pcController->pModifiers[iSelectedMod].fStatus = ( IsDlgButtonChecked( hDlg, IDC_STATE ) == BST_CHECKED ); - // Specific Data - if( hModProperties ) - SendMessage( hModProperties, WM_USER_READVALUES, (WPARAM)&pcController->pModifiers[iSelectedMod].dwSpecific, 0 ); - else - pcController->pModifiers[iSelectedMod].dwSpecific = 0; + // Specific Data + if( hModProperties ) + SendMessage( hModProperties, WM_USER_READVALUES, (WPARAM)&pcController->pModifiers[iSelectedMod].dwSpecific, 0 ); + else + pcController->pModifiers[iSelectedMod].dwSpecific = 0; - // ModButton - pcController->pModifiers[iSelectedMod].btnButton = storage; - LeaveCriticalSection(&g_critical); + // ModButton + pcController->pModifiers[iSelectedMod].btnButton = storage; + LeaveCriticalSection(&g_critical); - ModDescription( GetDlgItem( hDlg, IDC_MODIFIERLIST ), iSelectedMod, &pcController->pModifiers[iSelectedMod] ); + ModDescription( GetDlgItem( hDlg, IDC_MODIFIERLIST ), iSelectedMod, &pcController->pModifiers[iSelectedMod] ); - return TRUE; - case IDC_RESET: - ModifierTabProc( hDlg, WM_USER_UPDATE, 1, 0 ); - return TRUE; + return TRUE; + case IDC_RESET: + ModifierTabProc( hDlg, WM_USER_UPDATE, 1, 0 ); + return TRUE; - case IDC_TOGGLE: - EnableWindow( GetDlgItem( hDlg, IDC_STATE ), ( IsDlgButtonChecked( hDlg, IDC_TOGGLE ) == BST_CHECKED ) ? TRUE : FALSE ); - return TRUE; - case IDC_STATE: - return TRUE; + case IDC_TOGGLE: + EnableWindow( GetDlgItem( hDlg, IDC_STATE ), ( IsDlgButtonChecked( hDlg, IDC_TOGGLE ) == BST_CHECKED ) ? TRUE : FALSE ); + return TRUE; + case IDC_STATE: + return TRUE; - default: - return FALSE; - } + default: + return FALSE; + } - case WM_TIMER: // when assigning modifiers, this gets called every 20ms (or value in INTERVAL_BUTTON) - if( wParam == TIMER_BUTTON && bScanRunning ) - { - BUTTON newButton; - i = ScanDevices( &dwCounter, &newButton ); - if( i || dwCounter > 500 ) - { - bScanRunning = false; - KillTimer( hDlg, TIMER_BUTTON ); + case WM_TIMER: // when assigning modifiers, this gets called every 20ms (or value in INTERVAL_BUTTON) + if( wParam == TIMER_BUTTON && bScanRunning ) + { + BUTTON newButton; + i = ScanDevices( &dwCounter, &newButton ); + if( i || dwCounter > 500 ) + { + bScanRunning = false; + KillTimer( hDlg, TIMER_BUTTON ); - hDlgItem = GetDlgItem( hDlg, IDC_ASSIGNMOD ); + hDlgItem = GetDlgItem( hDlg, IDC_ASSIGNMOD ); - EnterCriticalSection(&g_critical); - if( i == SC_SCANESCAPE ) // Got an escape char from keyboard; cancel - ZeroMemory(&storage, sizeof(BUTTON)); - else if( i == SC_SCANSUCCEED ) // Got a button or axis - storage = newButton; - newButton = storage; - DestroyWindow( hBlocker ); + EnterCriticalSection(&g_critical); + if( i == SC_SCANESCAPE ) // Got an escape char from keyboard; cancel + ZeroMemory(&storage, sizeof(BUTTON)); + else if( i == SC_SCANSUCCEED ) // Got a button or axis + storage = newButton; + newButton = storage; + DestroyWindow( hBlocker ); - LeaveCriticalSection(&g_critical); + LeaveCriticalSection(&g_critical); - GetButtonText( newButton, szBuffer ); - SendMessage( GetDlgItem( hDlg, IDT_ASSIGNMOD ), WM_SETTEXT , 0, (LPARAM)szBuffer ); - if( hFocus != NULL ) - { - SetFocus( hFocus ); - hFocus = NULL; - } - } - else - { - if(( dwCounter % 50 ) == 0 ) - { - TCHAR tszText[DEFAULT_BUFFER]; + GetButtonText( newButton, szBuffer ); + SendMessage( GetDlgItem( hDlg, IDT_ASSIGNMOD ), WM_SETTEXT , 0, (LPARAM)szBuffer ); + if( hFocus != NULL ) + { + SetFocus( hFocus ); + hFocus = NULL; + } + } + else + { + if(( dwCounter % 50 ) == 0 ) + { + TCHAR tszText[DEFAULT_BUFFER]; - LoadString( g_hResourceDLL, IDS_C_POLLING, tszText, DEFAULT_BUFFER ); - wsprintf( szBuffer, tszText, 10 - dwCounter / 50 ); - SendMessage( GetDlgItem( hDlg, IDT_ASSIGNMOD ), WM_SETTEXT , 0, (LPARAM)szBuffer ); - } - ++dwCounter; - } - return TRUE; - } - else - return FALSE; + LoadString( g_hResourceDLL, IDS_C_POLLING, tszText, DEFAULT_BUFFER ); + wsprintf( szBuffer, tszText, 10 - dwCounter / 50 ); + SendMessage( GetDlgItem( hDlg, IDT_ASSIGNMOD ), WM_SETTEXT , 0, (LPARAM)szBuffer ); + } + ++dwCounter; + } + return TRUE; + } + else + return FALSE; - case WM_NOTIFY: - switch( ((LPNMHDR)lParam)->idFrom ) - { - case IDC_MODIFIERLIST: - switch( ((LPNMHDR)lParam)->code ) - { - case LVN_ITEMCHANGED: - ModifierTabProc( hDlg, WM_USER_UPDATE, 1, 0 ); - return TRUE; - default: - return FALSE; - } - default: - return FALSE; - } + case WM_NOTIFY: + switch( ((LPNMHDR)lParam)->idFrom ) + { + case IDC_MODIFIERLIST: + switch( ((LPNMHDR)lParam)->code ) + { + case LVN_ITEMCHANGED: + ModifierTabProc( hDlg, WM_USER_UPDATE, 1, 0 ); + return TRUE; + default: + return FALSE; + } + default: + return FALSE; + } - case WM_USER_UPDATE: - pcController = &g_ivConfig->Controllers[g_ivConfig->ChosenTab]; - hDlgItem = GetDlgItem( hDlg, IDC_MODIFIERLIST ); + case WM_USER_UPDATE: + pcController = &g_ivConfig->Controllers[g_ivConfig->ChosenTab]; + hDlgItem = GetDlgItem( hDlg, IDC_MODIFIERLIST ); - if( wParam == 0 ) - { - // Update Modifier List - ListView_DeleteAllItems( hDlgItem ); - if( lParam == 0 ) - iSelectedMod = -1; + if( wParam == 0 ) + { + // Update Modifier List + ListView_DeleteAllItems( hDlgItem ); + if( lParam == 0 ) + iSelectedMod = -1; - LVITEM lvItem; - lvItem.mask = LVIF_TEXT | LVIF_PARAM; - lvItem.iItem = 0; - lvItem.iSubItem = 0; - lvItem.pszText = _T(""); + LVITEM lvItem; + lvItem.mask = LVIF_TEXT | LVIF_PARAM; + lvItem.iItem = 0; + lvItem.iSubItem = 0; + lvItem.pszText = _T(""); - ListView_SetItemCount( hDlgItem, pcController->nModifiers ); - for( lvItem.lParam = 0; lvItem.lParam < pcController->nModifiers; ++lvItem.lParam ) - { - lvItem.iItem = lvItem.lParam; - i = ListView_InsertItem( hDlgItem, &lvItem ); + ListView_SetItemCount( hDlgItem, pcController->nModifiers ); + for( lvItem.lParam = 0; lvItem.lParam < pcController->nModifiers; ++lvItem.lParam ) + { + lvItem.iItem = lvItem.lParam; + i = ListView_InsertItem( hDlgItem, &lvItem ); - ModDescription( hDlgItem, i, &pcController->pModifiers[lvItem.lParam] ); - } - if( iSelectedMod >= 0 && iSelectedMod < ListView_GetItemCount( hDlgItem )) + ModDescription( hDlgItem, i, &pcController->pModifiers[lvItem.lParam] ); + } + if( iSelectedMod >= 0 && iSelectedMod < ListView_GetItemCount( hDlgItem )) - ListView_SetItemState( hDlgItem, iSelectedMod, LVIS_SELECTED, LVIS_SELECTED ) - else - iSelectedMod = -1; + ListView_SetItemState( hDlgItem, iSelectedMod, LVIS_SELECTED, LVIS_SELECTED ) + else + iSelectedMod = -1; - } - else - { - // Get selected Modifier - iSelectedMod = -1; - if( ListView_GetSelectedCount( hDlgItem ) > 0 ) - { - for( i = ListView_GetItemCount( hDlgItem ) - 1; i >= 0; i-- ) - { - if( ListView_GetItemState( hDlgItem, i, LVIS_SELECTED )) - { - iSelectedMod = i; - i = -1; - } - } - } - } + } + else + { + // Get selected Modifier + iSelectedMod = -1; + if( ListView_GetSelectedCount( hDlgItem ) > 0 ) + { + for( i = ListView_GetItemCount( hDlgItem ) - 1; i >= 0; i-- ) + { + if( ListView_GetItemState( hDlgItem, i, LVIS_SELECTED )) + { + iSelectedMod = i; + i = -1; + } + } + } + } - hDlgItem = GetDlgItem( hDlg, IDC_MODTYP ); + hDlgItem = GetDlgItem( hDlg, IDC_MODTYP ); - if( lParam == 0 ) - { - if( iSelectedMod >= 0 ) - { // a mod is selected - EnableWindow( GetDlgItem( hDlg, IDC_ASSIGNMOD ), TRUE ); - EnableWindow( GetDlgItem( hDlg, IDT_ASSIGNMOD ), TRUE ); - EnableWindow( GetDlgItem( hDlg, IDC_TOGGLE ), TRUE ); - EnableWindow( hDlgItem, TRUE ); - EnableWindow( GetDlgItem( hDlg, IDT_MODTYP ), TRUE ); - EnableWindow( GetDlgItem( hDlg, IDC_APPCHANGES ), TRUE ); - EnableWindow( GetDlgItem( hDlg, IDC_RESET ), TRUE ); + if( lParam == 0 ) + { + if( iSelectedMod >= 0 ) + { // a mod is selected + EnableWindow( GetDlgItem( hDlg, IDC_ASSIGNMOD ), TRUE ); + EnableWindow( GetDlgItem( hDlg, IDT_ASSIGNMOD ), TRUE ); + EnableWindow( GetDlgItem( hDlg, IDC_TOGGLE ), TRUE ); + EnableWindow( hDlgItem, TRUE ); + EnableWindow( GetDlgItem( hDlg, IDT_MODTYP ), TRUE ); + EnableWindow( GetDlgItem( hDlg, IDC_APPCHANGES ), TRUE ); + EnableWindow( GetDlgItem( hDlg, IDC_RESET ), TRUE ); - for( i = SendMessage( hDlgItem, CB_GETCOUNT, 0, 0 )-1; i >= 0; i-- ) - { // looking which Mod-Typ - bByte = (BYTE)SendMessage( hDlgItem, CB_GETITEMDATA, i, 0 ); - if( pcController->pModifiers[iSelectedMod].bModType == bByte ) - { - SendMessage( hDlgItem, CB_SETCURSEL, i, 0 ); - i = -10; - } - } - if( i > -5 ) - SendMessage( hDlgItem, CB_SETCURSEL, 0, 0 ); + for( i = SendMessage( hDlgItem, CB_GETCOUNT, 0, 0 )-1; i >= 0; i-- ) + { // looking which Mod-Typ + bByte = (BYTE)SendMessage( hDlgItem, CB_GETITEMDATA, i, 0 ); + if( pcController->pModifiers[iSelectedMod].bModType == bByte ) + { + SendMessage( hDlgItem, CB_SETCURSEL, i, 0 ); + i = -10; + } + } + if( i > -5 ) + SendMessage( hDlgItem, CB_SETCURSEL, 0, 0 ); - CheckDlgButton( hDlg, IDC_TOGGLE, pcController->pModifiers[iSelectedMod].fToggle ? BST_CHECKED : BST_UNCHECKED ); - EnableWindow( GetDlgItem( hDlg, IDC_STATE ), pcController->pModifiers[iSelectedMod].fToggle ? TRUE : FALSE ); - CheckDlgButton( hDlg, IDC_STATE, pcController->pModifiers[iSelectedMod].fStatus ? BST_CHECKED : BST_UNCHECKED ); + CheckDlgButton( hDlg, IDC_TOGGLE, pcController->pModifiers[iSelectedMod].fToggle ? BST_CHECKED : BST_UNCHECKED ); + EnableWindow( GetDlgItem( hDlg, IDC_STATE ), pcController->pModifiers[iSelectedMod].fToggle ? TRUE : FALSE ); + CheckDlgButton( hDlg, IDC_STATE, pcController->pModifiers[iSelectedMod].fStatus ? BST_CHECKED : BST_UNCHECKED ); - storage = pcController->pModifiers[iSelectedMod].btnButton; - GetButtonText( pcController->pModifiers[iSelectedMod].btnButton, szBuffer ); - SendMessage( GetDlgItem( hDlg, IDT_ASSIGNMOD ), WM_SETTEXT , 0, (LPARAM)szBuffer ); - } - else - { - EnableWindow( GetDlgItem( hDlg, IDC_ASSIGNMOD ), FALSE ); - EnterCriticalSection(&g_critical); - ZeroMemory(&storage, sizeof(BUTTON)); - LeaveCriticalSection(&g_critical); - SendMessage( GetDlgItem( hDlg, IDT_ASSIGNMOD ), WM_SETTEXT , 0, (LPARAM) _T("") ); - EnableWindow( GetDlgItem( hDlg, IDT_ASSIGNMOD ), FALSE ); + storage = pcController->pModifiers[iSelectedMod].btnButton; + GetButtonText( pcController->pModifiers[iSelectedMod].btnButton, szBuffer ); + SendMessage( GetDlgItem( hDlg, IDT_ASSIGNMOD ), WM_SETTEXT , 0, (LPARAM)szBuffer ); + } + else + { + EnableWindow( GetDlgItem( hDlg, IDC_ASSIGNMOD ), FALSE ); + EnterCriticalSection(&g_critical); + ZeroMemory(&storage, sizeof(BUTTON)); + LeaveCriticalSection(&g_critical); + SendMessage( GetDlgItem( hDlg, IDT_ASSIGNMOD ), WM_SETTEXT , 0, (LPARAM) _T("") ); + EnableWindow( GetDlgItem( hDlg, IDT_ASSIGNMOD ), FALSE ); - SendMessage( hDlgItem, CB_SETCURSEL, 0, 0 ); - EnableWindow( hDlgItem, FALSE ); - EnableWindow( GetDlgItem( hDlg, IDT_MODTYP ), FALSE ); + SendMessage( hDlgItem, CB_SETCURSEL, 0, 0 ); + EnableWindow( hDlgItem, FALSE ); + EnableWindow( GetDlgItem( hDlg, IDT_MODTYP ), FALSE ); - EnableWindow( GetDlgItem( hDlg, IDC_TOGGLE ), FALSE ); - CheckDlgButton( hDlg, IDC_TOGGLE , BST_UNCHECKED ); - EnableWindow( GetDlgItem( hDlg, IDC_STATE ), FALSE ); - CheckDlgButton( hDlg, IDC_STATE , BST_UNCHECKED ); - EnableWindow( GetDlgItem( hDlg, IDC_APPCHANGES ), FALSE ); - EnableWindow( GetDlgItem( hDlg, IDC_RESET ), FALSE ); - } - } + EnableWindow( GetDlgItem( hDlg, IDC_TOGGLE ), FALSE ); + CheckDlgButton( hDlg, IDC_TOGGLE , BST_UNCHECKED ); + EnableWindow( GetDlgItem( hDlg, IDC_STATE ), FALSE ); + CheckDlgButton( hDlg, IDC_STATE , BST_UNCHECKED ); + EnableWindow( GetDlgItem( hDlg, IDC_APPCHANGES ), FALSE ); + EnableWindow( GetDlgItem( hDlg, IDC_RESET ), FALSE ); + } + } - i = SendMessage( hDlgItem, CB_GETCURSEL, 0, 0 ); - bByte = (BYTE)SendMessage( hDlgItem, CB_GETITEMDATA, i, 0 ); + i = SendMessage( hDlgItem, CB_GETCURSEL, 0, 0 ); + bByte = (BYTE)SendMessage( hDlgItem, CB_GETITEMDATA, i, 0 ); - if(( bByte == bDisplayedProbs ) && hModProperties ) - SendMessage( hModProperties, WM_USER_UPDATE, pcController->pModifiers[iSelectedMod].bModType, pcController->pModifiers[iSelectedMod].dwSpecific ); - else - { - if( hModProperties ) - DestroyWindow( hModProperties ); + if(( bByte == bDisplayedProbs ) && hModProperties ) + SendMessage( hModProperties, WM_USER_UPDATE, pcController->pModifiers[iSelectedMod].bModType, pcController->pModifiers[iSelectedMod].dwSpecific ); + else + { + if( hModProperties ) + DestroyWindow( hModProperties ); - switch( bByte ) - { - case MDT_MOVE: - hModProperties = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_MOD_MOVE), hDlg, (DLGPROC)MoveModifierDialog); - break; - case MDT_MACRO: - hModProperties = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_MOD_MACRO), hDlg, (DLGPROC)MacroModifierDialog); - break; - case MDT_CONFIG: - hModProperties = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_MOD_CONFIG), hDlg, (DLGPROC)ConfigModifierDialog); - break; - case MDT_NONE: - default: - hModProperties = NULL; - } + switch( bByte ) + { + case MDT_MOVE: + hModProperties = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_MOD_MOVE), hDlg, (DLGPROC)MoveModifierDialog); + break; + case MDT_MACRO: + hModProperties = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_MOD_MACRO), hDlg, (DLGPROC)MacroModifierDialog); + break; + case MDT_CONFIG: + hModProperties = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_MOD_CONFIG), hDlg, (DLGPROC)ConfigModifierDialog); + break; + case MDT_NONE: + default: + hModProperties = NULL; + } - hDlgItem = GetDlgItem( hDlg, IDC_PROPWINDOW ); + hDlgItem = GetDlgItem( hDlg, IDC_PROPWINDOW ); - if( hModProperties ) - { - RECT rectProp, rectMain; // need to know the position of the calling tab window relative to its parent + if( hModProperties ) + { + RECT rectProp, rectMain; // need to know the position of the calling tab window relative to its parent - GetWindowRect( hDlg, &rectMain ); - GetWindowRect( hDlgItem, &rectProp ); + GetWindowRect( hDlg, &rectMain ); + GetWindowRect( hDlgItem, &rectProp ); - MoveWindow( hModProperties, rectProp.left - rectMain.left, rectProp.top - rectMain.top, rectProp.right - rectProp.left, rectProp.bottom - rectProp.top, FALSE ); - SendMessage( hModProperties, WM_USER_UPDATE, pcController->pModifiers[iSelectedMod].bModType, pcController->pModifiers[iSelectedMod].dwSpecific ); - ShowWindow( hModProperties, SW_SHOW ); - } - bDisplayedProbs = bByte; - } - return TRUE; + MoveWindow( hModProperties, rectProp.left - rectMain.left, rectProp.top - rectMain.top, rectProp.right - rectProp.left, rectProp.bottom - rectProp.top, FALSE ); + SendMessage( hModProperties, WM_USER_UPDATE, pcController->pModifiers[iSelectedMod].bModType, pcController->pModifiers[iSelectedMod].dwSpecific ); + ShowWindow( hModProperties, SW_SHOW ); + } + bDisplayedProbs = bByte; + } + return TRUE; - default: - return FALSE; //false means the msg didn't got processed - } + default: + return FALSE; //false means the msg didn't got processed + } } BOOL CALLBACK ControllerPakTabProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) { - static HWND hPakWindow; - static bool bAdaptoidInList; - static BYTE bCurrentPak; - HWND hDlgItem; - long i,j; - BYTE bByte; - TCHAR tszMsg[DEFAULT_BUFFER]; + static HWND hPakWindow; + static bool bAdaptoidInList; + static BYTE bCurrentPak; + HWND hDlgItem; + long i,j; + BYTE bByte; + TCHAR tszMsg[DEFAULT_BUFFER]; - switch(uMsg) - { - case WM_INITDIALOG: - hPakWindow = NULL; - bAdaptoidInList = false; - bCurrentPak = (BYTE)(-1); + switch(uMsg) + { + case WM_INITDIALOG: + hPakWindow = NULL; + bAdaptoidInList = false; + bCurrentPak = (BYTE)(-1); - // DropDown-List; - hDlgItem = GetDlgItem( hDlg, IDC_PAKTYPE ); - LoadString( g_hResourceDLL, IDS_P_NONE, tszMsg, DEFAULT_BUFFER ); - i = SendMessage( hDlgItem, CB_ADDSTRING, 0, (LPARAM)tszMsg ); - SendMessage( hDlgItem, CB_SETITEMDATA, i, PAK_NONE ); + // DropDown-List; + hDlgItem = GetDlgItem( hDlg, IDC_PAKTYPE ); + LoadString( g_hResourceDLL, IDS_P_NONE, tszMsg, DEFAULT_BUFFER ); + i = SendMessage( hDlgItem, CB_ADDSTRING, 0, (LPARAM)tszMsg ); + SendMessage( hDlgItem, CB_SETITEMDATA, i, PAK_NONE ); - LoadString( g_hResourceDLL, IDS_P_MEMPAK, tszMsg, DEFAULT_BUFFER ); - i = SendMessage( hDlgItem, CB_ADDSTRING, 0, (LPARAM)tszMsg ); - SendMessage( hDlgItem, CB_SETITEMDATA, i, PAK_MEM ); + LoadString( g_hResourceDLL, IDS_P_MEMPAK, tszMsg, DEFAULT_BUFFER ); + i = SendMessage( hDlgItem, CB_ADDSTRING, 0, (LPARAM)tszMsg ); + SendMessage( hDlgItem, CB_SETITEMDATA, i, PAK_MEM ); - LoadString( g_hResourceDLL, IDS_P_RUMBLEPAK, tszMsg, DEFAULT_BUFFER ); - i = SendMessage( hDlgItem, CB_ADDSTRING, 0, (LPARAM)tszMsg ); - SendMessage( hDlgItem, CB_SETITEMDATA, i, PAK_RUMBLE ); + LoadString( g_hResourceDLL, IDS_P_RUMBLEPAK, tszMsg, DEFAULT_BUFFER ); + i = SendMessage( hDlgItem, CB_ADDSTRING, 0, (LPARAM)tszMsg ); + SendMessage( hDlgItem, CB_SETITEMDATA, i, PAK_RUMBLE ); #ifdef V_TRANSFERPAK - LoadString( g_hResourceDLL, IDS_P_TRANSFERPAK, tszMsg, DEFAULT_BUFFER ); - i = SendMessage( hDlgItem, CB_ADDSTRING, 0, (LPARAM)tszMsg ); - SendMessage( hDlgItem, CB_SETITEMDATA, i, PAK_TRANSFER ); + LoadString( g_hResourceDLL, IDS_P_TRANSFERPAK, tszMsg, DEFAULT_BUFFER ); + i = SendMessage( hDlgItem, CB_ADDSTRING, 0, (LPARAM)tszMsg ); + SendMessage( hDlgItem, CB_SETITEMDATA, i, PAK_TRANSFER ); #pragma message( "Transferpak enabled in Interface" ) #endif #ifdef V_VOICEPAK - LoadString( g_hResourceDLL, IDS_P_VOICEPAK, tszMsg, DEFAULT_BUFFER ); - i = SendMessage( hDlgItem, CB_ADDSTRING, 0, (LPARAM)tszMsg ); - SendMessage( hDlgItem, CB_SETITEMDATA, i, PAK_VOICE ); + LoadString( g_hResourceDLL, IDS_P_VOICEPAK, tszMsg, DEFAULT_BUFFER ); + i = SendMessage( hDlgItem, CB_ADDSTRING, 0, (LPARAM)tszMsg ); + SendMessage( hDlgItem, CB_SETITEMDATA, i, PAK_VOICE ); #pragma message( "Voicepak enabled in Interface" ) #endif - ControllerPakTabProc( hDlg, WM_USER_UPDATE, 0, 0 ); - return FALSE; // don't give it focus + ControllerPakTabProc( hDlg, WM_USER_UPDATE, 0, 0 ); + return FALSE; // don't give it focus - case WM_COMMAND: - hDlgItem = GetDlgItem( hDlg, LOWORD(wParam) ); + case WM_COMMAND: + hDlgItem = GetDlgItem( hDlg, LOWORD(wParam) ); - switch( LOWORD(wParam) ) - { - case IDC_PAKTYPE: - if( HIWORD (wParam) == CBN_SELCHANGE ) - { - i = SendMessage( hDlgItem, CB_GETCURSEL, 0, 0 ); - g_ivConfig->Controllers[g_ivConfig->ChosenTab].PakType = SendMessage( hDlgItem, CB_GETITEMDATA, i, 0 ); - ControllerPakTabProc( hDlg, WM_USER_UPDATE, 0, 0 ); - } - return TRUE; - case IDC_RAWMODE: - g_ivConfig->Controllers[g_ivConfig->ChosenTab].fRawData = ( IsDlgButtonChecked( hDlg, LOWORD(wParam) ) == BST_CHECKED ); - ControllerPakTabProc( hDlg, WM_USER_UPDATE, 0, 0 ); - return TRUE; + switch( LOWORD(wParam) ) + { + case IDC_PAKTYPE: + if( HIWORD (wParam) == CBN_SELCHANGE ) + { + i = SendMessage( hDlgItem, CB_GETCURSEL, 0, 0 ); + g_ivConfig->Controllers[g_ivConfig->ChosenTab].PakType = SendMessage( hDlgItem, CB_GETITEMDATA, i, 0 ); + ControllerPakTabProc( hDlg, WM_USER_UPDATE, 0, 0 ); + } + return TRUE; + case IDC_RAWMODE: + g_ivConfig->Controllers[g_ivConfig->ChosenTab].fRawData = ( IsDlgButtonChecked( hDlg, LOWORD(wParam) ) == BST_CHECKED ); + ControllerPakTabProc( hDlg, WM_USER_UPDATE, 0, 0 ); + return TRUE; - default: - return FALSE; - } + default: + return FALSE; + } - case WM_USER_UPDATE: - CheckDlgButton( hDlg, IDC_RAWMODE, g_ivConfig->Controllers[g_ivConfig->ChosenTab].fRawData ? BST_CHECKED : BST_UNCHECKED ); - //Set Dropdownlist - hDlgItem = GetDlgItem( hDlg, IDC_PAKTYPE ); + case WM_USER_UPDATE: + CheckDlgButton( hDlg, IDC_RAWMODE, g_ivConfig->Controllers[g_ivConfig->ChosenTab].fRawData ? BST_CHECKED : BST_UNCHECKED ); + //Set Dropdownlist + hDlgItem = GetDlgItem( hDlg, IDC_PAKTYPE ); - if( g_ivConfig->Controllers[g_ivConfig->ChosenTab].fRawData && - !lstrcmp( g_ivConfig->FFDevices[g_ivConfig->ChosenTab].szProductName, _T(STRING_ADAPTOID) ) && - !bAdaptoidInList ) - { - // add Adaptoid Pak to list - LoadString( g_hResourceDLL, IDS_P_ADAPTOIDPAK, tszMsg, DEFAULT_BUFFER ); - i = SendMessage( hDlgItem, CB_ADDSTRING, 0, (LPARAM)tszMsg ); - SendMessage( hDlgItem, CB_SETITEMDATA, i, PAK_ADAPTOID ); - bAdaptoidInList = true; - } + if( g_ivConfig->Controllers[g_ivConfig->ChosenTab].fRawData && + !lstrcmp( g_ivConfig->FFDevices[g_ivConfig->ChosenTab].szProductName, _T(STRING_ADAPTOID) ) && + !bAdaptoidInList ) + { + // add Adaptoid Pak to list + LoadString( g_hResourceDLL, IDS_P_ADAPTOIDPAK, tszMsg, DEFAULT_BUFFER ); + i = SendMessage( hDlgItem, CB_ADDSTRING, 0, (LPARAM)tszMsg ); + SendMessage( hDlgItem, CB_SETITEMDATA, i, PAK_ADAPTOID ); + bAdaptoidInList = true; + } - if( bAdaptoidInList && - ( lstrcmp( g_ivConfig->FFDevices[g_ivConfig->ChosenTab].szProductName, _T(STRING_ADAPTOID) ) || - !g_ivConfig->Controllers[g_ivConfig->ChosenTab].fRawData )) - { - // remove Adaptoid Pak from list - i = SendMessage( hDlgItem, CB_GETCOUNT, 0, 0 ) - 1; - while(( i >= 0 )) - { - j = SendMessage( hDlgItem, CB_GETITEMDATA, i, 0 ); - if( j == PAK_ADAPTOID ) - { - SendMessage( hDlgItem, CB_DELETESTRING, i, 0 ); - i = -1; - } - i--; - } - bAdaptoidInList = false; - } + if( bAdaptoidInList && + ( lstrcmp( g_ivConfig->FFDevices[g_ivConfig->ChosenTab].szProductName, _T(STRING_ADAPTOID) ) || + !g_ivConfig->Controllers[g_ivConfig->ChosenTab].fRawData )) + { + // remove Adaptoid Pak from list + i = SendMessage( hDlgItem, CB_GETCOUNT, 0, 0 ) - 1; + while(( i >= 0 )) + { + j = SendMessage( hDlgItem, CB_GETITEMDATA, i, 0 ); + if( j == PAK_ADAPTOID ) + { + SendMessage( hDlgItem, CB_DELETESTRING, i, 0 ); + i = -1; + } + i--; + } + bAdaptoidInList = false; + } - i = SendMessage( hDlgItem, CB_GETCOUNT, 0, 0 ) - 1; + i = SendMessage( hDlgItem, CB_GETCOUNT, 0, 0 ) - 1; - while(( i >= 0 )) - { - bByte = (BYTE)SendMessage( hDlgItem, CB_GETITEMDATA, i, 0 ); - if( g_ivConfig->Controllers[g_ivConfig->ChosenTab].PakType == bByte ) - { - SendMessage( hDlgItem, CB_SETCURSEL, i, 0 ); - i = -10; - } - else - i--; - } - if( i != -10 ) - SendMessage( hDlgItem, CB_SETCURSEL, 0, 0 ); + while(( i >= 0 )) + { + bByte = (BYTE)SendMessage( hDlgItem, CB_GETITEMDATA, i, 0 ); + if( g_ivConfig->Controllers[g_ivConfig->ChosenTab].PakType == bByte ) + { + SendMessage( hDlgItem, CB_SETCURSEL, i, 0 ); + i = -10; + } + else + i--; + } + if( i != -10 ) + SendMessage( hDlgItem, CB_SETCURSEL, 0, 0 ); - // Update Pak-Display - if( g_ivConfig->Controllers[g_ivConfig->ChosenTab].fRawData ) - { - i = SendMessage( GetDlgItem( hDlg, IDC_PAKTYPE ), CB_GETCURSEL, 0, 0 ); - bByte = (BYTE)SendMessage( hDlgItem, CB_GETITEMDATA, i, 0 ); - } - else - bByte = PAK_NONRAW; + // Update Pak-Display + if( g_ivConfig->Controllers[g_ivConfig->ChosenTab].fRawData ) + { + i = SendMessage( GetDlgItem( hDlg, IDC_PAKTYPE ), CB_GETCURSEL, 0, 0 ); + bByte = (BYTE)SendMessage( hDlgItem, CB_GETITEMDATA, i, 0 ); + } + else + bByte = PAK_NONRAW; - if( bByte == bCurrentPak && hPakWindow ) - SendMessage( hPakWindow, WM_USER_UPDATE, 0, 0 ); - else - { - if( hPakWindow ) - DestroyWindow( hPakWindow ); + if( bByte == bCurrentPak && hPakWindow ) + SendMessage( hPakWindow, WM_USER_UPDATE, 0, 0 ); + else + { + if( hPakWindow ) + DestroyWindow( hPakWindow ); - hDlgItem = GetDlgItem( hDlg, IDC_PAKAREA ); + hDlgItem = GetDlgItem( hDlg, IDC_PAKAREA ); - switch( bByte ) - { - case PAK_MEM: - hPakWindow = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_PAK_MEMPAK), hDlg, (DLGPROC)MemPakProc); - break; - case PAK_RUMBLE: - hPakWindow = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_PAK_RUMBLE), hDlg, (DLGPROC)RumblePakProc); - break; - case PAK_TRANSFER: - hPakWindow = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_PAK_TRANSFER), hDlg, (DLGPROC)TransferPakProc); - break; - case PAK_ADAPTOID: - hPakWindow = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_PAK_ADAPTOID), hDlg, (DLGPROC)PakProc); - break; + switch( bByte ) + { + case PAK_MEM: + hPakWindow = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_PAK_MEMPAK), hDlg, (DLGPROC)MemPakProc); + break; + case PAK_RUMBLE: + hPakWindow = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_PAK_RUMBLE), hDlg, (DLGPROC)RumblePakProc); + break; + case PAK_TRANSFER: + hPakWindow = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_PAK_TRANSFER), hDlg, (DLGPROC)TransferPakProc); + break; + case PAK_ADAPTOID: + hPakWindow = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_PAK_ADAPTOID), hDlg, (DLGPROC)PakProc); + break; - case PAK_VOICE: - case PAK_NONRAW: - case PAK_NONE: - default: - hPakWindow = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_PAK_TEXT), hDlg, (DLGPROC)PakProc); + case PAK_VOICE: + case PAK_NONRAW: + case PAK_NONE: + default: + hPakWindow = CreateDialog(g_hResourceDLL, MAKEINTRESOURCE(IDD_PAK_TEXT), hDlg, (DLGPROC)PakProc); - } - if( hPakWindow ) - { - RECT rectProp, rectMain; // need to know the position of the calling tab window relative to its parent + } + if( hPakWindow ) + { + RECT rectProp, rectMain; // need to know the position of the calling tab window relative to its parent - GetWindowRect( hDlg, &rectMain ); - GetWindowRect( hDlgItem, &rectProp ); + GetWindowRect( hDlg, &rectMain ); + GetWindowRect( hDlgItem, &rectProp ); - MoveWindow( hPakWindow, rectProp.left - rectMain.left, rectProp.top - rectMain.top, rectProp.right - rectProp.left, rectProp.bottom - rectProp.top, FALSE ); - ShowWindow( hPakWindow, SW_SHOW ); - } - bCurrentPak = bByte; - } - return TRUE; + MoveWindow( hPakWindow, rectProp.left - rectMain.left, rectProp.top - rectMain.top, rectProp.right - rectProp.left, rectProp.bottom - rectProp.top, FALSE ); + ShowWindow( hPakWindow, SW_SHOW ); + } + bCurrentPak = bByte; + } + return TRUE; - default: - return FALSE; //false means the msg didn't got processed - } + default: + return FALSE; //false means the msg didn't got processed + } } BOOL CALLBACK PakProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) { - TCHAR tszLineOne[DEFAULT_BUFFER] = _T(""), tszLineTwo[DEFAULT_BUFFER] = _T(""); - TCHAR *pszDescription[2] = { tszLineOne, tszLineTwo }; - bool bRAW; + TCHAR tszLineOne[DEFAULT_BUFFER] = _T(""), tszLineTwo[DEFAULT_BUFFER] = _T(""); + TCHAR *pszDescription[2] = { tszLineOne, tszLineTwo }; + bool bRAW; - switch(uMsg) - { - case WM_INITDIALOG: - PakProc( hDlg, WM_USER_UPDATE, 0, 0 ); - return FALSE; // don't give it focus + switch(uMsg) + { + case WM_INITDIALOG: + PakProc( hDlg, WM_USER_UPDATE, 0, 0 ); + return FALSE; // don't give it focus - case WM_USER_UPDATE: - bRAW = g_ivConfig->Controllers[g_ivConfig->ChosenTab].fRawData ? 1 : 0; + case WM_USER_UPDATE: + bRAW = g_ivConfig->Controllers[g_ivConfig->ChosenTab].fRawData ? 1 : 0; - switch( g_ivConfig->Controllers[g_ivConfig->ChosenTab].PakType ) - { - case PAK_MEM: - LoadString( g_hResourceDLL, IDS_P_MEM_NORAW, pszDescription[0], DEFAULT_BUFFER ); - break; - case PAK_RUMBLE: - LoadString( g_hResourceDLL, IDS_P_RUMBLE_NORAW, pszDescription[0], DEFAULT_BUFFER ); - break; - case PAK_TRANSFER: - LoadString( g_hResourceDLL, IDS_P_TRANSFER_NORAW, pszDescription[0], DEFAULT_BUFFER ); - break; - case PAK_VOICE: - LoadString( g_hResourceDLL, IDS_P_VOICE_RAW, pszDescription[1], DEFAULT_BUFFER ); - pszDescription[0] = pszDescription[1]; - break; - case PAK_ADAPTOID: - LoadString( g_hResourceDLL, IDS_P_ADAPTOID_NORAW, pszDescription[0], DEFAULT_BUFFER ); - break; - case PAK_NONE: - default: - LoadString( g_hResourceDLL, IDS_P_NONE_RAWNORAW, pszDescription[1], DEFAULT_BUFFER ); - pszDescription[0] = pszDescription[1]; - } - SendMessage( GetDlgItem( hDlg, IDT_PAKDESC ), WM_SETTEXT, 0, (LPARAM)pszDescription[bRAW] ); + switch( g_ivConfig->Controllers[g_ivConfig->ChosenTab].PakType ) + { + case PAK_MEM: + LoadString( g_hResourceDLL, IDS_P_MEM_NORAW, pszDescription[0], DEFAULT_BUFFER ); + break; + case PAK_RUMBLE: + LoadString( g_hResourceDLL, IDS_P_RUMBLE_NORAW, pszDescription[0], DEFAULT_BUFFER ); + break; + case PAK_TRANSFER: + LoadString( g_hResourceDLL, IDS_P_TRANSFER_NORAW, pszDescription[0], DEFAULT_BUFFER ); + break; + case PAK_VOICE: + LoadString( g_hResourceDLL, IDS_P_VOICE_RAW, pszDescription[1], DEFAULT_BUFFER ); + pszDescription[0] = pszDescription[1]; + break; + case PAK_ADAPTOID: + LoadString( g_hResourceDLL, IDS_P_ADAPTOID_NORAW, pszDescription[0], DEFAULT_BUFFER ); + break; + case PAK_NONE: + default: + LoadString( g_hResourceDLL, IDS_P_NONE_RAWNORAW, pszDescription[1], DEFAULT_BUFFER ); + pszDescription[0] = pszDescription[1]; + } + SendMessage( GetDlgItem( hDlg, IDT_PAKDESC ), WM_SETTEXT, 0, (LPARAM)pszDescription[bRAW] ); - return TRUE; + return TRUE; - default: - return FALSE; //false means the msg didn't got processed - } + default: + return FALSE; //false means the msg didn't got processed + } } BOOL CALLBACK MemPakProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) { - static TCHAR *pszMemPakFile; - static WORD wMemPakState; - static int iSelectedNote; - TCHAR szBuffer[MAX_PATH+1], szTemp[MAX_PATH+1]; + static TCHAR *pszMemPakFile; + static WORD wMemPakState; + static int iSelectedNote; + TCHAR szBuffer[MAX_PATH+1], szTemp[MAX_PATH+1]; - HWND hDlgItem; - long i,j; + HWND hDlgItem; + long i,j; - switch(uMsg) - { - case WM_INITDIALOG: - if( g_bRunning ) - { - EnableWindow( GetDlgItem( hDlg, IDC_CHGDIR ), FALSE ); - LoadString( g_hResourceDLL, IDS_P_MEM_NOCHANGE, szBuffer, MAX_PATH + 1 ); - SendMessage( GetDlgItem( hDlg, IDC_CHGDIR ), WM_SETTEXT, 0, (LPARAM)szBuffer ); - } - iSelectedNote = -1; - // Browser - hDlgItem = GetDlgItem( hDlg, IDC_MEMPAKBROWSER ); + switch(uMsg) + { + case WM_INITDIALOG: + if( g_bRunning ) + { + EnableWindow( GetDlgItem( hDlg, IDC_CHGDIR ), FALSE ); + LoadString( g_hResourceDLL, IDS_P_MEM_NOCHANGE, szBuffer, MAX_PATH + 1 ); + SendMessage( GetDlgItem( hDlg, IDC_CHGDIR ), WM_SETTEXT, 0, (LPARAM)szBuffer ); + } + iSelectedNote = -1; + // Browser + hDlgItem = GetDlgItem( hDlg, IDC_MEMPAKBROWSER ); - LVCOLUMN lvColumn; + LVCOLUMN lvColumn; - lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT; - lvColumn.fmt = LVCFMT_LEFT; - lvColumn.cx = 147; - LoadString( g_hResourceDLL, IDS_P_MEM_NAME, szBuffer, MAX_PATH + 1 ); - lvColumn.pszText = szBuffer; - ListView_InsertColumn( hDlgItem, 0, &lvColumn ); + lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT; + lvColumn.fmt = LVCFMT_LEFT; + lvColumn.cx = 147; + LoadString( g_hResourceDLL, IDS_P_MEM_NAME, szBuffer, MAX_PATH + 1 ); + lvColumn.pszText = szBuffer; + ListView_InsertColumn( hDlgItem, 0, &lvColumn ); - lvColumn.fmt = LVCFMT_CENTER | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; + lvColumn.fmt = LVCFMT_CENTER | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; - lvColumn.cx = 70; - lvColumn.iSubItem = 1; - LoadString( g_hResourceDLL, IDS_P_MEM_REGION, szBuffer, MAX_PATH + 1 ); - lvColumn.pszText = szBuffer; - ListView_InsertColumn( hDlgItem, 1, &lvColumn ); + lvColumn.cx = 70; + lvColumn.iSubItem = 1; + LoadString( g_hResourceDLL, IDS_P_MEM_REGION, szBuffer, MAX_PATH + 1 ); + lvColumn.pszText = szBuffer; + ListView_InsertColumn( hDlgItem, 1, &lvColumn ); - lvColumn.cx = 50; - lvColumn.iSubItem = 2; - LoadString( g_hResourceDLL, IDS_P_MEM_BLOCKS, szBuffer, MAX_PATH + 1 ); - lvColumn.pszText = szBuffer; - ListView_InsertColumn( hDlgItem, 2, &lvColumn ); + lvColumn.cx = 50; + lvColumn.iSubItem = 2; + LoadString( g_hResourceDLL, IDS_P_MEM_BLOCKS, szBuffer, MAX_PATH + 1 ); + lvColumn.pszText = szBuffer; + ListView_InsertColumn( hDlgItem, 2, &lvColumn ); - ListView_SetExtendedListViewStyle( hDlgItem, LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP ); + ListView_SetExtendedListViewStyle( hDlgItem, LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP ); - MemPakProc( hDlg, WM_USER_UPDATE, 0, 0 ); // setting values - return FALSE; // don't give it focus + MemPakProc( hDlg, WM_USER_UPDATE, 0, 0 ); // setting values + return FALSE; // don't give it focus - case WM_COMMAND: - hDlgItem = GetDlgItem( hDlg, LOWORD(wParam) ); - switch( LOWORD(wParam) ) - { - TCHAR tszTitle[DEFAULT_BUFFER], tszText[DEFAULT_BUFFER]; + case WM_COMMAND: + hDlgItem = GetDlgItem( hDlg, LOWORD(wParam) ); + switch( LOWORD(wParam) ) + { + TCHAR tszTitle[DEFAULT_BUFFER], tszText[DEFAULT_BUFFER]; - case IDC_MEMPAKLIST: - if( HIWORD(wParam) == LBN_SELCHANGE ) - { - i = SendMessage( hDlgItem, LB_GETCURSEL, 0, 0 ); - SendMessage( hDlgItem, LB_GETTEXT, i, (LPARAM)pszMemPakFile ); - MemPakProc( hDlg, WM_USER_UPDATE, 1, 0 ); - } - return TRUE; - case IDC_BROWSE: - lstrcpyn( szBuffer, pszMemPakFile, ARRAYSIZE(szBuffer) ); - if( BrowseFile( hDlg, szBuffer, BF_MEMPAK, BF_LOAD )) - { - if( !CheckFileExists( szBuffer ) ) - { - BYTE aMemPak[PAK_MEM_SIZE]; + case IDC_MEMPAKLIST: + if( HIWORD(wParam) == LBN_SELCHANGE ) + { + i = SendMessage( hDlgItem, LB_GETCURSEL, 0, 0 ); + SendMessage( hDlgItem, LB_GETTEXT, i, (LPARAM)pszMemPakFile ); + MemPakProc( hDlg, WM_USER_UPDATE, 1, 0 ); + } + return TRUE; + case IDC_BROWSE: + lstrcpyn( szBuffer, pszMemPakFile, ARRAYSIZE(szBuffer) ); + if( BrowseFile( hDlg, szBuffer, BF_MEMPAK, BF_LOAD )) + { + if( !CheckFileExists( szBuffer ) ) + { + BYTE aMemPak[PAK_MEM_SIZE]; - FormatMemPak( aMemPak ); - WriteMemPakFile( szBuffer, aMemPak, true ); - } - if( CheckFileExists( szBuffer ) ) - { - lstrcpyn( pszMemPakFile, szBuffer, MAX_PATH ); - MemPakProc( hDlg, WM_USER_UPDATE, 0, 0 ); - } - } - return TRUE; - case IDC_CHGDIR: - if (DialogBox(g_hResourceDLL, MAKEINTRESOURCE(IDD_FOLDERS), hDlg, (DLGPROC)FoldersDialogProc) == TRUE) - MemPakProc( hDlg, WM_USER_UPDATE, 0, 0 ); - return TRUE; + FormatMemPak( aMemPak ); + WriteMemPakFile( szBuffer, aMemPak, true ); + } + if( CheckFileExists( szBuffer ) ) + { + lstrcpyn( pszMemPakFile, szBuffer, MAX_PATH ); + MemPakProc( hDlg, WM_USER_UPDATE, 0, 0 ); + } + } + return TRUE; + case IDC_CHGDIR: + if (DialogBox(g_hResourceDLL, MAKEINTRESOURCE(IDD_FOLDERS), hDlg, (DLGPROC)FoldersDialogProc) == TRUE) + MemPakProc( hDlg, WM_USER_UPDATE, 0, 0 ); + return TRUE; - case IDC_DELMEMPAK: - LoadString( g_hResourceDLL, IDS_DLG_DELETEPAK, tszText, DEFAULT_BUFFER ); - LoadString( g_hResourceDLL, IDS_DLG_MSG_TITLE, tszTitle, DEFAULT_BUFFER ); - if( MessageBox( hDlg, tszText, tszTitle, MB_OKCANCEL | MB_ICONQUESTION ) == IDOK ) - { - GetAbsoluteFileName( szBuffer, pszMemPakFile, DIRECTORY_MEMPAK ); - DeleteFile( szBuffer ); - pszMemPakFile[0] = '\0'; - MemPakProc( hDlg, WM_USER_UPDATE, 0, 0 ); - } - return TRUE; + case IDC_DELMEMPAK: + LoadString( g_hResourceDLL, IDS_DLG_DELETEPAK, tszText, DEFAULT_BUFFER ); + LoadString( g_hResourceDLL, IDS_DLG_MSG_TITLE, tszTitle, DEFAULT_BUFFER ); + if( MessageBox( hDlg, tszText, tszTitle, MB_OKCANCEL | MB_ICONQUESTION ) == IDOK ) + { + GetAbsoluteFileName( szBuffer, pszMemPakFile, DIRECTORY_MEMPAK ); + DeleteFile( szBuffer ); + pszMemPakFile[0] = '\0'; + MemPakProc( hDlg, WM_USER_UPDATE, 0, 0 ); + } + return TRUE; - case IDC_FORMATMEMPAK: - LoadString( g_hResourceDLL, IDS_DLG_FORMATPAK, tszText, DEFAULT_BUFFER ); - LoadString( g_hResourceDLL, IDS_DLG_MSG_TITLE, tszTitle, DEFAULT_BUFFER ); - if( MessageBox( hDlg, tszText, tszTitle, MB_OKCANCEL | MB_ICONQUESTION ) == IDOK ) - { - GetAbsoluteFileName( szBuffer, pszMemPakFile, DIRECTORY_MEMPAK ); - BYTE aMemPak[PAK_MEM_SIZE]; + case IDC_FORMATMEMPAK: + LoadString( g_hResourceDLL, IDS_DLG_FORMATPAK, tszText, DEFAULT_BUFFER ); + LoadString( g_hResourceDLL, IDS_DLG_MSG_TITLE, tszTitle, DEFAULT_BUFFER ); + if( MessageBox( hDlg, tszText, tszTitle, MB_OKCANCEL | MB_ICONQUESTION ) == IDOK ) + { + GetAbsoluteFileName( szBuffer, pszMemPakFile, DIRECTORY_MEMPAK ); + BYTE aMemPak[PAK_MEM_SIZE]; - FormatMemPak( aMemPak ); - WriteMemPakFile( szBuffer, aMemPak, false ); - MemPakProc( hDlg, WM_USER_UPDATE, 1, 0 ); - } - return TRUE; - case IDC_SAVENOTE: - { - BYTE aMemPak[PAK_MEM_SIZE]; - if( g_bRunning && ( HIWORD(wMemPakState) == MPAK_INUSE ) - && g_pcControllers[g_ivConfig->ChosenTab].pPakData - && ( *(BYTE*)g_pcControllers[g_ivConfig->ChosenTab].pPakData == PAK_MEM )) - { - EnterCriticalSection( &g_critical ); - CopyMemory( aMemPak, ((MEMPAK*)g_pcControllers[g_ivConfig->ChosenTab].pPakData)->aMemPakData, PAK_MEM_SIZE ); - LeaveCriticalSection( &g_critical ); - } - else - { - GetAbsoluteFileName( szBuffer, pszMemPakFile, DIRECTORY_MEMPAK ); - ReadMemPakFile( szBuffer, aMemPak, false ); - } + FormatMemPak( aMemPak ); + WriteMemPakFile( szBuffer, aMemPak, false ); + MemPakProc( hDlg, WM_USER_UPDATE, 1, 0 ); + } + return TRUE; + case IDC_SAVENOTE: + { + BYTE aMemPak[PAK_MEM_SIZE]; + if( g_bRunning && ( HIWORD(wMemPakState) == MPAK_INUSE ) + && g_pcControllers[g_ivConfig->ChosenTab].pPakData + && ( *(BYTE*)g_pcControllers[g_ivConfig->ChosenTab].pPakData == PAK_MEM )) + { + EnterCriticalSection( &g_critical ); + CopyMemory( aMemPak, ((MEMPAK*)g_pcControllers[g_ivConfig->ChosenTab].pPakData)->aMemPakData, PAK_MEM_SIZE ); + LeaveCriticalSection( &g_critical ); + } + else + { + GetAbsoluteFileName( szBuffer, pszMemPakFile, DIRECTORY_MEMPAK ); + ReadMemPakFile( szBuffer, aMemPak, false ); + } - int iChars = TranslateNotes( &aMemPak[0x300 + iSelectedNote * 32 + 0x10], szBuffer, 16 ); + int iChars = TranslateNotes( &aMemPak[0x300 + iSelectedNote * 32 + 0x10], szBuffer, 16 ); - if( TranslateNotes( &aMemPak[0x300 + iSelectedNote * 32 + 0x0C], &szBuffer[iChars + 1], 1 ) ) - szBuffer[iChars] = _T('_'); + if( TranslateNotes( &aMemPak[0x300 + iSelectedNote * 32 + 0x0C], &szBuffer[iChars + 1], 1 ) ) + szBuffer[iChars] = _T('_'); - if( BrowseFile( hDlg, szBuffer, BF_NOTE, BF_SAVE )) - { - TCHAR szAbsoluteMemPak[MAX_PATH+1]; - GetAbsoluteFileName( szAbsoluteMemPak, pszMemPakFile, DIRECTORY_MEMPAK ); + if( BrowseFile( hDlg, szBuffer, BF_NOTE, BF_SAVE )) + { + TCHAR szAbsoluteMemPak[MAX_PATH+1]; + GetAbsoluteFileName( szAbsoluteMemPak, pszMemPakFile, DIRECTORY_MEMPAK ); - SaveNoteFileA( aMemPak, iSelectedNote, szBuffer ); - } - } - return TRUE; - case IDC_INSERTNOTE: - { - GetAbsoluteFileName( szBuffer, pszMemPakFile, DIRECTORY_MEMPAK ); - BYTE aMemPak[PAK_MEM_SIZE]; - ReadMemPakFile( szBuffer, aMemPak, false ); - szBuffer[0] = '\0'; + SaveNoteFileA( aMemPak, iSelectedNote, szBuffer ); + } + } + return TRUE; + case IDC_INSERTNOTE: + { + GetAbsoluteFileName( szBuffer, pszMemPakFile, DIRECTORY_MEMPAK ); + BYTE aMemPak[PAK_MEM_SIZE]; + ReadMemPakFile( szBuffer, aMemPak, false ); + szBuffer[0] = '\0'; - if( BrowseFile( hDlg, szBuffer, BF_NOTE, BF_LOAD )) - { - if( InsertNoteFile( aMemPak, szBuffer ) ) - { - GetAbsoluteFileName( szBuffer, pszMemPakFile, DIRECTORY_MEMPAK ); - WriteMemPakFile( szBuffer, aMemPak, false ); - MemPakProc( hDlg, WM_USER_UPDATE, 1, 0 ); - } - } - } - return TRUE; - case IDC_DELETENOTE: - LoadString( g_hResourceDLL, IDS_DLG_DELETENOTE, tszText, DEFAULT_BUFFER ); - LoadString( g_hResourceDLL, IDS_DLG_MSG_TITLE, tszTitle, DEFAULT_BUFFER ); - if( MessageBox( hDlg, tszText, tszTitle, MB_OKCANCEL | MB_ICONQUESTION ) == IDOK ) - { - GetAbsoluteFileName( szBuffer, pszMemPakFile, DIRECTORY_MEMPAK ); - BYTE aMemPak[PAK_MEM_SIZE]; - ReadMemPakFile( szBuffer, aMemPak, false ); - if( RemoveNote( aMemPak, iSelectedNote ) ) - { - WriteMemPakFile( szBuffer, aMemPak, false ); - MemPakProc( hDlg, WM_USER_UPDATE, 1, 0 ); - } - } - return TRUE; - default: - return FALSE; - } + if( BrowseFile( hDlg, szBuffer, BF_NOTE, BF_LOAD )) + { + if( InsertNoteFile( aMemPak, szBuffer ) ) + { + GetAbsoluteFileName( szBuffer, pszMemPakFile, DIRECTORY_MEMPAK ); + WriteMemPakFile( szBuffer, aMemPak, false ); + MemPakProc( hDlg, WM_USER_UPDATE, 1, 0 ); + } + } + } + return TRUE; + case IDC_DELETENOTE: + LoadString( g_hResourceDLL, IDS_DLG_DELETENOTE, tszText, DEFAULT_BUFFER ); + LoadString( g_hResourceDLL, IDS_DLG_MSG_TITLE, tszTitle, DEFAULT_BUFFER ); + if( MessageBox( hDlg, tszText, tszTitle, MB_OKCANCEL | MB_ICONQUESTION ) == IDOK ) + { + GetAbsoluteFileName( szBuffer, pszMemPakFile, DIRECTORY_MEMPAK ); + BYTE aMemPak[PAK_MEM_SIZE]; + ReadMemPakFile( szBuffer, aMemPak, false ); + if( RemoveNote( aMemPak, iSelectedNote ) ) + { + WriteMemPakFile( szBuffer, aMemPak, false ); + MemPakProc( hDlg, WM_USER_UPDATE, 1, 0 ); + } + } + return TRUE; + default: + return FALSE; + } - case WM_NOTIFY: - switch( ((LPNMHDR)lParam)->idFrom ) - { - case IDC_MEMPAKBROWSER: - switch( ((LPNMHDR)lParam)->code ) - { - case LVN_ITEMCHANGED: - if( ((LPNMLISTVIEW)lParam)->uNewState & LVIS_SELECTED ) - { - iSelectedNote = ((LPNMLISTVIEW)lParam)->lParam; - if( HIBYTE(wMemPakState) & MPAK_READABLE ) - EnableWindow( GetDlgItem( hDlg, IDC_SAVENOTE ), TRUE ); - if( HIBYTE(wMemPakState) & MPAK_WRITEABLE ) - EnableWindow( GetDlgItem( hDlg, IDC_DELETENOTE ), TRUE ); - } - else - { - iSelectedNote = -1; - EnableWindow( GetDlgItem( hDlg, IDC_SAVENOTE ), FALSE ); - EnableWindow( GetDlgItem( hDlg, IDC_DELETENOTE ), FALSE ); - } - return TRUE; - default: - return FALSE; - } - default: - return FALSE; - } + case WM_NOTIFY: + switch( ((LPNMHDR)lParam)->idFrom ) + { + case IDC_MEMPAKBROWSER: + switch( ((LPNMHDR)lParam)->code ) + { + case LVN_ITEMCHANGED: + if( ((LPNMLISTVIEW)lParam)->uNewState & LVIS_SELECTED ) + { + iSelectedNote = ((LPNMLISTVIEW)lParam)->lParam; + if( HIBYTE(wMemPakState) & MPAK_READABLE ) + EnableWindow( GetDlgItem( hDlg, IDC_SAVENOTE ), TRUE ); + if( HIBYTE(wMemPakState) & MPAK_WRITEABLE ) + EnableWindow( GetDlgItem( hDlg, IDC_DELETENOTE ), TRUE ); + } + else + { + iSelectedNote = -1; + EnableWindow( GetDlgItem( hDlg, IDC_SAVENOTE ), FALSE ); + EnableWindow( GetDlgItem( hDlg, IDC_DELETENOTE ), FALSE ); + } + return TRUE; + default: + return FALSE; + } + default: + return FALSE; + } - case WM_USER_UPDATE: - pszMemPakFile = g_ivConfig->Controllers[g_ivConfig->ChosenTab].szMempakFile; - iSelectedNote = -1; + case WM_USER_UPDATE: + pszMemPakFile = g_ivConfig->Controllers[g_ivConfig->ChosenTab].szMempakFile; + iSelectedNote = -1; - // Mempak List Window - if( wParam == 0 && lParam == 0 ) - { - hDlgItem = GetDlgItem( hDlg, IDC_MEMPAKLIST ); - SendMessage( hDlgItem, LB_RESETCONTENT, 0, 0 ); - SendFilestoList( hDlgItem, FILIST_MEM ); + // Mempak List Window + if( wParam == 0 && lParam == 0 ) + { + hDlgItem = GetDlgItem( hDlg, IDC_MEMPAKLIST ); + SendMessage( hDlgItem, LB_RESETCONTENT, 0, 0 ); + SendFilestoList( hDlgItem, FILIST_MEM ); - if( pszMemPakFile[1] == ':' || ( pszMemPakFile[1] == '\\' && pszMemPakFile[0] == '\\' )) - { - GetDirectory( szBuffer, DIRECTORY_MEMPAK ); - i = lstrlen( szBuffer ); - if( !_tcsncmp( szBuffer, pszMemPakFile, i )) - { - lstrcpyn( szBuffer, &pszMemPakFile[i], MAX_PATH ); - lstrcpyn( pszMemPakFile, szBuffer, MAX_PATH ); - } + if( pszMemPakFile[1] == ':' || ( pszMemPakFile[1] == '\\' && pszMemPakFile[0] == '\\' )) + { + GetDirectory( szBuffer, DIRECTORY_MEMPAK ); + i = lstrlen( szBuffer ); + if( !_tcsncmp( szBuffer, pszMemPakFile, i )) + { + lstrcpyn( szBuffer, &pszMemPakFile[i], MAX_PATH ); + lstrcpyn( pszMemPakFile, szBuffer, MAX_PATH ); + } - } + } - j = -1; - if( !( pszMemPakFile[1] == ':' || ( pszMemPakFile[1] == '\\' && pszMemPakFile[0] == '\\' )) ) - { - i = SendMessage( hDlgItem, LB_FINDSTRINGEXACT, (WPARAM)(-1), (LPARAM)pszMemPakFile ); - if( i != LB_ERR ) - j = i; - } - SendMessage( hDlgItem, LB_SETCURSEL, j, 0 ); - } - // Mempak List Window End + j = -1; + if( !( pszMemPakFile[1] == ':' || ( pszMemPakFile[1] == '\\' && pszMemPakFile[0] == '\\' )) ) + { + i = SendMessage( hDlgItem, LB_FINDSTRINGEXACT, (WPARAM)(-1), (LPARAM)pszMemPakFile ); + if( i != LB_ERR ) + j = i; + } + SendMessage( hDlgItem, LB_SETCURSEL, j, 0 ); + } + // Mempak List Window End - // MamPak Full Path+Name - GetAbsoluteFileName( szBuffer, pszMemPakFile, DIRECTORY_MEMPAK ); + // MamPak Full Path+Name + GetAbsoluteFileName( szBuffer, pszMemPakFile, DIRECTORY_MEMPAK ); - // MemPak Browser - ListView_DeleteAllItems( GetDlgItem( hDlg, IDC_MEMPAKBROWSER )); - if( (!lstrcmpi( &szBuffer[lstrlen(szBuffer)-4], _T(".mpk") )) - || (!lstrcmpi( &szBuffer[lstrlen(szBuffer)-4], _T(".n64") ))) - { - BYTE aMemPakHeader[0x500]; + // MemPak Browser + ListView_DeleteAllItems( GetDlgItem( hDlg, IDC_MEMPAKBROWSER )); + if( (!lstrcmpi( &szBuffer[lstrlen(szBuffer)-4], _T(".mpk") )) + || (!lstrcmpi( &szBuffer[lstrlen(szBuffer)-4], _T(".n64") ))) + { + BYTE aMemPakHeader[0x500]; - bool bMemPakUsed = false; - // first, if we're running emulation we need to make sure we haven't selected a file that's currently in use - if (g_bRunning) - { - TCHAR szMemPakFile[MAX_PATH+1]; - for( i = 0; i < 4; ++i ) - { - if( g_pcControllers[i].pPakData && ( *(BYTE*)g_pcControllers[i].pPakData == PAK_MEM ) && !((LPMEMPAK)g_pcControllers[i].pPakData)->fReadonly ) - { - GetAbsoluteFileName( szMemPakFile, g_pcControllers[i].szMempakFile, DIRECTORY_MEMPAK ); - if( !lstrcmp( szMemPakFile, szBuffer )) - { - // grab the file info from memory instead of the file... but keep in mind we can't do anything dangerous with it - EnterCriticalSection( &g_critical ); - wMemPakState = ShowMemPakContent( ((MEMPAK*)g_pcControllers[i].pPakData)->aMemPakData, GetDlgItem( hDlg, IDC_MEMPAKBROWSER )); - LeaveCriticalSection( &g_critical ); - if (HIBYTE(wMemPakState) == MPAK_OK) - { - LoadString( g_hResourceDLL, IDS_P_MEM_INUSE, szTemp, MAX_PATH + 1 ); - wsprintf( szBuffer, szTemp, LOBYTE(wMemPakState) ); - wMemPakState = MAKEWORD( MPAK_READABLE, MPAK_INUSE ); - } - bMemPakUsed = true; - } - } - } - } + bool bMemPakUsed = false; + // first, if we're running emulation we need to make sure we haven't selected a file that's currently in use + if (g_bRunning) + { + TCHAR szMemPakFile[MAX_PATH+1]; + for( i = 0; i < 4; ++i ) + { + if( g_pcControllers[i].pPakData && ( *(BYTE*)g_pcControllers[i].pPakData == PAK_MEM ) && !((LPMEMPAK)g_pcControllers[i].pPakData)->fReadonly ) + { + GetAbsoluteFileName( szMemPakFile, g_pcControllers[i].szMempakFile, DIRECTORY_MEMPAK ); + if( !lstrcmp( szMemPakFile, szBuffer )) + { + // grab the file info from memory instead of the file... but keep in mind we can't do anything dangerous with it + EnterCriticalSection( &g_critical ); + wMemPakState = ShowMemPakContent( ((MEMPAK*)g_pcControllers[i].pPakData)->aMemPakData, GetDlgItem( hDlg, IDC_MEMPAKBROWSER )); + LeaveCriticalSection( &g_critical ); + if (HIBYTE(wMemPakState) == MPAK_OK) + { + LoadString( g_hResourceDLL, IDS_P_MEM_INUSE, szTemp, MAX_PATH + 1 ); + wsprintf( szBuffer, szTemp, LOBYTE(wMemPakState) ); + wMemPakState = MAKEWORD( MPAK_READABLE, MPAK_INUSE ); + } + bMemPakUsed = true; + } + } + } + } - if( !bMemPakUsed ) - { - HANDLE hFile; - hFile = CreateFile( szBuffer, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL ); - if ( hFile != INVALID_HANDLE_VALUE ) - { - DWORD dwFileSize = GetFileSize( hFile, NULL ); - DWORD dwCorrectFileSize = PAK_MEM_SIZE; + if( !bMemPakUsed ) + { + HANDLE hFile; + hFile = CreateFile( szBuffer, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL ); + if ( hFile != INVALID_HANDLE_VALUE ) + { + DWORD dwFileSize = GetFileSize( hFile, NULL ); + DWORD dwCorrectFileSize = PAK_MEM_SIZE; - TCHAR *pcPoint = _tcsrchr( szBuffer, _T('.') ); - if( !lstrcmpi( pcPoint, _T(".n64") ) ) - { - SetFilePointer( hFile, PAK_MEM_DEXOFFSET, NULL, FILE_BEGIN ); - dwCorrectFileSize += PAK_MEM_DEXOFFSET; - } - else - SetFilePointer( hFile, 0L, NULL, FILE_BEGIN ); + TCHAR *pcPoint = _tcsrchr( szBuffer, _T('.') ); + if( !lstrcmpi( pcPoint, _T(".n64") ) ) + { + SetFilePointer( hFile, PAK_MEM_DEXOFFSET, NULL, FILE_BEGIN ); + dwCorrectFileSize += PAK_MEM_DEXOFFSET; + } + else + SetFilePointer( hFile, 0L, NULL, FILE_BEGIN ); - if( dwFileSize > ( dwCorrectFileSize - 0x7500 )) - { - DWORD dwBytesRead; + if( dwFileSize > ( dwCorrectFileSize - 0x7500 )) + { + DWORD dwBytesRead; - ReadFile( hFile, aMemPakHeader, 0x500, &dwBytesRead, NULL); - ListView_DeleteAllItems( GetDlgItem( hDlg, IDC_MEMPAKBROWSER )); - wMemPakState = ShowMemPakContent( aMemPakHeader, GetDlgItem( hDlg, IDC_MEMPAKBROWSER )); - } - else - wMemPakState = MAKEWORD( 0, MPAK_DAMAGED ); + ReadFile( hFile, aMemPakHeader, 0x500, &dwBytesRead, NULL); + ListView_DeleteAllItems( GetDlgItem( hDlg, IDC_MEMPAKBROWSER )); + wMemPakState = ShowMemPakContent( aMemPakHeader, GetDlgItem( hDlg, IDC_MEMPAKBROWSER )); + } + else + wMemPakState = MAKEWORD( 0, MPAK_DAMAGED ); - if( HIBYTE( wMemPakState ) == MPAK_OK && - dwFileSize != dwCorrectFileSize ) - wMemPakState = MAKEWORD( LOBYTE( wMemPakState ), MPAK_WRONGSIZE ); + if( HIBYTE( wMemPakState ) == MPAK_OK && + dwFileSize != dwCorrectFileSize ) + wMemPakState = MAKEWORD( LOBYTE( wMemPakState ), MPAK_WRONGSIZE ); - CloseHandle( hFile ); - } - else - wMemPakState = MAKEWORD( 0, MPAK_ERROR ); - } - } - else - wMemPakState = MAKEWORD( 0, MPAK_NOSELECTION ); + CloseHandle( hFile ); + } + else + wMemPakState = MAKEWORD( 0, MPAK_ERROR ); + } + } + else + wMemPakState = MAKEWORD( 0, MPAK_NOSELECTION ); - switch( HIBYTE(wMemPakState) ) - { - case MPAK_OK: - LoadString( g_hResourceDLL, IDS_P_MEM_BLOCKSFREE, szTemp, MAX_PATH + 1 ); - wsprintf( szBuffer, szTemp, LOBYTE(wMemPakState) ); - break; - case MPAK_INUSE: - // text field already set - break; - case MPAK_WRONGSIZE: - LoadString( g_hResourceDLL, IDS_P_MEM_WRONGSIZE, szTemp, MAX_PATH + 1 ); - wsprintf( szBuffer, szTemp, LOBYTE(wMemPakState) ); - break; - case MPAK_NOSELECTION: - LoadString( g_hResourceDLL, IDS_P_MEM_NONESELECTED, szBuffer, MAX_PATH + 1 ); - break; - case MPAK_DAMAGED: - LoadString( g_hResourceDLL, IDS_P_MEM_DAMAGED, szBuffer, MAX_PATH + 1 ); - break; + switch( HIBYTE(wMemPakState) ) + { + case MPAK_OK: + LoadString( g_hResourceDLL, IDS_P_MEM_BLOCKSFREE, szTemp, MAX_PATH + 1 ); + wsprintf( szBuffer, szTemp, LOBYTE(wMemPakState) ); + break; + case MPAK_INUSE: + // text field already set + break; + case MPAK_WRONGSIZE: + LoadString( g_hResourceDLL, IDS_P_MEM_WRONGSIZE, szTemp, MAX_PATH + 1 ); + wsprintf( szBuffer, szTemp, LOBYTE(wMemPakState) ); + break; + case MPAK_NOSELECTION: + LoadString( g_hResourceDLL, IDS_P_MEM_NONESELECTED, szBuffer, MAX_PATH + 1 ); + break; + case MPAK_DAMAGED: + LoadString( g_hResourceDLL, IDS_P_MEM_DAMAGED, szBuffer, MAX_PATH + 1 ); + break; - case MPAK_ERROR: - default: - { - LoadString( g_hResourceDLL, IDS_P_MEM_ERROR, szTemp, MAX_PATH + 1 ); - DWORD dwError = GetLastError(); - DWORD dwLength = wsprintf( szBuffer, szTemp, dwError ); - FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError , 0, &szBuffer[dwLength], ARRAYSIZE(szBuffer) - dwLength - 1, NULL ); - } - break; - } - SendMessage( GetDlgItem( hDlg, IDT_MEMPAKSTATE ), WM_SETTEXT, 0, (LPARAM)szBuffer ); + case MPAK_ERROR: + default: + { + LoadString( g_hResourceDLL, IDS_P_MEM_ERROR, szTemp, MAX_PATH + 1 ); + DWORD dwError = GetLastError(); + DWORD dwLength = wsprintf( szBuffer, szTemp, dwError ); + FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError , 0, &szBuffer[dwLength], ARRAYSIZE(szBuffer) - dwLength - 1, NULL ); + } + break; + } + SendMessage( GetDlgItem( hDlg, IDT_MEMPAKSTATE ), WM_SETTEXT, 0, (LPARAM)szBuffer ); - if( HIBYTE(wMemPakState) & MPAK_FORMATABLE ) - { - EnableWindow( GetDlgItem( hDlg, IDC_FORMATMEMPAK ), TRUE ); - EnableWindow( GetDlgItem( hDlg, IDC_DELMEMPAK ), TRUE ); - } - else - { - EnableWindow( GetDlgItem( hDlg, IDC_FORMATMEMPAK ), FALSE ); - EnableWindow( GetDlgItem( hDlg, IDC_DELMEMPAK ), FALSE ); - } + if( HIBYTE(wMemPakState) & MPAK_FORMATABLE ) + { + EnableWindow( GetDlgItem( hDlg, IDC_FORMATMEMPAK ), TRUE ); + EnableWindow( GetDlgItem( hDlg, IDC_DELMEMPAK ), TRUE ); + } + else + { + EnableWindow( GetDlgItem( hDlg, IDC_FORMATMEMPAK ), FALSE ); + EnableWindow( GetDlgItem( hDlg, IDC_DELMEMPAK ), FALSE ); + } - if( HIBYTE(wMemPakState) & MPAK_WRITEABLE ) - EnableWindow( GetDlgItem( hDlg, IDC_INSERTNOTE ), TRUE ); - else - EnableWindow( GetDlgItem( hDlg, IDC_INSERTNOTE ), FALSE ); + if( HIBYTE(wMemPakState) & MPAK_WRITEABLE ) + EnableWindow( GetDlgItem( hDlg, IDC_INSERTNOTE ), TRUE ); + else + EnableWindow( GetDlgItem( hDlg, IDC_INSERTNOTE ), FALSE ); - EnableWindow( GetDlgItem( hDlg, IDC_SAVENOTE ), FALSE ); - EnableWindow( GetDlgItem( hDlg, IDC_DELETENOTE ), FALSE ); + EnableWindow( GetDlgItem( hDlg, IDC_SAVENOTE ), FALSE ); + EnableWindow( GetDlgItem( hDlg, IDC_DELETENOTE ), FALSE ); - return TRUE; + return TRUE; - default: - return FALSE; //false means the msg didn't got processed - } + default: + return FALSE; //false means the msg didn't got processed + } } BOOL CALLBACK RumblePakProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) { - static BOOL bNewRumbleTyp = true; - IFDEVICE *pifDevice = &g_ivConfig->FFDevices[g_ivConfig->ChosenTab]; - CONTROLLER *pcController = &g_ivConfig->Controllers[g_ivConfig->ChosenTab]; - TCHAR szBuffer[DEFAULT_BUFFER], szTemp[DEFAULT_BUFFER]; - HWND hDlgItem; - long i = 0,j; + static BOOL bNewRumbleTyp = true; + IFDEVICE *pifDevice = &g_ivConfig->FFDevices[g_ivConfig->ChosenTab]; + CONTROLLER *pcController = &g_ivConfig->Controllers[g_ivConfig->ChosenTab]; + TCHAR szBuffer[DEFAULT_BUFFER], szTemp[DEFAULT_BUFFER]; + HWND hDlgItem; + long i = 0,j; - switch(uMsg) - { - case WM_INITDIALOG: - hDlgItem = GetDlgItem( hDlg, IDC_RUMBLESTRENGTH ); + switch(uMsg) + { + case WM_INITDIALOG: + hDlgItem = GetDlgItem( hDlg, IDC_RUMBLESTRENGTH ); - SendMessage( hDlgItem, TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG( 0, 100 )); - SendMessage( hDlgItem, TBM_SETTICFREQ, (WPARAM) 10, 0 ); - SendMessage( hDlgItem, TBM_SETPAGESIZE, (WPARAM) 0, 1 ); + SendMessage( hDlgItem, TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG( 0, 100 )); + SendMessage( hDlgItem, TBM_SETTICFREQ, (WPARAM) 10, 0 ); + SendMessage( hDlgItem, TBM_SETPAGESIZE, (WPARAM) 0, 1 ); - RumblePakProc( hDlg, WM_USER_UPDATE, 0, 0 ); - return FALSE; // don't give it focus + RumblePakProc( hDlg, WM_USER_UPDATE, 0, 0 ); + return FALSE; // don't give it focus - case WM_COMMAND: - hDlgItem = GetDlgItem( hDlg, LOWORD(wParam) ); + case WM_COMMAND: + hDlgItem = GetDlgItem( hDlg, LOWORD(wParam) ); - switch( LOWORD(wParam) ) - { - case IDC_CTRDEVICE: - if( HIWORD(wParam) == CBN_SELCHANGE ) - { - i = SendMessage( hDlgItem, CB_GETCURSEL, 0, 0 ); - j = SendMessage( hDlgItem, CB_GETITEMDATA, i, 0 ); + switch( LOWORD(wParam) ) + { + case IDC_CTRDEVICE: + if( HIWORD(wParam) == CBN_SELCHANGE ) + { + i = SendMessage( hDlgItem, CB_GETCURSEL, 0, 0 ); + j = SendMessage( hDlgItem, CB_GETITEMDATA, i, 0 ); - EnterCriticalSection(&g_critical); - if( j == -1 ) - { - pifDevice->bProductCounter = 0; - pifDevice->szProductName[0] = '\0'; - } - else - { - pifDevice->bProductCounter = g_devList[j].bProductCounter; - lstrcpyn( pifDevice->szProductName, g_devList[j].szProductName, sizeof(pifDevice->szProductName) / sizeof(TCHAR) ); - } - LeaveCriticalSection(&g_critical); + EnterCriticalSection(&g_critical); + if( j == -1 ) + { + pifDevice->bProductCounter = 0; + pifDevice->szProductName[0] = '\0'; + } + else + { + pifDevice->bProductCounter = g_devList[j].bProductCounter; + lstrcpyn( pifDevice->szProductName, g_devList[j].szProductName, sizeof(pifDevice->szProductName) / sizeof(TCHAR) ); + } + LeaveCriticalSection(&g_critical); - RumblePakProc( hDlg, WM_USER_UPDATE, 0, 0 ); // en/disabling RumbleOptions - } - return TRUE; + RumblePakProc( hDlg, WM_USER_UPDATE, 0, 0 ); // en/disabling RumbleOptions + } + return TRUE; - // the following three cases use fallthrough assignment - case IDC_RUMBLE1: - if( LOWORD(wParam) == IDC_RUMBLE1 ) - i = RUMBLE_EFF1; - case IDC_RUMBLE2: - if( LOWORD(wParam) == IDC_RUMBLE2 ) - i = RUMBLE_EFF2; - case IDC_RUMBLE3: - if( LOWORD(wParam) == IDC_RUMBLE3 ) - i = RUMBLE_EFF3; - if(( HIWORD(wParam) == BN_CLICKED ) && - ( IsDlgButtonChecked( hDlg, LOWORD(wParam) ) == BST_CHECKED )) - { - pcController->bRumbleTyp = (BYTE)i; - bNewRumbleTyp = true; - } - return TRUE; + // the following three cases use fallthrough assignment + case IDC_RUMBLE1: + if( LOWORD(wParam) == IDC_RUMBLE1 ) + i = RUMBLE_EFF1; + case IDC_RUMBLE2: + if( LOWORD(wParam) == IDC_RUMBLE2 ) + i = RUMBLE_EFF2; + case IDC_RUMBLE3: + if( LOWORD(wParam) == IDC_RUMBLE3 ) + i = RUMBLE_EFF3; + if(( HIWORD(wParam) == BN_CLICKED ) && + ( IsDlgButtonChecked( hDlg, LOWORD(wParam) ) == BST_CHECKED )) + { + pcController->bRumbleTyp = (BYTE)i; + bNewRumbleTyp = true; + } + return TRUE; - case IDC_VISUALRUMBLE: - pcController->fVisualRumble = ( IsDlgButtonChecked( hDlg, LOWORD(wParam) ) == BST_CHECKED ); - return TRUE; + case IDC_VISUALRUMBLE: + pcController->fVisualRumble = ( IsDlgButtonChecked( hDlg, LOWORD(wParam) ) == BST_CHECKED ); + return TRUE; - case IDC_RUMBLETEST: - if ( !g_pConfigEffect || bNewRumbleTyp ) - { - EnterCriticalSection(&g_critical); - ReleaseEffect( g_pConfigEffect ); - if ( !CreateEffectHandle(g_hMainDialog, g_pConfigDevice, g_pConfigEffect, pcController->bRumbleTyp, pcController->bRumbleStrength) ) - { - DebugWriteA("Interface: CreateEffectHandle failed\n"); - } - bNewRumbleTyp = false; - LeaveCriticalSection(&g_critical); - } - g_pConfigDevice->Acquire(); - { - HRESULT hRslt = g_pConfigEffect->Start(1, 0); - if (hRslt != DI_OK ) - { - switch (hRslt) - { - case DIERR_INCOMPLETEEFFECT: - DebugWriteA("Test Rumble: DIError: incomplete effect.\n"); - break; - case DIERR_INVALIDPARAM: - DebugWriteA("Test Rumble: DIError: invalid param.\n"); - break; - case DIERR_NOTEXCLUSIVEACQUIRED: - DebugWriteA("Test Rumble: DIError: not exclusive acquired.\n"); - break; - case DIERR_NOTINITIALIZED: - DebugWriteA("Test Rumble: DIError: not initialized.\n"); - break; - case DIERR_UNSUPPORTED: - DebugWriteA("Test Rumble: DIError: unsupported.\n"); - break; - default: - DebugWriteA("Test Rumble: DIError: undocumented: %lX\n", hRslt); - } - } - else - DebugWriteA("Test Rumble: OK\n"); - } - return TRUE; + case IDC_RUMBLETEST: + if ( !g_pConfigEffect || bNewRumbleTyp ) + { + EnterCriticalSection(&g_critical); + ReleaseEffect( g_pConfigEffect ); + if ( !CreateEffectHandle(g_hMainDialog, g_pConfigDevice, g_pConfigEffect, pcController->bRumbleTyp, pcController->bRumbleStrength) ) + { + DebugWriteA("Interface: CreateEffectHandle failed\n"); + } + bNewRumbleTyp = false; + LeaveCriticalSection(&g_critical); + } + g_pConfigDevice->Acquire(); + { + HRESULT hRslt = g_pConfigEffect->Start(1, 0); + if (hRslt != DI_OK ) + { + switch (hRslt) + { + case DIERR_INCOMPLETEEFFECT: + DebugWriteA("Test Rumble: DIError: incomplete effect.\n"); + break; + case DIERR_INVALIDPARAM: + DebugWriteA("Test Rumble: DIError: invalid param.\n"); + break; + case DIERR_NOTEXCLUSIVEACQUIRED: + DebugWriteA("Test Rumble: DIError: not exclusive acquired.\n"); + break; + case DIERR_NOTINITIALIZED: + DebugWriteA("Test Rumble: DIError: not initialized.\n"); + break; + case DIERR_UNSUPPORTED: + DebugWriteA("Test Rumble: DIError: unsupported.\n"); + break; + default: + DebugWriteA("Test Rumble: DIError: undocumented: %lX\n", hRslt); + } + } + else + DebugWriteA("Test Rumble: OK\n"); + } + return TRUE; - default: - return FALSE; - } + default: + return FALSE; + } - case WM_HSCROLL: // TrackBars - case WM_VSCROLL: - i = GetWindowLong( (HWND)lParam, GWL_ID ); - switch( i ) - { - case IDC_RUMBLESTRENGTH: - pcController->bRumbleStrength = (BYTE)SendMessage( (HWND)lParam, TBM_GETPOS, 0, 0 ); - LoadString( g_hResourceDLL, IDS_D_RUMBLESTR, szTemp, DEFAULT_BUFFER ); - wsprintf( szBuffer, szTemp, pcController->bRumbleStrength ); - SendMessage( GetDlgItem( hDlg, IDT_RUMBLESTRENGTH ), WM_SETTEXT , 0, (LPARAM)szBuffer ); - bNewRumbleTyp = true; - return TRUE; - default: - return FALSE; - } + case WM_HSCROLL: // TrackBars + case WM_VSCROLL: + i = GetWindowLong( (HWND)lParam, GWL_ID ); + switch( i ) + { + case IDC_RUMBLESTRENGTH: + pcController->bRumbleStrength = (BYTE)SendMessage( (HWND)lParam, TBM_GETPOS, 0, 0 ); + LoadString( g_hResourceDLL, IDS_D_RUMBLESTR, szTemp, DEFAULT_BUFFER ); + wsprintf( szBuffer, szTemp, pcController->bRumbleStrength ); + SendMessage( GetDlgItem( hDlg, IDT_RUMBLESTRENGTH ), WM_SETTEXT , 0, (LPARAM)szBuffer ); + bNewRumbleTyp = true; + return TRUE; + default: + return FALSE; + } - case WM_USER_UPDATE: - // filling DropDownlist with devices - hDlgItem = GetDlgItem( hDlg, IDC_CTRDEVICE ); - SendMessage (hDlgItem, CB_RESETCONTENT, 0, 0); // HACK: yeah this isn't the best way to do this, but it works. - LoadString( g_hResourceDLL, IDS_P_R_NODEVICE, szBuffer, DEFAULT_BUFFER ); - j = SendMessage( hDlgItem, CB_ADDSTRING, 0, (LPARAM)szBuffer ); - SendMessage( hDlgItem, CB_SETITEMDATA, j, -1 ); - for( i = 0; i < g_nDevices; i++ ) - { - bool bMatch = false; - // if device is not already set as a FF device in some other tab - for( int m = 0; m < 4; m++) - { - if( g_ivConfig->ChosenTab != m) - if (g_devList[i].bProductCounter == g_ivConfig->FFDevices[m].bProductCounter && !lstrcmp( g_devList[i].szProductName, g_ivConfig->FFDevices[m].szProductName ) ) - bMatch = true; - } + case WM_USER_UPDATE: + // filling DropDownlist with devices + hDlgItem = GetDlgItem( hDlg, IDC_CTRDEVICE ); + SendMessage (hDlgItem, CB_RESETCONTENT, 0, 0); // HACK: yeah this isn't the best way to do this, but it works. + LoadString( g_hResourceDLL, IDS_P_R_NODEVICE, szBuffer, DEFAULT_BUFFER ); + j = SendMessage( hDlgItem, CB_ADDSTRING, 0, (LPARAM)szBuffer ); + SendMessage( hDlgItem, CB_SETITEMDATA, j, -1 ); + for( i = 0; i < g_nDevices; i++ ) + { + bool bMatch = false; + // if device is not already set as a FF device in some other tab + for( int m = 0; m < 4; m++) + { + if( g_ivConfig->ChosenTab != m) + if (g_devList[i].bProductCounter == g_ivConfig->FFDevices[m].bProductCounter && !lstrcmp( g_devList[i].szProductName, g_ivConfig->FFDevices[m].szProductName ) ) + bMatch = true; + } - if (!bMatch && g_devList[i].bEffType != 0 ) - { - if( g_devList[i].bProductCounter == 0 ) - lstrcpyn( szBuffer, g_devList[i].szProductName, ARRAYSIZE(szBuffer) ); - else - wsprintf( szBuffer, _T("%s %i"), g_devList[i].szProductName, g_devList[i].bProductCounter ); + if (!bMatch && g_devList[i].bEffType != 0 ) + { + if( g_devList[i].bProductCounter == 0 ) + lstrcpyn( szBuffer, g_devList[i].szProductName, ARRAYSIZE(szBuffer) ); + else + wsprintf( szBuffer, _T("%s %i"), g_devList[i].szProductName, g_devList[i].bProductCounter ); - j = SendMessage( hDlgItem, CB_ADDSTRING, 0, (LPARAM)szBuffer ); - SendMessage( hDlgItem, CB_SETITEMDATA, j, i ); - } - } - // DropDownlist End + j = SendMessage( hDlgItem, CB_ADDSTRING, 0, (LPARAM)szBuffer ); + SendMessage( hDlgItem, CB_SETITEMDATA, j, i ); + } + } + // DropDownlist End - EnterCriticalSection(&g_critical); - j = FindDeviceinList( pifDevice->szProductName, pifDevice->bProductCounter, true ); - hDlgItem = GetDlgItem( hDlg, IDC_CTRDEVICE ); - ReleaseEffect( g_pConfigEffect ); - ReleaseDevice( g_pConfigDevice ); - if( j == -1 || !g_devList[j].bEffType) - { - SendMessage( hDlgItem, CB_SETCURSEL, 0, 0 ); // set "None" - EnableWindow( GetDlgItem( hDlg, IDC_RUMBLE1 ), FALSE ); - EnableWindow( GetDlgItem( hDlg, IDC_RUMBLE2 ), FALSE ); - EnableWindow( GetDlgItem( hDlg, IDC_RUMBLE3 ), FALSE ); - EnableWindow( GetDlgItem( hDlg, IDC_RUMBLESTRENGTH ), FALSE ); - EnableWindow( GetDlgItem( hDlg, IDT_RUMBLESTRENGTH ), FALSE ); - EnableWindow( GetDlgItem( hDlg, IDC_RUMBLETEST ), FALSE ); - } - else - { - if (! GetInputDevice( g_hMainDialog, g_pConfigDevice, g_devList[j].guidInstance, g_devList[j].dwDevType, DIB_FF ) ) - { - g_pConfigDevice = NULL; - DebugWriteA("Could not GetInputDevice in user update, RumblePakProc.\n"); - } - else - { - DebugWriteA("GetInputDevice in RumblePakProc: OK\n"); - } + EnterCriticalSection(&g_critical); + j = FindDeviceinList( pifDevice->szProductName, pifDevice->bProductCounter, true ); + hDlgItem = GetDlgItem( hDlg, IDC_CTRDEVICE ); + ReleaseEffect( g_pConfigEffect ); + ReleaseDevice( g_pConfigDevice ); + if( j == -1 || !g_devList[j].bEffType) + { + SendMessage( hDlgItem, CB_SETCURSEL, 0, 0 ); // set "None" + EnableWindow( GetDlgItem( hDlg, IDC_RUMBLE1 ), FALSE ); + EnableWindow( GetDlgItem( hDlg, IDC_RUMBLE2 ), FALSE ); + EnableWindow( GetDlgItem( hDlg, IDC_RUMBLE3 ), FALSE ); + EnableWindow( GetDlgItem( hDlg, IDC_RUMBLESTRENGTH ), FALSE ); + EnableWindow( GetDlgItem( hDlg, IDT_RUMBLESTRENGTH ), FALSE ); + EnableWindow( GetDlgItem( hDlg, IDC_RUMBLETEST ), FALSE ); + } + else + { + if (! GetInputDevice( g_hMainDialog, g_pConfigDevice, g_devList[j].guidInstance, g_devList[j].dwDevType, DIB_FF ) ) + { + g_pConfigDevice = NULL; + DebugWriteA("Could not GetInputDevice in user update, RumblePakProc.\n"); + } + else + { + DebugWriteA("GetInputDevice in RumblePakProc: OK\n"); + } - // DropDownList - if( g_devList[j].bProductCounter == 0 ) - i = SendMessage( hDlgItem, CB_FINDSTRINGEXACT, (WPARAM)(-1), (LPARAM)g_devList[j].szProductName ); - else - { - wsprintf( szBuffer, _T("%s %i"), g_devList[j].szProductName, g_devList[j].bProductCounter ); - i = SendMessage( hDlgItem, CB_FINDSTRINGEXACT, (WPARAM)(-1), (LPARAM)szBuffer ); // search index of Device-String - } + // DropDownList + if( g_devList[j].bProductCounter == 0 ) + i = SendMessage( hDlgItem, CB_FINDSTRINGEXACT, (WPARAM)(-1), (LPARAM)g_devList[j].szProductName ); + else + { + wsprintf( szBuffer, _T("%s %i"), g_devList[j].szProductName, g_devList[j].bProductCounter ); + i = SendMessage( hDlgItem, CB_FINDSTRINGEXACT, (WPARAM)(-1), (LPARAM)szBuffer ); // search index of Device-String + } - SendMessage( hDlgItem, CB_SETCURSEL, i, 0 ); // select the right string + SendMessage( hDlgItem, CB_SETCURSEL, i, 0 ); // select the right string - if( g_devList[j].bEffType & RUMBLE_EFF1 ) - EnableWindow( GetDlgItem( hDlg, IDC_RUMBLE1 ), TRUE ); - else - EnableWindow( GetDlgItem( hDlg, IDC_RUMBLE1 ), FALSE ); - if( g_devList[j].bEffType & RUMBLE_EFF2 ) - EnableWindow( GetDlgItem( hDlg, IDC_RUMBLE2 ), TRUE ); - else - EnableWindow( GetDlgItem( hDlg, IDC_RUMBLE2 ), FALSE ); - if( g_devList[j].bEffType & RUMBLE_EFF3 ) - EnableWindow( GetDlgItem( hDlg, IDC_RUMBLE3 ), TRUE ); - else - EnableWindow( GetDlgItem( hDlg, IDC_RUMBLE3 ), FALSE ); + if( g_devList[j].bEffType & RUMBLE_EFF1 ) + EnableWindow( GetDlgItem( hDlg, IDC_RUMBLE1 ), TRUE ); + else + EnableWindow( GetDlgItem( hDlg, IDC_RUMBLE1 ), FALSE ); + if( g_devList[j].bEffType & RUMBLE_EFF2 ) + EnableWindow( GetDlgItem( hDlg, IDC_RUMBLE2 ), TRUE ); + else + EnableWindow( GetDlgItem( hDlg, IDC_RUMBLE2 ), FALSE ); + if( g_devList[j].bEffType & RUMBLE_EFF3 ) + EnableWindow( GetDlgItem( hDlg, IDC_RUMBLE3 ), TRUE ); + else + EnableWindow( GetDlgItem( hDlg, IDC_RUMBLE3 ), FALSE ); - if( ( g_devList[j].bEffType & RUMBLE_EFF1 ) || - ( g_devList[j].bEffType & RUMBLE_EFF2 )) - { - EnableWindow( GetDlgItem( hDlg, IDC_RUMBLESTRENGTH ), TRUE ); - EnableWindow( GetDlgItem( hDlg, IDT_RUMBLESTRENGTH ), TRUE ); - } - else - { - EnableWindow( GetDlgItem( hDlg, IDC_RUMBLESTRENGTH ), FALSE ); - EnableWindow( GetDlgItem( hDlg, IDT_RUMBLESTRENGTH ), FALSE ); - } + if( ( g_devList[j].bEffType & RUMBLE_EFF1 ) || + ( g_devList[j].bEffType & RUMBLE_EFF2 )) + { + EnableWindow( GetDlgItem( hDlg, IDC_RUMBLESTRENGTH ), TRUE ); + EnableWindow( GetDlgItem( hDlg, IDT_RUMBLESTRENGTH ), TRUE ); + } + else + { + EnableWindow( GetDlgItem( hDlg, IDC_RUMBLESTRENGTH ), FALSE ); + EnableWindow( GetDlgItem( hDlg, IDT_RUMBLESTRENGTH ), FALSE ); + } - if( g_devList[j].bEffType != RUMBLE_NONE ) - { - // if (!CreateEffectHandle(g_hMainDialog, g_pConfigDevice, g_pConfigEffect, pcController->bRumbleTyp, pcController->bRumbleStrength) ) - // { - // DebugWriteA("Interface: CreateEffectHandle failed\n"); - // } - bNewRumbleTyp = true; - EnableWindow( GetDlgItem( hDlg, IDC_RUMBLETEST ), TRUE ); - } - else - EnableWindow( GetDlgItem( hDlg, IDC_RUMBLETEST ), FALSE ); + if( g_devList[j].bEffType != RUMBLE_NONE ) + { + // if (!CreateEffectHandle(g_hMainDialog, g_pConfigDevice, g_pConfigEffect, pcController->bRumbleTyp, pcController->bRumbleStrength) ) + // { + // DebugWriteA("Interface: CreateEffectHandle failed\n"); + // } + bNewRumbleTyp = true; + EnableWindow( GetDlgItem( hDlg, IDC_RUMBLETEST ), TRUE ); + } + else + EnableWindow( GetDlgItem( hDlg, IDC_RUMBLETEST ), FALSE ); - } - LeaveCriticalSection(&g_critical); + } + LeaveCriticalSection(&g_critical); - if( pcController->bRumbleTyp == RUMBLE_EFF1 ) - CheckDlgButton( hDlg, IDC_RUMBLE1, BST_CHECKED ); - else - CheckDlgButton( hDlg, IDC_RUMBLE1, BST_UNCHECKED ); + if( pcController->bRumbleTyp == RUMBLE_EFF1 ) + CheckDlgButton( hDlg, IDC_RUMBLE1, BST_CHECKED ); + else + CheckDlgButton( hDlg, IDC_RUMBLE1, BST_UNCHECKED ); - if( pcController->bRumbleTyp == RUMBLE_EFF2 ) - CheckDlgButton( hDlg, IDC_RUMBLE2, BST_CHECKED ); - else - CheckDlgButton( hDlg, IDC_RUMBLE2, BST_UNCHECKED ); + if( pcController->bRumbleTyp == RUMBLE_EFF2 ) + CheckDlgButton( hDlg, IDC_RUMBLE2, BST_CHECKED ); + else + CheckDlgButton( hDlg, IDC_RUMBLE2, BST_UNCHECKED ); - if( pcController->bRumbleTyp == RUMBLE_EFF3 ) - CheckDlgButton( hDlg, IDC_RUMBLE3, BST_CHECKED ); - else - CheckDlgButton( hDlg, IDC_RUMBLE3, BST_UNCHECKED ); + if( pcController->bRumbleTyp == RUMBLE_EFF3 ) + CheckDlgButton( hDlg, IDC_RUMBLE3, BST_CHECKED ); + else + CheckDlgButton( hDlg, IDC_RUMBLE3, BST_UNCHECKED ); - CheckDlgButton( hDlg, IDC_VISUALRUMBLE, pcController->fVisualRumble ? BST_CHECKED : BST_UNCHECKED ); + CheckDlgButton( hDlg, IDC_VISUALRUMBLE, pcController->fVisualRumble ? BST_CHECKED : BST_UNCHECKED ); - // TrackBars - SendMessage( GetDlgItem( hDlg, IDC_RUMBLESTRENGTH ), TBM_SETPOS, TRUE, pcController->bRumbleStrength ); - LoadString( g_hResourceDLL, IDS_D_RUMBLESTR, szTemp, DEFAULT_BUFFER ); - wsprintf( szBuffer, szTemp, pcController->bRumbleStrength ); - SendMessage( GetDlgItem( hDlg, IDT_RUMBLESTRENGTH ), WM_SETTEXT , 0, (LPARAM)szBuffer ); + // TrackBars + SendMessage( GetDlgItem( hDlg, IDC_RUMBLESTRENGTH ), TBM_SETPOS, TRUE, pcController->bRumbleStrength ); + LoadString( g_hResourceDLL, IDS_D_RUMBLESTR, szTemp, DEFAULT_BUFFER ); + wsprintf( szBuffer, szTemp, pcController->bRumbleStrength ); + SendMessage( GetDlgItem( hDlg, IDT_RUMBLESTRENGTH ), WM_SETTEXT , 0, (LPARAM)szBuffer ); - return TRUE; + return TRUE; - default: - return FALSE; //false means the msg didn't got processed - } + default: + return FALSE; //false means the msg didn't got processed + } } BOOL CALLBACK TransferPakProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) { - static LPTSTR pszGBRomFile = NULL; - static LPTSTR pszGBSaveFile = NULL; - TCHAR tszMsg[DEFAULT_BUFFER]; + static LPTSTR pszGBRomFile = NULL; + static LPTSTR pszGBSaveFile = NULL; + TCHAR tszMsg[DEFAULT_BUFFER]; - switch(uMsg) - { - case WM_INITDIALOG: - if( g_bRunning ) - { - EnableWindow( GetDlgItem( hDlg, IDC_CHGDIR ), FALSE ); - LoadString( g_hResourceDLL, IDS_P_TRANS_NOCHANGE, tszMsg, DEFAULT_BUFFER ); - SendMessage( GetDlgItem( hDlg, IDC_CHGDIR ), WM_SETTEXT, 0, (LPARAM)tszMsg ); - } + switch(uMsg) + { + case WM_INITDIALOG: + if( g_bRunning ) + { + EnableWindow( GetDlgItem( hDlg, IDC_CHGDIR ), FALSE ); + LoadString( g_hResourceDLL, IDS_P_TRANS_NOCHANGE, tszMsg, DEFAULT_BUFFER ); + SendMessage( GetDlgItem( hDlg, IDC_CHGDIR ), WM_SETTEXT, 0, (LPARAM)tszMsg ); + } - TransferPakProc( hDlg, WM_USER_UPDATE, 0, 0 ); // setting values - return FALSE; // don't give it focus + TransferPakProc( hDlg, WM_USER_UPDATE, 0, 0 ); // setting values + return FALSE; // don't give it focus - case WM_COMMAND: - switch( LOWORD(wParam) ) - { - case IDC_GBROM_EDIT: - if( HIWORD(wParam) == EN_CHANGE ) - GetDlgItemText( hDlg, IDC_GBROM_EDIT, pszGBRomFile, ARRAYSIZE(g_ivConfig->Controllers->szTransferRom) ); - return TRUE; + case WM_COMMAND: + switch( LOWORD(wParam) ) + { + case IDC_GBROM_EDIT: + if( HIWORD(wParam) == EN_CHANGE ) + GetDlgItemText( hDlg, IDC_GBROM_EDIT, pszGBRomFile, ARRAYSIZE(g_ivConfig->Controllers->szTransferRom) ); + return TRUE; - case IDC_GBSAVE_EDIT: - if( HIWORD(wParam) == EN_CHANGE ) - GetDlgItemText( hDlg, IDC_GBSAVE_EDIT, pszGBSaveFile, ARRAYSIZE(g_ivConfig->Controllers->szTransferSave) ); - return TRUE; + case IDC_GBSAVE_EDIT: + if( HIWORD(wParam) == EN_CHANGE ) + GetDlgItemText( hDlg, IDC_GBSAVE_EDIT, pszGBSaveFile, ARRAYSIZE(g_ivConfig->Controllers->szTransferSave) ); + return TRUE; - case IDC_GBROM_BROWSE: - { - TCHAR szBuffer[MAX_PATH+1]; - GetAbsoluteFileName( szBuffer, pszGBRomFile, DIRECTORY_GBROMS ); - if( BrowseFile( hDlg, szBuffer, BF_GBROM, BF_LOAD )) - { - lstrcpyn( pszGBRomFile, szBuffer, ARRAYSIZE(g_ivConfig->Controllers->szTransferRom) ); - TransferPakProc( hDlg, WM_USER_UPDATE, 0, 0 ); - } - } - return TRUE; + case IDC_GBROM_BROWSE: + { + TCHAR szBuffer[MAX_PATH+1]; + GetAbsoluteFileName( szBuffer, pszGBRomFile, DIRECTORY_GBROMS ); + if( BrowseFile( hDlg, szBuffer, BF_GBROM, BF_LOAD )) + { + lstrcpyn( pszGBRomFile, szBuffer, ARRAYSIZE(g_ivConfig->Controllers->szTransferRom) ); + TransferPakProc( hDlg, WM_USER_UPDATE, 0, 0 ); + } + } + return TRUE; - case IDC_GBSAVE_BROWSE: - { - TCHAR szBuffer[MAX_PATH+1]; - GetAbsoluteFileName( szBuffer, pszGBSaveFile, DIRECTORY_GBSAVES ); - if( BrowseFile( hDlg, szBuffer, BF_GBSAVE, BF_LOAD )) - { - lstrcpyn( pszGBSaveFile, szBuffer, ARRAYSIZE(g_ivConfig->Controllers->szTransferSave) ); - TransferPakProc( hDlg, WM_USER_UPDATE, 0, 0 ); - } - } - return TRUE; + case IDC_GBSAVE_BROWSE: + { + TCHAR szBuffer[MAX_PATH+1]; + GetAbsoluteFileName( szBuffer, pszGBSaveFile, DIRECTORY_GBSAVES ); + if( BrowseFile( hDlg, szBuffer, BF_GBSAVE, BF_LOAD )) + { + lstrcpyn( pszGBSaveFile, szBuffer, ARRAYSIZE(g_ivConfig->Controllers->szTransferSave) ); + TransferPakProc( hDlg, WM_USER_UPDATE, 0, 0 ); + } + } + return TRUE; - case IDC_CHGDIR: - if (DialogBox(g_hResourceDLL, MAKEINTRESOURCE(IDD_FOLDERS), hDlg, (DLGPROC)FoldersDialogProc) == TRUE) - TransferPakProc( hDlg, WM_USER_UPDATE, 0, 0 ); - return TRUE; + case IDC_CHGDIR: + if (DialogBox(g_hResourceDLL, MAKEINTRESOURCE(IDD_FOLDERS), hDlg, (DLGPROC)FoldersDialogProc) == TRUE) + TransferPakProc( hDlg, WM_USER_UPDATE, 0, 0 ); + return TRUE; - default: - return FALSE; - } + default: + return FALSE; + } - case WM_USER_UPDATE: - pszGBRomFile = g_ivConfig->Controllers[g_ivConfig->ChosenTab].szTransferRom; - pszGBSaveFile = g_ivConfig->Controllers[g_ivConfig->ChosenTab].szTransferSave; + case WM_USER_UPDATE: + pszGBRomFile = g_ivConfig->Controllers[g_ivConfig->ChosenTab].szTransferRom; + pszGBSaveFile = g_ivConfig->Controllers[g_ivConfig->ChosenTab].szTransferSave; - SetDlgItemText( hDlg, IDC_GBROM_EDIT, pszGBRomFile ); - SetDlgItemText( hDlg, IDC_GBSAVE_EDIT, pszGBSaveFile ); - return TRUE; + SetDlgItemText( hDlg, IDC_GBROM_EDIT, pszGBRomFile ); + SetDlgItemText( hDlg, IDC_GBSAVE_EDIT, pszGBSaveFile ); + return TRUE; - default: - return FALSE; //false means the msg didn't got processed - } + default: + return FALSE; //false means the msg didn't got processed + } } BOOL CALLBACK ShortcutsTabProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) { - static bool bScanRunning; - static DWORD dwButtonID[3]; - static DWORD dwCounter; - static HWND hFocus = NULL; - static int iPlayer = 5; // HACK: player "5" is obviously out of bounds, so indicates no control has been set + static bool bScanRunning; + static DWORD dwButtonID[3]; + static DWORD dwCounter; + static HWND hFocus = NULL; + static int iPlayer = 5; // HACK: player "5" is obviously out of bounds, so indicates no control has been set - long i; - static HWND hBlocker = NULL; + long i; + static HWND hBlocker = NULL; - TCHAR szBuffer[40]; + TCHAR szBuffer[40]; - switch(uMsg) - { - case WM_INITDIALOG: - bScanRunning = false; - iPlayer = 5; + switch(uMsg) + { + case WM_INITDIALOG: + bScanRunning = false; + iPlayer = 5; - ShortcutsTabProc( hDlg, WM_USER_UPDATE, 0, 0 ); // setting values - return FALSE; // don't give it focus + ShortcutsTabProc( hDlg, WM_USER_UPDATE, 0, 0 ); // setting values + return FALSE; // don't give it focus - case WM_COMMAND: - switch( LOWORD(wParam) ) - { - case IDC_SHOWMESSAGES: - g_ivConfig->fDisplayShortPop = ( IsDlgButtonChecked( hDlg, LOWORD(wParam) ) == BST_CHECKED ); - return TRUE; - case IDC_LOCKMOUSE: - iPlayer = -1; + case WM_COMMAND: + switch( LOWORD(wParam) ) + { + case IDC_SHOWMESSAGES: + g_ivConfig->fDisplayShortPop = ( IsDlgButtonChecked( hDlg, LOWORD(wParam) ) == BST_CHECKED ); + return TRUE; + case IDC_LOCKMOUSE: + iPlayer = -1; - case IDC_SETNOPAK_P1: - case IDC_SETMEMPAK_P1: - case IDC_SETRUMBLEPAK_P1: - case IDC_SETTRANSFERPAK_P1: - case IDC_SETADAPTOIDPAK_P1: - case IDC_SWMEMRUMBLE_P1: - case IDC_SWMEMADAPTOID_P1: - if (iPlayer > -1) - iPlayer = 0; + case IDC_SETNOPAK_P1: + case IDC_SETMEMPAK_P1: + case IDC_SETRUMBLEPAK_P1: + case IDC_SETTRANSFERPAK_P1: + case IDC_SETADAPTOIDPAK_P1: + case IDC_SWMEMRUMBLE_P1: + case IDC_SWMEMADAPTOID_P1: + if (iPlayer > -1) + iPlayer = 0; - case IDC_SETNOPAK_P2: - case IDC_SETMEMPAK_P2: - case IDC_SETRUMBLEPAK_P2: - case IDC_SETTRANSFERPAK_P2: - case IDC_SETADAPTOIDPAK_P2: - case IDC_SWMEMRUMBLE_P2: - case IDC_SWMEMADAPTOID_P2: - if (iPlayer > 0) - iPlayer = 1; + case IDC_SETNOPAK_P2: + case IDC_SETMEMPAK_P2: + case IDC_SETRUMBLEPAK_P2: + case IDC_SETTRANSFERPAK_P2: + case IDC_SETADAPTOIDPAK_P2: + case IDC_SWMEMRUMBLE_P2: + case IDC_SWMEMADAPTOID_P2: + if (iPlayer > 0) + iPlayer = 1; - case IDC_SETNOPAK_P3: - case IDC_SETMEMPAK_P3: - case IDC_SETRUMBLEPAK_P3: - case IDC_SETTRANSFERPAK_P3: - case IDC_SETADAPTOIDPAK_P3: - case IDC_SWMEMRUMBLE_P3: - case IDC_SWMEMADAPTOID_P3: - if (iPlayer > 1) - iPlayer = 2; + case IDC_SETNOPAK_P3: + case IDC_SETMEMPAK_P3: + case IDC_SETRUMBLEPAK_P3: + case IDC_SETTRANSFERPAK_P3: + case IDC_SETADAPTOIDPAK_P3: + case IDC_SWMEMRUMBLE_P3: + case IDC_SWMEMADAPTOID_P3: + if (iPlayer > 1) + iPlayer = 2; - case IDC_SETNOPAK_P4: - case IDC_SETMEMPAK_P4: - case IDC_SETRUMBLEPAK_P4: - case IDC_SETTRANSFERPAK_P4: - case IDC_SETADAPTOIDPAK_P4: - case IDC_SWMEMRUMBLE_P4: - case IDC_SWMEMADAPTOID_P4: - if (iPlayer > 2) - iPlayer = 3; + case IDC_SETNOPAK_P4: + case IDC_SETMEMPAK_P4: + case IDC_SETRUMBLEPAK_P4: + case IDC_SETTRANSFERPAK_P4: + case IDC_SETADAPTOIDPAK_P4: + case IDC_SWMEMRUMBLE_P4: + case IDC_SWMEMADAPTOID_P4: + if (iPlayer > 2) + iPlayer = 3; - if( bScanRunning ) - { -/* bScanRunning = false; - KillTimer( hDlg, TIMER_BUTTON ); - if( ((LPBYTE)&g_ivConfig->Shortcuts)[dwButtonID[2]] == VK_ESCAPE ) - lstrcpyn( szKeyname, "Unassigned", sizeof(szKeyname) ); - else - GetKeyNameText(( MapVirtualKey( ((LPBYTE)&g_ivConfig->Shortcuts)[dwButtonID[2]], 0 ) << 16 ), szKeyname, sizeof(szKeyname) ); + if( bScanRunning ) + { +/* bScanRunning = false; + KillTimer( hDlg, TIMER_BUTTON ); + if( ((LPBYTE)&g_ivConfig->Shortcuts)[dwButtonID[2]] == VK_ESCAPE ) + lstrcpyn( szKeyname, "Unassigned", sizeof(szKeyname) ); + else + GetKeyNameText(( MapVirtualKey( ((LPBYTE)&g_ivConfig->Shortcuts)[dwButtonID[2]], 0 ) << 16 ), szKeyname, sizeof(szKeyname) ); - SendMessage( GetDlgItem( hDlg, dwButtonID[1] ), WM_SETTEXT, 0, (LPARAM)szKeyname ); */; // do nothing! - } - if( HIWORD(wParam) == BN_CLICKED ) - { - EnterCriticalSection(&g_critical); - dwButtonID[0] = LOWORD(wParam); - dwCounter = 0; - GetButtonID( dwButtonID, 0, BSET_SHORTCUTS ); - if (hFocus == NULL) - hFocus = SetFocus( NULL ); - hBlocker = MakeOverlay(); + SendMessage( GetDlgItem( hDlg, dwButtonID[1] ), WM_SETTEXT, 0, (LPARAM)szKeyname ); */; // do nothing! + } + if( HIWORD(wParam) == BN_CLICKED ) + { + EnterCriticalSection(&g_critical); + dwButtonID[0] = LOWORD(wParam); + dwCounter = 0; + GetButtonID( dwButtonID, 0, BSET_SHORTCUTS ); + if (hFocus == NULL) + hFocus = SetFocus( NULL ); + hBlocker = MakeOverlay(); - SetTimer( hDlg, TIMER_BUTTON, INTERVAL_BUTTON, NULL ); - bScanRunning = true; - LeaveCriticalSection(&g_critical); - } - return TRUE; + SetTimer( hDlg, TIMER_BUTTON, INTERVAL_BUTTON, NULL ); + bScanRunning = true; + LeaveCriticalSection(&g_critical); + } + return TRUE; - case IDC_SETDEFAULTSC: - { - TCHAR tszTitle[DEFAULT_BUFFER], tszMsg[DEFAULT_BUFFER]; + case IDC_SETDEFAULTSC: + { + TCHAR tszTitle[DEFAULT_BUFFER], tszMsg[DEFAULT_BUFFER]; - LoadString( g_hResourceDLL, IDS_DLG_SHORTCUTRESTORE, tszMsg, DEFAULT_BUFFER ); - LoadString( g_hResourceDLL, IDS_DLG_CONTROLRESTORE_TITLE, tszTitle, DEFAULT_BUFFER ); + LoadString( g_hResourceDLL, IDS_DLG_SHORTCUTRESTORE, tszMsg, DEFAULT_BUFFER ); + LoadString( g_hResourceDLL, IDS_DLG_CONTROLRESTORE_TITLE, tszTitle, DEFAULT_BUFFER ); - if( MessageBox( hDlg, tszMsg, tszTitle, MB_OKCANCEL | MB_ICONWARNING ) == IDOK ) - { - LoadShortcutsFromResource(true); - ShortcutsTabProc( hDlg, WM_USER_UPDATE, 0, 0 ); - } - } - return TRUE; + if( MessageBox( hDlg, tszMsg, tszTitle, MB_OKCANCEL | MB_ICONWARNING ) == IDOK ) + { + LoadShortcutsFromResource(true); + ShortcutsTabProc( hDlg, WM_USER_UPDATE, 0, 0 ); + } + } + return TRUE; - case IDC_SAVESHORTCUTS: - { - TCHAR szFilename[MAX_PATH+1] = _T( "" ); - if( BrowseFile( hDlg, szFilename, BF_SHORTCUTS, BF_SAVE )) - { - FILE * fFile = _tfopen( szFilename, _T("wS") ); - if (fFile) - { - fprintf(fFile, "@" STRING_PROFILEVERSION "\n\n"); - FormatShortcutsBlock( fFile, false ); + case IDC_SAVESHORTCUTS: + { + TCHAR szFilename[MAX_PATH+1] = _T( "" ); + if( BrowseFile( hDlg, szFilename, BF_SHORTCUTS, BF_SAVE )) + { + FILE * fFile = _tfopen( szFilename, _T("wS") ); + if (fFile) + { + fprintf(fFile, "@" STRING_PROFILEVERSION "\n\n"); + FormatShortcutsBlock( fFile, false ); - fclose(fFile); - } - else - WarningMessage( IDS_ERR_PROFWRITE, MB_OK ); - } - } - return TRUE; + fclose(fFile); + } + else + WarningMessage( IDS_ERR_PROFWRITE, MB_OK ); + } + } + return TRUE; - case IDC_LOADSHORTCUTS: - { - TCHAR szFilename[MAX_PATH+1] = TEXT( "" ); - if( BrowseFile( hDlg, szFilename, BF_SHORTCUTS, BF_LOAD )) - { - DebugWrite(_T("Config interface: Load shortcuts file: %s\n"), szFilename); - if( LoadShortcutsFile( szFilename )) - ShortcutsTabProc( hDlg, WM_USER_UPDATE, 0, 0 ); - else - WarningMessage( IDS_ERR_SHORTREAD, MB_OK ); + case IDC_LOADSHORTCUTS: + { + TCHAR szFilename[MAX_PATH+1] = TEXT( "" ); + if( BrowseFile( hDlg, szFilename, BF_SHORTCUTS, BF_LOAD )) + { + DebugWrite(_T("Config interface: Load shortcuts file: %s\n"), szFilename); + if( LoadShortcutsFile( szFilename )) + ShortcutsTabProc( hDlg, WM_USER_UPDATE, 0, 0 ); + else + WarningMessage( IDS_ERR_SHORTREAD, MB_OK ); - } - } - return TRUE; + } + } + return TRUE; - default: - return FALSE; - } + default: + return FALSE; + } - case WM_TIMER: // when assigning shortcuts, this gets called every 20ms (or value in INTERVAL_BUTTON) - if( wParam == TIMER_BUTTON && bScanRunning ) - { - BUTTON newButton; + case WM_TIMER: // when assigning shortcuts, this gets called every 20ms (or value in INTERVAL_BUTTON) + if( wParam == TIMER_BUTTON && bScanRunning ) + { + BUTTON newButton; - i = ScanDevices( &dwCounter, &newButton); - if( i || dwCounter > 500 ) - { - bScanRunning = false; - KillTimer( hDlg, TIMER_BUTTON ); + i = ScanDevices( &dwCounter, &newButton); + if( i || dwCounter > 500 ) + { + bScanRunning = false; + KillTimer( hDlg, TIMER_BUTTON ); - EnterCriticalSection(&g_critical); - if( i == SC_SCANESCAPE ) // Scan aborted - { - if (iPlayer == -1) - ZeroMemory(&g_ivConfig->Shortcuts.bMouseLock, sizeof(BUTTON) ); - else - ZeroMemory(&g_ivConfig->Shortcuts.Player[iPlayer].aButtons[dwButtonID[2] % SC_TOTAL], sizeof(BUTTON)); - } - else if( i == SC_SCANSUCCEED ) // Got a key, mouseclick, joybutton, or axis - if (iPlayer == -1) - g_ivConfig->Shortcuts.bMouseLock = newButton; - else - g_ivConfig->Shortcuts.Player[iPlayer].aButtons[dwButtonID[2] % SC_TOTAL] = newButton; - DestroyWindow( hBlocker ); + EnterCriticalSection(&g_critical); + if( i == SC_SCANESCAPE ) // Scan aborted + { + if (iPlayer == -1) + ZeroMemory(&g_ivConfig->Shortcuts.bMouseLock, sizeof(BUTTON) ); + else + ZeroMemory(&g_ivConfig->Shortcuts.Player[iPlayer].aButtons[dwButtonID[2] % SC_TOTAL], sizeof(BUTTON)); + } + else if( i == SC_SCANSUCCEED ) // Got a key, mouseclick, joybutton, or axis + if (iPlayer == -1) + g_ivConfig->Shortcuts.bMouseLock = newButton; + else + g_ivConfig->Shortcuts.Player[iPlayer].aButtons[dwButtonID[2] % SC_TOTAL] = newButton; + DestroyWindow( hBlocker ); - if (iPlayer == -1) - GetButtonText( g_ivConfig->Shortcuts.bMouseLock, szBuffer ); - else - GetButtonText( g_ivConfig->Shortcuts.Player[iPlayer].aButtons[dwButtonID[2] % SC_TOTAL], szBuffer ); - iPlayer = 5; // reset invalid player value - LeaveCriticalSection(&g_critical); + if (iPlayer == -1) + GetButtonText( g_ivConfig->Shortcuts.bMouseLock, szBuffer ); + else + GetButtonText( g_ivConfig->Shortcuts.Player[iPlayer].aButtons[dwButtonID[2] % SC_TOTAL], szBuffer ); + iPlayer = 5; // reset invalid player value + LeaveCriticalSection(&g_critical); - SendMessage( GetDlgItem( hDlg, dwButtonID[1] ), WM_SETTEXT , 0, (LPARAM)szBuffer ); - if( hFocus != NULL ) - { - SetFocus( hFocus ); - hFocus = NULL; - } - } - else - { - if(( dwCounter % 50 ) == 0 ) - { - TCHAR tszText[DEFAULT_BUFFER]; + SendMessage( GetDlgItem( hDlg, dwButtonID[1] ), WM_SETTEXT , 0, (LPARAM)szBuffer ); + if( hFocus != NULL ) + { + SetFocus( hFocus ); + hFocus = NULL; + } + } + else + { + if(( dwCounter % 50 ) == 0 ) + { + TCHAR tszText[DEFAULT_BUFFER]; - LoadString( g_hResourceDLL, IDS_C_POLLING, tszText, DEFAULT_BUFFER ); - wsprintf( szBuffer, tszText, 10 - dwCounter / 50 ); - SendMessage( GetDlgItem( hDlg, dwButtonID[1] ), WM_SETTEXT , 0, (LPARAM)szBuffer ); - } - ++dwCounter; - } - return TRUE; - } - else - return FALSE; + LoadString( g_hResourceDLL, IDS_C_POLLING, tszText, DEFAULT_BUFFER ); + wsprintf( szBuffer, tszText, 10 - dwCounter / 50 ); + SendMessage( GetDlgItem( hDlg, dwButtonID[1] ), WM_SETTEXT , 0, (LPARAM)szBuffer ); + } + ++dwCounter; + } + return TRUE; + } + else + return FALSE; - case WM_USER_UPDATE: - bScanRunning = false; - KillTimer( hDlg, TIMER_BUTTON ); + case WM_USER_UPDATE: + bScanRunning = false; + KillTimer( hDlg, TIMER_BUTTON ); - for ( i = 0; i < 4; i++ ) // controllers - for( int j = 0; j < SC_TOTAL * 4; j++ ) // shortcuts - { - DWORD aIDs[3]; - aIDs[2] = i * SC_TOTAL + j; - if( !GetButtonID( aIDs, 2, BSET_SHORTCUTS )) - continue; // for not implemented Buttons, otherwise the behaviour is unsafe + for ( i = 0; i < 4; i++ ) // controllers + for( int j = 0; j < SC_TOTAL * 4; j++ ) // shortcuts + { + DWORD aIDs[3]; + aIDs[2] = i * SC_TOTAL + j; + if( !GetButtonID( aIDs, 2, BSET_SHORTCUTS )) + continue; // for not implemented Buttons, otherwise the behaviour is unsafe - GetButtonText( g_ivConfig->Shortcuts.Player[i].aButtons[j], szBuffer ); - SendMessage( GetDlgItem( hDlg, aIDs[1] ), WM_SETTEXT , 0, (LPARAM)szBuffer ); - } + GetButtonText( g_ivConfig->Shortcuts.Player[i].aButtons[j], szBuffer ); + SendMessage( GetDlgItem( hDlg, aIDs[1] ), WM_SETTEXT , 0, (LPARAM)szBuffer ); + } - DWORD aIDs[3]; - aIDs[2] = (DWORD)(-1); - if( GetButtonID( aIDs, 2, BSET_SHORTCUTS ) ) - { - GetButtonText( g_ivConfig->Shortcuts.bMouseLock, szBuffer ); - SendMessage( GetDlgItem( hDlg, aIDs[1] ), WM_SETTEXT , 0, (LPARAM)szBuffer ); - } + DWORD aIDs[3]; + aIDs[2] = (DWORD)(-1); + if( GetButtonID( aIDs, 2, BSET_SHORTCUTS ) ) + { + GetButtonText( g_ivConfig->Shortcuts.bMouseLock, szBuffer ); + SendMessage( GetDlgItem( hDlg, aIDs[1] ), WM_SETTEXT , 0, (LPARAM)szBuffer ); + } - CheckDlgButton( hDlg, IDC_SHOWMESSAGES, g_ivConfig->fDisplayShortPop ? BST_CHECKED : BST_UNCHECKED ); - return TRUE; + CheckDlgButton( hDlg, IDC_SHOWMESSAGES, g_ivConfig->fDisplayShortPop ? BST_CHECKED : BST_UNCHECKED ); + return TRUE; - default: - return FALSE; //false means the msg didn't got processed - } + default: + return FALSE; //false means the msg didn't got processed + } } BOOL CALLBACK FoldersDialogProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) { - long i,j; - TCHAR szBuffer[MAX_PATH+1]; - TCHAR szApplication[MAX_PATH+1], - *pcSlash; + long i,j; + TCHAR szBuffer[MAX_PATH+1]; + TCHAR szApplication[MAX_PATH+1], + *pcSlash; - switch(uMsg) - { - case WM_INITDIALOG: + switch(uMsg) + { + case WM_INITDIALOG: #if defined(HIDEUNIMPLEMENTED) && !defined(V_TRANSFERPAK) - { - RECT rRect, rGBSave; - GetWindowRect( GetDlgItem( hDlg, IDC_GBSAVEPANEL ), &rGBSave ); - GetWindowRect( GetDlgItem( hDlg, IDC_MEMPAKPANEL ), &rRect ); - int iShift = rRect.bottom - rGBSave.bottom; + { + RECT rRect, rGBSave; + GetWindowRect( GetDlgItem( hDlg, IDC_GBSAVEPANEL ), &rGBSave ); + GetWindowRect( GetDlgItem( hDlg, IDC_MEMPAKPANEL ), &rRect ); + int iShift = rRect.bottom - rGBSave.bottom; - WINDOWPLACEMENT pos; - pos.length = sizeof(WINDOWPLACEMENT); + WINDOWPLACEMENT pos; + pos.length = sizeof(WINDOWPLACEMENT); - GetWindowPlacement( GetDlgItem( hDlg, IDOK ), &pos ); - pos.rcNormalPosition.top += iShift; - pos.rcNormalPosition.bottom += iShift; - SetWindowPlacement( GetDlgItem( hDlg, IDOK ), &pos ); + GetWindowPlacement( GetDlgItem( hDlg, IDOK ), &pos ); + pos.rcNormalPosition.top += iShift; + pos.rcNormalPosition.bottom += iShift; + SetWindowPlacement( GetDlgItem( hDlg, IDOK ), &pos ); - GetWindowPlacement( GetDlgItem( hDlg, IDCANCEL ), &pos ); - pos.rcNormalPosition.top += iShift; - pos.rcNormalPosition.bottom += iShift; - SetWindowPlacement( GetDlgItem( hDlg, IDCANCEL ), &pos ); + GetWindowPlacement( GetDlgItem( hDlg, IDCANCEL ), &pos ); + pos.rcNormalPosition.top += iShift; + pos.rcNormalPosition.bottom += iShift; + SetWindowPlacement( GetDlgItem( hDlg, IDCANCEL ), &pos ); - GetWindowRect( hDlg, &rRect ); - rRect.bottom += iShift; + GetWindowRect( hDlg, &rRect ); + rRect.bottom += iShift; - SetWindowPos( hDlg, NULL, rRect.left, rRect.top, rRect.right-rRect.left, rRect.bottom-rRect.top, SWP_NOMOVE | SWP_NOZORDER ); + SetWindowPos( hDlg, NULL, rRect.left, rRect.top, rRect.right-rRect.left, rRect.bottom-rRect.top, SWP_NOMOVE | SWP_NOZORDER ); - int aChilds[] = { IDC_GBROMPANEL, IDC_GBROM_REL, IDC_GBROM_REL_EDIT, IDC_GBROM_BROWSE_REL, IDC_GBROM_ABS, - IDC_GBROM_ABS_EDIT, IDC_GBROM_BROWSE_ABS, IDC_GBSAVEPANEL, IDC_GBSAVE_SAME, IDC_GBSAVE_REL, - IDC_GBSAVE_REL_EDIT, IDC_GBSAVE_BROWSE_REL, IDC_GBSAVE_ABS, IDC_GBSAVE_ABS_EDIT, IDC_GBSAVE_BROWSE_ABS }; + int aChilds[] = { IDC_GBROMPANEL, IDC_GBROM_REL, IDC_GBROM_REL_EDIT, IDC_GBROM_BROWSE_REL, IDC_GBROM_ABS, + IDC_GBROM_ABS_EDIT, IDC_GBROM_BROWSE_ABS, IDC_GBSAVEPANEL, IDC_GBSAVE_SAME, IDC_GBSAVE_REL, + IDC_GBSAVE_REL_EDIT, IDC_GBSAVE_BROWSE_REL, IDC_GBSAVE_ABS, IDC_GBSAVE_ABS_EDIT, IDC_GBSAVE_BROWSE_ABS }; - for( int i = 0; i < sizeof(aChilds)/sizeof(int); ++i ) - DestroyWindow( GetDlgItem( hDlg, aChilds[i] )); - } + for( int i = 0; i < sizeof(aChilds)/sizeof(int); ++i ) + DestroyWindow( GetDlgItem( hDlg, aChilds[i] )); + } #pragma message( "unimplemented Features from the Folderdialog will be removed" ) #endif // #ifdef HIDEUNIMPLEMENTED - GetDirectory( szApplication, DIRECTORY_GBROMS ); - GetDirectory( szBuffer, DIRECTORY_GBSAVES ); - j = lstrcmp( szApplication, szBuffer ); + GetDirectory( szApplication, DIRECTORY_GBROMS ); + GetDirectory( szBuffer, DIRECTORY_GBSAVES ); + j = lstrcmp( szApplication, szBuffer ); - GetDirectory( szApplication, DIRECTORY_APPLICATION ); - i = lstrlen( szApplication ); + GetDirectory( szApplication, DIRECTORY_APPLICATION ); + i = lstrlen( szApplication ); - // MemPak Directory - lstrcpyn(szBuffer, g_aszDefFolders[DIRECTORY_MEMPAK], MAX_PATH); + // MemPak Directory + lstrcpyn(szBuffer, g_aszDefFolders[DIRECTORY_MEMPAK], MAX_PATH); - if( szBuffer[0] != 0 && ( szBuffer[1] == ':' || ( szBuffer[1] == '\\' && szBuffer[0] == '\\' ))) - { - CheckDlgButton( hDlg, IDC_MEMPAK_ABS, BST_CHECKED ); + if( szBuffer[0] != 0 && ( szBuffer[1] == ':' || ( szBuffer[1] == '\\' && szBuffer[0] == '\\' ))) + { + CheckDlgButton( hDlg, IDC_MEMPAK_ABS, BST_CHECKED ); - GetDirectory( szBuffer, DIRECTORY_MEMPAK ); - if( !_tcsncmp( szBuffer, szApplication, i )) - { - TCHAR *pcSub = &szBuffer[i]; - pcSlash = _tcsrchr( pcSub, _T('\\') ); - if( pcSlash && ( pcSlash[1] == '\0' )) *pcSlash = '\0'; - SendMessage( GetDlgItem( hDlg, IDC_MEMPAK_REL_EDIT ), WM_SETTEXT, 0, (LPARAM)pcSub ); - } - else - SendMessage( GetDlgItem( hDlg, IDC_MEMPAK_REL_EDIT ), WM_SETTEXT, 0, (LPARAM)STRING_DEF_MEMPAKFILE ); - } - else - { - CheckDlgButton( hDlg, IDC_MEMPAK_REL, BST_CHECKED ); + GetDirectory( szBuffer, DIRECTORY_MEMPAK ); + if( !_tcsncmp( szBuffer, szApplication, i )) + { + TCHAR *pcSub = &szBuffer[i]; + pcSlash = _tcsrchr( pcSub, _T('\\') ); + if( pcSlash && ( pcSlash[1] == '\0' )) *pcSlash = '\0'; + SendMessage( GetDlgItem( hDlg, IDC_MEMPAK_REL_EDIT ), WM_SETTEXT, 0, (LPARAM)pcSub ); + } + else + SendMessage( GetDlgItem( hDlg, IDC_MEMPAK_REL_EDIT ), WM_SETTEXT, 0, (LPARAM)STRING_DEF_MEMPAKFILE ); + } + else + { + CheckDlgButton( hDlg, IDC_MEMPAK_REL, BST_CHECKED ); - if( szBuffer[0] != 0 ) - SendMessage( GetDlgItem( hDlg, IDC_MEMPAK_REL_EDIT ), WM_SETTEXT, 0, (LPARAM)szBuffer ); - else - SendMessage( GetDlgItem( hDlg, IDC_MEMPAK_REL_EDIT ), WM_SETTEXT, 0, (LPARAM)STRING_DEF_MEMPAKFILE ); - } + if( szBuffer[0] != 0 ) + SendMessage( GetDlgItem( hDlg, IDC_MEMPAK_REL_EDIT ), WM_SETTEXT, 0, (LPARAM)szBuffer ); + else + SendMessage( GetDlgItem( hDlg, IDC_MEMPAK_REL_EDIT ), WM_SETTEXT, 0, (LPARAM)STRING_DEF_MEMPAKFILE ); + } - GetDirectory( szBuffer, DIRECTORY_MEMPAK ); - pcSlash = _tcsrchr( szBuffer, '\\' ); - if( pcSlash && ( pcSlash[1] == '\0' )) *pcSlash = '\0'; - SendMessage( GetDlgItem( hDlg, IDC_MEMPAK_ABS_EDIT ), WM_SETTEXT, 0, (LPARAM)szBuffer ); + GetDirectory( szBuffer, DIRECTORY_MEMPAK ); + pcSlash = _tcsrchr( szBuffer, '\\' ); + if( pcSlash && ( pcSlash[1] == '\0' )) *pcSlash = '\0'; + SendMessage( GetDlgItem( hDlg, IDC_MEMPAK_ABS_EDIT ), WM_SETTEXT, 0, (LPARAM)szBuffer ); - // GBRom Directory - lstrcpyn(szBuffer, g_aszDefFolders[DIRECTORY_GBROMS], MAX_PATH); + // GBRom Directory + lstrcpyn(szBuffer, g_aszDefFolders[DIRECTORY_GBROMS], MAX_PATH); - if( szBuffer[0] != 0 && ( szBuffer[1] == _T(':') || ( szBuffer[1] == _T('\\') && szBuffer[0] == _T('\\') ))) - { - CheckDlgButton( hDlg, IDC_GBROM_ABS, BST_CHECKED ); + if( szBuffer[0] != 0 && ( szBuffer[1] == _T(':') || ( szBuffer[1] == _T('\\') && szBuffer[0] == _T('\\') ))) + { + CheckDlgButton( hDlg, IDC_GBROM_ABS, BST_CHECKED ); - GetDirectory( szBuffer, DIRECTORY_GBROMS ); - if( !_tcsncmp( szBuffer, szApplication, i )) - { - TCHAR *pcSub = &szBuffer[i]; - pcSlash = _tcsrchr( pcSub, _T('\\') ); - if( pcSlash && ( pcSlash[1] == '\0' )) *pcSlash = '\0'; - SendMessage( GetDlgItem( hDlg, IDC_GBROM_REL_EDIT ), WM_SETTEXT, 0, (LPARAM)szBuffer ); - } - else - SendMessage( GetDlgItem( hDlg, IDC_GBROM_REL_EDIT ), WM_SETTEXT, 0, (LPARAM)STRING_DEF_GBROMFILE ); - } - else - { - CheckDlgButton( hDlg, IDC_GBROM_REL, BST_CHECKED ); + GetDirectory( szBuffer, DIRECTORY_GBROMS ); + if( !_tcsncmp( szBuffer, szApplication, i )) + { + TCHAR *pcSub = &szBuffer[i]; + pcSlash = _tcsrchr( pcSub, _T('\\') ); + if( pcSlash && ( pcSlash[1] == '\0' )) *pcSlash = '\0'; + SendMessage( GetDlgItem( hDlg, IDC_GBROM_REL_EDIT ), WM_SETTEXT, 0, (LPARAM)szBuffer ); + } + else + SendMessage( GetDlgItem( hDlg, IDC_GBROM_REL_EDIT ), WM_SETTEXT, 0, (LPARAM)STRING_DEF_GBROMFILE ); + } + else + { + CheckDlgButton( hDlg, IDC_GBROM_REL, BST_CHECKED ); - if( szBuffer[0] != 0 ) - SendMessage( GetDlgItem( hDlg, IDC_GBROM_REL_EDIT ), WM_SETTEXT, 0, (LPARAM)szBuffer ); - else - SendMessage( GetDlgItem( hDlg, IDC_GBROM_REL_EDIT ), WM_SETTEXT, 0, (LPARAM)STRING_DEF_GBROMFILE ); - } + if( szBuffer[0] != 0 ) + SendMessage( GetDlgItem( hDlg, IDC_GBROM_REL_EDIT ), WM_SETTEXT, 0, (LPARAM)szBuffer ); + else + SendMessage( GetDlgItem( hDlg, IDC_GBROM_REL_EDIT ), WM_SETTEXT, 0, (LPARAM)STRING_DEF_GBROMFILE ); + } - GetDirectory( szBuffer, DIRECTORY_GBROMS ); - pcSlash = _tcsrchr( szBuffer, _T('\\') ); - if( pcSlash && ( pcSlash[1] == _T('\0') )) *pcSlash = '\0'; - SendMessage( GetDlgItem( hDlg, IDC_GBROM_ABS_EDIT ), WM_SETTEXT, 0, (LPARAM)szBuffer ); + GetDirectory( szBuffer, DIRECTORY_GBROMS ); + pcSlash = _tcsrchr( szBuffer, _T('\\') ); + if( pcSlash && ( pcSlash[1] == _T('\0') )) *pcSlash = '\0'; + SendMessage( GetDlgItem( hDlg, IDC_GBROM_ABS_EDIT ), WM_SETTEXT, 0, (LPARAM)szBuffer ); - // GBSave Directory - lstrcpyn(szBuffer, g_aszDefFolders[DIRECTORY_GBSAVES], MAX_PATH); + // GBSave Directory + lstrcpyn(szBuffer, g_aszDefFolders[DIRECTORY_GBSAVES], MAX_PATH); - if( !j ) - { - CheckDlgButton( hDlg, IDC_GBSAVE_SAME, BST_CHECKED ); - FoldersDialogProc( hDlg, WM_COMMAND, (WPARAM)MAKELONG( IDC_GBSAVE_SAME, BN_CLICKED ), (LPARAM)GetDlgItem( hDlg, IDC_GBSAVE_SAME )); - SendMessage( GetDlgItem( hDlg, IDC_GBROM_REL_EDIT ), WM_GETTEXT, sizeof(szBuffer), (LPARAM)szBuffer ); - SendMessage( GetDlgItem( hDlg, IDC_GBSAVE_REL_EDIT ), WM_SETTEXT, 0, (LPARAM)szBuffer ); - } - else - { - if( szBuffer[0] != 0 && ( szBuffer[1] == _T(':') || ( szBuffer[1] == _T('\\') && szBuffer[0] == _T('\\') ))) - { - CheckDlgButton( hDlg, IDC_GBSAVE_ABS, BST_CHECKED ); + if( !j ) + { + CheckDlgButton( hDlg, IDC_GBSAVE_SAME, BST_CHECKED ); + FoldersDialogProc( hDlg, WM_COMMAND, (WPARAM)MAKELONG( IDC_GBSAVE_SAME, BN_CLICKED ), (LPARAM)GetDlgItem( hDlg, IDC_GBSAVE_SAME )); + SendMessage( GetDlgItem( hDlg, IDC_GBROM_REL_EDIT ), WM_GETTEXT, sizeof(szBuffer), (LPARAM)szBuffer ); + SendMessage( GetDlgItem( hDlg, IDC_GBSAVE_REL_EDIT ), WM_SETTEXT, 0, (LPARAM)szBuffer ); + } + else + { + if( szBuffer[0] != 0 && ( szBuffer[1] == _T(':') || ( szBuffer[1] == _T('\\') && szBuffer[0] == _T('\\') ))) + { + CheckDlgButton( hDlg, IDC_GBSAVE_ABS, BST_CHECKED ); - GetDirectory( szBuffer, DIRECTORY_GBSAVES ); - if( !_tcsncmp( szBuffer, szApplication, i )) - { - TCHAR *pcSub = &szBuffer[i]; - pcSlash = _tcsrchr( pcSub, '\\' ); - if( pcSlash && ( pcSlash[1] == '\0' )) *pcSlash = '\0'; - SendMessage( GetDlgItem( hDlg, IDC_GBSAVE_REL_EDIT ), WM_SETTEXT, 0, (LPARAM)szBuffer ); - } - else - SendMessage( GetDlgItem( hDlg, IDC_GBSAVE_REL_EDIT ), WM_SETTEXT, 0, (LPARAM)STRING_DEF_GBROMSAVE ); - } - else - { - CheckDlgButton( hDlg, IDC_GBSAVE_REL, BST_CHECKED ); + GetDirectory( szBuffer, DIRECTORY_GBSAVES ); + if( !_tcsncmp( szBuffer, szApplication, i )) + { + TCHAR *pcSub = &szBuffer[i]; + pcSlash = _tcsrchr( pcSub, '\\' ); + if( pcSlash && ( pcSlash[1] == '\0' )) *pcSlash = '\0'; + SendMessage( GetDlgItem( hDlg, IDC_GBSAVE_REL_EDIT ), WM_SETTEXT, 0, (LPARAM)szBuffer ); + } + else + SendMessage( GetDlgItem( hDlg, IDC_GBSAVE_REL_EDIT ), WM_SETTEXT, 0, (LPARAM)STRING_DEF_GBROMSAVE ); + } + else + { + CheckDlgButton( hDlg, IDC_GBSAVE_REL, BST_CHECKED ); - if( szBuffer[0] != 0 ) - SendMessage( GetDlgItem( hDlg, IDC_GBSAVE_REL_EDIT ), WM_SETTEXT, 0, (LPARAM)szBuffer ); - else - SendMessage( GetDlgItem( hDlg, IDC_GBSAVE_REL_EDIT ), WM_SETTEXT, 0, (LPARAM)STRING_DEF_GBROMSAVE ); - } - } + if( szBuffer[0] != 0 ) + SendMessage( GetDlgItem( hDlg, IDC_GBSAVE_REL_EDIT ), WM_SETTEXT, 0, (LPARAM)szBuffer ); + else + SendMessage( GetDlgItem( hDlg, IDC_GBSAVE_REL_EDIT ), WM_SETTEXT, 0, (LPARAM)STRING_DEF_GBROMSAVE ); + } + } - GetDirectory( szBuffer, DIRECTORY_GBSAVES ); - pcSlash = _tcsrchr( szBuffer, _T('\\') ); - if( pcSlash && ( pcSlash[1] == _T('\0') )) *pcSlash = '\0'; - SendMessage( GetDlgItem( hDlg, IDC_GBSAVE_ABS_EDIT ), WM_SETTEXT, 0, (LPARAM)szBuffer ); + GetDirectory( szBuffer, DIRECTORY_GBSAVES ); + pcSlash = _tcsrchr( szBuffer, _T('\\') ); + if( pcSlash && ( pcSlash[1] == _T('\0') )) *pcSlash = '\0'; + SendMessage( GetDlgItem( hDlg, IDC_GBSAVE_ABS_EDIT ), WM_SETTEXT, 0, (LPARAM)szBuffer ); - return FALSE; // don't give it focus + return FALSE; // don't give it focus - case WM_COMMAND: - switch( LOWORD(wParam) ) - { - case IDC_GBSAVE_ABS: - case IDC_GBSAVE_REL: - EnableWindow( GetDlgItem( hDlg, IDC_GBSAVE_REL_EDIT ), TRUE ); - EnableWindow( GetDlgItem( hDlg, IDC_GBSAVE_ABS_EDIT ), TRUE ); - EnableWindow( GetDlgItem( hDlg, IDC_GBSAVE_BROWSE_REL ), TRUE ); - EnableWindow( GetDlgItem( hDlg, IDC_GBSAVE_BROWSE_ABS ), TRUE ); - return TRUE; + case WM_COMMAND: + switch( LOWORD(wParam) ) + { + case IDC_GBSAVE_ABS: + case IDC_GBSAVE_REL: + EnableWindow( GetDlgItem( hDlg, IDC_GBSAVE_REL_EDIT ), TRUE ); + EnableWindow( GetDlgItem( hDlg, IDC_GBSAVE_ABS_EDIT ), TRUE ); + EnableWindow( GetDlgItem( hDlg, IDC_GBSAVE_BROWSE_REL ), TRUE ); + EnableWindow( GetDlgItem( hDlg, IDC_GBSAVE_BROWSE_ABS ), TRUE ); + return TRUE; - case IDC_GBSAVE_SAME: - EnableWindow( GetDlgItem( hDlg, IDC_GBSAVE_REL_EDIT ), FALSE ); - EnableWindow( GetDlgItem( hDlg, IDC_GBSAVE_ABS_EDIT ), FALSE ); - EnableWindow( GetDlgItem( hDlg, IDC_GBSAVE_BROWSE_REL ), FALSE ); - EnableWindow( GetDlgItem( hDlg, IDC_GBSAVE_BROWSE_ABS ), FALSE ); - return TRUE; + case IDC_GBSAVE_SAME: + EnableWindow( GetDlgItem( hDlg, IDC_GBSAVE_REL_EDIT ), FALSE ); + EnableWindow( GetDlgItem( hDlg, IDC_GBSAVE_ABS_EDIT ), FALSE ); + EnableWindow( GetDlgItem( hDlg, IDC_GBSAVE_BROWSE_REL ), FALSE ); + EnableWindow( GetDlgItem( hDlg, IDC_GBSAVE_BROWSE_ABS ), FALSE ); + return TRUE; - case IDC_MEMPAK_BROWSE_ABS: - szBuffer[0] = '\0'; - if( BrowseFolders( hDlg, NULL, szBuffer )) - SendMessage( GetDlgItem( hDlg, IDC_MEMPAK_ABS_EDIT ), WM_SETTEXT, 0, (LPARAM)szBuffer ); - return TRUE; - case IDC_GBROM_BROWSE_ABS: - szBuffer[0] = '\0'; - if( BrowseFolders( hDlg, NULL, szBuffer )) - SendMessage( GetDlgItem( hDlg, IDC_GBROM_ABS_EDIT ), WM_SETTEXT, 0, (LPARAM)szBuffer ); - return TRUE; - case IDC_GBSAVE_BROWSE_ABS: - szBuffer[0] = '\0'; - if( BrowseFolders( hDlg, NULL, szBuffer )) - SendMessage( GetDlgItem( hDlg, IDC_GBSAVE_ABS_EDIT ), WM_SETTEXT, 0, (LPARAM)szBuffer ); - return TRUE; - case IDC_MEMPAK_BROWSE_REL: - GetDirectory( szApplication, DIRECTORY_APPLICATION ); - lstrcpyn( szBuffer, szApplication, ARRAYSIZE(szBuffer) ); - if( BrowseFolders( hDlg, NULL, szBuffer )) - { - i = lstrlen( szApplication ); - lstrcpyn( szBuffer, &szBuffer[i], ARRAYSIZE(szBuffer) ); // HACK: The lstrcpyn function has an undefined behavior if source and destination buffers overlap. - SendMessage( GetDlgItem( hDlg, IDC_MEMPAK_REL_EDIT ), WM_SETTEXT, 0, (LPARAM)szBuffer ); - } - return TRUE; + case IDC_MEMPAK_BROWSE_ABS: + szBuffer[0] = '\0'; + if( BrowseFolders( hDlg, NULL, szBuffer )) + SendMessage( GetDlgItem( hDlg, IDC_MEMPAK_ABS_EDIT ), WM_SETTEXT, 0, (LPARAM)szBuffer ); + return TRUE; + case IDC_GBROM_BROWSE_ABS: + szBuffer[0] = '\0'; + if( BrowseFolders( hDlg, NULL, szBuffer )) + SendMessage( GetDlgItem( hDlg, IDC_GBROM_ABS_EDIT ), WM_SETTEXT, 0, (LPARAM)szBuffer ); + return TRUE; + case IDC_GBSAVE_BROWSE_ABS: + szBuffer[0] = '\0'; + if( BrowseFolders( hDlg, NULL, szBuffer )) + SendMessage( GetDlgItem( hDlg, IDC_GBSAVE_ABS_EDIT ), WM_SETTEXT, 0, (LPARAM)szBuffer ); + return TRUE; + case IDC_MEMPAK_BROWSE_REL: + GetDirectory( szApplication, DIRECTORY_APPLICATION ); + lstrcpyn( szBuffer, szApplication, ARRAYSIZE(szBuffer) ); + if( BrowseFolders( hDlg, NULL, szBuffer )) + { + i = lstrlen( szApplication ); + lstrcpyn( szBuffer, &szBuffer[i], ARRAYSIZE(szBuffer) ); // HACK: The lstrcpyn function has an undefined behavior if source and destination buffers overlap. + SendMessage( GetDlgItem( hDlg, IDC_MEMPAK_REL_EDIT ), WM_SETTEXT, 0, (LPARAM)szBuffer ); + } + return TRUE; - case IDC_GBROM_BROWSE_REL: - GetDirectory( szApplication, DIRECTORY_APPLICATION ); - lstrcpyn( szBuffer, szApplication, ARRAYSIZE(szBuffer) ); - if( BrowseFolders( hDlg, NULL, szBuffer )) - { - i = lstrlen( szApplication ); - lstrcpyn( szBuffer, &szBuffer[i], ARRAYSIZE(szBuffer) ); // HACK: The lstrcpyn function has an undefined behavior if source and destination buffers overlap. - SendMessage( GetDlgItem( hDlg, IDC_GBROM_REL_EDIT ), WM_SETTEXT, 0, (LPARAM)szBuffer ); - } - return TRUE; + case IDC_GBROM_BROWSE_REL: + GetDirectory( szApplication, DIRECTORY_APPLICATION ); + lstrcpyn( szBuffer, szApplication, ARRAYSIZE(szBuffer) ); + if( BrowseFolders( hDlg, NULL, szBuffer )) + { + i = lstrlen( szApplication ); + lstrcpyn( szBuffer, &szBuffer[i], ARRAYSIZE(szBuffer) ); // HACK: The lstrcpyn function has an undefined behavior if source and destination buffers overlap. + SendMessage( GetDlgItem( hDlg, IDC_GBROM_REL_EDIT ), WM_SETTEXT, 0, (LPARAM)szBuffer ); + } + return TRUE; - case IDC_GBSAVE_BROWSE_REL: - GetDirectory( szApplication, DIRECTORY_APPLICATION ); - lstrcpyn( szBuffer, szApplication, ARRAYSIZE(szBuffer) ); - if( BrowseFolders( hDlg, NULL, szBuffer )) - { - i = lstrlen( szApplication ); - lstrcpyn( szBuffer, &szBuffer[i], ARRAYSIZE(szBuffer) ); // HACK: The lstrcpyn function has an undefined behavior if source and destination buffers overlap. - SendMessage( GetDlgItem( hDlg, IDC_GBSAVE_REL_EDIT ), WM_SETTEXT, 0, (LPARAM)szBuffer ); - } - return TRUE; + case IDC_GBSAVE_BROWSE_REL: + GetDirectory( szApplication, DIRECTORY_APPLICATION ); + lstrcpyn( szBuffer, szApplication, ARRAYSIZE(szBuffer) ); + if( BrowseFolders( hDlg, NULL, szBuffer )) + { + i = lstrlen( szApplication ); + lstrcpyn( szBuffer, &szBuffer[i], ARRAYSIZE(szBuffer) ); // HACK: The lstrcpyn function has an undefined behavior if source and destination buffers overlap. + SendMessage( GetDlgItem( hDlg, IDC_GBSAVE_REL_EDIT ), WM_SETTEXT, 0, (LPARAM)szBuffer ); + } + return TRUE; - case IDOK: - if( IsDlgButtonChecked( hDlg, IDC_MEMPAK_ABS ) == BST_CHECKED ) - { - SendMessage( GetDlgItem( hDlg, IDC_MEMPAK_ABS_EDIT ), WM_GETTEXT, ARRAYSIZE(szApplication), (LPARAM)szApplication ); - GetFullPathName( szApplication, ARRAYSIZE(szBuffer), szBuffer, &pcSlash ); - } - else - SendMessage( GetDlgItem( hDlg, IDC_MEMPAK_REL_EDIT ), WM_GETTEXT, ARRAYSIZE(szBuffer), (LPARAM)szBuffer ); - pcSlash = _tcsrchr( szBuffer, '\\' ); - if( pcSlash && ( pcSlash[1] == '\0' )) - *pcSlash = '\0'; + case IDOK: + if( IsDlgButtonChecked( hDlg, IDC_MEMPAK_ABS ) == BST_CHECKED ) + { + SendMessage( GetDlgItem( hDlg, IDC_MEMPAK_ABS_EDIT ), WM_GETTEXT, ARRAYSIZE(szApplication), (LPARAM)szApplication ); + GetFullPathName( szApplication, ARRAYSIZE(szBuffer), szBuffer, &pcSlash ); + } + else + SendMessage( GetDlgItem( hDlg, IDC_MEMPAK_REL_EDIT ), WM_GETTEXT, ARRAYSIZE(szBuffer), (LPARAM)szBuffer ); + pcSlash = _tcsrchr( szBuffer, '\\' ); + if( pcSlash && ( pcSlash[1] == '\0' )) + *pcSlash = '\0'; - if( !lstrcmp( szBuffer, STRING_DEF_MEMPAKFILE )) - g_aszDefFolders[DIRECTORY_MEMPAK][0] = 0; - else - lstrcpyn(g_aszDefFolders[DIRECTORY_MEMPAK], szBuffer, MAX_PATH); + if( !lstrcmp( szBuffer, STRING_DEF_MEMPAKFILE )) + g_aszDefFolders[DIRECTORY_MEMPAK][0] = 0; + else + lstrcpyn(g_aszDefFolders[DIRECTORY_MEMPAK], szBuffer, MAX_PATH); - if( IsDlgButtonChecked( hDlg, IDC_GBROM_ABS ) == BST_CHECKED ) - { - SendMessage( GetDlgItem( hDlg, IDC_GBROM_ABS_EDIT ), WM_GETTEXT, ARRAYSIZE(szApplication), (LPARAM)szApplication ); - GetFullPathName( szApplication, ARRAYSIZE(szBuffer), szBuffer, &pcSlash ); - } - else - SendMessage( GetDlgItem( hDlg, IDC_GBROM_REL_EDIT ), WM_GETTEXT, ARRAYSIZE(szBuffer), (LPARAM)szBuffer ); - pcSlash = _tcsrchr( szBuffer, '\\' ); - if( pcSlash && ( pcSlash[1] == '\0' )) *pcSlash = '\0'; + if( IsDlgButtonChecked( hDlg, IDC_GBROM_ABS ) == BST_CHECKED ) + { + SendMessage( GetDlgItem( hDlg, IDC_GBROM_ABS_EDIT ), WM_GETTEXT, ARRAYSIZE(szApplication), (LPARAM)szApplication ); + GetFullPathName( szApplication, ARRAYSIZE(szBuffer), szBuffer, &pcSlash ); + } + else + SendMessage( GetDlgItem( hDlg, IDC_GBROM_REL_EDIT ), WM_GETTEXT, ARRAYSIZE(szBuffer), (LPARAM)szBuffer ); + pcSlash = _tcsrchr( szBuffer, '\\' ); + if( pcSlash && ( pcSlash[1] == '\0' )) *pcSlash = '\0'; - if( !lstrcmp( szBuffer, STRING_DEF_GBROMFILE )) - g_aszDefFolders[DIRECTORY_GBROMS][0] = 0; - else - lstrcpyn(g_aszDefFolders[DIRECTORY_GBROMS], szBuffer, MAX_PATH); + if( !lstrcmp( szBuffer, STRING_DEF_GBROMFILE )) + g_aszDefFolders[DIRECTORY_GBROMS][0] = 0; + else + lstrcpyn(g_aszDefFolders[DIRECTORY_GBROMS], szBuffer, MAX_PATH); - if( !IsDlgButtonChecked( hDlg, IDC_GBSAVE_SAME ) == BST_CHECKED ) - { - if( IsDlgButtonChecked( hDlg, IDC_GBSAVE_ABS ) == BST_CHECKED ) - { - SendMessage( GetDlgItem( hDlg, IDC_GBSAVE_ABS_EDIT ), WM_GETTEXT, ARRAYSIZE(szApplication), (LPARAM)szApplication ); - GetFullPathName( szApplication, ARRAYSIZE(szBuffer), szBuffer, &pcSlash ); - } - else - SendMessage( GetDlgItem( hDlg, IDC_GBSAVE_REL_EDIT ), WM_GETTEXT, ARRAYSIZE(szBuffer), (LPARAM)szBuffer ); - } + if( !IsDlgButtonChecked( hDlg, IDC_GBSAVE_SAME ) == BST_CHECKED ) + { + if( IsDlgButtonChecked( hDlg, IDC_GBSAVE_ABS ) == BST_CHECKED ) + { + SendMessage( GetDlgItem( hDlg, IDC_GBSAVE_ABS_EDIT ), WM_GETTEXT, ARRAYSIZE(szApplication), (LPARAM)szApplication ); + GetFullPathName( szApplication, ARRAYSIZE(szBuffer), szBuffer, &pcSlash ); + } + else + SendMessage( GetDlgItem( hDlg, IDC_GBSAVE_REL_EDIT ), WM_GETTEXT, ARRAYSIZE(szBuffer), (LPARAM)szBuffer ); + } - pcSlash = _tcsrchr( szBuffer, _T('\\') ); - if( pcSlash && ( pcSlash[1] == '\0' )) *pcSlash = '\0'; + pcSlash = _tcsrchr( szBuffer, _T('\\') ); + if( pcSlash && ( pcSlash[1] == '\0' )) *pcSlash = '\0'; - if( !lstrcmp( szBuffer, STRING_DEF_GBROMSAVE )) - g_aszDefFolders[DIRECTORY_GBSAVES][0] = 0; - else - lstrcpyn(g_aszDefFolders[DIRECTORY_GBSAVES], szBuffer, MAX_PATH); + if( !lstrcmp( szBuffer, STRING_DEF_GBROMSAVE )) + g_aszDefFolders[DIRECTORY_GBSAVES][0] = 0; + else + lstrcpyn(g_aszDefFolders[DIRECTORY_GBSAVES], szBuffer, MAX_PATH); - EndDialog( hDlg, TRUE ); - return TRUE; + EndDialog( hDlg, TRUE ); + return TRUE; - case IDCANCEL: - EndDialog( hDlg, FALSE ); - return TRUE; + case IDCANCEL: + EndDialog( hDlg, FALSE ); + return TRUE; - default: - return FALSE; // unhandled WM_COMMAND - } - default: - return FALSE; //false means the msg didn't got processed - } + default: + return FALSE; // unhandled WM_COMMAND + } + default: + return FALSE; //false means the msg didn't got processed + } } /////////////////////////////////////////////////////////////////////////////// @@ -3321,7 +3321,7 @@ BOOL CALLBACK FoldersDialogProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPa // called by EnumObjects in MainDlgProcess to enumerate the keys on the keyboard...? /* BOOL CALLBACK EnumGetKeyDesc( LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef ) { - // REMOVED // + // REMOVED // } // I am putting this function out of its misery before it causes more grief. --rabid */ @@ -3331,415 +3331,415 @@ BOOL CALLBACK FoldersDialogProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPa // This function is confusing, but not much I can do to fix it now. I'm sorry. --rabid bool GetButtonID( LPDWORD ButtonID, const BYTE bIndex, const BYTE bButtonSet ) { - // TODO: make these const, read from a resource or a define, or something... I don't know - LPDWORD ButtonTable = NULL; - int nEntries = 0; + // TODO: make these const, read from a resource or a define, or something... I don't know + LPDWORD ButtonTable = NULL; + int nEntries = 0; - // ID of PushButton ID of TextWindow place in Button-structure - const DWORD Controls[][3] = { { IDC_DRIGHT , IDT_DRIGHT , PF_DPADR }, // Controls - { IDC_DLEFT , IDT_DLEFT , PF_DPADL }, - { IDC_DDOWN , IDT_DDOWN , PF_DPADD }, - { IDC_DUP , IDT_DUP , PF_DPADU }, - { IDC_SBUTTON , IDT_SBUTTON , PF_START }, - { IDC_ZTRIGGER , IDT_ZTRIGGER , PF_TRIGGERZ }, - { IDC_BBUTTON , IDT_BBUTTON , PF_BBUTTON }, - { IDC_ABUTTON , IDT_ABUTTON , PF_ABUTTON }, - { IDC_CRIGHT , IDT_CRIGHT , PF_CBUTTONR }, - { IDC_CLEFT , IDT_CLEFT , PF_CBUTTONL }, - { IDC_CDOWN , IDT_CDOWN , PF_CBUTTOND }, - { IDC_CUP , IDT_CUP , PF_CBUTTONU }, - { IDC_RIGHTTRIGGER , IDT_RIGHTTRIGGER , PF_TRIGGERR }, - { IDC_LEFTTRIGGER , IDT_LEFTTRIGGER , PF_TRIGGERL }, - { IDC_ARIGHT , IDT_ARIGHT , PF_APADR }, - { IDC_ALEFT , IDT_ALEFT , PF_APADL }, - { IDC_ADOWN , IDT_ADOWN , PF_APADD }, - { IDC_AUP , IDT_AUP , PF_APADU } }; + // ID of PushButton ID of TextWindow place in Button-structure + const DWORD Controls[][3] = { { IDC_DRIGHT , IDT_DRIGHT , PF_DPADR }, // Controls + { IDC_DLEFT , IDT_DLEFT , PF_DPADL }, + { IDC_DDOWN , IDT_DDOWN , PF_DPADD }, + { IDC_DUP , IDT_DUP , PF_DPADU }, + { IDC_SBUTTON , IDT_SBUTTON , PF_START }, + { IDC_ZTRIGGER , IDT_ZTRIGGER , PF_TRIGGERZ }, + { IDC_BBUTTON , IDT_BBUTTON , PF_BBUTTON }, + { IDC_ABUTTON , IDT_ABUTTON , PF_ABUTTON }, + { IDC_CRIGHT , IDT_CRIGHT , PF_CBUTTONR }, + { IDC_CLEFT , IDT_CLEFT , PF_CBUTTONL }, + { IDC_CDOWN , IDT_CDOWN , PF_CBUTTOND }, + { IDC_CUP , IDT_CUP , PF_CBUTTONU }, + { IDC_RIGHTTRIGGER , IDT_RIGHTTRIGGER , PF_TRIGGERR }, + { IDC_LEFTTRIGGER , IDT_LEFTTRIGGER , PF_TRIGGERL }, + { IDC_ARIGHT , IDT_ARIGHT , PF_APADR }, + { IDC_ALEFT , IDT_ALEFT , PF_APADL }, + { IDC_ADOWN , IDT_ADOWN , PF_APADD }, + { IDC_AUP , IDT_AUP , PF_APADU } }; - const DWORD Shortcuts[][3]= { - { IDC_SETNOPAK_P1 , IDC_SETNOPAK_P1 , SC_NOPAK }, - { IDC_SETMEMPAK_P1 , IDC_SETMEMPAK_P1 , SC_MEMPAK }, - { IDC_SETRUMBLEPAK_P1 , IDC_SETRUMBLEPAK_P1 , SC_RUMBPAK }, - { IDC_SETTRANSFERPAK_P1 , IDC_SETTRANSFERPAK_P1 , SC_TRANSPAK }, - { IDC_SETADAPTOIDPAK_P1 , IDC_SETADAPTOIDPAK_P1 , SC_ADAPTPAK }, - { IDC_SWMEMRUMBLE_P1 , IDC_SWMEMRUMBLE_P1 , SC_SWMEMRUMB }, - { IDC_SWMEMADAPTOID_P1 , IDC_SWMEMADAPTOID_P1 , SC_SWMEMADAPT }, + const DWORD Shortcuts[][3]= { + { IDC_SETNOPAK_P1 , IDC_SETNOPAK_P1 , SC_NOPAK }, + { IDC_SETMEMPAK_P1 , IDC_SETMEMPAK_P1 , SC_MEMPAK }, + { IDC_SETRUMBLEPAK_P1 , IDC_SETRUMBLEPAK_P1 , SC_RUMBPAK }, + { IDC_SETTRANSFERPAK_P1 , IDC_SETTRANSFERPAK_P1 , SC_TRANSPAK }, + { IDC_SETADAPTOIDPAK_P1 , IDC_SETADAPTOIDPAK_P1 , SC_ADAPTPAK }, + { IDC_SWMEMRUMBLE_P1 , IDC_SWMEMRUMBLE_P1 , SC_SWMEMRUMB }, + { IDC_SWMEMADAPTOID_P1 , IDC_SWMEMADAPTOID_P1 , SC_SWMEMADAPT }, - { IDC_SETNOPAK_P2 , IDC_SETNOPAK_P2 , SC_NOPAK + SC_TOTAL }, - { IDC_SETMEMPAK_P2 , IDC_SETMEMPAK_P2 , SC_MEMPAK + SC_TOTAL }, - { IDC_SETRUMBLEPAK_P2 , IDC_SETRUMBLEPAK_P2 , SC_RUMBPAK + SC_TOTAL }, - { IDC_SETTRANSFERPAK_P2 , IDC_SETTRANSFERPAK_P2 , SC_TRANSPAK + SC_TOTAL }, - { IDC_SETADAPTOIDPAK_P2 , IDC_SETADAPTOIDPAK_P2 , SC_ADAPTPAK + SC_TOTAL }, - { IDC_SWMEMRUMBLE_P2 , IDC_SWMEMRUMBLE_P2 , SC_SWMEMRUMB + SC_TOTAL }, - { IDC_SWMEMADAPTOID_P2 , IDC_SWMEMADAPTOID_P2 , SC_SWMEMADAPT + SC_TOTAL }, + { IDC_SETNOPAK_P2 , IDC_SETNOPAK_P2 , SC_NOPAK + SC_TOTAL }, + { IDC_SETMEMPAK_P2 , IDC_SETMEMPAK_P2 , SC_MEMPAK + SC_TOTAL }, + { IDC_SETRUMBLEPAK_P2 , IDC_SETRUMBLEPAK_P2 , SC_RUMBPAK + SC_TOTAL }, + { IDC_SETTRANSFERPAK_P2 , IDC_SETTRANSFERPAK_P2 , SC_TRANSPAK + SC_TOTAL }, + { IDC_SETADAPTOIDPAK_P2 , IDC_SETADAPTOIDPAK_P2 , SC_ADAPTPAK + SC_TOTAL }, + { IDC_SWMEMRUMBLE_P2 , IDC_SWMEMRUMBLE_P2 , SC_SWMEMRUMB + SC_TOTAL }, + { IDC_SWMEMADAPTOID_P2 , IDC_SWMEMADAPTOID_P2 , SC_SWMEMADAPT + SC_TOTAL }, - { IDC_SETNOPAK_P3 , IDC_SETNOPAK_P3 , SC_NOPAK + SC_TOTAL * 2 }, - { IDC_SETMEMPAK_P3 , IDC_SETMEMPAK_P3 , SC_MEMPAK + SC_TOTAL * 2 }, - { IDC_SETRUMBLEPAK_P3 , IDC_SETRUMBLEPAK_P3 , SC_RUMBPAK + SC_TOTAL * 2 }, - { IDC_SETTRANSFERPAK_P3 , IDC_SETTRANSFERPAK_P3 , SC_TRANSPAK + SC_TOTAL * 2 }, - { IDC_SETADAPTOIDPAK_P3 , IDC_SETADAPTOIDPAK_P3 , SC_ADAPTPAK + SC_TOTAL * 2 }, - { IDC_SWMEMRUMBLE_P3 , IDC_SWMEMRUMBLE_P3 , SC_SWMEMRUMB + SC_TOTAL * 2 }, - { IDC_SWMEMADAPTOID_P3 , IDC_SWMEMADAPTOID_P3 , SC_SWMEMADAPT + SC_TOTAL * 2 }, + { IDC_SETNOPAK_P3 , IDC_SETNOPAK_P3 , SC_NOPAK + SC_TOTAL * 2 }, + { IDC_SETMEMPAK_P3 , IDC_SETMEMPAK_P3 , SC_MEMPAK + SC_TOTAL * 2 }, + { IDC_SETRUMBLEPAK_P3 , IDC_SETRUMBLEPAK_P3 , SC_RUMBPAK + SC_TOTAL * 2 }, + { IDC_SETTRANSFERPAK_P3 , IDC_SETTRANSFERPAK_P3 , SC_TRANSPAK + SC_TOTAL * 2 }, + { IDC_SETADAPTOIDPAK_P3 , IDC_SETADAPTOIDPAK_P3 , SC_ADAPTPAK + SC_TOTAL * 2 }, + { IDC_SWMEMRUMBLE_P3 , IDC_SWMEMRUMBLE_P3 , SC_SWMEMRUMB + SC_TOTAL * 2 }, + { IDC_SWMEMADAPTOID_P3 , IDC_SWMEMADAPTOID_P3 , SC_SWMEMADAPT + SC_TOTAL * 2 }, - { IDC_SETNOPAK_P4 , IDC_SETNOPAK_P4 , SC_NOPAK + SC_TOTAL * 3 }, - { IDC_SETMEMPAK_P4 , IDC_SETMEMPAK_P4 , SC_MEMPAK + SC_TOTAL * 3 }, - { IDC_SETRUMBLEPAK_P4 , IDC_SETRUMBLEPAK_P4 , SC_RUMBPAK + SC_TOTAL * 3 }, - { IDC_SETTRANSFERPAK_P4 , IDC_SETTRANSFERPAK_P4 , SC_TRANSPAK + SC_TOTAL * 3 }, - { IDC_SETADAPTOIDPAK_P4 , IDC_SETADAPTOIDPAK_P4 , SC_ADAPTPAK + SC_TOTAL * 3 }, - { IDC_SWMEMRUMBLE_P4 , IDC_SWMEMRUMBLE_P4 , SC_SWMEMRUMB + SC_TOTAL * 3 }, - { IDC_SWMEMADAPTOID_P4 , IDC_SWMEMADAPTOID_P4 , SC_SWMEMADAPT + SC_TOTAL * 3 }, + { IDC_SETNOPAK_P4 , IDC_SETNOPAK_P4 , SC_NOPAK + SC_TOTAL * 3 }, + { IDC_SETMEMPAK_P4 , IDC_SETMEMPAK_P4 , SC_MEMPAK + SC_TOTAL * 3 }, + { IDC_SETRUMBLEPAK_P4 , IDC_SETRUMBLEPAK_P4 , SC_RUMBPAK + SC_TOTAL * 3 }, + { IDC_SETTRANSFERPAK_P4 , IDC_SETTRANSFERPAK_P4 , SC_TRANSPAK + SC_TOTAL * 3 }, + { IDC_SETADAPTOIDPAK_P4 , IDC_SETADAPTOIDPAK_P4 , SC_ADAPTPAK + SC_TOTAL * 3 }, + { IDC_SWMEMRUMBLE_P4 , IDC_SWMEMRUMBLE_P4 , SC_SWMEMRUMB + SC_TOTAL * 3 }, + { IDC_SWMEMADAPTOID_P4 , IDC_SWMEMADAPTOID_P4 , SC_SWMEMADAPT + SC_TOTAL * 3 }, - { IDC_LOCKMOUSE , IDC_LOCKMOUSE , (DWORD)(-1) } - }; + { IDC_LOCKMOUSE , IDC_LOCKMOUSE , (DWORD)(-1) } + }; - if( bButtonSet == BSET_CONTROLS ) - { - ButtonTable = (LPDWORD)Controls; // HACK: what an ugly solution, using a cast like that - nEntries = ARRAYSIZE( Controls ); - } + if( bButtonSet == BSET_CONTROLS ) + { + ButtonTable = (LPDWORD)Controls; // HACK: what an ugly solution, using a cast like that + nEntries = ARRAYSIZE( Controls ); + } - if( bButtonSet == BSET_SHORTCUTS ) - { - ButtonTable = (LPDWORD)Shortcuts; - nEntries = ARRAYSIZE( Shortcuts ); - } + if( bButtonSet == BSET_SHORTCUTS ) + { + ButtonTable = (LPDWORD)Shortcuts; + nEntries = ARRAYSIZE( Shortcuts ); + } - bool bReturn = false; + bool bReturn = false; - // TODO: fix this! just use 2 dimensional arrays for crying out loud! - if( ButtonTable != NULL ) - { - nEntries *= 3; - for( int i = 0; i < nEntries; i+=3 ) - { - if( ButtonTable[i+bIndex] == ButtonID[bIndex] ) - { - ButtonID[0] = ButtonTable[i+0]; - ButtonID[1] = ButtonTable[i+1]; - ButtonID[2] = ButtonTable[i+2]; + // TODO: fix this! just use 2 dimensional arrays for crying out loud! + if( ButtonTable != NULL ) + { + nEntries *= 3; + for( int i = 0; i < nEntries; i+=3 ) + { + if( ButtonTable[i+bIndex] == ButtonID[bIndex] ) + { + ButtonID[0] = ButtonTable[i+0]; + ButtonID[1] = ButtonTable[i+1]; + ButtonID[2] = ButtonTable[i+2]; - bReturn = true; - break; - } - } - } + bReturn = true; + break; + } + } + } - return bReturn; + return bReturn; } // a text-munging routine to spit out what PC control was assigned to a button bool GetButtonText( const BUTTON& btnButton, LPTSTR Buffer ) { - const UINT iDevice[] ={ IDS_BUTTON_UNASSIGNED, - IDS_C_GAMEPAD, - IDS_C_KEYBOARD, - IDS_C_MOUSE }; - const UINT iGamepad[] ={ IDS_C_XAXIS, - IDS_C_YAXIS, - IDS_C_ZAXIS, - IDS_C_XROT, - IDS_C_YROT, - IDS_C_ZROT, - IDS_C_SLIDER, - IDS_C_SLIDER, - IDS_C_POV, - IDS_C_POV, - IDS_C_POV, - IDS_C_POV, - IDS_C_BUTTON }; - const UINT iMouse[] = { IDS_C_XAXIS, - IDS_C_YAXIS, - IDS_C_WHEEL, - IDS_C_BUTTON }; - const LPTSTR AxeID[] = { TEXT( " +" ), - TEXT( " -" ), - TEXT( " /\\" ), - TEXT( " >" ), - TEXT( " \\/" ), - TEXT( " <" ) }; - TCHAR a[16], b[16], buff[16]; // gotta allocate the space, stack is easier than P_malloc - TCHAR Btn[6]; - LPTSTR Text[] = {a, b, NULL }; - bool bReturn = true; - DIDEVICEOBJECTINSTANCE didoi; - didoi.dwSize = sizeof(DIDEVICEOBJECTINSTANCE); + const UINT iDevice[] ={ IDS_BUTTON_UNASSIGNED, + IDS_C_GAMEPAD, + IDS_C_KEYBOARD, + IDS_C_MOUSE }; + const UINT iGamepad[] ={ IDS_C_XAXIS, + IDS_C_YAXIS, + IDS_C_ZAXIS, + IDS_C_XROT, + IDS_C_YROT, + IDS_C_ZROT, + IDS_C_SLIDER, + IDS_C_SLIDER, + IDS_C_POV, + IDS_C_POV, + IDS_C_POV, + IDS_C_POV, + IDS_C_BUTTON }; + const UINT iMouse[] = { IDS_C_XAXIS, + IDS_C_YAXIS, + IDS_C_WHEEL, + IDS_C_BUTTON }; + const LPTSTR AxeID[] = { TEXT( " +" ), + TEXT( " -" ), + TEXT( " /\\" ), + TEXT( " >" ), + TEXT( " \\/" ), + TEXT( " <" ) }; + TCHAR a[16], b[16], buff[16]; // gotta allocate the space, stack is easier than P_malloc + TCHAR Btn[6]; + LPTSTR Text[] = {a, b, NULL }; + bool bReturn = true; + DIDEVICEOBJECTINSTANCE didoi; + didoi.dwSize = sizeof(DIDEVICEOBJECTINSTANCE); - switch ( btnButton.bBtnType ) - { - case DT_JOYBUTTON: - LoadString( g_hResourceDLL, iDevice[1], Text[0], 16 ); - LoadString( g_hResourceDLL, iGamepad[12], Text[1], 16 ); - Text[2] = Btn; - wsprintf( Btn, TEXT( "%02u" ), btnButton.bOffset ); - break; - case DT_JOYAXE: - LoadString( g_hResourceDLL, iDevice[1], Text[0], 16 ); - LoadString( g_hResourceDLL, iGamepad[btnButton.bOffset], Text[1], 16 ); - Text[2] = AxeID[btnButton.bAxisID]; - break; - case DT_JOYSLIDER: - LoadString( g_hResourceDLL, iDevice[1], Text[0], 16 ); - LoadString( g_hResourceDLL, iGamepad[btnButton.bOffset], buff, 16 ); - wsprintf(Text[1], buff, btnButton.bOffset - 5 ); - Text[2] = AxeID[btnButton.bAxisID]; - case DT_JOYPOV: - LoadString( g_hResourceDLL, iDevice[1], Text[0], 16 ); - LoadString( g_hResourceDLL, iGamepad[btnButton.bOffset], buff, 16 ); - wsprintf(Text[1], buff, btnButton.bOffset - 7 ); - Text[2] = AxeID[2 + btnButton.bAxisID]; - break; - case DT_KEYBUTTON: - LoadString( g_hResourceDLL, iDevice[2], Text[0], 16 ); - //TODO: this is great! can we do this for all of them? - if (btnButton.parentDevice->didHandle->GetObjectInfo(&didoi, btnButton.bOffset, DIPH_BYOFFSET) == DI_OK) - Text[1] = didoi.tszName; - else - LoadString( g_hResourceDLL, IDS_C_UNKNOWN, Text[1], 16 ); - Text[2] = TEXT( "" ); - break; - case DT_MOUSEBUTTON: - LoadString( g_hResourceDLL, iDevice[3], Text[0], 16 ); - LoadString( g_hResourceDLL, iMouse[3], Text[1], 16 ); - Text[2] = Btn; - wsprintf( Btn, TEXT( "%02u" ), btnButton.bOffset ); - break; - case DT_MOUSEAXE: - LoadString( g_hResourceDLL, iDevice[3], Text[0], 16 ); - LoadString( g_hResourceDLL, iMouse[btnButton.bOffset], Text[1], 16 ); - Text[2] = AxeID[btnButton.bAxisID]; - break; - case DT_UNASSIGNED: - default: - LoadString( g_hResourceDLL, iDevice[0], Text[0], 16 ); - Text[1] = Text[2] = TEXT( "" ); - bReturn = false; - } + switch ( btnButton.bBtnType ) + { + case DT_JOYBUTTON: + LoadString( g_hResourceDLL, iDevice[1], Text[0], 16 ); + LoadString( g_hResourceDLL, iGamepad[12], Text[1], 16 ); + Text[2] = Btn; + wsprintf( Btn, TEXT( "%02u" ), btnButton.bOffset ); + break; + case DT_JOYAXE: + LoadString( g_hResourceDLL, iDevice[1], Text[0], 16 ); + LoadString( g_hResourceDLL, iGamepad[btnButton.bOffset], Text[1], 16 ); + Text[2] = AxeID[btnButton.bAxisID]; + break; + case DT_JOYSLIDER: + LoadString( g_hResourceDLL, iDevice[1], Text[0], 16 ); + LoadString( g_hResourceDLL, iGamepad[btnButton.bOffset], buff, 16 ); + wsprintf(Text[1], buff, btnButton.bOffset - 5 ); + Text[2] = AxeID[btnButton.bAxisID]; + case DT_JOYPOV: + LoadString( g_hResourceDLL, iDevice[1], Text[0], 16 ); + LoadString( g_hResourceDLL, iGamepad[btnButton.bOffset], buff, 16 ); + wsprintf(Text[1], buff, btnButton.bOffset - 7 ); + Text[2] = AxeID[2 + btnButton.bAxisID]; + break; + case DT_KEYBUTTON: + LoadString( g_hResourceDLL, iDevice[2], Text[0], 16 ); + //TODO: this is great! can we do this for all of them? + if (btnButton.parentDevice->didHandle->GetObjectInfo(&didoi, btnButton.bOffset, DIPH_BYOFFSET) == DI_OK) + Text[1] = didoi.tszName; + else + LoadString( g_hResourceDLL, IDS_C_UNKNOWN, Text[1], 16 ); + Text[2] = TEXT( "" ); + break; + case DT_MOUSEBUTTON: + LoadString( g_hResourceDLL, iDevice[3], Text[0], 16 ); + LoadString( g_hResourceDLL, iMouse[3], Text[1], 16 ); + Text[2] = Btn; + wsprintf( Btn, TEXT( "%02u" ), btnButton.bOffset ); + break; + case DT_MOUSEAXE: + LoadString( g_hResourceDLL, iDevice[3], Text[0], 16 ); + LoadString( g_hResourceDLL, iMouse[btnButton.bOffset], Text[1], 16 ); + Text[2] = AxeID[btnButton.bAxisID]; + break; + case DT_UNASSIGNED: + default: + LoadString( g_hResourceDLL, iDevice[0], Text[0], 16 ); + Text[1] = Text[2] = TEXT( "" ); + bReturn = false; + } - wsprintf( Buffer, TEXT( "%s%s%s" ), Text[0], Text[1], Text[2] ); - return ( bReturn ); + wsprintf( Buffer, TEXT( "%s%s%s" ), Text[0], Text[1], Text[2] ); + return ( bReturn ); } // called when scanning devices to assign N64 buttons DWORD ScanKeyboard( LPDEVICE lpDevice, LPDWORD lpdwCounter, LPBUTTON pButton ) { - HRESULT hr; - BYTE cKeys[256]; + HRESULT hr; + BYTE cKeys[256]; - hr = lpDevice->didHandle->GetDeviceState( sizeof( cKeys ), (LPVOID)&cKeys ); - if ( FAILED(hr) ) - { - lpDevice->didHandle->Acquire(); - return FALSE; - } + hr = lpDevice->didHandle->GetDeviceState( sizeof( cKeys ), (LPVOID)&cKeys ); + if ( FAILED(hr) ) + { + lpDevice->didHandle->Acquire(); + return FALSE; + } - int iGotKey = FALSE; - int i = 0; + int iGotKey = FALSE; + int i = 0; - for( i = 0; i < ARRAYSIZE( cKeys ); ++i ) - { - if (( cKeys[i] & 0x80 ) ) - { - if( i == DIK_ESCAPE ) - iGotKey = SC_SCANESCAPE; - else - { - iGotKey = SC_SCANSUCCEED; - pButton->bBtnType = (BYTE)DT_KEYBUTTON; - pButton->bAxisID = (BYTE)0; - pButton->bOffset = (BYTE)i; - pButton->parentDevice = lpDevice; - } - } - } - return iGotKey; + for( i = 0; i < ARRAYSIZE( cKeys ); ++i ) + { + if (( cKeys[i] & 0x80 ) ) + { + if( i == DIK_ESCAPE ) + iGotKey = SC_SCANESCAPE; + else + { + iGotKey = SC_SCANSUCCEED; + pButton->bBtnType = (BYTE)DT_KEYBUTTON; + pButton->bAxisID = (BYTE)0; + pButton->bOffset = (BYTE)i; + pButton->parentDevice = lpDevice; + } + } + } + return iGotKey; } // called when scanning devices to assign N64 buttons DWORD ScanMouse( LPDEVICE lpDevice, LPDWORD lpdwCounter, LPBUTTON pButton ) { - static BYTE rgbInitButtons[8]; - static bool bFirstScan = true; - DIMOUSESTATE2 dm_Current; - HRESULT hr; + static BYTE rgbInitButtons[8]; + static bool bFirstScan = true; + DIMOUSESTATE2 dm_Current; + HRESULT hr; - if ( *lpdwCounter == 0 ) - bFirstScan = true; + if ( *lpdwCounter == 0 ) + bFirstScan = true; - hr = lpDevice->didHandle->GetDeviceState( sizeof(DIMOUSESTATE2), &dm_Current ); - if ( FAILED(hr) ) - { - lpDevice->didHandle->Acquire(); - return FALSE; - } + hr = lpDevice->didHandle->GetDeviceState( sizeof(DIMOUSESTATE2), &dm_Current ); + if ( FAILED(hr) ) + { + lpDevice->didHandle->Acquire(); + return FALSE; + } - if ( bFirstScan ) - { - CopyMemory( rgbInitButtons, dm_Current.rgbButtons, sizeof(rgbInitButtons)); - bFirstScan = false; - lpDevice->didHandle->GetDeviceState( sizeof(DIMOUSESTATE2), &dm_Current ); - } + if ( bFirstScan ) + { + CopyMemory( rgbInitButtons, dm_Current.rgbButtons, sizeof(rgbInitButtons)); + bFirstScan = false; + lpDevice->didHandle->GetDeviceState( sizeof(DIMOUSESTATE2), &dm_Current ); + } - int iGotKey = FALSE; - int i = 0; - BYTE bAxeDirection = 0; - long Mouse[] ={ FIELD_OFFSET( DIMOUSESTATE2, lX ) / sizeof(long), - FIELD_OFFSET( DIMOUSESTATE2, lY ) / sizeof(long), - FIELD_OFFSET( DIMOUSESTATE2, lZ ) / sizeof(long) }; + int iGotKey = FALSE; + int i = 0; + BYTE bAxeDirection = 0; + long Mouse[] ={ FIELD_OFFSET( DIMOUSESTATE2, lX ) / sizeof(long), + FIELD_OFFSET( DIMOUSESTATE2, lY ) / sizeof(long), + FIELD_OFFSET( DIMOUSESTATE2, lZ ) / sizeof(long) }; - long lValue; + long lValue; - for( i = 0; i < ARRAYSIZE(Mouse); ++i ) - { - lValue = ((long*)&dm_Current)[Mouse[i]]; + for( i = 0; i < ARRAYSIZE(Mouse); ++i ) + { + lValue = ((long*)&dm_Current)[Mouse[i]]; - if( lValue > MOUSE_THRESHOLD ) - { - iGotKey = SC_SCANSUCCEED; - bAxeDirection = AI_AXE_P; - } - if( lValue < -MOUSE_THRESHOLD ) - { - iGotKey = SC_SCANSUCCEED; - bAxeDirection = AI_AXE_N; - } - if( iGotKey ) - break; - } + if( lValue > MOUSE_THRESHOLD ) + { + iGotKey = SC_SCANSUCCEED; + bAxeDirection = AI_AXE_P; + } + if( lValue < -MOUSE_THRESHOLD ) + { + iGotKey = SC_SCANSUCCEED; + bAxeDirection = AI_AXE_N; + } + if( iGotKey ) + break; + } - if( iGotKey == SC_SCANSUCCEED ) - { - pButton->bBtnType = (BYTE)DT_MOUSEAXE; - pButton->bAxisID = (BYTE)bAxeDirection; - pButton->bOffset = (BYTE)Mouse[i]; - pButton->parentDevice = lpDevice; - } - else - { - for( i = 0; i < ARRAYSIZE( dm_Current.rgbButtons ); ++i ) - { - if(( dm_Current.rgbButtons[i] != rgbInitButtons[i] ) && ( dm_Current.rgbButtons[i] & 0x80 )) - { - iGotKey = SC_SCANSUCCEED; - pButton->bBtnType = (BYTE)DT_MOUSEBUTTON; - pButton->bAxisID = (BYTE)0; - pButton->bOffset = (BYTE)i; - pButton->parentDevice = lpDevice; - break; - } - } - } - CopyMemory( rgbInitButtons, dm_Current.rgbButtons, sizeof(rgbInitButtons)); + if( iGotKey == SC_SCANSUCCEED ) + { + pButton->bBtnType = (BYTE)DT_MOUSEAXE; + pButton->bAxisID = (BYTE)bAxeDirection; + pButton->bOffset = (BYTE)Mouse[i]; + pButton->parentDevice = lpDevice; + } + else + { + for( i = 0; i < ARRAYSIZE( dm_Current.rgbButtons ); ++i ) + { + if(( dm_Current.rgbButtons[i] != rgbInitButtons[i] ) && ( dm_Current.rgbButtons[i] & 0x80 )) + { + iGotKey = SC_SCANSUCCEED; + pButton->bBtnType = (BYTE)DT_MOUSEBUTTON; + pButton->bAxisID = (BYTE)0; + pButton->bOffset = (BYTE)i; + pButton->parentDevice = lpDevice; + break; + } + } + } + CopyMemory( rgbInitButtons, dm_Current.rgbButtons, sizeof(rgbInitButtons)); - return iGotKey; + return iGotKey; } // called when scanning devices to assign N64 buttons // tries to read any possible button presses or axes from lpDirectInputDevice; called by ScanDevices DWORD ScanGamePad ( LPDEVICE lpDevice, LPDWORD lpdwCounter, LPBUTTON pButton, int iDeviceNumber ) { - static DIJOYSTATE dj_Initial[MAX_DEVICES]; - static bool bFirstScan = true; - HRESULT hr; + static DIJOYSTATE dj_Initial[MAX_DEVICES]; + static bool bFirstScan = true; + HRESULT hr; - if ( *lpdwCounter == 0 ) - bFirstScan = true; + if ( *lpdwCounter == 0 ) + bFirstScan = true; - hr = lpDevice->didHandle->GetDeviceState( sizeof(DIJOYSTATE), &lpDevice->stateAs.joyState ); - if ( FAILED(hr) ) - { - hr = lpDevice->didHandle->Acquire(); - return FALSE; - } + hr = lpDevice->didHandle->GetDeviceState( sizeof(DIJOYSTATE), &lpDevice->stateAs.joyState ); + if ( FAILED(hr) ) + { + hr = lpDevice->didHandle->Acquire(); + return FALSE; + } - if ( bFirstScan ) - { - dj_Initial[iDeviceNumber] = lpDevice->stateAs.joyState; - bFirstScan = false; - return FALSE; // initial scan done; gotta wait until next time - } + if ( bFirstScan ) + { + dj_Initial[iDeviceNumber] = lpDevice->stateAs.joyState; + bFirstScan = false; + return FALSE; // initial scan done; gotta wait until next time + } - long lAxePos = ZEROVALUE + ( RANGERELATIVE * CONFIGTHRESHOLD / 100 ); - long lAxeNeg = ZEROVALUE - ( RANGERELATIVE * CONFIGTHRESHOLD / 100 ); - long lValue; + long lAxePos = ZEROVALUE + ( RANGERELATIVE * CONFIGTHRESHOLD / 100 ); + long lAxeNeg = ZEROVALUE - ( RANGERELATIVE * CONFIGTHRESHOLD / 100 ); + long lValue; - int iGotKey = FALSE; - BYTE bAxeDirection = 0; + int iGotKey = FALSE; + BYTE bAxeDirection = 0; - int JoyPad[][2] ={ { FIELD_OFFSET( DIJOYSTATE, lX ) / sizeof(long) , DT_JOYAXE }, - { FIELD_OFFSET( DIJOYSTATE, lY ) / sizeof(long) , DT_JOYAXE }, - { FIELD_OFFSET( DIJOYSTATE, lZ ) / sizeof(long) , DT_JOYAXE }, - { FIELD_OFFSET( DIJOYSTATE, lRx ) / sizeof(long) , DT_JOYAXE }, - { FIELD_OFFSET( DIJOYSTATE, lRy ) / sizeof(long) , DT_JOYAXE }, - { FIELD_OFFSET( DIJOYSTATE, lRz ) / sizeof(long) , DT_JOYAXE }, - { FIELD_OFFSET( DIJOYSTATE, rglSlider[0] ) / sizeof(long) , DT_JOYSLIDER }, - { FIELD_OFFSET( DIJOYSTATE, rglSlider[1] ) / sizeof(long) , DT_JOYSLIDER }, - { FIELD_OFFSET( DIJOYSTATE, rgdwPOV[0] ) / sizeof(long) , DT_JOYPOV }, - { FIELD_OFFSET( DIJOYSTATE, rgdwPOV[1] ) / sizeof(long) , DT_JOYPOV }, - { FIELD_OFFSET( DIJOYSTATE, rgdwPOV[2] ) / sizeof(long) , DT_JOYPOV }, - { FIELD_OFFSET( DIJOYSTATE, rgdwPOV[3] ) / sizeof(long) , DT_JOYPOV } }; + int JoyPad[][2] ={ { FIELD_OFFSET( DIJOYSTATE, lX ) / sizeof(long) , DT_JOYAXE }, + { FIELD_OFFSET( DIJOYSTATE, lY ) / sizeof(long) , DT_JOYAXE }, + { FIELD_OFFSET( DIJOYSTATE, lZ ) / sizeof(long) , DT_JOYAXE }, + { FIELD_OFFSET( DIJOYSTATE, lRx ) / sizeof(long) , DT_JOYAXE }, + { FIELD_OFFSET( DIJOYSTATE, lRy ) / sizeof(long) , DT_JOYAXE }, + { FIELD_OFFSET( DIJOYSTATE, lRz ) / sizeof(long) , DT_JOYAXE }, + { FIELD_OFFSET( DIJOYSTATE, rglSlider[0] ) / sizeof(long) , DT_JOYSLIDER }, + { FIELD_OFFSET( DIJOYSTATE, rglSlider[1] ) / sizeof(long) , DT_JOYSLIDER }, + { FIELD_OFFSET( DIJOYSTATE, rgdwPOV[0] ) / sizeof(long) , DT_JOYPOV }, + { FIELD_OFFSET( DIJOYSTATE, rgdwPOV[1] ) / sizeof(long) , DT_JOYPOV }, + { FIELD_OFFSET( DIJOYSTATE, rgdwPOV[2] ) / sizeof(long) , DT_JOYPOV }, + { FIELD_OFFSET( DIJOYSTATE, rgdwPOV[3] ) / sizeof(long) , DT_JOYPOV } }; - int i; + int i; - for( i = 0; i < ARRAYSIZE( JoyPad ); ++i ) - { - lValue = ((long*)&lpDevice->stateAs.joyState)[JoyPad[i][0]]; - if( lValue != ((long*)&(dj_Initial[iDeviceNumber]))[JoyPad[i][0]] ) - { - if(( JoyPad[i][1] == DT_JOYAXE ) || ( JoyPad[i][1] == DT_JOYSLIDER )) - { - if( lValue - ((long*)&(dj_Initial[iDeviceNumber]))[JoyPad[i][0]] > lAxePos ) - { - iGotKey = SC_SCANSUCCEED; - bAxeDirection = AI_AXE_P; - break; - } - else if( lValue - ((long*)&(dj_Initial[iDeviceNumber]))[JoyPad[i][0]] < lAxeNeg ) - { - iGotKey = SC_SCANSUCCEED; - bAxeDirection = AI_AXE_N; - break; - } - } - if( JoyPad[i][1] == DT_JOYPOV && LOWORD( lValue ) != 0xFFFF ) - { - iGotKey = SC_SCANSUCCEED; - if (( lValue > 31500 ) || ( lValue < 4500 )) - bAxeDirection = AI_POV_UP; - if (( lValue > 4500 ) && ( lValue < 13500 )) - bAxeDirection = AI_POV_RIGHT; - if (( lValue > 13500 ) && ( lValue < 22500 )) - bAxeDirection = AI_POV_DOWN; - if (( lValue > 22500 ) && ( lValue < 31500 )) - bAxeDirection = AI_POV_LEFT; - break; - } - } - } + for( i = 0; i < ARRAYSIZE( JoyPad ); ++i ) + { + lValue = ((long*)&lpDevice->stateAs.joyState)[JoyPad[i][0]]; + if( lValue != ((long*)&(dj_Initial[iDeviceNumber]))[JoyPad[i][0]] ) + { + if(( JoyPad[i][1] == DT_JOYAXE ) || ( JoyPad[i][1] == DT_JOYSLIDER )) + { + if( lValue - ((long*)&(dj_Initial[iDeviceNumber]))[JoyPad[i][0]] > lAxePos ) + { + iGotKey = SC_SCANSUCCEED; + bAxeDirection = AI_AXE_P; + break; + } + else if( lValue - ((long*)&(dj_Initial[iDeviceNumber]))[JoyPad[i][0]] < lAxeNeg ) + { + iGotKey = SC_SCANSUCCEED; + bAxeDirection = AI_AXE_N; + break; + } + } + if( JoyPad[i][1] == DT_JOYPOV && LOWORD( lValue ) != 0xFFFF ) + { + iGotKey = SC_SCANSUCCEED; + if (( lValue > 31500 ) || ( lValue < 4500 )) + bAxeDirection = AI_POV_UP; + if (( lValue > 4500 ) && ( lValue < 13500 )) + bAxeDirection = AI_POV_RIGHT; + if (( lValue > 13500 ) && ( lValue < 22500 )) + bAxeDirection = AI_POV_DOWN; + if (( lValue > 22500 ) && ( lValue < 31500 )) + bAxeDirection = AI_POV_LEFT; + break; + } + } + } - if( iGotKey == SC_SCANSUCCEED ) - { - pButton->bBtnType = (BYTE)JoyPad[i][1]; - pButton->bAxisID = (BYTE)bAxeDirection; - pButton->bOffset = (BYTE)JoyPad[i][0]; - pButton->parentDevice = lpDevice; - } - else - { - for( i = 0; i < ARRAYSIZE( lpDevice->stateAs.joyState.rgbButtons ); ++i ) - { - if (( lpDevice->stateAs.joyState.rgbButtons[i] & 0x80 )) - { - iGotKey = SC_SCANSUCCEED; - pButton->bBtnType = (BYTE)DT_JOYBUTTON; - pButton->bAxisID = (BYTE)0; - pButton->bOffset = (BYTE)i; - pButton->parentDevice = lpDevice; - break; - } - } - } + if( iGotKey == SC_SCANSUCCEED ) + { + pButton->bBtnType = (BYTE)JoyPad[i][1]; + pButton->bAxisID = (BYTE)bAxeDirection; + pButton->bOffset = (BYTE)JoyPad[i][0]; + pButton->parentDevice = lpDevice; + } + else + { + for( i = 0; i < ARRAYSIZE( lpDevice->stateAs.joyState.rgbButtons ); ++i ) + { + if (( lpDevice->stateAs.joyState.rgbButtons[i] & 0x80 )) + { + iGotKey = SC_SCANSUCCEED; + pButton->bBtnType = (BYTE)DT_JOYBUTTON; + pButton->bAxisID = (BYTE)0; + pButton->bOffset = (BYTE)i; + pButton->parentDevice = lpDevice; + break; + } + } + } - return iGotKey; + return iGotKey; } // called when we assign a control to an N64 button @@ -3747,52 +3747,52 @@ DWORD ScanGamePad ( LPDEVICE lpDevice, LPDWORD lpdwCounter, LPBUTTON pButton, in // *apDirectInputDevices is an array of only 2 devices; sys keyboard, sys mouse DWORD ScanDevices( LPDWORD lpdwCounter, LPBUTTON pButton ) { - // Do ALL our polling first-- this ensures consistency (i.e. every device always gets polled at same interval) -/* if( g_sysKeyboard.didHandle ) - { - if( FAILED(g_sysKeyboard.didHandle->Poll())) - g_sysKeyboard.didHandle->Acquire(); - } */ - if( g_sysMouse.didHandle ) - { - if( FAILED(g_sysMouse.didHandle->Poll())) - g_sysMouse.didHandle->Acquire(); - } - for (int i = 0; i < g_nDevices; i++) - if (g_devList[i].didHandle) - if (FAILED(g_devList[i].didHandle->Poll())) - g_devList[i].didHandle->Acquire(); + // Do ALL our polling first-- this ensures consistency (i.e. every device always gets polled at same interval) +/* if( g_sysKeyboard.didHandle ) + { + if( FAILED(g_sysKeyboard.didHandle->Poll())) + g_sysKeyboard.didHandle->Acquire(); + } */ + if( g_sysMouse.didHandle ) + { + if( FAILED(g_sysMouse.didHandle->Poll())) + g_sysMouse.didHandle->Acquire(); + } + for (int i = 0; i < g_nDevices; i++) + if (g_devList[i].didHandle) + if (FAILED(g_devList[i].didHandle->Poll())) + g_devList[i].didHandle->Acquire(); - // While we have devices to scan, - // if it's a keyboard, ScanKeyboard; if it's a mouse, ScanMouse; - // otherwise ScanGamePad. + // While we have devices to scan, + // if it's a keyboard, ScanKeyboard; if it's a mouse, ScanMouse; + // otherwise ScanGamePad. - DWORD dwReturn = FALSE; + DWORD dwReturn = FALSE; -// if( !dwReturn && g_sysKeyboard.didHandle ) -// dwReturn = ScanKeyboard( &g_sysKeyboard, lpdwCounter, pButton ); +// if( !dwReturn && g_sysKeyboard.didHandle ) +// dwReturn = ScanKeyboard( &g_sysKeyboard, lpdwCounter, pButton ); - if( !dwReturn && g_sysMouse.didHandle ) - dwReturn = ScanMouse( &g_sysMouse, lpdwCounter, pButton ); + if( !dwReturn && g_sysMouse.didHandle ) + dwReturn = ScanMouse( &g_sysMouse, lpdwCounter, pButton ); - // ScanGamePad on ALL remaining devices - for (int i = 0; !dwReturn && i < g_nDevices; i++) - if (g_devList[i].didHandle) - { - switch (LOBYTE(g_devList[i].dwDevType)) - { - case DI8DEVTYPE_KEYBOARD: - dwReturn = ScanKeyboard( &g_devList[i], lpdwCounter, pButton ); - break; - case DI8DEVTYPE_MOUSE: - dwReturn = ScanMouse( &g_devList[i], lpdwCounter, pButton ); - break; - default: - dwReturn = ScanGamePad( &g_devList[i], lpdwCounter, pButton, i ); - } - } + // ScanGamePad on ALL remaining devices + for (int i = 0; !dwReturn && i < g_nDevices; i++) + if (g_devList[i].didHandle) + { + switch (LOBYTE(g_devList[i].dwDevType)) + { + case DI8DEVTYPE_KEYBOARD: + dwReturn = ScanKeyboard( &g_devList[i], lpdwCounter, pButton ); + break; + case DI8DEVTYPE_MOUSE: + dwReturn = ScanMouse( &g_devList[i], lpdwCounter, pButton ); + break; + default: + dwReturn = ScanGamePad( &g_devList[i], lpdwCounter, pButton, i ); + } + } - return dwReturn; + return dwReturn; } // sets controller defaults; called when user clicks on "Clear Controller" or "Default Config" @@ -3800,205 +3800,205 @@ DWORD ScanDevices( LPDWORD lpdwCounter, LPBUTTON pButton ) // DEFAULTS TO NOT PLUGGED. Make sure you "plug" the first controller manually. void SetControllerDefaults( LPCONTROLLER pcController ) { - freePakData( pcController ); - freeModifiers( pcController ); - ZeroMemory( pcController, sizeof(CONTROLLER) ); + freePakData( pcController ); + freeModifiers( pcController ); + ZeroMemory( pcController, sizeof(CONTROLLER) ); - pcController->fRawData = true; - pcController->fRealN64Range = true; - pcController->bRapidFireEnabled = false; - pcController->bRapidFireRate = 3; // Set default rapid fire rate here - pcController->bStickRange = DEFAULT_STICKRANGE; - pcController->bPadDeadZone = DEFAULT_DEADZONE; - pcController->bRumbleTyp = DEFAULT_RUMBLETYP; - pcController->bRumbleStrength = DEFAULT_RUMBLESTRENGTH; - pcController->wMouseSensitivityX = DEFAULT_MOUSESENSIVITY; - pcController->wMouseSensitivityY = DEFAULT_MOUSESENSIVITY; - pcController->PakType = DEFAULT_PAKTYPE; - pcController->bMouseMoveX = DEFAULT_MOUSEMOVE; - pcController->bMouseMoveY = DEFAULT_MOUSEMOVE; + pcController->fRawData = true; + pcController->fRealN64Range = true; + pcController->bRapidFireEnabled = false; + pcController->bRapidFireRate = 3; // Set default rapid fire rate here + pcController->bStickRange = DEFAULT_STICKRANGE; + pcController->bPadDeadZone = DEFAULT_DEADZONE; + pcController->bRumbleTyp = DEFAULT_RUMBLETYP; + pcController->bRumbleStrength = DEFAULT_RUMBLESTRENGTH; + pcController->wMouseSensitivityX = DEFAULT_MOUSESENSIVITY; + pcController->wMouseSensitivityY = DEFAULT_MOUSESENSIVITY; + pcController->PakType = DEFAULT_PAKTYPE; + pcController->bMouseMoveX = DEFAULT_MOUSEMOVE; + pcController->bMouseMoveY = DEFAULT_MOUSEMOVE; } void DeleteControllerSettings( int indexController ) { - if( !g_ivConfig ) - return; + if( !g_ivConfig ) + return; - SetControllerDefaults( &g_ivConfig->Controllers[indexController] ); - g_ivConfig->FFDevices[indexController].bProductCounter = 0; - g_ivConfig->FFDevices[indexController].szProductName[0] = _T('\0'); + SetControllerDefaults( &g_ivConfig->Controllers[indexController] ); + g_ivConfig->FFDevices[indexController].bProductCounter = 0; + g_ivConfig->FFDevices[indexController].szProductName[0] = _T('\0'); - return; + return; } // SetModifier activates certain "always on" Config modifiers after they've been inserted or loaded void SetModifier( LPCONTROLLER pcController ) { - for( int i = 0; i < pcController->nModifiers; i++ ) - { - if( pcController->pModifiers[i].bModType == MDT_CONFIG && pcController->pModifiers[i].fStatus ) - { - MODSPEC_CONFIG args; - args.dwValue = pcController->pModifiers[i].dwSpecific; - if( args.fChangeAnalogConfig ) - { - BYTE bConfig = (BYTE)args.fAnalogStickMode; - if( bConfig < PF_AXESETS ) - pcController->bAxisSet = bConfig; - else - { - if( pcController->bAxisSet == PF_AXESETS-1 ) - pcController->bAxisSet = 0; - else - ++pcController->bAxisSet; - } - } - if( args.fChangeMouseXAxis ) - if (pcController->bMouseMoveX == MM_BUFF) - pcController->bMouseMoveX = MM_ABS; - else if (pcController->bMouseMoveX == MM_ABS) - pcController->bMouseMoveX = MM_BUFF; - if( args.fChangeMouseYAxis ) - if (pcController->bMouseMoveY == MM_BUFF) - pcController->bMouseMoveY = MM_ABS; - else if (pcController->bMouseMoveY == MM_ABS) - pcController->bMouseMoveY = MM_BUFF; + for( int i = 0; i < pcController->nModifiers; i++ ) + { + if( pcController->pModifiers[i].bModType == MDT_CONFIG && pcController->pModifiers[i].fStatus ) + { + MODSPEC_CONFIG args; + args.dwValue = pcController->pModifiers[i].dwSpecific; + if( args.fChangeAnalogConfig ) + { + BYTE bConfig = (BYTE)args.fAnalogStickMode; + if( bConfig < PF_AXESETS ) + pcController->bAxisSet = bConfig; + else + { + if( pcController->bAxisSet == PF_AXESETS-1 ) + pcController->bAxisSet = 0; + else + ++pcController->bAxisSet; + } + } + if( args.fChangeMouseXAxis ) + if (pcController->bMouseMoveX == MM_BUFF) + pcController->bMouseMoveX = MM_ABS; + else if (pcController->bMouseMoveX == MM_ABS) + pcController->bMouseMoveX = MM_BUFF; + if( args.fChangeMouseYAxis ) + if (pcController->bMouseMoveY == MM_BUFF) + pcController->bMouseMoveY = MM_ABS; + else if (pcController->bMouseMoveY == MM_ABS) + pcController->bMouseMoveY = MM_BUFF; - if( args.fChangeKeyboardXAxis ) - pcController->fKeyAbsoluteX = !pcController->fKeyAbsoluteX; - if( args.fChangeKeyboardYAxis ) - pcController->fKeyAbsoluteY = !pcController->fKeyAbsoluteY; - } - } + if( args.fChangeKeyboardXAxis ) + pcController->fKeyAbsoluteX = !pcController->fKeyAbsoluteX; + if( args.fChangeKeyboardYAxis ) + pcController->fKeyAbsoluteY = !pcController->fKeyAbsoluteY; + } + } } // Copies over the existing g_pcControllers' idea of configuration over to the interface. void GetCurrentConfiguration() { - EnterCriticalSection( &g_critical ); + EnterCriticalSection( &g_critical ); - g_ivConfig->Language = g_strEmuInfo.Language; - g_ivConfig->fDisplayShortPop = g_strEmuInfo.fDisplayShortPop; + g_ivConfig->Language = g_strEmuInfo.Language; + g_ivConfig->fDisplayShortPop = g_strEmuInfo.fDisplayShortPop; - LPCONTROLLER pcController; - for( int i = 0; i < 4; i++ ) - { - pcController = &g_ivConfig->Controllers[i]; - CopyMemory( pcController, &g_pcControllers[i], sizeof(CONTROLLER)); + LPCONTROLLER pcController; + for( int i = 0; i < 4; i++ ) + { + pcController = &g_ivConfig->Controllers[i]; + CopyMemory( pcController, &g_pcControllers[i], sizeof(CONTROLLER)); - if( pcController->nModifiers > 0 ) - { - pcController->pModifiers = (LPMODIFIER)P_malloc( sizeof(MODIFIER) * pcController->nModifiers ); - CopyMemory( pcController->pModifiers, g_pcControllers[i].pModifiers, sizeof(MODIFIER) * pcController->nModifiers ); - SetModifier( pcController ); - } - else - pcController->pModifiers = NULL; + if( pcController->nModifiers > 0 ) + { + pcController->pModifiers = (LPMODIFIER)P_malloc( sizeof(MODIFIER) * pcController->nModifiers ); + CopyMemory( pcController->pModifiers, g_pcControllers[i].pModifiers, sizeof(MODIFIER) * pcController->nModifiers ); + SetModifier( pcController ); + } + else + pcController->pModifiers = NULL; - pcController->pPakData = NULL; + pcController->pPakData = NULL; - for( int iDevice = 0; iDevice < ARRAYSIZE(g_devList) && g_devList[iDevice].dwDevType; ++iDevice ) - { - if( g_devList[iDevice].guidInstance == pcController->guidFFDevice ) - { - g_ivConfig->FFDevices[i].bProductCounter = g_devList[iDevice].bProductCounter; - lstrcpyn( g_ivConfig->FFDevices[i].szProductName, g_devList[iDevice].szProductName, MAX_PATH ); - break; - } - } - } + for( int iDevice = 0; iDevice < ARRAYSIZE(g_devList) && g_devList[iDevice].dwDevType; ++iDevice ) + { + if( g_devList[iDevice].guidInstance == pcController->guidFFDevice ) + { + g_ivConfig->FFDevices[i].bProductCounter = g_devList[iDevice].bProductCounter; + lstrcpyn( g_ivConfig->FFDevices[i].szProductName, g_devList[iDevice].szProductName, MAX_PATH ); + break; + } + } + } - LeaveCriticalSection( &g_critical ); - return; + LeaveCriticalSection( &g_critical ); + return; } // Copies over the interface's idea of configuration over to g_pcControllers. void UpdateControllerStructures() { - // bDebug = g_ivConfig->bAutoConfig; - EnterCriticalSection( &g_critical ); + // bDebug = g_ivConfig->bAutoConfig; + EnterCriticalSection( &g_critical ); - g_iFirstController = -1; + g_iFirstController = -1; #ifdef _UNICODE - // might as well use this time to copy over language info and open the new DLL as well... --rabid - g_strEmuInfo.Language = g_ivConfig->Language; - if (g_hResourceDLL != g_strEmuInfo.hinst) - FreeLibrary(g_hResourceDLL); - g_hResourceDLL = LoadLanguageDLL(g_strEmuInfo.Language); - if( g_hResourceDLL == NULL ) - { - g_strEmuInfo.Language = 0; - g_hResourceDLL = g_strEmuInfo.hinst; - DebugWriteA("couldn't load language DLL, falling back to defaults\n"); - } + // might as well use this time to copy over language info and open the new DLL as well... --rabid + g_strEmuInfo.Language = g_ivConfig->Language; + if (g_hResourceDLL != g_strEmuInfo.hinst) + FreeLibrary(g_hResourceDLL); + g_hResourceDLL = LoadLanguageDLL(g_strEmuInfo.Language); + if( g_hResourceDLL == NULL ) + { + g_strEmuInfo.Language = 0; + g_hResourceDLL = g_strEmuInfo.hinst; + DebugWriteA("couldn't load language DLL, falling back to defaults\n"); + } #endif // #ifdef _UNICODE - g_strEmuInfo.fDisplayShortPop = g_ivConfig->fDisplayShortPop; + g_strEmuInfo.fDisplayShortPop = g_ivConfig->fDisplayShortPop; - LPCONTROLLER pcController; - for( int i = 3; i >= 0; i-- ) - { - pcController = &g_ivConfig->Controllers[i]; + LPCONTROLLER pcController; + for( int i = 3; i >= 0; i-- ) + { + pcController = &g_ivConfig->Controllers[i]; - SaveControllerPak( i ); - CloseControllerPak( i ); -// freePakData( &g_pcControllers[i] ); // called already by CloseControllerPak - freeModifiers( &g_pcControllers[i] ); + SaveControllerPak( i ); + CloseControllerPak( i ); +// freePakData( &g_pcControllers[i] ); // called already by CloseControllerPak + freeModifiers( &g_pcControllers[i] ); - CopyMemory( &g_pcControllers[i], pcController, sizeof(CONTROLLER)); - g_pcControllers[i].pPakData = NULL; - g_pcControllers[i].pModifiers = NULL; + CopyMemory( &g_pcControllers[i], pcController, sizeof(CONTROLLER)); + g_pcControllers[i].pPakData = NULL; + g_pcControllers[i].pModifiers = NULL; - if( g_pcControllers[i].nModifiers > 0 ) - { - g_pcControllers[i].pModifiers = (LPMODIFIER)P_malloc( sizeof(MODIFIER) * g_pcControllers[i].nModifiers ); - CopyMemory( g_pcControllers[i].pModifiers, pcController->pModifiers, sizeof(MODIFIER) * g_pcControllers[i].nModifiers ); - SetModifier( &g_pcControllers[i] ); - } + if( g_pcControllers[i].nModifiers > 0 ) + { + g_pcControllers[i].pModifiers = (LPMODIFIER)P_malloc( sizeof(MODIFIER) * g_pcControllers[i].nModifiers ); + CopyMemory( g_pcControllers[i].pModifiers, pcController->pModifiers, sizeof(MODIFIER) * g_pcControllers[i].nModifiers ); + SetModifier( &g_pcControllers[i] ); + } - int iDevice = FindDeviceinList( g_ivConfig->FFDevices[i].szProductName, g_ivConfig->FFDevices[i].bProductCounter, true ); - if( iDevice != -1 && g_devList[iDevice].bEffType ) - { - g_pcControllers[i].guidFFDevice = g_devList[iDevice].guidInstance; - } - else - { - g_pcControllers[i].guidFFDevice = GUID_NULL; - } + int iDevice = FindDeviceinList( g_ivConfig->FFDevices[i].szProductName, g_ivConfig->FFDevices[i].bProductCounter, true ); + if( iDevice != -1 && g_devList[iDevice].bEffType ) + { + g_pcControllers[i].guidFFDevice = g_devList[iDevice].guidInstance; + } + else + { + g_pcControllers[i].guidFFDevice = GUID_NULL; + } - g_pcControllers[i].fPakCRCError = false; - g_pcControllers[i].fPakInitialized = false; + g_pcControllers[i].fPakCRCError = false; + g_pcControllers[i].fPakInitialized = false; - if (g_pcControllers[i].fPlugged) - g_iFirstController = i; - } - LeaveCriticalSection( &g_critical ); - return; + if (g_pcControllers[i].fPlugged) + g_iFirstController = i; + } + LeaveCriticalSection( &g_critical ); + return; } LRESULT CALLBACK BlockerProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { - PAINTSTRUCT ps; + PAINTSTRUCT ps; - switch (msg) - { - case WM_CREATE: - return 0; - case WM_PAINT: - BeginPaint(hwnd, &ps); - EndPaint(hwnd, &ps); - return 0; - default: - return DefWindowProc(hwnd, msg, wParam, lParam); - } -// return 0; + switch (msg) + { + case WM_CREATE: + return 0; + case WM_PAINT: + BeginPaint(hwnd, &ps); + EndPaint(hwnd, &ps); + return 0; + default: + return DefWindowProc(hwnd, msg, wParam, lParam); + } +// return 0; } BOOL InitOverlay(void) { - // registers our overlay class + // registers our overlay class WNDCLASS wc; @@ -4023,31 +4023,31 @@ BOOL InitOverlay(void) HWND MakeOverlay() { - HWND hwnd; - RECT size; + HWND hwnd; + RECT size; - GetWindowRect(g_hMainDialog, &size); + GetWindowRect(g_hMainDialog, &size); - // Create the main window. + // Create the main window. - hwnd = CreateWindowEx( - WS_EX_TOPMOST | WS_EX_TRANSPARENT, - _T("BlockerClass"), - _T("Blocker"), - WS_POPUP, - size.left, // horizontal position - size.top, // vertical position - size.right - size.left, // width - size.bottom - size.top, // height - g_hMainDialog, // owner window - (HMENU) NULL, // menu - g_strEmuInfo.hinst, // handle to application instance - (LPVOID) NULL // window-creation data - ); - if (!hwnd) - return NULL; + hwnd = CreateWindowEx( + WS_EX_TOPMOST | WS_EX_TRANSPARENT, + _T("BlockerClass"), + _T("Blocker"), + WS_POPUP, + size.left, // horizontal position + size.top, // vertical position + size.right - size.left, // width + size.bottom - size.top, // height + g_hMainDialog, // owner window + (HMENU) NULL, // menu + g_strEmuInfo.hinst, // handle to application instance + (LPVOID) NULL // window-creation data + ); + if (!hwnd) + return NULL; - // Show the window (necessary to block input) - ShowWindow(hwnd, SW_SHOWNOACTIVATE); - return hwnd; + // Show the window (necessary to block input) + ShowWindow(hwnd, SW_SHOWNOACTIVATE); + return hwnd; } diff --git a/Source/nragev20/Interface.h b/Source/nragev20/Interface.h index 998b2e569..9f386403f 100644 --- a/Source/nragev20/Interface.h +++ b/Source/nragev20/Interface.h @@ -1,9 +1,9 @@ -/* - N-Rage`s Dinput8 Plugin +/* + N-Rage`s Dinput8 Plugin (C) 2002, 2006 Norbert Wladyka - Author`s Email: norbert.wladyka@chello.at - Website: http://go.to/nrage + Author`s Email: norbert.wladyka@chello.at + Website: http://go.to/nrage This program is free software; you can redistribute it and/or modify @@ -29,64 +29,64 @@ void SetModifier( CONTROLLER *pcController ); void SetControllerDefaults( CONTROLLER *pcController ); // application internal message -#define WM_USER_UPDATE WM_USER + 1 +#define WM_USER_UPDATE WM_USER + 1 // application internal message -#define WM_USER_READVALUES WM_USER + 2 +#define WM_USER_READVALUES WM_USER + 2 -#define CONFIGTHRESHOLD 50 -#define MOUSE_THRESHOLD 10 +#define CONFIGTHRESHOLD 50 +#define MOUSE_THRESHOLD 10 -#define SC_SCANSUCCEED 0x01 -#define SC_SCANESCAPE 0x10 +#define SC_SCANSUCCEED 0x01 +#define SC_SCANESCAPE 0x10 -#define TIMER_BUTTON 1 +#define TIMER_BUTTON 1 -#define INTERVAL_BUTTON 20 -#define INTERVAL_RUMBLETEST 20 +#define INTERVAL_BUTTON 20 +#define INTERVAL_RUMBLETEST 20 -#define MPAK_FORMATABLE 0x01 -#define MPAK_READABLE 0x02 -#define MPAK_WRITEABLE 0x04 +#define MPAK_FORMATABLE 0x01 +#define MPAK_READABLE 0x02 +#define MPAK_WRITEABLE 0x04 -#define MPAK_OK 0x07 -#define MPAK_INUSE 0x12 -#define MPAK_WRONGSIZE 0x27 -#define MPAK_DAMAGED 0x71 -#define MPAK_ERROR 0x81 -#define MPAK_NOSELECTION 0xF0 +#define MPAK_OK 0x07 +#define MPAK_INUSE 0x12 +#define MPAK_WRONGSIZE 0x27 +#define MPAK_DAMAGED 0x71 +#define MPAK_ERROR 0x81 +#define MPAK_NOSELECTION 0xF0 -#define BSET_CONTROLS 1 -#define BSET_SHORTCUTS 2 +#define BSET_CONTROLS 1 +#define BSET_SHORTCUTS 2 typedef struct _IFDEVICE { - TCHAR szProductName[MAX_PATH+1]; - BYTE bProductCounter; + TCHAR szProductName[MAX_PATH+1]; + BYTE bProductCounter; } IFDEVICE, *LPIFDEVICE; typedef struct _INTERFACEVALUES { - BYTE ChosenTab; - CONTROLLER Controllers[4]; - IFDEVICE FFDevices[4]; - SHORTCUTS Shortcuts; - LANGID Language; - bool fDisplayShortPop; + BYTE ChosenTab; + CONTROLLER Controllers[4]; + IFDEVICE FFDevices[4]; + SHORTCUTS Shortcuts; + LANGID Language; + bool fDisplayShortPop; } INTERFACEVALUES, *LPINTERFACEVALUES; -#define TAB_CONTROLLER1 0 -#define TAB_CONTROLLER2 1 -#define TAB_CONTROLLER3 2 -#define TAB_CONTROLLER4 3 -#define TAB_SHORTCUTS 4 -#define TAB_FOLDERS 5 +#define TAB_CONTROLLER1 0 +#define TAB_CONTROLLER2 1 +#define TAB_CONTROLLER3 2 +#define TAB_CONTROLLER4 3 +#define TAB_SHORTCUTS 4 +#define TAB_FOLDERS 5 -#define TAB_CONTROLS 0 -#define TAB_DEVICES 1 -#define TAB_MODIFIERS 2 -#define TAB_PAK 3 +#define TAB_CONTROLS 0 +#define TAB_DEVICES 1 +#define TAB_MODIFIERS 2 +#define TAB_PAK 3 extern INTERFACEVALUES *g_ivConfig; diff --git a/Source/nragev20/International.cpp b/Source/nragev20/International.cpp index 5aa0ac3ce..1e0eab5f3 100644 --- a/Source/nragev20/International.cpp +++ b/Source/nragev20/International.cpp @@ -1,9 +1,9 @@ /* - N-Rage`s Dinput8 Plugin + N-Rage`s Dinput8 Plugin (C) 2002, 2006 Norbert Wladyka - Author`s Email: norbert.wladyka@chello.at - Website: http://go.to/nrage + Author`s Email: norbert.wladyka@chello.at + Website: http://go.to/nrage This program is free software; you can redistribute it and/or modify @@ -41,29 +41,29 @@ BOOL CALLBACK EnumLangProc(HANDLE hModule, LPCTSTR lpszType, LPCTSTR lpszName, W // "If it ain't broke, don't fix it." // Loads the satellite DLL specified for the language DesiredLanguage -HMODULE LoadLanguageDLL(LANGID DesiredLanguage) +HMODULE LoadLanguageDLL(LANGID DesiredLanguage) { - TCHAR SatellitePath[MAX_PATH]; - HMODULE hDLL; + TCHAR SatellitePath[MAX_PATH]; + HMODULE hDLL; - // First try to load the library with the fully specified language - _stprintf(SatellitePath, _T("NRage-Language-%u.dll"), DesiredLanguage); - hDLL = LoadLibraryEx(SatellitePath, 0, 0); - if( hDLL ) - return hDLL; - else - { // try the primary language ID - DesiredLanguage = PRIMARYLANGID(DesiredLanguage); - _stprintf(SatellitePath, _T("NRage-Language-%u.dll"), DesiredLanguage); - hDLL = LoadLibraryEx(SatellitePath, 0, 0); - if( hDLL ) - return hDLL; - else - { - DebugWrite(_T("Couldn't load library: %s\n"), SatellitePath); - return NULL; - } - } + // First try to load the library with the fully specified language + _stprintf(SatellitePath, _T("NRage-Language-%u.dll"), DesiredLanguage); + hDLL = LoadLibraryEx(SatellitePath, 0, 0); + if( hDLL ) + return hDLL; + else + { // try the primary language ID + DesiredLanguage = PRIMARYLANGID(DesiredLanguage); + _stprintf(SatellitePath, _T("NRage-Language-%u.dll"), DesiredLanguage); + hDLL = LoadLibraryEx(SatellitePath, 0, 0); + if( hDLL ) + return hDLL; + else + { + DebugWrite(_T("Couldn't load library: %s\n"), SatellitePath); + return NULL; + } + } } // The following functions contain code to @@ -71,7 +71,7 @@ HMODULE LoadLanguageDLL(LANGID DesiredLanguage) // user interface should be displayed BOOL CALLBACK EnumLangProc(HANDLE hModule, LPCTSTR lpszType, LPCTSTR lpszName, - WORD wIDLanguage, LONG_PTR lParam) + WORD wIDLanguage, LONG_PTR lParam) { PLANGINFO LangInfo; @@ -82,7 +82,7 @@ BOOL CALLBACK EnumLangProc(HANDLE hModule, LPCTSTR lpszType, LPCTSTR lpszName, return (TRUE); // continue enumeration } -// Detects the language of ntdll.dll with some specific processing for +// Detects the language of ntdll.dll with some specific processing for // the Hongkong SAR version LANGID GetNTDLLNativeLangID() { @@ -113,7 +113,7 @@ BOOL IsHongKongVersion() { HMODULE hMod; BOOL bRet=FALSE; - typedef BOOL (WINAPI *IMMRELEASECONTEXT)(HWND,HIMC); + typedef BOOL (WINAPI *IMMRELEASECONTEXT)(HWND,HIMC); IMMRELEASECONTEXT pImmReleaseContext; hMod = LoadLibrary(_T("imm32.dll")); @@ -133,65 +133,65 @@ BOOL IsHongKongVersion() LANGID DetectLanguage() { -#define MAX_KEY_BUFFER 80 +#define MAX_KEY_BUFFER 80 - OSVERSIONINFO VersionInfo; - LANGID uiLangID = 0; - HKEY hKey; - DWORD Type, BuffLen = MAX_KEY_BUFFER; - TCHAR LangKeyValue[MAX_KEY_BUFFER]; + OSVERSIONINFO VersionInfo; + LANGID uiLangID = 0; + HKEY hKey; + DWORD Type, BuffLen = MAX_KEY_BUFFER; + TCHAR LangKeyValue[MAX_KEY_BUFFER]; - VersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - if( !GetVersionEx(&VersionInfo) ) - return(0); + VersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + if( !GetVersionEx(&VersionInfo) ) + return(0); - switch( VersionInfo.dwPlatformId ) - { - // On Windows NT, Windows 2000 or higher - case VER_PLATFORM_WIN32_NT: - if( VersionInfo.dwMajorVersion >= 5) // Windows 2000 or higher - { - // we need to dynamically link the GetUserDefaultUILanguage func - HMODULE hmKernDLL = LoadLibrary(_T("kernel32.dll")); - if (hmKernDLL) - { - LANGID (*fpGetLang)() = NULL; - fpGetLang = (LANGID(*)(void))GetProcAddress(hmKernDLL, "GetUserDefaultUILanguage"); - uiLangID = fpGetLang(); - } // and if we couldn't load kernel32.dll, just fall back to default language - } - else - { // for NT4 check the language of ntdll.dll - uiLangID = GetNTDLLNativeLangID(); - if (uiLangID == 1033) - { // special processing for Honkong SAR version of NT4 - if (IsHongKongVersion()) - { - uiLangID = 3076; - } - } - } - break; - // On Windows 95, Windows 98 or Windows ME - case VER_PLATFORM_WIN32_WINDOWS: - // Open the registry key for the UI language - if( RegOpenKeyEx(HKEY_CURRENT_USER,_T("Default\\Control Panel\\Desktop\\ResourceLocale"), 0, - KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS ) - { - // Get the type of the default key - if( RegQueryValueEx(hKey, NULL, NULL, &Type, NULL, NULL) == ERROR_SUCCESS - && Type == REG_SZ ) - { // Read the key value - if( RegQueryValueEx(hKey, NULL, NULL, &Type, (LPBYTE)LangKeyValue, &BuffLen) - == ERROR_SUCCESS ) - { - uiLangID = _ttoi(LangKeyValue); - } - } - RegCloseKey(hKey); - } - break; - } + switch( VersionInfo.dwPlatformId ) + { + // On Windows NT, Windows 2000 or higher + case VER_PLATFORM_WIN32_NT: + if( VersionInfo.dwMajorVersion >= 5) // Windows 2000 or higher + { + // we need to dynamically link the GetUserDefaultUILanguage func + HMODULE hmKernDLL = LoadLibrary(_T("kernel32.dll")); + if (hmKernDLL) + { + LANGID (*fpGetLang)() = NULL; + fpGetLang = (LANGID(*)(void))GetProcAddress(hmKernDLL, "GetUserDefaultUILanguage"); + uiLangID = fpGetLang(); + } // and if we couldn't load kernel32.dll, just fall back to default language + } + else + { // for NT4 check the language of ntdll.dll + uiLangID = GetNTDLLNativeLangID(); + if (uiLangID == 1033) + { // special processing for Honkong SAR version of NT4 + if (IsHongKongVersion()) + { + uiLangID = 3076; + } + } + } + break; + // On Windows 95, Windows 98 or Windows ME + case VER_PLATFORM_WIN32_WINDOWS: + // Open the registry key for the UI language + if( RegOpenKeyEx(HKEY_CURRENT_USER,_T("Default\\Control Panel\\Desktop\\ResourceLocale"), 0, + KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS ) + { + // Get the type of the default key + if( RegQueryValueEx(hKey, NULL, NULL, &Type, NULL, NULL) == ERROR_SUCCESS + && Type == REG_SZ ) + { // Read the key value + if( RegQueryValueEx(hKey, NULL, NULL, &Type, (LPBYTE)LangKeyValue, &BuffLen) + == ERROR_SUCCESS ) + { + uiLangID = _ttoi(LangKeyValue); + } + } + RegCloseKey(hKey); + } + break; + } if (uiLangID == 0) { diff --git a/Source/nragev20/International.h b/Source/nragev20/International.h index abac85e56..0edcde48a 100644 --- a/Source/nragev20/International.h +++ b/Source/nragev20/International.h @@ -1,9 +1,9 @@ -/* - N-Rage`s Dinput8 Plugin +/* + N-Rage`s Dinput8 Plugin (C) 2002, 2006 Norbert Wladyka - Author`s Email: norbert.wladyka@chello.at - Website: http://go.to/nrage + Author`s Email: norbert.wladyka@chello.at + Website: http://go.to/nrage This program is free software; you can redistribute it and/or modify @@ -30,15 +30,15 @@ typedef struct LANGINFO_DEF { - int Count; - LANGID LangID; + int Count; + LANGID LangID; } LANGINFO; typedef LANGINFO *PLANGINFO; // only export these functions if UNICODE support is enabled #ifdef _UNICODE LANGID DetectLanguage(); -HMODULE LoadLanguageDLL(LANGID DesiredLanguage); +HMODULE LoadLanguageDLL(LANGID DesiredLanguage); #endif // #ifdef _UNICODE #endif // #ifndef _NRINTERNATIONAL_ diff --git a/Source/nragev20/NRagePluginV2.cpp b/Source/nragev20/NRagePluginV2.cpp index a69bcd95b..2d34c15e5 100644 --- a/Source/nragev20/NRagePluginV2.cpp +++ b/Source/nragev20/NRagePluginV2.cpp @@ -1,9 +1,9 @@ -/* - N-Rage`s Dinput8 Plugin +/* + N-Rage`s Dinput8 Plugin (C) 2002, 2006 Norbert Wladyka - Author`s Email: norbert.wladyka@chello.at - Website: http://go.to/nrage + Author`s Email: norbert.wladyka@chello.at + Website: http://go.to/nrage This program is free software; you can redistribute it and/or modify @@ -45,98 +45,98 @@ DWORD WINAPI MsgThreadFunction( LPVOID lpParam ); DWORD WINAPI DelayedShortcut(LPVOID lpParam); // Global Variables // -HMODULE g_hDirectInputDLL = NULL; // Handle to DirectInput8 library -HMODULE g_hXInputDLL = NULL; // Handle to XInput Library -HMODULE g_hResourceDLL = NULL; // Handle to resource library; used by LoadString for internationalization -HANDLE g_hHeap = NULL; // Handle to our heap -int g_nDevices = 0; // number of devices in g_devList -DEVICE g_devList[MAX_DEVICES]; // list of attached input devices, except SysMouse - // note: we never purge the list of devices during normal operation -DEVICE g_sysMouse; // we need to treat the sysmouse differently, as we may use "locking"; changed from g_apInputDevice[1] --rabid +HMODULE g_hDirectInputDLL = NULL; // Handle to DirectInput8 library +HMODULE g_hXInputDLL = NULL; // Handle to XInput Library +HMODULE g_hResourceDLL = NULL; // Handle to resource library; used by LoadString for internationalization +HANDLE g_hHeap = NULL; // Handle to our heap +int g_nDevices = 0; // number of devices in g_devList +DEVICE g_devList[MAX_DEVICES]; // list of attached input devices, except SysMouse + // note: we never purge the list of devices during normal operation +DEVICE g_sysMouse; // we need to treat the sysmouse differently, as we may use "locking"; changed from g_apInputDevice[1] --rabid -EMULATOR_INFO g_strEmuInfo; // emulator info? Stores stuff like our hWnd handle and whether the plugin is initialized yet -TCHAR g_aszDefFolders[3][MAX_PATH]; // default folders: DIRECTORY_MEMPAK, DIRECTORY_GBROMS, DIRECTORY_GBSAVES -TCHAR g_aszLastBrowse[6][MAX_PATH]; // last browsed folders: BF_MEMPAK, BF_GBROM, BF_GBSAVE, BF_PROFILE, BF_NOTE, BF_SHORTCUTS +EMULATOR_INFO g_strEmuInfo; // emulator info? Stores stuff like our hWnd handle and whether the plugin is initialized yet +TCHAR g_aszDefFolders[3][MAX_PATH]; // default folders: DIRECTORY_MEMPAK, DIRECTORY_GBROMS, DIRECTORY_GBSAVES +TCHAR g_aszLastBrowse[6][MAX_PATH]; // last browsed folders: BF_MEMPAK, BF_GBROM, BF_GBSAVE, BF_PROFILE, BF_NOTE, BF_SHORTCUTS -CRITICAL_SECTION g_critical; // our critical section semaphore -int g_iFirstController = -1; // The first controller which is plugged in - // Normally controllers are scanned all at once in sequence, 1-4. We only want to scan devices once per pass; - // this is so we get consistent sample rates on our mouse. +CRITICAL_SECTION g_critical; // our critical section semaphore +int g_iFirstController = -1; // The first controller which is plugged in + // Normally controllers are scanned all at once in sequence, 1-4. We only want to scan devices once per pass; + // this is so we get consistent sample rates on our mouse. -bool g_bRunning = false; // Is the emulator running (i.e. have we opened a ROM)? -bool g_bConfiguring = false; // Are we currently in a config menu? -bool g_bExclusiveMouse = true; // Do we have an exclusive mouse lock? defaults to true unless we have no bound mouse buttons/axes -CONTROLLER g_pcControllers[4]; // Our four N64 controllers, connected or otherwise +bool g_bRunning = false; // Is the emulator running (i.e. have we opened a ROM)? +bool g_bConfiguring = false; // Are we currently in a config menu? +bool g_bExclusiveMouse = true; // Do we have an exclusive mouse lock? defaults to true unless we have no bound mouse buttons/axes +CONTROLLER g_pcControllers[4]; // Our four N64 controllers, connected or otherwise SHORTCUTS g_scShortcuts; -LPDIRECTINPUTDEVICE8 g_apFFDevice[4] = { NULL, NULL, NULL, NULL }; // added by rabid -LPDIRECTINPUTEFFECT g_apdiEffect[4] = { NULL, NULL, NULL, NULL }; // array of handles for FF-Effects, one for each controller +LPDIRECTINPUTDEVICE8 g_apFFDevice[4] = { NULL, NULL, NULL, NULL }; // added by rabid +LPDIRECTINPUTEFFECT g_apdiEffect[4] = { NULL, NULL, NULL, NULL }; // array of handles for FF-Effects, one for each controller TCHAR g_pszThreadMessage[DEFAULT_BUFFER] = _T(""); BOOL APIENTRY DllMain( HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { - switch ( ul_reason_for_call ) - { - case DLL_PROCESS_ATTACH: - DisableThreadLibraryCalls( hModule ); - if( !prepareHeap()) - return FALSE; - DebugWriteA("*** DLL Attach (" VER_FILE_VERSION_STR "-Debugbuild | built on " __DATE__ " at " __TIME__")\n"); - ZeroMemory( &g_strEmuInfo, sizeof(g_strEmuInfo) ); - ZeroMemory( g_devList, sizeof(g_devList) ); - ZeroMemory( &g_sysMouse, sizeof(g_sysMouse) ); - ZeroMemory( g_aszDefFolders, sizeof(g_aszDefFolders) ); - ZeroMemory( g_aszLastBrowse, sizeof(g_aszLastBrowse) ); - g_strEmuInfo.hinst = hModule; - g_strEmuInfo.fDisplayShortPop = true; // display pak switching message windows by default + switch ( ul_reason_for_call ) + { + case DLL_PROCESS_ATTACH: + DisableThreadLibraryCalls( hModule ); + if( !prepareHeap()) + return FALSE; + DebugWriteA("*** DLL Attach (" VER_FILE_VERSION_STR "-Debugbuild | built on " __DATE__ " at " __TIME__")\n"); + ZeroMemory( &g_strEmuInfo, sizeof(g_strEmuInfo) ); + ZeroMemory( g_devList, sizeof(g_devList) ); + ZeroMemory( &g_sysMouse, sizeof(g_sysMouse) ); + ZeroMemory( g_aszDefFolders, sizeof(g_aszDefFolders) ); + ZeroMemory( g_aszLastBrowse, sizeof(g_aszLastBrowse) ); + g_strEmuInfo.hinst = hModule; + g_strEmuInfo.fDisplayShortPop = true; // display pak switching message windows by default #ifdef _UNICODE - { - g_strEmuInfo.Language = GetLanguageFromINI(); - if ( g_strEmuInfo.Language == 0 ) - { - g_strEmuInfo.Language = DetectLanguage(); - DebugWriteA("Autoselect language: %d\n", g_strEmuInfo.Language); - } - g_hResourceDLL = LoadLanguageDLL(g_strEmuInfo.Language); // HACK: it's theoretically not safe to call LoadLibraryEx from DllMain... --rabid - if( g_hResourceDLL == NULL ) - { - g_strEmuInfo.Language = 0; - g_hResourceDLL = hModule; - DebugWriteA("couldn't load language DLL, falling back to defaults\n"); - } - } + { + g_strEmuInfo.Language = GetLanguageFromINI(); + if ( g_strEmuInfo.Language == 0 ) + { + g_strEmuInfo.Language = DetectLanguage(); + DebugWriteA("Autoselect language: %d\n", g_strEmuInfo.Language); + } + g_hResourceDLL = LoadLanguageDLL(g_strEmuInfo.Language); // HACK: it's theoretically not safe to call LoadLibraryEx from DllMain... --rabid + if( g_hResourceDLL == NULL ) + { + g_strEmuInfo.Language = 0; + g_hResourceDLL = hModule; + DebugWriteA("couldn't load language DLL, falling back to defaults\n"); + } + } #else - DebugWriteA(" (compiled in ANSI mode, language detection DISABLED.)\n"); - g_strEmuInfo.Language = 0; - g_hResourceDLL = hModule; + DebugWriteA(" (compiled in ANSI mode, language detection DISABLED.)\n"); + g_strEmuInfo.Language = 0; + g_hResourceDLL = hModule; #endif // #ifndef _UNICODE - InitializeCriticalSection( &g_critical ); - break; + InitializeCriticalSection( &g_critical ); + break; - case DLL_THREAD_ATTACH: - break; + case DLL_THREAD_ATTACH: + break; - case DLL_THREAD_DETACH: - break; + case DLL_THREAD_DETACH: + break; - case DLL_PROCESS_DETACH: - //CloseDLL(); - if (g_hResourceDLL != g_strEmuInfo.hinst) - FreeLibrary(g_hResourceDLL); // HACK: it's not safe to call FreeLibrary from DllMain... but screw it + case DLL_PROCESS_DETACH: + //CloseDLL(); + if (g_hResourceDLL != g_strEmuInfo.hinst) + FreeLibrary(g_hResourceDLL); // HACK: it's not safe to call FreeLibrary from DllMain... but screw it - DebugWriteA("*** DLL Detach\n"); + DebugWriteA("*** DLL Detach\n"); - CloseDebugFile(); // Moved here from CloseDll - DeleteCriticalSection( &g_critical ); + CloseDebugFile(); // Moved here from CloseDll + DeleteCriticalSection( &g_critical ); - // Moved here from CloseDll... Heap is created from DllMain, - // and now it's destroyed by DllMain... just safer code --rabid - if( g_hHeap != NULL ) - { - HeapDestroy( g_hHeap ); - g_hHeap = NULL; - } - break; - } + // Moved here from CloseDll... Heap is created from DllMain, + // and now it's destroyed by DllMain... just safer code --rabid + if( g_hHeap != NULL ) + { + HeapDestroy( g_hHeap ); + g_hHeap = NULL; + } + break; + } return TRUE; } @@ -148,17 +148,17 @@ BOOL APIENTRY DllMain( HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpRe input: a pointer to a PLUGIN_INFO stucture that needs to be filled by the function. (see def above) output: none -*******************************************************************/ +*******************************************************************/ EXPORT void CALL GetDllInfo ( PLUGIN_INFO* PluginInfo ) { - DebugWriteA("CALLED: GetDllInfo\n"); + DebugWriteA("CALLED: GetDllInfo\n"); #ifdef _DEBUG - sprintf(PluginInfo->Name,"N-Rage For PJ64 (Debug): %s",VER_FILE_VERSION_STR); + sprintf(PluginInfo->Name,"N-Rage For PJ64 (Debug): %s",VER_FILE_VERSION_STR); #else - sprintf(PluginInfo->Name,"N-Rage For PJ64: %s",VER_FILE_VERSION_STR); + sprintf(PluginInfo->Name,"N-Rage For PJ64: %s",VER_FILE_VERSION_STR); #endif - PluginInfo->Type = PLUGIN_TYPE_CONTROLLER; - PluginInfo->Version = SPECS_VERSION; + PluginInfo->Type = PLUGIN_TYPE_CONTROLLER; + PluginInfo->Version = SPECS_VERSION; } /****************************************************************** @@ -167,29 +167,29 @@ EXPORT void CALL GetDllInfo ( PLUGIN_INFO* PluginInfo ) to give further information about the DLL. input: a handle to the window that calls this function output: none -*******************************************************************/ +*******************************************************************/ EXPORT void CALL DllAbout ( HWND hParent ) { - DebugWriteA("CALLED: DllAbout\n"); - TCHAR tszTitle[DEFAULT_BUFFER], tszTranslator[DEFAULT_BUFFER]; + DebugWriteA("CALLED: DllAbout\n"); + TCHAR tszTitle[DEFAULT_BUFFER], tszTranslator[DEFAULT_BUFFER]; - LoadString( g_hResourceDLL, IDS_DLG_ABOUT_TITLE, tszTitle, DEFAULT_BUFFER ); + LoadString( g_hResourceDLL, IDS_DLG_ABOUT_TITLE, tszTitle, DEFAULT_BUFFER ); - TCHAR szText[DEFAULT_BUFFER * 4] = _T(VER_FILE_DESCRIPTION_STR) _T("\n\n") \ - _T("Visit my site for support: >>http://go.to/nrage<<\n\n") \ - _T("Version ") VER_FILE_VERSION_STR _T(" (") _T(__DATE__) _T(")\n") \ - _T("Done by N-Rage\n") \ - _T("\n") \ - _T(" - - - - -\n") \ - _T("Transferpak emulation done by MadManMarkAu\n") \ - _T("Cleanup, tweaks, and language support by RabidDeity\n"); + TCHAR szText[DEFAULT_BUFFER * 4] = _T(VER_FILE_DESCRIPTION_STR) _T("\n\n") \ + _T("Visit my site for support: >>http://go.to/nrage<<\n\n") \ + _T("Version ") VER_FILE_VERSION_STR _T(" (") _T(__DATE__) _T(")\n") \ + _T("Done by N-Rage\n") \ + _T("\n") \ + _T(" - - - - -\n") \ + _T("Transferpak emulation done by MadManMarkAu\n") \ + _T("Cleanup, tweaks, and language support by RabidDeity\n"); - LoadString( g_hResourceDLL, IDS_DLG_ABOUT, tszTranslator, DEFAULT_BUFFER ); + LoadString( g_hResourceDLL, IDS_DLG_ABOUT, tszTranslator, DEFAULT_BUFFER ); - _tcscat(szText, tszTranslator); + _tcscat(szText, tszTranslator); - MessageBox( hParent, szText, tszTitle, MB_OK | MB_ICONINFORMATION); - return; + MessageBox( hParent, szText, tszTitle, MB_OK | MB_ICONINFORMATION); + return; } /****************************************************************** @@ -198,95 +198,95 @@ EXPORT void CALL DllAbout ( HWND hParent ) to allow the user to configure the dll input: a handle to the window that calls this function output: none -*******************************************************************/ +*******************************************************************/ EXPORT void CALL DllConfig ( HWND hParent ) { - DebugWriteA("CALLED: DllConfig\n"); - static bool bInitCC = false; - if( !prepareHeap()) - return; + DebugWriteA("CALLED: DllConfig\n"); + static bool bInitCC = false; + if( !prepareHeap()) + return; - if( !g_pDIHandle ) - { - if( InitDirectInput( hParent )) - { - EnterCriticalSection ( &g_critical ); - InitMouse(); - g_pDIHandle->EnumDevices( DI8DEVCLASS_ALL, EnumMakeDeviceList, NULL, DIEDFL_ATTACHEDONLY ); - LeaveCriticalSection ( &g_critical ); - DebugWriteA("InitDirectInput run in DllConfig, g_nDevices=%d\n", g_nDevices); - } - } + if( !g_pDIHandle ) + { + if( InitDirectInput( hParent )) + { + EnterCriticalSection ( &g_critical ); + InitMouse(); + g_pDIHandle->EnumDevices( DI8DEVCLASS_ALL, EnumMakeDeviceList, NULL, DIEDFL_ATTACHEDONLY ); + LeaveCriticalSection ( &g_critical ); + DebugWriteA("InitDirectInput run in DllConfig, g_nDevices=%d\n", g_nDevices); + } + } - if (g_hXInputDLL == NULL) - { - if (!InitXinput()) - { - //TODO Disable ability to set XInput - //TODO Make XInput and DirectInput settings same page - } - } + if (g_hXInputDLL == NULL) + { + if (!InitXinput()) + { + //TODO Disable ability to set XInput + //TODO Make XInput and DirectInput settings same page + } + } - if( g_pDIHandle && !g_bConfiguring ) - { - g_bConfiguring = true; - if( !bInitCC ) - { - INITCOMMONCONTROLSEX ccCtrls = { sizeof(INITCOMMONCONTROLSEX), - ICC_BAR_CLASSES | ICC_TAB_CLASSES | ICC_LISTVIEW_CLASSES }; - InitCommonControlsEx( &ccCtrls ); // needed for TrackBars & Tabs - } - - EnterCriticalSection( &g_critical ); - if( g_sysMouse.didHandle ) - { // unlock mouse while configuring - g_sysMouse.didHandle->SetCooperativeLevel( g_strEmuInfo.hMainWindow, DIB_DEVICE ); - g_sysMouse.didHandle->Acquire(); - } - LeaveCriticalSection( &g_critical ); + if( g_pDIHandle && !g_bConfiguring ) + { + g_bConfiguring = true; + if( !bInitCC ) + { + INITCOMMONCONTROLSEX ccCtrls = { sizeof(INITCOMMONCONTROLSEX), + ICC_BAR_CLASSES | ICC_TAB_CLASSES | ICC_LISTVIEW_CLASSES }; + InitCommonControlsEx( &ccCtrls ); // needed for TrackBars & Tabs + } - int iOK = DialogBox(g_hResourceDLL, MAKEINTRESOURCE(IDD_MAINCFGDIALOG), hParent, (DLGPROC)MainDlgProc); + EnterCriticalSection( &g_critical ); + if( g_sysMouse.didHandle ) + { // unlock mouse while configuring + g_sysMouse.didHandle->SetCooperativeLevel( g_strEmuInfo.hMainWindow, DIB_DEVICE ); + g_sysMouse.didHandle->Acquire(); + } + LeaveCriticalSection( &g_critical ); - // If we go into the dialog box, and the user navigates to the Rumble window, our FF device can get unacquired. - // So let's reinit them now if we're running, just to be safe --rabid - if( g_bRunning ) - { - EnterCriticalSection( &g_critical ); - // PrepareInputDevices resets g_bExclusiveMouse to false if no mouse keys are bound, and the only way to - // re-enable exclusive mouse is with a shortcut. - // This is undesirable behavior, but it beats the alternative (and we REALLY need to re-init FF devices here) - PrepareInputDevices(); - if (iOK) - { - InitiatePaks( false ); // only re-init the mempaks and such if the user clicked Save or Use - } - - if( g_sysMouse.didHandle ) - { - if ( g_bExclusiveMouse ) - { // if we have exclusive mouse, we need to relock mouse after closing the config - g_sysMouse.didHandle->SetCooperativeLevel( g_strEmuInfo.hMainWindow, DIB_MOUSE ); - g_sysMouse.didHandle->Acquire(); - if (g_strEmuInfo.fDisplayShortPop) - { - LoadString( g_hResourceDLL, IDS_POP_MOUSELOCKED, g_pszThreadMessage, ARRAYSIZE(g_pszThreadMessage) ); - // HWND hMessage = CreateWindowEx( WS_EX_NOPARENTNOTIFY | WS_EX_STATICEDGE | WS_EX_TOPMOST, _T("STATIC"), pszMessage, WS_CHILD | WS_VISIBLE, 10, 10, 200, 30, g_strEmuInfo.hMainWindow, NULL, g_strEmuInfo.hinst, NULL ); - // SetTimer( hMessage, TIMER_MESSAGEWINDOW, 2000, MessageTimer ); - CreateThread(NULL, 0, MsgThreadFunction, g_pszThreadMessage, 0, NULL); - } - } - else - { - g_sysMouse.didHandle->SetCooperativeLevel( g_strEmuInfo.hMainWindow, DIB_KEYBOARD ); - g_sysMouse.didHandle->Acquire(); - } - } - LeaveCriticalSection( &g_critical ); - } + int iOK = DialogBox(g_hResourceDLL, MAKEINTRESOURCE(IDD_MAINCFGDIALOG), hParent, (DLGPROC)MainDlgProc); - g_bConfiguring = false; - } - return; + // If we go into the dialog box, and the user navigates to the Rumble window, our FF device can get unacquired. + // So let's reinit them now if we're running, just to be safe --rabid + if( g_bRunning ) + { + EnterCriticalSection( &g_critical ); + // PrepareInputDevices resets g_bExclusiveMouse to false if no mouse keys are bound, and the only way to + // re-enable exclusive mouse is with a shortcut. + // This is undesirable behavior, but it beats the alternative (and we REALLY need to re-init FF devices here) + PrepareInputDevices(); + if (iOK) + { + InitiatePaks( false ); // only re-init the mempaks and such if the user clicked Save or Use + } + + if( g_sysMouse.didHandle ) + { + if ( g_bExclusiveMouse ) + { // if we have exclusive mouse, we need to relock mouse after closing the config + g_sysMouse.didHandle->SetCooperativeLevel( g_strEmuInfo.hMainWindow, DIB_MOUSE ); + g_sysMouse.didHandle->Acquire(); + if (g_strEmuInfo.fDisplayShortPop) + { + LoadString( g_hResourceDLL, IDS_POP_MOUSELOCKED, g_pszThreadMessage, ARRAYSIZE(g_pszThreadMessage) ); + // HWND hMessage = CreateWindowEx( WS_EX_NOPARENTNOTIFY | WS_EX_STATICEDGE | WS_EX_TOPMOST, _T("STATIC"), pszMessage, WS_CHILD | WS_VISIBLE, 10, 10, 200, 30, g_strEmuInfo.hMainWindow, NULL, g_strEmuInfo.hinst, NULL ); + // SetTimer( hMessage, TIMER_MESSAGEWINDOW, 2000, MessageTimer ); + CreateThread(NULL, 0, MsgThreadFunction, g_pszThreadMessage, 0, NULL); + } + } + else + { + g_sysMouse.didHandle->SetCooperativeLevel( g_strEmuInfo.hMainWindow, DIB_KEYBOARD ); + g_sysMouse.didHandle->Acquire(); + } + } + LeaveCriticalSection( &g_critical ); + } + + g_bConfiguring = false; + } + return; } /****************************************************************** @@ -295,11 +295,11 @@ EXPORT void CALL DllConfig ( HWND hParent ) to allow the user to test the dll input: a handle to the window that calls this function output: none -*******************************************************************/ +*******************************************************************/ EXPORT void CALL DllTest ( HWND hParent ) { - DebugWriteA("CALLED: DllTest\n"); - return; + DebugWriteA("CALLED: DllTest\n"); + return; } // It's easier to maintain one version of this, as not much really changes @@ -307,12 +307,12 @@ EXPORT void CALL DllTest ( HWND hParent ) /****************************************************************** Function: InitiateControllers - Purpose: This function initialises how each of the controllers + Purpose: This function initialises how each of the controllers should be handled. - input: - A controller structure that needs to be filled for - the emulator to know how to handle each controller. + input: - A controller structure that needs to be filled for + the emulator to know how to handle each controller. output: none -*******************************************************************/ +*******************************************************************/ EXPORT void CALL InitiateControllers( #if (SPECS_VERSION < 0x0101) void * hMainWindow, CONTROL Controls[4] @@ -323,9 +323,9 @@ EXPORT void CALL InitiateControllers( #endif ) { - DebugWriteA("CALLED: InitiateControllers\n"); - if( !prepareHeap()) - return; + DebugWriteA("CALLED: InitiateControllers\n"); + if( !prepareHeap()) + return; #if (SPECS_VERSION < 0x0101) g_strEmuInfo.controllers = &Controls[0]; @@ -343,146 +343,146 @@ EXPORT void CALL InitiateControllers( // g_strEmuInfo.MemoryBswaped = ControlInfo->MemoryBswaped; // g_strEmuInfo.HEADER = ControlInfo->HEADER; #endif - // UNDONE: Instead of just storing the header, figure out what ROM we're running and save that information somewhere + // UNDONE: Instead of just storing the header, figure out what ROM we're running and save that information somewhere - // The emulator expects us to tell what controllers are plugged in and what their paks are at this point. + // The emulator expects us to tell what controllers are plugged in and what their paks are at this point. - if( !g_pDIHandle ) // if we don't have a directinput handle, we need to make one, attach it to the main window (so it will die if our emulator dies), and enumerate devices - { - if( InitDirectInput( g_strEmuInfo.hMainWindow )) - { - EnterCriticalSection ( &g_critical ); - InitMouse(); - g_pDIHandle->EnumDevices( DI8DEVCLASS_ALL, EnumMakeDeviceList, NULL, DIEDFL_ATTACHEDONLY ); - LeaveCriticalSection ( &g_critical ); - DebugWriteA("InitDirectInput run in InitiateControllers, g_nDevices=%d\n", g_nDevices); - } - else - return; - } + if( !g_pDIHandle ) // if we don't have a directinput handle, we need to make one, attach it to the main window (so it will die if our emulator dies), and enumerate devices + { + if( InitDirectInput( g_strEmuInfo.hMainWindow )) + { + EnterCriticalSection ( &g_critical ); + InitMouse(); + g_pDIHandle->EnumDevices( DI8DEVCLASS_ALL, EnumMakeDeviceList, NULL, DIEDFL_ATTACHEDONLY ); + LeaveCriticalSection ( &g_critical ); + DebugWriteA("InitDirectInput run in InitiateControllers, g_nDevices=%d\n", g_nDevices); + } + else + return; + } - if (g_hXInputDLL == NULL) - { - if (!InitXinput()) - { - //TODO Disable ability to set XInput - //TODO Make XInput and DirectInput settings same page - } - } + if (g_hXInputDLL == NULL) + { + if (!InitXinput()) + { + //TODO Disable ability to set XInput + //TODO Make XInput and DirectInput settings same page + } + } - //To handle XInput controllers better, we need to set id to 0 - iXinputControlId = 0; + //To handle XInput controllers better, we need to set id to 0 + iXinputControlId = 0; - int iDevice; + int iDevice; - EnterCriticalSection( &g_critical ); + EnterCriticalSection( &g_critical ); - // ZeroMemory( g_apFFDevice, sizeof(g_apFFDevice) ); // NO, we'll reinit the existing reference if it's already loaded - // ZeroMemory( g_apdiEffect, sizeof(g_apdiEffect) ); // NO, we'll release it with CloseControllerPak + // ZeroMemory( g_apFFDevice, sizeof(g_apFFDevice) ); // NO, we'll reinit the existing reference if it's already loaded + // ZeroMemory( g_apdiEffect, sizeof(g_apdiEffect) ); // NO, we'll release it with CloseControllerPak - for( int i = 3; i >= 0; i-- ) - { - SaveControllerPak( i ); - CloseControllerPak( i ); - // freePakData( &g_pcControllers[i] ); // already called by CloseControllerPak - freeModifiers( &g_pcControllers[i] ); - SetControllerDefaults( &g_pcControllers[i] ); - } + for( int i = 3; i >= 0; i-- ) + { + SaveControllerPak( i ); + CloseControllerPak( i ); + // freePakData( &g_pcControllers[i] ); // already called by CloseControllerPak + freeModifiers( &g_pcControllers[i] ); + SetControllerDefaults( &g_pcControllers[i] ); + } - g_pcControllers[0].fPlugged = true; + g_pcControllers[0].fPlugged = true; - if (! LoadConfigFromINI() ) - { - DebugWriteA("\tINI load failed, loading defaults from resource\n"); - for ( int i = 0; i < 4; i++ ) - LoadProfileFromResource( i, false ); - LoadShortcutsFromResource(false); - } + if (! LoadConfigFromINI() ) + { + DebugWriteA("\tINI load failed, loading defaults from resource\n"); + for ( int i = 0; i < 4; i++ ) + LoadProfileFromResource( i, false ); + LoadShortcutsFromResource(false); + } - // Init: Find force-feedback devices and init - for( int i = 0; i < 4; i++ ) - { - DebugWriteA("Controller %d: ", i+1); + // Init: Find force-feedback devices and init + for( int i = 0; i < 4; i++ ) + { + DebugWriteA("Controller %d: ", i+1); - if( g_pcControllers[i].fPlugged ) - { - if (g_pcControllers[i].fXInput) - { - InitiateXInputController(&g_pcControllers[i].xiController, i); - continue; - } + if( g_pcControllers[i].fPlugged ) + { + if (g_pcControllers[i].fXInput) + { + InitiateXInputController(&g_pcControllers[i].xiController, i); + continue; + } - // Search for right Controller - iDevice = FindDeviceinList( g_pcControllers[i].guidFFDevice ); - if( iDevice != -1 && g_devList[iDevice].bEffType ) - { - DebugWriteA("rumble device set, "); - } - else // we couldn't find the device specified in the INI file, or it was already null - { - g_pcControllers[i].guidFFDevice = GUID_NULL; - DebugWriteA("no rumble device/effect type set, "); - } + // Search for right Controller + iDevice = FindDeviceinList( g_pcControllers[i].guidFFDevice ); + if( iDevice != -1 && g_devList[iDevice].bEffType ) + { + DebugWriteA("rumble device set, "); + } + else // we couldn't find the device specified in the INI file, or it was already null + { + g_pcControllers[i].guidFFDevice = GUID_NULL; + DebugWriteA("no rumble device/effect type set, "); + } - if( g_pcControllers[i].nModifiers > 0) - SetModifier( &g_pcControllers[i] ); - g_iFirstController = i; - DebugWriteA("plugged in, with paktype %d, ", g_pcControllers[i].PakType); - DebugWriteA("RawMode is %d\n", g_pcControllers[i].fRawData); - } - else - { - DebugWriteA("unplugged\n"); - freePakData( &g_pcControllers[i] ); // we don't need to do this again, but there's not much overhead so I'll leave it --rabid - freeModifiers( &g_pcControllers[i] ); - } - } + if( g_pcControllers[i].nModifiers > 0) + SetModifier( &g_pcControllers[i] ); + g_iFirstController = i; + DebugWriteA("plugged in, with paktype %d, ", g_pcControllers[i].PakType); + DebugWriteA("RawMode is %d\n", g_pcControllers[i].fRawData); + } + else + { + DebugWriteA("unplugged\n"); + freePakData( &g_pcControllers[i] ); // we don't need to do this again, but there's not much overhead so I'll leave it --rabid + freeModifiers( &g_pcControllers[i] ); + } + } - PrepareInputDevices(); + PrepareInputDevices(); - if( g_bExclusiveMouse ) - { - // g_sysMouse.didHandle->Unacquire(); - // g_sysMouse.didHandle->SetCooperativeLevel( g_strEmuInfo.hMainWindow, DIB_MOUSE ); // PrepareInputDevices does this. - g_sysMouse.didHandle->Acquire(); - } + if( g_bExclusiveMouse ) + { + // g_sysMouse.didHandle->Unacquire(); + // g_sysMouse.didHandle->SetCooperativeLevel( g_strEmuInfo.hMainWindow, DIB_MOUSE ); // PrepareInputDevices does this. + g_sysMouse.didHandle->Acquire(); + } - InitiatePaks( true ); + InitiatePaks( true ); - g_strEmuInfo.fInitialisedPlugin = true; + g_strEmuInfo.fInitialisedPlugin = true; - LeaveCriticalSection( &g_critical ); + LeaveCriticalSection( &g_critical ); - FillControls(g_strEmuInfo.controllers); - return; + FillControls(g_strEmuInfo.controllers); + return; } // end InitiateControllers /****************************************************************** Function: RomOpen - Purpose: This function is called when a rom is open. (from the + Purpose: This function is called when a rom is open. (from the emulation thread) input: none output: none -*******************************************************************/ +*******************************************************************/ EXPORT void CALL RomOpen (void) { - DebugWriteA("CALLED: RomOpen\n"); + DebugWriteA("CALLED: RomOpen\n"); - //XInputEnable( TRUE ); // enables xinput --tecnicors + //XInputEnable( TRUE ); // enables xinput --tecnicors - if( !g_strEmuInfo.fInitialisedPlugin ) - { - ErrorMessage(IDS_ERR_NOINIT, 0, false); - return; - } + if( !g_strEmuInfo.fInitialisedPlugin ) + { + ErrorMessage(IDS_ERR_NOINIT, 0, false); + return; + } - EnterCriticalSection( &g_critical ); - // re-init our paks and shortcuts - InitiatePaks( true ); - // LoadShortcuts( &g_scShortcuts ); WHY are we loading shortcuts again?? Should already be loaded! - LeaveCriticalSection( &g_critical ); - g_bRunning = true; - return; + EnterCriticalSection( &g_critical ); + // re-init our paks and shortcuts + InitiatePaks( true ); + // LoadShortcuts( &g_scShortcuts ); WHY are we loading shortcuts again?? Should already be loaded! + LeaveCriticalSection( &g_critical ); + g_bRunning = true; + return; } /****************************************************************** @@ -490,300 +490,300 @@ EXPORT void CALL RomOpen (void) Purpose: This function is called when a rom is closed. input: none output: none -*******************************************************************/ +*******************************************************************/ EXPORT void CALL RomClosed(void) { - int i; + int i; - //XInputEnable( FALSE ); // disables xinput --tecnicors + //XInputEnable( FALSE ); // disables xinput --tecnicors - DebugWriteA("CALLED: RomClosed\n"); - EnterCriticalSection( &g_critical ); + DebugWriteA("CALLED: RomClosed\n"); + EnterCriticalSection( &g_critical ); - if (g_sysMouse.didHandle) - { - g_sysMouse.didHandle->Unacquire(); - g_sysMouse.didHandle->SetCooperativeLevel(g_strEmuInfo.hMainWindow, DIB_KEYBOARD); // unlock the mouse, just in case - } + if (g_sysMouse.didHandle) + { + g_sysMouse.didHandle->Unacquire(); + g_sysMouse.didHandle->SetCooperativeLevel(g_strEmuInfo.hMainWindow, DIB_KEYBOARD); // unlock the mouse, just in case + } - for( i = 0; i < ARRAYSIZE(g_pcControllers); ++i ) - { - if( g_pcControllers[i].pPakData ) - { - SaveControllerPak( i ); - CloseControllerPak( i ); - } - // freePakData( &g_pcControllers[i] ); already done by CloseControllerPak --rabid - // DON'T free the modifiers! -// ZeroMemory( &g_pcControllers[i], sizeof(CONTROLLER) ); - } + for( i = 0; i < ARRAYSIZE(g_pcControllers); ++i ) + { + if( g_pcControllers[i].pPakData ) + { + SaveControllerPak( i ); + CloseControllerPak( i ); + } + // freePakData( &g_pcControllers[i] ); already done by CloseControllerPak --rabid + // DON'T free the modifiers! +// ZeroMemory( &g_pcControllers[i], sizeof(CONTROLLER) ); + } - for( i = 0; i < ARRAYSIZE( g_apdiEffect ); ++i ) - ReleaseEffect( g_apdiEffect[i] ); - ZeroMemory( g_apdiEffect, sizeof(g_apdiEffect) ); + for( i = 0; i < ARRAYSIZE( g_apdiEffect ); ++i ) + ReleaseEffect( g_apdiEffect[i] ); + ZeroMemory( g_apdiEffect, sizeof(g_apdiEffect) ); - g_bRunning = false; - LeaveCriticalSection( &g_critical ); - - return; + g_bRunning = false; + LeaveCriticalSection( &g_critical ); + + return; } /****************************************************************** Function: GetKeys Purpose: To get the current state of the controllers buttons. input: - Controller Number (0 to 3) - - A pointer to a BUTTONS structure to be filled with - the controller state. + - A pointer to a BUTTONS structure to be filled with + the controller state. output: none -*******************************************************************/ +*******************************************************************/ EXPORT void CALL GetKeys(int Control, BUTTONS * Keys ) { #ifdef ENABLE_RAWPAK_DEBUG - DebugWriteA("CALLED: GetKeys\n"); + DebugWriteA("CALLED: GetKeys\n"); #endif - if( g_bConfiguring || (!g_pcControllers[Control].bBackgroundInput && GetForegroundWindow() != g_strEmuInfo.hMainWindow) ) - Keys->Value = 0; - else - { - EnterCriticalSection( &g_critical ); - - if( g_pcControllers[Control].fPlugged ) - { - if (Control == g_iFirstController ) - { - GetDeviceDatas(); - CheckShortcuts(); - } - if( g_pcControllers[Control].fXInput ) // reads the xinput controller keys, if connected --tecnicors - GetXInputControllerKeys( Control, &Keys->Value ); - else - GetNControllerInput( Control, &Keys->Value ); - } - LeaveCriticalSection( &g_critical ); - } - return; + if( g_bConfiguring || (!g_pcControllers[Control].bBackgroundInput && GetForegroundWindow() != g_strEmuInfo.hMainWindow) ) + Keys->Value = 0; + else + { + EnterCriticalSection( &g_critical ); + + if( g_pcControllers[Control].fPlugged ) + { + if (Control == g_iFirstController ) + { + GetDeviceDatas(); + CheckShortcuts(); + } + if( g_pcControllers[Control].fXInput ) // reads the xinput controller keys, if connected --tecnicors + GetXInputControllerKeys( Control, &Keys->Value ); + else + GetNControllerInput( Control, &Keys->Value ); + } + LeaveCriticalSection( &g_critical ); + } + return; } /****************************************************************** Function: ControllerCommand - Purpose: To process the raw data that has just been sent to a + Purpose: To process the raw data that has just been sent to a specific controller. - input: - Controller Number (0 to 3) and -1 signalling end of + input: - Controller Number (0 to 3) and -1 signalling end of processing the pif ram. - - Pointer of data to be processed. + - Pointer of data to be processed. output: none - + note: This function is only needed if the DLL is allowing raw data. the data that is being processed looks like this: - initilize controller: 01 03 00 FF FF FF + initilize controller: 01 03 00 FF FF FF read controller: 01 04 01 FF FF FF FF *******************************************************************/ EXPORT void CALL ControllerCommand( int Control, BYTE * Command) { - // We don't need to use this because it will be echoed immediately afterwards - // by a call to ReadController - return; + // We don't need to use this because it will be echoed immediately afterwards + // by a call to ReadController + return; } /****************************************************************** Function: ReadController Purpose: To process the raw data in the pif ram that is about to be read. - input: - Controller Number (0 to 3) and -1 signalling end of + input: - Controller Number (0 to 3) and -1 signalling end of processing the pif ram. - - Pointer of data to be processed. - output: none + - Pointer of data to be processed. + output: none note: This function is only needed if the DLL is allowing raw data. *******************************************************************/ EXPORT void CALL ReadController( int Control, BYTE * Command ) { #ifdef ENABLE_RAWPAK_DEBUG - DebugWriteA("CALLED: ReadController\n"); + DebugWriteA("CALLED: ReadController\n"); #endif - if( Control == -1 ) - return; + if( Control == -1 ) + return; - EnterCriticalSection( &g_critical ); + EnterCriticalSection( &g_critical ); - if( !g_pcControllers[Control].fPlugged ) - { - Command[1] |= RD_ERROR; - LeaveCriticalSection( &g_critical ); - return; - } + if( !g_pcControllers[Control].fPlugged ) + { + Command[1] |= RD_ERROR; + LeaveCriticalSection( &g_critical ); + return; + } - - switch( Command[2] ) - { - case RD_RESETCONTROLLER: - WriteDatasA( "ResetController-PreProcessing", Control, Command, 0); - case RD_GETSTATUS: - // expected: controller gets 1 byte (command), controller sends back 3 bytes - // should be: Command[0] == 0x01 - // Command[1] == 0x03 + + switch( Command[2] ) + { + case RD_RESETCONTROLLER: + WriteDatasA( "ResetController-PreProcessing", Control, Command, 0); + case RD_GETSTATUS: + // expected: controller gets 1 byte (command), controller sends back 3 bytes + // should be: Command[0] == 0x01 + // Command[1] == 0x03 #ifdef ENABLE_RAWPAK_DEBUG - WriteDatasA( "GetStatus-PreProcessing", Control, Command, 0); + WriteDatasA( "GetStatus-PreProcessing", Control, Command, 0); #endif - Command[3] = RD_GAMEPAD | RD_ABSOLUTE; - Command[4] = RD_NOEEPROM; + Command[3] = RD_GAMEPAD | RD_ABSOLUTE; + Command[4] = RD_NOEEPROM; - if (g_pcControllers[Control].fN64Mouse) // Is Controller a mouse? - Command[3] = RD_RELATIVE; + if (g_pcControllers[Control].fN64Mouse) // Is Controller a mouse? + Command[3] = RD_RELATIVE; - if( g_pcControllers[Control].fPakInitialized && g_pcControllers[Control].pPakData ) - { - if( *(BYTE*)g_pcControllers[Control].pPakData == PAK_ADAPTOID ) - { - Command[5] = GetAdaptoidStatus( Control ); + if( g_pcControllers[Control].fPakInitialized && g_pcControllers[Control].pPakData ) + { + if( *(BYTE*)g_pcControllers[Control].pPakData == PAK_ADAPTOID ) + { + Command[5] = GetAdaptoidStatus( Control ); - if( Command[5] & RD_NOTINITIALIZED ) - ((ADAPTOIDPAK*)g_pcControllers[Control].pPakData)->fRumblePak = true; - } - else - { - Command[5] = ( *(BYTE*)g_pcControllers[Control].pPakData != PAK_NONE ) ? RD_PLUGIN : RD_NOPLUGIN; - if( g_pcControllers[Control].fPakCRCError ) - { - Command[5] = Command[5] | RD_ADDRCRCERR; - g_pcControllers[Control].fPakCRCError = false; - } - } - } - else - { - if( !g_bConfiguring && InitControllerPak( Control ) && g_pcControllers[Control].pPakData ) - { - g_pcControllers[Control].fPakInitialized = true; + if( Command[5] & RD_NOTINITIALIZED ) + ((ADAPTOIDPAK*)g_pcControllers[Control].pPakData)->fRumblePak = true; + } + else + { + Command[5] = ( *(BYTE*)g_pcControllers[Control].pPakData != PAK_NONE ) ? RD_PLUGIN : RD_NOPLUGIN; + if( g_pcControllers[Control].fPakCRCError ) + { + Command[5] = Command[5] | RD_ADDRCRCERR; + g_pcControllers[Control].fPakCRCError = false; + } + } + } + else + { + if( !g_bConfiguring && InitControllerPak( Control ) && g_pcControllers[Control].pPakData ) + { + g_pcControllers[Control].fPakInitialized = true; - if( *(BYTE*)g_pcControllers[Control].pPakData == PAK_ADAPTOID ) - Command[5] = GetAdaptoidStatus( Control ); - else - { - Command[5] = ( *(BYTE*)g_pcControllers[Control].pPakData ) ? RD_PLUGIN : RD_NOPLUGIN; - Command[5] = Command[5] | ( g_pcControllers[Control].fPakCRCError ? RD_ADDRCRCERR : 0 ); - } - } - else - Command[5] = RD_NOPLUGIN | RD_NOTINITIALIZED; - } + if( *(BYTE*)g_pcControllers[Control].pPakData == PAK_ADAPTOID ) + Command[5] = GetAdaptoidStatus( Control ); + else + { + Command[5] = ( *(BYTE*)g_pcControllers[Control].pPakData ) ? RD_PLUGIN : RD_NOPLUGIN; + Command[5] = Command[5] | ( g_pcControllers[Control].fPakCRCError ? RD_ADDRCRCERR : 0 ); + } + } + else + Command[5] = RD_NOPLUGIN | RD_NOTINITIALIZED; + } - if( g_pcControllers[Control].fPakCRCError ) - { - Command[5] = Command[5] | RD_ADDRCRCERR; - g_pcControllers[Control].fPakCRCError = false; - } + if( g_pcControllers[Control].fPakCRCError ) + { + Command[5] = Command[5] | RD_ADDRCRCERR; + g_pcControllers[Control].fPakCRCError = false; + } #ifdef ENABLE_RAWPAK_DEBUG - WriteDatasA( "GetStatus-PostProcessing", Control, Command, 0); - DebugWriteA( NULL ); + WriteDatasA( "GetStatus-PostProcessing", Control, Command, 0); + DebugWriteA( NULL ); #endif - break; + break; - case RD_READKEYS: - // expected: controller gets 1 byte (command), controller sends back 4 bytes - // should be: Command[0] == 0x01 - // Command[1] == 0x04 + case RD_READKEYS: + // expected: controller gets 1 byte (command), controller sends back 4 bytes + // should be: Command[0] == 0x01 + // Command[1] == 0x04 - if( g_bConfiguring || (!g_pcControllers[Control].bBackgroundInput && GetForegroundWindow() != g_strEmuInfo.hMainWindow) ) - Command[3] = Command[4] = Command[5] = Command[6] = 0; - else - { - if (Control == g_iFirstController ) - { - GetDeviceDatas(); - CheckShortcuts(); - } - if( g_pcControllers[Control].fXInput ) // reads xinput controller kesy, if connected --tecnicors - GetXInputControllerKeys( Control, (LPDWORD)&Command[3] ); - else - GetNControllerInput( Control, (DWORD*)&Command[3] ); - } - break; - case RD_READPAK: + if( g_bConfiguring || (!g_pcControllers[Control].bBackgroundInput && GetForegroundWindow() != g_strEmuInfo.hMainWindow) ) + Command[3] = Command[4] = Command[5] = Command[6] = 0; + else + { + if (Control == g_iFirstController ) + { + GetDeviceDatas(); + CheckShortcuts(); + } + if( g_pcControllers[Control].fXInput ) // reads xinput controller kesy, if connected --tecnicors + GetXInputControllerKeys( Control, (LPDWORD)&Command[3] ); + else + GetNControllerInput( Control, (DWORD*)&Command[3] ); + } + break; + case RD_READPAK: #ifdef ENABLE_RAWPAK_DEBUG - WriteDatasA( "ReadPak-PreProcessing", Control, Command, 0); + WriteDatasA( "ReadPak-PreProcessing", Control, Command, 0); #endif - if( g_pcControllers[Control].fPakInitialized ) - //Command[1] = Command[1] | ReadControllerPak( Control, &Command[3] ); - ReadControllerPak( Control, &Command[3] ); - else - { - DebugWriteA("Tried to read, but pak wasn't initialized!!\n"); - // InitControllerPak( Control ); - Command[1] |= RD_ERROR; - //ZeroMemory( &Command[5], 32 ); - } + if( g_pcControllers[Control].fPakInitialized ) + //Command[1] = Command[1] | ReadControllerPak( Control, &Command[3] ); + ReadControllerPak( Control, &Command[3] ); + else + { + DebugWriteA("Tried to read, but pak wasn't initialized!!\n"); + // InitControllerPak( Control ); + Command[1] |= RD_ERROR; + //ZeroMemory( &Command[5], 32 ); + } #ifdef ENABLE_RAWPAK_DEBUG - WriteDatasA( "ReadPak-PostProcessing", Control, Command, 0); - DebugWriteA( NULL ); + WriteDatasA( "ReadPak-PostProcessing", Control, Command, 0); + DebugWriteA( NULL ); #endif - break; - case RD_WRITEPAK: + break; + case RD_WRITEPAK: #ifdef ENABLE_RAWPAK_DEBUG - WriteDatasA( "WritePak-PreProcessing", Control, Command, 0); + WriteDatasA( "WritePak-PreProcessing", Control, Command, 0); #endif - if( g_pcControllers[Control].fPakInitialized ) - //Command[1] = Command[1] | WriteControllerPak( Control, &Command[3] ); - WriteControllerPak( Control, &Command[3] ); - else - { - DebugWriteA("Tried to write, but pak wasn't initialized! (paktype was %u)\n", g_pcControllers[Control].PakType); - // InitControllerPak( Control ); - Command[1] |= RD_ERROR; - } + if( g_pcControllers[Control].fPakInitialized ) + //Command[1] = Command[1] | WriteControllerPak( Control, &Command[3] ); + WriteControllerPak( Control, &Command[3] ); + else + { + DebugWriteA("Tried to write, but pak wasn't initialized! (paktype was %u)\n", g_pcControllers[Control].PakType); + // InitControllerPak( Control ); + Command[1] |= RD_ERROR; + } #ifdef ENABLE_PAK_WRITES_DEBUG - WriteDatasA( "WritePak-PostProcessing", Control, Command, 0); - DebugWriteA( NULL ); + WriteDatasA( "WritePak-PostProcessing", Control, Command, 0); + DebugWriteA( NULL ); #endif - break; - case RD_READEEPROM: - // Should be handled by the Emulator - WriteDatasA( "ReadEeprom-PreProcessing", Control, Command, 0); - WriteDatasA( "ReadEeprom-PostProcessing", Control, Command, 0); - DebugWriteA( NULL ); - break; - case RD_WRITEEPROM: - // Should be handled by the Emulator - WriteDatasA( "WriteEeprom-PreProcessing", Control, Command, 0); - WriteDatasA( "WriteEeprom-PostProcessing", Control, Command, 0); - DebugWriteA( NULL ); - break; - default: - // only accessible if the Emulator has bugs.. or maybe the Rom is flawed - WriteDatasA( "ReadController: Bad read", Control, Command, 0); - DebugWriteA( NULL ); - Command[1] = Command[1] | RD_ERROR; - } + break; + case RD_READEEPROM: + // Should be handled by the Emulator + WriteDatasA( "ReadEeprom-PreProcessing", Control, Command, 0); + WriteDatasA( "ReadEeprom-PostProcessing", Control, Command, 0); + DebugWriteA( NULL ); + break; + case RD_WRITEEPROM: + // Should be handled by the Emulator + WriteDatasA( "WriteEeprom-PreProcessing", Control, Command, 0); + WriteDatasA( "WriteEeprom-PostProcessing", Control, Command, 0); + DebugWriteA( NULL ); + break; + default: + // only accessible if the Emulator has bugs.. or maybe the Rom is flawed + WriteDatasA( "ReadController: Bad read", Control, Command, 0); + DebugWriteA( NULL ); + Command[1] = Command[1] | RD_ERROR; + } - LeaveCriticalSection( &g_critical ); - return; + LeaveCriticalSection( &g_critical ); + return; } /****************************************************************** Function: WM_KeyDown - Purpose: To pass the WM_KeyDown message from the emulator to the + Purpose: To pass the WM_KeyDown message from the emulator to the plugin. input: wParam and lParam of the WM_KEYDOWN message. output: none -*******************************************************************/ +*******************************************************************/ EXPORT void CALL WM_KeyDown( WPARAM wParam, LPARAM lParam ) { - return; + return; } /****************************************************************** Function: WM_KeyUp - Purpose: To pass the WM_KEYUP message from the emulator to the + Purpose: To pass the WM_KEYUP message from the emulator to the plugin. input: wParam and lParam of the WM_KEYDOWN message. output: none -*******************************************************************/ +*******************************************************************/ EXPORT void CALL WM_KeyUp( WPARAM wParam, LPARAM lParam ) { - return; + return; } /****************************************************************** @@ -792,92 +792,92 @@ EXPORT void CALL WM_KeyUp( WPARAM wParam, LPARAM lParam ) down allowing the dll to de-initialise. input: none output: none -*******************************************************************/ +*******************************************************************/ EXPORT void CALL CloseDLL (void) -{ // HACK: THIS IS BROKEN IN PJ64 1.6 (it calls CloseDLL too often) - DebugWriteA("CALLED: CloseDLL\n"); - if( g_bRunning ) - RomClosed(); - for( int i = 0; i < 4; i++ ) - { - freePakData( &g_pcControllers[i] ); - freeModifiers( &g_pcControllers[i] ); - } +{ // HACK: THIS IS BROKEN IN PJ64 1.6 (it calls CloseDLL too often) + DebugWriteA("CALLED: CloseDLL\n"); + if( g_bRunning ) + RomClosed(); + for( int i = 0; i < 4; i++ ) + { + freePakData( &g_pcControllers[i] ); + freeModifiers( &g_pcControllers[i] ); + } - // ZeroMemory( g_pcControllers, sizeof(g_pcControllers) ); // why zero the memory if we're just going to close down? - - FreeDirectInput(); - FreeXinput(); - return; + // ZeroMemory( g_pcControllers, sizeof(g_pcControllers) ); // why zero the memory if we're just going to close down? + + FreeDirectInput(); + FreeXinput(); + return; } // Prepare a global heap. Use P_malloc and P_free as wrappers to grab/release memory. bool prepareHeap() { - if( g_hHeap == NULL ) - g_hHeap = HeapCreate( 0, 4*1024, 0 ); - return (g_hHeap != NULL); + if( g_hHeap == NULL ) + g_hHeap = HeapCreate( 0, 4*1024, 0 ); + return (g_hHeap != NULL); } // Frees pakdata memory (called more often than you'd think). void freePakData( CONTROLLER *pcController ) { - if( pcController && pcController->pPakData ) - { - P_free( pcController->pPakData ); - pcController->pPakData = NULL; - } + if( pcController && pcController->pPakData ) + { + P_free( pcController->pPakData ); + pcController->pPakData = NULL; + } } // Frees modifier memory void freeModifiers( CONTROLLER *pcController ) { - if( pcController && pcController->pModifiers ) - { - pcController->nModifiers = 0; - P_free( pcController->pModifiers ); - pcController->pModifiers = NULL; - } + if( pcController && pcController->pModifiers ) + { + pcController->nModifiers = 0; + P_free( pcController->pModifiers ); + pcController->pModifiers = NULL; + } } // After enumerating DirectInput devices into g_devList, find a device by product name and counter int FindDeviceinList( const TCHAR *pszProductName, const BYTE bProductCounter, bool fFindSimilar ) { - if( !(*pszProductName) ) - return -1; + if( !(*pszProductName) ) + return -1; - int i = 0, iSimilar = -1, iExact = -1; - while(( i < ARRAYSIZE(g_devList) ) && ( iExact == -1 )) - { - if( !lstrcmp( g_devList[i].szProductName, pszProductName )) - { - if(( bProductCounter > 0 ) || ( iSimilar == -1 )) - iSimilar = i; - if( g_devList[i].bProductCounter == bProductCounter ) - iExact = i; - } - i++; - } + int i = 0, iSimilar = -1, iExact = -1; + while(( i < ARRAYSIZE(g_devList) ) && ( iExact == -1 )) + { + if( !lstrcmp( g_devList[i].szProductName, pszProductName )) + { + if(( bProductCounter > 0 ) || ( iSimilar == -1 )) + iSimilar = i; + if( g_devList[i].bProductCounter == bProductCounter ) + iExact = i; + } + i++; + } - if( fFindSimilar && ( iExact == -1 )) - iExact = iSimilar; + if( fFindSimilar && ( iExact == -1 )) + iExact = iSimilar; - return iExact; + return iExact; } // After enumerating DirectInput devices into g_devList, find a device by GUID. Finding similar devices is impossible. int FindDeviceinList( REFGUID rGUID ) { - if (rGUID == GUID_NULL ) - return -1; - int i = 0; - while( i < ARRAYSIZE(g_devList) ) - { - if ( IsEqualGUID(g_devList[i].guidInstance, rGUID) ) - return i; - i++; - } - return -1; + if (rGUID == GUID_NULL ) + return -1; + int i = 0; + while( i < ARRAYSIZE(g_devList) ) + { + if ( IsEqualGUID(g_devList[i].guidInstance, rGUID) ) + return i; + i++; + } + return -1; } // Let's initialize all plugged in controllers' paks. @@ -886,409 +886,409 @@ int FindDeviceinList( REFGUID rGUID ) // Rather counterintuitive. void InitiatePaks( bool bInitialize ) { - for( int i = 0; i < 4; i++ ) - { - if( g_pcControllers[i].fPlugged) - { - g_pcControllers[i].fPakCRCError = false; - - if( g_pcControllers[i].fRawData ) - { - if( !bInitialize ) - g_pcControllers[i].fPakInitialized = InitControllerPak( i ); - } - else - { // we only support "RAW mode" paks so this won't do much - ;//if( g_pcControllers[i].PakType == PAK_RUMBLE ) - // CreateEffectHandle( i, g_pcControllers[i].bRumbleTyp, g_pcControllers[i].bRumbleStrength ); - } - } - } + for( int i = 0; i < 4; i++ ) + { + if( g_pcControllers[i].fPlugged) + { + g_pcControllers[i].fPakCRCError = false; + + if( g_pcControllers[i].fRawData ) + { + if( !bInitialize ) + g_pcControllers[i].fPakInitialized = InitControllerPak( i ); + } + else + { // we only support "RAW mode" paks so this won't do much + ;//if( g_pcControllers[i].PakType == PAK_RUMBLE ) + // CreateEffectHandle( i, g_pcControllers[i].bRumbleTyp, g_pcControllers[i].bRumbleStrength ); + } + } + } } // This used to be "NotifyEmulator" which was supposed to tell the emulator if we changed the way it sees controllers. -// Unfortunately the spec doesn't work that way. Fixed the func and changed the func name to something that makes more sense. +// Unfortunately the spec doesn't work that way. Fixed the func and changed the func name to something that makes more sense. // FillControls takes a Controls array from InitiateControllers and fills it with what we know about whether -// a controller is plugged in, accepting raw data, and what type of pak is plugged in. +// a controller is plugged in, accepting raw data, and what type of pak is plugged in. void FillControls(CONTROL * Controls) { - for( int i = 4-1; i >= 0; i-- ) - { - if( g_pcControllers[i].fPlugged ) - { - Controls[i].Present = g_pcControllers[i].fPlugged; - Controls[i].RawData = g_pcControllers[i].fRawData; + for( int i = 4-1; i >= 0; i-- ) + { + if( g_pcControllers[i].fPlugged ) + { + Controls[i].Present = g_pcControllers[i].fPlugged; + Controls[i].RawData = g_pcControllers[i].fRawData; - switch( g_pcControllers[i].PakType ) - { - case PAK_MEM: - Controls[i].Plugin = PLUGIN_MEMPAK; - Controls[i].RawData = false; - break; - case PAK_RUMBLE: - Controls[i].Plugin = PLUGIN_RUMBLE_PAK; - break; - case PAK_TRANSFER: - Controls[i].Plugin = PLUGIN_TRANSFER_PAK; - break; - case PAK_VOICE: - Controls[i].Plugin = g_pcControllers[i].fRawData ? PLUGIN_RAW : PLUGIN_NONE; - break; - case PAK_ADAPTOID: - Controls[i].Plugin = g_pcControllers[i].fRawData ? PLUGIN_RAW : PLUGIN_NONE; - break; + switch( g_pcControllers[i].PakType ) + { + case PAK_MEM: + Controls[i].Plugin = PLUGIN_MEMPAK; + Controls[i].RawData = false; + break; + case PAK_RUMBLE: + Controls[i].Plugin = PLUGIN_RUMBLE_PAK; + break; + case PAK_TRANSFER: + Controls[i].Plugin = PLUGIN_TRANSFER_PAK; + break; + case PAK_VOICE: + Controls[i].Plugin = g_pcControllers[i].fRawData ? PLUGIN_RAW : PLUGIN_NONE; + break; + case PAK_ADAPTOID: + Controls[i].Plugin = g_pcControllers[i].fRawData ? PLUGIN_RAW : PLUGIN_NONE; + break; - case PAK_NONE: - default: - Controls[i].Plugin = PLUGIN_NONE; - } - } - else - { - Controls[i].Plugin = PLUGIN_NONE; - Controls[i].Present = false; - Controls[i].RawData = true; - } - } + case PAK_NONE: + default: + Controls[i].Plugin = PLUGIN_NONE; + } + } + else + { + Controls[i].Plugin = PLUGIN_NONE; + Controls[i].Present = false; + Controls[i].RawData = true; + } + } } // called after a poll to execute any shortcuts void CheckShortcuts() { - static bool bWasPressed[ sizeof(SHORTCUTSPL)/sizeof(BUTTON) ][4]; - static bool bMLWasPressed; // mouselock - bool bMatching = false; + static bool bWasPressed[ sizeof(SHORTCUTSPL)/sizeof(BUTTON) ][4]; + static bool bMLWasPressed; // mouselock + bool bMatching = false; - if ( g_bConfiguring || !g_bRunning ) - return; // we don't process shortcuts if we're in a config menu or are not running emulation + if ( g_bConfiguring || !g_bRunning ) + return; // we don't process shortcuts if we're in a config menu or are not running emulation - // just process if key wasnt pressed before - for ( int i = 0; i < 4; i++ ) // controllers - { - for( int j = 0; j < SC_TOTAL; j++ ) - { - bMatching = IsBtnPressed( g_scShortcuts.Player[i].aButtons[j] ); + // just process if key wasnt pressed before + for ( int i = 0; i < 4; i++ ) // controllers + { + for( int j = 0; j < SC_TOTAL; j++ ) + { + bMatching = IsBtnPressed( g_scShortcuts.Player[i].aButtons[j] ); - if( bMatching && !bWasPressed[j][i] ) - DoShortcut(i, j); + if( bMatching && !bWasPressed[j][i] ) + DoShortcut(i, j); - bWasPressed[j][i] = bMatching; - } - } + bWasPressed[j][i] = bMatching; + } + } - bMatching = IsBtnPressed( g_scShortcuts.bMouseLock ); + bMatching = IsBtnPressed( g_scShortcuts.bMouseLock ); - if( bMatching && !bMLWasPressed ) - DoShortcut(-1, -1); // controller -1 means do mouselock shortcut + if( bMatching && !bMLWasPressed ) + DoShortcut(-1, -1); // controller -1 means do mouselock shortcut - bMLWasPressed = bMatching; + bMLWasPressed = bMatching; } // Executes the shortcut iShortcut on controller iController // Special case: if iPlayer is -1, run the mouselock shortcut void DoShortcut( int iControl, int iShortcut ) { - DebugWriteA("Shortcut: %d %d\n", iControl, iShortcut); - TCHAR pszMessage[DEFAULT_BUFFER / 2] = TEXT(""); - bool bEjectFirst = false; + DebugWriteA("Shortcut: %d %d\n", iControl, iShortcut); + TCHAR pszMessage[DEFAULT_BUFFER / 2] = TEXT(""); + bool bEjectFirst = false; - if (iControl == -1) - { - EnterCriticalSection( &g_critical ); - if( g_sysMouse.didHandle ) - { - g_sysMouse.didHandle->Unacquire(); - if( g_bExclusiveMouse ) - { - g_sysMouse.didHandle->Unacquire(); - g_sysMouse.didHandle->SetCooperativeLevel( g_strEmuInfo.hMainWindow, DIB_KEYBOARD ); - g_sysMouse.didHandle->Acquire(); - LoadString( g_hResourceDLL, IDS_POP_MOUSEUNLOCKED, pszMessage, ARRAYSIZE(pszMessage) ); - } - else - { - g_sysMouse.didHandle->Unacquire(); - g_sysMouse.didHandle->SetCooperativeLevel( g_strEmuInfo.hMainWindow, DIB_MOUSE ); - g_sysMouse.didHandle->Acquire(); - LoadString( g_hResourceDLL, IDS_POP_MOUSELOCKED, pszMessage, ARRAYSIZE(pszMessage) ); - } - g_sysMouse.didHandle->Acquire(); - g_bExclusiveMouse = !g_bExclusiveMouse; - } - LeaveCriticalSection( &g_critical ); - } - else if( g_pcControllers[iControl].fPlugged ) - { - if( g_pcControllers[iControl].pPakData ) - { - SaveControllerPak( iControl ); - CloseControllerPak( iControl ); - } + if (iControl == -1) + { + EnterCriticalSection( &g_critical ); + if( g_sysMouse.didHandle ) + { + g_sysMouse.didHandle->Unacquire(); + if( g_bExclusiveMouse ) + { + g_sysMouse.didHandle->Unacquire(); + g_sysMouse.didHandle->SetCooperativeLevel( g_strEmuInfo.hMainWindow, DIB_KEYBOARD ); + g_sysMouse.didHandle->Acquire(); + LoadString( g_hResourceDLL, IDS_POP_MOUSEUNLOCKED, pszMessage, ARRAYSIZE(pszMessage) ); + } + else + { + g_sysMouse.didHandle->Unacquire(); + g_sysMouse.didHandle->SetCooperativeLevel( g_strEmuInfo.hMainWindow, DIB_MOUSE ); + g_sysMouse.didHandle->Acquire(); + LoadString( g_hResourceDLL, IDS_POP_MOUSELOCKED, pszMessage, ARRAYSIZE(pszMessage) ); + } + g_sysMouse.didHandle->Acquire(); + g_bExclusiveMouse = !g_bExclusiveMouse; + } + LeaveCriticalSection( &g_critical ); + } + else if( g_pcControllers[iControl].fPlugged ) + { + if( g_pcControllers[iControl].pPakData ) + { + SaveControllerPak( iControl ); + CloseControllerPak( iControl ); + } - switch (iShortcut) - { - case SC_NOPAK: - EnterCriticalSection( &g_critical ); - g_pcControllers[iControl].PakType = PAK_NONE; - g_pcControllers[iControl].fPakInitialized = false; - LoadString( g_hResourceDLL, IDS_P_NONE, pszMessage, ARRAYSIZE(pszMessage) ); - LeaveCriticalSection( &g_critical ); - break; - case SC_MEMPAK: - if (PAK_NONE == g_pcControllers[iControl].PakType) - { - EnterCriticalSection( &g_critical ); - g_pcControllers[iControl].PakType = PAK_MEM; - g_pcControllers[iControl].fPakInitialized = false; - LoadString( g_hResourceDLL, IDS_P_MEMPAK, pszMessage, ARRAYSIZE(pszMessage) ); - LeaveCriticalSection( &g_critical ); - } - else - { - bEjectFirst = true; - } - break; - case SC_RUMBPAK: - if (PAK_NONE == g_pcControllers[iControl].PakType) - { - EnterCriticalSection( &g_critical ); - g_pcControllers[iControl].PakType = PAK_RUMBLE; - g_pcControllers[iControl].fPakInitialized = false; + switch (iShortcut) + { + case SC_NOPAK: + EnterCriticalSection( &g_critical ); + g_pcControllers[iControl].PakType = PAK_NONE; + g_pcControllers[iControl].fPakInitialized = false; + LoadString( g_hResourceDLL, IDS_P_NONE, pszMessage, ARRAYSIZE(pszMessage) ); + LeaveCriticalSection( &g_critical ); + break; + case SC_MEMPAK: + if (PAK_NONE == g_pcControllers[iControl].PakType) + { + EnterCriticalSection( &g_critical ); + g_pcControllers[iControl].PakType = PAK_MEM; + g_pcControllers[iControl].fPakInitialized = false; + LoadString( g_hResourceDLL, IDS_P_MEMPAK, pszMessage, ARRAYSIZE(pszMessage) ); + LeaveCriticalSection( &g_critical ); + } + else + { + bEjectFirst = true; + } + break; + case SC_RUMBPAK: + if (PAK_NONE == g_pcControllers[iControl].PakType) + { + EnterCriticalSection( &g_critical ); + g_pcControllers[iControl].PakType = PAK_RUMBLE; + g_pcControllers[iControl].fPakInitialized = false; - if( g_pcControllers[iControl].fRawData ) - if (CreateEffectHandle( iControl, g_pcControllers[iControl].bRumbleTyp, g_pcControllers[iControl].bRumbleStrength ) ) - { - DebugWriteA("CreateEffectHandle for shortcut switch: OK\n"); - } - else - { - DebugWriteA("Couldn't CreateEffectHandle for shortcut switch.\n"); - } + if( g_pcControllers[iControl].fRawData ) + if (CreateEffectHandle( iControl, g_pcControllers[iControl].bRumbleTyp, g_pcControllers[iControl].bRumbleStrength ) ) + { + DebugWriteA("CreateEffectHandle for shortcut switch: OK\n"); + } + else + { + DebugWriteA("Couldn't CreateEffectHandle for shortcut switch.\n"); + } - LoadString( g_hResourceDLL, IDS_P_RUMBLEPAK, pszMessage, ARRAYSIZE(pszMessage) ); - LeaveCriticalSection( &g_critical ); - } - else - { - bEjectFirst = true; - } - break; - - case SC_TRANSPAK: - if (PAK_NONE == g_pcControllers[iControl].PakType) - { - EnterCriticalSection( &g_critical ); - g_pcControllers[iControl].PakType = PAK_TRANSFER; - g_pcControllers[iControl].fPakInitialized = false; + LoadString( g_hResourceDLL, IDS_P_RUMBLEPAK, pszMessage, ARRAYSIZE(pszMessage) ); + LeaveCriticalSection( &g_critical ); + } + else + { + bEjectFirst = true; + } + break; - LoadString( g_hResourceDLL, IDS_P_TRANSFERPAK, pszMessage, ARRAYSIZE(pszMessage) ); - LeaveCriticalSection( &g_critical ); - } - else - { - bEjectFirst = true; - } - break; - case SC_VOICEPAK: - if (PAK_NONE == g_pcControllers[iControl].PakType) - { - EnterCriticalSection( &g_critical ); - g_pcControllers[iControl].PakType = PAK_VOICE; - g_pcControllers[iControl].fPakInitialized = false; + case SC_TRANSPAK: + if (PAK_NONE == g_pcControllers[iControl].PakType) + { + EnterCriticalSection( &g_critical ); + g_pcControllers[iControl].PakType = PAK_TRANSFER; + g_pcControllers[iControl].fPakInitialized = false; - LoadString( g_hResourceDLL, IDS_P_VOICEPAK, pszMessage, ARRAYSIZE(pszMessage) ); - LeaveCriticalSection( &g_critical ); - } - else - { - bEjectFirst = true; - } - break; - case SC_ADAPTPAK: - if (PAK_NONE == g_pcControllers[iControl].PakType) - { - EnterCriticalSection( &g_critical ); - g_pcControllers[iControl].PakType = PAK_ADAPTOID; - g_pcControllers[iControl].fPakInitialized = false; + LoadString( g_hResourceDLL, IDS_P_TRANSFERPAK, pszMessage, ARRAYSIZE(pszMessage) ); + LeaveCriticalSection( &g_critical ); + } + else + { + bEjectFirst = true; + } + break; + case SC_VOICEPAK: + if (PAK_NONE == g_pcControllers[iControl].PakType) + { + EnterCriticalSection( &g_critical ); + g_pcControllers[iControl].PakType = PAK_VOICE; + g_pcControllers[iControl].fPakInitialized = false; - LoadString( g_hResourceDLL, IDS_P_ADAPTOIDPAK, pszMessage, ARRAYSIZE(pszMessage) ); - LeaveCriticalSection( &g_critical ); - } - else - { - bEjectFirst = true; - } - break; - case SC_SWMEMRUMB: - bEjectFirst = true; - if( g_pcControllers[iControl].PakType == PAK_MEM ) - { - iShortcut = PAK_RUMBLE; - } - else - { - iShortcut = PAK_MEM; - } - break; - case SC_SWMEMADAPT: - bEjectFirst = true; - if( g_pcControllers[iControl].PakType == PAK_MEM ) - { - iShortcut = PAK_ADAPTOID; - } - else - { - iShortcut = PAK_MEM; - } - break; - default: - DebugWriteA("Invalid iShortcut passed to DoShortcut\n"); - EnterCriticalSection( &g_critical ); - g_pcControllers[iControl].fPakInitialized = false; - LeaveCriticalSection( &g_critical ); - return; - } // switch (iShortcut) - } // else if + LoadString( g_hResourceDLL, IDS_P_VOICEPAK, pszMessage, ARRAYSIZE(pszMessage) ); + LeaveCriticalSection( &g_critical ); + } + else + { + bEjectFirst = true; + } + break; + case SC_ADAPTPAK: + if (PAK_NONE == g_pcControllers[iControl].PakType) + { + EnterCriticalSection( &g_critical ); + g_pcControllers[iControl].PakType = PAK_ADAPTOID; + g_pcControllers[iControl].fPakInitialized = false; - // let the game code re-init the pak. + LoadString( g_hResourceDLL, IDS_P_ADAPTOIDPAK, pszMessage, ARRAYSIZE(pszMessage) ); + LeaveCriticalSection( &g_critical ); + } + else + { + bEjectFirst = true; + } + break; + case SC_SWMEMRUMB: + bEjectFirst = true; + if( g_pcControllers[iControl].PakType == PAK_MEM ) + { + iShortcut = PAK_RUMBLE; + } + else + { + iShortcut = PAK_MEM; + } + break; + case SC_SWMEMADAPT: + bEjectFirst = true; + if( g_pcControllers[iControl].PakType == PAK_MEM ) + { + iShortcut = PAK_ADAPTOID; + } + else + { + iShortcut = PAK_MEM; + } + break; + default: + DebugWriteA("Invalid iShortcut passed to DoShortcut\n"); + EnterCriticalSection( &g_critical ); + g_pcControllers[iControl].fPakInitialized = false; + LeaveCriticalSection( &g_critical ); + return; + } // switch (iShortcut) + } // else if - if (bEjectFirst) // we need to eject the current pack first; then set a DoShortcut to try again in 1 second - { - EnterCriticalSection( &g_critical ); - g_pcControllers[iControl].PakType = PAK_NONE; - g_pcControllers[iControl].fPakInitialized = false; - LoadString( g_hResourceDLL, IDS_P_SWITCHING, pszMessage, ARRAYSIZE(pszMessage) ); - LeaveCriticalSection( &g_critical ); + // let the game code re-init the pak. - LPMSHORTCUT lpmNextShortcut = (LPMSHORTCUT)P_malloc(sizeof(MSHORTCUT)); - if (!lpmNextShortcut) - return; - lpmNextShortcut->iControl = iControl; - lpmNextShortcut->iShortcut = iShortcut; - CreateThread(NULL, 0, DelayedShortcut, lpmNextShortcut, 0, NULL); - iControl = -2; // this is just a hack to get around the check that appends "Changing Pak X to ..." - } + if (bEjectFirst) // we need to eject the current pack first; then set a DoShortcut to try again in 1 second + { + EnterCriticalSection( &g_critical ); + g_pcControllers[iControl].PakType = PAK_NONE; + g_pcControllers[iControl].fPakInitialized = false; + LoadString( g_hResourceDLL, IDS_P_SWITCHING, pszMessage, ARRAYSIZE(pszMessage) ); + LeaveCriticalSection( &g_critical ); - if( g_strEmuInfo.fDisplayShortPop && _tcslen(pszMessage) > 0 ) - { - if( iControl >= 0 ) - { - TCHAR tszNotify[DEFAULT_BUFFER / 2]; + LPMSHORTCUT lpmNextShortcut = (LPMSHORTCUT)P_malloc(sizeof(MSHORTCUT)); + if (!lpmNextShortcut) + return; + lpmNextShortcut->iControl = iControl; + lpmNextShortcut->iShortcut = iShortcut; + CreateThread(NULL, 0, DelayedShortcut, lpmNextShortcut, 0, NULL); + iControl = -2; // this is just a hack to get around the check that appends "Changing Pak X to ..." + } - LoadString( g_hResourceDLL, IDS_POP_CHANGEPAK, tszNotify, ARRAYSIZE(tszNotify)); - wsprintf( g_pszThreadMessage, tszNotify, iControl+1, pszMessage ); - } - else - lstrcpyn( g_pszThreadMessage, pszMessage, ARRAYSIZE(g_pszThreadMessage) ); + if( g_strEmuInfo.fDisplayShortPop && _tcslen(pszMessage) > 0 ) + { + if( iControl >= 0 ) + { + TCHAR tszNotify[DEFAULT_BUFFER / 2]; - CreateThread(NULL, 0, MsgThreadFunction, g_pszThreadMessage, 0, NULL); - } + LoadString( g_hResourceDLL, IDS_POP_CHANGEPAK, tszNotify, ARRAYSIZE(tszNotify)); + wsprintf( g_pszThreadMessage, tszNotify, iControl+1, pszMessage ); + } + else + lstrcpyn( g_pszThreadMessage, pszMessage, ARRAYSIZE(g_pszThreadMessage) ); + + CreateThread(NULL, 0, MsgThreadFunction, g_pszThreadMessage, 0, NULL); + } } // Use string table refs to generate and throw an error message with title IDS_ERR_TITLE (see string table in resources) // Also if compiled with DEBUG, will log the message with DebugWrite -// uID the string table ref to display -// dwError if nonzero, will display a Windows error message using FormatMessage (for use when an API function fails) -// fUserChoose if true, display buttons Retry and Cancel. if false, display single button OK. -// for fUserChoose==true; ErrorMessage returns true if user selects Retry, and false if user selects Cancel. -// for fUserChoose==false; ErrorMessage always returns false. +// uID the string table ref to display +// dwError if nonzero, will display a Windows error message using FormatMessage (for use when an API function fails) +// fUserChoose if true, display buttons Retry and Cancel. if false, display single button OK. +// for fUserChoose==true; ErrorMessage returns true if user selects Retry, and false if user selects Cancel. +// for fUserChoose==false; ErrorMessage always returns false. bool ErrorMessage( UINT uID, DWORD dwError, bool fUserChoose ) { - TCHAR pszFirstLine[DEFAULT_BUFFER]; + TCHAR pszFirstLine[DEFAULT_BUFFER]; - bool fReturn = false; - int iBytes; - TCHAR szError[512]; - TCHAR tszErrorTitle[DEFAULT_BUFFER]; + bool fReturn = false; + int iBytes; + TCHAR szError[512]; + TCHAR tszErrorTitle[DEFAULT_BUFFER]; - LoadString( g_hResourceDLL, uID, pszFirstLine, DEFAULT_BUFFER ); - LoadString( g_hResourceDLL, IDS_ERR_TITLE, tszErrorTitle, DEFAULT_BUFFER ); + LoadString( g_hResourceDLL, uID, pszFirstLine, DEFAULT_BUFFER ); + LoadString( g_hResourceDLL, IDS_ERR_TITLE, tszErrorTitle, DEFAULT_BUFFER ); - if( dwError ) - { - iBytes = wsprintf( szError, _T("%s\n\n Error description: "), pszFirstLine ); - FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError , 0, &szError[iBytes], sizeof(szError) - iBytes, NULL ); - } - else - lstrcpyn( szError, pszFirstLine, 512 ); - - DebugWrite(_T("ErrorMessage! ID:%d "), uID); - DebugFlush(); + if( dwError ) + { + iBytes = wsprintf( szError, _T("%s\n\n Error description: "), pszFirstLine ); + FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError , 0, &szError[iBytes], sizeof(szError) - iBytes, NULL ); + } + else + lstrcpyn( szError, pszFirstLine, 512 ); - if( fUserChoose ) - fReturn = MessageBox( g_strEmuInfo.hMainWindow, szError, tszErrorTitle, MB_RETRYCANCEL | MB_ICONERROR ) == IDRETRY; - else - MessageBox( g_strEmuInfo.hMainWindow, szError, tszErrorTitle, MB_OK | MB_ICONERROR ); + DebugWrite(_T("ErrorMessage! ID:%d "), uID); + DebugFlush(); - DebugWriteA(fReturn ? "(user: retry)\n" : "(user: acknowledge)\n"); - return fReturn; + if( fUserChoose ) + fReturn = MessageBox( g_strEmuInfo.hMainWindow, szError, tszErrorTitle, MB_RETRYCANCEL | MB_ICONERROR ) == IDRETRY; + else + MessageBox( g_strEmuInfo.hMainWindow, szError, tszErrorTitle, MB_OK | MB_ICONERROR ); + + DebugWriteA(fReturn ? "(user: retry)\n" : "(user: acknowledge)\n"); + return fReturn; } // Post a message box, using string resource uTextID and MessageBox style uType int WarningMessage( UINT uTextID, UINT uType ) { - DebugWriteA("WarningMessage: ID:%d Type:%d\n", uTextID, uType); - DebugFlush(); + DebugWriteA("WarningMessage: ID:%d Type:%d\n", uTextID, uType); + DebugFlush(); - TCHAR tszTitle[DEFAULT_BUFFER], tszText[DEFAULT_BUFFER]; + TCHAR tszTitle[DEFAULT_BUFFER], tszText[DEFAULT_BUFFER]; - LoadString( g_hResourceDLL, uTextID, tszText, DEFAULT_BUFFER ); - LoadString( g_hResourceDLL, IDS_DLG_WARN_TITLE, tszTitle, DEFAULT_BUFFER ); + LoadString( g_hResourceDLL, uTextID, tszText, DEFAULT_BUFFER ); + LoadString( g_hResourceDLL, IDS_DLG_WARN_TITLE, tszTitle, DEFAULT_BUFFER ); - return MessageBox( g_strEmuInfo.hMainWindow, tszText, tszTitle, uType ); + return MessageBox( g_strEmuInfo.hMainWindow, tszText, tszTitle, uType ); } /* H.Morii - MsgThreadFunction is used because the SetTimer function relies - on the WM_TIMER message which is low priority and will not be + MsgThreadFunction is used because the SetTimer function relies + on the WM_TIMER message which is low priority and will not be executed if other windows messages are frequently dispatched. */ -DWORD WINAPI MsgThreadFunction( LPVOID lpParam ) +DWORD WINAPI MsgThreadFunction( LPVOID lpParam ) { - HWND hMessage = CreateWindowEx( WS_EX_NOPARENTNOTIFY | WS_EX_STATICEDGE | WS_EX_TOPMOST, _T("STATIC"), NULL, WS_CHILD | WS_VISIBLE, 10, 10, 200, 40, g_strEmuInfo.hMainWindow, NULL, g_strEmuInfo.hinst, NULL ); + HWND hMessage = CreateWindowEx( WS_EX_NOPARENTNOTIFY | WS_EX_STATICEDGE | WS_EX_TOPMOST, _T("STATIC"), NULL, WS_CHILD | WS_VISIBLE, 10, 10, 200, 40, g_strEmuInfo.hMainWindow, NULL, g_strEmuInfo.hinst, NULL ); - /* prepare the screen to bitblt */ - RECT rt; - GetClientRect(hMessage, &rt); - HDC hdc = GetDC(hMessage); - HDC memdc = CreateCompatibleDC(hdc); - HBITMAP hbitmap = CreateCompatibleBitmap(hdc, rt.right - rt.left, rt.bottom - rt.top); - SelectObject(memdc, hbitmap); + /* prepare the screen to bitblt */ + RECT rt; + GetClientRect(hMessage, &rt); + HDC hdc = GetDC(hMessage); + HDC memdc = CreateCompatibleDC(hdc); + HBITMAP hbitmap = CreateCompatibleBitmap(hdc, rt.right - rt.left, rt.bottom - rt.top); + SelectObject(memdc, hbitmap); - /* draw some nice stuff. - choose fonts, paint the back ground, etc here. */ - FillRect(memdc, &rt, (HBRUSH)(COLOR_WINDOW+1)); - DrawText(memdc, (LPCTSTR)lpParam, -1, &rt, DT_WORDBREAK); + /* draw some nice stuff. + choose fonts, paint the back ground, etc here. */ + FillRect(memdc, &rt, (HBRUSH)(COLOR_WINDOW+1)); + DrawText(memdc, (LPCTSTR)lpParam, -1, &rt, DT_WORDBREAK); - /* bitblt to kingdom come */ - for (int i = 0; i < 60; i++) - { - Sleep(16); // 1/60 second - BitBlt(hdc, rt.left, rt.top, rt.right - rt.left, rt.bottom - rt.top, memdc, 0, 0, SRCCOPY); - } + /* bitblt to kingdom come */ + for (int i = 0; i < 60; i++) + { + Sleep(16); // 1/60 second + BitBlt(hdc, rt.left, rt.top, rt.right - rt.left, rt.bottom - rt.top, memdc, 0, 0, SRCCOPY); + } - /* cleanup */ - DeleteObject(hbitmap); - DeleteDC(memdc); - ReleaseDC(hMessage, hdc); + /* cleanup */ + DeleteObject(hbitmap); + DeleteDC(memdc); + ReleaseDC(hMessage, hdc); - /* Can only destroy windows created from the owner thread */ - DestroyWindow(hMessage); + /* Can only destroy windows created from the owner thread */ + DestroyWindow(hMessage); - return 0; + return 0; } // This function is called as a thread by DoShortcut in order to tell the plugin to insert a pak shortly // (usually after we've just removed whatever pak was there) DWORD WINAPI DelayedShortcut(LPVOID lpParam) { - LPMSHORTCUT sc = (LPMSHORTCUT)lpParam; - if (sc && sc->iShortcut != SC_SWMEMRUMB && sc->iShortcut != SC_SWMEMADAPT) // don't allow recursion into self, it would cause a deadlock - { - Sleep(1000); // sleep a little bit before calling DoShortcut again - DoShortcut(sc->iControl, sc->iShortcut); - } - P_free(lpParam); - return 0; + LPMSHORTCUT sc = (LPMSHORTCUT)lpParam; + if (sc && sc->iShortcut != SC_SWMEMRUMB && sc->iShortcut != SC_SWMEMADAPT) // don't allow recursion into self, it would cause a deadlock + { + Sleep(1000); // sleep a little bit before calling DoShortcut again + DoShortcut(sc->iControl, sc->iShortcut); + } + P_free(lpParam); + return 0; } diff --git a/Source/nragev20/NRagePluginV2.h b/Source/nragev20/NRagePluginV2.h index 52fc95f3e..5929cdb6a 100644 --- a/Source/nragev20/NRagePluginV2.h +++ b/Source/nragev20/NRagePluginV2.h @@ -1,24 +1,24 @@ /* - N-Rage`s Dinput8 Plugin - (C) 2002, 2006 Norbert Wladyka + N-Rage`s Dinput8 Plugin + (C) 2002, 2006 Norbert Wladyka - Author`s Email: norbert.wladyka@chello.at - Website: http://go.to/nrage + Author`s Email: norbert.wladyka@chello.at + Website: http://go.to/nrage - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the free Software Foundation; either version 2 of the License, or - (at your option) any later version. + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the free Software Foundation; either version 2 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ + You should have received a copy of the GNU General Public License + along with this program; if not, write to the free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ #ifndef _NRAGEPLUGIN_ #define _NRAGEPLUGIN_ @@ -30,38 +30,38 @@ ///////////////////////////////////////////////////////////////////////////////// //General Plugin -#define TIMER_MESSAGEWINDOW 123 +#define TIMER_MESSAGEWINDOW 123 // maximum number of devices other than SysMouse -#define MAX_DEVICES 32 +#define MAX_DEVICES 32 // maximum number of modifiers -#define MAX_MODIFIERS 256 +#define MAX_MODIFIERS 256 -#define DEFAULT_STICKRANGE 66 -#define DEFAULT_DEADZONE 5 -#define DEFAULT_RUMBLETYP RUMBLE_EFF1 -#define DEFAULT_RUMBLESTRENGTH 80 -#define DEFAULT_MOUSESENSIVITY 100 -#define DEFAULT_PAKTYPE PAK_MEM -#define DEFAULT_MOUSEMOVE MM_BUFF +#define DEFAULT_STICKRANGE 66 +#define DEFAULT_DEADZONE 5 +#define DEFAULT_RUMBLETYP RUMBLE_EFF1 +#define DEFAULT_RUMBLESTRENGTH 80 +#define DEFAULT_MOUSESENSIVITY 100 +#define DEFAULT_PAKTYPE PAK_MEM +#define DEFAULT_MOUSEMOVE MM_BUFF -#define PAK_NONE 0 -#define PAK_MEM 1 -#define PAK_RUMBLE 2 -#define PAK_TRANSFER 3 -#define PAK_VOICE 4 -#define PAK_ADAPTOID 7 +#define PAK_NONE 0 +#define PAK_MEM 1 +#define PAK_RUMBLE 2 +#define PAK_TRANSFER 3 +#define PAK_VOICE 4 +#define PAK_ADAPTOID 7 // just used to display text in GUI -#define PAK_NONRAW 16 +#define PAK_NONRAW 16 typedef struct _EMULATOR_INFO { - bool fInitialisedPlugin; - HWND hMainWindow; - HINSTANCE hinst; - LANGID Language; - bool fDisplayShortPop; // do we display shortcut message popups? + bool fInitialisedPlugin; + HWND hMainWindow; + HINSTANCE hinst; + LANGID Language; + bool fDisplayShortPop; // do we display shortcut message popups? /* * 2015.11.09 cxd4 @@ -71,152 +71,152 @@ typedef struct _EMULATOR_INFO */ CONTROL * controllers; - // BOOL MemoryBswaped; // If this is set to TRUE, then the memory has been pre - // bswap on a dword (32 bits) boundry, only effects header. - // eg. the first 8 bytes are stored like this: - // 4 3 2 1 8 7 6 5 - // BYTE * HEADER; // This is the rom header (first 40h bytes of the rom) + // BOOL MemoryBswaped; // If this is set to TRUE, then the memory has been pre + // bswap on a dword (32 bits) boundry, only effects header. + // eg. the first 8 bytes are stored like this: + // 4 3 2 1 8 7 6 5 + // BYTE * HEADER; // This is the rom header (first 40h bytes of the rom) } EMULATOR_INFO, *LPEMULATOR_INFO; typedef struct _DEVICE { - LPDIRECTINPUTDEVICE8 didHandle; - TCHAR szProductName[MAX_PATH]; - BYTE bProductCounter; - GUID guidInstance; - DWORD dwDevType; // can be DI8DEVTYPE_KEYBOARD, DI8DEVTYPE_MOUSE, etc - BYTE bEffType; // What rumble effects does this device support? - union INPUTSTATE // the last polled data from this device - { - DIJOYSTATE joyState; - DIMOUSESTATE2 mouseState; - BYTE rgbButtons[256]; // keyboard state - } stateAs; + LPDIRECTINPUTDEVICE8 didHandle; + TCHAR szProductName[MAX_PATH]; + BYTE bProductCounter; + GUID guidInstance; + DWORD dwDevType; // can be DI8DEVTYPE_KEYBOARD, DI8DEVTYPE_MOUSE, etc + BYTE bEffType; // What rumble effects does this device support? + union INPUTSTATE // the last polled data from this device + { + DIJOYSTATE joyState; + DIMOUSESTATE2 mouseState; + BYTE rgbButtons[256]; // keyboard state + } stateAs; } DEVICE, *LPDEVICE; typedef struct _BUTTON { - bool fPrevPressed; // Was this button pressed last time we checked? (not to be saved in config) - BYTE bOffset; // Offset in the DirectInput data structure - BYTE bAxisID; // Tells which range of the Axe/POV is important (see AI_AXE_P, AI_POV_UP, etc) - BYTE bBtnType; // Type of device/button: Keyboard key, Joystick axis, Joystick button, Mouse axis, etc - LPDEVICE parentDevice; // pointer to the DEVICE this assignment came from + bool fPrevPressed; // Was this button pressed last time we checked? (not to be saved in config) + BYTE bOffset; // Offset in the DirectInput data structure + BYTE bAxisID; // Tells which range of the Axe/POV is important (see AI_AXE_P, AI_POV_UP, etc) + BYTE bBtnType; // Type of device/button: Keyboard key, Joystick axis, Joystick button, Mouse axis, etc + LPDEVICE parentDevice; // pointer to the DEVICE this assignment came from } BUTTON, *LPBUTTON; // Modifiers are a feature built into NRage. Emulator turbo buttons, macros, stuff like that. typedef struct _MODIFIER { - BUTTON btnButton; // button to associate with - BYTE bModType; // Type of modifier (None, Movement, Macro, Config) - BOOL fToggle; // false if you have to hold the button down to activate, true if the modifier toggles on button press - BOOL fStatus; // if true, control defaults to ACTIVE, and deactivates on button press - DWORD32 dwSpecific; // will be cast to MODSPEC_MOVE, MODSPEC_MACRO, or MODSPEC_CONFIG + BUTTON btnButton; // button to associate with + BYTE bModType; // Type of modifier (None, Movement, Macro, Config) + BOOL fToggle; // false if you have to hold the button down to activate, true if the modifier toggles on button press + BOOL fStatus; // if true, control defaults to ACTIVE, and deactivates on button press + DWORD32 dwSpecific; // will be cast to MODSPEC_MOVE, MODSPEC_MACRO, or MODSPEC_CONFIG } MODIFIER, *LPMODIFIER; // bModType (modifiers) -#define MDT_NONE 0 -#define MDT_MOVE 1 -#define MDT_MACRO 2 -#define MDT_CONFIG 3 +#define MDT_NONE 0 +#define MDT_MOVE 1 +#define MDT_MACRO 2 +#define MDT_CONFIG 3 // buffered -#define MM_BUFF 0 +#define MM_BUFF 0 // absolute -#define MM_ABS 1 +#define MM_ABS 1 // deadpan -#define MM_DEAD 2 +#define MM_DEAD 2 // Number of analog axes. Standard N64 controller has just 2: X and Y joystick. -#define PF_AXESETS 2 +#define PF_AXESETS 2 -typedef struct _CONTROLLER // AN N64 CONTROLLER +typedef struct _CONTROLLER // AN N64 CONTROLLER { - unsigned fPlugged; // is the controller "plugged" (i.e. does the emulator see a controller on this port?) - unsigned fXInput; // is the controller an xInput device? - unsigned fN64Mouse; // is the controller a N64 Mouse (Relative)? - unsigned fRawData; // are we using RAW mode for this controller? - unsigned fIsAdaptoid; // is it an adaptoid? + unsigned fPlugged; // is the controller "plugged" (i.e. does the emulator see a controller on this port?) + unsigned fXInput; // is the controller an xInput device? + unsigned fN64Mouse; // is the controller a N64 Mouse (Relative)? + unsigned fRawData; // are we using RAW mode for this controller? + unsigned fIsAdaptoid; // is it an adaptoid? - unsigned fKeyboard; // does it use a keyboard? - unsigned fMouse; // does it use a mouse? - unsigned fGamePad; // does it use a gamepad/joystick? + unsigned fKeyboard; // does it use a keyboard? + unsigned fMouse; // does it use a mouse? + unsigned fGamePad; // does it use a gamepad/joystick? - unsigned fRealN64Range; // does it have the "Real N64 Range" flag set? - unsigned bAxisSet; // which set of axes are we using? (Control 1, Control 2) - unsigned bMouseMoveX; // does it use buffered/absolute mouse for X? MM_BUFF, MM_ABS, MM_DEAD - unsigned bMouseMoveY; // does it use buffered/absolute mouse for Y? - unsigned fKeyAbsoluteX; // does it use absolute key for X? - unsigned fKeyAbsoluteY; // does it use absolute key for Y? + unsigned fRealN64Range; // does it have the "Real N64 Range" flag set? + unsigned bAxisSet; // which set of axes are we using? (Control 1, Control 2) + unsigned bMouseMoveX; // does it use buffered/absolute mouse for X? MM_BUFF, MM_ABS, MM_DEAD + unsigned bMouseMoveY; // does it use buffered/absolute mouse for Y? + unsigned fKeyAbsoluteX; // does it use absolute key for X? + unsigned fKeyAbsoluteY; // does it use absolute key for Y? - unsigned fPakInitialized; // Has our pak been initialized? Used to make sure we don't try to write to a mempak that doesn't point to anything. - unsigned fPakCRCError; // The ROM sends CRC data when it tries to write to a mempak. Is the CRC incorrect? Usually indicates a bad ROM. - unsigned PakType; // what type of controller pak? mempak? rumble? transfer? etc - unsigned fVisualRumble; // is visual rumble enabled for this controller? + unsigned fPakInitialized; // Has our pak been initialized? Used to make sure we don't try to write to a mempak that doesn't point to anything. + unsigned fPakCRCError; // The ROM sends CRC data when it tries to write to a mempak. Is the CRC incorrect? Usually indicates a bad ROM. + unsigned PakType; // what type of controller pak? mempak? rumble? transfer? etc + unsigned fVisualRumble; // is visual rumble enabled for this controller? - unsigned bBackgroundInput; // allow input while main window isn't focused? + unsigned bBackgroundInput; // allow input while main window isn't focused? - BYTE bRumbleTyp; // what type of rumble effect? none, constant, ramp, or direct? + BYTE bRumbleTyp; // what type of rumble effect? none, constant, ramp, or direct? - GUID guidFFDevice; // GUID of the device that rumble gets sent to + GUID guidFFDevice; // GUID of the device that rumble gets sent to - BYTE bStickRange; // our "range modifier". + BYTE bStickRange; // our "range modifier". - long wAxeBuffer[4]; // makes pseudo-relative Movement possible through keyboard or buttons - // also acts as a mouse buffer + long wAxeBuffer[4]; // makes pseudo-relative Movement possible through keyboard or buttons + // also acts as a mouse buffer - WORD wMouseSensitivityX; // set per N64 controller, that's OK - WORD wMouseSensitivityY; - BYTE bPadDeadZone; // our manual dead zone, set per N64 controller - BYTE bRumbleStrength; // set per N64 controller - unsigned short nModifiers; // number of modifiers + WORD wMouseSensitivityX; // set per N64 controller, that's OK + WORD wMouseSensitivityY; + BYTE bPadDeadZone; // our manual dead zone, set per N64 controller + BYTE bRumbleStrength; // set per N64 controller + unsigned short nModifiers; // number of modifiers - bool bRapidFireEnabled; - BYTE bRapidFireRate; - BYTE bRapidFireCounter; + bool bRapidFireEnabled; + BYTE bRapidFireRate; + BYTE bRapidFireCounter; - TCHAR szMempakFile[MAX_PATH + 1]; // MemPak-FileName - TCHAR szTransferRom[MAX_PATH + 1]; // GameBoyRom-Filename - TCHAR szTransferSave[MAX_PATH + 1]; // GameBoyEEPRom-Filename + TCHAR szMempakFile[MAX_PATH + 1]; // MemPak-FileName + TCHAR szTransferRom[MAX_PATH + 1]; // GameBoyRom-Filename + TCHAR szTransferSave[MAX_PATH + 1]; // GameBoyEEPRom-Filename - BUTTON aButton[14 + PF_AXESETS * 4]; // Ten buttons, 4 d-pad directions times two (for Config 1 and Config 2) + BUTTON aButton[14 + PF_AXESETS * 4]; // Ten buttons, 4 d-pad directions times two (for Config 1 and Config 2) - MODIFIER *pModifiers; // Array of Modifiers + MODIFIER *pModifiers; // Array of Modifiers - void *pPakData; // Pointer to Pak Data (specific): see PakIO.h - // pPakData->bPakType will always be a BYTE indicating what the current pak type is + void *pPakData; // Pointer to Pak Data (specific): see PakIO.h + // pPakData->bPakType will always be a BYTE indicating what the current pak type is - XCONTROLLER xiController; // To handle an XInput enabled controller --tecnicors + XCONTROLLER xiController; // To handle an XInput enabled controller --tecnicors } CONTROLLER, *LPCONTROLLER; // This is the Index of WORD PROFILE.Button[X] // Buttons: -#define PF_DPADR 0 -#define PF_DPADL 1 -#define PF_DPADD 2 -#define PF_DPADU 3 -#define PF_START 4 -#define PF_TRIGGERZ 5 -#define PF_BBUTTON 6 -#define PF_ABUTTON 7 +#define PF_DPADR 0 +#define PF_DPADL 1 +#define PF_DPADD 2 +#define PF_DPADU 3 +#define PF_START 4 +#define PF_TRIGGERZ 5 +#define PF_BBUTTON 6 +#define PF_ABUTTON 7 #define PF_CBUTTONR 8 -#define PF_CBUTTONL 9 +#define PF_CBUTTONL 9 #define PF_CBUTTOND 10 #define PF_CBUTTONU 11 -#define PF_TRIGGERR 12 -#define PF_TRIGGERL 13 +#define PF_TRIGGERR 12 +#define PF_TRIGGERL 13 // Analog Stick // cause you can assign Buttons to it, I need 4 of 'em -#define PF_APADR 14 -#define PF_APADL 15 -#define PF_APADD 16 -#define PF_APADU 17 +#define PF_APADR 14 +#define PF_APADL 15 +#define PF_APADD 16 +#define PF_APADU 17 // second Set -// #define PF_APADR 18 -// #define PF_APADL 19 -// #define PF_APADD 20 -// #define PF_APADU 21 +// #define PF_APADR 18 +// #define PF_APADL 19 +// #define PF_APADD 20 +// #define PF_APADU 21 // Data Format of DWORD Controller.Button: // @@ -226,140 +226,140 @@ typedef struct _CONTROLLER // AN N64 CONTROLLER // BYTE bOffset : Offset in the DirectInput data structure // BYTE bBtnType : Determines the Device and general Type of Control -#define DT_UNASSIGNED 0 +#define DT_UNASSIGNED 0 // Joystick -#define DT_JOYBUTTON 1 -#define DT_JOYAXE 2 -#define DT_JOYPOV 3 -#define DT_JOYSLIDER 4 +#define DT_JOYBUTTON 1 +#define DT_JOYAXE 2 +#define DT_JOYPOV 3 +#define DT_JOYSLIDER 4 // Keyboard -#define DT_KEYBUTTON 5 +#define DT_KEYBUTTON 5 // Mouse -#define DT_MOUSEBUTTON 6 -#define DT_MOUSEAXE 7 +#define DT_MOUSEBUTTON 6 +#define DT_MOUSEAXE 7 // BYTE bAxisID : AxeIndentifier, Tells which range of the Axe/POV is important // Positive Range of an Axe -#define AI_AXE_P 0 +#define AI_AXE_P 0 // Negative Range -#define AI_AXE_N 1 +#define AI_AXE_N 1 // Applies to POVs obviously -#define AI_POV_UP 0 -#define AI_POV_RIGHT 1 -#define AI_POV_DOWN 2 -#define AI_POV_LEFT 3 +#define AI_POV_UP 0 +#define AI_POV_RIGHT 1 +#define AI_POV_DOWN 2 +#define AI_POV_LEFT 3 // BYTE bOffset : Offset in the DirectInput data structure typedef union _MODSPEC_MOVE { - DWORD dwValue; - struct - { - short XModification; - short YModification; - }; + DWORD dwValue; + struct + { + short XModification; + short YModification; + }; } MODSPEC_MOVE, *LPMODSPEC_MOVE; typedef union _MODSPEC_MACRO { - DWORD dwValue; - struct - { - unsigned short aButtons; - unsigned short aFlags; - }; - struct - { - unsigned fDigitalRight : 1; - unsigned fDigitalLeft : 1; - unsigned fDigitalDown : 1; - unsigned fDigitalUp : 1; - unsigned fStart : 1; - unsigned fTriggerZ : 1; - unsigned fBButton : 1; - unsigned fAButton : 1; - unsigned fCRight : 1; - unsigned fCLeft : 1; - unsigned fCDown : 1; - unsigned fCUp : 1; - unsigned fTriggerR : 1; - unsigned fTriggerL : 1; - unsigned : 2; + DWORD dwValue; + struct + { + unsigned short aButtons; + unsigned short aFlags; + }; + struct + { + unsigned fDigitalRight : 1; + unsigned fDigitalLeft : 1; + unsigned fDigitalDown : 1; + unsigned fDigitalUp : 1; + unsigned fStart : 1; + unsigned fTriggerZ : 1; + unsigned fBButton : 1; + unsigned fAButton : 1; + unsigned fCRight : 1; + unsigned fCLeft : 1; + unsigned fCDown : 1; + unsigned fCUp : 1; + unsigned fTriggerR : 1; + unsigned fTriggerL : 1; + unsigned : 2; - unsigned fAnalogRight : 1; - unsigned fAnalogLeft : 1; - unsigned fAnalogDown : 1; - unsigned fAnalogUp : 1; - unsigned fRapidFire : 1; - unsigned fRapidFireRate : 1; - unsigned fPrevFireState : 1; - unsigned fPrevFireState2 : 1; - }; + unsigned fAnalogRight : 1; + unsigned fAnalogLeft : 1; + unsigned fAnalogDown : 1; + unsigned fAnalogUp : 1; + unsigned fRapidFire : 1; + unsigned fRapidFireRate : 1; + unsigned fPrevFireState : 1; + unsigned fPrevFireState2 : 1; + }; } MODSPEC_MACRO, *LPMODSPEC_MACRO; typedef union _MODSPEC_CONFIG { - DWORD dwValue; - struct - { - BYTE bAnalogStick; - BYTE bMouse; - BYTE bKeyboard; - }; - struct - { - unsigned fChangeAnalogConfig : 1; - unsigned fAnalogStickMode : 7; - unsigned fChangeMouseXAxis : 1; - unsigned fChangeMouseYAxis : 1; - unsigned : 6; - unsigned fChangeKeyboardXAxis : 1; - unsigned fChangeKeyboardYAxis : 1; - unsigned : 6; - }; + DWORD dwValue; + struct + { + BYTE bAnalogStick; + BYTE bMouse; + BYTE bKeyboard; + }; + struct + { + unsigned fChangeAnalogConfig : 1; + unsigned fAnalogStickMode : 7; + unsigned fChangeMouseXAxis : 1; + unsigned fChangeMouseYAxis : 1; + unsigned : 6; + unsigned fChangeKeyboardXAxis : 1; + unsigned fChangeKeyboardYAxis : 1; + unsigned : 6; + }; } MODSPEC_CONFIG, *LPMODSPEC_CONFIG; -#define SC_NOPAK 0 -#define SC_MEMPAK 1 -#define SC_RUMBPAK 2 -#define SC_TRANSPAK 3 -#define SC_VOICEPAK 4 -#define SC_ADAPTPAK 5 -#define SC_SWMEMRUMB 6 -#define SC_SWMEMADAPT 7 +#define SC_NOPAK 0 +#define SC_MEMPAK 1 +#define SC_RUMBPAK 2 +#define SC_TRANSPAK 3 +#define SC_VOICEPAK 4 +#define SC_ADAPTPAK 5 +#define SC_SWMEMRUMB 6 +#define SC_SWMEMADAPT 7 // total arraysize of aButtons in SHORTCUTSPL; // make sure you update this if you change the list above -#define SC_TOTAL 8 +#define SC_TOTAL 8 typedef struct _SHORTCUTSPL { - BUTTON aButtons[SC_TOTAL]; - //BUTTON NoPakButton; - //BUTTON MemPakButton; - //BUTTON RumblePakButton; - //BUTTON TransferPakButton; - //BUTTON VoicePakButton; - //BUTTON AdaptoidPakButton; - //BUTTON SwMemRumbleButton; - //BUTTON SwMemAdaptoidButton; + BUTTON aButtons[SC_TOTAL]; + //BUTTON NoPakButton; + //BUTTON MemPakButton; + //BUTTON RumblePakButton; + //BUTTON TransferPakButton; + //BUTTON VoicePakButton; + //BUTTON AdaptoidPakButton; + //BUTTON SwMemRumbleButton; + //BUTTON SwMemAdaptoidButton; } SHORTCUTSPL, *LPSHORTCUTSPL; typedef struct _SHORTCUTS { - SHORTCUTSPL Player[4]; - BUTTON bMouseLock; + SHORTCUTSPL Player[4]; + BUTTON bMouseLock; } SHORTCUTS, *LPSHORTCUTS; typedef struct _MSHORTCUT { - int iControl; - int iShortcut; -} MSHORTCUT, *LPMSHORTCUT; // shortcut message + int iControl; + int iShortcut; +} MSHORTCUT, *LPMSHORTCUT; // shortcut message #define CHECK_WHITESPACES( str ) ( str == '\r' || str == '\n' || str == '\t' ) diff --git a/Source/nragev20/PakIO.cpp b/Source/nragev20/PakIO.cpp index 7be39855d..246fea82d 100644 --- a/Source/nragev20/PakIO.cpp +++ b/Source/nragev20/PakIO.cpp @@ -1,9 +1,9 @@ -/* - N-Rage`s Dinput8 Plugin +/* + N-Rage`s Dinput8 Plugin (C) 2002, 2006 Norbert Wladyka - Author`s Email: norbert.wladyka@chello.at - Website: http://go.to/nrage + Author`s Email: norbert.wladyka@chello.at + Website: http://go.to/nrage This program is free software; you can redistribute it and/or modify @@ -47,807 +47,807 @@ VOID CALLBACK WritebackProc( HWND hWnd, UINT msg, UINT_PTR idEvent, DWORD dwTime bool InitControllerPak( const int iControl ) // Prepares the Pak { - if( !g_pcControllers[iControl].fPlugged ) - return false; - bool bReturn = false; - if( g_pcControllers[iControl].pPakData ) - { - SaveControllerPak( iControl ); - CloseControllerPak( iControl ); - } + if( !g_pcControllers[iControl].fPlugged ) + return false; + bool bReturn = false; + if( g_pcControllers[iControl].pPakData ) + { + SaveControllerPak( iControl ); + CloseControllerPak( iControl ); + } - switch( g_pcControllers[iControl].PakType ) - { - case PAK_MEM: - { - g_pcControllers[iControl].pPakData = P_malloc( sizeof(MEMPAK)); - MEMPAK *mPak = (MEMPAK*)g_pcControllers[iControl].pPakData; - mPak->bPakType = PAK_MEM; - mPak->fReadonly = false; - mPak->fDexSave = false; - mPak->hMemPakHandle = NULL; + switch( g_pcControllers[iControl].PakType ) + { + case PAK_MEM: + { + g_pcControllers[iControl].pPakData = P_malloc( sizeof(MEMPAK)); + MEMPAK *mPak = (MEMPAK*)g_pcControllers[iControl].pPakData; + mPak->bPakType = PAK_MEM; + mPak->fReadonly = false; + mPak->fDexSave = false; + mPak->hMemPakHandle = NULL; - DWORD dwFilesize = PAK_MEM_SIZE; // expected file size - TCHAR szBuffer[MAX_PATH+1], - szFullPath[MAX_PATH+1], - *pcFile; + DWORD dwFilesize = PAK_MEM_SIZE; // expected file size + TCHAR szBuffer[MAX_PATH+1], + szFullPath[MAX_PATH+1], + *pcFile; - GetAbsoluteFileName( szBuffer, g_pcControllers[iControl].szMempakFile, DIRECTORY_MEMPAK ); - GetFullPathName( szBuffer, sizeof(szFullPath) / sizeof(TCHAR), szFullPath, &pcFile ); + GetAbsoluteFileName( szBuffer, g_pcControllers[iControl].szMempakFile, DIRECTORY_MEMPAK ); + GetFullPathName( szBuffer, sizeof(szFullPath) / sizeof(TCHAR), szFullPath, &pcFile ); - bool isNewfile = !CheckFileExists( szBuffer ); + bool isNewfile = !CheckFileExists( szBuffer ); - if( pcFile == NULL ) - { // no Filename specified - WarningMessage( IDS_ERR_MEM_NOSPEC, MB_OK | MB_ICONWARNING ); - g_pcControllers[iControl].PakType = PAK_NONE; - break; // memory is freed at the end of this function - } + if( pcFile == NULL ) + { // no Filename specified + WarningMessage( IDS_ERR_MEM_NOSPEC, MB_OK | MB_ICONWARNING ); + g_pcControllers[iControl].PakType = PAK_NONE; + break; // memory is freed at the end of this function + } - TCHAR *pcPoint = _tcsrchr( pcFile, '.' ); - if( !lstrcmpi( pcPoint, _T(".n64") ) ) - { - mPak->fDexSave = true; - dwFilesize += PAK_MEM_DEXOFFSET; - } - else - { - mPak->fDexSave = false; - } + TCHAR *pcPoint = _tcsrchr( pcFile, '.' ); + if( !lstrcmpi( pcPoint, _T(".n64") ) ) + { + mPak->fDexSave = true; + dwFilesize += PAK_MEM_DEXOFFSET; + } + else + { + mPak->fDexSave = false; + } - HANDLE hFileHandle = CreateFile( szFullPath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL ); - if( hFileHandle == INVALID_HANDLE_VALUE ) - {// test if Read-only access is possible - hFileHandle = CreateFile( szFullPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL ); - if( hFileHandle != INVALID_HANDLE_VALUE ) - { - TCHAR tszTitle[DEFAULT_BUFFER], tszText[DEFAULT_BUFFER]; + HANDLE hFileHandle = CreateFile( szFullPath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL ); + if( hFileHandle == INVALID_HANDLE_VALUE ) + {// test if Read-only access is possible + hFileHandle = CreateFile( szFullPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL ); + if( hFileHandle != INVALID_HANDLE_VALUE ) + { + TCHAR tszTitle[DEFAULT_BUFFER], tszText[DEFAULT_BUFFER]; - LoadString( g_hResourceDLL, IDS_DLG_MEM_READONLY, tszText, DEFAULT_BUFFER ); - LoadString( g_hResourceDLL, IDS_DLG_WARN_TITLE, tszTitle, DEFAULT_BUFFER ); - wsprintf( szBuffer, tszText, pcFile ); - MessageBox( g_strEmuInfo.hMainWindow, szBuffer, tszTitle, MB_OK | MB_ICONWARNING ); - mPak->fReadonly = true; - DebugWriteA("Ramfile opened in READ ONLY mode.\n"); - } - else - { - TCHAR tszTitle[DEFAULT_BUFFER], tszText[DEFAULT_BUFFER]; + LoadString( g_hResourceDLL, IDS_DLG_MEM_READONLY, tszText, DEFAULT_BUFFER ); + LoadString( g_hResourceDLL, IDS_DLG_WARN_TITLE, tszTitle, DEFAULT_BUFFER ); + wsprintf( szBuffer, tszText, pcFile ); + MessageBox( g_strEmuInfo.hMainWindow, szBuffer, tszTitle, MB_OK | MB_ICONWARNING ); + mPak->fReadonly = true; + DebugWriteA("Ramfile opened in READ ONLY mode.\n"); + } + else + { + TCHAR tszTitle[DEFAULT_BUFFER], tszText[DEFAULT_BUFFER]; - LoadString( g_hResourceDLL, IDS_ERR_MEMOPEN, tszText, DEFAULT_BUFFER ); - LoadString( g_hResourceDLL, IDS_DLG_WARN_TITLE, tszTitle, DEFAULT_BUFFER ); - wsprintf( szBuffer, tszText, pcFile ); - MessageBox( g_strEmuInfo.hMainWindow, szBuffer, tszTitle, MB_OK | MB_ICONWARNING ); - g_pcControllers[iControl].PakType = PAK_NONE; // set so that CloseControllerPak doesn't try to close a file that isn't open - DebugWrite(_T("Unable to read or create MemPak file %s.\n"), pcFile); - break; // memory is freed at the end of this function - } - } + LoadString( g_hResourceDLL, IDS_ERR_MEMOPEN, tszText, DEFAULT_BUFFER ); + LoadString( g_hResourceDLL, IDS_DLG_WARN_TITLE, tszTitle, DEFAULT_BUFFER ); + wsprintf( szBuffer, tszText, pcFile ); + MessageBox( g_strEmuInfo.hMainWindow, szBuffer, tszTitle, MB_OK | MB_ICONWARNING ); + g_pcControllers[iControl].PakType = PAK_NONE; // set so that CloseControllerPak doesn't try to close a file that isn't open + DebugWrite(_T("Unable to read or create MemPak file %s.\n"), pcFile); + break; // memory is freed at the end of this function + } + } - DWORD dwCurrentSize = GetFileSize( hFileHandle, NULL ); - if ( mPak->fReadonly ) - { - DWORD dwBytesRead = 0; + DWORD dwCurrentSize = GetFileSize( hFileHandle, NULL ); + if ( mPak->fReadonly ) + { + DWORD dwBytesRead = 0; - if( mPak->fDexSave ) - { - SetFilePointer( hFileHandle, PAK_MEM_DEXOFFSET, NULL, FILE_BEGIN ); - } - else - { - SetFilePointer( hFileHandle, 0L, NULL, FILE_BEGIN ); - } + if( mPak->fDexSave ) + { + SetFilePointer( hFileHandle, PAK_MEM_DEXOFFSET, NULL, FILE_BEGIN ); + } + else + { + SetFilePointer( hFileHandle, 0L, NULL, FILE_BEGIN ); + } - dwFilesize = min( dwFilesize, GetFileSize( hFileHandle, NULL )); - if( !isNewfile ) - { - mPak->aMemPakData = (LPBYTE)P_malloc( sizeof(BYTE) * PAK_MEM_SIZE ); - if( ReadFile( hFileHandle, mPak->aMemPakData, PAK_MEM_SIZE, &dwBytesRead, NULL )) - { - if( dwBytesRead < dwFilesize ) - FillMemory( (LPBYTE)mPak->aMemPakData + dwBytesRead, PAK_MEM_SIZE - dwBytesRead, 0xFF ); + dwFilesize = min( dwFilesize, GetFileSize( hFileHandle, NULL )); + if( !isNewfile ) + { + mPak->aMemPakData = (LPBYTE)P_malloc( sizeof(BYTE) * PAK_MEM_SIZE ); + if( ReadFile( hFileHandle, mPak->aMemPakData, PAK_MEM_SIZE, &dwBytesRead, NULL )) + { + if( dwBytesRead < dwFilesize ) + FillMemory( (LPBYTE)mPak->aMemPakData + dwBytesRead, PAK_MEM_SIZE - dwBytesRead, 0xFF ); - bReturn = true; - } - else - P_free( mPak->aMemPakData ); - } - else - { - FormatMemPak( mPak->aMemPakData ); - bReturn = true; - } - CloseHandle( hFileHandle ); - } - else - { - // use mapped file - mPak->hMemPakHandle = CreateFileMapping( hFileHandle, NULL, mPak->fReadonly ? PAGE_READONLY : PAGE_READWRITE, 0, dwFilesize, NULL); - // test for invalid handle - if (mPak->hMemPakHandle == NULL) - { - // note: please don't move the CloseHandle call before GetLastError - DebugWriteA("Couldn't CreateFileMapping for MemPak file : %08x\n", GetLastError()); - CloseHandle(hFileHandle); - break; // memory is freed at the end of the function - } - CloseHandle(hFileHandle); // we can close the file handle now with no problems + bReturn = true; + } + else + P_free( mPak->aMemPakData ); + } + else + { + FormatMemPak( mPak->aMemPakData ); + bReturn = true; + } + CloseHandle( hFileHandle ); + } + else + { + // use mapped file + mPak->hMemPakHandle = CreateFileMapping( hFileHandle, NULL, mPak->fReadonly ? PAGE_READONLY : PAGE_READWRITE, 0, dwFilesize, NULL); + // test for invalid handle + if (mPak->hMemPakHandle == NULL) + { + // note: please don't move the CloseHandle call before GetLastError + DebugWriteA("Couldn't CreateFileMapping for MemPak file : %08x\n", GetLastError()); + CloseHandle(hFileHandle); + break; // memory is freed at the end of the function + } + CloseHandle(hFileHandle); // we can close the file handle now with no problems - mPak->aMemPakData = (LPBYTE)MapViewOfFile( mPak->hMemPakHandle, FILE_MAP_ALL_ACCESS, 0, 0, mPak->fDexSave ? PAK_MEM_SIZE + PAK_MEM_DEXOFFSET : PAK_MEM_SIZE ); + mPak->aMemPakData = (LPBYTE)MapViewOfFile( mPak->hMemPakHandle, FILE_MAP_ALL_ACCESS, 0, 0, mPak->fDexSave ? PAK_MEM_SIZE + PAK_MEM_DEXOFFSET : PAK_MEM_SIZE ); - // this is a bit tricky: - // if it's a dexsave, move the pakdata pointer forward so it points to where the actual mempak data starts - // we need to make sure to move it back when we UnmapViewOfFile - if (mPak->aMemPakData == NULL) - ErrorMessage(IDS_ERR_MAPVIEW, GetLastError(), false); + // this is a bit tricky: + // if it's a dexsave, move the pakdata pointer forward so it points to where the actual mempak data starts + // we need to make sure to move it back when we UnmapViewOfFile + if (mPak->aMemPakData == NULL) + ErrorMessage(IDS_ERR_MAPVIEW, GetLastError(), false); - if ( mPak->fDexSave ) - mPak->aMemPakData += PAK_MEM_DEXOFFSET; + if ( mPak->fDexSave ) + mPak->aMemPakData += PAK_MEM_DEXOFFSET; if( dwCurrentSize < dwFilesize ) - FillMemory( (LPBYTE)mPak->aMemPakData + (mPak->fDexSave ? dwCurrentSize - PAK_MEM_DEXOFFSET : dwCurrentSize), dwFilesize - dwCurrentSize, 0xFF ); + FillMemory( (LPBYTE)mPak->aMemPakData + (mPak->fDexSave ? dwCurrentSize - PAK_MEM_DEXOFFSET : dwCurrentSize), dwFilesize - dwCurrentSize, 0xFF ); - if( isNewfile ) - { - if (mPak->fDexSave ) - { - PVOID pHeader = MapViewOfFile( mPak->hMemPakHandle, FILE_MAP_ALL_ACCESS, 0, 0, PAK_MEM_DEXOFFSET ); - const char szHeader[] = "123-456-STD"; // "OMG-WTF-BBQ"? --rabid - ZeroMemory( pHeader, PAK_MEM_DEXOFFSET ); - CopyMemory( pHeader, szHeader, sizeof(szHeader) ); - FlushViewOfFile( pHeader, PAK_MEM_DEXOFFSET ); - UnmapViewOfFile( pHeader ); - } - FormatMemPak( mPak->aMemPakData ); - } + if( isNewfile ) + { + if (mPak->fDexSave ) + { + PVOID pHeader = MapViewOfFile( mPak->hMemPakHandle, FILE_MAP_ALL_ACCESS, 0, 0, PAK_MEM_DEXOFFSET ); + const char szHeader[] = "123-456-STD"; // "OMG-WTF-BBQ"? --rabid + ZeroMemory( pHeader, PAK_MEM_DEXOFFSET ); + CopyMemory( pHeader, szHeader, sizeof(szHeader) ); + FlushViewOfFile( pHeader, PAK_MEM_DEXOFFSET ); + UnmapViewOfFile( pHeader ); + } + FormatMemPak( mPak->aMemPakData ); + } - bReturn = true; - } - } - break; - case PAK_RUMBLE: - { - g_pcControllers[iControl].pPakData = P_malloc( sizeof(RUMBLEPAK)); - RUMBLEPAK *rPak = (RUMBLEPAK*)g_pcControllers[iControl].pPakData; - rPak->bPakType = PAK_RUMBLE; + bReturn = true; + } + } + break; + case PAK_RUMBLE: + { + g_pcControllers[iControl].pPakData = P_malloc( sizeof(RUMBLEPAK)); + RUMBLEPAK *rPak = (RUMBLEPAK*)g_pcControllers[iControl].pPakData; + rPak->bPakType = PAK_RUMBLE; - rPak->fLastData = true; // statistically, if uninitted it would return true --rabid -// rPak->bRumbleTyp = g_pcControllers[iControl].bRumbleTyp; -// rPak->bRumbleStrength = g_pcControllers[iControl].bRumbleStrength; -// rPak->fVisualRumble = g_pcControllers[iControl].fVisualRumble; - if( !g_pcControllers[iControl].fXInput ) //used to make sure only xinput cotroller rumbles --tecnicors - CreateEffectHandle( iControl, g_pcControllers[iControl].bRumbleTyp, g_pcControllers[iControl].bRumbleStrength ); - bReturn = true; - } - break; - case PAK_TRANSFER: - { - g_pcControllers[iControl].pPakData = P_malloc( sizeof(TRANSFERPAK)); - LPTRANSFERPAK tPak = (LPTRANSFERPAK)g_pcControllers[iControl].pPakData; - tPak->bPakType = PAK_TRANSFER; + rPak->fLastData = true; // statistically, if uninitted it would return true --rabid +// rPak->bRumbleTyp = g_pcControllers[iControl].bRumbleTyp; +// rPak->bRumbleStrength = g_pcControllers[iControl].bRumbleStrength; +// rPak->fVisualRumble = g_pcControllers[iControl].fVisualRumble; + if( !g_pcControllers[iControl].fXInput ) //used to make sure only xinput cotroller rumbles --tecnicors + CreateEffectHandle( iControl, g_pcControllers[iControl].bRumbleTyp, g_pcControllers[iControl].bRumbleStrength ); + bReturn = true; + } + break; + case PAK_TRANSFER: + { + g_pcControllers[iControl].pPakData = P_malloc( sizeof(TRANSFERPAK)); + LPTRANSFERPAK tPak = (LPTRANSFERPAK)g_pcControllers[iControl].pPakData; + tPak->bPakType = PAK_TRANSFER; - tPak->gbCart.hRomFile = NULL; - tPak->gbCart.hRamFile = NULL; - tPak->gbCart.RomData = NULL; - tPak->gbCart.RamData = NULL; + tPak->gbCart.hRomFile = NULL; + tPak->gbCart.hRamFile = NULL; + tPak->gbCart.RomData = NULL; + tPak->gbCart.RamData = NULL; - /* - * Once the Interface is implemented g_pcControllers[iControl].szTransferRom will hold filename of the GB-Rom - * and g_pcControllers[iControl].szTransferSave holds Filename of the SRAM Save - * - * Here, both files should be opened and the handles stored in tPak ( modify the struct for Your own purposes, only bPakType must stay at first ) - */ + /* + * Once the Interface is implemented g_pcControllers[iControl].szTransferRom will hold filename of the GB-Rom + * and g_pcControllers[iControl].szTransferSave holds Filename of the SRAM Save + * + * Here, both files should be opened and the handles stored in tPak ( modify the struct for Your own purposes, only bPakType must stay at first ) + */ - //CreateFile( g_pcControllers[iControl].szTransferSave, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL ); - tPak->iCurrentAccessMode = 0; - tPak->iCurrentBankNo = 0; - tPak->iEnableState = false; - tPak->iAccessModeChanged = 0x44; + //CreateFile( g_pcControllers[iControl].szTransferSave, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL ); + tPak->iCurrentAccessMode = 0; + tPak->iCurrentBankNo = 0; + tPak->iEnableState = false; + tPak->iAccessModeChanged = 0x44; - tPak->bPakInserted = LoadCart( &tPak->gbCart, g_pcControllers[iControl].szTransferRom, g_pcControllers[iControl].szTransferSave, _T("") ); + tPak->bPakInserted = LoadCart( &tPak->gbCart, g_pcControllers[iControl].szTransferRom, g_pcControllers[iControl].szTransferSave, _T("") ); - if (tPak->bPakInserted) - { - DebugWriteA( "*** Init Transfer Pak - Success***\n" ); - } - else - { - DebugWriteA( "*** Init Transfer Pak - FAILURE***\n" ); - } + if (tPak->bPakInserted) + { + DebugWriteA( "*** Init Transfer Pak - Success***\n" ); + } + else + { + DebugWriteA( "*** Init Transfer Pak - FAILURE***\n" ); + } - bReturn = true; - } - break; - /*case PAK_VOICE: - { - g_pcControllers[iControl].pPakData = P_malloc( sizeof(VOICEPAK)); - VOICEPAK *vPak = (VOICEPAK*)g_pcControllers[iControl].pPakData; - vPak->bPakType = PAK_VOICE; + bReturn = true; + } + break; + /*case PAK_VOICE: + { + g_pcControllers[iControl].pPakData = P_malloc( sizeof(VOICEPAK)); + VOICEPAK *vPak = (VOICEPAK*)g_pcControllers[iControl].pPakData; + vPak->bPakType = PAK_VOICE; - bReturn = true; - } - break;*/ - case PAK_ADAPTOID: - if( !g_pcControllers[iControl].fIsAdaptoid ) - g_pcControllers[iControl].PakType = PAK_NONE; - else - { - g_pcControllers[iControl].pPakData = P_malloc( sizeof(ADAPTOIDPAK)); - ADAPTOIDPAK *aPak = (ADAPTOIDPAK*)g_pcControllers[iControl].pPakData; - aPak->bPakType = PAK_ADAPTOID; + bReturn = true; + } + break;*/ + case PAK_ADAPTOID: + if( !g_pcControllers[iControl].fIsAdaptoid ) + g_pcControllers[iControl].PakType = PAK_NONE; + else + { + g_pcControllers[iControl].pPakData = P_malloc( sizeof(ADAPTOIDPAK)); + ADAPTOIDPAK *aPak = (ADAPTOIDPAK*)g_pcControllers[iControl].pPakData; + aPak->bPakType = PAK_ADAPTOID; - aPak->bIdentifier = 0x80; + aPak->bIdentifier = 0x80; #ifdef ADAPTOIDPAK_RUMBLEFIX - aPak->fRumblePak = true; + aPak->fRumblePak = true; #pragma message( "Driver-fix for Rumble with Adaptoid enabled" ) #else - aPak->fRumblePak = false; + aPak->fRumblePak = false; #endif - bReturn = true; - } - break; - /*case PAK_NONE: - break;*/ - } + bReturn = true; + } + break; + /*case PAK_NONE: + break;*/ + } - // if there were any unrecoverable errors and we have allocated pPakData, free it and set paktype to NONE - if( !bReturn && g_pcControllers[iControl].pPakData ) - CloseControllerPak( iControl ); + // if there were any unrecoverable errors and we have allocated pPakData, free it and set paktype to NONE + if( !bReturn && g_pcControllers[iControl].pPakData ) + CloseControllerPak( iControl ); - return bReturn; + return bReturn; } BYTE ReadControllerPak( const int iControl, LPBYTE Command ) { - BYTE bReturn = RD_ERROR; - LPBYTE Data = &Command[2]; + BYTE bReturn = RD_ERROR; + LPBYTE Data = &Command[2]; #ifdef MAKEADRESSCRCCHECK #pragma message( "Addresscheck for Pak-Reads active" ) - if( AddressCRC( Command ) != (Command[1] & 0x1F) ) - { - g_pcControllers[iControl].fPakCRCError = true; - if( WarningMessage( IDS_DLG_MEM_BADADDRESSCRC, MB_OKCANCEL | MB_ICONQUESTION ) == IDCANCEL ) - return RD_ERROR; - } + if( AddressCRC( Command ) != (Command[1] & 0x1F) ) + { + g_pcControllers[iControl].fPakCRCError = true; + if( WarningMessage( IDS_DLG_MEM_BADADDRESSCRC, MB_OKCANCEL | MB_ICONQUESTION ) == IDCANCEL ) + return RD_ERROR; + } #endif - if( !g_pcControllers[iControl].pPakData ) - return RD_ERROR; + if( !g_pcControllers[iControl].pPakData ) + return RD_ERROR; - WORD dwAddress = (Command[0] << 8) + (Command[1] & 0xE0); + WORD dwAddress = (Command[0] << 8) + (Command[1] & 0xE0); - switch( *(BYTE*)g_pcControllers[iControl].pPakData ) - { - case PAK_MEM: - { - MEMPAK *mPak = (MEMPAK*)g_pcControllers[iControl].pPakData; - - if( dwAddress < 0x8000 ) - CopyMemory( Data, &mPak->aMemPakData[dwAddress], 32 ); - else - CopyMemory( Data, &mPak->aMemPakTemp[(dwAddress%0x100)], 32 ); - Data[32] = DataCRC( Data, 32 ); - bReturn = RD_OK; - } - break; - case PAK_RUMBLE: - if(( dwAddress >= 0x8000 ) && ( dwAddress < 0x9000 ) ) - { - RUMBLEPAK *rPak = (RUMBLEPAK*)g_pcControllers[iControl].pPakData; + switch( *(BYTE*)g_pcControllers[iControl].pPakData ) + { + case PAK_MEM: + { + MEMPAK *mPak = (MEMPAK*)g_pcControllers[iControl].pPakData; - if (rPak->fLastData) - FillMemory( Data, 32, 0x80 ); - else - ZeroMemory( Data, 32 ); + if( dwAddress < 0x8000 ) + CopyMemory( Data, &mPak->aMemPakData[dwAddress], 32 ); + else + CopyMemory( Data, &mPak->aMemPakTemp[(dwAddress%0x100)], 32 ); + Data[32] = DataCRC( Data, 32 ); + bReturn = RD_OK; + } + break; + case PAK_RUMBLE: + if(( dwAddress >= 0x8000 ) && ( dwAddress < 0x9000 ) ) + { + RUMBLEPAK *rPak = (RUMBLEPAK*)g_pcControllers[iControl].pPakData; - if( g_pcControllers[iControl].fXInput ) // xinput controller rumble --tecnicors - VibrateXInputController( g_pcControllers[iControl].xiController.nControl, 0, 0); - else if (g_apFFDevice[iControl]) - g_apFFDevice[iControl]->Acquire(); - } - else - ZeroMemory( Data, 32 ); + if (rPak->fLastData) + FillMemory( Data, 32, 0x80 ); + else + ZeroMemory( Data, 32 ); - Data[32] = DataCRC( Data, 32 ); - bReturn = RD_OK; - break; + if( g_pcControllers[iControl].fXInput ) // xinput controller rumble --tecnicors + VibrateXInputController( g_pcControllers[iControl].xiController.nControl, 0, 0); + else if (g_apFFDevice[iControl]) + g_apFFDevice[iControl]->Acquire(); + } + else + ZeroMemory( Data, 32 ); - case PAK_TRANSFER: - { - LPTRANSFERPAK tPak = (LPTRANSFERPAK)g_pcControllers[iControl].pPakData; // TODO: null pointer check on tPak - // set bReturn = RD_OK when implementing Transferpak - bReturn = RD_OK; - DebugWriteA( "TPak Read:\n" ); - DebugWriteA( " Address: %04X\n", dwAddress ); + Data[32] = DataCRC( Data, 32 ); + bReturn = RD_OK; + break; - switch (dwAddress >> 12) - { - case 0x8: // if ((dwAddress >= 0x8000) && (dwAddress <= 0x8FFF)) - DebugWriteA( "Query Enable State: %u\n", tPak->iEnableState ); - if (tPak->iEnableState == false) - ZeroMemory(Data, 32); - else - FillMemory(Data, 32, 0x84); - break; - case 0xB: // if ((dwAddress >= 0xB000) && (dwAddress <= 0xBFFF)) - if (tPak->iEnableState == true) - { - DebugWriteA( "Query Cart. State:" ); - if (tPak->bPakInserted) - { - if (tPak->iCurrentAccessMode == 1) - { - FillMemory(Data, 32, 0x89); - DebugWriteA( " Inserted, Access Mode 1\n" ); - } - else - { - FillMemory(Data, 32, 0x80); - DebugWriteA( " Inserted, Access Mode 0\n" ); - } - Data[0] = Data[0] | tPak->iAccessModeChanged; - } - else - { - FillMemory(Data, 32, 0x40); // Cart not inserted. - DebugWriteA( " Not Inserted\n" ); - } - tPak->iAccessModeChanged = 0; - } - break; - case 0xC: - case 0xD: - case 0xE: - case 0xF: // if ((dwAddress >= 0xC000)) - if (tPak->iEnableState == true) - { - DebugWriteA( "Cart Read: Bank:%i\n", tPak->iCurrentBankNo ); - DebugWriteA( " Address:%04X\n", ((dwAddress & 0xFFE0) - 0xC000) + ((tPak->iCurrentBankNo & 3) * 0x4000) ); + case PAK_TRANSFER: + { + LPTRANSFERPAK tPak = (LPTRANSFERPAK)g_pcControllers[iControl].pPakData; // TODO: null pointer check on tPak + // set bReturn = RD_OK when implementing Transferpak + bReturn = RD_OK; + DebugWriteA( "TPak Read:\n" ); + DebugWriteA( " Address: %04X\n", dwAddress ); - tPak->gbCart.ptrfnReadCart(&tPak->gbCart, ((dwAddress & 0xFFE0) - 0xC000) + ((tPak->iCurrentBankNo & 3) * 0x4000), Data); - } - break; - default: - DebugWriteA("WARNING: Unusual Pak Read\n" ); - DebugWriteA(" Address: %04X\n", dwAddress); - } // end switch (dwAddress >> 12) + switch (dwAddress >> 12) + { + case 0x8: // if ((dwAddress >= 0x8000) && (dwAddress <= 0x8FFF)) + DebugWriteA( "Query Enable State: %u\n", tPak->iEnableState ); + if (tPak->iEnableState == false) + ZeroMemory(Data, 32); + else + FillMemory(Data, 32, 0x84); + break; + case 0xB: // if ((dwAddress >= 0xB000) && (dwAddress <= 0xBFFF)) + if (tPak->iEnableState == true) + { + DebugWriteA( "Query Cart. State:" ); + if (tPak->bPakInserted) + { + if (tPak->iCurrentAccessMode == 1) + { + FillMemory(Data, 32, 0x89); + DebugWriteA( " Inserted, Access Mode 1\n" ); + } + else + { + FillMemory(Data, 32, 0x80); + DebugWriteA( " Inserted, Access Mode 0\n" ); + } + Data[0] = Data[0] | tPak->iAccessModeChanged; + } + else + { + FillMemory(Data, 32, 0x40); // Cart not inserted. + DebugWriteA( " Not Inserted\n" ); + } + tPak->iAccessModeChanged = 0; + } + break; + case 0xC: + case 0xD: + case 0xE: + case 0xF: // if ((dwAddress >= 0xC000)) + if (tPak->iEnableState == true) + { + DebugWriteA( "Cart Read: Bank:%i\n", tPak->iCurrentBankNo ); + DebugWriteA( " Address:%04X\n", ((dwAddress & 0xFFE0) - 0xC000) + ((tPak->iCurrentBankNo & 3) * 0x4000) ); + + tPak->gbCart.ptrfnReadCart(&tPak->gbCart, ((dwAddress & 0xFFE0) - 0xC000) + ((tPak->iCurrentBankNo & 3) * 0x4000), Data); + } + break; + default: + DebugWriteA("WARNING: Unusual Pak Read\n" ); + DebugWriteA(" Address: %04X\n", dwAddress); + } // end switch (dwAddress >> 12) #ifdef ENABLE_RAWPAK_DEBUG - DebugWriteA( "TPak Data: " ); + DebugWriteA( "TPak Data: " ); - for (int i = 0; i < 32; i ++) - { - if ((i < 31) && ((i & 7) == 0)) DebugWriteA( "\n " ); - DebugWriteByteA(Data[i]); - if (i < 31) - { - DebugWriteA( ", "); - } - } - DebugWriteA( "\n" ); + for (int i = 0; i < 32; i ++) + { + if ((i < 31) && ((i & 7) == 0)) DebugWriteA( "\n " ); + DebugWriteByteA(Data[i]); + if (i < 31) + { + DebugWriteA( ", "); + } + } + DebugWriteA( "\n" ); #endif - Data[32] = DataCRC( Data, 32 ); + Data[32] = DataCRC( Data, 32 ); - bReturn = RD_OK; - } - break; - /*case PAK_VOICE: - break;*/ - case PAK_ADAPTOID: - if( ReadAdaptoidPak( iControl, dwAddress, Data ) == DI_OK ) - { - Data[32] = DataCRC( Data, 32 ); - bReturn = RD_OK; + bReturn = RD_OK; + } + break; + /*case PAK_VOICE: + break;*/ + case PAK_ADAPTOID: + if( ReadAdaptoidPak( iControl, dwAddress, Data ) == DI_OK ) + { + Data[32] = DataCRC( Data, 32 ); + bReturn = RD_OK; - if( ((ADAPTOIDPAK*)g_pcControllers[iControl].pPakData)->fRumblePak ) - { - BYTE bId = ((ADAPTOIDPAK*)g_pcControllers[iControl].pPakData)->bIdentifier; - if( (( dwAddress == 0x8000 ) && ( bId == 0x80 ) && ( Data[0] != 0x80 )) - || (( dwAddress == 0x8000 ) && ( bId != 0x80 ) && ( Data[0] != 0x00 )) - || (( dwAddress < 0x8000 ) && ( Data[0] != 0x00 ))) - { - ((ADAPTOIDPAK*)g_pcControllers[iControl].pPakData)->fRumblePak = false; - DebugWriteA( "\nAssuming the inserted Pak AINT a RumblePak\nDisabling Rumblefix\n" ); - } - } - } - break; + if( ((ADAPTOIDPAK*)g_pcControllers[iControl].pPakData)->fRumblePak ) + { + BYTE bId = ((ADAPTOIDPAK*)g_pcControllers[iControl].pPakData)->bIdentifier; + if( (( dwAddress == 0x8000 ) && ( bId == 0x80 ) && ( Data[0] != 0x80 )) + || (( dwAddress == 0x8000 ) && ( bId != 0x80 ) && ( Data[0] != 0x00 )) + || (( dwAddress < 0x8000 ) && ( Data[0] != 0x00 ))) + { + ((ADAPTOIDPAK*)g_pcControllers[iControl].pPakData)->fRumblePak = false; + DebugWriteA( "\nAssuming the inserted Pak AINT a RumblePak\nDisabling Rumblefix\n" ); + } + } + } + break; - /*case PAK_NONE: - break;*/ - } + /*case PAK_NONE: + break;*/ + } - return bReturn; + return bReturn; } // Called when the N64 tries to write to the controller pak, e.g. a mempak BYTE WriteControllerPak( const int iControl, LPBYTE Command ) { - BYTE bReturn = RD_ERROR; - BYTE *Data = &Command[2]; + BYTE bReturn = RD_ERROR; + BYTE *Data = &Command[2]; #ifdef MAKEADRESSCRCCHECK #pragma message( "Addresscheck for Pak-Writes active" ) - if( AddressCRC( Command ) != (Command[1] & 0x1F) ) - { - g_pcControllers[iControl].fPakCRCError = true; - if( WarningMessage( IDS_DLG_MEM_BADADDRESSCRC, MB_OKCANCEL | MB_ICONQUESTION ) == IDCANCEL ) - return RD_ERROR; - } + if( AddressCRC( Command ) != (Command[1] & 0x1F) ) + { + g_pcControllers[iControl].fPakCRCError = true; + if( WarningMessage( IDS_DLG_MEM_BADADDRESSCRC, MB_OKCANCEL | MB_ICONQUESTION ) == IDCANCEL ) + return RD_ERROR; + } #endif - if( !g_pcControllers[iControl].pPakData ) - return RD_ERROR; + if( !g_pcControllers[iControl].pPakData ) + return RD_ERROR; - WORD dwAddress = (Command[0] << 8) + (Command[1] & 0xE0); + WORD dwAddress = (Command[0] << 8) + (Command[1] & 0xE0); - switch( *(BYTE*)g_pcControllers[iControl].pPakData ) - { - case PAK_MEM: - { - // Switched to memory-mapped file - // That way, if the computer dies due to power loss or something mid-play, the savegame is still there. - MEMPAK *mPak = (MEMPAK*)g_pcControllers[iControl].pPakData; + switch( *(BYTE*)g_pcControllers[iControl].pPakData ) + { + case PAK_MEM: + { + // Switched to memory-mapped file + // That way, if the computer dies due to power loss or something mid-play, the savegame is still there. + MEMPAK *mPak = (MEMPAK*)g_pcControllers[iControl].pPakData; - if( dwAddress < 0x8000 ) - { - CopyMemory( &mPak->aMemPakData[dwAddress], Data, 32 ); - if (!mPak->fReadonly ) - SetTimer( g_strEmuInfo.hMainWindow, PAK_MEM, 2000, (TIMERPROC) WritebackProc ); // if we go 2 seconds without a write, call the Writeback proc (which will flush the cache) - } - else - CopyMemory( &mPak->aMemPakTemp[(dwAddress%0x100)], Data, 32 ); - Data[32] = DataCRC( Data, 32 ); - bReturn = RD_OK; - } - break; - case PAK_RUMBLE: - if( dwAddress == PAK_IO_RUMBLE ) - { - if( g_pcControllers[iControl].fXInput ) // xinput controller rumble --tecnicors - { - if( *Data ) - VibrateXInputController( g_pcControllers[iControl].xiController.nControl ); - else - VibrateXInputController( g_pcControllers[iControl].xiController.nControl, 0, 0 ); - goto end_rumble; - } + if( dwAddress < 0x8000 ) + { + CopyMemory( &mPak->aMemPakData[dwAddress], Data, 32 ); + if (!mPak->fReadonly ) + SetTimer( g_strEmuInfo.hMainWindow, PAK_MEM, 2000, (TIMERPROC) WritebackProc ); // if we go 2 seconds without a write, call the Writeback proc (which will flush the cache) + } + else + CopyMemory( &mPak->aMemPakTemp[(dwAddress%0x100)], Data, 32 ); + Data[32] = DataCRC( Data, 32 ); + bReturn = RD_OK; + } + break; + case PAK_RUMBLE: + if( dwAddress == PAK_IO_RUMBLE ) + { + if( g_pcControllers[iControl].fXInput ) // xinput controller rumble --tecnicors + { + if( *Data ) + VibrateXInputController( g_pcControllers[iControl].xiController.nControl ); + else + VibrateXInputController( g_pcControllers[iControl].xiController.nControl, 0, 0 ); + goto end_rumble; + } - if( g_pcControllers[iControl].fVisualRumble ) - FlashWindow( g_strEmuInfo.hMainWindow, ( *Data != 0 ) ? TRUE : FALSE ); - if( g_pcControllers[iControl].bRumbleTyp == RUMBLE_DIRECT ) - { // Adaptoid Direct Rumble - if( g_pcControllers[iControl].fIsAdaptoid ) - DirectRumbleCommand( iControl, *Data ); - } - else - { // FF-FeedBack Rumble - if( g_apdiEffect[iControl] ) - { - g_apFFDevice[iControl]->Acquire(); - if( *Data ) - { - // g_apdiEffect[iControl]->Start( 1, DIES_SOLO ); - HRESULT hr; - hr = g_apdiEffect[iControl]->Start( 1, DIES_NODOWNLOAD ); - if( hr != DI_OK )// just download if needed( seems to work smoother) - { - hr = g_apdiEffect[iControl]->Start( 1, 0 ); - if (hr != DI_OK) - { - DebugWriteA("Rumble: Can't rumble %d: %lX\n", iControl, hr); - } - else - DebugWriteA("Rumble: DIES_NODOWNLOAD failed, regular OK on control %d\n", iControl); - } - else - DebugWriteA("Rumble: DIES_NODOWNLOAD OK on control %d\n", iControl); - } - else - { - g_apdiEffect[iControl]->Stop(); - } - } - } - } - else if (dwAddress >= 0x8000 && dwAddress < 0x9000) - { - RUMBLEPAK *rPak = (RUMBLEPAK*)g_pcControllers[iControl].pPakData; - rPak->fLastData = (*Data) ? true : false; - } + if( g_pcControllers[iControl].fVisualRumble ) + FlashWindow( g_strEmuInfo.hMainWindow, ( *Data != 0 ) ? TRUE : FALSE ); + if( g_pcControllers[iControl].bRumbleTyp == RUMBLE_DIRECT ) + { // Adaptoid Direct Rumble + if( g_pcControllers[iControl].fIsAdaptoid ) + DirectRumbleCommand( iControl, *Data ); + } + else + { // FF-FeedBack Rumble + if( g_apdiEffect[iControl] ) + { + g_apFFDevice[iControl]->Acquire(); + if( *Data ) + { + // g_apdiEffect[iControl]->Start( 1, DIES_SOLO ); + HRESULT hr; + hr = g_apdiEffect[iControl]->Start( 1, DIES_NODOWNLOAD ); + if( hr != DI_OK )// just download if needed( seems to work smoother) + { + hr = g_apdiEffect[iControl]->Start( 1, 0 ); + if (hr != DI_OK) + { + DebugWriteA("Rumble: Can't rumble %d: %lX\n", iControl, hr); + } + else + DebugWriteA("Rumble: DIES_NODOWNLOAD failed, regular OK on control %d\n", iControl); + } + else + DebugWriteA("Rumble: DIES_NODOWNLOAD OK on control %d\n", iControl); + } + else + { + g_apdiEffect[iControl]->Stop(); + } + } + } + } + else if (dwAddress >= 0x8000 && dwAddress < 0x9000) + { + RUMBLEPAK *rPak = (RUMBLEPAK*)g_pcControllers[iControl].pPakData; + rPak->fLastData = (*Data) ? true : false; + } -end_rumble: // added so after xinput controller rumbles, gets here --tecnicors - Data[32] = DataCRC( Data, 32 ); - bReturn = RD_OK; - break; - case PAK_TRANSFER: - { - LPTRANSFERPAK tPak = (LPTRANSFERPAK)g_pcControllers[iControl].pPakData; - // set bReturn = RD_OK when implementing Transferpak - DebugWriteA( "TPak Write:\n" ); - DebugWriteA( " Address: %04X\n", dwAddress ); +end_rumble: // added so after xinput controller rumbles, gets here --tecnicors + Data[32] = DataCRC( Data, 32 ); + bReturn = RD_OK; + break; + case PAK_TRANSFER: + { + LPTRANSFERPAK tPak = (LPTRANSFERPAK)g_pcControllers[iControl].pPakData; + // set bReturn = RD_OK when implementing Transferpak + DebugWriteA( "TPak Write:\n" ); + DebugWriteA( " Address: %04X\n", dwAddress ); #ifdef ENABLE_RAWPAK_DEBUG - DebugWriteA( " Data: "); + DebugWriteA( " Data: "); - for (int i = 0; i < 32; i++) - { - if ((i < 31) && ((i & 7) == 0)) - { - DebugWriteA( "\n " ); - } - DebugWriteByteA( Data[i]); - if (i < 31) - { - DebugWriteA( ", " ); - } - } + for (int i = 0; i < 32; i++) + { + if ((i < 31) && ((i & 7) == 0)) + { + DebugWriteA( "\n " ); + } + DebugWriteByteA( Data[i]); + if (i < 31) + { + DebugWriteA( ", " ); + } + } - DebugWriteA( "\n" ); + DebugWriteA( "\n" ); #endif // #ifdef ENABLE_RAWPAK_DEBUG - switch (dwAddress >> 12) - { - case 0x8: // if ((dwAddress >= 0x8000) && (dwAddress <= 0x8FFF)) - if (Data[0] == 0xFE) - { - DebugWriteA("Cart Disable\n" ); - tPak->iEnableState = false; - } - else if (Data[0] == 0x84) - { - DebugWriteA("Cart Enable\n" ); - tPak->iEnableState = true; - } - else - { - DebugWriteA("WARNING: Unusual Cart Enable/Disable\n" ); - DebugWriteA(" Address: " ); - DebugWriteWordA(dwAddress); - DebugWriteA("\n" ); - DebugWriteA(" Data: " ); - DebugWriteByteA(Data[0]); - DebugWriteA("\n" ); - } - break; - case 0xA: // if ((dwAddress >= 0xA000) && (dwAddress <= 0xAFFF)) - if (tPak->iEnableState == true) - { - tPak->iCurrentBankNo = Data[0]; - DebugWriteA("Set TPak Bank No:%02X\n", Data[0] ); - } - break; - case 0xB: // if ((dwAddress >= 0xB000) && (dwAddress <= 0xBFFF)) - if (tPak->iEnableState == true) - { - tPak->iCurrentAccessMode = Data[0] & 1; - tPak->iAccessModeChanged = 4; - DebugWriteA("Set TPak Access Mode: %04X\n", tPak->iCurrentAccessMode); - if ((Data[0] != 1) && (Data[0] != 0)) - { - DebugWriteA("WARNING: Unusual Access Mode Change\n" ); - DebugWriteA(" Address: " ); - DebugWriteWordA(dwAddress); - DebugWriteA("\n" ); - DebugWriteA(" Data: " ); - DebugWriteByteA(Data[0]); - DebugWriteA("\n" ); - } - } - break; - case 0xC: - case 0xD: - case 0xE: - case 0xF: // if (dwAddress >= 0xC000) - tPak->gbCart.ptrfnWriteCart(&tPak->gbCart, ((dwAddress & 0xFFE0) - 0xC000) + ((tPak->iCurrentBankNo & 3) * 0x4000), Data); - if (tPak->gbCart.hRamFile != NULL ) - SetTimer( g_strEmuInfo.hMainWindow, PAK_TRANSFER, 2000, (TIMERPROC) WritebackProc ); // if we go 2 seconds without a write, call the Writeback proc (which will flush the cache) - break; - default: - DebugWriteA("WARNING: Unusual Pak Write\n" ); - DebugWriteA(" Address: %04X\n", dwAddress); - } // end switch (dwAddress >> 12) + switch (dwAddress >> 12) + { + case 0x8: // if ((dwAddress >= 0x8000) && (dwAddress <= 0x8FFF)) + if (Data[0] == 0xFE) + { + DebugWriteA("Cart Disable\n" ); + tPak->iEnableState = false; + } + else if (Data[0] == 0x84) + { + DebugWriteA("Cart Enable\n" ); + tPak->iEnableState = true; + } + else + { + DebugWriteA("WARNING: Unusual Cart Enable/Disable\n" ); + DebugWriteA(" Address: " ); + DebugWriteWordA(dwAddress); + DebugWriteA("\n" ); + DebugWriteA(" Data: " ); + DebugWriteByteA(Data[0]); + DebugWriteA("\n" ); + } + break; + case 0xA: // if ((dwAddress >= 0xA000) && (dwAddress <= 0xAFFF)) + if (tPak->iEnableState == true) + { + tPak->iCurrentBankNo = Data[0]; + DebugWriteA("Set TPak Bank No:%02X\n", Data[0] ); + } + break; + case 0xB: // if ((dwAddress >= 0xB000) && (dwAddress <= 0xBFFF)) + if (tPak->iEnableState == true) + { + tPak->iCurrentAccessMode = Data[0] & 1; + tPak->iAccessModeChanged = 4; + DebugWriteA("Set TPak Access Mode: %04X\n", tPak->iCurrentAccessMode); + if ((Data[0] != 1) && (Data[0] != 0)) + { + DebugWriteA("WARNING: Unusual Access Mode Change\n" ); + DebugWriteA(" Address: " ); + DebugWriteWordA(dwAddress); + DebugWriteA("\n" ); + DebugWriteA(" Data: " ); + DebugWriteByteA(Data[0]); + DebugWriteA("\n" ); + } + } + break; + case 0xC: + case 0xD: + case 0xE: + case 0xF: // if (dwAddress >= 0xC000) + tPak->gbCart.ptrfnWriteCart(&tPak->gbCart, ((dwAddress & 0xFFE0) - 0xC000) + ((tPak->iCurrentBankNo & 3) * 0x4000), Data); + if (tPak->gbCart.hRamFile != NULL ) + SetTimer( g_strEmuInfo.hMainWindow, PAK_TRANSFER, 2000, (TIMERPROC) WritebackProc ); // if we go 2 seconds without a write, call the Writeback proc (which will flush the cache) + break; + default: + DebugWriteA("WARNING: Unusual Pak Write\n" ); + DebugWriteA(" Address: %04X\n", dwAddress); + } // end switch (dwAddress >> 12) - Data[32] = DataCRC( Data, 32 ); - bReturn = RD_OK; - } - break; - /*case PAK_VOICE: - break;*/ - case PAK_ADAPTOID: - if(( dwAddress == PAK_IO_RUMBLE ) && ((ADAPTOIDPAK*)g_pcControllers[iControl].pPakData)->fRumblePak ) - { - if( DirectRumbleCommand( iControl, *Data ) == DI_OK ) - { - Data[32] = DataCRC( Data, 32 ); - bReturn = RD_OK; - } - } - else - { - if( WriteAdaptoidPak( iControl, dwAddress, Data ) == DI_OK ) - { - Data[32] = DataCRC( Data, 32 ); - if( dwAddress == 0x8000 ) - ((ADAPTOIDPAK*)g_pcControllers[iControl].pPakData)->bIdentifier = Data[0]; + Data[32] = DataCRC( Data, 32 ); + bReturn = RD_OK; + } + break; + /*case PAK_VOICE: + break;*/ + case PAK_ADAPTOID: + if(( dwAddress == PAK_IO_RUMBLE ) && ((ADAPTOIDPAK*)g_pcControllers[iControl].pPakData)->fRumblePak ) + { + if( DirectRumbleCommand( iControl, *Data ) == DI_OK ) + { + Data[32] = DataCRC( Data, 32 ); + bReturn = RD_OK; + } + } + else + { + if( WriteAdaptoidPak( iControl, dwAddress, Data ) == DI_OK ) + { + Data[32] = DataCRC( Data, 32 ); + if( dwAddress == 0x8000 ) + ((ADAPTOIDPAK*)g_pcControllers[iControl].pPakData)->bIdentifier = Data[0]; - bReturn = RD_OK; - } - } - break; - /*case PAK_NONE: - break;*/ - } + bReturn = RD_OK; + } + } + break; + /*case PAK_NONE: + break;*/ + } - return bReturn; + return bReturn; } void SaveControllerPak( const int iControl ) { - if( !g_pcControllers[iControl].pPakData ) - return; + if( !g_pcControllers[iControl].pPakData ) + return; - switch( *(BYTE*)g_pcControllers[iControl].pPakData ) - { - case PAK_MEM: - { - MEMPAK *mPak = (MEMPAK*)g_pcControllers[iControl].pPakData; + switch( *(BYTE*)g_pcControllers[iControl].pPakData ) + { + case PAK_MEM: + { + MEMPAK *mPak = (MEMPAK*)g_pcControllers[iControl].pPakData; - if( !mPak->fReadonly ) - FlushViewOfFile( mPak->aMemPakData, PAK_MEM_SIZE ); // we've already written the stuff, just flush the cache - } - break; - case PAK_RUMBLE: - break; - case PAK_TRANSFER: - { - LPTRANSFERPAK tPak = (LPTRANSFERPAK)g_pcControllers[iControl].pPakData; - // here the changes( if any ) in the SRAM should be saved + if( !mPak->fReadonly ) + FlushViewOfFile( mPak->aMemPakData, PAK_MEM_SIZE ); // we've already written the stuff, just flush the cache + } + break; + case PAK_RUMBLE: + break; + case PAK_TRANSFER: + { + LPTRANSFERPAK tPak = (LPTRANSFERPAK)g_pcControllers[iControl].pPakData; + // here the changes( if any ) in the SRAM should be saved - if (tPak->gbCart.hRamFile != NULL) - { - SaveCart(&tPak->gbCart, g_pcControllers[iControl].szTransferSave, _T("")); - DebugWriteA( "*** Save Transfer Pak ***\n" ); - } - } - break; - case PAK_VOICE: - break; - case PAK_ADAPTOID: - break; - /*case PAK_NONE: - break;*/ - } + if (tPak->gbCart.hRamFile != NULL) + { + SaveCart(&tPak->gbCart, g_pcControllers[iControl].szTransferSave, _T("")); + DebugWriteA( "*** Save Transfer Pak ***\n" ); + } + } + break; + case PAK_VOICE: + break; + case PAK_ADAPTOID: + break; + /*case PAK_NONE: + break;*/ + } } // if there is pPakData for the controller, does any closing of handles before freeing the pPakData struct and setting it to NULL // also sets fPakInitialized to false void CloseControllerPak( const int iControl ) { - if( !g_pcControllers[iControl].pPakData ) - return; + if( !g_pcControllers[iControl].pPakData ) + return; - g_pcControllers[iControl].fPakInitialized = false; + g_pcControllers[iControl].fPakInitialized = false; - switch( *(BYTE*)g_pcControllers[iControl].pPakData ) - { - case PAK_MEM: - { - MEMPAK *mPak = (MEMPAK*)g_pcControllers[iControl].pPakData; - - if( mPak->fReadonly ) - { - P_free( mPak->aMemPakData ); - mPak->aMemPakData = NULL; - } - else - { - FlushViewOfFile( mPak->aMemPakData, PAK_MEM_SIZE ); - // if it's a dexsave, our original mapped view is not aMemPakData - UnmapViewOfFile( mPak->fDexSave ? mPak->aMemPakData - PAK_MEM_DEXOFFSET : mPak->aMemPakData ); - if ( mPak->hMemPakHandle != NULL ) - CloseHandle( mPak->hMemPakHandle ); - } - } - break; - case PAK_RUMBLE: - ReleaseEffect( g_apdiEffect[iControl] ); - g_apdiEffect[iControl] = NULL; - break; - case PAK_TRANSFER: - { - LPTRANSFERPAK tPak = (LPTRANSFERPAK)g_pcControllers[iControl].pPakData; - UnloadCart(&tPak->gbCart); - DebugWriteA( "*** Close Transfer Pak ***\n" ); - // close files and free any additionally ressources - } - break; - case PAK_VOICE: - break; - case PAK_ADAPTOID: - break; - /*case PAK_NONE: - break;*/ - } + switch( *(BYTE*)g_pcControllers[iControl].pPakData ) + { + case PAK_MEM: + { + MEMPAK *mPak = (MEMPAK*)g_pcControllers[iControl].pPakData; - freePakData( &g_pcControllers[iControl] ); - return; + if( mPak->fReadonly ) + { + P_free( mPak->aMemPakData ); + mPak->aMemPakData = NULL; + } + else + { + FlushViewOfFile( mPak->aMemPakData, PAK_MEM_SIZE ); + // if it's a dexsave, our original mapped view is not aMemPakData + UnmapViewOfFile( mPak->fDexSave ? mPak->aMemPakData - PAK_MEM_DEXOFFSET : mPak->aMemPakData ); + if ( mPak->hMemPakHandle != NULL ) + CloseHandle( mPak->hMemPakHandle ); + } + } + break; + case PAK_RUMBLE: + ReleaseEffect( g_apdiEffect[iControl] ); + g_apdiEffect[iControl] = NULL; + break; + case PAK_TRANSFER: + { + LPTRANSFERPAK tPak = (LPTRANSFERPAK)g_pcControllers[iControl].pPakData; + UnloadCart(&tPak->gbCart); + DebugWriteA( "*** Close Transfer Pak ***\n" ); + // close files and free any additionally ressources + } + break; + case PAK_VOICE: + break; + case PAK_ADAPTOID: + break; + /*case PAK_NONE: + break;*/ + } + + freePakData( &g_pcControllers[iControl] ); + return; } // returns the number of remaining blocks in a mempak // aNoteSizes should be an array of 16 bytes, which will be overwritten with the size in blocks of each note inline WORD CountBlocks( const unsigned char * bMemPakBinary, LPBYTE aNoteSizes ) { - WORD wRemainingBlocks = 123; - BYTE bNextIndex; - int i = 0; - while( i < 16 && wRemainingBlocks <= 123 ) - { - aNoteSizes[i] = 0; - bNextIndex = bMemPakBinary[0x307 + (i*0x20)]; - while(( bNextIndex >= 5 ) && ( aNoteSizes[i] < wRemainingBlocks)) - { - aNoteSizes[i]++; - bNextIndex = bMemPakBinary[0x101 + (bNextIndex*2)]; - } + WORD wRemainingBlocks = 123; + BYTE bNextIndex; + int i = 0; + while( i < 16 && wRemainingBlocks <= 123 ) + { + aNoteSizes[i] = 0; + bNextIndex = bMemPakBinary[0x307 + (i*0x20)]; + while(( bNextIndex >= 5 ) && ( aNoteSizes[i] < wRemainingBlocks)) + { + aNoteSizes[i]++; + bNextIndex = bMemPakBinary[0x101 + (bNextIndex*2)]; + } - if( aNoteSizes[i] > wRemainingBlocks ) - wRemainingBlocks = 0xFF; - else - wRemainingBlocks -= aNoteSizes[i]; - - i++; - } - return wRemainingBlocks; + if( aNoteSizes[i] > wRemainingBlocks ) + wRemainingBlocks = 0xFF; + else + wRemainingBlocks -= aNoteSizes[i]; + + i++; + } + return wRemainingBlocks; } void FormatMemPak( LPBYTE aMemPak ) { - size_t iRand, n; + size_t iRand, n; - FillMemory(aMemPak, 0x100, 0xFF); - aMemPak[0] = 0x81; + FillMemory(aMemPak, 0x100, 0xFF); + aMemPak[0] = 0x81; - // generate a valid code( i hope i can calculate it one day) - BYTE aValidCodes[] = { 0x12, 0xC5, 0x8F, 0x6F, 0xA4, 0x28, 0x5B, 0xCA }; - BYTE aCode[8]; + // generate a valid code( i hope i can calculate it one day) + BYTE aValidCodes[] = { 0x12, 0xC5, 0x8F, 0x6F, 0xA4, 0x28, 0x5B, 0xCA }; + BYTE aCode[8]; - iRand = ((size_t)aMemPak / 4) + ((size_t)g_strEmuInfo.hMainWindow / 4); - iRand %= sizeof(aValidCodes) / 8; - for (n = 0; n < 8; n++) - aCode[n] = aValidCodes[n + iRand]; + iRand = ((size_t)aMemPak / 4) + ((size_t)g_strEmuInfo.hMainWindow / 4); + iRand %= sizeof(aValidCodes) / 8; + for (n = 0; n < 8; n++) + aCode[n] = aValidCodes[n + iRand]; - //---------- + //---------- - aMemPak[0x20+0] = aMemPak[0x60+0] = aMemPak[0x80+0] = aMemPak[0xC0+0] = 0xFF; - aMemPak[0x20+1] = aMemPak[0x60+1] = aMemPak[0x80+1] = aMemPak[0xC0+1] = 0xFF; - aMemPak[0x20+2] = aMemPak[0x60+2] = aMemPak[0x80+2] = aMemPak[0xC0+2] = 0xFF; - aMemPak[0x20+3] = aMemPak[0x60+3] = aMemPak[0x80+3] = aMemPak[0xC0+3] = 0xFF; + aMemPak[0x20+0] = aMemPak[0x60+0] = aMemPak[0x80+0] = aMemPak[0xC0+0] = 0xFF; + aMemPak[0x20+1] = aMemPak[0x60+1] = aMemPak[0x80+1] = aMemPak[0xC0+1] = 0xFF; + aMemPak[0x20+2] = aMemPak[0x60+2] = aMemPak[0x80+2] = aMemPak[0xC0+2] = 0xFF; + aMemPak[0x20+3] = aMemPak[0x60+3] = aMemPak[0x80+3] = aMemPak[0xC0+3] = 0xFF; - aMemPak[0x20+4] = aMemPak[0x60+4] = aMemPak[0x80+4] = aMemPak[0xC0+4] = aCode[0]; - aMemPak[0x20+5] = aMemPak[0x60+5] = aMemPak[0x80+5] = aMemPak[0xC0+5] = aCode[1]; - aMemPak[0x20+6] = aMemPak[0x60+6] = aMemPak[0x80+6] = aMemPak[0xC0+6] = aCode[2]; - aMemPak[0x20+7] = aMemPak[0x60+7] = aMemPak[0x80+7] = aMemPak[0xC0+7] = aCode[3]; + aMemPak[0x20+4] = aMemPak[0x60+4] = aMemPak[0x80+4] = aMemPak[0xC0+4] = aCode[0]; + aMemPak[0x20+5] = aMemPak[0x60+5] = aMemPak[0x80+5] = aMemPak[0xC0+5] = aCode[1]; + aMemPak[0x20+6] = aMemPak[0x60+6] = aMemPak[0x80+6] = aMemPak[0xC0+6] = aCode[2]; + aMemPak[0x20+7] = aMemPak[0x60+7] = aMemPak[0x80+7] = aMemPak[0xC0+7] = aCode[3]; - //aMemPak[0x30+9] = aMemPak[0x70+9] = aMemPak[0x90+9] = aMemPak[0xD0+9] = 0x01; // not sure - aMemPak[0x30+10] = aMemPak[0x70+10] = aMemPak[0x90+10] = aMemPak[0xD0+10] = 0x01; + //aMemPak[0x30+9] = aMemPak[0x70+9] = aMemPak[0x90+9] = aMemPak[0xD0+9] = 0x01; // not sure + aMemPak[0x30+10] = aMemPak[0x70+10] = aMemPak[0x90+10] = aMemPak[0xD0+10] = 0x01; - aMemPak[0x30+12] = aMemPak[0x70+12] = aMemPak[0x90+12] = aMemPak[0xD0+12] = aCode[4]; - aMemPak[0x30+13] = aMemPak[0x70+13] = aMemPak[0x90+13] = aMemPak[0xD0+13] = aCode[5]; - aMemPak[0x30+14] = aMemPak[0x70+14] = aMemPak[0x90+14] = aMemPak[0xD0+14] = aCode[6]; - aMemPak[0x30+15] = aMemPak[0x70+15] = aMemPak[0x90+15] = aMemPak[0xD0+15] = aCode[7]; + aMemPak[0x30+12] = aMemPak[0x70+12] = aMemPak[0x90+12] = aMemPak[0xD0+12] = aCode[4]; + aMemPak[0x30+13] = aMemPak[0x70+13] = aMemPak[0x90+13] = aMemPak[0xD0+13] = aCode[5]; + aMemPak[0x30+14] = aMemPak[0x70+14] = aMemPak[0x90+14] = aMemPak[0xD0+14] = aCode[6]; + aMemPak[0x30+15] = aMemPak[0x70+15] = aMemPak[0x90+15] = aMemPak[0xD0+15] = aCode[7]; - // Index - ZeroMemory( &aMemPak[0x100], 0x400 ); + // Index + ZeroMemory( &aMemPak[0x100], 0x400 ); - aMemPak[0x100+1] = aMemPak[0x200+1] = 0x71; - for( int i = 0x00b; i < 0x100; i += 2 ) - aMemPak[0x100+i] = aMemPak[0x200+i] = 03; + aMemPak[0x100+1] = aMemPak[0x200+1] = 0x71; + for( int i = 0x00b; i < 0x100; i += 2 ) + aMemPak[0x100+i] = aMemPak[0x200+i] = 03; - FillMemory( &aMemPak[0x500], 0x7B00, 0xFF ); + FillMemory( &aMemPak[0x500], 0x7B00, 0xFF ); } // Translates a mempak header into a real Unicode string, for display in the Mempaks window @@ -856,46 +856,46 @@ void FormatMemPak( LPBYTE aMemPak ) // Text automatically gets a terminating null, so make sure there's enough space. int TranslateNotesW( const unsigned char * bNote, LPWSTR Text, const int iChars ) { - WCHAR aSpecial[] = { 0x0021, 0x0022, 0x0023, 0x0060, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F, 0x003A, 0x003D, 0x003F, 0x0040, 0x2122, 0x00A9, 0x00AE }; - // { '!' , '\"', '#' , '`' , '*' , '+' , ',' , '-' , '.' , '/' , ':' , '=' , '?' , '>' , 'tm', '(c)', '(r)' }; - const WCHAR aJmap[] = { // map of Japanese characters N64 to UTF-16, starting at 0x45 - 0x00A1, 0x30A3, 0x30A5, 0x30A7, 0x30A9, 0x30E3, 0x30E5, 0x30E7, 0x30C3, 0x30F2, // small a-i-u-e-o, next are probably small ya-yu-yo, small tsu, wo - 0x30F3, // 0x4F -> 'n' - 0x30A2, 0x30A4, 0x30A6, 0x30A8, 0x30AA, 0x30AB, 0x30AD, 0x30AF, 0x30B1, 0x30B3, 0x30B5, 0x30B7, 0x30B9, 0x30BB, 0x30BD, // nil-K-S - 0x30BF, 0x30C1, 0x30C4, 0x30C6, 0x30C8, 0x30CA, 0x30CB, 0x30CC, 0x30CD, 0x30CE, 0x30CF, 0x30D2, 0x30D5, 0x30D8, 0x30DB, // T-N-H - 0x30DE, 0x30DF, 0x30E0, 0x30E1, 0x30E2, 0x30E4, 0x30E6, 0x30E8, 0x30E9, 0x30EA, 0x30EB, 0x30EC, 0x30ED, // M-Y-R - 0x30EF, // 'wa' - 0x30AC, 0x30AE, 0x30B0, 0x30B2, 0x30B4, 0x30B6, 0x30B8, 0x30BA, 0x30BC, 0x30BE, 0x30C0, 0x30C2, 0x30C5, 0x30C7, 0x30C9, // G-Z-D - 0x30D0, 0x30D3, 0x30D6, 0x30D9, 0x30DC, 0x30D1, 0x30D4, 0x30D7, 0x30DA, 0x30DD // B-P - }; - int iReturn = 0; + WCHAR aSpecial[] = { 0x0021, 0x0022, 0x0023, 0x0060, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F, 0x003A, 0x003D, 0x003F, 0x0040, 0x2122, 0x00A9, 0x00AE }; + // { '!' , '\"', '#' , '`' , '*' , '+' , ',' , '-' , '.' , '/' , ':' , '=' , '?' , '>' , 'tm', '(c)', '(r)' }; + const WCHAR aJmap[] = { // map of Japanese characters N64 to UTF-16, starting at 0x45 + 0x00A1, 0x30A3, 0x30A5, 0x30A7, 0x30A9, 0x30E3, 0x30E5, 0x30E7, 0x30C3, 0x30F2, // small a-i-u-e-o, next are probably small ya-yu-yo, small tsu, wo + 0x30F3, // 0x4F -> 'n' + 0x30A2, 0x30A4, 0x30A6, 0x30A8, 0x30AA, 0x30AB, 0x30AD, 0x30AF, 0x30B1, 0x30B3, 0x30B5, 0x30B7, 0x30B9, 0x30BB, 0x30BD, // nil-K-S + 0x30BF, 0x30C1, 0x30C4, 0x30C6, 0x30C8, 0x30CA, 0x30CB, 0x30CC, 0x30CD, 0x30CE, 0x30CF, 0x30D2, 0x30D5, 0x30D8, 0x30DB, // T-N-H + 0x30DE, 0x30DF, 0x30E0, 0x30E1, 0x30E2, 0x30E4, 0x30E6, 0x30E8, 0x30E9, 0x30EA, 0x30EB, 0x30EC, 0x30ED, // M-Y-R + 0x30EF, // 'wa' + 0x30AC, 0x30AE, 0x30B0, 0x30B2, 0x30B4, 0x30B6, 0x30B8, 0x30BA, 0x30BC, 0x30BE, 0x30C0, 0x30C2, 0x30C5, 0x30C7, 0x30C9, // G-Z-D + 0x30D0, 0x30D3, 0x30D6, 0x30D9, 0x30DC, 0x30D1, 0x30D4, 0x30D7, 0x30DA, 0x30DD // B-P + }; + int iReturn = 0; - while (iChars - iReturn > 0 && *bNote) - { - BYTE b = *bNote; - if( b <= 0x0F ) // translate Icons as Spaces - *Text = 0x0020; - else if( b <= 0x19 ) // Numbers - *Text = 0x0020 + b; - else if( b <= 0x33 ) // English characters - *Text = 0x0047 + b; - else if( b <= 0x44 ) // special symbols - *Text = aSpecial[b - 0x34]; - else if( b <= 0x94 ) // Japanese (halfwidth katakana, mapped similarly to JIS X 0201 but not enough that we can use a simple codepage) - { - aSpecial[7] = 0x30fc; // change regular dash to Japanese "long sound dash" - *Text = aJmap[b - 0x45]; - } - else // unknown - *Text = 0x00A4; // unknown characters become "currency sign" (looks like a letter o superimposed on an x) - Text++; - iReturn++; - bNote++; - } + while (iChars - iReturn > 0 && *bNote) + { + BYTE b = *bNote; + if( b <= 0x0F ) // translate Icons as Spaces + *Text = 0x0020; + else if( b <= 0x19 ) // Numbers + *Text = 0x0020 + b; + else if( b <= 0x33 ) // English characters + *Text = 0x0047 + b; + else if( b <= 0x44 ) // special symbols + *Text = aSpecial[b - 0x34]; + else if( b <= 0x94 ) // Japanese (halfwidth katakana, mapped similarly to JIS X 0201 but not enough that we can use a simple codepage) + { + aSpecial[7] = 0x30fc; // change regular dash to Japanese "long sound dash" + *Text = aJmap[b - 0x45]; + } + else // unknown + *Text = 0x00A4; // unknown characters become "currency sign" (looks like a letter o superimposed on an x) + Text++; + iReturn++; + bNote++; + } - *Text = L'\0'; + *Text = L'\0'; - return iReturn; + return iReturn; } // TODO: rename this function! It serves a completely different function from TranslateNotesW @@ -905,598 +905,598 @@ int TranslateNotesW( const unsigned char * bNote, LPWSTR Text, const int iChars // Text automatically gets a terminating null, so make sure there's enough space. int TranslateNotesA( const unsigned char * bNote, LPSTR Text, const int iChars ) { - const UCHAR aSpecial[] ={ 0x21, 0x22, 0x23, 0x60, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x3A, 0x3D, 0x3F, 0x40, 0x99, 0xA9, 0xAE }; - // { '!' , '\"', '#' , '`' , '*' , '+' , ',' , '-' , '.' , '/' , ':' , '=' , '?' , '>' , 'tm', '(c)','(r)' }; - int iReturn = 0; + const UCHAR aSpecial[] ={ 0x21, 0x22, 0x23, 0x60, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x3A, 0x3D, 0x3F, 0x40, 0x99, 0xA9, 0xAE }; + // { '!' , '\"', '#' , '`' , '*' , '+' , ',' , '-' , '.' , '/' , ':' , '=' , '?' , '>' , 'tm', '(c)','(r)' }; + int iReturn = 0; - while (iChars - iReturn > 0 && *bNote) - { - BYTE b = *bNote; - if( b <= 0x0F ) // translate Icons as Spaces - *Text = 0x20; - else if( b <= 0x19 ) // Numbers - *Text = 0x20 + b; - else if( b <= 0x33 ) // English characters - *Text = 0x47 + b; - else if( b <= 0x44 ) // special symbols - *Text = aSpecial[b - 0x34]; - else if( b <= 0x94 ) // Japan - *Text = 0xC0 + ( b % 40 ); - else // unknown - *Text = (UCHAR)0xA4; // HACK: this will screw up any save with unknown characters + while (iChars - iReturn > 0 && *bNote) + { + BYTE b = *bNote; + if( b <= 0x0F ) // translate Icons as Spaces + *Text = 0x20; + else if( b <= 0x19 ) // Numbers + *Text = 0x20 + b; + else if( b <= 0x33 ) // English characters + *Text = 0x47 + b; + else if( b <= 0x44 ) // special symbols + *Text = aSpecial[b - 0x34]; + else if( b <= 0x94 ) // Japan + *Text = 0xC0 + ( b % 40 ); + else // unknown + *Text = (UCHAR)0xA4; // HACK: this will screw up any save with unknown characters - Text++; - iReturn++; - bNote++; - } + Text++; + iReturn++; + bNote++; + } - *Text = '\0'; - return iReturn; + *Text = '\0'; + return iReturn; } int ReverseNotesA( LPCSTR Text, LPBYTE Note ) { - const UCHAR aSpecial[] = { 0x21, 0x22, 0x23, 0x60, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x3A, 0x3D, 0x3F, 0x40, 0x74, 0xA9, 0xAE }; - // { '!' , '\"', '#' , '`' , '*' , '+' , ',' , '-' , '.' , '/' , ':' , '=' , '?' , '>' , 'tm', '(r)','(c)' }; + const UCHAR aSpecial[] = { 0x21, 0x22, 0x23, 0x60, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x3A, 0x3D, 0x3F, 0x40, 0x74, 0xA9, 0xAE }; + // { '!' , '\"', '#' , '`' , '*' , '+' , ',' , '-' , '.' , '/' , ':' , '=' , '?' , '>' , 'tm', '(r)','(c)' }; - LPCSTR TextPos = Text; - while( *TextPos != '\0' ) - { - char c = *TextPos; - *Note = 0x0F; + LPCSTR TextPos = Text; + while( *TextPos != '\0' ) + { + char c = *TextPos; + *Note = 0x0F; - if( c >= '0' && c <= '9' ) - *Note = c - '0' + 0x10; - else if( c >= 'A' && c <= 'Z' ) - *Note = c - 'A' + 0x1A; - else if( c >= 'a' && c <= 'z' ) - *Note = c - 'a' + 0x1A; + if( c >= '0' && c <= '9' ) + *Note = c - '0' + 0x10; + else if( c >= 'A' && c <= 'Z' ) + *Note = c - 'A' + 0x1A; + else if( c >= 'a' && c <= 'z' ) + *Note = c - 'a' + 0x1A; - else - { - for( int i = 0; i < ARRAYSIZE(aSpecial); ++i ) - { - if( c == aSpecial[i] ) - { - *Note = i + 0x34; - break; - } - } - } - TextPos++; - Note++; - } - return TextPos - Text; + else + { + for( int i = 0; i < ARRAYSIZE(aSpecial); ++i ) + { + if( c == aSpecial[i] ) + { + *Note = i + 0x34; + break; + } + } + } + TextPos++; + Note++; + } + return TextPos - Text; } WORD ShowMemPakContent( const unsigned char * bMemPakBinary, HWND hListWindow ) { - BYTE bMemPakValid = MPAK_OK; - TCHAR szBuffer[40]; - BYTE aNoteSizes[16]; - bool bFirstChar; + BYTE bMemPakValid = MPAK_OK; + TCHAR szBuffer[40]; + BYTE aNoteSizes[16]; + bool bFirstChar; - LVITEM lvItem; - lvItem.mask = LVIF_TEXT | LVIF_PARAM; - lvItem.iItem = 0; - lvItem.iSubItem = 0; - lvItem.pszText = szBuffer; + LVITEM lvItem; + lvItem.mask = LVIF_TEXT | LVIF_PARAM; + lvItem.iItem = 0; + lvItem.iSubItem = 0; + lvItem.pszText = szBuffer; - int i = 0, - nNotes = 0, - iSum = 0, - iRemainingBlocks = 0; + int i = 0, + nNotes = 0, + iSum = 0, + iRemainingBlocks = 0; - for( i = 0x10A; i < 0x200; i++ ) - iSum += bMemPakBinary[i]; + for( i = 0x10A; i < 0x200; i++ ) + iSum += bMemPakBinary[i]; - if((( iSum % 256 ) == bMemPakBinary[0x101] )) - { - iRemainingBlocks = CountBlocks( bMemPakBinary, aNoteSizes ); + if((( iSum % 256 ) == bMemPakBinary[0x101] )) + { + iRemainingBlocks = CountBlocks( bMemPakBinary, aNoteSizes ); - if( iRemainingBlocks <= 123 ) - { - for( lvItem.lParam = 0; lvItem.lParam < 16; lvItem.lParam++ ) - { - - if( bMemPakBinary[0x300 + (lvItem.lParam*32)] || - bMemPakBinary[0x301 + (lvItem.lParam*32)] || - bMemPakBinary[0x302 + (lvItem.lParam*32)] ) - { - int iChars = TranslateNotes( &bMemPakBinary[0x300 + (lvItem.lParam*32) + 0x10], szBuffer, 16 ); + if( iRemainingBlocks <= 123 ) + { + for( lvItem.lParam = 0; lvItem.lParam < 16; lvItem.lParam++ ) + { - if( TranslateNotes( &bMemPakBinary[0x300 + (lvItem.lParam*32) + 0x0C], &szBuffer[iChars + 1], 1 ) ) - szBuffer[iChars] = _T('_'); + if( bMemPakBinary[0x300 + (lvItem.lParam*32)] || + bMemPakBinary[0x301 + (lvItem.lParam*32)] || + bMemPakBinary[0x302 + (lvItem.lParam*32)] ) + { + int iChars = TranslateNotes( &bMemPakBinary[0x300 + (lvItem.lParam*32) + 0x10], szBuffer, 16 ); - bFirstChar = true; - for( i = 0; i < (int)lstrlen(szBuffer); i++ ) - { - if( szBuffer[i] == ' ' ) - bFirstChar = true; - else - { - if( bFirstChar && ( szBuffer[i] >= 'a') && ( szBuffer[i] <= 'z')) - { - bFirstChar = false; - szBuffer[i] -= 0x20; - } - } + if( TranslateNotes( &bMemPakBinary[0x300 + (lvItem.lParam*32) + 0x0C], &szBuffer[iChars + 1], 1 ) ) + szBuffer[iChars] = _T('_'); - } - - i = ListView_InsertItem( hListWindow, &lvItem ); + bFirstChar = true; + for( i = 0; i < (int)lstrlen(szBuffer); i++ ) + { + if( szBuffer[i] == ' ' ) + bFirstChar = true; + else + { + if( bFirstChar && ( szBuffer[i] >= 'a') && ( szBuffer[i] <= 'z')) + { + bFirstChar = false; + szBuffer[i] -= 0x20; + } + } - switch( bMemPakBinary[0x303 + (lvItem.lParam*32)] ) - { - case 0x00: - LoadString( g_hResourceDLL, IDS_P_MEM_NOREGION, szBuffer, 40 ); - break; - case 0x37: - LoadString( g_hResourceDLL, IDS_P_MEM_BETA, szBuffer, 40 ); - break; - case 0x41: - LoadString( g_hResourceDLL, IDS_P_MEM_NTSC, szBuffer, 40 ); - break; - case 0x44: - LoadString( g_hResourceDLL, IDS_P_MEM_GERMANY, szBuffer, 40 ); - break; - case 0x45: - LoadString( g_hResourceDLL, IDS_P_MEM_USA, szBuffer, 40 ); - break; - case 0x46: - LoadString( g_hResourceDLL, IDS_P_MEM_FRANCE, szBuffer, 40 ); - break; - case 0x49: - LoadString( g_hResourceDLL, IDS_P_MEM_ITALY, szBuffer, 40 ); - break; - case 0x4A: - LoadString( g_hResourceDLL, IDS_P_MEM_JAPAN, szBuffer, 40 ); - break; - case 0x50: - LoadString( g_hResourceDLL, IDS_P_MEM_EUROPE, szBuffer, 40 ); - break; - case 0x53: - LoadString( g_hResourceDLL, IDS_P_MEM_SPAIN, szBuffer, 40 ); - break; - case 0x55: - LoadString( g_hResourceDLL, IDS_P_MEM_AUSTRALIA, szBuffer, 40 ); - break; - case 0x58: - case 0x59: - LoadString( g_hResourceDLL, IDS_P_MEM_PAL, szBuffer, 40 ); - break; - default: - { - TCHAR szTemp[40]; - LoadString( g_hResourceDLL, IDS_P_MEM_UNKNOWNREGION, szTemp, 40 ); - wsprintf( szBuffer, szTemp, bMemPakBinary[0x303 + (lvItem.lParam*32)] ); - } - } + } - ListView_SetItemText( hListWindow, i, 1, szBuffer ); + i = ListView_InsertItem( hListWindow, &lvItem ); - wsprintf( szBuffer, _T("%i"), aNoteSizes[lvItem.lParam] ); - ListView_SetItemText( hListWindow, i, 2, szBuffer ); - nNotes++; - } - } - - } - else - bMemPakValid = MPAK_DAMAGED; + switch( bMemPakBinary[0x303 + (lvItem.lParam*32)] ) + { + case 0x00: + LoadString( g_hResourceDLL, IDS_P_MEM_NOREGION, szBuffer, 40 ); + break; + case 0x37: + LoadString( g_hResourceDLL, IDS_P_MEM_BETA, szBuffer, 40 ); + break; + case 0x41: + LoadString( g_hResourceDLL, IDS_P_MEM_NTSC, szBuffer, 40 ); + break; + case 0x44: + LoadString( g_hResourceDLL, IDS_P_MEM_GERMANY, szBuffer, 40 ); + break; + case 0x45: + LoadString( g_hResourceDLL, IDS_P_MEM_USA, szBuffer, 40 ); + break; + case 0x46: + LoadString( g_hResourceDLL, IDS_P_MEM_FRANCE, szBuffer, 40 ); + break; + case 0x49: + LoadString( g_hResourceDLL, IDS_P_MEM_ITALY, szBuffer, 40 ); + break; + case 0x4A: + LoadString( g_hResourceDLL, IDS_P_MEM_JAPAN, szBuffer, 40 ); + break; + case 0x50: + LoadString( g_hResourceDLL, IDS_P_MEM_EUROPE, szBuffer, 40 ); + break; + case 0x53: + LoadString( g_hResourceDLL, IDS_P_MEM_SPAIN, szBuffer, 40 ); + break; + case 0x55: + LoadString( g_hResourceDLL, IDS_P_MEM_AUSTRALIA, szBuffer, 40 ); + break; + case 0x58: + case 0x59: + LoadString( g_hResourceDLL, IDS_P_MEM_PAL, szBuffer, 40 ); + break; + default: + { + TCHAR szTemp[40]; + LoadString( g_hResourceDLL, IDS_P_MEM_UNKNOWNREGION, szTemp, 40 ); + wsprintf( szBuffer, szTemp, bMemPakBinary[0x303 + (lvItem.lParam*32)] ); + } + } - } - else - bMemPakValid = MPAK_DAMAGED; + ListView_SetItemText( hListWindow, i, 1, szBuffer ); - return MAKEWORD( (BYTE)iRemainingBlocks, bMemPakValid ); + wsprintf( szBuffer, _T("%i"), aNoteSizes[lvItem.lParam] ); + ListView_SetItemText( hListWindow, i, 2, szBuffer ); + nNotes++; + } + } + + } + else + bMemPakValid = MPAK_DAMAGED; + + } + else + bMemPakValid = MPAK_DAMAGED; + + return MAKEWORD( (BYTE)iRemainingBlocks, bMemPakValid ); } void HextoTextA( const unsigned char * Data, LPSTR szText, const int nBytes ) { - const char acValues[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - 'A', 'B', 'C', 'D', 'E', 'F' }; + const char acValues[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'A', 'B', 'C', 'D', 'E', 'F' }; - for( int i = 0; i < nBytes; i++ ) - { - BYTE byte = *Data; - szText[0] = acValues[(byte>>4) & 0x0F]; - szText[1] = acValues[byte & 0x0F]; + for( int i = 0; i < nBytes; i++ ) + { + BYTE byte = *Data; + szText[0] = acValues[(byte>>4) & 0x0F]; + szText[1] = acValues[byte & 0x0F]; - ++Data; - szText+=2; - } - *szText = '\0'; + ++Data; + szText+=2; + } + *szText = '\0'; } // used when reading in a Note file, to convert text to binary (unserialize) void TexttoHexA( LPCSTR szText, LPBYTE Data, const int nBytes ) { - bool fLowByte = false; - LPCSTR endText = szText + nBytes * 2; + bool fLowByte = false; + LPCSTR endText = szText + nBytes * 2; - for( ; szText < endText; ++szText ) - { - BYTE bByte = 0; + for( ; szText < endText; ++szText ) + { + BYTE bByte = 0; - if(( '0' <= *szText ) && ( *szText <= '9' )) - bByte = *szText - '0'; - else - { - if(( 'A' <= *szText ) && ( *szText <= 'F' )) - bByte = szText[0] - 'A' + 10; - else if(( 'a' <= *szText ) && ( *szText <= 'f' )) - bByte = szText[0] - 'a' + 10; - } + if(( '0' <= *szText ) && ( *szText <= '9' )) + bByte = *szText - '0'; + else + { + if(( 'A' <= *szText ) && ( *szText <= 'F' )) + bByte = szText[0] - 'A' + 10; + else if(( 'a' <= *szText ) && ( *szText <= 'f' )) + bByte = szText[0] - 'a' + 10; + } - if( !fLowByte ) - *Data = bByte << 4; - else - { - *Data |= bByte; - ++Data; - } + if( !fLowByte ) + *Data = bByte << 4; + else + { + *Data |= bByte; + ++Data; + } - fLowByte = !fLowByte; - } + fLowByte = !fLowByte; + } } bool SaveNoteFileA( const unsigned char * aMemPak, const int iNote, LPCTSTR pszFileName ) { - BYTE aNoteSizes[16]; - LPBYTE aNote; - bool bReturn = false; - if( CountBlocks( aMemPak, aNoteSizes ) > 123 ) - return false; + BYTE aNoteSizes[16]; + LPBYTE aNote; + bool bReturn = false; + if( CountBlocks( aMemPak, aNoteSizes ) > 123 ) + return false; - aNote = (LPBYTE)P_malloc( aNoteSizes[iNote] * 0x100 + 32 ); - if( !aNote ) - return false; + aNote = (LPBYTE)P_malloc( aNoteSizes[iNote] * 0x100 + 32 ); + if( !aNote ) + return false; - CopyMemory( aNote, &aMemPak[0x300 + iNote * 32], 32 ); - BYTE bNextIndex = aNote[0x7]; - int iBlock = 0; - while( iBlock < aNoteSizes[iNote] ) - { - CopyMemory( &aNote[32 + iBlock * 0x100], &aMemPak[bNextIndex * 0x100], 0x100); - bNextIndex = aMemPak[0x101 + (bNextIndex*2)]; - - iBlock++; - } + CopyMemory( aNote, &aMemPak[0x300 + iNote * 32], 32 ); + BYTE bNextIndex = aNote[0x7]; + int iBlock = 0; + while( iBlock < aNoteSizes[iNote] ) + { + CopyMemory( &aNote[32 + iBlock * 0x100], &aMemPak[bNextIndex * 0x100], 0x100); + bNextIndex = aMemPak[0x101 + (bNextIndex*2)]; - HANDLE hFile = CreateFile( pszFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); - if ( hFile != INVALID_HANDLE_VALUE ) - { - SetFilePointer( hFile, 0L, NULL, FILE_BEGIN ); - char szLine[70]; - - - DWORD dwBytesWritten = 0; - lstrcpyA( szLine, "a64-notes\r\ndescription of game save goes here...\r\na64-data\r\n" ); - WriteFile( hFile, szLine, lstrlenA(szLine), &dwBytesWritten, NULL ); + iBlock++; + } - CopyMemory( szLine, aNote, 4 ); - szLine[4] = ' '; - szLine[5] = aNote[4]; - szLine[6] = aNote[5]; - szLine[7] = ' '; - HextoTextA( &aNote[8], &szLine[8], 2 ); + HANDLE hFile = CreateFile( pszFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); + if ( hFile != INVALID_HANDLE_VALUE ) + { + SetFilePointer( hFile, 0L, NULL, FILE_BEGIN ); + char szLine[70]; - int pos = 12; - szLine[pos++] = ' '; - szLine[pos++] = aNote[0x0A] + '0'; - szLine[pos++] = ' '; - szLine[pos++] = '{'; - - pos += TranslateNotesA( &aNote[0x0C], &szLine[pos], 1 ); - szLine[pos++] = '}'; - szLine[pos++] = ' '; - szLine[pos++] = '{'; + DWORD dwBytesWritten = 0; + lstrcpyA( szLine, "a64-notes\r\ndescription of game save goes here...\r\na64-data\r\n" ); + WriteFile( hFile, szLine, lstrlenA(szLine), &dwBytesWritten, NULL ); - pos += TranslateNotesA( &aNote[0x10], &szLine[pos], 16 ); + CopyMemory( szLine, aNote, 4 ); + szLine[4] = ' '; + szLine[5] = aNote[4]; + szLine[6] = aNote[5]; + szLine[7] = ' '; + HextoTextA( &aNote[8], &szLine[8], 2 ); - lstrcatA( szLine, "}\r\n" ); - WriteFile( hFile, szLine, lstrlenA(szLine), &dwBytesWritten, NULL ); + int pos = 12; + szLine[pos++] = ' '; + szLine[pos++] = aNote[0x0A] + '0'; + szLine[pos++] = ' '; + szLine[pos++] = '{'; - for( int i = 32; i < aNoteSizes[iNote] * 0x100 + 32; i += 32 ) - { - HextoTextA( &aNote[i], szLine, 32 ); - WriteFile( hFile, szLine, lstrlenA(szLine), &dwBytesWritten, NULL ); - WriteFile( hFile, "\r\n", 2, &dwBytesWritten, NULL ); - } - WriteFile( hFile, "a64-crc\r\n", 9, &dwBytesWritten, NULL ); + pos += TranslateNotesA( &aNote[0x0C], &szLine[pos], 1 ); - // TODO: insert crc here - lstrcpynA( szLine, "00000000\r\n", 70 ); - WriteFile( hFile, szLine, lstrlenA(szLine), &dwBytesWritten, NULL ); - // - WriteFile( hFile, "a64-end\r\n", 9, &dwBytesWritten, NULL ); + szLine[pos++] = '}'; + szLine[pos++] = ' '; + szLine[pos++] = '{'; - SetEndOfFile( hFile ); - bReturn = true; - CloseHandle( hFile ); - } - else - ErrorMessage( IDS_ERR_NOTEREAD, GetLastError(), false ); + pos += TranslateNotesA( &aNote[0x10], &szLine[pos], 16 ); - P_free( aNote ); - return bReturn; + lstrcatA( szLine, "}\r\n" ); + WriteFile( hFile, szLine, lstrlenA(szLine), &dwBytesWritten, NULL ); + + for( int i = 32; i < aNoteSizes[iNote] * 0x100 + 32; i += 32 ) + { + HextoTextA( &aNote[i], szLine, 32 ); + WriteFile( hFile, szLine, lstrlenA(szLine), &dwBytesWritten, NULL ); + WriteFile( hFile, "\r\n", 2, &dwBytesWritten, NULL ); + } + WriteFile( hFile, "a64-crc\r\n", 9, &dwBytesWritten, NULL ); + + // TODO: insert crc here + lstrcpynA( szLine, "00000000\r\n", 70 ); + WriteFile( hFile, szLine, lstrlenA(szLine), &dwBytesWritten, NULL ); + // + WriteFile( hFile, "a64-end\r\n", 9, &dwBytesWritten, NULL ); + + SetEndOfFile( hFile ); + bReturn = true; + CloseHandle( hFile ); + } + else + ErrorMessage( IDS_ERR_NOTEREAD, GetLastError(), false ); + + P_free( aNote ); + return bReturn; } // read a Note from a file pszFileName (.a64 format), and insert it into the given MemPak // returns true on success, false otherwise bool InsertNoteFile( LPBYTE aMemPak, LPCTSTR pszFileName ) { -// bool bReturn = false; +// bool bReturn = false; - FILE* nFile = NULL; + FILE* nFile = NULL; - if( (nFile = _tfopen(pszFileName, _T("r") ) ) != NULL ) - { - char szLine[128]; - fpos_t pDataStart; + if( (nFile = _tfopen(pszFileName, _T("r") ) ) != NULL ) + { + char szLine[128]; + fpos_t pDataStart; - while( fgets(szLine, sizeof(szLine) - 1, nFile) ) - { - if( !strncmp( "a64-data", szLine, 8 )) - { - fgetpos(nFile, &pDataStart); - break; - } - } + while( fgets(szLine, sizeof(szLine) - 1, nFile) ) + { + if( !strncmp( "a64-data", szLine, 8 )) + { + fgetpos(nFile, &pDataStart); + break; + } + } - // assumes the file keeps going... - // discard the next line - fgets(szLine, sizeof(szLine) - 1, nFile); // not really necessary to check for EOF, as it will fail gracefully when dwNoteSize is zero. + // assumes the file keeps going... + // discard the next line + fgets(szLine, sizeof(szLine) - 1, nFile); // not really necessary to check for EOF, as it will fail gracefully when dwNoteSize is zero. - DWORD dwNoteSize = 0; - while( fgets(szLine, sizeof(szLine) - 1, nFile) && strncmp( "a64-crc", szLine, 7 )) - { - dwNoteSize++; - } - dwNoteSize /= 8; + DWORD dwNoteSize = 0; + while( fgets(szLine, sizeof(szLine) - 1, nFile) && strncmp( "a64-crc", szLine, 7 )) + { + dwNoteSize++; + } + dwNoteSize /= 8; - BYTE aNoteSizes[16]; - WORD wRemainingBlocks; - int i, - ifreeNote = -1; + BYTE aNoteSizes[16]; + WORD wRemainingBlocks; + int i, + ifreeNote = -1; - wRemainingBlocks = CountBlocks( aMemPak, aNoteSizes ); + wRemainingBlocks = CountBlocks( aMemPak, aNoteSizes ); - if( dwNoteSize <= 0 ) - { - ErrorMessage( IDS_ERR_NOTEREAD, 0, false ); - fclose(nFile); - return false; - } - else - { - if( wRemainingBlocks < dwNoteSize ) - { - ErrorMessage( IDS_ERR_MEMPAK_SPACE, 0, false ); - fclose(nFile); - return false; - } - else - { - i = 0; - while(( i < 16 ) && ( ifreeNote == -1 )) - { - if( aNoteSizes[i] == 0 ) - ifreeNote = i; - i++; - } - if( ifreeNote == -1 ) - { + if( dwNoteSize <= 0 ) + { + ErrorMessage( IDS_ERR_NOTEREAD, 0, false ); + fclose(nFile); + return false; + } + else + { + if( wRemainingBlocks < dwNoteSize ) + { + ErrorMessage( IDS_ERR_MEMPAK_SPACE, 0, false ); + fclose(nFile); + return false; + } + else + { + i = 0; + while(( i < 16 ) && ( ifreeNote == -1 )) + { + if( aNoteSizes[i] == 0 ) + ifreeNote = i; + i++; + } + if( ifreeNote == -1 ) + { ErrorMessage( IDS_ERR_MEMPAK_NONOTES, 0, false ); - fclose(nFile); - return false; - } - } - } + fclose(nFile); + return false; + } + } + } - // HEADER START + // HEADER START - // .a64 header should look something like this: - // NBCE 01 0203 0 {} {BLASTCORPS GAME} - // first 4 chars are the first 4 bytes - // next 2 chars are the next 2 bytes - // next 4 chars are bytes 8 and 9, in hex (huh?) - // next character is byte 10, in hex (but only one character this time) - // now we've got two sets of braces... the first one contains byte 12 in encoded form (use ReverseNotesA) - // the second one should contain bytes 16 through 31 (ReverseNotesA) + // .a64 header should look something like this: + // NBCE 01 0203 0 {} {BLASTCORPS GAME} + // first 4 chars are the first 4 bytes + // next 2 chars are the next 2 bytes + // next 4 chars are bytes 8 and 9, in hex (huh?) + // next character is byte 10, in hex (but only one character this time) + // now we've got two sets of braces... the first one contains byte 12 in encoded form (use ReverseNotesA) + // the second one should contain bytes 16 through 31 (ReverseNotesA) - BYTE *pBlock; - fsetpos(nFile, &pDataStart); - if (! fgets(szLine, sizeof(szLine) - 1, nFile) ) - { - ErrorMessage( IDS_ERR_NOTEEOF, 0, false ); - fclose(nFile); - return false; - } + BYTE *pBlock; + fsetpos(nFile, &pDataStart); + if (! fgets(szLine, sizeof(szLine) - 1, nFile) ) + { + ErrorMessage( IDS_ERR_NOTEEOF, 0, false ); + fclose(nFile); + return false; + } - szLine[strlen(szLine) - 1] = '\0'; // remove newline - - pBlock = &aMemPak[0x300 + ifreeNote*32]; - CopyMemory( pBlock, szLine, 4 ); - pBlock[4] = szLine[5]; - pBlock[5] = szLine[6]; - TexttoHexA( &szLine[8], &pBlock[8], 2 ); - pBlock[10] = szLine[13] - '0'; + szLine[strlen(szLine) - 1] = '\0'; // remove newline - int len = lstrlenA( szLine ); + pBlock = &aMemPak[0x300 + ifreeNote*32]; + CopyMemory( pBlock, szLine, 4 ); + pBlock[4] = szLine[5]; + pBlock[5] = szLine[6]; + TexttoHexA( &szLine[8], &pBlock[8], 2 ); + pBlock[10] = szLine[13] - '0'; - i = 16; - while(( szLine[i] != '}' ) && (i < len)) - i++; + int len = lstrlenA( szLine ); - szLine[i] = '\0'; - i += ReverseNotesA( &szLine[16], &pBlock[12] ); + i = 16; + while(( szLine[i] != '}' ) && (i < len)) + i++; - while(( szLine[i] != '{' ) && (i < len)) - i++; + szLine[i] = '\0'; + i += ReverseNotesA( &szLine[16], &pBlock[12] ); - if(i < len) - { - int start = i+1; - while(( szLine[i] != '}' ) && (i < len)) - i++; - if(i < len) - { - szLine[i] = '\0'; - ReverseNotesA( &szLine[start], &pBlock[16] ); - } - } + while(( szLine[i] != '{' ) && (i < len)) + i++; - while(( szLine[i] != '}' ) && (i < len)) - i++; - szLine[i] = '\0'; + if(i < len) + { + int start = i+1; + while(( szLine[i] != '}' ) && (i < len)) + i++; + if(i < len) + { + szLine[i] = '\0'; + ReverseNotesA( &szLine[start], &pBlock[16] ); + } + } - // HEADER END + while(( szLine[i] != '}' ) && (i < len)) + i++; + szLine[i] = '\0'; - BYTE bDataBlock = 5; - pBlock = &pBlock[7]; - BYTE *pDataBlock; + // HEADER END - while( dwNoteSize > 0 ) - { - while( aMemPak[0x101 + bDataBlock*2] != 0x03 ) - bDataBlock++; - *pBlock = bDataBlock; - pBlock = &aMemPak[0x101 + bDataBlock*2]; - pDataBlock = &aMemPak[bDataBlock * 0x100]; - for( i = 0; i < 0x100; i+=32 ) - { - if (! fgets(szLine, sizeof(szLine) - 1, nFile) ) - { - ErrorMessage( IDS_ERR_NOTEEOF, 0, false ); - fclose(nFile); - return false; - } + BYTE bDataBlock = 5; + pBlock = &pBlock[7]; + BYTE *pDataBlock; - szLine[strlen(szLine) - 1] = '\0'; // remove newline - TexttoHexA( szLine, &pDataBlock[i], 32 ); - } - bDataBlock++; - dwNoteSize--; - } - *pBlock = 0x01; + while( dwNoteSize > 0 ) + { + while( aMemPak[0x101 + bDataBlock*2] != 0x03 ) + bDataBlock++; + *pBlock = bDataBlock; + pBlock = &aMemPak[0x101 + bDataBlock*2]; + pDataBlock = &aMemPak[bDataBlock * 0x100]; + for( i = 0; i < 0x100; i+=32 ) + { + if (! fgets(szLine, sizeof(szLine) - 1, nFile) ) + { + ErrorMessage( IDS_ERR_NOTEEOF, 0, false ); + fclose(nFile); + return false; + } - int iSum = 0; + szLine[strlen(szLine) - 1] = '\0'; // remove newline + TexttoHexA( szLine, &pDataBlock[i], 32 ); + } + bDataBlock++; + dwNoteSize--; + } + *pBlock = 0x01; - for( i = 0x10A; i < 0x200; i++ ) - iSum += aMemPak[i]; + int iSum = 0; - aMemPak[0x101] = iSum % 256; + for( i = 0x10A; i < 0x200; i++ ) + iSum += aMemPak[i]; - CopyMemory( &aMemPak[0x200], &aMemPak[0x100], 0x100 ); + aMemPak[0x101] = iSum % 256; - fclose(nFile); - return true; - } - else - ErrorMessage( IDS_ERR_NOTEREAD, 0, false ); - return false; + CopyMemory( &aMemPak[0x200], &aMemPak[0x100], 0x100 ); + + fclose(nFile); + return true; + } + else + ErrorMessage( IDS_ERR_NOTEREAD, 0, false ); + return false; } // Remove a mempak "Note" // See "MemPak-Format.doc" for more info bool RemoveNote( LPBYTE aMemPak, const int iNote ) { - BYTE bBlock = aMemPak[0x307 + iNote*32]; - int iPos; + BYTE bBlock = aMemPak[0x307 + iNote*32]; + int iPos; - while( bBlock >= 0x05 ) - { - iPos = 0x101 + bBlock*2; - bBlock = aMemPak[iPos]; - aMemPak[iPos] = 0x03; - } + while( bBlock >= 0x05 ) + { + iPos = 0x101 + bBlock*2; + bBlock = aMemPak[iPos]; + aMemPak[iPos] = 0x03; + } - int i = 0, iSum = 0; - for( i = 0x10A; i < 0x200; i++ ) - iSum += aMemPak[i]; + int i = 0, iSum = 0; + for( i = 0x10A; i < 0x200; i++ ) + iSum += aMemPak[i]; - aMemPak[0x101] = iSum % 256; - CopyMemory( &aMemPak[0x200], &aMemPak[0x100], 0x100 ); - ZeroMemory( &aMemPak[0x300 + iNote*32], 32 ); - return true; + aMemPak[0x101] = iSum % 256; + CopyMemory( &aMemPak[0x200], &aMemPak[0x100], 0x100 ); + ZeroMemory( &aMemPak[0x300 + iNote*32], 32 ); + return true; } BYTE AddressCRC( const unsigned char * Address ) { - bool HighBit; - WORD Data = MAKEWORD( Address[1], Address[0] ); - register BYTE Remainder = ( Data >> 11 ) & 0x1F; + bool HighBit; + WORD Data = MAKEWORD( Address[1], Address[0] ); + register BYTE Remainder = ( Data >> 11 ) & 0x1F; - BYTE bBit = 5; + BYTE bBit = 5; - while( bBit < 16 ) - { - HighBit = (Remainder & 0x10) != 0; - Remainder = (Remainder << 1) & 0x1E; + while( bBit < 16 ) + { + HighBit = (Remainder & 0x10) != 0; + Remainder = (Remainder << 1) & 0x1E; - Remainder += ( bBit < 11 && Data & (0x8000 >> bBit )) ? 1 : 0; - Remainder ^= (HighBit) ? 0x15 : 0; - - bBit++; - } + Remainder += ( bBit < 11 && Data & (0x8000 >> bBit )) ? 1 : 0; + Remainder ^= (HighBit) ? 0x15 : 0; - return Remainder; + bBit++; + } + + return Remainder; } BYTE DataCRC( const unsigned char * Data, const int iLength ) { - register BYTE Remainder = Data[0]; + register BYTE Remainder = Data[0]; - int iByte = 1; - BYTE bBit = 0; + int iByte = 1; + BYTE bBit = 0; - while( iByte <= iLength ) - { - bool HighBit = ((Remainder & 0x80) != 0); - Remainder = Remainder << 1; + while( iByte <= iLength ) + { + bool HighBit = ((Remainder & 0x80) != 0); + Remainder = Remainder << 1; - Remainder += ( iByte < iLength && Data[iByte] & (0x80 >> bBit )) ? 1 : 0; + Remainder += ( iByte < iLength && Data[iByte] & (0x80 >> bBit )) ? 1 : 0; - Remainder ^= (HighBit) ? 0x85 : 0; - - bBit++; - iByte += bBit/8; - bBit %= 8; - } + Remainder ^= (HighBit) ? 0x85 : 0; - return Remainder; + bBit++; + iByte += bBit/8; + bBit %= 8; + } + + return Remainder; } VOID CALLBACK WritebackProc( HWND hWnd, UINT msg, UINT_PTR idEvent, DWORD dwTime ) { - KillTimer(hWnd, idEvent); // timer suicide + KillTimer(hWnd, idEvent); // timer suicide - switch (idEvent) - { - case PAK_MEM: - DebugWriteA("Mempak: WritebackProc flushed file writes\n"); - for( int i = 0; i < 4; i++ ) - { - MEMPAK *mPak = (MEMPAK*)g_pcControllers[i].pPakData; + switch (idEvent) + { + case PAK_MEM: + DebugWriteA("Mempak: WritebackProc flushed file writes\n"); + for( int i = 0; i < 4; i++ ) + { + MEMPAK *mPak = (MEMPAK*)g_pcControllers[i].pPakData; - if ( mPak && mPak->bPakType == PAK_MEM && !mPak->fReadonly && mPak->hMemPakHandle != NULL ) - FlushViewOfFile( mPak->aMemPakData, PAK_MEM_SIZE ); - } - return; - case PAK_TRANSFER: - DebugWriteA("TPak: WritebackProc flushed file writes\n"); - for( int i = 0; i < 4; i++ ) - { - LPTRANSFERPAK tPak = (LPTRANSFERPAK)g_pcControllers[i].pPakData; + if ( mPak && mPak->bPakType == PAK_MEM && !mPak->fReadonly && mPak->hMemPakHandle != NULL ) + FlushViewOfFile( mPak->aMemPakData, PAK_MEM_SIZE ); + } + return; + case PAK_TRANSFER: + DebugWriteA("TPak: WritebackProc flushed file writes\n"); + for( int i = 0; i < 4; i++ ) + { + LPTRANSFERPAK tPak = (LPTRANSFERPAK)g_pcControllers[i].pPakData; - if (tPak && tPak->bPakType == PAK_TRANSFER && tPak->bPakInserted && tPak->gbCart.hRamFile != NULL ) - FlushViewOfFile( tPak->gbCart.RamData, (tPak->gbCart.RomData[0x149] == 1 ) ? 0x0800 : tPak->gbCart.iNumRamBanks * 0x2000); - } - return; - } + if (tPak && tPak->bPakType == PAK_TRANSFER && tPak->bPakInserted && tPak->gbCart.hRamFile != NULL ) + FlushViewOfFile( tPak->gbCart.RamData, (tPak->gbCart.RomData[0x149] == 1 ) ? 0x0800 : tPak->gbCart.iNumRamBanks * 0x2000); + } + return; + } } diff --git a/Source/nragev20/PakIO.h b/Source/nragev20/PakIO.h index 3def49a86..b6586efad 100644 --- a/Source/nragev20/PakIO.h +++ b/Source/nragev20/PakIO.h @@ -1,9 +1,9 @@ -/* - N-Rage`s Dinput8 Plugin +/* + N-Rage`s Dinput8 Plugin (C) 2002, 2006 Norbert Wladyka - Author`s Email: norbert.wladyka@chello.at - Website: http://go.to/nrage + Author`s Email: norbert.wladyka@chello.at + Website: http://go.to/nrage This program is free software; you can redistribute it and/or modify @@ -54,65 +54,65 @@ void HextoTextA( const unsigned char * Data, LPSTR szText, const int nBytes ); //byte 2 = number of bytes to recieve //byte 3 = Command Type - // get status -#define RD_GETSTATUS 0x00 - // read button values -#define RD_READKEYS 0x01 - // read from controllerpak -#define RD_READPAK 0x02 - // write to controllerpack -#define RD_WRITEPAK 0x03 - // reset controller -#define RD_RESETCONTROLLER 0xff - // read eeprom -#define RD_READEEPROM 0x04 - // write eeprom -#define RD_WRITEEPROM 0x05 + // get status +#define RD_GETSTATUS 0x00 + // read button values +#define RD_READKEYS 0x01 + // read from controllerpak +#define RD_READPAK 0x02 + // write to controllerpack +#define RD_WRITEPAK 0x03 + // reset controller +#define RD_RESETCONTROLLER 0xff + // read eeprom +#define RD_READEEPROM 0x04 + // write eeprom +#define RD_WRITEEPROM 0x05 - // Codes for retrieving status + // Codes for retrieving status // 0x010300 - A1B2C3FF - //A1 - // Default GamePad -#define RD_ABSOLUTE 0x01 -#define RD_RELATIVE 0x02 - // Default GamePad -#define RD_GAMEPAD 0x04 + //A1 + // Default GamePad +#define RD_ABSOLUTE 0x01 +#define RD_RELATIVE 0x02 + // Default GamePad +#define RD_GAMEPAD 0x04 - //B2 -#define RD_EEPROM 0x80 -#define RD_NOEEPROM 0x00 + //B2 +#define RD_EEPROM 0x80 +#define RD_NOEEPROM 0x00 - //C3 - // No Plugin in Controller -#define RD_NOPLUGIN 0x00 - // Plugin in Controller (Mempack, RumblePack etc) -#define RD_PLUGIN 0x01 - // Pak interface was uninitialized before the call -#define RD_NOTINITIALIZED 0x02 - // Address of last Pak I/O was invalid -#define RD_ADDRCRCERR 0x04 - // eeprom busy -#define RD_EEPROMBUSY 0x80 + //C3 + // No Plugin in Controller +#define RD_NOPLUGIN 0x00 + // Plugin in Controller (Mempack, RumblePack etc) +#define RD_PLUGIN 0x01 + // Pak interface was uninitialized before the call +#define RD_NOTINITIALIZED 0x02 + // Address of last Pak I/O was invalid +#define RD_ADDRCRCERR 0x04 + // eeprom busy +#define RD_EEPROMBUSY 0x80 // The Error values are as follows: // 0x01ER00 - ........ - //ER - // no error, operation successful. -#define RD_OK 0x00 - // error, device not present for specified command. -#define RD_ERROR 0x80 - // error, unable to send/recieve the number bytes for command type. -#define RD_WRONGSIZE 0x40 + //ER + // no error, operation successful. +#define RD_OK 0x00 + // error, device not present for specified command. +#define RD_ERROR 0x80 + // error, unable to send/recieve the number bytes for command type. +#define RD_WRONGSIZE 0x40 - // the address where rumble-commands are sent to - // this is really 0xC01B but our addressing code truncates the last several bits. -#define PAK_IO_RUMBLE 0xC000 + // the address where rumble-commands are sent to + // this is really 0xC01B but our addressing code truncates the last several bits. +#define PAK_IO_RUMBLE 0xC000 - // 32 KB mempak -#define PAK_MEM_SIZE 32*1024 -#define PAK_MEM_DEXOFFSET 0x1040 + // 32 KB mempak +#define PAK_MEM_SIZE 32*1024 +#define PAK_MEM_DEXOFFSET 0x1040 // Pak Specific Data // // First BYTE always determines current Paktype @@ -125,49 +125,49 @@ void HextoTextA( const unsigned char * Data, LPSTR szText, const int nBytes ); //PAK_MEM typedef struct _MEMPAK { - BYTE bPakType; // set to PAK_MEM - HANDLE hMemPakHandle; // a file mapping handle - bool fDexSave; // true if .n64 file, false if .mpk file - bool fReadonly; // set if we can't open mempak file in "write" mode - LPBYTE aMemPakData; //[PAK_MEM_SIZE]; - BYTE aMemPakTemp[0x100]; // some extra on the top for "test" (temporary) data + BYTE bPakType; // set to PAK_MEM + HANDLE hMemPakHandle; // a file mapping handle + bool fDexSave; // true if .n64 file, false if .mpk file + bool fReadonly; // set if we can't open mempak file in "write" mode + LPBYTE aMemPakData; //[PAK_MEM_SIZE]; + BYTE aMemPakTemp[0x100]; // some extra on the top for "test" (temporary) data } MEMPAK, *LPMEMPAK; //PAK_RUMBLE typedef struct _RUMBLEPAK { - BYTE bPakType; -// BYTE bRumbleTyp; // obsolete: use g_pcControllers[i].xyz instead --rabid -// BYTE bRumbleStrength; -// bool fVisualRumble; - bool fLastData; // true if the last data sent to block 0x8000 was nonzero + BYTE bPakType; +// BYTE bRumbleTyp; // obsolete: use g_pcControllers[i].xyz instead --rabid +// BYTE bRumbleStrength; +// bool fVisualRumble; + bool fLastData; // true if the last data sent to block 0x8000 was nonzero } RUMBLEPAK, *LPRUMBLEPAK; #include "GBCart.h" //PAK_TRANSFER typedef struct _TRANSFERPAK { - BYTE bPakType; - int iCurrentBankNo; - int iCurrentAccessMode; - int iAccessModeChanged; - bool iEnableState; - bool bPakInserted; - GBCART gbCart; + BYTE bPakType; + int iCurrentBankNo; + int iCurrentAccessMode; + int iAccessModeChanged; + bool iEnableState; + bool bPakInserted; + GBCART gbCart; } TRANSFERPAK, *LPTRANSFERPAK; //PAK_VOICE typedef struct _VOICEPAK //not supported { - BYTE bPakType; + BYTE bPakType; } VOICEPAK, *LPVOICEPAK; - + //PAK_ADAPTOID typedef struct _ADAPTOIDPAK { - BYTE bPakType; - BYTE bIdentifier; - bool fRumblePak; + BYTE bPakType; + BYTE bIdentifier; + bool fRumblePak; } ADAPTOIDPAK, *LPADAPTOIDPAK; #endif // #ifndef _PAKIO_H_ diff --git a/Source/nragev20/XInputController.cpp b/Source/nragev20/XInputController.cpp index 836e7e26e..c630e6438 100644 --- a/Source/nragev20/XInputController.cpp +++ b/Source/nragev20/XInputController.cpp @@ -1,8 +1,8 @@ /* - XInput Controller support for N-Rage`s Dinput8 Plugin by tecnicors - (C) 2009 Daniel Rehren - XInput Controller support + XInput Controller support for N-Rage`s Dinput8 Plugin by tecnicors + (C) 2009 Daniel Rehren - XInput Controller support - Author's Email: rehren_007@hotmail.com + Author's Email: rehren_007@hotmail.com This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -61,21 +61,21 @@ BOOL IsXInputDevice( const GUID* pGuidProductFromDirectInput ) if( FAILED(hr) || pIWbemLocator == NULL ) goto LCleanup; - bstrNamespace = SysAllocString( L"\\\\.\\root\\cimv2" );if( bstrNamespace == NULL ) goto LCleanup; - bstrClassName = SysAllocString( L"Win32_PNPEntity" ); if( bstrClassName == NULL ) goto LCleanup; - bstrDeviceID = SysAllocString( L"DeviceID" ); if( bstrDeviceID == NULL ) goto LCleanup; - - // Connect to WMI - hr = pIWbemLocator->ConnectServer( bstrNamespace, NULL, NULL, 0L, + bstrNamespace = SysAllocString( L"\\\\.\\root\\cimv2" );if( bstrNamespace == NULL ) goto LCleanup; + bstrClassName = SysAllocString( L"Win32_PNPEntity" ); if( bstrClassName == NULL ) goto LCleanup; + bstrDeviceID = SysAllocString( L"DeviceID" ); if( bstrDeviceID == NULL ) goto LCleanup; + + // Connect to WMI + hr = pIWbemLocator->ConnectServer( bstrNamespace, NULL, NULL, 0L, 0L, NULL, NULL, &pIWbemServices ); if( FAILED(hr) || pIWbemServices == NULL ) goto LCleanup; - // Switch security level to IMPERSONATE. - CoSetProxyBlanket( pIWbemServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL, - RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE ); + // Switch security level to IMPERSONATE. + CoSetProxyBlanket( pIWbemServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL, + RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE ); - hr = pIWbemServices->CreateInstanceEnum( bstrClassName, 0, NULL, &pEnumDevices ); + hr = pIWbemServices->CreateInstanceEnum( bstrClassName, 0, NULL, &pEnumDevices ); if( FAILED(hr) || pEnumDevices == NULL ) goto LCleanup; @@ -95,32 +95,32 @@ BOOL IsXInputDevice( const GUID* pGuidProductFromDirectInput ) hr = pDevices[iDevice]->Get( bstrDeviceID, 0L, &var, NULL, NULL ); if( SUCCEEDED( hr ) ) { - if(var.vt == VT_BSTR && var.bstrVal != NULL) - { - // Check if the device ID contains "IG_". If it does, then it's an XInput device - // This information can not be found from DirectInput - if( wcsstr( var.bstrVal, L"IG_" ) ) - { - // If it does, then get the VID/PID from var.bstrVal - DWORD dwPid = 0, dwVid = 0; - WCHAR* strVid = wcsstr( var.bstrVal, L"VID_" ); - if (strVid && wscanf(strVid, L"VID_%4X", &dwVid) != 1) - dwVid = 0; - WCHAR* strPid = wcsstr( var.bstrVal, L"PID_" ); - if (strPid && wscanf(strPid, L"PID_%4X", &dwPid) != 1) - dwPid = 0; + if(var.vt == VT_BSTR && var.bstrVal != NULL) + { + // Check if the device ID contains "IG_". If it does, then it's an XInput device + // This information can not be found from DirectInput + if( wcsstr( var.bstrVal, L"IG_" ) ) + { + // If it does, then get the VID/PID from var.bstrVal + DWORD dwPid = 0, dwVid = 0; + WCHAR* strVid = wcsstr( var.bstrVal, L"VID_" ); + if (strVid && wscanf(strVid, L"VID_%4X", &dwVid) != 1) + dwVid = 0; + WCHAR* strPid = wcsstr( var.bstrVal, L"PID_" ); + if (strPid && wscanf(strPid, L"PID_%4X", &dwPid) != 1) + dwPid = 0; - // Compare the VID/PID to the DInput device - DWORD dwVidPid = MAKELONG( dwVid, dwPid ); - if( dwVidPid == pGuidProductFromDirectInput->Data1 ) - { - bIsXinputDevice = true; - goto LCleanup; - } - } - } - VariantClear(&var); - } + // Compare the VID/PID to the DInput device + DWORD dwVidPid = MAKELONG( dwVid, dwPid ); + if( dwVidPid == pGuidProductFromDirectInput->Data1 ) + { + bIsXinputDevice = true; + goto LCleanup; + } + } + } + VariantClear(&var); + } SAFE_RELEASE( pDevices[iDevice] ); } } @@ -146,677 +146,677 @@ LCleanup: void AxisDeadzone( SHORT &AxisValue, long lDeadZoneValue, float fDeadZoneRelation ) { - short sign = AxisValue < 0 ? -1 : 1; - float value = (float)(AxisValue < 0 ? -AxisValue : AxisValue); + short sign = AxisValue < 0 ? -1 : 1; + float value = (float)(AxisValue < 0 ? -AxisValue : AxisValue); - if(value < lDeadZoneValue) - value = 0; - else - { - value = (value - lDeadZoneValue) * fDeadZoneRelation; - value = value > 32767.0f ? 32767.0f : value; - } + if(value < lDeadZoneValue) + value = 0; + else + { + value = (value - lDeadZoneValue) * fDeadZoneRelation; + value = value > 32767.0f ? 32767.0f : value; + } - AxisValue = (SHORT)(value * sign); + AxisValue = (SHORT)(value * sign); } void GetXInputControllerKeys( const int indexController, LPDWORD Keys ) { - if (fnXInputGetState == NULL) - { - return; - } + if (fnXInputGetState == NULL) + { + return; + } - using namespace N64_BUTTONS; + using namespace N64_BUTTONS; - LPCONTROLLER pcController = &g_pcControllers[indexController]; - LPXCONTROLLER gController = &g_pcControllers[indexController].xiController; + LPCONTROLLER pcController = &g_pcControllers[indexController]; + LPXCONTROLLER gController = &g_pcControllers[indexController].xiController; - *Keys = 0; + *Keys = 0; - if ( !gController->bConfigured ) - return; + if ( !gController->bConfigured ) + return; - DWORD result; - XINPUT_STATE state; + DWORD result; + XINPUT_STATE state; - result = fnXInputGetState(gController->nControl, &state); + result = fnXInputGetState(gController->nControl, &state); - if( result != ERROR_SUCCESS ) - return; + if( result != ERROR_SUCCESS ) + return; - DWORD wButtons = state.Gamepad.wButtons; + DWORD wButtons = state.Gamepad.wButtons; - if( pcController->bPadDeadZone > 0 ) - { - const int RANGERELATIVE = 32767; - long lDeadZoneValue = pcController->bPadDeadZone * RANGERELATIVE / 100; - float fDeadZoneRelation = (float)RANGERELATIVE / (float)( RANGERELATIVE - lDeadZoneValue ); + if( pcController->bPadDeadZone > 0 ) + { + const int RANGERELATIVE = 32767; + long lDeadZoneValue = pcController->bPadDeadZone * RANGERELATIVE / 100; + float fDeadZoneRelation = (float)RANGERELATIVE / (float)( RANGERELATIVE - lDeadZoneValue ); - AxisDeadzone(state.Gamepad.sThumbLX, lDeadZoneValue, fDeadZoneRelation); - AxisDeadzone(state.Gamepad.sThumbLY, lDeadZoneValue, fDeadZoneRelation); - AxisDeadzone(state.Gamepad.sThumbRX, lDeadZoneValue, fDeadZoneRelation); - AxisDeadzone(state.Gamepad.sThumbRY, lDeadZoneValue, fDeadZoneRelation); - } + AxisDeadzone(state.Gamepad.sThumbLX, lDeadZoneValue, fDeadZoneRelation); + AxisDeadzone(state.Gamepad.sThumbLY, lDeadZoneValue, fDeadZoneRelation); + AxisDeadzone(state.Gamepad.sThumbRX, lDeadZoneValue, fDeadZoneRelation); + AxisDeadzone(state.Gamepad.sThumbRY, lDeadZoneValue, fDeadZoneRelation); + } - short LY = state.Gamepad.sThumbLY * N64_ANALOG_MAX / XC_ANALOG_MAX; - short LX = state.Gamepad.sThumbLX * N64_ANALOG_MAX / XC_ANALOG_MAX; + short LY = state.Gamepad.sThumbLY * N64_ANALOG_MAX / XC_ANALOG_MAX; + short LX = state.Gamepad.sThumbLX * N64_ANALOG_MAX / XC_ANALOG_MAX; - short RY = state.Gamepad.sThumbRY * N64_ANALOG_MAX / XC_ANALOG_MAX; - short RX = state.Gamepad.sThumbRX * N64_ANALOG_MAX / XC_ANALOG_MAX; + short RY = state.Gamepad.sThumbRY * N64_ANALOG_MAX / XC_ANALOG_MAX; + short RX = state.Gamepad.sThumbRX * N64_ANALOG_MAX / XC_ANALOG_MAX; - short XAx = 0, XAxc = 0; - short YAx = 0, YAxc = 0; + short XAx = 0, XAxc = 0; + short YAx = 0, YAxc = 0; - WORD valButtons = 0; - valButtons |= ( wButtons & gController->stButtons.iDRight ) ? DRight : 0; - valButtons |= ( wButtons & gController->stButtons.iDLeft ) ? DLeft : 0; - valButtons |= ( wButtons & gController->stButtons.iDDown ) ? DDown : 0; - valButtons |= ( wButtons & gController->stButtons.iDUp ) ? DUp : 0; - valButtons |= ( wButtons & gController->stButtons.iStart ) ? Start : 0; - valButtons |= ( wButtons & gController->stButtons.iZ ) ? Z : 0; - valButtons |= ( wButtons & gController->stButtons.iB ) ? B : 0; - valButtons |= ( wButtons & gController->stButtons.iA ) ? A : 0; - valButtons |= ( wButtons & gController->stButtons.iCRight ) ? CRight : 0; - valButtons |= ( wButtons & gController->stButtons.iCLeft ) ? CLeft : 0; - valButtons |= ( wButtons & gController->stButtons.iCDown ) ? CDown : 0; - valButtons |= ( wButtons & gController->stButtons.iCUp ) ? CUp : 0; - valButtons |= ( wButtons & gController->stButtons.iR ) ? R : 0; - valButtons |= ( wButtons & gController->stButtons.iL ) ? L : 0; + WORD valButtons = 0; + valButtons |= ( wButtons & gController->stButtons.iDRight ) ? DRight : 0; + valButtons |= ( wButtons & gController->stButtons.iDLeft ) ? DLeft : 0; + valButtons |= ( wButtons & gController->stButtons.iDDown ) ? DDown : 0; + valButtons |= ( wButtons & gController->stButtons.iDUp ) ? DUp : 0; + valButtons |= ( wButtons & gController->stButtons.iStart ) ? Start : 0; + valButtons |= ( wButtons & gController->stButtons.iZ ) ? Z : 0; + valButtons |= ( wButtons & gController->stButtons.iB ) ? B : 0; + valButtons |= ( wButtons & gController->stButtons.iA ) ? A : 0; + valButtons |= ( wButtons & gController->stButtons.iCRight ) ? CRight : 0; + valButtons |= ( wButtons & gController->stButtons.iCLeft ) ? CLeft : 0; + valButtons |= ( wButtons & gController->stButtons.iCDown ) ? CDown : 0; + valButtons |= ( wButtons & gController->stButtons.iCUp ) ? CUp : 0; + valButtons |= ( wButtons & gController->stButtons.iR ) ? R : 0; + valButtons |= ( wButtons & gController->stButtons.iL ) ? L : 0; - valButtons |= state.Gamepad.bLeftTrigger > 30 ? gController->stAnalogs.iLeftTrigger : 0; - valButtons |= state.Gamepad.bRightTrigger > 30 ? gController->stAnalogs.iRightTrigger : 0; + valButtons |= state.Gamepad.bLeftTrigger > 30 ? gController->stAnalogs.iLeftTrigger : 0; + valButtons |= state.Gamepad.bRightTrigger > 30 ? gController->stAnalogs.iRightTrigger : 0; - if (LX >= BUTTON_ANALOG_VALUE) - valButtons |= gController->stAnalogs.iLXAxis & ((CRight | DRight) << 16) ? gController->stAnalogs.iLXAxis >> 16 : 0; - if (LX <= -BUTTON_ANALOG_VALUE) - valButtons |= gController->stAnalogs.iLXAxis & (CLeft | DLeft) ? gController->stAnalogs.iLXAxis : 0; - if (LY >= BUTTON_ANALOG_VALUE) - valButtons |= gController->stAnalogs.iLYAxis & ((CUp | DUp) << 16) ? gController->stAnalogs.iLYAxis >> 16 : 0; - if (LY <= -BUTTON_ANALOG_VALUE) - valButtons |= gController->stAnalogs.iLYAxis & (CDown | DDown) ? gController->stAnalogs.iLYAxis : 0; + if (LX >= BUTTON_ANALOG_VALUE) + valButtons |= gController->stAnalogs.iLXAxis & ((CRight | DRight) << 16) ? gController->stAnalogs.iLXAxis >> 16 : 0; + if (LX <= -BUTTON_ANALOG_VALUE) + valButtons |= gController->stAnalogs.iLXAxis & (CLeft | DLeft) ? gController->stAnalogs.iLXAxis : 0; + if (LY >= BUTTON_ANALOG_VALUE) + valButtons |= gController->stAnalogs.iLYAxis & ((CUp | DUp) << 16) ? gController->stAnalogs.iLYAxis >> 16 : 0; + if (LY <= -BUTTON_ANALOG_VALUE) + valButtons |= gController->stAnalogs.iLYAxis & (CDown | DDown) ? gController->stAnalogs.iLYAxis : 0; - if (RX >= BUTTON_ANALOG_VALUE) - valButtons |= gController->stAnalogs.iRXAxis & ((CRight | DRight) << 16) ? gController->stAnalogs.iRXAxis >> 16 : 0; - if (RX <= -BUTTON_ANALOG_VALUE) - valButtons |= gController->stAnalogs.iRXAxis & (CLeft | DLeft) ? gController->stAnalogs.iRXAxis : 0; - if (RY >= BUTTON_ANALOG_VALUE) - valButtons |= gController->stAnalogs.iRYAxis & ((CUp | DUp) << 16) ? gController->stAnalogs.iRYAxis >> 16 : 0; - if (RY <= -BUTTON_ANALOG_VALUE) - valButtons |= gController->stAnalogs.iRYAxis & (CDown | DDown) ? gController->stAnalogs.iRYAxis : 0; + if (RX >= BUTTON_ANALOG_VALUE) + valButtons |= gController->stAnalogs.iRXAxis & ((CRight | DRight) << 16) ? gController->stAnalogs.iRXAxis >> 16 : 0; + if (RX <= -BUTTON_ANALOG_VALUE) + valButtons |= gController->stAnalogs.iRXAxis & (CLeft | DLeft) ? gController->stAnalogs.iRXAxis : 0; + if (RY >= BUTTON_ANALOG_VALUE) + valButtons |= gController->stAnalogs.iRYAxis & ((CUp | DUp) << 16) ? gController->stAnalogs.iRYAxis >> 16 : 0; + if (RY <= -BUTTON_ANALOG_VALUE) + valButtons |= gController->stAnalogs.iRYAxis & (CDown | DDown) ? gController->stAnalogs.iRYAxis : 0; - if (gController->stAnalogs.iLXAxis == XAxis) - { - XAx += LX; - XAxc += LX > 0 ? 1 : 0; - } - if (gController->stAnalogs.iRXAxis == XAxis) - { - XAx += RX; - XAxc += RX > 0 ? 1 : 0; - } - if( XAxc ) - XAx /= XAxc; + if (gController->stAnalogs.iLXAxis == XAxis) + { + XAx += LX; + XAxc += LX > 0 ? 1 : 0; + } + if (gController->stAnalogs.iRXAxis == XAxis) + { + XAx += RX; + XAxc += RX > 0 ? 1 : 0; + } + if( XAxc ) + XAx /= XAxc; - if (gController->stAnalogs.iLYAxis == YAxis) - { - YAx += LY; - YAxc += LY > 0 ? 1 : 0; - } - if (gController->stAnalogs.iRYAxis == YAxis) - { - YAx += RY; - YAxc += RY > 0 ? 1 : 0; - } - if( YAxc ) - YAx /= YAxc; + if (gController->stAnalogs.iLYAxis == YAxis) + { + YAx += LY; + YAxc += LY > 0 ? 1 : 0; + } + if (gController->stAnalogs.iRYAxis == YAxis) + { + YAx += RY; + YAxc += RY > 0 ? 1 : 0; + } + if( YAxc ) + YAx /= YAxc; - *Keys = MAKELONG(valButtons, MAKEWORD(XAx, YAx)); + *Keys = MAKELONG(valButtons, MAKEWORD(XAx, YAx)); } void DefaultXInputControllerKeys( LPXCONTROLLER gController) { - using namespace N64_BUTTONS; + using namespace N64_BUTTONS; - gController->stButtons.iA = XINPUT_GAMEPAD_A | XINPUT_GAMEPAD_Y; - gController->stButtons.iB = XINPUT_GAMEPAD_B | XINPUT_GAMEPAD_X; - gController->stButtons.iStart = XINPUT_GAMEPAD_START | XINPUT_GAMEPAD_BACK; - gController->stButtons.iDDown = XINPUT_GAMEPAD_DPAD_DOWN; - gController->stButtons.iDLeft = XINPUT_GAMEPAD_DPAD_LEFT; - gController->stButtons.iDRight = XINPUT_GAMEPAD_DPAD_RIGHT; - gController->stButtons.iDUp = XINPUT_GAMEPAD_DPAD_UP; - gController->stButtons.iL = XINPUT_GAMEPAD_LEFT_SHOULDER; - gController->stButtons.iR = XINPUT_GAMEPAD_RIGHT_SHOULDER; - gController->stAnalogs.iLeftTrigger = Z; - gController->stAnalogs.iRightTrigger = R; - gController->stAnalogs.iRXAxis = (CRight << 16) | CLeft; - gController->stAnalogs.iRYAxis = (CUp << 16) | CDown; - gController->stAnalogs.iLXAxis = XAxis; - gController->stAnalogs.iLYAxis = YAxis; - gController->bConfigured = true; + gController->stButtons.iA = XINPUT_GAMEPAD_A | XINPUT_GAMEPAD_Y; + gController->stButtons.iB = XINPUT_GAMEPAD_B | XINPUT_GAMEPAD_X; + gController->stButtons.iStart = XINPUT_GAMEPAD_START | XINPUT_GAMEPAD_BACK; + gController->stButtons.iDDown = XINPUT_GAMEPAD_DPAD_DOWN; + gController->stButtons.iDLeft = XINPUT_GAMEPAD_DPAD_LEFT; + gController->stButtons.iDRight = XINPUT_GAMEPAD_DPAD_RIGHT; + gController->stButtons.iDUp = XINPUT_GAMEPAD_DPAD_UP; + gController->stButtons.iL = XINPUT_GAMEPAD_LEFT_SHOULDER; + gController->stButtons.iR = XINPUT_GAMEPAD_RIGHT_SHOULDER; + gController->stAnalogs.iLeftTrigger = Z; + gController->stAnalogs.iRightTrigger = R; + gController->stAnalogs.iRXAxis = (CRight << 16) | CLeft; + gController->stAnalogs.iRYAxis = (CUp << 16) | CDown; + gController->stAnalogs.iLXAxis = XAxis; + gController->stAnalogs.iLYAxis = YAxis; + gController->bConfigured = true; } void VibrateXInputController( DWORD nController, int LeftMotorVal, int RightMotorVal ) { - if (fnXInputSetState == NULL) - { - return; - } + if (fnXInputSetState == NULL) + { + return; + } - XINPUT_VIBRATION vibration; + XINPUT_VIBRATION vibration; - ZeroMemory( &vibration, sizeof( XINPUT_VIBRATION ) ); + ZeroMemory( &vibration, sizeof( XINPUT_VIBRATION ) ); - vibration.wLeftMotorSpeed = LeftMotorVal; - vibration.wRightMotorSpeed = RightMotorVal; + vibration.wLeftMotorSpeed = LeftMotorVal; + vibration.wRightMotorSpeed = RightMotorVal; - fnXInputSetState(nController, &vibration); + fnXInputSetState(nController, &vibration); } bool InitXinput() { - //Lets dynamically load in the XInput library - if (g_hXInputDLL == NULL) - g_hXInputDLL = LoadLibrary("Xinput1_4.dll"); + //Lets dynamically load in the XInput library + if (g_hXInputDLL == NULL) + g_hXInputDLL = LoadLibrary("Xinput1_4.dll"); - if (g_hXInputDLL == NULL) - { - //Ok since 1.4 is present, try 9.1.0 as its present on Vista and newer - g_hXInputDLL = LoadLibrary("Xinput9_1_0.dll"); - } - if (g_hXInputDLL == NULL) - { - return false; - } + if (g_hXInputDLL == NULL) + { + //Ok since 1.4 is present, try 9.1.0 as its present on Vista and newer + g_hXInputDLL = LoadLibrary("Xinput9_1_0.dll"); + } + if (g_hXInputDLL == NULL) + { + return false; + } - //Prepare the functions where going to use, nice and simple for XInput - fnXInputSetState = (DWORD(WINAPI *) (DWORD, XINPUT_VIBRATION*))GetProcAddress(g_hXInputDLL, "XInputSetState"); - fnXInputGetState = (DWORD(WINAPI *) (DWORD, XINPUT_STATE*))GetProcAddress(g_hXInputDLL, "XInputGetState"); - return true; + //Prepare the functions where going to use, nice and simple for XInput + fnXInputSetState = (DWORD(WINAPI *) (DWORD, XINPUT_VIBRATION*))GetProcAddress(g_hXInputDLL, "XInputSetState"); + fnXInputGetState = (DWORD(WINAPI *) (DWORD, XINPUT_STATE*))GetProcAddress(g_hXInputDLL, "XInputGetState"); + return true; } void FreeXinput() { - //Unload the Library - if (g_hXInputDLL != NULL) - { - FreeLibrary(g_hXInputDLL); - g_hXInputDLL = NULL; - } + //Unload the Library + if (g_hXInputDLL != NULL) + { + FreeLibrary(g_hXInputDLL); + g_hXInputDLL = NULL; + } } bool InitiateXInputController( LPXCONTROLLER gController, int nControl ) { - if (fnXInputGetState == NULL || fnXInputSetState == NULL) - { - return false; - } - - gController->nControl = iXinputControlId; - iXinputControlId++; + if (fnXInputGetState == NULL || fnXInputSetState == NULL) + { + return false; + } - TCHAR buffer[MAX_PATH]; - GetDirectory( buffer, DIRECTORY_CONFIG ); - _stprintf_s( buffer, _T("%sXInput Controller %d Config.xcc"), buffer, nControl + 1 ); - FILE *file = _tfopen( buffer, _T("rS") ); - if( file ) - { - LoadXInputConfigFromFile( file, gController ); - fclose( file ); - } + gController->nControl = iXinputControlId; + iXinputControlId++; - if( !gController->bConfigured ) - DefaultXInputControllerKeys( gController ); + TCHAR buffer[MAX_PATH]; + GetDirectory( buffer, DIRECTORY_CONFIG ); + _stprintf_s( buffer, _T("%sXInput Controller %d Config.xcc"), buffer, nControl + 1 ); + FILE *file = _tfopen( buffer, _T("rS") ); + if( file ) + { + LoadXInputConfigFromFile( file, gController ); + fclose( file ); + } - return true; + if( !gController->bConfigured ) + DefaultXInputControllerKeys( gController ); + + return true; } TCHAR * GetN64ButtonNameFromButtonCode( int Button ) { - using namespace N64_BUTTONS; + using namespace N64_BUTTONS; - TCHAR *btnName; - btnName = new TCHAR[10]; + TCHAR *btnName; + btnName = new TCHAR[10]; - switch( Button ) - { - case A: _tcscpy_s( btnName, 10, _T( "A" )); break; - case B: _tcscpy_s( btnName, 10, _T( "B" )); break; - case Z: _tcscpy_s( btnName, 10, _T( "Z" )); break; - case L: _tcscpy_s( btnName, 10, _T( "L" )); break; - case R: _tcscpy_s( btnName, 10, _T( "R" )); break; - case Start: _tcscpy_s( btnName, 10, _T( "Start" )); break; - case CUp: _tcscpy_s( btnName, 10, _T( "C-Up" )); break; - case CDown: _tcscpy_s( btnName, 10, _T( "C-Down" )); break; - case CRight: _tcscpy_s( btnName, 10, _T( "C-Right" )); break; - case CLeft: _tcscpy_s( btnName, 10, _T( "C-Left" )); break; - case DUp: _tcscpy_s( btnName, 10, _T( "D-Up" )); break; - case DDown: _tcscpy_s( btnName, 10, _T( "D-Down" )); break; - case DRight: _tcscpy_s( btnName, 10, _T( "D-Right" )); break; - case DLeft: _tcscpy_s( btnName, 10, _T( "D-Left" )); break; - default: _tcscpy_s( btnName, 10, _T( "None" )); - } - return btnName; + switch( Button ) + { + case A: _tcscpy_s( btnName, 10, _T( "A" )); break; + case B: _tcscpy_s( btnName, 10, _T( "B" )); break; + case Z: _tcscpy_s( btnName, 10, _T( "Z" )); break; + case L: _tcscpy_s( btnName, 10, _T( "L" )); break; + case R: _tcscpy_s( btnName, 10, _T( "R" )); break; + case Start: _tcscpy_s( btnName, 10, _T( "Start" )); break; + case CUp: _tcscpy_s( btnName, 10, _T( "C-Up" )); break; + case CDown: _tcscpy_s( btnName, 10, _T( "C-Down" )); break; + case CRight: _tcscpy_s( btnName, 10, _T( "C-Right" )); break; + case CLeft: _tcscpy_s( btnName, 10, _T( "C-Left" )); break; + case DUp: _tcscpy_s( btnName, 10, _T( "D-Up" )); break; + case DDown: _tcscpy_s( btnName, 10, _T( "D-Down" )); break; + case DRight: _tcscpy_s( btnName, 10, _T( "D-Right" )); break; + case DLeft: _tcscpy_s( btnName, 10, _T( "D-Left" )); break; + default: _tcscpy_s( btnName, 10, _T( "None" )); + } + return btnName; } TCHAR * GetN64ButtonFromXInputControl( LPXCONTROLLER gController, int XInputButton ) { - using namespace N64_BUTTONS; + using namespace N64_BUTTONS; - if( !gController || !gController->bConfigured ) - return GetN64ButtonNameFromButtonCode( 0 ); + if( !gController || !gController->bConfigured ) + return GetN64ButtonNameFromButtonCode( 0 ); - int N64ButtonCode = 0; + int N64ButtonCode = 0; - N64ButtonCode |= gController->stButtons.iA & XInputButton ? A : 0; - N64ButtonCode |= gController->stButtons.iB & XInputButton ? B : 0; - N64ButtonCode |= gController->stButtons.iCDown & XInputButton ? CDown : 0; - N64ButtonCode |= gController->stButtons.iCLeft & XInputButton ? CLeft : 0; - N64ButtonCode |= gController->stButtons.iCRight & XInputButton ? CRight : 0; - N64ButtonCode |= gController->stButtons.iCUp & XInputButton ? CUp : 0; - N64ButtonCode |= gController->stButtons.iDDown & XInputButton ? DDown : 0; - N64ButtonCode |= gController->stButtons.iDLeft & XInputButton ? DLeft : 0; - N64ButtonCode |= gController->stButtons.iDRight & XInputButton ? DRight : 0; - N64ButtonCode |= gController->stButtons.iDUp & XInputButton ? DUp : 0; - N64ButtonCode |= gController->stButtons.iL & XInputButton ? L : 0; - N64ButtonCode |= gController->stButtons.iR & XInputButton ? R : 0; - N64ButtonCode |= gController->stButtons.iStart & XInputButton ? Start : 0; - N64ButtonCode |= gController->stButtons.iZ & XInputButton ? Z : 0; + N64ButtonCode |= gController->stButtons.iA & XInputButton ? A : 0; + N64ButtonCode |= gController->stButtons.iB & XInputButton ? B : 0; + N64ButtonCode |= gController->stButtons.iCDown & XInputButton ? CDown : 0; + N64ButtonCode |= gController->stButtons.iCLeft & XInputButton ? CLeft : 0; + N64ButtonCode |= gController->stButtons.iCRight & XInputButton ? CRight : 0; + N64ButtonCode |= gController->stButtons.iCUp & XInputButton ? CUp : 0; + N64ButtonCode |= gController->stButtons.iDDown & XInputButton ? DDown : 0; + N64ButtonCode |= gController->stButtons.iDLeft & XInputButton ? DLeft : 0; + N64ButtonCode |= gController->stButtons.iDRight & XInputButton ? DRight : 0; + N64ButtonCode |= gController->stButtons.iDUp & XInputButton ? DUp : 0; + N64ButtonCode |= gController->stButtons.iL & XInputButton ? L : 0; + N64ButtonCode |= gController->stButtons.iR & XInputButton ? R : 0; + N64ButtonCode |= gController->stButtons.iStart & XInputButton ? Start : 0; + N64ButtonCode |= gController->stButtons.iZ & XInputButton ? Z : 0; - return GetN64ButtonNameFromButtonCode( N64ButtonCode ); + return GetN64ButtonNameFromButtonCode( N64ButtonCode ); } TCHAR * GetN64ButtonArrayFromXAnalog( LPXCONTROLLER gController, int XThStickOrXDpad ) { - using namespace N64_BUTTONS; + using namespace N64_BUTTONS; - if( !gController || !gController->bConfigured ) - return NULL; + if( !gController || !gController->bConfigured ) + return NULL; - TCHAR *name; - name = new TCHAR[15]; + TCHAR *name; + name = new TCHAR[15]; - switch( XThStickOrXDpad ) - { - case XC_LTBS: - if( gController->stAnalogs.iLXAxis == XAxis ) - _tcscpy_s( name, 15, _T( "Analog Stick" )); - else if( gController->stAnalogs.iLXAxis & CLeft ) - _tcscpy_s( name, 15, _T( "C Buttons" )); - else if( gController->stAnalogs.iLXAxis & DLeft ) - _tcscpy_s( name, 15, _T( "DPad" )); - else - _tcscpy_s( name, 15, _T( "None" )); - break; + switch( XThStickOrXDpad ) + { + case XC_LTBS: + if( gController->stAnalogs.iLXAxis == XAxis ) + _tcscpy_s( name, 15, _T( "Analog Stick" )); + else if( gController->stAnalogs.iLXAxis & CLeft ) + _tcscpy_s( name, 15, _T( "C Buttons" )); + else if( gController->stAnalogs.iLXAxis & DLeft ) + _tcscpy_s( name, 15, _T( "DPad" )); + else + _tcscpy_s( name, 15, _T( "None" )); + break; - case XC_RTBS: - if( gController->stAnalogs.iRXAxis == XAxis ) - _tcscpy_s( name, 15, _T( "Analog Stick" )); - else if( gController->stAnalogs.iRXAxis & CLeft ) - _tcscpy_s( name, 15, _T( "C Buttons" )); - else if( gController->stAnalogs.iRXAxis & DLeft ) - _tcscpy_s( name, 15, _T( "DPad" )); - else - _tcscpy_s( name, 15, _T( "None" )); - break; + case XC_RTBS: + if( gController->stAnalogs.iRXAxis == XAxis ) + _tcscpy_s( name, 15, _T( "Analog Stick" )); + else if( gController->stAnalogs.iRXAxis & CLeft ) + _tcscpy_s( name, 15, _T( "C Buttons" )); + else if( gController->stAnalogs.iRXAxis & DLeft ) + _tcscpy_s( name, 15, _T( "DPad" )); + else + _tcscpy_s( name, 15, _T( "None" )); + break; - case XC_DPAD: - if( gController->stButtons.iCDown == XINPUT_GAMEPAD_DPAD_DOWN ) - _tcscpy_s( name, 15, _T( "C Button" )); - else if( gController->stButtons.iDDown == XINPUT_GAMEPAD_DPAD_DOWN ) - _tcscpy_s( name, 15, _T( "DPad" )); - else - _tcscpy_s( name, 15, _T( "None" )); - break; + case XC_DPAD: + if( gController->stButtons.iCDown == XINPUT_GAMEPAD_DPAD_DOWN ) + _tcscpy_s( name, 15, _T( "C Button" )); + else if( gController->stButtons.iDDown == XINPUT_GAMEPAD_DPAD_DOWN ) + _tcscpy_s( name, 15, _T( "DPad" )); + else + _tcscpy_s( name, 15, _T( "None" )); + break; - default: - _tcscpy_s( name, 15, _T( "None" )); - } - return name; + default: + _tcscpy_s( name, 15, _T( "None" )); + } + return name; } bool ReadXInputControllerKeys( HWND hDlg, LPXCONTROLLER gController ) { - if( hDlg == NULL || gController == NULL || !gController->bConfigured) - return false; + if( hDlg == NULL || gController == NULL || !gController->bConfigured) + return false; - SendDlgItemMessage( hDlg, IDC_XC_A, CB_SELECTSTRING, -1, (LPARAM)GetN64ButtonFromXInputControl( gController, XINPUT_GAMEPAD_A )); - SendDlgItemMessage( hDlg, IDC_XC_B, CB_SELECTSTRING, -1, (LPARAM)GetN64ButtonFromXInputControl( gController, XINPUT_GAMEPAD_B )); - SendDlgItemMessage( hDlg, IDC_XC_X, CB_SELECTSTRING, -1, (LPARAM)GetN64ButtonFromXInputControl( gController, XINPUT_GAMEPAD_X )); - SendDlgItemMessage( hDlg, IDC_XC_Y, CB_SELECTSTRING, -1, (LPARAM)GetN64ButtonFromXInputControl( gController, XINPUT_GAMEPAD_Y )); - SendDlgItemMessage( hDlg, IDC_XC_BACK, CB_SELECTSTRING, -1, (LPARAM)GetN64ButtonFromXInputControl( gController, XINPUT_GAMEPAD_BACK )); - SendDlgItemMessage( hDlg, IDC_XC_START, CB_SELECTSTRING, -1, (LPARAM)GetN64ButtonFromXInputControl( gController, XINPUT_GAMEPAD_START )); - SendDlgItemMessage( hDlg, IDC_XC_LB, CB_SELECTSTRING, -1, (LPARAM)GetN64ButtonFromXInputControl( gController, XINPUT_GAMEPAD_LEFT_SHOULDER )); - SendDlgItemMessage( hDlg, IDC_XC_RB, CB_SELECTSTRING, -1, (LPARAM)GetN64ButtonFromXInputControl( gController, XINPUT_GAMEPAD_RIGHT_SHOULDER )); - SendDlgItemMessage( hDlg, IDC_XC_LTSB, CB_SELECTSTRING, -1, (LPARAM)GetN64ButtonFromXInputControl( gController, XINPUT_GAMEPAD_LEFT_THUMB )); - SendDlgItemMessage( hDlg, IDC_XC_RTSB, CB_SELECTSTRING, -1, (LPARAM)GetN64ButtonFromXInputControl( gController, XINPUT_GAMEPAD_RIGHT_THUMB )); + SendDlgItemMessage( hDlg, IDC_XC_A, CB_SELECTSTRING, -1, (LPARAM)GetN64ButtonFromXInputControl( gController, XINPUT_GAMEPAD_A )); + SendDlgItemMessage( hDlg, IDC_XC_B, CB_SELECTSTRING, -1, (LPARAM)GetN64ButtonFromXInputControl( gController, XINPUT_GAMEPAD_B )); + SendDlgItemMessage( hDlg, IDC_XC_X, CB_SELECTSTRING, -1, (LPARAM)GetN64ButtonFromXInputControl( gController, XINPUT_GAMEPAD_X )); + SendDlgItemMessage( hDlg, IDC_XC_Y, CB_SELECTSTRING, -1, (LPARAM)GetN64ButtonFromXInputControl( gController, XINPUT_GAMEPAD_Y )); + SendDlgItemMessage( hDlg, IDC_XC_BACK, CB_SELECTSTRING, -1, (LPARAM)GetN64ButtonFromXInputControl( gController, XINPUT_GAMEPAD_BACK )); + SendDlgItemMessage( hDlg, IDC_XC_START, CB_SELECTSTRING, -1, (LPARAM)GetN64ButtonFromXInputControl( gController, XINPUT_GAMEPAD_START )); + SendDlgItemMessage( hDlg, IDC_XC_LB, CB_SELECTSTRING, -1, (LPARAM)GetN64ButtonFromXInputControl( gController, XINPUT_GAMEPAD_LEFT_SHOULDER )); + SendDlgItemMessage( hDlg, IDC_XC_RB, CB_SELECTSTRING, -1, (LPARAM)GetN64ButtonFromXInputControl( gController, XINPUT_GAMEPAD_RIGHT_SHOULDER )); + SendDlgItemMessage( hDlg, IDC_XC_LTSB, CB_SELECTSTRING, -1, (LPARAM)GetN64ButtonFromXInputControl( gController, XINPUT_GAMEPAD_LEFT_THUMB )); + SendDlgItemMessage( hDlg, IDC_XC_RTSB, CB_SELECTSTRING, -1, (LPARAM)GetN64ButtonFromXInputControl( gController, XINPUT_GAMEPAD_RIGHT_THUMB )); - SendDlgItemMessage( hDlg, IDC_XC_LT, CB_SELECTSTRING, -1, (LPARAM)GetN64ButtonNameFromButtonCode( gController->stAnalogs.iLeftTrigger )); - SendDlgItemMessage( hDlg, IDC_XC_RT, CB_SELECTSTRING, -1, (LPARAM)GetN64ButtonNameFromButtonCode( gController->stAnalogs.iRightTrigger )); + SendDlgItemMessage( hDlg, IDC_XC_LT, CB_SELECTSTRING, -1, (LPARAM)GetN64ButtonNameFromButtonCode( gController->stAnalogs.iLeftTrigger )); + SendDlgItemMessage( hDlg, IDC_XC_RT, CB_SELECTSTRING, -1, (LPARAM)GetN64ButtonNameFromButtonCode( gController->stAnalogs.iRightTrigger )); - SendDlgItemMessage( hDlg, IDC_XC_DPAD, CB_SELECTSTRING, -1, (LPARAM)GetN64ButtonArrayFromXAnalog( gController, XC_DPAD )); - SendDlgItemMessage( hDlg, IDC_XC_LTS, CB_SELECTSTRING, -1, (LPARAM)GetN64ButtonArrayFromXAnalog( gController, XC_LTBS )); - SendDlgItemMessage( hDlg, IDC_XC_RTS, CB_SELECTSTRING, -1, (LPARAM)GetN64ButtonArrayFromXAnalog( gController, XC_RTBS )); + SendDlgItemMessage( hDlg, IDC_XC_DPAD, CB_SELECTSTRING, -1, (LPARAM)GetN64ButtonArrayFromXAnalog( gController, XC_DPAD )); + SendDlgItemMessage( hDlg, IDC_XC_LTS, CB_SELECTSTRING, -1, (LPARAM)GetN64ButtonArrayFromXAnalog( gController, XC_LTBS )); + SendDlgItemMessage( hDlg, IDC_XC_RTS, CB_SELECTSTRING, -1, (LPARAM)GetN64ButtonArrayFromXAnalog( gController, XC_RTBS )); - return true; + return true; } int GetComboBoxXInputKey( int ComboBox ) { - switch( ComboBox ) - { - case IDC_XC_A: return XINPUT_GAMEPAD_A; - case IDC_XC_B: return XINPUT_GAMEPAD_B; - case IDC_XC_X: return XINPUT_GAMEPAD_X; - case IDC_XC_Y: return XINPUT_GAMEPAD_Y; - case IDC_XC_BACK: return XINPUT_GAMEPAD_BACK; - case IDC_XC_START: return XINPUT_GAMEPAD_START; - case IDC_XC_LB: return XINPUT_GAMEPAD_LEFT_SHOULDER; - case IDC_XC_RB: return XINPUT_GAMEPAD_RIGHT_SHOULDER; - case IDC_XC_LT: return -1; // triggers don't use these macros - case IDC_XC_RT: return -1; - case IDC_XC_LTSB: return XINPUT_GAMEPAD_LEFT_THUMB; - case IDC_XC_RTSB: return XINPUT_GAMEPAD_RIGHT_THUMB; - case IDC_XC_DPAD: return -2; // to handle analogs and dpad - case IDC_XC_LTS: return -2; - case IDC_XC_RTS: return -2; - default: return 0; - } + switch( ComboBox ) + { + case IDC_XC_A: return XINPUT_GAMEPAD_A; + case IDC_XC_B: return XINPUT_GAMEPAD_B; + case IDC_XC_X: return XINPUT_GAMEPAD_X; + case IDC_XC_Y: return XINPUT_GAMEPAD_Y; + case IDC_XC_BACK: return XINPUT_GAMEPAD_BACK; + case IDC_XC_START: return XINPUT_GAMEPAD_START; + case IDC_XC_LB: return XINPUT_GAMEPAD_LEFT_SHOULDER; + case IDC_XC_RB: return XINPUT_GAMEPAD_RIGHT_SHOULDER; + case IDC_XC_LT: return -1; // triggers don't use these macros + case IDC_XC_RT: return -1; + case IDC_XC_LTSB: return XINPUT_GAMEPAD_LEFT_THUMB; + case IDC_XC_RTSB: return XINPUT_GAMEPAD_RIGHT_THUMB; + case IDC_XC_DPAD: return -2; // to handle analogs and dpad + case IDC_XC_LTS: return -2; + case IDC_XC_RTS: return -2; + default: return 0; + } } -int GetN64ButtonCode( TCHAR *btnName ) //esta wea esta muy fea, hay que buscar una mejor manera definitivamente.. +int GetN64ButtonCode( TCHAR *btnName ) //esta wea esta muy fea, hay que buscar una mejor manera definitivamente.. { - using namespace N64_BUTTONS; + using namespace N64_BUTTONS; - int value = 0; + int value = 0; - if( !_tcscmp( btnName, _T( "A" ))) - value = A; - else if( !_tcscmp( btnName, _T( "B" ))) - value = B; - else if( !_tcscmp( btnName, _T( "R" ))) - value = R; - else if( !_tcscmp( btnName, _T( "L" ))) - value = L; - else if( !_tcscmp( btnName, _T( "Z" ))) - value = Z; - else if( !_tcscmp( btnName, _T( "Start" ))) - value = Start; - else if( !_tcscmp( btnName, _T( "C-Up" ))) - value = CUp; - else if( !_tcscmp( btnName, _T( "C-Down" ))) - value = CDown; - else if( !_tcscmp( btnName, _T( "C-Left" ))) - value = CLeft; - else if( !_tcscmp( btnName, _T( "C-Right" ))) - value = CRight; - else if( !_tcscmp( btnName, _T( "D-Up" ))) - value = DUp; - else if( !_tcscmp( btnName, _T( "D-Down" ))) - value = DDown; - else if( !_tcscmp( btnName, _T( "D-Left" ))) - value = DLeft; - else if( !_tcscmp( btnName, _T( "D-Right" ))) - value = DRight; + if( !_tcscmp( btnName, _T( "A" ))) + value = A; + else if( !_tcscmp( btnName, _T( "B" ))) + value = B; + else if( !_tcscmp( btnName, _T( "R" ))) + value = R; + else if( !_tcscmp( btnName, _T( "L" ))) + value = L; + else if( !_tcscmp( btnName, _T( "Z" ))) + value = Z; + else if( !_tcscmp( btnName, _T( "Start" ))) + value = Start; + else if( !_tcscmp( btnName, _T( "C-Up" ))) + value = CUp; + else if( !_tcscmp( btnName, _T( "C-Down" ))) + value = CDown; + else if( !_tcscmp( btnName, _T( "C-Left" ))) + value = CLeft; + else if( !_tcscmp( btnName, _T( "C-Right" ))) + value = CRight; + else if( !_tcscmp( btnName, _T( "D-Up" ))) + value = DUp; + else if( !_tcscmp( btnName, _T( "D-Down" ))) + value = DDown; + else if( !_tcscmp( btnName, _T( "D-Left" ))) + value = DLeft; + else if( !_tcscmp( btnName, _T( "D-Right" ))) + value = DRight; - return value; + return value; } void ResetXInputControllerKeys( LPXCONTROLLER gController ) { - gController->stButtons.iA = 0; - gController->stButtons.iB = 0; - gController->stButtons.iZ = 0; - gController->stButtons.iL = 0; - gController->stButtons.iR = 0; - gController->stButtons.iStart = 0; - gController->stButtons.iCUp = 0; - gController->stButtons.iCLeft = 0; - gController->stButtons.iCDown = 0; - gController->stButtons.iCRight = 0; - gController->stButtons.iDUp = 0; - gController->stButtons.iDLeft = 0; - gController->stButtons.iDDown = 0; - gController->stButtons.iDRight = 0; + gController->stButtons.iA = 0; + gController->stButtons.iB = 0; + gController->stButtons.iZ = 0; + gController->stButtons.iL = 0; + gController->stButtons.iR = 0; + gController->stButtons.iStart = 0; + gController->stButtons.iCUp = 0; + gController->stButtons.iCLeft = 0; + gController->stButtons.iCDown = 0; + gController->stButtons.iCRight = 0; + gController->stButtons.iDUp = 0; + gController->stButtons.iDLeft = 0; + gController->stButtons.iDDown = 0; + gController->stButtons.iDRight = 0; - gController->stAnalogs.iLeftTrigger = 0; - gController->stAnalogs.iLXAxis = 0; - gController->stAnalogs.iLYAxis = 0; - gController->stAnalogs.iRightTrigger = 0; - gController->stAnalogs.iRXAxis = 0; - gController->stAnalogs.iRYAxis = 0; + gController->stAnalogs.iLeftTrigger = 0; + gController->stAnalogs.iLXAxis = 0; + gController->stAnalogs.iLYAxis = 0; + gController->stAnalogs.iRightTrigger = 0; + gController->stAnalogs.iRXAxis = 0; + gController->stAnalogs.iRYAxis = 0; } void StoreAnalogConfig( LPXCONTROLLER gController, int ComboBox, int index ) { - using namespace N64_BUTTONS; + using namespace N64_BUTTONS; - switch( index ) - { - case 1: // DPAD - switch( ComboBox ) - { - case IDC_XC_DPAD: - gController->stButtons.iDDown |= XINPUT_GAMEPAD_DPAD_DOWN; - gController->stButtons.iDUp |= XINPUT_GAMEPAD_DPAD_UP; - gController->stButtons.iDLeft |= XINPUT_GAMEPAD_DPAD_LEFT; - gController->stButtons.iDRight |= XINPUT_GAMEPAD_DPAD_RIGHT; - break; - case IDC_XC_LTS: - gController->stAnalogs.iLXAxis = ( DRight << 16 ) | DLeft; - gController->stAnalogs.iLYAxis = ( DUp << 16 ) | DDown; - break; - case IDC_XC_RTS: - gController->stAnalogs.iRXAxis = ( DRight << 16 ) | DLeft; - gController->stAnalogs.iRYAxis = ( DUp << 16 ) | DDown; - break; - } - break; - case 2: // C Buttons - switch( ComboBox ) - { - case IDC_XC_DPAD: - gController->stButtons.iCDown |= XINPUT_GAMEPAD_DPAD_DOWN; - gController->stButtons.iCUp |= XINPUT_GAMEPAD_DPAD_UP; - gController->stButtons.iCLeft |= XINPUT_GAMEPAD_DPAD_LEFT; - gController->stButtons.iCRight |= XINPUT_GAMEPAD_DPAD_RIGHT; - break; - case IDC_XC_LTS: - gController->stAnalogs.iLXAxis = ( CRight << 16 ) | CLeft; - gController->stAnalogs.iLYAxis = ( CUp << 16 ) | CDown; - break; - case IDC_XC_RTS: - gController->stAnalogs.iRXAxis = ( CRight << 16 ) | CLeft; - gController->stAnalogs.iRYAxis = ( CUp << 16 ) | CDown; - break; - } - break; - case 3: // Analog - switch( ComboBox ) - { - case IDC_XC_LTS: - gController->stAnalogs.iLXAxis = XAxis; - gController->stAnalogs.iLYAxis = YAxis; - break; - case IDC_XC_RTS: - gController->stAnalogs.iRXAxis = XAxis; - gController->stAnalogs.iRYAxis = YAxis; - break; - } - break; - } + switch( index ) + { + case 1: // DPAD + switch( ComboBox ) + { + case IDC_XC_DPAD: + gController->stButtons.iDDown |= XINPUT_GAMEPAD_DPAD_DOWN; + gController->stButtons.iDUp |= XINPUT_GAMEPAD_DPAD_UP; + gController->stButtons.iDLeft |= XINPUT_GAMEPAD_DPAD_LEFT; + gController->stButtons.iDRight |= XINPUT_GAMEPAD_DPAD_RIGHT; + break; + case IDC_XC_LTS: + gController->stAnalogs.iLXAxis = ( DRight << 16 ) | DLeft; + gController->stAnalogs.iLYAxis = ( DUp << 16 ) | DDown; + break; + case IDC_XC_RTS: + gController->stAnalogs.iRXAxis = ( DRight << 16 ) | DLeft; + gController->stAnalogs.iRYAxis = ( DUp << 16 ) | DDown; + break; + } + break; + case 2: // C Buttons + switch( ComboBox ) + { + case IDC_XC_DPAD: + gController->stButtons.iCDown |= XINPUT_GAMEPAD_DPAD_DOWN; + gController->stButtons.iCUp |= XINPUT_GAMEPAD_DPAD_UP; + gController->stButtons.iCLeft |= XINPUT_GAMEPAD_DPAD_LEFT; + gController->stButtons.iCRight |= XINPUT_GAMEPAD_DPAD_RIGHT; + break; + case IDC_XC_LTS: + gController->stAnalogs.iLXAxis = ( CRight << 16 ) | CLeft; + gController->stAnalogs.iLYAxis = ( CUp << 16 ) | CDown; + break; + case IDC_XC_RTS: + gController->stAnalogs.iRXAxis = ( CRight << 16 ) | CLeft; + gController->stAnalogs.iRYAxis = ( CUp << 16 ) | CDown; + break; + } + break; + case 3: // Analog + switch( ComboBox ) + { + case IDC_XC_LTS: + gController->stAnalogs.iLXAxis = XAxis; + gController->stAnalogs.iLYAxis = YAxis; + break; + case IDC_XC_RTS: + gController->stAnalogs.iRXAxis = XAxis; + gController->stAnalogs.iRYAxis = YAxis; + break; + } + break; + } } void StoreXInputControllerKeys( HWND hDlg, LPXCONTROLLER gController ) { - LRESULT index = -1; - DWORD value = 0; + LRESULT index = -1; + DWORD value = 0; - ResetXInputControllerKeys( gController ); + ResetXInputControllerKeys( gController ); - for( int i = IDC_XC_A; i <= IDC_XC_RTS; i++ ) - { - index = SendDlgItemMessage( hDlg, i, CB_GETCURSEL, 0, 0 ); - value = GetComboBoxXInputKey( i ); - if( value == 0 ) - continue; - else if ( value == -1 ) - { - TCHAR btnName[10] = _T( "\0" ); - SendDlgItemMessage( hDlg, i, CB_GETLBTEXT, index, (LPARAM)(LPTSTR)btnName ); - switch( i ) - { - case IDC_XC_LT: - gController->stAnalogs.iLeftTrigger = GetN64ButtonCode( btnName ); - break; - case IDC_XC_RT: - gController->stAnalogs.iRightTrigger = GetN64ButtonCode( btnName ); - break; - } - continue; - } - else if ( value == -2 ) - { - StoreAnalogConfig( gController, i, index); - continue; - } + for( int i = IDC_XC_A; i <= IDC_XC_RTS; i++ ) + { + index = SendDlgItemMessage( hDlg, i, CB_GETCURSEL, 0, 0 ); + value = GetComboBoxXInputKey( i ); + if( value == 0 ) + continue; + else if ( value == -1 ) + { + TCHAR btnName[10] = _T( "\0" ); + SendDlgItemMessage( hDlg, i, CB_GETLBTEXT, index, (LPARAM)(LPTSTR)btnName ); + switch( i ) + { + case IDC_XC_LT: + gController->stAnalogs.iLeftTrigger = GetN64ButtonCode( btnName ); + break; + case IDC_XC_RT: + gController->stAnalogs.iRightTrigger = GetN64ButtonCode( btnName ); + break; + } + continue; + } + else if ( value == -2 ) + { + StoreAnalogConfig( gController, i, index); + continue; + } - switch( index ) - { - case 1: gController->stButtons.iA |= value; break; - case 2: gController->stButtons.iB |= value; break; - case 3: gController->stButtons.iZ |= value; break; - case 4: gController->stButtons.iL |= value; break; - case 5: gController->stButtons.iR |= value; break; - case 6: gController->stButtons.iStart |= value; break; - case 7: gController->stButtons.iCUp |= value; break; - case 8: gController->stButtons.iCLeft |= value; break; - case 9: gController->stButtons.iCDown |= value; break; - case 10: gController->stButtons.iCRight |= value; break; - case 11: gController->stButtons.iDUp |= value; break; - case 12: gController->stButtons.iDLeft |= value; break; - case 13: gController->stButtons.iDDown |= value; break; - case 14: gController->stButtons.iDRight |= value; break; - } - } - gController->bConfigured = true; + switch( index ) + { + case 1: gController->stButtons.iA |= value; break; + case 2: gController->stButtons.iB |= value; break; + case 3: gController->stButtons.iZ |= value; break; + case 4: gController->stButtons.iL |= value; break; + case 5: gController->stButtons.iR |= value; break; + case 6: gController->stButtons.iStart |= value; break; + case 7: gController->stButtons.iCUp |= value; break; + case 8: gController->stButtons.iCLeft |= value; break; + case 9: gController->stButtons.iCDown |= value; break; + case 10: gController->stButtons.iCRight |= value; break; + case 11: gController->stButtons.iDUp |= value; break; + case 12: gController->stButtons.iDLeft |= value; break; + case 13: gController->stButtons.iDDown |= value; break; + case 14: gController->stButtons.iDRight |= value; break; + } + } + gController->bConfigured = true; } void SaveXInputConfigToFile( FILE *file, LPXCONTROLLER gController ) { -// fprintf( file, "[XInput Controller %d]\n", gController->nControl ); - fprintf( file, "A=%lu\n", gController->stButtons.iA ); - fprintf( file, "B=%lu\n", gController->stButtons.iB ); - fprintf( file, "CDown=%lu\n", gController->stButtons.iCDown ); - fprintf( file, "CLeft=%lu\n", gController->stButtons.iCLeft ); - fprintf( file, "CRight=%lu\n", gController->stButtons.iCRight ); - fprintf( file, "CUp=%lu\n", gController->stButtons.iCUp ); - fprintf( file, "DDown=%lu\n", gController->stButtons.iDDown ); - fprintf( file, "DLeft=%lu\n", gController->stButtons.iDLeft ); - fprintf( file, "DRight=%lu\n", gController->stButtons.iDRight ); - fprintf( file, "DUp=%lu\n", gController->stButtons.iDUp ); - fprintf( file, "L=%lu\n", gController->stButtons.iL ); - fprintf( file, "R=%lu\n", gController->stButtons.iR ); - fprintf( file, "Start=%lu\n", gController->stButtons.iStart ); - fprintf( file, "Z=%lu\n", gController->stButtons.iZ ); - fprintf( file, "XAxis=%lu\n", gController->stButtons.iXAxis ); - fprintf( file, "YAxis=%lu\n", gController->stButtons.iYAxis ); - fprintf( file, "LeftTrigger=%lu\n", gController->stAnalogs.iLeftTrigger ); - fprintf( file, "RightTrigger=%lu\n", gController->stAnalogs.iRightTrigger ); - fprintf( file, "LeftXAxis=%lu\n", gController->stAnalogs.iLXAxis ); - fprintf( file, "LeftYAxis=%lu\n", gController->stAnalogs.iLYAxis ); - fprintf( file, "RightXAxis=%lu\n", gController->stAnalogs.iRXAxis ); - fprintf( file, "RightYAxis=%lu\n\n", gController->stAnalogs.iRYAxis ); +// fprintf( file, "[XInput Controller %d]\n", gController->nControl ); + fprintf( file, "A=%lu\n", gController->stButtons.iA ); + fprintf( file, "B=%lu\n", gController->stButtons.iB ); + fprintf( file, "CDown=%lu\n", gController->stButtons.iCDown ); + fprintf( file, "CLeft=%lu\n", gController->stButtons.iCLeft ); + fprintf( file, "CRight=%lu\n", gController->stButtons.iCRight ); + fprintf( file, "CUp=%lu\n", gController->stButtons.iCUp ); + fprintf( file, "DDown=%lu\n", gController->stButtons.iDDown ); + fprintf( file, "DLeft=%lu\n", gController->stButtons.iDLeft ); + fprintf( file, "DRight=%lu\n", gController->stButtons.iDRight ); + fprintf( file, "DUp=%lu\n", gController->stButtons.iDUp ); + fprintf( file, "L=%lu\n", gController->stButtons.iL ); + fprintf( file, "R=%lu\n", gController->stButtons.iR ); + fprintf( file, "Start=%lu\n", gController->stButtons.iStart ); + fprintf( file, "Z=%lu\n", gController->stButtons.iZ ); + fprintf( file, "XAxis=%lu\n", gController->stButtons.iXAxis ); + fprintf( file, "YAxis=%lu\n", gController->stButtons.iYAxis ); + fprintf( file, "LeftTrigger=%lu\n", gController->stAnalogs.iLeftTrigger ); + fprintf( file, "RightTrigger=%lu\n", gController->stAnalogs.iRightTrigger ); + fprintf( file, "LeftXAxis=%lu\n", gController->stAnalogs.iLXAxis ); + fprintf( file, "LeftYAxis=%lu\n", gController->stAnalogs.iLYAxis ); + fprintf( file, "RightXAxis=%lu\n", gController->stAnalogs.iRXAxis ); + fprintf( file, "RightYAxis=%lu\n\n", gController->stAnalogs.iRYAxis ); } void LoadXInputConfigFromFile( FILE *file, LPXCONTROLLER gController ) { - char buffer[4096]; - int c = 0; + char buffer[4096]; + int c = 0; - while( fgets( buffer, 4096, file )) - { - if( strlen( buffer ) == 1 ) // means end of controller config - break; - c++; - switch( buffer[0] ) - { - case 'A': - sscanf(buffer, "A=%lu", &gController->stButtons.iA); break; - case 'B': - sscanf(buffer, "B=%lu", &gController->stButtons.iB); break; - case 'C': - switch( buffer[1] ) - { - case 'U': - sscanf(buffer, "CUp=%lu", &gController->stButtons.iCUp); break; - case 'D': - sscanf(buffer, "CDown=%lu", &gController->stButtons.iCDown); break; - case 'L': - sscanf(buffer, "CLeft=%lu", &gController->stButtons.iCLeft); break; - case 'R': - sscanf(buffer, "CRight=%lu", &gController->stButtons.iCRight); break; - } - break; - case 'D': - switch( buffer[1] ) - { - case 'U': - sscanf(buffer, "DUp=%lu", &gController->stButtons.iDUp); break; - case 'D': - sscanf(buffer, "DDown=%lu", &gController->stButtons.iDDown); break; - case 'L': - sscanf(buffer, "DLeft=%lu", &gController->stButtons.iDLeft); break; - case 'R': - sscanf(buffer, "DRight=%lu", &gController->stButtons.iDRight); break; - } - break; - case 'L': - switch( buffer[1] ) - { - case '=': - sscanf(buffer, "L=%lu", &gController->stButtons.iL); break; - case 'e': - switch( buffer[4] ) - { - case 'T': - sscanf(buffer, "LeftTrigger=%lu", &gController->stAnalogs.iLeftTrigger); break; - case 'X': - sscanf(buffer, "LeftXAxis=%lu", &gController->stAnalogs.iLXAxis); break; - case 'Y': - sscanf(buffer, "LeftYAxis=%lu", &gController->stAnalogs.iLYAxis); break; - } - break; - } - break; - case 'R': - switch( buffer[1] ) - { - case '=': - sscanf(buffer, "R=%lu", &gController->stButtons.iR); break; - case 'i': - switch( buffer[5] ) - { - case 'T': - sscanf(buffer, "RightTrigger=%lu", &gController->stAnalogs.iRightTrigger); break; - case 'X': - sscanf(buffer, "RightXAxis=%lu", &gController->stAnalogs.iRXAxis); break; - case 'Y': - sscanf(buffer, "RightYAxis=%lu", &gController->stAnalogs.iRYAxis); break; - } - break; - } - break; - case 'Z': - sscanf(buffer, "Z=%lu", &gController->stButtons.iZ); break; - case 'S': - sscanf(buffer, "Start=%lu", &gController->stButtons.iStart); break; - case 'X': - sscanf(buffer, "XAxis=%lu", &gController->stButtons.iXAxis); break; - case 'Y': - sscanf(buffer, "YAxis=%lu", &gController->stButtons.iYAxis); break; - } - } + while( fgets( buffer, 4096, file )) + { + if( strlen( buffer ) == 1 ) // means end of controller config + break; + c++; + switch( buffer[0] ) + { + case 'A': + sscanf(buffer, "A=%lu", &gController->stButtons.iA); break; + case 'B': + sscanf(buffer, "B=%lu", &gController->stButtons.iB); break; + case 'C': + switch( buffer[1] ) + { + case 'U': + sscanf(buffer, "CUp=%lu", &gController->stButtons.iCUp); break; + case 'D': + sscanf(buffer, "CDown=%lu", &gController->stButtons.iCDown); break; + case 'L': + sscanf(buffer, "CLeft=%lu", &gController->stButtons.iCLeft); break; + case 'R': + sscanf(buffer, "CRight=%lu", &gController->stButtons.iCRight); break; + } + break; + case 'D': + switch( buffer[1] ) + { + case 'U': + sscanf(buffer, "DUp=%lu", &gController->stButtons.iDUp); break; + case 'D': + sscanf(buffer, "DDown=%lu", &gController->stButtons.iDDown); break; + case 'L': + sscanf(buffer, "DLeft=%lu", &gController->stButtons.iDLeft); break; + case 'R': + sscanf(buffer, "DRight=%lu", &gController->stButtons.iDRight); break; + } + break; + case 'L': + switch( buffer[1] ) + { + case '=': + sscanf(buffer, "L=%lu", &gController->stButtons.iL); break; + case 'e': + switch( buffer[4] ) + { + case 'T': + sscanf(buffer, "LeftTrigger=%lu", &gController->stAnalogs.iLeftTrigger); break; + case 'X': + sscanf(buffer, "LeftXAxis=%lu", &gController->stAnalogs.iLXAxis); break; + case 'Y': + sscanf(buffer, "LeftYAxis=%lu", &gController->stAnalogs.iLYAxis); break; + } + break; + } + break; + case 'R': + switch( buffer[1] ) + { + case '=': + sscanf(buffer, "R=%lu", &gController->stButtons.iR); break; + case 'i': + switch( buffer[5] ) + { + case 'T': + sscanf(buffer, "RightTrigger=%lu", &gController->stAnalogs.iRightTrigger); break; + case 'X': + sscanf(buffer, "RightXAxis=%lu", &gController->stAnalogs.iRXAxis); break; + case 'Y': + sscanf(buffer, "RightYAxis=%lu", &gController->stAnalogs.iRYAxis); break; + } + break; + } + break; + case 'Z': + sscanf(buffer, "Z=%lu", &gController->stButtons.iZ); break; + case 'S': + sscanf(buffer, "Start=%lu", &gController->stButtons.iStart); break; + case 'X': + sscanf(buffer, "XAxis=%lu", &gController->stButtons.iXAxis); break; + case 'Y': + sscanf(buffer, "YAxis=%lu", &gController->stButtons.iYAxis); break; + } + } - gController->bConfigured = c > 20 ; + gController->bConfigured = c > 20 ; } diff --git a/Source/nragev20/XInputController.h b/Source/nragev20/XInputController.h index 8b37af2b0..940a95773 100644 --- a/Source/nragev20/XInputController.h +++ b/Source/nragev20/XInputController.h @@ -1,14 +1,14 @@ /* - XInput Controller support for N-Rage`s Dinput8 Plugin + XInput Controller support for N-Rage`s Dinput8 Plugin (C) 2002, 2006 Norbert Wladyka - N-Rage`s Dinput8 Plugin - (C) 2009 Daniel Rehren - XInput Controller support + (C) 2009 Daniel Rehren - XInput Controller support - N-Rage`s Dinput8 Plugin: - Author`s Email: norbert.wladyka@chello.at - Website: http://go.to/nrage + N-Rage`s Dinput8 Plugin: + Author`s Email: norbert.wladyka@chello.at + Website: http://go.to/nrage - XInput Controller support: - Author's Email: rehren_007@hotmail.com + XInput Controller support: + Author's Email: rehren_007@hotmail.com This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -33,7 +33,7 @@ /* fixes undefined FILE, etc. type errors in MSVC 2010 build -- cxd4 */ #include -#ifndef SAFE_RELEASE // when Windows Media Device M? is not present +#ifndef SAFE_RELEASE // when Windows Media Device M? is not present #define SAFE_RELEASE(x) \ if(x != NULL) \ { \ @@ -43,18 +43,18 @@ #endif //----------------------------------------------------------------------------- -// Enum each PNP device using WMI and check each device ID to see if it contains +// Enum each PNP device using WMI and check each device ID to see if it contains // "IG_" (ex. "VID_045E&PID_028E&IG_00"). If it does, then it's an XInput device -// Unfortunately this information can not be found by just using DirectInput +// Unfortunately this information can not be found by just using DirectInput //----------------------------------------------------------------------------- BOOL IsXInputDevice( const GUID* pGuidProductFromDirectInput ); //END conde from ... /* - Xinput header for NRage Plugin, by tecnicors. + Xinput header for NRage Plugin, by tecnicors. - XInput Controller is going to take over the N64 control that matches its - number, ie. first XInput controller is first N64 player, etc. + XInput Controller is going to take over the N64 control that matches its + number, ie. first XInput controller is first N64 player, etc. */ #include "commonIncludes.h" @@ -68,34 +68,34 @@ BOOL IsXInputDevice( const GUID* pGuidProductFromDirectInput ); //enums namespace N64_BUTTONS { - // Whith this we can asign buttons to the xinput struct - enum _N64_BUTTONS { A = 0x0080, B = 0x0040, Z = 0x0020, R = 0x1000, L = 0x2000, XAxis = 0x4000, - Start = 0x0010, DUp = 0x0008, DDown = 0x0004, DLeft = 0x0002, YAxis = 0x8000, - DRight = 0x0001, CUp = 0x0800, CDown = 0x0400, CLeft = 0x0200, CRight = 0x0100, - None = 0x0 }; + // Whith this we can asign buttons to the xinput struct + enum _N64_BUTTONS { A = 0x0080, B = 0x0040, Z = 0x0020, R = 0x1000, L = 0x2000, XAxis = 0x4000, + Start = 0x0010, DUp = 0x0008, DDown = 0x0004, DLeft = 0x0002, YAxis = 0x8000, + DRight = 0x0001, CUp = 0x0800, CDown = 0x0400, CLeft = 0x0200, CRight = 0x0100, + None = 0x0 }; } //structures -typedef struct _XCONTROLLER // XInput controller struct +typedef struct _XCONTROLLER // XInput controller struct { - int nControl; - bool bConfigured; + int nControl; + bool bConfigured; - struct _N64_BUTTONS // For button configurations - { - int iA, iB; - int iStart; - int iL, iR, iZ; - int iXAxis, iYAxis; - int iDUp, iDDown, iDLeft, iDRight; - int iCUp, iCDown, iCLeft, iCRight; - }stButtons; + struct _N64_BUTTONS // For button configurations + { + int iA, iB; + int iStart; + int iL, iR, iZ; + int iXAxis, iYAxis; + int iDUp, iDDown, iDLeft, iDRight; + int iCUp, iCDown, iCLeft, iCRight; + }stButtons; - struct _XINPUT_ANALOGS // For analog configurations - { - int iLeftTrigger, iRightTrigger; - unsigned int iRXAxis, iRYAxis, iLXAxis, iLYAxis; - }stAnalogs; + struct _XINPUT_ANALOGS // For analog configurations + { + int iLeftTrigger, iRightTrigger; + unsigned int iRXAxis, iRYAxis, iLXAxis, iLYAxis; + }stAnalogs; }XCONTROLLER; @@ -132,32 +132,32 @@ void StoreXInputControllerKeys( HWND hDlg, LPXCONTROLLER gController ); // Fills N64 button comobox with its buttons. inline void FillN64ButtonComboBox( HWND hDlg, int ComboBox ) { - SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "None" )); - SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "A" )); - SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "B" )); - SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "Z" )); - SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "L" )); - SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "R" )); - SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "Start" )); - SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "C-Up" )); - SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "C-Left" )); - SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "C-Down" )); - SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "C-Right" )); - SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "D-Up" )); - SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "D-Left" )); - SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "D-Down" )); - SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "D-Right" )); - SendDlgItemMessage( hDlg, ComboBox, CB_SETCURSEL, 0, ( LPARAM )0 ); + SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "None" )); + SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "A" )); + SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "B" )); + SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "Z" )); + SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "L" )); + SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "R" )); + SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "Start" )); + SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "C-Up" )); + SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "C-Left" )); + SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "C-Down" )); + SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "C-Right" )); + SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "D-Up" )); + SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "D-Left" )); + SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "D-Down" )); + SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "D-Right" )); + SendDlgItemMessage( hDlg, ComboBox, CB_SETCURSEL, 0, ( LPARAM )0 ); } inline void FillN64AnalogComboBox( HWND hDlg, int ComboBox ) { - SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "None" )); - SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "DPad" )); - SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "C Buttons" )); - if( ComboBox != IDC_XC_DPAD ) - SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "Analog Stick" )); - SendDlgItemMessage( hDlg, ComboBox, CB_SETCURSEL, 0, ( LPARAM )0); + SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "None" )); + SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "DPad" )); + SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "C Buttons" )); + if( ComboBox != IDC_XC_DPAD ) + SendDlgItemMessage( hDlg, ComboBox, CB_ADDSTRING, 0, ( LPARAM )_T( "Analog Stick" )); + SendDlgItemMessage( hDlg, ComboBox, CB_SETCURSEL, 0, ( LPARAM )0); } // Save/Load Keys from own config file diff --git a/Source/nragev20/commonIncludes.h b/Source/nragev20/commonIncludes.h index e5bc55ab7..c61c99071 100644 --- a/Source/nragev20/commonIncludes.h +++ b/Source/nragev20/commonIncludes.h @@ -1,9 +1,9 @@ -/* - N-Rage`s Dinput8 Plugin +/* + N-Rage`s Dinput8 Plugin (C) 2002, 2006 Norbert Wladyka - Author`s Email: norbert.wladyka@chello.at - Website: http://go.to/nrage + Author`s Email: norbert.wladyka@chello.at + Website: http://go.to/nrage This program is free software; you can redistribute it and/or modify @@ -40,7 +40,7 @@ #define P_malloc( size ) HeapAlloc( g_hHeap, 0, size ) #define P_free( memory ) HeapFree( g_hHeap, 0, memory ) #define P_realloc( memory, size ) \ - ( (memory == NULL) ? P_malloc(size) : HeapReAlloc( g_hHeap, 0, memory, size ) ) + ( (memory == NULL) ? P_malloc(size) : HeapReAlloc( g_hHeap, 0, memory, size ) ) #ifdef ARRAYSIZE #undef ARRAYSIZE diff --git a/Source/nragev20/resource.h b/Source/nragev20/resource.h index 17b102157..ddded5f69 100644 --- a/Source/nragev20/resource.h +++ b/Source/nragev20/resource.h @@ -2,7 +2,7 @@ // Microsoft Visual C++ generated include file. // Used by NRagePluginV2.rc // -#define IDC_STATIC -1 +#define IDC_STATIC -1 #define IDC_STOREINDB 3 #define IDC_ERASEFROMDB 4 #define IDC_SAVEPROFILE 5 @@ -365,7 +365,7 @@ #define IDC_BACKGROUNDINPUT 1197 // Next default values for new objects -// +// #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 149 diff --git a/Source/nragev20/settings.h b/Source/nragev20/settings.h index 3711ab696..a1065de2b 100644 --- a/Source/nragev20/settings.h +++ b/Source/nragev20/settings.h @@ -1,9 +1,9 @@ -/* - N-Rage`s Dinput8 Plugin +/* + N-Rage`s Dinput8 Plugin (C) 2002, 2006 Norbert Wladyka - Author`s Email: norbert.wladyka@chello.at - Website: http://go.to/nrage + Author`s Email: norbert.wladyka@chello.at + Website: http://go.to/nrage This program is free software; you can redistribute it and/or modify @@ -44,31 +44,31 @@ #endif // #ifdef __GNUC__ - // Our default buffer size for TCHAR arrays (resources get loaded through here) - // MAKE SURE localized resources do not exceed this limit, or they will be cut off. -#define DEFAULT_BUFFER 256 + // Our default buffer size for TCHAR arrays (resources get loaded through here) + // MAKE SURE localized resources do not exceed this limit, or they will be cut off. +#define DEFAULT_BUFFER 256 - // use default settings for Release and Debugbuild + // use default settings for Release and Debugbuild #define STDCONFIG #ifndef STDCONFIG // ---------------------------------------------------------------------------- // custom (nonstandard) settings here - // workaround for a Adaptoiddriver bug; - // basically if the Adaptoid USB driver doesn't respond that there's a pak, say there is one anyway + // workaround for a Adaptoiddriver bug; + // basically if the Adaptoid USB driver doesn't respond that there's a pak, say there is one anyway #define ADAPTOIDPAK_RUMBLEFIX - // remove unimplemented Elements of the GUI + // remove unimplemented Elements of the GUI // #define HIDEUNIMPLEMENTED - // check controllercommands for valid CRC + // check controllercommands for valid CRC // #define MAKEADRESSCRCCHECK - // display Button for writing Shortcuts binary + // display Button for writing Shortcuts binary // #define RAWPROFILEWRITE - // enable selection of Transferpak + // enable selection of Transferpak // #define V_TRANSFERPAK - // enable selection of VoicePak + // enable selection of VoicePak // #define V_VOICEPAK // ---------------------------------------------------------------------------- @@ -78,20 +78,20 @@ #ifdef _DEBUG // ---------------------------------------------------------------------------- // Standard Debug Settings - // workaround for a Adaptoiddriver bug + // workaround for a Adaptoiddriver bug #define ADAPTOIDPAK_RUMBLEFIX - // remove unimplemented Elements of the GUI + // remove unimplemented Elements of the GUI // #define HIDEUNIMPLEMENTED - // check controllercommands for valid CRC + // check controllercommands for valid CRC #define MAKEADRESSCRCCHECK - // display Button for writing Shortcuts binary + // display Button for writing Shortcuts binary #define RAWPROFILEWRITE - // enable selection of Transferpak + // enable selection of Transferpak #define V_TRANSFERPAK - // enable selection of VoicePak + // enable selection of VoicePak #define V_VOICEPAK // spits out loads of extra info for ControllerCommand and ReadController @@ -102,20 +102,20 @@ #else // ---------------------------------------------------------------------------- // Standard Release Settings - // workaround for a Adaptoiddriver bug + // workaround for a Adaptoiddriver bug #define ADAPTOIDPAK_RUMBLEFIX - // remove unimplemented Elements of the GUI + // remove unimplemented Elements of the GUI #define HIDEUNIMPLEMENTED - // check controllercommands for valid CRC + // check controllercommands for valid CRC // #define MAKEADRESSCRCCHECK - // display Button for writing Shortcuts binary + // display Button for writing Shortcuts binary // #define RAWPROFILEWRITE - // enable selection of Transferpak + // enable selection of Transferpak #define V_TRANSFERPAK - // enable selection of VoicePak + // enable selection of VoicePak // #define V_VOICEPAK // ---------------------------------------------------------------------------- From d5caf89dfc258b0de6729c1d474d065643a48b03 Mon Sep 17 00:00:00 2001 From: oddMLan Date: Sun, 9 Feb 2020 04:43:37 -0700 Subject: [PATCH 3/3] [Nrage-input] Create Makefile, delete Script/MinGW/nrage.cmd - Created a Makefile to work under MSYS2; requires the w32api package installed through MSYS2's pacman. The old script isn't needed anymore. Thanks to DKO for the patch. --- Source/Script/MinGW/nrage.cmd | 71 ----------------------------------- Source/nragev20/Makefile | 66 ++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 71 deletions(-) delete mode 100644 Source/Script/MinGW/nrage.cmd create mode 100644 Source/nragev20/Makefile diff --git a/Source/Script/MinGW/nrage.cmd b/Source/Script/MinGW/nrage.cmd deleted file mode 100644 index da25f15d6..000000000 --- a/Source/Script/MinGW/nrage.cmd +++ /dev/null @@ -1,71 +0,0 @@ -@ECHO OFF -TITLE MinGW Compiler Suite Invocation - -set src=%CD%\..\..\nragev20 -set obj=%CD%\N-Rage - -if not exist %obj% ( -mkdir %obj% -) - - set MinGW=C:\MinGW -REM set MinGW=C:\msys64\mingw64\x86_64-w64-mingw32\.. - -set FLAGS_x86=^ - -I%src%\..\3rdParty\directx\include^ - -Wno-write-strings^ - -S^ - -masm=intel^ - -march=native^ - -Os - -set C_FLAGS=%FLAGS_x86% - -cd %MinGW%\bin -set CC=%MinGW%\bin\g++.exe -set AS=%MinGW%\bin\as.exe - -ECHO Compiling N-Rage plugin sources... -%CC% -o %obj%\NRagePluginV2.asm %src%\NRagePluginV2.cpp %C_FLAGS% -%CC% -o %obj%\Interface.asm %src%\Interface.cpp %C_FLAGS% -%CC% -o %obj%\FileAccess.asm %src%\FileAccess.cpp %C_FLAGS% -%CC% -o %obj%\PakIO.asm %src%\PakIO.cpp %C_FLAGS% -%CC% -o %obj%\GBCart.asm %src%\GBCart.cpp %C_FLAGS% -%CC% -o %obj%\International.asm %src%\International.cpp %C_FLAGS% -%CC% -o %obj%\DirectInput.asm %src%\DirectInput.cpp %C_FLAGS% -%CC% -o %obj%\XInputController.asm %src%\XInputController.cpp %C_FLAGS% - -ECHO Assembling N-Rage sources... -%AS% -o %obj%\NRagePluginV2.o %obj%\NRagePluginV2.asm -%AS% -o %obj%\Interface.o %obj%\Interface.asm -%AS% -o %obj%\FileAccess.o %obj%\FileAccess.asm -%AS% -o %obj%\PakIO.o %obj%\PakIO.asm -%AS% -o %obj%\GBCart.o %obj%\GBCart.asm -%AS% -o %obj%\International.o %obj%\International.asm -%AS% -o %obj%\DirectInput.o %obj%\DirectInput.asm -%AS% -o %obj%\XInputController.o %obj%\XInputController.asm -ECHO. - -set OBJ_LIST=^ - %obj%\XInputController.o^ - %obj%\DirectInput.o^ - %obj%\International.o^ - %obj%\GBCart.o^ - %obj%\PakIO.o^ - %obj%\FileAccess.o^ - %obj%\Interface.o^ - %obj%\NRagePluginV2.o^ - -ldinput8^ - -loleaut32^ - -lole32^ - -luuid^ - -lcomctl32^ - -mwindows^ - -lcomdlg32^ - -lgdi32^ - %obj%\NRagePluginV2.res - -ECHO Linking N-Rage objects... -%MinGW%\bin\windres.exe -o %obj%\NRagePluginV2.res -i %src%\NRagePluginV2.rc -O coff -%MinGW%\bin\g++.exe -o %obj%\PJ64_NRage.dll %OBJ_LIST% -shared -shared-libgcc -PAUSE diff --git a/Source/nragev20/Makefile b/Source/nragev20/Makefile new file mode 100644 index 000000000..aae16ecbc --- /dev/null +++ b/Source/nragev20/Makefile @@ -0,0 +1,66 @@ +CXX := g++ +LD := g++ +WINDRES := windres + +OBJECTS := \ + Debug.o \ + DirectInput.o \ + FileAccess.o \ + GBCart.o \ + Interface.o \ + International.o \ + NRagePluginV2.o \ + PakIO.o \ + XInputController.o + +RESOURCE := NRagePluginV2.res + +TARGET := PJ64_NRage.dll + +CPPFLAGS := \ + -DNOMINMAX + +CXXFLAGS := \ + -shared \ + -fPIC \ + -Os \ + -Wno-write-strings + +LIBS := \ + -lcomctl32 \ + -lcomdlg32 \ + -ldinput8 \ + -lgdi32 \ + -lole32 \ + -loleaut32 \ + -luuid \ + -static -lwinpthread + +LDFLAGS := \ + -mwindows \ + -static-libgcc \ + -static-libstdc++ + +DEPFILES := $(addprefix .deps/,$(OBJECTS:.o=.d)) + +.PHONY: all clean + +all: .deps $(TARGET) + +-include $(DEPFILES) + +clean: + rm -f $(TARGET) $(OBJECTS) $(RESOURCE) $(DEPFILES) + rm -rf .deps + +.deps: + mkdir -p $@ + +%.res: %.rc + $(WINDRES) -O coff -o $@ -i $< + +%.o: %.cpp + $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -MP -MF .deps/$(@:.o=.d) -o $@ -c $< + +$(TARGET): $(OBJECTS) $(RESOURCE) + $(LD) $(CXXFLAGS) $(LDFLAGS) $^ $(LIBS) -o $@