 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
dayglo How do I cheat?
Reputation: 0
Joined: 28 Jul 2009 Posts: 6
|
Posted: Wed Jul 29, 2009 8:01 pm Post subject: postmessagea with detours hook not working |
|
|
Trying to get this to send a click to darkfall, not working
This is unmanaged c++ code:
| Code: |
// w32acgood.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "w32acgood.h"
#include <windows.h>
#pragma comment(lib, "Detours/detours.lib")
#include "Detours/detours.h"
// Function pointer type for PostMessageA in user32 DLL
typedef BOOL (__stdcall *PMAPtr) (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
PMAPtr pTargetPMA = NULL; // Target function pointer
PMAPtr pTrampolinePMA = NULL; // Trampoline function pointer
// This Detour function does nothing new. It just calls the trampoline function
BOOL WINAPI DetourPMA(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
return pTrampolinePMA(hWnd, Msg, wParam, lParam);
}
#define MAX_LOADSTRING 100
#define IDC_BUTTON_ONE 101
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_W32ACGOOD, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_W32ACGOOD));
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage are only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_W32ACGOOD));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_W32ACGOOD);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
return RegisterClassEx(&wcex);
}
//
// FUNCTION: InitInstance(HINSTANCE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // Store instance handle in our global variable
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
HINSTANCE huInst; // Instance of user32 DLL
HWND cHandle;
UINT scancode;
LPARAM lparam;
static HINSTANCE ghInstance = NULL;
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
HWND hButton;
switch (message)
{
case WM_CREATE:
// Load user32 DLL
huInst = LoadLibraryA("user32.dll");
// Get function pointer address of PostMessageA
pTargetPMA = (PMAPtr) GetProcAddress(huInst, "PostMessageA");
// Hook PostMessageA with the detour function DetourPMA
pTrampolinePMA = (PMAPtr) DetourFunction((PBYTE) pTargetPMA, (PBYTE) DetourPMA);
hButton = CreateWindowExA(NULL, "Button", "Click", WS_BORDER | WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 0, 0, 100, 30, hWnd, (HMENU)IDC_BUTTON_ONE, ghInstance, NULL);
break;
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDC_BUTTON_ONE:
// Get window handle on Darkfall
cHandle = FindWindowA(NULL, "Darkfall Online");
// map virtual key code to scan code
scancode = MapVirtualKey(VK_LBUTTON, 0);
// Format of lparam needs the scancode value
// to be at bit 16 to 23.
// + 1 is the repeat count
lparam = (scancode << 16) + 1;
PostMessageA(cHandle, WM_LBUTTONDOWN, NULL, lparam);
PostMessageA(cHandle, WM_LBUTTONUP, NULL, lparam);
break;
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
// Remove hook
DetourRemove((PBYTE) pTrampolinePMA, (PBYTE) DetourPMA);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}
|
|
|
| Back to top |
|
 |
smartz993 I post too much
Reputation: 2
Joined: 20 Jun 2006 Posts: 2013 Location: USA
|
Posted: Wed Jul 29, 2009 8:55 pm Post subject: |
|
|
Don't call original PostMessageA.
Call the trampoline.
|
|
| Back to top |
|
 |
dayglo How do I cheat?
Reputation: 0
Joined: 28 Jul 2009 Posts: 6
|
Posted: Thu Jul 30, 2009 5:14 am Post subject: |
|
|
| smartz993 wrote: | Don't call original PostMessageA.
Call the trampoline. |
I've tried this by calling the trampoline and it gets the exact same result. It doesn't really matter because it's hooking postmessagea so calling postmessagea has the same result as calling the trampoline.
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Thu Jul 30, 2009 5:30 am Post subject: |
|
|
| of course it 'matters'. your trampoline jumps over the hook.. allowing you to use the function without getting redirected to the hook procedure. what's the point of writing the trampoline if you never call it..
|
|
| Back to top |
|
 |
dayglo How do I cheat?
Reputation: 0
Joined: 28 Jul 2009 Posts: 6
|
Posted: Thu Jul 30, 2009 6:06 am Post subject: |
|
|
I'm saying it doesn't matter because I have already tried this:
| Code: | pTrampolinePMA(cHandle, WM_LBUTTONDOWN, NULL, lparam);
pTrampolinePMA(cHandle, WM_LBUTTONUP, NULL, lparam); |
Instead of PostMessageA, and I got the exact same results.
|
|
| Back to top |
|
 |
smartz993 I post too much
Reputation: 2
Joined: 20 Jun 2006 Posts: 2013 Location: USA
|
Posted: Thu Jul 30, 2009 6:15 am Post subject: |
|
|
| Maybe you should try SetCursorPos right before it.
|
|
| Back to top |
|
 |
mStorm Expert Cheater
Reputation: 0
Joined: 21 Feb 2009 Posts: 107
|
Posted: Thu Jul 30, 2009 8:03 am Post subject: |
|
|
<-- just uses DirectInput for DF. Couldn't get PostMessage to work in any form or fashion. If you get it to work, pm me
|
|
| Back to top |
|
 |
dnsi0 I post too much
Reputation: 0
Joined: 04 Jan 2007 Posts: 2674
|
Posted: Thu Jul 30, 2009 9:17 am Post subject: |
|
|
| It might be my eyes but I don't see any code that hops the first 5 bytes O.O
|
|
| Back to top |
|
 |
dayglo How do I cheat?
Reputation: 0
Joined: 28 Jul 2009 Posts: 6
|
Posted: Thu Jul 30, 2009 10:06 am Post subject: |
|
|
| smartz993 wrote: | | Maybe you should try SetCursorPos right before it. |
No, that didn't work.
Does anyone else have any ideas? I dont' want to have to code raw input for this.
| mStorm wrote: | <-- just uses DirectInput for DF. Couldn't get PostMessage to work in any form or fashion. If you get it to work, pm me  |
PostMessage and SendMessage will not work with Darkfall, because it uses Direct Input. The only way to do it is with a hook, or raw input.
|
|
| Back to top |
|
 |
dnsi0 I post too much
Reputation: 0
Joined: 04 Jan 2007 Posts: 2674
|
Posted: Thu Jul 30, 2009 4:55 pm Post subject: |
|
|
| dayglo wrote: | | smartz993 wrote: | | Maybe you should try SetCursorPos right before it. |
No, that didn't work.
Does anyone else have any ideas? I dont' want to have to code raw input for this.
| mStorm wrote: | <-- just uses DirectInput for DF. Couldn't get PostMessage to work in any form or fashion. If you get it to work, pm me  |
PostMessage and SendMessage will not work with Darkfall, because it uses Direct Input. The only way to do it is with a hook, or raw input. |
SendInput(). MSDN is your friend. =).
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Thu Jul 30, 2009 5:02 pm Post subject: |
|
|
| i think that's what he means by 'raw input'
|
|
| Back to top |
|
 |
&Vage Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Jul 2008 Posts: 1053
|
Posted: Thu Jul 30, 2009 5:22 pm Post subject: |
|
|
| dnsi0 wrote: | | dayglo wrote: | | smartz993 wrote: | | Maybe you should try SetCursorPos right before it. |
No, that didn't work.
Does anyone else have any ideas? I dont' want to have to code raw input for this.
| mStorm wrote: | <-- just uses DirectInput for DF. Couldn't get PostMessage to work in any form or fashion. If you get it to work, pm me  |
PostMessage and SendMessage will not work with Darkfall, because it uses Direct Input. The only way to do it is with a hook, or raw input. |
SendInput(). MSDN is your friend. =). | SendInput won't either ^^
|
|
| Back to top |
|
 |
dnsi0 I post too much
Reputation: 0
Joined: 04 Jan 2007 Posts: 2674
|
Posted: Thu Jul 30, 2009 6:30 pm Post subject: |
|
|
| ; wrote: | | dnsi0 wrote: | | dayglo wrote: | | smartz993 wrote: | | Maybe you should try SetCursorPos right before it. |
No, that didn't work.
Does anyone else have any ideas? I dont' want to have to code raw input for this.
| mStorm wrote: | <-- just uses DirectInput for DF. Couldn't get PostMessage to work in any form or fashion. If you get it to work, pm me  |
PostMessage and SendMessage will not work with Darkfall, because it uses Direct Input. The only way to do it is with a hook, or raw input. |
SendInput(). MSDN is your friend. =). | SendInput won't either ^^ |
Doesn't it? It works for MS O.o?
|
|
| Back to top |
|
 |
dayglo How do I cheat?
Reputation: 0
Joined: 28 Jul 2009 Posts: 6
|
Posted: Thu Jul 30, 2009 7:59 pm Post subject: |
|
|
| Guys the whole point of this software is to make it work on Darkfall while it is minimized, therefore SendInput is out of the question.
|
|
| Back to top |
|
 |
smartz993 I post too much
Reputation: 2
Joined: 20 Jun 2006 Posts: 2013 Location: USA
|
Posted: Thu Jul 30, 2009 8:59 pm Post subject: |
|
|
| Hook the IDirectInput8 Interface.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|