Last active
August 29, 2015 14:05
-
-
Save thomas15v/752f5c74ad28d4e254f2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import mcpc.patchengine.api.IPatch; | |
| import mcpc.patchengine.asm.util.ClassUtil; | |
| import mcpc.patchengine.asm.util.MethodUtil; | |
| import mcpc.patchengine.asm.util.NavigationUtil; | |
| import mcpc.patchengine.common.Configuration; | |
| import mcpc.patchengine.common.Constants; | |
| import org.objectweb.asm.Opcodes; | |
| import org.objectweb.asm.tree.*; | |
| /** | |
| * Created by thomas on 8/7/2014. | |
| */ | |
| public class RedPowerFix implements IPatch { | |
| private String classname = "com.eloraam.redpower.core.CoreLib"; | |
| @Override | |
| public String[] getClassNames() { | |
| return new String[]{classname}; | |
| } | |
| @Override | |
| public void loadConfigurations(Configuration configuration) { | |
| } | |
| @Override | |
| public void transform(String s, ClassNode classNode) { | |
| if (s.equalsIgnoreCase(classname)) { | |
| MethodNode method = ClassUtil.getMethod(classNode, "compareItemStack", String.format("(Lur;Lur;)I", new Object[] { Constants.ItemStackClass, Constants.ItemStackClass })); | |
| if (method == null) { | |
| System.out.println("[PatchEngine - Redpower2] A LibCore class Without this methode has no reason of exist. Crash Bitch!! "); | |
| return; | |
| } | |
| LabelNode label = NavigationUtil.getPreviousLabel(method.instructions, method.instructions.size() - 1); | |
| InsnList instructions = new InsnList(); | |
| //ASM code (- is to remove and + is to add code | |
| /* - iconst_0 | |
| - ireturn | |
| + aload_0 | |
| + invokevirtual ur.o() //Something like this | |
| + ifeq 63 | |
| + iconst_m1 | |
| + ireturn | |
| + iconst_0 | |
| + ireturn | |
| */ | |
| //psudo code (Compiled with normal minecraf (paramUr1 is a itemstack) | |
| /* | |
| if (paramUr1.o()) { | |
| return -1; | |
| } | |
| */ | |
| //psudo code (workspace) | |
| /* | |
| if (paramUr1.hasTagCompound()) { | |
| return -1; | |
| } | |
| */ | |
| //redpower2 code (original) | |
| /* | |
| public static int compareItemStack(ur paramUr1, ur paramUr2) | |
| { | |
| if (paramUr1.c != paramUr2.c) { | |
| return paramUr1.c - paramUr2.c; | |
| } | |
| if (paramUr1.j() == paramUr2.j()) { | |
| return 0; | |
| } | |
| if (paramUr1.b().l()) { | |
| return paramUr1.j() - paramUr2.j(); | |
| } | |
| return 0; | |
| } | |
| */ | |
| //redpower2 code (How i want it) | |
| /* | |
| public static int compareItemStack(ur paramUr1, ur paramUr2) | |
| { | |
| if (paramUr1.c != paramUr2.c) { | |
| return paramUr1.c - paramUr2.c; | |
| } | |
| if (paramUr1.j() == paramUr2.j()) { | |
| return 0; | |
| } | |
| if (paramUr1.b().l()) { | |
| return paramUr1.j() - paramUr2.j(); | |
| } | |
| if (paramUr1.o()) { | |
| return -1; | |
| } | |
| return 0; | |
| } | |
| */ | |
| instructions.add( new VarInsnNode(Opcodes.ALOAD, 0)); | |
| instructions.add( new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "ur", "o", "()Z") ); | |
| LabelNode l3 = new LabelNode(); | |
| instructions.add( new JumpInsnNode(Opcodes.IFEQ, l3) ); | |
| instructions.add( new InsnNode(Opcodes.ICONST_M1) ); | |
| instructions.add( new InsnNode(Opcodes.IRETURN)); | |
| instructions.add( l3 ); | |
| method.instructions.insert(MethodUtil.getLastLabel(method), instructions); | |
| System.out.println("[PatchEngine - Redpower2] Fixed ItemStack Compare methode"); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment