/
header.go
117 lines (92 loc) · 2.66 KB
/
header.go
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
Type describing the replay header (replay game version and length).
*/
package rep
import (
"fmt"
"time"
"github.com/icza/s2prot"
)
// Header describes the replay header (replay game version and length).
type Header struct {
s2prot.Struct
version string // Lazily initialized full version string
}
// BaseBuild returns the base build.
func (h *Header) BaseBuild() int64 {
return h.Int("version", "baseBuild")
}
// VersionString returns the full version string in the form of "major.minor.revision.build".
func (h *Header) VersionString() string {
if h.version == "" {
v := h.Version()
h.version = fmt.Sprintf("%d.%d.%d.%d", v.Major(), v.Minor(), v.Revision(), v.Build())
}
return h.version
}
// Loops returns the elapsed game loops (game length in loops).
func (h *Header) Loops() int64 {
return h.Int("elapsedGameLoops")
}
// Duration returns the game duration.
func (h *Header) Duration() time.Duration {
// 1 second = 16 loops => 1 loop = 1/16 second = 62,500,000 ns
return time.Duration(h.Loops() * 62500000)
}
// Signature returns the header signature.
// Should always be "StarCratII replay\u001b11".
func (h *Header) Signature() string {
return h.Stringv("signature")
}
// UseScaledTime returns whether scaled time is used.
func (h *Header) UseScaledTime() bool {
return h.Bool("useScaledTime")
}
// Type returns the type.
func (h *Header) Type() int64 {
return h.Int("type")
}
// DataBuildNum returns the data build number.
func (h *Header) DataBuildNum() int64 {
return h.Int("dataBuildNum")
}
// NgdpRootKey returns the data ngdp root key.
func (h *Header) NgdpRootKey() string {
return h.Stringv("ngdpRootKey", "data")
}
// ReplayCompatibilityHash returns the replay compatibility hash.
func (h *Header) ReplayCompatibilityHash() string {
return h.Stringv("replayCompatibilityHash", "data")
}
// Version returns the version of the replay.
func (h *Header) Version() Version {
return Version{Struct: h.Structv("version")}
}
// Version of the replay.
type Version struct {
s2prot.Struct
}
// Major returns the major part of the version.
func (v *Version) Major() int64 {
return v.Int("major")
}
// Minor returns the minor part of the version.
func (v *Version) Minor() int64 {
return v.Int("minor")
}
// Revision returns the revision part of the version.
func (v *Version) Revision() int64 {
return v.Int("revision")
}
// Build returns the build part of the version.
func (v *Version) Build() int64 {
return v.Int("build")
}
// BaseBuild returns the base build part of the version.
func (v *Version) BaseBuild() int64 {
return v.Int("baseBuild")
}
// Flags returns the flags part of the version.
func (v *Version) Flags() int64 {
return v.Int("flags")
}