mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 13:05:52 +08:00
refactor: remove standalone Loader module and consolidate loader into OrangeX
- Delete Loader/ module (build.gradle + Loader.java) - Delete Detector.java and DetectorType.java - Add simplified Loader.java inside OrangeX module - Add Utils.java for finding Minecraft ClassLoader
This commit is contained in:
1 parent
9f779dec5e
commit
ccada5472f
6 files changed
+41
-179
No files matched your search
@@ -1,21 +0,0 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id "com.gradleup.shadow" version "8.3.9"
|
||||
}
|
||||
|
||||
group = 'cn.xiaozhou233.orangex.loader'
|
||||
version = 'unspecified'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly files("../libraries/JuiceAgent-API-1.4.1+build.1.jar")
|
||||
implementation files("../libraries/JuiceRemapper-1.0-SNAPSHOT-all.jar")
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
archiveFileName = 'Loader.jar'
|
||||
relocate 'org.objectweb.asm', 'cn.xiaozhou233.asm9'
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.loader;
|
||||
|
||||
|
||||
import cn.xiaozhou233.juiceagent.api.JuiceAgent;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class Loader {
|
||||
public static String userDir = System.getProperty("user.home");
|
||||
public static Thread clientThread;
|
||||
public static ClassLoader minecraftClassLoader;
|
||||
|
||||
public static void start() {
|
||||
System.out.println("======== Loader START ========");
|
||||
|
||||
// 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");
|
||||
}
|
||||
|
||||
// // Check if LaunchWrapper exists
|
||||
// if (Detector.isLaunchWrapper()){
|
||||
// System.out.println("LaunchWrapper detected");
|
||||
// }
|
||||
|
||||
// Get Minecraft ClassLoader
|
||||
minecraftClassLoader = clientThread.getContextClassLoader();
|
||||
System.out.println("Minecraft ClassLoader: " + minecraftClassLoader);
|
||||
|
||||
// switch (Detector.detect()) {
|
||||
// case MCP:
|
||||
// break;
|
||||
// case VANILLA:
|
||||
// // No more support
|
||||
// JOptionPane.showMessageDialog(
|
||||
// null,
|
||||
// "Not support Vanilla Client! \n 不支持原版客户端!",
|
||||
// "Vanilla Obfuscation",
|
||||
// JOptionPane.ERROR_MESSAGE
|
||||
// );
|
||||
// throw new IllegalStateException("Not support Vanilla Client!");
|
||||
// case LUNAR:
|
||||
// break;
|
||||
// case BADLION:
|
||||
// // No more support
|
||||
// JOptionPane.showMessageDialog(
|
||||
// null,
|
||||
// "Not support Badlion Client! \n 不支持Badlion客户端!",
|
||||
// "Badlion Obfuscation",
|
||||
// JOptionPane.ERROR_MESSAGE
|
||||
// );
|
||||
// throw new IllegalStateException("Not support Badlion Client!");
|
||||
// case UNKNOWN:
|
||||
// JOptionPane.showMessageDialog(
|
||||
// null,
|
||||
// "Inject Failed! Cause: Unknown Obfuscation \n 注入失败! 原因: 未知的混淆",
|
||||
// "Unknown Obfuscation",
|
||||
// JOptionPane.ERROR_MESSAGE
|
||||
// );
|
||||
// throw new IllegalStateException("Unknown Obfuscation");
|
||||
// default:
|
||||
// JOptionPane.showMessageDialog(
|
||||
// null,
|
||||
// "Inject Failed! Cause: Unknown Obfuscation",
|
||||
// "Unknown Obfuscation",
|
||||
// JOptionPane.ERROR_MESSAGE
|
||||
// );
|
||||
// throw new IllegalStateException("Unexpected value: " + Detector.detect());
|
||||
// }
|
||||
|
||||
// Load OrangeX
|
||||
File injectionFile = new File(userDir + "/.orangex/OrangeX.jar");
|
||||
System.out.println("OrangeX Injection: " + injectionFile.getAbsolutePath());
|
||||
JuiceAgent.addToClassLoader(injectionFile.getAbsolutePath(), minecraftClassLoader);
|
||||
|
||||
// Start OrangeX
|
||||
try {
|
||||
Class<?> orangeXClass = Class.forName("cn.xiaozhou233.orangex.OrangeX", true, minecraftClassLoader);
|
||||
Object orangeXInstance = orangeXClass.getMethod("getInstance").invoke(null);
|
||||
orangeXClass.getMethod("start").invoke(orangeXInstance);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
System.out.println("======== Loader END ========");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.detector;
|
||||
|
||||
public class Detector {
|
||||
|
||||
private static boolean classExists(String className) {
|
||||
String resourceName = className.replace('.', '/') + ".class";
|
||||
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
if (classLoader == null) {
|
||||
classLoader = Detector.class.getClassLoader();
|
||||
}
|
||||
|
||||
return classLoader.getResource(resourceName) != null;
|
||||
}
|
||||
|
||||
public static DetectorType detect() {
|
||||
|
||||
// Lunar Client Detection
|
||||
if (classExists("com.moonsworth.lunar.genesis.Genesis")) {
|
||||
System.out.println("Lunar class found!");
|
||||
return DetectorType.LUNAR;
|
||||
}
|
||||
|
||||
System.out.println("Lunar class not found");
|
||||
|
||||
// Badlion Detection
|
||||
if (classExists("net.badlion.client.Wrapper")) {
|
||||
System.out.println("Badlion class found!");
|
||||
return DetectorType.BADLION;
|
||||
}
|
||||
|
||||
System.out.println("Badlion class not found");
|
||||
|
||||
// MCP Detection
|
||||
if (classExists("net.minecraft.client.Minecraft")) {
|
||||
System.out.println("MCP class found!");
|
||||
return DetectorType.MCP;
|
||||
}
|
||||
System.out.println("MCP class not found");
|
||||
|
||||
// Vanilla Detection
|
||||
if (classExists("ave")) {
|
||||
System.out.println("Vanilla class found!");
|
||||
return DetectorType.VANILLA;
|
||||
}
|
||||
|
||||
System.out.println("Vanilla class not found");
|
||||
|
||||
return DetectorType.UNKNOWN;
|
||||
}
|
||||
|
||||
public static boolean isLaunchWrapper() {
|
||||
return classExists("net.minecraft.launchwrapper.Launch");
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package cn.xiaozhou233.orangex.detector;
|
||||
|
||||
public enum DetectorType {
|
||||
BADLION,
|
||||
LUNAR,
|
||||
VANILLA,
|
||||
MCP,
|
||||
UNKNOWN
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package cn.xiaozhou233.orangex.loader;
|
||||
|
||||
|
||||
import cn.xiaozhou233.orangex.loader.detector.Detector;
|
||||
import cn.xiaozhou233.orangex.loader.utils.Utils;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class Loader {
|
||||
private static ClassLoader minecraftClassLoader;
|
||||
|
||||
public static void start() {
|
||||
System.out.println("======== Loader START ========");
|
||||
minecraftClassLoader = Utils.findMinecraftClassLoader();
|
||||
|
||||
Detector.detect(minecraftClassLoader);
|
||||
System.out.println("======== Loader END ========");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package cn.xiaozhou233.orangex.loader.utils;
|
||||
|
||||
public class Utils {
|
||||
public static ClassLoader findMinecraftClassLoader() {
|
||||
Thread thread = null;
|
||||
// Find client thread
|
||||
for (Thread t : Thread.getAllStackTraces().keySet()) {
|
||||
if ("Client thread".equals(t.getName()) || "Render thread".equals(t.getName())) {
|
||||
thread = t;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (thread == null) {
|
||||
throw new IllegalStateException("Cannot find Minecraft client thread");
|
||||
}
|
||||
ClassLoader minecraftClassLoader = thread.getContextClassLoader();
|
||||
System.out.println("Minecraft ClassLoader: " + minecraftClassLoader);
|
||||
|
||||
return minecraftClassLoader;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user