Make injected rscanvas turn around and call another class which will actually reside in the client, have a fake stub here for it to compile. Fix inject to inject getters on static fields in classes that arent Implemented, fixed signature of injected getters, this seems to work.

This commit is contained in:
Adam
2016-04-17 00:40:53 -04:00
parent fe54620dbe
commit e710975305
4 changed files with 49 additions and 18 deletions

View File

@@ -95,6 +95,31 @@ public class Inject
sig.addArg(toObType(t));
return sig;
}
private Type toApiType(Type t)
{
// t = vanilla type
if (t.isPrimitive())
return t;
String type = t.getType();
type = type.substring(1, type.length() - 1);
ClassFile cf = vanilla.findClass(type);
if (cf == null)
return t;
for (Class c : cf.getInterfaces().getInterfaces())
{
if (c.getName().startsWith(API_PACKAGE_BASE.replace('.', '/')))
{
return new Type("L" + c.getName() + ";", t.getArrayDims());
}
}
return t;
}
public void run()
{
@@ -114,8 +139,8 @@ public class Inject
assert other != null;
java.lang.Class implementingClass = injectInterface(cf, other);
if (implementingClass == null)
continue;
// it can not implement an interface but still have exported static fields, which are
// moved to client
InjectReplace ij = new InjectReplace(cf, other);
try
@@ -132,7 +157,7 @@ public class Inject
{
an = f.getAttributes().getAnnotations();
if (an.find(EXPORT) == null)
if (an == null || an.find(EXPORT) == null)
continue; // not an exported field
String exportedName = an.find(EXPORT).getElement().getString();
@@ -153,12 +178,16 @@ public class Inject
ClassFile targetClass = f.isStatic() ? vanilla.findClass("client") : other; // target class for getter
java.lang.Class targetApiClass = f.isStatic() ? clientClass : implementingClass; // target api class for getter
assert targetApiClass != null;
java.lang.reflect.Method apiMethod = findImportMethodOnApi(targetApiClass, exportedName);
assert apiMethod != null;
injectGetter(targetClass, apiMethod, otherf, getter);
}
if (implementingClass == null)
continue; // can't export methods from non implementing class
for (Method m : cf.getMethods().getMethods())
{
@@ -271,7 +300,7 @@ public class Inject
assert field.isStatic() || field.getFields().getClassFile() == clazz;
Signature sig = new Signature();
sig.setTypeOfReturnValue(field.getType());
sig.setTypeOfReturnValue(toApiType(field.getType()));
Method getterMethod = new Method(clazz.getMethods(), method.getName(), sig);
getterMethod.setAccessFlags(Method.ACC_PUBLIC);

View File

@@ -2,26 +2,16 @@ package net.runelite.inject;
import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import net.runelite.inject.callbacks.RSCanvasCallback;
public abstract class RSCanvas extends Canvas
{
private final BufferedImage clientBuffer = new BufferedImage(756, 503, BufferedImage.TYPE_INT_RGB);
private final BufferedImage gameBuffer = new BufferedImage(756, 503, BufferedImage.TYPE_INT_RGB);
private RSCanvasCallback callback = new RSCanvasCallback();
@Override
public Graphics getGraphics()
{
Graphics clientGraphics = clientBuffer.getGraphics();
clientGraphics.drawImage(gameBuffer, 0, 0, null);
//clientGraphics.dispose();
//clientGraphics = clientBuffer.getGraphics();
clientGraphics.drawString("something, something", 42, 42);
Graphics superGraphics = super.getGraphics();
superGraphics.drawImage(clientBuffer, 0, 0, null);
return gameBuffer.getGraphics();
return callback.getGraphics(this, superGraphics);
}
}

View File

@@ -0,0 +1,12 @@
package net.runelite.inject.callbacks;
import java.awt.Canvas;
import java.awt.Graphics;
public class RSCanvasCallback
{
public Graphics getGraphics(Canvas canvas, Graphics graphics)
{
return graphics;
}
}

View File

@@ -10,7 +10,7 @@ import org.junit.Test;
public class InjectTest
{
private static final File DEOBFUSCATED = new File("d:/rs/07/gamepack_v21_mapped.jar");//C:\\Users\\Adam\\.m2\\repository\\net\\runelite\\rs\\rs-client\\1.0-SNAPSHOT\\rs-client-1.0-SNAPSHOT.jar");
private static final File DEOBFUSCATED = new File("C:\\Users\\Adam\\.m2\\repository\\net\\runelite\\rs\\rs-client\\1.0-SNAPSHOT\\rs-client-1.0-SNAPSHOT.jar");
private static final File VANILLA = new File(InjectTest.class.getResource("/gamepack_v21.jar").getFile());
private static final File OUT = new File("d:/rs/07/adamout.jar");