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

View File

@@ -27,66 +27,74 @@
package net.runelite.client.plugins.flexo; 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.api.Client;
import net.runelite.client.ui.overlay.Overlay; import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer; import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition; import net.runelite.client.ui.overlay.OverlayPosition;
import javax.annotation.Nullable; public class FlexoOverlay extends Overlay
import javax.inject.Inject; {
import java.awt.*; private static Rectangle clickArea;
import java.awt.geom.Line2D;
import java.util.ArrayList;
public class FlexoOverlay extends Overlay { ArrayList<Rectangle> clickAreas = new ArrayList<>();
ArrayList<Point> clickPoints = new ArrayList<>();
public static Rectangle clickArea; @Inject
public ArrayList<Rectangle> clickAreas = new ArrayList<>(); private FlexoConfig config;
public ArrayList<Point> clickPoints = new ArrayList<>();
@Inject @Inject
private Client client; public FlexoOverlay(FlexoConfig config)
{
@Inject setPosition(OverlayPosition.DYNAMIC);
private FlexoPlugin plugin; setLayer(OverlayLayer.ABOVE_WIDGETS);
this.config = config;
@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;
}
@Override @Override
public Dimension render(Graphics2D graphics) { public Dimension render(Graphics2D graphics)
if (config.getDebugNPCs() || config.getDebugGroundItems() || config.getDebugPlayers()) { {
if (clickArea!=null) if (config.getDebugNPCs() || config.getDebugGroundItems() || config.getDebugPlayers())
graphics.draw(clickArea); {
if (clickAreas!=null) { if (clickArea != null)
for (Rectangle clickArea : clickAreas) { {
if (clickArea!=null) graphics.draw(clickArea);
graphics.draw(clickArea); }
} if (clickAreas != null)
} {
if (clickPoints!=null) { for (Rectangle clickArea : clickAreas)
for (Point p : clickPoints) { {
if (p!=null) { if (clickArea != null)
graphics.setColor(Color.MAGENTA); {
graphics.draw(new Line2D.Double(p.x, p.y, p.x, p.y)); graphics.draw(clickArea);
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)); if (clickPoints != null)
} {
} for (Point p : clickPoints)
} {
} if (p != null)
return 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.support.SinusoidalDeviationProvider;
import com.github.joonasvali.naturalmouse.util.FlowTemplates; import com.github.joonasvali.naturalmouse.util.FlowTemplates;
import com.google.inject.Provides; 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.Client;
import net.runelite.api.NPC; import net.runelite.api.NPC;
import net.runelite.api.Perspective; import net.runelite.api.Perspective;
@@ -42,7 +47,6 @@ import net.runelite.api.Player;
import net.runelite.api.coords.LocalPoint; import net.runelite.api.coords.LocalPoint;
import net.runelite.api.events.BeforeRender; import net.runelite.api.events.BeforeRender;
import net.runelite.api.events.ConfigChanged; import net.runelite.api.events.ConfigChanged;
import net.runelite.api.events.GameTick;
import net.runelite.client.config.ConfigManager; import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe; import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.flexo.Flexo; 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.ClientUI;
import net.runelite.client.ui.overlay.OverlayManager; import net.runelite.client.ui.overlay.OverlayManager;
import javax.inject.Inject;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
@PluginDescriptor( @PluginDescriptor(
name = "Flexo Config", name = "Flexo Config",
description = "Customizes the flexo api", description = "Customizes the flexo api",
tags = {"flexo", "null"}, tags = {"flexo", "null"},
type = PluginType.UTILITY 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();
}
}
{ @Inject
try { private Client client;
flexo = new Flexo();
} catch (AWTException e) {
e.printStackTrace();
}
}
@Inject @Inject
private Client client; private ClientUI clientUI;
@Inject
private ClientUI clientUI;
@Inject @Inject
private ConfigManager configManager; private ConfigManager configManager;
@Inject @Inject
private OverlayManager overlayManager; private OverlayManager overlayManager;
@Inject @Inject
private FlexoOverlay overlay; private FlexoOverlay overlay;
@Provides @Provides
FlexoConfig getConfig(ConfigManager configManager) { FlexoConfig getConfig(ConfigManager configManager)
return configManager.getConfig(FlexoConfig.class); {
} return configManager.getConfig(FlexoConfig.class);
}
@Subscribe @Subscribe
private void onConfigChanged(ConfigChanged event) { private void onConfigChanged(ConfigChanged event)
if (event.getKey().compareTo("overlayEnabled")==0) { {
if (getConfig(configManager).overlayEnabled()) { if (event.getKey().compareTo("overlayEnabled") == 0)
overlayManager.add(overlay); {
} else { if (getConfig(configManager).overlayEnabled())
overlayManager.remove(overlay); {
} overlayManager.add(overlay);
} }
updateMouseMotionFactory(); else
} {
overlayManager.remove(overlay);
}
}
updateMouseMotionFactory();
}
@Subscribe @Subscribe
public void onBeforeRender(BeforeRender event) { public void onBeforeRender(BeforeRender event)
if (Flexo.client==null) {
Flexo.client = client; if (Flexo.client == null)
if (Flexo.clientUI==null) {
Flexo.clientUI = clientUI; Flexo.client = client;
overlay.clickAreas = new ArrayList<>(); }
overlay.clickPoints = new ArrayList<>(); if (Flexo.clientUI == null)
if (getConfig(configManager).getDebugNPCs()) { {
Flexo.isStretched = client.isStretchedEnabled(); Flexo.clientUI = clientUI;
Flexo.scale = configManager.getConfig(StretchedModeConfig.class).scalingFactor(); }
if (flexo != null) overlay.clickAreas = new ArrayList<>();
for (NPC npc : client.getNpcs()) { overlay.clickPoints = new ArrayList<>();
if (npc != null) if (getConfig(configManager).getDebugNPCs())
if (npc.getConvexHull() != null) { {
Rectangle r = FlexoMouse.getClickArea(npc.getConvexHull().getBounds()); Flexo.isStretched = client.isStretchedEnabled();
overlay.clickAreas.add(r); Flexo.scale = configManager.getConfig(StretchedModeConfig.class).scalingFactor();
java.awt.Point p = FlexoMouse.getClickPoint(r); if (flexo != null)
overlay.clickPoints.add(p); {
} 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()) { if (getConfig(configManager).getDebugPlayers())
Flexo.isStretched = client.isStretchedEnabled(); {
Flexo.scale = configManager.getConfig(StretchedModeConfig.class).scalingFactor(); Flexo.isStretched = client.isStretchedEnabled();
if (flexo != null) Flexo.scale = configManager.getConfig(StretchedModeConfig.class).scalingFactor();
for (Player player : client.getPlayers()) { if (flexo != null)
if (player != null) {
if (player.getConvexHull() != null) { for (Player player : client.getPlayers())
Rectangle r = FlexoMouse.getClickArea(player.getConvexHull().getBounds()); {
overlay.clickAreas.add(r); if (player != null)
java.awt.Point p = FlexoMouse.getClickPoint(r); {
overlay.clickPoints.add(p); 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 // Could still use some improvement
if (getConfig(configManager).getDebugGroundItems()) { if (getConfig(configManager).getDebugGroundItems())
Flexo.isStretched = client.isStretchedEnabled(); {
Flexo.scale = configManager.getConfig(StretchedModeConfig.class).scalingFactor(); Flexo.isStretched = client.isStretchedEnabled();
if (flexo != null) Flexo.scale = configManager.getConfig(StretchedModeConfig.class).scalingFactor();
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);
}
}
}
}
@Subscribe if (flexo != null)
public void onGameTick(GameTick event) { {
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() { // Always add random
Flexo.minDelay = getConfig(configManager).minDelayAmt(); flows.add(new Flow(FlowTemplates.random()));
MouseMotionFactory factory = new MouseMotionFactory();
//TODO:Add Options for various flows to allow more personalization
List<Flow> flows = new ArrayList<>();
//Always add random if (getConfig(configManager).getVariatingFlow())
flows.add(new Flow(FlowTemplates.random())); {
flows.add(new Flow(FlowTemplates.variatingFlow()));
}
if (getConfig(configManager).getVariatingFlow()) if (getConfig(configManager).getSlowStartupFlow())
flows.add(new Flow(FlowTemplates.variatingFlow())); {
flows.add(new Flow(FlowTemplates.slowStartupFlow()));
}
if (getConfig(configManager).getSlowStartupFlow()) if (getConfig(configManager).getSlowStartup2Flow())
flows.add(new Flow(FlowTemplates.slowStartupFlow())); {
flows.add(new Flow(FlowTemplates.slowStartup2Flow()));
}
if (getConfig(configManager).getSlowStartup2Flow()) if (getConfig(configManager).getJaggedFlow())
flows.add(new Flow(FlowTemplates.slowStartup2Flow())); {
flows.add(new Flow(FlowTemplates.jaggedFlow()));
}
if (getConfig(configManager).getJaggedFlow()) if (getConfig(configManager).getInterruptedFlow())
flows.add(new Flow(FlowTemplates.jaggedFlow())); {
flows.add(new Flow(FlowTemplates.interruptedFlow()));
}
if (getConfig(configManager).getInterruptedFlow()) if (getConfig(configManager).getInterruptedFlow2())
flows.add(new Flow(FlowTemplates.interruptedFlow())); {
flows.add(new Flow(FlowTemplates.interruptedFlow2()));
}
if (getConfig(configManager).getInterruptedFlow2()) if (getConfig(configManager).getStoppingFlow())
flows.add(new Flow(FlowTemplates.interruptedFlow2())); {
flows.add(new Flow(FlowTemplates.stoppingFlow()));
}
if (getConfig(configManager).getStoppingFlow()) DefaultSpeedManager manager = new DefaultSpeedManager(flows);
flows.add(new Flow(FlowTemplates.stoppingFlow())); //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); DefaultOvershootManager overshootManager = (DefaultOvershootManager) factory.getOvershootManager();
//TODO:Add options for custom Deviation Provider and Noise Provider overshootManager.setOvershoots(getConfig(configManager).getOvershoots());
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(); factory.setSpeedManager(manager);
overshootManager.setOvershoots(getConfig(configManager).getOvershoots()); Flexo.currentMouseMotionFactory = factory;
}
factory.setSpeedManager(manager); @Override
Flexo.currentMouseMotionFactory = factory; protected void startUp() throws Exception
} {
Flexo.isStretched = client.isStretchedEnabled();
overlayManager.add(overlay);
updateMouseMotionFactory();
}
@Override @Override
protected void startUp() throws Exception { protected void shutDown() throws Exception
Flexo.isStretched = client.isStretchedEnabled(); {
overlayManager.add(overlay); overlayManager.remove(overlay);
updateMouseMotionFactory(); }
}
@Override
protected void shutDown() throws Exception {
overlayManager.remove(overlay);
}
} }