Last active
January 21, 2019 09:49
-
-
Save fipso/5234d12dbfad25a3a101ddce0fe8aed7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading; | |
using System.Diagnostics; | |
using System.Runtime.InteropServices; | |
using System.Drawing; | |
namespace BarrierX_Bot | |
{ | |
class Program | |
{ | |
static Random rnd = new Random(); | |
static Process proc; | |
const UInt32 WM_KEYDOWN = 0x0100; | |
const UInt32 WM_KEYUP = 0x0101; | |
const int VK_E = 0x45; | |
const int VK_A = 0x41; | |
const int VK_D = 0x44; | |
[DllImport("user32.dll")] | |
static extern bool PostMessage(IntPtr hWnd, UInt32 Msg, UInt32 wParam, UInt32 lParam); | |
[DllImport("user32.dll")] | |
static extern IntPtr GetDC(IntPtr hwnd); | |
[DllImport("user32.dll")] | |
static extern IntPtr GetWindowDC(IntPtr hwnd); | |
[DllImport("user32.dll")] | |
static extern Int32 ReleaseDC(IntPtr hwnd, IntPtr hdc); | |
[DllImport("gdi32.dll")] | |
static extern uint GetPixel(IntPtr hdc, int nXPos, int nYPos); | |
[STAThread] | |
static void Main(string[] args) | |
{ | |
try | |
{ | |
proc = Process.GetProcessesByName("BarrierX")[0]; | |
while (true) | |
{ | |
//Point InFront | |
Color c1 = GetPixelColor(643, 480); | |
//Point Behind | |
Color c2 = GetPixelColor(643, 610); | |
//Point Left 1 | |
Color c3 = GetPixelColor(100, 581); | |
//Point Right 1 | |
Color c4 = GetPixelColor(1200, 581); | |
//Point Left 2 | |
Color c5 = GetPixelColor(400, 500); | |
//Point Right 2 | |
Color c6 = GetPixelColor(900, 500); | |
//Point Left 3 | |
Color c7 = GetPixelColor(200, 500); | |
//Point Right 3 | |
Color c8 = GetPixelColor(1100, 500); | |
//Clean | |
Console.SetCursorPosition(0, 0); | |
Console.Write(" "); | |
Console.SetCursorPosition(0, 1); | |
Console.Write(" "); | |
Console.SetCursorPosition(0, 2); | |
Console.Write(" "); | |
Console.SetCursorPosition(0, 0); | |
//Bot Logic | |
if ((c1.R > 240 && c1.G > 90) && (c2.R > 240 && c2.G > 90)) | |
{ | |
Console.Write("RED"); | |
Console.SetCursorPosition(0, 1); | |
if (c3.R + c5.R + c7.R + c3.G + c5.G + c7.G < c4.R + c6.R + c8.R + c4.G + c6.G + c8.G) | |
{ | |
sendLeft(); | |
Console.Write("Left"); | |
} | |
else | |
{ | |
sendRight(); | |
Console.Write("Right"); | |
} | |
} | |
else | |
{ | |
if (isBlack(c2) || isBlack(c1)) | |
{ | |
sendOk(); | |
Console.SetCursorPosition(0, 2); | |
Console.Write("RESPAWN ?"); | |
} | |
} | |
Thread.Sleep(50); | |
} | |
} | |
catch(IndexOutOfRangeException) | |
{ | |
Console.WriteLine("Game not started !"); | |
Console.ReadLine(); | |
} | |
catch(Exception ex) | |
{ | |
Console.WriteLine(ex); | |
Console.ReadLine(); | |
} | |
} | |
static void sendLeft() | |
{ | |
PostMessage(proc.MainWindowHandle, WM_KEYUP, VK_A, 0); | |
PostMessage(proc.MainWindowHandle, WM_KEYDOWN, VK_A, 0xC14B0001); | |
} | |
static void sendRight() | |
{ | |
PostMessage(proc.MainWindowHandle, WM_KEYDOWN, VK_D, 0); | |
PostMessage(proc.MainWindowHandle, WM_KEYUP, VK_D, 0xC14B0001); | |
} | |
static void sendOk() | |
{ | |
PostMessage(proc.MainWindowHandle, WM_KEYDOWN, VK_E, 0); | |
PostMessage(proc.MainWindowHandle, WM_KEYUP, VK_E, 0xC14B0001); | |
} | |
static bool isBlack(Color c) | |
{ | |
if(c.R + c.G + c.B < 10) | |
{ | |
return true; | |
} | |
return false; | |
} | |
static Color GetPixelColor(int x, int y) | |
{ | |
//IntPtr hdc = GetDC(IntPtr.Zero); | |
IntPtr hdc = GetWindowDC(proc.MainWindowHandle); | |
uint pixel = GetPixel(hdc, x, y); | |
ReleaseDC(IntPtr.Zero, hdc); | |
Color color = Color.FromArgb((int)(pixel & 0x000000FF), | |
(int)(pixel & 0x0000FF00) >> 8, | |
(int)(pixel & 0x00FF0000) >> 16); | |
return color; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment