예제 #1
0
        protected void ExtractSvo(string SvoPath)
        {
            //try
            //{
            using (var _SvoStream = File.OpenRead(SvoPath))
            {
                Stream SvoStream  = _SvoStream;
                int    Compressed = TalesCompression.DetectVersion(SvoStream.Slice().ReadBytes(16), SvoStream.Length);
                if (Compressed >= 0)
                {
                    SvoStream = TalesCompression.DecompressStream(SvoStream);
                }

                if (SvoStream.SliceWithLength().ReadString(7) == "TO8SCEL")
                {
                    var TO8SCEL = new TO8SCEL(SvoStream);

                    foreach (var Entry in TO8SCEL)
                    {
                        Console.WriteLine("{0} ... Start: {1}, End: {2}, Length: {3}", Entry.Index, Entry.EntryStruct.Offset, Entry.EntryStruct.Offset + Entry.EntryStruct.LengthCompressed, Entry.EntryStruct.LengthCompressed);
                    }
                }
                else
                {
                    var FPS4 = new FPS4(SvoStream);

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

                    foreach (var Entry in FPS4)
                    {
                        Console.WriteLine("{0} ... Start: {1}, End: {2}, Length: {3}", Entry.Name, Entry.EntryStruct.Offset, Entry.EntryStruct.Offset + Entry.EntryStruct.LengthReal, Entry.EntryStruct.LengthReal);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="DatPath"></param>
        /// <param name="DavPath"></param>
        /// <param name="OutputDirectory"></param>
        protected void ExtractSvo2(string DatPath, string DavPath, string OutputDirectory = null)
        {
            if (DavPath == null)
            {
                DavPath = DatPath;
            }

            if (OutputDirectory == null)
            {
                OutputDirectory = DatPath + ".d";
            }

            Console.WriteLine("Loading {0}...", DatPath);
            //try
            //{
            using (var _Stream1 = File.OpenRead(DatPath))
                using (var Stream2 = File.OpenRead(DavPath))
                {
                    var Stream1 = (Stream)_Stream1;
                    try { Directory.CreateDirectory(OutputDirectory); }
                    catch { }

                    int Compressed = TalesCompression.DetectVersion(Stream1.Slice().ReadBytes(16), Stream1.Length);
                    if (Compressed >= 0)
                    {
                        Stream1 = TalesCompression.DecompressStream(Stream1);
                    }

                    if (Stream1.SliceWithLength().ReadString(7) == "TO8SCEL")
                    {
                        var TO8SCEL = new TO8SCEL(Stream1);

                        foreach (var Entry in TO8SCEL)
                        {
                            _ExtractFile(OutputDirectory + "/" + Entry.Index, () => Entry.UncompressedStream, (int)(uint)Entry.EntryStruct.Offset, (int)(uint)Entry.EntryStruct.LengthCompressed);
                        }
                    }
                    else
                    {
                        var FPS4 = new FPS4(Stream1, Stream2);

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

                        foreach (var Entry in FPS4)
                        {
                            _ExtractFile(OutputDirectory + "/" + Entry.Name, () => Entry.Open(), (int)(uint)Entry.EntryStruct.Offset, (int)(uint)Entry.EntryStruct.LengthReal);
                        }
                    }
                }
            //}
            //catch (Exception Exception)
            //{
            //	Console.Error.WriteLine("{0}", Exception);
            //}
        }
예제 #3
0
 public void DecompressStream()
 {
     using (var CompressedStream = File.OpenRead(Utils.TestInputPath + @"\textfile.txt.c1"))
         using (var UncompressedStream = TalesCompression.DecompressStream(CompressedStream))
             using (var OriginalStream = File.OpenRead(Utils.TestInputPath + @"\textfile.txt"))
             {
                 CollectionAssert.AreEqual(
                     OriginalStream.ReadAll(),
                     UncompressedStream.ReadAll()
                     );
             }
 }
예제 #4
0
파일: Program.cs 프로젝트: talestra/tov
        private Stream DecompressIfCompressedStream(Stream FileStream)
        {
            var MagicData = FileStream.Slice().ReadBytesUpTo(0x100);

            // Decompress if compressed
            try
            {
                if (TalesCompression.DetectVersion(MagicData, FileStream.Length) != -1)
                {
                    return(TalesCompression.DecompressStream(FileStream));
                }
            }
            catch
            {
            }

            return(FileStream);
        }
예제 #5
0
파일: BtlSvo.cs 프로젝트: talestra/tov
        public void HandleBattlePackDialogs(Stream OldStream, Stream NewStream)
        {
            FPS4 OldFps4;
            FPS4 NewFps4;

            OldFps4 = new FPS4(OldStream.Slice());
            NewFps4 = new FPS4(OldStream.Slice()); // Intended OldStream

            var TranslatedFiles = new ConcurrentDictionary <string, MemoryStream>();

            var Names = new[]
            {
                "BTL_EP_0070_010", "BTL_EP_030_040", "BTL_EP_030_080", "BTL_EP_0950_010",
                "BTL_EP_0960_020", "BTL_EP_1040_020", "BTL_EP_150_170", "BTL_EP_170_050",
                "BTL_EP_210_090", "BTL_EP_270_110", "BTL_EP_270_110_1", "BTL_EP_340_070",
                "BTL_EP_370_050", "BTL_EP_420_080", "BTL_EP_440_040", "BTL_EP_470_030",
                "BTL_EP_490_060_0", "BTL_EP_490_060_1", "BTL_EP_510_050", "BTL_EP_510_080",
                "BTL_EP_640_050", "BTL_EP_650_030", "BTL_EP_650_050", "BTL_LL_MONSTER",
                "MA_VAL_A_05",
            };

            Patcher.Action("Translating Battle Scripts", () =>
            {
                Patcher.ProgressHandler.AddProgressLevel("Traduciendo scripts de batalla...", Names.Length, () =>
                {
                    Patcher.ParallelForeach("Translating", Names, (Name) => Name, (Name) =>
                    {
                        using (var CompressedTssStream = OldFps4[Name].Open())
                        {
                            using (var TssStream = TalesCompression.DecompressStream(CompressedTssStream))
                            {
                                var TssName = Name;
                                var Tss     = new TSS().Load(TssStream);
                                Tss.TranslateTexts((Entry) =>
                                {
                                    //if (Entry == null) return;
                                    var TranslationEntry = Patcher.EntriesByRoom["battle/" + TssName][String.Format("{0:X8}", Entry.Id2)];

                                    int TextCount = Entry.Original.Length;

                                    Entry.TranslateWithTranslationEntry(TranslationEntry);

                                    //Console.WriteLine("{0} : {1}", Entry.Translated[1], TranslationEntry.texts.es[1]);
                                }, (String) =>
                                {
                                    return(null);
                                });

                                var TranslatedCompressedStream = TalesCompression.CreateFromVersion(Patcher.CompressionVersion, Patcher.CompressionFallback).EncodeFile(Tss.Save());

                                TranslatedFiles[Name] = TranslatedCompressedStream;
                            }
                        }
                        Patcher.ProgressHandler.IncrementLevelProgress();
                    });
                });
            });

            Patcher.Action("Reconstructing Battle Scripts Package", () =>
            {
                NewFps4.ClearAllEntries();
                foreach (var Entry in OldFps4.Entries.Values)
                {
                    var EntryName = Entry.Name;
                    if (TranslatedFiles.ContainsKey(EntryName))
                    {
                        NewFps4.CreateEntry(EntryName, TranslatedFiles[EntryName]);
                    }
                    else
                    {
                        NewFps4.CreateEntry(EntryName, Entry.Open());
                    }
                }

                NewFps4.SaveTo(NewStream, DoAlign: false);
            });
        }
예제 #6
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());
                }
            }
        }
예제 #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();
                    });
                });
            });
        }