use of net.runelite.asm.attributes.annotation.Annotation in project runelite by runelite.
the class Inject method injectInterface.
private java.lang.Class injectInterface(ClassFile cf, ClassFile other) {
Annotations an = cf.getAnnotations();
if (an == null) {
return null;
}
Annotation a = an.find(DeobAnnotations.IMPLEMENTS);
if (a == null) {
return null;
}
String ifaceName = API_PACKAGE_BASE + a.getElement().getString();
java.lang.Class<?> apiClass;
try {
apiClass = java.lang.Class.forName(ifaceName);
} catch (ClassNotFoundException ex) {
logger.trace("Class {} implements nonexistent interface {}, skipping interface injection", cf.getName(), ifaceName);
return null;
}
// to internal name
String ifaceNameInternal = ifaceName.replace('.', '/');
Class clazz = new Class(ifaceNameInternal);
Interfaces interfaces = other.getInterfaces();
interfaces.addInterface(clazz);
return apiClass;
}
use of net.runelite.asm.attributes.annotation.Annotation in project runelite by runelite.
the class InjectHookMethod method findHookLocations.
private List<Integer> findHookLocations(Annotation hook, Method vanillaMethod) throws InjectionException {
Instructions instructions = vanillaMethod.getCode().getInstructions();
boolean end = hook.getElements().size() == 2 && hook.getElements().get(1).getValue().equals(true);
if (end) {
// find return
List<Instruction> returns = instructions.getInstructions().stream().filter(i -> i instanceof ReturnInstruction).collect(Collectors.toList());
List<Integer> indexes = new ArrayList<>();
for (Instruction ret : returns) {
int idx = instructions.getInstructions().indexOf(ret);
assert idx != -1;
indexes.add(idx);
}
return indexes;
}
if (!vanillaMethod.getName().equals("<init>")) {
return Arrays.asList(0);
}
// Find index after invokespecial
for (int i = 0; i < instructions.getInstructions().size(); ++i) {
Instruction in = instructions.getInstructions().get(i);
if (in.getType() == InstructionType.INVOKESPECIAL) {
// one after
return Arrays.asList(i + 1);
}
}
throw new IllegalStateException("constructor with no invokespecial");
}
use of net.runelite.asm.attributes.annotation.Annotation in project runelite by runelite.
the class Field method accept.
public void accept(FieldVisitor visitor) {
for (Annotation annotation : annotations.getAnnotations()) {
AnnotationVisitor av = visitor.visitAnnotation(annotation.getType().toString(), true);
annotation.accept(av);
}
visitor.visitEnd();
}
use of net.runelite.asm.attributes.annotation.Annotation in project runelite by runelite.
the class Annotations method addAnnotation.
public Annotation addAnnotation(Type type, String name, Object value) {
Annotation annotation = new Annotation(this);
annotation.setType(type);
addAnnotation(annotation);
Element element = new Element(annotation);
element.setName(name);
element.setValue(value);
annotation.addElement(element);
return annotation;
}
use of net.runelite.asm.attributes.annotation.Annotation in project runelite by runelite.
the class MixinInjector method findShadowFields.
/**
* Find fields which are marked @Shadow, and what they shadow
*
* @param mixinClasses
* @throws InjectionException
*/
private void findShadowFields(Map<Class<?>, List<ClassFile>> mixinClasses) throws InjectionException {
// Injected static fields take precedence when looking up shadowed fields
for (Class<?> mixinClass : mixinClasses.keySet()) {
ClassFile mixinCf;
try {
mixinCf = loadClass(mixinClass);
} catch (IOException ex) {
throw new InjectionException(ex);
}
for (Field field : mixinCf.getFields()) {
Annotation shadow = field.getAnnotations().find(SHADOW);
if (shadow != null) {
if (!field.isStatic()) {
throw new InjectionException("Can only shadow static fields");
}
// shadow this field
String shadowName = shadow.getElement().getString();
Field injectedField = injectedFields.get(shadowName);
if (injectedField != null) {
// Shadow a field injected by a mixin
shadowFields.put(field.getPoolField(), injectedField);
} else {
// Shadow a field already in the gamepack
Field shadowField = findDeobField(shadowName);
if (shadowField == null) {
throw new InjectionException("Shadow of nonexistent field " + shadowName);
}
Field obShadow = inject.toObField(shadowField);
assert obShadow != null;
shadowFields.put(field.getPoolField(), obShadow);
}
}
}
}
}
Aggregations