mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 13:05:52 +08:00
Feat: MinecraftProbe
This commit is contained in:
1 parent
202780bb4c
commit
6087c1b912
5 files changed
+163
-14
No files matched your search
@@ -0,0 +1,18 @@
|
||||
package cn.xiaozhou233.orangex.runtime.utils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class ReflectUtils {
|
||||
public static Object readStaticField(String className, String fieldName) throws Exception {
|
||||
Class<?> owner = Class.forName(className);
|
||||
Field field;
|
||||
try {
|
||||
field = owner.getField(fieldName);
|
||||
}
|
||||
catch (NoSuchFieldException ignored) {
|
||||
field = owner.getDeclaredField(fieldName);
|
||||
}
|
||||
field.setAccessible(true);
|
||||
return field.get(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package cn.xiaozhou233.orangex.runtime.version;
|
||||
|
||||
import cn.xiaozhou233.orangex.runtime.ClassProbe;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MinecraftProbe {
|
||||
private final String minecraftClass;
|
||||
private final String minecraftGetter;
|
||||
private final String minecraftInstanceField;
|
||||
private final String[] minecraftAnchors;
|
||||
|
||||
public MinecraftProbe(String minecraftClass, String minecraftGetter, String minecraftInstanceField, String... minecraftAnchors) {
|
||||
this.minecraftClass = minecraftClass;
|
||||
this.minecraftGetter = minecraftGetter;
|
||||
this.minecraftInstanceField = minecraftInstanceField;
|
||||
this.minecraftAnchors = minecraftAnchors;
|
||||
}
|
||||
|
||||
public ProbeResult probe(ClassLoader loader) {
|
||||
int score = 0;
|
||||
List<String> matched = new ArrayList<>();
|
||||
|
||||
// Class Check
|
||||
Class<?> mcClass = ClassProbe.find(loader, minecraftClass);
|
||||
if (mcClass != null) {
|
||||
score += 10;
|
||||
matched.add(minecraftClass + " found + 10");
|
||||
} else {
|
||||
return new ProbeResult(score, matched);
|
||||
}
|
||||
|
||||
// Method(Getter) Check
|
||||
try {
|
||||
mcClass.getDeclaredMethod(minecraftGetter);
|
||||
score += 10;
|
||||
matched.add(minecraftGetter + " found + 10");
|
||||
} catch (NoSuchMethodException e) {
|
||||
return new ProbeResult(score, matched);
|
||||
}
|
||||
|
||||
// Instance Field Check (Tips: Some version of minecraft does not have this field)
|
||||
try {
|
||||
mcClass.getDeclaredField(minecraftInstanceField);
|
||||
score += 5;
|
||||
matched.add(minecraftInstanceField + " found + 5");
|
||||
} catch (NoSuchFieldException ignore) {
|
||||
|
||||
}
|
||||
|
||||
// Anchor Check
|
||||
for (String anchor : minecraftAnchors) {
|
||||
if (ClassProbe.exists(loader, anchor)) {
|
||||
score += 10;
|
||||
matched.add(anchor + " found + 10");
|
||||
}
|
||||
}
|
||||
|
||||
return new ProbeResult(score, matched);
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public static class ProbeResult {
|
||||
private final int score;
|
||||
private final List<String> matched;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.xiaozhou233.orangex.runtime.version;
|
||||
|
||||
import cn.xiaozhou233.orangex.runtime.version.probes.V189Probe;
|
||||
import cn.xiaozhou233.orangex.runtime.version.probes.*;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -13,7 +13,7 @@ public final class VersionDetector {
|
||||
private static List<ProbeScore> scores = null;
|
||||
// List of VersionProbe
|
||||
private static final List<VersionProbe> PROBES = Arrays.asList(
|
||||
new V189Probe()
|
||||
new V189Probe(), new V1122Probe()
|
||||
);
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package cn.xiaozhou233.orangex.runtime.version.probes;
|
||||
|
||||
import cn.xiaozhou233.orangex.runtime.ClassProbe;
|
||||
import cn.xiaozhou233.orangex.runtime.utils.ReflectUtils;
|
||||
import cn.xiaozhou233.orangex.runtime.version.MinecraftProbe;
|
||||
import cn.xiaozhou233.orangex.runtime.version.MinecraftVersion;
|
||||
import cn.xiaozhou233.orangex.runtime.version.VersionProbe;
|
||||
|
||||
public final class V1122Probe implements VersionProbe {
|
||||
|
||||
@Override
|
||||
public MinecraftVersion getVersion() {
|
||||
return MinecraftVersion.V1_12_2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int score(ClassLoader loader) {
|
||||
int score = 0;
|
||||
// Obfuscated
|
||||
MinecraftProbe.ProbeResult probeObf = new MinecraftProbe(
|
||||
"bib",
|
||||
"z",
|
||||
"R",
|
||||
"bud", "amu")
|
||||
.probe(loader);
|
||||
score+= probeObf.getScore();
|
||||
probeObf.getMatched().forEach(System.out::println);
|
||||
|
||||
// Forge
|
||||
try {
|
||||
Object minorVersion = ReflectUtils.readStaticField(
|
||||
"net.minecraftforge.common.ForgeVersion", "minorVersion");
|
||||
if (minorVersion instanceof Number) {
|
||||
int forgeMinorVersion = ((Number) minorVersion).intValue();
|
||||
if (forgeMinorVersion == 23) {
|
||||
score += 100;
|
||||
System.out.println("[DEBUG] Forge Version Probe Success! Version: 1.12.2");
|
||||
}
|
||||
}
|
||||
} catch (Exception ignore) {
|
||||
System.out.println("[DEBUG] Forge Version Probe Failed");
|
||||
}
|
||||
|
||||
return score;
|
||||
}
|
||||
}
|
||||
+26
-12
@@ -1,6 +1,8 @@
|
||||
package cn.xiaozhou233.orangex.runtime.version.probes;
|
||||
|
||||
import cn.xiaozhou233.orangex.runtime.ClassProbe;
|
||||
import cn.xiaozhou233.orangex.runtime.utils.ReflectUtils;
|
||||
import cn.xiaozhou233.orangex.runtime.version.MinecraftProbe;
|
||||
import cn.xiaozhou233.orangex.runtime.version.MinecraftVersion;
|
||||
import cn.xiaozhou233.orangex.runtime.version.VersionProbe;
|
||||
public final class V189Probe implements VersionProbe {
|
||||
@@ -13,19 +15,31 @@ public final class V189Probe implements VersionProbe {
|
||||
@Override
|
||||
public int score(ClassLoader loader) {
|
||||
int score = 0;
|
||||
// MCP, Obfuscated, Srg
|
||||
if (ClassProbe.exists(loader, "net.minecraft.client.Minecraft", "ave")) {
|
||||
score += 10;
|
||||
}
|
||||
if (ClassProbe.exists(loader, "net.minecraft.client.gui.GuiScreen", "axu")) {
|
||||
score += 10;
|
||||
}
|
||||
if (ClassProbe.exists(loader, "net.minecraft.client.renderer.entity.RenderManager", "bnn")) {
|
||||
score += 10;
|
||||
}
|
||||
if (ClassProbe.exists(loader, "net.minecraft.client.renderer.RenderGlobal", "buy")) {
|
||||
score += 10;
|
||||
// Vanilla
|
||||
MinecraftProbe.ProbeResult probeObf = new MinecraftProbe(
|
||||
"ave",
|
||||
"A",
|
||||
"S",
|
||||
"bew", "adm")
|
||||
.probe(loader);
|
||||
score+= probeObf.getScore();
|
||||
probeObf.getMatched().forEach(System.out::println);
|
||||
|
||||
// Forge
|
||||
try {
|
||||
Object minorVersion = ReflectUtils.readStaticField(
|
||||
"net.minecraftforge.common.ForgeVersion", "minorVersion");
|
||||
if (minorVersion instanceof Number) {
|
||||
int forgeMinorVersion = ((Number) minorVersion).intValue();
|
||||
if (forgeMinorVersion == 15) {
|
||||
score += 100;
|
||||
System.out.println("[DEBUG] Forge Version Probe Success! Version: 1.8.9");
|
||||
}
|
||||
}
|
||||
} catch (Exception ignore) {
|
||||
System.out.println("[DEBUG] Forge Version Probe Failed");
|
||||
}
|
||||
|
||||
return score;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user