[FEATURE][EXPERIMENTAL] Исправления для поддержки proguard

This commit is contained in:
Gravit 2019-12-09 01:37:18 +07:00
parent e673587d60
commit efc3cd4a09
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
5 changed files with 95 additions and 44 deletions

View file

@ -0,0 +1,90 @@
package pro.gravit.launcher.client;
import pro.gravit.launcher.LauncherAPI;
import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.JVMHelper;
import java.net.URL;
import java.net.URLClassLoader;
public class ClientClassLoader extends URLClassLoader {
public String nativePath;
/**
* Constructs a new URLClassLoader for the specified URLs using the
* default delegation parent {@code ClassLoader}. The URLs will
* be searched in the order specified for classes and resources after
* first searching in the parent class loader. Any URL that ends with
* a '/' is assumed to refer to a directory. Otherwise, the URL is
* assumed to refer to a JAR file which will be downloaded and opened
* as needed.
*
* <p>If there is a security manager, this method first
* calls the security manager's {@code checkCreateClassLoader} method
* to ensure creation of a class loader is allowed.
*
* @param urls the URLs from which to load classes and resources
* @throws SecurityException if a security manager exists and its
* {@code checkCreateClassLoader} method doesn't allow
* creation of a class loader.
* @throws NullPointerException if {@code urls} is {@code null}.
* @see SecurityManager#checkCreateClassLoader
*/
public ClientClassLoader(URL[] urls) {
super(urls);
}
/**
* Constructs a new URLClassLoader for the given URLs. The URLs will be
* searched in the order specified for classes and resources after first
* searching in the specified parent class loader. Any {@code jar:}
* scheme URL is assumed to refer to a JAR file. Any {@code file:} scheme
* URL that ends with a '/' is assumed to refer to a directory. Otherwise,
* the URL is assumed to refer to a JAR file which will be downloaded and
* opened as needed.
*
* <p>If there is a security manager, this method first
* calls the security manager's {@code checkCreateClassLoader} method
* to ensure creation of a class loader is allowed.
*
* @param urls the URLs from which to load classes and resources
* @param parent the parent class loader for delegation
* @throws SecurityException if a security manager exists and its
* {@code checkCreateClassLoader} method doesn't allow
* creation of a class loader.
* @throws NullPointerException if {@code urls} is {@code null}.
* @see SecurityManager#checkCreateClassLoader
*/
public ClientClassLoader(URL[] urls, ClassLoader parent) {
super(urls, parent);
}
@Override
public String findLibrary(String name) {
return nativePath.concat(IOHelper.PLATFORM_SEPARATOR).concat(getNativePrefix()).concat(name).concat(getNativeEx());
}
public String getNativeEx()
{
if(JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE)
return ".dll";
else if(JVMHelper.OS_TYPE == JVMHelper.OS.LINUX)
return ".so";
else if(JVMHelper.OS_TYPE == JVMHelper.OS.MACOSX)
return ".dylib";
return "";
}
public String getNativePrefix()
{
if(JVMHelper.OS_TYPE == JVMHelper.OS.LINUX)
return "lib";
else if(JVMHelper.OS_TYPE == JVMHelper.OS.MACOSX)
return "lib";
return "";
}
@Override
public void addURL(URL url) {
super.addURL(url);
}
}

View file

@ -10,7 +10,6 @@
import pro.gravit.launcher.hasher.FileNameMatcher;
import pro.gravit.launcher.hasher.HashedDir;
import pro.gravit.launcher.hwid.HWIDProvider;
import pro.gravit.launcher.hwid.OshiHWIDProvider;
import pro.gravit.launcher.managers.ClientGsonManager;
import pro.gravit.launcher.managers.ClientHookManager;
import pro.gravit.launcher.modules.events.PreConfigPhase;
@ -163,7 +162,7 @@ public void write(HOutput output) throws IOException {
// Constants
private static final Path NATIVES_DIR = IOHelper.toPath("natives");
private static final Path RESOURCEPACKS_DIR = IOHelper.toPath("resourcepacks");
private static PublicURLClassLoader classLoader;
private static ClientClassLoader classLoader;
public static class ClientUserProperties {
@LauncherAPI
@ -481,10 +480,9 @@ public static void main(String... args) throws Throwable {
}
});
URL[] classpathurls = resolveClassPath(params.clientDir, profile.getClassPath());
classLoader = new PublicURLClassLoader(classpathurls, ClassLoader.getSystemClassLoader());
classLoader = new ClientClassLoader(classpathurls, ClassLoader.getSystemClassLoader());
Thread.currentThread().setContextClassLoader(classLoader);
classLoader.nativePath = params.clientDir.resolve(NATIVES_DIR).toString();
PublicURLClassLoader.systemclassloader = classLoader;
// Start client with WatchService monitoring
boolean digest = !profile.isUpdateFastCheck();
LogHelper.debug("Restore sessions");

View file

@ -7,7 +7,6 @@
import pro.gravit.launcher.request.uuid.BatchProfileByUsernameRequest;
import pro.gravit.launcher.request.uuid.ProfileByUUIDRequest;
import pro.gravit.launcher.request.uuid.ProfileByUsernameRequest;
import pro.gravit.launcher.serialize.SerializeLimits;
import pro.gravit.utils.helper.LogHelper;
import java.util.UUID;
@ -15,7 +14,7 @@
// Used to bypass Launcher's class name obfuscation and access API
@LauncherAPI
public class CompatBridge {
public static final int PROFILES_MAX_BATCH_SIZE = SerializeLimits.MAX_BATCH_SIZE;
public static final int PROFILES_MAX_BATCH_SIZE = 128;
public static CompatProfile checkServer(String username, String serverID) throws Exception {
LogHelper.debug("CompatBridge.checkServer, Username: '%s', Server ID: %s", username, serverID);

View file

@ -6,7 +6,6 @@
import com.mojang.authlib.ProfileLookupCallback;
import pro.gravit.launcher.profiles.PlayerProfile;
import pro.gravit.launcher.request.uuid.BatchProfileByUsernameRequest;
import pro.gravit.launcher.serialize.SerializeLimits;
import pro.gravit.utils.helper.LogHelper;
import pro.gravit.utils.helper.VerifyHelper;
@ -37,8 +36,8 @@ public YggdrasilGameProfileRepository() {
public void findProfilesByNames(String[] usernames, Agent agent, ProfileLookupCallback callback) {
int offset = 0;
while (offset < usernames.length) {
String[] sliceUsernames = Arrays.copyOfRange(usernames, offset, Math.min(offset + SerializeLimits.MAX_BATCH_SIZE, usernames.length));
offset += SerializeLimits.MAX_BATCH_SIZE;
String[] sliceUsernames = Arrays.copyOfRange(usernames, offset, Math.min(offset + 128, usernames.length));
offset += 128;
// Batch Username-To-UUID request
PlayerProfile[] sliceProfiles;

View file

@ -1,21 +1,9 @@
package pro.gravit.utils;
import pro.gravit.launcher.LauncherAPI;
import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.JVMHelper;
import java.net.URL;
import java.net.URLClassLoader;
public class PublicURLClassLoader extends URLClassLoader {
@LauncherAPI
public static ClassLoader systemclassloader = ClassLoader.getSystemClassLoader();
public String nativePath;
@LauncherAPI
public static ClassLoader getSystemClassLoader() {
return systemclassloader;
}
/**
* Constructs a new URLClassLoader for the specified URLs using the
@ -66,29 +54,6 @@ public PublicURLClassLoader(URL[] urls, ClassLoader parent) {
super(urls, parent);
}
@Override
public String findLibrary(String name) {
return nativePath.concat(IOHelper.PLATFORM_SEPARATOR).concat(getNativePrefix()).concat(name).concat(getNativeEx());
}
public String getNativeEx()
{
if(JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE)
return ".dll";
else if(JVMHelper.OS_TYPE == JVMHelper.OS.LINUX)
return ".so";
else if(JVMHelper.OS_TYPE == JVMHelper.OS.MACOSX)
return ".dylib";
return "";
}
public String getNativePrefix()
{
if(JVMHelper.OS_TYPE == JVMHelper.OS.LINUX)
return "lib";
else if(JVMHelper.OS_TYPE == JVMHelper.OS.MACOSX)
return "lib";
return "";
}
@Override
public void addURL(URL url) {
super.addURL(url);