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 f3deccf680..c59b8cd765 100644 --- a/runelite-api/src/main/java/net/runelite/api/Client.java +++ b/runelite-api/src/main/java/net/runelite/api/Client.java @@ -356,11 +356,12 @@ public class Client } /** - * Returns the local player's current experience in the specified {@link Skill}. + * Returns the local player's current experience in the specified + * {@link Skill}. * * @param skill the {@link Skill} to retrieve the experience for - * @return the local player's current experience in the specified {@link Skill}, or -1 if the {@link Skill} isn't - * valid + * @return the local player's current experience in the specified + * {@link Skill}, or -1 if the {@link Skill} isn't valid */ public int getSkillExperience(Skill skill) { @@ -389,4 +390,14 @@ public class Client return experiences[idx]; } + + public int getGameDrawingMode() + { + return client.getGameDrawingMode(); + } + + public void setGameDrawingMode(int gameDrawingMode) + { + client.setGameDrawingMode(gameDrawingMode); + } } diff --git a/runelite-client/src/main/java/net/runelite/inject/callbacks/Hooks.java b/runelite-client/src/main/java/net/runelite/client/callback/Hooks.java similarity index 87% rename from runelite-client/src/main/java/net/runelite/inject/callbacks/Hooks.java rename to runelite-client/src/main/java/net/runelite/client/callback/Hooks.java index 37ffaac609..4c2c803eb3 100644 --- a/runelite-client/src/main/java/net/runelite/inject/callbacks/Hooks.java +++ b/runelite-client/src/main/java/net/runelite/client/callback/Hooks.java @@ -22,8 +22,10 @@ * (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.inject.callbacks; +package net.runelite.client.callback; +import java.awt.Graphics; +import java.awt.image.BufferedImage; import net.runelite.api.Skill; import net.runelite.client.RuneLite; import net.runelite.client.events.ExperienceChanged; @@ -31,6 +33,8 @@ import net.runelite.client.events.MapRegionChanged; import net.runelite.client.events.MenuOptionClicked; import net.runelite.client.events.PlayerMenuOptionsChanged; import net.runelite.client.events.AnimationChanged; +import net.runelite.client.ui.overlay.OverlayRenderer; +import net.runelite.rs.api.MainBufferProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,6 +44,24 @@ public class Hooks private static final RuneLite runelite = RuneLite.getRunelite(); + public static void draw(Object provider, Graphics graphics, int x, int y) + { + // XXX fix injector to use interface in signature + MainBufferProvider mpb = (MainBufferProvider) provider; + BufferedImage image = (BufferedImage) mpb.getImage(); + + OverlayRenderer renderer = runelite.getRenderer(); + + try + { + renderer.render(image); + } + catch (Exception ex) + { + logger.warn("Error during overlay rendering", ex); + } + } + public static void callHook(String name, int idx, Object object) { if (RuneLite.getClient() == null) diff --git a/runelite-client/src/main/java/net/runelite/client/ui/ClientPanel.java b/runelite-client/src/main/java/net/runelite/client/ui/ClientPanel.java index 2508f54a31..cf2dcbe342 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/ClientPanel.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/ClientPanel.java @@ -93,6 +93,11 @@ final class ClientPanel extends JPanel Client client = new Client((net.runelite.rs.api.Client) rs); RuneLite.setClient(client); + + // This causes the whole game frame to be redrawn each frame instead + // of only the viewport, so we can hook to MainBufferProvider#draw + // and draw anywhere without it leaving artifacts + client.setGameDrawingMode(2); } } diff --git a/runelite-client/src/main/java/net/runelite/inject/callbacks/RSCanvasCallback.java b/runelite-client/src/main/java/net/runelite/inject/callbacks/RSCanvasCallback.java deleted file mode 100644 index e7adee29b5..0000000000 --- a/runelite-client/src/main/java/net/runelite/inject/callbacks/RSCanvasCallback.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2016-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.inject.callbacks; - -import java.awt.Canvas; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Image; -import java.awt.image.BufferedImage; -import net.runelite.client.RuneLite; -import net.runelite.client.ui.overlay.OverlayRenderer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class RSCanvasCallback -{ - private static final Logger logger = LoggerFactory.getLogger(RSCanvasCallback.class); - - private static final int WIDTH = 765, HEIGHT = 503; - - private BufferedImage clientBuffer = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB); - private BufferedImage gameBuffer = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB); - - public Graphics getGraphics(Canvas canvas, Graphics superGraphics) - { - if (canvas.getHeight() != clientBuffer.getHeight() || canvas.getWidth() != clientBuffer.getWidth()) - { - clientBuffer = resize(clientBuffer, canvas.getWidth(), canvas.getHeight()); - gameBuffer = resize(gameBuffer, canvas.getWidth(), canvas.getHeight()); - } - - Graphics clientGraphics = clientBuffer.getGraphics(); - clientGraphics.drawImage(gameBuffer, 0, 0, null); - clientGraphics.dispose(); - - RuneLite runelite = RuneLite.getRunelite(); - if (runelite != null) - { - OverlayRenderer renderer = runelite.getRenderer(); - if (renderer != null) - { - try - { - renderer.render(clientBuffer); - } - catch (Exception ex) - { - logger.warn("Error during overlay rendering", ex); - } - } - } - - superGraphics.drawImage(clientBuffer, 0, 0, null); - - return gameBuffer.getGraphics(); - } - - private static BufferedImage resize(BufferedImage img, int newWidth, int newHeight) - { - Image tmp = img.getScaledInstance(newWidth, newHeight, Image.SCALE_FAST); - BufferedImage bufferedImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_RGB); - - Graphics2D graphics = bufferedImage.createGraphics(); - graphics.drawImage(tmp, 0, 0, null); - graphics.dispose(); - - return bufferedImage; - } -} diff --git a/runescape-api/src/main/java/net/runelite/rs/api/MainBufferProvider.java b/runescape-api/src/main/java/net/runelite/rs/api/MainBufferProvider.java new file mode 100644 index 0000000000..c0e80e9e25 --- /dev/null +++ b/runescape-api/src/main/java/net/runelite/rs/api/MainBufferProvider.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.rs.api; + +import java.awt.Image; +import net.runelite.mapping.Import; + +public interface MainBufferProvider +{ + @Import("image") + Image getImage(); +}