You have three choices;
1) Restore to 3.1.3 and loose hope of jailbreaking or unlocking your phone.
2) If Cydia has saved your SHSHs for 3.1.2 on file, you can follow the procedure on
iClarrified to restore genuine 3.1.2 firmware.
To know if you have SHSHs on file, Cydia should look like this:
3) Use my custom 3.1.3 firmware. I made it myself using the Pwnage tool. It does not have any bugs, although you may have to download the carrier logo fix from Cydia.
To install it, use the shift restore method that Chistopher mentioned.
PM me if you want the firmware and I'll send you the link for the download.