#!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import with_statement import argparse import os import traceback import struct def main(): 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', choices = ['gbk', 'big5'], help = 'Text encoding name, should be either gbk or big5.') parser.add_argument('-w', '--width', dest = 'wordwidth', default = 10, type = int, help = 'Word width in bytes, default is 10') parser.add_argument("-c", "--comment", action = 'store_true', help = 'Automatically generate comments') options = parser.parse_args() if options.gamepath[-1] != '/' and options.gamepath[-1] != '\\': options.gamepath += '/' script_bytes = [] index_bytes = [] msg_bytes = [] word_bytes = [] is_msg_group = 0 #是否正在处理文字组的标示。 msg_count = 0 last_index = -1 temp = "" comment = "" message = "" for file_ in os.listdir(options.gamepath): if file_.lower() == 'sss.mkf': try: with open(options.gamepath + file_, 'rb') as f: f.seek(12, os.SEEK_SET) offset_begin, script_begin, file_end = struct.unpack('