split and pack title_data (#293)

This commit is contained in:
alex 2021-05-08 07:54:34 +01:00 committed by GitHub
parent 08aad50545
commit 39029a810e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 86 additions and 2 deletions

View File

@ -164,6 +164,11 @@ def write_ninja_rules(ninja: ninja_syntax.Writer, cpp: str):
command=f"$python {BUILD_TOOLS}/mapfs/combine.py $out $in",
)
ninja.rule("pack_title_data",
description="pack_title_data $out",
command=f"$python {BUILD_TOOLS}/mapfs/pack_title_data.py $out $in",
)
ninja.rule("map_header", command=f"$python {BUILD_TOOLS}/mapfs/map_header.py $in > $out")
def write_ninja_for_tools(ninja: ninja_syntax.Writer):
@ -381,19 +386,48 @@ class Configure:
build(entry.object_path, [entry.object_path.with_suffix(".bin")], "bin")
elif seg.type == "PaperMarioMapFS":
bin_yay0s: List[Path] = [] # flat list of (uncompressed path, compressed? path) pairs
src_dir = Path("assets/x") / seg.name
for path in entry.src_paths:
name = path.stem
bin_path = entry.object_path.with_suffix("").with_suffix("") / f"{name}.bin"
out_dir = entry.object_path.with_suffix("").with_suffix("")
bin_path = out_dir / f"{name}.bin"
if name.startswith("party_"):
compress = True
yay0_path = bin_path.with_suffix(".Yay0")
build(bin_path, [path], "img", variables={
"img_type": "party",
"img_flags": "",
})
elif name == "title_data":
compress = True
logotype_path = out_dir / "title_logotype.bin"
copyright_path = out_dir / "title_copyright.bin"
press_start_path = out_dir / "title_press_start.bin"
build(logotype_path, [src_dir / "title/logotype.png"], "img", variables={
"img_type": "rgba32",
"img_flags": "",
})
build(copyright_path, [src_dir / "title/copyright.png"], "img", variables={
"img_type": "ia8",
"img_flags": "",
})
build(press_start_path, [src_dir / "title/press_start.png"], "img", variables={
"img_type": "ia8",
"img_flags": "",
})
build(bin_path, [
logotype_path,
copyright_path,
press_start_path,
], "pack_title_data")
elif name.endswith("_bg"):
compress = True
bin_path = self.build_path() / bin_path
build(bin_path, [path], "img", variables={
"img_type": "bg",
"img_flags": "",

View File

@ -0,0 +1,33 @@
#! /usr/bin/python3
from sys import argv
if __name__ == "__main__":
argv.pop(0) # python3
out, img1, img2, img3 = argv
with open(img1, "rb") as f:
img1 = f.read()
with open(img2, "rb") as f:
img2 = f.read()
with open(img3, "rb") as f:
img3 = f.read()
with open(out, "wb") as f:
f.seek(0x10)
pos2 = f.tell()
f.write(img2)
pos3 = f.tell()
f.write(img3)
pos1 = f.tell()
f.write(img1)
f.seek(0)
f.write(pos1.to_bytes(4, byteorder="big"))
f.write(pos2.to_bytes(4, byteorder="big"))
f.write(pos3.to_bytes(4, byteorder="big"))

View File

@ -1,4 +1,6 @@
from segtypes.n64.segment import N64Segment
from segtypes.n64.ia8 import N64SegIa8
from segtypes.n64.rgba32 import N64SegRgba32
from util.n64 import Yay0decompress
from util.color import unpack_color
from util.iter import iter_in_groups
@ -42,7 +44,7 @@ class N64SegPaperMarioMapFS(N64Segment):
def split(self, rom_bytes):
fs_dir = options.get_asset_path() / self.dir / self.name
fs_dir.mkdir(parents=True, exist_ok=True)
(fs_dir / "title").mkdir(parents=True, exist_ok=True)
data = rom_bytes[self.rom_start: self.rom_end]
@ -77,6 +79,21 @@ class N64SegPaperMarioMapFS(N64Segment):
# CI-8
w = png.Writer(150, 105, palette=parse_palette(bytes[:0x200]))
w.write_array(f, bytes[0x200:])
elif name == "title_data":
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))
elif name.endswith("_bg"):
def write_bg_png(bytes, path, header_offset=0):
header = bytes[header_offset:header_offset+0x10]