12 read $fh, my $header, 8;
14 die "Invalid BSP format"
15 if $header ne "IBSP\x2e\x00\x00\x00";
17 my @lumpname = qw/entities textures planes nodes leafs leaffaces leafbrushes models brushes brushsides vertices triangles effects faces lightmaps lightgrid pvs advertisements/;
18 my %lumpid = map { $lumpname[$_] => $_ } 0..@lumpname-1;
24 read $fh, my $lump, 8;
25 my ($offset, $length) = unpack "VV", $lump;
27 print "BSP lump $_ ($lumpname[$_]): offset $offset length $length\n";
28 push @bsp, [$offset, $length, undef];
33 my ($offset, $length, $data) = @$_;
35 read $fh, $data, $length;
36 length $data == $length
37 or die "Incomplete BSP lump at $offset\n";
46 die "invalid lump $1 to remove"
54 elsif(/^-e(.*)$/) # extract lump
57 die "invalid lump $1 to extract"
66 my $pos = 17 * 8 + tell($fh) + length $msg;
70 $_->[1] = length $_->[2];
72 print $fh pack "VV", $_->[0], $_->[1];
84 # externalize lightmaps