Esempio n. 1
0
    def get_game_export_params(self) -> GameExportParams:
        spoiler_output = spoiler_path_for(self.auto_save_spoiler,
                                          self.output_file)
        cache_path = self._options.internal_copies_path.joinpath(
            "prime1", "randomprime_cache")
        asset_cache_path = self._options.internal_copies_path.joinpath(
            "prime1", "prime2_models")

        if self._use_echoes_models:
            backup_files_path = self._options.internal_copies_path.joinpath(
                "prime2", "vanilla")
        else:
            backup_files_path = None

        return PrimeGameExportParams(
            spoiler_output=spoiler_output,
            input_path=self.input_file,
            output_path=self.output_file,
            echoes_input_path=self.echoes_file,
            echoes_contents_path=self._echoes_contents_path,
            echoes_backup_path=backup_files_path,
            asset_cache_path=asset_cache_path,
            use_echoes_models=self._use_echoes_models,
            cache_path=cache_path,
        )
Esempio n. 2
0
def test_get_game_export_params(skip_qtbot, tmp_path, is_echoes_multi, use_external_models):
    # Setup
    games = [RandovaniaGame.METROID_PRIME]
    if is_echoes_multi:
        games.append(RandovaniaGame.METROID_PRIME_ECHOES)
        echoes_path = tmp_path.joinpath("input/echoes.iso")
    else:
        echoes_path = None

    if use_external_models:
        models = {RandovaniaGame.METROID_PRIME_ECHOES}
    else:
        models = {}

    options = MagicMock()
    options.internal_copies_path = tmp_path.joinpath("internal_copies")
    options.options_for_game.side_effect = [PrimePerGameOptions(
        cosmetic_patches=PrimeCosmeticPatches.default(),
        input_path=tmp_path.joinpath("input/game.iso"),
        output_directory=tmp_path.joinpath("output"),
        output_format="iso",
        use_external_models=models,
    ),
        EchoesPerGameOptions(
            cosmetic_patches=EchoesCosmeticPatches.default(),
            input_path=echoes_path
        )]

    expected_backup_path = None
    expected_contents_path = None
    if is_echoes_multi:
        expected_contents_path = tmp_path.joinpath("internal_copies", "prime2", "contents")
        if use_external_models:
            expected_backup_path = tmp_path.joinpath("internal_copies", "prime2", "vanilla")

    window = PrimeGameExportDialog(options, {}, "MyHash", True, games)

    # Run
    result = window.get_game_export_params()

    # Assert
    assert result == PrimeGameExportParams(
        spoiler_output=tmp_path.joinpath("output", "Prime Randomizer - MyHash.rdvgame"),
        input_path=tmp_path.joinpath("input/game.iso"),
        output_path=tmp_path.joinpath("output", "Prime Randomizer - MyHash.iso"),
        echoes_input_path=echoes_path,
        echoes_backup_path=expected_backup_path,
        echoes_contents_path=expected_contents_path,
        asset_cache_path=tmp_path.joinpath("internal_copies", "prime1", "prime2_models"),
        use_echoes_models=is_echoes_multi and use_external_models,
        cache_path=tmp_path.joinpath("internal_copies", "prime1", "randomprime_cache"),
    )
Esempio n. 3
0
def test_room_rando_map_maker(test_files_dir, mocker, tmp_path):
    mock_symbols_for_file: MagicMock = mocker.patch(
        "py_randomprime.symbols_for_file",
        return_value={
            "UpdateHintState__13CStateManagerFf": 0x80044D38,
        })
    mock_patch_iso_raw: MagicMock = mocker.patch(
        "py_randomprime.patch_iso_raw")
    progress_update = MagicMock()

    with test_files_dir.joinpath("randomprime_expected_data_crazy.json").open(
            "r") as file:
        patch_data = json.load(file)

    exporter = PrimeGameExporter()

    # Run
    exporter.export_game(
        patch_data,
        PrimeGameExportParams(
            spoiler_output=tmp_path,
            input_path=tmp_path.joinpath("input.iso"),
            output_path=tmp_path.joinpath("output.iso"),
            echoes_input_path=None,
            echoes_backup_path=None,
            echoes_contents_path=None,
            asset_cache_path=None,
            use_echoes_models=False,
            cache_path=tmp_path.joinpath("cache_path"),
        ), progress_update)

    # Assert
    mock_symbols_for_file.assert_called_once_with(
        tmp_path.joinpath("input.iso"))
    mock_patch_iso_raw.assert_called_once_with(ANY, ANY)

    pngs = [
        f for f in os.listdir(tmp_path)
        if os.path.isfile(os.path.join(tmp_path, f)) and f.endswith(".png")
    ]
    assert len(pngs) == 7
    for png in pngs:
        assert os.path.getsize(os.path.join(tmp_path, png)) > 10_000
Esempio n. 4
0
def test_patch_game(mocker, tmp_path, use_echoes_models):
    mock_symbols_for_file: MagicMock = mocker.patch(
        "py_randomprime.symbols_for_file",
        return_value={
            "UpdateHintState__13CStateManagerFf": 0x80044D38,
        })
    mock_patch_iso_raw: MagicMock = mocker.patch(
        "py_randomprime.patch_iso_raw")
    mock_extract_echoes: MagicMock = mocker.patch(
        "randovania.games.prime2.exporter.game_exporter.extract_and_backup_iso"
    )
    mock_asset_convert: MagicMock = mocker.patch(
        "randovania.patching.prime.asset_conversion.convert_prime2_pickups")
    mocker.patch(
        "randovania.games.prime1.exporter.game_exporter.adjust_model_names")
    patch_data = {
        "patch": "data",
        'gameConfig': {},
        'hasSpoiler': True,
        "preferences": {},
        "roomRandoMode": "None"
    }
    progress_update = MagicMock()

    echoes_input_path = tmp_path.joinpath("echoes.iso")
    echoes_backup_path = tmp_path.joinpath("internal_copies", "prime2",
                                           "backup")
    echoes_contents_path = tmp_path.joinpath("internal_copies", "prime2",
                                             "contents")
    asset_cache_path = tmp_path.joinpath("internal_copies", "prime1",
                                         "prime2_models")

    exporter = PrimeGameExporter()

    # Run
    exporter.export_game(
        patch_data,
        PrimeGameExportParams(
            spoiler_output=None,
            input_path=tmp_path.joinpath("input.iso"),
            output_path=tmp_path.joinpath("output.iso"),
            echoes_input_path=echoes_input_path,
            echoes_backup_path=echoes_backup_path,
            echoes_contents_path=echoes_contents_path,
            asset_cache_path=asset_cache_path,
            use_echoes_models=use_echoes_models,
            cache_path=tmp_path.joinpath("cache_path"),
        ), progress_update)

    # Assert
    expected = {
        "patch": "data",
        'gameConfig': {
            "updateHintStateReplacement": [
                148, 33, 255, 204, 124, 8, 2, 166, 144, 1, 0, 56, 191, 193, 0,
                44, 124, 127, 27, 120, 136, 159, 0, 2, 44, 4, 0, 0, 64, 130, 0,
                24, 187, 193, 0, 44, 128, 1, 0, 56, 124, 8, 3, 166, 56, 33, 0,
                52, 78, 128, 0, 32, 63, 192, 128, 4, 99, 222, 77, 140, 56, 128,
                1, 128, 124, 4, 247, 172, 44, 4, 0, 0, 56, 132, 255, 224, 64,
                130, 255, 244, 124, 0, 4, 172, 76, 0, 1, 44, 56, 192, 0, 0,
                152, 223, 0, 2, 187, 193, 0, 44, 128, 1, 0, 56, 124, 8, 3, 166,
                56, 33, 0, 52, 78, 128, 0, 32
            ]
        },
        "preferences": {
            "cacheDir": os.fspath(tmp_path.joinpath("cache_path")),
        },
        "inputIso": os.fspath(tmp_path.joinpath("input.iso")),
        "outputIso": os.fspath(tmp_path.joinpath("output.iso")),
    }

    if use_echoes_models:
        expected["externAssetsDir"] = os.fspath(asset_cache_path)
        mock_extract_echoes.assert_called_once_with(echoes_input_path,
                                                    echoes_contents_path,
                                                    echoes_backup_path, ANY)
        mock_asset_convert.assert_called_once_with(asset_cache_path, ANY)

    mock_symbols_for_file.assert_called_once_with(
        tmp_path.joinpath("input.iso"))
    mock_patch_iso_raw.assert_called_once_with(
        json.dumps(expected, indent=4, separators=(',', ': ')), ANY)