/// <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;
            Console.WriteLine("DisplayDDS :" + ggpkPath);


            DDSImage dds = new DDSImage(buffer);

            Console.WriteLine("DisplayDDS DDSImage ok");


            using (MemoryStream ms = new MemoryStream())
            {
                Console.WriteLine("DisplayDDS MemoryStream ok");


                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;

                Console.WriteLine("DisplayDDS MemoryStream end");
            }
        }
Пример #2
0
        /// <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);
        }
Пример #3
0
 /// <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 = Visibility.Visible;
     using (MemoryStream ms = new MemoryStream(buffer))
     {
         richTextOutput.Selection.Load(ms, DataFormats.Rtf);
     }
 }
        /// <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);
            }
        }
Пример #5
0
        /// <summary>
        /// Applies translations to content.ggpk
        /// </summary>
        public void ApplyTranslations()
        {
            StringBuilder outputBuffer = new StringBuilder();

            foreach (var datTranslation in AllDatTranslations)
            {
                // Map of originalText -> Translation containing all translations to apply
                Dictionary <string, Translation> translationsToApply = (from n in datTranslation.Value.Translations
                                                                        where n.Status == Translation.TranslationStatus.NeedToApply
                                                                        select n).ToDictionary(k => k.OriginalText);
                if (translationsToApply.Count == 0)
                {
                    continue;
                }

                // Record we will be translating with data from translationTable
                FileRecord datRecord = fileRecordMap[datTranslation.Value.DatName];

                // Raw bytes of the .dat file we will be translating
                byte[] datBytes = datRecord.ReadData(ggpkPath);

                // Dat parser for changing the actual strings
                DatContainer dc = new DatContainer(new MemoryStream(datBytes), datTranslation.Value.DatName);

                // Replace the actual strings
                foreach (var item in dc.DataEntries)
                {
                    UnicodeString currentDatString = (item.Value as UnicodeString);
                    if (currentDatString == null || !currentDatString.IsUserString)
                    {
                        continue;
                    }

                    if (!translationsToApply.ContainsKey(currentDatString.Data))
                    {
                        continue;
                    }

                    Translation translationBeingApplied = translationsToApply[currentDatString.Data];
                    currentDatString.NewData = translationBeingApplied.TranslatedText;

                    outputBuffer.AppendLine(string.Format(Settings.Strings["ApplyTranslations_TextReplaced"], translationBeingApplied.ShortNameCurrent, translationBeingApplied.ShortNameTranslated));
                    translationBeingApplied.Status = Translation.TranslationStatus.AlreadyApplied;
                }

                // dc.GetBytes() will return the new data for this .dat file after replacing the original strings with whatever's in 'NewData'
                datRecord.ReplaceContents(ggpkPath, dc.GetBytes(), content.FreeRoot);
            }

            if (outputBuffer.Length > 0)
            {
                Output(outputBuffer.ToString());
            }
        }
        /// <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;
            }
        }
Пример #7
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());
        }
Пример #8
0
 /// <summary>
 /// Displays the contents of a FileRecord in the TextBox as Unicode text
 /// </summary>
 /// <param name="selectedRecord">FileRecord to display</param>
 private void DisplayUnicode(FileRecord selectedRecord)
 {
     byte[] buffer = selectedRecord.ReadData(ggpkPath);
     textBoxOutput.Visibility = Visibility.Visible;
     textBoxOutput.Text       = Encoding.Unicode.GetString(buffer);
 }