Java wdt class finished reads & writes menu

User Tag List

Results 1 to 6 of 6
  1. #1
    danielrhodea's Avatar Master Sergeant
    Reputation
    11
    Join Date
    Apr 2010
    Posts
    107
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Java wdt class finished reads & writes

    :wave: Here it is my finished WDT java class, it's perfect for my needs!

    Usage:
    !!!Obviously include in your project and add to namespace to reflect directory structure
    WDT wdt = new WDT("absolutefilepath",true);//auto opens wdt
    WDT wdt = new WDT("absolutefilepath",false);//needs wdt.read() to open
    wdt.debugMode() // toggles tracing of info
    wdt.setActive(row,col); // sets an adt tile to become active
    wdt.setInactive(row,col); // sets an adt tile to become inactive
    wdt.write(filename); // writes to file (try not to overwrite it's untested and may break the file)

    NOTE: Always keep a backup of the file!

    Code:
    import java.io.*;
    import java.lang.String;
    public class WDT
    {
    	private boolean[] fileperms = {false,false};
    	private String filename = "";
    	private boolean debug = true;
    	
    	private boolean[] data = new boolean[4096];//because there are 64*64 possibilities 
    	
    	public WDT(String _filename, boolean autoOpen)
    	{
    		filename = _filename;
    		File fil = new File(_filename);
    		if(fil.canRead())//check read capability
    			fileperms[0] = true;
    		
    		if(fil.canWrite())//check write capability
    			fileperms[1] = true;
    
    		if(autoOpen)
    			read();
    	}
    	private char[] flip(char[] target)
    	{
    		char[] tmp = new char[target.length];
    		for(int i=0;i<target.length;i++)
    		{
    			tmp[(tmp.length-i)-1] = target[i];	
    		}
    		return tmp;
    	}
    	
    	private void trace()
    	{
    		for(int row = 1; row<=64 ;row++)
    		{
    			for(int col = 1;col<=64;col++)
    			{
    				System.out.print( ((data[((row-1)*64)+(col-1)]) ? ("x") : ("0")) + ((col == 64)?("\n"):("")) );// = ( ( (fourcc[0]|fourcc[1]|fourcc[2]|fourcc[3]) & 1 ) == 1) ? (true) : (false);
    			}
    		}
    	}
    	
    	public boolean read()
    	{
    		if(!fileperms[0])
    			return false;
    		
    		try
    		{
    			FileReader f = new FileReader(filename);
    			char[] fourcc = new char[4];
    
    			boolean eof = false;			
    			while (!eof)
    			{
    				int tmp = f.read(fourcc);
    				if(tmp == -1)
    					eof = true;
    				fourcc = flip(fourcc);
    
    				if((fourcc[0] == 'M') && (fourcc[1] == 'A') && (fourcc[2] == 'I') && (fourcc[3] == 'N'))
    				{
    					f.read(fourcc);
    					f.read(fourcc);
    					for(int row = 1; row<=64 ;row++)
    					{
    						for(int col = 1;col<=64;col++)
    						{
    							f.read(fourcc);
    							f.read(fourcc);
    
    							data[((row-1)*64)+(col-1)] = ( ( (fourcc[0]|fourcc[1]|fourcc[2]|fourcc[3]) & 1 ) == 1) ? (true) : (false);
    						}
    					}
    				}
    			}
    			if(debug)
    				trace();
    		}
    		catch(IOException ioexc)
    		{
    
    		}
    		return true;
    	}
    	
    	public void debugMode()
    	{
    		debug = !debug;
    	}
    	
    	public void setActive(int row, int col)
    	{
    		(data[((row-1)*64)+(col-1)]) = true;
    	}
    	
    	public void setInactive(int row, int col)
    	{
    		(data[((row-1)*64)+(col-1)]) = false;
    	}
    	
    	public boolean write(String _filename)
    	{
    		if(!fileperms[0])
    			return false;
    
    		try
    		{
    			File file = new File(filename);
    			long bytes = file.length();
    			FileReader fr = new FileReader(filename);
    			char[] fourcc = new char[4];
    			FileWriter fw = new FileWriter(_filename);
    			fw.flush();
    			
    			int test = 0;
    			while(bytes > 0)
    			{
    				if(bytes > 4)
    				{
    					fr.read(fourcc);
    					if(String.copyValueOf(fourcc) != "NIAM")
    					{
    						fw.append(fourcc[0]);
    						fw.append(fourcc[1]);
    						fw.append(fourcc[2]);
    						fw.append(fourcc[3]);
    						bytes -= 4;
    					}
    					else
    					{
    						fw.append(fourcc[0]);
    						fw.append(fourcc[1]);
    						fw.append(fourcc[2]);
    						fw.append(fourcc[3]);
    						bytes -= 4;
    						
    						fr.read(fourcc);
    						fw.append(fourcc[0]);
    						fw.append(fourcc[1]);
    						fw.append(fourcc[2]);
    						fw.append(fourcc[3]);
    						bytes -= 4;
    						
    						fr.read(fourcc);
    						fw.append(fourcc[0]);
    						fw.append(fourcc[1]);
    						fw.append(fourcc[2]);
    						fw.append(fourcc[3]);
    						bytes -= 4;
    						
    						for(int row = 1; row<=64 ;row++)
    						{
    							for(int col = 1;col<=64;col++)
    							{
    								fw.append((char)(0));
    								fw.append((char)(0));
    								fw.append((char)(0));
    								fw.append((char)(0));
    
    								fw.append((char)(0));
    								fw.append((char)(0));
    								fw.append((char)(0));
    								fw.append((char)((data[((row-1)*64)+(col-1)]) ? (1) : (0)));
    
    							}
    						}
    
    					}
    					
    				}
    				else
    				{
    					fw.append((char)fr.read());
    					bytes --;
    				}
    				
    			}
    			//EOF (fr.read() returned -1)
    			fw.close();
    			fr.close();
    		}
    		catch(IOException ioexc)
    		{
    			return false;
    		}
    		return true;
    	}
    }

    Java wdt class finished reads &amp; writes
  2. #2
    DeathKnight117's Avatar Private
    Reputation
    3
    Join Date
    Apr 2010
    Posts
    10
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    does it work for a mac?

  3. #3
    danielrhodea's Avatar Master Sergeant
    Reputation
    11
    Join Date
    Apr 2010
    Posts
    107
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    untested as I d not have a mac but it should because it's a java class (it's not a standalne program as such but it would be rather easy to make into one)

    java is not a compiled language as such and should make it multi-platform

  4. #4
    danielrhodea's Avatar Master Sergeant
    Reputation
    11
    Join Date
    Apr 2010
    Posts
    107
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    WTF I can see ldz I have contributed to this website, why am I branded a leecher, this code works and is 100% mine ???

  5. #5
    The-Eradicator's Avatar Contributor

    Reputation
    149
    Join Date
    May 2007
    Posts
    829
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by danielrhodea View Post
    WTF I can see ldz I have contributed to this website, why am I branded a leecher, this code works and is 100% mine ???
    You start off as a leecher until you have ~15? rep, at which point you become an Active Member.
    The most beautiful thing we can experience is the mysterious. It is the source of all true art and all science. He to whom this emotion is a stranger, who can no longer pause to wonder and stand rapt in awe, is as good as dead: his eyes are closed.
    Albert Einstein

  6. #6
    danielrhodea's Avatar Master Sergeant
    Reputation
    11
    Join Date
    Apr 2010
    Posts
    107
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can't believe i dont have more than 15 rep... oh well

Similar Threads

  1. Make your own Bot with Java Robot Class
    By whappit in forum Programming
    Replies: 19
    Last Post: 09-27-2015, 06:07 AM
  2. Reading and writing strings
    By miceiken in forum WoW Memory Editing
    Replies: 9
    Last Post: 03-10-2010, 03:49 PM
  3. LUA Help (reading from/writing to files)
    By tagala in forum WoW EMU Questions & Requests
    Replies: 2
    Last Post: 10-05-2009, 06:48 PM
  4. How to get read AND write access to wow process?
    By Shutzler in forum WoW Memory Editing
    Replies: 8
    Last Post: 09-26-2009, 04:16 PM
  5. Need help reading Memory, Writing too memory
    By Neer in forum Programming
    Replies: 0
    Last Post: 08-17-2009, 12:11 PM
All times are GMT -5. The time now is 05:36 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search