@@ -4,10 +4,10 @@ import (
4
4
"fmt"
5
5
"strings"
6
6
7
- r3 "github.com/golang/geo/r3"
7
+ "github.com/golang/geo/r3"
8
8
9
- common "github.com/markus-wa/demoinfocs-golang/common"
10
- events "github.com/markus-wa/demoinfocs-golang/events"
9
+ "github.com/markus-wa/demoinfocs-golang/common"
10
+ "github.com/markus-wa/demoinfocs-golang/events"
11
11
st "github.com/markus-wa/demoinfocs-golang/sendtables"
12
12
)
13
13
@@ -95,15 +95,15 @@ func (p *Parser) bindBomb() {
95
95
// Track bomb when it is being held by a player
96
96
scPlayerC4 := p .stParser .ServerClasses ().FindByName ("CC4" )
97
97
scPlayerC4 .OnEntityCreated (func (bombEntity * st.Entity ) {
98
- bombEntity .FindProperty ("m_hOwner" ).OnUpdate (func (val st.PropertyValue ) {
98
+ bombEntity .FindPropertyI ("m_hOwner" ).OnUpdate (func (val st.PropertyValue ) {
99
99
bomb .Carrier = p .gameState .Participants ().FindByHandle (val .IntVal )
100
100
})
101
101
})
102
102
}
103
103
104
104
func (p * Parser ) bindTeamStates () {
105
105
p .stParser .ServerClasses ().FindByName ("CCSTeam" ).OnEntityCreated (func (entity * st.Entity ) {
106
- team := entity .FindProperty ("m_szTeamname" ).Value ().StringVal
106
+ team := entity .FindPropertyI ("m_szTeamname" ).Value ().StringVal
107
107
108
108
var s * common.TeamState
109
109
@@ -127,7 +127,7 @@ func (p *Parser) bindTeamStates() {
127
127
entity .BindProperty ("m_szClanTeamname" , & s .ClanName , st .ValTypeString )
128
128
entity .BindProperty ("m_szTeamFlagImage" , & s .Flag , st .ValTypeString )
129
129
130
- entity .FindProperty ("m_scoreTotal" ).OnUpdate (func (val st.PropertyValue ) {
130
+ entity .FindPropertyI ("m_scoreTotal" ).OnUpdate (func (val st.PropertyValue ) {
131
131
oldScore := s .Score
132
132
s .Score = val .IntVal
133
133
@@ -220,7 +220,7 @@ func (p *Parser) bindNewPlayer(playerEntity st.IEntity) {
220
220
})
221
221
222
222
// General info
223
- playerEntity .FindProperty ("m_iTeamNum" ).OnUpdate (func (val st.PropertyValue ) {
223
+ playerEntity .FindPropertyI ("m_iTeamNum" ).OnUpdate (func (val st.PropertyValue ) {
224
224
pl .Team = common .Team (val .IntVal ) // Need to cast to team so we can't use BindProperty
225
225
pl .TeamState = p .gameState .Team (pl .Team )
226
226
})
@@ -233,7 +233,7 @@ func (p *Parser) bindNewPlayer(playerEntity st.IEntity) {
233
233
234
234
playerEntity .BindProperty ("m_angEyeAngles[1]" , & pl .ViewDirectionX , st .ValTypeFloat32 )
235
235
playerEntity .BindProperty ("m_angEyeAngles[0]" , & pl .ViewDirectionY , st .ValTypeFloat32 )
236
- playerEntity .FindProperty ("m_flFlashDuration" ).OnUpdate (func (val st.PropertyValue ) {
236
+ playerEntity .FindPropertyI ("m_flFlashDuration" ).OnUpdate (func (val st.PropertyValue ) {
237
237
if val .FloatVal == 0 {
238
238
pl .FlashTick = 0
239
239
} else {
@@ -254,7 +254,7 @@ func (p *Parser) bindNewPlayer(playerEntity st.IEntity) {
254
254
255
255
// Some demos have an additional prefix for player weapons weapon
256
256
var wepPrefix string
257
- if playerEntity .FindProperty (playerWeaponPrefix + "000" ) != nil {
257
+ if playerEntity .FindPropertyI (playerWeaponPrefix + "000" ) != nil {
258
258
wepPrefix = playerWeaponPrefix
259
259
} else {
260
260
wepPrefix = playerWeaponPrePrefix + playerWeaponPrefix
@@ -264,7 +264,7 @@ func (p *Parser) bindNewPlayer(playerEntity st.IEntity) {
264
264
var cache [maxWeapons ]int
265
265
for i := range cache {
266
266
i2 := i // Copy for passing to handler
267
- playerEntity .FindProperty (wepPrefix + fmt .Sprintf ("%03d" , i )).OnUpdate (func (val st.PropertyValue ) {
267
+ playerEntity .FindPropertyI (wepPrefix + fmt .Sprintf ("%03d" , i )).OnUpdate (func (val st.PropertyValue ) {
268
268
entityID := val .IntVal & entityHandleIndexMask
269
269
if entityID != entityHandleIndexMask {
270
270
if cache [i2 ] != 0 {
@@ -289,7 +289,7 @@ func (p *Parser) bindNewPlayer(playerEntity st.IEntity) {
289
289
}
290
290
291
291
// Active weapon
292
- playerEntity .FindProperty ("m_hActiveWeapon" ).OnUpdate (func (val st.PropertyValue ) {
292
+ playerEntity .FindPropertyI ("m_hActiveWeapon" ).OnUpdate (func (val st.PropertyValue ) {
293
293
pl .ActiveWeaponID = val .IntVal & entityHandleIndexMask
294
294
})
295
295
@@ -298,14 +298,23 @@ func (p *Parser) bindNewPlayer(playerEntity st.IEntity) {
298
298
playerEntity .BindProperty ("m_iAmmo." + fmt .Sprintf ("%03d" , i2 ), & pl .AmmoLeft [i2 ], st .ValTypeInt )
299
299
}
300
300
301
- playerEntity .FindProperty ("m_bIsDefusing" ).OnUpdate (func (val st.PropertyValue ) {
301
+ playerEntity .FindPropertyI ("m_bIsDefusing" ).OnUpdate (func (val st.PropertyValue ) {
302
302
if p .gameState .currentDefuser == pl && pl .IsDefusing && val .IntVal == 0 {
303
303
p .eventDispatcher .Dispatch (events.BombDefuseAborted {Player : pl })
304
304
p .gameState .currentDefuser = nil
305
305
}
306
306
pl .IsDefusing = val .IntVal != 0
307
307
})
308
308
309
+ spottedByMaskProp := playerEntity .FindPropertyI ("m_bSpottedByMask.000" )
310
+ if spottedByMaskProp != nil {
311
+ spottersChanged := func (val st.PropertyValue ) {
312
+ p .eventDispatcher .Dispatch (events.PlayerSpottersChanged {Spotted : pl })
313
+ }
314
+ spottedByMaskProp .OnUpdate (spottersChanged )
315
+ playerEntity .FindPropertyI ("m_bSpottedByMask.001" ).OnUpdate (spottersChanged )
316
+ }
317
+
309
318
if isNew && pl .SteamID != 0 {
310
319
p .eventDispatcher .Dispatch (events.PlayerConnect {Player : pl })
311
320
}
@@ -349,16 +358,16 @@ func (p *Parser) bindGrenadeProjectiles(entity *st.Entity) {
349
358
p .nadeProjectileDestroyed (proj )
350
359
})
351
360
352
- entity .FindProperty ("m_nModelIndex" ).OnUpdate (func (val st.PropertyValue ) {
361
+ entity .FindPropertyI ("m_nModelIndex" ).OnUpdate (func (val st.PropertyValue ) {
353
362
proj .Weapon = p .grenadeModelIndices [val .IntVal ]
354
363
})
355
364
356
365
// @micvbang: not quite sure what the difference between Thrower and Owner is.
357
- entity .FindProperty ("m_hThrower" ).OnUpdate (func (val st.PropertyValue ) {
366
+ entity .FindPropertyI ("m_hThrower" ).OnUpdate (func (val st.PropertyValue ) {
358
367
proj .Thrower = p .gameState .Participants ().FindByHandle (val .IntVal )
359
368
})
360
369
361
- entity .FindProperty ("m_hOwnerEntity" ).OnUpdate (func (val st.PropertyValue ) {
370
+ entity .FindPropertyI ("m_hOwnerEntity" ).OnUpdate (func (val st.PropertyValue ) {
362
371
proj .Owner = p .gameState .Participants ().FindByHandle (val .IntVal )
363
372
})
364
373
@@ -370,8 +379,7 @@ func (p *Parser) bindGrenadeProjectiles(entity *st.Entity) {
370
379
371
380
// Some demos don't have this property as it seems
372
381
// So we need to check for nil and can't send out bounce events if it's missing
373
- bounceProp := entity .FindProperty ("m_nBounces" )
374
- if bounceProp != nil {
382
+ if bounceProp := entity .FindPropertyI ("m_nBounces" ); bounceProp != nil {
375
383
bounceProp .OnUpdate (func (val st.PropertyValue ) {
376
384
if val .IntVal != 0 {
377
385
p .eventDispatcher .Dispatch (events.GrenadeProjectileBounce {
@@ -405,19 +413,19 @@ func (p *Parser) bindWeapon(entity *st.Entity, wepType common.EquipmentElement)
405
413
eq .EntityID = entityID
406
414
eq .AmmoInMagazine = - 1
407
415
408
- entity .FindProperty ("m_iClip1" ).OnUpdate (func (val st.PropertyValue ) {
416
+ entity .FindPropertyI ("m_iClip1" ).OnUpdate (func (val st.PropertyValue ) {
409
417
eq .AmmoInMagazine = val .IntVal - 1
410
418
})
411
419
412
420
// Only weapons with scopes have m_zoomLevel property
413
- if entity .FindProperty ("m_zoomLevel" ) != nil {
414
- entity . BindProperty ( "m_zoomLevel" , & eq .ZoomLevel , st .ValTypeInt )
421
+ if zoomLvlProp := entity .FindPropertyI ("m_zoomLevel" ); zoomLvlProp != nil {
422
+ zoomLvlProp . Bind ( & eq .ZoomLevel , st .ValTypeInt )
415
423
}
416
424
417
- eq .AmmoType = entity .FindProperty ("LocalWeaponData.m_iPrimaryAmmoType" ).Value ().IntVal
425
+ eq .AmmoType = entity .FindPropertyI ("LocalWeaponData.m_iPrimaryAmmoType" ).Value ().IntVal
418
426
419
427
// Detect alternative weapons (P2k -> USP, M4A4 -> M4A1-S etc.)
420
- modelIndex := entity .FindProperty ("m_nModelIndex" ).Value ().IntVal
428
+ modelIndex := entity .FindPropertyI ("m_nModelIndex" ).Value ().IntVal
421
429
eq .OriginalString = p .modelPreCache [modelIndex ]
422
430
423
431
wepFix := func (defaultName , altName string , alt common.EquipmentElement ) {
@@ -459,13 +467,13 @@ func (p *Parser) bindNewInferno(entity *st.Entity) {
459
467
460
468
origin := entity .Position ()
461
469
nFires := 0
462
- entity .FindProperty ("m_fireCount" ).OnUpdate (func (val st.PropertyValue ) {
470
+ entity .FindPropertyI ("m_fireCount" ).OnUpdate (func (val st.PropertyValue ) {
463
471
for i := nFires ; i < val .IntVal ; i ++ {
464
472
iStr := fmt .Sprintf ("%03d" , i )
465
473
offset := r3.Vector {
466
- X : float64 (entity .FindProperty ("m_fireXDelta." + iStr ).Value ().IntVal ),
467
- Y : float64 (entity .FindProperty ("m_fireYDelta." + iStr ).Value ().IntVal ),
468
- Z : float64 (entity .FindProperty ("m_fireZDelta." + iStr ).Value ().IntVal ),
474
+ X : float64 (entity .FindPropertyI ("m_fireXDelta." + iStr ).Value ().IntVal ),
475
+ Y : float64 (entity .FindPropertyI ("m_fireYDelta." + iStr ).Value ().IntVal ),
476
+ Z : float64 (entity .FindPropertyI ("m_fireZDelta." + iStr ).Value ().IntVal ),
469
477
}
470
478
471
479
fire := & common.Fire {Vector : origin .Add (offset ), IsBurning : true }
@@ -499,7 +507,7 @@ func (p *Parser) bindGameRules() {
499
507
500
508
gameRules := p .ServerClasses ().FindByName ("CCSGameRulesProxy" )
501
509
gameRules .OnEntityCreated (func (entity * st.Entity ) {
502
- entity .FindProperty (grPrefix ("m_gamePhase" )).OnUpdate (func (val st.PropertyValue ) {
510
+ entity .FindPropertyI (grPrefix ("m_gamePhase" )).OnUpdate (func (val st.PropertyValue ) {
503
511
oldGamePhase := p .gameState .gamePhase
504
512
p .gameState .gamePhase = common .GamePhase (val .IntVal )
505
513
@@ -517,7 +525,7 @@ func (p *Parser) bindGameRules() {
517
525
})
518
526
519
527
entity .BindProperty (grPrefix ("m_totalRoundsPlayed" ), & p .gameState .totalRoundsPlayed , st .ValTypeInt )
520
- entity .FindProperty (grPrefix ("m_bWarmupPeriod" )).OnUpdate (func (val st.PropertyValue ) {
528
+ entity .FindPropertyI (grPrefix ("m_bWarmupPeriod" )).OnUpdate (func (val st.PropertyValue ) {
521
529
oldIsWarmupPeriod := p .gameState .isWarmupPeriod
522
530
p .gameState .isWarmupPeriod = val .IntVal == 1
523
531
@@ -527,7 +535,7 @@ func (p *Parser) bindGameRules() {
527
535
})
528
536
})
529
537
530
- entity .FindProperty (grPrefix ("m_bHasMatchStarted" )).OnUpdate (func (val st.PropertyValue ) {
538
+ entity .FindPropertyI (grPrefix ("m_bHasMatchStarted" )).OnUpdate (func (val st.PropertyValue ) {
531
539
oldMatchStarted := p .gameState .isMatchStarted
532
540
p .gameState .isMatchStarted = val .IntVal == 1
533
541
0 commit comments