mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-04 00:37:46 +00:00
Injector: multiplier support added
This commit is contained in:
@@ -25,6 +25,7 @@ public class AddGetterAdapter implements Opcodes, Injectable {
|
||||
private String returnDesc;
|
||||
private boolean staticField;
|
||||
private boolean staticMethod;
|
||||
private long multiplier;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -40,11 +41,12 @@ public class AddGetterAdapter implements Opcodes, Injectable {
|
||||
* - 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 multiplier
|
||||
*/
|
||||
public AddGetterAdapter(final ClassNode into,
|
||||
final ClassNode fieldLocation, final FieldNode fieldNode,
|
||||
final String methodName, final String returnDesc,
|
||||
final boolean staticMethod) {
|
||||
final boolean staticMethod, final long multiplier) {
|
||||
this.into = into;
|
||||
this.fieldLocation = fieldLocation;
|
||||
this.fieldNode = fieldNode;
|
||||
@@ -52,6 +54,7 @@ public class AddGetterAdapter implements Opcodes, Injectable {
|
||||
this.returnDesc = returnDesc == null ? fieldNode.desc : returnDesc;
|
||||
this.staticField = Modifier.isStatic(fieldNode.access);
|
||||
this.staticMethod = staticMethod;
|
||||
this.multiplier = multiplier;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,7 +120,7 @@ public class AddGetterAdapter implements Opcodes, Injectable {
|
||||
@Override
|
||||
public void inject() {
|
||||
Core.verbose("Injecting: " + this.toString());
|
||||
|
||||
|
||||
MethodNode method = new MethodNode(ACC_PUBLIC
|
||||
| (staticMethod ? ACC_STATIC : 0), methodName, "()"
|
||||
+ returnDesc, null, null);
|
||||
@@ -138,8 +141,21 @@ public class AddGetterAdapter implements Opcodes, Injectable {
|
||||
}
|
||||
}
|
||||
|
||||
if (fieldNode.desc.equals("J") && returnDesc.equals("I"))
|
||||
if(multiplier != 0) {
|
||||
if(fieldNode.desc.equals("I")) {
|
||||
method.visitInsn(I2L);
|
||||
}
|
||||
method.visitLdcInsn(new Long(multiplier));
|
||||
method.visitInsn(LMUL);
|
||||
if(returnDesc.equals("I")) {
|
||||
method.visitInsn(L2I);
|
||||
}
|
||||
} else if (fieldNode.desc.equals("J") && returnDesc.equals("I")) {
|
||||
method.visitInsn(L2I);
|
||||
} else if(fieldNode.desc.equals("I") && returnDesc.equals("J")) {
|
||||
method.visitInsn(I2L);
|
||||
}
|
||||
|
||||
|
||||
method.visitInsn(ASMUtils.getReturnOpcode(returnDesc));
|
||||
method.visitMaxs(1, 1);
|
||||
|
||||
@@ -21,6 +21,7 @@ public class Getter implements Injectable {
|
||||
private String methodName;
|
||||
private String returnDesc;
|
||||
private boolean staticMethod;
|
||||
private long multiplier;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -30,9 +31,10 @@ public class Getter implements Injectable {
|
||||
* @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 there is one, otherwise 0L
|
||||
*/
|
||||
public Getter(final String into, final String fieldLocation, final String fieldNode,
|
||||
final String methodName, final String returnDesc, final boolean staticMethod) {
|
||||
final String methodName, final String returnDesc, final boolean staticMethod, final long multiplier) {
|
||||
Core.verbose(methodName + "[" + fieldLocation + "." + fieldNode + "]");
|
||||
this.into = ASMUtils.getClass(into);
|
||||
this.fieldLocation = ASMUtils.getClass(fieldLocation);
|
||||
@@ -40,6 +42,7 @@ public class Getter implements Injectable {
|
||||
this.methodName = methodName;
|
||||
this.returnDesc = returnDesc == null ? this.fieldNode.desc : returnDesc;
|
||||
this.staticMethod = staticMethod;
|
||||
this.multiplier = multiplier;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,7 +74,7 @@ public class Getter implements Injectable {
|
||||
* @return AddGetterAdapter
|
||||
*/
|
||||
public AddGetterAdapter getAdapter() {
|
||||
return new AddGetterAdapter(into, fieldLocation, fieldNode, methodName, returnDesc, staticMethod);
|
||||
return new AddGetterAdapter(into, fieldLocation, fieldNode, methodName, returnDesc, staticMethod, multiplier);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ public class JSONHookParser extends HookParser {
|
||||
String clazz = o.containsKey("class") ? this.get(o, "class") : interfaces.get(this.get(o, "accessor"));
|
||||
String into = o.containsKey("into") ? this.get(o, "into") : clazz;
|
||||
|
||||
g[i] = new Getter(into, clazz, this.get(o, "field"), this.get(o, "method"), desc, o.containsKey("static") ? (boolean) o.get("static") : false);
|
||||
g[i] = new Getter(into, clazz, this.get(o, "field"), this.get(o, "method"), desc, o.containsKey("static") ? (boolean) o.get("static") : false, 0);
|
||||
}
|
||||
return g;
|
||||
}
|
||||
|
||||
@@ -159,6 +159,7 @@ public class XMLHookParser extends HookParser {
|
||||
"accessor", addGetter));
|
||||
final String into = isSet("into", addGetter) ? getValue("into",
|
||||
addGetter) : className;
|
||||
final long multiplier = isSet("multiplier", addGetter) ? Long.parseLong(getValue("multiplier", addGetter)) : 0L;
|
||||
final String fieldName = getValue("field", addGetter);
|
||||
final String methodName = getValue("methodname", addGetter);
|
||||
boolean staticMethod = isSet("methstatic", addGetter) ? (getValue(
|
||||
@@ -184,7 +185,7 @@ public class XMLHookParser extends HookParser {
|
||||
returnDesc = str.toString();
|
||||
}
|
||||
final Getter get = new Getter(into, className, fieldName,
|
||||
methodName, returnDesc, staticMethod);
|
||||
methodName, returnDesc, staticMethod, multiplier);
|
||||
getterList.add(get);
|
||||
}
|
||||
return getterList.toArray(new Getter[getterList.size()]);
|
||||
|
||||
Reference in New Issue
Block a user