mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-03 00:37:55 +00:00
Updated context and environment
This commit is contained in:
@@ -10,7 +10,7 @@ import org.parabot.core.ui.ServerSelector;
|
||||
* Parabot X - A revolution in bot clients
|
||||
*
|
||||
* @author Clisprail
|
||||
* @author Matt, Dane, Queue, Parameter
|
||||
* @author Matt, Dane, Parameter
|
||||
* @version 2.0
|
||||
*/
|
||||
public class Landing {
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.applet.Applet;
|
||||
import java.util.HashMap;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.parabot.core.asm.ASMClassLoader;
|
||||
import org.parabot.core.bot.loader.BotLoader;
|
||||
import org.parabot.core.classpath.ClassPath;
|
||||
@@ -80,6 +81,9 @@ public class Context {
|
||||
*/
|
||||
public void load() {
|
||||
serverProvider.parseJar();
|
||||
for(final ClassNode node : classPath.classes.values()) {
|
||||
serverProvider.inject(node);
|
||||
}
|
||||
gameApplet = serverProvider.fetchApplet();
|
||||
final GamePanel panel = GamePanel.getInstance();
|
||||
panel.removeLoader();
|
||||
|
||||
@@ -14,15 +14,9 @@ import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.parabot.core.classpath.ClassPath;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Clisprail
|
||||
* @author Matt
|
||||
*
|
||||
*/
|
||||
public class ASMClassLoader extends ClassLoader {
|
||||
|
||||
public Map<String,Class<?>>classCache = new HashMap<String,Class<?>>();
|
||||
|
||||
private Map<String, Class<?>> classCache = new HashMap<String, Class<?>>();
|
||||
public ClassPath classPath = null;
|
||||
|
||||
public ASMClassLoader(final ClassPath classPath) {
|
||||
@@ -32,17 +26,13 @@ public class ASMClassLoader extends ClassLoader {
|
||||
@Override
|
||||
protected URL findResource(String name) {
|
||||
if (getSystemResource(name) == null) {
|
||||
if (classPath.resources.containsKey(name))
|
||||
if (classPath.resources.containsKey(name)) {
|
||||
return classPath.resources.get(name);
|
||||
else
|
||||
} else {
|
||||
return null;
|
||||
} else
|
||||
return getSystemResource(name);
|
||||
}
|
||||
|
||||
public void addClassToCache(final Class<?> clazz) {
|
||||
String clazzName = clazz.getName().replace('.', '/');
|
||||
classCache.put(clazzName, clazz);
|
||||
}
|
||||
}
|
||||
return getSystemResource(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -51,25 +41,25 @@ public class ASMClassLoader extends ClassLoader {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> findClass(String name) throws ClassNotFoundException {
|
||||
protected Class<?> findClass(String name) throws ClassNotFoundException {
|
||||
String key = name.replace('.', '/');
|
||||
if(classCache.containsKey(key)) {
|
||||
if (classCache.containsKey(key)) {
|
||||
return classCache.get(key);
|
||||
}
|
||||
|
||||
ClassNode node = classPath.classes.get(key);
|
||||
if (node != null) {
|
||||
classPath.classes.remove(key);
|
||||
Class<?>c = nodeToClass(node);
|
||||
Class<?> c = nodeToClass(node);
|
||||
classCache.put(key, c);
|
||||
return c;
|
||||
} else
|
||||
return super.getSystemClassLoader().loadClass(name);
|
||||
}
|
||||
return super.getSystemClassLoader().loadClass(name);
|
||||
}
|
||||
|
||||
public final Class<?> nodeToClass(ClassNode node) {
|
||||
if (super.findLoadedClass(node.name) != null)
|
||||
private final Class<?> nodeToClass(ClassNode node) {
|
||||
if (super.findLoadedClass(node.name) != null) {
|
||||
return findLoadedClass(node.name);
|
||||
}
|
||||
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
|
||||
node.accept(cw);
|
||||
byte[] b = cw.toByteArray();
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.parabot.core.asm.adapters;
|
||||
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.parabot.core.asm.ASMUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Clisprail
|
||||
*
|
||||
*/
|
||||
public class AddInterfaceAdapter {
|
||||
|
||||
private static String accessorPackage = null;
|
||||
private ClassNode node = null;
|
||||
private String interfaceClass = null;
|
||||
|
||||
public AddInterfaceAdapter(ClassNode node, String interfaceClass) {
|
||||
this.node = node;
|
||||
this.interfaceClass = interfaceClass;
|
||||
}
|
||||
|
||||
public AddInterfaceAdapter(String className, String interfaceClass) {
|
||||
this.node = ASMUtils.getClass(className);
|
||||
this.interfaceClass = interfaceClass;
|
||||
}
|
||||
|
||||
public static void setAccessorPackage(String packageName) {
|
||||
accessorPackage = packageName;
|
||||
}
|
||||
|
||||
public static String getAccessorPackage() {
|
||||
return accessorPackage;
|
||||
}
|
||||
|
||||
public void inject() {
|
||||
addInterface(node, accessorPackage + interfaceClass);
|
||||
}
|
||||
|
||||
protected static void addInterface(ClassNode cg, String i) {
|
||||
System.out.println(" ^ " + cg.name + " implements " + i);
|
||||
cg.interfaces.add(i);
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ public class BotLoader extends ASMClassLoader {
|
||||
|
||||
@Override
|
||||
public Class<?> findClass(String name) throws ClassNotFoundException {
|
||||
String key = name.replace('.', '/');
|
||||
/*String key = name.replace('.', '/');
|
||||
if(serverProvider.classCache.containsKey(key)) {
|
||||
return serverProvider.classCache.get(key);
|
||||
}
|
||||
@@ -35,7 +35,7 @@ public class BotLoader extends ASMClassLoader {
|
||||
Class<?>c = serverProvider.nodeToClass(node);
|
||||
serverProvider.classCache.put(key, c);
|
||||
return c;
|
||||
}
|
||||
}*/
|
||||
return super.findClass(name);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package org.parabot.core.parsers;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -40,6 +43,13 @@ public class ServerManifestParser {
|
||||
private ServerDescription[] localDesc() {
|
||||
final ClassPath path = new ClassPath();
|
||||
path.loadClasses(Directories.getServerPath(), null);
|
||||
try {
|
||||
Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
|
||||
method.setAccessible(true);
|
||||
method.invoke((URLClassLoader) ClassLoader.getSystemClassLoader(), Directories.getServerPath().toURI().toURL());
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
final ServerLoader loader = new ServerLoader(path);
|
||||
final List<ServerProvider> providers = new ArrayList<ServerProvider>();
|
||||
final List<ServerDescription> descs = new ArrayList<ServerDescription>();
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.applet.AppletStub;
|
||||
import java.net.URL;
|
||||
import javax.swing.JMenuBar;
|
||||
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.parabot.core.Context;
|
||||
/**
|
||||
* Provides a server to the bot
|
||||
@@ -34,6 +35,10 @@ public abstract class ServerProvider {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void inject(ClassNode node) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add custom items to the bot menu bar
|
||||
* @param menu bar to add items on
|
||||
|
||||
Reference in New Issue
Block a user