Пример #1
0
def create_backend(debug_game_backend: bool, options):
    from randovania.interface_common.options import Options
    options = typing.cast(Options, options)

    logger.info("Preparing game backend...")
    if debug_game_backend:
        from randovania.gui.debug_backend_window import DebugBackendWindow
        backend = DebugBackendWindow()
        backend.show()
    else:
        try:
            from randovania.game_connection.dolphin_backend import DolphinBackend
        except ImportError:
            from randovania.gui.lib import common_qt_lib
            common_qt_lib.show_install_visual_cpp_redist()
            raise SystemExit(1)

        from randovania.game_connection.nintendont_backend import NintendontBackend
        from randovania.game_connection.backend_choice import GameBackendChoice

        logger.info("Loaded all game backends...")
        if options.game_backend == GameBackendChoice.NINTENDONT and options.nintendont_ip is not None:
            backend = NintendontBackend(options.nintendont_ip)
        else:
            backend = DolphinBackend()

    logger.info("Game backend configured: %s", type(backend))
    return backend
Пример #2
0
async def test_perform_memory_operations_invalid(backend: NintendontBackend):
    backend._socket = MagicMock()
    backend._socket.max_input = 120
    backend._socket.max_output = 100
    backend._socket.max_addresses = 8
    backend._socket.writer.drain = AsyncMock()
    backend._socket.reader.read = AsyncMock(side_effect=[
        b"\x03" + b"A" * 50 + b"B" * 30,
    ])

    # Run
    with pytest.raises(MemoryOperationException):
        await backend._perform_memory_operations([
            MemoryOperation(0x1000, read_byte_count=50),
            MemoryOperation(0x2000, read_byte_count=10),
            MemoryOperation(0x2000, read_byte_count=10),
        ])

    # Assert
    backend._socket.writer.drain.assert_has_awaits([call()])
    backend._socket.writer.write.assert_has_calls([
        call(
            b'\x00\x03\x02\x01\x00\x00\x10\x00\x00\x00 \x00\x802\x81\n\x81\n'),
    ])
    backend._socket.reader.read.assert_has_awaits([call(1024)])
Пример #3
0
async def test_perform_memory_operations_success(backend: NintendontBackend):
    backend._socket = MagicMock()
    backend._socket.max_input = 120
    backend._socket.max_output = 100
    backend._socket.max_addresses = 8
    backend._socket.writer.drain = AsyncMock()
    backend._socket.reader.read = AsyncMock(side_effect=[
        b"\x03" + b"A" * 50 + b"B" * 30,
        b"\x01" + b"C" * 60,
    ])
    ops = {
        MemoryOperation(0x1000, read_byte_count=50):
        b"A" * 50,
        MemoryOperation(0x1000,
                        offset=10,
                        read_byte_count=30,
                        write_bytes=b"1" * 30):
        b"B" * 30,
        MemoryOperation(0x1000, read_byte_count=60):
        b"C" * 60,
    }

    # Run
    result = await backend._perform_memory_operations(list(ops.keys()))

    # Assert
    backend._socket.writer.drain.assert_has_awaits([call(), call()])
    backend._socket.writer.write.assert_has_calls([
        call(b'\x00\x02\x01\x01\x00\x00\x10\x00' + b'\x80\x32' +
             b'\xd0\x1e\x00\n' + (b"1" * 30)),
        call(b'\x00\x01\x01\x01\x00\x00\x10\x00\x80\x3c'),
    ])
    assert result == ops
    backend._socket.reader.read.assert_has_awaits([call(1024), call(1024)])
Пример #4
0
    async def on_use_nintendont_backend(self):
        dialog = QtWidgets.QInputDialog(self.parent)
        dialog.setModal(True)
        dialog.setWindowTitle("Enter Wii's IP")
        dialog.setLabelText(
            "Enter the IP address of your Wii. "
            "You can check the IP address on the pause screen of Homebrew Channel."
        )
        if self.options.nintendont_ip is not None:
            dialog.setTextValue(self.options.nintendont_ip)

        if await async_dialog.execute_dialog(dialog) == dialog.Accepted:
            new_ip = dialog.textValue()
            if new_ip != "":
                if not self.options.is_alert_displayed(
                        InfoAlert.NINTENDONT_UNSTABLE):
                    await async_dialog.warning(
                        self.parent, "Nintendont Limitation",
                        "Warning: The Nintendont integration isn't perfect and is known to "
                        "crash.")
                    self.options.mark_alert_as_displayed(
                        InfoAlert.NINTENDONT_UNSTABLE)

                with self.options as options:
                    options.nintendont_ip = new_ip
                    options.game_backend = GameBackendChoice.NINTENDONT
                self.game_connection.set_backend(NintendontBackend(new_ip))
        self.refresh_backend()
Пример #5
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--nintendont", help="Connect to the given IP via the Nintendont protocol instead.")
    args = parser.parse_args()

    app = QCoreApplication(sys.argv)

    os.environ['QT_API'] = "PySide2"
    import qasync
    loop = qasync.QEventLoop(app)
    asyncio.set_event_loop(loop)

    logging.config.dictConfig({
        'version': 1,
        'formatters': {
            'default': {
                'format': '[%(asctime)s] [%(levelname)s] [%(name)s] %(funcName)s: %(message)s',
            }
        },
        'handlers': {
            'default': {
                'level': 'DEBUG',
                'formatter': 'default',
                'class': 'logging.StreamHandler',
                'stream': 'ext://sys.stdout',  # Default is stderr
            },
        },
        'loggers': {
        },
        'root': {
            'level': 'DEBUG',
            'handlers': ['default'],
        },
    })

    def catch_exceptions(t, val, tb):
        global should_quit
        should_quit = True
        old_hook(t, val, tb)

    def catch_exceptions_async(loop, context):
        if 'future' in context:
            future: asyncio.Future = context['future']
            logging.exception(context["message"], exc_info=future.exception())
        else:
            logging.critical(str(context))

    sys.excepthook = catch_exceptions
    loop.set_exception_handler(catch_exceptions_async)

    if args.nintendont is not None:
        backend = NintendontBackend(args.nintendont)
    else:
        backend = DolphinBackend()

    with loop:
        try:
            asyncio.get_event_loop().run_until_complete(worker(app, backend))
        finally:
            app.quit()
Пример #6
0
def create_backend(debug_game_backend: bool, options):
    from randovania.interface_common.options import Options
    options = typing.cast(Options, options)

    if debug_game_backend:
        from randovania.gui.debug_backend_window import DebugBackendWindow
        backend = DebugBackendWindow()
        backend.show()
    else:
        from randovania.game_connection.dolphin_backend import DolphinBackend
        from randovania.game_connection.nintendont_backend import NintendontBackend
        from randovania.game_connection.backend_choice import GameBackendChoice

        if options.game_backend == GameBackendChoice.NINTENDONT and options.nintendont_ip is not None:
            backend = NintendontBackend(options.nintendont_ip)
        else:
            backend = DolphinBackend()

    return backend
Пример #7
0
async def test_perform_single_giant_memory_operation(
        backend: NintendontBackend):
    backend._socket = MagicMock()
    backend._socket.max_input = 120
    backend._socket.max_output = 100
    backend._socket.max_addresses = 8
    backend._socket.writer.drain = AsyncMock()
    backend._socket.reader.read = AsyncMock(side_effect=[
        b"\x01",
        b"\x01",
    ])

    # Run
    result = await backend._perform_single_memory_operations(
        MemoryOperation(0x1000, write_bytes=b"1" * 200), )

    # Assert
    backend._socket.writer.drain.assert_has_awaits([call(), call()])
    backend._socket.writer.write.assert_has_calls([
        call(b'\x00\x01\x01\x01\x00\x00\x10\x00' + b'\x40\x64' + (b"1" * 100)),
        call(b'\x00\x01\x01\x01\x00\x00\x10\x64' + b'\x40\x64' + (b"1" * 100)),
    ])
    assert result is None
    backend._socket.reader.read.assert_has_awaits([call(1024), call(1024)])
Пример #8
0
def nintendont_backend():
    backend = NintendontBackend("localhost")
    return backend