mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 21:15:53 +08:00
Feat: Minecraft 1.16.5/1.21.11 detect (forge/vanilla)
This commit is contained in:
1 parent
6087c1b912
commit
25a7c3506a
4 files changed
+139
-1
No files matched your search
@@ -0,0 +1,45 @@
|
||||
package cn.xiaozhou233.orangex.runtime.utils;
|
||||
|
||||
public class ForgeUtils {
|
||||
public static int parseForgeVersion(Object value) {
|
||||
if (value == null) {
|
||||
return -1;
|
||||
}
|
||||
String text = String.valueOf(value).trim();
|
||||
int start = 0;
|
||||
while (start < text.length() && !Character.isDigit(text.charAt(start))) {
|
||||
++start;
|
||||
}
|
||||
int end = start;
|
||||
while (end < text.length() && Character.isDigit(text.charAt(end))) {
|
||||
++end;
|
||||
}
|
||||
if (start == end) {
|
||||
return -1;
|
||||
}
|
||||
try {
|
||||
int parsed = Integer.parseInt(text.substring(start, end));
|
||||
if (parsed == 62) {
|
||||
return 100;
|
||||
}
|
||||
if (parsed == 65) {
|
||||
return 110;
|
||||
}
|
||||
return isKnownVersionId(parsed) ? parsed : -1;
|
||||
}
|
||||
catch (NumberFormatException ignored) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isKnownVersionId(int version) {
|
||||
switch (version) {
|
||||
case 13: case 15: case 23: case 28: case 35: case 36: case 37:
|
||||
case 47: case 50: case 51: case 52: case 54: case 55: case 56: case 60: case 61:
|
||||
case 100: case 110:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 V1122Probe()
|
||||
new V189Probe(), new V1122Probe(), new V1165Probe(), new V12111Probe()
|
||||
);
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package cn.xiaozhou233.orangex.runtime.version.probes;
|
||||
|
||||
import cn.xiaozhou233.orangex.runtime.utils.ForgeUtils;
|
||||
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 V1165Probe implements VersionProbe {
|
||||
|
||||
@Override
|
||||
public MinecraftVersion getVersion() {
|
||||
return MinecraftVersion.V1_16_5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int score(ClassLoader loader) {
|
||||
int score = 0;
|
||||
// Obfuscated
|
||||
MinecraftProbe.ProbeResult probeObf = new MinecraftProbe(
|
||||
"djz",
|
||||
"C",
|
||||
"F",
|
||||
"dwt", "dzm", "dzj", "brx")
|
||||
.probe(loader);
|
||||
score+= probeObf.getScore();
|
||||
probeObf.getMatched().forEach(System.out::println);
|
||||
|
||||
// Forge
|
||||
try {
|
||||
Object forgeVersion = ReflectUtils.readStaticField(
|
||||
"net.minecraftforge.fml.loading.FMLLoader", "forgeVersion");
|
||||
int parsedVersion = ForgeUtils.parseForgeVersion(forgeVersion);
|
||||
if (parsedVersion == 36) {
|
||||
score += 100;
|
||||
System.out.println("[DEBUG] Forge Version: " + parsedVersion + ", Version: 1.16.5");
|
||||
}
|
||||
} catch (Exception ignore) {
|
||||
System.out.println("[DEBUG] Forge Version Probe Failed");
|
||||
}
|
||||
|
||||
return score;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package cn.xiaozhou233.orangex.runtime.version.probes;
|
||||
|
||||
import cn.xiaozhou233.orangex.runtime.utils.ForgeUtils;
|
||||
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 V12111Probe implements VersionProbe {
|
||||
|
||||
@Override
|
||||
public MinecraftVersion getVersion() {
|
||||
return MinecraftVersion.V1_21_11;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int score(ClassLoader loader) {
|
||||
int score = 0;
|
||||
// Obfuscated
|
||||
MinecraftProbe.ProbeResult probeObf = new MinecraftProbe(
|
||||
"gfj",
|
||||
"V",
|
||||
"A",
|
||||
"hif", "hnh", "hne", "dwo")
|
||||
.probe(loader);
|
||||
score+= probeObf.getScore();
|
||||
probeObf.getMatched().forEach(System.out::println);
|
||||
|
||||
// Forge
|
||||
try {
|
||||
Class<?> fmlLoader = Class.forName("net.minecraftforge.fml.loading.FMLLoader");
|
||||
Object versionInfo = fmlLoader.getMethod("versionInfo").invoke(null);
|
||||
Object forgeVersion = versionInfo.getClass().getMethod("forgeVersion").invoke(versionInfo);
|
||||
int parsedVersion = ForgeUtils.parseForgeVersion(forgeVersion);
|
||||
if (parsedVersion == 61) {
|
||||
score += 100;
|
||||
System.out.println("[DEBUG] Forge Version: " + parsedVersion + ", Version: 1.21.11");
|
||||
}
|
||||
} catch (Exception ignore) {
|
||||
System.out.println("[DEBUG] Forge Version Probe Failed");
|
||||
}
|
||||
|
||||
return score;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user