From 82871ba1bac1d62f69e1933b66659e62d2e5e063 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Tue, 12 Sep 2023 20:53:09 +0300 Subject: another rewrite, v1.0.0 --- pkg/classes/userCmdInfo.go | 72 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 pkg/classes/userCmdInfo.go (limited to 'pkg/classes/userCmdInfo.go') diff --git a/pkg/classes/userCmdInfo.go b/pkg/classes/userCmdInfo.go new file mode 100644 index 0000000..a6d9091 --- /dev/null +++ b/pkg/classes/userCmdInfo.go @@ -0,0 +1,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.Reader(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 +} -- cgit v1.2.3