Exemple #1
0
        public static MapInfoArrNamFiles ReadDataTextFiles(string dataPath, string textPath)
        {
            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);
            }

            MapInfoArrNamFiles arrNamFile = new MapInfoArrNamFiles();

            using (BinaryReader dataReader = new BinaryReader(File.Open(dataPath, FileMode.Open)))
            {
                while (dataReader.BaseStream.Position < dataReader.BaseStream.Length)
                {
                    byte length = dataReader.ReadByte();
                    arrNamFile.Blocks.Add(dataReader.ReadBytes(length));
                }
            }

            using (BinaryReader textReader = new BinaryReader(File.Open(textPath, FileMode.Open), Encoding.Default))
            {
                char[] chars = textReader.ReadChars((int)textReader.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;
                foreach (var txt in texts)
                {
                    if (txt == "<ENDBLOCK>")
                    {
                        arrNamFile.Pointers.Add(0);
                    }
                    else if (Regex.IsMatch(txt, "<\\d+>"))
                    {
                        var index = ushort.Parse(txt.Replace("<", "").Replace(">", ""));
                        arrNamFile.Pointers.Add(arrNamFile.Pointers[index + 1]);
                    }
                    else
                    {
                        arrNamFile.Pointers.Add(length);
                        arrNamFile.Texts.Add(txt.ToCharArray().Concat(new char[] { '\0' }).ToArray());
                        length += (ushort)(txt.Length + 1);
                    }
                }
            }
            arrNamFile.Path = textPath;
            return(arrNamFile);
        }
Exemple #2
0
        private static void UnpackMapInfoArrNamFiles()
        {
            Console.Clear();
            Console.Write("Insert path of map_info .arr and .nam files (without filenames): ");
            string arrPath = Console.ReadLine();

            if (string.IsNullOrEmpty(arrPath))
            {
                arrPath = ".";
            }
            string namPath = arrPath + "\\map_info.nam";

            arrPath += "\\map_info.arr";
            MapInfoArrNamFiles.ReadFiles(arrPath, namPath).Extract();
        }
Exemple #3
0
        private static void RepackMapInfoArrNamFiles()
        {
            Console.Clear();
            Console.Write("Insert path of map_info .data and .text files (without filenames): ");
            string textPath = Console.ReadLine();

            if (string.IsNullOrEmpty(textPath))
            {
                textPath = ".";
            }
            string dataPath = textPath + "\\map_info.data";

            textPath += "\\map_info.text";
            MapInfoArrNamFiles.ReadDataTextFiles(dataPath, textPath).WriteArrNamFiles();
        }
Exemple #4
0
        public static MapInfoArrNamFiles ReadFiles(string arrPath, string namPath)
        {
            MapInfoArrNamFiles arrNamFile = new MapInfoArrNamFiles();

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

            using (BinaryReader arrReader = new BinaryReader(File.Open(arrPath, FileMode.Open)))
            {
                for (int i = 0x6; i < arrReader.BaseStream.Length; i += 0x26)
                {
                    for (int j = 0; j < 0xE / 2; j++)
                    {
                        ushort p1 = arrReader.ReadUInt16();
                        arrNamFile.Pointers.Add(p1);
                    }
                    arrNamFile.Blocks.Add(arrReader.ReadBytes(0x6));

                    ushort p2 = arrReader.ReadUInt16();
                    arrNamFile.Pointers.Add(p2);
                    arrNamFile.Blocks.Add(arrReader.ReadBytes(0x10));
                }
            }

            using (BinaryReader namReader = new BinaryReader(File.Open(namPath, FileMode.Open), Encoding.Default))
            {
                arrNamFile.Texts.Add(new char[] { '\0' });
                for (int i = 0; i < arrNamFile.Pointers.Count; i++)
                {
                    ushort      pointer   = arrNamFile.Pointers[i];
                    List <char> charArray = new List <char>();
                    int         p;
                    if (pointer == 0)
                    {
                        charArray.AddRange("<ENDBLOCK>".ToCharArray());
                    }
                    else if ((p = arrNamFile.Pointers.IndexOf(pointer)) < i)
                    {
                        charArray.AddRange(string.Format("<{0}>", p).ToCharArray());
                    }
                    else
                    {
                        namReader.BaseStream.Seek(pointer, SeekOrigin.Begin);
                        char c;
                        while ((c = namReader.ReadChar()) != '\0')
                        {
                            charArray.Add(c);
                        }
                    }
                    charArray.Add('\0');
                    arrNamFile.Texts.Add(charArray.ToArray());
                }
            }

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