Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.runescape.cache.graphics;
- import java.io.ByteArrayInputStream;
- import java.io.DataInputStream;
- import java.io.IOException;
- import org.apache.commons.compress.compressors.xz.XZCompressorInputStream;
- import org.seven.util.FileUtils;
- import com.runescape.io.Buffer;
- import com.runescape.sign.SignLink;
- public final class SpriteLoader {
- public static Sprite[] sprites;
- public static int totalSprites;
- public static void load() {
- Buffer data = new Buffer(FileUtils.readFile(SignLink.findcachedir() + "main_file_sprites.dat"));
- try (DataInputStream dataFile = new DataInputStream(new XZCompressorInputStream(new ByteArrayInputStream(data.payload)))) {
- int totalSprites = dataFile.readInt();
- sprites = new Sprite[totalSprites];
- for (int index = 0; index < totalSprites; index++) {
- sprites[index] = SpriteLoader.decode(dataFile);
- sprites[index].setTransparency(255, 0, 255);
- }
- System.out.println("Sprites Loaded: " + totalSprites);
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
- private static Sprite decode(DataInputStream dat) throws IOException {
- Sprite sprite = new Sprite();
- while (true) {
- byte opcode = dat.readByte();
- if (opcode == 0) {
- return sprite;
- } else if (opcode == 1) {
- sprite.setId(dat.readShort());
- } else if (opcode == 2) {
- sprite.setName(dat.readUTF());
- } else if (opcode == 3) {
- sprite.setWidth(dat.readShort());
- } else if (opcode == 4) {
- sprite.setHeight(dat.readShort());
- } else if (opcode == 5) {
- sprite.setOffsetX(dat.readShort());
- } else if (opcode == 6) {
- sprite.setOffsetY(dat.readShort());
- } else if (opcode == 7) {
- int indexLength = dat.readInt();
- int[] pixels = new int[indexLength];
- for (int i = 0; i < pixels.length; i++) {
- pixels[i] = dat.readInt();
- }
- sprite.pixels = pixels;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement