blob: 04d76b65a6b03a0d863d338eb903b3cbf0c4f97c (
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
|
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 int8
WeaponSelect int16
WeaponSubType int8
MouseDx int16
MouseDy int16
}
func ParseUserCmdInfo(data []byte) UserCmdInfo {
reader := bitreader.NewReader(bytes.NewReader(data), true)
userCmdInfo := UserCmdInfo{}
if reader.TryReadBool() {
userCmdInfo.CommandNumber = int32(reader.TryReadBits(32))
}
if reader.TryReadBool() {
userCmdInfo.TickCount = int32(reader.TryReadBits(32))
}
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.TryReadBits(32))
}
if reader.TryReadBool() {
userCmdInfo.Impulse = int8(reader.TryReadBits(8))
}
if reader.TryReadBool() {
userCmdInfo.WeaponSelect = int16(reader.TryReadBits(11))
if reader.TryReadBool() {
userCmdInfo.WeaponSubType = int8(reader.TryReadBits(6))
}
}
if reader.TryReadBool() {
userCmdInfo.MouseDx = int16(reader.TryReadBits(16))
}
if reader.TryReadBool() {
userCmdInfo.MouseDy = int16(reader.TryReadBits(16))
}
return userCmdInfo
}
|