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

feat: more source 2 player props support #402

Merged
merged 1 commit into from
Aug 16, 2023
Merged
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
62 changes: 62 additions & 0 deletions pkg/demoinfocs/common/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,18 +258,44 @@ func (p *Player) IsScoped() bool {
// IsDucking returns true if the player is currently fully crouching.
// See also: Flags().Ducking() & Flags().DuckingKeyPressed()
func (p *Player) IsDucking() bool {
if p.demoInfoProvider.IsSource2() {
return p.Flags().Ducking()
}

return p.Flags().Ducking() && p.Flags().DuckingKeyPressed()
}

// IsDuckingInProgress returns true if the player is currently in the progress of going from standing to crouched.
// See also: Flags().Ducking() & Flags().DuckingKeyPressed()
func (p *Player) IsDuckingInProgress() bool {
if p.demoInfoProvider.IsSource2() {
pawnEntity := p.PlayerPawnEntity()
if pawnEntity == nil {
return false
}
duckAmount := pawnEntity.PropertyValueMust("m_pMovementServices.m_flDuckAmount").Float()
wantToDuck := pawnEntity.PropertyValueMust("m_pMovementServices.m_bDesiresDuck").BoolVal()

return !p.Flags().Ducking() && wantToDuck && duckAmount > 0
}

return !p.Flags().Ducking() && p.Flags().DuckingKeyPressed()
}

// IsUnDuckingInProgress returns true if the player is currently in the progress of going from crouched to standing.
// See also: Flags().Ducking() & Flags().DuckingKeyPressed()
func (p *Player) IsUnDuckingInProgress() bool {
if p.demoInfoProvider.IsSource2() {
pawnEntity := p.PlayerPawnEntity()
if pawnEntity == nil {
return false
}
duckAmount := pawnEntity.PropertyValueMust("m_pMovementServices.m_flDuckAmount").Float()
wantToDuck := pawnEntity.PropertyValueMust("m_pMovementServices.m_bDesiresDuck").BoolVal()

return !p.Flags().Ducking() && !wantToDuck && duckAmount > 0
}

return p.Flags().Ducking() && !p.Flags().DuckingKeyPressed()
}

Expand Down Expand Up @@ -515,11 +541,19 @@ func (p *Player) resourceEntity() st.Entity {

// ClanTag returns the player's individual clan tag (Steam Groups etc.).
func (p *Player) ClanTag() string {
if p.demoInfoProvider.IsSource2() {
return getString(p.Entity, "m_szClan")
}

return getString(p.resourceEntity(), "m_szClan."+p.entityIDStr())
}

// CrosshairCode returns the player's crosshair code or an empty string if there isn't one.
func (p *Player) CrosshairCode() string {
if p.demoInfoProvider.IsSource2() {
return getString(p.Entity, "m_szCrosshairCodes")
}

if p.resourceEntity() == nil {
return ""
}
Expand Down Expand Up @@ -630,26 +664,54 @@ func (p *Player) MVPs() int {

// TotalDamage returns the total health damage done by the player.
func (p *Player) TotalDamage() int {
if p.demoInfoProvider.IsSource2() {
value := p.Entity.PropertyValueMust("m_pActionTrackingServices.m_iDamage")
if value.Any == nil {
return 0
}
return value.Int()
}

return getInt(p.resourceEntity(), "m_iMatchStats_Damage_Total."+p.entityIDStr())
}

// UtilityDamage returns the total damage done by the player with grenades.
func (p *Player) UtilityDamage() int {
if p.demoInfoProvider.IsSource2() {
value := p.Entity.PropertyValueMust("m_pActionTrackingServices.m_iUtilityDamage")
if value.Any == nil {
return 0
}
return value.Int()
}

return getInt(p.resourceEntity(), "m_iMatchStats_UtilityDamage_Total."+p.entityIDStr())
}

// MoneySpentTotal returns the total amount of money the player has spent in the current match.
func (p *Player) MoneySpentTotal() int {
if p.demoInfoProvider.IsSource2() {
return getInt(p.Entity, "m_pInGameMoneyServices.m_iTotalCashSpent")
}

return getInt(p.resourceEntity(), "m_iTotalCashSpent."+p.entityIDStr())
}

// MoneySpentThisRound returns the amount of money the player has spent in the current round.
func (p *Player) MoneySpentThisRound() int {
if p.demoInfoProvider.IsSource2() {
return getInt(p.Entity, "m_pInGameMoneyServices.m_iCashSpentThisRound")
}

return getInt(p.resourceEntity(), "m_iCashSpentThisRound."+p.entityIDStr())
}

// LastPlaceName returns the string value of the player's position.
func (p *Player) LastPlaceName() string {
if p.demoInfoProvider.IsSource2() {
return getString(p.PlayerPawnEntity(), "m_szLastPlaceName")
}

return getString(p.Entity, "m_szLastPlaceName")
}

Expand Down
Loading