/// <summary> /// Updates the lump data offsets in the lump headers. Must be called when any lump's data size has changed. /// </summary> private void UpdateLumpDataOffsets() { var pos = VBSPHeaderSize; foreach (var lump in Lumps.OrderBy(lump => lump.DataOrder)) { // Notify the lump about us updating the offsets. // This is necessary for the GameLump which for some dumb reason has absolute file offsets and not local offsets lump.UpdateOffsets(pos); lump.Offset = pos; pos = Util.RoundUp(pos + lump.Data.Length, 4); // Lumps should appear on int boundaries in the BSP file } }
/// <summary> /// Writes the BSP header and lump data using a BinaryWriter stream /// </summary> /// <param name="writer">The BinaryWriter stream</param> public void WriteBSP(BinaryWriter writer) { UpdateLumpDataOffsets(); // Write header writer.Write(VBSP); writer.Write(Version); foreach (var lump in Lumps) { lump.WriteHeader(writer); } writer.Write(Revision); // Write lump contents foreach (var lump in Lumps.OrderBy(lump => lump.Offset)) { writer.Seek(lump.Offset, SeekOrigin.Begin); lump.WriteData(writer); } }