Ability numbers are stored as follows:
1 - ability 0
2 - ability 1
4 - Hidden
To set the ability number from a 012 based scheme, left shift by 1 instead of adding one. pchex++ does setAbilityNum(ability+1), but it should do setAbilityNum(ability<<1).
PKHeX loads abilities based off of the ability number, not the ability ID. To load it right shifts the value by 1. Since this Gligar is hidden (index 2), pchex assigns it 3. When read, it comes back as 1 instead of 2.
AbilityNumber is based off individual bitflags, not an index number. Since there's only 3 bits used, a single bit shift is sufficient.