1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
#!/usr/bin/perl
use strict;
use warnings;
use Fcntl qw/:seek/;
sub get($$)
{
my ($fh, $n) = @_;
read $fh, my $v, $n
or die "read: $!";
return $v;
}
use constant LUMP_ENTITIES => 0;
if(!@ARGV)
{
die "Usage: bsp2ent BSPFILE > ENTFILE\n";
}
my $bspfile = $ARGV[0];
open my $fh, '<', $bspfile
or die "open $bspfile: $!";
get($fh, 4) eq 'IBSP'
or die "$bspfile is no IBSP";
unpack('V', get($fh, 4)) == 0x2e
or die "$bspfile is no Q3 BSP";
my @directory = map
{
[unpack('VV', get($fh, 8))] # offset, length
}
0..16;
seek($fh, $directory[LUMP_ENTITIES][0], SEEK_SET);
my $ent = get($fh, $directory[LUMP_ENTITIES][1]);
$ent =~ s/\000//g;
print $ent;
|