Beispiel #1
0
 public void SaveTest()
 {
     using (var InputStream = File.OpenRead(Utils.TestInputPath + @"\VC001US.TO8CHTX"))
         using (var OutputStream = File.Open(Utils.TestOutputPath + @"\VC001US.TO8CHTX", FileMode.Create))
         {
             var TO8CHTX = new TO8CHTX(InputStream);
             foreach (var Entry in TO8CHTX.Entries)
             {
                 Entry.TextOriginal = "";
                 //Entry.TextTranslated = "";
             }
             TO8CHTX.SaveTo(OutputStream);
         }
     using (var OutputStream = File.Open(Utils.TestOutputPath + @"\TEST.TO8CHTX", FileMode.Create))
     {
         var TO8CHTX = new TO8CHTX();
         TO8CHTX.Entries.Add(new TO8CHTX.Entry()
         {
             Title          = CharacterMapping.Instance.Map("Title Test"),
             TextOriginal   = CharacterMapping.Instance.Map("Text Original"),
             TextTranslated = CharacterMapping.Instance.Map("¡¿Esto es una prueba en ESPAÑOL o en Español?!"),
             Talker         = TalesOfVesperiaUtils.Formats.Packages.TO8CHTX.Talker.Yuri,
         });
         TO8CHTX.SaveTo(OutputStream);
     }
 }
Beispiel #2
0
 public void LoadTest()
 {
     using (var InputStream = File.OpenRead(Utils.TestInputPath + @"\VC001US.TO8CHTX"))
     {
         var TO8CHTX = new TO8CHTX(InputStream);
         Assert.AreEqual(12, TO8CHTX.Length);
         Assert.AreEqual <String>(TO8CHTX[0].TextTranslated, "Wow, the days just fly by...");
         Assert.AreEqual <String>(TO8CHTX[6].TextTranslated, "So all this bad luck made us fight, \nand so...we got stronger.");
     }
 }
Beispiel #3
0
        private void Handle3()
        {
            Patcher.ProgressHandler.AddProgressLevel("Actualizando chat.svo", 1, () =>
            {
                Patcher.Action("Updating chat.svo...", () =>
                {
                    Patcher.GameFileSystem.ReplaceFileWithStream("chat.svo", Patcher.TempFS.OpenFileRead("chat.es.svo"), (Current, Total) =>
                    {
                        Patcher.ProgressHandler.SetLevelProgressTo(Current, Total);
                    });
                });
            });
#if false
            //Patcher.TempFS.OpenFileRead("chat.es.svo").CopyTo(Patcher.GameFileSystem.OpenFileRW("chat.svo"));

            //Patcher.TempFS.WriteAllBytes("VC001US.DAT", TalesCompression.DecompressStream(ChatSvo["VC001US.DAT"].Open()).ReadAll());
            Patcher.GameAccessPath("chat.svo", () =>
            {
                var ChatId = "VC001";
                //Patcher.GameGetFile(ChatId + "US.DAT", (File) => { });

                Patcher.GameAccessPath(ChatId + "US.DAT", () =>
                {
                    Patcher.GameGetFile("3", (ChtxStream) =>
                    {
                        var Chtx = new TO8CHTX();
                        Chtx.Load(ChtxStream);
                        // Translate
                        {
                            foreach (var Entry in Patcher.EntriesByRoom["skits/" + ChatId])
                            {
                                int TextId = int.Parse(Entry.text_id) - 1;
                                if (TextId >= 0)
                                {
                                    Chtx[TextId].Title          = Entry.texts.es[0].TrimEnd(' ', '\t', '\n', '\r', '.');
                                    Chtx[TextId].TextOriginal   = "";
                                    Chtx[TextId].TextTranslated = Entry.texts.es[1];
                                }
                            }
                        }
                        //ChtxStream.SetLength(0);
                        ChtxStream.Position = 0;
                        Chtx.Save(ChtxStream);
                    });
                    //Console.WriteLine("Done");
                });
            });
#endif
        }
Beispiel #4
0
        public void TranslateWithAcmeFileTest()
        {
            using (var AcmeStream = File.OpenRead(Utils.TestInputPath + @"\tov_skits.zip"))
                using (var ACME1 = new ACME1(AcmeStream, Encoding.GetEncoding("ISO-8859-1")))
                {
                    using (var InputStream = File.OpenRead(Utils.TestInputPath + @"\VC001US.TO8CHTX"))
                        using (var OutputStream = File.Open(Utils.TestOutputPath + @"\VC001ES.TO8CHTX", FileMode.Create))
                        {
                            var TO8CHTX = new TO8CHTX(InputStream);
                            TO8CHTX.TranslateWithAcmeFile(ACME1.Files["T3@VC001"]);
                            TO8CHTX.SaveTo(OutputStream);
                        }

                    using (var EnglishInputStream = File.OpenRead(Utils.TestInputPath + @"\VC001US.TO8CHTX"))
                        using (var SpanishInputStream = File.OpenRead(Utils.TestOutputPath + @"\VC001ES.TO8CHTX"))
                        {
                            var EnglishTO8CHTX = new TO8CHTX(EnglishInputStream);
                            var SpanishTO8CHTX = new TO8CHTX(SpanishInputStream);
                            //Console.WriteLine("------------------------------");
                            //ACME1.Files["T3@VC001"].Entries[0]
                            //Console.WriteLine(SpanishTO8CHTX.Entries[0].TextTranslated);

                            EnglishTO8CHTX.TranslateWithAcmeFile(ACME1.Files["T3@VC001"]);

                            for (int n = 0; n < EnglishTO8CHTX.Length; n++)
                            {
                                var EnglishEntry = EnglishTO8CHTX.Entries[n];
                                var SpanishEntry = SpanishTO8CHTX.Entries[n];
                                Assert.AreEqual(EnglishEntry.Title, SpanishEntry.Title);
                                Assert.AreEqual(EnglishEntry.Talker, SpanishEntry.Talker);
                                Assert.AreEqual(EnglishEntry.TextTranslated, SpanishEntry.TextTranslated);
                                Assert.AreEqual(EnglishEntry.TextOriginal, SpanishEntry.TextOriginal);
                            }
                        }
                }
        }
Beispiel #5
0
        protected void HandleEntry(Regex SelectAll, Func <String, String, String> ReplaceSuffixName, FPS4.Entry EnglishEntry)
        {
            //Console.WriteLine(Thread.CurrentThread.ManagedThreadId);
            using (EnglishEntry)
            {
                //Console.WriteLine("[1]");
                var BaseName    = SelectAll.Match(EnglishEntry.Name).Groups[1].Value;
                var SpanishName = ReplaceSuffixName(EnglishEntry.Name, "ES");
                Console.WriteLine("{0} : {1}", SpanishName, Thread.CurrentThread.ManagedThreadId);

                var ACMEFiles = ACME1.FilesByIndex.Where(Item => Item.Name.Contains(BaseName));
                if (ACMEFiles.Count() == 1)
                {
                    //Console.WriteLine("[2]");

                    var EsTempFile = TestOutputFolder + @"\" + SpanishName;

#if REUSE_PAK
                    if (!File.Exists(EsTempFile))
#endif
                    {
                        using (var CompressedSkitPAKStream = File.Open(EsTempFile, FileMode.Create))
                        {
                            //Console.WriteLine("[3]");
                            var ACMEFile = ACMEFiles.ElementAt(0);
                            //Console.WriteLine(SpanishName);
                            using (var SkitPAK = new FPS4(TalesCompression.DecompressStream(EnglishEntry.Open())))
                                using (var chtx = new TO8CHTX(SkitPAK[3].Open()))
                                {
                                    //Console.WriteLine("[4]");
                                    try
                                    {
                                        chtx.TranslateWithAcmeFile(ACMEFile);
                                    }
                                    catch (Exception Exception)
                                    {
                                        Console.Error.WriteLine(Exception);
                                        Console.ReadKey();
                                    }

                                    //Console.WriteLine("[5]");
                                    using (var NewChtxStream = new MemoryStream())
                                        using (var SkitPAKStream = new MemoryStream())
                                        {
                                            chtx.Save(NewChtxStream);
                                            SkitPAK[3].SetStream(NewChtxStream);

                                            //Console.WriteLine("[6]");
                                            SkitPAK.Save(SkitPAKStream);

                                            TalesCompression.EncodeFile(SkitPAKStream, CompressedSkitPAKStream);
                                        }
                                }
                        }
                    }
                    var SpanishEntry = PAK.CreateEntry(SpanishName, File.Open(EsTempFile, FileMode.Open));
                }
                else
                {
                    Console.WriteLine("WARNING. Untranslated Skit: ACMEFiles.Count() : {0} : {1}", ACMEFiles.Count(), BaseName);
                    var SpanishEntry = PAK.CreateEntry(SpanishName, EnglishEntry.Open());
                }
            }
        }
Beispiel #6
0
        protected void Expand(string FilePath)
        {
            if (FilePath.Contains('*') || FilePath.Contains('?'))
            {
                var BasePath  = Path.GetDirectoryName(FilePath);
                var Recursive = false;
                if (BasePath == "")
                {
                    BasePath = ".";
                }
                foreach (var FileName in Directory.EnumerateFiles(BasePath, Path.GetFileName(FilePath), Recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly))
                {
                    Expand(FileName);
                }
                return;
            }


            var ListToExpand = new List <string>();

            //Console.WriteLine("Expanding '{0}'...", FilePath);

            using (var _FileStream = File.OpenRead(FilePath))
            {
                if (_FileStream.Length == 0)
                {
                    //Console.WriteLine("EMPTY: {0}", FilePath);
                    return;
                }
                var FileStream = DecompressIfCompressedStream(_FileStream);
                var MagicData  = FileStream.Slice().ReadBytesUpTo(0x100);

                if (false)
                {
                }
                else if (TO8SCEL.IsValid(MagicData))
                {
                    try
                    {
                        var To8Scel = new TO8SCEL(FileStream);
                        foreach (var Entry in To8Scel)
                        {
                            var EntryFilePath = FilePath + ".d/" + Entry.Index;
                            if (Overwrite || !File.Exists(EntryFilePath))
                            {
                                Console.WriteLine("{0}", EntryFilePath);
                                try
                                {
                                    var EntryStream = DecompressIfCompressedStream(Entry.CompressedStream);
                                    if (EntryStream.Length > 0)
                                    {
                                        EntryStream.CopyToFile(EntryFilePath);
                                    }
                                }
                                catch (Exception Exception)
                                {
                                    ShowException(Exception);
                                }
                            }
                            if (File.Exists(EntryFilePath))
                            {
                                ListToExpand.Add(EntryFilePath);
                            }
                        }
                    }
                    catch (Exception Exception)
                    {
                        ShowException(Exception);
                    }
                }
                else if (FPS4.IsValid(MagicData))
                {
                    //Console.WriteLine("FPS4");
                    try
                    {
                        var Fps4 = new FPS4(FileStream);
                        foreach (var Entry in Fps4)
                        {
                            var EntryFilePath = FilePath + ".d/" + Entry.Name;
                            if (Overwrite || !File.Exists(EntryFilePath))
                            {
                                Console.WriteLine("{0}", EntryFilePath);
                                try
                                {
                                    var EntryStream = DecompressIfCompressedStream(Entry.Open());
                                    if (EntryStream.Length > 0)
                                    {
                                        EntryStream.CopyToFile(EntryFilePath);
                                    }
                                }
                                catch (Exception Exception)
                                {
                                    ShowException(Exception);
                                }
                            }
                            if (File.Exists(EntryFilePath))
                            {
                                ListToExpand.Add(EntryFilePath);
                            }
                        }
                    }
                    catch (Exception Exception)
                    {
                        ShowException(Exception);
                    }
                }
                else if (TSS.IsValid(MagicData))
                {
                    int RoomId = 0;
                    try { RoomId = int.Parse(Path.GetFileNameWithoutExtension(FilePath)); }
                    catch { }
                    var TxtFile = FilePath + ".txt";

                    Console.WriteLine("{0}", TxtFile);
                    if (Overwrite || !File.Exists(TxtFile))
                    {
                        var Tss = new TSS().Load(FileStream.Slice());

                        using (var TxtStream = File.Open(TxtFile, FileMode.Create, FileAccess.Write))
                            using (var TextWriter = new StreamWriter(TxtStream))
                            {
                                try
                                {
                                    Tss.DumpTexts(TextWriter);
                                }
                                catch (Exception Exception)
                                {
                                    ShowException(Exception);
                                }
                            }
                    }

                    var ScrFile = FilePath + ".scr";
                    Console.WriteLine("{0}", ScrFile);
                    if (Overwrite || !File.Exists(ScrFile))
                    {
                        var Tss = new TSS().Load(FileStream.Slice());

                        using (var TxtStream = File.Open(ScrFile, FileMode.Create, FileAccess.Write))
                            using (var TextWriter = new StreamWriter(TxtStream))
                            {
                                try
                                {
                                    var ErrorString = ConsoleUtils.CaptureError(() => {
                                        Tss.DumpScript(TextWriter);
                                    });
                                }
                                catch (Exception Exception)
                                {
                                    ShowException(Exception);
                                }
                            }
                    }
                }
                else if (TO8CHTX.IsValid(MagicData))
                {
                    var Chtx    = new TO8CHTX(FileStream);
                    var TxtFile = FilePath + ".txt";
                    Console.WriteLine("{0}", TxtFile);
                    if (Overwrite || !File.Exists(TxtFile))
                    {
                        using (var TxtStream = File.Open(TxtFile, FileMode.Create, FileAccess.Write))
                            using (var TextWriter = new StreamWriter(TxtStream))
                            {
                                foreach (var Entry in Chtx.Entries)
                                {
                                    TextWriter.WriteLine("{0}", Entry.Title);
                                    TextWriter.WriteLine("{0}", Entry.TextOriginal);
                                    TextWriter.WriteLine("{0}", Entry.TextTranslated);
                                    TextWriter.WriteLine("");
                                }
                            }
                        //Chtx.Entries[0].Title
                        //Console.WriteLine("CHAT!");
                    }
                }
                else if (SE3.IsValid(MagicData))
                {
                    var Se3 = new SE3().Load(FileStream);
                    foreach (var Entry in Se3.Entries)
                    {
                        var EntryFullNameXma = FilePath + "." + Entry.Name + ".xma";
                        var EntryFullNameWav = FilePath + "." + Entry.Name + ".wav";
                        Console.WriteLine("{0}", EntryFullNameXma);
                        if (Overwrite || !File.Exists(EntryFullNameXma))
                        {
                            Entry.ToXmaWav().CopyToFile(EntryFullNameXma);
                        }
                        if (Overwrite || !File.Exists(EntryFullNameWav))
                        {
                            using (var WavOut = File.Open(EntryFullNameWav, FileMode.Create, FileAccess.Write))
                            {
                                Entry.ToWav(WavOut);
                            }
                        }
                    }
                }
                else if (TXM.IsValid(MagicData))
                {
                    string BasePath;
                    string TxmPath;
                    string TxvPath;

                    if (Path.GetExtension(FilePath).ToLower() == ".txm")
                    {
                        BasePath = Path.GetDirectoryName(FilePath) + "/" + Path.GetFileNameWithoutExtension(FilePath);
                        TxmPath  = BasePath + ".txm";
                        TxvPath  = BasePath + ".txv";
                    }
                    else
                    {
                        var DirectoryPath = Path.GetDirectoryName(FilePath);
                        TxmPath  = DirectoryPath + "/" + Path.GetFileName(FilePath);
                        TxvPath  = DirectoryPath + "/" + (int.Parse(Path.GetFileName(TxmPath)) + 1);
                        BasePath = TxmPath;
                    }

                    var Txm = TXM.FromTxmTxv(File.OpenRead(TxmPath), File.OpenRead(TxvPath));

                    /*
                     * if (Txm.Surface2DEntries.Length > 0 && Txm.Surface3DEntries.Length > 0)
                     * {
                     *      // 3D and 2D surfaces
                     *      //Console.WriteLine("ERROR 3D and 2D SURFACES! (2D: {0}, 3D: {1})", Txm.Surface2DEntries.Length, Txm.Surface3DEntries.Length);
                     * }
                     * else if (Txm.Surface2DEntries.Length > 0)
                     * {
                     *      // 2D Surfaces
                     *      //Console.WriteLine("2D SURFACES! {0}", Txm.Surface2DEntries.Length);
                     * }
                     * else if (Txm.Surface3DEntries.Length > 0)
                     * {
                     *      // 3D Surfaces
                     *      //Console.WriteLine("3D SURFACES! {0}", Txm.Surface3DEntries.Length);
                     * }
                     */

                    foreach (var Entry in Txm.Surface2DEntries)
                    {
                        var ImagePath = BasePath + "." + Entry.Name + ".png";
                        if (Overwrite || !File.Exists(ImagePath))
                        {
                            try
                            {
                                Entry.Bitmap.Save(ImagePath);
                            }
                            catch (Exception Exception)
                            {
                                ShowException(Exception);
                            }
                        }
                    }

                    foreach (var Entry in Txm.Surface3DEntries)
                    {
                        var ImagePath0 = BasePath + "." + Entry.Name + "." + 0 + ".png";
                        if (Overwrite || !File.Exists(ImagePath0))
                        {
                            try
                            {
                                var n = 0;
                                foreach (var Bitmap in Entry.Bitmaps.Bitmaps)
                                {
                                    var ImagePath = BasePath + "." + Entry.Name + "." + n + ".png";
                                    Console.WriteLine("{0}", ImagePath);
                                    if (Overwrite || !File.Exists(ImagePath))
                                    {
                                        Bitmap.Save(ImagePath);
                                    }
                                    n++;
                                }
                            }
                            catch (Exception Exception)
                            {
                                ShowException(Exception);
                            }
                        }
                    }
                }
                else
                {
                }
            }

            // Expand all the queued stuff
            foreach (var Item in ListToExpand)
            {
                try
                {
                    Expand(Item);
                }
                catch (Exception Exception)
                {
                    Console.WriteLine("  ERROR: {0}", Verbose ? Exception.ToString() : Exception.Message.ToString());
                }
            }
        }
Beispiel #7
0
        private void Handle1()
        {
            Patcher.TempFS.CreateDirectory("CHAT_ES", 0777, false);

            Patcher.Action("Translating Skits...", () =>
            {
                Patcher.ProgressHandler.AddProgressLevel("Traduciendo skits", OriginalChatSvo.Count(), () =>
                {
                    Patcher.ParallelForeach("Translating", OriginalChatSvo, (ChatSvoEntry) => ChatSvoEntry.Name, (ChatSvoEntry) =>
                    {
                        var Match = ChatSvoEntry.Name.RegexMatch(@"^(VC\d+B?)(UK)\.DAT$");
                        if (Match != null)
                        {
                            var CompleteFile = Match[0].Value;
                            var ChatId       = Match[1].Value;
                            var EsFile       = PreppendTempFile + ChatId + "ES.DAT";

                            Console.WriteLine("{0}...", ChatId);

                            if (!Patcher.TempFS.Exists(EsFile))
                            {
                                var Fps4 = new FPS4(TalesCompression.DecompressStream(OriginalChatSvo[CompleteFile].Open()));
                                {
                                    var Chtx = new TO8CHTX();
                                    Chtx.Load(Fps4["3"].Open());
                                    // Translate
                                    {
                                        foreach (var Entry in Patcher.EntriesByRoom["skits/" + ChatId].Values)
                                        {
                                            int TextId = int.Parse(Entry.text_id) - 1;
                                            if (TextId >= 0)
                                            {
                                                //Chtx[TextId].Title = "";
                                                //Chtx[TextId].Title = TextProcessor.Instance.ProcessAndDetectPitfalls(Chtx[TextId].Title, Entry.texts.es[0].TrimEnd(' ', '\t', '\n', '\r', '.'));
                                                //Chtx[TextId].Title = TextProcessor.Instance.ProcessAndDetectPitfalls(Chtx[TextId].Title, Entry.texts.es[0]);
                                                Chtx[TextId].Title          = "";
                                                Chtx[TextId].TextOriginal   = "";
                                                Chtx[TextId].TextTranslated = TextProcessor.Instance.ProcessAndDetectPitfalls(Chtx[TextId].TextTranslated, Entry.texts.es[1]);
                                            }
                                        }
                                    }
                                    //ChtxStream.SetLength(0);
                                    var ChtxStream = new MemoryStream();
                                    Chtx.SaveTo(ChtxStream);
                                    ChtxStream.Position = 0;
                                    Fps4["3"].SetStream(ChtxStream);
                                }
                                Patcher.TempFS.WriteAllBytes(EsFile, TalesCompression.CreateFromVersion(Patcher.CompressionVersion, Patcher.CompressionFallback).EncodeBytes(Fps4.Save(false).ToArray()));
                                Console.WriteLine("{0}...Ok", ChatId);
                            }
                            else
                            {
                                Console.WriteLine("{0}...Exists", ChatId);
                            }
                        }

                        Patcher.ProgressHandler.IncrementLevelProgress();
                    });
                });
            });
        }