BPS support

This commit is contained in:
aerinon
2022-02-17 14:00:00 -07:00
parent ccb7ced735
commit b024311aaa
14 changed files with 451 additions and 9 deletions

View File

@@ -2,8 +2,15 @@ import os
import time
import logging
try:
import bps.apply
import bps.io
except ImportError:
raise Exception('Could not load BPS module')
from Utils import output_path
from Rom import LocalRom, apply_rom_settings
from source.tools.BPS import bps_read_vlv
def adjust(args):
@@ -34,3 +41,37 @@ def adjust(args):
logger.debug('Total Time: %s', time.process_time() - start)
return args
def patch(args):
start = time.process_time()
logger = logging.getLogger('')
logger.info('Patching ROM.')
outfile_base = os.path.basename(args.patch)[:-4]
rom = LocalRom(args.baserom, False)
if os.path.isfile(args.baserom):
rom.verify_base_rom()
orig_buffer = rom.buffer.copy()
with open(args.patch, 'rb') as stream:
stream.seek(4) # skip BPS1
bps_read_vlv(stream) # skip source size
target_length = bps_read_vlv(stream)
rom.buffer.extend(bytearray([0x00] * (target_length - len(rom.buffer))))
stream.seek(0)
bps.apply.apply_to_bytearrays(bps.io.read_bps(stream), orig_buffer, rom.buffer)
if not hasattr(args, "sprite"):
args.sprite = None
apply_rom_settings(rom, args.heartbeep, args.heartcolor, args.quickswap, args.fastmenu, args.disablemusic,
args.sprite, args.ow_palettes, args.uw_palettes, args.reduce_flashing, args.shuffle_sfx)
output_path.cached_path = args.outputpath
rom.write_to_file(output_path('%s.sfc' % outfile_base))
logger.info('Done. Enjoy.')
logger.debug('Total Time: %s', time.process_time() - start)
return args