private void InitializeWriter(Stream input, Stream output) { dataWriter = new BinaryWriter(output); infoWriter = new BspInfoWriter(dataWriter); reader = new BspReader(input); gatheredInfo = reader.ReadInfo(); }
public void Dispose() { dataWriter.Dispose(); infoWriter.Dispose(); reader.Dispose(); gatheredInfo = null; disposed = true; }
/// <summary> /// Reads BSP info from file /// </summary> public BspInfo ReadInfo() { ThrowExceptionIfDisposed(); if (cachedInfo == null) { cachedInfo = RefreshInfo(); } return(cachedInfo); }
/// <summary> /// Writes BspInfo (file header) to file /// </summary> public void WriteInfo(BspInfo i) { ThrowExceptionIfDisposed(); writer.BaseStream.Position = 0; writer.Write(i.Identifier); writer.Write(i.Version); foreach (BspLumpInfo l in i.Lumps) { WriteBspLumpInfo(l); } writer.Write(i.MapRevision); }
private BspInfo RefreshInfo() { BspInfo info = new BspInfo(); if (reader.BaseStream.Length < 1036) { throw new FileFormatException(); } reader.BaseStream.Position = 0; //Read identifier info.Identifier = reader.ReadInt32(); //Validate identifier //Little-endian "VBSP" 0x50534256 if (info.Identifier != 0x50534256) { throw new FileFormatException(); } //Read version info.Version = reader.ReadInt32(); //Read game lumps info.Lumps = new BspLumpInfo[64]; for (int i = 0; i < 64; i++) { info.Lumps[i] = ReadLump(); } //Read map revision number info.MapRevision = reader.ReadInt32(); //Return value return(info); }
internal BspInfo Clone() { var clonedInfo = new BspInfo { Identifier = Identifier, Version = Version, Lumps = new BspLumpInfo[64], MapRevision = MapRevision }; for (int i = 0; i < 64; i++) { var oldLump = Lumps[i]; clonedInfo.Lumps[i] = new BspLumpInfo() { FileLength = oldLump.FileLength, FileOffset = oldLump.FileOffset, fourCC = oldLump.fourCC, Version = oldLump.Version }; } return(clonedInfo); }