From 6e8f8adc9510bbd37371a3b32e922e5c19043c76 Mon Sep 17 00:00:00 2001 From: Toocanzs Date: Sat, 18 Nov 2017 17:12:15 -0500 Subject: [PATCH 1/2] Add game tick event --- .../java/net/runelite/api/PacketBuffer.java | 29 ++++++++++++++++ .../net/runelite/client/callback/Hooks.java | 7 ++++ .../net/runelite/client/events/GameTick.java | 34 +++++++++++++++++++ .../net/runelite/rs/api/RSPacketBuffer.java | 31 +++++++++++++++++ 4 files changed, 101 insertions(+) create mode 100644 runelite-api/src/main/java/net/runelite/api/PacketBuffer.java create mode 100644 runelite-client/src/main/java/net/runelite/client/events/GameTick.java create mode 100644 runescape-api/src/main/java/net/runelite/rs/api/RSPacketBuffer.java diff --git a/runelite-api/src/main/java/net/runelite/api/PacketBuffer.java b/runelite-api/src/main/java/net/runelite/api/PacketBuffer.java new file mode 100644 index 0000000000..a44f4c9ac9 --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/PacketBuffer.java @@ -0,0 +1,29 @@ +/* + * 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 interface PacketBuffer +{ +} diff --git a/runelite-client/src/main/java/net/runelite/client/callback/Hooks.java b/runelite-client/src/main/java/net/runelite/client/callback/Hooks.java index 325c9ced50..e3d0606ee4 100644 --- a/runelite-client/src/main/java/net/runelite/client/callback/Hooks.java +++ b/runelite-client/src/main/java/net/runelite/client/callback/Hooks.java @@ -33,6 +33,7 @@ import net.runelite.api.Client; import net.runelite.api.MainBufferProvider; import net.runelite.api.MenuAction; import net.runelite.api.MessageNode; +import net.runelite.api.PacketBuffer; import net.runelite.api.Skill; import net.runelite.client.RuneLite; import net.runelite.client.events.*; @@ -55,6 +56,7 @@ public class Hooks private static final Scheduler scheduler = injector.getInstance(Scheduler.class); private static final InfoBoxManager infoBoxManager = injector.getInstance(InfoBoxManager.class); private static final DeathChecker death = new DeathChecker(client, eventBus); + private static final GameTick tick = new GameTick(); private static long lastCheck; @@ -176,6 +178,11 @@ public class Hooks } } + public static void onPlayerUpdatePacketHandler(PacketBuffer var0, int var1) + { + eventBus.post(tick); + } + public static void menuActionHook(int var0, int widgetId, int menuAction, int id, String menuOption, String menuTarget, int var6, int var7) { /* Along the way, the RuneScape client may change a menuAction by incrementing it with 2000. diff --git a/runelite-client/src/main/java/net/runelite/client/events/GameTick.java b/runelite-client/src/main/java/net/runelite/client/events/GameTick.java new file mode 100644 index 0000000000..02fb3f01d2 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/events/GameTick.java @@ -0,0 +1,34 @@ +/* + * 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.events; + +/** + * Event called once per tick. + * + * @author Adam + */ +public class GameTick +{ +} diff --git a/runescape-api/src/main/java/net/runelite/rs/api/RSPacketBuffer.java b/runescape-api/src/main/java/net/runelite/rs/api/RSPacketBuffer.java new file mode 100644 index 0000000000..2a79d8983b --- /dev/null +++ b/runescape-api/src/main/java/net/runelite/rs/api/RSPacketBuffer.java @@ -0,0 +1,31 @@ +/* + * 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.rs.api; + +import net.runelite.api.PacketBuffer; + +public interface RSPacketBuffer extends PacketBuffer +{ +} From a96b0ada23677f2e9f4c271cf9f7153cb6d70233 Mon Sep 17 00:00:00 2001 From: Toocanzs Date: Sat, 18 Nov 2017 17:13:39 -0500 Subject: [PATCH 2/2] runelite-client: add pray flick plugin --- .../net/runelite/api/widgets/WidgetID.java | 1 + .../net/runelite/api/widgets/WidgetInfo.java | 2 + .../plugins/prayflick/PrayerFlickConfig.java | 47 +++++++ .../plugins/prayflick/PrayerFlickOverlay.java | 124 ++++++++++++++++++ .../plugins/prayflick/PrayerFlickPlugin.java | 68 ++++++++++ 5 files changed, 242 insertions(+) create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/prayflick/PrayerFlickConfig.java create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/prayflick/PrayerFlickOverlay.java create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/prayflick/PrayerFlickPlugin.java diff --git a/runelite-api/src/main/java/net/runelite/api/widgets/WidgetID.java b/runelite-api/src/main/java/net/runelite/api/widgets/WidgetID.java index 8c18ddfea6..17d2fbf227 100644 --- a/runelite-api/src/main/java/net/runelite/api/widgets/WidgetID.java +++ b/runelite-api/src/main/java/net/runelite/api/widgets/WidgetID.java @@ -136,6 +136,7 @@ class WidgetID static class Minimap { static final int XP_ORB = 1; + static final int QUICK_PRAYER_ORB = 14; } static class Viewport diff --git a/runelite-api/src/main/java/net/runelite/api/widgets/WidgetInfo.java b/runelite-api/src/main/java/net/runelite/api/widgets/WidgetInfo.java index deb6f3a9f5..2818f1b7c0 100644 --- a/runelite-api/src/main/java/net/runelite/api/widgets/WidgetInfo.java +++ b/runelite-api/src/main/java/net/runelite/api/widgets/WidgetInfo.java @@ -32,6 +32,8 @@ public enum WidgetInfo CLUE_SCROLL_TEXT(WidgetID.CLUE_SCROLL_GROUP_ID, WidgetID.Cluescroll.CLUE_TEXT), + QUICK_PRAYER_ORB(WidgetID.MINIMAP_GROUP_ID, WidgetID.Minimap.QUICK_PRAYER_ORB), + EQUIPMENT(WidgetID.EQUIPMENT_GROUP_ID, 0), EQUIPMENT_HELMET(WidgetID.EQUIPMENT_GROUP_ID, WidgetID.Equipment.HELMET), diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/prayflick/PrayerFlickConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/prayflick/PrayerFlickConfig.java new file mode 100644 index 0000000000..f6f633550e --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/prayflick/PrayerFlickConfig.java @@ -0,0 +1,47 @@ +/* + * 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.prayflick; + +import net.runelite.client.config.ConfigGroup; +import net.runelite.client.config.ConfigItem; +import net.runelite.client.config.Config; + +@ConfigGroup( + keyName = "prayflick", + name = "Prayer Flick", + description = "Configuration for the prayer flicking plugin" +) +public interface PrayerFlickConfig extends Config +{ + @ConfigItem( + keyName = "enabled", + name = "Enabled", + description = "Configures whether or not prayer flicking plugin is displayed" + ) + default boolean enabled() + { + return true; + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/prayflick/PrayerFlickOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/prayflick/PrayerFlickOverlay.java new file mode 100644 index 0000000000..b676ea237f --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/prayflick/PrayerFlickOverlay.java @@ -0,0 +1,124 @@ +/* + * 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.prayflick; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics2D; +import java.awt.geom.Rectangle2D; +import java.time.Duration; +import java.time.Instant; +import javax.annotation.Nullable; +import javax.inject.Inject; +import net.runelite.api.Client; +import net.runelite.api.GameState; +import net.runelite.api.Prayer; +import net.runelite.api.widgets.Widget; +import net.runelite.api.widgets.WidgetInfo; +import net.runelite.client.ui.overlay.Overlay; +import net.runelite.client.ui.overlay.OverlayPosition; + +public class PrayerFlickOverlay extends Overlay +{ + private final Client client; + private final PrayerFlickConfig config; + private boolean prayersActive = false; + private Instant startOfLastTick = Instant.now(); + + @Inject + public PrayerFlickOverlay(@Nullable Client client, PrayerFlickConfig config) + { + super(OverlayPosition.DYNAMIC); + this.client = client; + this.config = config; + } + + public void onTick() + { + startOfLastTick = Instant.now(); //Reset the tick timer + prayersActive = isAnyPrayerActive(); //Check if prayers are active + } + + @Override + public Dimension render(Graphics2D graphics) + { + if (client.getGameState() != GameState.LOGGED_IN || !config.enabled() || !prayersActive)//If there are no prayers active we don't need to be flicking + { + return null; + } + + Widget xpOrb = client.getWidget(WidgetInfo.QUICK_PRAYER_ORB); + if (xpOrb == null) + { + return null; + } + + Rectangle2D bounds = xpOrb.getBounds().getBounds2D(); + if (bounds.getX() <= 0) + { + return null; + } + + //Purposefully using height twice here as the bounds of the prayer orb includes the number sticking out the side + int orbInnerHeight = (int) bounds.getHeight(); + int orbInnerWidth = orbInnerHeight; + + int orbInnerX = (int) (bounds.getX() + 24);//x pos of the inside of the prayer orb + int orbInnerY = (int) (bounds.getY() - 1);//y pos of the inside of the prayer orb + + long timeSinceLastTick = Duration.between(startOfLastTick, Instant.now()).toMillis(); + + float tickProgress = timeSinceLastTick / 600f; + tickProgress = Math.min(tickProgress, 1);//Cap to 1, so if a tick continues past the expected 600 we don't move the indicator off the orb + + double t = tickProgress * Math.PI;//t on interval [0,pi] + + int xOffset = (int) (-Math.cos(t) * orbInnerWidth / 2) + orbInnerWidth / 2; + int indicatorHeight = (int) (Math.sin(t) * orbInnerHeight); + + int yOffset = (orbInnerHeight / 2) - (indicatorHeight / 2); + + graphics.setColor(new Color(255, 255, 255, 100)); + graphics.fillArc(orbInnerX, orbInnerY, orbInnerWidth, orbInnerHeight, 0, 360); + + graphics.setColor(Color.cyan); + graphics.fillRect(orbInnerX + xOffset, orbInnerY + yOffset, 1, indicatorHeight); + + return new Dimension((int) bounds.getWidth(), (int) bounds.getHeight()); + } + + boolean isAnyPrayerActive() + { + for (Prayer pray : Prayer.values())//Check if any prayers are active + { + if (client.isPrayerActive(pray)) + { + return true; + } + } + + return false; + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/prayflick/PrayerFlickPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/prayflick/PrayerFlickPlugin.java new file mode 100644 index 0000000000..a2766de774 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/prayflick/PrayerFlickPlugin.java @@ -0,0 +1,68 @@ +/* + * 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.prayflick; + +import com.google.common.eventbus.Subscribe; +import com.google.inject.Binder; +import com.google.inject.Provides; +import javax.inject.Inject; +import net.runelite.client.config.ConfigManager; +import net.runelite.client.events.GameTick; +import net.runelite.client.plugins.Plugin; +import net.runelite.client.plugins.PluginDescriptor; +import net.runelite.client.ui.overlay.Overlay; + +@PluginDescriptor( + name = "Prayer flicking plugin" +) +public class PrayerFlickPlugin extends Plugin +{ + @Inject + PrayerFlickOverlay overlay; + + @Override + public void configure(Binder binder) + { + binder.bind(PrayerFlickOverlay.class); + } + + @Provides + PrayerFlickConfig getConfig(ConfigManager configManager) + { + return configManager.getConfig(PrayerFlickConfig.class); + } + + @Override + public Overlay getOverlay() + { + return overlay; + } + + @Subscribe + public void onTick(GameTick tick) + { + overlay.onTick(); + } +}