From 513f1b8dfdec3285a9d039d5576737bfa1287d10 Mon Sep 17 00:00:00 2001 From: LunaticShiN3 <96666614+LunaticShiN3@users.noreply.github.com> Date: Sun, 26 Mar 2023 17:29:29 +0200 Subject: [PATCH] (Hopefully) fixed bug where stick inputs would stop working sometimes. Also reduced warnings. --- Luna's DirectInput8/directinput.c | 1 + Luna's DirectInput8/dllmain.c | 2 +- Luna's DirectInput8/gui.c | 13 +++++++------ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Luna's DirectInput8/directinput.c b/Luna's DirectInput8/directinput.c index eb1d56f..9b24080 100644 --- a/Luna's DirectInput8/directinput.c +++ b/Luna's DirectInput8/directinput.c @@ -102,6 +102,7 @@ void DInputGetKeys(HINSTANCE hinst, HWND hwnd) { if (lpdiKeyboard != NULL) { HRESULT result = IDirectInputDevice8_GetDeviceState(lpdiKeyboard, (sizeof(deviceState)), (LPVOID*)&deviceState); + deviceState[0] = 0; if (GetForegroundWindow() == hwnd) { if (result == DIERR_INPUTLOST) { diff --git a/Luna's DirectInput8/dllmain.c b/Luna's DirectInput8/dllmain.c index 516efeb..513f3b8 100644 --- a/Luna's DirectInput8/dllmain.c +++ b/Luna's DirectInput8/dllmain.c @@ -117,7 +117,7 @@ EXPORT void CALL GetKeys(int Control, BUTTONS* Keys) { } for (int i = 0; i < sizeof(config.modifiers) / sizeof(Modifier); i++) { - if (deviceState[config.modifiers[i].keybind] >> 7) { + if ((config.modifiers[i].keybind != 0) && (deviceState[config.modifiers[i].keybind] >> 7)) { Keys->Y_AXIS = (float)Keys->Y_AXIS * config.modifiers[i].multiplierX; //X and Y axis are swapped because of course they are???? Keys->X_AXIS = (float)Keys->X_AXIS * config.modifiers[i].multiplierY; } diff --git a/Luna's DirectInput8/gui.c b/Luna's DirectInput8/gui.c index a3fe275..8fcb6dc 100644 --- a/Luna's DirectInput8/gui.c +++ b/Luna's DirectInput8/gui.c @@ -235,10 +235,10 @@ void getEditBoxContent(HWND hwndDlg, int nIDDlgItem, byte* returnVariable) { char lpch[4]; hDlgItem = GetDlgItem(hwndDlg, nIDDlgItem); GetWindowTextA(hDlgItem, &lpch, sizeof(lpch)); - *returnVariable = atoi(lpch); - if (*returnVariable > 127) { - *returnVariable = 127; - setEditBoxContent(hwndDlg, nIDDlgItem, *returnVariable); + returnVariable = atoi(lpch); + if (returnVariable > 127) { + returnVariable = 127; + setEditBoxContent(hwndDlg, nIDDlgItem, returnVariable); } } @@ -257,6 +257,7 @@ void getConfigKey(HWND hwndDlg, int nIDDlgItem, byte* returnVariable) { int i, j; for (j = 0; j < 100; j++) { IDirectInputDevice8_GetDeviceState(lpdiKeyboard, (sizeof(deviceState)), (LPVOID*)&deviceState); + deviceState[0] = 0; for (i = 0; i < sizeof(deviceState); i++) { if (deviceState[i] >> 7) { *returnVariable = i; @@ -271,7 +272,7 @@ void getConfigKey(HWND hwndDlg, int nIDDlgItem, byte* returnVariable) { } } -void setButtonLabel(HWND hwndDlg, int nIDDlgItem, byte* returnVariable) { +void setButtonLabel(HWND hwndDlg, int nIDDlgItem, byte returnVariable) { dips.diph.dwSize = sizeof(dips); dips.diph.dwHeaderSize = sizeof(diph); dips.diph.dwHow = DIPH_BYOFFSET; @@ -282,7 +283,7 @@ void setButtonLabel(HWND hwndDlg, int nIDDlgItem, byte* returnVariable) { SetWindowTextW(hDlgItem, dips.wsz); } -void setEditBoxContent(HWND hwndDlg, int nIDDlgItem, byte* returnVariable) { +void setEditBoxContent(HWND hwndDlg, int nIDDlgItem, byte returnVariable) { char lpch[4]; hDlgItem = GetDlgItem(hwndDlg, nIDDlgItem); Edit_LimitText(hDlgItem, 3);