From c58e63b6953494b5a92d9e6e5f34481ad20ea36b Mon Sep 17 00:00:00 2001 From: LLCoolDave Date: Fri, 26 May 2017 18:39:32 +0200 Subject: [PATCH] Add support for custom Link sprites. --- Main.py | 12 +++++++++++- Rom.py | 6 +++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Main.py b/Main.py index c231a634..4cb3a900 100644 --- a/Main.py +++ b/Main.py @@ -70,8 +70,13 @@ def main(args, seed=None): logger.info('Patching ROM.') + if args.sprite is not None: + sprite = bytearray(open(args.sprite, 'rb').read()) + else: + sprite = None + rom = bytearray(open(args.rom, 'rb').read()) - patched_rom = patch_rom(world, rom, logic_hash, args.quickswap, args.heartbeep) + patched_rom = patch_rom(world, rom, logic_hash, args.quickswap, args.heartbeep, sprite) outfilebase = 'ER_%s_%s_%s_%s' % (world.mode, world.goal, world.shuffle, world.seed) @@ -394,11 +399,16 @@ if __name__ == '__main__': parser.add_argument('--nodungeonitems', help='Remove Maps and Compasses from Itempool, replacing them by empty slots.', action='store_true') parser.add_argument('--heartbeep', default='normal', const='normal', nargs='?', choices=['normal', 'half', 'quarter', 'off'], help='Select the rate at which the heart beep sound is played at low health.') + parser.add_argument('--sprite', help='Path to a sprite sheet to use for Link. Needs to be in binary format and have a length of 0x7000 (28672) bytes.') args = parser.parse_args() + # ToDo: Validate files further than mere existance if not os.path.isfile(args.rom): input('Could not find valid base rom for patching at expected path %s. Please run with -h to see help for further information. \nPress Enter to exit.' % args.rom) exit(1) + if args.sprite is not None and not os.path.isfile(args.rom): + input('Could not find link sprite sheet at given location. \nPress Enter to exit.' % args.sprite) + exit(1) # set up logger loglevel = {'error': logging.ERROR, 'info': logging.INFO, 'warning': logging.WARNING, 'debug': logging.DEBUG}[args.loglevel] diff --git a/Rom.py b/Rom.py index 3634b64a..3240eb3a 100644 --- a/Rom.py +++ b/Rom.py @@ -6,7 +6,7 @@ from Text import KingsReturn_texts, Sanctuary_texts, Kakariko_texts, Blacksmiths import random -def patch_rom(world, rom, hashtable, quickswap=False, beep='normal'): +def patch_rom(world, rom, hashtable, quickswap=False, beep='normal', sprite=None): # patch items for location in world.get_locations(): if location.name == 'Ganon': @@ -233,6 +233,10 @@ def patch_rom(world, rom, hashtable, quickswap=False, beep='normal'): # store hash table for main menu hash write_bytes(rom, 0x181000, hashtable) + # write link sprite if required + if sprite is not None: + write_bytes(rom, 0x80000, sprite) + return rom