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;
}
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;
}
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);
}
}
}
}
}
}
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;
}
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;
}
Aggregations