Search in sources :

Example 11 with InputStream

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

the class SpotAnimLoader method load.

public SpotAnimDefinition load(int id, byte[] b) {
    SpotAnimDefinition def = new SpotAnimDefinition();
    InputStream is = new InputStream(b);
    def.id = id;
    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) SpotAnimDefinition(net.runelite.cache.definitions.SpotAnimDefinition)

Example 12 with InputStream

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

the class TextureLoader method load.

public TextureDefinition load(int id, byte[] b) {
    TextureDefinition def = new TextureDefinition();
    InputStream is = new InputStream(b);
    def.field1777 = is.readUnsignedShort();
    def.field1778 = is.readByte() != 0;
    def.setId(id);
    int count = is.readUnsignedByte();
    int[] files = new int[count];
    for (int i = 0; i < count; ++i) files[i] = is.readUnsignedShort();
    def.setFileIds(files);
    if (count > 1) {
        def.field1780 = new int[count - 1];
        for (int var3 = 0; var3 < count - 1; ++var3) {
            def.field1780[var3] = is.readUnsignedByte();
        }
    }
    if (count > 1) {
        def.field1781 = new int[count - 1];
        for (int var3 = 0; var3 < count - 1; ++var3) {
            def.field1781[var3] = is.readUnsignedByte();
        }
    }
    def.field1786 = new int[count];
    for (int var3 = 0; var3 < count; ++var3) {
        def.field1786[var3] = is.readInt();
    }
    def.field1783 = is.readUnsignedByte();
    def.field1782 = is.readUnsignedByte();
    return def;
}
Also used : InputStream(net.runelite.cache.io.InputStream) TextureDefinition(net.runelite.cache.definitions.TextureDefinition)

Example 13 with InputStream

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

the class EnumLoader method load.

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

Example 14 with InputStream

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

the class FrameLoader method load.

public FrameDefinition load(FramemapDefinition framemap, byte[] b) {
    FrameDefinition def = new FrameDefinition();
    InputStream in = new InputStream(b);
    InputStream data = new InputStream(b);
    def.framemap = framemap;
    int framemapArchiveIndex = in.readUnsignedShort();
    int length = in.readUnsignedByte();
    // framemapArchiveIndex + length + data
    data.skip(3 + length);
    int[] indexFrameIds = new int[500];
    int[] scratchTranslatorX = new int[500];
    int[] scratchTranslatorY = new int[500];
    int[] scratchTranslatorZ = new int[500];
    int lastI = -1;
    int index = 0;
    for (int i = 0; i < length; ++i) {
        int var9 = in.readUnsignedByte();
        if (var9 <= 0) {
            continue;
        }
        if (def.framemap.field1456[i] != 0) {
            for (int var10 = i - 1; var10 > lastI; --var10) {
                if (def.framemap.field1456[var10] == 0) {
                    indexFrameIds[index] = var10;
                    scratchTranslatorX[index] = 0;
                    scratchTranslatorY[index] = 0;
                    scratchTranslatorZ[index] = 0;
                    ++index;
                    break;
                }
            }
        }
        indexFrameIds[index] = i;
        short var11 = 0;
        if (def.framemap.field1456[i] == 3) {
            var11 = 128;
        }
        if ((var9 & 1) != 0) {
            scratchTranslatorX[index] = data.readShortSmart();
        } else {
            scratchTranslatorX[index] = var11;
        }
        if ((var9 & 2) != 0) {
            scratchTranslatorY[index] = data.readShortSmart();
        } else {
            scratchTranslatorY[index] = var11;
        }
        if ((var9 & 4) != 0) {
            scratchTranslatorZ[index] = data.readShortSmart();
        } else {
            scratchTranslatorZ[index] = var11;
        }
        lastI = i;
        ++index;
        if (def.framemap.field1456[i] == 5) {
            def.field1315 = true;
        }
    }
    if (data.getOffset() != b.length) {
        throw new RuntimeException();
    }
    def.field1310 = index;
    def.indexFrameIds = new int[index];
    def.translator_x = new int[index];
    def.translator_y = new int[index];
    def.translator_z = new int[index];
    for (int i = 0; i < index; ++i) {
        def.indexFrameIds[i] = indexFrameIds[i];
        def.translator_x[i] = scratchTranslatorX[i];
        def.translator_y[i] = scratchTranslatorY[i];
        def.translator_z[i] = scratchTranslatorZ[i];
    }
    return def;
}
Also used : FrameDefinition(net.runelite.cache.definitions.FrameDefinition) InputStream(net.runelite.cache.io.InputStream)

Example 15 with InputStream

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

the class ArchiveFiles method loadContents.

public void loadContents(byte[] data) {
    logger.trace("Loading contents of archive ({} files)", files.size());
    assert !this.getFiles().isEmpty();
    if (this.getFiles().size() == 1) {
        this.getFiles().get(0).setContents(data);
        return;
    }
    int filesCount = this.getFiles().size();
    InputStream stream = new InputStream(data);
    stream.setOffset(stream.getLength() - 1);
    int chunks = stream.readUnsignedByte();
    // -1 for chunks count + one int per file slot per chunk
    stream.setOffset(stream.getLength() - 1 - chunks * filesCount * 4);
    int[][] chunkSizes = new int[filesCount][chunks];
    int[] filesSize = new int[filesCount];
    for (int chunk = 0; chunk < chunks; ++chunk) {
        int chunkSize = 0;
        for (int id = 0; id < filesCount; ++id) {
            int delta = stream.readInt();
            // size of this chunk
            chunkSize += delta;
            // store size of chunk
            chunkSizes[id][chunk] = chunkSize;
            // add chunk size to file size
            filesSize[id] += chunkSize;
        }
    }
    byte[][] fileContents = new byte[filesCount][];
    int[] fileOffsets = new int[filesCount];
    for (int i = 0; i < filesCount; ++i) {
        fileContents[i] = new byte[filesSize[i]];
    }
    // the file data is at the beginning of the stream
    stream.setOffset(0);
    for (int chunk = 0; chunk < chunks; ++chunk) {
        for (int id = 0; id < filesCount; ++id) {
            int chunkSize = chunkSizes[id][chunk];
            stream.readBytes(fileContents[id], fileOffsets[id], chunkSize);
            fileOffsets[id] += chunkSize;
        }
    }
    for (int i = 0; i < filesCount; ++i) {
        FSFile f = this.getFiles().get(i);
        f.setContents(fileContents[i]);
    }
}
Also used : 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