From f3387bc9f9484976d9e97b97cb348c030c8dc6c8 Mon Sep 17 00:00:00 2001 From: TheStonedTurtle <29030969+TheStonedTurtle@users.noreply.github.com> Date: Sat, 16 Mar 2019 21:12:54 -0700 Subject: [PATCH] Add destroy support to Item Charge plugin --- .../plugins/itemcharges/ItemChargePlugin.java | 48 ++++++++++ .../src/main/scripts/DestroyOnOpKey.hash | 1 + .../src/main/scripts/DestroyOnOpKey.rs2asm | 93 +++++++++++++++++++ 3 files changed, 142 insertions(+) create mode 100644 runelite-client/src/main/scripts/DestroyOnOpKey.hash create mode 100644 runelite-client/src/main/scripts/DestroyOnOpKey.rs2asm diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargePlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargePlugin.java index 1ddf3924bc..3a6c44a0fb 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargePlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargePlugin.java @@ -41,6 +41,9 @@ import net.runelite.api.ItemID; import net.runelite.api.events.ChatMessage; import net.runelite.api.events.ConfigChanged; import net.runelite.api.events.ItemContainerChanged; +import net.runelite.api.events.ScriptCallbackEvent; +import net.runelite.api.widgets.Widget; +import net.runelite.api.widgets.WidgetInfo; import net.runelite.client.Notifier; import net.runelite.client.config.ConfigManager; import net.runelite.client.eventbus.Subscribe; @@ -94,6 +97,9 @@ public class ItemChargePlugin extends Plugin @Inject private ItemChargeConfig config; + // Limits destroy callback to once per tick + private int lastCheckTick; + @Provides ItemChargeConfig getConfig(ConfigManager configManager) { @@ -111,6 +117,7 @@ public class ItemChargePlugin extends Plugin { overlayManager.remove(overlay); infoBoxManager.removeIf(ItemChargeInfobox.class::isInstance); + lastCheckTick = -1; } @Subscribe @@ -241,6 +248,21 @@ public class ItemChargePlugin extends Plugin } } + @Subscribe + private void onScriptCallbackEvent(ScriptCallbackEvent event) + { + if (!"destroyOnOpKey".equals(event.getEventName())) + { + return; + } + + final int yesOption = client.getIntStack()[client.getIntStackSize() - 1]; + if (yesOption == 1) + { + checkDestroyWidget(); + } + } + private void updateDodgyNecklaceCharges(final int value) { config.dodgyNecklace(value); @@ -275,6 +297,32 @@ public class ItemChargePlugin extends Plugin } } + private void checkDestroyWidget() + { + final int currentTick = client.getTickCount(); + if (lastCheckTick == currentTick) + { + return; + } + lastCheckTick = currentTick; + + final Widget widgetDestroyItemName = client.getWidget(WidgetInfo.DESTROY_ITEM_NAME); + if (widgetDestroyItemName == null) + { + return; + } + + switch (widgetDestroyItemName.getText()) + { + case "Binding necklace": + updateBindingNecklaceCharges(MAX_BINDING_CHARGES); + break; + case "Dodgy necklace": + updateDodgyNecklaceCharges(MAX_DODGY_CHARGES); + break; + } + } + private void updateJewelleryInfobox(ItemWithSlot item, Item[] items) { for (final EquipmentInventorySlot equipmentInventorySlot : item.getSlots()) diff --git a/runelite-client/src/main/scripts/DestroyOnOpKey.hash b/runelite-client/src/main/scripts/DestroyOnOpKey.hash new file mode 100644 index 0000000000..d52d81ffbb --- /dev/null +++ b/runelite-client/src/main/scripts/DestroyOnOpKey.hash @@ -0,0 +1 @@ +DA7BFF3D4B1135F264904DDCED76BC0CD56CEF4B41E1D7852097E9EECC235B9A \ No newline at end of file diff --git a/runelite-client/src/main/scripts/DestroyOnOpKey.rs2asm b/runelite-client/src/main/scripts/DestroyOnOpKey.rs2asm new file mode 100644 index 0000000000..854c1c8c69 --- /dev/null +++ b/runelite-client/src/main/scripts/DestroyOnOpKey.rs2asm @@ -0,0 +1,93 @@ +.id 1651 +.int_stack_count 5 +.string_stack_count 2 +.int_var_count 5 +.string_var_count 2 + iload 0 + iconst 1 + if_icmpeq LABEL13 + iload 1 + iconst -1 + if_icmpne LABEL7 + jump LABEL74 +LABEL7: + sload 1 + iload 1 + string_indexof_char + iconst -1 + if_icmpne LABEL13 + jump LABEL74 +LABEL13: + iload 0 + iconst 1 + if_icmpne LABEL17 + jump LABEL24 +LABEL17: + iconst 584 + iconst -1 + invoke 1701 + iconst 0 + if_icmpeq LABEL23 + jump LABEL24 +LABEL23: + return +LABEL24: + iload 3 + sconst "destroyOnOpKey" ; load event name + runelite_callback ; invoke callback + pop_int + iconst 2266 + iconst 1 + iconst 0 + sound_synth + iload 2 + iload 4 + cc_find + iconst 1 + if_icmpeq LABEL34 + jump LABEL38 +LABEL34: + iconst 16777215 + cc_setcolour + sconst "..." + cc_settext +LABEL38: + iconst -1 + sconst "" + iload 2 + if_setonmouserepeat + iconst -1 + sconst "" + iload 2 + if_setonmouseleave + iload 2 + if_clearops + iconst -1 + sconst "" + iload 2 + if_setonop + iconst -1 + sconst "" + iload 2 + if_setonkey + iconst 1652 + iload 2 + sload 0 + iload 3 + sload 1 + clientclock + iconst 40 + add + sconst "Isisi" + iload 2 + if_setontimer + iconst 38273024 + iload 3 + cc_find + iconst 1 + if_icmpeq LABEL73 + jump LABEL74 +LABEL73: + cc_resume_pausebutton +LABEL74: + return