I wanted to ask how to get a good ending in the last levels in the game?
There are only really two endings, one of which has a few variations.
The first ending where you return to Diadem XII is the one with the varying outcomes depending on how many encounters you've won and probes you've used, and the one where you stay and do the Government Base level doesn't have any variations.