Feat: Minecraft 26.2 detect

This commit is contained in:
xiaozhou233 committed 2026-08-25 12:14:27 +08:00
1 parent 25a7c3506a
commit 9dc01af62f
4 files changed
+116 -1

No files matched your search

@@ -0,0 +1,63 @@
package cn.xiaozhou233.orangex.runtime.utils;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
public class MinecraftUtils {
public static int matchesVersionMetadata(Class<?> minecraftClass) {
try (InputStream stream = minecraftClass.getResourceAsStream(
"/version.json")) {
if (stream == null) {
return 0;
}
JsonElement element = new JsonParser().parse(new InputStreamReader(
stream, StandardCharsets.UTF_8));
if (!element.isJsonObject()) {
return 0;
}
JsonObject version = element.getAsJsonObject();
if (getInteger(version, "java_version") != 25) {
return 0;
}
String id = getString(version, "id");
String name = getString(version, "name");
if (id != null && id.equals(name)) {
boolean is261Family = id.startsWith("26.1")
&& (id.length() == 4 || id.charAt(4) == '.');
boolean is262Family = id.startsWith("26.2")
&& (id.length() == 4 || id.charAt(4) == '.');
if (is261Family) {
return 100;
}
if (is262Family) {
return 110;
}
}
return 0;
}
catch (Exception ignored) {
return 0;
}
catch (LinkageError ignored) {
return 0;
}
}
private static String getString(JsonObject object, String name) {
JsonElement value = object.get(name);
return value != null && value.isJsonPrimitive()
? value.getAsString() : null;
}
private static int getInteger(JsonObject object, String name) {
JsonElement value = object.get(name);
return value != null && value.isJsonPrimitive()
? value.getAsInt() : Integer.MIN_VALUE;
}
}
@@ -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 V1165Probe(), new V12111Probe()
new V189Probe(), new V1122Probe(), new V1165Probe(), new V12111Probe(), new V262Probe()
);
@@ -40,6 +40,11 @@ public final class V189Probe implements VersionProbe {
System.out.println("[DEBUG] Forge Version Probe Failed");
}
// MCP
MinecraftProbe.ProbeResult probeMCP = new MinecraftProbe("net.minecraft.client.Minecraft", "getMinecraft", "theMinecraft").probe(loader);
score += probeMCP.getScore();
probeMCP.getMatched().forEach(System.out::println);
return score;
}
}
@@ -0,0 +1,47 @@
package cn.xiaozhou233.orangex.runtime.version.probes;
import cn.xiaozhou233.orangex.runtime.ClassProbe;
import cn.xiaozhou233.orangex.runtime.utils.ForgeUtils;
import cn.xiaozhou233.orangex.runtime.utils.MinecraftUtils;
import cn.xiaozhou233.orangex.runtime.version.MinecraftProbe;
import cn.xiaozhou233.orangex.runtime.version.MinecraftVersion;
import cn.xiaozhou233.orangex.runtime.version.VersionProbe;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
public final class V262Probe implements VersionProbe {
@Override
public MinecraftVersion getVersion() {
return MinecraftVersion.V1_21_11;
}
@Override
public int score(ClassLoader loader) {
int score = 0;
// Vanilla (Not obfuscated)
MinecraftProbe.ProbeResult probeObf = new MinecraftProbe(
"net.minecraft.client.Minecraft",
"getInstance",
"instance",
"net.minecraft.client.multiplayer.ClientLevel", "net.minecraft.client.player.LocalPlayer", "net.minecraft.client.player.AbstractClientPlayer", "net.minecraft.world.level.Level")
.probe(loader);
score+= probeObf.getScore();
probeObf.getMatched().forEach(System.out::println);
Class<?> mcClass = ClassProbe.find(loader, "net.minecraft.client.Minecraft");
if (mcClass != null) {
int protocol = MinecraftUtils.matchesVersionMetadata(mcClass);
if (protocol == 110) {
score += 100;
System.out.println("[DEBUG] Protocol Version: " + protocol + ", Version: 26.2");
}
}
return score;
}
}