示例#1
0
    def get_linker_entries(self):
        from segtypes.linker_entry import LinkerEntry

        basepath = options.get_asset_path() / "sprite" / f"{self.name}"
        out_paths = [options.get_asset_path() / "sprite" / self.name / (f["name"] if type(f) is dict else f)
                     for f in self.files]

        return [LinkerEntry(self, out_paths, basepath, ".data")]
示例#2
0
    def get_linker_entries(self):
        from segtypes.linker_entry import LinkerEntry

        return [
            LinkerEntry(
                self,
                [options.get_asset_path() / self.dir / f"{self.name}.png"],
                options.get_asset_path() / self.dir / f"{self.name}.pal",
                self.get_linker_section())
        ]
示例#3
0
    def get_linker_entries(self):
        from segtypes.linker_entry import LinkerEntry

        base_path = options.get_asset_path() / f"{self.name}"
        out_paths = [base_path / Path(f + ".msg") for f in self.files]

        return [LinkerEntry(self, out_paths, base_path, ".data")]
示例#4
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)
示例#5
0
    def split(self, rom_bytes):
        data = rom_bytes[self.rom_start:self.rom_end]

        section_offsets = []
        pos = 0
        while True:
            offset = int.from_bytes(data[pos:pos + 4], byteorder="big")

            if offset == 0:
                break

            section_offsets.append(offset)
            pos += 4

        msg_dir = options.get_asset_path() / self.name
        msg_dir.mkdir(parents=True, exist_ok=True)

        for i, section_offset in enumerate(section_offsets):
            name = f"{i:02X}"
            if len(self.files) >= i:
                name = self.files[i]

            msg_offsets = []
            pos = section_offset
            while True:
                offset = int.from_bytes(data[pos:pos + 4], byteorder="big")

                if offset == section_offset:
                    break

                msg_offsets.append(offset)
                pos += 4

            #self.log(f"Reading {len(msg_offsets)} messages in section {name} (0x{i:02X})")

            path = msg_dir / Path(name + ".msg")

            with open(path, "w") as self.f:
                for j, msg_offset in enumerate(msg_offsets):
                    if j != 0:
                        self.f.write("\n")

                    msg_name = None
                    for d in self.msg_names:
                        section, index, goodname = d[:3]

                        if i == section and j == index:
                            msg_name = goodname
                            break

                    if msg_name is None:
                        self.f.write(f"#message:{i:02X}:{j:03X} {{\n\t")
                    else:
                        self.f.write(f"#message:{i:02X}:({msg_name}) {{\n\t")
                    self.write_message_markup(data[msg_offset:])
                    self.f.write("\n}\n")
示例#6
0
    def get_linker_entries(self):
        from segtypes.linker_entry import LinkerEntry

        fs_dir = options.get_asset_path() / self.dir / self.name

        return [
            LinkerEntry(self,
                        [fs_dir / add_file_ext(name) for name in self.files],
                        fs_dir.with_suffix(".dat"), ".data"),
        ]
示例#7
0
    def get_linker_entries(self):
        from segtypes.linker_entry import LinkerEntry

        fs_dir = options.get_asset_path() / self.dir / self.name / "palette"

        return [
            LinkerEntry(self,
                        [fs_dir / f"{i:02X}.png" for i in range(self.yaml[3])],
                        fs_dir.with_suffix(".dat"), ".data"),
        ]
示例#8
0
    def split(self, rom_bytes):
        fs_dir = options.get_asset_path() / self.dir / self.name
        fs_dir.mkdir(parents=True, exist_ok=True)

        for i, raster in enumerate(self.rasters):
            palette = self.sibling.palettes[0]

            w = png.Writer(self.width, self.height, palette=palette)
            with open(fs_dir / f"{i:02X}.png", "wb") as f:
                w.write_array(f, raster)
示例#9
0
    def get_linker_entries(self):
        from segtypes.linker_entry import LinkerEntry

        # start, type, name, WIDTH, HEIGHT
        self.width = self.yaml[3]
        self.height = self.yaml[4]

        fs_dir = options.get_asset_path() / self.dir / self.name

        return [
            LinkerEntry(self,
                        [fs_dir / f"{i:02X}.png" for i in range(self.yaml[5])],
                        fs_dir.with_suffix(".dat"), ".data"),
        ]
示例#10
0
文件: Yay0.py 项目: pmret/papermario
    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}")
示例#11
0
文件: ci8.py 项目: pmret/papermario
    def split(self, rom_bytes):
        path = options.get_asset_path() / self.dir / (self.name + ".png")
        path.parent.mkdir(parents=True, exist_ok=True)

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

        if self.palette is None:
            # TODO: output with blank palette
            log.error(
                f"no palette sibling segment exists\n(hint: add a segment with type 'palette' and name '{self.name}')"
            )

        w = png.Writer(self.width,
                       self.height,
                       palette=self.palette.parse_palette(rom_bytes))
        image = self.__class__.parse_image(data, self.width, self.height,
                                           self.flip_horizontal,
                                           self.flip_vertical)

        with open(self.out_path(), "wb") as f:
            w.write_array(f, image)

        self.palette.extract = False
示例#12
0
 def out_path(self) -> Optional[Path]:
     return options.get_asset_path() / self.dir / f"{self.name}.png"
示例#13
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
示例#14
0
文件: gfx.py 项目: pmret/papermario
 def out_path(self) -> Path:
     return options.get_asset_path() / self.dir / f"{self.name}.gfx.inc.c"
示例#15
0
 def out_dir(self) -> Path:
     return options.get_asset_path() / "rzip" / self.name
示例#16
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