Last active
September 20, 2016 20:19
-
-
Save leonardosnt/eb3c8e1e6227a603adba57e70beedd05 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File origi = new File("C:\\Users\\Leonardo\\Documents\\Servers\\Eraldia\\plugins\\dtlTraders.jar"); | |
File jarFile = new File("C:\\Users\\Leonardo\\Documents\\Servers\\Eraldia\\plugins\\dtlTraders-patched.jar"); | |
java.nio.file.Files.copy(origi.toPath(), jarFile.toPath(), StandardCopyOption.REPLACE_EXISTING); | |
File patchedDir = new File("C:\\Users\\Leonardo\\Documents\\Servers\\Eraldia\\plugins\\patched"); | |
patchedDir.mkdir(); | |
JarFile jar = new JarFile(jarFile); | |
jar.stream().forEach(entry -> { | |
if (entry.getName().endsWith("/Trader.class")) { | |
try { | |
InputStream input = jar.getInputStream(entry); | |
ClassReader cr = new ClassReader(input); | |
ClassWriter cw = new ClassWriter(0); | |
cr.accept(new ClassVisitor(ASM5, cw) { | |
@Override | |
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { | |
MethodVisitor def = super.visitMethod(access, name, desc, signature, exceptions); | |
if (name.equals("transactionEvent")) { | |
return new MethodVisitor(ASM5, def) { | |
@Override | |
public void visitFieldInsn(int opcode, String owner, String name, String desc) { | |
if (opcode == GETSTATIC && name.equals("INVENTORY_FULL")) { | |
super.visitVarInsn(ALOAD, 1); | |
return; | |
} | |
super.visitFieldInsn(opcode, owner, name, desc); | |
} | |
}; | |
} | |
return def; | |
} | |
}, 0); | |
File classFile = new File(patchedDir, entry.getName()); | |
classFile.getParentFile().mkdirs(); | |
byte[] bytecode = cw.toByteArray(); | |
Files.write(bytecode, classFile); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment