How exactly is confidence of a shot calculated?

Is there a "base" (weapon-specific) value for a point-blank shot that is then decreased at longer ranges depending on weapon dispersion?

or

Is a "base" value for a point-blank shot also a function of the same weapon dispersion stat, not a different weapon characteristic?

Confidence is approximated actual hit chance. Don't trust it, the approximation is not good - just because confidence says you get x% chance to hit, doesn't mean the actual chance to hit will be that high/low.

Dispersion is currently calculated by summing up random rolls for weapon dispersion, skill dispersion, sight dispersion, recoil and possibly something more I forgot. Those can't be exchanged - if you have 50 weapon dispersion and 50 skill dispersion, you will not be as good at sniping as if you had 100 skill dispersion and 0 weapon dispersion. This is a major problem with the system, because it means you can't compensate for things, you need all parts of the dispersion roll near-perfect to actually hit things.

Once the dispersion value is rolled, it becomes an angle of miss, in minutes of degrees. So if you roll 60 on dispersion roll, you miss by 1 degree. This doesn't mean you miss the target totally, just its head.

From this miss angle, it is calculated (trigonometry) where you actually hit. If this hit is still within creature's size from the center, you hit the creature. If not, your shot goes wild, but you can still hit something else.

Whether you get a headshot, good shot, etc. depends on how little you missed, and on target's size. If you roll 0 on dispersion roll, it's always a headshot (if the target has a head).

After the dispersion roll, it's all just raw trigonometry. Point blank shots are simply covered by a wider angle.

EDIT:

P.S. Can you give me an example of a handgun you would use over a rifle for longer ranges if both had no hard range limits?

Honestly it's less about pistols, which are currently all either high recoil or sci-fi, and more about pistol caliber smgs/rifles, shotguns, pneumatic rifles and so on.

Shotguns are the worst offender because they are all very low dispersion and 00 shot is 0 dispersion. If there was no max range, consistent shotgun headshots would "only" require grinding up the skill.