aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/bitreader.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/utils/bitreader.go b/utils/bitreader.go
index c4936fd..ec7454e 100644
--- a/utils/bitreader.go
+++ b/utils/bitreader.go
@@ -6,6 +6,59 @@ import (
6 "strconv" 6 "strconv"
7) 7)
8 8
9func ReadButtonsDataFromInt32(input int32) []string {
10 buttonList := [32]string{
11 "Attack",
12 "Jump",
13 "Duck",
14 "Forward",
15 "Back",
16 "Use",
17 "Cancel",
18 "Left",
19 "Right",
20 "MoveLeft",
21 "MoveRight",
22 "Attack2",
23 "Run",
24 "Reload",
25 "Alt1",
26 "Alt2",
27 "Score",
28 "Speed",
29 "Walk",
30 "Zoom",
31 "Weapon1",
32 "Weapon2",
33 "BullRush",
34 "Grenade1",
35 "Grenade2",
36 "LookSpin",
37 "CurrentAbility",
38 "PreviousAbility",
39 "Ability1",
40 "Ability2",
41 "Ability3",
42 "Ability4",
43 }
44 var buttons []string
45 if input == 0 {
46 buttons = append(buttons, buttonList[0])
47 return buttons
48 }
49 for i := 1; i < 33; i++ {
50 if ReadBitState(input, i) {
51 buttons = append(buttons, buttonList[i])
52 }
53 }
54 return buttons
55}
56
57func ReadBitState(input int32, index int) bool {
58 value := input & (1 << index)
59 return value > 0
60}
61
9func ReadBitStateLSB(input byte, index int) (bool, error) { 62func ReadBitStateLSB(input byte, index int) (bool, error) {
10 if index < 0 && index > 7 { 63 if index < 0 && index > 7 {
11 return false, fmt.Errorf("IndexOutOfBounds for type byte") 64 return false, fmt.Errorf("IndexOutOfBounds for type byte")