I actually figured out how to solve this, so I'll describe my solution. If you want real code, I can do that upon request.
In the traceattack function, do an additional trace from the start to the TR_vecEndPos and check if you hit something other than the victim. If you do, then check if it's the ent that should be bulletproof. If it is, then supercede this call.