Suppenbiatch

CSGO AUTO ACCEPT V1.3.6

Apr 27th, 2020
3,476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 34.58 KB | None | 0 0
  1. import configparser
  2. import operator
  3. import os
  4. import re
  5. from shutil import copyfile
  6. import sys
  7. import time
  8. import webbrowser
  9. import winreg
  10. from datetime import datetime, timedelta
  11.  
  12. import pushbullet
  13. import pyperclip
  14. import pytesseract
  15. import requests
  16. import win32api
  17. import win32con
  18. import win32gui
  19. from GSI import server
  20. from PIL import ImageGrab, Image
  21. from playsound import playsound
  22.  
  23.  
  24. def Avg(lst: list):
  25.     if not lst:
  26.         return 0
  27.     return sum(lst) / len(lst)
  28.  
  29.  
  30. # noinspection PyShadowingNames,PyUnusedLocal
  31. def enum_cb(hwnd, results):
  32.     winlist.append((hwnd, win32gui.GetWindowText(hwnd)))
  33.  
  34.  
  35. def mute_csgo(lvl: int):
  36.     os.system(mute_csgo_path + str(lvl))
  37.  
  38.  
  39. # noinspection PyShadowingNames
  40. def write(message, add_time: bool = True, push: int = 0, push_now: bool = False, output: bool = True, overwrite: str = '0'):  # last_overwrite_key_used: 8
  41.     if output:
  42.         message = str(message)
  43.         if add_time:
  44.             message = datetime.now().strftime('%H:%M:%S') + ': ' + message
  45.         global last_printed_line
  46.         splits = last_printed_line.split(b'**')
  47.         last_key = splits[0]
  48.         last_string = splits[1].strip(b'\n\r')
  49.         last_end = splits[-1]
  50.         if overwrite != '0':
  51.             ending = console_window['suffix']
  52.             if last_key == overwrite.encode():
  53.                 if console_window['isatty']:
  54.                     print(' ' * len(last_string.decode()), end=ending)
  55.                 message = console_window['prefix'] + message
  56.             else:
  57.                 if last_end != b'\n':
  58.                     message = '\n' + message
  59.         else:
  60.             ending = '\n'
  61.             if last_end != b'\n':
  62.                 message = '\n' + message
  63.  
  64.         last_printed_line = (overwrite + '**' + message + '**' + ending).encode()
  65.         print(message, end=ending)
  66.  
  67.     if push >= 3:
  68.         global note
  69.         if message:
  70.             note = note + str(message.strip('\n\r')) + '\n'
  71.         if push_now:
  72.             device.push_note('CSGO AUTO ACCEPT', note)
  73.             note = ''
  74.  
  75.  
  76. # noinspection PyShadowingNames
  77. def click(x: int, y: int):
  78.     win32api.SetCursorPos((x, y))
  79.     win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0)
  80.     win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0)
  81.  
  82.  
  83. # noinspection PyShadowingNames
  84. def relate_list(l_org, compare_list, relate: operator = operator.le):
  85.     if not l_org:
  86.         return False
  87.     truth_list = []
  88.     for list_part in compare_list:
  89.         partial_truth = []
  90.         for i, val in enumerate(list_part):
  91.             partial_truth.append(relate(l_org[i], val))
  92.         truth_list.append(all(partial_truth))
  93.         l_org = l_org[len(list_part):]
  94.     return any(truth_list)
  95.  
  96.  
  97. # noinspection PyShadowingNames
  98. def color_average(image: Image, compare_list: list):
  99.     average = []
  100.     r, g, b = [], [], []
  101.     data = image.getdata()
  102.     for i in data:
  103.         r.append(i[0])
  104.         g.append(i[1])
  105.         b.append(i[2])
  106.  
  107.     rgb = [Avg(r), Avg(g), Avg(b)] * len(compare_list)
  108.     for part in compare_list:
  109.         for i, val in enumerate(part):
  110.             average.append(val - rgb[i])
  111.     average = list(map(abs, average))
  112.     return average
  113.  
  114.  
  115. # noinspection PyShadowingNames
  116. def getScreenShot(window_id: int, area: tuple = (0, 0, 0, 0)):
  117.     area = list(area)
  118.     win32gui.ShowWindow(window_id, win32con.SW_MAXIMIZE)
  119.     scaled_area = [screen_width / 2560, screen_height / 1440]
  120.     scaled_area = 2 * scaled_area
  121.     for i, _ in enumerate(area[-2:], start=len(area) - 2):
  122.         area[i] += 1
  123.     for i, val in enumerate(area, start=0):
  124.         scaled_area[i] = scaled_area[i] * val
  125.     scaled_area = list(map(int, scaled_area))
  126.     image = ImageGrab.grab(scaled_area)
  127.     return image
  128.  
  129.  
  130. # noinspection PyShadowingNames
  131. def getAccountsFromCfg():
  132.     steam_ids = ''
  133.     global accounts
  134.     for i in config.sections():
  135.         if i.startswith('Account'):
  136.             steam_id = config.get(i, 'Steam ID')
  137.             steam_id_3 = str(int(steam_id) - 76561197960265728)
  138.             auth_code = config.get(i, 'Authentication Code')
  139.             match_token = config.get(i, 'Match Token')
  140.             steam_ids += steam_id + ','
  141.             accounts.append({'steam_id': steam_id, 'steam_id_3': steam_id_3, 'auth_code': auth_code, 'match_token': match_token})
  142.  
  143.     steam_ids = steam_ids.lstrip(',').rstrip(',')
  144.     profiles = requests.get('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' + cfg['steam_api_key'] + '&steamids=' + steam_ids).json()['response']['players']
  145.     name_list = [online_data['personaname'] for local_acc in accounts for online_data in profiles if online_data['steamid'] == local_acc['steam_id']]
  146.     for num, val in enumerate(accounts):
  147.         val['name'] = name_list[num]
  148.  
  149.  
  150. # noinspection PyShadowingNames
  151. def getCsgoPath():
  152.     steam_reg_key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, 'SOFTWARE\WOW6432Node\Valve\Steam')
  153.     steam_path = winreg.QueryValueEx(steam_reg_key, 'InstallPath')[0]
  154.     libraries = [steam_path + '\\steamapps']
  155.     with open(steam_path + '\\steamapps\\libraryfolders.vdf', 'r') as library_file:
  156.         library_data = library_file.readlines()
  157.         compare_str = re.compile('\\t"\d*"\\t\\t"')
  158.         libraries.extend([re.sub(compare_str, "", i.rstrip('"\n')) for i in library_data if bool(re.match(compare_str, i))])
  159.  
  160.     csgo_path = [i for i in libraries if os.path.exists(i + '\\appmanifest_730.acf')][0] + '\\common\\Counter-Strike Global Offensive\\csgo\\'
  161.     if not csgo_path:
  162.         write('DID NOT FIND CSGO PATH', add_time=False)
  163.         exit('LORD PLZ HELP')
  164.     return csgo_path, steam_path
  165.  
  166.  
  167. # noinspection PyShadowingNames
  168. def CheckUserDataAutoExec(steam_id_3: str, csgo_int_path: str, steam_int_path: str):
  169.     userdata_path = steam_int_path + '\\userdata\\' + steam_id_3 + '\\730\\local\\cfg\\'
  170.     str_in_autoexec = ['developer 1', 'con_logfile "console_log.log"', 'con_filter_enable "2"', 'con_filter_text_out "Player:"', 'con_filter_text "Damage"', 'log_color General ' + cfg['log_color']]
  171.     with open(userdata_path + 'autoexec.cfg', 'a+') as autoexec:
  172.         autoexec.seek(0)
  173.         lines = autoexec.readlines()
  174.         for autoexec_str in str_in_autoexec:
  175.             if not any(autoexec_str.lower() in line.rstrip('\n').lower() for line in lines):
  176.                 write('Added %s to "autoexec.cfg" file in %s' % (autoexec_str, userdata_path), add_time=False)
  177.                 write('RESTART Counter-Strike for the script to work', add_time=False)
  178.                 autoexec.write('\n' + autoexec_str + '\n')
  179.     if os.path.exists(csgo_int_path + '\\cfg\\autoexec.cfg'):
  180.         write('YOU HAVE TO DELETE THE "autoexec.cfg" in %s WITH AND MERGE IT WITH THE ONE IN %s' % (csgo_int_path + '\\cfg', userdata_path), add_time=False)
  181.         write('THE SCRIPT WONT WORK UNTIL THERE IS NO "autoexec.cfg" in %s' % csgo_int_path + '\\cfg', add_time=False)
  182.         exit()
  183.  
  184.  
  185. # noinspection PyShadowingNames
  186. def getOldSharecodes(last_x: int = -1, from_x: str = ''):
  187.     if last_x >= 0:
  188.         return []
  189.     try:
  190.         last_game = open(appdata_path+'last_game_' + accounts[current_account]['steam_id'] + '.txt', 'r')
  191.         games = last_game.readlines()
  192.         last_game.close()
  193.     except FileNotFoundError:
  194.         last_game = open(appdata_path+'last_game_' + accounts[current_account]['steam_id'] + '.txt', 'w')
  195.         last_game.write(accounts[current_account]['match_token'] + '\n')
  196.         games = [accounts[current_account]['match_token']]
  197.         last_game.close()
  198.     last_game = open(appdata_path+'last_game_' + accounts[current_account]['steam_id'] + '.txt', 'w')
  199.     games = games[-200:]
  200.     for i, val in enumerate(games):
  201.         games[i] = 'CSGO' + val.strip('\n').split('CSGO')[1]
  202.         last_game.write(games[i] + '\n')
  203.     last_game.close()
  204.     if from_x:
  205.         try:
  206.             return games[(len(games) - games.index(from_x)) * -1:]
  207.         except ValueError:
  208.             return []
  209.     return games[last_x:]
  210.  
  211.  
  212. # noinspection PyShadowingNames
  213. def getNewCSGOSharecodes(game_id: str):
  214.     sharecodes = []
  215.     next_code = game_id
  216.     last_game = open(appdata_path+'last_game_' + accounts[current_account]['steam_id'] + '.txt', 'a')
  217.     while next_code != 'n/a':
  218.         steam_url = 'https://api.steampowered.com/ICSGOPlayers_730/GetNextMatchSharingCode/v1?key=' + cfg['steam_api_key'] + '&steamid=' + accounts[current_account]['steam_id'] + '&steamidkey=' + accounts[current_account][
  219.             'auth_code'] + '&knowncode=' + game_id
  220.         try:
  221.             next_code = (requests.get(steam_url).json()['result']['nextcode'])
  222.         except KeyError:
  223.             write('WRONG Match Token, Authentication Code or Steam ID ')
  224.             return [{'sharecode': game_id, 'queue_pos': None}]
  225.  
  226.         if next_code:
  227.             if next_code != 'n/a':
  228.                 sharecodes.append(next_code)
  229.                 game_id = next_code
  230.                 last_game.write(next_code + '\n')
  231.     last_game.close()
  232.     return [{'sharecode': code, 'queue_pos': None} for code in sharecodes]
  233.  
  234.  
  235. # noinspection PyShadowingNames
  236. def UpdateCSGOstats(repeater=None, get_all_games=False):
  237.     all_games, completed_games, not_completed_games, = [], [], []
  238.  
  239.     if repeater is None:
  240.         repeater = []
  241.     if repeater:
  242.         if get_all_games:
  243.             sharecodes = [getOldSharecodes(from_x=code['sharecode']) for code in repeater]
  244.             sharecodes = max(sharecodes, key=len)
  245.         else:
  246.             sharecodes = [code['sharecode'] for code in repeater]
  247.         all_games = [requests.post('https://csgostats.gg/match/upload/ajax', data={'sharecode': sharecode, 'index': '1'}).json() for sharecode in sharecodes]
  248.     else:
  249.         num = -1
  250.         sharecode = getOldSharecodes(num)[0]
  251.         while True:
  252.             response = requests.post('https://csgostats.gg/match/upload/ajax', data={'sharecode': sharecode, 'index': '1'})
  253.             all_games.append(response.json())
  254.             if response.json()['status'] != 'complete':
  255.                 num -= 1
  256.                 try:
  257.                     sharecode = getOldSharecodes(num)[0]
  258.                 except IndexError:
  259.                     break
  260.             else:
  261.                 break
  262.         temp_games = [{'sharecode': game['data']['sharecode']} for game in all_games if game['status'] != 'complete']
  263.         if temp_games and len(all_games) > 1:
  264.             all_games = all_games[:-1]
  265.  
  266.     for game in all_games:
  267.         if game['status'] == 'complete':
  268.             completed_games.append(game)
  269.         else:
  270.             not_completed_games.append(game)
  271.  
  272.     queued_games = [{'sharecode': game['data']['sharecode'], 'queue_pos': game['data']['queue_pos']} for game in not_completed_games if game['status'] != 'error']
  273.     corrupt_games = [{'sharecode': game['data']['sharecode'], 'queue_pos': None} for game in not_completed_games if game['status'] == 'error']
  274.  
  275.     global queue_difference, time_table
  276.     if queued_games:
  277.         temp_string = ''
  278.         for i, val in enumerate(queued_games):
  279.             temp_string += '#' + str(i + 1) + ': in Queue #' + str(val['queue_pos']) + ' - '
  280.  
  281.         if repeater:
  282.             current_queue_difference = Avg([last_game['queue_pos'] - game['queue_pos'] for game in queued_games for last_game in repeater if last_game['sharecode'] == game['sharecode'] and last_game['queue_pos'] is not None])
  283.             if current_queue_difference:
  284.                 queue_difference.append(current_queue_difference / ((time.time() - time_table['time_since_retry']) / 60))
  285.                 queue_difference = queue_difference[-10:]
  286.                 matches_per_min = round(Avg(queue_difference), 1)
  287.                 if matches_per_min != 0.0:
  288.                     time_till_done = str(timedelta(seconds=int((queued_games[0]['queue_pos'] / matches_per_min) * 60)))
  289.                 else:
  290.                     time_till_done = 'โˆž:โˆž:โˆž'
  291.                 temp_string += str(matches_per_min) + ' matches/min - #1 done in ' + time_till_done
  292.         temp_string = temp_string.rstrip(' - ')
  293.         write(temp_string, add_time=False, overwrite='4')
  294.  
  295.     time_table['time_since_retry'] = time.time()
  296.     repeater = [game for game in queued_games if game['queue_pos'] < cfg['max_queue_position']]
  297.     repeater.extend([game for game in corrupt_games])
  298.  
  299.     if corrupt_games:
  300.         write('An error occurred in %s game[s].' % len(corrupt_games), overwrite='5')
  301.  
  302.     if completed_games:
  303.         for i in completed_games:
  304.             sharecode = i['data']['sharecode']
  305.             game_url = i['data']['url']
  306.             info = ' '.join(i['data']['msg'].replace('-', '').replace('<br />', '. ').split('<')[0].rstrip(' ').split())
  307.             write('Sharecode: %s' % sharecode, add_time=False, push=push_urgency)
  308.             write('URL: %s' % game_url, add_time=False, push=push_urgency)
  309.             write('Status: %s.' % info, add_time=True, push=push_urgency)
  310.             pyperclip.copy(game_url)
  311.         write(None, add_time=False, push=push_urgency, push_now=True, output=False)
  312.     return repeater
  313.  
  314.  
  315. # noinspection PyShadowingNames,PyUnusedLocal
  316. def Image_to_Text(image: Image, size: tuple, white_threshold: tuple, arg: str = ''):
  317.     image_data = image.getdata()
  318.     pixel_map, image_text = [], ''
  319.     for y in range(size[1]):
  320.         for x in range(size[0]):
  321.             if relate_list(image_data[y * size[0] + x], [white_threshold], relate=operator.ge):
  322.                 pixel_map.append((0, 0, 0))
  323.             else:
  324.                 pixel_map.append((255, 255, 255))
  325.     temp_image = Image.new('RGB', (size[0], size[1]))
  326.     temp_image.putdata(pixel_map)
  327.     try:
  328.         image_text = pytesseract.image_to_string(temp_image, timeout=0.3, config=arg)
  329.     except RuntimeError:
  330.         # as timeout_error:
  331.         pass
  332.     if image_text:
  333.         image_text = ' '.join(image_text.replace(': ', ':').split())
  334.         global truth_table
  335.         if truth_table['debugging']:
  336.             image.save(str(cfg['debug_path']) + '\\' + datetime.now().strftime('%H-%M-%S') + '_' + image_text.replace(':', '-') + '.png', format='PNG')
  337.             temp_image.save(str(cfg['debug_path']) + '\\' + datetime.now().strftime('%H-%M-%S') + '_' + image_text.replace(':', '-') + '_temp.png', format='PNG')
  338.         return image_text
  339.     else:
  340.         return ''
  341.  
  342.  
  343. def getCfgData():
  344.     try:
  345.         get_cfg = {'activate_script': int(config.get('HotKeys', 'Activate Script'), 16), 'activate_push_notification': int(config.get('HotKeys', 'Activate Push Notification'), 16),
  346.                    'info_newest_match': int(config.get('HotKeys', 'Get Info on newest Match'), 16), 'mute_csgo_toggle': int(config.get('HotKeys', 'Mute CSGO'), 16),
  347.                    'open_live_tab': int(config.get('HotKeys', 'Live Tab Key'), 16), 'switch_accounts': int(config.get('HotKeys', 'Switch accounts for csgostats.gg'), 16),
  348.                    'end_script': int(config.get('HotKeys', 'End Script'), 16), 'stop_warmup_ocr': config.get('HotKeys', 'Stop Warmup OCR'), 'freezetime_test': int(config.get('HotKeys', 'FreezeTime Signaler'), 16),
  349.                    'screenshot_interval': float(config.get('Screenshot', 'Interval')), 'timeout_time': config.getint('Screenshot', 'Timeout Time'), 'debug_path': config.get('Screenshot', 'Debug Path'), 'steam_api_key': config.get('csgostats.gg', 'API Key'),
  350.                    'max_queue_position': config.getint('csgostats.gg', 'Auto-Retrying for queue position below'), 'log_color': config.get('Screenshot', 'Log Color').lower(),
  351.                    'auto_retry_interval': config.getint('csgostats.gg', 'Auto-Retrying-Interval'), 'pushbullet_device_name': config.get('Pushbullet', 'Device Name'), 'pushbullet_api_key': config.get('Pushbullet', 'API Key'),
  352.                    'tesseract_path': config.get('Warmup', 'Tesseract Path'), 'warmup_test_interval': config.getint('Warmup', 'Test Interval'), 'warmup_push_interval': config.get('Warmup', 'Push Interval'),
  353.                    'warmup_no_text_limit': config.getint('Warmup', 'No Text Limit'), 'freezetime_auto_on': config.getboolean('Screenshot', 'FreezeTime Signaler Auto-On')}
  354.         return get_cfg
  355.         # 'imgur_id': config.get('Imgur', 'Client ID'), 'imgur_secret': config.get('Imgur', 'Client Secret'), 'info_multiple_matches': int(config.get('HotKeys', 'Get Info on multiple Matches'), 16),
  356.     except (configparser.NoOptionError, configparser.NoSectionError, ValueError):
  357.         write('ERROR IN CONFIG')
  358.         exit('CHECK FOR NEW CONFIG')
  359.  
  360.  
  361. # OVERWRITE SETUP
  362. appdata_path = os.getenv('APPDATA') + '\\CSGO AUTO ACCEPT\\'
  363. try:
  364.     os.mkdir(appdata_path)
  365. except FileExistsError:
  366.     pass
  367. last_printed_line = b'0**\n'
  368. console_window = {}
  369. if not sys.stdout.isatty():
  370.     console_window = {'prefix': '\r', 'suffix': '', 'isatty': False}
  371. else:
  372.     console_window = {'prefix': '', 'suffix': '\r', 'isatty': True}
  373.  
  374. # CONFIG HANDLING
  375. config = configparser.ConfigParser()
  376. config.read('config.ini')
  377. cfg = getCfgData()
  378. cfg['timeout_time'] = int(cfg['timeout_time'] / cfg['screenshot_interval'])
  379. cfg['stop_warmup_ocr'] = [int(i, 16) for i in cfg['stop_warmup_ocr'].split('-')]
  380. cfg['stop_warmup_ocr'][1] += 1
  381. device = 0
  382.  
  383. # ACCOUNT HANDLING, GETTING ACCOUNT NAME, GETTING CSGO PATH, CHECKING AUTOEXEC
  384. accounts, current_account = [], 0
  385. getAccountsFromCfg()
  386. csgo_path, steam_path = getCsgoPath()
  387. CheckUserDataAutoExec(accounts[current_account]['steam_id_3'], csgo_path, steam_path)
  388. match_reservation = 'Matchmaking reservation confirmed: '
  389. with open(csgo_path + 'console_log.log', 'w') as log:
  390.     log.write('')
  391. with open(cfg['debug_path'] + '\\console.log', 'w') as debug_log:
  392.     debug_log.write('')
  393.  
  394. if not os.path.exists(csgo_path + 'cfg\\gamestate_integration_GSI.cfg'):
  395.     copyfile(os.path.join(os.getcwd(), 'GSI') + '\\gamestate_integration_GSI.cfg', csgo_path + 'cfg\\gamestate_integration_GSI.cfg')
  396.     write('Added GSI CONFIG to cfg folder. Counter-Strike needs to be restarted if running!')
  397. gsi_server = server.GSIServer(('127.0.0.1', 3000), "IDONTUSEATOKEN")
  398.  
  399. # INITIALIZATION FOR getScreenShot
  400. screen_width, screen_height = win32api.GetSystemMetrics(0), win32api.GetSystemMetrics(1)
  401. hwnd = 0
  402. toplist, csgo = [], []
  403.  
  404. # BOOLEAN, TIME INITIALIZATION
  405. truth_table = {'test_for_accept_button': False, 'test_for_success': False, 'test_for_warmup': False, 'first_ocr': True, 'testing': False, 'debugging': False, 'first_push': True, 'still_in_warmup': False, 'test_for_server': False, 'test_for_freezetime': False, 'first_freezetime': True, 'gsi_server_running': False}
  406. time_table = {'screenshot_time': time.time(), 'time_since_retry': time.time(), 'warmup_test_timer': time.time(), 'time_searching': time.time(), 'not_searching_cc': time.time(), 'searching_cc': time.time(), 'freezetime_time': time.time()}
  407. test_for_accept_counter = 0
  408. if cfg['freezetime_auto_on']:
  409.     truth_table['test_for_freezetime'] = True
  410.  
  411. # csgostats.gg VAR
  412. retryer = []
  413.  
  414. # WARMUP DETECTION SETUP
  415. pytesseract.pytesseract.tesseract_cmd = cfg['tesseract_path']
  416. no_text_found, push_counter = 0, 0
  417. push_times = [int(i) for i in cfg['warmup_push_interval'].split(',')]
  418. push_times.sort(reverse=True)
  419. join_warmup_time = push_times[0] + 1
  420.  
  421. # PUSHBULLET VAR
  422. note = ''
  423. push_urgency = 0
  424.  
  425. # MUTE CSGO PATH
  426. mute_csgo_path = '"' + os.getcwd() + '\\sounds\\nircmdc.exe" muteappvolume csgo.exe '
  427. mute_csgo(0)
  428.  
  429. write('READY')
  430. write('Current account is: %s\n' % accounts[current_account]['name'], add_time=False)
  431.  
  432.  
  433. while True:
  434.     if win32api.GetAsyncKeyState(cfg['activate_script']) & 1:  # F9 (ACTIVATE / DEACTIVATE SCRIPT)
  435.         truth_table['test_for_server'] = not truth_table['test_for_server']
  436.         write('TESTING: %s' % truth_table['test_for_server'], overwrite='1')
  437.         if truth_table['test_for_server']:
  438.             playsound('sounds/activated_2.mp3')
  439.             time_table['time_searching'] = time.time()
  440.             mute_csgo(1)
  441.         else:
  442.             playsound('sounds/deactivated.mp3')
  443.             mute_csgo(0)
  444.  
  445.     if win32api.GetAsyncKeyState(cfg['activate_push_notification']) & 1:  # F8 (ACTIVATE / DEACTIVATE PUSH NOTIFICATION)
  446.         if not device:
  447.             try:
  448.                 device = pushbullet.PushBullet(cfg['pushbullet_api_key']).get_device(cfg['pushbullet_device_name'])
  449.             except (pushbullet.errors.PushbulletError, pushbullet.errors.InvalidKeyError):
  450.                 write('Pushbullet is wrongly configured.\nWrong API Key or DeviceName in config.ini')
  451.         if device:
  452.             push_urgency += 1
  453.             if push_urgency > 3:
  454.                 push_urgency = 0
  455.             push_info = ['not active', 'only if accepted', 'all game status related information', 'all information (game status/csgostats.gg information)']
  456.             write('Pushing: %s' % push_info[push_urgency], overwrite='2')
  457.  
  458.     if win32api.GetAsyncKeyState(cfg['info_newest_match']) & 1:  # F7 Key (UPLOAD NEWEST MATCH)
  459.         write('Uploading / Getting status on newest match')
  460.         queue_difference = []
  461.         new_sharecodes = getNewCSGOSharecodes(getOldSharecodes(-1)[0])
  462.         for new_code in new_sharecodes:
  463.             retryer.append(new_code) if new_code['sharecode'] not in [old_code['sharecode'] for old_code in retryer] else retryer
  464.         retryer = UpdateCSGOstats(retryer, get_all_games=True)
  465.  
  466.     if win32api.GetAsyncKeyState(cfg['open_live_tab']) & 1:  # F13 Key (OPEN WEB BROWSER ON LIVE GAME TAB)
  467.         win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE)
  468.         webbrowser.open_new_tab('https://csgostats.gg/player/' + accounts[current_account]['steam_id'] + '#/live')
  469.         write('new tab opened', add_time=False)
  470.         time.sleep(0.5)
  471.         win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE)
  472.  
  473.     if win32api.GetAsyncKeyState(cfg['switch_accounts']) & 1:  # F15 (SWITCH ACCOUNTS)
  474.         current_account += 1
  475.         if current_account > len(accounts) - 1:
  476.             current_account = 0
  477.         CheckUserDataAutoExec(accounts[current_account]['steam_id_3'], csgo_path, steam_path)
  478.         write('current account is: %s' % accounts[current_account]['name'], add_time=False, overwrite='3')
  479.  
  480.     if win32api.GetAsyncKeyState(cfg['mute_csgo_toggle']) & 1:  # F6 (TOGGLE MUTE CSGO)
  481.         write("MUTE TOGGLED", add_time=False)
  482.         mute_csgo(2)
  483.  
  484.     if win32api.GetAsyncKeyState(cfg['freezetime_test']) & 1:
  485.         truth_table['test_for_freezetime'] = not truth_table['test_for_freezetime']
  486.         truth_table['first_freezetime'] = True
  487.         cfg['freezetime_auto_on'] = truth_table['test_for_freezetime']
  488.         write('Freeze Time Signal: %s' % truth_table['test_for_freezetime'], add_time=False, overwrite='6')
  489.  
  490.     if win32api.GetAsyncKeyState(cfg['end_script']) & 1:  # POS1 (END SCRIPT)
  491.         write('Exiting Script')
  492.         break
  493.  
  494.     if retryer:
  495.         if time.time() - time_table['time_since_retry'] > cfg['auto_retry_interval']:
  496.             retryer = UpdateCSGOstats(retryer)
  497.     winlist = []
  498.     win32gui.EnumWindows(enum_cb, toplist)
  499.     csgo = [(hwnd, title) for hwnd, title in winlist if 'counter-strike: global offensive' in title.lower()]
  500.  
  501.     if not csgo:
  502.         continue
  503.     hwnd = csgo[0][0]
  504.  
  505.     if not truth_table['gsi_server_running']:
  506.         gsi_server.start_server()
  507.         truth_table['gsi_server_running'] = True
  508.         write('CS:GO GSI Server running..', add_time=False)
  509.  
  510.     # TESTING HERE
  511.     if win32api.GetAsyncKeyState(0x6F) & 1:  # UNBOUND, TEST CODE
  512.         # truth_table['debugging'] = not truth_table['debugging']
  513.         time_table['screenshot_time'] = time.time()
  514.         truth_table['test_for_success'] = not truth_table['test_for_success']
  515.         write(truth_table['test_for_success'], add_time=False)
  516.         # truth_table['testing'] = not truth_table['testing']
  517.  
  518.     if truth_table['testing']:
  519.         # time_table['screenshot_time'] = time.time()
  520.         pass
  521.         # print('Took: %s ' % str(timedelta(milliseconds=int(time.time()*1000 - time_table['screenshot_time']*1000))))
  522.     # TESTING ENDS HERE
  523.  
  524.     if truth_table['test_for_server']:
  525.         if time.time() - time_table['searching_cc'] > 0.2:
  526.             time_table['searching_cc'] = time.time()
  527.         else:
  528.             continue
  529.         with open(csgo_path + 'console_log.log', 'rb+') as log:
  530.             log_lines = log.readlines()
  531.             console_line = [line.decode('utf-8', 'ignore').encode("utf-8").rstrip(b'\n\r').decode() for line in log_lines]
  532.             log.seek(0)
  533.             log.truncate()
  534.         with open(cfg['debug_path'] + '\\console.log', 'ab') as debug_log:
  535.             [debug_log.write(i) for i in log_lines]
  536.         server_ready = any(match_reservation in i for i in console_line)
  537.         if server_ready:
  538.             test_for_accept_counter = 0
  539.             write('Server found, starting to look for accept button')
  540.             truth_table['test_for_accept_button'] = True
  541.             # truth_table['test_for_server'] = False
  542.             playsound('sounds/server_found.mp3')
  543.             win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE)
  544.     else:
  545.         if time.time() - time_table['not_searching_cc'] > 20:
  546.             time_table['not_searching_cc'] = time.time()
  547.             with open(csgo_path + 'console_log.log', 'rb+') as log:
  548.                 log_lines = log.readlines()
  549.                 log.seek(0)
  550.                 log.truncate()
  551.             with open(cfg['debug_path'] + '\\console.log', 'ab') as debug_log:
  552.                 [debug_log.write(i) for i in log_lines]
  553.  
  554.     if truth_table['test_for_accept_button']:
  555.         if time.time() - time_table['screenshot_time'] < cfg['screenshot_interval']:
  556.             continue
  557.         time_table['screenshot_time'] = time.time()
  558.         img = getScreenShot(hwnd, (1265, 760, 1295, 785))
  559.         if not img:
  560.             continue
  561.         accept_avg = color_average(img, [(76, 176, 80), (89, 203, 94)])
  562.         mute_csgo(0)
  563.         if relate_list(accept_avg, [(2, 2, 2), (2, 2, 2)]):
  564.             write('Trying to Accept', push=push_urgency + 1)
  565.  
  566.             truth_table['test_for_success'] = True
  567.             truth_table['test_for_accept_button'] = False
  568.             truth_table['test_for_server'] = False
  569.             accept_avg = []
  570.  
  571.             for _ in range(5):
  572.                 click(int(screen_width / 2), int(screen_height / 1.78))
  573.                 pass
  574.  
  575.             write('Trying to catch a loading map')
  576.             playsound('sounds/accept_found.mp3')
  577.             time_table['screenshot_time'] = time.time()
  578.         test_for_accept_counter += 1
  579.         if test_for_accept_counter > cfg['timeout_time']:
  580.             write('NO ACCEPT BUTTON FOUND AFTER %s seconds.' % str(int(cfg['timeout_time']*cfg['screenshot_interval'])))
  581.             write('Continuing to look for ready server.')
  582.             mute_csgo(1)
  583.             playsound('sounds/back_to_testing.mp3')
  584.             truth_table['test_for_accept_button'] = False
  585.  
  586.     if truth_table['test_for_success']:
  587.         if time.time() - time_table['screenshot_time'] < 40:
  588.             img = getScreenShot(hwnd, (2435, 65, 2555, 100))
  589.             not_searching_avg = color_average(img, [(6, 10, 10)])
  590.             searching_avg = color_average(img, [(6, 163, 97), (4, 63, 35)])
  591.  
  592.             not_searching = relate_list(not_searching_avg, [(2, 5, 5)])
  593.             searching = relate_list(searching_avg, [(2.7, 55, 35), (1, 50, 35)])
  594.  
  595.             img = getScreenShot(hwnd, (467, 1409, 1300, 1417))
  596.             success_avg = color_average(img, [(21, 123, 169)])
  597.             success = relate_list(success_avg, [(1, 8, 7)])
  598.  
  599.             if success:
  600.                 write('\tTook %s since pressing accept.' % str(timedelta(seconds=int(time.time() - time_table['screenshot_time']))), add_time=False, push=push_urgency + 1)
  601.                 write('\tTook %s since trying to find a game.' % str(timedelta(seconds=int(time.time() - time_table['time_searching']))), add_time=False, push=push_urgency + 1)
  602.                 write('Game should have started', push=push_urgency + 2, push_now=True)
  603.                 truth_table['test_for_success'] = False
  604.                 truth_table['test_for_warmup'] = True
  605.                 truth_table['test_for_freezetime'] = False
  606.                 playsound('sounds/done_testing.mp3')
  607.                 time_table['warmup_test_timer'] = time.time() + 5
  608.                 continue
  609.  
  610.             if any([searching, not_searching]):
  611.                 write('\tTook: %s ' % str(timedelta(seconds=int(time.time() - time_table['screenshot_time']))), add_time=False, push=push_urgency + 1)
  612.                 write('Game doesnt seem to have started. Continuing to search for a Server!', push=push_urgency + 1, push_now=True)
  613.                 playsound('sounds/back_to_testing.mp3')
  614.                 mute_csgo(1)
  615.                 truth_table['test_for_success'] = False
  616.                 truth_table['test_for_server'] = True
  617.                 continue
  618.  
  619.         else:
  620.             write('40 Seconds after accept, did not find a loading map nor searching queue')
  621.             truth_table['test_for_success'] = False
  622.             # noinspection PyUnboundLocalVariable
  623.             print(success_avg)
  624.             # noinspection PyUnboundLocalVariable
  625.             print(searching_avg)
  626.             # noinspection PyUnboundLocalVariable
  627.             print(not_searching_avg)
  628.             playsound('sounds/fail.mp3')
  629.             # noinspection PyUnboundLocalVariable
  630.             img.save(cfg['debug_path'] + '\\Unknown Error.png')
  631.  
  632.     if truth_table['test_for_freezetime']:
  633.         if time.time() - time_table['freezetime_time'] > 2:
  634.             time_table['freezetime_time'] = time.time()
  635.             game_state = {'map_phase': gsi_server.get_info('map', 'phase'), 'round_phase': gsi_server.get_info('round', 'phase')}
  636.             if truth_table['first_freezetime']:
  637.                 if game_state['map_phase'] == 'live' and game_state['round_phase'] == 'freezetime':
  638.                     truth_table['first_freezetime'] = False
  639.                     write('Freeze Time starting.', overwrite='7')
  640.                     if win32gui.GetWindowPlacement(hwnd)[1] == 2:
  641.                         playsound('sounds/ready_up.mp3')
  642.             else:
  643.                 if game_state['map_phase'] == 'live' and game_state['round_phase'] != 'freezetime':
  644.                     truth_table['first_freezetime'] = True
  645.  
  646.     if truth_table['still_in_warmup']:
  647.         if time.time() - time_table['freezetime_time'] > 2:
  648.             time_table['freezetime_time'] = time.time()
  649.             if gsi_server.get_info('map', 'phase') != 'warmup':
  650.                 truth_table['still_in_warmup'] = False
  651.                 truth_table['first_freezetime'] = False
  652.                 write('WARMUP is over!', overwrite='7')
  653.                 if cfg['freezetime_auto_on']:
  654.                     truth_table['test_for_freezetime'] = True
  655.                 if win32gui.GetWindowPlacement(hwnd)[1] == 2:
  656.                     playsound('sounds/ready_up.mp3')
  657.  
  658.     if truth_table['test_for_warmup']:
  659.         for i in range(cfg['stop_warmup_ocr'][0], cfg['stop_warmup_ocr'][1]):
  660.             win32api.GetAsyncKeyState(i) & 1
  661.         truth_table['still_in_warmup'] = True
  662.         while True:
  663.             keys = [(win32api.GetAsyncKeyState(i) & 1) for i in range(cfg['stop_warmup_ocr'][0], cfg['stop_warmup_ocr'][1])]
  664.             if any(keys) or not push_urgency:
  665.                 write('Break from warmup-loop')
  666.                 push_counter = 0
  667.                 no_text_found = 0
  668.                 truth_table['test_for_warmup'] = False
  669.                 truth_table['first_ocr'] = True
  670.                 truth_table['first_push'] = True
  671.                 time_table['freezetime_time'] = time.time() + 5
  672.                 break
  673.  
  674.             if time.time() - time_table['warmup_test_timer'] >= cfg['warmup_test_interval']:
  675.                 time_table['warmup_test_timer'] = time.time()
  676.                 img = getScreenShot(hwnd, (1036, 425, 1525, 456))  # 'WAITING FOR PLAYERS X:XX'
  677.                 img_text = Image_to_Text(img, img.size, (225, 225, 225), arg='--psm 6')
  678.                 try:
  679.                     time_left = list(map(int, re.findall(re.compile('\d+?:\d+'), img_text)[0].split(':')))
  680.                     time_left = time_left[0] * 60 + time_left[1]
  681.                     if truth_table['first_ocr']:
  682.                         join_warmup_time = time_left
  683.                         time_table['screenshot_time'] = time.time()
  684.                         truth_table['first_ocr'] = False
  685.                     time_left_data = timedelta(seconds=int(time.time() - time_table['screenshot_time'])), time.strftime('%H:%M:%S', time.gmtime(abs((join_warmup_time - time_left) - (time.time() - time_table['screenshot_time'])))), img_text
  686.                     write('Time since start: %s - Time Difference: %s - Time left: %s' % (time_left_data[0], time_left_data[1], time_left_data[2]), add_time=False, overwrite='1')
  687.                     if no_text_found > 0:
  688.                         no_text_found = 0
  689.  
  690.                     if time_left <= push_times[push_counter] and push_counter >= len(push_times):
  691.                         push_counter += 1
  692.                         write('Time since start: %s\nTime Difference: %s\nTime left: %s' % (time_left_data[0], time_left_data[1], time_left_data[2]), push=push_urgency + 1, push_now=True, output=False)
  693.  
  694.                     if truth_table['first_push']:
  695.                         if abs((join_warmup_time - time_left) - (time.time() - time_table['screenshot_time'])) >= 5:
  696.                             truth_table['first_push'] = False
  697.                             write('Match should start in ' + str(time_left) + ' seconds, All players have connected.', push=push_urgency + 2, push_now=True)
  698.  
  699.                 except IndexError:
  700.                     no_text_found += 1
  701.  
  702.                 if gsi_server.get_info('map', 'phase') != 'warmup':
  703.                     push_counter = 0
  704.                     no_text_found = 0
  705.                     truth_table['test_for_warmup'] = False
  706.                     truth_table['first_ocr'] = True
  707.                     truth_table['first_push'] = True
  708.                     truth_table['still_in_warmup'] = False
  709.                     if cfg['freezetime_auto_on']:
  710.                         truth_table['test_for_freezetime'] = True
  711.                     write('WARMUP is over!', push=push_urgency + 2, push_now=True)
  712.                     break
  713.  
  714.             if no_text_found >= cfg['warmup_no_text_limit']:
  715.                 push_counter = 0
  716.                 no_text_found = 0
  717.                 truth_table['test_for_warmup'] = False
  718.                 truth_table['first_ocr'] = True
  719.                 truth_table['first_push'] = True
  720.                 write('Did not find any warmup text.', push=push_urgency + 2, push_now=True)
  721.                 time_table['freezetime_time'] = time.time() + 2
  722.                 break
  723.  
  724.  
  725. if console_window['isatty']:
  726.     if last_printed_line.split(b'**')[-1] != b'\n':
  727.         print('')
  728. exit('ENDED BY USER')
Add Comment
Please, Sign In to add comment