Skip to content

Commit

Permalink
Fix subalign logic, dep updates (#394)
Browse files Browse the repository at this point in the history
* Fix subalign logic, make img not look at subalign, updates

* mypy

* Fix img subalign stuff
  • Loading branch information
ethteck authored Aug 16, 2024
1 parent e2a638e commit 84d428f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# splat Release Notes

### 0.26.0

* Fixed the `subalign` segment property logic to be more straightforward
* Updated required versions of rabbitizier, n64img, and crunch64

### 0.25.3

* Fix incorrect calculation for `$gp` value in create_config.py for PSX when immediate value is negative.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The brackets corresponds to the optional dependencies to install while installin
If you use a `requirements.txt` file in your repository, then you can add this library with the following line:

```txt
splat64[mips]>=0.25.3,<1.0.0
splat64[mips]>=0.26.0,<1.0.0
```

### Optional dependencies
Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "splat64"
# Should be synced with src/splat/__init__.py
version = "0.25.3"
version = "0.26.0"
description = "A binary splitting tool to assist with decompilation and modding projects"
readme = "README.md"
license = {file = "LICENSE"}
Expand All @@ -21,10 +21,10 @@ dependencies = [
[project.optional-dependencies]
mips = [
"spimdisasm>=1.28.0,<2.0.0", # This value should be keep in sync with the version listed on disassembler/spimdisasm_disassembler.py
"rabbitizer>=1.10.0,<2.0.0",
"rabbitizer>=1.12.0,<2.0.0",
"pygfxd",
"n64img>=0.1.4",
"crunch64>=0.2.0,<1.0.0",
"n64img>=0.3.3",
"crunch64>=0.5.1,<1.0.0",
]
dev = [
"splat64[mips]",
Expand Down
4 changes: 1 addition & 3 deletions src/splat/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from typing import Tuple

__package_name__ = __name__

# Should be synced with pyproject.toml
__version__ = "0.25.3"
__version__ = "0.26.0"
__author__ = "ethteck"

from . import util as util
Expand Down
8 changes: 3 additions & 5 deletions src/splat/segtypes/n64/img.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,14 @@ def __init__(
self.n64img.width = self.width
self.n64img.height = self.height

self.check_len()

self.image_type_in_extension = options.opts.image_type_in_extension

def check_len(self) -> None:
expected_len = int(self.n64img.size())
assert isinstance(self.rom_start, int)
assert isinstance(self.rom_end, int)
assert isinstance(self.subalign, int)

actual_len = self.rom_end - self.rom_start
if actual_len > expected_len and actual_len - expected_len > self.subalign:
log.error(
Expand All @@ -76,12 +75,11 @@ def should_split(self) -> bool:
return options.opts.is_mode_active("img")

def split(self, rom_bytes):
self.check_len()

path = self.out_path()
path.parent.mkdir(parents=True, exist_ok=True)

assert isinstance(self.rom_start, int)
assert isinstance(self.rom_end, int)

if self.n64img.data == b"":
self.n64img.data = rom_bytes[self.rom_start : self.rom_end]
self.n64img.write(path)
Expand Down
14 changes: 8 additions & 6 deletions src/splat/segtypes/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ def parse_segment_align(segment: Union[dict, list]) -> Optional[int]:


def parse_segment_subalign(segment: Union[dict, list]) -> Optional[int]:
default = options.opts.subalign
if isinstance(segment, dict):
subalign = segment.get("subalign", default)
subalign = segment.get("subalign")
if subalign != None:
assert isinstance(subalign, int)
subalign = int(subalign)
return subalign
return default
return None


def parse_segment_section_order(segment: Union[dict, list]) -> List[str]:
Expand Down Expand Up @@ -237,7 +237,7 @@ def __init__(
self.vram_start: Optional[int] = vram_start

self.align: Optional[int] = None
self.given_subalign: Optional[int] = options.opts.subalign
self.given_subalign: Optional[int] = None
self.exclusive_ram_id: Optional[str] = None
self.given_dir: Path = Path()

Expand Down Expand Up @@ -433,10 +433,12 @@ def symbol_name_format_no_rom(self) -> str:

@property
def subalign(self) -> Optional[int]:
if self.parent:
if self.given_subalign is not None:
return self.given_subalign
elif self.parent:
return self.parent.subalign
else:
return self.given_subalign
return options.opts.subalign

@property
def vram_symbol(self) -> Optional[str]:
Expand Down

0 comments on commit 84d428f

Please sign in to comment.