View Full Version : [c++] runescape bot
kibbles18
04-15-2012, 09:18 PM
so what im trying to do is create a rs client in c++. i have an api spy im using to grab the game child hwnd. is there anyway i can do this without first opening internet explorer? and how can i move the mouse in the client without moving the actual mouse?
ShawnjohnSJ
04-15-2012, 09:20 PM
To grab the HWND of the game, it has to be open first. As for making a fake mouse, look up "SendMessage" and "PostMessage" in the windows API.
kibbles18
04-15-2012, 09:37 PM
thank you sir. and i know the game has to be open, i was just wondering if i could open it independantly so the user wouldnt have to
Imanoobbot
04-15-2012, 09:44 PM
This is going to be a really nice project. Would be nice to see this thread updated =)
ShawnjohnSJ
04-15-2012, 09:44 PM
You could create something like SMART (load the game client via java) and interface it with JNI, or you can simply open firefox up with the game URL.
You can use the SMART (https://github.com/BenLand100/SMART) library.
Edit: :ninja:'d.
kibbles18
04-15-2012, 09:53 PM
I would use smart lib but im the type of guy who has to know how things work and do it myself.
Anyways, i got the client working mostly, it just wont accept messages.
kibbles18
04-15-2012, 10:17 PM
does anybody know why the client wont accept sendmessage or postmessage?
ShawnjohnSJ
04-15-2012, 10:18 PM
Let me see your code using SendMessage. By the way, you need to replicate the mouse. You can't just send random click events because its easily detectable. You need to replicate all the mouse movement.
kibbles18
04-15-2012, 10:22 PM
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_KEYDOWN:
switch(LOWORD (wParam))
{
//case VK_UP:
}
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
kibbles18
04-15-2012, 10:24 PM
whats the msg for mouse events?
ShawnjohnSJ
04-15-2012, 10:25 PM
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
SendMessageA(client, msg, wParam, lParam);
switch(msg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_KEYDOWN:
switch(LOWORD (wParam))
{
//case VK_UP:
}
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
Try using PostMessage. Also, you need to use coordinates relative to the whole screen and not just your client.
What do you mean it acts weird?
kibbles18
04-15-2012, 10:32 PM
it seems i need to choose which events get sent to the client and which dont.
for example moving the parent will move the child client instead
ShawnjohnSJ
04-15-2012, 10:37 PM
it seems i need to choose which events get sent to the client and which dont.
for example moving the parent will move the child client instead
Its probably the method you're using (why are you putting SendMessage in WndProc?). I really can't help any further since I don't have a windows PC to test anything on.
kibbles18
04-15-2012, 10:44 PM
because im not sure how else to send messages to the rs client seeing they wont by themselves
ShawnjohnSJ
04-15-2012, 10:52 PM
Something along the lines of: (pseudo code)
void leftMouseClick(HWND window, int x, int y) // note: x, y are relative to the screen, not the client., so if the client is located at 500,500 and you want to click at 5, 5 - x, y would be: 505, 505.
{
SendMessage(window, WM_MBUTTONDOWN, MK_LBUTTON, MAKELPARAM(x, y));
SendMessage(window, WM_MBUTTONUP, MK_LBUTTON, MAKELPARAM(x, y));
}
Then you need some way of making scripts to do the clicking for you. (it might be alot more in depth than you think).
Frement
04-15-2012, 10:59 PM
Follow the discussion in this thread if you want to know how you could get the HWND: http://villavu.com/forum/showthread.php?t=54922
kibbles18
04-15-2012, 11:02 PM
the problem is that i cant type in anything like my username and pass. ill add the botting stuff later right now its a client
ShawnjohnSJ
04-15-2012, 11:03 PM
the problem is that i cant type in anything like my username and pass. ill add the botting stuff later right now its a client
I see, well I can't really help much further. I don't have windows to test any code on and I can't point you in the right direction without testing.
Frement
04-15-2012, 11:04 PM
Perhaps these help?
void MainWindow::MouseMove(int x, int y)
{
double fScreenWidth = GetSystemMetrics(SM_CXSCREEN) - 1;
double fScreenHeight = GetSystemMetrics(SM_CYSCREEN) - 1;
double fx = x * (65535.0f / fScreenWidth);
double fy = y * (65535.0f / fScreenHeight);
INPUT input = {0};
ZeroMemory(&input, sizeof(input));
input.type = INPUT_MOUSE;
input.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;
input.mi.dx = fx;
input.mi.dy = fy;
SendInput(1, &input, sizeof(INPUT));
}
void MainWindow::KB_A(bool keyUp)
{
INPUT input = {0};
ZeroMemory(&input, sizeof(input));
if (keyUp && aDown)
{
input.type = INPUT_KEYBOARD;
input.ki.wVk = 'A';
input.ki.dwFlags = KEYEVENTF_KEYUP;
input.ki.time = 0;
input.ki.dwExtraInfo = NULL;
aDown = false;
} else {
input.type = INPUT_KEYBOARD;
input.ki.wVk = 'A';
input.ki.time = 0;
input.ki.dwExtraInfo = NULL;
aDown = true;
}
SendInput(2, &input, sizeof(INPUT));
}
ShawnjohnSJ
04-15-2012, 11:07 PM
Perhaps these help?
void MainWindow::MouseMove(int x, int y)
{
double fScreenWidth = GetSystemMetrics(SM_CXSCREEN) - 1;
double fScreenHeight = GetSystemMetrics(SM_CYSCREEN) - 1;
double fx = x * (65535.0f / fScreenWidth);
double fy = y * (65535.0f / fScreenHeight);
INPUT input = {0};
ZeroMemory(&input, sizeof(input));
input.type = INPUT_MOUSE;
input.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;
input.mi.dx = fx;
input.mi.dy = fy;
SendInput(1, &input, sizeof(INPUT));
}
void MainWindow::KB_A(bool keyUp)
{
INPUT input = {0};
ZeroMemory(&input, sizeof(input));
if (keyUp && aDown)
{
input.type = INPUT_KEYBOARD;
input.ki.wVk = 'A';
input.ki.dwFlags = KEYEVENTF_KEYUP;
input.ki.time = 0;
input.ki.dwExtraInfo = NULL;
aDown = false;
} else {
input.type = INPUT_KEYBOARD;
input.ki.wVk = 'A';
input.ki.time = 0;
input.ki.dwExtraInfo = NULL;
aDown = true;
}
SendInput(2, &input, sizeof(INPUT));
}
I believe that code uses the real mouse/keyboard instead of simulating mouse/key presses.
Frement
04-15-2012, 11:08 PM
I believe that code uses the real mouse/keyboard instead of simulating mouse/key presses.
Oh yes it does, sorry about that, but for keyboard it shouldn't matter?
Heres more updated code:
void MainWindow::PressKey(WORD vKey, bool keyUp)
{
INPUT input;
ZeroMemory(&input, sizeof(INPUT));
input.type = INPUT_KEYBOARD;
input.ki.wVk = vKey;
input.ki.dwFlags = keyUp ? KEYEVENTF_KEYUP : 0;
input.ki.time = 0;
input.ki.dwExtraInfo = NULL;
keys[vKey] = keyUp;
SendInput(2, &input, sizeof(INPUT));
}
ShawnjohnSJ
04-15-2012, 11:09 PM
Oh yes it does, sorry about that, but for keyboard it shouldn't matter?
Heres more updated code:
void MainWindow::PressKey(WORD vKey, bool keyUp)
{
INPUT input;
ZeroMemory(&input, sizeof(INPUT));
input.type = INPUT_KEYBOARD;
input.ki.wVk = vKey;
input.ki.dwFlags = keyUp ? KEYEVENTF_KEYUP : 0;
input.ki.time = 0;
input.ki.dwExtraInfo = NULL;
keys[vKey] = keyUp;
SendInput(2, &input, sizeof(INPUT));
}
It does if you want to send key presses with the client minimized. That doesn't send key presses to any specific window, just to whatever is focused.
kibbles18
04-15-2012, 11:13 PM
they help, but not right now.
im out, ill try more tommorow
Frement
04-15-2012, 11:13 PM
It does if you want to send key presses with the client minimized. That doesn't send key presses to any specific window, just to whatever is focused.
Well I'll be damned. I suppose I can't paste anything specific to this situation then. :)
ShawnjohnSJ
04-15-2012, 11:14 PM
they help, but not right now.
im out, ill try more tommorow
I understand thats not what you're looking for right now. I don't know how to solve your problem without a windows PC to test, so hopefully someone else can step in and help.
kibbles18
04-16-2012, 12:47 AM
the problem is somewhere in the msg handler, i logged in on runescape before hijacking the client window and i could click stuff but not type
kibbles18
04-16-2012, 12:53 AM
maybe the problem is ive been using an on screen keyboard that wouldnt alert the msg handler of my program?
Brandon
04-16-2012, 12:57 AM
WUT? U cant even put SendMessage in the callback proc like that -___- it'll never do what you want. Your message handler isn't properly constructed.
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(............)
{
CreateWindowEx(..........);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while(GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT PS;
HDC hdc;
switch (message)
{
case WM_CREATE:
{
HWND SomeHandle = FindWindow(NULL, "SomeWindowName");
SendMessage(SomeHandle, WM_SETFONT, (WPARAM)hFont, (LPARAM) NULL); //Edit this to your liking or whatever
}
break;
case WM_PAINT:
hdc = BeginPaint(hwnd, &PS);
EndPaint(hwnd, &PS);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
}
kibbles18
04-16-2012, 01:05 AM
@ggzz yeah i figured that out. it was my first time using child windows and i thought all events were auto sent to parent.
kibbles18
04-16-2012, 01:19 AM
the problem dissapeared :o time to make the bot
Imanoobbot
04-16-2012, 01:35 AM
the problem dissapeared :o time to make the bot
Good Luck!
Powered by vBulletin® Version 4.2.1 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.