Skip to content

Commit c324998

Browse files
committed
ref: clean up weapon prop formatting
backport of 3ea42aa
1 parent 4dbe718 commit c324998

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

pkg/demoinfocs/datatables.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -709,17 +709,17 @@ const maxWeapons = 64
709709
func (p *parser) bindPlayerWeapons(playerEntity st.Entity, pl *common.Player) {
710710
// Some demos have an additional prefix for player weapons weapon
711711
var wepPrefix string
712-
if playerEntity.Property(playerWeaponPrefix+"000") != nil {
712+
if playerEntity.Property(playerWeaponPrefix+".000") != nil {
713713
wepPrefix = playerWeaponPrefix
714714
} else {
715-
wepPrefix = playerWeaponPrePrefix + playerWeaponPrefix
715+
wepPrefix = "bcc_nonlocaldata." + playerWeaponPrefix
716716
}
717717

718718
// Weapons
719719
var cache [maxWeapons]int
720720
for i := range cache {
721721
i2 := i // Copy for passing to handler
722-
playerEntity.Property(wepPrefix + fmt.Sprintf("%03d", i)).OnUpdate(func(val st.PropertyValue) {
722+
playerEntity.Property(wepPrefix + fmt.Sprintf(".%03d", i)).OnUpdate(func(val st.PropertyValue) {
723723
entityID := val.IntVal & constants.EntityHandleIndexMask
724724
if entityID != constants.EntityHandleIndexMask {
725725
if cache[i2] != 0 {
@@ -785,7 +785,7 @@ func (p *parser) bindPlayerWeaponsS2(pawnEntity st.Entity, pl *common.Player) {
785785
inventory := make(map[int]*common.Equipment, inventorySize)
786786

787787
for i := 0; i < inventorySize; i++ {
788-
val := pawnEntity.Property(playerWeaponPrefixS2 + fmt.Sprintf("%04d", i)).Value()
788+
val := pawnEntity.Property(playerWeaponPrefixS2 + fmt.Sprintf(".%04d", i)).Value()
789789
if val.Any == nil {
790790
continue
791791
}
@@ -797,7 +797,7 @@ func (p *parser) bindPlayerWeaponsS2(pawnEntity st.Entity, pl *common.Player) {
797797
pl.Inventory = inventory
798798
}
799799

800-
pawnEntity.Property("m_pWeaponServices.m_hMyWeapons").OnUpdate(func(pv st.PropertyValue) {
800+
pawnEntity.Property(playerWeaponPrefixS2).OnUpdate(func(pv st.PropertyValue) {
801801
inventorySize = len(pv.S2Array())
802802
setPlayerInventory()
803803
})
@@ -834,7 +834,7 @@ func (p *parser) bindPlayerWeaponsS2(pawnEntity st.Entity, pl *common.Player) {
834834
}
835835
}
836836

837-
property := pawnEntity.Property(playerWeaponPrefixS2 + fmt.Sprintf("%04d", i))
837+
property := pawnEntity.Property(playerWeaponPrefixS2 + fmt.Sprintf(".%04d", i))
838838
updateWeapon(property.Value())
839839
property.OnUpdate(updateWeapon)
840840
}

pkg/demoinfocs/game_state.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func (gr gameRules) RoundTime() (time.Duration, error) {
282282
return 0, ErrFailedToRetrieveGameRule
283283
}
284284

285-
prop := gr.entity.Property("cs_gamerules_data.m_iRoundTime")
285+
prop := gr.entity.Property(gameRulesPrefix + ".m_iRoundTime")
286286
if prop == nil {
287287
return 0, ErrFailedToRetrieveGameRule
288288
}

pkg/demoinfocs/game_state_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ func TestGameRules_RoundTime(t *testing.T) {
322322
prop := new(stfake.Property)
323323
prop.On("Value").Return(st.PropertyValue{IntVal: 115})
324324
ent := new(stfake.Entity)
325-
ent.On("Property", "cs_gamerules_data.m_iRoundTime").Return(prop)
325+
ent.On("Property", gameRulesPrefix+".m_iRoundTime").Return(prop)
326326
gr := gameRules{entity: ent}
327327

328328
rt, err := gr.RoundTime()
@@ -346,7 +346,7 @@ func TestGameRules(t *testing.T) {
346346
assert.Equal(t, ErrFailedToRetrieveGameRule, err)
347347

348348
ent := new(stfake.Entity)
349-
ent.On("Property", "cs_gamerules_data.m_iRoundTime").Return(nil)
349+
ent.On("Property", gameRulesPrefix+".m_iRoundTime").Return(nil)
350350
gr = gameRules{entity: ent}
351351

352352
_, err = gr.RoundTime()

pkg/demoinfocs/parsing.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@ import (
2525
const maxOsPath = 260
2626

2727
const (
28-
playerWeaponPrefix = "m_hMyWeapons."
29-
playerWeaponPrefixS2 = "m_pWeaponServices.m_hMyWeapons."
30-
playerWeaponPrePrefix = "bcc_nonlocaldata."
31-
gameRulesPrefix = "cs_gamerules_data"
32-
gameRulesPrefixS2 = "m_pGameRules"
28+
playerWeaponPrefix = "m_hMyWeapons"
29+
playerWeaponPrefixS2 = "m_pWeaponServices.m_hMyWeapons"
30+
gameRulesPrefix = "cs_gamerules_data"
31+
gameRulesPrefixS2 = "m_pGameRules"
3332
)
3433

3534
// Parsing errors

0 commit comments

Comments
 (0)