https://github.com/STJr/SRB2/pull/472
Since Confusion never opened a merge request here, and now seems to be absent, I figured I'd port it.
List of fixes from original pull request: