Init Commit

This commit is contained in:
xiaozhou233 committed 2026-01-16 00:01:38 +08:00
commit d492ba7224
39 files changed
+27426

No files matched your search

@@ -0,0 +1,24 @@
package cn.xiaozhou233.orangex;
import cn.xiaozhou233.orangex.mixin.MixinManager;
import cn.xiaozhou233.orangex.module.ModuleManager;
import lombok.Getter;
import org.greenrobot.eventbus.EventBus;
public class OrangeX {
@Getter
public static final EventBus eventBus = EventBus.builder()
.logNoSubscriberMessages(false)
.logSubscriberExceptions(false)
.sendNoSubscriberEvent(false)
.sendSubscriberExceptionEvent(false)
.installDefaultEventBus();
public static void start() {
System.out.println("OrangeX loading...");
MixinManager.start();
ModuleManager.registerAll();
}
}
@@ -0,0 +1,4 @@
package cn.xiaozhou233.orangex.event;
public class Event {
}
@@ -0,0 +1,13 @@
package cn.xiaozhou233.orangex.event.impl;
import cn.xiaozhou233.orangex.event.Event;
import lombok.Getter;
@Getter
public class EventRender2D extends Event {
private float partialTicks;
public EventRender2D(float partialTicks) {
this.partialTicks = partialTicks;
}
}
@@ -0,0 +1,65 @@
package cn.xiaozhou233.orangex.mixin;
import cn.xiaozhou233.orangex.mixin.impl.MixinGuiIngame;
import cn.xiaozhou233.orangex.utils.JuiceLoaderFacade;
import cn.yapeteam.ymixin.Transformer;
import cn.yapeteam.ymixin.YMixin;
public final class MixinManager {
private MixinManager() {}
public static void start() {
ClassLoader cl = MixinManager.class.getClassLoader();
YMixin.init(
className -> {
try {
return Class.forName(
className.replace("/", "."),
false,
cl
);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
},
clazz -> {
byte[] classBytes = JuiceLoaderFacade.getClassBytes(clazz);
if (classBytes == null) {
throw new RuntimeException(
"ClassBytes null: " + clazz.getName()
);
}
return classBytes;
},
null,
null,
null
);
Transformer transformer = new Transformer();
try {
transformer.addMixin(MixinGuiIngame.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 = JuiceLoaderFacade.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,42 @@
package cn.xiaozhou233.orangex.mixin.impl;
import cn.xiaozhou233.orangex.OrangeX;
import cn.xiaozhou233.orangex.event.impl.EventRender2D;
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 net.minecraft.client.gui.GuiIngame;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import org.lwjgl.opengl.GL11;
@Mixin(GuiIngame.class)
public class MixinGuiIngame {
@Inject(method = "renderGameOverlay", desc = "(F)V", target = @Target("HEAD"))
public void onRenderGameOverlay(@Local(source = "partialTicks", index = 1) float partialTicks) {
Minecraft mc = Minecraft.getMinecraft();
ScaledResolution sr = new ScaledResolution(mc);
GlStateManager.pushMatrix();
GlStateManager.disableDepth();
GlStateManager.disableLighting();
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(
GL11.GL_SRC_ALPHA,
GL11.GL_ONE_MINUS_SRC_ALPHA,
GL11.GL_ONE,
GL11.GL_ZERO
);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
mc.entityRenderer.setupOverlayRendering();
OrangeX.getEventBus().post(new EventRender2D(partialTicks));
GlStateManager.enableDepth();
GlStateManager.disableBlend();
GlStateManager.popMatrix();
}
}
@@ -0,0 +1,4 @@
package cn.xiaozhou233.orangex.module;
public class Module {
}
@@ -0,0 +1,10 @@
package cn.xiaozhou233.orangex.module;
import cn.xiaozhou233.orangex.OrangeX;
import cn.xiaozhou233.orangex.module.impl.render.HUD;
public class ModuleManager {
public static void registerAll() {
OrangeX.getEventBus().register(new HUD());
}
}
@@ -0,0 +1,102 @@
package cn.xiaozhou233.orangex.module.impl.render;
import cn.xiaozhou233.orangex.event.impl.EventRender2D;
import cn.xiaozhou233.orangex.module.Module;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.ScaledResolution;
import org.greenrobot.eventbus.Subscribe;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Comparator;
public class HUD extends Module {
private Minecraft mc;
private FontRenderer fr;
private final ArrayList<String> modules = new ArrayList<>();
private float rainbowTick = 0f;
public HUD() {
modules.add("Juice uwu");
modules.add("ExampleA");
modules.add("ExampleB");
modules.add("ExampleC");
modules.add("114514");
}
@Subscribe
public void onRender2D(EventRender2D event) {
// Lazy init, safe in MC thread
if (mc == null) {
mc = Minecraft.getMinecraft();
if (mc == null || mc.fontRendererObj == null) return;
fr = mc.fontRendererObj;
}
ScaledResolution sr = new ScaledResolution(mc);
float partialTicks = event.getPartialTicks();
rainbowTick += partialTicks;
renderLogo();
renderModuleList(sr, rainbowTick);
}
private void renderLogo() {
fr.drawStringWithShadow(
"OrangeX Client",
10,
10,
0xFFA500
);
}
private void renderModuleList(ScaledResolution sr, float baseTick) {
int margin = 6;
int y = margin;
int index = 0;
modules.sort(
Comparator.comparingInt(fr::getStringWidth).reversed()
);
for (String module : modules) {
int textWidth = fr.getStringWidth(module);
int x = sr.getScaledWidth() - textWidth - margin;
int color = getRainbowColor(baseTick + index * 6f);
drawHudString(module, x, y, color);
y += fr.FONT_HEIGHT + 4;
index++;
}
}
private void drawHudString(String text, int x, int y, int color) {
int padding = 2;
Gui.drawRect(
x - padding,
y - padding,
x + fr.getStringWidth(text) + padding,
y + fr.FONT_HEIGHT + padding,
0x70000000
);
fr.drawStringWithShadow(text, x, y, color);
}
private int getRainbowColor(float tick) {
float cycle = 60f;
float hue = (tick % cycle) / cycle;
return Color.HSBtoRGB(hue, 0.9f, 1.0f);
}
}
@@ -0,0 +1,61 @@
package cn.xiaozhou233.orangex.utils;
import java.lang.reflect.Method;
public final class JuiceLoaderFacade {
private static final Class<?> JL;
private static final Method INIT;
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.juiceloader.JuiceLoader",
true,
ClassLoader.getSystemClassLoader()
);
INIT = JL.getMethod("init");
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 JuiceLoaderFacade() {}
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