Search in sources :

Example 1 with InjectionModscript

use of net.runelite.runeloader.inject.InjectionModscript in project runelite by runelite.

the class CheckMappings method checkMappings.

@Test
@Ignore
public void checkMappings() throws IOException {
    InjectionModscript mod = Injection.load(MappingImporter.class.getResourceAsStream(MappingImporter.RL_INJECTION));
    for (int i = 0; i < mod.getGetterInjects().size(); ++i) {
        GetterInjectInstruction gii = (GetterInjectInstruction) mod.getGetterInjects().get(i);
        Class c = this.findClassWithObfuscatedName(gii.getGetterClassName());
        Assert.assertNotNull(c);
        Field f = this.findFieldWithObfuscatedName(c, gii.getGetterFieldName());
        Assert.assertNotNull(f);
        String exportedName = this.getExportedName(f);
        String attrName = gii.getGetterName();
        attrName = Utils.toExportedName(attrName);
        Integer mul = gii.getMultiplier(), myMul = this.getIntegerMultiplier(f);
        // XXX Check @Export etc names
        // Assert.assertEquals(exportedName, attrName);
        Assert.assertEquals(myMul, mul);
    }
}
Also used : Field(java.lang.reflect.Field) InjectionModscript(net.runelite.runeloader.inject.InjectionModscript) GetterInjectInstruction(net.runelite.runeloader.inject.GetterInjectInstruction) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with InjectionModscript

use of net.runelite.runeloader.inject.InjectionModscript in project runelite by runelite.

the class MappingImporter method makeMappings.

@Test
@Ignore
public void makeMappings() throws IOException {
    InjectionModscript mod = Injection.load(MappingImporter.class.getResourceAsStream(RL_INJECTION));
    int fields = 0, classes = 0;
    for (int i = 0; i < mod.getGetterInjects().size(); ++i) {
        GetterInjectInstruction gii = (GetterInjectInstruction) mod.getGetterInjects().get(i);
        ClassFile cf = this.findClassWithObfuscatedName(gii.getGetterClassName());
        Assert.assertNotNull(cf);
        Field f = this.findFieldWithObfuscatedName(cf, gii.getGetterFieldName());
        if (f == null) {
            // so they don't all exist
            continue;
        }
        String attrName = gii.getGetterName();
        attrName = Utils.toExportedName(attrName);
        Annotations an = f.getAnnotations();
        Annotation a = an.find(EXPORT);
        if (a != null) {
            String exportedName = a.getElement().getString();
            if (!attrName.equals(exportedName)) {
                logger.info("Exported field " + f + " with mismatched name. Theirs: " + attrName + ", mine: " + exportedName);
            }
        } else {
            an.addAnnotation(EXPORT, "value", attrName);
            logger.info("Exporting field " + f + " with name " + attrName);
            ++fields;
        }
    }
    for (AddInterfaceInstruction aii : mod.getAddInterfaceInjects()) {
        ClassFile cf = this.findClassWithObfuscatedName(aii.getClientClass());
        Assert.assertNotNull(cf);
        String iface = aii.getInterfaceClass();
        iface = iface.replace("com/runeloader/api/bridge/os/accessor/", "");
        Annotations an = cf.getAnnotations();
        Annotation a = an.find(IMPLEMENTS);
        if (a != null) {
            String implementsName = a.getElement().getString();
            if (!iface.equals(implementsName)) {
                logger.info("Implements class " + cf + " with mismatched name. Theirs: " + iface + ", mine: " + implementsName);
            }
        } else {
            an.addAnnotation(IMPLEMENTS, "value", iface);
            logger.info("Exporting class " + cf.getName() + " with name " + iface);
            ++classes;
        }
    }
    logger.info("Added {} fields, {} classes", fields, classes);
}
Also used : Field(net.runelite.asm.Field) ClassFile(net.runelite.asm.ClassFile) Annotations(net.runelite.asm.attributes.Annotations) InjectionModscript(net.runelite.runeloader.inject.InjectionModscript) AddInterfaceInstruction(net.runelite.runeloader.inject.AddInterfaceInstruction) GetterInjectInstruction(net.runelite.runeloader.inject.GetterInjectInstruction) Annotation(net.runelite.asm.attributes.annotation.Annotation) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with InjectionModscript

use of net.runelite.runeloader.inject.InjectionModscript in project runelite by runelite.

the class CheckExports method checkMappings.

@Test
@Ignore
public void checkMappings() throws IOException {
    InjectionModscript mod = Injection.load(MappingImporter.class.getResourceAsStream(MappingImporter.RL_INJECTION));
    for (int i = 0; i < mod.getGetterInjects().size(); ++i) {
        GetterInjectInstruction gii = (GetterInjectInstruction) mod.getGetterInjects().get(i);
        Class c = this.findClassWithObfuscatedName(gii.getGetterClassName());
        Assert.assertNotNull(c);
        Field f = this.findFieldWithObfuscatedName(c, gii.getGetterFieldName());
        Assert.assertNotNull(f);
        Assert.assertTrue(this.isExported(f));
    }
}
Also used : Field(java.lang.reflect.Field) InjectionModscript(net.runelite.runeloader.inject.InjectionModscript) GetterInjectInstruction(net.runelite.runeloader.inject.GetterInjectInstruction) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

GetterInjectInstruction (net.runelite.runeloader.inject.GetterInjectInstruction)3 InjectionModscript (net.runelite.runeloader.inject.InjectionModscript)3 Ignore (org.junit.Ignore)3 Test (org.junit.Test)3 Field (java.lang.reflect.Field)2 ClassFile (net.runelite.asm.ClassFile)1 Field (net.runelite.asm.Field)1 Annotations (net.runelite.asm.attributes.Annotations)1 Annotation (net.runelite.asm.attributes.annotation.Annotation)1 AddInterfaceInstruction (net.runelite.runeloader.inject.AddInterfaceInstruction)1