-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into pre-commit-ci-update-config
- Loading branch information
Showing
19 changed files
with
570 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
src/open_samus_returns_rando/files/exefs_patches/exheader.ips
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Lzss structure was taken from GodMode9 https://github.com/d0k3/GodMode9/commit/a6a15eb70d66e3c96bbc164598f9482bb545b3f9 | ||
|
||
from construct import Struct # type: ignore | ||
from construct.core import Int32ul # type: ignore | ||
|
||
LzssFooter = Struct( | ||
"off_size_comp" / Int32ul, # 0xOOSSSSSS, where O == reverse offset and S == size | ||
"addsize_dec" / Int32ul, # decompressed size - compressed size | ||
) | ||
|
||
|
||
def lzss_decompress(compressed: bytes) -> bytes | None: | ||
# copy of citra's `LZSS_Decompress` function | ||
# see: https://github.com/PabloMK7/citra/blob/7d00f47c5ead75db0a9f24d70aa4b609e85125d8/src/core/file_sys/ncch_container.cpp#L54 | ||
compressed_length = len(compressed) | ||
|
||
lzss_footer = LzssFooter.parse(compressed[-8:]) | ||
|
||
decompressed_length = compressed_length + lzss_footer.addsize_dec | ||
decompressed = bytearray(decompressed_length) | ||
|
||
out = decompressed_length | ||
index = compressed_length - ((lzss_footer.off_size_comp >> 24) & 0xFF) | ||
stop_index = compressed_length - (lzss_footer.off_size_comp & 0xFFFFFF) | ||
|
||
decompressed[0:compressed_length] = compressed | ||
while index > stop_index: | ||
index -= 1 | ||
control = compressed[index] | ||
|
||
for i in range(8): | ||
if index <= stop_index: | ||
break | ||
if index <= 0: | ||
break | ||
if out <= 0: | ||
break | ||
|
||
if control & 0x80: | ||
# Check if compression is out of bounds | ||
if index < 2: | ||
return None | ||
index -= 2 | ||
|
||
segment_offset = compressed[index] | (compressed[index + 1] << 8) | ||
segment_size = ((segment_offset >> 12) & 15) + 3 | ||
segment_offset &= 0x0FFF | ||
segment_offset += 2 | ||
|
||
# Check if compression is out of bounds | ||
if out < segment_size: | ||
return None | ||
|
||
for j in range(segment_size): | ||
# Check if compression is out of bounds | ||
if out + segment_offset >= decompressed_length: | ||
return None | ||
|
||
data = decompressed[out + segment_offset] | ||
out -= 1 | ||
decompressed[out] = data | ||
else: | ||
# Check if compression is out of bounds | ||
if out < 1: | ||
return None | ||
out -= 1 | ||
index -= 1 | ||
decompressed[out] = compressed[index] | ||
|
||
control <<= 1 | ||
return decompressed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import io | ||
from collections.abc import Iterator | ||
from contextlib import contextmanager | ||
|
||
import construct # type: ignore | ||
from mercury_engine_data_structures.romfs import RomFs | ||
|
||
from open_samus_returns_rando.romfs.rom3ds import Rom3DS | ||
|
||
|
||
class PackagedRomFs(RomFs): | ||
def __init__(self, parsed_rom: Rom3DS): | ||
self.parsed_rom = parsed_rom | ||
|
||
@contextmanager | ||
def get_pkg_stream(self, file_path: str) -> Iterator[io.BytesIO]: | ||
file_stream = io.BytesIO(self.parsed_rom.get_file_binary(file_path)) | ||
try: | ||
yield file_stream | ||
finally: | ||
file_stream.close() | ||
|
||
def read_file_with_entry(self, file_path: str, entry: construct.Container) -> bytes: | ||
with io.BytesIO(self.parsed_rom.get_file_binary(file_path)) as f: | ||
f.seek(entry.start_offset) | ||
return f.read(entry.end_offset - entry.start_offset) | ||
|
||
def get_file(self, file_path: str) -> bytes: | ||
return self.parsed_rom.get_file_binary(file_path) | ||
|
||
def all_files(self) -> Iterator[str]: | ||
yield from self.parsed_rom.file_name_to_entry.keys() |
Oops, something went wrong.