-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #212 from 3arthqu4ke/211-1122-xvfb-does-not-work
Fixed xvfb on older versions with lwjgl 2.9.4, like 1.12.2
- Loading branch information
Showing
8 changed files
with
159 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...src/main/java/me/earth/headlessmc/launcher/instrumentation/xvfb/XvfbLwjglTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package me.earth.headlessmc.launcher.instrumentation.xvfb; | ||
|
||
import lombok.CustomLog; | ||
import me.earth.headlessmc.launcher.instrumentation.AbstractClassTransformer; | ||
import me.earth.headlessmc.launcher.instrumentation.InstrumentationHelper; | ||
import me.earth.headlessmc.launcher.instrumentation.Target; | ||
import org.objectweb.asm.Opcodes; | ||
import org.objectweb.asm.tree.*; | ||
|
||
import java.util.Locale; | ||
|
||
/** | ||
* Lwjgl 2.9.4 (Mc 1.12.2) crashes in Github actions with xvfb at getAvailableDisplayModes, | ||
* because the array returned by XRandR.getResolutions is empty. | ||
* This patches that by always using XF86VIDMODE instead of XRANDR. | ||
*/ | ||
@CustomLog | ||
public class XvfbLwjglTransformer extends AbstractClassTransformer { | ||
public XvfbLwjglTransformer() { | ||
super("org/lwjgl/opengl/LinuxDisplay"); | ||
} | ||
|
||
@Override | ||
protected void transform(ClassNode cn) { | ||
// TODO: Actually isXrandrSupported can also be overriden by setting the system property LWJGL_DISABLE_XRANDR | ||
// but this would theoretically cover the case when XF86VIDMODE is not supported? | ||
for (MethodNode mn : cn.methods) { | ||
if ("getBestDisplayModeExtension".equals(mn.name) && "()I".equals(mn.desc)) { | ||
for (AbstractInsnNode insnNode : mn.instructions) { | ||
if (insnNode instanceof IntInsnNode && insnNode.getOpcode() == Opcodes.BIPUSH) { | ||
IntInsnNode intInsnNode = (IntInsnNode) insnNode; | ||
if (intInsnNode.operand == 10) { // private static final int XRANDR = 10; | ||
log.info("Found BI_PUSH XRANDR, replacing with XF86VIDMODE"); | ||
intInsnNode.operand = 11; // XF86VIDMODE, idk lets just try this? | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public boolean matches(Target target) { | ||
return target.getPath().toLowerCase(Locale.ENGLISH).contains("lwjgl") | ||
&& !target.getPath().endsWith(InstrumentationHelper.LWJGL_JAR); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...src/test/java/me/earth/headlessmc/launcher/instrumentation/InstrumentationHelperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package me.earth.headlessmc.launcher.instrumentation; | ||
|
||
import me.earth.headlessmc.launcher.UsesResources; | ||
import me.earth.headlessmc.launcher.launch.LaunchOptions; | ||
import me.earth.headlessmc.launcher.version.ParsesVersions; | ||
import me.earth.headlessmc.launcher.version.Version; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class InstrumentationHelperTest implements UsesResources, ParsesVersions { | ||
@Test | ||
public void testAddXvfbTransformer() { | ||
Version version = parseVersion(getJsonObject("version_with_old_lwjgl.json")); | ||
LaunchOptions launchOptions = LaunchOptions.builder().version(version).build(); | ||
List<Transformer> transformers = new ArrayList<>(); | ||
InstrumentationHelper.addXvfbTransformer(launchOptions, transformers); | ||
assertEquals(1, transformers.size()); | ||
|
||
version = parseVersion(getJsonObject("version_with_new_lwjgl.json")); | ||
launchOptions = LaunchOptions.builder().version(version).build(); | ||
transformers = new ArrayList<>(); | ||
InstrumentationHelper.addXvfbTransformer(launchOptions, transformers); | ||
assertEquals(0, transformers.size()); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
headlessmc-launcher/src/test/resources/version_with_new_lwjgl.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"id": "version-without-parent", | ||
"inheritsFrom": "1.18", | ||
"releaseTime": "2022-06-17T19:10:29+0000", | ||
"time": "2022-06-17T19:10:29+0000", | ||
"type": "release", | ||
"mainClass": "me.earth.headlessmc.runtime.Main", | ||
"arguments": { | ||
"game": [], | ||
"jvm": [ | ||
"-DMainClass\u003d net.minecraft.client.main.Main " | ||
] | ||
}, | ||
"libraries": [ | ||
{ | ||
"name": "org.lwjgl.lwjgl:lwjgl-platform:3.1.0", | ||
"url": "http://lwjgl-url" | ||
} | ||
] | ||
} |
20 changes: 20 additions & 0 deletions
20
headlessmc-launcher/src/test/resources/version_with_old_lwjgl.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"id": "version-without-parent", | ||
"inheritsFrom": "1.18", | ||
"releaseTime": "2022-06-17T19:10:29+0000", | ||
"time": "2022-06-17T19:10:29+0000", | ||
"type": "release", | ||
"mainClass": "me.earth.headlessmc.runtime.Main", | ||
"arguments": { | ||
"game": [], | ||
"jvm": [ | ||
"-DMainClass\u003d net.minecraft.client.main.Main " | ||
] | ||
}, | ||
"libraries": [ | ||
{ | ||
"name": "org.lwjgl.lwjgl:lwjgl-platform:2.9.4-nightly-20150209", | ||
"url": "http://lwjgl-url" | ||
} | ||
] | ||
} |