Skip to content

Commit db911cb

Browse files
committed
fix missing PlayerConnect events
1 parent a5adbe2 commit db911cb

File tree

1 file changed

+57
-49
lines changed

1 file changed

+57
-49
lines changed

pkg/demoinfocs/datatables.go

Lines changed: 57 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -488,72 +488,80 @@ func (p *parser) bindNewPlayerControllerS2(controllerEntity st.Entity) {
488488
}
489489

490490
func (p *parser) bindNewPlayerPawnS2(pawnEntity st.Entity) {
491-
controllerHandle := pawnEntity.PropertyValueMust("m_hController").Handle()
492-
if controllerHandle == constants.InvalidEntityHandleSource2 {
493-
return
494-
}
491+
var prevControllerHandle uint64
495492

496-
controllerEntityID := int(controllerHandle & constants.EntityHandleIndexMaskSource2)
497-
controllerEntity := p.gameState.playerControllerEntities[controllerEntityID]
493+
pawnEntity.Property("m_hController").OnUpdate(func(controllerHandleVal st.PropertyValue) {
494+
controllerHandle := controllerHandleVal.Handle()
495+
if controllerHandle == constants.InvalidEntityHandleSource2 || controllerHandle == prevControllerHandle {
496+
return
497+
}
498498

499-
pl := p.getOrCreatePlayerFromControllerEntity(controllerEntity)
500-
pl.IsConnected = true
499+
prevControllerHandle = controllerHandle
501500

502-
if pl.SteamID64 != 0 {
503-
p.eventDispatcher.Dispatch(events.PlayerConnect{Player: pl})
504-
} else {
505-
p.eventDispatcher.Dispatch(events.BotConnect{Player: pl})
506-
}
501+
controllerEntityID := int(controllerHandle & constants.EntityHandleIndexMaskSource2)
502+
controllerEntity := p.gameState.playerControllerEntities[controllerEntityID]
507503

508-
// Position
509-
pawnEntity.OnPositionUpdate(func(pos r3.Vector) {
510-
if pl.IsAlive() {
511-
pl.LastAlivePosition = pos
512-
}
513-
})
504+
pl := p.getOrCreatePlayerFromControllerEntity(controllerEntity)
514505

515-
pawnEntity.Property("m_flFlashDuration").OnUpdate(func(val st.PropertyValue) {
506+
if !pl.IsConnected {
507+
pl.IsConnected = true
516508

517-
if val.Float() == 0 {
518-
pl.FlashTick = 0
519-
} else {
520-
pl.FlashTick = p.gameState.ingameTick
509+
if pl.SteamID64 != 0 {
510+
p.eventDispatcher.Dispatch(events.PlayerConnect{Player: pl})
511+
} else {
512+
p.eventDispatcher.Dispatch(events.BotConnect{Player: pl})
513+
}
521514
}
522515

523-
pl.FlashDuration = val.Float()
516+
// Position
517+
pawnEntity.OnPositionUpdate(func(pos r3.Vector) {
518+
if pl.IsAlive() {
519+
pl.LastAlivePosition = pos
520+
}
521+
})
524522

525-
if pl.FlashDuration > 0 {
526-
if len(p.gameState.flyingFlashbangs) == 0 {
527-
return
523+
pawnEntity.Property("m_flFlashDuration").OnUpdate(func(val st.PropertyValue) {
524+
if val.Float() == 0 {
525+
pl.FlashTick = 0
526+
} else {
527+
pl.FlashTick = p.gameState.ingameTick
528528
}
529529

530-
flashbang := p.gameState.flyingFlashbangs[0]
531-
flashbang.flashedEntityIDs = append(flashbang.flashedEntityIDs, pl.EntityID)
532-
}
533-
})
530+
pl.FlashDuration = val.Float()
534531

535-
p.bindPlayerWeaponsS2(pawnEntity, pl)
532+
if pl.FlashDuration > 0 {
533+
if len(p.gameState.flyingFlashbangs) == 0 {
534+
return
535+
}
536536

537-
pawnEntity.Property("m_pWeaponServices.m_hActiveWeapon").OnUpdate(func(val st.PropertyValue) {
538-
pl.IsReloading = false
539-
})
537+
flashbang := p.gameState.flyingFlashbangs[0]
538+
flashbang.flashedEntityIDs = append(flashbang.flashedEntityIDs, pl.EntityID)
539+
}
540+
})
540541

541-
pawnEntity.Property("m_bIsDefusing").OnUpdate(func(val st.PropertyValue) {
542-
pl.IsDefusing = val.BoolVal()
543-
})
542+
p.bindPlayerWeaponsS2(pawnEntity, pl)
544543

545-
spottedByMaskProp := pawnEntity.Property("m_bSpottedByMask.0000")
546-
if spottedByMaskProp != nil {
547-
spottersChanged := func(val st.PropertyValue) {
548-
p.eventDispatcher.Dispatch(events.PlayerSpottersChanged{Spotted: pl})
549-
}
544+
pawnEntity.Property("m_pWeaponServices.m_hActiveWeapon").OnUpdate(func(val st.PropertyValue) {
545+
pl.IsReloading = false
546+
})
550547

551-
spottedByMaskProp.OnUpdate(spottersChanged)
552-
pawnEntity.Property("m_bSpottedByMask.0001").OnUpdate(spottersChanged)
553-
}
548+
pawnEntity.Property("m_bIsDefusing").OnUpdate(func(val st.PropertyValue) {
549+
pl.IsDefusing = val.BoolVal()
550+
})
554551

555-
pawnEntity.OnDestroy(func() {
556-
pl.IsConnected = false
552+
spottedByMaskProp := pawnEntity.Property("m_bSpottedByMask.0000")
553+
if spottedByMaskProp != nil {
554+
spottersChanged := func(val st.PropertyValue) {
555+
p.eventDispatcher.Dispatch(events.PlayerSpottersChanged{Spotted: pl})
556+
}
557+
558+
spottedByMaskProp.OnUpdate(spottersChanged)
559+
pawnEntity.Property("m_bSpottedByMask.0001").OnUpdate(spottersChanged)
560+
}
561+
562+
pawnEntity.OnDestroy(func() {
563+
pl.IsConnected = false
564+
})
557565
})
558566
}
559567

0 commit comments

Comments
 (0)