Code:
diff -ruN rscd/src/com/method/rscd/CacheDownloader.java rscd_updated/src/com/method/rscd/CacheDownloader.java
--- rscd/src/com/method/rscd/CacheDownloader.java 2021-02-21 15:24:44.271341400 -0600
+++ rscd_updated/src/com/method/rscd/CacheDownloader.java 2021-02-21 15:24:00.225333900 -0600
@@ -23,10 +23,9 @@
*/
public class CacheDownloader {
- private static final int MAJOR_VERSION = 892;
+ private static final int MAJOR_VERSION = 917;
private static final int MINOR_VERSION = 1;
private static final String HOST = "content.runescape.com";
- private static final int WORLD = 2;
private static final int LANGUAGE = 0; // English language by default
private static final int MUSIC_INDEX = 40;
@@ -55,7 +54,6 @@
*/
public CacheDownloader() {
js5Worker = new Js5Worker();
- httpWorker = new HttpWorker(HOST);
}
/**
@@ -76,7 +74,7 @@
* Connects to the server, retrying as needed if the version is incorrect.
*/
private void connect() {
- String key = Crawler.extractParameter(Crawler.downloadPage("http://world" + WORLD + ".runescape.com/g=runescape/,j0"), 32);
+ String key = Crawler.extractParameter(Crawler.downloadPage("http://runescape.com/jav_config.ws?binaryType=2"), 32);
if (key == null) {
System.err.println("Couldn't find valid handshake key.");
System.exit(1);
@@ -86,6 +84,8 @@
js5Worker.process();
}
System.out.println("Successful connection");
+
+ httpWorker = new HttpWorker(HOST, js5Worker.major);
}
/**
diff -ruN rscd/src/com/method/rscd/net/HttpWorker.java rscd_updated/src/com/method/rscd/net/HttpWorker.java
--- rscd/src/com/method/rscd/net/HttpWorker.java 2021-02-21 15:24:44.340341000 -0600
+++ rscd_updated/src/com/method/rscd/net/HttpWorker.java 2020-09-19 18:20:08.279223300 -0500
@@ -11,10 +11,12 @@
public class HttpWorker {
private String host;
+ private int major;
private ExecutorService executor;
- public HttpWorker(String host) {
+ public HttpWorker(String host, int major) {
this.host = host;
+ this.major = major;
this.executor = Executors.newFixedThreadPool(2);
}
@@ -43,7 +45,7 @@
public void run() {
URL url;
try {
- url = new URL("http", host, 80, "/ms?m=0&a=" + request.getIndex() + "&g=" + request.getFile() + "&c=" + crc + "&v=" + version);
+ url = new URL("http", host, 80, "/ms?m=0&k=" + major + "&a=" + request.getIndex() + "&g=" + request.getFile() + "&c=" + crc + "&v=" + version);
} catch (MalformedURLException ex) {
return;
}
diff -ruN rscd/src/com/method/rscd/net/Js5Worker.java rscd_updated/src/com/method/rscd/net/Js5Worker.java
--- rscd/src/com/method/rscd/net/Js5Worker.java 2021-02-21 15:24:44.350342000 -0600
+++ rscd_updated/src/com/method/rscd/net/Js5Worker.java 2020-11-03 15:22:23.403957300 -0600
@@ -16,7 +16,7 @@
*/
public class Js5Worker {
- public static final int LOADING_REQUIREMENTS = 27;
+ public static final int LOADING_REQUIREMENTS = 28;
public static final int BLOCK_SIZE = 102400;
public enum State {
@@ -30,7 +30,7 @@
private OutputStream output;
private State state;
private String host;
- private int major;
+ public int major;
private int minor;
private String key;
private int language;
@@ -46,7 +46,7 @@
requests = new LinkedList<FileRequest>();
waiting = new HashMap<Long, FileRequest>();
state = State.DISCONNECTED;
- outputBuffer = ByteBuffer.allocate(6);
+ outputBuffer = ByteBuffer.allocate(10);
inputBuffer = ByteBuffer.allocate(5);
}
@@ -175,6 +175,7 @@
outputBuffer.put(request.getIndex() == 255 ? (byte) 1 : (byte) 0);
outputBuffer.put((byte) request.getIndex());
outputBuffer.putInt(request.getFile());
+ putFooter(outputBuffer);
output.write(outputBuffer.array());
output.flush();
outputBuffer.clear();
@@ -259,8 +260,9 @@
private void sendConnectionInfo() {
try {
outputBuffer.put((byte) 6);
- putMedInt(outputBuffer, 4);
+ putMedInt(outputBuffer, 5);
outputBuffer.putShort((short) 0);
+ putFooter(outputBuffer);
output.write(outputBuffer.array());
output.flush();
outputBuffer.clear();
@@ -268,6 +270,7 @@
outputBuffer.put((byte) 3);
putMedInt(outputBuffer, 0);
outputBuffer.putShort((short) 0);
+ putFooter(outputBuffer);
output.write(outputBuffer.array());
output.flush();
outputBuffer.clear();
@@ -299,6 +302,16 @@
}
/**
+ * Helper method to put the footer of the js5 packets
+ *
+ * @Param buffer The buffer
+ */
+ private void putFooter(ByteBuffer buffer) {
+ buffer.putShort((short) major);
+ buffer.putShort((short) 0);
+ }
+
+ /**
* Helper method to put a three-byte value into a buffer.
*
* @Param buffer The buffer
diff -ruN rscd/src/com/method/rscd/util/Crawler.java rscd_updated/src/com/method/rscd/util/Crawler.java
--- rscd/src/com/method/rscd/util/Crawler.java 2021-02-21 15:24:44.368341500 -0600
+++ rscd_updated/src/com/method/rscd/util/Crawler.java 2021-02-21 15:23:00.967993100 -0600
@@ -5,12 +5,14 @@
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Crawler {
- public static String downloadPage(String address) {
+ public static List<String> downloadPage(String address) {
URL url;
try {
url = new URL(address);
@@ -21,29 +23,34 @@
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openConnection().getInputStream()));
- StringBuilder page = new StringBuilder();
+ List<String> page = new ArrayList<>();
String line;
while ((line = reader.readLine()) != null) {
- page.append(line);
+ page.add(line);
}
- return page.toString();
+ return page;
} catch (IOException ex) {
ex.printStackTrace();
return null;
}
}
- public static String extractParameter(String input, int length) {
+ public static String extractParameter(List<String> input, int length) {
if (input == null) {
return null;
}
- Pattern p = Pattern.compile("value=\"(\\S{" + length + "})\"");
- Matcher m = p.matcher(input);
- if (m.find()) {
- return m.group(1);
- } else {
- return null;
+
+ Pattern p = Pattern.compile("=\\S{1,2}=(\\S{" + length + "})$");
+ for (String line : input) {
+ if (line.startsWith("param=")) {
+ Matcher m = p.matcher(line);
+ if (m.find()) {
+ return m.group(1);
+ }
+ }
}
+
+ return null;
}
}