4 # ./demosplit.pl demo.dem
5 # splits the demo into separate demos for each map played and writes them
6 # to demo-0000.dem, demo-0001.dem ...
12 my $svc_signon = "\001";
16 die "Usage: $0 infile"
20 my $demoname = [$in =~ /^(.*)\.dem$/]->[0];
22 if not defined $demoname;
24 open my $infh, "<", $in
25 or die "open $in: $!";
31 my $cdtrack = <$infh>;
41 unless 4 == read $infh, my $length, 4;
42 $length = unpack("V", $length);
43 die "Invalid demo packet"
44 unless 12 == read $infh, my $angles, 12;
45 die "Invalid demo packet"
46 unless $length == read $infh, my($data), $length;
56 my $outname = sprintf("%s-%04d.dem", $demoname, $outnum++);
57 open $outfh, ">", $outname
58 or die "open $outname: $!";
60 print $outfh $cdtrack;
61 print "Writing to $outname...\n";
64 die "No signon received"
66 print $outfh pack("V", length $data);