Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
Fix TileEntityVisitor
Browse files Browse the repository at this point in the history
  • Loading branch information
sjcl committed Jun 15, 2017
1 parent 86055e5 commit ae2fd8a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.kamesuta.mc.signpic.asm.lib.RefName;

public class ASMDeobfNames {
public static final @Nonnull RefName TileEntityGetRenderBoundingBox = RefName.deobName("getRenderBoundingBox", "func_184177_bl");
public static final @Nonnull RefName GuiNewChatDrawnChatLines = RefName.deobName("field_146253_i", "field_146253_i");
public static final @Nonnull RefName GuiScreenHandleInput = RefName.deobName("handleInput", "func_146269_k");
public static final @Nonnull RefName FontRendererDrawStringWithShadow = RefName.deobName("drawStringWithShadow", "func_78261_a");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ public class SignPictureTransformer implements IClassTransformer {
if (bytes==null||name==null||transformedName==null)
return bytes;

if (transformedName.equals("net.minecraft.tileentity.TileEntity"))
return VisitorHelper.apply(bytes, name, new TransformProvider(ClassWriter.COMPUTE_FRAMES) {
@Override
public ClassVisitor createVisitor(final String name, final ClassVisitor cv) {
Log.log.info(String.format("Patching TileEntity.getRenderBoundingBox (class: %s)", name));
return new TileEntityVisitor(name, cv);
}
});

if (transformedName.equals("net.minecraft.client.gui.GuiScreenBook"))
return VisitorHelper.apply(bytes, name, new TransformProvider(ClassWriter.COMPUTE_FRAMES) {
@Override
Expand Down
54 changes: 54 additions & 0 deletions src/main/java/com/kamesuta/mc/signpic/asm/TileEntityVisitor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.kamesuta.mc.signpic.asm;

import javax.annotation.Nullable;

import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

import com.kamesuta.mc.signpic.asm.lib.DescHelper;
import com.kamesuta.mc.signpic.asm.lib.MethodMatcher;

public class TileEntityVisitor extends ClassVisitor {
private static class HookMethodVisitor extends MethodVisitor {
public HookMethodVisitor(final @Nullable MethodVisitor mv) {
super(Opcodes.ASM5, mv);
}

@Override
public void visitCode() {
super.visitCode();
/*
* 0 aload_0 [this]
* 1 instanceof net.minecraft.tileentity.TileEntitySign [3]
* 4 ifeq 11
* 7 getstatic net.minecraft.tileentity.TileEntity.INFINITE_EXTENT_AABB : net.minecraft.util.math.AxisAlignedBB [16]
* 10 areturn
* 11 aload_0 [this]
*/
visitVarInsn(Opcodes.ALOAD, 0);
visitTypeInsn(Opcodes.INSTANCEOF, "net/minecraft/tileentity/TileEntitySign");
final Label skipReturn = new Label();
visitJumpInsn(Opcodes.IFEQ, skipReturn);
visitFieldInsn(Opcodes.GETSTATIC, "net/minecraft/tileentity/TileEntity", "INFINITE_EXTENT_AABB", DescHelper.toDesc("net.minecraft.util.math.AxisAlignedBB"));
visitInsn(Opcodes.ARETURN);
visitLabel(skipReturn);
}
}

private final MethodMatcher matcher;

public TileEntityVisitor(final String obfClassName, final ClassVisitor cv) {
super(Opcodes.ASM5, cv);
this.matcher = new MethodMatcher(obfClassName, DescHelper.toDesc("net.minecraft.util.math.AxisAlignedBB", new Object[0]), ASMDeobfNames.TileEntityGetRenderBoundingBox);
}

@Override
public @Nullable MethodVisitor visitMethod(final int access, final @Nullable String name, final @Nullable String desc, final @Nullable String signature, final @Nullable String[] exceptions) {
final MethodVisitor parent = super.visitMethod(access, name, desc, signature, exceptions);
if (name==null||desc==null)
return parent;
return this.matcher.match(name, desc) ? new HookMethodVisitor(parent) : parent;
}
}

0 comments on commit ae2fd8a

Please sign in to comment.