You're right about both the things in bold, actually, the two things are completely related!
For decades you've been making lots of money from exports, and sitting on a lot of capital that needs investment, and all the US has allowed you to do is buy their treasury bonds, CPEC and wider OBOR are a strategy for challenging that existing situation. We in Pakistan are both grateful and fully committed.
China is our ally, the US is both completely unreliable and has been very unreasonable. Still, it's a superpower that we can't afford to mess with especially too brazenly, Pakistan by comparison is a pipsqueak, perhaps not in the region, but globally that's true.