From 0a3082bd167b2caa1d4a54b62d72e8be13ff43b0 Mon Sep 17 00:00:00 2001 From: BiSaXa <1669855+BiSaXa@users.noreply.github.com> Date: Sat, 27 Aug 2022 18:53:13 +0300 Subject: some stuff before i realized i need my own bitreader library --- classes/userCmdInfo.go | 15 +++++++++++++-- messages/messages.go | 11 +++++++---- utils/utils.go | 31 +++++++++++++++++++++---------- 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/classes/userCmdInfo.go b/classes/userCmdInfo.go index ae27e9a..3705c8d 100644 --- a/classes/userCmdInfo.go +++ b/classes/userCmdInfo.go @@ -1,7 +1,10 @@ package classes import ( + "fmt" "parser/utils" + + "github.com/potterxu/bitreader" ) type UserCmdInfo struct { @@ -23,7 +26,15 @@ type UserCmdInfo struct { func UserCmdInfoInit(byteArr []byte, size int) (output UserCmdInfo) { var class UserCmdInfo - if size-1 >= 4 { + fmt.Println("Size: ", size) + reader := bitreader.BitReader(byteArr) + flag, err := reader.ReadBit() + utils.CheckError(err) + fmt.Println(flag) + flag2, err := reader.ReadBit() + utils.CheckError(err) + fmt.Println(flag2) + /*if size-1 >= 4 { class.CommandNumber = int32(utils.IntFromBytes(byteArr[:4])) } if size-1 >= 8 { @@ -52,6 +63,6 @@ func UserCmdInfoInit(byteArr []byte, size int) (output UserCmdInfo) { } if size-1 >= 40 { class.Impulse = byteArr[36] - } + }*/ return class } diff --git a/messages/messages.go b/messages/messages.go index db9d027..04c7268 100644 --- a/messages/messages.go +++ b/messages/messages.go @@ -7,8 +7,11 @@ import ( "parser/utils" ) +const ( + MSSC int32 = 2 +) + func MessageTypeCheck(file *os.File) (statusCode int) { - var MSSC int32 = 2 Type := make([]byte, 1) Tick := make([]byte, 4) Slot := make([]byte, 1) @@ -48,12 +51,12 @@ func MessageTypeCheck(file *os.File) (statusCode int) { return 4 case 0x05: // Usercmd FIXME: Correct bit-packing inside classes var usercmd UserCmd - //var usercmdinfo classes.UserCmdInfo + var usercmdinfo classes.UserCmdInfo usercmd.Cmd = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) usercmd.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) usercmd.Data = utils.ReadByteFromFile(file, usercmd.Size) - //usercmdinfo = classes.UserCmdInfoInit(usercmd.Data, int(usercmd.Size)) - //fmt.Printf("[%d] UserCmd: %v\n", utils.IntFromBytes(Tick), usercmdinfo) + usercmdinfo = classes.UserCmdInfoInit(usercmd.Data, int(usercmd.Size)) + fmt.Printf("[%d] UserCmd: %v\n", utils.IntFromBytes(Tick), usercmdinfo) return 5 case 0x06: // DataTables var datatables DataTables diff --git a/utils/utils.go b/utils/utils.go index 62924c2..77e87af 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -6,8 +6,6 @@ import ( "math" "os" "unsafe" - - "github.com/potterxu/bitreader" ) func ReadByteFromFile(file *os.File, size int32) []byte { @@ -22,15 +20,28 @@ func CheckError(e error) { } } -func CheckFirstBit(byteArr []byte) bool { - reader := bitreader.BitReader(byteArr) - state, err := reader.ReadBit() - if err != nil { - state = false - } - return state -} +/* +github.com/32bitkid/bitreader + func ReadBitsWithFirstBitCheckFromFile(file *os.File) (byteArr []byte, err error) { + arr := make([]byte, 4) + reader := bitreader.NewReader(file) + n := 0 + state, err := reader.Read1() + if err != nil || state == true { + return nil, fmt.Errorf("ERR or VAL in BIT CHECK") + } + n += 1 + if n == 0 { + val, err := reader.Read32(32) + if err != nil { + return nil, fmt.Errorf("ERR or VAL in BIT CHECK") + } + binary.LittleEndian.PutUint32(arr, val) + } + return arr, nil + } +*/ func IntFromBytes(byteArr []byte) uint32 { int := binary.LittleEndian.Uint32(byteArr) return int -- cgit v1.2.3