File: bsp2ent

package info (click to toggle)
nexuiz-data 2.5.2-13
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,294,288 kB
  • sloc: ansic: 10,523; perl: 6,845; sh: 2,188; java: 1,417; xml: 969; lisp: 519; ruby: 136; makefile: 125
file content (39 lines) | stat: -rwxr-xr-x 659 bytes parent folder | download | duplicates (6)
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;