gradle: add properties and modify injected-client (#1145)
* add implementation for getItemCount * Ignore build directory in project root * save injector results as class files * package injected-client for shading into client * auto-updating properties * fix run task * shade injected-client into jar
This commit is contained in:
@@ -26,29 +26,23 @@
|
||||
*/
|
||||
package net.runelite.client.rs;
|
||||
|
||||
import java.applet.Applet;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.net.URLConnection;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.client.RuneLite;
|
||||
import net.runelite.http.api.RuneLiteAPI;
|
||||
import java.applet.Applet;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
@Slf4j
|
||||
@Singleton
|
||||
public class ClientLoader
|
||||
{
|
||||
public static boolean useLocalInjected = false;
|
||||
public static boolean usePrivateServer = false;
|
||||
private final ClientConfigLoader clientConfigLoader;
|
||||
private final ClientUpdateCheckMode updateCheckMode;
|
||||
|
||||
@@ -61,69 +55,39 @@ public class ClientLoader
|
||||
this.clientConfigLoader = clientConfigLoader;
|
||||
}
|
||||
|
||||
private static Applet loadRLPlus(final RSConfig config) throws ClassNotFoundException, InstantiationException, IllegalAccessException
|
||||
private static Applet loadRLPlus(final RSConfig config)
|
||||
throws ClassNotFoundException, InstantiationException, IllegalAccessException
|
||||
{
|
||||
if (useLocalInjected)
|
||||
ClassLoader rsClassLoader = new ClassLoader(ClientLoader.class.getClassLoader())
|
||||
{
|
||||
try
|
||||
@Override
|
||||
protected Class<?> findClass(String name) throws ClassNotFoundException
|
||||
{
|
||||
URL localInjected = new File("./injected-client/build/libs/injected-client-" + RuneLiteAPI.getVersion() + ".jar").toURI().toURL();
|
||||
log.info("Using local injected-client");
|
||||
URLClassLoader classLoader = new URLClassLoader(new URL[]{localInjected});
|
||||
Class<?> clientClass = classLoader.loadClass("client");
|
||||
return loadFromClass(config, clientClass);
|
||||
}
|
||||
catch (MalformedURLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
File cachedInjected = new File(RuneLite.RUNELITE_DIR + "/injected-client-" + RuneLiteAPI.getVersion() + ".jar");
|
||||
URL remoteInjected = new URL("https://github.com/runelite-extended/maven-repo/raw/master/live/injected-client-" + RuneLiteAPI.getVersion() + ".jar");
|
||||
int remoteSize = getFileSize(remoteInjected);
|
||||
URL cachedInjectedURL = cachedInjected.toURI().toURL();
|
||||
int cachedSize = 0;
|
||||
if (cachedInjected.exists())
|
||||
{
|
||||
cachedSize = getFileSize(cachedInjectedURL);
|
||||
}
|
||||
|
||||
if (remoteSize != cachedSize)
|
||||
{
|
||||
log.info("Injected-client size mismatch, updating.");
|
||||
try (BufferedInputStream in = new BufferedInputStream(remoteInjected.openStream()))
|
||||
String path = "/injected-client/".concat(name.replace('.', '/')).concat(".class");
|
||||
InputStream inputStream = ClientLoader.class.getResourceAsStream(path);
|
||||
if (inputStream == null)
|
||||
{
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(cachedInjected);
|
||||
byte[] dataBuffer = new byte[1024];
|
||||
int bytesRead;
|
||||
while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1)
|
||||
{
|
||||
fileOutputStream.write(dataBuffer, 0, bytesRead);
|
||||
}
|
||||
throw new ClassNotFoundException(name + " " + path);
|
||||
}
|
||||
byte[] data;
|
||||
try
|
||||
{
|
||||
data = ByteStreams.toByteArray(inputStream);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Failed to load class: " + name + " " + path);
|
||||
}
|
||||
|
||||
return defineClass(name, data, 0, data.length);
|
||||
}
|
||||
URLClassLoader classLoader = new URLClassLoader(new URL[]{cachedInjectedURL}, RuneLite.class.getClassLoader());
|
||||
Class<?> clientClass = classLoader.loadClass("client");
|
||||
return loadFromClass(config, clientClass);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
log.error("Failed to load injected-client!");
|
||||
return null;
|
||||
};
|
||||
Class<?> clientClass = rsClassLoader.loadClass("client");
|
||||
return loadFromClass(config, clientClass);
|
||||
}
|
||||
|
||||
private static Applet loadVanilla(final RSConfig config) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException
|
||||
private static Applet loadVanilla(final RSConfig config)
|
||||
throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException
|
||||
{
|
||||
final String codebase = config.getCodeBase();
|
||||
final String initialJar = config.getInitialJar();
|
||||
@@ -137,39 +101,14 @@ public class ClientLoader
|
||||
return loadFromClass(config, clientClass);
|
||||
}
|
||||
|
||||
private static Applet loadFromClass(final RSConfig config, final Class<?> clientClass) throws IllegalAccessException, InstantiationException
|
||||
private static Applet loadFromClass(final RSConfig config, final Class<?> clientClass)
|
||||
throws IllegalAccessException, InstantiationException
|
||||
{
|
||||
final Applet rs = (Applet) clientClass.newInstance();
|
||||
rs.setStub(new RSAppletStub(config));
|
||||
return rs;
|
||||
}
|
||||
|
||||
private static int getFileSize(URL url)
|
||||
{
|
||||
URLConnection conn = null;
|
||||
try
|
||||
{
|
||||
conn = url.openConnection();
|
||||
if (conn instanceof HttpURLConnection)
|
||||
{
|
||||
((HttpURLConnection) conn).setRequestMethod("HEAD");
|
||||
}
|
||||
conn.getInputStream();
|
||||
return conn.getContentLength();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (conn instanceof HttpURLConnection)
|
||||
{
|
||||
((HttpURLConnection) conn).disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Applet load()
|
||||
{
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user