Skip to content

Commit

Permalink
fix: Debugging 1.1 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Pazaz committed Jan 17, 2024
1 parent 3c21655 commit 22479b2
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 61 deletions.
50 changes: 36 additions & 14 deletions client/src/main/java/client.java
Original file line number Diff line number Diff line change
Expand Up @@ -3635,13 +3635,16 @@ private void drawMinimap() {
}

@OriginalMember(owner = "client!client", name = "b", descriptor = "(B)Ljava/awt/Component;")
@Override
protected Component getBaseComponent() {
if (signlink.mainapp == null) {
return this;
} else {
if (signlink.mainapp != null) {
return signlink.mainapp;
}

if (super.frame != null) {
return super.frame;
}

return this;
}

@OriginalMember(owner = "client!client", name = "m", descriptor = "(I)V")
Expand Down Expand Up @@ -3930,10 +3933,10 @@ private void readNpcInfo(@OriginalArg(0) Packet buf, @OriginalArg(1) int size) {
@OriginalMember(owner = "client!client", name = "a", descriptor = "(Ljava/lang/Runnable;I)V")
@Override
public void startThread(@OriginalArg(0) Runnable runnable, @OriginalArg(1) int priority) {
if (signlink.mainapp == null) {
super.startThread(runnable, priority);
} else {
if (signlink.mainapp != null) {
signlink.startthread(runnable, priority);
} else {
super.startThread(runnable, priority);
}
}

Expand Down Expand Up @@ -5979,11 +5982,15 @@ private void useMenuOption(@OriginalArg(1) int optionId) {

@OriginalMember(owner = "client!client", name = "s", descriptor = "(I)Ljava/lang/String;")
private String getHost() {
if (signlink.mainapp == null) {
return super.frame == null ? super.getDocumentBase().getHost().toLowerCase() : "runescape.com";
} else {
if (signlink.mainapp != null) {
return signlink.mainapp.getDocumentBase().getHost().toLowerCase();
}

if (super.frame != null) {
return "2004scape.org";
}

return super.getDocumentBase().getHost().toLowerCase();
}

@OriginalMember(owner = "client!client", name = "t", descriptor = "(I)V")
Expand Down Expand Up @@ -7247,7 +7254,11 @@ private void showContextMenu() {

@OriginalMember(owner = "client!client", name = "a", descriptor = "(Ljava/lang/String;)Ljava/io/DataInputStream;")
private DataInputStream openUrl(@OriginalArg(0) String url) throws IOException {
return signlink.mainapp == null ? new DataInputStream((new URL(this.getCodeBase(), url)).openStream()) : signlink.openurl(url);
if (signlink.mainapp != null) {
return signlink.openurl(url);
}

return new DataInputStream((new URL(this.getCodeBase(), url)).openStream());
}

@OriginalMember(owner = "client!client", name = "j", descriptor = "(B)V")
Expand Down Expand Up @@ -7853,7 +7864,11 @@ protected void unload() {

@OriginalMember(owner = "client!client", name = "A", descriptor = "(I)Ljava/net/Socket;")
private Socket openSocket(@OriginalArg(0) int port) throws IOException {
return signlink.mainapp == null ? new Socket(InetAddress.getByName(this.getCodeBase().getHost()), port) : signlink.opensocket(port);
if (signlink.mainapp != null) {
return signlink.opensocket(port);
}

return new Socket(InetAddress.getByName(this.getCodeBase().getHost()), port);
}

@OriginalMember(owner = "client!client", name = "a", descriptor = "(ZIILclient!z;I)V")
Expand Down Expand Up @@ -9124,7 +9139,11 @@ private void readNpcs(@OriginalArg(1) Packet buf, @OriginalArg(2) int size) {
@OriginalMember(owner = "client!client", name = "getParameter", descriptor = "(Ljava/lang/String;)Ljava/lang/String;")
@Override
public String getParameter(@OriginalArg(0) String name) {
return signlink.mainapp == null ? super.getParameter(name) : signlink.mainapp.getParameter(name);
if (signlink.mainapp != null) {
return signlink.mainapp.getParameter(name);
}

return super.getParameter(name);
}

@OriginalMember(owner = "client!client", name = "l", descriptor = "(Z)V")
Expand Down Expand Up @@ -9522,7 +9541,7 @@ private void drawError() {
g.setColor(Color.white);
g.drawString("Error - unable to load game!", 50, 50);
g.drawString("To play RuneScape make sure you play from", 50, 100);
g.drawString("http://www.runescape.com", 50, 150);
g.drawString("http://2004scape.org", 50, 150);
}

if (this.errorStarted) {
Expand Down Expand Up @@ -11312,14 +11331,17 @@ private boolean isFriend(@OriginalArg(1) String username) {
public void init() {
nodeId = Integer.parseInt(this.getParameter("nodeid"));
portOffset = Integer.parseInt(this.getParameter("portoff"));

@Pc(15) String lowmem = this.getParameter("lowmem");
if (lowmem != null && lowmem.equals("1")) {
setLowMemory();
} else {
setHighMemory();
}

@Pc(31) String free = this.getParameter("free");
members = free == null || !free.equals("1");

this.initApplet(789, 532);
}

Expand Down
29 changes: 19 additions & 10 deletions client/src/main/java/jagex2/client/GameShell.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.net.InetAddress;

import sign.signlink;

@OriginalClass("client!a")
public class GameShell extends Applet implements Runnable, MouseListener, MouseMotionListener, KeyListener, FocusListener, WindowListener {
Expand Down Expand Up @@ -87,7 +90,6 @@ public class GameShell extends Applet implements Runnable, MouseListener, MouseM
protected final void initApplication(@OriginalArg(1) int width, @OriginalArg(0) int height) {
this.screenWidth = width;
this.screenHeight = height;
// this.setPreferredSize(new Dimension(this.screenWidth, this.screenHeight));
this.frame = new ViewBox(this, this.screenWidth, this.screenHeight);
this.graphics = this.getBaseComponent().getGraphics();
this.drawArea = new PixMap(this.getBaseComponent(), this.screenWidth, this.screenHeight);
Expand Down Expand Up @@ -274,9 +276,10 @@ public final void mousePressed(@OriginalArg(0) MouseEvent e) {
@Pc(2) int x = e.getX();
@Pc(5) int y = e.getY();

Insets insets = this.getInsets();
x -= insets.left;
y -= insets.top;
if (this.frame != null) {
x -= this.frame.insets.left;
y -= this.frame.insets.top;
}

this.idleCycles = 0;
this.mouseClickX = x;
Expand Down Expand Up @@ -348,9 +351,10 @@ public final void mouseDragged(@OriginalArg(0) MouseEvent e) {
@Pc(2) int x = e.getX();
@Pc(5) int y = e.getY();

Insets insets = this.getInsets();
x -= insets.left;
y -= insets.top;
if (this.frame != null) {
x -= this.frame.insets.left;
y -= this.frame.insets.top;
}

this.idleCycles = 0;
this.mouseX = x;
Expand All @@ -366,9 +370,10 @@ public final void mouseMoved(@OriginalArg(0) MouseEvent e) {
@Pc(2) int x = e.getX();
@Pc(5) int y = e.getY();

Insets insets = this.getInsets();
x -= insets.left;
y -= insets.top;
if (this.frame != null) {
x -= this.frame.insets.left;
y -= this.frame.insets.top;
}

this.idleCycles = 0;
this.mouseX = x;
Expand Down Expand Up @@ -566,6 +571,10 @@ protected void refresh() {

@OriginalMember(owner = "client!a", name = "b", descriptor = "(B)Ljava/awt/Component;")
protected Component getBaseComponent() {
if (this.frame != null) {
return this.frame;
}

return this;
}

Expand Down
24 changes: 14 additions & 10 deletions client/src/main/java/jagex2/client/ViewBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.openrs2.deob.annotation.OriginalArg;
import org.openrs2.deob.annotation.OriginalClass;
import org.openrs2.deob.annotation.OriginalMember;
import org.openrs2.deob.annotation.Pc;

import java.awt.*;

Expand All @@ -12,22 +13,25 @@ public class ViewBox extends Frame {
@OriginalMember(owner = "client!b", name = "b", descriptor = "Lclient!a;")
private final GameShell shell;

public final Insets insets;

@OriginalMember(owner = "client!b", name = "<init>", descriptor = "(IILclient!a;I)V")
public ViewBox(@OriginalArg(2) GameShell shell, @OriginalArg(3) int width, @OriginalArg(0) int height) {
this.shell = shell;
this.setTitle("Jagex");
this.setResizable(false);

this.setLayout(new BorderLayout());
this.add(shell);
this.pack();

// for compatibility with Java < 1.4
Insets insets = this.getInsets();
this.setSize(width + insets.left + insets.bottom, height + insets.top + insets.bottom);
this.setVisible(true);

this.show();
this.toFront();
this.insets = this.getInsets();
this.resize(width + this.insets.left + this.insets.bottom, height + this.insets.top + this.insets.bottom);
}

@OriginalMember(owner = "client!b", name = "getGraphics", descriptor = "()Ljava/awt/Graphics;")
@Override
public Graphics getGraphics() {
@Pc(2) Graphics g = super.getGraphics();
g.translate(this.insets.left, this.insets.top);
return g;
}

@OriginalMember(owner = "client!b", name = "update", descriptor = "(Ljava/awt/Graphics;)V")
Expand Down
44 changes: 17 additions & 27 deletions client/src/main/java/sign/signlink.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,46 +145,33 @@ public static void startpriv(@OriginalArg(0) InetAddress address) {
@OriginalMember(owner = "client!sign/signlink", name = "findcachedir", descriptor = "()Ljava/lang/String;")
public static String findcachedir() {
@Pc(50) String[] paths = new String[] {
// prioritize home directories
System.getProperty("user.home"),
// System.getenv("HOME"), System.getenv("HOMEDRIVE") + System.getenv("HOMEPATH"), System.getenv("USERPROFILE"),
// System.getenv("user.home"), "~",
// fall back to OS-specific paths
"c:", "c:/windows", "c:/winnt", "d:/windows", "d:/winnt", "e:/windows", "e:/winnt", "f:/windows", "f:/winnt",
// fall back to temporary cache directories (RAM or browser cache)
"/tmp", ""
"c:/windows/", "c:/winnt/", "d:/windows/", "d:/winnt/", "e:/windows/", "e:/winnt/", "f:/windows/", "f:/winnt/", "c:/",
"~/", "/tmp/", ""
};
@Pc(52) String dir = ".lostcity";
@Pc(52) String store = ".file_store_32";

for (@Pc(54) int i = 0; i < paths.length; i++) {
try {
@Pc(59) String path = paths[i];
@Pc(67) File file;
@Pc(59) String dir = paths[i];
@Pc(67) File cache;

if (path == null) {
continue;
}
if (dir.length() > 0) {
cache = new File(dir);

if (path.length() > 0) {
file = new File(path);

if (!file.exists()) {
if (!cache.exists() || !cache.canWrite()) {
System.out.println("Unable to find or write to cache directory: " + dir);
continue;
}
}

file = new File(path + "/" + dir);
if ((!file.exists() && !file.mkdir()) || !file.canWrite()) {
continue;
}

file = new File(path + "/" + dir + "/" + signlink.clientversion);
if ((!file.exists() && !file.mkdir()) || !file.canWrite()) {
cache = new File(dir + store);
if ((!cache.exists() && !cache.mkdir()) || !cache.canWrite()) {
System.out.println("Unable to find or write to cache directory: " + dir + store + "/");
continue;
}

return path + "/" + dir + "/" + signlink.clientversion + "/";
} catch (@Pc(102) Exception ignored) {
return dir + store + "/";
} catch (@Pc(102) Exception _ex) {
}
}

Expand Down Expand Up @@ -398,6 +385,9 @@ public void run() {

@Pc(3) String cacheDir = findcachedir();
uid = getuid(cacheDir);
if (cacheDir == null) {
cacheDir = "";
}

@Pc(8) int threadId = threadliveid;
while (threadliveid == threadId) {
Expand Down
4 changes: 4 additions & 0 deletions loader/src/main/java/loader.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public class loader extends Applet implements Runnable {

public void init() {
try {
Graphics g = getGraphics();
g.setColor(Color.black);
g.fillRect(0, 0, loader.swid, loader.shei);

signlink.mainapp = this;
signlink.startpriv(InetAddress.getByName(getCodeBase().getHost()));

Expand Down

0 comments on commit 22479b2

Please sign in to comment.