Ejemplo n.º 1
0
        public static bool WaitForProperties(object obj, int timeout)
        {
            int serial = AliasCommands.ResolveSerial(obj);

            if (serial == 0)
            {
                UOC.SystemMessage(Strings.Invalid_or_unknown_object_id);
                return(false);
            }

            PacketFilterInfo pfi = new PacketFilterInfo(0xD6,
                                                        new[] { PacketFilterConditions.IntAtPositionCondition(serial, 5) });

            PacketWaitEntry we = Engine.PacketWaitEntries.Add(pfi, PacketDirection.Incoming, true);

            Engine.SendPacketToServer(new BatchQueryProperties(serial));

            try
            {
                bool result = we.Lock.WaitOne(timeout);

                return(result);
            }
            finally
            {
                Engine.PacketWaitEntries.Remove(we);
            }
        }
Ejemplo n.º 2
0
        public static bool WaitForContainerContentsUse(int serial, int timeout)
        {
            int pos = 19;

            if (Engine.ClientVersion < new Version(6, 0, 1, 7))
            {
                pos = 18;
            }

            PacketFilterInfo pfi = new PacketFilterInfo(0x3C,
                                                        new[] { PacketFilterConditions.IntAtPositionCondition(serial, pos) });

            PacketWaitEntry we = Engine.PacketWaitEntries.Add(pfi, PacketDirection.Incoming, true);

            Engine.SendPacketToServer(new UseObject(serial));

            try
            {
                bool result = we.Lock.WaitOne(timeout);

                return(result);
            }
            finally
            {
                Engine.PacketWaitEntries.Remove(we);
            }
        }
Ejemplo n.º 3
0
        private static async Task <Item[]> FindWands(WandTypes wandType, int containerSerial, int minimumCharges)
        {
            // Hybrid has FeatureFlags.AOS, think of better solution
            if (!Engine.Features.HasFlag(FeatureFlags.AOS) || Engine.CurrentShard.Name.Equals("UOHybrid"))
            {
                Item[] allWands = Engine.Items.SelectEntities(i =>
                                                              _wandIds.Contains(i.ID) && (containerSerial == -1 || i.IsDescendantOf(containerSerial)));

                if (allWands == null)
                {
                    return(null);
                }

                foreach (Item wand in allWands)
                {
                    Engine.SendPacketToServer(new LookRequest(wand.Serial));
                    await UOC.WaitForIncomingPacketFilterAsync(
                        new PacketFilterInfo( 0xBF,
                                              new[]
                    {
                        PacketFilterConditions.ShortAtPositionCondition(0x10, 3),
                        PacketFilterConditions.IntAtPositionCondition(wand.Serial, 5)
                    } ), 2500);
                }
            }

            Item[] matches = Engine.Items.SelectEntities(i =>
                                                         _wandIds.Contains(i.ID) && (containerSerial == -1 || i.IsDescendantOf(containerSerial)) &&
                                                         i.Properties != null && i.Properties.Any(p =>
                                                                                                  _wandClilocs[wandType].Contains(p.Cliloc) &&
                                                                                                  (minimumCharges == -1 || int.Parse(p.Arguments[0]) >= minimumCharges)));

            return(matches);
        }
Ejemplo n.º 4
0
        private static async Task <Item[]> FindWands(WandTypes wandType, int containerSerial, int minimumCharges)
        {
            if (!Engine.TooltipsEnabled)
            {
                Item[] allWands = Engine.Items.SelectEntities(i =>
                                                              _wandIds.Contains(i.ID) && !ObjectCommands.InIgnoreList(i.Serial) && (containerSerial == -1 || i.IsDescendantOf(containerSerial)));

                if (allWands == null)
                {
                    return(null);
                }

                foreach (Item wand in allWands)
                {
                    Engine.SendPacketToServer(new LookRequest(wand.Serial));
                    await UOC.WaitForIncomingPacketFilterAsync(
                        new PacketFilterInfo( 0xBF,
                                              new[]
                    {
                        PacketFilterConditions.ShortAtPositionCondition(0x10, 3),
                        PacketFilterConditions.IntAtPositionCondition(wand.Serial, 5)
                    } ), 2500);
                }
            }

            Item[] matches = Engine.Items.SelectEntities(i =>
                                                         _wandIds.Contains(i.ID) && !ObjectCommands.InIgnoreList(i.Serial) && (containerSerial == -1 || i.IsDescendantOf(containerSerial)) &&
                                                         i.Properties != null && i.Properties.Any(p =>
                                                                                                  _wandClilocs[wandType].Contains(p.Cliloc) &&
                                                                                                  (minimumCharges == -1 || int.Parse(p.Arguments[0]) >= minimumCharges)));

            return(matches);
        }
Ejemplo n.º 5
0
        public static (bool Result, string Message) GetText(string prompt, int timeout = 30000)
        {
            int id = new Random().Next();

            UOC.SystemMessage(prompt);
            Engine.SendPacketToClient(new UnicodePromptRequest(id));

            AutoResetEvent are = new AutoResetEvent(false);

            string message = string.Empty;

            Engine.AddSendPreFilter(new PacketFilterInfo(0xC2,
                                                         new[]
            {
                PacketFilterConditions.IntAtPositionCondition(id, 3),
                PacketFilterConditions.IntAtPositionCondition(id, 7)
            }, (bytes, info) =>
            {
                PacketReader pr = new PacketReader(bytes, bytes.Length, false);
                pr.Seek(16, SeekOrigin.Current);
                message = pr.ReadUnicodeStringLE();
                are.Set();
            }));

            bool result = are.WaitOne(timeout);

            if (!result)
            {
                Engine.SendPacketToClient(new UnicodePromptCancel(id, id));
            }

            return(result, message);
        }
Ejemplo n.º 6
0
        public static bool WaitForTargetOrFizzle(int timeout)
        {
            PacketFilterInfo targetPfi = new PacketFilterInfo(0x6C);
            PacketFilterInfo fizzPfi   = new PacketFilterInfo(0xC0,
                                                              new[]
            {
                PacketFilterConditions.IntAtPositionCondition(Engine.Player.Serial, 2),
                PacketFilterConditions.ShortAtPositionCondition(0x3735, 10)
            });

            Engine.WaitingForTarget = true;

            PacketWaitEntry targetWe = Engine.PacketWaitEntries.Add(targetPfi, PacketDirection.Incoming);
            PacketWaitEntry fizzWe   = Engine.PacketWaitEntries.Add(fizzPfi, PacketDirection.Incoming);

            try
            {
                Task <bool> targetTask = Task.Run(() =>
                {
                    do
                    {
                        bool result = targetWe.Lock.WaitOne(timeout);

                        if (!result)
                        {
                            return(false);
                        }

                        if (targetWe.Packet[6] == 0x03)
                        {
                            continue;
                        }

                        return(true);
                    }while (true);
                });

                Task fizzTask = Task.Run(() => fizzWe.Lock.WaitOne(timeout));

                int index = Task.WaitAny(targetTask, fizzTask);

                return(index == 0 && targetTask.Result);
            }
            finally
            {
                Engine.PacketWaitEntries.Remove(targetWe);
                Engine.PacketWaitEntries.Remove(fizzWe);

                Engine.WaitingForTarget = false;
            }
        }
Ejemplo n.º 7
0
        public static bool WaitForContext(object obj, string entryName, int timeout)
        {
            int serial = AliasCommands.ResolveSerial(obj);

            if (serial == 0)
            {
                UOC.SystemMessage(Strings.Invalid_or_unknown_object_id, true);
                return(false);
            }

            AutoResetEvent are = new AutoResetEvent(false);

            PacketFilterInfo pfi = new PacketFilterInfo(0xBF,
                                                        new[]
            {
                PacketFilterConditions.ShortAtPositionCondition(0x14, 3),
                PacketFilterConditions.IntAtPositionCondition(serial, 7)
            }, (bytes, info) =>
            {
                IEnumerable <ContextMenuEntry> entries = ParseContextMenuEntries(bytes);

                ContextMenuEntry entry =
                    entries.FirstOrDefault(e => e.Text.Trim().ToLower().Equals(entryName.Trim().ToLower()));

                if (entry == null)
                {
                    UOC.SystemMessage(Strings.Context_menu_entry_not_found___, (int)UOC.SystemMessageHues.Yellow,
                                      true, true);
                    return;
                }

                Engine.SendPacketToServer(new ContextMenuClick(serial, entry.Index));
                are.Set();
            });

            Engine.AddReceiveFilter(pfi);

            Engine.SendPacketToServer(new ContextMenuRequest(serial));

            try
            {
                bool result = are.WaitOne(timeout);

                return(result);
            }
            finally
            {
                Engine.RemoveReceiveFilter(pfi);
            }
        }
Ejemplo n.º 8
0
        public Target(TargetType targetType, int senderSerial, TargetFlags flags, int targetSerial, int x, int y,
                      int z, int id, bool cancelClientCursor)
        {
            if (senderSerial == -1)
            {
                senderSerial = Engine.TargetSerial;
            }

            if (targetSerial > 0)
            {
                Engine.Player.LastTargetSerial = targetSerial;
                Engine.Player.LastTargetType   = targetType;
            }

            if (Engine.TargetFlags == TargetFlags.Harmful &&
                Options.CurrentOptions.PreventTargetingFriendsWithHarmful &&
                MobileCommands.InFriendList(targetSerial))
            {
                Commands.SystemMessage(Strings.Target_blocked____try_again___);
                Commands.ResendTargetToClient();

                return;
            }

            _writer = new PacketWriter(19);
            _writer.Write((byte)0x6C);
            _writer.Write((byte)targetType);
            _writer.Write(senderSerial);
            _writer.Write((byte)flags);
            _writer.Write(targetSerial);
            _writer.Write((short)x);
            _writer.Write((short)y);
            _writer.Write((short)z);
            _writer.Write((short)id);

            Engine.TargetExists = false;

            if (cancelClientCursor)
            {
                Engine.SendPacketToClient(new Target(targetType, senderSerial, TargetFlags.Cancel, targetSerial, x, y,
                                                     z, id, false));
                Engine.AddSendPreFilter(new PacketFilterInfo(0x6C,
                                                             new[] { PacketFilterConditions.IntAtPositionCondition(senderSerial, 2) },
                                                             (p, pfi) => { Engine.RemoveSendPreFilter(pfi); }));
            }
        }
Ejemplo n.º 9
0
        public static bool WaitForContainerContents(int serial, int timeout)
        {
            PacketFilterInfo pfi = new PacketFilterInfo(0x3C,
                                                        new[] { PacketFilterConditions.IntAtPositionCondition(serial, 19) });

            PacketWaitEntry we = Engine.PacketWaitEntries.Add(pfi, PacketDirection.Incoming, true);

            try
            {
                bool result = we.Lock.WaitOne(timeout);

                return(result);
            }
            finally
            {
                Engine.PacketWaitEntries.Remove(we);
            }
        }
Ejemplo n.º 10
0
        public static bool WaitForContext(object obj, int entry, int timeout)
        {
            int serial = AliasCommands.ResolveSerial(obj);

            if (serial == 0)
            {
                UOC.SystemMessage(Strings.Invalid_or_unknown_object_id);
                return(false);
            }

            AutoResetEvent are = new AutoResetEvent(false);

            PacketFilterInfo pfi = new PacketFilterInfo(0xBF,
                                                        new[]
            {
                PacketFilterConditions.ShortAtPositionCondition(0x14, 3),
                PacketFilterConditions.IntAtPositionCondition(serial, 7)
            }, (bytes, info) =>
            {
                Engine.SendPacketToServer(new ContextMenuClick(serial, entry));
                are.Set();
            });

            Engine.AddReceiveFilter(pfi);

            Engine.SendPacketToServer(new ContextMenuRequest(serial));

            try
            {
                bool result = are.WaitOne(timeout);

                return(result);
            }
            finally
            {
                Engine.RemoveReceiveFilter(pfi);
            }
        }
Ejemplo n.º 11
0
        public static (int, bool) WaitForTargetOrFizzle(int timeout)
        {
            PacketWaitEntry targetWe = CreateWaitEntry(new PacketFilterInfo(0x6C));

            PacketWaitEntry fizzWe = CreateWaitEntry(new PacketFilterInfo(0xC0,
                                                                          new[]
            {
                PacketFilterConditions.IntAtPositionCondition(Engine.Player.Serial, 2),
                PacketFilterConditions.ShortAtPositionCondition(0x3735, 10)
            }));

            PacketWaitEntry fizzMessageWe = CreateWaitEntry(new PacketFilterInfo(0xC1,
                                                                                 new[] { PacketFilterConditions.IntAtPositionCondition(502632, 14) /* The spell fizzles. */ }));

            PacketWaitEntry recoveredMessageWe = CreateWaitEntry(new PacketFilterInfo(0xC1,
                                                                                      new[]
            {
                PacketFilterConditions.IntAtPositionCondition(502644,
                                                              14) /* You have not yet recovered from casting a spell. */
            }));

            PacketWaitEntry alreadyCastingWe = CreateWaitEntry(new PacketFilterInfo(0xC1,
                                                                                    new[]
            {
                PacketFilterConditions.IntAtPositionCondition(502642,
                                                              14) /* You are already casting a spell. */
            }));

            PacketWaitEntry alreadyCasting2We = CreateWaitEntry(new PacketFilterInfo(0xC1,
                                                                                     new[]
            {
                PacketFilterConditions.IntAtPositionCondition(502645,
                                                              14) /* You are already casting a spell. */
            }));

            PacketWaitEntry concentrationWe = CreateWaitEntry(new PacketFilterInfo(0xC1,
                                                                                   new[]
            {
                PacketFilterConditions.IntAtPositionCondition(500641,
                                                              14) /* Your concentration is disturbed, thus ruining thy spell. */
            }));

            PacketWaitEntry noManaWe = CreateWaitEntry(new PacketFilterInfo(0xC1,
                                                                            new[]
            {
                PacketFilterConditions.IntAtPositionCondition(502625, 14)       /* Insufficient mana etc... */
            }));

            PacketWaitEntry fizzChivWe = CreateWaitEntry(new PacketFilterInfo(0x54,
                                                                              new[]
            {
                PacketFilterConditions.ShortAtPositionCondition(0x1D6, 2),
                PacketFilterConditions.ShortAtPositionCondition(Engine.Player.X, 6),
                PacketFilterConditions.ShortAtPositionCondition(Engine.Player.Y, 8),
                PacketFilterConditions.ShortAtPositionCondition(Engine.Player.Z, 10)
            }));

            Engine.WaitingForTarget = true;

            List <Task> tasks = new List <Task>();

            try
            {
                Task <bool> targetTask = Task.Run(() =>
                {
                    do
                    {
                        bool result = targetWe.Lock.WaitOne(timeout);

                        if (!result)
                        {
                            return(false);
                        }

                        if (targetWe.Packet[6] == 0x03)
                        {
                            continue;
                        }

                        return(true);
                    }while (true);
                });

                Task fizzTask = Task.Factory.StartNew(() => fizzWe.Lock.WaitOne(timeout),
                                                      TaskCreationOptions.LongRunning);

                Task fizzMessageTask = Task.Factory.StartNew(() => fizzMessageWe.Lock.WaitOne(timeout + 100),
                                                             TaskCreationOptions.LongRunning);

                Task recoveredMessageTask =
                    Task.Factory.StartNew(() => recoveredMessageWe.Lock.WaitOne(timeout + 100),
                                          TaskCreationOptions.LongRunning);

                Task alreadyCastingTask = Task.Factory.StartNew(() => alreadyCastingWe.Lock.WaitOne(timeout + 100),
                                                                TaskCreationOptions.LongRunning);

                Task alreadyCasting2Task = Task.Factory.StartNew(() => alreadyCasting2We.Lock.WaitOne(timeout + 100),
                                                                 TaskCreationOptions.LongRunning);

                Task concentrationTask = Task.Factory.StartNew(() => concentrationWe.Lock.WaitOne(timeout + 100),
                                                               TaskCreationOptions.LongRunning);

                Task noManaTask = Task.Factory.StartNew(() => noManaWe.Lock.WaitOne(timeout + 100),
                                                        TaskCreationOptions.LongRunning);

                Task fizzChivTask = Task.Factory.StartNew(() => fizzChivWe.Lock.WaitOne(timeout + 100),
                                                          TaskCreationOptions.LongRunning);

                int index;

                tasks.AddRange(new[]
                {
                    targetTask, fizzTask, fizzMessageTask, recoveredMessageTask, alreadyCastingTask,
                    alreadyCasting2Task, concentrationTask, noManaTask, fizzChivTask
                });

                try
                {
                    index = Task.WaitAny(tasks.ToArray());
                }
                catch (OperationCanceledException)
                {
                    return(-1, false);
                }
                catch (ThreadInterruptedException)
                {
                    return(-1, false);
                }

                return(index, index == 0 && targetTask.Result);
            }
            finally
            {
                Engine.PacketWaitEntries.Remove(targetWe);
                Engine.PacketWaitEntries.Remove(fizzWe);
                Engine.PacketWaitEntries.Remove(fizzMessageWe);
                Engine.PacketWaitEntries.Remove(recoveredMessageWe);
                Engine.PacketWaitEntries.Remove(alreadyCastingWe);
                Engine.PacketWaitEntries.Remove(alreadyCasting2We);
                Engine.PacketWaitEntries.Remove(concentrationWe);
                Engine.PacketWaitEntries.Remove(noManaWe);
                Engine.PacketWaitEntries.Remove(fizzChivWe);

                Engine.WaitingForTarget = false;
            }
        }