Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate Crunch64 for decompression #321

Merged
merged 2 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ venv/
.vscode/
__pycache__/
.mypy_cache/
util/n64/Yay0decompress
*.ld
*.n64
*.yaml
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# splat Release Notes

### 0.20.1

* splat now uses [crunch64](https://github.com/decompals/crunch64) as a dependency for handling decompression of various formats, starting with Yay0 and MIO0
* Changed compression_type (and thus file extension) for the Mio0 segment to "MIO0" from "Mio0", accurately reflecting its true name
* Removed utility cli Yay0decompress.py and Mio0decompress.py scripts; see crunch64-cli for a much more performant (de)compression CLI tool

### 0.20.0

* Add a pad segment that advances the linker script instead of dumping a binary / generating an assembly file.
Expand Down
11 changes: 0 additions & 11 deletions Makefile

This file was deleted.

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ spimdisasm>=1.18.0
rabbitizer>=1.8.0
pygfxd
n64img>=0.1.4
crunch64>=0.2.0
24 changes: 13 additions & 11 deletions segtypes/common/decompressor.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
from typing import Optional, Any

from util import log, options
from util.n64.decompressor import Decompressor

from segtypes.n64.segment import N64Segment


class CommonSegDecompressor(N64Segment):
decompressor: Decompressor
compression_type = "" # "Mio0" -> filename.Mio0.o

def split(self, rom_bytes):
if self.decompressor is None:
log.error("Decompressor is not a standalone segment type")

out_dir = options.opts.asset_path / self.dir
out_dir.mkdir(parents=True, exist_ok=True)

Expand All @@ -29,7 +20,7 @@ def split(self, rom_bytes):

self.log(f"Decompressing {self.name}")
compressed_bytes = rom_bytes[self.rom_start : self.rom_end]
decompressed_bytes = self.decompressor.decompress(compressed_bytes)
decompressed_bytes = self.decompress(compressed_bytes)
f.write(decompressed_bytes)
self.log(f"Wrote {self.name} to {out_path}")

Expand All @@ -42,9 +33,20 @@ def get_linker_entries(self):
[options.opts.asset_path / self.dir / f"{self.name}.bin"],
options.opts.asset_path
/ self.dir
/ f"{self.name}.{self.compression_type}",
/ f"{self.name}.{self.compression_type}", # "Mio0" -> filename.Mio0.o
self.get_linker_section_order(),
self.get_linker_section_linksection(),
self.is_noload(),
)
]

@property
def compression_type(self) -> str:
log.error(
f"Segment {self.__class__.__name__} needs to define a compression type"
)

def decompress(self, compressed_bytes: bytes) -> bytes:
log.error(
f"Segment {self.__class__.__name__} needs to define a decompression method"
)
9 changes: 4 additions & 5 deletions segtypes/gc/rarc.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import struct
from enum import IntEnum
from pathlib import Path

from typing import List, Optional

from util import options
from util.gc.gcutil import read_string_from_bytes
from util.n64.Yay0decompress import Yay0Decompressor
import crunch64

from segtypes.gc.segment import GCSegment
from util import options
from util.gc.gcutil import read_string_from_bytes


# Represents the RARC archive format used by first-party Nintendo games.
Expand Down Expand Up @@ -56,7 +55,7 @@ def try_decompress_archive(self, file_bytes):
# Yay0
elif compression_scheme == 0x59617930:
self.compression = "yay0"
return Yay0Decompressor.decompress(file_bytes)
return crunch64.yay0.decompress(file_bytes)
# Not compressed!
else:
return file_bytes
Expand Down
11 changes: 8 additions & 3 deletions segtypes/n64/mio0.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
from util.n64.Mio0decompress import Mio0Decompressor
import crunch64

from segtypes.common.decompressor import CommonSegDecompressor


class N64SegMio0(CommonSegDecompressor):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.decompressor = Mio0Decompressor()
self.compression_type = "Mio0"

@property
def compression_type(self):
return "MIO0"

def decompress(self, compressed_bytes: bytes) -> bytes:
return crunch64.mio0.decompress(compressed_bytes)
11 changes: 8 additions & 3 deletions segtypes/n64/yay0.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
from util.n64.Yay0decompress import Yay0Decompressor
import crunch64

from segtypes.common.decompressor import CommonSegDecompressor


class N64SegYay0(CommonSegDecompressor):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.decompressor = Yay0Decompressor()
self.compression_type = "Yay0"

@property
def compression_type(self):
return "Yay0"

def decompress(self, compressed_bytes: bytes) -> bytes:
return crunch64.yay0.decompress(compressed_bytes)
2 changes: 1 addition & 1 deletion split.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from segtypes.segment import Segment
from util import log, options, palettes, symbols, relocs

VERSION = "0.20.0"
VERSION = "0.20.1"

parser = argparse.ArgumentParser(
description="Split a rom given a rom, a config, and output directory"
Expand Down
108 changes: 0 additions & 108 deletions util/n64/Mio0decompress.py

This file was deleted.

44 changes: 0 additions & 44 deletions util/n64/Yay0decompress.c

This file was deleted.

Loading
Loading