Suppenbiatch

CSGO Auto Accept [success checker] V0.03

Mar 17th, 2020
550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.87 KB | None | 0 0
  1. from time import sleep, time
  2. from datetime import datetime
  3. from playsound import playsound
  4. import win32api
  5. import win32con
  6. import win32gui
  7. from PIL import Image, ImageChops, ImageGrab
  8. import operator
  9.  
  10.  
  11. def Avg(lst):
  12.     return sum(lst) / len(lst)
  13.  
  14.  
  15. def enum_cb(hwnd, results):
  16.     winlist.append((hwnd, win32gui.GetWindowText(hwnd)))
  17.  
  18.  
  19. def color_average(img, x1, y1, x2, y2):
  20.     average = []
  21.     r, g, b = [], [], []
  22.     data = img.getdata()
  23.     for y in range(y1, y2 + 1):
  24.         for x in range(x1, x2 + 1):
  25.             r.append(data[y * 2560 + x][0])
  26.             g.append(data[y * 2560 + x][1])
  27.             b.append(data[y * 2560 + x][2])
  28.     average.append(Avg(r))
  29.     average.append(Avg(g))
  30.     average.append(Avg(b))
  31.     return average
  32.  
  33.  
  34. def compare_list(l1, l2, relate):
  35.     if not l1:
  36.         return False
  37.     l3 = []
  38.     for i, val in enumerate(l1, start=0):
  39.         l3.append(relate(val, l2[i]))
  40.     return all(l3)
  41.  
  42.  
  43. def getScreenShot(hwnd):
  44.     win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE)
  45.     try:
  46.         bbox = win32gui.GetWindowRect(hwnd)
  47.     except pywintypes.error:
  48.         return 0
  49.     image = ImageGrab.grab(bbox)
  50.     i_width, i_height = image.size
  51.     if i_width != 2650 and i_height != 1440:
  52.         image = image.resize([2560, 1440])
  53.     return image
  54.  
  55.  
  56. def click(x, y):
  57.     win32api.SetCursorPos((x, y))
  58.     win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0)
  59.     win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0)
  60.  
  61.  
  62. screen_width, screen_height = win32api.GetSystemMetrics(0), win32api.GetSystemMetrics(1)
  63. toplist, winlist = [], []
  64. hwnd = 0
  65. test_for_live_game, test_for_success, debugging = False, False, False
  66. accept_avg, success_avg = [], []
  67. img_acc = Image.open("accept.jpg")
  68. start_time = time()
  69. print(datetime.now().strftime("%H:%M:%S"), "    Ready")
  70.  
  71. while True:
  72.     if win32api.GetAsyncKeyState(0x78) & 1:  # F9
  73.         test_for_live_game = not test_for_live_game
  74.         print(datetime.now().strftime("%H:%M:%S"), "    TESTING: ", test_for_live_game)
  75.         if test_for_live_game:
  76.             playsound('active.mp3')
  77.         else:
  78.             playsound('deactivated.mp3')
  79.  
  80.     if win32api.GetAsyncKeyState(0x77) & 1:  # F8 (DEBUGGING)
  81.         try:
  82.             print("Avg: ", accept_avg)
  83.         except NameError:
  84.             continue
  85.         img_difference.show()
  86.         img_difference.save("dif.png")
  87.  
  88.     if win32api.GetAsyncKeyState(0x76) & 1:  # F7 (DEBUGGING)
  89.         debugging = not debugging
  90.         print("debugging: ", debugging)
  91.  
  92.     if win32api.GetAsyncKeyState(0x75) & 1:  # F6 (DEBUGGING)
  93.         #test_for_success = True
  94.         #start_time = time()
  95.         print("debugging: test_for_success:")
  96.  
  97.     if win32api.GetAsyncKeyState(0x24) & 1:  # POS1/HOME Key
  98.         print(datetime.now().strftime("%H:%M:%S"), "    Exiting Script")
  99.         break
  100.  
  101.     winlist = []
  102.     win32gui.EnumWindows(enum_cb, toplist)
  103.     csgo = [(hwnd, title) for hwnd, title in winlist if 'counter-strike: global offensive' in title.lower()]
  104.     if not csgo:
  105.         continue
  106.     hwnd = csgo[0][0]
  107.  
  108.     if test_for_live_game:
  109.         if time() - start_time < 4:
  110.             continue
  111.         start_time = time()
  112.  
  113.         img = getScreenShot(hwnd)
  114.         if not img:
  115.             continue
  116.         img_difference = ImageChops.difference(img_acc, img)
  117.         accept_avg = color_average(img_difference, 1265, 760, 1295, 785)
  118.  
  119.         if debugging:
  120.             print("Avg: ", accept_avg)
  121.             # img.save("img.png")
  122.             # img_difference.save("img_dif.png")
  123.  
  124.     if compare_list(accept_avg, [15, 30, 15], operator.le):
  125.         print(datetime.now().strftime("%H:%M:%S"), "    Trying to Accept")
  126.  
  127.         test_for_success = True
  128.         test_for_live_game = False
  129.         start_time = time()
  130.  
  131.         for _ in range(5):
  132.             click(int(screen_width / 2), int(screen_height / 1.78))
  133.             sleep(0.5)
  134.         print(datetime.now().strftime("%H:%M:%S"), "    Trying to catch a loading map")
  135.         # print(accept_avg)
  136.         accept_avg = []
  137.         # img.save("img_acc.png")
  138.         playsound('beep.mp3')
  139.  
  140.     if test_for_success:
  141.         if time() - start_time < 30:
  142.             img = getScreenShot(hwnd)
  143.             success_avg = color_average(img, 467, 1409, 1300, 1417)
  144.             if compare_list(success_avg, [17, 100, 150], operator.ge):
  145.                 print(datetime.now().strftime("%H:%M:%S"), "    Game should have started")
  146.                 print("Took: ", time() - start_time)
  147.                 test_for_success = False
  148.                 # img.save("img_start.png")
  149.                 playsound('2beep.mp3')
  150.         else:
  151.             print(datetime.now().strftime("%H:%M:%S"), "    Game doesnt seem to have started. Continuing to search for accept Button")
  152.             test_for_success = False
  153.             test_for_live_game = True
  154.             playsound('nope.mp3')
Add Comment
Please, Sign In to add comment