You clean it up. I've cleaned up projects that we're total shit shows and the cleanup paid dividends when the time came to update or change that part of the code.
Even if a project has gone to seed, things rapidly get better when you start to do things the right way again.