Skip to content

Commit bdee4e1

Browse files
authored
Merge pull request #248 from AngelAuraMC/feat/misc
- OpenGL fallback for 26.2-snapshot-x (versions with the new Vulkan backend) should now work properly - Fixed mods using Veil 3.1.0 or lower crashing on arm/arm64 architectures
2 parents 4d57d49 + 1cb34a0 commit bdee4e1

4 files changed

Lines changed: 84 additions & 1 deletion

File tree

app_pojavlauncher/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ static def getDate() { return new Date().format('yyyyMMdd') }
77
def getVersionName = {
88
// Get the last version tag, as well as the short head of the last commit
99
ByteArrayOutputStream TAG = new ByteArrayOutputStream()
10-
String semVer = "1.1.3"
10+
String semVer = "1.1.4"
1111
// Used by the fallback for github actions
1212
ByteArrayOutputStream TAG_PART_COMMIT = new ByteArrayOutputStream()
1313
String TAG_STRING

app_pojavlauncher/src/main/jni/egl_bridge.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,12 @@ EXTERNAL_API void pojavSetWindowHint(int hint, int value) {
209209
// pojavInitVulkan();
210210
break;
211211
case GLFW_OPENGL_API:
212+
const char *renderer = getenv("AMETHYST_RENDERER");
213+
if (strncmp("opengles", renderer, 8) == 0) {
214+
pojav_environ->config_renderer = RENDERER_GL4ES;
215+
} else if (strcmp(renderer, "vulkan_zink") == 0) {
216+
pojav_environ->config_renderer = RENDERER_VK_ZINK;
217+
}
212218
/* Nothing to do: initialization is called in pojavCreateContext */
213219
// pojavInitOpenGL();
214220
break;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package org.angelauramc.methodsInjectorAgent.mod_compatibility_injector;
2+
3+
import java.lang.instrument.ClassFileTransformer;
4+
import java.lang.instrument.Instrumentation;
5+
import java.security.ProtectionDomain;
6+
7+
import org.angelauramc.methodsInjectorAgent.lwjgl2_methods_injector.ALC10Injector;
8+
import org.objectweb.asm.ClassReader;
9+
import org.objectweb.asm.ClassVisitor;
10+
import org.objectweb.asm.ClassWriter;
11+
import org.objectweb.asm.MethodVisitor;
12+
import org.objectweb.asm.Opcodes;
13+
14+
// Older veil versions overrides imgui.library.name with libimgui-javaarm64.dylib if on arm/arm64
15+
// which isn't the right lib. So veil fails to load.
16+
public class VeilImguiOverrideDisable extends ClassVisitor implements ClassFileTransformer {
17+
protected VeilImguiOverrideDisable(int api) {
18+
super(api);
19+
}
20+
21+
public static void premain(String args, Instrumentation inst) {
22+
inst.addTransformer(new ClassFileTransformer() {
23+
public byte[] transform(ClassLoader l, String name, Class c,
24+
ProtectionDomain d, byte[] b) {
25+
if (!"foundry/veil/impl/client/imgui/VeilImGuiImpl".equals(name)) {
26+
return null;
27+
}
28+
ClassReader cr = new ClassReader(b);
29+
ClassWriter cw = new ClassWriter(cr, 0);
30+
ClassVisitor cv = new DisableMethodAdapter(cw);
31+
cr.accept(cv, 0);
32+
return cw.toByteArray();
33+
}
34+
});
35+
}
36+
37+
public static class DisableMethodAdapter extends ClassVisitor {
38+
39+
public DisableMethodAdapter(ClassVisitor cv) {
40+
super(Opcodes.ASM4, cv);
41+
}
42+
43+
@Override
44+
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
45+
MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
46+
if (name.equals("setImGuiPath")
47+
&& desc.equals("()V")) {
48+
try { // Minecraft makes it ugly if we use println
49+
System.out.write(("Amethyst-Android: Patching VeilImGuiImpl for faulty setImGuiPath()...\n" +
50+
"This issue is fixed in Veil 3.1.1 and above. See https://github.com/FoundryMC/Veil/commit/8e0e09365049a106bfa3634e2ed78a0310c5b4df\n" +
51+
"The intended target of this patch is Veil 3.1.0 and below. If you see this log output without Veil 3.1.0 or lower running, please send a bug report to Amethyst-Android.\n" +
52+
"https://github.com/AngelAuraMC/Amethyst-Android/issues/new?template=bug_report.yml").getBytes());
53+
54+
System.out.flush();
55+
} catch (Exception ignored) {}
56+
return getMethodVisitor(mv);
57+
}
58+
return mv;
59+
}
60+
private MethodVisitor getMethodVisitor(MethodVisitor delegate) {
61+
return new MethodVisitor(this.api, null) {
62+
@Override
63+
public void visitCode() {
64+
delegate.visitCode();
65+
delegate.visitInsn(Opcodes.RETURN); // Add our return
66+
delegate.visitMaxs(0, 0); // ClassWriter.COMPUTE_FRAMES will fix this
67+
delegate.visitEnd();
68+
}
69+
};
70+
}
71+
}
72+
}
73+
74+
75+

methods_injector_agent/src/main/java/org/angelauramc/methodsInjectorAgent/startInjectors.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.angelauramc.methodsInjectorAgent.lwjgl2_methods_injector.ALC10Injector;
44
import org.angelauramc.methodsInjectorAgent.lwjgl2_methods_injector.ASM5OverrideInjector;
5+
import org.angelauramc.methodsInjectorAgent.mod_compatibility_injector.VeilImguiOverrideDisable;
56

67
import java.lang.instrument.Instrumentation;
78

@@ -19,6 +20,7 @@ public static void premain(String args, Instrumentation inst) {
1920
if (implVersion == null) implVersion = "not found";
2021
System.out.println("Amethyst-Android: Detected ASM version: " + implVersion);
2122
ALC10Injector.premain(args, inst);
23+
VeilImguiOverrideDisable.premain(args, inst);
2224
// This is the version we override old asm vers with. So we add the patches
2325
// so the older version bugs are ported.
2426
if (implVersion.equals("5.0.4")) ASM5OverrideInjector.premain(args, inst);

0 commit comments

Comments
 (0)