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 590c477
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 51 deletions.
14 changes: 10 additions & 4 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 @@ -11312,14 +11315,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
42 changes: 32 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 All @@ -96,6 +98,19 @@ protected final void initApplication(@OriginalArg(1) int width, @OriginalArg(0)

@OriginalMember(owner = "client!a", name = "a", descriptor = "(IZI)V")
protected final void initApplet(@OriginalArg(2) int width, @OriginalArg(0) int height) {
try {
if (signlink.mainapp == null) {
signlink.mainapp = this;
signlink.startpriv(InetAddress.getByName(getCodeBase().getHost()));

String vendor = System.getProperties().getProperty("java.vendor");
if (vendor.toLowerCase().indexOf("sun") != -1 || vendor.toLowerCase().indexOf("apple") != -1) {
signlink.sunjava = true;
}
}
} catch (@Pc(89) Exception _ex) {
}

this.screenWidth = width;
this.screenHeight = height;
this.graphics = this.getBaseComponent().getGraphics();
Expand Down Expand Up @@ -274,9 +289,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 +364,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 +383,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 +584,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

0 comments on commit 590c477

Please sign in to comment.