import random from time import time from window_capture import WindowCapture from vision import Vision import cv2 as cv import pytesseract from hsvfilter import HsvFilter from config_file import UserConfigs # import pyautogui import pydirectinput import keyboard from combine_overlay import CombineOverlay def run(): # initialize the user-class config = UserConfigs() overlay = CombineOverlay() while True: if overlay.run_mode == 'stopped': overlay.update_status_label("stopped", "0") overlay.run_mode = 'init' continue elif overlay.run_mode == 'started': cv.waitKey(1000) pass elif overlay.run_mode == 'init': cv.waitKey(1) continue elif overlay.run_mode == 'paused': continue elif overlay.run_mode == 'finished': overlay.update_status_label("finished", "0") overlay.run_mode = 'init' continue else: break SPAWN_COUNT = int(overlay.spawn_use.get()) capture_window = WindowCapture(None, "magic", config) # initialize the StunVision class vision_stun = Vision() # initialize the StunOverlay class hsv_filter_orange = HsvFilter(10, 156, 0, 17, 255, 255, 0, 0, 0, 0) hsv_filter_p = HsvFilter(130, 156, 0, 179, 255, 255, 0, 0, 0, 0) hsv_filter_b = HsvFilter(88, 156, 0, 128, 255, 255, 0, 0, 0, 0) hsv_filter_g = HsvFilter(34, 156, 0, 74, 255, 255, 0, 0, 0, 0) hsv_filter_y = HsvFilter(24, 156, 0, 33, 255, 255, 0, 0, 0, 0) hsv_filter_0 = HsvFilter(0, 0, 0, 179, 255, 255, 255, 0, 0, 0) hsv_filter_w = HsvFilter(69, 25, 0, 94, 255, 255, 0, 0, 0, 0) loop_time = time() pause = True magic_list = {"1": "body", "2": "finding", "3": "mind", "4": "perceiving", "5": "physical", "6": "seeing", "7": "spiritual"} tier_list = {"1": "0", "2": "orange", "3": "y", "4": "g", "5": "b", "6": "p"} # , "w"} hsv_filter_list = {"1": hsv_filter_0, "2": hsv_filter_orange, "3": hsv_filter_y, "4": hsv_filter_g, "5": hsv_filter_b, "6": hsv_filter_p} needle_list = [] hsv_list = [] for key1 in tier_list: for key2 in magic_list: needle_list.append(cv.imread("magic/" + magic_list[key2] + "_" + tier_list[key1] + ".jpg", cv.IMREAD_UNCHANGED)) hsv_list.append(hsv_filter_list[key1]) while True: if overlay.run_mode == 'paused': continue elif overlay.run_mode == 'stopped': break try: # get an updated image of the game screenshot = capture_window.get_screenshot() # screenshot = cv.imread("buffbar.jpg") except: capture_window.release() print("Game window not available - shutting down application") break #cv.imshow("screenshot", screenshot) #cv.waitKey(150) #continue spawn_1 = vision_stun.find(screenshot, cv.imread("magic/spawn_1.jpg", cv.IMREAD_UNCHANGED), 0.4, 1) if len(spawn_1) == 1: spawn_button_active = True points = vision_stun.get_click_points(spawn_1) for i in range(0, SPAWN_COUNT, 1): pydirectinput.moveTo(points[0][0], points[0][1]) pydirectinput.mouseDown() w = random.randint(1, 50) cv.waitKey(30 + w) pydirectinput.mouseUp() if overlay.run_mode == 'stopped': break else: spawn_0 = vision_stun.find(screenshot, cv.imread("magic/spawn_0.jpg", cv.IMREAD_UNCHANGED), 0.7, 1) points = vision_stun.get_click_points(spawn_0) for point in points: pydirectinput.moveTo(point[0], point[1]) pydirectinput.mouseDown() cv.waitKey(500) pydirectinput.mouseUp() if overlay.run_mode == 'stopped': break continue if overlay.run_mode == 'stopped': break # for needles in needle_list: for rer in range(0, len(needle_list), 1): while True: screenshot = capture_window.get_screenshot() processed_screenshot = vision_stun.apply_hsv_filter(screenshot, hsv_list[rer]) processed_needle = vision_stun.apply_hsv_filter(needle_list[rer], hsv_list[rer]) rectangles = vision_stun.find(processed_screenshot, processed_needle, 0.7, 2) # draw the detection results onto the original image # only trigger ocr reading if a stun is detected points = vision_stun.get_click_points(rectangles) if len(points) == 2: pydirectinput.moveTo(points[0][0], points[0][1]) pydirectinput.mouseDown() w = random.randint(1, 100) cv.waitKey(250 + w) pydirectinput.moveTo(points[1][0], points[1][1]) pydirectinput.mouseUp() if overlay.run_mode == 'stopped': break else: break if overlay.run_mode == 'stopped': break if overlay.run_mode == 'stopped': break needles_white = [] needles_white.append(cv.imread("magic/body_w.jpg", cv.IMREAD_UNCHANGED)) needles_white.append(cv.imread("magic/finding_w.jpg", cv.IMREAD_UNCHANGED)) needles_white.append(cv.imread("magic/mind_w.jpg", cv.IMREAD_UNCHANGED)) needles_white.append(cv.imread("magic/perceiving_w.jpg", cv.IMREAD_UNCHANGED)) needles_white.append(cv.imread("magic/physical_w.jpg", cv.IMREAD_UNCHANGED)) needles_white.append(cv.imread("magic/seeing_w.jpg", cv.IMREAD_UNCHANGED)) needles_white.append(cv.imread("magic/spiritual_w.jpg", cv.IMREAD_UNCHANGED)) for needle_w in needles_white: # do object detection screenshot = capture_window.get_screenshot() processed_screenshot = vision_stun.apply_hsv_filter(screenshot,hsv_filter_w) processed_needle = vision_stun.apply_hsv_filter(needle_w, hsv_filter_w) rectangles = vision_stun.find(processed_screenshot, processed_needle, 0.7, 1) # draw the detection results onto the original image # output_image = vision_stun.draw_rectangles(screenshot, rectangles) # cv.imshow("output_image", output_image) # cv.waitKey(150) points = vision_stun.get_click_points(rectangles) if len(points) >= 1: pydirectinput.moveTo(points[0][0], points[0][1]) pydirectinput.mouseDown() w = random.randint(1, 100) cv.waitKey(100 + w) pydirectinput.mouseUp() screenshot = capture_window.get_screenshot() rectangles = vision_stun.find(screenshot, cv.imread("magic/collect.jpg", cv.IMREAD_UNCHANGED), 0.8, 1) points = vision_stun.get_click_points(rectangles) if len(points) >= 1: pydirectinput.moveTo(points[0][0], points[0][1]) pydirectinput.mouseDown() w = random.randint(1, 100) cv.waitKey(100 + w) pydirectinput.mouseUp() if overlay.run_mode == 'stopped': break if overlay.run_mode == 'stopped': break if __name__ == "__main__": run()