Compare commits

...

2 commits

Author SHA1 Message Date
Gravita
50b463b439 [FEATURE] Support custom protocol 2023-04-21 16:14:33 +07:00
Gravita
6caa34e255 [FEATURE] MirrorHelper Quilt support 2023-04-21 15:34:42 +07:00
5 changed files with 72 additions and 9 deletions

View file

@ -60,6 +60,7 @@ public static ClientProfile makeProfile(ClientProfile.Version version, String ti
// ----------- // -----------
Optional<MakeProfileOptionForge> forge = findOption(options, MakeProfileOptionForge.class); Optional<MakeProfileOptionForge> forge = findOption(options, MakeProfileOptionForge.class);
Optional<MakeProfileOptionFabric> fabric = findOption(options, MakeProfileOptionFabric.class); Optional<MakeProfileOptionFabric> fabric = findOption(options, MakeProfileOptionFabric.class);
Optional<MakeProfilesOptionsQuilt> quilt = findOption(options, MakeProfilesOptionsQuilt.class);
if (version.compareTo(ClientProfileVersions.MINECRAFT_1_12_2) > 0) { if (version.compareTo(ClientProfileVersions.MINECRAFT_1_12_2) > 0) {
jvmArgs.add("-Djava.library.path=natives"); jvmArgs.add("-Djava.library.path=natives");
OptionalFile optionalMacOs = new OptionalFile(); OptionalFile optionalMacOs = new OptionalFile();
@ -73,6 +74,9 @@ public static ClientProfile makeProfile(ClientProfile.Version version, String ti
if (fabric.isPresent()) { if (fabric.isPresent()) {
builder.setAltClassPath(fabric.orElseThrow().getAltClassPath()); builder.setAltClassPath(fabric.orElseThrow().getAltClassPath());
} }
if(quilt.isPresent()) {
builder.setClassLoaderConfig(ClientProfile.ClassLoaderConfig.SYSTEM_ARGS);
}
if (findOption(options, MakeProfileOptionLwjgl.class).isPresent()) { if (findOption(options, MakeProfileOptionLwjgl.class).isPresent()) {
OptionalFile optionalMac = new OptionalFile(); OptionalFile optionalMac = new OptionalFile();
optionalMac.name = "MacLwjgl"; optionalMac.name = "MacLwjgl";
@ -152,7 +156,7 @@ public static ClientProfile makeProfile(ClientProfile.Version version, String ti
} else if (version.compareTo(ClientProfileVersions.MINECRAFT_1_12_2) > 0) { } else if (version.compareTo(ClientProfileVersions.MINECRAFT_1_12_2) > 0) {
if (forge.isPresent()) { if (forge.isPresent()) {
clientArgs.addAll(forge.get().makeClientArgs()); clientArgs.addAll(forge.get().makeClientArgs());
builder.setClassLoaderConfig(ClientProfile.ClassLoaderConfig.AGENT); builder.setClassLoaderConfig(ClientProfile.ClassLoaderConfig.SYSTEM_ARGS);
if (version.compareTo(ClientProfileVersions.MINECRAFT_1_16_5) <= 0) { if (version.compareTo(ClientProfileVersions.MINECRAFT_1_16_5) <= 0) {
builder.setMaxJavaVersion(15); builder.setMaxJavaVersion(15);
} }
@ -178,6 +182,9 @@ public static String getMainClassByVersion(ClientProfile.Version version, MakePr
if (findOption(options, MakeProfileOptionFabric.class).isPresent()) { if (findOption(options, MakeProfileOptionFabric.class).isPresent()) {
return "net.fabricmc.loader.launch.knot.KnotClient"; return "net.fabricmc.loader.launch.knot.KnotClient";
} }
if(findOption(options, MakeProfilesOptionsQuilt.class).isPresent()) {
return "org.quiltmc.loader.impl.launch.knot.KnotClient";
}
return "net.minecraft.client.main.Main"; return "net.minecraft.client.main.Main";
} }
@ -216,6 +223,9 @@ public static MakeProfileOption[] getMakeProfileOptionsFromDir(Path dir, ClientP
if (Files.exists(dir.resolve("libraries/net/fabricmc/fabric-loader"))) { if (Files.exists(dir.resolve("libraries/net/fabricmc/fabric-loader"))) {
options.add(new MakeProfileOptionFabric(dir)); options.add(new MakeProfileOptionFabric(dir));
} }
if (Files.exists(dir.resolve("libraries/org/quiltmc/quilt-loader"))) {
options.add(new MakeProfilesOptionsQuilt());
}
{ {
String log4jVersion = getLog4jVersion(dir); String log4jVersion = getLog4jVersion(dir);
if (log4jVersion != null) { if (log4jVersion != null) {
@ -344,6 +354,10 @@ public List<String> getAltClassPath() {
} }
} }
public static class MakeProfilesOptionsQuilt implements MakeProfileOption {
}
public static class MakeProfileOptionLiteLoader implements MakeProfileOption { public static class MakeProfileOptionLiteLoader implements MakeProfileOption {
} }

View file

@ -30,6 +30,7 @@ public final class ServerPinger {
private static final int PACKET_LENGTH = 65535; private static final int PACKET_LENGTH = 65535;
// Instance // Instance
private final InetSocketAddress address; private final InetSocketAddress address;
private final int protocol;
private final ClientProfile.Version version; private final ClientProfile.Version version;
// Cache // Cache
private final Object cacheLock = new Object(); private final Object cacheLock = new Object();
@ -47,6 +48,7 @@ public ServerPinger(ClientProfile.ServerProfile profile, ClientProfile.Version v
} }
this.address = profile.toSocketAddress(); this.address = profile.toSocketAddress();
this.version = Objects.requireNonNull(version, "version"); this.version = Objects.requireNonNull(version, "version");
this.protocol = profile.protocol;
} }
private static String readUTF16String(HInput input) throws IOException { private static String readUTF16String(HInput input) throws IOException {
@ -65,7 +67,7 @@ private Result doPing() throws IOException {
socket.connect(IOHelper.resolve(address), IOHelper.SOCKET_TIMEOUT); socket.connect(IOHelper.resolve(address), IOHelper.SOCKET_TIMEOUT);
try (HInput input = new HInput(socket.getInputStream()); try (HInput input = new HInput(socket.getInputStream());
HOutput output = new HOutput(socket.getOutputStream())) { HOutput output = new HOutput(socket.getOutputStream())) {
return version.compareTo(ClientProfileVersions.MINECRAFT_1_7_2) >= 0 ? modernPing(input, output) : legacyPing(input, output, version.compareTo(ClientProfileVersions.MINECRAFT_1_6_4) >= 0); return version.compareTo(ClientProfileVersions.MINECRAFT_1_7_2) >= 0 ? modernPing(input, output, protocol) : legacyPing(input, output, version.compareTo(ClientProfileVersions.MINECRAFT_1_6_4) >= 0);
} }
} }
} }
@ -121,13 +123,13 @@ private Result legacyPing(HInput input, HOutput output, boolean mc16) throws IOE
return new Result(onlinePlayers, maxPlayers, response); return new Result(onlinePlayers, maxPlayers, response);
} }
private Result modernPing(HInput input, HOutput output) throws IOException { private Result modernPing(HInput input, HOutput output, int protocol) throws IOException {
// Prepare handshake packet // Prepare handshake packet
byte[] handshakePacket; byte[] handshakePacket;
try (ByteArrayOutputStream packetArray = IOHelper.newByteArrayOutput()) { try (ByteArrayOutputStream packetArray = IOHelper.newByteArrayOutput()) {
try (HOutput packetOutput = new HOutput(packetArray)) { try (HOutput packetOutput = new HOutput(packetArray)) {
packetOutput.writeVarInt(0x0); // Handshake packet ID packetOutput.writeVarInt(0x0); // Handshake packet ID
packetOutput.writeVarInt(0x4); // Protocol version packetOutput.writeVarInt(protocol > 0 ? protocol : 0x4); // Protocol version
packetOutput.writeString(address.getHostString(), 0); // Server address packetOutput.writeString(address.getHostString(), 0); // Server address
packetOutput.writeShort((short) address.getPort()); // Server port packetOutput.writeShort((short) address.getPort()); // Server port
packetOutput.writeVarInt(0x1); // Next state - status packetOutput.writeVarInt(0x1); // Next state - status

View file

@ -467,11 +467,28 @@ public Version(long[] data, String original, boolean isObjectSerialized) {
@Override @Override
public int compareTo(Version some) { public int compareTo(Version some) {
int result = 0; int result = 0;
if(data.length == some.data.length) {
for (int i = 0; i < data.length; ++i) { for (int i = 0; i < data.length; ++i) {
if (i > some.data.length) break;
result = Long.compare(data[i], some.data[i]); result = Long.compare(data[i], some.data[i]);
if (result != 0) return result; if (result != 0) return result;
} }
} else if(data.length < some.data.length) {
for (int i = 0; i < data.length; ++i) {
result = Long.compare(data[i], some.data[i]);
if (result != 0) return result;
}
for(int i = data.length; i < some.data.length;++i) {
if(some.data[i] > 0) return -1;
}
} else {
for (int i = 0; i < some.data.length; ++i) {
result = Long.compare(data[i], some.data[i]);
if (result != 0) return result;
}
for(int i = some.data.length; i < data.length;++i) {
if(data[i] > 0) return 1;
}
}
return result; return result;
} }
@ -527,6 +544,7 @@ public static class ServerProfile {
public String serverAddress; public String serverAddress;
public int serverPort; public int serverPort;
public boolean isDefault = true; public boolean isDefault = true;
public int protocol = -1;
public boolean socketPing = true; public boolean socketPing = true;
public ServerProfile() { public ServerProfile() {

View file

@ -0,0 +1,29 @@
package pro.gravit.launcher;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import pro.gravit.launcher.profiles.ClientProfile;
public class ClientVersionTest {
@Test
public void parseTest() {
Assertions.assertEquals(ClientProfile.Version.of("1.0.0").toCleanString(), "1.0.0");
Assertions.assertEquals(ClientProfile.Version.of("1.0.0-1").toCleanString(), "1.0.0.1");
Assertions.assertEquals(ClientProfile.Version.of("-----1.0.0").toCleanString(), "1.0.0");
}
@Test
public void compareTest() {
Assertions.assertTrue(ClientProfile.Version.of("1.0.0").compareTo(ClientProfile.Version.of("1.0.0")) == 0);
Assertions.assertTrue(ClientProfile.Version.of("1.1.0").compareTo(ClientProfile.Version.of("1.0.0")) > 0);
Assertions.assertTrue(ClientProfile.Version.of("2.0.0").compareTo(ClientProfile.Version.of("1.0.0")) > 0);
Assertions.assertTrue(ClientProfile.Version.of("1.0.0").compareTo(ClientProfile.Version.of("1.0.1")) < 0);
Assertions.assertTrue(ClientProfile.Version.of("1.1.0").compareTo(ClientProfile.Version.of("1.0.0")) > 0);
Assertions.assertTrue(ClientProfile.Version.of("1.0.0").compareTo(ClientProfile.Version.of("1.1.0")) < 0);
Assertions.assertTrue(ClientProfile.Version.of("1.0").compareTo(ClientProfile.Version.of("1.0.0")) == 0);
Assertions.assertTrue(ClientProfile.Version.of("1.0.0").compareTo(ClientProfile.Version.of("1.0")) == 0);
Assertions.assertTrue(ClientProfile.Version.of("1.0.1").compareTo(ClientProfile.Version.of("1.0")) > 0);
Assertions.assertTrue(ClientProfile.Version.of("1.0").compareTo(ClientProfile.Version.of("1.0.1")) < 0);
Assertions.assertTrue(ClientProfile.Version.of("1.0").compareTo(ClientProfile.Version.of("1.0.1")) < 0);
}
}

@ -1 +1 @@
Subproject commit 06e98102578275e84ba8d3b7aed65228ecbfc30e Subproject commit 19e9cf3d6ce7148db4374e3736862d52b5854638