From 4bbb8e045895a2f19f5c9c3c3db00339a15fa66d Mon Sep 17 00:00:00 2001 From: ceikry Date: Sun, 10 Jul 2022 15:31:18 -0500 Subject: [PATCH] Plumbed in varp update handling --- client/src/main/java/plugin/Plugin.java | 18 +++++ .../main/java/plugin/PluginRepository.java | 4 ++ client/src/main/java/rt4/VarpDomain.java | 5 ++ .../InterfaceDebugPlugin/plugin.properties | 4 +- .../src/main/java/VarpLogPlugin/plugin.java | 70 +++++++++++++++++++ .../main/java/VarpLogPlugin/plugin.properties | 4 ++ 6 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 plugin-playground/src/main/java/VarpLogPlugin/plugin.java create mode 100644 plugin-playground/src/main/java/VarpLogPlugin/plugin.properties diff --git a/client/src/main/java/plugin/Plugin.java b/client/src/main/java/plugin/Plugin.java index 5cbb948..c9fc977 100644 --- a/client/src/main/java/plugin/Plugin.java +++ b/client/src/main/java/plugin/Plugin.java @@ -59,8 +59,26 @@ public abstract class Plugin { */ public void NPCOverheadDraw(Npc npc, int screenX, int screenY) {} + /** + * ProcessCommand is called when a user types and sends a message prefixed with :: + * @param commandStr the command the user used - should include :: in comparisons, eg
commandStr.equals("::command")
+ * @param args any other tokens included with the initial message. Tokens are determined by spaces. + */ public void ProcessCommand(String commandStr, String[] args) {} + /** + * ComponentDraw is called when an interface component is being rendered by the client. + * @param componentIndex the index of the component in its parent interface. + * @param component the component itself + * @param screenX the screen X coordinate of this component + * @param screenY the screen Y coordinate of this component + */ public void ComponentDraw(int componentIndex, Component component, int screenX, int screenY) {} + /** + * OnVarpUpdate is called when varps are updated by the server sending packets. + * @param id the ID of the varp + * @param value the value the varp is being set to. + */ + public void OnVarpUpdate(int id, int value) {} } diff --git a/client/src/main/java/plugin/PluginRepository.java b/client/src/main/java/plugin/PluginRepository.java index b21e2a3..4f2e7d5 100644 --- a/client/src/main/java/plugin/PluginRepository.java +++ b/client/src/main/java/plugin/PluginRepository.java @@ -99,4 +99,8 @@ public class PluginRepository { public static void ComponentDraw(int componentIndex, Component component, int screenX, int screenY) { loadedPlugins.values().forEach((plugin) -> plugin.ComponentDraw(componentIndex, component, screenX, screenY)); } + + public static void OnVarpUpdate(int id, int value) { + loadedPlugins.values().forEach((plugin) -> plugin.OnVarpUpdate(id, value)); + } } diff --git a/client/src/main/java/rt4/VarpDomain.java b/client/src/main/java/rt4/VarpDomain.java index cca6610..5fb00eb 100644 --- a/client/src/main/java/rt4/VarpDomain.java +++ b/client/src/main/java/rt4/VarpDomain.java @@ -3,6 +3,7 @@ package rt4; import org.openrs2.deob.annotation.OriginalArg; import org.openrs2.deob.annotation.OriginalMember; import org.openrs2.deob.annotation.Pc; +import plugin.PluginRepository; public class VarpDomain { @OriginalMember(owner = "client!gj", name = "q", descriptor = "[I") @@ -36,6 +37,10 @@ public class VarpDomain { @OriginalMember(owner = "client!nh", name = "a", descriptor = "(BII)V") public static void set(@OriginalArg(1) int value, @OriginalArg(2) int id) { + PluginRepository.OnVarpUpdate(id, value); + + if (id > varp.length) return; + varp[id] = value; @Pc(20) LongNode local20 = (LongNode) aClass133_20.get(id); if (local20 == null) { diff --git a/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.properties b/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.properties index 31de62c..2a2d1b2 100644 --- a/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.properties +++ b/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.properties @@ -1,4 +1,4 @@ -AUTHOR='Me' -DESCRIPTION='Make sure to rename both the MyPlugin folder and the package statement in plugin.java! +AUTHOR='Ceikry' +DESCRIPTION='Enables visual display of component children and a log of interface-related varps.' VERSION=-1.1 diff --git a/plugin-playground/src/main/java/VarpLogPlugin/plugin.java b/plugin-playground/src/main/java/VarpLogPlugin/plugin.java new file mode 100644 index 0000000..a78ebe7 --- /dev/null +++ b/plugin-playground/src/main/java/VarpLogPlugin/plugin.java @@ -0,0 +1,70 @@ +package VarpLogPlugin; + +import plugin.Plugin; +import plugin.api.*; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; + +public class plugin extends Plugin { + boolean isEnabled; + + int MAX_VISIBLE_UPDATES = 5; + + ArrayList varpUpdates = new ArrayList<>(); + ArrayList updateCreationTime = new ArrayList<>(); + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); + + @Override + public void Init() { + if (API.IsHD()) MAX_VISIBLE_UPDATES = 10; + } + + @Override + public void OnVarpUpdate(int id, int value) { + if (!isEnabled) return; + + if (varpUpdates.size() == MAX_VISIBLE_UPDATES) { + varpUpdates.remove(0); + updateCreationTime.remove(0); + } + varpUpdates.add(id + " = " + value); + String formattedTime = sdf.format(new Date()); + updateCreationTime.add(formattedTime); + System.out.println("[VARP Update]" + formattedTime + " " + id + "->" + value); + } + + @Override + public void Draw(long timeDelta) { + if (!isEnabled) return; + + int startX = 10; + int startY = 30; + + API.DrawText(FontType.SMALL, FontColor.YELLOW, TextModifier.LEFT, "Varp Updates:", startX, startY); + + for (int i = 0; i < varpUpdates.size(); i++){ + String update = varpUpdates.get(i); + String time = updateCreationTime.get(i); + + API.DrawText( + FontType.SMALL, + FontColor.YELLOW, + TextModifier.LEFT, + "[" + time + "] " + update, + startX, + startY + (i + 1) * 15 + ); + } + } + + @Override + public void ProcessCommand(String commandStr, String[] args) { + if (!API.PlayerHasPrivilege(Privileges.JMOD)) return; + + if (commandStr.equalsIgnoreCase("::varplog")) { + isEnabled = !isEnabled; + } + } +} diff --git a/plugin-playground/src/main/java/VarpLogPlugin/plugin.properties b/plugin-playground/src/main/java/VarpLogPlugin/plugin.properties new file mode 100644 index 0000000..97aa366 --- /dev/null +++ b/plugin-playground/src/main/java/VarpLogPlugin/plugin.properties @@ -0,0 +1,4 @@ + +AUTHOR='Ceikry' +DESCRIPTION='Draws some info about varp changes on the screen.' +VERSION=-1.0