@@ -44,6 +44,8 @@ public class NetworkMessage
4444
4545 private readonly byte [ ] _buffer = new byte [ MaxMessageSize ] ;
4646
47+ private Client _client ;
48+
4749 private uint _size = PayloadDataPosition ;
4850
4951 /// <value>
@@ -89,8 +91,9 @@ public bool IsCompressed
8991 }
9092 }
9193
92- public NetworkMessage ( )
94+ public NetworkMessage ( Client client )
9395 {
96+ _client = client ?? throw new ArgumentNullException ( nameof ( client ) ) ;
9497 SequenceNumber = ~ CompressedFlag ;
9598 }
9699
@@ -271,13 +274,13 @@ public Position ReadPosition(int x = -1, int y = -1, int z = -1)
271274 return new Position ( x , y , z ) ;
272275 }
273276
274- public AppearanceInstance ReadMountOutfit ( Client client )
277+ public AppearanceInstance ReadMountOutfit ( )
275278 {
276279 var mountId = ReadUInt16 ( ) ;
277- return client . AppearanceStorage . CreateOutfitInstance ( mountId , 0 , 0 , 0 , 0 , 0 ) ;
280+ return _client . AppearanceStorage . CreateOutfitInstance ( mountId , 0 , 0 , 0 , 0 , 0 ) ;
278281 }
279282
280- public AppearanceInstance ReadCreatureOutfit ( Client client )
283+ public AppearanceInstance ReadCreatureOutfit ( )
281284 {
282285 var outfitId = ReadUInt16 ( ) ;
283286 if ( outfitId != 0 )
@@ -287,18 +290,19 @@ public AppearanceInstance ReadCreatureOutfit(Client client)
287290 var colorLegs = ReadByte ( ) ;
288291 var colorDetail = ReadByte ( ) ;
289292 var addons = ReadByte ( ) ;
290- return client . AppearanceStorage . CreateOutfitInstance ( outfitId , colorHead , colorTorso , colorLegs , colorDetail , addons ) ;
293+ return
294+ _client . AppearanceStorage . CreateOutfitInstance ( outfitId , colorHead , colorTorso , colorLegs , colorDetail , addons ) ;
291295 }
292296
293297 var itemId = ReadUInt16 ( ) ;
294298 if ( itemId == 0 )
295299 {
296- return client . AppearanceStorage . CreateOutfitInstance ( 0 , 0 , 0 , 0 , 0 , 0 ) ;
300+ return _client . AppearanceStorage . CreateOutfitInstance ( 0 , 0 , 0 , 0 , 0 , 0 ) ;
297301 }
298- return client . AppearanceStorage . CreateObjectInstance ( itemId , 0 ) ;
302+ return _client . AppearanceStorage . CreateObjectInstance ( itemId , 0 ) ;
299303 }
300304
301- public ObjectInstance ReadObjectInstance ( Client client , ushort id = 0 )
305+ public ObjectInstance ReadObjectInstance ( ushort id = 0 )
302306 {
303307 if ( id == 0 )
304308 {
@@ -315,7 +319,7 @@ public ObjectInstance ReadObjectInstance(Client client, ushort id = 0)
315319 throw new Exception ( $ "[NetworkMessage.ReadObjectInstance] Invalid object id: { id } ") ;
316320 }
317321
318- var objectInstance = client . AppearanceStorage . CreateObjectInstance ( id , 0 ) ;
322+ var objectInstance = _client . AppearanceStorage . CreateObjectInstance ( id , 0 ) ;
319323 if ( objectInstance == null )
320324 {
321325 throw new Exception ( $ "[NetworkMessage.ReadObjectInstance] Invalid object id: { id } ") ;
@@ -327,6 +331,11 @@ public ObjectInstance ReadObjectInstance(Client client, ushort id = 0)
327331 return objectInstance ;
328332 }
329333
334+ if ( _client . VersionNumber < 19000000 )
335+ {
336+ ReadByte ( ) ; // mark
337+ }
338+
330339 if ( objectType . Flags . Liquidcontainer || objectType . Flags . Liquidpool || objectType . Flags . Cumulative )
331340 {
332341 objectInstance . Data = ReadByte ( ) ;
@@ -349,7 +358,7 @@ public ObjectInstance ReadObjectInstance(Client client, ushort id = 0)
349358 return objectInstance ;
350359 }
351360
352- public Creature ReadCreatureInstance ( Client client , int id = - 1 , Position position = null )
361+ public Creature ReadCreatureInstance ( int id = - 1 , Position position = null )
353362 {
354363 if ( id == - 1 )
355364 {
@@ -372,7 +381,7 @@ public Creature ReadCreatureInstance(Client client, int id = -1, Position positi
372381 var removeCreatureId = ReadUInt32 ( ) ;
373382 var creatureId = ReadUInt32 ( ) ;
374383
375- //creature = (creatureId == client .Player.Id) ? client .Player : new Creature(creatureId);
384+ //creature = (creatureId == _client .Player.Id) ? _client .Player : new Creature(creatureId);
376385 creature = new Creature ( creatureId )
377386 {
378387 Type = ( CreatureType ) ReadByte ( ) ,
@@ -387,8 +396,8 @@ public Creature ReadCreatureInstance(Client client, int id = -1, Position positi
387396 creature . Name = ReadString ( ) ;
388397 creature . HealthPercent = ReadByte ( ) ;
389398 creature . Direction = ( Direction ) ReadByte ( ) ;
390- creature . Outfit = ReadCreatureOutfit ( client ) ;
391- creature . Mount = ReadMountOutfit ( client ) ;
399+ creature . Outfit = ReadCreatureOutfit ( ) ;
400+ creature . Mount = ReadMountOutfit ( ) ;
392401 creature . Brightness = ReadByte ( ) ;
393402 creature . LightColor = ReadByte ( ) ;
394403 creature . Speed = ReadUInt16 ( ) ;
@@ -417,8 +426,8 @@ public Creature ReadCreatureInstance(Client client, int id = -1, Position positi
417426 Direction = ( Direction ) ReadByte ( )
418427 } ;
419428
420- creature . Outfit = ReadCreatureOutfit ( client ) ;
421- creature . Mount = ReadMountOutfit ( client ) ;
429+ creature . Outfit = ReadCreatureOutfit ( ) ;
430+ creature . Mount = ReadMountOutfit ( ) ;
422431 creature . Brightness = ReadByte ( ) ;
423432 creature . LightColor = ReadByte ( ) ;
424433 creature . Speed = ReadUInt16 ( ) ;
@@ -569,12 +578,12 @@ public void ReadDailyReward()
569578 }
570579 }
571580
572- public int ReadField ( Client client , int x , int y , int z , List < ( Field , Position ) > fields )
581+ public int ReadField ( int x , int y , int z , List < ( Field , Position ) > fields )
573582 {
574583 var thingsCount = 0 ;
575584 var numberOfTilesToSkip = 0 ;
576585 var mapPosition = new Position ( x , y , z ) ;
577- var absolutePosition = client . WorldMapStorage . ToAbsolute ( mapPosition ) ;
586+ var absolutePosition = _client . WorldMapStorage . ToAbsolute ( mapPosition ) ;
578587
579588 while ( true )
580589 {
@@ -589,21 +598,21 @@ public int ReadField(Client client, int x, int y, int z, List<(Field, Position)>
589598 thingId == ( int ) CreatureInstanceType . OutdatedCreature ||
590599 thingId == ( int ) CreatureInstanceType . Creature )
591600 {
592- var creature = ReadCreatureInstance ( client , thingId , absolutePosition ) ;
593- var objectInstance = client . AppearanceStorage . CreateObjectInstance ( 99 , creature . Id ) ;
601+ var creature = ReadCreatureInstance ( thingId , absolutePosition ) ;
602+ var objectInstance = _client . AppearanceStorage . CreateObjectInstance ( 99 , creature . Id ) ;
594603
595604 if ( thingsCount < MapSizeW )
596605 {
597- client . WorldMapStorage . AppendObject ( x , y , z , objectInstance ) ;
606+ _client . WorldMapStorage . AppendObject ( x , y , z , objectInstance ) ;
598607 }
599608 }
600609 else
601610 {
602- var objectInstance = ReadObjectInstance ( client , thingId ) ;
611+ var objectInstance = ReadObjectInstance ( thingId ) ;
603612
604613 if ( thingsCount < MapSizeW )
605614 {
606- client . WorldMapStorage . AppendObject ( x , y , z , objectInstance ) ;
615+ _client . WorldMapStorage . AppendObject ( x , y , z , objectInstance ) ;
607616 }
608617 else
609618 {
@@ -614,7 +623,7 @@ public int ReadField(Client client, int x, int y, int z, List<(Field, Position)>
614623 thingsCount ++ ;
615624 }
616625
617- var field = client . WorldMapStorage . GetField ( x , y , z ) ;
626+ var field = _client . WorldMapStorage . GetField ( x , y , z ) ;
618627 if ( field != null )
619628 {
620629 fields . Add ( ( field , absolutePosition ) ) ;
@@ -623,7 +632,7 @@ public int ReadField(Client client, int x, int y, int z, List<(Field, Position)>
623632 return numberOfTilesToSkip ;
624633 }
625634
626- public int ReadFloor ( Client client , int floorNumber , int numberOfTilesToSkip , List < ( Field , Position ) > fields )
635+ public int ReadFloor ( int floorNumber , int numberOfTilesToSkip , List < ( Field , Position ) > fields )
627636 {
628637 if ( floorNumber < 0 || floorNumber >= MapSizeZ )
629638 {
@@ -643,7 +652,7 @@ public int ReadFloor(Client client, int floorNumber, int numberOfTilesToSkip, Li
643652 }
644653 else
645654 {
646- numberOfTilesToSkip = ReadField ( client , currentX , currentY , floorNumber , fields ) ;
655+ numberOfTilesToSkip = ReadField ( currentX , currentY , floorNumber , fields ) ;
647656 }
648657 currentY ++ ;
649658 }
@@ -653,15 +662,15 @@ public int ReadFloor(Client client, int floorNumber, int numberOfTilesToSkip, Li
653662 return numberOfTilesToSkip ;
654663 }
655664
656- public int ReadArea ( Client client , int startX , int startY , int endX , int endY , List < ( Field , Position ) > fields )
665+ public int ReadArea ( int startX , int startY , int endX , int endY , List < ( Field , Position ) > fields )
657666 {
658667 var endZ = 0 ;
659668 var stepZ = 0 ;
660669 var numberOfTilesToSkip = 0 ;
661670 var currentX = 0 ;
662671 var currentY = 0 ;
663672 var currentZ = 0 ;
664- var position = client . WorldMapStorage . GetPosition ( ) ;
673+ var position = _client . WorldMapStorage . GetPosition ( ) ;
665674
666675 if ( position . Z <= GroundLayer )
667676 {
@@ -690,7 +699,7 @@ public int ReadArea(Client client, int startX, int startY, int endX, int endY, L
690699 }
691700 else
692701 {
693- numberOfTilesToSkip = ReadField ( client , currentX , currentY , currentZ , fields ) ;
702+ numberOfTilesToSkip = ReadField ( currentX , currentY , currentZ , fields ) ;
694703 }
695704 currentY ++ ;
696705 }
0 commit comments