Suppenbiatch

CSGO Auto Accept V0.04

Mar 20th, 2020
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.86 KB | None | 0 0
  1. from time import time
  2. from datetime import datetime
  3. from playsound import playsound
  4. from PIL import Image, ImageChops, ImageGrab
  5. from pushbullet import PushBullet
  6. import configparser
  7. import win32api
  8. import win32con
  9. import win32gui
  10. import operator
  11.  
  12.  
  13. def Avg(lst):
  14.     return sum(lst) / len(lst)
  15.  
  16.  
  17. def enum_cb(hwnd, results):
  18.     winlist.append((hwnd, win32gui.GetWindowText(hwnd)))
  19.  
  20.  
  21. def compare_list(l1, l2, relate=operator.le):
  22.     if not l1:
  23.         return False
  24.     l3 = []
  25.     for i, val in enumerate(l1, start=0):
  26.         l3.append(relate(val, l2[i]))
  27.     return all(l3)
  28.  
  29.  
  30. def color_average(image, x1, y1, x2, y2, compare_images=True, org_image=0):
  31.     average = []
  32.     r, g, b = [], [], []
  33.     if compare_images:
  34.         data = ImageChops.difference(org_image, image).getdata()
  35.     else:
  36.         data = image.getdata()
  37.     for y in range(y1, y2 + 1):
  38.         for x in range(x1, x2 + 1):
  39.             r.append(data[y * 2560 + x][0])
  40.             g.append(data[y * 2560 + x][1])
  41.             b.append(data[y * 2560 + x][2])
  42.     average.append(Avg(r))
  43.     average.append(Avg(g))
  44.     average.append(Avg(b))
  45.     return average
  46.  
  47.  
  48. def getScreenShot(window_id):
  49.     win32gui.ShowWindow(window_id, win32con.SW_MAXIMIZE)
  50.     try:
  51.         bbox = win32gui.GetWindowRect(window_id)
  52.     except pywintypes.error:
  53.         return 0
  54.     image = ImageGrab.grab(bbox)
  55.     if not image:
  56.         return 0
  57.     i_width, i_height = image.size
  58.     if i_width != 2650 and i_height != 1440:
  59.         image = image.resize([2560, 1440])
  60.     return image
  61.  
  62.  
  63. def click(x, y):
  64.     win32api.SetCursorPos((x, y))
  65.     win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0)
  66.     win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0)
  67.  
  68.  
  69. def push_note(message):
  70.     push = str(datetime.now().strftime("%H:%M:%S")) + "    " + str(message)
  71.     device.push_note("CSGO AUTO ACCEPT", push)
  72.  
  73.  
  74. def write(message, pushing=False):
  75.     print(datetime.now().strftime("%H:%M:%S") + "    " + message)
  76.     if pushing:
  77.         device.push_note("CSGO AUTO ACCEPT", str(datetime.now().strftime("%H:%M:%S")) + "    " + str(message))
  78.  
  79.  
  80. screen_width, screen_height = win32api.GetSystemMetrics(0), win32api.GetSystemMetrics(1)
  81. toplist, winlist = [], []
  82. hwnd = 0
  83.  
  84. test_for_live_game, test_for_success, debugging, push_active = False, False, False, False
  85. accept_avg = []
  86.  
  87. img_accept = Image.open("images/accept.jpg")
  88. img_not_searching = Image.open("images/not_searching.jpg")
  89. start_time = time()
  90. write("Ready")
  91.  
  92. while True:
  93.     if win32api.GetAsyncKeyState(0x78) & 1:  # F9 (ACTIVATE / DEACTIVATE SCRIPT)
  94.         test_for_live_game = not test_for_live_game
  95.         write("TESTING: %s" % test_for_live_game)
  96.         accept_avg = []
  97.         if test_for_live_game:
  98.             playsound('sounds/activated.mp3')
  99.             time_searching = time()
  100.         else:
  101.             playsound('sounds/deactivated.mp3')
  102.  
  103.     if win32api.GetAsyncKeyState(0x77) & 1:  # F8 (ACTIVATE / DEACTIVATE PUSH NOTIFICATION)
  104.         push_active = not push_active
  105.         write("Pushing: %s" % push_active)
  106.  
  107.         config = configparser.ConfigParser()
  108.         config.read("config.ini")
  109.  
  110.         PushBulletDeviceName = config.get('Pushbullet', 'DeviceName')
  111.         PushBulletAPIKey = config.get('Pushbullet', 'API Key')
  112.         device = PushBullet(PushBulletAPIKey).get_device(PushBulletDeviceName)
  113.  
  114.     if win32api.GetAsyncKeyState(0x76) & 1:  # F7 (DEBUGGING)
  115.         debugging = not debugging
  116.         print("debugging: ", debugging)
  117.  
  118.     if win32api.GetAsyncKeyState(0x24) & 1:  # POS1/HOME Key
  119.         write("Exiting Script")
  120.         break
  121.  
  122.     winlist = []
  123.     win32gui.EnumWindows(enum_cb, toplist)
  124.     csgo = [(hwnd, title) for hwnd, title in winlist if 'counter-strike: global offensive' in title.lower()]
  125.     if not csgo:
  126.         continue
  127.     hwnd = csgo[0][0]
  128.  
  129.     # TESTING HERE
  130.     if win32api.GetAsyncKeyState(0x75) & 1:  # F6, TEST CODE
  131.         write("Executing TestCode")
  132.         test_for_success = not test_for_success
  133.         start_time = time()
  134.  
  135.     # TESTING ENDS HERE
  136.  
  137.     if test_for_live_game:
  138.         if time() - start_time < 4:
  139.             continue
  140.         start_time = time()
  141.         img = getScreenShot(hwnd)
  142.         if not img:
  143.             continue
  144.         accept_avg = color_average(img, 1265, 760, 1295, 785, org_image=img_accept)
  145.  
  146.         if debugging:
  147.             print("Avg: ", accept_avg)
  148.             print(time() - start_time)
  149.  
  150.     if compare_list(accept_avg, [15, 30, 15]):
  151.         write("Trying to Accept", push_active)
  152.  
  153.         test_for_success = True
  154.         test_for_live_game = False
  155.         accept_avg = []
  156.  
  157.         for _ in range(5):
  158.             click(int(screen_width / 2), int(screen_height / 1.78))
  159.             # sleep(0.5)
  160.             # pass
  161.            
  162.         write("Trying to catch a loading map")
  163.         playsound('sounds/accept_found.mp3')
  164.         start_time = time()
  165.  
  166.     if test_for_success:
  167.         if time() - start_time < 40:
  168.             img = getScreenShot(hwnd)
  169.             success_avg = color_average(img, 467, 1409, 1300, 1417, compare_images=False)
  170.  
  171.             searching_avg = color_average(img, 2435, 55, 2550, 100, org_image=img_accept)
  172.             not_searching_avg = color_average(img, 2435, 55, 2550, 100, org_image=img_not_searching)
  173.             solo_not_searching_avg = color_average(img, 2435, 115, 2555, 135, org_image=img_not_searching)
  174.             no_success_truth = [compare_list(searching_avg, [0.7, 12, 10]), compare_list(not_searching_avg, [8, 9, 9]), compare_list(solo_not_searching_avg, [1, 1.5, 2])]
  175.  
  176.             if compare_list(success_avg, [17, 100, 150], relate=operator.ge):
  177.                 write("Game should have started", push_active)
  178.                 took_for_accept = round(time() - start_time, 2)
  179.                 took_for_searching = str(round(time() - time_searching, 2))
  180.                 print("Took %s s since pressing accept." % took_for_accept)
  181.                 print("Took %s s since trying to find a game." % took_for_searching)
  182.                 test_for_success = False
  183.                 playsound('sounds/done_testing.mp3')
  184.  
  185.             if any(no_success_truth):
  186.                 write("Game doesnt seem to have started. Continuing to search for accept Button!", push_active)
  187.                 # write("Searching again: "+str(no_success_truth[0]))
  188.                 print("Took: ", round(time() - start_time, 2))
  189.                 playsound('sounds/back_to_testing.mp3')
  190.                 test_for_success = False
  191.                 test_for_live_game = True
  192.                 time_searching = time()
  193.         else:
  194.             write("Unknown Error")
  195.             test_for_success = False
  196.             print(success_avg)
  197.             print(searching_avg)
  198.             print(not_searching_avg)
  199.             print(solo_not_searching_avg)
  200.             img.save("Unknown Error.png")
  201.             playsound('sounds/fail.mp3')
Add Comment
Please, Sign In to add comment