Skip to content

Commit 40c8acb

Browse files
committed
Merge remote-tracking branch 'origin/master' into s2-fake-CMsgSource1LegacyGameEventList
2 parents faa66bb + 6c73556 commit 40c8acb

File tree

15 files changed

+96
-30
lines changed

15 files changed

+96
-30
lines changed

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2017-2023 Markus Walther
3+
Copyright (c) 2017-2024 Markus Walther
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# demoinfocs-golang - CS:GO & CS2 Demo Parser
1+
# demoinfocs-golang - Counter-Strike 2 & CS:GO Demo Parser
22

3-
A blazing fast, feature complete and production ready Go library for parsing and analysing of Counter-Strike: Global Offensive (CS:GO) demos (aka replays).
3+
A blazing fast, feature complete and production ready Go library for parsing and analysing of Counter-Strike 2 and Counter-Strike: Global Offensive (CS:GO) demos (aka replays).
44

55
Counter-Strike 2 support is experimental.
66

@@ -23,12 +23,10 @@ For business inquiries please use the contact information found on the [GitHub p
2323

2424
## Go Get
2525

26-
### CS2 - ⚠️ Experimental
26+
### Counter-Strike 2
2727

2828
go get -u github.com/markus-wa/demoinfocs-golang/v4/pkg/demoinfocs
2929

30-
⚠️ The CS2 / v4 API may change in backwards incompatible ways without warning.
31-
3230
### CS:GO
3331

3432
go get -u github.com/markus-wa/demoinfocs-golang/v3/pkg/demoinfocs
@@ -67,11 +65,7 @@ You can download the latest version of Go [here](https://golang.org/).
6765
```terminal
6866
mkdir my-project
6967
cd my-project
70-
71-
go mod init github.com/<YOUR_GITHUB_USER>/my-project
72-
# the module name (github.com/<YOUR_GITHUB_USER>/my-project) can always be changed later
73-
# you can also put example.com/my-project or anything else if you don't plan to publish your project
74-
68+
go mod init my-project
7569
go get -u github.com/markus-wa/demoinfocs-golang/v4/pkg/demoinfocs
7670
```
7771

examples/voice-capture/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Capturing Voice Data
22

3+
## CS2
4+
5+
See https://github.com/DandrewsDev/CS2VoiceData
6+
7+
## CS:GO
8+
39
This example shows how to use the library to capture voice audio from demos.
410

511
Since the build process is somewhat different from the library itself (due to usage of CGO), the example has it's own repository which you can find here:

pkg/demoinfocs/common/common_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ type fakeProp struct {
212212
type demoInfoProviderMock struct {
213213
tickRate float64
214214
ingameTick int
215-
playersByHandle map[int]*Player
215+
playersByHandle map[uint64]*Player
216216
entitiesByHandle map[uint64]st.Entity
217217
playerResourceEntity st.Entity
218218
equipment *Equipment
@@ -235,12 +235,12 @@ func (p demoInfoProviderMock) IngameTick() int {
235235
return p.ingameTick
236236
}
237237

238-
func (p demoInfoProviderMock) FindPlayerByHandle(handle int) *Player {
238+
func (p demoInfoProviderMock) FindPlayerByHandle(handle uint64) *Player {
239239
return p.playersByHandle[handle]
240240
}
241241

242242
func (p demoInfoProviderMock) FindPlayerByPawnHandle(handle uint64) *Player {
243-
return p.playersByHandle[int(handle)]
243+
return p.playersByHandle[handle]
244244
}
245245

246246
func (p demoInfoProviderMock) PlayerResourceEntity() st.Entity {

pkg/demoinfocs/common/equipment.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,18 @@ func MapEquipment(eqName string) EquipmentType {
281281
wep = EqKnife
282282
} else {
283283
// If the eqName isn't known it will be EqUnknown as that is the default value for EquipmentType
284-
wep = eqNameToWeapon[eqName]
284+
if strings.HasPrefix(eqName, "m4a1_silencer") {
285+
wep = EqM4A1
286+
} else if strings.HasPrefix(eqName, "vesthelm") {
287+
wep = EqHelmet
288+
} else {
289+
for name := range eqNameToWeapon {
290+
if strings.HasPrefix(eqName, name) || strings.HasSuffix(eqName, name) {
291+
wep = eqNameToWeapon[name]
292+
break
293+
}
294+
}
295+
}
285296
}
286297

287298
return wep

pkg/demoinfocs/common/equipment_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,19 @@ func TestMapEquipment(t *testing.T) {
2424
assert.Equal(t, EqKnife, MapEquipment("weapon_knife_butterfly"), "'weapon_knife_butterfly' should be mapped to EqKnife")
2525
assert.Equal(t, EqM4A4, MapEquipment("weapon_m4a1"), "'weapon_m4a1' should be mapped to EqM4A4") // This is correct, weapon_m4a1 == M4A4
2626
assert.Equal(t, EqM4A1, MapEquipment("weapon_m4a1_silencer"), "'weapon_m4a1_silencer' should be mapped to EqM4A1")
27+
assert.Equal(t, EqKevlar, MapEquipment("weapon_vest"), "'weapon_vest' should be mapped to EqKevlar")
28+
assert.Equal(t, EqHelmet, MapEquipment("weapon_vesthelm"), "'weapon_vesthelm' should be mapped to EqHelmet")
2729
assert.Equal(t, EqUnknown, MapEquipment("asdf"), "'asdf' should be mapped to EqUnknown")
2830
}
2931

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+
3040
func TestEquipment_Class(t *testing.T) {
3141
assert.Equal(t, EqClassUnknown, NewEquipment(EqUnknown).Class(), "EqUnknown should have the class EqClassUnknown")
3242
assert.Equal(t, EqClassPistols, NewEquipment(EqP2000).Class(), "EqP2000 should have the class EqClassPistols")

pkg/demoinfocs/common/hostage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (hostage *Hostage) Leader() *Player {
5757
return hostage.demoInfoProvider.FindPlayerByPawnHandle(getUInt64(hostage.Entity, "m_leader"))
5858
}
5959

60-
return hostage.demoInfoProvider.FindPlayerByHandle(getInt(hostage.Entity, "m_leader"))
60+
return hostage.demoInfoProvider.FindPlayerByHandle(uint64(getInt(hostage.Entity, "m_leader")))
6161
}
6262

6363
// NewHostage creates a hostage.

pkg/demoinfocs/common/hostage_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func TestHostage_Leader(t *testing.T) {
1212
player := new(Player)
1313
player.EntityID = 10
1414
provider := demoInfoProviderMock{
15-
playersByHandle: map[int]*Player{10: player},
15+
playersByHandle: map[uint64]*Player{10: player},
1616
}
1717
hostage := hostageWithProperty("m_leader", st.PropertyValue{IntVal: 10}, provider)
1818

pkg/demoinfocs/common/inferno.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (inf *Inferno) Thrower() *Player {
5757
return inf.demoInfoProvider.FindPlayerByPawnHandle(handleProp.Handle())
5858
}
5959

60-
return inf.demoInfoProvider.FindPlayerByHandle(handleProp.Int())
60+
return inf.demoInfoProvider.FindPlayerByHandle(uint64(handleProp.Int()))
6161
}
6262

6363
// Fires returns all fires (past + present).

pkg/demoinfocs/common/inferno_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func TestInferno_Thrower(t *testing.T) {
116116

117117
player := new(Player)
118118
provider := demoInfoProviderMock{
119-
playersByHandle: map[int]*Player{1: player},
119+
playersByHandle: map[uint64]*Player{1: player},
120120
}
121121

122122
assert.Equal(t, player, NewInferno(provider, entity, nil).Thrower())

0 commit comments

Comments
 (0)