demoinfocs-golang icon indicating copy to clipboard operation
demoinfocs-golang copied to clipboard

Missing player in TeamState.Members()

Open CapekM opened this issue 1 year ago • 2 comments
trafficstars

Describe the bug I was parsing demofiles from HLTV and noticed that parser.GameState().TeamTerrorists().Members() does not return all players, but all players are in the parser.GameState().Participants().All(). When I looked into the func (ptcp participants) TeamMembers(team common.Team) there were only 9 participants, but the parser.GameState().Participants().All() is returning 13 players and all right ones are there. When I looked into the p.parser.GameState().Participants().Connected/Playing() there are the 9 players. I'm not sure if it's a problem with data or the parser, since I'm not much proficient with this library. Thanks for any reply.

To Reproduce For example:

  • 1st map of https://www.hltv.org/matches/2368503/virtuspro-vs-spirit-betboom-dacha-2023
    • After 3rd round player mir
  • Both maps of https://www.hltv.org/matches/2368419/space-vs-alternate-attax-cct-2023-online-finals-5
    • 1st map after 5th round player fozil
    • 2nd map after 4th round player PerX

Library version v4.0.0

CapekM avatar Jan 04 '24 21:01 CapekM

There seems to be an issue with disconnecting and reconnecting. When "mir" disconnects and later reconnects he is still marked as disconnected

Round finished: winnerSide=T  ; team_len=5:5
Round finished: winnerSide=T  ; team_len=5:5
Round finished: winnerSide=T  ; team_len=5:5
player mir disconnected
player mir connected
Round finished: winnerSide=T  ; team_len=5:4
Round finished: winnerSide=T  ; team_len=5:4

Probably there should be some additional handling for this situation in the playerConnect method analogically to the disconnecting https://github.com/markus-wa/demoinfocs-golang/blob/5543f4b8241a8a525bfa9ebe2ece95b0323746fb/pkg/demoinfocs/game_events.go#L655-L662 inside the playerDisconnect method?

kartol avatar Jan 08 '24 15:01 kartol

This is related to #494; I believe the problem is that we should switch to track players using the CCSTeam.m_aPlayers.00xx prop. From here, we can correctly keep track of players moving in and out of teams like so:

The most basic version of this is:

teamPlayers := make([]*common.Player, 64)

for i := 0; i < 64; i++ {
	i := i
	slot := fmt.Sprintf("m_aPlayers.%04d", i)
	entity.Property(slot).OnUpdate(func(pv st.PropertyValue) {
		var player *common.Player
		if pv.Any != nil {
			player = p.gameState.playersByEntityID[entityIDFromHandle(pv.S2UInt64(), true)]
		}
		teamPlayers[i] = player

		fmt.Printf("%v switched to %s\n", player, team)
	})
}

I have something like the above hacky version of this working locally, but I think we might need to consult @markus-wa or @akiver to decide how to do this properly. Right now I can't see a way to do this without a medium-sized overhaul of the team-related code.

micvbang avatar Jan 24 '24 20:01 micvbang

Sorry I'm currently a bit slow at getting back on issues - this definitely seems like an important thing to fix. I'm not sure about m_aPlayers - what about using m_iTeamNum on the player pawns?

I don't know how quickly I'll be able to get to this so MRs are very welcome. Happy to go with the m_aPlayers path if that seems to be the most reliable

markus-wa avatar Jan 31 '24 12:01 markus-wa

Sorry I'm currently a bit slow at getting back on issues - this definitely seems like an important thing to fix. I'm not sure about m_aPlayers - what about using m_iTeamNum on the player pawns?

I don't know how quickly I'll be able to get to this so MRs are very welcome. Happy to go with the m_aPlayers path if that seems to be the most reliable

This looks relevant: https://github.com/akiver/cs-demo-analyzer/blob/6c642144c19a40277e3690a3d6fc42e313f8752e/pkg/api/ebot.go#L71

micvbang avatar Feb 02 '24 20:02 micvbang

could you try with this branch please? https://github.com/markus-wa/demoinfocs-golang/pull/499

akiver avatar Feb 02 '24 23:02 akiver

I will be closing this for now, feel free to reopen if the issue persists with v4.0.2

markus-wa avatar Feb 09 '24 10:02 markus-wa