public byte[] Save() { //Save world to memory MemoryStream bytesStream = new MemoryStream(); BinaryWriter bw = new BinaryWriter(bytesStream); Save(bw, false); tileManager.Save(bw); itemManager.Save(bw); avatarManager.Save(bw); sectorManager.Save(bw); dayCycleManager.Save(bw); bw.Flush(); byte[] bytes = bytesStream.ToArray(); //Write header MemoryStream bytesStreamFinal = new MemoryStream(); BinaryWriter bwFinal = new BinaryWriter(bytesStreamFinal); bwFinal.Write(VERSION_INFO); bwFinal.Write(bytes.Length); bwFinal.Flush(); //Compress and write world GZipStream gzipStream = new GZipStream(bytesStreamFinal, CompressionMode.Compress, true); gzipStream.Write(bytes, 0, bytes.Length); gzipStream.Close(); return(bytesStreamFinal.ToArray()); }