public static void doExtract(string[] args) { bool isBigEndian = false; LocaleID lang = LocaleID.Default; String bigfilePath = String.Empty; String patchPath = String.Empty; if (args.Length < 2) { Console.WriteLine("Error! Not enough arguments passed to program."); Console.WriteLine(""); showHelpAndQuit(); } else { if (args[1] == "help") { showHelpAndQuit(); } else if (args.Length < 3) { Console.WriteLine("Error! Not enough arguments passed to program."); Console.WriteLine(""); showHelpAndQuit(); } else if (args.Length > 5) { Console.WriteLine("Error! Too many arguments passed to program."); Console.WriteLine(""); showHelpAndQuit(); } else { lang = Locale.getFromString(args[1]); if (lang == LocaleID.Default) { Console.WriteLine("Error! Unknown language {0}", args[1]); Console.WriteLine(""); showHelpAndQuit(); } bigfilePath = args[2]; if (args.Length > 3) { if (args[3] == "be") { isBigEndian = true; if (args.Length > 4) { patchPath = args[4]; } } else { patchPath = args[3]; } } } } // Remove trailing backslash on paths if (bigfilePath.EndsWith("\\")) { bigfilePath = bigfilePath.Remove(bigfilePath.Length - 1); } if (patchPath.EndsWith("\\")) { patchPath = patchPath.Remove(patchPath.Length - 1); } // Get locale mask uint mask; if (patchPath != "") { uint mask2 = Locale.getLocaleMask(bigfilePath); mask = Locale.getLocaleMask(patchPath); if (mask2 != mask) { throw new Exception("Patch and bigfile locale mask different"); } } else { mask = Locale.getLocaleMask(bigfilePath); } if (mask == uint.MaxValue) { throw new Exception("Error finding localisation database (\"locals.bin\"). Make sure the game files are properly unpacked."); } else if (mask == (uint.MaxValue - 1)) { Console.WriteLine(""); Console.WriteLine("Unable to determine language of game files."); Console.WriteLine("Please confirm that the language {0} is supported by your game.", Locale.toString(lang)); Console.WriteLine("NOTE: If the language is not supported by the game, you won't see any changes!"); Console.Write("Confirm? (y/n)"); var yes = new ConsoleKeyInfo('y', ConsoleKey.Y, false, false, false); var no = new ConsoleKeyInfo('n', ConsoleKey.N, false, false, false); while (true) { var key = Console.ReadKey(true); if (key == no) { System.Environment.Exit(0); } else if (key == yes) { break; } } Console.WriteLine(""); } //Check if lang is present in files else if ((mask & (1 << (int)lang)) == 0) { Console.WriteLine(""); Console.WriteLine("Error! Language {0} not found in game files.", Locale.toString(lang)); Console.WriteLine(""); Console.WriteLine("Detected languages:"); for (int i = 0; i < 16; i++) { if ((mask & (1 << i)) != 0) { Console.WriteLine(Locale.toString((LocaleID)i)); } } System.Environment.Exit(0); } TransFile tf = new TransFile(bigfilePath, patchPath, isBigEndian); var files = getFilelist(bigfilePath, patchPath, (int)lang, mask); System.Console.WriteLine("Searching following files for translatable text:"); int f = 0; foreach (string file in files) { System.Console.WriteLine("{0} of {1} - {2}", ++f, files.Count, Path.GetFileName(file)); if (file.EndsWith("locals.bin")) { LocalsFile lf = new LocalsFile(isBigEndian); lf.parse(file); string basep; string name; if (file.StartsWith(bigfilePath)) { basep = bigfilePath; name = file.Substring(bigfilePath.Length); } else { basep = patchPath; name = file.Substring(patchPath.Length); } tf.AddLocalsFile(lf, basep, name); } else { CineFile cf = new CineFile(isBigEndian); cf.parse(file); if (cf.isSubs()) { string basep; string name; if (file.StartsWith(bigfilePath)) { basep = bigfilePath; name = file.Substring(bigfilePath.Length); } else { basep = patchPath; name = file.Substring(patchPath.Length); } tf.AddFile(basep, name); List <SubtitleEntry> entries = cf.getSubtitles(); foreach (SubtitleEntry e in entries) { if (e.lang == lang) { tf.AddEntry(e.text, e.lang.ToString(), e.blockNumber.ToString()); } } } } } tf.Close(); System.Console.WriteLine("Translatable text saved to file \"translations.xml\""); }
public static void doExtract(string[] args) { bool isBigEndian = false; LocaleID lang = LocaleID.Default; String bigfilePath = String.Empty; String patchPath = String.Empty; if (args.Length < 2) { Console.WriteLine("Error! Not enough arguments passed to program."); Console.WriteLine(""); showHelpAndQuit(); } else { if (args[1] == "help") { showHelpAndQuit(); } else if (args.Length < 3) { Console.WriteLine("Error! Not enough arguments passed to program."); Console.WriteLine(""); showHelpAndQuit(); } else if (args.Length > 5) { Console.WriteLine("Error! Too many arguments passed to program."); Console.WriteLine(""); showHelpAndQuit(); } else { lang = Locale.getFromString(args[1]); if (lang == LocaleID.Default) { Console.WriteLine("Error! Unknown language {0}", args[1]); Console.WriteLine(""); showHelpAndQuit(); } bigfilePath = args[2]; if (args.Length > 3) if (args[3] == "be") { isBigEndian = true; if (args.Length > 4) patchPath = args[4]; } else patchPath = args[3]; } } // Remove trailing backslash on paths if (bigfilePath.EndsWith("\\")) bigfilePath = bigfilePath.Remove(bigfilePath.Length - 1); if (patchPath.EndsWith("\\")) patchPath = patchPath.Remove(patchPath.Length - 1); // Get locale mask uint mask; if (patchPath != "") { uint mask2 = Locale.getLocaleMask(bigfilePath); mask = Locale.getLocaleMask(patchPath); if (mask2 != mask) throw new Exception("Patch and bigfile locale mask different"); } else mask = Locale.getLocaleMask(bigfilePath); if (mask == uint.MaxValue) { throw new Exception("Error finding localisation database (\"locals.bin\"). Make sure the game files are properly unpacked."); } else if (mask == (uint.MaxValue - 1)) { Console.WriteLine(""); Console.WriteLine("Unable to determine language of game files."); Console.WriteLine("Please confirm that the language {0} is supported by your game.", Locale.toString(lang)); Console.WriteLine("NOTE: If the language is not supported by the game, you won't see any changes!"); Console.Write("Confirm? (y/n)"); var yes = new ConsoleKeyInfo('y', ConsoleKey.Y, false, false, false); var no = new ConsoleKeyInfo('n', ConsoleKey.N, false, false, false); while (true) { var key = Console.ReadKey(true); if (key == no) System.Environment.Exit(0); else if (key == yes) break; } Console.WriteLine(""); } //Check if lang is present in files else if ((mask & (1 << (int)lang)) == 0) { Console.WriteLine(""); Console.WriteLine("Error! Language {0} not found in game files.", Locale.toString(lang)); Console.WriteLine(""); Console.WriteLine("Detected languages:"); for (int i = 0; i < 16; i++) { if((mask & (1 << i)) != 0) Console.WriteLine(Locale.toString((LocaleID)i)); } System.Environment.Exit(0); } TransFile tf = new TransFile(bigfilePath, patchPath, isBigEndian); var files = getFilelist(bigfilePath, patchPath, (int)lang, mask); System.Console.WriteLine("Searching following files for translatable text:"); int f = 0; foreach (string file in files) { System.Console.WriteLine("{0} of {1} - {2}", ++f, files.Count, Path.GetFileName(file)); if (file.EndsWith("locals.bin")) { LocalsFile lf = new LocalsFile(isBigEndian); lf.parse(file); string basep; string name; if (file.StartsWith(bigfilePath)) { basep = bigfilePath; name = file.Substring(bigfilePath.Length); } else { basep = patchPath; name = file.Substring(patchPath.Length); } tf.AddLocalsFile(lf, basep, name); } else { CineFile cf = new CineFile(isBigEndian); cf.parse(file); if (cf.isSubs()) { string basep; string name; if (file.StartsWith(bigfilePath)) { basep = bigfilePath; name = file.Substring(bigfilePath.Length); } else { basep = patchPath; name = file.Substring(patchPath.Length); } tf.AddFile(basep, name); List<SubtitleEntry> entries = cf.getSubtitles(); foreach (SubtitleEntry e in entries) { if (e.lang == lang) { tf.AddEntry(e.text, e.lang.ToString(), e.blockNumber.ToString()); } } } } } tf.Close(); System.Console.WriteLine("Translatable text saved to file \"translations.xml\""); }