Search in sources :

Example 16 with InputStream

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

the class Container method decompress.

public static Container decompress(byte[] b, int[] keys) throws IOException {
    InputStream stream = new InputStream(b);
    int compression = stream.readUnsignedByte();
    int compressedLength = stream.readInt();
    if (compressedLength < 0 || compressedLength > 1000000) {
        throw new RuntimeException("Invalid data");
    }
    Crc32 crc32 = new Crc32();
    // compression + length
    crc32.update(b, 0, 5);
    byte[] data;
    int revision = -1;
    switch(compression) {
        case CompressionType.NONE:
            {
                byte[] encryptedData = new byte[compressedLength];
                stream.readBytes(encryptedData, 0, compressedLength);
                crc32.update(encryptedData, 0, compressedLength);
                byte[] decryptedData = decrypt(encryptedData, encryptedData.length, keys);
                if (stream.remaining() >= 2) {
                    revision = stream.readUnsignedShort();
                    assert revision != -1;
                }
                data = decryptedData;
                break;
            }
        case CompressionType.BZ2:
            {
                byte[] encryptedData = new byte[compressedLength + 4];
                stream.readBytes(encryptedData);
                crc32.update(encryptedData, 0, encryptedData.length);
                byte[] decryptedData = decrypt(encryptedData, encryptedData.length, keys);
                if (stream.remaining() >= 2) {
                    revision = stream.readUnsignedShort();
                    assert revision != -1;
                }
                stream = new InputStream(decryptedData);
                int decompressedLength = stream.readInt();
                data = BZip2.decompress(stream.getRemaining(), compressedLength);
                if (data == null) {
                    return null;
                }
                assert data.length == decompressedLength;
                break;
            }
        case CompressionType.GZ:
            {
                byte[] encryptedData = new byte[compressedLength + 4];
                stream.readBytes(encryptedData);
                crc32.update(encryptedData, 0, encryptedData.length);
                byte[] decryptedData = decrypt(encryptedData, encryptedData.length, keys);
                if (stream.remaining() >= 2) {
                    revision = stream.readUnsignedShort();
                    assert revision != -1;
                }
                stream = new InputStream(decryptedData);
                int decompressedLength = stream.readInt();
                data = GZip.decompress(stream.getRemaining(), compressedLength);
                if (data == null) {
                    return null;
                }
                assert data.length == decompressedLength;
                break;
            }
        default:
            throw new RuntimeException("Unknown decompression type");
    }
    Container container = new Container(compression, revision);
    container.data = data;
    container.crc = crc32.getHash();
    return container;
}
Also used : InputStream(net.runelite.cache.io.InputStream) Crc32(net.runelite.cache.util.Crc32)

Example 17 with InputStream

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

the class UnderlayLoader method load.

public UnderlayDefinition load(int id, byte[] b) {
    UnderlayDefinition def = new UnderlayDefinition();
    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.setColor(color);
        }
    }
    def.calculateHsl();
    return def;
}
Also used : InputStream(net.runelite.cache.io.InputStream) UnderlayDefinition(net.runelite.cache.definitions.UnderlayDefinition)

Example 18 with InputStream

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

the class WorldMapLoader method load.

public WorldMapDefinition load(byte[] b, int fileId) {
    WorldMapDefinition def = new WorldMapDefinition();
    InputStream in = new InputStream(b);
    def.fileId = fileId;
    def.safeName = in.readString();
    def.name = in.readString();
    int packedPos = in.readInt();
    if (packedPos == -1) {
        def.position = new Position(-1, -1, -1);
    } else {
        int y = packedPos >> 28 & 3;
        int x = packedPos >> 14 & 16383;
        int z = packedPos & 16383;
        def.position = new Position(x, y, z);
    }
    def.field450 = in.readInt();
    in.readUnsignedByte();
    def.field457 = in.readUnsignedByte() == 1;
    def.field451 = in.readUnsignedByte();
    int var3 = in.readUnsignedByte();
    def.field458 = new LinkedList();
    for (int var4 = 0; var4 < var3; ++var4) {
        def.field458.add(this.loadType(in));
    }
    return def;
}
Also used : Position(net.runelite.cache.region.Position) InputStream(net.runelite.cache.io.InputStream) WorldMapDefinition(net.runelite.cache.definitions.WorldMapDefinition) LinkedList(java.util.LinkedList)

Example 19 with InputStream

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

the class SoundEffectLoader method load.

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

Example 20 with InputStream

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

the class SequenceLoader method load.

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