aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--classes/userCmdInfo.go6
-rw-r--r--messages/messages.go2
-rw-r--r--utils/bitreader.go53
3 files changed, 58 insertions, 3 deletions
diff --git a/classes/userCmdInfo.go b/classes/userCmdInfo.go
index e91633d..55a8546 100644
--- a/classes/userCmdInfo.go
+++ b/classes/userCmdInfo.go
@@ -13,7 +13,7 @@ type UserCmdInfo struct {
13 ForwardMove float32 13 ForwardMove float32
14 SideMove float32 14 SideMove float32
15 UpMove float32 15 UpMove float32
16 // Buttons int32 This could work but no idea on parsing buttons 16 Buttons int32
17 // Impulse byte } 17 // Impulse byte }
18 // WeaponSelect int32 } 18 // WeaponSelect int32 }
19 // WeaponSubtype int32 Not worth the effort, no one cares about these 19 // WeaponSubtype int32 Not worth the effort, no one cares about these
@@ -31,7 +31,7 @@ func UserCmdInfoInit(byteArr []byte, size int32) (output UserCmdInfo) {
31 classIndex := 0 31 classIndex := 0
32 // fmt.Println(byteArr) 32 // fmt.Println(byteArr)
33 // fmt.Printf("%08b", byteArr) 33 // fmt.Printf("%08b", byteArr)
34 for i := 0; i < 8; i++ { 34 for i := 0; i < 9; i++ {
35 if successCount+failedCount > 7 { 35 if successCount+failedCount > 7 {
36 failedCount = -successCount 36 failedCount = -successCount
37 looped++ 37 looped++
@@ -57,6 +57,8 @@ func UserCmdInfoInit(byteArr []byte, size int32) (output UserCmdInfo) {
57 class.SideMove = utils.Read32BitsAfterFirstBitFloat32(byteArr, successCount+failedCount, successCount*4+looped) 57 class.SideMove = utils.Read32BitsAfterFirstBitFloat32(byteArr, successCount+failedCount, successCount*4+looped)
58 case 7: 58 case 7:
59 class.UpMove = utils.Read32BitsAfterFirstBitFloat32(byteArr, successCount+failedCount, successCount*4+looped) 59 class.UpMove = utils.Read32BitsAfterFirstBitFloat32(byteArr, successCount+failedCount, successCount*4+looped)
60 case 8:
61 class.Buttons = utils.Read32BitsAfterFirstBitInt32(byteArr, successCount+failedCount, successCount*4+looped)
60 } 62 }
61 classIndex++ 63 classIndex++
62 } else { 64 } else {
diff --git a/messages/messages.go b/messages/messages.go
index 075aece..6afa270 100644
--- a/messages/messages.go
+++ b/messages/messages.go
@@ -44,7 +44,7 @@ func ParseMessage(file *os.File) (statusCode int) {
44 var consolecmd ConsoleCmd 44 var consolecmd ConsoleCmd
45 consolecmd.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) 45 consolecmd.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
46 consolecmd.Data = string(utils.ReadByteFromFile(file, consolecmd.Size)) 46 consolecmd.Data = string(utils.ReadByteFromFile(file, consolecmd.Size))
47 fmt.Printf("[%d] %s\n", message.Tick, consolecmd.Data) 47 //fmt.Printf("[%d] %s\n", message.Tick, consolecmd.Data)
48 return 4 48 return 4
49 case 0x05: // Usercmd FIXME: Correct bit-packing inside classes 49 case 0x05: // Usercmd FIXME: Correct bit-packing inside classes
50 var usercmd UserCmd 50 var usercmd UserCmd
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")