aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBiSaXa <1669855+BiSaXa@users.noreply.github.com>2022-08-27 18:53:13 +0300
committerBiSaXa <1669855+BiSaXa@users.noreply.github.com>2022-08-27 18:53:13 +0300
commit0a3082bd167b2caa1d4a54b62d72e8be13ff43b0 (patch)
treea5d1c167da7015ccef4d9c3c5677e01f664850ba
parentsupport for multiple demos in a folder as an argument (diff)
downloadsdp.go-0a3082bd167b2caa1d4a54b62d72e8be13ff43b0.tar.gz
sdp.go-0a3082bd167b2caa1d4a54b62d72e8be13ff43b0.tar.bz2
sdp.go-0a3082bd167b2caa1d4a54b62d72e8be13ff43b0.zip
some stuff before i realized i need my own bitreader library
-rw-r--r--classes/userCmdInfo.go15
-rw-r--r--messages/messages.go11
-rw-r--r--utils/utils.go31
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 @@
1package classes 1package classes
2 2
3import ( 3import (
4 "fmt"
4 "parser/utils" 5 "parser/utils"
6
7 "github.com/potterxu/bitreader"
5) 8)
6 9
7type UserCmdInfo struct { 10type UserCmdInfo struct {
@@ -23,7 +26,15 @@ type UserCmdInfo struct {
23 26
24func UserCmdInfoInit(byteArr []byte, size int) (output UserCmdInfo) { 27func UserCmdInfoInit(byteArr []byte, size int) (output UserCmdInfo) {
25 var class UserCmdInfo 28 var class UserCmdInfo
26 if size-1 >= 4 { 29 fmt.Println("Size: ", size)
30 reader := bitreader.BitReader(byteArr)
31 flag, err := reader.ReadBit()
32 utils.CheckError(err)
33 fmt.Println(flag)
34 flag2, err := reader.ReadBit()
35 utils.CheckError(err)
36 fmt.Println(flag2)
37 /*if size-1 >= 4 {
27 class.CommandNumber = int32(utils.IntFromBytes(byteArr[:4])) 38 class.CommandNumber = int32(utils.IntFromBytes(byteArr[:4]))
28 } 39 }
29 if size-1 >= 8 { 40 if size-1 >= 8 {
@@ -52,6 +63,6 @@ func UserCmdInfoInit(byteArr []byte, size int) (output UserCmdInfo) {
52 } 63 }
53 if size-1 >= 40 { 64 if size-1 >= 40 {
54 class.Impulse = byteArr[36] 65 class.Impulse = byteArr[36]
55 } 66 }*/
56 return class 67 return class
57} 68}
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 (
7 "parser/utils" 7 "parser/utils"
8) 8)
9 9
10const (
11 MSSC int32 = 2
12)
13
10func MessageTypeCheck(file *os.File) (statusCode int) { 14func MessageTypeCheck(file *os.File) (statusCode int) {
11 var MSSC int32 = 2
12 Type := make([]byte, 1) 15 Type := make([]byte, 1)
13 Tick := make([]byte, 4) 16 Tick := make([]byte, 4)
14 Slot := make([]byte, 1) 17 Slot := make([]byte, 1)
@@ -48,12 +51,12 @@ func MessageTypeCheck(file *os.File) (statusCode int) {
48 return 4 51 return 4
49 case 0x05: // Usercmd FIXME: Correct bit-packing inside classes 52 case 0x05: // Usercmd FIXME: Correct bit-packing inside classes
50 var usercmd UserCmd 53 var usercmd UserCmd
51 //var usercmdinfo classes.UserCmdInfo 54 var usercmdinfo classes.UserCmdInfo
52 usercmd.Cmd = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) 55 usercmd.Cmd = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
53 usercmd.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) 56 usercmd.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
54 usercmd.Data = utils.ReadByteFromFile(file, usercmd.Size) 57 usercmd.Data = utils.ReadByteFromFile(file, usercmd.Size)
55 //usercmdinfo = classes.UserCmdInfoInit(usercmd.Data, int(usercmd.Size)) 58 usercmdinfo = classes.UserCmdInfoInit(usercmd.Data, int(usercmd.Size))
56 //fmt.Printf("[%d] UserCmd: %v\n", utils.IntFromBytes(Tick), usercmdinfo) 59 fmt.Printf("[%d] UserCmd: %v\n", utils.IntFromBytes(Tick), usercmdinfo)
57 return 5 60 return 5
58 case 0x06: // DataTables 61 case 0x06: // DataTables
59 var datatables DataTables 62 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 (
6 "math" 6 "math"
7 "os" 7 "os"
8 "unsafe" 8 "unsafe"
9
10 "github.com/potterxu/bitreader"
11) 9)
12 10
13func ReadByteFromFile(file *os.File, size int32) []byte { 11func ReadByteFromFile(file *os.File, size int32) []byte {
@@ -22,15 +20,28 @@ func CheckError(e error) {
22 } 20 }
23} 21}
24 22
25func CheckFirstBit(byteArr []byte) bool { 23/*
26 reader := bitreader.BitReader(byteArr) 24github.com/32bitkid/bitreader
27 state, err := reader.ReadBit()
28 if err != nil {
29 state = false
30 }
31 return state
32}
33 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*/
34func IntFromBytes(byteArr []byte) uint32 { 45func IntFromBytes(byteArr []byte) uint32 {
35 int := binary.LittleEndian.Uint32(byteArr) 46 int := binary.LittleEndian.Uint32(byteArr)
36 return int 47 return int