Commit bf07e63f9231dc3ddd3abfb78c237424f8237c4e

Authored by Mumfrey
1 parent 825f38a2

Remove MinecraftTransformer and replace with mixin injections

src/client/java/com/mumfrey/liteloader/client/api/LiteLoaderCoreAPIClient.java
... ... @@ -42,7 +42,6 @@ public class LiteLoaderCoreAPIClient extends LiteLoaderCoreAPI
42 42  
43 43 private static final String[] requiredDownstreamTransformers = {
44 44 LiteLoaderCoreAPI.PKG_LITELOADER_COMMON + ".transformers.LiteLoaderPacketTransformer",
45   - LiteLoaderCoreAPIClient.PKG_LITELOADER_CLIENT + ".transformers.MinecraftTransformer",
46 45 LiteLoaderCoreAPI.PKG_LITELOADER + ".transformers.event.json.ModEventInjectionTransformer"
47 46 };
48 47  
... ...
src/client/java/com/mumfrey/liteloader/client/mixin/MixinMinecraft.java
... ... @@ -19,7 +19,9 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
19 19 import com.mumfrey.liteloader.PlayerInteractionListener.MouseButton;
20 20 import com.mumfrey.liteloader.client.LiteLoaderEventBrokerClient;
21 21 import com.mumfrey.liteloader.client.ducks.IFramebuffer;
  22 +import com.mumfrey.liteloader.client.gui.startup.LoadingBar;
22 23 import com.mumfrey.liteloader.client.overlays.IMinecraft;
  24 +import com.mumfrey.liteloader.launch.LiteLoaderTweaker;
23 25  
24 26 import net.minecraft.client.Minecraft;
25 27 import net.minecraft.client.renderer.OpenGlHelper;
... ... @@ -45,6 +47,25 @@ public abstract class MixinMinecraft implements IMinecraft
45 47  
46 48 private LiteLoaderEventBrokerClient broker;
47 49  
  50 + @Inject(method = "init()V", at = @At(value = "NEW", target = "net/minecraft/client/renderer/EntityRenderer"))
  51 + private void init(CallbackInfo ci)
  52 + {
  53 + LiteLoaderTweaker.init();
  54 + LiteLoaderTweaker.postInit();
  55 + }
  56 +
  57 + @Inject(method = "init()V", at = @At(value = "NEW", target = "net/minecraft/client/renderer/texture/TextureMap"))
  58 + private void initTextures(CallbackInfo ci)
  59 + {
  60 + LoadingBar.initTextures();
  61 + }
  62 +
  63 + @Inject(method = "init()V", at = @At("INVOKE"))
  64 + private void progress(CallbackInfo ci)
  65 + {
  66 + LoadingBar.incrementProgress();
  67 + }
  68 +
48 69 @Inject(method = "init()V", at = @At("RETURN"))
49 70 private void onStartupComplete(CallbackInfo ci)
50 71 {
... ...
src/client/java/com/mumfrey/liteloader/client/transformers/MinecraftTransformer.java deleted 100644 → 0
1   -/*
2   - * This file is part of LiteLoader.
3   - * Copyright (C) 2012-16 Adam Mummery-Smith
4   - * All Rights Reserved.
5   - */
6   -package com.mumfrey.liteloader.client.transformers;
7   -
8   -import java.util.Iterator;
9   -
10   -import org.objectweb.asm.Opcodes;
11   -import org.objectweb.asm.tree.AbstractInsnNode;
12   -import org.objectweb.asm.tree.ClassNode;
13   -import org.objectweb.asm.tree.InsnList;
14   -import org.objectweb.asm.tree.LdcInsnNode;
15   -import org.objectweb.asm.tree.MethodInsnNode;
16   -import org.objectweb.asm.tree.MethodNode;
17   -import org.objectweb.asm.tree.TypeInsnNode;
18   -
19   -import com.mumfrey.liteloader.core.runtime.Obf;
20   -import com.mumfrey.liteloader.launch.LiteLoaderTweaker;
21   -import com.mumfrey.liteloader.transformers.ClassTransformer;
22   -import com.mumfrey.liteloader.util.log.LiteLoaderLogger;
23   -
24   -public class MinecraftTransformer extends ClassTransformer
25   -{
26   - private static final String TWEAKCLASS = LiteLoaderTweaker.class.getName().replace('.', '/');
27   -
28   - @Override
29   - public byte[] transform(String name, String transformedName, byte[] basicClass)
30   - {
31   - if ((Obf.Minecraft.name.equals(transformedName) || Obf.Minecraft.obf.equals(transformedName)))
32   - {
33   - ClassNode classNode = this.readClass(basicClass, true);
34   - for (MethodNode method : classNode.methods)
35   - {
36   - if (Obf.startGame.obf.equals(method.name) || Obf.startGame.srg.equals(method.name) || Obf.startGame.name.equals(method.name))
37   - {
38   - this.transformStartGame(method);
39   - }
40   - }
41   - return this.writeClass(classNode);
42   - }
43   - return basicClass;
44   - }
45   -
46   -
47   - private void transformStartGame(MethodNode method)
48   - {
49   - InsnList insns = new InsnList();
50   -
51   - boolean loadingBarEnabled = LiteLoaderTweaker.loadingBarEnabled();
52   - boolean found = false;
53   -
54   - Iterator<AbstractInsnNode> iter = method.instructions.iterator();
55   - while (iter.hasNext())
56   - {
57   - AbstractInsnNode insn = iter.next();
58   - if (loadingBarEnabled && insn instanceof MethodInsnNode)
59   - {
60   - insns.add(new MethodInsnNode(Opcodes.INVOKESTATIC, Obf.LoadingBar.ref, "incrementProgress", "()V", false));
61   - }
62   -
63   - insns.add(insn);
64   -
65   - if (insn instanceof TypeInsnNode && insn.getOpcode() == Opcodes.NEW && insns.getLast() != null)
66   - {
67   - TypeInsnNode typeNode = (TypeInsnNode)insn;
68   - if (!found && (Obf.EntityRenderer.obf.equals(typeNode.desc) || Obf.EntityRenderer.ref.equals(typeNode.desc)))
69   - {
70   - LiteLoaderLogger.info("MinecraftTransformer found INIT injection point, this is good.");
71   - found = true;
72   -
73   - insns.add(new MethodInsnNode(Opcodes.INVOKESTATIC, MinecraftTransformer.TWEAKCLASS, Obf.init.name, "()V", false));
74   - insns.add(new MethodInsnNode(Opcodes.INVOKESTATIC, MinecraftTransformer.TWEAKCLASS, Obf.postInit.name, "()V", false));
75   - }
76   - }
77   -
78   - if (loadingBarEnabled && insn instanceof LdcInsnNode)
79   - {
80   - LdcInsnNode ldcInsn = (LdcInsnNode)insn;
81   - if ("textures/blocks".equals(ldcInsn.cst))
82   - {
83   - insns.add(new MethodInsnNode(Opcodes.INVOKESTATIC, Obf.LoadingBar.ref, "initTextures", "()V", false));
84   - }
85   - }
86   - }
87   -
88   - method.instructions = insns;
89   -
90   - if (!found) LiteLoaderLogger.severe("MinecraftTransformer failed to find INIT injection point, the game will probably crash pretty soon.");
91   - }
92   -}
src/main/java/com/mumfrey/liteloader/core/runtime/Obf.java
... ... @@ -26,14 +26,11 @@ public class Obf
26 26 public static final Obf BakedProfilingHandlerList = new Obf("com.mumfrey.liteloader.core.event.ProfilingHandlerList$BakedList" );
27 27 public static final Obf PacketEvents = new Obf("com.mumfrey.liteloader.core.PacketEvents" );
28 28 public static final Obf PacketEventsClient = new Obf("com.mumfrey.liteloader.client.PacketEventsClient" );
29   - public static final Obf LoadingBar = new Obf("com.mumfrey.liteloader.client.gui.startup.LoadingBar" );
30 29 public static final Obf GameProfile = new Obf("com.mojang.authlib.GameProfile" );
31 30 public static final Obf MinecraftMain = new Obf("net.minecraft.client.main.Main" );
32 31 public static final Obf MinecraftServer = new Obf("net.minecraft.server.MinecraftServer" );
33 32 public static final Obf GL11 = new Obf("org.lwjgl.opengl.GL11" );
34 33 public static final Obf RealmsMainScreen = new Obf("com.mojang.realmsclient.RealmsMainScreen" );
35   - public static final Obf init = new Obf("init" );
36   - public static final Obf postInit = new Obf("postInit" );
37 34 public static final Obf constructor = new Obf("<init>" );
38 35  
39 36 // CHECKSTYLE:OFF
... ...