Exemple #1
0
        private static void UnpackMsgFile()
        {
            Console.Clear();
            Console.Write("Insert path of .msg file: ");
            string path = Console.ReadLine();

            MSGFile.ReadMSGFile(path).Unpack();
        }
 public static void WriteNPCT(this MSGFile file, BinaryWriter dataWriter)
 {
     if (file.HasNPCT)
     {
         dataWriter.Write(file.NPCT);
         dataWriter.Write(file.NPCT_BlockSize);
         dataWriter.Write(file.NPCT_Bytes, 0, file.NPCT_Bytes.Length);
     }
 }
Exemple #3
0
        private static void UnpackAllMsgFiles()
        {
            Console.Clear();
            var files = Directory.EnumerateFiles(".", "*.msg", SearchOption.AllDirectories);

            foreach (var file in files)
            {
                MSGFile.ReadMSGFile(file).Unpack();
                Console.WriteLine("{0} file unpacked", file);
            }
        }
Exemple #4
0
        private static void RepackMsgFile()
        {
            Console.Clear();
            Console.Write("Insert path of .data and .text (without file extension): ");
            string dataPath = Console.ReadLine();
            //Console.Write("Insert path of .text: ");
            //string textPath = Console.ReadLine();
            string textPath = dataPath + ".text";

            dataPath += ".data";
            MSGFile.ReadRepackFiles(dataPath, textPath).Repack();
        }
 public static bool ReadNAME(this MSGFile file, BinaryReader reader)
 {
     if (reader.BaseStream.Position == reader.BaseStream.Length)
     {
         return(false);
     }
     file.NAME = reader.ReadInt32();
     if (file.NAME != MSGFile.NAMEVALUE)
     {
         reader.BaseStream.Seek(-4, SeekOrigin.Current);
         return(false);
     }
     file.NAME_BlockSize = reader.ReadInt32();
     file.NAME_Bytes     = reader.ReadBytes(file.NAME_BlockSize);
     return(true);
 }
 public static void WriteTCRC(this MSGFile file, BinaryWriter dataWriter)
 {
     if (file.HasTCRC)
     {
         dataWriter.Write(file.TCRC);
         dataWriter.Write(file.TCRC_BlockSize);
         foreach (var value in file.CRCs.Values.OrderBy(o => o.Checksum))
         {
             if (value.Checksum == MSGFile.TEXTVALUE)
             {
                 continue;
             }
             dataWriter.Write(value.Checksum);
             dataWriter.Write(value.Pointer);
         }
         //dataWriter.Write(file.TEXT);
         //dataWriter.Write(file.TEXT_BlockSize);
     }
 }
Exemple #7
0
        private static void RepackAllMsgFiles()
        {
            Console.Clear();
            var files = Directory.EnumerateFiles(".", "*.text", SearchOption.AllDirectories);

            foreach (var file in files)
            {
                string textPath   = file,
                         dataPath = file.Replace(".text", ".data");
                Console.WriteLine($"[{textPath}]");
                try
                {
                    MSGFile.ReadRepackFiles(dataPath, textPath).Repack();
                    Console.WriteLine("{0} file repacked!", textPath);
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Error ocurred in file {textPath}: {e.Message}");
                }
                Console.WriteLine("");
            }
        }
 public static bool ReadTCRC(this MSGFile file, BinaryReader reader)
 {
     if (reader.BaseStream.Position == reader.BaseStream.Length)
     {
         return(false);
     }
     file.TCRC = reader.ReadInt32();
     if (file.TCRC != MSGFile.TCRCVALUE)
     {
         reader.BaseStream.Seek(-4, SeekOrigin.Current);
         return(false);
     }
     file.TCRC_BlockSize = reader.ReadInt32();
     for (int i = 0; i < file.TCRC_BlockSize / 8; i++)
     {
         uint checksum = reader.ReadUInt32();
         int  pointer  = reader.ReadInt32();
         file.CRCs.Add(pointer + 16 + file.TCRC_BlockSize, new TLOL_Extractor.MSGFile.CRC()
         {
             Checksum = checksum, Pointer = pointer
         });
     }
     return(true);
 }
        public static MSGFile ReadMSGFile(string path)
        {
            if (!File.Exists(path))
            {
                Console.WriteLine("The file {0} not exists.", path);
                return(null);
            }

            var msgFile = new MSGFile();

            BinaryReader reader = new BinaryReader(File.Open(path, FileMode.Open));

            /************ READ TCTC ************/
            msgFile.HasTCRC = msgFile.ReadTCRC(reader);

            /************ READ TEXT ************/
            if (msgFile.HasTCRC)
            {
                msgFile.TEXT           = reader.ReadInt32();
                msgFile.TEXT_BlockSize = reader.ReadInt32();
                msgFile.CRCs.Add(16 + msgFile.TCRC_BlockSize + msgFile.TEXT_BlockSize,
                                 new CRC()
                {
                    Checksum = (uint)msgFile.TEXT,
                    Pointer  = msgFile.TEXT_BlockSize
                });

                msgFile.Texts = new Dictionary <int, char[]>();
                int lastOffset = -1;
                foreach (var pointer in msgFile.CRCs.Keys.OrderBy(o => o))
                {
                    if (lastOffset == -1)
                    {
                        lastOffset = pointer;
                        continue;
                    }
                    reader.BaseStream.Seek(lastOffset, SeekOrigin.Begin);
                    // 15-03-16
                    //char[] text = reader.ReadChars(pointer - lastOffset);
                    List <char> characters = new List <char>();
                    int         n          = 0;
                    while (n < 2)
                    {
                        char c = reader.ReadChar();
                        if (c == '\0')
                        {
                            characters.Add(c);
                            n++;
                            continue;
                        }
                        n = 0;
                        characters.Add(c);
                    }
                    char[] text = characters.ToArray();
                    // FIN 15-03-16
                    lastOffset = pointer;
                    msgFile.Texts.Add(lastOffset, text);
                }
                msgFile.HasTEXT = true;
            }

            /************ READ NPCT ************/
            msgFile.HasNPCT = msgFile.ReadNPCT(reader);

            /************ READ NAME ************/
            msgFile.HasNAME = msgFile.ReadNAME(reader);

            reader.Close();

            msgFile.Path = path;
            return(msgFile);
        }
        public static MSGFile ReadRepackFiles(string dataPath, string textPath)
        {
            Console.WriteLine($"Repack {textPath}> Checking .text and .data files...");
            if (!File.Exists(dataPath))
            {
                Console.WriteLine("The file {0} not exists.", dataPath);
                return(null);
            }
            if (!File.Exists(textPath))
            {
                Console.WriteLine("The file {0} not exists.", textPath);
                return(null);
            }

            MSGFile msgFile = new MSGFile();

            /************ READ TCRC ************/
            Console.WriteLine($"Repack {textPath}> Reading TCRC block...");
            BinaryReader reader = new BinaryReader(File.Open(dataPath, FileMode.Open));

            msgFile.HasTCRC = msgFile.ReadTCRC(reader);

            /************ READ TEXT ************/
            Console.WriteLine($"Repack {textPath}> Reading TEXT block...");
            if (msgFile.HasTCRC)
            {
                msgFile.TEXT = TEXTVALUE;
                // JRH 2018-08-17
                //BinaryReader textReader = new BinaryReader(File.Open(textPath, FileMode.Open), Encoding.Default);
                BinaryReader textReader = new BinaryReader(File.Open(textPath, FileMode.Open), EncodingExtension.GetUTF8WithoutBOM());
                // FIN JRH
                char[] chars      = textReader.ReadChars((int)textReader.BaseStream.Length);
                string text       = new string(chars);
                var    texts      = text.Split(new string[] { "\n<end>\n\n<end>\n\n" }, StringSplitOptions.None);
                var    charArrays = texts.Select(s => s.Replace("\n<end>\n", "\0").ToCharArray().Concat(new char[] { '\0', '\0' }).ToArray())
                                    .ToArray();

                msgFile.Texts = new Dictionary <int, char[]>();
                CRC[] oldPointers = msgFile.CRCs.OrderBy(o => o.Key).Select(s => s.Value).ToArray();
                msgFile.CRCs.Clear();
                // JRH 2018-08-17
                int newPointers = charArrays.Length - 1;
                if (oldPointers.Length != newPointers)
                {
                    Console.WriteLine($"\tPointer's quanity has changed from {oldPointers.Length} to {newPointers}.");
                }
                msgFile.TCRC_BlockSize = newPointers * 8;
                // FIN JRH
                int n = 0;
                for (int i = 0; i < newPointers; i++)
                {
                    var txt = charArrays[i];
                    int key = n + 16 + msgFile.TCRC_BlockSize;
                    msgFile.Texts.Add(key, txt);
                    msgFile.CRCs.Add(key, new CRC()
                    {
                        Checksum = oldPointers[i].Checksum,
                        Pointer  = n
                    });
                    // JRH 2018-08-17
                    //n += txt.Length;
                    n += txt.Length + txt.Count(c => c == 'ñ' || c == 'á' || c == 'é' || c == 'í' || c == 'ó' || c == 'ú' || c == 'Ñ' || c == 'Á' || c == 'É' || c == 'Í' || c == 'Ó' || c == 'Ú' || c == '¿' || c == '¡');
                    // FIN JRH
                }
                msgFile.TEXT_BlockSize = n;
                textReader.Close();
                msgFile.HasTEXT = true;
            }

            /************ READ NPCT ************/
            Console.WriteLine($"Repack {textPath}> Reading NPCT block...");
            msgFile.HasNPCT = msgFile.ReadNPCT(reader);

            /************ READ NAME ************/
            Console.WriteLine($"Repack {textPath}> Reading NAME block...");
            msgFile.HasNAME = msgFile.ReadNAME(reader);
            reader.Close();

            msgFile.Path = textPath.Replace(".text", ".msg");
            return(msgFile);
        }