Commit f7711cd7abe151211784b0d0abce536d6cd746f5
1 parent
f709bce8
adding ProfilingHandlerList, some refactoring and minor fixes
Showing
10 changed files
with
483 additions
and
83 deletions
.classpath
... | ... | @@ -18,7 +18,7 @@ |
18 | 18 | <classpathentry exported="true" kind="lib" path="/Client/jars/libraries/net/java/jinput/jinput/2.0.5/jinput-2.0.5.jar"/> |
19 | 19 | <classpathentry exported="true" kind="lib" path="/Client/jars/libraries/com/mojang/authlib/1.5.17/authlib-1.5.17.jar"/> |
20 | 20 | <classpathentry exported="true" kind="lib" path="/Client/jars/libraries/org/lwjgl/lwjgl/lwjgl/2.9.1/lwjgl-2.9.1.jar"/> |
21 | - <classpathentry exported="true" kind="lib" path="lib/asm-debug-all-5.0.3.jar" sourcepath="/ASM/src"/> | |
21 | + <classpathentry exported="true" kind="lib" path="lib/asm-debug-all-5.0.3.jar"/> | |
22 | 22 | <classpathentry exported="true" kind="lib" path="/Client/jars/libraries/org/lwjgl/lwjgl/lwjgl_util/2.9.1/lwjgl_util-2.9.1.jar"/> |
23 | 23 | <classpathentry exported="true" kind="lib" path="/Client/jars/libraries/com/mojang/realms/1.5.5/realms-1.5.5.jar"/> |
24 | 24 | <classpathentry kind="output" path="bin"/> | ... | ... |
debug/obfuscation.properties
... | ... | @@ -19,6 +19,7 @@ field_147712_ad=shaderResourceLocations |
19 | 19 | field_147713_ae=shaderIndex |
20 | 20 | field_175083_ad=useShader |
21 | 21 | field_149528_b=view |
22 | +field_70163_u=posY | |
22 | 23 | func_148833_a=processPacket |
23 | 24 | func_71411_J=runGameLoop |
24 | 25 | func_71407_l=runTick |
... | ... | @@ -60,4 +61,5 @@ func_147346_a=processPlayerBlockPlacement |
60 | 61 | func_175087_a=handleAnimation |
61 | 62 | func_147345_a=processPlayerDigging |
62 | 63 | func_71190_q=updateTimeLightAndEntities |
63 | -func_180031_a=checkThreadAndEnqueue | |
64 | 64 | \ No newline at end of file |
65 | +func_180031_a=checkThreadAndEnqueue | |
66 | +func_147347_a=processPlayer | |
65 | 67 | \ No newline at end of file | ... | ... |
java/client/com/mumfrey/liteloader/client/LiteLoaderEventBrokerClient.java
... | ... | @@ -19,6 +19,7 @@ import net.minecraft.util.Timer; |
19 | 19 | import org.lwjgl.input.Mouse; |
20 | 20 | |
21 | 21 | import com.mumfrey.liteloader.*; |
22 | +import com.mumfrey.liteloader.client.overlays.IEntityRenderer; | |
22 | 23 | import com.mumfrey.liteloader.client.overlays.IMinecraft; |
23 | 24 | import com.mumfrey.liteloader.common.LoadingProgress; |
24 | 25 | import com.mumfrey.liteloader.core.InterfaceRegistrationDelegate; |
... | ... | @@ -26,6 +27,7 @@ import com.mumfrey.liteloader.core.LiteLoader; |
26 | 27 | import com.mumfrey.liteloader.core.LiteLoaderEventBroker; |
27 | 28 | import com.mumfrey.liteloader.core.event.HandlerList; |
28 | 29 | import com.mumfrey.liteloader.core.event.HandlerList.ReturnLogicOp; |
30 | +import com.mumfrey.liteloader.core.event.ProfilingHandlerList; | |
29 | 31 | import com.mumfrey.liteloader.interfaces.FastIterableDeque; |
30 | 32 | import com.mumfrey.liteloader.launch.LoaderProperties; |
31 | 33 | import com.mumfrey.liteloader.transformers.event.EventInfo; |
... | ... | @@ -62,7 +64,7 @@ public class LiteLoaderEventBrokerClient extends LiteLoaderEventBroker<Minecraft |
62 | 64 | */ |
63 | 65 | private int worldHashCode = 0; |
64 | 66 | |
65 | - private FastIterableDeque<Tickable> tickListeners = new HandlerList<Tickable>(Tickable.class); | |
67 | + private FastIterableDeque<Tickable> tickListeners; | |
66 | 68 | private FastIterableDeque<GameLoopListener> loopListeners = new HandlerList<GameLoopListener>(GameLoopListener.class); |
67 | 69 | private FastIterableDeque<RenderListener> renderListeners = new HandlerList<RenderListener>(RenderListener.class); |
68 | 70 | private FastIterableDeque<PostRenderListener> postRenderListeners = new HandlerList<PostRenderListener>(PostRenderListener.class); |
... | ... | @@ -84,6 +86,7 @@ public class LiteLoaderEventBrokerClient extends LiteLoaderEventBroker<Minecraft |
84 | 86 | LiteLoaderEventBrokerClient.instance = this; |
85 | 87 | |
86 | 88 | this.engineClient = (GameEngineClient)engine; |
89 | + this.tickListeners = new ProfilingHandlerList<Tickable>(Tickable.class, this.engineClient.getProfiler()); | |
87 | 90 | } |
88 | 91 | |
89 | 92 | static LiteLoaderEventBrokerClient getInstance() |
... | ... | @@ -302,6 +305,7 @@ public class LiteLoaderEventBrokerClient extends LiteLoaderEventBroker<Minecraft |
302 | 305 | */ |
303 | 306 | void postRender(float partialTicks, long timeSlice) |
304 | 307 | { |
308 | + ((IEntityRenderer)this.engineClient.getClient().entityRenderer).setupCamera(partialTicks, 0); | |
305 | 309 | this.postRenderListeners.all().onPostRender(partialTicks); |
306 | 310 | } |
307 | 311 | |
... | ... | @@ -377,7 +381,7 @@ public class LiteLoaderEventBrokerClient extends LiteLoaderEventBroker<Minecraft |
377 | 381 | */ |
378 | 382 | void onTick() |
379 | 383 | { |
380 | - this.profiler.startSection("litemods"); | |
384 | + this.profiler.endStartSection("litemods"); | |
381 | 385 | |
382 | 386 | Timer minecraftTimer = ((IMinecraft)this.engine.getClient()).getTimer(); |
383 | 387 | float partialTicks = minecraftTimer.renderPartialTicks; |
... | ... | @@ -408,8 +412,6 @@ public class LiteLoaderEventBrokerClient extends LiteLoaderEventBroker<Minecraft |
408 | 412 | this.worldHashCode = worldHashCode; |
409 | 413 | super.onWorldChanged(minecraft.theWorld); |
410 | 414 | } |
411 | - | |
412 | - this.profiler.endSection(); | |
413 | 415 | } |
414 | 416 | |
415 | 417 | /** | ... | ... |
java/client/com/mumfrey/liteloader/util/ModUtilities.java
... | ... | @@ -43,7 +43,7 @@ public abstract class ModUtilities |
43 | 43 | */ |
44 | 44 | public static boolean fmlIsPresent() |
45 | 45 | { |
46 | - return Obf.fmlIsPresent(); | |
46 | + return ObfuscationUtilities.fmlIsPresent(); | |
47 | 47 | } |
48 | 48 | |
49 | 49 | public static void setWindowSize(int width, int height) |
... | ... | @@ -212,10 +212,12 @@ public abstract class ModUtilities |
212 | 212 | * |
213 | 213 | * @param fieldName Name of field to get, returned unmodified if in debug mode |
214 | 214 | * @return Obfuscated field name if present |
215 | + * @deprecated use ObfuscationUtilities.getObfuscatedFieldName instead | |
215 | 216 | */ |
217 | + @Deprecated | |
216 | 218 | public static String getObfuscatedFieldName(String fieldName, String obfuscatedFieldName, String seargeFieldName) |
217 | 219 | { |
218 | - return Obf.getObfuscatedFieldName(fieldName, obfuscatedFieldName, seargeFieldName); | |
220 | + return ObfuscationUtilities.getObfuscatedFieldName(fieldName, obfuscatedFieldName, seargeFieldName); | |
219 | 221 | } |
220 | 222 | |
221 | 223 | /** |
... | ... | @@ -223,10 +225,12 @@ public abstract class ModUtilities |
223 | 225 | * |
224 | 226 | * @param obf Field to get, returned unmodified if in debug mode |
225 | 227 | * @return Obfuscated field name if present |
228 | + * @deprecated use ObfuscationUtilities.getObfuscatedFieldName instead | |
226 | 229 | */ |
230 | + @Deprecated | |
227 | 231 | public static String getObfuscatedFieldName(Obf obf) |
228 | 232 | { |
229 | - return Obf.getObfuscatedFieldName(obf); | |
233 | + return ObfuscationUtilities.getObfuscatedFieldName(obf); | |
230 | 234 | } |
231 | 235 | |
232 | 236 | @SuppressWarnings("unchecked") | ... | ... |
java/common/com/mumfrey/liteloader/core/event/HandlerList.java
1 | 1 | package com.mumfrey.liteloader.core.event; |
2 | 2 | |
3 | 3 | import java.io.Closeable; |
4 | +import java.io.File; | |
4 | 5 | import java.io.IOException; |
5 | 6 | import java.lang.reflect.Constructor; |
6 | 7 | import java.net.URL; |
... | ... | @@ -17,12 +18,15 @@ import java.util.Set; |
17 | 18 | import net.minecraft.launchwrapper.IClassTransformer; |
18 | 19 | import net.minecraft.launchwrapper.Launch; |
19 | 20 | |
21 | +import org.apache.commons.io.FileUtils; | |
22 | +import org.apache.logging.log4j.core.helpers.Booleans; | |
20 | 23 | import org.objectweb.asm.ClassReader; |
21 | 24 | import org.objectweb.asm.ClassWriter; |
22 | 25 | import org.objectweb.asm.Label; |
23 | 26 | import org.objectweb.asm.Opcodes; |
24 | 27 | import org.objectweb.asm.Type; |
25 | 28 | import org.objectweb.asm.tree.*; |
29 | +import org.objectweb.asm.util.CheckClassAdapter; | |
26 | 30 | |
27 | 31 | import com.mumfrey.liteloader.Priority; |
28 | 32 | import com.mumfrey.liteloader.core.runtime.Obf; |
... | ... | @@ -236,7 +240,7 @@ public class HandlerList<T> extends LinkedList<T> implements FastIterableDeque<T |
236 | 240 | */ |
237 | 241 | protected void bake() |
238 | 242 | { |
239 | - HandlerListClassLoader<T> classLoader = new HandlerListClassLoader<T>(this.type, this.logicOp); | |
243 | + HandlerListClassLoader<T> classLoader = new HandlerListClassLoader<T>(this.type, this.logicOp, this.getDecorator()); | |
240 | 244 | this.bakedHandler = classLoader.newHandler(this); |
241 | 245 | if (classLoader instanceof Closeable) |
242 | 246 | { |
... | ... | @@ -248,6 +252,11 @@ public class HandlerList<T> extends LinkedList<T> implements FastIterableDeque<T |
248 | 252 | } |
249 | 253 | } |
250 | 254 | |
255 | + protected IHandlerListDecorator<T> getDecorator() | |
256 | + { | |
257 | + return null; | |
258 | + } | |
259 | + | |
251 | 260 | /** |
252 | 261 | * Invalidate current baked list |
253 | 262 | */ |
... | ... | @@ -569,6 +578,10 @@ public class HandlerList<T> extends LinkedList<T> implements FastIterableDeque<T |
569 | 578 | { |
570 | 579 | private static final String HANDLER_VAR_PREFIX = "handler$"; |
571 | 580 | |
581 | + public static final boolean DUMP = Booleans.parseBoolean(System.getProperty("liteloader.debug.dump"), false); | |
582 | + | |
583 | + public static final boolean VALIDATE = Booleans.parseBoolean(System.getProperty("liteloader.debug.validate"), false); | |
584 | + | |
572 | 585 | /** |
573 | 586 | * Unique index number, just to ensure no name clashes |
574 | 587 | */ |
... | ... | @@ -590,6 +603,11 @@ public class HandlerList<T> extends LinkedList<T> implements FastIterableDeque<T |
590 | 603 | private final ReturnLogicOp logicOp; |
591 | 604 | |
592 | 605 | /** |
606 | + * Bytecode decorator | |
607 | + */ | |
608 | + private final IHandlerListDecorator<T> decorator; | |
609 | + | |
610 | + /** | |
593 | 611 | * Size of the handler list |
594 | 612 | */ |
595 | 613 | private int size; |
... | ... | @@ -598,12 +616,13 @@ public class HandlerList<T> extends LinkedList<T> implements FastIterableDeque<T |
598 | 616 | * @param type |
599 | 617 | * @param logicOp |
600 | 618 | */ |
601 | - HandlerListClassLoader(Class<T> type, ReturnLogicOp logicOp) | |
619 | + HandlerListClassLoader(Class<T> type, ReturnLogicOp logicOp, IHandlerListDecorator<T> decorator) | |
602 | 620 | { |
603 | 621 | super(new URL[0], Launch.classLoader); |
604 | 622 | this.type = type; |
605 | 623 | this.typeRef = type.getName().replace('.', '/'); |
606 | 624 | this.logicOp = logicOp; |
625 | + this.decorator = decorator; | |
607 | 626 | } |
608 | 627 | |
609 | 628 | /** |
... | ... | @@ -613,6 +632,12 @@ public class HandlerList<T> extends LinkedList<T> implements FastIterableDeque<T |
613 | 632 | public BakedHandlerList<T> newHandler(HandlerList<T> list) |
614 | 633 | { |
615 | 634 | this.size = list.size(); |
635 | + List<T> sortedList = list.getSortedList(); | |
636 | + | |
637 | + if (this.decorator != null) | |
638 | + { | |
639 | + this.decorator.prepare(sortedList); | |
640 | + } | |
616 | 641 | |
617 | 642 | Class<BakedHandlerList<T>> handlerClass = null; |
618 | 643 | |
... | ... | @@ -631,7 +656,7 @@ public class HandlerList<T> extends LinkedList<T> implements FastIterableDeque<T |
631 | 656 | { |
632 | 657 | // Create an instance of the class, populate the entries from the supplied list and return it |
633 | 658 | BakedHandlerList<T> handlerList = this.createInstance(handlerClass); |
634 | - return handlerList.populate(list.getSortedList()); | |
659 | + return handlerList.populate(sortedList); | |
635 | 660 | } |
636 | 661 | catch (InstantiationException ex) |
637 | 662 | { |
... | ... | @@ -650,6 +675,11 @@ public class HandlerList<T> extends LinkedList<T> implements FastIterableDeque<T |
650 | 675 | { |
651 | 676 | try |
652 | 677 | { |
678 | + if (this.decorator != null) | |
679 | + { | |
680 | + return this.decorator.createInstance(handlerClass); | |
681 | + } | |
682 | + | |
653 | 683 | Constructor<BakedHandlerList<T>> ctor = handlerClass.getDeclaredConstructor(); |
654 | 684 | ctor.setAccessible(true); |
655 | 685 | return ctor.newInstance(); |
... | ... | @@ -671,7 +701,7 @@ public class HandlerList<T> extends LinkedList<T> implements FastIterableDeque<T |
671 | 701 | try |
672 | 702 | { |
673 | 703 | // Read the basic class template |
674 | - byte[] bytes = Launch.classLoader.getClassBytes(Obf.BakedHandlerList.name); | |
704 | + byte[] bytes = Launch.classLoader.getClassBytes(this.getTemplate().name); | |
675 | 705 | ClassReader classReader = new ClassReader(bytes); |
676 | 706 | ClassNode classNode = new ClassNode(); |
677 | 707 | classReader.accept(classNode, ClassReader.EXPAND_FRAMES); |
... | ... | @@ -683,8 +713,16 @@ public class HandlerList<T> extends LinkedList<T> implements FastIterableDeque<T |
683 | 713 | ClassWriter classWriter = new ClassWriter(classReader, ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); |
684 | 714 | classNode.accept(classWriter); |
685 | 715 | bytes = classWriter.toByteArray(); |
716 | + | |
717 | + if (HandlerListClassLoader.VALIDATE) | |
718 | + { | |
719 | + classNode.accept(new CheckClassAdapter(new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES))); | |
720 | + } | |
686 | 721 | |
687 | -// classNode.accept(new org.objectweb.asm.util.CheckClassAdapter(new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES))); | |
722 | + if (HandlerListClassLoader.DUMP) | |
723 | + { | |
724 | + FileUtils.writeByteArrayToFile(new File(".classes/" + name.replace('.', '/') + ".class"), bytes); | |
725 | + } | |
688 | 726 | |
689 | 727 | // Delegate to ClassLoader's usual behaviour to load the class we just generated |
690 | 728 | return this.defineClass(name, bytes, 0, bytes.length); |
... | ... | @@ -696,6 +734,16 @@ public class HandlerList<T> extends LinkedList<T> implements FastIterableDeque<T |
696 | 734 | } |
697 | 735 | } |
698 | 736 | |
737 | + private Obf getTemplate() | |
738 | + { | |
739 | + if (this.decorator != null) | |
740 | + { | |
741 | + return this.decorator.getTemplate(); | |
742 | + } | |
743 | + | |
744 | + return Obf.BakedHandlerList; | |
745 | + } | |
746 | + | |
699 | 747 | /** |
700 | 748 | * Perform all class bytecode transformations |
701 | 749 | * |
... | ... | @@ -725,7 +773,7 @@ public class HandlerList<T> extends LinkedList<T> implements FastIterableDeque<T |
725 | 773 | { |
726 | 774 | classNode.access = classNode.access & ~Opcodes.ACC_ABSTRACT; |
727 | 775 | classNode.name = name.replace('.', '/'); |
728 | - classNode.superName = Obf.BakedHandlerList.ref; | |
776 | + classNode.superName = this.getTemplate().ref; | |
729 | 777 | classNode.interfaces.add(this.typeRef); |
730 | 778 | classNode.sourceFile = name.substring(name.lastIndexOf('.') + 1) + ".java"; |
731 | 779 | |
... | ... | @@ -733,6 +781,11 @@ public class HandlerList<T> extends LinkedList<T> implements FastIterableDeque<T |
733 | 781 | { |
734 | 782 | classNode.fields.add(new FieldNode(Opcodes.ACC_PRIVATE, HandlerListClassLoader.HANDLER_VAR_PREFIX + handlerIndex, "L" + this.typeRef + ";", null, null)); |
735 | 783 | } |
784 | + | |
785 | + if (this.decorator != null) | |
786 | + { | |
787 | + this.decorator.populateClass(name, classNode); | |
788 | + } | |
736 | 789 | } |
737 | 790 | |
738 | 791 | /** |
... | ... | @@ -775,12 +828,17 @@ public class HandlerList<T> extends LinkedList<T> implements FastIterableDeque<T |
775 | 828 | if (insn instanceof MethodInsnNode) |
776 | 829 | { |
777 | 830 | MethodInsnNode methodInsn = (MethodInsnNode)insn; |
778 | - if (methodInsn.owner.equals("java/lang/Object")) | |
831 | + if (methodInsn.getOpcode() == Opcodes.INVOKESPECIAL && methodInsn.name.equals(Obf.constructor.name)) | |
779 | 832 | { |
780 | - methodInsn.owner = Obf.BakedHandlerList.ref; | |
833 | + methodInsn.owner = this.getTemplate().ref; | |
781 | 834 | } |
782 | 835 | } |
783 | 836 | } |
837 | + | |
838 | + if (this.decorator != null) | |
839 | + { | |
840 | + this.decorator.processCtor(classNode, method); | |
841 | + } | |
784 | 842 | } |
785 | 843 | |
786 | 844 | /** |
... | ... | @@ -879,6 +937,11 @@ public class HandlerList<T> extends LinkedList<T> implements FastIterableDeque<T |
879 | 937 | method.access = Opcodes.ACC_PUBLIC; |
880 | 938 | this.populateVoidInvokationChain(classNode, method, args, returnType); |
881 | 939 | } |
940 | + | |
941 | + if (this.decorator != null) | |
942 | + { | |
943 | + this.decorator.populateInterfaceMethod(classNode, method); | |
944 | + } | |
882 | 945 | } |
883 | 946 | |
884 | 947 | /** |
... | ... | @@ -963,14 +1026,25 @@ public class HandlerList<T> extends LinkedList<T> implements FastIterableDeque<T |
963 | 1026 | * @param method |
964 | 1027 | * @param args |
965 | 1028 | */ |
966 | - private int invokeHandler(int handlerIndex, ClassNode classNode, MethodNode method, Type[] args) | |
1029 | + private void invokeHandler(int handlerIndex, ClassNode classNode, MethodNode method, Type[] args) | |
967 | 1030 | { |
968 | 1031 | LabelNode lineNumberLabel = new LabelNode(new Label()); |
969 | 1032 | method.instructions.add(lineNumberLabel); |
970 | 1033 | method.instructions.add(new LineNumberNode(100 + handlerIndex, lineNumberLabel)); |
971 | 1034 | method.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); |
972 | 1035 | method.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, classNode.name, HandlerListClassLoader.HANDLER_VAR_PREFIX + handlerIndex, "L" + this.typeRef + ";")); |
973 | - return this.invokeInterfaceMethod(method, args); | |
1036 | + | |
1037 | + if (this.decorator != null) | |
1038 | + { | |
1039 | + this.decorator.preInvokeInterfaceMethod(handlerIndex, classNode, method, args); | |
1040 | + } | |
1041 | + | |
1042 | + this.invokeInterfaceMethod(method, args); | |
1043 | + | |
1044 | + if (this.decorator != null) | |
1045 | + { | |
1046 | + this.decorator.postInvokeInterfaceMethod(handlerIndex, classNode, method, args); | |
1047 | + } | |
974 | 1048 | } |
975 | 1049 | |
976 | 1050 | /** |
... | ... | @@ -979,7 +1053,7 @@ public class HandlerList<T> extends LinkedList<T> implements FastIterableDeque<T |
979 | 1053 | * @param method |
980 | 1054 | * @param args |
981 | 1055 | */ |
982 | - private int invokeInterfaceMethod(MethodNode method, Type[] args) | |
1056 | + private void invokeInterfaceMethod(MethodNode method, Type[] args) | |
983 | 1057 | { |
984 | 1058 | int argNumber = 1; |
985 | 1059 | for (Type type : args) |
... | ... | @@ -989,7 +1063,6 @@ public class HandlerList<T> extends LinkedList<T> implements FastIterableDeque<T |
989 | 1063 | } |
990 | 1064 | |
991 | 1065 | method.instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, this.typeRef, method.name, method.desc, true)); |
992 | - return argNumber; | |
993 | 1066 | } |
994 | 1067 | |
995 | 1068 | /** | ... | ... |
java/common/com/mumfrey/liteloader/core/event/IHandlerListDecorator.java
0 → 100644
1 | +package com.mumfrey.liteloader.core.event; | |
2 | + | |
3 | +import java.util.List; | |
4 | + | |
5 | +import org.objectweb.asm.Type; | |
6 | +import org.objectweb.asm.tree.ClassNode; | |
7 | +import org.objectweb.asm.tree.MethodNode; | |
8 | + | |
9 | +import com.mumfrey.liteloader.core.event.HandlerList.BakedHandlerList; | |
10 | +import com.mumfrey.liteloader.core.runtime.Obf; | |
11 | + | |
12 | +/** | |
13 | + * Essentially a "mini plugin" for HandlerListClassLoader which allows alterations of the generated bytecode | |
14 | + * | |
15 | + * @author Adam Mummery-Smith | |
16 | + * | |
17 | + * @param <T> | |
18 | + */ | |
19 | +public interface IHandlerListDecorator<T> | |
20 | +{ | |
21 | + /** | |
22 | + * Get the template class name | |
23 | + */ | |
24 | + public abstract Obf getTemplate(); | |
25 | + | |
26 | + /** | |
27 | + * Prepare the decorator to accept the specified list of invokees | |
28 | + */ | |
29 | + public abstract void prepare(List<T> sortedList); | |
30 | + | |
31 | + /** | |
32 | + * Create an instance of the handler class | |
33 | + */ | |
34 | + public abstract BakedHandlerList<T> createInstance(Class<BakedHandlerList<T>> handlerClass) throws Exception; | |
35 | + | |
36 | + /** | |
37 | + * Called when populating the classNode | |
38 | + */ | |
39 | + public abstract void populateClass(String name, ClassNode classNode); | |
40 | + | |
41 | + /** | |
42 | + * Called when processing the ctor | |
43 | + */ | |
44 | + public abstract void processCtor(ClassNode classNode, MethodNode method); | |
45 | + | |
46 | + /** | |
47 | + * Called immediately before the interface method invokation bytecode is injected | |
48 | + */ | |
49 | + public abstract void preInvokeInterfaceMethod(int handlerIndex, ClassNode classNode, MethodNode method, Type[] args); | |
50 | + | |
51 | + /** | |
52 | + * Called immediately after the interface method invokation bytecode is injected | |
53 | + */ | |
54 | + public abstract void postInvokeInterfaceMethod(int handlerIndex, ClassNode classNode, MethodNode method, Type[] args); | |
55 | + | |
56 | + /** | |
57 | + * Called at the end of populateInterfaceMethod | |
58 | + */ | |
59 | + public abstract void populateInterfaceMethod(ClassNode classNode, MethodNode method); | |
60 | +} | ... | ... |
java/common/com/mumfrey/liteloader/core/event/ProfilingHandlerList.java
0 → 100644
1 | +package com.mumfrey.liteloader.core.event; | |
2 | + | |
3 | +import java.lang.reflect.Constructor; | |
4 | +import java.util.ArrayList; | |
5 | +import java.util.List; | |
6 | + | |
7 | +import net.minecraft.profiler.Profiler; | |
8 | + | |
9 | +import org.objectweb.asm.Opcodes; | |
10 | +import org.objectweb.asm.Type; | |
11 | +import org.objectweb.asm.tree.ClassNode; | |
12 | +import org.objectweb.asm.tree.InsnNode; | |
13 | +import org.objectweb.asm.tree.LdcInsnNode; | |
14 | +import org.objectweb.asm.tree.MethodInsnNode; | |
15 | +import org.objectweb.asm.tree.MethodNode; | |
16 | +import org.objectweb.asm.tree.VarInsnNode; | |
17 | + | |
18 | +import com.mumfrey.liteloader.api.Listener; | |
19 | +import com.mumfrey.liteloader.core.runtime.Obf; | |
20 | + | |
21 | +/** | |
22 | + * A HandlerList which calls Profiler.beginSection and Profiler.endSection before every invokation | |
23 | + * | |
24 | + * @author Adam Mummery-Smith | |
25 | + * | |
26 | + * @param <T> | |
27 | + */ | |
28 | +public class ProfilingHandlerList<T extends Listener> extends HandlerList<T> | |
29 | +{ | |
30 | + private static final long serialVersionUID = 1L; | |
31 | + | |
32 | + /** | |
33 | + * Profiler to pass in to baked handler lists | |
34 | + */ | |
35 | + private final Profiler profiler; | |
36 | + | |
37 | + /** | |
38 | + * @param type | |
39 | + * @param profiler | |
40 | + */ | |
41 | + public ProfilingHandlerList(Class<T> type, Profiler profiler) | |
42 | + { | |
43 | + super(type); | |
44 | + this.profiler = profiler; | |
45 | + } | |
46 | + | |
47 | + /** | |
48 | + * @param type | |
49 | + * @param logicOp | |
50 | + * @param profiler | |
51 | + */ | |
52 | + public ProfilingHandlerList(Class<T> type, ReturnLogicOp logicOp, Profiler profiler) | |
53 | + { | |
54 | + super(type, logicOp); | |
55 | + this.profiler = profiler; | |
56 | + } | |
57 | + | |
58 | + /** | |
59 | + * @param type | |
60 | + * @param logicOp | |
61 | + * @param sorted | |
62 | + * @param profiler | |
63 | + */ | |
64 | + public ProfilingHandlerList(Class<T> type, ReturnLogicOp logicOp, boolean sorted, Profiler profiler) | |
65 | + { | |
66 | + super(type, logicOp, sorted); | |
67 | + this.profiler = profiler; | |
68 | + } | |
69 | + | |
70 | + /* (non-Javadoc) | |
71 | + * @see com.mumfrey.liteloader.core.event.HandlerList#getDecorator() | |
72 | + */ | |
73 | + @Override | |
74 | + protected IHandlerListDecorator<T> getDecorator() | |
75 | + { | |
76 | + return new ProfilingHandlerListDecorator<T>(this.profiler); | |
77 | + } | |
78 | + | |
79 | + /** | |
80 | + * Decorator which adds the profiler section calls to the invokation lists | |
81 | + */ | |
82 | + static class ProfilingHandlerListDecorator<T extends Listener> implements IHandlerListDecorator<T> | |
83 | + { | |
84 | + private final Profiler profiler; | |
85 | + | |
86 | + private final List<String> names = new ArrayList<String>();; | |
87 | + | |
88 | + protected ProfilingHandlerListDecorator(Profiler profiler) | |
89 | + { | |
90 | + this.profiler = profiler; | |
91 | + } | |
92 | + | |
93 | + /* (non-Javadoc) | |
94 | + * @see com.mumfrey.liteloader.core.event.IHandlerListDecorator#getTemplate() | |
95 | + */ | |
96 | + @Override | |
97 | + public Obf getTemplate() | |
98 | + { | |
99 | + return Obf.BakedProfilingHandlerList; | |
100 | + } | |
101 | + | |
102 | + /* (non-Javadoc) | |
103 | + * @see com.mumfrey.liteloader.core.event.IHandlerListDecorator#prepare(java.util.List) | |
104 | + */ | |
105 | + @Override | |
106 | + public void prepare(List<T> sortedList) | |
107 | + { | |
108 | + this.names.clear(); | |
109 | + | |
110 | + for (Listener l : sortedList) | |
111 | + { | |
112 | + String name = l.getName(); | |
113 | + this.names.add(name != null ? name : l.getClass().getSimpleName()); | |
114 | + } | |
115 | + } | |
116 | + | |
117 | + /* (non-Javadoc) | |
118 | + * @see com.mumfrey.liteloader.core.event.IHandlerListDecorator#createInstance(java.lang.Class) | |
119 | + */ | |
120 | + @Override | |
121 | + public BakedHandlerList<T> createInstance(Class<BakedHandlerList<T>> handlerClass) throws Exception | |
122 | + { | |
123 | + try | |
124 | + { | |
125 | + Constructor<BakedHandlerList<T>> ctor = handlerClass.getDeclaredConstructor(Profiler.class); | |
126 | + ctor.setAccessible(true); | |
127 | + return ctor.newInstance(this.profiler); | |
128 | + } | |
129 | + catch (Exception ex) | |
130 | + { | |
131 | + ex.printStackTrace(); | |
132 | + throw ex; | |
133 | + } | |
134 | + } | |
135 | + | |
136 | + /* (non-Javadoc) | |
137 | + * @see com.mumfrey.liteloader.core.event.IHandlerListDecorator#populateClass(java.lang.String, org.objectweb.asm.tree.ClassNode) | |
138 | + */ | |
139 | + @Override | |
140 | + public void populateClass(String name, ClassNode classNode) | |
141 | + { | |
142 | + } | |
143 | + | |
144 | + /* (non-Javadoc) | |
145 | + * @see com.mumfrey.liteloader.core.event.IHandlerListDecorator#processCtor(org.objectweb.asm.tree.ClassNode, org.objectweb.asm.tree.MethodNode) | |
146 | + */ | |
147 | + @Override | |
148 | + public void processCtor(ClassNode classNode, MethodNode method) | |
149 | + { | |
150 | + // Actually replace the ctor code because it's easier | |
151 | + method.instructions.clear(); | |
152 | + method.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); | |
153 | + method.instructions.add(new VarInsnNode(Opcodes.ALOAD, 1)); | |
154 | + method.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, Obf.BakedProfilingHandlerList.ref, Obf.constructor.name, method.desc, false)); | |
155 | + method.instructions.add(new InsnNode(Opcodes.RETURN)); | |
156 | + } | |
157 | + | |
158 | + /* (non-Javadoc) | |
159 | + * @see com.mumfrey.liteloader.core.event.IHandlerListDecorator#preInvokeInterfaceMethod(int, org.objectweb.asm.tree.ClassNode, org.objectweb.asm.tree.MethodNode, org.objectweb.asm.Type[]) | |
160 | + */ | |
161 | + @Override | |
162 | + public void preInvokeInterfaceMethod(int handlerIndex, ClassNode classNode, MethodNode method, Type[] args) | |
163 | + { | |
164 | + // Call this.startSection | |
165 | + method.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); | |
166 | + method.instructions.add(new LdcInsnNode(this.names.get(handlerIndex))); | |
167 | + method.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, classNode.superName, "startSection", "(Ljava/lang/String;)V", false)); | |
168 | + } | |
169 | + | |
170 | + /* (non-Javadoc) | |
171 | + * @see com.mumfrey.liteloader.core.event.IHandlerListDecorator#postInvokeInterfaceMethod(int, org.objectweb.asm.tree.ClassNode, org.objectweb.asm.tree.MethodNode, org.objectweb.asm.Type[]) | |
172 | + */ | |
173 | + @Override | |
174 | + public void postInvokeInterfaceMethod(int handlerIndex, ClassNode classNode, MethodNode method, Type[] args) | |
175 | + { | |
176 | + // Call this.endSection | |
177 | + method.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); | |
178 | + method.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, classNode.superName, "endSection", "()V", false)); | |
179 | + } | |
180 | + | |
181 | + /* (non-Javadoc) | |
182 | + * @see com.mumfrey.liteloader.core.event.IHandlerListDecorator#populateInterfaceMethod(org.objectweb.asm.tree.ClassNode, org.objectweb.asm.tree.MethodNode) | |
183 | + */ | |
184 | + @Override | |
185 | + public void populateInterfaceMethod(ClassNode classNode, MethodNode method) | |
186 | + { | |
187 | + } | |
188 | + } | |
189 | + | |
190 | + /** | |
191 | + * Template class for the profiling handler lists | |
192 | + * | |
193 | + * @author Adam Mummery-Smith | |
194 | + * | |
195 | + * @param <T> | |
196 | + */ | |
197 | + public static abstract class BakedList<T> extends HandlerList.BakedHandlerList<T> | |
198 | + { | |
199 | + private final Profiler profiler; | |
200 | + | |
201 | + public BakedList(Profiler profiler) | |
202 | + { | |
203 | + this.profiler = profiler; | |
204 | + } | |
205 | + | |
206 | + @Override | |
207 | + public abstract T get(); | |
208 | + | |
209 | + @Override | |
210 | + public abstract BakedHandlerList<T> populate(List<T> listeners); | |
211 | + | |
212 | + protected void startSection(String name) | |
213 | + { | |
214 | + this.profiler.startSection(name); | |
215 | + } | |
216 | + | |
217 | + protected void endSection() | |
218 | + { | |
219 | + this.profiler.endSection(); | |
220 | + } | |
221 | + } | |
222 | +} | ... | ... |
java/common/com/mumfrey/liteloader/core/runtime/Obf.java
... | ... | @@ -7,10 +7,6 @@ import java.util.HashMap; |
7 | 7 | import java.util.Map; |
8 | 8 | import java.util.Properties; |
9 | 9 | |
10 | -import net.minecraft.launchwrapper.IClassTransformer; | |
11 | -import net.minecraft.launchwrapper.Launch; | |
12 | -import net.minecraft.server.MinecraftServer; | |
13 | - | |
14 | 10 | /** |
15 | 11 | * Centralised obfuscation table for LiteLoader |
16 | 12 | * |
... | ... | @@ -26,6 +22,7 @@ public class Obf |
26 | 22 | public static final Obf EventProxy = new Obf("com.mumfrey.liteloader.core.event.EventProxy" ); |
27 | 23 | public static final Obf HandlerList = new Obf("com.mumfrey.liteloader.core.event.HandlerList" ); |
28 | 24 | public static final Obf BakedHandlerList = new Obf("com.mumfrey.liteloader.core.event.HandlerList$BakedHandlerList" ); |
25 | + public static final Obf BakedProfilingHandlerList = new Obf("com.mumfrey.liteloader.core.event.ProfilingHandlerList$BakedList" ); | |
29 | 26 | public static final Obf PacketEvents = new Obf("com.mumfrey.liteloader.core.PacketEvents" ); |
30 | 27 | public static final Obf PacketEventsClient = new Obf("com.mumfrey.liteloader.client.PacketEventsClient" ); |
31 | 28 | public static final Obf LoadingBar = new Obf("com.mumfrey.liteloader.client.gui.startup.LoadingBar" ); |
... | ... | @@ -106,6 +103,7 @@ public class Obf |
106 | 103 | public static final Obf shaderIndex = new Obf("field_147713_ae", "ac" ); |
107 | 104 | public static final Obf useShader = new Obf("field_175083_ad", "ad" ); |
108 | 105 | public static final Obf viewDistance = new Obf("field_149528_b", "b" ); |
106 | + public static final Obf entityPosY = new Obf("field_70163_u", "t" ); | |
109 | 107 | |
110 | 108 | // Methods |
111 | 109 | // ----------------------------------------------------------------------------------------- |
... | ... | @@ -152,6 +150,7 @@ public class Obf |
152 | 150 | public static final Obf processPlayerDigging = new Obf("func_147345_a", "a" ); |
153 | 151 | public static final Obf updateTimeLightAndEntities = new Obf("func_71190_q", "z" ); |
154 | 152 | public static final Obf checkThreadAndEnqueue = new Obf("func_180031_a", "a" ); |
153 | + public static final Obf processPlayer = new Obf("func_147347_a", "a" ); | |
155 | 154 | |
156 | 155 | public static final int MCP = 0; |
157 | 156 | public static final int SRG = 1; |
... | ... | @@ -353,6 +352,17 @@ public class Obf |
353 | 352 | return Obf.getByName(name); |
354 | 353 | } |
355 | 354 | |
355 | + public static String lookupMCPName(String obfName) | |
356 | + { | |
357 | + for (Obf obf : Obf.obfs.values()) | |
358 | + { | |
359 | + if (obfName.equals(obf.obf)) | |
360 | + return obf.name; | |
361 | + } | |
362 | + | |
363 | + return obfName; | |
364 | + } | |
365 | + | |
356 | 366 | /** |
357 | 367 | * Ordinal reference, can be passed to some methods which accept an {@link Obf} to indicate an offset into a |
358 | 368 | * class rather than a named reference. |
... | ... | @@ -403,61 +413,4 @@ public class Obf |
403 | 413 | return this.ordinal; |
404 | 414 | } |
405 | 415 | } |
406 | - | |
407 | - /** | |
408 | - * True if FML is being used, in which case we use searge names instead of raw field/method names | |
409 | - */ | |
410 | - private static boolean fmlDetected = false; | |
411 | - | |
412 | - private static boolean seargeNames = false; | |
413 | - | |
414 | - static | |
415 | - { | |
416 | - // Check for FML | |
417 | - Obf.fmlDetected = Obf.fmlIsPresent(); | |
418 | - | |
419 | - try | |
420 | - { | |
421 | - MinecraftServer.class.getDeclaredField("serverRunning"); | |
422 | - } | |
423 | - catch (SecurityException ex) | |
424 | - { | |
425 | - } | |
426 | - catch (NoSuchFieldException ex) | |
427 | - { | |
428 | - Obf.seargeNames = true; | |
429 | - } | |
430 | - } | |
431 | - | |
432 | - public static boolean fmlIsPresent() | |
433 | - { | |
434 | - for (IClassTransformer transformer : Launch.classLoader.getTransformers()) | |
435 | - if (transformer.getClass().getName().contains("fml")) return true; | |
436 | - | |
437 | - return false; | |
438 | - } | |
439 | - | |
440 | - /** | |
441 | - * Abstraction helper function | |
442 | - * | |
443 | - * @param fieldName Name of field to get, returned unmodified if in debug mode | |
444 | - * @return Obfuscated field name if present | |
445 | - */ | |
446 | - public static String getObfuscatedFieldName(String fieldName, String obfuscatedFieldName, String seargeFieldName) | |
447 | - { | |
448 | - boolean deobfuscated = MinecraftServer.class.getSimpleName().equals("MinecraftServer"); | |
449 | - return deobfuscated ? (Obf.seargeNames ? seargeFieldName : fieldName) : (Obf.fmlDetected ? seargeFieldName : obfuscatedFieldName); | |
450 | - } | |
451 | - | |
452 | - /** | |
453 | - * Abstraction helper function | |
454 | - * | |
455 | - * @param obf Field to get, returned unmodified if in debug mode | |
456 | - * @return Obfuscated field name if present | |
457 | - */ | |
458 | - public static String getObfuscatedFieldName(Obf obf) | |
459 | - { | |
460 | - boolean deobfuscated = MinecraftServer.class.getSimpleName().equals("MinecraftServer"); | |
461 | - return deobfuscated ? (Obf.seargeNames ? obf.srg : obf.name) : (Obf.fmlDetected ? obf.srg : obf.obf); | |
462 | - } | |
463 | 416 | } | ... | ... |
java/common/com/mumfrey/liteloader/transformers/ByteCodeUtilities.java
... | ... | @@ -344,8 +344,24 @@ public abstract class ByteCodeUtilities |
344 | 344 | */ |
345 | 345 | public static List<LocalVariableNode> generateLocalVariableTable(ClassNode classNode, MethodNode method) |
346 | 346 | { |
347 | + List<Type> interfaces = null; | |
348 | + if (classNode.interfaces != null) | |
349 | + { | |
350 | + interfaces = new ArrayList<Type>(); | |
351 | + for (String iface : classNode.interfaces) | |
352 | + { | |
353 | + interfaces.add(Type.getObjectType(iface)); | |
354 | + } | |
355 | + } | |
356 | + | |
357 | + Type objectType = null; | |
358 | + if (classNode.superName != null) | |
359 | + { | |
360 | + objectType = Type.getObjectType(classNode.superName); | |
361 | + } | |
362 | + | |
347 | 363 | // Use Analyzer to generate the bytecode frames |
348 | - Analyzer<BasicValue> analyzer = new Analyzer<BasicValue>(new SimpleVerifier(Type.getObjectType(classNode.name), null, null, false)); | |
364 | + Analyzer<BasicValue> analyzer = new Analyzer<BasicValue>(new SimpleVerifier(Type.getObjectType(classNode.name), objectType, interfaces, false)); | |
349 | 365 | try |
350 | 366 | { |
351 | 367 | analyzer.analyze(classNode.name, method); | ... | ... |
java/common/com/mumfrey/liteloader/util/ObfuscationUtilities.java
0 → 100644
1 | +package com.mumfrey.liteloader.util; | |
2 | + | |
3 | +import net.minecraft.launchwrapper.IClassTransformer; | |
4 | +import net.minecraft.launchwrapper.Launch; | |
5 | +import net.minecraft.server.MinecraftServer; | |
6 | +import net.minecraft.util.BlockPos; | |
7 | + | |
8 | +import com.mumfrey.liteloader.core.runtime.Obf; | |
9 | + | |
10 | +public class ObfuscationUtilities | |
11 | +{ | |
12 | + /** | |
13 | + * True if FML is being used, in which case we use searge names instead of raw field/method names | |
14 | + */ | |
15 | + private static boolean fmlDetected = false; | |
16 | + | |
17 | + private static boolean seargeNames = false; | |
18 | + | |
19 | + static | |
20 | + { | |
21 | + // Check for FML | |
22 | + ObfuscationUtilities.fmlDetected = ObfuscationUtilities.fmlIsPresent(); | |
23 | + | |
24 | + try | |
25 | + { | |
26 | + MinecraftServer.class.getDeclaredField("serverRunning"); | |
27 | + } | |
28 | + catch (SecurityException ex) | |
29 | + { | |
30 | + } | |
31 | + catch (NoSuchFieldException ex) | |
32 | + { | |
33 | + ObfuscationUtilities.seargeNames = true; | |
34 | + } | |
35 | + } | |
36 | + | |
37 | + public static boolean fmlIsPresent() | |
38 | + { | |
39 | + for (IClassTransformer transformer : Launch.classLoader.getTransformers()) | |
40 | + if (transformer.getClass().getName().contains("fml")) return true; | |
41 | + | |
42 | + return false; | |
43 | + } | |
44 | + | |
45 | + /** | |
46 | + * Abstraction helper function | |
47 | + * | |
48 | + * @param fieldName Name of field to get, returned unmodified if in debug mode | |
49 | + * @return Obfuscated field name if present | |
50 | + */ | |
51 | + public static String getObfuscatedFieldName(String fieldName, String obfuscatedFieldName, String seargeFieldName) | |
52 | + { | |
53 | + boolean deobfuscated = BlockPos.class.getSimpleName().equals("BlockPos"); | |
54 | + return deobfuscated ? (ObfuscationUtilities.seargeNames ? seargeFieldName : fieldName) : (ObfuscationUtilities.fmlDetected ? seargeFieldName : obfuscatedFieldName); | |
55 | + } | |
56 | + | |
57 | + /** | |
58 | + * Abstraction helper function | |
59 | + * | |
60 | + * @param obf Field to get, returned unmodified if in debug mode | |
61 | + * @return Obfuscated field name if present | |
62 | + */ | |
63 | + public static String getObfuscatedFieldName(Obf obf) | |
64 | + { | |
65 | + boolean deobfuscated = BlockPos.class.getSimpleName().equals("BlockPos"); | |
66 | + return deobfuscated ? (ObfuscationUtilities.seargeNames ? obf.srg : obf.name) : (ObfuscationUtilities.fmlDetected ? obf.srg : obf.obf); | |
67 | + } | |
68 | +} | ... | ... |