2017-03-11 19:18:33 +10:30
|
|
|
#!python3 -i
|
|
|
|
'''
|
|
|
|
No license for now
|
|
|
|
'''
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import os
|
2017-03-18 13:52:33 +10:30
|
|
|
from struct import unpack
|
2017-03-17 16:56:19 +10:30
|
|
|
from itertools import chain
|
2017-03-11 19:18:33 +10:30
|
|
|
from array import array
|
2017-03-18 14:50:29 +10:30
|
|
|
from snestile import generate_glyphs, generate_glyphs_large, generate_palette, create_tile
|
2017-03-13 23:20:19 +10:30
|
|
|
import const
|
|
|
|
import time
|
2017-03-11 19:18:33 +10:30
|
|
|
|
|
|
|
pyqt_version = 0
|
2017-03-13 23:20:19 +10:30
|
|
|
skip_pyqt5 = "PYQT4" in os.environ
|
2017-03-17 16:56:19 +10:30
|
|
|
filename_en = "Final Fantasy V (Japan) [En by RPGe v1.1].sfc"
|
|
|
|
filename_jp = "Final Fantasy V (Japan).sfc"
|
2017-03-11 19:18:33 +10:30
|
|
|
|
|
|
|
if not skip_pyqt5:
|
|
|
|
try:
|
|
|
|
from PyQt5 import QtGui, QtCore
|
2017-03-12 00:14:37 +10:30
|
|
|
from PyQt5.QtGui import QIcon, QPalette, QColor, QFont, QFontInfo, QImage, QPixmap
|
2017-03-11 19:18:33 +10:30
|
|
|
from PyQt5.QtWidgets import (
|
|
|
|
QApplication, QMainWindow, QFormLayout,
|
|
|
|
QGridLayout, QHBoxLayout, QVBoxLayout,
|
|
|
|
QAbstractItemView, QHeaderView, QListWidget,
|
|
|
|
QListWidgetItem, QTabWidget, QTableWidget,
|
|
|
|
QTableWidgetItem, QFrame, QScrollArea,
|
|
|
|
QStackedWidget, QWidget, QCheckBox, QComboBox,
|
|
|
|
QDoubleSpinBox, QGroupBox, QLineEdit,
|
|
|
|
QPushButton, QRadioButton, QSpinBox,
|
|
|
|
QStyleOptionButton, QToolButton, QProgressBar,
|
|
|
|
QDialog, QColorDialog, QDialogButtonBox,
|
|
|
|
QFileDialog, QInputDialog, QMessageBox,
|
|
|
|
QAction, QActionGroup, QLabel, QMenu, QStyle,
|
|
|
|
QSystemTrayIcon, QStyleOptionProgressBar
|
|
|
|
)
|
|
|
|
pyqt_version = 5
|
|
|
|
except ImportError:
|
|
|
|
print("Couldn't import Qt5 dependencies. "
|
|
|
|
"Make sure you installed the PyQt5 package.")
|
2017-03-13 23:20:19 +10:30
|
|
|
if pyqt_version == 0:
|
2017-03-11 19:18:33 +10:30
|
|
|
try:
|
|
|
|
import sip
|
|
|
|
sip.setapi('QVariant', 2)
|
|
|
|
from PyQt4 import QtGui, QtCore
|
|
|
|
from PyQt4.QtGui import (
|
|
|
|
QApplication, QMainWindow, QFormLayout,
|
|
|
|
QGridLayout, QHBoxLayout, QVBoxLayout,
|
|
|
|
QAbstractItemView, QHeaderView, QListWidget,
|
|
|
|
QListWidgetItem, QTabWidget, QTableWidget,
|
|
|
|
QTableWidgetItem, QFrame, QScrollArea,
|
|
|
|
QStackedWidget, QWidget, QCheckBox,
|
|
|
|
QComboBox, QDoubleSpinBox, QGroupBox,
|
|
|
|
QLineEdit, QPushButton, QRadioButton,
|
|
|
|
QSpinBox, QStyleOptionButton, QToolButton,
|
|
|
|
QProgressBar, QDialog, QColorDialog,
|
|
|
|
QDialogButtonBox, QFileDialog, QInputDialog,
|
|
|
|
QMessageBox, QAction, QActionGroup,
|
|
|
|
QLabel, QMenu, QStyle,
|
|
|
|
QSystemTrayIcon, QIcon, QPalette, QColor,
|
2017-03-12 00:14:37 +10:30
|
|
|
QValidator, QFont, QFontInfo, QImage, QPixmap
|
2017-03-11 19:18:33 +10:30
|
|
|
)
|
|
|
|
from PyQt4.QtGui import QStyleOptionProgressBarV2 as QStyleOptionProgressBar
|
|
|
|
pyqt_version = 4
|
|
|
|
except ImportError:
|
|
|
|
print("Couldn't import Qt dependencies. "
|
|
|
|
"Make sure you installed the PyQt4 package.")
|
|
|
|
sys.exit(-1)
|
|
|
|
|
2017-03-18 13:52:33 +10:30
|
|
|
bg_color = QColor(0, 0, 128)
|
2017-03-18 18:34:55 +10:30
|
|
|
bg_trans = QColor(0, 0, 0, 0)
|
2017-03-18 13:52:33 +10:30
|
|
|
|
2017-03-12 00:14:37 +10:30
|
|
|
monofont = QFont()
|
|
|
|
monofont.setStyleHint(QFont.Monospace)
|
|
|
|
if not monofont.fixedPitch():
|
|
|
|
monofont.setStyleHint(QFont.TypeWriter)
|
|
|
|
if not monofont.fixedPitch():
|
|
|
|
monofont.setFamily("Monospace")
|
2017-03-11 19:18:33 +10:30
|
|
|
|
|
|
|
def divceil(numerator, denominator):
|
|
|
|
# Reverse floor division for ceil
|
|
|
|
return -(-numerator // denominator)
|
|
|
|
|
|
|
|
def hex_length(i):
|
|
|
|
return divceil(i.bit_length(), 4)
|
|
|
|
|
2017-03-17 16:56:19 +10:30
|
|
|
with open(filename_en, 'rb') as file1:
|
|
|
|
ROM_en = file1.read()
|
|
|
|
print(len(ROM_en), filename_en)
|
|
|
|
with open(filename_jp, 'rb') as file2:
|
|
|
|
ROM_jp = file2.read()
|
|
|
|
print(len(ROM_jp), filename_jp)
|
2017-03-12 00:14:37 +10:30
|
|
|
|
2017-03-11 19:18:33 +10:30
|
|
|
stringlist_headers = ["Address", "ID", "Name"]
|
2017-03-13 11:51:18 +10:30
|
|
|
imglist_headers = stringlist_headers + ["Img", "Name JP", "Img JP"]
|
2017-03-11 19:18:33 +10:30
|
|
|
|
|
|
|
|
|
|
|
class FF5Reader(QMainWindow):
|
|
|
|
"""
|
|
|
|
Main GUI class
|
|
|
|
"""
|
|
|
|
def __init__(self):
|
|
|
|
QMainWindow.__init__(self, None)
|
2017-03-17 16:56:19 +10:30
|
|
|
global glyph_sprites_en_large, glyph_sprites_en_small, glyph_sprites_jp_small, glyph_sprites_jp_large, glyph_sprites_kanji, glyph_sprites_jp_dialogue
|
|
|
|
glyph_sprites_en_small = generate_glyphs(ROM_en, 0x11F000)
|
|
|
|
glyph_sprites_en_large = generate_glyphs_large(ROM_en, 0x03E800)
|
|
|
|
glyph_sprites_jp_small = generate_glyphs(ROM_jp, 0x11F000)
|
|
|
|
glyph_sprites_jp_large = generate_glyphs_large(ROM_jp, 0x03E800)
|
|
|
|
glyph_sprites_kanji = generate_glyphs_large(ROM_jp, 0x1BD000, 0x1AA) # Kanji are unchanged in EN version
|
2017-04-02 14:37:53 +09:30
|
|
|
|
2017-03-13 16:02:36 +10:30
|
|
|
global zone_names
|
2017-03-13 21:08:49 +10:30
|
|
|
zone_names = make_string_img_list(0x107000, 2, 0x100, start_str=0x270000, start_jp_str=0x107200, indirect=True, large=True)
|
2017-03-13 16:02:36 +10:30
|
|
|
items = make_string_img_list(0x111380, 9, 256)
|
|
|
|
magics = make_string_img_list(0x111C80, 6, 87)
|
|
|
|
more_magics = make_string_img_list(0x111E8A, 9, 73)
|
|
|
|
enemy_names = make_string_img_list(0x200050, 10, 0x180, 0x105C00, 8)
|
2017-07-23 01:40:44 +09:30
|
|
|
character_names = make_string_img_list(0x115500, 6, 5)
|
2017-03-18 13:52:33 +10:30
|
|
|
job_names = make_string_img_list(0x115600, 8, 22)
|
2017-04-02 14:37:53 +09:30
|
|
|
ability_names = make_string_img_list(0x116200, 8, 33)
|
|
|
|
battle_commands = make_string_img_list(0x201150, 7, 0x60, 0x115800, 5)
|
2017-03-17 16:56:19 +10:30
|
|
|
dialogue = make_string_img_list(0x2013F0, 3, 0x900, start_jp=0x082220, len_jp=2, start_str=0x0, start_jp_str=0x0A0000, indirect=True, large=True, macros_en=const.Dialogue_Macros_EN, macros_jp=const.Dialogue_Macros_JP)
|
|
|
|
|
2017-03-13 16:02:36 +10:30
|
|
|
zone_structure = [("NPC Layer", 2, None),
|
2017-03-17 22:16:52 +10:30
|
|
|
("Name", 1, [z[2] for z in zone_names]),
|
2017-03-13 16:02:36 +10:30
|
|
|
("ShadowFlags", 1, None),
|
|
|
|
("0x04", 1, None),
|
|
|
|
("0x05", 1, None),
|
|
|
|
("Flags 0x06", 1, None),
|
|
|
|
("0x07", 1, None),
|
|
|
|
("Tileset", 1, None),
|
|
|
|
("Tileset2", 2, None),
|
|
|
|
#("0x0A", 1, None),
|
|
|
|
("0x0B", 1, None),
|
|
|
|
("Collision Layer",1, None),
|
|
|
|
("0x0D", 1, None),
|
|
|
|
("0x0E", 1, None),
|
|
|
|
("0x0F", 1, None),
|
|
|
|
("0x10", 1, None),
|
|
|
|
("0x11", 1, None),
|
|
|
|
("0x12", 1, None),
|
|
|
|
("0x13", 1, None),
|
|
|
|
("0x14", 1, None),
|
|
|
|
("0x15", 1, None),
|
|
|
|
("Palette", 1, None),
|
|
|
|
("0x17", 1, None),
|
|
|
|
("0x18", 1, None),
|
2017-03-13 23:20:19 +10:30
|
|
|
("Music", 1, const.BGM_Tracks)]
|
2017-03-13 16:02:36 +10:30
|
|
|
zone_headers = ["Address"] + [z[0] for z in zone_structure]
|
|
|
|
|
|
|
|
zone_data = []
|
2017-03-17 16:56:19 +10:30
|
|
|
for i in range(const.zone_count):
|
2017-03-13 16:02:36 +10:30
|
|
|
offset = 0x0E9C00 + (i*0x1A)
|
2017-03-18 23:22:27 +10:30
|
|
|
zone_data.append(parse_struct(ROM_en, offset, zone_structure))
|
2017-03-13 16:02:36 +10:30
|
|
|
|
2017-03-17 22:16:52 +10:30
|
|
|
tileset_headers = ("ID", "Offset", "Pointer", "Expected Length")
|
|
|
|
tileset_data = []
|
|
|
|
for i in range(0x1C):
|
|
|
|
offset = 0x0F0000 + (i*2)
|
|
|
|
pointer = 0x0F0000 + int.from_bytes(ROM_en[offset:offset+2],'little')
|
|
|
|
length = int.from_bytes(ROM_en[offset+2:offset+4],'little') - int.from_bytes(ROM_en[offset:offset+2],'little')
|
|
|
|
tileset_data.append(('0x{:02X}'.format(i), '0x{:06X}'.format(offset),
|
|
|
|
'0x{:06X}'.format(pointer), '0x{:04X}'.format(length)))
|
|
|
|
|
2017-03-13 16:02:36 +10:30
|
|
|
npc_layers = []
|
2017-03-18 23:22:27 +10:30
|
|
|
offset = 0x0E59C0
|
2017-03-17 16:56:19 +10:30
|
|
|
for layer in range(const.npc_layer_count):
|
2017-03-13 16:02:36 +10:30
|
|
|
i = offset + (layer*2)
|
2017-03-17 16:56:19 +10:30
|
|
|
start = int.from_bytes(ROM_en[i:i+2],'little') + offset
|
|
|
|
next = int.from_bytes(ROM_en[i+2:i+4],'little') + offset
|
2017-03-13 16:02:36 +10:30
|
|
|
npcs = (next - start) // 7
|
|
|
|
for npc in range(npcs):
|
|
|
|
address = start + (npc*7)
|
2017-03-18 23:22:27 +10:30
|
|
|
npc_layers.append(["0x{0:06X}".format(i), "0x{0:03X}".format(layer)] + parse_struct(ROM_en, address, const.npc_layer_structure))
|
|
|
|
|
|
|
|
enemy_tile_layouts = []
|
|
|
|
address = 0x10D004
|
|
|
|
for i in range(0x66):
|
|
|
|
offset = address + (i*8)
|
|
|
|
img = QImage(8, 8, QImage.Format_Mono)
|
|
|
|
img.setColorTable(const.mono_palette)
|
|
|
|
for i in range(8):
|
|
|
|
ptr = img.scanLine(i)
|
|
|
|
ptr.setsize(32)
|
|
|
|
ptr[0:1] = ROM_en[offset+i:offset+i+1]
|
|
|
|
pixmap = QPixmap.fromImage(img)
|
|
|
|
enemy_tile_layouts.append(pixmap.scaled(16, 16))
|
|
|
|
|
|
|
|
enemy_sprite_data = []
|
|
|
|
enemy_sprite_structure = [
|
|
|
|
("Sprite data offset", 2, None),
|
|
|
|
("Multiple things", 2, None),
|
|
|
|
("Tile Layout ID", 1, enemy_tile_layouts)
|
|
|
|
]
|
|
|
|
enemy_sprite_headers = ["Address"]+[i[0] for i in enemy_sprite_structure]+["EN Name","EN Name"]
|
|
|
|
address = 0x14B180
|
|
|
|
for i in range(0x180):
|
|
|
|
enemy_sprite_data.append(parse_struct(ROM_en, address + (i*5), enemy_sprite_structure) + enemy_names[i][2:4])
|
2017-03-12 00:14:37 +10:30
|
|
|
|
2017-03-18 15:12:19 +10:30
|
|
|
self.battle_strips = make_character_battle_sprites(ROM_en)
|
2017-03-18 18:34:55 +10:30
|
|
|
status_strips = make_character_status_sprites(ROM_en)
|
2017-03-18 23:22:27 +10:30
|
|
|
enemy_sprites = make_enemy_sprites(ROM_en)
|
2017-03-18 14:50:29 +10:30
|
|
|
|
2017-03-11 19:18:33 +10:30
|
|
|
self.tabwidget = QTabWidget()
|
2017-03-18 13:52:33 +10:30
|
|
|
strings_tab = QTabWidget()
|
|
|
|
structs_tab = QTabWidget()
|
|
|
|
sprites_tab = QTabWidget()
|
|
|
|
self.tabwidget.addTab(strings_tab, "Strings")
|
|
|
|
self.tabwidget.addTab(structs_tab, "Structs")
|
|
|
|
self.tabwidget.addTab(sprites_tab, "Images")
|
|
|
|
|
2017-03-18 14:50:29 +10:30
|
|
|
sprites_tab.addTab(make_pixmap_table(glyph_sprites_en_small, scale=4), "Glyphs (EN)")
|
|
|
|
sprites_tab.addTab(make_pixmap_table(glyph_sprites_en_large, scale=2), "Glyphs (Dialogue EN)")
|
|
|
|
sprites_tab.addTab(make_pixmap_table(glyph_sprites_jp_small, scale=4), "Glyphs (JP)")
|
|
|
|
sprites_tab.addTab(make_pixmap_table(glyph_sprites_jp_large, scale=2), "Glyphs (Large JP)")
|
|
|
|
sprites_tab.addTab(make_pixmap_table(glyph_sprites_kanji, scale=2), "Glyphs (Kanji)")
|
2017-03-18 18:34:55 +10:30
|
|
|
sprites_tab.addTab(make_pixmap_table(self.battle_strips, cols=22, scale=2), "Character Battle Sprites")
|
|
|
|
sprites_tab.addTab(make_pixmap_table(status_strips, cols=22, scale=2), "Status Sprites")
|
2017-03-18 23:22:27 +10:30
|
|
|
sprites_tab.addTab(make_pixmap_table(enemy_sprites, scale=1), "Enemy Sprites")
|
2017-03-18 13:52:33 +10:30
|
|
|
|
|
|
|
structs_tab.addTab(make_table(zone_headers, zone_data, True), "Zones")
|
|
|
|
structs_tab.addTab(make_table(tileset_headers, tileset_data, True), "Tilesets")
|
|
|
|
structs_tab.addTab(make_table(const.npc_layer_headers, npc_layers, True), "NPC Layers")
|
2017-03-18 23:22:27 +10:30
|
|
|
structs_tab.addTab(make_table(enemy_sprite_headers, enemy_sprite_data, True), "Enemy Sprites")
|
2017-03-18 13:52:33 +10:30
|
|
|
|
|
|
|
strings_tab.addTab(make_table(imglist_headers, items, row_labels=False), "Items")
|
|
|
|
strings_tab.addTab(make_table(imglist_headers, magics, row_labels=False), "Magics")
|
|
|
|
strings_tab.addTab(make_table(imglist_headers, more_magics, row_labels=False), "More Magics")
|
|
|
|
strings_tab.addTab(make_table(imglist_headers, enemy_names, row_labels=False), "Enemy Names")
|
2017-07-23 01:40:44 +09:30
|
|
|
strings_tab.addTab(make_table(imglist_headers, character_names, row_labels=False), "Character Names")
|
2017-03-18 13:52:33 +10:30
|
|
|
strings_tab.addTab(make_table(imglist_headers, job_names, row_labels=False), "Job Names")
|
2017-04-02 14:37:53 +09:30
|
|
|
strings_tab.addTab(make_table(imglist_headers, ability_names, row_labels=False), "Ability Names")
|
|
|
|
strings_tab.addTab(make_table(imglist_headers, battle_commands, row_labels=False), "Battle Commands")
|
2017-03-18 13:52:33 +10:30
|
|
|
strings_tab.addTab(make_table(imglist_headers, zone_names, True, scale=1), "Zone Names")
|
|
|
|
strings_tab.addTab(make_table(imglist_headers+['JP address'], dialogue, scale=1), "Dialogue")
|
2017-03-11 19:18:33 +10:30
|
|
|
|
2017-04-02 14:37:53 +09:30
|
|
|
self.string_decoder = QWidget()
|
|
|
|
self.decoder_input = QLineEdit()
|
|
|
|
self.decoder_input.returnPressed.connect(self._string_decode)
|
|
|
|
self.decoder_layout = QVBoxLayout()
|
|
|
|
self.decoder_layout.addWidget(self.decoder_input)
|
|
|
|
self.string_decoder.setLayout(self.decoder_layout)
|
|
|
|
strings_tab.addTab(self.string_decoder, "String Decoder")
|
|
|
|
|
2017-03-11 19:18:33 +10:30
|
|
|
layout = QHBoxLayout()
|
|
|
|
layout.addWidget(self.tabwidget)
|
|
|
|
self.main_widget = QWidget(self)
|
|
|
|
self.main_widget.setLayout(layout)
|
2017-04-02 14:37:53 +09:30
|
|
|
self.main_widget.setMinimumSize(800,600)
|
2017-03-11 19:18:33 +10:30
|
|
|
self.setCentralWidget(self.main_widget)
|
|
|
|
self.show()
|
|
|
|
|
2017-04-02 14:37:53 +09:30
|
|
|
def _string_decode(self):
|
|
|
|
string = ''.join(self.decoder_input.text().split())
|
|
|
|
if len(string) % 1:
|
|
|
|
string += '0'
|
|
|
|
bytelist = [int(string[i:i+2], 16) for i in range(0, len(string), 2)]
|
|
|
|
tups = make_string_img_small(bytes(bytelist))
|
|
|
|
print(tups[0])
|
|
|
|
img = QLabel()
|
|
|
|
img.setPixmap(tups[1])
|
|
|
|
self.decoder_layout.addWidget(img)
|
|
|
|
self.decoder_input.setText('')
|
|
|
|
|
2017-03-18 18:34:55 +10:30
|
|
|
|
|
|
|
class Canvas:
|
|
|
|
def __init__(self, rows, columns, color=bg_trans):
|
|
|
|
self.image = QImage(8*rows, 8*columns, QImage.Format_ARGB32_Premultiplied)
|
|
|
|
self.image.fill(color)
|
|
|
|
self.painter = QtGui.QPainter(self.image)
|
2017-04-02 14:37:53 +09:30
|
|
|
self.max_x = 1
|
|
|
|
self.max_y = 1
|
2017-03-18 18:34:55 +10:30
|
|
|
|
|
|
|
def __del__(self):
|
|
|
|
del self.painter
|
|
|
|
|
|
|
|
def draw_pixmap(self, row, column, pixmap):
|
|
|
|
self.painter.drawPixmap(row*8, column*8, pixmap)
|
2017-04-02 14:37:53 +09:30
|
|
|
if row > self.max_x:
|
|
|
|
self.max_x = row
|
|
|
|
if column > self.max_y:
|
|
|
|
self.max_y = column
|
|
|
|
|
|
|
|
def pixmap(self, trim=False):
|
|
|
|
if trim:
|
|
|
|
return QPixmap.fromImage(self.image.copy(0, 0, self.max_x*8+8, self.max_y*8+8))
|
2017-03-18 18:34:55 +10:30
|
|
|
return QPixmap.fromImage(self.image)
|
|
|
|
|
2017-07-23 18:29:22 +09:30
|
|
|
|
2017-03-18 23:22:27 +10:30
|
|
|
def parse_struct(rom, offset, structure):
|
|
|
|
out = ["0x{:06X}".format(offset)]
|
|
|
|
j = 0
|
|
|
|
for z in structure:
|
|
|
|
val = int.from_bytes(rom[offset+j:offset+j+z[1]],'little')
|
|
|
|
if z[2] and val < len(z[2]):
|
|
|
|
out.append(z[2][val])
|
|
|
|
else:
|
|
|
|
out.append("0x{:0{}X}".format(val, z[1]*2))
|
|
|
|
j += z[1]
|
|
|
|
return out
|
|
|
|
|
2017-07-23 18:29:22 +09:30
|
|
|
|
2017-03-18 23:22:27 +10:30
|
|
|
def make_enemy_sprites(rom):
|
|
|
|
sprites = []
|
|
|
|
for e_id in range(0, 0x180*5, 5):
|
|
|
|
triplane = bool(rom[0x14B180+e_id]&0x80) # True if 3 planes, False if 4
|
|
|
|
bytes_per_tile = 24 if triplane else 32
|
|
|
|
tile_offset = ((((rom[0x14B180+e_id]&0x7F)<<8)| rom[0x14B181+e_id]) << 3) + 0x150000 # For whatever reason this is big endian
|
|
|
|
pal_offset = ((((rom[0x14B182+e_id]&0x03)<<8)| rom[0x14B183+e_id]) << 4) + 0x0ED000 # For whatever reason this is big endian
|
|
|
|
pal_size = 16 if triplane else 32
|
|
|
|
palette = generate_palette(rom, pal_offset, pal_size)
|
2017-04-02 14:37:53 +09:30
|
|
|
palette[0] = 0
|
2017-03-18 23:22:27 +10:30
|
|
|
layout_id = rom[0x14B184+e_id]
|
|
|
|
boss_layout = bool(rom[0x14B182+e_id]&0x80)
|
|
|
|
if boss_layout:
|
|
|
|
layout = rom[0x10D334+(layout_id<<5):0x10D334+(layout_id<<5)+32]
|
|
|
|
sprite = Canvas(16, 16)
|
|
|
|
for x, y in [(x,y) for y in range(16) for x in range(16)]:
|
|
|
|
if (int.from_bytes(layout[y*2:y*2+2], 'little') & (0x8000 >> x)):
|
|
|
|
sprite.draw_pixmap(x, y, create_tile(rom[tile_offset:tile_offset+bytes_per_tile], palette))
|
|
|
|
tile_offset += bytes_per_tile
|
|
|
|
else:
|
|
|
|
layout = rom[0x10D004+(layout_id<<3):0x10D004+(layout_id<<3)+8]
|
|
|
|
sprite = Canvas(8, 8)
|
|
|
|
for x, y in [(x,y) for y in range(8) for x in range(8)]:
|
|
|
|
if (layout[y] & (0x80 >> x)):
|
|
|
|
sprite.draw_pixmap(x, y, create_tile(rom[tile_offset:tile_offset+bytes_per_tile], palette))
|
|
|
|
tile_offset += bytes_per_tile
|
|
|
|
|
|
|
|
# TODO: Shadow stuff
|
2017-04-02 14:37:53 +09:30
|
|
|
sprites.append(sprite.pixmap(True))
|
2017-03-18 23:22:27 +10:30
|
|
|
return sprites
|
|
|
|
|
2017-07-23 18:29:22 +09:30
|
|
|
|
2017-03-18 14:50:29 +10:30
|
|
|
def make_character_battle_sprites(rom):
|
|
|
|
tile_address = 0x120000
|
|
|
|
palette_address = 0x14A3C0
|
|
|
|
battle_strips = []
|
2017-03-18 15:12:19 +10:30
|
|
|
for i in range(0, 110*32, 32):
|
|
|
|
palette = generate_palette(rom, palette_address + i)
|
|
|
|
# We don't want the background drawn, so we'll make that colour transparent
|
|
|
|
palette[0] = 0
|
2017-03-18 23:22:27 +10:30
|
|
|
battle_strip = Canvas(2, 24)
|
|
|
|
for j in range(48):
|
|
|
|
offset = tile_address+(i*48)+(j*32)
|
|
|
|
battle_strip.draw_pixmap(j%2, j//2, create_tile(rom[offset:offset+32], palette))
|
|
|
|
battle_strips.append(battle_strip.pixmap())
|
2017-03-18 14:50:29 +10:30
|
|
|
return battle_strips
|
2017-03-11 19:18:33 +10:30
|
|
|
|
2017-07-23 18:29:22 +09:30
|
|
|
|
2017-03-18 18:34:55 +10:30
|
|
|
def make_character_status_sprites(rom):
|
|
|
|
tile_address = 0x149400
|
|
|
|
palette_address = 0x14A660
|
|
|
|
pixmaps = []
|
|
|
|
for i in range(5):
|
|
|
|
palette = generate_palette(rom, palette_address + (i*22*32)) # Freelance palette per character
|
|
|
|
# We don't want the background drawn, so we'll make that colour transparent
|
|
|
|
palette[0] = 0
|
|
|
|
wounded = Canvas(3, 2)
|
|
|
|
for j in range(6):
|
|
|
|
offset = tile_address+(i*192)+(j*32)
|
|
|
|
wounded.draw_pixmap(j%3, j//3, create_tile(rom[offset:offset+32], palette))
|
|
|
|
pixmaps.append(wounded.pixmap())
|
|
|
|
mini_strip = Canvas(2, 19)
|
|
|
|
for j in range(38):
|
|
|
|
offset = tile_address+0x3C0+(j*24)
|
|
|
|
mini_strip.draw_pixmap(j%2, j//2, create_tile(rom[offset:offset+24], palette))
|
|
|
|
pixmaps.append(mini_strip.pixmap())
|
|
|
|
frog_strip = Canvas(2, 15)
|
|
|
|
for j in range(30):
|
|
|
|
offset = tile_address+0x750+(j*24)
|
|
|
|
frog_strip.draw_pixmap(j%2, j//2, create_tile(rom[offset:offset+24], palette))
|
|
|
|
pixmaps.append(frog_strip.pixmap())
|
|
|
|
return pixmaps
|
|
|
|
|
2017-07-23 18:29:22 +09:30
|
|
|
|
2017-03-17 16:56:19 +10:30
|
|
|
def make_string_img_small(bytestring, jp=False):
|
2017-03-13 16:02:36 +10:30
|
|
|
if len(bytestring) < 1:
|
|
|
|
raise ValueError('Empty bytestring was passed')
|
|
|
|
string = ""
|
|
|
|
img = QImage(len(bytestring)*8, 10, QImage.Format_RGB16)
|
|
|
|
img.fill(bg_color)
|
|
|
|
painter = QtGui.QPainter(img)
|
|
|
|
if jp:
|
|
|
|
for x, j in enumerate(bytestring):
|
2017-03-13 23:20:19 +10:30
|
|
|
string = string + const.Glyphs_JP2[j]
|
2017-03-13 16:02:36 +10:30
|
|
|
if 0x20 <= j < 0x52:
|
|
|
|
if j > 0x48:
|
2017-03-17 16:56:19 +10:30
|
|
|
painter.drawPixmap(x*8, 2, glyph_sprites_jp_small[j+0x17])
|
|
|
|
painter.drawPixmap(x*8+1,-5, glyph_sprites_jp_small[0x52])
|
2017-03-13 16:02:36 +10:30
|
|
|
else:
|
2017-03-17 16:56:19 +10:30
|
|
|
painter.drawPixmap(x*8, 2, glyph_sprites_jp_small[j+0x40])
|
|
|
|
painter.drawPixmap(x*8+1,-6, glyph_sprites_jp_small[0x51])
|
2017-03-13 16:02:36 +10:30
|
|
|
else:
|
2017-03-17 16:56:19 +10:30
|
|
|
painter.drawPixmap(x*8, 2, glyph_sprites_jp_small[j])
|
2017-03-13 16:02:36 +10:30
|
|
|
else:
|
|
|
|
for x, j in enumerate(bytestring):
|
2017-03-13 23:20:19 +10:30
|
|
|
string = string + const.Glyphs[j]
|
2017-03-17 16:56:19 +10:30
|
|
|
painter.drawPixmap(x*8, 1, glyph_sprites_en_small[j])
|
2017-03-13 16:02:36 +10:30
|
|
|
del painter
|
|
|
|
return string, QPixmap.fromImage(img)
|
|
|
|
|
2017-07-23 18:29:22 +09:30
|
|
|
|
2017-03-17 16:56:19 +10:30
|
|
|
def make_string_img_large(bytestring, macros=None, jp=False):
|
2017-03-15 22:39:18 +10:30
|
|
|
'''
|
2017-03-17 16:56:19 +10:30
|
|
|
This is how we decipher dialogue data, which has multiple lines, macro expansions and kanji.
|
|
|
|
English characters have varying widths. In the japanese version, everything is fullwidth (16px)
|
|
|
|
Kanji aren't used in English dialogue but the cost is likely the same in checking either way.
|
2017-03-15 22:39:18 +10:30
|
|
|
'''
|
2017-03-17 16:56:19 +10:30
|
|
|
if len(bytestring) < 1:
|
|
|
|
raise ValueError('Empty bytestring was passed')
|
|
|
|
|
|
|
|
newstring = []
|
2017-03-15 19:43:29 +10:30
|
|
|
bytes = iter(bytestring)
|
|
|
|
for b in bytes:
|
|
|
|
if b in const.DoubleChars:
|
|
|
|
b2 = next(bytes)
|
2017-03-17 16:56:19 +10:30
|
|
|
newstring.append((b<<8) + b2)
|
2017-03-17 16:56:19 +10:30
|
|
|
elif macros and b in macros:
|
2017-03-17 16:56:19 +10:30
|
|
|
newstring.extend(macros[b])
|
2017-03-15 22:39:18 +10:30
|
|
|
else:
|
2017-03-17 16:56:19 +10:30
|
|
|
newstring.append(b)
|
2017-03-15 22:39:18 +10:30
|
|
|
|
|
|
|
string = ""
|
2017-03-17 16:56:19 +10:30
|
|
|
# Because the length of the input has little bearing on the size of the image thanks to linebreaks and macros, we overprovision then clip away.
|
2017-03-17 16:56:19 +10:30
|
|
|
max_width = 256 # This seems to check out, but the EN dialogue has linebreaks virtually everywhere anyway
|
2017-07-23 01:40:44 +09:30
|
|
|
max_height = 1024 # I've seen up to 58 rows in EN, 36 in JP. Stay safe.
|
2017-03-17 16:56:19 +10:30
|
|
|
img = QImage(max_width, max_height, QImage.Format_RGB16)
|
2017-03-15 22:39:18 +10:30
|
|
|
img.fill(bg_color)
|
|
|
|
painter = QtGui.QPainter(img)
|
|
|
|
|
|
|
|
x = xmax = y = 0
|
2017-03-17 16:56:19 +10:30
|
|
|
for j in newstring:
|
2017-03-15 22:39:18 +10:30
|
|
|
if x >= max_width: # Wrap on long line
|
|
|
|
string += '[wr]\n'
|
|
|
|
xmax = max_width # Can't go higher than this anyway
|
|
|
|
x = 0
|
2017-03-17 16:56:19 +10:30
|
|
|
y += 16
|
2017-03-15 22:39:18 +10:30
|
|
|
if j == 0x01: # Line break
|
|
|
|
string += '[br]\n'
|
|
|
|
xmax = x if x > xmax else xmax
|
|
|
|
x = 0
|
2017-03-17 16:56:19 +10:30
|
|
|
y += 16
|
2017-03-15 22:39:18 +10:30
|
|
|
elif 0x1E00 <= j < 0x1FAA: # Kanji live in this range
|
|
|
|
string += const.Glyphs_Kanji[j-0x1E00]
|
2017-03-17 16:56:19 +10:30
|
|
|
painter.drawPixmap(x, y+2, glyph_sprites_kanji[j-0x1E00])
|
|
|
|
x += 16
|
2017-03-15 22:39:18 +10:30
|
|
|
elif j < 0x13 or j > 0xFF: # Everything remaining outside this is a control char
|
|
|
|
string += '[0x{:02X}]'.format(j)
|
|
|
|
else:
|
2017-03-17 16:56:19 +10:30
|
|
|
if jp:
|
|
|
|
string += const.Glyphs_JP_large[j]
|
|
|
|
painter.drawPixmap(x, y+2, glyph_sprites_jp_large[j])
|
|
|
|
x += 16
|
|
|
|
else:
|
|
|
|
string += const.Glyphs[j]
|
|
|
|
painter.drawPixmap(x, y+4, glyph_sprites_en_large[j])
|
|
|
|
x += const.Dialogue_Width[j]
|
2017-03-13 18:07:09 +10:30
|
|
|
del painter
|
2017-03-13 21:08:49 +10:30
|
|
|
xmax = x if x > xmax else xmax
|
2017-03-17 16:56:19 +10:30
|
|
|
return string, QPixmap.fromImage(img.copy(0, 0, xmax, y+16))
|
2017-03-13 16:02:36 +10:30
|
|
|
|
2017-07-23 18:29:22 +09:30
|
|
|
|
2017-03-17 17:24:25 +10:30
|
|
|
def make_string_img_list(start, length, num, start_jp=None, len_jp=None, start_str=None, start_jp_str=None,
|
|
|
|
indirect=False, large=False, macros_en=None, macros_jp=None):
|
2017-03-13 16:02:36 +10:30
|
|
|
start_jp = start if start_jp is None else start_jp
|
|
|
|
len_jp = length if len_jp is None else len_jp
|
|
|
|
start_str = start if start_str is None else start_str
|
|
|
|
start_jp_str = start_str if start_jp_str is None else start_jp_str
|
|
|
|
stringlist = []
|
|
|
|
id_digits = hex_length(num-1)
|
2017-03-17 17:24:25 +10:30
|
|
|
|
2017-03-13 21:08:49 +10:30
|
|
|
if indirect:
|
|
|
|
for id in range(num):
|
|
|
|
en = start + (id*length)
|
|
|
|
jp = start_jp + (id*len_jp)
|
2017-03-17 16:56:19 +10:30
|
|
|
en_start = int.from_bytes(ROM_en[en:en+length],'little') + start_str
|
|
|
|
en_end = int.from_bytes(ROM_en[en+length:en+(length*2)],'little') + start_str
|
|
|
|
if en_start >= 0xC00000: # SNES memory space has the ROM starting at 0xC00000 in HiROM mode.
|
2017-03-13 21:08:49 +10:30
|
|
|
en_start -= 0xC00000
|
|
|
|
en_end -= 0xC00000
|
2017-03-17 16:56:19 +10:30
|
|
|
jp_start = int.from_bytes(ROM_jp[jp:jp+len_jp],'little') + start_jp_str
|
|
|
|
jp_end = int.from_bytes(ROM_jp[jp+len_jp:jp+(len_jp*2)],'little') + start_jp_str
|
|
|
|
if jp_start >= 0xC00000: # SNES memory space has the ROM starting at 0xC00000 in HiROM mode.
|
|
|
|
jp_start -= 0xC00000
|
|
|
|
jp_end -= 0xC00000
|
2017-03-17 17:24:25 +10:30
|
|
|
if (en_end == start_str) or (jp_end == start_jp_str):
|
2017-03-13 21:08:49 +10:30
|
|
|
break
|
2017-03-17 17:24:25 +10:30
|
|
|
try: # When dealing with pointer redirection we might end up passing empty strings
|
|
|
|
if large:
|
|
|
|
str_en, img_en = make_string_img_large(ROM_en[en_start:en_end], macros_en)
|
2017-03-13 21:08:49 +10:30
|
|
|
else:
|
2017-03-17 17:24:25 +10:30
|
|
|
str_en, img_en = make_string_img_small(ROM_en[en_start:en_end])
|
|
|
|
except ValueError:
|
|
|
|
str_en = ''
|
|
|
|
img_en = None
|
|
|
|
try:
|
|
|
|
if large:
|
|
|
|
str_jp, img_jp = make_string_img_large(ROM_jp[jp_start:jp_end], macros_jp, jp=True)
|
2017-03-13 21:08:49 +10:30
|
|
|
else:
|
2017-03-17 17:24:25 +10:30
|
|
|
str_jp, img_jp = make_string_img_small(ROM_jp[jp_start:jp_end], jp=True)
|
2017-03-13 21:08:49 +10:30
|
|
|
except ValueError:
|
2017-03-17 17:24:25 +10:30
|
|
|
str_jp = ''
|
|
|
|
img_jp = None
|
|
|
|
stringlist.append([
|
|
|
|
"0x{:06X}".format(en), "0x{:0{}X}".format(id, id_digits),
|
|
|
|
str_en, img_en, str_jp, img_jp, "0x{:06X}".format(jp_start)
|
|
|
|
])
|
2017-03-13 21:08:49 +10:30
|
|
|
else:
|
|
|
|
for id in range(num):
|
|
|
|
j1 = start + (id*length)
|
|
|
|
j2 = start_jp + (id*len_jp)
|
2017-03-13 18:07:09 +10:30
|
|
|
if large:
|
2017-03-17 16:56:19 +10:30
|
|
|
str_en, img_en = make_string_img_large(ROM_en[j1:j1+length], macros_en)
|
|
|
|
str_jp, img_jp = make_string_img_large(ROM_jp[j2:j2+len_jp], macros_jp, jp=True)
|
2017-03-13 18:07:09 +10:30
|
|
|
else:
|
2017-03-17 16:56:19 +10:30
|
|
|
str_en, img_en = make_string_img_small(ROM_en[j1:j1+length])
|
|
|
|
str_jp, img_jp = make_string_img_small(ROM_jp[j2:j2+len_jp], jp=True)
|
|
|
|
stringlist.append(["0x{:06X}".format(j1), "0x{:0{}X}".format(id, id_digits), str_en, img_en, str_jp, img_jp])
|
2017-03-13 16:02:36 +10:30
|
|
|
return stringlist
|
|
|
|
|
2017-07-23 18:29:22 +09:30
|
|
|
|
2017-03-18 15:12:19 +10:30
|
|
|
def table_size_to_contents(table):
|
|
|
|
# Stupid hack to get table to size correctly
|
|
|
|
table.hide()
|
|
|
|
geometry = table.viewport().geometry()
|
|
|
|
table.viewport().setGeometry(QtCore.QRect(0, 0, 0x7FFFFFFF, 0x7FFFFFFF))
|
|
|
|
table.resizeColumnsToContents()
|
|
|
|
table.resizeRowsToContents()
|
|
|
|
table.viewport().setGeometry(geometry)
|
|
|
|
table.show()
|
|
|
|
|
2017-07-23 18:29:22 +09:30
|
|
|
|
2017-03-17 14:48:16 +10:30
|
|
|
def make_table(headers, items, sortable=False, row_labels=True, scale=2):
|
2017-03-13 16:02:36 +10:30
|
|
|
"""
|
|
|
|
Helper function to tabulate 2d lists
|
|
|
|
"""
|
2017-03-13 23:20:19 +10:30
|
|
|
cols = len(headers)
|
2017-03-13 16:02:36 +10:30
|
|
|
rows = len(items)
|
|
|
|
rd = hex_length(rows-1)
|
2017-03-13 23:20:19 +10:30
|
|
|
table = QTableWidget(rows, cols)
|
2017-03-13 16:02:36 +10:30
|
|
|
if row_labels:
|
2017-03-13 23:20:19 +10:30
|
|
|
table.setVerticalHeaderLabels(['0x{:0{}X}'.format(v, rd) for v in range(rows)])
|
2017-03-13 16:02:36 +10:30
|
|
|
else:
|
|
|
|
table.verticalHeader().setVisible(False)
|
|
|
|
table.setHorizontalHeaderLabels(headers)
|
|
|
|
for row, col, item in [(x,y,items[x][y]) for x in range(rows) for y in range(cols)]:
|
|
|
|
if type(item) == type(QPixmap()):
|
|
|
|
lab = QLabel()
|
2017-03-17 14:48:16 +10:30
|
|
|
lab.setPixmap(item.scaled(item.size() * scale))
|
2017-03-13 16:02:36 +10:30
|
|
|
table.setCellWidget(row, col, lab)
|
|
|
|
elif item is not None:
|
|
|
|
q_item = QTableWidgetItem(item)
|
|
|
|
if item[:2] == "0x":
|
|
|
|
q_item.setFont(monofont)
|
|
|
|
table.setItem(row, col, q_item)
|
2017-03-18 15:12:19 +10:30
|
|
|
table_size_to_contents(table)
|
2017-03-13 16:02:36 +10:30
|
|
|
if sortable:
|
|
|
|
table.setSortingEnabled(True)
|
|
|
|
table.sortItems(0)
|
|
|
|
return table
|
2017-03-12 00:14:37 +10:30
|
|
|
|
2017-07-23 18:29:22 +09:30
|
|
|
|
2017-03-18 14:50:29 +10:30
|
|
|
def make_pixmap_table(items, cols=16, scale=4):
|
2017-03-13 23:20:19 +10:30
|
|
|
rows = divceil(len(items), cols)
|
|
|
|
rd = hex_length(rows-1)+1
|
2017-03-18 18:34:55 +10:30
|
|
|
cd = hex_length(cols-1)
|
2017-03-13 23:20:19 +10:30
|
|
|
table = QTableWidget(rows, cols)
|
|
|
|
table.setVerticalHeaderLabels(['0x{:0{}X}'.format(v*cols, rd) for v in range(rows)])
|
2017-03-18 18:34:55 +10:30
|
|
|
table.setHorizontalHeaderLabels(['0x{:0{}X}'.format(v, cd) for v in range(cols)])
|
2017-03-13 21:08:49 +10:30
|
|
|
for i in range(len(items)):
|
|
|
|
item = items[i]
|
|
|
|
lab = QLabel()
|
2017-03-13 23:20:19 +10:30
|
|
|
lab.setPixmap(item.scaled(item.size() * scale))
|
2017-04-02 14:37:53 +09:30
|
|
|
lab.setAlignment(QtCore.Qt.AlignCenter)
|
2017-03-13 21:08:49 +10:30
|
|
|
table.setCellWidget(i // cols, i % cols, lab)
|
2017-03-18 15:12:19 +10:30
|
|
|
table_size_to_contents(table)
|
2017-03-13 21:08:49 +10:30
|
|
|
return table
|
|
|
|
|
2017-03-11 19:18:33 +10:30
|
|
|
|
|
|
|
def main():
|
|
|
|
app = QApplication(sys.argv)
|
|
|
|
mainwindow = FF5Reader()
|
|
|
|
sys.exit(app.exec_())
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|