From 590c477098a3c0ce0d1122c290e3b7617667c833 Mon Sep 17 00:00:00 2001 From: Pazaz Date: Tue, 16 Jan 2024 19:08:07 -0500 Subject: [PATCH] fix: Debugging 1.1 compatibility --- client/src/main/java/client.java | 14 ++++-- .../main/java/jagex2/client/GameShell.java | 42 +++++++++++++----- .../src/main/java/jagex2/client/ViewBox.java | 24 +++++----- client/src/main/java/sign/signlink.java | 44 +++++++------------ 4 files changed, 73 insertions(+), 51 deletions(-) diff --git a/client/src/main/java/client.java b/client/src/main/java/client.java index f79b82f4..ed0b00ef 100644 --- a/client/src/main/java/client.java +++ b/client/src/main/java/client.java @@ -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") @@ -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); } diff --git a/client/src/main/java/jagex2/client/GameShell.java b/client/src/main/java/jagex2/client/GameShell.java index 15ccf536..25cce397 100644 --- a/client/src/main/java/jagex2/client/GameShell.java +++ b/client/src/main/java/jagex2/client/GameShell.java @@ -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 { @@ -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); @@ -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(); @@ -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; @@ -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; @@ -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; @@ -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; } diff --git a/client/src/main/java/jagex2/client/ViewBox.java b/client/src/main/java/jagex2/client/ViewBox.java index 74ccf0a5..8e6c4672 100644 --- a/client/src/main/java/jagex2/client/ViewBox.java +++ b/client/src/main/java/jagex2/client/ViewBox.java @@ -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.*; @@ -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 = "", 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") diff --git a/client/src/main/java/sign/signlink.java b/client/src/main/java/sign/signlink.java index 91b8f56d..d29de247 100644 --- a/client/src/main/java/sign/signlink.java +++ b/client/src/main/java/sign/signlink.java @@ -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) { } } @@ -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) {