public static XPR Load(string path) { FileInfo fi = new FileInfo(path); Logger.LogToFile(Logger.LogLevel.Info, "{0}", path); XPR xpr = new XPR() { name = Path.GetFileNameWithoutExtension(path), location = Path.GetDirectoryName(path) + "\\" }; using (BinaryReader br = new BinaryReader(fi.OpenRead())) { if (br.ReadByte() != 0x58 || // X br.ReadByte() != 0x50 || // P br.ReadByte() != 0x52 || // R br.ReadByte() != 0x30) // 0 { Logger.LogToFile(Logger.LogLevel.Error, "{0} isn't a valid XPR file", path); return(null); } xpr.size = (int)br.ReadInt32(); xpr.dataOffset = (int)br.ReadInt32(); bool bLoop = true; while (bLoop) { RecordType type = (RecordType)br.ReadUInt32(); switch (type) { case RecordType.Texture: int offset = (int)br.ReadInt32(); br.ReadInt32(); // 0x0 int settings = (int)br.ReadInt32(); br.ReadInt32(); // 0x0 xpr.contents.Add( new XPREntry { Type = type, Name = offset.ToString("00000000"), Offset = xpr.dataOffset + offset, Flags = settings } ); break; case RecordType.Model: break; case RecordType.EOF: bLoop = false; break; default: throw new NotImplementedException(string.Format("Unknown type: {0}", type)); } } br.BaseStream.Seek(xpr.dataOffset, SeekOrigin.Begin); } return(xpr); }
public static XPR Load(string path) { FileInfo fi = new FileInfo(path); Logger.LogToFile(Logger.LogLevel.Info, "{0}", path); XPR xpr = new XPR(); xpr.name = Path.GetFileNameWithoutExtension(path); xpr.location = Path.GetDirectoryName(path) + "\\"; using (var br = new BinaryReader(fi.OpenRead())) { if (br.ReadByte() != 0x58 || // X br.ReadByte() != 0x50 || // P br.ReadByte() != 0x52 || // R br.ReadByte() != 0x30) // 0 { Logger.LogToFile(Logger.LogLevel.Error, "{0} isn't a valid XPR file", path); return null; } xpr.size = (int)br.ReadInt32(); xpr.dataOffset = (int)br.ReadInt32(); bool bLoop = true; while (bLoop) { RecordType type = (RecordType)br.ReadUInt32(); switch (type) { case RecordType.Texture: int offset = (int)br.ReadInt32(); br.ReadInt32(); // 0x0 int settings = (int)br.ReadInt32(); br.ReadInt32(); // 0x0 xpr.contents.Add( new XPREntry { Type = type, Name = offset.ToString("00000000"), Offset = xpr.dataOffset + offset, Flags = settings } ); break; case RecordType.Model: break; case RecordType.EOF: bLoop = false; break; default: throw new NotImplementedException(string.Format("Unknown type: {0}", type)); } } br.BaseStream.Seek(xpr.dataOffset, SeekOrigin.Begin); } return xpr; }