public static ArtsdataArrNamFiles 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); } ArtsdataArrNamFiles arrNamFile = new ArtsdataArrNamFiles(); 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); }
private static void UnpackArtsdataArrNamFiles() { Console.Clear(); Console.Write("Insert path of itemlist .arr and .nam files (without filenames): "); string arrPath = Console.ReadLine(); if (string.IsNullOrEmpty(arrPath)) { arrPath = "."; } string namPath = arrPath + "\\arts_data.nam"; arrPath += "\\arts_data.arr"; ArtsdataArrNamFiles.ReadFiles(arrPath, namPath).Extract(); }
private static void RepackArtsdataArrNamFiles() { Console.Clear(); Console.Write("Insert path of itemlist .data and .text files (without filenames): "); string textPath = Console.ReadLine(); if (string.IsNullOrEmpty(textPath)) { textPath = "."; } string dataPath = textPath + "\\arts_data.data"; textPath += "\\arts_data.text"; ArtsdataArrNamFiles.ReadDataTextFiles(dataPath, textPath).WriteArrNamFiles(); }
public static ArtsdataArrNamFiles ReadFiles(string arrPath, string namPath) { ArtsdataArrNamFiles arrNamFile = new ArtsdataArrNamFiles(); 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 += 0x28) { arrNamFile.Blocks.Add(arrReader.ReadBytes(0x4)); ushort pointer = arrReader.ReadUInt16(); arrNamFile.Pointers.Add(pointer); arrNamFile.Blocks.Add(arrReader.ReadBytes(0x20)); 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); }