From 354f23cf3f568b147fb5a480dcc9467f7a866216 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sun, 5 Jan 2020 03:48:02 +0000 Subject: [PATCH 1/3] 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. --- src/Input.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Input.cpp b/src/Input.cpp index c5911123..605ad4f9 100644 --- a/src/Input.cpp +++ b/src/Input.cpp @@ -121,7 +121,7 @@ BOOL __stdcall EnumDevices_Callback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef) } 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 @@ BOOL __stdcall EnumDevices_Callback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef) 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 @@ BOOL __stdcall EnumDevices_Callback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef) 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 @@ BOOL GetJoystickStatus(JOYSTICK_STATUS *status) 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 @@ BOOL ResetJoystickStatus(void) if (joystick == NULL) return FALSE; - if (joystick->Poll()) + if (joystick->Poll() != DI_OK) return FALSE; HRESULT res = joystick->GetDeviceState(sizeof(DIJOYSTATE), &joystate); From 38484613d5ade3ff4302db348dda8cc0f8faaf48 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sun, 5 Jan 2020 04:44:32 +0000 Subject: [PATCH 2/3] Better GUID-printing bugfix %hhx is a C99 thing, apparently. --- src/Input.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Input.cpp b/src/Input.cpp index 605ad4f9..f1e73db3 100644 --- a/src/Input.cpp +++ b/src/Input.cpp @@ -146,7 +146,7 @@ BOOL __stdcall EnumDevices_Callback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef) char string[0x100]; #ifdef FIX_BUGS - 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]); + sprintf(string, "DeviceGUID = %08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X\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", lpddi->guidInstance); // Tries to print a struct as an int #endif From f36fc61de3dada74f5f5861db9a1c5addcc8242f Mon Sep 17 00:00:00 2001 From: Clownacy Date: Mon, 6 Jan 2020 15:52:07 +0000 Subject: [PATCH 3/3] Made Input.cpp more ASM-accurate There was one ASM-inaccuracy I missed last time, but now I've also made the file's memory layout accurate (it appears that global variable initialisation actually affects the order they reside in memory). --- src/Input.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Input.cpp b/src/Input.cpp index f1e73db3..9f8b9d87 100644 --- a/src/Input.cpp +++ b/src/Input.cpp @@ -19,11 +19,11 @@ typedef struct DirectInputPair LPDIRECTINPUTDEVICE2A device; } DirectInputPair; -static LPDIRECTINPUTDEVICE2A joystick; -static LPDIRECTINPUTA lpDI; - -static int joystick_neutral_x; -static int joystick_neutral_y; +// The original names for these variables are unknown +static LPDIRECTINPUTA lpDI = NULL; +static LPDIRECTINPUTDEVICE2A joystick = NULL; +static int joystick_neutral_x = 0; +static int joystick_neutral_y = 0; void ReleaseDirectInput(void) { @@ -40,7 +40,7 @@ void ReleaseDirectInput(void) } } -// The original name for this function is unknown +// The original name for this function and its variables are unknown BOOL SetDeviceAquire(BOOL aquire) { if (aquire == TRUE) @@ -57,6 +57,7 @@ BOOL SetDeviceAquire(BOOL aquire) return TRUE; } +// It looks like Pixel declared his functions early, so he could forward-reference BOOL HookAllDirectInputDevices(HWND hWnd); BOOL __stdcall EnumDevices_Callback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef); @@ -75,7 +76,7 @@ BOOL InitDirectInput(HINSTANCE hinst, HWND hWnd) return TRUE; } -// The original name for this function is unknown +// The original name for this function and its variables are unknown BOOL HookAllDirectInputDevices(HWND hWnd) { DirectInputPair directinput_objects; @@ -83,7 +84,8 @@ BOOL HookAllDirectInputDevices(HWND hWnd) directinput_objects.device = NULL; directinput_objects.lpDI = lpDI; - lpDI->AddRef(); + directinput_objects.lpDI->AddRef(); + lpDI->EnumDevices(DIDEVTYPE_JOYSTICK, EnumDevices_Callback, &directinput_objects, DIEDFL_ATTACHEDONLY); if (directinput_objects.lpDI != NULL) @@ -108,7 +110,7 @@ BOOL HookAllDirectInputDevices(HWND hWnd) return TRUE; } -// The original name for this function is unknown +// The original name for this function and its variables are unknown BOOL __stdcall EnumDevices_Callback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef) { static int already_ran;