so is just an intensifier in this context, and it goes with either.
much is the simpler word, expressing mere degree.
badly is more complicated. When coupled with a verb that has to do with physical sensations or emotional feelings, badly casts the sensation or feeling as something physically painful or causing psychological distress. If the verb phrase admits the notion of physical pain or psychological distress of some kind, such as a painful yearning, badly can be used.
My sprained knee hurts so much!
She wanted that political victory so much.
He wanted her so much.
My sprained knee hurts so badly!
She wanted that political victory so badly.
He wanted her so badly.
Here are some verbs relating to emotion which do not admit the notion of physical pain or emotional distress, and so badly in the sense of to a painful or distressing degree does not work with them; the meaning of the verb and the meaning of the adverbial phrase are inimical to each other:
I liked her so badly. not idiomatic
I trusted her so badly. not idiomatic
I respected them so badly. not idiomatic
But as soon as we add even the slightest hint of yearning, it begins to work:
I looked forward to their visit so badly.marginal
Of course, badly can also mean "not achieving a good or acceptable result".
She did so badly in the election.
He did so badly on the chemistry exam.
The party was doing so badly in the polls.
But that meaning is not germane to the question of deciding between much and badly when expressing degree.