Skip to content

Commit bb27e1d

Browse files
committed
sendtables: Entity.FindProperty() cleanup
1 parent 4609a93 commit bb27e1d

File tree

10 files changed

+83
-97
lines changed

10 files changed

+83
-97
lines changed

examples/entities/entities.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ func main() {
2121

2222
p.RegisterEventHandler(func(events.DataTablesParsed) {
2323
p.ServerClasses().FindByName("CWeaponAWP").OnEntityCreated(func(ent *st.Entity) {
24-
ent.FindPropertyI("m_hOwnerEntity").OnUpdate(func(val st.PropertyValue) {
24+
ent.FindProperty("m_hOwnerEntity").OnUpdate(func(val st.PropertyValue) {
2525
x := p.GameState().Participants().FindByHandle(val.IntVal)
2626
if x != nil {
2727
var prev string
28-
prevHandle := ent.FindPropertyI("m_hPrevOwner").Value().IntVal
28+
prevHandle := ent.FindProperty("m_hPrevOwner").Value().IntVal
2929
prevPlayer := p.GameState().Participants().FindByHandle(prevHandle)
3030
if prevPlayer != nil {
3131
if prevHandle != val.IntVal {

pkg/demoinfocs/common/common_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func entityWithProperty(propName string, value st.PropertyValue) st.IEntity {
143143
prop := new(stfake.Property)
144144
prop.On("Value").Return(value)
145145

146-
entity.On("FindPropertyI", propName).Return(prop)
146+
entity.On("FindProperty", propName).Return(prop)
147147

148148
return entity
149149
}

pkg/demoinfocs/common/inferno.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func (inf Inferno) Owner() *Player {
157157
// Thrower returns the player who threw the fire grenade.
158158
// Could be nil if the player disconnected after throwing it.
159159
func (inf Inferno) Thrower() *Player {
160-
return inf.demoInfoProvider.FindPlayerByHandle(inf.Entity.FindPropertyI("m_hOwnerEntity").Value().IntVal)
160+
return inf.demoInfoProvider.FindPlayerByHandle(inf.Entity.FindProperty("m_hOwnerEntity").Value().IntVal)
161161
}
162162

163163
func convexHull(pointCloud []r3.Vector) quickhull.ConvexHull {

pkg/demoinfocs/common/player.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (p *Player) IsAirborne() bool {
8181
return false
8282
}
8383

84-
groundEntityHandle := p.Entity.FindPropertyI("m_hGroundEntity").Value().IntVal
84+
groundEntityHandle := p.Entity.FindProperty("m_hGroundEntity").Value().IntVal
8585

8686
return groundEntityHandle == invalidEntityHandle
8787
}
@@ -160,10 +160,10 @@ func (p *Player) IsSpottedBy(other *Player) bool {
160160

161161
var mask st.IProperty
162162
if bit < 32 {
163-
mask = p.Entity.FindPropertyI("m_bSpottedByMask.000")
163+
mask = p.Entity.FindProperty("m_bSpottedByMask.000")
164164
} else {
165165
bit -= 32
166-
mask = p.Entity.FindPropertyI("m_bSpottedByMask.001")
166+
mask = p.Entity.FindProperty("m_bSpottedByMask.001")
167167
}
168168

169169
return (mask.Value().IntVal & (1 << bit)) != 0
@@ -176,22 +176,22 @@ func (p *Player) HasSpotted(other *Player) bool {
176176

177177
// IsInBombZone returns whether the player is currently in the bomb zone or not.
178178
func (p *Player) IsInBombZone() bool {
179-
return p.Entity.FindPropertyI("m_bInBombZone").Value().IntVal == 1
179+
return p.Entity.FindProperty("m_bInBombZone").Value().IntVal == 1
180180
}
181181

182182
// IsInBuyZone returns whether the player is currently in the buy zone or not.
183183
func (p *Player) IsInBuyZone() bool {
184-
return p.Entity.FindPropertyI("m_bInBuyZone").Value().IntVal == 1
184+
return p.Entity.FindProperty("m_bInBuyZone").Value().IntVal == 1
185185
}
186186

187187
// IsWalking returns whether the player is currently walking (sneaking) in or not.
188188
func (p *Player) IsWalking() bool {
189-
return p.Entity.FindPropertyI("m_bIsWalking").Value().IntVal == 1
189+
return p.Entity.FindProperty("m_bIsWalking").Value().IntVal == 1
190190
}
191191

192192
// IsScoped returns whether the player is currently scoped in or not.
193193
func (p *Player) IsScoped() bool {
194-
return p.Entity.FindPropertyI("m_bIsScoped").Value().IntVal == 1
194+
return p.Entity.FindProperty("m_bIsScoped").Value().IntVal == 1
195195
}
196196

197197
// CashSpentThisRound returns the amount of cash the player spent in the current round.
@@ -215,7 +215,7 @@ func (p *Player) IsControllingBot() bool {
215215
return false
216216
}
217217

218-
return p.Entity.FindPropertyI("m_bIsControllingBot").Value().IntVal != 0
218+
return p.Entity.FindProperty("m_bIsControllingBot").Value().IntVal != 0
219219
}
220220

221221
// ControlledBot returns the player instance of the bot that the player is controlling, if any.
@@ -225,7 +225,7 @@ func (p *Player) ControlledBot() *Player {
225225
return nil
226226
}
227227

228-
botHandle := p.Entity.FindPropertyI("m_iControlledBotEntIndex").Value().IntVal
228+
botHandle := p.Entity.FindProperty("m_iControlledBotEntIndex").Value().IntVal
229229

230230
return p.demoInfoProvider.FindPlayerByHandle(botHandle)
231231
}

pkg/demoinfocs/datatables.go

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ func (p *Parser) bindBomb() {
9191
bomb.LastOnGroundPosition = pos
9292
})
9393

94-
bombEntity.FindPropertyI("m_hOwner").OnUpdate(func(val st.PropertyValue) {
94+
bombEntity.FindProperty("m_hOwner").OnUpdate(func(val st.PropertyValue) {
9595
bomb.Carrier = p.gameState.Participants().FindByHandle(val.IntVal)
9696
})
9797

98-
bombEntity.FindPropertyI("m_bStartedArming").OnUpdate(func(val st.PropertyValue) {
98+
bombEntity.FindProperty("m_bStartedArming").OnUpdate(func(val st.PropertyValue) {
9999
if val.IntVal != 0 {
100100
p.gameState.currentPlanter = bomb.Carrier
101101
} else if p.gameState.currentPlanter != nil {
@@ -117,7 +117,7 @@ func (p *Parser) bindBomb() {
117117

118118
func (p *Parser) bindTeamStates() {
119119
p.stParser.ServerClasses().FindByName("CCSTeam").OnEntityCreated(func(entity *st.Entity) {
120-
team := entity.FindPropertyI("m_szTeamname").Value().StringVal
120+
team := entity.FindProperty("m_szTeamname").Value().StringVal
121121

122122
var s *common.TeamState
123123

@@ -141,7 +141,7 @@ func (p *Parser) bindTeamStates() {
141141
entity.BindProperty("m_szClanTeamname", &s.ClanName, st.ValTypeString)
142142
entity.BindProperty("m_szTeamFlagImage", &s.Flag, st.ValTypeString)
143143

144-
entity.FindPropertyI("m_scoreTotal").OnUpdate(func(val st.PropertyValue) {
144+
entity.FindProperty("m_scoreTotal").OnUpdate(func(val st.PropertyValue) {
145145
oldScore := s.Score
146146
s.Score = val.IntVal
147147

@@ -256,7 +256,7 @@ func (p *Parser) bindNewPlayer(playerEntity st.IEntity) {
256256
})
257257

258258
// General info
259-
playerEntity.FindPropertyI("m_iTeamNum").OnUpdate(func(val st.PropertyValue) {
259+
playerEntity.FindProperty("m_iTeamNum").OnUpdate(func(val st.PropertyValue) {
260260
pl.Team = common.Team(val.IntVal) // Need to cast to team so we can't use BindProperty
261261
pl.TeamState = p.gameState.Team(pl.Team)
262262
})
@@ -269,7 +269,7 @@ func (p *Parser) bindNewPlayer(playerEntity st.IEntity) {
269269

270270
playerEntity.BindProperty("m_angEyeAngles[1]", &pl.ViewDirectionX, st.ValTypeFloat32)
271271
playerEntity.BindProperty("m_angEyeAngles[0]", &pl.ViewDirectionY, st.ValTypeFloat32)
272-
playerEntity.FindPropertyI("m_flFlashDuration").OnUpdate(func(val st.PropertyValue) {
272+
playerEntity.FindProperty("m_flFlashDuration").OnUpdate(func(val st.PropertyValue) {
273273
if val.FloatVal == 0 {
274274
pl.FlashTick = 0
275275
} else {
@@ -291,7 +291,7 @@ func (p *Parser) bindNewPlayer(playerEntity st.IEntity) {
291291
p.bindPlayerWeapons(playerEntity, pl)
292292

293293
// Active weapon
294-
playerEntity.FindPropertyI("m_hActiveWeapon").OnUpdate(func(val st.PropertyValue) {
294+
playerEntity.FindProperty("m_hActiveWeapon").OnUpdate(func(val st.PropertyValue) {
295295
pl.IsReloading = false
296296
pl.ActiveWeaponID = val.IntVal & entityHandleIndexMask
297297
})
@@ -301,21 +301,21 @@ func (p *Parser) bindNewPlayer(playerEntity st.IEntity) {
301301
playerEntity.BindProperty("m_iAmmo."+fmt.Sprintf("%03d", i2), &pl.AmmoLeft[i2], st.ValTypeInt)
302302
}
303303

304-
playerEntity.FindPropertyI("m_bIsDefusing").OnUpdate(func(val st.PropertyValue) {
304+
playerEntity.FindProperty("m_bIsDefusing").OnUpdate(func(val st.PropertyValue) {
305305
if p.gameState.currentDefuser == pl && pl.IsDefusing && val.IntVal == 0 {
306306
p.eventDispatcher.Dispatch(events.BombDefuseAborted{Player: pl})
307307
p.gameState.currentDefuser = nil
308308
}
309309
pl.IsDefusing = val.IntVal != 0
310310
})
311311

312-
spottedByMaskProp := playerEntity.FindPropertyI("m_bSpottedByMask.000")
312+
spottedByMaskProp := playerEntity.FindProperty("m_bSpottedByMask.000")
313313
if spottedByMaskProp != nil {
314314
spottersChanged := func(val st.PropertyValue) {
315315
p.eventDispatcher.Dispatch(events.PlayerSpottersChanged{Spotted: pl})
316316
}
317317
spottedByMaskProp.OnUpdate(spottersChanged)
318-
playerEntity.FindPropertyI("m_bSpottedByMask.001").OnUpdate(spottersChanged)
318+
playerEntity.FindProperty("m_bSpottedByMask.001").OnUpdate(spottersChanged)
319319
}
320320

321321
if isNew && pl.SteamID != 0 {
@@ -326,7 +326,7 @@ func (p *Parser) bindNewPlayer(playerEntity st.IEntity) {
326326
func (p *Parser) bindPlayerWeapons(playerEntity st.IEntity, pl *common.Player) {
327327
// Some demos have an additional prefix for player weapons weapon
328328
var wepPrefix string
329-
if playerEntity.FindPropertyI(playerWeaponPrefix+"000") != nil {
329+
if playerEntity.FindProperty(playerWeaponPrefix+"000") != nil {
330330
wepPrefix = playerWeaponPrefix
331331
} else {
332332
wepPrefix = playerWeaponPrePrefix + playerWeaponPrefix
@@ -336,7 +336,7 @@ func (p *Parser) bindPlayerWeapons(playerEntity st.IEntity, pl *common.Player) {
336336
var cache [maxWeapons]int
337337
for i := range cache {
338338
i2 := i // Copy for passing to handler
339-
playerEntity.FindPropertyI(wepPrefix + fmt.Sprintf("%03d", i)).OnUpdate(func(val st.PropertyValue) {
339+
playerEntity.FindProperty(wepPrefix + fmt.Sprintf("%03d", i)).OnUpdate(func(val st.PropertyValue) {
340340
entityID := val.IntVal & entityHandleIndexMask
341341
if entityID != entityHandleIndexMask {
342342
if cache[i2] != 0 {
@@ -423,17 +423,16 @@ func (p *Parser) bindGrenadeProjectiles(entity *st.Entity) {
423423
p.nadeProjectileDestroyed(proj)
424424
})
425425

426-
entity.FindPropertyI("m_nModelIndex").OnUpdate(func(val st.PropertyValue) {
427-
proj.Weapon = p.grenadeModelIndices[val.IntVal]
426+
entity.FindProperty("m_nModelIndex").OnUpdate(func(val st.PropertyValue) {
428427
wep = p.grenadeModelIndices[val.IntVal]
429428
})
430429

431430
// @micvbang: not quite sure what the difference between Thrower and Owner is.
432-
entity.FindPropertyI("m_hThrower").OnUpdate(func(val st.PropertyValue) {
431+
entity.FindProperty("m_hThrower").OnUpdate(func(val st.PropertyValue) {
433432
proj.Thrower = p.gameState.Participants().FindByHandle(val.IntVal)
434433
})
435434

436-
entity.FindPropertyI("m_hOwnerEntity").OnUpdate(func(val st.PropertyValue) {
435+
entity.FindProperty("m_hOwnerEntity").OnUpdate(func(val st.PropertyValue) {
437436
proj.Owner = p.gameState.Participants().FindByHandle(val.IntVal)
438437
})
439438

@@ -445,7 +444,7 @@ func (p *Parser) bindGrenadeProjectiles(entity *st.Entity) {
445444

446445
// Some demos don't have this property as it seems
447446
// So we need to check for nil and can't send out bounce events if it's missing
448-
if bounceProp := entity.FindPropertyI("m_nBounces"); bounceProp != nil {
447+
if bounceProp := entity.FindProperty("m_nBounces"); bounceProp != nil {
449448
bounceProp.OnUpdate(func(val st.PropertyValue) {
450449
if val.IntVal != 0 {
451450
p.eventDispatcher.Dispatch(events.GrenadeProjectileBounce{
@@ -506,23 +505,23 @@ func (p *Parser) bindWeapon(entity *st.Entity, wepType common.EquipmentType) {
506505
delete(p.gameState.weapons, entityID)
507506
})
508507

509-
entity.FindPropertyI("m_iClip1").OnUpdate(func(val st.PropertyValue) {
508+
entity.FindProperty("m_iClip1").OnUpdate(func(val st.PropertyValue) {
510509
if eq.Owner != nil {
511510
eq.Owner.IsReloading = false
512511
}
513512
})
514513

515514
// Only weapons with scopes have m_zoomLevel property
516-
if zoomLvlProp := entity.FindPropertyI("m_zoomLevel"); zoomLvlProp != nil {
515+
if zoomLvlProp := entity.FindProperty("m_zoomLevel"); zoomLvlProp != nil {
517516
zoomLvlProp.OnUpdate(func(value st.PropertyValue) {
518517
eq.ZoomLevel = common.ZoomLevel(value.IntVal)
519518
})
520519
}
521520

522-
eq.AmmoType = entity.FindPropertyI("LocalWeaponData.m_iPrimaryAmmoType").Value().IntVal
521+
eq.AmmoType = entity.FindProperty("LocalWeaponData.m_iPrimaryAmmoType").Value().IntVal
523522

524523
// Detect alternative weapons (P2k -> USP, M4A4 -> M4A1-S etc.)
525-
modelIndex := entity.FindPropertyI("m_nModelIndex").Value().IntVal
524+
modelIndex := entity.FindProperty("m_nModelIndex").Value().IntVal
526525
eq.OriginalString = p.modelPreCache[modelIndex]
527526

528527
wepFix := func(defaultName, altName string, alt common.EquipmentType) {
@@ -565,13 +564,13 @@ func (p *Parser) bindNewInferno(entity *st.Entity) {
565564
origin := entity.Position()
566565
nFires := 0
567566

568-
entity.FindPropertyI("m_fireCount").OnUpdate(func(val st.PropertyValue) {
567+
entity.FindProperty("m_fireCount").OnUpdate(func(val st.PropertyValue) {
569568
for i := nFires; i < val.IntVal; i++ {
570569
iStr := fmt.Sprintf("%03d", i)
571570
offset := r3.Vector{
572-
X: float64(entity.FindPropertyI("m_fireXDelta." + iStr).Value().IntVal),
573-
Y: float64(entity.FindPropertyI("m_fireYDelta." + iStr).Value().IntVal),
574-
Z: float64(entity.FindPropertyI("m_fireZDelta." + iStr).Value().IntVal),
571+
X: float64(entity.FindProperty("m_fireXDelta." + iStr).Value().IntVal),
572+
Y: float64(entity.FindProperty("m_fireYDelta." + iStr).Value().IntVal),
573+
Z: float64(entity.FindProperty("m_fireZDelta." + iStr).Value().IntVal),
575574
}
576575

577576
fire := &common.Fire{Vector: origin.Add(offset), IsBurning: true}
@@ -607,7 +606,7 @@ func (p *Parser) bindGameRules() {
607606

608607
gameRules := p.ServerClasses().FindByName("CCSGameRulesProxy")
609608
gameRules.OnEntityCreated(func(entity *st.Entity) {
610-
entity.FindPropertyI(grPrefix("m_gamePhase")).OnUpdate(func(val st.PropertyValue) {
609+
entity.FindProperty(grPrefix("m_gamePhase")).OnUpdate(func(val st.PropertyValue) {
611610
oldGamePhase := p.gameState.gamePhase
612611
p.gameState.gamePhase = common.GamePhase(val.IntVal)
613612

@@ -625,7 +624,7 @@ func (p *Parser) bindGameRules() {
625624
})
626625

627626
entity.BindProperty(grPrefix("m_totalRoundsPlayed"), &p.gameState.totalRoundsPlayed, st.ValTypeInt)
628-
entity.FindPropertyI(grPrefix("m_bWarmupPeriod")).OnUpdate(func(val st.PropertyValue) {
627+
entity.FindProperty(grPrefix("m_bWarmupPeriod")).OnUpdate(func(val st.PropertyValue) {
629628
oldIsWarmupPeriod := p.gameState.isWarmupPeriod
630629
p.gameState.isWarmupPeriod = val.IntVal == 1
631630

@@ -635,7 +634,7 @@ func (p *Parser) bindGameRules() {
635634
})
636635
})
637636

638-
entity.FindPropertyI(grPrefix("m_bHasMatchStarted")).OnUpdate(func(val st.PropertyValue) {
637+
entity.FindProperty(grPrefix("m_bHasMatchStarted")).OnUpdate(func(val st.PropertyValue) {
639638
oldMatchStarted := p.gameState.isMatchStarted
640639
p.gameState.isMatchStarted = val.IntVal == 1
641640

pkg/demoinfocs/datatables_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func testPlayerSpotted(t *testing.T, propName string) {
9797
spottedByUpdateHandler = args.Get(0).(st.PropertyUpdateHandler)
9898
})
9999

100-
spotted.On("FindPropertyI", propName).Return(spottedByProp0)
100+
spotted.On("FindProperty", propName).Return(spottedByProp0)
101101
configurePlayerEntityMock(1, spotted)
102102
p.bindNewPlayer(spotted)
103103

@@ -138,7 +138,7 @@ func configurePlayerEntityMock(id int, entity *fakest.Entity) {
138138
})
139139

140140
entity.On("OnPositionUpdate", mock.Anything).Return()
141-
entity.On("FindPropertyI", mock.Anything).Return(new(st.Property))
141+
entity.On("FindProperty", mock.Anything).Return(new(st.Property))
142142
entity.On("BindProperty", mock.Anything, mock.Anything, mock.Anything)
143143
entity.On("Destroy").Run(func(mock.Arguments) {
144144
destroyCallback()

pkg/demoinfocs/game_state_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,10 @@ func TestParticipants_SpottersOf(t *testing.T) {
215215
entity := new(fake.Entity)
216216
prop0 := new(fake.Property)
217217
prop0.On("Value").Return(st.PropertyValue{IntVal: 1})
218-
entity.On("FindPropertyI", "m_bSpottedByMask.000").Return(prop0)
218+
entity.On("FindProperty", "m_bSpottedByMask.000").Return(prop0)
219219
prop1 := new(fake.Property)
220220
prop1.On("Value").Return(st.PropertyValue{IntVal: 1 << 2})
221-
entity.On("FindPropertyI", "m_bSpottedByMask.001").Return(prop1)
221+
entity.On("FindProperty", "m_bSpottedByMask.001").Return(prop1)
222222
spotted.Entity = entity
223223
spotted.EntityID = 3
224224

@@ -245,7 +245,7 @@ func TestParticipants_SpottedBy(t *testing.T) {
245245
entity := new(fake.Entity)
246246
prop0 := new(fake.Property)
247247
prop0.On("Value").Return(st.PropertyValue{IntVal: 1})
248-
entity.On("FindPropertyI", "m_bSpottedByMask.000").Return(prop0)
248+
entity.On("FindProperty", "m_bSpottedByMask.000").Return(prop0)
249249
spotted1.Entity = entity
250250
spotted2.Entity = entity
251251

@@ -257,7 +257,7 @@ func TestParticipants_SpottedBy(t *testing.T) {
257257
unSpottedEntity := new(fake.Entity)
258258
unSpottedProp := new(fake.Property)
259259
unSpottedProp.On("Value").Return(st.PropertyValue{IntVal: 0})
260-
unSpottedEntity.On("FindPropertyI", "m_bSpottedByMask.000").Return(unSpottedProp)
260+
unSpottedEntity.On("FindProperty", "m_bSpottedByMask.000").Return(unSpottedProp)
261261
unSpotted.Entity = unSpottedEntity
262262
spotter.Entity = unSpottedEntity
263263

0 commit comments

Comments
 (0)