mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 13:05:52 +08:00
Feat: Support Fabric 26.2 injection
- Expose OrangeX.jar through KnotClassDelegate.addCodeSource for Fabric - Resolve 26.2 mappings by runtime class visibility instead of loader type - Keep identity mappings for the current Mojang-named Fabric 26.2 runtime
This commit is contained in:
1 parent
1699df9c5d
commit
40ca99f853
2 files changed
+64
-7
No files matched your search
@@ -4,6 +4,8 @@ import cn.xiaozhou233.juiceagent.api.JuiceAgent;
|
||||
import cn.xiaozhou233.orangex.loader.classloader.GameClassLoaderResolver;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class Loader {
|
||||
public static final String VERSION = "1.0.0-SNAPSHOT";
|
||||
@@ -47,7 +49,7 @@ public class Loader {
|
||||
orangexFile = new File(OrangeXPath + "/OrangeX.jar");
|
||||
}
|
||||
System.out.println("OrangeX Injection: " + orangexFile.getAbsolutePath());
|
||||
JuiceAgent.addToClassLoader(orangexFile.getAbsolutePath(), minecraftClassLoader);
|
||||
addToGameClassLoader(orangexFile, minecraftClassLoader);
|
||||
|
||||
// Start OrangeX
|
||||
try {
|
||||
@@ -87,4 +89,44 @@ public class Loader {
|
||||
|
||||
return renderThread;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fabric's KnotClassLoader keeps its own code-source list and rejects jars
|
||||
* that were added with a plain URLClassLoader-style addURL. Expose the jar
|
||||
* through KnotClassDelegate#addCodeSource, which updates both the code
|
||||
* source list and the internal URL loader.
|
||||
*/
|
||||
private static void addToGameClassLoader(File jar, ClassLoader loader) {
|
||||
if (isKnotClassLoader(loader)) {
|
||||
try {
|
||||
addToKnotClassLoader(loader, jar.toPath());
|
||||
return;
|
||||
} catch (ReflectiveOperationException | RuntimeException e) {
|
||||
System.err.println(
|
||||
"Failed to expose " + jar.getName()
|
||||
+ " to Fabric KnotClassLoader: " + e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
JuiceAgent.addToClassLoader(jar.getAbsolutePath(), loader);
|
||||
}
|
||||
|
||||
private static boolean isKnotClassLoader(ClassLoader loader) {
|
||||
return loader != null
|
||||
&& "net.fabricmc.loader.impl.launch.knot.KnotClassLoader"
|
||||
.equals(loader.getClass().getName());
|
||||
}
|
||||
|
||||
private static void addToKnotClassLoader(ClassLoader loader, Path jar)
|
||||
throws ReflectiveOperationException {
|
||||
Method getDelegate = loader.getClass().getDeclaredMethod("getDelegate");
|
||||
getDelegate.setAccessible(true);
|
||||
Object delegate = getDelegate.invoke(loader);
|
||||
|
||||
Method addCodeSource = delegate.getClass()
|
||||
.getMethod("addCodeSource", Path.class);
|
||||
addCodeSource.setAccessible(true);
|
||||
addCodeSource.invoke(delegate, jar);
|
||||
}
|
||||
}
|
||||
@@ -31,15 +31,16 @@ public class MappingManager {
|
||||
}
|
||||
|
||||
case V26_2: {
|
||||
if (loaderType == LoaderType.VANILLA
|
||||
|| loaderType == LoaderType.MCP
|
||||
|| loaderType == LoaderType.NEOFORGE) {
|
||||
// 26.x runtimes use Mojang names for classes, fields and
|
||||
// methods, so no obfuscation mapping is needed.
|
||||
// 26.x normally uses Mojang names. Fabric 26.2 currently ships
|
||||
// empty intermediary mappings, so it also runs with Mojang
|
||||
// names. Verify the runtime instead of trusting the loader type.
|
||||
if (usesMojangNames(info)) {
|
||||
resolver = new IdentityFallbackMappingResolver();
|
||||
} else {
|
||||
throw new RuntimeException(
|
||||
"Unsupported loader for 26.2: " + loaderType);
|
||||
"Unsupported runtime naming for 26.2 ("
|
||||
+ loaderType + "): expected "
|
||||
+ "net.minecraft.client.Minecraft");
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -54,6 +55,20 @@ public class MappingManager {
|
||||
return resolver != null;
|
||||
}
|
||||
|
||||
private static boolean usesMojangNames(RuntimeInfo info) {
|
||||
ClassLoader loader = info.getMinecraftClassLoader();
|
||||
if (loader == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
Class.forName("net.minecraft.client.Minecraft", false, loader);
|
||||
return true;
|
||||
} catch (Throwable ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static MappingResolver getResolver() {
|
||||
if (!isInitialized()) {
|
||||
System.out.println("Resolver not initialized!");
|
||||
|
||||
Reference in new issue
Block a user