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:
ThatGamerBlue
2019-07-27 20:02:57 +01:00
committed by Ganom
parent 207c65c325
commit 2ba1c7f80b
14 changed files with 209 additions and 172 deletions

2
.gitignore vendored
View File

@@ -14,7 +14,7 @@ classes/artifacts/client_jar/run.bat
classes/artifacts/client_jar/client.jar classes/artifacts/client_jar/client.jar
*.jar *.jar
.live/ .live/
*/build/ **/build/*
*/out/ */out/
.gradle/ .gradle/
runelite-client/src/main/resources/runelite/* runelite-client/src/main/resources/runelite/*

View File

@@ -1,12 +1,44 @@
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.ajoberstar.grgit:grgit-gradle:3.1.1"
}
}
plugins { plugins {
id "com.github.ben-manes.versions" version "0.21.0" id "com.github.ben-manes.versions" version "0.21.0"
id "com.gradle.build-scan" version "2.3" id "com.gradle.build-scan" version "2.3"
} }
apply plugin: 'application'
ext {
grgit = org.ajoberstar.grgit.Grgit.open(dir: '.')
localGitCommit = grgit.head().id
localGitCommitShort = grgit.head().getAbbreviatedId(7)
localGitDirty = !grgit.status().clean
}
allprojects { allprojects {
apply plugin: 'maven' apply plugin: 'maven'
apply plugin: 'checkstyle' apply plugin: 'checkstyle'
ext {
rsversion = 181
cacheversion = 165
gitCommit = localGitCommit
gitCommitShort = localGitCommitShort
gitDirty = localGitDirty
rootPath = rootDir.toString().replace('\\', '/')
injectedClassesPath = rootPath + "/injector-plugin/out/injected-client/"
}
group = 'net.runelite' group = 'net.runelite'
version = '1.5.30-SNAPSHOT' version = '1.5.30-SNAPSHOT'
@@ -55,3 +87,9 @@ wrapper {
batchScript.write batchScript.text.replace("set $optsEnvVar=\"-Xmx64m\" \"-Xms64m\"", "set $optsEnvVar=\"-Xmx4g\" \"-Xms2g\" \"-Dfile.encoding=UTF-8\"") batchScript.write batchScript.text.replace("set $optsEnvVar=\"-Xmx64m\" \"-Xms64m\"", "set $optsEnvVar=\"-Xmx4g\" \"-Xms2g\" \"-Dfile.encoding=UTF-8\"")
} }
} }
run {
classpath = childProjects.client.sourceSets.main.runtimeClasspath
mainClassName = "net.runelite.client.RuneLite"
args += "--local-injected"
}

5
cache/build.gradle vendored
View File

@@ -22,11 +22,6 @@ dependencies {
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: '1.18.8' annotationProcessor group: 'org.projectlombok', name: 'lombok', version: '1.18.8'
} }
ext {
rsversion = 181
cacheversion = 165
}
test { test {
exclude '**/TitleDumper*' exclude '**/TitleDumper*'
} }

View File

@@ -6,10 +6,9 @@ plugins {
description = 'Deobfuscator' description = 'Deobfuscator'
def osrsRevision = 181
def rootPath = project.rootDir.toString().replace('\\', '/') def rootPath = project.rootDir.toString().replace('\\', '/')
def deobfuscatedJar = "${rootPath}/runescape-client/build/libs/rs-client-${project.version}.jar" def deobfuscatedJar = "${rootPath}/runescape-client/build/libs/rs-client-${project.version}.jar"
def vanillaJar = "${rootPath}/injector-plugin/vanilla-${osrsRevision}.jar" def vanillaJar = "${rootPath}/injector-plugin/vanilla-${rsversion}.jar"
dependencies { dependencies {
implementation project(':runelite-api') implementation project(':runelite-api')
@@ -26,10 +25,6 @@ dependencies {
testImplementation group: 'org.mockito', name: 'mockito-core', version: '3.0.0' testImplementation group: 'org.mockito', name: 'mockito-core', version: '3.0.0'
} }
ext {
rsversion = 181
}
processTestResources { processTestResources {
from file("src/test/resources/deob-test.properties"), { from file("src/test/resources/deob-test.properties"), {
filter(ReplaceTokens, tokens: [ filter(ReplaceTokens, tokens: [

View File

@@ -1,3 +1,4 @@
import org.apache.tools.ant.filters.ReplaceTokens
description = 'Web API' description = 'Web API'
dependencies { dependencies {
implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '4.0.1' implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '4.0.1'
@@ -11,3 +12,14 @@ dependencies {
compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.8' compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.8'
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: '1.18.8' annotationProcessor group: 'org.projectlombok', name: 'lombok', version: '1.18.8'
} }
processResources {
from file("src/main/resources/runelite.properties"), {
filter(ReplaceTokens, tokens: [
"projectver": project.version,
"rsver": rsversion.toString(),
"gitcommit": gitCommitShort,
"gitdirty": gitDirty.toString()
])
}
}

View File

@@ -45,7 +45,6 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.util.Properties; import java.util.Properties;
@@ -53,9 +52,9 @@ import java.util.concurrent.TimeUnit;
public class RuneLiteAPI public class RuneLiteAPI
{ {
public static final String buildCommit = "6fe334c02648d3f8b38625e3175e3f547d54aa37"; private static String version;
private static final String version = "1.5.30-SNAPSHOT"; private static String upstreamVersion;
private static final int rsVersion = 181; private static int rsVersion;
public static final String RUNELITE_AUTH = "RUNELITE-AUTH"; public static final String RUNELITE_AUTH = "RUNELITE-AUTH";
public static final OkHttpClient CLIENT; public static final OkHttpClient CLIENT;
@@ -63,13 +62,12 @@ public class RuneLiteAPI
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
private static final Logger logger = LoggerFactory.getLogger(RuneLiteAPI.class); private static final Logger logger = LoggerFactory.getLogger(RuneLiteAPI.class);
private static final String BASE = "https://api.runelite.net"; private static final String BASE = "https://api.runelite.net";
private static final String PLUS_BASE = "https://api.runelitepl.us"; private static final String RLPLUS_BASE = "https://api.runelitepl.us";
private static final String RLPLUS = "https://session.runelitepl.us"; private static final String RLPLUS_SESSION = "https://session.runelitepl.us";
private static final String WSBASE = "https://api.runelite.net/ws"; private static final String WSBASE = "https://api.runelite.net/ws";
private static final String STATICBASE = "https://static.runelite.net"; private static final String STATICBASE = "https://static.runelite.net";
private static final String MAVEN_METADATA = private static final String MAVEN_METADATA =
"http://repo.runelite.net/net/runelite/runelite-parent/maven-metadata.xml"; "http://repo.runelite.net/net/runelite/runelite-parent/maven-metadata.xml";
private static final String GITHUB_API = "https://api.github.com/repos/runelite/runelite/commits/master";
private static final String ALPHA_NUMERIC_STRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"; private static final String ALPHA_NUMERIC_STRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
private static final Properties properties = new Properties(); private static final Properties properties = new Properties();
private static String userAgent; private static String userAgent;
@@ -83,15 +81,18 @@ public class RuneLiteAPI
properties.load(in); properties.load(in);
parseMavenVersion(); parseMavenVersion();
String commit = buildCommit; rsVersion = Integer.parseInt(properties.getProperty("rs.version"));
String rlpCommit = ""; String commit = randomAlphaNumeric(7);
boolean dirty = false; String rlpCommit = properties.getProperty("runelite.commit");
boolean dirty = Boolean.parseBoolean(properties.getProperty("runelite.dirty"));
version = properties.getProperty("runelite.version");
userAgent = "RuneLite/" + version + "-" + commit + (dirty ? "+" : ""); userAgent = "RuneLite/" + upstreamVersion + "-" + commit + (dirty ? "+" : "");
rlpUserAgent = "RuneLite/" + version + "-" + rlpCommit + (dirty ? "+" : ""); rlpUserAgent = "RuneLitePlus/" + version + "-" + rlpCommit + (dirty ? "+" : "");
} }
catch (NumberFormatException e) catch (NumberFormatException e)
{ {
e.printStackTrace();
throw new RuntimeException("Version string has not been substituted; Re-run maven"); throw new RuntimeException("Version string has not been substituted; Re-run maven");
} }
catch (IOException ex) catch (IOException ex)
@@ -150,7 +151,7 @@ public class RuneLiteAPI
public static HttpUrl getRuneLitePlusSessionBase() public static HttpUrl getRuneLitePlusSessionBase()
{ {
return HttpUrl.parse(RLPLUS); return HttpUrl.parse(RLPLUS_SESSION);
} }
public static HttpUrl getApiBase() public static HttpUrl getApiBase()
@@ -167,7 +168,7 @@ public class RuneLiteAPI
public static HttpUrl getPlusApiBase() public static HttpUrl getPlusApiBase()
{ {
return HttpUrl.parse(PLUS_BASE + "/runelite-" + getRlpVersion()); return HttpUrl.parse(RLPLUS_BASE + "/runelite-" + getRlpVersion());
} }
public static HttpUrl getStaticBase() public static HttpUrl getStaticBase()
@@ -199,11 +200,6 @@ public class RuneLiteAPI
return version; return version;
} }
public static void setVersion(String version)
{
//RuneLiteAPI.version = version;
}
public static int getRsVersion() public static int getRsVersion()
{ {
return rsVersion; return rsVersion;
@@ -256,7 +252,7 @@ public class RuneLiteAPI
Node node = versionList.item(i); Node node = versionList.item(i);
if (node.getTextContent() != null) if (node.getTextContent() != null)
{ {
//version = node.getTextContent(); upstreamVersion = node.getTextContent();
} }
} }
} }
@@ -266,37 +262,6 @@ public class RuneLiteAPI
} }
} }
private static String parseGithubCommit()
{
try
{
byte[] commits = downloadUrl(new URL(GITHUB_API));
if (commits == null)
{
return null;
}
String jsonData = new String(commits);
for (String s : jsonData.split("\n"))
{
if (s.startsWith("\"sha\":"))
{
s = s.replace(",", "");
s = s.replace(" ", "");
s = s.replace("\"", "");
return s.split(":")[1];
}
}
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
return null;
}
private static String randomAlphaNumeric(int count) private static String randomAlphaNumeric(int count)
{ {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();

View File

@@ -1,4 +1,4 @@
runelite.version=${project.version} runelite.version=@projectver@
rs.version=${rs.version} rs.version=@rsver@
runelite.commit=${git.commit.id.abbrev} runelite.commit=@gitcommit@
runelite.dirty=${git.dirty} runelite.dirty=@gitdirty@

View File

@@ -1,5 +1,51 @@
/*
* Copyright (c) 2019 ThatGamerBlue
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
description = 'Injected Client' description = 'Injected Client'
dependencies {
implementation project(':rs-client')
implementation group: 'net.runelite.rs', name: 'vanilla', version: '181'
def injectedClassesPath = "${rootPath}/injector-plugin/out/injected-client/"
compileJava {
dependsOn ':injector-plugin:assemble'
} }
compileJava.outputs.upToDateWhen { false }
compileJava.doLast() {
copy {
File f = file("build/classes/java/main/injected-client")
f.deleteDir()
f.mkdirs()
from ("${injectedClassesPath}")
into ("build/classes/java/main/injected-client")
}
}
classes.doLast() {
File f = file("build/classes/java/main/Placeholder.class")
f.delete()
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright (c) 2019 ThatGamerBlue
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @author ThatGamerBlue
*
* This file exists to force gradle to execute the compileJava task
* so we can hijack it and run the injector-plugin
*/
public class Placeholder
{
}

View File

@@ -1,12 +1,11 @@
group = 'net.runelite.rs' group = 'net.runelite.rs'
description = 'Injector' description = 'Injector'
def osrsRevision = 181 def buildPath = buildDir.toString().replace('\\', '/') // this doesnt work in an ext block for some reason
def rootPath = project.rootDir.toString().replace('\\', '/')
def buildPath = project.buildDir.toString().replace('\\', '/')
def deobfuscatedJar = "${rootPath}/runescape-client/build/libs/rs-client-${project.version}.jar" def deobfuscatedJar = "${rootPath}/runescape-client/build/libs/rs-client-${project.version}.jar"
def vanillaJar = "${buildPath}/vanilla-${osrsRevision}.jar" def vanillaJar = "${buildPath}/vanilla-${rsversion}.jar"
def injectedJar = "${rootPath}/injected-client/build/libs/injected-client-${project.version}.jar"
configurations { configurations {
vanilla vanilla
@@ -17,7 +16,6 @@ dependencies {
implementation project(':mixins') implementation project(':mixins')
implementation project(':runelite-api') implementation project(':runelite-api')
implementation project(':runescape-api') implementation project(':runescape-api')
implementation project(':injected-client')
implementation group: 'com.google.guava', name: 'guava', version: '28.0-jre' implementation group: 'com.google.guava', name: 'guava', version: '28.0-jre'
implementation group: 'org.apache.maven', name: 'maven-plugin-api', version: '3.6.1' implementation group: 'org.apache.maven', name: 'maven-plugin-api', version: '3.6.1'
implementation group: 'org.ow2.asm', name: 'asm-debug-all', version: '5.2' implementation group: 'org.ow2.asm', name: 'asm-debug-all', version: '5.2'
@@ -26,14 +24,14 @@ dependencies {
testImplementation group: 'org.mockito', name: 'mockito-core', version: '3.0.0' testImplementation group: 'org.mockito', name: 'mockito-core', version: '3.0.0'
compileOnly group: 'org.apache.maven.plugin-tools', name: 'maven-plugin-annotations', version: '3.6.0' compileOnly group: 'org.apache.maven.plugin-tools', name: 'maven-plugin-annotations', version: '3.6.0'
annotationProcessor group: 'org.eclipse.sisu', name: 'org.eclipse.sisu.inject', version: '0.3.3' annotationProcessor group: 'org.eclipse.sisu', name: 'org.eclipse.sisu.inject', version: '0.3.3'
vanilla "net.runelite.rs:vanilla:"+osrsRevision vanilla "net.runelite.rs:vanilla:${rsversion}"
} }
compileJava { compileJava {
dependsOn ":rs-client:build" dependsOn ":rs-client:build"
} }
compileJava.outputs.upToDateWhen {false} compileJava.outputs.upToDateWhen { false }
compileJava.doLast() { compileJava.doLast() {
copy { copy {
@@ -46,7 +44,7 @@ compileJava.doLast() {
String[] jarPaths = [ String[] jarPaths = [
deobfuscatedJar.toString(), deobfuscatedJar.toString(),
vanillaJar.toString(), vanillaJar.toString(),
injectedJar.toString() injectedClassesPath.toString()
] ]
inject.main(jarPaths) inject.main(jarPaths)
} }

View File

@@ -26,6 +26,9 @@ package net.runelite.injector;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import com.google.common.io.Files;
import net.runelite.asm.ClassFile;
import net.runelite.asm.ClassGroup; import net.runelite.asm.ClassGroup;
import net.runelite.deob.util.JarUtil; import net.runelite.deob.util.JarUtil;
@@ -69,7 +72,13 @@ public class Injector
private void save(File out) throws IOException private void save(File out) throws IOException
{ {
JarUtil.saveJar(vanilla, out); out.mkdirs();
for (ClassFile cf : vanilla.getClasses())
{
File f = new File(out, cf.getClassName() + ".class");
byte[] data = JarUtil.writeClass(vanilla, cf);
Files.write(data, f);
}
} }

View File

@@ -45,6 +45,7 @@ dependencies {
runtime group: 'org.jogamp.gluegen', name: 'gluegen-rt', version: '2.3.2', classifier: 'natives-linux-amd64' runtime group: 'org.jogamp.gluegen', name: 'gluegen-rt', version: '2.3.2', classifier: 'natives-linux-amd64'
runtime group: 'org.jogamp.gluegen', name: 'gluegen-rt', version: '2.3.2', classifier: 'natives-linux-i586' runtime group: 'org.jogamp.gluegen', name: 'gluegen-rt', version: '2.3.2', classifier: 'natives-linux-i586'
runtime project(':runescape-api') runtime project(':runescape-api')
runtime project(':injected-client')
testImplementation group: 'junit', name: 'junit', version: '4.12' testImplementation group: 'junit', name: 'junit', version: '4.12'
testImplementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.26' testImplementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.26'
testImplementation group: 'org.hamcrest', name: 'hamcrest-library', version: '2.1' testImplementation group: 'org.hamcrest', name: 'hamcrest-library', version: '2.1'
@@ -72,6 +73,8 @@ jar {
shadowJar { shadowJar {
archiveClassifier.set("shaded") archiveClassifier.set("shaded")
exclude("net/runelite/injector/**")
} }
tasks.build.dependsOn tasks.shadowJar tasks.build.dependsOn tasks.shadowJar

View File

@@ -26,29 +26,23 @@
*/ */
package net.runelite.client.rs; package net.runelite.client.rs;
import java.applet.Applet; import com.google.common.io.ByteStreams;
import java.io.BufferedInputStream; import lombok.extern.slf4j.Slf4j;
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.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import lombok.extern.slf4j.Slf4j; import java.applet.Applet;
import net.runelite.client.RuneLite; import java.io.IOException;
import net.runelite.http.api.RuneLiteAPI; import java.io.InputStream;
import java.net.URL;
import java.net.URLClassLoader;
@Slf4j @Slf4j
@Singleton @Singleton
public class ClientLoader public class ClientLoader
{ {
public static boolean useLocalInjected = false; public static boolean useLocalInjected = false;
public static boolean usePrivateServer = false;
private final ClientConfigLoader clientConfigLoader; private final ClientConfigLoader clientConfigLoader;
private final ClientUpdateCheckMode updateCheckMode; private final ClientUpdateCheckMode updateCheckMode;
@@ -61,69 +55,39 @@ public class ClientLoader
this.clientConfigLoader = clientConfigLoader; 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(); String path = "/injected-client/".concat(name.replace('.', '/')).concat(".class");
log.info("Using local injected-client"); InputStream inputStream = ClientLoader.class.getResourceAsStream(path);
URLClassLoader classLoader = new URLClassLoader(new URL[]{localInjected}); if (inputStream == null)
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); throw new ClassNotFoundException(name + " " + path);
byte[] dataBuffer = new byte[1024]; }
int bytesRead; byte[] data;
while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) try
{ {
fileOutputStream.write(dataBuffer, 0, bytesRead); data = ByteStreams.toByteArray(inputStream);
}
} }
catch (IOException e) catch (IOException e)
{ {
e.printStackTrace(); 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"); Class<?> clientClass = rsClassLoader.loadClass("client");
return loadFromClass(config, clientClass); 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 private static Applet loadVanilla(final RSConfig config)
throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException
{ {
final String codebase = config.getCodeBase(); final String codebase = config.getCodeBase();
final String initialJar = config.getInitialJar(); final String initialJar = config.getInitialJar();
@@ -137,39 +101,14 @@ public class ClientLoader
return loadFromClass(config, clientClass); 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(); final Applet rs = (Applet) clientClass.newInstance();
rs.setStub(new RSAppletStub(config)); rs.setStub(new RSAppletStub(config));
return rs; 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() public Applet load()
{ {
try try

View File

@@ -1045,4 +1045,7 @@ public interface RSClient extends RSGameShell, Client
BigInteger getModulus(); BigInteger getModulus();
void setModulus(BigInteger modulus); void setModulus(BigInteger modulus);
@Import("ItemDefinition_fileCount")
int getItemCount();
} }