From 5e6ec6a7c1e90d7b362d4effb370ce4199525bd2 Mon Sep 17 00:00:00 2001 From: BiSaXa <1669855+BiSaXa@users.noreply.github.com> Date: Wed, 31 Aug 2022 23:58:02 +0300 Subject: usercmdinfo buttons complete --- classes/userCmdInfo.go | 6 ++++-- messages/messages.go | 2 +- utils/bitreader.go | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 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 { ForwardMove float32 SideMove float32 UpMove float32 - // Buttons int32 This could work but no idea on parsing buttons + Buttons int32 // Impulse byte } // WeaponSelect int32 } // WeaponSubtype int32 Not worth the effort, no one cares about these @@ -31,7 +31,7 @@ func UserCmdInfoInit(byteArr []byte, size int32) (output UserCmdInfo) { classIndex := 0 // fmt.Println(byteArr) // fmt.Printf("%08b", byteArr) - for i := 0; i < 8; i++ { + for i := 0; i < 9; i++ { if successCount+failedCount > 7 { failedCount = -successCount looped++ @@ -57,6 +57,8 @@ func UserCmdInfoInit(byteArr []byte, size int32) (output UserCmdInfo) { class.SideMove = utils.Read32BitsAfterFirstBitFloat32(byteArr, successCount+failedCount, successCount*4+looped) case 7: class.UpMove = utils.Read32BitsAfterFirstBitFloat32(byteArr, successCount+failedCount, successCount*4+looped) + case 8: + class.Buttons = utils.Read32BitsAfterFirstBitInt32(byteArr, successCount+failedCount, successCount*4+looped) } classIndex++ } 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) { var consolecmd ConsoleCmd consolecmd.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) consolecmd.Data = string(utils.ReadByteFromFile(file, consolecmd.Size)) - fmt.Printf("[%d] %s\n", message.Tick, consolecmd.Data) + //fmt.Printf("[%d] %s\n", message.Tick, consolecmd.Data) return 4 case 0x05: // Usercmd FIXME: Correct bit-packing inside classes 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 ( "strconv" ) +func ReadButtonsDataFromInt32(input int32) []string { + buttonList := [32]string{ + "Attack", + "Jump", + "Duck", + "Forward", + "Back", + "Use", + "Cancel", + "Left", + "Right", + "MoveLeft", + "MoveRight", + "Attack2", + "Run", + "Reload", + "Alt1", + "Alt2", + "Score", + "Speed", + "Walk", + "Zoom", + "Weapon1", + "Weapon2", + "BullRush", + "Grenade1", + "Grenade2", + "LookSpin", + "CurrentAbility", + "PreviousAbility", + "Ability1", + "Ability2", + "Ability3", + "Ability4", + } + var buttons []string + if input == 0 { + buttons = append(buttons, buttonList[0]) + return buttons + } + for i := 1; i < 33; i++ { + if ReadBitState(input, i) { + buttons = append(buttons, buttonList[i]) + } + } + return buttons +} + +func ReadBitState(input int32, index int) bool { + value := input & (1 << index) + return value > 0 +} + func ReadBitStateLSB(input byte, index int) (bool, error) { if index < 0 && index > 7 { return false, fmt.Errorf("IndexOutOfBounds for type byte") -- cgit v1.2.3