aboutsummaryrefslogtreecommitdiff
path: root/packets/classes/usercmd.go
blob: a3183b6aeac2c354f6c626753eb096c01c59c0a3 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package classes

import (
	"github.com/pektezol/bitreader"
)

func ParseUserCmdInfo(reader *bitreader.ReaderType, size int) UserCmdInfo {
	var bitCount int
	var userCmdInfo UserCmdInfo
	if reader.TryReadBool() {
		userCmdInfo.CommandNumber = int(reader.TryReadInt32())
		bitCount += 32
	}
	bitCount++
	if reader.TryReadBool() {
		userCmdInfo.TickCount = int(reader.TryReadInt32())
		bitCount += 32
	}
	bitCount++
	if reader.TryReadBool() {
		userCmdInfo.ViewAnglesX = reader.TryReadFloat32()
		bitCount += 32
	}
	bitCount++
	if reader.TryReadBool() {
		userCmdInfo.ViewAnglesY = reader.TryReadFloat32()
		bitCount += 32
	}
	bitCount++
	if reader.TryReadBool() {
		userCmdInfo.ViewAnglesZ = reader.TryReadFloat32()
		bitCount += 32
	}
	bitCount++
	if reader.TryReadBool() {
		userCmdInfo.ForwardMove = reader.TryReadFloat32()
		bitCount += 32
	}
	bitCount++
	if reader.TryReadBool() {
		userCmdInfo.SideMove = reader.TryReadFloat32()
		bitCount += 32
	}
	bitCount++
	if reader.TryReadBool() {
		userCmdInfo.UpMove = reader.TryReadFloat32()
		bitCount += 32
	}
	bitCount++
	if reader.TryReadBool() {
		userCmdInfo.Buttons = int(reader.TryReadInt32())
		bitCount += 32
	}
	bitCount++
	if reader.TryReadBool() {
		userCmdInfo.Impulse = reader.TryReadInt8()
		bitCount += 8
	}
	bitCount++
	if reader.TryReadBool() {
		value, err := reader.ReadBits(11)
		if err != nil {
			panic(err)
		}
		userCmdInfo.WeaponSelect = int(value)
		bitCount += 11
		if reader.TryReadBool() {
			value, err := reader.ReadBits(6)
			if err != nil {
				panic(err)
			}
			userCmdInfo.WeaponSubtype = int(value)
			bitCount += 6
		}
		bitCount++
	}
	bitCount++
	if reader.TryReadBool() {
		userCmdInfo.MouseDx = int16(reader.TryReadInt16())
		bitCount += 16
	}
	bitCount++
	if reader.TryReadBool() {
		userCmdInfo.MouseDy = int16(reader.TryReadInt16())
		bitCount += 16
	}
	bitCount++
	/*if bitCount > size*8 {
		//reader.SkipBits(size * 8)
		return userCmdInfo
	}*/
	reader.SkipBits(size*8 - bitCount)
	return userCmdInfo
}