[FEATURE] Support option loadNatives

This commit is contained in:
Gravita 2023-12-14 01:36:07 +07:00
parent 240e36aab6
commit 5896a12449
3 changed files with 20 additions and 5 deletions

View file

@ -60,6 +60,8 @@ public final class ClientProfile implements Comparable<ClientProfile> {
@LauncherNetworkAPI @LauncherNetworkAPI
private List<String> compatClasses; private List<String> compatClasses;
@LauncherNetworkAPI @LauncherNetworkAPI
private List<String> loadNatives;
@LauncherNetworkAPI
private Map<String, String> properties; private Map<String, String> properties;
@LauncherNetworkAPI @LauncherNetworkAPI
private List<ServerProfile> servers; private List<ServerProfile> servers;
@ -253,6 +255,10 @@ public ProfileDefaultSettings getSettings() {
return settings; return settings;
} }
public List<String> getLoadNatives() {
return loadNatives;
}
public void updateOptionalGraph() { public void updateOptionalGraph() {
for (OptionalFile file : updateOptional) { for (OptionalFile file : updateOptional) {
if (file.dependenciesFile != null) { if (file.dependenciesFile != null) {

View file

@ -142,6 +142,12 @@ private static void realMain(String[] args) throws Throwable {
LaunchOptions options = new LaunchOptions(); LaunchOptions options = new LaunchOptions();
options.enableHacks = profile.hasFlag(ClientProfile.CompatibilityFlags.ENABLE_HACKS); options.enableHacks = profile.hasFlag(ClientProfile.CompatibilityFlags.ENABLE_HACKS);
options.moduleConf = profile.getModuleConf(); options.moduleConf = profile.getModuleConf();
ClientService.nativePath = params.nativesDir;
if(profile.getLoadNatives() != null) {
for(String e : profile.getLoadNatives()) {
System.load(Paths.get(params.nativesDir).resolve(ClientService.findLibrary(e)).toAbsolutePath().toString());
}
}
if (classLoaderConfig == ClientProfile.ClassLoaderConfig.LAUNCHER) { if (classLoaderConfig == ClientProfile.ClassLoaderConfig.LAUNCHER) {
if(JVMHelper.JVM_VERSION <= 11) { if(JVMHelper.JVM_VERSION <= 11) {
launch = new LegacyLaunch(); launch = new LegacyLaunch();
@ -151,7 +157,6 @@ private static void realMain(String[] args) throws Throwable {
classLoaderControl = launch.init(classpath, params.nativesDir, options); classLoaderControl = launch.init(classpath, params.nativesDir, options);
System.setProperty("java.class.path", classpath.stream().map(Path::toString).collect(Collectors.joining(File.pathSeparator))); System.setProperty("java.class.path", classpath.stream().map(Path::toString).collect(Collectors.joining(File.pathSeparator)));
modulesManager.invokeEvent(new ClientProcessClassLoaderEvent(launch, classLoaderControl, profile)); modulesManager.invokeEvent(new ClientProcessClassLoaderEvent(launch, classLoaderControl, profile));
ClientService.nativePath = params.nativesDir;
ClientService.baseURLs = classLoaderControl.getURLs(); ClientService.baseURLs = classLoaderControl.getURLs();
} else if (classLoaderConfig == ClientProfile.ClassLoaderConfig.AGENT) { } else if (classLoaderConfig == ClientProfile.ClassLoaderConfig.AGENT) {
launch = new BasicLaunch(LauncherAgent.inst); launch = new BasicLaunch(LauncherAgent.inst);
@ -161,14 +166,12 @@ private static void realMain(String[] args) throws Throwable {
LauncherAgent.addJVMClassPath(Paths.get(url.toURI())); LauncherAgent.addJVMClassPath(Paths.get(url.toURI()));
} }
ClientService.instrumentation = LauncherAgent.inst; ClientService.instrumentation = LauncherAgent.inst;
ClientService.nativePath = params.nativesDir;
modulesManager.invokeEvent(new ClientProcessClassLoaderEvent(launch, null, profile)); modulesManager.invokeEvent(new ClientProcessClassLoaderEvent(launch, null, profile));
ClientService.baseURLs = classpathURLs.toArray(new URL[0]); ClientService.baseURLs = classpathURLs.toArray(new URL[0]);
} else if (classLoaderConfig == ClientProfile.ClassLoaderConfig.SYSTEM_ARGS) { } else if (classLoaderConfig == ClientProfile.ClassLoaderConfig.SYSTEM_ARGS) {
launch = new BasicLaunch(); launch = new BasicLaunch();
classLoaderControl = launch.init(classpath, params.nativesDir, options); classLoaderControl = launch.init(classpath, params.nativesDir, options);
ClientService.baseURLs = classpathURLs.toArray(new URL[0]); ClientService.baseURLs = classpathURLs.toArray(new URL[0]);
ClientService.nativePath = params.nativesDir;
} }
if(profile.hasFlag(ClientProfile.CompatibilityFlags.CLASS_CONTROL_API)) { if(profile.hasFlag(ClientProfile.CompatibilityFlags.CLASS_CONTROL_API)) {
ClientService.classLoaderControl = classLoaderControl; ClientService.classLoaderControl = classLoaderControl;

View file

@ -184,6 +184,13 @@ public void run(String... args) throws Throwable {
System.arraycopy(args, 1, real_args, 0, args.length - 1); System.arraycopy(args, 1, real_args, 0, args.length - 1);
} else real_args = args; } else real_args = args;
Launch launch; Launch launch;
ClientService.nativePath = config.nativesDir;
ConfigService.serverName = config.serverName;
if(config.loadNatives != null) {
for(String e : config.loadNatives) {
System.load(Paths.get(config.nativesDir).resolve(ClientService.findLibrary(e)).toAbsolutePath().toString());
}
}
switch (config.classLoaderConfig) { switch (config.classLoaderConfig) {
case LAUNCHER: case LAUNCHER:
launch = new LegacyLaunch(); launch = new LegacyLaunch();
@ -210,8 +217,6 @@ public void run(String... args) throws Throwable {
} }
ClientService.classLoaderControl = classLoaderControl; ClientService.classLoaderControl = classLoaderControl;
ClientService.baseURLs = classLoaderControl.getURLs(); ClientService.baseURLs = classLoaderControl.getURLs();
ClientService.nativePath = config.nativesDir;
ConfigService.serverName = config.serverName;
if(config.configServiceSettings != null) { if(config.configServiceSettings != null) {
config.configServiceSettings.apply(); config.configServiceSettings.apply();
} }
@ -277,6 +282,7 @@ public static final class Config {
public String nativesDir = "natives"; public String nativesDir = "natives";
public List<String> args; public List<String> args;
public List<String> compatClasses; public List<String> compatClasses;
public List<String> loadNatives;
public String authId; public String authId;
public AuthRequestEvent.OAuthRequestEvent oauth; public AuthRequestEvent.OAuthRequestEvent oauth;
public long oauthExpireTime; public long oauthExpireTime;