Merge pull request #1 from runelite-extended/master

update
This commit is contained in:
gazivodag
2019-04-18 20:06:30 -04:00
committed by GitHub
11 changed files with 477 additions and 345 deletions

View File

@@ -26,15 +26,16 @@
package net.runelite.client.rs; package net.runelite.client.rs;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.inject.Inject;
import javax.inject.Singleton;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@Singleton @Singleton
class ClientConfigLoader class ClientConfigLoader
{ {

View File

@@ -32,47 +32,12 @@ import com.google.common.reflect.TypeToken;
import com.google.gson.Gson; import com.google.gson.Gson;
import io.sigpipe.jbsdiff.InvalidHeaderException; import io.sigpipe.jbsdiff.InvalidHeaderException;
import io.sigpipe.jbsdiff.Patch; import io.sigpipe.jbsdiff.Patch;
import java.applet.Applet;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Field;
import java.net.URL;
import java.net.URLClassLoader;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.jar.Attributes;
import java.util.jar.JarEntry;
import java.util.jar.JarInputStream;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
import java.util.logging.Logger;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import javassist.ClassPool; import javassist.ClassPool;
import javassist.NotFoundException; import javassist.NotFoundException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import static net.runelite.client.rs.ClientUpdateCheckMode.AUTO;
import static net.runelite.client.rs.ClientUpdateCheckMode.NONE;
import static net.runelite.client.rs.ClientUpdateCheckMode.VANILLA;
import net.runelite.client.RuneLite; import net.runelite.client.RuneLite;
import net.runelite.client.rs.bytecode.ByteCodeUtils;
import net.runelite.client.rs.bytecode.ByteCodePatcher; import net.runelite.client.rs.bytecode.ByteCodePatcher;
import net.runelite.client.rs.bytecode.ByteCodeUtils;
import net.runelite.client.rs.bytecode.Hooks; import net.runelite.client.rs.bytecode.Hooks;
import net.runelite.http.api.RuneLiteAPI; import net.runelite.http.api.RuneLiteAPI;
import okhttp3.Request; import okhttp3.Request;
@@ -80,6 +45,28 @@ import okhttp3.Response;
import org.apache.commons.compress.compressors.CompressorException; import org.apache.commons.compress.compressors.CompressorException;
import org.xeustechnologies.jcl.JarClassLoader; import org.xeustechnologies.jcl.JarClassLoader;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.applet.Applet;
import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.jar.*;
import java.util.logging.Logger;
import static net.runelite.client.rs.ClientUpdateCheckMode.*;
@Slf4j @Slf4j
@Singleton @Singleton
public class ClientLoader public class ClientLoader
@@ -88,6 +75,7 @@ public class ClientLoader
private final ClientConfigLoader clientConfigLoader; private final ClientConfigLoader clientConfigLoader;
private ClientUpdateCheckMode updateCheckMode; private ClientUpdateCheckMode updateCheckMode;
private JarOutputStream target; private JarOutputStream target;
private boolean scrapedHooks = false;
@Inject @Inject
private ClientLoader( private ClientLoader(
@@ -98,15 +86,94 @@ public class ClientLoader
this.clientConfigLoader = clientConfigLoader; this.clientConfigLoader = clientConfigLoader;
} }
public Applet load() private static Certificate[] getJagexCertificateChain() throws CertificateException
{
if (updateCheckMode == NONE)
{ {
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
Collection<? extends Certificate> certificates = certificateFactory.generateCertificates(ClientLoader.class.getResourceAsStream("jagex.crt"));
return certificates.toArray(new Certificate[certificates.size()]);
}
public static String initVanillaInjected(String jarFile) {
List<String> protectedMethods = new ArrayList<>();
String clientInstance = "";
JarClassLoader jcl = new JarClassLoader();
try {
ClassPool classPool = new ClassPool(true);
classPool.appendClassPath(RuneLite.RUNELITE_DIR + "/injectedClient-" + RuneLiteAPI.getVersion() + "-.jar");
} catch (NotFoundException e) {
e.printStackTrace();
}
try {
jcl.add(new FileInputStream(jarFile));
try (JarInputStream in = new JarInputStream(new BufferedInputStream(new FileInputStream(jarFile)))) {
JarEntry entry;
while ((entry = in.getNextJarEntry()) != null) {
if (entry.getName().endsWith(".class")) {
File temp = new File(jarFile);
ClassLoader cl = ClassLoader.getSystemClassLoader();
try {
URLClassLoader child = new URLClassLoader(
new URL[]{temp.toURI().toURL()},
cl
);
try {
Class classToLoad = Class.forName(entry.getName().replace(".class", ""), false, child);
JarClassLoader jcl2 = new JarClassLoader();
try {
jcl2.add(new FileInputStream(ByteCodeUtils.injectedClientFile));
Field[] fields = classToLoad.getDeclaredFields();
Method[] methods = classToLoad.getMethods();
for (Field f : fields) {
try {
if (f.getType().getName() == "client") {
ByteCodePatcher.hooks.clientInstance = classToLoad.getName() + "." + f.getName();
System.out.println("[RuneLit] Found client instance at " + classToLoad.getName() + "." + f.getName());
return classToLoad.getName() + "." + f.getName();
}
} catch (Exception e) {
e.printStackTrace();
}
}
for (Method m : methods) {
if (m.getName().contains("protect")) {
protectedMethods.add(classToLoad.getName()+":"+m.getName());
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
System.out.println("Class not found: " + entry.getName());
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
String[] hooksProtectedMethods = new String[protectedMethods.size()];
int i = 0;
for (String s : protectedMethods) {
hooksProtectedMethods[i] = s;
i++;
}
ByteCodePatcher.hooks.protectedMethods = hooksProtectedMethods;
return clientInstance;
}
public Applet load() {
if (updateCheckMode == NONE) {
return null; return null;
} }
try try {
{
File injectedClientFile = ByteCodeUtils.injectedClientFile; File injectedClientFile = ByteCodeUtils.injectedClientFile;
File hijackedClientFile = ByteCodeUtils.hijackedClientFile; File hijackedClientFile = ByteCodeUtils.hijackedClientFile;
Manifest manifest = new Manifest(); Manifest manifest = new Manifest();
@@ -124,28 +191,23 @@ public class ClientLoader
.url(url) .url(url)
.build(); .build();
try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) {
{
JarInputStream jis; JarInputStream jis;
jis = new JarInputStream(response.body().byteStream()); jis = new JarInputStream(response.body().byteStream());
byte[] tmp = new byte[4096]; byte[] tmp = new byte[4096];
ByteArrayOutputStream buffer = new ByteArrayOutputStream(756 * 1024); ByteArrayOutputStream buffer = new ByteArrayOutputStream(756 * 1024);
for (; ; ) for (; ; ) {
{
JarEntry metadata = jis.getNextJarEntry(); JarEntry metadata = jis.getNextJarEntry();
if (metadata == null) if (metadata == null) {
{
break; break;
} }
buffer.reset(); buffer.reset();
for (; ; ) for (; ; ) {
{
int n = jis.read(tmp); int n = jis.read(tmp);
if (n <= -1) if (n <= -1) {
{
break; break;
} }
buffer.write(tmp, 0, n); buffer.write(tmp, 0, n);
@@ -156,28 +218,22 @@ public class ClientLoader
} }
} }
if (updateCheckMode == AUTO) if (updateCheckMode == AUTO) {
{
Map<String, String> hashes; Map<String, String> hashes;
try (InputStream is = ClientLoader.class.getResourceAsStream("/patch/hashes.json")) try (InputStream is = ClientLoader.class.getResourceAsStream("/patch/hashes.json")) {
{ hashes = new Gson().fromJson(new InputStreamReader(is), new TypeToken<HashMap<String, String>>() {
hashes = new Gson().fromJson(new InputStreamReader(is), new TypeToken<HashMap<String, String>>()
{
}.getType()); }.getType());
} }
for (Map.Entry<String, String> file : hashes.entrySet()) for (Map.Entry<String, String> file : hashes.entrySet()) {
{
byte[] bytes = zipFile.get(file.getKey()); byte[] bytes = zipFile.get(file.getKey());
String ourHash = null; String ourHash = null;
if (bytes != null) if (bytes != null) {
{
ourHash = Hashing.sha512().hashBytes(bytes).toString(); ourHash = Hashing.sha512().hashBytes(bytes).toString();
} }
if (!file.getValue().equals(ourHash)) if (!file.getValue().equals(ourHash)) {
{
if (hijackedClientFile.exists()) { if (hijackedClientFile.exists()) {
Logger.getAnonymousLogger().warning("[RuneLit] Hash checking / Client patching skipped due to hijacked client."); Logger.getAnonymousLogger().warning("[RuneLit] Hash checking / Client patching skipped due to hijacked client.");
updateCheckMode = VANILLA; updateCheckMode = VANILLA;
@@ -192,18 +248,14 @@ public class ClientLoader
} }
} }
if (updateCheckMode == AUTO) if (updateCheckMode == AUTO) {
{
ByteArrayOutputStream patchOs = new ByteArrayOutputStream(756 * 1024); ByteArrayOutputStream patchOs = new ByteArrayOutputStream(756 * 1024);
int patchCount = 0; int patchCount = 0;
for (Map.Entry<String, byte[]> file : zipFile.entrySet()) for (Map.Entry<String, byte[]> file : zipFile.entrySet()) {
{
byte[] bytes; byte[] bytes;
try (InputStream is = ClientLoader.class.getResourceAsStream("/patch/" + file.getKey() + ".bs")) try (InputStream is = ClientLoader.class.getResourceAsStream("/patch/" + file.getKey() + ".bs")) {
{ if (is == null) {
if (is == null)
{
continue; continue;
} }
@@ -230,12 +282,13 @@ public class ClientLoader
ByteCodePatcher.classPool.appendClassPath(RuneLite.RUNELITE_DIR + "/injectedClient-" + RuneLiteAPI.getVersion() + "-.jar"); ByteCodePatcher.classPool.appendClassPath(RuneLite.RUNELITE_DIR + "/injectedClient-" + RuneLiteAPI.getVersion() + "-.jar");
Gson gson = new Gson(); Gson gson = new Gson();
Hooks hooks = gson.fromJson(new BufferedReader(new FileReader(hooksFile)), Hooks.class); Hooks hooks = gson.fromJson(new BufferedReader(new FileReader(hooksFile)), Hooks.class);
if (hooks.clientInstance.equals("") || if (hooks.clientInstance.equals("") ||
hooks.projectileClass.equals("") || hooks.projectileClass.equals("") ||
hooks.actorClass.equals("")) { hooks.actorClass.equals("") ||
hooks.clientInstance.equals("") ||
hooks.playerClass.equals("")) {
System.out.println("[RuneLit] Bad hooks, re-scraping."); System.out.println("[RuneLit] Bad hooks, re-scraping.");
ByteCodePatcher.clientInstance = getClientInstance(ByteCodeUtils.injectedClientFile.getPath()); ByteCodePatcher.clientInstance = ByteCodeUtils.injectedClientFile.getPath();
ByteCodePatcher.findHooks(injectedClientFile.getPath()); ByteCodePatcher.findHooks(injectedClientFile.getPath());
} else { } else {
ByteCodePatcher.clientInstance = hooks.clientInstance; ByteCodePatcher.clientInstance = hooks.clientInstance;
@@ -245,7 +298,7 @@ public class ClientLoader
} else { } else {
System.out.println("[RuneLit] Hooks file not found, scraping hooks."); System.out.println("[RuneLit] Hooks file not found, scraping hooks.");
ByteCodePatcher.clientInstance = getClientInstance(ByteCodeUtils.injectedClientFile.getPath()); ByteCodePatcher.clientInstance = initVanillaInjected(ByteCodeUtils.injectedClientFile.getPath());
ByteCodePatcher.findHooks(injectedClientFile.getPath()); ByteCodePatcher.findHooks(injectedClientFile.getPath());
} }
@@ -274,15 +327,12 @@ public class ClientLoader
String initialClass = config.getInitialClass(); String initialClass = config.getInitialClass();
ClassLoader rsClassLoader = new ClassLoader(ClientLoader.class.getClassLoader()) ClassLoader rsClassLoader = new ClassLoader(ClientLoader.class.getClassLoader()) {
{
@Override @Override
protected Class<?> findClass(String name) throws ClassNotFoundException protected Class<?> findClass(String name) throws ClassNotFoundException {
{
String path = name.replace('.', '/').concat(".class"); String path = name.replace('.', '/').concat(".class");
byte[] data = zipFile2.get(path); byte[] data = zipFile2.get(path);
if (data == null) if (data == null) {
{
throw new ClassNotFoundException(name); throw new ClassNotFoundException(name);
} }
@@ -295,12 +345,9 @@ public class ClientLoader
Applet rs = (Applet) clientClass.newInstance(); Applet rs = (Applet) clientClass.newInstance();
rs.setStub(new RSAppletStub(config)); rs.setStub(new RSAppletStub(config));
return rs; return rs;
} } catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException
catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException | CompressorException | InvalidHeaderException | CertificateException | SecurityException e) {
| CompressorException | InvalidHeaderException | CertificateException | SecurityException e) if (e instanceof ClassNotFoundException) {
{
if (e instanceof ClassNotFoundException)
{
log.error("Unable to load client - class not found. This means you" log.error("Unable to load client - class not found. This means you"
+ " are not running RuneLite with Maven as the client patch" + " are not running RuneLite with Maven as the client patch"
+ " is not in your classpath."); + " is not in your classpath.");
@@ -326,70 +373,4 @@ public class ClientLoader
in.close(); in.close();
} }
} }
private static Certificate[] getJagexCertificateChain() throws CertificateException
{
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
Collection<? extends Certificate> certificates = certificateFactory.generateCertificates(ClientLoader.class.getResourceAsStream("jagex.crt"));
return certificates.toArray(new Certificate[certificates.size()]);
}
public static String getClientInstance(String jarFile) {
JarClassLoader jcl = new JarClassLoader();
try {
ClassPool classPool = new ClassPool(true);
classPool.appendClassPath(RuneLite.RUNELITE_DIR+"/injectedClient-"+ RuneLiteAPI.getVersion() +"-.jar");
} catch (NotFoundException e) {
e.printStackTrace();
}
try {
jcl.add(new FileInputStream(jarFile));
try (JarInputStream in = new JarInputStream(new BufferedInputStream(new FileInputStream(jarFile)))) {
JarEntry entry;
while ((entry = in.getNextJarEntry()) != null) {
if (entry.getName().endsWith(".class")) {
File temp = new File(jarFile);
ClassLoader cl = ClassLoader.getSystemClassLoader();
try {
URLClassLoader child = new URLClassLoader(
new URL[] {temp.toURI().toURL()},
cl
);
try {
Class classToLoad = Class.forName(entry.getName().replace(".class", ""), false, child);
JarClassLoader jcl2 = new JarClassLoader();
try {
jcl2.add(new FileInputStream(ByteCodeUtils.injectedClientFile));
Field[] fields = classToLoad.getDeclaredFields();
for (Field f : fields) {
try {
if (f.getType().getName()=="client") {
ByteCodePatcher.hooks.clientInstance = classToLoad.getName()+"."+f.getName();
System.out.println("[RuneLit] Found client instance at "+classToLoad.getName()+"."+f.getName());
return classToLoad.getName()+"."+f.getName();
}
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
System.out.println("Class not found: "+entry.getName());
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
} }

View File

@@ -25,11 +25,12 @@
*/ */
package net.runelite.client.rs; package net.runelite.client.rs;
import lombok.RequiredArgsConstructor;
import java.applet.AppletContext; import java.applet.AppletContext;
import java.applet.AppletStub; import java.applet.AppletStub;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor @RequiredArgsConstructor
class RSAppletStub implements AppletStub class RSAppletStub implements AppletStub

View File

@@ -25,9 +25,10 @@
*/ */
package net.runelite.client.rs; package net.runelite.client.rs;
import lombok.Getter;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import lombok.Getter;
@Getter @Getter
class RSConfig class RSConfig

View File

@@ -7,22 +7,12 @@ import javassist.CtClass;
import javassist.NotFoundException; import javassist.NotFoundException;
import net.runelite.client.RuneLite; import net.runelite.client.RuneLite;
import net.runelite.client.rs.ClientLoader; import net.runelite.client.rs.ClientLoader;
import net.runelite.client.rs.bytecode.transformers.ActorTransform; import net.runelite.client.rs.bytecode.transformers.*;
import net.runelite.client.rs.bytecode.transformers.ProjectileTransform;
import net.runelite.http.api.RuneLiteAPI; import net.runelite.http.api.RuneLiteAPI;
import org.xeustechnologies.jcl.JarClassLoader; import org.xeustechnologies.jcl.JarClassLoader;
import java.io.BufferedInputStream; import java.io.*;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import java.util.ArrayList; import java.util.ArrayList;
@@ -50,6 +40,10 @@ public class ByteCodePatcher {
transformActor(actorClass); transformActor(actorClass);
Class projectileClass = Class.forName(hooks.projectileClass, false, child); Class projectileClass = Class.forName(hooks.projectileClass, false, child);
transformProjectile(projectileClass); transformProjectile(projectileClass);
Class playerClass = Class.forName(hooks.playerClass, false, child);
transformPlayer(playerClass);
Class clientClass = Class.forName(hooks.clientClass, false, child);
transformClient(clientClass);
ByteCodeUtils.updateHijackedJar(); ByteCodeUtils.updateHijackedJar();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@@ -103,6 +97,8 @@ public class ByteCodePatcher {
Class classToLoad = Class.forName(entry.getName().replace(".class", ""), false, child); Class classToLoad = Class.forName(entry.getName().replace(".class", ""), false, child);
checkActor(classToLoad); checkActor(classToLoad);
checkProjectile(classToLoad); checkProjectile(classToLoad);
checkPlayer(classToLoad);
checkClient(classToLoad);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@@ -115,10 +111,10 @@ public class ByteCodePatcher {
public static void checkActor(Class current) { public static void checkActor(Class current) {
try { try {
Method method = current.getDeclaredMethod("setCombatInfo", new Class[] { int.class, int.class, int.class, int.class, int.class, int.class }); Method method = current.getDeclaredMethod("setCombatInfo", int.class, int.class, int.class, int.class, int.class, int.class);
if (method != null) { if (method != null) {
hooks.actorClass = current.getName(); hooks.actorClass = current.getName();
System.out.println("[RuneLit] Transforming Actor at class: "+current.getName()); System.out.println("[Z-lyte] Transforming Actor at class: " + current.getName());
ActorTransform at = new ActorTransform(); ActorTransform at = new ActorTransform();
at.modify(current); at.modify(current);
} }
@@ -129,15 +125,15 @@ public class ByteCodePatcher {
} }
} }
public static void transformActor(Class current) { public static void transformActor(Class actor) {
System.out.println("[RuneLit] Transforming Actor at class: "+current.getName()); System.out.println("[RuneLit] Transforming Actor at class: " + actor.getName());
ActorTransform at = new ActorTransform(); ActorTransform at = new ActorTransform();
at.modify(current); at.modify(actor);
} }
public static void checkProjectile(Class current) { public static void checkProjectile(Class current) {
try { try {
Method method = current.getDeclaredMethod("projectileMoved", new Class[] { int.class, int.class, int.class, int.class}); Method method = current.getDeclaredMethod("projectileMoved", int.class, int.class, int.class, int.class);
if (method != null) { if (method != null) {
hooks.projectileClass = current.getName(); hooks.projectileClass = current.getName();
System.out.println("[RuneLit] Transforming Projectile at class: " + current.getName()); System.out.println("[RuneLit] Transforming Projectile at class: " + current.getName());
@@ -151,10 +147,52 @@ public class ByteCodePatcher {
} }
} }
public static void transformProjectile(Class current) { public static void transformProjectile(Class projectile) {
System.out.println("[RuneLit] Transforming Projectile at class: "+current.getName()); System.out.println("[RuneLit] Transforming Projectile at class: " + projectile.getName());
ProjectileTransform pt = new ProjectileTransform(); ProjectileTransform pt = new ProjectileTransform();
pt.modify(current); pt.modify(projectile);
} }
public static void checkPlayer(Class current) {
try {
Method method = current.getDeclaredMethod("getSkullIcon");
if (method != null) {
hooks.playerClass = current.getName();
System.out.println("[RuneLit] Transforming Player at class: " + current.getName());
PlayerTransform pt = new PlayerTransform();
pt.modify(current);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void checkClient(Class current) {
try {
Method method = current.getDeclaredMethod("getProjectiles");
if (method != null) {
hooks.clientInstance = current.getName();
System.out.println("[RuneLit] Transforming Projectile at class: " + current.getName());
ClientTransform ct = new ClientTransform();
ct.modify(current);
}
} catch (NoSuchMethodException e) {
//e.printStackTrace();
} catch (NoClassDefFoundError e) {
//e.printStackTrace();
}
}
public static void transformClient(Class client) {
System.out.println("[RuneLit] Transforming Client at class: " + client.getName());
ClientTransform ct = new ClientTransform();
ct.modify(client);
}
public static void transformPlayer(Class player) {
System.out.println("[RuneLit] Transforming Player at class: " + player.getName());
PlayerTransform pt = new PlayerTransform();
pt.modify(player);
}
} }

View File

@@ -4,19 +4,11 @@ import javassist.CtClass;
import net.runelite.client.RuneLite; import net.runelite.client.RuneLite;
import net.runelite.http.api.RuneLiteAPI; import net.runelite.http.api.RuneLiteAPI;
import java.io.ByteArrayOutputStream; import java.io.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.List; import java.util.List;
import java.util.jar.Attributes; import java.util.jar.*;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;

View File

@@ -1,10 +1,16 @@
package net.runelite.client.rs.bytecode; package net.runelite.client.rs.bytecode;
import java.lang.reflect.Method;
import java.util.List;
public class Hooks { public class Hooks {
public String clientInstance = ""; public String clientInstance = "";
public String actorClass = ""; public String actorClass = "";
public String projectileClass = ""; public String projectileClass = "";
public String playerClass = "";
public String clientClass = "client"; //Always named client
public String[] protectedMethods;
public Hooks() { public Hooks() {
} }

View File

@@ -1,17 +1,10 @@
package net.runelite.client.rs.bytecode.transformers; package net.runelite.client.rs.bytecode.transformers;
import javassist.CannotCompileException;
import javassist.CtClass; import javassist.CtClass;
import javassist.CtMethod; import javassist.CtMethod;
import javassist.CtNewMethod; import javassist.CtNewMethod;
import javassist.NotFoundException; import javassist.NotFoundException;
import net.runelite.client.rs.bytecode.ByteCodePatcher; import net.runelite.client.rs.bytecode.ByteCodePatcher;
import net.runelite.client.rs.bytecode.ByteCodeUtils;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
public class ActorTransform { public class ActorTransform {
public CtClass ct = null; public CtClass ct = null;

View File

@@ -0,0 +1,56 @@
package net.runelite.client.rs.bytecode.transformers;
import javassist.CtClass;
import javassist.CtMethod;
import javassist.CtNewMethod;
import javassist.NotFoundException;
import javassist.bytecode.AnnotationsAttribute;
import javassist.bytecode.ClassFile;
import javassist.bytecode.ConstPool;
import net.runelite.client.rs.bytecode.ByteCodePatcher;
public class ClientTransform {
public CtClass ct = null;
public void modify(Class client) {
try {
ct = ByteCodePatcher.classPool.get(client.getName());
transformGetProjectiles();
ByteCodePatcher.modifiedClasses.add(ct);
} catch (NotFoundException e) {
e.printStackTrace();
}
}
public void transformGetProjectiles() {
CtMethod getProjectiles;
try {
CtMethod protectedAnimation = ct.getDeclaredMethod("1protect$getProjectilesDeque");
ct.removeMethod(protectedAnimation);
protectedAnimation.setName("getProjectilesDeque");
ct.addMethod(protectedAnimation);
getProjectiles = ct.getDeclaredMethod("getProjectiles");
ct.removeMethod(getProjectiles);
getProjectiles = CtNewMethod.make("public java.util.List getProjectiles() { " +
" java.util.ArrayList localArrayList = new java.util.ArrayList();" +
" net.runelite.rs.api.RSDeque localRSDeque = getProjectilesDeque();" +
" net.runelite.rs.api.RSNode localRSNode = localRSDeque.getHead();" +
" for (net.runelite.api.Node localNode = localRSNode.getNext(); localNode != localRSNode; localNode = localNode.getNext()) {" +
" net.runelite.api.Projectile localProjectile = (net.runelite.api.Projectile)localNode;" +
" localArrayList.add(localProjectile); }" +
" return localArrayList; }", ct);
ct.addMethod(getProjectiles);
ClassFile classFile = ct.getClassFile();
ConstPool constPool = classFile.getConstPool();
AnnotationsAttribute attr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
javassist.bytecode.annotation.Annotation annotation = new javassist.bytecode.annotation.Annotation("Override", constPool);
attr.setAnnotation(annotation);
getProjectiles.getMethodInfo().addAttribute(attr);
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,64 @@
package net.runelite.client.rs.bytecode.transformers;
import javassist.CtClass;
import javassist.CtMethod;
import javassist.CtNewMethod;
import net.runelite.client.rs.bytecode.ByteCodePatcher;
public class PlayerTransform {
public CtClass ct = null;
public void modify(Class player) {
try {
ct = ByteCodePatcher.classPool.get(player.getName());
transformProtectedGetSkullIcon();
transformGetSkullIcon();
ByteCodePatcher.modifiedClasses.add(ct);
} catch (Exception e) {
e.printStackTrace();
}
}
public void transformProtectedGetSkullIcon() {
CtMethod protectedGetSkullIcon;
try {
protectedGetSkullIcon = ct.getDeclaredMethod("1protect$getRsSkullIcon");
ct.removeMethod(protectedGetSkullIcon);
protectedGetSkullIcon.setName("getRsSkullIcon");
ct.addMethod(protectedGetSkullIcon);
} catch (Exception e) {
e.printStackTrace();
}
}
public void transformGetSkullIcon() {
CtMethod getSkullIcon;
try {
String SkullIcon = "net.runelite.api.SkullIcon";
getSkullIcon = ct.getDeclaredMethod("getSkullIcon");
ct.removeMethod(getSkullIcon);
getSkullIcon = CtNewMethod.make("public " + SkullIcon + " getSkullIcon() {" +
" switch (this.getRsSkullIcon()) {" +
" case 0: {" +
" return " + SkullIcon + ".SKULL; }" +
" case 1: {" +
" return " + SkullIcon + ".SKULL_FIGHT_PIT; }" +
" case 8: {" +
" return " + SkullIcon + ".DEAD_MAN_FIVE; }" +
" case 9: {" +
" return " + SkullIcon + ".DEAD_MAN_FOUR; }" +
" case 10: {" +
" return " + SkullIcon + ".DEAD_MAN_THREE; }" +
" case 11: {" +
" return " + SkullIcon + ".DEAD_MAN_TWO; }" +
" case 12: {" +
" return " + SkullIcon + ".DEAD_MAN_ONE; } }" +
" return null; }", ct);
ct.addMethod(getSkullIcon);
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@@ -4,7 +4,6 @@ import javassist.CtClass;
import javassist.CtMethod; import javassist.CtMethod;
import javassist.CtNewMethod; import javassist.CtNewMethod;
import net.runelite.client.rs.bytecode.ByteCodePatcher; import net.runelite.client.rs.bytecode.ByteCodePatcher;
import net.runelite.client.rs.bytecode.ByteCodeUtils;
public class ProjectileTransform { public class ProjectileTransform {
public CtClass ct = null; public CtClass ct = null;