Skip to content

Commit 8b8848a

Browse files
committed
Add LWJGLX mode support to use LWJGL3 (Close #40)
1 parent dbff4e0 commit 8b8848a

File tree

8 files changed

+138
-24
lines changed

8 files changed

+138
-24
lines changed

loader/src/main/java/com/fox2code/foxloader/installer/InstallerGUI.java

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,15 @@ final class InstallerGUI {
6262
private static final String FULLSCREEN_LABEL =
6363
"FoxLoader " + BuildConfig.FOXLOADER_VERSION + " for ReIndev " + BuildConfig.REINDEV_VERSION;
6464
private static final int PROGRESS_BAR_MAX = DependencyHelper.commonDependencies.length + 1;
65-
private static final HashSet<String> MMC_PATCHES = new HashSet<>(Arrays.asList(
66-
"com.fox2code.foxloader.json", "net.minecraft.json", "net.minecraftforge.json"));
65+
private static final HashSet<String> MMC_PATCHES_ALL = new HashSet<>(Arrays.asList(
66+
"com.fox2code.foxloader.json", "net.minecraft.json",
67+
"net.minecraftforge.json", "com.fox2code.lwjglx.json"));
68+
private static final String[] MMC_FILES = new String[]{"patches/com.fox2code.foxloader.json",
69+
"patches/net.minecraft.json", "patches/net.minecraftforge.json",
70+
"patches/org.lwjgl.json", "instance.cfg", "mmc-pack.json"};
71+
private static final String[] MMC_FILES_LWJGLX = new String[]{"patches/com.fox2code.foxloader.json",
72+
"patches/net.minecraft.json", "patches/net.minecraftforge.json",
73+
"patches/com.fox2code.lwjglx.json", "instance.cfg", "mmc-pack-lwjglx.json"};
6774
private final InstallerPlatform installerPlatform;
6875
private final LauncherType launcherType;
6976
private final JFrame jFrame;
@@ -94,16 +101,16 @@ public InstallerGUI(InstallerPlatform installerPlatform) {
94101
languageContainer.add(TranslateEngine.makeLanguageSelectComponent());
95102
JPanel clientContainer = makeContainer("installer.install-client");
96103
JButton minecraftButton;
97-
JButton mmcButton;
98104
if (installerPlatform.specialLauncher) {
99105
minecraftButton = makeButton(clientContainer,
100106
"installer.install-special", this::installMineCraft, installerPlatform.platformName);
101-
mmcButton = null;
102107
} else {
103108
minecraftButton = makeButton(clientContainer,
104109
"installer.install-minecraft", this::installMineCraft);
105-
mmcButton = makeButton(clientContainer,
106-
"installer.extract-multimc", this::extractMMCInstance);
110+
makeButton(clientContainer,
111+
"installer.extract-multimc", () -> this.extractMMCInstance(false));
112+
makeButton(clientContainer,
113+
"installer.extract-multimc-lwjglx", () -> this.extractMMCInstance(true));
107114
}
108115
if (BuildConfig.IS_PRIVATE_DEV_BUILD) {
109116
minecraftButton.setEnabled(false);
@@ -291,15 +298,15 @@ public void installMineCraft() {
291298
TranslateEngine.getTranslation("installer.comment"), false);
292299
}
293300

294-
public void extractMMCInstance() {
301+
public void extractMMCInstance(boolean lwjglx) {
295302
String fileName = Main.currentInstallerFile.getName();
296303
if (fileName.endsWith("-installer.jar")) {
297304
fileName = fileName.replace("-installer.jar", ".jar");
298305
}
299-
this.extractMMCInstance(fileName);
306+
this.extractMMCInstance(fileName, lwjglx);
300307
}
301308

302-
public void extractMMCInstance(String baseFileName) {
309+
public void extractMMCInstance(String baseFileName, boolean lwjglx) {
303310
if (this.checkInstaller(true)) {
304311
return;
305312
}
@@ -309,7 +316,16 @@ public void extractMMCInstance(String baseFileName) {
309316
}
310317

311318
File instanceDest = new File(Main.currentInstallerFile.getParentFile(),
312-
baseFileName.substring(0, baseFileName.length() - 4) + "-mmc.zip");
319+
baseFileName.substring(0, baseFileName.length() - 4) +
320+
(lwjglx ? "-mmc-lwjglx.zip" : "-mmc.zip"));
321+
String lwjglPatchId, lwjglVersion;
322+
if (lwjglx) {
323+
lwjglVersion = "3.3.3";
324+
lwjglPatchId = "org.lwjgl3";
325+
} else {
326+
lwjglVersion = "2.9.4-nightly-20150209";
327+
lwjglPatchId = "org.lwjgl";
328+
}
313329
try (ZipOutputStream zipOutputStream = new ZipOutputStream(Files.newOutputStream(instanceDest.toPath()))) {
314330
zipOutputStream.putNextEntry(new ZipEntry("libraries/foxloader-" + BuildConfig.FOXLOADER_VERSION + ".jar"));
315331
copyCloseIn(Files.newInputStream(Main.currentInstallerFile.toPath()), zipOutputStream);
@@ -320,16 +336,19 @@ public void extractMMCInstance(String baseFileName) {
320336
zipOutputStream.closeEntry();
321337
}
322338
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
323-
for (String entry : new String[]{"patches/com.fox2code.foxloader.json",
324-
"patches/net.minecraft.json", "patches/net.minecraftforge.json",
325-
"patches/org.lwjgl.json", "instance.cfg", "mmc-pack.json"}) {
326-
zipOutputStream.putNextEntry(new ZipEntry(entry));
339+
for (String entry : (lwjglx ? MMC_FILES_LWJGLX : MMC_FILES)) {
340+
zipOutputStream.putNextEntry(new ZipEntry(
341+
"mmc-pack-lwjglx.json".equals(entry) ?
342+
"mmc-pack.json" : entry));
327343
byteArrayOutputStream.reset();
328344
IOUtils.copyAndClose(InstallerGUI.class.getResourceAsStream(
329345
"/mmc/" + entry), byteArrayOutputStream);
330346
copyCloseIn(new ByteArrayInputStream(byteArrayOutputStream.toString()
331347
.replace("#version#", this.versionName)
332348
.replace("#foxloader_version#", BuildConfig.FOXLOADER_VERSION)
349+
.replace("#lwjglx_version#", BuildConfig.LWJGLX_VERSION)
350+
.replace("#lwjgl_version#", lwjglVersion)
351+
.replace("#lwjgl_uid#", lwjglPatchId)
333352
.getBytes(StandardCharsets.UTF_8)), zipOutputStream);
334353
zipOutputStream.closeEntry();
335354
}
@@ -416,22 +435,42 @@ public void doSilentInstall() throws IOException {
416435
if (!patch.exists()) {
417436
for (File file : Objects.requireNonNull(patches.listFiles())) {
418437
if (file.getName().endsWith(".json") &&
419-
!MMC_PATCHES.contains(file.getName())) {
438+
!MMC_PATCHES_ALL.contains(file.getName())) {
420439
if (!file.delete()) file.deleteOnExit();
421440
}
422441
}
423442
}
443+
File patchLwjglx = new File(patches, "com.fox2code.lwjglx.json");
444+
boolean lwjglx = patchLwjglx.exists();
445+
String lwjglPatchId, lwjglVersion;
446+
if (lwjglx) {
447+
lwjglVersion = "3.3.3";
448+
lwjglPatchId = "org.lwjgl3";
449+
} else {
450+
lwjglVersion = "2.9.4-nightly-20150209";
451+
lwjglPatchId = "org.lwjgl";
452+
}
424453
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
425454
IOUtils.copyAndClose(InstallerGUI.class.getResourceAsStream(
426455
"/mmc/patches/com.fox2code.foxloader.json"), byteArrayOutputStream);
427456
IOUtils.copyAndClose(new ByteArrayInputStream(byteArrayOutputStream.toString()
428457
.replace("#version#", this.versionName)
429458
.replace("#foxloader_version#", BuildConfig.FOXLOADER_VERSION)
459+
.replace("#lwjgl_version#", lwjglVersion)
460+
.replace("#lwjgl_uid#", lwjglPatchId)
430461
.getBytes(StandardCharsets.UTF_8)), Files.newOutputStream(patch.toPath()));
462+
if (lwjglx) {
463+
byteArrayOutputStream.reset();
464+
IOUtils.copyAndClose(InstallerGUI.class.getResourceAsStream(
465+
"/mmc/patches/com.fox2code.lwjglx.json"), byteArrayOutputStream);
466+
IOUtils.copyAndClose(new ByteArrayInputStream(byteArrayOutputStream.toString()
467+
.replace("#lwjglx_version#", BuildConfig.LWJGLX_VERSION)
468+
.getBytes(StandardCharsets.UTF_8)), Files.newOutputStream(patchLwjglx.toPath()));
469+
}
431470
for (String entry : new String[]{ // Fix in place replace!
432471
"patches/net.minecraft.json", "patches/net.minecraftforge.json"}) {
433472
IOUtils.copyAndClose(InstallerGUI.class.getResourceAsStream(
434-
"/mmc/patches/com.fox2code.foxloader.json"),
473+
"/mmc/patches/" + entry + ".json"),
435474
Files.newOutputStream(new File(entry).toPath()));
436475
}
437476
break;

loader/src/main/java/com/fox2code/foxloader/installer/Main.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,12 @@ public static void main(String[] args) throws Throwable {
8888
if (!newName.exists()) {
8989
Files.copy(currentInstallerFile.toPath(), newName.toPath());
9090
}
91-
installerGUI.extractMMCInstance("fox" + installerName);
91+
installerGUI.extractMMCInstance("fox" + installerName, false);
92+
installerGUI.extractMMCInstance("fox" + installerName, true);
9293
installerGUI.extractServer("fox" + installerName);
9394
} else {
94-
installerGUI.extractMMCInstance();
95+
installerGUI.extractMMCInstance(false);
96+
installerGUI.extractMMCInstance(true);
9597
installerGUI.extractServer();
9698
}
9799
return;

loader/src/main/resources/assets/foxloader/lang/en_US.lang

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ installer.install-special=Install on %s Launcher
5353
installer.install-minecraft=Install on Minecraft Launcher
5454
installer.install-betacraft=Install on BetaCraft Launcher
5555
installer.extract-multimc=Extract MultiMC Instance
56+
installer.extract-multimc-lwjglx=Extract LWJGLX MultiMC Instance
5657
installer.extract-server=Extract Server Jar
5758
installer.exit-installer=Exit installer
5859
installer.install-server=Install Server

loader/src/main/resources/assets/foxloader/lang/ru_RU.lang

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ installer.install-special=Установить на %s лаунчер
2727
installer.install-minecraft=Установить на Minecraft лаунчер
2828
installer.install-betacraft=Установить на BetaCraft лаунчер
2929
installer.extract-multimc=Извлечь сборку MultiMC
30+
installer.extract-multimc-lwjglx=Извлечь сборку LWJGLX MultiMC
3031
installer.exit-installer=Выйти из программы установки
3132
installer.install-server=Установить сервер
3233
installer.install-server.text.1=Вы можете добавить аргумент "--server" в
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"components": [
3+
{
4+
"cachedName": "LWJGLX",
5+
"cachedVersion": "#lwjglx_version#",
6+
"cachedVolatile": true,
7+
"important": true,
8+
"uid": "com.fox2code.lwjglx",
9+
"version": "#lwjglx_version#"
10+
},
11+
{
12+
"cachedName": "LWJGL 3",
13+
"cachedVersion": "#lwjgl_version#",
14+
"cachedVolatile": true,
15+
"dependencyOnly": true,
16+
"uid": "#lwjgl_uid#",
17+
"version": "#lwjgl_version#"
18+
},
19+
{
20+
"cachedName": "FoxLoader",
21+
"cachedRequires": [
22+
{
23+
"suggests": "#lwjgl_version#",
24+
"uid": "#lwjgl_uid#"
25+
}
26+
],
27+
"cachedVersion": "#version#",
28+
"important": true,
29+
"uid": "com.fox2code.foxloader",
30+
"version": "#version#"
31+
},
32+
{
33+
"cachedName": "Workaround to prevent MultiMC Crash",
34+
"cachedRequires": [
35+
{
36+
"uid": "com.fox2code.foxloader"
37+
}
38+
],
39+
"cachedVersion": "no-op",
40+
"disabled": true,
41+
"uid": "net.minecraft",
42+
"version": "no-op"
43+
},
44+
{
45+
"cachedName": "Workaround to display CoreMods tab",
46+
"cachedRequires": [
47+
{
48+
"uid": "com.fox2code.foxloader"
49+
}
50+
],
51+
"cachedVersion": "no-op",
52+
"disabled": true,
53+
"uid": "net.minecraftforge",
54+
"version": "no-op"
55+
}
56+
],
57+
"formatVersion": 1
58+
}

loader/src/main/resources/mmc/mmc-pack.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
"cachedVersion": "2.9.4+legacyfabric.9",
66
"cachedVolatile": true,
77
"dependencyOnly": true,
8-
"uid": "org.lwjgl",
9-
"version": "2.9.4-nightly-20150209"
8+
"uid": "#lwjgl_uid#",
9+
"version": "#lwjgl_version#"
1010
},
1111
{
1212
"cachedName": "FoxLoader",
1313
"cachedRequires": [
1414
{
15-
"suggests": "2.9.4-nightly-20150209",
16-
"uid": "org.lwjgl"
15+
"suggests": "#lwjgl_version#",
16+
"uid": "#lwjgl_uid#"
1717
}
1818
],
1919
"cachedVersion": "#version#",

loader/src/main/resources/mmc/patches/com.fox2code.foxloader.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
"name": "FoxLoader",
3232
"requires": [
3333
{
34-
"suggests": "2.9.4-nightly-20150209",
35-
"uid": "org.lwjgl"
34+
"suggests": "#lwjgl_version#",
35+
"uid": "#lwjgl_uid#"
3636
}
3737
],
3838
"mainClass": "com.fox2code.foxloader.launcher.ClientMain",
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"formatVersion": 1,
3+
"libraries": [
4+
{
5+
"name": "com.fox2code:lwjglx:#lwjglx_version#",
6+
"url": "https://cdn.fox2code.com/maven"
7+
}
8+
],
9+
"name": "LWJGLX",
10+
"type": "release",
11+
"uid": "com.fox2code.lwjglx",
12+
"version": "#lwjglx_version#"
13+
}

0 commit comments

Comments
 (0)