Cleanup and better logging

This commit is contained in:
Scott Burns
2019-05-16 02:21:43 +02:00
parent 56eaf248fb
commit 16de0c559e
8 changed files with 224 additions and 32 deletions

View File

@@ -233,6 +233,7 @@ public class ClientLoader
Hooks hooks = gson.fromJson(new BufferedReader(new FileReader(hooksFile)), Hooks.class);
if (hooks.clientInstance.equals("") ||
hooks.clientClass.equals("") ||
hooks.projectileClass.equals("") ||
hooks.actorClass.equals("") ||
hooks.playerClass.equals(""))

View File

@@ -18,6 +18,7 @@ import java.util.jar.JarInputStream;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.NotFoundException;
import lombok.extern.slf4j.Slf4j;
import net.runelite.client.RuneLite;
import net.runelite.client.rs.ClientLoader;
import net.runelite.client.rs.bytecode.transformers.ActorTransform;
@@ -28,6 +29,7 @@ import net.runelite.client.rs.bytecode.transformers.ProjectileTransform;
import net.runelite.http.api.RuneLiteAPI;
import org.xeustechnologies.jcl.JarClassLoader;
@Slf4j
public class ByteCodePatcher
{
@@ -51,43 +53,43 @@ public class ByteCodePatcher
);
try
{
RuneLite.splashScreen.setSubMessage("Transforming Client");
Class clientClass = Class.forName(hooks.clientClass, false, child);
transformClient(clientClass);
RuneLite.splashScreen.setProgress(1, 5);
RuneLite.splashScreen.setSubMessage("Transforming Actor");
Class actorClass = Class.forName(hooks.actorClass, false, child);
transformActor(actorClass);
RuneLite.splashScreen.setProgress(1, 5);
RuneLite.splashScreen.setProgress(2, 5);
RuneLite.splashScreen.setSubMessage("Transforming Projectile");
Class projectileClass = Class.forName(hooks.projectileClass, false, child);
transformProjectile(projectileClass);
RuneLite.splashScreen.setProgress(2, 5);
RuneLite.splashScreen.setProgress(3, 5);
RuneLite.splashScreen.setSubMessage("Transforming Player");
Class playerClass = Class.forName(hooks.playerClass, false, child);
transformPlayer(playerClass);
RuneLite.splashScreen.setProgress(3, 5);
RuneLite.splashScreen.setSubMessage("Transforming Client");
Class clientClass = Class.forName("client", false, child);
transformClient(clientClass);
RuneLite.splashScreen.setProgress(4, 5);
// Odds and ends
RuneLite.splashScreen.setSubMessage("Transforming Error method");
ErrorTransform et = new ErrorTransform();
et.modify(null);
transformStackTrace();
RuneLite.splashScreen.setProgress(5, 5);
RuneLite.splashScreen.setSubMessage("");
ByteCodeUtils.updateHijackedJar();
}
catch (Exception e)
{
e.printStackTrace();
// e.printStackTrace();
}
}
catch (Exception e)
{
e.printStackTrace();
// e.printStackTrace();
}
}
@@ -165,23 +167,50 @@ public class ByteCodePatcher
try
{
Class classToLoad = Class.forName(entry.getName().replace(".class", ""), false, child);
checkClient(classToLoad);
checkActor(classToLoad);
checkProjectile(classToLoad);
checkPlayer(classToLoad);
}
catch (Exception e)
{
e.printStackTrace();
// e.printStackTrace();
}
}
catch (Exception e)
{
e.printStackTrace();
System.out.println("Class not found: " + entry.getName());
// e.printStackTrace();
// System.out.println("Class not found: "+entry.getName());
}
}
private static void checkClient(Class current)
{
try
{
Method method = current.getDeclaredMethod("getProjectiles");
if (method != null)
{
hooks.clientClass = current.getName();
log.info("[RuneLitePlus] Transforming Client at class: " + current.getName());
ClientTransform ct = new ClientTransform();
ct.modify(current);
}
}
catch (NoSuchMethodException | NoClassDefFoundError e)
{
// e.printStackTrace();
}
}
private static void transformClient(Class client)
{
log.info("[RuneLitePlus] Transforming Client at class: " + client.getName());
ClientTransform ct = new ClientTransform();
ct.modify(client);
}
private static void checkActor(Class current)
{
try
@@ -190,19 +219,20 @@ public class ByteCodePatcher
if (method != null)
{
hooks.actorClass = current.getName();
System.out.println("[RuneLitePlus] Transforming Actor at class: " + current.getName());
log.info("[RuneLitePlus] Transforming Actor at class: " + current.getName());
ActorTransform at = new ActorTransform();
at.modify(current);
}
}
catch (NoSuchMethodException | NoClassDefFoundError e) {
e.printStackTrace();
catch (NoSuchMethodException | NoClassDefFoundError e)
{
// e.printStackTrace();
}
}
private static void transformActor(Class actor)
{
System.out.println("[RuneLitePlus] Transforming Actor at class: " + actor.getName());
log.info("[RuneLitePlus] Transforming Actor at class: " + actor.getName());
ActorTransform at = new ActorTransform();
at.modify(actor);
}
@@ -215,20 +245,20 @@ public class ByteCodePatcher
if (method != null)
{
hooks.projectileClass = current.getName();
System.out.println("[RuneLitePlus] Transforming Projectile at class: " + current.getName());
log.info("[RuneLitePlus] Transforming Projectile at class: " + current.getName());
ProjectileTransform pt = new ProjectileTransform();
pt.modify(current);
}
}
catch (NoSuchMethodException | NoClassDefFoundError e)
{
e.printStackTrace();
// e.printStackTrace();
}
}
private static void transformProjectile(Class projectile)
{
System.out.println("[RuneLitePlus] Transforming Projectile at class: " + projectile.getName());
log.info("[RuneLitePlus] Transforming Projectile at class: " + projectile.getName());
ProjectileTransform pt = new ProjectileTransform();
pt.modify(projectile);
}
@@ -241,29 +271,28 @@ public class ByteCodePatcher
if (method != null)
{
hooks.playerClass = current.getName();
System.out.println("[RuneLitePlus] Transforming Player at class: " + current.getName());
log.info("[RuneLitePlus] Transforming Player at class: " + current.getName());
PlayerTransform pt = new PlayerTransform();
pt.modify(current);
}
}
catch (NoSuchMethodException | NoClassDefFoundError e)
{
e.printStackTrace();
// e.printStackTrace();
}
}
private static void transformPlayer(Class player)
{
System.out.println("[RuneLitePlus] Transforming Player at class: " + player.getName());
log.info("[RuneLitePlus] Transforming Player at class: " + player.getName());
PlayerTransform pt = new PlayerTransform();
pt.modify(player);
}
private static void transformClient(Class clazz)
private static void transformStackTrace()
{
System.out.println("[RuneLitePlus] Transforming Client");
ClientTransform bt = new ClientTransform();
bt.modify(clazz);
log.info("[RuneLitePlus] Transforming Stack Trace");
ErrorTransform et = new ErrorTransform();
et.modify(null);
}
}

View File

@@ -7,6 +7,7 @@ public class Hooks {
public String projectileClass = "";
public String playerClass = "";
public String[] protectedStuff;
public String clientClass = "";
public Hooks() {
}

View File

@@ -5,8 +5,10 @@ import javassist.CtClass;
import javassist.CtMethod;
import javassist.CtNewMethod;
import javassist.NotFoundException;
import lombok.extern.slf4j.Slf4j;
import net.runelite.client.rs.bytecode.ByteCodePatcher;
@Slf4j
public class ActorTransform implements Transform
{
private CtClass ct;
@@ -47,6 +49,13 @@ public class ActorTransform implements Transform
" return this.getRsAnimation();" +
"}", ct);
ct.addMethod(getAnimation);
log.info(
"[RuneLitePlus] transformed {} ({}) at class: {}",
this.getClass().getSimpleName(),
new Object(){}.getClass().getEnclosingMethod().getName(),
ct.getName()
);
}
@@ -63,6 +72,13 @@ public class ActorTransform implements Transform
ByteCodePatcher.clientInstance + ".getCallbacks().post((java.lang.Object)animationChanged);" +
"}", ct);
ct.addMethod(getAnimationChanged);
log.info(
"[RuneLitePlus] transformed {} ({}) at class: {}",
this.getClass().getSimpleName(),
new Object(){}.getClass().getEnclosingMethod().getName(),
ct.getName()
);
}
private void transformGraphicChanged() throws CannotCompileException, NotFoundException
@@ -78,6 +94,13 @@ public class ActorTransform implements Transform
ByteCodePatcher.clientInstance + ".getCallbacks().post(localGraphicChanged);" +
"}", ct);
ct.addMethod(graphicChanged);
log.info(
"[RuneLitePlus] transformed {} ({}) at class: {}",
this.getClass().getSimpleName(),
new Object(){}.getClass().getEnclosingMethod().getName(),
ct.getName()
);
}
}

View File

@@ -8,8 +8,10 @@ import javassist.NotFoundException;
import javassist.bytecode.AnnotationsAttribute;
import javassist.bytecode.ClassFile;
import javassist.bytecode.ConstPool;
import lombok.extern.slf4j.Slf4j;
import net.runelite.client.rs.bytecode.ByteCodePatcher;
@Slf4j
public class ClientTransform implements Transform
{
@@ -55,6 +57,13 @@ public class ClientTransform implements Transform
protectedGetMenuOptions.setName("getMenuOptions");
ct.addMethod(protectedGetMenuOptions);
log.info(
"[RuneLitePlus] transformed {} ({}) at class: {}",
this.getClass().getSimpleName(),
new Object(){}.getClass().getEnclosingMethod().getName(),
ct.getName()
);
}
private void transformGetProjectiles() throws CannotCompileException, NotFoundException
@@ -87,7 +96,13 @@ public class ClientTransform implements Transform
javassist.bytecode.annotation.Annotation annotation = new javassist.bytecode.annotation.Annotation("Override", constPool);
attr.setAnnotation(annotation);
getProjectiles.getMethodInfo().addAttribute(attr);
System.out.println("Added override annotation for getprojectiles");
log.info(
"[RuneLitePlus] transformed {} ({}) at class: {}",
this.getClass().getSimpleName(),
new Object(){}.getClass().getEnclosingMethod().getName(),
ct.getName()
);
}
private void transformProtectedGetMenuTargets() throws CannotCompileException, NotFoundException
@@ -99,6 +114,13 @@ public class ClientTransform implements Transform
protectedGetMenuTargets.setName("getMenuTargets");
ct.addMethod(protectedGetMenuTargets);
log.info(
"[RuneLitePlus] transformed {} ({}) at class: {}",
this.getClass().getSimpleName(),
new Object(){}.getClass().getEnclosingMethod().getName(),
ct.getName()
);
}
private void transformGetCollisionMaps() throws CannotCompileException, NotFoundException
@@ -116,6 +138,13 @@ public class ClientTransform implements Transform
getCollisionMaps = CtMethod.make("public net.runelite.rs.api.RSCollisionData[] getCollisionMaps() { return getRsCollisionMaps(); }", ct);
ct.addMethod(getCollisionMaps);
log.info(
"[RuneLitePlus] transformed {} ({}) at class: {}",
this.getClass().getSimpleName(),
new Object(){}.getClass().getEnclosingMethod().getName(),
ct.getName()
);
}
private void transformProtectedGetMenuIdentifiers() throws CannotCompileException, NotFoundException
@@ -127,6 +156,13 @@ public class ClientTransform implements Transform
protectedGetMenuIdentifiers.setName("getMenuIdentifiers");
ct.addMethod(protectedGetMenuIdentifiers);
log.info(
"[RuneLitePlus] transformed {} ({}) at class: {}",
this.getClass().getSimpleName(),
new Object(){}.getClass().getEnclosingMethod().getName(),
ct.getName()
);
}
private void transformProtectedGetMenuTypes() throws CannotCompileException, NotFoundException
@@ -141,6 +177,13 @@ public class ClientTransform implements Transform
newProtectedGetMenuTypes.setName("getMenuTypes");
ct.addMethod(newProtectedGetMenuTypes);
log.info(
"[RuneLitePlus] transformed {} ({}) at class: {}",
this.getClass().getSimpleName(),
new Object(){}.getClass().getEnclosingMethod().getName(),
ct.getName()
);
}
private void transformProtectedGetMenuActionParams0() throws CannotCompileException, NotFoundException
@@ -152,6 +195,13 @@ public class ClientTransform implements Transform
protectedGetMenuActionParams0.setName("getMenuActionParams0");
ct.addMethod(protectedGetMenuActionParams0);
log.info(
"[RuneLitePlus] transformed {} ({}) at class: {}",
this.getClass().getSimpleName(),
new Object(){}.getClass().getEnclosingMethod().getName(),
ct.getName()
);
}
private void transformProtectedGetMenuActionParams1() throws CannotCompileException, NotFoundException
@@ -162,6 +212,13 @@ public class ClientTransform implements Transform
ct.removeMethod(protectedGetMenuActionParams1);
protectedGetMenuActionParams1.setName("getMenuActionParams1");
ct.addMethod(protectedGetMenuActionParams1);
log.info(
"[RuneLitePlus] transformed {} ({}) at class: {}",
this.getClass().getSimpleName(),
new Object(){}.getClass().getEnclosingMethod().getName(),
ct.getName()
);
}
private void transformGetMenuEntries() throws CannotCompileException, NotFoundException
@@ -199,6 +256,13 @@ public class ClientTransform implements Transform
" return arrmenuEntry;" +
"}", ct);
ct.addMethod(getMenuEntries);
log.info(
"[RuneLitePlus] transformed {} ({}) at class: {}",
this.getClass().getSimpleName(),
new Object(){}.getClass().getEnclosingMethod().getName(),
ct.getName()
);
}
private void transformSetMenuEntries() throws CannotCompileException, NotFoundException
@@ -273,6 +337,13 @@ public class ClientTransform implements Transform
, ct);
ct.addMethod(onMenuOptionsChanged);
log.info(
"[RuneLitePlus] transformed {} ({}) at class: {}",
this.getClass().getSimpleName(),
new Object(){}.getClass().getEnclosingMethod().getName(),
ct.getName()
);
}
private void transformRenderSelf() throws CannotCompileException
@@ -289,6 +360,13 @@ public class ClientTransform implements Transform
renderSelf.getMethodInfo().addAttribute(attr);
ct.addMethod(renderSelf);
log.info(
"[RuneLitePlus] transformed {} ({}) at class: {}",
this.getClass().getSimpleName(),
new Object(){}.getClass().getEnclosingMethod().getName(),
ct.getName()
);
}
private void transformDraw2010Menu() throws CannotCompileException, NotFoundException
@@ -350,6 +428,13 @@ public class ClientTransform implements Transform
"}"
, ct);
ct.addMethod(draw2010Menu);
log.info(
"[RuneLitePlus] transformed {} ({}) at class: {}",
this.getClass().getSimpleName(),
new Object(){}.getClass().getEnclosingMethod().getName(),
ct.getName()
);
}
//TODO: fix not being able to click far away objects towards top of screen only.
@@ -431,6 +516,13 @@ public class ClientTransform implements Transform
" return false;" +
"}", ct);
ct.addMethod(boundingboxCheck2);
log.info(
"[RuneLitePlus] transformed {} ({}) at class: {}",
this.getClass().getSimpleName(),
new Object(){}.getClass().getEnclosingMethod().getName(),
ct.getName()
);
}
private void transformcheckClickBox() throws CannotCompileException, NotFoundException
@@ -539,5 +631,12 @@ public class ClientTransform implements Transform
" }" +
"}", ct);
ct.addMethod(checkClickBox);
log.info(
"[RuneLitePlus] transformed {} ({}) at class: {}",
this.getClass().getSimpleName(),
new Object(){}.getClass().getEnclosingMethod().getName(),
ct.getName()
);
}
}

View File

@@ -4,8 +4,10 @@ import javassist.CannotCompileException;
import javassist.CtClass;
import javassist.CtMethod;
import javassist.NotFoundException;
import lombok.extern.slf4j.Slf4j;
import net.runelite.client.rs.bytecode.ByteCodePatcher;
@Slf4j
// This prevents the client from sending stack traces to Jagex at all, even classes outside of runelite.
public class ErrorTransform implements Transform
{
@@ -21,8 +23,6 @@ public class ErrorTransform implements Transform
{
try
{
System.out.println("[RuneLitePlus] Transforming error method at class: " + ERROR_INSTANCE_CLASS);
ct = ByteCodePatcher.classPool.get(ERROR_INSTANCE_CLASS);
transformError();
@@ -46,5 +46,12 @@ public class ErrorTransform implements Transform
" System.out.println(\"[RuneLitePlus] Prevented preceeding stack trace from being sent to Jagex\");" +
"}", ct);
ct.addMethod(error);
log.info(
"[RuneLitePlus] transformed {} ({}) at class: {}",
this.getClass().getSimpleName(),
new Object(){}.getClass().getEnclosingMethod().getName(),
ct.getName()
);
}
}

View File

@@ -5,8 +5,10 @@ import javassist.CtClass;
import javassist.CtMethod;
import javassist.CtNewMethod;
import javassist.NotFoundException;
import lombok.extern.slf4j.Slf4j;
import net.runelite.client.rs.bytecode.ByteCodePatcher;
@Slf4j
public class PlayerTransform implements Transform
{
private CtClass ct;
@@ -36,6 +38,13 @@ public class PlayerTransform implements Transform
protectedGetSkullIcon.setName("getRsSkullIcon");
ct.addMethod(protectedGetSkullIcon);
log.info(
"[RuneLitePlus] transformed {} ({}) at class: {}",
this.getClass().getSimpleName(),
new Object(){}.getClass().getEnclosingMethod().getName(),
ct.getName()
);
}
private void transformGetSkullIcon() throws CannotCompileException, NotFoundException
@@ -69,5 +78,12 @@ public class PlayerTransform implements Transform
"return null;" +
"}", ct);
ct.addMethod(getSkullIcon);
log.info(
"[RuneLitePlus] transformed {} ({}) at class: {}",
this.getClass().getSimpleName(),
new Object(){}.getClass().getEnclosingMethod().getName(),
ct.getName()
);
}
}

View File

@@ -5,8 +5,10 @@ import javassist.CtClass;
import javassist.CtMethod;
import javassist.CtNewMethod;
import javassist.NotFoundException;
import lombok.extern.slf4j.Slf4j;
import net.runelite.client.rs.bytecode.ByteCodePatcher;
@Slf4j
public class ProjectileTransform implements Transform
{
private CtClass ct;
@@ -49,6 +51,13 @@ public class ProjectileTransform implements Transform
ByteCodePatcher.clientInstance + ".getCallbacks().post(projectileMoved);" +
"}", ct);
ct.addMethod(getAnimation);
log.info(
"[RuneLitePlus] transformed {} ({}) at class: {}",
this.getClass().getSimpleName(),
new Object(){}.getClass().getEnclosingMethod().getName(),
ct.getName()
);
}
private void transformInteracting() throws CannotCompileException
@@ -92,5 +101,12 @@ public class ProjectileTransform implements Transform
" }" +
"}", ct);
ct.addMethod(getInteracting);
log.info(
"[RuneLitePlus] transformed {} ({}) at class: {}",
this.getClass().getSimpleName(),
new Object(){}.getClass().getEnclosingMethod().getName(),
ct.getName()
);
}
}