Esempio n. 1
0
def relocate():
    hc = pyclick.HumanClicker()
    time.sleep(0.5)
    hc.move((404, 312), 0.5)
    time.sleep(0.1)
    hc.click()
    return
Esempio n. 2
0
def move_to_songs(star=1):
    hc = pyclick.HumanClicker()
    time.sleep(1)
    hc.move((496, 125), 0.3)
    hc.click()
    time.sleep(0.5)
    hc.move((496, 325), 0.3)
    hc.click()
    time.sleep(0.5)
    hc.click()
    time.sleep(0.5)
    hc.click()
    time.sleep(1)
    pyautogui.scroll(10)
    time.sleep(0.5)
    pyautogui.scroll(10)
    time.sleep(0.5)
    pyautogui.scroll(10)
    time.sleep(1.25)
    pyautogui.scroll(-10)
    time.sleep(0.5)
    pyautogui.scroll(-10)
    time.sleep(0.5)
    if star is not None:
        hc.move((630, 110 + (star - 1) * 60), 1)
        time.sleep(0.5)
        hc.click()
    time.sleep(0.4)
    hc.move((450, 320), 0.8)
    del hc
    return
Esempio n. 3
0
def shut_annoying_window():
    hc = pyclick.HumanClicker()
    time.sleep(1)
    hc.move((1390, 792), 0.8)
    time.sleep(0.1)
    hc.click()
    return
Esempio n. 4
0
def return_to_beatmap2():
    hc = pyclick.HumanClicker()
    time.sleep(1.5)
    hc.move((515, 483), 0.9)
    time.sleep(0.5)
    hc.click()
    time.sleep(0.15)
    hc.click()
    time.sleep(0.1)
    return
Esempio n. 5
0
def restart():
    hc = pyclick.HumanClicker()
    time.sleep(3)
    hc.move((600, 336), 1.0)
    time.sleep(1)
    hc.click()
    time.sleep(0.1)
    hc.click()
    time.sleep(0.2)
    return
Esempio n. 6
0
def launch_selected_beatmap():
    hc = pyclick.HumanClicker()
    time.sleep(0.2)
    hc.move((1010, 622), 0.6)
    time.sleep(0.25)
    hc.click()
    time.sleep(0.3)
    hc.move((500, 320), 0.3)
    time.sleep(0.7)
    return
Esempio n. 7
0
def return_to_beatmap():
    hc = pyclick.HumanClicker()
    time.sleep(8)
    hc.move((800, 270), 0.8)
    time.sleep(0.2)
    hc.click()
    time.sleep(0.4)
    hc.click()
    hc.move((50, 605), 0.9)
    time.sleep(0.15)
    hc.click()
    time.sleep(0.4)
    return
Esempio n. 8
0
def select_beatmap(search_name):
    hc = pyclick.HumanClicker()
    pyautogui.mouseUp(button='left')
    pyautogui.mouseUp(button='right')
    time.sleep(0.5)
    for letter in search_name:
        win32api.keybd_event(KEY_DICT[letter], 0, 0, 0)
        time.sleep(0.04)
        win32api.keybd_event(KEY_DICT[letter], 0, win32con.KEYEVENTF_KEYUP, 0)
    hc.move((830, 370), 2.5)
    time.sleep(0.8)
    hc.click()
    return
Esempio n. 9
0
def launch_random_beatmap():
    hc = pyclick.HumanClicker()
    pyautogui.mouseUp(button='left')
    pyautogui.mouseUp(button='right')
    time.sleep(0.1)
    hc.move((338, 594), 0.25)
    time.sleep(0.1)
    hc.click()
    time.sleep(3.3)
    hc.move((1010, 622), 0.5)
    time.sleep(0.2)
    hc.click()
    time.sleep(0.1)
    hc.move((500, 320), 0.3)
    time.sleep(0.7)
    return
Esempio n. 10
0
def reset_mods():
    hc = pyclick.HumanClicker()
    time.sleep(0.25)
    hc.move((275, 590), 0.4)
    time.sleep(0.1)
    hc.click()
    time.sleep(0.3)
    hc.move((670, 450), 0.8)
    time.sleep(0.3)
    hc.click()
    time.sleep(0.2)
    hc.move((504, 518), 0.5)
    time.sleep(0.1)
    hc.click()
    time.sleep(0.4)
    hc.move((400, 360), 0.8)
    time.sleep(0.3)
    return
Esempio n. 11
0
def enable_nofail():
    hc = pyclick.HumanClicker()
    time.sleep(0.2)
    hc.move((275, 590), 0.5)
    time.sleep(0.2)
    hc.click()
    time.sleep(0.2)
    hc.move((385, 195), 0.5)
    time.sleep(0.15)
    hc.click()
    time.sleep(0.2)
    hc.move((350, 520), 0.6)
    time.sleep(0.15)
    hc.click()
    time.sleep(0.3)
    hc.move((150, 520), 0.7)
    time.sleep(0.3)
    return
Esempio n. 12
0
    def __init__(self,
                 game,
                 enableBezierCurve: bool,
                 mouse_speed: float = 0.2,
                 debug_mode: bool = False):
        super().__init__()

        self._game = game
        self._enableBezierCurve = enableBezierCurve
        self._mouse_speed = mouse_speed
        self._debug_mode = debug_mode

        if (enableBezierCurve):
            self._hc = pyclick.HumanClicker()
        else:
            pyautogui.MINIMUM_DURATION = 0.1
            pyautogui.MINIMUM_SLEEP = 0.05
            pyautogui.PAUSE = 0.25
Esempio n. 13
0
    def __init__(self, discrete_width, discrete_height, discrete_factor, height, width, stack_size, star=2, beatmap_name=None, no_fail=False, skip_pixels=4, human_off_policy=False):
        super(OsuEnv, self).__init__()
        self.discrete_width = discrete_width
        self.discrete_height = discrete_height
        self.height = height
        self.width = width
        self.stack_size = stack_size
        self.discrete_factor = discrete_factor

        self.human_off_policy = human_off_policy

        self.action_space = spaces.Discrete(discrete_height * discrete_width * 4)
        self.observation_space = spaces.Box(low=0, high=1, shape=(height, width, stack_size))

        self.screen = utils.screen.init_screen(capture_output="pytorch_float_gpu")
        self.score_ocr = utils.OCR.init_OCR('./weights/OCR/OCR_score2.pt').to(device)
        self.acc_ocr = utils.OCR.init_OCR('./weights/OCR/OCR_acc2.pt').to(device)
        self.process, self.window = utils.osu_routines.start_osu()
        self.hc = pyclick.HumanClicker()

        self.star = star
        self.beatmap_name = beatmap_name
        self.no_fail = no_fail
        self.skip_pixels = skip_pixels
        self.first = True

        self.history = None
        self.previous_score = None
        self.previous_acc = None
        self.thread = None

        utils.osu_routines.move_to_songs(star=star)
        if beatmap_name is not None:
            utils.osu_routines.select_beatmap(beatmap_name)
        if no_fail:
            utils.osu_routines.enable_nofail()
class MouseUtils:
    """
    Provides the utility functions needed to perform mouse-related actions.
    """

    _hc = pyclick.HumanClicker()

    if Settings.enable_bezier_curve_mouse_movement is False:
        pyautogui.MINIMUM_DURATION = 0.1
        pyautogui.MINIMUM_SLEEP = 0.05
        pyautogui.PAUSE = 0.25

    @staticmethod
    def move_to(x: int, y: int, custom_mouse_speed: float = 0.0):
        """Move the cursor to the coordinates on the screen.

        Args:
            x (int): X coordinate on the screen.
            y (int): Y coordinate on the screen.
            custom_mouse_speed (float, optional): Time in seconds it takes for the mouse to move to the specified point. Defaults to 0.0.

        Returns:
            None
        """
        if Settings.enable_bezier_curve_mouse_movement:
            # HumanClicker only accepts int as the mouse speed.
            if int(custom_mouse_speed) < 1:
                custom_mouse_speed = 1

            MouseUtils._hc.move(
                (x, y),
                duration=custom_mouse_speed,
                humanCurve=pyclick.HumanCurve(pyautogui.position(), (x, y)))
        else:
            if custom_mouse_speed <= 0.0:
                custom_mouse_speed = Settings.custom_mouse_speed

            pyautogui.moveTo(x,
                             y,
                             duration=custom_mouse_speed,
                             tween=pyautogui.easeInOutQuad)

        return None

    @staticmethod
    def move_and_click_point(x: int,
                             y: int,
                             image_name: str,
                             custom_mouse_speed: float = 0.0,
                             mouse_clicks: int = 1):
        """Move the cursor to the specified point on the screen and clicks it.

        Args:
            x (int): X coordinate on the screen.
            y (int): Y coordinate on the screen.
            image_name (str): File name of the image in /images/buttons/ folder.
            custom_mouse_speed (float, optional): Time in seconds it takes for the mouse to move to the specified point. Defaults to 0.0.
            mouse_clicks (int, optional): Number of mouse clicks. Defaults to 1.

        Returns:
            None
        """
        if Settings.debug_mode:
            MessageLog.print_message(f"[DEBUG] Old coordinates: ({x}, {y})")

        new_x, new_y = MouseUtils._randomize_point(x, y, image_name)

        if Settings.debug_mode:
            MessageLog.print_message(
                f"[DEBUG] New coordinates: ({new_x}, {new_y})")

        # Move the mouse to the specified coordinates.
        if Settings.enable_bezier_curve_mouse_movement:
            # HumanClicker only accepts int as the mouse speed.
            if int(custom_mouse_speed) < 1:
                custom_mouse_speed = 1

            MouseUtils._hc.move(
                (new_x, new_y),
                duration=custom_mouse_speed,
                humanCurve=pyclick.HumanCurve(pyautogui.position(),
                                              (new_x, new_y)))
        else:
            if custom_mouse_speed <= 0.0:
                custom_mouse_speed = Settings.custom_mouse_speed

            pyautogui.moveTo(x,
                             y,
                             duration=custom_mouse_speed,
                             tween=pyautogui.easeInOutQuad)

        pyautogui.click(clicks=mouse_clicks)

        # This delay is necessary as ImageUtils will take the screenshot too fast and the bot will use the last frame before clicking to navigate.
        from bot.game import Game
        Game.wait(1)

        return None

    @staticmethod
    def _randomize_point(x: int, y: int, image_name: str):
        """Randomize the clicking location in an attempt to avoid clicking the same location that may make the bot look suspicious.

        Args:
            x (int): X coordinate on the screen of the center of the match location.
            y (int): Y coordinate on the screen of the center of the match location.
            image_name (str): File name of the image in /images/buttons/ folder.

        Returns:
            (int, int): Tuple of the newly randomized location to click.
        """
        # Get the width and height of the template image.
        from utils.image_utils import ImageUtils
        width, height = ImageUtils.get_button_dimensions(image_name)

        dimensions_x0 = x - (width // 2)
        dimensions_x1 = x + (width // 2)

        dimensions_y0 = y - (height // 2)
        dimensions_y1 = y + (height // 2)

        while True:
            new_width = random.randint(int(width * 0.2), int(width * 0.8))
            new_height = random.randint(int(height * 0.2), int(height * 0.8))

            new_x = dimensions_x0 + new_width
            new_y = dimensions_y0 + new_height

            # If the new coordinates are within the bounds of the template image, break out of the loop and return the coordinates.
            if new_x > dimensions_x0 or new_x < dimensions_x1 or new_y > dimensions_y0 or new_y < dimensions_y1:
                break

        return new_x, new_y

    @staticmethod
    def scroll_screen(x: int, y: int, scroll_clicks: int):
        """Attempt to scroll the screen to reveal more UI elements from the provided x and y coordinates.

        Args:
            x (int): X coordinate on the screen.
            y (int): Y coordinate on the screen.
            scroll_clicks (int): How much to scroll the screen. Positive for scrolling up and negative for scrolling down.

        Returns:
            None
        """
        if Settings.debug_mode:
            MessageLog.print_message(
                f"[DEBUG] Now scrolling the screen from ({x}, {y}) by {scroll_clicks} clicks..."
            )

        MouseUtils.move_to(x, y)

        if Settings.enable_bezier_curve_mouse_movement:
            # Reset the pause delay back to 0.25, primarily for ImageUtils' methods using pyautogui.
            pyautogui.PAUSE = 0.25

        pyautogui.scroll(scroll_clicks, x=x, y=y)

        return None

    @staticmethod
    def scroll_screen_from_home_button(scroll_clicks: int):
        """Attempt to scroll the screen using the "Home" button coordinates to reveal more UI elements.

        Args:
            scroll_clicks (int): How much to scroll the screen. Positive for scrolling up and negative for scrolling down.

        Returns:
            None
        """
        x = Settings.home_button_location[0]
        y = Settings.home_button_location[1] - 50

        if Settings.debug_mode:
            MessageLog.print_message(
                f"[DEBUG] Now scrolling the screen from the \"Home\" button's coordinates at ({x}, {y}) by {scroll_clicks} clicks..."
            )

        MouseUtils.move_to(x, y)

        if Settings.enable_bezier_curve_mouse_movement:
            # Reset the pause delay back to 0.25, primarily for ImageUtils' methods using pyautogui.
            pyautogui.PAUSE = 0.25

        pyautogui.scroll(scroll_clicks, x=x, y=y)

        return None

    @staticmethod
    def clear_textbox():
        """Clear the selected textbox of all text by selecting all text by CTRL + A and then pressing DEL.

        Returns:
            None
        """
        pyautogui.keyDown("ctrl")
        pyautogui.press("a")
        pyautogui.keyUp("ctrl")
        pyautogui.press("del")
        return None

    @staticmethod
    def copy_to_clipboard(message: str):
        """Copy the message to the clipboard.

        Args:
            message (str): The message to be copied.

        Returns:
            None
        """
        pyperclip.copy(message)
        return None

    @staticmethod
    def paste_from_clipboard():
        """Paste from the clipboard. Make sure that the textbox is already selected.

        Returns:
            None
        """
        message = pyperclip.paste()
        pyautogui.write(message)
        return None
Esempio n. 15
0
 def __init__(self):
     self.clicker = pyclick.HumanClicker()
Esempio n. 16
0
 def __init__(self):
     # object contains window ID and x,y positions
     self.rs_window = setup.Window()
     self.rsx, self.rsy = self.rs_window.position
     self.hc = pyclick.HumanClicker()