Ejemplo n.º 1
0
        public void WillParseXmfHtmlTokNullArgs()
        {
            const string localPath = @"C:\Users\johns\Desktop\KvG Client 2.0";

            if (!Directory.Exists(localPath))
            {
                Debug.WriteLine("Not running test, requires Cliloc.enu");
                return;
            }

            Cliloc.Initialize(localPath);

            const string base64 =
                "3RK2BJa1nQAPPsgAAAAKAAAACgAAEm0AAG+ceAGtXduuHLcRzKcMkNc8DOe686ZfSRzFESJZgnIMODHy76nizMmS3dWzFBHAlo+l3t4asru62CRHvw/f/vzzx2Ec/vP78P3jPz/9++O3Tz/hf8dhHtdlG/bHOGxj/uPfvvzt729fPr99/ceQRv6zb/jPIxunY34cQ0ppWdM8fPhjSuuyjg96vT72869fvv309fPX78M6TXA+TPCOT2dL/MivPL3gM3/59e3t6y/Zch2HZUw7f4ExjcYx0e/b16+f3z59yw62Yym+igjXbRrw0Wnc8O+QvU/7su/n9wE87Yuv2Sf7NdO8tX0NPqq/Zjs2+zXAaZ5mmvMovX4afFR+zTGvS/6aen6eI1wMbR7s6+Gfs43fwFDBzzkpmB4O78ff3j7+8vb9X58/ffn09vGvQ8KA4kmXibM2Lcc5G9NaDCRjYmHgzPP1Kzzi6+GuAIevgVX5LO/Rg5jBt3wYP6R9/dM4jvy3do8Rrd0zcJx7WGn327KXMwK8CQ9Te5yVR5ppl+ucrMslJ08xBot0CbPA5eJcIpprlKt0CbPAJaKsHsn0sDN1SJcwi1yuxiXtapQYYDE9p79nYhbTj5yrYU6TnZ9EEnBTTrsIp53zCRFocMoopV3k87A4wQLGpwykybBF8eyIB/PsSHnjU077ZKjh6XN7zMbnnNwcyRSinX72DRFR45wRXAbnruaIdpFPG0szaovxyUrj5p122ue6uGd/uDmSMT/DTvlMy7RanMto5wjlRuCkXeTTxvwy2TmaZMzTLvJpY35Z7ByB5hVO2EU+LYUsu52jScY87SKfNo+Ww87RJNmTdoFPREQdn2tycyTziHbKJ3TQYed9BVPV8YnJEONJO+kT5dbG53qN55o9r1ntlC4LCYWKDePMT1Q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svOAAAAaAAAACoAAADueAFjYGUoYShiyGcoY0hlYGQwYOBkMGQwZzAFshCQYbgAAKDDBC0=";

            byte[] packet = Convert.FromBase64String(base64);

            IncomingPacketHandlers.Initialize();
            PacketHandler handler = IncomingPacketHandlers.GetHandler(0xDD);

            try
            {
                handler.OnReceive(new PacketReader(packet, packet.Length, false));
            }
            catch (Exception)
            {
                Assert.Fail();
            }
        }
Ejemplo n.º 2
0
        public void WillAutoAcceptPartyInvite()
        {
            Options.CurrentOptions.AutoAcceptPartyInvite          = true;
            Options.CurrentOptions.AutoAcceptPartyOnlyFromFriends = false;

            AutoResetEvent are = new AutoResetEvent(false);

            void OnPacketSentEvent(byte[] data, int length)
            {
                if (data[0] == 0xBF && data[5] == 0x08)
                {
                    are.Set();
                }
            }

            Engine.InternalPacketSentEvent += OnPacketSentEvent;

            IncomingPacketHandlers.Initialize();

            PacketHandler handler = IncomingPacketHandlers.GetHandler(0xBF);

            byte[] packet = { 0xBF, 0x00, 0x0A, 0x00, 0x06, 0x07, 0x00, 0xaa, 0xbb, 0xcc };

            handler.OnReceive(new PacketReader(packet, packet.Length, false));

            bool result = are.WaitOne(5000);

            Assert.IsTrue(result);

            Engine.InternalPacketSentEvent -= OnPacketSentEvent;
        }
Ejemplo n.º 3
0
        public void WontAutoAcceptPartyInviteNonFriend()
        {
            Options.CurrentOptions.AutoAcceptPartyInvite          = true;
            Options.CurrentOptions.AutoAcceptPartyOnlyFromFriends = true;

            void OnPacketSentEvent(byte[] data, int length)
            {
                if (data[0] == 0xBF && data[5] == 0x08)
                {
                    Assert.Fail();
                }
            }

            Engine.InternalPacketSentEvent += OnPacketSentEvent;

            IncomingPacketHandlers.Initialize();

            PacketHandler handler = IncomingPacketHandlers.GetHandler(0xBF);

            byte[] packet = { 0xBF, 0x00, 0x0A, 0x00, 0x06, 0x07, 0x00, 0xaa, 0xbb, 0xcc };

            handler.OnReceive(new PacketReader(packet, packet.Length, false));

            Engine.InternalPacketSentEvent -= OnPacketSentEvent;
        }
Ejemplo n.º 4
0
        public void WillParseTilepicComma()
        {
            const string localPath = @"C:\Users\johns\Desktop\KvG Client 2.0";

            if (!Directory.Exists(localPath))
            {
                Debug.WriteLine("Not running test, requires Cliloc.enu");
                return;
            }

            Cliloc.Initialize(localPath);

            const string base64 =
                "3QD8BZkjmgAPPvAAAACWAAAAyAAAAMkAAAFCeAFtUEuOwjAM5SiW2M4idpxPd1wFSoCKtomQKyEh7j52ZxYg2Fjyy/s5D2j7cwEHzwecl6m1odfFATuMaGDpL/v5OJZhbosYcFhE6gwpQs5Kc4j/E1WGRNFIUusoQwPE0HEMBt2n00WmUerVtB0BZg8U1jRPKSYlIwf0sNv+yXh1GsZipZCjunfA5Bl/3vqij0DZOjsi0/S32lo5SrkLYNDHlFW/phF3WSOV9HHYS0FP4JFXU7LfcPClYfJBD9v8AsDyVswAAAABAAAAFAAAAAh4AWNgZjBhMGAwAAAB4QCY";

            byte[] packet = Convert.FromBase64String(base64);

            IncomingPacketHandlers.Initialize();
            PacketHandler handler = IncomingPacketHandlers.GetHandler(0xDD);

            try
            {
                handler.OnReceive(new PacketReader(packet, packet.Length, false));
            }
            catch (Exception)
            {
                Assert.Fail();
            }
        }
Ejemplo n.º 5
0
        public void WillMatchSystemRegular()
        {
            const string localPath = @"C:\Users\johns\Desktop\KvG Client 2.0";

            if (!Directory.Exists(localPath))
            {
                Debug.WriteLine("Not running test, requires Cliloc.enu");
                return;
            }

            Cliloc.Initialize(localPath);

            byte[] packet =
            {
                0xC1, 0x00, 0x32, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x03, 0xB2, 0x00, 0x03, 0x00, 0x07,
                0xA4, 0xE1, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00
            };

            IncomingPacketHandlers.Initialize();

            PacketHandler handler = IncomingPacketHandlers.GetHandler(0xc1);

            Assert.IsNotNull(handler);

            handler.OnReceive(new PacketReader(packet, packet.Length, false));

            Assert.IsTrue(JournalCommands.InJournal("fingers slip!", "system"));
        }
Ejemplo n.º 6
0
        public void WillParseOldHealthbarColour()
        {
            AppDomain appDomain = AppDomain.CreateDomain("WillParseOldHealthbarColour",
                                                         AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.SetupInformation);

            appDomain.DoCallBack(() =>
            {
                Engine.ClientVersion = new Version(5, 0, 9, 1);

                byte[] packet =
                {
                    0x17, 0x00, 0x0F, 0x00, 0x07, 0x5D, 0x67, 0x00, 0x02, 0x00, 0x01, 0x01, 0x00, 0x02, 0x00
                };

                IncomingPacketHandlers.Initialize();

                Mobile mobile = new Mobile(0x00075D67);

                Engine.Mobiles.Add(mobile);

                PacketHandler handler = IncomingPacketHandlers.GetHandler(0x17);
                handler?.OnReceive(new PacketReader(packet, packet.Length, false));

                Assert.IsTrue(mobile.IsPoisoned);
            });
        }
Ejemplo n.º 7
0
        public static async Task <bool> WaitForIncomingPacketFilterAsync(PacketFilterInfo pfi, int timeout,
                                                                         bool invokeHandler = true, bool fixedSize = false)
        {
            AutoResetEvent are = new AutoResetEvent(false);

            byte[] packet = null;

            Engine.AddReceiveFilter(new PacketFilterInfo(pfi.PacketID, pfi.GetConditions(), (data, info) =>
            {
                packet = data;
                are.Set();
            }));

            Task filterTask = are.ToTask();

            if (await Task.WhenAny(filterTask, Task.Delay(timeout)) == filterTask)
            {
                if (invokeHandler)
                {
                    PacketHandler handler = IncomingPacketHandlers.GetHandler(packet[0]);

                    handler?.OnReceive(new PacketReader(packet, packet.Length, fixedSize));
                }
            }

            Engine.RemoveReceiveFilter(pfi);

            return(packet != null);
        }
Ejemplo n.º 8
0
        public void WillParseOldContainerContents()
        {
            AppDomain appDomain = AppDomain.CreateDomain("WillParseOldContainerContents",
                                                         AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.SetupInformation);

            appDomain.DoCallBack(() =>
            {
                Engine.ClientVersion = new Version(5, 0, 9, 1);
                byte[] packet        =
                {
                    0x3C, 0x00, 0x2B, 0x00, 0x02, 0x46, 0x13, 0xFF, 0x71, 0x0E, 0x76, 0x00, 0x00, 0x01, 0x00, 0x2C,
                    0x00, 0x7F, 0x46, 0x13, 0xFF, 0x6D, 0x00, 0x00, 0x46, 0x58, 0x64, 0xFB, 0x0E, 0xED, 0x00, 0x03,
                    0xE8, 0x00, 0x4C, 0x00, 0x48, 0x46, 0x13, 0xFF, 0x6D, 0x00, 0x00
                };

                IncomingPacketHandlers.Initialize();
                Engine.Items = new ItemCollection(0);

                PacketHandler handler = IncomingPacketHandlers.GetHandler(0x3C);
                handler?.OnReceive(new PacketReader(packet, packet.Length, false));

                Assert.AreEqual(1, Engine.Items.GetItemCount());
                Assert.IsTrue(Engine.Items.Any(i => i.Serial == 0x4613ff6d));
                Item container = Engine.Items.GetItem(0x4613ff6d);
                Assert.IsNotNull(container);
                Assert.AreEqual(2, container.Container.GetItemCount());
                Engine.Items         = null;
                Engine.ClientVersion = new Version(7, 0, 45, 1);
            });
        }
Ejemplo n.º 9
0
        public void WontRehueNotEnabled()
        {
            Item corpse = new Item(0x40000000)
            {
                ID = 0x2006
            };

            Engine.Items.Add(corpse);

            IncomingPacketHandlers.Initialize();
            AutolootViewModel vm = new AutolootViewModel {
                Enabled = true
            };

            AutolootEntry lootEntry = new AutolootEntry
            {
                Rehue       = true,
                Autoloot    = false,
                Constraints = new ObservableCollection <AutolootConstraintEntry>(),
                ID          = 0x108a,
                Enabled     = true
            };

            vm.Items.Add(lootEntry);
            vm.Enabled = false;

            Engine.PacketWaitEntries = new PacketWaitEntries();

            void OnPacketReceivedEvent(byte[] data, int length)
            {
                Assert.Fail();
            }

            Engine.InternalPacketReceivedEvent += OnPacketReceivedEvent;

            Engine.PacketWaitEntries.WaitEntryAddedEvent += entry =>
            {
                byte[] containerContentsPacket =
                {
                    0x3C, 0x00, 0x19, 0x00, 0x01, 0x43, 0x13, 0xFC, 0x5E, 0x10, 0x8A, 0x00, 0x00, 0x01, 0x00, 0x13,
                    0x00, 0x82, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00
                };

                PacketHandler handler = IncomingPacketHandlers.GetHandler(0x3C);

                handler.OnReceive(new PacketReader(containerContentsPacket, containerContentsPacket.Length, false));
                entry.Packet = containerContentsPacket;
                entry.Lock.Set();
            };

            vm.OnCorpseEvent(corpse.Serial);

            Engine.Items.Clear();
            Engine.PacketWaitEntries = null;

            Engine.InternalPacketReceivedEvent -= OnPacketReceivedEvent;
        }
Ejemplo n.º 10
0
        public void WontSellMoreThanAmount()
        {
            AutoResetEvent are = new AutoResetEvent(false);

            void OnPacket(byte[] data, int length)
            {
                if (data[0] != 0x9F)
                {
                    return;
                }

                int amount = (data[13] << 8) | data[14];

                if (amount != 10)
                {
                    Assert.Fail();
                    return;
                }

                are.Set();
            }

            Engine.InternalPacketSentEvent += OnPacket;

            VendorSellTabViewModel vsvm = new VendorSellTabViewModel();

            vsvm.Items.Add(new VendorSellAgentEntry {
                Enabled = true, Graphic = 0xff, Amount = 10, Name = "Shmoo"
            });

            IncomingPacketHandlers.Initialize();
            PacketHandler handler = IncomingPacketHandlers.GetHandler(0x9E);

            PacketWriter pw = new PacketWriter(23);

            pw.Write((byte)0x9E);
            pw.Write((short)21);
            pw.Write(0);
            pw.Write((short)1);
            pw.Write(0);
            pw.Write((short)0xFF);
            pw.Write((short)0);
            pw.Write((short)100);
            pw.Write((short)9);
            pw.Write((short)0);

            byte[] packet = pw.ToArray();

            handler.OnReceive(new PacketReader(packet, packet.Length, false));

            bool result = are.WaitOne(1000);

            Assert.IsTrue(result);

            vsvm.Items.Clear();
            Engine.InternalPacketSentEvent -= OnPacket;
        }
Ejemplo n.º 11
0
        private static void ProcessIncomingQueue(Packet packet)
        {
            PacketReceivedEvent?.Invoke(packet.GetPacket(), packet.GetLength());

            PacketHandler handler = IncomingPacketHandlers.GetHandler(packet.GetPacketID());

            int length = _getPacketLength(packet.GetPacketID());

            handler?.OnReceive?.Invoke(new PacketReader(packet.GetPacket(), packet.GetLength(), length > 0));

            PacketWaitEntries.CheckWait(packet.GetPacket(), PacketDirection.Incoming);
        }
Ejemplo n.º 12
0
            private static void ServerInstance_IncomingPacketEvent(int clientID, byte[] data)
            {
                int           clientIndex = GetClient(clientID);
                PacketHandler handler     = IncomingPacketHandlers.GetHandler(data[0]);

                if (handler != null)
                {
                    handler.OnReceive(clientIndex, new PacketReader(data, data.Length, handler.Length != 0));
                }

                LowLevel.OnIncomingPacket(clientIndex, data);
            }
Ejemplo n.º 13
0
 private void ExpectAbilityPacket(byte[] data, int length)
 {
     if (data[0] == 0xD7 && data[8] == 0x19)
     {
         if (data[13] == 0x00)
         {
             byte[] packet = { 0xBF, 0x00, 0x05, 0x00, 0x21 };
             IncomingPacketHandlers.Initialize();
             PacketHandler handler = IncomingPacketHandlers.GetHandler(0xBF);
             handler.OnReceive(new PacketReader(packet, packet.Length, false));
         }
         _are.Set();
     }
 }
Ejemplo n.º 14
0
        public void WontThrowExceptionExtended()
        {
            // Shard: The Lost Chapter
            byte[] packet =
            {
                0xbf, 0x00, 0x17, 0xfa, 0xce, 0x80, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc3, 0xf7, 0xff, 0xff,
                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
            };

            IncomingPacketHandlers.Initialize();

            PacketHandler handler = IncomingPacketHandlers.GetHandler(0xBF);

            handler?.OnReceive(new PacketReader(packet, packet.Length, false));
        }
Ejemplo n.º 15
0
        public void WontThrowExceptionEmptyLayout()
        {
            string base64 = "3QAsAHmUqh85QMYAAAEsAAAAyAAAAA0AAAABeJxjAAAAAQABAAAAAAAAAAA=";

            byte[] packet = Convert.FromBase64String(base64);

            IncomingPacketHandlers.Initialize();
            PacketHandler handler = IncomingPacketHandlers.GetHandler(0xDD);

            try
            {
                handler.OnReceive(new PacketReader(packet, packet.Length, false));
            }
            catch (Exception)
            {
                Assert.Fail();
            }
        }
        public void WillSetFrozenOnMobileStatus()
        {
            Engine.Player = new PlayerMobile(0x01);

            Assert.IsFalse(Engine.Player.IsFrozen);

            byte[] packet = { 0x20, 0x00, 0x00, 0x00, 0x01, 0x01, 0x90, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

            PacketHandler handler = IncomingPacketHandlers.GetHandler(0x20);

            Assert.IsNotNull(handler);

            handler.OnReceive(new PacketReader(packet, packet.Length, true));

            Assert.IsTrue(Engine.Player.IsFrozen);

            Engine.Player = null;
        }
Ejemplo n.º 17
0
        public void WontSellIncorrectHue()
        {
            void OnPacket(byte[] data, int length)
            {
                Assert.Fail();
            }

            Engine.InternalPacketSentEvent += OnPacket;

            VendorSellTabViewModel vsvm = new VendorSellTabViewModel();

            vsvm.Items.Add(
                new VendorSellAgentEntry
            {
                Enabled  = true,
                Graphic  = 0xff,
                MinPrice = 10,
                Name     = "Shmoo",
                Hue      = 0xff
            });

            IncomingPacketHandlers.Initialize();
            PacketHandler handler = IncomingPacketHandlers.GetHandler(0x9E);

            PacketWriter pw = new PacketWriter(23);

            pw.Write((byte)0x9E);
            pw.Write((short)21);
            pw.Write(0);
            pw.Write((short)1);
            pw.Write(0);
            pw.Write((short)0xFF);
            pw.Write((short)0);
            pw.Write((short)0);
            pw.Write((short)9);
            pw.Write((short)0);

            byte[] packet = pw.ToArray();

            handler.OnReceive(new PacketReader(packet, packet.Length, false));

            vsvm.Items.Clear();
            Engine.InternalPacketSentEvent -= OnPacket;
        }
        public void WillGetPropertyValue()
        {
            const string localPath = @"C:\Users\johns\Desktop\KvG Client 2.0";

            if (!Directory.Exists(localPath))
            {
                Debug.WriteLine("Not running test, requires Cliloc.enu");
                return;
            }

            Cliloc.Initialize(localPath);

            byte[] packet =
            {
                0xD6, 0x00, 0x43, 0x00, 0x01, 0x40, 0xC5, 0xF6, 0x09, 0x00, 0x00, 0x02, 0xA0, 0x3B, 0xCF, 0x00,
                0x0F, 0x9E, 0xD5, 0x00, 0x00, 0x00, 0x10, 0x5E, 0x95, 0x00, 0x04, 0x37, 0x00, 0x34, 0x00, 0x00,
                0x10, 0x5C, 0x71, 0x00, 0x1A, 0x34, 0x00, 0x39, 0x00, 0x09, 0x00, 0x31, 0x00, 0x32, 0x00, 0x35,
                0x00, 0x09, 0x00, 0x37, 0x00, 0x31, 0x00, 0x09, 0x00, 0x35, 0x00, 0x35, 0x00, 0x30, 0x00, 0x00,
                0x00, 0x00, 0x00
            };

            Item item = new Item(0x40c5f609);

            Engine.Items.Add(item);

            IncomingPacketHandlers.Initialize();

            PacketHandler handler = IncomingPacketHandlers.GetHandler(0xD6);

            handler.OnReceive(new PacketReader(packet, packet.Length, false));

            Assert.IsNotNull(item.Properties);

            int value = PropertiesCommands.PropertyValue <int>(item.Serial, "Contents");

            Assert.AreEqual(49, value);

            value = PropertiesCommands.PropertyValue <int>(item.Serial, "Contents", 2);

            Assert.AreEqual(71, value);

            Engine.Items.Clear();
        }
Ejemplo n.º 19
0
        private static void ProcessIncomingQueue(Packet packet)
        {
            try
            {
                PacketReceivedEvent?.Invoke(packet.GetPacket(), packet.GetLength());

                PacketHandler handler = IncomingPacketHandlers.GetHandler(packet.GetPacketID());

                int length = _getPacketLength(packet.GetPacketID());

                handler?.OnReceive?.Invoke(new PacketReader(packet.GetPacket(), packet.GetLength(), length > 0));

                PacketWaitEntries.CheckWait(packet.GetPacket(), PacketDirection.Incoming);
            }
            catch (Exception e)
            {
                e.ToExceptionless().SetProperty("Packet", packet.GetPacket())
                .SetProperty("Player", Player.ToString()).SetProperty("WorldItemCount", Items.Count())
                .SetProperty("WorldMobileCount", Mobiles.Count()).Submit();
            }
        }
Ejemplo n.º 20
0
        public void WillSetPoisonedFromOldMoving()
        {
            AppDomain appDomain = AppDomain.CreateDomain("WillSetPoisonedFromOldMoving",
                                                         AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.SetupInformation);

            appDomain.DoCallBack(() =>
            {
                Engine.ClientVersion = new Version(5, 0, 9, 1);

                byte[] packet =
                {
                    0x77, 0x00, 0x25, 0x49, 0xbb, 0x01, 0x90, 0x0d, 0xf9, 0x0a, 0x37, 0x00, 0x84, 0x83, 0xea, 0x04,
                    0x01
                };

                IncomingPacketHandlers.Initialize();

                PacketHandler handler = IncomingPacketHandlers.GetHandler(0x77);
                handler?.OnReceive(new PacketReader(packet, packet.Length, true));

                Mobile mobile = Engine.Mobiles.GetMobile(0x2549bb);

                Assert.IsNotNull(mobile);
                Assert.IsTrue(mobile.IsPoisoned);

                byte[] packet2 =
                {
                    0x77, 0x00, 0x06, 0xbc, 0x06, 0x01, 0x90, 0x09, 0xd0, 0x02, 0x2b, 0x00, 0x02, 0x83, 0xea, 0x44,
                    0x01
                };

                handler?.OnReceive(new PacketReader(packet2, packet2.Length, true));

                mobile = Engine.Mobiles.GetMobile(0x6bc06);

                Assert.IsNotNull(mobile);
                Assert.IsTrue(mobile.IsPoisoned);
            });
        }
Ejemplo n.º 21
0
        public void WillSetExpireTime()
        {
            byte[] packet =
            {
                0xDF, 0x00, 0x44, 0x00, 0x00, 0x77, 0x42, 0x04, 0x45, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x04,
                0x45, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x10, 0x2E, 0xF4,
                0x00, 0x11, 0x9B, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x09, 0x31, 0x00,
                0x30, 0x00, 0x09, 0x00, 0x32, 0x00, 0x34, 0x00, 0x09, 0x00, 0x34, 0x00, 0x30, 0x00, 0x00, 0x00,
                0x00, 0x01, 0x00, 0x00
            };

            IncomingPacketHandlers.Initialize();
            PacketHandler handler = IncomingPacketHandlers.GetHandler(0xDF);

            BuffIconManager manager = BuffIconManager.GetInstance();

            handler?.OnReceive(new PacketReader(packet, packet.Length, false));

            double milliseconds = manager.BuffTime("Confidence");

            Assert.IsTrue(milliseconds > 0);
        }
Ejemplo n.º 22
0
        public void ContainerContentsWillAddToPlayerBackpack()
        {
            const int backpackSerial = 0x40000001;
            const int itemSerial     = 0x40000002;

            Item backpack = new Item(backpackSerial, 1)
            {
                Layer = Layer.Backpack
            };

            Engine.Player.SetLayer(Layer.Backpack, backpack.Serial);
            Engine.Items.Add(backpack);

            Assert.IsTrue(Engine.Player.Backpack.Serial > 0);

            ContainerContentsPacket cc =
                new ContainerContentsPacket(new ItemCollection(backpackSerial)
            {
                new Item(itemSerial)
            });

            PacketHandler handler = IncomingPacketHandlers.GetHandler(0x3C);

            Assert.IsNotNull(handler);

            byte[] packet = cc.ToArray();

            handler.OnReceive(new PacketReader(packet, packet.Length, false));

            Item item = Engine.Items.GetItem(backpackSerial);

            Assert.IsNotNull(item.Container);
            Assert.AreEqual(1, item.Container.GetTotalItemCount());
            Assert.IsNotNull(Engine.Items.GetItem(itemSerial));
            Assert.IsNotNull(item.Container.GetItem(itemSerial));

            Engine.Items.Clear();
            Engine.Player.SetLayer(Layer.Backpack, 0);
        }
Ejemplo n.º 23
0
        public void WillSetYellowHitsOnHealthbarColour()
        {
            Engine.Player = new PlayerMobile(0x01);

            byte[] packet = { 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x02, 0x01 };

            PacketHandler handler = IncomingPacketHandlers.GetHandler(0x17);

            Assert.IsNotNull(handler);

            handler.OnReceive(new PacketReader(packet, packet.Length, false));

            Assert.IsTrue(Engine.Player.IsYellowHits);

            packet = new byte[] { 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x02, 0x00 };

            handler.OnReceive(new PacketReader(packet, packet.Length, false));

            Assert.IsFalse(Engine.Player.IsYellowHits);

            Engine.Player = null;
        }
        public void WillEnableDisableSpecialMove()
        {
            SpecialMovesManager manager = SpecialMovesManager.GetInstance();

            byte[] enablePacket  = { 0xBF, 0x00, 0x08, 0x00, 0x25, 0x01, 0xF6, 0x01 };
            byte[] disablePacket = { 0xBF, 0x00, 0x08, 0x00, 0x25, 0x01, 0xF6, 0x00 };

            IncomingPacketHandlers.Initialize();

            PacketHandler handler = IncomingPacketHandlers.GetHandler(0xBF);

            handler?.OnReceive(new PacketReader(enablePacket, enablePacket.Length, false));

            bool result = EntityCommands.SpecialMoveExists("Death Strike");

            Assert.IsTrue(result);

            handler?.OnReceive(new PacketReader(disablePacket, disablePacket.Length, false));

            result = EntityCommands.SpecialMoveExists("Death Strike");

            Assert.IsFalse(result);
        }
Ejemplo n.º 25
0
        public void WillBuyCorrectAmount()
        {
            int vendorSerial = 0x0b0354;

            byte[] shopList =
            {
                0x74, 0x01, 0x67, 0x42, 0x0C, 0x82, 0x83, 0x1B, 0x00, 0x00, 0x00, 0x12, 0x08, 0x31, 0x30, 0x32,
                0x33, 0x38, 0x33, 0x34, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x31, 0x30, 0x32, 0x34, 0x30, 0x33,
                0x31, 0x00, 0x00, 0x00, 0x00, 0x05, 0x08, 0x31, 0x30, 0x32, 0x33, 0x38, 0x32, 0x37, 0x00, 0x00,
                0x00, 0x00, 0x0B, 0x08, 0x31, 0x30, 0x34, 0x31, 0x30, 0x37, 0x32, 0x00, 0x00, 0x00, 0x00, 0x0F,
                0x08, 0x31, 0x30, 0x32, 0x37, 0x39, 0x35, 0x36, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x08, 0x31, 0x30,
                0x32, 0x33, 0x38, 0x35, 0x31, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x08, 0x31, 0x30, 0x32, 0x33, 0x38,
                0x34, 0x38, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x08, 0x31, 0x30, 0x32, 0x33, 0x38, 0x34, 0x36, 0x00,
                0x00, 0x00, 0x00, 0x0F, 0x08, 0x31, 0x30, 0x32, 0x33, 0x38, 0x35, 0x32, 0x00, 0x00, 0x00, 0x00,
                0x0F, 0x08, 0x31, 0x30, 0x32, 0x33, 0x38, 0x34, 0x39, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x08, 0x31,
                0x30, 0x32, 0x33, 0x38, 0x34, 0x37, 0x00, 0x00, 0x00, 0x00, 0x05, 0x08, 0x31, 0x30, 0x32, 0x33,
                0x39, 0x36, 0x32, 0x00, 0x00, 0x00, 0x00, 0x05, 0x08, 0x31, 0x30, 0x32, 0x33, 0x39, 0x36, 0x33,
                0x00, 0x00, 0x00, 0x00, 0x03, 0x08, 0x31, 0x30, 0x32, 0x33, 0x39, 0x37, 0x32, 0x00, 0x00, 0x00,
                0x00, 0x03, 0x08, 0x31, 0x30, 0x32, 0x33, 0x39, 0x37, 0x33, 0x00, 0x00, 0x00, 0x00, 0x03, 0x08,
                0x31, 0x30, 0x32, 0x33, 0x39, 0x37, 0x34, 0x00, 0x00, 0x00, 0x00, 0x03, 0x08, 0x31, 0x30, 0x32,
                0x33, 0x39, 0x37, 0x36, 0x00, 0x00, 0x00, 0x00, 0x03, 0x08, 0x31, 0x30, 0x32, 0x33, 0x39, 0x38,
                0x31, 0x00, 0x00, 0x00, 0x00, 0x03, 0x08, 0x31, 0x30, 0x32, 0x33, 0x39, 0x38, 0x30, 0x00, 0x00,
                0x00, 0x00, 0x0C, 0x08, 0x31, 0x30, 0x32, 0x37, 0x39, 0x38, 0x32, 0x00, 0x00, 0x00, 0x00, 0x0C,
                0x08, 0x31, 0x30, 0x32, 0x37, 0x39, 0x38, 0x33, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x08, 0x31, 0x30,
                0x32, 0x37, 0x39, 0x38, 0x34, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x08, 0x31, 0x30, 0x32, 0x37, 0x39,
                0x38, 0x35, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x08, 0x31, 0x30, 0x32, 0x37, 0x39, 0x38, 0x36, 0x00,
                0x00, 0x00, 0x00, 0x0C, 0x08, 0x31, 0x30, 0x32, 0x37, 0x39, 0x38, 0x37, 0x00, 0x00, 0x00, 0x00,
                0x0C, 0x08, 0x31, 0x30, 0x32, 0x37, 0x39, 0x38, 0x31, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x08, 0x31,
                0x30, 0x32, 0x37, 0x39, 0x38, 0x38, 0x00
            };

            byte[] contents =
            {
                0x3C, 0x02, 0x21, 0x00, 0x1B, 0x40, 0x1F, 0x00, 0x1B, 0x1F, 0x34, 0x00, 0x00, 0x14, 0x00, 0x1B,
                0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1F, 0x00, 0x1A, 0x1F, 0x2D, 0x00,
                0x00, 0x14, 0x00, 0x1A, 0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1F, 0x00,
                0x19, 0x1F, 0x33, 0x00, 0x00, 0x14, 0x00, 0x19, 0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00,
                0x00, 0x40, 0x1F, 0x00, 0x17, 0x1F, 0x32, 0x00, 0x00, 0x14, 0x00, 0x18, 0x00, 0x01, 0x00, 0x42,
                0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1F, 0x00, 0x14, 0x1F, 0x31, 0x00, 0x00, 0x14, 0x00, 0x17,
                0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1F, 0x00, 0x13, 0x1F, 0x30, 0x00,
                0x00, 0x14, 0x00, 0x16, 0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1F, 0x00,
                0x12, 0x1F, 0x2F, 0x00, 0x00, 0x14, 0x00, 0x15, 0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00,
                0x00, 0x40, 0x1F, 0x00, 0x10, 0x1F, 0x2E, 0x00, 0x00, 0x14, 0x00, 0x14, 0x00, 0x01, 0x00, 0x42,
                0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1F, 0x00, 0x0F, 0x0F, 0x8C, 0x00, 0x00, 0x28, 0x00, 0x13,
                0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1F, 0x00, 0x0E, 0x0F, 0x8D, 0x00,
                0x00, 0x28, 0x00, 0x12, 0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1F, 0x00,
                0x0D, 0x0F, 0x88, 0x00, 0x00, 0x28, 0x00, 0x11, 0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00,
                0x00, 0x40, 0x1F, 0x00, 0x0C, 0x0F, 0x86, 0x00, 0x00, 0x14, 0x00, 0x10, 0x00, 0x01, 0x00, 0x42,
                0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1F, 0x00, 0x0A, 0x0F, 0x85, 0x00, 0x00, 0x28, 0x00, 0x0F,
                0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1F, 0x00, 0x09, 0x0F, 0x84, 0x00,
                0x00, 0x28, 0x00, 0x0E, 0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1F, 0x00,
                0x08, 0x0F, 0x7B, 0x00, 0x00, 0x14, 0x00, 0x0D, 0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00,
                0x00, 0x40, 0x1F, 0x00, 0x07, 0x0F, 0x7A, 0x00, 0x00, 0x14, 0x00, 0x0C, 0x00, 0x01, 0x00, 0x42,
                0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1F, 0x00, 0x06, 0x0F, 0x07, 0x00, 0x00, 0x14, 0x00, 0x0B,
                0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1F, 0x00, 0x05, 0x0F, 0x09, 0x00,
                0x00, 0x14, 0x00, 0x0A, 0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1F, 0x00,
                0x04, 0x0F, 0x0C, 0x00, 0x00, 0x14, 0x00, 0x09, 0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00,
                0x00, 0x40, 0x1F, 0x00, 0x02, 0x0F, 0x06, 0x00, 0x00, 0x14, 0x00, 0x08, 0x00, 0x01, 0x00, 0x42,
                0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1F, 0x00, 0x01, 0x0F, 0x08, 0x00, 0x00, 0x14, 0x00, 0x07,
                0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1F, 0x00, 0x00, 0x0F, 0x0B, 0x00,
                0x00, 0x14, 0x00, 0x06, 0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1E, 0xFF,
                0xFF, 0x1F, 0x14, 0x00, 0x00, 0x10, 0x00, 0x05, 0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00,
                0x00, 0x40, 0x1E, 0xFF, 0xFE, 0x17, 0x18, 0x00, 0x00, 0x0A, 0x00, 0x04, 0x00, 0x01, 0x00, 0x42,
                0x0C, 0x82, 0x83, 0x00, 0xE1, 0x40, 0x1E, 0xFF, 0xFD, 0x0E, 0xF3, 0x00, 0x00, 0x14, 0x00, 0x03,
                0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1E, 0xFF, 0xFC, 0x0F, 0xBF, 0x00,
                0x00, 0x14, 0x00, 0x02, 0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00, 0x00, 0x40, 0x1E, 0xFF,
                0xFB, 0x0E, 0xFA, 0x00, 0x00, 0x0A, 0x00, 0x01, 0x00, 0x01, 0x00, 0x42, 0x0C, 0x82, 0x83, 0x00, 0x00
            };

            byte[] containerDisplay = { 0x24, 0x00, 0x0B, 0x03, 0x54, 0x00, 0x30, 0x00, 0x00 };

            Mobile vendor = new Mobile(vendorSerial);

            vendor.SetLayer(Layer.ShopBuy, 0x420c8283);

            Engine.Mobiles.Add(vendor);

            IncomingPacketHandlers.Initialize();

            VendorBuyTabViewModel vm = new VendorBuyTabViewModel();

            VendorBuyAgentEntry entry = new VendorBuyAgentEntry();

            entry.Items.Add(new VendorBuyAgentItem
            {
                Graphic  = 0xf8c,
                Amount   = 1,
                Enabled  = true,
                Hue      = -1,
                MaxPrice = -1
            });
            entry.Items.Add(new VendorBuyAgentItem
            {
                Graphic  = 0xf8d,
                Amount   = 1,
                Enabled  = true,
                Hue      = -1,
                MaxPrice = -1
            });
            entry.Items.Add(new VendorBuyAgentItem
            {
                Graphic  = 0xf85,
                Amount   = 1,
                Enabled  = true,
                Hue      = -1,
                MaxPrice = -1
            });
            entry.Items.Add(new VendorBuyAgentItem
            {
                Graphic  = 0xf88,
                Amount   = 1,
                Enabled  = true,
                Hue      = -1,
                MaxPrice = -1
            });

            entry.Enabled = true;
            vm.Items.Add(entry);

            PacketHandler containerContentsHandler = IncomingPacketHandlers.GetHandler(0x3C);

            containerContentsHandler?.OnReceive(new PacketReader(contents, contents.Length, false));

            vendor.Equipment.Add(Engine.Items.GetItem(0x420c8283));

            PacketHandler shopListHandler = IncomingPacketHandlers.GetHandler(0x74);

            shopListHandler?.OnReceive(new PacketReader(shopList, shopList.Length, false));

            PacketHandler containerDisplayHandler = IncomingPacketHandlers.GetHandler(0x24);

            AutoResetEvent are = new AutoResetEvent(false);

            List <ShopListEntry> buyList = new List <ShopListEntry>();

            void OnPacketSentEvent(byte[] data, int length)
            {
                if (data[0] != 0x3B)
                {
                    return;
                }

                PacketReader reader = new PacketReader(data, data.Length, false);

                int count = (data.Length - 8) / 7;

                reader.Seek(5, SeekOrigin.Current);

                for (int i = 0; i < count; i++)
                {
                    reader.ReadByte(); // layer
                    int serial = reader.ReadInt32();
                    int amount = reader.ReadInt16();

                    buyList.Add(new ShopListEntry {
                        Amount = amount, Item = Engine.Items.GetItem(serial)
                    });
                }
            }

            Engine.InternalPacketSentEvent += OnPacketSentEvent;

            containerDisplayHandler?.OnReceive(new PacketReader(containerDisplay, containerDisplay.Length, true));

            foreach (VendorBuyAgentItem item in vm.Items.Where(e => e.Enabled).SelectMany(e => e.Items))
            {
                int amount = buyList.Where(e => e.Item.ID == item.Graphic).Sum(e => e.Amount);

                Assert.AreEqual(item.Amount, amount, 0, "Buy incorrect amount");
            }

            Engine.Items.Clear();
            Engine.Mobiles.Clear();
        }
Ejemplo n.º 26
0
        private void OnInternalPacketSentEvent(byte[] data, int length)
        {
            PacketHandler handler = OutgoingPacketHandlers.GetHandler(data[0]);

            handler?.OnReceive(new PacketReader(data, data.Length, _packetLengths[data[0]] != 0));

            if (data[0] == 0x08)
            {
                int serial          = (data[1] << 24) | (data[2] << 16) | (data[3] << 8) | data[4];
                int containerSerial = (data[11] << 24) | (data[12] << 16) | (data[13] << 8) | data[14];

                //container cont update

                PacketWriter pw = new PacketWriter(21);
                pw.Write((byte)0x25);
                pw.Write(serial);
                pw.Seek(10, SeekOrigin.Current);
                pw.Write(containerSerial);
                pw.Write((short)0);

                byte[] packet = pw.ToArray();

                handler = IncomingPacketHandlers.GetHandler(packet[0]);

                handler?.OnReceive(new PacketReader(packet, packet.Length, true));
            }

            if (data[0] == 0x13)
            {
                int   serial          = (data[1] << 24) | (data[2] << 16) | (data[3] << 8) | data[4];
                Layer layer           = (Layer)data[5];
                int   containerSerial = (data[6] << 24) | (data[7] << 16) | (data[8] << 8) | data[9];


                Mobile mobile = Engine.Mobiles.GetMobile(containerSerial);

                int itemInLayer = mobile?.GetLayer(layer) ?? 0;

                if (itemInLayer != 0)
                {
                    // item already in layer / liftrej
                    return;
                }

                // equip update

                PacketWriter pw = new PacketWriter(15);
                pw.Write((byte)0x2E);
                pw.Write(serial);
                pw.Write((short)0);
                pw.Write((byte)0);
                pw.Write((byte)layer);
                pw.Write(containerSerial);
                pw.Write((short)0);

                byte[] packet = pw.ToArray();

                handler = IncomingPacketHandlers.GetHandler(packet[0]);

                handler?.OnReceive(new PacketReader(packet, packet.Length, true));
            }
        }
Ejemplo n.º 27
0
        public void WillLootMatchingObjectProperties()
        {
            Engine.Player = new PlayerMobile(0x01);
            Item backpack = new Item(0x40000001, 0x01)
            {
                Container = new ItemCollection(0x40000001)
            };

            Engine.Player.SetLayer(Layer.Backpack, backpack.Serial);
            Engine.Items.Add(backpack);

            Item corpse = new Item(0x40000000)
            {
                ID = 0x2006
            };

            Engine.Items.Add(corpse);

            IncomingPacketHandlers.Initialize();
            AutolootViewModel vm = new AutolootViewModel {
                Enabled = true
            };

            AutolootEntry lootEntry = new AutolootEntry
            {
                Rehue       = false,
                Autoloot    = true,
                Constraints = new ObservableCollection <AutolootConstraintEntry>(),
                ID          = 0x108a
            };

            AutolootConstraintEntry autolootConstraint = new AutolootConstraintEntry
            {
                Property = vm.Constraints.FirstOrDefault(c => c.Name == "ID"),
                Operator = AutolootOperator.Equal,
                Value    = 0x108a
            };

            lootEntry.Constraints.Add(autolootConstraint);

            vm.Items.Add(lootEntry);

            Engine.PacketWaitEntries = new PacketWaitEntries();

            AutoResetEvent are = new AutoResetEvent(false);

            void OnPacketSentEvent(byte[] data, int length)
            {
                if (data[0] == 0x07 || data[0] == 0x08)
                {
                    are.Set();
                }
                else if (data[0] == 0xD6 || data[0] == 0x06)
                {
                }
                else
                {
                    Assert.Fail();
                }
            }

            Engine.InternalPacketSentEvent += OnPacketSentEvent;

            Engine.PacketWaitEntries.WaitEntryAddedEvent += entry =>
            {
                byte[] containerContentsPacket =
                {
                    0x3C, 0x00, 0x19, 0x00, 0x01, 0x43, 0x13, 0xFC, 0x5E, 0x10, 0x8A, 0x00, 0x00, 0x01, 0x00, 0x13,
                    0x00, 0x82, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x64
                };

                PacketHandler handler = IncomingPacketHandlers.GetHandler(0x3C);

                handler.OnReceive(new PacketReader(containerContentsPacket, containerContentsPacket.Length, false));
                entry.Packet = containerContentsPacket;
                entry.Lock.Set();
            };

            vm.OnCorpseEvent(corpse.Serial);

            bool result = are.WaitOne(5000);

            Assert.IsTrue(result);

            Engine.Items.Clear();
            Engine.PacketWaitEntries        = null;
            Engine.InternalPacketSentEvent -= OnPacketSentEvent;
            Engine.Player = null;
        }
Ejemplo n.º 28
0
        public void WillRehueMatchingItemProperties()
        {
            const string localPath = @"C:\Users\johns\Desktop\KvG Client 2.0";

            if (!Directory.Exists(localPath))
            {
                Debug.WriteLine("Not running test, requires Cliloc.enu");
                return;
            }

            Cliloc.Initialize(localPath);

            Item corpse = new Item(0x40000000)
            {
                ID = 0x2006
            };

            Engine.Items.Add(corpse);

            IncomingPacketHandlers.Initialize();
            AutolootViewModel vm = new AutolootViewModel {
                Enabled = true
            };

            AutolootEntry lootEntry = new AutolootEntry
            {
                Rehue       = true,
                Autoloot    = false,
                Constraints = new ObservableCollection <AutolootConstraintEntry>(),
                ID          = 0x108a
            };

            AutolootConstraintEntry constraintEntry = new AutolootConstraintEntry
            {
                Property = vm.Constraints.FirstOrDefault(c => c.Name == "Faster Casting"),
                Operator = AutolootOperator.GreaterThan,
                Value    = 1
            };

            lootEntry.Constraints.Add(constraintEntry);

            vm.Items.Add(lootEntry);

            Engine.PacketWaitEntries = new PacketWaitEntries();

            AutoResetEvent are = new AutoResetEvent(false);

            void OnPacketReceivedEvent(byte[] data, int length)
            {
                if (data[0] == 0x25)
                {
                    are.Set();
                }
                else
                {
                    Assert.Fail();
                }
            }

            Engine.InternalPacketReceivedEvent += OnPacketReceivedEvent;

            Engine.PacketWaitEntries.WaitEntryAddedEvent += entry =>
            {
                byte[] containerContentsPacket =
                {
                    0x3C, 0x00, 0x19, 0x00, 0x01, 0x43, 0x13, 0xFC, 0x5E, 0x10, 0x8A, 0x00, 0x00, 0x01, 0x00, 0x13,
                    0x00, 0x82, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00
                };

                PacketHandler handler = IncomingPacketHandlers.GetHandler(0x3C);

                handler.OnReceive(new PacketReader(containerContentsPacket, containerContentsPacket.Length, false));
                entry.Packet = containerContentsPacket;
                entry.Lock.Set();

                byte[] propertiesPacket =
                {
                    0xD6, 0x00, 0x53, 0x00, 0x01, 0x43, 0x13, 0xFC, 0x5E, 0x00, 0x00, 0x01, 0x6E, 0x08, 0xB4, 0x00,
                    0x0F, 0xA0, 0xEA, 0x00, 0x00, 0x00, 0x10, 0x5E, 0x94, 0x00, 0x02, 0x31, 0x00, 0x00, 0x10, 0x2E,
                    0x64, 0x00, 0x14, 0x23, 0x00, 0x31, 0x00, 0x30, 0x00, 0x34, 0x00, 0x34, 0x00, 0x30, 0x00, 0x38,
                    0x00, 0x35, 0x00, 0x09, 0x00, 0x39, 0x00, 0x00, 0x10, 0x2E, 0x3C, 0x00, 0x02, 0x32, 0x00, 0x00,
                    0x10, 0x2E, 0x3D, 0x00, 0x02, 0x31, 0x00, 0x00, 0x10, 0x2E, 0x83, 0x00, 0x02, 0x34, 0x00, 0x00,
                    0x00, 0x00, 0x00
                };

                handler = IncomingPacketHandlers.GetHandler(0xD6);

                handler.OnReceive(new PacketReader(propertiesPacket, propertiesPacket.Length, false));
            };

            vm.OnCorpseEvent(corpse.Serial);

            bool result = are.WaitOne(5000);

            Assert.IsTrue(result);

            Engine.Items.Clear();
            Engine.PacketWaitEntries = null;

            Engine.InternalPacketReceivedEvent -= OnPacketReceivedEvent;
        }
Ejemplo n.º 29
0
        public void WontLootDisabledLootHumanoids()
        {
            Engine.Player = new PlayerMobile(0x01)
            {
                X = 652, Y = 869
            };
            Item backpack = new Item(0x40000001, 0x01)
            {
                Container = new ItemCollection(0x40000001)
            };

            Engine.Player.SetLayer(Layer.Backpack, backpack.Serial);
            Engine.Items.Add(backpack);

            Item corpse = new Item(0x40000000)
            {
                ID        = 0x2006,
                Count     = 400,
                Container = new ItemCollection(0x40000000),
                X         = 652,
                Y         = 869
            };

            corpse.Container.Add(new Item(0x4313FC5E)
            {
                ID = 0x108a
            });

            Engine.Items.Add(corpse);

            IncomingPacketHandlers.Initialize();
            AutolootViewModel vm = new AutolootViewModel {
                Enabled = true, LootHumanoids = false
            };

            AutolootEntry lootEntry = new AutolootEntry
            {
                Rehue       = false,
                Autoloot    = true,
                Constraints = new ObservableCollection <AutolootConstraintEntry>(),
                ID          = 0x108a
            };

            AutolootConstraintEntry autolootConstraint = new AutolootConstraintEntry
            {
                Property = vm.Constraints.FirstOrDefault(c => c.Name == "Hue"),
                Operator = AutolootOperator.Equal,
                Value    = 0
            };

            lootEntry.Constraints.Add(autolootConstraint);

            vm.Items.Add(lootEntry);

            Engine.PacketWaitEntries = new PacketWaitEntries();

            AutoResetEvent are = new AutoResetEvent(false);

            void OnPacketSentEvent(byte[] data, int length)
            {
                if (data[0] == 0xD6 || data[0] == 0x06)
                {
                    return;
                }

                are.Set();
                Assert.Fail();
            }

            Engine.InternalPacketSentEvent += OnPacketSentEvent;

            Engine.PacketWaitEntries.WaitEntryAddedEvent += entry =>
            {
                byte[] containerContentsPacket =
                {
                    0x3C, 0x00, 0x19, 0x00, 0x01, 0x43, 0x13, 0xFC, 0x5E, 0x10, 0x8A, 0x00, 0x00, 0x01, 0x00, 0x13,
                    0x00, 0x82, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00
                };

                PacketHandler handler = IncomingPacketHandlers.GetHandler(0x3C);

                handler.OnReceive(new PacketReader(containerContentsPacket, containerContentsPacket.Length, false));
                entry.Packet = containerContentsPacket;
                entry.Lock.Set();
            };

            vm.OnCorpseEvent(corpse.Serial);

            are.WaitOne(2000);

            Engine.Items.Clear();
            Engine.PacketWaitEntries        = null;
            Engine.InternalPacketSentEvent -= OnPacketSentEvent;
            Engine.Player = null;
        }
Ejemplo n.º 30
0
        public void WillLootByPriority()
        {
            Engine.Player = new PlayerMobile(0x01)
            {
                X = 652, Y = 869
            };
            Item backpack = new Item(0x40000001, 0x01)
            {
                Container = new ItemCollection(0x40000001)
            };

            Engine.Player.SetLayer(Layer.Backpack, backpack.Serial);
            Engine.Items.Add(backpack);
            Engine.ClientVersion = Version.Parse("7.0.45.0");

            Item corpse = new Item(0x40000000)
            {
                ID        = 0x2006,
                Count     = 400,
                Container = new ItemCollection(0x40000000),
                X         = 652,
                Y         = 869
            };

            corpse.Container.Add(new Item(0x4546E4AC)
            {
                ID = 0xaa
            });
            corpse.Container.Add(new Item(0x44215a1c)
            {
                ID = 0xbb
            });

            Engine.Items.Add(corpse);

            IncomingPacketHandlers.Initialize();
            AutolootViewModel vm = new AutolootViewModel {
                Enabled = true, LootHumanoids = true
            };

            AutolootEntry lootEntry = new AutolootEntry
            {
                Rehue       = false,
                Autoloot    = true,
                Constraints = new ObservableCollection <AutolootConstraintEntry>(),
                ID          = 0xaa,
                Priority    = AutolootPriority.Normal
            };

            AutolootEntry lootEntry2 = new AutolootEntry
            {
                Rehue       = false,
                Autoloot    = true,
                Constraints = new ObservableCollection <AutolootConstraintEntry>(),
                ID          = 0xbb,
                Priority    = AutolootPriority.High
            };

            vm.Items.Add(lootEntry);
            vm.Items.Add(lootEntry2);

            /*
             * 0x44215a1c should be dragged first because the priority is higher
             * thats all the test checks
             */

            Engine.PacketWaitEntries = new PacketWaitEntries();

            AutoResetEvent are = new AutoResetEvent(false);

            bool lootedItem = false;

            void OnPacketSentEvent(byte[] data, int length)
            {
                if (data[0] == 0xD6 || data[0] == 0x08)
                {
                    return;
                }

                int serial = (data[1] << 24) | (data[2] << 16) | (data[3] << 8) | data[4];

                if (!serial.Equals(0x44215a1c) && !lootedItem)
                {
                    are.Set();
                    Assert.Fail("Autoloot wrong item");
                }

                lootedItem = true;
                are.Set();
            }

            Engine.InternalPacketSentEvent += OnPacketSentEvent;

            Engine.PacketWaitEntries.WaitEntryAddedEvent += entry =>
            {
                byte[] containerContentsPacket =
                {
                    0x3C, 0x00, 0x2D, 0x00, 0x02, 0x45, 0x46, 0xE4, 0xAC, 0x00, 0xAA, 0x00, 0x00, 0x01, 0x00, 0x2D,
                    0x00, 0x50, 0x00, 0x41, 0x5D, 0x8E, 0xDB, 0x05, 0x54, 0x44, 0x21, 0x5A, 0x1C, 0x00, 0xBB, 0x00,
                    0x00, 0x01, 0x00, 0x38, 0x00, 0x70, 0x00, 0x41, 0x5D, 0x8E, 0xDB, 0x04, 0x8D
                };

                PacketHandler handler = IncomingPacketHandlers.GetHandler(0x3C);

                handler.OnReceive(new PacketReader(containerContentsPacket, containerContentsPacket.Length, false));
                entry.Packet = containerContentsPacket;
                entry.Lock.Set();
            };

            vm.OnCorpseEvent(corpse.Serial);

            are.WaitOne(2000);

            Engine.Items.Clear();
            Engine.PacketWaitEntries        = null;
            Engine.InternalPacketSentEvent -= OnPacketSentEvent;
            Engine.Player = null;
        }