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

Commit

Permalink
asm
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamesuta committed Jun 21, 2017
1 parent 1c89ba4 commit 493a677
Show file tree
Hide file tree
Showing 7 changed files with 792 additions and 696 deletions.
33 changes: 17 additions & 16 deletions src/main/java/com/kamesuta/mc/signpic/asm/ASMDeobfNames.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.kamesuta.mc.signpic.asm;

import javax.annotation.Nonnull;

import com.kamesuta.mc.signpic.asm.lib.RefName;

public class ASMDeobfNames {
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");
public static final @Nonnull RefName FontRendererDrawSplitString = RefName.deobName("drawSplitString", "func_78279_b");
public static final @Nonnull RefName GuiNewChatDrawChat = RefName.deobName("drawChat", "func_146230_a");
public static final @Nonnull RefName GuiNewChatGetChatComponent = RefName.deobName("func_146236_a", "func_146236_a");
public static final @Nonnull RefName GuiScreenBookDrawScreen = RefName.deobName("drawScreen", "func_73863_a");
public static final @Nonnull RefName GuiScreenBookPageInsertIntoCurrent = RefName.deobName("func_146459_b", "func_146459_b");
}
package com.kamesuta.mc.signpic.asm;

import javax.annotation.Nonnull;

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");
public static final @Nonnull RefName FontRendererDrawSplitString = RefName.deobName("drawSplitString", "func_78279_b");
public static final @Nonnull RefName GuiNewChatDrawChat = RefName.deobName("drawChat", "func_146230_a");
public static final @Nonnull RefName GuiNewChatGetChatComponent = RefName.deobName("getChatComponent", "func_146236_a");
public static final @Nonnull RefName GuiScreenBookDrawScreen = RefName.deobName("drawScreen", "func_73863_a");
public static final @Nonnull RefName GuiScreenBookPageInsertIntoCurrent = RefName.deobName("pageInsertIntoCurrent", "func_146459_b");
}
350 changes: 175 additions & 175 deletions src/main/java/com/kamesuta/mc/signpic/asm/GuiNewChatVisitor.java

Large diffs are not rendered by default.

90 changes: 45 additions & 45 deletions src/main/java/com/kamesuta/mc/signpic/asm/GuiScreenBookVisitor.java
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
package com.kamesuta.mc.signpic.asm;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import org.objectweb.asm.ClassVisitor;
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;
import com.kamesuta.mc.signpic.asm.lib.VisitorHelper;

public class GuiScreenBookVisitor extends ClassVisitor {
private static class HookMethodVisitor extends MethodVisitor {
private final @Nonnull MethodMatcher matcher;

public HookMethodVisitor(final @Nullable MethodVisitor mv) {
super(Opcodes.ASM5, mv);
this.matcher = new MethodMatcher(VisitorHelper.getMappedName("net/minecraft/client/gui/FontRenderer"), DescHelper.toDesc(void.class, "java.lang.String", int.class, int.class, int.class, int.class), ASMDeobfNames.FontRendererDrawSplitString);
}

@Override
public void visitMethodInsn(final int opcode, final @Nullable String owner, final @Nullable String name, final @Nullable String desc, final boolean itf) {
if (name!=null&&desc!=null&&this.matcher.match(name, desc))
super.visitMethodInsn(Opcodes.INVOKESTATIC, "com/kamesuta/mc/signpic/render/CustomBookRenderer", "hookDrawSplitString", desc, itf);
else
super.visitMethodInsn(opcode, owner, name, desc, itf);
}
}

private final MethodMatcher matcher;

public GuiScreenBookVisitor(final @Nonnull String obfClassName, final @Nonnull ClassVisitor cv) {
super(Opcodes.ASM5, cv);
this.matcher = new MethodMatcher(obfClassName, DescHelper.toDesc(void.class, int.class, int.class, float.class), ASMDeobfNames.GuiScreenBookDrawScreen);
}

@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;
}
package com.kamesuta.mc.signpic.asm;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import org.objectweb.asm.ClassVisitor;
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;
import com.kamesuta.mc.signpic.asm.lib.VisitorHelper;

public class GuiScreenBookVisitor extends ClassVisitor {
private static class HookMethodVisitor extends MethodVisitor {
private final @Nonnull MethodMatcher matcher;

public HookMethodVisitor(final @Nullable MethodVisitor mv) {
super(Opcodes.ASM5, mv);
this.matcher = new MethodMatcher(VisitorHelper.getMappedName("net/minecraft/client/gui/FontRenderer"), DescHelper.toDesc(void.class, "java.lang.String", int.class, int.class, int.class, int.class), ASMDeobfNames.FontRendererDrawSplitString);
}

@Override
public void visitMethodInsn(final int opcode, final @Nullable String owner, final @Nullable String name, final @Nullable String desc, final boolean itf) {
if (name!=null&&desc!=null&&this.matcher.match(name, desc))
super.visitMethodInsn(Opcodes.INVOKESTATIC, "com/kamesuta/mc/signpic/render/CustomBookRenderer", "hookDrawSplitString", DescHelper.toDesc(void.class, owner, "java.lang.String", int.class, int.class, int.class, int.class), itf);
else
super.visitMethodInsn(opcode, owner, name, desc, itf);
}
}

private final MethodMatcher matcher;

public GuiScreenBookVisitor(final @Nonnull String obfClassName, final @Nonnull ClassVisitor cv) {
super(Opcodes.ASM5, cv);
this.matcher = new MethodMatcher(obfClassName, DescHelper.toDesc(void.class, int.class, int.class, float.class), ASMDeobfNames.GuiScreenBookDrawScreen);
}

@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;
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,59 @@
package com.kamesuta.mc.signpic.asm;

import javax.annotation.Nullable;

import net.minecraft.launchwrapper.IClassTransformer;

public class SignPictureTransformer implements IClassTransformer {

@Override
public @Nullable byte[] transform(final @Nullable String name, final @Nullable String transformedName, final @Nullable byte[] bytes) {
if (bytes==null||name==null||transformedName==null)
return bytes;

//TODO

return bytes;
}
package com.kamesuta.mc.signpic.asm;

import javax.annotation.Nullable;

import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;

import com.kamesuta.mc.signpic.Log;
import com.kamesuta.mc.signpic.asm.lib.VisitorHelper;
import com.kamesuta.mc.signpic.asm.lib.VisitorHelper.TransformProvider;

import net.minecraft.launchwrapper.IClassTransformer;

public class SignPictureTransformer implements IClassTransformer {

@Override
public @Nullable byte[] transform(final @Nullable String name, final @Nullable String transformedName, final @Nullable byte[] bytes) {
if (bytes==null||name==null||transformedName==null)
return bytes;

if (transformedName.equals("net.minecraft.client.gui.GuiScreenBook"))
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 GuiScreenBook.drawScreen (class: %s)", name));
return new GuiScreenBookVisitor(name, cv);
}
});

if (transformedName.equals("net.minecraft.client.gui.GuiNewChat"))
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 GuiNewChat (class: %s)", name));
return new GuiNewChatVisitor(name, cv);
}
});

if (transformedName.equals("net.minecraft.client.gui.GuiScreen"))
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 GuiScreen.handleInput (class: %s)", name));
return new GuiScreenVisitor(name, cv);
}
});
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);
}
});
//TODO

return bytes;
}
}
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;
}
}
Loading

0 comments on commit 493a677

Please sign in to comment.