diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-09-21 01:53:59 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-21 01:53:59 +0300 |
| commit | 171e350e348afadb55967b9c13d5eadc7f7d2cf4 (patch) | |
| tree | 14ec93df8ccc1aca0cf453f826d46a402b09dc8f /pkg/classes | |
| parent | define todos on packets (diff) | |
| download | sdp.go-171e350e348afadb55967b9c13d5eadc7f7d2cf4.tar.gz sdp.go-171e350e348afadb55967b9c13d5eadc7f7d2cf4.tar.bz2 sdp.go-171e350e348afadb55967b9c13d5eadc7f7d2cf4.zip | |
add strings builder, customize ALL outputs (#6)
Diffstat (limited to 'pkg/classes')
| -rw-r--r-- | pkg/classes/cmdInfo.go | 12 | ||||
| -rw-r--r-- | pkg/classes/sarData.go | 110 | ||||
| -rw-r--r-- | pkg/classes/sendTable.go | 174 | ||||
| -rw-r--r-- | pkg/classes/serverClassInfo.go | 5 | ||||
| -rw-r--r-- | pkg/classes/stringTable.go | 15 | ||||
| -rw-r--r-- | pkg/classes/userCmdInfo.go | 15 |
6 files changed, 253 insertions, 78 deletions
diff --git a/pkg/classes/cmdInfo.go b/pkg/classes/cmdInfo.go index 545d14b..eccfe99 100644 --- a/pkg/classes/cmdInfo.go +++ b/pkg/classes/cmdInfo.go | |||
| @@ -4,6 +4,7 @@ import ( | |||
| 4 | "fmt" | 4 | "fmt" |
| 5 | 5 | ||
| 6 | "github.com/pektezol/bitreader" | 6 | "github.com/pektezol/bitreader" |
| 7 | "github.com/pektezol/demoparser/pkg/writer" | ||
| 7 | ) | 8 | ) |
| 8 | 9 | ||
| 9 | type CmdInfo struct { | 10 | type CmdInfo struct { |
| @@ -41,7 +42,7 @@ func (cmdInfoFlags CmdInfoFlags) String() string { | |||
| 41 | } | 42 | } |
| 42 | 43 | ||
| 43 | func ParseCmdInfo(reader *bitreader.Reader) CmdInfo { | 44 | func ParseCmdInfo(reader *bitreader.Reader) CmdInfo { |
| 44 | return CmdInfo{ | 45 | cmdInfo := CmdInfo{ |
| 45 | Flags: CmdInfoFlags(reader.TryReadUInt32()).String(), | 46 | Flags: CmdInfoFlags(reader.TryReadUInt32()).String(), |
| 46 | ViewOrigin: []float32{reader.TryReadFloat32(), reader.TryReadFloat32(), reader.TryReadFloat32()}, | 47 | ViewOrigin: []float32{reader.TryReadFloat32(), reader.TryReadFloat32(), reader.TryReadFloat32()}, |
| 47 | ViewAngles: []float32{reader.TryReadFloat32(), reader.TryReadFloat32(), reader.TryReadFloat32()}, | 48 | ViewAngles: []float32{reader.TryReadFloat32(), reader.TryReadFloat32(), reader.TryReadFloat32()}, |
| @@ -50,4 +51,13 @@ func ParseCmdInfo(reader *bitreader.Reader) CmdInfo { | |||
| 50 | ViewAngles2: []float32{reader.TryReadFloat32(), reader.TryReadFloat32(), reader.TryReadFloat32()}, | 51 | ViewAngles2: []float32{reader.TryReadFloat32(), reader.TryReadFloat32(), reader.TryReadFloat32()}, |
| 51 | LocalViewAngles2: []float32{reader.TryReadFloat32(), reader.TryReadFloat32(), reader.TryReadFloat32()}, | 52 | LocalViewAngles2: []float32{reader.TryReadFloat32(), reader.TryReadFloat32(), reader.TryReadFloat32()}, |
| 52 | } | 53 | } |
| 54 | writer.AppendLine("\tFlags: %s", cmdInfo.Flags) | ||
| 55 | writer.AppendLine("\tView Origin: %v", cmdInfo.ViewOrigin) | ||
| 56 | writer.AppendLine("\tView Angles: %v", cmdInfo.ViewAngles) | ||
| 57 | writer.AppendLine("\tLocal View Angles: %v", cmdInfo.LocalViewAngles) | ||
| 58 | writer.AppendLine("\tView Origin 2: %v", cmdInfo.ViewOrigin2) | ||
| 59 | writer.AppendLine("\tView Angles 2: %v", cmdInfo.ViewAngles2) | ||
| 60 | writer.AppendLine("\tLocal View Angles 2: %v", cmdInfo.LocalViewAngles2) | ||
| 61 | writer.AppendLine("") | ||
| 62 | return cmdInfo | ||
| 53 | } | 63 | } |
diff --git a/pkg/classes/sarData.go b/pkg/classes/sarData.go index 35163c3..27e8a64 100644 --- a/pkg/classes/sarData.go +++ b/pkg/classes/sarData.go | |||
| @@ -5,6 +5,7 @@ import ( | |||
| 5 | "fmt" | 5 | "fmt" |
| 6 | 6 | ||
| 7 | "github.com/pektezol/bitreader" | 7 | "github.com/pektezol/bitreader" |
| 8 | "github.com/pektezol/demoparser/pkg/writer" | ||
| 8 | ) | 9 | ) |
| 9 | 10 | ||
| 10 | type SarDataType uint8 | 11 | type SarDataType uint8 |
| @@ -137,12 +138,12 @@ type SarDataSpeedrunTimeSplits struct { | |||
| 137 | } | 138 | } |
| 138 | 139 | ||
| 139 | type SarDataTimestamp struct { | 140 | type SarDataTimestamp struct { |
| 140 | Year uint16 | 141 | Year uint16 |
| 141 | Mon uint8 | 142 | Month uint8 |
| 142 | Day uint8 | 143 | Day uint8 |
| 143 | Hour uint8 | 144 | Hour uint8 |
| 144 | Min uint8 | 145 | Minute uint8 |
| 145 | Sec uint8 | 146 | Second uint8 |
| 146 | } | 147 | } |
| 147 | 148 | ||
| 148 | type SarDataFileChecksum struct { | 149 | type SarDataFileChecksum struct { |
| @@ -163,6 +164,7 @@ func (sarData *SarData) ParseSarData(reader *bitreader.Reader) (err error) { | |||
| 163 | len = 9 | 164 | len = 9 |
| 164 | } | 165 | } |
| 165 | dataReader := bitreader.NewReaderFromBytes(reader.TryReadBytesToSlice(len-1), true) | 166 | dataReader := bitreader.NewReaderFromBytes(reader.TryReadBytesToSlice(len-1), true) |
| 167 | writer.AppendLine("\tMessage: %s (%d):", sarData.Type.String(), sarData.Type) | ||
| 166 | switch sarData.Type { | 168 | switch sarData.Type { |
| 167 | case ESarDataTimescaleCheat: | 169 | case ESarDataTimescaleCheat: |
| 168 | sarData.Data, err = parseTimescaleCheatData(dataReader, len) | 170 | sarData.Data, err = parseTimescaleCheatData(dataReader, len) |
| @@ -173,6 +175,7 @@ func (sarData *SarData) ParseSarData(reader *bitreader.Reader) (err error) { | |||
| 173 | sarData.Data = parseInitialCVarData(dataReader) | 175 | sarData.Data = parseInitialCVarData(dataReader) |
| 174 | case ESarDataEntityInputSlot: | 176 | case ESarDataEntityInputSlot: |
| 175 | sarData.Slot = int(dataReader.TryReadBytes(1)) | 177 | sarData.Slot = int(dataReader.TryReadBytes(1)) |
| 178 | writer.AppendLine("\t\tSlot: %d", sarData.Slot) | ||
| 176 | case ESarDataEntityInput: | 179 | case ESarDataEntityInput: |
| 177 | sarData.Data = parseEntityInputData(dataReader) | 180 | sarData.Data = parseEntityInputData(dataReader) |
| 178 | case ESarDataChecksum: | 181 | case ESarDataChecksum: |
| @@ -198,6 +201,7 @@ func (sarData *SarData) ParseSarData(reader *bitreader.Reader) (err error) { | |||
| 198 | if err != nil { | 201 | if err != nil { |
| 199 | sarData.Data = nil | 202 | sarData.Data = nil |
| 200 | } | 203 | } |
| 204 | writer.AppendLine("\t\tSlot: %d", sarData.Slot) | ||
| 201 | case ESarDataPause: | 205 | case ESarDataPause: |
| 202 | sarData.Data, err = parsePauseData(dataReader, len) | 206 | sarData.Data, err = parsePauseData(dataReader, len) |
| 203 | if err != nil { | 207 | if err != nil { |
| @@ -239,45 +243,60 @@ func parseTimescaleCheatData(reader *bitreader.Reader, length uint64) (SarDataTi | |||
| 239 | if length != 5 { | 243 | if length != 5 { |
| 240 | return SarDataTimescaleCheat{}, errors.New("sar data invalid") | 244 | return SarDataTimescaleCheat{}, errors.New("sar data invalid") |
| 241 | } | 245 | } |
| 242 | return SarDataTimescaleCheat{ | 246 | sarDataTimescaleCheat := SarDataTimescaleCheat{ |
| 243 | Timescale: reader.TryReadFloat32(), | 247 | Timescale: reader.TryReadFloat32(), |
| 244 | }, nil | 248 | } |
| 249 | writer.AppendLine("\t\tTimescale: %f", sarDataTimescaleCheat.Timescale) | ||
| 250 | return sarDataTimescaleCheat, nil | ||
| 245 | } | 251 | } |
| 246 | 252 | ||
| 247 | func parseInitialCVarData(reader *bitreader.Reader) SarDataInitialCVar { | 253 | func parseInitialCVarData(reader *bitreader.Reader) SarDataInitialCVar { |
| 248 | return SarDataInitialCVar{ | 254 | sarDataInitialCvar := SarDataInitialCVar{ |
| 249 | CVar: reader.TryReadString(), | 255 | CVar: reader.TryReadString(), |
| 250 | Val: reader.TryReadString(), | 256 | Val: reader.TryReadString(), |
| 251 | } | 257 | } |
| 258 | writer.AppendLine("\t\tCvar: \"%s\" = \"%s\"", sarDataInitialCvar.CVar, sarDataInitialCvar.Val) | ||
| 259 | return sarDataInitialCvar | ||
| 252 | } | 260 | } |
| 253 | 261 | ||
| 254 | func parseEntityInputData(reader *bitreader.Reader) SarDataEntityInput { | 262 | func parseEntityInputData(reader *bitreader.Reader) SarDataEntityInput { |
| 255 | return SarDataEntityInput{ | 263 | sarDataEntityInput := SarDataEntityInput{ |
| 256 | TargetName: reader.TryReadString(), | 264 | TargetName: reader.TryReadString(), |
| 257 | ClassName: reader.TryReadString(), | 265 | ClassName: reader.TryReadString(), |
| 258 | InputName: reader.TryReadString(), | 266 | InputName: reader.TryReadString(), |
| 259 | Parameter: reader.TryReadString(), | 267 | Parameter: reader.TryReadString(), |
| 260 | } | 268 | } |
| 269 | writer.AppendLine("\t\tTarget: %s", sarDataEntityInput.TargetName) | ||
| 270 | writer.AppendLine("\t\tClass: %s", sarDataEntityInput.ClassName) | ||
| 271 | writer.AppendLine("\t\tInput: %s", sarDataEntityInput.InputName) | ||
| 272 | writer.AppendLine("\t\tParameter: %s", sarDataEntityInput.Parameter) | ||
| 273 | return sarDataEntityInput | ||
| 261 | } | 274 | } |
| 262 | 275 | ||
| 263 | func parseChecksumData(reader *bitreader.Reader, length uint64) (SarDataChecksum, error) { | 276 | func parseChecksumData(reader *bitreader.Reader, length uint64) (SarDataChecksum, error) { |
| 264 | if length != 9 { | 277 | if length != 9 { |
| 265 | return SarDataChecksum{}, errors.New("sar data invalid") | 278 | return SarDataChecksum{}, errors.New("sar data invalid") |
| 266 | } | 279 | } |
| 267 | return SarDataChecksum{ | 280 | sarDataChecksum := SarDataChecksum{ |
| 268 | DemoSum: reader.TryReadUInt32(), | 281 | DemoSum: reader.TryReadUInt32(), |
| 269 | SarSum: reader.TryReadUInt32(), | 282 | SarSum: reader.TryReadUInt32(), |
| 270 | }, nil | 283 | } |
| 284 | writer.AppendLine("\t\tDemo Checksum: %d", sarDataChecksum.DemoSum) | ||
| 285 | writer.AppendLine("\t\tSAR Checksum: %d", sarDataChecksum.SarSum) | ||
| 286 | return sarDataChecksum, nil | ||
| 271 | } | 287 | } |
| 272 | 288 | ||
| 273 | func parseChecksumV2Data(reader *bitreader.Reader, length uint64) (SarDataChecksumV2, error) { | 289 | func parseChecksumV2Data(reader *bitreader.Reader, length uint64) (SarDataChecksumV2, error) { |
| 274 | if length != 69 { | 290 | if length != 69 { |
| 275 | return SarDataChecksumV2{}, errors.New("sar data invalid") | 291 | return SarDataChecksumV2{}, errors.New("sar data invalid") |
| 276 | } | 292 | } |
| 277 | return SarDataChecksumV2{ | 293 | sarDataChecksumV2 := SarDataChecksumV2{ |
| 278 | SarSum: reader.TryReadUInt32(), | 294 | SarSum: reader.TryReadUInt32(), |
| 279 | Signature: [64]byte(reader.TryReadBytesToSlice(60)), | 295 | Signature: [64]byte(reader.TryReadBytesToSlice(60)), |
| 280 | }, nil | 296 | } |
| 297 | writer.AppendLine("\t\tSAR Checksum: %d", sarDataChecksumV2.SarSum) | ||
| 298 | writer.AppendLine("\t\tSignature: %v", sarDataChecksumV2.Signature) | ||
| 299 | return sarDataChecksumV2, nil | ||
| 281 | } | 300 | } |
| 282 | 301 | ||
| 283 | func parsePortalPlacementData(reader *bitreader.Reader, length uint64) (SarDataPortalPlacement, int, error) { | 302 | func parsePortalPlacementData(reader *bitreader.Reader, length uint64) (SarDataPortalPlacement, int, error) { |
| @@ -287,12 +306,17 @@ func parsePortalPlacementData(reader *bitreader.Reader, length uint64) (SarDataP | |||
| 287 | slot := int(reader.TryReadBytes(1)) | 306 | slot := int(reader.TryReadBytes(1)) |
| 288 | orange := reader.TryReadBool() | 307 | orange := reader.TryReadBool() |
| 289 | reader.SkipBits(7) | 308 | reader.SkipBits(7) |
| 290 | return SarDataPortalPlacement{ | 309 | sarDataPortalPlacement := SarDataPortalPlacement{ |
| 291 | Orange: orange, | 310 | Orange: orange, |
| 292 | X: reader.TryReadFloat32(), | 311 | X: reader.TryReadFloat32(), |
| 293 | Y: reader.TryReadFloat32(), | 312 | Y: reader.TryReadFloat32(), |
| 294 | Z: reader.TryReadFloat32(), | 313 | Z: reader.TryReadFloat32(), |
| 295 | }, slot, nil | 314 | } |
| 315 | writer.AppendLine("\t\tOrange: %t", orange) | ||
| 316 | writer.AppendLine("\t\tX: %f", sarDataPortalPlacement.X) | ||
| 317 | writer.AppendLine("\t\tY: %f", sarDataPortalPlacement.Y) | ||
| 318 | writer.AppendLine("\t\tZ: %f", sarDataPortalPlacement.Z) | ||
| 319 | return sarDataPortalPlacement, slot, nil | ||
| 296 | } | 320 | } |
| 297 | 321 | ||
| 298 | func parseChallengeFlagsCrouchFlyData(reader *bitreader.Reader, length uint64) (int, error) { | 322 | func parseChallengeFlagsCrouchFlyData(reader *bitreader.Reader, length uint64) (int, error) { |
| @@ -306,29 +330,37 @@ func parsePauseData(reader *bitreader.Reader, length uint64) (SarDataPause, erro | |||
| 306 | if length != 5 { | 330 | if length != 5 { |
| 307 | return SarDataPause{}, errors.New("sar data invalid") | 331 | return SarDataPause{}, errors.New("sar data invalid") |
| 308 | } | 332 | } |
| 309 | return SarDataPause{ | 333 | sarDataPause := SarDataPause{ |
| 310 | PauseTicks: reader.TryReadUInt32(), | 334 | PauseTicks: reader.TryReadUInt32(), |
| 311 | }, nil | 335 | } |
| 336 | writer.AppendLine("\t\tPause Ticks: %d", sarDataPause.PauseTicks) | ||
| 337 | return sarDataPause, nil | ||
| 312 | } | 338 | } |
| 313 | 339 | ||
| 314 | func parseWaitRunData(reader *bitreader.Reader, length uint64) (SarDataWaitRun, error) { | 340 | func parseWaitRunData(reader *bitreader.Reader, length uint64) (SarDataWaitRun, error) { |
| 315 | if length < 6 { | 341 | if length < 6 { |
| 316 | return SarDataWaitRun{}, errors.New("sar data invalid") | 342 | return SarDataWaitRun{}, errors.New("sar data invalid") |
| 317 | } | 343 | } |
| 318 | return SarDataWaitRun{ | 344 | sarDataWaitRun := SarDataWaitRun{ |
| 319 | Ticks: int(reader.TryReadUInt32()), | 345 | Ticks: int(reader.TryReadUInt32()), |
| 320 | Cmd: reader.TryReadString(), | 346 | Cmd: reader.TryReadString(), |
| 321 | }, nil | 347 | } |
| 348 | writer.AppendLine("\t\tTicks: %d", sarDataWaitRun.Ticks) | ||
| 349 | writer.AppendLine("\t\tCmd: \"%s\"", sarDataWaitRun.Cmd) | ||
| 350 | return sarDataWaitRun, nil | ||
| 322 | } | 351 | } |
| 323 | 352 | ||
| 324 | func parseHWaitRunData(reader *bitreader.Reader, length uint64) (SarDataHWaitRun, error) { | 353 | func parseHWaitRunData(reader *bitreader.Reader, length uint64) (SarDataHWaitRun, error) { |
| 325 | if length < 6 { | 354 | if length < 6 { |
| 326 | return SarDataHWaitRun{}, errors.New("sar data invalid") | 355 | return SarDataHWaitRun{}, errors.New("sar data invalid") |
| 327 | } | 356 | } |
| 328 | return SarDataHWaitRun{ | 357 | sarDataHWaitRun := SarDataHWaitRun{ |
| 329 | Ticks: int(reader.TryReadUInt32()), | 358 | Ticks: int(reader.TryReadUInt32()), |
| 330 | Cmd: reader.TryReadString(), | 359 | Cmd: reader.TryReadString(), |
| 331 | }, nil | 360 | } |
| 361 | writer.AppendLine("\t\tTicks: %d", sarDataHWaitRun.Ticks) | ||
| 362 | writer.AppendLine("\t\tCmd: \"%s\"", sarDataHWaitRun.Cmd) | ||
| 363 | return sarDataHWaitRun, nil | ||
| 332 | } | 364 | } |
| 333 | 365 | ||
| 334 | func parseSpeedrunTimeData(reader *bitreader.Reader, length uint64) (SarDataSpeedrunTime, error) { | 366 | func parseSpeedrunTimeData(reader *bitreader.Reader, length uint64) (SarDataSpeedrunTime, error) { |
| @@ -340,10 +372,14 @@ func parseSpeedrunTimeData(reader *bitreader.Reader, length uint64) (SarDataSpee | |||
| 340 | for splitCount := 0; splitCount < int(numberOfSplits); splitCount++ { | 372 | for splitCount := 0; splitCount < int(numberOfSplits); splitCount++ { |
| 341 | splits[splitCount].Name = reader.TryReadString() | 373 | splits[splitCount].Name = reader.TryReadString() |
| 342 | splits[splitCount].NSegs = reader.TryReadUInt32() | 374 | splits[splitCount].NSegs = reader.TryReadUInt32() |
| 375 | writer.AppendLine("\t\t[%d] Split Name: \"%s\"", splitCount, splits[splitCount].Name) | ||
| 376 | writer.AppendLine("\t\t[%d] Number of Segments: %d", splitCount, splits[splitCount].NSegs) | ||
| 343 | splits[splitCount].Segs = make([]SarDataSpeedrunTimeSegs, splits[splitCount].NSegs) | 377 | splits[splitCount].Segs = make([]SarDataSpeedrunTimeSegs, splits[splitCount].NSegs) |
| 344 | for segCount := 0; segCount < int(splits[splitCount].NSegs); segCount++ { | 378 | for segCount := 0; segCount < int(splits[splitCount].NSegs); segCount++ { |
| 345 | splits[splitCount].Segs[segCount].Name = reader.TryReadString() | 379 | splits[splitCount].Segs[segCount].Name = reader.TryReadString() |
| 346 | splits[splitCount].Segs[segCount].Ticks = reader.TryReadUInt32() | 380 | splits[splitCount].Segs[segCount].Ticks = reader.TryReadUInt32() |
| 381 | writer.AppendLine("\t\t\t[%d] Segment Name: \"%s\"", segCount, splits[splitCount].Segs[segCount].Name) | ||
| 382 | writer.AppendLine("\t\t\t[%d] Segment Ticks: %d", segCount, splits[splitCount].Segs[segCount].Ticks) | ||
| 347 | } | 383 | } |
| 348 | } | 384 | } |
| 349 | return SarDataSpeedrunTime{ | 385 | return SarDataSpeedrunTime{ |
| @@ -357,22 +393,32 @@ func parseTimestampData(reader *bitreader.Reader, length uint64) (SarDataTimesta | |||
| 357 | return SarDataTimestamp{}, errors.New("sar data invalid") | 393 | return SarDataTimestamp{}, errors.New("sar data invalid") |
| 358 | } | 394 | } |
| 359 | timestamp := reader.TryReadBytesToSlice(7) | 395 | timestamp := reader.TryReadBytesToSlice(7) |
| 360 | return SarDataTimestamp{ | 396 | sarDataTimeStamp := SarDataTimestamp{ |
| 361 | Year: uint16(timestamp[0]) | uint16(timestamp[1])<<8, | 397 | Year: uint16(timestamp[0]) | uint16(timestamp[1])<<8, |
| 362 | Mon: timestamp[2] + 1, | 398 | Month: timestamp[2] + 1, |
| 363 | Day: timestamp[3], | 399 | Day: timestamp[3], |
| 364 | Hour: timestamp[4], | 400 | Hour: timestamp[4], |
| 365 | Min: timestamp[5], | 401 | Minute: timestamp[5], |
| 366 | Sec: timestamp[6], | 402 | Second: timestamp[6], |
| 367 | }, nil | 403 | } |
| 404 | writer.AppendLine("\t\tYear: %d", sarDataTimeStamp.Year) | ||
| 405 | writer.AppendLine("\t\tMonth: %d", sarDataTimeStamp.Month) | ||
| 406 | writer.AppendLine("\t\tDay: %d", sarDataTimeStamp.Day) | ||
| 407 | writer.AppendLine("\t\tHour: %d", sarDataTimeStamp.Hour) | ||
| 408 | writer.AppendLine("\t\tMinute: %d", sarDataTimeStamp.Minute) | ||
| 409 | writer.AppendLine("\t\tSecond: %d", sarDataTimeStamp.Second) | ||
| 410 | return sarDataTimeStamp, nil | ||
| 368 | } | 411 | } |
| 369 | 412 | ||
| 370 | func parseFileChecksumData(reader *bitreader.Reader, length uint64) (SarDataFileChecksum, error) { | 413 | func parseFileChecksumData(reader *bitreader.Reader, length uint64) (SarDataFileChecksum, error) { |
| 371 | if length < 6 { | 414 | if length < 6 { |
| 372 | return SarDataFileChecksum{}, errors.New("sar data invalid") | 415 | return SarDataFileChecksum{}, errors.New("sar data invalid") |
| 373 | } | 416 | } |
| 374 | return SarDataFileChecksum{ | 417 | sarDataFileChecksum := SarDataFileChecksum{ |
| 375 | Sum: reader.TryReadUInt32(), | 418 | Sum: reader.TryReadUInt32(), |
| 376 | Path: reader.TryReadString(), | 419 | Path: reader.TryReadString(), |
| 377 | }, nil | 420 | } |
| 421 | writer.AppendLine("\t\tChecksum: %d", sarDataFileChecksum.Sum) | ||
| 422 | writer.AppendLine("\t\tPath: \"%s\"", sarDataFileChecksum.Path) | ||
| 423 | return sarDataFileChecksum, nil | ||
| 378 | } | 424 | } |
diff --git a/pkg/classes/sendTable.go b/pkg/classes/sendTable.go index bc36d75..927d967 100644 --- a/pkg/classes/sendTable.go +++ b/pkg/classes/sendTable.go | |||
| @@ -1,7 +1,10 @@ | |||
| 1 | package classes | 1 | package classes |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | ||
| 5 | |||
| 4 | "github.com/pektezol/bitreader" | 6 | "github.com/pektezol/bitreader" |
| 7 | "github.com/pektezol/demoparser/pkg/writer" | ||
| 5 | ) | 8 | ) |
| 6 | 9 | ||
| 7 | type SendTable struct { | 10 | type SendTable struct { |
| @@ -12,10 +15,10 @@ type SendTable struct { | |||
| 12 | } | 15 | } |
| 13 | 16 | ||
| 14 | type prop struct { | 17 | type prop struct { |
| 15 | SendPropType int8 | 18 | SendPropType sendPropType |
| 16 | SendPropName string | 19 | SendPropName string |
| 17 | SendPropFlags int32 | 20 | SendPropFlags uint32 |
| 18 | Priority int8 | 21 | Priority uint8 |
| 19 | ExcludeDtName string | 22 | ExcludeDtName string |
| 20 | LowValue float32 | 23 | LowValue float32 |
| 21 | HighValue float32 | 24 | HighValue float32 |
| @@ -23,84 +26,169 @@ type prop struct { | |||
| 23 | NumElements int32 | 26 | NumElements int32 |
| 24 | } | 27 | } |
| 25 | 28 | ||
| 26 | type sendPropFlag int | 29 | type sendPropType int |
| 27 | 30 | ||
| 28 | const ( | 31 | const ( |
| 29 | Unsigned sendPropFlag = iota | 32 | ESendPropTypeInt sendPropType = iota |
| 30 | Coord | 33 | ESendPropTypeFloat |
| 31 | NoScale | 34 | ESendPropTypeVector3 |
| 32 | RoundDown | 35 | ESendPropTypeVector2 |
| 33 | RoundUp | 36 | ESendPropTypeString |
| 34 | Normal | 37 | ESendPropTypeArray |
| 35 | Exclude | 38 | ESendPropTypeDataTable |
| 36 | Xyze | ||
| 37 | InsideArray | ||
| 38 | ProxyAlwaysYes | ||
| 39 | IsVectorElem | ||
| 40 | Collapsible | ||
| 41 | CoordMp | ||
| 42 | CoordMpLp // low precision | ||
| 43 | CoordMpInt | ||
| 44 | CellCoord | ||
| 45 | CellCoordLp | ||
| 46 | CellCoordInt | ||
| 47 | ChangesOften | ||
| 48 | ) | 39 | ) |
| 49 | 40 | ||
| 50 | type sendPropType int | ||
| 51 | |||
| 52 | const ( | 41 | const ( |
| 53 | Int sendPropType = iota | 42 | ESendPropFlagUnsigned string = "Unsigned" |
| 54 | Float | 43 | ESendPropFlagCoord string = "Coord" |
| 55 | Vector3 | 44 | ESendPropFlagNoScale string = "NoScale" |
| 56 | Vector2 | 45 | ESendPropFlagRoundDown string = "RoundDown" |
| 57 | String | 46 | ESendPropFlagRoundUp string = "RoundUp" |
| 58 | Array | 47 | ESendPropFlagNormal string = "Normal" |
| 59 | DataTable | 48 | ESendPropFlagExclude string = "Exclude" |
| 49 | ESendPropFlagXyze string = "Xyze" | ||
| 50 | ESendPropFlagInsideArray string = "InsideArray" | ||
| 51 | ESendPropFlagProxyAlwaysYes string = "ProxyAlwaysYes" | ||
| 52 | ESendPropFlagIsVectorElem string = "IsVectorElem" | ||
| 53 | ESendPropFlagCollapsible string = "Collapsible" | ||
| 54 | ESendPropFlagCoordMp string = "CoordMp" | ||
| 55 | ESendPropFlagCoordMpLp string = "CoordMpLp" | ||
| 56 | ESendPropFlagCoordMpInt string = "CoordMpInt" | ||
| 57 | ESendPropFlagCellCoord string = "CellCoord" | ||
| 58 | ESendPropFlagCellCoordLp string = "CellCoordLp" | ||
| 59 | ESendPropFlagCellCoordInt string = "CellCoordInt" | ||
| 60 | ESendPropFlagChangesOften string = "ChangesOften" | ||
| 60 | ) | 61 | ) |
| 61 | 62 | ||
| 63 | func (prop prop) GetFlags() []string { | ||
| 64 | flags := []string{} | ||
| 65 | if checkBit(prop.SendPropFlags, 0) { | ||
| 66 | flags = append(flags, ESendPropFlagUnsigned) | ||
| 67 | } | ||
| 68 | if checkBit(prop.SendPropFlags, 1) { | ||
| 69 | flags = append(flags, ESendPropFlagCoord) | ||
| 70 | } | ||
| 71 | if checkBit(prop.SendPropFlags, 2) { | ||
| 72 | flags = append(flags, ESendPropFlagNoScale) | ||
| 73 | } | ||
| 74 | if checkBit(prop.SendPropFlags, 3) { | ||
| 75 | flags = append(flags, ESendPropFlagRoundDown) | ||
| 76 | } | ||
| 77 | if checkBit(prop.SendPropFlags, 4) { | ||
| 78 | flags = append(flags, ESendPropFlagRoundUp) | ||
| 79 | } | ||
| 80 | if checkBit(prop.SendPropFlags, 5) { | ||
| 81 | flags = append(flags, ESendPropFlagNormal) | ||
| 82 | } | ||
| 83 | if checkBit(prop.SendPropFlags, 6) { | ||
| 84 | flags = append(flags, ESendPropFlagExclude) | ||
| 85 | } | ||
| 86 | if checkBit(prop.SendPropFlags, 7) { | ||
| 87 | flags = append(flags, ESendPropFlagXyze) | ||
| 88 | } | ||
| 89 | if checkBit(prop.SendPropFlags, 8) { | ||
| 90 | flags = append(flags, ESendPropFlagInsideArray) | ||
| 91 | } | ||
| 92 | if checkBit(prop.SendPropFlags, 9) { | ||
| 93 | flags = append(flags, ESendPropFlagProxyAlwaysYes) | ||
| 94 | } | ||
| 95 | if checkBit(prop.SendPropFlags, 10) { | ||
| 96 | flags = append(flags, ESendPropFlagIsVectorElem) | ||
| 97 | } | ||
| 98 | if checkBit(prop.SendPropFlags, 11) { | ||
| 99 | flags = append(flags, ESendPropFlagCollapsible) | ||
| 100 | } | ||
| 101 | if checkBit(prop.SendPropFlags, 12) { | ||
| 102 | flags = append(flags, ESendPropFlagCoordMp) | ||
| 103 | } | ||
| 104 | if checkBit(prop.SendPropFlags, 13) { | ||
| 105 | flags = append(flags, ESendPropFlagCoordMpLp) | ||
| 106 | } | ||
| 107 | if checkBit(prop.SendPropFlags, 14) { | ||
| 108 | flags = append(flags, ESendPropFlagCoordMpInt) | ||
| 109 | } | ||
| 110 | if checkBit(prop.SendPropFlags, 15) { | ||
| 111 | flags = append(flags, ESendPropFlagCellCoord) | ||
| 112 | } | ||
| 113 | if checkBit(prop.SendPropFlags, 16) { | ||
| 114 | flags = append(flags, ESendPropFlagCellCoordLp) | ||
| 115 | } | ||
| 116 | if checkBit(prop.SendPropFlags, 17) { | ||
| 117 | flags = append(flags, ESendPropFlagCellCoordInt) | ||
| 118 | } | ||
| 119 | if checkBit(prop.SendPropFlags, 18) { | ||
| 120 | flags = append(flags, ESendPropFlagChangesOften) | ||
| 121 | } | ||
| 122 | return flags | ||
| 123 | } | ||
| 124 | |||
| 125 | func (sendPropType sendPropType) String() string { | ||
| 126 | switch sendPropType { | ||
| 127 | case ESendPropTypeInt: | ||
| 128 | return "Int" | ||
| 129 | case ESendPropTypeFloat: | ||
| 130 | return "Float" | ||
| 131 | case ESendPropTypeVector3: | ||
| 132 | return "Vector3" | ||
| 133 | case ESendPropTypeVector2: | ||
| 134 | return "Vector2" | ||
| 135 | case ESendPropTypeString: | ||
| 136 | return "String" | ||
| 137 | case ESendPropTypeArray: | ||
| 138 | return "Array" | ||
| 139 | case ESendPropTypeDataTable: | ||
| 140 | return "DataTable" | ||
| 141 | default: | ||
| 142 | return fmt.Sprintf("%d", int(sendPropType)) | ||
| 143 | } | ||
| 144 | } | ||
| 145 | |||
| 62 | func ParseSendTable(reader *bitreader.Reader) SendTable { | 146 | func ParseSendTable(reader *bitreader.Reader) SendTable { |
| 63 | sendTable := SendTable{ | 147 | sendTable := SendTable{ |
| 64 | NeedsDecoder: reader.TryReadBool(), | 148 | NeedsDecoder: reader.TryReadBool(), |
| 65 | NetTableName: reader.TryReadString(), | 149 | NetTableName: reader.TryReadString(), |
| 66 | NumOfProps: int16(reader.TryReadBits(10)), | 150 | NumOfProps: int16(reader.TryReadBits(10)), |
| 67 | // SendPropType: int8(reader.TryReadBits(5)), | ||
| 68 | // SendPropName: reader.TryReadString(), | ||
| 69 | // SendPropFlags: int16(reader.TryReadBits(16)), | ||
| 70 | } | 151 | } |
| 71 | if sendTable.NumOfProps < 0 { | 152 | if sendTable.NumOfProps < 0 { |
| 72 | return sendTable | 153 | return sendTable |
| 73 | } | 154 | } |
| 155 | writer.TempAppendLine("\t\t%s (%d Props):", sendTable.NetTableName, sendTable.NumOfProps) | ||
| 74 | for count := 0; count < int(sendTable.NumOfProps); count++ { | 156 | for count := 0; count < int(sendTable.NumOfProps); count++ { |
| 75 | propType := int8(reader.TryReadBits(5)) | 157 | propType := int8(reader.TryReadBits(5)) |
| 76 | if propType >= int8(7) { | 158 | if propType >= int8(7) { |
| 77 | return sendTable | 159 | return sendTable |
| 78 | } | 160 | } |
| 79 | prop := prop{ | 161 | prop := prop{ |
| 80 | SendPropType: propType, | 162 | SendPropType: sendPropType(propType), |
| 81 | SendPropName: reader.TryReadString(), | 163 | SendPropName: reader.TryReadString(), |
| 82 | SendPropFlags: int32(reader.TryReadBits(19)), | 164 | SendPropFlags: uint32(reader.TryReadBits(19)), |
| 83 | Priority: int8(reader.TryReadBits(8)), | 165 | Priority: reader.TryReadUInt8(), |
| 84 | } | 166 | } |
| 85 | if propType == int8(DataTable) || CheckBit(int64(prop.SendPropFlags), int(Exclude)) { | 167 | writer.TempAppend("\t\t\t%s\t", prop.SendPropType) |
| 168 | if propType == int8(ESendPropTypeDataTable) || checkBit(prop.SendPropFlags, 6) { | ||
| 86 | prop.ExcludeDtName = reader.TryReadString() | 169 | prop.ExcludeDtName = reader.TryReadString() |
| 170 | writer.TempAppend(":\t%s\t", prop.ExcludeDtName) | ||
| 87 | } else { | 171 | } else { |
| 88 | switch propType { | 172 | switch propType { |
| 89 | case int8(String), int8(Int), int8(Float), int8(Vector3), int8(Vector2): | 173 | case int8(ESendPropTypeString), int8(ESendPropTypeInt), int8(ESendPropTypeFloat), int8(ESendPropTypeVector3), int8(ESendPropTypeVector2): |
| 90 | prop.LowValue = reader.TryReadFloat32() | 174 | prop.LowValue = reader.TryReadFloat32() |
| 91 | prop.HighValue = reader.TryReadFloat32() | 175 | prop.HighValue = reader.TryReadFloat32() |
| 92 | prop.NumBits = int32(reader.TryReadBits(7)) | 176 | prop.NumBits = int32(reader.TryReadBits(7)) |
| 93 | case int8(Array): | 177 | writer.TempAppend("Low: %f\tHigh: %f\t%d bits\t", prop.LowValue, prop.HighValue, prop.NumBits) |
| 178 | case int8(ESendPropTypeArray): | ||
| 94 | prop.NumElements = int32(reader.TryReadBits(10)) | 179 | prop.NumElements = int32(reader.TryReadBits(10)) |
| 180 | writer.TempAppend("Elements: %d\t", prop.NumElements) | ||
| 95 | default: | 181 | default: |
| 182 | writer.TempAppend("Unknown Prop Type: %v\t", propType) | ||
| 96 | return sendTable | 183 | return sendTable |
| 97 | } | 184 | } |
| 98 | } | 185 | } |
| 186 | writer.TempAppend("Flags: %v\tPriority: %d\n", prop.GetFlags(), prop.Priority) | ||
| 99 | sendTable.Props = append(sendTable.Props, prop) | 187 | sendTable.Props = append(sendTable.Props, prop) |
| 100 | } | 188 | } |
| 101 | return sendTable | 189 | return sendTable |
| 102 | } | 190 | } |
| 103 | 191 | ||
| 104 | func CheckBit(val int64, bit int) bool { | 192 | func checkBit(val uint32, bit int) bool { |
| 105 | return (val & (int64(1) << bit)) != 0 | 193 | return (val & (uint32(1) << bit)) != 0 |
| 106 | } | 194 | } |
diff --git a/pkg/classes/serverClassInfo.go b/pkg/classes/serverClassInfo.go index 36bd8b8..c0d2a2a 100644 --- a/pkg/classes/serverClassInfo.go +++ b/pkg/classes/serverClassInfo.go | |||
| @@ -2,6 +2,7 @@ package classes | |||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "github.com/pektezol/bitreader" | 4 | "github.com/pektezol/bitreader" |
| 5 | "github.com/pektezol/demoparser/pkg/writer" | ||
| 5 | ) | 6 | ) |
| 6 | 7 | ||
| 7 | type ServerClassInfo struct { | 8 | type ServerClassInfo struct { |
| @@ -11,11 +12,13 @@ type ServerClassInfo struct { | |||
| 11 | } | 12 | } |
| 12 | 13 | ||
| 13 | func ParseServerClassInfo(reader *bitreader.Reader, count int, numOfClasses int) ServerClassInfo { | 14 | func ParseServerClassInfo(reader *bitreader.Reader, count int, numOfClasses int) ServerClassInfo { |
| 14 | return ServerClassInfo{ | 15 | serverClassInfo := ServerClassInfo{ |
| 15 | ClassId: reader.TryReadUInt16(), | 16 | ClassId: reader.TryReadUInt16(), |
| 16 | ClassName: reader.TryReadString(), | 17 | ClassName: reader.TryReadString(), |
| 17 | DataTableName: reader.TryReadString(), | 18 | DataTableName: reader.TryReadString(), |
| 18 | } | 19 | } |
| 20 | writer.TempAppendLine("\t\t\t[%d] %s (%s)", serverClassInfo.ClassId, serverClassInfo.ClassName, serverClassInfo.DataTableName) | ||
| 21 | return serverClassInfo | ||
| 19 | } | 22 | } |
| 20 | 23 | ||
| 21 | // func serverClassBits(numOfClasses int) int { | 24 | // func serverClassBits(numOfClasses int) int { |
diff --git a/pkg/classes/stringTable.go b/pkg/classes/stringTable.go index 3983c1f..44d8a73 100644 --- a/pkg/classes/stringTable.go +++ b/pkg/classes/stringTable.go | |||
| @@ -2,6 +2,7 @@ package classes | |||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "github.com/pektezol/bitreader" | 4 | "github.com/pektezol/bitreader" |
| 5 | "github.com/pektezol/demoparser/pkg/writer" | ||
| 5 | ) | 6 | ) |
| 6 | 7 | ||
| 7 | type StringTable struct { | 8 | type StringTable struct { |
| @@ -38,6 +39,7 @@ func ParseStringTables(reader *bitreader.Reader) []StringTable { | |||
| 38 | func (stringTable *StringTable) ParseStream(reader *bitreader.Reader) { | 39 | func (stringTable *StringTable) ParseStream(reader *bitreader.Reader) { |
| 39 | stringTable.Name = reader.TryReadString() | 40 | stringTable.Name = reader.TryReadString() |
| 40 | entryCount := reader.TryReadBits(16) | 41 | entryCount := reader.TryReadBits(16) |
| 42 | writer.AppendLine("\tTable Name: %s", stringTable.Name) | ||
| 41 | stringTable.TableEntries = make([]StringTableEntry, entryCount) | 43 | stringTable.TableEntries = make([]StringTableEntry, entryCount) |
| 42 | 44 | ||
| 43 | for i := 0; i < int(entryCount); i++ { | 45 | for i := 0; i < int(entryCount); i++ { |
| @@ -45,7 +47,12 @@ func (stringTable *StringTable) ParseStream(reader *bitreader.Reader) { | |||
| 45 | entry.Parse(reader) | 47 | entry.Parse(reader) |
| 46 | stringTable.TableEntries[i] = entry | 48 | stringTable.TableEntries[i] = entry |
| 47 | } | 49 | } |
| 48 | 50 | if entryCount != 0 { | |
| 51 | writer.AppendLine("\t\t%d Table Entries:", entryCount) | ||
| 52 | writer.AppendOutputFromTemp() | ||
| 53 | } else { | ||
| 54 | writer.AppendLine("\t\tNo Table Entries") | ||
| 55 | } | ||
| 49 | if reader.TryReadBool() { | 56 | if reader.TryReadBool() { |
| 50 | classCount := reader.TryReadBits(16) | 57 | classCount := reader.TryReadBits(16) |
| 51 | stringTable.Classes = make([]StringTableClass, classCount) | 58 | stringTable.Classes = make([]StringTableClass, classCount) |
| @@ -55,6 +62,10 @@ func (stringTable *StringTable) ParseStream(reader *bitreader.Reader) { | |||
| 55 | class.Parse(reader) | 62 | class.Parse(reader) |
| 56 | stringTable.Classes[i] = class | 63 | stringTable.Classes[i] = class |
| 57 | } | 64 | } |
| 65 | writer.AppendLine("\t\t%d Classes:", classCount) | ||
| 66 | writer.AppendOutputFromTemp() | ||
| 67 | } else { | ||
| 68 | writer.AppendLine("\t\tNo Class Entries") | ||
| 58 | } | 69 | } |
| 59 | } | 70 | } |
| 60 | 71 | ||
| @@ -73,8 +84,10 @@ func (stringTableEntry *StringTableEntry) Parse(reader *bitreader.Reader) { | |||
| 73 | 84 | ||
| 74 | func (stringTableClass *StringTableClass) Parse(reader *bitreader.Reader) { | 85 | func (stringTableClass *StringTableClass) Parse(reader *bitreader.Reader) { |
| 75 | stringTableClass.Name = reader.TryReadString() | 86 | stringTableClass.Name = reader.TryReadString() |
| 87 | writer.TempAppendLine("\t\t\tName: %s", stringTableClass.Name) | ||
| 76 | if reader.TryReadBool() { | 88 | if reader.TryReadBool() { |
| 77 | dataLen := reader.TryReadBits(16) | 89 | dataLen := reader.TryReadBits(16) |
| 78 | stringTableClass.Data = reader.TryReadStringLength(dataLen) | 90 | stringTableClass.Data = reader.TryReadStringLength(dataLen) |
| 91 | writer.TempAppendLine("\t\t\tData: %s", stringTableClass.Data) | ||
| 79 | } | 92 | } |
| 80 | } | 93 | } |
diff --git a/pkg/classes/userCmdInfo.go b/pkg/classes/userCmdInfo.go index 04d76b6..f1bb613 100644 --- a/pkg/classes/userCmdInfo.go +++ b/pkg/classes/userCmdInfo.go | |||
| @@ -4,6 +4,7 @@ import ( | |||
| 4 | "bytes" | 4 | "bytes" |
| 5 | 5 | ||
| 6 | "github.com/pektezol/bitreader" | 6 | "github.com/pektezol/bitreader" |
| 7 | "github.com/pektezol/demoparser/pkg/writer" | ||
| 7 | ) | 8 | ) |
| 8 | 9 | ||
| 9 | type UserCmdInfo struct { | 10 | type UserCmdInfo struct { |
| @@ -68,5 +69,19 @@ func ParseUserCmdInfo(data []byte) UserCmdInfo { | |||
| 68 | if reader.TryReadBool() { | 69 | if reader.TryReadBool() { |
| 69 | userCmdInfo.MouseDy = int16(reader.TryReadBits(16)) | 70 | userCmdInfo.MouseDy = int16(reader.TryReadBits(16)) |
| 70 | } | 71 | } |
| 72 | writer.AppendLine("\tCommand Number: %v", userCmdInfo.CommandNumber) | ||
| 73 | writer.AppendLine("\tTick Count: %v", userCmdInfo.TickCount) | ||
| 74 | writer.AppendLine("\tView Angles X: %v", userCmdInfo.ViewAnglesX) | ||
| 75 | writer.AppendLine("\tView Angles Y: %v", userCmdInfo.ViewAnglesY) | ||
| 76 | writer.AppendLine("\tView Angles Z: %v", userCmdInfo.ViewAnglesZ) | ||
| 77 | writer.AppendLine("\tForward Move: %v", userCmdInfo.ForwardMove) | ||
| 78 | writer.AppendLine("\tSide Move: %v", userCmdInfo.SideMove) | ||
| 79 | writer.AppendLine("\tUp Move: %v", userCmdInfo.UpMove) | ||
| 80 | writer.AppendLine("\tButtons: %v", userCmdInfo.Buttons) | ||
| 81 | writer.AppendLine("\tImpulse: %v", userCmdInfo.Impulse) | ||
| 82 | writer.AppendLine("\tWeapon Select: %v", userCmdInfo.WeaponSelect) | ||
| 83 | writer.AppendLine("\tWeapon Sub Type: %v", userCmdInfo.WeaponSubType) | ||
| 84 | writer.AppendLine("\tMouse Dx: %v", userCmdInfo.MouseDx) | ||
| 85 | writer.AppendLine("\tMouse Dy: %v", userCmdInfo.MouseDy) | ||
| 71 | return userCmdInfo | 86 | return userCmdInfo |
| 72 | } | 87 | } |