diff options
Diffstat (limited to 'utils/bitreader.go')
| -rw-r--r-- | utils/bitreader.go | 94 |
1 files changed, 0 insertions, 94 deletions
diff --git a/utils/bitreader.go b/utils/bitreader.go deleted file mode 100644 index ec7454e..0000000 --- a/utils/bitreader.go +++ /dev/null | |||
| @@ -1,94 +0,0 @@ | |||
| 1 | package utils | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "fmt" | ||
| 5 | "math" | ||
| 6 | "strconv" | ||
| 7 | ) | ||
| 8 | |||
| 9 | func 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 | |||
| 57 | func ReadBitState(input int32, index int) bool { | ||
| 58 | value := input & (1 << index) | ||
| 59 | return value > 0 | ||
| 60 | } | ||
| 61 | |||
| 62 | func ReadBitStateLSB(input byte, index int) (bool, error) { | ||
| 63 | if index < 0 && index > 7 { | ||
| 64 | return false, fmt.Errorf("IndexOutOfBounds for type byte") | ||
| 65 | } | ||
| 66 | value := input & (1 << index) | ||
| 67 | return (value > 0), nil | ||
| 68 | } | ||
| 69 | |||
| 70 | func Read32BitsAfterFirstBitInt32(input []byte, index int, step int) int32 { | ||
| 71 | binary := "" | ||
| 72 | binary += fmt.Sprintf("%08b", input[step])[8-index : 8] | ||
| 73 | binary += fmt.Sprintf("%08b", input[step-1]) | ||
| 74 | binary += fmt.Sprintf("%08b", input[step-2]) | ||
| 75 | binary += fmt.Sprintf("%08b", input[step-3]) | ||
| 76 | binary += fmt.Sprintf("%08b", input[step-4])[:8-index] | ||
| 77 | output, err := strconv.ParseInt(binary, 2, 32) | ||
| 78 | CheckError(err) | ||
| 79 | return int32(output) | ||
| 80 | |||
| 81 | } | ||
| 82 | |||
| 83 | func Read32BitsAfterFirstBitFloat32(input []byte, index int, step int) float32 { | ||
| 84 | binary := "" | ||
| 85 | binary += fmt.Sprintf("%08b", input[step])[8-index : 8] | ||
| 86 | binary += fmt.Sprintf("%08b", input[step-1]) | ||
| 87 | binary += fmt.Sprintf("%08b", input[step-2]) | ||
| 88 | binary += fmt.Sprintf("%08b", input[step-3]) | ||
| 89 | binary += fmt.Sprintf("%08b", input[step-4])[:8-index] | ||
| 90 | output, err := strconv.ParseUint(binary, 2, 32) | ||
| 91 | CheckError(err) | ||
| 92 | return math.Float32frombits(uint32(output)) | ||
| 93 | |||
| 94 | } | ||