How to get a trace hit on the opposite end of a wall?

I did this recently just as a test, here’s what I came up with, though I haven’t tested it fully, it seems to work well.

Basically it’s doing a multiline trace first, getting the first hit point, then tracing backwards from the location of the second hit, or, if there was no second hit, tracing back from the end of the previous trace: