From 8746c0935496edc28e9bd9aa3a748fda793ac8c0 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 22 Apr 2022 13:12:03 -0400 Subject: [PATCH 1/4] interact highlight: fix detecting spell attacks on npc click This was counting any widget use as an attack, when only spell use should be --- .../plugins/interacthighlight/InteractHighlightPlugin.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/interacthighlight/InteractHighlightPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/interacthighlight/InteractHighlightPlugin.java index f2a5b84e2b..fc9a71a480 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/interacthighlight/InteractHighlightPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/interacthighlight/InteractHighlightPlugin.java @@ -43,9 +43,11 @@ import net.runelite.api.TileObject; import net.runelite.api.WallObject; import net.runelite.api.events.GameStateChanged; import net.runelite.api.events.GameTick; +import net.runelite.api.events.InteractingChanged; import net.runelite.api.events.MenuOptionClicked; import net.runelite.api.events.NpcDespawned; -import net.runelite.api.events.InteractingChanged; +import net.runelite.api.widgets.WidgetID; +import net.runelite.api.widgets.WidgetInfo; import net.runelite.client.config.ConfigManager; import net.runelite.client.eventbus.Subscribe; import net.runelite.client.plugins.Plugin; @@ -168,7 +170,8 @@ public class InteractHighlightPlugin extends Plugin int id = menuOptionClicked.getId(); interactedObject = null; interactedNpc = findNpc(id); - attacked = menuOptionClicked.getMenuAction() == MenuAction.NPC_SECOND_OPTION || menuOptionClicked.getMenuAction() == MenuAction.WIDGET_TARGET_ON_NPC; + attacked = menuOptionClicked.getMenuAction() == MenuAction.NPC_SECOND_OPTION || + menuOptionClicked.getMenuAction() == MenuAction.WIDGET_TARGET_ON_NPC && WidgetInfo.TO_GROUP(client.getSelectedWidget().getId()) == WidgetID.SPELLBOOK_GROUP_ID; clickTick = client.getTickCount(); gameCycle = client.getGameCycle(); break; From 9bd36db0c9f0e42adaab9a3b546adcdc8a72cc0f Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 22 Apr 2022 20:03:19 -0400 Subject: [PATCH 2/4] chat commands: update gotr kill message --- .../client/plugins/chatcommands/ChatCommandsPlugin.java | 2 +- .../client/plugins/chatcommands/ChatCommandsPluginTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java index 5bf8595d08..778289a605 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java @@ -121,7 +121,7 @@ public class ChatCommandsPlugin extends Plugin private static final Pattern HS_KC_FLOOR_PATTERN = Pattern.compile("You have completed Floor (\\d) of the Hallowed Sepulchre! Total completions: ([0-9,]+)\\."); private static final Pattern HS_KC_GHC_PATTERN = Pattern.compile("You have opened the Grand Hallowed Coffin ([0-9,]+) times?!"); private static final Pattern COLLECTION_LOG_ITEM_PATTERN = Pattern.compile("New item added to your collection log: (.*)"); - private static final Pattern GUARDIANS_OF_THE_RIFT_PATTERN = Pattern.compile("Amount of Rifts you have closed: ([0-9,]+)."); + private static final Pattern GUARDIANS_OF_THE_RIFT_PATTERN = Pattern.compile("Amount of Rifts you have closed: ([0-9,]+).", Pattern.CASE_INSENSITIVE); private static final String TOTAL_LEVEL_COMMAND_STRING = "!total"; private static final String PRICE_COMMAND_STRING = "!price"; diff --git a/runelite-client/src/test/java/net/runelite/client/plugins/chatcommands/ChatCommandsPluginTest.java b/runelite-client/src/test/java/net/runelite/client/plugins/chatcommands/ChatCommandsPluginTest.java index e3967b88f2..734d303213 100644 --- a/runelite-client/src/test/java/net/runelite/client/plugins/chatcommands/ChatCommandsPluginTest.java +++ b/runelite-client/src/test/java/net/runelite/client/plugins/chatcommands/ChatCommandsPluginTest.java @@ -1144,9 +1144,9 @@ public class ChatCommandsPluginTest @Test public void testGuardiansOfTheRift() { - ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Amount of Rifts you have closed: 7.", null, 0); + ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Amount of rifts you have closed: 167.", null, 0); chatCommandsPlugin.onChatMessage(chatMessage); - verify(configManager).setRSProfileConfiguration("killcount", "guardians of the rift", 7); + verify(configManager).setRSProfileConfiguration("killcount", "guardians of the rift", 167); } } From e6d83c832224eeee3771b953162266bba8c4f83a Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 22 Apr 2022 21:31:41 -0400 Subject: [PATCH 3/4] examine: fix examining ground items Remove support for examining npcs/objects which has been unused for a long time. All examines I see go through this examine_item script, so we can assume the ITEM_EXAMINE chat message type is used for all examines. --- .../client/plugins/examine/CacheKey.java | 71 ------------------- .../client/plugins/examine/ExaminePlugin.java | 70 +++++------------- .../client/plugins/examine/ExamineType.java | 33 --------- .../plugins/examine/PendingExamine.java | 4 +- 4 files changed, 20 insertions(+), 158 deletions(-) delete mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/examine/CacheKey.java delete mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/examine/ExamineType.java diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/examine/CacheKey.java b/runelite-client/src/main/java/net/runelite/client/plugins/examine/CacheKey.java deleted file mode 100644 index 8cd0340b69..0000000000 --- a/runelite-client/src/main/java/net/runelite/client/plugins/examine/CacheKey.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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.examine; - -import java.util.Objects; - -class CacheKey -{ - private final ExamineType type; - private final int id; - - public CacheKey(ExamineType type, int id) - { - this.type = type; - this.id = id; - } - - @Override - public int hashCode() - { - int hash = 3; - hash = 23 * hash + Objects.hashCode(this.type); - hash = 23 * hash + this.id; - return hash; - } - - @Override - public boolean equals(Object obj) - { - if (this == obj) - { - return true; - } - if (obj == null) - { - return false; - } - if (getClass() != obj.getClass()) - { - return false; - } - final CacheKey other = (CacheKey) obj; - if (this.id != other.id) - { - return false; - } - return this.type == other.type; - } -} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/examine/ExaminePlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/examine/ExaminePlugin.java index 66323a1ca5..f6b7615e47 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/examine/ExaminePlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/examine/ExaminePlugin.java @@ -25,7 +25,6 @@ package net.runelite.client.plugins.examine; import com.google.common.annotations.VisibleForTesting; -import java.time.Instant; import java.util.ArrayDeque; import java.util.Deque; import javax.inject.Inject; @@ -52,7 +51,6 @@ import net.runelite.client.game.ItemManager; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.util.QuantityFormatter; -import net.runelite.client.util.Text; @PluginDescriptor( name = "Examine", @@ -82,18 +80,18 @@ public class ExaminePlugin extends Plugin @Subscribe public void onMenuOptionClicked(MenuOptionClicked event) { - if (!Text.removeTags(event.getMenuOption()).equals("Examine")) + if (!event.getMenuOption().equals("Examine")) { return; } - ExamineType type; + final ChatMessageType type; int id, quantity = -1; switch (event.getMenuAction()) { case EXAMINE_ITEM: { - type = ExamineType.ITEM; + type = ChatMessageType.ITEM_EXAMINE; id = event.getId(); int widgetId = event.getParam1(); @@ -120,12 +118,12 @@ public class ExaminePlugin extends Plugin break; } case EXAMINE_ITEM_GROUND: - type = ExamineType.ITEM; + type = ChatMessageType.ITEM_EXAMINE; id = event.getId(); break; case CC_OP_LOW_PRIORITY: { - type = ExamineType.IF3_ITEM; + type = ChatMessageType.ITEM_EXAMINE; // these are spoofed by us from a [proc,examine_item] script edit int[] qi = findItemFromWidget(event.getParam1(), event.getParam0()); if (qi == null) { @@ -136,77 +134,45 @@ public class ExaminePlugin extends Plugin id = qi[1]; break; } - case EXAMINE_OBJECT: - type = ExamineType.OBJECT; - id = event.getId(); - break; - case EXAMINE_NPC: - type = ExamineType.NPC; - id = event.getId(); - break; default: return; } PendingExamine pendingExamine = new PendingExamine(); - pendingExamine.setType(type); + pendingExamine.setResponseType(type); pendingExamine.setId(id); pendingExamine.setQuantity(quantity); - pendingExamine.setCreated(Instant.now()); pending.push(pendingExamine); } @Subscribe public void onChatMessage(ChatMessage event) { - ExamineType type; - switch (event.getType()) - { - case OBJECT_EXAMINE: - type = ExamineType.OBJECT; - break; - case NPC_EXAMINE: - type = ExamineType.NPC; - break; - case GAMEMESSAGE: - case ITEM_EXAMINE: // these are spoofed by us from a [proc,examine_item] script edit - type = ExamineType.IF3_ITEM; - break; - default: - return; - } - if (pending.isEmpty()) { - log.debug("Got examine without a pending examine?"); return; } - PendingExamine pendingExamine = pending.pop(); - - if (pendingExamine.getType() != type) + PendingExamine pendingExamine = pending.poll(); + if (pendingExamine.getResponseType() != event.getType()) { - log.debug("Type mismatch for pending examine: {} != {}", pendingExamine.getType(), type); + log.debug("Type mismatch for pending examine: {} != {}", pendingExamine.getResponseType(), event.getType()); pending.clear(); // eh return; } - log.debug("Got examine for {} {}: {}", pendingExamine.getType(), pendingExamine.getId(), event.getMessage()); + log.debug("Got examine type {} {}: {}", pendingExamine.getResponseType(), pendingExamine.getId(), event.getMessage()); - // If it is an item, show the price of it - if (pendingExamine.getType() == ExamineType.ITEM || pendingExamine.getType() == ExamineType.IF3_ITEM) + final int itemId = pendingExamine.getId(); + final int itemQuantity = pendingExamine.getQuantity(); + + if (itemId == ItemID.COINS_995) { - final int itemId = pendingExamine.getId(); - final int itemQuantity = pendingExamine.getQuantity(); - - if (itemId == ItemID.COINS_995) - { - return; - } - - final ItemComposition itemComposition = itemManager.getItemComposition(itemId); - getItemPrice(itemComposition.getId(), itemComposition, itemQuantity); + return; } + + final ItemComposition itemComposition = itemManager.getItemComposition(itemId); + getItemPrice(itemComposition.getId(), itemComposition, itemQuantity); } private int[] findItemFromWidget(int widgetId, int childIdx) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/examine/ExamineType.java b/runelite-client/src/main/java/net/runelite/client/plugins/examine/ExamineType.java deleted file mode 100644 index 796d8db764..0000000000 --- a/runelite-client/src/main/java/net/runelite/client/plugins/examine/ExamineType.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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.examine; - -enum ExamineType -{ - ITEM, - IF3_ITEM, - NPC, - OBJECT; -} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/examine/PendingExamine.java b/runelite-client/src/main/java/net/runelite/client/plugins/examine/PendingExamine.java index 96b7389e06..8ae2844499 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/examine/PendingExamine.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/examine/PendingExamine.java @@ -26,12 +26,12 @@ package net.runelite.client.plugins.examine; import java.time.Instant; import lombok.Data; +import net.runelite.api.ChatMessageType; @Data class PendingExamine { - private ExamineType type; + private ChatMessageType responseType; private int id; private int quantity; - private Instant created; } From 1149a5a0e7758b4bfbe8feefb4388bc239079de5 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 22 Apr 2022 21:39:37 -0400 Subject: [PATCH 4/4] examine: remove unused import --- .../java/net/runelite/client/plugins/examine/PendingExamine.java | 1 - 1 file changed, 1 deletion(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/examine/PendingExamine.java b/runelite-client/src/main/java/net/runelite/client/plugins/examine/PendingExamine.java index 8ae2844499..38d327a756 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/examine/PendingExamine.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/examine/PendingExamine.java @@ -24,7 +24,6 @@ */ package net.runelite.client.plugins.examine; -import java.time.Instant; import lombok.Data; import net.runelite.api.ChatMessageType;