Beispiel #1
0
#!/bin/python

# Script to initially dump tilesets

import os, sys
from functools import partial

sys.path.append(os.path.join(os.path.dirname(__file__), 'common'))
from common import utils, tilesets

nametable = {}
namefile = None
if os.path.exists("scripts/res/tileset_names.tbl"):
	nametable = utils.read_table("scripts/res/tileset_names.tbl")
else:
	namefile = open("scripts/res/tileset_names.tbl","w")

tiletable = 0x10f0
count = 51
with open("baserom_kabuto.gb", "rb") as rom, open("game/src/gfx/tileset_table.asm", "w") as output:
	rom.seek(tiletable)
	ptrs = [utils.read_short(rom) for i in range(0, count)]
	data = {}
	for ptr in ptrs:
		rom.seek(ptr) # Bank 0, no need to convert addresses
		# (Bank, Pointer, VRAM Offset, Name)
		if namefile: # We assume the table file not existing is fine
			nametable[ptr] = "{:04X}".format(ptr)
			namefile.write("{:04X}={}\n".format(ptr, nametable[ptr]))
		data[ptr] = (utils.read_byte(rom), utils.read_short(rom), utils.read_short(rom), nametable[ptr])
	output.write('INCLUDE "game/src/common/macros.asm"\n\n')
Beispiel #2
0
import os, sys
from shutil import copyfile
sys.path.append(os.path.join(os.path.dirname(__file__), 'common'))
from common import utils

if __name__ == '__main__':
    input_file = sys.argv[1]
    output_file = sys.argv[2]

    with open(output_file, 'w') as f:
        t = utils.read_table(input_file, keystring=True)
        for k in t:
            f.write("c{:<5}           EQU ${:04X}\n".format(k, int(t[k], 16)))
Beispiel #3
0
output_file = sys.argv[1]
input_file = sys.argv[2]
column_name = sys.argv[3]
version_suffix = sys.argv[4]

base_name = os.path.splitext(os.path.basename(input_file))[0]
char_table = utils.reverse_dict(
    utils.merge_dicts([
        tilesets.get_tileset("MainDialog1", override_offset=0x0),
        tilesets.get_tileset("MainDialog2", override_offset=0x80),
        tilesets.get_tileset("Special", override_offset=0xE0)
    ]))
kanji = utils.reverse_dict(tilesets.get_tileset("Kanji", override_offset=0x0))
assert ((set(kanji.keys()) - set(char_table.keys())) == set(kanji.keys()))
ptr_names = utils.read_table(os.path.join(os.path.dirname(__file__), 'res',
                                          'ptrs.tbl'),
                             keystring=True)

with open(input_file, 'r', encoding='utf-8-sig') as fp:
    reader = csv.reader(fp, delimiter=',', quotechar='"')
    header = next(reader, None)
    idx_index = header.index("Index[#version]")
    idx_pointer = header.index("Pointer[#version|]")
    idx_text = header.index(column_name)

    # Keep track of the offset from the start
    bintext = bytearray()
    pointer_offset_map = OrderedDict()
    pointer_length_map = OrderedDict()

    for line in reader:
Beispiel #4
0
#!/bin/python

import os, sys
from ast import literal_eval
sys.path.append(os.path.join(os.path.dirname(__file__), 'common'))
from common import utils

if __name__ == '__main__':
    input_file = sys.argv[1]
    output_file = sys.argv[2]
    version_suffix = sys.argv[3]

    # This is actually a hack with how lists work
    # TODO: Tilesets are probably going to vary between lists, so this may break in the future
    char_table = utils.merge_dicts([
        utils.read_table("scripts/res/tileset_MainDialog.tbl", reverse=True),
        utils.read_table("scripts/res/tileset_MainSpecial.tbl", reverse=True),
        utils.read_table("scripts/res/tileset_MenuText.tbl", reverse=True),
        utils.read_table("scripts/res/dakuten.tbl", reverse=True),
    ])

    char_table2 = utils.merge_dicts([
        char_table,
        utils.read_table("scripts/res/tileset_BoldLetters.tbl", reverse=True)
    ])

    with open(output_file, 'wb') as o, open(input_file, 'r',
                                            encoding="utf-8") as i:
        length, term, padbyte = (int(x) if x.isdigit() else literal_eval(x)
                                 for x in i.readline().split("|"))
        char_table['\n'] = term
Beispiel #5
0
    if len(txt):
        result.append(0x4F)
        result.append(endcode)
    return result


if __name__ == '__main__':
    # TODO: Set this up to take these as an argument
    arg1 = 'build'  #output directory
    trans_dir = 'text/credits'
    output_dir = 'build'

    char_table = utils.merge_dicts([
        utils.read_table(
            "scripts/res/medarot.tbl", reverse=True
        ),  # FIXME: There are missing tileset mappings, for now just read medarot.tbl
        #utils.read_table("scripts/res/tileset_MainDialog.tbl", reverse=True),
        #utils.read_table("scripts/res/tileset_MainSpecial.tbl", reverse=True),
        #utils.read_table("scripts/res/dakuten.tbl", reverse=True),
    ])
    char_table['\\'] = 0x4A
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)

    #Reads from the text_tables.asm file to determine banks
    sections = ['Credits']
    bank_size_max = 0x7FFF

    bank_map = {}
    with open('game/src/story/credits.asm', 'r') as txt_file:
Beispiel #6
0
         ("baserom_kuwagata.gbc", "kuwagata")])

# Kabuto and Kuwagata both have the pointer tables in the same place
tiletable = 0x3995
infotable = (0x39, 0x706a)
terminator = 0x3d95  # The final address of the table, and also what's used to specify an empty entry

default_version = roms[0][1]
nametable = OrderedDict()
namefile = None
realptr_key_map = {}

# Map real address to a defined name

if os.path.exists(meta_tileset_names_file):
    nametable = utils.read_table(meta_tileset_names_file)
else:
    namefile = open(meta_tileset_names_file, "w")

# M3 keeps source addresses in a table in bank 0 and banks + destination info in a separate table
# This is pretty much a single table that's been split over 2 banks, and there may be duplicate tileset entries
count = ((terminator - tiletable) // 2)
terminator_key = utils.rom2realaddr((0, terminator))
nametable[terminator] = "TilesetSourceAddressTableEnd"

tileset_data = OrderedDict()
tileset_metadata = {}

common_tilesets = []
unique_pointer_and_tilesets = []
unique_tilesets = []
Beispiel #7
0
#!/bin/python

import os, sys
from shutil import copyfile

sys.path.append(os.path.join(os.path.dirname(__file__), 'common'))
from common import utils, tilemaps

if __name__ == '__main__':
    input_file = sys.argv[1]
    output_file = sys.argv[2]

    fname = os.path.splitext(os.path.basename(input_file))[0]
    char_table = utils.merge_dicts([
        utils.read_table(tbl, reverse=True) for tbl in filter(
            None,
            utils.read_table("scripts/res/tilemap_tilesets.tbl",
                             keystring=True)[fname].split(","))
    ])

    # 0xFE is a special character indicating a new line for tilemaps, it doesn't really belong in the tileset table but for this specifically it makes sense
    char_table['\n'] = 0xFE

    prebuilt = "game/tilemaps/{}.tmap".format(fname)
    if os.path.isfile(prebuilt):
        print("\tUsing prebuilt {}".format(prebuilt))
        copyfile(prebuilt, output_file)
        os.utime(output_file, None)
        quit()

    with open(input_file, 'r', encoding='utf-8-sig') as f:
Beispiel #8
0
sys.path.append(os.path.join(os.path.dirname(__file__), 'common'))
from common import utils

list_map = ({
    # 'Type' : (Start of Pointers, Terminator, Number of Items, Prefix Length)
    'PartTypes': ((0x1, 0x750b), 0x50, 4, 0),
    'Attributes': ((0x2, 0x7f03), 0x50, 28, 0),
    'PartDescriptions': (0x7F234, 0x50, 50, 0),
    'Skills': ((0x2, 0x7fc0), 0x50, 8, 0),
    'Attacks': ((0x17, 0x76d2), 0x50, 19, 0),
    # Medarotters have a 3-byte prefix before the names
    'Medarotters': ((0x17, 0x64e6), 0x50, 85, 3),
})

tileset = utils.merge_dicts([
    utils.read_table("scripts/res/tileset_MainDialog.tbl"),
    utils.read_table("scripts/res/tileset_MainSpecial.tbl"),
    utils.read_table("scripts/res/dakuten.tbl")
])
with open("baserom_kabuto.gb", "rb") as rom:
    for l in list_map:
        addr, term, n, prefixlen = list_map[l]
        if isinstance(addr, tuple):
            bank = addr[0]
            addr = utils.rom2realaddr(addr)
        else:
            bank = utils.real2romaddr(addr)[0]
        rom.seek(addr)
        with open('text/ptrlists/{}.txt'.format(l), 'w',
                  encoding="utf-8") as output:
            output.write("{}\n".format(term))
import os, sys
sys.path.append(os.path.join(os.path.dirname(__file__), 'common'))
from common import utils

table = utils.read_table("scripts/res/tilemap_files.tbl")
with open(sys.argv[1], "w") as tf:
    tf.write("; auto-generated by {}\n".format(sys.argv[0]))
    tilemap_files = []
    # Pointer table
    for i in table:
        tmap_name = os.path.splitext(os.path.basename(table[i]))[0]
        tf.write("dw {} ; Tilemap 0x{:02X}\n".format(tmap_name, i))
        if tmap_name not in tilemap_files:
            tilemap_files.append(tmap_name)
    tf.write("\n")
    for file in tilemap_files:
        tf.write('{0}:\n  INCBIN "build/tilemaps/{0}.tmap"\n'.format(file))
Beispiel #10
0
class NotPointerException(ValueError): pass

def readpointer(rom, bank):
    s = readshort(rom)
    if 0x4000 > s or 0x8000 <= s:
        raise NotPointerException(s)
    return (bank * 0x4000) + (s - 0x4000)

def readshort(rom):
    return readbyte(rom) + (readbyte(rom) << 8)

def readbyte(rom):
    return ord(rom.read(1))

table = utils.read_table("scripts/res/medarot.tbl")

class Special():
    def __init__(self, symbol, default=0, bts=1, end=False, names=None):
        self.symbol = symbol
        self.default = default
        self.bts = bts
        self.end = end
        self.names = names

table[0x4b] = Special("&", bts=2, names=name_table)
table[0x4d] = Special('S', default=-1)
table[0x4f] = Special('*', end=True)
table[0x50] = Special('`', bts=0, end=True)

import os, sys
sys.path.append(os.path.join(os.path.dirname(__file__), 'common'))
from common import utils, tilesets

script_name = sys.argv[0]
output_file = sys.argv[1]
res_file = sys.argv[2]

table = utils.read_table(res_file)
with open(output_file, "w") as tf:
    tf.write(f"; auto-generated by {script_name}\n")
    tilemap_files = []
    # Pointer table
    for i in table:
        if not table[i]:
            tf.write("dw TILEMAPS_END ; NULL\n")
            continue
        tmap_name = os.path.splitext(os.path.basename(table[i]))[0]
        tf.write(f"dw {tmap_name} ; Tilemap 0x{i:02X}\n")
        if tmap_name not in tilemap_files:
            tilemap_files.append(tmap_name)
    tf.write("\n")
    for file in tilemap_files:
        tf.write(f'{file}:\n  INCBIN "build/tilemaps/{file}.tmap"\n')
    tf.write("TILEMAPS_END::")
Beispiel #12
0
    while rom.tell() < end:  # The first tilemap is where the table should end
        tilemap_ptr[i] = utils.read_short(rom)
        i += 1
    TERMINATOR = tilemap_ptr[
        i -
        1]  # A bit of a hack, but the last pointer is effectively a 'null', even though there's a list entry pointing to it

    ptrfile = None
    ptrtable = {}

    tileset_file = None
    tileset_table = {}
    tiletables = {}

    if os.path.exists("scripts/res/meta_tilemap_files.tbl"):
        ptrtable = utils.read_table("scripts/res/meta_tilemap_files.tbl")
    else:
        ptrfile = open("scripts/res/meta_tilemap_files.tbl", "w")

    # Load previously generated/manually written tilemap <-> tileset mapping
    tileset_default = utils.merge_dicts([
        tilesets.get_tileset("MainDialog"),
        tilesets.get_tileset("MainSpecial"),
    ])
    tileset_default[
        0xFE] = '\n'  # 0xFE is a special control code for a new line, not really a tile

    if os.path.exists("scripts/res/meta_tilemap_tilesets.tbl"):
        tileset_table = utils.read_table(
            "scripts/res/meta_tilemap_tilesets.tbl", keystring=True)
        for fname in tileset_table:
Beispiel #13
0
# tilemap bank is 1e (0x78000)
BANK_SIZE = 0x4000
BASE_ADDR = 0x78000
MAX_ADDR = BASE_ADDR + BANK_SIZE - 1

tilemap_ptr = {}
tilemap_bytes = {}
tilemap_files = []
with open("baserom_kabuto.gb", "rb") as rom:
    rom.seek(BASE_ADDR)
    for i in range(0xf0):
        tilemap_ptr[i] = utils.read_short(rom)

    ptrfile = None
    if os.path.exists("scripts/res/tilemap_files.tbl"):
        ptrtable = utils.read_table("scripts/res/tilemap_files.tbl")
    else:
        ptrfile = open("scripts/res/tilemap_files.tbl","w")

    # Load previously generated/manually written tilemap <-> tileset mapping
    tileset_file = None
    tilesets = {}
    tiletables = {}
    tileset_default = utils.read_table("scripts/res/tileset_MainDialog.tbl")
    if os.path.exists("scripts/res/tilemap_tilesets.tbl"):
        tilesets = utils.read_table("scripts/res/tilemap_tilesets.tbl", keystring=True)
        for fname in tilesets:
            if tilesets[fname] not in tiletables:
                tiletables[tilesets[fname]] = utils.merge_dicts([utils.read_table(tbl) for tbl in filter(None, tilesets[fname].split(","))])
                tiletables[tilesets[fname]][0xFE] = '\n' # 0xFE is a special control code for a new line, not really a tile
    else:
Beispiel #14
0
# Those tables each point to the actual tilemap data
map_bank_table = int(sys.argv[7], 16)
map_addr_table = int(sys.argv[8], 16)
map_table_count = int(sys.argv[9], 16)

meta_tilemap_names_file = os.path.join(scripts_res_path,
                                       f"meta_{map_label}_files.tbl")

roms = ([("baserom_kabuto.gbc", "kabuto"),
         ("baserom_kuwagata.gbc", "kuwagata")])

# Map real address to a defined name
nametable = {}
namefile = None
if os.path.exists(meta_tilemap_names_file):
    nametable = utils.read_table(meta_tilemap_names_file, keystring=True)
else:
    namefile = open(meta_tilemap_names_file, "w")

default_version = roms[0]
tilemap_tables = None

try:
    with open(default_version[0], "rb") as rom:
        rom.seek(map_bank_table)
        tilemap_banks = [
            utils.read_byte(rom) for i in range(0, map_table_count)
        ]
        rom.seek(map_addr_table)
        tilemap_addrs = [
            utils.read_short(rom) for i in range(0, map_table_count)