Thread: Index Repacking

Page 1 of 25 12311 ... LastLast
Results 1 to 10 of 250
  1. #1 Index Repacking 
    Retired. Stop PMing me.


    Galkon's Avatar
    Join Date
    Nov 2007
    Age
    17
    Posts
    7,526
    Thanks given
    1,805
    Thanks received
    2,830
    Rep Power
    5000
    For those of you who want to pack models, animations, and maps into the cache but don't know how, here are some methods I've written to make the client do it for you with one simple calling of a method.

    Add these methods in client.java:
    Spoiler for Methods:
    Code:
    	public String indexLocation(int cacheIndex, int index) {
    		return signlink.findcachedir() + "index" + cacheIndex + "/" + (index != -1 ? index + ".gz" : "");
    	}
    
    	public void repackCacheIndex(int cacheIndex) {
    		System.out.println("Started repacking index " + cacheIndex + ".");
    		int indexLength = new File(indexLocation(cacheIndex, -1)).listFiles().length;
    		File[] file = new File(indexLocation(cacheIndex, -1)).listFiles();
    		try {
    			for (int index = 0; index < indexLength; index++) {
    				int fileIndex = Integer.parseInt(getFileNameWithoutExtension(file[index].toString()));
    				byte[] data = fileToByteArray(cacheIndex, fileIndex);
    				if(data != null && data.length > 0) {
    					decompressors[cacheIndex].method234(data.length, data, fileIndex);
    					System.out.println("Repacked " + fileIndex + ".");
    				} else {
    					System.out.println("Unable to locate index " + fileIndex + ".");
    				}
    			}
    		} catch(Exception e) {
    			System.out.println("Error packing cache index " + cacheIndex + ".");
    		}
    		System.out.println("Finished repacking " + cacheIndex + ".");
    	}
    
    	public byte[] fileToByteArray(int cacheIndex, int index) {
    		try {
    			if (indexLocation(cacheIndex, index).length() <= 0 || indexLocation(cacheIndex, index) == null) {
    				return null;
    			}
    			File file = new File(indexLocation(cacheIndex, index));
    			byte[] fileData = new byte[(int)file.length()];
    			FileInputStream fis = new FileInputStream(file);
    			fis.read(fileData);
    			fis.close();
    			return fileData;
    		} catch(Exception e) {
    			return null;
    		}
    	}

    And if you need getFileNameWithoutExtension, here it is:
    Code:
    	public static String getFileNameWithoutExtension(String fileName) {
    		File tmpFile = new File(fileName);
    		tmpFile.getName();
    		int whereDot = tmpFile.getName().lastIndexOf('.');
    		if (0 < whereDot && whereDot <= tmpFile.getName().length() - 2) {
    			return tmpFile.getName().substring(0, whereDot);
    		}
    		return "";
    	}
    If you want to add models past 40k or so:
    Spoiler for Unlimiting cache size:

    Decompressor.java, replace this method:
    Code:
    	private synchronized void seekTo(RandomAccessFile randomaccessfile, int j) throws IOException {
    		try {
    			/*if (j < 0 || j > 0x3c00000) {
    				System.out.println("Badseek - pos:" + j + " len:" + randomaccessfile.length());
    				j = 0x3c00000;
    				try {
    					Thread.sleep(1000L);
    				} catch (Exception _ex) {
    				}
    			}*/
    			randomaccessfile.seek(j);
    		} catch(Exception e) {
    			e.printStackTrace();
    		}
    	}
    signlink.java, replace the top part of run() with this:
    Code:
        public void run() {
            active = true;
            String s = findcachedir();
            uid = getuid(s);
            try {
                cache_dat = new RandomAccessFile(s + "main_file_cache.dat", "rw");
                for(int j = 0; j < 5; j++) {
                    cache_idx[j] = new RandomAccessFile(s + "main_file_cache.idx" + j, "rw");
    			}
            } catch(Exception exception) {
                exception.printStackTrace();
            }


    Now if you want to repack an index:
    • Place the folder containing all the gzipped files in the cache folder.
    • Make sure the folder is called index#, so for example models would be located at "/cache/index1/#.gz".
    • In the startup method, simply call 'repackCacheIndex(#)'.

    models = index1
    animations = index2
    sounds = index3
    maps = index4

    What this will do is it will find the index directory with the gzipped files, and pack only the files in the directory, so you can also use this to repack a few models at a time.
    Last edited by Galkon; 08-07-2011 at 07:23 PM.
    Attached image
    Reply With Quote  
     


  2. #2  
    q.q


    Join Date
    Dec 2010
    Posts
    6,519
    Thanks given
    1,072
    Thanks received
    3,535
    Rep Power
    4752
    Spoiler for Spoiler:
    Quote Originally Posted by Galkon View Post
    For those of you who want to pack models, animations, and maps into the cache but don't know how, here are some methods I've written to make the client do it for you with one simple calling of a method.

    Add these methods in client.java:
    Spoiler for Methods:
    Code:
    	public String indexLocation(int cacheIndex, int index) {
    		return signlink.findcachedir() + "index" + cacheIndex + "/" + (index != -1 ? index + ".gz" : "");
    	}
    
    	public void repackCacheIndex(int cacheIndex) {
    		System.out.println("Started repacking index " + cacheIndex + ".");
    		int indexLength = new File(indexLocation(cacheIndex, -1)).listFiles().length;
    		File[] file = new File(indexLocation(cacheIndex, -1)).listFiles();
    		try {
    			for (int index = 0; index < indexLength; index++) {
    				int fileIndex = Integer.parseInt(getFileNameWithoutExtension(file[index].toString()));
    				byte[] data = fileToByteArray(cacheIndex, fileIndex);
    				if(data != null && data.length > 0) {
    					decompressors[cacheIndex].method234(data.length, data, fileIndex);
    					System.out.println("Repacked " + fileIndex + ".");
    				} else {
    					System.out.println("Unable to locate index " + fileIndex + ".");
    				}
    			}
    		} catch(Exception e) {
    			System.out.println("Error packing cache index " + cacheIndex + ".");
    		}
    		System.out.println("Finished repacking " + cacheIndex + ".");
    	}
    
    	public byte[] fileToByteArray(int cacheIndex, int index) {
    		try {
    			if (indexLocation(cacheIndex, index).length() <= 0 || indexLocation(cacheIndex, index) == null) {
    				return null;
    			}
    			File file = new File(indexLocation(cacheIndex, index));
    			byte[] fileData = new byte[(int)file.length()];
    			FileInputStream fis = new FileInputStream(file);
    			fis.read(fileData);
    			fis.close();
    			return fileData;
    		} catch(Exception e) {
    			return null;
    		}
    	}

    And if you need getFileNameWithoutExtension, here it is:
    Code:
    	public static String getFileNameWithoutExtension(String fileName) {
    		File tmpFile = new File(fileName);
    		tmpFile.getName();
    		int whereDot = tmpFile.getName().lastIndexOf('.');
    		if (0 < whereDot && whereDot <= tmpFile.getName().length() - 2) {
    			return tmpFile.getName().substring(0, whereDot);
    		}
    		return "";
    	}
    If you want to add models past 40k or so:
    Spoiler for Unlimiting cache size:

    Decompressor.java, replace this method:
    Code:
    	private synchronized void seekTo(RandomAccessFile randomaccessfile, int j) throws IOException {
    		try {
    			/*if (j < 0 || j > 0x3c00000) {
    				System.out.println("Badseek - pos:" + j + " len:" + randomaccessfile.length());
    				j = 0x3c00000;
    				try {
    					Thread.sleep(1000L);
    				} catch (Exception _ex) {
    				}
    			}*/
    			randomaccessfile.seek(j);
    		} catch(Exception e) {
    			e.printStackTrace();
    		}
    	}
    signlink.java, replace the top part of run() with this:
    Code:
        public void run() {
            active = true;
            String s = findcachedir();
            uid = getuid(s);
            try {
                cache_dat = new RandomAccessFile(s + "main_file_cache.dat", "rw");
                for(int j = 0; j < 5; j++) {
                    cache_idx[j] = new RandomAccessFile(s + "main_file_cache.idx" + j, "rw");
    			}
            } catch(Exception exception) {
                exception.printStackTrace();
            }


    Now if you want to repack an index:
    • Place the folder containing all the gzipped files in the cache folder.
    • Make sure the folder is called index#, so for example models would be located at "/cache/index1/#.gz".
    • In the startup method, simply call 'repackCacheIndex(#)'.

    models = index1
    animations = index2
    maps = index4

    What this will do is it will find the index directory with the gzipped files, and pack only the files in the directory, so you can also use this to repack a few models at a time.


    Awesome, needed something like this. Thanks.
    Reply With Quote  
     

  3. #3  
    Interface Junkie Index Repacking Market Banned
    Nyan's Avatar
    Join Date
    Apr 2011
    Posts
    646
    Thanks given
    35
    Thanks received
    82
    Rep Power
    56
    easy but good job
    Reply With Quote  
     

  4. #4  
    Super Donator


    Join Date
    Feb 2011
    Age
    27
    Posts
    1,126
    Thanks given
    180
    Thanks received
    178
    Rep Power
    243
    Nice work Galkon once again
    Reply With Quote  
     

  5. #5  
    Retired. Stop PMing me.


    Galkon's Avatar
    Join Date
    Nov 2007
    Age
    17
    Posts
    7,526
    Thanks given
    1,805
    Thanks received
    2,830
    Rep Power
    5000
    Quote Originally Posted by Harlan View Post

    Awesome, needed something like this. Thanks.
    No need to quote, it'll never be removed .
    Attached image
    Reply With Quote  
     

  6. #6  
    Banned

    Join Date
    Sep 2010
    Age
    29
    Posts
    567
    Thanks given
    147
    Thanks received
    202
    Rep Power
    0
    You're a beast, thank you
    Reply With Quote  
     

  7. #7  
    Banned

    Join Date
    Aug 2008
    Posts
    1,885
    Thanks given
    56
    Thanks received
    102
    Rep Power
    0
    Thank's. This is useful
    Reply With Quote  
     

  8. #8  
    If you read this you're gay!
    Infexis's Avatar
    Join Date
    Aug 2009
    Age
    28
    Posts
    4,557
    Thanks given
    1,158
    Thanks received
    1,174
    Rep Power
    2949
    How is it recognizing if it's a map, or if it's an animation?

    "If you can't explain it simply, you don't understand it well enough." - Albert Einstein
    Reply With Quote  
     

  9. #9  
    .supersyn

    myK-'s Avatar
    Join Date
    Aug 2008
    Posts
    1,781
    Thanks given
    22
    Thanks received
    40
    Rep Power
    399
    Thanks so much needed this for the unlimiting cache.


    Quote Originally Posted by Infexis View Post
    How is it recognizing if it's a map, or if it's an animation?
    Quote Originally Posted by Galkon View Post
    Now if you want to repack an index:
    • Place the folder containing all the gzipped files in the cache folder.
    • Make sure the folder is called index#, so for example models would be located at "/cache/index1/#.gz".
    • In the startup method, simply call 'repackCacheIndex(#)'.

    models = index1
    animations = index2
    maps = index4

    What this will do is it will find the index directory with the gzipped files, and pack only the files in the directory, so you can also use this to repack a few models at a time.
    Reply With Quote  
     

  10. Thankful users:


  11. #10  
    Registered Member
    Join Date
    Nov 2009
    Posts
    3,052
    Thanks given
    112
    Thanks received
    838
    Rep Power
    740
    thx, didnt knew how to fix badseek b4
    Reply With Quote  
     

Page 1 of 25 12311 ... 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. 634 map index for 317
    By mige5 in forum Downloads
    Replies: 223
    Last Post: 09-27-2016, 05:08 AM
  2. index?t=something
    By minutes in forum Application Development
    Replies: 0
    Last Post: 02-20-2011, 12:38 PM
  3. model_index archive repacking
    By Xaves in forum Help
    Replies: 9
    Last Post: 01-07-2011, 11:36 PM
  4. Repacking Data
    By Stewie in forum Help
    Replies: 1
    Last Post: 05-02-2010, 07:45 AM
  5. Index Help
    By Streetwave in forum Application Development
    Replies: 6
    Last Post: 10-21-2009, 12:38 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •