diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/runtime/utils/ForgeUtils.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/runtime/utils/ForgeUtils.java new file mode 100644 index 0000000..2c86206 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/runtime/utils/ForgeUtils.java @@ -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; + } + } +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/runtime/version/VersionDetector.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/runtime/version/VersionDetector.java index b251fd4..49264fd 100644 --- a/OrangeX/src/main/java/cn/xiaozhou233/orangex/runtime/version/VersionDetector.java +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/runtime/version/VersionDetector.java @@ -13,7 +13,7 @@ public final class VersionDetector { private static List scores = null; // List of VersionProbe private static final List PROBES = Arrays.asList( - new V189Probe(), new V1122Probe() + new V189Probe(), new V1122Probe(), new V1165Probe(), new V12111Probe() ); diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/runtime/version/probes/V1165Probe.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/runtime/version/probes/V1165Probe.java new file mode 100644 index 0000000..181eab5 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/runtime/version/probes/V1165Probe.java @@ -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; + } + + +} diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/runtime/version/probes/V12111Probe.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/runtime/version/probes/V12111Probe.java new file mode 100644 index 0000000..fdae9e4 --- /dev/null +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/runtime/version/probes/V12111Probe.java @@ -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; + } + + +}