Example #1
0
        public void Extract()
        {
            string path     = Path.Replace(".arr", ".text"),
                   dataPath = Path.Replace(".arr", ".data");

            using (BinaryWriter writer = new BinaryWriter(File.Create(path), EncodingExtension.GetUTF8WithoutBOM()))
            {
                foreach (var text in Texts)
                {
                    var aux1 = new string(text);
                    aux1 = aux1.Replace("\0", "\n<end>\n") + '\n';
                    var aux2 = aux1.ToCharArray();
                    writer.Write(aux2, 0, aux2.Length);
                }
            }

            using (BinaryWriter writer = new BinaryWriter(File.Create(dataPath)))
            {
                foreach (var block in Blocks)
                {
                    writer.Write((byte)block.Length);
                    writer.Write(block, 0, block.Length);
                }
            }
        }
Example #2
0
        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);
        }
        public static SysmsgArrNamFiles ReadTextFile(string path)
        {
            SysmsgArrNamFiles arrNamFile = new SysmsgArrNamFiles();

            if (!File.Exists(path))
            {
                Console.WriteLine("The file {0} not exists.", path);
                return(null);
            }

            using (BinaryReader reader = new BinaryReader(File.Open(path, FileMode.Open), EncodingExtension.GetUTF8WithoutBOM()))
            {
                char[] chars = reader.ReadChars((int)reader.BaseStream.Length);
                string text  = new string(chars);//.ReplaceSpanishChars();
                var    texts = text.Split(new string[] { "\n<end>\n\n" }, StringSplitOptions.None).Reverse()
                               .Skip(1).Reverse().ToArray();

                ushort length = 0;
                arrNamFile.Texts.Add(texts[0].ToCharArray().Concat(new char[] { '\0' }).ToArray());
                length += (ushort)(texts[0].Length + texts[0].Count(c => c == 'ñ' || c == 'á' || c == 'é' || c == 'í' || c == 'ó' || c == 'ú' || c == 'Ñ' || c == 'Á' || c == 'É' || c == 'Í' || c == 'Ó' || c == 'Ú' || c == '¿' || c == '¡') + 1);
                foreach (var txt in texts.Skip(1))
                {
                    if (txt.Contains('<'))
                    {
                        if (Regex.IsMatch(txt, "<\\d+>"))
                        {
                            var index = ushort.Parse(txt.Replace("<", "").Replace(">", ""));
                            arrNamFile.Pointers.Add(arrNamFile.Pointers[index]);
                            //arrNamFile.Texts.Add(texts[index].ToCharArray().Concat(new char[] { '\0' }).ToArray());
                        }
                        else if (txt == "<ENDBLOCK>")
                        {
                            arrNamFile.Pointers.Add(0);
                        }
                    }
                    else
                    {
                        if (txt != texts.Last())
                        {
                            arrNamFile.Pointers.Add(length);
                        }
                        arrNamFile.Texts.Add(txt.ToCharArray().Concat(new char[] { '\0' }).ToArray());
                        length += (ushort)(txt.Length + txt.Count(c => c == 'ñ' || c == 'á' || c == 'é' || c == 'í' || c == 'ó' || c == 'ú' || c == 'Ñ' || c == 'Á' || c == 'É' || c == 'Í' || c == 'Ó' || c == 'Ú' || c == '¿' || c == '¡') + 1);
                    }
                }
                //var charArrays = texts.Select(s => s.ToCharArray().Concat(new char[] { '\0' }).ToArray())
                //    .ToArray();
            }

            arrNamFile.Path = path;
            return(arrNamFile);
        }