Beispiel #1
0
def test_rstb():
    buf = bytearray(388352)
    assert rstb.guess_bfres_size(memoryview(buf), True,
                                 "Link.sbfres") >= 498776
    buf = bytearray(1609904)
    assert rstb.guess_bfres_size(memoryview(buf), False,
                                 "Link.Tex.sbfres") >= 1619112
    buf = bytearray(436)
    assert rstb.guess_aamp_size(memoryview(buf), True, ".bxml") >= 1940
    assert rstb.guess_aamp_size(memoryview(buf), False, ".bxml") >= 2792
Beispiel #2
0
def calculate_size(
    path: Union[Path, str], data: ByteString = None, guess: bool = True
) -> int:
    ext = path.suffix if isinstance(path, Path) else path[path.rindex(".") :]
    data = util.unyaz_if_needed(path.read_bytes() if isinstance(path, Path) else data)
    try:
        be = util.get_settings("wiiu")  # pylint: disable=invalid-name
        size = getattr(calculate_size, "calculator").calculate_file_size_with_ext(
            data, wiiu=be, ext=ext, force=False
        )
        if ext == ".bdmgparam":
            size = 0
        if ext == ".hkrb":
            size += 40
        if ext == ".baniminfo":
            size = int(
                (((len(data) + 31) & -32) * (1.5 if len(data) > 36864 else 4))
                + 0xE4
                + 0x24C
            )
            if not be:
                size = int(size * 1.5)
        if size == 0 and guess:
            if ext in util.AAMP_EXTS:
                size = guess_aamp_size(data, be, ext)
            elif ext in {".bfres", ".sbfres"}:
                size = guess_bfres_size(
                    data, be, path if isinstance(path, str) else path.name,
                )
        return size
    except struct.error:
        return 0
def _get_rstb_val(name: str, data: bytes, should_guess: bool, be: bool) -> int:
    if not hasattr(_get_rstb_val, "calc"):
        setattr(_get_rstb_val, "calc", SizeCalculator())
    ext = name[name.rindex(".") :]
    if data[:4] == b"Yaz0":
        data = oead.yaz0.decompress(data)
    val = _get_rstb_val.calc.calculate_file_size_with_ext(  # pylint: disable=no-member
        data, wiiu=be, ext=ext
    )
    if ext == ".bdmgparam":
        val += 1000
    elif ext == ".hkrb":
        val += 40
    if val == 0 and should_guess:
        if ext in AAMP_EXTS:
            val = guess_aamp_size(data, be, ext)
        elif ext in {".bfres", ".sbfres"}:
            val = guess_bfres_size(data, be, name)
        elif ext == ".baniminfo":
            val = int(
                (((len(data) + 31) & -32) * (1.5 if len(data) > 36864 else 4))
                + 0xE4
                + 0x24C
            )
            if not be:
                val *= 1.5
    return val
Beispiel #4
0
def get_rstb_value(filename: str, data: ByteString, wiiu: bool) -> (int, bool):
    ext = filename[filename.rindex("."):]
    value = get_rstb_calc().calculate_file_size_with_ext(data, wiiu, ext)
    if value and ext != ".bdmgparam":
        return value, False
    else:
        from botw import rstb, extensions

        if ext in {".bfres", ".sbfres"}:
            return rstb.guess_bfres_size(bytes(data), wiiu, filename), True
        elif ext in extensions.AAMP_EXTS:
            return rstb.guess_aamp_size(bytes(data), wiiu, ext), True
        else:
            return 0, False
Beispiel #5
0
 def _get_rstb_val(self, name: str, data: bytes) -> int:
     ext = name[name.rindex("."):]
     if data[:4] == b"Yaz0":
         data = oead.yaz0.decompress(data)
     val = self._calc.calculate_file_size_with_ext(data,
                                                   wiiu=self.be,
                                                   ext=ext)
     if ext == ".bdmgparam":
         val += 1000
     elif ext == ".hkrb":
         val += 40
     if val == 0 and self.guess:
         if ext in AAMP_EXTS:
             val = guess_aamp_size(data, self.be, ext)
         elif ext in {".bfres", ".sbfres"}:
             val = guess_bfres_size(data, self.be, name)
         elif ext == ".baniminfo":
             val = int((((len(data) + 31) & -32) *
                        (1.5 if len(data) > 36864 else 4)) + 0xE4 + 0x24C)
             if not self.be:
                 val *= 1.5
     return val