Fall back on key 0 when invalid, fix footer reading code

This commit is contained in:
Campbell 2024-07-25 13:09:01 -04:00
parent 5f4fa8827c
commit 39eecec864
Signed by: NinjaCheetah
GPG Key ID: 670C282B3291D63D
3 changed files with 9 additions and 8 deletions

View File

@ -10,7 +10,8 @@ vwii_key = '30bfc76e7c19afbb23163330ced7c28d'
def get_common_key(common_key_index) -> bytes: 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 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: case 2:
common_key_bin = binascii.unhexlify(vwii_key) common_key_bin = binascii.unhexlify(vwii_key)
case _: 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 return common_key_bin

View File

@ -84,7 +84,7 @@ class ContentRegion:
content_region_data = b'' content_region_data = b''
for content in self.content_list: 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 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) content_region_data = _pad_bytes(content_region_data, 64)
# Calculate padding after this content before the next one. # Calculate padding after this content before the next one.
padding_bytes = 0 padding_bytes = 0
@ -127,7 +127,7 @@ class ContentRegion:
Parameters Parameters
---------- ----------
cid : int 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 Returns
------- -------
@ -197,7 +197,7 @@ class ContentRegion:
Parameters Parameters
---------- ----------
cid : int 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 title_key : bytes
The Title Key for the title the content is from. The Title Key for the title the content is from.

View File

@ -103,13 +103,13 @@ class WAD:
# Calculate file offsets from sizes. Every section of the WAD is padded out to a multiple of 0x40. # 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 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_crl_offset = _align_value(wad_cert_offset + self.wad_cert_size)
wad_tik_offset = _align_value(wad_crl_offset + self.wad_crl_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_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. # 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_meta_offset = _align_value(wad_content_offset + self.wad_content_size)
wad_content_offset = _align_value(wad_meta_offset + self.wad_meta_size)
# ==================================================================================== # ====================================================================================
# Load data for each WAD section based on the previously calculated offsets. # Load data for each WAD section based on the previously calculated offsets.
# ==================================================================================== # ====================================================================================