From 2f8c92f261586f68a976efce0cfcdd0401f402e0 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Mon, 6 Nov 2023 18:37:11 +0300 Subject: dont try to understand it, feel it --- pkg/classes/userCmd.go | 222 ------------------------------------------------- 1 file changed, 222 deletions(-) delete mode 100644 pkg/classes/userCmd.go (limited to 'pkg/classes/userCmd.go') diff --git a/pkg/classes/userCmd.go b/pkg/classes/userCmd.go deleted file mode 100644 index a4bf3d4..0000000 --- a/pkg/classes/userCmd.go +++ /dev/null @@ -1,222 +0,0 @@ -package classes - -import ( - "github.com/pektezol/bitreader" -) - -type UserCmd struct { - Cmd uint32 - Size uint32 - Data UserCmdInfo -} - -type UserCmdInfo struct { - CommandNumber uint32 - TickCount uint32 - ViewAnglesX float32 - ViewAnglesY float32 - ViewAnglesZ float32 - ForwardMove float32 - SideMove float32 - UpMove float32 - Buttons uint32 - Impulse uint8 - WeaponSelect uint16 - WeaponSubType uint8 - MouseDx uint16 - MouseDy uint16 -} - -func (userCmd *UserCmd) ParseUserCmd(reader *bitreader.Reader) { - userCmd.Cmd = reader.TryReadUInt32() - userCmd.Size = reader.TryReadUInt32() - userCmdReader := bitreader.NewReaderFromBytes(reader.TryReadBytesToSlice(uint64(userCmd.Size)), true) - userCmd.ParseUserCmdInfo(userCmdReader) -} - -func (userCmd *UserCmd) ParseUserCmdInfo(reader *bitreader.Reader) { - if reader.TryReadBool() { - userCmd.Data.CommandNumber = reader.TryReadUInt32() - } - if reader.TryReadBool() { - userCmd.Data.TickCount = reader.TryReadUInt32() - } - if reader.TryReadBool() { - userCmd.Data.ViewAnglesX = reader.TryReadFloat32() - } - if reader.TryReadBool() { - userCmd.Data.ViewAnglesY = reader.TryReadFloat32() - } - if reader.TryReadBool() { - userCmd.Data.ViewAnglesZ = reader.TryReadFloat32() - } - if reader.TryReadBool() { - userCmd.Data.ForwardMove = reader.TryReadFloat32() - } - if reader.TryReadBool() { - userCmd.Data.SideMove = reader.TryReadFloat32() - } - if reader.TryReadBool() { - userCmd.Data.UpMove = reader.TryReadFloat32() - } - if reader.TryReadBool() { - userCmd.Data.Buttons = reader.TryReadUInt32() - } - if reader.TryReadBool() { - userCmd.Data.Impulse = reader.TryReadUInt8() - } - if reader.TryReadBool() { - userCmd.Data.WeaponSelect = uint16(reader.TryReadBits(11)) - if reader.TryReadBool() { - userCmd.Data.WeaponSubType = uint8(reader.TryReadBits(6)) - } - } - if reader.TryReadBool() { - userCmd.Data.MouseDx = reader.TryReadUInt16() - } - if reader.TryReadBool() { - userCmd.Data.MouseDy = reader.TryReadUInt16() - } -} - -func (button Buttons) GetButtons() []string { - flags := []string{} - if button == 0 { - flags = append(flags, EButtonsNone) - } - if checkBit(uint32(button), 0) { - flags = append(flags, EButtonsAttack) - } - if checkBit(uint32(button), 1) { - flags = append(flags, EButtonsJump) - } - if checkBit(uint32(button), 2) { - flags = append(flags, EButtonsDuck) - } - if checkBit(uint32(button), 3) { - flags = append(flags, EButtonsForward) - } - if checkBit(uint32(button), 4) { - flags = append(flags, EButtonsBack) - } - if checkBit(uint32(button), 5) { - flags = append(flags, EButtonsUse) - } - if checkBit(uint32(button), 6) { - flags = append(flags, EButtonsCancel) - } - if checkBit(uint32(button), 7) { - flags = append(flags, EButtonsLeft) - } - if checkBit(uint32(button), 8) { - flags = append(flags, EButtonsRight) - } - if checkBit(uint32(button), 9) { - flags = append(flags, EButtonsMoveLeft) - } - if checkBit(uint32(button), 10) { - flags = append(flags, EButtonsMoveRight) - } - if checkBit(uint32(button), 11) { - flags = append(flags, EButtonsAttack2) - } - if checkBit(uint32(button), 12) { - flags = append(flags, EButtonsRun) - } - if checkBit(uint32(button), 13) { - flags = append(flags, EButtonsReload) - } - if checkBit(uint32(button), 14) { - flags = append(flags, EButtonsAlt1) - } - if checkBit(uint32(button), 15) { - flags = append(flags, EButtonsAlt2) - } - if checkBit(uint32(button), 16) { - flags = append(flags, EButtonsScore) - } - if checkBit(uint32(button), 17) { - flags = append(flags, EButtonsSpeed) - } - if checkBit(uint32(button), 18) { - flags = append(flags, EButtonsWalk) - } - if checkBit(uint32(button), 19) { - flags = append(flags, EButtonsZoom) - } - if checkBit(uint32(button), 20) { - flags = append(flags, EButtonsWeapon1) - } - if checkBit(uint32(button), 21) { - flags = append(flags, EButtonsWeapon2) - } - if checkBit(uint32(button), 22) { - flags = append(flags, EButtonsBullRush) - } - if checkBit(uint32(button), 23) { - flags = append(flags, EButtonsGrenade1) - } - if checkBit(uint32(button), 24) { - flags = append(flags, EButtonsGrenade2) - } - if checkBit(uint32(button), 25) { - flags = append(flags, EButtonsLookSpin) - } - if checkBit(uint32(button), 26) { - flags = append(flags, EButtonsCurrentAbility) - } - if checkBit(uint32(button), 27) { - flags = append(flags, EButtonsPreviousAbility) - } - if checkBit(uint32(button), 28) { - flags = append(flags, EButtonsAbility1) - } - if checkBit(uint32(button), 29) { - flags = append(flags, EButtonsAbility2) - } - if checkBit(uint32(button), 30) { - flags = append(flags, EButtonsAbility3) - } - if checkBit(uint32(button), 31) { - flags = append(flags, EButtonsAbility4) - } - return flags -} - -type Buttons int - -const ( - EButtonsNone string = "None" - EButtonsAttack string = "Attack" - EButtonsJump string = "Jump" - EButtonsDuck string = "Duck" - EButtonsForward string = "Forward" - EButtonsBack string = "Back" - EButtonsUse string = "Use" - EButtonsCancel string = "Cancel" - EButtonsLeft string = "Left" - EButtonsRight string = "Right" - EButtonsMoveLeft string = "MoveLeft" - EButtonsMoveRight string = "MoveRight" - EButtonsAttack2 string = "Attack2" - EButtonsRun string = "Run" - EButtonsReload string = "Reload" - EButtonsAlt1 string = "Alt1" - EButtonsAlt2 string = "Alt2" - EButtonsScore string = "Score" - EButtonsSpeed string = "Speed" - EButtonsWalk string = "Walk" - EButtonsZoom string = "Zoom" - EButtonsWeapon1 string = "Weapon1" - EButtonsWeapon2 string = "Weapon2" - EButtonsBullRush string = "BullRush" - EButtonsGrenade1 string = "Grenade1" - EButtonsGrenade2 string = "Grenade2" - EButtonsLookSpin string = "LookSpin" - EButtonsCurrentAbility string = "CurrentAbility" - EButtonsPreviousAbility string = "PreviousAbility" - EButtonsAbility1 string = "Ability1" - EButtonsAbility2 string = "Ability2" - EButtonsAbility3 string = "Ability3" - EButtonsAbility4 string = "Ability4" -) -- cgit v1.2.3