/// <summary> /// Parses the .dat file contents from inStream. /// </summary> /// <param name="inStream">Unicode binary reader containing ONLY the contents of a single .dat file and nothing more</param> /// <param name="fileName">Name of the dat file (with extension)</param> public DatContainer(Stream inStream, string fileName) { datName = Path.GetFileNameWithoutExtension(fileName); DatType = DatFactory.GetTypeName(datName); using (BinaryReader br = new BinaryReader(inStream, Encoding.Unicode)) { Read(br); } }
/// <summary> /// Parses the .dat file found at path 'fileName' /// </summary> /// <param name="fileName">Path of .dat file to parse</param> public DatContainer(string fileName) { this.datName = Path.GetFileNameWithoutExtension(fileName); DatType = DatFactory.GetTypeName(datName); byte[] fileBytes = File.ReadAllBytes(fileName); using (MemoryStream ms = new MemoryStream(fileBytes)) { using (BinaryReader br = new BinaryReader(ms, System.Text.Encoding.Unicode)) { Read(br); } } }
/// <summary> /// Reads the .dat frile from the specified stream /// </summary> /// <param name="inStream">Stream containing contents of .dat file</param> private void Read(BinaryReader inStream) { numberOfEntries = inStream.ReadInt32(); if (inStream.ReadUInt64() == 0xBBbbBBbbBBbbBBbb) { Entries = new List <BaseDat>(); return; } inStream.BaseStream.Seek(-8, SeekOrigin.Current); Entries = new List <BaseDat>(numberOfEntries); if (DatType == null) { throw new Exception("Missing dat parser for type " + datName); } for (uint i = 0; i < numberOfEntries; i++) { BaseDat bd = DatFactory.Create(datName, inStream); bd.Key = i; Entries.Add(bd); } if (inStream.ReadUInt64() != 0xBBbbBBbbBBbbBBbb) { throw new ApplicationException("Missing magic number after records"); } DataTableBegin = inStream.BaseStream.Position - 8; inStream.BaseStream.Seek(-8, SeekOrigin.Current); originalDataTable = inStream.ReadBytes((int)(inStream.BaseStream.Length - inStream.BaseStream.Position)); for (int i = 0; i < numberOfEntries; i++) { if (i == numberOfEntries - 1) { } Entries[i].ReadResources(inStream, DataTableBegin); } // Read all referenced string and data entries from the data following the entries (starting at magic number) foreach (var item in Entries) { AddDataToTable(item, inStream); } }