hi,
I saw several thread with autoit bots. And many people who choose autoit, because they had problems with c#.
So, i will show you some of my core source, which will allow you to make bots in C#.
First of all we need to know gamestates. This is done by pixel colors, to be patch safe. Due to Directx problems, you have to use WINDOW MODE in Diablo 3 to succesfully get the pixel color.
Just find your a pixel, which is always the same color at a gamestate. for example the background at login screen, the button at loginloading screen, or the monsters near the healthball ingame.
To read the pixel and check it just use following code:
Code:
static public Color GetColorAt(Point location)
{
using (Graphics gdest = Graphics.FromImage(screenPixel))
{
using (Graphics gsrc = Graphics.FromHwnd(IntPtr.Zero))
{
IntPtr hSrcDC = gsrc.GetHdc();
IntPtr hDC = gdest.GetHdc();
int retval = BitBlt(hDC, 0, 0, 1, 1, hSrcDC, location.X, location.Y, (int)CopyPixelOperation.SourceCopy);
gdest.ReleaseHdc();
gsrc.ReleaseHdc();
}
}
return screenPixel.GetPixel(0, 0);
}
To get the right coords in the window, and always if you move d3 window, use a convert method to get right pixel coords:
Code:
[DllImport("user32.dll")]
private static extern int GetWindowRect(IntPtr hwnd, out Rectangle rect);
static private Point ConvertToScreenPixel(Point point)
{
Rectangle rect;
GetWindowRect(D3MemReader.getInstance().getD3WinHandle(), out rect);
Point ret = new Point();
ret.X = rect.Location.X + point.X;
ret.Y = rect.Location.Y + point.Y;
return ret;
}
And here is a sample check method of my bot:
Code:
static public bool isInGame()
{
Point pixel = ConvertToScreenPixel(new Point(125, 598));
Color c = GetColorAt(pixel);
return (c.Name == "ff5d574c");
}
The next important point is how to make a click in d3? IMPORTANT thing here is the waittime, it reduces the chance of a ban =)
Code:
[DllImport("user32.dll")]
static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
static public int LeftClick(int x, int y, bool random_sleep = true, int lowest_sleep = 100, int highes_sleep = 200, bool chest_click = false)
{
int sleep = 0;
if (random_sleep)
{
sleep = random.Next(lowest_sleep, highes_sleep);
System.Threading.Thread.Sleep(sleep);
}
Point tmp = Cursor.Position;
mouse_event((int)(MouseEventFlags.LEFTUP), 0, 0, 0, 0);
Cursor.Position = ConvertToScreenPixel(new Point(x, y));
if(chest_click)
System.Threading.Thread.Sleep(50);
mouse_event((int)(MouseEventFlags.LEFTDOWN), 0, 0, 0, 0);
mouse_event((int)(MouseEventFlags.LEFTUP), 0, 0, 0, 0);
Cursor.Position = tmp;
return sleep;
}
MAKE SURE YOU ALWAYS CALL THIS METHOD WITH RANDOM COORDS!
Code:
Tools.LeftClick(rnd.Next(278, 285), rnd.Next(230, 235), true, big_run_time_min, big_run_time_max, true);
Next important thing would be to press a key. Currently i only use this for reconnect, because u are able to do all other things with the mouse.
Code:
[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);
static public int PressKey(Keys key, bool random_sleep = true, int lowest_sleep = 100, int highes_sleep = 200)
{
int sleep = 0;
if (random_sleep)
{
sleep = random.Next(lowest_sleep, highes_sleep);
System.Threading.Thread.Sleep(sleep);
}
const int KEYEVENTF_EXTENDEDKEY = 0x1;
const int KEYEVENTF_KEYUP = 0x2;
keybd_event((byte)key, 0x45, KEYEVENTF_EXTENDEDKEY, (UIntPtr)0);
System.Threading.Thread.Sleep(random.Next(5, 10));
keybd_event((byte)key, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, (UIntPtr)0);
return sleep;
}
With this pieces of code your are already able to make a nice bot.
Hope it helps u a bit =)
-Shoruun