-
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.
Potential fix for xrandr xvfb on old versions
- Loading branch information
1 parent
9518393
commit 2bfdfc6
Showing
8 changed files
with
152 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
41 changes: 41 additions & 0 deletions
41
...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,41 @@ | ||
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; | ||
|
||
@CustomLog | ||
public class XvfbLwjglTransformer extends AbstractClassTransformer { | ||
public XvfbLwjglTransformer() { | ||
super("org/lwjgl/opengl/LinuxDisplay"); | ||
} | ||
|
||
@Override | ||
protected void transform(ClassNode cn) { | ||
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" | ||
} | ||
] | ||
} |