class CKeyHook
{
public:
CKeyHook()
{
memset(bKeyTable, false, sizeof(bKeyTable));
oWndProc = (tWndProc)(pSAMP->g_dwSAMP_Addr + 0x5DB40);
oCPad_UpdateGameKey = (tCPad_UpdateGameKey)0x541C40;
DetourRestoreAfterWith();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
pSecure->SDetourAttach(&(PVOID&)oWndProc, hkWndProc);
DetourTransactionCommit();
pSecure->HookInstallCall((DWORD)0x541E17, (DWORD)hkCPad_UpdateGameKey);
}
~CKeyHook()
{
memset(bKeyTable, false, sizeof(bKeyTable));
DetourRestoreAfterWith();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID&)oWndProc, hkWndProc);
DetourTransactionCommit();
Memory::memcpy_safe((void*)0x541E17, "\xE8\x24\xFE\xFF\xFF", 5);
}
bool bKeyTable[256];
struct stGameKeyState
{
int iState{ 0 };
bool bActive{ false };
} g_GameKeyState[32];
private:
typedef LRESULT(__stdcall* tWndProc)(HWND, UINT, WPARAM, LPARAM);
typedef BYTE(__thiscall* tCPad_UpdateGameKey)(CPad*, int);
static LRESULT __stdcall hkWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
static BYTE __stdcall hkCPad_UpdateGameKey(int iKey);
tWndProc oWndProc;
tCPad_UpdateGameKey oCPad_UpdateGameKey;
};
extern CKeyHook * pKeyHook;