Skip to content

Commit 09c8137

Browse files
committed
CS2 POV crash fixes
1 parent 5f3b9e7 commit 09c8137

File tree

3 files changed

+71
-31
lines changed

3 files changed

+71
-31
lines changed

pkg/demoinfocs/datatables.go

+50-15
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,30 @@ func (p *parser) bindBomb() {
164164

165165
if p.isSource2() {
166166
ownerProp := bombEntity.PropertyValueMust("m_hOwnerEntity")
167-
planter := p.gameState.Participants().FindByPawnHandle(ownerProp.Handle())
168-
if planter == nil {
169-
return
167+
168+
var planter *common.Player
169+
170+
if ownerProp.Any != nil {
171+
planter = p.gameState.Participants().FindByPawnHandle(ownerProp.Handle())
172+
173+
if planter != nil {
174+
planter.IsPlanting = false
175+
}
170176
}
177+
171178
isTicking := true
172-
planter.IsPlanting = false
173179

174-
siteNumber := bombEntity.PropertyValueMust("m_nBombSite").Int()
180+
siteNumberVal := bombEntity.PropertyValueMust("m_nBombSite")
181+
175182
site := events.BomsiteUnknown
176-
if siteNumber == 0 {
177-
site = events.BombsiteA
178-
} else if siteNumber == 1 {
179-
site = events.BombsiteB
183+
184+
if siteNumberVal.Any != nil {
185+
siteNumber := siteNumberVal.Int()
186+
if siteNumber == 0 {
187+
site = events.BombsiteA
188+
} else if siteNumber == 1 {
189+
site = events.BombsiteB
190+
}
180191
}
181192

182193
if !p.disableMimicSource1GameEvents {
@@ -190,6 +201,10 @@ func (p *parser) bindBomb() {
190201

191202
// Set to true when the bomb has been planted and to false when it has been defused or has exploded.
192203
bombEntity.Property("m_bBombTicking").OnUpdate(func(val st.PropertyValue) {
204+
if val.Any == nil {
205+
return
206+
}
207+
193208
isTicking = val.BoolVal()
194209
if isTicking {
195210
return
@@ -214,31 +229,51 @@ func (p *parser) bindBomb() {
214229

215230
// Updated when a player starts/stops defusing the bomb
216231
bombEntity.Property("m_hBombDefuser").OnUpdate(func(val st.PropertyValue) {
232+
if val.Any == nil {
233+
return
234+
}
235+
217236
isValidPlayer := val.Handle() != constants.InvalidEntityHandleSource2
218237
if isValidPlayer {
219238
defuser := p.gameState.Participants().FindByPawnHandle(val.Handle())
220239
p.gameState.currentDefuser = defuser
240+
hasKit := false
241+
242+
// defuser may be nil for POV demos
243+
if defuser != nil {
244+
hasKit = defuser.HasDefuseKit()
245+
}
246+
221247
if !p.disableMimicSource1GameEvents {
222248
p.eventDispatcher.Dispatch(events.BombDefuseStart{
223249
Player: defuser,
224-
HasKit: defuser.HasDefuseKit(),
250+
HasKit: hasKit,
225251
})
226252
}
253+
227254
return
228255
}
229256

230-
isDefused := bombEntity.PropertyValueMust("m_bBombDefused").BoolVal()
231-
if !isDefused && p.gameState.currentDefuser != nil {
232-
p.eventDispatcher.Dispatch(events.BombDefuseAborted{
233-
Player: p.gameState.currentDefuser,
234-
})
257+
isDefusedVal := bombEntity.PropertyValueMust("m_bBombDefused")
258+
259+
if isDefusedVal.Any != nil {
260+
isDefused := isDefusedVal.BoolVal()
261+
if !isDefused && p.gameState.currentDefuser != nil {
262+
p.eventDispatcher.Dispatch(events.BombDefuseAborted{
263+
Player: p.gameState.currentDefuser,
264+
})
265+
}
235266
}
236267

237268
p.gameState.currentDefuser = nil
238269
})
239270

240271
// Updated when the bomb has been planted and defused.
241272
bombEntity.Property("m_bBombDefused").OnUpdate(func(val st.PropertyValue) {
273+
if val.Any == nil {
274+
return
275+
}
276+
242277
isDefused := val.BoolVal()
243278
if isDefused && !p.disableMimicSource1GameEvents {
244279
defuser := p.gameState.Participants().FindByPawnHandle(bombEntity.PropertyValueMust("m_hBombDefuser").Handle())

pkg/demoinfocs/game_events.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -492,12 +492,13 @@ func (geh gameEventHandler) playerHurt(data map[string]*msg.CSVCMsg_GameEventKey
492492
armorDamageTaken = 100
493493
}
494494

495-
if player != nil {
496-
if health == 0 {
495+
if player != nil && (!geh.parser.isSource2() || (player.PlayerPawnEntity() != nil)) {
496+
// m_iHealth & m_ArmorValue check for CS2 POV demos
497+
if health == 0 && (!geh.parser.isSource2() || player.PlayerPawnEntity().Property("m_iHealth") != nil) {
497498
healthDamageTaken = player.Health()
498499
}
499500

500-
if armor == 0 {
501+
if armor == 0 && (!geh.parser.isSource2() || player.PlayerPawnEntity().Property("m_ArmorValue") != nil) {
501502
armorDamageTaken = player.Armor()
502503
}
503504
}

pkg/demoinfocs/sendtables2/entity.go

+17-13
Original file line numberDiff line numberDiff line change
@@ -204,19 +204,23 @@ func coordFromCell(cell uint64, offset float32) float64 {
204204
}
205205

206206
func (e *Entity) Position() r3.Vector {
207-
cellXProp := e.Property(propCellX)
208-
cellYProp := e.Property(propCellY)
209-
cellZProp := e.Property(propCellZ)
210-
offsetXProp := e.Property(propVecX)
211-
offsetYProp := e.Property(propVecY)
212-
offsetZProp := e.Property(propVecZ)
213-
214-
cellX := cellXProp.Value().S2UInt64()
215-
cellY := cellYProp.Value().S2UInt64()
216-
cellZ := cellZProp.Value().S2UInt64()
217-
offsetX := offsetXProp.Value().Float()
218-
offsetY := offsetYProp.Value().Float()
219-
offsetZ := offsetZProp.Value().Float()
207+
cellXVal := e.Property(propCellX).Value()
208+
cellYVal := e.Property(propCellY).Value()
209+
cellZVal := e.Property(propCellZ).Value()
210+
offsetXVal := e.Property(propVecX).Value()
211+
offsetYVal := e.Property(propVecY).Value()
212+
offsetZVal := e.Property(propVecZ).Value()
213+
214+
if cellXVal.Any == nil || cellYVal.Any == nil || cellZVal.Any == nil || offsetXVal.Any == nil || offsetYVal.Any == nil || offsetZVal.Any == nil {
215+
return r3.Vector{} // CS2 POV demos
216+
}
217+
218+
cellX := cellXVal.S2UInt64()
219+
cellY := cellYVal.S2UInt64()
220+
cellZ := cellZVal.S2UInt64()
221+
offsetX := offsetXVal.Float()
222+
offsetY := offsetYVal.Float()
223+
offsetZ := offsetZVal.Float()
220224

221225
return r3.Vector{
222226
X: coordFromCell(cellX, offsetX),

0 commit comments

Comments
 (0)