Skip to content

Commit a34aa7c

Browse files
committed
full support for POV demos (PVF fix)
this fixes some of the PVF (potentially-visible-field) behaviour and by doing so adds full POV demo support to the lib
1 parent 2f08f35 commit a34aa7c

File tree

4 files changed

+31
-28
lines changed

4 files changed

+31
-28
lines changed

examples/print-events/print_events.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func main() {
3535
if e.PenetratedObjects > 0 {
3636
wallBang = " (WB)"
3737
}
38-
fmt.Printf("%s <%v%s%s> %s\n", formatPlayer(e.Killer), e.Weapon.Type, hs, wallBang, formatPlayer(e.Victim))
38+
fmt.Printf("%s <%v%s%s> %s\n", formatPlayer(e.Killer), e.Weapon, hs, wallBang, formatPlayer(e.Victim))
3939
})
4040

4141
// Register handler on round end to figure out who won
@@ -78,6 +78,7 @@ func formatPlayer(p *common.Player) string {
7878
case common.TeamCounterTerrorists:
7979
return "[CT]" + p.Name
8080
}
81+
8182
return p.Name
8283
}
8384

pkg/demoinfocs/datatables.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,8 @@ func (p *parser) bindWeapon(entity st.Entity, wepType common.EquipmentType) {
477477
if strings.Contains(eq.OriginalString, altName) {
478478
eq.Type = alt
479479
} else if !strings.Contains(eq.OriginalString, defaultName) {
480-
p.setError(fmt.Errorf("unknown weapon model %q", eq.OriginalString))
480+
// happens with POV demos, not sure why (model pre-cache not working right?)
481+
//p.setError(fmt.Errorf("unknown weapon model %q", eq.OriginalString))
481482
}
482483
}
483484

pkg/demoinfocs/game_events.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,11 @@ func (geh gameEventHandler) bombPlanted(data map[string]*msg.CSVCMsg_GameEventKe
523523
}
524524

525525
event := events.BombPlanted{BombEvent: bombEvent}
526-
event.Player.IsPlanting = false
526+
527+
if event.Player != nil { // if not nil check is necessary for POV demos
528+
event.Player.IsPlanting = false
529+
}
530+
527531
geh.parser.gameState.currentPlanter = nil
528532
geh.dispatch(event)
529533
}

pkg/demoinfocs/net_messages.go

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
msg "github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs/msg"
99
)
1010

11-
const entitySentinel = 9999
12-
1311
func (p *parser) handlePacketEntities(pe *msg.CSVCMsg_PacketEntities) {
1412
defer func() {
1513
p.setError(recoverFromUnexpectedEOF(recover()))
@@ -21,31 +19,30 @@ func (p *parser) handlePacketEntities(pe *msg.CSVCMsg_PacketEntities) {
2119
for i := 0; i < int(pe.UpdatedEntries); i++ {
2220
currentEntity += 1 + int(r.ReadUBitInt())
2321

24-
if currentEntity > entitySentinel {
25-
break
26-
}
27-
28-
if r.ReadBit() {
29-
// Leave PVS
30-
if entity := p.gameState.entities[currentEntity]; entity != nil {
31-
entity.Destroy()
32-
delete(p.gameState.entities, currentEntity)
33-
}
22+
cmd := r.ReadBitsToByte(2)
23+
if cmd&1 == 0 {
24+
if cmd&2 != 0 {
25+
// Enter PVS
26+
if existing := p.gameState.entities[currentEntity]; existing != nil {
27+
// Sometimes entities don't get destroyed when they should be
28+
// For instance when a player is replaced by a BOT
29+
existing.Destroy()
30+
}
3431

35-
// 'Force Delete' flag, not exactly sure what it's supposed to do
36-
r.ReadBit()
37-
} else if r.ReadBit() {
38-
// Enter PVS
39-
if existing := p.gameState.entities[currentEntity]; existing != nil {
40-
// Sometimes entities don't get destroyed when they should be
41-
// For instance when a player is replaced by a BOT
42-
existing.Destroy()
32+
p.gameState.entities[currentEntity] = p.stParser.ReadEnterPVS(r, currentEntity)
33+
} else { //nolint:gocritic
34+
// Delta Update
35+
if entity := p.gameState.entities[currentEntity]; entity != nil {
36+
entity.ApplyUpdate(r)
37+
}
4338
}
44-
p.gameState.entities[currentEntity] = p.stParser.ReadEnterPVS(r, currentEntity)
45-
} else { //nolint:gocritic
46-
// Delta Update
47-
if entity := p.gameState.entities[currentEntity]; entity != nil {
48-
entity.ApplyUpdate(r)
39+
} else {
40+
if cmd&2 != 0 {
41+
// Leave PVS
42+
if entity := p.gameState.entities[currentEntity]; entity != nil {
43+
entity.Destroy()
44+
delete(p.gameState.entities, currentEntity)
45+
}
4946
}
5047
}
5148
}

0 commit comments

Comments
 (0)