mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-03 08:39:09 +00:00
Conditional callback support
This commit is contained in:
@@ -6,6 +6,8 @@ import org.objectweb.asm.Label;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
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;
|
||||
@@ -26,15 +28,17 @@ public class AddCallbackAdapter implements Injectable, Opcodes {
|
||||
private String invokeMethod;
|
||||
private String desc;
|
||||
private int[] args;
|
||||
private boolean conditional;
|
||||
|
||||
public AddCallbackAdapter(final MethodNode method,
|
||||
final String invokeClass, final String invokeMethod,
|
||||
final String desc, final int[] args) {
|
||||
final String desc, final int[] args, final boolean conditional) {
|
||||
this.method = method;
|
||||
this.invokeClass = invokeClass;
|
||||
this.invokeMethod = invokeMethod;
|
||||
this.desc = desc;
|
||||
this.args = args;
|
||||
this.conditional = conditional;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,6 +64,12 @@ public class AddCallbackAdapter implements Injectable, Opcodes {
|
||||
inject.add(new MethodInsnNode(INVOKESTATIC,
|
||||
this.invokeClass, this.invokeMethod,
|
||||
this.desc));
|
||||
if(this.conditional) {
|
||||
LabelNode ln = new LabelNode(new Label());
|
||||
inject.add(new JumpInsnNode(IFEQ, ln));
|
||||
inject.add(new InsnNode(RETURN));
|
||||
inject.add(ln);
|
||||
}
|
||||
this.method.instructions.insert(inject);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,14 +18,16 @@ public class Callback implements Injectable {
|
||||
private String invokeMethod;
|
||||
private String desc;
|
||||
private int[] args;
|
||||
|
||||
private boolean conditional;
|
||||
|
||||
public Callback(final String className, final String methodName,
|
||||
final String methodDesc, final String callbackClass,
|
||||
final String callbackMethod, final String callbackDesc, String args) {
|
||||
final String callbackMethod, final String callbackDesc, String args, final boolean conditional) {
|
||||
this.method = ASMUtils.getMethod(className, methodName, methodDesc);
|
||||
this.invokeClass = callbackClass;
|
||||
this.invokeMethod = callbackMethod;
|
||||
this.desc = callbackDesc;
|
||||
this.conditional = conditional;
|
||||
if (args.contains(",")) {
|
||||
final String[] strArgs = args.split(",");
|
||||
this.args = new int[strArgs.length];
|
||||
@@ -44,7 +46,7 @@ public class Callback implements Injectable {
|
||||
|
||||
public AddCallbackAdapter getAdapter() {
|
||||
return new AddCallbackAdapter(this.method, this.invokeClass,
|
||||
this.invokeMethod, this.desc, this.args);
|
||||
this.invokeMethod, this.desc, this.args, this.conditional);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ public class JSONHookParser extends HookParser {
|
||||
|
||||
String clazz = o.containsKey("class") ? this.get(o, "class") : interfaces.get(this.get(o, "accessor"));
|
||||
|
||||
c[j] = new Callback(clazz, this.get(o, "method"), this.get(o, "callclass"), this.get(o, "callmethod"), this.get(o, "calldesc"), this.get(o, "callargs"), this.get(o, "desc"));
|
||||
c[j] = new Callback(clazz, this.get(o, "method"), this.get(o, "callclass"), this.get(o, "callmethod"), this.get(o, "calldesc"), this.get(o, "callargs"), this.get(o, "desc"), false);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
@@ -445,9 +445,10 @@ public class XMLHookParser extends HookParser {
|
||||
final String callDesc = getValue("calldesc", addCallback);
|
||||
final String callArgs = getValue("callargs", addCallback);
|
||||
final String desc = getValue("desc", addCallback);
|
||||
final boolean conditional = isSet("conditional", addCallback);
|
||||
|
||||
final Callback callback = new Callback(className, methodName, desc,
|
||||
callClass, callMethod, callDesc, callArgs);
|
||||
callClass, callMethod, callDesc, callArgs, conditional);
|
||||
callbackList.add(callback);
|
||||
}
|
||||
return callbackList.toArray(new Callback[callbackList.size()]);
|
||||
|
||||
Reference in New Issue
Block a user