diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-09-12 20:53:09 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-09-16 21:39:42 +0300 |
| commit | 82871ba1bac1d62f69e1933b66659e62d2e5e063 (patch) | |
| tree | a906310fba89b670bcfda9625a6d776553d482f6 /pkg/classes/userCmdInfo.go | |
| parent | net/svc messages finally getting parsed correctly (diff) | |
| download | sdp.go-82871ba1bac1d62f69e1933b66659e62d2e5e063.tar.gz sdp.go-82871ba1bac1d62f69e1933b66659e62d2e5e063.tar.bz2 sdp.go-82871ba1bac1d62f69e1933b66659e62d2e5e063.zip | |
another rewrite, v1.0.0
Diffstat (limited to '')
| -rw-r--r-- | pkg/classes/userCmdInfo.go (renamed from packets/classes/usercmd.go) | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/packets/classes/usercmd.go b/pkg/classes/userCmdInfo.go index d3328fd..a6d9091 100644 --- a/packets/classes/usercmd.go +++ b/pkg/classes/userCmdInfo.go | |||
| @@ -16,21 +16,21 @@ type UserCmdInfo struct { | |||
| 16 | SideMove float32 | 16 | SideMove float32 |
| 17 | UpMove float32 | 17 | UpMove float32 |
| 18 | Buttons int32 | 18 | Buttons int32 |
| 19 | Impulse byte | 19 | Impulse int8 |
| 20 | WeaponSelect int | 20 | WeaponSelect int16 |
| 21 | WeaponSubtype int | 21 | WeaponSubType int8 |
| 22 | MouseDx int16 | 22 | MouseDx int16 |
| 23 | MouseDy int16 | 23 | MouseDy int16 |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | func ParseUserCmdInfo(data []byte) UserCmdInfo { | 26 | func ParseUserCmdInfo(data []byte) UserCmdInfo { |
| 27 | reader := bitreader.Reader(bytes.NewReader(data), true) | 27 | reader := bitreader.Reader(bytes.NewReader(data), true) |
| 28 | var userCmdInfo UserCmdInfo | 28 | userCmdInfo := UserCmdInfo{} |
| 29 | if reader.TryReadBool() { | 29 | if reader.TryReadBool() { |
| 30 | userCmdInfo.CommandNumber = int32(reader.TryReadInt32()) | 30 | userCmdInfo.CommandNumber = int32(reader.TryReadBits(32)) |
| 31 | } | 31 | } |
| 32 | if reader.TryReadBool() { | 32 | if reader.TryReadBool() { |
| 33 | userCmdInfo.TickCount = int32(reader.TryReadInt32()) | 33 | userCmdInfo.TickCount = int32(reader.TryReadBits(32)) |
| 34 | } | 34 | } |
| 35 | if reader.TryReadBool() { | 35 | if reader.TryReadBool() { |
| 36 | userCmdInfo.ViewAnglesX = reader.TryReadFloat32() | 36 | userCmdInfo.ViewAnglesX = reader.TryReadFloat32() |
| @@ -51,30 +51,22 @@ func ParseUserCmdInfo(data []byte) UserCmdInfo { | |||
| 51 | userCmdInfo.UpMove = reader.TryReadFloat32() | 51 | userCmdInfo.UpMove = reader.TryReadFloat32() |
| 52 | } | 52 | } |
| 53 | if reader.TryReadBool() { | 53 | if reader.TryReadBool() { |
| 54 | userCmdInfo.Buttons = int32(reader.TryReadInt32()) | 54 | userCmdInfo.Buttons = int32(reader.TryReadBits(32)) |
| 55 | } | 55 | } |
| 56 | if reader.TryReadBool() { | 56 | if reader.TryReadBool() { |
| 57 | userCmdInfo.Impulse = reader.TryReadInt8() | 57 | userCmdInfo.Impulse = int8(reader.TryReadBits(8)) |
| 58 | } | 58 | } |
| 59 | if reader.TryReadBool() { | 59 | if reader.TryReadBool() { |
| 60 | value, err := reader.ReadBits(11) | 60 | userCmdInfo.WeaponSelect = int16(reader.TryReadBits(11)) |
| 61 | if err != nil { | ||
| 62 | panic(err) | ||
| 63 | } | ||
| 64 | userCmdInfo.WeaponSelect = int(value) | ||
| 65 | if reader.TryReadBool() { | 61 | if reader.TryReadBool() { |
| 66 | value, err := reader.ReadBits(6) | 62 | userCmdInfo.WeaponSubType = int8(reader.TryReadBits(6)) |
| 67 | if err != nil { | ||
| 68 | panic(err) | ||
| 69 | } | ||
| 70 | userCmdInfo.WeaponSubtype = int(value) | ||
| 71 | } | 63 | } |
| 72 | } | 64 | } |
| 73 | if reader.TryReadBool() { | 65 | if reader.TryReadBool() { |
| 74 | userCmdInfo.MouseDx = int16(reader.TryReadInt16()) | 66 | userCmdInfo.MouseDx = int16(reader.TryReadBits(16)) |
| 75 | } | 67 | } |
| 76 | if reader.TryReadBool() { | 68 | if reader.TryReadBool() { |
| 77 | userCmdInfo.MouseDy = int16(reader.TryReadInt16()) | 69 | userCmdInfo.MouseDy = int16(reader.TryReadBits(16)) |
| 78 | } | 70 | } |
| 79 | return userCmdInfo | 71 | return userCmdInfo |
| 80 | } | 72 | } |