runelite-client: add debug/ground item plugins for labeling objects and tiles, and the apis for them

This commit is contained in:
Adam
2017-04-10 18:49:37 -04:00
parent 3f6212507d
commit df92264e8d
31 changed files with 1312 additions and 18 deletions

View File

@@ -22,7 +22,6 @@
* (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;
import java.util.ArrayList;
@@ -31,12 +30,18 @@ import java.util.List;
import net.runelite.client.RuneLite;
import net.runelite.client.plugins.boosts.Boosts;
import net.runelite.client.plugins.bosstimer.BossTimers;
import net.runelite.client.plugins.debug.Debug;
import net.runelite.client.plugins.fpsinfo.FPS;
import net.runelite.client.plugins.gronditems.GroundItems;
import net.runelite.client.plugins.hiscore.Hiscore;
import net.runelite.client.plugins.opponentinfo.OpponentInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class PluginManager
{
private static final Logger logger = LoggerFactory.getLogger(PluginManager.class);
private final RuneLite runelite;
private final List<Plugin> plugins = new ArrayList<>();
@@ -52,6 +57,14 @@ public class PluginManager
load(new FPS());
load(new Hiscore());
load(new BossTimers());
if (RuneLite.getOptions().has("developer-mode"))
{
logger.info("Loading developer plugins");
load(new Debug());
load(new GroundItems());
}
}
private void load(Plugin plugin)

View File

@@ -0,0 +1,40 @@
/*
* Copyright (c) 2017, Adam <Adam@sigterm.info>
* 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.debug;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.ui.overlay.Overlay;
public class Debug extends Plugin
{
private final DebugOverlay debugOverlay = new DebugOverlay();
@Override
public Overlay getOverlay()
{
return debugOverlay;
}
}

View File

@@ -0,0 +1,163 @@
/*
* Copyright (c) 2017, Adam <Adam@sigterm.info>
* 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.debug;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import net.runelite.api.Client;
import net.runelite.api.DecorativeObject;
import net.runelite.api.GameObject;
import net.runelite.api.GameState;
import net.runelite.api.GroundObject;
import net.runelite.api.Point;
import net.runelite.api.Region;
import net.runelite.api.Tile;
import net.runelite.api.TileObject;
import net.runelite.api.WallObject;
import net.runelite.client.RuneLite;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayPosition;
public class DebugOverlay extends Overlay
{
private static final Client client = RuneLite.getClient();
private static final int REGION_SIZE = 104;
public DebugOverlay()
{
super(OverlayPosition.DYNAMIC);
}
@Override
public Dimension render(Graphics2D graphics)
{
if (client.getGameState() != GameState.LOGGED_IN)
{
return null;
}
Region region = client.getRegion();
Tile[][][] tiles = region.getTiles();
int z = client.getPlane();
for (int x = 0; x < REGION_SIZE; ++x)
{
for (int y = 0; y < REGION_SIZE; ++y)
{
Tile tile = tiles[z][x][y];
if (tile == null)
{
continue;
}
render(graphics, tile);
}
}
return null;
}
private void render(Graphics2D graphics, Tile tile)
{
renderDecorativeObject(graphics, tile);
renderWallObject(graphics, tile);
renderGroundObject(graphics, tile);
renderGameObjects(graphics, tile);
}
private void renderDecorativeObject(Graphics2D graphics, Tile tile)
{
DecorativeObject decorativeObject = tile.getDecorativeObject();
if (decorativeObject == null)
{
return;
}
int id = decorativeObject.getId();
renderTileObject(graphics, decorativeObject, Color.RED, "D" + id);
}
private void renderWallObject(Graphics2D graphics, Tile tile)
{
WallObject wallObject = tile.getWallObject();
if (wallObject == null)
{
return;
}
int id = wallObject.getId();
renderTileObject(graphics, wallObject, Color.GREEN, "W" + id);
}
private void renderGroundObject(Graphics2D graphics, Tile tile)
{
GroundObject groundObject = tile.getGroundObject();
if (groundObject == null)
{
return;
}
int id = groundObject.getId();
renderTileObject(graphics, groundObject, Color.BLUE, "G" + id);
}
private void renderGameObjects(Graphics2D graphics, Tile tile)
{
GameObject[] gameObjects = tile.getGameObjects();
if (gameObjects == null)
{
return;
}
for (GameObject gameObject : gameObjects)
{
if (gameObject == null)
{
continue;
}
renderTileObject(graphics, gameObject, Color.YELLOW, "GA" + gameObject.getId());
}
}
private void renderTileObject(Graphics2D graphics, TileObject tileObject, Color color, String text)
{
Point canvasLocation = tileObject.getCanvasLocation();
if (canvasLocation == null)
{
return;
}
graphics.setColor(color);
graphics.drawString(text, canvasLocation.getX(), canvasLocation.getY());
}
}

View File

@@ -0,0 +1,40 @@
/*
* Copyright (c) 2017, Adam <Adam@sigterm.info>
* 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.gronditems;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.ui.overlay.Overlay;
public class GroundItems extends Plugin
{
private final GroundItemsOverlay groundItemsOverlay = new GroundItemsOverlay();
@Override
public Overlay getOverlay()
{
return groundItemsOverlay;
}
}

View File

@@ -0,0 +1,114 @@
/*
* Copyright (c) 2017, Adam <Adam@sigterm.info>
* 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.gronditems;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.Item;
import net.runelite.api.ItemLayer;
import net.runelite.api.Node;
import net.runelite.api.Point;
import net.runelite.api.Region;
import net.runelite.api.Tile;
import net.runelite.client.RuneLite;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayPosition;
public class GroundItemsOverlay extends Overlay
{
private static final Client client = RuneLite.getClient();
private static final int REGION_SIZE = 104;
public GroundItemsOverlay()
{
super(OverlayPosition.DYNAMIC);
}
@Override
public Dimension render(Graphics2D graphics)
{
if (client.getGameState() != GameState.LOGGED_IN)
{
return null;
}
Region region = client.getRegion();
Tile[][][] tiles = region.getTiles();
int z = client.getPlane();
for (int x = 0; x < REGION_SIZE; ++x)
{
for (int y = 0; y < REGION_SIZE; ++y)
{
Tile tile = tiles[z][x][y];
if (tile == null)
{
continue;
}
render(graphics, tile);
}
}
return null;
}
private void render(Graphics2D graphics, Tile tile)
{
ItemLayer itemLayer = tile.getItemLayer();
if (itemLayer == null)
{
return;
}
Point canvasLocation = itemLayer.getCanvasLocation();
if (canvasLocation == null)
{
return;
}
Node current = itemLayer.getBottom();
while (current instanceof Item)
{
Item item = (Item) current;
render(graphics, canvasLocation, item);
current = current.getNext();
}
}
private void render(Graphics2D graphics, Point canvasLocation, Item item)
{
graphics.setColor(Color.ORANGE);
graphics.drawString("I" + item.getId(), canvasLocation.getX(), canvasLocation.getY());
}
}

View File

@@ -0,0 +1,52 @@
/*
* Copyright (c) 2017, Adam <Adam@sigterm.info>
* 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.ui.overlay;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
public class DynamicRenderer implements Renderer
{
private final List<Overlay> overlays = new ArrayList<>();
public void add(Overlay overlay)
{
overlays.add(overlay);
}
@Override
public void render(BufferedImage clientBuffer)
{
for (Overlay overlay : overlays)
{
Graphics2D graphics = clientBuffer.createGraphics();
overlay.render(graphics);
graphics.dispose();
}
}
}

View File

@@ -33,6 +33,11 @@ public abstract class Overlay
private OverlayPosition position; // where to draw it
private OverlayPriority priority; // if multiple overlays exist in the same position, who wins
public Overlay(OverlayPosition position)
{
this(position, OverlayPriority.NONE);
}
public Overlay(OverlayPosition position, OverlayPriority priority)
{
this.position = position;

View File

@@ -22,11 +22,20 @@
* (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.ui.overlay;
public enum OverlayPosition
{
/**
* Place overlay in the top left most area possible
*/
TOP_LEFT,
TOP_RIGHT;
/**
* Place overlay in the top right most area possible
*/
TOP_RIGHT,
/**
* Overlay places itself where it wants
*/
DYNAMIC;
}

View File

@@ -27,6 +27,7 @@ package net.runelite.client.ui.overlay;
public enum OverlayPriority
{
NONE,
LOW,
MED,
HIGH;

View File

@@ -36,6 +36,7 @@ public class OverlayRenderer
{
TopDownRendererLeft tdl = new TopDownRendererLeft();
TopDownRendererRight tdr = new TopDownRendererRight();
DynamicRenderer dr = new DynamicRenderer();
for (Plugin plugin : RuneLite.getRunelite().getPluginManager().getPlugins())
{
@@ -54,10 +55,14 @@ public class OverlayRenderer
case TOP_LEFT:
tdl.add(overlay);
break;
case DYNAMIC:
dr.add(overlay);
break;
}
}
tdl.render(clientBuffer);
tdr.render(clientBuffer);
dr.render(clientBuffer);
}
}

View File

@@ -0,0 +1,32 @@
/*
* Copyright (c) 2017, Adam <Adam@sigterm.info>
* 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.ui.overlay;
import java.awt.image.BufferedImage;
public interface Renderer
{
void render(BufferedImage clientBuffer);
}

View File

@@ -31,7 +31,7 @@ import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
public class TopDownRendererLeft
public class TopDownRendererLeft implements Renderer
{
private static final int BORDER_TOP = 25;
private static final int BORDER_LEFT = 10;
@@ -44,6 +44,7 @@ public class TopDownRendererLeft
overlays.add(overlay);
}
@Override
public void render(BufferedImage clientBuffer)
{
overlays.sort((o1, o2) -> o2.getPriority().compareTo(o1.getPriority()));

View File

@@ -25,15 +25,15 @@
package net.runelite.client.ui.overlay;
import net.runelite.api.Client;
import net.runelite.client.RuneLite;
import java.awt.*;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
import net.runelite.api.Client;
import net.runelite.client.RuneLite;
public class TopDownRendererRight
public class TopDownRendererRight implements Renderer
{
private static final int BORDER_TOP = 0;
private static final int BORDER_RIGHT = 0;
@@ -46,6 +46,7 @@ public class TopDownRendererRight
overlays.add(overlay);
}
@Override
public void render(BufferedImage clientBuffer)
{
Client client = RuneLite.getClient();