Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package reghzy.mods.shiftsprint;
- import java.io.BufferedOutputStream;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.lang.reflect.Field;
- import java.util.ArrayList;
- import net.minecraft.launchwrapper.IClassTransformer;
- import net.minecraft.launchwrapper.LaunchClassLoader;
- public class TransformerA implements IClassTransformer {
- public static final String PATH = "F:\\TEMPPP\\";
- public static boolean reInit = false;
- public TransformerA() {
- System.out.println("TransformerA loaded");
- }
- public static File getFileForClass(String clazz, boolean create) throws IOException {
- int last = clazz.lastIndexOf(46);
- if (last == -1) {
- return new File("F:\\TEMPPP\\" + clazz);
- } else {
- File folder = new File("F:\\TEMPPP\\" + clazz.substring(0, last).replace('.', '\\'));
- if (create) {
- folder.mkdirs();
- }
- File file = new File(folder, clazz.substring(last + 1) + ".class");
- if (create) {
- file.createNewFile();
- }
- return file;
- }
- }
- public byte[] transform(String from, String to, byte[] bytes) {
- if (!to.startsWith("net") && !to.startsWith("cpw")) {
- return bytes;
- } else if (!reInit) {
- reInit = true;
- System.out.println("Re-registering transformer for latest updates");
- LaunchClassLoader loader = (LaunchClassLoader)ShiftSprint.class.getClassLoader();
- try {
- Field field = LaunchClassLoader.class.getDeclaredField("transformers");
- field.setAccessible(true);
- ArrayList<IClassTransformer> transformers = (ArrayList)field.get(loader);
- Field elementDataField = ArrayList.class.getDeclaredField("elementData");
- elementDataField.setAccessible(true);
- Object[] data = (Object[])((Object[])elementDataField.get(transformers));
- int len = transformers.size();
- for(int i = 0; i < len; ++i) {
- if (data[i] == this) {
- data[i] = data[len - 1];
- data[len - 1] = new TransformerA();
- return ((IClassTransformer)data[i]).transform(from, to, bytes);
- }
- }
- } catch (NoSuchFieldException var24) {
- var24.printStackTrace();
- } catch (IllegalAccessException var25) {
- var25.printStackTrace();
- }
- return bytes;
- } else {
- File file;
- try {
- file = getFileForClass(to, true);
- } catch (IOException var23) {
- var23.printStackTrace();
- return bytes;
- }
- try {
- BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file));
- byte[] var7;
- try {
- System.out.println("Writing class '" + to + "' to file: " + file.getAbsolutePath());
- outputStream.write(bytes);
- outputStream.flush();
- System.out.println("Success!");
- byte[] var6 = bytes;
- return var6;
- } catch (IOException var26) {
- System.out.println("Failed to write bytes to " + file.getAbsolutePath());
- var26.printStackTrace();
- var7 = bytes;
- } finally {
- try {
- outputStream.close();
- } catch (IOException var22) {
- System.out.println("Failed to close stream for FileOutputStream to " + file.getAbsolutePath());
- var22.printStackTrace();
- }
- }
- return var7;
- } catch (FileNotFoundException var28) {
- var28.printStackTrace();
- if (var28.getCause() != null) {
- var28.getCause().printStackTrace();
- if (var28.getCause().getCause() != null) {
- var28.getCause().getCause().printStackTrace();
- }
- }
- return bytes;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement