From ada648a085f2b66b9e7badcfd92f6f8095a70e13 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sun, 18 Aug 2024 17:50:35 -0500 Subject: [PATCH] fix: elims were counted as kills --- dissect/feedback.go | 21 +++++++++++++-------- dissect/reader.go | 28 +++++++++++++++------------- dissect/scoreboard.go | 25 +++++++++++++++++++++++++ dissect/time.go | 7 ++++++- 4 files changed, 59 insertions(+), 22 deletions(-) diff --git a/dissect/feedback.go b/dissect/feedback.go index 1e776ad..e82098c 100644 --- a/dissect/feedback.go +++ b/dissect/feedback.go @@ -27,14 +27,15 @@ const ( ) type MatchUpdate struct { - Type MatchUpdateType `json:"type"` - Username string `json:"username,omitempty"` - Target string `json:"target,omitempty"` - Headshot *bool `json:"headshot,omitempty"` - Time string `json:"time"` - TimeInSeconds float64 `json:"timeInSeconds"` - Message string `json:"message,omitempty"` - Operator Operator `json:"operator,omitempty"` + Type MatchUpdateType `json:"type"` + Username string `json:"username,omitempty"` + Target string `json:"target,omitempty"` + Headshot *bool `json:"headshot,omitempty"` + Time string `json:"time"` + TimeInSeconds float64 `json:"timeInSeconds"` + Message string `json:"message,omitempty"` + Operator Operator `json:"operator,omitempty"` + usernameFromScoreboard string } func (i MatchUpdateType) MarshalJSON() (text []byte, err error) { @@ -151,6 +152,10 @@ func readMatchFeedback(r *Reader) error { return nil } } + // removing the elimination username for now + if r.lastKillerFromScoreboard != username { + u.usernameFromScoreboard = r.lastKillerFromScoreboard + } r.MatchFeedback = append(r.MatchFeedback, u) log.Debug().Interface("match_update", u).Send() return nil diff --git a/dissect/reader.go b/dissect/reader.go index 7cbd33c..ce3ee4c 100644 --- a/dissect/reader.go +++ b/dissect/reader.go @@ -18,19 +18,20 @@ import ( var strSep = []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} type Reader struct { - b []byte - offset int - queries [][]byte - listeners [][]func(r *Reader) error - time float64 // in seconds - timeRaw string // raw dissect format - lastDefuserPlayerIndex int - planted bool - readPartial bool // reads up to the player info packets - playersRead int - Header Header `json:"header"` - MatchFeedback []MatchUpdate `json:"matchFeedback"` - Scoreboard Scoreboard + b []byte + offset int + queries [][]byte + listeners [][]func(r *Reader) error + time float64 // in seconds + timeRaw string // raw dissect format + lastDefuserPlayerIndex int + planted bool + readPartial bool // reads up to the player info packets + playersRead int + lastKillerFromScoreboard string + Header Header `json:"header"` + MatchFeedback []MatchUpdate `json:"matchFeedback"` + Scoreboard Scoreboard } // NewReader decompresses in using zstd and @@ -68,6 +69,7 @@ func NewReader(in io.Reader) (r *Reader, err error) { r.Listen([]byte{0x22, 0xA9, 0xC8, 0x58, 0xD9}, readDefuserTimer) r.Listen([]byte{0xEC, 0xDA, 0x4F, 0x80}, readScoreboardScore) r.Listen([]byte{0x4D, 0x73, 0x7F, 0x9E}, readScoreboardAssists) + r.Listen([]byte{0x1C, 0xD2, 0xB1, 0x9D}, readScoreboardKills) return r, err } diff --git a/dissect/scoreboard.go b/dissect/scoreboard.go index ab960cc..8e2c73f 100644 --- a/dissect/scoreboard.go +++ b/dissect/scoreboard.go @@ -13,6 +13,31 @@ type ScoreboardPlayer struct { AssistsFromRound uint32 } +// this function fixes kills that were previously recorded as elims +func readScoreboardKills(r *Reader) error { + kills, err := r.Uint32() + if err != nil { + return err + } + if err := r.Skip(30); err != nil { + return err + } + id, err := r.Bytes(4) + if err != nil { + return err + } + idx := r.PlayerIndexByID(id) + if idx != -1 { + username := r.Header.Players[idx].Username + r.lastKillerFromScoreboard = username + log.Warn(). + Str("username", username). + Uint32("kills", kills). + Msg("scoreboard_kill") + } + return nil +} + func readScoreboardAssists(r *Reader) error { assists, err := r.Uint32() if err != nil { diff --git a/dissect/time.go b/dissect/time.go index 4376b4f..7235362 100644 --- a/dissect/time.go +++ b/dissect/time.go @@ -2,9 +2,10 @@ package dissect import ( "fmt" - "github.com/rs/zerolog/log" "strconv" "strings" + + "github.com/rs/zerolog/log" ) func readTime(r *Reader) error { @@ -57,6 +58,10 @@ func (r *Reader) roundEnd() { case Kill: i := r.Header.Players[r.PlayerIndexByUsername(u.Target)].TeamIndex deaths[i] = deaths[i] + 1 + // fix killer username + if len(u.usernameFromScoreboard) > 0 { + u.Username = u.usernameFromScoreboard + } break case Death: i := r.Header.Players[r.PlayerIndexByUsername(u.Username)].TeamIndex