Skip to content

Commit 27d74d4

Browse files
committed
small s2 fixes
1 parent afe697a commit 27d74d4

File tree

4 files changed

+38
-18
lines changed

4 files changed

+38
-18
lines changed

pkg/demoinfocs/common/player.go

+6
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,12 @@ func (p *Player) Health() int {
274274

275275
// Armor returns the player's armor points, normally 0-100.
276276
func (p *Player) Armor() int {
277+
s2Prop := p.Entity.Property("m_iPawnArmor")
278+
279+
if s2Prop != nil {
280+
return s2Prop.Value().Int()
281+
}
282+
277283
return getInt(p.Entity, "m_ArmorValue")
278284
}
279285

pkg/demoinfocs/demoinfocs_test.go

+29-18
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ const (
3131
testDataPath = "../../test"
3232
csDemosPath = testDataPath + "/cs-demos"
3333
demSetPath = csDemosPath + "/set"
34+
demSetPathS2 = csDemosPath + "/s2"
3435
defaultDemPath = csDemosPath + "/default.dem"
3536
retakeDemPath = csDemosPath + "/retake_unknwon_bombsite_index.dem"
3637
unexpectedEndOfDemoPath = csDemosPath + "/unexpected_end_of_demo.dem"
37-
s2DemPath = csDemosPath + "/s2.dem"
38+
s2DemPath = demSetPathS2 + "/s2.dem"
3839
)
3940

4041
var concurrentDemos = flag.Int("concurrentdemos", 2, "The `number` of current demos")
@@ -217,10 +218,6 @@ func TestS2(t *testing.T) {
217218
_, err = p.ParseHeader()
218219
assertions.NoError(err, "error returned by Parser.ParseHeader()")
219220

220-
p.RegisterEventHandler(func(e any) {
221-
fmt.Printf("%#v\n", e)
222-
})
223-
224221
t.Log("Parsing to end")
225222
err = p.ParseToEnd()
226223
assertions.NoError(err, "error occurred in ParseToEnd()")
@@ -488,26 +485,20 @@ func runConcurrently(runner func()) {
488485
wg.Wait()
489486
}
490487

491-
func TestDemoSet(t *testing.T) {
492-
t.Parallel()
493-
494-
if testing.Short() {
495-
t.Skip("skipping test due to -short flag")
496-
}
497-
498-
dems, err := ioutil.ReadDir(demSetPath)
499-
assert.NoError(t, err, "failed to list directory %q", demSetPath)
488+
func testDemoSet(t *testing.T, path string) {
489+
dems, err := os.ReadDir(path)
490+
assert.NoError(t, err, "failed to list directory %q", path)
500491

501492
for _, d := range dems {
502493
name := d.Name()
503494
if strings.HasSuffix(name, ".dem") {
504-
t.Logf("Parsing '%s/%s'\n", demSetPath, name)
495+
t.Logf("Parsing '%s/%s'\n", path, name)
505496
func() {
506-
f := openFile(t, fmt.Sprintf("%s/%s", demSetPath, name))
497+
f := openFile(t, fmt.Sprintf("%s/%s", path, name))
507498
defer mustClose(t, f)
508499

509500
defer func() {
510-
assert.Nil(t, recover(), "parsing of '%s/%s' panicked", demSetPath, name)
501+
assert.Nil(t, recover(), "parsing of '%s/%s' panicked", path, name)
511502
}()
512503

513504
p := demoinfocs.NewParser(f)
@@ -538,12 +529,32 @@ func TestDemoSet(t *testing.T) {
538529
})
539530

540531
err = p.ParseToEnd()
541-
assert.Nil(t, err, "parsing of '%s/%s' failed", demSetPath, name)
532+
assert.NoError(t, err, "parsing of '%s/%s' failed", demSetPath, name)
542533
}()
543534
}
544535
}
545536
}
546537

538+
func TestDemoSet(t *testing.T) {
539+
if testing.Short() {
540+
t.Skip("skipping test due to -short flag")
541+
}
542+
543+
t.Parallel()
544+
545+
testDemoSet(t, demSetPath)
546+
}
547+
548+
func TestDemoSetS2(t *testing.T) {
549+
if testing.Short() {
550+
t.Skip("skipping test due to -short flag")
551+
}
552+
553+
t.Parallel()
554+
555+
testDemoSet(t, demSetPathS2)
556+
}
557+
547558
func BenchmarkDemoInfoCs(b *testing.B) {
548559
for i := 0; i < b.N; i++ {
549560
parseDefaultDemo(b)

pkg/demoinfocs/game_events.go

+1
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ func newGameEventHandler(parser *parser, ignoreBombsiteIndexNotFound bool) gameE
226226
"player_given_c4": nil, // Dunno, only present in locally recorded (POV) demos
227227
"player_ping": nil, // When a player uses the "ping system" added with the operation Broken Fang, only present in locally recorded (POV) demos
228228
"player_ping_stop": nil, // When a player's ping expired, only present in locally recorded (POV) demos
229+
"player_sound": nil, // When a player makes a sound. TODO: implement player_sound
229230

230231
// Player changed team. Delayed for two reasons
231232
// - team IDs of other players changing teams in the same tick might not have changed yet

pkg/demoinfocs/stringtables.go

+2
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,8 @@ func (p *parser) processModelPreCacheUpdate() {
538538
// XXX TODO: decide if we want to at all integrate these updates,
539539
// or trust create/update entirely. Let's ignore them for now.
540540
func (p *parser) handleStringTables(msg *msgs2.CDemoStringTables) {
541+
p.msgDispatcher.SyncAllQueues()
542+
541543
for _, tab := range msg.GetTables() {
542544
if tab.GetTableName() == stNameInstanceBaseline {
543545
for _, item := range tab.GetItems() {

0 commit comments

Comments
 (0)