This repository has been archived by the owner on Jan 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
sjcl
committed
Jun 15, 2017
1 parent
86055e5
commit ae2fd8a
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/com/kamesuta/mc/signpic/asm/TileEntityVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |