Пример #1
0
    for letter_i in range(0, len(tilepairs)):
        letter = Pixmap((8,16))
        letter.paste(tilepairs[letter_i][0], (0,0))
        letter.paste(tilepairs[letter_i][1], (0,8))
        
        x = (letter_i % ROW_LETTERS) * 16
        y = (letter_i // ROW_LETTERS) * 16
        img.paste(letter.flip_lr(), (x,y))

    img.save(name, PIXELCHARS)

print("Reading font data")
raw_tiles = {}
for fontname in OFFSETS:
    data = rom[OFFSETS[fontname][0] : OFFSETS[fontname][1]]
    raw_tiles[fontname] = list(gba.iter_decode_tiles(codec, data))

print("Exporting normal fonts")
decode_en(raw_tiles["font_en_black"], EXPDIR + "font_en_black.txt")
decode_jp(raw_tiles["font_jp_black"], EXPDIR + "font_jp_black.txt")
decode_en(raw_tiles["font_en_red"], EXPDIR + "font_en_red.txt")
decode_jp(raw_tiles["font_jp_red"], EXPDIR + "font_jp_red.txt")
decode_en(raw_tiles["font_en_blue"], EXPDIR + "font_en_blue.txt")
decode_jp(raw_tiles["font_jp_blue"], EXPDIR + "font_jp_blue.txt")
decode_en(raw_tiles["font_en_other"], EXPDIR + "font_en_other.txt")
decode_jp_tiny(raw_tiles["font_jp_other"], EXPDIR + "font_jp_other.txt")

print("Exporting tiny fonts")
decode_en_tiny(raw_tiles["font_en_tiny"], EXPDIR + "font_en_tiny.txt")
decode_jp_tiny(raw_tiles["font_jp_tiny"], EXPDIR + "font_jp_tiny.txt")
decode_jp_tiny(raw_tiles["font_jp_tiny2"], EXPDIR + "font_jp_tiny2.txt")
Пример #2
0
bag_palette_data = lz77.decompress(rom[bag_palette:])

bag_palette_pal = gba.decode_palette(bag_palette_data, alpha=True)
bag_male_img = gba.decode_image(bag_male_data, codec, bag_palette_pal, 8)
bag_male_img.save("export/textures/bag_male.png")
bag_female_img = gba.decode_image(bag_female_data, codec, bag_palette_pal, 8)
bag_female_img.save("export/textures/bag_female.png")

arrow_data = lz77.decompress(rom[arrow_addr:])
arrow_palette_data = lz77.decompress(rom[arrow_palette_addr:])
arrow_palette = gba.decode_palette(arrow_palette_data, alpha=True)
arrow_image = gba.decode_image(arrow_data, codec, arrow_palette, 2)
arrow_image.save("export/textures/arrow.png")

bkgr_data = lz77.decompress(rom[bkgr_addr:])
bkgr_tiles = list(gba.iter_decode_tiles(codec, bkgr_data))

bkgr_palettes = [None, None]
bkgr_palettes_data0 = lz77.decompress(rom[bkgr_palettes_addr[0]:])
bkgr_palettes_data1 = lz77.decompress(rom[bkgr_palettes_addr[1]:])
bkgr_palettes[0] = list(gba.iter_decode_palettes(bkgr_palettes_data0, alpha=True))
bkgr_palettes[1] = copy.copy(bkgr_palettes[0])
bkgr_palettes[1][0] = gba.decode_palette(bkgr_palettes_data1)

for mode in (0,1):
    bkgr_map = lz77.decompress(rom[bkgr_maps_addr[mode]:])
    for gender in (0,1):
        bkgr_map_tiles = gba.decode_tilemap(bkgr_map, bkgr_tiles, bkgr_palettes[gender])
        bkgr_img = gba.combine_tiles(bkgr_map_tiles, 32)
        bkgr_img = bkgr_img.crop((0, 0, 240, 160))
        bkgr_img.save("export/textures/background{}_{}.png".format(mode, GENDERNAMES[gender]))
Пример #3
-1
def decode_tilemap_at(rom, codec, image_ptr, palettes_ptr, tilemap_ptr, width=16):
    image_offset = get_rom_addr(image_ptr)
    palettes_offset = get_rom_addr(palettes_ptr)
    tilemap_offset = get_rom_addr(tilemap_ptr)
    bpp = codec.getBitsPerPixel()

    if check_valid(rom, image_offset, strict=True):
        print("Loading compressed image at", hex(image_ptr))
        image_data = lz77.decompress(rom, image_offset)
    else:
        print("Loading uncompressed image at", hex(image_ptr))
        image_len = 1024 * codec.getTileSize()  # Max amount of tiles
        image_data = rom[image_offset : image_offset + image_len]

    tile_size = codec.getTileSize()
    if len(image_data) % tile_size:
        # Fill remaining tile with padding bytes
        image_data += b"\x00" * (tile_size - len(image_data) % tile_size)

    pal_size = gba.get_palette_size(bpp)
    if check_valid(rom, palettes_offset, strict=True):
        print("Loading compressed palettes at", hex(palettes_ptr))
        palettes_data = lz77.decompress(rom, palettes_offset)
        if len(palettes_data) < pal_size:
            return "PALETTE_TOO_SMALL"
    else:
        print("Loading uncompressed palettes at", hex(palettes_ptr))
        palettes_len = 16 * pal_size  # Max amount of palettes
        palettes_data = rom[palettes_offset : palettes_offset + palettes_len]

    if check_valid(rom, tilemap_offset, strict=True):
        print("Loading compressed tilemap at", hex(tilemap_ptr))
        tilemap = lz77.decompress(rom, tilemap_offset)
    else:
        print("Loading uncompressed tilemap at", hex(tilemap_ptr))
        tilemap_len = 1024  # Max tilemap size (maybe)
        tilemap = rom[tilemap_offset : tilemap_offset + tilemap_len]

    try:
        tiles = list(gba.iter_decode_tiles(codec, image_data))
    except:
        return "IMAGE_DECODE_FAILED"

    try:
        palettes = list(gba.iter_decode_palettes(palettes_data, bpp=bpp, alpha=True))
    except:
        return "PALETTE_DECODE_FAILED"

    try:
        tilemap_tiles = gba.decode_tilemap(tilemap, tiles, palettes)
        img = gba.combine_tiles(tilemap_tiles, width)
    except:
        return "TILEMAP_DECODE_FAILED"

    return img