Ejemplo n.º 1
0
        static void LoadStrings(IGameInstance sriv)
        {
            var results = sriv.SearchForFiles("*.le_strings");

            foreach (var result in results)
            {
                string filename = result.Value.Filename.ToLowerInvariant();
                filename = Path.GetFileNameWithoutExtension(filename);

                string[] pieces       = filename.Split('_');
                string   languageCode = pieces.Last();

                Language language = LanguageUtility.GetLanguageFromCode(languageCode);

                if (!languageStrings.ContainsKey(language))
                {
                    languageStrings.Add(language, new Dictionary <uint, string>());
                }

                Dictionary <uint, string> strings = languageStrings[language];

                using (Stream s = sriv.OpenPackfileFile(result.Value.Filename, result.Value.Packfile))
                {
                    StringFile file = new StringFile(s, language, sriv);

                    foreach (var hash in file.GetHashes())
                    {
                        if (strings.ContainsKey(hash))
                        {
                            continue;
                        }

                        strings.Add(hash, file.GetString(hash));
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            Options options = null;

            try
            {
                options = CommandLine.Parse <Options>();
            }
            catch (CommandLineException exception)
            {
                Console.WriteLine(exception.ArgumentHelp.Message);
                Console.WriteLine();
                Console.WriteLine(exception.ArgumentHelp.GetHelpText(Console.BufferWidth));

#if DEBUG
                Console.ReadLine();
#endif
                return;
            }

            IGameInstance instance = GameInstance.GetFromString(options.Game);

            string   filename     = Path.GetFileNameWithoutExtension(options.Input);
            string   languageCode = filename.Remove(0, filename.Length - 2);
            Language language     = LanguageUtility.GetLanguageFromCode(languageCode);

            Dictionary <UInt32, string> hashLookup = new Dictionary <UInt32, string>();

            if (options.LoadXtbls)
            {
                Console.WriteLine("Loading XTBL files...");
                Dictionary <string, FileSearchResult> results = instance.SearchForFiles("*.xtbl");
                int i = 0;
                foreach (var pair in results)
                {
                    i++;
                    Console.WriteLine("[{0}/{1}] Loading xtbl: {2}", i, results.Count, pair.Key);

                    string xtbl = null;
                    using (StreamReader reader = new StreamReader(pair.Value.GetStream()))
                    {
                        xtbl = reader.ReadToEnd();
                    }
                    Regex regex = new Regex("<Name>(.*?)</Name>", RegexOptions.Compiled);
                    foreach (Match m in regex.Matches(xtbl))
                    {
                        uint hash = Hashes.CrcVolition(m.Groups[1].Value);
                        if (!hashLookup.ContainsKey(hash))
                        {
                            hashLookup.Add(hash, m.Groups[1].Value);
                        }
                    }
                }
            }

            string outputFile = (options.Output != null) ? options.Output : Path.ChangeExtension(options.Input, ".xml");

            Console.WriteLine("Extracting {0} to {1}...", options.Input, outputFile);

            StringFile stringFile = null;

            using (Stream stream = File.OpenRead(options.Input))
            {
                stringFile = new StringFile(stream, language, instance);
            }

            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent       = true;
            settings.IndentChars  = "\t";
            settings.NewLineChars = "\r\n";

            Dictionary <string, string> stringsWithName = new Dictionary <string, string>();
            Dictionary <uint, string>   stringsWithHash = new Dictionary <uint, string>();

            foreach (uint hash in stringFile.GetHashes())
            {
                string text = stringFile.GetString(hash);

                if (hashLookup.ContainsKey(hash))
                {
                    stringsWithName.Add(hashLookup[hash], text);
                }
                else
                {
                    stringsWithHash.Add(hash, text);
                }
            }



            using (XmlWriter xml = XmlTextWriter.Create(outputFile, settings))
            {
                xml.WriteStartDocument();
                xml.WriteStartElement("Strings");
                xml.WriteAttributeString("Language", language.ToString());
                xml.WriteAttributeString("Game", instance.Game.ToString());

                foreach (var pair in stringsWithName.OrderBy(x => x.Key))
                {
                    xml.WriteStartElement("String");

                    xml.WriteAttributeString("Name", pair.Key);
                    xml.WriteString(pair.Value);

                    xml.WriteEndElement(); // String
                }

                foreach (var pair in stringsWithHash)
                {
                    xml.WriteStartElement("String");

                    xml.WriteAttributeString("Hash", pair.Key.ToString("X8"));
                    xml.WriteString(pair.Value);

                    xml.WriteEndElement(); // String
                }

                xml.WriteEndElement(); // Strings
                xml.WriteEndDocument();
            }

            Console.WriteLine("Done.");
#if DEBUG
            Console.ReadLine();
#endif
        }