From 39eecec8644477ccd7418a72a1a8129f0fc3e9f8 Mon Sep 17 00:00:00 2001 From: NinjaCheetah <58050615+NinjaCheetah@users.noreply.github.com> Date: Thu, 25 Jul 2024 13:09:01 -0400 Subject: [PATCH] Fall back on key 0 when invalid, fix footer reading code --- src/libWiiPy/title/commonkeys.py | 5 +++-- src/libWiiPy/title/content.py | 6 +++--- src/libWiiPy/title/wad.py | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/libWiiPy/title/commonkeys.py b/src/libWiiPy/title/commonkeys.py index 9875bff..66cd8be 100644 --- a/src/libWiiPy/title/commonkeys.py +++ b/src/libWiiPy/title/commonkeys.py @@ -10,7 +10,8 @@ vwii_key = '30bfc76e7c19afbb23163330ced7c28d' def get_common_key(common_key_index) -> bytes: """ - Gets the specified Wii Common Key based on the index provided. + Gets the specified Wii Common Key based on the index provided. If an invalid common key index is provided, this + function falls back on always returning key 0 (the Common Key). Possible values for common_key_index: 0: Common Key, 1: Korean Key, 2: vWii Key @@ -32,5 +33,5 @@ def get_common_key(common_key_index) -> bytes: case 2: common_key_bin = binascii.unhexlify(vwii_key) case _: - raise ValueError("The common key index provided, " + str(common_key_index) + ", does not exist.") + common_key_bin = binascii.unhexlify(common_key) return common_key_bin diff --git a/src/libWiiPy/title/content.py b/src/libWiiPy/title/content.py index 783da79..df4fba9 100644 --- a/src/libWiiPy/title/content.py +++ b/src/libWiiPy/title/content.py @@ -84,7 +84,7 @@ class ContentRegion: content_region_data = b'' for content in self.content_list: # If this isn't the first content, pad the whole region to 64 bytes before the next one. - if content_region_data is not b'': + if content_region_data != b'': content_region_data = _pad_bytes(content_region_data, 64) # Calculate padding after this content before the next one. padding_bytes = 0 @@ -127,7 +127,7 @@ class ContentRegion: Parameters ---------- cid : int - The Content ID of the content you want to get. Expected to be in decimal form. + The Content ID of the content you want to get. Expected to be in decimal form, not hex. Returns ------- @@ -197,7 +197,7 @@ class ContentRegion: Parameters ---------- cid : int - The Content ID of the content you want to get. Expected to be in decimal form. + The Content ID of the content you want to get. Expected to be in decimal form, not hex. title_key : bytes The Title Key for the title the content is from. diff --git a/src/libWiiPy/title/wad.py b/src/libWiiPy/title/wad.py index 765211a..0853d71 100644 --- a/src/libWiiPy/title/wad.py +++ b/src/libWiiPy/title/wad.py @@ -103,13 +103,13 @@ class WAD: # Calculate file offsets from sizes. Every section of the WAD is padded out to a multiple of 0x40. # ==================================================================================== wad_cert_offset = self.wad_hdr_size - # crl isn't ever used, however an entry for its size exists in the header, so its calculated just in case. + # crl isn't ever used, however an entry for its size exists in the header, so it's calculated just in case. wad_crl_offset = _align_value(wad_cert_offset + self.wad_cert_size) wad_tik_offset = _align_value(wad_crl_offset + self.wad_crl_size) wad_tmd_offset = _align_value(wad_tik_offset + self.wad_tik_size) + wad_content_offset = _align_value(wad_tmd_offset + self.wad_tmd_size) # meta isn't guaranteed to be used, but some older SDK titles use it, and not reading it breaks things. - wad_meta_offset = _align_value(wad_tmd_offset + self.wad_tmd_size) - wad_content_offset = _align_value(wad_meta_offset + self.wad_meta_size) + wad_meta_offset = _align_value(wad_content_offset + self.wad_content_size) # ==================================================================================== # Load data for each WAD section based on the previously calculated offsets. # ====================================================================================