From 44266d0dccd1b09b7304c78ad03a3d855207eeeb Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 25 Mar 2018 18:43:29 -0400 Subject: [PATCH] instance map plugin: rewrite to use client minimap code --- .../main/java/net/runelite/api/Client.java | 2 + .../main/java/net/runelite/api/Region.java | 4 - .../instancemap/InstanceMapOverlay.java | 560 +----------------- .../client/plugins/instancemap/PixelMaps.java | 271 --------- .../plugins/instancemap/WallOffset.java | 47 -- .../client/plugins/instancemap/WallShape.java | 51 -- .../net/runelite/mixins/MinimapMixin.java | 101 ++++ .../net/runelite/rs/api/RSBufferProvider.java | 3 + .../java/net/runelite/rs/api/RSClient.java | 13 +- .../java/net/runelite/rs/api/RSRegion.java | 10 +- .../net/runelite/rs/api/RSSpritePixels.java | 3 + 11 files changed, 153 insertions(+), 912 deletions(-) delete mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/instancemap/PixelMaps.java delete mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/instancemap/WallOffset.java delete mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/instancemap/WallShape.java create mode 100644 runelite-mixins/src/main/java/net/runelite/mixins/MinimapMixin.java 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 f2b1f60a00..24c6cd9aba 100644 --- a/runelite-api/src/main/java/net/runelite/api/Client.java +++ b/runelite-api/src/main/java/net/runelite/api/Client.java @@ -344,4 +344,6 @@ public interface Client extends GameEngine * @return world */ World createWorld(); + + SpritePixels drawInstanceMap(int z); } diff --git a/runelite-api/src/main/java/net/runelite/api/Region.java b/runelite-api/src/main/java/net/runelite/api/Region.java index c095406d39..95fd4148eb 100644 --- a/runelite-api/src/main/java/net/runelite/api/Region.java +++ b/runelite-api/src/main/java/net/runelite/api/Region.java @@ -27,8 +27,4 @@ package net.runelite.api; public interface Region { Tile[][][] getTiles(); - - int[][] getTileMask2d(); - - int[][] getTileRotation2d(); } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/instancemap/InstanceMapOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/instancemap/InstanceMapOverlay.java index 4295f65ccb..6950f2cc82 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/instancemap/InstanceMapOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/instancemap/InstanceMapOverlay.java @@ -32,42 +32,14 @@ import java.awt.image.BufferedImage; import javax.inject.Inject; import javax.inject.Singleton; import net.runelite.api.Client; -import net.runelite.api.GameObject; -import net.runelite.api.GroundObject; -import net.runelite.api.IndexedSprite; -import net.runelite.api.ObjectComposition; import net.runelite.api.Player; -import net.runelite.api.Point; -import net.runelite.api.Region; -import net.runelite.api.SceneTileModel; -import net.runelite.api.SceneTilePaint; import net.runelite.api.SpritePixels; import net.runelite.api.Tile; -import net.runelite.api.WallObject; import net.runelite.api.coords.LocalPoint; import net.runelite.api.events.GameStateChanged; import net.runelite.api.events.MapRegionChanged; -import static net.runelite.client.plugins.instancemap.PixelMaps.ALL; -import static net.runelite.client.plugins.instancemap.PixelMaps.BOTTOM; -import static net.runelite.client.plugins.instancemap.PixelMaps.BOTTOM_LEFT_CORNER; -import static net.runelite.client.plugins.instancemap.PixelMaps.BOTTOM_LEFT_DOT; -import static net.runelite.client.plugins.instancemap.PixelMaps.BOTTOM_LEFT_TO_TOP_RIGHT; -import static net.runelite.client.plugins.instancemap.PixelMaps.BOTTOM_RIGHT_CORNER; -import static net.runelite.client.plugins.instancemap.PixelMaps.BOTTOM_RIGHT_DOT; -import static net.runelite.client.plugins.instancemap.PixelMaps.LEFT; -import static net.runelite.client.plugins.instancemap.PixelMaps.RIGHT; -import static net.runelite.client.plugins.instancemap.PixelMaps.TOP; -import static net.runelite.client.plugins.instancemap.PixelMaps.TOP_LEFT_CORNER; -import static net.runelite.client.plugins.instancemap.PixelMaps.TOP_LEFT_DOT; -import static net.runelite.client.plugins.instancemap.PixelMaps.TOP_LEFT_TO_BOTTOM_RIGHT; -import static net.runelite.client.plugins.instancemap.PixelMaps.TOP_RIGHT_CORNER; -import static net.runelite.client.plugins.instancemap.PixelMaps.TOP_RIGHT_DOT; -import static net.runelite.client.plugins.instancemap.WallOffset.BOTTOM_LEFT; -import static net.runelite.client.plugins.instancemap.WallOffset.BOTTOM_RIGHT; -import static net.runelite.client.plugins.instancemap.WallOffset.NONE; -import static net.runelite.client.plugins.instancemap.WallOffset.TOP_LEFT; -import static net.runelite.client.plugins.instancemap.WallOffset.TOP_RIGHT; import net.runelite.client.ui.overlay.Overlay; +import net.runelite.client.ui.overlay.OverlayLayer; import net.runelite.client.ui.overlay.OverlayPosition; import net.runelite.client.ui.overlay.OverlayPriority; import net.runelite.client.ui.overlay.components.BackgroundComponent; @@ -82,12 +54,6 @@ class InstanceMapOverlay extends Overlay */ static final int TILE_SIZE = 4; - /** - * The multiplier to scale the map size by. This is just for rendering - * mapImage. mapImage is scaled by this value - */ - private static final double MAP_SCALING = 1; - /** * The size of the player's position marker on the map */ @@ -120,6 +86,8 @@ class InstanceMapOverlay extends Overlay this.client = client; setPriority(OverlayPriority.HIGH); setPosition(OverlayPosition.TOP_LEFT); + setLayer(OverlayLayer.ABOVE_WIDGETS); + backgroundComponent.setFill(false); } public boolean isMapShown() @@ -185,7 +153,8 @@ class InstanceMapOverlay extends Overlay if (image == null) { - image = drawMapImage(getTiles()); + SpritePixels map = client.drawInstanceMap(viewedPlane); + image = minimapToBufferedImage(map); synchronized (this) { if (showMap) @@ -196,6 +165,8 @@ class InstanceMapOverlay extends Overlay } graphics.drawImage(image, 0, 0, null); + backgroundComponent.setRectangle(new Rectangle(0, 0, image.getWidth(), image.getHeight())); + backgroundComponent.render(graphics); if (client.getPlane() == viewedPlane)//If we are not viewing the plane we are on, don't show player's position { @@ -210,6 +181,17 @@ class InstanceMapOverlay extends Overlay return new Dimension(image.getWidth(), image.getHeight()); } + /** + * Get the files for the current viewed plane + * + * @return + */ + private Tile[][] getTiles() + { + Tile[][][] regionTiles = client.getRegion().getTiles(); + return regionTiles[viewedPlane]; + } + /** * Draws the players position as a dot on the map. * @@ -224,8 +206,8 @@ class InstanceMapOverlay extends Overlay int tileX = playerLoc.getRegionX(); int tileY = (tiles[0].length - 1) - playerLoc.getRegionY(); // flip the y value - int x = (int) (tileX * TILE_SIZE * MAP_SCALING); - int y = (int) (tileY * TILE_SIZE * MAP_SCALING); + int x = (int) (tileX * TILE_SIZE); + int y = (int) (tileY * TILE_SIZE); graphics.setColor(dotColor); graphics.fillRect(x, y, PLAYER_MARKER_SIZE, PLAYER_MARKER_SIZE);//draw the players point on the map graphics.setColor(outlineColor); @@ -239,7 +221,7 @@ class InstanceMapOverlay extends Overlay */ public void onRegionChange(MapRegionChanged event) { - mapImage = drawMapImage(getTiles()); + mapImage = null; } /** @@ -249,498 +231,18 @@ class InstanceMapOverlay extends Overlay */ public void onGameStateChange(GameStateChanged event) { - mapImage = drawMapImage(getTiles()); + mapImage = null; } - /** - * Get the files for the current viewed plane - * - * @return - */ - private Tile[][] getTiles() + private static BufferedImage minimapToBufferedImage(SpritePixels spritePixels) { - Tile[][][] regionTiles = client.getRegion().getTiles(); - return regionTiles[viewedPlane]; + int width = spritePixels.getWidth(); + int height = spritePixels.getHeight(); + int[] pixels = spritePixels.getPixels(); + BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + img.setRGB(0, 0, width, height, pixels, 0, width); + // 24624 / 512 and 24624 % 512 are both 48 + img = img.getSubimage(48, 48, TILE_SIZE * 104, TILE_SIZE * 104); + return img; } - - /** - * Draws the map to the the buffered image mapImage - * - * @param tiles The tiles to draw to the map - */ - private BufferedImage drawMapImage(Tile[][] tiles) - { - BufferedImage image = new BufferedImage(tiles.length * TILE_SIZE, tiles[0].length * TILE_SIZE, BufferedImage.TYPE_INT_RGB); - Graphics2D g = image.createGraphics(); - drawInstanceMap(g); - g.dispose(); - return image; - } - - /** - * Draws all the tiles on the current plane of client.reigion to the - * screen. This will show instances unlike the world map. - * - * @param graphics graphics to draw to - * @return The dimensions of the map - */ - private void drawInstanceMap(Graphics2D graphics) - { - Region region = client.getRegion(); - Tile[][] tiles = getTiles(); - - Dimension mapOverlaySize = new Dimension(tiles.length * TILE_SIZE, tiles[0].length * TILE_SIZE); - - backgroundComponent.setFill(false); - backgroundComponent.setRectangle(new Rectangle(0, 0, mapOverlaySize.width, mapOverlaySize.height)); - backgroundComponent.render(graphics); - - //These loops are seperated on purpose to prevent layering issues. This is how it's written in the client - //Draw the base colors first - for (int x = 0; x < tiles.length; x++) - { - for (int y = tiles[x].length - 1; y >= 0; y--)//flip y value - { - drawTileColor(graphics, region, tiles[x][(tiles[x].length - 1) - y], x, y); - } - } - - //environment - for (int x = 0; x < tiles.length; x++) - { - for (int y = tiles[x].length - 1; y >= 0; y--)//Flip y value - { - drawEnvironment(graphics, region, tiles[x][(tiles[x].length - 1) - y], x, y);//draw trees/rocks/bushes - } - } - - //Draw walls - for (int x = 0; x < tiles.length; x++) - { - for (int y = tiles[x].length - 1; y >= 0; y--)//Flip y value - { - drawTileWalls(graphics, tiles[x][(tiles[x].length - 1) - y], x, y); - } - } - - //Finally draw map icons on top of that - for (int x = 0; x < tiles.length; x++) - { - for (int y = tiles[x].length - 1; y >= 0; y--)//Flip y value - { - drawMapIcons(graphics, region, tiles[x][(tiles[x].length - 1) - y], x, y);//draw map icons - } - } - - } - - private void drawTileWalls(Graphics2D graphics, Tile curTile, int x, int y) - { - if (curTile == null) - { - return; - } - - WallObject wallObject = curTile.getWallObject(); - if (wallObject != null) - { - drawWallObject(graphics, wallObject, curTile, x * TILE_SIZE, y * TILE_SIZE); - } - } - - private void drawTileColor(Graphics2D graphics, Region region, Tile curTile, int x, int y) - { - if (curTile == null) - { - return; - } - - SceneTilePaint sceneTilePaint = curTile.getSceneTilePaint(); - SceneTileModel sceneTileModel = curTile.getSceneTileModel(); - - if (sceneTilePaint != null) - { - drawMapPixel(graphics, sceneTilePaint, x * TILE_SIZE, y * TILE_SIZE); - } - else if (sceneTileModel != null) - { - drawComplexMapPixel(graphics, sceneTileModel, region, x * TILE_SIZE, y * TILE_SIZE); - } - } - - private void drawMapIcons(Graphics2D graphics, Region region, Tile curTile, int x, int y) - { - if (curTile == null) - { - return; - } - - //Draw game objects - GroundObject groundObject = curTile.getGroundObject(); - if (groundObject == null) - { - return; - } - - int hash = groundObject.getHash(); - int objId = groundObject.getId(); - - int startX = x * TILE_SIZE; - int startY = y * TILE_SIZE; - - if (hash != 0) - { - ObjectComposition objectComposition = client.getObjectDefinition(objId); - int mapIconId = objectComposition.getMapIconId(); - if (mapIconId >= 0) - { - // this parameter is unused - SpritePixels sprite = client.getMapAreas()[mapIconId].getMapIcon(false); - - if (sprite == null) - { - return; - } - - BufferedImage img = sprite.toBufferedImage(); - graphics.drawImage(img, startX - (img.getWidth() / 2), startY - (img.getHeight() / 2), null); - } - } - } - - private void drawEnvironment(Graphics2D graphics, Region region, Tile curTile, int x, int y) - { - if (curTile == null) - { - return; - } - - //Draw game objects - GameObject[] gameObjects = curTile.getGameObjects(); - if (gameObjects != null) - { - Tile[][] tiles = getTiles(); - for (GameObject gameObject : gameObjects) - { - if (gameObject == null) - { - continue; - } - - int hash = gameObject.getHash(); - int objId = gameObject.getId(); - - int startX = x * TILE_SIZE; - int startY = y * TILE_SIZE; - - if (hash == 0) - { - continue; - } - - ObjectComposition objectComposition = client.getObjectDefinition(objId); - if (objectComposition.getMapSceneId() != -1) - { - Point gameObjectLocation = gameObject.getRegionMinLocation(); - int tileX = x; - int tileY = ((tiles[x].length - 1) - y);//flip y value - - if (gameObjectLocation.getX() == tileX && gameObjectLocation.getY() == tileY) - { - - IndexedSprite objectMapSprite = client.getMapScene()[objectComposition.getMapSceneId()]; - if (objectMapSprite != null) - { - drawIndexedSprite(graphics, objectMapSprite, gameObject, startX, startY); - } - } - } - - } - } - } - - private void drawIndexedSprite(Graphics2D graphics, IndexedSprite indexedSprite, GameObject gameObject, int startX, int startY) - { - //Mostly from code in IndexedSprite - int sourceOffset = 0; - - //For some reason some sprites don't have a byte array that is the same size as the width*height - if (indexedSprite.getPixels().length != indexedSprite.getHeight() * indexedSprite.getWidth()) - { - return; - } - - for (int y = -indexedSprite.getHeight(); y < 0; y++) - { - for (int x = -indexedSprite.getWidth(); x < 0; x++) - { - int index = indexedSprite.getPixels()[sourceOffset++] & 0xff; - if (index != 0) - { - graphics.setColor(new Color(indexedSprite.getPalette()[index]));//Get color from the pallete - drawPoint(graphics, startX + x + indexedSprite.getWidth() + indexedSprite.getOffsetX(), startY + y + indexedSprite.getHeight() / 2 + indexedSprite.getOffsetY()); - } - } - } - } - - /** - * Draws a tile as 4x4 pixels on the map. This tile will be drawn as a - * set of 4x4 pixels - * - * @param graphics graphics to be drawn to - * @param sceneTilePaint the tiles sceneTilePaint used to get the RGB - * value of that tile - * @param startX the top left point at which the 4x4 is drawn - * @param startY the top left point at which the 4x4 is drawn - */ - private void drawMapPixel(Graphics2D graphics, SceneTilePaint sceneTilePaint, int startX, int startY) - { - //Normal map pixels have only 1 solid color - Color c = new Color(sceneTilePaint.getRBG()); - graphics.setColor(c); - graphics.fillRect(startX, startY, TILE_SIZE, TILE_SIZE); - } - - private WallShape getWallShape(WallObject wallObject) - { - int[][] pixels = ALL; - WallOffset wallOffset = NONE; - - //Warning: Gower code below - int flags = wallObject.getConfig() & 255; - int config1 = flags >> 6 & 3; - int config2 = flags & 31; - - // Straight walls - if (config2 == 0) - { - switch (config1) - { - case 0: - //draw left wall - pixels = LEFT; - wallOffset = NONE; - break; - case 1: - //draw top wall - pixels = TOP; - wallOffset = NONE; - break; - case 2: - //draw right wall - pixels = RIGHT; - wallOffset = NONE; - break; - case 3: - //draw bottom wall - pixels = BOTTOM; - wallOffset = NONE; - break; - - } - } - // Corners - else if (config2 == 2) - { - switch (config1) - { - case 0: - pixels = TOP_LEFT_CORNER; - break; - case 1: - pixels = TOP_RIGHT_CORNER; - wallOffset = NONE; - break; - case 2: - pixels = BOTTOM_RIGHT_CORNER; - wallOffset = NONE; - break; - case 3: - pixels = BOTTOM_LEFT_CORNER; - wallOffset = NONE; - break; - default: - break; - } - } - // Dots - else if (config2 == 3) - { - switch (config1) - { - case 0: - //draw dot top left - pixels = TOP_LEFT_DOT; - wallOffset = NONE; - break; - case 1: - //draw dot top right - pixels = TOP_RIGHT_DOT; - wallOffset = NONE; - break; - case 2: - //draw dot bottom right - pixels = BOTTOM_RIGHT_DOT; - wallOffset = NONE; - break; - case 3: - //draw dot bottom left - pixels = BOTTOM_LEFT_DOT; - wallOffset = NONE; - break; - default: - break; - } - } - //This part never gets called, but it's written in the client. ¯\_(ツ)_/¯ - else if (config2 == 9) - { - if (config1 != 0 && config1 != 2) - { - //draw diagonal \ - pixels = TOP_LEFT_TO_BOTTOM_RIGHT; - wallOffset = NONE; - } - else - { - //draw diagonal / - pixels = BOTTOM_LEFT_TO_TOP_RIGHT; - wallOffset = NONE; - } - } - //Diagonals - else if (config2 == 1) - { - switch (config1) - { - case 0: - //draw diagonal / - pixels = BOTTOM_LEFT_TO_TOP_RIGHT; - wallOffset = TOP_LEFT; - break; - case 1: - //draw diagonal \ - pixels = TOP_LEFT_TO_BOTTOM_RIGHT; - wallOffset = TOP_RIGHT; - break; - case 2: - pixels = BOTTOM_LEFT_TO_TOP_RIGHT; - wallOffset = BOTTOM_RIGHT; - break; - case 3: - pixels = TOP_LEFT_TO_BOTTOM_RIGHT; - wallOffset = BOTTOM_LEFT; - break; - default: - break; - } - } - - return new WallShape(pixels, wallOffset); - } - - /** - * Draws a wall on the map using a tiles WallObject. This wall will be - * drawn as a set of 4x4 pixels - * - * @param graphics graphics to be drawn to - * @param wallObject the wall object of the tile - * @param startX the top left point at which the 4x4 is drawn - * @param startY the top left point at which the 4x4 is drawn - */ - private void drawWallObject(Graphics2D graphics, WallObject wallObject, Tile tile, int startX, int startY) - { - graphics.setColor(Color.white); - - if (wallObject.getHash() == 0) - { - return; - } - - //door - if (wallObject.getHash() > 0) - { - graphics.setColor(Color.red); - } - ObjectComposition objectComposition = client.getObjectDefinition(wallObject.getId()); - - if (objectComposition.getMapSceneId() != -1) - { - return; - } - - WallShape wallShape = getWallShape(wallObject); - int[][] pixels = wallShape.getPixels(); - - for (int i = 0; i < pixels.length; i++) - { - for (int j = 0; j < pixels.length; j++) - { - if (pixels[i][j] == 1) - { - //Draw the 4x4 and offset accordingly - drawPoint(graphics, startX + wallShape.getOffset().xOffset + j, startY + wallShape.getOffset().yOffset + i); - } - } - } - - } - - /** - * Draws just one pixel to the screen - * - * @param graphics Graphics to be drawn to - * @param x x position of the pixel - * @param y y position of the pixel - */ - private void drawPoint(Graphics2D graphics, int x, int y) - { - graphics.drawLine(x, y, x, y); - } - - /** - * Draws tiles which have more than one color to them. For example a - * tile that falls on the edge of a river will have one part that is - * grass, and the other part will be water. To draw these tiles we need - * to use two colors. This tile will be drawn as a 4x4 set of pixels - * - * @param graphics the graphics to be drawn to - * @param sceneTileModel The SceneTileModel of the complex tile - * @param region The current region - * @param startX the top left point at which the 4x4 is drawn - * @param startY the top left point at which the 4x4 is drawn - */ - private void drawComplexMapPixel(Graphics2D graphics, SceneTileModel sceneTileModel, Region region, int startX, int startY) - { - //Most of this code is directly from the client from minimap rendering - int[][] TILE_MASK_2D = region.getTileMask2d(); - int[][] TILE_ROTATION_2D = region.getTileRotation2d(); - - int shape = sceneTileModel.getShape(); - int rotation = sceneTileModel.getRotation(); - - //SceneTileModels have only two colors, and overlay and underlay. - int overlay = sceneTileModel.getModelOverlay(); - int underlay = sceneTileModel.getModelUnderlay(); - - int[] shapes = TILE_MASK_2D[shape]; - int[] rotations = TILE_ROTATION_2D[rotation]; - - int rotationIndex = 0; - - for (int i = 0; i < TILE_SIZE; i++) - { - for (int j = 0; j < TILE_SIZE; j++) - { - int intColor = (shapes[rotations[rotationIndex++]] == 0) ? underlay : overlay; - Color c = new Color(intColor); - graphics.setColor(c); - graphics.fillRect(startX + j, startY + i, 1, 1); - } - } - - } - } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/instancemap/PixelMaps.java b/runelite-client/src/main/java/net/runelite/client/plugins/instancemap/PixelMaps.java deleted file mode 100644 index 09d74671e2..0000000000 --- a/runelite-client/src/main/java/net/runelite/client/plugins/instancemap/PixelMaps.java +++ /dev/null @@ -1,271 +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.instancemap; - -class PixelMaps -{ - static final int[][] ALL = new int[][] - { - { - 1, 1, 1, 1 - }, - { - 1, 1, 1, 1 - }, - { - 1, 1, 1, 1 - }, - { - 1, 1, 1, 1 - } - }; - - //Diagonal / - static final int[][] BOTTOM_LEFT_TO_TOP_RIGHT = new int[][] - { - { - 0, 0, 0, 1 - }, - { - 0, 0, 1, 0 - }, - { - 0, 1, 0, 0 - }, - { - 1, 0, 0, 0 - } - }; - - static final int[][] TOP_LEFT_DOT = new int[][] - { - { - 1, 0, 0, 0 - }, - { - 0, 0, 0, 0 - }, - { - 0, 0, 0, 0 - }, - { - 0, 0, 0, 0 - } - }; - - static final int[][] TOP_RIGHT_DOT = new int[][] - { - { - 0, 0, 0, 1 - }, - { - 0, 0, 0, 0 - }, - { - 0, 0, 0, 0 - }, - { - 0, 0, 0, 0 - } - }; - - static final int[][] BOTTOM_RIGHT_DOT = new int[][] - { - { - 0, 0, 0, 0 - }, - { - 0, 0, 0, 0 - }, - { - 0, 0, 0, 0 - }, - { - 0, 0, 0, 1 - } - }; - - static final int[][] BOTTOM_LEFT_DOT = new int[][] - { - { - 0, 0, 0, 0 - }, - { - 0, 0, 0, 0 - }, - { - 0, 0, 0, 0 - }, - { - 1, 0, 0, 0 - } - }; - - //Diagonal \ - static final int[][] TOP_LEFT_TO_BOTTOM_RIGHT = new int[][] - { - { - 1, 0, 0, 0 - }, - { - 0, 1, 0, 0 - }, - { - 0, 0, 1, 0 - }, - { - 0, 0, 0, 1 - } - }; - - //Left - static final int[][] LEFT = new int[][] - { - { - 1, 0, 0, 0 - }, - { - 1, 0, 0, 0 - }, - { - 1, 0, 0, 0 - }, - { - 1, 0, 0, 0 - } - }; - - static final int[][] TOP = new int[][] - { - { - 1, 1, 1, 1 - }, - { - 0, 0, 0, 0 - }, - { - 0, 0, 0, 0 - }, - { - 0, 0, 0, 0 - } - }; - - static final int[][] RIGHT = new int[][] - { - { - 0, 0, 0, 1 - }, - { - 0, 0, 0, 1 - }, - { - 0, 0, 0, 1 - }, - { - 0, 0, 0, 1 - } - }; - - static final int BOTTOM[][] = new int[][] - { - { - 0, 0, 0, 0 - }, - { - 0, 0, 0, 0 - }, - { - 0, 0, 0, 0 - }, - { - 1, 1, 1, 1 - } - }; - - static final int[][] TOP_LEFT_CORNER = new int[][] - { - { - 1, 1, 1, 1 - }, - { - 1, 0, 0, 0 - }, - { - 1, 0, 0, 0 - }, - { - 1, 0, 0, 0 - } - }; - - static final int[][] TOP_RIGHT_CORNER = new int[][] - { - { - 1, 1, 1, 1 - }, - { - 0, 0, 0, 1 - }, - { - 0, 0, 0, 1 - }, - { - 0, 0, 0, 1 - } - }; - - static final int[][] BOTTOM_RIGHT_CORNER = new int[][] - { - { - 0, 0, 0, 1 - }, - { - 0, 0, 0, 1 - }, - { - 0, 0, 0, 1 - }, - { - 1, 1, 1, 1 - } - }; - - static final int[][] BOTTOM_LEFT_CORNER = new int[][] - { - { - 1, 0, 0, 0 - }, - { - 1, 0, 0, 0 - }, - { - 1, 0, 0, 0 - }, - { - 1, 1, 1, 1 - } - }; -} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/instancemap/WallOffset.java b/runelite-client/src/main/java/net/runelite/client/plugins/instancemap/WallOffset.java deleted file mode 100644 index 8d4f868c2d..0000000000 --- a/runelite-client/src/main/java/net/runelite/client/plugins/instancemap/WallOffset.java +++ /dev/null @@ -1,47 +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.instancemap; - -import static net.runelite.client.plugins.instancemap.InstanceMapOverlay.TILE_SIZE; - -enum WallOffset -{ - TOP_LEFT(-TILE_SIZE / 2, -TILE_SIZE / 2), - TOP_RIGHT(TILE_SIZE / 2, -TILE_SIZE / 2), - BOTTOM_LEFT(-TILE_SIZE / 2, TILE_SIZE / 2), - BOTTOM_RIGHT(TILE_SIZE / 2, TILE_SIZE / 2), - RIGHT(TILE_SIZE / 2, 0), - LEFT(-TILE_SIZE / 2, 0), - NONE(0, 0); - - public final int xOffset; - public final int yOffset; - - WallOffset(int xOffset, int yOffset) - { - this.xOffset = xOffset; - this.yOffset = yOffset; - } -} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/instancemap/WallShape.java b/runelite-client/src/main/java/net/runelite/client/plugins/instancemap/WallShape.java deleted file mode 100644 index ac2702effe..0000000000 --- a/runelite-client/src/main/java/net/runelite/client/plugins/instancemap/WallShape.java +++ /dev/null @@ -1,51 +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.instancemap; - -/** - * Used to represent the wall as a 4x4 set of pixels with an offset - */ -class WallShape -{ - private final int[][] pixels; - private final WallOffset offset; - - public WallShape(int[][] pixels, WallOffset offset) - { - this.pixels = pixels; - this.offset = offset; - } - - public int[][] getPixels() - { - return pixels; - } - - public WallOffset getOffset() - { - return offset; - } - -} diff --git a/runelite-mixins/src/main/java/net/runelite/mixins/MinimapMixin.java b/runelite-mixins/src/main/java/net/runelite/mixins/MinimapMixin.java new file mode 100644 index 0000000000..404c806455 --- /dev/null +++ b/runelite-mixins/src/main/java/net/runelite/mixins/MinimapMixin.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2018, 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.mixins; + +import static net.runelite.api.Perspective.SCENE_SIZE; +import net.runelite.api.mixins.Inject; +import net.runelite.api.mixins.Mixin; +import net.runelite.rs.api.RSClient; +import net.runelite.rs.api.RSRegion; +import net.runelite.rs.api.RSSpritePixels; + +@Mixin(RSClient.class) +public abstract class MinimapMixin implements RSClient +{ + @Inject + @Override + public RSSpritePixels drawInstanceMap(int z) + { + RSSpritePixels ourSprite = createSpritePixels(new int[512 * 512], 512, 512); + RSSpritePixels theirSprite = getMinimapSprite(); + + RSRegion region = getRegion(); + int[] pixels = ourSprite.getPixels(); + byte[][][] tileSettings = getTileSettings(); + + try + { + setMinimapSprite(ourSprite); + + int var4; + for (int x = 1; x < SCENE_SIZE - 1; ++x) + { + var4 = (103 - x) * 2048 + 24628; + + for (int y = 1; y < SCENE_SIZE - 1; ++y) + { + if ((tileSettings[z][y][x] & 24) == 0) + { + region.drawTile(pixels, var4, 512, z, y, x); + } + + if (z < 3 && (tileSettings[z + 1][y][x] & 8) != 0) + { + region.drawTile(pixels, var4, 512, z + 1, y, x); + } + + var4 += 4; + } + } + + int color1 = (238 + (int) (Math.random() * 20.0D) - 10 << 16) + (238 + (int) (Math.random() * 20.0D) - 10 << 8) + (238 + (int) (Math.random() * 20.0D) - 10); + int color2 = 238 + (int) (Math.random() * 20.0D) - 10 << 16; + ourSprite.setRaster(); + + for (int y = 1; y < SCENE_SIZE - 1; ++y) + { + for (int x = 1; x < SCENE_SIZE - 1; ++x) + { + if ((tileSettings[z][x][y] & 24) == 0) + { + drawObject(z, x, y, color1, color2); + } + + if (z < 3 && (tileSettings[z + 1][x][y] & 8) != 0) + { + drawObject(z + 1, x, y, color1, color2); + } + } + } + } + finally + { + getBufferProvider().setRaster(); + setMinimapSprite(theirSprite); + } + + return ourSprite; + } +} diff --git a/runescape-api/src/main/java/net/runelite/rs/api/RSBufferProvider.java b/runescape-api/src/main/java/net/runelite/rs/api/RSBufferProvider.java index e33115af6a..8c555a2873 100644 --- a/runescape-api/src/main/java/net/runelite/rs/api/RSBufferProvider.java +++ b/runescape-api/src/main/java/net/runelite/rs/api/RSBufferProvider.java @@ -25,7 +25,10 @@ package net.runelite.rs.api; import net.runelite.api.BufferProvider; +import net.runelite.mapping.Import; public interface RSBufferProvider extends BufferProvider { + @Import("setRaster") + void setRaster(); } diff --git a/runescape-api/src/main/java/net/runelite/rs/api/RSClient.java b/runescape-api/src/main/java/net/runelite/rs/api/RSClient.java index bcebd5fa7a..b36aa765fa 100644 --- a/runescape-api/src/main/java/net/runelite/rs/api/RSClient.java +++ b/runescape-api/src/main/java/net/runelite/rs/api/RSClient.java @@ -25,8 +25,8 @@ package net.runelite.rs.api; import java.util.Map; -import net.runelite.api.BufferProvider; import net.runelite.api.Client; +import net.runelite.api.SpritePixels; import net.runelite.api.World; import net.runelite.api.widgets.Widget; import net.runelite.mapping.Construct; @@ -425,7 +425,7 @@ public interface RSClient extends RSGameEngine, Client @Import("rasterProvider") @Override - BufferProvider getBufferProvider(); + RSBufferProvider getBufferProvider(); @Import("mouseIdleTicks") @Override @@ -532,4 +532,13 @@ public interface RSClient extends RSGameEngine, Client @Construct @Override RSWorld createWorld(); + + @Import("minimapSprite") + RSSpritePixels getMinimapSprite(); + + @Import("minimapSprite") + void setMinimapSprite(SpritePixels spritePixels); + + @Import("drawObject") + void drawObject(int z, int x, int y, int randomColor1, int randomColor2); } diff --git a/runescape-api/src/main/java/net/runelite/rs/api/RSRegion.java b/runescape-api/src/main/java/net/runelite/rs/api/RSRegion.java index 41b417ba79..ed6d14c4eb 100644 --- a/runescape-api/src/main/java/net/runelite/rs/api/RSRegion.java +++ b/runescape-api/src/main/java/net/runelite/rs/api/RSRegion.java @@ -37,12 +37,6 @@ public interface RSRegion extends Region @Override Tile[][][] getTiles(); - @Import("TILE_MASK_2D") - @Override - int[][] getTileMask2d(); - - @Import("TILE_ROTATION_2D") - @Override - int[][] getTileRotation2d(); - + @Import("drawTile") + void drawTile(int[] pixels, int pixelOffset, int width, int z, int x, int y); } diff --git a/runescape-api/src/main/java/net/runelite/rs/api/RSSpritePixels.java b/runescape-api/src/main/java/net/runelite/rs/api/RSSpritePixels.java index 9d2ae3ff63..394c1c9f47 100644 --- a/runescape-api/src/main/java/net/runelite/rs/api/RSSpritePixels.java +++ b/runescape-api/src/main/java/net/runelite/rs/api/RSSpritePixels.java @@ -44,4 +44,7 @@ public interface RSSpritePixels extends SpritePixels @Import("pixels") @Override int[] getPixels(); + + @Import("setRaster") + void setRaster(); }