public override void Write(EndianWriter bw, int magic) { // Note: This will not actually work for writing a tab_block to a compiled map. // Check if there are any blocks in the block list. if (blockCount == 0) { // Write empty tag_block and return. bw.Write(new byte[base.FieldSize]); return; } // Save current stream position. long oldPos = bw.BaseStream.Position; // Write a dummy tag_block header. bw.Write(new byte[base.FieldSize]); // Seek to the end of the stream. bw.BaseStream.Position = bw.BaseStream.Length; // Write alignment padding. bw.AlignToBoundary(paddingInterval); // Save the tag_block data address. address = (int)bw.BaseStream.Position; // Write an empty buffer for the block list so all // child tag_block elements will be written correctly. bw.Write(new byte[blockCount * definitionSize]); // Seek back to the start of the tag_block data. bw.BaseStream.Position = address; // Loop through the blocks and write each one. for (int x = 0; x < blockCount; x++) { // Position the stream at the correct address for this block. // NOTE: If our definition sizes are correct we should not need this. //bw.BaseStream.Position = address + (x * definitionSize); // Write the block definition fields to the stream. for (int i = 0; i < definition.Length; i++) { blocks[x][i].Write(bw, magic); } } // Restore stream position. bw.BaseStream.Position = oldPos; // Write the tag_block header. bw.Write(blockCount); bw.Write(address + magic); if (Engine != EngineManager.HaloEngine.Halo2) { bw.Write(0); } }