Player Save State for Game Mode
When they enter the area do:
/tag @a[m=s] add survival
And:
/tag @a[m=c] add creative
And:
/tag @a[m=a] add adventure
Then just change their gamemodes back later accordingly:
/gamemode a @a[tag=adventure,r=5]
etc.
Make sure to untag them:
/tag @a[tag=survival,r=5] remove survival