Hafeez century takes Pakistan to 299