Make the patch apply to the recent src tree

It builds but I can't guarantee it works correctly. Use at your own risk.