mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-01-10 01:29:45 +03:00
[FEATURE] ClientLauncherContext
This commit is contained in:
parent
aad6ea7833
commit
5dc07290eb
6 changed files with 88 additions and 32 deletions
|
@ -302,6 +302,7 @@ public static Process launch(
|
||||||
ClientProfile profile, Params params, boolean pipeOutput) throws Throwable {
|
ClientProfile profile, Params params, boolean pipeOutput) throws Throwable {
|
||||||
// Write params file (instead of CLI; Mustdie32 API can't handle command line > 32767 chars)
|
// Write params file (instead of CLI; Mustdie32 API can't handle command line > 32767 chars)
|
||||||
LogHelper.debug("Writing ClientLauncher params");
|
LogHelper.debug("Writing ClientLauncher params");
|
||||||
|
ClientLauncherContext context = new ClientLauncherContext();
|
||||||
CommonHelper.newThread("Client params writter", false, () ->
|
CommonHelper.newThread("Client params writter", false, () ->
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
@ -333,53 +334,44 @@ public static Process launch(
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
checkJVMBitsAndVersion();
|
checkJVMBitsAndVersion();
|
||||||
// Fill CLI arguments
|
|
||||||
List<String> args = new LinkedList<>();
|
|
||||||
boolean wrapper = isUsingWrapper();
|
|
||||||
LogHelper.debug("Resolving JVM binary");
|
LogHelper.debug("Resolving JVM binary");
|
||||||
Path javaBin = LauncherGuardManager.getGuardJavaBinPath();
|
Path javaBin = LauncherGuardManager.getGuardJavaBinPath();
|
||||||
args.add(javaBin.toString());
|
context.args.add(javaBin.toString());
|
||||||
args.add(MAGICAL_INTEL_OPTION);
|
context.args.add(MAGICAL_INTEL_OPTION);
|
||||||
if (params.ram > 0 && params.ram <= JVMHelper.RAM) {
|
if (params.ram > 0 && params.ram <= JVMHelper.RAM) {
|
||||||
args.add("-Xms" + params.ram + 'M');
|
context.args.add("-Xms" + params.ram + 'M');
|
||||||
args.add("-Xmx" + params.ram + 'M');
|
context.args.add("-Xmx" + params.ram + 'M');
|
||||||
}
|
}
|
||||||
args.add(JVMHelper.jvmProperty(LogHelper.DEBUG_PROPERTY, Boolean.toString(LogHelper.isDebugEnabled())));
|
context.args.add(JVMHelper.jvmProperty(LogHelper.DEBUG_PROPERTY, Boolean.toString(LogHelper.isDebugEnabled())));
|
||||||
args.add(JVMHelper.jvmProperty(LogHelper.STACKTRACE_PROPERTY, Boolean.toString(LogHelper.isStacktraceEnabled())));
|
context.args.add(JVMHelper.jvmProperty(LogHelper.STACKTRACE_PROPERTY, Boolean.toString(LogHelper.isStacktraceEnabled())));
|
||||||
args.add(JVMHelper.jvmProperty(LogHelper.DEV_PROPERTY, Boolean.toString(LogHelper.isDevEnabled())));
|
context.args.add(JVMHelper.jvmProperty(LogHelper.DEV_PROPERTY, Boolean.toString(LogHelper.isDevEnabled())));
|
||||||
if (LauncherConfig.ADDRESS_OVERRIDE != null)
|
if (LauncherConfig.ADDRESS_OVERRIDE != null)
|
||||||
args.add(JVMHelper.jvmProperty(LauncherConfig.ADDRESS_OVERRIDE_PROPERTY, LauncherConfig.ADDRESS_OVERRIDE));
|
context.args.add(JVMHelper.jvmProperty(LauncherConfig.ADDRESS_OVERRIDE_PROPERTY, LauncherConfig.ADDRESS_OVERRIDE));
|
||||||
if (JVMHelper.OS_TYPE == OS.MUSTDIE) {
|
if (JVMHelper.OS_TYPE == OS.MUSTDIE) {
|
||||||
if (JVMHelper.OS_VERSION.startsWith("10.")) {
|
if (JVMHelper.OS_VERSION.startsWith("10.")) {
|
||||||
LogHelper.debug("MustDie 10 fix is applied");
|
LogHelper.debug("MustDie 10 fix is applied");
|
||||||
args.add(JVMHelper.jvmProperty("os.name", "Windows 10"));
|
context.args.add(JVMHelper.jvmProperty("os.name", "Windows 10"));
|
||||||
args.add(JVMHelper.jvmProperty("os.version", "10.0"));
|
context.args.add(JVMHelper.jvmProperty("os.version", "10.0"));
|
||||||
}
|
}
|
||||||
args.add(JVMHelper.systemToJvmProperty("avn32"));
|
context.args.add(JVMHelper.systemToJvmProperty("avn32"));
|
||||||
args.add(JVMHelper.systemToJvmProperty("avn64"));
|
context.args.add(JVMHelper.systemToJvmProperty("avn64"));
|
||||||
}
|
}
|
||||||
// Add classpath and main class
|
// Add classpath and main class
|
||||||
String pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString();
|
String pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString();
|
||||||
Collections.addAll(args, profile.getJvmArgs());
|
Collections.addAll(context.args, profile.getJvmArgs());
|
||||||
profile.pushOptionalJvmArgs(args);
|
profile.pushOptionalJvmArgs(context.args);
|
||||||
Collections.addAll(args, "-Djava.library.path=".concat(params.clientDir.resolve(NATIVES_DIR).toString())); // Add Native Path
|
Collections.addAll(context.args, "-Djava.library.path=".concat(params.clientDir.resolve(NATIVES_DIR).toString())); // Add Native Path
|
||||||
Collections.addAll(args, "-javaagent:".concat(pathLauncher));
|
Collections.addAll(context.args, "-javaagent:".concat(pathLauncher));
|
||||||
if (wrapper)
|
LauncherGuardManager.guard.addCustomParams(context);
|
||||||
Collections.addAll(args, "-Djava.class.path=".concat(pathLauncher)); // Add Class Path
|
Collections.addAll(context.args, ClientLauncher.class.getName());
|
||||||
else {
|
|
||||||
Collections.addAll(args, "-cp");
|
|
||||||
Collections.addAll(args, pathLauncher);
|
|
||||||
}
|
|
||||||
Collections.addAll(args, ClientLauncher.class.getName());
|
|
||||||
|
|
||||||
// Print commandline debug message
|
// Print commandline debug message
|
||||||
LogHelper.debug("Commandline: " + args);
|
LogHelper.debug("Commandline: " + context.args);
|
||||||
|
|
||||||
// Build client process
|
// Build client process
|
||||||
LogHelper.debug("Launching client instance");
|
LogHelper.debug("Launching client instance");
|
||||||
ProcessBuilder builder = new ProcessBuilder(args);
|
ProcessBuilder builder = new ProcessBuilder(context.args);
|
||||||
if (wrapper)
|
LauncherGuardManager.guard.addCustomEnv(context);
|
||||||
builder.environment().put("JAVA_HOME", System.getProperty("java.home"));
|
|
||||||
//else
|
//else
|
||||||
//builder.environment().put("CLASSPATH", classPathString.toString());
|
//builder.environment().put("CLASSPATH", classPathString.toString());
|
||||||
EnvHelper.addEnv(builder);
|
EnvHelper.addEnv(builder);
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
package ru.gravit.launcher.client;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ClientLauncherContext {
|
||||||
|
public Path javaBin;
|
||||||
|
public List<String> args = new LinkedList<>();
|
||||||
|
public String pathLauncher;
|
||||||
|
public ProcessBuilder builder;
|
||||||
|
}
|
|
@ -1,9 +1,14 @@
|
||||||
package ru.gravit.launcher.guard;
|
package ru.gravit.launcher.guard;
|
||||||
|
|
||||||
|
import ru.gravit.launcher.client.ClientLauncherContext;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
public interface LauncherGuardInterface {
|
public interface LauncherGuardInterface {
|
||||||
String getName();
|
String getName();
|
||||||
Path getJavaBinPath();
|
Path getJavaBinPath();
|
||||||
void init(boolean clientInstance);
|
void init(boolean clientInstance);
|
||||||
|
void addCustomParams(ClientLauncherContext context);
|
||||||
|
void addCustomEnv(ClientLauncherContext context);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
package ru.gravit.launcher.guard;
|
package ru.gravit.launcher.guard;
|
||||||
|
|
||||||
import ru.gravit.launcher.client.ClientLauncher;
|
import ru.gravit.launcher.client.ClientLauncher;
|
||||||
|
import ru.gravit.launcher.client.ClientLauncherContext;
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
import ru.gravit.utils.helper.JVMHelper;
|
import ru.gravit.utils.helper.JVMHelper;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
public class LauncherJavaGuard implements LauncherGuardInterface {
|
public class LauncherJavaGuard implements LauncherGuardInterface {
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,4 +28,15 @@ public Path getJavaBinPath() {
|
||||||
public void init(boolean clientInstance) {
|
public void init(boolean clientInstance) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addCustomParams(ClientLauncherContext context) {
|
||||||
|
Collections.addAll(context.args, "-cp");
|
||||||
|
Collections.addAll(context.args, context.pathLauncher);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addCustomEnv(ClientLauncherContext context) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
package ru.gravit.launcher.guard;
|
package ru.gravit.launcher.guard;
|
||||||
|
|
||||||
|
import ru.gravit.launcher.client.ClientLauncherContext;
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
public class LauncherNoGuard implements LauncherGuardInterface {
|
public class LauncherNoGuard implements LauncherGuardInterface {
|
||||||
@Override
|
@Override
|
||||||
|
@ -21,4 +24,15 @@ public Path getJavaBinPath() {
|
||||||
public void init(boolean clientInstance) {
|
public void init(boolean clientInstance) {
|
||||||
LogHelper.warning("Using noGuard interface");
|
LogHelper.warning("Using noGuard interface");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addCustomParams(ClientLauncherContext context) {
|
||||||
|
Collections.addAll(context.args, "-cp");
|
||||||
|
Collections.addAll(context.args, context.pathLauncher);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addCustomEnv(ClientLauncherContext context) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package ru.gravit.launcher.guard;
|
package ru.gravit.launcher.guard;
|
||||||
|
|
||||||
import ru.gravit.launcher.Launcher;
|
import ru.gravit.launcher.Launcher;
|
||||||
|
import ru.gravit.launcher.client.ClientLauncherContext;
|
||||||
import ru.gravit.launcher.client.DirBridge;
|
import ru.gravit.launcher.client.DirBridge;
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
import ru.gravit.utils.helper.JVMHelper;
|
import ru.gravit.utils.helper.JVMHelper;
|
||||||
|
@ -9,6 +10,8 @@
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
public class LauncherWrapperGuard implements LauncherGuardInterface {
|
public class LauncherWrapperGuard implements LauncherGuardInterface {
|
||||||
@Override
|
@Override
|
||||||
|
@ -19,7 +22,11 @@ public String getName() {
|
||||||
@Override
|
@Override
|
||||||
public Path getJavaBinPath() {
|
public Path getJavaBinPath() {
|
||||||
if(JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE)
|
if(JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE)
|
||||||
return DirBridge.getGuardDir().resolve(JVMHelper.JVM_BITS == 64 ? "wrapper64.exe" : "wrapper32.exe");
|
{
|
||||||
|
String projectName = Launcher.getConfig().projectname;
|
||||||
|
String wrapperUnpackName = JVMHelper.JVM_BITS == 64 ? projectName.concat("64.exe") : projectName.concat("32.exe");
|
||||||
|
return DirBridge.getGuardDir().resolve(wrapperUnpackName);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
return IOHelper.resolveJavaBin(Paths.get(System.getProperty("java.home")));
|
return IOHelper.resolveJavaBin(Paths.get(System.getProperty("java.home")));
|
||||||
}
|
}
|
||||||
|
@ -28,11 +35,23 @@ public Path getJavaBinPath() {
|
||||||
public void init(boolean clientInstance) {
|
public void init(boolean clientInstance) {
|
||||||
try {
|
try {
|
||||||
String wrapperName = JVMHelper.JVM_BITS == 64 ? "wrapper64.exe" : "wrapper32.exe";
|
String wrapperName = JVMHelper.JVM_BITS == 64 ? "wrapper64.exe" : "wrapper32.exe";
|
||||||
|
String projectName = Launcher.getConfig().projectname;
|
||||||
|
String wrapperUnpackName = JVMHelper.JVM_BITS == 64 ? projectName.concat("64.exe") : projectName.concat("32.exe");
|
||||||
String antiInjectName = JVMHelper.JVM_BITS == 64 ? "AntiInject64.dll" : "AntiInject32.dll";
|
String antiInjectName = JVMHelper.JVM_BITS == 64 ? "AntiInject64.dll" : "AntiInject32.dll";
|
||||||
UnpackHelper.unpack(Launcher.getResourceURL(wrapperName, "guard"),DirBridge.getGuardDir().resolve(wrapperName));
|
UnpackHelper.unpack(Launcher.getResourceURL(wrapperName, "guard"),DirBridge.getGuardDir().resolve(wrapperUnpackName));
|
||||||
UnpackHelper.unpack(Launcher.getResourceURL(antiInjectName, "guard"),DirBridge.getGuardDir().resolve(antiInjectName));
|
UnpackHelper.unpack(Launcher.getResourceURL(antiInjectName, "guard"),DirBridge.getGuardDir().resolve(antiInjectName));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new SecurityException(e);
|
throw new SecurityException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addCustomParams(ClientLauncherContext context) {
|
||||||
|
Collections.addAll(context.args, "-Djava.class.path=".concat(context.pathLauncher));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addCustomEnv(ClientLauncherContext context) {
|
||||||
|
context.builder.environment().put("JAVA_HOME", System.getProperty("java.home"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue