Browse Source

Bug fix for Linux-based systems.

louyihua 8 years ago
parent
commit
229efd8eed
3 changed files with 48 additions and 46 deletions
  1. 30 32
      makemessage.py
  2. 7 7
      script.c
  3. 11 7
      text.c

+ 30 - 32
makemessage.py

@@ -9,31 +9,16 @@ 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 = 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()

+ 7 - 7
script.c

@@ -539,7 +539,7 @@ PAL_AdditionalCredits(
    LPCWSTR rgszStrings[] = {
       L"  SDLPAL (http://sdlpal.codeplex.com/)",
 #ifdef PAL_CLASSIC
-	  L"%s(" WIDETEXT(__DATE__) L")",
+	  L"%ls(" WIDETEXT(__DATE__) L")",
 #else
 	  L"                        (" WIDETEXT(__DATE__) L")",
 #endif
@@ -547,12 +547,12 @@ PAL_AdditionalCredits(
 	  L"    (c) 2009-2011, Wei Mingzhi",
 	  L"        <whistler_wmz@users.sf.net>.",
       L"    (c) 2011-2015, SDLPAL Team",
-	  L"%s",  // Porting information line 1
-	  L"%s",  // Porting information line 2
-	  L"%s",  // GNU line 1
-	  L"%s",  // GNU line 2
-	  L"%s",  // GNU line 3
-      L"%s",  // Press Enter to continue
+	  L"%ls",  // Porting information line 1
+	  L"%ls",  // Porting information line 2
+	  L"%ls",  // GNU line 1
+	  L"%ls",  // GNU line 2
+	  L"%ls",  // GNU line 3
+      L"%ls",  // Press Enter to continue
    };
 
    int        i = 0;

+ 11 - 7
text.c

@@ -444,12 +444,13 @@ PAL_ReadMessageFile(
 		for (witem = whead.next; witem; )
 		{
 			struct _word_list_entry *temp = witem->next;
+			if (witem->index < PAL_ADDITIONAL_WORD_FIRST)
+				g_TextLib.lpWordBuf[witem->index] = witem->value;
+			else
 #ifndef PAL_CLASSIC
-			if (witem->index >= PAL_ADDITIONAL_WORD_FIRST)
 				g_TextLib.lpExtraWordBuf[witem->index - PAL_ADDITIONAL_WORD_FIRST] = witem->value;
-			else
 #else
-			g_TextLib.lpWordBuf[witem->index] = witem->value;
+				free(witem->value);
 #endif
 			free(witem); witem = temp;
 		}
@@ -505,10 +506,13 @@ PAL_InitText(
 		   int i;
 		   for (i = 1; i < g_TextLib.nWords; i++)
 		   {
-			   LPWSTR ptr = g_TextLib.lpWordBuf[i];
-			   DWORD n = 0;
-			   while (*ptr) n += PAL_CharWidth(*ptr++) >> 3;
-			   if (dwWordLength < n) dwWordLength = n;
+			   if (g_TextLib.lpWordBuf[i])
+			   {
+				   LPWSTR ptr = g_TextLib.lpWordBuf[i];
+				   DWORD n = 0;
+				   while (*ptr) n += PAL_CharWidth(*ptr++) >> 3;
+				   if (dwWordLength < n) dwWordLength = n;
+			   }
 		   }
 		   gpGlobals->dwWordLength = dwWordLength;
 		   for (i = 0; i < 12; i++)