Skip to content

Commit 7e299ca

Browse files
committed
fix: CBombTarget is not available with old CS2 beta demos
1 parent 1b38783 commit 7e299ca

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

pkg/demoinfocs/datatables.go

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -308,23 +308,36 @@ func (p *parser) bindBombSites() {
308308
playerResource.BindProperty("m_bombsiteCenterB", &p.bombsiteB.center, st.ValTypeVector)
309309
})
310310

311-
if p.isSource2() {
312-
p.stParser.ServerClasses().FindByName("CBombTarget").OnEntityCreated(func(target st.Entity) {
313-
t := new(boundingBoxInformation)
314-
p.triggers[target.ID()] = t
311+
onBombTargetEntityCreated := func(target st.Entity) {
312+
t := new(boundingBoxInformation)
313+
p.triggers[target.ID()] = t
314+
315+
var (
316+
minPropName string
317+
maxPropName string
318+
)
319+
if p.isSource2() {
320+
minPropName = "m_vecMins"
321+
maxPropName = "m_vecMaxs"
322+
} else {
323+
minPropName = "m_Collision.m_vecMins"
324+
maxPropName = "m_Collision.m_vecMaxs"
325+
}
315326

316-
target.BindProperty("m_vecMins", &t.min, st.ValTypeVector)
317-
target.BindProperty("m_vecMaxs", &t.max, st.ValTypeVector)
318-
})
319-
} else {
320-
p.stParser.ServerClasses().FindByName("CBaseTrigger").OnEntityCreated(func(baseTrigger st.Entity) {
321-
t := new(boundingBoxInformation)
322-
p.triggers[baseTrigger.ID()] = t
327+
target.BindProperty(minPropName, &t.min, st.ValTypeVector)
328+
target.BindProperty(maxPropName, &t.max, st.ValTypeVector)
329+
}
323330

324-
baseTrigger.BindProperty("m_Collision.m_vecMins", &t.min, st.ValTypeVector)
325-
baseTrigger.BindProperty("m_Collision.m_vecMaxs", &t.max, st.ValTypeVector)
326-
})
331+
if p.isSource2() {
332+
// CBombTarget is not available with CS2 demos created in the early days of the limited test.
333+
bombTargetClass := p.stParser.ServerClasses().FindByName("CBombTarget")
334+
if bombTargetClass != nil {
335+
bombTargetClass.OnEntityCreated(onBombTargetEntityCreated)
336+
return
337+
}
327338
}
339+
340+
p.stParser.ServerClasses().FindByName("CBaseTrigger").OnEntityCreated(onBombTargetEntityCreated)
328341
}
329342

330343
func (p *parser) bindPlayers() {

0 commit comments

Comments
 (0)