Skip to content

Commit 44540a6

Browse files
committed
Merge branch 'fix-classloading' into dev
2 parents 35f317e + 17fca70 commit 44540a6

11 files changed

Lines changed: 106 additions & 94 deletions

src/main/java/alexiil/mods/load/LoadingFrame.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ public static void setSystemLAF() {
7070
}
7171
}
7272

73-
/** Launch the application. */
73+
/**
74+
* Launch the application.
75+
*/
7476
public static LoadingFrame openWindow() {
7577
try {
7678
LoadingFrame frame = new LoadingFrame();
@@ -94,7 +96,9 @@ public static Rectangle getWindowBounds(LoadingFrame frame) {
9496
bounds.height);
9597
}
9698

97-
/** Create the frame. */
99+
/**
100+
* Create the frame.
101+
*/
98102
public LoadingFrame() {
99103
setTitle("Minecraft Loading");
100104
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

src/main/java/alexiil/mods/load/MinecraftDisplayer.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
package alexiil.mods.load;
22

3-
import static org.lwjgl.opengl.GL11.GL_ALPHA_TEST;
4-
import static org.lwjgl.opengl.GL11.GL_DEPTH_TEST;
5-
import static org.lwjgl.opengl.GL11.GL_GREATER;
6-
import static org.lwjgl.opengl.GL11.GL_LEQUAL;
7-
import static org.lwjgl.opengl.GL11.GL_MODELVIEW;
8-
import static org.lwjgl.opengl.GL11.GL_PROJECTION;
9-
10-
import java.awt.*;
11-
import java.io.*;
3+
import static org.lwjgl.opengl.GL11.*;
4+
5+
import java.awt.Color;
6+
import java.io.BufferedReader;
7+
import java.io.File;
8+
import java.io.FileInputStream;
9+
import java.io.FileNotFoundException;
10+
import java.io.FileOutputStream;
11+
import java.io.IOException;
12+
import java.io.InputStream;
13+
import java.io.InputStreamReader;
14+
import java.io.OutputStream;
15+
import java.io.PrintStream;
1216
import java.lang.reflect.Field;
1317
import java.lang.reflect.Modifier;
1418
import java.nio.charset.StandardCharsets;
@@ -345,8 +349,8 @@ public static String[] readTipsFile(String file) throws IOException {
345349
List<String> lines = new ArrayList<>();
346350
try {
347351
reader = new BufferedReader((new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8))); // new
348-
// BufferedReader(new
349-
// FileReader(file));
352+
// BufferedReader(new
353+
// FileReader(file));
350354
StringBuffer inputBuffer = new StringBuffer();
351355
String line;
352356
while ((line = reader.readLine()) != null) {
@@ -671,11 +675,11 @@ public void open(Configuration cfg) {
671675

672676
try {
673677
lbRGB[0] = (float) (Color.decode("#" + loadingBarsColor).getRed() & 255) / 255.0f; // Color.decode("#" +
674-
// loadingBarsColor).getRed();
678+
// loadingBarsColor).getRed();
675679
lbRGB[1] = (float) (Color.decode("#" + loadingBarsColor).getGreen() & 255) / 255.0f; // Color.decode("#" +
676-
// loadingBarsColor).getGreen();
680+
// loadingBarsColor).getGreen();
677681
lbRGB[2] = (float) (Color.decode("#" + loadingBarsColor).getBlue() & 255) / 255.0f; // Color.decode("#" +
678-
// loadingBarsColor).getBlue();
682+
// loadingBarsColor).getBlue();
679683
// BetterLoadingScreen.log.debug("The color: " + String.valueOf(lbRGB[0]) + ";" + String.valueOf(lbRGB[1]) +
680684
// ";" + String.valueOf(lbRGB[2]));
681685
} catch (Exception e) {

src/main/java/alexiil/mods/load/ModLoadingListener.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
import com.google.common.eventbus.Subscribe;
1010

1111
import cpw.mods.fml.common.ModContainer;
12-
import cpw.mods.fml.common.event.*;
12+
import cpw.mods.fml.common.event.FMLConstructionEvent;
13+
import cpw.mods.fml.common.event.FMLInitializationEvent;
14+
import cpw.mods.fml.common.event.FMLLoadCompleteEvent;
15+
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
16+
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
1317
import cpw.mods.fml.relauncher.FMLLaunchHandler;
1418

1519
public class ModLoadingListener {
@@ -26,7 +30,9 @@ public enum State {
2630

2731
private String translatedName = null;
2832
final String name;
29-
/** If this state is only called once. This is false for all except for FINAL_LOADING */
33+
/**
34+
* If this state is only called once. This is false for all except for FINAL_LOADING
35+
*/
3036
final boolean isLoneState;
3137
/**
3238
* If this is true, then ModStage.getNext will skip this, but it will still be included in the percentage

src/main/java/alexiil/mods/load/Translation.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package alexiil.mods.load;
22

3-
import java.io.*;
3+
import java.io.BufferedReader;
4+
import java.io.File;
5+
import java.io.FileReader;
6+
import java.io.IOException;
7+
import java.io.InputStreamReader;
48
import java.nio.charset.StandardCharsets;
59
import java.util.Arrays;
610
import java.util.Enumeration;

src/main/java/alexiil/mods/load/coremod/BetterLoadingScreenTransformer.java

Lines changed: 47 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,22 @@ public class BetterLoadingScreenTransformer implements IClassTransformer, Opcode
1818

1919
@Override
2020
public byte[] transform(String name, String transformedName, byte[] basicClass) {
21-
try {
22-
if (transformedName.equals("net.minecraft.client.Minecraft")) return transformMinecraft(basicClass);
23-
if (transformedName.equals("cpw.mods.fml.client.SplashProgress"))
24-
return transformSplashProgress(basicClass);
25-
if (name.equals("com.mumfrey.liteloader.client.api.ObjectFactoryClient"))
26-
return transformObjectFactoryClient(basicClass);
27-
} catch (Throwable t) {
28-
BetterLoadingScreen.log.error("An issue occurred while transforming " + transformedName);
29-
t.printStackTrace();
21+
if (transformedName.equals("net.minecraft.client.Minecraft")) {
22+
return transformMinecraft(basicClass);
23+
}
24+
if (transformedName.equals("cpw.mods.fml.client.SplashProgress")) {
25+
return transformSplashProgress(basicClass);
26+
}
27+
if (name.equals("com.mumfrey.liteloader.client.api.ObjectFactoryClient")) {
28+
return transformObjectFactoryClient(basicClass);
3029
}
3130
return basicClass;
3231
}
3332

3433
private byte[] transformObjectFactoryClient(byte[] before) {
3534
ClassNode classNode = new ClassNode();
3635
ClassReader reader = new ClassReader(before);
37-
reader.accept(classNode, 0);
38-
36+
reader.accept(classNode, ClassReader.SKIP_DEBUG);
3937
for (MethodNode m : classNode.methods) {
4038
if (m.name.equals("preBeginGame")) {
4139
m.instructions.clear();
@@ -50,93 +48,82 @@ private byte[] transformObjectFactoryClient(byte[] before) {
5048
m.instructions.add(new InsnNode(RETURN));
5149
}
5250
}
53-
54-
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
51+
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
5552
classNode.accept(cw);
5653
return cw.toByteArray();
5754
}
5855

5956
private byte[] transformSplashProgress(byte[] before) {
6057
ClassNode classNode = new ClassNode();
6158
ClassReader reader = new ClassReader(before);
62-
reader.accept(classNode, 0);
63-
59+
reader.accept(classNode, ClassReader.SKIP_DEBUG);
6460
for (MethodNode m : classNode.methods) {
6561
if (m.name.equals("finish")) {
6662
m.instructions.insert(
6763
new MethodInsnNode(INVOKESTATIC, "alexiil/mods/load/ProgressDisplayer", "close", "()V", false));
6864
}
6965
}
70-
71-
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
66+
ClassWriter cw = new ClassWriter(0);
7267
classNode.accept(cw);
7368
return cw.toByteArray();
7469
}
7570

7671
private byte[] transformMinecraft(byte[] before) {
77-
boolean hasFoundFMLClientHandler = false;
78-
boolean hasFoundGL11 = false;
7972
ClassNode classNode = new ClassNode();
8073
ClassReader reader = new ClassReader(before);
81-
reader.accept(classNode, 0);
74+
reader.accept(classNode, ClassReader.SKIP_DEBUG);
75+
int transformations = 0;
8276

8377
for (MethodNode m : classNode.methods) {
84-
if (hasFoundGL11) break;
85-
if (m.exceptions.size() == 1 && m.exceptions.get(0).equals("org/lwjgl/LWJGLException")) {
86-
for (int i = 0; i < m.instructions.size(); i++) {
87-
AbstractInsnNode node = m.instructions.get(i);
88-
if (node instanceof MethodInsnNode) {
89-
MethodInsnNode method = (MethodInsnNode) node;
90-
if (method.owner.equals("org/lwjgl/opengl/GL11") && method.name.equals("glFlush")) {
91-
hasFoundGL11 = true;
92-
// This method throws an LWJGL exception, and calls GL11.glFlush(). This must be
93-
// Minecraft.loadScreen()!
94-
m.instructions.insertBefore(m.instructions.getFirst(), new InsnNode(RETURN));
95-
// just return from the method, as if nothing happened
96-
break;
97-
}
78+
if ((m.name.equals("aj") || m.name.equals("loadScreen")) && m.desc.equals("()V")) {
79+
m.instructions.clear();
80+
m.instructions.add(new InsnNode(RETURN));
81+
m.exceptions.clear();
82+
m.tryCatchBlocks.clear();
83+
m.localVariables = null;
84+
m.visitMaxs(0, 1);
85+
transformations++;
86+
break;
87+
} else if ((m.name.equals("ag") || m.name.equals("startGame")) && m.desc.equals("()V")) {
88+
for (AbstractInsnNode node : m.instructions.toArray()) {
89+
if (node instanceof MethodInsnNode
90+
&& ((MethodInsnNode) node).owner.equals("cpw/mods/fml/client/FMLClientHandler")
91+
&& ((MethodInsnNode) node).name.equals("instance")) {
92+
m.instructions.insertBefore(
93+
node,
94+
new MethodInsnNode(
95+
INVOKESTATIC,
96+
"alexiil/mods/load/ProgressDisplayer",
97+
"minecraftDisplayFirstProgress",
98+
"()V",
99+
false));
100+
transformations++;
101+
break;
98102
}
99103
}
100104
}
101-
for (int i = 0; i < m.instructions.size(); i++) {
105+
for (AbstractInsnNode node : m.instructions.toArray()) {
102106
/*
103107
* LiteLoader disabling -NOTE TO ANYONE FROM LITELOADER OR ANYONE ELSE: I am disabling liteloader's
104108
* overlay simply because otherwise it switches between liteloader's bar and mine. I can safely assume
105109
* that people won't want this, and as my progress bar is the entire mod, they can disable this
106110
* behaviour by removing my mod (as all my mod does is just add a loading bar)
107111
*/
108-
AbstractInsnNode node = m.instructions.get(i);
109112
if (node instanceof MethodInsnNode) {
110-
MethodInsnNode method = (MethodInsnNode) node;
111-
if (method.owner.equals("com/mumfrey/liteloader/client/gui/startup/LoadingBar")) {
112-
m.instructions.remove(method);
113-
continue;
114-
}
115-
}
116-
// LiteLoader removing end
117-
118-
if (!hasFoundFMLClientHandler) {
119-
if (node instanceof MethodInsnNode) {
120-
MethodInsnNode method = (MethodInsnNode) node;
121-
if (method.owner.equals("cpw/mods/fml/client/FMLClientHandler")
122-
&& method.name.equals("instance")) {
123-
MethodInsnNode newOne = new MethodInsnNode(
124-
INVOKESTATIC,
125-
"alexiil/mods/load/ProgressDisplayer",
126-
"minecraftDisplayFirstProgress",
127-
"()V",
128-
false);
129-
m.instructions.insertBefore(method, newOne);
130-
hasFoundFMLClientHandler = true;
131-
}
113+
if (((MethodInsnNode) node).owner.equals("com/mumfrey/liteloader/client/gui/startup/LoadingBar")) {
114+
m.instructions.remove(node);
132115
}
133116
}
134117
}
135118
}
136119

137-
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
120+
if (transformations != 2) {
121+
throw new IllegalStateException("BetterLoadingScreen couldn't not transform Minecraft properly!");
122+
}
123+
ClassWriter cw = new ClassWriter(0);
138124
classNode.accept(cw);
125+
final byte[] byteArray = cw.toByteArray();
139126
BetterLoadingScreen.log.debug("Transformed Minecraft");
140-
return cw.toByteArray();
127+
return byteArray;
141128
}
142129
}

src/main/java/alexiil/mods/load/coremod/LoadingScreenLoadPlugin.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
11
package alexiil.mods.load.coremod;
22

33
import java.io.File;
4-
import java.lang.reflect.Method;
54
import java.util.Map;
65

76
import alexiil.mods.load.ProgressDisplayer;
87
import alexiil.mods.load.Translation;
9-
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.MCVersion;
10-
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.SortingIndex;
8+
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
119

12-
@MCVersion("1.7.10")
13-
@SortingIndex(Integer.MAX_VALUE - 80)
14-
// A big number
15-
public class LoadingScreenLoadPlugin implements cpw.mods.fml.relauncher.IFMLLoadingPlugin {
16-
17-
private static Method disableSplashMethodRef;
10+
@IFMLLoadingPlugin.MCVersion("1.7.10")
11+
@IFMLLoadingPlugin.TransformerExclusions({ "alexiil.mods.load.coremod" })
12+
public class LoadingScreenLoadPlugin implements IFMLLoadingPlugin {
1813

1914
@Override
2015
public String[] getASMTransformerClass() {
21-
return new String[] { "alexiil.mods.load.coremod.BetterLoadingScreenTransformer" };
16+
return new String[] { BetterLoadingScreenTransformer.class.getName() };
2217
}
2318

2419
@Override

src/main/java/alexiil/mods/load/gui/BaseConfig.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ public class BaseConfig extends GuiScreen {
2222
private int xPosHelp = 0;
2323
private List<List<String>> helpText;
2424
private GuiScreen parent;
25-
/** Used to determine the button positions across the top */
25+
/**
26+
* Used to determine the button positions across the top
27+
*/
2628
protected int totalLength;
2729

2830
public BaseConfig(GuiScreen screen) {

src/main/java/alexiil/mods/load/gui/FrameEditor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ public class FrameEditor extends JFrame {
3636
private final GuiPreview gui;
3737
private ImageRender[] renders;
3838

39-
/** Create the frame. */
39+
/**
40+
* Create the frame.
41+
*/
4042
public FrameEditor(GuiPreview preview) {
4143
this.gui = preview;
4244
renders = gui.getImageData();

src/main/java/alexiil/mods/load/gui/FramePreview.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ public class FramePreview extends JFrame {
2626

2727
private JTextField textField;
2828

29-
/** Create the frame. */
29+
/**
30+
* Create the frame.
31+
*/
3032
public FramePreview(final GuiPreview gui) {
3133
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
3234
setBounds(100, 100, 450, 300);

src/main/java/alexiil/mods/load/imgur/ImgurCacheManager.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package alexiil.mods.load.imgur;
22

33
import java.awt.image.BufferedImage;
4-
import java.io.*;
4+
import java.io.BufferedInputStream;
5+
import java.io.BufferedOutputStream;
6+
import java.io.ByteArrayInputStream;
7+
import java.io.IOException;
8+
import java.io.InputStream;
59
import java.nio.file.Files;
610
import java.nio.file.Path;
711
import java.nio.file.Paths;

0 commit comments

Comments
 (0)