mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-10-01 02:17:22 +00:00
Merge pull request #242 from Parabot/development
[MERGE] Development into master
This commit is contained in:
+6
-4
@@ -1,7 +1,9 @@
|
||||
language: java
|
||||
|
||||
dist: trusty
|
||||
|
||||
jdk:
|
||||
- oraclejdk7
|
||||
- openjdk7
|
||||
- oraclejdk8
|
||||
|
||||
before_install:
|
||||
@@ -32,7 +34,7 @@ env:
|
||||
- secure: UG+b1tEgc8xv9x4r//2OAIK1RrYv6n209KTTFMMwcnAa7DI8HaP8nljRa5/VhDhuKHdlVrYH/tI90v7UVBs0GDVNwK5V17Io0fMm3FUGZekSthTCqqno5wAGa9r6a6mMLtSaSmIFeIKi0+0d2ZwplRuhj/dtEYjjBBj+kK8g4nE=
|
||||
- secure: St/fecUDInFBCRriYqgp2F8PU9/SooorgxD9Mrs+b0EsC7AbtSsQXvdIv2Lp6xzdQ0VSXPcLIhULPOYrmBKnGQ/NjXTIZXxnroyQxxnI6xyEWIZwiHRY/bKRJDRbQTxD9NL32szKiDSwnw7pu6llF4D64UqQvziq4Gm6VohU75M=
|
||||
- secure: bD15GVZWowiknbfLavh8CxSh0GsnF5kT4kZ6ggCuUDGyj0mzqf7dNRnchQIKkCG0WRYyTrFN4pEiygeywWsipEeAVv9Xhx3cuUZmzeQaR5KCWabSwJ8gK6jZd1YhcWmM9vrdPHobZr65MP0y/8mu/Fovgky9dY7KDf4G3SebNrM=
|
||||
- PARABOT_VERSION=2.6.6.6
|
||||
- PARABOT_VERSION=2.6.8
|
||||
|
||||
cache:
|
||||
directories:
|
||||
@@ -56,7 +58,7 @@ deploy:
|
||||
branch:
|
||||
- master
|
||||
- development
|
||||
jdk: 'oraclejdk7'
|
||||
jdk: 'openjdk7'
|
||||
|
||||
- provider: script
|
||||
script: "cp ./.travis/.travis.settings.xml $HOME/.m2/settings.xml && mvn package javadoc:javadoc deploy site:deploy"
|
||||
@@ -65,4 +67,4 @@ deploy:
|
||||
repo: Parabot/Parabot
|
||||
branch:
|
||||
- master
|
||||
jdk: 'oraclejdk7'
|
||||
jdk: 'openjdk7'
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>org.parabot</groupId>
|
||||
<artifactId>client</artifactId>
|
||||
<version>2.6.6.6</version>
|
||||
<version>2.6.8</version>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
|
||||
@@ -80,6 +80,14 @@ public class Context {
|
||||
return getInstance(null);
|
||||
}
|
||||
|
||||
public static String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public static void setUsername(String username) {
|
||||
Context.username = username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the main client instance
|
||||
*/
|
||||
@@ -88,12 +96,12 @@ public class Context {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the hook parser
|
||||
* Gets the mouse
|
||||
*
|
||||
* @param hookParser
|
||||
* @return mouse
|
||||
*/
|
||||
public void setHookParser(final HookParser hookParser) {
|
||||
this.hookParser = hookParser;
|
||||
public Mouse getMouse() {
|
||||
return mouse;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,15 +114,14 @@ public class Context {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the mouse
|
||||
* Gets the keyboard
|
||||
*
|
||||
* @return mouse
|
||||
* @return keyboard
|
||||
*/
|
||||
public Mouse getMouse() {
|
||||
return mouse;
|
||||
public Keyboard getKeyboard() {
|
||||
return keyboard;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the keyboard
|
||||
*
|
||||
@@ -124,15 +131,6 @@ public class Context {
|
||||
this.keyboard = keyboard;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the keyboard
|
||||
*
|
||||
* @return keyboard
|
||||
*/
|
||||
public Keyboard getKeyboard() {
|
||||
return keyboard;
|
||||
}
|
||||
|
||||
/**
|
||||
* ClassPath
|
||||
*
|
||||
@@ -160,32 +158,9 @@ public class Context {
|
||||
return gameApplet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the game
|
||||
*/
|
||||
public void load() {
|
||||
Core.verbose(TranslationHelper.translate("PARSING_SERVER_JAR"));
|
||||
serverProvider.init();
|
||||
serverProvider.parseJar();
|
||||
Core.verbose(TranslationHelper.translate("DONE"));
|
||||
Core.verbose(TranslationHelper.translate("INJECTING_HOOKS"));
|
||||
serverProvider.injectHooks();
|
||||
Core.verbose(TranslationHelper.translate("DONE"));
|
||||
Core.verbose(TranslationHelper.translate("FETCHING_GAME_APPLET"));
|
||||
if(Core.shouldDump()) {
|
||||
Core.verbose(TranslationHelper.translate("DUMPING_INJECTED_CLIENT"));
|
||||
classPath.dump(new File(Directories.getWorkspace(), "dump.jar"));
|
||||
Core.verbose(TranslationHelper.translate("DONE"));
|
||||
}
|
||||
Applet applet = serverProvider.fetchApplet();
|
||||
// if applet is null the server provider will call setApplet itself
|
||||
if(applet != null) {
|
||||
setApplet(applet);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the bot target applet
|
||||
*
|
||||
* @param applet
|
||||
*/
|
||||
public void setApplet(final Applet applet) {
|
||||
@@ -237,6 +212,30 @@ public class Context {
|
||||
System.setErr(this.defaultErr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the game
|
||||
*/
|
||||
public void load() {
|
||||
Core.verbose(TranslationHelper.translate("PARSING_SERVER_JAR"));
|
||||
serverProvider.init();
|
||||
serverProvider.parseJar();
|
||||
Core.verbose(TranslationHelper.translate("DONE"));
|
||||
Core.verbose(TranslationHelper.translate("INJECTING_HOOKS"));
|
||||
serverProvider.injectHooks();
|
||||
Core.verbose(TranslationHelper.translate("DONE"));
|
||||
Core.verbose(TranslationHelper.translate("FETCHING_GAME_APPLET"));
|
||||
if (Core.shouldDump()) {
|
||||
Core.verbose(TranslationHelper.translate("DUMPING_INJECTED_CLIENT"));
|
||||
classPath.dump(new File(Directories.getWorkspace(), "dump.jar"));
|
||||
Core.verbose(TranslationHelper.translate("DONE"));
|
||||
}
|
||||
Applet applet = serverProvider.fetchApplet();
|
||||
// if applet is null the server provider will call setApplet itself
|
||||
if (applet != null) {
|
||||
setApplet(applet);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the server prodiver belonging to this context
|
||||
*
|
||||
@@ -247,7 +246,6 @@ public class Context {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Sets provider info of this context
|
||||
*
|
||||
* @param providerInfo
|
||||
@@ -259,6 +257,7 @@ public class Context {
|
||||
/**
|
||||
* Gets ServerProvider info
|
||||
* Can be null if this is not a public server provider
|
||||
*
|
||||
* @return info about this provider
|
||||
*/
|
||||
public ServerProviderInfo getServerProviderInfo() {
|
||||
@@ -329,12 +328,12 @@ public class Context {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current running script, if a script stops it will call this method with a null argument
|
||||
* Sets the hook parser
|
||||
*
|
||||
* @param script
|
||||
* @param hookParser
|
||||
*/
|
||||
public void setRunningScript(final Script script) {
|
||||
this.runningScript = script;
|
||||
public void setHookParser(final HookParser hookParser) {
|
||||
this.hookParser = hookParser;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -346,22 +345,24 @@ public class Context {
|
||||
return this.runningScript;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current running script, if a script stops it will call this method with a null argument
|
||||
*
|
||||
* @param script
|
||||
*/
|
||||
public void setRunningScript(final Script script) {
|
||||
this.runningScript = script;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the random handler
|
||||
*
|
||||
* @return random handler
|
||||
*/
|
||||
public RandomHandler getRandomHandler() {
|
||||
return this.randomHandler;
|
||||
}
|
||||
|
||||
public static String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public static void setUsername(String username) {
|
||||
Context.username = username;
|
||||
}
|
||||
|
||||
public JSONParser getJsonParser() {
|
||||
return jsonParser;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,14 @@ public class ProjectProperties {
|
||||
setProperties();
|
||||
}
|
||||
|
||||
public static Version getProjectVersion() {
|
||||
return new Version(getInstance().getCached().getProperty("application.version"));
|
||||
}
|
||||
|
||||
public static ProjectProperties getInstance() {
|
||||
return instance == null ? instance = new ProjectProperties() : instance;
|
||||
}
|
||||
|
||||
private void setProperties() {
|
||||
InputStream input;
|
||||
try {
|
||||
@@ -35,12 +43,4 @@ public class ProjectProperties {
|
||||
private Properties getCached() {
|
||||
return cached;
|
||||
}
|
||||
|
||||
public static Version getProjectVersion() {
|
||||
return new Version(getInstance().getCached().getProperty("application.version"));
|
||||
}
|
||||
|
||||
public static ProjectProperties getInstance() {
|
||||
return instance == null ? instance = new ProjectProperties() : instance;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.parabot.core.asm;
|
||||
|
||||
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.parabot.core.classpath.ClassPath;
|
||||
@@ -16,17 +15,15 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* Makes classnodes into runnable classes
|
||||
*
|
||||
* @author Everel
|
||||
* @author Matt
|
||||
*
|
||||
*/
|
||||
public class ASMClassLoader extends ClassLoader {
|
||||
|
||||
private Map<String, Class<?>> classCache;
|
||||
public ClassPath classPath;
|
||||
private Map<String, Class<?>> classCache;
|
||||
|
||||
public ASMClassLoader(final ClassPath classPath) {
|
||||
this.classCache = new HashMap<String, Class<?>>();
|
||||
|
||||
@@ -9,11 +9,9 @@ import org.parabot.core.Context;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
/**
|
||||
*
|
||||
* A collection of various asm util methods
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class ASMUtils implements Opcodes {
|
||||
|
||||
@@ -28,7 +26,7 @@ public class ASMUtils implements Opcodes {
|
||||
}
|
||||
|
||||
public static FieldNode getField(ClassNode node, String fieldName, String desc) {
|
||||
if(desc == null) {
|
||||
if (desc == null) {
|
||||
return getField(node, fieldName);
|
||||
}
|
||||
for (final Object fieldNode : node.fields) {
|
||||
@@ -70,6 +68,7 @@ public class ASMUtils implements Opcodes {
|
||||
* Return right opcode for desc
|
||||
*
|
||||
* @param desc
|
||||
*
|
||||
* @return return opcode
|
||||
*/
|
||||
public static int getReturnOpcode(String desc) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.HashMap;
|
||||
|
||||
public class ClassRemapper extends Remapper {
|
||||
private static HashMap<String, String> remapNames = new HashMap<String, String>();
|
||||
|
||||
static {
|
||||
remapNames.put("java/net/Socket", "org/parabot/core/network/proxy/ProxySocket");
|
||||
remapNames.put("java/net/NetworkInterface", "org/parabot/core/network/NetworkInterface");
|
||||
|
||||
@@ -17,9 +17,6 @@ import java.util.Map;
|
||||
public class RedirectClassAdapter extends ClassVisitor implements Opcodes {
|
||||
|
||||
private static final Map<String, Class<?>> redirects = new HashMap<String, Class<?>>();
|
||||
|
||||
private String className;
|
||||
|
||||
private static PrintStream str_out, class_out;
|
||||
|
||||
static {
|
||||
@@ -34,36 +31,47 @@ public class RedirectClassAdapter extends ClassVisitor implements Opcodes {
|
||||
redirects.put("java/lang/System", SystemRedirect.class);
|
||||
}
|
||||
|
||||
private String className;
|
||||
|
||||
public RedirectClassAdapter(ClassVisitor cv) {
|
||||
super(ASM5, cv);
|
||||
if (str_out == null && Core.shouldDump())
|
||||
if (str_out == null && Core.shouldDump()) {
|
||||
try {
|
||||
str_out = new PrintStream(new FileOutputStream(new File(Directories.getWorkspace(),"strings.txt")));
|
||||
str_out = new PrintStream(new FileOutputStream(new File(Directories.getWorkspace(), "strings.txt")));
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(class_out == null && Core.shouldDump())
|
||||
}
|
||||
if (class_out == null && Core.shouldDump()) {
|
||||
try {
|
||||
class_out = new PrintStream(new FileOutputStream(new File(Directories.getWorkspace(),"classes.txt")));
|
||||
class_out = new PrintStream(new FileOutputStream(new File(Directories.getWorkspace(), "classes.txt")));
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static SecurityException createSecurityException() {
|
||||
Exception e = new Exception();
|
||||
StackTraceElement[] elements = e.getStackTrace();
|
||||
return new SecurityException("Unsafe operation blocked. Op:"
|
||||
+ elements[1].getMethodName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(int version, int access, String name, String signature,
|
||||
String superName, String[] interfaces) {
|
||||
this.className = name;
|
||||
super.visit(version, access, name, signature, superName, interfaces);
|
||||
if(class_out != null) {
|
||||
if (class_out != null) {
|
||||
class_out.println(className + " References:");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitEnd(){
|
||||
public void visitEnd() {
|
||||
super.visitEnd();
|
||||
if(class_out != null){
|
||||
if (class_out != null) {
|
||||
class_out.println();
|
||||
class_out.println();
|
||||
}
|
||||
@@ -106,7 +114,7 @@ public class RedirectClassAdapter extends ClassVisitor implements Opcodes {
|
||||
}
|
||||
}
|
||||
|
||||
if(class_out != null) {
|
||||
if (class_out != null) {
|
||||
class_out.println(owner);
|
||||
}
|
||||
|
||||
@@ -115,25 +123,19 @@ public class RedirectClassAdapter extends ClassVisitor implements Opcodes {
|
||||
|
||||
@Override
|
||||
public void visitFieldInsn(int opcode, String owner, String name,
|
||||
String desc){
|
||||
String desc) {
|
||||
if (Core.isSecure() && (opcode == GETSTATIC || opcode == PUTSTATIC)) {
|
||||
if (redirects.containsKey(owner)) {
|
||||
owner = redirects.get(owner).getName()
|
||||
.replaceAll("\\.", "/");
|
||||
}
|
||||
}
|
||||
if(class_out != null)
|
||||
if (class_out != null) {
|
||||
class_out.println(owner);
|
||||
}
|
||||
super.visitFieldInsn(opcode, owner, name, desc);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static SecurityException createSecurityException() {
|
||||
Exception e = new Exception();
|
||||
StackTraceElement[] elements = e.getStackTrace();
|
||||
return new SecurityException("Unsafe operation blocked. Op:"
|
||||
+ elements[1].getMethodName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,27 +1,18 @@
|
||||
package org.parabot.core.asm.adapters;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import org.objectweb.asm.Label;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.InsnList;
|
||||
import org.objectweb.asm.tree.InsnNode;
|
||||
import org.objectweb.asm.tree.JumpInsnNode;
|
||||
import org.objectweb.asm.tree.LabelNode;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.VarInsnNode;
|
||||
import org.objectweb.asm.tree.*;
|
||||
import org.parabot.core.asm.ASMUtils;
|
||||
import org.parabot.core.asm.interfaces.Injectable;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
/**
|
||||
*
|
||||
* Injects a callback, invokes a given static method
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class AddCallbackAdapter implements Injectable, Opcodes {
|
||||
private MethodNode method;
|
||||
@@ -50,11 +41,11 @@ public class AddCallbackAdapter implements Injectable, Opcodes {
|
||||
inject.add(new LabelNode(l0));
|
||||
int offset = 0;
|
||||
for (int arg : args) {
|
||||
if(Modifier.isStatic(method.access)) {
|
||||
if (Modifier.isStatic(method.access)) {
|
||||
int loadOpcode = ASMUtils.getLoadOpcode(types[arg]
|
||||
.getDescriptor());
|
||||
inject.add(new VarInsnNode(loadOpcode, arg + offset));
|
||||
if(loadOpcode == Opcodes.LLOAD) {
|
||||
if (loadOpcode == Opcodes.LLOAD) {
|
||||
offset++;
|
||||
}
|
||||
} else {
|
||||
@@ -65,10 +56,10 @@ public class AddCallbackAdapter implements Injectable, Opcodes {
|
||||
inject.add(new MethodInsnNode(INVOKESTATIC,
|
||||
this.invokeClass, this.invokeMethod,
|
||||
this.desc));
|
||||
if(this.conditional) {
|
||||
if (this.conditional) {
|
||||
LabelNode ln = new LabelNode(new Label());
|
||||
inject.add(new JumpInsnNode(IFEQ, ln));
|
||||
if(Type.getReturnType(method.desc).equals(Type.BOOLEAN_TYPE)) {
|
||||
if (Type.getReturnType(method.desc).equals(Type.BOOLEAN_TYPE)) {
|
||||
inject.add(new InsnNode(ICONST_1));
|
||||
inject.add(new InsnNode(IRETURN));
|
||||
} else {
|
||||
@@ -77,17 +68,17 @@ public class AddCallbackAdapter implements Injectable, Opcodes {
|
||||
inject.add(ln);
|
||||
}
|
||||
|
||||
if(method.name.startsWith("<") && !Modifier.isStatic(method.access)) {
|
||||
if (method.name.startsWith("<") && !Modifier.isStatic(method.access)) {
|
||||
// find target
|
||||
AbstractInsnNode target = null;
|
||||
for(AbstractInsnNode node : this.method.instructions.toArray()) {
|
||||
if(node.getOpcode() == Opcodes.INVOKESPECIAL) {
|
||||
for (AbstractInsnNode node : this.method.instructions.toArray()) {
|
||||
if (node.getOpcode() == Opcodes.INVOKESPECIAL) {
|
||||
target = node;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(target != null) {
|
||||
if (target != null) {
|
||||
this.method.instructions.insert(target, inject);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -2,12 +2,7 @@ package org.parabot.core.asm.adapters;
|
||||
|
||||
import org.objectweb.asm.Label;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.InsnList;
|
||||
import org.objectweb.asm.tree.LabelNode;
|
||||
import org.objectweb.asm.tree.LdcInsnNode;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.*;
|
||||
|
||||
public class AddDebugAdapter {
|
||||
private ClassNode owner;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package org.parabot.core.asm.adapters;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
@@ -11,11 +9,12 @@ import org.parabot.core.Core;
|
||||
import org.parabot.core.asm.ASMUtils;
|
||||
import org.parabot.core.asm.interfaces.Injectable;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
/**
|
||||
* Adds a method into a Classnode which returns a field
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class AddGetterAdapter implements Opcodes, Injectable {
|
||||
private ClassNode into;
|
||||
@@ -28,21 +27,13 @@ public class AddGetterAdapter implements Opcodes, Injectable {
|
||||
private long multiplier;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param into
|
||||
* - classnode to inject getter method in
|
||||
* @param fieldLocation
|
||||
* - classnode where field is located
|
||||
* @param fieldNode
|
||||
* - field name to get
|
||||
* @param methodName
|
||||
* - method name of getter
|
||||
* @param returnDesc
|
||||
* - return type of method, can be null for default return
|
||||
* @param staticMethod
|
||||
* - pass true if you want the method to be static
|
||||
* @param multiplier
|
||||
* - if this field requires a multipli
|
||||
* @param into - classnode to inject getter method in
|
||||
* @param fieldLocation - classnode where field is located
|
||||
* @param fieldNode - field name to get
|
||||
* @param methodName - method name of getter
|
||||
* @param returnDesc - return type of method, can be null for default return
|
||||
* @param staticMethod - pass true if you want the method to be static
|
||||
* @param multiplier - if this field requires a multipli
|
||||
*/
|
||||
public AddGetterAdapter(final ClassNode into,
|
||||
final ClassNode fieldLocation, final FieldNode fieldNode,
|
||||
@@ -59,7 +50,6 @@ public class AddGetterAdapter implements Opcodes, Injectable {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param fieldLocation
|
||||
* @param fieldNode
|
||||
* @param methodName
|
||||
@@ -129,7 +119,7 @@ public class AddGetterAdapter implements Opcodes, Injectable {
|
||||
if (!staticField) {
|
||||
method.visitVarInsn(ALOAD, 0);
|
||||
}
|
||||
if(staticField) {
|
||||
if (staticField) {
|
||||
ASMUtils.makePublic(fieldNode);
|
||||
}
|
||||
method.visitFieldInsn(staticField ? GETSTATIC : GETFIELD,
|
||||
|
||||
@@ -7,11 +7,9 @@ import org.parabot.core.asm.ASMUtils;
|
||||
import org.parabot.core.asm.interfaces.Injectable;
|
||||
|
||||
/**
|
||||
*
|
||||
* This class appends an interface to a class
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class AddInterfaceAdapter implements Injectable {
|
||||
private static String accessorPackage;
|
||||
@@ -29,12 +27,23 @@ public class AddInterfaceAdapter implements Injectable {
|
||||
this.interfaceClass = interfaceClass;
|
||||
}
|
||||
|
||||
public static String getAccessorPackage() {
|
||||
return accessorPackage;
|
||||
}
|
||||
|
||||
public static void setAccessorPackage(String packageName) {
|
||||
accessorPackage = packageName;
|
||||
}
|
||||
|
||||
public static String getAccessorPackage() {
|
||||
return accessorPackage;
|
||||
protected static void addInterface(ClassNode node, String i) {
|
||||
ASMUtils.makePublic(node);
|
||||
for (Object mn : node.methods) {
|
||||
MethodNode methodNode = (MethodNode) mn;
|
||||
if (methodNode.name.startsWith("<init")) {
|
||||
ASMUtils.makePublic(methodNode);
|
||||
}
|
||||
}
|
||||
node.interfaces.add(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,17 +52,6 @@ public class AddInterfaceAdapter implements Injectable {
|
||||
addInterface(node, accessorPackage + interfaceClass);
|
||||
}
|
||||
|
||||
protected static void addInterface(ClassNode node, String i) {
|
||||
ASMUtils.makePublic(node);
|
||||
for(Object mn : node.methods) {
|
||||
MethodNode methodNode = (MethodNode) mn;
|
||||
if(methodNode.name.startsWith("<init")) {
|
||||
ASMUtils.makePublic(methodNode);
|
||||
}
|
||||
}
|
||||
node.interfaces.add(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringBuilder("[Injectable: interface, into classname: ").append(node.name).append(", interface: ").append(accessorPackage).append(interfaceClass).append("]").toString();
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package org.parabot.core.asm.adapters;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
@@ -9,12 +7,12 @@ import org.objectweb.asm.tree.MethodNode;
|
||||
import org.parabot.core.asm.ASMUtils;
|
||||
import org.parabot.core.asm.interfaces.Injectable;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
/**
|
||||
*
|
||||
* Injects a method which invokes an other method
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class AddInvokerAdapter implements Opcodes, Injectable {
|
||||
private ClassNode into;
|
||||
@@ -56,7 +54,7 @@ public class AddInvokerAdapter implements Opcodes, Injectable {
|
||||
MethodNode m = new MethodNode(ACC_PUBLIC, this.methodName,
|
||||
mArgsDesc + this.returnDesc, null, null);
|
||||
|
||||
if(!isInterface) {
|
||||
if (!isInterface) {
|
||||
isStatic = (this.mn.access & ACC_STATIC) != 0;
|
||||
|
||||
if (!Modifier.isPublic(mn.access)) {
|
||||
@@ -71,11 +69,11 @@ public class AddInvokerAdapter implements Opcodes, Injectable {
|
||||
}
|
||||
}
|
||||
|
||||
if(!isStatic || isInterface) {
|
||||
if (!isStatic || isInterface) {
|
||||
m.visitVarInsn(ALOAD, 0);
|
||||
}
|
||||
|
||||
if(instanceCast != null) {
|
||||
if (instanceCast != null) {
|
||||
m.visitTypeInsn(CHECKCAST, instanceCast);
|
||||
}
|
||||
|
||||
@@ -83,11 +81,11 @@ public class AddInvokerAdapter implements Opcodes, Injectable {
|
||||
Type[] castArgs = argsCheckCast == null ? null : Type.getArgumentTypes(argsCheckCast + "V");
|
||||
Type[] methodArgs = Type.getArgumentTypes(argsDesc + "V");
|
||||
|
||||
for(int i = 0; i < methodArgs.length; i++) {
|
||||
for (int i = 0; i < methodArgs.length; i++) {
|
||||
m.visitVarInsn(ASMUtils.getLoadOpcode(methodArgs[i].getDescriptor()), i + 1);
|
||||
if(castArgs != null && !castArgs[i].getDescriptor().equals(methodArgs[i].getDescriptor())) {
|
||||
if (castArgs != null && !castArgs[i].getDescriptor().equals(methodArgs[i].getDescriptor())) {
|
||||
String cast = methodArgs[i].getDescriptor();
|
||||
if(cast.startsWith("L")) {
|
||||
if (cast.startsWith("L")) {
|
||||
cast = cast.substring(1).replace(";", "");
|
||||
}
|
||||
m.visitTypeInsn(CHECKCAST, cast);
|
||||
@@ -95,7 +93,7 @@ public class AddInvokerAdapter implements Opcodes, Injectable {
|
||||
}
|
||||
}
|
||||
|
||||
if(isInterface) {
|
||||
if (isInterface) {
|
||||
m.visitMethodInsn(INVOKEINTERFACE, instanceCast, mName, mDesc);
|
||||
} else {
|
||||
m.visitMethodInsn(isStatic ? INVOKESTATIC : INVOKEVIRTUAL, methodLocation.name, mn.name, mn.desc);
|
||||
|
||||
@@ -11,7 +11,6 @@ import org.parabot.core.asm.interfaces.Injectable;
|
||||
* Injects methods which sets a field
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class AddSetterAdapter implements Opcodes, Injectable {
|
||||
private ClassNode fieldLocation;
|
||||
@@ -38,8 +37,9 @@ public class AddSetterAdapter implements Opcodes, Injectable {
|
||||
|
||||
private static void addSetter(ClassNode fieldLocation, ClassNode into,
|
||||
FieldNode field, String name, String desc, boolean methodStatic) {
|
||||
if (desc.contains("L") && !desc.endsWith("Ljava/lang/String;"))
|
||||
if (desc.contains("L") && !desc.endsWith("Ljava/lang/String;")) {
|
||||
desc = "Ljava/lang/Object;";
|
||||
}
|
||||
MethodNode method = new MethodNode(ACC_PUBLIC
|
||||
| (methodStatic ? ACC_STATIC : 0), name, "(" + desc + ")V",
|
||||
null, null);
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package org.parabot.core.asm.adapters;
|
||||
|
||||
import java.util.ListIterator;
|
||||
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
@@ -11,12 +9,12 @@ import org.parabot.core.Core;
|
||||
import org.parabot.core.asm.ASMUtils;
|
||||
import org.parabot.core.asm.interfaces.Injectable;
|
||||
|
||||
import java.util.ListIterator;
|
||||
|
||||
/**
|
||||
*
|
||||
* This class is used for changing the super class of a class
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class AddSuperAdapter implements Injectable {
|
||||
private ClassNode node;
|
||||
@@ -32,12 +30,6 @@ public class AddSuperAdapter implements Injectable {
|
||||
this.superClass = superClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inject() {
|
||||
Core.verbose("Injecting: " + this.toString());
|
||||
setSuper(node, superClass);
|
||||
}
|
||||
|
||||
private static final void setSuper(final ClassNode node,
|
||||
final String superClass) {
|
||||
ListIterator<?> mli = node.methods.listIterator();
|
||||
@@ -49,7 +41,7 @@ public class AddSuperAdapter implements Injectable {
|
||||
AbstractInsnNode ain = (AbstractInsnNode) ili.next();
|
||||
if (ain.getOpcode() == Opcodes.INVOKESPECIAL) {
|
||||
MethodInsnNode min = (MethodInsnNode) ain;
|
||||
if(!min.owner.equals(node.name)) {
|
||||
if (!min.owner.equals(node.name)) {
|
||||
min.owner = superClass;
|
||||
}
|
||||
break;
|
||||
@@ -60,6 +52,12 @@ public class AddSuperAdapter implements Injectable {
|
||||
node.superName = superClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inject() {
|
||||
Core.verbose("Injecting: " + this.toString());
|
||||
setSuper(node, superClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringBuilder("[Injectable: super, class name: ")
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package org.parabot.core.asm.hooks;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.parabot.core.parsers.hooks.HookParser;
|
||||
import org.parabot.core.parsers.hooks.JSONHookParser;
|
||||
import org.parabot.core.parsers.hooks.XMLHookParser;
|
||||
import org.parabot.environment.api.utils.WebUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
public class HookFile {
|
||||
public static final int TYPE_XML = 0;
|
||||
public static final int TYPE_JSON = 1;
|
||||
@@ -27,7 +27,7 @@ public class HookFile {
|
||||
}
|
||||
|
||||
private void setType(int type) {
|
||||
if(type < 0 || type > 1) {
|
||||
if (type < 0 || type > 1) {
|
||||
throw new IllegalArgumentException("This type does not exist");
|
||||
}
|
||||
this.type = type;
|
||||
@@ -38,7 +38,7 @@ public class HookFile {
|
||||
}
|
||||
|
||||
public HookParser getParser() {
|
||||
switch(type) {
|
||||
switch (type) {
|
||||
case TYPE_XML:
|
||||
return new XMLHookParser(this);
|
||||
case TYPE_JSON:
|
||||
|
||||
@@ -2,8 +2,8 @@ package org.parabot.core.asm.interfaces;
|
||||
|
||||
/**
|
||||
* Injectable
|
||||
* @author Everel
|
||||
*
|
||||
* @author Everel
|
||||
*/
|
||||
public interface Injectable {
|
||||
|
||||
|
||||
@@ -12,11 +12,11 @@ public class ClassLoaderRedirect extends ClassLoader {
|
||||
|
||||
static int count = 0;
|
||||
|
||||
public static Class<?>loadClass(ClassLoader c,String name){
|
||||
public static Class<?> loadClass(ClassLoader c, String name) {
|
||||
throw RedirectClassAdapter.createSecurityException();
|
||||
}
|
||||
|
||||
public static ClassLoader getParent(ClassLoader c){
|
||||
public static ClassLoader getParent(ClassLoader c) {
|
||||
throw RedirectClassAdapter.createSecurityException();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,9 +8,22 @@ import java.io.InputStream;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.ProtectionDomain;
|
||||
|
||||
public class ClassRedirect {
|
||||
|
||||
public static ProtectionDomain getProtectionDomain(final Class<?> clazz) {
|
||||
System.err.println(clazz.getName() + " getProtectionDomain request granted.");
|
||||
|
||||
return AccessController.doPrivileged(new PrivilegedAction<ProtectionDomain>() {
|
||||
public ProtectionDomain run() {
|
||||
return clazz.getProtectionDomain();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static Object newInstance(Class<?> c) throws IllegalAccessException, InstantiationException {
|
||||
if (validStack()) {
|
||||
return c.newInstance();
|
||||
@@ -136,9 +149,10 @@ public class ClassRedirect {
|
||||
private static boolean validStack() {
|
||||
Exception e = new Exception();
|
||||
for (StackTraceElement elem : e.getStackTrace()) {
|
||||
if (elem.getClassName().equals(Script.class.getName()))
|
||||
if (elem.getClassName().equals(Script.class.getName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.ArrayList;
|
||||
/**
|
||||
* @author JKetelaar
|
||||
*/
|
||||
public class FileRedirect extends File{
|
||||
public class FileRedirect extends File {
|
||||
|
||||
private static ArrayList<String> cachedFiles = new ArrayList<>();
|
||||
|
||||
@@ -35,57 +35,57 @@ public class FileRedirect extends File{
|
||||
sout(uri.toString());
|
||||
}
|
||||
|
||||
public static boolean exists(File file){
|
||||
public static boolean exists(File file) {
|
||||
sout(file.toString());
|
||||
return file.exists();
|
||||
}
|
||||
|
||||
public static boolean isFile(File file){
|
||||
public static boolean isFile(File file) {
|
||||
sout(file.toString());
|
||||
return file.isFile();
|
||||
}
|
||||
|
||||
public static long length(File file){
|
||||
public static long length(File file) {
|
||||
sout(file.toString());
|
||||
return file.length();
|
||||
}
|
||||
|
||||
public static boolean mkdirs(File file){
|
||||
public static boolean mkdirs(File file) {
|
||||
sout(file.toString());
|
||||
return file.mkdirs();
|
||||
}
|
||||
|
||||
public static boolean mkdir(File file){
|
||||
public static boolean mkdir(File file) {
|
||||
sout(file.toString());
|
||||
return file.mkdir();
|
||||
}
|
||||
|
||||
public static boolean isDirectory(File file){
|
||||
public static boolean isDirectory(File file) {
|
||||
sout(file.toString());
|
||||
return file.isDirectory();
|
||||
}
|
||||
|
||||
public static String getAbsolutePath(File file){
|
||||
public static String getAbsolutePath(File file) {
|
||||
sout(file.toString());
|
||||
return file.getAbsolutePath();
|
||||
}
|
||||
|
||||
public static File getAbsoluteFile(File file){
|
||||
public static File getAbsoluteFile(File file) {
|
||||
sout(file.toString());
|
||||
return file.getAbsoluteFile();
|
||||
}
|
||||
|
||||
public static File[] listFiles(File file){
|
||||
public static File[] listFiles(File file) {
|
||||
sout(file.toString());
|
||||
return file.listFiles();
|
||||
}
|
||||
|
||||
public static String getName(File file){
|
||||
public static String getName(File file) {
|
||||
sout(file.getName());
|
||||
return file.getName();
|
||||
}
|
||||
|
||||
private static void sout(String s){
|
||||
private static void sout(String s) {
|
||||
if (!cachedFiles.contains(s)) {
|
||||
Core.verbose("Server requested file: " + s);
|
||||
cachedFiles.add(s);
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.parabot.core.asm.redirect;
|
||||
|
||||
public class PacketCallback {
|
||||
|
||||
public static void onPacket(String methodName,int value){
|
||||
public static void onPacket(String methodName, int value) {
|
||||
System.out.println(methodName + "(" + value + ")");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.parabot.core.asm.redirect;
|
||||
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.core.Directories;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
@@ -1,66 +1,64 @@
|
||||
package org.parabot.core.asm.redirect;
|
||||
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.core.asm.RedirectClassAdapter;
|
||||
|
||||
public class ThreadRedirect {
|
||||
|
||||
private static int count = 0;
|
||||
|
||||
public static void start(Thread t){
|
||||
public static void start(Thread t) {
|
||||
t.start();
|
||||
}
|
||||
|
||||
public static void setPriority(Thread t,int i){
|
||||
public static void setPriority(Thread t, int i) {
|
||||
t.setPriority(i);
|
||||
}
|
||||
|
||||
public static void setDaemon(Thread t,boolean b){
|
||||
public static void setDaemon(Thread t, boolean b) {
|
||||
t.setDaemon(b);
|
||||
}
|
||||
|
||||
public static void interrupt(Thread t){
|
||||
public static void interrupt(Thread t) {
|
||||
t.interrupt();
|
||||
}
|
||||
|
||||
public static Thread currentThread(){
|
||||
return null;
|
||||
public static Thread currentThread() {
|
||||
return new Thread();
|
||||
}
|
||||
|
||||
public static void join(Thread t) throws InterruptedException{
|
||||
public static void join(Thread t) throws InterruptedException {
|
||||
t.join();
|
||||
}
|
||||
|
||||
public static void join(Thread t,long l) throws InterruptedException{
|
||||
public static void join(Thread t, long l) throws InterruptedException {
|
||||
t.join(l);
|
||||
}
|
||||
|
||||
public static void join(Thread t, long l,int i) throws InterruptedException{
|
||||
public static void join(Thread t, long l, int i) throws InterruptedException {
|
||||
t.join(l, i);
|
||||
}
|
||||
|
||||
public static ClassLoader getContextClassLoader(Thread t){
|
||||
public static ClassLoader getContextClassLoader(Thread t) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ThreadGroup getThreadGroup(Thread t){
|
||||
public static ThreadGroup getThreadGroup(Thread t) {
|
||||
throw RedirectClassAdapter.createSecurityException();
|
||||
}
|
||||
|
||||
public static void setName(Thread t, String name){
|
||||
public static void setName(Thread t, String name) {
|
||||
t.setName(name);
|
||||
}
|
||||
|
||||
public static String getName(Thread t){
|
||||
public static String getName(Thread t) {
|
||||
return t.getName();
|
||||
}
|
||||
|
||||
public static void sleep(long time) throws InterruptedException{
|
||||
public static void sleep(long time) throws InterruptedException {
|
||||
Thread.sleep(time);
|
||||
}
|
||||
|
||||
|
||||
public static void setUncaughtExceptionHandler(Thread t, Thread.UncaughtExceptionHandler handler){
|
||||
public static void setUncaughtExceptionHandler(Thread t, Thread.UncaughtExceptionHandler handler) {
|
||||
t.setUncaughtExceptionHandler(handler);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.awt.datatransfer.Clipboard;
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||
import java.awt.image.ImageProducer;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
@@ -12,7 +13,7 @@ public class ToolkitRedirect {
|
||||
|
||||
private static final Clipboard clipboard = new Clipboard("default");
|
||||
|
||||
static{
|
||||
static {
|
||||
clipboard.setContents(new Transferable() {
|
||||
@Override
|
||||
public DataFlavor[] getTransferDataFlavors() {
|
||||
@@ -31,43 +32,47 @@ public class ToolkitRedirect {
|
||||
}, null);
|
||||
}
|
||||
|
||||
public static Toolkit getDefaultToolkit(){
|
||||
public static Toolkit getDefaultToolkit() {
|
||||
return Toolkit.getDefaultToolkit();
|
||||
}
|
||||
|
||||
public static Dimension getScreenSize(Toolkit t){
|
||||
return new Dimension(0,0);
|
||||
public static Dimension getScreenSize(Toolkit t) {
|
||||
return new Dimension(0, 0);
|
||||
}
|
||||
|
||||
public static Image createImage(Toolkit t,byte[] b){
|
||||
return null;
|
||||
public static Image createImage(Toolkit t, byte[] b) {
|
||||
return t.createImage(b);
|
||||
}
|
||||
|
||||
public static Image createImage(Toolkit t, String s){
|
||||
return null;
|
||||
public static Image createImage(Toolkit t, String s) {
|
||||
return t.createImage(s);
|
||||
}
|
||||
|
||||
public static Image getImage(Toolkit t,URL u){
|
||||
public static Image createImage(Toolkit t, ImageProducer i) {
|
||||
return t.createImage(i);
|
||||
}
|
||||
|
||||
public static Image getImage(Toolkit t, URL u) {
|
||||
return t.getImage(u);
|
||||
}
|
||||
|
||||
public static Image getImage(Toolkit t,String str){
|
||||
public static Image getImage(Toolkit t, String str) {
|
||||
return t.getImage(str);
|
||||
}
|
||||
|
||||
public static Cursor createCustomCursor(Toolkit t, Image i, Point p, String s){
|
||||
public static Cursor createCustomCursor(Toolkit t, Image i, Point p, String s) {
|
||||
return Cursor.getDefaultCursor();
|
||||
}
|
||||
|
||||
public static Clipboard getSystemClipboard(Toolkit toolkit){
|
||||
public static Clipboard getSystemClipboard(Toolkit toolkit) {
|
||||
return clipboard;
|
||||
}
|
||||
|
||||
public static void sync(Toolkit toolkit){
|
||||
public static void sync(Toolkit toolkit) {
|
||||
toolkit.sync();
|
||||
}
|
||||
|
||||
public static void sync(){
|
||||
public static void sync() {
|
||||
Toolkit.getDefaultToolkit().sync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@ package org.parabot.core.asm.redirect;
|
||||
/**
|
||||
* @author JKetelaar
|
||||
*/
|
||||
public class URLRedirect{
|
||||
public class URLRedirect {
|
||||
|
||||
}
|
||||
@@ -6,11 +6,9 @@ import org.parabot.core.asm.adapters.AddCallbackAdapter;
|
||||
import org.parabot.core.asm.interfaces.Injectable;
|
||||
|
||||
/**
|
||||
*
|
||||
* This class is used for injecting a callback into a methodnode
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class Callback implements Injectable {
|
||||
private MethodNode method;
|
||||
@@ -35,7 +33,7 @@ public class Callback implements Injectable {
|
||||
this.args[i] = Integer.parseInt(strArgs[i]);
|
||||
}
|
||||
} else {
|
||||
this.args = new int[] { Integer.parseInt(args) };
|
||||
this.args = new int[]{ Integer.parseInt(args) };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,11 +8,9 @@ import org.parabot.core.asm.adapters.AddGetterAdapter;
|
||||
import org.parabot.core.asm.interfaces.Injectable;
|
||||
|
||||
/**
|
||||
*
|
||||
* This class injects a getter which gets a specific field
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class Getter implements Injectable {
|
||||
private ClassNode into;
|
||||
@@ -24,7 +22,6 @@ public class Getter implements Injectable {
|
||||
private long multiplier;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param into - classnode to inject getter method in
|
||||
* @param fieldLocation - classnode where field is located
|
||||
* @param fieldNode - field name to get
|
||||
@@ -48,7 +45,6 @@ public class Getter implements Injectable {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param fieldLocation
|
||||
* @param fieldNode
|
||||
* @param methodName
|
||||
@@ -64,6 +60,7 @@ public class Getter implements Injectable {
|
||||
|
||||
/**
|
||||
* Short route for getAdaptar().inject();
|
||||
*
|
||||
* @see AddGetterAdapter#inject
|
||||
*/
|
||||
@Override
|
||||
@@ -73,6 +70,7 @@ public class Getter implements Injectable {
|
||||
|
||||
/**
|
||||
* Gets the AddGetterAdapter
|
||||
*
|
||||
* @return AddGetterAdapter
|
||||
*/
|
||||
public AddGetterAdapter getAdapter() {
|
||||
|
||||
@@ -4,11 +4,9 @@ import org.parabot.core.asm.adapters.AddInterfaceAdapter;
|
||||
import org.parabot.core.asm.interfaces.Injectable;
|
||||
|
||||
/**
|
||||
*
|
||||
* This class appends an interface to a class
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class Interface implements Injectable {
|
||||
private String className;
|
||||
@@ -30,6 +28,7 @@ public class Interface implements Injectable {
|
||||
|
||||
/**
|
||||
* Gets the add interface adapter
|
||||
*
|
||||
* @return AddInterface adapter
|
||||
*/
|
||||
public AddInterfaceAdapter getAdapter() {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.parabot.core.asm.wrappers;
|
||||
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.parabot.core.asm.ASMUtils;
|
||||
@@ -7,11 +8,9 @@ import org.parabot.core.asm.adapters.AddInvokerAdapter;
|
||||
import org.parabot.core.asm.interfaces.Injectable;
|
||||
|
||||
/**
|
||||
*
|
||||
* This class is used for injecting an invoker into a methodnode
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class Invoker implements Injectable {
|
||||
private ClassNode into;
|
||||
@@ -37,7 +36,7 @@ public class Invoker implements Injectable {
|
||||
String argsDesc, String returnDesc, String methodName, boolean isInterface, String instanceCast, String argsCheckCastDesc) {
|
||||
this.into = ASMUtils.getClass(into);
|
||||
this.methodLocation = ASMUtils.getClass(methodLoc);
|
||||
this.mn = getMethod(this.methodLocation, invMethName, argsDesc);
|
||||
this.mn = getMethod(this.methodLocation, invMethName, argsDesc, returnDesc);
|
||||
this.returnDesc = returnDesc;
|
||||
this.methodName = methodName;
|
||||
this.argsDesc = argsDesc;
|
||||
@@ -49,12 +48,12 @@ public class Invoker implements Injectable {
|
||||
this.argsCheckCastDesc = argsCheckCastDesc;
|
||||
}
|
||||
|
||||
private static MethodNode getMethod(ClassNode into, String name, String desc) {
|
||||
for (Object m : into.methods) {
|
||||
MethodNode methodNode = (MethodNode) m;
|
||||
String s = methodNode.desc.substring(0, methodNode.desc.indexOf(')') + 1);
|
||||
if (methodNode.name.equals(name) && s.equals(desc)) {
|
||||
return methodNode;
|
||||
private static MethodNode getMethod(ClassNode into, String name, String argsDesc, String returnDesc) {
|
||||
for (Object method : into.methods) {
|
||||
MethodNode m = (MethodNode) method;
|
||||
if (m.name.equals(name) && m.desc.substring(0, m.desc.indexOf(')') + 1).equals(argsDesc)
|
||||
&& (returnDesc == null || Type.getType(m.desc).getReturnType().getDescriptor().equals(returnDesc))) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -7,11 +7,9 @@ import org.parabot.core.asm.adapters.AddSetterAdapter;
|
||||
import org.parabot.core.asm.interfaces.Injectable;
|
||||
|
||||
/**
|
||||
*
|
||||
* This class is used for injecting a setter for a specific field
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class Setter implements Injectable {
|
||||
private ClassNode fieldLocation;
|
||||
@@ -37,6 +35,7 @@ public class Setter implements Injectable {
|
||||
|
||||
/**
|
||||
* Short route for getAdaptar().inject();
|
||||
*
|
||||
* @see AddSetterAdapter#inject
|
||||
*/
|
||||
@Override
|
||||
@@ -46,6 +45,7 @@ public class Setter implements Injectable {
|
||||
|
||||
/**
|
||||
* Gets the AddGetterAdapter
|
||||
*
|
||||
* @return AddGetterAdapter
|
||||
*/
|
||||
public AddSetterAdapter getAdapter() {
|
||||
|
||||
@@ -2,12 +2,11 @@ package org.parabot.core.asm.wrappers;
|
||||
|
||||
import org.parabot.core.asm.adapters.AddSuperAdapter;
|
||||
import org.parabot.core.asm.interfaces.Injectable;
|
||||
|
||||
/**
|
||||
*
|
||||
* This class is used for changing the super class of a class
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class Super implements Injectable {
|
||||
private String className;
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package org.parabot.core.build;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class used for adding urls to the buildpath
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class BuildPath extends org.parabot.api.io.build.BuildPath {
|
||||
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
package org.parabot.core.classpath;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.commons.RemappingClassAdapter;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.parabot.core.Directories;
|
||||
import org.parabot.core.asm.ClassRemapper;
|
||||
import org.parabot.core.asm.RedirectClassAdapter;
|
||||
import org.parabot.core.build.BuildPath;
|
||||
import org.parabot.core.io.SizeInputStream;
|
||||
import org.parabot.core.ui.components.VerboseLoader;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
@@ -20,17 +25,6 @@ import java.util.jar.JarOutputStream;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.commons.RemappingClassAdapter;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.parabot.core.Directories;
|
||||
import org.parabot.core.asm.ClassRemapper;
|
||||
import org.parabot.core.asm.RedirectClassAdapter;
|
||||
import org.parabot.core.build.BuildPath;
|
||||
import org.parabot.core.io.SizeInputStream;
|
||||
import org.parabot.core.ui.components.VerboseLoader;
|
||||
|
||||
/**
|
||||
* Manages, parses and dumps class files & jars
|
||||
*
|
||||
@@ -47,7 +41,6 @@ public class ClassPath {
|
||||
private boolean parseJar;
|
||||
private ArrayList<URL> jarFiles;
|
||||
|
||||
|
||||
public ClassPath() {
|
||||
this(false);
|
||||
}
|
||||
@@ -92,8 +85,9 @@ public class ClassPath {
|
||||
final ZipInputStream zin = new ZipInputStream(sizeInputStream);
|
||||
ZipEntry e;
|
||||
while ((e = zin.getNextEntry()) != null) {
|
||||
if (e.isDirectory())
|
||||
if (e.isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
if (e.getName().endsWith(".class")) {
|
||||
loadClass(zin);
|
||||
} else {
|
||||
@@ -108,13 +102,10 @@ public class ClassPath {
|
||||
VerboseLoader.get().onProgressUpdate(100);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Adds a jar to this classpath
|
||||
*
|
||||
* @param url
|
||||
* - in string format
|
||||
* @param url - in string format
|
||||
*/
|
||||
public void addJar(final String url) {
|
||||
try {
|
||||
@@ -135,10 +126,11 @@ public class ClassPath {
|
||||
|
||||
/**
|
||||
* Finds and loads all classes/jar files in folder
|
||||
*
|
||||
* @param directory
|
||||
*/
|
||||
public void addClasses(final File directory) {
|
||||
if(directory == null || !directory.isDirectory()) {
|
||||
if (directory == null || !directory.isDirectory()) {
|
||||
throw new IllegalArgumentException("Not a valid directory.");
|
||||
}
|
||||
addClasses(directory, null);
|
||||
@@ -147,13 +139,13 @@ public class ClassPath {
|
||||
/**
|
||||
* Finds and loads all classes/jar files in folder
|
||||
*
|
||||
* @param f
|
||||
* to find class / jar files
|
||||
* @param f to find class / jar files
|
||||
* @param root
|
||||
*/
|
||||
public void addClasses(final File f, File root) {
|
||||
if (f == null)
|
||||
if (f == null) {
|
||||
return;
|
||||
}
|
||||
if (!f.exists()) {
|
||||
f.mkdirs();
|
||||
}
|
||||
@@ -167,9 +159,9 @@ public class ClassPath {
|
||||
addClasses(f1, root);
|
||||
} else {
|
||||
try (FileInputStream fin = new FileInputStream(f1)) {
|
||||
if (f1.getName().endsWith(".class"))
|
||||
if (f1.getName().endsWith(".class")) {
|
||||
loadClass(fin);
|
||||
else if (f.equals(root) && f1.getName().endsWith(".jar")) {
|
||||
} else if (f.equals(root) && f1.getName().endsWith(".jar")) {
|
||||
jarFiles.add(f1.toURI().toURL());
|
||||
if (this.parseJar) {
|
||||
// if enabled, there may be problem with duplicate
|
||||
@@ -192,20 +184,19 @@ public class ClassPath {
|
||||
* Loads class from input stream
|
||||
*
|
||||
* @param in
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
protected void loadClass(InputStream in) throws IOException {
|
||||
ClassReader cr = new ClassReader(in);
|
||||
ClassNode cn = new ClassNode();
|
||||
RemappingClassAdapter rca = new RemappingClassAdapter(cn,classRemapper);
|
||||
RemappingClassAdapter rca = new RemappingClassAdapter(cn, classRemapper);
|
||||
RedirectClassAdapter redir = new RedirectClassAdapter(rca);
|
||||
cr.accept(redir, ClassReader.EXPAND_FRAMES);
|
||||
classNames.add(cn.name.replace('/', '.'));
|
||||
classes.put(cn.name, cn);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Determines if this classpath represents a jar file
|
||||
*
|
||||
@@ -236,6 +227,7 @@ public class ClassPath {
|
||||
* @param classPath
|
||||
* @param name
|
||||
* @param inputstream
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
private void loadResource(final String name, final InputStream in)
|
||||
@@ -246,8 +238,9 @@ public class ClassPath {
|
||||
try (OutputStream out = new FileOutputStream(f)) {
|
||||
byte[] buffer = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buffer)) != -1)
|
||||
while ((len = in.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, len);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
}
|
||||
this.resources.put(name, f);
|
||||
@@ -284,6 +277,7 @@ public class ClassPath {
|
||||
|
||||
/**
|
||||
* Dumps this classPath classes to a jar file
|
||||
*
|
||||
* @param stream
|
||||
*/
|
||||
public void dump(final FileOutputStream stream) {
|
||||
@@ -296,7 +290,7 @@ public class ClassPath {
|
||||
cn.accept(cw);
|
||||
out.write(cw.toByteArray());
|
||||
}
|
||||
for(Entry<String, File> entry : this.resources.entrySet()) {
|
||||
for (Entry<String, File> entry : this.resources.entrySet()) {
|
||||
JarEntry je = new JarEntry(entry.getKey());
|
||||
out.putNextEntry(je);
|
||||
out.write(Files.readAllBytes(entry.getValue().toPath()));
|
||||
|
||||
@@ -4,7 +4,6 @@ package org.parabot.core.desc;
|
||||
* Holds information about a script
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class ScriptDescription implements Comparable<ScriptDescription> {
|
||||
public String scriptName;
|
||||
@@ -109,7 +108,7 @@ public class ScriptDescription implements Comparable<ScriptDescription> {
|
||||
.append(this.category).append(", version: ")
|
||||
.append(this.version).append(", description: ")
|
||||
.append(this.description).append(", servers: ");
|
||||
if(this.servers != null) {
|
||||
if (this.servers != null) {
|
||||
for (int i = 0; i < this.servers.length; i++) {
|
||||
b.append(this.servers[i]);
|
||||
if (i < (this.servers.length - 1)) {
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package org.parabot.core.desc;
|
||||
|
||||
/**
|
||||
*
|
||||
* Holds information about a server
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class ServerDescription implements Comparable<ServerDescription> {
|
||||
private String serverName;
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
package org.parabot.core.desc;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import org.parabot.core.Configuration;
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.core.ui.utils.UILog;
|
||||
import org.parabot.environment.api.utils.WebUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
@@ -22,7 +19,6 @@ import java.util.zip.CRC32;
|
||||
* Gets the information for the selected server provider
|
||||
*
|
||||
* @author Paradox, Everel
|
||||
*
|
||||
*/
|
||||
public class ServerProviderInfo {
|
||||
|
||||
@@ -39,10 +35,10 @@ public class ServerProviderInfo {
|
||||
JSONObject jsonObject = (JSONObject) WebUtil.getJsonParser().parse(br);
|
||||
for (Object o : jsonObject.entrySet()) {
|
||||
Map.Entry<?, ?> pairs = (Map.Entry<?, ?>) o;
|
||||
if (String.valueOf(pairs.getKey()).equalsIgnoreCase("settings")){
|
||||
if (String.valueOf(pairs.getKey()).equalsIgnoreCase("settings")) {
|
||||
JSONObject object = (JSONObject) pairs.getValue();
|
||||
parseSettings(object);
|
||||
}else {
|
||||
} else {
|
||||
properties.put(String.valueOf(pairs.getKey()), String.valueOf(pairs.getValue()));
|
||||
}
|
||||
}
|
||||
@@ -54,7 +50,7 @@ public class ServerProviderInfo {
|
||||
}
|
||||
}
|
||||
|
||||
public ServerProviderInfo(String clientJar, String hooks, String name, String clientClass, int bankTabs){
|
||||
public ServerProviderInfo(String clientJar, String hooks, String name, String clientClass, int bankTabs) {
|
||||
this.properties = new Properties();
|
||||
this.settings = new HashMap<>();
|
||||
|
||||
@@ -75,15 +71,15 @@ public class ServerProviderInfo {
|
||||
this.properties.setProperty("bank_tabs", String.valueOf(bankTabs));
|
||||
}
|
||||
|
||||
private long getCRC32(String name, String type){
|
||||
private long getCRC32(String name, String type) {
|
||||
CRC32 crc = new CRC32();
|
||||
name += "-" + type;
|
||||
crc.update(name.getBytes());
|
||||
return crc.getValue();
|
||||
}
|
||||
|
||||
private void parseSettings(JSONObject object){
|
||||
for (Object settingObject : object.entrySet()){
|
||||
private void parseSettings(JSONObject object) {
|
||||
for (Object settingObject : object.entrySet()) {
|
||||
Map.Entry<?, ?> settingValue = (Map.Entry<?, ?>) settingObject;
|
||||
String key = (String) settingValue.getKey();
|
||||
long value = (Long) settingValue.getValue();
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
package org.parabot.core.forum;
|
||||
|
||||
import org.parabot.core.Core;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class which holds parabot forum account user and pass, only specific classes
|
||||
* have access to it unless it's a modified version of parabot intended to
|
||||
* steal user information.
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class Account {
|
||||
private String username;
|
||||
@@ -20,7 +16,6 @@ public class Account {
|
||||
private String api;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param username - Forum account username
|
||||
* @param password - Forum account password
|
||||
*/
|
||||
@@ -37,6 +32,7 @@ public class Account {
|
||||
|
||||
/**
|
||||
* Gets user's parabot account name
|
||||
*
|
||||
* @return username.
|
||||
*/
|
||||
public String getUsername() {
|
||||
@@ -45,6 +41,7 @@ public class Account {
|
||||
|
||||
/**
|
||||
* Gets user's parabot password
|
||||
*
|
||||
* @return password.
|
||||
*/
|
||||
public String getPassword() {
|
||||
@@ -53,9 +50,10 @@ public class Account {
|
||||
|
||||
/**
|
||||
* Gets user's parabot account name
|
||||
*
|
||||
* @return username, already URL UTF-8 encoded.
|
||||
*/
|
||||
public String getURLUsername(){
|
||||
public String getURLUsername() {
|
||||
try {
|
||||
return URLEncoder.encode(this.username, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
@@ -66,9 +64,10 @@ public class Account {
|
||||
|
||||
/**
|
||||
* Gets user's password
|
||||
*
|
||||
* @return password, already URL UTF-8 encoded.
|
||||
*/
|
||||
public String getURLPassword(){
|
||||
public String getURLPassword() {
|
||||
try {
|
||||
return URLEncoder.encode(this.password, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.util.ArrayList;
|
||||
* Handles logging in to parabot forum, only certain classes may use this class.
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public final class AccountManager {
|
||||
private static boolean validated;
|
||||
@@ -69,7 +68,7 @@ public final class AccountManager {
|
||||
throw new IllegalStateException("Already logged in.");
|
||||
}
|
||||
JSONObject result = null;
|
||||
if (!requestTwoStep){
|
||||
if (!requestTwoStep) {
|
||||
try {
|
||||
BufferedReader contents = WebUtil.getReader(WebUtil.getConnection(
|
||||
new URL(Configuration.LOGIN_SERVER),
|
||||
@@ -82,7 +81,7 @@ public final class AccountManager {
|
||||
t.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
try {
|
||||
String two = JOptionPane.showInputDialog("Please provide your two factor authentication code\nYou can find this in either your email or the app you've setup");
|
||||
if (two != null && two.length() > 0) {
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package org.parabot.core.forum;
|
||||
|
||||
/**
|
||||
*
|
||||
* Gives access to account details
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public interface AccountManagerAccess {
|
||||
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package org.parabot.core.io;
|
||||
|
||||
/**
|
||||
*
|
||||
* Keeps track of a progress
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public interface ProgressListener extends org.parabot.api.io.ProgressListener{
|
||||
public interface ProgressListener extends org.parabot.api.io.ProgressListener {
|
||||
|
||||
}
|
||||
|
||||
@@ -4,9 +4,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class SizeInputStream extends InputStream {
|
||||
public int bytesRead;
|
||||
@@ -50,8 +48,8 @@ public class SizeInputStream extends InputStream {
|
||||
}
|
||||
|
||||
private void updateListener() {
|
||||
if(l != null) {
|
||||
double percent = ( bytesRead / size) * 100.0D;
|
||||
if (l != null) {
|
||||
double percent = (bytesRead / size) * 100.0D;
|
||||
l.onProgressUpdate(percent);
|
||||
|
||||
long curTime = System.currentTimeMillis();
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package org.parabot.core.lib;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public abstract class Library extends org.parabot.api.io.libraries.Library {
|
||||
|
||||
|
||||
@@ -1,24 +1,26 @@
|
||||
package org.parabot.core.lib.javafx;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.core.Directories;
|
||||
import org.parabot.core.build.BuildPath;
|
||||
import org.parabot.core.lib.Library;
|
||||
import org.parabot.environment.api.utils.JavaUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
*
|
||||
* Jython util class
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class JavaFX extends Library {
|
||||
private static boolean valid;
|
||||
|
||||
public static boolean isValid() {
|
||||
return valid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
if (!hasJar()) {
|
||||
@@ -69,8 +71,4 @@ public class JavaFX extends Library {
|
||||
public String getLibraryName() {
|
||||
return "JavaFX";
|
||||
}
|
||||
|
||||
public static boolean isValid() {
|
||||
return valid;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.util.Enumeration;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
public class NetworkInterface {
|
||||
public static byte[] mac = new byte[] { 11, 11, 11, 11, 11, 11 };
|
||||
public static byte[] mac = new byte[]{ 11, 11, 11, 11, 11, 11 };
|
||||
private static byte[] realMac;
|
||||
private static NetworkInterface cached;
|
||||
|
||||
@@ -18,16 +18,13 @@ public class NetworkInterface {
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] getHardwareAddress() {
|
||||
return mac;
|
||||
}
|
||||
|
||||
public static Enumeration<NetworkInterface> getNetworkInterfaces()
|
||||
throws SocketException {
|
||||
final ArrayList<NetworkInterface> netifs = new ArrayList<>();
|
||||
|
||||
return new Enumeration<NetworkInterface>() {
|
||||
private int i = 0;
|
||||
|
||||
public NetworkInterface nextElement() {
|
||||
if (i < netifs.size()) {
|
||||
NetworkInterface netif = netifs.get(i++);
|
||||
@@ -43,9 +40,10 @@ public class NetworkInterface {
|
||||
};
|
||||
}
|
||||
|
||||
public static byte[] getRealHardwareAddress() throws SocketException{
|
||||
if (realMac != null)
|
||||
public static byte[] getRealHardwareAddress() throws SocketException {
|
||||
if (realMac != null) {
|
||||
return realMac;
|
||||
}
|
||||
try {
|
||||
return realMac = java.net.NetworkInterface.getByInetAddress(
|
||||
InetAddress.getLocalHost()).getHardwareAddress();
|
||||
@@ -55,8 +53,9 @@ public class NetworkInterface {
|
||||
}
|
||||
|
||||
public static NetworkInterface getByInetAddress(InetAddress addr) {
|
||||
if (cached == null)
|
||||
if (cached == null) {
|
||||
cached = new NetworkInterface();
|
||||
}
|
||||
return cached;
|
||||
}
|
||||
|
||||
@@ -65,13 +64,18 @@ public class NetworkInterface {
|
||||
mac = mac2;
|
||||
}
|
||||
|
||||
public static String formatMac(byte[] mac){
|
||||
public static String formatMac(byte[] mac) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
for(int i = 0; i < 6;i++){
|
||||
for (int i = 0; i < 6; i++) {
|
||||
b.append(String.format("%02X", mac[i]));
|
||||
if(i < 5)
|
||||
if (i < 5) {
|
||||
b.append(':');
|
||||
}
|
||||
}
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
public byte[] getHardwareAddress() {
|
||||
return mac;
|
||||
}
|
||||
}
|
||||
@@ -4,36 +4,41 @@ import java.io.IOException;
|
||||
|
||||
public class Runtime {
|
||||
|
||||
private static Runtime cached;
|
||||
private java.lang.Runtime rt;
|
||||
|
||||
private static Runtime cached;
|
||||
|
||||
private Runtime(java.lang.Runtime rt){
|
||||
private Runtime(java.lang.Runtime rt) {
|
||||
this.rt = rt;
|
||||
}
|
||||
|
||||
public static Runtime getRuntime() {
|
||||
if (cached == null) {
|
||||
cached = new Runtime(java.lang.Runtime.getRuntime());
|
||||
}
|
||||
return cached;
|
||||
}
|
||||
|
||||
public void addShutdownHook(Thread t){
|
||||
public void addShutdownHook(Thread t) {
|
||||
rt.addShutdownHook(t);
|
||||
}
|
||||
|
||||
public int availableProcessors(){
|
||||
public int availableProcessors() {
|
||||
return rt.availableProcessors();
|
||||
}
|
||||
|
||||
public void exit(int i){
|
||||
public void exit(int i) {
|
||||
rt.exit(i);
|
||||
}
|
||||
|
||||
public Process exec(String str) throws IOException{
|
||||
public Process exec(String str) throws IOException {
|
||||
System.out.println("RT:" + str);
|
||||
System.out.println("RT:" + str);
|
||||
return rt.exec(str);
|
||||
}
|
||||
|
||||
public Process exec(String[] cmdarray) throws IOException{
|
||||
public Process exec(String[] cmdarray) throws IOException {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for(int i = 0; i < cmdarray.length;i++){
|
||||
for (int i = 0; i < cmdarray.length; i++) {
|
||||
sb.append(cmdarray[i] + (i < cmdarray.length - 1 ? "," : ""));
|
||||
}
|
||||
System.out.println("RT: {" + sb + "}");
|
||||
@@ -49,18 +54,12 @@ public class Runtime {
|
||||
return rt.totalMemory();
|
||||
}
|
||||
|
||||
public void gc(){
|
||||
public void gc() {
|
||||
rt.gc();
|
||||
}
|
||||
|
||||
public long maxMemory(){
|
||||
public long maxMemory() {
|
||||
return rt.maxMemory();
|
||||
}
|
||||
|
||||
public static Runtime getRuntime(){
|
||||
if(cached == null)
|
||||
cached = new Runtime(java.lang.Runtime.getRuntime());
|
||||
return cached;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,38 +11,16 @@ import java.util.List;
|
||||
|
||||
public class ProxySocket extends Socket {
|
||||
|
||||
public static boolean auth = false;
|
||||
private static List<ProxySocket> connections = new ArrayList<ProxySocket>();
|
||||
|
||||
private static ProxyType proxyType = ProxyType.NONE;
|
||||
|
||||
private static int proxyPort = 0;
|
||||
|
||||
private static String username = null, password = null;
|
||||
private static InetAddress proxyInetAddress = null;
|
||||
private InetAddress addr;
|
||||
private int port;
|
||||
|
||||
private static String username = null, password = null;
|
||||
|
||||
public static boolean auth = false;
|
||||
|
||||
private static InetAddress proxyInetAddress = null;
|
||||
|
||||
private InetSocketAddress cachedAddr;
|
||||
|
||||
public static int closeConnections() {
|
||||
int value = 0;
|
||||
for (ProxySocket socket : connections)
|
||||
try {
|
||||
connections.remove(socket);
|
||||
if (socket.isClosed())
|
||||
continue;
|
||||
socket.close();
|
||||
value++;
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public ProxySocket(InetAddress addr, int port) throws IOException {
|
||||
super(addr, port);
|
||||
}
|
||||
@@ -55,6 +33,23 @@ public class ProxySocket extends Socket {
|
||||
super(host, port);
|
||||
}
|
||||
|
||||
public static int closeConnections() {
|
||||
int value = 0;
|
||||
for (ProxySocket socket : connections) {
|
||||
try {
|
||||
connections.remove(socket);
|
||||
if (socket.isClosed()) {
|
||||
continue;
|
||||
}
|
||||
socket.close();
|
||||
value++;
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static void setProxy(ProxyType type, String host, int port) {
|
||||
try {
|
||||
proxyInetAddress = InetAddress.getByName(host);
|
||||
@@ -77,6 +72,23 @@ public class ProxySocket extends Socket {
|
||||
return proxyType;
|
||||
}
|
||||
|
||||
public static void setType(ProxyType pt) {
|
||||
proxyType = pt;
|
||||
}
|
||||
|
||||
public static int getConnectionCount() {
|
||||
return connections.size();
|
||||
}
|
||||
|
||||
public static void setLogin(String user, char[] pass) {
|
||||
setLogin(user, new String(pass));
|
||||
}
|
||||
|
||||
public static void setLogin(String user, String pass) {
|
||||
username = user;
|
||||
password = pass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect(SocketAddress addr) throws IOException {
|
||||
connections.add(this);
|
||||
@@ -94,9 +106,10 @@ public class ProxySocket extends Socket {
|
||||
UILog.log("Proxy Error", e.getMessage(),
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
} else
|
||||
} else {
|
||||
super.connect(addr);
|
||||
}
|
||||
}
|
||||
|
||||
private void initProxy() throws IOException {
|
||||
System.out.println("Proxying:" + addr + ":" + port + " Over:"
|
||||
@@ -126,10 +139,12 @@ public class ProxySocket extends Socket {
|
||||
out.write("\r\n".getBytes());
|
||||
String str;
|
||||
while ((str = br.readLine()) != null) {
|
||||
if (str.length() == 0)
|
||||
if (str.length() == 0) {
|
||||
break;
|
||||
if (!str.startsWith("HTTP"))
|
||||
}
|
||||
if (!str.startsWith("HTTP")) {
|
||||
continue;
|
||||
}
|
||||
int code = Integer.parseInt(str.substring(9, 12));
|
||||
switch (code) {
|
||||
case 404:
|
||||
@@ -140,12 +155,13 @@ public class ProxySocket extends Socket {
|
||||
"Proxy doesn't support connecting to port: " + port
|
||||
+ "! Try a different proxy.");
|
||||
}
|
||||
if (code / 100 != 2)
|
||||
if (code / 100 != 2) {
|
||||
throw new IOException(
|
||||
"Unable to connect to proxy server! HTTP Error code:"
|
||||
+ code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void socks4_connect() throws IOException {
|
||||
DataOutputStream out = new DataOutputStream(getOutputStream());
|
||||
@@ -155,18 +171,22 @@ public class ProxySocket extends Socket {
|
||||
out.write(0x01); // connection type (TCP stream)
|
||||
out.writeShort(port);
|
||||
byte[] b = addr.getAddress();
|
||||
if (b.length != 4)
|
||||
if (b.length != 4) {
|
||||
throw new IOException("Unsupported IP type for socksv4!");
|
||||
}
|
||||
out.write(b);
|
||||
out.write(0); // the userID stuff, 0 means end of string (null
|
||||
// terminated)
|
||||
out.flush();
|
||||
|
||||
if (in.read() != 0x00) // null byte
|
||||
{
|
||||
throw new IOException("Proxy server dun goofed");
|
||||
if (in.read() != 0x5a)
|
||||
}
|
||||
if (in.read() != 0x5a) {
|
||||
throw new IOException(
|
||||
"Proxy server was unable to connect to server!");
|
||||
}
|
||||
|
||||
in.readShort(); // ignored
|
||||
in.readFully(b); // ignored
|
||||
@@ -184,7 +204,9 @@ public class ProxySocket extends Socket {
|
||||
}
|
||||
out.flush();
|
||||
if (in.read() != 0x05) // remote proxy version
|
||||
{
|
||||
throw new IOException("Proxy server is not supported!");
|
||||
}
|
||||
switch (in.read()) { // auth method
|
||||
case 0:
|
||||
break; // no auth
|
||||
@@ -198,7 +220,9 @@ public class ProxySocket extends Socket {
|
||||
out.flush();
|
||||
in.read(); // skip the version
|
||||
if (in.read() == 0) // Successful login, continue
|
||||
{
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new IOException("Proxy server declined request!");
|
||||
}
|
||||
@@ -217,12 +241,16 @@ public class ProxySocket extends Socket {
|
||||
|
||||
// now to read the server's reply
|
||||
if (in.read() != 0x05) // socks version (again)
|
||||
{
|
||||
throw new IOException("Proxy server dun goofed");
|
||||
}
|
||||
int reply = in.read();
|
||||
if (reply == 0x08)
|
||||
if (reply == 0x08) {
|
||||
throw new IOException("Bad address sent to proxy server");
|
||||
if (reply != 0x00)
|
||||
}
|
||||
if (reply != 0x00) {
|
||||
throw new IOException("Unable to connect to server!");
|
||||
}
|
||||
in.read(); // reserve byte
|
||||
int addrType = in.read();
|
||||
b = new byte[4];
|
||||
@@ -242,29 +270,33 @@ public class ProxySocket extends Socket {
|
||||
|
||||
@Override
|
||||
public int getPort() {
|
||||
if (super.getInetAddress().equals(proxyInetAddress))
|
||||
if (super.getInetAddress().equals(proxyInetAddress)) {
|
||||
return port;
|
||||
}
|
||||
return super.getPort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetAddress getInetAddress() {
|
||||
if (super.getInetAddress().equals(proxyInetAddress))
|
||||
if (super.getInetAddress().equals(proxyInetAddress)) {
|
||||
return addr;
|
||||
}
|
||||
return super.getInetAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketAddress getRemoteSocketAddress() {
|
||||
if (super.getInetAddress().equals(proxyInetAddress))
|
||||
if (super.getInetAddress().equals(proxyInetAddress)) {
|
||||
return cachedAddr;
|
||||
}
|
||||
return super.getRemoteSocketAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketChannel getChannel() {
|
||||
if (super.getInetAddress().equals(proxyInetAddress))
|
||||
if (super.getInetAddress().equals(proxyInetAddress)) {
|
||||
return null;
|
||||
}
|
||||
return super.getChannel();
|
||||
}
|
||||
|
||||
@@ -274,21 +306,4 @@ public class ProxySocket extends Socket {
|
||||
super.close();
|
||||
}
|
||||
|
||||
public static void setType(ProxyType pt) {
|
||||
proxyType = pt;
|
||||
}
|
||||
|
||||
public static int getConnectionCount() {
|
||||
return connections.size();
|
||||
}
|
||||
|
||||
public static void setLogin(String user, char[] pass) {
|
||||
setLogin(user, new String(pass));
|
||||
}
|
||||
|
||||
public static void setLogin(String user, String pass) {
|
||||
username = user;
|
||||
password = pass;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
package org.parabot.core.network.proxy;
|
||||
|
||||
public enum ProxyType {
|
||||
NONE,SOCKS5, SOCKS4, HTTP
|
||||
NONE, SOCKS5, SOCKS4, HTTP
|
||||
}
|
||||
@@ -3,11 +3,9 @@ package org.parabot.core.paint;
|
||||
import org.parabot.environment.api.interfaces.Paintable;
|
||||
|
||||
/**
|
||||
*
|
||||
* Abstract class for debugging in game values & more
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractDebugger implements Paintable {
|
||||
|
||||
@@ -17,7 +15,6 @@ public abstract class AbstractDebugger implements Paintable {
|
||||
public abstract void toggle();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return True if this debugger is enabled, otherwise false
|
||||
*/
|
||||
public abstract boolean isEnabled();
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
package org.parabot.core.paint;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import org.parabot.core.Context;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
import org.parabot.core.Context;
|
||||
|
||||
/**
|
||||
*
|
||||
* Manages and paints on a collection of AbstractDebuggers
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class PaintDebugger {
|
||||
private final HashMap<String, AbstractDebugger> debuggers;
|
||||
@@ -24,28 +21,28 @@ public class PaintDebugger {
|
||||
this.stringDebug = new LinkedList<String>();
|
||||
}
|
||||
|
||||
public static final PaintDebugger getInstance() {
|
||||
return Context.getInstance().getPaintDebugger();
|
||||
}
|
||||
|
||||
public final void addDebugger(final String name, final AbstractDebugger debugger) {
|
||||
debuggers.put(name, debugger);
|
||||
}
|
||||
|
||||
public void debug(Graphics g) {
|
||||
for(final AbstractDebugger d : debuggers.values()) {
|
||||
if(d.isEnabled()) {
|
||||
for (final AbstractDebugger d : debuggers.values()) {
|
||||
if (d.isEnabled()) {
|
||||
d.paint(g);
|
||||
}
|
||||
}
|
||||
g.setColor(Color.green);
|
||||
int y = 40;
|
||||
while(stringDebug.size() > 0) {
|
||||
while (stringDebug.size() > 0) {
|
||||
g.drawString(stringDebug.poll(), 10, y);
|
||||
y += 15;
|
||||
}
|
||||
}
|
||||
|
||||
public static final PaintDebugger getInstance() {
|
||||
return Context.getInstance().getPaintDebugger();
|
||||
}
|
||||
|
||||
public final void addLine(final String debugLine) {
|
||||
stringDebug.add(debugLine);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.parabot.core.parsers.hooks;
|
||||
import org.parabot.core.asm.hooks.HookFile;
|
||||
import org.parabot.core.asm.interfaces.Injectable;
|
||||
import org.parabot.core.asm.wrappers.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@@ -15,7 +16,6 @@ import java.util.HashMap;
|
||||
*/
|
||||
public abstract class HookParser {
|
||||
|
||||
|
||||
public HookParser(HookFile hookFile) {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,25 +1,18 @@
|
||||
package org.parabot.core.parsers.hooks;
|
||||
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.parabot.core.asm.adapters.AddInterfaceAdapter;
|
||||
import org.parabot.core.asm.hooks.HookFile;
|
||||
import org.parabot.core.asm.wrappers.Callback;
|
||||
import org.parabot.core.asm.wrappers.Getter;
|
||||
import org.parabot.core.asm.wrappers.Interface;
|
||||
import org.parabot.core.asm.wrappers.Invoker;
|
||||
import org.parabot.core.asm.wrappers.Setter;
|
||||
import org.parabot.core.asm.wrappers.Super;
|
||||
import org.parabot.core.asm.wrappers.*;
|
||||
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Dane
|
||||
*
|
||||
*/
|
||||
public class JSONHookParser extends HookParser {
|
||||
private JSONObject root;
|
||||
|
||||
@@ -1,25 +1,19 @@
|
||||
package org.parabot.core.parsers.hooks;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.core.asm.adapters.AddInterfaceAdapter;
|
||||
import org.parabot.core.asm.hooks.HookFile;
|
||||
import org.parabot.core.asm.wrappers.Callback;
|
||||
import org.parabot.core.asm.wrappers.Getter;
|
||||
import org.parabot.core.asm.wrappers.Interface;
|
||||
import org.parabot.core.asm.wrappers.Invoker;
|
||||
import org.parabot.core.asm.wrappers.Setter;
|
||||
import org.parabot.core.asm.wrappers.Super;
|
||||
import org.parabot.core.asm.wrappers.*;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class XMLHookParser extends HookParser {
|
||||
private Document doc;
|
||||
private HashMap<String, String> interfaceMap;
|
||||
@@ -44,6 +38,39 @@ public class XMLHookParser extends HookParser {
|
||||
}
|
||||
}
|
||||
|
||||
private static String resolveDesc(String returnDesc) {
|
||||
String array = "";
|
||||
if (returnDesc != null && returnDesc.contains("%s")) {
|
||||
StringBuilder str = new StringBuilder();
|
||||
if (returnDesc.startsWith("[")) {
|
||||
for (int i = 0; i < returnDesc.length(); i++) {
|
||||
if (returnDesc.charAt(i) == '[') {
|
||||
array += '[';
|
||||
}
|
||||
}
|
||||
returnDesc = returnDesc.replaceAll("\\[", "");
|
||||
}
|
||||
str.append(array)
|
||||
.append('L')
|
||||
.append(String.format(returnDesc,
|
||||
AddInterfaceAdapter.getAccessorPackage()))
|
||||
.append(";");
|
||||
returnDesc = str.toString();
|
||||
}
|
||||
return returnDesc;
|
||||
}
|
||||
|
||||
private static final boolean isSet(String tag, Element element) {
|
||||
return element.getElementsByTagName(tag).getLength() > 0;
|
||||
}
|
||||
|
||||
private static final String getValue(String tag, Element element) {
|
||||
NodeList nodes = element.getElementsByTagName(tag).item(0)
|
||||
.getChildNodes();
|
||||
Node node = (Node) nodes.item(0);
|
||||
return node.getNodeValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Interface[] getInterfaces() {
|
||||
parsedInterfaces = true;
|
||||
@@ -267,40 +294,6 @@ public class XMLHookParser extends HookParser {
|
||||
return setterList.toArray(new Setter[setterList.size()]);
|
||||
}
|
||||
|
||||
|
||||
private static String resolveDesc(String returnDesc) {
|
||||
String array = "";
|
||||
if (returnDesc != null && returnDesc.contains("%s")) {
|
||||
StringBuilder str = new StringBuilder();
|
||||
if (returnDesc.startsWith("[")) {
|
||||
for (int i = 0; i < returnDesc.length(); i++) {
|
||||
if (returnDesc.charAt(i) == '[') {
|
||||
array += '[';
|
||||
}
|
||||
}
|
||||
returnDesc = returnDesc.replaceAll("\\[", "");
|
||||
}
|
||||
str.append(array)
|
||||
.append('L')
|
||||
.append(String.format(returnDesc,
|
||||
AddInterfaceAdapter.getAccessorPackage()))
|
||||
.append(";");
|
||||
returnDesc = str.toString();
|
||||
}
|
||||
return returnDesc;
|
||||
}
|
||||
|
||||
private static final boolean isSet(String tag, Element element) {
|
||||
return element.getElementsByTagName(tag).getLength() > 0;
|
||||
}
|
||||
|
||||
private static final String getValue(String tag, Element element) {
|
||||
NodeList nodes = element.getElementsByTagName(tag).item(0)
|
||||
.getChildNodes();
|
||||
Node node = (Node) nodes.item(0);
|
||||
return node.getNodeValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Invoker[] getInvokers() {
|
||||
final NodeList invokerRootList = doc.getElementsByTagName("invokers");
|
||||
|
||||
@@ -29,7 +29,7 @@ public class PublicRandoms extends RandomParser {
|
||||
}
|
||||
try {
|
||||
URL url = myJar.toURI().toURL();
|
||||
URL[] urls = new URL[]{url};
|
||||
URL[] urls = new URL[]{ url };
|
||||
String server = Context.getInstance().getServerProviderInfo().getServerName();
|
||||
|
||||
URLClassLoader child = new URLClassLoader(urls, this.getClass().getClassLoader());
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package org.parabot.core.parsers.scripts;
|
||||
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.core.desc.ScriptDescription;
|
||||
import org.parabot.environment.scripts.executers.ScriptExecuter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.core.desc.ScriptDescription;
|
||||
import org.parabot.environment.scripts.executers.ScriptExecuter;
|
||||
|
||||
/**
|
||||
* Abstract class for parsing scripts
|
||||
*
|
||||
@@ -18,8 +18,6 @@ public abstract class ScriptParser {
|
||||
|
||||
public static final Map<ScriptDescription, ScriptExecuter> SCRIPT_CACHE = new HashMap<ScriptDescription, ScriptExecuter>();
|
||||
|
||||
public abstract void execute();
|
||||
|
||||
public static ScriptDescription[] getDescriptions() {
|
||||
SCRIPT_CACHE.clear();
|
||||
final ArrayList<ScriptParser> parsers = new ArrayList<ScriptParser>();
|
||||
@@ -44,9 +42,11 @@ public abstract class ScriptParser {
|
||||
Core.verbose("Scripts parsed.");
|
||||
}
|
||||
|
||||
Map<ScriptDescription, ScriptExecuter> SORTED_SCRIPT_CACHE = new TreeMap<ScriptDescription, ScriptExecuter>( SCRIPT_CACHE );
|
||||
Map<ScriptDescription, ScriptExecuter> SORTED_SCRIPT_CACHE = new TreeMap<ScriptDescription, ScriptExecuter>(SCRIPT_CACHE);
|
||||
|
||||
return SORTED_SCRIPT_CACHE.keySet().toArray(new ScriptDescription[SORTED_SCRIPT_CACHE.size()]);
|
||||
}
|
||||
|
||||
public abstract void execute();
|
||||
|
||||
}
|
||||
@@ -1,36 +1,23 @@
|
||||
package org.parabot.core.parsers.servers;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import org.parabot.core.Configuration;
|
||||
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.desc.ServerProviderInfo;
|
||||
import org.parabot.core.ui.components.VerboseLoader;
|
||||
import org.parabot.core.ui.utils.UILog;
|
||||
import org.parabot.environment.api.utils.WebUtil;
|
||||
import org.parabot.environment.servers.ServerManifest;
|
||||
import org.parabot.environment.servers.ServerProvider;
|
||||
import org.parabot.environment.servers.executers.LocalPublicServerExecuter;
|
||||
import org.parabot.environment.servers.executers.LocalServerExecuter;
|
||||
import org.parabot.environment.servers.executers.PublicServerExecuter;
|
||||
import org.parabot.environment.servers.loader.ServerLoader;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Parses local server providers located in the servers directory
|
||||
@@ -86,7 +73,7 @@ public class LocalServers extends ServerParser {
|
||||
}
|
||||
}
|
||||
|
||||
for (File file : Directories.listJSONFiles(Directories.getServerPath())){
|
||||
for (File file : Directories.listJSONFiles(Directories.getServerPath())) {
|
||||
Core.verbose("[Local server in]: " + file.getName());
|
||||
try {
|
||||
JSONObject object = (JSONObject) WebUtil.getJsonParser().parse(new FileReader(file));
|
||||
@@ -96,7 +83,7 @@ public class LocalServers extends ServerParser {
|
||||
String clientClass = (String) object.get("client-class");
|
||||
Object bank;
|
||||
int bankTabs = 0;
|
||||
if ((bank = object.get("bank")) != null){
|
||||
if ((bank = object.get("bank")) != null) {
|
||||
bankTabs = (int) bank;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,6 @@ import java.util.TreeMap;
|
||||
public abstract class ServerParser {
|
||||
public static final Map<ServerDescription, ServerExecuter> SERVER_CACHE = new HashMap<ServerDescription, ServerExecuter>();
|
||||
|
||||
public abstract void execute();
|
||||
|
||||
public static final ServerDescription[] getDescriptions() {
|
||||
SERVER_CACHE.clear();
|
||||
final ArrayList<ServerParser> parsers = new ArrayList<>();
|
||||
@@ -43,9 +41,11 @@ public abstract class ServerParser {
|
||||
Core.verbose("Server providers parsed.");
|
||||
}
|
||||
|
||||
Map<ServerDescription, ServerExecuter> SORTED_SERVER_CACHE = new TreeMap<ServerDescription, ServerExecuter>( SERVER_CACHE );
|
||||
Map<ServerDescription, ServerExecuter> SORTED_SERVER_CACHE = new TreeMap<ServerDescription, ServerExecuter>(SERVER_CACHE);
|
||||
|
||||
return SORTED_SERVER_CACHE.keySet().toArray(new ServerDescription[SORTED_SERVER_CACHE.size()]);
|
||||
}
|
||||
|
||||
public abstract void execute();
|
||||
|
||||
}
|
||||
@@ -9,13 +9,11 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
*
|
||||
* A <code>RefClass</code> represents a class or an instance of that class, if
|
||||
* no instance is provided this class can only get values from static fields and
|
||||
* only invoke static methods
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class RefClass extends RefModifiers {
|
||||
private Object instance;
|
||||
@@ -35,12 +33,21 @@ public class RefClass extends RefModifiers {
|
||||
setInstance(instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the instance of this class
|
||||
*
|
||||
* @return if an instance of this class is known it will return that
|
||||
* instance, otherwise it will return null.
|
||||
*/
|
||||
public Object getInstance() {
|
||||
return this.instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the instance of this class so now non static fields values can be
|
||||
* retrieved and non static methods can be invoked
|
||||
*
|
||||
* @param instance
|
||||
* instance of this class.
|
||||
* @param instance instance of this class.
|
||||
*/
|
||||
public void setInstance(Object instance) {
|
||||
if (instance == null) {
|
||||
@@ -56,16 +63,6 @@ public class RefClass extends RefModifiers {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the instance of this class
|
||||
*
|
||||
* @return if an instance of this class is known it will return that
|
||||
* instance, otherwise it will return null.
|
||||
*/
|
||||
public Object getInstance() {
|
||||
return this.instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the class which this RefClass is representing
|
||||
*
|
||||
@@ -87,7 +84,7 @@ public class RefClass extends RefModifiers {
|
||||
return this.clazz.getCanonicalName();
|
||||
}
|
||||
|
||||
public Annotation[] getAnnotations(){
|
||||
public Annotation[] getAnnotations() {
|
||||
return this.clazz.getAnnotations();
|
||||
}
|
||||
|
||||
@@ -127,7 +124,9 @@ public class RefClass extends RefModifiers {
|
||||
|
||||
/**
|
||||
* Determines if a object is an instance of this class
|
||||
*
|
||||
* @param object the object you want to check
|
||||
*
|
||||
* @return <code>true</code> if the object is an instance of this class; <code>false</code> otherwise
|
||||
*/
|
||||
public boolean instanceOf(Object object) {
|
||||
@@ -137,8 +136,8 @@ public class RefClass extends RefModifiers {
|
||||
/**
|
||||
* Gets field by field name
|
||||
*
|
||||
* @param name
|
||||
* name of the field
|
||||
* @param name name of the field
|
||||
*
|
||||
* @return the field if found
|
||||
*/
|
||||
public RefField getField(String name) {
|
||||
@@ -148,10 +147,9 @@ public class RefClass extends RefModifiers {
|
||||
/**
|
||||
* Gets field by field name and desc
|
||||
*
|
||||
* @param name
|
||||
* name of the field
|
||||
* @param desc
|
||||
* desc type of the field
|
||||
* @param name name of the field
|
||||
* @param desc desc type of the field
|
||||
*
|
||||
* @return the field if found
|
||||
*/
|
||||
public RefField getField(String name, String desc) {
|
||||
@@ -182,9 +180,9 @@ public class RefClass extends RefModifiers {
|
||||
/**
|
||||
* Determines if this class has a super class
|
||||
*
|
||||
* @param ignoreObjectClass
|
||||
* if you want this method to return false when the superclass is
|
||||
* @param ignoreObjectClass if you want this method to return false when the superclass is
|
||||
* the java/lang/Object class
|
||||
*
|
||||
* @return <code>true</code> if this class has a superclass, otherwise
|
||||
* <code>false</code>
|
||||
*/
|
||||
@@ -193,7 +191,7 @@ public class RefClass extends RefModifiers {
|
||||
return !clazz.equals(Object.class);
|
||||
}
|
||||
Class<?> superClass = clazz.getSuperclass();
|
||||
if(superClass == null) {
|
||||
if (superClass == null) {
|
||||
return false;
|
||||
}
|
||||
return !superClass.equals(Object.class);
|
||||
@@ -228,14 +226,14 @@ public class RefClass extends RefModifiers {
|
||||
* @return empty constructor if there, otherwise <code>null</code>
|
||||
*/
|
||||
public RefConstructor getConstructor() {
|
||||
return getConstructor(new Class<?>[] {});
|
||||
return getConstructor(new Class<?>[]{});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a RefConstructor from this class
|
||||
*
|
||||
* @param parameters
|
||||
* the constructor it's parameters
|
||||
* @param parameters the constructor it's parameters
|
||||
*
|
||||
* @return the retrieved constructor
|
||||
*/
|
||||
public RefConstructor getConstructor(Class<?>[] parameters) {
|
||||
@@ -289,8 +287,8 @@ public class RefClass extends RefModifiers {
|
||||
/**
|
||||
* Finds and returns the first RefMethod match with given method name
|
||||
*
|
||||
* @param name
|
||||
* method its name
|
||||
* @param name method its name
|
||||
*
|
||||
* @return the first match, or if not found <code>null</code>
|
||||
*/
|
||||
public RefMethod getMethod(String name) {
|
||||
@@ -300,10 +298,9 @@ public class RefClass extends RefModifiers {
|
||||
/**
|
||||
* Finds a RefMethod in this RefClass
|
||||
*
|
||||
* @param name
|
||||
* the method its name
|
||||
* @param parameters
|
||||
* the method its parameters
|
||||
* @param name the method its name
|
||||
* @param parameters the method its parameters
|
||||
*
|
||||
* @return the matched method or if not found null <code>null</code>
|
||||
*/
|
||||
public RefMethod getMethod(String name, Class<?>[] parameters) {
|
||||
|
||||
@@ -3,12 +3,10 @@ package org.parabot.core.reflect;
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
/**
|
||||
*
|
||||
* A <code>RefConstructor</code> class represent a constructor method of a
|
||||
* <code>RefClass</code>.
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class RefConstructor extends RefModifiers {
|
||||
private Constructor<?> constructor;
|
||||
@@ -24,14 +22,14 @@ public class RefConstructor extends RefModifiers {
|
||||
* @return the instance of the class
|
||||
*/
|
||||
public RefClass newInstance() {
|
||||
return newInstance(new Object[] {});
|
||||
return newInstance(new Object[]{});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of this class by invoking this constructor
|
||||
*
|
||||
* @param args
|
||||
* the arguments for the constructor
|
||||
* @param args the arguments for the constructor
|
||||
*
|
||||
* @return the instance of the class
|
||||
*/
|
||||
public RefClass newInstance(Object... args) {
|
||||
|
||||
@@ -4,11 +4,9 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
*
|
||||
* A <code>RefField</code> represents a field in a <code>RefClass</code>
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class RefField extends RefModifiers {
|
||||
private Field field;
|
||||
@@ -129,8 +127,7 @@ public class RefField extends RefModifiers {
|
||||
/**
|
||||
* Sets the field value
|
||||
*
|
||||
* @param object
|
||||
* object to set
|
||||
* @param object object to set
|
||||
*/
|
||||
public void set(Object object) {
|
||||
if (instance == null && !isStatic()) {
|
||||
@@ -150,8 +147,7 @@ public class RefField extends RefModifiers {
|
||||
/**
|
||||
* Sets the field integer value
|
||||
*
|
||||
* @param i
|
||||
* value to set
|
||||
* @param i value to set
|
||||
*/
|
||||
public void setInt(int i) {
|
||||
set(i);
|
||||
@@ -160,8 +156,7 @@ public class RefField extends RefModifiers {
|
||||
/**
|
||||
* Sets the field long value
|
||||
*
|
||||
* @param l
|
||||
* value to set
|
||||
* @param l value to set
|
||||
*/
|
||||
public void setLong(long l) {
|
||||
set(l);
|
||||
@@ -170,8 +165,7 @@ public class RefField extends RefModifiers {
|
||||
/**
|
||||
* Sets the field double value
|
||||
*
|
||||
* @param d
|
||||
* value to set
|
||||
* @param d value to set
|
||||
*/
|
||||
public void setDouble(double d) {
|
||||
set(d);
|
||||
@@ -180,8 +174,7 @@ public class RefField extends RefModifiers {
|
||||
/**
|
||||
* Sets the field float value
|
||||
*
|
||||
* @param f
|
||||
* value to set
|
||||
* @param f value to set
|
||||
*/
|
||||
public void setFloat(float f) {
|
||||
set(f);
|
||||
@@ -190,8 +183,7 @@ public class RefField extends RefModifiers {
|
||||
/**
|
||||
* Sets the field boolean value
|
||||
*
|
||||
* @param b
|
||||
* value to set
|
||||
* @param b value to set
|
||||
*/
|
||||
public void setBoolean(boolean b) {
|
||||
set(b);
|
||||
@@ -200,8 +192,7 @@ public class RefField extends RefModifiers {
|
||||
/**
|
||||
* Sets the field short value
|
||||
*
|
||||
* @param s
|
||||
* value to set
|
||||
* @param s value to set
|
||||
*/
|
||||
public void setShort(short s) {
|
||||
set(s);
|
||||
@@ -210,28 +201,16 @@ public class RefField extends RefModifiers {
|
||||
/**
|
||||
* Sets the byte integer value
|
||||
*
|
||||
* @param b
|
||||
* value to set
|
||||
* @param b value to set
|
||||
*/
|
||||
public void setByte(byte b) {
|
||||
set(b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the field string value
|
||||
*
|
||||
* @param s
|
||||
* value to set
|
||||
*/
|
||||
public void setString(String s) {
|
||||
set(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the field char value
|
||||
*
|
||||
* @param c
|
||||
* value to set
|
||||
* @param c value to set
|
||||
*/
|
||||
public void setChar(char c) {
|
||||
set(c);
|
||||
@@ -312,6 +291,15 @@ public class RefField extends RefModifiers {
|
||||
return getType() == String.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the field string value
|
||||
*
|
||||
* @param s value to set
|
||||
*/
|
||||
public void setString(String s) {
|
||||
set(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if this field represents an element of an
|
||||
* enumerated type; returns <code>false</code> otherwise.
|
||||
@@ -363,6 +351,7 @@ public class RefField extends RefModifiers {
|
||||
|
||||
/**
|
||||
* Gets the declaring <code>RefClass</code> of this field
|
||||
*
|
||||
* @return <code>RefClass</code> holding this field
|
||||
*/
|
||||
public RefClass getOwner() {
|
||||
@@ -377,5 +366,4 @@ public class RefField extends RefModifiers {
|
||||
return field.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -3,11 +3,9 @@ package org.parabot.core.reflect;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
*
|
||||
* A <code>RefMethod</code> class represent a method of a <code>RefClass</code>.
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class RefMethod extends RefModifiers {
|
||||
private Method method;
|
||||
@@ -114,15 +112,14 @@ public class RefMethod extends RefModifiers {
|
||||
* @return object returned by the method
|
||||
*/
|
||||
public Object invoke() {
|
||||
return invoke(new Object[] {});
|
||||
return invoke(new Object[]{});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Invokes the method and returns it returned object
|
||||
*
|
||||
* @param args
|
||||
* arguments for the invokable method
|
||||
* @param args arguments for the invokable method
|
||||
*
|
||||
* @return object returned by the method
|
||||
*/
|
||||
public Object invoke(Object... args) {
|
||||
@@ -130,7 +127,7 @@ public class RefMethod extends RefModifiers {
|
||||
throw new IllegalStateException(
|
||||
"Can not invoke non static method without an instance.");
|
||||
}
|
||||
if(!isAccessible()) {
|
||||
if (!isAccessible()) {
|
||||
method.setAccessible(true);
|
||||
}
|
||||
try {
|
||||
|
||||
@@ -3,9 +3,7 @@ package org.parabot.core.reflect;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class RefModifiers {
|
||||
private int modifiers;
|
||||
@@ -18,14 +16,14 @@ public class RefModifiers {
|
||||
setModifiers(modifiers);
|
||||
}
|
||||
|
||||
public void setModifiers(int modifiers) {
|
||||
this.modifiers = modifiers;
|
||||
}
|
||||
|
||||
public int getModifiers() {
|
||||
return this.modifiers;
|
||||
}
|
||||
|
||||
public void setModifiers(int modifiers) {
|
||||
this.modifiers = modifiers;
|
||||
}
|
||||
|
||||
public boolean isStatic() {
|
||||
return Modifier.isStatic(modifiers);
|
||||
}
|
||||
|
||||
@@ -5,9 +5,7 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class RefUtils {
|
||||
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
package org.parabot.core.ui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
|
||||
import javax.swing.JDialog;
|
||||
|
||||
import org.parabot.core.ui.components.PaintComponent;
|
||||
import org.parabot.environment.OperatingSystem;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class BotDialog extends JDialog {
|
||||
private static final long serialVersionUID = 521800552287194673L;
|
||||
@@ -45,6 +41,14 @@ public class BotDialog extends JDialog {
|
||||
|
||||
}
|
||||
|
||||
public static BotDialog getInstance(BotUI botUI) {
|
||||
return instance == null ? instance = new BotDialog(botUI) : instance;
|
||||
}
|
||||
|
||||
public static BotDialog getInstance() {
|
||||
return getInstance(null);
|
||||
}
|
||||
|
||||
public void setDimensions(Dimension dimension) {
|
||||
setUndecorated(true);
|
||||
getRootPane().setOpaque(false);
|
||||
@@ -57,12 +61,4 @@ public class BotDialog extends JDialog {
|
||||
PaintComponent.getInstance().setDimensions(dimension);
|
||||
}
|
||||
|
||||
public static BotDialog getInstance(BotUI botUI) {
|
||||
return instance == null ? instance = new BotDialog(botUI) : instance;
|
||||
}
|
||||
|
||||
public static BotDialog getInstance() {
|
||||
return getInstance(null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
|
||||
private JMenuItem run, pause, stop, cacheClear, notifications;
|
||||
private boolean runScript, pauseScript;
|
||||
|
||||
|
||||
public BotUI(String username, String password) {
|
||||
if (instance != null) {
|
||||
throw new IllegalStateException("BotUI already created");
|
||||
@@ -75,7 +74,6 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
private void createMenu() {
|
||||
menuBar = new JMenuBar();
|
||||
|
||||
@@ -146,7 +144,6 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
|
||||
menuBar.add(scripts);
|
||||
menuBar.add(features);
|
||||
|
||||
|
||||
setJMenuBar(menuBar);
|
||||
}
|
||||
|
||||
@@ -160,7 +157,10 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
|
||||
case "Create screenshot":
|
||||
try {
|
||||
Robot robot = new Robot();
|
||||
Rectangle parabotScreen = new Rectangle((int) getLocation().getX(), (int) getLocation().getY() + (menuBar.getHeight() + features.getHeight()), getWidth(), getHeight());
|
||||
int menuBarHeight = menuBar.getHeight() + file.getHeight();
|
||||
Rectangle parabotScreen = new Rectangle(
|
||||
(int) getLocation().getX(), (int) getLocation().getY() + menuBarHeight,
|
||||
getWidth(), getHeight() - menuBarHeight);
|
||||
BufferedImage image = robot.createScreenCapture(parabotScreen);
|
||||
String randString = StringUtils.randomString(10);
|
||||
boolean search = true;
|
||||
|
||||
@@ -18,7 +18,7 @@ public class Logger extends JPanel {
|
||||
|
||||
private boolean clearable;
|
||||
|
||||
private Logger(){
|
||||
private Logger() {
|
||||
setLayout(new BorderLayout());
|
||||
list = new JList<>();
|
||||
|
||||
@@ -45,34 +45,20 @@ public class Logger extends JPanel {
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
private ListCellRenderer<? super String> getRenderer() {
|
||||
return new DefaultListCellRenderer(){
|
||||
private static final long serialVersionUID = -3589192791360628745L;
|
||||
|
||||
@Override
|
||||
public Component getListCellRendererComponent(JList<?> list,
|
||||
Object value, int index, boolean isSelected,
|
||||
boolean cellHasFocus) {
|
||||
JLabel listCellRendererComponent = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected,cellHasFocus);
|
||||
listCellRendererComponent.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0,Color.BLACK));
|
||||
return listCellRendererComponent;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Logger getInstance() {
|
||||
return instance == null ? instance = new Logger() : instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a message in the logger ui
|
||||
*
|
||||
* @param message
|
||||
* @param uliratha Determines if this should be sent to the uliratha server
|
||||
*/
|
||||
public static void addMessage(String message, boolean uliratha){
|
||||
public static void addMessage(String message, boolean uliratha) {
|
||||
instance.model.addElement(message);
|
||||
|
||||
if (uliratha){
|
||||
if (uliratha) {
|
||||
// TODO: Implement latest Uliratha
|
||||
}
|
||||
|
||||
@@ -80,7 +66,7 @@ public class Logger extends JPanel {
|
||||
if (last >= 0) {
|
||||
instance.list.ensureIndexIsVisible(last);
|
||||
}
|
||||
if (instance.list.getModel().getSize() > 100 && instance.list.getModel().getElementAt(0) != null){
|
||||
if (instance.list.getModel().getSize() > 100 && instance.list.getModel().getElementAt(0) != null) {
|
||||
instance.model.remove(0);
|
||||
}
|
||||
}
|
||||
@@ -88,14 +74,29 @@ public class Logger extends JPanel {
|
||||
/**
|
||||
* @param message
|
||||
*/
|
||||
public static void addMessage(String message){
|
||||
public static void addMessage(String message) {
|
||||
addMessage(message, true);
|
||||
}
|
||||
|
||||
protected static void clearLogger(){
|
||||
protected static void clearLogger() {
|
||||
instance.model.clear();
|
||||
}
|
||||
|
||||
private ListCellRenderer<? super String> getRenderer() {
|
||||
return new DefaultListCellRenderer() {
|
||||
private static final long serialVersionUID = -3589192791360628745L;
|
||||
|
||||
@Override
|
||||
public Component getListCellRendererComponent(JList<?> list,
|
||||
Object value, int index, boolean isSelected,
|
||||
boolean cellHasFocus) {
|
||||
JLabel listCellRendererComponent = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||
listCellRendererComponent.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.BLACK));
|
||||
return listCellRendererComponent;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public boolean isClearable() {
|
||||
return clearable;
|
||||
}
|
||||
|
||||
@@ -17,11 +17,9 @@ import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
*
|
||||
* Users must login with their parabot account through this LoginUI class
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class LoginUI extends JFrame {
|
||||
private static final long serialVersionUID = 2032832552863466297L;
|
||||
@@ -33,38 +31,6 @@ public class LoginUI extends JFrame {
|
||||
private JButton cmdLogin;
|
||||
private JButton cmdRegister;
|
||||
|
||||
|
||||
public void attemptLogin() {
|
||||
String username = txtUsername.getText();
|
||||
String password = new String(txtPassword.getPassword());
|
||||
|
||||
if (username.length() > 0 && password.length() > 0) {
|
||||
if (manager.login(username, password, false)) {
|
||||
Core.verbose("Logged in.");
|
||||
instance.dispose();
|
||||
Core.verbose("Running server selector.");
|
||||
ServerSelector.getInstance();
|
||||
} else {
|
||||
Core.verbose("Failed to log in.");
|
||||
UILog.log("Error", "Incorrect username or password. Have you tried logging into http://bdn.parabot.org/account/", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void attempt(String user, String pass) {
|
||||
Core.verbose("Logging in...");
|
||||
if (manager.login(user, pass, false)) {
|
||||
Core.verbose("Logged in.");
|
||||
instance.dispose();
|
||||
Core.verbose("Running server selector.");
|
||||
ServerSelector.getInstance();
|
||||
} else {
|
||||
Core.verbose("Failed to log in.");
|
||||
UILog.log("Error", "Incorrect username or password. Have you tried logging into http://bdn.parabot.org/account/", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public LoginUI(String username, String password) {
|
||||
instance = this;
|
||||
attempt(username, password);
|
||||
@@ -169,4 +135,35 @@ public class LoginUI extends JFrame {
|
||||
|
||||
}
|
||||
|
||||
public void attemptLogin() {
|
||||
String username = txtUsername.getText();
|
||||
String password = new String(txtPassword.getPassword());
|
||||
|
||||
if (username.length() > 0 && password.length() > 0) {
|
||||
if (manager.login(username, password, false)) {
|
||||
Core.verbose("Logged in.");
|
||||
instance.dispose();
|
||||
Core.verbose("Running server selector.");
|
||||
ServerSelector.getInstance();
|
||||
} else {
|
||||
Core.verbose("Failed to log in.");
|
||||
UILog.log("Error", "Incorrect username or password. Have you tried logging into http://bdn.parabot.org/account/", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void attempt(String user, String pass) {
|
||||
Core.verbose("Logging in...");
|
||||
if (manager.login(user, pass, false)) {
|
||||
Core.verbose("Logged in.");
|
||||
instance.dispose();
|
||||
Core.verbose("Running server selector.");
|
||||
ServerSelector.getInstance();
|
||||
} else {
|
||||
Core.verbose("Failed to log in.");
|
||||
UILog.log("Error", "Incorrect username or password. Have you tried logging into http://bdn.parabot.org/account/", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -50,8 +50,9 @@ public class NetworkUI extends JFrame implements KeyListener, ActionListener,
|
||||
@Override
|
||||
public void setVisible(boolean b) {
|
||||
BotUI.getInstance().setEnabled(!b);
|
||||
if (ProxySocket.getProxyAddress() != null)
|
||||
if (ProxySocket.getProxyAddress() != null) {
|
||||
proxyHost.setText(ProxySocket.getProxyAddress().getHostName());
|
||||
}
|
||||
proxyPort.setText("" + ProxySocket.getProxyPort());
|
||||
proxyType.setSelectedItem(ProxySocket.getProxyType());
|
||||
authCheckBox.setSelected(ProxySocket.auth);
|
||||
@@ -95,7 +96,7 @@ public class NetworkUI extends JFrame implements KeyListener, ActionListener,
|
||||
Random rand = new Random();
|
||||
byte[] macAddr = new byte[6];
|
||||
rand.nextBytes(macAddr);
|
||||
macAddr[0] = (byte)(macAddr[0] & (byte)254);
|
||||
macAddr[0] = (byte) (macAddr[0] & (byte) 254);
|
||||
for (int i = 0; i < macAddr.length; i++) {
|
||||
int value = macAddr[i] & 0xFF;
|
||||
macList[i].setSelectedIndex(value);
|
||||
@@ -104,7 +105,6 @@ public class NetworkUI extends JFrame implements KeyListener, ActionListener,
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
authCheckBox = new JCheckBox("Auth");
|
||||
authCheckBox.setSelected(ProxySocket.auth);
|
||||
authCheckBox.addActionListener(this);
|
||||
@@ -262,9 +262,10 @@ public class NetworkUI extends JFrame implements KeyListener, ActionListener,
|
||||
.setLogin(username, password);
|
||||
|
||||
byte[] mac = new byte[macList.length];
|
||||
for (int i = 0; i < mac.length; i++)
|
||||
for (int i = 0; i < mac.length; i++) {
|
||||
mac[i] = (byte) Short.parseShort(
|
||||
(String) macList[i].getSelectedValue(), 16);
|
||||
}
|
||||
NetworkInterface.setMac(mac);
|
||||
|
||||
try {
|
||||
@@ -340,8 +341,9 @@ public class NetworkUI extends JFrame implements KeyListener, ActionListener,
|
||||
|
||||
public void insertString(int offs, String str, AttributeSet a)
|
||||
throws BadLocationException {
|
||||
if (str == null)
|
||||
if (str == null) {
|
||||
return;
|
||||
}
|
||||
String oldString = getText(0, getLength());
|
||||
String newString = oldString.substring(0, offs) + str
|
||||
+ oldString.substring(offs);
|
||||
|
||||
@@ -103,7 +103,6 @@ public class ReflectUI extends JFrame {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
final JButton adjustClasses = new JButton("Expand");
|
||||
adjustClasses.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
@@ -130,7 +129,6 @@ public class ReflectUI extends JFrame {
|
||||
searchContent.setMaximumSize(new Dimension(500, (int) searchContent.getPreferredSize().getHeight()));
|
||||
searchContent.add(searchButton);
|
||||
|
||||
|
||||
tree = new JTree();
|
||||
tree.setRootVisible(true);
|
||||
tree.setShowsRootHandles(true);
|
||||
|
||||
@@ -23,21 +23,23 @@ import java.net.URLEncoder;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* Script Selector GUI, shows all scripts
|
||||
*
|
||||
* @author Everel
|
||||
*/
|
||||
public final class ScriptSelector extends JFrame {
|
||||
public static ScriptParser parser;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static ScriptParser parser;
|
||||
private final int WIDTH;
|
||||
private final int HEIGHT;
|
||||
private HashMap<String, DefaultMutableTreeNode> categories;
|
||||
private HashMap<String, ScriptDescription> format;
|
||||
private DefaultMutableTreeNode root;
|
||||
private DefaultTreeModel model;
|
||||
private final int WIDTH;
|
||||
private final int HEIGHT;
|
||||
private Font fontCategory = new Font("Arial", Font.BOLD, 12);
|
||||
private Font fontScript = new Font("Arial", Font.PLAIN, 12);
|
||||
private JTree tree;
|
||||
private JEditorPane scriptInfo;
|
||||
|
||||
public ScriptSelector() {
|
||||
this.categories = new HashMap<String, DefaultMutableTreeNode>();
|
||||
@@ -77,7 +79,6 @@ public final class ScriptSelector extends JFrame {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String getScriptName(String path) {
|
||||
return path.split(", ")[2].replaceAll("\\]", "");
|
||||
}
|
||||
@@ -216,9 +217,4 @@ public final class ScriptSelector extends JFrame {
|
||||
return label;
|
||||
}
|
||||
}
|
||||
|
||||
private Font fontCategory = new Font("Arial", Font.BOLD, 12);
|
||||
private Font fontScript = new Font("Arial", Font.PLAIN, 12);
|
||||
private JTree tree;
|
||||
private JEditorPane scriptInfo;
|
||||
}
|
||||
|
||||
@@ -11,25 +11,16 @@ import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
/**
|
||||
*
|
||||
* Shows a list of every supported server which can be started
|
||||
*
|
||||
* @author Dane, Everel
|
||||
*
|
||||
*/
|
||||
|
||||
public class ServerSelector extends JPanel {
|
||||
public static String initServer;
|
||||
private static final long serialVersionUID = 5238720307271493899L;
|
||||
public static String initServer;
|
||||
private static ServerSelector instance;
|
||||
|
||||
public static ServerSelector getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new ServerSelector();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public ServerSelector() {
|
||||
Queue<ServerComponent> widgets = getServers();
|
||||
if (initServer != null) {
|
||||
@@ -39,7 +30,6 @@ public class ServerSelector extends JPanel {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
setPreferredSize(new Dimension(600, 350));
|
||||
|
||||
@@ -50,7 +40,7 @@ public class ServerSelector extends JPanel {
|
||||
while (widgets != null && !widgets.isEmpty()) {
|
||||
final ServerComponent w = widgets.poll();
|
||||
w.setSize(300, 100);
|
||||
if(i % 2 == 0 && i != 0) {
|
||||
if (i % 2 == 0 && i != 0) {
|
||||
y += 100;
|
||||
}
|
||||
w.setLocation(i % 2 == 0 ? 0 : 300, y);
|
||||
@@ -69,6 +59,13 @@ public class ServerSelector extends JPanel {
|
||||
|
||||
}
|
||||
|
||||
public static ServerSelector getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new ServerSelector();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when -server argument is given
|
||||
*
|
||||
|
||||
@@ -6,11 +6,9 @@ import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* Main panel where applets are added.
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class GamePanel extends JPanel {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -30,15 +28,6 @@ public class GamePanel extends JPanel {
|
||||
GroupLayout.Alignment.LEADING).addGap(0, 418, Short.MAX_VALUE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates context of this panel and adds a different Applet to the panel
|
||||
*
|
||||
* @param c
|
||||
*/
|
||||
public void setContext(final Context c) {
|
||||
add(c.getApplet(), BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets instance of this panel
|
||||
*
|
||||
@@ -48,6 +37,15 @@ public class GamePanel extends JPanel {
|
||||
return instance == null ? instance = new GamePanel() : instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates context of this panel and adds a different Applet to the panel
|
||||
*
|
||||
* @param c
|
||||
*/
|
||||
public void setContext(final Context c) {
|
||||
add(c.getApplet(), BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all components
|
||||
*/
|
||||
|
||||
@@ -1,23 +1,17 @@
|
||||
package org.parabot.core.ui.components;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import org.parabot.core.Context;
|
||||
import org.parabot.environment.api.interfaces.Paintable;
|
||||
import org.parabot.environment.api.utils.Time;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
/**
|
||||
*
|
||||
* The panel that is painted on
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class PaintComponent extends JComponent implements Runnable {
|
||||
private static final long serialVersionUID = 4653612412080038193L;
|
||||
@@ -39,6 +33,14 @@ public class PaintComponent extends JComponent implements Runnable {
|
||||
setIgnoreRepaint(true);
|
||||
}
|
||||
|
||||
public static PaintComponent getInstance(Dimension dimensions) {
|
||||
return instance == null ? instance = new PaintComponent(dimensions) : instance;
|
||||
}
|
||||
|
||||
public static PaintComponent getInstance() {
|
||||
return getInstance(null);
|
||||
}
|
||||
|
||||
public void setDimensions(Dimension dimensions) {
|
||||
this.dimensions = dimensions;
|
||||
this.dimensions = dimensions;
|
||||
@@ -51,14 +53,6 @@ public class PaintComponent extends JComponent implements Runnable {
|
||||
setIgnoreRepaint(true);
|
||||
}
|
||||
|
||||
public static PaintComponent getInstance(Dimension dimensions) {
|
||||
return instance == null ? instance = new PaintComponent(dimensions) : instance;
|
||||
}
|
||||
|
||||
public static PaintComponent getInstance() {
|
||||
return getInstance(null);
|
||||
}
|
||||
|
||||
public void startPainting(Context context) {
|
||||
this.context = context;
|
||||
new Thread(this).start();
|
||||
@@ -70,8 +64,8 @@ public class PaintComponent extends JComponent implements Runnable {
|
||||
g2.fillRect(0, 0, dimensions.width, dimensions.height);
|
||||
g2.setComposite(AlphaComposite.SrcOver);
|
||||
|
||||
if(context != null) {
|
||||
for(Paintable p : context.getPaintables()) {
|
||||
if (context != null) {
|
||||
for (Paintable p : context.getPaintables()) {
|
||||
p.paint(g);
|
||||
}
|
||||
context.getPaintDebugger().debug(g2);
|
||||
@@ -81,7 +75,7 @@ public class PaintComponent extends JComponent implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while(true) {
|
||||
while (true) {
|
||||
Time.sleep(100);
|
||||
repaint();
|
||||
}
|
||||
|
||||
@@ -1,18 +1,12 @@
|
||||
package org.parabot.core.ui.components;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
/**
|
||||
*
|
||||
* ProgressBar
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class ProgressBar {
|
||||
private double value;
|
||||
@@ -36,11 +30,15 @@ public class ProgressBar {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public double getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(double value) {
|
||||
if(value < 0 || value > 100) {
|
||||
if (value < 0 || value > 100) {
|
||||
return;
|
||||
}
|
||||
if(value > 99) {
|
||||
if (value > 99) {
|
||||
value = 100;
|
||||
}
|
||||
this.value = value;
|
||||
@@ -61,10 +59,6 @@ public class ProgressBar {
|
||||
this.progColor = new Color(255 - r, 253 - g, 145 - b);
|
||||
}
|
||||
|
||||
public double getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void draw(Graphics g, int x, int y) {
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
g2.setRenderingHint(
|
||||
|
||||
@@ -1,26 +1,19 @@
|
||||
package org.parabot.core.ui.components;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import org.parabot.core.desc.ServerDescription;
|
||||
import org.parabot.core.ui.fonts.Fonts;
|
||||
import org.parabot.environment.Environment;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
|
||||
/**
|
||||
* A neat looking server component
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class ServerComponent extends JPanel implements MouseListener,
|
||||
MouseMotionListener {
|
||||
|
||||
@@ -6,8 +6,8 @@ import org.parabot.core.forum.AccountManager;
|
||||
import org.parabot.core.forum.AccountManagerAccess;
|
||||
import org.parabot.core.io.ProgressListener;
|
||||
import org.parabot.core.ui.ServerSelector;
|
||||
import org.parabot.core.ui.images.Images;
|
||||
import org.parabot.core.ui.fonts.Fonts;
|
||||
import org.parabot.core.ui.images.Images;
|
||||
import org.parabot.core.ui.utils.UILog;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -24,22 +24,13 @@ import java.awt.image.RescaleOp;
|
||||
* @author Everel, EmmaStone
|
||||
*/
|
||||
public class VerboseLoader extends JPanel implements ProgressListener {
|
||||
public static final int STATE_LOADING = 1;
|
||||
private static final long serialVersionUID = 7412412644921803896L;
|
||||
private static final int STATE_AUTHENTICATION = 0;
|
||||
private static final int STATE_SERVER_SELECT = 2;
|
||||
private static VerboseLoader current;
|
||||
private static String state = "Initializing loader...";
|
||||
|
||||
private static final int STATE_AUTHENTICATION = 0;
|
||||
public static final int STATE_LOADING = 1;
|
||||
private static final int STATE_SERVER_SELECT = 2;
|
||||
private int currentState;
|
||||
|
||||
private static AccountManager manager;
|
||||
|
||||
private FontMetrics fontMetrics;
|
||||
private BufferedImage background, banner, loginBox;
|
||||
private ProgressBar progressBar;
|
||||
private JPanel loginPanel;
|
||||
|
||||
public static final AccountManagerAccess MANAGER_FETCHER = new AccountManagerAccess() {
|
||||
|
||||
@Override
|
||||
@@ -48,6 +39,11 @@ public class VerboseLoader extends JPanel implements ProgressListener {
|
||||
}
|
||||
|
||||
};
|
||||
private int currentState;
|
||||
private FontMetrics fontMetrics;
|
||||
private BufferedImage background, banner, loginBox;
|
||||
private ProgressBar progressBar;
|
||||
private JPanel loginPanel;
|
||||
|
||||
private VerboseLoader(String username, String password) {
|
||||
if (current != null) {
|
||||
@@ -77,6 +73,34 @@ public class VerboseLoader extends JPanel implements ProgressListener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets instance of this panel
|
||||
*
|
||||
* @return instance of this panel
|
||||
*/
|
||||
public static VerboseLoader get(String username, String password) {
|
||||
return current == null ? new VerboseLoader(username, password) : current;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets instance of this panel
|
||||
*
|
||||
* @return instance of this panel
|
||||
*/
|
||||
public static VerboseLoader get() {
|
||||
return current == null ? new VerboseLoader(null, null) : current;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the status message and repaints the panel
|
||||
*
|
||||
* @param message
|
||||
*/
|
||||
public static void setState(final String message) {
|
||||
state = message;
|
||||
current.repaint();
|
||||
}
|
||||
|
||||
public void addServerPanel() {
|
||||
JPanel servers = ServerSelector.getInstance();
|
||||
GridBagLayout bagLayout = (GridBagLayout) getLayout();
|
||||
@@ -139,7 +163,6 @@ public class VerboseLoader extends JPanel implements ProgressListener {
|
||||
passwordLabel.setAlignmentX(Box.CENTER_ALIGNMENT);
|
||||
passwordLabel.setForeground(Color.white);
|
||||
|
||||
|
||||
login.setAlignmentX(Box.CENTER_ALIGNMENT);
|
||||
login.setOpaque(false);
|
||||
|
||||
@@ -189,14 +212,13 @@ public class VerboseLoader extends JPanel implements ProgressListener {
|
||||
public void paintComponent(Graphics graphics) {
|
||||
super.paintComponent(graphics);
|
||||
|
||||
|
||||
Graphics2D g = (Graphics2D) graphics;
|
||||
g.setRenderingHint(
|
||||
RenderingHints.KEY_TEXT_ANTIALIASING,
|
||||
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
|
||||
g.drawImage(background, 0, 0, null);
|
||||
float[] scales = {1f, 1f, 1f, 0.9f};
|
||||
float[] scales = { 1f, 1f, 1f, 0.9f };
|
||||
float[] offsets = new float[4];
|
||||
RescaleOp rop = new RescaleOp(scales, offsets, null);
|
||||
g.drawImage(banner, rop, 0, 0);
|
||||
@@ -236,7 +258,6 @@ public class VerboseLoader extends JPanel implements ProgressListener {
|
||||
g.drawString(state, x, 200);
|
||||
}
|
||||
|
||||
|
||||
g.setFont(Fonts.getResource("leelawadee.ttf"));
|
||||
final String version = Configuration.BOT_VERSION.get();
|
||||
g.drawString(version,
|
||||
@@ -244,35 +265,6 @@ public class VerboseLoader extends JPanel implements ProgressListener {
|
||||
getHeight() - 12);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets instance of this panel
|
||||
*
|
||||
* @return instance of this panel
|
||||
*/
|
||||
public static VerboseLoader get(String username, String password) {
|
||||
return current == null ? new VerboseLoader(username, password) : current;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets instance of this panel
|
||||
*
|
||||
* @return instance of this panel
|
||||
*/
|
||||
public static VerboseLoader get() {
|
||||
return current == null ? new VerboseLoader(null, null) : current;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates the status message and repaints the panel
|
||||
*
|
||||
* @param message
|
||||
*/
|
||||
public static void setState(final String message) {
|
||||
state = message;
|
||||
current.repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressUpdate(double value) {
|
||||
progressBar.setValue(value);
|
||||
|
||||
@@ -1,27 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
|
||||
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="500.0" minWidth="500.0" prefHeight="503.0" prefWidth="735.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
|
||||
<BorderPane xmlns:fx="http://javafx.com/fxml/1" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="500.0" minWidth="500.0"
|
||||
prefHeight="503.0" prefWidth="735.0" xmlns="http://javafx.com/javafx/8">
|
||||
<top>
|
||||
<MenuBar BorderPane.alignment="CENTER">
|
||||
<menus>
|
||||
<Menu mnemonicParsing="false" text="File">
|
||||
<items>
|
||||
<MenuItem mnemonicParsing="false" text="Close" />
|
||||
<MenuItem mnemonicParsing="false" text="Close"/>
|
||||
</items>
|
||||
</Menu>
|
||||
<Menu mnemonicParsing="false" text="Edit">
|
||||
<items>
|
||||
<MenuItem mnemonicParsing="false" text="Delete" />
|
||||
<MenuItem mnemonicParsing="false" text="Delete"/>
|
||||
</items>
|
||||
</Menu>
|
||||
<Menu mnemonicParsing="false" text="Help">
|
||||
<items>
|
||||
<MenuItem mnemonicParsing="false" text="About" />
|
||||
<MenuItem mnemonicParsing="false" text="About"/>
|
||||
</items>
|
||||
</Menu>
|
||||
</menus>
|
||||
@@ -36,39 +35,41 @@
|
||||
<top>
|
||||
<ToolBar prefHeight="40.0" prefWidth="200.0" BorderPane.alignment="CENTER">
|
||||
<items>
|
||||
<TextField promptText="Search query" />
|
||||
<Separator prefHeight="30.0" prefWidth="25.0" visible="false" />
|
||||
<ComboBox prefWidth="150.0" promptText="Category" />
|
||||
<Separator prefHeight="30.0" prefWidth="25.0" visible="false" />
|
||||
<CheckBox mnemonicParsing="false" text="All servers" />
|
||||
<Separator prefHeight="30.0" prefWidth="25.0" visible="false" />
|
||||
<CheckBox mnemonicParsing="false" text="Include local scripts" />
|
||||
<Separator prefHeight="30.0" prefWidth="25.0" visible="false" />
|
||||
<Button alignment="CENTER_RIGHT" mnemonicParsing="false" text="Search" />
|
||||
<TextField promptText="Search query"/>
|
||||
<Separator prefHeight="30.0" prefWidth="25.0" visible="false"/>
|
||||
<ComboBox prefWidth="150.0" promptText="Category"/>
|
||||
<Separator prefHeight="30.0" prefWidth="25.0" visible="false"/>
|
||||
<CheckBox mnemonicParsing="false" text="All servers"/>
|
||||
<Separator prefHeight="30.0" prefWidth="25.0" visible="false"/>
|
||||
<CheckBox mnemonicParsing="false" text="Include local scripts"/>
|
||||
<Separator prefHeight="30.0" prefWidth="25.0" visible="false"/>
|
||||
<Button alignment="CENTER_RIGHT" mnemonicParsing="false" text="Search"/>
|
||||
</items>
|
||||
</ToolBar>
|
||||
</top>
|
||||
<center>
|
||||
<TableView prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER">
|
||||
<columns>
|
||||
<TableColumn prefWidth="75.0" text="Name" />
|
||||
<TableColumn prefWidth="75.0" text="Category" />
|
||||
<TableColumn prefWidth="75.0" text="Price" />
|
||||
<TableColumn prefWidth="75.0" text="Name"/>
|
||||
<TableColumn prefWidth="75.0" text="Category"/>
|
||||
<TableColumn prefWidth="75.0" text="Price"/>
|
||||
</columns>
|
||||
<contextMenu>
|
||||
<ContextMenu>
|
||||
<items>
|
||||
<MenuItem mnemonicParsing="false" text="View information" />
|
||||
<MenuItem mnemonicParsing="false" text="View information"/>
|
||||
</items>
|
||||
</ContextMenu>
|
||||
</contextMenu>
|
||||
</TableView>
|
||||
</center>
|
||||
<bottom>
|
||||
<HBox alignment="CENTER_RIGHT" prefHeight="35.0" prefWidth="735.0" BorderPane.alignment="CENTER">
|
||||
<HBox alignment="CENTER_RIGHT" prefHeight="35.0" prefWidth="735.0"
|
||||
BorderPane.alignment="CENTER">
|
||||
<children>
|
||||
<Button mnemonicParsing="false" prefHeight="25.0" prefWidth="83.0" text="Start" />
|
||||
<Separator prefHeight="4.0" prefWidth="35.0" visible="false" />
|
||||
<Button mnemonicParsing="false" prefHeight="25.0" prefWidth="83.0"
|
||||
text="Start"/>
|
||||
<Separator prefHeight="4.0" prefWidth="35.0" visible="false"/>
|
||||
</children>
|
||||
</HBox>
|
||||
</bottom>
|
||||
@@ -77,7 +78,7 @@
|
||||
</Tab>
|
||||
<Tab text="JKChicken">
|
||||
<content>
|
||||
<BorderPane prefHeight="200.0" prefWidth="200.0" />
|
||||
<BorderPane prefHeight="200.0" prefWidth="200.0"/>
|
||||
</content>
|
||||
</Tab>
|
||||
</tabs>
|
||||
|
||||
@@ -13,6 +13,7 @@ public class Fonts {
|
||||
* Calls the getResource with the default size of 12
|
||||
*
|
||||
* @param resource
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Font getResource(final String resource) {
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.parabot.core.ui.listeners;
|
||||
|
||||
import org.parabot.core.ui.listeners.key.ActionEventBinding;
|
||||
import org.parabot.core.ui.listeners.key.Binding;
|
||||
import org.parabot.environment.OperatingSystem;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
@@ -31,15 +30,15 @@ public class PBKeyListener implements KeyListener {
|
||||
}
|
||||
|
||||
public void addBinding(Binding binding) {
|
||||
for (Binding bind : this.bindings){
|
||||
if (bind.getKey() == binding.getKey()){
|
||||
for (Binding bind : this.bindings) {
|
||||
if (bind.getKey() == binding.getKey()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.bindings.add(binding);
|
||||
}
|
||||
|
||||
public void resetBindings(){
|
||||
public void resetBindings() {
|
||||
this.bindings = new ArrayList<>();
|
||||
this.fillBindings();
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import org.parabot.environment.api.utils.WebUtil;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the bot environment
|
||||
*
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package org.parabot.environment;
|
||||
|
||||
/**
|
||||
*
|
||||
* This class is used for detecting the user's operating system
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public enum OperatingSystem {
|
||||
|
||||
@@ -13,12 +11,15 @@ public enum OperatingSystem {
|
||||
|
||||
public static final OperatingSystem getOS() {
|
||||
String str = System.getProperty("os.name").toLowerCase();
|
||||
if (str.indexOf("win") > -1)
|
||||
if (str.indexOf("win") > -1) {
|
||||
return OperatingSystem.WINDOWS;
|
||||
if (str.indexOf("mac") > -1)
|
||||
}
|
||||
if (str.indexOf("mac") > -1) {
|
||||
return OperatingSystem.MAC;
|
||||
if (str.indexOf("nix") > -1 || str.indexOf("nux") > -1)
|
||||
}
|
||||
if (str.indexOf("nix") > -1 || str.indexOf("nux") > -1) {
|
||||
return OperatingSystem.LINUX;
|
||||
}
|
||||
return OperatingSystem.OTHER;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package org.parabot.environment.api.interfaces;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public interface Paintable {
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.security.NoSuchAlgorithmException;
|
||||
*/
|
||||
public class FileUtil {
|
||||
|
||||
public static String getChecksum(File file){
|
||||
public static String getChecksum(File file) {
|
||||
if (file.isFile()) {
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
|
||||
@@ -3,14 +3,16 @@ package org.parabot.environment.api.utils;
|
||||
/**
|
||||
* A simple class to filter things out of an collection
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
* @param <F>
|
||||
*
|
||||
* @author Everel
|
||||
*/
|
||||
public interface Filter<F> {
|
||||
/**
|
||||
* Determines if this object should be accepted
|
||||
*
|
||||
* @param f
|
||||
*
|
||||
* @return <b>true</b> to include this object, otherwise <b>false</b> to exclude.
|
||||
*/
|
||||
public boolean accept(F f);
|
||||
|
||||
@@ -6,10 +6,10 @@ package org.parabot.environment.api.utils;
|
||||
public class JavaUtil {
|
||||
public static double JAVA_VERSION = getVersion();
|
||||
|
||||
static double getVersion () {
|
||||
static double getVersion() {
|
||||
String version = System.getProperty("java.version");
|
||||
int pos = version.indexOf('.');
|
||||
pos = version.indexOf('.', pos+1);
|
||||
return Double.parseDouble (version.substring (0, pos));
|
||||
pos = version.indexOf('.', pos + 1);
|
||||
return Double.parseDouble(version.substring(0, pos));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,20 +3,16 @@ package org.parabot.environment.api.utils;
|
||||
import java.math.BigInteger;
|
||||
|
||||
/**
|
||||
*
|
||||
* Helper class for calculating setters for clients that uses multipliers
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class Multipliers {
|
||||
|
||||
/**
|
||||
* @param multiplier the multiplier
|
||||
* @param set the value you want to set
|
||||
*
|
||||
* @param multiplier
|
||||
* the multiplier
|
||||
* @param set
|
||||
* the value you want to set
|
||||
* @return the correct setter value
|
||||
*/
|
||||
public static int getIntSetter(int multiplier, int set) {
|
||||
@@ -28,11 +24,9 @@ public class Multipliers {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param multiplier the multiplier
|
||||
* @param set the value you want to set
|
||||
*
|
||||
* @param multiplier
|
||||
* the multiplier
|
||||
* @param set
|
||||
* the value you want to set
|
||||
* @return the correct setter value
|
||||
*/
|
||||
public static long getLongSetter(long multiplier, long set) {
|
||||
|
||||
@@ -19,16 +19,14 @@ import java.util.Properties;
|
||||
public class PBPreferences {
|
||||
|
||||
private static AccountManager manager;
|
||||
|
||||
private Properties properties;
|
||||
private int scriptID;
|
||||
|
||||
public static final AccountManagerAccess MANAGER_FETCHER = new AccountManagerAccess() {
|
||||
@Override
|
||||
public final void setManager(AccountManager manager) {
|
||||
PBPreferences.manager = manager;
|
||||
}
|
||||
};
|
||||
private Properties properties;
|
||||
private int scriptID;
|
||||
|
||||
public PBPreferences(int scriptID) {
|
||||
this.scriptID = scriptID;
|
||||
@@ -45,7 +43,7 @@ public class PBPreferences {
|
||||
|
||||
JSONArray resultArray;
|
||||
if ((resultArray = ((JSONArray) result.get("result"))) != null) {
|
||||
for(Object rObject : resultArray) {
|
||||
for (Object rObject : resultArray) {
|
||||
JSONObject resultObject = (JSONObject) rObject;
|
||||
for (Object map : resultObject.entrySet()) {
|
||||
Map.Entry<?, ?> pairs = (Map.Entry<?, ?>) map;
|
||||
@@ -60,6 +58,7 @@ public class PBPreferences {
|
||||
|
||||
/**
|
||||
* Change a setting
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
@@ -69,27 +68,32 @@ public class PBPreferences {
|
||||
|
||||
/**
|
||||
* Get a setting value
|
||||
*
|
||||
* @param key
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Object getSetting(Object key){
|
||||
public Object getSetting(Object key) {
|
||||
return this.properties.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a setting value as string
|
||||
*
|
||||
* @param key
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getSetting(String key){
|
||||
public String getSetting(String key) {
|
||||
return this.properties.getProperty(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a setting
|
||||
*
|
||||
* @param key
|
||||
*/
|
||||
public void removeSetting(Object key){
|
||||
public void removeSetting(Object key) {
|
||||
try {
|
||||
JSONObject result = (JSONObject) WebUtil.getJsonParser().parse(
|
||||
WebUtil.getContents("http://bdn.parabot.org/api/v2/user/preferences/set/",
|
||||
@@ -98,7 +102,7 @@ public class PBPreferences {
|
||||
"&script=" + String.valueOf(scriptID)
|
||||
)
|
||||
);
|
||||
if ((boolean)result.get("result")){
|
||||
if ((boolean) result.get("result")) {
|
||||
this.properties.remove(key);
|
||||
}
|
||||
} catch (ParseException | MalformedURLException | UnsupportedEncodingException e) {
|
||||
@@ -108,10 +112,11 @@ public class PBPreferences {
|
||||
|
||||
/**
|
||||
* Add a setting
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
public void addSetting(Object key, Object value){
|
||||
public void addSetting(Object key, Object value) {
|
||||
try {
|
||||
JSONObject result = (JSONObject) WebUtil.getJsonParser().parse(
|
||||
WebUtil.getContents("http://bdn.parabot.org/api/v2/user/preferences/set/",
|
||||
@@ -121,7 +126,7 @@ public class PBPreferences {
|
||||
"&script=" + String.valueOf(scriptID)
|
||||
)
|
||||
);
|
||||
if ((boolean)result.get("result")){
|
||||
if ((boolean) result.get("result")) {
|
||||
this.properties.put(key, value);
|
||||
}
|
||||
} catch (ParseException | MalformedURLException | UnsupportedEncodingException e) {
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package org.parabot.environment.api.utils;
|
||||
|
||||
/**
|
||||
*
|
||||
* A random class is used for generating random numbers
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class Random {
|
||||
private final static java.util.Random RANDOM = new java.util.Random();
|
||||
@@ -15,6 +13,7 @@ public class Random {
|
||||
*
|
||||
* @param min
|
||||
* @param max
|
||||
*
|
||||
* @return randomized number
|
||||
*/
|
||||
public static int between(final int min, final int max) {
|
||||
|
||||
@@ -3,16 +3,15 @@ package org.parabot.environment.api.utils;
|
||||
import org.parabot.environment.scripts.framework.SleepCondition;
|
||||
|
||||
/**
|
||||
*
|
||||
* Holds various Time utilities
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public final class Time {
|
||||
|
||||
/**
|
||||
* Sleeps for a given amount of time
|
||||
*
|
||||
* @param ms
|
||||
*/
|
||||
public static void sleep(final int ms) {
|
||||
@@ -23,9 +22,7 @@ public final class Time {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param minumum
|
||||
* @param maximum
|
||||
*/
|
||||
@@ -40,10 +37,9 @@ public final class Time {
|
||||
/**
|
||||
* Sleeps until the SleepCondition is valid.
|
||||
*
|
||||
* @param conn
|
||||
* the condition.
|
||||
* @param timeout
|
||||
* the time in miliseconds before it stops sleeping.
|
||||
* @param conn the condition.
|
||||
* @param timeout the time in miliseconds before it stops sleeping.
|
||||
*
|
||||
* @return whether it ran successfully without timing out.
|
||||
*/
|
||||
public static boolean sleep(SleepCondition conn, int timeout) {
|
||||
@@ -59,6 +55,7 @@ public final class Time {
|
||||
|
||||
/**
|
||||
* Gets current time in milliseconds
|
||||
*
|
||||
* @return time in ms
|
||||
*/
|
||||
public static long get() {
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package org.parabot.environment.api.utils;
|
||||
|
||||
/**
|
||||
*
|
||||
* A simple timer class
|
||||
*
|
||||
* @author Everel, Parameter
|
||||
*
|
||||
*/
|
||||
public class Timer {
|
||||
private long start;
|
||||
@@ -17,11 +15,21 @@ public class Timer {
|
||||
* @param end
|
||||
*/
|
||||
public Timer(long end) {
|
||||
|
||||
start = System.currentTimeMillis();
|
||||
this.end = System.currentTimeMillis() + end;
|
||||
}
|
||||
|
||||
/**
|
||||
* Timer Constructor
|
||||
*
|
||||
* @param end
|
||||
* @param start
|
||||
*/
|
||||
public Timer(long end, long start) {
|
||||
this.start = start;
|
||||
this.end = System.currentTimeMillis() + end;
|
||||
}
|
||||
|
||||
/**
|
||||
* Timer Constructor
|
||||
*/
|
||||
@@ -92,8 +100,8 @@ public class Timer {
|
||||
/**
|
||||
* Calculates hourly gains based on given variable
|
||||
*
|
||||
* @param gained
|
||||
* variable
|
||||
* @param gained variable
|
||||
*
|
||||
* @return hourly gains
|
||||
*/
|
||||
public int getPerHour(final int gained) {
|
||||
@@ -101,7 +109,7 @@ public class Timer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates string based on HH:MM:SS
|
||||
* Generates string based on DD:HH:MM:SS
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
@@ -109,9 +117,16 @@ public class Timer {
|
||||
public String toString() {
|
||||
StringBuilder b = new StringBuilder();
|
||||
long elapsed = getElapsedTime();
|
||||
int second = (int) (elapsed / 1000 % 60);
|
||||
int minute = (int) (elapsed / 60000 % 60);
|
||||
int hour = (int) (elapsed / 3600000 % 60);
|
||||
int day = (int) (elapsed / 86400000);
|
||||
elapsed -= day * 86400000;
|
||||
int hour = (int) (elapsed / 3600000);
|
||||
elapsed -= hour * 3600000;
|
||||
int minute = (int) (elapsed / 60000);
|
||||
elapsed -= minute * 60000;
|
||||
int second = (int) (elapsed / 1000);
|
||||
if (day > 0) {
|
||||
b.append(day).append("d:");
|
||||
}
|
||||
b.append(hour < 10 ? "0" : "").append(hour).append(":");
|
||||
b.append(minute < 10 ? "0" : "").append(minute).append(":");
|
||||
b.append(second < 10 ? "0" : "").append(second);
|
||||
|
||||
@@ -4,9 +4,8 @@ import org.parabot.core.ui.utils.UILog;
|
||||
|
||||
public class Version implements Comparable<Version> {
|
||||
|
||||
private String version;
|
||||
|
||||
private static boolean notified;
|
||||
private String version;
|
||||
|
||||
public Version(String version) {
|
||||
if (version == null) {
|
||||
@@ -18,11 +17,24 @@ public class Version implements Comparable<Version> {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
private static void notifyRC() {
|
||||
if (!notified) {
|
||||
UILog.log(
|
||||
"Version warning",
|
||||
"This is an RC version of Parabot\n" +
|
||||
"This could be an unstable version of Parabot, and might crash at anytime\n\n" +
|
||||
"If you find an error within the client, please report any at:\n" +
|
||||
"https://github.com/Parabot/Parabot/issues"
|
||||
);
|
||||
notified = true;
|
||||
}
|
||||
}
|
||||
|
||||
public final String get() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
public boolean isNightly(){
|
||||
public boolean isNightly() {
|
||||
return this.version.contains("RC");
|
||||
}
|
||||
|
||||
@@ -60,17 +72,4 @@ public class Version implements Comparable<Version> {
|
||||
public boolean equals(Object that) {
|
||||
return this == that || that != null && this.getClass() == that.getClass() && this.compareTo((Version) that) == 0;
|
||||
}
|
||||
|
||||
private static void notifyRC() {
|
||||
if (!notified) {
|
||||
UILog.log(
|
||||
"Version warning",
|
||||
"This is an RC version of Parabot\n" +
|
||||
"This could be an unstable version of Parabot, and might crash at anytime\n\n" +
|
||||
"If you find an error within the client, please report any at:\n" +
|
||||
"https://github.com/Parabot/Parabot/issues"
|
||||
);
|
||||
notified = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,32 @@
|
||||
package org.parabot.environment.input;
|
||||
|
||||
import java.awt.Component;
|
||||
import org.parabot.core.Context;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
|
||||
import org.parabot.core.Context;
|
||||
|
||||
/**
|
||||
*
|
||||
* Virtual keyboard, dispatches key events to a component.
|
||||
*
|
||||
* @author Everel, Matt, Dane
|
||||
*
|
||||
*/
|
||||
public class Keyboard implements KeyListener {
|
||||
private static HashMap<Character, Character> specialChars;
|
||||
|
||||
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 Component component;
|
||||
private long pressTime;
|
||||
|
||||
@@ -28,16 +38,6 @@ public class Keyboard implements KeyListener {
|
||||
return Context.getInstance().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;
|
||||
@@ -46,7 +46,7 @@ public class Keyboard implements KeyListener {
|
||||
public void sendKeys(String s) {
|
||||
|
||||
pressTime = System.currentTimeMillis();
|
||||
for (char c : s.toCharArray())
|
||||
for (char c : s.toCharArray()) {
|
||||
for (KeyEvent ke : createKeyClick(component, c)) {
|
||||
try {
|
||||
Thread.sleep(5);
|
||||
@@ -55,22 +55,25 @@ public class Keyboard implements KeyListener {
|
||||
}
|
||||
sendKeyEvent(ke);
|
||||
}
|
||||
}
|
||||
clickKey(10);
|
||||
}
|
||||
|
||||
public void clickKey(char c) {
|
||||
|
||||
pressTime = System.currentTimeMillis();
|
||||
for (KeyEvent ke : createKeyClick(component, c))
|
||||
for (KeyEvent ke : createKeyClick(component, c)) {
|
||||
sendKeyEvent(ke);
|
||||
}
|
||||
}
|
||||
|
||||
public void clickKey(int keyCode) {
|
||||
|
||||
pressTime = System.currentTimeMillis();
|
||||
for (KeyEvent ke : createKeyClick(component, keyCode))
|
||||
for (KeyEvent ke : createKeyClick(component, keyCode)) {
|
||||
sendKeyEvent(ke);
|
||||
}
|
||||
}
|
||||
|
||||
public void pressKey(int keyCode) {
|
||||
|
||||
@@ -103,7 +106,7 @@ public class Keyboard implements KeyListener {
|
||||
KeyEvent released = new KeyEvent(target, KeyEvent.KEY_RELEASED,
|
||||
pressTime, 0, keyCode, c);
|
||||
|
||||
return new KeyEvent[] { pressed, typed, released };
|
||||
return new KeyEvent[]{ pressed, typed, released };
|
||||
} else {
|
||||
KeyEvent shiftDown = new KeyEvent(target, KeyEvent.KEY_PRESSED,
|
||||
pressTime, KeyEvent.SHIFT_MASK, KeyEvent.VK_SHIFT,
|
||||
@@ -121,7 +124,7 @@ public class Keyboard implements KeyListener {
|
||||
KeyEvent shiftUp = new KeyEvent(target, KeyEvent.KEY_RELEASED,
|
||||
pressTime, 0, KeyEvent.VK_SHIFT, KeyEvent.CHAR_UNDEFINED);
|
||||
|
||||
return new KeyEvent[] { shiftDown, pressed, typed, released,
|
||||
return new KeyEvent[]{ shiftDown, pressed, typed, released,
|
||||
shiftUp };
|
||||
}
|
||||
}
|
||||
@@ -144,7 +147,7 @@ public class Keyboard implements KeyListener {
|
||||
KeyEvent released = new KeyEvent(target, KeyEvent.KEY_RELEASED,
|
||||
pressTime + getRandom(), 0, keyCode, KeyEvent.CHAR_UNDEFINED);
|
||||
|
||||
return new KeyEvent[] { pressed, released };
|
||||
return new KeyEvent[]{ pressed, released };
|
||||
}
|
||||
|
||||
private KeyEvent createKeyPress(Component target, int keyCode) {
|
||||
@@ -188,7 +191,7 @@ public class Keyboard implements KeyListener {
|
||||
|
||||
public void sendKeyEvent(KeyEvent e) {
|
||||
for (KeyListener kl : component.getKeyListeners()) {
|
||||
if(kl instanceof Keyboard) {
|
||||
if (kl instanceof Keyboard) {
|
||||
continue;
|
||||
}
|
||||
if (!e.isConsumed()) {
|
||||
|
||||
@@ -9,11 +9,9 @@ import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
|
||||
/**
|
||||
*
|
||||
* A virtual mouse, dispatches mouse events to a component
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class Mouse implements MouseListener, MouseMotionListener {
|
||||
private Component component;
|
||||
@@ -30,6 +28,7 @@ public class Mouse implements MouseListener, MouseMotionListener {
|
||||
|
||||
/**
|
||||
* Moves the mouse to the given point and clicks
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param left
|
||||
@@ -49,8 +48,8 @@ public class Mouse implements MouseListener, MouseMotionListener {
|
||||
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)) {
|
||||
for (MouseListener l : component.getMouseListeners()) {
|
||||
if (!(l instanceof Mouse)) {
|
||||
l.mousePressed(me);
|
||||
}
|
||||
}
|
||||
@@ -70,8 +69,8 @@ public class Mouse implements MouseListener, MouseMotionListener {
|
||||
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)) {
|
||||
for (MouseListener l : component.getMouseListeners()) {
|
||||
if (!(l instanceof Mouse)) {
|
||||
l.mouseClicked(me);
|
||||
}
|
||||
}
|
||||
@@ -86,8 +85,8 @@ public class Mouse implements MouseListener, MouseMotionListener {
|
||||
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)) {
|
||||
for (MouseListener l : component.getMouseListeners()) {
|
||||
if (!(l instanceof Mouse)) {
|
||||
l.mouseReleased(me);
|
||||
}
|
||||
}
|
||||
@@ -98,6 +97,7 @@ public class Mouse implements MouseListener, MouseMotionListener {
|
||||
|
||||
/**
|
||||
* Moves the mouse cursor to the given location
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
*/
|
||||
@@ -106,8 +106,8 @@ public class Mouse implements MouseListener, MouseMotionListener {
|
||||
MouseEvent me = new MouseEvent(component,
|
||||
MouseEvent.MOUSE_MOVED, System.currentTimeMillis(), 0, x,
|
||||
y, 0, false);
|
||||
for(MouseMotionListener l : component.getMouseMotionListeners()) {
|
||||
if(!(l instanceof Mouse)) {
|
||||
for (MouseMotionListener l : component.getMouseMotionListeners()) {
|
||||
if (!(l instanceof Mouse)) {
|
||||
l.mouseMoved(me);
|
||||
}
|
||||
}
|
||||
@@ -118,6 +118,7 @@ public class Mouse implements MouseListener, MouseMotionListener {
|
||||
|
||||
/**
|
||||
* Mouse cursor current location
|
||||
*
|
||||
* @return point
|
||||
*/
|
||||
public Point getPoint() {
|
||||
|
||||
@@ -48,6 +48,7 @@ public class RandomHandler {
|
||||
|
||||
/**
|
||||
* @param random
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
@@ -77,15 +78,6 @@ public class RandomHandler {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the whole random arraylist to the arraylist given as argument
|
||||
*
|
||||
* @param randoms The new random arraylist
|
||||
*/
|
||||
public void setRandoms(ArrayList<Random> randoms) {
|
||||
this.randoms = randoms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all added randoms
|
||||
*/
|
||||
@@ -104,15 +96,16 @@ public class RandomHandler {
|
||||
* Executes a specific random
|
||||
*
|
||||
* @param r
|
||||
*
|
||||
* @return True if the random is executed, false if not
|
||||
*/
|
||||
public boolean executeRandom(Random r){
|
||||
public boolean executeRandom(Random r) {
|
||||
if (r.activate()) {
|
||||
Logger.addMessage("Running random '" + r.getName() + "'", true);
|
||||
try {
|
||||
r.execute();
|
||||
return true;
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
Logger.addMessage("Random failed: '" + r.getName() + "'", false);
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -126,7 +119,7 @@ public class RandomHandler {
|
||||
*
|
||||
* @param type
|
||||
*/
|
||||
public void runAll(RandomType type){
|
||||
public void runAll(RandomType type) {
|
||||
for (Random r : this.activeRandoms) {
|
||||
if (r.getRandomType().getId() == type.getId()) {
|
||||
executeRandom(r);
|
||||
@@ -152,6 +145,7 @@ public class RandomHandler {
|
||||
* Checks if random occurs and runs it
|
||||
*
|
||||
* @return returns <b>true</b> if a random has been executed, otherwise <b>false</b>
|
||||
*
|
||||
* @see RandomHandler#checkAndRun(RandomType)
|
||||
* @deprecated
|
||||
*/
|
||||
@@ -165,6 +159,15 @@ public class RandomHandler {
|
||||
return this.randoms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the whole random arraylist to the arraylist given as argument
|
||||
*
|
||||
* @param randoms The new random arraylist
|
||||
*/
|
||||
public void setRandoms(ArrayList<Random> randoms) {
|
||||
this.randoms = randoms;
|
||||
}
|
||||
|
||||
public ArrayList<Random> getActiveRandoms() {
|
||||
return this.activeRandoms;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,10 @@ public enum RandomType {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public static RandomType getDefault() {
|
||||
return SCRIPT;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -25,8 +29,4 @@ public enum RandomType {
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public static RandomType getDefault() {
|
||||
return SCRIPT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,47 +5,15 @@ import org.parabot.core.ui.images.Images;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.HashMap;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Holds script categories
|
||||
*
|
||||
* @author Dane, Paradox
|
||||
*
|
||||
*/
|
||||
public enum Category
|
||||
{
|
||||
public enum Category {
|
||||
|
||||
AGILITY, COMBAT, COOKING, CRAFTING, CONSTRUCTION, DUNGEONEERING, FARMING, FIREMAKING, FISHING, FLETCHING, HERBLORE, HUNTER, MAGIC, MINIGAMES, MINING, MONEYMAKING, OTHER, PRAYER, RUNECRAFTING, SLAYER, SMITHING, THIEVING, UTILITY, WOODCUTTING;
|
||||
|
||||
/**
|
||||
* Gets image belonging to this category
|
||||
* @return icon
|
||||
*/
|
||||
public BufferedImage getIcon() {
|
||||
return Category.getIcon(this.name().toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets category icon image from filename
|
||||
* @param s Name of the image - used for the hashmap index
|
||||
* @return icon
|
||||
*/
|
||||
public static BufferedImage getIcon(String s) {
|
||||
if (images.get(s) == null) {
|
||||
images.put(s, Images.getResource("/storage/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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache
|
||||
*/
|
||||
@@ -55,4 +23,35 @@ public enum Category
|
||||
images.put("script", Images.getResource("/storage/images/category/script.png"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets category icon image from filename
|
||||
*
|
||||
* @param s Name of the image - used for the hashmap index
|
||||
*
|
||||
* @return icon
|
||||
*/
|
||||
public static BufferedImage getIcon(String s) {
|
||||
if (images.get(s) == null) {
|
||||
images.put(s, Images.getResource("/storage/images/category/" + s + ".png"));
|
||||
}
|
||||
return images.get(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets image belonging to this category
|
||||
*
|
||||
* @return icon
|
||||
*/
|
||||
public BufferedImage getIcon() {
|
||||
return Category.getIcon(this.name().toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.append(name().charAt(0));
|
||||
b.append(name().toLowerCase().substring(1));
|
||||
return new String(b);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
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;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
*
|
||||
* Holds various script frameworks
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class Frameworks {
|
||||
|
||||
@@ -31,10 +29,11 @@ class Looper extends AbstractFramework {
|
||||
public Looper(LoopTask loopTask) {
|
||||
this.loopTask = loopTask;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute() {
|
||||
int sleepTime = loopTask.loop();
|
||||
if(sleepTime < 0) {
|
||||
if (sleepTime < 0) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
@@ -55,8 +54,8 @@ class StrategyWorker extends AbstractFramework {
|
||||
|
||||
@Override
|
||||
public boolean execute() {
|
||||
for(Strategy s : strategies) {
|
||||
if(s.activate()) {
|
||||
for (Strategy s : strategies) {
|
||||
if (s.activate()) {
|
||||
s.execute();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ import org.parabot.core.ui.BotUI;
|
||||
import org.parabot.core.ui.Logger;
|
||||
import org.parabot.environment.api.utils.PBPreferences;
|
||||
import org.parabot.environment.api.utils.Time;
|
||||
import org.parabot.environment.randoms.Random;
|
||||
import org.parabot.environment.randoms.RandomType;
|
||||
import org.parabot.environment.scripts.framework.*;
|
||||
import org.parabot.environment.scripts.framework.Frameworks;
|
||||
import org.parabot.environment.scripts.randoms.Random;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -61,6 +61,11 @@ public class Script implements Runnable {
|
||||
this.frameWork = f;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public final void addRandom(org.parabot.environment.scripts.randoms.Random random) {
|
||||
new IllegalArgumentException("This type of random is deprecated").printStackTrace();
|
||||
}
|
||||
|
||||
public final void addRandom(Random random) {
|
||||
Context.getInstance().getRandomHandler().addRandom(random);
|
||||
}
|
||||
@@ -141,6 +146,7 @@ public class Script implements Runnable {
|
||||
*
|
||||
* @param conn the condition.
|
||||
* @param timeout the time in miliseconds before it stops sleeping.
|
||||
*
|
||||
* @return whether it ran successfully without timing out.
|
||||
*/
|
||||
@Deprecated
|
||||
@@ -148,18 +154,6 @@ public class Script implements Runnable {
|
||||
return Time.sleep(conn, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
@@ -173,6 +167,18 @@ public class Script implements Runnable {
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
public PBPreferences getPreferences() {
|
||||
if (this.preferences == null) {
|
||||
this.preferences = new PBPreferences(scriptID);
|
||||
|
||||
@@ -5,8 +5,8 @@ import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* A script manifest, holds all script data
|
||||
* @author Everel
|
||||
*
|
||||
* @author Everel
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ScriptManifest {
|
||||
|
||||
@@ -15,11 +15,9 @@ import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
/**
|
||||
*
|
||||
* Loads a script from the BDN
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class BDNScriptsExecuter extends ScriptExecuter {
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user