Jump to content

AntiBan Class


Deathimminent

Recommended Posts

I haven't been able to test anything, as I wrote this while the client is currently down. It works based on a weight system. Each action has a specific weight. The higher the weight, the more likely that action is to be performed. I only made 3 actions, but it's very simple to implement your own. Feedback is welcome. 

Adding your own action:

Say you want to add an action to...check your woodcutting exp. You would add to the Action enum constants the name of the action and the default weight, like such:

public enum Action {
    MOVE_MOUSE(3),
    ROTATE_CAMERA(7),
    RIGHT_CLICK_RANDOM_OBJECT(1),
    CHECK_WC_EXP(60); // <---------

    int weight;

    Action(int weight) {
        this.weight = weight;
    }

    public int getWeight() {
        return weight;
    }

    public void setWeight(int weight) {
        this.weight = weight;
    }
}

Then you would add your method that performs the action to the switch statement in the execute() method, like so:

switch (action) {
    case MOVE_MOUSE:
        script.log("[ANTI BAN:] Moving mouse.");
        moveMouseRandomly();
        break;
    case ROTATE_CAMERA:
	    script.log("[ANTI BAN:] Rotating camera.");
	    rotateCameraRandomly();
	    break;
    case RIGHT_CLICK_RANDOM_OBJECT:
	    script.log("[ANTI BAN:] Right-clicking an object");
	    rightClickRandomObject();
	    break;
    case CHECK_WC_EXP:
	    script.log("[ANTI BAN:] Good luck JAGEX");
	    checkWcExp();
	    break;
}

 

Basic usage:

import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(author = "", info = "", logo = "", name = "Test", version = 0.1)
public class Test extends Script {
    
    AntiBan antiban = new AntiBan(this, 30000, 180000);

    @Override
    public int onLoop() throws InterruptedException {
        
        if (antiban.shouldExecute()) {
            antiban.execute();
        }
        
        return 500;
    }

}

Using a custom action list:

import java.util.ArrayList;
import java.util.List;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import test.AntiBan.Action;

@ScriptManifest(author = "", info = "", logo = "", name = "Test", version = 0.1)
public class Test extends Script {
    
    AntiBan antiban;

    @Override
    public void onStart() {

        List<Action> actionList = new ArrayList<>();
        
        // create an action with default weight
        Action action1 = Action.MOVE_MOUSE;
        
        // create an action and change its weight
        Action action2 = Action.ROTATE_CAMERA;
        action2.setWeight(20);
        
        // add actions to list
        actionList.add(action1);
        actionList.add(action2);
        
        // create antiban object with custom action list
        antiban = new AntiBan(this, 30000, 180000, actionList);
    }

    @Override
    public int onLoop() throws InterruptedException {

        if (antiban.shouldExecute()) {
            antiban.execute();
        }

        return 500;
    }

}

Source:

Spoiler

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.osbot.rs07.api.model.RS2Object;
import static org.osbot.rs07.script.MethodProvider.random;
import org.osbot.rs07.script.Script;

public class AntiBan {

    private final Script script;

    private int minActionBound = 0; // minimum time between actions
    private int maxActionBound = 0; // maximum time between actions
    private long nextExecuteTime;

    private List<Action> defaultActions = Arrays.asList(Action.values());

    List<Action> actionList = new ArrayList<>();

    /**
     * Creates the object with all default actions to be performed.
     *
     * @param script script reference
     * @param minActionBound minimum delay between anti ban actions
     * @param maxActionBound maximum delay between anti ban actions
     */
    public AntiBan(Script script, int minActionBound, int maxActionBound) {
        this(script, minActionBound, maxActionBound, Arrays.asList(Action.values()));
    }

    /**
     * Actions must be added manually.
     *
     * @param script script reference
     * @param minActionBound minimum delay between anti ban actions
     * @param maxActionBound maximum delay between anti ban actions
     * @param actions the actions that should be performed
     */
    public AntiBan(Script script, int minActionBound, int maxActionBound, List<Action> actions) {
        this.script = script;
        this.minActionBound = minActionBound;
        this.maxActionBound = maxActionBound;
        nextExecuteTime = System.currentTimeMillis() + random(minActionBound, maxActionBound);
        actionList = actions;
    }

    /**
     * @return true if it's time to perform an action
     */
    public boolean shouldExecute() {
        return (System.currentTimeMillis() > nextExecuteTime);
    }

    public long getNextExecuteTime() {
        return nextExecuteTime;
    }

    /**
     * Performs a random action from the action list based off of the weighted
     * values.
     *
     * How it works: Creates an array the size of the cumulative weight
     * of the action list and then loops through the action list assigning each
     * index the value of the enum value. Then chooses a random number
     * 0-arrayLength to get the action to perform.
     */
    public void execute() {
        if (actionList.size() > 0) {
            // calcualte the cumulative weight of the action list
            int cumulativeWeight = 0;
            for (Action action : actionList) {
                cumulativeWeight += action.getWeight();
            }

            // for every action in the action list, add one slot to wheel per weight
            int[] wheel = new int[cumulativeWeight];
            int index = 0; // keep track of last index

            for (int i = 0; i < actionList.size(); i++) {
                int numSlots = actionList.get(i).getWeight();
                while (numSlots-- > 0) {
                    wheel[index++] = actionList.get(i).ordinal();
                }
            }

            // get an action from a random slot
            int actionOrdinal = wheel[random(0, wheel.length) - 1];
            Action action = Action.values()[actionOrdinal];

            // perform the action
            switch (action) {
                case MOVE_MOUSE:
                    script.log("[ANTI BAN:] Moving mouse.");
                    moveMouseRandomly();
                    break;
                case ROTATE_CAMERA:
                    script.log("[ANTI BAN:] Rotating camera.");
                    rotateCameraRandomly();
                    break;
                case RIGHT_CLICK_RANDOM_OBJECT:
                    script.log("[ANTI BAN:] Right-clicking an object");
                    rightClickRandomObject();
                    break;
            }

            // set the next execute time
            nextExecuteTime = System.currentTimeMillis() + random(minActionBound, maxActionBound);
        }
    }

    public void addAction(Action a) {
        actionList.add(a);
    }

    /**
     * @param a the action to add
     * @param weight likeliness of this action to be performed
     */
    public void addAction(Action a, int weight) {
        Action action = a;
        action.setWeight(weight);
        actionList.add(action);
    }

    /**
     * Adds an occurrence of all Actions to the action list
     */
    public void addAllActions() {
        actionList = defaultActions;
    }

    public void clearActions() {
        actionList.clear();
    }

    /**
     * Each action is weighted. Meaning the higher the weight, the more likely
     * that action is to be performed. If two actions have the same weight, they
     * are equally likely to be performed.<br><br>
     *
     *
     * Default weights<br>
     * ------------------------<br>
     * Move mouse: 3<br>
     * Rotate camera: 7<br>
     * Right click object: 1
     */
    public enum Action {
        MOVE_MOUSE(3),
        ROTATE_CAMERA(7),
        RIGHT_CLICK_RANDOM_OBJECT(1);

        int weight;

        Action(int weight) {
            this.weight = weight;
        }

        public int getWeight() {
            return weight;
        }

        public void setWeight(int weight) {
            this.weight = weight;
        }
    }

    /////////////////////////////
    //     Helper methods      //
    /////////////////////////////
    private void moveMouse() {
        script.getMouse().move(random(43, 538), random(47, 396));
    }

    /////////////////////////////
    //  Methods for execution  //
    /////////////////////////////
    public void moveMouseRandomly() {
        script.getMouse().move(random(43, 538), random(47, 396));
    }

    public void rotateCameraRandomly() {
        script.getCamera().movePitch(random(script.getCamera().getLowestPitchAngle(), 67));
        script.getCamera().moveYaw(random(0, 359));
    }

    /**
     * Right clicks a random visible object and then moves mouse to close the
     * menu.
     */
    public void rightClickRandomObject() {
        List<RS2Object> visibleObjs = script.getObjects().getAll().stream().filter(o -> o.isVisible()).collect(Collectors.toList());

        // select a random object
        int index = random(0, visibleObjs.size() - 1);
        RS2Object obj = visibleObjs.get(index);

        if (obj != null) {
            // hover the object and right click
            obj.hover();
            script.getMouse().click(true);

            // while the menu is still open, move the mouse to a new location
            while (script.getMenuAPI().isOpen()) {
                moveMouse();
            }
        }
    }

}

 

 

Edited by Deathiminent
source code edits
Link to comment
Share on other sites

4 minutes ago, Raccoon Hunter said:

well then tell them the truth, even alek said antiban is shit

 

good antiban is writing a good script

Well, it's not "truth", as we don't have any proof that anti ban is useless. Everyone has their own beliefs about it. I personally don't think it matters, but if someone is paying me to write a script for them and anti ban implementation is one of their specifications, then I'll add it.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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