async def test_execute_remote_patches(connector: EchoesRemoteConnector,
                                      version: EchoesDolVersion, mocker):
    # Setup
    patch_address, patch_bytes = MagicMock(), MagicMock()
    mock_remote_execute: MagicMock = mocker.patch(
        "randovania.patching.prime.all_prime_dol_patches.create_remote_execution_body",
        return_value=(patch_address, patch_bytes))

    executor = AsyncMock()

    memory_op_a = MemoryOperation(1234, write_bytes=b"1234")
    instructions = [BaseInstruction(), BaseInstruction()]
    patches = [
        DolRemotePatch([memory_op_a], instructions[:1]),
        DolRemotePatch([], instructions[1:]),
    ]
    memory_operations = [
        memory_op_a,
        MemoryOperation(patch_address, write_bytes=patch_bytes),
        MemoryOperation(version.cstate_manager_global + 0x2,
                        write_bytes=b"\x01"),
    ]

    # Run
    await connector.execute_remote_patches(executor, patches)

    # Assert
    mock_remote_execute.assert_called_once_with(version.string_display,
                                                instructions)
    executor.perform_memory_operations.assert_awaited_once_with(
        memory_operations)
async def test_find_missing_remote_pickups_give_pickup(
        connector: EchoesRemoteConnector, version: EchoesDolVersion, mocker,
        in_cooldown):
    # Setup
    mock_item_patch: MagicMock = mocker.patch(
        "randovania.patching.prime.all_prime_dol_patches.increment_item_capacity_patch"
    )
    mock_call_display_hud_patch: MagicMock = mocker.patch(
        "randovania.patching.prime.all_prime_dol_patches.call_display_hud_patch"
    )

    pickup_patches = MagicMock()
    connector._write_string_to_game_buffer = MagicMock()
    connector._patches_for_pickup = AsyncMock(
        return_value=([pickup_patches, pickup_patches], "The Message"))

    executor = AsyncMock()
    inventory = {
        connector.game.resource_database.multiworld_magic_item:
        InventoryItem(0, 0)
    }
    permanent_pickups = [
        ("A", MagicMock()),
        ("B", MagicMock()),
    ]

    # Run
    patches, has_message = await connector.find_missing_remote_pickups(
        executor, inventory, permanent_pickups, in_cooldown)

    # Assert
    if in_cooldown:
        assert patches == []
        assert not has_message
        mock_item_patch.assert_not_called()
        connector._patches_for_pickup.assert_not_called()
        connector._write_string_to_game_buffer.assert_not_called()
        mock_call_display_hud_patch.assert_not_called()
        return

    mock_item_patch.assert_called_once_with(
        version.powerup_functions, RandovaniaGame.METROID_PRIME_ECHOES,
        connector.game.resource_database.multiworld_magic_item.extra["item_id"]
    )
    connector._patches_for_pickup.assert_awaited_once_with(
        permanent_pickups[0][0], permanent_pickups[0][1], inventory)
    assert has_message
    assert patches == [
        DolRemotePatch([], pickup_patches),
        DolRemotePatch([], pickup_patches),
        DolRemotePatch([], mock_item_patch.return_value),
        DolRemotePatch(
            [connector._write_string_to_game_buffer.return_value],
            mock_call_display_hud_patch.return_value,
        ),
    ]
    connector._write_string_to_game_buffer.assert_called_once_with(
        "The Message")
    mock_call_display_hud_patch.assert_called_once_with(version.string_display)
Example #3
0
async def test_update_inventory_label(executor: DebugExecutorWindow,
                                      echoes_resource_database):
    # Setup
    await executor._ensure_initialized_game_memory()
    connector = PrimeRemoteConnector(executor._used_version)

    await connector.execute_remote_patches(
        executor,
        [
            DolRemotePatch([],
                           all_prime_dol_patches.increment_item_capacity_patch(
                               executor._used_version.powerup_functions,
                               echoes_resource_database.game_enum,
                               echoes_resource_database.multiworld_magic_item.
                               extra["item_id"],
                               delta=2,
                           )),
            DolRemotePatch(
                [],
                all_prime_dol_patches.adjust_item_amount_and_capacity_patch(
                    executor._used_version.powerup_functions,
                    echoes_resource_database.game_enum,
                    echoes_resource_database.energy_tank.extra["item_id"],
                    delta=4,
                )),
        ],
    )
    executor._handle_remote_execution()

    # Run
    await executor._update_inventory_label()

    # Assert
    assert "Energy Tank x 4/4" in executor.inventory_label.text()
    assert "Multiworld Magic Identifier x 0/2" in executor.inventory_label.text(
    )
async def test_known_collected_locations_location(
        connector: EchoesRemoteConnector, version: EchoesDolVersion, mocker,
        capacity):
    # Setup
    mock_item_patch: MagicMock = mocker.patch(
        "randovania.patching.prime.all_prime_dol_patches.adjust_item_amount_and_capacity_patch"
    )

    executor = AsyncMock()
    executor.perform_single_memory_operation.return_value = struct.pack(
        ">II", 10, 10 + capacity)

    # Run
    locations, patches = await connector.known_collected_locations(executor)

    # Assert
    mock_item_patch.assert_called_once_with(
        version.powerup_functions, RandovaniaGame.METROID_PRIME_ECHOES,
        connector.game.resource_database.multiworld_magic_item.
        extra["item_id"], -10)

    assert locations == {PickupIndex(9)}
    assert patches == [DolRemotePatch([], mock_item_patch.return_value)]