diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-09-16 20:39:02 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-09-16 21:39:43 +0300 |
| commit | 81f365e99636104ff81151370048a51e8ae8027a (patch) | |
| tree | 0bd2781ad73fdc982abdcb70f9f44c551ac76bcf | |
| parent | update CI workflow for go 1.21.0 (diff) | |
| download | sdp.go-81f365e99636104ff81151370048a51e8ae8027a.tar.gz sdp.go-81f365e99636104ff81151370048a51e8ae8027a.tar.bz2 sdp.go-81f365e99636104ff81151370048a51e8ae8027a.zip | |
feat: parsing sar custom data (#4)
47 files changed, 506 insertions, 157 deletions
diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml deleted file mode 100644 index f0e5e51..0000000 --- a/.github/workflows/CI.yml +++ /dev/null | |||
| @@ -1,40 +0,0 @@ | |||
| 1 | name: CI | ||
| 2 | |||
| 3 | on: | ||
| 4 | push: | ||
| 5 | branches: [ "main" ] | ||
| 6 | paths-ignore: | ||
| 7 | - '.github/*' | ||
| 8 | - '.gitignore' | ||
| 9 | - '**.md' | ||
| 10 | - 'LICENSE' | ||
| 11 | pull_request: | ||
| 12 | branches: [ "main" ] | ||
| 13 | |||
| 14 | jobs: | ||
| 15 | build-windows: | ||
| 16 | name: Windows Build | ||
| 17 | runs-on: ubuntu-latest | ||
| 18 | steps: | ||
| 19 | - uses: actions/checkout@v3 | ||
| 20 | |||
| 21 | - name: Setup Go environment | ||
| 22 | uses: actions/setup-go@v4 | ||
| 23 | with: | ||
| 24 | go-version: '1.21.0' | ||
| 25 | architecture: amd64 | ||
| 26 | - name: Build | ||
| 27 | run: cd cmd ; env GOOS=windows GOARCH=amd64 go build . | ||
| 28 | build-linux: | ||
| 29 | name: Linux Build | ||
| 30 | runs-on: ubuntu-latest | ||
| 31 | steps: | ||
| 32 | - uses: actions/checkout@v3 | ||
| 33 | |||
| 34 | - name: Setup Go environment | ||
| 35 | uses: actions/setup-go@v4 | ||
| 36 | with: | ||
| 37 | go-version: '1.21.0' | ||
| 38 | architecture: amd64 | ||
| 39 | - name: Build | ||
| 40 | run: cd cmd ; env GOOS=linux GOARCH=amd64 go build . | ||
diff --git a/cmd/parser.go b/cmd/parser.go index d03fa9c..98f4637 100644 --- a/cmd/parser.go +++ b/cmd/parser.go | |||
| @@ -9,6 +9,8 @@ import ( | |||
| 9 | "github.com/pektezol/demoparser/pkg/packets" | 9 | "github.com/pektezol/demoparser/pkg/packets" |
| 10 | ) | 10 | ) |
| 11 | 11 | ||
| 12 | const littleEndian bool = true | ||
| 13 | |||
| 12 | func main() { | 14 | func main() { |
| 13 | if len(os.Args) != 2 { | 15 | if len(os.Args) != 2 { |
| 14 | panic("specify file in command line arguments") | 16 | panic("specify file in command line arguments") |
| @@ -19,32 +21,29 @@ func main() { | |||
| 19 | if err != nil { | 21 | if err != nil { |
| 20 | panic(err) | 22 | panic(err) |
| 21 | } | 23 | } |
| 22 | reader := bitreader.Reader(file, true) | 24 | reader := bitreader.NewReader(file, littleEndian) |
| 23 | demoParserHandler(reader) | 25 | demoParserHandler(reader) |
| 24 | defer file.Close() | 26 | defer file.Close() |
| 27 | return | ||
| 25 | } | 28 | } |
| 26 | for _, fileinfo := range files { // If it is a directory | 29 | for _, fileinfo := range files { // If it is a directory |
| 27 | file, err := os.Open(os.Args[1] + fileinfo.Name()) | 30 | file, err := os.Open(os.Args[1] + fileinfo.Name()) |
| 28 | if err != nil { | 31 | if err != nil { |
| 29 | panic(err) | 32 | panic(err) |
| 30 | } | 33 | } |
| 31 | reader := bitreader.Reader(file, true) | 34 | reader := bitreader.NewReader(file, littleEndian) |
| 32 | demoParserHandler(reader) | 35 | demoParserHandler(reader) |
| 33 | defer file.Close() | 36 | defer file.Close() |
| 34 | } | 37 | } |
| 35 | // fmt.Scanln() | ||
| 36 | } | 38 | } |
| 37 | 39 | ||
| 38 | func demoParserHandler(reader *bitreader.ReaderType) { | 40 | func demoParserHandler(reader *bitreader.Reader) { |
| 39 | packets.ParseHeaders(reader) | 41 | packets.ParseHeaders(reader) |
| 40 | for { | 42 | for { |
| 41 | packet := packets.ParsePackets(reader) | 43 | packet := packets.ParsePackets(reader) |
| 44 | fmt.Printf("[%d] %s (%d):\n\t%+v\n", packet.TickNumber, reflect.ValueOf(packet.Data).Type(), packet.PacketType, packet.Data) | ||
| 42 | if packet.PacketType == 7 { | 45 | if packet.PacketType == 7 { |
| 43 | break | 46 | break |
| 44 | } | 47 | } |
| 45 | // if packet.PacketType != 5 { | ||
| 46 | // continue | ||
| 47 | // } | ||
| 48 | fmt.Printf("[%d] %s (%d):\n\t%+v\n", packet.TickNumber, reflect.ValueOf(packet.Data).Type(), packet.PacketType, packet.Data) | ||
| 49 | } | 48 | } |
| 50 | } | 49 | } |
| @@ -2,4 +2,4 @@ module github.com/pektezol/demoparser | |||
| 2 | 2 | ||
| 3 | go 1.21.0 | 3 | go 1.21.0 |
| 4 | 4 | ||
| 5 | require github.com/pektezol/bitreader v1.3.0 | 5 | require github.com/pektezol/bitreader v1.4.3 |
| @@ -1,2 +1,2 @@ | |||
| 1 | github.com/pektezol/bitreader v1.3.0 h1:VOj1M+vw0+xuBUlD4HPHdkjnVdUrHw2nwa5Ccxxm2ek= | 1 | github.com/pektezol/bitreader v1.4.3 h1:+WjsD6qOAaI6Q1jOOlEJcnaEso8vPMKRZnnaDnZhTSg= |
| 2 | github.com/pektezol/bitreader v1.3.0/go.mod h1:RKAUiA//jCPJzO10P+VSkBq4wfY38TaNjpCjQ+DmbcQ= | 2 | github.com/pektezol/bitreader v1.4.3/go.mod h1:xBQEsQpOf8B5yPrnOTkirZGyVUV6Bqp0ups2RIlTskk= |
diff --git a/pkg/classes/cmdInfo.go b/pkg/classes/cmdInfo.go index 6e56c41..b56afed 100644 --- a/pkg/classes/cmdInfo.go +++ b/pkg/classes/cmdInfo.go | |||
| @@ -14,7 +14,7 @@ type CmdInfo struct { | |||
| 14 | LocalViewAngles2 []float32 | 14 | LocalViewAngles2 []float32 |
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | func ParseCmdInfo(reader *bitreader.ReaderType) CmdInfo { | 17 | func ParseCmdInfo(reader *bitreader.Reader) CmdInfo { |
| 18 | return CmdInfo{ | 18 | return CmdInfo{ |
| 19 | Flags: int32(reader.TryReadBits(32)), | 19 | Flags: int32(reader.TryReadBits(32)), |
| 20 | ViewOrigin: []float32{reader.TryReadFloat32(), reader.TryReadFloat32(), reader.TryReadFloat32()}, | 20 | ViewOrigin: []float32{reader.TryReadFloat32(), reader.TryReadFloat32(), reader.TryReadFloat32()}, |
diff --git a/pkg/classes/sarData.go b/pkg/classes/sarData.go new file mode 100644 index 0000000..133b67a --- /dev/null +++ b/pkg/classes/sarData.go | |||
| @@ -0,0 +1,378 @@ | |||
| 1 | package classes | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "errors" | ||
| 5 | "fmt" | ||
| 6 | |||
| 7 | "github.com/pektezol/bitreader" | ||
| 8 | ) | ||
| 9 | |||
| 10 | type SarDataType uint8 | ||
| 11 | |||
| 12 | const ( | ||
| 13 | ESarDataTimescaleCheat SarDataType = 0x01 | ||
| 14 | ESarDataInitialCVar SarDataType = 0x02 | ||
| 15 | ESarDataEntityInput SarDataType = 0x03 | ||
| 16 | ESarDataEntityInputSlot SarDataType = 0x04 | ||
| 17 | ESarDataPortalPlacement SarDataType = 0x05 | ||
| 18 | ESarDataChallengeFlags SarDataType = 0x06 | ||
| 19 | ESarDataCrouchFly SarDataType = 0x07 | ||
| 20 | ESarDataPause SarDataType = 0x08 | ||
| 21 | ESarDataWaitRun SarDataType = 0x09 | ||
| 22 | ESarDataSpeedrunTime SarDataType = 0x0A | ||
| 23 | ESarDataTimestamp SarDataType = 0x0B | ||
| 24 | ESarDataFileChecksum SarDataType = 0x0C | ||
| 25 | ESarDataHWaitRun SarDataType = 0x0D | ||
| 26 | ESarDataChecksum SarDataType = 0xFF | ||
| 27 | ESarDataChecksumV2 SarDataType = 0xFE | ||
| 28 | ESarDataInvalid SarDataType = iota | ||
| 29 | ) | ||
| 30 | |||
| 31 | func (t SarDataType) String() string { | ||
| 32 | switch t { | ||
| 33 | case ESarDataTimescaleCheat: | ||
| 34 | return "SarDataTimescaleCheat" | ||
| 35 | case ESarDataInitialCVar: | ||
| 36 | return "SarDataInitialCVar" | ||
| 37 | case ESarDataEntityInput: | ||
| 38 | return "SarDataEntityInput" | ||
| 39 | case ESarDataEntityInputSlot: | ||
| 40 | return "SarDataEntityInputSlot" | ||
| 41 | case ESarDataPortalPlacement: | ||
| 42 | return "SarDataPortalPlacement" | ||
| 43 | case ESarDataChallengeFlags: | ||
| 44 | return "SarDataChallengeFlags" | ||
| 45 | case ESarDataCrouchFly: | ||
| 46 | return "SarDataCrouchFly" | ||
| 47 | case ESarDataPause: | ||
| 48 | return "SarDataPause" | ||
| 49 | case ESarDataWaitRun: | ||
| 50 | return "SarDataWaitRun" | ||
| 51 | case ESarDataSpeedrunTime: | ||
| 52 | return "SarDataSpeedrunTime" | ||
| 53 | case ESarDataTimestamp: | ||
| 54 | return "SarDataTimestamp" | ||
| 55 | case ESarDataFileChecksum: | ||
| 56 | return "SarDataFileChecksum" | ||
| 57 | case ESarDataHWaitRun: | ||
| 58 | return "SarDataHWaitRun" | ||
| 59 | case ESarDataChecksum: | ||
| 60 | return "SarDataChecksum" | ||
| 61 | case ESarDataChecksumV2: | ||
| 62 | return "SarDataChecksumV2" | ||
| 63 | case ESarDataInvalid: | ||
| 64 | return "SarDataInvalid" | ||
| 65 | default: | ||
| 66 | return fmt.Sprintf("%d", int(t)) | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | type SarData struct { | ||
| 71 | Type SarDataType | ||
| 72 | Slot int | ||
| 73 | Data any | ||
| 74 | } | ||
| 75 | |||
| 76 | type SarDataTimescaleCheat struct { | ||
| 77 | Timescale float32 | ||
| 78 | } | ||
| 79 | |||
| 80 | type SarDataInitialCVar struct { | ||
| 81 | CVar string | ||
| 82 | Val string | ||
| 83 | } | ||
| 84 | |||
| 85 | type SarDataChecksum struct { | ||
| 86 | DemoSum uint32 | ||
| 87 | SarSum uint32 | ||
| 88 | } | ||
| 89 | |||
| 90 | type SarDataChecksumV2 struct { | ||
| 91 | SarSum uint32 | ||
| 92 | Signature [64]byte | ||
| 93 | } | ||
| 94 | |||
| 95 | type SarDataEntityInput struct { | ||
| 96 | TargetName string | ||
| 97 | ClassName string | ||
| 98 | InputName string | ||
| 99 | Parameter string | ||
| 100 | } | ||
| 101 | |||
| 102 | type SarDataPortalPlacement struct { | ||
| 103 | Orange bool | ||
| 104 | X float32 | ||
| 105 | Y float32 | ||
| 106 | Z float32 | ||
| 107 | } | ||
| 108 | |||
| 109 | type SarDataPause struct { | ||
| 110 | PauseTicks uint32 | ||
| 111 | } | ||
| 112 | |||
| 113 | type SarDataWaitRun struct { | ||
| 114 | Ticks int | ||
| 115 | Cmd string | ||
| 116 | } | ||
| 117 | |||
| 118 | type SarDataHWaitRun struct { | ||
| 119 | Ticks int | ||
| 120 | Cmd string | ||
| 121 | } | ||
| 122 | |||
| 123 | type SarDataSpeedrunTime struct { | ||
| 124 | NSplits uint32 | ||
| 125 | Splits []SarDataSpeedrunTimeSplits | ||
| 126 | } | ||
| 127 | |||
| 128 | type SarDataSpeedrunTimeSegs struct { | ||
| 129 | Name string | ||
| 130 | Ticks uint32 | ||
| 131 | } | ||
| 132 | |||
| 133 | type SarDataSpeedrunTimeSplits struct { | ||
| 134 | Name string | ||
| 135 | NSegs uint32 | ||
| 136 | Segs []SarDataSpeedrunTimeSegs | ||
| 137 | } | ||
| 138 | |||
| 139 | type SarDataTimestamp struct { | ||
| 140 | Year uint16 | ||
| 141 | Mon uint8 | ||
| 142 | Day uint8 | ||
| 143 | Hour uint8 | ||
| 144 | Min uint8 | ||
| 145 | Sec uint8 | ||
| 146 | } | ||
| 147 | |||
| 148 | type SarDataFileChecksum struct { | ||
| 149 | Sum uint32 | ||
| 150 | Path string | ||
| 151 | } | ||
| 152 | |||
| 153 | func (sarData *SarData) ParseSarData(reader *bitreader.Reader) (err error) { | ||
| 154 | reader.SkipBytes(8) | ||
| 155 | len := reader.TryReadRemainingBits() / 8 | ||
| 156 | if len == 0 { | ||
| 157 | sarData.Type = ESarDataInvalid | ||
| 158 | err = errors.New("sar data invalid") | ||
| 159 | return err | ||
| 160 | } | ||
| 161 | sarData.Type = SarDataType(reader.TryReadBytes(1)) | ||
| 162 | if sarData.Type == ESarDataChecksum && len == 5 { | ||
| 163 | len = 9 | ||
| 164 | } | ||
| 165 | dataReader := bitreader.NewReaderFromBytes(reader.TryReadBytesToSlice(len-1), true) | ||
| 166 | switch sarData.Type { | ||
| 167 | case ESarDataTimescaleCheat: | ||
| 168 | sarData.Data, err = parseTimescaleCheatData(dataReader, len) | ||
| 169 | if err != nil { | ||
| 170 | sarData.Data = nil | ||
| 171 | } | ||
| 172 | case ESarDataInitialCVar: | ||
| 173 | sarData.Data = parseInitialCVarData(dataReader) | ||
| 174 | case ESarDataEntityInputSlot: | ||
| 175 | sarData.Slot = int(dataReader.TryReadBytes(1)) | ||
| 176 | case ESarDataEntityInput: | ||
| 177 | sarData.Data = parseEntityInputData(dataReader) | ||
| 178 | case ESarDataChecksum: | ||
| 179 | sarData.Data, err = parseChecksumData(dataReader, len) | ||
| 180 | if err != nil { | ||
| 181 | sarData.Data = nil | ||
| 182 | } | ||
| 183 | case ESarDataChecksumV2: | ||
| 184 | sarData.Data, err = parseChecksumV2Data(dataReader, len) | ||
| 185 | if err != nil { | ||
| 186 | sarData.Data = nil | ||
| 187 | } | ||
| 188 | case ESarDataPortalPlacement: | ||
| 189 | data, slot, err := parsePortalPlacementData(dataReader, len) | ||
| 190 | if err != nil { | ||
| 191 | sarData.Data = nil | ||
| 192 | } else { | ||
| 193 | sarData.Data = data | ||
| 194 | sarData.Slot = slot | ||
| 195 | } | ||
| 196 | case ESarDataChallengeFlags, ESarDataCrouchFly: | ||
| 197 | sarData.Slot, err = parseChallengeFlagsCrouchFlyData(dataReader, len) | ||
| 198 | if err != nil { | ||
| 199 | sarData.Data = nil | ||
| 200 | } | ||
| 201 | case ESarDataPause: | ||
| 202 | sarData.Data, err = parsePauseData(dataReader, len) | ||
| 203 | if err != nil { | ||
| 204 | sarData.Data = nil | ||
| 205 | } | ||
| 206 | case ESarDataWaitRun: | ||
| 207 | sarData.Data, err = parseWaitRunData(dataReader, len) | ||
| 208 | if err != nil { | ||
| 209 | sarData.Data = nil | ||
| 210 | } | ||
| 211 | case ESarDataHWaitRun: | ||
| 212 | sarData.Data, err = parseHWaitRunData(dataReader, len) | ||
| 213 | if err != nil { | ||
| 214 | sarData.Data = nil | ||
| 215 | } | ||
| 216 | case ESarDataSpeedrunTime: | ||
| 217 | sarData.Data, err = parseSpeedrunTimeData(dataReader, len) | ||
| 218 | if err != nil { | ||
| 219 | sarData.Data = nil | ||
| 220 | } | ||
| 221 | case ESarDataTimestamp: | ||
| 222 | sarData.Data, err = parseTimestampData(dataReader, len) | ||
| 223 | if err != nil { | ||
| 224 | sarData.Data = nil | ||
| 225 | } | ||
| 226 | case ESarDataFileChecksum: | ||
| 227 | sarData.Data, err = parseFileChecksumData(dataReader, len) | ||
| 228 | if err != nil { | ||
| 229 | sarData.Data = nil | ||
| 230 | } | ||
| 231 | default: | ||
| 232 | err = errors.New("unsupported SAR data type") | ||
| 233 | return err | ||
| 234 | } | ||
| 235 | return nil | ||
| 236 | } | ||
| 237 | |||
| 238 | func parseTimescaleCheatData(reader *bitreader.Reader, length uint64) (SarDataTimescaleCheat, error) { | ||
| 239 | if length != 5 { | ||
| 240 | return SarDataTimescaleCheat{}, errors.New("sar data invalid") | ||
| 241 | } | ||
| 242 | return SarDataTimescaleCheat{ | ||
| 243 | Timescale: reader.TryReadFloat32(), | ||
| 244 | }, nil | ||
| 245 | } | ||
| 246 | |||
| 247 | func parseInitialCVarData(reader *bitreader.Reader) SarDataInitialCVar { | ||
| 248 | return SarDataInitialCVar{ | ||
| 249 | CVar: reader.TryReadString(), | ||
| 250 | Val: reader.TryReadString(), | ||
| 251 | } | ||
| 252 | } | ||
| 253 | |||
| 254 | func parseEntityInputData(reader *bitreader.Reader) SarDataEntityInput { | ||
| 255 | return SarDataEntityInput{ | ||
| 256 | TargetName: reader.TryReadString(), | ||
| 257 | ClassName: reader.TryReadString(), | ||
| 258 | InputName: reader.TryReadString(), | ||
| 259 | Parameter: reader.TryReadString(), | ||
| 260 | } | ||
| 261 | } | ||
| 262 | |||
| 263 | func parseChecksumData(reader *bitreader.Reader, length uint64) (SarDataChecksum, error) { | ||
| 264 | if length != 9 { | ||
| 265 | return SarDataChecksum{}, errors.New("sar data invalid") | ||
| 266 | } | ||
| 267 | return SarDataChecksum{ | ||
| 268 | DemoSum: reader.TryReadUInt32(), | ||
| 269 | SarSum: reader.TryReadUInt32(), | ||
| 270 | }, nil | ||
| 271 | } | ||
| 272 | |||
| 273 | func parseChecksumV2Data(reader *bitreader.Reader, length uint64) (SarDataChecksumV2, error) { | ||
| 274 | if length != 69 { | ||
| 275 | return SarDataChecksumV2{}, errors.New("sar data invalid") | ||
| 276 | } | ||
| 277 | return SarDataChecksumV2{ | ||
| 278 | SarSum: reader.TryReadUInt32(), | ||
| 279 | Signature: [64]byte(reader.TryReadBytesToSlice(60)), | ||
| 280 | }, nil | ||
| 281 | } | ||
| 282 | |||
| 283 | func parsePortalPlacementData(reader *bitreader.Reader, length uint64) (SarDataPortalPlacement, int, error) { | ||
| 284 | if length != 15 { | ||
| 285 | return SarDataPortalPlacement{}, 0, errors.New("sar data invalid") | ||
| 286 | } | ||
| 287 | slot := int(reader.TryReadBytes(1)) | ||
| 288 | orange := reader.TryReadBool() | ||
| 289 | reader.SkipBits(7) | ||
| 290 | return SarDataPortalPlacement{ | ||
| 291 | Orange: orange, | ||
| 292 | X: reader.TryReadFloat32(), | ||
| 293 | Y: reader.TryReadFloat32(), | ||
| 294 | Z: reader.TryReadFloat32(), | ||
| 295 | }, slot, nil | ||
| 296 | } | ||
| 297 | |||
| 298 | func parseChallengeFlagsCrouchFlyData(reader *bitreader.Reader, length uint64) (int, error) { | ||
| 299 | if length != 2 { | ||
| 300 | return 0, errors.New("sar data invalid") | ||
| 301 | } | ||
| 302 | return int(reader.TryReadBytes(1)), nil | ||
| 303 | } | ||
| 304 | |||
| 305 | func parsePauseData(reader *bitreader.Reader, length uint64) (SarDataPause, error) { | ||
| 306 | if length != 5 { | ||
| 307 | return SarDataPause{}, errors.New("sar data invalid") | ||
| 308 | } | ||
| 309 | return SarDataPause{ | ||
| 310 | PauseTicks: reader.TryReadUInt32(), | ||
| 311 | }, nil | ||
| 312 | } | ||
| 313 | |||
| 314 | func parseWaitRunData(reader *bitreader.Reader, length uint64) (SarDataWaitRun, error) { | ||
| 315 | if length < 6 { | ||
| 316 | return SarDataWaitRun{}, errors.New("sar data invalid") | ||
| 317 | } | ||
| 318 | return SarDataWaitRun{ | ||
| 319 | Ticks: int(reader.TryReadUInt32()), | ||
| 320 | Cmd: reader.TryReadString(), | ||
| 321 | }, nil | ||
| 322 | } | ||
| 323 | |||
| 324 | func parseHWaitRunData(reader *bitreader.Reader, length uint64) (SarDataHWaitRun, error) { | ||
| 325 | if length < 6 { | ||
| 326 | return SarDataHWaitRun{}, errors.New("sar data invalid") | ||
| 327 | } | ||
| 328 | return SarDataHWaitRun{ | ||
| 329 | Ticks: int(reader.TryReadUInt32()), | ||
| 330 | Cmd: reader.TryReadString(), | ||
| 331 | }, nil | ||
| 332 | } | ||
| 333 | |||
| 334 | func parseSpeedrunTimeData(reader *bitreader.Reader, length uint64) (SarDataSpeedrunTime, error) { | ||
| 335 | if length < 5 { | ||
| 336 | return SarDataSpeedrunTime{}, errors.New("sar data invalid") | ||
| 337 | } | ||
| 338 | numberOfSplits := reader.TryReadUInt32() | ||
| 339 | splits := make([]SarDataSpeedrunTimeSplits, numberOfSplits) | ||
| 340 | for splitCount := 0; splitCount < int(numberOfSplits); splitCount++ { | ||
| 341 | splits[splitCount].Name = reader.TryReadString() | ||
| 342 | splits[splitCount].NSegs = reader.TryReadUInt32() | ||
| 343 | splits[splitCount].Segs = make([]SarDataSpeedrunTimeSegs, splits[splitCount].NSegs) | ||
| 344 | for segCount := 0; segCount < int(splits[splitCount].NSegs); segCount++ { | ||
| 345 | splits[splitCount].Segs[segCount].Name = reader.TryReadString() | ||
| 346 | splits[splitCount].Segs[segCount].Ticks = reader.TryReadUInt32() | ||
| 347 | } | ||
| 348 | } | ||
| 349 | return SarDataSpeedrunTime{ | ||
| 350 | NSplits: numberOfSplits, | ||
| 351 | Splits: splits, | ||
| 352 | }, nil | ||
| 353 | } | ||
| 354 | |||
| 355 | func parseTimestampData(reader *bitreader.Reader, length uint64) (SarDataTimestamp, error) { | ||
| 356 | if length != 8 { | ||
| 357 | return SarDataTimestamp{}, errors.New("sar data invalid") | ||
| 358 | } | ||
| 359 | timestamp := reader.TryReadBytesToSlice(7) | ||
| 360 | return SarDataTimestamp{ | ||
| 361 | Year: uint16(timestamp[0]) | uint16(timestamp[1])<<8, | ||
| 362 | Mon: timestamp[2] + 1, | ||
| 363 | Day: timestamp[3], | ||
| 364 | Hour: timestamp[4], | ||
| 365 | Min: timestamp[5], | ||
| 366 | Sec: timestamp[6], | ||
| 367 | }, nil | ||
| 368 | } | ||
| 369 | |||
| 370 | func parseFileChecksumData(reader *bitreader.Reader, length uint64) (SarDataFileChecksum, error) { | ||
| 371 | if length < 6 { | ||
| 372 | return SarDataFileChecksum{}, errors.New("sar data invalid") | ||
| 373 | } | ||
| 374 | return SarDataFileChecksum{ | ||
| 375 | Sum: reader.TryReadUInt32(), | ||
| 376 | Path: reader.TryReadString(), | ||
| 377 | }, nil | ||
| 378 | } | ||
diff --git a/pkg/classes/sendTable.go b/pkg/classes/sendTable.go index 4521464..bc36d75 100644 --- a/pkg/classes/sendTable.go +++ b/pkg/classes/sendTable.go | |||
| @@ -59,7 +59,7 @@ const ( | |||
| 59 | DataTable | 59 | DataTable |
| 60 | ) | 60 | ) |
| 61 | 61 | ||
| 62 | func ParseSendTable(reader *bitreader.ReaderType) SendTable { | 62 | func ParseSendTable(reader *bitreader.Reader) SendTable { |
| 63 | sendTable := SendTable{ | 63 | sendTable := SendTable{ |
| 64 | NeedsDecoder: reader.TryReadBool(), | 64 | NeedsDecoder: reader.TryReadBool(), |
| 65 | NetTableName: reader.TryReadString(), | 65 | NetTableName: reader.TryReadString(), |
diff --git a/pkg/classes/serverClassInfo.go b/pkg/classes/serverClassInfo.go index c60dad1..fbccffb 100644 --- a/pkg/classes/serverClassInfo.go +++ b/pkg/classes/serverClassInfo.go | |||
| @@ -10,7 +10,7 @@ type ServerClassInfo struct { | |||
| 10 | DataTableName string | 10 | DataTableName string |
| 11 | } | 11 | } |
| 12 | 12 | ||
| 13 | func ParseServerClassInfo(reader *bitreader.ReaderType, count int, numOfClasses int) ServerClassInfo { | 13 | func ParseServerClassInfo(reader *bitreader.Reader, count int, numOfClasses int) ServerClassInfo { |
| 14 | return ServerClassInfo{ | 14 | return ServerClassInfo{ |
| 15 | ClassId: int16(reader.TryReadBits(16)), | 15 | ClassId: int16(reader.TryReadBits(16)), |
| 16 | ClassName: reader.TryReadString(), | 16 | ClassName: reader.TryReadString(), |
diff --git a/pkg/classes/stringTable.go b/pkg/classes/stringTable.go index c6709f5..3983c1f 100644 --- a/pkg/classes/stringTable.go +++ b/pkg/classes/stringTable.go | |||
| @@ -1,8 +1,6 @@ | |||
| 1 | package classes | 1 | package classes |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "bytes" | ||
| 5 | |||
| 6 | "github.com/pektezol/bitreader" | 4 | "github.com/pektezol/bitreader" |
| 7 | ) | 5 | ) |
| 8 | 6 | ||
| @@ -26,7 +24,7 @@ type StringTableClass struct { | |||
| 26 | Data string | 24 | Data string |
| 27 | } | 25 | } |
| 28 | 26 | ||
| 29 | func ParseStringTables(reader *bitreader.ReaderType) []StringTable { | 27 | func ParseStringTables(reader *bitreader.Reader) []StringTable { |
| 30 | tableCount := reader.TryReadBits(8) | 28 | tableCount := reader.TryReadBits(8) |
| 31 | stringTables := make([]StringTable, tableCount) | 29 | stringTables := make([]StringTable, tableCount) |
| 32 | for i := 0; i < int(tableCount); i++ { | 30 | for i := 0; i < int(tableCount); i++ { |
| @@ -37,7 +35,7 @@ func ParseStringTables(reader *bitreader.ReaderType) []StringTable { | |||
| 37 | return stringTables | 35 | return stringTables |
| 38 | } | 36 | } |
| 39 | 37 | ||
| 40 | func (stringTable *StringTable) ParseStream(reader *bitreader.ReaderType) { | 38 | func (stringTable *StringTable) ParseStream(reader *bitreader.Reader) { |
| 41 | stringTable.Name = reader.TryReadString() | 39 | stringTable.Name = reader.TryReadString() |
| 42 | entryCount := reader.TryReadBits(16) | 40 | entryCount := reader.TryReadBits(16) |
| 43 | stringTable.TableEntries = make([]StringTableEntry, entryCount) | 41 | stringTable.TableEntries = make([]StringTableEntry, entryCount) |
| @@ -60,23 +58,23 @@ func (stringTable *StringTable) ParseStream(reader *bitreader.ReaderType) { | |||
| 60 | } | 58 | } |
| 61 | } | 59 | } |
| 62 | 60 | ||
| 63 | func (stringTableEntry *StringTableEntry) Parse(reader *bitreader.ReaderType) { | 61 | func (stringTableEntry *StringTableEntry) Parse(reader *bitreader.Reader) { |
| 64 | stringTableEntry.Name = reader.TryReadString() | 62 | stringTableEntry.Name = reader.TryReadString() |
| 65 | if reader.TryReadBool() { | 63 | if reader.TryReadBool() { |
| 66 | byteLen, err := reader.ReadBits(16) | 64 | byteLen, err := reader.ReadBits(16) |
| 67 | if err != nil { | 65 | if err != nil { |
| 68 | return | 66 | return |
| 69 | } | 67 | } |
| 70 | dataBsr := reader.TryReadBytesToSlice(int(byteLen)) | 68 | dataBsr := reader.TryReadBytesToSlice(byteLen) |
| 71 | _ = bitreader.Reader(bytes.NewReader(dataBsr), true) // TODO: Parse StringTableEntry | 69 | _ = bitreader.NewReaderFromBytes(dataBsr, true) // TODO: Parse StringTableEntry |
| 72 | // stringTableEntry.EntryData.ParseStream(entryReader) | 70 | // stringTableEntry.EntryData.ParseStream(entryReader) |
| 73 | } | 71 | } |
| 74 | } | 72 | } |
| 75 | 73 | ||
| 76 | func (stringTableClass *StringTableClass) Parse(reader *bitreader.ReaderType) { | 74 | func (stringTableClass *StringTableClass) Parse(reader *bitreader.Reader) { |
| 77 | stringTableClass.Name = reader.TryReadString() | 75 | stringTableClass.Name = reader.TryReadString() |
| 78 | if reader.TryReadBool() { | 76 | if reader.TryReadBool() { |
| 79 | dataLen := reader.TryReadBits(16) | 77 | dataLen := reader.TryReadBits(16) |
| 80 | stringTableClass.Data = reader.TryReadStringLen(int(dataLen)) | 78 | stringTableClass.Data = reader.TryReadStringLength(dataLen) |
| 81 | } | 79 | } |
| 82 | } | 80 | } |
diff --git a/pkg/classes/userCmdInfo.go b/pkg/classes/userCmdInfo.go index a6d9091..04d76b6 100644 --- a/pkg/classes/userCmdInfo.go +++ b/pkg/classes/userCmdInfo.go | |||
| @@ -24,7 +24,7 @@ type UserCmdInfo struct { | |||
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | func ParseUserCmdInfo(data []byte) UserCmdInfo { | 26 | func ParseUserCmdInfo(data []byte) UserCmdInfo { |
| 27 | reader := bitreader.Reader(bytes.NewReader(data), true) | 27 | reader := bitreader.NewReader(bytes.NewReader(data), true) |
| 28 | userCmdInfo := UserCmdInfo{} | 28 | userCmdInfo := UserCmdInfo{} |
| 29 | if reader.TryReadBool() { | 29 | if reader.TryReadBool() { |
| 30 | userCmdInfo.CommandNumber = int32(reader.TryReadBits(32)) | 30 | userCmdInfo.CommandNumber = int32(reader.TryReadBits(32)) |
diff --git a/pkg/messages/messages.go b/pkg/messages/messages.go index 39f89e9..6fa58fc 100644 --- a/pkg/messages/messages.go +++ b/pkg/messages/messages.go | |||
| @@ -8,7 +8,7 @@ import ( | |||
| 8 | messages "github.com/pektezol/demoparser/pkg/messages/types" | 8 | messages "github.com/pektezol/demoparser/pkg/messages/types" |
| 9 | ) | 9 | ) |
| 10 | 10 | ||
| 11 | func ParseMessages(messageType int, reader *bitreader.ReaderType) any { | 11 | func ParseMessages(messageType int, reader *bitreader.Reader) any { |
| 12 | var messageData any | 12 | var messageData any |
| 13 | switch messageType { | 13 | switch messageType { |
| 14 | case 0: | 14 | case 0: |
diff --git a/pkg/messages/types/netDisconnect.go b/pkg/messages/types/netDisconnect.go index 69d4a67..3ecf8e1 100644 --- a/pkg/messages/types/netDisconnect.go +++ b/pkg/messages/types/netDisconnect.go | |||
| @@ -6,7 +6,7 @@ type NetDisconnect struct { | |||
| 6 | Text string | 6 | Text string |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | func ParseNetDisconnect(reader *bitreader.ReaderType) NetDisconnect { | 9 | func ParseNetDisconnect(reader *bitreader.Reader) NetDisconnect { |
| 10 | return NetDisconnect{ | 10 | return NetDisconnect{ |
| 11 | Text: reader.TryReadString(), | 11 | Text: reader.TryReadString(), |
| 12 | } | 12 | } |
diff --git a/pkg/messages/types/netFile.go b/pkg/messages/types/netFile.go index a41a0cf..328900c 100644 --- a/pkg/messages/types/netFile.go +++ b/pkg/messages/types/netFile.go | |||
| @@ -8,7 +8,7 @@ type NetFile struct { | |||
| 8 | FileRequested bool | 8 | FileRequested bool |
| 9 | } | 9 | } |
| 10 | 10 | ||
| 11 | func ParseNetFile(reader *bitreader.ReaderType) NetFile { | 11 | func ParseNetFile(reader *bitreader.Reader) NetFile { |
| 12 | return NetFile{ | 12 | return NetFile{ |
| 13 | TransferId: int32(reader.TryReadBits(32)), | 13 | TransferId: int32(reader.TryReadBits(32)), |
| 14 | FileName: reader.TryReadString(), | 14 | FileName: reader.TryReadString(), |
diff --git a/pkg/messages/types/netNop.go b/pkg/messages/types/netNop.go index 33f8e25..f942786 100644 --- a/pkg/messages/types/netNop.go +++ b/pkg/messages/types/netNop.go | |||
| @@ -4,6 +4,6 @@ import "github.com/pektezol/bitreader" | |||
| 4 | 4 | ||
| 5 | type NetNop struct{} | 5 | type NetNop struct{} |
| 6 | 6 | ||
| 7 | func ParseNetNop(reader *bitreader.ReaderType) NetNop { | 7 | func ParseNetNop(reader *bitreader.Reader) NetNop { |
| 8 | return NetNop{} | 8 | return NetNop{} |
| 9 | } | 9 | } |
diff --git a/pkg/messages/types/netSetConVar.go b/pkg/messages/types/netSetConVar.go index 08042ae..f04f564 100644 --- a/pkg/messages/types/netSetConVar.go +++ b/pkg/messages/types/netSetConVar.go | |||
| @@ -12,7 +12,7 @@ type conVar struct { | |||
| 12 | Value string | 12 | Value string |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | func ParseNetSetConVar(reader *bitreader.ReaderType) NetSetConVar { | 15 | func ParseNetSetConVar(reader *bitreader.Reader) NetSetConVar { |
| 16 | length := reader.TryReadBits(8) | 16 | length := reader.TryReadBits(8) |
| 17 | convars := []conVar{} | 17 | convars := []conVar{} |
| 18 | for count := 0; count < int(length); count++ { | 18 | for count := 0; count < int(length); count++ { |
diff --git a/pkg/messages/types/netSignOnState.go b/pkg/messages/types/netSignOnState.go index 4609ff2..277a6ee 100644 --- a/pkg/messages/types/netSignOnState.go +++ b/pkg/messages/types/netSignOnState.go | |||
| @@ -12,15 +12,15 @@ type NetSignOnState struct { | |||
| 12 | MapName string | 12 | MapName string |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | func ParseNetSignOnState(reader *bitreader.ReaderType) NetSignOnState { | 15 | func ParseNetSignOnState(reader *bitreader.Reader) NetSignOnState { |
| 16 | netSignOnState := NetSignOnState{ | 16 | netSignOnState := NetSignOnState{ |
| 17 | SignOnState: int8(reader.TryReadBits(8)), | 17 | SignOnState: int8(reader.TryReadBits(8)), |
| 18 | SpawnCount: int32(reader.TryReadBits(32)), | 18 | SpawnCount: int32(reader.TryReadBits(32)), |
| 19 | NumServerPlayers: int32(reader.TryReadBits(32)), | 19 | NumServerPlayers: int32(reader.TryReadBits(32)), |
| 20 | IdsLength: int32(reader.TryReadBits(32)), | 20 | IdsLength: int32(reader.TryReadBits(32)), |
| 21 | } | 21 | } |
| 22 | netSignOnState.PlayersNetworksIds = reader.TryReadBytesToSlice(int(netSignOnState.IdsLength)) | 22 | netSignOnState.PlayersNetworksIds = reader.TryReadBytesToSlice(uint64(netSignOnState.IdsLength)) |
| 23 | netSignOnState.MapNameLength = int32(reader.TryReadBits(32)) | 23 | netSignOnState.MapNameLength = int32(reader.TryReadBits(32)) |
| 24 | netSignOnState.MapName = reader.TryReadStringLen(int(netSignOnState.MapNameLength)) | 24 | netSignOnState.MapName = reader.TryReadStringLength(uint64(netSignOnState.MapNameLength)) |
| 25 | return netSignOnState | 25 | return netSignOnState |
| 26 | } | 26 | } |
diff --git a/pkg/messages/types/netSplitScreenUser.go b/pkg/messages/types/netSplitScreenUser.go index 65e85f3..9e4caa8 100644 --- a/pkg/messages/types/netSplitScreenUser.go +++ b/pkg/messages/types/netSplitScreenUser.go | |||
| @@ -6,7 +6,7 @@ type NetSplitScreenUser struct { | |||
| 6 | Unknown bool | 6 | Unknown bool |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | func ParseNetSplitScreenUser(reader *bitreader.ReaderType) NetSplitScreenUser { | 9 | func ParseNetSplitScreenUser(reader *bitreader.Reader) NetSplitScreenUser { |
| 10 | return NetSplitScreenUser{ | 10 | return NetSplitScreenUser{ |
| 11 | Unknown: reader.TryReadBool(), | 11 | Unknown: reader.TryReadBool(), |
| 12 | } | 12 | } |
diff --git a/pkg/messages/types/netStringCmd.go b/pkg/messages/types/netStringCmd.go index 158658e..da5a75b 100644 --- a/pkg/messages/types/netStringCmd.go +++ b/pkg/messages/types/netStringCmd.go | |||
| @@ -6,7 +6,7 @@ type NetStringCmd struct { | |||
| 6 | Command string | 6 | Command string |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | func ParseNetStringCmd(reader *bitreader.ReaderType) NetStringCmd { | 9 | func ParseNetStringCmd(reader *bitreader.Reader) NetStringCmd { |
| 10 | return NetStringCmd{ | 10 | return NetStringCmd{ |
| 11 | Command: reader.TryReadString(), | 11 | Command: reader.TryReadString(), |
| 12 | } | 12 | } |
diff --git a/pkg/messages/types/netTick.go b/pkg/messages/types/netTick.go index e14f259..bd3464a 100644 --- a/pkg/messages/types/netTick.go +++ b/pkg/messages/types/netTick.go | |||
| @@ -8,7 +8,7 @@ type NetTick struct { | |||
| 8 | HostFrameTimeStdDeviation int16 | 8 | HostFrameTimeStdDeviation int16 |
| 9 | } | 9 | } |
| 10 | 10 | ||
| 11 | func ParseNetTick(reader *bitreader.ReaderType) NetTick { | 11 | func ParseNetTick(reader *bitreader.Reader) NetTick { |
| 12 | return NetTick{ | 12 | return NetTick{ |
| 13 | Tick: int32(reader.TryReadBits(32)), | 13 | Tick: int32(reader.TryReadBits(32)), |
| 14 | HostFrameTime: int16(reader.TryReadBits(16) / 10e5), | 14 | HostFrameTime: int16(reader.TryReadBits(16) / 10e5), |
diff --git a/pkg/messages/types/svcBspDecal.go b/pkg/messages/types/svcBspDecal.go index 484497f..dda81dd 100644 --- a/pkg/messages/types/svcBspDecal.go +++ b/pkg/messages/types/svcBspDecal.go | |||
| @@ -17,7 +17,7 @@ type vectorCoord struct { | |||
| 17 | Valid bool | 17 | Valid bool |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | func ParseSvcBspDecal(reader *bitreader.ReaderType) SvcBspDecal { | 20 | func ParseSvcBspDecal(reader *bitreader.Reader) SvcBspDecal { |
| 21 | svcBspDecal := SvcBspDecal{ | 21 | svcBspDecal := SvcBspDecal{ |
| 22 | Pos: readVectorCoords(reader), | 22 | Pos: readVectorCoords(reader), |
| 23 | DecalTextureIndex: int16(reader.TryReadBits(9)), | 23 | DecalTextureIndex: int16(reader.TryReadBits(9)), |
| @@ -30,7 +30,7 @@ func ParseSvcBspDecal(reader *bitreader.ReaderType) SvcBspDecal { | |||
| 30 | return svcBspDecal | 30 | return svcBspDecal |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | func readVectorCoords(reader *bitreader.ReaderType) []vectorCoord { | 33 | func readVectorCoords(reader *bitreader.Reader) []vectorCoord { |
| 34 | const COORD_INTEGER_BITS uint8 = 14 | 34 | const COORD_INTEGER_BITS uint8 = 14 |
| 35 | const COORD_FRACTIONAL_BITS uint8 = 5 | 35 | const COORD_FRACTIONAL_BITS uint8 = 5 |
| 36 | const COORD_DENOMINATOR uint8 = 1 << COORD_FRACTIONAL_BITS | 36 | const COORD_DENOMINATOR uint8 = 1 << COORD_FRACTIONAL_BITS |
| @@ -42,10 +42,10 @@ func readVectorCoords(reader *bitreader.ReaderType) []vectorCoord { | |||
| 42 | if integer != 0 || fraction != 0 { | 42 | if integer != 0 || fraction != 0 { |
| 43 | sign := reader.TryReadBits(1) | 43 | sign := reader.TryReadBits(1) |
| 44 | if integer != 0 { | 44 | if integer != 0 { |
| 45 | integer = reader.TryReadBits(int(COORD_INTEGER_BITS)) + 1 | 45 | integer = reader.TryReadBits(uint64(COORD_INTEGER_BITS)) + 1 |
| 46 | } | 46 | } |
| 47 | if fraction != 0 { | 47 | if fraction != 0 { |
| 48 | fraction = reader.TryReadBits(int(COORD_FRACTIONAL_BITS)) | 48 | fraction = reader.TryReadBits(uint64(COORD_FRACTIONAL_BITS)) |
| 49 | } | 49 | } |
| 50 | value = float32(integer) + float32(fraction)*COORD_RESOLUTION | 50 | value = float32(integer) + float32(fraction)*COORD_RESOLUTION |
| 51 | if sign != 0 { | 51 | if sign != 0 { |
diff --git a/pkg/messages/types/svcClassInfo.go b/pkg/messages/types/svcClassInfo.go index 9f367d3..27862bf 100644 --- a/pkg/messages/types/svcClassInfo.go +++ b/pkg/messages/types/svcClassInfo.go | |||
| @@ -19,7 +19,7 @@ type serverClass struct { | |||
| 19 | DataTableName string | 19 | DataTableName string |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | func ParseSvcClassInfo(reader *bitreader.ReaderType) SvcClassInfo { | 22 | func ParseSvcClassInfo(reader *bitreader.Reader) SvcClassInfo { |
| 23 | svcClassInfo := SvcClassInfo{ | 23 | svcClassInfo := SvcClassInfo{ |
| 24 | Length: int16(reader.TryReadBits(16)), | 24 | Length: int16(reader.TryReadBits(16)), |
| 25 | CreateOnClient: reader.TryReadBool(), | 25 | CreateOnClient: reader.TryReadBool(), |
| @@ -29,7 +29,7 @@ func ParseSvcClassInfo(reader *bitreader.ReaderType) SvcClassInfo { | |||
| 29 | for count := 0; count < int(svcClassInfo.Length); count++ { | 29 | for count := 0; count < int(svcClassInfo.Length); count++ { |
| 30 | fmt.Println(classes) | 30 | fmt.Println(classes) |
| 31 | classes = append(classes, serverClass{ | 31 | classes = append(classes, serverClass{ |
| 32 | ClassId: int16(reader.TryReadBits(int(math.Log2(float64(svcClassInfo.Length)) + 1))), | 32 | ClassId: int16(reader.TryReadBits(uint64(math.Log2(float64(svcClassInfo.Length)) + 1))), |
| 33 | ClassName: reader.TryReadString(), | 33 | ClassName: reader.TryReadString(), |
| 34 | DataTableName: reader.TryReadString(), | 34 | DataTableName: reader.TryReadString(), |
| 35 | }) | 35 | }) |
diff --git a/pkg/messages/types/svcCmdKeyValues.go b/pkg/messages/types/svcCmdKeyValues.go index 1c4d819..35a8a8d 100644 --- a/pkg/messages/types/svcCmdKeyValues.go +++ b/pkg/messages/types/svcCmdKeyValues.go | |||
| @@ -7,10 +7,10 @@ type SvcCmdKeyValues struct { | |||
| 7 | Data []byte | 7 | Data []byte |
| 8 | } | 8 | } |
| 9 | 9 | ||
| 10 | func ParseSvcCmdKeyValues(reader *bitreader.ReaderType) SvcCmdKeyValues { | 10 | func ParseSvcCmdKeyValues(reader *bitreader.Reader) SvcCmdKeyValues { |
| 11 | svcCmdKeyValues := SvcCmdKeyValues{ | 11 | svcCmdKeyValues := SvcCmdKeyValues{ |
| 12 | Length: int32(reader.TryReadBits(32)), | 12 | Length: int32(reader.TryReadBits(32)), |
| 13 | } | 13 | } |
| 14 | svcCmdKeyValues.Data = reader.TryReadBytesToSlice(int(svcCmdKeyValues.Length)) | 14 | svcCmdKeyValues.Data = reader.TryReadBytesToSlice(uint64(svcCmdKeyValues.Length)) |
| 15 | return svcCmdKeyValues | 15 | return svcCmdKeyValues |
| 16 | } | 16 | } |
diff --git a/pkg/messages/types/svcCreateStringTable.go b/pkg/messages/types/svcCreateStringTable.go index ed9e477..3c15e5c 100644 --- a/pkg/messages/types/svcCreateStringTable.go +++ b/pkg/messages/types/svcCreateStringTable.go | |||
| @@ -18,12 +18,12 @@ type SvcCreateStringTable struct { | |||
| 18 | StringData int | 18 | StringData int |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | func ParseSvcCreateStringTable(reader *bitreader.ReaderType) SvcCreateStringTable { | 21 | func ParseSvcCreateStringTable(reader *bitreader.Reader) SvcCreateStringTable { |
| 22 | svcCreateStringTable := SvcCreateStringTable{ | 22 | svcCreateStringTable := SvcCreateStringTable{ |
| 23 | Name: reader.TryReadString(), | 23 | Name: reader.TryReadString(), |
| 24 | MaxEntries: int16(reader.TryReadBits(16)), | 24 | MaxEntries: int16(reader.TryReadBits(16)), |
| 25 | } | 25 | } |
| 26 | svcCreateStringTable.NumEntries = int8(reader.TryReadBits(int(math.Log2(float64(svcCreateStringTable.MaxEntries))) + 1)) | 26 | svcCreateStringTable.NumEntries = int8(reader.TryReadBits(uint64(math.Log2(float64(svcCreateStringTable.MaxEntries))) + 1)) |
| 27 | svcCreateStringTable.Length = int32(reader.TryReadBits(20)) | 27 | svcCreateStringTable.Length = int32(reader.TryReadBits(20)) |
| 28 | svcCreateStringTable.UserDataFixedSize = reader.TryReadBool() | 28 | svcCreateStringTable.UserDataFixedSize = reader.TryReadBool() |
| 29 | if svcCreateStringTable.UserDataFixedSize { | 29 | if svcCreateStringTable.UserDataFixedSize { |
| @@ -31,6 +31,6 @@ func ParseSvcCreateStringTable(reader *bitreader.ReaderType) SvcCreateStringTabl | |||
| 31 | svcCreateStringTable.UserDataSizeBits = int8(reader.TryReadBits(4)) | 31 | svcCreateStringTable.UserDataSizeBits = int8(reader.TryReadBits(4)) |
| 32 | } | 32 | } |
| 33 | svcCreateStringTable.Flags = int8(reader.TryReadBits(2)) | 33 | svcCreateStringTable.Flags = int8(reader.TryReadBits(2)) |
| 34 | reader.SkipBits(int(svcCreateStringTable.Length)) // TODO: StringTable parsing | 34 | reader.SkipBits(uint64(svcCreateStringTable.Length)) // TODO: StringTable parsing |
| 35 | return svcCreateStringTable | 35 | return svcCreateStringTable |
| 36 | } | 36 | } |
diff --git a/pkg/messages/types/svcCrosshairAngle.go b/pkg/messages/types/svcCrosshairAngle.go index cf18212..e8424e1 100644 --- a/pkg/messages/types/svcCrosshairAngle.go +++ b/pkg/messages/types/svcCrosshairAngle.go | |||
| @@ -6,7 +6,7 @@ type SvcCrosshairAngle struct { | |||
| 6 | Angle []int16 | 6 | Angle []int16 |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | func ParseSvcCrosshairAngle(reader *bitreader.ReaderType) SvcCrosshairAngle { | 9 | func ParseSvcCrosshairAngle(reader *bitreader.Reader) SvcCrosshairAngle { |
| 10 | return SvcCrosshairAngle{ | 10 | return SvcCrosshairAngle{ |
| 11 | Angle: []int16{int16(reader.TryReadBits(16)), int16(reader.TryReadBits(16)), int16(reader.TryReadBits(16))}, | 11 | Angle: []int16{int16(reader.TryReadBits(16)), int16(reader.TryReadBits(16)), int16(reader.TryReadBits(16))}, |
| 12 | } | 12 | } |
diff --git a/pkg/messages/types/svcEntityMessage.go b/pkg/messages/types/svcEntityMessage.go index 9726ced..8d5c4aa 100644 --- a/pkg/messages/types/svcEntityMessage.go +++ b/pkg/messages/types/svcEntityMessage.go | |||
| @@ -9,12 +9,12 @@ type SvcEntityMessage struct { | |||
| 9 | Data []byte | 9 | Data []byte |
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | func ParseSvcEntityMessage(reader *bitreader.ReaderType) SvcEntityMessage { | 12 | func ParseSvcEntityMessage(reader *bitreader.Reader) SvcEntityMessage { |
| 13 | svcEntityMessage := SvcEntityMessage{ | 13 | svcEntityMessage := SvcEntityMessage{ |
| 14 | EntityIndex: int16(reader.TryReadBits(11)), | 14 | EntityIndex: int16(reader.TryReadBits(11)), |
| 15 | ClassId: int16(reader.TryReadBits(9)), | 15 | ClassId: int16(reader.TryReadBits(9)), |
| 16 | Length: int16(reader.TryReadBits(11)), | 16 | Length: int16(reader.TryReadBits(11)), |
| 17 | } | 17 | } |
| 18 | svcEntityMessage.Data = reader.TryReadBitsToSlice(int(svcEntityMessage.Length)) | 18 | svcEntityMessage.Data = reader.TryReadBitsToSlice(uint64(svcEntityMessage.Length)) |
| 19 | return svcEntityMessage | 19 | return svcEntityMessage |
| 20 | } | 20 | } |
diff --git a/pkg/messages/types/svcFixAngle.go b/pkg/messages/types/svcFixAngle.go index 56acf04..675c50e 100644 --- a/pkg/messages/types/svcFixAngle.go +++ b/pkg/messages/types/svcFixAngle.go | |||
| @@ -7,7 +7,7 @@ type SvcFixAngle struct { | |||
| 7 | Angle []int16 | 7 | Angle []int16 |
| 8 | } | 8 | } |
| 9 | 9 | ||
| 10 | func ParseSvcFixAngle(reader *bitreader.ReaderType) SvcFixAngle { | 10 | func ParseSvcFixAngle(reader *bitreader.Reader) SvcFixAngle { |
| 11 | return SvcFixAngle{ | 11 | return SvcFixAngle{ |
| 12 | Relative: reader.TryReadBool(), | 12 | Relative: reader.TryReadBool(), |
| 13 | Angle: []int16{int16(reader.TryReadBits(16)), int16(reader.TryReadBits(16)), int16(reader.TryReadBits(16))}, | 13 | Angle: []int16{int16(reader.TryReadBits(16)), int16(reader.TryReadBits(16)), int16(reader.TryReadBits(16))}, |
diff --git a/pkg/messages/types/svcGameEvent.go b/pkg/messages/types/svcGameEvent.go index 6ee4d01..44d6dd5 100644 --- a/pkg/messages/types/svcGameEvent.go +++ b/pkg/messages/types/svcGameEvent.go | |||
| @@ -7,10 +7,10 @@ type SvcGameEvent struct { | |||
| 7 | Data []byte // TODO: GameEvent[] | 7 | Data []byte // TODO: GameEvent[] |
| 8 | } | 8 | } |
| 9 | 9 | ||
| 10 | func ParseSvcGameEvent(reader *bitreader.ReaderType) SvcGameEvent { | 10 | func ParseSvcGameEvent(reader *bitreader.Reader) SvcGameEvent { |
| 11 | svcGameEvent := SvcGameEvent{ | 11 | svcGameEvent := SvcGameEvent{ |
| 12 | Length: int16(reader.TryReadBits(11)), | 12 | Length: int16(reader.TryReadBits(11)), |
| 13 | } | 13 | } |
| 14 | svcGameEvent.Data = reader.TryReadBitsToSlice(int(svcGameEvent.Length)) | 14 | svcGameEvent.Data = reader.TryReadBitsToSlice(uint64(svcGameEvent.Length)) |
| 15 | return svcGameEvent | 15 | return svcGameEvent |
| 16 | } | 16 | } |
diff --git a/pkg/messages/types/svcGameEventList.go b/pkg/messages/types/svcGameEventList.go index b99ce28..c6eb896 100644 --- a/pkg/messages/types/svcGameEventList.go +++ b/pkg/messages/types/svcGameEventList.go | |||
| @@ -11,11 +11,11 @@ type SvcGameEventList struct { | |||
| 11 | type gameEventDescriptor struct { | 11 | type gameEventDescriptor struct { |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | func ParseSvcGameEventList(reader *bitreader.ReaderType) SvcGameEventList { | 14 | func ParseSvcGameEventList(reader *bitreader.Reader) SvcGameEventList { |
| 15 | svcGameEventList := SvcGameEventList{ | 15 | svcGameEventList := SvcGameEventList{ |
| 16 | Events: int16(reader.TryReadBits(9)), | 16 | Events: int16(reader.TryReadBits(9)), |
| 17 | Length: int32(reader.TryReadBits(20)), | 17 | Length: int32(reader.TryReadBits(20)), |
| 18 | } | 18 | } |
| 19 | reader.TryReadBitsToSlice(int(svcGameEventList.Length)) | 19 | reader.TryReadBitsToSlice(uint64(svcGameEventList.Length)) |
| 20 | return svcGameEventList | 20 | return svcGameEventList |
| 21 | } | 21 | } |
diff --git a/pkg/messages/types/svcGetCvarValue.go b/pkg/messages/types/svcGetCvarValue.go index aef5c8e..0598722 100644 --- a/pkg/messages/types/svcGetCvarValue.go +++ b/pkg/messages/types/svcGetCvarValue.go | |||
| @@ -7,9 +7,9 @@ type SvcGetCvarValue struct { | |||
| 7 | CvarName string | 7 | CvarName string |
| 8 | } | 8 | } |
| 9 | 9 | ||
| 10 | func ParseSvcGetCvarValue(reader *bitreader.ReaderType) SvcGetCvarValue { | 10 | func ParseSvcGetCvarValue(reader *bitreader.Reader) SvcGetCvarValue { |
| 11 | svcGetCvarValue := SvcGetCvarValue{ | 11 | svcGetCvarValue := SvcGetCvarValue{ |
| 12 | Cookie: reader.TryReadStringLen(4), | 12 | Cookie: reader.TryReadStringLength(4), |
| 13 | CvarName: reader.TryReadString(), | 13 | CvarName: reader.TryReadString(), |
| 14 | } | 14 | } |
| 15 | return svcGetCvarValue | 15 | return svcGetCvarValue |
diff --git a/pkg/messages/types/svcMenu.go b/pkg/messages/types/svcMenu.go index d89f52c..9958e99 100644 --- a/pkg/messages/types/svcMenu.go +++ b/pkg/messages/types/svcMenu.go | |||
| @@ -8,11 +8,11 @@ type SvcMenu struct { | |||
| 8 | Data []byte | 8 | Data []byte |
| 9 | } | 9 | } |
| 10 | 10 | ||
| 11 | func ParseSvcMenu(reader *bitreader.ReaderType) SvcMenu { | 11 | func ParseSvcMenu(reader *bitreader.Reader) SvcMenu { |
| 12 | svcMenu := SvcMenu{ | 12 | svcMenu := SvcMenu{ |
| 13 | MenuType: int16(reader.TryReadBits(16)), | 13 | MenuType: int16(reader.TryReadBits(16)), |
| 14 | Length: int32(reader.TryReadBits(32)), | 14 | Length: int32(reader.TryReadBits(32)), |
| 15 | } | 15 | } |
| 16 | svcMenu.Data = reader.TryReadBitsToSlice(int(svcMenu.Length)) | 16 | svcMenu.Data = reader.TryReadBitsToSlice(uint64(svcMenu.Length)) |
| 17 | return svcMenu | 17 | return svcMenu |
| 18 | } | 18 | } |
diff --git a/pkg/messages/types/svcPacketEntities.go b/pkg/messages/types/svcPacketEntities.go index b1c23e5..54e4a2a 100644 --- a/pkg/messages/types/svcPacketEntities.go +++ b/pkg/messages/types/svcPacketEntities.go | |||
| @@ -1,6 +1,8 @@ | |||
| 1 | package messages | 1 | package messages |
| 2 | 2 | ||
| 3 | import "github.com/pektezol/bitreader" | 3 | import ( |
| 4 | "github.com/pektezol/bitreader" | ||
| 5 | ) | ||
| 4 | 6 | ||
| 5 | type SvcPacketEntities struct { | 7 | type SvcPacketEntities struct { |
| 6 | MaxEntries int16 | 8 | MaxEntries int16 |
| @@ -13,18 +15,23 @@ type SvcPacketEntities struct { | |||
| 13 | Data []byte | 15 | Data []byte |
| 14 | } | 16 | } |
| 15 | 17 | ||
| 16 | func ParseSvcPacketEntities(reader *bitreader.ReaderType) SvcPacketEntities { | 18 | func ParseSvcPacketEntities(reader *bitreader.Reader) SvcPacketEntities { |
| 17 | svcPacketEntities := SvcPacketEntities{ | 19 | svcPacketEntities := SvcPacketEntities{ |
| 18 | MaxEntries: int16(reader.TryReadBits(11)), | 20 | MaxEntries: int16(reader.TryReadBits(11)), |
| 19 | IsDelta: reader.TryReadBool(), | 21 | IsDelta: reader.TryReadBool(), |
| 20 | } | 22 | } |
| 21 | if svcPacketEntities.IsDelta { | 23 | if svcPacketEntities.IsDelta { |
| 22 | svcPacketEntities.DeltaFrom = int32(reader.TryReadBits(32)) | 24 | svcPacketEntities.DeltaFrom = int32(reader.TryReadBits(32)) |
| 25 | } else { | ||
| 26 | svcPacketEntities.DeltaFrom = -1 | ||
| 23 | } | 27 | } |
| 24 | svcPacketEntities.BaseLine = reader.TryReadBool() | 28 | svcPacketEntities.BaseLine = reader.TryReadBool() |
| 25 | svcPacketEntities.UpdatedEntries = int16(reader.TryReadBits(11)) | 29 | svcPacketEntities.UpdatedEntries = int16(reader.TryReadBits(11)) |
| 26 | svcPacketEntities.Length = int32(reader.TryReadBits(20)) | 30 | svcPacketEntities.Length = int32(reader.TryReadBits(20)) |
| 27 | svcPacketEntities.UpdatedBaseline = reader.TryReadBool() | 31 | svcPacketEntities.UpdatedBaseline = reader.TryReadBool() |
| 28 | svcPacketEntities.Data = reader.TryReadBitsToSlice(int(svcPacketEntities.Length)) | 32 | svcPacketEntities.Data = reader.TryReadBitsToSlice(uint64(svcPacketEntities.Length)) //, dataReader = reader.ForkAndSkip(int(svcPacketEntities.Length)) |
| 33 | // for count := 0; count < int(svcPacketEntities.UpdatedEntries); count++ { | ||
| 34 | // dataReader.TryReadBool() | ||
| 35 | // } | ||
| 29 | return svcPacketEntities | 36 | return svcPacketEntities |
| 30 | } | 37 | } |
diff --git a/pkg/messages/types/svcPaintmapData.go b/pkg/messages/types/svcPaintmapData.go index 6b041da..41ef515 100644 --- a/pkg/messages/types/svcPaintmapData.go +++ b/pkg/messages/types/svcPaintmapData.go | |||
| @@ -7,10 +7,10 @@ type SvcPaintmapData struct { | |||
| 7 | Data []byte | 7 | Data []byte |
| 8 | } | 8 | } |
| 9 | 9 | ||
| 10 | func ParseSvcPaintmapData(reader *bitreader.ReaderType) SvcPaintmapData { | 10 | func ParseSvcPaintmapData(reader *bitreader.Reader) SvcPaintmapData { |
| 11 | svcPaintmapData := SvcPaintmapData{ | 11 | svcPaintmapData := SvcPaintmapData{ |
| 12 | Length: int32(reader.TryReadBits(32)), | 12 | Length: int32(reader.TryReadBits(32)), |
| 13 | } | 13 | } |
| 14 | svcPaintmapData.Data = reader.TryReadBitsToSlice(int(svcPaintmapData.Length)) | 14 | svcPaintmapData.Data = reader.TryReadBitsToSlice(uint64(svcPaintmapData.Length)) |
| 15 | return svcPaintmapData | 15 | return svcPaintmapData |
| 16 | } | 16 | } |
diff --git a/pkg/messages/types/svcPrefetch.go b/pkg/messages/types/svcPrefetch.go index 549f926..50d01e9 100644 --- a/pkg/messages/types/svcPrefetch.go +++ b/pkg/messages/types/svcPrefetch.go | |||
| @@ -6,7 +6,7 @@ type SvcPrefetch struct { | |||
| 6 | SoundIndex int16 | 6 | SoundIndex int16 |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | func ParseSvcPrefetch(reader *bitreader.ReaderType) SvcPrefetch { | 9 | func ParseSvcPrefetch(reader *bitreader.Reader) SvcPrefetch { |
| 10 | return SvcPrefetch{ | 10 | return SvcPrefetch{ |
| 11 | SoundIndex: int16(reader.TryReadBits(13)), | 11 | SoundIndex: int16(reader.TryReadBits(13)), |
| 12 | } | 12 | } |
diff --git a/pkg/messages/types/svcPrint.go b/pkg/messages/types/svcPrint.go index 8aff927..f31d046 100644 --- a/pkg/messages/types/svcPrint.go +++ b/pkg/messages/types/svcPrint.go | |||
| @@ -6,7 +6,7 @@ type SvcPrint struct { | |||
| 6 | Message string | 6 | Message string |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | func ParseSvcPrint(reader *bitreader.ReaderType) SvcPrint { | 9 | func ParseSvcPrint(reader *bitreader.Reader) SvcPrint { |
| 10 | return SvcPrint{ | 10 | return SvcPrint{ |
| 11 | Message: reader.TryReadString(), | 11 | Message: reader.TryReadString(), |
| 12 | } | 12 | } |
diff --git a/pkg/messages/types/svcSendTable.go b/pkg/messages/types/svcSendTable.go index ae8960b..9eb47fc 100644 --- a/pkg/messages/types/svcSendTable.go +++ b/pkg/messages/types/svcSendTable.go | |||
| @@ -8,7 +8,7 @@ type SvcSendTable struct { | |||
| 8 | Props int32 | 8 | Props int32 |
| 9 | } | 9 | } |
| 10 | 10 | ||
| 11 | func ParseSvcSendTable(reader *bitreader.ReaderType) SvcSendTable { | 11 | func ParseSvcSendTable(reader *bitreader.Reader) SvcSendTable { |
| 12 | return SvcSendTable{ | 12 | return SvcSendTable{ |
| 13 | NeedsDecoder: int8(reader.TryReadBits(8)), | 13 | NeedsDecoder: int8(reader.TryReadBits(8)), |
| 14 | Length: int8(reader.TryReadBits(8)), | 14 | Length: int8(reader.TryReadBits(8)), |
diff --git a/pkg/messages/types/svcServerInfo.go b/pkg/messages/types/svcServerInfo.go index b8bb308..c699eca 100644 --- a/pkg/messages/types/svcServerInfo.go +++ b/pkg/messages/types/svcServerInfo.go | |||
| @@ -21,7 +21,7 @@ type SvcServerInfo struct { | |||
| 21 | HostName string | 21 | HostName string |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | func ParseSvcServerInfo(reader *bitreader.ReaderType) SvcServerInfo { | 24 | func ParseSvcServerInfo(reader *bitreader.Reader) SvcServerInfo { |
| 25 | return SvcServerInfo{ | 25 | return SvcServerInfo{ |
| 26 | Protocol: int16(reader.TryReadBits(16)), | 26 | Protocol: int16(reader.TryReadBits(16)), |
| 27 | ServerCount: int32(reader.TryReadBits(32)), | 27 | ServerCount: int32(reader.TryReadBits(32)), |
diff --git a/pkg/messages/types/svcSetPause.go b/pkg/messages/types/svcSetPause.go index 94303b7..551a4d3 100644 --- a/pkg/messages/types/svcSetPause.go +++ b/pkg/messages/types/svcSetPause.go | |||
| @@ -6,7 +6,7 @@ type SvcSetPause struct { | |||
| 6 | Paused bool | 6 | Paused bool |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | func ParseSvcSetPause(reader *bitreader.ReaderType) SvcSetPause { | 9 | func ParseSvcSetPause(reader *bitreader.Reader) SvcSetPause { |
| 10 | return SvcSetPause{ | 10 | return SvcSetPause{ |
| 11 | Paused: reader.TryReadBool(), | 11 | Paused: reader.TryReadBool(), |
| 12 | } | 12 | } |
diff --git a/pkg/messages/types/svcSetView.go b/pkg/messages/types/svcSetView.go index 70d1e2b..266a539 100644 --- a/pkg/messages/types/svcSetView.go +++ b/pkg/messages/types/svcSetView.go | |||
| @@ -6,7 +6,7 @@ type SvcSetView struct { | |||
| 6 | EntityIndex int16 | 6 | EntityIndex int16 |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | func ParseSvcSetView(reader *bitreader.ReaderType) SvcSetView { | 9 | func ParseSvcSetView(reader *bitreader.Reader) SvcSetView { |
| 10 | return SvcSetView{ | 10 | return SvcSetView{ |
| 11 | EntityIndex: int16(reader.TryReadBits(11)), | 11 | EntityIndex: int16(reader.TryReadBits(11)), |
| 12 | } | 12 | } |
diff --git a/pkg/messages/types/svcSounds.go b/pkg/messages/types/svcSounds.go index e87d584..22d4a66 100644 --- a/pkg/messages/types/svcSounds.go +++ b/pkg/messages/types/svcSounds.go | |||
| @@ -9,7 +9,7 @@ type SvcSounds struct { | |||
| 9 | Data []byte | 9 | Data []byte |
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | func ParseSvcSounds(reader *bitreader.ReaderType) SvcSounds { | 12 | func ParseSvcSounds(reader *bitreader.Reader) SvcSounds { |
| 13 | svcSounds := SvcSounds{ | 13 | svcSounds := SvcSounds{ |
| 14 | ReliableSound: reader.TryReadBool(), | 14 | ReliableSound: reader.TryReadBool(), |
| 15 | } | 15 | } |
| @@ -20,6 +20,6 @@ func ParseSvcSounds(reader *bitreader.ReaderType) SvcSounds { | |||
| 20 | svcSounds.Size = int8(reader.TryReadBits(8)) | 20 | svcSounds.Size = int8(reader.TryReadBits(8)) |
| 21 | svcSounds.Length = int16(reader.TryReadBits(16)) | 21 | svcSounds.Length = int16(reader.TryReadBits(16)) |
| 22 | } | 22 | } |
| 23 | svcSounds.Data = reader.TryReadBitsToSlice(int(svcSounds.Length)) | 23 | svcSounds.Data = reader.TryReadBitsToSlice(uint64(svcSounds.Length)) |
| 24 | return svcSounds | 24 | return svcSounds |
| 25 | } | 25 | } |
diff --git a/pkg/messages/types/svcSplitScreen.go b/pkg/messages/types/svcSplitScreen.go index 9c808bc..3ba6ee8 100644 --- a/pkg/messages/types/svcSplitScreen.go +++ b/pkg/messages/types/svcSplitScreen.go | |||
| @@ -8,11 +8,11 @@ type SvcSplitScreen struct { | |||
| 8 | Data []byte | 8 | Data []byte |
| 9 | } | 9 | } |
| 10 | 10 | ||
| 11 | func ParseSvcSplitScreen(reader *bitreader.ReaderType) SvcSplitScreen { | 11 | func ParseSvcSplitScreen(reader *bitreader.Reader) SvcSplitScreen { |
| 12 | svcSplitScreen := SvcSplitScreen{ | 12 | svcSplitScreen := SvcSplitScreen{ |
| 13 | Unk: reader.TryReadBool(), | 13 | Unk: reader.TryReadBool(), |
| 14 | Length: int16(reader.TryReadBits(11)), | 14 | Length: int16(reader.TryReadBits(11)), |
| 15 | } | 15 | } |
| 16 | svcSplitScreen.Data = reader.TryReadBitsToSlice(int(svcSplitScreen.Length)) | 16 | svcSplitScreen.Data = reader.TryReadBitsToSlice(uint64(svcSplitScreen.Length)) |
| 17 | return svcSplitScreen | 17 | return svcSplitScreen |
| 18 | } | 18 | } |
diff --git a/pkg/messages/types/svcTempEntities.go b/pkg/messages/types/svcTempEntities.go index d22423d..ca4b995 100644 --- a/pkg/messages/types/svcTempEntities.go +++ b/pkg/messages/types/svcTempEntities.go | |||
| @@ -8,11 +8,11 @@ type SvcTempEntities struct { | |||
| 8 | Data []byte | 8 | Data []byte |
| 9 | } | 9 | } |
| 10 | 10 | ||
| 11 | func ParseSvcTempEntities(reader *bitreader.ReaderType) SvcTempEntities { | 11 | func ParseSvcTempEntities(reader *bitreader.Reader) SvcTempEntities { |
| 12 | svcTempEntities := SvcTempEntities{ | 12 | svcTempEntities := SvcTempEntities{ |
| 13 | NumEntries: int8(reader.TryReadBits(8)), | 13 | NumEntries: int8(reader.TryReadBits(8)), |
| 14 | Length: int32(reader.TryReadBits(17)), | 14 | Length: int32(reader.TryReadBits(17)), |
| 15 | } | 15 | } |
| 16 | svcTempEntities.Data = reader.TryReadBitsToSlice(int(svcTempEntities.Length)) | 16 | svcTempEntities.Data = reader.TryReadBitsToSlice(uint64(svcTempEntities.Length)) |
| 17 | return svcTempEntities | 17 | return svcTempEntities |
| 18 | } | 18 | } |
diff --git a/pkg/messages/types/svcUpdateStringTable.go b/pkg/messages/types/svcUpdateStringTable.go index 2840482..c606141 100644 --- a/pkg/messages/types/svcUpdateStringTable.go +++ b/pkg/messages/types/svcUpdateStringTable.go | |||
| @@ -9,7 +9,7 @@ type SvcUpdateStringTable struct { | |||
| 9 | Data []byte | 9 | Data []byte |
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | func ParseSvcUpdateStringTable(reader *bitreader.ReaderType) SvcUpdateStringTable { | 12 | func ParseSvcUpdateStringTable(reader *bitreader.Reader) SvcUpdateStringTable { |
| 13 | svcUpdateStringTable := SvcUpdateStringTable{ | 13 | svcUpdateStringTable := SvcUpdateStringTable{ |
| 14 | TableId: int8(reader.TryReadBits(5)), | 14 | TableId: int8(reader.TryReadBits(5)), |
| 15 | } | 15 | } |
| @@ -17,6 +17,6 @@ func ParseSvcUpdateStringTable(reader *bitreader.ReaderType) SvcUpdateStringTabl | |||
| 17 | svcUpdateStringTable.NumChangedEntries = int16(reader.TryReadBits(16)) | 17 | svcUpdateStringTable.NumChangedEntries = int16(reader.TryReadBits(16)) |
| 18 | } | 18 | } |
| 19 | svcUpdateStringTable.Length = int32(reader.TryReadBits(20)) | 19 | svcUpdateStringTable.Length = int32(reader.TryReadBits(20)) |
| 20 | svcUpdateStringTable.Data = reader.TryReadBitsToSlice(int(svcUpdateStringTable.Length)) | 20 | svcUpdateStringTable.Data = reader.TryReadBitsToSlice(uint64(svcUpdateStringTable.Length)) |
| 21 | return svcUpdateStringTable | 21 | return svcUpdateStringTable |
| 22 | } | 22 | } |
diff --git a/pkg/messages/types/svcUserMessage.go b/pkg/messages/types/svcUserMessage.go index b53c7c0..fb8be20 100644 --- a/pkg/messages/types/svcUserMessage.go +++ b/pkg/messages/types/svcUserMessage.go | |||
| @@ -8,11 +8,11 @@ type SvcUserMessage struct { | |||
| 8 | Data []byte | 8 | Data []byte |
| 9 | } | 9 | } |
| 10 | 10 | ||
| 11 | func ParseSvcUserMessage(reader *bitreader.ReaderType) SvcUserMessage { | 11 | func ParseSvcUserMessage(reader *bitreader.Reader) SvcUserMessage { |
| 12 | svcUserMessage := SvcUserMessage{ | 12 | svcUserMessage := SvcUserMessage{ |
| 13 | MsgType: int8(reader.TryReadBits(8)), | 13 | MsgType: int8(reader.TryReadBits(8)), |
| 14 | Length: int16(reader.TryReadBits(12)), | 14 | Length: int16(reader.TryReadBits(12)), |
| 15 | } | 15 | } |
| 16 | svcUserMessage.Data = reader.TryReadBitsToSlice(int(svcUserMessage.Length)) | 16 | svcUserMessage.Data = reader.TryReadBitsToSlice(uint64(svcUserMessage.Length)) |
| 17 | return svcUserMessage | 17 | return svcUserMessage |
| 18 | } | 18 | } |
diff --git a/pkg/messages/types/svcVoiceData.go b/pkg/messages/types/svcVoiceData.go index b6c81d4..9609d80 100644 --- a/pkg/messages/types/svcVoiceData.go +++ b/pkg/messages/types/svcVoiceData.go | |||
| @@ -9,12 +9,12 @@ type SvcVoiceData struct { | |||
| 9 | Data []byte | 9 | Data []byte |
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | func ParseSvcVoiceData(reader *bitreader.ReaderType) SvcVoiceData { | 12 | func ParseSvcVoiceData(reader *bitreader.Reader) SvcVoiceData { |
| 13 | svcVoiceData := SvcVoiceData{ | 13 | svcVoiceData := SvcVoiceData{ |
| 14 | Client: int8(reader.TryReadBits(8)), | 14 | Client: int8(reader.TryReadBits(8)), |
| 15 | Proximity: int8(reader.TryReadBits(8)), | 15 | Proximity: int8(reader.TryReadBits(8)), |
| 16 | Length: int16(reader.TryReadBits(16)), | 16 | Length: int16(reader.TryReadBits(16)), |
| 17 | } | 17 | } |
| 18 | svcVoiceData.Data = reader.TryReadBitsToSlice(int(svcVoiceData.Length)) | 18 | svcVoiceData.Data = reader.TryReadBitsToSlice(uint64(svcVoiceData.Length)) |
| 19 | return svcVoiceData | 19 | return svcVoiceData |
| 20 | } | 20 | } |
diff --git a/pkg/messages/types/svcVoiceInit.go b/pkg/messages/types/svcVoiceInit.go index 4c95aab..afabfc9 100644 --- a/pkg/messages/types/svcVoiceInit.go +++ b/pkg/messages/types/svcVoiceInit.go | |||
| @@ -8,7 +8,7 @@ type SvcVoiceInit struct { | |||
| 8 | Unk float32 | 8 | Unk float32 |
| 9 | } | 9 | } |
| 10 | 10 | ||
| 11 | func ParseSvcVoiceInit(reader *bitreader.ReaderType) SvcVoiceInit { | 11 | func ParseSvcVoiceInit(reader *bitreader.Reader) SvcVoiceInit { |
| 12 | svcVoiceInit := SvcVoiceInit{ | 12 | svcVoiceInit := SvcVoiceInit{ |
| 13 | Codec: reader.TryReadString(), | 13 | Codec: reader.TryReadString(), |
| 14 | Quality: uint8(reader.TryReadBits(8)), | 14 | Quality: uint8(reader.TryReadBits(8)), |
diff --git a/pkg/packets/headers.go b/pkg/packets/headers.go index 543476b..dbeab87 100644 --- a/pkg/packets/headers.go +++ b/pkg/packets/headers.go | |||
| @@ -20,19 +20,19 @@ type Headers struct { | |||
| 20 | SignOnLength int32 | 20 | SignOnLength int32 |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | func ParseHeaders(reader *bitreader.ReaderType) Headers { | 23 | func ParseHeaders(reader *bitreader.Reader) Headers { |
| 24 | headers := Headers{ | 24 | headers := Headers{ |
| 25 | DemoFileStamp: reader.TryReadString(), | 25 | DemoFileStamp: reader.TryReadString(), |
| 26 | DemoProtocol: int32(reader.TryReadInt32()), | 26 | DemoProtocol: int32(reader.TryReadSInt32()), |
| 27 | NetworkProtocol: int32(reader.TryReadInt32()), | 27 | NetworkProtocol: int32(reader.TryReadSInt32()), |
| 28 | ServerName: reader.TryReadStringLen(260), | 28 | ServerName: reader.TryReadStringLength(260), |
| 29 | ClientName: reader.TryReadStringLen(260), | 29 | ClientName: reader.TryReadStringLength(260), |
| 30 | MapName: reader.TryReadStringLen(260), | 30 | MapName: reader.TryReadStringLength(260), |
| 31 | GameDirectory: reader.TryReadStringLen(260), | 31 | GameDirectory: reader.TryReadStringLength(260), |
| 32 | PlaybackTime: reader.TryReadFloat32(), | 32 | PlaybackTime: reader.TryReadFloat32(), |
| 33 | PlaybackTicks: int32(reader.TryReadInt32()), | 33 | PlaybackTicks: int32(reader.TryReadSInt32()), |
| 34 | PlaybackFrames: int32(reader.TryReadInt32()), | 34 | PlaybackFrames: int32(reader.TryReadSInt32()), |
| 35 | SignOnLength: int32(reader.TryReadInt32()), | 35 | SignOnLength: int32(reader.TryReadSInt32()), |
| 36 | } | 36 | } |
| 37 | if headers.DemoFileStamp != "HL2DEMO" { | 37 | if headers.DemoFileStamp != "HL2DEMO" { |
| 38 | panic("invalid demo file stamp") | 38 | panic("invalid demo file stamp") |
diff --git a/pkg/packets/packets.go b/pkg/packets/packets.go index a84da21..fd5a14b 100644 --- a/pkg/packets/packets.go +++ b/pkg/packets/packets.go | |||
| @@ -1,8 +1,6 @@ | |||
| 1 | package packets | 1 | package packets |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "bytes" | ||
| 5 | |||
| 6 | "github.com/pektezol/bitreader" | 4 | "github.com/pektezol/bitreader" |
| 7 | "github.com/pektezol/demoparser/pkg/classes" | 5 | "github.com/pektezol/demoparser/pkg/classes" |
| 8 | "github.com/pektezol/demoparser/pkg/messages" | 6 | "github.com/pektezol/demoparser/pkg/messages" |
| @@ -15,9 +13,9 @@ type PacketMessageInfo struct { | |||
| 15 | Data any | 13 | Data any |
| 16 | } | 14 | } |
| 17 | 15 | ||
| 18 | const MSSC = 2 | 16 | const MSSC int = 2 |
| 19 | 17 | ||
| 20 | func ParsePackets(reader *bitreader.ReaderType) PacketMessageInfo { | 18 | func ParsePackets(reader *bitreader.Reader) PacketMessageInfo { |
| 21 | packetType := reader.TryReadBits(8) | 19 | packetType := reader.TryReadBits(8) |
| 22 | tickNumber := reader.TryReadBits(32) | 20 | tickNumber := reader.TryReadBits(32) |
| 23 | slotNumber := reader.TryReadBits(8) | 21 | slotNumber := reader.TryReadBits(8) |
| @@ -30,9 +28,9 @@ func ParsePackets(reader *bitreader.ReaderType) PacketMessageInfo { | |||
| 30 | } | 28 | } |
| 31 | signOn.InSequence = int32(reader.TryReadBits(32)) | 29 | signOn.InSequence = int32(reader.TryReadBits(32)) |
| 32 | signOn.OutSequence = int32(reader.TryReadBits(32)) | 30 | signOn.OutSequence = int32(reader.TryReadBits(32)) |
| 33 | signOn.Size = int32(reader.TryReadInt32()) | 31 | signOn.Size = int32(reader.TryReadSInt32()) |
| 34 | data := reader.TryReadBytesToSlice(int(signOn.Size)) | 32 | data := reader.TryReadBytesToSlice(uint64(signOn.Size)) |
| 35 | packetReader := bitreader.Reader(bytes.NewReader(data), true) | 33 | packetReader := bitreader.NewReaderFromBytes(data, true) |
| 36 | for { | 34 | for { |
| 37 | messageType, err := packetReader.ReadBits(6) | 35 | messageType, err := packetReader.ReadBits(6) |
| 38 | if err != nil { | 36 | if err != nil { |
| @@ -48,9 +46,9 @@ func ParsePackets(reader *bitreader.ReaderType) PacketMessageInfo { | |||
| 48 | } | 46 | } |
| 49 | packet.InSequence = int32(reader.TryReadBits(32)) | 47 | packet.InSequence = int32(reader.TryReadBits(32)) |
| 50 | packet.OutSequence = int32(reader.TryReadBits(32)) | 48 | packet.OutSequence = int32(reader.TryReadBits(32)) |
| 51 | packet.Size = int32(reader.TryReadInt32()) | 49 | packet.Size = int32(reader.TryReadSInt32()) |
| 52 | data := reader.TryReadBytesToSlice(int(packet.Size)) | 50 | data := reader.TryReadBytesToSlice(uint64(packet.Size)) |
| 53 | packetReader := bitreader.Reader(bytes.NewReader(data), true) | 51 | packetReader := bitreader.NewReaderFromBytes(data, true) |
| 54 | for { | 52 | for { |
| 55 | messageType, err := packetReader.ReadBits(6) | 53 | messageType, err := packetReader.ReadBits(6) |
| 56 | if err != nil { | 54 | if err != nil { |
| @@ -63,24 +61,24 @@ func ParsePackets(reader *bitreader.ReaderType) PacketMessageInfo { | |||
| 63 | syncTick := SyncTick{} | 61 | syncTick := SyncTick{} |
| 64 | packetData = syncTick | 62 | packetData = syncTick |
| 65 | case 4: // ConsoleCmd | 63 | case 4: // ConsoleCmd |
| 66 | size := reader.TryReadInt32() | 64 | size := reader.TryReadSInt32() |
| 67 | consoleCmd := ConsoleCmd{ | 65 | consoleCmd := ConsoleCmd{ |
| 68 | Size: int32(size), | 66 | Size: int32(size), |
| 69 | Data: reader.TryReadStringLen(int(size)), | 67 | Data: reader.TryReadStringLength(uint64(size)), |
| 70 | } | 68 | } |
| 71 | packetData = consoleCmd | 69 | packetData = consoleCmd |
| 72 | case 5: // UserCmd | 70 | case 5: // UserCmd |
| 73 | userCmd := UserCmd{} | 71 | userCmd := UserCmd{} |
| 74 | userCmd.Cmd = int32(reader.TryReadInt32()) | 72 | userCmd.Cmd = int32(reader.TryReadSInt32()) |
| 75 | userCmd.Size = int32(reader.TryReadInt32()) | 73 | userCmd.Size = int32(reader.TryReadSInt32()) |
| 76 | data := reader.TryReadBytesToSlice(int(userCmd.Size)) | 74 | data := reader.TryReadBytesToSlice(uint64(userCmd.Size)) |
| 77 | userCmd.Data = classes.ParseUserCmdInfo(data) | 75 | userCmd.Data = classes.ParseUserCmdInfo(data) |
| 78 | packetData = userCmd | 76 | packetData = userCmd |
| 79 | case 6: // DataTables | 77 | case 6: // DataTables |
| 80 | dataTables := DataTables{} | 78 | dataTables := DataTables{} |
| 81 | dataTables.Size = int32(reader.TryReadInt32()) | 79 | dataTables.Size = int32(reader.TryReadSInt32()) |
| 82 | data := reader.TryReadBytesToSlice(int(dataTables.Size)) | 80 | data := reader.TryReadBytesToSlice(uint64(dataTables.Size)) |
| 83 | dataTableReader := bitreader.Reader(bytes.NewReader(data), true) | 81 | dataTableReader := bitreader.NewReaderFromBytes(data, true) |
| 84 | count := 0 | 82 | count := 0 |
| 85 | for dataTableReader.TryReadBool() { | 83 | for dataTableReader.TryReadBool() { |
| 86 | count++ | 84 | count++ |
| @@ -94,8 +92,7 @@ func ParsePackets(reader *bitreader.ReaderType) PacketMessageInfo { | |||
| 94 | case 7: // Stop | 92 | case 7: // Stop |
| 95 | stop := Stop{} | 93 | stop := Stop{} |
| 96 | if reader.TryReadBool() { | 94 | if reader.TryReadBool() { |
| 97 | // read remaining data | 95 | stop.RemainingData = reader.TryReadBitsToSlice(uint64(reader.TryReadRemainingBits())) |
| 98 | stop.RemainingData = []byte{} | ||
| 99 | } | 96 | } |
| 100 | packetData = stop | 97 | packetData = stop |
| 101 | case 8: // CustomData | 98 | case 8: // CustomData |
| @@ -103,14 +100,24 @@ func ParsePackets(reader *bitreader.ReaderType) PacketMessageInfo { | |||
| 103 | Unknown: int32(reader.TryReadBits(32)), | 100 | Unknown: int32(reader.TryReadBits(32)), |
| 104 | Size: int32(reader.TryReadBits(32)), | 101 | Size: int32(reader.TryReadBits(32)), |
| 105 | } | 102 | } |
| 106 | customData.Data = string(reader.TryReadBytesToSlice(int(customData.Size))) | 103 | if customData.Unknown != 0 || customData.Size == 8 { |
| 107 | packetData = customData | 104 | // Not SAR data |
| 105 | customData.Data = string(reader.TryReadBytesToSlice(uint64(customData.Size))) | ||
| 106 | packetData = customData | ||
| 107 | break | ||
| 108 | } | ||
| 109 | // SAR data | ||
| 110 | sarData := classes.SarData{} | ||
| 111 | data := reader.TryReadBytesToSlice(uint64(customData.Size)) | ||
| 112 | sarReader := bitreader.NewReaderFromBytes(data, true) | ||
| 113 | sarData.ParseSarData(sarReader) | ||
| 114 | packetData = sarData | ||
| 108 | case 9: // StringTables | 115 | case 9: // StringTables |
| 109 | stringTables := StringTables{ | 116 | stringTables := StringTables{ |
| 110 | Size: int32(reader.TryReadInt32()), | 117 | Size: int32(reader.TryReadSInt32()), |
| 111 | } | 118 | } |
| 112 | data := reader.TryReadBytesToSlice(int(stringTables.Size)) | 119 | data := reader.TryReadBytesToSlice(uint64(stringTables.Size)) |
| 113 | stringTableReader := bitreader.Reader(bytes.NewReader(data), true) | 120 | stringTableReader := bitreader.NewReaderFromBytes(data, true) |
| 114 | stringTables.Data = classes.ParseStringTables(stringTableReader) | 121 | stringTables.Data = classes.ParseStringTables(stringTableReader) |
| 115 | packetData = stringTables | 122 | packetData = stringTables |
| 116 | default: // invalid | 123 | default: // invalid |