This commit is contained in:
zilmar 2015-02-25 08:44:49 +11:00
commit 3fac386d55
4 changed files with 53 additions and 9 deletions

View File

@ -44,6 +44,7 @@ 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
@ -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 )
{
g_bConfiguring = true;
@ -324,6 +334,15 @@ EXPORT void CALL InitiateControllers (CONTROL_INFO * ControlInfo)
return;
}
if (g_hXInputDLL == NULL)
{
if (!InitXinput())
{
//TODO Disable ability to set XInput
//TODO Make XInput and DirectInput settings same page
}
}
int iDevice;
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?
FreeDirectInput();
FreeXinput();
return;
}

View File

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

View File

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

View File

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