mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[ANY] New client format support, fix fabric
This commit is contained in:
parent
8c84a80372
commit
b496d60b40
2 changed files with 72 additions and 15 deletions
|
@ -97,6 +97,17 @@ public static ClientProfile makeProfile(ClientProfile.Version version, String ti
|
|||
optionalOther.triggersList = List.of(nonMacTrigger);
|
||||
optionals.add(optionalOther);
|
||||
}
|
||||
Optional<MakeProfileOptionLog4j> logFile = findOption(options, MakeProfileOptionLog4j.class);
|
||||
if(logFile.isPresent()) {
|
||||
var log4jOption = logFile.get();
|
||||
if(log4jOption.logFile != null) {
|
||||
jvmArgs.add("-Dlog4j.configurationFile=".concat(logFile.get().logFile));
|
||||
} else if(log4jOption.affected) {
|
||||
if(version.compareTo(ClientProfile.Version.MC117) >= 0 && version.compareTo(ClientProfile.Version.MC118) < 0) {
|
||||
jvmArgs.add("-Dlog4j2.formatMsgNoLookups=true");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (version.compareTo(ClientProfile.Version.MC117) >= 0) {
|
||||
builder.setMinJavaVersion(16);
|
||||
builder.setRecommendJavaVersion(16);
|
||||
|
@ -156,18 +167,52 @@ public static String getMainClassByVersion(ClientProfile.Version version, MakePr
|
|||
return "net.minecraft.client.main.Main";
|
||||
}
|
||||
|
||||
private static boolean isAffectedLog4jVersion(String version) {
|
||||
if(version == null) {
|
||||
return true;
|
||||
}
|
||||
String[] split = version.split("\\.");
|
||||
if(split.length < 2) return true;
|
||||
if(!split[0].equals("2")) return false;
|
||||
return Integer.parseInt(split[1]) < 15;
|
||||
}
|
||||
|
||||
private static String getLog4jVersion(Path dir) throws IOException {
|
||||
Path log4jCore = dir.resolve("org/apache/logging/log4j/log4j-core");
|
||||
if(Files.exists(log4jCore)) {
|
||||
Path target = Files.list(log4jCore).findFirst().orElse(null);
|
||||
if(target != null) {
|
||||
return target.getFileName().toString();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static MakeProfileOption[] getMakeProfileOptionsFromDir(Path dir, ClientProfile.Version version) throws IOException {
|
||||
List<MakeProfileOption> options = new ArrayList<>(2);
|
||||
if (version.compareTo(ClientProfile.Version.MC1122) <= 0) {
|
||||
if (Files.exists(dir.resolve("forge.jar"))) {
|
||||
if (Files.exists(dir.resolve("forge.jar"))) {
|
||||
options.add(new MakeProfileOptionForge());
|
||||
}
|
||||
else if (Files.exists(dir.resolve("libraries/net/minecraftforge/forge"))) {
|
||||
if(version.compareTo(ClientProfile.Version.MC1122) > 0) {
|
||||
options.add(new MakeProfileOptionForge(dir));
|
||||
} else {
|
||||
options.add(new MakeProfileOptionForge());
|
||||
}
|
||||
} else {
|
||||
if (Files.exists(dir.resolve("libraries/net/minecraftforge/forge"))) {
|
||||
options.add(new MakeProfileOptionForge(dir));
|
||||
}
|
||||
if (Files.exists(dir.resolve("libraries/net/fabricmc/fabric-loader"))) {
|
||||
options.add(new MakeProfileOptionFabric(dir));
|
||||
}
|
||||
if (Files.exists(dir.resolve("libraries/net/fabricmc/fabric-loader"))) {
|
||||
options.add(new MakeProfileOptionFabric(dir));
|
||||
}
|
||||
{
|
||||
String log4jVersion = getLog4jVersion(dir);
|
||||
if(log4jVersion != null) {
|
||||
|
||||
boolean affected = isAffectedLog4jVersion(log4jVersion);
|
||||
if(Files.exists(dir.resolve("log4j2_custom.xml"))) {
|
||||
options.add(new MakeProfileOptionLog4j(affected, "log4j2_custom.xml"));
|
||||
} else {
|
||||
options.add(new MakeProfileOptionLog4j(affected, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Files.exists(dir.resolve("liteloader.jar"))) {
|
||||
|
@ -176,7 +221,7 @@ public static MakeProfileOption[] getMakeProfileOptionsFromDir(Path dir, ClientP
|
|||
if (Files.exists(dir.resolve("libraries/org/lwjgl/lwjgl/3.2.2")) && Files.exists(dir.resolve("libraries/org/lwjgl/lwjgl/3.2.1"))) {
|
||||
options.add(new MakeProfileOptionLwjgl());
|
||||
}
|
||||
if (version.compareTo(ClientProfile.Version.MC1122) <= 0) {
|
||||
if (Files.exists(dir.resolve("libraries/forge/launchwrapper-1.12-launcherfixed.jar.jar")) || Files.exists(dir.resolve("libraries/net/minecraft/launchwrapper"))) {
|
||||
options.add(new MakeProfileOptionLaunchWrapper());
|
||||
}
|
||||
return options.toArray(new MakeProfileOption[0]);
|
||||
|
@ -193,6 +238,16 @@ private static Path findFirstMavenFile(Path path) throws IOException {
|
|||
public interface MakeProfileOption {
|
||||
}
|
||||
|
||||
public static class MakeProfileOptionLog4j implements MakeProfileOption {
|
||||
public boolean affected;
|
||||
public String logFile;
|
||||
|
||||
public MakeProfileOptionLog4j(boolean lower15, String logFile) {
|
||||
this.affected = lower15;
|
||||
this.logFile = logFile;
|
||||
}
|
||||
}
|
||||
|
||||
public static class MakeProfileOptionForge implements MakeProfileOption {
|
||||
public String launchTarget;
|
||||
public String forgeVersion;
|
||||
|
|
|
@ -119,7 +119,8 @@ public static void main(String[] args) throws Throwable {
|
|||
|
||||
// Verify ClientLauncher sign and classpath
|
||||
LogHelper.debug("Verifying ClientLauncher sign and classpath");
|
||||
List<URL> classpath = resolveClassPath(clientDir, params.actions, params.profile).map(IOHelper::toURL).collect(Collectors.toList());
|
||||
List<Path> classpath = resolveClassPath(clientDir, params.actions, params.profile).collect(Collectors.toList());
|
||||
List<URL> classpathURLs = classpath.stream().map(IOHelper::toURL).collect(Collectors.toList());
|
||||
// Start client with WatchService monitoring
|
||||
boolean digest = !profile.isUpdateFastCheck();
|
||||
RequestService service;
|
||||
|
@ -145,7 +146,8 @@ public static void main(String[] args) throws Throwable {
|
|||
}
|
||||
ClientProfile.ClassLoaderConfig classLoaderConfig = profile.getClassLoaderConfig();
|
||||
if (classLoaderConfig == ClientProfile.ClassLoaderConfig.LAUNCHER) {
|
||||
ClientClassLoader classLoader = new ClientClassLoader(classpath.toArray(new URL[0]), ClassLoader.getSystemClassLoader());
|
||||
ClientClassLoader classLoader = new ClientClassLoader(classpathURLs.toArray(new URL[0]), ClassLoader.getSystemClassLoader());
|
||||
System.setProperty("java.class.path", classpath.stream().map(Path::toString).collect(Collectors.joining(File.pathSeparator)));
|
||||
ClientLauncherEntryPoint.classLoader = classLoader;
|
||||
Thread.currentThread().setContextClassLoader(classLoader);
|
||||
classLoader.nativePath = clientDir.resolve("natives").toString();
|
||||
|
@ -156,19 +158,19 @@ public static void main(String[] args) throws Throwable {
|
|||
ClientService.baseURLs = classLoader.getURLs();
|
||||
} else if (classLoaderConfig == ClientProfile.ClassLoaderConfig.AGENT) {
|
||||
ClientLauncherEntryPoint.classLoader = ClassLoader.getSystemClassLoader();
|
||||
classpath.add(IOHelper.getCodeSource(ClientLauncherEntryPoint.class).toUri().toURL());
|
||||
for (URL url : classpath) {
|
||||
classpathURLs.add(IOHelper.getCodeSource(ClientLauncherEntryPoint.class).toUri().toURL());
|
||||
for (URL url : classpathURLs) {
|
||||
LauncherAgent.addJVMClassPath(Paths.get(url.toURI()));
|
||||
}
|
||||
ClientService.instrumentation = LauncherAgent.inst;
|
||||
ClientService.nativePath = clientDir.resolve("natives").toString();
|
||||
LauncherEngine.modulesManager.invokeEvent(new ClientProcessClassLoaderEvent(engine, classLoader, profile));
|
||||
ClientService.classLoader = classLoader;
|
||||
ClientService.baseURLs = classpath.toArray(new URL[0]);
|
||||
ClientService.baseURLs = classpathURLs.toArray(new URL[0]);
|
||||
} else if (classLoaderConfig == ClientProfile.ClassLoaderConfig.SYSTEM_ARGS) {
|
||||
ClientLauncherEntryPoint.classLoader = ClassLoader.getSystemClassLoader();
|
||||
ClientService.classLoader = ClassLoader.getSystemClassLoader();
|
||||
ClientService.baseURLs = classpath.toArray(new URL[0]);
|
||||
ClientService.baseURLs = classpathURLs.toArray(new URL[0]);
|
||||
}
|
||||
AuthService.username = params.playerProfile.username;
|
||||
AuthService.uuid = params.playerProfile.uuid;
|
||||
|
|
Loading…
Reference in a new issue