-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
s2prot.go
45 lines (37 loc) · 1.01 KB
/
s2prot.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
/*
This example shows how to use the s2prot package to extract basic information
from a StarCraft II (*.SC2Replay) file.
*/
package main
import (
"fmt"
"github.com/icza/mpq"
"github.com/icza/s2prot"
)
func main() {
m, err := mpq.NewFromFile("../../mpq/reps/automm.SC2Replay")
if err != nil {
panic(err)
}
defer m.Close()
header := s2prot.DecodeHeader(m.UserData())
ver := header.Structv("version")
fmt.Printf("Version: %d.%d.%d.%d\n",
ver.Int("major"), ver.Int("minor"), ver.Int("revision"), ver.Int("build"))
// Output: "Version: 2.1.9.34644"
baseBuild := int(ver.Int("baseBuild"))
fmt.Printf("Base build: %d\n", baseBuild)
// Output: "Base build: 32283"
p := s2prot.GetProtocol(baseBuild)
if p == nil {
panic("Unknown base build!")
}
detailsData, err := m.FileByName("replay.details")
if err != nil {
panic(err)
}
details := p.DecodeDetails(detailsData)
fmt.Println("Map name:", details.Stringv("title"))
// Output: "Map name: Hills of Peshkov"
fmt.Printf("Full Header:\n%v\n", header)
}