Skip to content

Commit

Permalink
NFS Porsche: Clear the keyboard input buffer on WM_KILLFOCUS
Browse files Browse the repository at this point in the history
  • Loading branch information
CookiePLMonster committed Sep 22, 2023
1 parent 268e865 commit 8937487
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions source/SilentPatchNFS90s.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,9 @@ namespace TextPasteSupport
return orgWndProc(hWnd, Msg, wParam, lParam);
}

// Used only by NFS Porsche
static bool* gKeyboardBuffer;

LRESULT WINAPI WindowProc_PasteSupport(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
if (Msg == WM_CHAR)
Expand All @@ -383,6 +386,11 @@ namespace TextPasteSupport
return 0;
}
}
// NFS Porsche only
else if (Msg == WM_KILLFOCUS && gKeyboardBuffer != nullptr)
{
memset(gKeyboardBuffer, 0, 128);
}
return orgWndProc(hWnd, Msg, wParam, lParam);
}

Expand Down Expand Up @@ -813,6 +821,16 @@ void OnInitializeHook()
auto register_class = get_pattern<decltype(RegisterClassA)**>("89 44 24 50 FF 15 ? ? ? ? 66 85 C0", 4 + 2);

pOrgRegisterClassA = std::exchange(*register_class, &pRegisterClassA_PasteSupport);

// NFS Porsche: Clear the keyboard input buffer on WM_KILLFOCUS
// Fixes an issue potentially introduced by Modern Patch where the keyboard buffer doesn't get cleared on Alt+Tab
try
{
auto keyboard_buffer = *get_pattern<bool*>("68 ? ? ? ? E8 ? ? ? ? 8B 54 24 28 8B 44 24 20", 1);

gKeyboardBuffer = keyboard_buffer;
}
TXN_CATCH();
}
TXN_CATCH();

Expand Down

0 comments on commit 8937487

Please sign in to comment.