Commit d59d4fa2e25934c7389d90fc5416b826fda241e1
1 parent
70ad9fc2
LiteLoader 1.6.4_02 - dev only - merge NPE fix from 1.7 branch
Showing
5 changed files
with
12 additions
and
124 deletions
java/com/mumfrey/liteloader/core/Events.java
@@ -9,14 +9,7 @@ import net.minecraft.src.*; | @@ -9,14 +9,7 @@ import net.minecraft.src.*; | ||
9 | 9 | ||
10 | import com.mumfrey.liteloader.*; | 10 | import com.mumfrey.liteloader.*; |
11 | import com.mumfrey.liteloader.Tickable; | 11 | import com.mumfrey.liteloader.Tickable; |
12 | -import com.mumfrey.liteloader.core.hooks.HookChat; | ||
13 | -import com.mumfrey.liteloader.core.hooks.HookLogin; | ||
14 | import com.mumfrey.liteloader.core.hooks.HookProfiler; | 12 | import com.mumfrey.liteloader.core.hooks.HookProfiler; |
15 | -import com.mumfrey.liteloader.core.hooks.asm.ASMHookProxy; | ||
16 | -import com.mumfrey.liteloader.core.hooks.asm.ChatPacketTransformer; | ||
17 | -import com.mumfrey.liteloader.core.hooks.asm.LoginPacketTransformer; | ||
18 | -import com.mumfrey.liteloader.core.hooks.asm.PacketTransformer; | ||
19 | -import com.mumfrey.liteloader.util.ModUtilities; | ||
20 | import com.mumfrey.liteloader.util.PrivateFields; | 13 | import com.mumfrey.liteloader.util.PrivateFields; |
21 | 14 | ||
22 | /** | 15 | /** |
@@ -41,11 +34,6 @@ public class Events implements IPlayerUsage | @@ -41,11 +34,6 @@ public class Events implements IPlayerUsage | ||
41 | private final PluginChannels pluginChannels; | 34 | private final PluginChannels pluginChannels; |
42 | 35 | ||
43 | /** | 36 | /** |
44 | - * ASM hook proxy | ||
45 | - */ | ||
46 | - private final ASMHookProxy asmProxy; | ||
47 | - | ||
48 | - /** | ||
49 | * Reference to the minecraft timer | 37 | * Reference to the minecraft timer |
50 | */ | 38 | */ |
51 | private Timer minecraftTimer; | 39 | private Timer minecraftTimer; |
@@ -53,7 +41,7 @@ public class Events implements IPlayerUsage | @@ -53,7 +41,7 @@ public class Events implements IPlayerUsage | ||
53 | /** | 41 | /** |
54 | * Flags which keep track of whether hooks have been applied | 42 | * Flags which keep track of whether hooks have been applied |
55 | */ | 43 | */ |
56 | - private boolean hookInitDone, lateInitDone, chatHooked, loginHooked, tickHooked; | 44 | + private boolean hookInitDone, lateInitDone, tickHooked; |
57 | 45 | ||
58 | /** | 46 | /** |
59 | * Profiler hook objects | 47 | * Profiler hook objects |
@@ -153,12 +141,11 @@ public class Events implements IPlayerUsage | @@ -153,12 +141,11 @@ public class Events implements IPlayerUsage | ||
153 | * @param minecraft | 141 | * @param minecraft |
154 | * @param pluginChannels | 142 | * @param pluginChannels |
155 | */ | 143 | */ |
156 | - Events(LiteLoader loader, Minecraft minecraft, PluginChannels pluginChannels, ASMHookProxy asmProxy) | 144 | + Events(LiteLoader loader, Minecraft minecraft, PluginChannels pluginChannels) |
157 | { | 145 | { |
158 | this.loader = loader; | 146 | this.loader = loader; |
159 | this.minecraft = minecraft; | 147 | this.minecraft = minecraft; |
160 | this.pluginChannels = pluginChannels; | 148 | this.pluginChannels = pluginChannels; |
161 | - this.asmProxy = asmProxy; | ||
162 | } | 149 | } |
163 | 150 | ||
164 | /** | 151 | /** |
@@ -245,40 +232,6 @@ public class Events implements IPlayerUsage | @@ -245,40 +232,6 @@ public class Events implements IPlayerUsage | ||
245 | { | 232 | { |
246 | LiteLoader.getLogger().info("Event manager is registering hooks"); | 233 | LiteLoader.getLogger().info("Event manager is registering hooks"); |
247 | 234 | ||
248 | - // Chat hook | ||
249 | - if ((this.chatListeners.size() > 0 || this.chatFilters.size() > 0) && !this.chatHooked) | ||
250 | - { | ||
251 | - this.chatHooked = true; | ||
252 | - | ||
253 | - if (ChatPacketTransformer.isInjected()) | ||
254 | - { | ||
255 | - PacketTransformer.registerProxy(Packet3Chat.class, this.asmProxy); | ||
256 | - } | ||
257 | - else | ||
258 | - { | ||
259 | - LiteLoader.getLogger().info("Callback injection failed for chat packet, injecting reflection hook"); | ||
260 | - HookChat.register(); | ||
261 | - HookChat.registerPacketHandler(this); | ||
262 | - } | ||
263 | - } | ||
264 | - | ||
265 | - // Login hook | ||
266 | - if ((this.preLoginListeners.size() > 0 || this.loginListeners.size() > 0) && !this.loginHooked) | ||
267 | - { | ||
268 | - this.loginHooked = true; | ||
269 | - | ||
270 | - if (LoginPacketTransformer.isInjected()) | ||
271 | - { | ||
272 | - PacketTransformer.registerProxy(Packet1Login.class, this.asmProxy); | ||
273 | - } | ||
274 | - else | ||
275 | - { | ||
276 | - LiteLoader.getLogger().info("Callback injection failed for login packet, injecting reflection hook"); | ||
277 | - ModUtilities.registerPacketOverride(1, HookLogin.class); | ||
278 | - HookLogin.events = this; | ||
279 | - } | ||
280 | - } | ||
281 | - | ||
282 | // Tick hook | 235 | // Tick hook |
283 | if (!this.tickHooked) | 236 | if (!this.tickHooked) |
284 | { | 237 | { |
@@ -289,8 +242,6 @@ public class Events implements IPlayerUsage | @@ -289,8 +242,6 @@ public class Events implements IPlayerUsage | ||
289 | // Sanity hook | 242 | // Sanity hook |
290 | PlayerUsageSnooper snooper = this.minecraft.getPlayerUsageSnooper(); | 243 | PlayerUsageSnooper snooper = this.minecraft.getPlayerUsageSnooper(); |
291 | PrivateFields.playerStatsCollector.setFinal(snooper, this); | 244 | PrivateFields.playerStatsCollector.setFinal(snooper, this); |
292 | - | ||
293 | - this.pluginChannels.initHook(); | ||
294 | } | 245 | } |
295 | catch (Exception ex) | 246 | catch (Exception ex) |
296 | { | 247 | { |
java/com/mumfrey/liteloader/core/LiteLoader.java
@@ -35,7 +35,6 @@ import net.minecraft.src.SimpleReloadableResourceManager; | @@ -35,7 +35,6 @@ import net.minecraft.src.SimpleReloadableResourceManager; | ||
35 | import net.minecraft.src.World; | 35 | import net.minecraft.src.World; |
36 | 36 | ||
37 | import com.mumfrey.liteloader.*; | 37 | import com.mumfrey.liteloader.*; |
38 | -import com.mumfrey.liteloader.core.hooks.asm.ASMHookProxy; | ||
39 | import com.mumfrey.liteloader.crashreport.CallableLiteLoaderBrand; | 38 | import com.mumfrey.liteloader.crashreport.CallableLiteLoaderBrand; |
40 | import com.mumfrey.liteloader.crashreport.CallableLiteLoaderMods; | 39 | import com.mumfrey.liteloader.crashreport.CallableLiteLoaderMods; |
41 | import com.mumfrey.liteloader.gui.GuiControlsPaginated; | 40 | import com.mumfrey.liteloader.gui.GuiControlsPaginated; |
@@ -151,11 +150,6 @@ public final class LiteLoader | @@ -151,11 +150,6 @@ public final class LiteLoader | ||
151 | private final LinkedList<ModFile> disabledMods = new LinkedList<ModFile>(); | 150 | private final LinkedList<ModFile> disabledMods = new LinkedList<ModFile>(); |
152 | 151 | ||
153 | /** | 152 | /** |
154 | - * ASM hook proxy | ||
155 | - */ | ||
156 | - private final ASMHookProxy asmProxy = new ASMHookProxy(); | ||
157 | - | ||
158 | - /** | ||
159 | * Event manager | 153 | * Event manager |
160 | */ | 154 | */ |
161 | private Events events; | 155 | private Events events; |
@@ -163,7 +157,7 @@ public final class LiteLoader | @@ -163,7 +157,7 @@ public final class LiteLoader | ||
163 | /** | 157 | /** |
164 | * Plugin channel manager | 158 | * Plugin channel manager |
165 | */ | 159 | */ |
166 | - private final PluginChannels pluginChannels = new PluginChannels(this.asmProxy); | 160 | + private final PluginChannels pluginChannels = new PluginChannels(); |
167 | 161 | ||
168 | /** | 162 | /** |
169 | * Permission Manager | 163 | * Permission Manager |
@@ -357,7 +351,7 @@ public final class LiteLoader | @@ -357,7 +351,7 @@ public final class LiteLoader | ||
357 | this.minecraft = minecraft; | 351 | this.minecraft = minecraft; |
358 | 352 | ||
359 | // Create the event broker | 353 | // Create the event broker |
360 | - this.events = new Events(this, this.minecraft, this.pluginChannels, this.asmProxy); | 354 | + this.events = new Events(this, this.minecraft, this.pluginChannels); |
361 | 355 | ||
362 | // Spawn mod instances | 356 | // Spawn mod instances |
363 | this.loadMods(); | 357 | this.loadMods(); |
java/com/mumfrey/liteloader/core/PluginChannels.java
@@ -11,10 +11,6 @@ import net.minecraft.src.Packet1Login; | @@ -11,10 +11,6 @@ import net.minecraft.src.Packet1Login; | ||
11 | import net.minecraft.src.Packet250CustomPayload; | 11 | import net.minecraft.src.Packet250CustomPayload; |
12 | 12 | ||
13 | import com.mumfrey.liteloader.PluginChannelListener; | 13 | import com.mumfrey.liteloader.PluginChannelListener; |
14 | -import com.mumfrey.liteloader.core.hooks.HookPluginChannels; | ||
15 | -import com.mumfrey.liteloader.core.hooks.asm.ASMHookProxy; | ||
16 | -import com.mumfrey.liteloader.core.hooks.asm.CustomPayloadPacketTransformer; | ||
17 | -import com.mumfrey.liteloader.core.hooks.asm.PacketTransformer; | ||
18 | import com.mumfrey.liteloader.permissions.PermissionsManagerClient; | 14 | import com.mumfrey.liteloader.permissions.PermissionsManagerClient; |
19 | 15 | ||
20 | /** | 16 | /** |
@@ -29,11 +25,6 @@ public class PluginChannels | @@ -29,11 +25,6 @@ public class PluginChannels | ||
29 | private static final String CHANNEL_UNREGISTER = "UNREGISTER"; | 25 | private static final String CHANNEL_UNREGISTER = "UNREGISTER"; |
30 | 26 | ||
31 | /** | 27 | /** |
32 | - * True if we have initialised the hook | ||
33 | - */ | ||
34 | - private boolean hookInitDone; | ||
35 | - | ||
36 | - /** | ||
37 | * Mapping of plugin channel names to listeners | 28 | * Mapping of plugin channel names to listeners |
38 | */ | 29 | */ |
39 | private HashMap<String, LinkedList<PluginChannelListener>> pluginChannels = new HashMap<String, LinkedList<PluginChannelListener>>(); | 30 | private HashMap<String, LinkedList<PluginChannelListener>> pluginChannels = new HashMap<String, LinkedList<PluginChannelListener>>(); |
@@ -43,40 +34,13 @@ public class PluginChannels | @@ -43,40 +34,13 @@ public class PluginChannels | ||
43 | */ | 34 | */ |
44 | private LinkedList<PluginChannelListener> pluginChannelListeners = new LinkedList<PluginChannelListener>(); | 35 | private LinkedList<PluginChannelListener> pluginChannelListeners = new LinkedList<PluginChannelListener>(); |
45 | 36 | ||
46 | - private ASMHookProxy asmProxy; | ||
47 | - | ||
48 | /** | 37 | /** |
49 | * Package private | 38 | * Package private |
50 | */ | 39 | */ |
51 | - PluginChannels(ASMHookProxy proxy) | ||
52 | - { | ||
53 | - this.asmProxy = proxy; | ||
54 | - } | ||
55 | - | ||
56 | - /** | ||
57 | - * | ||
58 | - */ | ||
59 | - public void initHook() | 40 | + PluginChannels() |
60 | { | 41 | { |
61 | - // Plugin channels hook | ||
62 | - if (this.pluginChannelListeners.size() > 0 && !this.hookInitDone) | ||
63 | - { | ||
64 | - if (CustomPayloadPacketTransformer.isInjected()) | ||
65 | - { | ||
66 | - PacketTransformer.registerProxy(Packet250CustomPayload.class, this.asmProxy); | ||
67 | - } | ||
68 | - else | ||
69 | - { | ||
70 | - LiteLoader.getLogger().info("Callback injection failed for custom payload packet, injecting reflection hook"); | ||
71 | - HookPluginChannels.register(); | ||
72 | - HookPluginChannels.registerPacketHandler(this); | ||
73 | - } | ||
74 | - | ||
75 | - this.hookInitDone = true; | ||
76 | - } | ||
77 | } | 42 | } |
78 | 43 | ||
79 | - | ||
80 | /** | 44 | /** |
81 | * @param pluginChannelListener | 45 | * @param pluginChannelListener |
82 | */ | 46 | */ |
@@ -85,8 +49,6 @@ public class PluginChannels | @@ -85,8 +49,6 @@ public class PluginChannels | ||
85 | if (!this.pluginChannelListeners.contains(pluginChannelListener)) | 49 | if (!this.pluginChannelListeners.contains(pluginChannelListener)) |
86 | { | 50 | { |
87 | this.pluginChannelListeners.add(pluginChannelListener); | 51 | this.pluginChannelListeners.add(pluginChannelListener); |
88 | - if (this.hookInitDone) | ||
89 | - this.initHook(); | ||
90 | } | 52 | } |
91 | } | 53 | } |
92 | 54 |
java/com/mumfrey/liteloader/core/hooks/asm/ASMHookProxy.java
@@ -16,15 +16,17 @@ import net.minecraft.src.Packet3Chat; | @@ -16,15 +16,17 @@ import net.minecraft.src.Packet3Chat; | ||
16 | * | 16 | * |
17 | * @author Adam Mummery-Smith | 17 | * @author Adam Mummery-Smith |
18 | */ | 18 | */ |
19 | -public class ASMHookProxy | 19 | +public abstract class ASMHookProxy |
20 | { | 20 | { |
21 | + private ASMHookProxy() {} | ||
22 | + | ||
21 | /** | 23 | /** |
22 | * Packet3Chat::processPacket() | 24 | * Packet3Chat::processPacket() |
23 | * | 25 | * |
24 | * @param netHandler | 26 | * @param netHandler |
25 | * @param packet | 27 | * @param packet |
26 | */ | 28 | */ |
27 | - public void handleChatPacket(NetHandler netHandler, Packet3Chat packet) | 29 | + public static void handleChatPacket(NetHandler netHandler, Packet3Chat packet) |
28 | { | 30 | { |
29 | Events events = LiteLoader.getEvents(); | 31 | Events events = LiteLoader.getEvents(); |
30 | if (events.onChat(packet)) | 32 | if (events.onChat(packet)) |
@@ -39,7 +41,7 @@ public class ASMHookProxy | @@ -39,7 +41,7 @@ public class ASMHookProxy | ||
39 | * @param netHandler | 41 | * @param netHandler |
40 | * @param packet | 42 | * @param packet |
41 | */ | 43 | */ |
42 | - public void handleLoginPacket(NetHandler netHandler, Packet1Login packet) | 44 | + public static void handleLoginPacket(NetHandler netHandler, Packet1Login packet) |
43 | { | 45 | { |
44 | Events events = LiteLoader.getEvents(); | 46 | Events events = LiteLoader.getEvents(); |
45 | if (events.onPreLogin(netHandler, packet)) | 47 | if (events.onPreLogin(netHandler, packet)) |
@@ -55,7 +57,7 @@ public class ASMHookProxy | @@ -55,7 +57,7 @@ public class ASMHookProxy | ||
55 | * @param netHandler | 57 | * @param netHandler |
56 | * @param packet | 58 | * @param packet |
57 | */ | 59 | */ |
58 | - public void handleCustomPayloadPacket(NetHandler netHandler, Packet250CustomPayload packet) | 60 | + public static void handleCustomPayloadPacket(NetHandler netHandler, Packet250CustomPayload packet) |
59 | { | 61 | { |
60 | netHandler.handleCustomPayload(packet); | 62 | netHandler.handleCustomPayload(packet); |
61 | 63 |
java/com/mumfrey/liteloader/core/hooks/asm/PacketTransformer.java
1 | package com.mumfrey.liteloader.core.hooks.asm; | 1 | package com.mumfrey.liteloader.core.hooks.asm; |
2 | 2 | ||
3 | -import java.lang.reflect.Field; | ||
4 | import java.util.List; | 3 | import java.util.List; |
5 | 4 | ||
6 | import org.objectweb.asm.ClassReader; | 5 | import org.objectweb.asm.ClassReader; |
@@ -146,7 +145,7 @@ public abstract class PacketTransformer implements IClassTransformer | @@ -146,7 +145,7 @@ public abstract class PacketTransformer implements IClassTransformer | ||
146 | method.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); | 145 | method.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); |
147 | 146 | ||
148 | // Invoke the handler function with the args we just pushed onto the stack | 147 | // Invoke the handler function with the args we just pushed onto the stack |
149 | - method.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "com/mumfrey/liteloader/core/hooks/asm/ASMHookProxy", this.handlerMethodName, targetMethodSig)); | 148 | + method.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/mumfrey/liteloader/core/hooks/asm/ASMHookProxy", this.handlerMethodName, targetMethodSig)); |
150 | 149 | ||
151 | // Return | 150 | // Return |
152 | method.instructions.add(new InsnNode(Opcodes.RETURN)); | 151 | method.instructions.add(new InsnNode(Opcodes.RETURN)); |
@@ -175,24 +174,4 @@ public abstract class PacketTransformer implements IClassTransformer | @@ -175,24 +174,4 @@ public abstract class PacketTransformer implements IClassTransformer | ||
175 | 174 | ||
176 | return null; | 175 | return null; |
177 | } | 176 | } |
178 | - | ||
179 | - /** | ||
180 | - * Register the proxy (handler) for a packet | ||
181 | - * | ||
182 | - * @param packetClass | ||
183 | - * @param proxy | ||
184 | - */ | ||
185 | - public static void registerProxy(Class<?> packetClass, ASMHookProxy proxy) | ||
186 | - { | ||
187 | - try | ||
188 | - { | ||
189 | - Field fProxy = packetClass.getDeclaredField("proxy"); | ||
190 | - fProxy.setAccessible(true); | ||
191 | - fProxy.set(null, proxy); | ||
192 | - } | ||
193 | - catch (Exception ex) | ||
194 | - { | ||
195 | - ex.printStackTrace(); | ||
196 | - } | ||
197 | - } | ||
198 | } | 177 | } |
199 | \ No newline at end of file | 178 | \ No newline at end of file |