コード例 #1
0
 def get_data(self):
     if not self._cache:
         buf = self._data_wrapper.get_data_clear()
         if buf[:4] == b"Yaz0":
             buf = wszst_yaz0.decompress(buf)
         self._cache = buf
     return self._cache
コード例 #2
0
ファイル: __main__.py プロジェクト: tiliarou/byml-v2
def byml_to_yml() -> None:
    parser = argparse.ArgumentParser(
        description='Converts a BYML file to YAML.')
    parser.add_argument('byml',
                        help='Path to a BYML file',
                        nargs='?',
                        default='-')
    parser.add_argument('yml',
                        help='Path to destination YAML file',
                        nargs='?',
                        default='-')
    args = parser.parse_args()

    dumper = yaml.CDumper
    yaml.add_representer(byml.Int,
                         lambda d, data: d.represent_int(data),
                         Dumper=dumper)
    yaml.add_representer(byml.Float,
                         lambda d, data: d.represent_float(data),
                         Dumper=dumper)
    yaml.add_representer(
        byml.UInt,
        lambda d, data: d.represent_scalar(u'!u', '0x%08x' % data),
        Dumper=dumper)
    yaml.add_representer(byml.Int64,
                         lambda d, data: d.represent_scalar(u'!l', str(data)),
                         Dumper=dumper)
    yaml.add_representer(byml.UInt64,
                         lambda d, data: d.represent_scalar(u'!ul', str(data)),
                         Dumper=dumper)
    yaml.add_representer(
        byml.Double,
        lambda d, data: d.represent_scalar(u'!f64', str(data)),
        Dumper=dumper)

    file = sys.stdin.buffer if args.byml == '-' else open(args.byml, 'rb')
    with file:
        data = file.read()
        if data[0:4] == b'Yaz0':
            data = wszst_yaz0.decompress(data)
        root = byml.Byml(data).parse()

        if args.byml != '-':
            args.yml = args.yml.replace('!!', os.path.splitext(args.byml)[0])
        elif '!!' in args.yml:
            sys.stderr.write(
                'error: cannot use !! (for input filename) when reading from stdin\n'
            )
            sys.exit(1)
        output = sys.stdout if args.yml == '-' else open(
            args.yml, 'w', encoding='utf-8')
        with output:
            yaml.dump(root,
                      output,
                      Dumper=dumper,
                      allow_unicode=True,
                      encoding='utf-8')
コード例 #3
0
def main() -> None:
    parser = argparse.ArgumentParser(
        'Shows actors that are not spawned when in final boss mode.')
    parser.add_argument(
        'map_path',
        help='Path to a map unit (BYAML or compressed BYAML or YAML)')
    args = parser.parse_args()
    MAP_PATH: str = args.map_path

    byml.yaml_util.add_constructors(yaml.CSafeLoader)
    with open(MAP_PATH, 'rb') as f:
        if MAP_PATH.endswith('mubin'):
            map_data = byml.Byml(wszst_yaz0.decompress(f.read())).parse()
        else:
            map_data = yaml.load(f, Loader=yaml.CSafeLoader)

    pmap = Map(map_data)
    pmap.parse_obj_links()

    skip_reasons: typing.Dict[int, str] = dict()
    skipped_objs: typing.Set[int] = set()
    for obj in pmap.objs.values():
        objid = obj['HashId']
        if objid in skipped_objs or should_spawn_obj(obj):
            continue
        skipped_objs.add(objid)
        gen_group = pmap.build_gen_group(obj)
        for linked_obj in gen_group:
            skipped_objs.add(linked_obj['HashId'])
            skip_reasons[linked_obj[
                'HashId']] = f'linked to skipped object: 0x{obj["HashId"]:08x} {obj["UnitConfigName"]}'
        skip_reasons[objid] = 'skipped'

    for objid in skipped_objs:
        obj = pmap.get_obj(objid)
        print(
            f"[0x{obj['HashId']:08x}] {obj['UnitConfigName']} {tuple(obj['Translate'])}"
        )
        if '!Parameters' in obj:
            pprint.pprint(obj['!Parameters'], indent=2)
        print(f"| SKIP REASON: {skip_reasons[objid]}")
        for link in obj['__links']:
            print(f"| LINKS TO: {link.description()}")
        for link in obj['__links_to_self']:
            print(f"| LINKED BY: {link.description()}")
        print('-' * 70)
コード例 #4
0
def main() -> None:
    parser = argparse.ArgumentParser(
        'Shows the placement generation group for a map object.')
    parser.add_argument(
        'map_path',
        help='Path to a map unit (BYAML or compressed BYAML or YAML)')
    parser.add_argument('object_id',
                        type=lambda x: int(x, 0),
                        help='Map object ID (HashId)')
    args = parser.parse_args()
    MAP_PATH: str = args.map_path
    MAP_OBJID: int = args.object_id

    byml.yaml_util.add_constructors(yaml.CSafeLoader)
    with open(MAP_PATH, 'rb') as f:
        if MAP_PATH.endswith('mubin'):
            map_data = byml.Byml(wszst_yaz0.decompress(f.read())).parse()
        else:
            map_data = yaml.load(f, Loader=yaml.CSafeLoader)

    pmap = Map(map_data)
    pmap.parse_obj_links()

    gen_group = pmap.build_gen_group(pmap.get_obj(MAP_OBJID))

    for obj in gen_group:
        print(
            f"[0x{obj['HashId']:08x} ({obj['HashId']})] {obj['UnitConfigName']} {tuple(obj['Translate'])}"
        )
        if '!Parameters' in obj:
            pprint.pprint(obj['!Parameters'], indent=2)
        for link in obj['__links']:
            print(f"| LINKS TO: {link.description()}")
        for link in obj['__links_to_self']:
            print(f"| LINKED BY: {link.description()}")
        print('-' * 70)
コード例 #5
0
def read_rstb(content_dir: str, be: bool) -> rstb.ResourceSizeTable:
    with open(
            "%s/System/Resource/ResourceSizeTable.product.srsizetable" %
            content_dir, "rb") as file:
        buf = wszst_yaz0.decompress(file.read())
        return rstb.ResourceSizeTable(buf, be)
コード例 #6
0
ファイル: file.py プロジェクト: zeldamods/zeldabuilder
 def read_file_and_decomp(self, path: Path) -> bytes:
     data = self.read_file(path)
     if path.suffix.startswith(".s"):
         return wszst_yaz0.decompress(data)
     return data