-
Notifications
You must be signed in to change notification settings - Fork 1
/
ClassTransformer.java
51 lines (45 loc) · 1.96 KB
/
ClassTransformer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package me.djtheredstoner.lwjgl.plugin;
import net.minecraft.launchwrapper.IClassTransformer;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.*;
public class ClassTransformer implements IClassTransformer {
@Override
public byte[] transform(String name, String transformedName, byte[] basicClass) {
if (name.equals("org.lwjgl.nanovg.NanoVGGLConfig")) {
ClassReader reader = new ClassReader(basicClass);
ClassNode node = new ClassNode();
reader.accept(node, ClassReader.EXPAND_FRAMES);
for (MethodNode method : node.methods) {
if (method.name.equals("configGL")) {
InsnList list = new InsnList();
list.add(new VarInsnNode(Opcodes.LLOAD, 0));
list.add(new TypeInsnNode(Opcodes.NEW, "me/djtheredstoner/lwjgl/Lwjgl2FunctionProvider"));
list.add(new InsnNode(Opcodes.DUP));
list.add(new MethodInsnNode(
Opcodes.INVOKESPECIAL,
"me/djtheredstoner/lwjgl/Lwjgl2FunctionProvider",
"<init>",
"()V",
false
));
list.add(new MethodInsnNode(
Opcodes.INVOKESTATIC,
"org/lwjgl/nanovg/NanoVGGLConfig",
"config",
"(JLorg/lwjgl/system/FunctionProvider;)V",
false
));
list.add(new InsnNode(Opcodes.RETURN));
method.instructions.clear();
method.instructions.insert(list);
}
}
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
node.accept(cw);
return cw.toByteArray();
}
return basicClass;
}
}