diff --git a/pkg/demoinfocs/sendtables2/entity.go b/pkg/demoinfocs/sendtables2/entity.go index 2d000d18..ac2c6dcb 100644 --- a/pkg/demoinfocs/sendtables2/entity.go +++ b/pkg/demoinfocs/sendtables2/entity.go @@ -126,7 +126,7 @@ func (p property) Bind(variable any, t st.PropertyValueType) { } func (e *Entity) Property(name string) st.Property { - ok := e.class.serializer.getFieldPathForName(newFieldPath(), name) + ok := e.class.serializer.checkFieldName(name) if !ok { return nil } diff --git a/pkg/demoinfocs/sendtables2/parser.go b/pkg/demoinfocs/sendtables2/parser.go index f636ba95..ad819cff 100644 --- a/pkg/demoinfocs/sendtables2/parser.go +++ b/pkg/demoinfocs/sendtables2/parser.go @@ -161,11 +161,10 @@ func (p *Parser) ParsePacket(b []byte) error { fieldTypes := map[string]*fieldType{} for _, s := range msg.GetSerializers() { - serializer := &serializer{ - name: msg.GetSymbols()[s.GetSerializerNameSym()], - version: s.GetSerializerVersion(), - fields: []*field{}, - } + serializer := newSerializer( + msg.GetSymbols()[s.GetSerializerNameSym()], + s.GetSerializerVersion(), + ) for _, i := range s.GetFieldsIndex() { if _, ok := fields[i]; !ok { diff --git a/pkg/demoinfocs/sendtables2/serializer.go b/pkg/demoinfocs/sendtables2/serializer.go index 2f4abf22..801805be 100644 --- a/pkg/demoinfocs/sendtables2/serializer.go +++ b/pkg/demoinfocs/sendtables2/serializer.go @@ -11,10 +11,21 @@ type fieldIndex struct { } type serializer struct { - name string - version int32 - fields []*field - fieldIndexes map[string]*fieldIndex + name string + version int32 + fields []*field + fieldIndexes map[string]*fieldIndex + fieldNameChecks map[string]bool +} + +func newSerializer(name string, version int32) *serializer { + return &serializer{ + name: name, + version: version, + fields: []*field{}, + fieldIndexes: make(map[string]*fieldIndex), + fieldNameChecks: make(map[string]bool), + } } func (s *serializer) id() string { @@ -78,12 +89,18 @@ func (s *serializer) addField(f *field) { newFieldIndex := len(s.fields) s.fields = append(s.fields, f) - if s.fieldIndexes == nil { - s.fieldIndexes = make(map[string]*fieldIndex) - } - s.fieldIndexes[f.varName] = &fieldIndex{ index: newFieldIndex, field: f, } } + +func (s *serializer) checkFieldName(name string) bool { + ok, exists := s.fieldNameChecks[name] + if !exists { + ok = s.getFieldPathForName(newFieldPath(), name) + s.fieldNameChecks[name] = ok + } + + return ok +}