Merge pull request #137 from death-droid/NRageChanges

Change XInput to be loaded into memory at startup rather than every time...
This commit is contained in:
zilmar 2015-02-25 04:51:52 +11:00
commit 663c011bee
4 changed files with 53 additions and 9 deletions

View File

@ -44,6 +44,7 @@ DWORD WINAPI DelayedShortcut(LPVOID lpParam);
// Global Variables // // Global Variables //
HMODULE g_hDirectInputDLL = NULL; // Handle to DirectInput8 library 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 HMODULE g_hResourceDLL = NULL; // Handle to resource library; used by LoadString for internationalization
HANDLE g_hHeap = NULL; // Handle to our heap HANDLE g_hHeap = NULL; // Handle to our heap
int g_nDevices = 0; // number of devices in g_devList int g_nDevices = 0; // number of devices in g_devList
@ -215,6 +216,15 @@ EXPORT void CALL DllConfig ( HWND hParent )
} }
} }
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 ) if( g_pDIHandle && !g_bConfiguring )
{ {
g_bConfiguring = true; g_bConfiguring = true;
@ -324,6 +334,15 @@ EXPORT void CALL InitiateControllers (CONTROL_INFO * ControlInfo)
return; return;
} }
if (g_hXInputDLL == NULL)
{
if (!InitXinput())
{
//TODO Disable ability to set XInput
//TODO Make XInput and DirectInput settings same page
}
}
int iDevice; int iDevice;
EnterCriticalSection( &g_critical ); EnterCriticalSection( &g_critical );
@ -761,7 +780,7 @@ EXPORT void CALL CloseDLL (void)
// ZeroMemory( g_pcControllers, sizeof(g_pcControllers) ); // why zero the memory if we're just going to close down? // ZeroMemory( g_pcControllers, sizeof(g_pcControllers) ); // why zero the memory if we're just going to close down?
FreeDirectInput(); FreeDirectInput();
FreeXinput();
return; return;
} }

View File

@ -362,6 +362,7 @@ typedef struct _MSHORTCUT {
extern HANDLE g_hHeap; extern HANDLE g_hHeap;
extern HMODULE g_hDirectInputDLL; extern HMODULE g_hDirectInputDLL;
extern HMODULE g_hXInputDLL;
extern HMODULE g_hResourceDLL; extern HMODULE g_hResourceDLL;
extern EMULATOR_INFO g_strEmuInfo; extern EMULATOR_INFO g_strEmuInfo;
extern TCHAR g_aszDefFolders[3][MAX_PATH]; extern TCHAR g_aszDefFolders[3][MAX_PATH];

View File

@ -306,20 +306,40 @@ void VibrateXInputController( DWORD nController, int LeftMotorVal, int RightMoto
fnXInputSetState(nController, &vibration); fnXInputSetState(nController, &vibration);
} }
bool InitiateXInputController( LPXCONTROLLER gController, int nControl ) bool InitXinput()
{ {
HMODULE hInput = LoadLibrary("Xinput1_4.dll"); //Lets dynamically load in the XInput library
if (hInput == NULL) if (g_hXInputDLL == NULL)
g_hXInputDLL = LoadLibrary("Xinput1_4.dll");
if (g_hXInputDLL == NULL)
{ {
hInput = LoadLibrary("Xinput9_1_0.dll"); //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 (hInput == NULL) if (g_hXInputDLL == NULL)
{ {
return false; return false;
} }
fnXInputSetState = (DWORD(WINAPI *) (DWORD, XINPUT_VIBRATION*))GetProcAddress(hInput, "XInputSetState"); //Prepare the functions where going to use, nice and simple for XInput
fnXInputGetState = (DWORD(WINAPI *) (DWORD, XINPUT_STATE*))GetProcAddress(hInput, "XInputGetState"); 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;
}
}
bool InitiateXInputController( LPXCONTROLLER gController, int nControl )
{
if (fnXInputGetState == NULL || fnXInputSetState == NULL) if (fnXInputGetState == NULL || fnXInputSetState == NULL)
{ {
return false; return false;

View File

@ -105,6 +105,10 @@ typedef struct _XCONTROLLER // XInput controller struct
typedef XCONTROLLER *LPXCONTROLLER; typedef XCONTROLLER *LPXCONTROLLER;
//Initiates XInput library
bool InitXinput();
//Free the Xinput library
void FreeXinput();
// Sets the keys pressed for Xinput controller gController, into keys. // Sets the keys pressed for Xinput controller gController, into keys.
void GetXInputControllerKeys( const int indexController, LPDWORD Keys ); void GetXInputControllerKeys( const int indexController, LPDWORD Keys );
// Sets the default keys for Xinput controller gController. // Sets the default keys for Xinput controller gController.