Just wanted to show my support to you in this situation.
I've also gained weight due to my chronic pain conditions that have got worse over the past few years.
It isn't helped by the depression, which may partly be because of it too I guess, and leads me to eat more.
My only suggestions are to try and find exercise that doesn't exacerbate the pain. Maybe ask your dr what they can suggest to help you in this.