Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!

Resource Simple Mouse Target Renderer for debugging

Joined
Jun 21, 2014
Messages
350
This version doesn't block your bot from interacting, but you can override the path generator move function to do nothing to do so.

See an example of this working here:

WFcaCPIiCt

Code:
/* Originally written by ? and shared by Swatarianess
* Modified by Furor June 2020
* Renders the current and previous target interaction box in the background
* Issues: Currently does not close created windows on generation
*/

package transfer;

import com.runemate.game.api.hybrid.Environment;
import com.runemate.game.api.hybrid.entities.details.Interactable;
import com.runemate.game.api.hybrid.entities.details.Modeled;
import com.runemate.game.api.hybrid.entities.details.Renderable;
import com.runemate.game.api.hybrid.input.Mouse;
import com.runemate.game.api.hybrid.local.Screen;
import com.runemate.game.api.hybrid.local.hud.InteractablePoint;
import com.runemate.game.api.hybrid.local.hud.InteractableRectangle;
import com.runemate.game.api.hybrid.local.hud.InteractableShape;
import com.runemate.game.api.hybrid.local.hud.Model;
import com.runemate.game.api.script.framework.AbstractBot;
import com.runemate.game.api.script.framework.core.LoopingThread;
import javafx.application.Platform;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

import java.awt.*;
import java.util.concurrent.Future;

public class RenderMouseTargets extends Stage {
    private String id;
    private Canvas pane;
    private GraphicsContext graphics;
    private InteractableRectangle bounds;
    private InteractablePoint location;
    private Future<?> renderLoop;

    //invoke manually in onStop to close the screen generated with your bot
    public void stop(){
        renderLoop.cancel(false);
        Platform.runLater(() -> {
                    this.close();
                }
        );
    }

    public Future<?> getRenderLoop() {
        return renderLoop;
    }

    //1 prev, 2 next
    private Renderable[] renderModels = new Renderable[2];

    public RenderMouseTargets(AbstractBot bot) {
        pane = new Canvas();

        Scene scene = new Scene(new Group(pane));
        setScene(scene);

        graphics = pane.getGraphicsContext2D();

        graphics.setLineWidth(1);
        graphics.setStroke(Color.RED);

        this.renderLoop = (bot.getPlatform().invokeLater(() -> new LoopingThread(() -> {
            bounds = Screen.getBounds();
            location = Screen.getLocation();

            //move with window
            if (bounds != null && location != null) {
                Platform.runLater(() -> {
                    setX(location.x);
                    setY(location.y);
                    pane.setWidth(bounds.width);
                    pane.setHeight(bounds.width);
                    setWidth(bounds.width);
                    setHeight(bounds.height);
                });
            }
            renderModels();
        }, 100).start()));

        //can be used for visibility
        bot.getPlatform().invokeLater(() -> id = Environment.getRuneScapeProcessId());

        setAlwaysOnTop(true);

        initStyle(StageStyle.TRANSPARENT);

        scene.setFill(null);

        show();
    }

    private void renderModels() {
        Interactable [] targs = new Interactable[]{ Mouse.getPreviousTarget(), Mouse.getTarget() };

        for(int i = 0; i < targs.length; i++){
            Interactable target = targs[i];

            //Should typically be modeled
            if(target instanceof Modeled){
                Model model = ((Modeled) target).getModel();
                if(model != null){
                    //Interaction area
                    Polygon hull = model.projectConvexHull();
                    if(hull != null){
                        renderModels[i] = new InteractableShape(hull);
                    } else {
                        renderModels[i] = null;
                    }
                } else {
                    renderModels[i] = null;
                }
            } else if (target instanceof Renderable) {
                renderModels[i] = (Renderable)target;
            } else {
                renderModels[i] = null;
            }
        }

        try {
            graphics = pane.getGraphicsContext2D();
            if (graphics != null) {
                Canvas canvas = graphics.getCanvas();
                double width = canvas.getWidth();
                double height = canvas.getHeight();
                if (width > 0 && height > 0) {
                    //canvas is now 1920 * 1080, so it works.
                    graphics.clearRect(0, 0, width, height);
                    if(renderModels[0] != null){
                        graphics.setStroke(Color.BLUE);
                        renderModels[0].render(graphics);
                    }
                    if(renderModels[1] != null){
                        graphics.setStroke(Color.RED);
                        renderModels[1].render(graphics);
                    }
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

Example use:

Code:
package transfer;

import com.runemate.game.api.hybrid.entities.GameObject;
import com.runemate.game.api.hybrid.input.Mouse;
import com.runemate.game.api.hybrid.region.GameObjects;
import com.runemate.game.api.script.framework.LoopingBot;
import javafx.application.Platform;


public class SelectRandomTarget extends LoopingBot {
    @Override
    public void onStart(String... arguments) {
        Platform.runLater(() -> new RenderMouseTargets(this));
    }

    @Override
    public void onLoop() {
        GameObject rand = GameObjects.newQuery().names("Bank booth").visible().results().random();
        if(rand != null && rand.isVisible()){
            Mouse.move(rand);
        }
    }
}
 
Top