Illinois recently enacted an affirmative defense to the violation of municipal firearm bans when the person is found with a firearm after he defended himself. In other words, if the only reason the cops know you have a gun is because you used it to protect your home and family, you're safe. The law reads:
It is an affirmative defense to a violation of a municipal ordinance that prohibits, regulates, or restricts the private ownership of firearms if the individual who is charged with the violation used the firearm in an act of self-defense or defense of another as defined in Sections 7-1 and 7-2 of this Code when on his or her land or in his or her abode or fixed place of business. (720 ILCS 5/24-10)
Please see this post at the Volokh Conspiracy for further details and commentary.