Skip to content

Commit

Permalink
yeet python logic
Browse files Browse the repository at this point in the history
  • Loading branch information
AngheloAlf committed Dec 15, 2023
1 parent 39aa352 commit acda9bf
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 305 deletions.
10 changes: 0 additions & 10 deletions src/ipl3checksum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,4 @@
__version__ = ".".join(map(str, __version_info__)) + ".dev0"
__author__ = "Decompollaborate"

from . import utils as utils

from .cickinds import CICKind as CICKind

from .checksum import calculateChecksum as calculateChecksum
from .checksum import calculateChecksumAutodetect as calculateChecksumAutodetect

from .detect import detectCIC as detectCIC
from .detect import detectCICRaw as detectCICRaw

from .ipl3checksum import *
183 changes: 0 additions & 183 deletions src/ipl3checksum/checksum.py

This file was deleted.

36 changes: 36 additions & 0 deletions src/ipl3checksum/checksum.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python3

# SPDX-FileCopyrightText: © 2023 Decompollaborate
# SPDX-License-Identifier: MIT

from __future__ import annotations

from .cickinds import CICKind

def calculateChecksum(romBytes: bytes, kind: CICKind) -> tuple[int, int]|None:
"""Calculates the checksum required by an official CIC of a N64 ROM.
Args:
romBytes (bytes): The bytes of the N64 ROM in big endian format. It must have a minimum size of 0x101000 bytes.
kind (CICKind): The CIC kind variation used to calculate the checksum.
Returns:
tuple[int, int]|None: If no error happens then the calculated checksum is returned, stored as a tuple
containing two 32-bits words. Otherwise, `None` is returned. Possible errors:
- `romBytes` not being big enough
"""

def calculateChecksumAutodetect(romBytes: bytes) -> tuple[int, int]|None:
"""Calculates the checksum required by an official CIC of a N64 ROM.
This function will try to autodetect the CIC kind automatically. If it fails to detect it then it will return `None`.
Args:
romBytes (bytes): The bytes of the N64 ROM in big endian format. It must have a minimum size of 0x101000 bytes.
Returns:
tuple[int, int]|None: If no error happens then the calculated checksum is returned, stored as a tuple
containing two 32-bits words. Otherwise, `None` is returned. Possible errors:
- `romBytes` not being big enough
- Not able to detect the CIC kind
"""
82 changes: 0 additions & 82 deletions src/ipl3checksum/cickinds.py

This file was deleted.

41 changes: 41 additions & 0 deletions src/ipl3checksum/cickinds.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python3

# SPDX-FileCopyrightText: © 2023 Decompollaborate
# SPDX-License-Identifier: MIT

from __future__ import annotations

class CICKind():
CIC_6101: CICKind
CIC_6102_7101: CICKind
CIC_7102: CICKind
CIC_X103: CICKind # Both 6103 and 7103
# 6104/7104 does not exist
CIC_X105: CICKind # Both 6105 and 7105
CIC_X106: CICKind # Both 6106 and 7106


def getSeed(self) -> int:
"""
Seed value set by the PIF ROM before the CPU (and the IPL3) is executed.
https://n64brew.dev/wiki/PIF-NUS#IPL3_checksum_algorithm
"""

def getMagic(self) -> int:
"""
Magic value hardcoded inside the IPL3 itself
"""

def getHashMd5(self) -> str:
"""
Expected md5 hash of the IPL3 blob
"""

@staticmethod
def fromHashMd5(hash_str: str) -> CICKind|None:
...

@staticmethod
def fromValue(value: int) -> CICKind|None:
...

17 changes: 1 addition & 16 deletions src/ipl3checksum/detect.py → src/ipl3checksum/detect.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

from __future__ import annotations

from . import utils
from .cickinds import CICKind, CICHashMd5

from .cickinds import CICKind

def detectCICRaw(rawBytes: bytes) -> CICKind|None:
"""Tries to detect an IPL3 binary.
Expand All @@ -21,17 +19,6 @@ def detectCICRaw(rawBytes: bytes) -> CICKind|None:
CICKind|None: The detected CIC kind, or `None` if was not able to detect the CIC kind.
"""

if len(rawBytes) < 0xFC0:
return None

bytesHash = utils.getHashMd5(rawBytes[:0xFC0])

for kind, expectedHash in CICHashMd5.items():
if bytesHash == expectedHash:
return kind

return None


def detectCIC(romBytes: bytes) -> CICKind|None:
"""Tries to detect an IPL3 in a ROM.
Expand All @@ -44,5 +31,3 @@ def detectCIC(romBytes: bytes) -> CICKind|None:
Returns:
CICKind|None: The detected CIC kind, or `None` if was not able to detect the CIC kind.
"""

return detectCICRaw(romBytes[0x40:0x1000])
Loading

0 comments on commit acda9bf

Please sign in to comment.