├── .gitattributes ├── directKeys.py └── main.py /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /directKeys.py: -------------------------------------------------------------------------------- 1 | import ctypes 2 | import time 3 | 4 | SendInput = ctypes.windll.user32.SendInput 5 | 6 | W = 0x11 7 | A = 0x1E 8 | S = 0x1F 9 | D = 0x20 10 | M = 0x32 11 | K = 0x25 12 | 13 | # C struct redefinitions 14 | PUL = ctypes.POINTER(ctypes.c_ulong) 15 | 16 | 17 | class KeyBdInput(ctypes.Structure): 18 | _fields_ = [("wVk", ctypes.c_ushort), 19 | ("wScan", ctypes.c_ushort), 20 | ("dwFlags", ctypes.c_ulong), 21 | ("time", ctypes.c_ulong), 22 | ("dwExtraInfo", PUL)] 23 | 24 | 25 | class HardwareInput(ctypes.Structure): 26 | _fields_ = [("uMsg", ctypes.c_ulong), 27 | ("wParamL", ctypes.c_short), 28 | ("wParamH", ctypes.c_ushort)] 29 | 30 | 31 | class MouseInput(ctypes.Structure): 32 | _fields_ = [("dx", ctypes.c_long), 33 | ("dy", ctypes.c_long), 34 | ("mouseData", ctypes.c_ulong), 35 | ("dwFlags", ctypes.c_ulong), 36 | ("time", ctypes.c_ulong), 37 | ("dwExtraInfo", PUL)] 38 | 39 | 40 | class Input_I(ctypes.Union): 41 | _fields_ = [("ki", KeyBdInput), 42 | ("mi", MouseInput), 43 | ("hi", HardwareInput)] 44 | 45 | 46 | class Input(ctypes.Structure): 47 | _fields_ = [("type", ctypes.c_ulong), 48 | ("ii", Input_I)] 49 | 50 | 51 | from ctypes import windll, Structure, c_long, byref 52 | 53 | 54 | class POINT(Structure): 55 | _fields_ = [("x", c_long), ("y", c_long)] 56 | 57 | 58 | def queryMousePosition(): 59 | pt = POINT() 60 | windll.user32.GetCursorPos(byref(pt)) 61 | return pt 62 | # return { "x": pt.x, "y": pt.y}/ 63 | 64 | 65 | 66 | 67 | 68 | def click(x, y): 69 | # convert to ctypes pixels 70 | # x = int(x * 0.666) 71 | # y = int(y * 0.666) 72 | ctypes.windll.user32.SetCursorPos(x, y) 73 | ctypes.windll.user32.mouse_event(2, 0, 0, 0, 0) # left down 74 | ctypes.windll.user32.mouse_event(4, 0, 0, 0, 0) # left up 75 | 76 | 77 | def moveMouseTo(x, y): 78 | # convert to ctypes pixels 79 | # x = int(x * 0.666) 80 | # y = int(y * 0.666) 81 | print(x, y) 82 | ctypes.windll.user32.SetCursorPos(x, y) 83 | # ctypes.windll.user32.mouse_event(2, 0, 0, 0, 0) # left down 84 | # ctypes.windll.user32.mouse_event(4, 0, 0, 0, 0) # left up 85 | 86 | 87 | def PressKey(hexKeyCode): 88 | extra = ctypes.c_ulong(0) 89 | ii_ = Input_I() 90 | ii_.ki = KeyBdInput(0, hexKeyCode, 0x0008, 0, ctypes.pointer(extra)) 91 | x = Input(ctypes.c_ulong(1), ii_) 92 | ctypes.windll.user32.SendInput(1, ctypes.pointer(x), ctypes.sizeof(x)) 93 | 94 | 95 | def ReleaseKey(hexKeyCode): 96 | extra = ctypes.c_ulong(0) 97 | ii_ = Input_I() 98 | ii_.ki = KeyBdInput(0, hexKeyCode, 0x0008 | 0x0002, 0, ctypes.pointer(extra)) 99 | x = Input(ctypes.c_ulong(1), ii_) 100 | ctypes.windll.user32.SendInput(1, ctypes.pointer(x), ctypes.sizeof(x)) 101 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from PIL import ImageGrab 3 | import cv2 4 | from directKeys import click, queryMousePosition 5 | import time 6 | 7 | # 8 | # click(1800, 10) 9 | # time.sleep(1) 10 | 11 | # gameCoords = [657, 232, 1262, 1039] 12 | gameCoords = [656, 32, 1222, 1037] 13 | 14 | smallerGameCoords = [657, 800, 1262, 802] 15 | score = 0 16 | previousLane = -1 17 | 18 | 19 | def clickOnFirstBlock(screen): 20 | global gameCoords, score, previousLane 21 | for y_ in range(5, len(screen) - 5, 5): 22 | for i in range(4): 23 | if previousLane == i: 24 | continue 25 | w = gameCoords[2] - gameCoords[0] 26 | x = i * w / 4 + w / 8 27 | y = len(screen) - y_ 28 | if screen[y][x] < 40: 29 | actualX = x + gameCoords[0] 30 | actualY = y + gameCoords[1] 31 | score += 1 32 | if score > 1000: 33 | actualY += 10 34 | if score > 1250: 35 | actualY += 10 36 | if score > 1450: 37 | actualY += 10 38 | if score > 1600: 39 | actualY += 20 40 | for k in range(1700, 2500): 41 | if score > k: 42 | actualY += 10 43 | else: 44 | break 45 | click(actualX, actualY) 46 | previousLane = i 47 | 48 | return 49 | # previousLane = -1 50 | 51 | 52 | while True: 53 | mousePos = queryMousePosition() 54 | if mousePos.x < 0: 55 | break 56 | 57 | while True: 58 | 59 | mousePos = queryMousePosition() 60 | 61 | if gameCoords[2] > mousePos.x > gameCoords[0]: 62 | startTime = time.time() 63 | screen = np.array(ImageGrab.grab(bbox=gameCoords)) 64 | screen = cv2.cvtColor(screen, cv2.COLOR_BGR2GRAY) 65 | clickOnFirstBlock(screen) 66 | print("Frame took {} seconds. Up to frame no {}".format((time.time() - startTime), "FUCK YOU")) 67 | else: 68 | if mousePos.x < 0: 69 | score = 0 70 | while True: 71 | mousePos = queryMousePosition() 72 | if gameCoords[2] < mousePos.x: 73 | break 74 | --------------------------------------------------------------------------------