diff --git a/ThDxHook/MyMmsystem.cpp b/ThDxHook/MyMmsystem.cpp index 6d6c003..4a29b52 100755 --- a/ThDxHook/MyMmsystem.cpp +++ b/ThDxHook/MyMmsystem.cpp @@ -11,6 +11,9 @@ #define Y_MID 32767 #define Y_MAX 65535 +#define VK_X 0x58 +#define VK_C 0x43 + enum { WinmmFN_joyGetDevCapsA = 0, WinmmFN_joyGetPosEx = 1, @@ -28,7 +31,21 @@ SDLLHook WinmmHook = { } }; +enum { + User32FN_GetKeyboardState = 0, +}; + +SDLLHook User32Hook = { + "USER32.DLL", + false, NULL, // Default hook disabled, NULL function pointer. + { + {"GetKeyboardState", (DWORD*)MyGetKeyboardState}, + {NULL, NULL} + } +}; + typedef MMRESULT(WINAPI *joyGetPos_t)(UINT uJoyID, LPJOYINFO pji); +typedef BOOL(WINAPI * OriGetKeyboardState)(_Out_ PBYTE lpKeyState); MMRESULT WINAPI MyJoyGetPos(UINT uJoyID, LPJOYINFO pji) { joyGetPos_t old_func = (joyGetPos_t)WinmmHook.Functions[WinmmFN_joyGetPos].OrigFn; @@ -206,4 +223,76 @@ MMRESULT WINAPI MyJoyGetPosEx(__in UINT uJoyID, __out LPJOYINFOEX pji) { } return JOYERR_NOERROR; +} + +BOOL WINAPI MyGetKeyboardState(PBYTE lpKeyState) { + auto old_func = (OriGetKeyboardState)User32Hook.Functions[User32FN_GetKeyboardState].OrigFn; + auto rs = old_func(lpKeyState); + + if (keyBoard != TRUE && rs != 0) { + if (g_mouseDown) { + lpKeyState[VK_X] |= 0x80; + g_mouseDown = 0; + } + if (g_midMouseDown) { + lpKeyState[VK_C] |= 0x80; + g_midMouseDown = 0; + } + if (dxVersion != 8 ? g_working : g_working2) { + DWORD address = g_currentGameConfig.Posistion.Chain[0]; + if (offsetIsRelative == true) { + if (firstOffsetDirection == -1) address = baseOfCode - address; + else address += baseOfCode; + } + for (int i = 1; i < g_currentGameConfig.Posistion.Length; i++) { + address = *((DWORD*)address); + if (address == 0) { + break; + } + address += g_currentGameConfig.Posistion.Chain[i]; + } + if (address != 0) { + POINT playerPos, mousePos; + if (g_currentGameConfig.PosDataType == Int_DataType) { + IntPoint * pPosition = (IntPoint*)(address); + playerPos.x = + pPosition->X / g_currentGameConfig.PixelRate + g_currentGameConfig.PixelOffset.X; + playerPos.y = + pPosition->Y / g_currentGameConfig.PixelRate + g_currentGameConfig.PixelOffset.Y; + } else if (g_currentGameConfig.PosDataType == Float_DataType) { + FloatPoint * pPosition = (FloatPoint*)(address); + playerPos.x = + pPosition->X / g_currentGameConfig.PixelRate + g_currentGameConfig.PixelOffset.X; + playerPos.y = + pPosition->Y / g_currentGameConfig.PixelRate + g_currentGameConfig.PixelOffset.Y; + } else if (g_currentGameConfig.PosDataType == Short_DataType) { + ShortPoint * pPosition = (ShortPoint*)(address); + playerPos.x = + pPosition->X / g_currentGameConfig.PixelRate + g_currentGameConfig.PixelOffset.X; + playerPos.y = + pPosition->Y / g_currentGameConfig.PixelRate + g_currentGameConfig.PixelOffset.Y; + } + GetCursorPos(&mousePos); + if ((dxVersion != 8 ? windowed : windowed2) == TRUE) + ScreenToClient(dxVersion != 8 ? g_hFocusWindow : g_hFocusWindow2, &mousePos); + + auto shiftPressed = lpKeyState[VK_SHIFT] & 0x80; + shiftPressed = false; + if (shiftPressed ? playerPos.x < mousePos.x : playerPos.x < mousePos.x - 1) { + lpKeyState[VK_RIGHT] |= 0x80; + } else if (shiftPressed ? playerPos.x > mousePos.x : playerPos.x > mousePos.x + 1) { + lpKeyState[VK_LEFT] |= 0x80; + } + + if (shiftPressed ? playerPos.y < mousePos.y : playerPos.y < mousePos.y - 1) { + lpKeyState[VK_DOWN] |= 0x80; + } else if (shiftPressed ? playerPos.y > mousePos.y : playerPos.y > mousePos.y + 1) { + lpKeyState[VK_UP] |= 0x80; + } + + } + } + } + + return rs; } \ No newline at end of file diff --git a/ThDxHook/MyMmsystem.h b/ThDxHook/MyMmsystem.h index 0280b63..cd95372 100755 --- a/ThDxHook/MyMmsystem.h +++ b/ThDxHook/MyMmsystem.h @@ -15,10 +15,12 @@ MMRESULT WINAPI MyJoyGetPosEx( MMRESULT WINAPI MyJoyGetPos( UINT uJoyID, LPJOYINFO pji - ); +BOOL WINAPI MyGetKeyboardState(_Out_ PBYTE lpKeyState); + //MMRESULT WINAPI MyTimeBeginPeriod( __in UINT uPeriod); //MMRESULT WINAPI MyTimeEndPeriod( __in UINT uPeriod); //DWORD WINAPI MyTimeGetTime(void); extern SDLLHook WinmmHook; +extern SDLLHook User32Hook; \ No newline at end of file diff --git a/ThDxHook/dllmain.cpp b/ThDxHook/dllmain.cpp index 257ae14..a0d8dfc 100755 --- a/ThDxHook/dllmain.cpp +++ b/ThDxHook/dllmain.cpp @@ -16,10 +16,7 @@ HINSTANCE hinstance = NULL; static char buffer[256]; -BOOL APIENTRY DllMain(HMODULE hModule, - DWORD ul_reason_for_call, - LPVOID lpReserved -) { +BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { char dbBuff[128]; switch (ul_reason_for_call) { @@ -89,6 +86,9 @@ BOOL APIENTRY DllMain(HMODULE hModule, // hook JoyStick (ánh xạ input chuột lên DirectInput) HookAPICalls(&WinmmHook); + // hook GetKeyboardState + HookAPICalls(&User32Hook); + // hook Message Loop (đọc trạng thái của chuột) HookAPICalls(&PeekMessageAHook);