So sorry you are going through this.
It takes time, but you can heal from this, and I suspect that in time you will realize that you loved the IDEA of him, not him. You loved who you thought he was, who he pretended to be, NOT him.
A lot of what you are feeling is also habit. It is deeply ingrained in you to think of him, care about his feelings, remember to buy his favorite thing at the grocery, do his laundry to make his life a little easier. This is a lot of habit. And habits are challenging to break, but you absolutely can.
One thing I found helpful in the early days was to write out a list of all the things he did that hurt me. All of them. The cheating. The lying. The disrespect. The loneliness when he was not present in our relationship. The financial infidelity. The rudeness. The snarkieness and unpleasantness. And I had it close by at all times. When I started feeling weak and missing what I thought I had, I re-read the list. And added to it often because I realized there were a LOT more things like this that I had excused, wrote off of one-offs (but they happened way more than that), or justified as "no one is perfect."
Also mix up your routines to help disrupt those ingrained patterns. Re-arrange the furniture, take up new hobbies, switch going to the gym in the morning instead of the evening, try new recipes with ingredients he doesn’t like (but you do). See friends more often and say "yes" to every invitation even if you would usually say no.
As for what you could have done—- there is nothing you can do to change how another person acts. But I did realize that I allowed my XWS to "get away" with a lot more disrespect and taking me for granted than I should have. I should have spoken up more. I was afraid of rocking the boat so much that I didn’t see that the boat was not sea-worthy. Nice paint job and fun to sail in calm seas, but I was afraid of stormy weather but didn’t realize my fear. And obviously our boat sank anyway, so my sacrificing myself didn’t hep. I should have rocked the boat so we either could have worked to make it seaworthy or bailed out sooner. So you can definitely contemplate how you were in your M and perhaps decide to do things differently for yourself going forward. But you DID NOT cause his cheating or his supposed unhappiness.
Are you in IC (individual counseling)? I found it really helpful in helping me see our M clearly and without the rose-colored glasses, and to help me become the person I want to be and reclaiming the parts of me I downplayed to make my XWS happy.
And lastly No Contact (NC) is really helpful. I found that if I spoke to my WS it gave me a hangover of sorts and started my yearning and wishing for what "might have been" more. NC was hard at first (and I failed at it a few times- totally normal), but it really accelerated my healing.
You are stronger than you know and in a couple years you will be amazed at how different but beautiful your life has become.