From c5025348dde9c4fd281646e4702f47d94429e655 Mon Sep 17 00:00:00 2001 From: rmc Date: Thu, 29 Feb 2024 22:12:26 -0500 Subject: [PATCH] Get WAD content records. --- .gitignore | 8 +++++++- src/libWiiPy/tmd.py | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 62b9984..aef39b9 100644 --- a/.gitignore +++ b/.gitignore @@ -163,4 +163,10 @@ cython_debug/ # Allows me to keep TMD files in my repository folder for testing without accidentally publishing them *.tmd -*.wad \ No newline at end of file +*.wad +out_prod/ +remakewad.pl + +# Also awful macOS files +*._* +*.DS_Store diff --git a/src/libWiiPy/tmd.py b/src/libWiiPy/tmd.py index 31155b0..114ae47 100644 --- a/src/libWiiPy/tmd.py +++ b/src/libWiiPy/tmd.py @@ -5,6 +5,7 @@ import io import binascii +import struct from dataclasses import dataclass from typing import List @@ -41,7 +42,8 @@ class TMD: self.title_version: int self.num_contents: int self.boot_index: int - self.content_record: List[ContentRecord] + self.content_record: List[ContentRecord] = [] + self.content_record_hdr: List = [] # Load data from TMD file with io.BytesIO(tmd) as tmddata: # Signing certificate issuer @@ -101,6 +103,13 @@ class TMD: # Content index in content list that contains the boot file tmddata.seek(0x1E0) self.boot_index = tmddata.read(2) + # Got content records for the number of contents in num_contents. + i = 0 + while i < self.num_contents: + tmddata.seek(0x1E4 + (36 * i)) + self.content_record_hdr = struct.unpack(">LHH4x4s20s", tmddata.read(36)) + self.content_record.append(ContentRecord(self.content_record_hdr[0], self.content_record_hdr[1], self.content_record_hdr[2], self.content_record_hdr[3], self.content_record_hdr[4])) + i += 1 def get_title_id(self): """Returns the TID of the TMD's associated title.""" @@ -183,3 +192,7 @@ class TMD: def get_num_contents(self): """Returns the number of contents listed in the TMD.""" return self.num_contents + + def get_content_records(self, record): + """Returns all values for the specified content record.""" + return self.content_record[record].cid, self.content_record[record].index, self.content_record[record].content_type, self.content_record[record].content_size, self.content_record[record].content_hash