Exemple #1
0
        /// <summary>
        /// Gets a list of all translatable strings in specified record. Record must be a FileRecord of a valid dat file.
        /// </summary>
        /// <param name="record">Dat File Record to extract translatable strings from</param>
        /// <returns>List of translatable strings contained in specified dat file</returns>
        private List<string> GetTranslatableStringsFromDatFile(FileRecord record)
        {
            // Map of all strings that can be safely translated (not used as ID's, paths, etc) stored by their hash
            HashSet<string> currentStrings = new HashSet<string>();

            byte[] datBytes = record.ReadData(ggpkPath);
            using (MemoryStream datStream = new MemoryStream(datBytes))
            {
                DatContainer container = new DatContainer(datStream, record.Name);

                // Any properties with the UserStringIndex attribute are translatable
                foreach (var propInfo in container.DatType.GetProperties())
                {
                    if (!propInfo.GetCustomAttributes(false).Any(n => n is UserStringIndex))
                    {
                        continue;
                    }

                    foreach (var entry in container.Entries)
                    {
                        int stringIndex = (int)propInfo.GetValue(entry, null);
                        string stringValue = container.DataEntries[stringIndex].ToString();

                        if (string.IsNullOrWhiteSpace(stringValue))
                        {
                            continue;
                        }

                        if (!currentStrings.Contains(stringValue))
                        {
                            currentStrings.Add(stringValue);
                        }
                    }
                }
            }

            return currentStrings.ToList();
        }
        /// <summary>
        /// Displays the contents of a FileRecord in the TextBox as Ascii text
        /// </summary>
        /// <param name="selectedRecord">FileRecord to display</param>
        private void DisplayAscii(FileRecord selectedRecord)
        {
            byte[] buffer = selectedRecord.ReadData(ggpkPath);
            textBoxOutput.Visibility = System.Windows.Visibility.Visible;

            textBoxOutput.Text = Encoding.ASCII.GetString(buffer);
        }
        /// <summary>
        /// Displays the contents of a FileRecord in the RichTextBox
        /// </summary>
        /// <param name="selectedRecord">FileRecord to display</param>
        private void DisplayRichText(FileRecord selectedRecord)
        {
            byte[] buffer = selectedRecord.ReadData(ggpkPath);
            richTextOutput.Visibility = System.Windows.Visibility.Visible;

            using (MemoryStream ms = new MemoryStream(buffer))
            {
                richTextOutput.Selection.Load(ms, DataFormats.Rtf);
            }
        }
        /// <summary>
        /// Displays the contents of a FileRecord in the ImageBox
        /// </summary>
        /// <param name="selectedRecord">FileRecord to display</param>
        private void DisplayImage(FileRecord selectedRecord)
        {
            byte[] buffer = selectedRecord.ReadData(ggpkPath);
            imageOutput.Visibility = System.Windows.Visibility.Visible;

            using (MemoryStream ms = new MemoryStream(buffer))
            {
                BitmapImage bmp = new BitmapImage();
                bmp.BeginInit();
                bmp.CacheOption = BitmapCacheOption.OnLoad;
                bmp.StreamSource = ms;
                bmp.EndInit();
                imageOutput.Source = bmp;
            }
        }
        /// <summary>
        /// Displays the contents of a FileRecord in the ImageBox (DDS Texture mode)
        /// </summary>
        /// <param name="selectedRecord">FileRecord to display</param>
        private void DisplayDDS(FileRecord selectedRecord)
        {
            byte[] buffer = selectedRecord.ReadData(ggpkPath);
            imageOutput.Visibility = System.Windows.Visibility.Visible;

            DDSImage dds = new DDSImage(buffer);

            using (MemoryStream ms = new MemoryStream())
            {
                dds.images[0].Save(ms, ImageFormat.Png);

                BitmapImage bmp = new BitmapImage();
                bmp.BeginInit();
                bmp.CacheOption = BitmapCacheOption.OnLoad;
                bmp.StreamSource = ms;
                bmp.EndInit();
                imageOutput.Source = bmp;
            }
        }
        /// <summary>
        /// Displays the contents of a FileRecord in the DatViewer
        /// </summary>
        /// <param name="selectedRecord">FileRecord to display</param>
        private void DisplayDat(FileRecord selectedRecord)
        {
            byte[] data = selectedRecord.ReadData(ggpkPath);
            datViewerOutput.Visibility = System.Windows.Visibility.Visible;

            using (MemoryStream ms = new MemoryStream(data))
            {
                datViewerOutput.Reset(selectedRecord.Name, ms);
            }
        }