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