The file is src/game/bg_misc.c. You have to change minNormal and invertNormal, minNormal is the minimal cosine of the angle of the ground (e.g. 0 degrees -> 1, 60 degrees -> 0.5, 90 degrees -> 0) and invertNormal must be true to allow building upside down.