Creating a Pixel Bot in C# from zero  - "kinda" tutorial menu

User Tag List

Page 7 of 9 FirstFirst ... 3456789 LastLast
Results 91 to 105 of 122
  1. #91
    Plobbi's Avatar Member
    Reputation
    1
    Join Date
    Aug 2014
    Posts
    11
    Thanks G/R
    6/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can Warden or other features detect my inputs?

    [DllImport("user32.dll")]
    static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

    Creating a Pixel Bot in C# from zero  - "kinda" tutorial
  2. #92
    GlittPrizes's Avatar Active Member CoreCoins Purchaser Authenticator enabled
    Reputation
    58
    Join Date
    Nov 2019
    Posts
    104
    Thanks G/R
    53/33
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Plobbi View Post
    can Warden or other features detect my inputs?

    [DllImport("user32.dll")]
    static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
    They can see that you are sending virtual presses, but I don't think they will go after you just on that because it would wipe out most of the multiboxers. You can use/write a keyboard driver or I think Java's Robot class has a hardware keyboard driver.
    Last edited by GlittPrizes; 07-04-2020 at 01:46 AM.

  3. #93
    AspiringBotter's Avatar Member
    Reputation
    2
    Join Date
    Jun 2020
    Posts
    4
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    I am a noob with C#, I only have experience in python very minimal.

    I am trying to put together this tutorial, but receive an error when passing through an argument into one of the functions

    Code:
     Color GetColorAt(int x, int y)
        {
            Rectangle bounds = new Rectangle(x, y, 1, 1);
            using (Graphics g = Graphics.FromImage(bmp))
                g.CopyFromScreen(bounds.Location, Point.Empty, bounds.Size);
            return bmp.GetPixel(0, 0);
        }
    and the 'bmp' gives error cs5001 and says that the name bmp does not exist in the current context

    Thanks and sorry about the total noob question.

  4. #94
    GlittPrizes's Avatar Active Member CoreCoins Purchaser Authenticator enabled
    Reputation
    58
    Join Date
    Nov 2019
    Posts
    104
    Thanks G/R
    53/33
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by AspiringBotter View Post
    Hello,

    I am a noob with C#, I only have experience in python very minimal.

    I am trying to put together this tutorial, but receive an error when passing through an argument into one of the functions

    Code:
     Color GetColorAt(int x, int y)
        {
            Rectangle bounds = new Rectangle(x, y, 1, 1);
            using (Graphics g = Graphics.FromImage(bmp))
                g.CopyFromScreen(bounds.Location, Point.Empty, bounds.Size);
            return bmp.GetPixel(0, 0);
        }
    and the 'bmp' gives error cs5001 and says that the name bmp does not exist in the current context

    Thanks and sorry about the total noob question.
    It means that within that scope aka the variables that function has access to, it can't see any Bitmap named bmp. You need to initialize a variable like "Bitmap bmp = new Bitmap(1,1);". Make it a global variable instead of inside the function, so the bitmap won't be black. Also, you can always look up an error code (cs5001) to get more details on the specific error.
    Last edited by GlittPrizes; 06-16-2020 at 01:46 PM.

  5. #95
    AspiringBotter's Avatar Member
    Reputation
    2
    Join Date
    Jun 2020
    Posts
    4
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your reply. Just curious, can these types of bots be made in python?

  6. #96
    GlittPrizes's Avatar Active Member CoreCoins Purchaser Authenticator enabled
    Reputation
    58
    Join Date
    Nov 2019
    Posts
    104
    Thanks G/R
    53/33
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by AspiringBotter View Post
    Thanks for your reply. Just curious, can these types of bots be made in python?
    Of course, you could likely use PIL (Python Image Library) to do the same stuff. I would however, try sticking to C#/C++ because of the type safety. For game automation related stuff I think it's a must to define your objects explicitly even if you're mostly using auto/var.
    Last edited by GlittPrizes; 06-17-2020 at 04:17 PM. Reason: shorten

  7. #97
    Humbleguy's Avatar Active Member
    Reputation
    24
    Join Date
    Dec 2019
    Posts
    27
    Thanks G/R
    6/5
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by tessier-ashpool View Post
    I stumbled across this post and since i dabble with programming from time to time I decided to see what I could do with the information provided. I actually surprised myself with the progress I have made. I am able to record and follow a route. The bot will check for targets periodically and when it finds one will engage in combat. I did not plan out my code or have any idea what I was getting myself into and its starting to become difficult to make sense of it. I spent far too long writing the algorithm to turn the player the shortest direction especially across the 0/360 degree value. I believe I need to implement some FSM but I still don't understand them. Just wanted to say thanks for the information here and leave my two cents.
    I think the easiest way to deal with this issue, is use a 0-2000 scale instead of 0-360. That's because it takes exactly two seconds to make a 360 degree turn using arrow keys.

    If anyone has issue with an specific point, just ask me and I might paste my code if that helps.

  8. #98
    stonebent's Avatar Member
    Reputation
    9
    Join Date
    Sep 2008
    Posts
    36
    Thanks G/R
    3/8
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Humbleguy View Post
    I think the easiest way to deal with this issue, is use a 0-2000 scale instead of 0-360. That's because it takes exactly two seconds to make a 360 degree turn using arrow keys.

    If anyone has issue with an specific point, just ask me and I might paste my code if that helps.
    Code:
    float twoPi = (float)Math.PI * 2;
    
    cell = (float)Math.Floor(angle / twoPi * 108 + 0.5) % 108;
    
    if (cell <= 53.5f)
    {
        //turn left
    }
    else if (cell >= 53.5f)
    {
        //turn right
    }
    Here's my solution to deciding which way to turn for the best result
    Last edited by stonebent; 06-25-2020 at 03:39 PM.

  9. Thanks GlittPrizes (1 members gave Thanks to stonebent for this useful post)
  10. #99
    Plobbi's Avatar Member
    Reputation
    1
    Join Date
    Aug 2014
    Posts
    11
    Thanks G/R
    6/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now I have about 20 pixels to look for. Every pixel costs me about 15 milliseconds. Anyone who has a faster function to do that?

  11. #100
    GlittPrizes's Avatar Active Member CoreCoins Purchaser Authenticator enabled
    Reputation
    58
    Join Date
    Nov 2019
    Posts
    104
    Thanks G/R
    53/33
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Plobbi View Post
    Now I have about 20 pixels to look for. Every pixel costs me about 15 milliseconds. Anyone who has a faster function to do that?
    PixelMap nuget package is good for working with fast bitmaps. Probably one of the fastest things you can do is capture a region that includes just the pixel outputs and then read the 20 pixels. I'm just reading each pixel and haven't bothered with updating to PixelMap or LockBits bitmap method yet. Another thing you can do is have a pixel that cycles through every single color and only increments when your outputs are updated to get an accurate sync. Threading or parallel bitmap reading will also increase speed.

  12. #101
    Plobbi's Avatar Member
    Reputation
    1
    Join Date
    Aug 2014
    Posts
    11
    Thanks G/R
    6/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by hycolyte View Post
    PixelMap nuget package is good for working with fast bitmaps. Probably one of the fastest things you can do is capture a region that includes just the pixel outputs and then read the 20 pixels. I'm just reading each pixel and haven't bothered with updating to PixelMap or LockBits bitmap method yet. Another thing you can do is have a pixel that cycles through every single color and only increments when your outputs are updated to get an accurate sync. Threading or parallel bitmap reading will also increase speed.
    Threading was also something I tried but it does not work for me. It is the same duration if I give every Thread his own handle. And if they get all the same handle then only the first thread is getting the values. And yes I am waiting for all Threads before I release the handle (I use a simple own created bool for each thread that tells me if the thread is running. And those booleans I check (in a while after thread starting) before I release.

    So at the moment I am in C++ trying to create some fast dll I can call from my C#

    But thanks for the hint with PixelMap nuget package, maybe I will look into that!

    What is your duration for pixelreading?

  13. #102
    GlittPrizes's Avatar Active Member CoreCoins Purchaser Authenticator enabled
    Reputation
    58
    Join Date
    Nov 2019
    Posts
    104
    Thanks G/R
    53/33
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Plobbi View Post
    Threading was also something I tried but it does not work for me. It is the same duration if I give every Thread his own handle. And if they get all the same handle then only the first thread is getting the values. And yes I am waiting for all Threads before I release the handle (I use a simple own created bool for each thread that tells me if the thread is running. And those booleans I check (in a while after thread starting) before I release.

    So at the moment I am in C++ trying to create some fast dll I can call from my C#

    But thanks for the hint with PixelMap nuget package, maybe I will look into that!

    What is your duration for pixelreading?
    I'm no expert on multi-threading but one thing to try is using condition variables instead of while + booleans

    Here is an example of how I exit a single thread with a condition variable. (hInstance is the same parameter passed from DllMain)
    Code:
    std::mutex _mtx;
    std::condition_variable _threadSafety;
    bool _safeToExit;        // changing this to true elsewhere in code will exit the thread after calling notify_all on the cv
    
    int Dx12Thread(LPVOID hInstance)
    {
    	// Do work here
    
    
            // Exit routine cv
    	std::unique_lock<std::mutex> lock(_mtx);
    	_threadSafety.wait(lock, [] { return _safeToExit == true; });
    
    	FreeLibraryAndExitThread(HMODULE(hInstance), 0);
    }

    This is pretty much what I was doing with a fish bot. The scans are very fast.

    Code:
    // ... pass in x, y
    
    var rect = new Rectangle(x, y, width, height);
    
    var captureBitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb);
    
    var graphics = Graphics.FromImage(captureBitmap);
    graphics.SetClip(rect);
    
    graphics.CopyFromScreen(rect.Left + Window.Dimensions.X, rect.Top + Window.Dimensions.Y, 0, 0, new Size(width, height), CopyPixelOperation.SourceCopy);
    
    pixelMap = new PixelMap(captureBitmap);
    
    var color = pixelMap[x, y].Color;
    return Color.FromArgb(255, color.R, color.G, color.B);        // There is an issue with PixelMap where it doesn't translate the alpha value hence the tmp color
    I'm not sure if PixelMap is just C# or not, but the performance is good. I think GDI calls in this manner actually outperform working with the raw Direct X buffer because DX isn't optimized for 2D reads.
    Last edited by GlittPrizes; 07-30-2020 at 05:25 PM. Reason: forgot part

  14. Thanks Plobbi (1 members gave Thanks to GlittPrizes for this useful post)
  15. #103
    MrNotSoBright's Avatar Member
    Reputation
    1
    Join Date
    Jul 2019
    Posts
    10
    Thanks G/R
    1/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Humbleguy View Post
    I think the easiest way to deal with this issue, is use a 0-2000 scale instead of 0-360. That's because it takes exactly two seconds to make a 360 degree turn using arrow keys.

    If anyone has issue with an specific point, just ask me and I might paste my code if that helps.
    I actually made the turning mouse based. Sure, in the beginning there was some problem turning it off but now I think it works better and looks more humanlike. You do it intervals, like first determine in what way is the shortest to spin, then you take ur total screen values (max X and Y) and the sensitivity of the mouse and move the mouse accordingly. You may or may not turn 5-25% too much but in the next iteration you will get around the correct facing value. It looks very real when you run and follow a path.

  16. #104
    Xcesiuss's Avatar Contributor CoreCoins Purchaser
    Reputation
    119
    Join Date
    Mar 2008
    Posts
    135
    Thanks G/R
    14/85
    Trade Feedback
    4 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    While I understand the need and usage for this for some, I just want to point out that MouseEventFlags are highly detectable by any decent developer with some anti-cheat.
    If you still plan on using mouse (which is required for a bot), look into alternatives for mouse clicking.

  17. #105
    Plobbi's Avatar Member
    Reputation
    1
    Join Date
    Aug 2014
    Posts
    11
    Thanks G/R
    6/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by hycolyte View Post
    I'm no expert on multi-threading but one thing to try is using condition variables instead of while + booleans

    Here is an example of how I exit a single thread with a condition variable. (hInstance is the same parameter passed from DllMain)
    Code:
    std::mutex _mtx;
    std::condition_variable _threadSafety;
    bool _safeToExit;        // changing this to true elsewhere in code will exit the thread after calling notify_all on the cv
    
    int Dx12Thread(LPVOID hInstance)
    {
    	// Do work here
    
    
            // Exit routine cv
    	std::unique_lock<std::mutex> lock(_mtx);
    	_threadSafety.wait(lock, [] { return _safeToExit == true; });
    
    	FreeLibraryAndExitThread(HMODULE(hInstance), 0);
    }

    My read times are pretty slow because I wasn't doing it properly and started on a different project instead before updating. My fishbot however is also uncompleted, but it has way faster read times. You could adapt it to suit your needs though and it would be fast (It can scan through big chunks of image really quick).

    Angles/GDI.cs at master . glubdos/Angles . GitHub

    I implemented it in kind of a weird way, so without getting too distracted by that mainly focus on this part for reference. Try capturing a region of just the pixel outputs and then see how long reading into pixelMao[x,y] takes for each value you need.

    Code:
    // ... pass in x, y
    
    var rect = new Rectangle(x, y, width, height);
    
    var captureBitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb);
    
    var graphics = Graphics.FromImage(captureBitmap);
    graphics.SetClip(rect);
    
    graphics.CopyFromScreen(rect.Left + Window.Dimensions.X, rect.Top + Window.Dimensions.Y, 0, 0, new Size(width, height), CopyPixelOperation.SourceCopy);
    
    pixelMap = new PixelMap(captureBitmap);
    
    var color = pixelMap[x, y].Color;
    return Color.FromArgb(255, color.R, color.G, color.B);        // There is an issue with PixelMap where it doesn't translate the alpha value hence the tmp color
    I'm not sure if PixelMap is just C# or not, but the performance is good. I think GDI calls in this manner actually outperform working with the raw Direct X buffer because DX isn't optimized for 2D reads.
    Now I found the time to import PixelMap and adapt it to my code and I am so suprised how well it performs. It dropped my time from about 500ms to 0ms - yes 0ms!!! crazy. No more thoughts about dropping some pixels to decrease wait and calculation times. thank you soo much.

Page 7 of 9 FirstFirst ... 3456789 LastLast

Similar Threads

  1. [Question] Has anyone ever made an entire farming-bot with much much pixel-reading in AutoIt?
    By crunk001 in forum WoW Bots Questions & Requests
    Replies: 18
    Last Post: 02-05-2017, 06:34 AM
  2. Gold from botting in MOP
    By 403Forbidden in forum WoW Bots Questions & Requests
    Replies: 3
    Last Post: 01-16-2013, 06:49 AM
  3. Replies: 0
    Last Post: 09-09-2012, 06:38 AM
  4. Replies: 4
    Last Post: 04-18-2010, 12:47 PM
  5. Botting in Barrens 12-20
    By karokekid in forum World of Warcraft Bots and Programs
    Replies: 20
    Last Post: 12-02-2006, 07:21 PM
All times are GMT -5. The time now is 12:30 PM. 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