Refactor flexo

This commit is contained in:
Scott Burns
2019-05-16 00:48:25 +02:00
parent b0194eeefd
commit 2004c3d4bf
3 changed files with 431 additions and 352 deletions

View File

@@ -29,180 +29,198 @@ import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;
@ConfigGroup("flexo")
public interface FlexoConfig extends Config {
public interface FlexoConfig extends Config
{
@ConfigItem(
position = 0,
keyName = "overlayEnabled",
name = "Overlay Enabled",
description = "Shows clicking area and points etc."
)
default boolean overlayEnabled() {
return true;
}
@ConfigItem(
position = 0,
keyName = "overlayEnabled",
name = "Overlay Enabled",
description = "Shows clicking area and points etc."
)
default boolean overlayEnabled()
{
return true;
}
@ConfigItem(
position = 1,
keyName = "minDelayAmount",
name = "Min Delay",
description = "Minimum delay that is applied to every action at the end (ms)"
)
default int minDelayAmt() {
return 45;
}
@ConfigItem(
position = 1,
keyName = "minDelayAmount",
name = "Min Delay",
description = "Minimum delay that is applied to every action at the end (ms)"
)
default int minDelayAmt()
{
return 45;
}
@ConfigItem(
position = 2,
keyName = "reactionTime",
name = "Reaction Time",
description = "The base time between actions (ms)"
)
default int getReactionTimeVariation() {
return 80;
}
@ConfigItem(
position = 2,
keyName = "reactionTime",
name = "Reaction Time",
description = "The base time between actions (ms)"
)
default int getReactionTimeVariation()
{
return 80;
}
@ConfigItem(
position = 3,
keyName = "mouseDragSpeed",
name = "Mouse drag speed",
description = "The speed at which steps are executed. Keep at 49? cuz jagex mouse recorder?"
)
default int getMouseDragSpeed() {
return 49;
}
@ConfigItem(
position = 3,
keyName = "mouseDragSpeed",
name = "Mouse drag speed",
description = "The speed at which steps are executed. Keep at 49? cuz jagex mouse recorder?"
)
default int getMouseDragSpeed()
{
return 49;
}
@ConfigItem(
position = 4,
keyName = "overshoots",
name = "Overshoots",
description = "Higher number = more overshoots"
)
default int getOvershoots() {
return 4;
}
@ConfigItem(
position = 4,
keyName = "overshoots",
name = "Overshoots",
description = "Higher number = more overshoots"
)
default int getOvershoots()
{
return 4;
}
@ConfigItem(
position = 5,
keyName = "variatingFlow",
name = "Flow - Variating",
description = ""
)
default boolean getVariatingFlow() {
return true;
}
@ConfigItem(
position = 5,
keyName = "variatingFlow",
name = "Flow - Variating",
description = ""
)
default boolean getVariatingFlow()
{
return true;
}
@ConfigItem(
position = 6,
keyName = "slowStartupFlow",
name = "Flow - Slow startup",
description = ""
)
default boolean getSlowStartupFlow() {
return true;
}
@ConfigItem(
position = 6,
keyName = "slowStartupFlow",
name = "Flow - Slow startup",
description = ""
)
default boolean getSlowStartupFlow()
{
return true;
}
@ConfigItem(
position = 7,
keyName = "slowStartup2Flow",
name = "Flow - Slow startup 2",
description = ""
)
default boolean getSlowStartup2Flow() {
return true;
}
@ConfigItem(
position = 7,
keyName = "slowStartup2Flow",
name = "Flow - Slow startup 2",
description = ""
)
default boolean getSlowStartup2Flow()
{
return true;
}
@ConfigItem(
position = 8,
keyName = "jaggedFlow",
name = "Flow - Jagged",
description = ""
)
default boolean getJaggedFlow() {
return true;
}
@ConfigItem(
position = 8,
keyName = "jaggedFlow",
name = "Flow - Jagged",
description = ""
)
default boolean getJaggedFlow()
{
return true;
}
@ConfigItem(
position = 9,
keyName = "interruptedFlow",
name = "Flow - Interrupted",
description = ""
)
default boolean getInterruptedFlow() {
return false;
}
@ConfigItem(
position = 9,
keyName = "interruptedFlow",
name = "Flow - Interrupted",
description = ""
)
default boolean getInterruptedFlow()
{
return false;
}
@ConfigItem(
position = 10,
keyName = "interruptedFlow2",
name = "Flow - Interrupted 2",
description = ""
)
default boolean getInterruptedFlow2() {
return false;
}
@ConfigItem(
position = 10,
keyName = "interruptedFlow2",
name = "Flow - Interrupted 2",
description = ""
)
default boolean getInterruptedFlow2()
{
return false;
}
@ConfigItem(
position = 11,
keyName = "stoppingFlow",
name = "Flow - Stopping",
description = ""
)
default boolean getStoppingFlow() {
return false;
}
@ConfigItem(
position = 11,
keyName = "stoppingFlow",
name = "Flow - Stopping",
description = ""
)
default boolean getStoppingFlow()
{
return false;
}
@ConfigItem(
position = 12,
keyName = "deviationSlopeDivider",
name = "Deviation slope divider",
description = ""
)
default int getDeviationSlope() {
return 10;
}
@ConfigItem(
position = 12,
keyName = "deviationSlopeDivider",
name = "Deviation slope divider",
description = ""
)
default int getDeviationSlope()
{
return 10;
}
@ConfigItem(
position = 13,
keyName = "noisinessDivider",
name = "Noisiness divider",
description = ""
)
default String getNoisinessDivider() {
return "2.0D";
}
@ConfigItem(
position = 13,
keyName = "noisinessDivider",
name = "Noisiness divider",
description = ""
)
default String getNoisinessDivider()
{
return "2.0D";
}
@ConfigItem(
position = 14,
keyName = "debugNPCs",
name = "Debug NPCs",
description = "Draws clickArea and clickPoints across all visible npcs"
)
default boolean getDebugNPCs() {
return false;
}
@ConfigItem(
position = 14,
keyName = "debugNPCs",
name = "Debug NPCs",
description = "Draws clickArea and clickPoints across all visible npcs"
)
default boolean getDebugNPCs()
{
return false;
}
@ConfigItem(
position = 15,
keyName = "debugPlayers",
name = "Debug Players",
description = "Draws clickArea and clickPoints across all visible players"
)
default boolean getDebugPlayers() {
return false;
}
@ConfigItem(
position = 15,
keyName = "debugPlayers",
name = "Debug Players",
description = "Draws clickArea and clickPoints across all visible players"
)
default boolean getDebugPlayers()
{
return false;
}
@ConfigItem(
position = 16,
keyName = "debugGroundItems",
name = "Debug Ground Items",
description = "Draws clickArea and clickPoints across all visible ground items"
)
default boolean getDebugGroundItems() {
return false;
}
@ConfigItem(
position = 16,
keyName = "debugGroundItems",
name = "Debug Ground Items",
description = "Draws clickArea and clickPoints across all visible ground items"
)
default boolean getDebugGroundItems()
{
return false;
}
}

View File

@@ -27,66 +27,74 @@
package net.runelite.client.plugins.flexo;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.Line2D;
import java.util.ArrayList;
import javax.annotation.Nullable;
import javax.inject.Inject;
import net.runelite.api.Client;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition;
import javax.annotation.Nullable;
import javax.inject.Inject;
import java.awt.*;
import java.awt.geom.Line2D;
import java.util.ArrayList;
public class FlexoOverlay extends Overlay
{
private static Rectangle clickArea;
public class FlexoOverlay extends Overlay {
ArrayList<Rectangle> clickAreas = new ArrayList<>();
ArrayList<Point> clickPoints = new ArrayList<>();
public static Rectangle clickArea;
public ArrayList<Rectangle> clickAreas = new ArrayList<>();
public ArrayList<Point> clickPoints = new ArrayList<>();
@Inject
private FlexoConfig config;
@Inject
private Client client;
@Inject
private FlexoPlugin plugin;
@Inject
private FlexoConfig config;
@Inject
public FlexoOverlay(@Nullable Client client, FlexoPlugin plugin, FlexoConfig config) {
setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.ABOVE_WIDGETS);
this.client = client;
this.plugin = plugin;
this.config = config;
}
@Inject
public FlexoOverlay(FlexoConfig config)
{
setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.ABOVE_WIDGETS);
this.config = config;
}
@Override
public Dimension render(Graphics2D graphics) {
if (config.getDebugNPCs() || config.getDebugGroundItems() || config.getDebugPlayers()) {
if (clickArea!=null)
graphics.draw(clickArea);
if (clickAreas!=null) {
for (Rectangle clickArea : clickAreas) {
if (clickArea!=null)
graphics.draw(clickArea);
}
}
if (clickPoints!=null) {
for (Point p : clickPoints) {
if (p!=null) {
graphics.setColor(Color.MAGENTA);
graphics.draw(new Line2D.Double(p.x, p.y, p.x, p.y));
graphics.draw(new Line2D.Double(p.x-1, p.y-1, p.x-1, p.y-1));
graphics.draw(new Line2D.Double(p.x+1, p.y+1, p.x+1, p.y+1));
graphics.draw(new Line2D.Double(p.x-1, p.y+1, p.x-1, p.y+1));
graphics.draw(new Line2D.Double(p.x+1, p.y-1, p.x+1, p.y-1));
}
}
}
}
return null;
}
@Override
public Dimension render(Graphics2D graphics)
{
if (config.getDebugNPCs() || config.getDebugGroundItems() || config.getDebugPlayers())
{
if (clickArea != null)
{
graphics.draw(clickArea);
}
if (clickAreas != null)
{
for (Rectangle clickArea : clickAreas)
{
if (clickArea != null)
{
graphics.draw(clickArea);
}
}
}
if (clickPoints != null)
{
for (Point p : clickPoints)
{
if (p != null)
{
graphics.setColor(Color.MAGENTA);
graphics.draw(new Line2D.Double(p.x, p.y, p.x, p.y));
graphics.draw(new Line2D.Double(p.x - 1, p.y - 1, p.x - 1, p.y - 1));
graphics.draw(new Line2D.Double(p.x + 1, p.y + 1, p.x + 1, p.y + 1));
graphics.draw(new Line2D.Double(p.x - 1, p.y + 1, p.x - 1, p.y + 1));
graphics.draw(new Line2D.Double(p.x + 1, p.y - 1, p.x + 1, p.y - 1));
}
}
}
}
return null;
}
}

View File

@@ -35,6 +35,11 @@ import com.github.joonasvali.naturalmouse.support.Flow;
import com.github.joonasvali.naturalmouse.support.SinusoidalDeviationProvider;
import com.github.joonasvali.naturalmouse.util.FlowTemplates;
import com.google.inject.Provides;
import java.awt.AWTException;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import net.runelite.api.Client;
import net.runelite.api.NPC;
import net.runelite.api.Perspective;
@@ -42,7 +47,6 @@ import net.runelite.api.Player;
import net.runelite.api.coords.LocalPoint;
import net.runelite.api.events.BeforeRender;
import net.runelite.api.events.ConfigChanged;
import net.runelite.api.events.GameTick;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.flexo.Flexo;
@@ -56,178 +60,227 @@ import net.runelite.client.plugins.stretchedmode.StretchedModeConfig;
import net.runelite.client.ui.ClientUI;
import net.runelite.client.ui.overlay.OverlayManager;
import javax.inject.Inject;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
@PluginDescriptor(
name = "Flexo Config",
description = "Customizes the flexo api",
tags = {"flexo", "null"},
type = PluginType.UTILITY
name = "Flexo Config",
description = "Customizes the flexo api",
tags = {"flexo", "null"},
type = PluginType.UTILITY
)
public class FlexoPlugin extends Plugin {
public class FlexoPlugin extends Plugin
{
private Flexo flexo;
private Flexo flexo;
{
try
{
flexo = new Flexo();
}
catch (AWTException e)
{
e.printStackTrace();
}
}
{
try {
flexo = new Flexo();
} catch (AWTException e) {
e.printStackTrace();
}
}
@Inject
private Client client;
@Inject
private Client client;
@Inject
private ClientUI clientUI;
@Inject
private ClientUI clientUI;
@Inject
private ConfigManager configManager;
@Inject
private ConfigManager configManager;
@Inject
private OverlayManager overlayManager;
@Inject
private OverlayManager overlayManager;
@Inject
private FlexoOverlay overlay;
@Inject
private FlexoOverlay overlay;
@Provides
FlexoConfig getConfig(ConfigManager configManager) {
return configManager.getConfig(FlexoConfig.class);
}
@Provides
FlexoConfig getConfig(ConfigManager configManager)
{
return configManager.getConfig(FlexoConfig.class);
}
@Subscribe
private void onConfigChanged(ConfigChanged event) {
if (event.getKey().compareTo("overlayEnabled")==0) {
if (getConfig(configManager).overlayEnabled()) {
overlayManager.add(overlay);
} else {
overlayManager.remove(overlay);
}
}
updateMouseMotionFactory();
}
@Subscribe
private void onConfigChanged(ConfigChanged event)
{
if (event.getKey().compareTo("overlayEnabled") == 0)
{
if (getConfig(configManager).overlayEnabled())
{
overlayManager.add(overlay);
}
else
{
overlayManager.remove(overlay);
}
}
updateMouseMotionFactory();
}
@Subscribe
public void onBeforeRender(BeforeRender event) {
if (Flexo.client==null)
Flexo.client = client;
if (Flexo.clientUI==null)
Flexo.clientUI = clientUI;
overlay.clickAreas = new ArrayList<>();
overlay.clickPoints = new ArrayList<>();
if (getConfig(configManager).getDebugNPCs()) {
Flexo.isStretched = client.isStretchedEnabled();
Flexo.scale = configManager.getConfig(StretchedModeConfig.class).scalingFactor();
if (flexo != null)
for (NPC npc : client.getNpcs()) {
if (npc != null)
if (npc.getConvexHull() != null) {
Rectangle r = FlexoMouse.getClickArea(npc.getConvexHull().getBounds());
overlay.clickAreas.add(r);
java.awt.Point p = FlexoMouse.getClickPoint(r);
overlay.clickPoints.add(p);
}
}
}
@Subscribe
public void onBeforeRender(BeforeRender event)
{
if (Flexo.client == null)
{
Flexo.client = client;
}
if (Flexo.clientUI == null)
{
Flexo.clientUI = clientUI;
}
overlay.clickAreas = new ArrayList<>();
overlay.clickPoints = new ArrayList<>();
if (getConfig(configManager).getDebugNPCs())
{
Flexo.isStretched = client.isStretchedEnabled();
Flexo.scale = configManager.getConfig(StretchedModeConfig.class).scalingFactor();
if (flexo != null)
{
for (NPC npc : client.getNpcs())
{
if (npc != null)
{
if (npc.getConvexHull() != null)
{
Rectangle r = FlexoMouse.getClickArea(npc.getConvexHull().getBounds());
overlay.clickAreas.add(r);
java.awt.Point p = FlexoMouse.getClickPoint(r);
overlay.clickPoints.add(p);
}
}
}
}
}
if (getConfig(configManager).getDebugPlayers()) {
Flexo.isStretched = client.isStretchedEnabled();
Flexo.scale = configManager.getConfig(StretchedModeConfig.class).scalingFactor();
if (flexo != null)
for (Player player : client.getPlayers()) {
if (player != null)
if (player.getConvexHull() != null) {
Rectangle r = FlexoMouse.getClickArea(player.getConvexHull().getBounds());
overlay.clickAreas.add(r);
java.awt.Point p = FlexoMouse.getClickPoint(r);
overlay.clickPoints.add(p);
}
}
}
if (getConfig(configManager).getDebugPlayers())
{
Flexo.isStretched = client.isStretchedEnabled();
Flexo.scale = configManager.getConfig(StretchedModeConfig.class).scalingFactor();
if (flexo != null)
{
for (Player player : client.getPlayers())
{
if (player != null)
{
if (player.getConvexHull() != null)
{
Rectangle r = FlexoMouse.getClickArea(player.getConvexHull().getBounds());
overlay.clickAreas.add(r);
java.awt.Point p = FlexoMouse.getClickPoint(r);
overlay.clickPoints.add(p);
}
}
}
}
}
//Could still use some improvement
if (getConfig(configManager).getDebugGroundItems()) {
Flexo.isStretched = client.isStretchedEnabled();
Flexo.scale = configManager.getConfig(StretchedModeConfig.class).scalingFactor();
if (flexo != null)
if (GroundItemsPlugin.getCollectedGroundItems()!=null)
for (GroundItem gi : GroundItemsPlugin.getCollectedGroundItems().values()) {
if (gi != null)
if (Perspective.getCanvasTilePoly(client, LocalPoint.fromWorld(client, gi.getLocation()))!=null) {
Rectangle r1 = FlexoMouse.getClickArea(Perspective.getCanvasTilePoly(client, LocalPoint.fromWorld(client, gi.getLocation())).getBounds());
Rectangle r2 = FlexoMouse.getClickArea(r1);
Rectangle r3 = FlexoMouse.getClickArea(r2);
overlay.clickAreas.add(r3);
java.awt.Point p = FlexoMouse.getClickPoint(r3);
overlay.clickPoints.add(p);
}
}
}
}
// Could still use some improvement
if (getConfig(configManager).getDebugGroundItems())
{
Flexo.isStretched = client.isStretchedEnabled();
Flexo.scale = configManager.getConfig(StretchedModeConfig.class).scalingFactor();
@Subscribe
public void onGameTick(GameTick event) {
if (flexo != null)
{
if (GroundItemsPlugin.getCollectedGroundItems() != null)
{
for (GroundItem gi : GroundItemsPlugin.getCollectedGroundItems().values())
{
if (gi != null)
{
LocalPoint lp = LocalPoint.fromWorld(client, gi.getLocation());
if (lp != null)
{
if (Perspective.getCanvasTilePoly(client, lp) != null)
{
Rectangle r1 = FlexoMouse.getClickArea(Perspective.getCanvasTilePoly(client, lp).getBounds());
Rectangle r2 = FlexoMouse.getClickArea(r1);
Rectangle r3 = FlexoMouse.getClickArea(r2);
overlay.clickAreas.add(r3);
java.awt.Point p = FlexoMouse.getClickPoint(r3);
overlay.clickPoints.add(p);
}
}
}
}
}
}
}
}
}
private void updateMouseMotionFactory()
{
Flexo.minDelay = getConfig(configManager).minDelayAmt();
MouseMotionFactory factory = new MouseMotionFactory();
// TODO:Add Options for various flows to allow more personalization
List<Flow> flows = new ArrayList<>();
private void updateMouseMotionFactory() {
Flexo.minDelay = getConfig(configManager).minDelayAmt();
MouseMotionFactory factory = new MouseMotionFactory();
//TODO:Add Options for various flows to allow more personalization
List<Flow> flows = new ArrayList<>();
// Always add random
flows.add(new Flow(FlowTemplates.random()));
//Always add random
flows.add(new Flow(FlowTemplates.random()));
if (getConfig(configManager).getVariatingFlow())
{
flows.add(new Flow(FlowTemplates.variatingFlow()));
}
if (getConfig(configManager).getVariatingFlow())
flows.add(new Flow(FlowTemplates.variatingFlow()));
if (getConfig(configManager).getSlowStartupFlow())
{
flows.add(new Flow(FlowTemplates.slowStartupFlow()));
}
if (getConfig(configManager).getSlowStartupFlow())
flows.add(new Flow(FlowTemplates.slowStartupFlow()));
if (getConfig(configManager).getSlowStartup2Flow())
{
flows.add(new Flow(FlowTemplates.slowStartup2Flow()));
}
if (getConfig(configManager).getSlowStartup2Flow())
flows.add(new Flow(FlowTemplates.slowStartup2Flow()));
if (getConfig(configManager).getJaggedFlow())
{
flows.add(new Flow(FlowTemplates.jaggedFlow()));
}
if (getConfig(configManager).getJaggedFlow())
flows.add(new Flow(FlowTemplates.jaggedFlow()));
if (getConfig(configManager).getInterruptedFlow())
{
flows.add(new Flow(FlowTemplates.interruptedFlow()));
}
if (getConfig(configManager).getInterruptedFlow())
flows.add(new Flow(FlowTemplates.interruptedFlow()));
if (getConfig(configManager).getInterruptedFlow2())
{
flows.add(new Flow(FlowTemplates.interruptedFlow2()));
}
if (getConfig(configManager).getInterruptedFlow2())
flows.add(new Flow(FlowTemplates.interruptedFlow2()));
if (getConfig(configManager).getStoppingFlow())
{
flows.add(new Flow(FlowTemplates.stoppingFlow()));
}
if (getConfig(configManager).getStoppingFlow())
flows.add(new Flow(FlowTemplates.stoppingFlow()));
DefaultSpeedManager manager = new DefaultSpeedManager(flows);
//TODO:Add options for custom Deviation Provider and Noise Provider
factory.setDeviationProvider(new SinusoidalDeviationProvider(getConfig(configManager).getDeviationSlope()));
factory.setNoiseProvider(new DefaultNoiseProvider(Double.valueOf(getConfig(configManager).getNoisinessDivider())));
factory.getNature().setReactionTimeVariationMs(getConfig(configManager).getReactionTimeVariation());
manager.setMouseMovementBaseTimeMs(getConfig(configManager).getMouseDragSpeed());
DefaultSpeedManager manager = new DefaultSpeedManager(flows);
//TODO:Add options for custom Deviation Provider and Noise Provider
factory.setDeviationProvider(new SinusoidalDeviationProvider(getConfig(configManager).getDeviationSlope()));
factory.setNoiseProvider(new DefaultNoiseProvider(Double.valueOf(getConfig(configManager).getNoisinessDivider())));
factory.getNature().setReactionTimeVariationMs(getConfig(configManager).getReactionTimeVariation());
manager.setMouseMovementBaseTimeMs(getConfig(configManager).getMouseDragSpeed());
DefaultOvershootManager overshootManager = (DefaultOvershootManager) factory.getOvershootManager();
overshootManager.setOvershoots(getConfig(configManager).getOvershoots());
DefaultOvershootManager overshootManager = (DefaultOvershootManager) factory.getOvershootManager();
overshootManager.setOvershoots(getConfig(configManager).getOvershoots());
factory.setSpeedManager(manager);
Flexo.currentMouseMotionFactory = factory;
}
factory.setSpeedManager(manager);
Flexo.currentMouseMotionFactory = factory;
}
@Override
protected void startUp() throws Exception
{
Flexo.isStretched = client.isStretchedEnabled();
overlayManager.add(overlay);
updateMouseMotionFactory();
}
@Override
protected void startUp() throws Exception {
Flexo.isStretched = client.isStretchedEnabled();
overlayManager.add(overlay);
updateMouseMotionFactory();
}
@Override
protected void shutDown() throws Exception {
overlayManager.remove(overlay);
}
@Override
protected void shutDown() throws Exception
{
overlayManager.remove(overlay);
}
}