Skip to content

Commit

Permalink
project(injector): Make it possible to use rsc-api in rsc
Browse files Browse the repository at this point in the history
  • Loading branch information
Owain94 committed May 11, 2022
1 parent 8ed22ca commit 28dcc47
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import com.openosrs.injector.InjectUtil;
import com.openosrs.injector.injection.InjectData;
import com.openosrs.injector.injectors.AbstractInjector;
import java.util.HashSet;
import java.util.List;
import java.util.ListIterator;
import java.util.Set;
import net.runelite.asm.ClassFile;
import net.runelite.asm.Field;
import net.runelite.asm.Method;
Expand Down Expand Up @@ -43,6 +45,9 @@ public class CopyRuneLiteClasses extends AbstractInjector
"RuneLiteObject"
);


private final Set<Type> shadowFields = new HashSet<>();

public CopyRuneLiteClasses(InjectData inject)
{
super(inject);
Expand All @@ -52,6 +57,8 @@ public void inject()
{
for (String className : RUNELITE_OBJECTS)
{
shadowFields.clear();

ClassFile runeliteObjectVanilla = inject.vanilla.findClass(className);

final ClassFile runeLiteDeob = inject.getDeobfuscated()
Expand Down Expand Up @@ -85,18 +92,23 @@ public void inject()
runeliteObjectVanilla.getInterfaces().addInterface(interfaze);
}

for (Field field : runeLiteDeob.getFields())
{
field.setType(InjectUtil.deobToVanilla(inject, field.getType()));
runeliteObjectVanilla.addField(field);
}

for (Method method : runeLiteDeob.getMethods())
{
transformMethod(method);
runeliteObjectVanilla.addMethod(method);
}

for (Field field : runeLiteDeob.getFields())
{
if (shadowFields.contains(field.getType()))
{
continue;
}

field.setType(InjectUtil.deobToVanilla(inject, field.getType()));
runeliteObjectVanilla.addField(field);
}

inject.vanilla.addClass(runeliteObjectVanilla);
}
}
Expand Down Expand Up @@ -165,7 +177,16 @@ else if (i instanceof GetStatic)
net.runelite.asm.pool.Field field = ((GetStatic) i).getField();
Field vanilla = findField(field);

if (vanilla != null)
if (method.getClassFile().getName().equals(field.getClazz().getName()) && field.getType().toString().contains("Lnet/runelite/rs/api/RS"))
{
shadowFields.add(field.getType());

String fieldName = field.getType().toString().replace("Lnet/runelite/rs/api/RS", "").replace(";", "");
final Field deobTargetField = InjectUtil.findStaticField(inject, fieldName.substring(0, 1).toLowerCase() + fieldName.substring(1), null, InjectUtil.apiToDeob(inject, field.getType()));

iterator.set(new GetStatic(ins, inject.toVanilla(deobTargetField)));
}
else if (vanilla != null)
{
iterator.set(new GetStatic(ins, vanilla));
}
Expand Down
1 change: 1 addition & 0 deletions runescape-client/runescape-client.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ group = "com.openosrs.rs"
description = "RuneScape Client"

dependencies {
api(project(":runescape-api"))
api(project(":runelite-api"))

implementation(project(":injection-annotations"))
Expand Down

0 comments on commit 28dcc47

Please sign in to comment.