Search in sources :

Example 6 with InputStream

use of net.runelite.cache.io.InputStream 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 7 with InputStream

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

the class ScriptLoader method load.

public ScriptDefinition load(int id, byte[] b) {
    ScriptDefinition def = new ScriptDefinition();
    InputStream in = new InputStream(b);
    in.setOffset(in.getLength() - 2);
    int switchLength = in.readUnsignedShort();
    // 2 for switchLength + the switch data + 12 for the param/vars/stack data
    int endIdx = in.getLength() - 2 - switchLength - 12;
    in.setOffset(endIdx);
    int numOpcodes = in.readInt();
    int localIntCount = in.readUnsignedShort();
    int localStringCount = in.readUnsignedShort();
    int intStackCount = in.readUnsignedShort();
    int stringStackCount = in.readUnsignedShort();
    int numSwitches = in.readUnsignedByte();
    if (numSwitches > 0) {
        Map<Integer, Integer>[] switches = new Map[numSwitches];
        def.setSwitches(switches);
        for (int i = 0; i < numSwitches; ++i) {
            switches[i] = new HashMap<>();
            int count = in.readUnsignedShort();
            while (count-- > 0) {
                // int from stack is compared to this
                int key = in.readInt();
                // pc jumps by this
                int pcOffset = in.readInt();
                switches[i].put(key, pcOffset);
            }
        }
    }
    def.setLocalIntCount(localIntCount);
    def.setLocalStringCount(localStringCount);
    def.setIntStackCount(intStackCount);
    def.setStringStackCount(stringStackCount);
    in.setOffset(0);
    in.readStringOrNull();
    int[] instructions = new int[numOpcodes];
    int[] intOperands = new int[numOpcodes];
    String[] stringOperands = new String[numOpcodes];
    def.setInstructions(instructions);
    def.setIntOperands(intOperands);
    def.setStringOperands(stringOperands);
    int opcode;
    for (int i = 0; in.getOffset() < endIdx; instructions[i++] = opcode) {
        opcode = in.readUnsignedShort();
        if (opcode == LOAD_STRING) {
            stringOperands[i] = in.readString();
        } else if (opcode < 100 && opcode != RETURN && opcode != POP_INT && opcode != POP_STRING) {
            intOperands[i] = in.readInt();
        } else {
            intOperands[i] = in.readUnsignedByte();
        }
    }
    return def;
}
Also used : ScriptDefinition(net.runelite.cache.definitions.ScriptDefinition) InputStream(net.runelite.cache.io.InputStream) Map(java.util.Map) HashMap(java.util.HashMap)

Example 8 with InputStream

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

the class MapLoader method loadTerrain.

private void loadTerrain(MapDefinition map, byte[] buf) {
    Tile[][][] tiles = map.getTiles();
    InputStream in = new InputStream(buf);
    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] = new Tile();
                while (true) {
                    int attribute = in.readUnsignedByte();
                    if (attribute == 0) {
                        break;
                    } else if (attribute == 1) {
                        int height = in.readUnsignedByte();
                        tile.height = height;
                        break;
                    } else if (attribute <= 49) {
                        tile.attrOpcode = attribute;
                        tile.overlayId = in.readByte();
                        tile.overlayPath = (byte) ((attribute - 2) / 4);
                        tile.overlayRotation = (byte) (attribute - 2 & 3);
                    } else if (attribute <= 81) {
                        tile.settings = (byte) (attribute - 49);
                    } else {
                        tile.underlayId = (byte) (attribute - 81);
                    }
                }
            }
        }
    }
}
Also used : InputStream(net.runelite.cache.io.InputStream) Tile(net.runelite.cache.definitions.MapDefinition.Tile)

Example 9 with InputStream

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

the class NpcLoader method load.

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

Example 10 with InputStream

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

the class VarbitLoader method load.

public VarbitDefinition load(int id, byte[] b) {
    VarbitDefinition def = new VarbitDefinition();
    InputStream is = new InputStream(b);
    def.setId(id);
    for (; ; ) {
        int opcode = is.readUnsignedByte();
        if (opcode == 0) {
            break;
        }
        if (opcode == 1) {
            def.setIndex(is.readUnsignedShort());
            def.setLeastSignificantBit(is.readUnsignedByte());
            def.setMostSignificantBit(is.readUnsignedByte());
        }
    }
    return def;
}
Also used : VarbitDefinition(net.runelite.cache.definitions.VarbitDefinition) 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