def __init__(self, path): self.wad = wad.Wad(path) #self.path = path self.files = [[0, '<header>']] for path, file in self.wad.files.items(): self.files.append([file[0], path]) self.files.sort() self.offsets = [offset for [offset, _] in self.files]
import formats.wad as wad import sys import json import pprint wad = wad.Wad(sys.argv[1]) offsets = [[0, '<header>']] for path, file in wad.files.items(): offsets.append([file[0], path]) offsets.sort(key=lambda l: l[0]) for i in range(len(offsets) - 1): assert offsets[i][0] < offsets[i + 1][0] print(json.dumps(offsets))
import sys import os import toml import formats.wad as wad import formats.pak as pak from metadata.report_card import report_card as report_card_meta _pak = 'Dr2/data/us/bin/bin_progress_font_l.pak' report_card = toml.load(os.path.join(sys.argv[1], 'report_card.toml')) dr2_data_us = wad.Wad(sys.argv[2]) bin_progress_font_l = pak.PakHeader(dr2_data_us.file, dr2_data_us.files[_pak][0]) bin_progress_font_l_strings = bin_progress_font_l.extract_strings(dr2_data_us.file) def replace_strings(strings, data, meta): if isinstance(data, str): indices = meta.pak_indices while len(indices) > 1: strings = strings[indices[0]] indices.pop(0) strings[indices[0]] = data elif isinstance(data, list): for i in range(len(data)): replace_strings(strings, data[i], meta[i]) elif isinstance(data, dict): for k in data.keys(): replace_strings(strings, data[k], meta[k]) else: raise ValueError replace_strings(bin_progress_font_l_strings, report_card, report_card_meta)
import formats.wad as wad import metadata import argparse parser = argparse.ArgumentParser( description='quickly replaces a file in a wad') parser.add_argument('file') parser.add_argument('wad') parser.add_argument('path') args = vars(parser.parse_args()) wad = wad.Wad(args['wad']) with open(args['file'], 'rb') as f: new_data = f.read() wad.update_file(args['path'], new_data)
import formats.wad as wad import metadata import argparse parser = argparse.ArgumentParser( description='extracts data from dr2_data.wad and dr2_data_us.wad') parser.add_argument('dr2_data') parser.add_argument('dr2_data_us') parser.add_argument('output') parser.add_argument('--prefix', default='') args = vars(parser.parse_args()) dr2_data = wad.Wad(args['dr2_data']) dr2_data_us = wad.Wad(args['dr2_data_us']) wads = { 'dr2_data': dr2_data, 'dr2_data_us': dr2_data_us, } metadata.extract(wads, args['output'], args['prefix'])