From 5e197a36431a61974bd5d0a158d2d9855aac1baf Mon Sep 17 00:00:00 2001 From: Shiar Date: Mon, 12 Nov 2007 21:03:52 +0100 Subject: [PATCH] screp: parse player data Shows players by name and race. --- screp | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/screp b/screp index 7bf178f..910f3d2 100755 --- a/screp +++ b/screp @@ -414,6 +414,8 @@ sub open { } +my @race = (qw(Z T P), (undef) x 3, '-'); + sub showtime { my $time = shift() * .042; my $minutes = int($time / 60); @@ -445,14 +447,32 @@ $_ eq "\10"x8 . "\0"x4 or warn sprintf( ) for $head->{mag2}; delete $head->{$_} for qw(mag1 mag2 unknown1 unknown2); -my @playdata = unpack "a36"x12 . "V8C8", $headdata[0] +my @playdata = unpack "Va32"x12 . "V8C8", $headdata[0] or die "Couldn't parse player data in replay header\n"; -my @player; -push @player, unpackhash("x11Z25", shift @playdata, qw/name/) for 0 .. 11; +my (@player, @slot); +for (0 .. 11) { + my $number = shift @playdata; + defined $player[$number] and warn "Player #$number redefined"; + my ($data) = unpackhash("VcccZ25", shift @playdata, qw( + slot type race unknown name + )); + defined $race[$_] ? ($data->{race} = $race[$_]) : + warn "Unknown race #$_ for player $number" + for $data->{race}; + $slot[$data->{slot}] = $number if $data->{slot} < 16; + $player[$number] = $data; +} $player[$_]->{color} = shift @playdata for 0 .. 7; $player[$_]->{index} = shift @playdata for 0 .. 7; +sub showplayer { + my $id = shift; + my $playdata = $player[$slot[$id]]; + return defined $playdata ? + sprintf '%s (%s)', $playdata->{name}, $playdata->{race} : "#$id"; +} + printf "%s: %s\n", $_, $head->{$_} for qw(name creator); use Date::Format; printf "created: %s\n", time2str('%Y-%m-%d %X', $_) for $head->{time}; @@ -498,9 +518,10 @@ for (@$map) { for my $player (sort keys %stats) { my $row = $stats{$player}; $row->{last} ||= $map->[-1][0]; -# printf("%d:%6d actions (%3d micro,%4d macro);%4d APM\n", - printf("%d:%6d actions in%7d frames (%s) = %d APM\n", - $player, $row->{actions}, $row->{last}, +# printf("%-16s%6d actions (%3d micro,%4d macro);%4d APM\n", + my $name = showplayer($player); + printf("%-16s%6d actions in%7d frames (%s) = %d APM\n", + $name, $row->{actions}, $row->{last}, showtime($row->{last}), # $row->{micro} / $row->{last} * 60 / .042 * 1.05, # $row->{macro} / $row->{last} * 60 / .042 * 1.05, -- 2.30.0