-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinclude.replay.php
More file actions
68 lines (68 loc) · 1.97 KB
/
include.replay.php
File metadata and controls
68 lines (68 loc) · 1.97 KB
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
64
65
66
67
68
<?php
function binstr($str) {
$r='';
$r.="\x0B".pack('c',strlen($str));
$r.=$str;
return $r;
}
function date_to_hex($seconds) {
$hex="";
// UTC = GMT+8 - 28800
$seconds=(years_to_seconds(1970) + $seconds) * 10000000;
$hex=pack("q",$seconds);
/*
$hexsplit=str_split(strrev(base_convert(number_format($seconds,0,'',''),10,16)),2);
for ($i=0;$i<8;$i++) {
if (strlen($hexsplit[$i]) == 1) {
$hexsplit[$i]="0".$hexsplit[$i];
} else {
$hexsplit[$i]=strrev($hexsplit[$i]);
}
$hex.=pack("h*",$hexsplit[$i]);
}
*/
return $hex;
}
function years_to_seconds($years) {
/*
$s=0;
for ($i=1;$i<$year;$i++) {
if (($i % 100 == 0 && ($i % 400 == 0 && $i % 3200 != 0)) || ($i % 4 == 0 && $i % 100 != 0)) {
$s += 31622400;
} else {
$s += 31536000;
}
}
return $s;
*/
if ($years === 1970) {
return 62135596800;
}
return 31536000*($years-1)+(floor($years/4)-floor($years/100)+floor($years/400)-floor($years/3200))*86400;
}
function packreplay($mode,$username,$fileChecksum,$mods,$score,$maxcombo,$perfect,$rank,$countmiss,$count50,$count100,$count300,$countkatu,$countgeki,$repdata,$date) {
$output='';
$output.=pack('C',$mode);
$output.=pack('I',20150414);
$output.=binstr($fileChecksum);
$output.=binstr($username);
$output.=binstr(sprintf("%dp%do%do%dt%da%dr%de%sy%do%du%s%d%s",$count100+$count300,$count50,$countgeki,$countkatu,$countmiss,$fileChecksum,$maxcombo,($perfect ? "True" : "False"),$username,$score,$rank,$mods,"True"));
$output.=pack('S',$count300);
$output.=pack('S',$count100);
$output.=pack('S',$count50);
$output.=pack('S',$countgeki);
$output.=pack('S',$countkatu);
$output.=pack('S',$countmiss);
$output.=pack('I',$score);
$output.=pack('S',$maxcombo);
$output.=pack('C',$perfect);
$output.=pack('I',$mods);
$output.=pack('C',0);
$output.=date_to_hex($date);
$output.=pack('I',strlen($repdata));
$output.=$repdata;
$output.=pack('I',0);
$output.=pack('I',0);
return $output;
}
?>