Skip to content

Commit

Permalink
Merge pull request #107 from redraskal/fix/kill-count
Browse files Browse the repository at this point in the history
fix: elims were counted as kills
  • Loading branch information
redraskal authored Aug 26, 2024
2 parents 3bdbaef + 35eccd9 commit 72b9102
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 22 deletions.
21 changes: 13 additions & 8 deletions dissect/feedback.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
28 changes: 15 additions & 13 deletions dissect/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
25 changes: 25 additions & 0 deletions dissect/scoreboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion dissect/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 72b9102

Please sign in to comment.