Search in sources :

Example 1 with ObjectDefinition

use of net.runelite.cache.definitions.ObjectDefinition in project runelite by runelite.

the class MapImageDumper method drawObjects.

private void drawObjects(BufferedImage image, int drawBaseX, int drawBaseY, Region region, int z) {
    Graphics2D graphics = image.createGraphics();
    for (Location location : region.getLocations()) {
        int rotation = location.getOrientation();
        int type = location.getType();
        int localX = location.getPosition().getX() - region.getBaseX();
        int localY = location.getPosition().getY() - region.getBaseY();
        boolean isBridge = (region.getTileSetting(1, localX, localY) & 2) != 0;
        if (location.getPosition().getZ() == z + 1) {
            if (!isBridge) {
                continue;
            }
        } else if (location.getPosition().getZ() == z) {
            if (isBridge) {
                continue;
            }
            if ((region.getTileSetting(z, localX, localY) & 24) != 0) {
                continue;
            }
        } else {
            continue;
        }
        ObjectDefinition object = findObject(location.getId());
        int drawX = (drawBaseX + localX) * MAP_SCALE;
        int drawY = (drawBaseY + (Region.Y - 1 - localY)) * MAP_SCALE;
        if (type >= 0 && type <= 3) {
            // this is a wall
            int hash = (localY << 7) + localX + (location.getId() << 14) + 0x4000_0000;
            if (object.getAnInt2088() == 0) {
                hash -= Integer.MIN_VALUE;
            }
            int rgb = wallColor;
            if (hash > 0) {
                rgb = doorColor;
            }
            if (object.getMapSceneID() != -1) {
                Image spriteImage = scaledMapIcons.get(object.getMapSceneID());
                graphics.drawImage(spriteImage, drawX * MAP_SCALE, drawY * MAP_SCALE, null);
            } else {
                if (type == 0 || type == 2) {
                    if (rotation == 0) {
                        image.setRGB(drawX + 0, drawY + 0, rgb);
                        image.setRGB(drawX + 0, drawY + 1, rgb);
                        image.setRGB(drawX + 0, drawY + 2, rgb);
                        image.setRGB(drawX + 0, drawY + 3, rgb);
                    } else if (rotation == 1) {
                        image.setRGB(drawX + 0, drawY + 0, rgb);
                        image.setRGB(drawX + 1, drawY + 0, rgb);
                        image.setRGB(drawX + 2, drawY + 0, rgb);
                        image.setRGB(drawX + 3, drawY + 0, rgb);
                    } else if (rotation == 2) {
                        image.setRGB(drawX + 3, drawY + 0, rgb);
                        image.setRGB(drawX + 3, drawY + 1, rgb);
                        image.setRGB(drawX + 3, drawY + 2, rgb);
                        image.setRGB(drawX + 3, drawY + 3, rgb);
                    } else if (rotation == 3) {
                        image.setRGB(drawX + 0, drawY + 3, rgb);
                        image.setRGB(drawX + 1, drawY + 3, rgb);
                        image.setRGB(drawX + 2, drawY + 3, rgb);
                        image.setRGB(drawX + 3, drawY + 3, rgb);
                    }
                }
                if (type == 3) {
                    if (rotation == 0) {
                        image.setRGB(drawX + 0, drawY + 0, rgb);
                    } else if (rotation == 1) {
                        image.setRGB(drawX + 3, drawY + 0, rgb);
                    } else if (rotation == 2) {
                        image.setRGB(drawX + 3, drawY + 3, rgb);
                    } else if (rotation == 3) {
                        image.setRGB(drawX + 0, drawY + 3, rgb);
                    }
                }
                if (type == 2) {
                    if (rotation == 3) {
                        image.setRGB(drawX + 0, drawY + 0, rgb);
                        image.setRGB(drawX + 0, drawY + 1, rgb);
                        image.setRGB(drawX + 0, drawY + 2, rgb);
                        image.setRGB(drawX + 0, drawY + 3, rgb);
                    } else if (rotation == 0) {
                        image.setRGB(drawX + 0, drawY + 0, rgb);
                        image.setRGB(drawX + 1, drawY + 0, rgb);
                        image.setRGB(drawX + 2, drawY + 0, rgb);
                        image.setRGB(drawX + 3, drawY + 0, rgb);
                    } else if (rotation == 1) {
                        image.setRGB(drawX + 3, drawY + 0, rgb);
                        image.setRGB(drawX + 3, drawY + 1, rgb);
                        image.setRGB(drawX + 3, drawY + 2, rgb);
                        image.setRGB(drawX + 3, drawY + 3, rgb);
                    } else if (rotation == 2) {
                        image.setRGB(drawX + 0, drawY + 3, rgb);
                        image.setRGB(drawX + 1, drawY + 3, rgb);
                        image.setRGB(drawX + 2, drawY + 3, rgb);
                        image.setRGB(drawX + 3, drawY + 3, rgb);
                    }
                }
            }
        } else if (type == 9) {
            if (object.getMapSceneID() != -1) {
                Image spriteImage = scaledMapIcons.get(object.getMapSceneID());
                graphics.drawImage(spriteImage, drawX, drawY, null);
                continue;
            }
            int hash = (localY << 7) + localX + (location.getId() << 14) + 0x4000_0000;
            if (object.getAnInt2088() == 0) {
                hash -= Integer.MIN_VALUE;
            }
            if ((hash >> 29 & 3) != 2) {
                continue;
            }
            int rgb = 0xEE_EEEE;
            if (hash > 0) {
                rgb = 0xEE_0000;
            }
            if (rotation != 0 && rotation != 2) {
                image.setRGB(drawX + 0, drawY + 0, rgb);
                image.setRGB(drawX + 1, drawY + 1, rgb);
                image.setRGB(drawX + 2, drawY + 2, rgb);
                image.setRGB(drawX + 3, drawY + 3, rgb);
            } else {
                image.setRGB(drawX + 0, drawY + 3, rgb);
                image.setRGB(drawX + 1, drawY + 2, rgb);
                image.setRGB(drawX + 2, drawY + 1, rgb);
                image.setRGB(drawX + 3, drawY + 0, rgb);
            }
        } else if (type == 22 || (type >= 9 && type <= 11)) {
            // ground object
            if (object.getMapSceneID() != -1) {
                Image spriteImage = scaledMapIcons.get(object.getMapSceneID());
                graphics.drawImage(spriteImage, drawX, drawY, null);
            }
        }
    }
    graphics.dispose();
}
Also used : ObjectDefinition(net.runelite.cache.definitions.ObjectDefinition) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) Location(net.runelite.cache.region.Location)

Example 2 with ObjectDefinition

use of net.runelite.cache.definitions.ObjectDefinition in project runelite by runelite.

the class ObjectLoader method load.

public ObjectDefinition load(int id, byte[] b) {
    ObjectDefinition def = new ObjectDefinition();
    InputStream is = new InputStream(b);
    def.setId(id);
    for (; ; ) {
        int opcode = is.readUnsignedByte();
        if (opcode == 0) {
            break;
        }
        processOp(opcode, def, is);
    }
    post(def);
    return def;
}
Also used : InputStream(net.runelite.cache.io.InputStream) ObjectDefinition(net.runelite.cache.definitions.ObjectDefinition)

Example 3 with ObjectDefinition

use of net.runelite.cache.definitions.ObjectDefinition in project runelite by runelite.

the class ObjectManager method java.

public void java(File java) throws IOException {
    System.setProperty("line.separator", "\n");
    java.mkdirs();
    File targ = new File(java, "ObjectID.java");
    try (PrintWriter fw = new PrintWriter(targ)) {
        fw.println("/* This file is automatically generated. Do not edit. */");
        fw.println("package net.runelite.api;");
        fw.println("");
        fw.println("public final class ObjectID");
        fw.println("{");
        for (ObjectDefinition def : objects.values()) {
            String name;
            if (def.getName().equalsIgnoreCase("NULL")) {
                name = namer.name("NULL", def.getId());
            } else {
                name = namer.name(def.getName(), def.getId());
            }
            if (name == null) {
                continue;
            }
            fw.println("	public static final int " + name + " = " + def.getId() + ";");
        }
        fw.println("}");
    }
}
Also used : ObjectDefinition(net.runelite.cache.definitions.ObjectDefinition) File(java.io.File) FSFile(net.runelite.cache.fs.FSFile) PrintWriter(java.io.PrintWriter)

Example 4 with ObjectDefinition

use of net.runelite.cache.definitions.ObjectDefinition in project runelite by runelite.

the class ObjectManager method load.

public void load() throws IOException {
    ObjectLoader loader = new ObjectLoader();
    Storage storage = store.getStorage();
    Index index = store.getIndex(IndexType.CONFIGS);
    Archive archive = index.getArchive(ConfigType.OBJECT.getId());
    byte[] archiveData = storage.loadArchive(archive);
    ArchiveFiles files = archive.getFiles(archiveData);
    for (FSFile f : files.getFiles()) {
        ObjectDefinition def = loader.load(f.getFileId(), f.getContents());
        objects.put(f.getFileId(), def);
    }
}
Also used : Storage(net.runelite.cache.fs.Storage) Archive(net.runelite.cache.fs.Archive) ArchiveFiles(net.runelite.cache.fs.ArchiveFiles) ObjectLoader(net.runelite.cache.definitions.loaders.ObjectLoader) Index(net.runelite.cache.fs.Index) ObjectDefinition(net.runelite.cache.definitions.ObjectDefinition) FSFile(net.runelite.cache.fs.FSFile)

Example 5 with ObjectDefinition

use of net.runelite.cache.definitions.ObjectDefinition in project runelite by runelite.

the class ModelViewer method drawLocations.

private static void drawLocations(Region region) {
    for (Location location : region.getLocations()) {
        int id = location.getId();
        ObjectDefinition object = getObject(id);
        if (object == null || object.getObjectModels() == null) {
            continue;
        }
        Position objectPos = location.getPosition();
        if (location.getPosition().getZ() != 0) {
            continue;
        }
        int regionX = objectPos.getX() - region.getBaseX();
        int regionY = objectPos.getY() - region.getBaseY();
        int height = -region.getTileHeight(objectPos.getZ(), regionX, regionY) / HEIGHT_MOD;
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        // TILE_SCALE/2 to draw the object from the center of the tile it is on
        GL11.glTranslatef(regionX * TILE_SCALE + (TILE_SCALE / 2), height, -regionY * TILE_SCALE - (TILE_SCALE / 2));
        for (int i = 0; i < object.getObjectModels().length; ++i) {
            ModelDefinition md = ModelManager.getModel(object.getObjectModels()[i], object, location);
            if (object.getObjectTypes() != null && object.getObjectTypes()[i] != location.getType()) {
                continue;
            }
            drawModel(md, object.getRecolorToFind(), object.getRecolorToReplace());
        }
        GL11.glTranslatef(-regionX * TILE_SCALE - (TILE_SCALE / 2), -height, regionY * TILE_SCALE + (TILE_SCALE / 2));
        GL11.glPopMatrix();
    }
}
Also used : Position(net.runelite.cache.region.Position) ModelDefinition(net.runelite.cache.definitions.ModelDefinition) ObjectDefinition(net.runelite.cache.definitions.ObjectDefinition) Location(net.runelite.cache.region.Location)

Aggregations

ObjectDefinition (net.runelite.cache.definitions.ObjectDefinition)10 FSFile (net.runelite.cache.fs.FSFile)4 Location (net.runelite.cache.region.Location)4 BufferedImage (java.awt.image.BufferedImage)3 Gson (com.google.gson.Gson)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 ModelDefinition (net.runelite.cache.definitions.ModelDefinition)2 ObjectLoader (net.runelite.cache.definitions.loaders.ObjectLoader)2 ArchiveFiles (net.runelite.cache.fs.ArchiveFiles)2 Position (net.runelite.cache.region.Position)2 Color (java.awt.Color)1 Graphics2D (java.awt.Graphics2D)1 Image (java.awt.Image)1 FileNotFoundException (java.io.FileNotFoundException)1 PrintWriter (java.io.PrintWriter)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1