Ejemplo n.º 1
0
class CardTest(GenericCardTemplate()):
    """
    An example class connecting with another one

    my fun bot recieves accepts an image and calls the swipe callback
    with the coordinates identified.
    """
    def __init__(self):
        super().__init__()

    def do_bot_recieve_img(self, img):
        """
        receives image, returns coordinates to swipe from and to
        :param img:
        :return:
        """
        print("DETECTING LOCATIONS")
        img = crop_img_percent(img, 0, .4, 1, .4)
        # show_img(img)
        img1, (img2, num_loc) = pokestop_detector.find_locations(img)
        # show_img(img1)
        # show_img(img2)
        # print(num_loc)
        print("SWIPING")
        return (50, 100), (50, 20)
Ejemplo n.º 2
0
class TransferPokemon(GenericCardTemplate()):
    def __init__(self, name):
        super().__init__(self)
        self.name = name

    def print_click(self, *args, **kwargs):
        print(args, kwargs)

    def do_transfer(self, num_pokemon):
        print("initiating transfer routine in 10s")
        time.sleep(10)
        print("initiating for: ")
        for i in range(num_pokemon):
            print(i / num_pokemon, '% left: ', num_pokemon - i)

            android_phone.swipe(step1, step1)
            time.sleep(long_d)
            android_phone.swipe(step2, step2)
            time.sleep(short_d)
            android_phone.swipe(step3, step3)
            time.sleep(short_d)
            android_phone.swipe(step4, step4)
            time.sleep(med_d)
            android_phone.swipe(step5, step5)
            time.sleep(long_d)
Ejemplo n.º 3
0
class ChangeText(GenericCardTemplate()):
    def do_call(self, arg='hello world'):
        print("PROCESS TEXT RECEIVED: : ", arg)
        arg = arg + " some modification"
        return arg

    def do_method(self):
        return None

    def other_method(self, args):
        return args
Ejemplo n.º 4
0
class SendGifts(GenericCardTemplate()):
    def __init__(self, name):
        super().__init__(self)
        android_phone.set_resolution()
        android_phone.set_full_screen('com.nianticlabs.pokemongo')
        self.name = name

    def print_click(self, *args, **kwargs):
        if kwargs['event'] != 4:
            return
        p = np.array([kwargs['x'], kwargs['y']])
        t = np.array([android_phone.width, android_phone.height])
        p_percent = p / t
        print(p_percent)

    def next_profile(self):
        android_phone.swipe()

    def calibrate(self):
        images_path = './PokemonGo/images/FriendGifting/'
        images = ['open_gift_page', 'gift_received_profile', 'can_send_gift_profile']
        print("CALIBRATING:")
        print("EXPECTED TO BE ON PAGE WHERE GIFT IS RECIEVED FROM FRIEND AND IT WOBBLES")
        update_img_from_details(android_phone.latest_frame, images[1], images_path)
        print("CAPTURED...")
        print("CLICKING TO ACCEPT GIFT...")
        click_wabble_gift()
        time.sleep(2)
        print("EXPECTED TO BE ON PAGE WHERE YOU CAN OPEN THE GIFT...")
        update_img_from_details(android_phone.latest_frame, images[0], images_path)
        print("IMAGE CAPTURED... LEAVING PAGE TO PROFILE PAGE")
        leave_page()
        time.sleep(1)
        print("EXPECTING TO BE ON PROFILE PAGE...")
        print("EXPECTING GIFT IS NOT SENT (COLOURFUL)")
        update_img_from_details(android_phone.latest_frame, images[2], images_path)
        print("CALIBRATION COMPLETE...")

    def do_send_gifts(self):
        print("initiating transfer routine in 10s")
        time.sleep(1)
        limit_reached = False

        while True:
            if gift_received():
                if limit_reached:
                    leave_page()
                else:
                    limit_reached = not open_gift()
            if can_send():
                # break
                send_gift()
            change_profile()
Ejemplo n.º 5
0
Archivo: Human.py Proyecto: Occy88/bots
class Human(GenericCardTemplate()):
    def __init__(self, name):
        super().__init__(self)
        self.name = name

    def do_say(self, words=''):
        print(self.name, " SAID: ", words)

    def do_move(self, x, y):
        self.x = x
        self.y = y
        print("HUMAN HAS MOVED: ", x, y)
Ejemplo n.º 6
0
class ReceiveText(GenericCardTemplate()):
    """
    Print C
    """
    def do_send_msg(self, text):
        """
        receives text,
        :param text:
        :return:
        """
        text = "do_msg_modified " + text
        print("MSG Received, (modified a bit) : ", text)
        pass
Ejemplo n.º 7
0
class CatchPokemon(GenericCardTemplate()):
    def __init__(self, name):
        super().__init__(self)
        android_phone.set_resolution()
        self.name = name

    def print_click(self, *args, **kwargs):
        if kwargs['event'] != 4:
            return
        p = np.array([kwargs['x'], kwargs['y']])
        t = np.array([android_phone.width, android_phone.height])
        p_percent = p / t
        print(p_percent)

    def next_profile(self):
        android_phone.swipe()

    def catch_pokemon(self):
        android_phone.do_mouse_event_complete(self.print_click)
        time.sleep(2)
        while True:
            catch()
            print("SLEEPING")
            time.sleep(10)
Ejemplo n.º 8
0
class Win32Wrapper(GenericCardTemplate()):
    def __init__(self, window_title):
        self.win_32_window = win32gui.FindWindow(None, window_title)
        self.update_properties()
        print('properties updated, starting thread')

        print('window thread complete')

    def update_properties(self):
        self.left, self.top, self.right, self.bottom = win32gui.GetWindowRect(
            self.win_32_window)
        self.height = self.bottom - self.top
        self.width = self.right - self.left
        print(self.width, self.height)

    def get_window_dim(self):
        return np.array([self.width, self.height])

    def get_mouse_pos(self):
        x, y = win32gui.GetCursorPos()
        print(self.left, self.right, self.bottom, self.top)
        x -= self.left
        y -= self.top
        return np.array([x, y])

    def get_cursor_location(self):
        flags, hcursor, (x, y) = win32gui.GetCursorInfo()
        return win32api.GetCursorPos()

    def prepare_screenshot(self):
        self.wDC = win32gui.GetWindowDC(self.win_32_window)
        self.dcObj = win32ui.CreateDCFromHandle(self.wDC)
        self.cDC = self.dcObj.CreateCompatibleDC()

        self.saveBitMap = win32ui.CreateBitmap()
        self.saveBitMap.CreateCompatibleBitmap(self.dcObj, self.width,
                                               self.height)
        self.cDC.SelectObject(self.saveBitMap)

    def show_image(self, screen_name, image):
        cv2.imshow(screen_name, image)
        if cv2.waitKey(1) == ord('q'):
            cv2.destroyAllWindows()

    def start_capture(self):
        self.prepare_screenshot()

        t = time()
        f = 0
        while True:
            if cv2.waitKey(1) == ord('q'):
                cv2.destroyAllWindows()
                break
            if time() - t > 1:
                print(f)
                f = 0
                t = time()

            f += 1
            cv2.imshow('preview', self.get_latest_screenshot())
        self.release()

    def get_latest_screenshot(self):
        result = windll.user32.PrintWindow(self.win_32_window,
                                           self.cDC.GetSafeHdc(), 0)
        signedIntsArray = self.saveBitMap.GetBitmapBits(True)
        img = np.fromstring(signedIntsArray, dtype='uint8')
        img.shape = (self.height, self.width, 4)
        # release happens here...
        img = img[..., :3]
        img = np.ascontiguousarray(img)
        return img

    def release(self):
        self.cDC.DeleteDC()
        self.dcObj.DeleteDC()
        win32gui.ReleaseDC(self.win_32_window, self.wDC)
        win32gui.DeleteObject(self.saveBitMap.GetHandle())

    def screenshot(self):
        img = self.get_latest_screenshot()
        self.show_image('preview', img)

    def kill_all_windows(self):
        cv2.destroyAllWindows()
Ejemplo n.º 9
0
Archivo: ADB.py Proyecto: Occy88/bots
class ADBManager(GenericCardTemplate()):
    def __init__(self):
        super().__init__()
        self.adjusted_resolution = None
        self.latest_frame = None
        self.notif_bar_height = np.array([0, 0])
        logging.info('Bind methods generated')
        self.video_thread = None
        self.android = AndroidViewer()
        self.stop = True
        self.scale_factor = SCREEN_SCALE_FACTOR
        atexit.register(self._shutdown)
        try:
            signal.signal(signal.SIGINT, self._shutdown)
            signal.signal(signal.SIGTERM, self._shutdown)
            # signal.signal(signal.SIGKILL, self._shutdown)
            signal.signal(signal.SIGQUIT, self._shutdown)
            signal.signal(signal.SIGHUP, self._shutdown)
        except Exception as e:
            pass
        time.sleep(2)

    def set_resolution(self, res=np.array([1080, 1920])):
        # adb shell wm size reset
        # adb shell wm density resetpytho
        # adb shell wm size 1080x1920

        self.exec_adb_command(f'wm size ' + 'x'.join(res.astype(str)))
        if NOTiFICATION_BAR_RESCALE:
            time.sleep(1)
            notif_height = self.exec_adb_command(
                "dumpsys window windows| sed -n '/Window .*StatusBar.*:/,/Window .*:/p'| grep 'Requested' |grep h"
            )

            h = int(notif_height.split('h=')[1].split(' ')[0]) + 1
            print("CROPPING OUT NOTIF HEIGHT :")
            print(h)
            self.notif_bar_height = np.array([0, h])
            self.exec_adb_command(f'wm size ' + 'x'.join(
                (res + self.notif_bar_height).astype(str)))

        self.adjusted_resolution = res
        time.sleep(4)

    def reset_resolution(self):
        self.exec_adb_command('wm size reset')

    def set_full_screen(self, app_ref='com.nianticlabs.pokemongo'):
        self.exec_adb_command(
            f'settings put global policy_control immersive.full={app_ref}')

    def exec_adb_command(self, cmd):
        r = os.popen(f'adb shell {cmd}')
        return r.read()

    def do_mouse_event(self, x=0, y=0, flags=0, **kwargs):

        pass

    def do_frame_update(self, img: np.ndarray):
        pass

    def hold(self, xy: np.ndarray, as_percent=True):
        if as_percent:
            xy = self.to_percent(xy)
        self.android.hold(*xy)
        pass

    def release(self, xy, as_percent=True):
        if as_percent:
            xy = self.to_percent(xy)
        self.android.release(*xy)

    def to_percent(self, xy):
        return np.array([self.width, self.height]) * xy

    def swipe(self,
              xy_from: np.ndarray,
              xy_to: np.ndarray,
              as_percent=True,
              step_pixels=5,
              step_delay=0.05):
        """
        Swipe or click event
        (from==to -> click)
        :param xy_from:
        :param xy_to:
        :return:
        """
        if as_percent:
            xy_from = self.to_percent(xy_from)
            xy_to = self.to_percent(xy_to)
        logging.info("Adb Swipe message Recieved: " + str(xy_from) +
                     str(xy_to))
        self.android.swipe(*xy_from,
                           *xy_to,
                           step_pixels=step_pixels,
                           step_delay=step_delay)

    def _shutdown(self, *args):
        logging.info('Shutdown Signal Recieved: ', args)
        logging.info('Cleaning up')
        self.reset_resolution()

        self.stop = True
        self.android.close_all_sockets()
        logging.info("SHUTDOWN CALLED")
        logging.info("SLEEP COMPLETE")
        exit(0)
        return

    def _stop_all_threads(self):
        logging.info("STOPPING ALL THREADS")
        self.stop = True

    def _swipe(self, start_x, start_y, end_x, end_y):
        self.android.swipe(start_x, start_y, end_x, end_y)

    def _preprocess_frame(self, frame):
        xy = np.array([0, 0])
        wh = np.flip(frame.shape)[1:]
        if NOTiFICATION_BAR_RESCALE:
            xy = self.notif_bar_height
        if self.adjusted_resolution is not None:
            wh = self.adjusted_resolution
        frame = crop_img(frame, *xy, *wh)
        # print(frame.shape)
        return frame

    def _special_opencv_thread(self, window):
        logging.info("Video starting on:" + str(window))
        cv2.namedWindow(window)
        cv2.setMouseCallback(window, self.__sanitize_mouse_event)
        logging.info("Callbacks set")
        t = time.time()
        f = 0
        while not self.stop:

            dt = time.time() - t
            t = time.time()
            frames = self.android.get_next_frames()
            if frames is None:
                continue

            for frame in frames:
                f += 1

                self.latest_frame = self._preprocess_frame(frame)

                self._update_dim(self.latest_frame)
                self.do_frame_update(self.latest_frame)
                cv2.imshow(
                    window,
                    resize_img(self.latest_frame, self.scale_factor, True))
                cv2.waitKey(1)
            if dt > 1:
                f = 0
        cv2.destroyWindow(window)
        cv2.waitKey(1)
        logging.info("Thread ended")

    def _update_dim(self, img):
        self.height = len(img)
        self.width = len(img[1])

    def _get_window_dim(self):
        return np.array([self.width, self.height])

    def __sanitize_mouse_event(self, event, x, y, flags, param):
        # logging.info(event, x, y, flags, param)
        self.mouse_x = x / self.scale_factor
        self.mouse_y = y / self.scale_factor
        kwargs = {
            'x': self.mouse_x,
            'y': self.mouse_y,
            'flags': flags,
            'param': param,
            'event': event
        }
        self.do_mouse_event(**kwargs)

    def _get_mouse_pos(self):
        return np.array([self.mouse_x, self.mouse_y])

    def start_capture(self, screen_name):
        self.stop = False
        self.video_thread = threading.Thread(
            target=self._special_opencv_thread, args=[screen_name])
        self.video_thread.daemon = True
        self.video_thread.start()