Moving long mesh on the uneven surface

There’s a control rig called CR_Mannequin_FootPlant, which is pretty much basic stuff on how IK works and how to shift the pelvis based on the lowest foot.
Everything is commented for you to understand what’s happening in the entire control rig.