Debian Codegraph @

tools/palres

raw
1 #!/usr/bin/perl
2 #
3 # Seven Kingdoms: Ancient Adversaries
4 #
5 # Copyright 1997,1998 Enlight Software Ltd.
6 # Copyright 2018 Jesse Allen
7 #
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 2 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #
21 #
22
23 use warnings;
24 use strict;
25
26 use FindBin;
27 use lib $FindBin::Bin;
28
29 my $PaletteHeaderSize = 8;
30 my @pal;
31
32 if (@ARGV < 2) {
33 print "Usage: $0 PAL.RES pal.txt\n";
34 print "Reconstructs pal.txt into PAL.RES file.\n";
35 exit 0;
36 }
37 my ($pal_file, $in_file) = @ARGV;
38
39 my $pal_fh;
40 my $buf;
41 my $in_fh;
42
43 if (!open($pal_fh, '>', $pal_file)) {
44 print "Unable to open $pal_file\n";
45 exit 1;
46 }
47
48 if (!open($in_fh, '<', $in_file)) {
49 print "Unable to open $in_file\n";
50 exit 1;
51 }
52
53 $buf = pack('C*', 0,0,0,0,0,0,0,0);
54 print $pal_fh $buf;
55
56 my $i = 0;
57 while (my $line = <$in_fh>) {
58 $line =~ s/^\s*//;
59 my ($entry, $r, $g, $b) = split(/[\s:]+/, $line);
60 $buf = pack('CCC', $r, $g, $b);
61 print $pal_fh $buf;
62 }
63
64 close($pal_fh);
65 close($in_fh);
66
67 exit 0;