private static void RegisterExtended(int packetId, int length, OnPacketReceive onReceive)
 {
     _extendedHandlers[packetId] = new PacketHandler(packetId, length, onReceive);
 }
        private static bool OnMobileIncoming(byte[] packet, int length)
        {
            PacketReader reader = new PacketReader(packet, length, false);

            int            serial    = reader.ReadInt32();
            ItemCollection container = new ItemCollection(serial);

            Mobile mobile = serial == Engine.Player?.Serial ? Engine.Player : Engine.GetOrCreateMobile(serial);

            mobile.ID        = reader.ReadInt16();
            mobile.X         = reader.ReadInt16();
            mobile.Y         = reader.ReadInt16();
            mobile.Z         = reader.ReadSByte();
            mobile.Direction = (Direction)(reader.ReadByte() & 0x07);
            mobile.Hue       = reader.ReadUInt16();
            mobile.Status    = (MobileStatus)reader.ReadByte();
            mobile.Notoriety = (Notoriety)reader.ReadByte();

            bool useNewIncoming = Engine.ClientVersion == null || Engine.ClientVersion >= new Version(7, 0, 33, 1);

            for ( ;;)
            {
                int itemSerial = reader.ReadInt32();

                if (itemSerial == 0)
                {
                    break;
                }

                Item item = Engine.GetOrCreateItem(itemSerial);
                item.Owner = serial;
                item.ID    = reader.ReadUInt16();
                item.Layer = (Layer)reader.ReadByte();

                if (useNewIncoming)
                {
                    item.Hue = reader.ReadUInt16();
                }
                else
                {
                    if ((item.ID & 0x8000) != 0)
                    {
                        item.ID ^= 0x8000;
                        item.Hue = reader.ReadUInt16();
                    }
                }

                container.Add(item);
            }

            mobile.Equipment.Clear();
            mobile.Equipment.Add(container.GetItems());

            foreach (Item item in container.GetItems())
            {
                mobile.SetLayer(item.Layer, item.Serial);
            }

            if (!Engine.RehueList.CheckMobileIncoming(mobile, container))
            {
                return(false);
            }

            // Will need to send to handler ourselves because we won't see packet again
            reader.Seek(3, SeekOrigin.Begin);
            PacketHandler handler = IncomingPacketHandlers.GetHandler(0x78);

            handler?.OnReceive(reader);
            return(true);
        }