Skip to content

Commit

Permalink
injector: add interfaces correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatGamerBlue committed Dec 22, 2020
1 parent 399549e commit de0773d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ buildscript {
dependencies {
classpath("org.ajoberstar.grgit:grgit-core:4.1.0")
classpath("com.github.ben-manes:gradle-versions-plugin:0.36.0")
classpath("com.openosrs:openosrs-injector:1.0.1")
classpath("com.openosrs:openosrs-injector:1.0.2")
}
}

Expand Down
7 changes: 5 additions & 2 deletions deobfuscator/src/main/java/net/runelite/asm/Interfaces.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@ public class Interfaces implements Iterable<Class>
classFile = c;
}

public void addInterface(Class clazz)
public boolean addInterface(Class clazz)
{
if (!interfaces.contains(clazz))
if (interfaces.stream().noneMatch((itf) -> itf.getName().equals(clazz.getName())))
{
interfaces.add(clazz);
return true;
}

return false;
}

public List<Class> getInterfaces()
Expand Down
4 changes: 1 addition & 3 deletions openosrs-injector/openosrs-injector.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ plugins {
id("se.patrikerdes.use-latest-versions")
}

val oprsver = "3.5.1"

group = "com.openosrs"
version = "1.0.1"
version = "1.0.2"

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public class MixinInjector extends AbstractInjector
private static final String ASSERTION_FIELD = "$assertionsDisabled";
private static final String MIXIN_BASE = "net/runelite/mixins/";

private int injectedInterfaces = 0;
private final Map<String, Field> injectedFields = new HashMap<>();
private final Map<net.runelite.asm.pool.Field, ShadowField> shadowFields = new HashMap<>();
private int copied = 0, replaced = 0, injected = 0;
Expand All @@ -106,6 +107,13 @@ public void inject()
@VisibleForTesting
void inject(Map<Provider<ClassFile>, List<ClassFile>> mixinTargets)
{
for (Map.Entry<Provider<ClassFile>, List<ClassFile>> entry : mixinTargets.entrySet())
{
injectInterfaces(entry.getKey(), entry.getValue());
}

log.info("[INFO] Injected {} interfaces", injectedInterfaces);

for (Map.Entry<Provider<ClassFile>, List<ClassFile>> entry : mixinTargets.entrySet())
{
System.out.println(entry.getKey().get().getName());
Expand Down Expand Up @@ -157,6 +165,29 @@ private Map<Provider<ClassFile>, List<ClassFile>> initTargets()
return builder.build();
}

private void injectInterfaces(Provider<ClassFile> mixinProvider, List<ClassFile> targetClasses)
{
try
{
final ClassFile mixinClass = mixinProvider.get();

for (final ClassFile targetClass : targetClasses)
{
mixinClass.getInterfaces().getInterfaces().forEach((itf) ->
{
if (targetClass.getInterfaces().addInterface(itf))
{
injectedInterfaces++;
}
});
}
}
catch (Exception e)
{
e.printStackTrace();
}
}

private void injectFields(Provider<ClassFile> mixinProvider, List<ClassFile> targetClasses)
{
try
Expand Down

0 comments on commit de0773d

Please sign in to comment.