@@ -292,6 +292,39 @@ var defaultNetMessageCreators = map[int]NetMessageCreator{
292292 int (msg .SVC_Messages_svc_UserMessage ): func () proto.Message { return new (msg.CSVCMsg_UserMessage ) },
293293 int (msg .SVC_Messages_svc_ServerInfo ): func () proto.Message { return new (msg.CSVCMsg_ServerInfo ) },
294294 int (msg .NET_Messages_net_SetConVar ): func () proto.Message { return new (msg.CNETMsg_SetConVar ) },
295+ int (msg .SVC_Messages_svc_EncryptedData ): func () proto.Message { return new (msg.CSVCMsg_EncryptedData ) },
296+ }
297+
298+ func (p * parser ) netMessageForCmd (cmd int ) proto.Message {
299+ msgCreator := defaultNetMessageCreators [cmd ]
300+
301+ if msgCreator != nil {
302+ return msgCreator ()
303+ }
304+
305+ var msgName string
306+ if cmd < 8 || cmd >= 100 {
307+ msgName = msg .NET_Messages_name [int32 (cmd )]
308+ } else {
309+ msgName = msg .SVC_Messages_name [int32 (cmd )]
310+ }
311+
312+ if msgName == "" {
313+ // Send a warning if the command is unknown
314+ // This might mean our proto files are out of date
315+ p .eventDispatcher .Dispatch (events.ParserWarn {Message : fmt .Sprintf ("unknown message command %q" , cmd )})
316+ unassert .Error ("unknown message command %q" , cmd )
317+ }
318+
319+ // Handle additional net-messages as defined by the user
320+ msgCreator = p .additionalNetMessageCreators [cmd ]
321+ if msgCreator != nil {
322+ return msgCreator ()
323+ }
324+
325+ debugUnhandledMessage (cmd , msgName )
326+
327+ return nil
295328}
296329
297330//nolint:funlen
@@ -311,41 +344,19 @@ func (p *parser) parsePacket() {
311344
312345 p .bitReader .BeginChunk (size << 3 )
313346
314- msgCreator := defaultNetMessageCreators [cmd ]
315-
316- if msgCreator == nil {
317- var msgName string
318- if cmd < 8 || cmd >= 100 {
319- msgName = msg .NET_Messages_name [int32 (cmd )]
320- } else {
321- msgName = msg .SVC_Messages_name [int32 (cmd )]
322- }
323-
324- if msgName == "" {
325- // Send a warning if the command is unknown
326- // This might mean our proto files are out of date
327- p .eventDispatcher .Dispatch (events.ParserWarn {Message : fmt .Sprintf ("unknown message command %q" , cmd )})
328- unassert .Error ("unknown message command %q" , cmd )
329- }
330-
331- // Handle additional net-messages as defined by the user
332- msgCreator = p .additionalNetMessageCreators [cmd ]
333- if msgCreator == nil {
334- debugUnhandledMessage (cmd , msgName )
335-
336- // On to the next one
337- p .bitReader .EndChunk ()
338-
339- continue
340- }
347+ m := p .netMessageForCmd (cmd )
348+
349+ if m == nil {
350+ // On to the next one
351+ p .bitReader .EndChunk ()
352+
353+ continue
341354 }
342355
343356 b := byteSlicePool .Get ().(* []byte )
344357
345358 p .bitReader .ReadBytesInto (b , size )
346359
347- m := msgCreator ()
348-
349360 err := proto .Unmarshal (* b , m )
350361 if err != nil {
351362 // TODO: Don't crash here, happens with demos that work in gotv
0 commit comments