Ejemplo n.º 1
0
    async def image_rec_main(self):
        # create capture
        self.cap = await AsyncVideoCapture.create("/dev/video21")

        # get detectors
        finish_flag = get_pixel_detector(PIXELS_FINISH)

        # loop through frames
        i = 0
        async for frame in self.cap.frames():
            # detect
            if finish_flag(frame):
                logging.info("Has flag!")
                for seat in self.io._message_router.get_all_seats():
                    logging.info(f"\t"+str(seat))
                    self.io.send_score(
                        score=1, seat=seat, seat_final_score=True,
                    )
                self.io.send_score(score=1, final_score=True)

            # generic
            # if i % 100 == 0:
            #     logging.info("100 frames checked")
            # if SAVE_FRAMES and i % 100 == 0:
            #     cv2.imwrite(f"{SAVE_DIR_PATH}/{i}.jpg", frame)
            #     logging.info(f"SAVED {i}.jpg")
            # i += 1

        if self.image_rec_task_cancelled:
            logging.info("Image rec task finished.")
        else:
            raise RuntimeError("Image rec task finished by itself")
Ejemplo n.º 2
0
    async def image_rec_main(self):
        # create capture
        self.cap = await AsyncVideoCapture.create("/dev/video21")

        # get detector
        has_flag = get_pixel_detector(FLAG_PIXELS)

        # loop through frames
        i = 0
        async for frame in self.cap.frames():
            # detect
            if has_flag(frame):
                logging.info("Has flag!")
            else:
                logging.info("Doesn't have flag")

            # generic
            if i % 100 == 0:
                logging.info("100 frames checked")
            if SAVE_FRAMES:
                cv2.imwrite(f"{SAVE_DIR_PATH}/{i}.jpg", frame)
                logging.info(f"SAVED {i}.jpg")
            i += 1
Ejemplo n.º 3
0
    async def on_init(self):
        # init controls
        # connect to pigpio daemon

        self.pi = pigpio.pi()
        if not self.pi.connected:
            raise RuntimeError("Could not connect to pigpio")

        # init joystick splitter, enable physical joystick by default
        self.pi.set_mode(20, pigpio.OUTPUT)
        self.pi.set_mode(21, pigpio.OUTPUT)
        self.pi.write(20, 1)
        self.pi.write(21, 1)
        self.nsg = NSGamepadSerial()
        self.nsg.begin()
        self.io.register_inputs(
            {
                "left_joystick":
                NSJoystick(self.nsg.leftXAxis, self.nsg.leftYAxis),
                "right_joystick":
                NSJoystick(self.nsg.rightXAxis, self.nsg.rightYAxis),
                "dpad_up":
                NSDPadSwitch(self.nsg, NSDPad.UP),
                "dpad_left":
                NSDPadSwitch(self.nsg, NSDPad.LEFT),
                "dpad_right":
                NSDPadSwitch(self.nsg, NSDPad.RIGHT),
                "dpad_down":
                NSDPadSwitch(self.nsg, NSDPad.DOWN),
                "Y":
                NSSwitch(self.nsg, NSButton.Y),
                "X":
                WeplayXSwitch(self.nsg, NSButton.X),
                "A":
                WeplayASwitch(self.nsg, NSButton.A),
                "B":
                WeplayBSwitch(self.nsg, NSButton.B),
                "left_throttle":
                NSSwitch(self.nsg, NSButton.LEFT_THROTTLE),
                "left_trigger":
                WeplayTriggerSwitch(self.nsg, NSButton.LEFT_TRIGGER),
                "right_throttle":
                NSSwitch(self.nsg, NSButton.RIGHT_THROTTLE),
                "right_trigger":
                WeplayTriggerSwitch(self.nsg, NSButton.RIGHT_TRIGGER),
                "minus":
                WeplayMinusSwitch(self.nsg, NSButton.MINUS),
                "plus":
                NSSwitch(self.nsg, NSButton.PLUS),
                "left_stick":
                NSSwitch(self.nsg, NSButton.LEFT_STICK),
                "right_stick":
                NSSwitch(self.nsg, NSButton.RIGHT_STICK),
                "home":
                NSSwitch(self.nsg, NSButton.HOME),
                "capture":
                NSSwitch(self.nsg, NSButton.CAPTURE),
            }, )
        self.lock = asyncio.Lock()

        # create capture
        self.cap = await AsyncVideoCapture.create("/dev/video21")
        # get home current detector
        self.has_home_current_game_selected = get_pixel_detector(
            HOME_CURRENT_GAME_SELECTED_PIXELS, close=35)
        self.has_maybe_game_over = get_pixel_detector(MAYBE_GAME_OVER_PIXELS)

        self.image_rec_task = asyncio.create_task(self.image_rec_main())
        self.image_rec_task.add_done_callback(self.image_rec_done_cb)
        self.inputs_can_be_enabled = False

        if SAVE_FRAMES:
            logging.info(f"SAVING FRAMES TO {SAVE_DIR_PATH}")
            Path(SAVE_DIR_PATH).mkdir(parents=True, exist_ok=True)

        # single press B, this will exit MAP_MENU/ITEMS_MENU,
        # to PLAYING game_state (weplay_switches.py)
        logging.info("single pressing B to get away from menus")
        await single_press(NSButton.B, self.nsg)
Ejemplo n.º 4
0
    ((1149, 681), (226, 231, 164)),
    ((1165, 681), (224, 227, 158)),
    ((1218, 682), (250, 249, 201)),
    ((547, 39), (255, 255, 226)),
    ((609, 38), (25, 28, 0)),
    ((238, 244), (94, 79, 46)),
    ((235, 470), (97, 84, 49)),
    ((1047, 246), (91, 82, 43)),
    ((1047, 413), (97, 84, 49)),
    ((650, 286), (245, 224, 167)),
    ((649, 434), (255, 226, 175)),
]

# when detected, disable inputs and do actions until not detected
AUTO_ACTIONS = {
    get_pixel_detector(MAYBE_GAME_OVER_PIXELS):
    [],  # this just blocks the controls
    get_pixel_detector(GAME_OVER_RETRY_PIXELS_1, close=50):
    [NSButton.A],  # press retry
    get_pixel_detector(GAME_OVER_RETRY_PIXELS_2, close=50):
    [NSButton.A],  # press retry
    get_pixel_detector(GAME_OVER_RETRY_PIXELS_3, close=50): [NSButton.A
                                                             ],  # press retry
    get_pixel_detector(GAME_OVER_SAVE_AND_QUIT_PIXELS): [NSDPad.UP
                                                         ],  # move up to retry
    get_pixel_detector(SAVE_TO_WHICH_FILE_PIXELS):
    [NSButton.B],  # move back to retry screen
}


class NinSwitchWeplayGame(Game):
    async def image_rec_main(self):
        # create capture
        self.cap = await AsyncVideoCapture.create("/dev/video21")

        global LOCKED, allowReset, bypass, DEBUG
        LOCKED = False

        # get detector
        home = get_pixel_detector(HOME, 50)
        input_needed = get_pixel_detector(INPUT_NEEDED, 50)
        reconnected = get_pixel_detector(RECONNECTED, 50)
        settings = get_pixel_detector(SETTINGS, 50)
        title = get_pixel_detector(TITLE, 50)

        # loop through frames
        i = 0
        z = 0
        async for frame in self.cap.frames():
            # detect trigger
            if i % 30 == 0 and (input_needed(frame) or reconnected(frame)):
                pi.write(nsg_reset, ON)
                await asyncio.sleep(0.5)
                pi.write(nsg_reset, OFF)
                await asyncio.sleep(1)
            try:
                if (input_needed(frame) or reconnected(frame)) and not DEBUG:
                    self.io.disable_input(0)
                    self.nsg.press(NSButton.A)
                    await asyncio.sleep(0.1)
                    self.nsg.release(NSButton.A)
                    await asyncio.sleep(2)
                    self.nsg.press(NSButton.A)
                    await asyncio.sleep(0.1)
                    self.nsg.release(NSButton.A)
                    await asyncio.sleep(2)
                    self.io.enable_input(0)
            except:
                if (input_needed(frame) or reconnected(frame)) and not DEBUG:
                    self.nsg.press(NSButton.A)
                    await asyncio.sleep(0.1)
                    self.nsg.release(NSButton.A)
                    await asyncio.sleep(2)
                    self.nsg.press(NSButton.A)
                    await asyncio.sleep(0.1)
                    self.nsg.release(NSButton.A)
                    await asyncio.sleep(2)

            # lock trigger
            try:
                if (home(frame) or settings(frame)
                        or title(frame)) and not LOCKED and not DEBUG:
                    self.io.disable_input(0)
                    if not (i < 100 or bypass):
                        player = json.loads(json.dumps(
                            self.curUser))[0]['username']
                        msg = "ANIMAL CROSSING\nGame locked due to either being at home screen or capture card bars. \nUser's information are as follows:\n> " + player + "\n> " + self.userID
                        bot.send_message(chat_id, msg, parse_mode="markdown")
                        LOCKED = True
                        self.nsg.end()
                        self.prepare = False
                        content = json.loads('{"game":"crossing"}')
                        req = requests.post("[REDACTED]", content)
                    else:
                        msg = "ANIMAL CROSSING\nBypass utilized...Take action to get to a proper menu before something messes up."
                        bot.send_message(chat_id, msg, parse_mode="markdown")
                        bypass = True
                        DEBUG = True
                        LOCKED = True
                        content = json.loads('{"game":"crossing"}')
                        req = requests.post("[REDACTED]", content)
            except:
                if (home(frame) or settings(frame)
                        or title(frame)) and not LOCKED and not DEBUG:
                    if not (i < 100 or bypass):
                        player = json.loads(json.dumps(
                            self.curUser))[0]['username']
                        msg = "ANIMAL CROSSING\nGame locked due to either being at home screen or capture card bars. \nUser's information are as follows:\n> " + player + "\n> " + self.userID
                        bot.send_message(chat_id, msg, parse_mode="markdown")
                        LOCKED = True
                        self.nsg.end()
                        self.prepare = False
                        content = json.loads('{"game":"crossing"}')
                        req = requests.post("[REDACTED]", content)
                    else:
                        msg = "ANIMAL CROSSING\nBypass utilized...Take action to get to a proper menu before something messes up."
                        bot.send_message(chat_id, msg, parse_mode="markdown")
                        bypass = True
                        DEBUG = True
                        LOCKED = True
                        content = json.loads('{"game":"crossing"}')
                        req = requests.post("[REDACTED]", content)

            if LOCKED:
                self.io.send_playing_ended()
                self.prepare = True

            # generic
            if i % 100 == 0:
                allowReset = True
            if SAVE_ALL_FRAMES or save_individual_fame:
                cv2.imwrite(f"{SAVE_DIR_PATH}/{i}.jpg", frame)
                logging.info(f"SAVED {i}.jpg")
            i += 1
Ejemplo n.º 6
0
    async def image_rec_main(self):
        # create capture
        self.cap = await AsyncVideoCapture.create("/dev/video21")

        global LOCKED, allowReset, bypass, DEBUG
        LOCKED = False

        # get detector
        controller_dc_game_detec = get_pixel_detector(
            CONTROLLER_DC_GAME_DETECT, 50)
        controller_dc_input_needed = get_pixel_detector(
            CONTROLLER_DC_INPUT_NEEDED, 50)
        controller_dc_reconnect = get_pixel_detector(CONTROLLER_DC_RECONNECT,
                                                     50)

        game_pause_menu = get_pixel_detector(GAME_PAUSE_MENU, 75)
        game_settings_menu = get_pixel_detector(GAME_SETTINGS_MENU, 50)

        inventory_condenced = get_pixel_detector(INVENTORY_CONDENCED, 50)
        inventory_extended = get_pixel_detector(INVENTORY_EXTENDED, 50)

        game_main_menu = get_pixel_detector(GAME_MAIN_MENU, 50)
        game_main_menu_world = get_pixel_detector(GAME_MAIN_MENU_WORLD, 50)
        home_menu = get_pixel_detector(HOME_MENU, 50)
        settings_menu = get_pixel_detector(SETTINGS_MENU, 50)

        you_died_left = get_pixel_detector(YOU_DIED_LEFT, 50)
        you_died_right = get_pixel_detector(YOU_DIED_RIGHT, 50)
        sure_quit_confirm = get_pixel_detector(SURE_QUIT_CONFIRM, 50)
        sure_quit_cancel = get_pixel_detector(SURE_QUIT_CANCEL, 50)

        # loop through frames
        i = 0
        z = 0
        async for frame in self.cap.frames():
            # detect trigger
            if i % 30 == 0 and (controller_dc_game_detec(frame)
                                or controller_dc_input_needed(frame)
                                or controller_dc_reconnect(frame) or
                                you_died_left(frame) or you_died_right(frame)
                                or sure_quit_cancel(frame)
                                or sure_quit_confirm(frame)) and not DEBUG:
                pi.write(nsg_reset, ON)
                await asyncio.sleep(0.5)
                pi.write(nsg_reset, OFF)
                await asyncio.sleep(1)
            try:
                if (controller_dc_game_detec(frame)
                        or controller_dc_input_needed(frame)
                        or controller_dc_reconnect(frame)) and not DEBUG:
                    self.io.disable_input(0)
                    self.nsg.press(NSButton.A)
                    await asyncio.sleep(0.1)
                    self.nsg.release(NSButton.A)
                    await asyncio.sleep(2)
                    self.nsg.press(NSButton.A)
                    await asyncio.sleep(0.1)
                    self.nsg.release(NSButton.A)
                    await asyncio.sleep(2)
                    self.io.enable_input(0)
            except:
                if (controller_dc_game_detec(frame)
                        or controller_dc_input_needed(frame)
                        or controller_dc_reconnect(frame)) and not DEBUG:
                    self.nsg.press(NSButton.A)
                    await asyncio.sleep(0.1)
                    self.nsg.release(NSButton.A)
                    await asyncio.sleep(2)
                    self.nsg.press(NSButton.A)
                    await asyncio.sleep(0.1)
                    self.nsg.release(NSButton.A)
                    await asyncio.sleep(2)

            try:
                if (you_died_left(frame)) and not DEBUG:
                    self.io.disable_input(0)
                    self.nsg.press(NSButton.A)
                    await asyncio.sleep(0.1)
                    self.nsg.release(NSButton.A)
                    await asyncio.sleep(2)
                    self.io.enable_input(0)

                if (you_died_right(frame)) and not DEBUG:
                    self.io.disable_input(0)
                    self.nsg.leftXAxis(0)
                    self.nsg.leftYAxis(128)
                    await asyncio.sleep(0.1)
                    self.nsg.leftXAxis(128)
                    self.nsg.leftYAxis(128)
                    await asyncio.sleep(0.1)
                    self.nsg.press(NSButton.A)
                    await asyncio.sleep(0.1)
                    self.nsg.release(NSButton.A)
                    await asyncio.sleep(2)
                    self.io.enable_input(0)

                if (sure_quit_confirm(frame)
                        or sure_quit_cancel(frame)) and not DEBUG:
                    self.io.disable_input(0)
                    self.nsg.press(NSButton.B)
                    await asyncio.sleep(0.1)
                    self.nsg.release(NSButton.B)
                    await asyncio.sleep(2)
                    self.io.enable_input(0)

            except:
                if (you_died_left(frame)) and not DEBUG:
                    self.nsg.press(NSButton.A)
                    await asyncio.sleep(0.1)
                    self.nsg.release(NSButton.A)
                    await asyncio.sleep(2)

                if (you_died_right(frame)) and not DEBUG:
                    self.nsg.leftXAxis(0)
                    self.nsg.leftYAxis(128)
                    await asyncio.sleep(0.1)
                    self.nsg.leftXAxis(128)
                    self.nsg.leftYAxis(128)
                    await asyncio.sleep(0.1)
                    self.nsg.press(NSButton.A)
                    await asyncio.sleep(0.1)
                    self.nsg.release(NSButton.A)
                    await asyncio.sleep(2)

                if (sure_quit_confirm(frame)
                        or sure_quit_cancel(frame)) and not DEBUG:
                    self.nsg.press(NSButton.B)
                    await asyncio.sleep(0.1)
                    self.nsg.release(NSButton.B)
                    await asyncio.sleep(2)

            # Get to pause frames...Update as needed
            if (self.prepare and not (game_pause_menu(frame))
                    and not LOCKED) and not DEBUG:
                if z % 3 == 2:
                    self.nsg.press(NSButton.A)
                    await asyncio.sleep(0.1)
                    self.nsg.release(NSButton.A)
                    await asyncio.sleep(1)
                    self.nsg.press(NSButton.B)
                    await asyncio.sleep(0.1)
                    self.nsg.release(NSButton.B)
                    await asyncio.sleep(1)
                elif z % 3 == 1:
                    self.nsg.press(NSButton.PLUS)
                    await asyncio.sleep(0.1)
                    self.nsg.release(NSButton.PLUS)
                    await asyncio.sleep(2)
                z += 1
            elif not LOCKED:
                z = 0
                self.prepare = False

            # lock trigger
            try:
                if (game_main_menu(frame) or game_main_menu_world(frame)
                        or home_menu(frame)
                        or settings_menu(frame)) and not LOCKED and not DEBUG:
                    self.io.disable_input(0)
                    if not (i < 100 or bypass):
                        player = json.loads(json.dumps(
                            self.curUser))[0]['username']
                        msg = "MINECRAFT\nGame locked due to either being at home screen or capture card bars. \nUser's information are as follows:\n> " + player + "\n> " + self.userID
                        bot.send_message(chat_id, msg, parse_mode="markdown")
                        LOCKED = True
                        self.nsg.end()
                        self.prepare = False
                    else:
                        msg = "MINECRAFT\nBypass utilized...Take action to get to a proper menu before something messes up."
                        bot.send_message(chat_id, msg, parse_mode="markdown")
                        bypass = True
                        DEBUG = True
                        LOCKED = True
            except:
                if (game_main_menu(frame) or game_main_menu_world(frame)
                        or home_menu(frame)
                        or settings_menu(frame)) and not LOCKED and not DEBUG:
                    if not (i < 100 or bypass):
                        player = json.loads(json.dumps(
                            self.curUser))[0]['username']
                        msg = "MINECRAFT\nGame locked due to either being at home screen or capture card bars. \nUser's information are as follows:\n> " + player + "\n> " + self.userID
                        bot.send_message(chat_id, msg, parse_mode="markdown")
                        LOCKED = True
                        self.nsg.end()
                        self.prepare = False
                    else:
                        msg = "MINECRAFT\nBypass utilized...Take action to get to a proper menu before something messes up."
                        bot.send_message(chat_id, msg, parse_mode="markdown")
                        bypass = True
                        DEBUG = True
                        LOCKED = True

            if LOCKED:
                self.io.send_playing_ended()
                self.prepare = True

            # generic
            if i % 100 == 0:
                allowReset = True
            if SAVE_ALL_FRAMES or save_individual_fame:
                cv2.imwrite(f"{SAVE_DIR_PATH}/{i}.jpg", frame)
                logging.info(f"SAVED {i}.jpg")
            i += 1
Ejemplo n.º 7
0
    async def image_rec_main(self):
        # create capture
        self.cap = await AsyncVideoCapture.create("/dev/video21")

        global LOCKED, allowReset, bypass, DEBUG
        LOCKED = False

        controller_dc_input_needed = get_pixel_detector(
            CONTROLLER_DC_INPUT_NEEDED, 150)
        controller_dc_reconnect = get_pixel_detector(CONTROLLER_DC_RECONNECT,
                                                     100)

        b_menu = get_pixel_detector(B_MENU, 150)
        creation_body = get_pixel_detector(CREATION_BODY, 150)
        creation_brow = get_pixel_detector(CREATION_BROW, 150)
        creation_eyes = get_pixel_detector(CREATION_EYES, 150)
        creation_face = get_pixel_detector(CREATION_FACE, 150)
        creation_hair = get_pixel_detector(CREATION_HAIR, 150)
        creation_mouth = get_pixel_detector(CREATION_MOUTH, 150)
        creation_race = get_pixel_detector(CREATION_RACE, 150)

        plus_opening = get_pixel_detector(PLUS_OPENING,
                                          200)  # Need to allow for reasons
        plus_system = get_pixel_detector(PLUS_SYSTEM_GEN,
                                         200)  # Avoid if possible
        plus_system_2 = get_pixel_detector(PLUS_SYSTEM_2, 200)

        plus_general_stats = get_pixel_detector(PLUS_GENERAL_STATS,
                                                200)  # Disable going to System
        plus_quests = get_pixel_detector(PLUS_QUESTS,
                                         200)  # Disable going to system

        game_main_menu = get_pixel_detector(GAME_MAIN_MENU, 150)
        game_main_menu_2 = get_pixel_detector(GAME_MAIN_MENU_2, 150)
        home_menu = get_pixel_detector(HOME_MENU, 150)
        settings_menu = get_pixel_detector(SETTINGS_MENU, 150)

        # loop through frames
        i = 0
        z = 0
        async for frame in self.cap.frames():
            # detect trigger
            if i % 30 == 0 and (controller_dc_input_needed(frame) or
                                controller_dc_reconnect(frame)) and not DEBUG:
                pi.write(nsg_reset, ON)
                await asyncio.sleep(0.5)
                pi.write(nsg_reset, OFF)
                await asyncio.sleep(1)
            try:
                if (controller_dc_input_needed(frame)
                        or controller_dc_reconnect(frame)) and not DEBUG:
                    self.io.disable_input(0)
                    self.nsg.press(NSButton.A)
                    await asyncio.sleep(0.1)
                    self.nsg.release(NSButton.A)
                    await asyncio.sleep(2)
                    self.nsg.press(NSButton.A)
                    await asyncio.sleep(0.1)
                    self.nsg.release(NSButton.A)
                    await asyncio.sleep(2)
                    self.io.enable_input(0)
            except:
                if (controller_dc_input_needed(frame)
                        or controller_dc_reconnect(frame)) and not DEBUG:
                    self.nsg.press(NSButton.A)
                    await asyncio.sleep(0.1)
                    self.nsg.release(NSButton.A)
                    await asyncio.sleep(2)
                    self.nsg.press(NSButton.A)
                    await asyncio.sleep(0.1)
                    self.nsg.release(NSButton.A)
                    await asyncio.sleep(2)

            try:
                if (self.started and (plus_system(frame)
                                      or plus_system_2(frame))) and not DEBUG:
                    self.io.disable_input(0)
                    self.nsg.press(NSButton.LEFT_THROTTLE)
                    await asyncio.sleep(0.1)
                    self.nsg.release(NSButton.LEFT_THROTTLE)
                    await asyncio.sleep(1)
                    self.nsg.press(NSButton.B)
                    await asyncio.sleep(0.1)
                    self.nsg.release(NSButton.B)
                    await asyncio.sleep(1)
                    self.io.enable_input(0)
            except:
                if (self.started and (plus_system(frame)
                                      or plus_system_2(frame))) and not DEBUG:
                    self.nsg.press(NSButton.LEFT_THROTTLE)
                    await asyncio.sleep(0.1)
                    self.nsg.release(NSButton.LEFT_THROTTLE)
                    await asyncio.sleep(1)
                    self.nsg.press(NSButton.B)
                    await asyncio.sleep(0.1)
                    self.nsg.release(NSButton.B)
                    await asyncio.sleep(1)

            if (self.prepare and b_menu(frame) and not LOCKED and not DEBUG):
                self.nsg.press(NSButton.B)
                await asyncio.sleep(0.1)
                self.nsg.release(NSButton.B)

            # Get to pause frames...Update as needed
            if (self.prepare and not (
                (plus_system(frame) or plus_system_2(frame)
                 or creation_body(frame) or creation_brow(frame)
                 or creation_eyes(frame) or creation_face(frame)
                 or creation_hair(frame) or creation_mouth(frame)
                 or creation_race(frame) or plus_general_stats(frame)
                 or plus_quests(frame))) and not LOCKED) and not DEBUG:
                if z % 3 == 2:
                    self.nsg.press(NSButton.A)
                    await asyncio.sleep(0.1)
                    self.nsg.release(NSButton.A)
                    await asyncio.sleep(1)
                    self.nsg.press(NSButton.B)
                    await asyncio.sleep(0.1)
                    self.nsg.release(NSButton.B)
                    await asyncio.sleep(1)
                elif z % 3 == 1:
                    self.nsg.rightXAxis(255)
                    self.nsg.rightYAxis(128)
                    await asyncio.sleep(0.5)
                    self.nsg.rightXAxis(128)
                    self.nsg.rightYAxis(128)
                    await asyncio.sleep(1)
                    self.nsg.press(NSButton.PLUS)
                    await asyncio.sleep(0.1)
                    self.nsg.release(NSButton.PLUS)
                    await asyncio.sleep(1)
                    self.nsg.press(NSButton.LEFT_THROTTLE)
                    await asyncio.sleep(0.1)
                    self.nsg.release(NSButton.LEFT_THROTTLE)
                    await asyncio.sleep(1)
                z += 1
            elif not LOCKED:
                z = 0
                self.prepare = False

            # lock trigger
            try:
                if (game_main_menu(frame) or game_main_menu_2(frame)
                        or home_menu(frame)
                        or settings_menu(frame)) and not LOCKED and not DEBUG:
                    self.io.disable_input(0)
                    if not (i < 100 or bypass):
                        player = json.loads(json.dumps(
                            self.curUser))[0]['username']
                        msg = "SKYRIM\nGame locked due to either being at home screen or capture card bars. \nUser's information are as follows:\n> " + player + "\n> " + self.userID
                        bot.send_message(chat_id, msg, parse_mode="markdown")
                        LOCKED = True
                        self.nsg.end()
                        self.prepare = False
                        content = json.loads('{"game":"skyrim"}')
                        req = requests.post("[REDACTED]", content)
                    else:
                        msg = "SKYRIM\nBypass utilized...Take action to get to a proper menu before something messes up."
                        bot.send_message(chat_id, msg, parse_mode="markdown")
                        bypass = True
                        DEBUG = True
                        LOCKED = True
                        content = json.loads('{"game":"skyrim"}')
                        req = requests.post("[REDACTED]", content)
            except:
                if (game_main_menu(frame) or game_main_menu_2(frame)
                        or home_menu(frame)
                        or settings_menu(frame)) and not LOCKED and not DEBUG:
                    if not (i < 100 or bypass):
                        player = json.loads(json.dumps(
                            self.curUser))[0]['username']
                        msg = "SKYRIM\nGame locked due to either being at home screen or capture card bars. \nUser's information are as follows:\n> " + player + "\n> " + self.userID
                        bot.send_message(chat_id, msg, parse_mode="markdown")
                        LOCKED = True
                        self.nsg.end()
                        self.prepare = False
                        content = json.loads('{"game":"skyrim"}')
                        req = requests.post("[REDACTED]", content)
                    else:
                        msg = "SKYRIM\nBypass utilized...Take action to get to a proper menu before something messes up."
                        bot.send_message(chat_id, msg, parse_mode="markdown")
                        bypass = True
                        DEBUG = True
                        LOCKED = True
                        content = json.loads('{"game":"skyrim"}')
                        req = requests.post("[REDACTED]", content)

            if LOCKED:
                self.io.send_playing_ended()
                self.prepare = True

            # generic
            if i % 100 == 0:
                allowReset = True
            if SAVE_ALL_FRAMES or save_individual_fame:
                cv2.imwrite(f"{SAVE_DIR_PATH}/{i}.jpg", frame)
                logging.info(f"SAVED {i}.jpg")
            i += 1
Ejemplo n.º 8
0
    async def on_init(self):
        # init controls
        self.nsg = NSGamepadSerial()
        self.nsg.begin()
        self.io.register_inputs({
            "left_joystick":
            NSJoystick(self.nsg.leftXAxis, self.nsg.leftYAxis),
            "dpad_up":
            NSDPadSwitch(self.nsg, NSDPad.UP),
            "dpad_left":
            NSDPadSwitch(self.nsg, NSDPad.LEFT),
            "dpad_right":
            NSDPadSwitch(self.nsg, NSDPad.RIGHT),
            "dpad_down":
            NSDPadSwitch(self.nsg, NSDPad.DOWN),
            "X":
            NSSwitch(self.nsg, NSButton.X),
            "A":
            NSSwitch(self.nsg, NSButton.A),
            "B":
            NSSwitch(self.nsg, NSButton.B),
            "left_throttle":
            NSSwitch(self.nsg, NSButton.LEFT_THROTTLE),
            "right_throttle":
            NSSwitch(self.nsg, NSButton.RIGHT_THROTTLE),
        })
        self.io.register_inputs(
            {
                "right_joystick":
                NSJoystick(self.nsg.rightXAxis, self.nsg.rightYAxis),
                "Y":
                NSSwitch(self.nsg, NSButton.Y),
                "left_trigger":
                NSSwitch(self.nsg, NSButton.LEFT_TRIGGER),
                "right_trigger":
                NSSwitch(self.nsg, NSButton.RIGHT_TRIGGER),
                "minus":
                NSSwitch(self.nsg, NSButton.MINUS),
                "plus":
                NSSwitch(self.nsg, NSButton.PLUS),
                "left_stick":
                NSSwitch(self.nsg, NSButton.LEFT_STICK),
                "right_stick":
                NSSwitch(self.nsg, NSButton.RIGHT_STICK),
                "home":
                NSSwitch(self.nsg, NSButton.HOME),
                "capture":
                NSSwitch(self.nsg, NSButton.CAPTURE),
            },
            admin=True,
        )

        # get detectors
        self.has_4_ready_to_start = get_pixel_detector(HAS_4_READY_PIXELS)
        self.has_flag = get_pixel_detector(FLAG_PIXELS)
        self.has_finish_text = get_pixel_detector(FINISH_TEXT_PIXELS)
        self.position_detectors = {
            1: get_pixel_detector(POS_1_PIXELS),
            2: get_pixel_detector(POS_2_PIXELS),
            3: get_pixel_detector(POS_3_PIXELS),
            4: get_pixel_detector(POS_4_PIXELS),
        }

        # init image rec
        self.image_rec_task = asyncio.create_task(self.image_rec_main())
        self.image_rec_task.add_done_callback(self.image_rec_done_cb)
        self.image_rec_task_cancelled = False

        # frame saving
        if SAVE_FRAMES:
            logging.info(f"SAVING FRAMES TO {SAVE_DIR_PATH}")
            Path(SAVE_DIR_PATH).mkdir(parents=True, exist_ok=True)

        if SAVE_POS_FRAMES:
            logging.info(f"SAVING POS FRAMES TO {SAVE_POS_DIR_PATH}")
            Path(SAVE_POS_DIR_PATH).mkdir(parents=True, exist_ok=True)

        # game state
        self.has_started = False
        self.has_finished = False
        self.failed_score_reads = 0
        self.pre_game_ready_sent = False
        self.score_sent = False
Ejemplo n.º 9
0
    3. shows one digit on each position for manual checking
            """)
        sys.exit(0)

    import cv2
    import pathlib
    from surrortg.image_recognition import get_pixel_detector
    from games.ninswitch.game_irlkart import (
        POS_1_PIXELS,
        POS_2_PIXELS,
        POS_3_PIXELS,
        POS_4_PIXELS,
    )

    position_detectors = {
        1: get_pixel_detector(POS_1_PIXELS),
        2: get_pixel_detector(POS_2_PIXELS),
        3: get_pixel_detector(POS_3_PIXELS),
        4: get_pixel_detector(POS_4_PIXELS),
    }

    def get_position(frame):
        detected = None
        for position in position_detectors.keys():
            if position_detectors[position](frame):
                detected = position
                break
        return detected

    path = sys.argv[1]