From 39ecba8a16a1ef734edb216f1fafb094c5c38745 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Mon, 7 Nov 2022 17:55:50 +0300 Subject: done until the hard part --- packets/classes/usercmd.go | 94 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 packets/classes/usercmd.go (limited to 'packets/classes/usercmd.go') 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 @@ +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 +} -- cgit v1.2.3