ChocolateBird/scripts/loaders/snes/ff5_dialog.gd

113 lines
6.3 KiB
GDScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const LITERAL_MACROS := {
# Is 0x00 a wait for input marker?
# 0x01 is linebreak
#0x02: [0x20, 0xBC, 0x82], # 0x02 expands to Bartz's name バッツ. Used for his dialogue in EN, only used for other chars in JP.
0x03: [0x6E, 0xA8, 0x78, 0x7E, 0xAA], # 0x03 is クリスタル
0x04: [0x7E, 0x8C, 0x6E, 0xC5, 0xB8], # expands to タイクーン
0x06: [0x37, 0xBF], # expands to じゃ
0x07: [0x8D, 0xAB], # expands to いる
0x08: [0xFF, 0xFF, 0xFF, 0xFF], # 4 spaces
0x09: [0xFF, 0xFF, 0xFF], # 3 spaces
0x0A: [0xFF, 0xFF], # 2 spaces
0x0B: [0x1E12, 0x1E13], # expands to 魔物
# 0x0C appears to be a pause in delivery - affects previous char
0x0D: [0x1E24, 0x9B, 0x1E52, 0x1E57], # expands to 風の神殿
0x0E: [0x1E04, 0x1E0A], # expands to 飛竜
# 0x0F - unknown (invisible control char)
# 0x10 is a gil substitution
# 0x11 and 0x12 appear to be item (obtained) substitutions
0x13: [0x1E07, 0x1E0D], # expands to 封印
0x14: [0x76, 0x46, 0xD0], # Cid speaking - シド「
0x15: [0x9E, 0x46, 0xD0], # Mid speaking - ミド「
0x16: [0x1E05, 0x1E06], # expands to 世界
# 0x17 uses the next byte for pause duration (seconds?)
0x18: [0x8E, 0x6E, 0x78, 0x44, 0x78], # expands to エクスデス
0x19: [0xAC, 0x92, 0xD0], # Lenna speaking - レナ「
0x1A: [0x2A, 0xA6, 0x64, 0xD0], # Galuf speaking - ガラフ「
0x1B: [0x64, 0xC4, 0xA8, 0x78, 0xD0], # Faris speaking - ファリス「
0x1C: [0x6E, 0xAA, 0xAA, 0xD0], # Krile/Kara speaking - クルル「
0x1D: [0x91, 0x37, 0x8D, 0x81, 0xBF, 0xB9], # expands to おじいちゃん
# 0x1E-0x1F form kanji with the next byte
# 0x20-0xCC are standard character set
0xCD: [0xC9, 0xC9], # % (0xCD) to !!
# 0xCE is
0xCF: [0xBD, 0x85], # : (0xCF) appears to expand to って
# 0xD0-0xD4 are 「」。AB
0xD5: [0x1E1B, 0x95, 0x1E08, 0xAD], # expands to 手に入れ
# 0xD6, 0xD7, 0xD8 are
0xD9: [0x93, 0x8D], # expands to ない
# 0xDA-0xDC are
0xDD: [0xC7, 0xC7], # S (0xDD) to ……
0xDE: [0x3F, 0x8D, 0x37, 0xC3, 0x89, 0x25], # C (0xDE) to だいじょうぶ
0xDF: [0x61, 0xE3], # T (0xDF) to は、
0xE0: [0xB9, 0x3F], # expands to んだ
0xE1: [0x85, 0x8D], # expands to てい
0xE2: [0x77, 0x7F], # expands to した
# 0xE3 is 、
0xE4: [0x77, 0x85], # ◯ (0xE4) appears to expand to して
# 0xE5 is used for Bartz speaking in JP. This only appears as 『
0xE6: [0x91, 0x1E0F, 0x1E03], # F (0xE6) appears to expand to otousan (お父様)
0xE7: [0xC9, 0xCB], # °C (0xE7) to !? - yes this is the wrong order interrobang
0xE8: [0x45, 0x79], # ・ (0xE8) appears to expand to です
# 0xE9, 0xEA are
0xEB: [0x73, 0x9B], # expands to この
0xEC: [0x9B, 0x1E02], # expands to の力
0xED: [0x70, 0xAA, 0x2A, 0xC5], # expands to ケルガー
0xEE: [0x1E86, 0x1ED7, 0x1E87, 0x1E62, 0x1EA7], # expands to 古代図書舘 (ancient library?)
0xEF: [0x1E1C, 0xBD, 0x85], # expands to 言って
0xF0: [0x1E2B, 0x1E0B, 0xD0], # soldier speaking - 兵士「
0xF1: [0x6B, 0xA7], # expands to から
0xF2: [0x1E2C, 0x6A, 0x1E0C], # expands to 火カ船
0xF3: [0x1E0E, 0x3D, 0x6F], # expands to 海ぞく
0xF4: [0x8D, 0x37, 0xC3, 0x89], # expands to いじょう
0xF5: [0x2B, 0xE3], # expands to が、
0xF6: [0x7F, 0x81], # expands to たち
0xF7: [0x7F, 0x9B], # expands to たの
0xF8: [0x9D, 0x79], # expands to ます
0xF9: [0x6F, 0x3F, 0x75, 0x8D], # expands to ください
0xFA: [0x6B, 0xBD, 0x7F], # expands to かった
0xFB: [0x7F, 0xC9], # expands to た!
0xFC: [0x95, 0xE3], # expands to に、
0xFD: [0x8D, 0x93, 0x8D, 0x6B, 0xA7, 0x93, 0xB9, 0x3F], # expands to いないからなんだ
0xFE: [0x1F20, 0x1F38, 0x9B, 0x61, 0x35, 0x9D], # expands to 次元のはざま
# 0xFF is space
}
static func decode_string_dialog(bytes, glyph_table: PoolStringArray, glyph_table_kanji: PoolStringArray, variables:={}, trim_trailing_whitespace: bool = true) -> String:
# Dialog requires multibyte handling including kanji and other macros
var expanded_bytes = PoolIntArray() # Kanji are 16bit codes
var output = ''
var i := 0
var end := len(bytes)
while i < end:
var c: int = bytes[i]
match c:
# 0x17 uses the next byte for pause duration (seconds?)
0x17, 0x1E, 0x1F: # Kanji
i += 1
expanded_bytes.append((c << 8) + bytes[i])
_:
expanded_bytes.append_array(LITERAL_MACROS.get(c, [c]))
i += 1
for c in expanded_bytes:
match c:
0x02:
output += variables.get('bartz_name', 'Bartz')
0x0C: # 0x0C appears to be a pause in delivery - affects previous char
pass
0x0F: # 0x0F - unknown (invisible control char)
pass
0x10: # 0x10 is a gil substitution
output += '%d' % variables.get('gil_amount', 0)
0x11, 0x12: # 0x11 and 0x12 appear to be item (obtained) substitutions
output += variables.get('item_name', 'unk_item')
_:
if c < 0x1700:
output += glyph_table[c]
elif c < 0x1E00:
var delay = c - 0x1700
pass # TODO: work out a way to signal dialog delivery pauses
else:
output += glyph_table_kanji[c - 0x1E00]
return output.trim_suffix(' ') if trim_trailing_whitespace else output