diff --git a/1.9.2/src/MinecraftUtil.java b/1.9.2/src/customskinloader/utils/MinecraftUtil.java similarity index 87% rename from 1.9.2/src/MinecraftUtil.java rename to 1.9.2/src/customskinloader/utils/MinecraftUtil.java index 183fff3..41a8339 100644 --- a/1.9.2/src/MinecraftUtil.java +++ b/1.9.2/src/customskinloader/utils/MinecraftUtil.java @@ -19,8 +19,11 @@ public class MinecraftUtil { return getMinecraftDataDir(); } - private static String MINECRAFT_DATA_FOLDER=".minecraft"; + public static File minecraftDataFolder=null; + private static final String MINECRAFT_DATA_FOLDER=".minecraft"; public static File getMinecraftDataDir(){ + if(minecraftDataFolder!=null) + return minecraftDataFolder; File temp=new File(""); if(temp.getAbsolutePath().endsWith(MINECRAFT_DATA_FOLDER)) return temp; diff --git a/Common/customskinloader/Logger.java b/Common/customskinloader/Logger.java index a094a92..16fdd70 100644 --- a/Common/customskinloader/Logger.java +++ b/Common/customskinloader/Logger.java @@ -11,7 +11,10 @@ import java.util.logging.Level; public class Logger { private static final int LOWEST_DISPLAY_LEVEL=Level.INFO.intValue(); SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - private BufferedWriter writer; + private BufferedWriter writer=null; + public Logger(){ + //Logger isn't created. + } public Logger(File logFile){ try { if(!logFile.getParentFile().exists()){ @@ -39,6 +42,8 @@ public class Logger { public void log(Level level,String msg){ if(level.intValue()>=LOWEST_DISPLAY_LEVEL) System.out.println(msg); + if(writer==null) + return; try { StringBuilder sb=new StringBuilder(); sb.append("["); diff --git a/Common/customskinloader/tweaker/ClassTransformer.java b/Common/customskinloader/tweaker/ClassTransformer.java index 40e156c..f5d3de3 100644 --- a/Common/customskinloader/tweaker/ClassTransformer.java +++ b/Common/customskinloader/tweaker/ClassTransformer.java @@ -5,6 +5,8 @@ import java.net.*; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; +import org.apache.commons.io.IOUtils; + import net.minecraft.launchwrapper.IClassTransformer; public class ClassTransformer implements IClassTransformer { @@ -19,17 +21,19 @@ public class ClassTransformer implements IClassTransformer { for (int i = 0; i < urls.length; i++) { URL url = urls[i]; ZipFile tempZipFile = getZipFile(url); - if (tempZipFile == null) + if (tempZipFile.getEntry("customskinloader/tweaker/ClassTransformer.class") == null){ + tempZipFile.close(); continue; + } zipFile = tempZipFile; ForgeTweaker.logger.info("Jar File URL: " + url); break; } } catch (Exception e) { - e.printStackTrace(); + ForgeTweaker.logger.warning(e); } if (zipFile == null) { - ForgeTweaker.logger.info("Can not find needed JAR in the classpath."); + ForgeTweaker.logger.info("Can not find JAR in the classpath."); } } @@ -37,61 +41,44 @@ public class ClassTransformer implements IClassTransformer { { ZipFile zipFile0; try { - URI uri = url.toURI(); - File file = new File(uri); + File file = new File(url.toURI()); zipFile0 = new ZipFile(file); - if (zipFile0.getEntry("customskinloader/tweaker/ClassTransformer.class") != null){ - ForgeTweaker.logger.info("JAR Found!"); - return zipFile0; - } - zipFile0.close(); + return zipFile0; } catch (Exception e) { + ForgeTweaker.logger.warning(e); } return null; } public byte[] transform(String name, String transformedName, byte bytes[]) { - byte diBytes[] = getClass(name); + if (zipFile == null) + return bytes; + String fullName = name + ".class"; + ZipEntry ze = zipFile.getEntry(fullName); + if (ze == null) + return bytes; + byte diBytes[] = getClass(ze); if (diBytes != null) { - ForgeTweaker.logger.info("Class '" + name + "' transformed."); + ForgeTweaker.logger.info("Class '" + name + "'("+transformedName+") transformed."); return diBytes; } else return bytes; } - private byte[] getClass(String name) { - if (zipFile == null) - return null; - String fullName = name + ".class"; - ZipEntry ze = zipFile.getEntry(fullName); + private byte[] getClass(ZipEntry ze) { if (ze == null) return null; try { - InputStream in = zipFile.getInputStream(ze); - byte[] bytes = readAll(in); + InputStream is = zipFile.getInputStream(ze); + byte[] bytes = IOUtils.toByteArray(is); if ((long)bytes.length == ze.getSize()) return bytes; - ForgeTweaker.logger.info("Failed: " + fullName + " " + bytes.length + " / " + ze.getSize()); + ForgeTweaker.logger.info("Failed: " + ze.getName() + " " + bytes.length + " / " + ze.getSize()); } catch (IOException e) { e.printStackTrace(); } return null; } - - public static byte[] readAll(InputStream is) throws IOException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - byte buffer[] = new byte[1024]; - do { - int len = is.read(buffer); - if (len >= 0) { - baos.write(buffer, 0, len); - } else { - is.close(); - byte bytes[] = baos.toByteArray(); - return bytes; - } - } while (true); - } } diff --git a/Common/customskinloader/tweaker/ForgeTweaker.java b/Common/customskinloader/tweaker/ForgeTweaker.java index 7b9133e..aa25560 100644 --- a/Common/customskinloader/tweaker/ForgeTweaker.java +++ b/Common/customskinloader/tweaker/ForgeTweaker.java @@ -11,14 +11,17 @@ import net.minecraft.launchwrapper.LaunchClassLoader; public class ForgeTweaker implements ITweaker { - private static final File TWEAKER_LOG_FILE = new File(MinecraftUtil.getMinecraftDataDir(),"CustomSkinLoader/Tweaker.log"); - public static Logger logger = new Logger(TWEAKER_LOG_FILE); + public static Logger logger = new Logger(); public ForgeTweaker() { - logger.info("Using ForgeTweaker"); } public void acceptOptions(List args, File gameDir, File assetsDir, String profile) { + MinecraftUtil.minecraftDataFolder=gameDir; + File tweakerLogFile = new File(MinecraftUtil.getMinecraftDataDir(),"CustomSkinLoader/Tweaker.log"); + logger = new Logger(tweakerLogFile); + + logger.info("Using ForgeTweaker"); logger.info("ForgeTweaker: acceptOptions"); } diff --git a/Common/customskinloader/tweaker/Tweaker.java b/Common/customskinloader/tweaker/Tweaker.java index 12a0a60..25b491f 100644 --- a/Common/customskinloader/tweaker/Tweaker.java +++ b/Common/customskinloader/tweaker/Tweaker.java @@ -17,14 +17,18 @@ public class Tweaker implements ITweaker { private String assetsDir; private String profile; - private static final File TWEAKER_LOG_FILE = new File(MinecraftUtil.getMinecraftDataDir(),"CustomSkinLoader/Tweaker.log"); - public static Logger logger = new Logger(TWEAKER_LOG_FILE); + public static Logger logger = new Logger(); public Tweaker() { logger.info("Using Tweaker"); } public void acceptOptions(List args, File gameDir, File assetsDir, String profile) { + MinecraftUtil.minecraftDataFolder=gameDir; + File tweakerLogFile = new File(MinecraftUtil.getMinecraftDataDir(),"CustomSkinLoader/Tweaker.log"); + logger = new Logger(tweakerLogFile); + + logger.info("Using Tweaker"); logger.info("Tweaker: acceptOptions"); this.args = new ArrayList(args); this.gameDir = gameDir.getAbsolutePath(); diff --git a/Common/customskinloader/utils/MinecraftUtil.java b/Common/customskinloader/utils/MinecraftUtil.java index 75c143c..006eaae 100644 --- a/Common/customskinloader/utils/MinecraftUtil.java +++ b/Common/customskinloader/utils/MinecraftUtil.java @@ -19,8 +19,11 @@ public class MinecraftUtil { return net.minecraft.client.Minecraft.getMinecraft().mcDataDir; } - private static String MINECRAFT_DATA_FOLDER=".minecraft"; + public static File minecraftDataFolder=null; + private static final String MINECRAFT_DATA_FOLDER=".minecraft"; public static File getMinecraftDataDir(){ + if(minecraftDataFolder!=null) + return minecraftDataFolder; File temp=new File(""); if(temp.getAbsolutePath().endsWith(MINECRAFT_DATA_FOLDER)) return temp;