@@ -262,10 +262,29 @@ static void Main(string[] args)
262262 oxrFile . Write ( _client . Version ) ;
263263 }
264264
265+ _client . Connection . OnReceivedServerCreatureDataPacket += ( packet ) =>
266+ {
267+ var p = ( CreatureData ) packet ;
268+ if ( p . Creature != null )
269+ {
270+ if ( _extractMonsterData && p . Creature . Type == OXGaming . TibiaAPI . Constants . CreatureType . Monster && ! _knownMonsterIds . Contains ( p . Creature . Id ) )
271+ {
272+ _monsterFile . WriteLine ( $ "{ p . Creature . Name } { p . Creature . Position } ") ;
273+ _knownMonsterIds . Add ( p . Creature . Id ) ;
274+ }
275+ else if ( _extractNpcData && p . Creature . Type == OXGaming . TibiaAPI . Constants . CreatureType . Npc && ! _knownNpcIds . Contains ( p . Creature . Id ) )
276+ {
277+ _npcFile . WriteLine ( $ "{ p . Creature . Name } { p . Creature . Position } ") ;
278+ _knownNpcIds . Add ( p . Creature . Id ) ;
279+ }
280+ }
281+ return true ;
282+ } ;
283+
265284 _client . Connection . OnReceivedServerChangeOnMapPacket += ( packet ) =>
266285 {
267286 var p = ( ChangeOnMap ) packet ;
268- if ( _extractItemData && p . ObjectInstance != null )
287+ if ( _extractItemData && p . ObjectInstance != null && p . Id > ( int ) CreatureInstanceType . Creature )
269288 {
270289 _itemFile . WriteLine ( $ "{ p . ObjectInstance . Id } { p . Position . ToString ( ) } ") ;
271290 }
@@ -288,7 +307,7 @@ static void Main(string[] args)
288307 _client . Connection . OnReceivedServerCreateOnMapPacket += ( packet ) =>
289308 {
290309 var p = ( CreateOnMap ) packet ;
291- if ( _extractItemData && p . ObjectInstance != null )
310+ if ( _extractItemData && p . ObjectInstance != null && p . Id > ( int ) CreatureInstanceType . Creature )
292311 {
293312 _itemFile . WriteLine ( $ "{ p . ObjectInstance . Id } { p . Position . ToString ( ) } ") ;
294313 }
@@ -340,42 +359,47 @@ static void Main(string[] args)
340359 _otbmFile = InitializeMapFile ( otbmName , outputPath ) ;
341360 }
342361
343- foreach ( var field in p . Fields )
362+ foreach ( var ( _ , _ , position ) in p . Fields )
344363 {
345364 if ( _extractMapData )
346365 {
347- ParseField ( field ) ;
366+ ParseField ( position ) ;
348367 }
349368
350- for ( var i = 0 ; i < MapSizeW ; ++ i )
369+ var mapPosition = _client . WorldMapStorage . ToMap ( position ) ;
370+ var field = _client . WorldMapStorage . GetField ( mapPosition . X , mapPosition . Y , mapPosition . Z ) ;
371+ if ( field != null )
351372 {
352- var obj = field . Item1 . GetObject ( i ) ;
353- if ( obj == null )
354- {
355- continue ;
356- }
357-
358- if ( _extractItemData && obj . Id > ( int ) CreatureInstanceType . Creature )
359- {
360- _itemFile . WriteLine ( $ "{ obj . Id } { field . Item2 . ToString ( ) } ") ;
361- }
362- else if ( obj . Id <= ( int ) CreatureInstanceType . Creature )
373+ for ( var i = 0 ; i < MapSizeW ; ++ i )
363374 {
364- var creature = _client . CreatureStorage . GetCreature ( obj . Data ) ;
365- if ( creature == null )
375+ var obj = field . GetObject ( i ) ;
376+ if ( obj == null )
366377 {
367378 continue ;
368379 }
369380
370- if ( _extractMonsterData && creature . Type == OXGaming . TibiaAPI . Constants . CreatureType . Monster && ! _knownMonsterIds . Contains ( creature . Id ) )
381+ if ( _extractItemData && obj . Id > ( int ) CreatureInstanceType . Creature )
371382 {
372- _monsterFile . WriteLine ( $ "{ creature . Name } { creature . Position } ") ;
373- _knownMonsterIds . Add ( creature . Id ) ;
383+ _itemFile . WriteLine ( $ "{ obj . Id } { position . ToString ( ) } ") ;
374384 }
375- else if ( _extractNpcData && creature . Type == OXGaming . TibiaAPI . Constants . CreatureType . Npc && ! _knownNpcIds . Contains ( creature . Id ) )
385+ else if ( obj . Id <= ( int ) CreatureInstanceType . Creature )
376386 {
377- _npcFile . WriteLine ( $ "{ creature . Name } { creature . Position } ") ;
378- _knownNpcIds . Add ( creature . Id ) ;
387+ var creature = _client . CreatureStorage . GetCreature ( obj . Data ) ;
388+ if ( creature == null )
389+ {
390+ continue ;
391+ }
392+
393+ if ( _extractMonsterData && creature . Type == OXGaming . TibiaAPI . Constants . CreatureType . Monster && ! _knownMonsterIds . Contains ( creature . Id ) )
394+ {
395+ _monsterFile . WriteLine ( $ "{ creature . Name } { creature . Position } ") ;
396+ _knownMonsterIds . Add ( creature . Id ) ;
397+ }
398+ else if ( _extractNpcData && creature . Type == OXGaming . TibiaAPI . Constants . CreatureType . Npc && ! _knownNpcIds . Contains ( creature . Id ) )
399+ {
400+ _npcFile . WriteLine ( $ "{ creature . Name } { creature . Position } ") ;
401+ _knownNpcIds . Add ( creature . Id ) ;
402+ }
379403 }
380404 }
381405 }
@@ -505,42 +529,46 @@ static void Main(string[] args)
505529 static bool Proxy_OnReceivedMapPacket ( Packet packet )
506530 {
507531 var p = ( Map ) packet ;
508- foreach ( var field in p . Fields )
532+ foreach ( var ( _ , _ , position ) in p . Fields )
509533 {
510534 if ( _extractMapData )
511535 {
512- ParseField ( field ) ;
536+ ParseField ( position ) ;
513537 }
514538
515- for ( var i = 0 ; i < MapSizeW ; ++ i )
539+ var field = _client . WorldMapStorage . GetField ( position . X , position . Y , position . Z ) ;
540+ if ( field != null )
516541 {
517- var obj = field . Item1 . GetObject ( i ) ;
518- if ( obj == null )
519- {
520- continue ;
521- }
522-
523- if ( _extractItemData && obj . Id > ( int ) CreatureInstanceType . Creature )
524- {
525- _itemFile . WriteLine ( $ "{ obj . Id } { field . Item2 . ToString ( ) } ") ;
526- }
527- else if ( obj . Id <= ( int ) CreatureInstanceType . Creature )
542+ for ( var i = 0 ; i < MapSizeW ; ++ i )
528543 {
529- var creature = _client . CreatureStorage . GetCreature ( obj . Data ) ;
530- if ( creature == null )
544+ var obj = field . GetObject ( i ) ;
545+ if ( obj == null )
531546 {
532547 continue ;
533548 }
534549
535- if ( _extractMonsterData && creature . Type == OXGaming . TibiaAPI . Constants . CreatureType . Monster && ! _knownMonsterIds . Contains ( creature . Id ) )
550+ if ( _extractItemData && obj . Id > ( int ) CreatureInstanceType . Creature )
536551 {
537- _monsterFile . WriteLine ( $ "{ creature . Name } { creature . Position } ") ;
538- _knownMonsterIds . Add ( creature . Id ) ;
552+ _itemFile . WriteLine ( $ "{ obj . Id } { position . ToString ( ) } ") ;
539553 }
540- else if ( _extractNpcData && creature . Type == OXGaming . TibiaAPI . Constants . CreatureType . Npc && ! _knownNpcIds . Contains ( creature . Id ) )
554+ else if ( obj . Id <= ( int ) CreatureInstanceType . Creature )
541555 {
542- _npcFile . WriteLine ( $ "{ creature . Name } { creature . Position } ") ;
543- _knownNpcIds . Add ( creature . Id ) ;
556+ var creature = _client . CreatureStorage . GetCreature ( obj . Data ) ;
557+ if ( creature == null )
558+ {
559+ continue ;
560+ }
561+
562+ if ( _extractMonsterData && creature . Type == OXGaming . TibiaAPI . Constants . CreatureType . Monster && ! _knownMonsterIds . Contains ( creature . Id ) )
563+ {
564+ _monsterFile . WriteLine ( $ "{ creature . Name } { creature . Position } ") ;
565+ _knownMonsterIds . Add ( creature . Id ) ;
566+ }
567+ else if ( _extractNpcData && creature . Type == OXGaming . TibiaAPI . Constants . CreatureType . Npc && ! _knownNpcIds . Contains ( creature . Id ) )
568+ {
569+ _npcFile . WriteLine ( $ "{ creature . Name } { creature . Position } ") ;
570+ _knownNpcIds . Add ( creature . Id ) ;
571+ }
544572 }
545573 }
546574 }
@@ -647,10 +675,8 @@ static void WriteData(FileStream file, byte[] data)
647675 }
648676 }
649677
650- static void ParseField ( ( Field , Position ) field )
678+ static void ParseField ( Position position )
651679 {
652- var position = field . Item2 ;
653-
654680 var index = ( ulong ) ( ( position . Z * 40959 * 40959 ) + ( position . Y * 40959 ) + position . X ) ;
655681 if ( _knownPositions . Contains ( index ) )
656682 {
@@ -676,46 +702,51 @@ static void ParseField((Field, Position) field)
676702 WriteData ( _otbmFile , new byte [ ] { ( byte ) ( position . X & 0xFF ) } ) ;
677703 WriteData ( _otbmFile , new byte [ ] { ( byte ) ( position . Y & 0xFF ) } ) ;
678704
679- for ( int i = 0 ; i < 10 ; ++ i )
705+ var mapPosition = _client . WorldMapStorage . ToMap ( position ) ;
706+ var field = _client . WorldMapStorage . GetField ( mapPosition . X , mapPosition . Y , mapPosition . Z ) ;
707+ if ( field != null )
680708 {
681- var item = field . Item1 . GetObject ( i ) ;
682- if ( item == null || item . Id == 97 || item . Id == 98 || item . Id == 99 || _ignoreIds . Contains ( item . Id ) )
709+ for ( int i = 0 ; i < MapSizeW ; ++ i )
683710 {
684- continue ;
685- }
711+ var item = field . GetObject ( i ) ;
712+ if ( item == null || item . Id == 97 || item . Id == 98 || item . Id == 99 || _ignoreIds . Contains ( item . Id ) )
713+ {
714+ continue ;
715+ }
686716
687- // node item
688- _otbmFile . WriteByte ( 254 ) ;
689- _otbmFile . WriteByte ( 6 ) ;
717+ // node item
718+ _otbmFile . WriteByte ( 254 ) ;
719+ _otbmFile . WriteByte ( 6 ) ;
690720
691- // item id
692- if ( ! _replaceIds . TryGetValue ( item . Id , out uint id ) )
693- {
694- id = item . Id ;
695- }
696- WriteData ( _otbmFile , BitConverter . GetBytes ( ( ushort ) id ) ) ;
721+ // item id
722+ if ( ! _replaceIds . TryGetValue ( item . Id , out uint id ) )
723+ {
724+ id = item . Id ;
725+ }
726+ WriteData ( _otbmFile , BitConverter . GetBytes ( ( ushort ) id ) ) ;
697727
698- // item data
699- if ( item . Type != null && item . Type . Flags . Cumulative )
700- {
701- _otbmFile . WriteByte ( 15 ) ;
702- WriteData ( _otbmFile , new byte [ ] { ( byte ) item . Data } ) ;
703- }
728+ // item data
729+ if ( item . Type != null && item . Type . Flags . Cumulative )
730+ {
731+ _otbmFile . WriteByte ( 15 ) ;
732+ WriteData ( _otbmFile , new byte [ ] { ( byte ) item . Data } ) ;
733+ }
704734
705- // item sub type
706- if ( item . Type != null && ( item . Type . Flags . Liquidcontainer || item . Type . Flags . Liquidpool ) )
707- {
708- _otbmFile . WriteByte ( 15 ) ;
709- byte subType = 0 ;
710- if ( Enum . IsDefined ( typeof ( FluidType ) , ( int ) item . Data ) )
735+ // item sub type
736+ if ( item . Type != null && ( item . Type . Flags . Liquidcontainer || item . Type . Flags . Liquidpool ) )
711737 {
712- subType = ( byte ) item . Data ;
738+ _otbmFile . WriteByte ( 15 ) ;
739+ byte subType = 0 ;
740+ if ( Enum . IsDefined ( typeof ( FluidType ) , ( int ) item . Data ) )
741+ {
742+ subType = ( byte ) item . Data ;
743+ }
744+ WriteData ( _otbmFile , new byte [ ] { subType } ) ;
713745 }
714- WriteData ( _otbmFile , new byte [ ] { subType } ) ;
715- }
716746
717- //end item node
718- _otbmFile . WriteByte ( 255 ) ;
747+ //end item node
748+ _otbmFile . WriteByte ( 255 ) ;
749+ }
719750 }
720751
721752 // end tile node
0 commit comments