Quadratic Chabauty and Rational Points II: Generalised Height Functions on Selmer Varieties