## Using slightly modified ticket patching from FunKiiU ##
def patch_ticket(ticket_data, offset, data):
"""
Patch a Wii U ticket with the given data.
Parameters:
ticket_data (bytearray): The ticket data to be patched.
offset (int): The offset to start the patching.
data (bytes): The data to be patched in.
Returns:
None
"""
ticket_offset_start = TIK_OFFSET + offset
ticket_offset_end = ticket_offset_start + len(data)
ticket_data[ticket_offset_start:ticket_offset_end] = data
def patch_ticket_demo(ticket_data):
"""
This function takes a Wii U ticket data and patches it with demo data.
Parameters:
ticket_data (bytearray): The ticket data to be patched.
offset (int): The offset to start the patching.
demo_data (bytes): The data to be patched in.
Returns:
None
"""
# Offset to patch
offset = 0x124
# Demo data to be patched
demo_data = b"\x00" * 64
# Patch the ticket data with demo data
patch_ticket(ticket_data, offset, demo_data)
def patch_ticket_dlc(ticket_data):
"""
This function takes a Wii U ticket data and patches it with DLC data.
Parameters:
ticket_data (bytearray): The ticket data to be patched.
offset (int): The offset to start the patching.
dlc_data (bytes): The data to be patched in.
Returns:
None
"""
# Offset to patch
offset = 0x164
# DLC data to be patched
dlc_data = base64.b64decode("...") # not showing this on GBATemp, srry
dlc_data = zlib.decompress(dlc_data)
# Patch the ticket data with DLC data
patch_ticket(ticket_data, offset, dlc_data)
def generate_ticket(title_id, title_key, title_version, full_output_path, patch_demo=False, patch_dlc=False):
"""
This function generates a Wii U ticket for a given title ID, title key, and title version.
title_id: The ID of the title.
title_key: The key of the title.
title_version: The version of the title.
full_output_path: The path to save the ticket.
patch_demo: A flag indicating whether to patch the ticket with demo data.
patch_dlc: A flag indicating whether to patch the ticket with DLC data.
"""
# Create an empty bytearray to store the ticket data
ticket_data = bytearray(TIK_DATA)
# Update the title version, title ID, and title key in the ticket data
ticket_data[TIK_OFFSET + 0xA6: TIK_OFFSET + 0xA8] = title_version
ticket_data[TIK_OFFSET + 0x9C: TIK_OFFSET + 0xA4] = binascii.a2b_hex(title_id)
ticket_data[TIK_OFFSET + 0x7F: TIK_OFFSET + 0x8F] = binascii.a2b_hex(title_key)
# Determine the type of title ID and apply the corresponding patch function if applicable
type_check = title_id[4:8]
patch_functions = {
"0002": patch_ticket_demo if patch_demo else None,
"000C": patch_ticket_dlc if patch_dlc else None,
}
patch_func = patch_functions.get(type_check)
if patch_func:
patch_func(ticket_data)
# Save the ticket data to the specified output path
with open(full_output_path, "wb") as f:
f.write(ticket_data)
## Using slightly modified ticket patching from FunKiiU ##