mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 13:05:52 +08:00
Feat: Add OrangeX module with MCPLoader injection
This commit is contained in:
1 parent
818ce5910a
commit
80307f6edc
15 files changed
+149
-2
No files matched your search
@@ -0,0 +1,51 @@
|
||||
package cn.xiaozhou233.orangex.loader;
|
||||
|
||||
import cn.xiaozhou233.juiceagent.api.JuiceAgent;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public enum MCPLoader {
|
||||
INSTANCE;
|
||||
|
||||
public static String userDir = System.getProperty("user.home");
|
||||
public static Thread clientThread;
|
||||
public static ClassLoader minecraftClassLoader;
|
||||
|
||||
public void start() {
|
||||
System.out.println("======== OrangeX MCP Loader ========");
|
||||
System.load(new File("../natives/libagent.dll").getAbsolutePath());
|
||||
JuiceAgent.init("");
|
||||
|
||||
// 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);
|
||||
|
||||
// Load OrangeX
|
||||
File injectionFile = new File("../../out/tmp/OrangeX.jar");
|
||||
System.out.println("OrangeX Injection: " + injectionFile.getAbsolutePath());
|
||||
JuiceAgent.addToClassLoader(injectionFile.getAbsolutePath(), minecraftClassLoader);
|
||||
|
||||
try {
|
||||
Class<?> orangeXClass = Class.forName("cn.xiaozhou233.orangex.OrangeX", true, minecraftClassLoader);
|
||||
Object instance = orangeXClass.getMethod("getInstance").invoke(null);
|
||||
orangeXClass.getMethod("start").invoke(instance);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
System.out.println("OrangeX MCP Loader Stopping...");
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.minecraft.client;
|
||||
|
||||
import cn.xiaozhou233.orangex.loader.MCPLoader;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
@@ -589,6 +590,10 @@ public class Minecraft implements IThreadListener, IPlayerUsage
|
||||
}
|
||||
|
||||
this.renderGlobal.makeEntityOutlineShader();
|
||||
|
||||
// OrangeX MCP Loader Inject Point //
|
||||
MCPLoader.INSTANCE.start();
|
||||
// OrangeX MCP Loader Inject Point //
|
||||
}
|
||||
|
||||
private void registerMetadataSerializers()
|
||||
@@ -1031,6 +1036,10 @@ public class Minecraft implements IThreadListener, IPlayerUsage
|
||||
this.stream.shutdownStream();
|
||||
logger.info("Stopping!");
|
||||
|
||||
// OrangeX MCP Loader Inject Point //
|
||||
MCPLoader.INSTANCE.stop();
|
||||
// OrangeX MCP Loader Inject Point //
|
||||
|
||||
try
|
||||
{
|
||||
this.loadWorld((WorldClient)null);
|
||||
|
||||
Reference in new issue
Block a user