mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-03 00:37:55 +00:00
Merge pull request #303 from Parabot/task/thread-getId-redirect
[TASK] Added Thread#getId redirect
This commit is contained in:
@@ -73,8 +73,8 @@ public class Context {
|
|||||||
public static double getJavaVersion() {
|
public static double getJavaVersion() {
|
||||||
String version = System.getProperty("java.version");
|
String version = System.getProperty("java.version");
|
||||||
int pos = version.indexOf('.');
|
int pos = version.indexOf('.');
|
||||||
pos = version.indexOf('.', pos+1);
|
pos = version.indexOf('.', pos + 1);
|
||||||
return Double.parseDouble(version.substring (0, pos));
|
return Double.parseDouble(version.substring(0, pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -65,4 +65,8 @@ public class ThreadRedirect {
|
|||||||
public static boolean isInterrupted(Thread thread) {
|
public static boolean isInterrupted(Thread thread) {
|
||||||
return thread.isInterrupted();
|
return thread.isInterrupted();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static long getId(Thread thread) {
|
||||||
|
return thread.getId();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,15 +22,15 @@ import java.util.Map;
|
|||||||
* @author JKetelaar
|
* @author JKetelaar
|
||||||
*/
|
*/
|
||||||
public class XMLHookParser extends HookParser {
|
public class XMLHookParser extends HookParser {
|
||||||
private Document doc;
|
private Document doc;
|
||||||
private HashMap<String, String> interfaceMap;
|
private HashMap<String, String> interfaceMap;
|
||||||
private HashMap<String, String> constants;
|
private HashMap<String, String> constants;
|
||||||
private boolean parsedInterfaces;
|
private boolean parsedInterfaces;
|
||||||
|
|
||||||
public XMLHookParser(HookFile hookFile) {
|
public XMLHookParser(HookFile hookFile) {
|
||||||
super(hookFile);
|
super(hookFile);
|
||||||
interfaceMap = new HashMap<String, String>();
|
interfaceMap = new HashMap<>();
|
||||||
constants = new HashMap<String, String>();
|
constants = new HashMap<>();
|
||||||
try {
|
try {
|
||||||
DocumentBuilderFactory dbFactory = DocumentBuilderFactory
|
DocumentBuilderFactory dbFactory = DocumentBuilderFactory
|
||||||
.newInstance();
|
.newInstance();
|
||||||
@@ -45,48 +45,6 @@ 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) {
|
|
||||||
if (element.getElementsByTagName(tag).item(0) == null) {
|
|
||||||
throw new NullPointerException("MISSING HOOK TAG: The '" + tag + "' xml tag is missing from one of the hooks of type: " + element.getParentNode().getNodeName());
|
|
||||||
}
|
|
||||||
NodeList nodes = element.getElementsByTagName(tag).item(0)
|
|
||||||
.getChildNodes();
|
|
||||||
if (nodes.getLength() == 0 || nodes.item(0) == null) {
|
|
||||||
if (Core.inVerboseMode()) {
|
|
||||||
System.err.println("WARNING: Invalid Hook " + tag + " subnode. Tag is missing or empty?");
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
Node node = (Node) nodes.item(0);
|
|
||||||
return node.getNodeValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Interface[] getInterfaces() {
|
public Interface[] getInterfaces() {
|
||||||
parsedInterfaces = true;
|
parsedInterfaces = true;
|
||||||
@@ -105,8 +63,8 @@ public class XMLHookParser extends HookParser {
|
|||||||
if (node.getNodeType() != Node.ELEMENT_NODE) {
|
if (node.getNodeType() != Node.ELEMENT_NODE) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final Element interfaceRoot = (Element) node;
|
final Element interfaceRoot = (Element) node;
|
||||||
final NodeList interfaces = interfaceRoot.getElementsByTagName("add");
|
final NodeList interfaces = interfaceRoot.getElementsByTagName("add");
|
||||||
if (interfaces.getLength() == 0) {
|
if (interfaces.getLength() == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -116,9 +74,9 @@ public class XMLHookParser extends HookParser {
|
|||||||
if (n.getNodeType() != Node.ELEMENT_NODE) {
|
if (n.getNodeType() != Node.ELEMENT_NODE) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final Element addInterface = (Element) n;
|
final Element addInterface = (Element) n;
|
||||||
final String className = getValue("classname", addInterface);
|
final String className = getValue("classname", addInterface);
|
||||||
final String interfaceClass = getValue("interface", addInterface);
|
final String interfaceClass = getValue("interface", addInterface);
|
||||||
interfaceMap.put(interfaceClass, className);
|
interfaceMap.put(interfaceClass, className);
|
||||||
final Interface inf = new Interface(className, interfaceClass);
|
final Interface inf = new Interface(className, interfaceClass);
|
||||||
interfaceList.add(inf);
|
interfaceList.add(inf);
|
||||||
@@ -147,8 +105,8 @@ public class XMLHookParser extends HookParser {
|
|||||||
if (node.getNodeType() != Node.ELEMENT_NODE) {
|
if (node.getNodeType() != Node.ELEMENT_NODE) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final Element superRoot = (Element) node;
|
final Element superRoot = (Element) node;
|
||||||
final NodeList supers = superRoot.getElementsByTagName("add");
|
final NodeList supers = superRoot.getElementsByTagName("add");
|
||||||
if (supers.getLength() == 0) {
|
if (supers.getLength() == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -158,10 +116,10 @@ public class XMLHookParser extends HookParser {
|
|||||||
if (n.getNodeType() != Node.ELEMENT_NODE) {
|
if (n.getNodeType() != Node.ELEMENT_NODE) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final Element addSuper = (Element) n;
|
final Element addSuper = (Element) n;
|
||||||
final String className = getValue("classname", addSuper);
|
final String className = getValue("classname", addSuper);
|
||||||
final String superClass = getValue("super", addSuper);
|
final String superClass = getValue("super", addSuper);
|
||||||
final Super sup = new Super(className, superClass);
|
final Super sup = new Super(className, superClass);
|
||||||
superList.add(sup);
|
superList.add(sup);
|
||||||
}
|
}
|
||||||
return superList.toArray(new Super[superList.size()]);
|
return superList.toArray(new Super[superList.size()]);
|
||||||
@@ -183,8 +141,8 @@ public class XMLHookParser extends HookParser {
|
|||||||
if (node.getNodeType() != Node.ELEMENT_NODE) {
|
if (node.getNodeType() != Node.ELEMENT_NODE) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final Element getterRoot = (Element) node;
|
final Element getterRoot = (Element) node;
|
||||||
final NodeList getters = getterRoot.getElementsByTagName("add");
|
final NodeList getters = getterRoot.getElementsByTagName("add");
|
||||||
if (getters.getLength() == 0) {
|
if (getters.getLength() == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -208,9 +166,9 @@ public class XMLHookParser extends HookParser {
|
|||||||
"accessor", addGetter));
|
"accessor", addGetter));
|
||||||
final String into = isSet("into", addGetter) ? getValue("into",
|
final String into = isSet("into", addGetter) ? getValue("into",
|
||||||
addGetter) : className;
|
addGetter) : className;
|
||||||
final long multiplier = isSet("multiplier", addGetter) ? Long.parseLong(getValue("multiplier", addGetter)) : 0L;
|
final long multiplier = isSet("multiplier", addGetter) ? Long.parseLong(getValue("multiplier", addGetter)) : 0L;
|
||||||
final String fieldName = getValue("field", addGetter);
|
final String fieldName = getValue("field", addGetter);
|
||||||
final String fieldDesc = isSet("descfield", addGetter) ? getValue("descfield", addGetter) : null;
|
final String fieldDesc = isSet("descfield", addGetter) ? getValue("descfield", addGetter) : null;
|
||||||
final String methodName = getValue("methodname", addGetter);
|
final String methodName = getValue("methodname", addGetter);
|
||||||
boolean staticMethod = isSet("methstatic", addGetter) ? (getValue(
|
boolean staticMethod = isSet("methstatic", addGetter) ? (getValue(
|
||||||
"methstatic", addGetter).equals("true")) : false;
|
"methstatic", addGetter).equals("true")) : false;
|
||||||
@@ -258,8 +216,8 @@ public class XMLHookParser extends HookParser {
|
|||||||
if (node.getNodeType() != Node.ELEMENT_NODE) {
|
if (node.getNodeType() != Node.ELEMENT_NODE) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final Element setterRoot = (Element) node;
|
final Element setterRoot = (Element) node;
|
||||||
final NodeList setters = setterRoot.getElementsByTagName("add");
|
final NodeList setters = setterRoot.getElementsByTagName("add");
|
||||||
if (setters.getLength() == 0) {
|
if (setters.getLength() == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -283,8 +241,8 @@ public class XMLHookParser extends HookParser {
|
|||||||
"accessor", addSetter));
|
"accessor", addSetter));
|
||||||
final String into = isSet("into", addSetter) ? getValue("into",
|
final String into = isSet("into", addSetter) ? getValue("into",
|
||||||
addSetter) : className;
|
addSetter) : className;
|
||||||
final String fieldName = getValue("field", addSetter);
|
final String fieldName = getValue("field", addSetter);
|
||||||
final String fieldDesc = isSet("descfield", addSetter) ? getValue("descfield", addSetter) : null;
|
final String fieldDesc = isSet("descfield", addSetter) ? getValue("descfield", addSetter) : null;
|
||||||
final String methodName = getValue("methodname", addSetter);
|
final String methodName = getValue("methodname", addSetter);
|
||||||
boolean staticMethod = isSet("methstatic", addSetter) ? (getValue(
|
boolean staticMethod = isSet("methstatic", addSetter) ? (getValue(
|
||||||
"methstatic", addSetter).equals("true")) : false;
|
"methstatic", addSetter).equals("true")) : false;
|
||||||
@@ -331,8 +289,8 @@ public class XMLHookParser extends HookParser {
|
|||||||
if (node.getNodeType() != Node.ELEMENT_NODE) {
|
if (node.getNodeType() != Node.ELEMENT_NODE) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final Element invokerRoot = (Element) node;
|
final Element invokerRoot = (Element) node;
|
||||||
final NodeList invokers = invokerRoot.getElementsByTagName("add");
|
final NodeList invokers = invokerRoot.getElementsByTagName("add");
|
||||||
if (invokers.getLength() == 0) {
|
if (invokers.getLength() == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -356,15 +314,15 @@ public class XMLHookParser extends HookParser {
|
|||||||
"accessor", addInvoker));
|
"accessor", addInvoker));
|
||||||
final String into = isSet("into", addInvoker) ? getValue("into",
|
final String into = isSet("into", addInvoker) ? getValue("into",
|
||||||
addInvoker) : className;
|
addInvoker) : className;
|
||||||
final String methodName = getValue("methodname", addInvoker);
|
final String methodName = getValue("methodname", addInvoker);
|
||||||
final String invMethodName = getValue("invokemethod", addInvoker);
|
final String invMethodName = getValue("invokemethod", addInvoker);
|
||||||
final String argsDesc = getValue("argsdesc", addInvoker);
|
final String argsDesc = getValue("argsdesc", addInvoker);
|
||||||
String returnDesc = isSet("desc", addInvoker) ? resolveDesc(getValue(
|
String returnDesc = isSet("desc", addInvoker) ? resolveDesc(getValue(
|
||||||
"desc", addInvoker)) : null;
|
"desc", addInvoker)) : null;
|
||||||
|
|
||||||
final boolean isInterface = isSet("interface", addInvoker) ? Boolean.parseBoolean(getValue("interface", addInvoker)) : false;
|
final boolean isInterface = isSet("interface", addInvoker) ? Boolean.parseBoolean(getValue("interface", addInvoker)) : false;
|
||||||
final String instanceCast = isSet("instancecast", addInvoker) ? getValue("instancecast", addInvoker) : null;
|
final String instanceCast = isSet("instancecast", addInvoker) ? getValue("instancecast", addInvoker) : null;
|
||||||
final String checkCastArgsDesc = isSet("castargs", addInvoker) ? getValue("castargs", addInvoker) : null;
|
final String checkCastArgsDesc = isSet("castargs", addInvoker) ? getValue("castargs", addInvoker) : null;
|
||||||
|
|
||||||
final Invoker invoker = new Invoker(into, className, invMethodName,
|
final Invoker invoker = new Invoker(into, className, invMethodName,
|
||||||
argsDesc, returnDesc, methodName, isInterface, instanceCast, checkCastArgsDesc);
|
argsDesc, returnDesc, methodName, isInterface, instanceCast, checkCastArgsDesc);
|
||||||
@@ -393,7 +351,7 @@ public class XMLHookParser extends HookParser {
|
|||||||
if (node.getNodeType() != Node.ELEMENT_NODE) {
|
if (node.getNodeType() != Node.ELEMENT_NODE) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final Element constantRoot = (Element) node;
|
final Element constantRoot = (Element) node;
|
||||||
final NodeList constantsList = constantRoot.getElementsByTagName("add");
|
final NodeList constantsList = constantRoot.getElementsByTagName("add");
|
||||||
if (constantsList.getLength() == 0) {
|
if (constantsList.getLength() == 0) {
|
||||||
// return empty hashmap
|
// return empty hashmap
|
||||||
@@ -405,8 +363,8 @@ public class XMLHookParser extends HookParser {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final Element addConstant = (Element) n;
|
final Element addConstant = (Element) n;
|
||||||
final String key = getValue("key", addConstant);
|
final String key = getValue("key", addConstant);
|
||||||
final String value = getValue("value", addConstant);
|
final String value = getValue("value", addConstant);
|
||||||
constants.put(key, value);
|
constants.put(key, value);
|
||||||
}
|
}
|
||||||
return constants;
|
return constants;
|
||||||
@@ -428,8 +386,8 @@ public class XMLHookParser extends HookParser {
|
|||||||
if (node.getNodeType() != Node.ELEMENT_NODE) {
|
if (node.getNodeType() != Node.ELEMENT_NODE) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final Element callbackRoot = (Element) node;
|
final Element callbackRoot = (Element) node;
|
||||||
final NodeList callbacks = callbackRoot.getElementsByTagName("add");
|
final NodeList callbacks = callbackRoot.getElementsByTagName("add");
|
||||||
if (callbacks.getLength() == 0) {
|
if (callbacks.getLength() == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -453,12 +411,12 @@ public class XMLHookParser extends HookParser {
|
|||||||
"classname", addCallback) : interfaceMap.get(getValue(
|
"classname", addCallback) : interfaceMap.get(getValue(
|
||||||
"accessor", addCallback));
|
"accessor", addCallback));
|
||||||
|
|
||||||
final String methodName = getValue("methodname", addCallback);
|
final String methodName = getValue("methodname", addCallback);
|
||||||
final String callClass = getValue("callclass", addCallback);
|
final String callClass = getValue("callclass", addCallback);
|
||||||
final String callMethod = getValue("callmethod", addCallback);
|
final String callMethod = getValue("callmethod", addCallback);
|
||||||
final String callDesc = getValue("calldesc", addCallback);
|
final String callDesc = getValue("calldesc", addCallback);
|
||||||
final String callArgs = getValue("callargs", addCallback);
|
final String callArgs = getValue("callargs", addCallback);
|
||||||
final String desc = getValue("desc", addCallback);
|
final String desc = getValue("desc", addCallback);
|
||||||
final boolean conditional = isSet("conditional", addCallback);
|
final boolean conditional = isSet("conditional", addCallback);
|
||||||
|
|
||||||
final Callback callback = new Callback(className, methodName, desc,
|
final Callback callback = new Callback(className, methodName, desc,
|
||||||
@@ -468,4 +426,46 @@ public class XMLHookParser extends HookParser {
|
|||||||
return callbackList.toArray(new Callback[callbackList.size()]);
|
return callbackList.toArray(new Callback[callbackList.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) {
|
||||||
|
if (element.getElementsByTagName(tag).item(0) == null) {
|
||||||
|
throw new NullPointerException("MISSING HOOK TAG: The '" + tag + "' xml tag is missing from one of the hooks of type: " + element.getParentNode().getNodeName());
|
||||||
|
}
|
||||||
|
NodeList nodes = element.getElementsByTagName(tag).item(0)
|
||||||
|
.getChildNodes();
|
||||||
|
if (nodes.getLength() == 0 || nodes.item(0) == null) {
|
||||||
|
if (Core.inVerboseMode()) {
|
||||||
|
System.err.println("WARNING: Invalid Hook " + tag + " subnode. Tag is missing or empty?");
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
Node node = (Node) nodes.item(0);
|
||||||
|
return node.getNodeValue();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user