#!/usr/bin/env python3 # parameters # stdin - input containing list of game metadata, filename, display name (e.g. GAMES.CONF or some subset of it) # stdout - binary OKVS data structure # 1 - output filename for game count in assembler code format # 2 - input filename of HGR titles, offsets, and sizes # 3 - input filename of DHGR titles, offsets, and sizes import argparse import pprint import struct import sys gSearchIndex = 0x6000 # must match gSearchIndex in src/constants.a # indexes into |flags| as string iDHGRTitle = 2 iCheatCategory = 3 iSingleLoad = 4 # maps of flag raw string value -> value in final flags byte kHasDHGRTitle = {'0': 0, '1': 128} kSingleLoad = {'0': 0, '1': 64} def parse_log_file(filename): rv = {} if filename: with open(filename, 'r') as f: lines = [x.strip().split(',') for x in f.readlines()] for title, offset, size in lines: rv[title] = (int(offset), int(size)) return rv def build(records, args): # records is [(flags, key, value), (flags, key, value) ...] hgr_cache = parse_log_file(args.input_hgr_log_file) dhgr_cache = parse_log_file(args.input_dhgr_log_file) cache_ptr = {'0': hgr_cache, '1': dhgr_cache} record_count = len(records) # generate source file with game count with open(args.output_game_count_file, 'w') as file_handle: file_handle.write(f"""; ; Game count ; ; This file is automatically generated ; !word {record_count:>8} """) # yield OKVS record count (2 bytes, unsigned int, little-endian) yield struct.pack('L', rec_offset)[1:] # yield record size (2 bytes, little-endian, unsigned short) yield struct.pack('