hpacker: Add fix for CHPKTreeWriter

(I thought I already pushed that)
Offsets were incorrectly calculated, because of incorrect ordering
(offsets weren't calculated for tree root) and excessive loop in
calcOffsets.
hpacker: Simplify CItdPacker

It got more messy, but simpler. This is an intermediate step before
creation of libitd