Thread: Index Repacking

Page 1 of 20 123 11 ... LastLast
Results 1 to 10 of 191
  1. #1 Index Repacking 
    The Javatar


    Galkon's Avatar
    Join Date
    Nov 2007
    Age
    13
    Posts
    7,155
    Thanks given
    1,455
    Thanks received
    2,314
    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.
    "I would rather have a mind opened by wonder than one closed by belief." - Gerry Spence

    Project Insanity Help & Assistance

    [Only registered and activated users can see links. ]
    [Only registered and activated users can see links. ]
    Reply With Quote  
     


  2. #2  
    q.q


    Join Date
    Dec 2010
    Posts
    6,308
    Thanks given
    948
    Thanks received
    3,192
    Rep Power
    3593
    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
    Nyan's Avatar
    Join Date
    Apr 2011
    Posts
    644
    Thanks given
    35
    Thanks received
    83
    Rep Power
    56
    easy but good job
    Reply With Quote  
     

  4. #4  
    Helping around :P

    Join Date
    Feb 2011
    Age
    18
    Posts
    603
    Thanks given
    24
    Thanks received
    42
    Rep Power
    18
    Nice work Galkon once again
    Reply With Quote  
     

  5. #5  
    The Javatar


    Galkon's Avatar
    Join Date
    Nov 2007
    Age
    13
    Posts
    7,155
    Thanks given
    1,455
    Thanks received
    2,314
    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 .
    "I would rather have a mind opened by wonder than one closed by belief." - Gerry Spence

    Project Insanity Help & Assistance

    [Only registered and activated users can see links. ]
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  6. #6  
    Banned

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

  7. #7  
    Banned

    Join Date
    Aug 2008
    Posts
    1,889
    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!

    Join Date
    Aug 2009
    Age
    18
    Posts
    4,383
    Thanks given
    1,052
    Thanks received
    1,115
    Rep Power
    2752
    How is it recognizing if it's a map, or if it's an animation?

    [Only registered and activated users can see links. ]

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

  9. #9  
    .supersyn

    n0data's Avatar
    Join Date
    Aug 2008
    Posts
    1,748
    Thanks given
    18
    Thanks received
    37
    Rep Power
    397
    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
    owner blade's Avatar
    Join Date
    Nov 2009
    Posts
    2,921
    Thanks given
    96
    Thanks received
    701
    Rep Power
    524
    thx, didnt knew how to fix badseek b4

    rofl
    Reply With Quote  
     

Page 1 of 20 12311 ... LastLast

Thread Information
Users Browsing this Thread

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

Similar Threads

  1. 634 map index for 317
    By mige5 in forum Downloads
    Replies: 222
    Last Post: 02-25-2012, 08:03 PM
  2. index?t=something
    By minutes in forum Help
    Replies: 0
    Last Post: 02-20-2011, 11:38 AM
  3. model_index archive repacking
    By Xaves in forum Help
    Replies: 9
    Last Post: 01-07-2011, 10: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 Help
    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
  •