Search in sources :

Example 6 with OutputStream

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

the class MapSaver method save.

public byte[] save(MapDefinition map) {
    Tile[][][] tiles = map.getTiles();
    OutputStream out = new OutputStream();
    for (int z = 0; z < Z; z++) {
        for (int x = 0; x < X; x++) {
            for (int y = 0; y < Y; y++) {
                Tile tile = tiles[z][x][y];
                if (tile.attrOpcode != 0) {
                    out.writeByte(tile.attrOpcode);
                    out.writeByte(tile.overlayId);
                }
                if (tile.settings != 0) {
                    out.writeByte(tile.settings + 49);
                }
                if (tile.underlayId != 0) {
                    out.writeByte(tile.underlayId + 81);
                }
                if (tile.height == null) {
                    out.writeByte(0);
                } else {
                    out.writeByte(1);
                    out.writeByte(tile.height);
                }
            }
        }
    }
    return out.flip();
}
Also used : OutputStream(net.runelite.cache.io.OutputStream) Tile(net.runelite.cache.definitions.MapDefinition.Tile)

Example 7 with OutputStream

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

the class ObjectSaver method save.

public byte[] save(ObjectDefinition obj) {
    OutputStream out = new OutputStream();
    if (obj.getObjectTypes() != null && obj.getObjectModels() != null) {
        out.writeByte(1);
        out.writeByte(obj.getObjectTypes().length);
        for (int i = 0; i < obj.getObjectTypes().length; ++i) {
            out.writeShort(obj.getObjectModels()[i]);
            out.writeByte(obj.getObjectTypes()[i]);
        }
    }
    if (obj.getName() != null) {
        out.writeByte(2);
        out.writeString(obj.getName());
    }
    if (obj.getObjectTypes() == null && obj.getObjectModels() != null) {
        out.writeByte(5);
        out.writeByte(obj.getObjectModels().length);
        for (int i = 0; i < obj.getObjectModels().length; ++i) {
            out.writeShort(obj.getObjectModels()[i]);
        }
    }
    out.writeByte(14);
    out.writeByte(obj.getSizeX());
    out.writeByte(15);
    out.writeByte(obj.getSizeY());
    if (obj.getInteractType() == 0 && !obj.isBlocksProjectile()) {
        out.writeByte(17);
    } else if (!obj.isBlocksProjectile()) {
        out.writeByte(18);
    }
    if (obj.getAnInt2088() != -1) {
        out.writeByte(19);
        out.writeByte(obj.getAnInt2088());
    }
    if (obj.getAnInt2105() == 0) {
        out.writeByte(21);
    }
    if (!obj.isNonFlatShading()) {
        out.writeByte(22);
    }
    if (obj.isABool2111()) {
        out.writeByte(23);
    }
    if (obj.getAnimationID() != -1) {
        out.writeByte(24);
        out.writeShort(obj.getAnimationID());
    }
    if (obj.getInteractType() == 1) {
        out.writeByte(27);
    }
    out.writeByte(28);
    out.writeByte(obj.getAnInt2069());
    out.writeByte(29);
    out.writeByte(obj.getAmbient());
    out.writeByte(39);
    out.writeByte(obj.getContrast());
    for (int i = 0; i < 5; ++i) {
        out.writeByte(30 + i);
        String action = obj.getActions()[i];
        out.writeString(action != null ? action : "Hidden");
    }
    if (obj.getRecolorToFind() != null && obj.getRecolorToReplace() != null) {
        out.writeByte(40);
        out.writeByte(obj.getRecolorToFind().length);
        for (int i = 0; i < obj.getRecolorToFind().length; ++i) {
            out.writeShort(obj.getRecolorToFind()[i]);
            out.writeShort(obj.getRecolorToReplace()[i]);
        }
    }
    if (obj.getRetextureToFind() != null && obj.getTextureToReplace() != null) {
        out.writeByte(41);
        out.writeByte(obj.getRetextureToFind().length);
        for (int i = 0; i < obj.getRetextureToFind().length; ++i) {
            out.writeShort(obj.getRetextureToFind()[i]);
            out.writeShort(obj.getTextureToReplace()[i]);
        }
    }
    if (obj.isRotated()) {
        out.writeByte(62);
    }
    if (!obj.isABool2097()) {
        out.writeByte(64);
    }
    out.writeByte(65);
    out.writeShort(obj.getModelSizeX());
    out.writeByte(66);
    out.writeShort(obj.getModelSizeHeight());
    out.writeByte(67);
    out.writeShort(obj.getModelSizeY());
    if (obj.getMapSceneID() != -1) {
        out.writeByte(68);
        out.writeShort(obj.getMapSceneID());
    }
    out.writeByte(70);
    out.writeShort(obj.getOffsetX());
    out.writeByte(71);
    out.writeShort(obj.getOffsetHeight());
    out.writeByte(72);
    out.writeShort(obj.getOffsetY());
    if (obj.isABool2104()) {
        out.writeByte(73);
    }
    if (obj.isSolid()) {
        out.writeByte(74);
    }
    if (obj.getAnInt2106() != -1) {
        out.writeByte(75);
        out.writeByte(obj.getAnInt2106());
    }
    if (obj.getAnInt2110() != -1) {
        out.writeByte(78);
        out.writeShort(obj.getAnInt2110());
        out.writeByte(obj.getAnInt2083());
    }
    if (obj.getAnIntArray2084() != null) {
        out.writeByte(79);
        out.writeShort(obj.getAnInt2112());
        out.writeShort(obj.getAnInt2113());
        out.writeByte(obj.getAnInt2083());
        out.writeByte(obj.getAnIntArray2084().length);
        for (int i : obj.getAnIntArray2084()) {
            out.writeShort(i);
        }
    }
    if (obj.getAnInt2105() != -1) {
        out.writeByte(81);
        out.writeByte(obj.getAnInt2105() / 256);
    }
    if (obj.getMapAreaId() != -1) {
        out.writeByte(82);
        out.writeShort(obj.getMapAreaId());
    }
    if (obj.getConfigChangeDest() != null) {
        out.writeByte(92);
        out.writeShort(obj.getVarpID());
        out.writeShort(obj.getConfigId());
        int[] c = obj.getConfigChangeDest();
        out.writeShort(c[c.length - 1]);
        out.writeByte(c.length - 2);
        for (int i = 0; i <= c.length - 2; ++i) {
            out.writeShort(c[i]);
        }
    }
    if (obj.getParams() != null) {
        out.writeByte(249);
        out.writeByte(obj.getParams().size());
        for (Map.Entry<Integer, Object> entry : obj.getParams().entrySet()) {
            out.writeByte(entry.getValue() instanceof String ? 1 : 0);
            out.write24BitInt(entry.getKey());
            if (entry.getValue() instanceof String) {
                out.writeString((String) entry.getValue());
            } else {
                out.writeInt((Integer) entry.getValue());
            }
        }
    }
    out.writeByte(0);
    return out.flip();
}
Also used : OutputStream(net.runelite.cache.io.OutputStream) Map(java.util.Map)

Example 8 with OutputStream

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

the class ScriptSaver method save.

public byte[] save(ScriptDefinition script) {
    int[] instructions = script.getInstructions();
    int[] intOperands = script.getIntOperands();
    String[] stringOperands = script.getStringOperands();
    Map<Integer, Integer>[] switches = script.getSwitches();
    OutputStream out = new OutputStream();
    // null string
    out.writeByte(0);
    for (int i = 0; i < instructions.length; ++i) {
        int opcode = instructions[i];
        out.writeShort(opcode);
        if (opcode == LOAD_STRING) {
            out.writeString(stringOperands[i]);
        } else if (opcode < 100 && opcode != RETURN && opcode != POP_INT && opcode != POP_STRING) {
            out.writeInt(intOperands[i]);
        } else {
            out.writeByte(intOperands[i]);
        }
    }
    out.writeInt(instructions.length);
    out.writeShort(script.getLocalIntCount());
    out.writeShort(script.getLocalStringCount());
    out.writeShort(script.getIntStackCount());
    out.writeShort(script.getStringStackCount());
    int switchStart = out.getOffset();
    if (switches == null) {
        out.writeByte(0);
    } else {
        out.writeByte(switches.length);
        for (Map<Integer, Integer> s : switches) {
            out.writeShort(s.size());
            for (Entry<Integer, Integer> e : s.entrySet()) {
                out.writeInt(e.getKey());
                out.writeInt(e.getValue());
            }
        }
    }
    int switchLength = out.getOffset() - switchStart;
    out.writeShort(switchLength);
    return out.flip();
}
Also used : OutputStream(net.runelite.cache.io.OutputStream) Map(java.util.Map)

Example 9 with OutputStream

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

the class Container method compress.

public void compress(byte[] data, int[] keys) throws IOException {
    OutputStream stream = new OutputStream();
    byte[] compressedData;
    int length;
    switch(compression) {
        case CompressionType.NONE:
            compressedData = data;
            length = compressedData.length;
            break;
        case CompressionType.BZ2:
            compressedData = concat(Ints.toByteArray(data.length), BZip2.compress(data));
            length = compressedData.length - 4;
            break;
        case CompressionType.GZ:
            compressedData = concat(Ints.toByteArray(data.length), GZip.compress(data));
            length = compressedData.length - 4;
            break;
        default:
            throw new RuntimeException("Unknown compression type");
    }
    compressedData = encrypt(compressedData, compressedData.length, keys);
    stream.writeByte(compression);
    stream.writeInt(length);
    stream.writeBytes(compressedData);
    if (revision != -1) {
        stream.writeShort(revision);
    }
    this.data = stream.flip();
}
Also used : OutputStream(net.runelite.cache.io.OutputStream)

Example 10 with OutputStream

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

the class IndexData method writeIndexData.

public byte[] writeIndexData() {
    OutputStream stream = new OutputStream();
    stream.writeByte(protocol);
    if (protocol >= 6) {
        stream.writeInt(this.revision);
    }
    stream.writeByte(named ? 1 : 0);
    if (protocol >= 7) {
        stream.writeBigSmart(this.archives.length);
    } else {
        stream.writeShort(this.archives.length);
    }
    for (int i = 0; i < this.archives.length; ++i) {
        ArchiveData a = this.archives[i];
        int archive = a.getId();
        if (i != 0) {
            ArchiveData prev = this.archives[i - 1];
            archive -= prev.getId();
        }
        if (protocol >= 7) {
            stream.writeBigSmart(archive);
        } else {
            stream.writeShort(archive);
        }
    }
    if (named) {
        for (int i = 0; i < this.archives.length; ++i) {
            ArchiveData a = this.archives[i];
            stream.writeInt(a.getNameHash());
        }
    }
    for (int i = 0; i < this.archives.length; ++i) {
        ArchiveData a = this.archives[i];
        stream.writeInt(a.getCrc());
    }
    for (int i = 0; i < this.archives.length; ++i) {
        ArchiveData a = this.archives[i];
        stream.writeInt(a.getRevision());
    }
    for (int i = 0; i < this.archives.length; ++i) {
        ArchiveData a = this.archives[i];
        int len = a.getFiles().length;
        if (protocol >= 7) {
            stream.writeBigSmart(len);
        } else {
            stream.writeShort(len);
        }
    }
    for (int i = 0; i < this.archives.length; ++i) {
        ArchiveData a = this.archives[i];
        for (int j = 0; j < a.getFiles().length; ++j) {
            FileData file = a.getFiles()[j];
            int offset = file.getId();
            if (j != 0) {
                FileData prev = a.getFiles()[j - 1];
                offset -= prev.getId();
            }
            if (protocol >= 7) {
                stream.writeBigSmart(offset);
            } else {
                stream.writeShort(offset);
            }
        }
    }
    if (named) {
        for (int i = 0; i < this.archives.length; ++i) {
            ArchiveData a = this.archives[i];
            for (int j = 0; j < a.getFiles().length; ++j) {
                FileData file = a.getFiles()[j];
                stream.writeInt(file.getNameHash());
            }
        }
    }
    return stream.flip();
}
Also used : OutputStream(net.runelite.cache.io.OutputStream)

Aggregations

OutputStream (net.runelite.cache.io.OutputStream)11 Map (java.util.Map)3 ArrayList (java.util.ArrayList)1 Tile (net.runelite.cache.definitions.MapDefinition.Tile)1 Location (net.runelite.cache.region.Location)1