use of org.objectweb.asm.tree.MethodInsnNode in project malmo by Microsoft.
the class OverclockingClassTransformer method insertTextureHandler.
private static void insertTextureHandler(ClassNode node, boolean isObfuscated) {
// We're attempting to turn this line from GlStateManager.bindTexture:
// GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);
// into this:
// TextureHelper.glBindTexture(GL11.GL_TEXTURE_2D, texture);
// TextureHelpers's method then decides whether or not add a shader to the OpenGL pipeline before
// passing the call on to GL11.glBindTexture.
final String methodName = isObfuscated ? "func_179144_i" : "bindTexture";
// Takes one int, returns void.
final String methodDescriptor = "(I)V";
System.out.println("MALMO: Found GlStateManager, attempting to transform it");
for (MethodNode method : node.methods) {
if (method.name.equals(methodName) && method.desc.equals(methodDescriptor)) {
System.out.println("MALMO: Found GlStateManager.bindTexture() method, attempting to transform it");
for (AbstractInsnNode instruction : method.instructions.toArray()) {
if (instruction.getOpcode() == Opcodes.INVOKESTATIC) {
MethodInsnNode visitMethodNode = (MethodInsnNode) instruction;
if (visitMethodNode.name.equals("glBindTexture")) {
visitMethodNode.owner = "com/microsoft/Malmo/Utils/TextureHelper";
if (isObfuscated) {
visitMethodNode.name = "bindTexture";
}
System.out.println("MALMO: Hooked into call to GlStateManager.bindTexture()");
}
}
}
}
}
}
Aggregations