diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2022-11-07 17:55:50 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-09-16 21:39:37 +0300 |
| commit | 39ecba8a16a1ef734edb216f1fafb094c5c38745 (patch) | |
| tree | a5ff60e92660d93469f00c5367cc74c2628ab620 /packets/classes/usercmd.go | |
| parent | done until the hard part (diff) | |
| download | sdp.go-39ecba8a16a1ef734edb216f1fafb094c5c38745.tar.gz sdp.go-39ecba8a16a1ef734edb216f1fafb094c5c38745.tar.bz2 sdp.go-39ecba8a16a1ef734edb216f1fafb094c5c38745.zip | |
done until the hard part
Diffstat (limited to 'packets/classes/usercmd.go')
| -rw-r--r-- | packets/classes/usercmd.go | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/packets/classes/usercmd.go b/packets/classes/usercmd.go new file mode 100644 index 0000000..a3183b6 --- /dev/null +++ b/packets/classes/usercmd.go | |||
| @@ -0,0 +1,94 @@ | |||
| 1 | package classes | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "github.com/pektezol/bitreader" | ||
| 5 | ) | ||
| 6 | |||
| 7 | func ParseUserCmdInfo(reader *bitreader.ReaderType, size int) UserCmdInfo { | ||
| 8 | var bitCount int | ||
| 9 | var userCmdInfo UserCmdInfo | ||
| 10 | if reader.TryReadBool() { | ||
| 11 | userCmdInfo.CommandNumber = int(reader.TryReadInt32()) | ||
| 12 | bitCount += 32 | ||
| 13 | } | ||
| 14 | bitCount++ | ||
| 15 | if reader.TryReadBool() { | ||
| 16 | userCmdInfo.TickCount = int(reader.TryReadInt32()) | ||
| 17 | bitCount += 32 | ||
| 18 | } | ||
| 19 | bitCount++ | ||
| 20 | if reader.TryReadBool() { | ||
| 21 | userCmdInfo.ViewAnglesX = reader.TryReadFloat32() | ||
| 22 | bitCount += 32 | ||
| 23 | } | ||
| 24 | bitCount++ | ||
| 25 | if reader.TryReadBool() { | ||
| 26 | userCmdInfo.ViewAnglesY = reader.TryReadFloat32() | ||
| 27 | bitCount += 32 | ||
| 28 | } | ||
| 29 | bitCount++ | ||
| 30 | if reader.TryReadBool() { | ||
| 31 | userCmdInfo.ViewAnglesZ = reader.TryReadFloat32() | ||
| 32 | bitCount += 32 | ||
| 33 | } | ||
| 34 | bitCount++ | ||
| 35 | if reader.TryReadBool() { | ||
| 36 | userCmdInfo.ForwardMove = reader.TryReadFloat32() | ||
| 37 | bitCount += 32 | ||
| 38 | } | ||
| 39 | bitCount++ | ||
| 40 | if reader.TryReadBool() { | ||
| 41 | userCmdInfo.SideMove = reader.TryReadFloat32() | ||
| 42 | bitCount += 32 | ||
| 43 | } | ||
| 44 | bitCount++ | ||
| 45 | if reader.TryReadBool() { | ||
| 46 | userCmdInfo.UpMove = reader.TryReadFloat32() | ||
| 47 | bitCount += 32 | ||
| 48 | } | ||
| 49 | bitCount++ | ||
| 50 | if reader.TryReadBool() { | ||
| 51 | userCmdInfo.Buttons = int(reader.TryReadInt32()) | ||
| 52 | bitCount += 32 | ||
| 53 | } | ||
| 54 | bitCount++ | ||
| 55 | if reader.TryReadBool() { | ||
| 56 | userCmdInfo.Impulse = reader.TryReadInt8() | ||
| 57 | bitCount += 8 | ||
| 58 | } | ||
| 59 | bitCount++ | ||
| 60 | if reader.TryReadBool() { | ||
| 61 | value, err := reader.ReadBits(11) | ||
| 62 | if err != nil { | ||
| 63 | panic(err) | ||
| 64 | } | ||
| 65 | userCmdInfo.WeaponSelect = int(value) | ||
| 66 | bitCount += 11 | ||
| 67 | if reader.TryReadBool() { | ||
| 68 | value, err := reader.ReadBits(6) | ||
| 69 | if err != nil { | ||
| 70 | panic(err) | ||
| 71 | } | ||
| 72 | userCmdInfo.WeaponSubtype = int(value) | ||
| 73 | bitCount += 6 | ||
| 74 | } | ||
| 75 | bitCount++ | ||
| 76 | } | ||
| 77 | bitCount++ | ||
| 78 | if reader.TryReadBool() { | ||
| 79 | userCmdInfo.MouseDx = int16(reader.TryReadInt16()) | ||
| 80 | bitCount += 16 | ||
| 81 | } | ||
| 82 | bitCount++ | ||
| 83 | if reader.TryReadBool() { | ||
| 84 | userCmdInfo.MouseDy = int16(reader.TryReadInt16()) | ||
| 85 | bitCount += 16 | ||
| 86 | } | ||
| 87 | bitCount++ | ||
| 88 | /*if bitCount > size*8 { | ||
| 89 | //reader.SkipBits(size * 8) | ||
| 90 | return userCmdInfo | ||
| 91 | }*/ | ||
| 92 | reader.SkipBits(size*8 - bitCount) | ||
| 93 | return userCmdInfo | ||
| 94 | } | ||