示例#1
0
        public void Trigger(MouseInjector injector, Point current, Point target, Rectangle region, Esp esp, ref bool aim, double dt)
        {
            time += dt;

            if (Conditions != Condition.Never)
            {
                if (target != Point.Empty && esp != null)
                {
                    esp.Add(new CircleShape(new Point(target.X, target.Y), Proximity, Color.Transparent, Color.Yellow, 1));
                }

                bool trigger = (aim == true && (Conditions & Condition.WhenAiming) != 0) ||
                               (aim == false && (Conditions & Condition.WhenNotAiming) != 0);

                if (trigger && time >= TriggerRate)
                {
                    var distanceSq = current.DistanceSq(target);
                    if (distanceSq <= Proximity * Proximity)
                    {
                        injector.Click(TriggerButton, 50);
                        time = 0.0;
                        if (ContinueAiming == false)
                        {
                            aim = false;
                        }
                    }
                }
            }
        }
示例#2
0
 private void Render(Point target, Esp esp)
 {
     if (esp != null && targetId > 0)
     {
         var width  = 8;
         var height = 8;
         var rect   = new Rectangle(target.X - width / 2, target.Y - height / 2, width, height);
         esp.Add(new RectangleShape(rect, Color.Red, Color.Red, 4));
     }
 }
示例#3
0
        public IntPtr Grab(IntPtr windowHandle, Rectangle region, Esp esp, bool wait, out bool changed)
        {
            esp?.Add(new RectangleShape(region, Color.Transparent, Color.LimeGreen, 2));

            if (native != IntPtr.Zero)
            {
                int frames = 0;
                var data   = Capture(native, region.X, region.Y, region.Width, region.Height, 1, 1000, wait, ref frames);
                changed = frames > 0;

                return(data);
            }

            changed = false;
            return(IntPtr.Zero);
        }
示例#4
0
        public bool Tick(double dt, Rectangle region, Esp esp)
        {
            time += dt;

            if (process != null && grabber != null)
            {
                var image = grabber.Grab(process.MainWindowHandle, region, esp, true, out var changed);
                if (image != IntPtr.Zero && changed)
                {
                    if (detector != null)
                    {
                        stopwatch.Restart();

                        var position   = new Point(region.X + region.Width / 2, region.Y + region.Height / 2);
                        var detections = detector.Detect(image, region, esp);

                        if (tracker != null && selector != null)
                        {
                            tracker.Track(detections, esp, time);
                            var target = selector.Select(tracker, position, esp, activated, time);

                            if (aimer != null)
                            {
                                if (activated)
                                {
                                    aimer.Aim(injector, target, position, dt);
                                }
                                else
                                {
                                    aimer.Tick(injector, activated, dt);
                                }
                            }

                            if (trigger != null)
                            {
                                trigger.Trigger(injector, position, target, region, esp, ref activated, time);
                            }
                        }

                        time = 0.0;
                        stopwatch.Stop();

                        if (esp != null)
                        {
                            var fps = 1000.0 / (double)stopwatch.Elapsed.TotalMilliseconds;
                            esp.Add(new TextShape(new Point(region.X, region.Y - 20), $"FPS: {Math.Round(fps)}", Color.LimeGreen, 12));
                        }
                    }
                    else
                    {
                        tracker?.Clear();
                        selector?.Clear();
                        aimer?.Clear();
                        trigger?.Clear();
                    }

                    return(activated);
                }
                else
                {
                    if (aimer != null)
                    {
                        aimer.Tick(injector, activated, dt);
                    }

                    stopwatch.Stop();
                }
            }

            return(false);
        }
示例#5
0
        protected void AddDetection(int classId, Rectangle bounds, double confidence, Esp esp)
        {
            var center = bounds.Center();

            if (esp != null)
            {
                esp.Add(new TextShape(new Point(bounds.Left, bounds.Top - 12), $"ID: {classId}", Color.Red, 12));
                esp.Add(new RectangleShape(new Rectangle(bounds.X, bounds.Y, bounds.Width, bounds.Height), Color.Transparent, Color.Red, 2));
            }

            int hho = 0;
            int hvo = 0;
            int bho = 0;
            int bvo = 0;

            switch (OffsetUnits)
            {
            case Units.Pixels:
                hho = HeadHorizontalOffset;
                hvo = HeadVerticalOffset;
                bho = BodyHorizontalOffset;
                bvo = BodyVerticalOffset;
                break;

            case Units.Percentage:
                hho = (int)Math.Round(bounds.Width * HeadHorizontalOffset * 0.01);
                hvo = (int)Math.Round(bounds.Height * HeadVerticalOffset * 0.01);
                bho = (int)Math.Round(bounds.Width * BodyHorizontalOffset * 0.01);
                bvo = (int)Math.Round(bounds.Height * BodyVerticalOffset * 0.01);
                break;
            }

            var head = Point.Empty;
            var body = Point.Empty;

            switch (AnchorPoint)
            {
            case Anchor.Center:
                head = new Point(center.X + hho, center.Y + hvo);
                body = new Point(center.X + bho, center.Y + bvo);
                break;

            case Anchor.TopCenter:
                head = new Point(center.X + hho, bounds.Top + hvo);
                body = new Point(center.X + bho, bounds.Top + bvo);
                break;

            case Anchor.BottomCenter:
                head = new Point(center.X + hho, bounds.Bottom + hvo);
                body = new Point(center.X + bho, bounds.Bottom + bvo);
                break;
            }

            detections.Add(new Detection(bounds, head, body, confidence));

            if (esp != null)
            {
                esp.Add(new CircleShape(new Point(head.X, head.Y), 5, Color.Transparent, Color.Red, 1));

                if (head != body)
                {
                    esp.Add(new CircleShape(new Point(body.X, body.Y), 5, Color.Transparent, Color.Red, 1));
                }
            }
        }
示例#6
0
        public void Track(List <Detection> detections, Esp esp, double dt)
        {
            // Purge dropped objects that have exceeded the time limit.
            for (int i = droppedObjects.Count - 1; i >= 0; --i)
            {
                var dropped = droppedObjects[i];
                if (dropped.Time + dt > MaximumInactiveTime)
                {
                    droppedObjects.RemoveFast(i);
                }
                else
                {
                    droppedObjects[i] = new TrackedObject(dropped.Detection, dropped.Id, dropped.Time + dt);
                }
            }

            // Build the cost matrix.
            var rows       = trackedObjects.Count + droppedObjects.Count;
            var cols       = detections.Count;
            var dimensions = Math.Max(rows, cols);
            var costs      = new double[dimensions, dimensions];

            // Populate the cost matrix.
            // Detections are the rows of the matrix.
            // Tracked and droped objects are the columns.
            // Entries are the costs for matching each.
            // Note that if the number of detections is not equal to the number of tracked/dropped
            // objects then we will have a bunch of (dummy) zero entries. These correspond to
            // creating new tracked objects or dropping more tracked objects.
            for (int r = 0; r < detections.Count; ++r)
            {
                var detection = detections[r];

                for (int c = 0; c < trackedObjects.Count; ++c)
                {
                    costs[r, c] = GIOU(detection.BoundingBox, trackedObjects[c].Detection.BoundingBox);
                }

                for (int c = 0; c < droppedObjects.Count; ++c)
                {
                    costs[r, trackedObjects.Count + c] = GIOU(detection.BoundingBox, droppedObjects[c].Detection.BoundingBox);
                }
            }

            // Find matches using the Hungarian Algorithm.
            var assignments = HungarianAlgorithm.FindAssignments(costs);

            // Update or create the tracked/dropped objects.
            var persistedCount    = trackedObjects.Count;
            var maximumDistanceSq = MaximumTrackingDistance * MaximumTrackingDistance;

            for (int r = 0; r < detections.Count; ++r)
            {
                var detection       = detections[r];
                var detectionCenter = detection.BoundingBox.Center();
                var c = assignments[r];
                if (c < trackedObjects.Count)
                {
                    // We have a match with a tracked object.
                    // Check that the distance doesn't exceed the maximum allowed.
                    var tracked    = trackedObjects[c];
                    var distanceSq = detectionCenter.DistanceSq(tracked.Detection.BoundingBox.Center());
                    if (distanceSq <= maximumDistanceSq)
                    {
                        // Okay, we can update the tracked object.
                        trackedObjects[c] = new TrackedObject(detection, trackedObjects[c].Id, trackedObjects[c].Time + dt);
                    }
                    else
                    {
                        // Distance limit exceeded.
                        // We need to create a new tracking object and drop the old one.
                        trackedObjects.RemoveFast(c);
                        trackedObjects.Add(new TrackedObject(detection, nextId++, 0.0));
                        droppedObjects.Add(new TrackedObject(tracked.Detection, tracked.Id, 0.0));
                        persistedCount -= 1;
                    }
                }
                else if (c < rows)
                {
                    // We have a match with a dropped object.
                    // Check the distance doesn't exceed the maximum allowed.
                    var idx        = rows - trackedObjects.Count - 1;
                    var dropped    = droppedObjects[idx];
                    var distanceSq = detectionCenter.DistanceSq(dropped.Detection.BoundingBox.Center());
                    if (distanceSq <= maximumDistanceSq)
                    {
                        // Okay, we can bring back the dropped object.
                        trackedObjects.Add(new TrackedObject(detection, dropped.Id, 0.0));
                        droppedObjects.RemoveFast(idx);
                    }
                    else
                    {
                        // Distance limit exceeded.
                        // We need to add a new tracking object.
                        trackedObjects.Add(new TrackedObject(detection, nextId++, 0.0));
                    }
                }
                else
                {
                    // Completely new object.
                    trackedObjects.Add(new TrackedObject(detection, nextId++, 0.0));
                }
            }

            // Collect the list of tracked object IDs to be removed from the tracked object list and
            // drop the trapped objects.
            dropIds.Clear();
            for (int r = detections.Count; r < assignments.Length; ++r)
            {
                var c = assignments[r];
                if (c < persistedCount) // We could have added/removed tracked objects above.
                {
                    var tracked = trackedObjects[c];
                    dropIds.Add(tracked.Id);
                    droppedObjects.Add(new TrackedObject(tracked.Detection, tracked.Id, 0.0));
                }
            }

            // Now remove the dropped tracked objects.
            foreach (var id in dropIds)
            {
                for (int i = 0; i < persistedCount; ++i)
                {
                    if (trackedObjects[i].Id == id)
                    {
                        trackedObjects.RemoveFast(i);
                        persistedCount -= 1;
                        break;
                    }
                }
            }

            // Render tracked objects.
            if (esp != null)
            {
                foreach (var tracked in trackedObjects)
                {
                    esp.Add(new TextShape(tracked.Detection.BoundingBox.TopLeft(), tracked.Id.ToString(), Color.Red, 12));
                }
            }
        }
示例#7
0
        public IntPtr Grab(IntPtr windowHandle, Rectangle region, Esp esp, bool wait, out bool changed)
        {
            changed = false;

            if (esp != null)
            {
                esp.Add(new RectangleShape(region, Color.Transparent, Color.LimeGreen, 2));
            }

            // Reuse existing bitmap if possible.
            // Better not to hammer the GC.
            width  = region.Width;
            height = region.Height;
            var numPixels = width * height;
            var numBytes  = numPixels * 12;

            if (current == IntPtr.Zero || currentNumBytes != numBytes)
            {
                if (current != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(current);
                    current = IntPtr.Zero;
                }

                current         = Marshal.AllocHGlobal(numBytes);
                currentNumBytes = numBytes;
            }

            if (previous == IntPtr.Zero || previousNumBytes != numBytes)
            {
                if (previous != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(previous);
                    previous = IntPtr.Zero;
                }

                previous         = Marshal.AllocHGlobal(numBytes);
                previousNumBytes = numBytes;
            }

            if (data == null || data.Length != numPixels * 3)
            {
                data = new byte[numPixels * 3];
            }

            var clientRect = Helpers.ScreenHelper.ClientRectangle(windowHandle);

            var hdc     = GetDC(windowHandle);                        // Handle to display device context.
            var hdcMem  = CreateCompatibleDC(hdc);                    // Create memory device context for the device.
            var hBitmap = CreateCompatibleBitmap(hdc, width, height); // Create a bitmap.

            do
            {
                var hOld = SelectObject(hdcMem, hBitmap); // Select the bitmap in the memory device context.

                // Copy from screen to memory device context.
                if (BitBlt(hdcMem, 0, 0, width, height, hdc, region.X - clientRect.X, region.Y - clientRect.Y, (int)CopyPixelOperation.SourceCopy) == 0)
                {
                    // Failed!
                    int error = Marshal.GetLastWin32Error(); // TODO:
                }

                SelectObject(hdcMem, hOld); // Restore selection.

                var bitmapInfoHeader = new BITMAPINFOHEADER();
                bitmapInfoHeader.biSize          = (uint)Marshal.SizeOf <BITMAPINFOHEADER>();
                bitmapInfoHeader.biWidth         = width;
                bitmapInfoHeader.biHeight        = -height; // Top down.
                bitmapInfoHeader.biPlanes        = 1;
                bitmapInfoHeader.biBitCount      = 24;
                bitmapInfoHeader.biCompression   = 0; // BI_RGB = Uncompressed RGB
                bitmapInfoHeader.biSizeImage     = 0; // Size of the image in bytes - set to zero for BI_RGB
                bitmapInfoHeader.biXPelsPerMeter = 0;
                bitmapInfoHeader.biYPelsPerMeter = 0;
                bitmapInfoHeader.biClrUsed       = 0;
                bitmapInfoHeader.biClrImportant  = 0;

                // Copy the bits of the RGB bitmap to the data array.
                var linesCopied = GetDIBits(hdc, hBitmap, 0, (uint)height, data, ref bitmapInfoHeader, 0);
                if (linesCopied != height || data == null)
                {
                    int error = Marshal.GetLastWin32Error();
                }

                // Copy to "current" buffer.
                unsafe
                {
                    fixed(byte *source = data)
                    {
                        float *destination = (float *)current;

                        for (int c = 0; c < 3; ++c)
                        {
                            float *page = destination + c * width * height;
                            for (int y = 0; y < height; ++y)
                            {
                                int    offset = y * width;
                                float *scan0  = page + offset;
                                for (int x = 0; x < width; ++x)
                                {
                                    scan0[x] = (float)source[3 * (offset + x) + c] / 255.0F;
                                }
                            }
                        }
                    }
                }

                // Compare buffers.
                if (previousNumBytes != currentNumBytes)
                {
                    changed = true;
                }
                else
                {
                    changed = CompareMemory(previous, current, numBytes) != 0;
                }
            }while (wait == true && changed == false);

            // Free resources.
            DeleteObject(hBitmap);
            DeleteDC(hdcMem);
            ReleaseDC(IntPtr.Zero, hdc);

            // Swap buffers.
            var temp = current;

            current  = previous;
            previous = temp;
            var temp2 = currentNumBytes;

            currentNumBytes  = previousNumBytes;
            previousNumBytes = temp2;

            return(current);
        }