mirror of
https://github.com/zeldaret/af.git
synced 2026-09-26 13:33:16 -04:00
1d9c5c49c5
* tol_keitai_1 * kenjyu * evw_anime data extraction works * forgot to remove this * added comments for objects * fixes * scroll colprim colenv now extract as arrays * forgot commas
44 lines
1.7 KiB
Python
44 lines
1.7 KiB
Python
import struct
|
|
from typing import Optional
|
|
from splat.util import options, log
|
|
from splat.segtypes.common.codesubsegment import CommonSegCodeSubsegment
|
|
|
|
class N64SegEvw_scroll(CommonSegCodeSubsegment):
|
|
def __init__(self, rom_start, rom_end, type, name, vram_start, args, yaml):
|
|
super().__init__(rom_start, rom_end, type, name, vram_start, args=args, yaml=yaml),
|
|
|
|
self.file_text: Optional[str] = None
|
|
self.data_only = isinstance(yaml, dict) and yaml.get("data_only", False)
|
|
|
|
def scan(self, rom_bytes: bytes):
|
|
data = rom_bytes[self.rom_start : self.rom_end]
|
|
symbol = self.create_symbol(addr=self.vram_start, in_segment=True, type="data", define=True)
|
|
count = len(data) // 4
|
|
lines = []
|
|
|
|
if (len(data)) % 4 != 0:
|
|
log.error(f"Error: evw_scroll segment {self.name} length ({len(data)}) is not a multiple of 4!")
|
|
|
|
if not self.data_only:
|
|
lines.append(options.opts.generated_c_preamble)
|
|
lines.append("")
|
|
lines.append(f"EvwAnimeScroll {symbol.name}[{count}] = {{")
|
|
|
|
for EvwAnimeScroll in struct.iter_unpack(">bbBB", data):
|
|
x, y, width, height = EvwAnimeScroll
|
|
lines.append(f" {{ {x}, {y}, {width}, {height} }},")
|
|
|
|
if not self.data_only:
|
|
lines.append("};")
|
|
|
|
lines.append("")
|
|
self.file_text = "\n".join(lines)
|
|
|
|
def split(self, rom_bytes: bytes):
|
|
path = options.opts.asset_path / self.dir / f"{self.name}.inc.c"
|
|
|
|
if self.file_text and path:
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
with open(path, "w", newline="\n") as f:
|
|
f.write(self.file_text)
|