diff options
| -rw-r--r-- | classes/userCmdInfo.go | 105 | ||||
| -rw-r--r-- | utils/utils.go | 31 |
2 files changed, 84 insertions, 52 deletions
diff --git a/classes/userCmdInfo.go b/classes/userCmdInfo.go index 3705c8d..86b186c 100644 --- a/classes/userCmdInfo.go +++ b/classes/userCmdInfo.go | |||
| @@ -1,7 +1,6 @@ | |||
| 1 | package classes | 1 | package classes |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | ||
| 5 | "parser/utils" | 4 | "parser/utils" |
| 6 | 5 | ||
| 7 | "github.com/potterxu/bitreader" | 6 | "github.com/potterxu/bitreader" |
| @@ -16,53 +15,99 @@ type UserCmdInfo struct { | |||
| 16 | ForwardMove float32 | 15 | ForwardMove float32 |
| 17 | SideMove float32 | 16 | SideMove float32 |
| 18 | UpMove float32 | 17 | UpMove float32 |
| 19 | Buttons int32 | ||
| 20 | Impulse byte | ||
| 21 | /*WeaponSelect int | ||
| 22 | WeaponSubtype int | ||
| 23 | MouseDx int16 | ||
| 24 | MouseDy int16*/ | ||
| 25 | } | 18 | } |
| 26 | 19 | ||
| 27 | func UserCmdInfoInit(byteArr []byte, size int) (output UserCmdInfo) { | 20 | func UserCmdInfoInit(byteArr []byte, size int) (output UserCmdInfo) { |
| 28 | var class UserCmdInfo | 21 | var class UserCmdInfo |
| 29 | fmt.Println("Size: ", size) | 22 | reversedByteArr := utils.ReverseByteArrayValues(byteArr, size) |
| 30 | reader := bitreader.BitReader(byteArr) | 23 | reader := bitreader.BitReader(reversedByteArr) |
| 31 | flag, err := reader.ReadBit() | 24 | if size-1 >= 4 { |
| 32 | utils.CheckError(err) | 25 | bit, err := reader.ReadBit() |
| 33 | fmt.Println(flag) | 26 | utils.CheckError(err) |
| 34 | flag2, err := reader.ReadBit() | 27 | if bit { |
| 35 | utils.CheckError(err) | 28 | value, err := reader.ReadBits(32) |
| 36 | fmt.Println(flag2) | 29 | utils.CheckError(err) |
| 37 | /*if size-1 >= 4 { | 30 | class.CommandNumber = int32(value) |
| 38 | class.CommandNumber = int32(utils.IntFromBytes(byteArr[:4])) | 31 | } else { |
| 32 | return class | ||
| 33 | } | ||
| 39 | } | 34 | } |
| 40 | if size-1 >= 8 { | 35 | if size-1 >= 8 { |
| 41 | class.TickCount = int32(utils.IntFromBytes(byteArr[4:8])) | 36 | bit, err := reader.ReadBit() |
| 37 | utils.CheckError(err) | ||
| 38 | if bit { | ||
| 39 | value, err := reader.ReadBits(32) | ||
| 40 | utils.CheckError(err) | ||
| 41 | class.TickCount = int32(value) | ||
| 42 | } else { | ||
| 43 | return class | ||
| 44 | } | ||
| 42 | } | 45 | } |
| 43 | if size-1 >= 12 { | 46 | if size-1 >= 12 { |
| 44 | class.ViewAnglesX = utils.FloatFromBytes(byteArr[8:12]) | 47 | bit, err := reader.ReadBit() |
| 48 | utils.CheckError(err) | ||
| 49 | if bit { | ||
| 50 | value, err := reader.ReadBits(32) | ||
| 51 | utils.CheckError(err) | ||
| 52 | class.ViewAnglesX = float32(value) | ||
| 53 | } else { | ||
| 54 | return class | ||
| 55 | } | ||
| 45 | } | 56 | } |
| 46 | if size-1 >= 16 { | 57 | if size-1 >= 16 { |
| 47 | class.ViewAnglesY = utils.FloatFromBytes(byteArr[12:16]) | 58 | bit, err := reader.ReadBit() |
| 59 | utils.CheckError(err) | ||
| 60 | if bit { | ||
| 61 | value, err := reader.ReadBits(32) | ||
| 62 | utils.CheckError(err) | ||
| 63 | class.ViewAnglesY = float32(value) | ||
| 64 | } else { | ||
| 65 | return class | ||
| 66 | } | ||
| 48 | } | 67 | } |
| 49 | if size-1 >= 20 { | 68 | if size-1 >= 20 { |
| 50 | class.ViewAnglesZ = utils.FloatFromBytes(byteArr[16:20]) | 69 | bit, err := reader.ReadBit() |
| 70 | utils.CheckError(err) | ||
| 71 | if bit { | ||
| 72 | value, err := reader.ReadBits(32) | ||
| 73 | utils.CheckError(err) | ||
| 74 | class.ViewAnglesZ = float32(value) | ||
| 75 | } else { | ||
| 76 | return class | ||
| 77 | } | ||
| 51 | } | 78 | } |
| 52 | if size-1 >= 24 { | 79 | if size-1 >= 24 { |
| 53 | class.ForwardMove = utils.FloatFromBytes(byteArr[20:24]) | 80 | bit, err := reader.ReadBit() |
| 81 | utils.CheckError(err) | ||
| 82 | if bit { | ||
| 83 | value, err := reader.ReadBits(32) | ||
| 84 | utils.CheckError(err) | ||
| 85 | class.ForwardMove = float32(value) | ||
| 86 | } else { | ||
| 87 | return class | ||
| 88 | } | ||
| 54 | } | 89 | } |
| 55 | if size-1 >= 28 { | 90 | if size-1 >= 28 { |
| 56 | class.SideMove = utils.FloatFromBytes(byteArr[24:28]) | 91 | bit, err := reader.ReadBit() |
| 92 | utils.CheckError(err) | ||
| 93 | if bit { | ||
| 94 | value, err := reader.ReadBits(32) | ||
| 95 | utils.CheckError(err) | ||
| 96 | class.SideMove = float32(value) | ||
| 97 | } else { | ||
| 98 | return class | ||
| 99 | } | ||
| 57 | } | 100 | } |
| 58 | if size-1 >= 32 { | 101 | if size-1 >= 32 { |
| 59 | class.UpMove = utils.FloatFromBytes(byteArr[28:32]) | 102 | bit, err := reader.ReadBit() |
| 103 | utils.CheckError(err) | ||
| 104 | if bit { | ||
| 105 | value, err := reader.ReadBits(32) | ||
| 106 | utils.CheckError(err) | ||
| 107 | class.UpMove = float32(value) | ||
| 108 | } else { | ||
| 109 | return class | ||
| 110 | } | ||
| 60 | } | 111 | } |
| 61 | if size-1 >= 36 { | ||
| 62 | class.Buttons = int32(utils.IntFromBytes(byteArr[32:36])) | ||
| 63 | } | ||
| 64 | if size-1 >= 40 { | ||
| 65 | class.Impulse = byteArr[36] | ||
| 66 | }*/ | ||
| 67 | return class | 112 | return class |
| 68 | } | 113 | } |
diff --git a/utils/utils.go b/utils/utils.go index 77e87af..6db28b0 100644 --- a/utils/utils.go +++ b/utils/utils.go | |||
| @@ -4,10 +4,19 @@ import ( | |||
| 4 | "encoding/binary" | 4 | "encoding/binary" |
| 5 | "log" | 5 | "log" |
| 6 | "math" | 6 | "math" |
| 7 | "math/bits" | ||
| 7 | "os" | 8 | "os" |
| 8 | "unsafe" | 9 | "unsafe" |
| 9 | ) | 10 | ) |
| 10 | 11 | ||
| 12 | func ReverseByteArrayValues(byteArr []byte, size int) []byte { | ||
| 13 | arr := make([]byte, size) | ||
| 14 | for index, byteValue := range byteArr { | ||
| 15 | arr[index] = bits.Reverse8(byteValue) | ||
| 16 | } | ||
| 17 | return arr | ||
| 18 | } | ||
| 19 | |||
| 11 | func ReadByteFromFile(file *os.File, size int32) []byte { | 20 | func ReadByteFromFile(file *os.File, size int32) []byte { |
| 12 | tmp := make([]byte, size) | 21 | tmp := make([]byte, size) |
| 13 | file.Read(tmp) | 22 | file.Read(tmp) |
| @@ -20,28 +29,6 @@ func CheckError(e error) { | |||
| 20 | } | 29 | } |
| 21 | } | 30 | } |
| 22 | 31 | ||
| 23 | /* | ||
| 24 | github.com/32bitkid/bitreader | ||
| 25 | |||
| 26 | func ReadBitsWithFirstBitCheckFromFile(file *os.File) (byteArr []byte, err error) { | ||
| 27 | arr := make([]byte, 4) | ||
| 28 | reader := bitreader.NewReader(file) | ||
| 29 | n := 0 | ||
| 30 | state, err := reader.Read1() | ||
| 31 | if err != nil || state == true { | ||
| 32 | return nil, fmt.Errorf("ERR or VAL in BIT CHECK") | ||
| 33 | } | ||
| 34 | n += 1 | ||
| 35 | if n == 0 { | ||
| 36 | val, err := reader.Read32(32) | ||
| 37 | if err != nil { | ||
| 38 | return nil, fmt.Errorf("ERR or VAL in BIT CHECK") | ||
| 39 | } | ||
| 40 | binary.LittleEndian.PutUint32(arr, val) | ||
| 41 | } | ||
| 42 | return arr, nil | ||
| 43 | } | ||
| 44 | */ | ||
| 45 | func IntFromBytes(byteArr []byte) uint32 { | 32 | func IntFromBytes(byteArr []byte) uint32 { |
| 46 | int := binary.LittleEndian.Uint32(byteArr) | 33 | int := binary.LittleEndian.Uint32(byteArr) |
| 47 | return int | 34 | return int |