コード例 #1
0
        protected override void AddDetections(IntPtr image, Rectangle region, Esp esp, List <Detection> detections)
        {
            if (opencv != null && image != IntPtr.Zero)
            {
                var resized = resizer.Resize(image, region.Width, region.Height, InputWidth, InputHeight);
                if (resized != IntPtr.Zero)
                {
                    var ratiox = (double)region.Width / InputWidth;
                    var ratioy = (double)region.Height / InputHeight;

                    var results = opencv.Detect(resized, InputWidth, InputHeight, SwapRB, out var count);
                    if (results != null && results.Length > 0)
                    {
                        for (int i = 0; i < count; ++i)
                        {
                            var result = results[i];
                            if (result.confidence >= DetectionThreshold)
                            {
                                var x = (int)(result.x * ratiox);
                                var y = (int)(result.y * ratioy);
                                var w = (int)(result.width * ratiox);
                                var h = (int)(result.height * ratioy);

                                var bounds = new Rectangle(region.X + x, region.Y + y, w, h);
                                AddDetection(result.classId, bounds, result.confidence, esp);
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: Esp.cs プロジェクト: yytitx/HackBGRT
 /**
  * Unmount the EFI System Partition, if necessary.
  */
 private static void Unmount()
 {
     if (MountInstance != null)
     {
         Setup.Execute("mountvol", Path + " /D", true);
         RealPath      = null;
         MountInstance = null;
     }
 }
コード例 #3
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));
     }
 }
コード例 #4
0
        public MainWindow()
        {
            InitializeComponent();

            DataContext = this;

            serializerSettings = new JsonSerializerSettings()
            {
                TypeNameHandling = TypeNameHandling.Objects
            };

            stopwatch = new Stopwatch();
            esp       = null;
            bot       = new Bot();
        }
コード例 #5
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);
        }
コード例 #6
0
 /**
  * Find or mount or manually choose the EFI System Partition.
  */
 public static void InitEspPath()
 {
     if (!Esp.Find() && !Esp.Mount())
     {
         Console.WriteLine("EFI System Partition was not found.");
         Console.WriteLine("Press enter to exit, or give ESP path here: ");
         string s = Console.ReadLine();
         if (s.Length == 1)
         {
             s = s + ":";
         }
         if (!Esp.TryPath(s, true))
         {
             Console.WriteLine("That's not a valid ESP path!");
         }
     }
     if (Esp.Path == null)
     {
         throw new SetupException("EFI System Partition was not found.");
     }
     Console.WriteLine("EFI System Partition location is " + Esp.Path);
 }
コード例 #7
0
ファイル: Esp.cs プロジェクト: yytitx/HackBGRT
 /**
  * Mount the EFI System Partition.
  *
  * @return true if the drive was mounted, false otherwise.
  */
 public static bool Mount()
 {
     if (MountInstance != null)
     {
         return(true);
     }
     for (char c = 'A'; c <= 'Z'; ++c)
     {
         if (Setup.Execute("mountvol", c + ": /S", true) != null)
         {
             MountInstance = new Esp();
             if (TryPath(c + ":", false))
             {
                 return(true);
             }
             else
             {
                 throw new Exception("Mounted ESP at " + c + ": but it seems to be invalid!");
             }
         }
     }
     return(false);
 }
コード例 #8
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);
        }
コード例 #9
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;
                        }
                    }
                }
            }
        }
コード例 #10
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));
                }
            }
        }
コード例 #11
0
 public List <Detection> Detect(IntPtr image, Rectangle region, Esp esp)
 {
     detections.Clear();
     AddDetections(image, region, esp, detections);
     return(detections);
 }
コード例 #12
0
 protected abstract void AddDetections(IntPtr image, Rectangle region, Esp esp, List <Detection> detections);
コード例 #13
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));
                }
            }
        }
コード例 #14
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);
        }
コード例 #15
0
        /// <summary>
        /// Selects and returns a target point.
        /// </summary>
        /// <param name="tracker">The tracker, which tracks detections.</param>
        /// <param name="position">The current mouse position.</param>
        /// <param name="esp">The esp, which can be rendered to.</param>
        /// <param name="aim">Whether to select a target.</param>
        /// <param name="dt">The timestep.</param>
        /// <returns>The selected point.</returns>
        public Point Select(Tracker tracker, Point position, Esp esp, bool aim, double dt)
        {
            // If we don't want to select a target (e.g. the aim key is not depressed), then cancel
            // any existing tracking.
            if (aim == false)
            {
                Clear();
                return(Point.Empty);
            }

            time += dt;

            // Are we currently tracking an object?
            if (targetId > 0)
            {
                // Look in the list of active objects.
                foreach (var obj in tracker.Active)
                {
                    if (obj.Id == targetId)
                    {
                        if (time <= MaximumActiveSelectionTime)
                        {
                            var point = Select(obj, position);
                            Render(point, esp);
                            lost = false;
                            return(point);
                        }
                        else
                        {
                            // Select a new target.
                            time     = 0.0;
                            targetId = 0;
                            lost     = false;
                            break;
                        }
                    }
                }

                // Couldn't find the object.
                // Reset the time so that we don't immediately reselect a new target.
                if (lost == false)
                {
                    time = 0.0;
                    lost = true;
                }
            }

            // Can we select a new target.
            if (time >= MinimumReselectionTime)
            {
                // Select a new target.
                // We select the closest active object.
                targetId = 0;
                lost     = false;
                var distanceSq = double.MaxValue;
                var target     = Point.Empty;
                foreach (var obj in tracker.Active)
                {
                    if (obj.Detection.Confidence >= MinimumSelectionConfidence)
                    {
                        if (Select(obj, position, ref distanceSq, ref target))
                        {
                            targetId = obj.Id;
                        }
                    }
                }

                // Did we select a new target?
                if (targetId > 0)
                {
                    // Reset the timer.
                    time = 0.0;

                    // Render.
                    Render(target, esp);

                    // Return the selected target.
                    return(target);
                }
            }

            // We must wait before selecting another target.
            return(Point.Empty);
        }
コード例 #16
0
        // Example:
        //
        //   eax=7ffdb000 ebx=00000000 ecx=00000000 edx=7785f17d esi=00000000 edi=00000000
        //   eip=777f410c esp=040ef770 ebp=040ef79c iopl=0         nv up ei pl zr na pe nc
        //   cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000246
        //   ntdll!DbgBreakPoint:
        //
        public override ColorString ToColorString()
        {
            if (null == m_colorString)
            {
                ConsoleColor color;
                ColorString  cs = new ColorString("eax=");
                color = GetColorForDiffAgainstBaseline("eax");
                cs.Append(Eax.GetColorizedValueString(color));
                cs.Append(" ebx=");
                color = GetColorForDiffAgainstBaseline("ebx");
                cs.Append(Ebx.GetColorizedValueString(color));
                cs.Append(" ecx=");
                color = GetColorForDiffAgainstBaseline("ecx");
                cs.Append(Ecx.GetColorizedValueString(color));
                cs.Append(" edx=");
                color = GetColorForDiffAgainstBaseline("edx");
                cs.Append(Edx.GetColorizedValueString(color));
                cs.Append(" esi=");
                color = GetColorForDiffAgainstBaseline("esi");
                cs.Append(Esi.GetColorizedValueString(color));
                cs.Append(" edi=");
                color = GetColorForDiffAgainstBaseline("edi");
                cs.Append(Edi.GetColorizedValueString(color));
                cs.AppendLine();

                cs.Append("eip=");
                color = GetColorForDiffAgainstBaseline("eip");
                cs.Append(Eip.GetColorizedValueString(color));
                cs.Append(" esp=");
                color = GetColorForDiffAgainstBaseline("esp");
                cs.Append(Esp.GetColorizedValueString(color));
                cs.Append(" ebp=");
                color = GetColorForDiffAgainstBaseline("ebp");
                cs.Append(Ebp.GetColorizedValueString(color));
                cs.Append(" iopl=");
                color = GetColorForDiffAgainstBaseline("iopl");
                cs.AppendPushPopFg(color, ((uint)Iopl.Value).ToString("x"));
                // TODO:
                cs.AppendLine("   TBD: flags");

                cs.Append("cs=");
                color = GetColorForDiffAgainstBaseline("cs");
                cs.AppendPushPopFg(color, ((uint)Cs.Value).ToString("x4"));
                cs.Append("  ss=");
                color = GetColorForDiffAgainstBaseline("ss");
                cs.AppendPushPopFg(color, ((uint)Ss.Value).ToString("x4"));
                cs.Append("  ds=");
                color = GetColorForDiffAgainstBaseline("ds");
                cs.AppendPushPopFg(color, ((uint)Ds.Value).ToString("x4"));
                cs.Append("  es=");
                color = GetColorForDiffAgainstBaseline("es");
                cs.AppendPushPopFg(color, ((uint)Es.Value).ToString("x4"));
                cs.Append("  fs=");
                color = GetColorForDiffAgainstBaseline("fs");
                cs.AppendPushPopFg(color, ((uint)Fs.Value).ToString("x4"));
                cs.Append("  gs=");
                color = GetColorForDiffAgainstBaseline("gs");
                cs.AppendPushPopFg(color, ((uint)Gs.Value).ToString("x4"));
                cs.Append("             efl=");
                color = GetColorForDiffAgainstBaseline("efl");
                cs.Append(Efl.GetColorizedValueString(color));
                cs.AppendLine();

                cs.Append(DbgProvider.ColorizeSymbol(StackFrame.SymbolName));
                if (0 != StackFrame.Displacement)
                {
                    cs.Append("+0x");
                    cs.Append(StackFrame.Displacement.ToString("x"));
                }
                cs.AppendLine(":");
                cs.Append(Disasm(Eip.ValueAsPointer));

                m_colorString = cs;
            }
            return(m_colorString);
        } // end ToString()