From my understanding of the combat code (It's not much but hey at least I can try to help):
They is a function called: applyDamage(baseDamage, attacker, target, special = "") in combat.js.
This then calls calculateDamage(baseDamage, attacker, target, special).
calculateDamage is where crits...