How do you deal with those sweet cravings that come at midnight?

I really can’t stop myself, it’s like everything goes great all day and I say I’m on a diet, but when it’s midnight, it’s like another person comes out from inside me. Last night I finished a big pack of biscuits in one sitting and when I woke up in the morning and saw the pack, I literally hated myself. I don’t know if this is emotional hunger or what, but my psychology is really starting to break down. Is there anyone here who has found a way to overcome this?