The journey begins

'Automating' comes from the roots 'auto-' meaning 'self-', and 'mating', meaning 'screwing'.

This xkcd comic perfectly describes life of a botter. I felt obliged to include that so my first post is not just a TLDR wall of text. Before we start grinding XP, hitting quick time events like a boss and doing all sorts of fun stuff we need to cover some basics. I will try to keep it short and simple.

I look at botting as a process consisting of 3 steps:

  • acquiring game/environment state
  • making some decisions
  • interacting with game/environment

How to acquire a game state

Easiest way is image analysis. This may sound complicated but in reality it boils down to pixel search and image search.

During pixel search we are looking for a coordinates of a pixel with specified color (usually with some tolerance). AutoIt has PixelSearch function for that. Opposite to pixel search is getting color of a pixel at specified coordinates. In AutoIt you can use PixelGetColor combined with _ColorGetRGB to get color in RGB format.

Image search is a process of looking for an image inside another image. This functionality is not built into AutoIt but can be easily added though ImageSearch plugin. All you need is a bitmap file containing image you want to find and you are good to go.

What is good about these techniques is that they are virtually impossible to detect and sufficient to create a Diablo 3 bot which can explore maps like Fields of Misery, kill monsters and pick up items.

Advanced way of getting game state is reading it's process memory. Unless you have enough knowledge to figure out yourself what game structures are used and how to find them, you will have to rely on 3rd party libraries or code samples scattered around cheating forums like http://www.ownedcore.com or https://www.unknowncheats.me. Additional problem is that some anti-cheat software like EasyAntiCheat will disallow opening any unauthorized handles to the protected process (however there are ways to workaround that). By having this handle you create a link between your bot and a game, making you vulnerable to being detected. Advantages however, depending on what has been figured out, might be overwhelming as you may have access to pretty much anything (including stuff that you may not be able to see as a human player).

On rare occasions developers provide an API themselves allowing player to easily read game state (like StarCraft 2 API).

How to make decisions

So you have a knowledge about what is happening on the screen, now you need to decide what you want to do. It can be as simple as bunch of "if" statements or as complicated as fully blown artificial intelligence logic. Each situation is different. Just remember one thing: "keep it simple". Start with super simple solution and improve it as necessary. I will cover it in more depth when it comes to real life examples in future posts.

How to interact with a game

Most common way is simulating inputs like mouse clicks and key presses. AutoIt has a some useful functions for doing that.

For mouse there is MouseClickControlClick (for sending clicks to specific window by handle) and MouseMove to name a few. AutoIt is very well documented and there is whole family of mouse related functions which you can easily explore in their help. Keep in mind that there are 3 coordinates reference modes:

  • relative to active window
  • relative to client area of active window (window without surrounding frame)
  • absolute screen coordinates

You can specify which one should be used by setting MouseCoordMode option via AutoItSetOption.

For keyboard there is Send and ControlSend (for sending keys to specific window by handle).

Using above functions you can write simple key/mouse button smashing scripts to save your fingers and hardware.

There are also advanced techniques like calling game functions directly from your code, but these are very vulnerable to detection thus should be used only by those who know what they are doing.

And some people go one step further and create an actual robots to handle inputs like this guy who created a bot playing guitar...

Tools you may find useful

There are some tools, which I personally use, that can make your life easier when it comes to developing and debugging bots:

  • paint.net - very good replacement of windows paint
  • AutoIt Window Information Tool - comes as a part of AutoIt install package and allows acquiring all necessary window/mouse data (remember to set proper Coord Mode in Options)
  • Bandicam/ShadowPlay - video recording is very useful when it comes to storing data for debugging purposes
  • virtualdub - for frame by frame video analysis
  • TortoiseSVN - for keeping your code under control
  • Dropbox - cool combo is storing SVN repository on a dropbox so you can access it anywhere and share it with other people while being independent from external servers (detailed guide can be found here)

What now?

Now as we have all this boring basics behind us, we can focus on getting our hand dirty. In the next episode we will put all that knowledge to good use in:

In the meantime feel free to leave a comment with a question or suggestion or whatever you see fit. glhf!