]> icculus.org git repositories - divverent/nexuiz.git/blob - misc/democonv-15-20.pl
added the 1.5 to 2.0 demo converter
[divverent/nexuiz.git] / misc / democonv-15-20.pl
1 #!/usr/bin/perl
2
3 # usage:
4 #   ./democonv-15-20.pl infile outfile
5
6 use strict;
7 use warnings;
8
9 # constants
10 my $svc_print = "\010";
11 my $svc_serverinfo = "\013";
12
13 my %maps = (
14         nexdm01 => 'basement',
15         nexdm02 => 'bleach',
16         nexdm03 => 'slimepit',
17         nexdm04 => 'skyway',
18         nexdm05 => 'downer',
19         nexdm06 => 'starship',
20         nexdm07 => 'dsi',
21         nexdm08 => 'glowarena',
22         nexdm09 => 'aneurism',
23         nexdm10 => 'stormkeep',
24         nexdm11 => 'ruinsofslaughter',
25         nexdm12 => 'evilspace',
26         nexdm13 => 'dismal',
27         nexdm14 => 'soylent',
28         nexdm15 => 'oilrig',
29         nexdm16 => 'silvercity',
30         nexdm17 => 'dieselpower',
31         nexdm18 => 'runningman',
32         nexdm18_1on1remix => 'runningman_1on1remix',
33         nexdmextra1 => 'darkzone',
34         nexdmextra2 => 'aggressor',
35         nexctf01 => 'basementctf',
36         nexctf02 => 'runningmanctf',
37 );
38
39 # opening the files
40
41 die "Usage: $0 infile outfile"
42         if @ARGV != 2;
43 my ($in, $out) = @ARGV;
44
45 $in ne $out
46         or die "Input and output file may not be the same!";
47
48 open my $infh, "<", $in
49         or die "open $in: $!";
50 binmode $infh;
51
52 open my $outfh, ">", $out
53         or die "open $out: $!";
54 binmode $outfh;
55
56 sub TranslateMapname($)
57 {
58         my ($map) = @_;
59         return $maps{$map}
60                 if exists $maps{$map};
61         return $map;
62 }
63
64 # 1. CD track
65
66 $/ = "\012";
67 my $cdtrack = <$infh>;
68 print $outfh $cdtrack;
69
70 # 2. packets
71
72 for(;;)
73 {
74         last
75                 unless 4 == read $infh, my $length, 4;
76         $length = unpack("V", $length);
77         die "Invalid demo packet"
78                 unless 12 == read $infh, my $angles, 12;
79         die "Invalid demo packet"
80                 unless $length == read $infh, my($data), $length;
81
82         $data =~ s{
83                 ^
84                 ($svc_print
85                         [^\0]*\0
86                 $svc_serverinfo....
87                         [^\0]*\0
88                         maps/)([^\0]*)(\.bsp\0)
89         }{$1 . TranslateMapname($2) . $3}sex;
90
91         print $outfh pack("V", length $data);
92         print $outfh $angles;
93         print $outfh $data;
94 }
95
96 close $outfh;
97 close $infh;