From 47df7bd3d3e779588e144706df9d142ea98a5715 Mon Sep 17 00:00:00 2001 From: ipkpjersi Date: Mon, 17 Jun 2024 20:46:48 -0400 Subject: [PATCH 1/9] Added toggle resizeable SD plugin This also fixes two CMEs, very cool. --- .../main/java/plugin/PluginRepository.java | 12 ++--- client/src/main/java/rt4/Cheat.java | 11 ---- .../main/kotlin/ToggleResizableSD/plugin.kt | 53 +++++++++++++++++++ 3 files changed, 59 insertions(+), 17 deletions(-) create mode 100644 plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt diff --git a/client/src/main/java/plugin/PluginRepository.java b/client/src/main/java/plugin/PluginRepository.java index b04c2ea..88775c6 100644 --- a/client/src/main/java/plugin/PluginRepository.java +++ b/client/src/main/java/plugin/PluginRepository.java @@ -12,10 +12,7 @@ import java.awt.event.MouseWheelListener; import java.io.*; import java.net.URL; import java.net.URLClassLoader; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Objects; +import java.util.*; import java.util.stream.Collectors; /** @@ -133,7 +130,8 @@ public class PluginRepository { } public static void Draw() { - loadedPlugins.values().forEach(Plugin::_draw); + List pluginsSnapshot = new ArrayList<>(loadedPlugins.values()); + pluginsSnapshot.forEach(Plugin::_draw); } public static void NPCOverheadDraw(Npc npc, int screenX, int screenY) { @@ -147,7 +145,9 @@ public class PluginRepository { public static void ProcessCommand(JagString commandStr) { String[] tokens = commandStr.toString().split(" "); String[] args = Arrays.copyOfRange(tokens, 1, tokens.length); - loadedPlugins.values().forEach((plugin) -> plugin.ProcessCommand(tokens[0], args)); + List pluginsSnapshot = new ArrayList<>(loadedPlugins.values()); + + pluginsSnapshot.forEach((plugin) -> plugin.ProcessCommand(tokens[0], args)); } public static void ComponentDraw(int componentIndex, Component component, int screenX, int screenY) { diff --git a/client/src/main/java/rt4/Cheat.java b/client/src/main/java/rt4/Cheat.java index 23f5d9d..97affb5 100644 --- a/client/src/main/java/rt4/Cheat.java +++ b/client/src/main/java/rt4/Cheat.java @@ -99,7 +99,6 @@ public class Cheat { @OriginalMember(owner = "client!jg", name = "e", descriptor = "Z") public static boolean qaOpTest = false; public static final JagString RELOADPLUGINS = JagString.parse("::reloadplugins"); - public static final JagString USERESIZABLESD = JagString.parse("::resizablesd"); @OriginalMember(owner = "client!en", name = "a", descriptor = "(IIIB)V") public static void teleport(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1, @OriginalArg(2) int arg2) { @@ -232,16 +231,6 @@ public class Cheat { shiftClick = true; } } - if(arg0.equalsIgnoreCase(USERESIZABLESD)){ - DisplayMode.resizableSD = !DisplayMode.resizableSD; - if(!DisplayMode.resizableSD){ - // Revert to fixed - DisplayMode.setWindowMode(true, 0, -1, -1); - } else { - // use resizable - DisplayMode.setWindowMode(true, 0, GameShell.frameWidth, GameShell.frameHeight); - } - } if (arg0.equalsIgnoreCase(RELOADPLUGINS)) { PluginRepository.reloadPlugins(); diff --git a/plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt b/plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt new file mode 100644 index 0000000..11048d7 --- /dev/null +++ b/plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt @@ -0,0 +1,53 @@ +package ToggleResizableSD + +import plugin.Plugin +import plugin.annotations.PluginMeta +import plugin.api.API +import rt4.DisplayMode +import rt4.GameShell +import java.awt.event.KeyAdapter +import java.awt.event.KeyEvent + +@PluginMeta ( + author = "ipkpjersi", + description = "Allows you to use F12 to toggle resizable SD.", + version = 1.0 +) +class plugin : Plugin() { + var toggleResize = false + override fun Init() { + API.AddKeyboardListener(object : KeyAdapter() { + override fun keyPressed(e: KeyEvent) { + if (e.keyCode == KeyEvent.VK_F12) { + toggleResize = true + } + } + }) + } + + override fun ProcessCommand(commandStr: String, args: Array?) { + when(commandStr.toLowerCase()) { + "::resizablesd" -> { + toggleResize = true //We could call toggleResizableSd() directly here, but it's not necessary. + } + } + } + + fun toggleResizableSd() { + DisplayMode.resizableSD = !DisplayMode.resizableSD; + if(!DisplayMode.resizableSD){ + //Revert to fixed + DisplayMode.setWindowMode(true, 0, -1, -1) + } else { + //Use resizable + DisplayMode.setWindowMode(true, 0, GameShell.frameWidth, GameShell.frameHeight) + } + } + + override fun Draw(timeDelta: Long) { + if (toggleResize) { + toggleResizableSd() + toggleResize = false + } + } +} \ No newline at end of file From e0dac2e9f3a1c92572b402ac02b48711478e3d20 Mon Sep 17 00:00:00 2001 From: ipkpjersi Date: Mon, 17 Jun 2024 20:57:01 -0400 Subject: [PATCH 2/9] Fixed formatting --- client/src/main/java/plugin/PluginRepository.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/client/src/main/java/plugin/PluginRepository.java b/client/src/main/java/plugin/PluginRepository.java index 88775c6..613c8cb 100644 --- a/client/src/main/java/plugin/PluginRepository.java +++ b/client/src/main/java/plugin/PluginRepository.java @@ -130,7 +130,7 @@ public class PluginRepository { } public static void Draw() { - List pluginsSnapshot = new ArrayList<>(loadedPlugins.values()); + List pluginsSnapshot = new ArrayList<>(loadedPlugins.values()); pluginsSnapshot.forEach(Plugin::_draw); } @@ -146,7 +146,6 @@ public class PluginRepository { String[] tokens = commandStr.toString().split(" "); String[] args = Arrays.copyOfRange(tokens, 1, tokens.length); List pluginsSnapshot = new ArrayList<>(loadedPlugins.values()); - pluginsSnapshot.forEach((plugin) -> plugin.ProcessCommand(tokens[0], args)); } From 56319db91252089267599b0b993ac6fdcddb93f1 Mon Sep 17 00:00:00 2001 From: ipkpjersi Date: Mon, 17 Jun 2024 21:53:01 -0400 Subject: [PATCH 3/9] Added loading resizable SD on startup --- .../src/main/kotlin/ToggleResizableSD/plugin.kt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt b/plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt index 11048d7..b5c24c1 100644 --- a/plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt +++ b/plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt @@ -5,6 +5,8 @@ import plugin.annotations.PluginMeta import plugin.api.API import rt4.DisplayMode import rt4.GameShell +import rt4.InterfaceList +import rt4.client import java.awt.event.KeyAdapter import java.awt.event.KeyEvent @@ -23,6 +25,9 @@ class plugin : Plugin() { } } }) + if (!DisplayMode.resizableSD && API.GetData("use-resizable-sd") == true) { + toggleResize = true + } } override fun ProcessCommand(commandStr: String, args: Array?) { @@ -34,12 +39,20 @@ class plugin : Plugin() { } fun toggleResizableSd() { + if (InterfaceList.aClass13_26 == null || client.gameState != 30) { + println("Cannot toggle resize, InterfaceList.aClass13_26 is null") + return + } + println("getWindowMode() is " + DisplayMode.getWindowMode()); + toggleResize = false DisplayMode.resizableSD = !DisplayMode.resizableSD; if(!DisplayMode.resizableSD){ //Revert to fixed + API.StoreData("use-resizable-sd", false) //Note: It is important to call StoreData before setWindowMode because setWindowMode causes all plugins to reload. DisplayMode.setWindowMode(true, 0, -1, -1) } else { //Use resizable + API.StoreData("use-resizable-sd", true) //Note: It is important to call StoreData before setWindowMode because setWindowMode causes all plugins to reload. DisplayMode.setWindowMode(true, 0, GameShell.frameWidth, GameShell.frameHeight) } } @@ -47,7 +60,6 @@ class plugin : Plugin() { override fun Draw(timeDelta: Long) { if (toggleResize) { toggleResizableSd() - toggleResize = false } } } \ No newline at end of file From 824f85c7b3ae89722c14734c901e07a1d052ccd3 Mon Sep 17 00:00:00 2001 From: ipkpjersi Date: Mon, 17 Jun 2024 21:53:14 -0400 Subject: [PATCH 4/9] Removed print statements --- plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt b/plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt index b5c24c1..fdd0368 100644 --- a/plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt +++ b/plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt @@ -40,10 +40,8 @@ class plugin : Plugin() { fun toggleResizableSd() { if (InterfaceList.aClass13_26 == null || client.gameState != 30) { - println("Cannot toggle resize, InterfaceList.aClass13_26 is null") return } - println("getWindowMode() is " + DisplayMode.getWindowMode()); toggleResize = false DisplayMode.resizableSD = !DisplayMode.resizableSD; if(!DisplayMode.resizableSD){ From 7aab2d1735ebe334e5540f552a3c8ab682b4a167 Mon Sep 17 00:00:00 2001 From: ipkpjersi Date: Mon, 17 Jun 2024 22:27:56 -0400 Subject: [PATCH 5/9] Fixed HD flyover when logging out with resizable SD enabled --- client/src/main/java/plugin/PluginRepository.java | 3 ++- .../src/main/kotlin/ToggleResizableSD/plugin.kt | 13 +++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/client/src/main/java/plugin/PluginRepository.java b/client/src/main/java/plugin/PluginRepository.java index 613c8cb..748a474 100644 --- a/client/src/main/java/plugin/PluginRepository.java +++ b/client/src/main/java/plugin/PluginRepository.java @@ -162,7 +162,8 @@ public class PluginRepository { } public static void OnLogout() { - loadedPlugins.values().forEach(Plugin::OnLogout); + List pluginsSnapshot = new ArrayList<>(loadedPlugins.values()); + pluginsSnapshot.forEach(Plugin::OnLogout); } public static void DrawMiniMenu(MiniMenuEntry entry) { diff --git a/plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt b/plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt index fdd0368..b77e12c 100644 --- a/plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt +++ b/plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt @@ -3,10 +3,7 @@ package ToggleResizableSD import plugin.Plugin import plugin.annotations.PluginMeta import plugin.api.API -import rt4.DisplayMode -import rt4.GameShell -import rt4.InterfaceList -import rt4.client +import rt4.* import java.awt.event.KeyAdapter import java.awt.event.KeyEvent @@ -60,4 +57,12 @@ class plugin : Plugin() { toggleResizableSd() } } + + override fun OnLogout() { + if (DisplayMode.resizableSD) { + DisplayMode.resizableSD = false + //Because resizable SD always uses the "HD" size canvas/window mode (check the in-game Graphics Options with resizeable SD enabled if you don't believe me!), useHD becomes true when logging out, so logging out with resizeSD enabled means "HD" will always be enabled on the login screen after logging out, so we might as well fix the HD flyover by replacing the canvas and setting newMode to 2. + DisplayMode.setWindowMode(true, 2, GameShell.frameWidth, GameShell.frameHeight) + } + } } \ No newline at end of file From 17298c61a27b13e46336da17c957ffb47973df8e Mon Sep 17 00:00:00 2001 From: ipkpjersi Date: Mon, 17 Jun 2024 22:53:49 -0400 Subject: [PATCH 6/9] Improved resizable SD logging out comment --- plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt b/plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt index b77e12c..aeb0e56 100644 --- a/plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt +++ b/plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt @@ -60,8 +60,8 @@ class plugin : Plugin() { override fun OnLogout() { if (DisplayMode.resizableSD) { + //Because resizable SD always uses the "HD" size canvas/window mode (check the in-game Graphics Options with resizeable SD enabled if you don't believe me!), useHD becomes true when logging out, so logging out with resizeSD enabled means "HD" will always be enabled on the login screen after logging out, so we might as well fix the HD flyover by setting resizableSD to false first, and calling setWindowMode to replace the canvas and set newMode to 2. DisplayMode.resizableSD = false - //Because resizable SD always uses the "HD" size canvas/window mode (check the in-game Graphics Options with resizeable SD enabled if you don't believe me!), useHD becomes true when logging out, so logging out with resizeSD enabled means "HD" will always be enabled on the login screen after logging out, so we might as well fix the HD flyover by replacing the canvas and setting newMode to 2. DisplayMode.setWindowMode(true, 2, GameShell.frameWidth, GameShell.frameHeight) } } From 853b60e8711a2ff7e30b339d8cf952ee52fb86b7 Mon Sep 17 00:00:00 2001 From: ipkpjersi Date: Mon, 17 Jun 2024 22:55:46 -0400 Subject: [PATCH 7/9] Updated comment about resize SD logging out --- plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt b/plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt index aeb0e56..ecf53e7 100644 --- a/plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt +++ b/plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt @@ -60,7 +60,7 @@ class plugin : Plugin() { override fun OnLogout() { if (DisplayMode.resizableSD) { - //Because resizable SD always uses the "HD" size canvas/window mode (check the in-game Graphics Options with resizeable SD enabled if you don't believe me!), useHD becomes true when logging out, so logging out with resizeSD enabled means "HD" will always be enabled on the login screen after logging out, so we might as well fix the HD flyover by setting resizableSD to false first, and calling setWindowMode to replace the canvas and set newMode to 2. + //Because resizable SD always uses the "HD" size canvas/window mode (check the in-game Graphics Options with resizeable SD enabled if you don't believe me!), useHD becomes true when logging out, so logging out with resizeSD enabled means "HD" will always be enabled on the login screen after logging out, so we might as well fix the HD flyover by setting resizableSD to false first, and then calling setWindowMode to replace the canvas and set newMode to 2. DisplayMode.resizableSD = false DisplayMode.setWindowMode(true, 2, GameShell.frameWidth, GameShell.frameHeight) } From 8b1c75afec096111d79fe2b09a91c187f676b0a4 Mon Sep 17 00:00:00 2001 From: ipkpjersi Date: Tue, 18 Jun 2024 00:09:48 -0400 Subject: [PATCH 8/9] Added Mac check for resize SD logout using HD --- .../main/kotlin/ToggleResizableSD/plugin.kt | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt b/plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt index ecf53e7..c60c8cb 100644 --- a/plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt +++ b/plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt @@ -14,6 +14,7 @@ import java.awt.event.KeyEvent ) class plugin : Plugin() { var toggleResize = false + var wantHd = false //Setting wantHd to true hides the black screen on logout (when resize SD is enabled), by enabling HD on logout override fun Init() { API.AddKeyboardListener(object : KeyAdapter() { override fun keyPressed(e: KeyEvent) { @@ -25,6 +26,21 @@ class plugin : Plugin() { if (!DisplayMode.resizableSD && API.GetData("use-resizable-sd") == true) { toggleResize = true } + var osNameLowerCase: String = "" + var osName: String + + try { + osName = System.getProperty("os.name") + } catch (e: Exception) { + osName = "Unknown" + } + + osNameLowerCase = osName.toLowerCase() + if (!osNameLowerCase.startsWith("mac")) { + wantHd = true + } + //Alternatively, we could just force HD off here, if we want: + //wantHd = false } override fun ProcessCommand(commandStr: String, args: Array?) { @@ -36,6 +52,7 @@ class plugin : Plugin() { } fun toggleResizableSd() { + //We only want to toggle resizable SD when we are logged in and the lobby/welcome interface is not open. if (InterfaceList.aClass13_26 == null || client.gameState != 30) { return } @@ -59,7 +76,7 @@ class plugin : Plugin() { } override fun OnLogout() { - if (DisplayMode.resizableSD) { + if (DisplayMode.resizableSD && wantHd) { //Because resizable SD always uses the "HD" size canvas/window mode (check the in-game Graphics Options with resizeable SD enabled if you don't believe me!), useHD becomes true when logging out, so logging out with resizeSD enabled means "HD" will always be enabled on the login screen after logging out, so we might as well fix the HD flyover by setting resizableSD to false first, and then calling setWindowMode to replace the canvas and set newMode to 2. DisplayMode.resizableSD = false DisplayMode.setWindowMode(true, 2, GameShell.frameWidth, GameShell.frameHeight) From ba70c3f36c79b71f8fdc14339324c9245d406ab8 Mon Sep 17 00:00:00 2001 From: ipkpjersi Date: Tue, 18 Jun 2024 09:47:12 -0400 Subject: [PATCH 9/9] Added want HD toggle for resizable SD logout --- .../src/main/kotlin/ToggleResizableSD/plugin.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt b/plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt index c60c8cb..34f9479 100644 --- a/plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt +++ b/plugin-playground/src/main/kotlin/ToggleResizableSD/plugin.kt @@ -39,15 +39,21 @@ class plugin : Plugin() { if (!osNameLowerCase.startsWith("mac")) { wantHd = true } - //Alternatively, we could just force HD off here, if we want: - //wantHd = false + if (API.GetData("want-hd") == false) { + wantHd = false + } } override fun ProcessCommand(commandStr: String, args: Array?) { when(commandStr.toLowerCase()) { - "::resizablesd" -> { + "::toggleresizablesd", "::resizablesd", "::togglersd", "::rsd" -> { toggleResize = true //We could call toggleResizableSd() directly here, but it's not necessary. } + "::toggleresizablesdhd", "::resizablesdhd", "::togglersdhd", "::rsdhd", -> { + wantHd = !wantHd + API.StoreData("want-hd", wantHd) + API.SendMessage("You have turned login screen HD " + (if (wantHd) "on" else "off")) + } } }