Beispiel #1
0
def Attack():
    os.chdir(os.path.dirname(os.path.abspath(__file__)))
    wincap = WindowCapture('Legends of Runeterra')
    #vision_IP = Vision('img\minalegal.jpg')
    
    #haystack_img = cv.imread('img\este1.jpg', cv.IMREAD_UNCHANGED)
    needle_img = cv.imread('img\mobBeSelected.jpg', cv.IMREAD_UNCHANGED)

    result = cv.matchTemplate(wincap.get_screenshot(), needle_img, cv.TM_CCOEFF_NORMED)
    
    #cv.imshow('Result', result)
    #cv.waitKey()

    min_val, max_val, min_loc, max_loc = cv.minMaxLoc(result)

    print('Best match top left position: %s' % str(max_loc))
    print('Best match confidence: %s' % max_val)
    print('ScreenPosition: %s' % str(wincap.get_screen_position(max_loc)))
    
    pos = str(wincap.get_screen_position(max_loc))
    arrayPos = pos.split(', ')
    PosX = arrayPos[0].replace("(", '')
    PosY = arrayPos[1].replace(")", '')
    print(PosX)
    print(PosY)
    pyautogui.moveTo(int(PosX), int(PosY), 0.1)
    pyautogui.dragTo(2851, 652, 0.25)
Beispiel #2
0
def e():
    log("Waiting for client...")
    time.sleep(30)
    wincap = WindowCapture('League of Legends')
    while (True):
        try:
            screenshot = wincap.get_screenshot()
        except:
            break
        if (locate("playButton", screenshot) != None):
            log("Restarting.")
            break
        if (locate("honor", screenshot) != None):
            log("Honoring teammate...")
            click(client.honorButton)
            time.sleep(1)
        if (locate("dailyPlay", screenshot, 0.8) != None):
            log("Choosing reward...")
            click(client.dailyPlayButton)
            time.sleep(1)
        if (locate("okButton", screenshot, 0.8) != None):
            log("Choosing reward...")
            click(locate("okButton", screenshot, 0.8))
            time.sleep(1)
        if (locate("xButton", screenshot, 0.8) != None):
            log("Exiting lobby...")
            click(locate("xButton", screenshot, 0.8))
            time.sleep(1)
Beispiel #3
0
def streamScreen(window_name):

    print("Starting streaming game window")

    # initialize the WindowCapture class
    wincap = WindowCapture(window_name)

    loop_time = time()
    frames = 0
    while (True):

        # get an updated image of the game
        screenshot = wincap.get_screenshot()

        cv.imshow('Computer Vision', screenshot)
        frames = frames + 1

        # debug the loop rate
        if frames == 200:

            print('FPS {}'.format(int(200 / (time() - loop_time))))
            loop_time = time()
            frames = 0

        # press 'q' with the output window focused to exit.
        # waits 1 ms every loop to process key presses
        if cv.waitKey(1) == ord('q'):
            cv.destroyAllWindows()
            break

    print('Done.')
Beispiel #4
0
def SelectAlly(Ally):
    os.chdir(os.path.dirname(os.path.abspath(__file__)))
    wincap = WindowCapture('Legends of Runeterra')
    
    #------------------------------#
    #fogolivre = ["img\\oomcrewrookie.jpg", "img\\crimsondisciple.jpg", "img\\decimate.jpg", "img\\getexcited.jpg", "img\\imperialdemoli.jpg", "img\\legiongran.jpg", "img\\legionrear.jpg", "img\\legionsaboteur.jpg", "img\\mysticshot.jpg", "img\\oxianfervor.jpg", "img\\preciouspet.jpg", "img\\statikkshock.jpg", "img\\sformation.jpg", "img\\usedcasksalesman.jpg"]
    if Ally == "Legion Rearguard":
        vToFind = cv.imread('img\legionrear.jpg', cv.IMREAD_UNCHANGED)
    elif Ally == "Legion Saboteur":
        vToFind = cv.imread('img\legionsaboteur.jpg', cv.IMREAD_UNCHANGED)
    elif Ally == "Precious Pet":
        vToFind = cv.imread('img\preciouspet1.jpg', cv.IMREAD_UNCHANGED)
    elif Ally == "Boomcrew Rookie":
        vToFind = cv.imread('img\oomcrewrookie.jpg', cv.IMREAD_UNCHANGED)
    elif Ally == "Crimson Disciple":
        vToFind = cv.imread('img\crimsondisciple.jpg', cv.IMREAD_UNCHANGED)
    elif Ally == "Imperial Demolitionist":
        vToFind = cv.imread('img\imperialdemoli.jpg', cv.IMREAD_UNCHANGED)
    elif Ally == "Legion Granadier":
        vToFind = cv.imread('img\legiongran.jpg', cv.IMREAD_UNCHANGED)
    elif Ally == "Mystic Shot":
        vToFind = cv.imread('img\mysticshot.jpg', cv.IMREAD_UNCHANGED)
    elif Ally == "Transfusion":
        vToFind = cv.imread('img\sformation.jpg', cv.IMREAD_UNCHANGED)
    elif Ally == "Get Excited":
        vToFind = cv.imread('img\getexcited.jpg', cv.IMREAD_UNCHANGED)
    elif Ally == "Noxian Fervor":
        vToFind = cv.imread('img\oxianfervor.jpg', cv.IMREAD_UNCHANGED)
    elif Ally == "Used Cask Salesman":
        vToFind = cv.imread('img\casksalesman.jpg', cv.IMREAD_UNCHANGED)
    elif Ally == "Statikk Shock":
        vToFind = cv.imread('img\statikkshock.jpg', cv.IMREAD_UNCHANGED)
    elif Ally == "Decimate":
        vToFind = cv.imread('img\decimate.jpg', cv.IMREAD_UNCHANGED)

    #------------------------------#

    result = cv.matchTemplate(wincap.get_screenshot(), vToFind, cv.TM_CCOEFF_NORMED)

    min_val, max_val, min_loc, max_loc = cv.minMaxLoc(result)

    print('Best match top left position: %s' % str(max_loc))
    print('Best match confidence: %s' % max_val)
    print('ScreenPosition: %s' % str(wincap.get_screen_position(max_loc)))
    
    pos = str(wincap.get_screen_position(max_loc))
    arrayPos = pos.split(', ')
    PosX = arrayPos[0].replace("(", '')
    PosY = arrayPos[1].replace(")", '')
    print(PosX)
    print(PosY)
    pyautogui.click(PosX, PosY, clicks=1, interval=1)
Beispiel #5
0
def c():
    log("Game window found.")
    wincap = WindowCapture('League of Legends (TM) Client')
    while (True):
        try:
            screenshot = wincap.get_screenshot()
        except:
            break
        if (locate("minimap", screenshot) != None):
            log("Game started.")
            break
        else:
            log("Waiting for game to start...")
            click((computerWidth / 2, computerHeight / 2))
Beispiel #6
0
def b():
    wincap = WindowCapture('League of Legends')
    while (True):
        try:
            screenshot = wincap.get_screenshot()
        except:
            break
        if (locate("grayLockInButton", screenshot) == None):
            if (locate("findMatchButton", screenshot) != None):
                log("Finding a match...")
                click(client.findMatchButton)
            if (locate("acceptButton", screenshot) != None):
                log("Waiting for champ select...")
                click(client.acceptButton)
        if (locate("chooseChampion", screenshot) != None):
            chooseChamp()
    log("Waiting for game window...")
    time.sleep(10)
Beispiel #7
0
def make_cropped_ss(
    LOAD_IMAGE_=LOAD_IMAGE,
    cropping_x=450,
    cropping_y=970,
    cropping_width=1000,
    cropping_height=30,
    IMAGE_DEBUG_MODE_=IMAGE_DEBUG_MODE,
):
    """


    Parameters
    ----------
    LOAD_IMAGE_ : If want to open without game then change to 1.
        The default is 0.
    window : Window to be captured, set to None if want to open without game.
        The default is wincap.

        Defaults to cropp screenshot from first to fifth(1-5) champion card name.
    cropping_x :  The default is 450.
    cropping_y :  The default is 970.
    cropping_width :  The default is 1000.
    cropping_height :  The default is 30.

    Returns
    -------
    crop_img : Cropped screenshot.

    """
    logging.debug("Function make_cropped_ss() called")

    if LOAD_IMAGE_:
        screenshot = cv.imread("examples/ss3.jpg", cv.IMREAD_UNCHANGED)
    else:
        wincap = WindowCapture("League of Legends (TM) Client")
        screenshot = wincap.get_screenshot()
    crop_img = screenshot[cropping_y:cropping_y + cropping_height,
                          cropping_x:cropping_x + cropping_width, ]

    if IMAGE_DEBUG_MODE_:
        cv.imshow("make_cropped_ss()", crop_img)

    logging.debug("Function make_cropped_ss() end")
    return crop_img, screenshot
Beispiel #8
0
def Block(Spot):
    # -------------------- Found My Card ----------------------------- #
    os.chdir(os.path.dirname(os.path.abspath(__file__)))
    wincap = WindowCapture('Legends of Runeterra')
    needle_img = cv.imread('img\mobBeSelected.jpg', cv.IMREAD_UNCHANGED)
    result = cv.matchTemplate(wincap.get_screenshot(), needle_img, cv.TM_CCOEFF_NORMED)
    min_val, max_val, min_loc, max_loc = cv.minMaxLoc(result)
    pos = str(wincap.get_screen_position(max_loc))
    arrayPos = pos.split(', ')
    PosX = arrayPos[0].replace("(", '')
    PosY = arrayPos[1].replace(")", '')
    pyautogui.moveTo(int(PosX), int(PosY), 0.1)
    sleep(1)
    spot = ["2379", "711", "2576", "713", "2751", "710", "3008", "711", "3180", "712", "3370", "706"]
    if Spot == "1":
        cardToBlockX = spot[0]
        cardToBlockY = spot[1]
        pyautogui.dragTo(int(cardToBlockX), int(cardToBlockY), 0.25)
    if Spot == "2":
        cardToBlockX = spot[2]
        cardToBlockY = spot[3]
        pyautogui.dragTo(int(cardToBlockX), int(cardToBlockY), 0.25)
    if Spot == "3":
        cardToBlockX = spot[4]
        cardToBlockY = spot[5]
        pyautogui.dragTo(int(cardToBlockX), int(cardToBlockY), 0.25)
    if Spot == "4":
        cardToBlockX = spot[6]
        cardToBlockY = spot[7]
        pyautogui.dragTo(int(cardToBlockX), int(cardToBlockY), 0.25)
    if Spot == "5":
        cardToBlockX = spot[8]
        cardToBlockY = spot[9]
        pyautogui.dragTo(int(cardToBlockX), int(cardToBlockY), 0.25)
    if Spot == "6":
        cardToBlockX = spot[10]
        cardToBlockY = spot[11]
        pyautogui.dragTo(int(cardToBlockX), int(cardToBlockY), 0.25)
        
    # -------------------- Found My Enemy ----------------------------- #
    '''wincap2 = WindowCaptureEnemy('Legends of Runeterra')
Beispiel #9
0
def IsMyRound():
    os.chdir(os.path.dirname(os.path.abspath(__file__)))
    # initialize the WindowCapture class
    wincap = WindowCapture('Legends of Runeterra')
    # finding myRound.jpg
    #vision_IP = Vision('img\minalegal.jpg')
    vToFind = Vision('img\isMyRound.jpg')
    loop_time = time()
    while(True):
        screen = wincap.get_screenshot()
        points = vToFind.find(screen, 0.99, 'rectangles')
        #print('FPS {}'.format(1 / (time() - loop_time)))
        if points:
            print('Is my turn.')
        else:
            print('Not my turn')
            pass
        loop_time = time()
        #return False
        if cv.waitKey(1) == ord('q'):
            cv.destroyAllWindows()
            break
        pass
Beispiel #10
0
# initialize the Vision class
vision_pilar1 = Vision('pilar1.png')
vision_pilar2 = Vision('pilar2.png')
vision_pilar3 = Vision('pilar3.png')
#vision_pilar4 = Vision('pilar4.png')
vision_pilar5 = Vision('pilar5.png')
vision_pilar6 = Vision('pilar6.png')
vision_pilar7 = Vision('pilar7.png')
#vision_pilar62 = Vision('pilar62.png')
vision_pilarPr = Vision('pilarpr.png')

loop_time = time()
while (True):

    # get an updated image of the game
    screenshot = wincap.get_screenshot()
    points_1 = []
    points_2 = []
    points_3 = []
    #points_4 = []
    points_5 = []
    points_6 = []
    points_7 = []
    #points_62 = []
    points_pr = []
    # display the processed image
    points_1 = vision_pilar1.find(screenshot, 0.45, 'rectangles')
    points_2 = vision_pilar2.find(screenshot, 0.6, 'rectangles')
    points_3 = vision_pilar3.find(screenshot, 0.6, 'rectangles')
    #points_4 = vision_pilar4.find(screenshot, 0.5)
    points_5 = vision_pilar5.find(screenshot, 0.6, 'rectangles')
Beispiel #11
0
def d():
    rightClick((computerWidth / 2, computerHeight / 2))
    time.sleep(1)
    q = False
    w = False
    e = False
    buyItems()
    time.sleep(1)
    log("Locking screen...")
    pressKey(keyboardButton.n0)
    wincap = WindowCapture('League of Legends (TM) Client')
    while (True):
        try:
            screenshot = wincap.get_screenshot()
        except:
            break

        if (getPixel(game.recallButton) != (64, 85, 95)):
            #checking health
            if (getPixel(game.healthBar) == (1, 13, 7)):
                rightClick(game.base)
                rightClick(game.base)
                pressKey(keyboardButton.D)
                pressKey(keyboardButton.F)
                #pressKey(keyboardButton.n1)
                flag = True
                for i in range(8):
                    flag = getPixel(game.healthBar) == (1, 13, 7)
                    rightClick(game.base)
                    time.sleep(1)
                    if (flag == False):
                        break
                if flag:
                    pressKey(keyboardButton.B)
                    flag2 = True
                    for i in range(9):
                        flag2 = getPixel(game.healthBar) == (1, 13, 7)
                        time.sleep(1)
                        if (flag2 == False):
                            break
                    if flag2:
                        buyItems()
                        pressKey(keyboardButton.n4)
            else:
                max_loc = locateGame("casterMinion", screenshot,
                                     np.array([111, 167, 81]),
                                     np.array([121, 215, 130]), 0.5)
                if (max_loc != None):
                    setPos(max_loc)
                    pressKey(keyboardButton.Space)
                    #finding champ
                    maxChamp_loc = locateGame("champHealth", screenshot,
                                              np.array([2, 204, 165]),
                                              np.array([4, 204, 166]), 0.5)
                    #checking tower range
                    max_loc = locateGame("tower", screenshot,
                                         np.array([49, 0, 135]),
                                         np.array([100, 40, 166]), 0.5)
                    #checking if theres a enemy champion
                    if (maxChamp_loc != None):
                        #checking if you are not in tower range
                        if (max_loc == None):
                            pressKey(keyboardButton.T)
                            maxChamp_loc = (maxChamp_loc[0] + 50,
                                            maxChamp_loc[1] + 75)
                            setPos(maxChamp_loc)
                            pressKey(keyboardButton.E)
                            pressKey(keyboardButton.R)
                            pressKey(keyboardButton.Q)
                            pressKey(keyboardButton.W)
                            pressKey(keyboardButton.Space)
                            pressKey(keyboardButton.T)
                            time.sleep(0.5)
                    else:
                        pressKey(keyboardButton.W)
                else:
                    x = random.randint(-25, 25)
                    rightClick((game.tower[0] + x, game.tower[1] - x))

                #levelling up
                if (locate("levelUpButton", screenshot) != None):
                    holdKey(keyboardButton.Lctrl)
                    time.sleep(0.05)
                    pressKey(keyboardButton.R)
                    if (q == False):
                        pressKey(keyboardButton.Q)
                        q = True
                    elif (w == False):
                        pressKey(keyboardButton.W)
                        w = True
                    elif (e == False):
                        pressKey(keyboardButton.E)
                        e = True
                    pressKey(keyboardButton.Q)
                    pressKey(keyboardButton.W)
                    pressKey(keyboardButton.E)
                    releaseKey(keyboardButton.Lctrl)
        else:
            buyItems()
    log("Game has ended.")
Beispiel #12
0
os.chdir(os.path.dirname(os.path.abspath(__file__)))

# Inicializa o WindowCapture
wincap = WindowCapture('Camera')

# Carrega o modelo treinado
cascade_limestone = cv.CascadeClassifier('result.xml')

# Carregue uma classe Vision
vision_limestone = Vision(None)

loop_time = time()
while (True):

    # get an updated image of the game
    imagem = wincap.get_screenshot()

    # Detecção de objetos
    rectangles = cascade_limestone.detectMultiScale(imagem)

    # Desenha os resultados da detecção na imagem original
    detection_image = vision_limestone.draw_rectangles(imagem, rectangles)

    # Exibe a imagem
    cv.imshow('Imagem', detection_image)

    loop_time = time()

    key = cv.waitKey(1)
    # presionar Q para fecahr
    if key == ord('q'):
windows = Desktop(backend="uia").windows()
for i in windows:
    if i.window_text().startswith("GS"):
        windowname = i.window_text()
        print("Found Emulator")

wincap = WindowCapture(windowname)
loop_time = time()

with detection_graph.as_default():
    with tf.Session(graph=detection_graph,
                    config=tf.ConfigProto(gpu_options=gpu_options)) as sess:
        while True:
            # for image_path in TEST_IMAGE_PATHS:
            # image = Image.open(image_path)
            image_np = wincap.get_screenshot()

            # result image with boxes and labels on it.
            # Expand dimensions since the model expects images to have shape: [1, None, None, 3]
            image_np_expanded = np.expand_dims(image_np, axis=0)
            image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')
            # Each box represents a part of the image where a particular object was detected.
            boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
            # Each score represent how level of confidence for each of the objects.
            # Score is shown on the result image, together with the class label.
            scores = detection_graph.get_tensor_by_name('detection_scores:0')
            classes = detection_graph.get_tensor_by_name('detection_classes:0')
            num_detections = detection_graph.get_tensor_by_name(
                'num_detections:0')
            # Actual detection.
            (boxes, scores, classes, num_detections) = sess.run(
Beispiel #14
0
class Movement:

    # Properties
    wincap = None
    vision_target = None
    firstRun = True
    points = []
    current = ''
    key = None
    user = b'gAAAAABf470AGsKOJ65Ee9ZxZasRjABVUbdimwfivMloakcKoa20R_guknxp0K7xqYAbLD5IfZ9dUMJP77lKTM6oWRpYl17GHw=='
    pw = b'gAAAAABf470AeGuSrJmZEZrBzs8rJEQqiUDUoArQPNSkMJnlaKyxEknOUXvtvpWlLbTqBkq0SnEnYvjadV7gFI1sd7jtJJbImQ=='

    # Constructor
    def __init__(self, target, haystack_wnd='Toontown Rewritten'):
        # Window Capture has default to TTR, else we choose from main.
        self.wincap = WindowCapture(window_name=haystack_wnd)
        # Previously, we had to use the object to call this function.
        # Now that it is static, we can call the class directly.
        # wincap.list_window_names()
        # WindowCapture.list_window_names()

        # check foreground window title
        current = self.wincap.title()
        """ 
        The Encryption Method I used:
            click.write_key()
            key = click.load_key()
            message1 = user.encode()
            print(message1) - bytes now
            message2 = pw.encode()
            print(message2)
            f = Fernet(key)
            encrypted1 = f.encrypt(message1)
            encrypted2 = f.encrypt(message2)

            print(encrypted1)
            print(encrypted2)
        """
        # Decrypt our user name and pw. IF you want to use it,
        # remove the encryption method, or generate your own encrypted values.
        # Add in your own user/pw instead.``
        self.key = self.load_key()
        f = Fernet(self.key)

        # Target is selectable from main file now.
        if (current == "Toontown Rewritten Launcher"):
            # Make TextBox Bigger
            self.vision_target = Vision('TextBox.png')

            # empty bits on bitmap, idk how they made the launcher
            # self.locator()
            # Just send input
            pdi.press(['tab'])
            time.sleep(0.05)
            pdi.typewrite(f.decrypt(self.user).decode())
            time.sleep(0.05)
            pdi.press(['tab'])
            time.sleep(0.05)
            pdi.typewrite(f.decrypt(self.pw).decode())
            time.sleep(0.05)
            pdi.press(['enter'])
            time.sleep(0.05)
        else:
            self.vision_target = Vision(target)
            # Only find best match
            self.locator(multi=False)

    def locator(self, single=False, multi=True):
        loop_time = time()

        if not single:
            while (True):

                # screenshot = None
                # screenshot = pyautogui.screenshot()
                # cv.imshow is not compatable with pyautogui ss format.
                # so we use numpy.
                # screenshot = ImageGrab.grab()
                # screenshot = np.array(screenshot)
                # Reversing the RGB values
                # screenshot = screenshot[:, :, ::-1].copy()
                # More self-documenting version below:
                # screenshot = cv.cvtColor(screenshot, cv.COLOR_RGB2BGR)
                # screenshot = window_capture()

                screenshot = self.wincap.get_screenshot()
                # Processed Image shown instead of raw screenshot!
                # We show image in our find() function.
                # cv.imshow('Computer Vision', screenshot)
                # findClickPositions('', screenshot, threshold=0.72, debug_mode='points')

                # Show the best match only. Must run find() at least once however.
                if not multi:
                    if not self.firstRun:
                        bestMatch = self.vision_target.bestMatch()
                        self.points = self.vision_target.find(
                            screenshot, bestMatch, 'rectangles')
                    else:
                        self.points = self.vision_target.find(
                            screenshot, 0.9, 'rectangles')
                        self.firstRun = False
                else:
                    self.points = self.vision_target.find(
                        screenshot, 0.9, 'rectangles')

                # debug the loop rate - bad atm
                print('FPS {}'.format(1 / (time() - loop_time)))
                loop_time = time()

                # Press 'q' with the output window focused to exit.
                # Waits 1 ms every loop to process key presses
                if cv.waitKey(1) == ord('q'):
                    cv.destroyAllWindows()
                    break

        # For single uses
        else:
            screenshot = self.wincap.get_screenshot()

            if not multi:
                if not self.firstRun:
                    bestMatch = self.vision_target.bestMatch()
                    self.points = self.vision_target.find(
                        screenshot, bestMatch, 'rectangles')
                else:
                    self.points = self.vision_target.find(
                        screenshot, 0.9, 'rectangles')
                    self.firstRun = False
            else:
                self.points = self.vision_target.find(screenshot, 0.9,
                                                      'rectangles')

            while (True):
                if cv.waitKey(1) == ord('q'):
                    cv.destroyAllWindows()
                    break

        print('Done.')

    # Encrypts our user/pw
    def write_key(self):
        # Generates a key and save it into a file
        self.key = Fernet.generate_key()
        with open("key.key", "wb") as key_file:
            key_file.write(self.key)

    def load_key(self):
        # Loads the key from the current directory named `key.key`
        return open("key.key", "rb").read()
Beispiel #15
0
import cv2 as cv
from windowcapture import WindowCapture
import brain
from keyinput import PressKey  #https://gist.github.com/tracend/912308
import keyboard
import numpy as np
windowcap = WindowCapture("Trackmania")

recording = False
scaledw = 160
scaledh = int(9 / 16 * scaledw)
saved_actions = np.zeros(
    4 + scaledw * scaledh)  #= [2,2,2,2]#np.zeros(shape=[0,4],dtype=np.int)

while (True):
    screenshot = windowcap.get_screenshot()
    resized = cv.resize(screenshot, (scaledw, scaledh),
                        interpolation=cv.INTER_AREA)
    grayscale = cv.cvtColor(resized, cv.COLOR_BGR2GRAY)
    flat = np.reshape(grayscale, (scaledw * scaledh))
    restored = np.reshape(flat, (scaledh, scaledw))
    cv.imshow("screen grab", restored)
    if recording:
        action = [
            int(keyboard.is_pressed('w')),
            int(keyboard.is_pressed('a')),
            int(keyboard.is_pressed('s')),
            int(keyboard.is_pressed('d'))
        ]
        if (abs(np.max(action)) > 1):
            continue
Beispiel #16
0
class FishingBot:

    #properties
    fish_pos_x = None
    fish_pos_y = None
    fish_last_time = None
    detect_text_enable = False
    botting = False

    FISH_RANGE = 74
    FISH_VELO_PREDICT = 30

    BAIT_POSITION = (473, 750)
    FISH_POSITION = (440, 750)

    FILTER_CONFIG = [49, 0, 58, 134, 189, 189, 0, 0, 0, 0]

    FISH_WINDOW_CLOSE = (430, 115)

    # set position of the fish windows
    # this value can be diferent by the sizes of the game window

    FISH_WINDOW_SIZE = (280, 226)
    FISH_WINDOW_POSITION = (163, 125)

    wincap = None

    fishfilter = Filter() if detect_text_enable else None

    # Load the needle image

    needle_img = cv.imread('images/fiss.jpg', cv.IMREAD_UNCHANGED)
    needle_img_clock = cv.imread('images/clock.jpg', cv.IMREAD_UNCHANGED)

    # Some time cooldowns

    detect_text = True

    # Limit time

    initial_time = None

    end_time_enable = False

    end_time = 0

    # for fps

    loop_time = time()

    # The mouse click cooldown

    timer_mouse = time()

    # The timer beteween the states

    timer_action = time()

    bait_time = 2
    throw_time = 2
    game_time = 2

    # This is the filter parameters, this help to find the right image
    hsv_filter = HsvFilter(*FILTER_CONFIG)

    state = 0

    def detect(self, haystack_img):

        # match the needle_image with the hasytack image
        result = cv.matchTemplate(haystack_img, self.needle_img,
                                  cv.TM_CCOEFF_NORMED)

        min_val, max_val, min_loc, max_loc = cv.minMaxLoc(result)

        # needle_image's dimensions
        needle_w = self.needle_img.shape[1]
        needle_h = self.needle_img.shape[0]

        # get the position of the match image
        top_left = max_loc
        bottom_right = (top_left[0] + needle_w, top_left[1] + needle_h)

        # Draw the circle of the fish limits
        cv.circle(
            haystack_img,
            (int(haystack_img.shape[1] / 2), int(haystack_img.shape[0] / 2)),
            self.FISH_RANGE,
            color=(0, 0, 255),
            thickness=1)

        # Only the max level of match is greater than 0.5
        if max_val > 0.5:
            pos_x = (top_left[0] + bottom_right[0]) / 2
            pos_y = (top_left[1] + bottom_right[1]) / 2

            if self.fish_last_time:
                dist = math.sqrt((pos_x - self.fish_pos_x)**2 +
                                 (self.fish_pos_y - pos_y)**2)
                cv.rectangle(haystack_img,
                             top_left,
                             bottom_right,
                             color=(0, 255, 0),
                             thickness=2,
                             lineType=cv.LINE_4)

                # Calculate the fish velocity
                velo = dist / (time() - self.fish_last_time)

                if velo == 0.0:
                    return (pos_x, pos_y, True)
                elif velo >= 150:

                    # With this velocity the fish position will be predict

                    pro = self.FISH_VELO_PREDICT / dist
                    destiny_x = int(pos_x + (pos_x - self.fish_pos_x) * pro)
                    destiny_y = int(pos_y + (pos_y - self.fish_pos_y) * pro)

                    # Draw the predict line

                    cv.line(haystack_img, (int(pos_x), int(pos_y)),
                            (destiny_x, destiny_y), (0, 255, 0),
                            thickness=3)

                    return (destiny_x, destiny_y, False)

            # get the fish position and the time

            self.fish_pos_x = pos_x
            self.fish_pos_y = pos_y
            self.fish_last_time = time()
        return None

    def detect_minigame(self, haystack_img):
        result = cv.matchTemplate(haystack_img, self.needle_img_clock,
                                  cv.TM_CCOEFF_NORMED)

        min_val, max_val, min_loc, max_loc = cv.minMaxLoc(result)
        if max_val > 0.9:
            return True

        return False

    def set_to_begin(self, values):

        if values['-ENDTIMEP-']:
            self.end_time_enable = True
            try:
                self.end_time = int(values['-ENDTIME-']) * 60
            except:
                self.end_time = 0

        self.bait_time = values['-BAITTIME-']
        self.throw_time = values['-THROWTIME-']
        self.game_time = values['-STARTGAME-']

        self.wincap = WindowCapture('METIN2')
        self.state = 0
        self.initial_time = time()
        self.timer_action = time()

    def runHack(self):
        screenshot = self.wincap.get_screenshot()

        # crop and aply hsv filter
        crop_img = screenshot[
            self.FISH_WINDOW_POSITION[1]:self.FISH_WINDOW_POSITION[1] +
            self.FISH_WINDOW_SIZE[1],
            self.FISH_WINDOW_POSITION[0]:self.FISH_WINDOW_POSITION[0] +
            self.FISH_WINDOW_SIZE[0]]
        detect_end_img = screenshot[
            self.FISH_WINDOW_POSITION[1]:self.FISH_WINDOW_POSITION[1] +
            self.FISH_WINDOW_SIZE[1],
            self.FISH_WINDOW_POSITION[0]:self.FISH_WINDOW_POSITION[0] +
            self.FISH_WINDOW_SIZE[0]]
        crop_img = self.hsv_filter.apply_hsv_filter(crop_img)

        cv.putText(crop_img, 'FPS: ' + str(1 / (time() - self.loop_time))[:2],
                   (10, 200), cv.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
        cv.putText(
            crop_img, 'State: ' + str(self.state) + ' ' +
            str(time() - self.timer_action)[:5], (10, 160),
            cv.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
        self.loop_time = time()

        # Verify total time

        if self.end_time_enable and time() - self.initial_time > self.end_time:
            self.botting = False

        # State to click put the bait in the rod

        if self.state == 0:
            mouse_x = int(self.BAIT_POSITION[0] + self.wincap.offset_x)
            mouse_y = int(self.BAIT_POSITION[1] + self.wincap.offset_y)

            if time() - self.timer_action > self.bait_time:
                self.detect_text = True
                pydirectinput.click(x=mouse_x, y=mouse_y, button='right')
                self.state = 1
                self.timer_action = time()

        # State to throw the bait

        if self.state == 1:
            if time() - self.timer_action > self.throw_time:
                mouse_x = int(self.FISH_POSITION[0] + self.wincap.offset_x)
                mouse_y = int(self.FISH_POSITION[1] + self.wincap.offset_y)
                pydirectinput.click(x=mouse_x, y=mouse_y, button='right')
                self.state = 2
                self.timer_action = time()

        # Delay to start the clicks

        if self.state == 2:
            if time() - self.timer_action > self.game_time:
                self.state = 3
                self.timer_action = time()

        # Countdown to finish the state

        detected_end = self.detect_minigame(detect_end_img)

        if self.state == 3:

            if time() - self.timer_action > 15:
                self.timer_action = time()
                self.state = 0
            if time() - self.timer_action > 5 and detected_end is False:
                self.timer_action = time()
                self.state = 0

            if self.detect_text_enable and time() - self.timer_action > 1.5:
                if self.detect_text:
                    if self.fishfilter.match_with_text(screenshot) is False:
                        mouse_x = int(self.wincap.offset_x +
                                      self.FISH_WINDOW_CLOSE[0])
                        mouse_y = int(self.wincap.offset_y +
                                      self.FISH_WINDOW_CLOSE[1])
                        pydirectinput.click(x=mouse_x,
                                            y=mouse_y,
                                            button='left')
                        pydirectinput.click(x=mouse_x,
                                            y=mouse_y,
                                            button='left')

                self.detect_text = False

        # make the click

        if (time() -
                self.timer_mouse) > 0.3 and self.state == 3 and detected_end:

            # Detect the fish

            square_pos = self.detect(crop_img)

            if square_pos:

                # Recalculate the mouse position with the fish position

                pos_x = square_pos[0]
                pos_y = square_pos[1]

                center_x = self.FISH_WINDOW_SIZE[0] / 2
                center_y = self.FISH_WINDOW_SIZE[1] / 2

                mouse_x = int(pos_x)
                mouse_y = int(pos_y)

                # Verify if the fish is in range

                d = self.FISH_RANGE**2 - ((center_x - mouse_x)**2 +
                                          (center_y - mouse_y)**2)

                # Make the click

                if (d > 0):
                    self.timer_mouse = time()

                    mouse_x = int(pos_x + self.FISH_WINDOW_POSITION[0] +
                                  self.wincap.offset_x)
                    mouse_y = int(pos_y + self.FISH_WINDOW_POSITION[1] +
                                  self.wincap.offset_y)

                    pydirectinput.click(x=mouse_x, y=mouse_y)
        '''
        cv.imshow('Minha Janela', crop_img)

        if cv.waitKey(1) == ord('q'):
            cv.destroyAllWindows()
            return True
        '''

        return crop_img
Beispiel #17
0
class PuzzleBot:

    #properties
    
    botting = False

    PUZZLE_WINDOW_SIZE = (260, 170)
    PUZZLE_WINDOW_POSITION = (270, 227)

    PUZZLE_GET_NEW_PIECE = (230, 85)
    PUZZLE_COMFIRM = (100, 90)
    PUZZLE_GET_NEW_PIECE_COLOR = (110, 150)

    wincap = None

    tetris = Tetris()

    timer_action = time()

    get_piece_time = 2

    new_piece = None

    state = 0

    end = False
    dictdump = None

    def set_to_begin(self, values):
        self.wincap = WindowCapture(constants.GAME_NAME)
        self.state = 0
        with open('pieces_second.json') as handle:
            self.dictdump = json.loads(handle.read())

    def set_puzzle_state(self, crop_img):

        paint_c = 32

        board = [[0,0,0,0,0,0],
                [0,0,0,0,0,0],
                [0,0,0,0,0,0],
                [0,0,0,0,0,0]]

        for i in range(0, 4):
            for j in range(0, 6):
                if crop_img[15 + paint_c*i, 15 + paint_c*j, 0] < 50 and crop_img[15 + paint_c*i, 15 + paint_c*j, 1] < 50 and crop_img[15 + paint_c*i, 15 + paint_c*j, 2] < 50:
                    board[i][j] = 0
                else:
                    board[i][j] = 1

                cv.rectangle(crop_img, (15 + paint_c*j, 15 + paint_c*i), (15 + paint_c*j, 15 + paint_c*i),
                            color=(0, 255, 255), thickness=4, lineType=cv.LINE_4)

        self.tetris.board = board
        if self.tetris.count_zeros == 0:
            self.tetris.first = 0
            self.tetris.second = 0
        else:
            self.tetris.first = 1
            self.tetris.second = 1

    def get_image(self):

        screenshot = self.wincap.get_screenshot()

        crop_img = screenshot[self.PUZZLE_WINDOW_POSITION[1]:self.PUZZLE_WINDOW_POSITION[1]+self.PUZZLE_WINDOW_SIZE[1],
                            self.PUZZLE_WINDOW_POSITION[0]:self.PUZZLE_WINDOW_POSITION[0]+self.PUZZLE_WINDOW_SIZE[0]]

        return crop_img

    def press_comfirm(self):

        mouse_x = int(self.PUZZLE_COMFIRM[0] + self.PUZZLE_WINDOW_POSITION[0] + self.wincap.offset_x)
        mouse_y = int(self.PUZZLE_COMFIRM[1] + self.PUZZLE_WINDOW_POSITION[1] + self.wincap.offset_y)

        pydirectinput.click(x=mouse_x, y=mouse_y, button='left')
    
    def press_comfirm_cake(self):

        mouse_x = int(self.PUZZLE_COMFIRM[0] + 20 + self.PUZZLE_WINDOW_POSITION[0] + self.wincap.offset_x)
        mouse_y = int(self.PUZZLE_COMFIRM[1] + self.PUZZLE_WINDOW_POSITION[1] + self.wincap.offset_y)

        pydirectinput.click(x=mouse_x, y=mouse_y, button='left')

    def throw_pice(self):

        mouse_x = int(self.PUZZLE_COMFIRM[0] + self.PUZZLE_WINDOW_POSITION[0] + self.wincap.offset_x)
        mouse_y = int(self.PUZZLE_COMFIRM[1] + self.PUZZLE_WINDOW_POSITION[1] + self.wincap.offset_y)

        pydirectinput.click(x=mouse_x, y=mouse_y, button='right')

    def get_new_piece_color(self, crop_image):

        x = int(self.PUZZLE_GET_NEW_PIECE_COLOR[0])
        y = int(self.PUZZLE_GET_NEW_PIECE_COLOR[1])

        if (crop_image[y, x, 0] > 35 and crop_image[y, x, 0] < 40 and 
           crop_image[y, x, 1] > 60 and crop_image[y, x, 1] < 70 and 
           crop_image[y, x, 2] > 240 and crop_image[y, x, 2] < 260):
            return 4
        elif (crop_image[y, x, 0] > 20 and crop_image[y, x, 0] < 30 and 
           crop_image[y, x, 1] > 150 and crop_image[y, x, 1] < 170 and 
           crop_image[y, x, 2] > 240 and crop_image[y, x, 2] < 260):
            return 1
        elif (crop_image[y, x, 0] > 35 and crop_image[y, x, 0] < 50 and 
           crop_image[y, x, 1] > 240 and crop_image[y, x, 1] < 260 and 
           crop_image[y, x, 2] > 35 and crop_image[y, x, 2] < 50):
            return 5
        elif (crop_image[y, x, 0] > 240 and crop_image[y, x, 0] < 260 and 
           crop_image[y, x, 1] > 240 and crop_image[y, x, 1] < 260 and 
           crop_image[y, x, 2] > 20 and crop_image[y, x, 2] < 30):
            return 3
        elif (crop_image[y, x, 0] > 240 and crop_image[y, x, 0] < 260 and 
           crop_image[y, x, 1] > 100 and crop_image[y, x, 1] < 115 and 
           crop_image[y, x, 2] > -10 and crop_image[y, x, 2] < 10):
            return 2
        elif (crop_image[y, x, 0] > 50 and crop_image[y, x, 0] < 60 and 
           crop_image[y, x, 1] > 235 and crop_image[y, x, 1] < 255 and 
           crop_image[y, x, 2] > 250 and crop_image[y, x, 2] < 260):
            return 6

    def detect_end_game(self, crop_img):

        x = int(self.PUZZLE_GET_NEW_PIECE[0])
        y = int(self.PUZZLE_GET_NEW_PIECE[1])


        if crop_img[y, x, 0] > 100 and crop_img[y, x, 1] > 150 and crop_img[y, x, 2] > 150:
            return False
        else:
            return True

    def play_game(self):
        
        piece = Piece(self.new_piece)

        decision, pos = self.tetris.find_first(piece, self.dictdump)
        paint_c = 32
        if decision == 1:

            self.tetris.insert_piece(pos[0], pos[1], piece)
            if self.tetris.verify_end():
                self.end = True
            mouse_x = 15 + paint_c*pos[1] + self.PUZZLE_WINDOW_POSITION[0] + self.wincap.offset_x
            mouse_y = 15 + paint_c*pos[0] + self.PUZZLE_WINDOW_POSITION[1] + self.wincap.offset_y
            pydirectinput.click(mouse_x, mouse_y)

            return None

        if decision == 2:
            return None

        possibilites = self.tetris.find_possibles(piece)

        pices_count = 0

        for i in range(1,7):
            if i != piece.piece_type:
                possis = self.tetris.find_possibles(Piece(i))
                if len(possis):
                    pices_count += 1

        if piece.piece_type == 1 and pices_count != 0:
            possibilites = [i for i in possibilites if self.tetris.verify_isolated(i[0], i[1])]

        if len(possibilites):

            a = self.tetris.choose_better(piece, possibilites)

            self.tetris.insert_piece(a[0], a[1], piece)
            if self.tetris.verify_end():
                self.end = True
            mouse_x = 15 + paint_c*a[1] + self.PUZZLE_WINDOW_POSITION[0] + self.wincap.offset_x
            mouse_y = 15 + paint_c*a[0] + self.PUZZLE_WINDOW_POSITION[1] + self.wincap.offset_y
            pydirectinput.click(mouse_x, mouse_y)

            return True

        return None

    def runHack(self):
        
        crop_image = self.get_image()

        timep = 0.2

        if self.state == 0:
            mouse_x = int(self.PUZZLE_GET_NEW_PIECE[0] + self.PUZZLE_WINDOW_POSITION[0] + self.wincap.offset_x)
            mouse_y = int(self.PUZZLE_GET_NEW_PIECE[1] + self.PUZZLE_WINDOW_POSITION[1] + self.wincap.offset_y)

            if time() - self.timer_action > timep:

                if self.detect_end_game(crop_image):
                    self.botting = False
                    return None

                pydirectinput.click(x=mouse_x, y=mouse_y, button='left')
                self.state = 1
                self.timer_action = time()

        if self.state == 1:

            if time() - self.timer_action > timep:
                self.press_comfirm()
                self.state = 2
                self.timer_action = time()

        if self.state == 2:

            mouse_x = int(self.PUZZLE_GET_NEW_PIECE_COLOR[0] + self.PUZZLE_WINDOW_POSITION[0] + self.wincap.offset_x)
            mouse_y = int(self.PUZZLE_GET_NEW_PIECE_COLOR[1] + self.PUZZLE_WINDOW_POSITION[1] + self.wincap.offset_y)

            if time() - self.timer_action > timep:
                self.state = 4
                self.timer_action = time()
                pydirectinput.moveTo(mouse_x, mouse_y)

        if self.state == 4:

            if time() - self.timer_action > timep:
                self.state = 5
                self.timer_action = time()
                self.new_piece = self.get_new_piece_color(crop_image)

        if self.state == 5:
            if time() - self.timer_action > timep:
                self.timer_action = time()
                self.set_puzzle_state(crop_image)
                if self.play_game():
                    self.state = 6
                else:
                    self.state = 7
                
        if self.state == 6:
            if time() - self.timer_action > timep:
                self.press_comfirm()
                self.timer_action = time()
                if self.end:
                    self.state = 9
                else: 
                    self.state = 0

        if self.state == 7:
            if time() - self.timer_action > timep:
                self.throw_pice()
                self.timer_action = time()
                self.state = 8

        if self.state == 8:
            if time() - self.timer_action > timep:
                self.press_comfirm()
                self.timer_action = time()
                self.state = 0

        if self.state == 9:
            if time() - self.timer_action > 2:
                self.end = False
                self.press_comfirm_cake()
                self.timer_action = time()
                self.state = 0

        return None
Beispiel #18
0
def main():
    #if (GetWindowText(GetForegroundWindow()) == 'Battlefield™ V'):
    print("welcoming message coming")

    welcome_threading()






    # initialize the WindowCapture class
    wincap = WindowCapture('Battlefield™ V')




    loop_time = time()
    sg.theme('DarkAmber')  # Add a touch of color
    # All the stuff inside your window.


    # Create the Window
    window = sg.Window('OFC administrator', layout)
    # Event Loop to process "events" and get the "values" of the inputs
    while(True):

        event, values = window.read()
        if event == 'Send':
            print('ok')
            send_message(values['global_message'])
        print(sg.Checkbox.get)

        if event == sg.WIN_CLOSED or event == 'Cancel':  # if user closes window or clicks cancel
            break
        print('You entered ', values[0])

        window.close()
        if (GetWindowText(GetForegroundWindow()) == 'Battlefield™ V'):
            screenshot = wincap.get_screenshot()

            # data = process_screen_shot(screenshot)
            # kill_logs = process_kill_shot(screenshot)
            # #menue = process_menue_shot(screenshot)
            # commands(data)
            # kill_log(kill_logs)
            # proc_tick = process_tickets(screenshot)
            # ticket_data(proc_tick)
            # scoreboard = process_scoreboard(screenshot)
            # score_board_data(scoreboard)
            #commands(menue)
            #send_message(welcoming)


            # Button("QUIT", (100, 400), quit)
            #cv.imshow('Computer Vision', screenshot)


        # debug the loop rate
            #print('FPS {}'.format(1.0 / (time() - loop_time)))
        loop_time = time()


        # press 'q' with the output window focused to exit.
        # waits 1 ms every loop to process key presses
        if cv.waitKey(1) == ord('q'):
            pydirectinput.keyUp('ctrl')
            pydirectinput.keyUp('v')
            data =''
            cv.destroyAllWindows()
            break

    print('Done.')