Beispiel #1
0
    def split(self, rom_bytes, base_path):
        out_dir = self.create_split_dir(base_path, "sprite/" + self.name)

        data = rom_bytes[self.rom_start:self.rom_end]
        pos = 0

        for i, file in enumerate(self.files):
            if type(file) is dict:
                sprite_name = file["name"]
            else:
                sprite_name = file

            self.log(f"Splitting sprite {sprite_name}...")

            sprite_dir = self.create_split_dir(out_dir, sprite_name)

            start = int.from_bytes(data[i * 4:(i + 1) * 4], byteorder="big")
            end = int.from_bytes(data[(i + 1) * 4:(i + 2) * 4],
                                 byteorder="big")

            sprite_data = Yay0decompress.decompress_yay0(data[start:end])
            """
            with open(sprite_dir / "raw.bin", "wb") as f:
                f.write(sprite_data)
            """

            sprite = Sprite.from_bytes(sprite_data)

            if type(file) is dict:
                sprite.image_names = file.get("frames", [])
                sprite.palette_names = file.get("palettes", [])
                sprite.animation_names = file.get("animations", [])

            sprite.write_to_dir(sprite_dir)
Beispiel #2
0
    def split(self, rom_bytes):
        out_dir = options.get_asset_path() / self.dir / self.name

        data = rom_bytes[self.rom_start:self.rom_end]
        pos = 0

        for i, sprite_name in enumerate(self.files):
            #self.log(f"Splitting sprite {sprite_name}...")

            sprite_dir = out_dir / sprite_name
            sprite_dir.mkdir(parents=True, exist_ok=True)

            start = int.from_bytes(data[i * 4:(i + 1) * 4], byteorder="big")
            end = int.from_bytes(data[(i + 1) * 4:(i + 2) * 4],
                                 byteorder="big")

            sprite_data = Yay0decompress.decompress_yay0(data[start:end])
            sprite = Sprite.from_bytes(sprite_data)

            if sprite_name in self.sprite_cfg:
                sprite.image_names = self.sprite_cfg[sprite_name].get(
                    "frames", [])
                sprite.palette_names = self.sprite_cfg[sprite_name].get(
                    "palettes", [])
                sprite.animation_names = self.sprite_cfg[sprite_name].get(
                    "animations", [])

            sprite.write_to_dir(sprite_dir)
Beispiel #3
0
    def split(self, rom_bytes, base_path):
        out_dir = self.create_parent_dir(base_path + "/img", self.name)
        self.path = os.path.join(out_dir, os.path.basename(self.name) + ".png")

        data = rom_bytes[self.rom_start:self.rom_end]
        if self.compressed:
            data = Yay0decompress.decompress_yay0(data)

        self.palette = self.parse_palette(data)
Beispiel #4
0
    def split(self, rom_bytes, base_path):
        out_dir = self.create_parent_dir(
            base_path + "/" + self.options.get("assets_dir", "img"), self.name)
        self.path = os.path.join(out_dir, os.path.basename(self.name) + ".png")

        data = rom_bytes[self.rom_start:self.rom_end]
        if self.compressed:
            data = Yay0decompress.decompress_yay0(data)

        self.palette = N64SegPalette.parse_palette(data)
Beispiel #5
0
    def split(self, rom_bytes, base_path):
        out_dir = self.create_parent_dir(base_path + "/bin", self.name)

        path = os.path.join(out_dir, os.path.basename(self.name) + ".bin")
        with open(path, "wb") as f:
            self.log(f"Decompressing {self.name}...")
            compressed_bytes = rom_bytes[self.rom_start : self.rom_end]
            decompressed_bytes = Yay0decompress.decompress_yay0(compressed_bytes)
            f.write(decompressed_bytes)
        self.log(f"Wrote {self.name} to {path}")
Beispiel #6
0
    def split(self, rom_bytes, base_path):
        out_dir = self.create_parent_dir(base_path + "/img", self.name)
        path = os.path.join(out_dir, os.path.basename(self.name) + ".png")

        data = rom_bytes[self.rom_start: self.rom_end]
        if self.compressed:
            data = Yay0decompress.decompress_yay0(data)

        w = self.png_writer()
        with open(path, "wb") as f:
            w.write_array(f, self.parse_image(data))

        self.log(f"Wrote {self.name} to {path}")
Beispiel #7
0
    def split(self, rom_bytes):
        out_dir = options.get_asset_path() / self.dir
        out_dir.mkdir(parents=True, exist_ok=True)

        if self.rom_end == "auto":
            log.error(
                f"segment {self.name} needs to know where it ends; add a position marker [0xDEADBEEF] after it"
            )

        out_path = out_dir / f"{self.name}.bin"
        with open(out_path, "wb") as f:
            self.log(f"Decompressing {self.name}...")
            compressed_bytes = rom_bytes[self.rom_start : self.rom_end]
            decompressed_bytes = Yay0decompress.decompress_yay0(compressed_bytes)
            f.write(decompressed_bytes)
        self.log(f"Wrote {self.name} to {out_path}")
    def split(self, rom_bytes, base_path):
        bin_dir = self.create_split_dir(base_path, "bin/assets")

        data = rom_bytes[self.rom_start: self.rom_end]

        asset_idx = 0
        while True:
            asset_data = data[0x20 + asset_idx * 0x1C:]

            name = decode_null_terminated_ascii(asset_data[0:])
            offset = int.from_bytes(asset_data[0x10:0x14], byteorder="big")
            size = int.from_bytes(asset_data[0x14:0x18], byteorder="big")
            decompressed_size = int.from_bytes(
                asset_data[0x18:0x1C], byteorder="big")

            is_compressed = size != decompressed_size

            if offset == 0:
                path = None
            else:
                path = "{}.bin".format(name)
                self.create_parent_dir(bin_dir, path)

            if name == "end_data":
                break

            with open(os.path.join(bin_dir, path), "wb") as f:
                bytes = rom_bytes[self.rom_start + 0x20 +
                                  offset: self.rom_start + 0x20 + offset + size]

                if is_compressed:
                    self.log(f"Decompressing {name}...")
                    bytes = Yay0decompress.decompress_yay0(bytes)

                f.write(bytes)
                self.log(f"Wrote {name} to {Path(bin_dir, path)}")

            asset_idx += 1
Beispiel #9
0
    def split(self, rom_bytes):
        fs_dir = options.get_asset_path() / self.dir / self.name
        (fs_dir / "title").mkdir(parents=True, exist_ok=True)

        data = rom_bytes[self.rom_start:self.rom_end]

        asset_idx = 0
        while True:
            asset_data = data[0x20 + asset_idx * 0x1C:]

            name = decode_null_terminated_ascii(asset_data[0:])
            offset = int.from_bytes(asset_data[0x10:0x14], byteorder="big")
            size = int.from_bytes(asset_data[0x14:0x18], byteorder="big")
            decompressed_size = int.from_bytes(asset_data[0x18:0x1C],
                                               byteorder="big")

            is_compressed = size != decompressed_size

            if offset == 0:
                path = None
            else:
                path = fs_dir / add_file_ext(name)

            if name == "end_data":
                break

            bytes_start = self.rom_start + 0x20 + offset
            bytes = rom_bytes[bytes_start:bytes_start + size]

            if is_compressed:
                bytes = Yay0decompress.decompress_yay0(bytes)

            if name.startswith("party_"):
                with open(path, "wb") as f:
                    # CI-8
                    w = png.Writer(150,
                                   105,
                                   palette=parse_palette(bytes[:0x200]))
                    w.write_array(f, bytes[0x200:])
            elif name == "title_data":
                if "ver/us" in options.opts["target_path"]:
                    with open(fs_dir / "title/logotype.png", "wb") as f:
                        width = 200
                        height = 112
                        N64SegRgba32.get_writer(width, height).write_array(
                            f,
                            N64SegRgba32.parse_image(
                                bytes[0x2210:0x2210 + width * height * 4],
                                width, height))

                    with open(fs_dir / "title/copyright.png", "wb") as f:
                        width = 144
                        height = 32
                        N64SegIa8.get_writer(width, height).write_array(
                            f,
                            N64SegIa8.parse_image(
                                bytes[0x10:0x10 + width * height], width,
                                height))

                    with open(fs_dir / "title/press_start.png", "wb") as f:
                        width = 128
                        height = 32
                        N64SegIa8.get_writer(width, height).write_array(
                            f,
                            N64SegIa8.parse_image(
                                bytes[0x1210:0x1210 + width * height], width,
                                height))
                else:
                    with open(fs_dir / "title/logotype.png", "wb") as f:
                        width = 272
                        height = 88
                        N64SegRgba32.get_writer(width, height).write_array(
                            f,
                            N64SegRgba32.parse_image(
                                bytes[0x1830:0x1830 + width * height * 4],
                                width, height))

                    with open(fs_dir / "title/copyright.png", "wb") as f:
                        width = 128
                        height = 32

                        w = png.Writer(width,
                                       height,
                                       palette=parse_palette(
                                           bytes[0x810:0x830]))
                        w.write_array(
                            f,
                            N64SegCi4.parse_image(
                                bytes[0x10:0x10 + width * height], width,
                                height))

                    with open(fs_dir / "title/press_start.png", "wb") as f:
                        width = 128
                        height = 32
                        N64SegIa8.get_writer(width, height).write_array(
                            f,
                            N64SegIa8.parse_image(
                                bytes[0x830:0x830 + width * height], width,
                                height))
            elif name.endswith("_bg"):

                def write_bg_png(bytes, path, header_offset=0):
                    header = bytes[header_offset:header_offset + 0x10]

                    raster_offset = int.from_bytes(
                        header[0:4], byteorder="big") - 0x80200000
                    palette_offset = int.from_bytes(
                        header[4:8], byteorder="big") - 0x80200000
                    assert int.from_bytes(
                        header[8:12],
                        byteorder="big") == 0x000C0014  # draw pos
                    width = int.from_bytes(header[12:14], byteorder="big")
                    height = int.from_bytes(header[14:16], byteorder="big")

                    with open(path, "wb") as f:
                        # CI-8
                        w = png.Writer(
                            width,
                            height,
                            palette=parse_palette(
                                bytes[palette_offset:palette_offset + 512]))
                        w.write_array(f, bytes[raster_offset:])

                write_bg_png(bytes, path)

                # sbk_bg has an alternative palette
                if name == "sbk_bg":
                    write_bg_png(bytes,
                                 fs_dir / f"{name}.alt.png",
                                 header_offset=0x10)
            else:
                with open(path, "wb") as f:
                    f.write(bytes)

            asset_idx += 1
Beispiel #10
0
    def split(self, rom_bytes):
        fs_dir = options.get_asset_path() / self.dir / self.name
        fs_dir.mkdir(parents=True, exist_ok=True)

        data = rom_bytes[self.rom_start:self.rom_end]

        asset_idx = 0
        while True:
            asset_data = data[0x20 + asset_idx * 0x1C:]

            name = decode_null_terminated_ascii(asset_data[0:])
            offset = int.from_bytes(asset_data[0x10:0x14], byteorder="big")
            size = int.from_bytes(asset_data[0x14:0x18], byteorder="big")
            decompressed_size = int.from_bytes(asset_data[0x18:0x1C],
                                               byteorder="big")

            is_compressed = size != decompressed_size

            if offset == 0:
                path = None
            else:
                path = fs_dir / add_file_ext(name)

            if name == "end_data":
                break

            bytes_start = self.rom_start + 0x20 + offset
            bytes = rom_bytes[bytes_start:bytes_start + size]

            if is_compressed:
                bytes = Yay0decompress.decompress_yay0(bytes)

            if name.startswith("party_"):
                with open(path, "wb") as f:
                    # CI-8
                    w = png.Writer(150,
                                   105,
                                   palette=parse_palette(bytes[:0x200]))
                    w.write_array(f, bytes[0x200:])
            elif name.endswith("_bg"):

                def write_bg_png(bytes, path, header_offset=0):
                    header = bytes[header_offset:header_offset + 0x10]

                    raster_offset = int.from_bytes(
                        header[0:4], byteorder="big") - 0x80200000
                    palette_offset = int.from_bytes(
                        header[4:8], byteorder="big") - 0x80200000
                    assert int.from_bytes(
                        header[8:12],
                        byteorder="big") == 0x000C0014  # draw pos
                    width = int.from_bytes(header[12:14], byteorder="big")
                    height = int.from_bytes(header[14:16], byteorder="big")

                    with open(path, "wb") as f:
                        # CI-8
                        w = png.Writer(
                            width,
                            height,
                            palette=parse_palette(
                                bytes[palette_offset:palette_offset + 512]))
                        w.write_array(f, bytes[raster_offset:])

                write_bg_png(bytes, path)

                # sbk_bg has an alternative palette
                if name == "sbk_bg":
                    write_bg_png(bytes,
                                 fs_dir / f"{name}.alt.png",
                                 header_offset=0x10)
            else:
                with open(path, "wb") as f:
                    f.write(bytes)

            asset_idx += 1