port of https://github.com/id-tech-3-tools/map-compiler/pull/12 https://github.com/id-tech-3-tools/map-compiler/commit/87b8589a3a5069c482243bb33c587fc18911746c