Skip to content

Commit

Permalink
Fixed bug that prevented the plugin from loading the saved config and…
Browse files Browse the repository at this point in the history
… "other app has priority" error on acquiring keyboard.
  • Loading branch information
LunaticShiN3 committed Mar 26, 2023
1 parent b823eb3 commit dcbe5a5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Luna's DirectInput8/Luna's DirectInput8.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<CharacterSet>NotSet</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down Expand Up @@ -79,7 +79,7 @@
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalDependencies>dinput8.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>dinput8.lib;dxguid.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
Expand Down
5 changes: 3 additions & 2 deletions Luna's DirectInput8/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ void loadConfig(void) {
fclose(cptr);
}

if (config.configVersion != 0x0100);
restoreDefaults();
if (config.configVersion != 0x0100) {
restoreDefaults();
}
}

void restoreDefaults(void) {
Expand Down
10 changes: 8 additions & 2 deletions Luna's DirectInput8/directinput.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ void DInputInit(HINSTANCE hinst, HWND hwnd) {
}
}

result= IDirectInputDevice8_Acquire(lpdiKeyboard); //Acquires input device
result = DIERR_OTHERAPPHASPRIO;
while (result == DIERR_OTHERAPPHASPRIO) {
result = IDirectInputDevice8_Acquire(lpdiKeyboard); //Acquires input device
}

if (fptr != 0) {
switch (result) {
Expand Down Expand Up @@ -102,7 +105,10 @@ void DInputGetKeys(HINSTANCE hinst, HWND hwnd) {

if (GetForegroundWindow() == hwnd) {
if (result == DIERR_INPUTLOST) {
result = IDirectInputDevice8_Acquire(lpdiKeyboard); //Re-acquires dinput device after lost focus.
result = DIERR_OTHERAPPHASPRIO;
while (result == DIERR_OTHERAPPHASPRIO) {
result = IDirectInputDevice8_Acquire(lpdiKeyboard); //Re-acquires dinput device after lost focus.
}
}
}
}
Expand Down
20 changes: 16 additions & 4 deletions Luna's DirectInput8/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ BOOL CALLBACK DlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam)
case WM_INITDIALOG:
IDirectInputDevice8_Unacquire(lpdiKeyboard);
HRESULT result = IDirectInputDevice8_SetCooperativeLevel(lpdiKeyboard, hwndDlg, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND);
result = IDirectInputDevice8_Acquire(lpdiKeyboard);
result = DIERR_OTHERAPPHASPRIO;
while (result == DIERR_OTHERAPPHASPRIO) {
result = IDirectInputDevice8_Acquire(lpdiKeyboard);
}

hDlgItem = GetDlgItem(hwndDlg, IDC_MODIFIERS);
memset(&LvColumn, 0, sizeof(LvColumn));
Expand Down Expand Up @@ -57,7 +60,10 @@ BOOL CALLBACK DlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam)
EndDialog(hwndDlg, 0);
IDirectInputDevice8_Unacquire(lpdiKeyboard);
IDirectInputDevice8_SetCooperativeLevel(lpdiKeyboard, parentVariable, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
IDirectInputDevice8_Acquire(lpdiKeyboard);
result = DIERR_OTHERAPPHASPRIO;
while (result == DIERR_OTHERAPPHASPRIO) {
result = IDirectInputDevice8_Acquire(lpdiKeyboard);
}
break;

case WM_NOTIFY:
Expand Down Expand Up @@ -105,14 +111,20 @@ BOOL CALLBACK DlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam)
EndDialog(hwndDlg, 0);
IDirectInputDevice8_Unacquire(lpdiKeyboard);
IDirectInputDevice8_SetCooperativeLevel(lpdiKeyboard, parentVariable, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
IDirectInputDevice8_Acquire(lpdiKeyboard);
result = DIERR_OTHERAPPHASPRIO;
while (result == DIERR_OTHERAPPHASPRIO) {
result = IDirectInputDevice8_Acquire(lpdiKeyboard);
}
break;
case IDOK:
saveConfig();
EndDialog(hwndDlg, 0);
IDirectInputDevice8_Unacquire(lpdiKeyboard);
HRESULT result = IDirectInputDevice8_SetCooperativeLevel(lpdiKeyboard, parentVariable, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
result = IDirectInputDevice8_Acquire(lpdiKeyboard);
result = DIERR_OTHERAPPHASPRIO;
while (result == DIERR_OTHERAPPHASPRIO) {
result = IDirectInputDevice8_Acquire(lpdiKeyboard); //Acquires input device
}
break;
case IDC_RESTOREDEFAULTS:
restoreDefaults();
Expand Down

0 comments on commit dcbe5a5

Please sign in to comment.