[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
private List<String> compatClasses;
@LauncherNetworkAPI
private List<String> loadNatives;
@LauncherNetworkAPI
private Map<String, String> properties;
@LauncherNetworkAPI
private List<ServerProfile> servers;
@ -253,6 +255,10 @@ public ProfileDefaultSettings getSettings() {
return settings;
}
public List<String> getLoadNatives() {
return loadNatives;
}
public void updateOptionalGraph() {
for (OptionalFile file : updateOptional) {
if (file.dependenciesFile != null) {

View file

@ -142,6 +142,12 @@ private static void realMain(String[] args) throws Throwable {
LaunchOptions options = new LaunchOptions();
options.enableHacks = profile.hasFlag(ClientProfile.CompatibilityFlags.ENABLE_HACKS);
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(JVMHelper.JVM_VERSION <= 11) {
launch = new LegacyLaunch();
@ -151,7 +157,6 @@ private static void realMain(String[] args) throws Throwable {
classLoaderControl = launch.init(classpath, params.nativesDir, options);
System.setProperty("java.class.path", classpath.stream().map(Path::toString).collect(Collectors.joining(File.pathSeparator)));
modulesManager.invokeEvent(new ClientProcessClassLoaderEvent(launch, classLoaderControl, profile));
ClientService.nativePath = params.nativesDir;
ClientService.baseURLs = classLoaderControl.getURLs();
} else if (classLoaderConfig == ClientProfile.ClassLoaderConfig.AGENT) {
launch = new BasicLaunch(LauncherAgent.inst);
@ -161,14 +166,12 @@ private static void realMain(String[] args) throws Throwable {
LauncherAgent.addJVMClassPath(Paths.get(url.toURI()));
}
ClientService.instrumentation = LauncherAgent.inst;
ClientService.nativePath = params.nativesDir;
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]);
ClientService.nativePath = params.nativesDir;
}
if(profile.hasFlag(ClientProfile.CompatibilityFlags.CLASS_CONTROL_API)) {
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);
} else real_args = args;
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) {
case LAUNCHER:
launch = new LegacyLaunch();
@ -210,8 +217,6 @@ public void run(String... args) throws Throwable {
}
ClientService.classLoaderControl = classLoaderControl;
ClientService.baseURLs = classLoaderControl.getURLs();
ClientService.nativePath = config.nativesDir;
ConfigService.serverName = config.serverName;
if(config.configServiceSettings != null) {
config.configServiceSettings.apply();
}
@ -277,6 +282,7 @@ public static final class Config {
public String nativesDir = "natives";
public List<String> args;
public List<String> compatClasses;
public List<String> loadNatives;
public String authId;
public AuthRequestEvent.OAuthRequestEvent oauth;
public long oauthExpireTime;