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