blob: d3328fd5a904bf0323c0966396895bd7e9dccdf4 (
plain) (
blame)
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
|
package classes
import (
"bytes"
"github.com/pektezol/bitreader"
)
type UserCmdInfo struct {
CommandNumber int32
TickCount int32
ViewAnglesX float32
ViewAnglesY float32
ViewAnglesZ float32
ForwardMove float32
SideMove float32
UpMove float32
Buttons int32
Impulse byte
WeaponSelect int
WeaponSubtype int
MouseDx int16
MouseDy int16
}
func ParseUserCmdInfo(data []byte) UserCmdInfo {
reader := bitreader.Reader(bytes.NewReader(data), true)
var userCmdInfo UserCmdInfo
if reader.TryReadBool() {
userCmdInfo.CommandNumber = int32(reader.TryReadInt32())
}
if reader.TryReadBool() {
userCmdInfo.TickCount = int32(reader.TryReadInt32())
}
if reader.TryReadBool() {
userCmdInfo.ViewAnglesX = reader.TryReadFloat32()
}
if reader.TryReadBool() {
userCmdInfo.ViewAnglesY = reader.TryReadFloat32()
}
if reader.TryReadBool() {
userCmdInfo.ViewAnglesZ = reader.TryReadFloat32()
}
if reader.TryReadBool() {
userCmdInfo.ForwardMove = reader.TryReadFloat32()
}
if reader.TryReadBool() {
userCmdInfo.SideMove = reader.TryReadFloat32()
}
if reader.TryReadBool() {
userCmdInfo.UpMove = reader.TryReadFloat32()
}
if reader.TryReadBool() {
userCmdInfo.Buttons = int32(reader.TryReadInt32())
}
if reader.TryReadBool() {
userCmdInfo.Impulse = reader.TryReadInt8()
}
if reader.TryReadBool() {
value, err := reader.ReadBits(11)
if err != nil {
panic(err)
}
userCmdInfo.WeaponSelect = int(value)
if reader.TryReadBool() {
value, err := reader.ReadBits(6)
if err != nil {
panic(err)
}
userCmdInfo.WeaponSubtype = int(value)
}
}
if reader.TryReadBool() {
userCmdInfo.MouseDx = int16(reader.TryReadInt16())
}
if reader.TryReadBool() {
userCmdInfo.MouseDy = int16(reader.TryReadInt16())
}
return userCmdInfo
}
|