Jump to content

The development of a completely human-like mouse algorithm


Dreamliner

Recommended Posts

Hey everyone, @NotoriousPP and I are collaboratively producing scripts together. We're focused on bringing out the most human like scripts possible. To do this, we need to collect data of how a normal person uses the mouse. The things we are collecting in the following project will support our effort to create a mouse controller which behaves precisely how a human thinks.

I have developed a script which can be run through OSBot which will record position of your mouse every 25 milliseconds (subject to change). During this time period, metrics of how the mouse is behaving are calculated. These calculations include:

  • Distance from previous point
  • Average velocity from previous point to current location
  • Average acceleration from previous point to current location
  • Elapsed time from previous data entry

Aside from these calculations, I have a machine of higher computing power which I can calculate angle deviation, as well as, other very important characteristics of how the mouse is moving.
 
This is the point where we ask for your help!
 
Below you can download the script mentioned previously.  The script outputs a *.csv (comma separated values) file to the directory of (c:\Users\YOURNAME\Documents\DreamlinerMouseData)

 

Please leave the recorder on for between 60-120 seconds each time.  Try to do something normal in the game like fighting monsters or skilling.
 
When you have run your tests, please upload these files (new file for each test) to http://goo.gl/S3O0Ri
 
These tests are completely anonymous and no strange data will be collected, with or without your knowledge.
 
Below you can find my source code.
 
Thank you for everyone who contributes the data to us.  It will help us greatly and keep YOU from getting banned!
 
Download the script here: http://goo.gl/PD1rZQ
Upload your data here: http://goo.gl/S3O0Ri

package scripts;
 
import api.utils.RecordMouse;
import api.methods.mouse.data.MouseData;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
 
import java.awt.*;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
 
/**
 * Created by Dreamliner on 6/3/2014.
 */
@ScriptManifest(name = "Mouse Recorder", author = "Dreamliner", version = 1.0, info = "records mouse movements and saves them to csv file", logo = "")
 
public class MouseRecorder extends Script {
 
    private RecordMouse recordMouse = new RecordMouse(this);
    private Thread mouseThread = new Thread(recordMouse);
 
 
    private boolean init = false;
 
    @Override
    public void onStart() throws InterruptedException {
        super.onStart();
    }
 
    @Override
    public int onLoop() throws InterruptedException {
        if (!init) {
            this.bot.setHumanInputEnabled(true);
            mouseThread.start();
            init = true;
        }
        System.out.println("Mouse Data Array Size: " + recordMouse.getMdSize());
        return 1000;
    }
 
    @Override
    public void onPaint(Graphics2D g) {
 
    }
 
    @Override
    public void onExit() {
        try {
            File path = new File("C:/Users/" + System.getProperty("user.name") + "/Documents/DreamlinerMouseData/");
            if (!path.exists()) {
                path.mkdirs();
            }
            File f = new File("C:/Users/" + System.getProperty("user.name") + "/Documents/DreamlinerMouseData/" + System.currentTimeMillis() + ".csv");
            FileWriter fw = new FileWriter(f);
            fw.append("Absolute Time,Elapsed Time,X,Y,Distance from previous,Avg Velocity, Avg Acceleration");
            fw.append('\n');
            for (MouseData md : recordMouse.getMdList()) {
                fw.append(Integer.toString(md.getAbsTime()));
                fw.append(',');
                fw.append(Integer.toString(md.getTime()));
                fw.append(',');
                fw.append(Integer.toString(md.getX()));
                fw.append(',');
                fw.append(Integer.toString(md.getY()));
                fw.append(',');
                fw.append(Double.toString(md.getLocalDistance()));
                fw.append(',');
                fw.append(Double.toString(md.getVelocity()));
                fw.append(',');
                fw.append(Double.toString(md.getAcceleration()));
                fw.append('\n');
            }
            fw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
 
        recordMouse.kill();
    }
}
package api.utils;

import api.methods.mouse.data.MouseData;
import org.osbot.rs07.script.Script;

import java.awt.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Dreamliner on 6/3/2014.
 */
public class RecordMouse implements Runnable {
    private boolean run = false;
    private Script script;
    private List<MouseData> mdList = new ArrayList<>();

    private long previousTime = 0;
    private long startTime = System.currentTimeMillis();

    private int sleepTime = 25; // ms

    public RecordMouse(Script s) {
        run = true;
        script = s;
    }

    @Override
    public void run() {
        while (run) {
            Point p = script.mouse.getPosition();
            if (getMdList() != null && !getMdList().isEmpty()) {
                MouseData lastMD = getLastMd();

                double distance = getDistanceBetweenTwoPoints(p, lastMD.getP());
                int time = (int) (System.currentTimeMillis() - previousTime);
                previousTime = System.currentTimeMillis();
                double velocity = Math.abs(lastMD.getLocalDistance() - distance) / (time / 1000D);
                double acceleration = (velocity - lastMD.getVelocity()) / (time / 1000D);
                if (distance >= 150 || getLastMd().getX() == -1 || p.getX() == -1) {
                    velocity = 0D;
                    acceleration = 0D;
                }
                if (getLastMd().getLocalDistance() >= 150) {
                    velocity = 0D;
                    acceleration = 0D;
                }
                if (getLastMd().getAcceleration() == 0 && getLastMd().getVelocity() == 0 && p.equals(lastMD.getP())) {
                    previousTime = System.currentTimeMillis();
                } else {
                    int absTime = (int) (System.currentTimeMillis() - startTime);
                    pushMdList(new MouseData(p, velocity, acceleration, distance, time, absTime));
                }
            } else {
                previousTime = System.currentTimeMillis();
                int absTime = (int) (System.currentTimeMillis() - startTime);
                pushMdList(new MouseData(p, 0, 0, 0, 0, absTime));
            }
            try {
                Thread.sleep(sleepTime);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public void kill() {
        run = false;
    }

    public List<MouseData> getMdList() {
        return mdList;
    }

    public void setMdList(List<MouseData> mdList) {
        this.mdList = mdList;
    }

    public void pushMdList(MouseData md) {
        mdList.add(md);
    }

    public MouseData getLastMd() {
        return mdList.get(mdList.size() - 1);
    }

    public double getDistanceBetweenTwoPoints(Point a, Point b) {
        return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
    }

    public int getMdSize() {
        int r = 0;
        if (mdList != null && !mdList.isEmpty()) {
            r = mdList.size();
        }
        return r;
    }
}
package api.methods.mouse.data;

import java.awt.*;

/**
 * Created by Dreamliner on 6/3/2014.
 */
public class MouseData {
    private Point p;
    private int x;
    private int y;
    private double velocity;
    private double acceleration;
    private double localDistance;
    private int time;
    private int absTime;

    public MouseData(Point p, double v, double a, double d, int time, int absTime) {
        setP(p);
        setX(p.x);
        setY(p.y);
        setVelocity(v);
        setAcceleration(a);
        setLocalDistance(d);
        setTime(time);
        setAbsTime(absTime);
    }

    public double getVelocity() {
        return velocity;
    }

    public void setVelocity(double velocity) {
        this.velocity = velocity;
    }

    public double getAcceleration() {
        return acceleration;
    }

    public void setAcceleration(double acceleration) {
        this.acceleration = acceleration;
    }

    public double getLocalDistance() {
        return localDistance;
    }

    public void setLocalDistance(double localDistance) {
        this.localDistance = localDistance;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public Point getP() {
        return p;
    }

    public void setP(Point p) {
        this.p = p;
    }

    public int getTime() {
        return time;
    }

    public void setTime(int time) {
        this.time = time;
    }

    public int getAbsTime() {
        return absTime;
    }

    public void setAbsTime(int absTime) {
        this.absTime = absTime;
    }
}
Edited by dreamliner
  • Like 3
Link to comment
Share on other sites

Two brilliant programmers designing a mouse algorithm. Goodluck boys and remember to open source it (or at least give to @Swizzbeat) when you're all done wink.png

 

A mouse algorithm is more than move mouse to point B from A ;) It's largely dependent of how well it's implemented into the script.  How often does the mouse stand still in average scripts? Quite a bit. For a human, besides typing, the mouse is ALWAYS moving. (except for laptops sometimes). So what we're developing will have to be run in a separate thread, which will act like a human. We'll keep you updated :P

  • Like 1
Link to comment
Share on other sites

A mouse algorithm is more than move mouse to point B from A wink.png It's largely dependent of how well it's implemented into the script.  How often does the mouse stand still in average scripts? Quite a bit. For a human, besides typing, the mouse is ALWAYS moving. (except for laptops sometimes). So what we're developing will have to be run in a separate thread, which will act like a human. We'll keep you updated tongue.png

 

pls... give it to me...

getting banned since 08' I deserve it...

XD

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...