mirror of
https://github.com/codestation/mhtools
synced 2024-11-10 05:44:17 +00:00
Forgot to code formatting before the first commit -_-#
This commit is contained in:
parent
acf5415bd8
commit
f5e08987d6
12 changed files with 1325 additions and 1268 deletions
|
@ -34,7 +34,8 @@ public abstract class Decoder {
|
|||
* @throws IOException
|
||||
* if any error occur while reading
|
||||
*/
|
||||
protected int readInt(RandomAccessFile file) throws IOException, EOFException {
|
||||
protected int readInt(RandomAccessFile file) throws IOException,
|
||||
EOFException {
|
||||
int ch1 = file.read();
|
||||
int ch2 = file.read();
|
||||
int ch3 = file.read();
|
||||
|
@ -46,8 +47,8 @@ public abstract class Decoder {
|
|||
}
|
||||
|
||||
/**
|
||||
* Some hex-edited files have some extra zeros at the end of the strings so
|
||||
* its better to skip them
|
||||
* Some hex-edited files have some extra zeros at the end of the strings
|
||||
* so its better to skip them
|
||||
*
|
||||
* @param file
|
||||
* @throws IOException
|
||||
|
@ -61,8 +62,8 @@ public abstract class Decoder {
|
|||
}
|
||||
|
||||
/**
|
||||
* The "readUTF8" function of java expects a different format of the string
|
||||
* so i have to make a custom one
|
||||
* The "readUTF8" function of java expects a different format of the
|
||||
* string so i have to make a custom one
|
||||
*
|
||||
* @param file
|
||||
* @return string extracted from file
|
||||
|
|
|
@ -26,8 +26,8 @@ public abstract class Encoder {
|
|||
public abstract void compile(String filelist);
|
||||
|
||||
/**
|
||||
* The "readUTF8" function of java expects a different format of the string
|
||||
* so i have to make a custom one.
|
||||
* The "readUTF8" function of java expects a different format of
|
||||
* the string so i have to make a custom one.
|
||||
*
|
||||
* @param file
|
||||
* @return string extracted from file
|
||||
|
@ -65,8 +65,8 @@ public abstract class Encoder {
|
|||
}
|
||||
|
||||
/**
|
||||
* Checks if the file have the unicode BOM mark and skip it (thanks notepad
|
||||
* grr..)
|
||||
* Checks if the file have the unicode BOM mark and skip it
|
||||
* (thanks notepad grr..)
|
||||
*
|
||||
* @param file
|
||||
* @throws IOException
|
||||
|
@ -89,7 +89,8 @@ public abstract class Encoder {
|
|||
* @throws IOException
|
||||
* if any error occur while writing
|
||||
*/
|
||||
protected void writeInt(RandomAccessFile file, int value) throws IOException {
|
||||
protected void writeInt(RandomAccessFile file, int value)
|
||||
throws IOException {
|
||||
int ch1 = (byte) (value >>> 24);
|
||||
int ch2 = (byte) (value >>> 16);
|
||||
int ch3 = (byte) (value >>> 8);
|
||||
|
@ -109,7 +110,8 @@ public abstract class Encoder {
|
|||
* @throws IOException
|
||||
* if any error occur while reading
|
||||
*/
|
||||
protected int readInt(RandomAccessFile file) throws IOException, EOFException {
|
||||
protected int readInt(RandomAccessFile file) throws IOException,
|
||||
EOFException {
|
||||
int ch1 = file.read();
|
||||
int ch2 = file.read();
|
||||
int ch3 = file.read();
|
||||
|
|
|
@ -138,7 +138,8 @@ public class Mhtrans {
|
|||
}
|
||||
rebuild(args[1], args[2]);
|
||||
String filename = new File(args[1]).getName();
|
||||
new Encrypter().encrypt(filename + ".bin.out", filename + ".bin.enc");
|
||||
new Encrypter().encrypt(filename + ".bin.out", filename
|
||||
+ ".bin.enc");
|
||||
System.out.println("Moving to " + filename + ".bin.enc");
|
||||
new File(filename + ".bin.out").delete();
|
||||
} else if (args[0].equals("--gen-index")) {
|
||||
|
|
|
@ -106,15 +106,14 @@ public abstract class DecryptTable {
|
|||
}
|
||||
|
||||
protected long get_table_value(byte table[], int pos) {
|
||||
return (table[pos] & 0xFF)
|
||||
+ ((long) (table[pos+1] & 0xFF) << 8)
|
||||
return (table[pos] & 0xFF) + ((long) (table[pos + 1] & 0xFF) << 8)
|
||||
+ ((long) (table[pos + 2] & 0xFF) << 16)
|
||||
+ ((long) (table[pos + 3] & 0xFF) << 24);
|
||||
}
|
||||
|
||||
/*
|
||||
* Can't use the RandomAccessFile readInt func as we need the bytes
|
||||
* in reverse order
|
||||
* Can't use the RandomAccessFile readInt func as we need the bytes in
|
||||
* reverse order
|
||||
*/
|
||||
private int readInt(RandomAccessFile file) throws IOException, EOFException {
|
||||
int ch1 = file.read();
|
||||
|
@ -127,7 +126,8 @@ public abstract class DecryptTable {
|
|||
return (ch4 << 24) + (ch3 << 16) + (ch2 << 8) + (ch1 << 0);
|
||||
}
|
||||
|
||||
protected int getOffset(int value) throws EOFException, FileNotFoundException, IOException {
|
||||
protected int getOffset(int value) throws EOFException,
|
||||
FileNotFoundException, IOException {
|
||||
int res = -1;
|
||||
if (value == 0) {
|
||||
res = 0;
|
||||
|
@ -141,6 +141,7 @@ public abstract class DecryptTable {
|
|||
}
|
||||
|
||||
protected int extractNumber(String filename) {
|
||||
return Integer.parseInt(filename.substring(filename.indexOf(".") - 4, filename.indexOf(".")));
|
||||
return Integer.parseInt(filename.substring(filename.indexOf(".") - 4,
|
||||
filename.indexOf(".")));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,7 +83,8 @@ public class Decrypter extends DecryptTable {
|
|||
for (int i = 0; i < files_count; i++) {
|
||||
if (create_subdirectory) {
|
||||
last_subdirectory = i / 1000;
|
||||
new File(out + "/0" + Integer.toString(last_subdirectory)).mkdir();
|
||||
new File(out + "/0" + Integer.toString(last_subdirectory))
|
||||
.mkdir();
|
||||
create_subdirectory = false;
|
||||
} else {
|
||||
if (last_subdirectory < i / 1000) {
|
||||
|
@ -93,10 +94,11 @@ public class Decrypter extends DecryptTable {
|
|||
long offset = last_offset;
|
||||
last_offset = get_table_value(index_table, i * 4);
|
||||
long file_length = (get_table_value(index_table, i * 4) - offset) << 11;
|
||||
String fileout = out +
|
||||
"/0" + Integer.toString(last_subdirectory) +
|
||||
"/" + String.format("%04d.bin", i);
|
||||
System.out.print("Decrypting " + fileout + "(" + file_length + " bytes/offset: " + (offset << 11) + ") ... ");
|
||||
String fileout = out + "/0"
|
||||
+ Integer.toString(last_subdirectory) + "/"
|
||||
+ String.format("%04d.bin", i);
|
||||
System.out.print("Decrypting " + fileout + "(" + file_length
|
||||
+ " bytes/offset: " + (offset << 11) + ") ... ");
|
||||
decrypt_internal(filein, offset, file_length, fileout, false);
|
||||
|
||||
}
|
||||
|
@ -105,7 +107,8 @@ public class Decrypter extends DecryptTable {
|
|||
}
|
||||
}
|
||||
|
||||
private void decrypt_internal(RandomAccessFile filein, long pos, long size, String out, boolean single) {
|
||||
private void decrypt_internal(RandomAccessFile filein, long pos, long size,
|
||||
String out, boolean single) {
|
||||
try {
|
||||
if (!single)
|
||||
filein.seek(pos << 11);
|
||||
|
@ -142,7 +145,8 @@ public class Decrypter extends DecryptTable {
|
|||
try {
|
||||
filein = new RandomAccessFile(in, "r");
|
||||
System.out.print("Decrypting " + out + " ... ");
|
||||
decrypt_internal(filein, getOffset(extractNumber(in)), filein.length(), out, true);
|
||||
decrypt_internal(filein, getOffset(extractNumber(in)),
|
||||
filein.length(), out, true);
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -52,13 +52,17 @@ public class ExtractPluginA extends Decoder {
|
|||
String directory = filename.split("\\.")[0];
|
||||
new File(directory).mkdir();
|
||||
// create the list of string tables used in the rebuild
|
||||
PrintStream filelist = new PrintStream(new FileOutputStream(new File(directory + "/filelist.txt")), true, "UTF-8");
|
||||
PrintStream filelist = new PrintStream(new FileOutputStream(
|
||||
new File(directory + "/filelist.txt")), true, "UTF-8");
|
||||
// save the name and size of the file
|
||||
filelist.println(filename + " " + file.length());
|
||||
for (int j = 0; j < tables_count; j++) {
|
||||
if (table_offset[j] == -1) {
|
||||
//System.out.println("Creating " + directory + "/string_table_" + j + ".txt (empty)");
|
||||
System.out.println("Can't create " + directory + "/string_table_" + j + ".txt (null table), skipping.");
|
||||
// System.out.println("Creating " + directory +
|
||||
// "/string_table_" + j + ".txt (empty)");
|
||||
System.out.println("Can't create " + directory
|
||||
+ "/string_table_" + j
|
||||
+ ".txt (null table), skipping.");
|
||||
File f = new File(directory + "/string_table_" + j + ".txt");
|
||||
f.delete();
|
||||
// f.createNewFile();
|
||||
|
@ -66,8 +70,11 @@ public class ExtractPluginA extends Decoder {
|
|||
continue;
|
||||
}
|
||||
file.seek(table_offset[j]);
|
||||
System.out.println("Creating " + directory + "/string_table_" + j + ".txt");
|
||||
PrintStream stringout = new PrintStream(new FileOutputStream(new File(directory + "/string_table_" + j + ".txt")), true, "UTF-8");
|
||||
System.out.println("Creating " + directory + "/string_table_"
|
||||
+ j + ".txt");
|
||||
PrintStream stringout = new PrintStream(new FileOutputStream(
|
||||
new File(directory + "/string_table_" + j + ".txt")),
|
||||
true, "UTF-8");
|
||||
filelist.println("string_table_" + j + ".txt");
|
||||
int offsetCounter = 0;
|
||||
// just skip the offset section (not needed)
|
||||
|
@ -99,13 +106,14 @@ public class ExtractPluginA extends Decoder {
|
|||
stringout.close();
|
||||
}
|
||||
file.seek(file.getFilePointer() - 1);
|
||||
// calculate the size of the ending padding data and make a file of
|
||||
// it
|
||||
// calculate the size of the ending padding data and make
|
||||
// a file of it
|
||||
int size = (int) (file.length() - file.getFilePointer());
|
||||
paddingData = new byte[size];
|
||||
file.read(paddingData, 0, size);
|
||||
System.out.println("Creating " + directory + "/enddata.bin");
|
||||
RandomAccessFile end = new RandomAccessFile(directory + "/enddata.bin", "rw");
|
||||
RandomAccessFile end = new RandomAccessFile(directory
|
||||
+ "/enddata.bin", "rw");
|
||||
filelist.println("enddata.bin");
|
||||
end.write(paddingData, 0, size);
|
||||
end.setLength(end.getFilePointer());
|
||||
|
|
|
@ -38,6 +38,7 @@ import base.Decoder;
|
|||
public class ExtractPluginB extends Decoder {
|
||||
|
||||
private int mhp3_skip_bytes;
|
||||
|
||||
public ExtractPluginB(boolean newdec) {
|
||||
mhp3_skip_bytes = newdec ? 4 : 0;
|
||||
}
|
||||
|
@ -59,12 +60,16 @@ public class ExtractPluginB extends Decoder {
|
|||
}
|
||||
String directory = filename.split("\\.")[0];
|
||||
new File(directory).mkdir();
|
||||
PrintStream filelist = new PrintStream(new FileOutputStream(new File(directory + "/filelist.txt")), true, "UTF-8");
|
||||
PrintStream filelist = new PrintStream(new FileOutputStream(
|
||||
new File(directory + "/filelist.txt")), true, "UTF-8");
|
||||
filelist.println(filename + " " + file.length());
|
||||
for (int j = 0; j < table_offset.size(); j++) {
|
||||
file.seek(table_offset.get(j));
|
||||
System.out.println("Creating " + directory + "/string_table_" + j + ".txt");
|
||||
PrintStream stringout = new PrintStream(new FileOutputStream(new File(directory + "/string_table_" + j + ".txt")), true, "UTF-8");
|
||||
System.out.println("Creating " + directory + "/string_table_"
|
||||
+ j + ".txt");
|
||||
PrintStream stringout = new PrintStream(new FileOutputStream(
|
||||
new File(directory + "/string_table_" + j + ".txt")),
|
||||
true, "UTF-8");
|
||||
filelist.println("string_table_" + j + ".txt");
|
||||
// int unknown0 = readInt(file);
|
||||
// int payment = readInt(file);
|
||||
|
@ -102,20 +107,22 @@ public class ExtractPluginB extends Decoder {
|
|||
stringout.close();
|
||||
file.seek(offset_table_pointer + 7 * 4);
|
||||
}
|
||||
// calculate the size of the ending unknown data and make a file of
|
||||
// it
|
||||
// calculate the size of the ending unknown data and
|
||||
// make a file of it
|
||||
int size = (int) (file.length() - file.getFilePointer());
|
||||
unknownData = new byte[size];
|
||||
file.read(unknownData, 0, size);
|
||||
System.out.println("Creating " + directory + "/enddata.bin");
|
||||
RandomAccessFile end = new RandomAccessFile(directory + "/enddata.bin", "rw");
|
||||
RandomAccessFile end = new RandomAccessFile(directory
|
||||
+ "/enddata.bin", "rw");
|
||||
filelist.println("enddata.bin");
|
||||
end.write(unknownData, 0, size);
|
||||
end.setLength(end.getFilePointer());
|
||||
end.close();
|
||||
file.close();
|
||||
filelist.close();
|
||||
System.out.println("Copying " + filename + " to " + directory + "/" + filename + " (needed for rebuild)");
|
||||
System.out.println("Copying " + filename + " to " + directory + "/"
|
||||
+ filename + " (needed for rebuild)");
|
||||
copyfile(filename, directory + "/" + filename);
|
||||
System.out.println("Finished!");
|
||||
} catch (IOException e) {
|
||||
|
@ -138,7 +145,8 @@ public class ExtractPluginB extends Decoder {
|
|||
in.close();
|
||||
out.close();
|
||||
} catch (FileNotFoundException ex) {
|
||||
System.out.println(ex.getMessage() + " in the specified directory.");
|
||||
System.out
|
||||
.println(ex.getMessage() + " in the specified directory.");
|
||||
System.exit(0);
|
||||
} catch (IOException e) {
|
||||
System.out.println(e.getMessage());
|
||||
|
|
|
@ -52,16 +52,21 @@ public class ExtractPluginC extends Decoder {
|
|||
String directory = filename.split("\\.")[0];
|
||||
new File(directory).mkdir();
|
||||
// create the list of string tables used in the rebuild
|
||||
PrintStream filelist = new PrintStream(new FileOutputStream(new File(directory + "/filelist.txt")), true, "UTF-8");
|
||||
PrintStream filelist = new PrintStream(new FileOutputStream(
|
||||
new File(directory + "/filelist.txt")), true, "UTF-8");
|
||||
// save the name and size of the file
|
||||
filelist.println(filename + " " + file.length());
|
||||
int string_table_end = 0;
|
||||
;
|
||||
for (int j = 0; j < offset_tables.size(); j++) {
|
||||
file.seek(offset_tables.get(j));
|
||||
System.out.println("Creating " + directory + "/string_table_" + j + ".txt");
|
||||
PrintStream stringout = new PrintStream(new FileOutputStream(new File(directory + "/string_table_" + j + ".txt")), true, "UTF-8");
|
||||
filelist.println(unknown_values.get(j) + ",string_table_" + j + ".txt");
|
||||
System.out.println("Creating " + directory + "/string_table_"
|
||||
+ j + ".txt");
|
||||
PrintStream stringout = new PrintStream(new FileOutputStream(
|
||||
new File(directory + "/string_table_" + j + ".txt")),
|
||||
true, "UTF-8");
|
||||
filelist.println(unknown_values.get(j) + ",string_table_" + j
|
||||
+ ".txt");
|
||||
int offset_table_start = (int) file.getFilePointer();
|
||||
int string_table_start = 0;
|
||||
boolean first = false;
|
||||
|
@ -96,14 +101,15 @@ public class ExtractPluginC extends Decoder {
|
|||
stringout.close();
|
||||
}
|
||||
file.seek(string_table_end);
|
||||
// calculate the size of the ending unknown data and make a file of
|
||||
// it
|
||||
// calculate the size of the ending unknown data and
|
||||
// make a file of it
|
||||
int size = (int) (file.length() - file.getFilePointer());
|
||||
byte[] unknownData = new byte[size];
|
||||
file.read(unknownData, 0, size);
|
||||
file.close();
|
||||
System.out.println("Creating " + directory + "/enddata.bin");
|
||||
RandomAccessFile end = new RandomAccessFile(directory + "/enddata.bin", "rw");
|
||||
RandomAccessFile end = new RandomAccessFile(directory
|
||||
+ "/enddata.bin", "rw");
|
||||
filelist.println("enddata.bin");
|
||||
filelist.close();
|
||||
end.write(unknownData, 0, size);
|
||||
|
|
|
@ -37,7 +37,8 @@ public class RebuildPluginA extends Encoder {
|
|||
@Override
|
||||
public void compile(String filepath) {
|
||||
try {
|
||||
BufferedReader files = new BufferedReader(new FileReader(filepath + "/filelist.txt"));
|
||||
BufferedReader files = new BufferedReader(new FileReader(filepath
|
||||
+ "/filelist.txt"));
|
||||
String file = files.readLine();
|
||||
// retrieve the filename and size
|
||||
String filename = file.split(" ")[0];
|
||||
|
@ -74,7 +75,8 @@ public class RebuildPluginA extends Encoder {
|
|||
if (i < filenames.size() - 2) {
|
||||
long current = out.getFilePointer();
|
||||
out.seek(table_offset);
|
||||
// now we know the value of the next table, so write above
|
||||
// now we know the value of the next table, so write
|
||||
// above
|
||||
// in the main offset table
|
||||
writeInt(out, (int) current);
|
||||
out.seek(current);
|
||||
|
@ -82,7 +84,8 @@ public class RebuildPluginA extends Encoder {
|
|||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
// New in MHP3: null tables
|
||||
System.out.println(filenames.get(i) + " not found, assuming null table pointer.");
|
||||
System.out.println(filenames.get(i)
|
||||
+ " not found, assuming null table pointer.");
|
||||
if (i < filenames.size() - 2) {
|
||||
long current = out.getFilePointer();
|
||||
out.seek(table_offset - 4);
|
||||
|
@ -98,16 +101,21 @@ public class RebuildPluginA extends Encoder {
|
|||
}
|
||||
// we need to know the size of the enddata, so open it now
|
||||
System.out.println("Reading " + filenames.lastElement());
|
||||
RandomAccessFile enddata = new RandomAccessFile(filepath + "/" + filenames.lastElement(), "rw");
|
||||
RandomAccessFile enddata = new RandomAccessFile(filepath + "/"
|
||||
+ filenames.lastElement(), "rw");
|
||||
|
||||
long enddataSize = enddata.length();
|
||||
|
||||
// some checks to make sure that the file size of xxxx.bin is
|
||||
// correct
|
||||
if (out.getFilePointer() > size - enddataSize) {
|
||||
System.out.println("File too big (by " + (out.getFilePointer() - (size - enddataSize))+ " bytes), please reduce some strings :(");
|
||||
System.out.println("File too big (by "
|
||||
+ (out.getFilePointer() - (size - enddataSize))
|
||||
+ " bytes), please reduce some strings :(");
|
||||
} else if (out.getFilePointer() < size - enddataSize) {
|
||||
System.out.println("File too small (by " + ((size - enddataSize) - out.getFilePointer())+ " bytes), filling with 0x00 (this is OK) :D");
|
||||
System.out.println("File too small (by "
|
||||
+ ((size - enddataSize) - out.getFilePointer())
|
||||
+ " bytes), filling with 0x00 (this is OK) :D");
|
||||
while (out.getFilePointer() < size - enddataSize) {
|
||||
out.writeByte(0);
|
||||
}
|
||||
|
@ -141,7 +149,8 @@ public class RebuildPluginA extends Encoder {
|
|||
* @throws IOException
|
||||
* if any error occur while reading/writing
|
||||
*/
|
||||
public void createStringTable(String directory, String in, RandomAccessFile out) throws FileNotFoundException, IOException {
|
||||
public void createStringTable(String directory, String in,
|
||||
RandomAccessFile out) throws FileNotFoundException, IOException {
|
||||
System.out.println("Reading " + directory + "/" + in);
|
||||
RandomAccessFile file = new RandomAccessFile(directory + "/" + in, "r");
|
||||
if (file.length() == 0) {
|
||||
|
@ -172,7 +181,8 @@ public class RebuildPluginA extends Encoder {
|
|||
// now calculate the offsets using the length in bytes of the strings
|
||||
for (int i = 0; i < stringTable.size(); i++) {
|
||||
writeInt(out, offset);
|
||||
if (stringTable.elementAt(i).getBytes("UTF-8").length == 1 && stringTable.elementAt(i).charAt(0) == '\0') {
|
||||
if (stringTable.elementAt(i).getBytes("UTF-8").length == 1
|
||||
&& stringTable.elementAt(i).charAt(0) == '\0') {
|
||||
offset++;
|
||||
} else {
|
||||
offset += stringTable.elementAt(i).getBytes("UTF-8").length + 1;
|
||||
|
|
|
@ -41,6 +41,7 @@ import base.Encoder;
|
|||
public class RebuildPluginB extends Encoder {
|
||||
|
||||
private int encoder = 0;
|
||||
|
||||
public RebuildPluginB(int type) {
|
||||
encoder = type;
|
||||
}
|
||||
|
@ -48,7 +49,8 @@ public class RebuildPluginB extends Encoder {
|
|||
@Override
|
||||
public void compile(String filepath) {
|
||||
try {
|
||||
BufferedReader files = new BufferedReader(new FileReader(filepath + "/filelist.txt"));
|
||||
BufferedReader files = new BufferedReader(new FileReader(filepath
|
||||
+ "/filelist.txt"));
|
||||
String file = files.readLine();
|
||||
// retrieve the filename and size
|
||||
String filename = file.split(" ")[0];
|
||||
|
@ -71,7 +73,8 @@ public class RebuildPluginB extends Encoder {
|
|||
table_offset.add(pointer);
|
||||
}
|
||||
for (int i = 0; i < table_offset.size(); i++) {
|
||||
patchStringTable(filepath, filenames.get(i), out, table_offset.get(i));
|
||||
patchStringTable(filepath, filenames.get(i), out,
|
||||
table_offset.get(i));
|
||||
}
|
||||
out.close();
|
||||
System.out.println("Finished!");
|
||||
|
@ -82,7 +85,9 @@ public class RebuildPluginB extends Encoder {
|
|||
}
|
||||
}
|
||||
|
||||
private void patchStringTable(String directory, String in, RandomAccessFile out, int starting_offset) throws FileNotFoundException, IOException {
|
||||
private void patchStringTable(String directory, String in,
|
||||
RandomAccessFile out, int starting_offset)
|
||||
throws FileNotFoundException, IOException {
|
||||
System.out.println("Reading " + directory + "/" + in);
|
||||
RandomAccessFile file = new RandomAccessFile(directory + "/" + in, "r");
|
||||
checkUnicodeBOM(file); // thanks notepad :/ (die notepad, die)
|
||||
|
@ -108,9 +113,11 @@ public class RebuildPluginB extends Encoder {
|
|||
int string_start = (int) out.getFilePointer() + 28;
|
||||
out.seek(offset_table_pointer);
|
||||
int string_table_pointers = readInt(out);
|
||||
int diff = string_table_pointers - string_start - calculateTotalSize(stringTable);
|
||||
int diff = string_table_pointers - string_start
|
||||
- calculateTotalSize(stringTable);
|
||||
if (diff < 0) {
|
||||
System.err.println(in + " is too big, please remove at least " + -diff + " bytes. Skipped");
|
||||
System.err.println(in + " is too big, please remove at least "
|
||||
+ -diff + " bytes. Skipped");
|
||||
return;
|
||||
}
|
||||
out.seek(string_table_pointers);
|
||||
|
@ -138,7 +145,8 @@ public class RebuildPluginB extends Encoder {
|
|||
}
|
||||
}
|
||||
|
||||
private int calculateTotalSize(Vector<String> st) throws UnsupportedEncodingException {
|
||||
private int calculateTotalSize(Vector<String> st)
|
||||
throws UnsupportedEncodingException {
|
||||
int total = 0;
|
||||
for (String str : st) {
|
||||
int len = str.getBytes("UTF-8").length;
|
||||
|
@ -167,7 +175,8 @@ public class RebuildPluginB extends Encoder {
|
|||
in.close();
|
||||
out.close();
|
||||
} catch (FileNotFoundException ex) {
|
||||
System.out.println(ex.getMessage() + " in the specified directory.");
|
||||
System.out
|
||||
.println(ex.getMessage() + " in the specified directory.");
|
||||
System.exit(0);
|
||||
} catch (IOException e) {
|
||||
System.out.println(e.getMessage());
|
||||
|
|
|
@ -37,7 +37,8 @@ public class RebuildPluginC extends Encoder {
|
|||
@Override
|
||||
public void compile(String filepath) {
|
||||
try {
|
||||
BufferedReader files = new BufferedReader(new FileReader(filepath + "/filelist.txt"));
|
||||
BufferedReader files = new BufferedReader(new FileReader(filepath
|
||||
+ "/filelist.txt"));
|
||||
String string_file = files.readLine();
|
||||
// retrieve the filename and size
|
||||
String filename = string_file.split(" ")[0];
|
||||
|
@ -84,16 +85,21 @@ public class RebuildPluginC extends Encoder {
|
|||
out.writeByte(0);
|
||||
// we need to know the size of the enddata, so open it now
|
||||
System.out.println("Reading " + filenames.lastElement());
|
||||
RandomAccessFile enddata = new RandomAccessFile(filepath + "/" + filenames.lastElement(), "rw");
|
||||
RandomAccessFile enddata = new RandomAccessFile(filepath + "/"
|
||||
+ filenames.lastElement(), "rw");
|
||||
|
||||
long enddataSize = enddata.length();
|
||||
|
||||
// some checks to make sure that the file size of xxxx.bin is
|
||||
// correct
|
||||
if (out.getFilePointer() > size - enddataSize) {
|
||||
System.out.println("File too big (by " + (out.getFilePointer() - (size - enddataSize))+ " bytes), please reduce some strings :(");
|
||||
System.out.println("File too big (by "
|
||||
+ (out.getFilePointer() - (size - enddataSize))
|
||||
+ " bytes), please reduce some strings :(");
|
||||
} else if (out.getFilePointer() < size - enddataSize) {
|
||||
System.out.println("File too small (by " + ((size - enddataSize) - out.getFilePointer())+ " bytes), filling with 0x00 (this is OK) :D");
|
||||
System.out.println("File too small (by "
|
||||
+ ((size - enddataSize) - out.getFilePointer())
|
||||
+ " bytes), filling with 0x00 (this is OK) :D");
|
||||
while (out.getFilePointer() < size - enddataSize) {
|
||||
out.writeByte(0);
|
||||
}
|
||||
|
@ -127,7 +133,8 @@ public class RebuildPluginC extends Encoder {
|
|||
* @throws IOException
|
||||
* if any error occur while reading/writing
|
||||
*/
|
||||
private void createStringTable(String directory, String in, RandomAccessFile out) throws FileNotFoundException, IOException {
|
||||
private void createStringTable(String directory, String in,
|
||||
RandomAccessFile out) throws FileNotFoundException, IOException {
|
||||
System.out.println("Reading " + directory + "/" + in);
|
||||
RandomAccessFile file = new RandomAccessFile(directory + "/" + in, "r");
|
||||
checkUnicodeBOM(file); // thanks notepad :/ (*sigh*)
|
||||
|
|
Loading…
Reference in a new issue