Skip to content

Commit e5fbb0a

Browse files
committed
Introduce BuildConfig.FOXLOADER_DISPLAY and unpick it in dev.
1 parent b0881a0 commit e5fbb0a

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

patching/generate.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ static void generateBuildConfig0(File buildConfigSrc, Project project) {
7777
printStream.println(" private BuildConfig() {}")
7878
printStream.println(" public static final String FOXLOADER_VERSION = \"" + FOXLOADER_VERSION + "\";")
7979
printStream.println(" public static final String FOXLOADER_VERSION_MAJOR = \"" + FOXLOADER_VERSION_MAJOR + "\";")
80+
printStream.println(" public static final String FOXLOADER_DISPLAY = \"FoxLoader " + FOXLOADER_VERSION + "\";")
8081
printStream.println(" public static final String REINDEV_VERSION = \"" + REINDEV_VERSION + "\";")
8182
printStream.println(" public static final String SLIM_URL = \"" + SLIM_URL + "\";")
8283
printStream.println(" public static final String SLIM_JAR_NAME = \"" + SLIM_JAR_NAME + "\";")

patching/src/main/java/com/fox2code/foxloader/patching/dev/DevelopmentSourceConstantData.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424
package com.fox2code.foxloader.patching.dev;
2525

26+
import com.fox2code.foxloader.launcher.BuildConfig;
2627
import com.fox2code.foxloader.patching.TransformerUtils;
2728
import org.objectweb.asm.ClassReader;
2829
import org.objectweb.asm.Opcodes;
@@ -35,13 +36,14 @@
3536
import java.util.jar.JarEntry;
3637
import java.util.jar.JarFile;
3738

38-
public class DevelopmentSourceConstantData {
39+
public final class DevelopmentSourceConstantData {
3940
private static final int STATUS_DISABLED = -1;
4041
private static final int STATUS_DEFAULT = 0;
4142
private static final int STATUS_DISPLAY_FIRST = 1;
4243
private static final int PUBLIC_STATIC_FINAL = Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL;
4344
private static final String CoreConstants = "net/minecraft/common/CoreConstants";
4445
private static final String ChatColors = "net/minecraft/common/util/ChatColors";
46+
private static final String ASMBuildConfig = "com/fox2code/foxloader/launcher/BuildConfig";
4547
public final String internalVersion, version, displayVersion;
4648
private final ConstantCheck[] regular, displayFirst;
4749
private final ArrayList<ConstantCheck> chatColorsConstantChecks;
@@ -54,18 +56,20 @@ private DevelopmentSourceConstantData(ClassNode coreConstantsClassNode, ClassNod
5456
CoreConstantCheck internalVersionCheck = new CoreConstantCheck(this.internalVersion, "INTERNAL_VERSION");
5557
CoreConstantCheck versionCheck = new CoreConstantCheck(this.version, "VERSION");
5658
CoreConstantCheck displayVersionCheck = new CoreConstantCheck(this.displayVersion, "DISPLAY_VERSION");
59+
FLConstantCheck flVersionCheck = new FLConstantCheck(BuildConfig.FOXLOADER_DISPLAY, "FOXLOADER_DISPLAY");
5760
if (Objects.equals(this.version, this.displayVersion)) {
58-
this.regular = new ConstantCheck[]{versionCheck, internalVersionCheck};
59-
this.displayFirst = new ConstantCheck[]{displayVersionCheck, internalVersionCheck};
61+
this.regular = new ConstantCheck[]{versionCheck, internalVersionCheck, flVersionCheck};
62+
this.displayFirst = new ConstantCheck[]{displayVersionCheck, internalVersionCheck, flVersionCheck};
6063
} else {
6164
this.displayFirst = this.regular = new ConstantCheck[]{
62-
displayVersionCheck, versionCheck, internalVersionCheck};
65+
displayVersionCheck, versionCheck, internalVersionCheck, flVersionCheck};
6366
}
6467
this.chatColorsConstantChecks = new ArrayList<>();
6568
this.constants = new HashSet<>();
6669
this.constants.add(this.internalVersion);
6770
this.constants.add(this.version);
6871
this.constants.add(this.displayVersion);
72+
this.constants.add(BuildConfig.FOXLOADER_DISPLAY);
6973

7074
for (FieldNode fieldNode : chatColorsClassNode.fields) {
7175
if ((fieldNode.access & PUBLIC_STATIC_FINAL) == PUBLIC_STATIC_FINAL &&
@@ -217,6 +221,20 @@ public FieldInsnNode makeFieldInsnNode() {
217221
}
218222
}
219223

224+
private static class FLConstantCheck extends ConstantCheck {
225+
private final String fieldName;
226+
227+
private FLConstantCheck(String value, String fieldName) {
228+
super(value);
229+
this.fieldName = fieldName;
230+
}
231+
232+
public FieldInsnNode makeFieldInsnNode() {
233+
return new FieldInsnNode(Opcodes.GETSTATIC,
234+
ASMBuildConfig, this.fieldName, "Ljava/lang/String;");
235+
}
236+
}
237+
220238
private static class ColorConstantCheck extends ConstantCheck {
221239
private final String fieldName;
222240

patching/src/main/java/com/fox2code/foxloader/patching/game/GuiScreenPatch.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ private static void patchGuiDebug(ClassNode classNode) {
9090
if (constant.endsWith(")")) {
9191
// This branch happens for betas and such
9292
ldcInsnNode.cst = constant.substring(0, constant.length() - 1) +
93-
" / FoxLoader " + BuildConfig.FOXLOADER_VERSION + ")";
93+
" / " + BuildConfig.FOXLOADER_DISPLAY + ")";
9494
} else {
95-
ldcInsnNode.cst = constant + " (FoxLoader " + BuildConfig.FOXLOADER_VERSION + ")";
95+
ldcInsnNode.cst = constant + " (" + BuildConfig.FOXLOADER_DISPLAY + ")";
9696
}
9797
}
9898
}
@@ -153,7 +153,7 @@ private static void patchGuiMainMenu(ClassNode classNode) {
153153
LdcInsnNode ldcInsnNode = (LdcInsnNode) abstractInsnNode;
154154
if (ldcInsnNode.cst instanceof String &&
155155
((String) ldcInsnNode.cst).startsWith(reIndevVersionPattern)) {
156-
ldcInsnNode.cst = "FoxLoader " + BuildConfig.FOXLOADER_VERSION;
156+
ldcInsnNode.cst = BuildConfig.FOXLOADER_DISPLAY;
157157
}
158158
} else if (abstractInsnNode.getOpcode() == BIPUSH) {
159159
if(((IntInsnNode) abstractInsnNode).operand == 10) {

0 commit comments

Comments
 (0)