mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
Compare commits
No commits in common. "537623afaf1b23ae4a626196e5eca8dcc2fd3353" and "8509cbb6b54bcee6b67748fb22460b3a224662de" have entirely different histories.
537623afaf
...
8509cbb6b5
12 changed files with 92 additions and 31 deletions
|
@ -7,7 +7,10 @@
|
|||
import pro.gravit.utils.helper.UnpackHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.FileVisitResult;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.SimpleFileVisitor;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -37,7 +40,7 @@ public Path process(Path inputFile) throws IOException {
|
|||
if(Files.isDirectory(server.launcherLibrariesCompile)) {
|
||||
IOHelper.walk(server.launcherLibrariesCompile, new ListFileVisitor(server.launcherBinary.addonLibs), false);
|
||||
}
|
||||
try(Stream<Path> stream = Files.walk(server.launcherPack, FileVisitOption.FOLLOW_LINKS).filter((e) -> {
|
||||
try(Stream<Path> stream = Files.walk(server.launcherPack).filter((e) -> {
|
||||
try {
|
||||
return !Files.isDirectory(e) && !Files.isHidden(e);
|
||||
} catch (IOException ex) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
apply plugin: 'com.github.johnrengelman.shadow'
|
||||
|
||||
String mainClassName = "pro.gravit.launcher.start.ClientLauncherWrapper"
|
||||
String mainAgentName = "pro.gravit.launcher.runtime.LauncherAgent"
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
|
@ -19,6 +20,7 @@
|
|||
jar {
|
||||
archiveClassifier.set('clean')
|
||||
manifest.attributes("Main-Class": mainClassName,
|
||||
"Premain-Class": mainAgentName,
|
||||
"Multi-Release": "true",
|
||||
"Automatic-Module-Name": "GravitLauncher")
|
||||
}
|
||||
|
|
|
@ -124,6 +124,7 @@ public static void main(String... args) throws Throwable {
|
|||
LogHelper.printLicense("Launcher");
|
||||
LauncherEngine.checkClass(LauncherEngineWrapper.class);
|
||||
LauncherEngine.checkClass(LauncherEngine.class);
|
||||
LauncherEngine.checkClass(LauncherAgent.class);
|
||||
LauncherEngine.checkClass(ClientLauncherEntryPoint.class);
|
||||
LauncherEngine.modulesManager = new RuntimeModuleManager();
|
||||
LauncherEngine.modulesManager.loadModule(new RuntimeLauncherCoreModule());
|
||||
|
|
|
@ -142,7 +142,9 @@ public void start(boolean pipeOutput) throws IOException, InterruptedException {
|
|||
}
|
||||
//ADD CLASSPATH
|
||||
processArgs.add(JVMHelper.jvmProperty("java.library.path", this.params.nativesDir));
|
||||
if (params.profile.getClassLoaderConfig() == ClientProfile.ClassLoaderConfig.SYSTEM_ARGS) {
|
||||
if (params.profile.getClassLoaderConfig() == ClientProfile.ClassLoaderConfig.AGENT) {
|
||||
processArgs.add("-javaagent:".concat(IOHelper.getCodeSource(ClientLauncherEntryPoint.class).toAbsolutePath().toString()));
|
||||
} else if (params.profile.getClassLoaderConfig() == ClientProfile.ClassLoaderConfig.SYSTEM_ARGS) {
|
||||
Set<Path> ignorePath = new HashSet<>();
|
||||
var moduleConf = params.profile.getModuleConf();
|
||||
if(moduleConf != null) {
|
||||
|
@ -157,24 +159,6 @@ public void start(boolean pipeOutput) throws IOException, InterruptedException {
|
|||
processArgs.add("--add-modules");
|
||||
processArgs.add(String.join(",", moduleConf.modules));
|
||||
}
|
||||
if(moduleConf.exports != null && !moduleConf.exports.isEmpty()) {
|
||||
for(var e : moduleConf.exports.entrySet()) {
|
||||
processArgs.add("--add-exports");
|
||||
processArgs.add(String.format("%s=%s", e.getKey(), e.getValue()));
|
||||
}
|
||||
}
|
||||
if(moduleConf.opens != null && !moduleConf.opens.isEmpty()) {
|
||||
for(var e : moduleConf.opens.entrySet()) {
|
||||
processArgs.add("--add-opens");
|
||||
processArgs.add(String.format("%s=%s", e.getKey(), e.getValue()));
|
||||
}
|
||||
}
|
||||
if(moduleConf.reads != null && !moduleConf.reads.isEmpty()) {
|
||||
for(var e : moduleConf.reads.entrySet()) {
|
||||
processArgs.add("--add-reads");
|
||||
processArgs.add(String.format("%s=%s", e.getKey(), e.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
systemClassPath.addAll(ClientLauncherEntryPoint.resolveClassPath(ignorePath, workDir, params.actions, params.profile)
|
||||
.map(Path::toString)
|
||||
|
|
|
@ -392,7 +392,7 @@ public List<CompatibilityFlags> getFlags() {
|
|||
}
|
||||
|
||||
public enum ClassLoaderConfig {
|
||||
LAUNCHER, MODULE, SYSTEM_ARGS
|
||||
AGENT, LAUNCHER, MODULE, SYSTEM_ARGS
|
||||
}
|
||||
|
||||
public enum CompatibilityFlags {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
apply plugin: 'org.openjfx.javafxplugin'
|
||||
|
||||
String mainClassName = "pro.gravit.launcher.start.ClientLauncherWrapper"
|
||||
String mainClassName = "pro.gravit.launcher.ClientLauncherWrapper"
|
||||
String mainAgentName = "pro.gravit.launcher.LauncherAgent"
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
|
@ -13,6 +14,7 @@
|
|||
jar {
|
||||
archiveClassifier.set('clean')
|
||||
manifest.attributes("Main-Class": mainClassName,
|
||||
"Premain-Class": mainAgentName,
|
||||
"Multi-Release": "true")
|
||||
}
|
||||
|
||||
|
|
|
@ -86,7 +86,9 @@ private static void realMain(String[] args) throws Throwable {
|
|||
modulesManager.invokeEvent(new PreConfigPhase());
|
||||
LogHelper.debug("Reading ClientLauncher params");
|
||||
ClientParams params = readParams(new InetSocketAddress("127.0.0.1", Launcher.getConfig().clientPort));
|
||||
ClientLauncherMethods.verifyNoAgent();
|
||||
if (params.profile.getClassLoaderConfig() != ClientProfile.ClassLoaderConfig.AGENT) {
|
||||
ClientLauncherMethods.verifyNoAgent();
|
||||
}
|
||||
if(params.timestamp > System.currentTimeMillis() || params.timestamp + 30*1000 < System.currentTimeMillis() ) {
|
||||
LogHelper.error("Timestamp failed. Exit");
|
||||
ClientLauncherMethods.exitLauncher(-662);
|
||||
|
@ -158,7 +160,7 @@ private static void realMain(String[] args) throws Throwable {
|
|||
System.load(Paths.get(params.nativesDir).resolve(ClientService.findLibrary(e)).toAbsolutePath().toString());
|
||||
}
|
||||
}
|
||||
if (classLoaderConfig == ClientProfile.ClassLoaderConfig.LAUNCHER || classLoaderConfig == ClientProfile.ClassLoaderConfig.MODULE) {
|
||||
if (classLoaderConfig == ClientProfile.ClassLoaderConfig.LAUNCHER) {
|
||||
if(JVMHelper.JVM_VERSION <= 11) {
|
||||
launch = new LegacyLaunch();
|
||||
} else {
|
||||
|
@ -168,12 +170,20 @@ private static void realMain(String[] args) throws Throwable {
|
|||
System.setProperty("java.class.path", classpath.stream().map(Path::toString).collect(Collectors.joining(File.pathSeparator)));
|
||||
modulesManager.invokeEvent(new ClientProcessClassLoaderEvent(launch, classLoaderControl, profile));
|
||||
ClientService.baseURLs = classLoaderControl.getURLs();
|
||||
} else if (classLoaderConfig == ClientProfile.ClassLoaderConfig.AGENT) {
|
||||
launch = new BasicLaunch(LauncherAgent.inst);
|
||||
classpathURLs.add(IOHelper.getCodeSource(ClientLauncherEntryPoint.class).toUri().toURL());
|
||||
classLoaderControl = launch.init(classpath, params.nativesDir, options);
|
||||
for (URL url : classpathURLs) {
|
||||
LauncherAgent.addJVMClassPath(Paths.get(url.toURI()));
|
||||
}
|
||||
ClientService.instrumentation = LauncherAgent.inst;
|
||||
modulesManager.invokeEvent(new ClientProcessClassLoaderEvent(launch, null, profile));
|
||||
ClientService.baseURLs = classpathURLs.toArray(new URL[0]);
|
||||
} else if (classLoaderConfig == ClientProfile.ClassLoaderConfig.SYSTEM_ARGS) {
|
||||
launch = new BasicLaunch();
|
||||
classLoaderControl = launch.init(classpath, params.nativesDir, options);
|
||||
ClientService.baseURLs = classpathURLs.toArray(new URL[0]);
|
||||
} else {
|
||||
throw new UnsupportedOperationException(String.format("Unknown classLoaderConfig %s", classLoaderConfig));
|
||||
}
|
||||
if(profile.hasFlag(ClientProfile.CompatibilityFlags.CLASS_CONTROL_API)) {
|
||||
ClientService.classLoaderControl = classLoaderControl;
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
package pro.gravit.launcher.client;
|
||||
|
||||
import pro.gravit.launcher.client.utils.NativeJVMHalt;
|
||||
import pro.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.nio.file.Path;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
|
||||
public final class LauncherAgent {
|
||||
public static Instrumentation inst;
|
||||
private static boolean isAgentStarted = false;
|
||||
|
||||
public static void addJVMClassPath(String path) throws IOException {
|
||||
LogHelper.debug("Launcher Agent addJVMClassPath");
|
||||
inst.appendToSystemClassLoaderSearch(new JarFile(new File(path)));
|
||||
}
|
||||
|
||||
public static void addJVMClassPath(Path path) throws IOException {
|
||||
LogHelper.debug("Launcher Agent addJVMClassPath");
|
||||
inst.appendToSystemClassLoaderSearch(new JarFile(path.toFile()));
|
||||
}
|
||||
|
||||
public static void premain(String agentArgument, Instrumentation instrumentation) {
|
||||
System.out.println("Launcher Agent");
|
||||
checkAgentStacktrace();
|
||||
inst = instrumentation;
|
||||
NativeJVMHalt.initFunc();
|
||||
isAgentStarted = true;
|
||||
}
|
||||
|
||||
public static void checkAgentStacktrace() {
|
||||
RuntimeException ex = new SecurityException("Error check agent stacktrace");
|
||||
boolean isFoundNative = false;
|
||||
boolean foundPreMain = false;
|
||||
for (StackTraceElement e : ex.getStackTrace()) {
|
||||
if (e.isNativeMethod()) {
|
||||
if (!isFoundNative) isFoundNative = true;
|
||||
else throw ex;
|
||||
}
|
||||
if (e.getMethodName().equals("premain")) {
|
||||
if (!foundPreMain) foundPreMain = true;
|
||||
else throw ex;
|
||||
}
|
||||
}
|
||||
if (!isFoundNative || !foundPreMain) throw ex;
|
||||
}
|
||||
|
||||
public static boolean isStarted() {
|
||||
return isAgentStarted;
|
||||
}
|
||||
|
||||
public boolean isAgentStarted() {
|
||||
return isAgentStarted;
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@ public final class Version implements Comparable<Version> {
|
|||
public static final int MINOR = 6;
|
||||
public static final int PATCH = 6;
|
||||
public static final int BUILD = 1;
|
||||
public static final Version.Type RELEASE = Type.STABLE;
|
||||
public static final Version.Type RELEASE = Type.DEV;
|
||||
public final int major;
|
||||
public final int minor;
|
||||
public final int patch;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
id 'org.openjfx.javafxplugin' version '0.1.0' apply false
|
||||
}
|
||||
group = 'pro.gravit.launcher'
|
||||
version = '5.6.6'
|
||||
version = '5.6.5'
|
||||
|
||||
apply from: 'props.gradle'
|
||||
|
||||
|
|
2
modules
2
modules
|
@ -1 +1 @@
|
|||
Subproject commit 65f882bd90623aa1581ad24cfa4f52563ea95bc0
|
||||
Subproject commit fd0bbc04d1bcc2af9b0c86569166f491c266693b
|
|
@ -1,7 +1,7 @@
|
|||
project.ext {
|
||||
verAsm = '9.7'
|
||||
verNetty = '4.1.111.Final'
|
||||
verOshiCore = '6.6.2'
|
||||
verOshiCore = '6.6.1'
|
||||
verJunit = '5.10.2'
|
||||
verJansi = '2.4.1'
|
||||
verJline = '3.26.1'
|
||||
|
|
Loading…
Reference in a new issue