Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: elims were counted as kills #107

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading