How to use bcml - 10 common examples

To help you get started, we’ve selected a few bcml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NiceneNerd / BCML / bcml / mergers / shop.py View on Github external
def generate_diff(
        self, mod_dir: Path, modded_files: List[Union[Path, str]]
    ) -> ParameterIO:
        print("Logging changes to shop files...")
        diffs = ParameterIO()
        file_names = ParameterObject()
        for file in [file for file in modded_files if Path(file).suffix in EXT_FOLDERS]:
            try:
                mod_bytes = util.get_nested_file_bytes(str(mod_dir) + "/" + str(file))
                nests = str(file).split("//", 1)
                ref_path = str(util.get_game_file(Path(nests[0]))) + "//" + nests[1]
                ref_bytes = util.get_nested_file_bytes(ref_path)
                shop_type = str(file).split(".")[-1]

                mod_pio = get_named_pio(ParameterIO.from_binary(mod_bytes), shop_type)
                ref_pio = get_named_pio(ParameterIO.from_binary(ref_bytes), shop_type)

                file_names.params[oead.aamp.Name(file).hash] = Parameter(file)
                diffs.lists[file] = gen_diffs(ref_pio, mod_pio)
            except (FileNotFoundError, KeyError, AttributeError):
                continue
        diffs.objects["Filenames"] = file_names
        return diffs
github NiceneNerd / BCML / bcml / merge.py View on Github external
:type file: class:`typing.Union[class:pathlib.Path, str]`
    :param tmp_dir: The temp directory containing the mod
    :type tmp_dir: class:`pathlib.Path`
    :return: Returns a string representation of the AAMP file diff
    """
    if isinstance(file, str):
        nests = file.split('//')
        mod_bytes = util.get_nested_file_bytes(file)
        ref_path = str(util.get_game_file(
            Path(nests[0]).relative_to(tmp_dir))) + '//' + '//'.join(nests[1:])
        ref_bytes = util.get_nested_file_bytes(ref_path)
    else:
        with file.open('rb') as m_file:
            mod_bytes = m_file.read()
        mod_bytes = util.unyaz_if_needed(mod_bytes)
        with util.get_game_file(file.relative_to(tmp_dir)).open('rb') as r_file:
            ref_bytes = r_file.read()
        ref_bytes = util.unyaz_if_needed(ref_bytes)

    ref_aamp = aamp.Reader(ref_bytes).parse()
    mod_aamp = aamp.Reader(mod_bytes).parse()

    return _aamp_diff(ref_aamp, mod_aamp)
github NiceneNerd / BCML / bcml / rstable.py View on Github external
if size == 0 and not self._options['no_guess']:
                        if file.suffix in util.AAMP_EXTS:
                            size = guess_aamp_size(file)
                        elif file.suffix in ['.bfres', '.sbfres']:
                            size = guess_bfres_size(file)
                    rstb_diff[file] = size
            elif isinstance(file, str):
                parts = file.split('//')
                name = parts[-1]
                if parts[0] not in open_sarcs:
                    with (mod_dir / parts[0]).open('rb') as s_file:
                        open_sarcs[parts[0]] = sarc.read_file_and_make_sarc(s_file)
                for part in parts[1:-1]:
                    if part not in open_sarcs:
                        open_sarcs[part] = sarc.SARC(
                            util.unyaz_if_needed(
                                open_sarcs[parts[parts.index(part) - 1]]\
                                    .get_file_data(part).tobytes()
                            )
                        )
                ext = Path(name).suffix
                data = util.unyaz_if_needed(open_sarcs[parts[-2]].get_file_data(name).tobytes())
                rstb_val = rstb.SizeCalculator().calculate_file_size_with_ext(
                    data,
                    wiiu=True,
                    ext=ext
                )
                if ext == '.bdmgparam':
                    rstb_val = 0
                if rstb_val == 0 and (not self._options['no_guess'] or ext in ['.bas', '.baslist']):
                    if ext in util.AAMP_EXTS:
                        rstb_val = guess_aamp_size(data, ext)
github NiceneNerd / BCML / bcml / merge.py View on Github external
:param file: The modded AAMP file to diff
    :type file: class:`typing.Union[class:pathlib.Path, str]`
    :param tmp_dir: The temp directory containing the mod
    :type tmp_dir: class:`pathlib.Path`
    :return: Returns a string representation of the AAMP file diff
    """
    if isinstance(file, str):
        nests = file.split('//')
        mod_bytes = util.get_nested_file_bytes(file)
        ref_path = str(util.get_game_file(
            Path(nests[0]).relative_to(tmp_dir))) + '//' + '//'.join(nests[1:])
        ref_bytes = util.get_nested_file_bytes(ref_path)
    else:
        with file.open('rb') as m_file:
            mod_bytes = m_file.read()
        mod_bytes = util.unyaz_if_needed(mod_bytes)
        with util.get_game_file(file.relative_to(tmp_dir)).open('rb') as r_file:
            ref_bytes = r_file.read()
        ref_bytes = util.unyaz_if_needed(ref_bytes)

    ref_aamp = aamp.Reader(ref_bytes).parse()
    mod_aamp = aamp.Reader(mod_bytes).parse()

    return _aamp_diff(ref_aamp, mod_aamp)
github NiceneNerd / BCML / bcml / rstable.py View on Github external
elif isinstance(file, str):
                parts = file.split('//')
                name = parts[-1]
                if parts[0] not in open_sarcs:
                    with (mod_dir / parts[0]).open('rb') as s_file:
                        open_sarcs[parts[0]] = sarc.read_file_and_make_sarc(s_file)
                for part in parts[1:-1]:
                    if part not in open_sarcs:
                        open_sarcs[part] = sarc.SARC(
                            util.unyaz_if_needed(
                                open_sarcs[parts[parts.index(part) - 1]]\
                                    .get_file_data(part).tobytes()
                            )
                        )
                ext = Path(name).suffix
                data = util.unyaz_if_needed(open_sarcs[parts[-2]].get_file_data(name).tobytes())
                rstb_val = rstb.SizeCalculator().calculate_file_size_with_ext(
                    data,
                    wiiu=True,
                    ext=ext
                )
                if ext == '.bdmgparam':
                    rstb_val = 0
                if rstb_val == 0 and (not self._options['no_guess'] or ext in ['.bas', '.baslist']):
                    if ext in util.AAMP_EXTS:
                        rstb_val = guess_aamp_size(data, ext)
                    elif ext in ['.bfres', '.sbfres']:
                        rstb_val = guess_bfres_size(data, name)
                rstb_diff[file] = rstb_val
        for open_sarc in open_sarcs:
            del open_sarc
        return rstb_diff
github NiceneNerd / BCML / bcml / mergers / drop.py View on Github external
def merge_drop_file(file: str, drop_table: dict):
    base_path = file[: file.index("//")]
    sub_path = file[file.index("//") :]
    try:
        ref_drop = _drop_to_dict(
            ParameterIO.from_binary(
                util.get_nested_file_bytes(str(util.get_game_file(base_path)) + sub_path)
            )
        )
        for table in set(ref_drop.keys()):
            if table not in drop_table:
                del ref_drop[table]
            else:
                for item in set(ref_drop[table]["items"].keys()):
                    if item not in drop_table[table]["items"]:
                        del ref_drop[table]["items"][item]
        util.dict_merge(ref_drop, drop_table)
        drop_table = ref_drop
    except (FileNotFoundError, AttributeError, RuntimeError):
        pass
    actor_name = re.search(r"Pack\/(.+)\.sbactorpack", file).groups()[0]
    pio = _dict_to_drop(drop_table)
    util.inject_files_into_actor(actor_name, {file.split("//")[-1]: pio.to_binary()})
github NiceneNerd / BCML / bcml / mergers / shop.py View on Github external
def generate_diff(
        self, mod_dir: Path, modded_files: List[Union[Path, str]]
    ) -> ParameterIO:
        print("Logging changes to shop files...")
        diffs = ParameterIO()
        file_names = ParameterObject()
        for file in [file for file in modded_files if Path(file).suffix in EXT_FOLDERS]:
            try:
                mod_bytes = util.get_nested_file_bytes(str(mod_dir) + "/" + str(file))
                nests = str(file).split("//", 1)
                ref_path = str(util.get_game_file(Path(nests[0]))) + "//" + nests[1]
                ref_bytes = util.get_nested_file_bytes(ref_path)
                shop_type = str(file).split(".")[-1]

                mod_pio = get_named_pio(ParameterIO.from_binary(mod_bytes), shop_type)
                ref_pio = get_named_pio(ParameterIO.from_binary(ref_bytes), shop_type)

                file_names.params[oead.aamp.Name(file).hash] = Parameter(file)
                diffs.lists[file] = gen_diffs(ref_pio, mod_pio)
            except (FileNotFoundError, KeyError, AttributeError):
                continue
        diffs.objects["Filenames"] = file_names
        return diffs
github NiceneNerd / BCML / bcml / merge.py View on Github external
def get_aamp_diff(file: Union[Path, str], tmp_dir: Path):
    """
    Diffs a modded AAMP file from the stock game version

    :param file: The modded AAMP file to diff
    :type file: class:`typing.Union[class:pathlib.Path, str]`
    :param tmp_dir: The temp directory containing the mod
    :type tmp_dir: class:`pathlib.Path`
    :return: Returns a string representation of the AAMP file diff
    """
    if isinstance(file, str):
        nests = file.split('//')
        mod_bytes = util.get_nested_file_bytes(file)
        ref_path = str(util.get_game_file(
            Path(nests[0]).relative_to(tmp_dir))) + '//' + '//'.join(nests[1:])
        ref_bytes = util.get_nested_file_bytes(ref_path)
    else:
        with file.open('rb') as m_file:
            mod_bytes = m_file.read()
        mod_bytes = util.unyaz_if_needed(mod_bytes)
        with util.get_game_file(file.relative_to(tmp_dir)).open('rb') as r_file:
            ref_bytes = r_file.read()
        ref_bytes = util.unyaz_if_needed(ref_bytes)

    ref_aamp = aamp.Reader(ref_bytes).parse()
    mod_aamp = aamp.Reader(mod_bytes).parse()

    return _aamp_diff(ref_aamp, mod_aamp)
github NiceneNerd / BCML / bcml / mergers / shop.py View on Github external
def generate_diff(
        self, mod_dir: Path, modded_files: List[Union[Path, str]]
    ) -> ParameterIO:
        print("Logging changes to shop files...")
        diffs = ParameterIO()
        file_names = ParameterObject()
        for file in [file for file in modded_files if Path(file).suffix in EXT_FOLDERS]:
            try:
                mod_bytes = util.get_nested_file_bytes(str(mod_dir) + "/" + str(file))
                nests = str(file).split("//", 1)
                ref_path = str(util.get_game_file(Path(nests[0]))) + "//" + nests[1]
                ref_bytes = util.get_nested_file_bytes(ref_path)
                shop_type = str(file).split(".")[-1]

                mod_pio = get_named_pio(ParameterIO.from_binary(mod_bytes), shop_type)
                ref_pio = get_named_pio(ParameterIO.from_binary(ref_bytes), shop_type)

                file_names.params[oead.aamp.Name(file).hash] = Parameter(file)
                diffs.lists[file] = gen_diffs(ref_pio, mod_pio)
            except (FileNotFoundError, KeyError, AttributeError):
                continue
        diffs.objects["Filenames"] = file_names
        return diffs
github NiceneNerd / BCML / bcml / merge.py View on Github external
def get_aamp_diff(file: Union[Path, str], tmp_dir: Path):
    """
    Diffs a modded AAMP file from the stock game version

    :param file: The modded AAMP file to diff
    :type file: class:`typing.Union[class:pathlib.Path, str]`
    :param tmp_dir: The temp directory containing the mod
    :type tmp_dir: class:`pathlib.Path`
    :return: Returns a string representation of the AAMP file diff
    """
    if isinstance(file, str):
        nests = file.split('//')
        mod_bytes = util.get_nested_file_bytes(file)
        ref_path = str(util.get_game_file(
            Path(nests[0]).relative_to(tmp_dir))) + '//' + '//'.join(nests[1:])
        ref_bytes = util.get_nested_file_bytes(ref_path)
    else:
        with file.open('rb') as m_file:
            mod_bytes = m_file.read()
        mod_bytes = util.unyaz_if_needed(mod_bytes)
        with util.get_game_file(file.relative_to(tmp_dir)).open('rb') as r_file:
            ref_bytes = r_file.read()
        ref_bytes = util.unyaz_if_needed(ref_bytes)

    ref_aamp = aamp.Reader(ref_bytes).parse()
    mod_aamp = aamp.Reader(mod_bytes).parse()

    return _aamp_diff(ref_aamp, mod_aamp)