From 6f8d0003514bf97995cd86ed892a61d9e7d7c766 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 3 May 2017 18:52:31 -0400 Subject: [PATCH] dev tools: add simple settings tracker --- .../main/java/net/runelite/api/Client.java | 10 ++ .../plugins/devtools/DevToolsPanel.java | 14 +- .../plugins/devtools/SettingsTracker.java | 123 ++++++++++++++++++ 3 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/devtools/SettingsTracker.java diff --git a/runelite-api/src/main/java/net/runelite/api/Client.java b/runelite-api/src/main/java/net/runelite/api/Client.java index 67de0346b1..95c84b78cc 100644 --- a/runelite-api/src/main/java/net/runelite/api/Client.java +++ b/runelite-api/src/main/java/net/runelite/api/Client.java @@ -313,4 +313,14 @@ public class Client { return new XHashTable(client.getComponentTable()); } + + public int[] getSettings() + { + return client.getSettings(); + } + + public int[] getWidgetSettings() + { + return client.getWidgetSettings(); + } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/devtools/DevToolsPanel.java b/runelite-client/src/main/java/net/runelite/client/plugins/devtools/DevToolsPanel.java index b7c681d044..d398c9803c 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/devtools/DevToolsPanel.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/devtools/DevToolsPanel.java @@ -49,6 +49,8 @@ public class DevToolsPanel extends PluginPanel private JButton renderWallsBtn = new JButton(); private JButton renderDecorBtn = new JButton(); private JButton renderInventoryBtn = new JButton(); + private JButton settingsSnapshotBtn = new JButton(); + private JButton settingsClearBtn = new JButton(); private JLabel textLbl = new JLabel(); private JLabel textColorLbl = new JLabel(); @@ -62,6 +64,8 @@ public class DevToolsPanel extends PluginPanel private DefaultMutableTreeNode widgetListRoot = new DefaultMutableTreeNode(); + private final SettingsTracker settingsTracker = new SettingsTracker(client); + public DevToolsPanel(DevTools plugin) { this.plugin = plugin; @@ -79,7 +83,7 @@ public class DevToolsPanel extends PluginPanel private JPanel createOptionsPanel() { JPanel container = new JPanel(); - container.setLayout(new GridLayout(4, 2, 3, 3)); + container.setLayout(new GridLayout(5, 2, 3, 3)); container.setBorder(PADDING_BORDER); renderPlayersBtn = new JButton("Players"); @@ -146,6 +150,14 @@ public class DevToolsPanel extends PluginPanel }); container.add(renderInventoryBtn); + settingsSnapshotBtn = new JButton("Get Settings"); + settingsSnapshotBtn.addActionListener(settingsTracker::snapshot); + container.add(settingsSnapshotBtn); + + settingsClearBtn = new JButton("Clear Settings"); + settingsClearBtn.addActionListener(settingsTracker::clear); + container.add(settingsClearBtn); + return container; } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/devtools/SettingsTracker.java b/runelite-client/src/main/java/net/runelite/client/plugins/devtools/SettingsTracker.java new file mode 100644 index 0000000000..e06ae8b338 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/devtools/SettingsTracker.java @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.plugins.devtools; + +import java.awt.event.ActionEvent; +import java.util.Arrays; +import net.runelite.api.Client; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SettingsTracker +{ + private static final Logger logger = LoggerFactory.getLogger(SettingsTracker.class); + + private final Client client; + + private int[] clientSettings; + private int[] widgetSettings; + + public SettingsTracker(Client client) + { + this.client = client; + } + + public void snapshot(ActionEvent e) + { + if (clientSettings == null || widgetSettings == null) + { + clientSettings = copy(client.getSettings()); + widgetSettings = copy(client.getWidgetSettings()); + + logger.info("Snapshotted client and widget settings"); + return; + } + + int[] newClientSettings = client.getSettings(); + int[] newWidgetSettings = client.getWidgetSettings(); + + for (int i = 0; i < Math.min(clientSettings.length, newClientSettings.length); ++i) + { + int before = clientSettings[i]; + int after = newClientSettings[i]; + + if (before == after) + { + continue; + } + + logger.info("Client setting index {} has changed from {} to {}: {} -> {}", + i, before, after, prettyPrintInt(before), prettyPrintInt(after)); + } + + for (int i = 0; i < Math.min(widgetSettings.length, newWidgetSettings.length); ++i) + { + int before = widgetSettings[i]; + int after = newWidgetSettings[i]; + + if (before == after) + { + continue; + } + + logger.info("Widget setting index {} has changed from {} to {}: {} -> {}", + i, before, after, prettyPrintInt(before), prettyPrintInt(after)); + } + + clientSettings = copy(newClientSettings); + widgetSettings = copy(newWidgetSettings); + } + + public void clear(ActionEvent e) + { + clientSettings = widgetSettings = null; + } + + private static int[] copy(int[] array) + { + return Arrays.copyOf(array, array.length); + } + + private static String prettyPrintInt(int value) + { + String s = Integer.toBinaryString(value); + while (s.length() < 32) + { + s = "0" + s; + } + + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < 32; i += 8) + { + String substr = s.substring(i, i + 8); + if (i > 0) + { + sb.append(' '); + } + sb.append(substr); + } + return sb.toString(); + } +}