Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Modified WindMouse with customized Bézier curves and overshooting for human like movement


    Deep Slayer

    Recommended Posts

     

    import org.dreambot.api.input.Mouse;
    import org.dreambot.api.input.event.impl.mouse.MouseButton;
    import org.dreambot.api.input.mouse.algorithm.MouseAlgorithm;
    import org.dreambot.api.input.mouse.destination.AbstractMouseDestination;
    import org.dreambot.api.methods.Calculations;
    import org.dreambot.api.utilities.Logger;
    
    import java.awt.*;
    import java.util.Random;
    
    /**
     * Modified WindMouse with customized Bézier curves and overshooting for human like movement
     */
    public class WindMouseCustom implements MouseAlgorithm {
        private Random random = new Random();
    
        @Override
        public boolean handleMovement(AbstractMouseDestination abstractMouseDestination) {
            Point suitPos = abstractMouseDestination.getSuitablePoint();
            mouseMovement(suitPos);
            return distance(Mouse.getPosition(), suitPos) < 2;
        }
    
        @Override
        public boolean handleClick(MouseButton mouseButton) {
            return Mouse.getDefaultMouseAlgorithm().handleClick(mouseButton);
        }
    
        public static void sleep(int min, int max) {
            try {
                Thread.sleep(Calculations.random(min, max));
            } catch (InterruptedException e) {
                Logger.log(e.getMessage());
            }
        }
    
        public static void sleep(int ms) {
            try {
                Thread.sleep(ms);
            } catch (InterruptedException e) {
                Logger.log(e.getMessage());
            }
        }
    
        /**
         * enhanced mouse movement using Bézier curves for smooth, human like pathing
         *
         * @param point The destination point
         */
        public void mouseMovement(Point point) {
            Point curPos = Mouse.getPosition();
            boolean shouldOvershoot = random.nextBoolean(); // Random chance to overshoot
    
            if (shouldOvershoot) {
                Point overshootPoint = getOvershootPoint(curPos, point);
                moveMouseBezier(curPos, overshootPoint); // First move to the overshoot point
                moveMouseBezier(overshootPoint, point); // Then correct to the target point
            } else {
                moveMouseBezier(curPos, point); // Directly move to the target point
            }
        }
    
        /**
         * Generate control points for Bezier curve
         *
         * @param start The start point
         * @param end   The end point
         * @return Array of control points
         */
        private Point[] generateControlPoints(Point start, Point end) {
            Point[] controlPoints = new Point[4];
            controlPoints[0] = start;
            controlPoints[3] = end;
    
            int midX = (start.x + end.x) / 2;
            int midY = (start.y + end.y) / 2;
    
            controlPoints[1] = new Point(midX + random.nextInt(100) - 50, midY + random.nextInt(100) - 50);
            controlPoints[2] = new Point(midX + random.nextInt(100) - 50, midY + random.nextInt(100) - 50);
    
            return controlPoints;
        }
    
        /**
         * Move mouse using a Bezier curve
         *
         * @param start The start point
         * @param end   The end point
         */
        private void moveMouseBezier(Point start, Point end) {
            Point[] controlPoints = generateControlPoints(start, end);
            int steps = Calculations.random(30, 50); // Increase steps for smoother curves
    
            for (int i = 0; i <= steps; i++) {
                double t = (double) i / (double) steps;
                int x = (int) (Math.pow(1 - t, 3) * controlPoints[0].x +
                        3 * Math.pow(1 - t, 2) * t * controlPoints[1].x +
                        3 * (1 - t) * Math.pow(t, 2) * controlPoints[2].x +
                        Math.pow(t, 3) * controlPoints[3].x);
                int y = (int) (Math.pow(1 - t, 3) * controlPoints[0].y +
                        3 * Math.pow(1 - t, 2) * t * controlPoints[1].y +
                        3 * (1 - t) * Math.pow(t, 2) * controlPoints[2].y +
                        Math.pow(t, 3) * controlPoints[3].y);
    
                Mouse.hop(new Point(x, y));
    
                try {
                    Thread.sleep(Calculations.random(5, 15));
                } catch (InterruptedException e) {
                    Logger.log(e.getMessage());
                }
            }
        }
    
        /**
         * Calculate an overshoot point past the target for more human like behavior
         *
         * @param start The start point
         * @param end   The end point
         * @return The overshoot point
         */
        private Point getOvershootPoint(Point start, Point end) {
            int overshootDistance = 30 + random.nextInt(31); // Random overshoot between 30 and 60 pixels
            double angle = Math.atan2(end.y - start.y, end.x - start.x);
    
            int overshootX = (int) (end.x + overshootDistance * Math.cos(angle));
            int overshootY = (int) (end.y + overshootDistance * Math.sin(angle));
    
            return new Point(overshootX, overshootY);
        }
    
        public double distance(Point p1, Point p2) {
            return Math.sqrt((p2.y - p1.y) * (p2.y - p1.y) + (p2.x - p1.x) * (p2.x - p1.x));
        }
    }
    
    Link to comment
    Share on other sites

    Posted (edited)

    You can customize Bezier steps and overshooting distance.. have fun,

     

    Put this in your onStart method

     

    Mouse.setMouseAlgorithm(new WindMouseCustom());
    
    Edited by Deep Slayer
    Link to comment
    Share on other sites

    • 1 month later...
    • 2 weeks later...

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.