| 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 < 1) { |
| 33 |
print "Usage: $0 PAL.RES pal.txt\n"; |
| 34 |
print "Dumps palette colors, and optionally write pal.txt\n"; |
| 35 |
exit 0; |
| 36 |
} |
| 37 |
my ($pal_file, $out_file) = @ARGV; |
| 38 |
|
| 39 |
my $pal_fh; |
| 40 |
if (!open($pal_fh, '<', $pal_file)) { |
| 41 |
print "Unable to open $pal_file\n"; |
| 42 |
exit 1; |
| 43 |
} |
| 44 |
|
| 45 |
my $buf; |
| 46 |
my $out_fh; |
| 47 |
read($pal_fh, $buf, $PaletteHeaderSize); |
| 48 |
|
| 49 |
if (defined($out_file)) { |
| 50 |
if (!open($out_fh, '>', $out_file)) { |
| 51 |
print "Unable to open $out_file\n"; |
| 52 |
exit 1; |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
my $i = 0; |
| 57 |
while (!eof($pal_fh)) { |
| 58 |
read($pal_fh, $buf, 3); |
| 59 |
my ($r, $g, $b) = unpack('CCC', $buf); |
| 60 |
printf("%2x: r=%3d g=%3d b=%3d\n", $i, $r, $g, $b); |
| 61 |
if (defined($out_file)) { |
| 62 |
printf $out_fh ("%2x: %3d %3d %3d\n", $i, $r, $g, $b); |
| 63 |
} |
| 64 |
push(@pal, [$r, $g, $b]); |
| 65 |
|
| 66 |
$i++; |
| 67 |
} |
| 68 |
|
| 69 |
close($pal_fh); |
| 70 |
|
| 71 |
if (defined($out_file)) { |
| 72 |
close($out_fh); |
| 73 |
} |
| 74 |
|
| 75 |
exit 0; |