Make RSApiInjector prioritize same-class methods/fields over static

This commit is contained in:
Lucwousin
2019-11-06 17:37:21 +01:00
parent b07ad10afc
commit a7344a7773
3 changed files with 40 additions and 6 deletions

View File

@@ -14,7 +14,7 @@ plugins {
}
group = "com.openosrs"
version = "1.0.0"
version = "1.0.1"
repositories {
mavenCentral()

View File

@@ -265,9 +265,14 @@ public interface InjectUtil
throw new Injexception("Field " + name + " doesn't exist");
}
static ClassFile fromApiMethod(InjectData data, RSApiMethod apiMethod)
static ClassFile deobFromApiMethod(InjectData data, RSApiMethod apiMethod)
{
return data.toVanilla(data.toDeob(apiMethod.getClazz().getName()));
return data.toDeob(apiMethod.getClazz().getName());
}
static ClassFile vanillaFromApiMethod(InjectData data, RSApiMethod apiMethod)
{
return data.toVanilla(deobFromApiMethod(data, apiMethod));
}
static Signature apiToDeob(InjectData data, Signature api)

View File

@@ -70,7 +70,7 @@ public class RSApiInjector extends AbstractInjector
final RSApiClass implementingClass = inject.getRsApi().findClass(API_BASE + deobClass.getName());
injectFields(deobClass, implementingClass);
injectMethods(deobClass, implementingClass); // aka invokers
injectMethods(deobClass, implementingClass);
}
retryFailures();
@@ -101,6 +101,20 @@ public class RSApiInjector extends AbstractInjector
continue;
}
// Check if there's a field with the same exported name on the api target class itself,
// as that should come before random static fields.
if (deobField.isStatic())
{
ClassFile deobApiTarget = InjectUtil.deobFromApiMethod(inject, apiMethod);
if (deobApiTarget != deobClass &&
deobApiTarget.findField(deobField.getName()) != null)
{
it.remove();
continue;
}
}
final Signature sig = apiMethod.getSignature();
if (sig.isVoid())
@@ -161,6 +175,21 @@ public class RSApiInjector extends AbstractInjector
while (it.hasNext())
{
final RSApiMethod apiMethod = it.next();
// Check if there's a method with the same exported name on the api target class itself,
// as that should come before random static methods.
if (deobMethod.isStatic())
{
ClassFile deobApiTarget = InjectUtil.deobFromApiMethod(inject, apiMethod);
if (deobApiTarget != deobClass &&
deobApiTarget.findMethod(deobMethod.getName()) != null)
{
it.remove();
continue;
}
}
final Signature apiSig = apiMethod.getSignature();
if (apiMethod.isInjected()
@@ -174,7 +203,7 @@ public class RSApiInjector extends AbstractInjector
{
final RSApiMethod apiMethod = matching.get(0);
final ClassFile targetClass = InjectUtil.fromApiMethod(inject, apiMethod);
final ClassFile targetClass = InjectUtil.vanillaFromApiMethod(inject, apiMethod);
final Method vanillaMethod = inject.toVanilla(deobMethod);
final String garbage = DeobAnnotations.getDecoder(deobMethod);
log.debug("Injecting invoker {} for {} into {}", apiMethod.getMethod(), vanillaMethod.getPoolMethod(), targetClass.getPoolClass());
@@ -233,7 +262,7 @@ public class RSApiInjector extends AbstractInjector
{
for (RSApiMethod apiMethod : matched)
{
final ClassFile targetClass = InjectUtil.fromApiMethod(inject, apiMethod);
final ClassFile targetClass = InjectUtil.vanillaFromApiMethod(inject, apiMethod);
apiMethod.setInjected(true);
if (apiMethod.getSignature().isVoid())