|
@@ -9,31 +9,16 @@ import struct
|
|
|
|
|
|
def main():
|
|
|
|
|
|
-
|
|
|
- parser = argparse.ArgumentParser(description='Output FFFF info of Script file.')
|
|
|
- parser.add_argument('-i','--input', dest='inpath', help='Game path')
|
|
|
- parser.add_argument('-o','--output', dest='outfile', help='Output file')
|
|
|
+ parser = argparse.ArgumentParser(description='Generate a translatable language file that can be used by SDLPAL.')
|
|
|
+ parser.add_argument('gamepath', help='Game path where SSS.MKF & M.MSG & WORD.DAT are located.')
|
|
|
+ parser.add_argument('outputfile', help='Path of the output message file.')
|
|
|
+ parser.add_argument('encoding', help='Text encoding name (such as "gb2312" or "big5").')
|
|
|
parser.add_argument('-w','--width', dest='wordwidth', help='Word width in bytes')
|
|
|
- parser.add_argument('-e','--encoding', dest='encoding', help='Encoding name')
|
|
|
+ parser.add_argument("-c", "--comment", action="store_true", help='Automatically generate comments')
|
|
|
options = parser.parse_args()
|
|
|
|
|
|
- if options.inpath == None or len(options.inpath) == 0:
|
|
|
- print 'Game path must be specified!'
|
|
|
- parser.print_help()
|
|
|
- return
|
|
|
-
|
|
|
- if options.encoding == None or len(options.encoding) == 0:
|
|
|
- print 'Encoding must be specified!'
|
|
|
- parser.print_help()
|
|
|
- return
|
|
|
-
|
|
|
- if options.outfile == None or len(options.outfile) == 0:
|
|
|
- print 'Output file must be specified!'
|
|
|
- parser.print_help()
|
|
|
- return
|
|
|
-
|
|
|
- if options.inpath[-1] != '/' and options.inpath[-1] != '\\':
|
|
|
- options.inpath += '/'
|
|
|
+ if options.gamepath[-1] != '/' and options.gamepath[-1] != '\\':
|
|
|
+ options.gamepath += '/'
|
|
|
|
|
|
if options.wordwidth == None:
|
|
|
options.wordwidth = 10
|
|
@@ -48,11 +33,14 @@ def main():
|
|
|
is_msg_group = 0
|
|
|
msg_count = 0
|
|
|
last_index = -1
|
|
|
+ temp = ""
|
|
|
+ comment = ""
|
|
|
+ message = ""
|
|
|
|
|
|
- for file_ in os.listdir(options.inpath):
|
|
|
+ for file_ in os.listdir(options.gamepath):
|
|
|
if file_.lower() == 'sss.mkf':
|
|
|
try:
|
|
|
- with open(options.inpath + file_, 'rb') as f:
|
|
|
+ with open(options.gamepath + file_, 'rb') as f:
|
|
|
f.seek(12, os.SEEK_SET)
|
|
|
offset_begin, script_begin, file_end = struct.unpack('<III', f.read(12))
|
|
|
f.seek(offset_begin, os.SEEK_SET)
|
|
@@ -63,14 +51,14 @@ def main():
|
|
|
return
|
|
|
elif file_.lower() == 'm.msg':
|
|
|
try:
|
|
|
- with open(options.inpath + file_, 'rb') as f:
|
|
|
+ with open(options.gamepath + file_, 'rb') as f:
|
|
|
msg_bytes = f.read()
|
|
|
except:
|
|
|
traceback.print_exc()
|
|
|
return
|
|
|
elif file_.lower() == 'word.dat':
|
|
|
try:
|
|
|
- with open(options.inpath + file_, 'rb') as f:
|
|
|
+ with open(options.gamepath + file_, 'rb') as f:
|
|
|
data_bytes=f.read()
|
|
|
except:
|
|
|
traceback.print_exc()
|
|
@@ -101,7 +89,10 @@ def main():
|
|
|
output += "[BEGIN WORDS]\n"
|
|
|
output += "# Each line is a pattern of 'key=value', where key is an integer and value is a string.\n"
|
|
|
for i in range(0, len(data_bytes) / options.wordwidth):
|
|
|
- output += "%d=%s\n" % (i, data_bytes[i * options.wordwidth: (i + 1) * options.wordwidth].rstrip('\x20\x00').decode(options.encoding).encode('utf-8'))
|
|
|
+ temp = data_bytes[i * options.wordwidth: (i + 1) * options.wordwidth].rstrip('\x20\x00').decode(options.encoding).encode('utf-8')
|
|
|
+ if options.comment: output += "# Original word: %s\n" % temp
|
|
|
+ output += "%d=%s\n" % (i, temp)
|
|
|
+ output += "65530=Battle Speed"
|
|
|
output += "[END WORDS]\n\n"
|
|
|
|
|
|
output += "# The following sections contain dialog/description texts used by the game.\n\n"
|
|
@@ -114,29 +105,36 @@ def main():
|
|
|
|
|
|
if is_msg_group == 0:
|
|
|
is_msg_group = 1
|
|
|
- output += "%s %d\n" % ('[BEGIN MESSAGE]', w1)
|
|
|
+ message = "%s %d\n" % ('[BEGIN MESSAGE]', w1)
|
|
|
+ if options.comment: comment = "# Original message:\n"
|
|
|
|
|
|
last_index = w1
|
|
|
msg_count += 1
|
|
|
msg_begin, msg_end = struct.unpack("<II",index_bytes[w1 * 4 : (w1 + 2) * 4])
|
|
|
|
|
|
try:
|
|
|
- output += "%s\n" % (msg_bytes[msg_begin : msg_end].decode(options.encoding, 'replace').encode('utf-8'))
|
|
|
+ temp = "%s\n" % (msg_bytes[msg_begin : msg_end].decode(options.encoding, 'replace').encode('utf-8'))
|
|
|
+ message += temp
|
|
|
+ if options.comment: comment += "# " + temp
|
|
|
except:
|
|
|
traceback.print_exc()
|
|
|
|
|
|
elif op == 0x008E:
|
|
|
|
|
|
if is_msg_group == 1:
|
|
|
- output += "%s\n" % ('[CLEAR MESSAGE]')
|
|
|
+ temp = "%s\n" % ('[CLEAR MESSAGE]')
|
|
|
+ message += temp
|
|
|
+ if options.comment: comment += "# " + temp
|
|
|
|
|
|
else:
|
|
|
if is_msg_group == 1:
|
|
|
is_msg_group = 0
|
|
|
- output += "%s %d\n\n" % ('[END MESSAGE]', last_index)
|
|
|
+ temp = "%s %d\n\n" % ('[END MESSAGE]', last_index)
|
|
|
+ message += temp
|
|
|
+ output += comment + message
|
|
|
|
|
|
try:
|
|
|
- with open(options.outfile, "wt") as f:
|
|
|
+ with open(options.outputfile, "wt") as f:
|
|
|
f.write(output)
|
|
|
except:
|
|
|
traceback.print_exc()
|