3 # Fake demo "cutting" tool
4 # works by looking for time codes in the demo
5 # and injecting playback speed commands
8 # ./demotc.pl infile outfile tc0 tc1 - cuts the demo file for playback
9 # ./demotc.pl infile outfile tc0 tc1 --capture - cuts the demo file for video capture (it will automatically write a dpvideo001.avi file of the selected time range when playing)
10 # ./demotc.pl infile pattern - looks for a pattern, prints parentheses matches
18 $str =~ y/\000-\037//d;
24 die "Usage: $0 infile outfile tc_start tc_end [--capture], or $0 infile pattern"
25 if @ARGV != 2 && @ARGV != 4 && @ARGV != 5;
26 my ($in, $out, $tc0, $tc1, $capture) = (@ARGV, undef, undef, undef);
29 or die "Input and output file may not be the same!";
31 open my $infh, "<", $in
32 or die "open $in: $!";
36 if(defined $tc0) # cutting
38 open $outfh, ">", $out
39 or die "open $out: $!";
46 my $cdtrack = <$infh>;
47 print $outfh $cdtrack if $outfh;
56 my $inject_buffer = "";
61 unless 4 == read $infh, my $length, 4;
62 $length = unpack("V", $length);
63 die "Invalid demo packet"
64 unless 12 == read $infh, my $angles, 12;
65 die "Invalid demo packet"
66 unless $length == read $infh, my($data), $length;
68 if(substr($data, 0, 1) eq "\007") # svc_time
70 $tc = unpack "f", substr $data, 1, 4;
77 $inject_buffer = "\011\nslowmo 100\n\000";
80 if($demo_started < 1 && $tc > $tc0 - 50)
82 $inject_buffer = "\011\nslowmo 10\n\000";
85 if($demo_started < 2 && $tc > $tc0 - 5)
87 $inject_buffer = "\011\nslowmo 1\n\000";
90 if($demo_started < 3 && $tc > $tc0)
94 $inject_buffer = "\011\ncl_capturevideo 1\n\000";
98 $inject_buffer = "\011\nslowmo 0; defer 1 \"slowmo 1\"\n\000";
102 if(!$demo_stopped && $tc > $tc1)
106 $inject_buffer = "\011\ncl_capturevideo 0; defer 0.5 \"disconnect\"\n\000";
110 $inject_buffer = "\011\ndefer 0.5 \"disconnect\"\n\000";
117 if(my @l = ($data =~ /$out/))
122 print " \"", sanitize($_), "\"";
129 if(length($data . $inject_buffer) < 65536)
131 $data .= $inject_buffer;
134 print $outfh pack("V", length $data);
135 print $outfh $angles;
139 close $outfh if $outfh;