#!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import with_statement import argparse import os import traceback import struct def main(): #示例:lscript.py -i /home/user/PAL -e gb2312 -o dialog.txt 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.add_argument('-w','--width', dest='wordwidth', help='Word width in bytes') parser.add_argument('-e','--encoding', dest='encoding', help='Encoding name') 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.wordwidth == None: options.wordwidth = 10 else: options.wordwidth = int(options.wordwidth) script_bytes = [] index_bytes = [] msg_bytes = [] word_bytes = [] is_msg_group = 0 #是否正在处理文字组的标示。 msg_count = 0 last_index = -1 for file_ in os.listdir(options.inpath): if file_.lower() == 'sss.mkf': try: with open(options.inpath + file_, 'rb') as f: f.seek(12, os.SEEK_SET) offset_begin, script_begin, file_end = struct.unpack('