Thread: Map/Landscape compressor and loader

Page 1 of 3 123 LastLast
Results 1 to 10 of 23
  1. #1 Map/Landscape compressor and loader 
    Member Map/Landscape compressor and loader Market Banned

    Zee Best's Avatar
    Join Date
    Feb 2007
    Age
    32
    Posts
    3,036
    Thanks given
    24
    Thanks received
    210
    Rep Power
    1171
    I wrote this compressor and loader which uses RandomAccessFile so that people were not releasing client's with map folders bigger than the actual cache.

    This compressor will pack your maps into 3 files;

    MAP_CACHE.DAT - Contains the raw map bytes.
    MAP_CACHE.IDX - Contains the offset, length compressed and decompressed.
    MAP_CACHE.IDX2 - Contains the index table, for the map id's.

    The total file size is smaller than rarring the files in a rar archive, 23mb of maps went into a 2.7mb raw data file and 2 indexes around 20kb in size.

    Basically, in your client if you load 317 map's or whatever you can use this tool to compress and load with ease.

    The map's are stored in a HashMap and only loaded when required, then they are stored for future reference.

    So anyway;

    Compressor download link: Map compressor.rar

    Loader class;

    Code:
    /*
     * @ Author: Zee best
    */
    
    import java.io.RandomAccessFile;
    import java.io.DataInputStream;
    import java.io.IOException;
    import java.io.ByteArrayInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.util.zip.GZIPInputStream;
    import java.util.Map;
    import java.util.HashMap;
    import java.util.List;
    import java.util.ArrayList;
    
    public class MapDecompressor {
    
    	public static List<Integer> mapIndices = null;
    	public static Map<Integer, byte[]> mapBuffer = new HashMap<Integer, byte[]>();
    	
    	public static byte[] grabMap(int id) throws IOException
    	{
    		if(mapIndices == null)
    			loadIndex2();
    		if(mapBuffer.get(id) == null)
    		{
    			RandomAccessFile raf_cache = new RandomAccessFile("./MAP_CACHE.dat", "rw");
    			RandomAccessFile raf_index = new RandomAccessFile("./MAP_CACHE.idx", "rw");
    			int pos = getIndexPosition(id);
    			if(pos == -1)
    				return null;
    			raf_index.seek(pos * 12);
    			raf_cache.seek(raf_index.readInt());
    			byte[] b = new byte[raf_index.readInt()];
    			raf_cache.readFully(b);
    			b = inflate(b, raf_index.readInt());
    			mapBuffer.put(id, b);
    			return mapBuffer.get(id);
    		}
    		return mapBuffer.get(id);
    	}
    
    	public static void loadIndex2() throws IOException
    	{
    		mapIndices = new ArrayList<Integer>();
    		DataInputStream dis = new DataInputStream(new FileInputStream("./MAP_CACHE.idx2"));
    		for (int i = 0; i < (int) new File("./MAP_CACHE.idx2").length() / 2; i++)
    			mapIndices.add((int) dis.readShort());
    	}
    
    	public static int getIndexPosition(int id) throws IOException
    	{
    		if(mapIndices.contains(id))
    			for (int i = 0; i < mapIndices.size(); i++)
    				if(mapIndices.get(i) == id)
    					return i;
    		return -1;
    	}
    
    	public static byte[] inflate(byte[] b, int l) throws IOException
    	{
    		byte[] buf = new byte[l];
    		ByteArrayInputStream bais = new ByteArrayInputStream(b);
    		DataInputStream dis = new DataInputStream(new GZIPInputStream(bais));
    		dis.readFully(buf, 0, buf.length);
    		dis.close();
    		return buf;
    	}
    
    }
    Now, basically to get a map in the cache use it like this;

    Code:
    MapDecompressor.grabMap(id);
    That would replace any other loading method you have installed into your client.

    Feel free to use this for your client.

    Method summary:

    grabMap(Integer),

    This method attempts to get the map byte array from the HashTable, if it's not already loaded then it will read the index and cache and load it.

    loadIndex2()

    This method loads the idx2 index file which contains the index map id's, so that they can be found easy instead of searching a file for names.

    getIndexPosition(Integer)

    Checks the index array list for a match of map id, if it gets the map it returns
    the position / 12 of the index file.

    inflate(byte[], Integer)

    This method is used to un-gzip the compressed byte array, integer l is the uncompressed length.


     

  2. #2  
    Registered Member druidje's Avatar
    Join Date
    Jan 2007
    Posts
    375
    Thanks given
    1
    Thanks received
    0
    Rep Power
    28
    Nice, really handy ^.^

    Quote Originally Posted by zee_best View Post
    Get sarah101 to sleep with kevin?
    Quote Originally Posted by ject View Post
    but try ::noclit or whatever
    Developing 508!
     

  3. #3  
    Registered Member

    Join Date
    Sep 2008
    Posts
    2,156
    Thanks given
    3
    Thanks received
    2
    Rep Power
    182
    very cool.
     

  4. #4  
    Rukin1


    Rukin1's Avatar
    Join Date
    Apr 2007
    Age
    31
    Posts
    5,000
    Thanks given
    228
    Thanks received
    229
    Rep Power
    4166
    This will come in handy Zee, thanks
    Spoiler for large sig:


     

  5. #5  
    Brown
    Guest
    Thank you Zee Best.
     

  6. #6  
    Registered Member Globe's Avatar
    Join Date
    Oct 2008
    Posts
    223
    Thanks given
    0
    Thanks received
    0
    Rep Power
    12
    so this loads the map fully? sorry that i ask it....
    Those who only look to the past or the present are certain to miss the future
     

  7. #7  
    Member Map/Landscape compressor and loader Market Banned

    Zee Best's Avatar
    Join Date
    Feb 2007
    Age
    32
    Posts
    3,036
    Thanks given
    24
    Thanks received
    210
    Rep Power
    1171
    Quote Originally Posted by Globe View Post
    so this loads the map fully? sorry that i ask it....
    If your loading map files instead of xtea data on your client then it packs all the data into a small sized file instead of many seperate files.


     

  8. #8  
    Registered Member
    thing1's Avatar
    Join Date
    Aug 2008
    Posts
    2,111
    Thanks given
    131
    Thanks received
    1,099
    Rep Power
    2402
    I wonder if i can get 474 godwars with it lol
    Last edited by thing1; 05-15-2009 at 06:09 AM. Reason: forgot the l on lol
     

  9. #9  
    Typical Swede


    Join Date
    Jul 2008
    Posts
    1,162
    Thanks given
    204
    Thanks received
    154
    Rep Power
    217
    Oo, this is guud. thanks

    'Strange things did happen here no stranger would it be'
    ______________________________________________
     

  10. #10  
    Community Veteran


    Join Date
    Dec 2008
    Posts
    4,263
    Thanks given
    405
    Thanks received
    436
    Rep Power
    1674
    zee you dont release alot of stuff but when u do its flawless used it so repped
     

Page 1 of 3 123 LastLast

Thread Information
Users Browsing this Thread

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


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •