Example #1
0
        public static Bitmap Classify(out CursorClassification classification)
        {
            var result = new Bitmap(32, 32);

            try
            {
                NativeMethods.CURSORINFO pci;
                pci.cbSize = Marshal.SizeOf(typeof(NativeMethods.CURSORINFO));

                using (var g = Graphics.FromImage(result))
                {
                    if (NativeMethods.GetCursorInfo(out pci))
                    {
                        if (pci.flags == NativeMethods.CURSOR_SHOWING)
                        {
                            var hdc = g.GetHdc();
                            NativeMethods.DrawIconEx(hdc, 0, 0, pci.hCursor, 0, 0, 0, IntPtr.Zero, NativeMethods.DI_NORMAL);
                            g.ReleaseHdc();
                        }
                    }
                }

                var hash = ImageHashing.AverageHash(result);

                //var filename = hash + ".bmp";
                //if (!File.Exists(filename))
                //{
                //    result.Save(filename);
                //}

                var matching = imageHashes.SelectMany(i => i.Value.Select(v => (similarity: ImageHashing.Similarity(hash, v), imagehash: i)))
                               .Where(t => t.similarity > 80)
                               .OrderByDescending(t => t.similarity)
                               .FirstOrDefault();

                classification = matching.imagehash.Key;
                Debug.WriteLine(classification.ToString() + " " + matching.similarity);

                if (classification == 0)
                {
                    classification = CursorClassification.None;
                }

                return(result);
            }
            catch
            {
                classification = CursorClassification.Unknown;
                return(result);
            }
        }
Example #2
0
        public static Bitmap Classify(out CursorClassification classification)
        {
            var size   = NativeMethods.GetCursorSize();
            var result = new Bitmap(size.Width, size.Height);

            try
            {
                var cursorInfo = new NativeMethods.CURSORINFO();
                cursorInfo.cbSize = Marshal.SizeOf(cursorInfo);
                if (NativeMethods.GetCursorInfo(out cursorInfo))
                {
                    using (Graphics g = Graphics.FromImage(result))
                    {
                        if (cursorInfo.flags == NativeMethods.CURSOR_SHOWING)
                        {
                            NativeMethods.DrawIcon(g.GetHdc(), 0, 0, cursorInfo.hCursor);
                        }
                    }
                }

                var hash = ImageHashing.AverageHash(result);

                //var filename = hash + ".bmp";
                //var path = Path.Join("../Cursors/", filename);
                //if (!File.Exists(path))
                //{
                //    result.Save(path);
                //}

                var matching = imageHashes.SelectMany(i => i.Value.Select(v => (similarity: ImageHashing.Similarity(hash, v), imagehash: i)))
                               .Where(t => t.similarity > 80)
                               .OrderByDescending(t => t.similarity)
                               .FirstOrDefault();

                classification = matching.imagehash.Key;
                Debug.WriteLine($"[CursorClassifier.Classify] {classification} - {matching.similarity}");

                if (classification == 0)
                {
                    classification = CursorClassification.None;
                }

                return(result);
            }
            catch
            {
                classification = CursorClassification.Unknown;
                return(result);
            }
        }
        public async Task <bool> FindByCursorType(CursorClassification cursor)
        {
            foreach (var npc in Npcs)
            {
                foreach (var location in locFindByCursorType)
                {
                    var clickPostion = bitmapProvider.DirectBitmap.ToScreenCoordinates(npc.ClickPoint.X + location.X, npc.ClickPoint.Y + location.Y);
                    mouseInput.SetCursorPosition(clickPostion);
                    await Task.Delay(75);

                    CursorClassifier.Classify(out var cls).Dispose();
                    if (cls == cursor)
                    {
                        await AquireTargetAtCursor(clickPostion, npc);

                        return(true);
                    }
                }
            }
            return(false);
        }
        public static Bitmap Classify(out CursorClassification classification)
        {
            var result = new Bitmap(32, 32);

            try
            {
                NativeMethods.CURSORINFO pci;
                pci.cbSize = Marshal.SizeOf(typeof(NativeMethods.CURSORINFO));

                using (var g = Graphics.FromImage(result))
                {
                    if (NativeMethods.GetCursorInfo(out pci))
                    {
                        if (pci.flags == NativeMethods.CURSOR_SHOWING)
                        {
                            var hdc = g.GetHdc();
                            NativeMethods.DrawIconEx(hdc, 0, 0, pci.hCursor, 0, 0, 0, IntPtr.Zero, NativeMethods.DI_NORMAL);
                            g.ReleaseHdc();
                        }
                    }
                }

                var hash = ImageHashing.AverageHash(result);
                //logger.LogInformation("Hash: " + hash);

                var matching = imageHashes.Select(i => (similarity: ImageHashing.Similarity(hash, i.Value), imagehash: i))
                               .OrderByDescending(t => t.similarity)
                               .First();

                classification = matching.imagehash.Key;
                //System.Diagnostics.logger.LogInformation(classification);
                return(result);
            }
            catch
            {
                classification = CursorClassification.Unknown;
                return(result);
            }
        }
Example #5
0
        private async Task <bool> CheckForLoot(Point mousePosition, bool searchForMobs, bool ignoreMobs)
        {
            var inCombat = this.playerReader.PlayerBitValues.PlayerInCombat;

            Classification = CursorClassification.None;
            await Task.Delay(30);

            CursorClassifier.Classify(out var cls).Dispose();

            if (searchForMobs)
            {
                if (cls == CursorClassification.Kill)
                {
                    await Task.Delay(100);

                    CursorClassifier.Classify(out cls).Dispose();
                }
            }
            else
            {
                // found something, lets give the cursor a chance to update.
                if (cls == CursorClassification.Loot || cls == CursorClassification.Kill || cls == CursorClassification.Skin)
                {
                    await Task.Delay(200);

                    CursorClassifier.Classify(out cls).Dispose();
                }
            }

            if (cls == CursorClassification.Loot && !searchForMobs)
            {
                Log("Found: " + cls.ToString());
                await wowProcess.RightClickMouse(mousePosition);

                Classification = cls;
                await Task.Delay(500);
                await Wait(2000, inCombat);
            }

            if (cls == CursorClassification.Skin && !searchForMobs)
            {
                Log("Found: " + cls.ToString());
                await wowProcess.RightClickMouse(mousePosition);

                Classification = cls;
                await Task.Delay(1000);
                await Wait(6000, inCombat);
            }

            if (cls == CursorClassification.Kill && !ignoreMobs)
            {
                Log("Found: " + cls.ToString());
                await wowProcess.RightClickMouse(mousePosition);

                Classification = cls;
            }

            if (cls == CursorClassification.Loot || cls == CursorClassification.Skin)
            {
                lastLootFoundAt = mousePosition;
                logger.LogInformation($"Loot found at {this.lastLootFoundAt.X},{this.lastLootFoundAt.Y}");
            }

            if (searchForMobs)
            {
                return(cls == CursorClassification.Kill);
            }

            return(cls == CursorClassification.Loot || cls == CursorClassification.Skin || cls == CursorClassification.Kill);
        }