Skip to content

Commit ff069e7

Browse files
committed
Merge remote-tracking branch 'origin/master' into v5
2 parents 097b925 + 454fdda commit ff069e7

26 files changed

+3570
-5732
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ For business inquiries please use the contact information found on the [GitHub p
1919

2020
## Go Get
2121

22+
### Counter-Strike 2 + Live Broadcast Parsing - aka. CSTV+ (BETA)
23+
24+
go get -u github.com/markus-wa/demoinfocs-golang/v5/pkg/demoinfocs
25+
26+
See [v5 branch with broadcast example](https://github.com/markus-wa/demoinfocs-golang/tree/v5/examples/broadcasts)
27+
2228
### Counter-Strike 2
2329

2430
go get -u github.com/markus-wa/demoinfocs-golang/v5/pkg/demoinfocs
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Player Viewmodel Settings
2+
3+
This example shows how to use the library to extract player viewmodel settings from CS2 demos. Viewmodel settings include the viewmodel offset (X, Y, Z) and field of view.
4+
5+
## Running the example
6+
7+
`go run viewmodel_settings.go -demo /path/to/cs2-demo.dem`
8+
9+
### Sample output
10+
11+
```
12+
Player viewmodels:
13+
degster: Viewmodel Offset=(2.5, 0.0, -1.5), FOV=60.0
14+
kyxsan: Viewmodel Offset=(1.0, 1.0, -1.0), FOV=60.0
15+
NiKo: Viewmodel Offset=(-1.0, 1.5, -2.0), FOV=60.0
16+
SOMEBODY: Viewmodel Offset=(2.5, 2.0, -2.0), FOV=60.0
17+
Summer: Viewmodel Offset=(2.5, 0.0, -1.5), FOV=60.0
18+
L1haNg: Viewmodel Offset=(2.5, 0.0, -1.5), FOV=60.0
19+
ChildKing: Viewmodel Offset=(2.5, 1.0, -1.5), FOV=60.0
20+
TeSeS: Viewmodel Offset=(2.5, 0.0, -1.5), FOV=60.0
21+
Magisk: Viewmodel Offset=(2.5, 0.0, -1.5), FOV=60.0
22+
kaze: Viewmodel Offset=(2.5, 0.0, -1.5), FOV=60.0
23+
```
24+
25+
Note: Viewmodel settings are only available in CS2 demos. CS:GO demos will show zero values.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
ex "github.com/markus-wa/demoinfocs-golang/v4/examples"
8+
demoinfocs "github.com/markus-wa/demoinfocs-golang/v4/pkg/demoinfocs"
9+
events "github.com/markus-wa/demoinfocs-golang/v4/pkg/demoinfocs/events"
10+
)
11+
12+
// Run like this: go run viewmodel_settings.go -demo /path/to/cs2-demo.dem
13+
func main() {
14+
f, err := os.Open(ex.DemoPathFromArgs())
15+
if err != nil {
16+
panic(err)
17+
}
18+
19+
defer f.Close()
20+
21+
p := demoinfocs.NewParser(f)
22+
defer p.Close()
23+
24+
// Register handler on round start to collect viewmodel settings
25+
p.RegisterEventHandler(func(e events.RoundStart) {
26+
fmt.Println("Player viewmodels:")
27+
gs := p.GameState()
28+
29+
// Get all connected players
30+
players := gs.Participants().Playing()
31+
32+
for _, player := range players {
33+
if player == nil {
34+
continue
35+
}
36+
37+
// Get viewmodel settings
38+
offset := player.ViewmodelOffset()
39+
fov := player.ViewmodelFOV()
40+
41+
fmt.Printf("%s: Viewmodel Offset=(%.1f, %.1f, %.1f), FOV=%.1f\n",
42+
player.Name, offset.X, offset.Y, offset.Z, fov)
43+
}
44+
fmt.Println() // Empty line for readability
45+
})
46+
47+
// Parse to end
48+
err = p.ParseToEnd()
49+
if err != nil {
50+
panic(err)
51+
}
52+
}

pkg/demoinfocs/common/equipment.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ func initEqNameToWeapon() {
164164
eqNameToWeapon["hkp2000"] = EqP2000
165165
eqNameToWeapon["incgrenade"] = EqIncendiary
166166
eqNameToWeapon["incendiarygrenade"] = EqIncendiary
167+
eqNameToWeapon["inferno"] = EqIncendiary
167168
eqNameToWeapon["m249"] = EqM249
168169
eqNameToWeapon["m4a1"] = EqM4A4
169170
eqNameToWeapon["mac10"] = EqMac10

pkg/demoinfocs/common/player.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,40 @@ func (p *Player) CrosshairCode() string {
449449
return getString(p.Entity, "m_szCrosshairCodes")
450450
}
451451

452+
// ViewmodelOffset returns the player's viewmodel offset as a 3D vector (X, Y, Z).
453+
// Returns zero vector if not available (CS:GO demos or player not alive).
454+
func (p *Player) ViewmodelOffset() r3.Vector {
455+
if !p.demoInfoProvider.IsSource2() {
456+
return r3.Vector{}
457+
}
458+
459+
pawn := p.PlayerPawnEntity()
460+
if pawn == nil {
461+
return r3.Vector{}
462+
}
463+
464+
return r3.Vector{
465+
X: float64(getFloat(pawn, "m_flViewmodelOffsetX")),
466+
Y: float64(getFloat(pawn, "m_flViewmodelOffsetY")),
467+
Z: float64(getFloat(pawn, "m_flViewmodelOffsetZ")),
468+
}
469+
}
470+
471+
// ViewmodelFOV returns the player's viewmodel field of view.
472+
// Returns 0 if not available (CS:GO demos or player not alive).
473+
func (p *Player) ViewmodelFOV() float32 {
474+
if !p.demoInfoProvider.IsSource2() {
475+
return 0
476+
}
477+
478+
pawn := p.PlayerPawnEntity()
479+
if pawn == nil {
480+
return 0
481+
}
482+
483+
return getFloat(pawn, "m_flViewmodelFOV")
484+
}
485+
452486
// Ping returns the players latency to the game server.
453487
func (p *Player) Ping() int {
454488
return int(getUInt64(p.Entity, "m_iPing"))

0 commit comments

Comments
 (0)