Thread: RuneScape Bestiary Dumper

Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1 RuneScape Bestiary Dumper 
    Registered Member
    Join Date
    Sep 2013
    Posts
    70
    Thanks given
    23
    Thanks received
    46
    Rep Power
    6
    Example Formatted Output:
    Code:
    id=6222
    name=Kree'arra
    description=Graceful avatar of Armadyl.
    size=3
    xp=5635.3
    lifepoints=75000
    level=580
    attack=75
    defence=75
    ranged=75
    magic=75
    animations={death:17398,attack:17396}
    attackable=true
    poisonous=false
    weakness="None"
    slayercat=Aviansies
    areas=["God Wars Dungeon"]
    aggressive=true
    Source:
    Code:
    import java.io.*;
    import java.net.URL;
    import java.util.ArrayList;
    import java.util.concurrent.ExecutorService;
    import java.util.concurrent.Executors;
    
    /**
     * This program was created for learning purposes.
     * @author Archon
     */
    public class BestiaryDumper {
    
        /**
         * The path bestiary data will be dumped to.
         * (MUST END IN TRAILING SLASH)
         */
    
        private static String DUMP_PATH = "C:/Users/Archon/Desktop/bestiary/";
    
        /**
         * When true, dumped data will be formatted to the "formatted" folder.
         */
    
        private static final boolean FORMAT = true;
    
        /**
         * A thread pool used to quickly execute data dumping.
         */
    
        private static final ExecutorService EXECUTOR = Executors.newFixedThreadPool(16);
    
        /**
         * Identifiers used for formatting order.
         */
    
        private static final String[] IDENTIFIERS = {
                "id", "name", "description", "size", "xp", "lifepoints", "level",
                "attack", "defence", "ranged", "magic", "animations", "attackable",
                "poisonous", "weakness", "slayerLevel", "slayercat", "abilities",
                "areas", "aggressive", "members"
        };
    
        /**
         * Starts this program.
         * @param args not being used.
         */
    
        public static void main(String[] args) {
            File dumpFolder = new File(DUMP_PATH);
            if(!dumpFolder.exists()) {
                System.err.println("Invalid dump directory provided: " + DUMP_PATH);
                return;
            }
            if(FORMAT) {
                File formatFolder = new File(DUMP_PATH + "formatted");
                if(formatFolder.exists()) {
                    File[] files = formatFolder.listFiles();
                    if(files != null) {
                        for(File file : files)
                            file.delete();
                    }
                } else {
                    formatFolder.mkdir();
                }
            }
            for(int i = 0; i < 65000; i++) {
                final int id = i;
                EXECUTOR.execute(() -> dump(id));
            }
            EXECUTOR.shutdown();
        }
    
        private static void dump(int id) {
            BufferedReader br = null;
            BufferedWriter bw = null;
            try {
                URL url = new URL("http://services.runescape.com/m=itemdb_rs/bestiary/beastData.json?beastid=" + id);
                br = new BufferedReader(new InputStreamReader(url.openStream()));
                String line = br.readLine();
                if(line == null || line.isEmpty()) {
                    /* no bestiary data */
                    return;
                }
                bw = new BufferedWriter(new FileWriter(DUMP_PATH + id + ".txt"));
                bw.write(line);
                System.out.println("Successfully dumped bestiary data for npc: " + id);
            } catch(Exception e) {
                System.err.println("Failed to dump bestiary data for npc: " + id);
                e.printStackTrace();
            } finally {
                close(br, bw);
                if(FORMAT)
                    format(id);
            }
        }
    
        /**
         * Formats the already dumped file with the given id.
         * @param id the id of the dumped npc file.
         */
    
        private static void format(int id) {
            BufferedReader br = null;
            BufferedWriter bw = null;
            try {
                File dumped = new File(DUMP_PATH + id + ".txt");
                if(!dumped.exists())
                    return;
                br = new BufferedReader(new FileReader(dumped));
                String line = br.readLine();
                if(line == null) {
                    System.err.println("Failed to format dumped npc: " + id);
                    return;
                }
                /* remove starting and trailing brackets */
                line = line.substring(1, line.length() - 1);
    
                String s = "";
                Character enclosedBy = null;
                ArrayList<String> lines = new ArrayList<>(20);
                for(char c : line.toCharArray()) {
                    if(enclosedBy == null) {
                        if(c == '{' || c == '[' || c == '"')
                            enclosedBy = c;
                    } else {
                        if(enclosedBy == '{' && c == '}')
                            enclosedBy = null;
                        else if(enclosedBy == '[' && c == ']')
                            enclosedBy = null;
                        else if(enclosedBy == '"' && c == '"')
                            enclosedBy = null;
                    }
                    if(c == ',' && enclosedBy == null) {
                        /**
                         * Split line
                         */
                        s = s.replaceFirst("\"", "").replaceFirst("\":", "=");
                        if(!s.startsWith("weakness=") && !s.startsWith("areas=") && !s.startsWith("abilities=")) {
                            if(s.contains("\""))
                                s = s.replaceAll("\"", "");
                        }
                        if(s.isEmpty() || !s.contains("="))
                            System.err.println("Invalid line read for npc: " + id);
                        else
                            lines.add(s);
                        s = "";
                    } else {
                        /**
                         * Append character
                         */
                        s += c;
                    }
                }
                /* sorts dumped data by identifiers */
                lines.sort((s1, s2) -> getOrder(s1) - getOrder(s2));
    
                bw = new BufferedWriter(new FileWriter(DUMP_PATH + "formatted" + System.getProperty("file.separator") + id + ".txt"));
                for(String l : lines) {
                    bw.write(l);
                    bw.newLine();
                }
                System.out.println("Successfully formatted npc: " + id);
            } catch(Exception e) {
                System.err.println("Failed to format npc: " + id);
                e.printStackTrace();
            } finally {
                close(br, bw);
            }
        }
    
        /**
         * Retrieves the ascending order of the given identifier.
         * @param identifier the identifier being read.
         * @return the ascending order of the given identifier.
         */
    
        private static int getOrder(String identifier) {
            identifier = identifier.substring(0, identifier.indexOf("="));
            for(int i = 0; i < IDENTIFIERS.length; i++) {
                if(identifier.equalsIgnoreCase(IDENTIFIERS[i]))
                    return i;
            }
            System.err.println("Unhandled Identifier: " + identifier);
            return 0;
        }
    
        /**
         * Closes the given buffers.
         * @param br the <code>BufferedReader</code> to close.
         * @param bw the <code>BufferedWriter</code> to close.
         */
    
        private static void close(BufferedReader br, BufferedWriter bw) {
            if(br != null) {
                try {
                    br.close();
                } catch(IOException e) {
                    e.printStackTrace();
                }
            }
            if(bw != null) {
                try {
                    bw.close();
                } catch(IOException e) {
                    e.printStackTrace();
                }
            }
        }
    
    }
    Reply With Quote  
     


  2. #2  
    Registered Member
    Ynneh's Avatar
    Join Date
    Mar 2010
    Posts
    2,204
    Thanks given
    146
    Thanks received
    254
    Discord
    View profile
    Rep Power
    241
    Very nice.
    Reply With Quote  
     

  3. #3  
    Mug Club


    Join Date
    Jul 2011
    Age
    26
    Posts
    1,875
    Thanks given
    510
    Thanks received
    890
    Discord
    View profile
    Rep Power
    332
    Here's the one I used for my RS3 server lol. It does pretty much the exact same thing.

    Code:
    package com.rs.tools;
    
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.SocketTimeoutException;
    import java.net.URL;
    import java.net.URLConnection;
    
    import com.rs.cache.Cache;
    import com.rs.utils.Utils;
    
    public class BestiaryParser {
    	
    	public static void main(String[] args) throws IOException {
    		Cache.init();
    		File file = new File("npcCombatDefs.txt");
    		if (file.exists())
    			file.delete();
    		else
    			file.createNewFile();
    		BufferedWriter writer = new BufferedWriter(new FileWriter(file));
    		writer.flush();
    		for (int id = 0; id < Utils.getNPCDefinitionsSize(); id++) {
    			try {
    				URL url = new URL("http://services.runescape.com/m=itemdb_rs/bestiary/beastData.json?beastid="+id);
    				URLConnection con = url.openConnection();
    				con.setReadTimeout(5000);
    				BufferedReader stream = new BufferedReader(new InputStreamReader(con.getInputStream()));
    				if (stream.ready()) {
    					writer.append(id+"-"+stream.readLine());
    					writer.newLine();
    					System.out.println("Dumped success for: "+id);
    				}
    				stream.close();
    				writer.flush();
    			} catch(SocketTimeoutException e) {
    				System.out.println("Socket timeout connection on NPC: "+id);
    			}
    		}
    		writer.close();
    	}
    
    }


    My Open Source Projects
    [Only registered and activated users can see links. ]
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  4. #4  
    Registered Member
    Join Date
    Sep 2013
    Posts
    70
    Thanks given
    23
    Thanks received
    46
    Rep Power
    6
    Quote Originally Posted by Makar View Post
    Here's the one I used for my RS3 server lol. It does pretty much the exact same thing.
    Code:
        private static void dump(int id) {
            BufferedReader br = null;
            BufferedWriter bw = null;
            try {
                URL url = new URL("http://services.runescape.com/m=itemdb_rs/bestiary/beastData.json?beastid=" + id);
                br = new BufferedReader(new InputStreamReader(url.openStream()));
                String line = br.readLine();
                if(line == null || line.isEmpty()) {
                    /* no bestiary data */
                    return;
                }
                bw = new BufferedWriter(new FileWriter(DUMP_PATH + id + ".txt"));
                bw.write(line);
                System.out.println("Successfully dumped bestiary data for npc: " + id);
            } catch(Exception e) {
                System.err.println("Failed to dump bestiary data for npc: " + id);
                e.printStackTrace();
            } finally {
                close(br, bw);
                if(FORMAT)
                    format(id);
            }
        }
    ^That is all that was needed to simply dump the data. But this also formats the data making it much easier to read and removes the need of any JSON dependencies.
    Reply With Quote  
     

  5. #5  
    Registered Member jh_angel's Avatar
    Join Date
    Feb 2008
    Posts
    179
    Thanks given
    30
    Thanks received
    10
    Rep Power
    21
    Thank you so much!
    Reply With Quote  
     

  6. #6  
    Mug Club


    Join Date
    Jul 2011
    Age
    26
    Posts
    1,875
    Thanks given
    510
    Thanks received
    890
    Discord
    View profile
    Rep Power
    332
    Quote Originally Posted by Archon View Post
    Code:
        private static void dump(int id) {
            BufferedReader br = null;
            BufferedWriter bw = null;
            try {
                URL url = new URL("http://services.runescape.com/m=itemdb_rs/bestiary/beastData.json?beastid=" + id);
                br = new BufferedReader(new InputStreamReader(url.openStream()));
                String line = br.readLine();
                if(line == null || line.isEmpty()) {
                    /* no bestiary data */
                    return;
                }
                bw = new BufferedWriter(new FileWriter(DUMP_PATH + id + ".txt"));
                bw.write(line);
                System.out.println("Successfully dumped bestiary data for npc: " + id);
            } catch(Exception e) {
                System.err.println("Failed to dump bestiary data for npc: " + id);
                e.printStackTrace();
            } finally {
                close(br, bw);
                if(FORMAT)
                    format(id);
            }
        }
    ^That is all that was needed to simply dump the data. But this also formats the data making it much easier to read and removes the need of any JSON dependencies.
    If you're not going to use the JSON dependencies to load the data, you might as well store them into a bytebuffer.


    My Open Source Projects
    [Only registered and activated users can see links. ]
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  7. #7  
    Registered Member
    Join Date
    Sep 2013
    Posts
    70
    Thanks given
    23
    Thanks received
    46
    Rep Power
    6
    Quote Originally Posted by Makar View Post
    If you're not going to use the JSON dependencies to load the data, you might as well store them into a bytebuffer.
    I disagree. There are many other options. Plus, this is more of a helpful configuration type dump to easily acquire data.
    Reply With Quote  
     

  8. Thankful user:


  9. #8  
    Registered Member
    Join Date
    Apr 2014
    Posts
    174
    Thanks given
    25
    Thanks received
    11
    Rep Power
    11
    excuse me for beeing stupid fixed it. thanks alot for this man
    Reply With Quote  
     

  10. #9  
    Registered Member

    Join Date
    Dec 2012
    Posts
    3,006
    Thanks given
    899
    Thanks received
    929
    Rep Power
    2548
    • Code:
      "C:/Users/Archon/Desktop/bestiary/";
      <
      Code:
      System.getProperty("user.home") + "/Desktop/destiary
    • Why wouldn't you use JSON output? Looks way prettier and it's easier to parse than .txt
    • Instead of using <code>#</code> in your documentation, use {@link #}


    Great release though, never knew of the RS bestiary, if only it was around Pre-EOC. And props for parsing all that crap looked like it'd take a while
    Reply With Quote  
     

  11. Thankful user:


  12. #10  
    The stupid noob


    Join Date
    May 2011
    Age
    26
    Posts
    2,227
    Thanks given
    2,446
    Thanks received
    1,100
    Rep Power
    852
    To potentially save someone some time; here's the output.
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  13. Thankful users:


Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Runescape Model Dumper
    By Apfelsuchti in forum Requests
    Replies: 0
    Last Post: 11-19-2010, 05:27 PM
  2. Runescape deob dumper
    By `Michael in forum Downloads
    Replies: 10
    Last Post: 10-11-2009, 06:32 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •