Advertisement
Guest User

Untitled

a guest
Feb 25th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. package com.runescape.cache.graphics;
  2. import java.io.ByteArrayInputStream;
  3. import java.io.DataInputStream;
  4. import java.io.IOException;
  5. import org.apache.commons.compress.compressors.xz.XZCompressorInputStream;
  6. import org.seven.util.FileUtils;
  7.  
  8. import com.runescape.io.Buffer;
  9. import com.runescape.sign.SignLink;
  10.  
  11. public final class SpriteLoader {
  12.  
  13. public static Sprite[] sprites;
  14.  
  15. public static int totalSprites;
  16.  
  17. public static void load() {
  18. Buffer data = new Buffer(FileUtils.readFile(SignLink.findcachedir() + "main_file_sprites.dat"));
  19.  
  20. try (DataInputStream dataFile = new DataInputStream(new XZCompressorInputStream(new ByteArrayInputStream(data.payload)))) {
  21.  
  22. int totalSprites = dataFile.readInt();
  23.  
  24. sprites = new Sprite[totalSprites];
  25.  
  26. for (int index = 0; index < totalSprites; index++) {
  27. sprites[index] = SpriteLoader.decode(dataFile);
  28.  
  29. sprites[index].setTransparency(255, 0, 255);
  30. }
  31.  
  32. System.out.println("Sprites Loaded: " + totalSprites);
  33. } catch (IOException ex) {
  34. ex.printStackTrace();
  35. }
  36. }
  37.  
  38. private static Sprite decode(DataInputStream dat) throws IOException {
  39.  
  40. Sprite sprite = new Sprite();
  41.  
  42. while (true) {
  43.  
  44. byte opcode = dat.readByte();
  45.  
  46. if (opcode == 0) {
  47. return sprite;
  48. } else if (opcode == 1) {
  49. sprite.setId(dat.readShort());
  50. } else if (opcode == 2) {
  51. sprite.setName(dat.readUTF());
  52. } else if (opcode == 3) {
  53. sprite.setWidth(dat.readShort());
  54. } else if (opcode == 4) {
  55. sprite.setHeight(dat.readShort());
  56. } else if (opcode == 5) {
  57. sprite.setOffsetX(dat.readShort());
  58. } else if (opcode == 6) {
  59. sprite.setOffsetY(dat.readShort());
  60. } else if (opcode == 7) {
  61.  
  62. int indexLength = dat.readInt();
  63.  
  64. int[] pixels = new int[indexLength];
  65.  
  66. for (int i = 0; i < pixels.length; i++) {
  67. pixels[i] = dat.readInt();
  68. }
  69.  
  70. sprite.pixels = pixels;
  71. }
  72. }
  73. }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement