mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 21:15:53 +08:00
Feat: Add Loader module
Add Loader bootstrap that locates the Minecraft client thread, reuses its ClassLoader, injects OrangeX.jar via JuiceAgent and invokes OrangeX.start(). Also add JuiceAgent-API jar, register the Loader module in settings.gradle and update IDEA project config.
This commit is contained in:
1 parent
f6fa7c2a23
commit
d39eb63be4
7 files changed
+211
-3
No files matched your search
@@ -0,0 +1,19 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id("com.gradleup.shadow") version "8.3.11"
|
||||
}
|
||||
|
||||
group = 'cn.xiaozhou233.orangex.injector'
|
||||
version = 'unspecified'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation files("../libraries/JuiceAgent-API-1.4.1+build.1.jar")
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package cn.xiaozhou233.orangex.loader;
|
||||
|
||||
import cn.xiaozhou233.juiceagent.api.JuiceAgent;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class Loader {
|
||||
public static final String VERSION = "1.0.0-SNAPSHOT";
|
||||
public static final String ORANGEX_CLASS = "cn.xiaozhou233.orangex.OrangeX";
|
||||
|
||||
public static String OrangeXPath = new File(System.getProperty("user.home")+"/.orangex").getAbsolutePath();
|
||||
public static Thread clientThread;
|
||||
public static ClassLoader minecraftClassLoader;
|
||||
|
||||
public static void entry() {
|
||||
System.out.println("OrangeX-Loader " + VERSION + " loaded!");
|
||||
|
||||
// Find client thread
|
||||
for (Thread t : Thread.getAllStackTraces().keySet()) {
|
||||
if ("Client thread".equals(t.getName())) {
|
||||
clientThread = t;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (clientThread == null) {
|
||||
throw new IllegalStateException("Cannot find Minecraft client thread");
|
||||
}
|
||||
|
||||
// Get Minecraft ClassLoader
|
||||
minecraftClassLoader = clientThread.getContextClassLoader();
|
||||
System.out.println("Minecraft ClassLoader: " + minecraftClassLoader);
|
||||
|
||||
// Dev Only: Load JuiceAgent
|
||||
if (isDevEnvironment()) {
|
||||
System.load(new File("../../natives/libagent.dll").getAbsolutePath());
|
||||
JuiceAgent.init("");
|
||||
}
|
||||
|
||||
// Load OrangeX
|
||||
File orangexFile;
|
||||
if (isDevEnvironment()) {
|
||||
orangexFile = new File("../../out/tmp/OrangeX.jar");
|
||||
} else {
|
||||
orangexFile = new File(OrangeXPath + "/OrangeX.jar");
|
||||
}
|
||||
System.out.println("OrangeX Injection: " + orangexFile.getAbsolutePath());
|
||||
JuiceAgent.addToClassLoader(orangexFile.getAbsolutePath(), minecraftClassLoader);
|
||||
|
||||
// Start OrangeX
|
||||
try {
|
||||
Class<?> orangeX = Class.forName(ORANGEX_CLASS, true, minecraftClassLoader);
|
||||
Object orangeXInstance = orangeX.getMethod("getInstance").invoke(null);
|
||||
orangeX.getMethod("start").invoke(orangeXInstance);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Failed to invoke OrangeX start!");
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isDevEnvironment() {
|
||||
return Boolean.getBoolean("orangex.dev");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user