Skip to content

Commit d7f0779

Browse files
committed
fix: possible invalid weapon in kill events
Following #490. - It's not always a suffix - it can be a prefix. - The suffix/prefix is not the killer's name but the words `vip` or `default` (there may be others). - The team's name may also be part of the suffix/prefix Noticed with demos coming from akiver/cs-demo-manager#727. Example with this one https://mega.nz/file/LZFlhATB#aCO-g1hoGohndAKXJVUHzLCcbyzH-n7cGi9ZWO5UdSM. Weapon's name from game events: ``` 5e_vip_usp_silencer 5e_default_deagle 5e_vip_xm1014 5e_default_mp9 5e_default_galilar 5e_vip_m4a1_silencer 5e_vip_ak47 ```
1 parent 935fd38 commit d7f0779

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

pkg/demoinfocs/common/equipment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ func MapEquipment(eqName string) EquipmentType {
287287
wep = EqHelmet
288288
} else {
289289
for name := range eqNameToWeapon {
290-
if strings.HasPrefix(eqName, name) {
290+
if strings.HasPrefix(eqName, name) || strings.HasSuffix(eqName, name) {
291291
wep = eqNameToWeapon[name]
292292
break
293293
}

pkg/demoinfocs/common/equipment_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ func TestMapEquipment(t *testing.T) {
2929
assert.Equal(t, EqUnknown, MapEquipment("asdf"), "'asdf' should be mapped to EqUnknown")
3030
}
3131

32+
func TestWeirdCS2Values(t *testing.T) {
33+
assert.Equal(t, EqDeagle, MapEquipment("deagle_vip"), "'deagle_vip' should be mapped to EqDeagle")
34+
assert.Equal(t, EqUSP, MapEquipment("usp_silencer_vip"), "'usp_silencer_vip' should be mapped to EqUSP")
35+
assert.Equal(t, EqUSP, MapEquipment("5e_vip_usp_silencer"), "'5e_vip_usp_silencer' should be mapped to EqUSP")
36+
assert.Equal(t, EqAK47, MapEquipment("5e_vip_ak47"), "'5e_vip_ak47' should be mapped to EqAK47")
37+
assert.Equal(t, EqDeagle, MapEquipment("5e_default_deagle"), "'5e_default_deagle' should be mapped to EqDeagle")
38+
}
39+
3240
func TestEquipment_Class(t *testing.T) {
3341
assert.Equal(t, EqClassUnknown, NewEquipment(EqUnknown).Class(), "EqUnknown should have the class EqClassUnknown")
3442
assert.Equal(t, EqClassPistols, NewEquipment(EqP2000).Class(), "EqP2000 should have the class EqClassPistols")

0 commit comments

Comments
 (0)