From db2a86d75d9fd473abdc2f5767c7b60e0cbacc39 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 23 Apr 2017 16:00:44 -0400 Subject: [PATCH] api: fix finding widget parents and make isHidden check parent --- .../main/java/net/runelite/api/Client.java | 5 ++ .../src/main/java/net/runelite/api/Node.java | 10 +++ .../java/net/runelite/api/WidgetNode.java | 41 +++++++++++++ .../java/net/runelite/api/XHashTable.java | 61 +++++++++++++++++++ .../java/net/runelite/api/widgets/Widget.java | 40 +++++++++++- .../java/net/runelite/rs/api/WidgetNode.java | 2 +- .../java/net/runelite/rs/api/XHashTable.java | 8 ++- 7 files changed, 164 insertions(+), 3 deletions(-) create mode 100644 runelite-api/src/main/java/net/runelite/api/WidgetNode.java create mode 100644 runelite-api/src/main/java/net/runelite/api/XHashTable.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 1e722833b7..5abd245949 100644 --- a/runelite-api/src/main/java/net/runelite/api/Client.java +++ b/runelite-api/src/main/java/net/runelite/api/Client.java @@ -279,4 +279,9 @@ public class Client int value = settings[varbit.getIndex()]; return varbit.get(value); } + + public XHashTable getComponentTable() + { + return new XHashTable(client.getComponentTable()); + } } diff --git a/runelite-api/src/main/java/net/runelite/api/Node.java b/runelite-api/src/main/java/net/runelite/api/Node.java index 9c9986d641..3cc6bad0ae 100644 --- a/runelite-api/src/main/java/net/runelite/api/Node.java +++ b/runelite-api/src/main/java/net/runelite/api/Node.java @@ -49,6 +49,11 @@ public class Node return of(node.getPrevious()); } + public long getHash() + { + return node.getHash(); + } + public static final Node of(net.runelite.rs.api.Node node) { if (node == null) @@ -66,6 +71,11 @@ public class Node return new Renderable((net.runelite.rs.api.Renderable) node); } + if (node instanceof net.runelite.rs.api.WidgetNode) + { + return new WidgetNode((net.runelite.rs.api.WidgetNode) node); + } + return new Node(node); } } diff --git a/runelite-api/src/main/java/net/runelite/api/WidgetNode.java b/runelite-api/src/main/java/net/runelite/api/WidgetNode.java new file mode 100644 index 0000000000..391237599f --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/WidgetNode.java @@ -0,0 +1,41 @@ +/* + * 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.api; + +public class WidgetNode extends Node +{ + private final net.runelite.rs.api.WidgetNode widgetNode; + + public WidgetNode(net.runelite.rs.api.WidgetNode widgetNode) + { + super(widgetNode); + this.widgetNode = widgetNode; + } + + public int getId() + { + return widgetNode.getId(); + } +} diff --git a/runelite-api/src/main/java/net/runelite/api/XHashTable.java b/runelite-api/src/main/java/net/runelite/api/XHashTable.java new file mode 100644 index 0000000000..304224b5f4 --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/XHashTable.java @@ -0,0 +1,61 @@ +/* + * 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.api; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +public class XHashTable +{ + private final net.runelite.rs.api.XHashTable hashtable; + + public XHashTable(net.runelite.rs.api.XHashTable hashtable) + { + this.hashtable = hashtable; + } + + public Collection getNodes() + { + List nodes = new ArrayList<>(); + + net.runelite.rs.api.Node[] buckets = hashtable.getBuckets(); + for (int i = 0; i < buckets.length; ++i) + { + net.runelite.rs.api.Node node = buckets[i]; + + // It looks like the first node in the bucket is always + // a sentinel + net.runelite.rs.api.Node cur = node.getNext(); + while (cur != node) + { + nodes.add(Node.of(cur)); + cur = cur.getNext(); + } + } + + return nodes; + } +} diff --git a/runelite-api/src/main/java/net/runelite/api/widgets/Widget.java b/runelite-api/src/main/java/net/runelite/api/widgets/Widget.java index 929c804da4..9c20f22574 100644 --- a/runelite-api/src/main/java/net/runelite/api/widgets/Widget.java +++ b/runelite-api/src/main/java/net/runelite/api/widgets/Widget.java @@ -29,7 +29,10 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; import net.runelite.api.Client; +import net.runelite.api.Node; import net.runelite.api.Point; +import net.runelite.api.WidgetNode; +import net.runelite.api.XHashTable; public class Widget { @@ -67,6 +70,40 @@ public class Widget return new Widget(client, parent); } + public Widget getParentFromId() + { + int id = getParentId(); + if (id == -1) + { + return null; + } + + return client.getWidget(id >>> 16, id & 0xFFFF); + } + + public int getParentId() + { + int parentId = widget.getParentId(); + if (parentId != -1) + { + return parentId; + } + + int i = getId() >>> 16; + XHashTable componentTable = client.getComponentTable(); + for (Node node : componentTable.getNodes()) + { + WidgetNode wn = (WidgetNode) node; + + if (i == wn.getId()) + { + return (int) wn.getHash(); + } + } + + return -1; + } + private int getRelativeX() { return widget.getRelativeX(); @@ -84,7 +121,8 @@ public class Widget public boolean isHidden() { - return widget.isHidden(); + Widget parent = getParentFromId(); + return (parent != null && parent.isHidden()) || widget.isHidden(); } public Point getCanvasLocation() diff --git a/runescape-api/src/main/java/net/runelite/rs/api/WidgetNode.java b/runescape-api/src/main/java/net/runelite/rs/api/WidgetNode.java index 4cb0c3b7a9..7dd232f406 100644 --- a/runescape-api/src/main/java/net/runelite/rs/api/WidgetNode.java +++ b/runescape-api/src/main/java/net/runelite/rs/api/WidgetNode.java @@ -27,7 +27,7 @@ package net.runelite.rs.api; import net.runelite.mapping.Import; -public interface WidgetNode +public interface WidgetNode extends Node { @Import("id") int getId(); diff --git a/runescape-api/src/main/java/net/runelite/rs/api/XHashTable.java b/runescape-api/src/main/java/net/runelite/rs/api/XHashTable.java index 093af594a4..fedba0108d 100644 --- a/runescape-api/src/main/java/net/runelite/rs/api/XHashTable.java +++ b/runescape-api/src/main/java/net/runelite/rs/api/XHashTable.java @@ -25,7 +25,13 @@ package net.runelite.rs.api; +import net.runelite.mapping.Import; + public interface XHashTable { - //Node get(long var1); + @Import("size") + int getSize(); + + @Import("buckets") + Node[] getBuckets(); }