feat: add YMixin-based mixin system with JuiceRemapper obfuscation support

This commit is contained in:
xiaozhou233 committed 2026-08-19 20:12:08 +08:00
1 parent 33232a106c
commit ecf914a5e8
14 files changed
+26545 -3

No files matched your search

+1
View File
@@ -12,6 +12,7 @@ repositories {
dependencies {
compileOnly files("../libraries/JuiceAgent-API-1.4.1+build.1.jar")
implementation files("../libraries/JuiceRemapper-1.0-SNAPSHOT-all.jar")
}
shadowJar {
@@ -2,6 +2,7 @@ package cn.xiaozhou233.orangex.loader;
import cn.xiaozhou233.juiceagent.api.JuiceAgent;
import cn.xiaozhou233.juiceremapper.JuiceRemapper;
import java.io.File;
@@ -28,6 +29,23 @@ public class Loader {
minecraftClassLoader = clientThread.getContextClassLoader();
System.out.println("Minecraft ClassLoader: " + minecraftClassLoader);
// Check Obfuscation
// Only Check MCP or Vanilla Obfuscation
try {
Class.forName("net.minecraft.client.Minecraft");
} catch (ClassNotFoundException e) {
System.out.println("Obfuscation detected");
// Load JuiceRemapper Native
System.load(new File(userDir, "/.orangex/libremapper.dll").getAbsolutePath());
JuiceRemapper.init();
JuiceRemapper.addInclude("cn/xiaozhou233/orangex/");
JuiceRemapper.addExclude("cn/xiaozhou233/orangex/mixin");
}
// Load OrangeX
File injectionFile = new File(userDir + "/.orangex/OrangeX.jar");
System.out.println("OrangeX Injection: " + injectionFile.getAbsolutePath());
@@ -38,8 +56,6 @@ public class Loader {
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);
}
+11 -1
View File
@@ -13,8 +13,18 @@ repositories {
dependencies {
compileOnly("org.projectlombok:lombok:1.18.46")
annotationProcessor("org.projectlombok:lombok:1.18.46")
compileOnly fileTree(dir: "../libraries", include: ["**/*.jar"])
implementation files("../libraries/ymixin.jar")
// https://mvnrepository.com/artifact/org.ow2.asm/asm-tree
implementation("org.ow2.asm:asm-tree:9.8")
// https://mvnrepository.com/artifact/org.ow2.asm/asm-tree
implementation("org.ow2.asm:asm:9.8")
}
shadowJar {
archiveFileName = 'OrangeX.jar'
}
relocate 'org.objectweb.asm', 'cn.xiaozhou233.asm9'
relocate 'com.google.gson', "cn.xiaozhou233.gson"
}
@@ -1,9 +1,16 @@
package cn.xiaozhou233.orangex;
import cn.xiaozhou233.orangex.mixin.MixinManager;
public class OrangeX {
public static final OrangeX INSTANCE = new OrangeX();
public MixinManager mixinManager = new MixinManager();
public void start() {
System.out.println("OrangeX starting...");
mixinManager.start();
System.out.println("OrangeX started.");
}
@@ -0,0 +1,86 @@
package cn.xiaozhou233.orangex.mixin;
import cn.xiaozhou233.juiceremapper.utils.IOUtils;
import cn.xiaozhou233.orangex.mixin.impl.MixinMinecraft;
import cn.xiaozhou233.orangex.utils.JuiceAgentFacade;
import cn.yapeteam.ymixin.Transformer;
import cn.yapeteam.ymixin.YMixin;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
public final class MixinManager {
public void start() {
ClassLoader cl = MixinManager.class.getClassLoader();
// Check Obfuscation
String content = null;
try {
Class.forName("net.minecraft.client.Minecraft");
} catch (ClassNotFoundException e) {
System.out.println("[OrangeX] Obfuscation detected, use mapping.");
InputStream stream = MixinManager.class.getResourceAsStream("/joined.srg");
try {
content = new String(
IOUtils.toByteArray(stream),
StandardCharsets.UTF_8
);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
YMixin.init(
className -> {
try {
return Class.forName(
className.replace("/", "."),
false,
cl
);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
},
clazz -> {
byte[] classBytes = JuiceAgentFacade.getClassBytes(clazz);
if (classBytes == null) {
throw new RuntimeException(
"ClassBytes null: " + clazz.getName()
);
}
return classBytes;
},
null,
null,
content
);
Transformer transformer = new Transformer();
try {
transformer.addMixin(MixinMinecraft.class);
} catch (Throwable e) {
throw new RuntimeException("Failed to add mixin", e);
}
transformer.transform().forEach((name, bytes) -> {
try {
Class<?> targetClass = Class.forName(name, false, cl);
boolean ok = JuiceAgentFacade.redefineClass(targetClass, bytes);
if (!ok) {
throw new RuntimeException("Redefine failed: " + name);
}
System.out.println("[OrangeX] Redefined class: " + name);
} catch (Throwable e) {
throw new RuntimeException(
"Failed to redefine class: " + name,
e
);
}
});
}
}
@@ -0,0 +1,47 @@
package cn.xiaozhou233.orangex.mixin.impl;
import cn.xiaozhou233.orangex.OrangeX;
import cn.yapeteam.ymixin.annotations.Inject;
import cn.yapeteam.ymixin.annotations.Local;
import cn.yapeteam.ymixin.annotations.Mixin;
import cn.yapeteam.ymixin.annotations.Target;
import net.minecraft.client.Minecraft;
import org.lwjgl.input.Keyboard;
@Mixin(Minecraft.class)
public class MixinMinecraft {
@Inject(method = "runGameLoop", desc = "()V", target = @Target("HEAD"))
private void onLoop() {
System.out.println("LOOP!");
}
@Inject(method = "runTick", desc = "()V", target = @Target("HEAD"))
public void onTick() {
}
@Inject(method = "shutdownMinecraftApplet", desc = "()V", target = @Target("HEAD"))
public void onShutdown() {
OrangeX.getInstance().stop();
}
@Inject(
method = "runTick", desc = "()V",
target = @Target(
value = "INVOKESTATIC",
target = "org/lwjgl/input/Keyboard.getEventKeyState()Z",
shift = Target.Shift.AFTER
)
)
public void onKey(@Local(source = "key", index = 1) int key) {
if (Minecraft.getMinecraft().currentScreen == null && Keyboard.getEventKeyState())
;
}
@Inject(method = "loadWorld", desc = "(Lnet/minecraft/client/multiplayer/WorldClient;Ljava/lang/String;)V", target = @Target("HEAD"))
public void onLoadWorld() {
}
}
@@ -0,0 +1,59 @@
package cn.xiaozhou233.orangex.utils;
import java.lang.reflect.Method;
public final class JuiceAgentFacade {
private static final Class<?> JL;
private static final Method GET_CLASS_BYTES;
private static final Method REDEFINE_CLASS;
private static final Method GET_LOADED_CLASSES;
static {
try {
JL = Class.forName(
"cn.xiaozhou233.juiceagent.api.JuiceAgent",
true,
ClassLoader.getSystemClassLoader()
);
GET_CLASS_BYTES = JL.getMethod("getClassBytes", Class.class);
REDEFINE_CLASS = JL.getMethod(
"redefineClass",
Class.class,
byte[].class,
int.class
);
GET_LOADED_CLASSES = JL.getMethod("getLoadedClasses");
} catch (Exception e) {
throw new RuntimeException("Failed to init JuiceFacade", e);
}
}
private JuiceAgentFacade() {}
public static byte[] getClassBytes(Class<?> clazz) {
try {
return (byte[]) GET_CLASS_BYTES.invoke(null, clazz);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static boolean redefineClass(Class<?> clazz, byte[] bytes) {
try {
return (boolean) REDEFINE_CLASS.invoke(null, clazz, bytes, bytes.length);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static Class<?>[] getLoadedClasses() {
try {
return (Class<?>[]) GET_LOADED_CLASSES.invoke(null);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
File diff suppressed because it is too large. Load diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.