Skip to content

Commit d3c8779

Browse files
committed
fix & simplify a bunch of s2 code
1 parent cfd9e52 commit d3c8779

File tree

13 files changed

+132
-217
lines changed

13 files changed

+132
-217
lines changed

pkg/demoinfocs/game_events.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -578,12 +578,14 @@ func (geh gameEventHandler) HostageRescuedAll(map[string]*msg.CSVCMsg_GameEventK
578578

579579
func (geh gameEventHandler) playerConnect(data map[string]*msg.CSVCMsg_GameEventKeyT) {
580580
pl := common.PlayerInfo{
581-
UserID: int(data["userid"].GetValShort()),
582-
Name: data["name"].GetValString(),
583-
GUID: data["networkid"].GetValString(),
581+
UserID: int(data["userid"].GetValShort()),
582+
Name: data["name"].GetValString(),
583+
GUID: data["networkid"].GetValString(),
584+
XUID: data["xuid"].GetValUint64(),
585+
IsFakePlayer: data["bot"].GetValBool(),
584586
}
585587

586-
if pl.GUID != "" {
588+
if pl.GUID != "" && pl.XUID == 0 {
587589
var err error
588590
pl.XUID, err = guidToSteamID64(pl.GUID)
589591

pkg/demoinfocs/parsing.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,7 @@ func (p *parser) parseFrameS2() bool {
370370

371371
p.msgQueue <- ingameTickNumber(int32(tick))
372372

373-
if msgType == msgs2.EDemoCommands_DEM_Stop {
374-
return false
375-
}
376-
377-
return true
373+
return msgType != msgs2.EDemoCommands_DEM_Stop
378374
}
379375

380376
// FIXME: refactor to interface instead of switch

pkg/demoinfocs/s2_commands.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ func (m *pendingMessage) priority() int {
279279
// provide context in terms of delta updates.
280280
int32(msgs2.SVC_Messages_svc_PacketEntities):
281281
return 5
282-
283282
}
284283

285284
return 0

pkg/demoinfocs/sendtables/st_parser.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,18 @@ type SendTableParser struct {
2626
instanceBaselines map[int][]byte // Maps server-class IDs to raw instance baselines, needed for when we don't have the server-class when setting the baseline
2727
}
2828

29-
func (p *SendTableParser) OnDemoClassInfo(m *msgs2.CDemoClassInfo) error {
30-
//TODO implement me
31-
panic("implement me")
29+
// the following funcs are S2 only
30+
31+
func (p *SendTableParser) OnDemoClassInfo(*msgs2.CDemoClassInfo) error {
32+
panic("not implemented")
3233
}
3334

34-
func (p *SendTableParser) OnServerInfo(m *msgs2.CSVCMsg_ServerInfo) error {
35-
//TODO implement me
36-
panic("implement me")
35+
func (p *SendTableParser) OnServerInfo(*msgs2.CSVCMsg_ServerInfo) error {
36+
panic("not implemented")
3737
}
3838

39-
func (p *SendTableParser) OnPacketEntities(m *msgs2.CSVCMsg_PacketEntities) error {
40-
//TODO implement me
41-
panic("implement me")
39+
func (p *SendTableParser) OnPacketEntities(*msgs2.CSVCMsg_PacketEntities) error {
40+
panic("not implemented")
4241
}
4342

4443
// ServerClasses is a searchable list of ServerClasses.
@@ -132,10 +131,11 @@ func (p *SendTableParser) ParsePacket(b []byte) error {
132131
}
133132

134133
func parseSendTable(r *bit.BitReader) sendTable {
134+
var st msg.CSVCMsg_SendTable
135+
135136
size := int(r.ReadVarInt32())
136137

137-
st := new(msg.CSVCMsg_SendTable)
138-
err := proto.Unmarshal(r.ReadBytes(size), st)
138+
err := proto.Unmarshal(r.ReadBytes(size), &st)
139139
if err != nil {
140140
panic(fmt.Sprintf("Failed to unmarshal SendTable: %s", err.Error()))
141141
}

pkg/demoinfocs/sendtables2/class.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package sendtables2
22

33
import (
4-
"regexp"
54
"strings"
65
)
76

8-
var gameBuildRegexp = regexp.MustCompile(`/dota_v(\d+)/`)
9-
107
type class struct {
118
classId int32
129
name string

pkg/demoinfocs/sendtables2/entity.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,14 @@ func (p *Parser) FilterEntity(fb func(*Entity) bool) []*Entity {
217217
func (p *Parser) OnPacketEntities(m *msgs2.CSVCMsg_PacketEntities) error {
218218
r := newReader(m.GetEntityData())
219219

220-
var index = int32(-1)
221-
var updates = int(m.GetUpdatedEntries())
222-
var cmd uint32
223-
var classId int32
224-
var serial int32
225-
var e *Entity
226-
var op EntityOp
220+
var (
221+
index = int32(-1)
222+
updates = int(m.GetUpdatedEntries())
223+
cmd uint32
224+
classId int32
225+
serial int32
226+
e *Entity
227+
)
227228

228229
if !m.GetIsDelta() {
229230
if p.entityFullPackets > 0 {
@@ -240,9 +241,10 @@ func (p *Parser) OnPacketEntities(m *msgs2.CSVCMsg_PacketEntities) error {
240241

241242
for ; updates > 0; updates-- {
242243
next := index + int32(r.readUBitVar()) + 1
243-
op = EntityOpNone
244244
index = next
245245

246+
var op EntityOp
247+
246248
cmd = r.readBits(2)
247249
if cmd&0x01 == 0 {
248250
if cmd&0x02 != 0 {

pkg/demoinfocs/sendtables2/field_decoder.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var fieldTypeDecoders = map[string]fieldDecoder{
4444
DemoSimpleEncoders_t { m_Name = "float32" m_VarType = "NET_DATA_TYPE_FLOAT32" },
4545
DemoSimpleEncoders_t { m_Name = "float64" m_VarType = "NET_DATA_TYPE_FLOAT64" },
4646
*/
47-
//"float32": noscaleDecoder,
47+
// "float32": noscaleDecoder,
4848

4949
/*
5050
DemoSimpleEncoders_t { m_Name = "bool" m_VarType = "NET_DATA_TYPE_BOOL" },
@@ -227,10 +227,6 @@ var fieldTypeDecoders = map[string]fieldDecoder{
227227
"CRenderComponent": componentDecoder,
228228
}
229229

230-
func unsignedFactory(f *field) fieldDecoder {
231-
return unsignedDecoder
232-
}
233-
234230
func unsigned64Factory(f *field) fieldDecoder {
235231
switch f.encoder {
236232
case "fixed64":
@@ -365,10 +361,6 @@ func qangleFactory(f *field) fieldDecoder {
365361
}
366362
}
367363

368-
func vector2Decoder(r *reader) interface{} {
369-
return []float32{r.readFloat(), r.readFloat()}
370-
}
371-
372364
func unsignedDecoder(r *reader) interface{} {
373365
return uint64(r.readVarUint32())
374366
}

pkg/demoinfocs/sendtables2/field_patch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var fieldPatches = []fieldPatch{
1414
DemoSimpleEncoders_t { m_Name = "m_flAnimTime" m_VarType = "NET_DATA_TYPE_UINT64" },
1515
]
1616
*/
17-
fieldPatch{0, 0, func(f *field) {
17+
{0, 0, func(f *field) {
1818
switch f.varName {
1919
case "m_flSimulationTime", "m_flAnimTime":
2020
f.encoder = "simtime"

0 commit comments

Comments
 (0)