]> git.xonotic.org Git - xonotic/xonotic.git/blob - misc/tools/democonv-15-20.pl
nexuiz-map-compiler -> xonotic-map-compiler
[xonotic/xonotic.git] / misc / tools / 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 => 'aneurysm',
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 push @ARGV, "$ARGV[0]-converted.dem"
42         if @ARGV == 1;
43
44 die "Usage: $0 infile outfile"
45         if @ARGV != 2;
46 my ($in, $out) = @ARGV;
47
48 $in ne $out
49         or die "Input and output file may not be the same!";
50
51 open my $infh, "<", $in
52         or die "open $in: $!";
53 binmode $infh;
54
55 open my $outfh, ">", $out
56         or die "open $out: $!";
57 binmode $outfh;
58
59 sub TranslateMapname($)
60 {
61         my ($map) = @_;
62         return $maps{$map}
63                 if exists $maps{$map};
64         return $map;
65 }
66
67 # 1. CD track
68
69 $/ = "\012";
70 my $cdtrack = <$infh>;
71 print $outfh $cdtrack;
72
73 # 2. packets
74
75 for(;;)
76 {
77         last
78                 unless 4 == read $infh, my $length, 4;
79         $length = unpack("V", $length);
80         die "Invalid demo packet"
81                 unless 12 == read $infh, my $angles, 12;
82         die "Invalid demo packet"
83                 unless $length == read $infh, my($data), $length;
84
85         $data =~ s{
86                 ^
87                 ($svc_print
88                         [^\0]*\0
89                 $svc_serverinfo....
90                         [^\0]*\0
91                         maps/)([^\0]*)(\.bsp\0)
92         }{$1 . TranslateMapname($2) . $3}sex;
93
94         print $outfh pack("V", length $data);
95         print $outfh $angles;
96         print $outfh $data;
97 }
98
99 close $outfh;
100 close $infh;