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