BufferedInputStream is = new BufferedInputStream(jar.getInputStream(entry));
if (is.available() < 8000) { // TODO: Double check that this filter won't mess anything up.
byte[] classData = new byte[is.available()];
is.read(classData);
is.close();
byteClassStack.push(new ByteClass(nameSplit[0], classData));
}
}
}
jar.close();
Log.i("Jar load complete.");
} catch (Exception e) {
e.printStackTrace();
Log.crash(e, "Error extracting jar data.");
}
Log.i("Searching for classes...");
int checksRemaining = classChecks.length;
Object[] byteClasses = byteClassStack.toArray();
boolean[] found = new boolean[byteClasses.length];
while (checksRemaining != 0) {
for (int q = 0; q < classChecks.length; q++) {
for (int i = 0; i < byteClasses.length; i++) {
if (!found[q]) {
classChecks[q].check(this, (ByteClass)byteClasses[i]);
if (classChecks[q].isComplete) {
Log.debug("Found: " + byteClasses[i] + " as " + classChecks[q].getName() + " | " + classChecks[q].getClass().getSimpleName());
found[q] = true;
checksRemaining--;
}
// TODO: What is this line, and why is it commented
//byteClassMap.put(classChecks[q].getName(), classFiles[i].getName().split("\\.")[0]);
}
}
if (!found[q]) {
classChecks[q].passes--;
if (classChecks[q].passes == 0) {
found[q] = true;
checksRemaining--;
}
}
}
}
Log.i("Class search complete.");
Log.i("Generating version ID...");
use();
try {
use();
if (classLoader.findResource("net/minecraft/client/Minecraft.class") != null)
mainClass = classLoader.loadClass("net.minecraft.client.Minecraft");
else if (classLoader.findResource("net/minecraft/server/MinecraftServer.class") != null)
mainClass = classLoader.loadClass("net.minecraft.server.MinecraftServer");
else
throw new RuntimeException();
} catch (Exception e) {
e.printStackTrace(); // TODO: Make this exception far less broad.
Log.crash(e, "Attempted to load non-minecraft jar, or unable to locate starting point.");
}
String typeDump = "";
Field fields[] = null;
try {
fields = mainClass.getDeclaredFields();
} catch (NoClassDefFoundError e) {
e.printStackTrace();
Log.crash(e, "Unable to find critical external class while loading.\nPlease ensure you have the correct Minecraft libraries installed.");
}
for (int i = 0; i < fields.length; i++) {
String typeString = fields[i].getType().toString();
if (typeString.startsWith("class ") && !typeString.contains("."))
typeDump += typeString.substring(6);
}
versionId = typeDump;
for (VersionInfo v : VersionInfo.values()) {
if (versionId.equals(v.versionId)) {
version = v;
break;
}
}
Log.i("Identified Minecraft [" + version.name() + "] with versionID of " + versionId);
Log.i("Loading classes...");
nameMap = new HashMap<String, MinecraftClass>();
classMap = new HashMap<String, MinecraftClass>();
for (String name : byteClassNames) {
ByteClass byteClass = byteClassMap.get(name);
MinecraftClass minecraftClass = new MinecraftClass(name, byteClass.getClassName());
minecraftClass.load(this);
nameMap.put(minecraftClass.getName(), minecraftClass);
classMap.put(minecraftClass.getClassName(), minecraftClass);
}
for (MinecraftClass minecraftClass : nameMap.values()) {
ByteClass byteClass = byteClassMap.get(minecraftClass.getName());
for (String[] property : byteClass.getProperties())
minecraftClass.addProperty(new MinecraftProperty(minecraftClass, property[1], property[0]));
for (String[] method : byteClass.getMethods()) {
String methodString = obfuscateStringClasses(method[0]);
methodString = methodString.replaceAll(",INVALID", "").replaceAll("INVALID,","").replaceAll("INVALID", "");
String methodDeobfName = method[1];
String methodObfName = methodString.substring(0, methodString.indexOf('('));
String parameterString = methodString.substring(methodString.indexOf('(') + 1, methodString.indexOf(')'));
if (parameterString.equals("")) {
minecraftClass.addMethod(new MinecraftMethod(minecraftClass, methodDeobfName, methodObfName));
} else {
String[] parameterClasses = parameterString.split(",");
minecraftClass.addMethod(new MinecraftMethod(minecraftClass, methodDeobfName, methodObfName, parameterClasses));
}
}
for (String[] constructor : byteClass.getConstructors()) {
String methodString = obfuscateStringClasses(constructor[0]).replaceAll(",INVALID", "").replaceAll("INVALID,","").replaceAll("INVALID", "");
String methodDeobfName = constructor[1];
String methodObfName = methodString.substring(0, methodString.indexOf('('));
String parameterString = methodString.substring(methodString.indexOf('(') + 1, methodString.indexOf(')'));