Beispiel #1
0
def get_npc_palettes():
    palettes = {}
    for n in get_npcs():
        g = n.graphics
        if g not in palettes:
            palettes[g] = set([])
        palettes[g].add(n.palette)
    for k, v in list(palettes.items()):
        palettes[k] = sorted(v)
    return palettes
Beispiel #2
0
def manage_palettes(fout, change_to, char_ids):
    sabin_mode = options_.is_code_active('suplexwrecks')
    tina_mode = options_.is_code_active('bravenudeworld')
    christmas_mode = options_.is_code_active('christmas')
    new_palette_mode = not options_.is_code_active('sometimeszombies')

    characters = get_characters()
    npcs = get_npcs()
    charpal_options = {}
    for line in open(CHARACTER_PALETTE_TABLE):
        if line[0] == '#':
            continue
        charid, palettes = tuple(line.strip().split(':'))
        palettes = list(map(hex2int, palettes.split(',')))
        charid = hex2int(charid)
        charpal_options[charid] = palettes

    if new_palette_mode:
        twinpal = random.randint(0, 5)
        char_palette_pool = list(range(0, 6)) + list(range(0, 6))
        char_palette_pool.remove(twinpal)
        char_palette_pool.append(
            random.choice(list(range(0, twinpal)) + list(range(twinpal, 6))))
        while True:
            random.shuffle(char_palette_pool)
            #make sure terra, locke, and edgar are all different
            if twinpal in char_palette_pool[0:2]:
                continue
            if char_palette_pool[0] == char_palette_pool[1]:
                continue
            break
        char_palette_pool = char_palette_pool[:4] + [twinpal, twinpal
                                                     ] + char_palette_pool[4:]

    palette_change_to = {}
    additional_celeses = []
    for npc in npcs:
        if npc.graphics == 0x41:
            additional_celeses.append(npc)
        if npc.graphics not in charpal_options:
            continue
        # Don't recolor shadowy Sabin on Mt. Kolts
        if npc.locid in [0x60, 0x61]:
            continue
        if npc.graphics in change_to:
            new_graphics = change_to[npc.graphics]
            if (npc.graphics, npc.palette) in palette_change_to:
                new_palette = palette_change_to[(npc.graphics, npc.palette)]
            elif new_palette_mode and npc.graphics < 14:
                new_palette = char_palette_pool[npc.graphics]
                palette_change_to[(npc.graphics, npc.palette)] = new_palette
                npc.palette = new_palette
            else:
                while True:
                    new_palette = random.choice(charpal_options[new_graphics])
                    if sabin_mode or tina_mode:
                        new_palette = random.randint(0, 5)

                    if (new_palette == 5 and new_graphics
                            not in [3, 0xA, 0xC, 0xD, 0xE, 0xF, 0x12, 0x14]
                            and random.randint(1, 10) != 10):
                        continue
                    break
                palette_change_to[(npc.graphics, npc.palette)] = new_palette
                npc.palette = new_palette
            npc.palette = new_palette
    for npc in additional_celeses:
        if (6, 0) in palette_change_to:
            npc.palette = palette_change_to[(6, 0)]

    main_palette_changes = {}
    for character in characters:
        c = character.id
        if c not in change_to:
            continue
        fout.seek(0x2CE2B + c)
        before = ord(fout.read(1))
        new_graphics = change_to[c]
        new_palette = palette_change_to[(c, before)]
        main_palette_changes[c] = (before, new_palette)
        fout.seek(0x2CE2B + c)
        fout.write(bytes([new_palette]))
        pointers = [0, 4, 9, 13]
        pointers = [ptr + 0x18EA60 + (18 * c) for ptr in pointers]
        if c < 14:
            for ptr in pointers:
                fout.seek(ptr)
                byte = ord(fout.read(1))
                byte = byte & 0xF1
                byte |= ((new_palette + 2) << 1)
                fout.seek(ptr)
                fout.write(bytes([byte]))
        character.palette = new_palette

    if options_.is_code_active('repairpalette'):
        make_palette_repair(fout, main_palette_changes)

    if new_palette_mode:
        char_hues = [
            0, 10, 20, 30, 45, 60, 75, 90, 120, 150, 180, 200, 220, 240, 270,
            300, 330
        ]
        char_hues.append(random.choice([0, 0, 345, random.randint(105, 135)]))
        char_hues = shuffle_char_hues(char_hues)
        skintones = [((31, 24, 17), (25, 13, 7)), ((31, 23, 15), (25, 15, 8)),
                     ((31, 24, 17), (25, 13, 7)), ((31, 25, 15), (25, 19, 10)),
                     ((31, 25, 16), (24, 15, 12)),
                     ((27, 17, 10), (20, 12, 10)), ((25, 20, 14), (19, 12, 4)),
                     ((27, 22, 18), (20, 15, 12)), ((28, 22, 16), (22, 13, 6)),
                     ((28, 23, 15), (22, 16, 7)), ((27, 23, 15), (20, 14, 9))]
        snowmanvampire = ((29, 29, 30), (25, 25, 27))
        if christmas_mode or random.randint(1, 100) > 66:
            skintones.append(snowmanvampire)
        random.shuffle(skintones)
        # no vampire townsfolk
        if snowmanvampire in skintones[:6] and not christmas_mode:
            skintones.remove(snowmanvampire)
            skintones = skintones[:5] + [snowmanvampire]

    for i in range(6):
        pointer = 0x268000 + (i * 0x20)
        if new_palette_mode:
            palette = recolor_character_palette(fout,
                                                pointer,
                                                palette=None,
                                                flesh=(i == 5),
                                                santa=(christmas_mode
                                                       and i == 3),
                                                skintones=skintones,
                                                char_hues=char_hues)
        else:
            palette = recolor_character_palette(fout,
                                                pointer,
                                                palette=None,
                                                flesh=(i == 5),
                                                santa=(christmas_mode
                                                       and i == 3))
        pointer = 0x2D6300 + (i * 0x20)
        recolor_character_palette(fout, pointer, palette=palette)

    # esper terra
    pointer = 0x268000 + (8 * 0x20)
    if new_palette_mode:
        palette = recolor_character_palette(fout,
                                            pointer,
                                            palette=None,
                                            trance=True)
    else:
        palette = recolor_character_palette(fout,
                                            pointer,
                                            palette=None,
                                            flesh=True,
                                            middle=False)
    pointer = 0x2D6300 + (6 * 0x20)
    palette = recolor_character_palette(fout, pointer, palette=palette)

    # recolor magitek and chocobos
    transformer = get_palette_transformer(middle=True)

    def recolor_palette(pointer, size):
        fout.seek(pointer)
        palette = [read_multi(fout, length=2) for _ in range(size)]
        palette = transformer(palette)
        fout.seek(pointer)
        for c in palette:
            write_multi(fout, c, length=2)

    recolor_palette(0x2cfd4, 23)
    recolor_palette(0x268000 + (7 * 0x20), 16)
    recolor_palette(0x12ee20, 16)
    recolor_palette(0x12ef20, 16)

    for line in open(EVENT_PALETTE_TABLE):
        if line[0] == '#':
            continue
        line = line.split(' ')
        if len(line) > 1:
            if line[1] == 'c' and options_.is_code_active(
                    'thescenarionottaken'):
                return
            if line[1] == 'd' and not options_.is_code_active(
                    'thescenarionottaken'):
                return
        pointer = hex2int(line[0].strip())
        fout.seek(pointer)
        data = bytearray(fout.read(5))
        char_id, palette = data[1], data[4]
        if char_id not in char_ids:
            continue
        try:
            data[4] = palette_change_to[(char_id, palette)]
        except KeyError:
            continue

        fout.seek(pointer)
        fout.write(data)