Endangered mountain trees and shrubs are making a comeback in Scotland, mitigating the effects of extreme weather, a study by the University of Stirling has shown.