def patch_sfx(rom, settings, log, symbols):
    # Configurable Sound Effects
    sfx_config = [
        (settings.sfx_navi_overworld, sfx.SoundHooks.NAVI_OVERWORLD),
        (settings.sfx_navi_enemy, sfx.SoundHooks.NAVI_ENEMY),
        (settings.sfx_low_hp, sfx.SoundHooks.HP_LOW),
        (settings.sfx_menu_cursor, sfx.SoundHooks.MENU_CURSOR),
        (settings.sfx_menu_select, sfx.SoundHooks.MENU_SELECT),
        (settings.sfx_nightfall, sfx.SoundHooks.NIGHTFALL),
        (settings.sfx_horse_neigh, sfx.SoundHooks.HORSE_NEIGH),
        (settings.sfx_hover_boots, sfx.SoundHooks.BOOTS_HOVER),
    ]
    sound_dict = sfx.get_patch_dict()

    for selection, hook in sfx_config:
        if selection == 'default':
            for loc in hook.value.locations:
                sound_id = int.from_bytes((rom.original[loc:loc + 2]),
                                          byteorder='big',
                                          signed=False)
                rom.write_int16(loc, sound_id)
        else:
            if selection == 'random-choice':
                selection = random.choice(
                    sfx.get_hook_pool(hook)).value.keyword
            elif selection == 'random-ear-safe':
                selection = random.choice(sfx.get_hook_pool(
                    hook, "TRUE")).value.keyword
            elif selection == 'completely-random':
                selection = random.choice(sfx.standard).value.keyword
            sound_id = sound_dict[selection]
            for loc in hook.value.locations:
                rom.write_int16(loc, sound_id)
        log.sfx[hook.value.name] = selection
示例#2
0
def patch_sfx(rom, settings, log, symbols):
    # Configurable Sound Effects
    sfx_config = [
        ('sfx_navi_overworld', sfx.SoundHooks.NAVI_OVERWORLD),
        ('sfx_navi_enemy', sfx.SoundHooks.NAVI_ENEMY),
        ('sfx_low_hp', sfx.SoundHooks.HP_LOW),
        ('sfx_menu_cursor', sfx.SoundHooks.MENU_CURSOR),
        ('sfx_menu_select', sfx.SoundHooks.MENU_SELECT),
        ('sfx_nightfall', sfx.SoundHooks.NIGHTFALL),
        ('sfx_horse_neigh', sfx.SoundHooks.HORSE_NEIGH),
        ('sfx_hover_boots', sfx.SoundHooks.BOOTS_HOVER),
    ]
    sound_dict = sfx.get_patch_dict()
    sounds_keyword_label = {
        sound.value.keyword: sound.value.label
        for sound in sfx.Sounds
    }
    sounds_label_keyword = {
        sound.value.label: sound.value.keyword
        for sound in sfx.Sounds
    }

    for setting, hook in sfx_config:
        selection = settings.__dict__[setting]

        # Handle Plando
        if log.src_dict.get('sfx', {}).get(hook.value.name, ''):
            selection_label = log.src_dict['sfx'][hook.value.name]
            if selection_label == 'Default':
                selection = 'default'
            elif selection_label in sounds_label_keyword:
                selection = sounds_label_keyword[selection_label]

        if selection == 'default':
            for loc in hook.value.locations:
                sound_id = rom.original.read_int16(loc)
                rom.write_int16(loc, sound_id)
        else:
            if selection == 'random-choice':
                selection = random.choice(
                    sfx.get_hook_pool(hook)).value.keyword
            elif selection == 'random-ear-safe':
                selection = random.choice(sfx.get_hook_pool(
                    hook, "TRUE")).value.keyword
            elif selection == 'completely-random':
                selection = random.choice(sfx.standard).value.keyword
            sound_id = sound_dict[selection]
            for loc in hook.value.locations:
                rom.write_int16(loc, sound_id)
        if selection == 'default':
            log.sfx[hook.value.name] = 'Default'
        else:
            log.sfx[hook.value.name] = sounds_keyword_label[selection]
def patch_cosmetics(settings, rom):
    log = CosmeticsLog(settings)

    # re-seed for aesthetic effects. They shouldn't be affected by the generation seed
    random.seed()

    # Set default targeting option to Hold
    if settings.default_targeting == 'hold':
        rom.write_byte(0xB71E6D, 0x01)
    else:
        rom.write_byte(0xB71E6D, 0x00)

    # patch music
    if settings.background_music == 'random':
        restore_music(rom)
        log.bgm = randomize_music(rom)
    elif settings.background_music == 'off':
        disable_music(rom)
    else:
        restore_music(rom)

    # patch tunic colors
    tunics = [
        ('Kokiri Tunic', settings.kokiri_color, 0x00B6DA38),
        ('Goron Tunic', settings.goron_color, 0x00B6DA3B),
        ('Zora Tunic', settings.zora_color, 0x00B6DA3E),
    ]
    tunic_color_list = get_tunic_colors()

    for tunic, tunic_option, address in tunics:
        # handle random
        if tunic_option == 'Random Choice':
            tunic_option = random.choice(tunic_color_list)
        # handle completely random
        if tunic_option == 'Completely Random':
            color = [
                random.getrandbits(8),
                random.getrandbits(8),
                random.getrandbits(8)
            ]
        # grab the color from the list
        elif tunic_option in tunic_colors:
            color = tunic_colors[tunic_option]
        # build color from hex code
        else:
            color = list(int(tunic_option[i:i + 2], 16) for i in (0, 2, 4))
            tunic_option = 'Custom'
        rom.write_bytes(address, color)
        log.tunic_colors[tunic] = dict(
            option=tunic_option,
            color=''.join(['{:02X}'.format(c) for c in color]))

    # patch navi colors
    navi = [
        ('Navi Idle', settings.navi_color_default, [0x00B5E184]),  # Default
        ('Navi Targeting Enemy', settings.navi_color_enemy,
         [0x00B5E19C, 0x00B5E1BC]),  # Enemy, Boss
        ('Navi Targeting NPC', settings.navi_color_npc, [0x00B5E194]),  # NPC
        ('Navi Targeting Prop', settings.navi_color_prop, [
            0x00B5E174, 0x00B5E17C, 0x00B5E18C, 0x00B5E1A4, 0x00B5E1AC,
            0x00B5E1B4, 0x00B5E1C4, 0x00B5E1CC, 0x00B5E1D4
        ]),  # Everything else
    ]
    navi_color_list = get_navi_colors()

    for navi_action, navi_option, navi_addresses in navi:
        # choose a random choice for the whole group
        if navi_option == 'Random Choice':
            navi_option = random.choice(navi_color_list)
        custom_color = False
        for address in navi_addresses:
            # completely random is random for every subgroup
            if navi_option == 'Completely Random':
                color = [
                    random.getrandbits(8),
                    random.getrandbits(8),
                    random.getrandbits(8), 0xFF,
                    random.getrandbits(8),
                    random.getrandbits(8),
                    random.getrandbits(8), 0x00
                ]
                if navi_action not in log.navi_colors:
                    log.navi_colors[navi_action] = list()
                log.navi_colors[navi_action].append(
                    dict(option=navi_option,
                         color1=''.join(
                             ['{:02X}'.format(c) for c in color[0:3]]),
                         color2=''.join(
                             ['{:02X}'.format(c) for c in color[4:7]])))
            # grab the color from the list
            elif navi_option in NaviColors:
                color = NaviColors[navi_option]
            # build color from hex code
            else:
                color = list(int(navi_option[i:i + 2], 16) for i in (0, 2, 4))
                color = color + [0xFF] + color + [0x00]
                custom_color = True
            rom.write_bytes(address, color)
        if custom_color:
            navi_option = 'Custom'
        if navi_action not in log.navi_colors:
            log.navi_colors[navi_action] = [
                dict(option=navi_option,
                     color1=''.join(['{:02X}'.format(c) for c in color[0:3]]),
                     color2=''.join(['{:02X}'.format(c) for c in color[4:7]]))
            ]

    # Configurable Sound Effects
    sfx_config = [
        (settings.sfx_hover_boots, sfx.SoundHooks.BOOTS_HOVER),
        (settings.sfx_menu_select, sfx.SoundHooks.MENU_SELECT),
        (settings.sfx_menu_cursor, sfx.SoundHooks.MENU_CURSOR),
        (settings.sfx_horse_neigh, sfx.SoundHooks.HORSE_NEIGH),
        (settings.sfx_navi, sfx.SoundHooks.NAVI),
        (settings.sfx_low_hp, sfx.SoundHooks.HP_LOW),
        (settings.sfx_nightfall, sfx.SoundHooks.NIGHTFALL),
    ]
    sound_dict = sfx.get_patch_dict()

    for selection, hook in sfx_config:
        if selection == 'default':
            for loc in hook.value.locations:
                sound_id = int.from_bytes((rom.original[loc:loc + 2]),
                                          byteorder='big',
                                          signed=False)
                rom.write_int16(loc, sound_id)
        else:
            if selection == 'random-choice':
                selection = random.choice(
                    sfx.get_hook_pool(hook)).value.keyword
            elif selection == 'random-ear-safe':
                selection = random.choice(sfx.no_painful).value.keyword
            elif selection == 'completely-random':
                selection = random.choice(sfx.standard).value.keyword
            sound_id = sound_dict[selection]
            for loc in hook.value.locations:
                rom.write_int16(loc, sound_id)
        log.sfx[hook.value.name] = selection

    # Player Instrument
    instruments = {
        #'none':            0x00,
        'ocarina': 0x01,
        'malon': 0x02,
        'whistle': 0x03,
        'harp': 0x04,
        'grind_organ': 0x05,
        'flute': 0x06,
        #'another_ocarina': 0x07,
    }
    if settings.sfx_ocarina != 'random':
        choice = settings.sfx_ocarina
    else:
        choice = random.choice(list(instruments.keys()))
    rom.write_byte(0x00B53C7B, instruments[choice])
    log.sfx['Ocarina'] = choice

    return log