33using System ;
44using System . Collections . Generic ;
55using System . IO ;
6+ using System . Linq ;
67using System . Text ;
78
89namespace Atlasd . Battlenet . Protocols . Game . Messages
@@ -51,17 +52,10 @@ public override bool Invoke(MessageContext context)
5152
5253 var productId = ( UInt32 ) gameState . Product ;
5354
54- // Statstring length is either 0 bytes or 4- 128 bytes, not including the null-terminator.
55- if ( statstring . Length != 0 && ( statstring . Length < 4 || statstring . Length > 128 ) )
55+ // Statstring has a maximum length of 128 bytes
56+ if ( statstring . Length > 128 )
5657 throw new GameProtocolViolationException ( context . Client , $ "Client sent invalid statstring size in { MessageName ( Id ) } ") ;
5758
58- if ( statstring . Length < 4 ) statstring = new byte [ 4 ] ;
59-
60- using var _m = new MemoryStream ( statstring ) ;
61- using var _w = new BinaryWriter ( _m ) ;
62- _w . BaseStream . Position = 0 ;
63- _w . Write ( productId ) ; // ensure first 4 bytes of statstring always matches their agreed upon productId
64-
6559 return new SID_ENTERCHAT ( ) . Invoke ( new MessageContext ( context . Client , MessageDirection . ServerToClient ,
6660 new Dictionary < string , dynamic > ( ) { { "username" , username } , { "statstring" , statstring } } )
6761 ) ;
@@ -72,9 +66,14 @@ public override bool Invoke(MessageContext context)
7266 var statstring = context . Arguments . ContainsKey ( "statstring" ) ? ( byte [ ] ) context . Arguments [ "statstring" ] : gameState . Statstring ;
7367 var accountName = gameState . Username ;
7468
69+ if ( Product . IsDiabloII ( gameState . Product ) )
70+ {
71+ statstring = Product . ToByteArray ( gameState . Product ) ;
72+ }
73+
7574 // Do not use client-provided statstring if config.battlenet.emulation.statstring_updates is not enabled for this product.
7675 // Blizzard servers allowed statstring updates for Diablo, Diablo II (changing characters), Warcraft III (changing icons), and Shareware variants.
77- if ( ! GameState . CanStatstringUpdate ( gameState . Product ) ) statstring = gameState . GenerateStatstring ( ) ;
76+ if ( ! GameState . CanStatstringUpdate ( gameState . Product ) || statstring . Length == 0 ) statstring = gameState . GenerateStatstring ( ) ;
7877
7978 /**
8079 * (STRING) Unique name
0 commit comments