diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-11-06 18:37:11 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-11-06 18:37:11 +0300 |
| commit | 2f8c92f261586f68a976efce0cfcdd0401f402e0 (patch) | |
| tree | 33189cc48987789dff4e7fba0a74d2b2326f0a04 /pkg/classes/userCmd.go | |
| parent | convert cm ticks correctly (diff) | |
| download | sdp.go-2f8c92f261586f68a976efce0cfcdd0401f402e0.tar.gz sdp.go-2f8c92f261586f68a976efce0cfcdd0401f402e0.tar.bz2 sdp.go-2f8c92f261586f68a976efce0cfcdd0401f402e0.zip | |
dont try to understand it, feel itlp-parser
Diffstat (limited to '')
| -rw-r--r-- | pkg/classes/userCmd.go | 222 |
1 files changed, 0 insertions, 222 deletions
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 @@ | |||
| 1 | package classes | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "github.com/pektezol/bitreader" | ||
| 5 | ) | ||
| 6 | |||
| 7 | type UserCmd struct { | ||
| 8 | Cmd uint32 | ||
| 9 | Size uint32 | ||
| 10 | Data UserCmdInfo | ||
| 11 | } | ||
| 12 | |||
| 13 | type UserCmdInfo struct { | ||
| 14 | CommandNumber uint32 | ||
| 15 | TickCount uint32 | ||
| 16 | ViewAnglesX float32 | ||
| 17 | ViewAnglesY float32 | ||
| 18 | ViewAnglesZ float32 | ||
| 19 | ForwardMove float32 | ||
| 20 | SideMove float32 | ||
| 21 | UpMove float32 | ||
| 22 | Buttons uint32 | ||
| 23 | Impulse uint8 | ||
| 24 | WeaponSelect uint16 | ||
| 25 | WeaponSubType uint8 | ||
| 26 | MouseDx uint16 | ||
| 27 | MouseDy uint16 | ||
| 28 | } | ||
| 29 | |||
| 30 | func (userCmd *UserCmd) ParseUserCmd(reader *bitreader.Reader) { | ||
| 31 | userCmd.Cmd = reader.TryReadUInt32() | ||
| 32 | userCmd.Size = reader.TryReadUInt32() | ||
| 33 | userCmdReader := bitreader.NewReaderFromBytes(reader.TryReadBytesToSlice(uint64(userCmd.Size)), true) | ||
| 34 | userCmd.ParseUserCmdInfo(userCmdReader) | ||
| 35 | } | ||
| 36 | |||
| 37 | func (userCmd *UserCmd) ParseUserCmdInfo(reader *bitreader.Reader) { | ||
| 38 | if reader.TryReadBool() { | ||
| 39 | userCmd.Data.CommandNumber = reader.TryReadUInt32() | ||
| 40 | } | ||
| 41 | if reader.TryReadBool() { | ||
| 42 | userCmd.Data.TickCount = reader.TryReadUInt32() | ||
| 43 | } | ||
| 44 | if reader.TryReadBool() { | ||
| 45 | userCmd.Data.ViewAnglesX = reader.TryReadFloat32() | ||
| 46 | } | ||
| 47 | if reader.TryReadBool() { | ||
| 48 | userCmd.Data.ViewAnglesY = reader.TryReadFloat32() | ||
| 49 | } | ||
| 50 | if reader.TryReadBool() { | ||
| 51 | userCmd.Data.ViewAnglesZ = reader.TryReadFloat32() | ||
| 52 | } | ||
| 53 | if reader.TryReadBool() { | ||
| 54 | userCmd.Data.ForwardMove = reader.TryReadFloat32() | ||
| 55 | } | ||
| 56 | if reader.TryReadBool() { | ||
| 57 | userCmd.Data.SideMove = reader.TryReadFloat32() | ||
| 58 | } | ||
| 59 | if reader.TryReadBool() { | ||
| 60 | userCmd.Data.UpMove = reader.TryReadFloat32() | ||
| 61 | } | ||
| 62 | if reader.TryReadBool() { | ||
| 63 | userCmd.Data.Buttons = reader.TryReadUInt32() | ||
| 64 | } | ||
| 65 | if reader.TryReadBool() { | ||
| 66 | userCmd.Data.Impulse = reader.TryReadUInt8() | ||
| 67 | } | ||
| 68 | if reader.TryReadBool() { | ||
| 69 | userCmd.Data.WeaponSelect = uint16(reader.TryReadBits(11)) | ||
| 70 | if reader.TryReadBool() { | ||
| 71 | userCmd.Data.WeaponSubType = uint8(reader.TryReadBits(6)) | ||
| 72 | } | ||
| 73 | } | ||
| 74 | if reader.TryReadBool() { | ||
| 75 | userCmd.Data.MouseDx = reader.TryReadUInt16() | ||
| 76 | } | ||
| 77 | if reader.TryReadBool() { | ||
| 78 | userCmd.Data.MouseDy = reader.TryReadUInt16() | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | func (button Buttons) GetButtons() []string { | ||
| 83 | flags := []string{} | ||
| 84 | if button == 0 { | ||
| 85 | flags = append(flags, EButtonsNone) | ||
| 86 | } | ||
| 87 | if checkBit(uint32(button), 0) { | ||
| 88 | flags = append(flags, EButtonsAttack) | ||
| 89 | } | ||
| 90 | if checkBit(uint32(button), 1) { | ||
| 91 | flags = append(flags, EButtonsJump) | ||
| 92 | } | ||
| 93 | if checkBit(uint32(button), 2) { | ||
| 94 | flags = append(flags, EButtonsDuck) | ||
| 95 | } | ||
| 96 | if checkBit(uint32(button), 3) { | ||
| 97 | flags = append(flags, EButtonsForward) | ||
| 98 | } | ||
| 99 | if checkBit(uint32(button), 4) { | ||
| 100 | flags = append(flags, EButtonsBack) | ||
| 101 | } | ||
| 102 | if checkBit(uint32(button), 5) { | ||
| 103 | flags = append(flags, EButtonsUse) | ||
| 104 | } | ||
| 105 | if checkBit(uint32(button), 6) { | ||
| 106 | flags = append(flags, EButtonsCancel) | ||
| 107 | } | ||
| 108 | if checkBit(uint32(button), 7) { | ||
| 109 | flags = append(flags, EButtonsLeft) | ||
| 110 | } | ||
| 111 | if checkBit(uint32(button), 8) { | ||
| 112 | flags = append(flags, EButtonsRight) | ||
| 113 | } | ||
| 114 | if checkBit(uint32(button), 9) { | ||
| 115 | flags = append(flags, EButtonsMoveLeft) | ||
| 116 | } | ||
| 117 | if checkBit(uint32(button), 10) { | ||
| 118 | flags = append(flags, EButtonsMoveRight) | ||
| 119 | } | ||
| 120 | if checkBit(uint32(button), 11) { | ||
| 121 | flags = append(flags, EButtonsAttack2) | ||
| 122 | } | ||
| 123 | if checkBit(uint32(button), 12) { | ||
| 124 | flags = append(flags, EButtonsRun) | ||
| 125 | } | ||
| 126 | if checkBit(uint32(button), 13) { | ||
| 127 | flags = append(flags, EButtonsReload) | ||
| 128 | } | ||
| 129 | if checkBit(uint32(button), 14) { | ||
| 130 | flags = append(flags, EButtonsAlt1) | ||
| 131 | } | ||
| 132 | if checkBit(uint32(button), 15) { | ||
| 133 | flags = append(flags, EButtonsAlt2) | ||
| 134 | } | ||
| 135 | if checkBit(uint32(button), 16) { | ||
| 136 | flags = append(flags, EButtonsScore) | ||
| 137 | } | ||
| 138 | if checkBit(uint32(button), 17) { | ||
| 139 | flags = append(flags, EButtonsSpeed) | ||
| 140 | } | ||
| 141 | if checkBit(uint32(button), 18) { | ||
| 142 | flags = append(flags, EButtonsWalk) | ||
| 143 | } | ||
| 144 | if checkBit(uint32(button), 19) { | ||
| 145 | flags = append(flags, EButtonsZoom) | ||
| 146 | } | ||
| 147 | if checkBit(uint32(button), 20) { | ||
| 148 | flags = append(flags, EButtonsWeapon1) | ||
| 149 | } | ||
| 150 | if checkBit(uint32(button), 21) { | ||
| 151 | flags = append(flags, EButtonsWeapon2) | ||
| 152 | } | ||
| 153 | if checkBit(uint32(button), 22) { | ||
| 154 | flags = append(flags, EButtonsBullRush) | ||
| 155 | } | ||
| 156 | if checkBit(uint32(button), 23) { | ||
| 157 | flags = append(flags, EButtonsGrenade1) | ||
| 158 | } | ||
| 159 | if checkBit(uint32(button), 24) { | ||
| 160 | flags = append(flags, EButtonsGrenade2) | ||
| 161 | } | ||
| 162 | if checkBit(uint32(button), 25) { | ||
| 163 | flags = append(flags, EButtonsLookSpin) | ||
| 164 | } | ||
| 165 | if checkBit(uint32(button), 26) { | ||
| 166 | flags = append(flags, EButtonsCurrentAbility) | ||
| 167 | } | ||
| 168 | if checkBit(uint32(button), 27) { | ||
| 169 | flags = append(flags, EButtonsPreviousAbility) | ||
| 170 | } | ||
| 171 | if checkBit(uint32(button), 28) { | ||
| 172 | flags = append(flags, EButtonsAbility1) | ||
| 173 | } | ||
| 174 | if checkBit(uint32(button), 29) { | ||
| 175 | flags = append(flags, EButtonsAbility2) | ||
| 176 | } | ||
| 177 | if checkBit(uint32(button), 30) { | ||
| 178 | flags = append(flags, EButtonsAbility3) | ||
| 179 | } | ||
| 180 | if checkBit(uint32(button), 31) { | ||
| 181 | flags = append(flags, EButtonsAbility4) | ||
| 182 | } | ||
| 183 | return flags | ||
| 184 | } | ||
| 185 | |||
| 186 | type Buttons int | ||
| 187 | |||
| 188 | const ( | ||
| 189 | EButtonsNone string = "None" | ||
| 190 | EButtonsAttack string = "Attack" | ||
| 191 | EButtonsJump string = "Jump" | ||
| 192 | EButtonsDuck string = "Duck" | ||
| 193 | EButtonsForward string = "Forward" | ||
| 194 | EButtonsBack string = "Back" | ||
| 195 | EButtonsUse string = "Use" | ||
| 196 | EButtonsCancel string = "Cancel" | ||
| 197 | EButtonsLeft string = "Left" | ||
| 198 | EButtonsRight string = "Right" | ||
| 199 | EButtonsMoveLeft string = "MoveLeft" | ||
| 200 | EButtonsMoveRight string = "MoveRight" | ||
| 201 | EButtonsAttack2 string = "Attack2" | ||
| 202 | EButtonsRun string = "Run" | ||
| 203 | EButtonsReload string = "Reload" | ||
| 204 | EButtonsAlt1 string = "Alt1" | ||
| 205 | EButtonsAlt2 string = "Alt2" | ||
| 206 | EButtonsScore string = "Score" | ||
| 207 | EButtonsSpeed string = "Speed" | ||
| 208 | EButtonsWalk string = "Walk" | ||
| 209 | EButtonsZoom string = "Zoom" | ||
| 210 | EButtonsWeapon1 string = "Weapon1" | ||
| 211 | EButtonsWeapon2 string = "Weapon2" | ||
| 212 | EButtonsBullRush string = "BullRush" | ||
| 213 | EButtonsGrenade1 string = "Grenade1" | ||
| 214 | EButtonsGrenade2 string = "Grenade2" | ||
| 215 | EButtonsLookSpin string = "LookSpin" | ||
| 216 | EButtonsCurrentAbility string = "CurrentAbility" | ||
| 217 | EButtonsPreviousAbility string = "PreviousAbility" | ||
| 218 | EButtonsAbility1 string = "Ability1" | ||
| 219 | EButtonsAbility2 string = "Ability2" | ||
| 220 | EButtonsAbility3 string = "Ability3" | ||
| 221 | EButtonsAbility4 string = "Ability4" | ||
| 222 | ) | ||