mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-07 08:39:12 +00:00
finished everything
This commit is contained in:
@@ -1,15 +1,17 @@
|
||||
package org.parabot.environment;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
import org.parabot.core.Context;
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.core.Directories;
|
||||
import org.parabot.core.build.BuildPath;
|
||||
import org.parabot.core.classpath.ClassPath;
|
||||
import org.parabot.core.desc.ServerDescription;
|
||||
import org.parabot.core.parsers.ServerManifestParser;
|
||||
import org.parabot.core.parsers.ServerManifestParser.ServerCache;
|
||||
import org.parabot.core.ui.BotUI;
|
||||
import org.parabot.core.ui.ServerSelector;
|
||||
import org.parabot.core.ui.components.BotToolbar;
|
||||
import org.parabot.environment.servers.ServerProvider;
|
||||
import org.parabot.environment.servers.loader.ServerLoader;
|
||||
@@ -27,14 +29,26 @@ public class Environment {
|
||||
* @param url
|
||||
*/
|
||||
public static void load(final ServerDescription desc, final String serverName) {
|
||||
ServerSelector.getInstance().dispose();
|
||||
if (!BotUI.getInstance().isVisible()) {
|
||||
BotUI.getInstance().setVisible(true);
|
||||
}
|
||||
|
||||
final ClassPath classPath = Core.inDebugMode() ? null : new ClassPath();
|
||||
final ServerCache cache = Core.inDebugMode() ? ServerManifestParser.cache.get(desc) : null;
|
||||
|
||||
|
||||
// buildpath
|
||||
if(cache != null) {
|
||||
if(cache.getLoader().getClassPath().isJar()) {
|
||||
cache.getLoader().getClassPath().addToBuildPath();
|
||||
} else {
|
||||
try {
|
||||
BuildPath.add(Directories.getServerPath().toURI().toURL());
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final ServerLoader serverLoader = Core.inDebugMode() ? cache.getLoader() : new ServerLoader(classPath);
|
||||
String[] serverProviders = null;
|
||||
if (!Core.inDebugMode()) {
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.parabot.environment.api.utils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Clisprail
|
||||
*
|
||||
*/
|
||||
public class Random {
|
||||
private final static java.util.Random RANDOM = new java.util.Random();
|
||||
|
||||
/**
|
||||
* Randomizes a number between minimum and maximum
|
||||
*
|
||||
* @param min
|
||||
* @param max
|
||||
* @return randomized number
|
||||
*/
|
||||
public static int between(final int min, final int max) {
|
||||
try {
|
||||
return min + (max == min ? 0 : RANDOM.nextInt(max - min));
|
||||
} catch (Exception e) {
|
||||
return min + (max - min);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.parabot.environment.api.utils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Clisprail
|
||||
*
|
||||
*/
|
||||
public class Time {
|
||||
|
||||
/**
|
||||
* Sleeps for a given amount of time
|
||||
* @param ms
|
||||
*/
|
||||
public static void sleep(final int ms) {
|
||||
try {
|
||||
Thread.sleep(ms);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void sleep(final int minumum, final int maximum) {
|
||||
try {
|
||||
Thread.sleep(Random.between(minumum, maximum));
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static long get() {
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
package org.parabot.environment.input;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
|
||||
import org.parabot.core.Context;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Clisprail, Matt, Dane
|
||||
*
|
||||
*/
|
||||
public class Keyboard implements KeyListener {
|
||||
private Component component = null;
|
||||
private static HashMap<Character, Character> specialChars;
|
||||
private long pressTime;
|
||||
|
||||
public Keyboard(Component component) {
|
||||
this.component = component;
|
||||
}
|
||||
|
||||
public static Keyboard getInstance() {
|
||||
return Context.resolve().getKeyboard();
|
||||
}
|
||||
|
||||
static {
|
||||
char[] spChars = { '~', '!', '@', '#', '%', '^', '&', '*', '(', ')',
|
||||
'_', '+', '{', '}', ':', '<', '>', '?', '"', '|' };
|
||||
char[] replace = { '`', '1', '2', '3', '5', '6', '7', '8', '9', '0',
|
||||
'-', '=', '[', ']', ';', ',', '.', '/', '\'', '\\' };
|
||||
specialChars = new HashMap<Character, Character>(spChars.length);
|
||||
for (int x = 0; x < spChars.length; ++x)
|
||||
specialChars.put(spChars[x], replace[x]);
|
||||
}
|
||||
|
||||
private static long getRandom() {
|
||||
Random rand = new Random();
|
||||
return rand.nextInt(100) + 40;
|
||||
}
|
||||
|
||||
public void sendKeys(String s) {
|
||||
|
||||
pressTime = System.currentTimeMillis();
|
||||
for (char c : s.toCharArray())
|
||||
for (KeyEvent ke : createKeyClick(component, c)) {
|
||||
try {
|
||||
Thread.sleep(5);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
sendKeyEvent(ke);
|
||||
}
|
||||
clickKey(10);
|
||||
}
|
||||
|
||||
public void clickKey(char c) {
|
||||
|
||||
pressTime = System.currentTimeMillis();
|
||||
for (KeyEvent ke : createKeyClick(component, c))
|
||||
sendKeyEvent(ke);
|
||||
}
|
||||
|
||||
public void clickKey(int keyCode) {
|
||||
|
||||
pressTime = System.currentTimeMillis();
|
||||
for (KeyEvent ke : createKeyClick(component, keyCode))
|
||||
sendKeyEvent(ke);
|
||||
}
|
||||
|
||||
public void pressKey(int keyCode) {
|
||||
|
||||
pressTime = System.currentTimeMillis();
|
||||
KeyEvent ke = createKeyPress(component, keyCode);
|
||||
sendKeyEvent(ke);
|
||||
}
|
||||
|
||||
public void releaseKey(int keyCode) {
|
||||
|
||||
pressTime = System.currentTimeMillis();
|
||||
KeyEvent ke = createKeyRelease(component, keyCode);
|
||||
sendKeyEvent(ke);
|
||||
}
|
||||
|
||||
private KeyEvent[] createKeyClick(Component target, char c) {
|
||||
|
||||
pressTime += 2 * getRandom();
|
||||
|
||||
Character newChar = specialChars.get(c);
|
||||
int keyCode = Character.toUpperCase((newChar == null) ? c : newChar);
|
||||
|
||||
if (Character.isLowerCase(c)
|
||||
|| (!Character.isLetter(c) && (newChar == null))) {
|
||||
KeyEvent pressed = new KeyEvent(target, KeyEvent.KEY_PRESSED,
|
||||
pressTime, 0, keyCode, c);
|
||||
KeyEvent typed = new KeyEvent(target, KeyEvent.KEY_TYPED,
|
||||
pressTime, 0, 0, c);
|
||||
pressTime += getRandom();
|
||||
KeyEvent released = new KeyEvent(target, KeyEvent.KEY_RELEASED,
|
||||
pressTime, 0, keyCode, c);
|
||||
|
||||
return new KeyEvent[] { pressed, typed, released };
|
||||
} else {
|
||||
KeyEvent shiftDown = new KeyEvent(target, KeyEvent.KEY_PRESSED,
|
||||
pressTime, KeyEvent.SHIFT_MASK, KeyEvent.VK_SHIFT,
|
||||
KeyEvent.CHAR_UNDEFINED);
|
||||
|
||||
pressTime += getRandom();
|
||||
KeyEvent pressed = new KeyEvent(target, KeyEvent.KEY_PRESSED,
|
||||
pressTime, KeyEvent.SHIFT_MASK, keyCode, c);
|
||||
KeyEvent typed = new KeyEvent(target, KeyEvent.KEY_TYPED,
|
||||
pressTime, KeyEvent.SHIFT_MASK, 0, c);
|
||||
pressTime += getRandom();
|
||||
KeyEvent released = new KeyEvent(target, KeyEvent.KEY_RELEASED,
|
||||
pressTime, KeyEvent.SHIFT_MASK, keyCode, c);
|
||||
pressTime += getRandom();
|
||||
KeyEvent shiftUp = new KeyEvent(target, KeyEvent.KEY_RELEASED,
|
||||
pressTime, 0, KeyEvent.VK_SHIFT, KeyEvent.CHAR_UNDEFINED);
|
||||
|
||||
return new KeyEvent[] { shiftDown, pressed, typed, released,
|
||||
shiftUp };
|
||||
}
|
||||
}
|
||||
|
||||
private KeyEvent[] createKeyClick(Component target, int keyCode) {
|
||||
int modifier = 0;
|
||||
switch (keyCode) {
|
||||
case KeyEvent.VK_SHIFT:
|
||||
modifier = KeyEvent.SHIFT_MASK;
|
||||
break;
|
||||
case KeyEvent.VK_ALT:
|
||||
modifier = KeyEvent.ALT_MASK;
|
||||
break;
|
||||
case KeyEvent.VK_CONTROL:
|
||||
modifier = KeyEvent.CTRL_MASK;
|
||||
break;
|
||||
}
|
||||
KeyEvent pressed = new KeyEvent(target, KeyEvent.KEY_PRESSED,
|
||||
pressTime, modifier, keyCode, KeyEvent.CHAR_UNDEFINED);
|
||||
KeyEvent released = new KeyEvent(target, KeyEvent.KEY_RELEASED,
|
||||
pressTime + getRandom(), 0, keyCode, KeyEvent.CHAR_UNDEFINED);
|
||||
|
||||
return new KeyEvent[] { pressed, released };
|
||||
}
|
||||
|
||||
private KeyEvent createKeyPress(Component target, int keyCode) {
|
||||
int modifier = 0;
|
||||
switch (keyCode) {
|
||||
case KeyEvent.VK_SHIFT:
|
||||
modifier = KeyEvent.SHIFT_MASK;
|
||||
break;
|
||||
case KeyEvent.VK_ALT:
|
||||
modifier = KeyEvent.ALT_MASK;
|
||||
break;
|
||||
case KeyEvent.VK_CONTROL:
|
||||
modifier = KeyEvent.CTRL_MASK;
|
||||
break;
|
||||
}
|
||||
KeyEvent pressed = new KeyEvent(target, KeyEvent.KEY_PRESSED,
|
||||
pressTime, modifier, keyCode, KeyEvent.CHAR_UNDEFINED);
|
||||
|
||||
return pressed;
|
||||
}
|
||||
|
||||
private KeyEvent createKeyRelease(Component target, int keyCode) {
|
||||
@SuppressWarnings("unused")
|
||||
int modifier = 0;
|
||||
switch (keyCode) {
|
||||
case KeyEvent.VK_SHIFT:
|
||||
modifier = KeyEvent.SHIFT_MASK;
|
||||
break;
|
||||
case KeyEvent.VK_ALT:
|
||||
modifier = KeyEvent.ALT_MASK;
|
||||
break;
|
||||
case KeyEvent.VK_CONTROL:
|
||||
modifier = KeyEvent.CTRL_MASK;
|
||||
break;
|
||||
}
|
||||
KeyEvent released = new KeyEvent(target, KeyEvent.KEY_RELEASED,
|
||||
pressTime + getRandom(), 0, keyCode, KeyEvent.CHAR_UNDEFINED);
|
||||
|
||||
return released;
|
||||
}
|
||||
|
||||
public void sendKeyEvent(KeyEvent e) {
|
||||
for (KeyListener kl : component.getKeyListeners()) {
|
||||
if(kl instanceof Keyboard) {
|
||||
continue;
|
||||
}
|
||||
if (!e.isConsumed()) {
|
||||
switch (e.getID()) {
|
||||
case KeyEvent.KEY_PRESSED:
|
||||
kl.keyPressed(e);
|
||||
break;
|
||||
case KeyEvent.KEY_RELEASED:
|
||||
kl.keyReleased(e);
|
||||
break;
|
||||
case KeyEvent.KEY_TYPED:
|
||||
kl.keyTyped(e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
package org.parabot.environment.input;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
|
||||
import org.parabot.core.Context;
|
||||
import org.parabot.environment.api.utils.Time;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Clisprail
|
||||
*
|
||||
*/
|
||||
public class Mouse implements MouseListener, MouseMotionListener {
|
||||
private Component component = null;
|
||||
private int x = 0;
|
||||
private int y = 0;
|
||||
|
||||
public Mouse(Component component) {
|
||||
this.component = component;
|
||||
}
|
||||
|
||||
public static Mouse getInstance() {
|
||||
return Context.resolve().getMouse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the mouse to the given point and clicks
|
||||
* @param x
|
||||
* @param y
|
||||
* @param left
|
||||
*/
|
||||
public void click(final int x, final int y, final boolean left) {
|
||||
|
||||
moveMouse(x, y);
|
||||
Time.sleep(50, 200);
|
||||
MouseEvent me = new MouseEvent(component,
|
||||
MouseEvent.MOUSE_PRESSED, System.currentTimeMillis(), 0, x,
|
||||
y, 1, false, left ? MouseEvent.BUTTON1 : MouseEvent.BUTTON3);
|
||||
for(MouseListener l : component.getMouseListeners()) {
|
||||
if(!(l instanceof Mouse)) {
|
||||
l.mousePressed(me);
|
||||
}
|
||||
}
|
||||
Time.sleep(10, 100);
|
||||
releaseMouse(x, y, left);
|
||||
Time.sleep(10, 100);
|
||||
clickMouse(x, y, left);
|
||||
}
|
||||
|
||||
public void click(final Point p, final boolean left) {
|
||||
click(p.x, p.y, left);
|
||||
}
|
||||
|
||||
public void click(final Point p) {
|
||||
click(p.x, p.y, true);
|
||||
}
|
||||
|
||||
private void clickMouse(int x, int y, boolean left) {
|
||||
try {
|
||||
|
||||
MouseEvent me = new MouseEvent(component,
|
||||
MouseEvent.MOUSE_CLICKED, System.currentTimeMillis(), 0, x,
|
||||
y, 0, false, left ? MouseEvent.BUTTON1 : MouseEvent.BUTTON3);
|
||||
for(MouseListener l : component.getMouseListeners()) {
|
||||
if(!(l instanceof Mouse)) {
|
||||
l.mouseClicked(me);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void releaseMouse(int x, int y, boolean left) {
|
||||
try {
|
||||
|
||||
MouseEvent me = new MouseEvent(component,
|
||||
MouseEvent.MOUSE_RELEASED, System.currentTimeMillis(), 0, x,
|
||||
y, 0, false, left ? MouseEvent.BUTTON1 : MouseEvent.BUTTON3);
|
||||
for(MouseListener l : component.getMouseListeners()) {
|
||||
if(!(l instanceof Mouse)) {
|
||||
l.mouseReleased(me);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the mouse cursor to the given location
|
||||
* @param x
|
||||
* @param y
|
||||
*/
|
||||
public void moveMouse(int x, int y) {
|
||||
try {
|
||||
MouseEvent me = new MouseEvent(component,
|
||||
MouseEvent.MOUSE_MOVED, System.currentTimeMillis(), 0, x,
|
||||
y, 0, false);
|
||||
for(MouseMotionListener l : component.getMouseMotionListeners()) {
|
||||
if(!(l instanceof Mouse)) {
|
||||
l.mouseMoved(me);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mouse cursor current location
|
||||
* @return point
|
||||
*/
|
||||
public Point getPoint() {
|
||||
return new Point(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
x = e.getX();
|
||||
y = e.getY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package org.parabot.environment.scripts;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.parabot.core.ui.images.Images;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Dane
|
||||
*
|
||||
*/
|
||||
public enum Category
|
||||
{
|
||||
|
||||
AGILITY, COMBAT, COOKING, CRAFTING, FARMING, FIREMAKING, FISHING, FLETCHING, HERBLORE, MAGIC, MINING, OTHER, PRAYER, RUNECRAFTING, SLAYER, SMITHING, THIEVING, UTILITY, WOODCUTTING;
|
||||
|
||||
public BufferedImage getIcon() {
|
||||
return Category.getIcon(this.name().toLowerCase());
|
||||
}
|
||||
|
||||
public static BufferedImage getIcon(String s) {
|
||||
if (images.get(s) == null) {
|
||||
images.put(s, Images.getResource("/org/parabot/core/ui/images/category/" + s + ".png"));
|
||||
}
|
||||
return images.get(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.append(name().charAt(0));
|
||||
b.append(name().toLowerCase().substring(1));
|
||||
return new String(b);
|
||||
}
|
||||
|
||||
private static HashMap<String, BufferedImage> images = new HashMap<String, BufferedImage>();
|
||||
|
||||
static {
|
||||
images.put("script", Images.getResource("/org/parabot/core/ui/images/category/script.png"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package org.parabot.environment.scripts;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.parabot.environment.scripts.framework.AbstractFramework;
|
||||
import org.parabot.environment.scripts.framework.LoopTask;
|
||||
import org.parabot.environment.scripts.framework.Strategy;
|
||||
|
||||
public class Frameworks {
|
||||
|
||||
public static Looper getLooper(LoopTask loopTask) {
|
||||
return new Looper(loopTask);
|
||||
}
|
||||
|
||||
public static StrategyWorker getStrategyWorker(Collection<Strategy> strategies) {
|
||||
return new StrategyWorker(strategies);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Looper extends AbstractFramework {
|
||||
private LoopTask loopTask = null;
|
||||
|
||||
public Looper(LoopTask loopTask) {
|
||||
this.loopTask = loopTask;
|
||||
}
|
||||
@Override
|
||||
public boolean execute() {
|
||||
int sleepTime = loopTask.loop();
|
||||
if(sleepTime < 0) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(sleepTime);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class StrategyWorker extends AbstractFramework {
|
||||
private Collection<Strategy> strategies = null;
|
||||
|
||||
public StrategyWorker(Collection<Strategy> strategies) {
|
||||
this.strategies = strategies;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute() {
|
||||
for(Strategy s : strategies) {
|
||||
if(s.activate()) {
|
||||
s.execute();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
package org.parabot.environment.scripts;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.parabot.core.Context;
|
||||
import org.parabot.core.ui.components.BotToolbar;
|
||||
import org.parabot.environment.api.utils.Time;
|
||||
import org.parabot.environment.scripts.framework.AbstractFramework;
|
||||
import org.parabot.environment.scripts.framework.LoopTask;
|
||||
import org.parabot.environment.scripts.framework.SleepCondition;
|
||||
import org.parabot.environment.scripts.framework.Strategy;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Clisprail
|
||||
*
|
||||
*/
|
||||
public class Script implements Runnable {
|
||||
private Collection<Strategy> strategies = null;
|
||||
private int frameWorkType = 0;
|
||||
private AbstractFramework frameWork = null;
|
||||
|
||||
public static final int TYPE_STRATEGY = 0;
|
||||
public static final int TYPE_LOOP = 1;
|
||||
public static final int TYPE_OTHER = 2;
|
||||
|
||||
private int state = 0;
|
||||
public static final int STATE_RUNNING = 0;
|
||||
public static final int STATE_PAUSE = 1;
|
||||
public static final int STATE_STOPPED = 2;
|
||||
|
||||
public boolean onExecute() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onFinish() {
|
||||
|
||||
}
|
||||
|
||||
public final void provide(final Collection<Strategy> strategies) {
|
||||
this.strategies = strategies;
|
||||
}
|
||||
|
||||
public final int getFrameWorkType() {
|
||||
return frameWorkType;
|
||||
}
|
||||
|
||||
public final void setFrameWork(int frameWorkType) {
|
||||
if(frameWorkType < 0 || frameWorkType > 2) {
|
||||
throw new RuntimeException("Invalid framework type");
|
||||
}
|
||||
this.frameWorkType = frameWorkType;
|
||||
}
|
||||
|
||||
public final void setAbstractFrameWork(AbstractFramework f) {
|
||||
this.frameWork = f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void run() {
|
||||
Context.resolve().getServerProvider().initScript(this);
|
||||
if(!onExecute()) {
|
||||
Context.resolve().getServerProvider().unloadScript(this);
|
||||
this.state = STATE_STOPPED;
|
||||
return;
|
||||
}
|
||||
|
||||
Context.resolve().setRunningScript(this);
|
||||
BotToolbar.getInstance().toggleRun();
|
||||
if(this instanceof LoopTask) {
|
||||
frameWorkType = TYPE_LOOP;
|
||||
frameWork = Frameworks.getLooper((LoopTask) this);
|
||||
} else if(strategies != null && !strategies.isEmpty()) {
|
||||
frameWorkType = TYPE_STRATEGY;
|
||||
frameWork = Frameworks.getStrategyWorker(strategies);
|
||||
} else {
|
||||
frameWorkType = TYPE_OTHER;
|
||||
}
|
||||
try {
|
||||
while(this.state != STATE_STOPPED) {
|
||||
if(this.state == STATE_PAUSE) {
|
||||
sleep(500);
|
||||
continue;
|
||||
}
|
||||
if(!frameWork.execute()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
onFinish();
|
||||
|
||||
Context.resolve().getServerProvider().unloadScript(this);
|
||||
this.state = STATE_STOPPED;
|
||||
Context.resolve().setRunningScript(null);
|
||||
BotToolbar.getInstance().toggleRun();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sleeps until the SleepCondition is valid.
|
||||
*
|
||||
* @param conn
|
||||
* the condition.
|
||||
* @param timeout
|
||||
* the time in miliseconds before it stops sleeping.
|
||||
* @return whether it ran successfully without timing out.
|
||||
*/
|
||||
public final boolean sleep(SleepCondition conn, int timeout) {
|
||||
long start = System.currentTimeMillis();
|
||||
while (!conn.isValid()) {
|
||||
if (start + timeout < System.currentTimeMillis()) {
|
||||
return false;
|
||||
}
|
||||
Time.sleep(50);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the script's state
|
||||
* @param state
|
||||
*/
|
||||
public final void setState(final int state) {
|
||||
if(state < 0 || state > 2) {
|
||||
throw new IllegalArgumentException("Illegal state");
|
||||
}
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sleeps for an amount of milliseconds
|
||||
* @param ms
|
||||
*/
|
||||
public final void sleep(int ms) {
|
||||
try {
|
||||
Thread.sleep(ms);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.parabot.environment.scripts;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* A script manifest
|
||||
* @author Clisprail
|
||||
*
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ScriptManifest {
|
||||
|
||||
String author();
|
||||
|
||||
String name();
|
||||
|
||||
Category category();
|
||||
|
||||
double version();
|
||||
|
||||
String description();
|
||||
|
||||
String[] servers();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package org.parabot.environment.scripts.framework;
|
||||
|
||||
public abstract class AbstractFramework {
|
||||
|
||||
public abstract boolean execute();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package org.parabot.environment.scripts.framework;
|
||||
|
||||
public interface LoopTask {
|
||||
|
||||
public int loop();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package org.parabot.environment.scripts.framework;
|
||||
|
||||
public interface SleepCondition {
|
||||
|
||||
public boolean isValid();
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package org.parabot.environment.scripts.framework;
|
||||
|
||||
public interface Strategy {
|
||||
|
||||
public boolean activate();
|
||||
|
||||
public void execute();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.parabot.environment.scripts.loader;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.parabot.core.asm.ASMClassLoader;
|
||||
import org.parabot.core.classpath.ClassPath;
|
||||
import org.parabot.environment.scripts.Script;
|
||||
|
||||
/**
|
||||
*
|
||||
* An environment to load a server
|
||||
*
|
||||
* @author Clisprail
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ScriptLoader extends ASMClassLoader {
|
||||
private ClassPath classPath = null;
|
||||
|
||||
public ScriptLoader(ClassPath classPath) {
|
||||
super(classPath);
|
||||
this.classPath = classPath;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets all classes that extends ServerProvider
|
||||
* @return string array of class names that extends ServerProvider
|
||||
*/
|
||||
public final String[] getScriptClassNames() {
|
||||
final List<String> classNames = new ArrayList<String>();
|
||||
for (ClassNode c : classPath.classes.values())
|
||||
if (c.superName.replace('/', '.').equals(
|
||||
Script.class.getName())) {
|
||||
classNames.add(c.name.replace('/', '.'));
|
||||
}
|
||||
return classNames.toArray(new String[classNames.size()]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,9 @@ import org.objectweb.asm.Opcodes;
|
||||
import org.parabot.core.Context;
|
||||
import org.parabot.core.asm.interfaces.Injectable;
|
||||
import org.parabot.core.parsers.HookParser;
|
||||
import org.parabot.environment.input.Keyboard;
|
||||
import org.parabot.environment.input.Mouse;
|
||||
import org.parabot.environment.scripts.Script;
|
||||
|
||||
/**
|
||||
* Provides a server to the bot
|
||||
@@ -43,7 +46,6 @@ public abstract class ServerProvider implements Opcodes {
|
||||
public void injectHooks() {
|
||||
URL hooksFile = getHooks();
|
||||
if (hooksFile == null) {
|
||||
System.out.println("null");
|
||||
return;
|
||||
}
|
||||
HookParser parser = new HookParser(hooksFile);
|
||||
@@ -54,6 +56,7 @@ public abstract class ServerProvider implements Opcodes {
|
||||
for (Injectable inj : injectables) {
|
||||
inj.inject();
|
||||
}
|
||||
Context.resolve().setHookParser(parser);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,5 +79,30 @@ public abstract class ServerProvider implements Opcodes {
|
||||
public void parseJar() {
|
||||
Context.resolve().getClassPath().addJar(getJar());
|
||||
}
|
||||
|
||||
public void initScript(Script script) {
|
||||
|
||||
}
|
||||
|
||||
public void initMouse() {
|
||||
final Context context = Context.resolve();
|
||||
final Applet applet = context.getApplet();
|
||||
final Mouse mouse = new Mouse(applet);
|
||||
applet.addMouseListener(mouse);
|
||||
applet.addMouseMotionListener(mouse);
|
||||
context.setMouse(mouse);
|
||||
}
|
||||
|
||||
public void initKeyboard() {
|
||||
final Context context = Context.resolve();
|
||||
final Applet applet = context.getApplet();
|
||||
final Keyboard keyboard = new Keyboard(applet);
|
||||
applet.addKeyListener(keyboard);
|
||||
context.setKeyboard(keyboard);
|
||||
}
|
||||
|
||||
public void unloadScript(Script script) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,5 +38,9 @@ public class ServerLoader extends ASMClassLoader {
|
||||
}
|
||||
return classNames.toArray(new String[classNames.size()]);
|
||||
}
|
||||
|
||||
public ClassPath getClassPath() {
|
||||
return classPath;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user