public static MapPosArrNamFiles ReadFiles(string arrPath, string namPath)
        {
            MapPosArrNamFiles arrNamFile = new MapPosArrNamFiles();

            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 = 0; i < arrReader.BaseStream.Length; i += 0x6)
                {
                    arrNamFile.Blocks.Add(arrReader.ReadBytes(0x4));

                    ushort pointer = arrReader.ReadUInt16();
                    arrNamFile.Pointers.Add(pointer);
                }
            }

            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);
        }
        public static MapPosArrNamFiles 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);
            }

            MapPosArrNamFiles arrNamFile = new MapPosArrNamFiles();

            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);
        }
Exemplo n.º 3
0
        private static void UnpackMapPosArrNamFiles()
        {
            Console.Clear();
            Console.Write("Insert path of map_pos .arr and .nam files (without filenames): ");
            string arrPath = Console.ReadLine();

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

            arrPath += "\\map_pos.arr";
            MapPosArrNamFiles.ReadFiles(arrPath, namPath).Extract();
        }
Exemplo n.º 4
0
        private static void RepackMapPosArrNamFiles()
        {
            Console.Clear();
            Console.Write("Insert path of map_pos .data and .text files (without filenames): ");
            string textPath = Console.ReadLine();

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

            textPath += "\\map_pos.text";
            MapPosArrNamFiles.ReadDataTextFiles(dataPath, textPath).WriteArrNamFiles();
        }