-
Notifications
You must be signed in to change notification settings - Fork 0
/
header.go
46 lines (40 loc) · 1.34 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
package main
import (
"bytes"
"encoding/binary"
"os"
)
func getHeaderProperties(file *os.File) HeaderProperties {
headerProps := HeaderProperties{}
binary.Read(bytes.NewBuffer(readNextBytesFromFile(file, 4)), binary.LittleEndian, &headerProps.Size)
binary.Read(bytes.NewBuffer(readNextBytesFromFile(file, 4)), binary.LittleEndian, &headerProps.CRC)
headerProps.ByteStream = readNextBytesFromFile(file, int(headerProps.Size))
headerProps.ContentBuffer = bytes.NewBuffer(headerProps.ByteStream)
return headerProps
}
func getVersionInfo(buf *bytes.Buffer) VersionInfo {
versionInfo := VersionInfo{}
count := 0
bs := make([]byte, 4)
binary.LittleEndian.PutUint32(bs, 24)
data := readNextBytes(buf, 4)
for bs[0] != data[0] {
buffer := bytes.NewBuffer(data)
if count == 0 {
binary.Read(buffer, binary.LittleEndian, &versionInfo.MajorVersion)
} else if count == 1 {
binary.Read(buffer, binary.LittleEndian, &versionInfo.MinorVersion)
} else if count ==2 {
binary.Read(buffer, binary.LittleEndian, &versionInfo.NetVersion)
}
data = readNextBytes(buf, 4)
count++
}
return versionInfo
}
func getGameConstant(buf *bytes.Buffer) GameConstant {
gameConstant := GameConstant{}
gameConstant.Length = 24
gameConstant.Name = convertToString(getStringBytes(buf, gameConstant.Length))
return gameConstant
}