Think about the Goblet of Fire. They just figured out how to use magic indirectly to counter the anti devices. Like like using levitation to drop a rock on someone that is immune to direct magic effects or something similar. They found some avenue of attack that gets around things and the people that are doing the fighting have developed their abilities in that area abnormally high in secret or something. For example they could be really good at summoning gale force winds and the wind, once summoned is not magic, just wind.
The magic users colonized their system because it's high in some sort of magical ore that works as an enhancer for their magic - boosts them past what they could normally do, that's how they can move huge starships across lightyears. The bad guys found a system that has metal/crystal/whatever with the opposite property - it suppresses magic. Then they use that to build
their ships and armor and they also take a big hunk of it along and drop it in the middle of the only real city on the magical planet - that pretty much wins the opening battle of the invasion.
My hero and some other characters make it out of the city and then have to find a way to kick the bad guys off the planet. Which they do but it ends up with them making a deal with ancient mystical evil spirit things. And then the guy who's married to the woman the hero is in love with stages a coup and tries to take over the government.
And this story is just backstory for the story I really want to write.