Rollback
This commit is contained in:
@@ -26,15 +26,14 @@
|
|||||||
package net.runelite.client.rs;
|
package net.runelite.client.rs;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import okhttp3.OkHttpClient;
|
|
||||||
import okhttp3.Request;
|
|
||||||
import okhttp3.Response;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.Response;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class ClientConfigLoader
|
class ClientConfigLoader
|
||||||
@@ -52,13 +51,13 @@ class ClientConfigLoader
|
|||||||
RSConfig fetch() throws IOException
|
RSConfig fetch() throws IOException
|
||||||
{
|
{
|
||||||
final Request request = new Request.Builder()
|
final Request request = new Request.Builder()
|
||||||
.url(CONFIG_URL)
|
.url(CONFIG_URL)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
final RSConfig config = new RSConfig();
|
final RSConfig config = new RSConfig();
|
||||||
|
|
||||||
try (final Response response = httpClient.newCall(request).execute(); final BufferedReader in = new BufferedReader(
|
try (final Response response = httpClient.newCall(request).execute(); final BufferedReader in = new BufferedReader(
|
||||||
new InputStreamReader(response.body().byteStream())))
|
new InputStreamReader(response.body().byteStream())))
|
||||||
{
|
{
|
||||||
String str;
|
String str;
|
||||||
|
|
||||||
|
|||||||
@@ -32,24 +32,18 @@ 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 javassist.ClassPool;
|
|
||||||
import javassist.NotFoundException;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import net.runelite.client.RuneLite;
|
|
||||||
import net.runelite.client.rs.bytecode.ByteCodePatcher;
|
|
||||||
import net.runelite.client.rs.bytecode.ByteCodeUtils;
|
|
||||||
import net.runelite.client.rs.bytecode.Hooks;
|
|
||||||
import net.runelite.http.api.RuneLiteAPI;
|
|
||||||
import okhttp3.Request;
|
|
||||||
import okhttp3.Response;
|
|
||||||
import org.apache.commons.compress.compressors.CompressorException;
|
|
||||||
import org.xeustechnologies.jcl.JarClassLoader;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Named;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
import java.applet.Applet;
|
import java.applet.Applet;
|
||||||
import java.io.*;
|
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.lang.reflect.Field;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
@@ -59,38 +53,293 @@ import java.security.cert.CertificateFactory;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.jar.*;
|
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 java.util.logging.Logger;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import static net.runelite.client.rs.ClientUpdateCheckMode.*;
|
import javassist.ClassPool;
|
||||||
|
import javassist.NotFoundException;
|
||||||
|
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.rs.bytecode.ByteCodeUtils;
|
||||||
|
import net.runelite.client.rs.bytecode.ByteCodePatcher;
|
||||||
|
import net.runelite.client.rs.bytecode.Hooks;
|
||||||
|
import net.runelite.http.api.RuneLiteAPI;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.Response;
|
||||||
|
import org.apache.commons.compress.compressors.CompressorException;
|
||||||
|
import org.xeustechnologies.jcl.JarClassLoader;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Singleton
|
@Singleton
|
||||||
public class ClientLoader {
|
public class ClientLoader
|
||||||
public static File hooksFile = new File(RuneLite.RUNELITE_DIR + "/hooks-" + RuneLiteAPI.getVersion() + "-.json");
|
{
|
||||||
private final ClientConfigLoader clientConfigLoader;
|
public static File hooksFile = new File(RuneLite.RUNELITE_DIR+"/hooks-"+ RuneLiteAPI.getVersion() +"-.json");
|
||||||
private ClientUpdateCheckMode updateCheckMode;
|
private final ClientConfigLoader clientConfigLoader;
|
||||||
private JarOutputStream target;
|
private ClientUpdateCheckMode updateCheckMode;
|
||||||
|
private JarOutputStream target;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ClientLoader(
|
private ClientLoader(
|
||||||
@Named("updateCheckMode") final ClientUpdateCheckMode updateCheckMode,
|
@Named("updateCheckMode") final ClientUpdateCheckMode updateCheckMode,
|
||||||
final ClientConfigLoader clientConfigLoader) {
|
final ClientConfigLoader clientConfigLoader)
|
||||||
this.updateCheckMode = updateCheckMode;
|
{
|
||||||
this.clientConfigLoader = clientConfigLoader;
|
this.updateCheckMode = updateCheckMode;
|
||||||
}
|
this.clientConfigLoader = clientConfigLoader;
|
||||||
|
}
|
||||||
|
|
||||||
private static Certificate[] getJagexCertificateChain() throws CertificateException {
|
public Applet load()
|
||||||
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
|
{
|
||||||
Collection<? extends Certificate> certificates = certificateFactory.generateCertificates(ClientLoader.class.getResourceAsStream("jagex.crt"));
|
if (updateCheckMode == NONE)
|
||||||
return certificates.toArray(new Certificate[certificates.size()]);
|
{
|
||||||
}
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File injectedClientFile = ByteCodeUtils.injectedClientFile;
|
||||||
|
File hijackedClientFile = ByteCodeUtils.hijackedClientFile;
|
||||||
|
Manifest manifest = new Manifest();
|
||||||
|
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
|
||||||
|
target = new JarOutputStream(new FileOutputStream(injectedClientFile), manifest);
|
||||||
|
RSConfig config = clientConfigLoader.fetch();
|
||||||
|
|
||||||
|
Map<String, byte[]> zipFile = new HashMap<>();
|
||||||
|
{
|
||||||
|
Certificate[] jagexCertificateChain = getJagexCertificateChain();
|
||||||
|
String codebase = config.getCodeBase();
|
||||||
|
String initialJar = config.getInitialJar();
|
||||||
|
URL url = new URL(codebase + initialJar);
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute())
|
||||||
|
{
|
||||||
|
JarInputStream jis;
|
||||||
|
|
||||||
|
jis = new JarInputStream(response.body().byteStream());
|
||||||
|
|
||||||
|
byte[] tmp = new byte[4096];
|
||||||
|
ByteArrayOutputStream buffer = new ByteArrayOutputStream(756 * 1024);
|
||||||
|
for (; ; )
|
||||||
|
{
|
||||||
|
JarEntry metadata = jis.getNextJarEntry();
|
||||||
|
if (metadata == null)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer.reset();
|
||||||
|
for (; ; )
|
||||||
|
{
|
||||||
|
int n = jis.read(tmp);
|
||||||
|
if (n <= -1)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
buffer.write(tmp, 0, n);
|
||||||
|
}
|
||||||
|
|
||||||
|
zipFile.put(metadata.getName(), buffer.toByteArray());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (updateCheckMode == AUTO)
|
||||||
|
{
|
||||||
|
Map<String, String> hashes;
|
||||||
|
try (InputStream is = ClientLoader.class.getResourceAsStream("/patch/hashes.json"))
|
||||||
|
{
|
||||||
|
hashes = new Gson().fromJson(new InputStreamReader(is), new TypeToken<HashMap<String, String>>()
|
||||||
|
{
|
||||||
|
}.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Map.Entry<String, String> file : hashes.entrySet())
|
||||||
|
{
|
||||||
|
byte[] bytes = zipFile.get(file.getKey());
|
||||||
|
|
||||||
|
String ourHash = null;
|
||||||
|
if (bytes != null)
|
||||||
|
{
|
||||||
|
ourHash = Hashing.sha512().hashBytes(bytes).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file.getValue().equals(ourHash))
|
||||||
|
{
|
||||||
|
if (hijackedClientFile.exists()) {
|
||||||
|
Logger.getAnonymousLogger().warning("[RuneLit] Hash checking / Client patching skipped due to hijacked client.");
|
||||||
|
updateCheckMode = VANILLA;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
log.info("{} had a hash mismatch; falling back to vanilla. {} != {}", file.getKey(), file.getValue(), ourHash);
|
||||||
|
log.info("Client is outdated!");
|
||||||
|
updateCheckMode = VANILLA;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (updateCheckMode == AUTO)
|
||||||
|
{
|
||||||
|
ByteArrayOutputStream patchOs = new ByteArrayOutputStream(756 * 1024);
|
||||||
|
int patchCount = 0;
|
||||||
|
|
||||||
|
for (Map.Entry<String, byte[]> file : zipFile.entrySet())
|
||||||
|
{
|
||||||
|
byte[] bytes;
|
||||||
|
try (InputStream is = ClientLoader.class.getResourceAsStream("/patch/" + file.getKey() + ".bs"))
|
||||||
|
{
|
||||||
|
if (is == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes = ByteStreams.toByteArray(is);
|
||||||
|
}
|
||||||
|
|
||||||
|
patchOs.reset();
|
||||||
|
Patch.patch(file.getValue(), bytes, patchOs);
|
||||||
|
file.setValue(patchOs.toByteArray());
|
||||||
|
|
||||||
|
++patchCount;
|
||||||
|
|
||||||
|
if (!file.getKey().startsWith("META")) {
|
||||||
|
add(file.getValue(), file.getKey(), target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (target!=null)
|
||||||
|
target.close();
|
||||||
|
|
||||||
|
log.info("Patched {} classes", patchCount);
|
||||||
|
}
|
||||||
|
if (hooksFile.exists()) {
|
||||||
|
ByteCodePatcher.classPool = new ClassPool(true);
|
||||||
|
ByteCodePatcher.classPool.appendClassPath(RuneLite.RUNELITE_DIR+"/injectedClient-"+ RuneLiteAPI.getVersion() +"-.jar");
|
||||||
|
Gson gson = new Gson();
|
||||||
|
Hooks hooks = gson.fromJson(new BufferedReader(new FileReader(hooksFile)), Hooks.class);
|
||||||
|
|
||||||
|
if (hooks.clientInstance.equals("")||
|
||||||
|
hooks.projectileClass.equals("") ||
|
||||||
|
hooks.actorClass.equals("") ||
|
||||||
|
hooks.playerClass.equals("")) {
|
||||||
|
System.out.println("[RuneLit] Bad hooks, re-scraping.");
|
||||||
|
ByteCodePatcher.clientInstance = getClientInstance(ByteCodeUtils.injectedClientFile.getPath());
|
||||||
|
ByteCodePatcher.findHooks(injectedClientFile.getPath());
|
||||||
|
} else {
|
||||||
|
ByteCodePatcher.clientInstance = hooks.clientInstance;
|
||||||
|
ByteCodePatcher.applyHooks(ByteCodeUtils.injectedClientFile, hooks);
|
||||||
|
System.out.println("[RuneLit] Loaded hooks");
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
System.out.println("[RuneLit] Hooks file not found, scraping hooks.");
|
||||||
|
ByteCodePatcher.clientInstance = getClientInstance(ByteCodeUtils.injectedClientFile.getPath());
|
||||||
|
ByteCodePatcher.findHooks(injectedClientFile.getPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, byte[]> zipFile2 = new HashMap<>();
|
||||||
|
JarInputStream jis = new JarInputStream(new FileInputStream(hijackedClientFile));
|
||||||
|
|
||||||
|
byte[] tmp = new byte[4096];
|
||||||
|
ByteArrayOutputStream buffer = new ByteArrayOutputStream(756 * 1024);
|
||||||
|
for (; ; ) {
|
||||||
|
JarEntry metadata = jis.getNextJarEntry();
|
||||||
|
if (metadata == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer.reset();
|
||||||
|
for (; ; ) {
|
||||||
|
int n = jis.read(tmp);
|
||||||
|
if (n <= -1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
buffer.write(tmp, 0, n);
|
||||||
|
}
|
||||||
|
|
||||||
|
zipFile2.put(metadata.getName(), buffer.toByteArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
String initialClass = config.getInitialClass();
|
||||||
|
|
||||||
|
ClassLoader rsClassLoader = new ClassLoader(ClientLoader.class.getClassLoader())
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
protected Class<?> findClass(String name) throws ClassNotFoundException
|
||||||
|
{
|
||||||
|
String path = name.replace('.', '/').concat(".class");
|
||||||
|
byte[] data = zipFile2.get(path);
|
||||||
|
if (data == null)
|
||||||
|
{
|
||||||
|
throw new ClassNotFoundException(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return defineClass(name, data, 0, data.length);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Class<?> clientClass = rsClassLoader.loadClass(initialClass);
|
||||||
|
|
||||||
|
Applet rs = (Applet) clientClass.newInstance();
|
||||||
|
rs.setStub(new RSAppletStub(config));
|
||||||
|
return rs;
|
||||||
|
}
|
||||||
|
catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException
|
||||||
|
| CompressorException | InvalidHeaderException | CertificateException | SecurityException e)
|
||||||
|
{
|
||||||
|
if (e instanceof ClassNotFoundException)
|
||||||
|
{
|
||||||
|
log.error("Unable to load client - class not found. This means you"
|
||||||
|
+ " are not running RuneLite with Maven as the client patch"
|
||||||
|
+ " is not in your classpath.");
|
||||||
|
}
|
||||||
|
|
||||||
|
log.error("Error loading RS!", e);
|
||||||
|
return null;
|
||||||
|
} catch (NotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void add(byte[] bytes, String entryName ,JarOutputStream target) throws IOException {
|
||||||
|
BufferedInputStream in = null;
|
||||||
|
try {
|
||||||
|
JarEntry entry = new JarEntry(entryName);
|
||||||
|
target.putNextEntry(entry);
|
||||||
|
target.write(bytes);
|
||||||
|
target.closeEntry();
|
||||||
|
} finally {
|
||||||
|
if (in != null)
|
||||||
|
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) {
|
public static String getClientInstance(String jarFile) {
|
||||||
JarClassLoader jcl = new JarClassLoader();
|
JarClassLoader jcl = new JarClassLoader();
|
||||||
try {
|
try {
|
||||||
ClassPool classPool = new ClassPool(true);
|
ClassPool classPool = new ClassPool(true);
|
||||||
classPool.appendClassPath(RuneLite.RUNELITE_DIR + "/injectedClient-" + RuneLiteAPI.getVersion() + "-.jar");
|
classPool.appendClassPath(RuneLite.RUNELITE_DIR+"/injectedClient-"+ RuneLiteAPI.getVersion() +"-.jar");
|
||||||
} catch (NotFoundException e) {
|
} catch (NotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -105,7 +354,7 @@ public class ClientLoader {
|
|||||||
ClassLoader cl = ClassLoader.getSystemClassLoader();
|
ClassLoader cl = ClassLoader.getSystemClassLoader();
|
||||||
try {
|
try {
|
||||||
URLClassLoader child = new URLClassLoader(
|
URLClassLoader child = new URLClassLoader(
|
||||||
new URL[]{temp.toURI().toURL()},
|
new URL[] {temp.toURI().toURL()},
|
||||||
cl
|
cl
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
@@ -116,10 +365,10 @@ public class ClientLoader {
|
|||||||
Field[] fields = classToLoad.getDeclaredFields();
|
Field[] fields = classToLoad.getDeclaredFields();
|
||||||
for (Field f : fields) {
|
for (Field f : fields) {
|
||||||
try {
|
try {
|
||||||
if (f.getType().getName() == "client") {
|
if (f.getType().getName()=="client") {
|
||||||
ByteCodePatcher.hooks.clientInstance = classToLoad.getName() + "." + f.getName();
|
ByteCodePatcher.hooks.clientInstance = classToLoad.getName()+"."+f.getName();
|
||||||
System.out.println("[RuneLit] Found client instance at " + classToLoad.getName() + "." + f.getName());
|
System.out.println("[RuneLit] Found client instance at "+classToLoad.getName()+"."+f.getName());
|
||||||
return classToLoad.getName() + "." + f.getName();
|
return classToLoad.getName()+"."+f.getName();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -134,7 +383,7 @@ public class ClientLoader {
|
|||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
System.out.println("Class not found: " + entry.getName());
|
System.out.println("Class not found: "+entry.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -144,210 +393,4 @@ public class ClientLoader {
|
|||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public Applet load() {
|
|
||||||
if (updateCheckMode == NONE) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
File injectedClientFile = ByteCodeUtils.injectedClientFile;
|
|
||||||
File hijackedClientFile = ByteCodeUtils.hijackedClientFile;
|
|
||||||
Manifest manifest = new Manifest();
|
|
||||||
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
|
|
||||||
target = new JarOutputStream(new FileOutputStream(injectedClientFile), manifest);
|
|
||||||
RSConfig config = clientConfigLoader.fetch();
|
|
||||||
|
|
||||||
Map<String, byte[]> zipFile = new HashMap<>();
|
|
||||||
{
|
|
||||||
Certificate[] jagexCertificateChain = getJagexCertificateChain();
|
|
||||||
String codebase = config.getCodeBase();
|
|
||||||
String initialJar = config.getInitialJar();
|
|
||||||
URL url = new URL(codebase + initialJar);
|
|
||||||
Request request = new Request.Builder()
|
|
||||||
.url(url)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) {
|
|
||||||
JarInputStream jis;
|
|
||||||
|
|
||||||
jis = new JarInputStream(response.body().byteStream());
|
|
||||||
|
|
||||||
byte[] tmp = new byte[4096];
|
|
||||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream(756 * 1024);
|
|
||||||
for (; ; ) {
|
|
||||||
JarEntry metadata = jis.getNextJarEntry();
|
|
||||||
if (metadata == null) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer.reset();
|
|
||||||
for (; ; ) {
|
|
||||||
int n = jis.read(tmp);
|
|
||||||
if (n <= -1) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
buffer.write(tmp, 0, n);
|
|
||||||
}
|
|
||||||
|
|
||||||
zipFile.put(metadata.getName(), buffer.toByteArray());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (updateCheckMode == AUTO) {
|
|
||||||
Map<String, String> hashes;
|
|
||||||
try (InputStream is = ClientLoader.class.getResourceAsStream("/patch/hashes.json")) {
|
|
||||||
hashes = new Gson().fromJson(new InputStreamReader(is), new TypeToken<HashMap<String, String>>() {
|
|
||||||
}.getType());
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Map.Entry<String, String> file : hashes.entrySet()) {
|
|
||||||
byte[] bytes = zipFile.get(file.getKey());
|
|
||||||
|
|
||||||
String ourHash = null;
|
|
||||||
if (bytes != null) {
|
|
||||||
ourHash = Hashing.sha512().hashBytes(bytes).toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!file.getValue().equals(ourHash)) {
|
|
||||||
if (hijackedClientFile.exists()) {
|
|
||||||
Logger.getAnonymousLogger().warning("[RuneLit] Hash checking / Client patching skipped due to hijacked client.");
|
|
||||||
updateCheckMode = VANILLA;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
log.info("{} had a hash mismatch; falling back to vanilla. {} != {}", file.getKey(), file.getValue(), ourHash);
|
|
||||||
log.info("Client is outdated!");
|
|
||||||
updateCheckMode = VANILLA;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (updateCheckMode == AUTO) {
|
|
||||||
ByteArrayOutputStream patchOs = new ByteArrayOutputStream(756 * 1024);
|
|
||||||
int patchCount = 0;
|
|
||||||
|
|
||||||
for (Map.Entry<String, byte[]> file : zipFile.entrySet()) {
|
|
||||||
byte[] bytes;
|
|
||||||
try (InputStream is = ClientLoader.class.getResourceAsStream("/patch/" + file.getKey() + ".bs")) {
|
|
||||||
if (is == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
bytes = ByteStreams.toByteArray(is);
|
|
||||||
}
|
|
||||||
|
|
||||||
patchOs.reset();
|
|
||||||
Patch.patch(file.getValue(), bytes, patchOs);
|
|
||||||
file.setValue(patchOs.toByteArray());
|
|
||||||
|
|
||||||
++patchCount;
|
|
||||||
|
|
||||||
if (!file.getKey().startsWith("META")) {
|
|
||||||
add(file.getValue(), file.getKey(), target);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (target != null)
|
|
||||||
target.close();
|
|
||||||
|
|
||||||
log.info("Patched {} classes", patchCount);
|
|
||||||
}
|
|
||||||
if (hooksFile.exists()) {
|
|
||||||
ByteCodePatcher.classPool = new ClassPool(true);
|
|
||||||
ByteCodePatcher.classPool.appendClassPath(RuneLite.RUNELITE_DIR + "/injectedClient-" + RuneLiteAPI.getVersion() + "-.jar");
|
|
||||||
Gson gson = new Gson();
|
|
||||||
Hooks hooks = gson.fromJson(new BufferedReader(new FileReader(hooksFile)), Hooks.class);
|
|
||||||
if (hooks.clientInstance.equals("") ||
|
|
||||||
hooks.projectileClass.equals("") ||
|
|
||||||
hooks.actorClass.equals("") ||
|
|
||||||
hooks.mainClientInstance.equals("") ||
|
|
||||||
hooks.playerClass.equals("")) {
|
|
||||||
System.out.println("[RuneLit] Bad hooks, re-scraping.");
|
|
||||||
ByteCodePatcher.clientInstance = getClientInstance(ByteCodeUtils.injectedClientFile.getPath());
|
|
||||||
ByteCodePatcher.findHooks(injectedClientFile.getPath());
|
|
||||||
} else {
|
|
||||||
ByteCodePatcher.clientInstance = hooks.clientInstance;
|
|
||||||
ByteCodePatcher.applyHooks(ByteCodeUtils.injectedClientFile, hooks);
|
|
||||||
System.out.println("[RuneLit] Loaded hooks");
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
System.out.println("[RuneLit] Hooks file not found, scraping hooks.");
|
|
||||||
ByteCodePatcher.clientInstance = getClientInstance(ByteCodeUtils.injectedClientFile.getPath());
|
|
||||||
ByteCodePatcher.findHooks(injectedClientFile.getPath());
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, byte[]> zipFile2 = new HashMap<>();
|
|
||||||
JarInputStream jis = new JarInputStream(new FileInputStream(hijackedClientFile));
|
|
||||||
|
|
||||||
byte[] tmp = new byte[4096];
|
|
||||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream(756 * 1024);
|
|
||||||
for (; ; ) {
|
|
||||||
JarEntry metadata = jis.getNextJarEntry();
|
|
||||||
if (metadata == null) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer.reset();
|
|
||||||
for (; ; ) {
|
|
||||||
int n = jis.read(tmp);
|
|
||||||
if (n <= -1) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
buffer.write(tmp, 0, n);
|
|
||||||
}
|
|
||||||
|
|
||||||
zipFile2.put(metadata.getName(), buffer.toByteArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
String initialClass = config.getInitialClass();
|
|
||||||
|
|
||||||
ClassLoader rsClassLoader = new ClassLoader(ClientLoader.class.getClassLoader()) {
|
|
||||||
@Override
|
|
||||||
protected Class<?> findClass(String name) throws ClassNotFoundException {
|
|
||||||
String path = name.replace('.', '/').concat(".class");
|
|
||||||
byte[] data = zipFile2.get(path);
|
|
||||||
if (data == null) {
|
|
||||||
throw new ClassNotFoundException(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
return defineClass(name, data, 0, data.length);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Class<?> clientClass = rsClassLoader.loadClass(initialClass);
|
|
||||||
|
|
||||||
Applet rs = (Applet) clientClass.newInstance();
|
|
||||||
rs.setStub(new RSAppletStub(config));
|
|
||||||
return rs;
|
|
||||||
} catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException
|
|
||||||
| CompressorException | InvalidHeaderException | CertificateException | SecurityException e) {
|
|
||||||
if (e instanceof ClassNotFoundException) {
|
|
||||||
log.error("Unable to load client - class not found. This means you"
|
|
||||||
+ " are not running RuneLite with Maven as the client patch"
|
|
||||||
+ " is not in your classpath.");
|
|
||||||
}
|
|
||||||
|
|
||||||
log.error("Error loading RS!", e);
|
|
||||||
return null;
|
|
||||||
} catch (NotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void add(byte[] bytes, String entryName, JarOutputStream target) throws IOException {
|
|
||||||
BufferedInputStream in = null;
|
|
||||||
try {
|
|
||||||
JarEntry entry = new JarEntry(entryName);
|
|
||||||
target.putNextEntry(entry);
|
|
||||||
target.write(bytes);
|
|
||||||
target.closeEntry();
|
|
||||||
} finally {
|
|
||||||
if (in != null)
|
|
||||||
in.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,12 +25,11 @@
|
|||||||
*/
|
*/
|
||||||
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
|
||||||
|
|||||||
@@ -25,10 +25,9 @@
|
|||||||
*/
|
*/
|
||||||
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
|
||||||
|
|||||||
@@ -10,12 +10,20 @@ import net.runelite.client.rs.ClientLoader;
|
|||||||
import net.runelite.client.rs.bytecode.transformers.ActorTransform;
|
import net.runelite.client.rs.bytecode.transformers.ActorTransform;
|
||||||
import net.runelite.client.rs.bytecode.transformers.PlayerTransform;
|
import net.runelite.client.rs.bytecode.transformers.PlayerTransform;
|
||||||
import net.runelite.client.rs.bytecode.transformers.ProjectileTransform;
|
import net.runelite.client.rs.bytecode.transformers.ProjectileTransform;
|
||||||
import net.runelite.client.rs.bytecode.transformers.getProjectileTransform;
|
|
||||||
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.*;
|
import java.io.BufferedInputStream;
|
||||||
|
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;
|
||||||
@@ -35,7 +43,7 @@ public class ByteCodePatcher {
|
|||||||
public static void applyHooks(File jf, Hooks hooks) {
|
public static void applyHooks(File jf, Hooks hooks) {
|
||||||
try {
|
try {
|
||||||
URLClassLoader child = new URLClassLoader(
|
URLClassLoader child = new URLClassLoader(
|
||||||
new URL[]{jf.toURI().toURL()},
|
new URL[] {jf.toURI().toURL()},
|
||||||
cl
|
cl
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
@@ -43,11 +51,8 @@ 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 getProjectileClass = Class.forName(hooks.mainClientInstance, false, child);
|
|
||||||
transformGetProjectile(getProjectileClass);
|
|
||||||
Class playerClass = Class.forName(hooks.playerClass, false, child);
|
Class playerClass = Class.forName(hooks.playerClass, false, child);
|
||||||
transformPlayer(playerClass);
|
transformPlayer(playerClass);
|
||||||
|
|
||||||
ByteCodeUtils.updateHijackedJar();
|
ByteCodeUtils.updateHijackedJar();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -61,7 +66,7 @@ public class ByteCodePatcher {
|
|||||||
public static void findHooks(String jf) {
|
public static void findHooks(String jf) {
|
||||||
try {
|
try {
|
||||||
classPool = new ClassPool(true);
|
classPool = new ClassPool(true);
|
||||||
classPool.appendClassPath(RuneLite.RUNELITE_DIR + "/injectedClient-" + RuneLiteAPI.getVersion() + "-.jar");
|
classPool.appendClassPath(RuneLite.RUNELITE_DIR+"/injectedClient-"+ RuneLiteAPI.getVersion() +"-.jar");
|
||||||
} catch (NotFoundException e) {
|
} catch (NotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -94,31 +99,30 @@ public class ByteCodePatcher {
|
|||||||
public static void checkClasses(File jf, JarEntry entry) {
|
public static void checkClasses(File jf, JarEntry entry) {
|
||||||
try {
|
try {
|
||||||
URLClassLoader child = new URLClassLoader(
|
URLClassLoader child = new URLClassLoader(
|
||||||
new URL[]{jf.toURI().toURL()},
|
new URL[] {jf.toURI().toURL()},
|
||||||
cl
|
cl
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
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);
|
||||||
checkgetProjectiles(classToLoad);
|
|
||||||
checkPlayer(classToLoad);
|
checkPlayer(classToLoad);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
System.out.println("Class not found: " + entry.getName());
|
System.out.println("Class not found: "+entry.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void checkActor(Class current) {
|
public static void checkActor(Class current) {
|
||||||
try {
|
try {
|
||||||
Method method = current.getDeclaredMethod("setCombatInfo", int.class, int.class, int.class, int.class, int.class, int.class);
|
Method method = current.getDeclaredMethod("setCombatInfo", new Class[] { 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("[Z-lyte] Transforming Actor at class: " + current.getName());
|
System.out.println("[RuneLit] Transforming Actor at class: "+current.getName());
|
||||||
ActorTransform at = new ActorTransform();
|
ActorTransform at = new ActorTransform();
|
||||||
at.modify(current);
|
at.modify(current);
|
||||||
}
|
}
|
||||||
@@ -130,17 +134,17 @@ public class ByteCodePatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void transformActor(Class actor) {
|
public static void transformActor(Class actor) {
|
||||||
System.out.println("[RuneLit] Transforming Actor at class: " + actor.getName());
|
System.out.println("[RuneLit] Transforming Actor at class: "+actor.getName());
|
||||||
ActorTransform at = new ActorTransform();
|
ActorTransform at = new ActorTransform();
|
||||||
at.modify(actor);
|
at.modify(actor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void checkProjectile(Class current) {
|
public static void checkProjectile(Class current) {
|
||||||
try {
|
try {
|
||||||
Method method = current.getDeclaredMethod("projectileMoved", int.class, int.class, int.class, int.class);
|
Method method = current.getDeclaredMethod("projectileMoved", new Class[] { 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());
|
||||||
ProjectileTransform pt = new ProjectileTransform();
|
ProjectileTransform pt = new ProjectileTransform();
|
||||||
pt.modify(current);
|
pt.modify(current);
|
||||||
}
|
}
|
||||||
@@ -152,39 +156,17 @@ public class ByteCodePatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void transformProjectile(Class projectile) {
|
public static void transformProjectile(Class projectile) {
|
||||||
System.out.println("[RuneLit] Transforming Projectile at class: " + projectile.getName());
|
System.out.println("[RuneLit] Transforming Projectile at class: "+projectile.getName());
|
||||||
ProjectileTransform pt = new ProjectileTransform();
|
ProjectileTransform pt = new ProjectileTransform();
|
||||||
pt.modify(projectile);
|
pt.modify(projectile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void checkgetProjectiles(Class getprojectile) {
|
|
||||||
try {
|
|
||||||
Method method = getprojectile.getDeclaredMethod("getProjectiles");
|
|
||||||
if (method != null) {
|
|
||||||
hooks.mainClientInstance = getprojectile.getName();
|
|
||||||
System.out.println("[RuneLit] Transforming Projectile at class: " + getprojectile.getName());
|
|
||||||
getProjectileTransform gpt = new getProjectileTransform();
|
|
||||||
gpt.modify(getprojectile);
|
|
||||||
}
|
|
||||||
} catch (NoSuchMethodException e) {
|
|
||||||
//e.printStackTrace();
|
|
||||||
} catch (NoClassDefFoundError e) {
|
|
||||||
//e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void transformGetProjectile(Class current) {
|
|
||||||
System.out.println("[RuneLit] Transforming getProjectile at class: " + current.getName());
|
|
||||||
getProjectileTransform gpt = new getProjectileTransform();
|
|
||||||
gpt.modify(current);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void checkPlayer(Class current) {
|
public static void checkPlayer(Class current) {
|
||||||
try {
|
try {
|
||||||
Method method = current.getDeclaredMethod("getSkullIcon");
|
Method method = current.getDeclaredMethod("getSkullIcon");
|
||||||
if (method != null) {
|
if (method!=null) {
|
||||||
hooks.playerClass = current.getName();
|
hooks.playerClass = current.getName();
|
||||||
System.out.println("[RuneLit] Transforming Player at class: " + current.getName());
|
System.out.println("[RuneLit] Transforming Player at class: "+current.getName());
|
||||||
PlayerTransform pt = new PlayerTransform();
|
PlayerTransform pt = new PlayerTransform();
|
||||||
pt.modify(current);
|
pt.modify(current);
|
||||||
}
|
}
|
||||||
@@ -196,9 +178,9 @@ public class ByteCodePatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void transformPlayer(Class player) {
|
public static void transformPlayer(Class player) {
|
||||||
System.out.println("[RuneLit] Transforming Player at class: " + player.getName());
|
System.out.println("[RuneLit] Transforming Player at class: "+player.getName());
|
||||||
PlayerTransform pt = new PlayerTransform();
|
PlayerTransform pt = new PlayerTransform();
|
||||||
pt.modify(player);
|
pt.modify(player);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,18 +4,26 @@ 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.*;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
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.*;
|
import java.util.jar.Attributes;
|
||||||
|
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;
|
||||||
|
|
||||||
public class ByteCodeUtils {
|
public class ByteCodeUtils {
|
||||||
//TODO: Write method to delete old revision injected clients.
|
//TODO: Write method to delete old revision injected clients.
|
||||||
public static File injectedClientFile = new File(RuneLite.RUNELITE_DIR + "/injectedClient-" + RuneLiteAPI.getVersion() + "-.jar");
|
public static File injectedClientFile = new File(RuneLite.RUNELITE_DIR+"/injectedClient-"+ RuneLiteAPI.getVersion() +"-.jar");
|
||||||
public static File hijackedClientFile = new File(RuneLite.RUNELITE_DIR + "/hijackedClient-" + RuneLiteAPI.getVersion() + "-.jar");
|
public static File hijackedClientFile = new File(RuneLite.RUNELITE_DIR+"/hijackedClient-"+ RuneLiteAPI.getVersion() +"-.jar");
|
||||||
|
|
||||||
public static JarOutputStream target;
|
public static JarOutputStream target;
|
||||||
|
|
||||||
@@ -39,12 +47,12 @@ public class ByteCodeUtils {
|
|||||||
JarEntry entry = entries.nextElement();
|
JarEntry entry = entries.nextElement();
|
||||||
boolean skip = false;
|
boolean skip = false;
|
||||||
for (CtClass ct : ByteCodePatcher.modifiedClasses) {
|
for (CtClass ct : ByteCodePatcher.modifiedClasses) {
|
||||||
if ((ct.getName() + ".class").equals(entry.getName())) {
|
if ((ct.getName()+".class").equals(entry.getName())) {
|
||||||
skip = true;
|
skip = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!skip)
|
if (!skip)
|
||||||
add(entry);
|
add(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (CtClass ct : ByteCodePatcher.modifiedClasses) {
|
for (CtClass ct : ByteCodePatcher.modifiedClasses) {
|
||||||
@@ -59,10 +67,10 @@ public class ByteCodeUtils {
|
|||||||
|
|
||||||
private static void add(CtClass ct) {
|
private static void add(CtClass ct) {
|
||||||
try {
|
try {
|
||||||
JarEntry newEntry = new JarEntry(ct.getName() + ".class");
|
JarEntry newEntry = new JarEntry(ct.getName()+".class");
|
||||||
target.putNextEntry(newEntry);
|
target.putNextEntry(newEntry);
|
||||||
target.write(ct.toBytecode());
|
target.write(ct.toBytecode());
|
||||||
target.closeEntry();
|
target.closeEntry();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -70,7 +78,7 @@ public class ByteCodeUtils {
|
|||||||
|
|
||||||
private static void add(JarEntry entry) throws IOException {
|
private static void add(JarEntry entry) throws IOException {
|
||||||
try {
|
try {
|
||||||
if (!entry.getName().startsWith("META") && !entry.getName().equals("")) {
|
if (!entry.getName().startsWith("META")&&!entry.getName().equals("")) {
|
||||||
target.putNextEntry(entry);
|
target.putNextEntry(entry);
|
||||||
target.write(getBytesFromZipFile(entry.getName()));
|
target.write(getBytesFromZipFile(entry.getName()));
|
||||||
target.closeEntry();
|
target.closeEntry();
|
||||||
@@ -86,7 +94,7 @@ public class ByteCodeUtils {
|
|||||||
zipFile = new ZipFile(injectedClientFile);
|
zipFile = new ZipFile(injectedClientFile);
|
||||||
Enumeration<? extends ZipEntry> entries = zipFile.entries();
|
Enumeration<? extends ZipEntry> entries = zipFile.entries();
|
||||||
|
|
||||||
while (entries.hasMoreElements()) {
|
while(entries.hasMoreElements()){
|
||||||
ZipEntry entry = entries.nextElement();
|
ZipEntry entry = entries.nextElement();
|
||||||
if (entry.getName().equals(entryName)) {
|
if (entry.getName().equals(entryName)) {
|
||||||
InputStream stream = zipFile.getInputStream(entry);
|
InputStream stream = zipFile.getInputStream(entry);
|
||||||
@@ -104,6 +112,6 @@ public class ByteCodeUtils {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ public class Hooks {
|
|||||||
public String clientInstance = "";
|
public String clientInstance = "";
|
||||||
public String actorClass = "";
|
public String actorClass = "";
|
||||||
public String projectileClass = "";
|
public String projectileClass = "";
|
||||||
public String mainClientInstance = "";
|
|
||||||
public String playerClass = "";
|
public String playerClass = "";
|
||||||
|
|
||||||
public Hooks() {
|
public Hooks() {
|
||||||
|
|||||||
@@ -1,10 +1,17 @@
|
|||||||
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;
|
||||||
@@ -29,7 +36,7 @@ public class ActorTransform {
|
|||||||
ct.addMethod(protectedAnimation);
|
ct.addMethod(protectedAnimation);
|
||||||
CtMethod getAnimation = ct.getDeclaredMethod("getAnimation");
|
CtMethod getAnimation = ct.getDeclaredMethod("getAnimation");
|
||||||
ct.removeMethod(getAnimation);
|
ct.removeMethod(getAnimation);
|
||||||
getAnimation = CtNewMethod.make("public int getAnimation() { return this.getRsAnimation(); }", ct);
|
getAnimation = CtNewMethod.make("public int getAnimation() { return this.getRsAnimation(); }",ct);
|
||||||
ct.addMethod(getAnimation);
|
ct.addMethod(getAnimation);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -44,7 +51,7 @@ public class ActorTransform {
|
|||||||
getAnimationChanged = CtNewMethod.make("public void animationChanged(int n) { " +
|
getAnimationChanged = CtNewMethod.make("public void animationChanged(int n) { " +
|
||||||
" net.runelite.api.events.AnimationChanged animationChanged = new net.runelite.api.events.AnimationChanged();" +
|
" net.runelite.api.events.AnimationChanged animationChanged = new net.runelite.api.events.AnimationChanged();" +
|
||||||
" animationChanged.setActor((net.runelite.api.Actor)this);" +
|
" animationChanged.setActor((net.runelite.api.Actor)this);" +
|
||||||
" " + ByteCodePatcher.clientInstance + ".getCallbacks().post((java.lang.Object)animationChanged); }", ct);
|
" "+ByteCodePatcher.clientInstance+".getCallbacks().post((java.lang.Object)animationChanged); }",ct);
|
||||||
ct.addMethod(getAnimationChanged);
|
ct.addMethod(getAnimationChanged);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
package net.runelite.client.rs.bytecode.transformers;
|
package net.runelite.client.rs.bytecode.transformers;
|
||||||
|
|
||||||
import javassist.CtClass;
|
import javassist.CtClass;
|
||||||
@@ -39,23 +38,23 @@ public class PlayerTransform {
|
|||||||
String SkullIcon = "net.runelite.api.SkullIcon";
|
String SkullIcon = "net.runelite.api.SkullIcon";
|
||||||
getSkullIcon = ct.getDeclaredMethod("getSkullIcon");
|
getSkullIcon = ct.getDeclaredMethod("getSkullIcon");
|
||||||
ct.removeMethod(getSkullIcon);
|
ct.removeMethod(getSkullIcon);
|
||||||
getSkullIcon = CtNewMethod.make("public " + SkullIcon + " getSkullIcon() {" +
|
getSkullIcon = CtNewMethod.make("public "+SkullIcon+" getSkullIcon() {" +
|
||||||
" switch (this.getRsSkullIcon()) {" +
|
" switch (this.getRsSkullIcon()) {" +
|
||||||
" case 0: {" +
|
" case 0: {" +
|
||||||
" return " + SkullIcon + ".SKULL; }" +
|
" return "+SkullIcon+".SKULL; }" +
|
||||||
" case 1: {" +
|
" case 1: {" +
|
||||||
" return " + SkullIcon + ".SKULL_FIGHT_PIT; }" +
|
" return "+SkullIcon+".SKULL_FIGHT_PIT; }" +
|
||||||
" case 8: {" +
|
" case 8: {" +
|
||||||
" return " + SkullIcon + ".DEAD_MAN_FIVE; }" +
|
" return "+SkullIcon+".DEAD_MAN_FIVE; }" +
|
||||||
" case 9: {" +
|
" case 9: {" +
|
||||||
" return " + SkullIcon + ".DEAD_MAN_FOUR; }" +
|
" return "+SkullIcon+".DEAD_MAN_FOUR; }" +
|
||||||
" case 10: {" +
|
" case 10: {" +
|
||||||
" return " + SkullIcon + ".DEAD_MAN_THREE; }" +
|
" return "+SkullIcon+".DEAD_MAN_THREE; }" +
|
||||||
" case 11: {" +
|
" case 11: {" +
|
||||||
" return " + SkullIcon + ".DEAD_MAN_TWO; }" +
|
" return "+SkullIcon+".DEAD_MAN_TWO; }" +
|
||||||
" case 12: {" +
|
" case 12: {" +
|
||||||
" return " + SkullIcon + ".DEAD_MAN_ONE; } }" +
|
" return "+SkullIcon+".DEAD_MAN_ONE; } }" +
|
||||||
" return null; }", ct);
|
" return null; }",ct);
|
||||||
ct.addMethod(getSkullIcon);
|
ct.addMethod(getSkullIcon);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ 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;
|
||||||
|
|||||||
@@ -1,56 +0,0 @@
|
|||||||
package net.runelite.client.rs.bytecode.transformers;
|
|
||||||
|
|
||||||
import javassist.CtClass;
|
|
||||||
import javassist.CtMethod;
|
|
||||||
import javassist.CtNewMethod;
|
|
||||||
import javassist.bytecode.AnnotationsAttribute;
|
|
||||||
import javassist.bytecode.ClassFile;
|
|
||||||
import javassist.bytecode.ConstPool;
|
|
||||||
import net.runelite.client.rs.bytecode.ByteCodePatcher;
|
|
||||||
|
|
||||||
|
|
||||||
public class getProjectileTransform {
|
|
||||||
public CtClass ct = null;
|
|
||||||
|
|
||||||
public void modify(Class getprojectile) {
|
|
||||||
try {
|
|
||||||
ct = ByteCodePatcher.classPool.get(getprojectile.getName());
|
|
||||||
|
|
||||||
transformGetProjectile();
|
|
||||||
ByteCodePatcher.modifiedClasses.add(ct);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void transformGetProjectile() {
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user