Code:
import java.applet.Applet;
import java.applet.AppletContext;
import java.applet.AppletStub;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLConnection;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Main extends JFrame {
URL codebase = null;
private Map<String, String> parameters = new HashMap<String, String>();
private JButton userInput;
public Main() throws Exception {
setTitle("Weequ's runescape loader");
setLayout(new GridLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
setPreferredSize(new Dimension(840, 680));
pack();
Applet applet = prepareApplet();
add(applet);
System.out.println(applet.toString());
pack();
setVisible(true);
Component[] ca = applet.getComponents();
for (Component c : ca) {
System.out.println(c.toString());
}
}
public String getLink() throws Exception{
URL url = new URL("http://www.runescape.com/game.ws?j=1");
System.out.println("Parsing "+url.toString());
URLConnection spoof = url.openConnection();
//Spoof the connection so we look like a web browser
spoof.addRequestProperty("Host", url.getHost());
spoof.addRequestProperty("Connection", "keep-alive");
spoof.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7");
spoof.addRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
spoof.addRequestProperty("Accept-Encoding", "gzip,deflate,sdch");
spoof.addRequestProperty("Accept-Language", "fi-FI,fi;q=0.8,en-US;q=0.6,en;q=0.4");
spoof.addRequestProperty("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.3");
BufferedReader in = new BufferedReader(new InputStreamReader(spoof.getInputStream()));
String strLine = "";
while ((strLine = in.readLine()) != null){
int index = strLine.indexOf("\"game\" src=\"");
if (index == -1) continue;
for (int index2 = index+12; index2 < strLine.length(); index2++) {
if (strLine.charAt(index2) == '"') return strLine.substring(index+12, index2);
}
}
System.out.println("Failed parsin the link from http://www.runescape.com/game.ws?j=1");
return null;
}
public String getArchive(String link) throws Exception {
if (link == null) return null;
System.out.println("Found the link. Parsing "+link);
URL url = new URL(link);
URLConnection spoof = url.openConnection();
spoof.addRequestProperty("Host", url.getHost());
spoof.addRequestProperty("Connection", "keep-alive");
spoof.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7");
spoof.addRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
spoof.addRequestProperty("Referer", "http://www.runescape.com/game.ws?j=1");
spoof.addRequestProperty("Accept-Encoding", "gzip,deflate,sdch");
spoof.addRequestProperty("Accept-Language", "fi-FI,fi;q=0.8,en-US;q=0.6,en;q=0.4");
spoof.addRequestProperty("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.3");
BufferedReader in = new BufferedReader(new InputStreamReader(spoof.getInputStream()));
String result = null;
String strLine = "";
while ((strLine = in.readLine()) != null){
if (result == null) {
int index = strLine.indexOf("archive=");
if (index == -1) continue;
for (int index2 = index+8; index2 < strLine.length(); index2++) {
if (strLine.charAt(index2) == '\'') result = strLine.substring(index+8, index2);
}
} else {
int index = strLine.indexOf("<param name=\"");
if (index == -1) continue;
String key = null;
for (int index2 = index+13; index2 < strLine.length(); index2++) {
if (strLine.charAt(index2) == '"') {
key = strLine.substring(index+13, index2);
break;
}
}
if (key == null) continue;
index = strLine.indexOf("value=\"");
if (index == -1) continue;
String value = null;
for (int index2 = index+7; index2 < strLine.length(); index2++) {
if (strLine.charAt(index2) == '"') {
value = strLine.substring(index+7, index2);
break;
}
}
if (value == null) continue;
parameters.put(key, value);
}
}
System.out.println(result);
if (result == null) System.out.println("Failed to find gamepack from "+link);
return result;
}
public final Applet prepareApplet() throws Exception {
String link = getLink();
String archive = getArchive(link);
URL gamepack = new URL("http://"+new URL(link).getHost()+"/"+archive);
codebase = new URL("http://"+gamepack.getHost());
System.out.println("Loading the client with these parameters:");
System.out.println(parameters.toString());
final Applet applet = (Applet) new URLClassLoader(
new URL[] {gamepack})
.loadClass("Rs2Applet").newInstance();
System.out.println("Client loaded. Setting AppletStub.");
AppletStub stub = new AppletStub() {
@Override
public boolean isActive() {
System.out.println("Applet requested isActive.");
return true;
}
@Override
public URL getDocumentBase() {
System.out.println("Applet requested DocumentBase. Returned "+codebase.toString());
return codebase;
}
@Override
public URL getCodeBase() {
System.out.println("Applet requested CodeBase. Returned "+codebase.toString());
return codebase;
}
@Override
public String getParameter(String name) {
String result = parameters.get(name);
System.out.println("Applet requested parameter name \""+name+"\". Returned "+result);
System.out.println("Applet requested DocumentBase. Returned "+codebase.toString());
return result;
}
@Override
public AppletContext getAppletContext() {
System.out.println("Applet requested AppletContext.");
return null;
}
@Override
public void appletResize(int width, int height) {
System.out.println("Applet requested to set the applet size to ("+width+", "+height+"). Doing so.");
applet.setSize(width, height);
}
};
applet.setStub(stub);
System.out.println("AppletStub set! Initializing applet.");
applet.init();
System.out.println("Applet Initialized! Starting applet.");
applet.start();
System.out.println("Applet Started!");
return applet;
}
public static void main(String[] args) throws Exception{
new Main();
}
}
Ah btw that's for finnish users because of this