Call the console window by pressing ~ (tilde) key, enter this command: con_restricted 0 and press ENTER. Now cheating comands are available and can be entered the same way:
g_godmode = 1 this will give you immortality
g_infiniteAmmo = 1 unlimited ammunition
g_infinitesuitenergy=1 unlimited nanosuit energy
NOTE: some Crysis 2 versions doesn't allow console commands (nothing happens when ~ is pressed). In that case, apply the newest game patch, and console support will be available.