Esempio n. 1
0
        /// <summary>
        /// Applies translations to content.ggpk
        /// </summary>
        public void ApplyTranslations()
        {
            var outputBuffer = new StringBuilder();

            foreach (var datTranslation in AllDatTranslations)
            {
                // Map of originalText -> Translation containing all translations to apply
                var 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
                var datRecord = fileRecordMap[datTranslation.Value.DatName];

                // Raw bytes of the .dat file we will be translating
                var datBytes = datRecord.ReadFileContent(ggpkPath);

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

                // Replace the actual strings
                var strings = dc.GetUserStrings();
                foreach (var currentDatString in strings)
                {
                    if (!translationsToApply.ContainsKey(currentDatString.Value))
                    {
                        continue;
                    }

                    // TODO skip already strings already procesed in this loops
                    var translationBeingApplied = translationsToApply[currentDatString.Value];
                    currentDatString.NewValue = translationBeingApplied.TranslatedText;

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

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

            if (outputBuffer.Length > 0)
            {
                Output(outputBuffer.ToString());
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Replaces selected file with file user selects via MessageBox
        /// </summary>
        /// <param name="recordToReplace"></param>
        private void ReplaceFileRecord(FileRecord recordToReplace)
        {
            if (_content.IsReadOnly)
            {
                MessageBox.Show(
                    Settings.Strings["ReplaceItem_Readonly"],
                    Settings.Strings["ReplaceItem_ReadonlyCaption"]);
                return;
            }

            try
            {
                var openFileDialog = new OpenFileDialog
                {
                    FileName        = "",
                    CheckFileExists = true,
                    CheckPathExists = true
                };

                if (openFileDialog.ShowDialog() != true)
                {
                    return;
                }
                _content.ReplaceFile(recordToReplace, openFileDialog.FileName);
                MessageBox.Show(
                    String.Format(Settings.Strings["ReplaceItem_Successful"], recordToReplace.Name, recordToReplace.RecordBegin.ToString("X")),
                    Settings.Strings["ReplaceItem_Successful_Caption"],
                    MessageBoxButton.OK, MessageBoxImage.Information);
                UpdateDisplayPanel();
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    string.Format(Settings.Strings["ReplaceItem_Failed"], ex.Message),
                    Settings.Strings["Error_Caption"],
                    MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Esempio n. 3
0
        private static void HandlePatchArchive(string archivePath)
        {
            using (ZipFile zipFile = new ZipFile(archivePath))
            {
                bool VersionCheck     = false;
                bool NeedVersionCheck = false;
                OutputLine(string.Format("Archive {0}", archivePath));

                /*
                 *              foreach (var item in zipFile.Entries)
                 *              {
                 *                      if (item.FileName.Equals("version.txt"))
                 *                      {
                 *                              using (var reader = item.OpenReader())
                 *                              {
                 *                                      byte[] versionData = new byte[item.UncompressedSize];
                 *                                      reader.Read(versionData, 0, versionData.Length);
                 *                                      string versionStr = Encoding.UTF8.GetString(versionData, 0, versionData.Length);
                 *                                      if (RecordsByPath.ContainsKey("patch_notes.rtf"))
                 *                                      {
                 *                                              string Hash = BitConverter.ToString(RecordsByPath["patch_notes.rtf"].Hash);
                 *                                              if (versionStr.Substring(0, Hash.Length).Equals(Hash))
                 *                                              {
                 *                                                      VersionCheck = true;
                 *                                              }
                 *                                      }
                 *                              }
                 *                              break;
                 *                      }
                 *                      else if (Path.GetDirectoryName(item.FileName) == "Data" && Path.GetExtension(item.FileName).ToLower() == ".dat")
                 *                      {
                 *                              NeedVersionCheck = true;
                 *                      }
                 *                      else if (Path.GetDirectoryName(item.FileName) == "Metadata" && Path.GetExtension(item.FileName).ToLower() == ".txt")
                 *                      {
                 *                              NeedVersionCheck = true;
                 *                      }
                 *              }
                 *              if (NeedVersionCheck && !VersionCheck)
                 *              {
                 *                      OutputLine("Version Check Failed");
                 *                      return;
                 *              }
                 */

                foreach (var item in zipFile.Entries)
                {
                    if (item.IsDirectory)
                    {
                        continue;
                    }
                    if (item.FileName.Equals("version.txt"))
                    {
                        continue;
                    }

                    string fixedFileName = "ROOT" + Path.DirectorySeparatorChar + item.FileName;
                    if (Path.DirectorySeparatorChar != '/')
                    {
                        fixedFileName = fixedFileName.Replace('/', Path.DirectorySeparatorChar);
                    }

                    if (!RecordsByPath.ContainsKey(fixedFileName))
                    {
                        OutputLine(string.Format("Failed {0}", fixedFileName));
                        continue;
                    }
                    OutputLine(string.Format("Replace {0}", fixedFileName));

                    using (var reader = item.OpenReader())
                    {
                        byte[] replacementData = new byte[item.UncompressedSize];
                        reader.Read(replacementData, 0, replacementData.Length);

                        content.ReplaceFile(RecordsByPath[fixedFileName], replacementData);
                    }
                }
                OutputLine("Content.ggpk is Fine.");
            }
        }
Esempio n. 4
0
        /// <summary>
        /// changes fonts of Text in the game. Changes Content.ggpk
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnApplyFontClick(object sender, RoutedEventArgs e)
        {
            InitGgpk();

            if (_content == null)
            {
                return;
            }

            const string commonUi = "Metadata\\UI\\Common.ui";

            if (!_recordsByPath.ContainsKey(commonUi))
            {
                OutputLine(@"Error: Not found Metadata\\UI\\Common.ui in GGPK gile");
                return;
            }

            var datBytes = _recordsByPath[commonUi].ReadFileContent(textBoxContentGGPK.Text);
            var c        = '\ufeff';
            var lines    = c.ToString();

            using (var datStream = new MemoryStream(datBytes))
                using (var reader = new StreamReader(datStream, Encoding.Unicode))
                {
                    string line;

                    while ((line = reader.ReadLine()) != null)
                    {
                        if (line.Contains("const $globalFontSizeSmall  = "))
                        {
                            var small = Convert.ToInt32(textBoxSmallFont.Text);
                            if (small > 10 && small < 100)
                            {
                                OutputLine("Small:" + line.Substring(30, 2) + " to " + small);
                                line = "const $globalFontSizeSmall  = " + small + ";";
                            }
                        }
                        else if (line.Contains("const $globalFontSizeNormal = "))
                        {
                            var normal = Convert.ToInt32(textBoxNormalFont.Text);
                            if (normal > 10 && normal < 100)
                            {
                                OutputLine("Normal:" + line.Substring(30, 2) + " to " + normal);
                                line = "const $globalFontSizeNormal = " + normal + ";";
                            }
                        }
                        else if (line.Contains("const $globalFontSizeLarge  = "))
                        {
                            var large = Convert.ToInt32(textBoxLargeFont.Text);
                            if (large > 10 && large < 100)
                            {
                                OutputLine("Large:" + line.Substring(30, 2) + " to " + large);
                                line = "const $globalFontSizeLarge  = " + large + ";";
                            }
                        }
                        lines += line + "\r\n";
                    }
                }
            _content.ReplaceFile(_recordsByPath[commonUi], Encoding.Unicode.GetBytes(lines));
            OutputLine("Font Size Changed.");
        }