From e079a0c29787701c76979901db62d8fd52be170a Mon Sep 17 00:00:00 2001 From: Joe12o Date: Sun, 8 Dec 2013 01:01:32 -0500 Subject: [PATCH] Initial 1.6.4 update. --- .gitignore | 1 + .../com/skcraft/alicefixes/AliceFixes.java | 15 -- .../skcraft/alicefixes/AliceTransformer.java | 41 ----- .../skcraft/alicefixes/BreakerBlacklist.java | 32 ---- .../transformers/TransformBlockBreaker.java | 103 ------------- .../transformers/TransformDislocWand.java | 106 ------------- .../transformers/TransformElemAxe.java | 104 ------------- .../transformers/TransformElemShovel.java | 140 ------------------ .../transformers/TransformExcWand.java | 117 --------------- .../transformers/TransformMiningLaser.java | 130 ---------------- .../transformers/TransformTradeWand.java | 135 ----------------- .../transformers/TransformVajra.java | 107 ------------- .../skcraft/alicefixes/util/CoordHelper.java | 35 ----- .../com/skcraft/alicefixes/util/ObfNames.java | 15 -- build.xml | 21 ++- .../com/skcraft/alicefixes/AFListener.java | 25 ++++ .../com/skcraft/alicefixes/AliceFixes.java | 16 ++ .../skcraft/alicefixes/AliceTransformer.java | 33 +++++ .../com/skcraft/alicefixes/LoadingPlugin.java | 7 +- .../transformers/TransformExcavationWand.java | 70 +++++++++ .../transformers/TransformTools.java | 63 ++++++++ .../transformers/TransformTradeWand.java | 67 +++++++++ .../skcraft/alicefixes/util/ASMHelper.java | 105 +++++++++++++ 23 files changed, 398 insertions(+), 1090 deletions(-) delete mode 100644 alicefixes/src/com/skcraft/alicefixes/AliceFixes.java delete mode 100644 alicefixes/src/com/skcraft/alicefixes/AliceTransformer.java delete mode 100644 alicefixes/src/com/skcraft/alicefixes/BreakerBlacklist.java delete mode 100644 alicefixes/src/com/skcraft/alicefixes/transformers/TransformBlockBreaker.java delete mode 100644 alicefixes/src/com/skcraft/alicefixes/transformers/TransformDislocWand.java delete mode 100644 alicefixes/src/com/skcraft/alicefixes/transformers/TransformElemAxe.java delete mode 100644 alicefixes/src/com/skcraft/alicefixes/transformers/TransformElemShovel.java delete mode 100644 alicefixes/src/com/skcraft/alicefixes/transformers/TransformExcWand.java delete mode 100644 alicefixes/src/com/skcraft/alicefixes/transformers/TransformMiningLaser.java delete mode 100644 alicefixes/src/com/skcraft/alicefixes/transformers/TransformTradeWand.java delete mode 100644 alicefixes/src/com/skcraft/alicefixes/transformers/TransformVajra.java delete mode 100644 alicefixes/src/com/skcraft/alicefixes/util/CoordHelper.java delete mode 100644 alicefixes/src/com/skcraft/alicefixes/util/ObfNames.java create mode 100644 src/main/java/com/skcraft/alicefixes/AFListener.java create mode 100644 src/main/java/com/skcraft/alicefixes/AliceFixes.java create mode 100644 src/main/java/com/skcraft/alicefixes/AliceTransformer.java rename {alicefixes/src => src/main/java}/com/skcraft/alicefixes/LoadingPlugin.java (83%) create mode 100644 src/main/java/com/skcraft/alicefixes/transformers/TransformExcavationWand.java create mode 100644 src/main/java/com/skcraft/alicefixes/transformers/TransformTools.java create mode 100644 src/main/java/com/skcraft/alicefixes/transformers/TransformTradeWand.java create mode 100644 src/main/java/com/skcraft/alicefixes/util/ASMHelper.java diff --git a/.gitignore b/.gitignore index da61aad..3a72ac8 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ /download /.project /.classpath +/*.iml diff --git a/alicefixes/src/com/skcraft/alicefixes/AliceFixes.java b/alicefixes/src/com/skcraft/alicefixes/AliceFixes.java deleted file mode 100644 index 3614e5d..0000000 --- a/alicefixes/src/com/skcraft/alicefixes/AliceFixes.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.skcraft.alicefixes; - -import cpw.mods.fml.common.Mod; -import cpw.mods.fml.common.Mod.PreInit; -import cpw.mods.fml.common.event.FMLPreInitializationEvent; - -//@Mod(modid = "aliceFixes", version = "0.1.0") -public class AliceFixes { - - @PreInit - public void preInit(FMLPreInitializationEvent evt) { - BreakerBlacklist.load(); - } - -} diff --git a/alicefixes/src/com/skcraft/alicefixes/AliceTransformer.java b/alicefixes/src/com/skcraft/alicefixes/AliceTransformer.java deleted file mode 100644 index c61770d..0000000 --- a/alicefixes/src/com/skcraft/alicefixes/AliceTransformer.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.skcraft.alicefixes; - -import java.util.logging.Level; - -import com.skcraft.alicefixes.transformers.TransformDislocWand; -import com.skcraft.alicefixes.transformers.TransformElemAxe; -import com.skcraft.alicefixes.transformers.TransformElemShovel; -import com.skcraft.alicefixes.transformers.TransformMiningLaser; -import com.skcraft.alicefixes.transformers.TransformExcWand; -import com.skcraft.alicefixes.transformers.TransformTradeWand; -import com.skcraft.alicefixes.transformers.TransformVajra; - -import cpw.mods.fml.common.FMLLog; -import cpw.mods.fml.relauncher.IClassTransformer; - -public class AliceTransformer implements IClassTransformer { - - private final IClassTransformer[] transformers = { - new TransformMiningLaser(), - new TransformExcWand(), - new TransformTradeWand(), - new TransformElemAxe(), - new TransformElemShovel(), - new TransformDislocWand(), - new TransformVajra()}; - - @Override - public byte[] transform(String name, String transformedName, byte[] bytes) { - if(bytes == null) { - return bytes; - } - - for(IClassTransformer transformer : transformers) { - bytes = transformer.transform(name, transformedName, bytes); - if(bytes == null) - FMLLog.log(Level.SEVERE, "Transformer " + transformer + " has corrupted class " + name); - } - - return bytes; - } -} diff --git a/alicefixes/src/com/skcraft/alicefixes/BreakerBlacklist.java b/alicefixes/src/com/skcraft/alicefixes/BreakerBlacklist.java deleted file mode 100644 index 220e990..0000000 --- a/alicefixes/src/com/skcraft/alicefixes/BreakerBlacklist.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.skcraft.alicefixes; - -import java.io.File; - -import cpw.mods.fml.common.Loader; -import net.minecraftforge.common.Configuration; - -public class BreakerBlacklist { - - public static int[] forbiddenIds = new int[] {}; - - public static void load() { - File configDir = Loader.instance().getConfigDir(); - configDir = new File(configDir, "/redpower/"); - configDir.mkdir(); - configDir = new File(configDir, "blacklist.cfg"); - Configuration blacklist = new Configuration(configDir); - - try { - blacklist.load(); - forbiddenIds = blacklist.get("Blacklist", "forbiddenBlocks", - new int[] {1}, "List of block IDs that the block breaker cannot break. Add 1 ID per line.").getIntList(); - } - catch(Throwable t) { - t.printStackTrace(); - } - finally { - blacklist.save(); - } - } - -} diff --git a/alicefixes/src/com/skcraft/alicefixes/transformers/TransformBlockBreaker.java b/alicefixes/src/com/skcraft/alicefixes/transformers/TransformBlockBreaker.java deleted file mode 100644 index 2c2a8b5..0000000 --- a/alicefixes/src/com/skcraft/alicefixes/transformers/TransformBlockBreaker.java +++ /dev/null @@ -1,103 +0,0 @@ -package com.skcraft.alicefixes.transformers; - -import static org.objectweb.asm.Opcodes.*; - -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassVisitor; -import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.Label; -import org.objectweb.asm.MethodVisitor; - -import com.skcraft.alicefixes.BreakerBlacklist; -import com.skcraft.alicefixes.util.CoordHelper; -import com.skcraft.alicefixes.util.ObfNames; - -import net.minecraft.tileentity.TileEntity; -import cpw.mods.fml.relauncher.IClassTransformer; - -// THIS MAY NOT WORK ANYMORE! -public class TransformBlockBreaker implements IClassTransformer { - - @Override - public byte[] transform(String name, String transformedName, byte[] bytes) { - if(name.equals("com.eloraam.redpower.machine.TileBreaker")) { - return handleBreakerTransform(bytes); - } - return bytes; - } - - private byte[] handleBreakerTransform(byte[] bytes) { - ClassReader cr = new ClassReader(bytes); - ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS); - - cr.accept(new TileBreakerVisitor(cw), 0); - return cw.toByteArray(); - } - - public static boolean canMine(TileEntity tile, int rotation) { - - CoordHelper facingCoords = new CoordHelper(tile.xCoord, tile.yCoord, - tile.zCoord); - facingCoords.addFacingAsOffset(rotation); - - int id = tile.worldObj.getBlockId(facingCoords.x, facingCoords.y, - facingCoords.z); - - for(int i = 0; i < BreakerBlacklist.forbiddenIds.length; i++) { - if(id == BreakerBlacklist.forbiddenIds[i]) { - return false; - } - } - return true; - } - - class TileBreakerVisitor extends ClassVisitor { - - public TileBreakerVisitor(ClassVisitor cv) { - super(ASM4, cv); - } - - @Override - public MethodVisitor visitMethod(int access, String name, String desc, - String signature, String[] exceptions) { - - if(name.equals("onBlockNeighborChange")) { - return new OnNeighborChangeVisitor(super.visitMethod(access, - name, desc, signature, exceptions)); - } - return super.visitMethod(access, name, desc, signature, - exceptions); - } - } - - class OnNeighborChangeVisitor extends MethodVisitor { - - public OnNeighborChangeVisitor(MethodVisitor mv) { - super(ASM4, mv); - } - - @Override - public void visitCode() { - Label l0 = new Label(); - mv.visitLabel(l0); - mv.visitVarInsn(ALOAD, 0); - mv.visitVarInsn(ALOAD, 0); - mv.visitFieldInsn(GETFIELD, - "com/eloraam/redpower/machine/TileBreaker", - "Rotation", - "I"); - mv.visitMethodInsn(INVOKESTATIC, - "com/skcraft/alicefixes/transformers/TransformBlockBreaker", - "canMine", - "(L" + ObfNames.TILE_ENTITY + ";I)Z"); - Label l1 = new Label(); - mv.visitJumpInsn(IFEQ, l1); - Label l2 = new Label(); - mv.visitLabel(l2); - mv.visitInsn(RETURN); - mv.visitLabel(l1); - mv.visitCode(); - } - - } -} diff --git a/alicefixes/src/com/skcraft/alicefixes/transformers/TransformDislocWand.java b/alicefixes/src/com/skcraft/alicefixes/transformers/TransformDislocWand.java deleted file mode 100644 index ef782ac..0000000 --- a/alicefixes/src/com/skcraft/alicefixes/transformers/TransformDislocWand.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.skcraft.alicefixes.transformers; - -import static org.objectweb.asm.Opcodes.*; - -import java.lang.reflect.Method; - -import net.minecraft.entity.player.EntityPlayer; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.event.block.BlockBreakEvent; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassVisitor; -import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.Label; -import org.objectweb.asm.MethodVisitor; - -import com.skcraft.alicefixes.util.ObfNames; - -import cpw.mods.fml.relauncher.IClassTransformer; - -public class TransformDislocWand implements IClassTransformer { - - @Override - public byte[] transform(String name, String transformedName, byte[] bytes) { - - if(name.equals("vazkii.tinkerer.item.ItemWandDislocation")) { - ClassReader cr = new ClassReader(bytes); - ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS); - cr.accept(new WandVisitor(cw), 0); - return cw.toByteArray(); - } - return bytes; - } - - public static boolean canMine(EntityPlayer player, int x, int y, int z) { - try { - Method m = player.getClass() - .getDeclaredMethod("getBukkitEntity", new Class[] {}); - org.bukkit.entity.Entity ent = - (org.bukkit.entity.Entity)m.invoke(player); - if ((ent instanceof Player)) { - Player bukkitPlayer = (Player)ent; - org.bukkit.World bukkitWorld = bukkitPlayer.getWorld(); - BlockBreakEvent breakEv = new BlockBreakEvent( - bukkitWorld.getBlockAt(x, y, z), bukkitPlayer); - Bukkit.getPluginManager().callEvent(breakEv); - if (breakEv.isCancelled()) { - return false; - } - breakEv.setCancelled(true); - } - } - catch(Exception e) { - e.printStackTrace(); - } - return true; - } - - class WandVisitor extends ClassVisitor { - - public WandVisitor(ClassVisitor cv) { - super(ASM4, cv); - } - - @Override - public MethodVisitor visitMethod(int access, String name, String desc, - String signature, String[] exceptions) { - - if(name.equals("onItemUseFirst")) { - return new OnItemUseFirstVisitor(super.visitMethod(access, name, - desc, signature, exceptions)); - } - return super.visitMethod(access, name, desc, signature, - exceptions); - } - } - - class OnItemUseFirstVisitor extends MethodVisitor { - - public OnItemUseFirstVisitor(MethodVisitor mv) { - super(ASM4, mv); - } - - @Override - public void visitCode() { - Label l0 = new Label(); - mv.visitLabel(l0); - mv.visitVarInsn(ALOAD, 2); - mv.visitVarInsn(ILOAD, 4); - mv.visitVarInsn(ILOAD, 5); - mv.visitVarInsn(ILOAD, 6); - mv.visitMethodInsn(INVOKESTATIC, "com/skcraft/alicefixes/transformers/TransformDislocWand", - "canMine", "(L" + ObfNames.ENTITY_PLAYER +";III)Z"); - Label l1 = new Label(); - mv.visitJumpInsn(IFNE, l1); - Label l2 = new Label(); - mv.visitLabel(l2); - mv.visitInsn(ICONST_1); - mv.visitInsn(IRETURN); - mv.visitLabel(l1); - mv.visitCode(); - } - } - -} diff --git a/alicefixes/src/com/skcraft/alicefixes/transformers/TransformElemAxe.java b/alicefixes/src/com/skcraft/alicefixes/transformers/TransformElemAxe.java deleted file mode 100644 index d70f2bd..0000000 --- a/alicefixes/src/com/skcraft/alicefixes/transformers/TransformElemAxe.java +++ /dev/null @@ -1,104 +0,0 @@ -package com.skcraft.alicefixes.transformers; - -import static org.objectweb.asm.Opcodes.*; - -import java.lang.reflect.Method; - -import net.minecraft.entity.player.EntityPlayer; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.event.block.BlockBreakEvent; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassVisitor; -import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.Label; -import org.objectweb.asm.MethodVisitor; - -import com.skcraft.alicefixes.util.ObfNames; - -import cpw.mods.fml.relauncher.IClassTransformer; - -public class TransformElemAxe implements IClassTransformer { - - @Override - public byte[] transform(String name, String transformedName, byte[] bytes) { - - if(name.equals("thaumcraft.common.items.equipment.ItemElementalAxe")) { - ClassReader cr = new ClassReader(bytes); - ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS); - cr.accept(new AxeVisitor(cw), 0); - return cw.toByteArray(); - } - return bytes; - } - - public static boolean canMine(EntityPlayer player, int x, int y, int z) { - try { - Method m = player.getClass() - .getDeclaredMethod("getBukkitEntity", new Class[] {}); - org.bukkit.entity.Entity ent = - (org.bukkit.entity.Entity)m.invoke(player); - if ((ent instanceof Player)) { - Player bukkitPlayer = (Player)ent; - org.bukkit.World bukkitWorld = bukkitPlayer.getWorld(); - BlockBreakEvent breakEv = new BlockBreakEvent( - bukkitWorld.getBlockAt(x, y, z), bukkitPlayer); - Bukkit.getPluginManager().callEvent(breakEv); - if (breakEv.isCancelled()) { - return false; - } - breakEv.setCancelled(true); - } - } - catch(Exception e) { - e.printStackTrace(); - } - return true; - } - - class AxeVisitor extends ClassVisitor { - - public AxeVisitor(ClassVisitor cv) { - super(ASM4, cv); - } - - @Override - public MethodVisitor visitMethod(int access, String name, String desc, - String signature, String[] exceptions) { - - if(name.equals("breakFurthestBlock")) { - return new BreakFurthestBlockVisitor(super.visitMethod(access, name, - desc, signature, exceptions)); - } - return super.visitMethod(access, name, desc, signature, - exceptions); - } - } - - class BreakFurthestBlockVisitor extends MethodVisitor { - - public BreakFurthestBlockVisitor(MethodVisitor mv) { - super(ASM4, mv); - } - - @Override - public void visitCode() { - Label l0 = new Label(); - mv.visitLabel(l0); - mv.visitVarInsn(ALOAD, 7); - mv.visitVarInsn(ILOAD, 3); - mv.visitVarInsn(ILOAD, 4); - mv.visitVarInsn(ILOAD, 5); - mv.visitMethodInsn(INVOKESTATIC, "com/skcraft/alicefixes/transformers/TransformElemAxe", - "canMine", "(L" + ObfNames.ENTITY_PLAYER +";III)Z"); - Label l1 = new Label(); - mv.visitJumpInsn(IFNE, l1); - Label l2 = new Label(); - mv.visitLabel(l2); - mv.visitInsn(RETURN); - mv.visitLabel(l1); - mv.visitCode(); - } - } -} diff --git a/alicefixes/src/com/skcraft/alicefixes/transformers/TransformElemShovel.java b/alicefixes/src/com/skcraft/alicefixes/transformers/TransformElemShovel.java deleted file mode 100644 index 52274ae..0000000 --- a/alicefixes/src/com/skcraft/alicefixes/transformers/TransformElemShovel.java +++ /dev/null @@ -1,140 +0,0 @@ -package com.skcraft.alicefixes.transformers; - -import static org.objectweb.asm.Opcodes.*; - -import java.lang.reflect.Method; - -import net.minecraft.entity.EntityLiving; -import net.minecraft.entity.player.EntityPlayer; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.event.block.BlockBreakEvent; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassVisitor; -import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.Label; -import org.objectweb.asm.MethodVisitor; - -import com.skcraft.alicefixes.util.ObfNames; - -import cpw.mods.fml.relauncher.IClassTransformer; - -public class TransformElemShovel implements IClassTransformer { - - @Override - public byte[] transform(String name, String transformedName, byte[] bytes) { - - if(name.equals("thaumcraft.common.items.equipment.ItemElementalShovel")) { - ClassReader cr = new ClassReader(bytes); - ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS); - cr.accept(new ShovelVisitor(cw), 0); - return cw.toByteArray(); - } - return bytes; - } - - public static boolean canMine(EntityLiving entity, int x, int y, int z) { - if(entity instanceof EntityPlayer) { - EntityPlayer player = (EntityPlayer)entity; - try { - Method m = player.getClass() - .getDeclaredMethod("getBukkitEntity", new Class[] {}); - org.bukkit.entity.Entity ent = - (org.bukkit.entity.Entity)m.invoke(player); - if ((ent instanceof Player)) { - Player bukkitPlayer = (Player)ent; - org.bukkit.World bukkitWorld = bukkitPlayer.getWorld(); - BlockBreakEvent breakEv = new BlockBreakEvent( - bukkitWorld.getBlockAt(x, y, z), bukkitPlayer); - Bukkit.getPluginManager().callEvent(breakEv); - if (breakEv.isCancelled()) { - return false; - } - breakEv.setCancelled(true); - } - } - catch(Exception e) { - e.printStackTrace(); - } - } - return true; - } - - class ShovelVisitor extends ClassVisitor { - - public ShovelVisitor(ClassVisitor cv) { - super(ASM4, cv); - } - - @Override - public MethodVisitor visitMethod(int access, String name, String desc, - String signature, String[] exceptions) { - - if(name.equals("func_77648_a")) { - return new OnItemUseVisitor(super.visitMethod(access, name, - desc, signature, exceptions)); - } else if(name.equals("func_77660_a")) { - return new OnBlockDestroyedVisitor(super.visitMethod(access, name, - desc, signature, exceptions)); - } - return super.visitMethod(access, name, desc, signature, - exceptions); - } - } - - class OnItemUseVisitor extends MethodVisitor { - - public OnItemUseVisitor(MethodVisitor mv) { - super(ASM4, mv); - } - - @Override - public void visitCode() { - Label l0 = new Label(); - mv.visitLabel(l0); - mv.visitVarInsn(ALOAD, 2); - mv.visitVarInsn(ILOAD, 4); - mv.visitVarInsn(ILOAD, 5); - mv.visitVarInsn(ILOAD, 6); - mv.visitMethodInsn(INVOKESTATIC, "com/skcraft/alicefixes/transformers/TransformElemShovel", - "canMine", "(L" + ObfNames.ENTITY_LIVING +";III)Z"); - Label l1 = new Label(); - mv.visitJumpInsn(IFNE, l1); - Label l2 = new Label(); - mv.visitLabel(l2); - mv.visitInsn(ICONST_0); - mv.visitInsn(IRETURN); - mv.visitLabel(l1); - mv.visitCode(); - } - } - - class OnBlockDestroyedVisitor extends MethodVisitor { - - public OnBlockDestroyedVisitor(MethodVisitor mv) { - super(ASM4, mv); - } - - @Override - public void visitCode() { - Label l0 = new Label(); - mv.visitLabel(l0); - mv.visitVarInsn(ALOAD, 7); - mv.visitVarInsn(ILOAD, 4); - mv.visitVarInsn(ILOAD, 5); - mv.visitVarInsn(ILOAD, 6); - mv.visitMethodInsn(INVOKESTATIC, "com/skcraft/alicefixes/transformers/TransformElemShovel", - "canMine", "(L" + ObfNames.ENTITY_LIVING + ";III)Z"); - Label l1 = new Label(); - mv.visitJumpInsn(IFNE, l1); - Label l2 = new Label(); - mv.visitLabel(l2); - mv.visitInsn(ICONST_0); - mv.visitInsn(IRETURN); - mv.visitLabel(l1); - mv.visitCode(); - } - } - -} diff --git a/alicefixes/src/com/skcraft/alicefixes/transformers/TransformExcWand.java b/alicefixes/src/com/skcraft/alicefixes/transformers/TransformExcWand.java deleted file mode 100644 index 8297f42..0000000 --- a/alicefixes/src/com/skcraft/alicefixes/transformers/TransformExcWand.java +++ /dev/null @@ -1,117 +0,0 @@ -package com.skcraft.alicefixes.transformers; - -import static org.objectweb.asm.Opcodes.*; - -import java.lang.reflect.Method; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.MovingObjectPosition; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.event.block.BlockBreakEvent; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassVisitor; -import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.Label; -import org.objectweb.asm.MethodVisitor; - -import com.skcraft.alicefixes.util.ObfNames; - -import cpw.mods.fml.relauncher.IClassTransformer; - -public class TransformExcWand implements IClassTransformer { - - @Override - public byte[] transform(String name, String transformedName, byte[] bytes) { - if(name.equals("thaumcraft.common.items.wands.ItemWandExcavation")) { - ClassReader cr = new ClassReader(bytes); - ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS); - cr.accept(new WandVisitor(cw), 0); - return cw.toByteArray(); - } - return bytes; - } - - public static boolean canMine(EntityPlayer player, MovingObjectPosition pos) { - if(pos != null) { - int xPos = pos.blockX; - int yPos = pos.blockY; - int zPos = pos.blockZ; - - try { - Method m = player.getClass() - .getDeclaredMethod("getBukkitEntity", new Class[] {}); - org.bukkit.entity.Entity ent = - (org.bukkit.entity.Entity)m.invoke(player); - if ((ent instanceof Player)) { - Player bukkitPlayer = (Player)ent; - org.bukkit.World bukkitWorld = bukkitPlayer.getWorld(); - BlockBreakEvent breakEv = new BlockBreakEvent( - bukkitWorld.getBlockAt(xPos, yPos, zPos), bukkitPlayer); - Bukkit.getPluginManager().callEvent(breakEv); - if (breakEv.isCancelled()) { - return false; - } - - breakEv.setCancelled(true); - } - } - catch(Exception e) { - e.printStackTrace(); - } - } - - return true; - } - - class WandVisitor extends ClassVisitor { - - public WandVisitor(ClassVisitor cv) { - super(ASM4, cv); - } - - @Override - public MethodVisitor visitMethod(int access, String name, String desc, - String signature, String[] exceptions) { - - if(name.equals("onUsingItemTick")) { - return new OnUsingItemTickVisitor(super.visitMethod(access, name, desc, - signature, exceptions)); - } - return super.visitMethod(access, name, desc, signature, - exceptions); - } - } - - class OnUsingItemTickVisitor extends MethodVisitor { - - public OnUsingItemTickVisitor(MethodVisitor mv) { - super(ASM4, mv); - } - - @Override - public void visitCode() { - Label l0 = new Label(); - mv.visitLabel(l0); - mv.visitVarInsn(ALOAD, 2); - mv.visitVarInsn(ALOAD, 2); - mv.visitFieldInsn(GETFIELD, ObfNames.ENTITY_PLAYER, ObfNames.WORLD_OBJ, "L" - + ObfNames.WORLD + ";"); - mv.visitVarInsn(ALOAD, 2); - mv.visitInsn(ICONST_0); - mv.visitMethodInsn(INVOKESTATIC, "thaumcraft/common/lib/Utils", - "getTargetBlock", "(L" + ObfNames.WORLD + ";L" + ObfNames.ENTITY_PLAYER - + ";Z)L" + ObfNames.MOV_OBJ_POS + ";"); - mv.visitMethodInsn(INVOKESTATIC, "com/skcraft/alicefixes/transformers/TransformExcWand", - "canMine", "(L" + ObfNames.ENTITY_PLAYER + ";L" + ObfNames.MOV_OBJ_POS + ";)Z"); - Label l1 = new Label(); - mv.visitJumpInsn(IFNE, l1); - Label l2 = new Label(); - mv.visitLabel(l2); - mv.visitInsn(RETURN); - mv.visitLabel(l1); - mv.visitCode(); - } - } -} diff --git a/alicefixes/src/com/skcraft/alicefixes/transformers/TransformMiningLaser.java b/alicefixes/src/com/skcraft/alicefixes/transformers/TransformMiningLaser.java deleted file mode 100644 index 351e6e7..0000000 --- a/alicefixes/src/com/skcraft/alicefixes/transformers/TransformMiningLaser.java +++ /dev/null @@ -1,130 +0,0 @@ -package com.skcraft.alicefixes.transformers; - -import static org.objectweb.asm.Opcodes.*; - -import java.lang.reflect.Method; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLiving; -import net.minecraft.util.MovingObjectPosition; -import net.minecraft.util.Vec3; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.event.block.BlockBreakEvent; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassVisitor; -import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.Label; -import org.objectweb.asm.MethodVisitor; - -import com.skcraft.alicefixes.util.ObfNames; - -import cpw.mods.fml.relauncher.IClassTransformer; - -public class TransformMiningLaser implements IClassTransformer { - - @Override - public byte[] transform(String name, String transformedName, byte[] bytes) { - if(name.equals("ic2.core.item.tool.EntityMiningLaser")) { - return handleLaserTransform(bytes); - } - return bytes; - } - - private byte[] handleLaserTransform(byte[] bytes) { - ClassReader cr = new ClassReader(bytes); - ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS); - - cr.accept(new EntityLaserVisitor(cw), 0); - return cw.toByteArray(); - } - - public static boolean canMine(Entity laser, EntityLiving owner) { - Vec3 currentPos = Vec3.createVectorHelper(laser.posX, laser.posY, - laser.posZ); - Vec3 heading = Vec3.createVectorHelper(laser.posX + laser.motionX, - laser.posY + laser.motionY, laser.posZ + laser.motionZ); - MovingObjectPosition pos = laser.worldObj.rayTraceBlocks_do_do( - currentPos, heading, false, true); - - if(pos != null) { - int xPos = pos.blockX; - int yPos = pos.blockY; - int zPos = pos.blockZ; - - try { - Method m = owner.getClass() - .getDeclaredMethod("getBukkitEntity", new Class[] {}); - org.bukkit.entity.Entity ent = - (org.bukkit.entity.Entity)m.invoke(owner); - if ((ent instanceof Player)) { - Player player = (Player)ent; - org.bukkit.World bukkitWorld = player.getWorld(); - BlockBreakEvent breakEv = new BlockBreakEvent( - bukkitWorld.getBlockAt(xPos, yPos, zPos), player); - Bukkit.getPluginManager().callEvent(breakEv); - if (breakEv.isCancelled()) { - return false; - } - - breakEv.setCancelled(true); - } - } - catch(Exception e) { - e.printStackTrace(); - } - } - - return true; - } - - class EntityLaserVisitor extends ClassVisitor { - - public EntityLaserVisitor(ClassVisitor cv) { - super(ASM4, cv); - } - - @Override - public MethodVisitor visitMethod(int access, String name, String desc, - String signature, String[] exceptions) { - - if(name.equals("canMine")) { - return new CanMineVisitor(super.visitMethod(access, name, desc, - signature, exceptions)); - } - return super.visitMethod(access, name, desc, signature, - exceptions); - } - } - - class CanMineVisitor extends MethodVisitor { - - public CanMineVisitor(MethodVisitor mv) { - super(ASM4, mv); - } - - @Override - public void visitCode() { - Label l0 = new Label(); - mv.visitLabel(l0); - mv.visitVarInsn(ALOAD, 0); - mv.visitVarInsn(ALOAD, 0); - mv.visitFieldInsn(GETFIELD, "ic2/core/item/tool/EntityMiningLaser", - "owner", "L" + ObfNames.ENTITY_LIVING + ";"); - mv.visitMethodInsn(INVOKESTATIC, - "com/skcraft/alicefixes/transformers/TransformMiningLaser", - "canMine", - "(L" + ObfNames.ENTITY + ";L" - + ObfNames.ENTITY_LIVING + ";)Z"); - Label l1 = new Label(); - mv.visitJumpInsn(IFNE, l1); - Label l2 = new Label(); - mv.visitLabel(l2); - mv.visitInsn(ICONST_0); - mv.visitInsn(IRETURN); - mv.visitLabel(l1); - mv.visitCode(); - } - } -} diff --git a/alicefixes/src/com/skcraft/alicefixes/transformers/TransformTradeWand.java b/alicefixes/src/com/skcraft/alicefixes/transformers/TransformTradeWand.java deleted file mode 100644 index 74dfff4..0000000 --- a/alicefixes/src/com/skcraft/alicefixes/transformers/TransformTradeWand.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.skcraft.alicefixes.transformers; - -import static org.objectweb.asm.Opcodes.*; - -import java.lang.reflect.Method; - -import net.minecraft.entity.player.EntityPlayer; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.event.block.BlockBreakEvent; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassVisitor; -import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.Label; -import org.objectweb.asm.MethodVisitor; - -import com.skcraft.alicefixes.util.ObfNames; - -import cpw.mods.fml.relauncher.IClassTransformer; - -public class TransformTradeWand implements IClassTransformer { - - @Override - public byte[] transform(String name, String transformedName, byte[] bytes) { - - if(name.equals("thaumcraft.common.items.wands.ItemWandTrade")) { - ClassReader cr = new ClassReader(bytes); - ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS); - cr.accept(new WandVisitor(cw), 0); - return cw.toByteArray(); - } - return bytes; - } - - public static boolean canMine(EntityPlayer player, int x, int y, int z) { - try { - Method m = player.getClass() - .getDeclaredMethod("getBukkitEntity", new Class[] {}); - org.bukkit.entity.Entity ent = - (org.bukkit.entity.Entity)m.invoke(player); - if ((ent instanceof Player)) { - Player bukkitPlayer = (Player)ent; - org.bukkit.World bukkitWorld = bukkitPlayer.getWorld(); - BlockBreakEvent breakEv = new BlockBreakEvent( - bukkitWorld.getBlockAt(x, y, z), bukkitPlayer); - Bukkit.getPluginManager().callEvent(breakEv); - if (breakEv.isCancelled()) { - return false; - } - breakEv.setCancelled(true); - } - } - catch(Exception e) { - e.printStackTrace(); - } - return true; - } - - class WandVisitor extends ClassVisitor { - - public WandVisitor(ClassVisitor cv) { - super(ASM4, cv); - } - - @Override - public MethodVisitor visitMethod(int access, String name, String desc, - String signature, String[] exceptions) { - - if(name.equals("onItemUseFirst")) { - return new OnItemUseFirstVisitor(super.visitMethod(access, name, - desc, signature, exceptions)); - } else if(name.equals("onBlockStartBreak")) { - return new OnBlockStartBreakVisitor(super.visitMethod(access, name, - desc, signature, exceptions)); - } - return super.visitMethod(access, name, desc, signature, - exceptions); - } - } - - class OnItemUseFirstVisitor extends MethodVisitor { - - public OnItemUseFirstVisitor(MethodVisitor mv) { - super(ASM4, mv); - } - - @Override - public void visitCode() { - Label l0 = new Label(); - mv.visitLabel(l0); - mv.visitVarInsn(ALOAD, 2); - mv.visitVarInsn(ILOAD, 4); - mv.visitVarInsn(ILOAD, 5); - mv.visitVarInsn(ILOAD, 6); - mv.visitMethodInsn(INVOKESTATIC, "com/skcraft/alicefixes/transformers/TransformTradeWand", - "canMine", "(L" + ObfNames.ENTITY_PLAYER + ";III)Z"); - Label l1 = new Label(); - mv.visitJumpInsn(IFNE, l1); - Label l2 = new Label(); - mv.visitLabel(l2); - mv.visitInsn(ICONST_0); - mv.visitInsn(IRETURN); - mv.visitLabel(l1); - mv.visitCode(); - } - } - - class OnBlockStartBreakVisitor extends MethodVisitor { - - public OnBlockStartBreakVisitor(MethodVisitor mv) { - super(ASM4, mv); - } - - @Override - public void visitCode() { - Label l0 = new Label(); - mv.visitLabel(l0); - mv.visitVarInsn(ALOAD, 5); - mv.visitVarInsn(ILOAD, 2); - mv.visitVarInsn(ILOAD, 3); - mv.visitVarInsn(ILOAD, 4); - mv.visitMethodInsn(INVOKESTATIC, "com/skcraft/alicefixes/transformers/TransformTradeWand", - "canMine", "(L" + ObfNames.ENTITY_PLAYER + ";III)Z"); - Label l1 = new Label(); - mv.visitJumpInsn(IFNE, l1); - Label l2 = new Label(); - mv.visitLabel(l2); - mv.visitInsn(ICONST_0); - mv.visitInsn(IRETURN); - mv.visitLabel(l1); - mv.visitCode(); - } - } -} diff --git a/alicefixes/src/com/skcraft/alicefixes/transformers/TransformVajra.java b/alicefixes/src/com/skcraft/alicefixes/transformers/TransformVajra.java deleted file mode 100644 index 4656591..0000000 --- a/alicefixes/src/com/skcraft/alicefixes/transformers/TransformVajra.java +++ /dev/null @@ -1,107 +0,0 @@ -package com.skcraft.alicefixes.transformers; - -import static org.objectweb.asm.Opcodes.*; - -import java.lang.reflect.Method; - -import net.minecraft.entity.player.EntityPlayer; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.event.block.BlockBreakEvent; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassVisitor; -import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.Label; -import org.objectweb.asm.MethodVisitor; - -import com.skcraft.alicefixes.util.ObfNames; - -import cpw.mods.fml.relauncher.IClassTransformer; - -public class TransformVajra implements IClassTransformer { - - @Override - public byte[] transform(String name, String transformedName, byte[] bytes) { - - if(name.equals("gravisuite.ItemVajra")) { - ClassReader cr = new ClassReader(bytes); - ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS); - cr.accept(new VajraVisitor(cw), 0); - return cw.toByteArray(); - } - return bytes; - } - - public static boolean canMine(EntityPlayer player, int x, int y, int z) { - try { - Method m = player.getClass() - .getDeclaredMethod("getBukkitEntity", new Class[] {}); - org.bukkit.entity.Entity ent = - (org.bukkit.entity.Entity)m.invoke(player); - if ((ent instanceof Player)) { - Player bukkitPlayer = (Player)ent; - org.bukkit.World bukkitWorld = bukkitPlayer.getWorld(); - BlockBreakEvent breakEv = new BlockBreakEvent( - bukkitWorld.getBlockAt(x, y, z), bukkitPlayer); - Bukkit.getPluginManager().callEvent(breakEv); - if (breakEv.isCancelled()) { - return false; - } - breakEv.setCancelled(true); - } - } - catch(Exception e) { - e.printStackTrace(); - } - return true; - } - - class VajraVisitor extends ClassVisitor { - - public VajraVisitor(ClassVisitor cv) { - super(ASM4, cv); - } - - @Override - public MethodVisitor visitMethod(int access, String name, String desc, - String signature, String[] exceptions) { - - if(name.equals("a") && desc.equals("(L" + ObfNames.ITEM_STACK + ";L" + - ObfNames.ENTITY_PLAYER + ";L" + ObfNames.WORLD + ";IIIIFFF)Z")) { - return new OnItemUseFirstVisitor(super.visitMethod(access, name, - desc, signature, exceptions)); - } - return super.visitMethod(access, name, desc, signature, - exceptions); - } - } - - class OnItemUseFirstVisitor extends MethodVisitor { - - public OnItemUseFirstVisitor(MethodVisitor mv) { - super(ASM4, mv); - } - - @Override - public void visitCode() { - Label l0 = new Label(); - mv.visitLabel(l0); - mv.visitVarInsn(ALOAD, 2); - mv.visitVarInsn(ILOAD, 4); - mv.visitVarInsn(ILOAD, 5); - mv.visitVarInsn(ILOAD, 6); - mv.visitMethodInsn(INVOKESTATIC, "com/skcraft/alicefixes/transformers/TransformVajra", - "canMine", "(L" + ObfNames.ENTITY_PLAYER +";III)Z"); - Label l1 = new Label(); - mv.visitJumpInsn(IFNE, l1); - Label l2 = new Label(); - mv.visitLabel(l2); - mv.visitInsn(ICONST_0); - mv.visitInsn(IRETURN); - mv.visitLabel(l1); - mv.visitCode(); - } - } - -} diff --git a/alicefixes/src/com/skcraft/alicefixes/util/CoordHelper.java b/alicefixes/src/com/skcraft/alicefixes/util/CoordHelper.java deleted file mode 100644 index e713be3..0000000 --- a/alicefixes/src/com/skcraft/alicefixes/util/CoordHelper.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.skcraft.alicefixes.util; - -public class CoordHelper { - - public int x, y, z; - - public CoordHelper(int x, int y, int z) { - this.x = x; - this.y = y; - this.z = z; - } - - public void addFacingAsOffset(int facing) { - switch (facing) - { - case 0: - this.y += 1; - break; - case 1: - this.y -= 1; - break; - case 2: - this.z += 1; - break; - case 3: - this.z -= 1; - break; - case 4: - this.x += 1; - break; - default: - this.x -= 1; - } - } -} diff --git a/alicefixes/src/com/skcraft/alicefixes/util/ObfNames.java b/alicefixes/src/com/skcraft/alicefixes/util/ObfNames.java deleted file mode 100644 index f99d5d7..0000000 --- a/alicefixes/src/com/skcraft/alicefixes/util/ObfNames.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.skcraft.alicefixes.util; - -public class ObfNames { - - public static final String ENTITY_LIVING = "ng"; - public static final String ENTITY = "mp"; - public static final String TILE_ENTITY = "aqp"; - public static final String ENTITY_PLAYER = "sq"; - public static final String WORLD = "aab"; - public static final String MOV_OBJ_POS = "ara"; - public static final String ITEM_STACK = "wm"; - - // Srgname for worldobj - public static final String WORLD_OBJ = "field_70170_p"; -} diff --git a/build.xml b/build.xml index 3534263..46a08db 100644 --- a/build.xml +++ b/build.xml @@ -7,11 +7,12 @@ - - - + + + + @@ -21,6 +22,9 @@ + + + @@ -33,7 +37,8 @@ - + + @@ -46,6 +51,7 @@ + @@ -53,7 +59,7 @@ - + @@ -76,7 +82,9 @@ - + + + @@ -87,6 +95,7 @@ + diff --git a/src/main/java/com/skcraft/alicefixes/AFListener.java b/src/main/java/com/skcraft/alicefixes/AFListener.java new file mode 100644 index 0000000..253c843 --- /dev/null +++ b/src/main/java/com/skcraft/alicefixes/AFListener.java @@ -0,0 +1,25 @@ +package com.skcraft.alicefixes; + +import com.skcraft.alicefixes.util.ASMHelper; +import ic2.api.event.LaserEvent.LaserExplodesEvent; +import ic2.api.event.LaserEvent.LaserHitsBlockEvent; +import net.minecraftforge.event.ForgeSubscribe; + +public class AFListener { + + @ForgeSubscribe + public void onLaserHitBlock(LaserHitsBlockEvent evt) { + if(!ASMHelper.canMine(evt.owner, null, evt.x, evt.y, evt.z)) { + evt.lasershot.setDead(); + evt.setCanceled(true); + } + } + + @ForgeSubscribe + public void onLaserExplode(LaserExplodesEvent evt) { + if(!ASMHelper.canMine(evt.owner, null, (int)evt.lasershot.posX, (int)evt.lasershot.posY, (int)evt.lasershot.posZ)) { + evt.lasershot.setDead(); + evt.setCanceled(true); + } + } +} diff --git a/src/main/java/com/skcraft/alicefixes/AliceFixes.java b/src/main/java/com/skcraft/alicefixes/AliceFixes.java new file mode 100644 index 0000000..66a8b8d --- /dev/null +++ b/src/main/java/com/skcraft/alicefixes/AliceFixes.java @@ -0,0 +1,16 @@ +package com.skcraft.alicefixes; + +import cpw.mods.fml.common.Mod; +import cpw.mods.fml.common.Mod.EventHandler; +import cpw.mods.fml.common.event.FMLPostInitializationEvent; +import net.minecraftforge.common.MinecraftForge; + +@Mod(modid = "com.skcraft.alicefixes", name = "AliceFixes", version = "1.2.0") +public class AliceFixes { + + @EventHandler + public void postInit(FMLPostInitializationEvent evt) { + MinecraftForge.EVENT_BUS.register(new AFListener()); + } + +} diff --git a/src/main/java/com/skcraft/alicefixes/AliceTransformer.java b/src/main/java/com/skcraft/alicefixes/AliceTransformer.java new file mode 100644 index 0000000..50157fd --- /dev/null +++ b/src/main/java/com/skcraft/alicefixes/AliceTransformer.java @@ -0,0 +1,33 @@ +package com.skcraft.alicefixes; + +import com.skcraft.alicefixes.transformers.TransformTools; +import com.skcraft.alicefixes.transformers.TransformExcavationWand; +import com.skcraft.alicefixes.transformers.TransformTradeWand; +import cpw.mods.fml.common.FMLLog; +import net.minecraft.launchwrapper.IClassTransformer; + +import java.util.logging.Level; + +public class AliceTransformer implements IClassTransformer { + + private final IClassTransformer[] transformers = { + new TransformExcavationWand(), + new TransformTradeWand(), + new TransformTools() + }; + + @Override + public byte[] transform(String name, String transformedName, byte[] bytes) { + if(bytes == null) { + return bytes; + } + + for(IClassTransformer transformer : transformers) { + bytes = transformer.transform(name, transformedName, bytes); + if(bytes == null) + FMLLog.log(Level.SEVERE, "Transformer " + transformer.getClass().getCanonicalName() + " has corrupted class " + name); + } + + return bytes; + } +} diff --git a/alicefixes/src/com/skcraft/alicefixes/LoadingPlugin.java b/src/main/java/com/skcraft/alicefixes/LoadingPlugin.java similarity index 83% rename from alicefixes/src/com/skcraft/alicefixes/LoadingPlugin.java rename to src/main/java/com/skcraft/alicefixes/LoadingPlugin.java index 4cb8647..46f60db 100644 --- a/alicefixes/src/com/skcraft/alicefixes/LoadingPlugin.java +++ b/src/main/java/com/skcraft/alicefixes/LoadingPlugin.java @@ -1,11 +1,10 @@ package com.skcraft.alicefixes; -import java.util.Map; - +import com.skcraft.alicefixes.util.ASMHelper; import cpw.mods.fml.relauncher.IFMLLoadingPlugin; -import cpw.mods.fml.relauncher.IFMLLoadingPlugin.TransformerExclusions; -@TransformerExclusions("com.skcraft.alicefixes") +import java.util.Map; + public class LoadingPlugin implements IFMLLoadingPlugin { @Override diff --git a/src/main/java/com/skcraft/alicefixes/transformers/TransformExcavationWand.java b/src/main/java/com/skcraft/alicefixes/transformers/TransformExcavationWand.java new file mode 100644 index 0000000..13057e1 --- /dev/null +++ b/src/main/java/com/skcraft/alicefixes/transformers/TransformExcavationWand.java @@ -0,0 +1,70 @@ +package com.skcraft.alicefixes.transformers; + +import static org.objectweb.asm.Opcodes.*; + +import com.skcraft.alicefixes.util.ASMHelper; +import net.minecraft.launchwrapper.IClassTransformer; +import org.objectweb.asm.*; + +import static org.objectweb.asm.Opcodes.ASM4; + +public class TransformExcavationWand implements IClassTransformer { + + @Override + public byte[] transform(String name, String transformedName, byte[] bytes) { + + if(name.equals("thaumcraft.common.items.wands.foci.ItemFocusExcavation")) { + ClassReader cr = new ClassReader(bytes); + ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS); + cr.accept(new WandVisitor(cw), 0); + return cw.toByteArray(); + } + return bytes; + } + + class WandVisitor extends ClassVisitor { + public WandVisitor(ClassVisitor cv) { + super(ASM4, cv); + } + + @Override + public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { + + if(name.equals("onUsingFocusTick")) { + return new OnUsingFocusTickVisitor(super.visitMethod(access, name, + desc, signature, exceptions)); + } + return super.visitMethod(access, name, desc, signature, + exceptions); + } + } + + class OnUsingFocusTickVisitor extends MethodVisitor { + public OnUsingFocusTickVisitor(MethodVisitor mv) { + super(ASM4, mv); + } + + @Override + public void visitCode() { + Label l0 = new Label(); + mv.visitLabel(l0); + mv.visitVarInsn(ALOAD, 2); + mv.visitVarInsn(ALOAD, 2); + mv.visitFieldInsn(GETFIELD, ASMHelper.getObf("EntityPlayer"), ASMHelper.getObf("WorldObj"), "L" + ASMHelper.getObf("World") + ";"); + mv.visitVarInsn(ALOAD, 2); + mv.visitInsn(ICONST_0); + mv.visitMethodInsn(INVOKESTATIC, "thaumcraft/common/lib/Utils", "getTargetBlock", "(L" + ASMHelper.getObf("World") + ";L" + ASMHelper.getObf("Entity") + ";Z)L" + ASMHelper.getObf("MovingObjectPosition") + ";"); + mv.visitInsn(ICONST_0); + mv.visitInsn(ICONST_0); + mv.visitInsn(ICONST_0); + mv.visitMethodInsn(INVOKESTATIC, "com/skcraft/alicefixes/util/ASMHelper", "canMine", "(L" + ASMHelper.getObf("EntityLivingBase") + ";Ljava/lang/Object;III)Z"); + Label l1 = new Label(); + mv.visitJumpInsn(IFNE, l1); + Label l2 = new Label(); + mv.visitLabel(l2); + mv.visitInsn(RETURN); + mv.visitLabel(l1); + mv.visitCode(); + } + } +} diff --git a/src/main/java/com/skcraft/alicefixes/transformers/TransformTools.java b/src/main/java/com/skcraft/alicefixes/transformers/TransformTools.java new file mode 100644 index 0000000..7c3c33b --- /dev/null +++ b/src/main/java/com/skcraft/alicefixes/transformers/TransformTools.java @@ -0,0 +1,63 @@ +package com.skcraft.alicefixes.transformers; + +import com.skcraft.alicefixes.util.ASMHelper; +import net.minecraft.launchwrapper.IClassTransformer; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassVisitor; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.MethodVisitor; + +import static org.objectweb.asm.Opcodes.ASM4; + +public class TransformTools implements IClassTransformer { + + @Override + public byte[] transform(String name, String transformedName, byte[] bytes) { + + if(name.equals("thaumcraft.common.items.equipment.ItemElementalAxe") || + name.equals("thaumcraft.common.items.equipment.ItemElementalShovel") || + name.equals("gravisuite.ItemVajra")) { + ClassReader cr = new ClassReader(bytes); + ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS); + cr.accept(new ToolVisitor(cw), 0); + return cw.toByteArray(); + } + return bytes; + } + + class ToolVisitor extends ClassVisitor { + public ToolVisitor(ClassVisitor cv) { + super(ASM4, cv); + } + + @Override + public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { + + if(name.equals("func_77648_a") || name.equals("func_77660_a") || (name.equals("a") && + desc.equals("(L" + ASMHelper.getObf("ItemStack") + ";L" + ASMHelper.getObf("EntityPlayer") + + ";L" + ASMHelper.getObf("World") + ";IIIIFFF)Z"))) { + return new ToolMethodVisitor(super.visitMethod(access, name, desc, signature, exceptions), name.equals("func_77660_a") ? false : true); + } + return super.visitMethod(access, name, desc, signature, exceptions); + } + } + + class ToolMethodVisitor extends MethodVisitor { + + boolean onBlockDestroyed; + + public ToolMethodVisitor(MethodVisitor mv, boolean onBlockDestroyed) { + super(ASM4, mv); + this.onBlockDestroyed = onBlockDestroyed; + } + + @Override + public void visitCode() { + if(onBlockDestroyed) { + ASMHelper.injectCodeBoolXYZ(mv, 2, 4, 5, 6); + } else { + ASMHelper.injectCodeBoolXYZ(mv, 7, 4, 5, 6); + } + } + } +} diff --git a/src/main/java/com/skcraft/alicefixes/transformers/TransformTradeWand.java b/src/main/java/com/skcraft/alicefixes/transformers/TransformTradeWand.java new file mode 100644 index 0000000..88310fb --- /dev/null +++ b/src/main/java/com/skcraft/alicefixes/transformers/TransformTradeWand.java @@ -0,0 +1,67 @@ +package com.skcraft.alicefixes.transformers; + +import static org.objectweb.asm.Opcodes.*; + +import com.skcraft.alicefixes.util.ASMHelper; +import net.minecraft.launchwrapper.IClassTransformer; +import org.objectweb.asm.*; + +import static org.objectweb.asm.Opcodes.ASM4; + +public class TransformTradeWand implements IClassTransformer { + + @Override + public byte[] transform(String name, String transformedName, byte[] bytes) { + + if(name.equals("thaumcraft.common.items.wands.foci.ItemFocusTrade")) { + ClassReader cr = new ClassReader(bytes); + ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS); + cr.accept(new WandVisitor(cw), 0); + return cw.toByteArray(); + } + return bytes; + } + + class WandVisitor extends ClassVisitor { + public WandVisitor(ClassVisitor cv) { + super(ASM4, cv); + } + + @Override + public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { + + if(name.equals("onFocusRightClick")) { + return new OnFocusRightClickVisitor(super.visitMethod(access, name, + desc, signature, exceptions)); + } + return super.visitMethod(access, name, desc, signature, + exceptions); + } + } + + class OnFocusRightClickVisitor extends MethodVisitor { + public OnFocusRightClickVisitor(MethodVisitor mv) { + super(ASM4, mv); + } + + @Override + public void visitCode() { + Label l0 = new Label(); + mv.visitLabel(l0); + mv.visitVarInsn(ALOAD, 3); + mv.visitVarInsn(ALOAD, 4); + mv.visitInsn(ICONST_0); + mv.visitInsn(ICONST_0); + mv.visitInsn(ICONST_0); + mv.visitMethodInsn(INVOKESTATIC, "com/skcraft/alicefixes/util/ASMHelper", "canMine", + "(L" + ASMHelper.getObf("EntityLivingBase") + ";Ljava/lang/Object;III)Z"); + Label l1 = new Label(); + mv.visitJumpInsn(IFNE, l1); + Label l2 = new Label(); + mv.visitLabel(l2); + mv.visitVarInsn(ALOAD, 1); + mv.visitInsn(ARETURN); + mv.visitLabel(l1); + } + } +} diff --git a/src/main/java/com/skcraft/alicefixes/util/ASMHelper.java b/src/main/java/com/skcraft/alicefixes/util/ASMHelper.java new file mode 100644 index 0000000..6959fbb --- /dev/null +++ b/src/main/java/com/skcraft/alicefixes/util/ASMHelper.java @@ -0,0 +1,105 @@ +package com.skcraft.alicefixes.util; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.block.BlockBreakEvent; +import org.objectweb.asm.Label; +import org.objectweb.asm.MethodVisitor; + +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +import static org.objectweb.asm.Opcodes.*; + +public class ASMHelper { + + public static final Map mappings = new HashMap(); + + public static boolean canMine(EntityLivingBase player, Object obj, int x, int y, int z) { + if(player == null) return true; + + if(obj != null) { + if(obj instanceof MovingObjectPosition) { + MovingObjectPosition pos = (MovingObjectPosition)obj; + x = pos.blockX; + y = pos.blockY; + z = pos.blockZ; + } + } + + if(!fireEvent(player, x, y, z)) { + return false; + } + + return true; + } + + private static boolean fireEvent(EntityLivingBase player, int x, int y, int z) { + try { + Method m = player.getClass().getDeclaredMethod("getBukkitEntity"); + org.bukkit.entity.Entity ent = (org.bukkit.entity.Entity)m.invoke(player); + if(ent instanceof Player) { + Player bukkitPlayer = (Player)ent; + org.bukkit.World bukkitWorld = bukkitPlayer.getWorld(); + BlockBreakEvent breakEvt = new BlockBreakEvent(bukkitWorld.getBlockAt(x, y, z), bukkitPlayer); + Bukkit.getPluginManager().callEvent(breakEvt); + if(breakEvt.isCancelled()) { + return false; + } + breakEvt.setCancelled(true); + } + } catch(Exception e) { + e.printStackTrace(); + } + return true; + } + + /** + * Should be used with methods that return a boolean value and have x, y, and z coordinates of the block readily available. + * + * @param mv + * @param entityVar + * @param xVar + * @param yVar + * @param zVar + */ + public static void injectCodeBoolXYZ(MethodVisitor mv, int entityVar, int xVar, int yVar, int zVar) { + Label l0 = new Label(); + mv.visitLabel(l0); + mv.visitVarInsn(ALOAD, entityVar); + mv.visitInsn(ACONST_NULL); + mv.visitVarInsn(ILOAD, xVar); + mv.visitVarInsn(ILOAD, yVar); + mv.visitVarInsn(ILOAD, zVar); + mv.visitMethodInsn(INVOKESTATIC, "com/skcraft/alicefixes/util/ASMHelper", + "canMine", "(L" + ASMHelper.getObf("EntityLivingBase") + ";Ljava/lang/Object;III)Z"); + Label l1 = new Label(); + mv.visitJumpInsn(IFNE, l1); + Label l2 = new Label(); + mv.visitLabel(l2); + mv.visitInsn(ICONST_0); + mv.visitInsn(IRETURN); + mv.visitLabel(l1); + mv.visitCode(); + } + + public static String getObf(String key) { + return mappings.get(key); + } + + static { + mappings.put("EntityPlayer", "uf"); + mappings.put("Entity", "nn"); + mappings.put("MovingObjectPosition", "ata"); + mappings.put("World", "abw"); + mappings.put("ItemStack", "ye"); + mappings.put("EntityLivingBase", "of"); + mappings.put("WorldObj", "field_70170_p"); + } +}