[Source] How to BOT in C# menu

User Tag List

Results 1 to 14 of 14
  1. #1
    Shoruun's Avatar Member
    Reputation
    5
    Join Date
    Jun 2012
    Posts
    39
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Source] How to BOT in C#

    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

    [Source] How to BOT in C#
  2. #2
    hovsa's Avatar Member
    Reputation
    1
    Join Date
    Aug 2010
    Posts
    8
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nice, as a Webdeveloper myself i was using AutoIT because i didnt have the first clue on how to do these things in WinForms and not having access to all the luxuries of C# is driving me crazy, i just might do my first ever WinForms project now

  3. #3
    Shoruun's Avatar Member
    Reputation
    5
    Join Date
    Jun 2012
    Posts
    39
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you r welcome =)

  4. #4
    CreativeXtent's Avatar Moderator Authenticator enabled
    Reputation
    580
    Join Date
    Jun 2011
    Posts
    1,594
    Thanks G/R
    242/148
    Trade Feedback
    3 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Very nice +! rep

  5. #5
    Sychotix's Avatar Moderator Authenticator enabled
    Reputation
    1421
    Join Date
    Apr 2006
    Posts
    3,942
    Thanks G/R
    285/572
    Trade Feedback
    1 (100%)
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    Eww... programming a bot with pixel detection. Regardless, I'm sure people will find this to be useful. +Rep.

  6. #6
    Arakkoa's Avatar Member
    Reputation
    1
    Join Date
    Sep 2007
    Posts
    34
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Sychotix View Post
    Eww... programming a bot with pixel detection. Regardless, I'm sure people will find this to be useful. +Rep.
    Well, screen scraping reduces the chances of getting banned as there is no need to inject code, or read memory or anything of the sorts.

  7. #7
    kyllesdk's Avatar Private
    Reputation
    1
    Join Date
    Sep 2010
    Posts
    1
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    GetWindowRect(D3MemReader.getInstance().getD3WinHandle(), out rect);

    I det the error that D3MemReader dosen't exist in the current context.

    What is the D3MemReader? Some code that you didn't include in this post?

  8. #8
    who knows's Avatar Contributor
    Reputation
    110
    Join Date
    Nov 2007
    Posts
    284
    Thanks G/R
    2/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by hovsa View Post
    nice, as a Webdeveloper myself i was using AutoIT because i didnt have the first clue on how to do these things in WinForms and not having access to all the luxuries of C# is driving me crazy, i just might do my first ever WinForms project now
    I've written bots in Visual Basic of all things, why wouldn't c# in visual studio work? Haven't used the language myself yet, I've just heard that they're similar, C++ & VB combined = C#.
    My Diablo 3 Gear Swap Program:
    https://www.ownedcore.com/forums/diablo-3/diablo-3-bots-programs/352782-free-wks-gear-swap-bot.html

  9. #9
    hecccy's Avatar Master Sergeant
    Reputation
    5
    Join Date
    Jan 2012
    Posts
    97
    Thanks G/R
    0/0
    Trade Feedback
    1 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i wish i knew how to code properly, C# is one of the only things i know but this is still too complex for me

  10. #10
    jockep's Avatar Private
    Reputation
    1
    Join Date
    Jul 2011
    Posts
    2
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by kyllesdk View Post
    GetWindowRect(D3MemReader.getInstance().getD3WinHandle(), out rect);

    I det the error that D3MemReader dosen't exist in the current context.

    What is the D3MemReader? Some code that you didn't include in this post?
    It's using some custom function to read the handle of the Diablo 3 window. You could use this
    Code:
    [DllImport("user32.dll", SetLastError = true)]
    static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
    
    IntPtr hWnd = (IntPtr)FindWindow("Diablo III", null);
    and replace D3MemReader.getInstance().getD3WinHandle() with hWnd

    Didn't try it tho.

  11. #11
    Shoruun's Avatar Member
    Reputation
    5
    Join Date
    Jun 2012
    Posts
    39
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    and the same without DllImport:
    Code:
    public IntPtr getD3WinHandle()
    {
    	Process[] processes = Process.GetProcessesByName("Diablo III");
    	if (processes.Count() > 1)
    		throw new Exception("Too many Processes named Diablo 3!");
    
    	if (processes.Count() == 0)
    		throw new Exception("Diablo 3 not found!");
    
    	return processes[0].MainWindowHandle;
    }
    i am saving this in a singleton, so i only need to get it once.

  12. #12
    muskatnuss's Avatar Member
    Reputation
    1
    Join Date
    Jun 2012
    Posts
    4
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow this is very usefull! Thanks for that pieces of code!

    I have only written one app in c# it was a simple maths program so far. well i know the basics here but i really do got stuck with this "BitBlt" i really dont get the point with this one ?!
    What is it and where do iget it?
    I have read about it everything i was able to find.

    Maybe you Shoruun can help me out or anybody else who knows c# and its librarys

    Cheers

  13. #13
    DozyJr's Avatar Private
    Reputation
    1
    Join Date
    Jun 2012
    Posts
    2
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by muskatnuss View Post
    Wow this is very usefull! Thanks for that pieces of code!

    I have only written one app in c# it was a simple maths program so far. well i know the basics here but i really do got stuck with this "BitBlt" i really dont get the point with this one ?!
    What is it and where do iget it?
    I have read about it everything i was able to find.

    Maybe you Shoruun can help me out or anybody else who knows c# and its librarys

    Cheers
    found this link: BitBlt : Windows API*«*Windows*«*C# / C Sharp

    Just put this in your code:
    Code:
    [DllImportAttribute("gdi32.dll")]
            private static extern int BitBlt
            (
                IntPtr hdcDest,     // handle to destination DC (device context)
                int nXDest,         // x-coord of destination upper-left corner
                int nYDest,         // y-coord of destination upper-left corner
                int nWidth,         // width of destination rectangle
                int nHeight,        // height of destination rectangle
                IntPtr hdcSrc,      // handle to source DC
                int nXSrc,          // x-coordinate of source upper-left corner
                int nYSrc,          // y-coordinate of source upper-left corner
                System.Int32 dwRop  // raster operation code
            );
    Thanks for this topic - really useful

    cheers

  14. #14
    egangster's Avatar Private
    Reputation
    1
    Join Date
    Jan 2013
    Posts
    1
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm, hello

    This may sound a bit lame question but...how do you fill in the screenPixel variable? I'm guessing you should have a method to get a snapshot of the game window and pass it to the screenPixel variable as an Image ?

Similar Threads

  1. [Guide] [How to run] Open Source Pokemon Go Bot [Noob friendly/Windows7]
    By misterne in forum Pokemon GO Hacks|Cheats
    Replies: 14
    Last Post: 08-13-2016, 08:05 PM
  2. [Source] Unfinished Fishing Bot [Help]
    By Molleren in forum Programming
    Replies: 10
    Last Post: 09-14-2009, 02:02 AM
  3. How to bot 2 chars at once!
    By Kazique in forum World of Warcraft Bots and Programs
    Replies: 8
    Last Post: 03-14-2008, 01:41 PM
  4. [GUIDE] How to BOT a mage
    By k!nKy^ in forum World of Warcraft Guides
    Replies: 11
    Last Post: 12-11-2007, 05:20 AM
  5. How To Bot/get Account Back Safely
    By darkriderking in forum World of Warcraft Bots and Programs
    Replies: 27
    Last Post: 12-10-2007, 06:00 AM
All times are GMT -5. The time now is 06:05 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search