shithub: cstory

Download patch

ref: 354f23cf3f568b147fb5a480dcc9467f7a866216
parent: 9bfaeb5390579becb35a7a5b03610e7c958bd989
author: Clownacy <Clownacy@users.noreply.github.com>
date: Sat Jan 4 22:48:02 EST 2020

Improved accuracy of Input.cpp

Applied some missing constants/macros, and corrected an
ASM-inaccuracy.

I always wondered why the original code only passed the first member
of the GUID struct, but it turned out it didn't: it actually passed
the whole thing.

Also, it's starting to bother me how many ASM-inaccuracies have
sneaked-through. v2.0 was *meant* to have fixed all this already.

--- a/src/Input.cpp
+++ b/src/Input.cpp
@@ -121,7 +121,7 @@
 	}
 
 	static LPDIRECTINPUTDEVICEA device;
-	if (directinput_objects->lpDI->CreateDevice(lpddi->guidInstance, &device, NULL))
+	if (directinput_objects->lpDI->CreateDevice(lpddi->guidInstance, &device, NULL) != DI_OK)
 	{
 		directinput_objects->device = NULL;
 		return TRUE;
@@ -130,7 +130,7 @@
 	static LPDIRECTINPUTDEVICE2A _joystick;
 	HRESULT res = device->QueryInterface(IID_IDirectInputDevice2A, (LPVOID*)&_joystick);
 
-	if (res < 0)
+	if (FAILED(res))
 	{
 		joystick = NULL;
 		return TRUE;
@@ -146,9 +146,9 @@
 
 	char string[0x100];
 #ifdef FIX_BUGS
-	sprintf(string, "DeviceGUID = %lx\n", lpddi->guidInstance.Data1);
+	sprintf(string, "DeviceGUID = %lx-%hx-%hx-%hhx%hhx-%hhx%hhx%hhx%hhx%hhx%hhx\n", lpddi->guidInstance.Data1, lpddi->guidInstance.Data2, lpddi->guidInstance.Data3, lpddi->guidInstance.Data4[0], lpddi->guidInstance.Data4[1], lpddi->guidInstance.Data4[2], lpddi->guidInstance.Data4[3], lpddi->guidInstance.Data4[4], lpddi->guidInstance.Data4[5], lpddi->guidInstance.Data4[6], lpddi->guidInstance.Data4[7]);
 #else
-	sprintf(string, "DeviceGUID = %x\n", (unsigned int)lpddi->guidInstance.Data1);
+	sprintf(string, "DeviceGUID = %x\n", lpddi->guidInstance);	// Tries to print a struct as an int
 #endif
 	OutputDebugStringA(string);
 
@@ -162,7 +162,7 @@
 	if (joystick == NULL)
 		return FALSE;
 
-	if (joystick->Poll())
+	if (joystick->Poll() != DI_OK)
 		return FALSE;
 
 	HRESULT res = joystick->GetDeviceState(sizeof(DIJOYSTATE), &joystate);
@@ -207,7 +207,7 @@
 	if (joystick == NULL)
 		return FALSE;
 
-	if (joystick->Poll())
+	if (joystick->Poll() != DI_OK)
 		return FALSE;
 
 	HRESULT res = joystick->GetDeviceState(sizeof(DIJOYSTATE), &joystate);