Thread: How to dump sprites? (Necrotic)

Results 1 to 2 of 2
  1. #1 How to dump sprites? (Necrotic) 
    Registered Member
    Join Date
    Jun 2019
    Posts
    2
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    First time using eclipse and setting up a RSPS server, I'd like to modify a few sprites but they're all packed so I'd like to dump the sprites so I can modify and repack them.

    I'm using the Necrotic source that's based on Ruse and I tried dumping them but it just doesn't do anything.

    Code:
    [sp]
    Code:
    package org.necrotic.client.graphics;
    
    import java.io.ByteArrayInputStream;
    import java.io.DataInputStream;
    import java.io.File;
    import java.io.IOException;
    import java.io.RandomAccessFile;
    import java.nio.channels.FileChannel;
    import java.util.zip.GZIPInputStream;
    
    import org.necrotic.client.Signlink;
    import org.necrotic.client.io.ByteBuffer;
    import org.necrotic.client.tools.FileUtilities;
    
    public class SpriteLoader {
    
    	public static SpriteLoader[] cache;
    	public static Sprite[] sprites = null;
    
    	/**
    	 * Creates a sprite out of the spriteData.
    	 *
    	 * @param sprite
    	 */
    	private static void createSprite(SpriteLoader sprite) {
    		
    		File directory = new File(Signlink.getCacheDirectory().toString() + "/sprites"); if
    			(!directory.exists()) { directory.mkdir(); } FileUtilities.WriteFile(directory.getAbsolutePath() +
    					System.getProperty("file.separator") + sprite.id + ".png",
    					sprite.spriteData);
    
    		sprites[sprite.id] = new Sprite(sprite.spriteData);
    		sprites[sprite.id].drawOffsetX = sprite.drawOffsetX;
    		sprites[sprite.id].drawOffsetY = sprite.drawOffsetY;
    	}
    
    	/**
    	 * Loads the sprite data and index files from the cache location. This can
    	 * be edited to use an archive such as config or media to load from the
    	 * cache.
    	 *
    	 * @param streamLoader_2
    	 */
    
    	public static void loadSprites() {
    		try {
    			ByteBuffer index = new ByteBuffer(readFile(Signlink.getCacheDirectory() + "/" + "sprites.idx"));
    			ByteBuffer data = new ByteBuffer(readFile(Signlink.getCacheDirectory() + "/" + "sprites.dat"));
    			DataInputStream indexFile = new DataInputStream(new GZIPInputStream(new ByteArrayInputStream(index.buffer)));
    			DataInputStream dataFile = new DataInputStream(new GZIPInputStream(new ByteArrayInputStream(data.buffer)));
    			int totalSprites = indexFile.readInt();
    
    			if (cache == null) {
    				cache = new SpriteLoader[totalSprites];
    				sprites = new Sprite[totalSprites];
    			}
    
    			for (int i = 0; i < totalSprites; i++) {
    				int id = indexFile.readInt();
    				if (cache[id] == null) {
    					cache[id] = new SpriteLoader();
    				}
    
    				cache[id].readValues(indexFile, dataFile);
    				createSprite(cache[id]);
    			}
    
    			indexFile.close();
    			dataFile.close();
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    
    	private static byte[] readFile(String name) {
    		try {
    			RandomAccessFile raf = new RandomAccessFile(name, "r");
    			java.nio.ByteBuffer buf = raf.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, raf.length());
    
    			try {
    				if (buf.hasArray()) {
    					return buf.array();
    				} else {
    					byte[] array = new byte[buf.remaining()];
    					buf.get(array);
    					return array;
    				}
    			} finally {
    				raf.close();
    			}
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    
    		return null;
    	}
    
    	private int id;
    	private int drawOffsetX;
    	private int drawOffsetY;
    	public byte[] spriteData;
    
    	/**
    	 * Sets the default values.
    	 */
    	public SpriteLoader() {
    		id = -1;
    		drawOffsetX = 0;
    		drawOffsetY = 0;
    		spriteData = null;
    	}
    
    	/**
    	 * Reads the information from the index and data files.
    	 *
    	 * @param index holds the sprite indices
    	 * @param data holds the sprite data per index
    	 * @throws IOException
    	 */
    	private void readValues(DataInputStream index, DataInputStream data) throws IOException {
    		do {
    			int opcode = data.readByte();
    
    			if (opcode == 0) {
    				break;
    			}
    			if (opcode == 1) {
    				id = data.readShort();
    			} else if (opcode == 2) {
    				data.readUTF();
    			} else if (opcode == 3) {
    				drawOffsetX = data.readShort();
    			} else if (opcode == 4) {
    				drawOffsetY = data.readShort();
    			} else if (opcode == 5) {
    				int indexLength = index.readInt();
    				byte[] dataread = new byte[indexLength];
    				data.readFully(dataread);
    				spriteData = dataread;
    			}
    		} while (true);
    	}
    
    }
    [/sp]
    Reply With Quote  
     

  2. #2  
    PHP Developer

    Join Date
    Oct 2017
    Posts
    40
    Thanks given
    1
    Thanks received
    7
    Rep Power
    14
    You already have the code there?

    Code:
    File directory = new File(Signlink.getCacheDirectory().toString() + "/sprites"); 
    if (!directory.exists()) { 
         directory.mkdir(); 
    } 
    FileUtilities.WriteFile(directory.getAbsolutePath() + System.getProperty("file.separator") + sprite.id + ".png", sprite.spriteData);
    Reply With Quote  
     


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. How to pack sprites into necrotic?
    By Zarte in forum Help
    Replies: 1
    Last Post: 04-24-2019, 11:43 AM
  2. Replies: 3
    Last Post: 05-27-2018, 05:28 AM
  3. Replies: 5
    Last Post: 03-22-2018, 09:14 PM
  4. How to create sprites.
    By Fallen Azn SinZ in forum Tutorials
    Replies: 8
    Last Post: 02-03-2008, 03:26 AM
  5. Need a tut on how to make Sprites.
    By Hooligan in forum Graphics
    Replies: 6
    Last Post: 12-22-2007, 10:45 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
  •