runeliteplus: adds full support for private servers into main project, also fixes -local-injected

This commit is contained in:
Zeruth
2019-07-19 22:20:30 -04:00
parent 8743044edd
commit 302c125deb
7 changed files with 333 additions and 36 deletions

View File

@@ -181,6 +181,7 @@ public class RuneLite
parser.accepts("debug", "Show extra debugging output");
parser.accepts("no-splash", "Do not show the splash screen");
parser.accepts("local-injected", "Use local injected-client");
parser.accepts("private-server", "Use a non official server to play");
final ArgumentAcceptingOptionSpec<String> proxyInfo = parser
.accepts("proxy")
@@ -251,6 +252,13 @@ public class RuneLite
}
}
final boolean privateServer = options.has("private-server");
if (privateServer)
{
ClientLoader.usePrivateServer = true;
}
PROFILES_DIR.mkdirs();
if (options.has("debug"))

View File

@@ -26,22 +26,31 @@
*/
package net.runelite.client.rs;
import java.net.URLClassLoader;
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 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;
@Slf4j
@Singleton
public class ClientLoader
{
public static boolean useLocalInjected = false;
public static boolean usePrivateServer = false;
private final ClientConfigLoader clientConfigLoader;
private final ClientUpdateCheckMode updateCheckMode;
public static boolean useLocalInjected = false;
@Inject
private ClientLoader(
@@ -52,6 +61,120 @@ public class ClientLoader
this.clientConfigLoader = clientConfigLoader;
}
private static Applet loadRLPlus(final RSConfig config) throws ClassNotFoundException, InstantiationException, IllegalAccessException
{
if (useLocalInjected)
{
try
{
URL localInjected = new File("./injected-client/target/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()))
{
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);
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
URLClassLoader classLoader = new URLClassLoader(new URL[]{cachedInjectedURL});
Class<?> clientClass = classLoader.loadClass("client");
return loadFromClass(config, clientClass);
}
catch (IOException e)
{
e.printStackTrace();
}
log.error("Failed to load injected-client!");
return null;
}
private static Applet loadVanilla(final RSConfig config) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException
{
final String codebase = config.getCodeBase();
final String initialJar = config.getInitialJar();
final String initialClass = config.getInitialClass();
final URL url = new URL(codebase + initialJar);
// Must set parent classloader to null, or it will pull from
// this class's classloader first
final URLClassLoader classloader = new URLClassLoader(new URL[]{url}, null);
final Class<?> clientClass = classloader.loadClass(initialClass);
return loadFromClass(config, clientClass);
}
private static Applet loadFromClass(final RSConfig config, final Class<?> clientClass) throws IllegalAccessException, InstantiationException
{
final Applet rs = (Applet) clientClass.newInstance();
if (usePrivateServer)
{
rs.setStub(new PrivateRSAppletStub());
return rs;
}
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
@@ -84,32 +207,4 @@ public class ClientLoader
return null;
}
}
private static Applet loadRLPlus(final RSConfig config) throws ClassNotFoundException, InstantiationException, IllegalAccessException
{
// the injected client is a runtime scoped dependency
final Class<?> clientClass = ClientLoader.class.getClassLoader().loadClass(config.getInitialClass());
return loadFromClass(config, clientClass);
}
private static Applet loadVanilla(final RSConfig config) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException
{
final String codebase = config.getCodeBase();
final String initialJar = config.getInitialJar();
final String initialClass = config.getInitialClass();
final URL url = new URL(codebase + initialJar);
// Must set parent classloader to null, or it will pull from
// this class's classloader first
final URLClassLoader classloader = new URLClassLoader(new URL[]{url}, null);
final Class<?> clientClass = classloader.loadClass(initialClass);
return loadFromClass(config, clientClass);
}
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;
}
}

View File

@@ -0,0 +1,115 @@
package net.runelite.client.rs;
import java.applet.AppletContext;
import java.applet.AppletStub;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
public class PrivateRSAppletStub implements AppletStub
{
public static final Logger logger = Logger.getLogger(RSAppletStub.class.getSimpleName());
private static final HashMap<String, String> params = new HashMap<String, String>();
private static final HashMap<String, String> cfg = new HashMap<String, String>();
private static URL codebase;
public PrivateRSAppletStub()
{
try
{
parseParams(new FileInputStream(new File("./params.txt")));
String worldListKey = null;
for (Map.Entry<String, String> paramEntry : params.entrySet())
{
String key = paramEntry.getKey();
String value = paramEntry.getValue();
if (value.contains("slr.ws"))
{
worldListKey = key;
break;
}
}
codebase = new URL("http://runeliteplus-ps.ddns.net"); //host
params.put(worldListKey, "http://" + codebase.getHost());
}
catch (IOException e)
{
e.printStackTrace();
}
}
private static void parseParams(InputStream stream) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(stream));
String line;
while ((line = br.readLine()) != null)
{
int idx = line.indexOf('=');
if (idx != -1)
{
String key = line.substring(0, idx);
String val = line.substring(idx + 1);
if (key.equals("param"))
{
idx = val.indexOf('=');
key = val.substring(0, idx);
val = val.substring(idx + 1);
params.put(key, val);
}
else
{
cfg.put(key, val);
}
}
}
}
public static void log(String format, Object... params)
{
System.out.printf(format + "\n", params);
}
@Override
public boolean isActive()
{
return false;
}
@Override
public URL getDocumentBase()
{
return codebase;
}
@Override
public URL getCodeBase()
{
return codebase;
}
@Override
public String getParameter(String name)
{
return params.get(name);
}
@Override
public AppletContext getAppletContext()
{
return null;
}
@Override
public void appletResize(int width, int height)
{
}
}