Advertisement
Guest User

Runescape Model Grabber

a guest
Nov 19th, 2012
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.22 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.io.InputStream;
  3. import java.io.OutputStream;
  4. import java.net.Socket;
  5. import java.io.*;
  6.  
  7. public class Main {
  8.     private UnPack pack = new UnPack();
  9.     public Main() {
  10.         try{
  11.         }
  12.         catch(Exception e){}
  13.         System.out.println("Runescape Model Grabber");
  14.         System.out.println("Thanks to Silabsoft");
  15.         System.out.println("~~~~~~~~~~");
  16.         findVersion();
  17.         System.out.println("~~~~~~~~~~");
  18.         try {
  19.             for(int i = new File("./Models/").listFiles().length; i < 9999999; i++){
  20. //      if(i > min-1 && i < max) {//for grabbing a range of models
  21. //      if(i == ) {//for grabbing 1 model
  22.         if(i > 0) {//grabs all models
  23.                 System.out.println("Sending request for Model: "+i);
  24.                 addRequest( 7, i);
  25.                 byte b[] =  pack.unpack(download().buffer);
  26.                 if(pack.unpacked) {
  27.                     savemodel(i,b);
  28.                     System.out.println("Model Saved");
  29.                 }else{
  30.                     System.out.println("Model Grabbing Complete");
  31.                     break;
  32.                 }
  33.         }
  34.             }
  35.         } catch (Exception e) {
  36.             System.out.println(e);
  37.         }
  38.     }
  39.  
  40.     public void savemodel(int id, byte[] b){
  41.             try {
  42.             FileOutputStream fileoutputstream = new FileOutputStream("./Models/"+id+".dat");
  43.             fileoutputstream.write(b, 0, b.length);
  44.             fileoutputstream.close();
  45.         } catch(Throwable _ex) {}
  46. }
  47.  
  48.     public static void main(String[] args) {
  49.         new Main();
  50.     }
  51.  
  52.     public void findVersion() {
  53.         System.out.println("Grabbing Cache Version.");
  54.         while (true) {
  55.             try {
  56.                 System.out.print("Trying: " + version);
  57.                 if (connect(address, port, version) == false) {
  58.                     System.out.println(" Rejected.");
  59.                     version++;
  60.                 } else {
  61.                     System.out.println(" Accepted.");
  62.                     break;
  63.                 }
  64.             } catch (Exception _ex) {
  65.                 System.out.println(" Rejected.");
  66.             }
  67.         }
  68.     }
  69.  
  70.     public boolean connect(String server, int port, int version) throws IOException {
  71.         socket = new Socket(server, port);
  72.         input = socket.getInputStream();
  73.         output = socket.getOutputStream();
  74.         output.write(15);
  75.         output.write(0);
  76.         output.write(0);
  77.         output.write(version >> 8);
  78.         output.write(version);
  79.         output.flush();
  80.         int r = input.read();
  81.         if (r == 0) {
  82.             return true;
  83.         } else {
  84.             close();
  85.             return false;
  86.         }
  87.     }
  88.  
  89.     public void addRequest(int c, int i) throws IOException {
  90.         output.write(0);
  91.         output.write(c);
  92.         output.write(i >> 8);
  93.         output.write(i);
  94.         output.flush();
  95.     }
  96.     public CacheChunk download() throws IOException {
  97.         CacheChunk chunk = new CacheChunk();
  98.         byte dHead[] = new byte[3];
  99.         byte jHead[] = new byte[5];
  100.         input.read(dHead);
  101.         input.read(jHead);
  102.         chunk.cache = dHead[0];
  103.         chunk.type = jHead[0];
  104.         chunk.index = ((dHead[1] & 0xff) << 8) + (dHead[2] & 0xff);
  105.         int s = ((jHead[1] & 0xff) << 24);
  106.         s += ((jHead[2] & 0xff) << 16);
  107.         s += ((jHead[3] & 0xff) << 8);
  108.         s += (jHead[4] & 0xff) + 5;
  109.         if (chunk.type == 2 || chunk.type == 1)
  110.             s += 4;
  111.         chunk.buffer = new byte[s];
  112.         System.arraycopy(jHead, 0, chunk.buffer, 0, 5);
  113.         int c = 5;
  114.         int m = 8;
  115.         while (c < s) {
  116.             if (m == 512) {
  117.                 m = 1;
  118.                 input.read();
  119.             } else {
  120.                 chunk.buffer[c] = (byte) input.read();
  121.                 c++;
  122.                 m++;
  123.             }
  124.         }
  125.         return chunk;
  126.     }
  127.  
  128.     public void close() {
  129.         try{
  130.             output.close();
  131.             input.close();
  132.             socket.close();
  133.         } catch (Exception _ex) {}
  134.     }
  135.     private int version = 503;
  136.     private static String address = "world138.runescape.com";
  137.     private static int port = 43594;
  138.  
  139.     private Socket socket;
  140.     private InputStream input;
  141.     private OutputStream output;
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement