summaryrefslogtreecommitdiffstats
path: root/high2dat.pl
blob: 32b335775a5484074b01000e83fe402ca8411d50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/perl
#
# Convert the binary grv_high file to the text-based grvscore.dat
#

eval { use bytes; };

$gameid = 0;

print "VC 1.0\n";

sub quote($) {
    my($i) = @_;
    my($o) = '';
    my($x);

    for ( $x = 0 ; $x < length($i) ; $x++ ) {
	$o .= sprintf("%02x", ord(substr($i,$x,1)));
    }
    $o .= '00';
    return $o;
}

for ( $i = 0 ; $i < 100 ; $i++ ) {
    read(STDIN, $hd, 23);
    ($score, $player, $level, $time) = unpack("dA9vf", $hd);
    printf STDERR "<..> %14f %-9s %2d %f\n", $score, $player, $level, $time;
    $level++;
    $player = quote($player);
    $score = int($score+0.5);
    $time = int($time*1000+0.5);
    $time = ($time > 1800000) ? 0x7fffffff : $time;
    $gameid++;
    print "TS $gameid $score $level $player\n";
}
for ( $l = 0 ; $l < 75 ; $l++ ) {
    for ( $i = 0 ; $i < 3 ; $i++ ) {
	read(STDIN, $hd, 23);
	($score, $player, $level, $time) = unpack("dA9vf", $hd);
	printf STDERR "<%2d> %14f %-9s %2d %f\n", $l,$score, $player, $level, $time;
	if ( $level == $l ) {
	    $level++;
	    $score = int($score+0.5);
	    $time = int($time*1000+0.5);
	    $time = ($time > 1800000) ? 0x7fffffff : $time;
	    $gameid++;
	    print "LT $gameid $level $time\n" if ( $time != 0x7fffffff );
	}
    }
    for ( $i = 0 ; $i < 3 ; $i++ ) {
	read(STDIN, $hd, 23);
	($score, $player, $level, $time) = unpack("dA9vf", $hd);
	printf STDERR "<%2d> %14f %-9s %2d %f\n", $l, $score, $player, $level, $time;
	if ( 1 || $level == $l ) {
	    $level++;
	    $score = int($score+0.5);
	    $time = int($time*1000+0.5);
	    $time = ($time > 1800000) ? 0x7fffffff : $time;
	    $gameid++;
	    print "LS $gameid $level $score\n" if ( $score );
	}
    }
}