// Path: src/base/Encoder.java
// public interface Encoder {
//     public abstract  void compile(String filelist);
// }
// 
// Path: src/base/HelperEnc.java
// public abstract class HelperEnc extends MHUtils {
//     protected String readString(RandomAccessFile file) throws IOException {
//         byte[] buffer = new byte[1024];
//         byte data = 0;
//         boolean eol = false;
//         int counter = 0;
//         try {
//             while (!eol) {
//                 switch (data = file.readByte()) {
//                 case '\n':
//                     eol = true;
//                     break;
//                 case '\r':
//                     eol = true;
//                     long cur = file.getFilePointer();
//                     if (file.readByte() != '\n') {
//                         file.seek(cur);
//                         eol = false;
//                     }
//                     break;
//                 default:
//                     buffer[counter++] = data;
//                     break;
//                 }
//             }
//         } catch (EOFException e) {
//             return null;
//         }
//         return new String(buffer, 0, counter, "UTF-8");
//     }
// 
//     /**
//      * Checks if the file have the unicode BOM mark and skip it
//      * (thanks notepad grr..)
//      * 
//      * @param file
//      * @throws IOException
//      *             if any error occur while reading
//      */
//     protected void checkUnicodeBOM(RandomAccessFile file) throws IOException {
//         int a = file.readByte();
//         int b = file.readByte();
//         int c = file.readByte();
//         if (a != -17 || b != -69 || c != -65) {
//             file.seek(0);
//         }
//     }
// }


import java.io.BufferedReader;
import java.io.EOFException;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Vector;
import base.Encoder;
import base.HelperEnc;
/*  MHTools - MHP 0016/475x/0017.bin language table rebuilder
    Copyright (C) 2008-2011 Codestation

    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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
 */

package enc;



/**
 * RebuildPluginA v2.0 - 0016/475x.bin language table rebuilder
 * 
 * @author Codestation
 */
public class RebuildPluginA extends HelperEnc implements Encoder {

    @Override
    public void compile(String filepath) {
        try {
            BufferedReader files = new BufferedReader(new FileReader(filepath
                    + "/filelist.txt"));
            String file = files.readLine();
            // retrieve the filename and size
            String filename = file.split(" ")[0];
            long size = Integer.parseInt(file.split(" ")[1]);
            // now make a list with the string tables files
            Vector<String> filenames = new Vector<String>();
            while ((file = files.readLine()) != null) {
                filenames.add(file);
            }
            files.close();
// Path: src/base/Encoder.java
// public interface Encoder {
//     public abstract  void compile(String filelist);
// }
// 
// Path: src/base/HelperEnc.java
// public abstract class HelperEnc extends MHUtils {
//     protected String readString(RandomAccessFile file) throws IOException {
//         byte[] buffer = new byte[1024];
//         byte data = 0;
//         boolean eol = false;
//         int counter = 0;
//         try {
//             while (!eol) {
//                 switch (data = file.readByte()) {
//                 case '\n':
//                     eol = true;
//                     break;
//                 case '\r':
//                     eol = true;
//                     long cur = file.getFilePointer();
//                     if (file.readByte() != '\n') {
//                         file.seek(cur);
//                         eol = false;
//                     }
//                     break;
//                 default:
//                     buffer[counter++] = data;
//                     break;
//                 }
//             }
//         } catch (EOFException e) {
//             return null;
//         }
//         return new String(buffer, 0, counter, "UTF-8");
//     }
// 
//     /**
//      * Checks if the file have the unicode BOM mark and skip it
//      * (thanks notepad grr..)
//      * 
//      * @param file
//      * @throws IOException
//      *             if any error occur while reading
//      */
//     protected void checkUnicodeBOM(RandomAccessFile file) throws IOException {
//         int a = file.readByte();
//         int b = file.readByte();
//         int c = file.readByte();
//         if (a != -17 || b != -69 || c != -65) {
//             file.seek(0);
//         }
//     }
// }


// Path: src/enc/RebuildPluginA.java
import java.io.BufferedReader;
import java.io.EOFException;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Vector;
import base.Encoder;
import base.HelperEnc;

/*  MHTools - MHP 0016/475x/0017.bin language table rebuilder
    Copyright (C) 2008-2011 Codestation

    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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
 */

package enc;



/**
 * RebuildPluginA v2.0 - 0016/475x.bin language table rebuilder
 * 
 * @author Codestation
 */
public class RebuildPluginA extends HelperEnc implements Encoder {

    @Override
    public void compile(String filepath) {
        try {
            BufferedReader files = new BufferedReader(new FileReader(filepath
                    + "/filelist.txt"));
            String file = files.readLine();
            // retrieve the filename and size
            String filename = file.split(" ")[0];
            long size = Integer.parseInt(file.split(" ")[1]);
            // now make a list with the string tables files
            Vector<String> filenames = new Vector<String>();
            while ((file = files.readLine()) != null) {
                filenames.add(file);
            }
            files.close();
            RandomAccessFile out = new RandomAccessFile(filename + ".out", "rw");