String deobfData = args[2]; //Path to FML's deobfusication_data.lzma
String outputDir = args[3]; //Path to place generated .binpatch
String killTarget = args[4]; //"true" if we should destroy the target file if it generated a successful .binpatch
LogManager.getLogger("GENDIFF").log(Level.INFO, String.format("Creating patches at %s for %s from %s", outputDir, sourceJar, targetDir));
Delta delta = new Delta();
FMLDeobfuscatingRemapper remapper = FMLDeobfuscatingRemapper.INSTANCE;
remapper.setupLoadOnly(deobfData, false);
JarFile sourceZip = new JarFile(sourceJar);
boolean kill = killTarget.equalsIgnoreCase("true");
File f = new File(outputDir);
f.mkdirs();
for (String name : remapper.getObfedClasses())
{
// Logger.getLogger("GENDIFF").info(String.format("Evaluating path for data :%s",name));
String fileName = name;
String jarName = name;
if (RESERVED_NAMES.contains(name.toUpperCase(Locale.ENGLISH)))
{
fileName = "_"+name;
}
File targetFile = new File(targetDir, fileName.replace('/', File.separatorChar) + ".class");
jarName = jarName+".class";
if (targetFile.exists())
{
String sourceClassName = name.replace('/', '.');
String targetClassName = remapper.map(name).replace('/', '.');
JarEntry entry = sourceZip.getJarEntry(jarName);
byte[] vanillaBytes = entry != null ? ByteStreams.toByteArray(sourceZip.getInputStream(entry)) : new byte[0];
byte[] patchedBytes = Files.toByteArray(targetFile);
byte[] diff = delta.compute(vanillaBytes, patchedBytes);
ByteArrayDataOutput diffOut = ByteStreams.newDataOutput(diff.length + 50);
// Original name
diffOut.writeUTF(name);