diff options
| author | BiSaXa <1669855+BiSaXa@users.noreply.github.com> | 2022-09-07 19:40:16 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-09-16 21:39:36 +0300 |
| commit | 4e71a481884c0c43aea3d0ee695ae68cdec56478 (patch) | |
| tree | d75c96612526a7c686d9f4d85af6b89c7cd864e6 /classes | |
| parent | final commit before rewrite (diff) | |
| download | sdp.go-4e71a481884c0c43aea3d0ee695ae68cdec56478.tar.gz sdp.go-4e71a481884c0c43aea3d0ee695ae68cdec56478.tar.bz2 sdp.go-4e71a481884c0c43aea3d0ee695ae68cdec56478.zip | |
first rewrite commit using bisaxa/bitreader
Diffstat (limited to 'classes')
| -rw-r--r-- | classes/classes.go | 155 | ||||
| -rw-r--r-- | classes/cmdInfo.go | 25 | ||||
| -rw-r--r-- | classes/stringTable.go | 27 | ||||
| -rw-r--r-- | classes/types.go | 28 | ||||
| -rw-r--r-- | classes/userCmdInfo.go | 72 |
5 files changed, 183 insertions, 124 deletions
diff --git a/classes/classes.go b/classes/classes.go new file mode 100644 index 0000000..beaab77 --- /dev/null +++ b/classes/classes.go | |||
| @@ -0,0 +1,155 @@ | |||
| 1 | package classes | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "os" | ||
| 5 | |||
| 6 | "github.com/bisaxa/bitreader" | ||
| 7 | "github.com/bisaxa/demoparser/utils" | ||
| 8 | ) | ||
| 9 | |||
| 10 | func ParseCmdInfo(file *os.File, MSSC int) []CmdInfo { | ||
| 11 | reader := bitreader.Reader(file, true) | ||
| 12 | var cmdinfo CmdInfo | ||
| 13 | var cmdinfoarray []CmdInfo | ||
| 14 | for count := 0; count < MSSC; count++ { | ||
| 15 | cmdinfo.Flags = int32(reader.TryReadInt32()) | ||
| 16 | var floatArray [3]float32 | ||
| 17 | for i := 0; i < 3; i++ { | ||
| 18 | floatArray[i] = reader.TryReadFloat32() | ||
| 19 | } | ||
| 20 | cmdinfo.ViewOrigin = floatArray[:] | ||
| 21 | for i := 0; i < 3; i++ { | ||
| 22 | floatArray[i] = reader.TryReadFloat32() | ||
| 23 | } | ||
| 24 | cmdinfo.ViewAngles = floatArray[:] | ||
| 25 | for i := 0; i < 3; i++ { | ||
| 26 | floatArray[i] = reader.TryReadFloat32() | ||
| 27 | } | ||
| 28 | cmdinfo.LocalViewAngles = floatArray[:] | ||
| 29 | for i := 0; i < 3; i++ { | ||
| 30 | floatArray[i] = reader.TryReadFloat32() | ||
| 31 | } | ||
| 32 | cmdinfo.ViewOrigin2 = floatArray[:] | ||
| 33 | for i := 0; i < 3; i++ { | ||
| 34 | floatArray[i] = reader.TryReadFloat32() | ||
| 35 | } | ||
| 36 | cmdinfo.ViewAngles2 = floatArray[:] | ||
| 37 | for i := 0; i < 3; i++ { | ||
| 38 | floatArray[i] = reader.TryReadFloat32() | ||
| 39 | } | ||
| 40 | cmdinfo.LocalViewAngles2 = floatArray[:] | ||
| 41 | cmdinfoarray = append(cmdinfoarray, cmdinfo) | ||
| 42 | } | ||
| 43 | return cmdinfoarray | ||
| 44 | } | ||
| 45 | |||
| 46 | func ParseUserCmdInfo(file *os.File, size int) UserCmdInfo { | ||
| 47 | count := 0 | ||
| 48 | reader := bitreader.Reader(file, true) | ||
| 49 | var usercmd UserCmdInfo | ||
| 50 | flag, err := reader.ReadBool() | ||
| 51 | utils.CheckError(err) | ||
| 52 | if flag { | ||
| 53 | usercmd.CommandNumber = int32(reader.TryReadInt32()) | ||
| 54 | count += 32 | ||
| 55 | } | ||
| 56 | count++ | ||
| 57 | flag, err = reader.ReadBool() | ||
| 58 | utils.CheckError(err) | ||
| 59 | if flag { | ||
| 60 | usercmd.TickCount = int32(reader.TryReadInt32()) | ||
| 61 | count += 32 | ||
| 62 | } | ||
| 63 | count++ | ||
| 64 | flag, err = reader.ReadBool() | ||
| 65 | utils.CheckError(err) | ||
| 66 | if flag { | ||
| 67 | usercmd.ViewAnglesX = reader.TryReadFloat32() | ||
| 68 | count += 32 | ||
| 69 | } | ||
| 70 | count++ | ||
| 71 | flag, err = reader.ReadBool() | ||
| 72 | utils.CheckError(err) | ||
| 73 | if flag { | ||
| 74 | usercmd.ViewAnglesY = reader.TryReadFloat32() | ||
| 75 | count += 32 | ||
| 76 | } | ||
| 77 | count++ | ||
| 78 | flag, err = reader.ReadBool() | ||
| 79 | utils.CheckError(err) | ||
| 80 | if flag { | ||
| 81 | usercmd.ViewAnglesZ = reader.TryReadFloat32() | ||
| 82 | count += 32 | ||
| 83 | } | ||
| 84 | count++ | ||
| 85 | flag, err = reader.ReadBool() | ||
| 86 | utils.CheckError(err) | ||
| 87 | if flag { | ||
| 88 | usercmd.ForwardMove = reader.TryReadFloat32() | ||
| 89 | count += 32 | ||
| 90 | } | ||
| 91 | count++ | ||
| 92 | flag, err = reader.ReadBool() | ||
| 93 | utils.CheckError(err) | ||
| 94 | if flag { | ||
| 95 | usercmd.SideMove = reader.TryReadFloat32() | ||
| 96 | count += 32 | ||
| 97 | } | ||
| 98 | count++ | ||
| 99 | flag, err = reader.ReadBool() | ||
| 100 | utils.CheckError(err) | ||
| 101 | if flag { | ||
| 102 | usercmd.UpMove = reader.TryReadFloat32() | ||
| 103 | count += 32 | ||
| 104 | } | ||
| 105 | count++ | ||
| 106 | flag, err = reader.ReadBool() | ||
| 107 | utils.CheckError(err) | ||
| 108 | if flag { | ||
| 109 | usercmd.Buttons = int32(reader.TryReadInt32()) | ||
| 110 | count += 32 | ||
| 111 | } | ||
| 112 | count++ | ||
| 113 | flag, err = reader.ReadBool() | ||
| 114 | utils.CheckError(err) | ||
| 115 | if flag { | ||
| 116 | //reader.SkipBits(8) | ||
| 117 | usercmd.Impulse = int8(reader.TryReadInt8()) | ||
| 118 | count += 8 | ||
| 119 | } | ||
| 120 | count++ | ||
| 121 | flag, err = reader.ReadBool() | ||
| 122 | utils.CheckError(err) | ||
| 123 | if flag { | ||
| 124 | value, err := reader.ReadBits(11) | ||
| 125 | utils.CheckError(err) | ||
| 126 | usercmd.WeaponSelect = int(value) | ||
| 127 | flag, err = reader.ReadBool() | ||
| 128 | utils.CheckError(err) | ||
| 129 | count += 11 | ||
| 130 | if flag { | ||
| 131 | value, err := reader.ReadBits(6) | ||
| 132 | utils.CheckError(err) | ||
| 133 | usercmd.WeaponSubtype = int(value) | ||
| 134 | count += 6 | ||
| 135 | } | ||
| 136 | count++ | ||
| 137 | } | ||
| 138 | count++ | ||
| 139 | flag, err = reader.ReadBool() | ||
| 140 | utils.CheckError(err) | ||
| 141 | if flag { | ||
| 142 | usercmd.MouseDx = int16(reader.TryReadInt16()) | ||
| 143 | count += 16 | ||
| 144 | } | ||
| 145 | count++ | ||
| 146 | flag, err = reader.ReadBool() | ||
| 147 | utils.CheckError(err) | ||
| 148 | if flag { | ||
| 149 | usercmd.MouseDy = int16(reader.TryReadInt16()) | ||
| 150 | count += 16 | ||
| 151 | } | ||
| 152 | count++ | ||
| 153 | reader.SkipBits(size*8 - count) | ||
| 154 | return usercmd | ||
| 155 | } | ||
diff --git a/classes/cmdInfo.go b/classes/cmdInfo.go deleted file mode 100644 index 7e7e1bc..0000000 --- a/classes/cmdInfo.go +++ /dev/null | |||
| @@ -1,25 +0,0 @@ | |||
| 1 | package classes | ||
| 2 | |||
| 3 | import "github.com/bisaxa/demoparser/utils" | ||
| 4 | |||
| 5 | type CmdInfo struct { | ||
| 6 | Flags int32 | ||
| 7 | ViewOrigin []float32 | ||
| 8 | ViewAngles []float32 | ||
| 9 | LocalViewAngles []float32 | ||
| 10 | ViewOrigin2 []float32 | ||
| 11 | ViewAngles2 []float32 | ||
| 12 | LocalViewAngles2 []float32 | ||
| 13 | } | ||
| 14 | |||
| 15 | func CmdInfoInit(bytes []byte) (output CmdInfo) { | ||
| 16 | var class CmdInfo | ||
| 17 | class.Flags = int32(utils.IntFromBytes(bytes[:4])) | ||
| 18 | class.ViewOrigin = utils.FloatArrFromBytes(bytes[4:16]) | ||
| 19 | class.ViewAngles = utils.FloatArrFromBytes(bytes[16:28]) | ||
| 20 | class.LocalViewAngles = utils.FloatArrFromBytes(bytes[28:40]) | ||
| 21 | class.ViewOrigin2 = utils.FloatArrFromBytes(bytes[40:52]) | ||
| 22 | class.ViewAngles2 = utils.FloatArrFromBytes(bytes[52:64]) | ||
| 23 | class.LocalViewAngles2 = utils.FloatArrFromBytes(bytes[64:76]) | ||
| 24 | return class | ||
| 25 | } | ||
diff --git a/classes/stringTable.go b/classes/stringTable.go deleted file mode 100644 index 0833612..0000000 --- a/classes/stringTable.go +++ /dev/null | |||
| @@ -1,27 +0,0 @@ | |||
| 1 | package classes | ||
| 2 | |||
| 3 | type StringTable struct { | ||
| 4 | NumOfTables int32 | ||
| 5 | TableName string | ||
| 6 | NumOfEntries int16 | ||
| 7 | EntryName string | ||
| 8 | EntrySize int16 | ||
| 9 | EntryData []byte | ||
| 10 | NumOfClientEntries int16 | ||
| 11 | ClientEntryName string | ||
| 12 | ClientEntrySize int16 | ||
| 13 | ClientEntryData []byte | ||
| 14 | } | ||
| 15 | |||
| 16 | /* | ||
| 17 | func StringTableInit(bytes []byte) (output StringTable) { | ||
| 18 | var class StringTable | ||
| 19 | class.NumOfTables = int(utils.IntFromBytes(bytes[:1])) | ||
| 20 | class.TableName = string(bytes[1:16]) | ||
| 21 | class.ViewAngles = utils.FloatArrFromBytes(bytes[16:28]) | ||
| 22 | class.LocalViewAngles = utils.FloatArrFromBytes(bytes[28:40]) | ||
| 23 | class.ViewOrigin2 = utils.FloatArrFromBytes(bytes[40:52]) | ||
| 24 | class.ViewAngles2 = utils.FloatArrFromBytes(bytes[52:64]) | ||
| 25 | class.LocalViewAngles2 = utils.FloatArrFromBytes(bytes[64:76]) | ||
| 26 | return class | ||
| 27 | }*/ | ||
diff --git a/classes/types.go b/classes/types.go new file mode 100644 index 0000000..3fcc692 --- /dev/null +++ b/classes/types.go | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | package classes | ||
| 2 | |||
| 3 | type CmdInfo struct { | ||
| 4 | Flags int32 | ||
| 5 | ViewOrigin []float32 | ||
| 6 | ViewAngles []float32 | ||
| 7 | LocalViewAngles []float32 | ||
| 8 | ViewOrigin2 []float32 | ||
| 9 | ViewAngles2 []float32 | ||
| 10 | LocalViewAngles2 []float32 | ||
| 11 | } | ||
| 12 | |||
| 13 | type UserCmdInfo struct { | ||
| 14 | CommandNumber int32 | ||
| 15 | TickCount int32 | ||
| 16 | ViewAnglesX float32 | ||
| 17 | ViewAnglesY float32 | ||
| 18 | ViewAnglesZ float32 | ||
| 19 | ForwardMove float32 | ||
| 20 | SideMove float32 | ||
| 21 | UpMove float32 | ||
| 22 | Buttons int32 | ||
| 23 | Impulse int8 | ||
| 24 | WeaponSelect int | ||
| 25 | WeaponSubtype int | ||
| 26 | MouseDx int16 | ||
| 27 | MouseDy int16 | ||
| 28 | } | ||
diff --git a/classes/userCmdInfo.go b/classes/userCmdInfo.go deleted file mode 100644 index d2de229..0000000 --- a/classes/userCmdInfo.go +++ /dev/null | |||
| @@ -1,72 +0,0 @@ | |||
| 1 | package classes | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "fmt" | ||
| 5 | |||
| 6 | "github.com/bisaxa/demoparser/utils" | ||
| 7 | ) | ||
| 8 | |||
| 9 | type UserCmdInfo struct { | ||
| 10 | CommandNumber int32 | ||
| 11 | TickCount int32 | ||
| 12 | ViewAnglesX float32 | ||
| 13 | ViewAnglesY float32 | ||
| 14 | ViewAnglesZ float32 | ||
| 15 | ForwardMove float32 | ||
| 16 | SideMove float32 | ||
| 17 | UpMove float32 | ||
| 18 | Buttons int32 | ||
| 19 | // Impulse byte } | ||
| 20 | // WeaponSelect int32 } | ||
| 21 | // WeaponSubtype int32 Not worth the effort, no one cares about these | ||
| 22 | // MouseDx int16 } | ||
| 23 | // MouseDy int } | ||
| 24 | } | ||
| 25 | |||
| 26 | // It is so janky it hurts, but hey it is at least working (hopefully) | ||
| 27 | // Reading the data is really weird, who even implemented this smh | ||
| 28 | func UserCmdInfoInit(byteArr []byte, size int32) (output UserCmdInfo) { | ||
| 29 | var class UserCmdInfo | ||
| 30 | successCount := 0 | ||
| 31 | failedCount := 0 | ||
| 32 | looped := 0 | ||
| 33 | classIndex := 0 | ||
| 34 | //fmt.Println(byteArr) | ||
| 35 | fmt.Printf("%08b\n", byteArr) | ||
| 36 | for i := 0; i < 9; i++ { | ||
| 37 | if successCount+failedCount > 7 { | ||
| 38 | failedCount = -successCount | ||
| 39 | looped++ | ||
| 40 | } | ||
| 41 | firstBit, err := utils.ReadBitStateLSB(byteArr[successCount*4+looped], successCount+failedCount) | ||
| 42 | utils.CheckError(err) | ||
| 43 | if firstBit { | ||
| 44 | successCount++ | ||
| 45 | switch classIndex { | ||
| 46 | case 0: | ||
| 47 | class.CommandNumber = utils.Read32BitsAfterFirstBitInt32(byteArr, successCount+failedCount, successCount*4+looped) | ||
| 48 | case 1: | ||
| 49 | class.TickCount = utils.Read32BitsAfterFirstBitInt32(byteArr, successCount+failedCount, successCount*4+looped) | ||
| 50 | case 2: | ||
| 51 | class.ViewAnglesX = utils.Read32BitsAfterFirstBitFloat32(byteArr, successCount+failedCount, successCount*4+looped) | ||
| 52 | case 3: | ||
| 53 | class.ViewAnglesY = utils.Read32BitsAfterFirstBitFloat32(byteArr, successCount+failedCount, successCount*4+looped) | ||
| 54 | case 4: | ||
| 55 | class.ViewAnglesZ = utils.Read32BitsAfterFirstBitFloat32(byteArr, successCount+failedCount, successCount*4+looped) | ||
| 56 | case 5: | ||
| 57 | class.ForwardMove = utils.Read32BitsAfterFirstBitFloat32(byteArr, successCount+failedCount, successCount*4+looped) | ||
| 58 | case 6: | ||
| 59 | class.SideMove = utils.Read32BitsAfterFirstBitFloat32(byteArr, successCount+failedCount, successCount*4+looped) | ||
| 60 | case 7: | ||
| 61 | class.UpMove = utils.Read32BitsAfterFirstBitFloat32(byteArr, successCount+failedCount, successCount*4+looped) | ||
| 62 | case 8: | ||
| 63 | class.Buttons = utils.Read32BitsAfterFirstBitInt32(byteArr, successCount+failedCount, successCount*4+looped) | ||
| 64 | } | ||
| 65 | classIndex++ | ||
| 66 | } else { | ||
| 67 | failedCount++ | ||
| 68 | classIndex++ | ||
| 69 | } | ||
| 70 | } | ||
| 71 | return class | ||
| 72 | } | ||