Fixed TID, type, and IOS editing for WADs via wad edit command

This commit is contained in:
Campbell 2024-11-27 12:42:44 -05:00
parent d6aa50697f
commit fa4e9bf2f1
Signed by: NinjaCheetah
GPG Key ID: B547958AF96ED344
4 changed files with 30 additions and 20 deletions

View File

@ -128,6 +128,13 @@ def _print_ticket_info(ticket: libWiiPy.title.Ticket):
def _print_wad_info(title: libWiiPy.title.Title): def _print_wad_info(title: libWiiPy.title.Title):
print(f"WAD Info") print(f"WAD Info")
channel_title = ""
try:
channel_title = title.get_channel_name()
except ValueError:
pass
if channel_title:
print(f" Channel Name: {channel_title}")
match title.wad.wad_type: match title.wad.wad_type:
case "Is": case "Is":
print(f" WAD Type: Standard Installable") print(f" WAD Type: Standard Installable")

View File

@ -4,7 +4,7 @@
import pathlib import pathlib
import libWiiPy import libWiiPy
from modules.core import fatal_error from modules.core import fatal_error
from modules.title import tmd_edit_ios, tmd_edit_tid, tmd_edit_type from modules.title import title_edit_ios, title_edit_tid, title_edit_type
def handle_tmd_edit(args): def handle_tmd_edit(args):
@ -21,13 +21,16 @@ def handle_tmd_edit(args):
edits_made = False edits_made = False
# Go over every possible change, and apply them if they were specified. # Go over every possible change, and apply them if they were specified.
if args.tid is not None: if args.tid is not None:
tmd = tmd_edit_tid(tmd, args.tid) new_tid = title_edit_tid(tmd.title_id, args.tid)
tmd.set_title_id(new_tid)
edits_made = True edits_made = True
if args.ios is not None: if args.ios is not None:
tmd = tmd_edit_ios(tmd, args.ios) new_ios_tid = title_edit_ios(args.ios)
tmd.ios_tid = new_ios_tid
edits_made = True edits_made = True
if args.type is not None: if args.type is not None:
tmd = tmd_edit_type(tmd, args.type) new_tid = title_edit_type(tmd.title_id, args.type)
tmd.set_title_id(new_tid)
edits_made = True edits_made = True
if not edits_made: if not edits_made:

View File

@ -5,7 +5,7 @@ import pathlib
from random import randint from random import randint
import libWiiPy import libWiiPy
from modules.core import fatal_error from modules.core import fatal_error
from modules.title import tmd_edit_ios, tmd_edit_tid, tmd_edit_type from modules.title import title_edit_ios, title_edit_tid, title_edit_type
def handle_wad_add(args): def handle_wad_add(args):
@ -151,13 +151,17 @@ def handle_wad_edit(args):
edits_made = False edits_made = False
# Go over every possible change, and apply them if they were specified. # Go over every possible change, and apply them if they were specified.
if args.tid is not None: if args.tid is not None:
title.tmd = tmd_edit_tid(title.tmd, args.tid) new_tid = title_edit_tid(title.tmd.title_id, args.tid)
title.set_title_id(new_tid)
edits_made = True edits_made = True
if args.ios is not None: if args.ios is not None:
title.tmd = tmd_edit_ios(title.tmd, args.ios) new_ios_tid = title_edit_ios(args.ios)
title.tmd.ios_tid = new_ios_tid
edits_made = True edits_made = True
if args.type is not None: if args.type is not None:
title.tmd = tmd_edit_type(title.tmd, args.type) print(title.tmd.title_id)
new_tid = title_edit_type(title.tmd.title_id, args.type)
title.set_title_id(new_tid)
edits_made = True edits_made = True
if not edits_made: if not edits_made:

View File

@ -2,11 +2,10 @@
# https://github.com/NinjaCheetah/WiiPy # https://github.com/NinjaCheetah/WiiPy
import binascii import binascii
import libWiiPy
from modules.core import fatal_error from modules.core import fatal_error
def tmd_edit_ios(tmd: libWiiPy.title.TMD, new_ios: str) -> libWiiPy.title.TMD: def title_edit_ios(new_ios: str) -> str:
# Setting a new required IOS. # Setting a new required IOS.
try: try:
new_ios = int(new_ios) new_ios = int(new_ios)
@ -15,24 +14,22 @@ def tmd_edit_ios(tmd: libWiiPy.title.TMD, new_ios: str) -> libWiiPy.title.TMD:
if new_ios < 3 or new_ios > 255: if new_ios < 3 or new_ios > 255:
fatal_error("The specified IOS is not valid! The new IOS version should be between 3 and 255.") fatal_error("The specified IOS is not valid! The new IOS version should be between 3 and 255.")
new_ios_tid = f"00000001{new_ios:08X}" new_ios_tid = f"00000001{new_ios:08X}"
tmd.ios_tid = new_ios_tid return new_ios_tid
return tmd
def tmd_edit_tid(tmd: libWiiPy.title.TMD, new_tid: str) -> libWiiPy.title.TMD: def title_edit_tid(tid: str, new_tid: str) -> str:
# Setting a new TID, only changing TID low since this expects a 4 character ASCII input. # Setting a new TID, only changing TID low since this expects a 4 character ASCII input.
if len(new_tid) != 4: if len(new_tid) != 4:
fatal_error(f"The specified Title ID is not valid! The new Title ID should be 4 characters long.") fatal_error(f"The specified Title ID is not valid! The new Title ID should be 4 characters long.")
if not new_tid.isalnum(): if not new_tid.isalnum():
fatal_error(f"The specified Title ID is not valid! The new Title ID should be alphanumeric.") fatal_error(f"The specified Title ID is not valid! The new Title ID should be alphanumeric.")
# Get the current TID high, because we want to preserve the title type while only changing the TID low. # Get the current TID high, because we want to preserve the title type while only changing the TID low.
tid_high = tmd.title_id[:8] tid_high = tid[:8]
new_tid = f"{tid_high}{str(binascii.hexlify(new_tid.encode()), 'ascii')}" new_tid = f"{tid_high}{str(binascii.hexlify(new_tid.encode()), 'ascii')}"
tmd.set_title_id(new_tid) return new_tid
return tmd
def tmd_edit_type(tmd: libWiiPy.title.TMD, new_type: str) -> libWiiPy.title.TMD: def title_edit_type(tid: str, new_type: str) -> str:
# Setting a new title type. # Setting a new title type.
new_tid_high = None new_tid_high = None
match new_type: match new_type:
@ -51,7 +48,6 @@ def tmd_edit_type(tmd: libWiiPy.title.TMD, new_type: str) -> libWiiPy.title.TMD:
case _: case _:
fatal_error("The specified type is not valid! The new type must be one of: System, Channel, " fatal_error("The specified type is not valid! The new type must be one of: System, Channel, "
"SystemChannel, GameChannel, DLC, HiddenChannel.") "SystemChannel, GameChannel, DLC, HiddenChannel.")
tid_low = tmd.title_id[8:] tid_low = tid[8:]
new_tid = f"{new_tid_high}{tid_low}" new_tid = f"{new_tid_high}{tid_low}"
tmd.set_title_id(new_tid) return new_tid
return tmd