44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
from pathlib import Path
|
|
from typing import Optional
|
|
|
|
from segtypes.n64.segment import N64Segment
|
|
from segtypes.n64.rgba16 import N64SegRgba16
|
|
from segtypes.n64.i4 import N64SegI4
|
|
|
|
from util import options, log
|
|
|
|
import lhafile
|
|
|
|
import sys
|
|
sys.path.append(str(options.opts.base_path / "tools"))
|
|
|
|
class N64SegLha(N64Segment):
|
|
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),
|
|
|
|
log.write(f"LHA decompression initialised with {self.name}")
|
|
|
|
def out_path(self) -> Optional[Path]:
|
|
return options.opts.asset_path / self.dir / f"{self.name}"
|
|
|
|
def split(self, rom_bytes):
|
|
data_bytes = rom_bytes[self.rom_start:self.rom_end]
|
|
|
|
path = self.out_path()
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
with path.open("wb") as f:
|
|
f.write(data_bytes)
|
|
f.close()
|
|
|
|
# Create Lhafile instance from filename
|
|
archive = lhafile.Lhafile(str(path))
|
|
|
|
# Print each file informaion in archive file.
|
|
for info in archive.infolist():
|
|
print(info.filename)
|
|
|
|
log.write(f"LHA decompression got {len(data_bytes)}")
|
|
|
|
log.write(data_bytes)
|
|
|