Compare commits

...

2 commits

Author SHA1 Message Date
Gravita
26c017a277 [ANY] Update modules 2023-04-20 21:48:52 +07:00
Gravita
48799cf3c2 [FEATURE] New ClientProfile$Version 2023-04-20 19:06:12 +07:00
18 changed files with 167 additions and 123 deletions

View file

@ -4,8 +4,11 @@
import me.tongfei.progressbar.ProgressBarBuilder; import me.tongfei.progressbar.ProgressBarBuilder;
import me.tongfei.progressbar.ProgressBarStyle; import me.tongfei.progressbar.ProgressBarStyle;
import pro.gravit.launcher.AsyncDownloader; import pro.gravit.launcher.AsyncDownloader;
import pro.gravit.launcher.Launcher;
import pro.gravit.launcher.profiles.ClientProfile;
import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.LaunchServer;
import pro.gravit.utils.Downloader; import pro.gravit.utils.Downloader;
import pro.gravit.utils.command.CommandException;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
@ -29,6 +32,13 @@ public Command(Map<String, pro.gravit.utils.command.Command> childCommands, Laun
this.server = server; this.server = server;
} }
protected ClientProfile.Version parseClientVersion(String arg) throws CommandException {
if(arg.isEmpty()) {
throw new CommandException("ClientVersion can't be empty");
}
return Launcher.gsonManager.gson.fromJson(arg, ClientProfile.Version.class);
}
protected boolean showApplyDialog(String text) throws IOException { protected boolean showApplyDialog(String text) throws IOException {
System.out.printf("%s [Y/N]:", text); System.out.printf("%s [Y/N]:", text);
String response = server.commandHandler.readLine().toLowerCase(Locale.ROOT); String response = server.commandHandler.readLine().toLowerCase(Locale.ROOT);

View file

@ -5,6 +5,7 @@
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import pro.gravit.launcher.Launcher; import pro.gravit.launcher.Launcher;
import pro.gravit.launcher.profiles.ClientProfile; import pro.gravit.launcher.profiles.ClientProfile;
import pro.gravit.launcher.profiles.ClientProfileVersions;
import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.LaunchServer;
import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.command.Command;
import pro.gravit.launchserver.helper.MakeProfileHelper; import pro.gravit.launchserver.helper.MakeProfileHelper;
@ -81,9 +82,9 @@ public void invoke(String... args) throws IOException, CommandException {
if (internalVersion.contains("-")) { if (internalVersion.contains("-")) {
internalVersion = internalVersion.substring(0, versionName.indexOf('-')); internalVersion = internalVersion.substring(0, versionName.indexOf('-'));
} }
ClientProfile.Version version = ClientProfile.Version.byName(internalVersion); ClientProfile.Version version = ClientProfile.Version.of(internalVersion);
if (version.compareTo(ClientProfile.Version.MC164) <= 0) { if (version.compareTo(ClientProfileVersions.MINECRAFT_1_7_10) <= 0) {
logger.warn("Minecraft 1.6.4 and below not supported. Use at your own risk"); logger.warn("Minecraft 1.7.9 and below not supported. Use at your own risk");
} }
MakeProfileHelper.MakeProfileOption[] options = MakeProfileHelper.getMakeProfileOptionsFromDir(clientDir, version, Files.exists(server.updatesDir.resolve("assets"))); MakeProfileHelper.MakeProfileOption[] options = MakeProfileHelper.getMakeProfileOptionsFromDir(clientDir, version, Files.exists(server.updatesDir.resolve("assets")));
for (MakeProfileHelper.MakeProfileOption option : options) { for (MakeProfileHelper.MakeProfileOption option : options) {

View file

@ -32,12 +32,12 @@ public String getUsageDescription() {
@Override @Override
public void invoke(String... args) throws Exception { public void invoke(String... args) throws Exception {
verifyArgs(args, 3); verifyArgs(args, 3);
ClientProfile.Version version = ClientProfile.Version.byName(args[1]); ClientProfile.Version version = parseClientVersion(args[1]);
MakeProfileHelper.MakeProfileOption[] options = MakeProfileHelper.getMakeProfileOptionsFromDir(server.updatesDir.resolve(args[2]), version, Files.exists(server.updatesDir.resolve("assets"))); MakeProfileHelper.MakeProfileOption[] options = MakeProfileHelper.getMakeProfileOptionsFromDir(server.updatesDir.resolve(args[2]), version, Files.exists(server.updatesDir.resolve("assets")));
for (MakeProfileHelper.MakeProfileOption option : options) { for (MakeProfileHelper.MakeProfileOption option : options) {
logger.info("Detected option {}", option); logger.info("Detected option {}", option);
} }
ClientProfile profile = MakeProfileHelper.makeProfile(ClientProfile.Version.byName(args[1]), args[0], options); ClientProfile profile = MakeProfileHelper.makeProfile(version, args[0], options);
try (Writer writer = IOHelper.newWriter(server.profilesDir.resolve(args[0].concat(".json")))) { try (Writer writer = IOHelper.newWriter(server.profilesDir.resolve(args[0].concat(".json")))) {
Launcher.gsonManager.configGson.toJson(profile, writer); Launcher.gsonManager.configGson.toJson(profile, writer);
} }

View file

@ -169,7 +169,7 @@ public void invoke(String... args) {
bad = true; bad = true;
} }
} else { } else {
if (nextToken.equals("memory_repo") || nextToken.equals(profile.getVersion().name)) { if (nextToken.equals("memory_repo") || nextToken.equals(profile.getVersion().toString())) {
printCheckResult(profileModuleName, String.format("updateExclusions %s not safe. Cheats may be injected very easy!", exc), false); printCheckResult(profileModuleName, String.format("updateExclusions %s not safe. Cheats may be injected very easy!", exc), false);
bad = true; bad = true;
} }

View file

@ -2,6 +2,7 @@
import pro.gravit.launcher.profiles.ClientProfile; import pro.gravit.launcher.profiles.ClientProfile;
import pro.gravit.launcher.profiles.ClientProfileBuilder; import pro.gravit.launcher.profiles.ClientProfileBuilder;
import pro.gravit.launcher.profiles.ClientProfileVersions;
import pro.gravit.launcher.profiles.optional.OptionalFile; import pro.gravit.launcher.profiles.optional.OptionalFile;
import pro.gravit.launcher.profiles.optional.actions.OptionalActionFile; import pro.gravit.launcher.profiles.optional.actions.OptionalActionFile;
import pro.gravit.launcher.profiles.optional.actions.OptionalActionJvmArgs; import pro.gravit.launcher.profiles.optional.actions.OptionalActionJvmArgs;
@ -16,14 +17,14 @@
public class MakeProfileHelper { public class MakeProfileHelper {
public static ClientProfile makeProfile(ClientProfile.Version version, String title, MakeProfileOption... options) { public static ClientProfile makeProfile(ClientProfile.Version version, String title, MakeProfileOption... options) {
ClientProfileBuilder builder = new ClientProfileBuilder(); ClientProfileBuilder builder = new ClientProfileBuilder();
builder.setVersion(version.name); builder.setVersion(version);
builder.setDir(title); builder.setDir(title);
if (findOption(options, MakeProfileOptionGlobalAssets.class).isPresent()) { if (findOption(options, MakeProfileOptionGlobalAssets.class).isPresent()) {
builder.setAssetDir("assets"); builder.setAssetDir("assets");
} else { } else {
builder.setAssetDir("asset" + version.name); builder.setAssetDir("asset" + version.toCleanString());
} }
builder.setAssetIndex(version.name); builder.setAssetIndex(version.toString());
builder.setInfo("Информация о сервере"); builder.setInfo("Информация о сервере");
builder.setTitle(title); builder.setTitle(title);
builder.setUuid(UUID.randomUUID()); builder.setUuid(UUID.randomUUID());
@ -35,7 +36,7 @@ public static ClientProfile makeProfile(ClientProfile.Version version, String ti
List<String> classPath = new ArrayList<>(5); List<String> classPath = new ArrayList<>(5);
classPath.add("libraries"); classPath.add("libraries");
classPath.add("minecraft.jar"); classPath.add("minecraft.jar");
if (version.compareTo(ClientProfile.Version.MC1122) <= 0) { if (version.compareTo(ClientProfileVersions.MINECRAFT_1_12_2) <= 0) {
findOption(options, MakeProfileOptionForge.class).ifPresent(e -> classPath.add("forge.jar")); findOption(options, MakeProfileOptionForge.class).ifPresent(e -> classPath.add("forge.jar"));
findOption(options, MakeProfileOptionLiteLoader.class).ifPresent(e -> classPath.add("liteloader.jar")); findOption(options, MakeProfileOptionLiteLoader.class).ifPresent(e -> classPath.add("liteloader.jar"));
} }
@ -46,20 +47,20 @@ public static ClientProfile makeProfile(ClientProfile.Version version, String ti
Set<OptionalFile> optionals = new HashSet<>(); Set<OptionalFile> optionals = new HashSet<>();
jvmArgs.add("-XX:+DisableAttachMechanism"); jvmArgs.add("-XX:+DisableAttachMechanism");
// Official Mojang launcher java arguments // Official Mojang launcher java arguments
if (version.compareTo(ClientProfile.Version.MC112) <= 0) { if (version.compareTo(ClientProfileVersions.MINECRAFT_1_12_2) <= 0) {
jvmArgs.add("-XX:+UseConcMarkSweepGC"); jvmArgs.add("-XX:+UseConcMarkSweepGC");
jvmArgs.add("-XX:+CMSIncrementalMode"); jvmArgs.add("-XX:+CMSIncrementalMode");
} else if (version.compareTo(ClientProfile.Version.MC118) <= 0) { // 1.13 - 1.16.5 } else if (version.compareTo(ClientProfileVersions.MINECRAFT_1_18) <= 0) { // 1.13 - 1.16.5
jvmArgs.add("-XX:+UseG1GC"); jvmArgs.add("-XX:+UseG1GC");
jvmArgs.add("-XX:+UnlockExperimentalVMOptions"); jvmArgs.add("-XX:+UnlockExperimentalVMOptions");
} else { // 1.18+ } else { // 1.18+
jvmArgs.add("-XX:+UseShenandoahGC"); //jvmArgs.add("-XX:+UseShenandoahGC");
jvmArgs.add("-XX:+UnlockExperimentalVMOptions"); //jvmArgs.add("-XX:+UnlockExperimentalVMOptions");
} }
// ----------- // -----------
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);
if (version.compareTo(ClientProfile.Version.MC1122) > 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();
optionalMacOs.name = "MacOSArgs"; optionalMacOs.name = "MacOSArgs";
@ -112,16 +113,16 @@ public static ClientProfile makeProfile(ClientProfile.Version version, String ti
if (log4jOption.logFile != null) { if (log4jOption.logFile != null) {
jvmArgs.add("-Dlog4j.configurationFile=".concat(logFile.get().logFile)); jvmArgs.add("-Dlog4j.configurationFile=".concat(logFile.get().logFile));
} else if (log4jOption.affected) { } else if (log4jOption.affected) {
if (version.compareTo(ClientProfile.Version.MC117) >= 0 && version.compareTo(ClientProfile.Version.MC118) < 0) { if (version.compareTo(ClientProfileVersions.MINECRAFT_1_17) >= 0 && version.compareTo(ClientProfileVersions.MINECRAFT_1_18) < 0) {
jvmArgs.add("-Dlog4j2.formatMsgNoLookups=true"); jvmArgs.add("-Dlog4j2.formatMsgNoLookups=true");
} }
} }
} }
if (version.compareTo(ClientProfile.Version.MC117) >= 0 && version.compareTo(ClientProfile.Version.MC118) < 0) { if (version.compareTo(ClientProfileVersions.MINECRAFT_1_17) >= 0 && version.compareTo(ClientProfileVersions.MINECRAFT_1_18) < 0) {
builder.setMinJavaVersion(16); builder.setMinJavaVersion(16);
builder.setRecommendJavaVersion(16); builder.setRecommendJavaVersion(16);
} }
if (version.compareTo(ClientProfile.Version.MC118) >= 0) { if (version.compareTo(ClientProfileVersions.MINECRAFT_1_18) >= 0) {
builder.setMinJavaVersion(17); builder.setMinJavaVersion(17);
builder.setRecommendJavaVersion(17); builder.setRecommendJavaVersion(17);
} }
@ -137,22 +138,22 @@ public static ClientProfile makeProfile(ClientProfile.Version version, String ti
} }
if (forge.isPresent()) { if (forge.isPresent()) {
clientArgs.add("--tweakClass"); clientArgs.add("--tweakClass");
if (version.compareTo(ClientProfile.Version.MC1710) > 0) { if (version.compareTo(ClientProfileVersions.MINECRAFT_1_7_10) > 0) {
clientArgs.add("net.minecraftforge.fml.common.launcher.FMLTweaker"); clientArgs.add("net.minecraftforge.fml.common.launcher.FMLTweaker");
} else { } else {
clientArgs.add("cpw.mods.fml.common.launcher.FMLTweaker"); clientArgs.add("cpw.mods.fml.common.launcher.FMLTweaker");
} }
if (version.compareTo(ClientProfile.Version.MC1122) <= 0) { if (version.compareTo(ClientProfileVersions.MINECRAFT_1_12_2) <= 0) {
builder.setMinJavaVersion(8); builder.setMinJavaVersion(8);
builder.setRecommendJavaVersion(8); builder.setRecommendJavaVersion(8);
builder.setMaxJavaVersion(8); builder.setMaxJavaVersion(8);
} }
} }
} else if (version.compareTo(ClientProfile.Version.MC1122) > 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.AGENT);
if (version.compareTo(ClientProfile.Version.MC1165) <= 0) { if (version.compareTo(ClientProfileVersions.MINECRAFT_1_16_5) <= 0) {
builder.setMaxJavaVersion(15); builder.setMaxJavaVersion(15);
} }
} }
@ -171,7 +172,7 @@ public static String getMainClassByVersion(ClientProfile.Version version, MakePr
if (findOption(options, MakeProfileOptionLaunchWrapper.class).isPresent()) { if (findOption(options, MakeProfileOptionLaunchWrapper.class).isPresent()) {
return "net.minecraft.launchwrapper.Launch"; return "net.minecraft.launchwrapper.Launch";
} }
if (findOption(options, MakeProfileOptionForge.class).isPresent() && version.compareTo(ClientProfile.Version.MC1122) > 0) { if (findOption(options, MakeProfileOptionForge.class).isPresent() && version.compareTo(ClientProfileVersions.MINECRAFT_1_12_2) > 0) {
return "cpw.mods.modlauncher.Launcher"; return "cpw.mods.modlauncher.Launcher";
} }
if (findOption(options, MakeProfileOptionFabric.class).isPresent()) { if (findOption(options, MakeProfileOptionFabric.class).isPresent()) {
@ -206,7 +207,7 @@ public static MakeProfileOption[] getMakeProfileOptionsFromDir(Path dir, ClientP
if (Files.exists(dir.resolve("forge.jar"))) { if (Files.exists(dir.resolve("forge.jar"))) {
options.add(new MakeProfileOptionForge()); options.add(new MakeProfileOptionForge());
} else if (Files.exists(dir.resolve("libraries/net/minecraftforge/forge"))) { } else if (Files.exists(dir.resolve("libraries/net/minecraftforge/forge"))) {
if (version.compareTo(ClientProfile.Version.MC1122) > 0) { if (version.compareTo(ClientProfileVersions.MINECRAFT_1_12_2) > 0) {
options.add(new MakeProfileOptionForge(dir)); options.add(new MakeProfileOptionForge(dir));
} else { } else {
options.add(new MakeProfileOptionForge()); options.add(new MakeProfileOptionForge());

View file

@ -5,6 +5,7 @@
import pro.gravit.launcher.events.request.GetAvailabilityAuthRequestEvent; import pro.gravit.launcher.events.request.GetAvailabilityAuthRequestEvent;
import pro.gravit.launcher.managers.GsonManager; import pro.gravit.launcher.managers.GsonManager;
import pro.gravit.launcher.modules.events.PreGsonPhase; import pro.gravit.launcher.modules.events.PreGsonPhase;
import pro.gravit.launcher.profiles.ClientProfile;
import pro.gravit.launcher.profiles.optional.actions.OptionalAction; import pro.gravit.launcher.profiles.optional.actions.OptionalAction;
import pro.gravit.launcher.profiles.optional.triggers.OptionalTrigger; import pro.gravit.launcher.profiles.optional.triggers.OptionalTrigger;
import pro.gravit.launcher.request.JsonResultSerializeAdapter; import pro.gravit.launcher.request.JsonResultSerializeAdapter;
@ -35,6 +36,7 @@ public void registerAdapters(GsonBuilder builder) {
builder.registerTypeAdapterFactory(RecordTypeAdapterFactory.builder() builder.registerTypeAdapterFactory(RecordTypeAdapterFactory.builder()
.allowMissingComponentValues() .allowMissingComponentValues()
.create()); .create());
builder.registerTypeAdapter(ClientProfile.Version.class, new ClientProfile.Version.GsonSerializer());
builder.registerTypeAdapter(TextureProvider.class, new UniversalJsonAdapter<>(TextureProvider.providers)); builder.registerTypeAdapter(TextureProvider.class, new UniversalJsonAdapter<>(TextureProvider.providers));
builder.registerTypeAdapter(AuthCoreProvider.class, new UniversalJsonAdapter<>(AuthCoreProvider.providers)); builder.registerTypeAdapter(AuthCoreProvider.class, new UniversalJsonAdapter<>(AuthCoreProvider.providers));
builder.registerTypeAdapter(PasswordVerifier.class, new UniversalJsonAdapter<>(PasswordVerifier.providers)); builder.registerTypeAdapter(PasswordVerifier.class, new UniversalJsonAdapter<>(PasswordVerifier.providers));

View file

@ -16,6 +16,7 @@
import pro.gravit.launcher.modules.events.OfflineModeEvent; import pro.gravit.launcher.modules.events.OfflineModeEvent;
import pro.gravit.launcher.modules.events.PreConfigPhase; import pro.gravit.launcher.modules.events.PreConfigPhase;
import pro.gravit.launcher.profiles.ClientProfile; import pro.gravit.launcher.profiles.ClientProfile;
import pro.gravit.launcher.profiles.ClientProfileVersions;
import pro.gravit.launcher.profiles.optional.actions.OptionalAction; import pro.gravit.launcher.profiles.optional.actions.OptionalAction;
import pro.gravit.launcher.profiles.optional.actions.OptionalActionClassPath; import pro.gravit.launcher.profiles.optional.actions.OptionalActionClassPath;
import pro.gravit.launcher.profiles.optional.actions.OptionalActionClientArgs; import pro.gravit.launcher.profiles.optional.actions.OptionalActionClientArgs;
@ -290,7 +291,7 @@ public static Stream<Path> resolveClassPath(Path clientDir, Set<OptionalAction>
private static void launch(ClientProfile profile, ClientLauncherProcess.ClientParams params) throws Throwable { private static void launch(ClientProfile profile, ClientLauncherProcess.ClientParams params) throws Throwable {
// Add client args // Add client args
Collection<String> args = new LinkedList<>(); Collection<String> args = new LinkedList<>();
if (profile.getVersion().compareTo(ClientProfile.Version.MC164) >= 0) if (profile.getVersion().compareTo(ClientProfileVersions.MINECRAFT_1_6_4) >= 0)
params.addClientArgs(args); params.addClientArgs(args);
else { else {
params.addClientLegacyArgs(args); params.addClientLegacyArgs(args);

View file

@ -10,6 +10,7 @@
import pro.gravit.launcher.events.request.AuthRequestEvent; import pro.gravit.launcher.events.request.AuthRequestEvent;
import pro.gravit.launcher.hasher.HashedDir; import pro.gravit.launcher.hasher.HashedDir;
import pro.gravit.launcher.profiles.ClientProfile; import pro.gravit.launcher.profiles.ClientProfile;
import pro.gravit.launcher.profiles.ClientProfileVersions;
import pro.gravit.launcher.profiles.PlayerProfile; import pro.gravit.launcher.profiles.PlayerProfile;
import pro.gravit.launcher.profiles.optional.OptionalView; import pro.gravit.launcher.profiles.optional.OptionalView;
import pro.gravit.launcher.profiles.optional.actions.OptionalAction; import pro.gravit.launcher.profiles.optional.actions.OptionalAction;
@ -289,7 +290,7 @@ public static class ClientParams {
public transient HashedDir javaHDir; public transient HashedDir javaHDir;
public void addClientArgs(Collection<String> args) { public void addClientArgs(Collection<String> args) {
if (profile.getVersion().compareTo(ClientProfile.Version.MC164) >= 0) if (profile.getVersion().compareTo(ClientProfileVersions.MINECRAFT_1_6_4) >= 0)
addModernClientArgs(args); addModernClientArgs(args);
else else
addClientLegacyArgs(args); addClientLegacyArgs(args);
@ -300,7 +301,7 @@ public void addClientLegacyArgs(Collection<String> args) {
args.add(accessToken); args.add(accessToken);
// Add args for tweaker // Add args for tweaker
Collections.addAll(args, "--version", profile.getVersion().name); Collections.addAll(args, "--version", profile.getVersion().toString());
Collections.addAll(args, "--gameDir", clientDir); Collections.addAll(args, "--gameDir", clientDir);
Collections.addAll(args, "--assetsDir", assetDir); Collections.addAll(args, "--assetsDir", assetDir);
} }
@ -310,12 +311,12 @@ private void addModernClientArgs(Collection<String> args) {
// Add version-dependent args // Add version-dependent args
ClientProfile.Version version = profile.getVersion(); ClientProfile.Version version = profile.getVersion();
Collections.addAll(args, "--username", playerProfile.username); Collections.addAll(args, "--username", playerProfile.username);
if (version.compareTo(ClientProfile.Version.MC172) >= 0) { if (version.compareTo(ClientProfileVersions.MINECRAFT_1_7_2) >= 0) {
Collections.addAll(args, "--uuid", Launcher.toHash(playerProfile.uuid)); Collections.addAll(args, "--uuid", Launcher.toHash(playerProfile.uuid));
Collections.addAll(args, "--accessToken", accessToken); Collections.addAll(args, "--accessToken", accessToken);
// Add 1.7.10+ args (user properties, asset index) // Add 1.7.10+ args (user properties, asset index)
if (version.compareTo(ClientProfile.Version.MC1710) >= 0) { if (version.compareTo(ClientProfileVersions.MINECRAFT_1_7_10) >= 0) {
// Add user properties // Add user properties
Collections.addAll(args, "--userType", "mojang"); Collections.addAll(args, "--userType", "mojang");
Collections.addAll(args, "--userProperties", "{}"); Collections.addAll(args, "--userProperties", "{}");
@ -327,11 +328,11 @@ private void addModernClientArgs(Collection<String> args) {
Collections.addAll(args, "--session", accessToken); Collections.addAll(args, "--session", accessToken);
// Add version and dirs args // Add version and dirs args
Collections.addAll(args, "--version", profile.getVersion().name); Collections.addAll(args, "--version", profile.getVersion().toString());
Collections.addAll(args, "--gameDir", clientDir); Collections.addAll(args, "--gameDir", clientDir);
Collections.addAll(args, "--assetsDir", assetDir); Collections.addAll(args, "--assetsDir", assetDir);
Collections.addAll(args, "--resourcePackDir", resourcePackDir); Collections.addAll(args, "--resourcePackDir", resourcePackDir);
if (version.compareTo(ClientProfile.Version.MC194) >= 0) if (version.compareTo(ClientProfileVersions.MINECRAFT_1_9_4) >= 0)
Collections.addAll(args, "--versionType", "Launcher v" + Version.getVersion().getVersionString()); Collections.addAll(args, "--versionType", "Launcher v" + Version.getVersion().getVersionString());
// Add server args // Add server args

View file

@ -4,6 +4,7 @@
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import pro.gravit.launcher.profiles.ClientProfile; import pro.gravit.launcher.profiles.ClientProfile;
import pro.gravit.launcher.profiles.ClientProfileVersions;
import pro.gravit.launcher.serialize.HInput; import pro.gravit.launcher.serialize.HInput;
import pro.gravit.launcher.serialize.HOutput; import pro.gravit.launcher.serialize.HOutput;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
@ -64,7 +65,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(ClientProfile.Version.MC172) >= 0 ? modernPing(input, output) : legacyPing(input, output, version.compareTo(ClientProfile.Version.MC164) >= 0); return version.compareTo(ClientProfileVersions.MINECRAFT_1_7_2) >= 0 ? modernPing(input, output) : legacyPing(input, output, version.compareTo(ClientProfileVersions.MINECRAFT_1_6_4) >= 0);
} }
} }
} }
@ -80,7 +81,7 @@ private Result legacyPing(HInput input, HOutput output, boolean mc16) throws IOE
byte[] customPayloadPacket; byte[] customPayloadPacket;
try (ByteArrayOutputStream packetArray = IOHelper.newByteArrayOutput()) { try (ByteArrayOutputStream packetArray = IOHelper.newByteArrayOutput()) {
try (HOutput packetOutput = new HOutput(packetArray)) { try (HOutput packetOutput = new HOutput(packetArray)) {
packetOutput.writeUnsignedByte(version.protocol); // Protocol version packetOutput.writeUnsignedByte(0x4a); // Protocol version
writeUTF16String(packetOutput, address.getHostString()); // Server address writeUTF16String(packetOutput, address.getHostString()); // Server address
packetOutput.writeInt(address.getPort()); // Server port packetOutput.writeInt(address.getPort()); // Server port
} }
@ -110,11 +111,7 @@ private Result legacyPing(HInput input, HOutput output, boolean mc16) throws IOE
if (!magic.equals(LEGACY_PING_HOST_MAGIC)) if (!magic.equals(LEGACY_PING_HOST_MAGIC))
throw new IOException("Magic file mismatch: " + magic); throw new IOException("Magic file mismatch: " + magic);
int protocol = Integer.parseInt(splitted[1]); int protocol = Integer.parseInt(splitted[1]);
if (protocol != version.protocol)
throw new IOException("Protocol mismatch: " + protocol);
String clientVersion = splitted[2]; String clientVersion = splitted[2];
if (!clientVersion.equals(version.name))
throw new IOException(String.format("Version mismatch: '%s'", clientVersion));
int onlinePlayers = VerifyHelper.verifyInt(Integer.parseInt(splitted[4]), int onlinePlayers = VerifyHelper.verifyInt(Integer.parseInt(splitted[4]),
VerifyHelper.NOT_NEGATIVE, "onlinePlayers can't be < 0"); VerifyHelper.NOT_NEGATIVE, "onlinePlayers can't be < 0");
int maxPlayers = VerifyHelper.verifyInt(Integer.parseInt(splitted[5]), int maxPlayers = VerifyHelper.verifyInt(Integer.parseInt(splitted[5]),
@ -130,7 +127,7 @@ private Result modernPing(HInput input, HOutput output) throws IOException {
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(version.protocol); // Protocol version packetOutput.writeVarInt(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

@ -1,5 +1,6 @@
package pro.gravit.launcher.profiles; package pro.gravit.launcher.profiles;
import com.google.gson.*;
import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.LauncherNetworkAPI;
import pro.gravit.launcher.hasher.FileNameMatcher; import pro.gravit.launcher.hasher.FileNameMatcher;
import pro.gravit.launcher.profiles.optional.OptionalDepend; import pro.gravit.launcher.profiles.optional.OptionalDepend;
@ -8,6 +9,7 @@
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.VerifyHelper; import pro.gravit.utils.helper.VerifyHelper;
import java.lang.reflect.Type;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.*; import java.util.*;
@ -20,7 +22,7 @@ public final class ClientProfile implements Comparable<ClientProfile> {
@LauncherNetworkAPI @LauncherNetworkAPI
private UUID uuid; private UUID uuid;
@LauncherNetworkAPI @LauncherNetworkAPI
private String version; private Version version;
@LauncherNetworkAPI @LauncherNetworkAPI
private String info; private String info;
@LauncherNetworkAPI @LauncherNetworkAPI
@ -97,7 +99,7 @@ public ClientProfile() {
flags = new ArrayList<>(); flags = new ArrayList<>();
} }
public ClientProfile(List<String> update, List<String> updateExclusions, List<String> updateShared, List<String> updateVerify, Set<OptionalFile> updateOptional, List<String> jvmArgs, List<String> classPath, List<String> modulePath, List<String> modules, List<String> altClassPath, List<String> clientArgs, List<String> compatClasses, Map<String, String> properties, List<ServerProfile> servers, ClassLoaderConfig classLoaderConfig, List<CompatibilityFlags> flags, String version, String assetIndex, String dir, String assetDir, int recommendJavaVersion, int minJavaVersion, int maxJavaVersion, ProfileDefaultSettings settings, int sortIndex, UUID uuid, String title, String info, String mainClass) { public ClientProfile(List<String> update, List<String> updateExclusions, List<String> updateShared, List<String> updateVerify, Set<OptionalFile> updateOptional, List<String> jvmArgs, List<String> classPath, List<String> modulePath, List<String> modules, List<String> altClassPath, List<String> clientArgs, List<String> compatClasses, Map<String, String> properties, List<ServerProfile> servers, ClassLoaderConfig classLoaderConfig, List<CompatibilityFlags> flags, Version version, String assetIndex, String dir, String assetDir, int recommendJavaVersion, int minJavaVersion, int maxJavaVersion, ProfileDefaultSettings settings, int sortIndex, UUID uuid, String title, String info, String mainClass) {
this.update = update; this.update = update;
this.updateExclusions = updateExclusions; this.updateExclusions = updateExclusions;
this.updateShared = updateShared; this.updateShared = updateShared;
@ -146,7 +148,7 @@ public String getAssetIndex() {
} }
public FileNameMatcher getAssetUpdateMatcher() { public FileNameMatcher getAssetUpdateMatcher() {
return getVersion().compareTo(Version.MC1710) >= 0 ? ASSET_MATCHER : null; return getVersion().compareTo(ClientProfileVersions.MINECRAFT_1_7_10) >= 0 ? ASSET_MATCHER : null;
} }
public String[] getClassPath() { public String[] getClassPath() {
@ -291,11 +293,11 @@ public void setInfo(String info) {
} }
public Version getVersion() { public Version getVersion() {
return Version.byName(version); return version;
} }
public void setVersion(Version version) { public void setVersion(Version version) {
this.version = version.name; this.version = version;
} }
@Deprecated @Deprecated
@ -429,76 +431,6 @@ public List<CompatibilityFlags> getFlags() {
return flags; return flags;
} }
public enum Version {
MC125("1.2.5", 29),
MC147("1.4.7", 51),
MC152("1.5.2", 61),
MC164("1.6.4", 78),
MC172("1.7.2", 4),
MC1710("1.7.10", 5),
MC189("1.8.9", 47),
MC19("1.9", 107),
MC192("1.9.2", 109),
MC194("1.9.4", 110),
MC1102("1.10.2", 210),
MC111("1.11", 315),
MC1112("1.11.2", 316),
MC112("1.12", 335),
MC1121("1.12.1", 338),
MC1122("1.12.2", 340),
MC113("1.13", 393),
MC1131("1.13.1", 401),
MC1132("1.13.2", 402),
MC114("1.14", 477),
MC1141("1.14.1", 480),
MC1142("1.14.2", 485),
MC1143("1.14.3", 490),
MC1144("1.14.4", 498),
MC115("1.15", 573),
MC1151("1.15.1", 575),
MC1152("1.15.2", 578),
MC1161("1.16.1", 736),
MC1162("1.16.2", 751),
MC1163("1.16.3", 753),
MC1164("1.16.4", 754),
MC1165("1.16.5", 754),
MC117("1.17", 755),
MC1171("1.17.1", 756),
MC118("1.18", 757),
MC1181("1.18.1", 757),
MC1182("1.18.2", 758),
MC119("1.19", 759),
MC1191("1.19.1", 760),
MC1192("1.19.2", 760),
MC1193("1.19.3", 761),
MC1194("1.19.4", 762);
private static final Map<String, Version> VERSIONS;
static {
Version[] versionsValues = values();
VERSIONS = new HashMap<>(versionsValues.length);
for (Version version : versionsValues)
VERSIONS.put(version.name, version);
}
public final String name;
public final int protocol;
Version(String name, int protocol) {
this.name = name;
this.protocol = protocol;
}
public static Version byName(String name) {
return VerifyHelper.getMapValue(VERSIONS, name, String.format("Unknown client version: '%s'", name));
}
@Override
public String toString() {
return "Minecraft " + name;
}
}
public enum ClassLoaderConfig { public enum ClassLoaderConfig {
AGENT, LAUNCHER, MODULE, SYSTEM_ARGS AGENT, LAUNCHER, MODULE, SYSTEM_ARGS
} }
@ -507,9 +439,87 @@ public enum CompatibilityFlags {
LEGACY_NATIVES_DIR LEGACY_NATIVES_DIR
} }
@FunctionalInterface public static class Version implements Comparable<Version> {
public interface pushOptionalClassPathCallback { private final long[] data;
void run(String[] opt); private final String original;
private final boolean isObjectSerialized;
public static Version of(String string) {
String tmp = string.replaceAll("[^.0-9]", "."); // Replace any non-digit character to .
String[] list = tmp.split("\\.");
return new Version(Arrays.stream(list)
.filter(e -> !e.isEmpty()) // Filter ".."
.mapToLong(Long::parseLong).toArray(), string);
}
private Version(long[] data, String str) {
this.data = data;
this.original = str;
this.isObjectSerialized = false;
}
public Version(long[] data, String original, boolean isObjectSerialized) {
this.data = data;
this.original = original;
this.isObjectSerialized = isObjectSerialized;
}
@Override
public int compareTo(Version some) {
int result = 0;
for (int i = 0; i < data.length; ++i) {
if (i > some.data.length) break;
result = Long.compare(data[i], some.data[i]);
if (result != 0) return result;
}
return result;
}
public String toCleanString() {
return join(data);
}
private static String join(long[] data) {
return String.join(".", Arrays.stream(data).mapToObj(String::valueOf).toArray(String[]::new));
}
@Override
public String toString() {
return original;
}
public static class GsonSerializer implements JsonSerializer<Version>, JsonDeserializer<Version> {
@Override
public Version deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
if(json.isJsonObject()) {
JsonObject object = json.getAsJsonObject();
String name = object.get("name").getAsString();
long[] list = context.deserialize(object.get("data"), long[].class);
return new Version(list, name, true);
} else if(json.isJsonArray()) {
long[] list = context.deserialize(json, long[].class);
return new Version(list, join(list), false);
} else {
return Version.of(json.getAsString());
}
}
@Override
public JsonElement serialize(Version src, Type typeOfSrc, JsonSerializationContext context) {
if(src.isObjectSerialized) {
JsonObject object = new JsonObject();
object.add("name", new JsonPrimitive(src.original));
JsonArray array = new JsonArray();
for(long l : src.data) {
array.add(l);
}
object.add("data", array);
return object;
}
return new JsonPrimitive(src.toString());
}
}
} }
public static class ServerProfile { public static class ServerProfile {

View file

@ -21,7 +21,7 @@ public class ClientProfileBuilder {
private List<ClientProfile.ServerProfile> servers = new ArrayList<>(); private List<ClientProfile.ServerProfile> servers = new ArrayList<>();
private ClientProfile.ClassLoaderConfig classLoaderConfig = ClientProfile.ClassLoaderConfig.LAUNCHER; private ClientProfile.ClassLoaderConfig classLoaderConfig = ClientProfile.ClassLoaderConfig.LAUNCHER;
private List<ClientProfile.CompatibilityFlags> flags = new ArrayList<>(); private List<ClientProfile.CompatibilityFlags> flags = new ArrayList<>();
private String version; private ClientProfile.Version version;
private String assetIndex; private String assetIndex;
private String dir; private String dir;
private String assetDir; private String assetDir;
@ -91,7 +91,7 @@ public void setClassLoaderConfig(ClientProfile.ClassLoaderConfig classLoaderConf
this.classLoaderConfig = classLoaderConfig; this.classLoaderConfig = classLoaderConfig;
} }
public void setVersion(String version) { public void setVersion(ClientProfile.Version version) {
this.version = version; this.version = version;
} }

View file

@ -0,0 +1,18 @@
package pro.gravit.launcher.profiles;
public class ClientProfileVersions {
private ClientProfileVersions() {
throw new UnsupportedOperationException();
}
public static final ClientProfile.Version MINECRAFT_1_6_4 = ClientProfile.Version.of("1.6.4");
public static final ClientProfile.Version MINECRAFT_1_7_2 = ClientProfile.Version.of("1.7.2");
public static final ClientProfile.Version MINECRAFT_1_7_10 = ClientProfile.Version.of("1.7.10");
public static final ClientProfile.Version MINECRAFT_1_9_4 = ClientProfile.Version.of("1.9.4");
public static final ClientProfile.Version MINECRAFT_1_12_2 = ClientProfile.Version.of("1.12.2");
public static final ClientProfile.Version MINECRAFT_1_13 = ClientProfile.Version.of("1.13");
public static final ClientProfile.Version MINECRAFT_1_16_5 = ClientProfile.Version.of("1.16.5");
public static final ClientProfile.Version MINECRAFT_1_17 = ClientProfile.Version.of("1.17");
public static final ClientProfile.Version MINECRAFT_1_18 = ClientProfile.Version.of("1.18");
public static final ClientProfile.Version MINECRAFT_1_19 = ClientProfile.Version.of("1.19");
}

View file

@ -7,6 +7,7 @@
import pro.gravit.launcher.events.request.*; import pro.gravit.launcher.events.request.*;
import pro.gravit.launcher.hasher.HashedEntry; import pro.gravit.launcher.hasher.HashedEntry;
import pro.gravit.launcher.hasher.HashedEntryAdapter; import pro.gravit.launcher.hasher.HashedEntryAdapter;
import pro.gravit.launcher.profiles.ClientProfile;
import pro.gravit.launcher.profiles.optional.actions.OptionalAction; import pro.gravit.launcher.profiles.optional.actions.OptionalAction;
import pro.gravit.launcher.profiles.optional.triggers.OptionalTrigger; import pro.gravit.launcher.profiles.optional.triggers.OptionalTrigger;
import pro.gravit.launcher.request.WebSocketEvent; import pro.gravit.launcher.request.WebSocketEvent;
@ -40,6 +41,7 @@ public ClientWebSocketService(String address) throws SSLException {
public static void appendTypeAdapters(GsonBuilder builder) { public static void appendTypeAdapters(GsonBuilder builder) {
builder.registerTypeAdapter(HashedEntry.class, new HashedEntryAdapter()); builder.registerTypeAdapter(HashedEntry.class, new HashedEntryAdapter());
builder.registerTypeAdapter(ClientProfile.Version.class, new ClientProfile.Version.GsonSerializer());
builder.registerTypeAdapter(WebSocketEvent.class, new UniversalJsonAdapter<>(ClientWebSocketService.results)); builder.registerTypeAdapter(WebSocketEvent.class, new UniversalJsonAdapter<>(ClientWebSocketService.results));
builder.registerTypeAdapter(WebSocketRequest.class, new UniversalJsonAdapter<>(ClientWebSocketService.requests)); builder.registerTypeAdapter(WebSocketRequest.class, new UniversalJsonAdapter<>(ClientWebSocketService.requests));
builder.registerTypeAdapter(AuthRequest.AuthPasswordInterface.class, new UniversalJsonAdapter<>(AuthRequest.providers)); builder.registerTypeAdapter(AuthRequest.AuthPasswordInterface.class, new UniversalJsonAdapter<>(AuthRequest.providers));

View file

@ -288,7 +288,7 @@ public enum WalkAction {
@FunctionalInterface @FunctionalInterface
public interface WalkCallback { public interface WalkCallback {
WalkAction walked(String path, String name, HashedEntry entry); WalkAction walked(String path, String name, HashedEntry entry) throws IOException;
} }
public static class FindRecursiveResult { public static class FindRecursiveResult {

View file

@ -157,7 +157,7 @@ public void run(String... args) throws Throwable {
ServerAgent.loadLibraries(librariesDir); ServerAgent.loadLibraries(librariesDir);
} }
LogHelper.info("ServerWrapper: LaunchServer address: %s. Title: %s", config.address, Launcher.profile != null ? Launcher.profile.getTitle() : "unknown"); LogHelper.info("ServerWrapper: LaunchServer address: %s. Title: %s", config.address, Launcher.profile != null ? Launcher.profile.getTitle() : "unknown");
LogHelper.info("Minecraft Version (for profile): %s", wrapper.profile == null ? "unknown" : wrapper.profile.getVersion().name); LogHelper.info("Minecraft Version (for profile): %s", wrapper.profile == null ? "unknown" : wrapper.profile.getVersion().toString());
String[] real_args; String[] real_args;
if(config.args != null && config.args.size() > 0) { if(config.args != null && config.args.size() > 0) {
real_args = config.args.toArray(new String[0]); real_args = config.args.toArray(new String[0]);

View file

@ -2,6 +2,7 @@
import pro.gravit.launcher.events.request.GetPublicKeyRequestEvent; import pro.gravit.launcher.events.request.GetPublicKeyRequestEvent;
import pro.gravit.launcher.profiles.ClientProfile; import pro.gravit.launcher.profiles.ClientProfile;
import pro.gravit.launcher.profiles.ClientProfileVersions;
import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.Request;
import pro.gravit.launcher.request.auth.GetPublicKeyRequest; import pro.gravit.launcher.request.auth.GetPublicKeyRequest;
import pro.gravit.launcher.request.websockets.StdWebSocketService; import pro.gravit.launcher.request.websockets.StdWebSocketService;
@ -90,7 +91,7 @@ public void run() throws Exception {
} }
} }
} }
if(wrapper.profile != null && wrapper.profile.getVersion().compareTo(ClientProfile.Version.MC118) >= 0) { if(wrapper.profile != null && wrapper.profile.getVersion().compareTo(ClientProfileVersions.MINECRAFT_1_18) >= 0) {
LogHelper.info("Switch to alternative start mode (1.18)"); LogHelper.info("Switch to alternative start mode (1.18)");
wrapper.config.classpath.add(jarName); wrapper.config.classpath.add(jarName);
wrapper.config.classLoaderConfig = ClientProfile.ClassLoaderConfig.LAUNCHER; wrapper.config.classLoaderConfig = ClientProfile.ClassLoaderConfig.LAUNCHER;

View file

@ -5,7 +5,7 @@
id 'org.openjfx.javafxplugin' version '0.0.10' apply false id 'org.openjfx.javafxplugin' version '0.0.10' apply false
} }
group = 'pro.gravit.launcher' group = 'pro.gravit.launcher'
version = '5.3.6' version = '5.4.0-SNAPSHOT'
apply from: 'props.gradle' apply from: 'props.gradle'

@ -1 +1 @@
Subproject commit 27977fe487fd477f644fa8471b747e87515a61a6 Subproject commit 06e98102578275e84ba8d3b7aed65228ecbfc30e