Merge branch 'added-toggle-resizesd-plugin' into 'master'

Added toggle resizeable SD plugin

See merge request 2009scape/rt4-client!21
This commit is contained in:
Ceikry 2024-09-07 17:28:23 +00:00
commit 8462065bcf
3 changed files with 98 additions and 18 deletions

View file

@ -12,10 +12,7 @@ import java.awt.event.MouseWheelListener;
import java.io.*; import java.io.*;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import java.util.Arrays; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -133,7 +130,8 @@ public class PluginRepository {
} }
public static void Draw() { public static void Draw() {
loadedPlugins.values().forEach(Plugin::_draw); List<Plugin> pluginsSnapshot = new ArrayList<>(loadedPlugins.values());
pluginsSnapshot.forEach(Plugin::_draw);
} }
public static void NPCOverheadDraw(Npc npc, int screenX, int screenY) { public static void NPCOverheadDraw(Npc npc, int screenX, int screenY) {
@ -147,7 +145,8 @@ public class PluginRepository {
public static void ProcessCommand(JagString commandStr) { public static void ProcessCommand(JagString commandStr) {
String[] tokens = commandStr.toString().split(" "); String[] tokens = commandStr.toString().split(" ");
String[] args = Arrays.copyOfRange(tokens, 1, tokens.length); String[] args = Arrays.copyOfRange(tokens, 1, tokens.length);
loadedPlugins.values().forEach((plugin) -> plugin.ProcessCommand(tokens[0], args)); List<Plugin> 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) { public static void ComponentDraw(int componentIndex, Component component, int screenX, int screenY) {
@ -163,7 +162,8 @@ public class PluginRepository {
} }
public static void OnLogout() { public static void OnLogout() {
loadedPlugins.values().forEach(Plugin::OnLogout); List<Plugin> pluginsSnapshot = new ArrayList<>(loadedPlugins.values());
pluginsSnapshot.forEach(Plugin::OnLogout);
} }
public static void DrawMiniMenu(MiniMenuEntry entry) { public static void DrawMiniMenu(MiniMenuEntry entry) {

View file

@ -99,7 +99,6 @@ public class Cheat {
@OriginalMember(owner = "client!jg", name = "e", descriptor = "Z") @OriginalMember(owner = "client!jg", name = "e", descriptor = "Z")
public static boolean qaOpTest = false; public static boolean qaOpTest = false;
public static final JagString RELOADPLUGINS = JagString.parse("::reloadplugins"); 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") @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) { 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; 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)) { if (arg0.equalsIgnoreCase(RELOADPLUGINS)) {
PluginRepository.reloadPlugins(); PluginRepository.reloadPlugins();

View file

@ -0,0 +1,91 @@
package ToggleResizableSD
import plugin.Plugin
import plugin.annotations.PluginMeta
import plugin.api.API
import rt4.*
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
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) {
if (e.keyCode == KeyEvent.VK_F12) {
toggleResize = true
}
}
})
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
}
if (API.GetData("want-hd") == false) {
wantHd = false
}
}
override fun ProcessCommand(commandStr: String, args: Array<out String>?) {
when(commandStr.toLowerCase()) {
"::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"))
}
}
}
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
}
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)
}
}
override fun Draw(timeDelta: Long) {
if (toggleResize) {
toggleResizableSd()
}
}
override fun OnLogout() {
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)
}
}
}