All pastes #18323 Raw Edit

Stuff

public java v1 · immutable
#18323 ·published 2005-07-23 02:05 UTC
rendered paste body
import java.io.BufferedReader;import java.io.File;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStreamReader;import java.io.RandomAccessFile;/* * $Header: UtExtract.java, 22/07/2005 16:52:18 luisantonioa Exp $ * * $Author: luisantonioa $ * $Date: 22/07/2005 16:52:18 $ * $Revision: 1 $ * $Log: UtExtract.java,v $ * Revision 1  22/07/2005 16:52:18  luisantonioa * Added copyright notice * *  * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * http://www.gnu.org/copyleft/gpl.html *//** * This class ... *  * @version $Revision: 1.2 $ $Date: 2004/06/27 08:12:59 $ */public class UtExtract{    private static int      FILE_SZIE   = 1024;    private static byte[]   buffer;    private static RandomAccessFile reader;        public static void main(String[] args) throws IOException    {        UtExtract u = new UtExtract();                while (true)        {            System.out.print("Please enter path to Lineage 2 Directory.\n> ");            String input    = new BufferedReader(new InputStreamReader(System.in)).readLine();            if (input == null)                return;            File dir        = new File(input.replace("\\", "/") + "/MAPS");                        if (!dir.isDirectory())            {                System.out.println("Not a Directory");                continue;            }                        File[] mapList  = dir.listFiles();                        for (File file : mapList)            {                u.open(file);            }                        break;        }                Runtime rt  = Runtime.getRuntime();        String s    = "del dec-*.unr";        //System.out.println(s);        //if (file != null) return;        try        {            Process p   = rt.exec(s);            p.waitFor();        }        catch (IOException e)        {            e.printStackTrace();        }        catch (InterruptedException e)        {            // TODO Auto-generated catch block            e.printStackTrace();        }    }        public class ObjectData    {        public long classID;        public long superID;        public int  group;        public long name;        public int  flags;        public long size;        public long offset;    }        public void open(File file)    {        Runtime rt  = Runtime.getRuntime();        String s    = "l2encdec.exe -s \"" + file.getAbsolutePath() + "\" dec-" + file.getName();        System.out.println(s);        if (file != null) return;        try        {            Process p   = rt.exec(s);            p.waitFor();        }        catch (IOException e)        {            e.printStackTrace();        }        catch (InterruptedException e)        {            // TODO Auto-generated catch block            e.printStackTrace();        }                File newFile    = new File("dec-" + file.getName());        try        {            reader  = new RandomAccessFile(newFile, "r");            reader.seek(0x14);            int count               = readD();            long exportTableOffset  = readD();                        System.out.println("Export Table Count:   " + count);            System.out.println("Export Table Offset: " + Long.toHexString(exportTableOffset));                        reader.seek(exportTableOffset);            ObjectData current  = null;            ObjectData maximum  = null;                        for (int i=0; i < count; i++)            {                current         = new ObjectData();                current.classID = readI();                current.superID = readI();                current.group   = readD();                current.name    = readI();                current.flags   = readD();                current.size    = readI();                current.offset  = (current.size > 0) ? readI() : 0;                                if (maximum == null || current.size > maximum.size)                {                    maximum = current;                }            }                        if (maximum == null)            {                return;            }            System.out.println("Maximum Object Size:   " + maximum.size);            System.out.println("Maximum Object Offset: " + Long.toHexString(maximum.offset));                        File output             = new File(file.getName().replace(".unr", ".dat"));            output.delete();            RandomAccessFile out    = new RandomAccessFile(output, "rwd");                        reader.seek(maximum.offset);                        buffer              = new byte[1024*16];            int bytesRead       = reader.read(buffer, 0, Math.min(buffer.length, (int)maximum.size));            int totalWritten    = 0;                        while (bytesRead > 0 || totalWritten < maximum.size)            {                out.write(buffer, 0, bytesRead);                totalWritten    += bytesRead;                int toWrite     = Math.min(buffer.length, (int)maximum.size - totalWritten);                bytesRead       = reader.read(buffer, 0, toWrite);            }                        System.out.println("Bytes Written: " + totalWritten);        }        catch (FileNotFoundException e)        {            e.printStackTrace();        }        catch (IOException e)        {            e.printStackTrace();        }    }     public int readD() throws IOException    {        int result = read() &0xff;        result |= read() << 8 &0xff00;        result |= read() << 0x10 &0xff0000;        result |= read() << 0x18 &0xff000000;        return result;    }        public byte read() throws IOException    {        return reader.readByte();    }        public long readI() throws IOException    {        byte b          = read();        boolean sign    = ((b & 0x80) == 0x80);        boolean next    = ((b & 0x40) == 0x40);        long result     = b & 0x3f;        int shift       = 6;        while (next)        {            b       = read();            next    = ((b & 0x80) == 0x80);            result  |= (b & 0x7f) << shift;            shift   += 7;        }        return result;    }}