If your wallet is hacked, then you will not do anything unfortunately. But you can protect your wallet. For better protection, you should be a bit paranoid: do not connect to unverified networks, maintain the correct password policy, etc.
The most important thing is to keep his bitcoin on a hardware wallet and divide it into different address inside the hardware wallet.
But yeah, do not ever connect to unknown network which is often to be a bait by hackerto penetrate your PC and steal your identity