public static FormationInitArrNamFiles ReadFiles(string arrPath, string namPath) { FormationInitArrNamFiles arrNamFile = new FormationInitArrNamFiles(); 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) { byte pointer = arrReader.ReadByte(); arrNamFile.Pointers.Add(pointer); arrNamFile.Blocks.Add(arrReader.ReadBytes(0x5)); } } 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++) { byte 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 FormationInitArrNamFiles 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); } FormationInitArrNamFiles arrNamFile = new FormationInitArrNamFiles(); 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(); byte 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 += (byte)(txt.Length + 1); } } } arrNamFile.Path = textPath; return(arrNamFile); }
private static void UnpackFormationInitArrNamFiles() { Console.Clear(); Console.Write("Insert path of formation_init .arr and .nam files (without filenames): "); string arrPath = Console.ReadLine(); if (string.IsNullOrEmpty(arrPath)) { arrPath = "."; } string namPath = arrPath + "\\formation_init.nam"; arrPath += "\\formation_init.arr"; FormationInitArrNamFiles.ReadFiles(arrPath, namPath).Extract(); }
private static void RepackFormationInitArrNamFiles() { Console.Clear(); Console.Write("Insert path of formation_init .data and .text files (without filenames): "); string textPath = Console.ReadLine(); if (string.IsNullOrEmpty(textPath)) { textPath = "."; } string dataPath = textPath + "\\formation_init.data"; textPath += "\\formation_init.text"; FormationInitArrNamFiles.ReadDataTextFiles(dataPath, textPath).WriteArrNamFiles(); }