Skip to content

Commit

Permalink
Merge pull request #84 from redraskal/feat/scoreboard
Browse files Browse the repository at this point in the history
feat: scoreboard (assist tracking)
  • Loading branch information
redraskal authored Feb 23, 2024
2 parents 6a33396 + 73de45f commit 1cb1111
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 4 deletions.
3 changes: 3 additions & 0 deletions dissect/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,9 @@ func (r *Reader) deriveTeamRoles() {
log.Debug().Interface("player", p).Send()
if p.Operator != 0 {
players = append(players, p)
r.Scoreboard.Players = append(r.Scoreboard.Players, ScoreboardPlayer{
ID: p.DissectID,
})
} else {
log.Warn().Str("username", p.Username).Msg("operator id was 0, removing from list")
}
Expand Down
4 changes: 2 additions & 2 deletions dissect/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (m *MatchReader) WriteExcel(out io.Writer) error {
c.Right(1).Str("Team Index")
c.Right(1).Str("Kills")
c.Right(1).Str("Died")
c.Right(1).Str("Assists (TODO)")
c.Right(1).Str("Assists")
c.Right(1).Str("Hs%")
c.Right(1).Str("Headshots")
c.Right(1).Str("1vX")
Expand Down Expand Up @@ -247,7 +247,7 @@ func (m *MatchReader) WriteExcel(out io.Writer) error {
c.Right(1).Str("Rounds")
c.Right(1).Str("Kills")
c.Right(1).Str("Deaths")
c.Right(1).Str("Assists (TODO)")
c.Right(1).Str("Assists")
c.Right(1).Str("Hs%")
c.Right(1).Str("Headshots")

Expand Down
7 changes: 5 additions & 2 deletions dissect/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Reader struct {
playersRead int
Header Header `json:"header"`
MatchFeedback []MatchUpdate `json:"matchFeedback"`
Scoreboard Scoreboard
}

// NewReader decompresses in using zstd and
Expand All @@ -49,7 +50,7 @@ func NewReader(in io.Reader) (r *Reader, err error) {
return r, err
}
} else {
if err = r.readUnchunkedData(br); err != nil {
if err = r.readNonChunkedData(br); err != nil {
return r, err
}
}
Expand All @@ -65,6 +66,8 @@ func NewReader(in io.Reader) (r *Reader, err error) {
}
r.Listen([]byte{0x59, 0x34, 0xE5, 0x8B, 0x04}, readMatchFeedback)
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)
return r, err
}

Expand Down Expand Up @@ -133,7 +136,7 @@ func (r *Reader) readChunkedData(genericReader io.Reader) error {
return nil
}

func (r *Reader) readUnchunkedData(genericReader io.Reader) error {
func (r *Reader) readNonChunkedData(genericReader io.Reader) error {
zstdReader, err := zstd.NewReader(genericReader)
if err != nil {
return err
Expand Down
69 changes: 69 additions & 0 deletions dissect/scoreboard.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package dissect

import "github.com/rs/zerolog/log"

type Scoreboard struct {
Players []ScoreboardPlayer
}

type ScoreboardPlayer struct {
ID []byte
Score uint32
Assists uint32
}

func readScoreboardAssists(r *Reader) error {
assists, err := r.Uint32()
if err != nil {
return err
}
if assists == 0 {
return nil
}
if err = r.Skip(30); err != nil {
return err
}
id, err := r.Bytes(4)
if err != nil {
return err
}
idx := r.PlayerIndexByID(id)
username := "N/A"
if idx != -1 {
username = r.Header.Players[idx].Username
r.Scoreboard.Players[idx].Assists = assists
}
log.Debug().
Uint32("assists", assists).
Str("username", username).
Msg("scoreboard_assists")
return nil
}

func readScoreboardScore(r *Reader) error {
score, err := r.Uint32()
if err != nil {
return err
}
if score == 0 {
return nil
}
if err = r.Skip(13); err != nil {
return err
}
id, err := r.Bytes(4)
if err != nil {
return err
}
idx := r.PlayerIndexByID(id)
username := "N/A"
if idx != -1 {
username = r.Header.Players[idx].Username
r.Scoreboard.Players[idx].Score = score
}
log.Debug().
Uint32("score", score).
Str("username", username).
Msg("scoreboard_score")
return nil
}
4 changes: 4 additions & 0 deletions dissect/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dissect
type PlayerRoundStats struct {
Username string `json:"username"`
TeamIndex int `json:"-"`
Score int `json:"score"`
Operator string `json:"-"`
Kills int `json:"kills"`
Died bool `json:"died"`
Expand Down Expand Up @@ -83,10 +84,13 @@ func (r *Reader) PlayerStats() []PlayerRoundStats {
winningTeamIndex = 1
}
for i, p := range r.Header.Players {
scorePlayer := r.Scoreboard.Players[i]
stats = append(stats, PlayerRoundStats{
Username: p.Username,
TeamIndex: p.TeamIndex,
Operator: p.Operator.String(),
Assists: int(scorePlayer.Assists),
Score: int(scorePlayer.Score),
})
index[p.Username] = i
}
Expand Down

0 comments on commit 1cb1111

Please sign in to comment.