Search in sources :

Example 21 with InputStream

use of net.runelite.cache.io.InputStream in project runelite by runelite.

the class SpriteLoader method load.

public SpriteDefinition[] load(int id, byte[] b) {
    InputStream is = new InputStream(b);
    is.setOffset(is.getLength() - 2);
    int spriteCount = is.readUnsignedShort();
    SpriteDefinition[] sprites = new SpriteDefinition[spriteCount];
    // 2 for size
    // 5 for width, height, palette length
    // + 8 bytes per sprite for offset x/y, width, and height
    is.setOffset(is.getLength() - 7 - spriteCount * 8);
    // max width and height
    int width = is.readUnsignedShort();
    int height = is.readUnsignedShort();
    int paletteLength = is.readUnsignedByte() + 1;
    for (int i = 0; i < spriteCount; ++i) {
        sprites[i] = new SpriteDefinition();
        sprites[i].setId(id);
        sprites[i].setFrame(i);
        sprites[i].setMaxWidth(width);
        sprites[i].setMaxHeight(height);
    }
    for (int i = 0; i < spriteCount; ++i) {
        sprites[i].setOffsetX(is.readUnsignedShort());
    }
    for (int i = 0; i < spriteCount; ++i) {
        sprites[i].setOffsetY(is.readUnsignedShort());
    }
    for (int i = 0; i < spriteCount; ++i) {
        sprites[i].setWidth(is.readUnsignedShort());
    }
    for (int i = 0; i < spriteCount; ++i) {
        sprites[i].setHeight(is.readUnsignedShort());
    }
    // same as above + 3 bytes for each palette entry, except for the first one (which is transparent)
    is.setOffset(is.getLength() - 7 - spriteCount * 8 - (paletteLength - 1) * 3);
    int[] palette = new int[paletteLength];
    for (int i = 1; i < paletteLength; ++i) {
        palette[i] = is.read24BitInt();
        if (palette[i] == 0) {
            palette[i] = 1;
        }
    }
    is.setOffset(0);
    for (int i = 0; i < spriteCount; ++i) {
        SpriteDefinition def = sprites[i];
        int spriteWidth = def.getWidth();
        int spriteHeight = def.getHeight();
        int dimension = spriteWidth * spriteHeight;
        byte[] pixelPaletteIndicies = new byte[dimension];
        byte[] pixelAlphas = new byte[dimension];
        def.pixelIdx = pixelPaletteIndicies;
        def.palette = palette;
        int flags = is.readUnsignedByte();
        if ((flags & FLAG_VERTICAL) == 0) {
            // read horizontally
            for (int j = 0; j < dimension; ++j) {
                pixelPaletteIndicies[j] = is.readByte();
            }
        } else {
            // read vertically
            for (int j = 0; j < spriteWidth; ++j) {
                for (int k = 0; k < spriteHeight; ++k) {
                    pixelPaletteIndicies[spriteWidth * k + j] = is.readByte();
                }
            }
        }
        // read alphas
        if ((flags & FLAG_ALPHA) != 0) {
            if ((flags & FLAG_VERTICAL) == 0) {
                // read horizontally
                for (int j = 0; j < dimension; ++j) {
                    pixelAlphas[j] = is.readByte();
                }
            } else {
                // read vertically
                for (int j = 0; j < spriteWidth; ++j) {
                    for (int k = 0; k < spriteHeight; ++k) {
                        pixelAlphas[spriteWidth * k + j] = is.readByte();
                    }
                }
            }
        } else {
            // everything non-zero is opaque
            for (int j = 0; j < dimension; ++j) {
                int index = pixelPaletteIndicies[j];
                if (index != 0)
                    pixelAlphas[j] = (byte) 0xFF;
            }
        }
        int[] pixels = new int[dimension];
        // build argb pixels from palette/alphas
        for (int j = 0; j < dimension; ++j) {
            int index = pixelPaletteIndicies[j] & 0xFF;
            pixels[j] = palette[index] | (pixelAlphas[j] << 24);
        }
        def.setPixels(pixels);
    }
    return sprites;
}
Also used : InputStream(net.runelite.cache.io.InputStream) SpriteDefinition(net.runelite.cache.definitions.SpriteDefinition)

Example 22 with InputStream

use of net.runelite.cache.io.InputStream in project runelite by runelite.

the class TrackLoader method load.

public TrackDefinition load(byte[] b) {
    TrackDefinition def = new TrackDefinition();
    load(def, new InputStream(b));
    return def;
}
Also used : TrackDefinition(net.runelite.cache.definitions.TrackDefinition) InputStream(net.runelite.cache.io.InputStream)

Example 23 with InputStream

use of net.runelite.cache.io.InputStream in project runelite by runelite.

the class InventoryLoader method load.

public InventoryDefinition load(int id, byte[] b) {
    InventoryDefinition def = new InventoryDefinition();
    def.id = id;
    InputStream is = new InputStream(b);
    while (true) {
        int opcode = is.readUnsignedByte();
        if (opcode == 0) {
            break;
        }
        if (opcode == 2) {
            def.size = is.readUnsignedShort();
        }
    }
    return def;
}
Also used : InputStream(net.runelite.cache.io.InputStream) InventoryDefinition(net.runelite.cache.definitions.InventoryDefinition)

Example 24 with InputStream

use of net.runelite.cache.io.InputStream in project runelite by runelite.

the class ItemLoader method load.

public ItemDefinition load(int id, byte[] b) {
    ItemDefinition def = new ItemDefinition(id);
    InputStream is = new InputStream(b);
    while (true) {
        int opcode = is.readUnsignedByte();
        if (opcode == 0) {
            break;
        }
        this.decodeValues(opcode, def, is);
    }
    return def;
}
Also used : InputStream(net.runelite.cache.io.InputStream) ItemDefinition(net.runelite.cache.definitions.ItemDefinition)

Example 25 with InputStream

use of net.runelite.cache.io.InputStream in project runelite by runelite.

the class OverlayLoader method load.

public OverlayDefinition load(int id, byte[] b) {
    OverlayDefinition def = new OverlayDefinition();
    InputStream is = new InputStream(b);
    def.setId(id);
    for (; ; ) {
        int opcode = is.readUnsignedByte();
        if (opcode == 0) {
            break;
        }
        if (opcode == 1) {
            int color = is.read24BitInt();
            def.setRgbColor(color);
        } else if (opcode == 2) {
            int texture = is.readUnsignedByte();
            def.setTexture(texture);
        } else if (opcode == 5) {
            def.setHideUnderlay(false);
        } else if (opcode == 7) {
            int secondaryColor = is.read24BitInt();
            def.setSecondaryRgbColor(secondaryColor);
        }
    }
    def.calculateHsl();
    return def;
}
Also used : OverlayDefinition(net.runelite.cache.definitions.OverlayDefinition) InputStream(net.runelite.cache.io.InputStream)

Aggregations

InputStream (net.runelite.cache.io.InputStream)28 Position (net.runelite.cache.region.Position)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 AreaDefinition (net.runelite.cache.definitions.AreaDefinition)1 EnumDefinition (net.runelite.cache.definitions.EnumDefinition)1 FrameDefinition (net.runelite.cache.definitions.FrameDefinition)1 FramemapDefinition (net.runelite.cache.definitions.FramemapDefinition)1 InterfaceDefinition (net.runelite.cache.definitions.InterfaceDefinition)1 InventoryDefinition (net.runelite.cache.definitions.InventoryDefinition)1 ItemDefinition (net.runelite.cache.definitions.ItemDefinition)1 KitDefinition (net.runelite.cache.definitions.KitDefinition)1 Tile (net.runelite.cache.definitions.MapDefinition.Tile)1 NpcDefinition (net.runelite.cache.definitions.NpcDefinition)1 ObjectDefinition (net.runelite.cache.definitions.ObjectDefinition)1 OverlayDefinition (net.runelite.cache.definitions.OverlayDefinition)1 ScriptDefinition (net.runelite.cache.definitions.ScriptDefinition)1 SequenceDefinition (net.runelite.cache.definitions.SequenceDefinition)1 SpotAnimDefinition (net.runelite.cache.definitions.SpotAnimDefinition)1