📜 ⬆️ ⬇️

Making a dragon bot in Google Chrome

Hello, not so long ago, I had a burning desire to break the record in the mini-game of Google Chrome browser. If someone does not know, then if there is no access to the Internet and when using the above mentioned browser, a mini-game appears to start which you just need to press the spacebar or in the case of mobile phones, tap on the screen.

image

Let's start creating it. The principle of the bot is that we parse the color of a pixel at a certain distance from the character in the cycle and check if the pixel's color is equal to the color of the cactus, then we jump or do nothing.

image

Let's start with finding the right pixel. In my case, this pixel is located at the coordinates "775x250". I take the required pixel 1 higher than the highest knob on the road and at a distance from the character derived by trial and error. It should also be noted that I have a screen resolution of 1920x1080 21.5 "and if you have another, you will most likely work crookedly.
Let's create a console application in VS.
')
First, let's declare variables for pixel coordinates.

public static int x = 775; public static int y = 250; 

Then we connect the DLL to work.

  [DllImport("user32.dll")] public static extern IntPtr GetDC(IntPtr hwnd); [DllImport("user32.dll")] public static extern int ReleaseDC(IntPtr hwnd, IntPtr hDC); [DllImport("gdi32.dll")] public static extern uint GetPixel(IntPtr hDC, int x, int y); 

Further, it is still easier to add the code for the handler itself.

 IntPtr hDC = GetDC(IntPtr.Zero); while (true) { uint pixel = GetPixel(hDC, x, y); if (pixel == 5460819) { SendKeys.SendWait("{UP}"); } } 

The code is taken in an endless loop.

 if (pixel == 5460819) 

This line means that when the pixel color is equal to the color of the cactus in Decimal, then the up arrow is pressed.

 SendKeys.SendWait("{UP}"); 

Just need to connect 2 links.

 using System.Diagnostics; using System.Windows.Forms; 

At the moment, the dragon with ease overcomes 500 meters of the game, and then it is waited for by surprise in the form of birds and nights. To solve these problems, I will write the following article. Good luck!

Full code
 using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Diagnostics; using System.Windows.Forms; namespace DragonChrome { class Program { #region VAR public static int x = 775; public static int y = 250; #endregion #region DLL [DllImport("user32.dll")] public static extern IntPtr GetDC(IntPtr hwnd); [DllImport("user32.dll")] public static extern int ReleaseDC(IntPtr hwnd, IntPtr hDC); [DllImport("gdi32.dll")] public static extern uint GetPixel(IntPtr hDC, int x, int y); #endregion static void Main(string[] args) { IntPtr hDC = GetDC(IntPtr.Zero); while (true) { uint pixel = GetPixel(hDC, Convert.ToInt32(x), y); if (pixel == 5460819) { SendKeys.SendWait("{UP}"); } } } } } 

Source: https://habr.com/ru/post/330672/


All Articles